blob: 5ad1bde3e2d21b7ec65332ba0e4ed948eaede89a [file] [log] [blame]
Chandler Carruth1989bb92012-04-01 10:11:17 +00001; RUN: opt < %s -inline-threshold=0 -always-inline -S | FileCheck %s
2;
3; Ensure the threshold has no impact on these decisions.
4; RUN: opt < %s -inline-threshold=20000000 -always-inline -S | FileCheck %s
5; RUN: opt < %s -inline-threshold=-20000000 -always-inline -S | FileCheck %s
6
7define i32 @inner1() alwaysinline {
8 ret i32 1
9}
10define i32 @outer1() {
Stephen Linc1c7a132013-07-14 01:42:54 +000011; CHECK-LABEL: @outer1(
Chandler Carruth1989bb92012-04-01 10:11:17 +000012; CHECK-NOT: call
13; CHECK: ret
14
15 %r = call i32 @inner1()
16 ret i32 %r
17}
18
19; The always inliner can't DCE internal functions. PR2945
Stephen Linc1c7a132013-07-14 01:42:54 +000020; CHECK-LABEL: @pr2945(
Chandler Carruth1989bb92012-04-01 10:11:17 +000021define internal i32 @pr2945() nounwind {
22 ret i32 0
23}
24
25define internal void @inner2(i32 %N) alwaysinline {
26 %P = alloca i32, i32 %N
27 ret void
28}
29define void @outer2(i32 %N) {
30; The always inliner (unlike the normal one) should be willing to inline
31; a function with a dynamic alloca into one without a dynamic alloca.
32; rdar://6655932
33;
Stephen Linc1c7a132013-07-14 01:42:54 +000034; CHECK-LABEL: @outer2(
Chandler Carruth1989bb92012-04-01 10:11:17 +000035; CHECK-NOT: call void @inner2
Chandler Carruth1989bb92012-04-01 10:11:17 +000036; CHECK-NOT: call void @inner2
37; CHECK: ret void
38
39 call void @inner2( i32 %N )
40 ret void
41}
Chandler Carruthc5bfb3c2012-04-01 10:21:05 +000042
43declare i32 @a() returns_twice
44declare i32 @b() returns_twice
45
46define i32 @inner3() alwaysinline {
47entry:
48 %call = call i32 @a() returns_twice
49 %add = add nsw i32 1, %call
50 ret i32 %add
51}
52define i32 @outer3() {
53entry:
Stephen Linc1c7a132013-07-14 01:42:54 +000054; CHECK-LABEL: @outer3(
Chandler Carruthc5bfb3c2012-04-01 10:21:05 +000055; CHECK-NOT: call i32 @a
56; CHECK: ret
57
58 %call = call i32 @inner3()
59 %add = add nsw i32 1, %call
60 ret i32 %add
61}
62
63define i32 @inner4() alwaysinline returns_twice {
64entry:
65 %call = call i32 @b() returns_twice
66 %add = add nsw i32 1, %call
67 ret i32 %add
68}
69
70define i32 @outer4() {
71entry:
Stephen Linc1c7a132013-07-14 01:42:54 +000072; CHECK-LABEL: @outer4(
Chandler Carruthc5bfb3c2012-04-01 10:21:05 +000073; CHECK: call i32 @b()
74; CHECK: ret
75
76 %call = call i32 @inner4() returns_twice
77 %add = add nsw i32 1, %call
78 ret i32 %add
79}
Chandler Carruthcdb1f8c2012-04-01 10:36:17 +000080
Gerolf Hoflehnerecebc372014-04-17 19:14:06 +000081define i32 @inner5(i8* %addr) alwaysinline {
Chandler Carruthcdb1f8c2012-04-01 10:36:17 +000082entry:
83 indirectbr i8* %addr, [ label %one, label %two ]
84
85one:
86 ret i32 42
87
88two:
89 ret i32 44
90}
91define i32 @outer5(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +000092; CHECK-LABEL: @outer5(
Chandler Carruthcdb1f8c2012-04-01 10:36:17 +000093; CHECK: call i32 @inner5
94; CHECK: ret
95
96 %cmp = icmp slt i32 %x, 42
97 %addr = select i1 %cmp, i8* blockaddress(@inner5, %one), i8* blockaddress(@inner5, %two)
98 %call = call i32 @inner5(i8* %addr)
99 ret i32 %call
100}
101
102define void @inner6(i32 %x) alwaysinline {
103entry:
104 %icmp = icmp slt i32 %x, 0
105 br i1 %icmp, label %return, label %bb
106
107bb:
108 %sub = sub nsw i32 %x, 1
109 call void @inner6(i32 %sub)
110 ret void
111
112return:
113 ret void
114}
115define void @outer6() {
Stephen Linc1c7a132013-07-14 01:42:54 +0000116; CHECK-LABEL: @outer6(
Chandler Carruthcdb1f8c2012-04-01 10:36:17 +0000117; CHECK: call void @inner6(i32 42)
118; CHECK: ret
119
120entry:
121 call void @inner6(i32 42)
122 ret void
123}
124
Peter Collingbourne68a88972014-05-19 18:25:54 +0000125define i32 @inner7() {
126 ret i32 1
127}
128define i32 @outer7() {
129; CHECK-LABEL: @outer7(
130; CHECK-NOT: call
131; CHECK: ret
132
133 %r = call i32 @inner7() alwaysinline
134 ret i32 %r
135}