Be careful not to request or look at bits shifted in from outside the size
of the input. This fixes the mediabench/gsm/toast failure last night.
llvm-svn: 26138
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 9b75ee1..4247d8a 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -939,20 +939,26 @@
// Compute the new bits that are at the top now.
uint64_t HighBits = (1ULL << ShAmt)-1;
HighBits <<= I->getType()->getPrimitiveSizeInBits() - ShAmt;
-
+ uint64_t TypeMask = I->getType()->getIntegralTypeMask();
if (I->getType()->isUnsigned()) { // Unsigned shift right.
- if (SimplifyDemandedBits(I->getOperand(0), DemandedMask << ShAmt,
+ if (SimplifyDemandedBits(I->getOperand(0),
+ (DemandedMask << ShAmt) & TypeMask,
KnownZero, KnownOne, Depth+1))
return true;
assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
+ KnownZero &= TypeMask;
+ KnownOne &= TypeMask;
KnownZero >>= ShAmt;
KnownOne >>= ShAmt;
KnownZero |= HighBits; // high bits known zero.
} else { // Signed shift right.
- if (SimplifyDemandedBits(I->getOperand(0), DemandedMask << ShAmt,
+ if (SimplifyDemandedBits(I->getOperand(0),
+ (DemandedMask << ShAmt) & TypeMask,
KnownZero, KnownOne, Depth+1))
return true;
assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
+ KnownZero &= TypeMask;
+ KnownOne &= TypeMask;
KnownZero >>= SA->getValue();
KnownOne >>= SA->getValue();