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

Iris Shi via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 14 08:49:50 PDT 2025


================
@@ -1298,6 +1298,21 @@ 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 ((X >> C) | (X & mask(C) != 0)), 0 -> icmp eq/ne X, 0
+  if (ICmpInst::isEquality(Pred)) {
+    Value *X;
+    const APInt *C1, *C2;
+    if (match(Cmp.getOperand(0),
+              m_OneUse(m_c_Or(
----------------
el-ev wrote:

It seems that removing the check results in an extra icmp in some cases.

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


More information about the llvm-commits mailing list