[llvm] [InstCombine] Extend (icmp eq/ne (and Z, X), (and Z, Y)) folds (PR #94867)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 9 15:09:32 PDT 2024


================
@@ -5570,10 +5570,25 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
       Z = B;
     }
 
-    if (X) { // Build (X^Y) & Z
-      Op1 = Builder.CreateXor(X, Y);
-      Op1 = Builder.CreateAnd(Op1, Z);
-      return new ICmpInst(Pred, Op1, Constant::getNullValue(Op1->getType()));
+    if (X) {
+      // If X^Y is a negative power of two, then `icmp eq/ne Z, NegP2` will fold
----------------
dtcxzyw wrote:

```suggestion
      // If X^Y is a negative power of two, then `icmp eq/ne (Z & NegP2), 0` will fold
```


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


More information about the llvm-commits mailing list