xref: /llvm-project/llvm/test/Transforms/Inline/recursive.ll (revision 151602c7a9935558ca671b35359989b261045db0)
1; Inlining in the presence of recursion presents special challenges that we
2; test here.
3;
4; RUN: opt -passes=inline -S < %s | FileCheck %s
5; RUN: opt -passes='cgscc(inline)' -S < %s | FileCheck %s
6
7define i32 @large_stack_callee(i32 %param) {
8; CHECK-LABEL: define i32 @large_stack_callee(
9entry:
10 %yyy = alloca [100000 x i8]
11 call void @bar(ptr %yyy)
12 ret i32 4
13}
14
15; Test a recursive function which calls another function with a large stack. In
16; addition to not inlining the recursive call, we should also not inline the
17; large stack allocation into a potentially recursive frame.
18define i32 @large_stack_recursive_caller(i32 %param) {
19; CHECK-LABEL: define i32 @large_stack_recursive_caller(
20entry:
21; CHECK-NEXT: entry:
22; CHECK-NOT: alloca
23  %t = call i32 @foo(i32 %param)
24  %cmp = icmp eq i32 %t, -1
25  br i1 %cmp, label %exit, label %cont
26
27cont:
28  %r = call i32 @large_stack_recursive_caller(i32 %t)
29; CHECK: call i32 @large_stack_recursive_caller
30  %f = call i32 @large_stack_callee(i32 %r)
31; CHECK: call i32 @large_stack_callee
32  br label %exit
33
34exit:
35  ret i32 4
36}
37
38declare void @bar(ptr %in)
39
40declare i32 @foo(i32 %param)
41
42; Check that when inlining a non-recursive path into a function's own body that
43; we get the re-mapping of instructions correct.
44define i32 @test_recursive_inlining_remapping(i1 %init, ptr %addr) {
45; CHECK-LABEL: define i32 @test_recursive_inlining_remapping(
46bb:
47  %n = alloca i32
48  br i1 %init, label %store, label %load
49; CHECK-NOT:     alloca
50;
51; CHECK:         %[[N:.*]] = alloca i32
52; CHECK-NEXT:    br i1 %init,
53
54store:
55  store i32 0, ptr %n
56  %v = call i32 @test_recursive_inlining_remapping(i1 false, ptr %n)
57  ret i32 %v
58; CHECK-NOT:     call
59;
60; CHECK:         store i32 0, ptr %[[N]]
61; CHECK-NEXT:    %[[INLINED_LOAD:.*]] = load i32, ptr %[[N]]
62; CHECK-NEXT:    ret i32 %[[INLINED_LOAD]]
63;
64; CHECK-NOT:     call
65
66load:
67  %n.load = load i32, ptr %addr
68  ret i32 %n.load
69}
70