diff options
author | Craig Topper <craig.topper@intel.com> | 2020-07-31 15:46:12 -0700 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2020-07-31 15:55:03 -0700 |
commit | 86dea1f39bd127776b999e10dff212003068d30a (patch) | |
tree | 44fedb3e0b55120f2a683234e9401ccbf3f07ea2 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | f2400f024d323bc9000a4c126f2008a8b58fb4a0 (diff) | |
download | llvm-86dea1f39bd127776b999e10dff212003068d30a.zip llvm-86dea1f39bd127776b999e10dff212003068d30a.tar.gz llvm-86dea1f39bd127776b999e10dff212003068d30a.tar.bz2 |
[ValueTracking] Improve llvm.abs handling in computeKnownBits.
Add the optimizations we have in the SelectionDAG version.
Known non-negative copies all known bits. Any known one other than
the sign bit makes result non-negative.
Differential Revision: https://reviews.llvm.org/D85000
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 4cd2d07..af55c96 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1644,13 +1644,24 @@ static void computeKnownBitsFromOperator(const Operator *I, default: break; case Intrinsic::abs: computeKnownBits(I->getOperand(0), Known2, Depth + 1, Q); - // Otherwise, if this call is undefined for INT_MIN, the result is - // positive. - if (match(II->getArgOperand(1), m_One())) - Known.Zero.setSignBit(); + + // If the source's MSB is zero then we know the rest of the bits. + if (Known2.isNonNegative()) { + Known.Zero |= Known2.Zero; + Known.One |= Known2.One; + break; + } + // Absolute value preserves trailing zero count. Known.Zero.setLowBits(Known2.Zero.countTrailingOnes()); - // FIXME: Handle known negative/non-negative input? + + // If this call is undefined for INT_MIN, the result is positive. We + // also know it can't be INT_MIN if there is a set bit that isn't the + // sign bit. + Known2.One.clearSignBit(); + if (match(II->getArgOperand(1), m_One()) || Known2.One.getBoolValue()) + Known.Zero.setSignBit(); + // FIXME: Handle known negative input? // FIXME: Calculate the negated Known bits and combine them? break; case Intrinsic::bitreverse: |