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