1 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=verde -amdgpu-early-ifcvt=1 -amdgpu-codegenprepare-break-large-phis=0 -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
2 ; XUN: llc -march=amdgcn -mcpu=tonga -amdgpu-early-ifcvt=1 -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
4 ; Note: breaking up large PHIs is disabled to prevent some testcases from becoming
7 ; FIXME: This leaves behind a now unnecessary and with exec
9 ; GCN-LABEL: {{^}}test_vccnz_ifcvt_triangle:
10 ; GCN: buffer_load_dword [[VAL:v[0-9]+]]
11 ; GCN: v_cmp_neq_f32_e32 vcc, 1.0, [[VAL]]
12 ; GCN: v_add_f32_e32 [[ADD:v[0-9]+]], [[VAL]], [[VAL]]
13 ; GCN: v_cndmask_b32_e32 [[RESULT:v[0-9]+]], [[ADD]], [[VAL]], vcc
14 ; GCN: buffer_store_dword [[RESULT]]
15 define amdgpu_kernel void @test_vccnz_ifcvt_triangle(ptr addrspace(1) %out, ptr addrspace(1) %in) #0 {
17 %v = load float, ptr addrspace(1) %in
18 %cc = fcmp oeq float %v, 1.000000e+00
19 br i1 %cc, label %if, label %endif
22 %u = fadd float %v, %v
26 %r = phi float [ %v, %entry ], [ %u, %if ]
27 store float %r, ptr addrspace(1) %out
31 ; GCN-LABEL: {{^}}test_vccnz_ifcvt_diamond:
32 ; GCN: buffer_load_dword [[VAL:v[0-9]+]]
33 ; GCN: v_cmp_neq_f32_e32 vcc, 1.0, [[VAL]]
34 ; GCN-DAG: v_add_f32_e32 [[ADD:v[0-9]+]], [[VAL]], [[VAL]]
35 ; GCN-DAG: v_mul_f32_e32 [[MUL:v[0-9]+]], [[VAL]], [[VAL]]
36 ; GCN: buffer_store_dword [[MUL]]
37 define amdgpu_kernel void @test_vccnz_ifcvt_diamond(ptr addrspace(1) %out, ptr addrspace(1) %in) #0 {
39 %v = load float, ptr addrspace(1) %in
40 %cc = fcmp oeq float %v, 1.000000e+00
41 br i1 %cc, label %if, label %else
44 %u0 = fadd float %v, %v
48 %u1 = fmul float %v, %v
52 %r = phi float [ %u0, %if ], [ %u1, %else ]
53 store float %r, ptr addrspace(1) %out
57 ; GCN-LABEL: {{^}}test_vccnz_ifcvt_triangle_vcc_clobber:
59 ; GCN: v_cmp_neq_f32_e64 [[CMP:s\[[0-9]+:[0-9]+\]]], s{{[0-9]+}}, 1.0
60 ; GCN: v_add_i32_e32 v{{[0-9]+}}, vcc
61 ; GCN: s_mov_b64 vcc, [[CMP]]
62 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}, vcc
63 define amdgpu_kernel void @test_vccnz_ifcvt_triangle_vcc_clobber(ptr addrspace(1) %out, ptr addrspace(1) %in, float %k) #0 {
65 %v = load i32, ptr addrspace(1) %in
66 %cc = fcmp oeq float %k, 1.000000e+00
67 br i1 %cc, label %if, label %endif
70 call void asm "; clobber $0", "~{vcc}"() #0
75 %r = phi i32 [ %v, %entry ], [ %u, %if ]
76 store i32 %r, ptr addrspace(1) %out
80 ; Longest chain of cheap instructions to convert
81 ; GCN-LABEL: {{^}}test_vccnz_ifcvt_triangle_max_cheap:
91 ; GCN: v_cndmask_b32_e32
92 define amdgpu_kernel void @test_vccnz_ifcvt_triangle_max_cheap(ptr addrspace(1) %out, ptr addrspace(1) %in) #0 {
94 %v = load float, ptr addrspace(1) %in
95 %cc = fcmp oeq float %v, 1.000000e+00
96 br i1 %cc, label %if, label %endif
99 %u.0 = fmul float %v, %v
100 %u.1 = fmul float %v, %u.0
101 %u.2 = fmul float %v, %u.1
102 %u.3 = fmul float %v, %u.2
103 %u.4 = fmul float %v, %u.3
104 %u.5 = fmul float %v, %u.4
105 %u.6 = fmul float %v, %u.5
106 %u.7 = fmul float %v, %u.6
107 %u.8 = fmul float %v, %u.7
111 %r = phi float [ %v, %entry ], [ %u.8, %if ]
112 store float %r, ptr addrspace(1) %out
116 ; Short chain of cheap instructions to not convert
117 ; GCN-LABEL: {{^}}test_vccnz_ifcvt_triangle_min_expensive:
118 ; GCN: s_cbranch_vccnz [[ENDIF:.LBB[0-9]+_[0-9]+]]
132 ; GCN: buffer_store_dword
133 define amdgpu_kernel void @test_vccnz_ifcvt_triangle_min_expensive(ptr addrspace(1) %out, ptr addrspace(1) %in) #0 {
135 %v = load float, ptr addrspace(1) %in
136 %cc = fcmp oeq float %v, 1.000000e+00
137 br i1 %cc, label %if, label %endif
140 %u.0 = fmul float %v, %v
141 %u.1 = fmul float %v, %u.0
142 %u.2 = fmul float %v, %u.1
143 %u.3 = fmul float %v, %u.2
144 %u.4 = fmul float %v, %u.3
145 %u.5 = fmul float %v, %u.4
146 %u.6 = fmul float %v, %u.5
147 %u.7 = fmul float %v, %u.6
148 %u.8 = fmul float %v, %u.7
149 %u.9 = fmul float %v, %u.8
153 %r = phi float [ %v, %entry ], [ %u.9, %if ]
154 store float %r, ptr addrspace(1) %out
158 ; Should still branch over fdiv expansion
159 ; GCN-LABEL: {{^}}test_vccnz_ifcvt_triangle_expensive:
160 ; GCN: v_cmp_neq_f32_e32
161 ; GCN: s_cbranch_vccnz [[ENDIF:.LBB[0-9]+_[0-9]+]]
163 ; GCN: v_div_scale_f32
166 ; GCN: buffer_store_dword
167 define amdgpu_kernel void @test_vccnz_ifcvt_triangle_expensive(ptr addrspace(1) %out, ptr addrspace(1) %in) #0 {
169 %v = load float, ptr addrspace(1) %in
170 %cc = fcmp oeq float %v, 1.000000e+00
171 br i1 %cc, label %if, label %endif
174 %u = fdiv float %v, %v
178 %r = phi float [ %v, %entry ], [ %u, %if ]
179 store float %r, ptr addrspace(1) %out
183 ; vcc branch with SGPR inputs
184 ; GCN-LABEL: {{^}}test_vccnz_sgpr_ifcvt_triangle:
185 ; GCN: v_cmp_neq_f32_e64
186 ; GCN: s_cbranch_vccnz [[ENDIF:.LBB[0-9]+_[0-9]+]]
191 ; GCN: buffer_store_dword
192 define amdgpu_kernel void @test_vccnz_sgpr_ifcvt_triangle(ptr addrspace(1) %out, ptr addrspace(4) %in, float %cnd) #0 {
194 %v = load i32, ptr addrspace(4) %in
195 %cc = fcmp oeq float %cnd, 1.000000e+00
196 br i1 %cc, label %if, label %endif
203 %r = phi i32 [ %v, %entry ], [ %u, %if ]
204 store i32 %r, ptr addrspace(1) %out
209 ; GCN-LABEL: {{^}}test_vccnz_ifcvt_triangle_constant_load:
211 define amdgpu_kernel void @test_vccnz_ifcvt_triangle_constant_load(ptr addrspace(1) %out, ptr addrspace(4) %in) #0 {
213 %v = load float, ptr addrspace(4) %in
214 %cc = fcmp oeq float %v, 1.000000e+00
215 br i1 %cc, label %if, label %endif
218 %u = fadd float %v, %v
222 %r = phi float [ %v, %entry ], [ %u, %if ]
223 store float %r, ptr addrspace(1) %out
227 ; Due to broken cost heuristic, this is not if converted like
228 ; test_vccnz_ifcvt_triangle_constant_load even though it should be.
230 ; GCN-LABEL: {{^}}test_vccnz_ifcvt_triangle_argload:
232 define amdgpu_kernel void @test_vccnz_ifcvt_triangle_argload(ptr addrspace(1) %out, float %v) #0 {
234 %cc = fcmp oeq float %v, 1.000000e+00
235 br i1 %cc, label %if, label %endif
238 %u = fadd float %v, %v
242 %r = phi float [ %v, %entry ], [ %u, %if ]
243 store float %r, ptr addrspace(1) %out
247 ; Scalar branch and scalar inputs
248 ; GCN-LABEL: {{^}}test_scc1_sgpr_ifcvt_triangle:
249 ; GCN: s_load_dword [[VAL:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0x0
250 ; GCN: s_add_i32 [[ADD:s[0-9]+]], [[VAL]], [[VAL]]
251 ; GCN: s_cmp_lg_u32 s{{[0-9]+}}, 1
252 ; GCN-NEXT: s_cselect_b32 [[SELECT:s[0-9]+]], [[VAL]], [[ADD]]
253 define amdgpu_kernel void @test_scc1_sgpr_ifcvt_triangle(ptr addrspace(4) %in, i32 %cond) #0 {
255 %v = load i32, ptr addrspace(4) %in
256 %cc = icmp eq i32 %cond, 1
257 br i1 %cc, label %if, label %endif
264 %r = phi i32 [ %v, %entry ], [ %u, %if ]
265 call void asm sideeffect "; reg use $0", "s"(i32 %r) #0
269 ; FIXME: Should be able to use VALU compare and select
270 ; Scalar branch but VGPR select operands
271 ; GCN-LABEL: {{^}}test_scc1_vgpr_ifcvt_triangle:
273 ; GCN: s_cbranch_scc1 [[ENDIF:.LBB[0-9]+_[0-9]+]]
278 ; GCN: buffer_store_dword
279 define amdgpu_kernel void @test_scc1_vgpr_ifcvt_triangle(ptr addrspace(1) %out, ptr addrspace(1) %in, i32 %cond) #0 {
281 %v = load float, ptr addrspace(1) %in
282 %cc = icmp eq i32 %cond, 1
283 br i1 %cc, label %if, label %endif
286 %u = fadd float %v, %v
290 %r = phi float [ %v, %entry ], [ %u, %if ]
291 store float %r, ptr addrspace(1) %out
295 ; GCN-LABEL: {{^}}test_scc1_sgpr_ifcvt_triangle64:
298 ; GCN: s_cmp_lg_u32 s{{[0-9]+}}, 1
299 ; GCN-NEXT: s_cselect_b64 s{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}
300 define amdgpu_kernel void @test_scc1_sgpr_ifcvt_triangle64(ptr addrspace(4) %in, i32 %cond) #0 {
302 %v = load i64, ptr addrspace(4) %in
303 %cc = icmp eq i32 %cond, 1
304 br i1 %cc, label %if, label %endif
311 %r = phi i64 [ %v, %entry ], [ %u, %if ]
312 call void asm sideeffect "; reg use $0", "s"(i64 %r) #0
316 ; TODO: Can do s_cselect_b64; s_cselect_b32
317 ; GCN-LABEL: {{^}}test_scc1_sgpr_ifcvt_triangle96:
321 ; GCN: s_cmp_lg_u32 s{{[0-9]+}}, 1
322 ; GCN-NEXT: s_cselect_b32 s
323 ; GCN-NEXT: s_cselect_b32 s
324 ; GCN-NEXT: s_cselect_b32 s
325 define amdgpu_kernel void @test_scc1_sgpr_ifcvt_triangle96(ptr addrspace(4) %in, i32 %cond) #0 {
327 %v = load <3 x i32>, ptr addrspace(4) %in
328 %cc = icmp eq i32 %cond, 1
329 br i1 %cc, label %if, label %endif
332 %u = add <3 x i32> %v, %v
336 %r = phi <3 x i32> [ %v, %entry ], [ %u, %if ]
337 %r.ext = shufflevector <3 x i32> %r, <3 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
338 call void asm sideeffect "; reg use $0", "s"(<4 x i32> %r.ext) #0
342 ; GCN-LABEL: {{^}}test_scc1_sgpr_ifcvt_triangle128:
347 ; GCN: s_cmp_lg_u32 s{{[0-9]+}}, 1
348 ; GCN-NEXT: s_cselect_b64 s{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}
349 ; GCN-NEXT: s_cselect_b64 s{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}
350 define amdgpu_kernel void @test_scc1_sgpr_ifcvt_triangle128(ptr addrspace(4) %in, i32 %cond) #0 {
352 %v = load <4 x i32>, ptr addrspace(4) %in
353 %cc = icmp eq i32 %cond, 1
354 br i1 %cc, label %if, label %endif
357 %u = add <4 x i32> %v, %v
361 %r = phi <4 x i32> [ %v, %entry ], [ %u, %if ]
362 call void asm sideeffect "; reg use $0", "s"(<4 x i32> %r) #0
366 ; GCN-LABEL: {{^}}uniform_if_swap_br_targets_scc_constant_select:
367 ; GCN: s_cmp_lg_u32 s{{[0-9]+}}, 0
368 ; GCN: s_cselect_b32 s{{[0-9]+}}, 0, 1{{$}}
369 define amdgpu_kernel void @uniform_if_swap_br_targets_scc_constant_select(i32 %cond, ptr addrspace(1) %out) {
371 %cmp0 = icmp eq i32 %cond, 0
372 br i1 %cmp0, label %else, label %if
381 %value = phi i32 [0, %if], [1, %else]
382 store i32 %value, ptr addrspace(1) %out
386 ; GCN-LABEL: {{^}}ifcvt_undef_scc:
388 ; GCN-NEXT: s_load_dwordx2
389 ; GCN-NEXT: s_cselect_b32 s{{[0-9]+}}, 0, 1{{$}}
390 define amdgpu_kernel void @ifcvt_undef_scc(i32 %cond, ptr addrspace(1) %out) {
392 br i1 undef, label %else, label %if
401 %value = phi i32 [0, %if], [1, %else]
402 store i32 %value, ptr addrspace(1) %out
406 ; GCN-LABEL: {{^}}test_vccnz_ifcvt_triangle256:
408 ; GCN: s_cbranch_vccnz [[ENDIF:.LBB[0-9]+_[0-9]+]]
414 ; GCN: buffer_store_dword
415 define amdgpu_kernel void @test_vccnz_ifcvt_triangle256(ptr addrspace(1) %out, ptr addrspace(1) %in, float %cnd) #0 {
417 %v = load <8 x i32>, ptr addrspace(1) %in
418 %cc = fcmp oeq float %cnd, 1.000000e+00
419 br i1 %cc, label %if, label %endif
422 %u = add <8 x i32> %v, %v
426 %r = phi <8 x i32> [ %v, %entry ], [ %u, %if ]
427 store <8 x i32> %r, ptr addrspace(1) %out
431 ; GCN-LABEL: {{^}}test_vccnz_ifcvt_triangle512:
433 ; GCN: s_cbranch_vccnz [[ENDIF:.LBB[0-9]+_[0-9]+]]
439 ; GCN: buffer_store_dword
440 define amdgpu_kernel void @test_vccnz_ifcvt_triangle512(ptr addrspace(1) %out, ptr addrspace(1) %in, float %cnd) #0 {
442 %v = load <16 x i32>, ptr addrspace(1) %in
443 %cc = fcmp oeq float %cnd, 1.000000e+00
444 br i1 %cc, label %if, label %endif
447 %u = add <16 x i32> %v, %v
451 %r = phi <16 x i32> [ %v, %entry ], [ %u, %if ]
452 store <16 x i32> %r, ptr addrspace(1) %out
456 attributes #0 = { nounwind }