1 ; RUN: opt < %s -inline-threshold=0 -always-inline -S | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
3 ; Ensure the threshold has no impact on these decisions.
4 ; RUN: opt < %s -inline-threshold=20000000 -always-inline -S | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
5 ; RUN: opt < %s -inline-threshold=-20000000 -always-inline -S | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
7 ; The new pass manager doesn't re-use any threshold based infrastructure for
8 ; the always inliner, but test that we get the correct result. The new PM
9 ; always inliner also doesn't support inlining call-site alwaysinline
10 ; annotations. It isn't clear that this is a reasonable use case for
12 ; RUN: opt < %s -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
14 define internal i32 @inner1() alwaysinline {
18 define i32 @outer1() {
19 ; CHECK-LABEL: @outer1(
23 %r = call i32 @inner1()
27 ; The always inliner can't DCE arbitrary internal functions. PR2945
28 define internal i32 @pr2945() nounwind {
29 ; CHECK-LABEL: @pr2945(
33 define internal void @inner2(i32 %N) alwaysinline {
35 %P = alloca i32, i32 %N
38 define void @outer2(i32 %N) {
39 ; The always inliner (unlike the normal one) should be willing to inline
40 ; a function with a dynamic alloca into one without a dynamic alloca.
43 ; CHECK-LABEL: @outer2(
44 ; CHECK-NOT: call void @inner2
45 ; CHECK-NOT: call void @inner2
48 call void @inner2( i32 %N )
52 declare i32 @a() returns_twice
53 declare i32 @b() returns_twice
55 ; Cannot alwaysinline when that would introduce a returns_twice call.
56 define internal i32 @inner3() alwaysinline {
57 ; CHECK-LABEL: @inner3(
59 %call = call i32 @a() returns_twice
60 %add = add nsw i32 1, %call
63 define i32 @outer3() {
65 ; CHECK-LABEL: @outer3(
66 ; CHECK-NOT: call i32 @a
69 %call = call i32 @inner3()
70 %add = add nsw i32 1, %call
74 define internal i32 @inner4() alwaysinline returns_twice {
77 %call = call i32 @b() returns_twice
78 %add = add nsw i32 1, %call
82 define i32 @outer4() {
84 ; CHECK-LABEL: @outer4(
85 ; CHECK: call i32 @b()
88 %call = call i32 @inner4() returns_twice
89 %add = add nsw i32 1, %call
93 ; We can't inline this even though it has alwaysinline!
94 define internal i32 @inner5(i8* %addr) alwaysinline {
95 ; CHECK-LABEL: @inner5(
97 indirectbr i8* %addr, [ label %one, label %two ]
105 define i32 @outer5(i32 %x) {
106 ; CHECK-LABEL: @outer5(
107 ; CHECK: call i32 @inner5
110 %cmp = icmp slt i32 %x, 42
111 %addr = select i1 %cmp, i8* blockaddress(@inner5, %one), i8* blockaddress(@inner5, %two)
112 %call = call i32 @inner5(i8* %addr)
116 ; We alwaysinline a function that call itself recursively.
117 define internal void @inner6(i32 %x) alwaysinline {
118 ; CHECK-LABEL: @inner6(
120 %icmp = icmp slt i32 %x, 0
121 br i1 %icmp, label %return, label %bb
124 %sub = sub nsw i32 %x, 1
125 call void @inner6(i32 %sub)
131 define void @outer6() {
132 ; CHECK-LABEL: @outer6(
133 ; CHECK: call void @inner6(i32 42)
137 call void @inner6(i32 42)
141 ; This is not an alwaysinline function and is actually external.
142 define i32 @inner7() {
143 ; CHECK-LABEL: @inner7(
146 define i32 @outer7() {
147 ; CHECK-CALL-LABEL: @outer7(
148 ; CHECK-CALL-NOT: call
151 %r = call i32 @inner7() alwaysinline
155 define internal float* @inner8(float* nocapture align 128 %a) alwaysinline {
156 ; CHECK-NOT: @inner8(
159 define float @outer8(float* nocapture %a) {
160 ; CHECK-LABEL: @outer8(
161 ; CHECK-NOT: call float* @inner8
164 %inner_a = call float* @inner8(float* %a)
165 %f = load float, float* %inner_a, align 4
170 ; The 'inner9*' and 'outer9' functions are designed to check that we remove
171 ; a function that is inlined by the always inliner even when it is used by
172 ; a complex constant expression prior to being inlined.
174 ; The 'a' function gets used in a complex constant expression that, despite
175 ; being constant folded, means it isn't dead. As a consequence it shouldn't be
176 ; deleted. If it is, then the constant expression needs to become more complex
177 ; to accurately test this scenario.
178 define internal void @inner9a(i1 %b) alwaysinline {
179 ; CHECK-LABEL: @inner9a(
184 define internal void @inner9b(i1 %b) alwaysinline {
185 ; CHECK-NOT: @inner9b(
190 declare void @dummy9(i1 %b)
192 define void @outer9() {
193 ; CHECK-LABEL: @outer9(
195 ; First we use @inner9a in a complex constant expression that may get folded
196 ; but won't get removed, and then we call it which will get inlined. Despite
197 ; this the function can't be deleted because of the constant expression
200 store volatile i1 icmp eq (i64 ptrtoint (void (i1)* @inner9a to i64), i64 ptrtoint(void (i1)* @dummy9 to i64)), i1* %sink
201 ; CHECK: store volatile
202 call void @inner9a(i1 false)
203 ; CHECK-NOT: call void @inner9a
205 ; Next we call @inner9b passing in a constant expression. This constant
206 ; expression will in fact be removed by inlining, so we should also be able
207 ; to delete the function.
208 call void @inner9b(i1 icmp eq (i64 ptrtoint (void (i1)* @inner9b to i64), i64 ptrtoint(void (i1)* @dummy9 to i64)))
209 ; CHECK-NOT: @inner9b
215 ; The 'inner10' and 'outer10' functions test a frustrating consquence of the
216 ; current 'alwaysinline' semantic model. Because such functions are allowed to
217 ; be external functions, it may be necessary to both inline all of their uses
218 ; and leave them in the final output. These tests can be removed if and when
219 ; we restrict alwaysinline further.
220 define void @inner10() alwaysinline {
221 ; CHECK-LABEL: @inner10(
226 define void @outer10() {
227 ; CHECK-LABEL: @outer10(
230 ; CHECK-NOT: call void @inner10
236 ; The 'inner11' and 'outer11' functions test another dimension of non-internal
237 ; functions with alwaysinline. These functions use external linkages that we can
238 ; actually remove safely and so we should.
239 define linkonce void @inner11a() alwaysinline {
240 ; CHECK-NOT: @inner11a(
245 define available_externally void @inner11b() alwaysinline {
246 ; CHECK-NOT: @inner11b(
251 define void @outer11() {
252 ; CHECK-LABEL: @outer11(
254 call void @inner11a()
255 call void @inner11b()
256 ; CHECK-NOT: call void @inner11a
257 ; CHECK-NOT: call void @inner11b
263 ; The 'inner12' and 'outer12' functions test that we don't remove functions
264 ; which are part of a comdat group even if they otherwise seem dead.
265 $comdat12 = comdat any
267 define linkonce void @inner12() alwaysinline comdat($comdat12) {
268 ; CHECK-LABEL: @inner12(
272 define void @outer12() comdat($comdat12) {
273 ; CHECK-LABEL: @outer12(
276 ; CHECK-NOT: call void @inner12
282 ; The 'inner13*' and 'outer13' functions test that we do remove functions
283 ; which are part of a comdat group where all of the members are removed during
285 $comdat13 = comdat any
287 define linkonce void @inner13a() alwaysinline comdat($comdat13) {
288 ; CHECK-NOT: @inner13a(
292 define linkonce void @inner13b() alwaysinline comdat($comdat13) {
293 ; CHECK-NOT: @inner13b(
297 define void @outer13() {
298 ; CHECK-LABEL: @outer13(
300 call void @inner13a()
301 call void @inner13b()
302 ; CHECK-NOT: call void @inner13a
303 ; CHECK-NOT: call void @inner13b
309 define void @inner14() readnone nounwind {
310 ; CHECK: define void @inner14
314 define void @outer14() {
315 ; CHECK: call void @inner14