Skip to content

Commit ebe7265

Browse files
authored
[Mips] Fix fast isel for i16 bswap. (#103398)
We need to mask the SRL result to 8 bits before ORing in the SLL. This is needed in case bits 23:16 of the input aren't zero. They will have been shifted into bits 15:8. We don't need to AND the result with 0xffff. It's ok if the upper 16 bits of the register are garbage. Fixes #103035.
1 parent bd9f2c2 commit ebe7265

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

llvm/lib/Target/Mips/MipsFastISel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,8 +1608,8 @@ bool MipsFastISel::fastLowerIntrinsicCall(const IntrinsicInst *II) {
16081608
}
16091609
emitInst(Mips::SLL, TempReg[0]).addReg(SrcReg).addImm(8);
16101610
emitInst(Mips::SRL, TempReg[1]).addReg(SrcReg).addImm(8);
1611-
emitInst(Mips::OR, TempReg[2]).addReg(TempReg[0]).addReg(TempReg[1]);
1612-
emitInst(Mips::ANDi, DestReg).addReg(TempReg[2]).addImm(0xFFFF);
1611+
emitInst(Mips::ANDi, TempReg[2]).addReg(TempReg[1]).addImm(0xFF);
1612+
emitInst(Mips::OR, DestReg).addReg(TempReg[0]).addReg(TempReg[2]);
16131613
updateValueMap(II, DestReg);
16141614
return true;
16151615
}

llvm/test/CodeGen/Mips/Fast-ISel/bswap1.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ define void @b16() {
2121

2222
; 32R1: sll $[[TMP1:[0-9]+]], $[[A_VAL]], 8
2323
; 32R1: srl $[[TMP2:[0-9]+]], $[[A_VAL]], 8
24-
; 32R1: or $[[TMP3:[0-9]+]], $[[TMP1]], $[[TMP2]]
25-
; 32R1: andi $[[TMP4:[0-9]+]], $[[TMP3]], 65535
24+
; 32R1: andi $[[TMP3:[0-9]+]], $[[TMP2]], 255
25+
; 32R1: or $[[RESULT:[0-9]+]], $[[TMP1]], $[[TMP3]]
2626

2727
; 32R2: wsbh $[[RESULT:[0-9]+]], $[[A_VAL]]
2828

0 commit comments

Comments
 (0)