We have the rule to fold A + B -> A - (-B) only when it is cheaper.
// fold (fadd A, (fneg B)) -> (fsub A, B)
if ((!LegalOperations || TLI.isOperationLegalOrCustom(ISD::FSUB, VT)) &&
TLI.getNegatibleCost(N1, DAG, LegalOperations, ForCodeSize) ==
TargetLowering::NegatibleCost::Cheaper)
return DAG.getNode(
ISD::FSUB, DL, VT, N0,
TLI.getNegatedExpression(N1, DAG, LegalOperations, ForCodeSize), Flags);But for the reverse folding(A - (-B) -> A + B), it is done as long as it is not expensive, which including that it is neutral. This patch fix this transformation that didn't have any gain.
This is a regression. The negate should have been pulled out since it folds into the user for smaller code size