[WinEH] Emit state stores for SEH scopes (#116546)
[llvm-project.git] / llvm / test / CodeGen / AMDGPU / recursion.ll
blobc0d228e1254e64bc0fcc194354c01bcc6dd51e4f
1 ; RUN: sed 's/CODE_OBJECT_VERSION/400/g' %s | llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -verify-machineinstrs | FileCheck %s
2 ; RUN: sed 's/CODE_OBJECT_VERSION/500/g' %s | llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -verify-machineinstrs | FileCheck -check-prefixes=V5 %s
3 ; RUN: sed 's/CODE_OBJECT_VERSION/600/g' %s | llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -verify-machineinstrs | FileCheck -check-prefixes=V5 %s
5 ; CHECK-LABEL: {{^}}recursive:
6 ; CHECK: .set recursive.private_seg_size, 16+(max(16384))
7 ; CHECK: ScratchSize: 16
9 ; V5-LABEL: {{^}}recursive:
10 ; V5: .set recursive.has_recursion, 1
11 define void @recursive() {
12   call void @recursive()
13   store volatile i32 0, ptr addrspace(1) undef
14   ret void
17 ; CHECK-LABEL: {{^}}tail_recursive:
18 ; CHECK: .set tail_recursive.private_seg_size, 0
19 ; CHECK: ScratchSize: 0
20 define void @tail_recursive() {
21   tail call void @tail_recursive()
22   ret void
25 ; CHECK: .set calls_tail_recursive.private_seg_size, 0+(max(tail_recursive.private_seg_size))
26 define void @calls_tail_recursive() norecurse {
27   tail call void @tail_recursive()
28   ret void
31 ; CHECK-LABEL: {{^}}tail_recursive_with_stack:
32 ; CHECK: .set tail_recursive_with_stack.private_seg_size, 8
33 ; CHECK: .set tail_recursive_with_stack.has_recursion, 1
34 define void @tail_recursive_with_stack() {
35   %alloca = alloca i32, addrspace(5)
36   store volatile i32 0, ptr addrspace(5) %alloca
37   tail call void @tail_recursive_with_stack()
38   ret void
41 ; For an arbitrary recursive call, report a large number for unknown stack
42 ; usage for code object v4 and older
43 ; CHECK-LABEL: {{^}}calls_recursive:
44 ; CHECK: .set calls_recursive.private_seg_size, 0+(max(16384, recursive.private_seg_size))
46 ; V5-LABEL: {{^}}calls_recursive:
47 ; V5: .set calls_recursive.private_seg_size, 0+(max(recursive.private_seg_size))
48 ; V5: .set calls_recursive.has_dyn_sized_stack, or(0, recursive.has_dyn_sized_stack)
49 define amdgpu_kernel void @calls_recursive() {
50   call void @recursive()
51   ret void
54 ; Make sure we do not report a huge stack size for tail recursive
55 ; functions
56 ; CHECK-LABEL: {{^}}kernel_indirectly_calls_tail_recursive:
57 ; CHECK: .set kernel_indirectly_calls_tail_recursive.private_seg_size, 0+(max(calls_tail_recursive.private_seg_size))
58 define amdgpu_kernel void @kernel_indirectly_calls_tail_recursive() {
59   call void @calls_tail_recursive()
60   ret void
63 ; TODO: Even though tail_recursive is only called as a tail call, we
64 ; end up treating it as generally recursive call from the regular call
65 ; in the kernel.
67 ; CHECK-LABEL: {{^}}kernel_calls_tail_recursive:
68 ; CHECK: .set kernel_calls_tail_recursive.private_seg_size, 0+(max(16384, tail_recursive.private_seg_size))
70 ; V5-LABEL: {{^}}kernel_calls_tail_recursive:
71 ; V5: .set kernel_calls_tail_recursive.private_seg_size, 0+(max(tail_recursive.private_seg_size))
72 ; V5: .set kernel_calls_tail_recursive.has_recursion, or(1, tail_recursive.has_recursion)
73 define amdgpu_kernel void @kernel_calls_tail_recursive() {
74   call void @tail_recursive()
75   ret void
78 ; CHECK-LABEL: {{^}}kernel_calls_tail_recursive_with_stack:
79 ; CHECK: .set kernel_calls_tail_recursive_with_stack.private_seg_size, 0+(max(16384, tail_recursive_with_stack.private_seg_size))
81 ; V5-LABEL: {{^}}kernel_calls_tail_recursive_with_stack:
82 ; V5: .set kernel_calls_tail_recursive_with_stack.private_seg_size, 0+(max(tail_recursive_with_stack.private_seg_size))
83 ; V5: .set kernel_calls_tail_recursive_with_stack.has_dyn_sized_stack, or(0, tail_recursive_with_stack.has_dyn_sized_stack)
84 define amdgpu_kernel void @kernel_calls_tail_recursive_with_stack() {
85   call void @tail_recursive_with_stack()
86   ret void
89 !llvm.module.flags = !{!0}
90 !0 = !{i32 1, !"amdhsa_code_object_version", i32 CODE_OBJECT_VERSION}