• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -mtriple amdgcn-unknown-amdhsa -analyze -divergence -use-gpu-divergence-analysis %s | FileCheck %s
2
3; temporal-divergent use of value carried by divergent loop
4define amdgpu_kernel void @temporal_diverge(i32 %n, i32 %a, i32 %b) #0 {
5; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'temporal_diverge':
6; CHECK-NOT: DIVERGENT: %uni.
7; CHECK-NOT: DIVERGENT: br i1 %uni.
8
9entry:
10  %tid = call i32 @llvm.amdgcn.workitem.id.x()
11  %uni.cond = icmp slt i32 %a, 0
12  br label %H
13
14H:
15  %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc, %H ]
16  %uni.inc = add i32 %uni.merge.h, 1
17  %div.exitx = icmp slt i32 %tid, 0
18  br i1 %div.exitx, label %X, label %H ; divergent branch
19; CHECK: DIVERGENT: %div.exitx =
20; CHECK: DIVERGENT: br i1 %div.exitx,
21
22X:
23  %div.user = add i32 %uni.inc, 5
24  ret void
25}
26
27; temporal-divergent use of value carried by divergent loop inside a top-level loop
28define amdgpu_kernel void @temporal_diverge_inloop(i32 %n, i32 %a, i32 %b) #0 {
29; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'temporal_diverge_inloop':
30; CHECK-NOT: DIVERGENT: %uni.
31; CHECK-NOT: DIVERGENT: br i1 %uni.
32
33entry:
34  %tid = call i32 @llvm.amdgcn.workitem.id.x()
35  %uni.cond = icmp slt i32 %a, 0
36  br label %G
37
38G:
39  br label %H
40
41H:
42  %uni.merge.h = phi i32 [ 0, %G ], [ %uni.inc, %H ]
43  %uni.inc = add i32 %uni.merge.h, 1
44  %div.exitx = icmp slt i32 %tid, 0
45  br i1 %div.exitx, label %X, label %H ; divergent branch
46; CHECK: DIVERGENT: %div.exitx =
47; CHECK: DIVERGENT: br i1 %div.exitx,
48
49X:
50  %div.user = add i32 %uni.inc, 5
51  br i1 %uni.cond, label %G, label %Y
52
53Y:
54  %div.alsouser = add i32 %uni.inc, 5
55  ret void
56}
57
58
59; temporal-uniform use of a valud, definition and users are carried by a surrounding divergent loop
60define amdgpu_kernel void @temporal_uniform_indivloop(i32 %n, i32 %a, i32 %b) #0 {
61; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'temporal_uniform_indivloop':
62; CHECK-NOT: DIVERGENT: %uni.
63; CHECK-NOT: DIVERGENT: br i1 %uni.
64
65entry:
66  %tid = call i32 @llvm.amdgcn.workitem.id.x()
67  %uni.cond = icmp slt i32 %a, 0
68  br label %G
69
70G:
71  br label %H
72
73H:
74  %uni.merge.h = phi i32 [ 0, %G ], [ %uni.inc, %H ]
75  %uni.inc = add i32 %uni.merge.h, 1
76  br i1 %uni.cond, label %X, label %H ; divergent branch
77
78X:
79  %uni.user = add i32 %uni.inc, 5
80  %div.exity = icmp slt i32 %tid, 0
81; CHECK: DIVERGENT: %div.exity =
82  br i1 %div.exity, label %G, label %Y
83; CHECK: DIVERGENT: br i1 %div.exity,
84
85Y:
86  %div.alsouser = add i32 %uni.inc, 5
87  ret void
88}
89
90
91; temporal-divergent use of value carried by divergent loop, user is inside sibling loop
92define amdgpu_kernel void @temporal_diverge_loopuser(i32 %n, i32 %a, i32 %b) #0 {
93; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'temporal_diverge_loopuser':
94; CHECK-NOT: DIVERGENT: %uni.
95; CHECK-NOT: DIVERGENT: br i1 %uni.
96
97entry:
98  %tid = call i32 @llvm.amdgcn.workitem.id.x()
99  %uni.cond = icmp slt i32 %a, 0
100  br label %H
101
102H:
103  %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc, %H ]
104  %uni.inc = add i32 %uni.merge.h, 1
105  %div.exitx = icmp slt i32 %tid, 0
106  br i1 %div.exitx, label %X, label %H ; divergent branch
107; CHECK: DIVERGENT: %div.exitx =
108; CHECK: DIVERGENT: br i1 %div.exitx,
109
110X:
111  br label %G
112
113G:
114  %div.user = add i32 %uni.inc, 5
115  br i1 %uni.cond, label %G, label %Y
116
117Y:
118  ret void
119}
120
121; temporal-divergent use of value carried by divergent loop, user is inside sibling loop, defs and use are carried by a uniform loop
122define amdgpu_kernel void @temporal_diverge_loopuser_nested(i32 %n, i32 %a, i32 %b) #0 {
123; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'temporal_diverge_loopuser_nested':
124; CHECK-NOT: DIVERGENT: %uni.
125; CHECK-NOT: DIVERGENT: br i1 %uni.
126
127entry:
128  %tid = call i32 @llvm.amdgcn.workitem.id.x()
129  %uni.cond = icmp slt i32 %a, 0
130  br label %H
131
132H:
133  %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc, %H ]
134  %uni.inc = add i32 %uni.merge.h, 1
135  %div.exitx = icmp slt i32 %tid, 0
136  br i1 %div.exitx, label %X, label %H ; divergent branch
137; CHECK: DIVERGENT: %div.exitx =
138; CHECK: DIVERGENT: br i1 %div.exitx,
139
140X:
141  br label %G
142
143G:
144  %div.user = add i32 %uni.inc, 5
145  br i1 %uni.cond, label %G, label %Y
146
147Y:
148  ret void
149}
150
151
152declare i32 @llvm.amdgcn.workitem.id.x() #0
153
154attributes #0 = { nounwind readnone }
155