xref: /llvm-project/llvm/test/CodeGen/SPIRV/structurizer/cf.logical-and.ll (revision cba70550ccf55c6ad3daa621bb8caf3c4ca6cbd7)
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 fn() { return true; }
6;
7; int process() {
8;   // Use in control flow
9;   int a = 0;
10;   int b = 0;
11;   int val = 0;
12;   if (a && b) val++;
13;
14;   // Operand with side effects
15;   if (fn() && fn()) val++;
16;
17;   if (a && fn())
18;     val++;
19;
20;   if (fn() && b)
21;     val++;
22;   return val;
23; }
24;
25; [numthreads(1, 1, 1)]
26; void main() {
27;   process();
28; }
29
30; CHECK:  %[[#func_9:]] = OpFunction %[[#uint:]] DontInline %[[#]]
31; CHECK:    %[[#bb43:]] = OpLabel
32; CHECK:                  OpReturnValue %[[#]]
33; CHECK:                  OpFunctionEnd
34; CHECK: %[[#func_10:]] = OpFunction %[[#uint:]] DontInline %[[#]]
35; CHECK:    %[[#bb44:]] = OpLabel
36; CHECK:                  OpSelectionMerge %[[#bb45:]] None
37; CHECK:                  OpBranchConditional %[[#]] %[[#bb46:]] %[[#bb45:]]
38; CHECK:    %[[#bb46:]] = OpLabel
39; CHECK:                  OpBranchConditional %[[#]] %[[#bb47:]] %[[#bb45:]]
40; CHECK:    %[[#bb47:]] = OpLabel
41; CHECK:                  OpBranch %[[#bb45:]]
42; CHECK:    %[[#bb45:]] = OpLabel
43; CHECK:                  OpSelectionMerge %[[#bb48:]] None
44; CHECK:                  OpBranchConditional %[[#]] %[[#bb49:]] %[[#bb48:]]
45; CHECK:    %[[#bb49:]] = OpLabel
46; CHECK:                  OpBranchConditional %[[#]] %[[#bb50:]] %[[#bb48:]]
47; CHECK:    %[[#bb50:]] = OpLabel
48; CHECK:                  OpBranch %[[#bb48:]]
49; CHECK:    %[[#bb48:]] = OpLabel
50; CHECK:                  OpSelectionMerge %[[#bb51:]] None
51; CHECK:                  OpBranchConditional %[[#]] %[[#bb52:]] %[[#bb51:]]
52; CHECK:    %[[#bb52:]] = OpLabel
53; CHECK:                  OpBranchConditional %[[#]] %[[#bb53:]] %[[#bb51:]]
54; CHECK:    %[[#bb53:]] = OpLabel
55; CHECK:                  OpBranch %[[#bb51:]]
56; CHECK:    %[[#bb51:]] = OpLabel
57; CHECK:                  OpSelectionMerge %[[#bb54:]] None
58; CHECK:                  OpBranchConditional %[[#]] %[[#bb55:]] %[[#bb54:]]
59; CHECK:    %[[#bb55:]] = OpLabel
60; CHECK:                  OpBranchConditional %[[#]] %[[#bb56:]] %[[#bb54:]]
61; CHECK:    %[[#bb56:]] = OpLabel
62; CHECK:                  OpBranch %[[#bb54:]]
63; CHECK:    %[[#bb54:]] = OpLabel
64; CHECK:                  OpReturnValue %[[#]]
65; CHECK:                  OpFunctionEnd
66; CHECK: %[[#func_39:]] = OpFunction %[[#void:]] DontInline %[[#]]
67; CHECK:    %[[#bb57:]] = OpLabel
68; CHECK:                  OpReturn
69; CHECK:                  OpFunctionEnd
70; CHECK: %[[#func_41:]] = OpFunction %[[#void:]] None %[[#]]
71; CHECK:    %[[#bb58:]] = OpLabel
72; CHECK:                  OpReturn
73; CHECK:                  OpFunctionEnd
74
75target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
76target triple = "spirv-unknown-vulkan1.3-compute"
77
78; Function Attrs: convergent noinline norecurse nounwind optnone
79define spir_func noundef i32 @_Z2fnv() #0 {
80entry:
81  %0 = call token @llvm.experimental.convergence.entry()
82  ret i32 1
83}
84
85; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)
86declare token @llvm.experimental.convergence.entry() #1
87
88; Function Attrs: convergent noinline norecurse nounwind optnone
89define spir_func noundef i32 @_Z7processv() #0 {
90entry:
91  %0 = call token @llvm.experimental.convergence.entry()
92  %a = alloca i32, align 4
93  %b = alloca i32, align 4
94  %val = alloca i32, align 4
95  store i32 0, ptr %a, align 4
96  store i32 0, ptr %b, align 4
97  store i32 0, ptr %val, align 4
98  %1 = load i32, ptr %a, align 4
99  %tobool = icmp ne i32 %1, 0
100  br i1 %tobool, label %land.lhs.true, label %if.end
101
102land.lhs.true:                                    ; preds = %entry
103  %2 = load i32, ptr %b, align 4
104  %tobool1 = icmp ne i32 %2, 0
105  br i1 %tobool1, label %if.then, label %if.end
106
107if.then:                                          ; preds = %land.lhs.true
108  %3 = load i32, ptr %val, align 4
109  %inc = add nsw i32 %3, 1
110  store i32 %inc, ptr %val, align 4
111  br label %if.end
112
113if.end:                                           ; preds = %if.then, %land.lhs.true, %entry
114  %call2 = call spir_func noundef i32 @_Z2fnv() #3 [ "convergencectrl"(token %0) ]
115  %tobool3 = icmp ne i32 %call2, 0
116  br i1 %tobool3, label %land.lhs.true4, label %if.end9
117
118land.lhs.true4:                                   ; preds = %if.end
119  %call5 = call spir_func noundef i32 @_Z2fnv() #3 [ "convergencectrl"(token %0) ]
120  %tobool6 = icmp ne i32 %call5, 0
121  br i1 %tobool6, label %if.then7, label %if.end9
122
123if.then7:                                         ; preds = %land.lhs.true4
124  %4 = load i32, ptr %val, align 4
125  %inc8 = add nsw i32 %4, 1
126  store i32 %inc8, ptr %val, align 4
127  br label %if.end9
128
129if.end9:                                          ; preds = %if.then7, %land.lhs.true4, %if.end
130  %5 = load i32, ptr %a, align 4
131  %tobool10 = icmp ne i32 %5, 0
132  br i1 %tobool10, label %land.lhs.true11, label %if.end16
133
134land.lhs.true11:                                  ; preds = %if.end9
135  %call12 = call spir_func noundef i32 @_Z2fnv() #3 [ "convergencectrl"(token %0) ]
136  %tobool13 = icmp ne i32 %call12, 0
137  br i1 %tobool13, label %if.then14, label %if.end16
138
139if.then14:                                        ; preds = %land.lhs.true11
140  %6 = load i32, ptr %val, align 4
141  %inc15 = add nsw i32 %6, 1
142  store i32 %inc15, ptr %val, align 4
143  br label %if.end16
144
145if.end16:                                         ; preds = %if.then14, %land.lhs.true11, %if.end9
146  %call17 = call spir_func noundef i32 @_Z2fnv() #3 [ "convergencectrl"(token %0) ]
147  %tobool18 = icmp ne i32 %call17, 0
148  br i1 %tobool18, label %land.lhs.true19, label %if.end23
149
150land.lhs.true19:                                  ; preds = %if.end16
151  %7 = load i32, ptr %b, align 4
152  %tobool20 = icmp ne i32 %7, 0
153  br i1 %tobool20, label %if.then21, label %if.end23
154
155if.then21:                                        ; preds = %land.lhs.true19
156  %8 = load i32, ptr %val, align 4
157  %inc22 = add nsw i32 %8, 1
158  store i32 %inc22, ptr %val, align 4
159  br label %if.end23
160
161if.end23:                                         ; preds = %if.then21, %land.lhs.true19, %if.end16
162  %9 = load i32, ptr %val, align 4
163  ret i32 %9
164}
165
166; Function Attrs: convergent noinline norecurse nounwind optnone
167define internal spir_func void @main() #0 {
168entry:
169  %0 = call token @llvm.experimental.convergence.entry()
170  %call1 = call spir_func noundef i32 @_Z7processv() #3 [ "convergencectrl"(token %0) ]
171  ret void
172}
173
174; Function Attrs: convergent norecurse
175define void @main.1() #2 {
176entry:
177  call void @main()
178  ret void
179}
180
181attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
182attributes #1 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
183attributes #2 = { convergent norecurse "frame-pointer"="all" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
184attributes #3 = { convergent }
185
186!llvm.module.flags = !{!0, !1, !2}
187
188
189!0 = !{i32 1, !"wchar_size", i32 4}
190!1 = !{i32 4, !"dx.disable_optimizations", i32 1}
191!2 = !{i32 7, !"frame-pointer", i32 2}
192
193
194