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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 10 04:54:50 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), 0`
+      // will fold to `icmp ult/uge Z, -NegP2` incuring no additional uses.
----------------
nikic wrote:

```suggestion
      // will fold to `icmp ult/uge Z, -NegP2` incurring no additional instructions.
```

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


More information about the llvm-commits mailing list