1 ; The new pass manager doesn't re-use any threshold based infrastructure for
2 ; the always inliner, but test that we get the correct result.
3 ; RUN: opt < %s -inline-threshold=0 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
4 ; RUN: opt < %s -inline-threshold=20000000 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
5 ; RUN: opt < %s -inline-threshold=-20000000 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
7 define internal i32 @inner1() alwaysinline {
11 define i32 @outer1() {
12 ; CHECK-LABEL: @outer1(
16 %r = call i32 @inner1()
20 ; The always inliner can't DCE arbitrary internal functions. PR2945
21 define internal i32 @pr2945() nounwind {
22 ; CHECK-LABEL: @pr2945(
26 define internal void @inner2(i32 %N) alwaysinline {
28 %P = alloca i32, i32 %N
31 define void @outer2(i32 %N) {
32 ; The always inliner (unlike the normal one) should be willing to inline
33 ; a function with a dynamic alloca into one without a dynamic alloca.
36 ; CHECK-LABEL: @outer2(
37 ; CHECK-NOT: call void @inner2
40 call void @inner2( i32 %N )
44 declare i32 @a() returns_twice
45 declare i32 @b() returns_twice
47 ; Cannot alwaysinline when that would introduce a returns_twice call.
48 define internal i32 @inner3() alwaysinline {
49 ; CHECK-LABEL: @inner3(
51 %call = call i32 @a() returns_twice
52 %add = add nsw i32 1, %call
55 define i32 @outer3() {
57 ; CHECK-LABEL: @outer3(
58 ; CHECK-NOT: call i32 @a
61 %call = call i32 @inner3()
62 %add = add nsw i32 1, %call
66 define internal i32 @inner4() alwaysinline returns_twice {
69 %call = call i32 @b() returns_twice
70 %add = add nsw i32 1, %call
74 define i32 @outer4() {
76 ; CHECK-LABEL: @outer4(
77 ; CHECK: call i32 @b()
80 %call = call i32 @inner4() returns_twice
81 %add = add nsw i32 1, %call
85 ; We can't inline this even though it has alwaysinline!
86 define internal i32 @inner5(ptr %addr) alwaysinline {
87 ; CHECK-LABEL: @inner5(
89 indirectbr ptr %addr, [ label %one, label %two ]
97 define i32 @outer5(i32 %x) {
98 ; CHECK-LABEL: @outer5(
99 ; CHECK: call i32 @inner5
102 %cmp = icmp slt i32 %x, 42
103 %addr = select i1 %cmp, ptr blockaddress(@inner5, %one), ptr blockaddress(@inner5, %two)
104 %call = call i32 @inner5(ptr %addr)
108 ; We never inline a function that calls itself recursively.
109 define internal void @inner6(i32 %x) alwaysinline {
110 ; CHECK-LABEL: @inner6(
112 %icmp = icmp slt i32 %x, 0
113 br i1 %icmp, label %return, label %bb
116 %sub = sub nsw i32 %x, 1
117 call void @inner6(i32 %sub)
123 define void @outer6() {
124 ; CHECK-LABEL: @outer6(
125 ; CHECK: call void @inner6(i32 42)
129 call void @inner6(i32 42)
133 ; This is not an alwaysinline function and is actually external.
134 define i32 @inner7() {
135 ; CHECK-LABEL: @inner7(
138 define i32 @outer7() {
139 ; CHECK-LABEL: @outer7(
142 %r = call i32 @inner7() alwaysinline
146 define internal ptr @inner8(ptr nocapture align 128 %a) alwaysinline {
147 ; CHECK-NOT: @inner8(
150 define float @outer8(ptr nocapture %a) {
151 ; CHECK-LABEL: @outer8(
152 ; CHECK-NOT: call ptr @inner8
155 %inner_a = call ptr @inner8(ptr %a)
156 %f = load float, ptr %inner_a, align 4
161 ; The 'inner9*' and 'outer9' functions are designed to check that we remove
162 ; a function that is inlined by the always inliner even when it is used by
163 ; a complex constant expression prior to being inlined.
165 ; The 'a' function gets used in a complex constant expression that, despite
166 ; being constant folded, means it isn't dead. As a consequence it shouldn't be
167 ; deleted. If it is, then the constant expression needs to become more complex
168 ; to accurately test this scenario.
169 define internal void @inner9a(i1 %b) alwaysinline {
170 ; CHECK-LABEL: @inner9a(
175 define internal void @inner9b(i1 %b) alwaysinline {
176 ; CHECK-NOT: @inner9b(
181 declare void @dummy9(i1 %b)
183 define void @outer9() {
184 ; CHECK-LABEL: @outer9(
186 ; First we use @inner9a in a complex constant expression that may get folded
187 ; but won't get removed, and then we call it which will get inlined. Despite
188 ; this the function can't be deleted because of the constant expression
191 store volatile i1 icmp eq (i64 ptrtoint (ptr @inner9a to i64), i64 ptrtoint(ptr @dummy9 to i64)), ptr %sink
192 ; CHECK: store volatile
193 call void @inner9a(i1 false)
194 ; CHECK-NOT: call void @inner9a
196 ; Next we call @inner9b passing in a constant expression. This constant
197 ; expression will in fact be removed by inlining, so we should also be able
198 ; to delete the function.
199 call void @inner9b(i1 icmp eq (i64 ptrtoint (ptr @inner9b to i64), i64 ptrtoint(ptr @dummy9 to i64)))
200 ; CHECK-NOT: @inner9b
206 ; The 'inner10' and 'outer10' functions test a frustrating consequence of the
207 ; current 'alwaysinline' semantic model. Because such functions are allowed to
208 ; be external functions, it may be necessary to both inline all of their uses
209 ; and leave them in the final output. These tests can be removed if and when
210 ; we restrict alwaysinline further.
211 define void @inner10() alwaysinline {
212 ; CHECK-LABEL: @inner10(
217 define void @outer10() {
218 ; CHECK-LABEL: @outer10(
221 ; CHECK-NOT: call void @inner10
227 ; The 'inner11' and 'outer11' functions test another dimension of non-internal
228 ; functions with alwaysinline. These functions use external linkages that we can
229 ; actually remove safely and so we should.
230 define linkonce void @inner11a() alwaysinline {
231 ; CHECK-NOT: @inner11a(
236 define available_externally void @inner11b() alwaysinline {
237 ; CHECK-NOT: @inner11b(
242 define void @outer11() {
243 ; CHECK-LABEL: @outer11(
245 call void @inner11a()
246 call void @inner11b()
247 ; CHECK-NOT: call void @inner11a
248 ; CHECK-NOT: call void @inner11b
254 ; The 'inner12' and 'outer12' functions test that we don't remove functions
255 ; which are part of a comdat group even if they otherwise seem dead.
256 $comdat12 = comdat any
258 define linkonce void @inner12() alwaysinline comdat($comdat12) {
259 ; CHECK-LABEL: @inner12(
263 define void @outer12() comdat($comdat12) {
264 ; CHECK-LABEL: @outer12(
267 ; CHECK-NOT: call void @inner12
273 ; The 'inner13*' and 'outer13' functions test that we do remove functions
274 ; which are part of a comdat group where all of the members are removed during
276 $comdat13 = comdat any
278 define linkonce void @inner13a() alwaysinline comdat($comdat13) {
279 ; CHECK-NOT: @inner13a(
283 define linkonce void @inner13b() alwaysinline comdat($comdat13) {
284 ; CHECK-NOT: @inner13b(
288 define void @outer13() {
289 ; CHECK-LABEL: @outer13(
291 call void @inner13a()
292 call void @inner13b()
293 ; CHECK-NOT: call void @inner13a
294 ; CHECK-NOT: call void @inner13b
300 define void @inner14() readnone nounwind {
301 ; CHECK: define void @inner14
305 define void @outer14() {
306 ; CHECK: call void @inner14
311 define internal i32 @inner15() {
316 define i32 @outer15() {
317 ; CHECK-LABEL: @outer15(
320 %r = call i32 @inner15() noinline
324 define internal i32 @inner16() alwaysinline {
329 define i32 @outer16() {
330 ; CHECK-LABEL: @outer16(
333 %r = call i32 @inner16() noinline
337 define i32 @inner17() alwaysinline {
342 define i32 @outer17() {
343 ; CHECK-LABEL: @outer17(
346 %r = call i32 @inner17() noinline
350 define i32 @inner18() noinline {
355 define i32 @outer18() {
356 ; CHECK-LABEL: @outer18(
360 %r = call i32 @inner18() alwaysinline