Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2542,6 +2542,14 @@ 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) ^ (~B & A) -> (A | ~B) + if (match(Op0I, m_Xor(m_Not(m_Value(A)), m_Value(B))) && + match(Op1I, m_And(m_Not(m_Specific(B)), m_Specific(A)))) + return BinaryOperator::CreateOr(A, Builder->CreateNot(B)); + // (A & ~B) ^ (B ^ ~A) -> (A | ~B) + if (match(Op0I, m_And(m_Value(A), m_Not(m_Value(B)))) && + match(Op1I, m_Xor(m_Specific(B), m_Not(m_Specific(A))))) + return BinaryOperator::CreateOr(A, Builder->CreateNot(B)); } // (A | B)^(~A) -> (A | ~B) Index: test/Transforms/InstCombine/or-xor.ll =================================================================== --- test/Transforms/InstCombine/or-xor.ll +++ test/Transforms/InstCombine/or-xor.ll @@ -139,13 +139,13 @@ ; ((x | y) ^ (x ^ y)) -> (x & y) 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 + %xor = xor i32 %y, %x + %or = or i32 %y, %x + %xor1 = xor i32 %or, %xor + ret i32 %xor1 ; CHECK-LABEL: @test15( -; CHECK-NEXT: %1 = and i32 %y, %x -; CHECK-NEXT: ret i32 %1 +; CHECK-NEXT: %xor1 = and i32 %y, %x +; CHECK-NEXT: ret i32 %xor1 } ; ((x | ~y) ^ (~x | y)) -> x ^ y @@ -160,3 +160,17 @@ ; CHECK-NEXT: %xor = xor i32 %x, %y ; CHECK-NEXT: ret i32 %xor } + +; ((~x ^ y) ^ (~y & x)) -> (x | ~y) +define i32 @test17(i32 %x, i32 %y) { + %notx = xor i32 %x, -1 + %xor1 = xor i32 %notx, %y + %noty = xor i32 %y, -1 + %and = and i32 %noty, %x + %xor2 = xor i32 %xor1, %and + ret i32 %xor2 +; CHECK-LABEL: @test17( +; CHECK-NEXT: %1 = xor i32 %y, -1 +; CHECK-NEXT: %xor2 = or i32 %x, %1 +; CHECK-NEXT: ret i32 %xor2 +}