1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
3 ; Test with buggy fract, shouldn't match
4 ; RUN: opt -S -mtriple=amdgcn-amd-amdpal -mcpu=tahiti -amdgpu-codegenprepare %s | FileCheck -check-prefixes=IR,GFX6-IR %s
6 ; Working fract, but no f16
7 ; RUN: opt -S -mtriple=amdgcn-amd-amdpal -mcpu=kaveri -amdgpu-codegenprepare %s | FileCheck -check-prefixes=IR,IR-FRACT,GFX7-IR %s
9 ; Working fract and f16 support
10 ; RUN: opt -S -mtriple=amdgcn-amd-amdpal -mcpu=gfx900 -amdgpu-codegenprepare %s | FileCheck -check-prefixes=IR,IR-FRACT,IR-LEGALF16 %s
11 ; RUN: opt -S -mtriple=amdgcn-amd-amdpal -mcpu=gfx1100 -amdgpu-codegenprepare %s | FileCheck -check-prefixes=IR,IR-FRACT,IR-LEGALF16 %s
13 ; RUN: llc -mtriple=amdgcn-amd-amdpal -mcpu=tahiti < %s | FileCheck -check-prefixes=GCN,GFX6 %s
14 ; RUN: llc -mtriple=amdgcn-amd-amdpal -mcpu=kaveri < %s | FileCheck -check-prefixes=GCN,GFX7 %s
15 ; RUN: llc -mtriple=amdgcn-amd-amdpal -mcpu=gfx900 < %s | FileCheck -check-prefixes=GCN,GFX8 %s
16 ; RUN: llc -mtriple=amdgcn-amd-amdpal -mcpu=gfx1100 < %s | FileCheck -check-prefixes=GCN,GFX11 %s
17 ; RUN: llc -mtriple=amdgcn-amd-amdpal -mcpu=gfx1200 < %s | FileCheck -check-prefixes=GFX12 %s
19 ; Test patterns to match v_fract_* instructions.
21 ; Expansion as it appears in the library with the extra output for
22 ; floor. We can fold in the nan check into the instruction, but the
23 ; inf check must remain.
24 define float @safe_math_fract_f32(float %x, ptr addrspace(1) writeonly captures(none) %ip) {
25 ; GFX6-IR-LABEL: define float @safe_math_fract_f32
26 ; GFX6-IR-SAME: (float [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0:[0-9]+]] {
27 ; GFX6-IR-NEXT: entry:
28 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
29 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
30 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
31 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno float [[X]], 0.000000e+00
32 ; GFX6-IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], float [[X]], float [[MIN]]
33 ; GFX6-IR-NEXT: [[FABS:%.*]] = tail call float @llvm.fabs.f32(float [[X]])
34 ; GFX6-IR-NEXT: [[CMPINF:%.*]] = fcmp oeq float [[FABS]], 0x7FF0000000000000
35 ; GFX6-IR-NEXT: [[COND6:%.*]] = select i1 [[CMPINF]], float 0.000000e+00, float [[COND]]
36 ; GFX6-IR-NEXT: store float [[FLOOR]], ptr addrspace(1) [[IP]], align 4
37 ; GFX6-IR-NEXT: ret float [[COND6]]
39 ; IR-FRACT-LABEL: define float @safe_math_fract_f32
40 ; IR-FRACT-SAME: (float [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0:[0-9]+]] {
41 ; IR-FRACT-NEXT: entry:
42 ; IR-FRACT-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
43 ; IR-FRACT-NEXT: [[COND:%.*]] = call float @llvm.amdgcn.fract.f32(float [[X]])
44 ; IR-FRACT-NEXT: [[FABS:%.*]] = tail call float @llvm.fabs.f32(float [[X]])
45 ; IR-FRACT-NEXT: [[CMPINF:%.*]] = fcmp oeq float [[FABS]], 0x7FF0000000000000
46 ; IR-FRACT-NEXT: [[COND6:%.*]] = select i1 [[CMPINF]], float 0.000000e+00, float [[COND]]
47 ; IR-FRACT-NEXT: store float [[FLOOR]], ptr addrspace(1) [[IP]], align 4
48 ; IR-FRACT-NEXT: ret float [[COND6]]
50 ; GFX6-LABEL: safe_math_fract_f32:
51 ; GFX6: ; %bb.0: ; %entry
52 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
53 ; GFX6-NEXT: v_floor_f32_e32 v3, v0
54 ; GFX6-NEXT: v_sub_f32_e32 v4, v0, v3
55 ; GFX6-NEXT: v_min_f32_e32 v4, 0x3f7fffff, v4
56 ; GFX6-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
57 ; GFX6-NEXT: s_mov_b32 s8, 0x7f800000
58 ; GFX6-NEXT: s_mov_b32 s6, 0
59 ; GFX6-NEXT: v_cndmask_b32_e32 v4, v4, v0, vcc
60 ; GFX6-NEXT: v_cmp_neq_f32_e64 vcc, |v0|, s8
61 ; GFX6-NEXT: s_mov_b32 s7, 0xf000
62 ; GFX6-NEXT: s_mov_b32 s4, s6
63 ; GFX6-NEXT: s_mov_b32 s5, s6
64 ; GFX6-NEXT: v_cndmask_b32_e32 v0, 0, v4, vcc
65 ; GFX6-NEXT: buffer_store_dword v3, v[1:2], s[4:7], 0 addr64
66 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0)
67 ; GFX6-NEXT: s_setpc_b64 s[30:31]
69 ; GFX7-LABEL: safe_math_fract_f32:
70 ; GFX7: ; %bb.0: ; %entry
71 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
72 ; GFX7-NEXT: s_mov_b32 s8, 0x7f800000
73 ; GFX7-NEXT: s_mov_b32 s6, 0
74 ; GFX7-NEXT: v_fract_f32_e32 v4, v0
75 ; GFX7-NEXT: v_cmp_neq_f32_e64 vcc, |v0|, s8
76 ; GFX7-NEXT: s_mov_b32 s7, 0xf000
77 ; GFX7-NEXT: s_mov_b32 s4, s6
78 ; GFX7-NEXT: s_mov_b32 s5, s6
79 ; GFX7-NEXT: v_floor_f32_e32 v3, v0
80 ; GFX7-NEXT: v_cndmask_b32_e32 v0, 0, v4, vcc
81 ; GFX7-NEXT: buffer_store_dword v3, v[1:2], s[4:7], 0 addr64
82 ; GFX7-NEXT: s_waitcnt vmcnt(0)
83 ; GFX7-NEXT: s_setpc_b64 s[30:31]
85 ; GFX8-LABEL: safe_math_fract_f32:
86 ; GFX8: ; %bb.0: ; %entry
87 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
88 ; GFX8-NEXT: s_mov_b32 s4, 0x7f800000
89 ; GFX8-NEXT: v_fract_f32_e32 v4, v0
90 ; GFX8-NEXT: v_cmp_neq_f32_e64 vcc, |v0|, s4
91 ; GFX8-NEXT: v_floor_f32_e32 v3, v0
92 ; GFX8-NEXT: v_cndmask_b32_e32 v0, 0, v4, vcc
93 ; GFX8-NEXT: global_store_dword v[1:2], v3, off
94 ; GFX8-NEXT: s_waitcnt vmcnt(0)
95 ; GFX8-NEXT: s_setpc_b64 s[30:31]
97 ; GFX11-LABEL: safe_math_fract_f32:
98 ; GFX11: ; %bb.0: ; %entry
99 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
100 ; GFX11-NEXT: v_fract_f32_e32 v3, v0
101 ; GFX11-NEXT: v_cmp_neq_f32_e64 vcc_lo, 0x7f800000, |v0|
102 ; GFX11-NEXT: v_floor_f32_e32 v4, v0
103 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_3)
104 ; GFX11-NEXT: v_cndmask_b32_e32 v0, 0, v3, vcc_lo
105 ; GFX11-NEXT: global_store_b32 v[1:2], v4, off
106 ; GFX11-NEXT: s_setpc_b64 s[30:31]
108 ; GFX12-LABEL: safe_math_fract_f32:
109 ; GFX12: ; %bb.0: ; %entry
110 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
111 ; GFX12-NEXT: s_wait_expcnt 0x0
112 ; GFX12-NEXT: s_wait_samplecnt 0x0
113 ; GFX12-NEXT: s_wait_bvhcnt 0x0
114 ; GFX12-NEXT: s_wait_kmcnt 0x0
115 ; GFX12-NEXT: v_fract_f32_e32 v3, v0
116 ; GFX12-NEXT: v_cmp_neq_f32_e64 vcc_lo, 0x7f800000, |v0|
117 ; GFX12-NEXT: v_floor_f32_e32 v4, v0
118 ; GFX12-NEXT: s_wait_alu 0xfffd
119 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_3)
120 ; GFX12-NEXT: v_cndmask_b32_e32 v0, 0, v3, vcc_lo
121 ; GFX12-NEXT: global_store_b32 v[1:2], v4, off
122 ; GFX12-NEXT: s_setpc_b64 s[30:31]
124 %floor = tail call float @llvm.floor.f32(float %x)
125 %sub = fsub float %x, %floor
126 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
127 %uno = fcmp uno float %x, 0.000000e+00
128 %cond = select i1 %uno, float %x, float %min
129 %fabs = tail call float @llvm.fabs.f32(float %x)
130 %cmpinf = fcmp oeq float %fabs, 0x7FF0000000000000
131 %cond6 = select i1 %cmpinf, float 0.000000e+00, float %cond
132 store float %floor, ptr addrspace(1) %ip, align 4
136 define float @safe_math_fract_f32_noinf_check(float %x, ptr addrspace(1) writeonly captures(none) %ip) {
137 ; GFX6-IR-LABEL: define float @safe_math_fract_f32_noinf_check
138 ; GFX6-IR-SAME: (float [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
139 ; GFX6-IR-NEXT: entry:
140 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
141 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
142 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
143 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno float [[X]], 0.000000e+00
144 ; GFX6-IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], float [[X]], float [[MIN]]
145 ; GFX6-IR-NEXT: store float [[FLOOR]], ptr addrspace(1) [[IP]], align 4
146 ; GFX6-IR-NEXT: ret float [[COND]]
148 ; IR-FRACT-LABEL: define float @safe_math_fract_f32_noinf_check
149 ; IR-FRACT-SAME: (float [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
150 ; IR-FRACT-NEXT: entry:
151 ; IR-FRACT-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
152 ; IR-FRACT-NEXT: [[COND:%.*]] = call float @llvm.amdgcn.fract.f32(float [[X]])
153 ; IR-FRACT-NEXT: store float [[FLOOR]], ptr addrspace(1) [[IP]], align 4
154 ; IR-FRACT-NEXT: ret float [[COND]]
156 ; GFX6-LABEL: safe_math_fract_f32_noinf_check:
157 ; GFX6: ; %bb.0: ; %entry
158 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
159 ; GFX6-NEXT: v_floor_f32_e32 v3, v0
160 ; GFX6-NEXT: v_sub_f32_e32 v4, v0, v3
161 ; GFX6-NEXT: s_mov_b32 s6, 0
162 ; GFX6-NEXT: v_min_f32_e32 v4, 0x3f7fffff, v4
163 ; GFX6-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
164 ; GFX6-NEXT: s_mov_b32 s7, 0xf000
165 ; GFX6-NEXT: s_mov_b32 s4, s6
166 ; GFX6-NEXT: s_mov_b32 s5, s6
167 ; GFX6-NEXT: v_cndmask_b32_e32 v0, v4, v0, vcc
168 ; GFX6-NEXT: buffer_store_dword v3, v[1:2], s[4:7], 0 addr64
169 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0)
170 ; GFX6-NEXT: s_setpc_b64 s[30:31]
172 ; GFX7-LABEL: safe_math_fract_f32_noinf_check:
173 ; GFX7: ; %bb.0: ; %entry
174 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
175 ; GFX7-NEXT: s_mov_b32 s6, 0
176 ; GFX7-NEXT: s_mov_b32 s7, 0xf000
177 ; GFX7-NEXT: s_mov_b32 s4, s6
178 ; GFX7-NEXT: s_mov_b32 s5, s6
179 ; GFX7-NEXT: v_floor_f32_e32 v3, v0
180 ; GFX7-NEXT: v_fract_f32_e32 v0, v0
181 ; GFX7-NEXT: buffer_store_dword v3, v[1:2], s[4:7], 0 addr64
182 ; GFX7-NEXT: s_waitcnt vmcnt(0)
183 ; GFX7-NEXT: s_setpc_b64 s[30:31]
185 ; GFX8-LABEL: safe_math_fract_f32_noinf_check:
186 ; GFX8: ; %bb.0: ; %entry
187 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
188 ; GFX8-NEXT: v_floor_f32_e32 v3, v0
189 ; GFX8-NEXT: v_fract_f32_e32 v0, v0
190 ; GFX8-NEXT: global_store_dword v[1:2], v3, off
191 ; GFX8-NEXT: s_waitcnt vmcnt(0)
192 ; GFX8-NEXT: s_setpc_b64 s[30:31]
194 ; GFX11-LABEL: safe_math_fract_f32_noinf_check:
195 ; GFX11: ; %bb.0: ; %entry
196 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
197 ; GFX11-NEXT: v_floor_f32_e32 v3, v0
198 ; GFX11-NEXT: v_fract_f32_e32 v0, v0
199 ; GFX11-NEXT: global_store_b32 v[1:2], v3, off
200 ; GFX11-NEXT: s_setpc_b64 s[30:31]
202 ; GFX12-LABEL: safe_math_fract_f32_noinf_check:
203 ; GFX12: ; %bb.0: ; %entry
204 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
205 ; GFX12-NEXT: s_wait_expcnt 0x0
206 ; GFX12-NEXT: s_wait_samplecnt 0x0
207 ; GFX12-NEXT: s_wait_bvhcnt 0x0
208 ; GFX12-NEXT: s_wait_kmcnt 0x0
209 ; GFX12-NEXT: v_floor_f32_e32 v3, v0
210 ; GFX12-NEXT: v_fract_f32_e32 v0, v0
211 ; GFX12-NEXT: global_store_b32 v[1:2], v3, off
212 ; GFX12-NEXT: s_setpc_b64 s[30:31]
214 %floor = tail call float @llvm.floor.f32(float %x)
215 %sub = fsub float %x, %floor
216 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
217 %uno = fcmp uno float %x, 0.000000e+00
218 %cond = select i1 %uno, float %x, float %min
219 store float %floor, ptr addrspace(1) %ip, align 4
223 ; Cannot match fract without a nan check or no-nans.
224 define float @no_nan_check_math_fract_f32(float %x, ptr addrspace(1) writeonly captures(none) %ip) {
225 ; IR-LABEL: define float @no_nan_check_math_fract_f32
226 ; IR-SAME: (float [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0:[0-9]+]] {
228 ; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
229 ; IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
230 ; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
231 ; IR-NEXT: [[FABS:%.*]] = tail call float @llvm.fabs.f32(float [[X]])
232 ; IR-NEXT: [[CMPINF:%.*]] = fcmp oeq float [[FABS]], 0x7FF0000000000000
233 ; IR-NEXT: [[COND6:%.*]] = select i1 [[CMPINF]], float 0.000000e+00, float [[MIN]]
234 ; IR-NEXT: store float [[FLOOR]], ptr addrspace(1) [[IP]], align 4
235 ; IR-NEXT: ret float [[COND6]]
237 ; GFX6-LABEL: no_nan_check_math_fract_f32:
238 ; GFX6: ; %bb.0: ; %entry
239 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
240 ; GFX6-NEXT: v_floor_f32_e32 v3, v0
241 ; GFX6-NEXT: v_sub_f32_e32 v4, v0, v3
242 ; GFX6-NEXT: s_mov_b32 s8, 0x7f800000
243 ; GFX6-NEXT: s_mov_b32 s6, 0
244 ; GFX6-NEXT: v_min_f32_e32 v4, 0x3f7fffff, v4
245 ; GFX6-NEXT: v_cmp_neq_f32_e64 vcc, |v0|, s8
246 ; GFX6-NEXT: s_mov_b32 s7, 0xf000
247 ; GFX6-NEXT: s_mov_b32 s4, s6
248 ; GFX6-NEXT: s_mov_b32 s5, s6
249 ; GFX6-NEXT: v_cndmask_b32_e32 v0, 0, v4, vcc
250 ; GFX6-NEXT: buffer_store_dword v3, v[1:2], s[4:7], 0 addr64
251 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0)
252 ; GFX6-NEXT: s_setpc_b64 s[30:31]
254 ; GFX7-LABEL: no_nan_check_math_fract_f32:
255 ; GFX7: ; %bb.0: ; %entry
256 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
257 ; GFX7-NEXT: v_floor_f32_e32 v3, v0
258 ; GFX7-NEXT: v_sub_f32_e32 v4, v0, v3
259 ; GFX7-NEXT: s_mov_b32 s8, 0x7f800000
260 ; GFX7-NEXT: s_mov_b32 s6, 0
261 ; GFX7-NEXT: v_min_f32_e32 v4, 0x3f7fffff, v4
262 ; GFX7-NEXT: v_cmp_neq_f32_e64 vcc, |v0|, s8
263 ; GFX7-NEXT: s_mov_b32 s7, 0xf000
264 ; GFX7-NEXT: s_mov_b32 s4, s6
265 ; GFX7-NEXT: s_mov_b32 s5, s6
266 ; GFX7-NEXT: v_cndmask_b32_e32 v0, 0, v4, vcc
267 ; GFX7-NEXT: buffer_store_dword v3, v[1:2], s[4:7], 0 addr64
268 ; GFX7-NEXT: s_waitcnt vmcnt(0)
269 ; GFX7-NEXT: s_setpc_b64 s[30:31]
271 ; GFX8-LABEL: no_nan_check_math_fract_f32:
272 ; GFX8: ; %bb.0: ; %entry
273 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
274 ; GFX8-NEXT: v_floor_f32_e32 v3, v0
275 ; GFX8-NEXT: v_sub_f32_e32 v4, v0, v3
276 ; GFX8-NEXT: s_mov_b32 s4, 0x7f800000
277 ; GFX8-NEXT: v_min_f32_e32 v4, 0x3f7fffff, v4
278 ; GFX8-NEXT: v_cmp_neq_f32_e64 vcc, |v0|, s4
279 ; GFX8-NEXT: v_cndmask_b32_e32 v0, 0, v4, vcc
280 ; GFX8-NEXT: global_store_dword v[1:2], v3, off
281 ; GFX8-NEXT: s_waitcnt vmcnt(0)
282 ; GFX8-NEXT: s_setpc_b64 s[30:31]
284 ; GFX11-LABEL: no_nan_check_math_fract_f32:
285 ; GFX11: ; %bb.0: ; %entry
286 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
287 ; GFX11-NEXT: v_floor_f32_e32 v3, v0
288 ; GFX11-NEXT: v_cmp_neq_f32_e64 vcc_lo, 0x7f800000, |v0|
289 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
290 ; GFX11-NEXT: v_sub_f32_e32 v4, v0, v3
291 ; GFX11-NEXT: global_store_b32 v[1:2], v3, off
292 ; GFX11-NEXT: v_min_f32_e32 v4, 0x3f7fffff, v4
293 ; GFX11-NEXT: v_cndmask_b32_e32 v0, 0, v4, vcc_lo
294 ; GFX11-NEXT: s_setpc_b64 s[30:31]
296 ; GFX12-LABEL: no_nan_check_math_fract_f32:
297 ; GFX12: ; %bb.0: ; %entry
298 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
299 ; GFX12-NEXT: s_wait_expcnt 0x0
300 ; GFX12-NEXT: s_wait_samplecnt 0x0
301 ; GFX12-NEXT: s_wait_bvhcnt 0x0
302 ; GFX12-NEXT: s_wait_kmcnt 0x0
303 ; GFX12-NEXT: v_floor_f32_e32 v3, v0
304 ; GFX12-NEXT: v_cmp_neq_f32_e64 vcc_lo, 0x7f800000, |v0|
305 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
306 ; GFX12-NEXT: v_sub_f32_e32 v4, v0, v3
307 ; GFX12-NEXT: global_store_b32 v[1:2], v3, off
308 ; GFX12-NEXT: v_min_num_f32_e32 v4, 0x3f7fffff, v4
309 ; GFX12-NEXT: s_wait_alu 0xfffd
310 ; GFX12-NEXT: v_cndmask_b32_e32 v0, 0, v4, vcc_lo
311 ; GFX12-NEXT: s_setpc_b64 s[30:31]
313 %floor = tail call float @llvm.floor.f32(float %x)
314 %sub = fsub float %x, %floor
315 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
316 %fabs = tail call float @llvm.fabs.f32(float %x)
317 %cmpinf = fcmp oeq float %fabs, 0x7FF0000000000000
318 %cond6 = select i1 %cmpinf, float 0.000000e+00, float %min
319 store float %floor, ptr addrspace(1) %ip, align 4
323 define float @basic_fract_f32_nonans(float nofpclass(nan) %x) {
324 ; GFX6-IR-LABEL: define float @basic_fract_f32_nonans
325 ; GFX6-IR-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
326 ; GFX6-IR-NEXT: entry:
327 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
328 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
329 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
330 ; GFX6-IR-NEXT: ret float [[MIN]]
332 ; IR-FRACT-LABEL: define float @basic_fract_f32_nonans
333 ; IR-FRACT-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
334 ; IR-FRACT-NEXT: entry:
335 ; IR-FRACT-NEXT: [[MIN:%.*]] = call nnan float @llvm.amdgcn.fract.f32(float [[X]])
336 ; IR-FRACT-NEXT: ret float [[MIN]]
338 ; GFX6-LABEL: basic_fract_f32_nonans:
339 ; GFX6: ; %bb.0: ; %entry
340 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
341 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
342 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
343 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
344 ; GFX6-NEXT: s_setpc_b64 s[30:31]
346 ; GFX7-LABEL: basic_fract_f32_nonans:
347 ; GFX7: ; %bb.0: ; %entry
348 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
349 ; GFX7-NEXT: v_fract_f32_e32 v0, v0
350 ; GFX7-NEXT: s_setpc_b64 s[30:31]
352 ; GFX8-LABEL: basic_fract_f32_nonans:
353 ; GFX8: ; %bb.0: ; %entry
354 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
355 ; GFX8-NEXT: v_fract_f32_e32 v0, v0
356 ; GFX8-NEXT: s_setpc_b64 s[30:31]
358 ; GFX11-LABEL: basic_fract_f32_nonans:
359 ; GFX11: ; %bb.0: ; %entry
360 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
361 ; GFX11-NEXT: v_fract_f32_e32 v0, v0
362 ; GFX11-NEXT: s_setpc_b64 s[30:31]
364 ; GFX12-LABEL: basic_fract_f32_nonans:
365 ; GFX12: ; %bb.0: ; %entry
366 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
367 ; GFX12-NEXT: s_wait_expcnt 0x0
368 ; GFX12-NEXT: s_wait_samplecnt 0x0
369 ; GFX12-NEXT: s_wait_bvhcnt 0x0
370 ; GFX12-NEXT: s_wait_kmcnt 0x0
371 ; GFX12-NEXT: v_fract_f32_e32 v0, v0
372 ; GFX12-NEXT: s_setpc_b64 s[30:31]
374 %floor = tail call float @llvm.floor.f32(float %x)
375 %sub = fsub float %x, %floor
376 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
380 define float @basic_fract_f32_flags_minnum(float %x) {
381 ; IR-LABEL: define float @basic_fract_f32_flags_minnum
382 ; IR-SAME: (float [[X:%.*]]) #[[ATTR0]] {
384 ; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
385 ; IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
386 ; IR-NEXT: [[MIN:%.*]] = tail call nsz float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
387 ; IR-NEXT: ret float [[MIN]]
389 ; GFX6-LABEL: basic_fract_f32_flags_minnum:
390 ; GFX6: ; %bb.0: ; %entry
391 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
392 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
393 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
394 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
395 ; GFX6-NEXT: s_setpc_b64 s[30:31]
397 ; GFX7-LABEL: basic_fract_f32_flags_minnum:
398 ; GFX7: ; %bb.0: ; %entry
399 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
400 ; GFX7-NEXT: v_floor_f32_e32 v1, v0
401 ; GFX7-NEXT: v_sub_f32_e32 v0, v0, v1
402 ; GFX7-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
403 ; GFX7-NEXT: s_setpc_b64 s[30:31]
405 ; GFX8-LABEL: basic_fract_f32_flags_minnum:
406 ; GFX8: ; %bb.0: ; %entry
407 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
408 ; GFX8-NEXT: v_floor_f32_e32 v1, v0
409 ; GFX8-NEXT: v_sub_f32_e32 v0, v0, v1
410 ; GFX8-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
411 ; GFX8-NEXT: s_setpc_b64 s[30:31]
413 ; GFX11-LABEL: basic_fract_f32_flags_minnum:
414 ; GFX11: ; %bb.0: ; %entry
415 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
416 ; GFX11-NEXT: v_floor_f32_e32 v1, v0
417 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
418 ; GFX11-NEXT: v_sub_f32_e32 v0, v0, v1
419 ; GFX11-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
420 ; GFX11-NEXT: s_setpc_b64 s[30:31]
422 ; GFX12-LABEL: basic_fract_f32_flags_minnum:
423 ; GFX12: ; %bb.0: ; %entry
424 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
425 ; GFX12-NEXT: s_wait_expcnt 0x0
426 ; GFX12-NEXT: s_wait_samplecnt 0x0
427 ; GFX12-NEXT: s_wait_bvhcnt 0x0
428 ; GFX12-NEXT: s_wait_kmcnt 0x0
429 ; GFX12-NEXT: v_floor_f32_e32 v1, v0
430 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
431 ; GFX12-NEXT: v_sub_f32_e32 v0, v0, v1
432 ; GFX12-NEXT: v_min_num_f32_e32 v0, 0x3f7fffff, v0
433 ; GFX12-NEXT: s_setpc_b64 s[30:31]
435 %floor = tail call float @llvm.floor.f32(float %x)
436 %sub = fsub float %x, %floor
437 %min = tail call nsz float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
441 define float @basic_fract_f32_flags_fsub(float nofpclass(nan) %x) {
442 ; GFX6-IR-LABEL: define float @basic_fract_f32_flags_fsub
443 ; GFX6-IR-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
444 ; GFX6-IR-NEXT: entry:
445 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
446 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub nsz float [[X]], [[FLOOR]]
447 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
448 ; GFX6-IR-NEXT: ret float [[MIN]]
450 ; IR-FRACT-LABEL: define float @basic_fract_f32_flags_fsub
451 ; IR-FRACT-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
452 ; IR-FRACT-NEXT: entry:
453 ; IR-FRACT-NEXT: [[MIN:%.*]] = call nnan float @llvm.amdgcn.fract.f32(float [[X]])
454 ; IR-FRACT-NEXT: ret float [[MIN]]
456 ; GFX6-LABEL: basic_fract_f32_flags_fsub:
457 ; GFX6: ; %bb.0: ; %entry
458 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
459 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
460 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
461 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
462 ; GFX6-NEXT: s_setpc_b64 s[30:31]
464 ; GFX7-LABEL: basic_fract_f32_flags_fsub:
465 ; GFX7: ; %bb.0: ; %entry
466 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
467 ; GFX7-NEXT: v_fract_f32_e32 v0, v0
468 ; GFX7-NEXT: s_setpc_b64 s[30:31]
470 ; GFX8-LABEL: basic_fract_f32_flags_fsub:
471 ; GFX8: ; %bb.0: ; %entry
472 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
473 ; GFX8-NEXT: v_fract_f32_e32 v0, v0
474 ; GFX8-NEXT: s_setpc_b64 s[30:31]
476 ; GFX11-LABEL: basic_fract_f32_flags_fsub:
477 ; GFX11: ; %bb.0: ; %entry
478 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
479 ; GFX11-NEXT: v_fract_f32_e32 v0, v0
480 ; GFX11-NEXT: s_setpc_b64 s[30:31]
482 ; GFX12-LABEL: basic_fract_f32_flags_fsub:
483 ; GFX12: ; %bb.0: ; %entry
484 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
485 ; GFX12-NEXT: s_wait_expcnt 0x0
486 ; GFX12-NEXT: s_wait_samplecnt 0x0
487 ; GFX12-NEXT: s_wait_bvhcnt 0x0
488 ; GFX12-NEXT: s_wait_kmcnt 0x0
489 ; GFX12-NEXT: v_fract_f32_e32 v0, v0
490 ; GFX12-NEXT: s_setpc_b64 s[30:31]
492 %floor = tail call float @llvm.floor.f32(float %x)
493 %sub = fsub nsz float %x, %floor
494 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
498 define <2 x float> @basic_fract_v2f32_nonans(<2 x float> nofpclass(nan) %x) {
499 ; GFX6-IR-LABEL: define <2 x float> @basic_fract_v2f32_nonans
500 ; GFX6-IR-SAME: (<2 x float> nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
501 ; GFX6-IR-NEXT: entry:
502 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call <2 x float> @llvm.floor.v2f32(<2 x float> [[X]])
503 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub <2 x float> [[X]], [[FLOOR]]
504 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call <2 x float> @llvm.minnum.v2f32(<2 x float> [[SUB]], <2 x float> splat (float 0x3FEFFFFFE0000000))
505 ; GFX6-IR-NEXT: ret <2 x float> [[MIN]]
507 ; IR-FRACT-LABEL: define <2 x float> @basic_fract_v2f32_nonans
508 ; IR-FRACT-SAME: (<2 x float> nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
509 ; IR-FRACT-NEXT: entry:
510 ; IR-FRACT-NEXT: [[TMP0:%.*]] = extractelement <2 x float> [[X]], i64 0
511 ; IR-FRACT-NEXT: [[TMP1:%.*]] = extractelement <2 x float> [[X]], i64 1
512 ; IR-FRACT-NEXT: [[TMP2:%.*]] = call nnan float @llvm.amdgcn.fract.f32(float [[TMP0]])
513 ; IR-FRACT-NEXT: [[TMP3:%.*]] = call nnan float @llvm.amdgcn.fract.f32(float [[TMP1]])
514 ; IR-FRACT-NEXT: [[TMP4:%.*]] = insertelement <2 x float> poison, float [[TMP2]], i64 0
515 ; IR-FRACT-NEXT: [[MIN:%.*]] = insertelement <2 x float> [[TMP4]], float [[TMP3]], i64 1
516 ; IR-FRACT-NEXT: ret <2 x float> [[MIN]]
518 ; GFX6-LABEL: basic_fract_v2f32_nonans:
519 ; GFX6: ; %bb.0: ; %entry
520 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
521 ; GFX6-NEXT: v_floor_f32_e32 v2, v0
522 ; GFX6-NEXT: v_floor_f32_e32 v3, v1
523 ; GFX6-NEXT: v_sub_f32_e32 v1, v1, v3
524 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v2
525 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
526 ; GFX6-NEXT: v_min_f32_e32 v1, 0x3f7fffff, v1
527 ; GFX6-NEXT: s_setpc_b64 s[30:31]
529 ; GFX7-LABEL: basic_fract_v2f32_nonans:
530 ; GFX7: ; %bb.0: ; %entry
531 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
532 ; GFX7-NEXT: v_fract_f32_e32 v0, v0
533 ; GFX7-NEXT: v_fract_f32_e32 v1, v1
534 ; GFX7-NEXT: s_setpc_b64 s[30:31]
536 ; GFX8-LABEL: basic_fract_v2f32_nonans:
537 ; GFX8: ; %bb.0: ; %entry
538 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
539 ; GFX8-NEXT: v_fract_f32_e32 v0, v0
540 ; GFX8-NEXT: v_fract_f32_e32 v1, v1
541 ; GFX8-NEXT: s_setpc_b64 s[30:31]
543 ; GFX11-LABEL: basic_fract_v2f32_nonans:
544 ; GFX11: ; %bb.0: ; %entry
545 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
546 ; GFX11-NEXT: v_fract_f32_e32 v0, v0
547 ; GFX11-NEXT: v_fract_f32_e32 v1, v1
548 ; GFX11-NEXT: s_setpc_b64 s[30:31]
550 ; GFX12-LABEL: basic_fract_v2f32_nonans:
551 ; GFX12: ; %bb.0: ; %entry
552 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
553 ; GFX12-NEXT: s_wait_expcnt 0x0
554 ; GFX12-NEXT: s_wait_samplecnt 0x0
555 ; GFX12-NEXT: s_wait_bvhcnt 0x0
556 ; GFX12-NEXT: s_wait_kmcnt 0x0
557 ; GFX12-NEXT: v_fract_f32_e32 v0, v0
558 ; GFX12-NEXT: v_fract_f32_e32 v1, v1
559 ; GFX12-NEXT: s_setpc_b64 s[30:31]
561 %floor = tail call <2 x float> @llvm.floor.v2f32(<2 x float> %x)
562 %sub = fsub <2 x float> %x, %floor
563 %min = tail call <2 x float> @llvm.minnum.v2f32(<2 x float> %sub, <2 x float> <float 0x3FEFFFFFE0000000, float 0x3FEFFFFFE0000000>)
567 define float @basic_fract_f32_multi_use_fsub_nonans(float nofpclass(nan) %x, ptr addrspace(1) %ptr) {
568 ; GFX6-IR-LABEL: define float @basic_fract_f32_multi_use_fsub_nonans
569 ; GFX6-IR-SAME: (float nofpclass(nan) [[X:%.*]], ptr addrspace(1) [[PTR:%.*]]) #[[ATTR0]] {
570 ; GFX6-IR-NEXT: entry:
571 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
572 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
573 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
574 ; GFX6-IR-NEXT: store float [[SUB]], ptr addrspace(1) [[PTR]], align 4
575 ; GFX6-IR-NEXT: ret float [[MIN]]
577 ; IR-FRACT-LABEL: define float @basic_fract_f32_multi_use_fsub_nonans
578 ; IR-FRACT-SAME: (float nofpclass(nan) [[X:%.*]], ptr addrspace(1) [[PTR:%.*]]) #[[ATTR0]] {
579 ; IR-FRACT-NEXT: entry:
580 ; IR-FRACT-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
581 ; IR-FRACT-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
582 ; IR-FRACT-NEXT: [[MIN:%.*]] = call nnan float @llvm.amdgcn.fract.f32(float [[X]])
583 ; IR-FRACT-NEXT: store float [[SUB]], ptr addrspace(1) [[PTR]], align 4
584 ; IR-FRACT-NEXT: ret float [[MIN]]
586 ; GFX6-LABEL: basic_fract_f32_multi_use_fsub_nonans:
587 ; GFX6: ; %bb.0: ; %entry
588 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
589 ; GFX6-NEXT: v_floor_f32_e32 v3, v0
590 ; GFX6-NEXT: s_mov_b32 s6, 0
591 ; GFX6-NEXT: v_sub_f32_e32 v3, v0, v3
592 ; GFX6-NEXT: s_mov_b32 s7, 0xf000
593 ; GFX6-NEXT: s_mov_b32 s4, s6
594 ; GFX6-NEXT: s_mov_b32 s5, s6
595 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v3
596 ; GFX6-NEXT: buffer_store_dword v3, v[1:2], s[4:7], 0 addr64
597 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0)
598 ; GFX6-NEXT: s_setpc_b64 s[30:31]
600 ; GFX7-LABEL: basic_fract_f32_multi_use_fsub_nonans:
601 ; GFX7: ; %bb.0: ; %entry
602 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
603 ; GFX7-NEXT: s_mov_b32 s6, 0
604 ; GFX7-NEXT: v_floor_f32_e32 v3, v0
605 ; GFX7-NEXT: s_mov_b32 s7, 0xf000
606 ; GFX7-NEXT: s_mov_b32 s4, s6
607 ; GFX7-NEXT: s_mov_b32 s5, s6
608 ; GFX7-NEXT: v_sub_f32_e32 v3, v0, v3
609 ; GFX7-NEXT: v_fract_f32_e32 v0, v0
610 ; GFX7-NEXT: buffer_store_dword v3, v[1:2], s[4:7], 0 addr64
611 ; GFX7-NEXT: s_waitcnt vmcnt(0)
612 ; GFX7-NEXT: s_setpc_b64 s[30:31]
614 ; GFX8-LABEL: basic_fract_f32_multi_use_fsub_nonans:
615 ; GFX8: ; %bb.0: ; %entry
616 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
617 ; GFX8-NEXT: v_floor_f32_e32 v3, v0
618 ; GFX8-NEXT: v_sub_f32_e32 v3, v0, v3
619 ; GFX8-NEXT: v_fract_f32_e32 v0, v0
620 ; GFX8-NEXT: global_store_dword v[1:2], v3, off
621 ; GFX8-NEXT: s_waitcnt vmcnt(0)
622 ; GFX8-NEXT: s_setpc_b64 s[30:31]
624 ; GFX11-LABEL: basic_fract_f32_multi_use_fsub_nonans:
625 ; GFX11: ; %bb.0: ; %entry
626 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
627 ; GFX11-NEXT: v_floor_f32_e32 v3, v0
628 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1)
629 ; GFX11-NEXT: v_sub_f32_e32 v3, v0, v3
630 ; GFX11-NEXT: v_fract_f32_e32 v0, v0
631 ; GFX11-NEXT: global_store_b32 v[1:2], v3, off
632 ; GFX11-NEXT: s_setpc_b64 s[30:31]
634 ; GFX12-LABEL: basic_fract_f32_multi_use_fsub_nonans:
635 ; GFX12: ; %bb.0: ; %entry
636 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
637 ; GFX12-NEXT: s_wait_expcnt 0x0
638 ; GFX12-NEXT: s_wait_samplecnt 0x0
639 ; GFX12-NEXT: s_wait_bvhcnt 0x0
640 ; GFX12-NEXT: s_wait_kmcnt 0x0
641 ; GFX12-NEXT: v_floor_f32_e32 v3, v0
642 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1)
643 ; GFX12-NEXT: v_sub_f32_e32 v3, v0, v3
644 ; GFX12-NEXT: v_fract_f32_e32 v0, v0
645 ; GFX12-NEXT: global_store_b32 v[1:2], v3, off
646 ; GFX12-NEXT: s_setpc_b64 s[30:31]
648 %floor = tail call float @llvm.floor.f32(float %x)
649 %sub = fsub float %x, %floor
650 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
651 store float %sub, ptr addrspace(1) %ptr
655 define float @nnan_minnum_fract_f32(float %x) {
656 ; GFX6-IR-LABEL: define float @nnan_minnum_fract_f32
657 ; GFX6-IR-SAME: (float [[X:%.*]]) #[[ATTR0]] {
658 ; GFX6-IR-NEXT: entry:
659 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
660 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
661 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call nnan float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
662 ; GFX6-IR-NEXT: ret float [[MIN]]
664 ; IR-FRACT-LABEL: define float @nnan_minnum_fract_f32
665 ; IR-FRACT-SAME: (float [[X:%.*]]) #[[ATTR0]] {
666 ; IR-FRACT-NEXT: entry:
667 ; IR-FRACT-NEXT: [[MIN:%.*]] = call nnan float @llvm.amdgcn.fract.f32(float [[X]])
668 ; IR-FRACT-NEXT: ret float [[MIN]]
670 ; GFX6-LABEL: nnan_minnum_fract_f32:
671 ; GFX6: ; %bb.0: ; %entry
672 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
673 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
674 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
675 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
676 ; GFX6-NEXT: s_setpc_b64 s[30:31]
678 ; GFX7-LABEL: nnan_minnum_fract_f32:
679 ; GFX7: ; %bb.0: ; %entry
680 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
681 ; GFX7-NEXT: v_fract_f32_e32 v0, v0
682 ; GFX7-NEXT: s_setpc_b64 s[30:31]
684 ; GFX8-LABEL: nnan_minnum_fract_f32:
685 ; GFX8: ; %bb.0: ; %entry
686 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
687 ; GFX8-NEXT: v_fract_f32_e32 v0, v0
688 ; GFX8-NEXT: s_setpc_b64 s[30:31]
690 ; GFX11-LABEL: nnan_minnum_fract_f32:
691 ; GFX11: ; %bb.0: ; %entry
692 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
693 ; GFX11-NEXT: v_fract_f32_e32 v0, v0
694 ; GFX11-NEXT: s_setpc_b64 s[30:31]
696 ; GFX12-LABEL: nnan_minnum_fract_f32:
697 ; GFX12: ; %bb.0: ; %entry
698 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
699 ; GFX12-NEXT: s_wait_expcnt 0x0
700 ; GFX12-NEXT: s_wait_samplecnt 0x0
701 ; GFX12-NEXT: s_wait_bvhcnt 0x0
702 ; GFX12-NEXT: s_wait_kmcnt 0x0
703 ; GFX12-NEXT: v_fract_f32_e32 v0, v0
704 ; GFX12-NEXT: s_setpc_b64 s[30:31]
706 %floor = tail call float @llvm.floor.f32(float %x)
707 %sub = fsub float %x, %floor
708 %min = tail call nnan float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
712 ; TODO: Could match if we checked isKnownNeverNaN on the minnum src
713 ; instead of the pattern input source.
714 define float @nnan_fsub_fract_f32(float %x) {
715 ; IR-LABEL: define float @nnan_fsub_fract_f32
716 ; IR-SAME: (float [[X:%.*]]) #[[ATTR0]] {
718 ; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
719 ; IR-NEXT: [[SUB:%.*]] = fsub nnan float [[X]], [[FLOOR]]
720 ; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
721 ; IR-NEXT: ret float [[MIN]]
723 ; GFX6-LABEL: nnan_fsub_fract_f32:
724 ; GFX6: ; %bb.0: ; %entry
725 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
726 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
727 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
728 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
729 ; GFX6-NEXT: s_setpc_b64 s[30:31]
731 ; GFX7-LABEL: nnan_fsub_fract_f32:
732 ; GFX7: ; %bb.0: ; %entry
733 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
734 ; GFX7-NEXT: v_floor_f32_e32 v1, v0
735 ; GFX7-NEXT: v_sub_f32_e32 v0, v0, v1
736 ; GFX7-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
737 ; GFX7-NEXT: s_setpc_b64 s[30:31]
739 ; GFX8-LABEL: nnan_fsub_fract_f32:
740 ; GFX8: ; %bb.0: ; %entry
741 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
742 ; GFX8-NEXT: v_floor_f32_e32 v1, v0
743 ; GFX8-NEXT: v_sub_f32_e32 v0, v0, v1
744 ; GFX8-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
745 ; GFX8-NEXT: s_setpc_b64 s[30:31]
747 ; GFX11-LABEL: nnan_fsub_fract_f32:
748 ; GFX11: ; %bb.0: ; %entry
749 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
750 ; GFX11-NEXT: v_floor_f32_e32 v1, v0
751 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
752 ; GFX11-NEXT: v_sub_f32_e32 v0, v0, v1
753 ; GFX11-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
754 ; GFX11-NEXT: s_setpc_b64 s[30:31]
756 ; GFX12-LABEL: nnan_fsub_fract_f32:
757 ; GFX12: ; %bb.0: ; %entry
758 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
759 ; GFX12-NEXT: s_wait_expcnt 0x0
760 ; GFX12-NEXT: s_wait_samplecnt 0x0
761 ; GFX12-NEXT: s_wait_bvhcnt 0x0
762 ; GFX12-NEXT: s_wait_kmcnt 0x0
763 ; GFX12-NEXT: v_floor_f32_e32 v1, v0
764 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
765 ; GFX12-NEXT: v_sub_f32_e32 v0, v0, v1
766 ; GFX12-NEXT: v_min_num_f32_e32 v0, 0x3f7fffff, v0
767 ; GFX12-NEXT: s_setpc_b64 s[30:31]
769 %floor = tail call float @llvm.floor.f32(float %x)
770 %sub = fsub nnan float %x, %floor
771 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
775 define float @nnan_floor_fract_f32(float %x) {
776 ; IR-LABEL: define float @nnan_floor_fract_f32
777 ; IR-SAME: (float [[X:%.*]]) #[[ATTR0]] {
779 ; IR-NEXT: [[FLOOR:%.*]] = tail call nnan float @llvm.floor.f32(float [[X]])
780 ; IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
781 ; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
782 ; IR-NEXT: ret float [[MIN]]
784 ; GFX6-LABEL: nnan_floor_fract_f32:
785 ; GFX6: ; %bb.0: ; %entry
786 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
787 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
788 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
789 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
790 ; GFX6-NEXT: s_setpc_b64 s[30:31]
792 ; GFX7-LABEL: nnan_floor_fract_f32:
793 ; GFX7: ; %bb.0: ; %entry
794 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
795 ; GFX7-NEXT: v_floor_f32_e32 v1, v0
796 ; GFX7-NEXT: v_sub_f32_e32 v0, v0, v1
797 ; GFX7-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
798 ; GFX7-NEXT: s_setpc_b64 s[30:31]
800 ; GFX8-LABEL: nnan_floor_fract_f32:
801 ; GFX8: ; %bb.0: ; %entry
802 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
803 ; GFX8-NEXT: v_floor_f32_e32 v1, v0
804 ; GFX8-NEXT: v_sub_f32_e32 v0, v0, v1
805 ; GFX8-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
806 ; GFX8-NEXT: s_setpc_b64 s[30:31]
808 ; GFX11-LABEL: nnan_floor_fract_f32:
809 ; GFX11: ; %bb.0: ; %entry
810 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
811 ; GFX11-NEXT: v_floor_f32_e32 v1, v0
812 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
813 ; GFX11-NEXT: v_sub_f32_e32 v0, v0, v1
814 ; GFX11-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
815 ; GFX11-NEXT: s_setpc_b64 s[30:31]
817 ; GFX12-LABEL: nnan_floor_fract_f32:
818 ; GFX12: ; %bb.0: ; %entry
819 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
820 ; GFX12-NEXT: s_wait_expcnt 0x0
821 ; GFX12-NEXT: s_wait_samplecnt 0x0
822 ; GFX12-NEXT: s_wait_bvhcnt 0x0
823 ; GFX12-NEXT: s_wait_kmcnt 0x0
824 ; GFX12-NEXT: v_floor_f32_e32 v1, v0
825 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
826 ; GFX12-NEXT: v_sub_f32_e32 v0, v0, v1
827 ; GFX12-NEXT: v_min_num_f32_e32 v0, 0x3f7fffff, v0
828 ; GFX12-NEXT: s_setpc_b64 s[30:31]
830 %floor = tail call nnan float @llvm.floor.f32(float %x)
831 %sub = fsub float %x, %floor
832 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
836 define float @nnan_src_fract_f32(float nofpclass(nan) %x) {
837 ; GFX6-IR-LABEL: define float @nnan_src_fract_f32
838 ; GFX6-IR-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
839 ; GFX6-IR-NEXT: entry:
840 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
841 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
842 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
843 ; GFX6-IR-NEXT: ret float [[MIN]]
845 ; IR-FRACT-LABEL: define float @nnan_src_fract_f32
846 ; IR-FRACT-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
847 ; IR-FRACT-NEXT: entry:
848 ; IR-FRACT-NEXT: [[MIN:%.*]] = call nnan float @llvm.amdgcn.fract.f32(float [[X]])
849 ; IR-FRACT-NEXT: ret float [[MIN]]
851 ; GFX6-LABEL: nnan_src_fract_f32:
852 ; GFX6: ; %bb.0: ; %entry
853 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
854 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
855 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
856 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
857 ; GFX6-NEXT: s_setpc_b64 s[30:31]
859 ; GFX7-LABEL: nnan_src_fract_f32:
860 ; GFX7: ; %bb.0: ; %entry
861 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
862 ; GFX7-NEXT: v_fract_f32_e32 v0, v0
863 ; GFX7-NEXT: s_setpc_b64 s[30:31]
865 ; GFX8-LABEL: nnan_src_fract_f32:
866 ; GFX8: ; %bb.0: ; %entry
867 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
868 ; GFX8-NEXT: v_fract_f32_e32 v0, v0
869 ; GFX8-NEXT: s_setpc_b64 s[30:31]
871 ; GFX11-LABEL: nnan_src_fract_f32:
872 ; GFX11: ; %bb.0: ; %entry
873 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
874 ; GFX11-NEXT: v_fract_f32_e32 v0, v0
875 ; GFX11-NEXT: s_setpc_b64 s[30:31]
877 ; GFX12-LABEL: nnan_src_fract_f32:
878 ; GFX12: ; %bb.0: ; %entry
879 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
880 ; GFX12-NEXT: s_wait_expcnt 0x0
881 ; GFX12-NEXT: s_wait_samplecnt 0x0
882 ; GFX12-NEXT: s_wait_bvhcnt 0x0
883 ; GFX12-NEXT: s_wait_kmcnt 0x0
884 ; GFX12-NEXT: v_fract_f32_e32 v0, v0
885 ; GFX12-NEXT: s_setpc_b64 s[30:31]
887 %floor = tail call float @llvm.floor.f32(float %x)
888 %sub = fsub float %x, %floor
889 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
894 define float @not_fract_f32_wrong_const(float nofpclass(nan) %x) {
895 ; IR-LABEL: define float @not_fract_f32_wrong_const
896 ; IR-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
898 ; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
899 ; IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
900 ; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFC0000000)
901 ; IR-NEXT: ret float [[MIN]]
903 ; GFX6-LABEL: not_fract_f32_wrong_const:
904 ; GFX6: ; %bb.0: ; %entry
905 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
906 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
907 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
908 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7ffffe, v0
909 ; GFX6-NEXT: s_setpc_b64 s[30:31]
911 ; GFX7-LABEL: not_fract_f32_wrong_const:
912 ; GFX7: ; %bb.0: ; %entry
913 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
914 ; GFX7-NEXT: v_floor_f32_e32 v1, v0
915 ; GFX7-NEXT: v_sub_f32_e32 v0, v0, v1
916 ; GFX7-NEXT: v_min_f32_e32 v0, 0x3f7ffffe, v0
917 ; GFX7-NEXT: s_setpc_b64 s[30:31]
919 ; GFX8-LABEL: not_fract_f32_wrong_const:
920 ; GFX8: ; %bb.0: ; %entry
921 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
922 ; GFX8-NEXT: v_floor_f32_e32 v1, v0
923 ; GFX8-NEXT: v_sub_f32_e32 v0, v0, v1
924 ; GFX8-NEXT: v_min_f32_e32 v0, 0x3f7ffffe, v0
925 ; GFX8-NEXT: s_setpc_b64 s[30:31]
927 ; GFX11-LABEL: not_fract_f32_wrong_const:
928 ; GFX11: ; %bb.0: ; %entry
929 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
930 ; GFX11-NEXT: v_floor_f32_e32 v1, v0
931 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
932 ; GFX11-NEXT: v_sub_f32_e32 v0, v0, v1
933 ; GFX11-NEXT: v_min_f32_e32 v0, 0x3f7ffffe, v0
934 ; GFX11-NEXT: s_setpc_b64 s[30:31]
936 ; GFX12-LABEL: not_fract_f32_wrong_const:
937 ; GFX12: ; %bb.0: ; %entry
938 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
939 ; GFX12-NEXT: s_wait_expcnt 0x0
940 ; GFX12-NEXT: s_wait_samplecnt 0x0
941 ; GFX12-NEXT: s_wait_bvhcnt 0x0
942 ; GFX12-NEXT: s_wait_kmcnt 0x0
943 ; GFX12-NEXT: v_floor_f32_e32 v1, v0
944 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
945 ; GFX12-NEXT: v_sub_f32_e32 v0, v0, v1
946 ; GFX12-NEXT: v_min_num_f32_e32 v0, 0x3f7ffffe, v0
947 ; GFX12-NEXT: s_setpc_b64 s[30:31]
949 %floor = tail call float @llvm.floor.f32(float %x)
950 %sub = fsub float %x, %floor
951 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFC0000000)
956 define float @not_fract_f32_swapped_fsub(float nofpclass(nan) %x) {
957 ; IR-LABEL: define float @not_fract_f32_swapped_fsub
958 ; IR-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
960 ; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
961 ; IR-NEXT: [[SUB:%.*]] = fsub float [[FLOOR]], [[X]]
962 ; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
963 ; IR-NEXT: ret float [[MIN]]
965 ; GFX6-LABEL: not_fract_f32_swapped_fsub:
966 ; GFX6: ; %bb.0: ; %entry
967 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
968 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
969 ; GFX6-NEXT: v_sub_f32_e32 v0, v1, v0
970 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
971 ; GFX6-NEXT: s_setpc_b64 s[30:31]
973 ; GFX7-LABEL: not_fract_f32_swapped_fsub:
974 ; GFX7: ; %bb.0: ; %entry
975 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
976 ; GFX7-NEXT: v_floor_f32_e32 v1, v0
977 ; GFX7-NEXT: v_sub_f32_e32 v0, v1, v0
978 ; GFX7-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
979 ; GFX7-NEXT: s_setpc_b64 s[30:31]
981 ; GFX8-LABEL: not_fract_f32_swapped_fsub:
982 ; GFX8: ; %bb.0: ; %entry
983 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
984 ; GFX8-NEXT: v_floor_f32_e32 v1, v0
985 ; GFX8-NEXT: v_sub_f32_e32 v0, v1, v0
986 ; GFX8-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
987 ; GFX8-NEXT: s_setpc_b64 s[30:31]
989 ; GFX11-LABEL: not_fract_f32_swapped_fsub:
990 ; GFX11: ; %bb.0: ; %entry
991 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
992 ; GFX11-NEXT: v_floor_f32_e32 v1, v0
993 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
994 ; GFX11-NEXT: v_sub_f32_e32 v0, v1, v0
995 ; GFX11-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
996 ; GFX11-NEXT: s_setpc_b64 s[30:31]
998 ; GFX12-LABEL: not_fract_f32_swapped_fsub:
999 ; GFX12: ; %bb.0: ; %entry
1000 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1001 ; GFX12-NEXT: s_wait_expcnt 0x0
1002 ; GFX12-NEXT: s_wait_samplecnt 0x0
1003 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1004 ; GFX12-NEXT: s_wait_kmcnt 0x0
1005 ; GFX12-NEXT: v_floor_f32_e32 v1, v0
1006 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
1007 ; GFX12-NEXT: v_sub_f32_e32 v0, v1, v0
1008 ; GFX12-NEXT: v_min_num_f32_e32 v0, 0x3f7fffff, v0
1009 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1011 %floor = tail call float @llvm.floor.f32(float %x)
1012 %sub = fsub float %floor, %x
1013 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
1018 define float @not_fract_f32_not_floor(float nofpclass(nan) %x) {
1019 ; IR-LABEL: define float @not_fract_f32_not_floor
1020 ; IR-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
1022 ; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.trunc.f32(float [[X]])
1023 ; IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
1024 ; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
1025 ; IR-NEXT: ret float [[MIN]]
1027 ; GFX6-LABEL: not_fract_f32_not_floor:
1028 ; GFX6: ; %bb.0: ; %entry
1029 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1030 ; GFX6-NEXT: v_trunc_f32_e32 v1, v0
1031 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
1032 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
1033 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1035 ; GFX7-LABEL: not_fract_f32_not_floor:
1036 ; GFX7: ; %bb.0: ; %entry
1037 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1038 ; GFX7-NEXT: v_trunc_f32_e32 v1, v0
1039 ; GFX7-NEXT: v_sub_f32_e32 v0, v0, v1
1040 ; GFX7-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
1041 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1043 ; GFX8-LABEL: not_fract_f32_not_floor:
1044 ; GFX8: ; %bb.0: ; %entry
1045 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1046 ; GFX8-NEXT: v_trunc_f32_e32 v1, v0
1047 ; GFX8-NEXT: v_sub_f32_e32 v0, v0, v1
1048 ; GFX8-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
1049 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1051 ; GFX11-LABEL: not_fract_f32_not_floor:
1052 ; GFX11: ; %bb.0: ; %entry
1053 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1054 ; GFX11-NEXT: v_trunc_f32_e32 v1, v0
1055 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
1056 ; GFX11-NEXT: v_sub_f32_e32 v0, v0, v1
1057 ; GFX11-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
1058 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1060 ; GFX12-LABEL: not_fract_f32_not_floor:
1061 ; GFX12: ; %bb.0: ; %entry
1062 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1063 ; GFX12-NEXT: s_wait_expcnt 0x0
1064 ; GFX12-NEXT: s_wait_samplecnt 0x0
1065 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1066 ; GFX12-NEXT: s_wait_kmcnt 0x0
1067 ; GFX12-NEXT: v_trunc_f32_e32 v1, v0
1068 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
1069 ; GFX12-NEXT: v_sub_f32_e32 v0, v0, v1
1070 ; GFX12-NEXT: v_min_num_f32_e32 v0, 0x3f7fffff, v0
1071 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1073 %floor = tail call float @llvm.trunc.f32(float %x)
1074 %sub = fsub float %x, %floor
1075 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
1080 define float @not_fract_f32_different_floor(float %x, float %y) {
1081 ; IR-LABEL: define float @not_fract_f32_different_floor
1082 ; IR-SAME: (float [[X:%.*]], float [[Y:%.*]]) #[[ATTR0]] {
1084 ; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[Y]])
1085 ; IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
1086 ; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
1087 ; IR-NEXT: ret float [[MIN]]
1089 ; GFX6-LABEL: not_fract_f32_different_floor:
1090 ; GFX6: ; %bb.0: ; %entry
1091 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1092 ; GFX6-NEXT: v_floor_f32_e32 v1, v1
1093 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
1094 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
1095 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1097 ; GFX7-LABEL: not_fract_f32_different_floor:
1098 ; GFX7: ; %bb.0: ; %entry
1099 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1100 ; GFX7-NEXT: v_floor_f32_e32 v1, v1
1101 ; GFX7-NEXT: v_sub_f32_e32 v0, v0, v1
1102 ; GFX7-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
1103 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1105 ; GFX8-LABEL: not_fract_f32_different_floor:
1106 ; GFX8: ; %bb.0: ; %entry
1107 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1108 ; GFX8-NEXT: v_floor_f32_e32 v1, v1
1109 ; GFX8-NEXT: v_sub_f32_e32 v0, v0, v1
1110 ; GFX8-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
1111 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1113 ; GFX11-LABEL: not_fract_f32_different_floor:
1114 ; GFX11: ; %bb.0: ; %entry
1115 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1116 ; GFX11-NEXT: v_floor_f32_e32 v1, v1
1117 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
1118 ; GFX11-NEXT: v_sub_f32_e32 v0, v0, v1
1119 ; GFX11-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
1120 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1122 ; GFX12-LABEL: not_fract_f32_different_floor:
1123 ; GFX12: ; %bb.0: ; %entry
1124 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1125 ; GFX12-NEXT: s_wait_expcnt 0x0
1126 ; GFX12-NEXT: s_wait_samplecnt 0x0
1127 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1128 ; GFX12-NEXT: s_wait_kmcnt 0x0
1129 ; GFX12-NEXT: v_floor_f32_e32 v1, v1
1130 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
1131 ; GFX12-NEXT: v_sub_f32_e32 v0, v0, v1
1132 ; GFX12-NEXT: v_min_num_f32_e32 v0, 0x3f7fffff, v0
1133 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1135 %floor = tail call float @llvm.floor.f32(float %y)
1136 %sub = fsub float %x, %floor
1137 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
1142 define float @not_fract_f32_maxnum(float nofpclass(nan) %x) {
1143 ; IR-LABEL: define float @not_fract_f32_maxnum
1144 ; IR-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
1146 ; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
1147 ; IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
1148 ; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.maxnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
1149 ; IR-NEXT: ret float [[MIN]]
1151 ; GFX6-LABEL: not_fract_f32_maxnum:
1152 ; GFX6: ; %bb.0: ; %entry
1153 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1154 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
1155 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
1156 ; GFX6-NEXT: v_max_f32_e32 v0, 0x3f7fffff, v0
1157 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1159 ; GFX7-LABEL: not_fract_f32_maxnum:
1160 ; GFX7: ; %bb.0: ; %entry
1161 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1162 ; GFX7-NEXT: v_floor_f32_e32 v1, v0
1163 ; GFX7-NEXT: v_sub_f32_e32 v0, v0, v1
1164 ; GFX7-NEXT: v_max_f32_e32 v0, 0x3f7fffff, v0
1165 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1167 ; GFX8-LABEL: not_fract_f32_maxnum:
1168 ; GFX8: ; %bb.0: ; %entry
1169 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1170 ; GFX8-NEXT: v_floor_f32_e32 v1, v0
1171 ; GFX8-NEXT: v_sub_f32_e32 v0, v0, v1
1172 ; GFX8-NEXT: v_max_f32_e32 v0, 0x3f7fffff, v0
1173 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1175 ; GFX11-LABEL: not_fract_f32_maxnum:
1176 ; GFX11: ; %bb.0: ; %entry
1177 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1178 ; GFX11-NEXT: v_floor_f32_e32 v1, v0
1179 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
1180 ; GFX11-NEXT: v_sub_f32_e32 v0, v0, v1
1181 ; GFX11-NEXT: v_max_f32_e32 v0, 0x3f7fffff, v0
1182 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1184 ; GFX12-LABEL: not_fract_f32_maxnum:
1185 ; GFX12: ; %bb.0: ; %entry
1186 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1187 ; GFX12-NEXT: s_wait_expcnt 0x0
1188 ; GFX12-NEXT: s_wait_samplecnt 0x0
1189 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1190 ; GFX12-NEXT: s_wait_kmcnt 0x0
1191 ; GFX12-NEXT: v_floor_f32_e32 v1, v0
1192 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
1193 ; GFX12-NEXT: v_sub_f32_e32 v0, v0, v1
1194 ; GFX12-NEXT: v_max_num_f32_e32 v0, 0x3f7fffff, v0
1195 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1197 %floor = tail call float @llvm.floor.f32(float %x)
1198 %sub = fsub float %x, %floor
1199 %min = tail call float @llvm.maxnum.f32(float %sub, float 0x3FEFFFFFE0000000)
1203 define float @fcmp_uno_check_is_nan_f32(float %x) {
1204 ; IR-LABEL: define float @fcmp_uno_check_is_nan_f32
1205 ; IR-SAME: (float [[X:%.*]]) #[[ATTR0]] {
1207 ; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
1208 ; IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
1209 ; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
1210 ; IR-NEXT: [[UNO:%.*]] = fcmp uno float [[X]], 0x7FF8000000000000
1211 ; IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], float [[X]], float [[MIN]]
1212 ; IR-NEXT: ret float [[COND]]
1214 ; GCN-LABEL: fcmp_uno_check_is_nan_f32:
1215 ; GCN: ; %bb.0: ; %entry
1216 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1217 ; GCN-NEXT: s_setpc_b64 s[30:31]
1219 ; GFX12-LABEL: fcmp_uno_check_is_nan_f32:
1220 ; GFX12: ; %bb.0: ; %entry
1221 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1222 ; GFX12-NEXT: s_wait_expcnt 0x0
1223 ; GFX12-NEXT: s_wait_samplecnt 0x0
1224 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1225 ; GFX12-NEXT: s_wait_kmcnt 0x0
1226 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1228 %floor = tail call float @llvm.floor.f32(float %x)
1229 %sub = fsub float %x, %floor
1230 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
1231 %uno = fcmp uno float %x, 0x7FF8000000000000
1232 %cond = select i1 %uno, float %x, float %min
1237 define float @select_nan_fract_f32(float %x) {
1238 ; GFX6-IR-LABEL: define float @select_nan_fract_f32
1239 ; GFX6-IR-SAME: (float [[X:%.*]]) #[[ATTR0]] {
1240 ; GFX6-IR-NEXT: entry:
1241 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
1242 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
1243 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
1244 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno float [[X]], 0.000000e+00
1245 ; GFX6-IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], float [[X]], float [[MIN]]
1246 ; GFX6-IR-NEXT: ret float [[COND]]
1248 ; IR-FRACT-LABEL: define float @select_nan_fract_f32
1249 ; IR-FRACT-SAME: (float [[X:%.*]]) #[[ATTR0]] {
1250 ; IR-FRACT-NEXT: entry:
1251 ; IR-FRACT-NEXT: [[COND:%.*]] = call float @llvm.amdgcn.fract.f32(float [[X]])
1252 ; IR-FRACT-NEXT: ret float [[COND]]
1254 ; GFX6-LABEL: select_nan_fract_f32:
1255 ; GFX6: ; %bb.0: ; %entry
1256 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1257 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
1258 ; GFX6-NEXT: v_sub_f32_e32 v1, v0, v1
1259 ; GFX6-NEXT: v_min_f32_e32 v1, 0x3f7fffff, v1
1260 ; GFX6-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
1261 ; GFX6-NEXT: v_cndmask_b32_e32 v0, v1, v0, vcc
1262 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1264 ; GFX7-LABEL: select_nan_fract_f32:
1265 ; GFX7: ; %bb.0: ; %entry
1266 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1267 ; GFX7-NEXT: v_fract_f32_e32 v0, v0
1268 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1270 ; GFX8-LABEL: select_nan_fract_f32:
1271 ; GFX8: ; %bb.0: ; %entry
1272 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1273 ; GFX8-NEXT: v_fract_f32_e32 v0, v0
1274 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1276 ; GFX11-LABEL: select_nan_fract_f32:
1277 ; GFX11: ; %bb.0: ; %entry
1278 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1279 ; GFX11-NEXT: v_fract_f32_e32 v0, v0
1280 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1282 ; GFX12-LABEL: select_nan_fract_f32:
1283 ; GFX12: ; %bb.0: ; %entry
1284 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1285 ; GFX12-NEXT: s_wait_expcnt 0x0
1286 ; GFX12-NEXT: s_wait_samplecnt 0x0
1287 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1288 ; GFX12-NEXT: s_wait_kmcnt 0x0
1289 ; GFX12-NEXT: v_fract_f32_e32 v0, v0
1290 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1292 %floor = tail call float @llvm.floor.f32(float %x)
1293 %sub = fsub float %x, %floor
1294 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
1295 %uno = fcmp uno float %x, 0.000000e+00
1296 %cond = select i1 %uno, float %x, float %min
1300 define float @commuted_select_nan_fract_f32(float %x) {
1301 ; GFX6-IR-LABEL: define float @commuted_select_nan_fract_f32
1302 ; GFX6-IR-SAME: (float [[X:%.*]]) #[[ATTR0]] {
1303 ; GFX6-IR-NEXT: entry:
1304 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
1305 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
1306 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
1307 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp ord float [[X]], 0.000000e+00
1308 ; GFX6-IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], float [[MIN]], float [[X]]
1309 ; GFX6-IR-NEXT: ret float [[COND]]
1311 ; IR-FRACT-LABEL: define float @commuted_select_nan_fract_f32
1312 ; IR-FRACT-SAME: (float [[X:%.*]]) #[[ATTR0]] {
1313 ; IR-FRACT-NEXT: entry:
1314 ; IR-FRACT-NEXT: [[COND:%.*]] = call float @llvm.amdgcn.fract.f32(float [[X]])
1315 ; IR-FRACT-NEXT: ret float [[COND]]
1317 ; GFX6-LABEL: commuted_select_nan_fract_f32:
1318 ; GFX6: ; %bb.0: ; %entry
1319 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1320 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
1321 ; GFX6-NEXT: v_sub_f32_e32 v1, v0, v1
1322 ; GFX6-NEXT: v_min_f32_e32 v1, 0x3f7fffff, v1
1323 ; GFX6-NEXT: v_cmp_o_f32_e32 vcc, v0, v0
1324 ; GFX6-NEXT: v_cndmask_b32_e32 v0, v0, v1, vcc
1325 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1327 ; GFX7-LABEL: commuted_select_nan_fract_f32:
1328 ; GFX7: ; %bb.0: ; %entry
1329 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1330 ; GFX7-NEXT: v_fract_f32_e32 v0, v0
1331 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1333 ; GFX8-LABEL: commuted_select_nan_fract_f32:
1334 ; GFX8: ; %bb.0: ; %entry
1335 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1336 ; GFX8-NEXT: v_fract_f32_e32 v0, v0
1337 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1339 ; GFX11-LABEL: commuted_select_nan_fract_f32:
1340 ; GFX11: ; %bb.0: ; %entry
1341 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1342 ; GFX11-NEXT: v_fract_f32_e32 v0, v0
1343 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1345 ; GFX12-LABEL: commuted_select_nan_fract_f32:
1346 ; GFX12: ; %bb.0: ; %entry
1347 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1348 ; GFX12-NEXT: s_wait_expcnt 0x0
1349 ; GFX12-NEXT: s_wait_samplecnt 0x0
1350 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1351 ; GFX12-NEXT: s_wait_kmcnt 0x0
1352 ; GFX12-NEXT: v_fract_f32_e32 v0, v0
1353 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1355 %floor = tail call float @llvm.floor.f32(float %x)
1356 %sub = fsub float %x, %floor
1357 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
1358 %uno = fcmp ord float %x, 0.000000e+00
1359 %cond = select i1 %uno, float %min, float %x
1363 define float @wrong_commuted_nan_select_f32(float %x) {
1364 ; IR-LABEL: define float @wrong_commuted_nan_select_f32
1365 ; IR-SAME: (float [[X:%.*]]) #[[ATTR0]] {
1367 ; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
1368 ; IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
1369 ; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
1370 ; IR-NEXT: [[UNO:%.*]] = fcmp uno float [[X]], 0.000000e+00
1371 ; IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], float [[MIN]], float [[X]]
1372 ; IR-NEXT: ret float [[COND]]
1374 ; GFX6-LABEL: wrong_commuted_nan_select_f32:
1375 ; GFX6: ; %bb.0: ; %entry
1376 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1377 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
1378 ; GFX6-NEXT: v_sub_f32_e32 v1, v0, v1
1379 ; GFX6-NEXT: v_min_f32_e32 v1, 0x3f7fffff, v1
1380 ; GFX6-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
1381 ; GFX6-NEXT: v_cndmask_b32_e32 v0, v0, v1, vcc
1382 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1384 ; GFX7-LABEL: wrong_commuted_nan_select_f32:
1385 ; GFX7: ; %bb.0: ; %entry
1386 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1387 ; GFX7-NEXT: v_floor_f32_e32 v1, v0
1388 ; GFX7-NEXT: v_sub_f32_e32 v1, v0, v1
1389 ; GFX7-NEXT: v_min_f32_e32 v1, 0x3f7fffff, v1
1390 ; GFX7-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
1391 ; GFX7-NEXT: v_cndmask_b32_e32 v0, v0, v1, vcc
1392 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1394 ; GFX8-LABEL: wrong_commuted_nan_select_f32:
1395 ; GFX8: ; %bb.0: ; %entry
1396 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1397 ; GFX8-NEXT: v_floor_f32_e32 v1, v0
1398 ; GFX8-NEXT: v_sub_f32_e32 v1, v0, v1
1399 ; GFX8-NEXT: v_min_f32_e32 v1, 0x3f7fffff, v1
1400 ; GFX8-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
1401 ; GFX8-NEXT: v_cndmask_b32_e32 v0, v0, v1, vcc
1402 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1404 ; GFX11-LABEL: wrong_commuted_nan_select_f32:
1405 ; GFX11: ; %bb.0: ; %entry
1406 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1407 ; GFX11-NEXT: v_floor_f32_e32 v1, v0
1408 ; GFX11-NEXT: v_cmp_u_f32_e32 vcc_lo, v0, v0
1409 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
1410 ; GFX11-NEXT: v_sub_f32_e32 v1, v0, v1
1411 ; GFX11-NEXT: v_min_f32_e32 v1, 0x3f7fffff, v1
1412 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1)
1413 ; GFX11-NEXT: v_cndmask_b32_e32 v0, v0, v1, vcc_lo
1414 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1416 ; GFX12-LABEL: wrong_commuted_nan_select_f32:
1417 ; GFX12: ; %bb.0: ; %entry
1418 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1419 ; GFX12-NEXT: s_wait_expcnt 0x0
1420 ; GFX12-NEXT: s_wait_samplecnt 0x0
1421 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1422 ; GFX12-NEXT: s_wait_kmcnt 0x0
1423 ; GFX12-NEXT: v_floor_f32_e32 v1, v0
1424 ; GFX12-NEXT: v_cmp_u_f32_e32 vcc_lo, v0, v0
1425 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
1426 ; GFX12-NEXT: v_sub_f32_e32 v1, v0, v1
1427 ; GFX12-NEXT: v_min_num_f32_e32 v1, 0x3f7fffff, v1
1428 ; GFX12-NEXT: s_wait_alu 0xfffd
1429 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1)
1430 ; GFX12-NEXT: v_cndmask_b32_e32 v0, v0, v1, vcc_lo
1431 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1433 %floor = tail call float @llvm.floor.f32(float %x)
1434 %sub = fsub float %x, %floor
1435 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
1436 %uno = fcmp uno float %x, 0.000000e+00
1437 %cond = select i1 %uno, float %min, float %x
1441 define half @basic_fract_f16_nonan(half nofpclass(nan) %x) {
1442 ; GFX6-IR-LABEL: define half @basic_fract_f16_nonan
1443 ; GFX6-IR-SAME: (half nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
1444 ; GFX6-IR-NEXT: entry:
1445 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call half @llvm.floor.f16(half [[X]])
1446 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub half [[X]], [[FLOOR]]
1447 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call half @llvm.minnum.f16(half [[SUB]], half 0xH3BFF)
1448 ; GFX6-IR-NEXT: ret half [[MIN]]
1450 ; GFX7-IR-LABEL: define half @basic_fract_f16_nonan
1451 ; GFX7-IR-SAME: (half nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
1452 ; GFX7-IR-NEXT: entry:
1453 ; GFX7-IR-NEXT: [[FLOOR:%.*]] = tail call half @llvm.floor.f16(half [[X]])
1454 ; GFX7-IR-NEXT: [[SUB:%.*]] = fsub half [[X]], [[FLOOR]]
1455 ; GFX7-IR-NEXT: [[MIN:%.*]] = tail call half @llvm.minnum.f16(half [[SUB]], half 0xH3BFF)
1456 ; GFX7-IR-NEXT: ret half [[MIN]]
1458 ; IR-LEGALF16-LABEL: define half @basic_fract_f16_nonan
1459 ; IR-LEGALF16-SAME: (half nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
1460 ; IR-LEGALF16-NEXT: entry:
1461 ; IR-LEGALF16-NEXT: [[MIN:%.*]] = call nnan half @llvm.amdgcn.fract.f16(half [[X]])
1462 ; IR-LEGALF16-NEXT: ret half [[MIN]]
1464 ; GFX6-LABEL: basic_fract_f16_nonan:
1465 ; GFX6: ; %bb.0: ; %entry
1466 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1467 ; GFX6-NEXT: v_cvt_f16_f32_e32 v0, v0
1468 ; GFX6-NEXT: v_cvt_f32_f16_e32 v0, v0
1469 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
1470 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
1471 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fe000, v0
1472 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1474 ; GFX7-LABEL: basic_fract_f16_nonan:
1475 ; GFX7: ; %bb.0: ; %entry
1476 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1477 ; GFX7-NEXT: v_cvt_f16_f32_e32 v0, v0
1478 ; GFX7-NEXT: v_cvt_f32_f16_e32 v0, v0
1479 ; GFX7-NEXT: v_floor_f32_e32 v1, v0
1480 ; GFX7-NEXT: v_sub_f32_e32 v0, v0, v1
1481 ; GFX7-NEXT: v_min_f32_e32 v0, 0x3f7fe000, v0
1482 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1484 ; GFX8-LABEL: basic_fract_f16_nonan:
1485 ; GFX8: ; %bb.0: ; %entry
1486 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1487 ; GFX8-NEXT: v_fract_f16_e32 v0, v0
1488 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1490 ; GFX11-LABEL: basic_fract_f16_nonan:
1491 ; GFX11: ; %bb.0: ; %entry
1492 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1493 ; GFX11-NEXT: v_fract_f16_e32 v0, v0
1494 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1496 ; GFX12-LABEL: basic_fract_f16_nonan:
1497 ; GFX12: ; %bb.0: ; %entry
1498 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1499 ; GFX12-NEXT: s_wait_expcnt 0x0
1500 ; GFX12-NEXT: s_wait_samplecnt 0x0
1501 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1502 ; GFX12-NEXT: s_wait_kmcnt 0x0
1503 ; GFX12-NEXT: v_fract_f16_e32 v0, v0
1504 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1506 %floor = tail call half @llvm.floor.f16(half %x)
1507 %sub = fsub half %x, %floor
1508 %min = tail call half @llvm.minnum.f16(half %sub, half 0xH3BFF)
1512 define <2 x half> @basic_fract_v2f16_nonan(<2 x half> nofpclass(nan) %x) {
1513 ; GFX6-IR-LABEL: define <2 x half> @basic_fract_v2f16_nonan
1514 ; GFX6-IR-SAME: (<2 x half> nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
1515 ; GFX6-IR-NEXT: entry:
1516 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call <2 x half> @llvm.floor.v2f16(<2 x half> [[X]])
1517 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub <2 x half> [[X]], [[FLOOR]]
1518 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call <2 x half> @llvm.minnum.v2f16(<2 x half> [[SUB]], <2 x half> splat (half 0xH3BFF))
1519 ; GFX6-IR-NEXT: ret <2 x half> [[MIN]]
1521 ; GFX7-IR-LABEL: define <2 x half> @basic_fract_v2f16_nonan
1522 ; GFX7-IR-SAME: (<2 x half> nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
1523 ; GFX7-IR-NEXT: entry:
1524 ; GFX7-IR-NEXT: [[FLOOR:%.*]] = tail call <2 x half> @llvm.floor.v2f16(<2 x half> [[X]])
1525 ; GFX7-IR-NEXT: [[SUB:%.*]] = fsub <2 x half> [[X]], [[FLOOR]]
1526 ; GFX7-IR-NEXT: [[MIN:%.*]] = tail call <2 x half> @llvm.minnum.v2f16(<2 x half> [[SUB]], <2 x half> splat (half 0xH3BFF))
1527 ; GFX7-IR-NEXT: ret <2 x half> [[MIN]]
1529 ; IR-LEGALF16-LABEL: define <2 x half> @basic_fract_v2f16_nonan
1530 ; IR-LEGALF16-SAME: (<2 x half> nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
1531 ; IR-LEGALF16-NEXT: entry:
1532 ; IR-LEGALF16-NEXT: [[TMP0:%.*]] = extractelement <2 x half> [[X]], i64 0
1533 ; IR-LEGALF16-NEXT: [[TMP1:%.*]] = extractelement <2 x half> [[X]], i64 1
1534 ; IR-LEGALF16-NEXT: [[TMP2:%.*]] = call nnan half @llvm.amdgcn.fract.f16(half [[TMP0]])
1535 ; IR-LEGALF16-NEXT: [[TMP3:%.*]] = call nnan half @llvm.amdgcn.fract.f16(half [[TMP1]])
1536 ; IR-LEGALF16-NEXT: [[TMP4:%.*]] = insertelement <2 x half> poison, half [[TMP2]], i64 0
1537 ; IR-LEGALF16-NEXT: [[MIN:%.*]] = insertelement <2 x half> [[TMP4]], half [[TMP3]], i64 1
1538 ; IR-LEGALF16-NEXT: ret <2 x half> [[MIN]]
1540 ; GFX6-LABEL: basic_fract_v2f16_nonan:
1541 ; GFX6: ; %bb.0: ; %entry
1542 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1543 ; GFX6-NEXT: v_cvt_f16_f32_e32 v0, v0
1544 ; GFX6-NEXT: v_cvt_f16_f32_e32 v1, v1
1545 ; GFX6-NEXT: v_cvt_f32_f16_e32 v0, v0
1546 ; GFX6-NEXT: v_cvt_f32_f16_e32 v1, v1
1547 ; GFX6-NEXT: v_floor_f32_e32 v2, v0
1548 ; GFX6-NEXT: v_floor_f32_e32 v3, v1
1549 ; GFX6-NEXT: v_sub_f32_e32 v1, v1, v3
1550 ; GFX6-NEXT: v_sub_f32_e32 v0, v0, v2
1551 ; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fe000, v0
1552 ; GFX6-NEXT: v_min_f32_e32 v1, 0x3f7fe000, v1
1553 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1555 ; GFX7-LABEL: basic_fract_v2f16_nonan:
1556 ; GFX7: ; %bb.0: ; %entry
1557 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1558 ; GFX7-NEXT: v_cvt_f16_f32_e32 v0, v0
1559 ; GFX7-NEXT: v_cvt_f16_f32_e32 v1, v1
1560 ; GFX7-NEXT: v_cvt_f32_f16_e32 v0, v0
1561 ; GFX7-NEXT: v_cvt_f32_f16_e32 v1, v1
1562 ; GFX7-NEXT: v_floor_f32_e32 v2, v0
1563 ; GFX7-NEXT: v_floor_f32_e32 v3, v1
1564 ; GFX7-NEXT: v_sub_f32_e32 v1, v1, v3
1565 ; GFX7-NEXT: v_sub_f32_e32 v0, v0, v2
1566 ; GFX7-NEXT: v_min_f32_e32 v0, 0x3f7fe000, v0
1567 ; GFX7-NEXT: v_min_f32_e32 v1, 0x3f7fe000, v1
1568 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1570 ; GFX8-LABEL: basic_fract_v2f16_nonan:
1571 ; GFX8: ; %bb.0: ; %entry
1572 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1573 ; GFX8-NEXT: v_fract_f16_e32 v1, v0
1574 ; GFX8-NEXT: v_fract_f16_sdwa v0, v0 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1
1575 ; GFX8-NEXT: v_pack_b32_f16 v0, v1, v0
1576 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1578 ; GFX11-LABEL: basic_fract_v2f16_nonan:
1579 ; GFX11: ; %bb.0: ; %entry
1580 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1581 ; GFX11-NEXT: v_lshrrev_b32_e32 v1, 16, v0
1582 ; GFX11-NEXT: v_fract_f16_e32 v0, v0
1583 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
1584 ; GFX11-NEXT: v_fract_f16_e32 v1, v1
1585 ; GFX11-NEXT: v_pack_b32_f16 v0, v0, v1
1586 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1588 ; GFX12-LABEL: basic_fract_v2f16_nonan:
1589 ; GFX12: ; %bb.0: ; %entry
1590 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1591 ; GFX12-NEXT: s_wait_expcnt 0x0
1592 ; GFX12-NEXT: s_wait_samplecnt 0x0
1593 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1594 ; GFX12-NEXT: s_wait_kmcnt 0x0
1595 ; GFX12-NEXT: v_lshrrev_b32_e32 v1, 16, v0
1596 ; GFX12-NEXT: v_fract_f16_e32 v0, v0
1597 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
1598 ; GFX12-NEXT: v_fract_f16_e32 v1, v1
1599 ; GFX12-NEXT: v_pack_b32_f16 v0, v0, v1
1600 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1602 %floor = tail call <2 x half> @llvm.floor.v2f16(<2 x half> %x)
1603 %sub = fsub <2 x half> %x, %floor
1604 %min = tail call <2 x half> @llvm.minnum.v2f16(<2 x half> %sub, <2 x half> <half 0xH3BFF, half 0xH3BFF>)
1608 define double @basic_fract_f64_nanans(double nofpclass(nan) %x) {
1609 ; GFX6-IR-LABEL: define double @basic_fract_f64_nanans
1610 ; GFX6-IR-SAME: (double nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
1611 ; GFX6-IR-NEXT: entry:
1612 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call double @llvm.floor.f64(double [[X]])
1613 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub double [[X]], [[FLOOR]]
1614 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call double @llvm.minnum.f64(double [[SUB]], double 0x3FEFFFFFFFFFFFFF)
1615 ; GFX6-IR-NEXT: ret double [[MIN]]
1617 ; IR-FRACT-LABEL: define double @basic_fract_f64_nanans
1618 ; IR-FRACT-SAME: (double nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
1619 ; IR-FRACT-NEXT: entry:
1620 ; IR-FRACT-NEXT: [[MIN:%.*]] = call nnan double @llvm.amdgcn.fract.f64(double [[X]])
1621 ; IR-FRACT-NEXT: ret double [[MIN]]
1623 ; GFX6-LABEL: basic_fract_f64_nanans:
1624 ; GFX6: ; %bb.0: ; %entry
1625 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1626 ; GFX6-NEXT: v_fract_f64_e32 v[2:3], v[0:1]
1627 ; GFX6-NEXT: v_mov_b32_e32 v4, -1
1628 ; GFX6-NEXT: v_mov_b32_e32 v5, 0x3fefffff
1629 ; GFX6-NEXT: v_min_f64 v[2:3], v[2:3], v[4:5]
1630 ; GFX6-NEXT: v_cmp_class_f64_e64 vcc, v[0:1], 3
1631 ; GFX6-NEXT: s_mov_b32 s4, -1
1632 ; GFX6-NEXT: v_cndmask_b32_e32 v2, v2, v0, vcc
1633 ; GFX6-NEXT: v_cndmask_b32_e32 v3, v3, v1, vcc
1634 ; GFX6-NEXT: v_add_f64 v[2:3], v[0:1], -v[2:3]
1635 ; GFX6-NEXT: s_mov_b32 s5, 0x3fefffff
1636 ; GFX6-NEXT: v_add_f64 v[0:1], v[0:1], -v[2:3]
1637 ; GFX6-NEXT: v_min_f64 v[0:1], v[0:1], s[4:5]
1638 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1640 ; GFX7-LABEL: basic_fract_f64_nanans:
1641 ; GFX7: ; %bb.0: ; %entry
1642 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1643 ; GFX7-NEXT: v_fract_f64_e32 v[0:1], v[0:1]
1644 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1646 ; GFX8-LABEL: basic_fract_f64_nanans:
1647 ; GFX8: ; %bb.0: ; %entry
1648 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1649 ; GFX8-NEXT: v_fract_f64_e32 v[0:1], v[0:1]
1650 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1652 ; GFX11-LABEL: basic_fract_f64_nanans:
1653 ; GFX11: ; %bb.0: ; %entry
1654 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1655 ; GFX11-NEXT: v_fract_f64_e32 v[0:1], v[0:1]
1656 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1658 ; GFX12-LABEL: basic_fract_f64_nanans:
1659 ; GFX12: ; %bb.0: ; %entry
1660 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1661 ; GFX12-NEXT: s_wait_expcnt 0x0
1662 ; GFX12-NEXT: s_wait_samplecnt 0x0
1663 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1664 ; GFX12-NEXT: s_wait_kmcnt 0x0
1665 ; GFX12-NEXT: v_fract_f64_e32 v[0:1], v[0:1]
1666 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1668 %floor = tail call double @llvm.floor.f64(double %x)
1669 %sub = fsub double %x, %floor
1670 %min = tail call double @llvm.minnum.f64(double %sub, double 0x3FEFFFFFFFFFFFFF)
1674 define half @safe_math_fract_f16_noinf_check(half %x, ptr addrspace(1) writeonly captures(none) %ip) {
1675 ; GFX6-IR-LABEL: define half @safe_math_fract_f16_noinf_check
1676 ; GFX6-IR-SAME: (half [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
1677 ; GFX6-IR-NEXT: entry:
1678 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call half @llvm.floor.f16(half [[X]])
1679 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub half [[X]], [[FLOOR]]
1680 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call half @llvm.minnum.f16(half [[SUB]], half 0xH3BFF)
1681 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno half [[X]], 0xH0000
1682 ; GFX6-IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], half [[X]], half [[MIN]]
1683 ; GFX6-IR-NEXT: store half [[FLOOR]], ptr addrspace(1) [[IP]], align 4
1684 ; GFX6-IR-NEXT: ret half [[COND]]
1686 ; GFX7-IR-LABEL: define half @safe_math_fract_f16_noinf_check
1687 ; GFX7-IR-SAME: (half [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
1688 ; GFX7-IR-NEXT: entry:
1689 ; GFX7-IR-NEXT: [[FLOOR:%.*]] = tail call half @llvm.floor.f16(half [[X]])
1690 ; GFX7-IR-NEXT: [[SUB:%.*]] = fsub half [[X]], [[FLOOR]]
1691 ; GFX7-IR-NEXT: [[MIN:%.*]] = tail call half @llvm.minnum.f16(half [[SUB]], half 0xH3BFF)
1692 ; GFX7-IR-NEXT: [[UNO:%.*]] = fcmp uno half [[X]], 0xH0000
1693 ; GFX7-IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], half [[X]], half [[MIN]]
1694 ; GFX7-IR-NEXT: store half [[FLOOR]], ptr addrspace(1) [[IP]], align 4
1695 ; GFX7-IR-NEXT: ret half [[COND]]
1697 ; IR-LEGALF16-LABEL: define half @safe_math_fract_f16_noinf_check
1698 ; IR-LEGALF16-SAME: (half [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
1699 ; IR-LEGALF16-NEXT: entry:
1700 ; IR-LEGALF16-NEXT: [[FLOOR:%.*]] = tail call half @llvm.floor.f16(half [[X]])
1701 ; IR-LEGALF16-NEXT: [[COND:%.*]] = call half @llvm.amdgcn.fract.f16(half [[X]])
1702 ; IR-LEGALF16-NEXT: store half [[FLOOR]], ptr addrspace(1) [[IP]], align 4
1703 ; IR-LEGALF16-NEXT: ret half [[COND]]
1705 ; GFX6-LABEL: safe_math_fract_f16_noinf_check:
1706 ; GFX6: ; %bb.0: ; %entry
1707 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1708 ; GFX6-NEXT: v_cvt_f16_f32_e32 v0, v0
1709 ; GFX6-NEXT: s_mov_b32 s6, 0
1710 ; GFX6-NEXT: s_mov_b32 s7, 0xf000
1711 ; GFX6-NEXT: s_mov_b32 s4, s6
1712 ; GFX6-NEXT: v_cvt_f32_f16_e32 v0, v0
1713 ; GFX6-NEXT: s_mov_b32 s5, s6
1714 ; GFX6-NEXT: v_floor_f32_e32 v3, v0
1715 ; GFX6-NEXT: v_sub_f32_e32 v4, v0, v3
1716 ; GFX6-NEXT: v_cvt_f16_f32_e32 v3, v3
1717 ; GFX6-NEXT: v_min_f32_e32 v4, 0x3f7fe000, v4
1718 ; GFX6-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
1719 ; GFX6-NEXT: v_cndmask_b32_e32 v0, v4, v0, vcc
1720 ; GFX6-NEXT: buffer_store_short v3, v[1:2], s[4:7], 0 addr64
1721 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0)
1722 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1724 ; GFX7-LABEL: safe_math_fract_f16_noinf_check:
1725 ; GFX7: ; %bb.0: ; %entry
1726 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1727 ; GFX7-NEXT: v_cvt_f16_f32_e32 v0, v0
1728 ; GFX7-NEXT: s_mov_b32 s6, 0
1729 ; GFX7-NEXT: s_mov_b32 s7, 0xf000
1730 ; GFX7-NEXT: s_mov_b32 s4, s6
1731 ; GFX7-NEXT: v_cvt_f32_f16_e32 v0, v0
1732 ; GFX7-NEXT: s_mov_b32 s5, s6
1733 ; GFX7-NEXT: v_floor_f32_e32 v3, v0
1734 ; GFX7-NEXT: v_sub_f32_e32 v4, v0, v3
1735 ; GFX7-NEXT: v_cvt_f16_f32_e32 v3, v3
1736 ; GFX7-NEXT: v_min_f32_e32 v4, 0x3f7fe000, v4
1737 ; GFX7-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
1738 ; GFX7-NEXT: v_cndmask_b32_e32 v0, v4, v0, vcc
1739 ; GFX7-NEXT: buffer_store_short v3, v[1:2], s[4:7], 0 addr64
1740 ; GFX7-NEXT: s_waitcnt vmcnt(0)
1741 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1743 ; GFX8-LABEL: safe_math_fract_f16_noinf_check:
1744 ; GFX8: ; %bb.0: ; %entry
1745 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1746 ; GFX8-NEXT: v_floor_f16_e32 v3, v0
1747 ; GFX8-NEXT: v_fract_f16_e32 v0, v0
1748 ; GFX8-NEXT: global_store_short v[1:2], v3, off
1749 ; GFX8-NEXT: s_waitcnt vmcnt(0)
1750 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1752 ; GFX11-LABEL: safe_math_fract_f16_noinf_check:
1753 ; GFX11: ; %bb.0: ; %entry
1754 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1755 ; GFX11-NEXT: v_floor_f16_e32 v3, v0
1756 ; GFX11-NEXT: v_fract_f16_e32 v0, v0
1757 ; GFX11-NEXT: global_store_b16 v[1:2], v3, off
1758 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1760 ; GFX12-LABEL: safe_math_fract_f16_noinf_check:
1761 ; GFX12: ; %bb.0: ; %entry
1762 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1763 ; GFX12-NEXT: s_wait_expcnt 0x0
1764 ; GFX12-NEXT: s_wait_samplecnt 0x0
1765 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1766 ; GFX12-NEXT: s_wait_kmcnt 0x0
1767 ; GFX12-NEXT: v_floor_f16_e32 v3, v0
1768 ; GFX12-NEXT: v_fract_f16_e32 v0, v0
1769 ; GFX12-NEXT: global_store_b16 v[1:2], v3, off
1770 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1772 %floor = tail call half @llvm.floor.f16(half %x)
1773 %sub = fsub half %x, %floor
1774 %min = tail call half @llvm.minnum.f16(half %sub, half 0xH3BFF)
1775 %uno = fcmp uno half %x, 0.000000e+00
1776 %cond = select i1 %uno, half %x, half %min
1777 store half %floor, ptr addrspace(1) %ip, align 4
1781 define double @safe_math_fract_f64_noinf_check(double %x, ptr addrspace(1) writeonly captures(none) %ip) {
1782 ; GFX6-IR-LABEL: define double @safe_math_fract_f64_noinf_check
1783 ; GFX6-IR-SAME: (double [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
1784 ; GFX6-IR-NEXT: entry:
1785 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call double @llvm.floor.f64(double [[X]])
1786 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub double [[X]], [[FLOOR]]
1787 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call double @llvm.minnum.f64(double [[SUB]], double 0x3FEFFFFFFFFFFFFF)
1788 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno double [[X]], 0.000000e+00
1789 ; GFX6-IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], double [[X]], double [[MIN]]
1790 ; GFX6-IR-NEXT: store double [[FLOOR]], ptr addrspace(1) [[IP]], align 4
1791 ; GFX6-IR-NEXT: ret double [[COND]]
1793 ; IR-FRACT-LABEL: define double @safe_math_fract_f64_noinf_check
1794 ; IR-FRACT-SAME: (double [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
1795 ; IR-FRACT-NEXT: entry:
1796 ; IR-FRACT-NEXT: [[FLOOR:%.*]] = tail call double @llvm.floor.f64(double [[X]])
1797 ; IR-FRACT-NEXT: [[COND:%.*]] = call double @llvm.amdgcn.fract.f64(double [[X]])
1798 ; IR-FRACT-NEXT: store double [[FLOOR]], ptr addrspace(1) [[IP]], align 4
1799 ; IR-FRACT-NEXT: ret double [[COND]]
1801 ; GFX6-LABEL: safe_math_fract_f64_noinf_check:
1802 ; GFX6: ; %bb.0: ; %entry
1803 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1804 ; GFX6-NEXT: v_fract_f64_e32 v[4:5], v[0:1]
1805 ; GFX6-NEXT: v_mov_b32_e32 v6, -1
1806 ; GFX6-NEXT: v_mov_b32_e32 v7, 0x3fefffff
1807 ; GFX6-NEXT: v_min_f64 v[4:5], v[4:5], v[6:7]
1808 ; GFX6-NEXT: v_cmp_class_f64_e64 vcc, v[0:1], 3
1809 ; GFX6-NEXT: s_mov_b32 s8, -1
1810 ; GFX6-NEXT: v_cndmask_b32_e32 v4, v4, v0, vcc
1811 ; GFX6-NEXT: v_cndmask_b32_e32 v5, v5, v1, vcc
1812 ; GFX6-NEXT: v_add_f64 v[4:5], v[0:1], -v[4:5]
1813 ; GFX6-NEXT: s_mov_b32 s9, 0x3fefffff
1814 ; GFX6-NEXT: v_add_f64 v[6:7], v[0:1], -v[4:5]
1815 ; GFX6-NEXT: v_cmp_u_f64_e32 vcc, v[0:1], v[0:1]
1816 ; GFX6-NEXT: v_min_f64 v[6:7], v[6:7], s[8:9]
1817 ; GFX6-NEXT: s_mov_b32 s6, 0
1818 ; GFX6-NEXT: s_mov_b32 s7, 0xf000
1819 ; GFX6-NEXT: s_mov_b32 s4, s6
1820 ; GFX6-NEXT: s_mov_b32 s5, s6
1821 ; GFX6-NEXT: v_cndmask_b32_e32 v0, v6, v0, vcc
1822 ; GFX6-NEXT: v_cndmask_b32_e32 v1, v7, v1, vcc
1823 ; GFX6-NEXT: buffer_store_dwordx2 v[4:5], v[2:3], s[4:7], 0 addr64
1824 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0)
1825 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1827 ; GFX7-LABEL: safe_math_fract_f64_noinf_check:
1828 ; GFX7: ; %bb.0: ; %entry
1829 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1830 ; GFX7-NEXT: v_floor_f64_e32 v[4:5], v[0:1]
1831 ; GFX7-NEXT: v_fract_f64_e32 v[0:1], v[0:1]
1832 ; GFX7-NEXT: s_mov_b32 s6, 0
1833 ; GFX7-NEXT: s_mov_b32 s7, 0xf000
1834 ; GFX7-NEXT: s_mov_b32 s4, s6
1835 ; GFX7-NEXT: s_mov_b32 s5, s6
1836 ; GFX7-NEXT: buffer_store_dwordx2 v[4:5], v[2:3], s[4:7], 0 addr64
1837 ; GFX7-NEXT: s_waitcnt vmcnt(0)
1838 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1840 ; GFX8-LABEL: safe_math_fract_f64_noinf_check:
1841 ; GFX8: ; %bb.0: ; %entry
1842 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1843 ; GFX8-NEXT: v_floor_f64_e32 v[4:5], v[0:1]
1844 ; GFX8-NEXT: v_fract_f64_e32 v[0:1], v[0:1]
1845 ; GFX8-NEXT: global_store_dwordx2 v[2:3], v[4:5], off
1846 ; GFX8-NEXT: s_waitcnt vmcnt(0)
1847 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1849 ; GFX11-LABEL: safe_math_fract_f64_noinf_check:
1850 ; GFX11: ; %bb.0: ; %entry
1851 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1852 ; GFX11-NEXT: v_floor_f64_e32 v[4:5], v[0:1]
1853 ; GFX11-NEXT: v_fract_f64_e32 v[0:1], v[0:1]
1854 ; GFX11-NEXT: global_store_b64 v[2:3], v[4:5], off
1855 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1857 ; GFX12-LABEL: safe_math_fract_f64_noinf_check:
1858 ; GFX12: ; %bb.0: ; %entry
1859 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1860 ; GFX12-NEXT: s_wait_expcnt 0x0
1861 ; GFX12-NEXT: s_wait_samplecnt 0x0
1862 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1863 ; GFX12-NEXT: s_wait_kmcnt 0x0
1864 ; GFX12-NEXT: v_floor_f64_e32 v[4:5], v[0:1]
1865 ; GFX12-NEXT: v_fract_f64_e32 v[0:1], v[0:1]
1866 ; GFX12-NEXT: global_store_b64 v[2:3], v[4:5], off
1867 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1869 %floor = tail call double @llvm.floor.f64(double %x)
1870 %sub = fsub double %x, %floor
1871 %min = tail call double @llvm.minnum.f64(double %sub, double 0x3FEFFFFFFFFFFFFF)
1872 %uno = fcmp uno double %x, 0.000000e+00
1873 %cond = select i1 %uno, double %x, double %min
1874 store double %floor, ptr addrspace(1) %ip, align 4
1878 define float @select_nan_fract_f32_flags_select(float %x) {
1879 ; GFX6-IR-LABEL: define float @select_nan_fract_f32_flags_select
1880 ; GFX6-IR-SAME: (float [[X:%.*]]) #[[ATTR0]] {
1881 ; GFX6-IR-NEXT: entry:
1882 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
1883 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
1884 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
1885 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno float [[X]], 0.000000e+00
1886 ; GFX6-IR-NEXT: [[COND:%.*]] = select nsz i1 [[UNO]], float [[X]], float [[MIN]]
1887 ; GFX6-IR-NEXT: ret float [[COND]]
1889 ; IR-FRACT-LABEL: define float @select_nan_fract_f32_flags_select
1890 ; IR-FRACT-SAME: (float [[X:%.*]]) #[[ATTR0]] {
1891 ; IR-FRACT-NEXT: entry:
1892 ; IR-FRACT-NEXT: [[COND:%.*]] = call nsz float @llvm.amdgcn.fract.f32(float [[X]])
1893 ; IR-FRACT-NEXT: ret float [[COND]]
1895 ; GFX6-LABEL: select_nan_fract_f32_flags_select:
1896 ; GFX6: ; %bb.0: ; %entry
1897 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1898 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
1899 ; GFX6-NEXT: v_sub_f32_e32 v1, v0, v1
1900 ; GFX6-NEXT: v_min_f32_e32 v1, 0x3f7fffff, v1
1901 ; GFX6-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
1902 ; GFX6-NEXT: v_cndmask_b32_e32 v0, v1, v0, vcc
1903 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1905 ; GFX7-LABEL: select_nan_fract_f32_flags_select:
1906 ; GFX7: ; %bb.0: ; %entry
1907 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1908 ; GFX7-NEXT: v_fract_f32_e32 v0, v0
1909 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1911 ; GFX8-LABEL: select_nan_fract_f32_flags_select:
1912 ; GFX8: ; %bb.0: ; %entry
1913 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1914 ; GFX8-NEXT: v_fract_f32_e32 v0, v0
1915 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1917 ; GFX11-LABEL: select_nan_fract_f32_flags_select:
1918 ; GFX11: ; %bb.0: ; %entry
1919 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1920 ; GFX11-NEXT: v_fract_f32_e32 v0, v0
1921 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1923 ; GFX12-LABEL: select_nan_fract_f32_flags_select:
1924 ; GFX12: ; %bb.0: ; %entry
1925 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1926 ; GFX12-NEXT: s_wait_expcnt 0x0
1927 ; GFX12-NEXT: s_wait_samplecnt 0x0
1928 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1929 ; GFX12-NEXT: s_wait_kmcnt 0x0
1930 ; GFX12-NEXT: v_fract_f32_e32 v0, v0
1931 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1933 %floor = tail call float @llvm.floor.f32(float %x)
1934 %sub = fsub float %x, %floor
1935 %min = tail call float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
1936 %uno = fcmp uno float %x, 0.000000e+00
1937 %cond = select nsz i1 %uno, float %x, float %min
1941 define float @select_nan_fract_f32_flags_minnum(float %x) {
1942 ; GFX6-IR-LABEL: define float @select_nan_fract_f32_flags_minnum
1943 ; GFX6-IR-SAME: (float [[X:%.*]]) #[[ATTR0]] {
1944 ; GFX6-IR-NEXT: entry:
1945 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
1946 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
1947 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call nsz float @llvm.minnum.f32(float [[SUB]], float 0x3FEFFFFFE0000000)
1948 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno float [[X]], 0.000000e+00
1949 ; GFX6-IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], float [[X]], float [[MIN]]
1950 ; GFX6-IR-NEXT: ret float [[COND]]
1952 ; IR-FRACT-LABEL: define float @select_nan_fract_f32_flags_minnum
1953 ; IR-FRACT-SAME: (float [[X:%.*]]) #[[ATTR0]] {
1954 ; IR-FRACT-NEXT: entry:
1955 ; IR-FRACT-NEXT: [[COND:%.*]] = call float @llvm.amdgcn.fract.f32(float [[X]])
1956 ; IR-FRACT-NEXT: ret float [[COND]]
1958 ; GFX6-LABEL: select_nan_fract_f32_flags_minnum:
1959 ; GFX6: ; %bb.0: ; %entry
1960 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1961 ; GFX6-NEXT: v_floor_f32_e32 v1, v0
1962 ; GFX6-NEXT: v_sub_f32_e32 v1, v0, v1
1963 ; GFX6-NEXT: v_min_f32_e32 v1, 0x3f7fffff, v1
1964 ; GFX6-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
1965 ; GFX6-NEXT: v_cndmask_b32_e32 v0, v1, v0, vcc
1966 ; GFX6-NEXT: s_setpc_b64 s[30:31]
1968 ; GFX7-LABEL: select_nan_fract_f32_flags_minnum:
1969 ; GFX7: ; %bb.0: ; %entry
1970 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1971 ; GFX7-NEXT: v_fract_f32_e32 v0, v0
1972 ; GFX7-NEXT: s_setpc_b64 s[30:31]
1974 ; GFX8-LABEL: select_nan_fract_f32_flags_minnum:
1975 ; GFX8: ; %bb.0: ; %entry
1976 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1977 ; GFX8-NEXT: v_fract_f32_e32 v0, v0
1978 ; GFX8-NEXT: s_setpc_b64 s[30:31]
1980 ; GFX11-LABEL: select_nan_fract_f32_flags_minnum:
1981 ; GFX11: ; %bb.0: ; %entry
1982 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1983 ; GFX11-NEXT: v_fract_f32_e32 v0, v0
1984 ; GFX11-NEXT: s_setpc_b64 s[30:31]
1986 ; GFX12-LABEL: select_nan_fract_f32_flags_minnum:
1987 ; GFX12: ; %bb.0: ; %entry
1988 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
1989 ; GFX12-NEXT: s_wait_expcnt 0x0
1990 ; GFX12-NEXT: s_wait_samplecnt 0x0
1991 ; GFX12-NEXT: s_wait_bvhcnt 0x0
1992 ; GFX12-NEXT: s_wait_kmcnt 0x0
1993 ; GFX12-NEXT: v_fract_f32_e32 v0, v0
1994 ; GFX12-NEXT: s_setpc_b64 s[30:31]
1996 %floor = tail call float @llvm.floor.f32(float %x)
1997 %sub = fsub float %x, %floor
1998 %min = tail call nsz float @llvm.minnum.f32(float %sub, float 0x3FEFFFFFE0000000)
1999 %uno = fcmp uno float %x, 0.000000e+00
2000 %cond = select i1 %uno, float %x, float %min
2004 define <2 x float> @safe_math_fract_v2f32(<2 x float> %x, ptr addrspace(1) writeonly captures(none) %ip) {
2005 ; GFX6-IR-LABEL: define <2 x float> @safe_math_fract_v2f32
2006 ; GFX6-IR-SAME: (<2 x float> [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
2007 ; GFX6-IR-NEXT: entry:
2008 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call <2 x float> @llvm.floor.v2f32(<2 x float> [[X]])
2009 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub <2 x float> [[X]], [[FLOOR]]
2010 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call <2 x float> @llvm.minnum.v2f32(<2 x float> [[SUB]], <2 x float> splat (float 0x3FEFFFFFE0000000))
2011 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno <2 x float> [[X]], zeroinitializer
2012 ; GFX6-IR-NEXT: [[COND:%.*]] = select <2 x i1> [[UNO]], <2 x float> [[X]], <2 x float> [[MIN]]
2013 ; GFX6-IR-NEXT: [[FABS:%.*]] = tail call <2 x float> @llvm.fabs.v2f32(<2 x float> [[X]])
2014 ; GFX6-IR-NEXT: [[CMPINF:%.*]] = fcmp oeq <2 x float> [[FABS]], splat (float 0x7FF0000000000000)
2015 ; GFX6-IR-NEXT: [[COND6:%.*]] = select <2 x i1> [[CMPINF]], <2 x float> zeroinitializer, <2 x float> [[COND]]
2016 ; GFX6-IR-NEXT: store <2 x float> [[FLOOR]], ptr addrspace(1) [[IP]], align 4
2017 ; GFX6-IR-NEXT: ret <2 x float> [[COND6]]
2019 ; IR-FRACT-LABEL: define <2 x float> @safe_math_fract_v2f32
2020 ; IR-FRACT-SAME: (<2 x float> [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
2021 ; IR-FRACT-NEXT: entry:
2022 ; IR-FRACT-NEXT: [[FLOOR:%.*]] = tail call <2 x float> @llvm.floor.v2f32(<2 x float> [[X]])
2023 ; IR-FRACT-NEXT: [[TMP0:%.*]] = extractelement <2 x float> [[X]], i64 0
2024 ; IR-FRACT-NEXT: [[TMP1:%.*]] = extractelement <2 x float> [[X]], i64 1
2025 ; IR-FRACT-NEXT: [[TMP2:%.*]] = call float @llvm.amdgcn.fract.f32(float [[TMP0]])
2026 ; IR-FRACT-NEXT: [[TMP3:%.*]] = call float @llvm.amdgcn.fract.f32(float [[TMP1]])
2027 ; IR-FRACT-NEXT: [[TMP4:%.*]] = insertelement <2 x float> poison, float [[TMP2]], i64 0
2028 ; IR-FRACT-NEXT: [[COND:%.*]] = insertelement <2 x float> [[TMP4]], float [[TMP3]], i64 1
2029 ; IR-FRACT-NEXT: [[FABS:%.*]] = tail call <2 x float> @llvm.fabs.v2f32(<2 x float> [[X]])
2030 ; IR-FRACT-NEXT: [[CMPINF:%.*]] = fcmp oeq <2 x float> [[FABS]], splat (float 0x7FF0000000000000)
2031 ; IR-FRACT-NEXT: [[COND6:%.*]] = select <2 x i1> [[CMPINF]], <2 x float> zeroinitializer, <2 x float> [[COND]]
2032 ; IR-FRACT-NEXT: store <2 x float> [[FLOOR]], ptr addrspace(1) [[IP]], align 4
2033 ; IR-FRACT-NEXT: ret <2 x float> [[COND6]]
2035 ; GFX6-LABEL: safe_math_fract_v2f32:
2036 ; GFX6: ; %bb.0: ; %entry
2037 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2038 ; GFX6-NEXT: v_floor_f32_e32 v5, v1
2039 ; GFX6-NEXT: v_floor_f32_e32 v4, v0
2040 ; GFX6-NEXT: v_sub_f32_e32 v6, v1, v5
2041 ; GFX6-NEXT: v_sub_f32_e32 v7, v0, v4
2042 ; GFX6-NEXT: v_min_f32_e32 v6, 0x3f7fffff, v6
2043 ; GFX6-NEXT: v_cmp_u_f32_e32 vcc, v1, v1
2044 ; GFX6-NEXT: v_min_f32_e32 v7, 0x3f7fffff, v7
2045 ; GFX6-NEXT: v_cndmask_b32_e32 v6, v6, v1, vcc
2046 ; GFX6-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
2047 ; GFX6-NEXT: v_mov_b32_e32 v8, 0x204
2048 ; GFX6-NEXT: v_cndmask_b32_e32 v7, v7, v0, vcc
2049 ; GFX6-NEXT: v_cmp_class_f32_e32 vcc, v0, v8
2050 ; GFX6-NEXT: s_mov_b32 s6, 0
2051 ; GFX6-NEXT: v_cndmask_b32_e64 v0, v7, 0, vcc
2052 ; GFX6-NEXT: v_cmp_class_f32_e32 vcc, v1, v8
2053 ; GFX6-NEXT: s_mov_b32 s7, 0xf000
2054 ; GFX6-NEXT: s_mov_b32 s4, s6
2055 ; GFX6-NEXT: s_mov_b32 s5, s6
2056 ; GFX6-NEXT: v_cndmask_b32_e64 v1, v6, 0, vcc
2057 ; GFX6-NEXT: buffer_store_dwordx2 v[4:5], v[2:3], s[4:7], 0 addr64
2058 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0)
2059 ; GFX6-NEXT: s_setpc_b64 s[30:31]
2061 ; GFX7-LABEL: safe_math_fract_v2f32:
2062 ; GFX7: ; %bb.0: ; %entry
2063 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2064 ; GFX7-NEXT: v_mov_b32_e32 v8, 0x204
2065 ; GFX7-NEXT: v_fract_f32_e32 v6, v0
2066 ; GFX7-NEXT: v_cmp_class_f32_e32 vcc, v0, v8
2067 ; GFX7-NEXT: s_mov_b32 s6, 0
2068 ; GFX7-NEXT: v_floor_f32_e32 v4, v0
2069 ; GFX7-NEXT: v_fract_f32_e32 v7, v1
2070 ; GFX7-NEXT: v_cndmask_b32_e64 v0, v6, 0, vcc
2071 ; GFX7-NEXT: v_cmp_class_f32_e32 vcc, v1, v8
2072 ; GFX7-NEXT: s_mov_b32 s7, 0xf000
2073 ; GFX7-NEXT: s_mov_b32 s4, s6
2074 ; GFX7-NEXT: s_mov_b32 s5, s6
2075 ; GFX7-NEXT: v_floor_f32_e32 v5, v1
2076 ; GFX7-NEXT: v_cndmask_b32_e64 v1, v7, 0, vcc
2077 ; GFX7-NEXT: buffer_store_dwordx2 v[4:5], v[2:3], s[4:7], 0 addr64
2078 ; GFX7-NEXT: s_waitcnt vmcnt(0)
2079 ; GFX7-NEXT: s_setpc_b64 s[30:31]
2081 ; GFX8-LABEL: safe_math_fract_v2f32:
2082 ; GFX8: ; %bb.0: ; %entry
2083 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2084 ; GFX8-NEXT: v_mov_b32_e32 v8, 0x204
2085 ; GFX8-NEXT: v_fract_f32_e32 v6, v0
2086 ; GFX8-NEXT: v_cmp_class_f32_e32 vcc, v0, v8
2087 ; GFX8-NEXT: v_floor_f32_e32 v4, v0
2088 ; GFX8-NEXT: v_fract_f32_e32 v7, v1
2089 ; GFX8-NEXT: v_cndmask_b32_e64 v0, v6, 0, vcc
2090 ; GFX8-NEXT: v_cmp_class_f32_e32 vcc, v1, v8
2091 ; GFX8-NEXT: v_floor_f32_e32 v5, v1
2092 ; GFX8-NEXT: v_cndmask_b32_e64 v1, v7, 0, vcc
2093 ; GFX8-NEXT: global_store_dwordx2 v[2:3], v[4:5], off
2094 ; GFX8-NEXT: s_waitcnt vmcnt(0)
2095 ; GFX8-NEXT: s_setpc_b64 s[30:31]
2097 ; GFX11-LABEL: safe_math_fract_v2f32:
2098 ; GFX11: ; %bb.0: ; %entry
2099 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2100 ; GFX11-NEXT: v_fract_f32_e32 v6, v0
2101 ; GFX11-NEXT: v_cmp_class_f32_e64 s0, v0, 0x204
2102 ; GFX11-NEXT: v_fract_f32_e32 v7, v1
2103 ; GFX11-NEXT: v_floor_f32_e32 v4, v0
2104 ; GFX11-NEXT: v_floor_f32_e32 v5, v1
2105 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_4)
2106 ; GFX11-NEXT: v_cndmask_b32_e64 v0, v6, 0, s0
2107 ; GFX11-NEXT: v_cmp_class_f32_e64 s0, v1, 0x204
2108 ; GFX11-NEXT: global_store_b64 v[2:3], v[4:5], off
2109 ; GFX11-NEXT: v_cndmask_b32_e64 v1, v7, 0, s0
2110 ; GFX11-NEXT: s_setpc_b64 s[30:31]
2112 ; GFX12-LABEL: safe_math_fract_v2f32:
2113 ; GFX12: ; %bb.0: ; %entry
2114 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
2115 ; GFX12-NEXT: s_wait_expcnt 0x0
2116 ; GFX12-NEXT: s_wait_samplecnt 0x0
2117 ; GFX12-NEXT: s_wait_bvhcnt 0x0
2118 ; GFX12-NEXT: s_wait_kmcnt 0x0
2119 ; GFX12-NEXT: v_fract_f32_e32 v6, v0
2120 ; GFX12-NEXT: v_cmp_class_f32_e64 s0, v0, 0x204
2121 ; GFX12-NEXT: v_fract_f32_e32 v7, v1
2122 ; GFX12-NEXT: v_floor_f32_e32 v4, v0
2123 ; GFX12-NEXT: v_floor_f32_e32 v5, v1
2124 ; GFX12-NEXT: s_wait_alu 0xf1ff
2125 ; GFX12-NEXT: v_cndmask_b32_e64 v0, v6, 0, s0
2126 ; GFX12-NEXT: v_cmp_class_f32_e64 s0, v1, 0x204
2127 ; GFX12-NEXT: global_store_b64 v[2:3], v[4:5], off
2128 ; GFX12-NEXT: s_wait_alu 0xf1ff
2129 ; GFX12-NEXT: v_cndmask_b32_e64 v1, v7, 0, s0
2130 ; GFX12-NEXT: s_setpc_b64 s[30:31]
2132 %floor = tail call <2 x float> @llvm.floor.v2f32(<2 x float> %x)
2133 %sub = fsub <2 x float> %x, %floor
2134 %min = tail call <2 x float> @llvm.minnum.v2f32(<2 x float> %sub, <2 x float> <float 0x3FEFFFFFE0000000, float 0x3FEFFFFFE0000000>)
2135 %uno = fcmp uno <2 x float> %x, zeroinitializer
2136 %cond = select <2 x i1> %uno, <2 x float> %x, <2 x float> %min
2137 %fabs = tail call <2 x float> @llvm.fabs.v2f32(<2 x float> %x)
2138 %cmpinf = fcmp oeq <2 x float> %fabs, <float 0x7FF0000000000000, float 0x7FF0000000000000>
2139 %cond6 = select <2 x i1> %cmpinf, <2 x float> zeroinitializer, <2 x float> %cond
2140 store <2 x float> %floor, ptr addrspace(1) %ip, align 4
2141 ret <2 x float> %cond6
2144 define double @safe_math_fract_f64(double %x, ptr addrspace(1) writeonly captures(none) %ip) {
2145 ; GFX6-IR-LABEL: define double @safe_math_fract_f64
2146 ; GFX6-IR-SAME: (double [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
2147 ; GFX6-IR-NEXT: entry:
2148 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call double @llvm.floor.f64(double [[X]])
2149 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub double [[X]], [[FLOOR]]
2150 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call double @llvm.minnum.f64(double [[SUB]], double 0x3FEFFFFFFFFFFFFF)
2151 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno double [[X]], 0.000000e+00
2152 ; GFX6-IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], double [[X]], double [[MIN]]
2153 ; GFX6-IR-NEXT: [[FABS:%.*]] = tail call double @llvm.fabs.f64(double [[X]])
2154 ; GFX6-IR-NEXT: [[CMPINF:%.*]] = fcmp oeq double [[FABS]], 0x7FF0000000000000
2155 ; GFX6-IR-NEXT: [[COND6:%.*]] = select i1 [[CMPINF]], double 0.000000e+00, double [[COND]]
2156 ; GFX6-IR-NEXT: store double [[FLOOR]], ptr addrspace(1) [[IP]], align 4
2157 ; GFX6-IR-NEXT: ret double [[COND6]]
2159 ; IR-FRACT-LABEL: define double @safe_math_fract_f64
2160 ; IR-FRACT-SAME: (double [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
2161 ; IR-FRACT-NEXT: entry:
2162 ; IR-FRACT-NEXT: [[FLOOR:%.*]] = tail call double @llvm.floor.f64(double [[X]])
2163 ; IR-FRACT-NEXT: [[COND:%.*]] = call double @llvm.amdgcn.fract.f64(double [[X]])
2164 ; IR-FRACT-NEXT: [[FABS:%.*]] = tail call double @llvm.fabs.f64(double [[X]])
2165 ; IR-FRACT-NEXT: [[CMPINF:%.*]] = fcmp oeq double [[FABS]], 0x7FF0000000000000
2166 ; IR-FRACT-NEXT: [[COND6:%.*]] = select i1 [[CMPINF]], double 0.000000e+00, double [[COND]]
2167 ; IR-FRACT-NEXT: store double [[FLOOR]], ptr addrspace(1) [[IP]], align 4
2168 ; IR-FRACT-NEXT: ret double [[COND6]]
2170 ; GFX6-LABEL: safe_math_fract_f64:
2171 ; GFX6: ; %bb.0: ; %entry
2172 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2173 ; GFX6-NEXT: v_fract_f64_e32 v[4:5], v[0:1]
2174 ; GFX6-NEXT: v_mov_b32_e32 v6, -1
2175 ; GFX6-NEXT: v_mov_b32_e32 v7, 0x3fefffff
2176 ; GFX6-NEXT: v_min_f64 v[4:5], v[4:5], v[6:7]
2177 ; GFX6-NEXT: v_cmp_class_f64_e64 vcc, v[0:1], 3
2178 ; GFX6-NEXT: s_mov_b32 s8, -1
2179 ; GFX6-NEXT: v_cndmask_b32_e32 v4, v4, v0, vcc
2180 ; GFX6-NEXT: v_cndmask_b32_e32 v5, v5, v1, vcc
2181 ; GFX6-NEXT: v_add_f64 v[4:5], v[0:1], -v[4:5]
2182 ; GFX6-NEXT: s_mov_b32 s9, 0x3fefffff
2183 ; GFX6-NEXT: v_add_f64 v[6:7], v[0:1], -v[4:5]
2184 ; GFX6-NEXT: v_cmp_u_f64_e32 vcc, v[0:1], v[0:1]
2185 ; GFX6-NEXT: v_min_f64 v[6:7], v[6:7], s[8:9]
2186 ; GFX6-NEXT: s_mov_b32 s8, 0
2187 ; GFX6-NEXT: s_mov_b32 s9, 0x7ff00000
2188 ; GFX6-NEXT: v_cndmask_b32_e32 v7, v7, v1, vcc
2189 ; GFX6-NEXT: v_cndmask_b32_e32 v6, v6, v0, vcc
2190 ; GFX6-NEXT: v_cmp_neq_f64_e64 vcc, |v[0:1]|, s[8:9]
2191 ; GFX6-NEXT: s_mov_b32 s6, 0
2192 ; GFX6-NEXT: s_mov_b32 s7, 0xf000
2193 ; GFX6-NEXT: s_mov_b32 s4, s6
2194 ; GFX6-NEXT: s_mov_b32 s5, s6
2195 ; GFX6-NEXT: v_cndmask_b32_e32 v0, 0, v6, vcc
2196 ; GFX6-NEXT: v_cndmask_b32_e32 v1, 0, v7, vcc
2197 ; GFX6-NEXT: buffer_store_dwordx2 v[4:5], v[2:3], s[4:7], 0 addr64
2198 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0)
2199 ; GFX6-NEXT: s_setpc_b64 s[30:31]
2201 ; GFX7-LABEL: safe_math_fract_f64:
2202 ; GFX7: ; %bb.0: ; %entry
2203 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2204 ; GFX7-NEXT: s_mov_b32 s4, 0
2205 ; GFX7-NEXT: s_mov_b32 s5, 0x7ff00000
2206 ; GFX7-NEXT: v_fract_f64_e32 v[4:5], v[0:1]
2207 ; GFX7-NEXT: v_cmp_neq_f64_e64 vcc, |v[0:1]|, s[4:5]
2208 ; GFX7-NEXT: v_floor_f64_e32 v[6:7], v[0:1]
2209 ; GFX7-NEXT: s_mov_b32 s6, 0
2210 ; GFX7-NEXT: s_mov_b32 s7, 0xf000
2211 ; GFX7-NEXT: s_mov_b32 s4, s6
2212 ; GFX7-NEXT: s_mov_b32 s5, s6
2213 ; GFX7-NEXT: v_cndmask_b32_e32 v0, 0, v4, vcc
2214 ; GFX7-NEXT: v_cndmask_b32_e32 v1, 0, v5, vcc
2215 ; GFX7-NEXT: buffer_store_dwordx2 v[6:7], v[2:3], s[4:7], 0 addr64
2216 ; GFX7-NEXT: s_waitcnt vmcnt(0)
2217 ; GFX7-NEXT: s_setpc_b64 s[30:31]
2219 ; GFX8-LABEL: safe_math_fract_f64:
2220 ; GFX8: ; %bb.0: ; %entry
2221 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2222 ; GFX8-NEXT: s_mov_b32 s4, 0
2223 ; GFX8-NEXT: s_mov_b32 s5, 0x7ff00000
2224 ; GFX8-NEXT: v_fract_f64_e32 v[4:5], v[0:1]
2225 ; GFX8-NEXT: v_cmp_neq_f64_e64 vcc, |v[0:1]|, s[4:5]
2226 ; GFX8-NEXT: v_floor_f64_e32 v[6:7], v[0:1]
2227 ; GFX8-NEXT: v_cndmask_b32_e32 v0, 0, v4, vcc
2228 ; GFX8-NEXT: v_cndmask_b32_e32 v1, 0, v5, vcc
2229 ; GFX8-NEXT: global_store_dwordx2 v[2:3], v[6:7], off
2230 ; GFX8-NEXT: s_waitcnt vmcnt(0)
2231 ; GFX8-NEXT: s_setpc_b64 s[30:31]
2233 ; GFX11-LABEL: safe_math_fract_f64:
2234 ; GFX11: ; %bb.0: ; %entry
2235 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2236 ; GFX11-NEXT: v_fract_f64_e32 v[4:5], v[0:1]
2237 ; GFX11-NEXT: v_cmp_neq_f64_e64 vcc_lo, 0x7ff00000, |v[0:1]|
2238 ; GFX11-NEXT: v_floor_f64_e32 v[6:7], v[0:1]
2239 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_3)
2240 ; GFX11-NEXT: v_dual_cndmask_b32 v0, 0, v4 :: v_dual_cndmask_b32 v1, 0, v5
2241 ; GFX11-NEXT: global_store_b64 v[2:3], v[6:7], off
2242 ; GFX11-NEXT: s_setpc_b64 s[30:31]
2244 ; GFX12-LABEL: safe_math_fract_f64:
2245 ; GFX12: ; %bb.0: ; %entry
2246 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
2247 ; GFX12-NEXT: s_wait_expcnt 0x0
2248 ; GFX12-NEXT: s_wait_samplecnt 0x0
2249 ; GFX12-NEXT: s_wait_bvhcnt 0x0
2250 ; GFX12-NEXT: s_wait_kmcnt 0x0
2251 ; GFX12-NEXT: v_fract_f64_e32 v[4:5], v[0:1]
2252 ; GFX12-NEXT: v_cmp_neq_f64_e64 vcc_lo, 0x7ff00000, |v[0:1]|
2253 ; GFX12-NEXT: v_floor_f64_e32 v[6:7], v[0:1]
2254 ; GFX12-NEXT: s_wait_alu 0xfffd
2255 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_3)
2256 ; GFX12-NEXT: v_dual_cndmask_b32 v0, 0, v4 :: v_dual_cndmask_b32 v1, 0, v5
2257 ; GFX12-NEXT: global_store_b64 v[2:3], v[6:7], off
2258 ; GFX12-NEXT: s_setpc_b64 s[30:31]
2260 %floor = tail call double @llvm.floor.f64(double %x)
2261 %sub = fsub double %x, %floor
2262 %min = tail call double @llvm.minnum.f64(double %sub, double 0x3FEFFFFFFFFFFFFF)
2263 %uno = fcmp uno double %x, 0.000000e+00
2264 %cond = select i1 %uno, double %x, double %min
2265 %fabs = tail call double @llvm.fabs.f64(double %x)
2266 %cmpinf = fcmp oeq double %fabs, 0x7FF0000000000000
2267 %cond6 = select i1 %cmpinf, double 0.000000e+00, double %cond
2268 store double %floor, ptr addrspace(1) %ip, align 4
2272 define half @safe_math_fract_f16(half %x, ptr addrspace(1) writeonly captures(none) %ip) {
2273 ; GFX6-IR-LABEL: define half @safe_math_fract_f16
2274 ; GFX6-IR-SAME: (half [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
2275 ; GFX6-IR-NEXT: entry:
2276 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call half @llvm.floor.f16(half [[X]])
2277 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub half [[X]], [[FLOOR]]
2278 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call half @llvm.minnum.f16(half [[SUB]], half 0xH3BFF)
2279 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno half [[X]], 0xH0000
2280 ; GFX6-IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], half [[X]], half [[MIN]]
2281 ; GFX6-IR-NEXT: [[FABS:%.*]] = tail call half @llvm.fabs.f16(half [[X]])
2282 ; GFX6-IR-NEXT: [[CMPINF:%.*]] = fcmp oeq half [[FABS]], 0xH7C00
2283 ; GFX6-IR-NEXT: [[COND6:%.*]] = select i1 [[CMPINF]], half 0xH0000, half [[COND]]
2284 ; GFX6-IR-NEXT: store half [[FLOOR]], ptr addrspace(1) [[IP]], align 4
2285 ; GFX6-IR-NEXT: ret half [[COND6]]
2287 ; GFX7-IR-LABEL: define half @safe_math_fract_f16
2288 ; GFX7-IR-SAME: (half [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
2289 ; GFX7-IR-NEXT: entry:
2290 ; GFX7-IR-NEXT: [[FLOOR:%.*]] = tail call half @llvm.floor.f16(half [[X]])
2291 ; GFX7-IR-NEXT: [[SUB:%.*]] = fsub half [[X]], [[FLOOR]]
2292 ; GFX7-IR-NEXT: [[MIN:%.*]] = tail call half @llvm.minnum.f16(half [[SUB]], half 0xH3BFF)
2293 ; GFX7-IR-NEXT: [[UNO:%.*]] = fcmp uno half [[X]], 0xH0000
2294 ; GFX7-IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], half [[X]], half [[MIN]]
2295 ; GFX7-IR-NEXT: [[FABS:%.*]] = tail call half @llvm.fabs.f16(half [[X]])
2296 ; GFX7-IR-NEXT: [[CMPINF:%.*]] = fcmp oeq half [[FABS]], 0xH7C00
2297 ; GFX7-IR-NEXT: [[COND6:%.*]] = select i1 [[CMPINF]], half 0xH0000, half [[COND]]
2298 ; GFX7-IR-NEXT: store half [[FLOOR]], ptr addrspace(1) [[IP]], align 4
2299 ; GFX7-IR-NEXT: ret half [[COND6]]
2301 ; IR-LEGALF16-LABEL: define half @safe_math_fract_f16
2302 ; IR-LEGALF16-SAME: (half [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
2303 ; IR-LEGALF16-NEXT: entry:
2304 ; IR-LEGALF16-NEXT: [[FLOOR:%.*]] = tail call half @llvm.floor.f16(half [[X]])
2305 ; IR-LEGALF16-NEXT: [[COND:%.*]] = call half @llvm.amdgcn.fract.f16(half [[X]])
2306 ; IR-LEGALF16-NEXT: [[FABS:%.*]] = tail call half @llvm.fabs.f16(half [[X]])
2307 ; IR-LEGALF16-NEXT: [[CMPINF:%.*]] = fcmp oeq half [[FABS]], 0xH7C00
2308 ; IR-LEGALF16-NEXT: [[COND6:%.*]] = select i1 [[CMPINF]], half 0xH0000, half [[COND]]
2309 ; IR-LEGALF16-NEXT: store half [[FLOOR]], ptr addrspace(1) [[IP]], align 4
2310 ; IR-LEGALF16-NEXT: ret half [[COND6]]
2312 ; GFX6-LABEL: safe_math_fract_f16:
2313 ; GFX6: ; %bb.0: ; %entry
2314 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2315 ; GFX6-NEXT: v_cvt_f16_f32_e32 v0, v0
2316 ; GFX6-NEXT: s_movk_i32 s8, 0x7c00
2317 ; GFX6-NEXT: s_mov_b32 s6, 0
2318 ; GFX6-NEXT: s_mov_b32 s7, 0xf000
2319 ; GFX6-NEXT: v_cvt_f32_f16_e32 v3, v0
2320 ; GFX6-NEXT: v_and_b32_e32 v0, 0x7fff, v0
2321 ; GFX6-NEXT: s_mov_b32 s4, s6
2322 ; GFX6-NEXT: s_mov_b32 s5, s6
2323 ; GFX6-NEXT: v_floor_f32_e32 v4, v3
2324 ; GFX6-NEXT: v_sub_f32_e32 v5, v3, v4
2325 ; GFX6-NEXT: v_cvt_f16_f32_e32 v4, v4
2326 ; GFX6-NEXT: v_min_f32_e32 v5, 0x3f7fe000, v5
2327 ; GFX6-NEXT: v_cmp_u_f32_e32 vcc, v3, v3
2328 ; GFX6-NEXT: v_cndmask_b32_e32 v3, v5, v3, vcc
2329 ; GFX6-NEXT: v_cmp_ne_u32_e32 vcc, s8, v0
2330 ; GFX6-NEXT: v_cndmask_b32_e32 v0, 0, v3, vcc
2331 ; GFX6-NEXT: buffer_store_short v4, v[1:2], s[4:7], 0 addr64
2332 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0)
2333 ; GFX6-NEXT: s_setpc_b64 s[30:31]
2335 ; GFX7-LABEL: safe_math_fract_f16:
2336 ; GFX7: ; %bb.0: ; %entry
2337 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2338 ; GFX7-NEXT: v_cvt_f16_f32_e32 v0, v0
2339 ; GFX7-NEXT: s_movk_i32 s8, 0x7c00
2340 ; GFX7-NEXT: s_mov_b32 s6, 0
2341 ; GFX7-NEXT: s_mov_b32 s7, 0xf000
2342 ; GFX7-NEXT: v_cvt_f32_f16_e32 v3, v0
2343 ; GFX7-NEXT: v_and_b32_e32 v0, 0x7fff, v0
2344 ; GFX7-NEXT: s_mov_b32 s4, s6
2345 ; GFX7-NEXT: s_mov_b32 s5, s6
2346 ; GFX7-NEXT: v_floor_f32_e32 v4, v3
2347 ; GFX7-NEXT: v_sub_f32_e32 v5, v3, v4
2348 ; GFX7-NEXT: v_cvt_f16_f32_e32 v4, v4
2349 ; GFX7-NEXT: v_min_f32_e32 v5, 0x3f7fe000, v5
2350 ; GFX7-NEXT: v_cmp_u_f32_e32 vcc, v3, v3
2351 ; GFX7-NEXT: v_cndmask_b32_e32 v3, v5, v3, vcc
2352 ; GFX7-NEXT: v_cmp_ne_u32_e32 vcc, s8, v0
2353 ; GFX7-NEXT: v_cndmask_b32_e32 v0, 0, v3, vcc
2354 ; GFX7-NEXT: buffer_store_short v4, v[1:2], s[4:7], 0 addr64
2355 ; GFX7-NEXT: s_waitcnt vmcnt(0)
2356 ; GFX7-NEXT: s_setpc_b64 s[30:31]
2358 ; GFX8-LABEL: safe_math_fract_f16:
2359 ; GFX8: ; %bb.0: ; %entry
2360 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2361 ; GFX8-NEXT: s_movk_i32 s4, 0x7c00
2362 ; GFX8-NEXT: v_fract_f16_e32 v4, v0
2363 ; GFX8-NEXT: v_cmp_neq_f16_e64 vcc, |v0|, s4
2364 ; GFX8-NEXT: v_floor_f16_e32 v3, v0
2365 ; GFX8-NEXT: v_cndmask_b32_e32 v0, 0, v4, vcc
2366 ; GFX8-NEXT: global_store_short v[1:2], v3, off
2367 ; GFX8-NEXT: s_waitcnt vmcnt(0)
2368 ; GFX8-NEXT: s_setpc_b64 s[30:31]
2370 ; GFX11-LABEL: safe_math_fract_f16:
2371 ; GFX11: ; %bb.0: ; %entry
2372 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2373 ; GFX11-NEXT: v_fract_f16_e32 v3, v0
2374 ; GFX11-NEXT: v_cmp_neq_f16_e64 vcc_lo, 0x7c00, |v0|
2375 ; GFX11-NEXT: v_floor_f16_e32 v4, v0
2376 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_3)
2377 ; GFX11-NEXT: v_cndmask_b32_e32 v0, 0, v3, vcc_lo
2378 ; GFX11-NEXT: global_store_b16 v[1:2], v4, off
2379 ; GFX11-NEXT: s_setpc_b64 s[30:31]
2381 ; GFX12-LABEL: safe_math_fract_f16:
2382 ; GFX12: ; %bb.0: ; %entry
2383 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
2384 ; GFX12-NEXT: s_wait_expcnt 0x0
2385 ; GFX12-NEXT: s_wait_samplecnt 0x0
2386 ; GFX12-NEXT: s_wait_bvhcnt 0x0
2387 ; GFX12-NEXT: s_wait_kmcnt 0x0
2388 ; GFX12-NEXT: v_fract_f16_e32 v3, v0
2389 ; GFX12-NEXT: v_cmp_neq_f16_e64 vcc_lo, 0x7c00, |v0|
2390 ; GFX12-NEXT: v_floor_f16_e32 v4, v0
2391 ; GFX12-NEXT: s_wait_alu 0xfffd
2392 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_3)
2393 ; GFX12-NEXT: v_cndmask_b32_e32 v0, 0, v3, vcc_lo
2394 ; GFX12-NEXT: global_store_b16 v[1:2], v4, off
2395 ; GFX12-NEXT: s_setpc_b64 s[30:31]
2397 %floor = tail call half @llvm.floor.f16(half %x)
2398 %sub = fsub half %x, %floor
2399 %min = tail call half @llvm.minnum.f16(half %sub, half 0xH3BFF)
2400 %uno = fcmp uno half %x, 0.000000e+00
2401 %cond = select i1 %uno, half %x, half %min
2402 %fabs = tail call half @llvm.fabs.f16(half %x)
2403 %cmpinf = fcmp oeq half %fabs, 0xH7C00
2404 %cond6 = select i1 %cmpinf, half 0.000000e+00, half %cond
2405 store half %floor, ptr addrspace(1) %ip, align 4
2409 define <2 x half> @safe_math_fract_v2f16(<2 x half> %x, ptr addrspace(1) writeonly captures(none) %ip) {
2410 ; GFX6-IR-LABEL: define <2 x half> @safe_math_fract_v2f16
2411 ; GFX6-IR-SAME: (<2 x half> [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
2412 ; GFX6-IR-NEXT: entry:
2413 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call <2 x half> @llvm.floor.v2f16(<2 x half> [[X]])
2414 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub <2 x half> [[X]], [[FLOOR]]
2415 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call <2 x half> @llvm.minnum.v2f16(<2 x half> [[SUB]], <2 x half> splat (half 0xH3BFF))
2416 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno <2 x half> [[X]], zeroinitializer
2417 ; GFX6-IR-NEXT: [[COND:%.*]] = select <2 x i1> [[UNO]], <2 x half> [[X]], <2 x half> [[MIN]]
2418 ; GFX6-IR-NEXT: [[FABS:%.*]] = tail call <2 x half> @llvm.fabs.v2f16(<2 x half> [[X]])
2419 ; GFX6-IR-NEXT: [[CMPINF:%.*]] = fcmp oeq <2 x half> [[FABS]], splat (half 0xH7C00)
2420 ; GFX6-IR-NEXT: [[COND6:%.*]] = select <2 x i1> [[CMPINF]], <2 x half> zeroinitializer, <2 x half> [[COND]]
2421 ; GFX6-IR-NEXT: store <2 x half> [[FLOOR]], ptr addrspace(1) [[IP]], align 4
2422 ; GFX6-IR-NEXT: ret <2 x half> [[COND6]]
2424 ; GFX7-IR-LABEL: define <2 x half> @safe_math_fract_v2f16
2425 ; GFX7-IR-SAME: (<2 x half> [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
2426 ; GFX7-IR-NEXT: entry:
2427 ; GFX7-IR-NEXT: [[FLOOR:%.*]] = tail call <2 x half> @llvm.floor.v2f16(<2 x half> [[X]])
2428 ; GFX7-IR-NEXT: [[SUB:%.*]] = fsub <2 x half> [[X]], [[FLOOR]]
2429 ; GFX7-IR-NEXT: [[MIN:%.*]] = tail call <2 x half> @llvm.minnum.v2f16(<2 x half> [[SUB]], <2 x half> splat (half 0xH3BFF))
2430 ; GFX7-IR-NEXT: [[UNO:%.*]] = fcmp uno <2 x half> [[X]], zeroinitializer
2431 ; GFX7-IR-NEXT: [[COND:%.*]] = select <2 x i1> [[UNO]], <2 x half> [[X]], <2 x half> [[MIN]]
2432 ; GFX7-IR-NEXT: [[FABS:%.*]] = tail call <2 x half> @llvm.fabs.v2f16(<2 x half> [[X]])
2433 ; GFX7-IR-NEXT: [[CMPINF:%.*]] = fcmp oeq <2 x half> [[FABS]], splat (half 0xH7C00)
2434 ; GFX7-IR-NEXT: [[COND6:%.*]] = select <2 x i1> [[CMPINF]], <2 x half> zeroinitializer, <2 x half> [[COND]]
2435 ; GFX7-IR-NEXT: store <2 x half> [[FLOOR]], ptr addrspace(1) [[IP]], align 4
2436 ; GFX7-IR-NEXT: ret <2 x half> [[COND6]]
2438 ; IR-LEGALF16-LABEL: define <2 x half> @safe_math_fract_v2f16
2439 ; IR-LEGALF16-SAME: (<2 x half> [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
2440 ; IR-LEGALF16-NEXT: entry:
2441 ; IR-LEGALF16-NEXT: [[FLOOR:%.*]] = tail call <2 x half> @llvm.floor.v2f16(<2 x half> [[X]])
2442 ; IR-LEGALF16-NEXT: [[TMP0:%.*]] = extractelement <2 x half> [[X]], i64 0
2443 ; IR-LEGALF16-NEXT: [[TMP1:%.*]] = extractelement <2 x half> [[X]], i64 1
2444 ; IR-LEGALF16-NEXT: [[TMP2:%.*]] = call half @llvm.amdgcn.fract.f16(half [[TMP0]])
2445 ; IR-LEGALF16-NEXT: [[TMP3:%.*]] = call half @llvm.amdgcn.fract.f16(half [[TMP1]])
2446 ; IR-LEGALF16-NEXT: [[TMP4:%.*]] = insertelement <2 x half> poison, half [[TMP2]], i64 0
2447 ; IR-LEGALF16-NEXT: [[COND:%.*]] = insertelement <2 x half> [[TMP4]], half [[TMP3]], i64 1
2448 ; IR-LEGALF16-NEXT: [[FABS:%.*]] = tail call <2 x half> @llvm.fabs.v2f16(<2 x half> [[X]])
2449 ; IR-LEGALF16-NEXT: [[CMPINF:%.*]] = fcmp oeq <2 x half> [[FABS]], splat (half 0xH7C00)
2450 ; IR-LEGALF16-NEXT: [[COND6:%.*]] = select <2 x i1> [[CMPINF]], <2 x half> zeroinitializer, <2 x half> [[COND]]
2451 ; IR-LEGALF16-NEXT: store <2 x half> [[FLOOR]], ptr addrspace(1) [[IP]], align 4
2452 ; IR-LEGALF16-NEXT: ret <2 x half> [[COND6]]
2454 ; GFX6-LABEL: safe_math_fract_v2f16:
2455 ; GFX6: ; %bb.0: ; %entry
2456 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2457 ; GFX6-NEXT: v_cvt_f16_f32_e32 v1, v1
2458 ; GFX6-NEXT: v_cvt_f16_f32_e32 v0, v0
2459 ; GFX6-NEXT: s_movk_i32 s8, 0x7c00
2460 ; GFX6-NEXT: s_mov_b32 s6, 0
2461 ; GFX6-NEXT: v_cvt_f32_f16_e32 v4, v1
2462 ; GFX6-NEXT: v_cvt_f32_f16_e32 v5, v0
2463 ; GFX6-NEXT: v_and_b32_e32 v0, 0x7fff, v0
2464 ; GFX6-NEXT: v_and_b32_e32 v1, 0x7fff, v1
2465 ; GFX6-NEXT: v_floor_f32_e32 v6, v4
2466 ; GFX6-NEXT: v_cvt_f16_f32_e32 v7, v6
2467 ; GFX6-NEXT: v_floor_f32_e32 v8, v5
2468 ; GFX6-NEXT: v_sub_f32_e32 v6, v4, v6
2469 ; GFX6-NEXT: v_cvt_f16_f32_e32 v9, v8
2470 ; GFX6-NEXT: v_sub_f32_e32 v8, v5, v8
2471 ; GFX6-NEXT: v_min_f32_e32 v6, 0x3f7fe000, v6
2472 ; GFX6-NEXT: v_cmp_u_f32_e32 vcc, v4, v4
2473 ; GFX6-NEXT: v_min_f32_e32 v8, 0x3f7fe000, v8
2474 ; GFX6-NEXT: v_cndmask_b32_e32 v4, v6, v4, vcc
2475 ; GFX6-NEXT: v_cmp_u_f32_e32 vcc, v5, v5
2476 ; GFX6-NEXT: v_cndmask_b32_e32 v5, v8, v5, vcc
2477 ; GFX6-NEXT: v_cmp_ne_u32_e32 vcc, s8, v0
2478 ; GFX6-NEXT: v_lshlrev_b32_e32 v7, 16, v7
2479 ; GFX6-NEXT: v_cndmask_b32_e32 v0, 0, v5, vcc
2480 ; GFX6-NEXT: v_cmp_ne_u32_e32 vcc, s8, v1
2481 ; GFX6-NEXT: s_mov_b32 s7, 0xf000
2482 ; GFX6-NEXT: s_mov_b32 s4, s6
2483 ; GFX6-NEXT: s_mov_b32 s5, s6
2484 ; GFX6-NEXT: v_or_b32_e32 v7, v9, v7
2485 ; GFX6-NEXT: v_cndmask_b32_e32 v1, 0, v4, vcc
2486 ; GFX6-NEXT: buffer_store_dword v7, v[2:3], s[4:7], 0 addr64
2487 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0)
2488 ; GFX6-NEXT: s_setpc_b64 s[30:31]
2490 ; GFX7-LABEL: safe_math_fract_v2f16:
2491 ; GFX7: ; %bb.0: ; %entry
2492 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2493 ; GFX7-NEXT: v_cvt_f16_f32_e32 v1, v1
2494 ; GFX7-NEXT: v_cvt_f16_f32_e32 v0, v0
2495 ; GFX7-NEXT: s_movk_i32 s8, 0x7c00
2496 ; GFX7-NEXT: s_mov_b32 s6, 0
2497 ; GFX7-NEXT: v_cvt_f32_f16_e32 v4, v1
2498 ; GFX7-NEXT: v_cvt_f32_f16_e32 v5, v0
2499 ; GFX7-NEXT: v_and_b32_e32 v0, 0x7fff, v0
2500 ; GFX7-NEXT: v_and_b32_e32 v1, 0x7fff, v1
2501 ; GFX7-NEXT: v_floor_f32_e32 v6, v4
2502 ; GFX7-NEXT: v_cvt_f16_f32_e32 v7, v6
2503 ; GFX7-NEXT: v_floor_f32_e32 v8, v5
2504 ; GFX7-NEXT: v_sub_f32_e32 v6, v4, v6
2505 ; GFX7-NEXT: v_cvt_f16_f32_e32 v9, v8
2506 ; GFX7-NEXT: v_sub_f32_e32 v8, v5, v8
2507 ; GFX7-NEXT: v_min_f32_e32 v6, 0x3f7fe000, v6
2508 ; GFX7-NEXT: v_cmp_u_f32_e32 vcc, v4, v4
2509 ; GFX7-NEXT: v_min_f32_e32 v8, 0x3f7fe000, v8
2510 ; GFX7-NEXT: v_cndmask_b32_e32 v4, v6, v4, vcc
2511 ; GFX7-NEXT: v_cmp_u_f32_e32 vcc, v5, v5
2512 ; GFX7-NEXT: v_cndmask_b32_e32 v5, v8, v5, vcc
2513 ; GFX7-NEXT: v_cmp_ne_u32_e32 vcc, s8, v0
2514 ; GFX7-NEXT: v_lshlrev_b32_e32 v7, 16, v7
2515 ; GFX7-NEXT: v_cndmask_b32_e32 v0, 0, v5, vcc
2516 ; GFX7-NEXT: v_cmp_ne_u32_e32 vcc, s8, v1
2517 ; GFX7-NEXT: s_mov_b32 s7, 0xf000
2518 ; GFX7-NEXT: s_mov_b32 s4, s6
2519 ; GFX7-NEXT: s_mov_b32 s5, s6
2520 ; GFX7-NEXT: v_or_b32_e32 v7, v9, v7
2521 ; GFX7-NEXT: v_cndmask_b32_e32 v1, 0, v4, vcc
2522 ; GFX7-NEXT: buffer_store_dword v7, v[2:3], s[4:7], 0 addr64
2523 ; GFX7-NEXT: s_waitcnt vmcnt(0)
2524 ; GFX7-NEXT: s_setpc_b64 s[30:31]
2526 ; GFX8-LABEL: safe_math_fract_v2f16:
2527 ; GFX8: ; %bb.0: ; %entry
2528 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2529 ; GFX8-NEXT: s_movk_i32 s6, 0x204
2530 ; GFX8-NEXT: v_floor_f16_sdwa v3, v0 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1
2531 ; GFX8-NEXT: v_floor_f16_e32 v4, v0
2532 ; GFX8-NEXT: v_fract_f16_sdwa v5, v0 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1
2533 ; GFX8-NEXT: v_cmp_class_f16_sdwa s[4:5], v0, s6 src0_sel:WORD_1 src1_sel:DWORD
2534 ; GFX8-NEXT: v_pack_b32_f16 v3, v4, v3
2535 ; GFX8-NEXT: v_fract_f16_e32 v4, v0
2536 ; GFX8-NEXT: v_cndmask_b32_e64 v5, v5, 0, s[4:5]
2537 ; GFX8-NEXT: v_cmp_class_f16_e64 s[4:5], v0, s6
2538 ; GFX8-NEXT: v_cndmask_b32_e64 v0, v4, 0, s[4:5]
2539 ; GFX8-NEXT: v_pack_b32_f16 v0, v0, v5
2540 ; GFX8-NEXT: global_store_dword v[1:2], v3, off
2541 ; GFX8-NEXT: s_waitcnt vmcnt(0)
2542 ; GFX8-NEXT: s_setpc_b64 s[30:31]
2544 ; GFX11-LABEL: safe_math_fract_v2f16:
2545 ; GFX11: ; %bb.0: ; %entry
2546 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2547 ; GFX11-NEXT: v_lshrrev_b32_e32 v3, 16, v0
2548 ; GFX11-NEXT: v_fract_f16_e32 v6, v0
2549 ; GFX11-NEXT: v_floor_f16_e32 v5, v0
2550 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_2) | instid1(VALU_DEP_2)
2551 ; GFX11-NEXT: v_fract_f16_e32 v4, v3
2552 ; GFX11-NEXT: v_cmp_class_f16_e64 s0, v3, 0x204
2553 ; GFX11-NEXT: v_floor_f16_e32 v7, v3
2554 ; GFX11-NEXT: v_cndmask_b32_e64 v3, v4, 0, s0
2555 ; GFX11-NEXT: v_cmp_class_f16_e64 s0, v0, 0x204
2556 ; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
2557 ; GFX11-NEXT: v_pack_b32_f16 v4, v5, v7
2558 ; GFX11-NEXT: v_cndmask_b32_e64 v0, v6, 0, s0
2559 ; GFX11-NEXT: global_store_b32 v[1:2], v4, off
2560 ; GFX11-NEXT: v_pack_b32_f16 v0, v0, v3
2561 ; GFX11-NEXT: s_setpc_b64 s[30:31]
2563 ; GFX12-LABEL: safe_math_fract_v2f16:
2564 ; GFX12: ; %bb.0: ; %entry
2565 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
2566 ; GFX12-NEXT: s_wait_expcnt 0x0
2567 ; GFX12-NEXT: s_wait_samplecnt 0x0
2568 ; GFX12-NEXT: s_wait_bvhcnt 0x0
2569 ; GFX12-NEXT: s_wait_kmcnt 0x0
2570 ; GFX12-NEXT: v_lshrrev_b32_e32 v3, 16, v0
2571 ; GFX12-NEXT: v_fract_f16_e32 v6, v0
2572 ; GFX12-NEXT: v_floor_f16_e32 v5, v0
2573 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_3) | instid1(VALU_DEP_2)
2574 ; GFX12-NEXT: v_fract_f16_e32 v4, v3
2575 ; GFX12-NEXT: v_cmp_class_f16_e64 s0, v3, 0x204
2576 ; GFX12-NEXT: v_floor_f16_e32 v7, v3
2577 ; GFX12-NEXT: s_wait_alu 0xf1ff
2578 ; GFX12-NEXT: v_cndmask_b32_e64 v3, v4, 0, s0
2579 ; GFX12-NEXT: v_cmp_class_f16_e64 s0, v0, 0x204
2580 ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_2)
2581 ; GFX12-NEXT: v_pack_b32_f16 v4, v5, v7
2582 ; GFX12-NEXT: s_wait_alu 0xf1ff
2583 ; GFX12-NEXT: v_cndmask_b32_e64 v0, v6, 0, s0
2584 ; GFX12-NEXT: global_store_b32 v[1:2], v4, off
2585 ; GFX12-NEXT: v_pack_b32_f16 v0, v0, v3
2586 ; GFX12-NEXT: s_setpc_b64 s[30:31]
2588 %floor = tail call <2 x half> @llvm.floor.v2f16(<2 x half> %x)
2589 %sub = fsub <2 x half> %x, %floor
2590 %min = tail call <2 x half> @llvm.minnum.v2f16(<2 x half> %sub, <2 x half> <half 0xH3BFF, half 0xH3BFF>)
2591 %uno = fcmp uno <2 x half> %x, zeroinitializer
2592 %cond = select <2 x i1> %uno, <2 x half> %x, <2 x half> %min
2593 %fabs = tail call <2 x half> @llvm.fabs.v2f16(<2 x half> %x)
2594 %cmpinf = fcmp oeq <2 x half> %fabs, <half 0xH7C00, half 0xH7C00>
2595 %cond6 = select <2 x i1> %cmpinf, <2 x half> zeroinitializer, <2 x half> %cond
2596 store <2 x half> %floor, ptr addrspace(1) %ip, align 4
2597 ret <2 x half> %cond6
2600 define <2 x double> @safe_math_fract_v2f64(<2 x double> %x, ptr addrspace(1) writeonly captures(none) %ip) {
2601 ; GFX6-IR-LABEL: define <2 x double> @safe_math_fract_v2f64
2602 ; GFX6-IR-SAME: (<2 x double> [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
2603 ; GFX6-IR-NEXT: entry:
2604 ; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call <2 x double> @llvm.floor.v2f64(<2 x double> [[X]])
2605 ; GFX6-IR-NEXT: [[SUB:%.*]] = fsub <2 x double> [[X]], [[FLOOR]]
2606 ; GFX6-IR-NEXT: [[MIN:%.*]] = tail call <2 x double> @llvm.minnum.v2f64(<2 x double> [[SUB]], <2 x double> splat (double 0x3FEFFFFFFFFFFFFF))
2607 ; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno <2 x double> [[X]], zeroinitializer
2608 ; GFX6-IR-NEXT: [[COND:%.*]] = select <2 x i1> [[UNO]], <2 x double> [[X]], <2 x double> [[MIN]]
2609 ; GFX6-IR-NEXT: [[FABS:%.*]] = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> [[X]])
2610 ; GFX6-IR-NEXT: [[CMPINF:%.*]] = fcmp oeq <2 x double> [[FABS]], splat (double 0x7FF0000000000000)
2611 ; GFX6-IR-NEXT: [[COND6:%.*]] = select <2 x i1> [[CMPINF]], <2 x double> zeroinitializer, <2 x double> [[COND]]
2612 ; GFX6-IR-NEXT: store <2 x double> [[FLOOR]], ptr addrspace(1) [[IP]], align 4
2613 ; GFX6-IR-NEXT: ret <2 x double> [[COND6]]
2615 ; IR-FRACT-LABEL: define <2 x double> @safe_math_fract_v2f64
2616 ; IR-FRACT-SAME: (<2 x double> [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) #[[ATTR0]] {
2617 ; IR-FRACT-NEXT: entry:
2618 ; IR-FRACT-NEXT: [[FLOOR:%.*]] = tail call <2 x double> @llvm.floor.v2f64(<2 x double> [[X]])
2619 ; IR-FRACT-NEXT: [[TMP0:%.*]] = extractelement <2 x double> [[X]], i64 0
2620 ; IR-FRACT-NEXT: [[TMP1:%.*]] = extractelement <2 x double> [[X]], i64 1
2621 ; IR-FRACT-NEXT: [[TMP2:%.*]] = call double @llvm.amdgcn.fract.f64(double [[TMP0]])
2622 ; IR-FRACT-NEXT: [[TMP3:%.*]] = call double @llvm.amdgcn.fract.f64(double [[TMP1]])
2623 ; IR-FRACT-NEXT: [[TMP4:%.*]] = insertelement <2 x double> poison, double [[TMP2]], i64 0
2624 ; IR-FRACT-NEXT: [[COND:%.*]] = insertelement <2 x double> [[TMP4]], double [[TMP3]], i64 1
2625 ; IR-FRACT-NEXT: [[FABS:%.*]] = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> [[X]])
2626 ; IR-FRACT-NEXT: [[CMPINF:%.*]] = fcmp oeq <2 x double> [[FABS]], splat (double 0x7FF0000000000000)
2627 ; IR-FRACT-NEXT: [[COND6:%.*]] = select <2 x i1> [[CMPINF]], <2 x double> zeroinitializer, <2 x double> [[COND]]
2628 ; IR-FRACT-NEXT: store <2 x double> [[FLOOR]], ptr addrspace(1) [[IP]], align 4
2629 ; IR-FRACT-NEXT: ret <2 x double> [[COND6]]
2631 ; GFX6-LABEL: safe_math_fract_v2f64:
2632 ; GFX6: ; %bb.0: ; %entry
2633 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2634 ; GFX6-NEXT: v_fract_f64_e32 v[6:7], v[2:3]
2635 ; GFX6-NEXT: v_mov_b32_e32 v10, -1
2636 ; GFX6-NEXT: v_mov_b32_e32 v11, 0x3fefffff
2637 ; GFX6-NEXT: v_min_f64 v[6:7], v[6:7], v[10:11]
2638 ; GFX6-NEXT: v_cmp_class_f64_e64 vcc, v[2:3], 3
2639 ; GFX6-NEXT: v_fract_f64_e32 v[12:13], v[0:1]
2640 ; GFX6-NEXT: v_cndmask_b32_e32 v6, v6, v2, vcc
2641 ; GFX6-NEXT: v_cndmask_b32_e32 v7, v7, v3, vcc
2642 ; GFX6-NEXT: v_add_f64 v[8:9], v[2:3], -v[6:7]
2643 ; GFX6-NEXT: v_min_f64 v[6:7], v[12:13], v[10:11]
2644 ; GFX6-NEXT: v_cmp_class_f64_e64 vcc, v[0:1], 3
2645 ; GFX6-NEXT: v_add_f64 v[10:11], v[2:3], -v[8:9]
2646 ; GFX6-NEXT: v_cndmask_b32_e32 v6, v6, v0, vcc
2647 ; GFX6-NEXT: v_cndmask_b32_e32 v7, v7, v1, vcc
2648 ; GFX6-NEXT: v_add_f64 v[6:7], v[0:1], -v[6:7]
2649 ; GFX6-NEXT: s_mov_b32 s8, -1
2650 ; GFX6-NEXT: s_mov_b32 s9, 0x3fefffff
2651 ; GFX6-NEXT: v_add_f64 v[12:13], v[0:1], -v[6:7]
2652 ; GFX6-NEXT: v_min_f64 v[10:11], v[10:11], s[8:9]
2653 ; GFX6-NEXT: v_cmp_u_f64_e32 vcc, v[2:3], v[2:3]
2654 ; GFX6-NEXT: v_min_f64 v[12:13], v[12:13], s[8:9]
2655 ; GFX6-NEXT: v_cndmask_b32_e32 v11, v11, v3, vcc
2656 ; GFX6-NEXT: v_cndmask_b32_e32 v10, v10, v2, vcc
2657 ; GFX6-NEXT: v_cmp_u_f64_e32 vcc, v[0:1], v[0:1]
2658 ; GFX6-NEXT: v_mov_b32_e32 v14, 0x204
2659 ; GFX6-NEXT: v_cndmask_b32_e32 v13, v13, v1, vcc
2660 ; GFX6-NEXT: v_cndmask_b32_e32 v12, v12, v0, vcc
2661 ; GFX6-NEXT: v_cmp_class_f64_e32 vcc, v[0:1], v14
2662 ; GFX6-NEXT: s_mov_b32 s6, 0
2663 ; GFX6-NEXT: v_cndmask_b32_e64 v0, v12, 0, vcc
2664 ; GFX6-NEXT: v_cndmask_b32_e64 v1, v13, 0, vcc
2665 ; GFX6-NEXT: v_cmp_class_f64_e32 vcc, v[2:3], v14
2666 ; GFX6-NEXT: s_mov_b32 s7, 0xf000
2667 ; GFX6-NEXT: s_mov_b32 s4, s6
2668 ; GFX6-NEXT: s_mov_b32 s5, s6
2669 ; GFX6-NEXT: v_cndmask_b32_e64 v2, v10, 0, vcc
2670 ; GFX6-NEXT: v_cndmask_b32_e64 v3, v11, 0, vcc
2671 ; GFX6-NEXT: buffer_store_dwordx4 v[6:9], v[4:5], s[4:7], 0 addr64
2672 ; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0)
2673 ; GFX6-NEXT: s_setpc_b64 s[30:31]
2675 ; GFX7-LABEL: safe_math_fract_v2f64:
2676 ; GFX7: ; %bb.0: ; %entry
2677 ; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2678 ; GFX7-NEXT: v_mov_b32_e32 v6, 0x204
2679 ; GFX7-NEXT: v_fract_f64_e32 v[10:11], v[0:1]
2680 ; GFX7-NEXT: v_cmp_class_f64_e32 vcc, v[0:1], v6
2681 ; GFX7-NEXT: v_fract_f64_e32 v[12:13], v[2:3]
2682 ; GFX7-NEXT: v_cmp_class_f64_e64 s[4:5], v[2:3], v6
2683 ; GFX7-NEXT: v_floor_f64_e32 v[8:9], v[2:3]
2684 ; GFX7-NEXT: v_floor_f64_e32 v[6:7], v[0:1]
2685 ; GFX7-NEXT: s_mov_b32 s10, 0
2686 ; GFX7-NEXT: s_mov_b32 s11, 0xf000
2687 ; GFX7-NEXT: s_mov_b32 s8, s10
2688 ; GFX7-NEXT: s_mov_b32 s9, s10
2689 ; GFX7-NEXT: v_cndmask_b32_e64 v0, v10, 0, vcc
2690 ; GFX7-NEXT: v_cndmask_b32_e64 v1, v11, 0, vcc
2691 ; GFX7-NEXT: v_cndmask_b32_e64 v2, v12, 0, s[4:5]
2692 ; GFX7-NEXT: v_cndmask_b32_e64 v3, v13, 0, s[4:5]
2693 ; GFX7-NEXT: buffer_store_dwordx4 v[6:9], v[4:5], s[8:11], 0 addr64
2694 ; GFX7-NEXT: s_waitcnt vmcnt(0)
2695 ; GFX7-NEXT: s_setpc_b64 s[30:31]
2697 ; GFX8-LABEL: safe_math_fract_v2f64:
2698 ; GFX8: ; %bb.0: ; %entry
2699 ; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2700 ; GFX8-NEXT: v_mov_b32_e32 v6, 0x204
2701 ; GFX8-NEXT: v_fract_f64_e32 v[10:11], v[0:1]
2702 ; GFX8-NEXT: v_cmp_class_f64_e32 vcc, v[0:1], v6
2703 ; GFX8-NEXT: v_fract_f64_e32 v[12:13], v[2:3]
2704 ; GFX8-NEXT: v_cmp_class_f64_e64 s[4:5], v[2:3], v6
2705 ; GFX8-NEXT: v_floor_f64_e32 v[8:9], v[2:3]
2706 ; GFX8-NEXT: v_floor_f64_e32 v[6:7], v[0:1]
2707 ; GFX8-NEXT: v_cndmask_b32_e64 v0, v10, 0, vcc
2708 ; GFX8-NEXT: v_cndmask_b32_e64 v1, v11, 0, vcc
2709 ; GFX8-NEXT: v_cndmask_b32_e64 v2, v12, 0, s[4:5]
2710 ; GFX8-NEXT: v_cndmask_b32_e64 v3, v13, 0, s[4:5]
2711 ; GFX8-NEXT: global_store_dwordx4 v[4:5], v[6:9], off
2712 ; GFX8-NEXT: s_waitcnt vmcnt(0)
2713 ; GFX8-NEXT: s_setpc_b64 s[30:31]
2715 ; GFX11-LABEL: safe_math_fract_v2f64:
2716 ; GFX11: ; %bb.0: ; %entry
2717 ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
2718 ; GFX11-NEXT: v_fract_f64_e32 v[10:11], v[0:1]
2719 ; GFX11-NEXT: v_cmp_class_f64_e64 s0, v[0:1], 0x204
2720 ; GFX11-NEXT: v_fract_f64_e32 v[12:13], v[2:3]
2721 ; GFX11-NEXT: v_cmp_class_f64_e64 s1, v[2:3], 0x204
2722 ; GFX11-NEXT: v_floor_f64_e32 v[8:9], v[2:3]
2723 ; GFX11-NEXT: v_floor_f64_e32 v[6:7], v[0:1]
2724 ; GFX11-NEXT: v_cndmask_b32_e64 v0, v10, 0, s0
2725 ; GFX11-NEXT: v_cndmask_b32_e64 v1, v11, 0, s0
2726 ; GFX11-NEXT: v_cndmask_b32_e64 v2, v12, 0, s1
2727 ; GFX11-NEXT: v_cndmask_b32_e64 v3, v13, 0, s1
2728 ; GFX11-NEXT: global_store_b128 v[4:5], v[6:9], off
2729 ; GFX11-NEXT: s_setpc_b64 s[30:31]
2731 ; GFX12-LABEL: safe_math_fract_v2f64:
2732 ; GFX12: ; %bb.0: ; %entry
2733 ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
2734 ; GFX12-NEXT: s_wait_expcnt 0x0
2735 ; GFX12-NEXT: s_wait_samplecnt 0x0
2736 ; GFX12-NEXT: s_wait_bvhcnt 0x0
2737 ; GFX12-NEXT: s_wait_kmcnt 0x0
2738 ; GFX12-NEXT: v_fract_f64_e32 v[10:11], v[0:1]
2739 ; GFX12-NEXT: v_cmp_class_f64_e64 s0, v[0:1], 0x204
2740 ; GFX12-NEXT: v_fract_f64_e32 v[12:13], v[2:3]
2741 ; GFX12-NEXT: v_cmp_class_f64_e64 s1, v[2:3], 0x204
2742 ; GFX12-NEXT: v_floor_f64_e32 v[8:9], v[2:3]
2743 ; GFX12-NEXT: v_floor_f64_e32 v[6:7], v[0:1]
2744 ; GFX12-NEXT: s_wait_alu 0xf1ff
2745 ; GFX12-NEXT: v_cndmask_b32_e64 v0, v10, 0, s0
2746 ; GFX12-NEXT: v_cndmask_b32_e64 v1, v11, 0, s0
2747 ; GFX12-NEXT: v_cndmask_b32_e64 v2, v12, 0, s1
2748 ; GFX12-NEXT: v_cndmask_b32_e64 v3, v13, 0, s1
2749 ; GFX12-NEXT: global_store_b128 v[4:5], v[6:9], off
2750 ; GFX12-NEXT: s_setpc_b64 s[30:31]
2752 %floor = tail call <2 x double> @llvm.floor.v2f64(<2 x double> %x)
2753 %sub = fsub <2 x double> %x, %floor
2754 %min = tail call <2 x double> @llvm.minnum.v2f64(<2 x double> %sub, <2 x double> <double 0x3FEFFFFFFFFFFFFF, double 0x3FEFFFFFFFFFFFFF>)
2755 %uno = fcmp uno <2 x double> %x, zeroinitializer
2756 %cond = select <2 x i1> %uno, <2 x double> %x, <2 x double> %min
2757 %fabs = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
2758 %cmpinf = fcmp oeq <2 x double> %fabs, <double 0x7FF0000000000000, double 0x7FF0000000000000>
2759 %cond6 = select <2 x i1> %cmpinf, <2 x double> zeroinitializer, <2 x double> %cond
2760 store <2 x double> %floor, ptr addrspace(1) %ip, align 4
2761 ret <2 x double> %cond6
2764 declare half @llvm.floor.f16(half) #0
2765 declare float @llvm.floor.f32(float) #0
2766 declare double @llvm.floor.f64(double) #0
2767 declare <2 x double> @llvm.floor.v2f64(<2 x double>) #0
2768 declare <2 x float> @llvm.floor.v2f32(<2 x float>) #0
2769 declare <2 x half> @llvm.floor.v2f16(<2 x half>) #0
2770 declare float @llvm.trunc.f32(float) #0
2771 declare float @llvm.minnum.f32(float, float) #0
2772 declare half @llvm.minnum.f16(half, half) #0
2773 declare double @llvm.minnum.f64(double, double) #0
2774 declare <2 x float> @llvm.minnum.v2f32(<2 x float>, <2 x float>) #0
2775 declare <2 x half> @llvm.minnum.v2f16(<2 x half>, <2 x half>) #0
2776 declare <2 x double> @llvm.minnum.v2f64(<2 x double>, <2 x double>) #0
2777 declare float @llvm.maxnum.f32(float, float) #0
2778 declare float @llvm.fabs.f32(float) #0
2779 declare double @llvm.fabs.f64(double) #0
2780 declare <2 x float> @llvm.fabs.v2f32(<2 x float>) #0
2781 declare half @llvm.fabs.f16(half) #0
2782 declare <2 x half> @llvm.fabs.v2f16(<2 x half>) #0
2783 declare <2 x double> @llvm.fabs.v2f64(<2 x double>) #0
2785 attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }