[llvm] r213662 - This patch implements transform for pattern "(A | B) ^ (~A) -> (A | ~B)".
Suyog Sarda
suyog.sarda at samsung.com
Tue Jul 22 08:37:39 PDT 2014
Author: suyog
Date: Tue Jul 22 10:37:39 2014
New Revision: 213662
URL: http://llvm.org/viewvc/llvm-project?rev=213662&view=rev
Log:
This patch implements transform for pattern "(A | B) ^ (~A) -> (A | ~B)".
Patch Credit to Ankit Jain !!
Differential Revision: http://reviews.llvm.org/D4588
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
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=213662&r1=213661&r2=213662&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Tue Jul 22 10:37:39 2014
@@ -2446,6 +2446,12 @@ Instruction *InstCombiner::visitXor(Bina
}
}
+ // (A | B)^(~A) -> (A | ~B)
+ Value *A = nullptr, *B = nullptr;
+ if (match(Op0, m_Or(m_Value(A), m_Value(B))) &&
+ match(Op1, m_Not(m_Specific(A))))
+ return BinaryOperator::CreateOr(A, Builder->CreateNot(B));
+
// (icmp1 A, B) ^ (icmp2 A, B) --> (icmp3 A, B)
if (ICmpInst *RHS = dyn_cast<ICmpInst>(I.getOperand(1)))
if (ICmpInst *LHS = dyn_cast<ICmpInst>(I.getOperand(0)))
Modified: llvm/trunk/test/Transforms/InstCombine/xor2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/xor2.ll?rev=213662&r1=213661&r2=213662&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/xor2.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/xor2.ll Tue Jul 22 10:37:39 2014
@@ -82,3 +82,26 @@ define i32 @test6(i32 %x) {
; CHECK: lshr i32 %x, 16
; CHECK: ret
}
+
+
+; (A | B) ^ (~A) -> (A | ~B)
+define i32 @test7(i32 %a, i32 %b) #0 {
+ %or = or i32 %a, %b
+ %neg = xor i32 %a, -1
+ %xor = xor i32 %or, %neg
+ ret i32 %xor
+; CHECK-LABEL: @test7(
+; CHECK-NEXT: %1 = xor i32 %b, -1
+; CHECK-NEXT: %xor = or i32 %a, %1
+}
+
+; (~A) ^ (A | B) -> (A | ~B)
+define i32 @test8(i32 %a, i32 %b) #0 {
+ %neg = xor i32 %a, -1
+ %or = or i32 %a, %b
+ %xor = xor i32 %neg, %or
+ ret i32 %xor
+; CHECK-LABEL: @test8(
+; CHECK-NEXT: %1 = xor i32 %b, -1
+; CHECK-NEXT: %xor = or i32 %a, %1
+}
More information about the llvm-commits
mailing list