summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-10-13 21:28:50 +0000
committerSanjay Patel <spatel@rotateright.com>2017-10-13 21:28:50 +0000
commitb869f76d850ca9c14face41014cc708b488e7724 (patch)
tree911355812334db64c9c6ef6c5257f427b4114f71 /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
parent11300cead8fd7ecc31f71cdf493e69e4c66a5e82 (diff)
downloadbcm5719-llvm-b869f76d850ca9c14face41014cc708b488e7724.tar.gz
bcm5719-llvm-b869f76d850ca9c14face41014cc708b488e7724.zip
[InstCombine] use m_Neg() to reduce code; NFCI
llvm-svn: 315762
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp22
1 files changed, 9 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 2962300a57d..85572f91cd3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1098,22 +1098,19 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
return Shl;
}
- // -A + B --> B - A
- // -A + -B --> -(A + B)
- if (Value *LHSV = dyn_castNegVal(LHS)) {
- if (!isa<Constant>(RHS))
- if (Value *RHSV = dyn_castNegVal(RHS)) {
- Value *NewAdd = Builder.CreateAdd(LHSV, RHSV, "sum");
- return BinaryOperator::CreateNeg(NewAdd);
- }
+ Value *A, *B;
+ if (match(LHS, m_Neg(m_Value(A)))) {
+ // -A + -B --> -(A + B)
+ if (match(RHS, m_Neg(m_Value(B))))
+ return BinaryOperator::CreateNeg(Builder.CreateAdd(A, B));
- return BinaryOperator::CreateSub(RHS, LHSV);
+ // -A + B --> B - A
+ return BinaryOperator::CreateSub(RHS, A);
}
// A + -B --> A - B
- if (!isa<Constant>(RHS))
- if (Value *V = dyn_castNegVal(RHS))
- return BinaryOperator::CreateSub(LHS, V);
+ if (match(RHS, m_Neg(m_Value(B))))
+ return BinaryOperator::CreateSub(LHS, B);
if (Value *V = checkForNegativeOperand(I, Builder))
return replaceInstUsesWith(I, V);
@@ -1247,7 +1244,6 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
}
}
- Value *A, *B;
// (add (xor A, B) (and A, B)) --> (or A, B)
if (match(LHS, m_Xor(m_Value(A), m_Value(B))) &&
match(RHS, m_c_And(m_Specific(A), m_Specific(B))))
OpenPOWER on IntegriCloud