@@ -2828,23 +2828,47 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
2828
2828
case Intrinsic::uadd_sat:
2829
2829
return isKnownNonZero (II->getArgOperand (1 ), DemandedElts, Depth, Q) ||
2830
2830
isKnownNonZero (II->getArgOperand (0 ), DemandedElts, Depth, Q);
2831
- case Intrinsic::smin:
2832
2831
case Intrinsic::smax: {
2833
- auto KnownOpImpliesNonZero = [&](const KnownBits &K) {
2834
- return II->getIntrinsicID () == Intrinsic::smin
2835
- ? K.isNegative ()
2836
- : K.isStrictlyPositive ();
2837
- };
2838
- KnownBits XKnown =
2832
+ // if either arg is strictly positive the result is non-zero. Otherwise
2833
+ // the result is non-zero if both ops are non-zero.
2834
+ KnownBits Op1Known =
2835
+ computeKnownBits (II->getArgOperand (1 ), DemandedElts, Depth, Q);
2836
+ // Avoid re-computing isKnownNonZero if we already failed once.
2837
+ bool OpsMaybeZero = false ;
2838
+ if (Op1Known.isNonNegative ()) {
2839
+ if (Op1Known.isNonZero () ||
2840
+ isKnownNonZero (II->getArgOperand (1 ), DemandedElts, Depth, Q))
2841
+ return true ;
2842
+ OpsMaybeZero = true ;
2843
+ }
2844
+ KnownBits Op0Known =
2839
2845
computeKnownBits (II->getArgOperand (0 ), DemandedElts, Depth, Q);
2840
- if (KnownOpImpliesNonZero (XKnown))
2841
- return true ;
2842
- KnownBits YKnown =
2846
+ if (Op0Known.isNonNegative ()) {
2847
+ if (Op0Known.isNonZero () ||
2848
+ isKnownNonZero (II->getArgOperand (0 ), DemandedElts, Depth, Q))
2849
+ return true ;
2850
+ OpsMaybeZero = true ;
2851
+ }
2852
+ // We already failed at least one call to isKnownNonZero
2853
+ if (OpsMaybeZero)
2854
+ break ;
2855
+ return isKnownNonZero (II->getArgOperand (0 ), DemandedElts, Depth, Q) &&
2856
+ isKnownNonZero (II->getArgOperand (1 ), DemandedElts, Depth, Q);
2857
+ }
2858
+
2859
+ case Intrinsic::smin: {
2860
+ // if either arg is negative the result is non-zero. Otherwise
2861
+ // the result is non-zero if both ops are non-zero.
2862
+ KnownBits Op1Known =
2843
2863
computeKnownBits (II->getArgOperand (1 ), DemandedElts, Depth, Q);
2844
- if (KnownOpImpliesNonZero (YKnown))
2864
+ if (Op1Known.isNegative ())
2865
+ return true ;
2866
+ KnownBits Op0Known =
2867
+ computeKnownBits (II->getArgOperand (0 ), DemandedElts, Depth, Q);
2868
+ if (Op0Known.isNegative ())
2845
2869
return true ;
2846
2870
2847
- if (XKnown .isNonZero () && YKnown .isNonZero ())
2871
+ if (Op1Known .isNonZero () && Op0Known .isNonZero ())
2848
2872
return true ;
2849
2873
}
2850
2874
[[fallthrough]];
0 commit comments