| 1 |
; RUN: %if spirv-tools %{ llc -mtriple=spirv-unknown-vulkan-compute -O0 %s -o - | spirv-as --preserve-numeric-ids - -o - | spirv-val %} |
| 2 |
; |
| 3 |
; Source HLSL: |
| 4 |
; |
| 5 |
; int process() { |
| 6 |
; int val = 0; |
| 7 |
; |
| 8 |
; for (int i = 0; i < 10; ++i) { |
| 9 |
; if (i < 5) { |
| 10 |
; break; |
| 11 |
; } |
| 12 |
; val = i; |
| 13 |
; { |
| 14 |
; break; |
| 15 |
; } |
| 16 |
; break; // No SPIR-V should be emitted for this statement. |
| 17 |
; val++; // No SPIR-V should be emitted for this statement. |
| 18 |
; while(true); // No SPIR-V should be emitted for this statement. |
| 19 |
; } |
| 20 |
; |
| 21 |
; //////////////////////////////////////////////////////////////////////////////// |
| 22 |
; // Nested for loops with break statements // |
| 23 |
; // Each break statement should branch to the corresponding loop's break block // |
| 24 |
; //////////////////////////////////////////////////////////////////////////////// |
| 25 |
; for (int j = 0; j < 10; ++j) { |
| 26 |
; val = j+5; |
| 27 |
; for ( ; val < 20; ++val) { |
| 28 |
; int k = val + j; |
| 29 |
; { |
| 30 |
; { |
| 31 |
; break; |
| 32 |
; } |
| 33 |
; } |
| 34 |
; k++; // No SPIR-V should be emitted for this statement. |
| 35 |
; } |
| 36 |
; |
| 37 |
; // FIXME: val--; generates add nsw i32 ..., -1 |
| 38 |
; // This is compiled into a OpIAdd %val, MAX_INT. |
| 39 |
; val -= 1; |
| 40 |
; break; |
| 41 |
; break; // No SPIR-V should be emitted for this statement. |
| 42 |
; val = val*10; // No SPIR-V should be emitted for this statement. |
| 43 |
; } |
| 44 |
; |
| 45 |
; return val; |
| 46 |
; } |
| 47 |
; |
| 48 |
; [numthreads(1, 1, 1)] |
| 49 |
; void main() { |
| 50 |
; process(); |
| 51 |
; } |
| 52 |
|
| 53 |
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1" |
| 54 |
target triple = "spirv-unknown-vulkan1.3-compute" |
| 55 |
|
| 56 |
; Function Attrs: convergent noinline nounwind optnone |
| 57 |
define spir_func noundef i32 @_Z7processv() #0 { |
| 58 |
entry: |
| 59 |
%0 = call token @llvm.experimental.convergence.entry() |
| 60 |
%val = alloca i32, align 4 |
| 61 |
%i = alloca i32, align 4 |
| 62 |
%j = alloca i32, align 4 |
| 63 |
%k = alloca i32, align 4 |
| 64 |
store i32 0, ptr %val, align 4 |
| 65 |
store i32 0, ptr %i, align 4 |
| 66 |
br label %for.cond |
| 67 |
|
| 68 |
for.cond: ; preds = %for.inc, %entry |
| 69 |
%1 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ] |
| 70 |
%2 = load i32, ptr %i, align 4 |
| 71 |
%cmp = icmp slt i32 %2, 10 |
| 72 |
br i1 %cmp, label %for.body, label %for.end |
| 73 |
|
| 74 |
for.body: ; preds = %for.cond |
| 75 |
%3 = load i32, ptr %i, align 4 |
| 76 |
%cmp1 = icmp slt i32 %3, 5 |
| 77 |
br i1 %cmp1, label %if.then, label %if.end |
| 78 |
|
| 79 |
if.then: ; preds = %for.body |
| 80 |
br label %for.end |
| 81 |
|
| 82 |
if.end: ; preds = %for.body |
| 83 |
%4 = load i32, ptr %i, align 4 |
| 84 |
store i32 %4, ptr %val, align 4 |
| 85 |
br label %for.end |
| 86 |
|
| 87 |
for.inc: ; No predecessors! |
| 88 |
%5 = load i32, ptr %i, align 4 |
| 89 |
%inc = add nsw i32 %5, 1 |
| 90 |
store i32 %inc, ptr %i, align 4 |
| 91 |
br label %for.cond |
| 92 |
|
| 93 |
for.end: ; preds = %if.end, %if.then, %for.cond |
| 94 |
store i32 0, ptr %j, align 4 |
| 95 |
br label %for.cond2 |
| 96 |
|
| 97 |
for.cond2: ; preds = %for.inc12, %for.end |
| 98 |
%6 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ] |
| 99 |
%7 = load i32, ptr %j, align 4 |
| 100 |
%cmp3 = icmp slt i32 %7, 10 |
| 101 |
br i1 %cmp3, label %for.body4, label %for.end14 |
| 102 |
|
| 103 |
for.body4: ; preds = %for.cond2 |
| 104 |
%8 = load i32, ptr %j, align 4 |
| 105 |
%add = add nsw i32 %8, 5 |
| 106 |
store i32 %add, ptr %val, align 4 |
| 107 |
br label %for.cond5 |
| 108 |
|
| 109 |
for.cond5: ; preds = %for.inc9, %for.body4 |
| 110 |
%9 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %6) ] |
| 111 |
%10 = load i32, ptr %val, align 4 |
| 112 |
%cmp6 = icmp slt i32 %10, 20 |
| 113 |
br i1 %cmp6, label %for.body7, label %for.end11 |
| 114 |
|
| 115 |
for.body7: ; preds = %for.cond5 |
| 116 |
%11 = load i32, ptr %val, align 4 |
| 117 |
%12 = load i32, ptr %j, align 4 |
| 118 |
%add8 = add nsw i32 %11, %12 |
| 119 |
store i32 %add8, ptr %k, align 4 |
| 120 |
br label %for.end11 |
| 121 |
|
| 122 |
for.inc9: ; No predecessors! |
| 123 |
%13 = load i32, ptr %val, align 4 |
| 124 |
%inc10 = add nsw i32 %13, 1 |
| 125 |
store i32 %inc10, ptr %val, align 4 |
| 126 |
br label %for.cond5 |
| 127 |
|
| 128 |
for.end11: ; preds = %for.body7, %for.cond5 |
| 129 |
%14 = load i32, ptr %val, align 4 |
| 130 |
%sub = sub nsw i32 %14, 1 |
| 131 |
store i32 %sub, ptr %val, align 4 |
| 132 |
br label %for.end14 |
| 133 |
|
| 134 |
for.inc12: ; No predecessors! |
| 135 |
%15 = load i32, ptr %j, align 4 |
| 136 |
%inc13 = add nsw i32 %15, 1 |
| 137 |
store i32 %inc13, ptr %j, align 4 |
| 138 |
br label %for.cond2 |
| 139 |
|
| 140 |
for.end14: ; preds = %for.end11, %for.cond2 |
| 141 |
%16 = load i32, ptr %val, align 4 |
| 142 |
ret i32 %16 |
| 143 |
} |
| 144 |
|
| 145 |
; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none) |
| 146 |
declare token @llvm.experimental.convergence.entry() #1 |
| 147 |
|
| 148 |
; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none) |
| 149 |
declare token @llvm.experimental.convergence.loop() #1 |
| 150 |
|
| 151 |
; Function Attrs: convergent noinline norecurse nounwind optnone |
| 152 |
define internal spir_func void @main() #2 { |
| 153 |
entry: |
| 154 |
%0 = call token @llvm.experimental.convergence.entry() |
| 155 |
%call1 = call spir_func noundef i32 @_Z7processv() #4 [ "convergencectrl"(token %0) ] |
| 156 |
ret void |
| 157 |
} |
| 158 |
|
| 159 |
; Function Attrs: convergent norecurse |
| 160 |
define void @main.1() #3 { |
| 161 |
entry: |
| 162 |
call void @main() |
| 163 |
ret void |
| 164 |
} |
| 165 |
|
| 166 |
attributes #0 = { convergent noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } |
| 167 |
attributes #1 = { convergent nocallback nofree nosync nounwind willreturn memory(none) } |
| 168 |
attributes #2 = { convergent noinline norecurse nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } |
| 169 |
attributes #3 = { convergent norecurse "frame-pointer"="all" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } |
| 170 |
attributes #4 = { convergent } |
| 171 |
|
| 172 |
!llvm.module.flags = !{!0, !1, !2} |
| 173 |
|
| 174 |
!0 = !{i32 1, !"wchar_size", i32 4} |
| 175 |
!1 = !{i32 4, !"dx.disable_optimizations", i32 1} |
| 176 |
!2 = !{i32 7, !"frame-pointer", i32 2} |
| 177 |
|