[llvm] r315743 - [InstCombine] recycle adds for better efficiency
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 13 13:12:21 PDT 2017
Author: spatel
Date: Fri Oct 13 13:12:21 2017
New Revision: 315743
URL: http://llvm.org/viewvc/llvm-project?rev=315743&view=rev
Log:
[InstCombine] recycle adds for better efficiency
Also, clean up unnecessary matcher capture variable initializations.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=315743&r1=315742&r2=315743&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Fri Oct 13 13:12:21 2017
@@ -1248,36 +1248,31 @@ Instruction *InstCombiner::visitAdd(Bina
}
}
+ Value *A, *B;
// (add (xor A, B) (and A, B)) --> (or A, B)
- {
- Value *A = nullptr, *B = nullptr;
- 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);
- 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);
// (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)))) {
+ I.setOperand(0, A);
+ I.setOperand(1, B);
+ return &I;
+ }
- 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;
- }
+ // (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
More information about the llvm-commits
mailing list