[llvm] [ValueTracking] improve `isKnownNonZero` precision for `smax` (PR #88170)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 9 22:45:45 PDT 2024
================
@@ -2828,23 +2828,47 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
case Intrinsic::uadd_sat:
return isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q) ||
isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q);
- case Intrinsic::smin:
case Intrinsic::smax: {
- auto KnownOpImpliesNonZero = [&](const KnownBits &K) {
- return II->getIntrinsicID() == Intrinsic::smin
- ? K.isNegative()
- : K.isStrictlyPositive();
- };
- KnownBits XKnown =
+ // if either arg is strictly positive the result is non-zero. Otherwise
+ // the result is non-zero if both ops are non-zero.
+ KnownBits Op1Known =
+ computeKnownBits(II->getArgOperand(1), DemandedElts, Depth, Q);
+ // Avoid re-computing isKnownNonZero if we already failed once.
+ bool OpsMaybeZero = false;
+ if (Op1Known.isNonNegative()) {
+ if (Op1Known.isNonZero() ||
+ isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q))
+ return true;
+ OpsMaybeZero = true;
----------------
goldsteinn wrote:
Oh missed that you ended that with a question. I don't think it really makes a difference but ended up changing.
https://github.com/llvm/llvm-project/pull/88170
More information about the llvm-commits
mailing list