From bfa0442391b10e24dd9f1c19243a92f34f81ec14 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Fri, 13 Oct 2017 21:28:50 +0000 Subject: [PATCH] [InstCombine] use m_Neg() to reduce code; NFCI git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315762 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../InstCombine/InstCombineAddSub.cpp | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 2962300a57d..85572f91cd3 100644 --- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/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(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(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))))