summaryrefslogtreecommitdiff
path: root/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2011-03-12 17:18:11 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2011-03-12 17:18:11 +0000
commit14b2a59301e9e4065c7b9b07a0c68462b6037a4f (patch)
tree24e22757d901ffa8e83af49a47da3746e6333b75 /lib/Analysis/ValueTracking.cpp
parent879d3a98a2d64793a49e747b3d64020db74c5a3e (diff)
downloadllvm-14b2a59301e9e4065c7b9b07a0c68462b6037a4f.tar.gz
llvm-14b2a59301e9e4065c7b9b07a0c68462b6037a4f.tar.bz2
llvm-14b2a59301e9e4065c7b9b07a0c68462b6037a4f.tar.xz
Teach ComputeMaskedBits about sub nsw.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127548 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ValueTracking.cpp')
-rw-r--r--lib/Analysis/ValueTracking.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index 6c33d2d508..c36f68c2ae 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/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);
+ }
}
}