Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1279,7 +1279,8 @@ return BinaryOperator::CreateAnd(A, Op1); if (match(Op1, m_Or(m_Not(m_Specific(Op0)), m_Value(A))) || match(Op1, m_Or(m_Value(A), m_Not(m_Specific(Op0))))) - return BinaryOperator::CreateAnd(A, Op0); + return BinaryOperator::CreateAnd(A, Op0); + } if (ICmpInst *RHS = dyn_cast(Op1)) @@ -1982,6 +1983,11 @@ return BinaryOperator::CreateXor(NOr, C1); } + // (A^B) | (~(A)^B) -> 1 + if(match(Op0,m_Xor(m_Value(A),m_Value(B))) + && match(Op1,m_Xor(m_Not(m_Specific(A)),m_Specific(B)))) + return BinaryOperator::CreateOr(A, Builder->CreateNot(A)); + // (A & C)|(B & D) Value *C = nullptr, *D = nullptr; if (match(Op0, m_And(m_Value(A), m_Value(C))) && Index: test/Transforms/InstCombine/or.ll =================================================================== --- test/Transforms/InstCombine/or.ll +++ test/Transforms/InstCombine/or.ll @@ -408,3 +408,13 @@ %or = or i32 %x, %sext ret i32 %or } + +define i32 @test39(i32%x,i32%y){ +; CHECK-LABEL: @test39( +; CHECK-NEXT: ret i32 -1 +%xor = xor i32%x,%y +%nega = xor i32%x,-1 +%xor1 = xor i32%nega,%y +%or = or i32%xor,%xor1 +ret i32 %or +}