1 ; RUN: opt < %s -passes='cgscc(inline)' -inline-threshold=0 -S | FileCheck %s
2 ; RUN: opt < %s -passes='cgscc(inline)' -inline-threshold=0 -inline-enable-priority-order=true -S | FileCheck %s
4 ; The 'test1_' prefixed functions test the basic 'last callsite' inline
5 ; threshold adjustment where we specifically inline the last call site of an
6 ; internal function regardless of cost.
8 define internal void @test1_f() {
11 store volatile i32 0, i32* %p
12 store volatile i32 0, i32* %p
13 store volatile i32 0, i32* %p
14 store volatile i32 0, i32* %p
15 store volatile i32 0, i32* %p
16 store volatile i32 0, i32* %p
17 store volatile i32 0, i32* %p
18 store volatile i32 0, i32* %p
22 ; Identical to @test1_f but doesn't get inlined because there is more than one
23 ; call. If this *does* get inlined, the body used both here and in @test1_f
24 ; isn't a good test for different threshold based on the last call.
25 define internal void @test1_g() {
28 store volatile i32 0, i32* %p
29 store volatile i32 0, i32* %p
30 store volatile i32 0, i32* %p
31 store volatile i32 0, i32* %p
32 store volatile i32 0, i32* %p
33 store volatile i32 0, i32* %p
34 store volatile i32 0, i32* %p
35 store volatile i32 0, i32* %p
39 define void @test1() {
40 ; CHECK-LABEL: define void @test1()
47 ; CHECK: call void @test1_g()
48 ; CHECK: call void @test1_g()
54 ; The 'test2_' prefixed functions test that we can discover the last callsite
55 ; bonus after having inlined the prior call site. For this to work, we need
56 ; a callsite dependent cost so we have a trivial predicate guarding all the
57 ; cost, and set that in a particular direction.
59 define internal void @test2_f(i1 %b) {
62 br i1 %b, label %then, label %exit
65 store volatile i32 0, i32* %p
66 store volatile i32 0, i32* %p
67 store volatile i32 0, i32* %p
68 store volatile i32 0, i32* %p
69 store volatile i32 0, i32* %p
70 store volatile i32 0, i32* %p
71 store volatile i32 0, i32* %p
72 store volatile i32 0, i32* %p
79 ; Identical to @test2_f but doesn't get inlined because there is more than one
80 ; call. If this *does* get inlined, the body used both here and in @test2_f
81 ; isn't a good test for different threshold based on the last call.
82 define internal void @test2_g(i1 %b) {
85 br i1 %b, label %then, label %exit
88 store volatile i32 0, i32* %p
89 store volatile i32 0, i32* %p
90 store volatile i32 0, i32* %p
91 store volatile i32 0, i32* %p
92 store volatile i32 0, i32* %p
93 store volatile i32 0, i32* %p
94 store volatile i32 0, i32* %p
95 store volatile i32 0, i32* %p
102 define void @test2() {
103 ; CHECK-LABEL: define void @test2()
105 ; The first call is trivial to inline due to the argument.
106 call void @test2_f(i1 false)
107 ; CHECK-NOT: @test2_f
109 ; The second call is too expensive to inline unless we update the number of
110 ; calls after inlining the second.
111 call void @test2_f(i1 true)
112 ; CHECK-NOT: @test2_f
114 ; Sanity check that two calls with the hard predicate remain uninlined.
115 call void @test2_g(i1 true)
116 call void @test2_g(i1 true)
117 ; CHECK: call void @test2_g(i1 true)
118 ; CHECK: call void @test2_g(i1 true)
124 ; The 'test3_' prefixed functions are similar to the 'test2_' functions but the
125 ; relative order of the trivial and hard to inline callsites is reversed. This
126 ; checks that the order of calls isn't significant to whether we observe the
127 ; "last callsite" threshold difference because the next-to-last gets inlined.
128 ; FIXME: We don't currently catch this case.
130 define internal void @test3_f(i1 %b) {
133 br i1 %b, label %then, label %exit
136 store volatile i32 0, i32* %p
137 store volatile i32 0, i32* %p
138 store volatile i32 0, i32* %p
139 store volatile i32 0, i32* %p
140 store volatile i32 0, i32* %p
141 store volatile i32 0, i32* %p
142 store volatile i32 0, i32* %p
143 store volatile i32 0, i32* %p
150 ; Identical to @test3_f but doesn't get inlined because there is more than one
151 ; call. If this *does* get inlined, the body used both here and in @test3_f
152 ; isn't a good test for different threshold based on the last call.
153 define internal void @test3_g(i1 %b) {
156 br i1 %b, label %then, label %exit
159 store volatile i32 0, i32* %p
160 store volatile i32 0, i32* %p
161 store volatile i32 0, i32* %p
162 store volatile i32 0, i32* %p
163 store volatile i32 0, i32* %p
164 store volatile i32 0, i32* %p
165 store volatile i32 0, i32* %p
166 store volatile i32 0, i32* %p
173 define void @test3() {
174 ; CHECK-LABEL: define void @test3()
176 ; The first call is too expensive to inline unless we update the number of
177 ; calls after inlining the second.
178 call void @test3_f(i1 true)
179 ; FIXME: We should inline this call without iteration.
180 ; CHECK: call void @test3_f(i1 true)
182 ; But the second call is trivial to inline due to the argument.
183 call void @test3_f(i1 false)
184 ; CHECK-NOT: @test3_f
186 ; Sanity check that two calls with the hard predicate remain uninlined.
187 call void @test3_g(i1 true)
188 call void @test3_g(i1 true)
189 ; CHECK: call void @test3_g(i1 true)
190 ; CHECK: call void @test3_g(i1 true)
196 ; The 'test4_' prefixed functions are similar to the 'test2_' prefixed
197 ; functions but include unusual constant expressions that make discovering that
198 ; a function is dead harder.
200 define internal void @test4_f(i1 %b) {
203 br i1 %b, label %then, label %exit
206 store volatile i32 0, i32* %p
207 store volatile i32 0, i32* %p
208 store volatile i32 0, i32* %p
209 store volatile i32 0, i32* %p
210 store volatile i32 0, i32* %p
211 store volatile i32 0, i32* %p
212 store volatile i32 0, i32* %p
213 store volatile i32 0, i32* %p
220 ; Identical to @test4_f but doesn't get inlined because there is more than one
221 ; call. If this *does* get inlined, the body used both here and in @test4_f
222 ; isn't a good test for different threshold based on the last call.
223 define internal void @test4_g(i1 %b) {
226 br i1 %b, label %then, label %exit
229 store volatile i32 0, i32* %p
230 store volatile i32 0, i32* %p
231 store volatile i32 0, i32* %p
232 store volatile i32 0, i32* %p
233 store volatile i32 0, i32* %p
234 store volatile i32 0, i32* %p
235 store volatile i32 0, i32* %p
236 store volatile i32 0, i32* %p
243 define void @test4() {
244 ; CHECK-LABEL: define void @test4()
246 ; The first call is trivial to inline due to the argument. However this
247 ; argument also uses the function being called as part of a complex
248 ; constant expression. Merely inlining and deleting the call isn't enough to
249 ; drop the use count here, we need to GC the dead constant expression as
251 call void @test4_f(i1 icmp ne (i64 ptrtoint (void (i1)* @test4_f to i64), i64 ptrtoint(void (i1)* @test4_f to i64)))
252 ; CHECK-NOT: @test4_f
254 ; The second call is too expensive to inline unless we update the number of
255 ; calls after inlining the second.
256 call void @test4_f(i1 true)
257 ; CHECK-NOT: @test4_f
259 ; And check that a single call to a function which is used by a complex
260 ; constant expression cannot be inlined because the constant expression forms
261 ; a second use. If this part starts failing we need to use more complex
262 ; constant expressions to reference a particular function with them.
264 store volatile i1 icmp ne (i64 ptrtoint (void (i1)* @test4_g to i64), i64 ptrtoint(void (i1)* @test4_g to i64)), i1* %sink
265 call void @test4_g(i1 true)
266 ; CHECK: store volatile i1 false
267 ; CHECK: call void @test4_g(i1 true)