xref: /llvm-project/llvm/test/CodeGen/SPIRV/structurizer/cf.while.continue.ll (revision 53326ee0cf45fce3f80e2e98638dd27edb20c516)
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 %}
3
4;
5; int foo() { return true; }
6;
7; [numthreads(1, 1, 1)]
8; void main() {
9;   int val = 0;
10;   int i = 0;
11;
12;   while (i < 10) {
13;     val = i;
14;     if (val > 5) {
15;       continue;
16;     }
17;
18;     if (val > 6) {
19;       {{continue;}}
20;       val++;       // No SPIR-V should be emitted for this statement.
21;       continue;    // No SPIR-V should be emitted for this statement.
22;       while(true); // No SPIR-V should be emitted for this statement.
23;       --i;         // No SPIR-V should be emitted for this statement.
24;     }
25;
26;   }
27;
28;   //////////////////////////////////////////////////////////////////////////////////////
29;   // Nested while loops with continue statements                                      //
30;   // Each continue statement should branch to the corresponding loop's continue block //
31;   //////////////////////////////////////////////////////////////////////////////////////
32;
33;   while (true) {
34;     i++;
35;
36;     while(i<20) {
37;       val = i;
38;       continue;
39;     }
40;     --i;
41;     continue;
42;     continue;  // No SPIR-V should be emitted for this statement.
43;
44;   }
45; }
46
47; CHECK: %[[#func_15:]] = OpFunction %[[#uint:]] DontInline %[[#]]
48; CHECK:    %[[#bb36:]] = OpLabel
49; CHECK:                  OpReturnValue %[[#]]
50; CHECK:                  OpFunctionEnd
51
52; CHECK: %[[#func_16:]] = OpFunction %[[#void:]] DontInline %[[#]]
53; CHECK:    %[[#bb37:]] = OpLabel
54; CHECK:                  OpBranch %[[#bb38:]]
55; CHECK:     %[[#bb38]] = OpLabel
56; CHECK:                  OpLoopMerge %[[#bb39:]] %[[#bb40:]] None
57; CHECK:                  OpBranchConditional %[[#]] %[[#bb41:]] %[[#bb39]]
58; CHECK:     %[[#bb39]] = OpLabel
59; CHECK:                  OpBranch %[[#bb42:]]
60; CHECK:     %[[#bb42]] = OpLabel
61; CHECK:                  OpLoopMerge %[[#bb43:]] %[[#bb44:]] None
62; CHECK:                  OpBranchConditional %[[#]] %[[#bb43]] %[[#bb45:]]
63; CHECK:     %[[#bb45]] = OpLabel
64; CHECK:                  OpBranch %[[#bb46:]]
65; CHECK:     %[[#bb46]] = OpLabel
66; CHECK:                  OpLoopMerge %[[#bb47:]] %[[#bb48:]] None
67; CHECK:                  OpBranchConditional %[[#]] %[[#bb48]] %[[#bb47]]
68; CHECK:     %[[#bb47]] = OpLabel
69; CHECK:                  OpBranch %[[#bb44]]
70; CHECK:     %[[#bb44]] = OpLabel
71; CHECK:                  OpBranch %[[#bb42]]
72; CHECK:     %[[#bb48]] = OpLabel
73; CHECK:                  OpBranch %[[#bb46]]
74; CHECK:     %[[#bb43]] = OpLabel
75; CHECK:     %[[#bb41]] = OpLabel
76; CHECK:                  OpSelectionMerge %[[#bb49:]] None
77; CHECK:                  OpBranchConditional %[[#]] %[[#bb49]] %[[#bb50:]]
78; CHECK:     %[[#bb50]] = OpLabel
79; CHECK:                  OpSelectionMerge %[[#bb51:]] None
80; CHECK:                  OpBranchConditional %[[#]] %[[#bb51]] %[[#bb52:]]
81; CHECK:     %[[#bb52]] = OpLabel
82; CHECK:                  OpBranch %[[#bb51]]
83; CHECK:     %[[#bb51]] = OpLabel
84; CHECK:                  OpBranch %[[#bb49]]
85; CHECK:     %[[#bb49]] = OpLabel
86; CHECK:                  OpBranch %[[#bb40]]
87; CHECK:     %[[#bb40]] = OpLabel
88; CHECK:                  OpBranch %[[#bb38]]
89; CHECK:                  OpFunctionEnd
90
91; CHECK: %[[#func_34:]] = OpFunction %[[#void]] None %[[#]]
92; CHECK:    %[[#bb53:]] = OpLabel
93; CHECK:                  OpReturn
94; CHECK:                  OpFunctionEnd
95
96target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
97target triple = "spirv-unknown-vulkan1.3-compute"
98
99; Function Attrs: convergent noinline norecurse nounwind optnone
100define spir_func noundef i32 @_Z3foov() #0 {
101entry:
102  %0 = call token @llvm.experimental.convergence.entry()
103  ret i32 1
104}
105
106; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)
107declare token @llvm.experimental.convergence.entry() #1
108
109; Function Attrs: convergent noinline norecurse nounwind optnone
110define internal spir_func void @main() #0 {
111entry:
112  %0 = call token @llvm.experimental.convergence.entry()
113  %val = alloca i32, align 4
114  %i = alloca i32, align 4
115  store i32 0, ptr %val, align 4
116  store i32 0, ptr %i, align 4
117  br label %while.cond
118
119while.cond:                                       ; preds = %if.end4, %if.then3, %if.then, %entry
120  %1 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ]
121  %2 = load i32, ptr %i, align 4
122  %cmp = icmp slt i32 %2, 10
123  br i1 %cmp, label %while.body, label %while.end
124
125while.body:                                       ; preds = %while.cond
126  %3 = load i32, ptr %i, align 4
127  store i32 %3, ptr %val, align 4
128  %4 = load i32, ptr %val, align 4
129  %cmp1 = icmp sgt i32 %4, 5
130  br i1 %cmp1, label %if.then, label %if.end
131
132if.then:                                          ; preds = %while.body
133  br label %while.cond
134
135if.end:                                           ; preds = %while.body
136  %5 = load i32, ptr %val, align 4
137  %cmp2 = icmp sgt i32 %5, 6
138  br i1 %cmp2, label %if.then3, label %if.end4
139
140if.then3:                                         ; preds = %if.end
141  br label %while.cond
142
143if.end4:                                          ; preds = %if.end
144  br label %while.cond
145
146while.end:                                        ; preds = %while.cond
147  br label %while.cond5
148
149while.cond5:                                      ; preds = %while.end10, %while.end
150  %6 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ]
151  br label %while.body6
152
153while.body6:                                      ; preds = %while.cond5
154  %7 = load i32, ptr %i, align 4
155  %inc = add nsw i32 %7, 1
156  store i32 %inc, ptr %i, align 4
157  br label %while.cond7
158
159while.cond7:                                      ; preds = %while.body9, %while.body6
160  %8 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %6) ]
161  %9 = load i32, ptr %i, align 4
162  %cmp8 = icmp slt i32 %9, 20
163  br i1 %cmp8, label %while.body9, label %while.end10
164
165while.body9:                                      ; preds = %while.cond7
166  %10 = load i32, ptr %i, align 4
167  store i32 %10, ptr %val, align 4
168  br label %while.cond7
169
170while.end10:                                      ; preds = %while.cond7
171  %11 = load i32, ptr %i, align 4
172  %dec = add nsw i32 %11, -1
173  store i32 %dec, ptr %i, align 4
174  br label %while.cond5
175}
176
177; Function Attrs: convergent norecurse
178define void @main.1() #2 {
179entry:
180  call void @main()
181  ret void
182}
183
184; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)
185declare token @llvm.experimental.convergence.loop() #1
186
187attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
188attributes #1 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
189attributes #2 = { convergent norecurse "frame-pointer"="all" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
190
191!llvm.module.flags = !{!0, !1, !2}
192
193
194!0 = !{i32 1, !"wchar_size", i32 4}
195!1 = !{i32 4, !"dx.disable_optimizations", i32 1}
196!2 = !{i32 7, !"frame-pointer", i32 2}
197
198
199