1 ; RUN: opt -mtriple amdgcn-unknown-amdhsa -analyze -divergence -use-gpu-divergence-analysis %s | 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: Printing analysis 'Legacy Divergence Analysis' 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: Printing analysis 'Legacy Divergence Analysis' 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: Printing analysis 'Legacy Divergence Analysis' 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 %div.merge.x = phi i32 [ %a, %entry ], [ %uni.merge.h, %B ] ; temporal divergent phi
123 br i1 %uni.cond, label %Y, label %exit
124 ; CHECK: DIVERGENT: %div.merge.x =
127 %div.merge.y = phi i32 [ 42, %X ], [ %b, %C ]
129 ; CHECK: DIVERGENT: %div.merge.y =
132 %div.merge.exit = phi i32 [ %a, %X ], [ %b, %Y ]
134 ; CHECK: DIVERGENT: %div.merge.exit =
137 ; divergent loop (G<header>, L<exiting to X>) in divergent loop (H<header>, B<exiting to C>, C, G, L)
138 ; the outer loop has no immediately divergent exiting edge.
139 ; the inner exiting edge is exiting to top-level through the outer loop causing both to become divergent.
140 define amdgpu_kernel void @hidden_doublebreak_diverge(i32 %n, i32 %a, i32 %b) #0 {
141 ; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'hidden_doublebreak_diverge':
142 ; CHECK-NOT: DIVERGENT: %uni.
143 ; CHECK-NOT: DIVERGENT: br i1 %uni.
146 %tid = call i32 @llvm.amdgcn.workitem.id.x()
147 %uni.cond = icmp slt i32 %a, 0
148 %div.exitx = icmp slt i32 %tid, 0
149 br i1 %uni.cond, label %X, label %H
152 %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc, %C ]
153 br i1 %uni.cond, label %G, label %B
154 ; CHECK: DIVERGENT: %div.exitx =
157 br i1 %uni.cond, label %Y, label %C
160 %uni.inc = add i32 %uni.merge.h, 1
164 br i1 %div.exitx, label %X, label %L ; two-level break
165 ; CHECK: DIVERGENT: br i1 %div.exitx,
168 br i1 %uni.cond, label %C, label %G
171 %div.merge.x = phi i32 [ %a, %entry ], [ %uni.merge.h, %G ] ; temporal divergence
173 ; CHECK: DIVERGENT: %div.merge.x =
176 %div.merge.y = phi i32 [ 42, %X ], [ %b, %B ]
178 ; CHECK: DIVERGENT: %div.merge.y =
181 ; divergent loop (G<header>, L<exiting to D>) contained inside a uniform loop (H<header>, B, G, L , D<exiting to x>)
182 define amdgpu_kernel void @hidden_containedloop_diverge(i32 %n, i32 %a, i32 %b) #0 {
183 ; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'hidden_containedloop_diverge':
184 ; CHECK-NOT: DIVERGENT: %uni.
185 ; CHECK-NOT: DIVERGENT: br i1 %uni.
188 %tid = call i32 @llvm.amdgcn.workitem.id.x()
189 %uni.cond = icmp slt i32 %a, 0
190 %div.exitx = icmp slt i32 %tid, 0
191 br i1 %uni.cond, label %X, label %H
194 %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc.d, %D ]
195 br i1 %uni.cond, label %G, label %B
196 ; CHECK: DIVERGENT: %div.exitx =
199 %div.merge.b = phi i32 [ 42, %H ], [ %uni.merge.g, %G ]
201 ; CHECK: DIVERGENT: %div.merge.b =
204 %uni.merge.g = phi i32 [ 123, %H ], [ %uni.inc.l, %L ]
205 br i1 %div.exitx, label %B, label %L
206 ; CHECK: DIVERGENT: br i1 %div.exitx,
209 %uni.inc.l = add i32 %uni.merge.g, 1
210 br i1 %uni.cond, label %G, label %D
213 %uni.inc.d = add i32 %uni.merge.h, 1
214 br i1 %uni.cond, label %X, label %H
217 %uni.merge.x = phi i32 [ %a, %entry ], [ %uni.inc.d, %D ]
221 declare i32 @llvm.amdgcn.workitem.id.x() #0
223 attributes #0 = { nounwind readnone }