reapply benjamin's instcombine patch, I don't see anything wrong with it and can...
authorChris Lattner <sabre@nondot.org>
Wed, 14 Jul 2010 05:59:13 +0000 (05:59 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 14 Jul 2010 05:59:13 +0000 (05:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108320 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
test/Transforms/InstCombine/or.ll

index 3f4a857c41a5ad53ee9b1ba854c99688b9eea215..4542dda63721367b0bda4202c97053dfffa15f39 100644 (file)
@@ -1597,6 +1597,14 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
       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.
index c3526b77f6a5b15948bade8fe8c4a77a7980ff12..0246925bd82a31b6bcc49c95322a1707387882db 100644 (file)
@@ -350,3 +350,16 @@ define <4 x i32> @test32(<4 x i1> %and.i1352, <4 x i32> %vecinit6.i176, <4 x i32
 ; 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
+}