1 ; RUN: llc -march=amdgcn -mcpu=verde -amdgpu-early-ifcvt=0 -machine-sink-split-probability-threshold=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN -check-prefix=SI %s
2 ; RUN: llc -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -amdgpu-early-ifcvt=0 -machine-sink-split-probability-threshold=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN -check-prefix=VI %s
4 ; GCN-LABEL: {{^}}uniform_if_scc:
5 ; GCN-DAG: s_cmp_eq_u32 s{{[0-9]+}}, 0
6 ; GCN-DAG: s_mov_b32 [[S_VAL:s[0-9]+]], 0
7 ; GCN: s_cbranch_scc1 [[IF_LABEL:[0-9_A-Za-z]+]]
9 ; Fall-through to the else
10 ; GCN: s_mov_b32 [[S_VAL]], 1
13 ; GCN: v_mov_b32_e32 [[V_VAL:v[0-9]+]], [[S_VAL]]
14 ; GCN: buffer_store_dword [[V_VAL]]
15 define amdgpu_kernel void @uniform_if_scc(i32 %cond, i32 addrspace(1)* %out) {
17 %cmp0 = icmp eq i32 %cond, 0
18 br i1 %cmp0, label %if, label %else
27 %value = phi i32 [0, %if], [1, %else]
28 store i32 %value, i32 addrspace(1)* %out
32 ; GCN-LABEL: {{^}}uniform_if_vcc:
33 ; GCN-DAG: v_cmp_eq_f32_e64 [[COND:vcc|s\[[0-9]+:[0-9]+\]]], s{{[0-9]+}}, 0{{$}}
34 ; GCN-DAG: s_mov_b32 [[S_VAL:s[0-9]+]], 0
35 ; GCN: s_cbranch_vccnz [[IF_LABEL:[0-9_A-Za-z]+]]
37 ; Fall-through to the else
38 ; GCN: s_mov_b32 [[S_VAL]], 1
41 ; GCN: v_mov_b32_e32 [[V_VAL:v[0-9]+]], [[S_VAL]]
42 ; GCN: buffer_store_dword [[V_VAL]]
43 define amdgpu_kernel void @uniform_if_vcc(float %cond, i32 addrspace(1)* %out) {
45 %cmp0 = fcmp oeq float %cond, 0.0
46 br i1 %cmp0, label %if, label %else
55 %value = phi i32 [0, %if], [1, %else]
56 store i32 %value, i32 addrspace(1)* %out
60 ; GCN-LABEL: {{^}}uniform_if_swap_br_targets_scc:
61 ; GCN-DAG: s_cmp_lg_u32 s{{[0-9]+}}, 0
62 ; GCN-DAG: s_mov_b32 [[S_VAL:s[0-9]+]], 0
63 ; GCN: s_cbranch_scc1 [[IF_LABEL:[0-9_A-Za-z]+]]
65 ; Fall-through to the else
66 ; GCN: s_mov_b32 [[S_VAL]], 1
69 ; GCN: v_mov_b32_e32 [[V_VAL:v[0-9]+]], [[S_VAL]]
70 ; GCN: buffer_store_dword [[V_VAL]]
71 define amdgpu_kernel void @uniform_if_swap_br_targets_scc(i32 %cond, i32 addrspace(1)* %out) {
73 %cmp0 = icmp eq i32 %cond, 0
74 br i1 %cmp0, label %else, label %if
83 %value = phi i32 [0, %if], [1, %else]
84 store i32 %value, i32 addrspace(1)* %out
88 ; GCN-LABEL: {{^}}uniform_if_swap_br_targets_vcc:
89 ; GCN-DAG: v_cmp_neq_f32_e64 [[COND:vcc|s\[[0-9]+:[0-9]+\]]], s{{[0-9]+}}, 0{{$}}
90 ; GCN-DAG: s_mov_b32 [[S_VAL:s[0-9]+]], 0
91 ; GCN: s_cbranch_vccnz [[IF_LABEL:[0-9_A-Za-z]+]]
93 ; Fall-through to the else
94 ; GCN: s_mov_b32 [[S_VAL]], 1
97 ; GCN: v_mov_b32_e32 [[V_VAL:v[0-9]+]], [[S_VAL]]
98 ; GCN: buffer_store_dword [[V_VAL]]
99 define amdgpu_kernel void @uniform_if_swap_br_targets_vcc(float %cond, i32 addrspace(1)* %out) {
101 %cmp0 = fcmp oeq float %cond, 0.0
102 br i1 %cmp0, label %else, label %if
111 %value = phi i32 [0, %if], [1, %else]
112 store i32 %value, i32 addrspace(1)* %out
116 ; GCN-LABEL: {{^}}uniform_if_move_valu:
117 ; GCN: v_add_f32_e32 [[CMP:v[0-9]+]]
118 ; Using a floating-point value in an integer compare will cause the compare to
119 ; be selected for the SALU and then later moved to the VALU.
120 ; GCN: v_cmp_ne_u32_e32 [[COND:vcc|s\[[0-9]+:[0-9]+\]]], 5, [[CMP]]
121 ; GCN: s_and_b64 vcc, exec, [[COND]]
122 ; GCN: s_cbranch_vccnz [[ENDIF_LABEL:[0-9_A-Za-z]+]]
123 ; GCN: buffer_store_dword
124 ; GCN: [[ENDIF_LABEL]]:
126 define amdgpu_kernel void @uniform_if_move_valu(i32 addrspace(1)* %out, float %a) {
128 %a.0 = fadd float %a, 10.0
129 %cond = bitcast float %a.0 to i32
130 %cmp = icmp eq i32 %cond, 5
131 br i1 %cmp, label %if, label %endif
134 store i32 0, i32 addrspace(1)* %out
141 ; GCN-LABEL: {{^}}uniform_if_move_valu_commute:
142 ; GCN: v_add_f32_e32 [[CMP:v[0-9]+]]
143 ; Using a floating-point value in an integer compare will cause the compare to
144 ; be selected for the SALU and then later moved to the VALU.
145 ; GCN: v_cmp_gt_u32_e32 [[COND:vcc|s\[[0-9]+:[0-9]+\]]], 6, [[CMP]]
146 ; GCN: s_and_b64 vcc, exec, [[COND]]
147 ; GCN: s_cbranch_vccnz [[ENDIF_LABEL:[0-9_A-Za-z]+]]
148 ; GCN: buffer_store_dword
149 ; GCN: [[ENDIF_LABEL]]:
151 define amdgpu_kernel void @uniform_if_move_valu_commute(i32 addrspace(1)* %out, float %a) {
153 %a.0 = fadd float %a, 10.0
154 %cond = bitcast float %a.0 to i32
155 %cmp = icmp ugt i32 %cond, 5
156 br i1 %cmp, label %if, label %endif
159 store i32 0, i32 addrspace(1)* %out
167 ; GCN-LABEL: {{^}}uniform_if_else_ret:
168 ; GCN: s_cmp_lg_u32 s{{[0-9]+}}, 0
169 ; GCN: s_cbranch_scc0 [[IF_LABEL:[0-9_A-Za-z]+]]
171 ; GCN: v_mov_b32_e32 [[TWO:v[0-9]+]], 2
172 ; GCN: buffer_store_dword [[TWO]]
175 ; GCN: {{^}}[[IF_LABEL]]:
176 ; GCN: v_mov_b32_e32 [[ONE:v[0-9]+]], 1
177 ; GCN: buffer_store_dword [[ONE]]
179 define amdgpu_kernel void @uniform_if_else_ret(i32 addrspace(1)* nocapture %out, i32 %a) {
181 %cmp = icmp eq i32 %a, 0
182 br i1 %cmp, label %if.then, label %if.else
184 if.then: ; preds = %entry
185 store i32 1, i32 addrspace(1)* %out
188 if.else: ; preds = %entry
189 store i32 2, i32 addrspace(1)* %out
192 if.end: ; preds = %if.else, %if.then
196 ; GCN-LABEL: {{^}}uniform_if_else:
197 ; GCN: s_cmp_lg_u32 s{{[0-9]+}}, 0
198 ; GCN: s_cbranch_scc0 [[IF_LABEL:[0-9_A-Za-z]+]]
200 ; GCN: v_mov_b32_e32 [[IMM_REG:v[0-9]+]], 2
201 ; GCN: s_branch [[ENDIF_LABEL:[0-9_A-Za-z]+]]
204 ; GCN-NEXT: v_mov_b32_e32 [[IMM_REG]], 1
206 ; GCN-NEXT: [[ENDIF_LABEL]]:
207 ; GCN: buffer_store_dword [[IMM_REG]]
209 ; GCN: v_mov_b32_e32 [[THREE:v[0-9]+]], 3
210 ; GCN: buffer_store_dword [[THREE]]
212 define amdgpu_kernel void @uniform_if_else(i32 addrspace(1)* nocapture %out0, i32 addrspace(1)* nocapture %out1, i32 %a) {
214 %cmp = icmp eq i32 %a, 0
215 br i1 %cmp, label %if.then, label %if.else
217 if.then: ; preds = %entry
218 store i32 1, i32 addrspace(1)* %out0
221 if.else: ; preds = %entry
222 store i32 2, i32 addrspace(1)* %out0
225 if.end: ; preds = %if.else, %if.then
226 store i32 3, i32 addrspace(1)* %out1
230 ; GCN-LABEL: {{^}}icmp_2_users:
231 ; GCN: s_cmp_lt_i32 s{{[0-9]+}}, 1
232 ; GCN: s_cbranch_scc1 [[LABEL:[a-zA-Z0-9_]+]]
233 ; GCN: buffer_store_dword
236 define amdgpu_kernel void @icmp_2_users(i32 addrspace(1)* %out, i32 %cond) {
238 %0 = icmp sgt i32 %cond, 0
239 %1 = sext i1 %0 to i32
240 br i1 %0, label %IF, label %ENDIF
243 store i32 %1, i32 addrspace(1)* %out
246 ENDIF: ; preds = %IF, %main_body
250 ; GCN-LABEL: {{^}}icmp_users_different_blocks:
251 ; GCN: s_load_dwordx2 s{{\[}}[[COND0:[0-9]+]]:[[COND1:[0-9]+]]{{\]}}
252 ; GCN: s_cmp_lt_i32 s[[COND0]], 1
253 ; GCN: s_cbranch_scc1 [[EXIT:[A-Za-z0-9_]+]]
254 ; GCN: v_cmp_gt_i32_e64 {{[^,]*}}, s[[COND1]], 0{{$}}
255 ; GCN: s_cbranch_vccz [[BODY:[A-Za-z0-9_]+]]
256 ; GCN: {{^}}[[EXIT]]:
258 ; GCN: {{^}}[[BODY]]:
261 define amdgpu_kernel void @icmp_users_different_blocks(i32 %cond0, i32 %cond1, i32 addrspace(1)* %out) {
263 %tmp = tail call i32 @llvm.amdgcn.workitem.id.x() #0
264 %cmp0 = icmp sgt i32 %cond0, 0
265 %cmp1 = icmp sgt i32 %cond1, 0
266 br i1 %cmp0, label %bb2, label %bb9
269 %tmp2 = sext i1 %cmp1 to i32
270 %tmp3 = add i32 %tmp2, %tmp
271 br i1 %cmp1, label %bb9, label %bb7
274 store i32 %tmp3, i32 addrspace(1)* %out
277 bb9: ; preds = %bb8, %bb4
281 ; SI-LABEL: {{^}}uniform_loop:
282 ; SI: {{^}}[[LOOP_LABEL:[A-Z0-9_a-z]+]]:
283 ; SI: s_add_i32 [[I:s[0-9]+]], s{{[0-9]+}}, -1
284 ; SI: s_cmp_lg_u32 [[I]], 0
285 ; SI: s_cbranch_scc1 [[LOOP_LABEL]]
287 define amdgpu_kernel void @uniform_loop(i32 addrspace(1)* %out, i32 %a) {
292 %i = phi i32 [0, %entry], [%i.i, %loop]
294 %cmp = icmp eq i32 %a, %i.i
295 br i1 %cmp, label %done, label %loop
301 ; Test uniform and divergent.
303 ; GCN-LABEL: {{^}}uniform_inside_divergent:
304 ; GCN: v_cmp_gt_u32_e32 vcc, 16, v{{[0-9]+}}
305 ; GCN: s_and_saveexec_b64 [[MASK:s\[[0-9]+:[0-9]+\]]], vcc
306 ; GCN: s_cmp_lg_u32 {{s[0-9]+}}, 0
307 ; GCN: s_cbranch_scc0 [[IF_UNIFORM_LABEL:[A-Z0-9_a-z]+]]
309 ; GCN: {{^}}[[IF_UNIFORM_LABEL]]:
310 ; GCN: v_mov_b32_e32 [[ONE:v[0-9]+]], 1
311 ; GCN: buffer_store_dword [[ONE]]
312 define amdgpu_kernel void @uniform_inside_divergent(i32 addrspace(1)* %out, i32 %cond) {
314 %tid = call i32 @llvm.amdgcn.workitem.id.x() #0
315 %d_cmp = icmp ult i32 %tid, 16
316 br i1 %d_cmp, label %if, label %endif
319 store i32 0, i32 addrspace(1)* %out
320 %u_cmp = icmp eq i32 %cond, 0
321 br i1 %u_cmp, label %if_uniform, label %endif
324 store i32 1, i32 addrspace(1)* %out
331 ; GCN-LABEL: {{^}}divergent_inside_uniform:
332 ; GCN: s_cmp_lg_u32 s{{[0-9]+}}, 0
333 ; GCN: s_cbranch_scc1 [[ENDIF_LABEL:[0-9_A-Za-z]+]]
334 ; GCN: v_cmp_gt_u32_e32 vcc, 16, v{{[0-9]+}}
335 ; GCN: s_and_saveexec_b64 [[MASK:s\[[0-9]+:[0-9]+\]]], vcc
336 ; GCN: ; mask branch [[ENDIF_LABEL]]
337 ; GCN: v_mov_b32_e32 [[ONE:v[0-9]+]], 1
338 ; GCN: buffer_store_dword [[ONE]]
339 ; GCN: [[ENDIF_LABEL]]:
341 define amdgpu_kernel void @divergent_inside_uniform(i32 addrspace(1)* %out, i32 %cond) {
343 %u_cmp = icmp eq i32 %cond, 0
344 br i1 %u_cmp, label %if, label %endif
347 store i32 0, i32 addrspace(1)* %out
348 %tid = call i32 @llvm.amdgcn.workitem.id.x() #0
349 %d_cmp = icmp ult i32 %tid, 16
350 br i1 %d_cmp, label %if_uniform, label %endif
353 store i32 1, i32 addrspace(1)* %out
360 ; GCN-LABEL: {{^}}divergent_if_uniform_if:
361 ; GCN: v_cmp_eq_u32_e32 vcc, 0, v0
362 ; GCN: s_and_saveexec_b64 [[MASK:s\[[0-9]+:[0-9]+\]]], vcc
363 ; GCN: v_mov_b32_e32 [[ONE:v[0-9]+]], 1
364 ; GCN: buffer_store_dword [[ONE]]
365 ; GCN: s_or_b64 exec, exec, [[MASK]]
366 ; GCN: s_cmp_lg_u32 s{{[0-9]+}}, 0
367 ; GCN: s_cbranch_scc0 [[IF_UNIFORM:[A-Z0-9_]+]]
369 ; GCN: [[IF_UNIFORM]]:
370 ; GCN: v_mov_b32_e32 [[TWO:v[0-9]+]], 2
371 ; GCN: buffer_store_dword [[TWO]]
372 define amdgpu_kernel void @divergent_if_uniform_if(i32 addrspace(1)* %out, i32 %cond) {
374 %tid = call i32 @llvm.amdgcn.workitem.id.x() #0
375 %d_cmp = icmp eq i32 %tid, 0
376 br i1 %d_cmp, label %if, label %endif
379 store i32 1, i32 addrspace(1)* %out
383 %u_cmp = icmp eq i32 %cond, 0
384 br i1 %u_cmp, label %if_uniform, label %exit
387 store i32 2, i32 addrspace(1)* %out
394 ; The condition of the branches in the two blocks are
395 ; uniform. MachineCSE replaces the 2nd condition with the inverse of
396 ; the first, leaving an scc use in a different block than it was
399 ; GCN-LABEL: {{^}}cse_uniform_condition_different_blocks:
400 ; GCN: s_load_dword [[COND:s[0-9]+]]
401 ; GCN: s_cmp_lt_i32 [[COND]], 1
402 ; GCN: s_cbranch_scc1 BB[[FNNUM:[0-9]+]]_3
406 ; GCN: buffer_load_dword
407 ; GCN: buffer_store_dword
408 ; GCN: s_cbranch_scc1 BB[[FNNUM]]_3
410 ; GCN: BB[[FNNUM]]_3:
412 define amdgpu_kernel void @cse_uniform_condition_different_blocks(i32 %cond, i32 addrspace(1)* %out) {
414 %tmp = tail call i32 @llvm.amdgcn.workitem.id.x() #0
415 %tmp1 = icmp sgt i32 %cond, 0
416 br i1 %tmp1, label %bb2, label %bb9
419 %tmp3 = load volatile i32, i32 addrspace(1)* undef
420 store volatile i32 0, i32 addrspace(1)* undef
421 %tmp9 = icmp sle i32 %cond, 0
422 br i1 %tmp9, label %bb9, label %bb7
425 store i32 %tmp3, i32 addrspace(1)* %out
428 bb9: ; preds = %bb8, %bb4
432 ; GCN-LABEL: {{^}}uniform_if_scc_i64_eq:
433 ; VI-DAG: s_cmp_eq_u64 s{{\[[0-9]+:[0-9]+\]}}, 0
434 ; GCN-DAG: s_mov_b32 [[S_VAL:s[0-9]+]], 0
435 ; SI-DAG: v_cmp_eq_u64_e64
436 ; SI: s_cbranch_vccnz [[IF_LABEL:[0-9_A-Za-z]+]]
438 ; VI: s_cbranch_scc1 [[IF_LABEL:[0-9_A-Za-z]+]]
440 ; Fall-through to the else
441 ; GCN: s_mov_b32 [[S_VAL]], 1
444 ; GCN: v_mov_b32_e32 [[V_VAL:v[0-9]+]], [[S_VAL]]
445 ; GCN: buffer_store_dword [[V_VAL]]
446 define amdgpu_kernel void @uniform_if_scc_i64_eq(i64 %cond, i32 addrspace(1)* %out) {
448 %cmp0 = icmp eq i64 %cond, 0
449 br i1 %cmp0, label %if, label %else
458 %value = phi i32 [0, %if], [1, %else]
459 store i32 %value, i32 addrspace(1)* %out
463 ; GCN-LABEL: {{^}}uniform_if_scc_i64_ne:
464 ; VI-DAG: s_cmp_lg_u64 s{{\[[0-9]+:[0-9]+\]}}, 0
465 ; GCN-DAG: s_mov_b32 [[S_VAL:s[0-9]+]], 0
467 ; SI-DAG: v_cmp_ne_u64_e64
468 ; SI: s_cbranch_vccnz [[IF_LABEL:[0-9_A-Za-z]+]]
470 ; VI: s_cbranch_scc1 [[IF_LABEL:[0-9_A-Za-z]+]]
472 ; Fall-through to the else
473 ; GCN: s_mov_b32 [[S_VAL]], 1
476 ; GCN: v_mov_b32_e32 [[V_VAL:v[0-9]+]], [[S_VAL]]
477 ; GCN: buffer_store_dword [[V_VAL]]
478 define amdgpu_kernel void @uniform_if_scc_i64_ne(i64 %cond, i32 addrspace(1)* %out) {
480 %cmp0 = icmp ne i64 %cond, 0
481 br i1 %cmp0, label %if, label %else
490 %value = phi i32 [0, %if], [1, %else]
491 store i32 %value, i32 addrspace(1)* %out
495 ; GCN-LABEL: {{^}}uniform_if_scc_i64_sgt:
496 ; GCN-DAG: s_mov_b32 [[S_VAL:s[0-9]+]], 0
497 ; GCN-DAG: v_cmp_gt_i64_e64
498 ; GCN: s_cbranch_vccnz [[IF_LABEL:[0-9_A-Za-z]+]]
500 ; Fall-through to the else
501 ; GCN: s_mov_b32 [[S_VAL]], 1
504 ; GCN: v_mov_b32_e32 [[V_VAL:v[0-9]+]], [[S_VAL]]
505 ; GCN: buffer_store_dword [[V_VAL]]
506 define amdgpu_kernel void @uniform_if_scc_i64_sgt(i64 %cond, i32 addrspace(1)* %out) {
508 %cmp0 = icmp sgt i64 %cond, 0
509 br i1 %cmp0, label %if, label %else
518 %value = phi i32 [0, %if], [1, %else]
519 store i32 %value, i32 addrspace(1)* %out
523 ; GCN-LABEL: {{^}}move_to_valu_i64_eq:
524 ; GCN: v_cmp_eq_u64_e32
525 define amdgpu_kernel void @move_to_valu_i64_eq(i32 addrspace(1)* %out) {
526 %cond = load volatile i64, i64 addrspace(3)* undef
527 %cmp0 = icmp eq i64 %cond, 0
528 br i1 %cmp0, label %if, label %else
537 %value = phi i32 [0, %if], [1, %else]
538 store i32 %value, i32 addrspace(1)* %out
542 ; GCN-LABEL: {{^}}move_to_valu_i64_ne:
543 ; GCN: v_cmp_ne_u64_e32
544 define amdgpu_kernel void @move_to_valu_i64_ne(i32 addrspace(1)* %out) {
545 %cond = load volatile i64, i64 addrspace(3)* undef
546 %cmp0 = icmp ne i64 %cond, 0
547 br i1 %cmp0, label %if, label %else
556 %value = phi i32 [0, %if], [1, %else]
557 store i32 %value, i32 addrspace(1)* %out
561 ; GCN-LABEL: {{^}}move_to_valu_vgpr_operand_phi:
562 ; GCN: v_add_{{[iu]}}32_e32
564 define void @move_to_valu_vgpr_operand_phi(i32 addrspace(3)* %out) {
568 bb1: ; preds = %bb3, %bb0
569 %tmp0 = phi i32 [ 8, %bb0 ], [ %tmp4, %bb3 ]
570 %tmp1 = add nsw i32 %tmp0, -1
571 %tmp2 = getelementptr inbounds i32, i32 addrspace(3)* %out, i32 %tmp1
572 br i1 undef, label %bb2, label %bb3
575 store volatile i32 1, i32 addrspace(3)* %tmp2, align 4
578 bb3: ; preds = %bb2, %bb1
579 %tmp4 = add nsw i32 %tmp0, 2
583 declare i32 @llvm.amdgcn.workitem.id.x() #0
585 attributes #0 = { nounwind readnone }