blob: e0067f9f45acc5988de1b067085b2f41335e388c [file] [log] [blame]
Matt Arsenault49459052016-05-21 00:29:40 +00001; RUN: llc -march=amdgcn -mcpu=verde < %s | FileCheck %s
Nicolai Haehnleef160de2016-03-16 20:14:33 +00002
3; Test a simple uniform loop that lives inside non-uniform control flow.
4
Matt Arsenault49459052016-05-21 00:29:40 +00005; CHECK-LABEL: {{^}}test1:
Matt Arsenault5d8eb252016-09-30 01:50:20 +00006; CHECK: v_cmp_ne_u32_e32 vcc, 0
Matt Arsenault49459052016-05-21 00:29:40 +00007; CHECK: s_and_saveexec_b64
Matt Arsenault57431c92016-08-10 19:11:42 +00008; CHECK-NEXT: s_xor_b64
9; CHECK-NEXT: ; mask branch
Matt Arsenault57431c92016-08-10 19:11:42 +000010
11; CHECK-NEXT: BB{{[0-9]+_[0-9]+}}: ; %loop_body.preheader
Matt Arsenault49459052016-05-21 00:29:40 +000012
13; CHECK: [[LOOP_BODY_LABEL:BB[0-9]+_[0-9]+]]:
Tom Stellard0bc68812016-11-29 00:46:46 +000014; CHECK: s_cbranch_scc0 [[LOOP_BODY_LABEL]]
Matt Arsenault49459052016-05-21 00:29:40 +000015
16; CHECK: s_endpgm
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +000017define amdgpu_ps void @test1(<8 x i32> inreg %rsrc, <2 x i32> %addr.base, i32 %y, i32 %p) {
Nicolai Haehnleef160de2016-03-16 20:14:33 +000018main_body:
19 %cc = icmp eq i32 %p, 0
20 br i1 %cc, label %out, label %loop_body
21
22loop_body:
23 %counter = phi i32 [ 0, %main_body ], [ %incr, %loop_body ]
24
25 ; Prevent the loop from being optimized out
26 call void asm sideeffect "", "" ()
27
28 %incr = add i32 %counter, 1
29 %lc = icmp sge i32 %incr, 1000
30 br i1 %lc, label %out, label %loop_body
31
32out:
33 ret void
34}
35
Matt Arsenault57431c92016-08-10 19:11:42 +000036; CHECK-LABEL: {{^}}test2:
37; CHECK: s_and_saveexec_b64
38; CHECK-NEXT: s_xor_b64
39; CHECK-NEXT: ; mask branch
40; CHECK-NEXT: s_cbranch_execz
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000041define amdgpu_kernel void @test2(i32 addrspace(1)* %out, i32 %a, i32 %b) {
Tom Stellard92339e82016-03-21 18:56:58 +000042main_body:
43 %tid = call i32 @llvm.amdgcn.workitem.id.x() #1
44 %cc = icmp eq i32 %tid, 0
45 br i1 %cc, label %done1, label %if
46
47if:
48 %cmp = icmp eq i32 %a, 0
49 br i1 %cmp, label %done0, label %loop_body
50
51loop_body:
52 %counter = phi i32 [ 0, %if ], [0, %done0], [ %incr, %loop_body ]
53
54 ; Prevent the loop from being optimized out
55 call void asm sideeffect "", "" ()
56
57 %incr = add i32 %counter, 1
58 %lc = icmp sge i32 %incr, 1000
59 br i1 %lc, label %done1, label %loop_body
60
61done0:
62 %cmp0 = icmp eq i32 %b, 0
63 br i1 %cmp0, label %done1, label %loop_body
64
65done1:
66 ret void
67}
68
69declare i32 @llvm.amdgcn.workitem.id.x() #1
70
Nicolai Haehnleef160de2016-03-16 20:14:33 +000071attributes #1 = { nounwind readonly }