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 %}
14 ; // for-stmt following if-stmt
15 ; for (int i = 0; i < 10; ++i) {
16 ; if (color < 0) { // if-stmt nested in for-stmt
18 ; for (int j = 0; j < 15; ++j) { // for-stmt deeply nested in if-then
24 ; if (color < 1) { // if-stmt following if-stmt
27 ; for (int k = 0; k < 20; ++k) { // for-stmt deeply nested in if-else
29 ; if (val < 0) { // deeply nested if-stmt
36 ; // if-stmt following for-stmt
44 ; [numthreads(1, 1, 1)]
49 ; CHECK: %[[#func_18:]] = OpFunction %[[#uint:]] DontInline %[[#]]
50 ; CHECK: %[[#bb65:]] = OpLabel
51 ; CHECK: OpSelectionMerge %[[#bb66:]] None
52 ; CHECK: OpBranchConditional %[[#]] %[[#bb67:]] %[[#bb66:]]
53 ; CHECK: %[[#bb67:]] = OpLabel
54 ; CHECK: OpBranch %[[#bb66:]]
55 ; CHECK: %[[#bb66:]] = OpLabel
56 ; CHECK: OpBranch %[[#bb68:]]
57 ; CHECK: %[[#bb68:]] = OpLabel
58 ; CHECK: OpLoopMerge %[[#bb69:]] %[[#bb70:]] None
59 ; CHECK: OpBranchConditional %[[#]] %[[#bb71:]] %[[#bb69:]]
60 ; CHECK: %[[#bb71:]] = OpLabel
61 ; CHECK: OpSelectionMerge %[[#bb72:]] None
62 ; CHECK: OpBranchConditional %[[#]] %[[#bb73:]] %[[#bb72:]]
63 ; CHECK: %[[#bb73:]] = OpLabel
64 ; CHECK: OpBranch %[[#bb74:]]
65 ; CHECK: %[[#bb74:]] = OpLabel
66 ; CHECK: OpLoopMerge %[[#bb75:]] %[[#bb76:]] None
67 ; CHECK: OpBranchConditional %[[#]] %[[#bb77:]] %[[#bb75:]]
68 ; CHECK: %[[#bb77:]] = OpLabel
69 ; CHECK: OpBranch %[[#bb76:]]
70 ; CHECK: %[[#bb76:]] = OpLabel
71 ; CHECK: OpBranch %[[#bb74:]]
72 ; CHECK: %[[#bb75:]] = OpLabel
73 ; CHECK: OpBranch %[[#bb72:]]
74 ; CHECK: %[[#bb72:]] = OpLabel
75 ; CHECK: OpSelectionMerge %[[#bb78:]] None
76 ; CHECK: OpBranchConditional %[[#]] %[[#bb79:]] %[[#bb80:]]
77 ; CHECK: %[[#bb79:]] = OpLabel
78 ; CHECK: OpBranch %[[#bb78:]]
79 ; CHECK: %[[#bb80:]] = OpLabel
80 ; CHECK: OpBranch %[[#bb81:]]
81 ; CHECK: %[[#bb81:]] = OpLabel
82 ; CHECK: OpLoopMerge %[[#bb82:]] %[[#bb83:]] None
83 ; CHECK: OpBranchConditional %[[#]] %[[#bb84:]] %[[#bb82:]]
84 ; CHECK: %[[#bb84:]] = OpLabel
85 ; CHECK: OpSelectionMerge %[[#bb85:]] None
86 ; CHECK: OpBranchConditional %[[#]] %[[#bb86:]] %[[#bb85:]]
87 ; CHECK: %[[#bb86:]] = OpLabel
88 ; CHECK: OpBranch %[[#bb85:]]
89 ; CHECK: %[[#bb85:]] = OpLabel
90 ; CHECK: OpBranch %[[#bb83:]]
91 ; CHECK: %[[#bb83:]] = OpLabel
92 ; CHECK: OpBranch %[[#bb81:]]
93 ; CHECK: %[[#bb82:]] = OpLabel
94 ; CHECK: OpBranch %[[#bb78:]]
95 ; CHECK: %[[#bb78:]] = OpLabel
96 ; CHECK: OpBranch %[[#bb70:]]
97 ; CHECK: %[[#bb70:]] = OpLabel
98 ; CHECK: OpBranch %[[#bb68:]]
99 ; CHECK: %[[#bb69:]] = OpLabel
100 ; CHECK: OpSelectionMerge %[[#bb87:]] None
101 ; CHECK: OpBranchConditional %[[#]] %[[#bb88:]] %[[#bb87:]]
102 ; CHECK: %[[#bb88:]] = OpLabel
103 ; CHECK: OpBranch %[[#bb87:]]
104 ; CHECK: %[[#bb87:]] = OpLabel
105 ; CHECK: OpReturnValue %[[#]]
106 ; CHECK: OpFunctionEnd
107 ; CHECK: %[[#func_61:]] = OpFunction %[[#void:]] DontInline %[[#]]
108 ; CHECK: %[[#bb89:]] = OpLabel
110 ; CHECK: OpFunctionEnd
111 ; CHECK: %[[#func_63:]] = OpFunction %[[#void:]] None %[[#]]
112 ; CHECK: %[[#bb90:]] = OpLabel
114 ; CHECK: OpFunctionEnd
118 target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
119 target triple = "spirv-unknown-vulkan1.3-compute"
121 ; Function Attrs: convergent noinline norecurse nounwind optnone
122 define spir_func noundef i32 @_Z7processv() #0 {
124 %0 = call token @llvm.experimental.convergence.entry()
125 %color = alloca i32, align 4
126 %val = alloca i32, align 4
127 %i = alloca i32, align 4
128 %j = alloca i32, align 4
129 %k = alloca i32, align 4
130 store i32 0, ptr %color, align 4
131 store i32 0, ptr %val, align 4
132 %1 = load i32, ptr %color, align 4
133 %cmp = icmp slt i32 %1, 0
134 br i1 %cmp, label %if.then, label %if.end
136 if.then: ; preds = %entry
137 store i32 1, ptr %val, align 4
140 if.end: ; preds = %if.then, %entry
141 store i32 0, ptr %i, align 4
144 for.cond: ; preds = %for.inc23, %if.end
145 %2 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ]
146 %3 = load i32, ptr %i, align 4
147 %cmp1 = icmp slt i32 %3, 10
148 br i1 %cmp1, label %for.body, label %for.end25
150 for.body: ; preds = %for.cond
151 %4 = load i32, ptr %color, align 4
152 %cmp2 = icmp slt i32 %4, 0
153 br i1 %cmp2, label %if.then3, label %if.end8
155 if.then3: ; preds = %for.body
156 %5 = load i32, ptr %val, align 4
157 %add = add nsw i32 %5, 1
158 store i32 %add, ptr %val, align 4
159 store i32 0, ptr %j, align 4
162 for.cond4: ; preds = %for.inc, %if.then3
163 %6 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %2) ]
164 %7 = load i32, ptr %j, align 4
165 %cmp5 = icmp slt i32 %7, 15
166 br i1 %cmp5, label %for.body6, label %for.end
168 for.body6: ; preds = %for.cond4
169 %8 = load i32, ptr %val, align 4
170 %mul = mul nsw i32 %8, 2
171 store i32 %mul, ptr %val, align 4
174 for.inc: ; preds = %for.body6
175 %9 = load i32, ptr %j, align 4
176 %inc = add nsw i32 %9, 1
177 store i32 %inc, ptr %j, align 4
180 for.end: ; preds = %for.cond4
181 %10 = load i32, ptr %val, align 4
182 %add7 = add nsw i32 %10, 3
183 store i32 %add7, ptr %val, align 4
186 if.end8: ; preds = %for.end, %for.body
187 %11 = load i32, ptr %color, align 4
188 %cmp9 = icmp slt i32 %11, 1
189 br i1 %cmp9, label %if.then10, label %if.else
191 if.then10: ; preds = %if.end8
192 %12 = load i32, ptr %val, align 4
193 %mul11 = mul nsw i32 %12, 4
194 store i32 %mul11, ptr %val, align 4
197 if.else: ; preds = %if.end8
198 store i32 0, ptr %k, align 4
201 for.cond12: ; preds = %for.inc19, %if.else
202 %13 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %2) ]
203 %14 = load i32, ptr %k, align 4
204 %cmp13 = icmp slt i32 %14, 20
205 br i1 %cmp13, label %for.body14, label %for.end21
207 for.body14: ; preds = %for.cond12
208 %15 = load i32, ptr %val, align 4
209 %sub = sub nsw i32 %15, 5
210 store i32 %sub, ptr %val, align 4
211 %16 = load i32, ptr %val, align 4
212 %cmp15 = icmp slt i32 %16, 0
213 br i1 %cmp15, label %if.then16, label %if.end18
215 if.then16: ; preds = %for.body14
216 %17 = load i32, ptr %val, align 4
217 %add17 = add nsw i32 %17, 100
218 store i32 %add17, ptr %val, align 4
221 if.end18: ; preds = %if.then16, %for.body14
224 for.inc19: ; preds = %if.end18
225 %18 = load i32, ptr %k, align 4
226 %inc20 = add nsw i32 %18, 1
227 store i32 %inc20, ptr %k, align 4
230 for.end21: ; preds = %for.cond12
233 if.end22: ; preds = %for.end21, %if.then10
236 for.inc23: ; preds = %if.end22
237 %19 = load i32, ptr %i, align 4
238 %inc24 = add nsw i32 %19, 1
239 store i32 %inc24, ptr %i, align 4
242 for.end25: ; preds = %for.cond
243 %20 = load i32, ptr %color, align 4
244 %cmp26 = icmp slt i32 %20, 2
245 br i1 %cmp26, label %if.then27, label %if.end29
247 if.then27: ; preds = %for.end25
248 %21 = load i32, ptr %val, align 4
249 %add28 = add nsw i32 %21, 6
250 store i32 %add28, ptr %val, align 4
253 if.end29: ; preds = %if.then27, %for.end25
254 %22 = load i32, ptr %val, align 4
258 ; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)
259 declare token @llvm.experimental.convergence.entry() #1
261 ; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)
262 declare token @llvm.experimental.convergence.loop() #1
264 ; Function Attrs: convergent noinline norecurse nounwind optnone
265 define internal spir_func void @main() #0 {
267 %0 = call token @llvm.experimental.convergence.entry()
268 %call1 = call spir_func noundef i32 @_Z7processv() #3 [ "convergencectrl"(token %0) ]
272 ; Function Attrs: convergent norecurse
273 define void @main.1() #2 {
279 attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
280 attributes #1 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
281 attributes #2 = { convergent norecurse "frame-pointer"="all" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
282 attributes #3 = { convergent }
284 !llvm.module.flags = !{!0, !1, !2}
287 !0 = !{i32 1, !"wchar_size", i32 4}
288 !1 = !{i32 4, !"dx.disable_optimizations", i32 1}
289 !2 = !{i32 7, !"frame-pointer", i32 2}