diff options
author | Michael Berg <michael_c_berg@apple.com> | 2018-08-09 17:00:03 +0000 |
---|---|---|
committer | Michael Berg <michael_c_berg@apple.com> | 2018-08-09 17:00:03 +0000 |
commit | ca38254601ce7b0f9b096d54cf9b4e2ebaa4716b (patch) | |
tree | c677f0da3704073a2d99597696a11b5e264578a3 /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | |
parent | 8c4366273cda0928f218fef6b3030e33b69fb447 (diff) | |
download | bcm5719-llvm-ca38254601ce7b0f9b096d54cf9b4e2ebaa4716b.tar.gz bcm5719-llvm-ca38254601ce7b0f9b096d54cf9b4e2ebaa4716b.zip |
extend folding fsub/fadd to fneg for FMF
Summary: This change provides a common optimization path for both Unsafe and FMF driven optimization for this fsub fold adding reassociation, as it the flag that most closely represents the translation
Reviewers: spatel, wristow, arsenm
Reviewed By: spatel
Subscribers: wdng
Differential Revision: https://reviews.llvm.org/D50195
llvm-svn: 339357
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index f78688787dd..5bf0e1635a6 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -10935,20 +10935,22 @@ SDValue DAGCombiner::visitFSUB(SDNode *N) { } } - // fold (fsub A, (fneg B)) -> (fadd A, B) - if (isNegatibleForFree(N1, LegalOperations, TLI, &Options)) - return DAG.getNode(ISD::FADD, DL, VT, N0, - GetNegatedExpression(N1, DAG, LegalOperations), Flags); - - if (Options.UnsafeFPMath && N1.getOpcode() == ISD::FADD) { + if ((Options.UnsafeFPMath || + (Flags.hasAllowReassociation() && Flags.hasNoSignedZeros())) + && N1.getOpcode() == ISD::FADD) { // X - (X + Y) -> -Y if (N0 == N1->getOperand(0)) - return DAG.getNode(ISD::FNEG, DL, VT, N1->getOperand(1)); + return DAG.getNode(ISD::FNEG, DL, VT, N1->getOperand(1), Flags); // X - (Y + X) -> -Y if (N0 == N1->getOperand(1)) - return DAG.getNode(ISD::FNEG, DL, VT, N1->getOperand(0)); + return DAG.getNode(ISD::FNEG, DL, VT, N1->getOperand(0), Flags); } + // fold (fsub A, (fneg B)) -> (fadd A, B) + if (isNegatibleForFree(N1, LegalOperations, TLI, &Options)) + return DAG.getNode(ISD::FADD, DL, VT, N0, + GetNegatedExpression(N1, DAG, LegalOperations), Flags); + // FSUB -> FMA combines: if (SDValue Fused = visitFSUBForFMACombine(N)) { AddToWorklist(Fused.getNode()); |