[llvm-commits] [llvm] r108136 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp test/Transforms/InstCombine/or.ll test/Transforms/InstCombine/xor2.ll
Benjamin Kramer
benny.kra at googlemail.com
Mon Jul 12 04:54:45 PDT 2010
Author: d0k
Date: Mon Jul 12 06:54:45 2010
New Revision: 108136
URL: http://llvm.org/viewvc/llvm-project?rev=108136&view=rev
Log:
instcombine: fold (x & y) | (~x & z) and (x & y) ^ (~x & z) into ((y ^ z) & x) ^ z which is one instruction shorter. (PR6773)
before:
%and = and i32 %y, %x
%neg = xor i32 %x, -1
%and4 = and i32 %z, %neg
%xor = xor i32 %and4, %and
after:
%xor1 = xor i32 %z, %y
%and2 = and i32 %xor1, %x
%xor = xor i32 %and2, %z
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/trunk/test/Transforms/InstCombine/or.ll
llvm/trunk/test/Transforms/InstCombine/xor2.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=108136&r1=108135&r2=108136&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Mon Jul 12 06:54:45 2010
@@ -1584,6 +1584,14 @@
if ((match(A, m_Not(m_Specific(B))) &&
match(D, m_Not(m_Specific(C)))))
return BinaryOperator::CreateXor(C, B);
+
+ // (A & ~C) | (B & C) -> ((B ^ A) & C) ^ 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.
@@ -1920,6 +1928,15 @@
return BinaryOperator::CreateAnd(NewOp, X);
}
}
+
+ // (A & ~C) ^ (B & C) -> ((B ^ A) & C) ^ A
+ if (Op0->hasOneUse() && Op1->hasOneUse() &&
+ match(Op0I, m_And(m_Value(A), m_Not(m_Value(D)))) &&
+ match(Op1I, m_And(m_Value(B), m_Value(D)))) {
+ Value *Xor = Builder->CreateXor(B, A, "xor");
+ Value *And = Builder->CreateAnd(Xor, D, "and");
+ return BinaryOperator::CreateXor(And, A);
+ }
}
// (icmp1 A, B) ^ (icmp2 A, B) --> (icmp3 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=108136&r1=108135&r2=108136&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/or.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/or.ll Mon Jul 12 06:54:45 2010
@@ -350,3 +350,17 @@
; 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
+ %xor = xor i32 %and2, %and
+ ret i32 %xor
+; CHECK: @test33
+; CHECK: xor i32
+; CHECK: and i32
+; CHECK: xor i32
+; CHECK: ret i32
+}
+
Modified: llvm/trunk/test/Transforms/InstCombine/xor2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/xor2.ll?rev=108136&r1=108135&r2=108136&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/xor2.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/xor2.ll Mon Jul 12 06:54:45 2010
@@ -51,3 +51,17 @@
; CHECK: %1 = ashr i32 %A, %B
; CHECK: ret i32 %1
}
+
+; PR6773
+define i32 @test5(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: @test5
+; CHECK: xor i32
+; CHECK: and i32
+; CHECK: xor i32
+; CHECK: ret i32
+}
More information about the llvm-commits
mailing list