mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-14 15:38:57 +00:00
Add instcombine patterns for the following transformations:
(x & y) | (x ^ y) -> x | y (x & y) + (x ^ y) -> x | y Patch by Manman Ren. rdar://10770603 llvm-svn: 155674
This commit is contained in:
parent
4be3b28946
commit
f3d4646377
@ -329,6 +329,20 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for (x & y) + (x ^ y)
|
||||||
|
{
|
||||||
|
Value *A = 0, *B = 0;
|
||||||
|
if (match(RHS, m_Xor(m_Value(A), m_Value(B))) &&
|
||||||
|
(match(LHS, m_And(m_Specific(A), m_Specific(B))) ||
|
||||||
|
match(LHS, m_And(m_Specific(B), m_Specific(A)))))
|
||||||
|
return BinaryOperator::CreateOr(A, B);
|
||||||
|
|
||||||
|
if (match(LHS, m_Xor(m_Value(A), m_Value(B))) &&
|
||||||
|
(match(RHS, m_And(m_Specific(A), m_Specific(B))) ||
|
||||||
|
match(RHS, m_And(m_Specific(B), m_Specific(A)))))
|
||||||
|
return BinaryOperator::CreateOr(A, B);
|
||||||
|
}
|
||||||
|
|
||||||
return Changed ? &I : 0;
|
return Changed ? &I : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1932,10 +1932,15 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
|||||||
|
|
||||||
// A | ( A ^ B) -> A | B
|
// A | ( A ^ B) -> A | B
|
||||||
// A | (~A ^ B) -> A | ~B
|
// A | (~A ^ B) -> A | ~B
|
||||||
|
// (A & B) | (A ^ B)
|
||||||
if (match(Op1, m_Xor(m_Value(A), m_Value(B)))) {
|
if (match(Op1, m_Xor(m_Value(A), m_Value(B)))) {
|
||||||
if (Op0 == A || Op0 == B)
|
if (Op0 == A || Op0 == B)
|
||||||
return BinaryOperator::CreateOr(A, B);
|
return BinaryOperator::CreateOr(A, B);
|
||||||
|
|
||||||
|
if (match(Op0, m_And(m_Specific(A), m_Specific(B))) ||
|
||||||
|
match(Op0, m_And(m_Specific(B), m_Specific(A))))
|
||||||
|
return BinaryOperator::CreateOr(A, B);
|
||||||
|
|
||||||
if (Op1->hasOneUse() && match(A, m_Not(m_Specific(Op0)))) {
|
if (Op1->hasOneUse() && match(A, m_Not(m_Specific(Op0)))) {
|
||||||
Value *Not = Builder->CreateNot(B, B->getName()+".not");
|
Value *Not = Builder->CreateNot(B, B->getName()+".not");
|
||||||
return BinaryOperator::CreateOr(Not, Op0);
|
return BinaryOperator::CreateOr(Not, Op0);
|
||||||
|
24
test/Transforms/InstCombine/and-xor-or.ll
Normal file
24
test/Transforms/InstCombine/and-xor-or.ll
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
||||||
|
|
||||||
|
; rdar://10770603
|
||||||
|
; (x & y) | (x ^ y) -> x | y
|
||||||
|
define i64 @or(i64 %x, i64 %y) nounwind uwtable readnone ssp {
|
||||||
|
%1 = and i64 %y, %x
|
||||||
|
%2 = xor i64 %y, %x
|
||||||
|
%3 = add i64 %1, %2
|
||||||
|
ret i64 %3
|
||||||
|
; CHECK: @or
|
||||||
|
; CHECK: or i64
|
||||||
|
; CHECK-NEXT: ret
|
||||||
|
}
|
||||||
|
|
||||||
|
; (x & y) + (x ^ y) -> x | y
|
||||||
|
define i64 @or2(i64 %x, i64 %y) nounwind uwtable readnone ssp {
|
||||||
|
%1 = and i64 %y, %x
|
||||||
|
%2 = xor i64 %y, %x
|
||||||
|
%3 = or i64 %1, %2
|
||||||
|
ret i64 %3
|
||||||
|
; CHECK: @or2
|
||||||
|
; CHECK: or i64
|
||||||
|
; CHECK-NEXT: ret
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user