[llvm] [InstCombine] Fold `ceil(X / (2 ^ C)) == 0` -> `X == 0` (PR #143683)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 22 01:06:05 PDT 2025


================
@@ -1298,6 +1298,13 @@ Instruction *InstCombinerImpl::foldICmpWithZero(ICmpInst &Cmp) {
     // eq/ne (mul X, Y)) with (icmp eq/ne X/Y) and if X/Y is known non-zero that
     // will fold to a constant elsewhere.
   }
+
+  // (icmp eq/ne f(X), 0) -> (icmp eq/ne X, 0)
+  // where f(X) == 0 if and only if X == 0
+  if (ICmpInst::isEquality(Pred))
+    if (Value *Stripped = stripNullTest(Cmp.getOperand(0)))
+      return new ICmpInst(Pred, Stripped, Cmp.getOperand(1));
----------------
dtcxzyw wrote:

```suggestion
      return new ICmpInst(Pred, Stripped, Constant::getNullValue(Stripped->getType()));
```
We may extend this function to return a value of a different type.


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


More information about the llvm-commits mailing list