diff options
| author | Nick Lewycky <nicholas@mxc.ca> | 2011-03-11 09:00:19 +0000 |
|---|---|---|
| committer | Nick Lewycky <nicholas@mxc.ca> | 2011-03-11 09:00:19 +0000 |
| commit | cc799738560bc8fc0acc7438e508223539ebc43c (patch) | |
| tree | 4ce8a6cd3bd10f10274ff66786aa694c46f41598 /llvm/lib/Analysis/ValueTracking.cpp | |
| parent | 8559f5914c6c21a1b2e72aaf074f90132faab428 (diff) | |
| download | llvm-cc799738560bc8fc0acc7438e508223539ebc43c.zip llvm-cc799738560bc8fc0acc7438e508223539ebc43c.tar.gz llvm-cc799738560bc8fc0acc7438e508223539ebc43c.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!
llvm-svn: 127463
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
| -rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index f05ad66..33fb1e8 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/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: |
