forked from OSchip/llvm-project
This patch implements transform for pattern "(A & B) | ((~A) ^ B) -> (~A ^ B)".
Patch Credit to Ankit Jain ! Differential Revision: http://reviews.llvm.org/D4655 llvm-svn: 214476
This commit is contained in:
parent
aa9a1a813e
commit
16d646594e
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue