[llvm] [InstCombine] KnownBits::isNonNegative should recognize `b - a` after `a <= b` (PR #145105)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 22 22:08:42 PDT 2025


================
@@ -371,6 +362,12 @@ static void computeKnownBitsAddSub(bool Add, const Value *Op0, const Value *Op1,
 
   computeKnownBits(Op0, DemandedElts, Known2, Q, Depth + 1);
   KnownOut = KnownBits::computeForAddSub(Add, NSW, NUW, Known2, KnownOut);
+
+  if (!Add && NSW)
+    if (std::optional<bool> result =
+            isImpliedByDomCondition(ICmpInst::ICMP_SLE, Op1, Op0, Q.CxtI, Q.DL);
+        *result)
----------------
dtcxzyw wrote:

```suggestion
  if (!Add && NSW && isImpliedByDomCondition(ICmpInst::ICMP_SLE, Op1, Op0, Q.CxtI, Q.DL).value_or(false))
```


https://github.com/llvm/llvm-project/pull/145105


More information about the llvm-commits mailing list