diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-03-12 17:18:11 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-03-12 17:18:11 +0000 |
| commit | 5acc751b6f8679473edbf4f3b8165986eba9b0f8 (patch) | |
| tree | ebb5c26f8470b66eb825649f712b5bd3802f9e39 /llvm/lib/Analysis/ValueTracking.cpp | |
| parent | cc48b9ac0f38ab92dd4448241771e4d406da312c (diff) | |
| download | llvm-5acc751b6f8679473edbf4f3b8165986eba9b0f8.zip llvm-5acc751b6f8679473edbf4f3b8165986eba9b0f8.tar.gz llvm-5acc751b6f8679473edbf4f3b8165986eba9b0f8.tar.bz2 | |
Teach ComputeMaskedBits about sub nsw.
llvm-svn: 127548
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
| -rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 6c33d2d..c36f68c 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -431,16 +431,24 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask, } // Are we still trying to solve for the sign bit? - if (I->getOpcode() == Instruction::Add && - Mask.isNegative() && !KnownZero.isNegative() && !KnownOne.isNegative()){ + 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); + if (I->getOpcode() == Instruction::Add) { + // 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); + } else { + // Subtracting a negative number from a positive one can't wrap + if (LHSKnownZero.isNegative() && KnownOne2.isNegative()) + KnownZero |= APInt::getSignBit(BitWidth); + // neither can subtracting a positive number from a negative one. + else if (LHSKnownOne.isNegative() && KnownZero2.isNegative()) + KnownOne |= APInt::getSignBit(BitWidth); + } } } |
