diff options
author | Sven van Haastregt <sven.vanhaastregt@arm.com> | 2022-07-26 09:39:12 +0100 |
---|---|---|
committer | Sven van Haastregt <sven.vanhaastregt@arm.com> | 2022-07-26 09:39:12 +0100 |
commit | c8d91b07bba80ac204a93b61c3dd2b0c79aa2402 (patch) | |
tree | 2d792b2f19b8649005cb19937a484e1eb1a718a5 /llvm/lib/CodeGen | |
parent | [llvm-objdump,ARM] Make dumpARMELFData line up with instructions. (diff) | |
download | llvm-project-c8d91b07bba80ac204a93b61c3dd2b0c79aa2402.tar.gz llvm-project-c8d91b07bba80ac204a93b61c3dd2b0c79aa2402.tar.bz2 llvm-project-c8d91b07bba80ac204a93b61c3dd2b0c79aa2402.zip |
Reassoc FMF should not optimize FMA(a, 0, b) to (b)
Optimizing (a * 0 + b) to (b) requires assuming that a is finite and not
NaN. DAGCombiner will do this optimization when the reassoc fast math
flag is set, which is not correct. Change DAGCombiner to only consider
UnsafeMath for this optimization.
Differential Revision: https://reviews.llvm.org/D130232
Co-authored-by: Andrea Faulds <andrea.faulds@arm.com>
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index c16336eee65b..0edfefa9df61 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -15002,7 +15002,7 @@ SDValue DAGCombiner::visitFMA(SDNode *N) { // FMA nodes have flags that propagate to the created nodes. SelectionDAG::FlagInserter FlagsInserter(DAG, N); - bool UnsafeFPMath = + bool CanReassociate = Options.UnsafeFPMath || N->getFlags().hasAllowReassociation(); // Constant fold FMA. @@ -15026,7 +15026,8 @@ SDValue DAGCombiner::visitFMA(SDNode *N) { CostN1 == TargetLowering::NegatibleCost::Cheaper)) return DAG.getNode(ISD::FMA, DL, VT, NegN0, NegN1, N2); - if (UnsafeFPMath) { + // FIXME: use fast math flags instead of Options.UnsafeFPMath + if (Options.UnsafeFPMath) { if (N0CFP && N0CFP->isZero()) return N2; if (N1CFP && N1CFP->isZero()) @@ -15043,7 +15044,7 @@ SDValue DAGCombiner::visitFMA(SDNode *N) { !DAG.isConstantFPBuildVectorOrConstantFP(N1)) return DAG.getNode(ISD::FMA, SDLoc(N), VT, N1, N0, N2); - if (UnsafeFPMath) { + if (CanReassociate) { // (fma x, c1, (fmul x, c2)) -> (fmul x, c1+c2) if (N2.getOpcode() == ISD::FMUL && N0 == N2.getOperand(0) && DAG.isConstantFPBuildVectorOrConstantFP(N1) && @@ -15084,7 +15085,7 @@ SDValue DAGCombiner::visitFMA(SDNode *N) { } } - if (UnsafeFPMath) { + if (CanReassociate) { // (fma x, c, x) -> (fmul x, (c+1)) if (N1CFP && N0 == N2) { return DAG.getNode( |