1
0
mirror of https://github.com/c64scene-ar/llvm-6502.git synced 2024-12-15 04:30:12 +00:00

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

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214479 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Suyog Sarda 2014-08-01 05:07:20 +00:00
parent 78061f4db4
commit 1952b5a4da
2 changed files with 27 additions and 0 deletions
lib/Transforms/InstCombine
test/Transforms/InstCombine

View File

@ -2524,6 +2524,11 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
match(Op1, m_Not(m_Specific(A)))) match(Op1, m_Not(m_Specific(A))))
return BinaryOperator::CreateOr(A, Builder->CreateNot(B)); return BinaryOperator::CreateOr(A, Builder->CreateNot(B));
// (A & ~B) ^ (~A) -> ~(A & B)
if (match(Op0, m_And(m_Value(A), m_Not(m_Value(B)))) &&
match(Op1, m_Not(m_Specific(A))))
return BinaryOperator::CreateNot(Builder->CreateAnd(A, B));
// (icmp1 A, B) ^ (icmp2 A, B) --> (icmp3 A, B) // (icmp1 A, B) ^ (icmp2 A, B) --> (icmp3 A, B)
if (ICmpInst *RHS = dyn_cast<ICmpInst>(I.getOperand(1))) if (ICmpInst *RHS = dyn_cast<ICmpInst>(I.getOperand(1)))
if (ICmpInst *LHS = dyn_cast<ICmpInst>(I.getOperand(0))) if (ICmpInst *LHS = dyn_cast<ICmpInst>(I.getOperand(0)))

View File

@ -145,3 +145,25 @@ define i32 @test12(i32 %A, i32 %B) {
; CHECK-LABEL: @test12( ; CHECK-LABEL: @test12(
; CHECK-NEXT: ret i32 0 ; CHECK-NEXT: ret i32 0
} }
define i32 @test13(i32 %a, i32 %b) {
%negb = xor i32 %b, -1
%and = and i32 %a, %negb
%nega = xor i32 %a, -1
%xor = xor i32 %and, %nega
ret i32 %xor
; CHECK-LABEL: @test13(
; CHECK-NEXT: %1 = and i32 %a, %b
; CHECK-NEXT: %xor = xor i32 %1, -1
}
define i32 @test14(i32 %a, i32 %b) {
%nega = xor i32 %a, -1
%negb = xor i32 %b, -1
%and = and i32 %a, %negb
%xor = xor i32 %nega, %and
ret i32 %xor
; CHECK-LABEL: @test14(
; CHECK-NEXT: %1 = and i32 %a, %b
; CHECK-NEXT: %xor = xor i32 %1, -1
}