| 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 process() { |
| 6 |
; int color = 0; |
| 7 |
; |
| 8 |
; int val = 0; |
| 9 |
; |
| 10 |
; if (color < 0) { |
| 11 |
; val = 1; |
| 12 |
; } |
| 13 |
; |
| 14 |
; // for-stmt following if-stmt |
| 15 |
; for (int i = 0; i < 10; ++i) { |
| 16 |
; if (color < 0) { // if-stmt nested in for-stmt |
| 17 |
; val = val + 1; |
| 18 |
; for (int j = 0; j < 15; ++j) { // for-stmt deeply nested in if-then |
| 19 |
; val = val * 2; |
| 20 |
; } // end for (int j |
| 21 |
; val = val + 3; |
| 22 |
; } |
| 23 |
; |
| 24 |
; if (color < 1) { // if-stmt following if-stmt |
| 25 |
; val = val * 4; |
| 26 |
; } else { |
| 27 |
; for (int k = 0; k < 20; ++k) { // for-stmt deeply nested in if-else |
| 28 |
; val = val - 5; |
| 29 |
; if (val < 0) { // deeply nested if-stmt |
| 30 |
; val = val + 100; |
| 31 |
; } |
| 32 |
; } // end for (int k |
| 33 |
; } // end elsek |
| 34 |
; } // end for (int i |
| 35 |
; |
| 36 |
; // if-stmt following for-stmt |
| 37 |
; if (color < 2) { |
| 38 |
; val = val + 6; |
| 39 |
; } |
| 40 |
; |
| 41 |
; return val; |
| 42 |
; } |
| 43 |
; |
| 44 |
; [numthreads(1, 1, 1)] |
| 45 |
; void main() { |
| 46 |
; process(); |
| 47 |
; } |
| 48 |
|
| 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: %[[#bb69]] = OpLabel |
| 61 |
; CHECK: OpSelectionMerge %[[#bb72:]] None |
| 62 |
; CHECK: OpBranchConditional %[[#]] %[[#bb73:]] %[[#bb72]] |
| 63 |
; CHECK: %[[#bb73]] = OpLabel |
| 64 |
; CHECK: OpBranch %[[#bb72]] |
| 65 |
; CHECK: %[[#bb72]] = OpLabel |
| 66 |
; CHECK: OpReturnValue %[[#]] |
| 67 |
; CHECK: %[[#bb71]] = OpLabel |
| 68 |
; CHECK: OpSelectionMerge %[[#bb74:]] None |
| 69 |
; CHECK: OpBranchConditional %[[#]] %[[#bb75:]] %[[#bb74]] |
| 70 |
; CHECK: %[[#bb75]] = OpLabel |
| 71 |
; CHECK: OpBranch %[[#bb76:]] |
| 72 |
; CHECK: %[[#bb76]] = OpLabel |
| 73 |
; CHECK: OpLoopMerge %[[#bb77:]] %[[#bb78:]] None |
| 74 |
; CHECK: OpBranchConditional %[[#]] %[[#bb79:]] %[[#bb77]] |
| 75 |
; CHECK: %[[#bb77]] = OpLabel |
| 76 |
; CHECK: OpBranch %[[#bb74]] |
| 77 |
; CHECK: %[[#bb74]] = OpLabel |
| 78 |
; CHECK: OpSelectionMerge %[[#bb80:]] None |
| 79 |
; CHECK: OpBranchConditional %[[#]] %[[#bb81:]] %[[#bb82:]] |
| 80 |
; CHECK: %[[#bb82]] = OpLabel |
| 81 |
; CHECK: OpBranch %[[#bb83:]] |
| 82 |
; CHECK: %[[#bb83]] = OpLabel |
| 83 |
; CHECK: OpLoopMerge %[[#bb84:]] %[[#bb85:]] None |
| 84 |
; CHECK: OpBranchConditional %[[#]] %[[#bb86:]] %[[#bb84]] |
| 85 |
; CHECK: %[[#bb84]] = OpLabel |
| 86 |
; CHECK: OpBranch %[[#bb80]] |
| 87 |
; CHECK: %[[#bb86]] = OpLabel |
| 88 |
; CHECK: OpSelectionMerge %[[#bb87:]] None |
| 89 |
; CHECK: OpBranchConditional %[[#]] %[[#bb88:]] %[[#bb87]] |
| 90 |
; CHECK: %[[#bb88]] = OpLabel |
| 91 |
; CHECK: OpBranch %[[#bb87]] |
| 92 |
; CHECK: %[[#bb87]] = OpLabel |
| 93 |
; CHECK: OpBranch %[[#bb85]] |
| 94 |
; CHECK: %[[#bb85]] = OpLabel |
| 95 |
; CHECK: OpBranch %[[#bb83]] |
| 96 |
; CHECK: %[[#bb81]] = OpLabel |
| 97 |
; CHECK: OpBranch %[[#bb80]] |
| 98 |
; CHECK: %[[#bb80]] = OpLabel |
| 99 |
; CHECK: OpBranch %[[#bb70]] |
| 100 |
; CHECK: %[[#bb70]] = OpLabel |
| 101 |
; CHECK: OpBranch %[[#bb68]] |
| 102 |
; CHECK: %[[#bb79]] = OpLabel |
| 103 |
; CHECK: OpBranch %[[#bb78]] |
| 104 |
; CHECK: %[[#bb78]] = OpLabel |
| 105 |
; CHECK: OpBranch %[[#bb76]] |
| 106 |
; CHECK: OpFunctionEnd |
| 107 |
|
| 108 |
; CHECK: %[[#func_61:]] = OpFunction %[[#void:]] DontInline %[[#]] |
| 109 |
; CHECK: %[[#bb89:]] = OpLabel |
| 110 |
; CHECK: OpReturn |
| 111 |
; CHECK: OpFunctionEnd |
| 112 |
|
| 113 |
; CHECK: %[[#func_63:]] = OpFunction %[[#void]] None %[[#]] |
| 114 |
; CHECK: %[[#bb90:]] = OpLabel |
| 115 |
; CHECK: OpReturn |
| 116 |
; CHECK: OpFunctionEnd |
| 117 |
|
| 118 |
|
| 119 |
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1" |
| 120 |
target triple = "spirv-unknown-vulkan1.3-compute" |
| 121 |
|
| 122 |
; Function Attrs: convergent noinline norecurse nounwind optnone |
| 123 |
define spir_func noundef i32 @_Z7processv() #0 { |
| 124 |
entry: |
| 125 |
%0 = call token @llvm.experimental.convergence.entry() |
| 126 |
%color = alloca i32, align 4 |
| 127 |
%val = alloca i32, align 4 |
| 128 |
%i = alloca i32, align 4 |
| 129 |
%j = alloca i32, align 4 |
| 130 |
%k = alloca i32, align 4 |
| 131 |
store i32 0, ptr %color, align 4 |
| 132 |
store i32 0, ptr %val, align 4 |
| 133 |
%1 = load i32, ptr %color, align 4 |
| 134 |
%cmp = icmp slt i32 %1, 0 |
| 135 |
br i1 %cmp, label %if.then, label %if.end |
| 136 |
|
| 137 |
if.then: ; preds = %entry |
| 138 |
store i32 1, ptr %val, align 4 |
| 139 |
br label %if.end |
| 140 |
|
| 141 |
if.end: ; preds = %if.then, %entry |
| 142 |
store i32 0, ptr %i, align 4 |
| 143 |
br label %for.cond |
| 144 |
|
| 145 |
for.cond: ; preds = %for.inc23, %if.end |
| 146 |
%2 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ] |
| 147 |
%3 = load i32, ptr %i, align 4 |
| 148 |
%cmp1 = icmp slt i32 %3, 10 |
| 149 |
br i1 %cmp1, label %for.body, label %for.end25 |
| 150 |
|
| 151 |
for.body: ; preds = %for.cond |
| 152 |
%4 = load i32, ptr %color, align 4 |
| 153 |
%cmp2 = icmp slt i32 %4, 0 |
| 154 |
br i1 %cmp2, label %if.then3, label %if.end8 |
| 155 |
|
| 156 |
if.then3: ; preds = %for.body |
| 157 |
%5 = load i32, ptr %val, align 4 |
| 158 |
%add = add nsw i32 %5, 1 |
| 159 |
store i32 %add, ptr %val, align 4 |
| 160 |
store i32 0, ptr %j, align 4 |
| 161 |
br label %for.cond4 |
| 162 |
|
| 163 |
for.cond4: ; preds = %for.inc, %if.then3 |
| 164 |
%6 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %2) ] |
| 165 |
%7 = load i32, ptr %j, align 4 |
| 166 |
%cmp5 = icmp slt i32 %7, 15 |
| 167 |
br i1 %cmp5, label %for.body6, label %for.end |
| 168 |
|
| 169 |
for.body6: ; preds = %for.cond4 |
| 170 |
%8 = load i32, ptr %val, align 4 |
| 171 |
%mul = mul nsw i32 %8, 2 |
| 172 |
store i32 %mul, ptr %val, align 4 |
| 173 |
br label %for.inc |
| 174 |
|
| 175 |
for.inc: ; preds = %for.body6 |
| 176 |
%9 = load i32, ptr %j, align 4 |
| 177 |
%inc = add nsw i32 %9, 1 |
| 178 |
store i32 %inc, ptr %j, align 4 |
| 179 |
br label %for.cond4 |
| 180 |
|
| 181 |
for.end: ; preds = %for.cond4 |
| 182 |
%10 = load i32, ptr %val, align 4 |
| 183 |
%add7 = add nsw i32 %10, 3 |
| 184 |
store i32 %add7, ptr %val, align 4 |
| 185 |
br label %if.end8 |
| 186 |
|
| 187 |
if.end8: ; preds = %for.end, %for.body |
| 188 |
%11 = load i32, ptr %color, align 4 |
| 189 |
%cmp9 = icmp slt i32 %11, 1 |
| 190 |
br i1 %cmp9, label %if.then10, label %if.else |
| 191 |
|
| 192 |
if.then10: ; preds = %if.end8 |
| 193 |
%12 = load i32, ptr %val, align 4 |
| 194 |
%mul11 = mul nsw i32 %12, 4 |
| 195 |
store i32 %mul11, ptr %val, align 4 |
| 196 |
br label %if.end22 |
| 197 |
|
| 198 |
if.else: ; preds = %if.end8 |
| 199 |
store i32 0, ptr %k, align 4 |
| 200 |
br label %for.cond12 |
| 201 |
|
| 202 |
for.cond12: ; preds = %for.inc19, %if.else |
| 203 |
%13 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %2) ] |
| 204 |
%14 = load i32, ptr %k, align 4 |
| 205 |
%cmp13 = icmp slt i32 %14, 20 |
| 206 |
br i1 %cmp13, label %for.body14, label %for.end21 |
| 207 |
|
| 208 |
for.body14: ; preds = %for.cond12 |
| 209 |
%15 = load i32, ptr %val, align 4 |
| 210 |
%sub = sub nsw i32 %15, 5 |
| 211 |
store i32 %sub, ptr %val, align 4 |
| 212 |
%16 = load i32, ptr %val, align 4 |
| 213 |
%cmp15 = icmp slt i32 %16, 0 |
| 214 |
br i1 %cmp15, label %if.then16, label %if.end18 |
| 215 |
|
| 216 |
if.then16: ; preds = %for.body14 |
| 217 |
%17 = load i32, ptr %val, align 4 |
| 218 |
%add17 = add nsw i32 %17, 100 |
| 219 |
store i32 %add17, ptr %val, align 4 |
| 220 |
br label %if.end18 |
| 221 |
|
| 222 |
if.end18: ; preds = %if.then16, %for.body14 |
| 223 |
br label %for.inc19 |
| 224 |
|
| 225 |
for.inc19: ; preds = %if.end18 |
| 226 |
%18 = load i32, ptr %k, align 4 |
| 227 |
%inc20 = add nsw i32 %18, 1 |
| 228 |
store i32 %inc20, ptr %k, align 4 |
| 229 |
br label %for.cond12 |
| 230 |
|
| 231 |
for.end21: ; preds = %for.cond12 |
| 232 |
br label %if.end22 |
| 233 |
|
| 234 |
if.end22: ; preds = %for.end21, %if.then10 |
| 235 |
br label %for.inc23 |
| 236 |
|
| 237 |
for.inc23: ; preds = %if.end22 |
| 238 |
%19 = load i32, ptr %i, align 4 |
| 239 |
%inc24 = add nsw i32 %19, 1 |
| 240 |
store i32 %inc24, ptr %i, align 4 |
| 241 |
br label %for.cond |
| 242 |
|
| 243 |
for.end25: ; preds = %for.cond |
| 244 |
%20 = load i32, ptr %color, align 4 |
| 245 |
%cmp26 = icmp slt i32 %20, 2 |
| 246 |
br i1 %cmp26, label %if.then27, label %if.end29 |
| 247 |
|
| 248 |
if.then27: ; preds = %for.end25 |
| 249 |
%21 = load i32, ptr %val, align 4 |
| 250 |
%add28 = add nsw i32 %21, 6 |
| 251 |
store i32 %add28, ptr %val, align 4 |
| 252 |
br label %if.end29 |
| 253 |
|
| 254 |
if.end29: ; preds = %if.then27, %for.end25 |
| 255 |
%22 = load i32, ptr %val, align 4 |
| 256 |
ret i32 %22 |
| 257 |
} |
| 258 |
|
| 259 |
; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none) |
| 260 |
declare token @llvm.experimental.convergence.entry() #1 |
| 261 |
|
| 262 |
; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none) |
| 263 |
declare token @llvm.experimental.convergence.loop() #1 |
| 264 |
|
| 265 |
; Function Attrs: convergent noinline norecurse nounwind optnone |
| 266 |
define internal spir_func void @main() #0 { |
| 267 |
entry: |
| 268 |
%0 = call token @llvm.experimental.convergence.entry() |
| 269 |
%call1 = call spir_func noundef i32 @_Z7processv() #3 [ "convergencectrl"(token %0) ] |
| 270 |
ret void |
| 271 |
} |
| 272 |
|
| 273 |
; Function Attrs: convergent norecurse |
| 274 |
define void @main.1() #2 { |
| 275 |
entry: |
| 276 |
call void @main() |
| 277 |
ret void |
| 278 |
} |
| 279 |
|
| 280 |
attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } |
| 281 |
attributes #1 = { convergent nocallback nofree nosync nounwind willreturn memory(none) } |
| 282 |
attributes #2 = { convergent norecurse "frame-pointer"="all" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } |
| 283 |
attributes #3 = { convergent } |
| 284 |
|
| 285 |
!llvm.module.flags = !{!0, !1, !2} |
| 286 |
|
| 287 |
|
| 288 |
!0 = !{i32 1, !"wchar_size", i32 4} |
| 289 |
!1 = !{i32 4, !"dx.disable_optimizations", i32 1} |
| 290 |
!2 = !{i32 7, !"frame-pointer", i32 2} |
| 291 |
|
| 292 |
|