Skip to content

Commit 398067a

Browse files
committed
Remove UnsafeMath
1 parent f5891bf commit 398067a

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6414,14 +6414,11 @@ bool CombinerHelper::matchCombineFMinMaxNaN(MachineInstr &MI,
64146414
bool CombinerHelper::matchRepeatedFPDivisor(
64156415
MachineInstr &MI, SmallVector<MachineInstr *> &MatchInfo) const {
64166416
assert(MI.getOpcode() == TargetOpcode::G_FDIV);
6417-
auto *MF = MI.getMF();
6418-
const TargetOptions &Options = MF->getTarget().Options;
64196417

64206418
Register X = MI.getOperand(1).getReg();
64216419
Register Y = MI.getOperand(2).getReg();
64226420

6423-
bool UnsafeMath = Options.UnsafeFPMath;
6424-
if (!UnsafeMath && !MI.getFlag(MachineInstr::MIFlag::FmArcp))
6421+
if (!MI.getFlag(MachineInstr::MIFlag::FmArcp))
64256422
return false;
64266423

64276424
// Skip if current node is a reciprocal/fneg-reciprocal.
@@ -6446,7 +6443,7 @@ bool CombinerHelper::matchRepeatedFPDivisor(
64466443
U.getOperand(2).getReg() == Y && U.getOperand(1).getReg() != Y) {
64476444
// This division is eligible for optimization only if global unsafe math
64486445
// is enabled or if this division allows reciprocal formation.
6449-
if (UnsafeMath || U.getFlag(MachineInstr::MIFlag::FmArcp)) {
6446+
if (U.getFlag(MachineInstr::MIFlag::FmArcp)) {
64506447
MatchInfo.push_back(&U);
64516448
if (dominates(U, *MatchInfo[0]))
64526449
std::swap(MatchInfo[0], MatchInfo.back());

llvm/test/CodeGen/AArch64/fdiv-combine.ll

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ define void @three_fdiv_float(float %D, float %a, float %b, float %c) #0 {
2020
; CHECK-NEXT: fmul s1, s2, s4
2121
; CHECK-NEXT: fmul s2, s3, s4
2222
; CHECK-NEXT: b foo_3f
23-
%div = fdiv float %a, %D
24-
%div1 = fdiv float %b, %D
25-
%div2 = fdiv float %c, %D
23+
%div = fdiv arcp float %a, %D
24+
%div1 = fdiv arcp float %b, %D
25+
%div2 = fdiv arcp float %c, %D
2626
tail call void @foo_3f(float %div, float %div1, float %div2)
2727
ret void
2828
}
@@ -36,9 +36,9 @@ define void @three_fdiv_double(double %D, double %a, double %b, double %c) #0 {
3636
; CHECK-NEXT: fmul d1, d2, d4
3737
; CHECK-NEXT: fmul d2, d3, d4
3838
; CHECK-NEXT: b foo_3d
39-
%div = fdiv double %a, %D
40-
%div1 = fdiv double %b, %D
41-
%div2 = fdiv double %c, %D
39+
%div = fdiv arcp double %a, %D
40+
%div1 = fdiv arcp double %b, %D
41+
%div2 = fdiv arcp double %c, %D
4242
tail call void @foo_3d(double %div, double %div1, double %div2)
4343
ret void
4444
}
@@ -52,9 +52,9 @@ define void @three_fdiv_4xfloat(<4 x float> %D, <4 x float> %a, <4 x float> %b,
5252
; CHECK-NEXT: fmul v1.4s, v2.4s, v4.4s
5353
; CHECK-NEXT: fmul v2.4s, v3.4s, v4.4s
5454
; CHECK-NEXT: b foo_3_4xf
55-
%div = fdiv <4 x float> %a, %D
56-
%div1 = fdiv <4 x float> %b, %D
57-
%div2 = fdiv <4 x float> %c, %D
55+
%div = fdiv arcp <4 x float> %a, %D
56+
%div1 = fdiv arcp <4 x float> %b, %D
57+
%div2 = fdiv arcp <4 x float> %c, %D
5858
tail call void @foo_3_4xf(<4 x float> %div, <4 x float> %div1, <4 x float> %div2)
5959
ret void
6060
}
@@ -68,9 +68,9 @@ define void @three_fdiv_2xdouble(<2 x double> %D, <2 x double> %a, <2 x double>
6868
; CHECK-NEXT: fmul v1.2d, v2.2d, v4.2d
6969
; CHECK-NEXT: fmul v2.2d, v3.2d, v4.2d
7070
; CHECK-NEXT: b foo_3_2xd
71-
%div = fdiv <2 x double> %a, %D
72-
%div1 = fdiv <2 x double> %b, %D
73-
%div2 = fdiv <2 x double> %c, %D
71+
%div = fdiv arcp <2 x double> %a, %D
72+
%div1 = fdiv arcp <2 x double> %b, %D
73+
%div2 = fdiv arcp <2 x double> %c, %D
7474
tail call void @foo_3_2xd(<2 x double> %div, <2 x double> %div1, <2 x double> %div2)
7575
ret void
7676
}
@@ -84,8 +84,8 @@ define void @two_fdiv_float(float %D, float %a, float %b) #0 {
8484
; CHECK-NEXT: fdiv s1, s2, s0
8585
; CHECK-NEXT: fmov s0, s3
8686
; CHECK-NEXT: b foo_2f
87-
%div = fdiv float %a, %D
88-
%div1 = fdiv float %b, %D
87+
%div = fdiv arcp float %a, %D
88+
%div1 = fdiv arcp float %b, %D
8989
tail call void @foo_2f(float %div, float %div1)
9090
ret void
9191
}
@@ -97,8 +97,8 @@ define void @two_fdiv_double(double %D, double %a, double %b) #0 {
9797
; CHECK-NEXT: fdiv d1, d2, d0
9898
; CHECK-NEXT: fmov d0, d3
9999
; CHECK-NEXT: b foo_2d
100-
%div = fdiv double %a, %D
101-
%div1 = fdiv double %b, %D
100+
%div = fdiv arcp double %a, %D
101+
%div1 = fdiv arcp double %b, %D
102102
tail call void @foo_2d(double %div, double %div1)
103103
ret void
104104
}
@@ -125,10 +125,10 @@ define void @four_fdiv_multi_float(float %D, float %a, float %b, float %c) #0 {
125125
; CHECK-GI-NEXT: fmul s2, s3, s5
126126
; CHECK-GI-NEXT: fmov s3, s4
127127
; CHECK-GI-NEXT: b foo_4f
128-
%div = fdiv float %a, %D
129-
%div1 = fdiv float %b, %D
130-
%div2 = fdiv float %c, %D
131-
%div3 = fdiv float %D, %D
128+
%div = fdiv arcp float %a, %D
129+
%div1 = fdiv arcp float %b, %D
130+
%div2 = fdiv arcp float %c, %D
131+
%div3 = fdiv arcp float %D, %D
132132
tail call void @foo_4f(float %div, float %div1, float %div2, float %div3)
133133
ret void
134134
}
@@ -146,9 +146,9 @@ define void @splat_three_fdiv_4xfloat(float %D, <4 x float> %a, <4 x float> %b,
146146
; CHECK-NEXT: b foo_3_4xf
147147
%D.ins = insertelement <4 x float> poison, float %D, i64 0
148148
%splat = shufflevector <4 x float> %D.ins, <4 x float> poison, <4 x i32> zeroinitializer
149-
%div = fdiv <4 x float> %a, %splat
150-
%div1 = fdiv <4 x float> %b, %splat
151-
%div2 = fdiv <4 x float> %c, %splat
149+
%div = fdiv arcp <4 x float> %a, %splat
150+
%div1 = fdiv arcp <4 x float> %b, %splat
151+
%div2 = fdiv arcp <4 x float> %c, %splat
152152
tail call void @foo_3_4xf(<4 x float> %div, <4 x float> %div1, <4 x float> %div2)
153153
ret void
154154
}
@@ -172,7 +172,7 @@ define <4 x float> @splat_fdiv_v4f32(float %D, <4 x float> %a) #1 {
172172
entry:
173173
%D.ins = insertelement <4 x float> poison, float %D, i64 0
174174
%splat = shufflevector <4 x float> %D.ins, <4 x float> poison, <4 x i32> zeroinitializer
175-
%div = fdiv <4 x float> %a, %splat
175+
%div = fdiv arcp <4 x float> %a, %splat
176176
ret <4 x float> %div
177177
}
178178

@@ -187,7 +187,7 @@ define <vscale x 4 x float> @splat_fdiv_nxv4f32(float %D, <vscale x 4 x float> %
187187
entry:
188188
%D.ins = insertelement <vscale x 4 x float> poison, float %D, i64 0
189189
%splat = shufflevector <vscale x 4 x float> %D.ins, <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer
190-
%div = fdiv <vscale x 4 x float> %a, %splat
190+
%div = fdiv arcp <vscale x 4 x float> %a, %splat
191191
ret <vscale x 4 x float> %div
192192
}
193193

@@ -204,9 +204,9 @@ define void @splat_three_fdiv_nxv4f32(float %D, <vscale x 4 x float> %a, <vscale
204204
entry:
205205
%D.ins = insertelement <vscale x 4 x float> poison, float %D, i64 0
206206
%splat = shufflevector <vscale x 4 x float> %D.ins, <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer
207-
%div = fdiv <vscale x 4 x float> %a, %splat
208-
%div1 = fdiv <vscale x 4 x float> %b, %splat
209-
%div2 = fdiv <vscale x 4 x float> %c, %splat
207+
%div = fdiv arcp <vscale x 4 x float> %a, %splat
208+
%div1 = fdiv arcp <vscale x 4 x float> %b, %splat
209+
%div2 = fdiv arcp <vscale x 4 x float> %c, %splat
210210
tail call void @foo_3_nxv4f32(<vscale x 4 x float> %div, <vscale x 4 x float> %div1, <vscale x 4 x float> %div2)
211211
ret void
212212
}
@@ -222,7 +222,7 @@ define <vscale x 2 x double> @splat_fdiv_nxv2f64(double %D, <vscale x 2 x double
222222
entry:
223223
%D.ins = insertelement <vscale x 2 x double> poison, double %D, i64 0
224224
%splat = shufflevector <vscale x 2 x double> %D.ins, <vscale x 2 x double> poison, <vscale x 2 x i32> zeroinitializer
225-
%div = fdiv <vscale x 2 x double> %a, %splat
225+
%div = fdiv arcp <vscale x 2 x double> %a, %splat
226226
ret <vscale x 2 x double> %div
227227
}
228228

@@ -238,8 +238,8 @@ define void @splat_two_fdiv_nxv2f64(double %D, <vscale x 2 x double> %a, <vscale
238238
entry:
239239
%D.ins = insertelement <vscale x 2 x double> poison, double %D, i64 0
240240
%splat = shufflevector <vscale x 2 x double> %D.ins, <vscale x 2 x double> poison, <vscale x 2 x i32> zeroinitializer
241-
%div = fdiv <vscale x 2 x double> %a, %splat
242-
%div1 = fdiv <vscale x 2 x double> %b, %splat
241+
%div = fdiv arcp <vscale x 2 x double> %a, %splat
242+
%div1 = fdiv arcp <vscale x 2 x double> %b, %splat
243243
tail call void @foo_2_nxv2f64(<vscale x 2 x double> %div, <vscale x 2 x double> %div1)
244244
ret void
245245
}

0 commit comments

Comments
 (0)