From fe839695a8b9986da53f5587e901aca0a4e46c90 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Wed, 8 Aug 2018 16:19:22 +0000 Subject: [InstCombine] fold fadd+fsub with common operand This is a sibling to the simplify from: https://reviews.llvm.org/rL339174 llvm-svn: 339267 --- llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp') 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 -- cgit v1.2.3