Teach ComputeMaskedBits about nsw on add. I don't think there's anything we can

do with nuw here, but sub and mul should be given similar treatment.
Fixes PR9343 #15!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127463 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky
2011-03-11 09:00:19 +00:00
parent 6fd2472b1b
commit b69050a94c
2 changed files with 24 additions and 0 deletions

View File

@@ -429,6 +429,20 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
KnownZero |= LHSKnownZero & Mask;
KnownOne |= LHSKnownOne & Mask;
}
// Are we still trying to solve for the sign bit?
if (Mask.isNegative() && !KnownZero.isNegative() && !KnownOne.isNegative()){
OverflowingBinaryOperator *OBO = cast<OverflowingBinaryOperator>(I);
if (OBO->hasNoSignedWrap()) {
// Adding two positive numbers can't wrap into negative ...
if (LHSKnownZero.isNegative() && KnownZero2.isNegative())
KnownZero |= APInt::getSignBit(BitWidth);
// and adding two negative numbers can't wrap into positive.
else if (LHSKnownOne.isNegative() && KnownOne2.isNegative())
KnownOne |= APInt::getSignBit(BitWidth);
}
}
return;
}
case Instruction::SRem: