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