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_min_max_ValK0_K1_f32(float %a) #0 {
5 ; GFX10-LABEL: test_min_max_ValK0_K1_f32:
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 %maxnum = call nnan float @llvm.maxnum.f32(float %fmul, float 0.0)
12 %fmed = call nnan float @llvm.minnum.f32(float %maxnum, float 1.0)
16 define double @test_min_max_K0Val_K1_f64(double %a) #1 {
17 ; GFX10-LABEL: test_min_max_K0Val_K1_f64:
19 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
20 ; GFX10-NEXT: v_mul_f64 v[0:1], v[0:1], 2.0 clamp
21 ; GFX10-NEXT: s_setpc_b64 s[30:31]
22 %fmul = fmul double %a, 2.0
23 %maxnum = call nnan double @llvm.maxnum.f64(double 0.0, double %fmul)
24 %fmed = call nnan double @llvm.minnum.f64(double %maxnum, double 1.0)
28 ; min-max patterns for ieee=true, dx10_clamp=true don't have to check for NaNs
29 define half @test_min_K1max_ValK0_f16(half %a) #2 {
30 ; GFX10-LABEL: test_min_K1max_ValK0_f16:
32 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
33 ; GFX10-NEXT: v_mul_f16_e64 v0, v0, 2.0 clamp
34 ; GFX10-NEXT: s_setpc_b64 s[30:31]
35 %fmul = fmul half %a, 2.0
36 %maxnum = call half @llvm.maxnum.f16(half %fmul, half 0.0)
37 %fmed = call half @llvm.minnum.f16(half 1.0, half %maxnum)
41 define <2 x half> @test_min_K1max_K0Val_f16(<2 x half> %a) #1 {
42 ; GFX10-LABEL: test_min_K1max_K0Val_f16:
44 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
45 ; GFX10-NEXT: v_pk_mul_f16 v0, v0, 2.0 op_sel_hi:[1,0] clamp
46 ; GFX10-NEXT: s_setpc_b64 s[30:31]
47 %fmul = fmul <2 x half> %a, <half 2.0, half 2.0>
48 %maxnum = call nnan <2 x half> @llvm.maxnum.v2f16(<2 x half> <half 0.0, half 0.0>, <2 x half> %fmul)
49 %fmed = call nnan <2 x half> @llvm.minnum.v2f16(<2 x half> <half 1.0, half 1.0>, <2 x half> %maxnum)
53 define <2 x half> @test_min_max_splat_padded_with_undef(<2 x half> %a) #2 {
54 ; GFX10-LABEL: test_min_max_splat_padded_with_undef:
56 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
57 ; GFX10-NEXT: v_pk_mul_f16 v0, v0, 2.0 op_sel_hi:[1,0] clamp
58 ; GFX10-NEXT: s_setpc_b64 s[30:31]
59 %fmul = fmul <2 x half> %a, <half 2.0, half 2.0>
60 %maxnum = call <2 x half> @llvm.maxnum.v2f16(<2 x half> <half 0.0, half undef>, <2 x half> %fmul)
61 %fmed = call <2 x half> @llvm.minnum.v2f16(<2 x half> <half 1.0, half undef>, <2 x half> %maxnum)
65 ; max-mix patterns work only for known non-NaN inputs
67 define float @test_max_min_ValK1_K0_f32(float %a) #0 {
68 ; GFX10-LABEL: test_max_min_ValK1_K0_f32:
70 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
71 ; GFX10-NEXT: v_mul_f32_e64 v0, v0, 2.0 clamp
72 ; GFX10-NEXT: s_setpc_b64 s[30:31]
73 %fmul = fmul float %a, 2.0
74 %minnum = call nnan float @llvm.minnum.f32(float %fmul, float 1.0)
75 %fmed = call nnan float @llvm.maxnum.f32(float %minnum, float 0.0)
79 define double @test_max_min_K1Val_K0_f64(double %a) #1 {
80 ; GFX10-LABEL: test_max_min_K1Val_K0_f64:
82 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
83 ; GFX10-NEXT: v_mul_f64 v[0:1], v[0:1], 2.0 clamp
84 ; GFX10-NEXT: s_setpc_b64 s[30:31]
85 %fmul = fmul double %a, 2.0
86 %minnum = call nnan double @llvm.minnum.f64(double 1.0, double %fmul)
87 %fmed = call nnan double @llvm.maxnum.f64(double %minnum, double 0.0)
91 define half @test_max_K0min_ValK1_f16(half %a) #0 {
92 ; GFX10-LABEL: test_max_K0min_ValK1_f16:
94 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
95 ; GFX10-NEXT: v_mul_f16_e64 v0, v0, 2.0 clamp
96 ; GFX10-NEXT: s_setpc_b64 s[30:31]
97 %fmul = fmul half %a, 2.0
98 %minnum = call nnan half @llvm.minnum.f16(half %fmul, half 1.0)
99 %fmed = call nnan half @llvm.maxnum.f16(half 0.0, half %minnum)
103 ; treat undef as value that will result in a constant splat
104 define <2 x half> @test_max_K0min_K1Val_v2f16(<2 x half> %a) #1 {
105 ; GFX10-LABEL: test_max_K0min_K1Val_v2f16:
107 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
108 ; GFX10-NEXT: v_pk_mul_f16 v0, v0, 2.0 op_sel_hi:[1,0] clamp
109 ; GFX10-NEXT: s_setpc_b64 s[30:31]
110 %fmul = fmul <2 x half> %a, <half 2.0, half 2.0>
111 %minnum = call nnan <2 x half> @llvm.minnum.v2f16(<2 x half> <half 1.0, half undef>, <2 x half> %fmul)
112 %fmed = call nnan <2 x half> @llvm.maxnum.v2f16(<2 x half> <half undef, half 0.0>, <2 x half> %minnum)
116 ; global nnan function attribute always forces clamp combine
118 define float @test_min_max_global_nnan(float %a) #3 {
119 ; GFX10-LABEL: test_min_max_global_nnan:
121 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
122 ; GFX10-NEXT: v_max_f32_e64 v0, v0, v0 clamp
123 ; GFX10-NEXT: s_setpc_b64 s[30:31]
124 %maxnum = call float @llvm.maxnum.f32(float %a, float 0.0)
125 %fmed = call float @llvm.minnum.f32(float %maxnum, float 1.0)
129 define float @test_max_min_global_nnan(float %a) #3 {
130 ; GFX10-LABEL: test_max_min_global_nnan:
132 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
133 ; GFX10-NEXT: v_max_f32_e64 v0, v0, v0 clamp
134 ; GFX10-NEXT: s_setpc_b64 s[30:31]
135 %minnum = call float @llvm.minnum.f32(float %a, float 1.0)
136 %fmed = call float @llvm.maxnum.f32(float %minnum, float 0.0)
140 ; ------------------------------------------------------------------------------
142 ; ------------------------------------------------------------------------------
144 ; min(max(Val, 1.0), 0.0), should be min(max(Val, 0.0), 1.0)
145 define float @test_min_max_K0_gt_K1(float %a) #0 {
146 ; GFX10-LABEL: test_min_max_K0_gt_K1:
148 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
149 ; GFX10-NEXT: v_max_f32_e32 v0, 1.0, v0
150 ; GFX10-NEXT: v_min_f32_e32 v0, 0, v0
151 ; GFX10-NEXT: s_setpc_b64 s[30:31]
152 %maxnum = call nnan float @llvm.maxnum.f32(float %a, float 1.0)
153 %fmed = call nnan float @llvm.minnum.f32(float %maxnum, float 0.0)
157 ; max(min(Val, 0.0), 1.0), should be max(min(Val, 1.0), 0.0)
158 define float @test_max_min_K0_gt_K1(float %a) #0 {
159 ; GFX10-LABEL: test_max_min_K0_gt_K1:
161 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
162 ; GFX10-NEXT: v_min_f32_e32 v0, 0, v0
163 ; GFX10-NEXT: v_max_f32_e32 v0, 1.0, v0
164 ; GFX10-NEXT: s_setpc_b64 s[30:31]
165 %minnum = call nnan float @llvm.minnum.f32(float %a, float 0.0)
166 %fmed = call nnan float @llvm.maxnum.f32(float %minnum, float 1.0)
170 ; Input that can be NaN
172 ; min-max patterns for ieee=false require known non-NaN input
173 define float @test_min_max_maybe_NaN_input_ieee_false(float %a) #1 {
174 ; GFX10-LABEL: test_min_max_maybe_NaN_input_ieee_false:
176 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
177 ; GFX10-NEXT: v_mul_f32_e32 v0, 2.0, v0
178 ; GFX10-NEXT: v_max_f32_e32 v0, 0, v0
179 ; GFX10-NEXT: v_min_f32_e32 v0, 1.0, v0
180 ; GFX10-NEXT: s_setpc_b64 s[30:31]
181 %fmul = fmul float %a, 2.0
182 %maxnum = call float @llvm.maxnum.f32(float %fmul, float 0.0)
183 %fmed = call float @llvm.minnum.f32(float %maxnum, float 1.0)
187 ; clamp fails here since input can be NaN and dx10_clamp=false; fmed3 succeds
188 define float @test_min_max_maybe_NaN_input_ieee_true_dx10clamp_false(float %a) #4 {
189 ; GFX10-LABEL: test_min_max_maybe_NaN_input_ieee_true_dx10clamp_false:
191 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
192 ; GFX10-NEXT: v_mul_f32_e32 v0, 2.0, v0
193 ; GFX10-NEXT: v_med3_f32 v0, v0, 0, 1.0
194 ; GFX10-NEXT: s_setpc_b64 s[30:31]
195 %fmul = fmul float %a, 2.0
196 %maxnum = call float @llvm.maxnum.f32(float %fmul, float 0.0)
197 %fmed = call float @llvm.minnum.f32(float %maxnum, float 1.0)
201 ; max-min patterns always require known non-NaN input
203 define float @test_max_min_maybe_NaN_input_ieee_true(float %a) #0 {
204 ; GFX10-LABEL: test_max_min_maybe_NaN_input_ieee_true:
206 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
207 ; GFX10-NEXT: v_mul_f32_e32 v0, 2.0, v0
208 ; GFX10-NEXT: v_min_f32_e32 v0, 1.0, v0
209 ; GFX10-NEXT: v_max_f32_e32 v0, 0, v0
210 ; GFX10-NEXT: s_setpc_b64 s[30:31]
211 %fmul = fmul float %a, 2.0
212 %minnum = call float @llvm.minnum.f32(float %fmul, float 1.0)
213 %fmed = call float @llvm.maxnum.f32(float %minnum, float 0.0)
217 define float @test_max_min_maybe_NaN_input_ieee_false(float %a) #1 {
218 ; GFX10-LABEL: test_max_min_maybe_NaN_input_ieee_false:
220 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
221 ; GFX10-NEXT: v_mul_f32_e32 v0, 2.0, v0
222 ; GFX10-NEXT: v_min_f32_e32 v0, 1.0, v0
223 ; GFX10-NEXT: v_max_f32_e32 v0, 0, v0
224 ; GFX10-NEXT: s_setpc_b64 s[30:31]
225 %fmul = fmul float %a, 2.0
226 %minnum = call float @llvm.minnum.f32(float %fmul, float 1.0)
227 %fmed = call float @llvm.maxnum.f32(float %minnum, float 0.0)
231 declare half @llvm.minnum.f16(half, half)
232 declare half @llvm.maxnum.f16(half, half)
233 declare float @llvm.minnum.f32(float, float)
234 declare float @llvm.maxnum.f32(float, float)
235 declare double @llvm.minnum.f64(double, double)
236 declare double @llvm.maxnum.f64(double, double)
237 declare <2 x half> @llvm.minnum.v2f16(<2 x half>, <2 x half>)
238 declare <2 x half> @llvm.maxnum.v2f16(<2 x half>, <2 x half>)
239 attributes #0 = {"amdgpu-ieee"="true"}
240 attributes #1 = {"amdgpu-ieee"="false"}
241 attributes #2 = {"amdgpu-ieee"="true" "amdgpu-dx10-clamp"="true"}
242 attributes #3 = {"no-nans-fp-math"="true"}
243 attributes #4 = {"amdgpu-ieee"="true" "amdgpu-dx10-clamp"="false"}