Skip to content

Commit 6d150a3

Browse files
committed
Remove UnsafeFPMath in visitFADDForFMACombine
1 parent 12b2652 commit 6d150a3

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16914,8 +16914,7 @@ SDValue DAGCombiner::visitFADDForFMACombine(SDNode *N) {
1691416914
// fadd (G, (fma A, B, (fma (C, D, (fmul (E, F)))))) -->
1691516915
// fma A, B, (fma C, D, fma (E, F, G)).
1691616916
// This requires reassociation because it changes the order of operations.
16917-
bool CanReassociate =
16918-
Options.UnsafeFPMath || N->getFlags().hasAllowReassociation();
16917+
bool CanReassociate = N->getFlags().hasAllowReassociation();
1691916918
if (CanReassociate) {
1692016919
SDValue FMA, E;
1692116920
if (isFusedOp(N0) && N0.hasOneUse()) {
@@ -18087,8 +18086,7 @@ template <class MatchContextClass> SDValue DAGCombiner::visitFMA(SDNode *N) {
1808718086
return matcher.getNode(ISD::FMA, DL, VT, NegN0, NegN1, N2);
1808818087
}
1808918088

18090-
// FIXME: use fast math flags instead of Options.UnsafeFPMath
18091-
// TODO: Finally migrate away from global TargetOptions.
18089+
// FIXME: Finally migrate away from global TargetOptions.
1809218090
if (Options.AllowFPOpFusion == FPOpFusion::Fast ||
1809318091
(Options.NoNaNsFPMath && Options.NoInfsFPMath) ||
1809418092
(N->getFlags().hasNoNaNs() && N->getFlags().hasNoInfs())) {
@@ -18112,8 +18110,7 @@ template <class MatchContextClass> SDValue DAGCombiner::visitFMA(SDNode *N) {
1811218110
!DAG.isConstantFPBuildVectorOrConstantFP(N1))
1811318111
return matcher.getNode(ISD::FMA, DL, VT, N1, N0, N2);
1811418112

18115-
bool CanReassociate =
18116-
Options.UnsafeFPMath || N->getFlags().hasAllowReassociation();
18113+
bool CanReassociate = N->getFlags().hasAllowReassociation();
1811718114
if (CanReassociate) {
1811818115
// (fma x, c1, (fmul x, c2)) -> (fmul x, c1+c2)
1811918116
if (matcher.match(N2, ISD::FMUL) && N0 == N2.getOperand(0) &&

llvm/test/CodeGen/NVPTX/fma-assoc.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ define ptx_device float @t1_f32(float %x, float %y, float %z,
2020
; CHECK-UNSAFE-NEXT: st.param.b32 [func_retval0], %r7;
2121
; CHECK-UNSAFE-NEXT: ret;
2222
float %u, float %v) {
23-
%a = fmul float %x, %y
24-
%b = fmul float %u, %v
25-
%c = fadd float %a, %b
26-
%d = fadd float %c, %z
23+
%a = fmul reassoc float %x, %y
24+
%b = fmul reassoc float %u, %v
25+
%c = fadd reassoc float %a, %b
26+
%d = fadd reassoc float %c, %z
2727
ret float %d
2828
}
2929

@@ -43,10 +43,10 @@ define ptx_device double @t1_f64(double %x, double %y, double %z,
4343
; CHECK-UNSAFE-NEXT: st.param.b64 [func_retval0], %rd7;
4444
; CHECK-UNSAFE-NEXT: ret;
4545
double %u, double %v) {
46-
%a = fmul double %x, %y
47-
%b = fmul double %u, %v
48-
%c = fadd double %a, %b
49-
%d = fadd double %c, %z
46+
%a = fmul reassoc double %x, %y
47+
%b = fmul reassoc double %u, %v
48+
%c = fadd reassoc double %a, %b
49+
%d = fadd reassoc double %c, %z
5050
ret double %d
5151
}
5252

0 commit comments

Comments
 (0)