aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-03-11 09:00:19 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-03-11 09:00:19 +0000
commitb69050a94c1c9266ab048a79c8375e5b14d87c72 (patch)
treebf7c5218182894c05403125a704ce60ba3aa5b18 /lib/Analysis
parent6fd2472b1b2d8f6a64b38874cbca95d3578e16a4 (diff)
downloadexternal_llvm-b69050a94c1c9266ab048a79c8375e5b14d87c72.zip
external_llvm-b69050a94c1c9266ab048a79c8375e5b14d87c72.tar.gz
external_llvm-b69050a94c1c9266ab048a79c8375e5b14d87c72.tar.bz2
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
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/ValueTracking.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index f05ad66..33fb1e8 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/lib/Analysis/ValueTracking.cpp
@@ -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: