Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2508,6 +2508,18 @@ if ((A == C && B == D) || (A == D && B == C)) return BinaryOperator::CreateXor(A, B); } + // (A ^ B)^(A | B) -> A & B + if (match(Op0I, m_Xor(m_Value(A), m_Value(B))) && + match(Op1I, m_Or(m_Value(C), m_Value(D)))) { + if ((A == C && B == D) || (A == D && B == C)) + return BinaryOperator::CreateAnd(A, B); + } + // (A | B)^(A ^ B) -> A & B + if (match(Op0I, m_Or(m_Value(A), m_Value(B))) && + match(Op1I, m_Xor(m_Value(C), m_Value(D)))) { + if ((A == C && B == D) || (A == D && B == C)) + return BinaryOperator::CreateAnd(A, B); + } // (A & B) ^ (A ^ B) -> (A | B) if (match(Op0I, m_And(m_Value(A), m_Value(B))) && match(Op1I, m_Xor(m_Specific(A), m_Specific(B)))) Index: test/Transforms/InstCombine/or-xor.ll =================================================================== --- test/Transforms/InstCombine/or-xor.ll +++ test/Transforms/InstCombine/or-xor.ll @@ -136,3 +136,13 @@ ; CHECK-NEXT: %and = and i32 %x, %y ; CHECK-NEXT: ret i32 %and } + +define i32 @test15(i32 %x, i32 %y) { + %1 = xor i32 %y, %x + %2 = or i32 %y, %x + %3 = xor i32 %2, %1 + ret i32 %3 +; CHECK-LABEL: @test15( +; CHECK-NEXT: %1 = and i32 %y, %x +; CHECK-NEXT: ret i32 %1 +}