[llvm] [InstCombine] Change (add x, c) to (xor x, c) (PR #75129)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 01:25:08 PST 2023


================
@@ -552,6 +552,16 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
     if (DemandedFromOps.isSubsetOf(LHSKnown.Zero))
       return I->getOperand(1);
 
+    // (add X, C) --> (xor X, C) IFF C is equal to the top bit of the DemandMask
+    {
+      Value *X;
+      const APInt *C;
+      if (match(I, m_Add(m_Value(X), m_APInt(C))) &&
----------------
nikic wrote:

```suggestion
      if (match(I->getOperand(1), m_APInt(C)) &&
```
We already know that this is an `add`, so I think we can just check the operand here.

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


More information about the llvm-commits mailing list