1 ; RUN: opt < %s -inline-threshold=0 -always-inline -enable-new-pm=0 -S | FileCheck %s --check-prefix=CHECK
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
5 ; RUN: opt < %s -inline-threshold=-20000000 -always-inline -enable-new-pm=0 -S | FileCheck %s --check-prefix=CHECK
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.
9 ; RUN: opt < %s -inline-threshold=0 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
10 ; RUN: opt < %s -inline-threshold=20000000 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
11 ; RUN: opt < %s -inline-threshold=-20000000 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
13 define internal i32 @inner1() alwaysinline {
17 define i32 @outer1() {
18 ; CHECK-LABEL: @outer1(
22 %r = call i32 @inner1()
26 ; The always inliner can't DCE arbitrary internal functions. PR2945
27 define internal i32 @pr2945() nounwind {
28 ; CHECK-LABEL: @pr2945(
32 define internal void @inner2(i32 %N) alwaysinline {
34 %P = alloca i32, i32 %N
37 define void @outer2(i32 %N) {
38 ; The always inliner (unlike the normal one) should be willing to inline
39 ; a function with a dynamic alloca into one without a dynamic alloca.
42 ; CHECK-LABEL: @outer2(
43 ; CHECK-NOT: call void @inner2
46 call void @inner2( i32 %N )
50 declare i32 @a() returns_twice
51 declare i32 @b() returns_twice
53 ; Cannot alwaysinline when that would introduce a returns_twice call.
54 define internal i32 @inner3() alwaysinline {
55 ; CHECK-LABEL: @inner3(
57 %call = call i32 @a() returns_twice
58 %add = add nsw i32 1, %call
61 define i32 @outer3() {
63 ; CHECK-LABEL: @outer3(
64 ; CHECK-NOT: call i32 @a
67 %call = call i32 @inner3()
68 %add = add nsw i32 1, %call
72 define internal i32 @inner4() alwaysinline returns_twice {
75 %call = call i32 @b() returns_twice
76 %add = add nsw i32 1, %call
80 define i32 @outer4() {
82 ; CHECK-LABEL: @outer4(
83 ; CHECK: call i32 @b()
86 %call = call i32 @inner4() returns_twice
87 %add = add nsw i32 1, %call
91 ; We can't inline this even though it has alwaysinline!
92 define internal i32 @inner5(i8* %addr) alwaysinline {
93 ; CHECK-LABEL: @inner5(
95 indirectbr i8* %addr, [ label %one, label %two ]
103 define i32 @outer5(i32 %x) {
104 ; CHECK-LABEL: @outer5(
105 ; CHECK: call i32 @inner5
108 %cmp = icmp slt i32 %x, 42
109 %addr = select i1 %cmp, i8* blockaddress(@inner5, %one), i8* blockaddress(@inner5, %two)
110 %call = call i32 @inner5(i8* %addr)
114 ; We never inline a function that calls itself recursively.
115 define internal void @inner6(i32 %x) alwaysinline {
116 ; CHECK-LABEL: @inner6(
118 %icmp = icmp slt i32 %x, 0
119 br i1 %icmp, label %return, label %bb
122 %sub = sub nsw i32 %x, 1
123 call void @inner6(i32 %sub)
129 define void @outer6() {
130 ; CHECK-LABEL: @outer6(
131 ; CHECK: call void @inner6(i32 42)
135 call void @inner6(i32 42)
139 ; This is not an alwaysinline function and is actually external.
140 define i32 @inner7() {
141 ; CHECK-LABEL: @inner7(
144 define i32 @outer7() {
145 ; CHECK-LABEL: @outer7(
148 %r = call i32 @inner7() alwaysinline
152 define internal float* @inner8(float* nocapture align 128 %a) alwaysinline {
153 ; CHECK-NOT: @inner8(
156 define float @outer8(float* nocapture %a) {
157 ; CHECK-LABEL: @outer8(
158 ; CHECK-NOT: call float* @inner8
161 %inner_a = call float* @inner8(float* %a)
162 %f = load float, float* %inner_a, align 4
167 ; The 'inner9*' and 'outer9' functions are designed to check that we remove
168 ; a function that is inlined by the always inliner even when it is used by
169 ; a complex constant expression prior to being inlined.
171 ; The 'a' function gets used in a complex constant expression that, despite
172 ; being constant folded, means it isn't dead. As a consequence it shouldn't be
173 ; deleted. If it is, then the constant expression needs to become more complex
174 ; to accurately test this scenario.
175 define internal void @inner9a(i1 %b) alwaysinline {
176 ; CHECK-LABEL: @inner9a(
181 define internal void @inner9b(i1 %b) alwaysinline {
182 ; CHECK-NOT: @inner9b(
187 declare void @dummy9(i1 %b)
189 define void @outer9() {
190 ; CHECK-LABEL: @outer9(
192 ; First we use @inner9a in a complex constant expression that may get folded
193 ; but won't get removed, and then we call it which will get inlined. Despite
194 ; this the function can't be deleted because of the constant expression
197 store volatile i1 icmp eq (i64 ptrtoint (void (i1)* @inner9a to i64), i64 ptrtoint(void (i1)* @dummy9 to i64)), i1* %sink
198 ; CHECK: store volatile
199 call void @inner9a(i1 false)
200 ; CHECK-NOT: call void @inner9a
202 ; Next we call @inner9b passing in a constant expression. This constant
203 ; expression will in fact be removed by inlining, so we should also be able
204 ; to delete the function.
205 call void @inner9b(i1 icmp eq (i64 ptrtoint (void (i1)* @inner9b to i64), i64 ptrtoint(void (i1)* @dummy9 to i64)))
206 ; CHECK-NOT: @inner9b
212 ; The 'inner10' and 'outer10' functions test a frustrating consequence of the
213 ; current 'alwaysinline' semantic model. Because such functions are allowed to
214 ; be external functions, it may be necessary to both inline all of their uses
215 ; and leave them in the final output. These tests can be removed if and when
216 ; we restrict alwaysinline further.
217 define void @inner10() alwaysinline {
218 ; CHECK-LABEL: @inner10(
223 define void @outer10() {
224 ; CHECK-LABEL: @outer10(
227 ; CHECK-NOT: call void @inner10
233 ; The 'inner11' and 'outer11' functions test another dimension of non-internal
234 ; functions with alwaysinline. These functions use external linkages that we can
235 ; actually remove safely and so we should.
236 define linkonce void @inner11a() alwaysinline {
237 ; CHECK-NOT: @inner11a(
242 define available_externally void @inner11b() alwaysinline {
243 ; CHECK-NOT: @inner11b(
248 define void @outer11() {
249 ; CHECK-LABEL: @outer11(
251 call void @inner11a()
252 call void @inner11b()
253 ; CHECK-NOT: call void @inner11a
254 ; CHECK-NOT: call void @inner11b
260 ; The 'inner12' and 'outer12' functions test that we don't remove functions
261 ; which are part of a comdat group even if they otherwise seem dead.
262 $comdat12 = comdat any
264 define linkonce void @inner12() alwaysinline comdat($comdat12) {
265 ; CHECK-LABEL: @inner12(
269 define void @outer12() comdat($comdat12) {
270 ; CHECK-LABEL: @outer12(
273 ; CHECK-NOT: call void @inner12
279 ; The 'inner13*' and 'outer13' functions test that we do remove functions
280 ; which are part of a comdat group where all of the members are removed during
282 $comdat13 = comdat any
284 define linkonce void @inner13a() alwaysinline comdat($comdat13) {
285 ; CHECK-NOT: @inner13a(
289 define linkonce void @inner13b() alwaysinline comdat($comdat13) {
290 ; CHECK-NOT: @inner13b(
294 define void @outer13() {
295 ; CHECK-LABEL: @outer13(
297 call void @inner13a()
298 call void @inner13b()
299 ; CHECK-NOT: call void @inner13a
300 ; CHECK-NOT: call void @inner13b
306 define void @inner14() readnone nounwind {
307 ; CHECK: define void @inner14
311 define void @outer14() {
312 ; CHECK: call void @inner14
317 define internal i32 @inner15() {
322 define i32 @outer15() {
323 ; CHECK-LABEL: @outer15(
326 %r = call i32 @inner15() noinline
330 define internal i32 @inner16() alwaysinline {
335 define i32 @outer16() {
336 ; CHECK-LABEL: @outer16(
339 %r = call i32 @inner16() noinline
343 define i32 @inner17() alwaysinline {
348 define i32 @outer17() {
349 ; CHECK-LABEL: @outer17(
352 %r = call i32 @inner17() noinline
356 define i32 @inner18() noinline {
361 define i32 @outer18() {
362 ; CHECK-LABEL: @outer18(
366 %r = call i32 @inner18() alwaysinline