Debian Codegraph @

llvm-project/llvm/projects/llvm-spirv/test/transcoding/LoopUnroll.ll

raw
1 ; Source:
2 ; /*** for ***/
3 ; void for_count()
4 ; {
5 ; __attribute__((opencl_unroll_hint(1)))
6 ; for( int i = 0; i < 1024; ++i) {
7 ; if(i%2) continue;
8 ; int x = i;
9 ; }
10 ; }
11 ;
12 ; /*** while ***/
13 ; void while_count()
14 ; {
15 ; int i = 1024;
16 ; __attribute__((opencl_unroll_hint(8)))
17 ; while(i-->0) {
18 ; if(i%2) continue;
19 ; int x = i;
20 ; }
21 ; }
22 ;
23 ; /*** do ***/
24 ; void do_count()
25 ; {
26 ; int i = 1024;
27 ; __attribute__((opencl_unroll_hint))
28 ; do {
29 ; if(i%2) continue;
30 ; int x = i;
31 ; } while(i--> 0);
32 ; }
33 ;
34 ; for_count_unusual() is a synthetically written function
35 ;
36 ; Command:
37 ; clang -cc1 -triple spir64 -O0 LoopUnroll.cl -emit-llvm -o /test/SPIRV/transcoding/LoopUnroll.ll
38 ;
39 ; unroll_full() test was generated from the following source with -O2
40 ; void foo();
41 ;
42 ; void unroll_full() {
43 ; #pragma clang unroll(full)
44 ; for (int i = 0; i != 1024; ++i) {
45 ; foo();
46 ; }
47 ; }
48
49 ; RUN: llvm-as < %s > %t.bc
50 ; RUN: llvm-spirv %t.bc -o %t.spv
51 ; RUN: llvm-spirv -to-text %t.spv -o %t.spt
52 ; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
53 ; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc
54 ; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefixes=CHECK-LLVM
55 ; RUN: llvm-spirv %t.bc -o %t.spv --spirv-max-version=1.1
56 ; RUN: llvm-spirv -to-text %t.spv -o %t.spt
57 ; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV-NEGATIVE
58
59 ; Check SPIR-V versions in a format magic number + version
60 ; CHECK-SPIRV: 119734787 66560
61 ; CHECK-SPIRV-NEGATIVE: 119734787 65536
62
63 target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
64 target triple = "spir64"
65
66 ; CHECK-SPIRV: Function
67 ; Function Attrs: noinline nounwind optnone
68 define spir_func void @for_count() #0 {
69 entry:
70 ; CHECK-SPIRV: Label
71 %i = alloca i32, align 4
72 %x = alloca i32, align 4
73 store i32 0, i32* %i, align 4
74 br label %for.cond
75
76 for.cond: ; preds = %for.inc, %entry
77 ; CHECK-SPIRV: Label [[#HEADER:]]
78 %0 = load i32, i32* %i, align 4
79 %cmp = icmp slt i32 %0, 1024
80 ; Per SPIRV spec p3.23 "DontUnroll" loop control = 0x2
81 ; CHECK-SPIRV: LoopMerge [[#MERGEBLOCK:]] [[#CONTINUE:]] 2
82 ; CHECK-SPIRV: BranchConditional [[#]] [[#]] [[#MERGEBLOCK]]
83 br i1 %cmp, label %for.body, label %for.end
84
85 for.body: ; preds = %for.cond
86 ; CHECK-SPIRV: Label
87 %1 = load i32, i32* %i, align 4
88 %rem = srem i32 %1, 2
89 %tobool = icmp ne i32 %rem, 0
90 br i1 %tobool, label %if.then, label %if.end
91
92 if.then: ; preds = %for.body
93 ; CHECK-SPIRV: Label
94 br label %for.inc
95
96 if.end: ; preds = %for.body
97 ; CHECK-SPIRV: Label
98 %2 = load i32, i32* %i, align 4
99 store i32 %2, i32* %x, align 4
100 br label %for.inc
101
102 for.inc: ; preds = %if.end, %if.then
103 ; CHECK-SPIRV: Label [[#CONTINUE]]
104 %3 = load i32, i32* %i, align 4
105 %inc = add nsw i32 %3, 1
106 store i32 %inc, i32* %i, align 4
107 br label %for.cond, !llvm.loop !5
108 ; CHECK-LLVM: br label %for.cond, !llvm.loop ![[#UNROLLDISABLE:]]
109 ; CHECK-SPIRV: Branch [[#HEADER]]
110
111 for.end: ; preds = %for.cond
112 ; CHECK-SPIRV: Label [[#MERGEBLOCK]]
113 ret void
114 }
115
116 ; CHECK-SPIRV: Function
117 ; Function Attrs: noinline nounwind optnone
118 define spir_func void @while_count() #0 {
119 entry:
120 ; CHECK-SPIRV: Label
121 %i = alloca i32, align 4
122 %x = alloca i32, align 4
123 store i32 1024, i32* %i, align 4
124 br label %while.cond
125
126 while.cond: ; preds = %if.end, %if.then, %entry
127 ; CHECK-SPIRV: Label [[#HEADER:]]
128 %0 = load i32, i32* %i, align 4
129 %dec = add nsw i32 %0, -1
130 store i32 %dec, i32* %i, align 4
131 %cmp = icmp sgt i32 %0, 0
132 ; Per SPIRV spec p3.23 "Unroll" loop control = 0x1
133 ; CHECK-SPIRV: LoopMerge [[#MERGEBLOCK:]] [[#CONTINUE:]] 256 8
134 ; CHECK-SPIRV: BranchConditional [[#]] [[#]] [[#MERGEBLOCK]]
135 ; CHECK-SPIRV-NEGATIVE-NOT: LoopMerge {{.*}} 256
136 br i1 %cmp, label %while.body, label %while.end
137
138 while.body: ; preds = %while.cond
139 ; CHECK-SPIRV: Label
140 %1 = load i32, i32* %i, align 4
141 %rem = srem i32 %1, 2
142 %tobool = icmp ne i32 %rem, 0
143 br i1 %tobool, label %if.then, label %if.end
144
145 if.then: ; preds = %while.body
146 ; CHECK-SPIRV: Label
147 ; CHECK-LLVM: br label %while.cond, !llvm.loop ![[#UNROLLCOUNT:]]
148 br label %while.cond, !llvm.loop !7
149
150 ; loop-simplify pass will create extra basic block which is the only one in
151 ; loop having a back-edge to the header
152 ; CHECK-SPIRV: [[#CONTINUE]]
153 ; CHECK-SPIRV: Branch [[#HEADER]]
154
155 if.end: ; preds = %while.body
156 ; CHECK-SPIRV: Label
157 %2 = load i32, i32* %i, align 4
158 store i32 %2, i32* %x, align 4
159 br label %while.cond, !llvm.loop !7
160
161 while.end: ; preds = %while.cond
162 ; CHECK-SPIRV: [[#MERGEBLOCK]]
163 ret void
164 }
165
166 ; CHECK-SPIRV: Function
167 ; Function Attrs: noinline nounwind optnone
168 define spir_func void @do_count() #0 {
169 entry:
170 ; CHECK-SPIRV: Label
171 %i = alloca i32, align 4
172 %x = alloca i32, align 4
173 store i32 1024, i32* %i, align 4
174 br label %do.body
175
176 do.body: ; preds = %do.cond, %entry
177 ; CHECK-SPIRV: Label [[#HEADER:]]
178 %0 = load i32, i32* %i, align 4
179 %rem = srem i32 %0, 2
180 %tobool = icmp ne i32 %rem, 0
181 ; Per SPIRV spec p3.23 "Unroll" loop control = 0x1
182 ; CHECK-SPIRV: LoopMerge [[#MERGEBLOCK:]] [[#CONTINUE:]] 1
183 ; CHECK-SPIRV: BranchConditional
184 br i1 %tobool, label %if.then, label %if.end
185
186 if.then: ; preds = %do.body
187 ; CHECK-SPIRV: Label
188 br label %do.cond
189
190 if.end: ; preds = %do.body
191 ; CHECK-SPIRV: Label
192 %1 = load i32, i32* %i, align 4
193 store i32 %1, i32* %x, align 4
194 br label %do.cond
195
196 do.cond: ; preds = %if.end, %if.then
197 ; CHECK-SPIRV: Label [[#CONTINUE]]
198 %2 = load i32, i32* %i, align 4
199 %dec = add nsw i32 %2, -1
200 store i32 %dec, i32* %i, align 4
201 %cmp = icmp sgt i32 %2, 0
202 ; CHECK-SPIRV: BranchConditional [[#]] [[#HEADER]] [[#MERGEBLOCK]]
203 ; CHECK-LLVM: br i1 %cmp, label %do.body, label %do.end, !llvm.loop ![[#UNROLLENABLE1:]]
204 br i1 %cmp, label %do.body, label %do.end, !llvm.loop !9
205
206 do.end: ; preds = %do.cond
207 ; CHECK-SPIRV: Label [[#MERGEBLOCK]]
208 ret void
209 }
210
211 ; CHECK-SPIRV: Function
212 ; Function Attrs: noinline nounwind optnone
213 define spir_func void @for_count_unusual() #0 {
214 entry:
215 ; CHECK-SPIRV: Label
216 %i = alloca i32, align 4
217 %x = alloca i32, align 4
218 store i32 1024, i32* %i, align 4
219 br label %for.body
220
221 for.body: ; preds = %for.cond, %entry
222 ; CHECK-SPIRV: Label [[#HEADER:]]
223 %0 = load i32, i32* %i, align 4
224 %rem = srem i32 %0, 2
225 %tobool = icmp ne i32 %rem, 0
226 ; Per SPIRV spec p3.23 "Unroll" loop control = 0x1
227 ; CHECK-SPIRV: LoopMerge [[#MERGEBLOCK:]] [[#CONTINUE:]] 1
228 ; CHECK-SPIRV: BranchConditional
229 br i1 %tobool, label %if.then, label %if.end
230
231 if.then: ; preds = %for.body
232 ; CHECK-SPIRV: Label
233 br label %for.cond
234
235 if.end: ; preds = %for.body
236 ; CHECK-SPIRV: Label
237 %1 = load i32, i32* %i, align 4
238 store i32 %1, i32* %x, align 4
239 br label %for.cond
240
241 for.cond: ; preds = %if.end, %if.then
242 ; CHECK-SPIRV: Label [[#CONTINUE]]
243 %2 = load i32, i32* %i, align 4
244 %dec = add nsw i32 %2, -1
245 store i32 %dec, i32* %i, align 4
246 %cmp = icmp sgt i32 %2, 0
247 ; CHECK-SPIRV: BranchConditional [[#]] [[#MERGEBLOCK]] [[#HEADER]]
248 ; CHECK-LLVM: br i1 %cmp, label %for.end, label %for.body, !llvm.loop ![[#UNROLLENABLE2:]]
249 br i1 %cmp, label %for.end, label %for.body, !llvm.loop !9
250
251 for.end: ; preds = %for.cond
252 ; CHECK-SPIRV: Label [[#MERGEBLOCK]]
253 ret void
254 }
255
256 ; CHECK-SPIRV: Function
257 ; CHECK-SPIRV: Label
258 ; CHECK-SPIRV: Branch [[#Header:]]
259 ; CHECK-SPIRV: LoopMerge [[#Return:]] [[#Header]] 257 1
260 ; CHECK-SPIRV: BranchConditional [[#]] [[#Return]] [[#Header]]
261 ; CHECK-SPIRV: Label [[#Return]]
262 ; Function Attrs: noinline nounwind optnone
263 define spir_func void @unroll_full() {
264 br label %2
265
266 1: ; preds = %2
267 ret void
268
269 2: ; preds = %0, %2
270 %3 = phi i32 [ 0, %0 ], [ %4, %2 ]
271 tail call void @_Z3foov()
272 %4 = add nuw nsw i32 %3, 1
273 %5 = icmp eq i32 %4, 1024
274 ; CHECK-LLVM: br i1 %[[#]], label %[[#]], label %[[#]], !llvm.loop ![[#FULL:]]
275 br i1 %5, label %1, label %2, !llvm.loop !11
276 }
277
278 declare void @_Z3foov()
279
280 attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
281
282 !llvm.module.flags = !{!0}
283 !opencl.enable.FP_CONTRACT = !{}
284 !opencl.ocl.version = !{!1}
285 !opencl.spir.version = !{!2}
286 !opencl.used.extensions = !{!3}
287 !opencl.used.optional.core.features = !{!3}
288 !opencl.compiler.options = !{!3}
289 !llvm.ident = !{!4}
290
291 !0 = !{i32 1, !"wchar_size", i32 4}
292 !1 = !{i32 1, i32 0}
293 !2 = !{i32 1, i32 2}
294 !3 = !{}
295 !4 = !{!"clang version 5.0.1 (cfe/trunk)"}
296 !5 = distinct !{!5, !6}
297 !6 = !{!"llvm.loop.unroll.disable"}
298 !7 = distinct !{!7, !8}
299 !8 = !{!"llvm.loop.unroll.count", i32 8}
300 !9 = distinct !{!9, !10}
301 !10 = !{!"llvm.loop.unroll.enable"}
302 !11 = distinct !{!11, !12}
303 !12 = !{!"llvm.loop.unroll.full"}
304
305 ; CHECK-LLVM: ![[#UNROLLDISABLE]] = distinct !{![[#UNROLLDISABLE]], ![[#DISABLE:]]}
306 ; CHECK-LLVM: ![[#DISABLE]] = !{!"llvm.loop.unroll.disable"}
307 ; CHECK-LLVM: ![[#UNROLLCOUNT]] = distinct !{![[#UNROLLCOUNT]], ![[#COUNT:]]}
308 ; CHECK-LLVM: ![[#COUNT]] = !{!"llvm.loop.unroll.count", i32 8}
309 ; CHECK-LLVM: ![[#UNROLLENABLE1]] = distinct !{![[#UNROLLENABLE1]], ![[#ENABLE:]]}
310 ; CHECK-LLVM: ![[#ENABLE]] = !{!"llvm.loop.unroll.enable"}
311 ; CHECK-LLVM: ![[#UNROLLENABLE2]] = distinct !{![[#UNROLLENABLE2]], ![[#ENABLE]]}
312 ; CHECK-LLVM: ![[#FULL]] = distinct !{![[#FULL]], ![[#UNROLLFULL:]]}
313 ; CHECK-LLVM: ![[#UNROLLFULL]] = !{!"llvm.loop.unroll.full"}