Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2528,6 +2528,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) -> ((~B) & C) + if (match(Op0I, m_Or(m_Value(A), m_Value(B))) && + match(Op1I, m_Or(m_Xor(m_Specific(A), m_Value(C)), m_Specific(B)))) + return BinaryOperator::CreateAnd(Builder->CreateNot(B), 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,15 @@ ; CHECK-NEXT: %1 = and i32 %a, %b ; CHECK-NEXT: %xor = xor i32 %1, -1 } + +define i32 @test15(i32 %x, i32 %y, i32 %z) { +; CHECK-LABEL: @test15( +; CHECK-NEXT: %1 = xor i32 %y, -1 +; CHECK-NEXT: %xor1 = and i32 %1, %z +; CHECK-NEXT: ret i32 %xor1 + %and = or i32 %x, %y + %xor = xor i32 %x, %z + %or = or i32 %xor, %y + %xor1 = xor i32 %and, %or + ret i32 %xor1 +}