1; RUN: llc -march=amdgcn -mcpu=verde < %s | FileCheck %s
2
3; Test a simple uniform loop that lives inside non-uniform control flow.
4
5; CHECK-LABEL: {{^}}test1:
6; CHECK: v_cmp_ne_u32_e32 vcc, 0
7; CHECK: s_and_saveexec_b64
8; CHECK-NEXT: s_xor_b64
9; CHECK-NEXT: ; mask branch
10; CHECK-NEXT: s_cbranch_execz
11
12; CHECK-NEXT: BB{{[0-9]+_[0-9]+}}: ; %loop_body.preheader
13
14; CHECK: [[LOOP_BODY_LABEL:BB[0-9]+_[0-9]+]]:
15; CHECK: s_and_b64 vcc, exec, vcc
16; CHECK: s_cbranch_vccz [[LOOP_BODY_LABEL]]
17
18; CHECK: s_endpgm
19define amdgpu_ps void @test1(<8 x i32> inreg %rsrc, <2 x i32> %addr.base, i32 %y, i32 %p) {
20main_body:
21  %cc = icmp eq i32 %p, 0
22  br i1 %cc, label %out, label %loop_body
23
24loop_body:
25  %counter = phi i32 [ 0, %main_body ], [ %incr, %loop_body ]
26
27  ; Prevent the loop from being optimized out
28  call void asm sideeffect "", "" ()
29
30  %incr = add i32 %counter, 1
31  %lc = icmp sge i32 %incr, 1000
32  br i1 %lc, label %out, label %loop_body
33
34out:
35  ret void
36}
37
38; CHECK-LABEL: {{^}}test2:
39; CHECK: s_and_saveexec_b64
40; CHECK-NEXT: s_xor_b64
41; CHECK-NEXT: ; mask branch
42; CHECK-NEXT: s_cbranch_execz
43define void @test2(i32 addrspace(1)* %out, i32 %a, i32 %b) {
44main_body:
45  %tid = call i32 @llvm.amdgcn.workitem.id.x() #1
46  %cc = icmp eq i32 %tid, 0
47  br i1 %cc, label %done1, label %if
48
49if:
50  %cmp = icmp eq i32 %a, 0
51  br i1 %cmp, label %done0, label %loop_body
52
53loop_body:
54  %counter = phi i32 [ 0, %if ], [0, %done0], [ %incr, %loop_body ]
55
56  ; Prevent the loop from being optimized out
57  call void asm sideeffect "", "" ()
58
59  %incr = add i32 %counter, 1
60  %lc = icmp sge i32 %incr, 1000
61  br i1 %lc, label %done1, label %loop_body
62
63done0:
64  %cmp0 = icmp eq i32 %b, 0
65  br i1 %cmp0, label %done1, label %loop_body
66
67done1:
68  ret void
69}
70
71declare i32 @llvm.amdgcn.workitem.id.x() #1
72
73attributes #1 = { nounwind readonly }
74