[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 05:54:11 PST 2023
================
@@ -552,6 +552,14 @@ 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
+ {
+ const APInt *C;
+ if (match(I->getOperand(1), m_APInt(C)) &&
+ C->isOneBitSet(DemandedMask.getActiveBits() - 1))
+ return Builder.CreateXor(I->getOperand(0), ConstantInt::get(VTy, *C));
----------------
nikic wrote:
Ah, sorry for missing that. As this is in SimplifyDemanded we should explicitly set the IRBuilder InsertPoint.
https://github.com/llvm/llvm-project/pull/75129
More information about the llvm-commits
mailing list