[llvm] [InstCombine] Fold Xor with or disjoint (PR #105992)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 22 03:28:22 PDT 2024
================
@@ -4693,7 +4693,20 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) {
// calls in there are unnecessary as SimplifyDemandedInstructionBits should
// have already taken care of those cases.
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
- Value *M;
+ Value *X, *Y, *M;
+
+ // (X | Y) ^ M -> (X ^ M) ^ Y
+ // (X | Y) ^ M -> (Y ^ M) ^ X
+ if (match(&I, m_c_Xor(m_OneUse(m_DisjointOr(m_Value(X), m_Value(Y))),
+ m_Value(M)))) {
+ if (Value *XorAC =
+ simplifyBinOp(Instruction::Xor, X, M, SQ.getWithInstruction(&I)))
+ return BinaryOperator::CreateXor(XorAC, Y);
+
+ if (Value *XorBC = simplifyBinOp(Instruction::Xor, Y, M, SQ))
----------------
nikic wrote:
```suggestion
if (Value *XorBC = simplifyXorInst(Y, M, SQ.getWithInstruction(&I)))
```
https://github.com/llvm/llvm-project/pull/105992
More information about the llvm-commits
mailing list