Skip to content

Commit b4e8603

Browse files
committed
Move logic into computeKnownBits.
1 parent 823ede1 commit b4e8603

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,7 @@ static bool isKnownNonZero(const Value *V, const APInt &DemandedElts,
278278

279279
bool 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

293284
bool 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

376373
static void computeKnownBitsMul(const Value *Op0, const Value *Op1, bool NSW,

0 commit comments

Comments
 (0)