aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2023-04-30 09:33:22 -0500
committerNoah Goldstein <goldstein.w.n@gmail.com>2023-04-30 10:06:46 -0500
commitd840391401735a2cd5be54c11e1806ef47df622d (patch)
tree06ca44a29476d9a213c0f806b38b7f7f66cbe2b2 /llvm/lib/Analysis/ValueTracking.cpp
parente78c30a10fe73c03843604a9d06ac55b87fda735 (diff)
downloadllvm-d840391401735a2cd5be54c11e1806ef47df622d.zip
llvm-d840391401735a2cd5be54c11e1806ef47df622d.tar.gz
llvm-d840391401735a2cd5be54c11e1806ef47df622d.tar.bz2
[ValueTracking] Add logic for `isKnownNonZero(smin/smax X, Y)`
For `smin` if either `X` or `Y` is negative, the result is non-zero. For `smax` if either `X` or `Y` is strictly positive, the result is non-zero. For both if `X != 0` and `Y != 0` the result is non-zero. Alive2 Link: https://alive2.llvm.org/ce/z/7yvbgN https://alive2.llvm.org/ce/z/zizbvq Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149417
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 8551de6..fa267ce 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2942,6 +2942,26 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q))
return true;
break;
+ case Intrinsic::smin:
+ case Intrinsic::smax: {
+ auto KnownOpImpliesNonZero = [&](const KnownBits &K) {
+ return II->getIntrinsicID() == Intrinsic::smin
+ ? K.isNegative()
+ : K.isStrictlyPositive();
+ };
+ KnownBits XKnown =
+ computeKnownBits(II->getArgOperand(0), DemandedElts, Depth, Q);
+ if (KnownOpImpliesNonZero(XKnown))
+ return true;
+ KnownBits YKnown =
+ computeKnownBits(II->getArgOperand(1), DemandedElts, Depth, Q);
+ if (KnownOpImpliesNonZero(YKnown))
+ return true;
+
+ if (XKnown.isNonZero() && YKnown.isNonZero())
+ return true;
+ }
+ [[fallthrough]];
case Intrinsic::umin:
return isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q) &&
isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q);