1 ; RUN: opt < %s -inline-threshold=0 -always-inline -enable-new-pm=0 -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 -enable-new-pm=0 -S | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
5 ; RUN: opt < %s -inline-threshold=-20000000 -always-inline -enable-new-pm=0 -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 -inline-threshold=0 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
13 ; RUN: opt < %s -inline-threshold=20000000 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
14 ; RUN: opt < %s -inline-threshold=-20000000 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
16 define internal i32 @inner1() alwaysinline {
20 define i32 @outer1() {
21 ; CHECK-LABEL: @outer1(
25 %r = call i32 @inner1()
29 ; The always inliner can't DCE arbitrary internal functions. PR2945
30 define internal i32 @pr2945() nounwind {
31 ; CHECK-LABEL: @pr2945(
35 define internal void @inner2(i32 %N) alwaysinline {
37 %P = alloca i32, i32 %N
40 define void @outer2(i32 %N) {
41 ; The always inliner (unlike the normal one) should be willing to inline
42 ; a function with a dynamic alloca into one without a dynamic alloca.
45 ; CHECK-LABEL: @outer2(
46 ; CHECK-NOT: call void @inner2
47 ; CHECK-NOT: call void @inner2
50 call void @inner2( i32 %N )
54 declare i32 @a() returns_twice
55 declare i32 @b() returns_twice
57 ; Cannot alwaysinline when that would introduce a returns_twice call.
58 define internal i32 @inner3() alwaysinline {
59 ; CHECK-LABEL: @inner3(
61 %call = call i32 @a() returns_twice
62 %add = add nsw i32 1, %call
65 define i32 @outer3() {
67 ; CHECK-LABEL: @outer3(
68 ; CHECK-NOT: call i32 @a
71 %call = call i32 @inner3()
72 %add = add nsw i32 1, %call
76 define internal i32 @inner4() alwaysinline returns_twice {
79 %call = call i32 @b() returns_twice
80 %add = add nsw i32 1, %call
84 define i32 @outer4() {
86 ; CHECK-LABEL: @outer4(
87 ; CHECK: call i32 @b()
90 %call = call i32 @inner4() returns_twice
91 %add = add nsw i32 1, %call
95 ; We can't inline this even though it has alwaysinline!
96 define internal i32 @inner5(i8* %addr) alwaysinline {
97 ; CHECK-LABEL: @inner5(
99 indirectbr i8* %addr, [ label %one, label %two ]
107 define i32 @outer5(i32 %x) {
108 ; CHECK-LABEL: @outer5(
109 ; CHECK: call i32 @inner5
112 %cmp = icmp slt i32 %x, 42
113 %addr = select i1 %cmp, i8* blockaddress(@inner5, %one), i8* blockaddress(@inner5, %two)
114 %call = call i32 @inner5(i8* %addr)
118 ; We alwaysinline a function that call itself recursively.
119 define internal void @inner6(i32 %x) alwaysinline {
120 ; CHECK-LABEL: @inner6(
122 %icmp = icmp slt i32 %x, 0
123 br i1 %icmp, label %return, label %bb
126 %sub = sub nsw i32 %x, 1
127 call void @inner6(i32 %sub)
133 define void @outer6() {
134 ; CHECK-LABEL: @outer6(
135 ; CHECK: call void @inner6(i32 42)
139 call void @inner6(i32 42)
143 ; This is not an alwaysinline function and is actually external.
144 define i32 @inner7() {
145 ; CHECK-LABEL: @inner7(
148 define i32 @outer7() {
149 ; CHECK-CALL-LABEL: @outer7(
150 ; CHECK-CALL-NOT: call
153 %r = call i32 @inner7() alwaysinline
157 define internal float* @inner8(float* nocapture align 128 %a) alwaysinline {
158 ; CHECK-NOT: @inner8(
161 define float @outer8(float* nocapture %a) {
162 ; CHECK-LABEL: @outer8(
163 ; CHECK-NOT: call float* @inner8
166 %inner_a = call float* @inner8(float* %a)
167 %f = load float, float* %inner_a, align 4
172 ; The 'inner9*' and 'outer9' functions are designed to check that we remove
173 ; a function that is inlined by the always inliner even when it is used by
174 ; a complex constant expression prior to being inlined.
176 ; The 'a' function gets used in a complex constant expression that, despite
177 ; being constant folded, means it isn't dead. As a consequence it shouldn't be
178 ; deleted. If it is, then the constant expression needs to become more complex
179 ; to accurately test this scenario.
180 define internal void @inner9a(i1 %b) alwaysinline {
181 ; CHECK-LABEL: @inner9a(
186 define internal void @inner9b(i1 %b) alwaysinline {
187 ; CHECK-NOT: @inner9b(
192 declare void @dummy9(i1 %b)
194 define void @outer9() {
195 ; CHECK-LABEL: @outer9(
197 ; First we use @inner9a in a complex constant expression that may get folded
198 ; but won't get removed, and then we call it which will get inlined. Despite
199 ; this the function can't be deleted because of the constant expression
202 store volatile i1 icmp eq (i64 ptrtoint (void (i1)* @inner9a to i64), i64 ptrtoint(void (i1)* @dummy9 to i64)), i1* %sink
203 ; CHECK: store volatile
204 call void @inner9a(i1 false)
205 ; CHECK-NOT: call void @inner9a
207 ; Next we call @inner9b passing in a constant expression. This constant
208 ; expression will in fact be removed by inlining, so we should also be able
209 ; to delete the function.
210 call void @inner9b(i1 icmp eq (i64 ptrtoint (void (i1)* @inner9b to i64), i64 ptrtoint(void (i1)* @dummy9 to i64)))
211 ; CHECK-NOT: @inner9b
217 ; The 'inner10' and 'outer10' functions test a frustrating consequence of the
218 ; current 'alwaysinline' semantic model. Because such functions are allowed to
219 ; be external functions, it may be necessary to both inline all of their uses
220 ; and leave them in the final output. These tests can be removed if and when
221 ; we restrict alwaysinline further.
222 define void @inner10() alwaysinline {
223 ; CHECK-LABEL: @inner10(
228 define void @outer10() {
229 ; CHECK-LABEL: @outer10(
232 ; CHECK-NOT: call void @inner10
238 ; The 'inner11' and 'outer11' functions test another dimension of non-internal
239 ; functions with alwaysinline. These functions use external linkages that we can
240 ; actually remove safely and so we should.
241 define linkonce void @inner11a() alwaysinline {
242 ; CHECK-NOT: @inner11a(
247 define available_externally void @inner11b() alwaysinline {
248 ; CHECK-NOT: @inner11b(
253 define void @outer11() {
254 ; CHECK-LABEL: @outer11(
256 call void @inner11a()
257 call void @inner11b()
258 ; CHECK-NOT: call void @inner11a
259 ; CHECK-NOT: call void @inner11b
265 ; The 'inner12' and 'outer12' functions test that we don't remove functions
266 ; which are part of a comdat group even if they otherwise seem dead.
267 $comdat12 = comdat any
269 define linkonce void @inner12() alwaysinline comdat($comdat12) {
270 ; CHECK-LABEL: @inner12(
274 define void @outer12() comdat($comdat12) {
275 ; CHECK-LABEL: @outer12(
278 ; CHECK-NOT: call void @inner12
284 ; The 'inner13*' and 'outer13' functions test that we do remove functions
285 ; which are part of a comdat group where all of the members are removed during
287 $comdat13 = comdat any
289 define linkonce void @inner13a() alwaysinline comdat($comdat13) {
290 ; CHECK-NOT: @inner13a(
294 define linkonce void @inner13b() alwaysinline comdat($comdat13) {
295 ; CHECK-NOT: @inner13b(
299 define void @outer13() {
300 ; CHECK-LABEL: @outer13(
302 call void @inner13a()
303 call void @inner13b()
304 ; CHECK-NOT: call void @inner13a
305 ; CHECK-NOT: call void @inner13b
311 define void @inner14() readnone nounwind {
312 ; CHECK: define void @inner14
316 define void @outer14() {
317 ; CHECK: call void @inner14