This patch implements transform for pattern "(A & B) | ((~A) ^ B) -> (~A ^ B)".

Patch Credit to Ankit Jain !

Differential Revision: http://reviews.llvm.org/D4655



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214476 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Suyog Sarda 2014-08-01 04:41:43 +00:00
parent de55992d54
commit 87569413b0
2 changed files with 32 additions and 0 deletions

View File

@ -2167,6 +2167,16 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
return BinaryOperator::CreateOr(Not, Op0);
}
// (A & B) | ((~A) ^ B) -> (~A ^ B)
if (match(Op0, m_And(m_Value(A), m_Value(B))) &&
match(Op1, m_Xor(m_Not(m_Specific(A)), m_Specific(B))))
return BinaryOperator::CreateXor(Builder->CreateNot(A), B);
// ((~A) ^ B) | (A & B) -> (~A ^ B)
if (match(Op0, m_Xor(m_Not(m_Value(A)), m_Value(B))) &&
match(Op1, m_And(m_Specific(A), m_Specific(B))))
return BinaryOperator::CreateXor(Builder->CreateNot(A), B);
if (SwappedForXor)
std::swap(Op0, Op1);

View File

@ -427,3 +427,25 @@ define i32 @test40(i32 %a, i32 %b) {
%or = or i32 %and, %xor
ret i32 %or
}
define i32 @test41(i32 %a, i32 %b) {
; CHECK-LABEL: test41(
; CHECK-NEXT: %1 = xor i32 %a, -1
; CHECK-NEXT: %or = xor i32 %1, %b
%and = and i32 %a, %b
%nega = xor i32 %a, -1
%xor = xor i32 %nega, %b
%or = or i32 %and, %xor
ret i32 %or
}
define i32 @test42(i32 %a, i32 %b) {
; CHECK-LABEL: test42(
; CHECK-NEXT: %1 = xor i32 %a, -1
; CHECK-NEXT: %or = xor i32 %1, %b
%nega = xor i32 %a, -1
%xor = xor i32 %nega, %b
%and = and i32 %a, %b
%or = or i32 %xor, %and
ret i32 %or
}