[llvm-commits] [llvm] r108152 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp test/Transforms/InstCombine/or.ll

Benjamin Kramer benny.kra at googlemail.com
Mon Jul 12 09:15:48 PDT 2010


Author: d0k
Date: Mon Jul 12 11:15:48 2010
New Revision: 108152

URL: http://llvm.org/viewvc/llvm-project?rev=108152&view=rev
Log:
Reapply the "or" half of r108136, which seems to be less problematic.

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=108152&r1=108151&r2=108152&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Mon Jul 12 11:15:48 2010
@@ -1597,6 +1597,14 @@
       Instruction *Ret = FoldOrWithConstants(I, Op0, A, V1, D);
       if (Ret) return Ret;
     }
+
+    // (A & ~D) | (B & D) -> ((B ^ A) & D) ^ A
+    if (Op0->hasOneUse() && Op1->hasOneUse() &&
+        match(C, m_Not(m_Specific(D)))) {
+      Value *Xor = Builder->CreateXor(B, A, "xor");
+      Value *And = Builder->CreateAnd(Xor, D, "and");
+      return BinaryOperator::CreateXor(And, A);
+    }
   }
   
   // (X >> Z) | (Y >> Z)  -> (X|Y) >> Z  for all shifts.

Modified: llvm/trunk/test/Transforms/InstCombine/or.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or.ll?rev=108152&r1=108151&r2=108152&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/or.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/or.ll Mon Jul 12 11:15:48 2010
@@ -350,3 +350,16 @@
 ; CHECK: or <4 x i32> %and.i, %and.i129
 }
 
+; PR6773
+define i32 @test33(i32 %x, i32 %y, i32 %z) nounwind readnone {
+  %and = and i32 %y, %x
+  %not = xor i32 %x, -1
+  %and2 = and i32 %z, %not
+  %or = or i32 %and2, %and
+  ret i32 %or
+; CHECK: @test33
+; CHECK-NEXT: xor i32
+; CHECK-NEXT: and i32
+; CHECK-NEXT: xor i32
+; CHECK-NEXT: ret i32
+}





More information about the llvm-commits mailing list