| 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 |
; ////////////////////////// |
| 13 |
; //// Basic while loop //// |
| 14 |
; ////////////////////////// |
| 15 |
; while (i < 10) { |
| 16 |
; val = i; |
| 17 |
; } |
| 18 |
; |
| 19 |
; ////////////////////////// |
| 20 |
; //// infinite loop //// |
| 21 |
; ////////////////////////// |
| 22 |
; while (true) { |
| 23 |
; val = 0; |
| 24 |
; } |
| 25 |
; |
| 26 |
; ////////////////////////// |
| 27 |
; //// Null Body //// |
| 28 |
; ////////////////////////// |
| 29 |
; while (val < 20) |
| 30 |
; ; |
| 31 |
; |
| 32 |
; //////////////////////////////////////////////////////////////// |
| 33 |
; //// Condition variable has VarDecl //// |
| 34 |
; //// foo() returns an integer which must be cast to boolean //// |
| 35 |
; //////////////////////////////////////////////////////////////// |
| 36 |
; while (int a = foo()) { |
| 37 |
; val = a; |
| 38 |
; } |
| 39 |
; |
| 40 |
; } |
| 41 |
|
| 42 |
; CHECK: %[[#func_11:]] = OpFunction %[[#uint:]] DontInline %[[#]] |
| 43 |
; CHECK: %[[#bb20:]] = OpLabel |
| 44 |
; CHECK: OpReturnValue %[[#]] |
| 45 |
; CHECK: OpFunctionEnd |
| 46 |
|
| 47 |
; CHECK: %[[#func_12:]] = OpFunction %[[#void:]] DontInline %[[#]] |
| 48 |
; CHECK: %[[#bb21:]] = OpLabel |
| 49 |
; CHECK: OpBranch %[[#bb22:]] |
| 50 |
; CHECK: %[[#bb22]] = OpLabel |
| 51 |
; CHECK: OpLoopMerge %[[#bb23:]] %[[#bb24:]] None |
| 52 |
; CHECK: OpBranchConditional %[[#]] %[[#bb24]] %[[#bb23]] |
| 53 |
; CHECK: %[[#bb23]] = OpLabel |
| 54 |
; CHECK: OpBranch %[[#bb25:]] |
| 55 |
; CHECK: %[[#bb25]] = OpLabel |
| 56 |
; CHECK: OpLoopMerge %[[#bb26:]] %[[#bb27:]] None |
| 57 |
; CHECK: OpBranchConditional %[[#]] %[[#bb26]] %[[#bb27]] |
| 58 |
; CHECK: %[[#bb27]] = OpLabel |
| 59 |
; CHECK: OpBranch %[[#bb25]] |
| 60 |
; CHECK: %[[#bb26]] = OpLabel |
| 61 |
; CHECK-NEXT: OpUnreachable |
| 62 |
; CHECK: %[[#bb24]] = OpLabel |
| 63 |
; CHECK: OpBranch %[[#bb22]] |
| 64 |
; CHECK: OpFunctionEnd |
| 65 |
|
| 66 |
; CHECK: %[[#func_18:]] = OpFunction %[[#void:]] None %[[#]] |
| 67 |
; CHECK: %[[#bb28:]] = OpLabel |
| 68 |
; CHECK: OpReturn |
| 69 |
; CHECK: OpFunctionEnd |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1" |
| 74 |
target triple = "spirv-unknown-vulkan1.3-compute" |
| 75 |
|
| 76 |
; Function Attrs: convergent noinline norecurse nounwind optnone |
| 77 |
define spir_func noundef i32 @_Z3foov() #0 { |
| 78 |
entry: |
| 79 |
%0 = call token @llvm.experimental.convergence.entry() |
| 80 |
ret i32 1 |
| 81 |
} |
| 82 |
|
| 83 |
; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none) |
| 84 |
declare token @llvm.experimental.convergence.entry() #1 |
| 85 |
|
| 86 |
; Function Attrs: convergent noinline norecurse nounwind optnone |
| 87 |
define internal spir_func void @main() #0 { |
| 88 |
entry: |
| 89 |
%0 = call token @llvm.experimental.convergence.entry() |
| 90 |
%val = alloca i32, align 4 |
| 91 |
%i = alloca i32, align 4 |
| 92 |
store i32 0, ptr %val, align 4 |
| 93 |
store i32 0, ptr %i, align 4 |
| 94 |
br label %while.cond |
| 95 |
|
| 96 |
while.cond: ; preds = %while.body, %entry |
| 97 |
%1 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ] |
| 98 |
%2 = load i32, ptr %i, align 4 |
| 99 |
%cmp = icmp slt i32 %2, 10 |
| 100 |
br i1 %cmp, label %while.body, label %while.end |
| 101 |
|
| 102 |
while.body: ; preds = %while.cond |
| 103 |
%3 = load i32, ptr %i, align 4 |
| 104 |
store i32 %3, ptr %val, align 4 |
| 105 |
br label %while.cond |
| 106 |
|
| 107 |
while.end: ; preds = %while.cond |
| 108 |
br label %while.cond1 |
| 109 |
|
| 110 |
while.cond1: ; preds = %while.body2, %while.end |
| 111 |
%4 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ] |
| 112 |
br label %while.body2 |
| 113 |
|
| 114 |
while.body2: ; preds = %while.cond1 |
| 115 |
store i32 0, ptr %val, align 4 |
| 116 |
br label %while.cond1 |
| 117 |
} |
| 118 |
|
| 119 |
; Function Attrs: convergent norecurse |
| 120 |
define void @main.1() #2 { |
| 121 |
entry: |
| 122 |
call void @main() |
| 123 |
ret void |
| 124 |
} |
| 125 |
|
| 126 |
; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none) |
| 127 |
declare token @llvm.experimental.convergence.loop() #1 |
| 128 |
|
| 129 |
attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } |
| 130 |
attributes #1 = { convergent nocallback nofree nosync nounwind willreturn memory(none) } |
| 131 |
attributes #2 = { convergent norecurse "frame-pointer"="all" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } |
| 132 |
|
| 133 |
!llvm.module.flags = !{!0, !1, !2} |
| 134 |
|
| 135 |
|
| 136 |
!0 = !{i32 1, !"wchar_size", i32 4} |
| 137 |
!1 = !{i32 4, !"dx.disable_optimizations", i32 1} |
| 138 |
!2 = !{i32 7, !"frame-pointer", i32 2} |
| 139 |
|
| 140 |
|