xref: /llvm-project/llvm/test/Transforms/Inline/inline-stacksize.ll (revision 151602c7a9935558ca671b35359989b261045db0)
1; Check the inliner doesn't inline a function with a stack size exceeding a given limit.
2; RUN: opt < %s -passes=inline -S | FileCheck --check-prefixes=ALL,UNLIMITED %s
3; RUN: opt < %s -passes=inline -S -inline-max-stacksize=256 | FileCheck --check-prefixes=ALL,LIMITED %s
4
5declare void @init(ptr)
6
7define internal i32 @foo() {
8  %1 = alloca [65 x i32], align 16
9  call void @init(ptr %1)
10  %2 = load i32, ptr %1, align 4
11  ret i32 %2
12}
13
14define i32 @barNoAttr() {
15  %1 = call i32 @foo()
16  ret i32 %1
17; ALL: define {{.*}}@barNoAttr
18; ALL-NOT: define
19; UNLIMITED-NOT: call {{.*}}@foo
20; LIMITED: call {{.*}}@foo
21}
22
23; Check that, under the imposed limit, baz() inlines bar(), but not foo().
24define i32 @bazNoAttr() {
25  %1 = call i32 @barNoAttr()
26  ret i32 %1
27; ALL: define {{.*}}@baz
28; UNLIMITED-NOT: call {{.*}}@barNoAttr
29; UNLIMITED-NOT: call {{.*}}@foo
30; LIMITED-NOT: call {{.*}}@barNoAttr
31; LIMITED: call {{.*}}@foo
32}
33
34; Check that the function attribute prevents inlining of foo().
35define i32 @barAttr() #0 {
36  %1 = call i32 @foo()
37  ret i32 %1
38; ALL: define {{.*}}@barAttr
39; ALL-NOT: define
40; ALL: call {{.*}}@foo
41}
42
43; Check that the commandline option overrides the function attribute.
44define i32 @bazAttr() #1 {
45  %1 = call i32 @barAttr()
46  ret i32 %1
47; ALL: define {{.*}}@bazAttr
48; UNLIMITED-NOT: call {{.*}}@barAttr
49; UNLIMITED-NOT: call {{.*}}@foo
50; LIMITED: call {{.*}}@foo
51}
52
53attributes #0 = { "inline-max-stacksize"="256" }
54attributes #1 = { "inline-max-stacksize"="512" }
55