@@ -278,16 +278,7 @@ static bool isKnownNonZero(const Value *V, const APInt &DemandedElts,
278278
279279bool llvm::isKnownNonNegative (const Value *V, const SimplifyQuery &SQ,
280280 unsigned Depth) {
281- if (computeKnownBits (V, SQ, Depth).isNonNegative ())
282- return true ;
283-
284- Value *X, *Y;
285- if (match (V, m_NSWSub (m_Value (X), m_Value (Y))))
286- if (std::optional<bool > result =
287- isImpliedByDomCondition (ICmpInst::ICMP_SLE, Y, X, SQ.CxtI , SQ.DL ))
288- return *result;
289-
290- return false ;
281+ return computeKnownBits (V, SQ, Depth).isNonNegative ();
291282}
292283
293284bool llvm::isKnownPositive (const Value *V, const SimplifyQuery &SQ,
@@ -371,6 +362,12 @@ static void computeKnownBitsAddSub(bool Add, const Value *Op0, const Value *Op1,
371362
372363 computeKnownBits (Op0, DemandedElts, Known2, Q, Depth + 1 );
373364 KnownOut = KnownBits::computeForAddSub (Add, NSW, NUW, Known2, KnownOut);
365+
366+ if (!Add && NSW)
367+ if (std::optional<bool > result =
368+ isImpliedByDomCondition (ICmpInst::ICMP_SLE, Op1, Op0, Q.CxtI , Q.DL );
369+ *result)
370+ KnownOut.makeNonNegative ();
374371}
375372
376373static void computeKnownBitsMul (const Value *Op0, const Value *Op1, bool NSW,
0 commit comments