1 ; RUN: llc -mtriple=spirv-unknown-vulkan-compute -O0 %s -o - | FileCheck %s
2 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val %}
5 ; int foo() { return 200; }
13 ; const int t = 3*r+2*s;
16 ; ////////////////////////////////////////
17 ; // DefaultStmt is the first statement //
18 ; ////////////////////////////////////////
30 ; //////////////////////////////////////////////
31 ; // DefaultStmt in the middle of other cases //
32 ; //////////////////////////////////////////////
43 ; ///////////////////////////////////////////////
44 ; // Various CaseStmt and BreakStmt topologies //
45 ; // DefaultStmt is the last statement //
46 ; ///////////////////////////////////////////////
73 ; //////////////////////////
74 ; // No Default statement //
75 ; //////////////////////////
83 ; /////////////////////////////////////////////////////////
84 ; // No cases. Only a default //
85 ; // This means the default body will always be executed //
86 ; /////////////////////////////////////////////////////////
95 ; ////////////////////////////////////////////////////////////
96 ; // Nested Switch with branching //
97 ; // The two inner switch statements should be executed for //
98 ; // both cases of the outer switch (case 300 and case 400) //
99 ; ////////////////////////////////////////////////////////////
120 ; [numthreads(1, 1, 1)]
125 ; CHECK: %[[#func_22:]] = OpFunction %[[#uint:]] DontInline %[[#]]
126 ; CHECK: %[[#bb94:]] = OpLabel
127 ; CHECK: OpReturnValue %[[#]]
128 ; CHECK: OpFunctionEnd
129 ; CHECK: %[[#func_23:]] = OpFunction %[[#uint:]] DontInline %[[#]]
130 ; CHECK: %[[#bb95:]] = OpLabel
131 ; CHECK: OpSelectionMerge %[[#bb96:]] None
132 ; CHECK: OpBranchConditional %[[#]] %[[#bb97:]] %[[#bb98:]]
133 ; CHECK: %[[#bb97:]] = OpLabel
134 ; CHECK: OpSelectionMerge %[[#bb99:]] None
135 ; CHECK: OpSwitch %[[#]] %[[#bb100:]] 1 %[[#bb99:]] 2 %[[#bb101:]]
136 ; CHECK: %[[#bb98:]] = OpLabel
137 ; CHECK: %[[#bb100:]] = OpLabel
138 ; CHECK: OpBranch %[[#bb99:]]
139 ; CHECK: %[[#bb101:]] = OpLabel
140 ; CHECK: OpBranch %[[#bb99:]]
141 ; CHECK: %[[#bb99:]] = OpLabel
142 ; CHECK: OpBranchConditional %[[#]] %[[#bb102:]] %[[#bb96:]]
143 ; CHECK: %[[#bb102:]] = OpLabel
144 ; CHECK: OpBranch %[[#bb96:]]
145 ; CHECK: %[[#bb96:]] = OpLabel
146 ; CHECK: OpSelectionMerge %[[#bb103:]] None
147 ; CHECK: OpBranchConditional %[[#]] %[[#bb104:]] %[[#bb105:]]
148 ; CHECK: %[[#bb104:]] = OpLabel
149 ; CHECK: OpSelectionMerge %[[#bb106:]] None
150 ; CHECK: OpSwitch %[[#]] %[[#bb106:]] 10 %[[#bb107:]] 20 %[[#bb108:]]
151 ; CHECK: %[[#bb105:]] = OpLabel
152 ; CHECK: %[[#bb107:]] = OpLabel
153 ; CHECK: OpBranch %[[#bb106:]]
154 ; CHECK: %[[#bb108:]] = OpLabel
155 ; CHECK: OpBranch %[[#bb106:]]
156 ; CHECK: %[[#bb106:]] = OpLabel
157 ; CHECK: OpBranchConditional %[[#]] %[[#bb109:]] %[[#bb103:]]
158 ; CHECK: %[[#bb109:]] = OpLabel
159 ; CHECK: OpBranch %[[#bb103:]]
160 ; CHECK: %[[#bb103:]] = OpLabel
161 ; CHECK: OpBranch %[[#bb110:]]
162 ; CHECK: %[[#bb110:]] = OpLabel
163 ; CHECK: OpSelectionMerge %[[#bb111:]] None
164 ; CHECK: OpBranchConditional %[[#]] %[[#bb112:]] %[[#bb113:]]
165 ; CHECK: %[[#bb112:]] = OpLabel
166 ; CHECK: OpSelectionMerge %[[#bb114:]] None
167 ; CHECK: OpBranchConditional %[[#]] %[[#bb115:]] %[[#bb116:]]
168 ; CHECK: %[[#bb113:]] = OpLabel
169 ; CHECK: %[[#bb115:]] = OpLabel
170 ; CHECK: OpSelectionMerge %[[#bb117:]] None
171 ; CHECK: OpBranchConditional %[[#]] %[[#bb118:]] %[[#bb119:]]
172 ; CHECK: %[[#bb116:]] = OpLabel
173 ; CHECK: %[[#bb118:]] = OpLabel
174 ; CHECK: OpSelectionMerge %[[#bb120:]] None
175 ; CHECK: OpSwitch %[[#]] %[[#bb121:]] 1 %[[#bb122:]] 2 %[[#bb120:]] 3 %[[#bb123:]] 140 %[[#bb124:]] 4 %[[#bb125:]] 5 %[[#bb126:]] 6 %[[#bb127:]] 7 %[[#bb128:]]
176 ; CHECK: %[[#bb119:]] = OpLabel
177 ; CHECK: %[[#bb121:]] = OpLabel
178 ; CHECK: OpBranch %[[#bb120:]]
179 ; CHECK: %[[#bb122:]] = OpLabel
180 ; CHECK: OpBranch %[[#bb120:]]
181 ; CHECK: %[[#bb123:]] = OpLabel
182 ; CHECK: OpBranch %[[#bb120:]]
183 ; CHECK: %[[#bb124:]] = OpLabel
184 ; CHECK: OpBranch %[[#bb120:]]
185 ; CHECK: %[[#bb125:]] = OpLabel
186 ; CHECK: OpBranch %[[#bb120:]]
187 ; CHECK: %[[#bb126:]] = OpLabel
188 ; CHECK: OpBranch %[[#bb120:]]
189 ; CHECK: %[[#bb127:]] = OpLabel
190 ; CHECK: OpBranch %[[#bb120:]]
191 ; CHECK: %[[#bb128:]] = OpLabel
192 ; CHECK: OpBranch %[[#bb120:]]
193 ; CHECK: %[[#bb120:]] = OpLabel
194 ; CHECK: OpSelectionMerge %[[#bb129:]] None
195 ; CHECK: OpSwitch %[[#]] %[[#bb130:]] 1 %[[#bb129:]] 2 %[[#bb131:]] 3 %[[#bb132:]]
196 ; CHECK: %[[#bb130:]] = OpLabel
197 ; CHECK: OpBranch %[[#bb129:]]
198 ; CHECK: %[[#bb131:]] = OpLabel
199 ; CHECK: OpBranch %[[#bb129:]]
200 ; CHECK: %[[#bb132:]] = OpLabel
201 ; CHECK: OpBranch %[[#bb129:]]
202 ; CHECK: %[[#bb129:]] = OpLabel
203 ; CHECK: OpBranch %[[#bb117:]]
204 ; CHECK: %[[#bb117:]] = OpLabel
205 ; CHECK: OpSelectionMerge %[[#bb133:]] None
206 ; CHECK: OpSwitch %[[#]] %[[#bb134:]] 1 %[[#bb133:]] 2 %[[#bb135:]]
207 ; CHECK: %[[#bb134:]] = OpLabel
208 ; CHECK: OpBranch %[[#bb133:]]
209 ; CHECK: %[[#bb135:]] = OpLabel
210 ; CHECK: OpBranch %[[#bb133:]]
211 ; CHECK: %[[#bb133:]] = OpLabel
212 ; CHECK: OpBranch %[[#bb114:]]
213 ; CHECK: %[[#bb114:]] = OpLabel
214 ; CHECK: OpBranch %[[#bb111:]]
215 ; CHECK: %[[#bb111:]] = OpLabel
216 ; CHECK: OpSelectionMerge %[[#bb136:]] None
217 ; CHECK: OpBranchConditional %[[#]] %[[#bb137:]] %[[#bb136:]]
218 ; CHECK: %[[#bb137:]] = OpLabel
219 ; CHECK: OpBranch %[[#bb136:]]
220 ; CHECK: %[[#bb136:]] = OpLabel
221 ; CHECK: OpBranch %[[#bb138:]]
222 ; CHECK: %[[#bb138:]] = OpLabel
223 ; CHECK: OpBranch %[[#bb139:]]
224 ; CHECK: %[[#bb139:]] = OpLabel
225 ; CHECK: OpSelectionMerge %[[#bb140:]] None
226 ; CHECK: OpBranchConditional %[[#]] %[[#bb141:]] %[[#bb142:]]
227 ; CHECK: %[[#bb141:]] = OpLabel
228 ; CHECK: OpSelectionMerge %[[#bb143:]] None
229 ; CHECK: OpSwitch %[[#]] %[[#bb143:]] 300 %[[#bb144:]] 400 %[[#bb145:]]
230 ; CHECK: %[[#bb142:]] = OpLabel
231 ; CHECK: %[[#bb144:]] = OpLabel
232 ; CHECK: OpBranch %[[#bb143:]]
233 ; CHECK: %[[#bb145:]] = OpLabel
234 ; CHECK: OpBranch %[[#bb143:]]
235 ; CHECK: %[[#bb143:]] = OpLabel
236 ; CHECK: OpBranchConditional %[[#]] %[[#bb140:]] %[[#bb146:]]
237 ; CHECK: %[[#bb146:]] = OpLabel
238 ; CHECK: OpSelectionMerge %[[#bb147:]] None
239 ; CHECK: OpSwitch %[[#]] %[[#bb147:]] 500 %[[#bb148:]] 600 %[[#bb149:]]
240 ; CHECK: %[[#bb148:]] = OpLabel
241 ; CHECK: OpBranch %[[#bb147:]]
242 ; CHECK: %[[#bb149:]] = OpLabel
243 ; CHECK: OpBranch %[[#bb150:]]
244 ; CHECK: %[[#bb150:]] = OpLabel
245 ; CHECK: OpBranch %[[#bb147:]]
246 ; CHECK: %[[#bb147:]] = OpLabel
247 ; CHECK: OpBranch %[[#bb140:]]
248 ; CHECK: %[[#bb140:]] = OpLabel
249 ; CHECK: OpReturnValue %[[#]]
250 ; CHECK: OpFunctionEnd
251 ; CHECK: %[[#func_90:]] = OpFunction %[[#void:]] DontInline %[[#]]
252 ; CHECK: %[[#bb151:]] = OpLabel
254 ; CHECK: OpFunctionEnd
255 ; CHECK: %[[#func_92:]] = OpFunction %[[#void:]] None %[[#]]
256 ; CHECK: %[[#bb152:]] = OpLabel
258 ; CHECK: OpFunctionEnd
262 target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
263 target triple = "spirv-unknown-vulkan1.3-compute"
265 ; Function Attrs: convergent noinline norecurse nounwind optnone
266 define spir_func noundef i32 @_Z3foov() #0 {
268 %0 = call token @llvm.experimental.convergence.entry()
272 ; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)
273 declare token @llvm.experimental.convergence.entry() #1
275 ; Function Attrs: convergent noinline norecurse nounwind optnone
276 define spir_func noundef i32 @_Z7processv() #0 {
278 %0 = call token @llvm.experimental.convergence.entry()
279 %a = alloca i32, align 4
280 %b = alloca i32, align 4
281 %c = alloca i32, align 4
282 %r = alloca i32, align 4
283 %s = alloca i32, align 4
284 %t = alloca i32, align 4
285 %d = alloca i32, align 4
286 store i32 0, ptr %a, align 4
287 store i32 0, ptr %b, align 4
288 store i32 0, ptr %c, align 4
289 store i32 20, ptr %r, align 4
290 store i32 40, ptr %s, align 4
291 store i32 140, ptr %t, align 4
292 %1 = load i32, ptr %a, align 4
293 switch i32 %1, label %sw.default [
298 sw.default: ; preds = %entry
299 %2 = load i32, ptr %b, align 4
300 %add = add nsw i32 %2, 0
301 store i32 %add, ptr %b, align 4
304 sw.bb: ; preds = %entry, %sw.default
305 %3 = load i32, ptr %b, align 4
306 %add1 = add nsw i32 %3, 1
307 store i32 %add1, ptr %b, align 4
310 sw.bb2: ; preds = %entry
311 %4 = load i32, ptr %b, align 4
312 %add3 = add nsw i32 %4, 2
313 store i32 %add3, ptr %b, align 4
316 sw.epilog: ; preds = %sw.bb2, %sw.bb
317 %5 = load i32, ptr %a, align 4
318 switch i32 %5, label %sw.default6 [
319 i32 10, label %sw.bb4
320 i32 20, label %sw.bb8
323 sw.bb4: ; preds = %sw.epilog
324 %6 = load i32, ptr %b, align 4
325 %add5 = add nsw i32 %6, 1
326 store i32 %add5, ptr %b, align 4
327 br label %sw.default6
329 sw.default6: ; preds = %sw.epilog, %sw.bb4
330 %7 = load i32, ptr %b, align 4
331 %add7 = add nsw i32 %7, 0
332 store i32 %add7, ptr %b, align 4
335 sw.bb8: ; preds = %sw.epilog, %sw.default6
336 %8 = load i32, ptr %b, align 4
337 %add9 = add nsw i32 %8, 2
338 store i32 %add9, ptr %b, align 4
339 br label %sw.epilog10
341 sw.epilog10: ; preds = %sw.bb8
342 store i32 5, ptr %d, align 4
343 %9 = load i32, ptr %d, align 4
344 switch i32 %9, label %sw.default25 [
345 i32 1, label %sw.bb11
346 i32 2, label %sw.bb15
347 i32 3, label %sw.bb17
348 i32 140, label %sw.bb19
349 i32 4, label %sw.bb21
350 i32 5, label %sw.bb21
351 i32 6, label %sw.bb23
352 i32 7, label %sw.bb24
355 sw.bb11: ; preds = %sw.epilog10
356 %10 = load i32, ptr %b, align 4
357 %add12 = add nsw i32 %10, 1
358 store i32 %add12, ptr %b, align 4
359 %call13 = call spir_func noundef i32 @_Z3foov() #3 [ "convergencectrl"(token %0) ]
360 %11 = load i32, ptr %c, align 4
361 %add14 = add nsw i32 %11, %call13
362 store i32 %add14, ptr %c, align 4
365 sw.bb15: ; preds = %sw.epilog10, %sw.bb11
366 %12 = load i32, ptr %b, align 4
367 %add16 = add nsw i32 %12, 2
368 store i32 %add16, ptr %b, align 4
369 br label %sw.epilog26
371 sw.bb17: ; preds = %sw.epilog10
372 %13 = load i32, ptr %b, align 4
373 %add18 = add nsw i32 %13, 3
374 store i32 %add18, ptr %b, align 4
375 br label %sw.epilog26
377 sw.bb19: ; preds = %sw.epilog10
378 %14 = load i32, ptr %b, align 4
379 %add20 = add nsw i32 %14, 140
380 store i32 %add20, ptr %b, align 4
383 sw.bb21: ; preds = %sw.epilog10, %sw.epilog10, %sw.bb19
384 %15 = load i32, ptr %b, align 4
385 %add22 = add nsw i32 %15, 5
386 store i32 %add22, ptr %b, align 4
387 br label %sw.epilog26
389 sw.bb23: ; preds = %sw.epilog10
392 sw.bb24: ; preds = %sw.epilog10, %sw.bb23
393 br label %sw.epilog26
395 sw.default25: ; preds = %sw.epilog10
396 br label %sw.epilog26
398 sw.epilog26: ; preds = %sw.default25, %sw.bb24, %sw.bb21, %sw.bb17, %sw.bb15
399 %16 = load i32, ptr %a, align 4
400 switch i32 %16, label %sw.epilog29 [
401 i32 100, label %sw.bb27
404 sw.bb27: ; preds = %sw.epilog26
405 %17 = load i32, ptr %b, align 4
406 %add28 = add nsw i32 %17, 100
407 store i32 %add28, ptr %b, align 4
408 br label %sw.epilog29
410 sw.epilog29: ; preds = %sw.epilog26, %sw.bb27
411 %18 = load i32, ptr %a, align 4
412 switch i32 %18, label %sw.default30 [
415 sw.default30: ; preds = %sw.epilog29
416 %19 = load i32, ptr %b, align 4
417 %add31 = add nsw i32 %19, 100
418 store i32 %add31, ptr %b, align 4
419 %20 = load i32, ptr %c, align 4
420 %add32 = add nsw i32 %20, 200
421 store i32 %add32, ptr %c, align 4
422 br label %sw.epilog33
424 sw.epilog33: ; preds = %sw.default30
425 %21 = load i32, ptr %a, align 4
426 switch i32 %21, label %sw.epilog45 [
427 i32 300, label %sw.bb34
428 i32 400, label %sw.bb36
431 sw.bb34: ; preds = %sw.epilog33
432 %22 = load i32, ptr %b, align 4
433 %add35 = add nsw i32 %22, 300
434 store i32 %add35, ptr %b, align 4
437 sw.bb36: ; preds = %sw.epilog33, %sw.bb34
438 %23 = load i32, ptr %c, align 4
439 switch i32 %23, label %sw.epilog44 [
440 i32 500, label %sw.bb37
441 i32 600, label %sw.bb39
444 sw.bb37: ; preds = %sw.bb36
445 %24 = load i32, ptr %b, align 4
446 %add38 = add nsw i32 %24, 500
447 store i32 %add38, ptr %b, align 4
448 br label %sw.epilog44
450 sw.bb39: ; preds = %sw.bb36
451 %25 = load i32, ptr %b, align 4
452 switch i32 %25, label %sw.default40 [
455 sw.default40: ; preds = %sw.bb39
456 %26 = load i32, ptr %a, align 4
457 %add41 = add nsw i32 %26, 600
458 store i32 %add41, ptr %a, align 4
459 %27 = load i32, ptr %b, align 4
460 %add42 = add nsw i32 %27, 600
461 store i32 %add42, ptr %b, align 4
462 br label %sw.epilog43
464 sw.epilog43: ; preds = %sw.default40
465 br label %sw.epilog44
467 sw.epilog44: ; preds = %sw.epilog43, %sw.bb36, %sw.bb37
468 br label %sw.epilog45
470 sw.epilog45: ; preds = %sw.epilog44, %sw.epilog33
471 %28 = load i32, ptr %a, align 4
472 %29 = load i32, ptr %b, align 4
473 %add46 = add nsw i32 %28, %29
474 %30 = load i32, ptr %c, align 4
475 %add47 = add nsw i32 %add46, %30
479 ; Function Attrs: convergent noinline norecurse nounwind optnone
480 define internal spir_func void @main() #0 {
482 %0 = call token @llvm.experimental.convergence.entry()
483 %call1 = call spir_func noundef i32 @_Z7processv() #3 [ "convergencectrl"(token %0) ]
487 ; Function Attrs: convergent norecurse
488 define void @main.1() #2 {
494 attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
495 attributes #1 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
496 attributes #2 = { convergent norecurse "frame-pointer"="all" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
497 attributes #3 = { convergent }
499 !llvm.module.flags = !{!0, !1, !2}
502 !0 = !{i32 1, !"wchar_size", i32 4}
503 !1 = !{i32 4, !"dx.disable_optimizations", i32 1}
504 !2 = !{i32 7, !"frame-pointer", i32 2}