Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2552,6 +2552,10 @@ if (match(Op0I, m_Xor(m_Value(A), m_Value(B))) && match(Op1I, m_And(m_Specific(A), m_Specific(B)))) return BinaryOperator::CreateOr(A, B); + // (A ^ B) ^ ((A ^ C) & B) -> (C ^ (B | (A ^ C))) + if (match(Op0I, m_Xor(m_Value(A), m_Value(B))) && + match(Op1I, m_And(m_Xor(m_Specific(A), m_Value(C)), m_Specific(B)))) + return BinaryOperator::CreateXor(C, Builder->CreateOr(B, Builder->CreateXor(A, C))); } // (A | B)^(~A) -> (A | ~B) Index: test/Transforms/InstCombine/xor2.ll =================================================================== --- test/Transforms/InstCombine/xor2.ll +++ test/Transforms/InstCombine/xor2.ll @@ -167,3 +167,28 @@ ; CHECK-NEXT: %1 = and i32 %a, %b ; CHECK-NEXT: %xor = xor i32 %1, -1 } + +define i32 @test15(i32 %a, i32 %b) { +; CHECK-LABEL: test15( +; CHECK-NEXT: %1 = xor i32 %b, -1 +; CHECK-NEXT: %xor2 = and i32 %a, %1 +; CHECK-NEXT: ret i32 %xor2 + %xor1 = xor i32 %a, %b + %not = xor i32 %a, -1 + %and = and i32 %not, %b + %xor2 = xor i32 %xor1, %and + ret i32 %xor2 +} + +define i32 @test16(i32 %a, i32 %b, i32 %c) { +; CHECK-LABEL: test16( +; CHECK-NEXT: %1 = xor i32 %a, %c +; CHECK-NEXT: %2 = or i32 %1, %b +; CHECK-NEXT: %xor2 = xor i32 %2, %c +; CHECK-NEXT: ret i32 %xor2 + %xor1 = xor i32 %a, %b + %not = xor i32 %a, %c + %and = and i32 %not, %b + %xor2 = xor i32 %xor1, %and + ret i32 %xor2 +}