diff options
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 7 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/or.ll | 6 |
2 files changed, 6 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 6b6e362a34c..024949f8eee 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2098,9 +2098,10 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { return BinaryOperator::CreateOr(Op0, A); // ((A & B) | ~A) -> (~A | B) - if (match(Op0, m_And(m_Value(A), m_Value(B))) && - match(Op1, m_Not(m_Specific(A)))) - return BinaryOperator::CreateOr(Builder->CreateNot(A), B); + // The NOT is guaranteed to be in the RHS by complexity ordering. + if (match(Op1, m_Not(m_Value(A))) && + match(Op0, m_c_And(m_Specific(A), m_Value(B)))) + return BinaryOperator::CreateOr(Op1, B); // (A & ~B) | (A ^ B) -> (A ^ B) // (~B & A) | (A ^ B) -> (A ^ B) diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll index 57ceff27053..be1e8e6d4a9 100644 --- a/llvm/test/Transforms/InstCombine/or.ll +++ b/llvm/test/Transforms/InstCombine/or.ll @@ -544,9 +544,8 @@ define i32 @test40(i32 %a, i32 %b) { define i32 @test40b(i32 %a, i32 %b) { ; CHECK-LABEL: @test40b( -; CHECK-NEXT: [[AND:%.*]] = and i32 %b, %a ; CHECK-NEXT: [[XOR:%.*]] = xor i32 %a, -1 -; CHECK-NEXT: [[OR:%.*]] = or i32 [[AND]], [[XOR]] +; CHECK-NEXT: [[OR:%.*]] = or i32 [[XOR]], %b ; CHECK-NEXT: ret i32 [[OR]] ; %and = and i32 %b, %a @@ -557,9 +556,8 @@ define i32 @test40b(i32 %a, i32 %b) { define i32 @test40c(i32 %a, i32 %b) { ; CHECK-LABEL: @test40c( -; CHECK-NEXT: [[AND:%.*]] = and i32 %b, %a ; CHECK-NEXT: [[XOR:%.*]] = xor i32 %a, -1 -; CHECK-NEXT: [[OR:%.*]] = or i32 [[AND]], [[XOR]] +; CHECK-NEXT: [[OR:%.*]] = or i32 [[XOR]], %b ; CHECK-NEXT: ret i32 [[OR]] ; %and = and i32 %b, %a |

