Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2516,6 +2516,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) -> (~A) + if (match(Op0I, m_And(m_Value(A), m_Value(B))) && + match(Op1I, m_Or(m_Xor(m_Specific(A), m_Value(C)), m_Specific(B)))) + return BinaryOperator::CreateNot(A); } // (A | B)^(~A) -> (A | ~B) Index: test/Transforms/InstCombine/xor2.ll =================================================================== --- test/Transforms/InstCombine/xor2.ll +++ test/Transforms/InstCombine/xor2.ll @@ -167,3 +167,14 @@ ; CHECK-NEXT: %1 = and i32 %a, %b ; CHECK-NEXT: %xor = xor i32 %1, -1 } + +define i32 @test15(i32 %x, i32 %y) { + %and = and i32 %x, %y + %nega = xor i32 %x, -1 + %or = or i32 %nega, %y + %and1 = xor i32 %and, %or + ret i32 %and1 +; CHECK-LABEL: @test15( +; CHECK-NEXT: %and1 = xor i32 %x, -1 +; CHECK-NEXT: ret i32 %and1 +}