summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-08-08 16:19:22 +0000
committerSanjay Patel <spatel@rotateright.com>2018-08-08 16:19:22 +0000
commitfe839695a8b9986da53f5587e901aca0a4e46c90 (patch)
tree744b3ce48922ce7e2420073fd4ca7b3f4f74ded3 /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
parent2054dd79c200f2a3b7d6e770dd92a1908fbc25dc (diff)
downloadbcm5719-llvm-fe839695a8b9986da53f5587e901aca0a4e46c90.tar.gz
bcm5719-llvm-fe839695a8b9986da53f5587e901aca0a4e46c90.zip
[InstCombine] fold fadd+fsub with common operand
This is a sibling to the simplify from: https://reviews.llvm.org/rL339174 llvm-svn: 339267
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index f3fe09f1cb0..8b355dcd1b2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1911,6 +1911,11 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) {
if (match(Op0, m_FSub(m_Specific(Op1), m_Value(X))))
return BinaryOperator::CreateFNegFMF(X, &I);
+ // Y - (X + Y) --> -X
+ // Y - (Y + X) --> -X
+ if (match(Op1, m_c_FAdd(m_Specific(Op0), m_Value(X))))
+ return BinaryOperator::CreateFNegFMF(X, &I);
+
// TODO: This performs reassociative folds for FP ops. Some fraction of the
// functionality has been subsumed by simple pattern matching here and in
// InstSimplify. We should let a dedicated reassociation pass handle more
OpenPOWER on IntegriCloud