[llvm] [InstCombine] Fold `icmp eq/ne (X and C), 0` when partial bits are known (PR #85863)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 03:11:20 PDT 2024


================
@@ -1771,11 +1771,14 @@ Instruction *InstCombinerImpl::foldICmpAndConstConst(ICmpInst &Cmp,
       return new ICmpInst(NewPred, X, Zero);
     }
 
-    APInt NewC2 = *C2;
     KnownBits Know = computeKnownBits(And->getOperand(0), 0, And);
+    if (Know.One.intersects(*C2))
+      return replaceInstUsesWith(
+          Cmp, ConstantInt::getBool(Cmp.getType(), isICMP_NE));
----------------
dtcxzyw wrote:

Before: http://llvm-compile-time-tracker.com/compare.php?from=a747e86caacf0ba3d5272474da8c10eb0b67dbc2&to=fd6783edc42218cf3d197cefe8b89cea41589f4d&stat=instructions%3Au

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


More information about the llvm-commits mailing list