[llvm] r299747 - [InstCombine] Handle more commuted cases of ((A & B) | ~A) -> (~A | B)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 7 00:32:01 PDT 2017


Author: ctopper
Date: Fri Apr  7 02:32:00 2017
New Revision: 299747

URL: http://llvm.org/viewvc/llvm-project?rev=299747&view=rev
Log:
[InstCombine] Handle more commuted cases of ((A & B) | ~A) -> (~A | B)

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
    llvm/trunk/test/Transforms/InstCombine/or.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=299747&r1=299746&r2=299747&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Fri Apr  7 02:32:00 2017
@@ -2098,9 +2098,10 @@ Instruction *InstCombiner::visitOr(Binar
     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)

Modified: llvm/trunk/test/Transforms/InstCombine/or.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or.ll?rev=299747&r1=299746&r2=299747&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/or.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/or.ll Fri Apr  7 02:32:00 2017
@@ -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




More information about the llvm-commits mailing list