@@ -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