File: reducible-headers.ll

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (225 lines) | stat: -rw-r--r-- 6,291 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
; RUN: opt %s -mtriple amdgcn-- -passes='print<uniformity>' -disable-output 2>&1 | FileCheck %s

;
;                         Entry
;                           |
;                           v
;                  -------->H---------
;                  |        |        |
;                  |        v        |
;                  |    --->T----    |
;                  |    |       |    |
;                  |    |       V    |
;                  S<---R       P <---
;                  ^    ^       |
;                  |    |  Div  |
;                  |    --- Q <--
;                  |        |
;                  |        v
;                  -------- U
;                           |
;                           v
;                          Exit
;
; The divergent branch is at Q that exits an irreducible cycle with
; entries T and P nested inside a reducible cycle with header H. R is
; assigned label R, which reaches P. S is a join node with label S. If
; this is propagated to P via H, then P is incorrectly recognized as a
; join, making the inner cycle divergent. P is always executed
; convergently -- either by threads that reconverged at header H, or
; by threads that are still executing the inner cycle. Thus, any PHI
; at P should not be marked divergent.

define amdgpu_kernel void @nested_irreducible(i32 %a, i32 %b, i32 %c) {
; CHECK=LABEL: UniformityInfo for function 'nested_irreducible':
; CHECK-NOT: CYCLES ASSSUMED DIVERGENT:
; CHECK: CYCLES WITH DIVERGENT EXIT:
; CHECK-DAG:   depth=2: entries(P T) R Q
; CHECK-DAG:   depth=1: entries(H) S P T R Q U
entry:
  %cond.uni = icmp slt i32 %a, 0
  %tid = call i32 @llvm.amdgcn.workitem.id.x()
  %cond.div = icmp slt i32 %tid, 0
  br label %H

H:
 br i1 %cond.uni, label %T, label %P

P:
; CHECK-LABEL: BLOCK P
; CHECK-NOT:   DIVERGENT:   %pp.phi =
; CHECK-NOT: DIVERGENT:      %pp =
  %pp.phi  = phi i32 [ %a, %H], [ %b, %T ]
  %pp = add i32 %b, 1
  br label %Q

Q:
; CHECK-LABEL: BLOCK Q
; CHECK-NOT: DIVERGENT:   %qq =
; CHECK-NOT:   DIVERGENT:   %qq.uni =
  %qq = add i32 %b, 1
  %qq.uni = add i32 %pp.phi, 1
  br i1 %cond.div, label %R, label %U

R:
  br i1 %cond.uni, label %S, label %T

T:
; CHECK-LABEL: BLOCK T
; CHECK-NOT:   DIVERGENT:   %tt.phi =
; CHECK-NOT: DIVERGENT:     %tt =
  %tt.phi = phi i32 [ %qq, %R ], [ %a, %H ]
  %tt = add i32 %b, 1
  br label %P

S:
; CHECK-LABEL: BLOCK S
; CHECK:   DIVERGENT:   %ss.phi =
; CHECK-NOT: DIVERGENT:     %ss =
  %ss.phi = phi i32 [ %qq.uni, %U ], [ %a, %R ]
  %ss = add i32 %b, 1
  br label %H

U:
  br i1 %cond.uni, label %S, label %exit

exit:
; CHECK: DIVERGENT:     %ee.div =
; CHECK-NOT: DIVERGENT:     %ee =
  %ee.div =  add i32 %qq.uni, 1
  %ee = add i32 %b, 1
  ret void
}

;
;                         Entry
;                           |
;                           v
;               -->-------->H---------
;               |  ^        |        |
;               |  |        |        |
;               |  |        |        |
;               |  |        |        |
;               |  |        v        V
;               |  R<-------T-->U--->P
;               |          Div       |
;               |                    |
;               ----------- Q <-------
;                           |
;                           v
;                          Exit
;
; This is a reducible cycle with a divergent branch at T. Disjoint
; paths eventually join at the header H, which is assigned label H.
; Node P is assigned label U. If the header label were propagated to
; P, it will be incorrectly recgonized as a join. P is always executed
; convergently -- either by threads that reconverged at header H, or
; by threads that diverged at T (and eventually reconverged at H).
; Thus, any PHI at P should not be marked divergent.

define amdgpu_kernel void @header_label_1(i32 %a, i32 %b, i32 %c) {
; CHECK=LABEL: UniformityInfo for function 'header_label_1':
; CHECK-NOT: CYCLES ASSSUMED DIVERGENT:
; CHECK: CYCLES WITH DIVERGENT EXIT:
; CHECK:  depth=1: entries(H) Q P U T R
entry:
  %cond.uni = icmp slt i32 %a, 0
  %tid = call i32 @llvm.amdgcn.workitem.id.x()
  %cond.div = icmp slt i32 %tid, 0
  br label %H

H:
  br i1 %cond.uni, label %T, label %P

P:
; CHECK-LABEL: BLOCK P
; CHECK-NOT:   DIVERGENT:   %pp.phi =
; CHECK-NOT: DIVERGENT:      %pp =
  %pp.phi  = phi i32 [ %a, %H], [ %b, %U ]
  %pp = add i32 %b, 1
  br label %Q

Q:
; CHECK-LABEL: BLOCK Q
; CHECK-NOT: DIVERGENT:   %qq =
; CHECK-NOT:   DIVERGENT:   %qq.uni =
  %qq = add i32 %b, 1
  %qq.uni = add i32 %pp.phi, 1
  br i1 %cond.uni, label %exit, label %H

R:
  br label %H

T:
  br i1 %cond.div, label %R, label %U

U:
  br label %P

exit:
; CHECK-LABEL: BLOCK exit
; CHECK: DIVERGENT:     %ee.div =
; CHECK-NOT: DIVERGENT:     %ee =
  %ee.div =  add i32 %qq.uni, 1
  %ee = add i32 %b, 1
  ret void
}

;        entry
;            |
;        --> H1
;        |   | \
;        |   | H2(div)
;        |   \ / \
;        |    B   C
;        ^     \ /
;        \------D
;               |
;               X
;
; This is a reducible cycle with a divergent branch at H2. Disjoint
; paths eventually join at the header D, which is assigned label D.
; Node B is assigned label B. If the header label D were propagated to
; B, it will be incorrectly recgonized as a join. B is always executed
; convergently -- either by threads that reconverged at header H1, or
; by threads that diverge at H2 (and eventually reconverged at H1).
; Thus, any PHI at B should not be marked divergent.

define amdgpu_kernel void @header_label_2(i32 %a, i32 %b, i32 %c) {
; CHECK-LABEL: UniformityInfo for function 'header_label_2':
; CHECK-NOT: CYCLES ASSSUMED DIVERGENT:
; CHECK-NOT: CYCLES WITH DIVERGENT EXIT:
entry:
  %cond.uni = icmp slt i32 %a, 0
  %tid = call i32 @llvm.amdgcn.workitem.id.x()
  %cond.div = icmp slt i32 %tid, 0
  br label %H1

H1:
  br i1 %cond.uni, label %B, label %H2

H2:
  br i1 %cond.div, label %B, label %C

B:
; CHECK-LABEL: BLOCK B
; CHECK-NOT: DIVERGENT:     %bb.phi =
  %bb.phi = phi i32 [%a, %H1], [%b, %H2]
  br label %D

C:
  br label %D

D:
; CHECK-LABEL: BLOCK D
; CHECK: DIVERGENT:     %dd.phi =
  %dd.phi = phi i32 [%a, %B], [%b, %C]
  br i1 %cond.uni, label %exit, label %H1

exit:
  %ee.1 = add i32 %dd.phi, 1
  %ee.2 = add i32 %b, 1
  ret void
}

declare i32 @llvm.amdgcn.workitem.id.x() #0