[InstCombine] reduce code for fadd with fneg operand; NFC

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367224 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sanjay Patel 2019-07-29 13:20:46 +00:00
parent a35ba1f31e
commit 9efe2bcad2

View File

@ -1382,17 +1382,14 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {
if (Instruction *FoldedFAdd = foldBinOpIntoSelectOrPhi(I)) if (Instruction *FoldedFAdd = foldBinOpIntoSelectOrPhi(I))
return FoldedFAdd; return FoldedFAdd;
Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
Value *X;
// (-X) + Y --> Y - X // (-X) + Y --> Y - X
if (match(LHS, m_FNeg(m_Value(X)))) Value *X, *Y;
return BinaryOperator::CreateFSubFMF(RHS, X, &I); if (match(&I, m_c_FAdd(m_FNeg(m_Value(X)), m_Value(Y))))
// Y + (-X) --> Y - X return BinaryOperator::CreateFSubFMF(Y, X, &I);
if (match(RHS, m_FNeg(m_Value(X))))
return BinaryOperator::CreateFSubFMF(LHS, X, &I);
// Check for (fadd double (sitofp x), y), see if we can merge this into an // Check for (fadd double (sitofp x), y), see if we can merge this into an
// integer add followed by a promotion. // integer add followed by a promotion.
Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
if (SIToFPInst *LHSConv = dyn_cast<SIToFPInst>(LHS)) { if (SIToFPInst *LHSConv = dyn_cast<SIToFPInst>(LHS)) {
Value *LHSIntVal = LHSConv->getOperand(0); Value *LHSIntVal = LHSConv->getOperand(0);
Type *FPType = LHSConv->getType(); Type *FPType = LHSConv->getType();