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