Skip to content

Commit e396dab

Browse files
authored
[RISCV] Use SignExtend64<32> instead of ORing in 32 1s into upper bits in RISCVMatInt. NFC (#159864)
I think this better reflects the intent of modification. In all these places we know bit 31 is 1 so we are sign extending.
1 parent 03cf9ba commit e396dab

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static void generateInstSeqImpl(int64_t Val, const MCSubtargetInfo &STI,
158158
// Reduce the shift amount and add zeros to the LSBs so it will match
159159
// LUI, then shift left with SLLI.UW to clear the upper 32 set bits.
160160
ShiftAmount -= 12;
161-
Val = ((uint64_t)Val << 12) | (0xffffffffull << 32);
161+
Val = SignExtend64<32>((uint64_t)Val << 12);
162162
Unsigned = true;
163163
}
164164
}
@@ -168,7 +168,7 @@ static void generateInstSeqImpl(int64_t Val, const MCSubtargetInfo &STI,
168168
STI.hasFeature(RISCV::FeatureStdExtZba)) {
169169
// Use LUI+ADDI or LUI to compose, then clear the upper 32 bits with
170170
// SLLI_UW.
171-
Val = ((uint64_t)Val) | (0xffffffffull << 32);
171+
Val = SignExtend64<32>((uint64_t)Val);
172172
Unsigned = true;
173173
}
174174
}
@@ -239,8 +239,8 @@ static void generateInstSeqLeadingZeros(int64_t Val, const MCSubtargetInfo &STI,
239239
// If we have exactly 32 leading zeros and Zba, we can try using zext.w at
240240
// the end of the sequence.
241241
if (LeadingZeros == 32 && STI.hasFeature(RISCV::FeatureStdExtZba)) {
242-
// Try replacing upper bits with 1.
243-
uint64_t LeadingOnesVal = Val | maskLeadingOnes<uint64_t>(LeadingZeros);
242+
// Bit 31 is set, so sign extend to fill the upper bits with 1s.
243+
uint64_t LeadingOnesVal = SignExtend64<32>(Val);
244244
TmpSeq.clear();
245245
generateInstSeqImpl(LeadingOnesVal, STI, TmpSeq);
246246

0 commit comments

Comments
 (0)