xref: /llvm-project/llvm/test/CodeGen/SPIRV/structurizer/cf.for.plain.ll (revision 53326ee0cf45fce3f80e2e98638dd27edb20c516)
1; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val %}
2; RUN: llc -mtriple=spirv-unknown-vulkan-compute -O0 %s -o - | FileCheck %s
3
4target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
5target triple = "spirv-unknown-vulkan1.3-compute"
6
7; CHECK-DAG: OpName %[[#process:]] "_Z7processv"
8; CHECK-DAG: OpName %[[#val:]] "val"
9; CHECK-DAG: OpName %[[#i:]] "i"
10
11; CHECK-DAG: %[[#int_ty:]] = OpTypeInt 32 0
12; CHECK-DAG: %[[#int_pfty:]] = OpTypePointer Function %[[#int_ty]]
13; CHECK-DAG: %[[#false:]] = OpConstantFalse
14
15
16; CHECK: %[[#process]] = OpFunction %[[#]] DontInline %[[#]]
17define spir_func noundef i32 @_Z7processv() #0 {
18entry:
19  %0 = call token @llvm.experimental.convergence.entry()
20
21  ; CHECK-DAG: %[[#val]] = OpVariable %[[#int_pfty]] Function
22  ; CHECK-DAG:   %[[#i]] = OpVariable %[[#int_pfty]] Function
23  %val = alloca i32, align 4
24  %i = alloca i32, align 4
25  store i32 0, ptr %val, align 4
26  store i32 0, ptr %i, align 4
27  br label %for.cond
28  ; CHECK: OpBranch %[[#for_cond:]]
29
30for.cond:                                         ; preds = %for.inc, %entry
31  ; CHECK: %[[#for_cond]] = OpLabel
32  %1 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ]
33  %2 = load i32, ptr %i, align 4
34  %cmp = icmp slt i32 %2, 10
35
36  ; CHECK: OpLoopMerge %[[#for_end:]] %[[#for_inc:]]
37  ; CHECK: OpBranchConditional %[[#]] %[[#for_body:]] %[[#for_end]]
38  br i1 %cmp, label %for.body, label %for.end
39
40for.end:                                          ; preds = %for.cond
41  br label %for.cond1
42  ; CHECK: %[[#for_end]] = OpLabel
43  ; CHECK:                 OpBranch %[[#for_cond1:]]
44
45for.cond1:                                        ; preds = %for.cond1, %for.end
46  %3 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ]
47  store i32 0, ptr %val, align 4
48  br label %for.cond1
49  ; CHECK: %[[#for_cond1]] = OpLabel
50  ; CHECK: OpLoopMerge %[[#unreachable:]] %[[#for_cond1]]
51  ; CHECK: OpBranchConditional %[[#false]] %[[#unreachable]] %[[#for_cond1]]
52
53  ; CHECK: %[[#unreachable]] = OpLabel
54  ; CHECK-NEXT:                OpUnreachable
55
56for.body:                                         ; preds = %for.cond
57  %4 = load i32, ptr %i, align 4
58  store i32 %4, ptr %val, align 4
59  br label %for.inc
60  ; CHECK: %[[#for_body]] = OpLabel
61  ; CHECK:                 OpBranch %[[#for_inc]]
62
63for.inc:                                          ; preds = %for.body
64  %5 = load i32, ptr %i, align 4
65  %inc = add nsw i32 %5, 1
66  store i32 %inc, ptr %i, align 4
67  br label %for.cond
68  ; CHECK: %[[#for_inc]] = OpLabel
69  ; CHECK:                 OpBranch %[[#for_cond]]
70
71
72}
73
74; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)
75declare token @llvm.experimental.convergence.entry() #1
76
77; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)
78declare token @llvm.experimental.convergence.loop() #1
79
80; Function Attrs: convergent noinline norecurse nounwind optnone
81define internal spir_func void @main() #2 {
82entry:
83  %0 = call token @llvm.experimental.convergence.entry()
84  %call1 = call spir_func noundef i32 @_Z7processv() #4 [ "convergencectrl"(token %0) ]
85  ret void
86}
87
88; Function Attrs: convergent norecurse
89define void @main.1() #3 {
90entry:
91  call void @main()
92  ret void
93}
94
95attributes #0 = { convergent noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
96attributes #1 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
97attributes #2 = { convergent noinline norecurse nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
98attributes #3 = { convergent norecurse "frame-pointer"="all" "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
99attributes #4 = { convergent }
100
101!llvm.module.flags = !{!0, !1, !2}
102
103!0 = !{i32 1, !"wchar_size", i32 4}
104!1 = !{i32 4, !"dx.disable_optimizations", i32 1}
105!2 = !{i32 7, !"frame-pointer", i32 2}
106