Skip to content

Commit 4d54ec2

Browse files
committed
[SelectionDAG] Remove UnsafeFPMath check in visitFADDForFMACombine
1 parent 972ecc3 commit 4d54ec2

File tree

10 files changed

+311
-106
lines changed

10 files changed

+311
-106
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16619,8 +16619,8 @@ SDValue DAGCombiner::visitFADDForFMACombine(SDNode *N) {
1661916619
if (!HasFMAD && !HasFMA)
1662016620
return SDValue();
1662116621

16622-
bool AllowFusionGlobally = (Options.AllowFPOpFusion == FPOpFusion::Fast ||
16623-
Options.UnsafeFPMath || HasFMAD);
16622+
bool AllowFusionGlobally =
16623+
Options.AllowFPOpFusion == FPOpFusion::Fast || HasFMAD;
1662416624
// If the addition is not contractable, do not combine.
1662516625
if (!AllowFusionGlobally && !N->getFlags().hasAllowContract())
1662616626
return SDValue();
@@ -17826,6 +17826,7 @@ template <class MatchContextClass> SDValue DAGCombiner::visitFMA(SDNode *N) {
1782617826
SDValue N2 = N->getOperand(2);
1782717827
ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N0);
1782817828
ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1);
17829+
ConstantFPSDNode *N2CFP = dyn_cast<ConstantFPSDNode>(N2);
1782917830
EVT VT = N->getValueType(0);
1783017831
SDLoc DL(N);
1783117832
const TargetOptions &Options = DAG.getTarget().Options;
@@ -17855,12 +17856,26 @@ template <class MatchContextClass> SDValue DAGCombiner::visitFMA(SDNode *N) {
1785517856
}
1785617857

1785717858
// FIXME: use fast math flags instead of Options.UnsafeFPMath
17858-
if (Options.UnsafeFPMath) {
17859+
// TODO: Finally migrate away from global TargetOptions.
17860+
if (Options.AllowFPOpFusion == FPOpFusion::Fast ||
17861+
Options.NoSignedZerosFPMath || N->getFlags().hasNoSignedZeros()) {
1785917862
if (N0CFP && N0CFP->isZero())
1786017863
return N2;
1786117864
if (N1CFP && N1CFP->isZero())
1786217865
return N2;
1786317866
}
17867+
// Handle (fma x, 0.0, c) and (fma 0.0, x, c)
17868+
if (Options.AllowFPOpFusion == FPOpFusion::Fast ||
17869+
(Options.NoInfsFPMath && Options.NoNaNsFPMath) ||
17870+
(N->getFlags().hasNoInfs() && N->getFlags().hasNoNaNs())) {
17871+
// Fold to c only when c is not -0.0.
17872+
if (N2CFP && !N2CFP->isExactlyValue(-0.0)) {
17873+
if (N0CFP && N0CFP->isZero())
17874+
return N2;
17875+
if (N1CFP && N1CFP->isZero())
17876+
return N2;
17877+
}
17878+
}
1786417879

1786517880
// FIXME: Support splat of constant.
1786617881
if (N0CFP && N0CFP->isExactlyValue(1.0))
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2-
; RUN: llc -mtriple=arm64 -fp-contract=fast -o - %s | FileCheck %s
2+
; RUN: llc -mtriple=arm64 -o - %s | FileCheck %s
33

44

55
; Make sure we don't try to fold an fneg into +0.0, creating an illegal constant
66
; -0.0. It's also good, though not essential, that we don't resort to a litpool.
77
define double @test_fms_fold(double %a, double %b) {
88
; CHECK-LABEL: test_fms_fold:
99
; CHECK: // %bb.0:
10-
; CHECK-NEXT: movi d2, #0000000000000000
11-
; CHECK-NEXT: fmul d1, d1, d2
12-
; CHECK-NEXT: fnmsub d0, d0, d2, d1
10+
; CHECK-NEXT: movi {{d[0-9]+}}, #0000000000000000
1311
; CHECK-NEXT: ret
14-
%mul = fmul double %a, 0.000000e+00
15-
%mul1 = fmul double %b, 0.000000e+00
12+
%mul = fmul fast double %a, 0.000000e+00
13+
%mul1 = fmul fast double %b, 0.000000e+00
1614
%sub = fsub double %mul, %mul1
1715
ret double %sub
1816
}

0 commit comments

Comments
 (0)