[llvm-commits] [llvm] r60291 - in /llvm/trunk: lib/Target/README.txt lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/or-to-xor.ll
Bill Wendling
isanbard at gmail.com
Sun Nov 30 05:52:49 PST 2008
Author: void
Date: Sun Nov 30 07:52:49 2008
New Revision: 60291
URL: http://llvm.org/viewvc/llvm-project?rev=60291&view=rev
Log:
Add instruction combining for ((A&~B)|(~A&B)) -> A^B and all permutations.
Added:
llvm/trunk/test/Transforms/InstCombine/or-to-xor.ll
Modified:
llvm/trunk/lib/Target/README.txt
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Modified: llvm/trunk/lib/Target/README.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/README.txt?rev=60291&r1=60290&r2=60291&view=diff
==============================================================================
--- llvm/trunk/lib/Target/README.txt (original)
+++ llvm/trunk/lib/Target/README.txt Sun Nov 30 07:52:49 2008
@@ -1171,12 +1171,6 @@
//===---------------------------------------------------------------------===//
-int a(int a, int b, int c) {return ((a&~b) | (~a&b));}
-Should fold to xor. Currently not optimized with "clang -emit-llvm-bc
-| opt -std-compile-opts".
-
-//===---------------------------------------------------------------------===//
-
int a(int a, int b, int c) {return (~a & c) | ((c|a) & b);}
Should fold to "(~a & c) | (a & b)". Currently not optimized with
"clang -emit-llvm-bc | opt -std-compile-opts".
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=60291&r1=60290&r2=60291&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sun Nov 30 07:52:49 2008
@@ -4638,6 +4638,29 @@
return Match;
if (Instruction *Match = MatchSelectFromAndOr(D, A, B, C))
return Match;
+
+ V1 = V2 = 0;
+
+ // ((A&~B)|(~A&B)) -> A^B
+ if ((match(C, m_Not(m_Value(V1))) &&
+ match(B, m_Not(m_Value(V2)))))
+ if (V1 == D && V2 == A)
+ return BinaryOperator::CreateXor(V1, V2);
+ // ((~B&A)|(~A&B)) -> A^B
+ if ((match(A, m_Not(m_Value(V1))) &&
+ match(B, m_Not(m_Value(V2)))))
+ if (V1 == D && V2 == C)
+ return BinaryOperator::CreateXor(V1, V2);
+ // ((A&~B)|(B&~A)) -> A^B
+ if ((match(C, m_Not(m_Value(V1))) &&
+ match(D, m_Not(m_Value(V2)))))
+ if (V1 == B && V2 == A)
+ return BinaryOperator::CreateXor(V1, V2);
+ // ((~B&A)|(B&~A)) -> A^B
+ if ((match(A, m_Not(m_Value(V1))) &&
+ match(D, m_Not(m_Value(V2)))))
+ if (V1 == B && V2 == C)
+ return BinaryOperator::CreateXor(V1, V2);
}
// (X >> Z) | (Y >> Z) -> (X|Y) >> Z for all shifts.
Added: llvm/trunk/test/Transforms/InstCombine/or-to-xor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or-to-xor.ll?rev=60291&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/or-to-xor.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/or-to-xor.ll Sun Nov 30 07:52:49 2008
@@ -0,0 +1,42 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {xor i32 %b, %a} | count 4
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep {and}
+
+define i32 @func1(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %b_not = xor i32 %b, -1
+ %0 = and i32 %a, %b_not
+ %a_not = xor i32 %a, -1
+ %1 = and i32 %a_not, %b
+ %2 = or i32 %0, %1
+ ret i32 %2
+}
+
+define i32 @func2(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %b_not = xor i32 %b, -1
+ %0 = and i32 %b_not, %a
+ %a_not = xor i32 %a, -1
+ %1 = and i32 %a_not, %b
+ %2 = or i32 %0, %1
+ ret i32 %2
+}
+
+define i32 @func3(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %b_not = xor i32 %b, -1
+ %0 = and i32 %a, %b_not
+ %a_not = xor i32 %a, -1
+ %1 = and i32 %b, %a_not
+ %2 = or i32 %0, %1
+ ret i32 %2
+}
+
+define i32 @func4(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %b_not = xor i32 %b, -1
+ %0 = and i32 %b_not, %a
+ %a_not = xor i32 %a, -1
+ %1 = and i32 %b, %a_not
+ %2 = or i32 %0, %1
+ ret i32 %2
+}
More information about the llvm-commits
mailing list