1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -global-isel -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1010 -verify-machineinstrs < %s | FileCheck -check-prefix=GFX10 %s
4 define float @test_fmed3_f32_known_nnan_ieee_true(float %a) #0 {
5 ; GFX10-LABEL: test_fmed3_f32_known_nnan_ieee_true:
7 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
8 ; GFX10-NEXT: v_mul_f32_e64 v0, v0, 2.0 clamp
9 ; GFX10-NEXT: s_setpc_b64 s[30:31]
10 %fmul = fmul float %a, 2.0
11 %fmed = call nnan float @llvm.amdgcn.fmed3.f32(float %fmul, float 0.0, float 1.0)
15 define half @test_fmed3_f16_known_nnan_ieee_false(half %a) #1 {
16 ; GFX10-LABEL: test_fmed3_f16_known_nnan_ieee_false:
18 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
19 ; GFX10-NEXT: v_mul_f16_e64 v0, v0, 2.0 clamp
20 ; GFX10-NEXT: s_setpc_b64 s[30:31]
21 %fmul = fmul half %a, 2.0
22 %fmed = call nnan half @llvm.amdgcn.fmed3.f16(half %fmul, half 0.0, half 1.0)
26 ; %fmin is known non-SNaN because fmin inputs are fcanonicalized
27 define float @test_fmed3_non_SNaN_input_ieee_true_dx10clamp_true(float %a) #2 {
28 ; GFX10-LABEL: test_fmed3_non_SNaN_input_ieee_true_dx10clamp_true:
30 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
31 ; GFX10-NEXT: v_max_f32_e32 v0, v0, v0
32 ; GFX10-NEXT: v_min_f32_e64 v0, 0x41200000, v0 clamp
33 ; GFX10-NEXT: s_setpc_b64 s[30:31]
34 %fmin = call float @llvm.minnum.f32(float %a, float 10.0)
35 %fmed = call float @llvm.amdgcn.fmed3.f32(float %fmin, float 0.0, float 1.0)
39 ; input may be SNaN. It's safe to clamp since third operand in fmed3 is 0.0
40 define float @test_fmed3_maybe_SNaN_input_zero_third_operand_ieee_true_dx10clamp_true(float %a) #2 {
41 ; GFX10-LABEL: test_fmed3_maybe_SNaN_input_zero_third_operand_ieee_true_dx10clamp_true:
43 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
44 ; GFX10-NEXT: v_mul_f32_e64 v0, v0, 2.0 clamp
45 ; GFX10-NEXT: s_setpc_b64 s[30:31]
46 %fmul = fmul float %a, 2.0
47 %fmed = call float @llvm.amdgcn.fmed3.f32(float %fmul, float 1.0, float 0.0)
51 ; global nnan function attribute always forces clamp combine
53 define float @test_fmed3_global_nnan(float %a) #3 {
54 ; GFX10-LABEL: test_fmed3_global_nnan:
56 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
57 ; GFX10-NEXT: v_mul_f32_e64 v0, v0, 2.0 clamp
58 ; GFX10-NEXT: s_setpc_b64 s[30:31]
59 %fmul = fmul float %a, 2.0
60 %fmed = call float @llvm.amdgcn.fmed3.f32(float %fmul, float 0.0, float 1.0)
64 ; ------------------------------------------------------------------------------
66 ; ------------------------------------------------------------------------------
68 ; ieee=false requires known never NaN input
69 define float @test_fmed3_f32_maybe_NaN_ieee_false(float %a) #1 {
70 ; GFX10-LABEL: test_fmed3_f32_maybe_NaN_ieee_false:
72 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
73 ; GFX10-NEXT: v_mul_f32_e32 v0, 2.0, v0
74 ; GFX10-NEXT: v_med3_f32 v0, v0, 1.0, 0
75 ; GFX10-NEXT: s_setpc_b64 s[30:31]
76 %fmul = fmul float %a, 2.0
77 %fmed = call float @llvm.amdgcn.fmed3.f32(float %fmul, float 1.0, float 0.0)
81 ; ieee=true input is known non-SNaN but dx10_clamp=false
82 define float @test_fmed3_non_SNaN_input_ieee_true_dx10clamp_false(float %a) #4 {
83 ; GFX10-LABEL: test_fmed3_non_SNaN_input_ieee_true_dx10clamp_false:
85 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
86 ; GFX10-NEXT: v_max_f32_e32 v0, v0, v0
87 ; GFX10-NEXT: v_min_f32_e32 v0, 0x41200000, v0
88 ; GFX10-NEXT: v_med3_f32 v0, v0, 0, 1.0
89 ; GFX10-NEXT: s_setpc_b64 s[30:31]
90 %fmin = call float @llvm.minnum.f32(float %a, float 10.0)
91 %fmed = call float @llvm.amdgcn.fmed3.f32(float %fmin, float 0.0, float 1.0)
95 ; ieee=true dx10_clamp=true but input may be SNaN, clamp requires third operand in fmed3 to be 0.0
96 define float @test_fmed3_maybe_SNaN_input_ieee_true_dx10clamp_true(float %a) #2 {
97 ; GFX10-LABEL: test_fmed3_maybe_SNaN_input_ieee_true_dx10clamp_true:
99 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
100 ; GFX10-NEXT: v_mul_f32_e64 v0, v0, 2.0 clamp
101 ; GFX10-NEXT: s_setpc_b64 s[30:31]
102 %fmul = fmul float %a, 2.0
103 %fmed = call float @llvm.amdgcn.fmed3.f32(float %fmul, float 0.0, float 1.0)
107 declare half @llvm.amdgcn.fmed3.f16(half, half, half)
108 declare float @llvm.amdgcn.fmed3.f32(float, float, float)
109 declare float @llvm.minnum.f32(float, float)
111 attributes #0 = {"amdgpu-ieee"="true"}
112 attributes #1 = {"amdgpu-ieee"="false"}
113 attributes #2 = {"amdgpu-ieee"="true" "amdgpu-dx10-clamp"="true"}
114 attributes #3 = {"no-nans-fp-math"="true"}
115 attributes #4 = {"amdgpu-ieee"="true" "amdgpu-dx10-clamp"="false"}