1 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val %}
2 ; RUN: llc -mtriple=spirv-unknown-vulkan-compute -O0 %s -o - | FileCheck %s
4 ; The goal of this test is to voluntarily create 2 overlapping convergence
5 ; structures: the loop, and the inner condition.
6 ; Here, the condition header also branches to 2 internal nodes, which are not
7 ; directly a merge/exits.
8 ; This will require a proper header-split.
9 ; In addition, splitting the header makes the continue the merge of the inner
10 ; condition, so we need to properly split the continue block to create a
11 ; valid inner merge, in the correct order.
13 target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
14 target triple = "spirv-unknown-vulkan1.3-compute"
16 ; CHECK-DAG: OpName %[[#switch_0:]] "reg1"
17 ; CHECK-DAG: OpName %[[#variable:]] "var"
19 ; CHECK-DAG: %[[#int_0:]] = OpConstant %[[#]] 0
20 ; CHECK-DAG: %[[#int_1:]] = OpConstant %[[#]] 1
21 ; CHECK-DAG: %[[#int_2:]] = OpConstant %[[#]] 2
22 ; CHECK-DAG: %[[#int_3:]] = OpConstant %[[#]] 3
23 ; CHECK-DAG: %[[#int_4:]] = OpConstant %[[#]] 4
25 define internal spir_func void @main() #1 {
26 ; CHECK: %[[#entry:]] = OpLabel
27 ; CHECK: %[[#switch_0]] = OpVariable %[[#]] Function
28 ; CHECK: %[[#variable]] = OpVariable %[[#]] Function
29 ; CHECK: OpBranch %[[#header:]]
31 %0 = call token @llvm.experimental.convergence.entry()
32 %var = alloca i32, align 4
35 ; CHECK: %[[#header]] = OpLabel
36 ; CHECK: OpLoopMerge %[[#merge:]] %[[#continue:]] None
37 ; CHECK: OpBranch %[[#split_header:]]
39 ; CHECK: %[[#split_header]] = OpLabel
40 ; CHECK: OpSelectionMerge %[[#inner_merge:]] None
41 ; CHECK: OpBranchConditional %[[#]] %[[#left:]] %[[#right:]]
43 %2 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ]
44 br i1 true, label %left, label %right
46 ; CHECK: %[[#left]] = OpLabel
47 ; CHECK-DAG: OpStore %[[#switch_0]] %[[#int_0]]
48 ; CHECK-DAG: OpStore %[[#variable]] %[[#int_1]]
49 ; CHECK: OpBranchConditional %[[#]] %[[#inner_merge]] %[[#left_next:]]
52 br i1 true, label %merge, label %left_next
54 ; CHECK: %[[#right]] = OpLabel
55 ; CHECK-DAG: OpStore %[[#switch_0]] %[[#int_0]]
56 ; CHECK-DAG: OpStore %[[#variable]] %[[#int_2]]
57 ; CHECK: OpBranchConditional %[[#]] %[[#inner_merge]] %[[#right_next:]]
60 br i1 true, label %merge, label %right_next
62 ; CHECK: %[[#left_next]] = OpLabel
63 ; CHECK-DAG: OpStore %[[#switch_0]] %[[#int_1]]
64 ; CHECK-DAG: OpStore %[[#variable]] %[[#int_3]]
65 ; CHECK: OpBranch %[[#inner_merge]]
70 ; CHECK: %[[#right_next]] = OpLabel
71 ; CHECK-DAG: OpStore %[[#switch_0]] %[[#int_1]]
72 ; CHECK-DAG: OpStore %[[#variable]] %[[#int_4]]
73 ; CHECK: OpBranch %[[#inner_merge]]
78 ; CHECK: %[[#inner_merge]] = OpLabel
79 ; CHECK: %[[#tmp:]] = OpLoad %[[#]] %[[#switch_0]]
80 ; CHECK: %[[#cond:]] = OpIEqual %[[#]] %[[#int_0]] %[[#tmp]]
81 ; CHECK: OpBranchConditional %[[#cond]] %[[#merge]] %[[#continue]]
83 ; CHECK: %[[#continue]] = OpLabel
84 ; CHECK: OpBranch %[[#header]]
88 ; CHECK: %[[#merge]] = OpLabel
95 declare token @llvm.experimental.convergence.entry() #0
96 declare token @llvm.experimental.convergence.loop() #0
98 attributes #0 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
99 attributes #1 = { convergent noinline norecurse nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
101 !llvm.module.flags = !{!0, !1}
103 !0 = !{i32 1, !"wchar_size", i32 4}
104 !1 = !{i32 4, !"dx.disable_optimizations", i32 1}