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

Amr Hesham via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 1 12:10:15 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);
+  }
----------------
AmrDeveloper wrote:

So can we do

if X ^ M folds or if Y ^ M folds -> (X ^ M) ^ Y


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


More information about the llvm-commits mailing list