xref: /llvm-project/llvm/test/CodeGen/SPIRV/structurizer/merge-exit-convergence-in-break.ll (revision cba70550ccf55c6ad3daa621bb8caf3c4ca6cbd7)
1; RUN: llc -mtriple=spirv-unknown-vulkan-compute -O0 %s -o - | FileCheck %s --match-full-lines
2; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val %}
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-vulkan-compute"
6
7define internal spir_func void @main() #0 {
8
9; CHECK-DAG:                   OpName %[[#idx:]] "idx"
10; CHECK-DAG:                      OpDecorate %[[#builtin:]] BuiltIn SubgroupLocalInvocationId
11; CHECK-DAG:  %[[#int_ty:]] = OpTypeInt 32 0
12; CHECK-DAG: %[[#bool_ty:]] = OpTypeBool
13; CHECK-DAG:   %[[#int_0:]] = OpConstant %[[#int_ty]] 0
14; CHECK-DAG:  %[[#int_10:]] = OpConstant %[[#int_ty]] 10
15
16; CHECK:   %[[#entry:]] = OpLabel
17; CHECK:      %[[#idx]] = OpVariable %[[#]] Function
18; CHECK:                  OpStore %[[#idx]] %[[#int_0]] Aligned 4
19; CHECK:                  OpBranch %[[#while_cond:]]
20entry:
21  %0 = call token @llvm.experimental.convergence.entry()
22  %idx = alloca i32, align 4
23  store i32 0, ptr %idx, align 4
24  br label %while.cond
25
26; CHECK:   %[[#while_cond]] = OpLabel
27; CHECK:         %[[#tmp:]] = OpLoad %[[#int_ty]] %[[#idx]] Aligned 4
28; CHECK:         %[[#cmp:]] = OpINotEqual %[[#bool_ty]] %[[#tmp]] %[[#int_10]]
29; CHECK:                      OpLoopMerge %[[#new_end:]] %[[#if_end:]] None
30; CHECK:                      OpBranchConditional %[[#cmp]] %[[#while_body:]] %[[#new_end]]
31while.cond:
32  %1 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ]
33  %2 = load i32, ptr %idx, align 4
34  %cmp = icmp ne i32 %2, 10
35  br i1 %cmp, label %while.body, label %while.end
36
37; CHECK:      %[[#while_body]] = OpLabel
38; CHECK-NEXT:       %[[#tmp:]] = OpLoad %[[#int_ty]] %[[#builtin]] Aligned 1
39; CHECK-NEXT:                    OpStore %[[#idx]] %[[#tmp]] Aligned 4
40; CHECK-NEXT:       %[[#tmp:]] = OpLoad %[[#int_ty]] %[[#idx]] Aligned 4
41; CHECK-NEXT:      %[[#cmp1:]] = OpIEqual %[[#bool_ty]] %[[#tmp]] %[[#int_0]]
42; CHECK:                         OpBranchConditional %[[#cmp1]] %[[#if_then:]] %[[#if_end]]
43while.body:
44  %3 = call i32 @__hlsl_wave_get_lane_index() [ "convergencectrl"(token %1) ]
45  store i32 %3, ptr %idx, align 4
46  %4 = load i32, ptr %idx, align 4
47  %cmp1 = icmp eq i32 %4, 0
48  br i1 %cmp1, label %if.then, label %if.end
49
50; CHECK: %[[#if_end]] = OpLabel
51; CHECK:                OpBranch %[[#while_cond]]
52
53; CHECK:      %[[#if_then]] = OpLabel
54; CHECK:         %[[#tmp:]] = OpLoad %[[#int_ty]] %[[#builtin]] Aligned 1
55; CHECK:                      OpStore %[[#idx]] %[[#tmp]] Aligned 4
56; CHECK:                      OpBranch %[[#new_end]]
57if.then:
58  %5 = call i32 @__hlsl_wave_get_lane_index() [ "convergencectrl"(token %1) ]
59  store i32 %5, ptr %idx, align 4
60  br label %while.end
61
62if.end:
63  br label %while.cond
64
65; CHECK:   %[[#new_end]] = OpLabel
66; CHECK:                   OpBranch %[[#while_end:]]
67
68; CHECK: %[[#while_end]] = OpLabel
69; CHECK:                   OpReturn
70while.end:
71  ret void
72
73
74
75}
76
77declare token @llvm.experimental.convergence.entry() #2
78declare token @llvm.experimental.convergence.loop() #2
79declare i32 @__hlsl_wave_get_lane_index() #3
80
81attributes #0 = { convergent noinline norecurse nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
82attributes #1 = { convergent norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
83attributes #2 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
84attributes #3 = { convergent }
85
86!llvm.module.flags = !{!0, !1}
87
88!0 = !{i32 1, !"wchar_size", i32 4}
89!1 = !{i32 4, !"dx.disable_optimizations", i32 1}
90
91