Skip to content

Commit bcb15d0

Browse files
authored
[APInt] Slightly simplify APInt::ashrSlowCase. NFC (#111220)
Use an arithmetic shift for the last word copy when BitShift!=0. This avoids an explicit sign extend after the shift.
1 parent e8f01b0 commit bcb15d0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

llvm/lib/Support/APInt.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1055,11 +1055,10 @@ void APInt::ashrSlowCase(unsigned ShiftAmt) {
10551055
U.pVal[i] = (U.pVal[i + WordShift] >> BitShift) |
10561056
(U.pVal[i + WordShift + 1] << (APINT_BITS_PER_WORD - BitShift));
10571057

1058-
// Handle the last word which has no high bits to copy.
1059-
U.pVal[WordsToMove - 1] = U.pVal[WordShift + WordsToMove - 1] >> BitShift;
1060-
// Sign extend one more time.
1058+
// Handle the last word which has no high bits to copy. Use an arithmetic
1059+
// shift to preserve the sign bit.
10611060
U.pVal[WordsToMove - 1] =
1062-
SignExtend64(U.pVal[WordsToMove - 1], APINT_BITS_PER_WORD - BitShift);
1061+
(int64_t)U.pVal[WordShift + WordsToMove - 1] >> BitShift;
10631062
}
10641063
}
10651064

0 commit comments

Comments
 (0)