When determining if we can fold (x >> C1) << C2, the bits that we need to verify are zero

are not the low bits of x, but the bits that WILL be the low bits after the operation completes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122529 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson
2010-12-23 23:56:24 +00:00
parent e4a2dd2f1a
commit ec3953ff95
2 changed files with 21 additions and 1 deletions
@@ -168,8 +168,9 @@ static bool CanEvaluateShifted(Value *V, unsigned NumBits, bool isLeftShift,
// We can always turn lshr(c1)+shl(c2) -> lshr(c3)+and(c4), but it isn't
// profitable unless we know the and'd out bits are already zero.
if (CI->getZExtValue() > NumBits) {
unsigned LowBits = CI->getZExtValue() - NumBits;
if (MaskedValueIsZero(I->getOperand(0),
APInt::getLowBitsSet(TypeWidth, NumBits)))
APInt::getLowBitsSet(TypeWidth, NumBits) << LowBits))
return true;
}