[InstCombine] recycle adds for better efficiency

Also, clean up unnecessary matcher capture variable initializations.

llvm-svn: 315743
This commit is contained in:
Sanjay Patel 2017-10-13 20:12:21 +00:00
parent db65f969f2
commit 28b3aa3663
1 changed files with 20 additions and 25 deletions

View File

@ -1248,36 +1248,31 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
}
}
Value *A, *B;
// (add (xor A, B) (and A, B)) --> (or A, B)
{
Value *A = nullptr, *B = nullptr;
if (match(LHS, m_Xor(m_Value(A), m_Value(B))) &&
match(RHS, m_c_And(m_Specific(A), m_Specific(B))))
return BinaryOperator::CreateOr(A, B);
// (add (and A, B) (xor A, B)) --> (or A, B)
if (match(RHS, m_Xor(m_Value(A), m_Value(B))) &&
match(LHS, m_c_And(m_Specific(A), m_Specific(B))))
return BinaryOperator::CreateOr(A, B);
if (match(LHS, m_Xor(m_Value(A), m_Value(B))) &&
match(RHS, m_c_And(m_Specific(A), m_Specific(B))))
return BinaryOperator::CreateOr(A, B);
}
// (add (or A, B) (and A, B)) --> (add A, B)
{
Value *A = nullptr, *B = nullptr;
if (match(RHS, m_Or(m_Value(A), m_Value(B))) &&
match(LHS, m_c_And(m_Specific(A), m_Specific(B)))) {
auto *New = BinaryOperator::CreateAdd(A, B);
New->setHasNoSignedWrap(I.hasNoSignedWrap());
New->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());
return New;
}
if (match(LHS, m_Or(m_Value(A), m_Value(B))) &&
match(RHS, m_c_And(m_Specific(A), m_Specific(B)))) {
auto *New = BinaryOperator::CreateAdd(A, B);
New->setHasNoSignedWrap(I.hasNoSignedWrap());
New->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());
return New;
I.setOperand(0, A);
I.setOperand(1, B);
return &I;
}
// (add (and A, B) (or A, B)) --> (add A, B)
if (match(RHS, m_Or(m_Value(A), m_Value(B))) &&
match(LHS, m_c_And(m_Specific(A), m_Specific(B)))) {
I.setOperand(0, A);
I.setOperand(1, B);
return &I;
}
// TODO(jingyue): Consider willNotOverflowSignedAdd and