xref: /llvm-project/llvm/test/CodeGen/SPIRV/structurizer/loop-continue-split.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
4; The goal of this test is to voluntarily create 2 overlapping convergence
5; structures: the loop, and the inner condition.
6; Here, the condition header also branches to 2 internal nodes, which are not
7; directly a merge/exits.
8; This will require a proper header-split.
9; In addition, splitting the header makes the continue the merge of the inner
10; condition, so we need to properly split the continue block to create a
11; valid inner merge, in the correct order.
12
13target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
14target triple = "spirv-unknown-vulkan1.3-compute"
15
16; CHECK-DAG:    OpName %[[#switch_0:]] "reg1"
17; CHECK-DAG:    OpName %[[#variable:]] "var"
18
19; CHECK-DAG:    %[[#int_0:]] = OpConstant %[[#]] 0
20; CHECK-DAG:    %[[#int_1:]] = OpConstant %[[#]] 1
21; CHECK-DAG:    %[[#int_2:]] = OpConstant %[[#]] 2
22; CHECK-DAG:    %[[#int_3:]] = OpConstant %[[#]] 3
23; CHECK-DAG:    %[[#int_4:]] = OpConstant %[[#]] 4
24
25define internal spir_func void @main() #1 {
26; CHECK:      %[[#entry:]] = OpLabel
27; CHECK:    %[[#switch_0]] = OpVariable %[[#]] Function
28; CHECK:    %[[#variable]] = OpVariable %[[#]] Function
29; CHECK:                     OpBranch %[[#header:]]
30entry:
31  %0 = call token @llvm.experimental.convergence.entry()
32  %var = alloca i32, align 4
33  br label %header
34
35; CHECK: %[[#header]] = OpLabel
36; CHECK:                OpLoopMerge %[[#merge:]] %[[#continue:]] None
37; CHECK:                OpBranch %[[#split_header:]]
38
39; CHECK: %[[#split_header]] = OpLabel
40; CHECK:                      OpSelectionMerge %[[#inner_merge:]] None
41; CHECK:                      OpBranchConditional %[[#]] %[[#left:]] %[[#right:]]
42header:
43  %2 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ]
44  br i1 true, label %left, label %right
45
46; CHECK:     %[[#right]] = OpLabel
47; CHECK-DAG:               OpStore %[[#switch_0]] %[[#int_0]]
48; CHECK-DAG:               OpStore %[[#variable]] %[[#int_2]]
49; CHECK:                   OpBranchConditional %[[#]] %[[#inner_merge]] %[[#right_next:]]
50right:
51  store i32 2, ptr %var
52  br i1 true, label %merge, label %right_next
53
54; CHECK:     %[[#right_next]] = OpLabel
55; CHECK-DAG:                    OpStore %[[#switch_0]] %[[#int_1]]
56; CHECK-DAG:                    OpStore %[[#variable]] %[[#int_4]]
57; CHECK:                        OpBranch %[[#inner_merge]]
58right_next:
59  store i32 4, ptr %var
60  br label %continue
61
62; CHECK:     %[[#left]] = OpLabel
63; CHECK-DAG:              OpStore %[[#switch_0]] %[[#int_0]]
64; CHECK-DAG:              OpStore %[[#variable]] %[[#int_1]]
65; CHECK:                  OpBranchConditional %[[#]] %[[#inner_merge]] %[[#left_next:]]
66left:
67  store i32 1, ptr %var
68  br i1 true, label %merge, label %left_next
69
70; CHECK:     %[[#left_next]] = OpLabel
71; CHECK-DAG:                   OpStore %[[#switch_0]] %[[#int_1]]
72; CHECK-DAG:                   OpStore %[[#variable]] %[[#int_3]]
73; CHECK:                       OpBranch %[[#inner_merge]]
74left_next:
75  store i32 3, ptr %var
76  br label %continue
77
78; CHECK: %[[#inner_merge]] = OpLabel
79; CHECK:        %[[#tmp:]] = OpLoad %[[#]] %[[#switch_0]]
80; CHECK:       %[[#cond:]] = OpIEqual %[[#]] %[[#int_0]] %[[#tmp]]
81; CHECK:                     OpBranchConditional %[[#cond]] %[[#merge]] %[[#continue]]
82
83; CHECK: %[[#continue]] = OpLabel
84; CHECK:                  OpBranch %[[#header]]
85continue:
86  br label %header
87
88; CHECK: %[[#merge]] = OpLabel
89; CHECK:               OpReturn
90merge:
91  ret void
92}
93
94
95declare token @llvm.experimental.convergence.entry() #0
96declare token @llvm.experimental.convergence.loop() #0
97
98attributes #0 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
99attributes #1 = { convergent noinline norecurse nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
100
101!llvm.module.flags = !{!0, !1}
102
103!0 = !{i32 1, !"wchar_size", i32 4}
104!1 = !{i32 4, !"dx.disable_optimizations", i32 1}
105