mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-19 15:13:49 -04:00
[APInt] Fix rotl/rotr when the shift amount is greater than the total bit width.
Review: https://reviews.llvm.org/D27749 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294295 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
+15
-2
@@ -1252,8 +1252,21 @@ APInt APInt::shlSlowCase(unsigned shiftAmt) const {
|
||||
return Result;
|
||||
}
|
||||
|
||||
// Calculate the rotate amount modulo the bit width.
|
||||
static unsigned rotateModulo(unsigned BitWidth, const APInt &rotateAmt) {
|
||||
unsigned rotBitWidth = rotateAmt.getBitWidth();
|
||||
APInt rot = rotateAmt;
|
||||
if (rotBitWidth < BitWidth) {
|
||||
// Extend the rotate APInt, so that the urem doesn't divide by 0.
|
||||
// e.g. APInt(1, 32) would give APInt(1, 0).
|
||||
rot = rotateAmt.zext(BitWidth);
|
||||
}
|
||||
rot = rot.urem(APInt(rot.getBitWidth(), BitWidth));
|
||||
return rot.getLimitedValue(BitWidth);
|
||||
}
|
||||
|
||||
APInt APInt::rotl(const APInt &rotateAmt) const {
|
||||
return rotl((unsigned)rotateAmt.getLimitedValue(BitWidth));
|
||||
return rotl(rotateModulo(BitWidth, rotateAmt));
|
||||
}
|
||||
|
||||
APInt APInt::rotl(unsigned rotateAmt) const {
|
||||
@@ -1264,7 +1277,7 @@ APInt APInt::rotl(unsigned rotateAmt) const {
|
||||
}
|
||||
|
||||
APInt APInt::rotr(const APInt &rotateAmt) const {
|
||||
return rotr((unsigned)rotateAmt.getLimitedValue(BitWidth));
|
||||
return rotr(rotateModulo(BitWidth, rotateAmt));
|
||||
}
|
||||
|
||||
APInt APInt::rotr(unsigned rotateAmt) const {
|
||||
|
||||
Reference in New Issue
Block a user