diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 8b355dcd1b2..16e3d742ce0 100644 --- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1892,17 +1892,15 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) { // Similar to above, but look through a cast of the negated value: // X - (fptrunc(-Y)) --> X + fptrunc(Y) - if (match(Op1, m_OneUse(m_FPTrunc(m_FNeg(m_Value(Y)))))) { - Value *TruncY = Builder.CreateFPTrunc(Y, I.getType()); - return BinaryOperator::CreateFAddFMF(Op0, TruncY, &I); - } - // X - (fpext(-Y)) --> X + fpext(Y) - if (match(Op1, m_OneUse(m_FPExt(m_FNeg(m_Value(Y)))))) { - Value *ExtY = Builder.CreateFPExt(Y, I.getType()); - return BinaryOperator::CreateFAddFMF(Op0, ExtY, &I); - } + Type *Ty = I.getType(); + if (match(Op1, m_OneUse(m_FPTrunc(m_FNeg(m_Value(Y)))))) + return BinaryOperator::CreateFAddFMF(Op0, Builder.CreateFPTrunc(Y, Ty), &I); - // Handle specials cases for FSub with selects feeding the operation + // X - (fpext(-Y)) --> X + fpext(Y) + if (match(Op1, m_OneUse(m_FPExt(m_FNeg(m_Value(Y)))))) + return BinaryOperator::CreateFAddFMF(Op0, Builder.CreateFPExt(Y, Ty), &I); + + // Handle special cases for FSub with selects feeding the operation if (Value *V = SimplifySelectsFeedingBinaryOp(I, Op0, Op1)) return replaceInstUsesWith(I, V);