Skip to content

Commit f98b955

Browse files
authored
[GlobalIsel] Remove NoNaNsFPMath uses (#163484)
Users should use `nnan` instead. This is the GlobalIsel part.
1 parent f7f6f6d commit f98b955

File tree

5 files changed

+159
-163
lines changed

5 files changed

+159
-163
lines changed

llvm/lib/CodeGen/GlobalISel/Utils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,7 @@ bool llvm::isKnownNeverNaN(Register Val, const MachineRegisterInfo &MRI,
818818
if (!DefMI)
819819
return false;
820820

821-
const TargetMachine& TM = DefMI->getMF()->getTarget();
822-
if (DefMI->getFlag(MachineInstr::FmNoNans) || TM.Options.NoNaNsFPMath)
821+
if (DefMI->getFlag(MachineInstr::FmNoNans))
823822
return true;
824823

825824
// If the value is a constant, we can obviously see if it is a NaN or not.

llvm/test/CodeGen/AMDGPU/GlobalISel/clamp-minmax-const-combine.ll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ define <2 x half> @test_max_K0min_K1Val_v2f16(<2 x half> %a) #1 {
206206

207207
; global nnan function attribute always forces clamp combine
208208

209-
define float @test_min_max_global_nnan(float %a) #3 {
209+
define float @test_min_max_global_nnan(float %a) {
210210
; GFX10-LABEL: test_min_max_global_nnan:
211211
; GFX10: ; %bb.0:
212212
; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
@@ -223,11 +223,11 @@ define float @test_min_max_global_nnan(float %a) #3 {
223223
; GFX12-NEXT: v_max_num_f32_e64 v0, v0, v0 clamp
224224
; GFX12-NEXT: s_setpc_b64 s[30:31]
225225
%maxnum = call float @llvm.maxnum.f32(float %a, float 0.0)
226-
%fmed = call float @llvm.minnum.f32(float %maxnum, float 1.0)
226+
%fmed = call nnan float @llvm.minnum.f32(float %maxnum, float 1.0)
227227
ret float %fmed
228228
}
229229

230-
define float @test_max_min_global_nnan(float %a) #3 {
230+
define float @test_max_min_global_nnan(float %a) {
231231
; GFX10-LABEL: test_max_min_global_nnan:
232232
; GFX10: ; %bb.0:
233233
; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
@@ -244,7 +244,7 @@ define float @test_max_min_global_nnan(float %a) #3 {
244244
; GFX12-NEXT: v_max_num_f32_e64 v0, v0, v0 clamp
245245
; GFX12-NEXT: s_setpc_b64 s[30:31]
246246
%minnum = call float @llvm.minnum.f32(float %a, float 1.0)
247-
%fmed = call float @llvm.maxnum.f32(float %minnum, float 0.0)
247+
%fmed = call nnan float @llvm.maxnum.f32(float %minnum, float 0.0)
248248
ret float %fmed
249249
}
250250

@@ -414,5 +414,4 @@ declare <2 x half> @llvm.maxnum.v2f16(<2 x half>, <2 x half>)
414414
attributes #0 = {"amdgpu-ieee"="true"}
415415
attributes #1 = {"amdgpu-ieee"="false"}
416416
attributes #2 = {"amdgpu-ieee"="true" "amdgpu-dx10-clamp"="true"}
417-
attributes #3 = {"no-nans-fp-math"="true"}
418417
attributes #4 = {"amdgpu-ieee"="true" "amdgpu-dx10-clamp"="false"}

llvm/test/CodeGen/AMDGPU/GlobalISel/fmed3-min-max-const-combine.ll

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ define half @test_max_K0min_K1Val_f16(half %a) #1 {
232232

233233
; global nnan function attribute always forces fmed3 combine
234234

235-
define float @test_min_max_global_nnan(float %a) #2 {
235+
define float @test_min_max_global_nnan(float %a) {
236236
; GFX10-LABEL: test_min_max_global_nnan:
237237
; GFX10: ; %bb.0:
238238
; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
@@ -254,12 +254,12 @@ define float @test_min_max_global_nnan(float %a) #2 {
254254
; GFX12-NEXT: s_wait_kmcnt 0x0
255255
; GFX12-NEXT: v_med3_num_f32 v0, v0, 2.0, 4.0
256256
; GFX12-NEXT: s_setpc_b64 s[30:31]
257-
%maxnum = call float @llvm.maxnum.f32(float %a, float 2.0)
257+
%maxnum = call nnan float @llvm.maxnum.f32(float %a, float 2.0)
258258
%fmed = call float @llvm.minnum.f32(float %maxnum, float 4.0)
259259
ret float %fmed
260260
}
261261

262-
define float @test_max_min_global_nnan(float %a) #2 {
262+
define float @test_max_min_global_nnan(float %a) {
263263
; GFX10-LABEL: test_max_min_global_nnan:
264264
; GFX10: ; %bb.0:
265265
; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
@@ -281,8 +281,8 @@ define float @test_max_min_global_nnan(float %a) #2 {
281281
; GFX12-NEXT: s_wait_kmcnt 0x0
282282
; GFX12-NEXT: v_med3_num_f32 v0, v0, 2.0, 4.0
283283
; GFX12-NEXT: s_setpc_b64 s[30:31]
284-
%minnum = call float @llvm.minnum.f32(float %a, float 4.0)
285-
%fmed = call float @llvm.maxnum.f32(float %minnum, float 2.0)
284+
%minnum = call nnan float @llvm.minnum.f32(float %a, float 4.0)
285+
%fmed = call nnan float @llvm.maxnum.f32(float %minnum, float 2.0)
286286
ret float %fmed
287287
}
288288

@@ -560,4 +560,3 @@ declare <2 x half> @llvm.minnum.v2f16(<2 x half>, <2 x half>)
560560
declare <2 x half> @llvm.maxnum.v2f16(<2 x half>, <2 x half>)
561561
attributes #0 = {"amdgpu-ieee"="true"}
562562
attributes #1 = {"amdgpu-ieee"="false"}
563-
attributes #2 = {"no-nans-fp-math"="true"}

0 commit comments

Comments
 (0)