[llvm] [InstCombine] Fold Xor with or disjoint (PR #105992)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 6 11:17:36 PDT 2024


================
@@ -4706,6 +4706,15 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) {
     return Xor;
 
   Value *X, *Y;
+
+  // (A | B) ^ C -> (A ^ C) ^ B
+  // C ^ (A | B) -> B ^ (A ^ C)
+  if (match(&I, m_c_Xor(m_OneUse(m_c_DisjointOr(m_Value(X), m_Value(Y))),
+                        m_Value(M)))) {
+    Value *XorAC = Builder.CreateXor(X, M);
+    return BinaryOperator::CreateXor(XorAC, Y);
+  }
----------------
XChy wrote:

With `simplifyBinOp`, it could not handle the motivating case anymore. @dtcxzyw, could you test the impact of this patch? If it optimizes other cases still, I wouldn't argue about it.

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


More information about the llvm-commits mailing list