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

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 22:27:31 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))) &&
+          C->isOneBitSet(DemandedMask.getBitWidth() -
----------------
topperc wrote:

You can use `DemandedMask.getActiveBits() - 1`

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


More information about the llvm-commits mailing list