@@ -2833,19 +2833,27 @@ static bool isNonZeroAdd(const APInt &DemandedElts, const SimplifyQuery &Q,
2833
2833
if (matchOpWithOpEqZero (X, Y))
2834
2834
return true ;
2835
2835
2836
- if (NUW)
2836
+ if (NUW) {
2837
+ // X + Y != 0 if X != Y, and X + Y is NUW.
2838
+ if (isKnownNonEqual (X, Y, DemandedElts, Q, Depth))
2839
+ return true ;
2837
2840
return isKnownNonZero (Y, DemandedElts, Q, Depth) ||
2838
2841
isKnownNonZero (X, DemandedElts, Q, Depth);
2842
+ }
2839
2843
2840
2844
KnownBits XKnown = computeKnownBits (X, DemandedElts, Q, Depth);
2841
2845
KnownBits YKnown = computeKnownBits (Y, DemandedElts, Q, Depth);
2842
2846
2843
2847
// If X and Y are both non-negative (as signed values) then their sum is not
2844
2848
// zero unless both X and Y are zero.
2845
- if (XKnown.isNonNegative () && YKnown.isNonNegative ())
2849
+ if (XKnown.isNonNegative () && YKnown.isNonNegative ()) {
2846
2850
if (isKnownNonZero (Y, DemandedElts, Q, Depth) ||
2847
2851
isKnownNonZero (X, DemandedElts, Q, Depth))
2848
2852
return true ;
2853
+ // X + Y != 0 if X != Y, and X + Y are both nonnegative.
2854
+ if (isKnownNonEqual (X, Y, DemandedElts, Q, Depth))
2855
+ return true ;
2856
+ }
2849
2857
2850
2858
// If X and Y are both negative (as signed values) then their sum is not
2851
2859
// zero unless both X and Y equal INT_MIN.
@@ -2859,6 +2867,9 @@ static bool isNonZeroAdd(const APInt &DemandedElts, const SimplifyQuery &Q,
2859
2867
// to INT_MIN.
2860
2868
if (YKnown.One .intersects (Mask))
2861
2869
return true ;
2870
+ // X + Y != 0 because if they are not equal, they cannot both be INT_MIN.
2871
+ if (isKnownNonEqual (X, Y, DemandedElts, Q, Depth))
2872
+ return true ;
2862
2873
}
2863
2874
2864
2875
// The sum of a non-negative number and a power of two is not zero.
0 commit comments