1 ; RUN: opt -mtriple amdgcn-unknown-amdhsa -passes='print<uniformity>' -disable-output %s 2>&1 | FileCheck %s
3 ; divergent loop (H<header><exiting to X>, B<exiting to Y>)
4 ; the divergent join point in %exit is obscured by uniform control joining in %X
5 define amdgpu_kernel void @hidden_loop_diverge(i32 %n, i32 %a, i32 %b) #0 {
6 ; CHECK-LABEL: for function 'hidden_loop_diverge':
7 ; CHECK-NOT: DIVERGENT: %uni.
8 ; CHECK-NOT: DIVERGENT: br i1 %uni.
11 %tid = call i32 @llvm.amdgcn.workitem.id.x()
12 %uni.cond = icmp slt i32 %a, 0
13 br i1 %uni.cond, label %X, label %H ; uniform
16 %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc, %B ]
17 %div.exitx = icmp slt i32 %tid, 0
18 br i1 %div.exitx, label %X, label %B ; divergent branch
19 ; CHECK: DIVERGENT: %div.exitx =
20 ; CHECK: DIVERGENT: br i1 %div.exitx,
23 %uni.inc = add i32 %uni.merge.h, 1
24 %div.exity = icmp sgt i32 %tid, 0
25 br i1 %div.exity, label %Y, label %H ; divergent branch
26 ; CHECK: DIVERGENT: %div.exity =
27 ; CHECK: DIVERGENT: br i1 %div.exity,
30 %div.merge.x = phi i32 [ %a, %entry ], [ %uni.merge.h, %H ] ; temporal divergent phi
31 br i1 %uni.cond, label %Y, label %exit
32 ; CHECK: DIVERGENT: %div.merge.x =
35 %div.merge.y = phi i32 [ 42, %X ], [ %b, %B ]
37 ; CHECK: DIVERGENT: %div.merge.y =
40 %div.merge.exit = phi i32 [ %a, %X ], [ %b, %Y ]
42 ; CHECK: DIVERGENT: %div.merge.exit =
45 ; divergent loop (H<header><exiting to X>, B<exiting to Y>)
46 ; the phi nodes in X and Y don't actually receive divergent values
47 define amdgpu_kernel void @unobserved_loop_diverge(i32 %n, i32 %a, i32 %b) #0 {
48 ; CHECK-LABEL: for function 'unobserved_loop_diverge':
49 ; CHECK-NOT: DIVERGENT: %uni.
50 ; CHECK-NOT: DIVERGENT: br i1 %uni.
53 %tid = call i32 @llvm.amdgcn.workitem.id.x()
54 %uni.cond = icmp slt i32 %a, 0
55 br i1 %uni.cond, label %X, label %H ; uniform
58 %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc, %B ]
59 %div.exitx = icmp slt i32 %tid, 0
60 br i1 %div.exitx, label %X, label %B ; divergent branch
61 ; CHECK: DIVERGENT: %div.exitx =
62 ; CHECK: DIVERGENT: br i1 %div.exitx,
65 %uni.inc = add i32 %uni.merge.h, 1
66 %div.exity = icmp sgt i32 %tid, 0
67 br i1 %div.exity, label %Y, label %H ; divergent branch
68 ; CHECK: DIVERGENT: %div.exity =
69 ; CHECK: DIVERGENT: br i1 %div.exity,
72 %uni.merge.x = phi i32 [ %a, %entry ], [ %b, %H ]
76 %uni.merge.y = phi i32 [ %b, %B ]
80 %div.merge.exit = phi i32 [ %a, %X ], [ %b, %Y ]
82 ; CHECK: DIVERGENT: %div.merge.exit =
85 ; divergent loop (G<header>, L<exiting to D>) inside divergent loop (H<header>, B<exiting to X>, C<exiting to Y>, D, G, L)
86 ; the inner loop has no exit to top level.
87 ; the outer loop becomes divergent as its exiting branch in C is control-dependent on the inner loop's divergent loop exit in D.
88 define amdgpu_kernel void @hidden_nestedloop_diverge(i32 %n, i32 %a, i32 %b) #0 {
89 ; CHECK-LABEL: for function 'hidden_nestedloop_diverge':
90 ; CHECK-NOT: DIVERGENT: %uni.
91 ; CHECK-NOT: DIVERGENT: br i1 %uni.
94 %tid = call i32 @llvm.amdgcn.workitem.id.x()
95 %uni.cond = icmp slt i32 %a, 0
96 %div.exitx = icmp slt i32 %tid, 0
97 br i1 %uni.cond, label %X, label %H
100 %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc, %D ]
101 br i1 %uni.cond, label %G, label %B
102 ; CHECK: DIVERGENT: %div.exitx =
105 br i1 %uni.cond, label %X, label %C
108 br i1 %uni.cond, label %Y, label %D
111 %uni.inc = add i32 %uni.merge.h, 1
115 br i1 %div.exitx, label %C, label %L
116 ; CHECK: DIVERGENT: br i1 %div.exitx,
119 br i1 %uni.cond, label %D, label %G
122 %uni.merge.x = phi i32 [ %a, %entry ], [ %uni.merge.h, %B ]
123 br i1 %uni.cond, label %Y, label %exit
126 %div.merge.y = phi i32 [ 42, %X ], [ %b, %C ]
128 ; CHECK: DIVERGENT: %div.merge.y =
131 %div.merge.exit = phi i32 [ %a, %X ], [ %b, %Y ]
133 ; CHECK: DIVERGENT: %div.merge.exit =
136 ; divergent loop (G<header>, L<exiting to X>) in divergent loop (H<header>, B<exiting to C>, C, G, L)
137 ; the outer loop has no immediately divergent exiting edge.
138 ; the inner exiting edge is exiting to top-level through the outer loop causing both to become divergent.
139 define amdgpu_kernel void @hidden_doublebreak_diverge(i32 %n, i32 %a, i32 %b) #0 {
140 ; CHECK-LABEL: for function 'hidden_doublebreak_diverge':
141 ; CHECK-NOT: DIVERGENT: %uni.
142 ; CHECK-NOT: DIVERGENT: br i1 %uni.
145 %tid = call i32 @llvm.amdgcn.workitem.id.x()
146 %uni.cond = icmp slt i32 %a, 0
147 %div.exitx = icmp slt i32 %tid, 0
148 br i1 %uni.cond, label %X, label %H
151 %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc, %C ]
152 br i1 %uni.cond, label %G, label %B
153 ; CHECK: DIVERGENT: %div.exitx =
156 br i1 %uni.cond, label %Y, label %C
159 %uni.inc = add i32 %uni.merge.h, 1
163 br i1 %div.exitx, label %X, label %L ; two-level break
164 ; CHECK: DIVERGENT: br i1 %div.exitx,
167 br i1 %uni.cond, label %C, label %G
170 %div.merge.x = phi i32 [ %a, %entry ], [ %uni.merge.h, %G ] ; temporal divergence
172 ; CHECK: DIVERGENT: %div.merge.x =
175 %div.merge.y = phi i32 [ 42, %X ], [ %b, %B ]
177 ; CHECK: DIVERGENT: %div.merge.y =
180 ; divergent loop (G<header>, L<exiting to D>) contained inside a uniform loop (H<header>, B, G, L , D<exiting to x>)
181 define amdgpu_kernel void @hidden_containedloop_diverge(i32 %n, i32 %a, i32 %b) #0 {
182 ; CHECK-LABEL: for function 'hidden_containedloop_diverge':
183 ; CHECK-NOT: DIVERGENT: %uni.
184 ; CHECK-NOT: DIVERGENT: br i1 %uni.
187 %tid = call i32 @llvm.amdgcn.workitem.id.x()
188 %uni.cond = icmp slt i32 %a, 0
189 %div.exitx = icmp slt i32 %tid, 0
190 br i1 %uni.cond, label %X, label %H
193 %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc.d, %D ]
194 br i1 %uni.cond, label %G, label %B
195 ; CHECK: DIVERGENT: %div.exitx =
198 %div.merge.b = phi i32 [ 42, %H ], [ %uni.merge.g, %G ]
200 ; CHECK: DIVERGENT: %div.merge.b =
203 %uni.merge.g = phi i32 [ 123, %H ], [ %uni.inc.l, %L ]
204 br i1 %div.exitx, label %B, label %L
205 ; CHECK: DIVERGENT: br i1 %div.exitx,
208 %uni.inc.l = add i32 %uni.merge.g, 1
209 br i1 %uni.cond, label %G, label %D
212 %uni.inc.d = add i32 %uni.merge.h, 1
213 br i1 %uni.cond, label %X, label %H
216 %uni.merge.x = phi i32 [ %a, %entry ], [ %uni.inc.d, %D ]
220 declare i32 @llvm.amdgcn.workitem.id.x() #0
222 attributes #0 = { nounwind readnone }