blob: 1bbda66fddb16ad697cde22b56c3a73268f70c5f [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: ; mask branch
Matt Arsenault57431c92016-08-10 19:11:42 +00009; CHECK-NEXT: BB{{[0-9]+_[0-9]+}}: ; %loop_body.preheader
Matt Arsenault49459052016-05-21 00:29:40 +000010
11; CHECK: [[LOOP_BODY_LABEL:BB[0-9]+_[0-9]+]]:
Alexander Timofeevc1425c9d2017-12-01 11:56:34 +000012; CHECK: s_cbranch_scc0 [[LOOP_BODY_LABEL]]
Matt Arsenault49459052016-05-21 00:29:40 +000013
14; CHECK: s_endpgm
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +000015define 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 +000016main_body:
17 %cc = icmp eq i32 %p, 0
18 br i1 %cc, label %out, label %loop_body
19
20loop_body:
21 %counter = phi i32 [ 0, %main_body ], [ %incr, %loop_body ]
22
23 ; Prevent the loop from being optimized out
24 call void asm sideeffect "", "" ()
25
26 %incr = add i32 %counter, 1
27 %lc = icmp sge i32 %incr, 1000
28 br i1 %lc, label %out, label %loop_body
29
30out:
31 ret void
32}
33
Matt Arsenault57431c92016-08-10 19:11:42 +000034; CHECK-LABEL: {{^}}test2:
35; CHECK: s_and_saveexec_b64
Matt Arsenault57431c92016-08-10 19:11:42 +000036; CHECK-NEXT: ; mask branch
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000037define amdgpu_kernel void @test2(i32 addrspace(1)* %out, i32 %a, i32 %b) {
Tom Stellard92339e82016-03-21 18:56:58 +000038main_body:
39 %tid = call i32 @llvm.amdgcn.workitem.id.x() #1
40 %cc = icmp eq i32 %tid, 0
41 br i1 %cc, label %done1, label %if
42
43if:
44 %cmp = icmp eq i32 %a, 0
45 br i1 %cmp, label %done0, label %loop_body
46
47loop_body:
48 %counter = phi i32 [ 0, %if ], [0, %done0], [ %incr, %loop_body ]
49
50 ; Prevent the loop from being optimized out
51 call void asm sideeffect "", "" ()
52
53 %incr = add i32 %counter, 1
54 %lc = icmp sge i32 %incr, 1000
55 br i1 %lc, label %done1, label %loop_body
56
57done0:
58 %cmp0 = icmp eq i32 %b, 0
59 br i1 %cmp0, label %done1, label %loop_body
60
61done1:
62 ret void
63}
64
65declare i32 @llvm.amdgcn.workitem.id.x() #1
66
Nicolai Haehnleef160de2016-03-16 20:14:33 +000067attributes #1 = { nounwind readonly }