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(i64 %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 %cmp = icmp eq i64 ptrtoint (ptr @inner9a to i64), ptrtoint(ptr @dummy9 to i64)
192 store volatile i1 %cmp, ptr %sink
193 ; CHECK: store volatile
194 call void @inner9a(i1 false)
195 ; CHECK-NOT: call void @inner9a
197 ; Next we call @inner9b passing in a constant expression. This constant
198 ; expression will in fact be removed by inlining, so we should also be able
199 ; to delete the function.
200 call void @inner9b(i64 ptrtoint (ptr @inner9b to i64))
201 ; CHECK-NOT: @inner9b
207 ; The 'inner10' and 'outer10' functions test a frustrating consequence of the
208 ; current 'alwaysinline' semantic model. Because such functions are allowed to
209 ; be external functions, it may be necessary to both inline all of their uses
210 ; and leave them in the final output. These tests can be removed if and when
211 ; we restrict alwaysinline further.
212 define void @inner10() alwaysinline {
213 ; CHECK-LABEL: @inner10(
218 define void @outer10() {
219 ; CHECK-LABEL: @outer10(
222 ; CHECK-NOT: call void @inner10
228 ; The 'inner11' and 'outer11' functions test another dimension of non-internal
229 ; functions with alwaysinline. These functions use external linkages that we can
230 ; actually remove safely and so we should.
231 define linkonce void @inner11a() alwaysinline {
232 ; CHECK-NOT: @inner11a(
237 define available_externally void @inner11b() alwaysinline {
238 ; CHECK-NOT: @inner11b(
243 define void @outer11() {
244 ; CHECK-LABEL: @outer11(
246 call void @inner11a()
247 call void @inner11b()
248 ; CHECK-NOT: call void @inner11a
249 ; CHECK-NOT: call void @inner11b
255 ; The 'inner12' and 'outer12' functions test that we don't remove functions
256 ; which are part of a comdat group even if they otherwise seem dead.
257 $comdat12 = comdat any
259 define linkonce void @inner12() alwaysinline comdat($comdat12) {
260 ; CHECK-LABEL: @inner12(
264 define void @outer12() comdat($comdat12) {
265 ; CHECK-LABEL: @outer12(
268 ; CHECK-NOT: call void @inner12
274 ; The 'inner13*' and 'outer13' functions test that we do remove functions
275 ; which are part of a comdat group where all of the members are removed during
277 $comdat13 = comdat any
279 define linkonce void @inner13a() alwaysinline comdat($comdat13) {
280 ; CHECK-NOT: @inner13a(
284 define linkonce void @inner13b() alwaysinline comdat($comdat13) {
285 ; CHECK-NOT: @inner13b(
289 define void @outer13() {
290 ; CHECK-LABEL: @outer13(
292 call void @inner13a()
293 call void @inner13b()
294 ; CHECK-NOT: call void @inner13a
295 ; CHECK-NOT: call void @inner13b
301 define void @inner14() readnone nounwind {
302 ; CHECK: define void @inner14
306 define void @outer14() {
307 ; CHECK: call void @inner14
312 define internal i32 @inner15() {
317 define i32 @outer15() {
318 ; CHECK-LABEL: @outer15(
321 %r = call i32 @inner15() noinline
325 define internal i32 @inner16() alwaysinline {
330 define i32 @outer16() {
331 ; CHECK-LABEL: @outer16(
334 %r = call i32 @inner16() noinline
338 define i32 @inner17() alwaysinline {
343 define i32 @outer17() {
344 ; CHECK-LABEL: @outer17(
347 %r = call i32 @inner17() noinline
351 define i32 @inner18() noinline {
356 define i32 @outer18() {
357 ; CHECK-LABEL: @outer18(
361 %r = call i32 @inner18() alwaysinline