1 ; This test creates a monster SCC with a very pernicious call graph. It builds
2 ; a cycle of cross-connected pairs of functions with interesting inlining
3 ; decisions throughout, but ultimately trivial code complexity.
5 ; Typically, a greedy approach to inlining works well for bottom-up inliners
6 ; such as LLVM's. However, there is no way to be bottom-up over an SCC: it's
7 ; a cycle! Greedily inlining as much as possible into each function of this
8 ; *SCC* will have the disasterous effect of inlining all N-1 functions into the
9 ; first one visited, N-2 functions into the second one visited, N-3 into the
10 ; third, and so on. This is because until inlining occurs, each function in
11 ; isolation appears to be an excellent inline candidate.
13 ; Note that the exact number of calls in each function doesn't really matter.
14 ; It is mostly a function of cost thresholds and visit order. Because this is an
15 ; SCC there is no "right" or "wrong" answer here as long as no function blows up
16 ; to be *huge*. The specific concerning pattern is if one or more functions get
17 ; more than 16 calls in them.
19 ; This test is extracted from the following C++ program compiled with Clang.
20 ; The IR is simplified with SROA, instcombine, and simplify-cfg. Then C++
21 ; linkage stuff, attributes, target specific things, metadata and comments were
22 ; removed. The order of the fuctions is also made more predictable than Clang's
27 ; template <bool K, int N> void f(bool *B, bool *E) {
33 ; f<true, N + 1>(B + 1, E);
35 ; f<false, N + 1>(B + 1, E);
37 ; template <> void f<false, MAX>(bool *B, bool *E) { return f<false, 0>(B, E); }
38 ; template <> void f<true, MAX>(bool *B, bool *E) { return f<true, 0>(B, E); }
40 ; void test(bool *B, bool *E) { f<false, 0>(B, E); }
42 ; RUN: opt -S < %s -inline -inline-threshold=150 | FileCheck %s --check-prefixes=CHECK,OLD
43 ; RUN: opt -S < %s -passes=inline -inline-threshold=150 | FileCheck %s --check-prefixes=CHECK,NEW
45 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
47 declare void @_Z1gi(i32)
49 ; CHECK-LABEL: define void @_Z1fILb0ELi0EEvPbS0_(
51 ; OLD: call void @_Z1gi(
53 ; OLD: call void @_Z1fILb1ELi2EEvPbS0_(
55 ; OLD: call void @_Z1fILb0ELi2EEvPbS0_(
57 ; OLD: call void @_Z1fILb0ELi1EEvPbS0_(
60 ; NEW: call void @_Z1gi(
62 ; NEW: call void @_Z1fILb1ELi2EEvPbS0_(
64 ; NEW: call void @_Z1fILb0ELi2EEvPbS0_(
66 ; NEW: call void @_Z1fILb1ELi2EEvPbS0_(
68 ; NEW: call void @_Z1fILb0ELi2EEvPbS0_(
70 define void @_Z1fILb0ELi0EEvPbS0_(i8* %B, i8* %E) {
72 %cmp = icmp eq i8* %B, %E
73 br i1 %cmp, label %if.end3, label %if.end
76 %0 = load i8, i8* %B, align 1
77 %tobool = icmp eq i8 %0, 0
78 %add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
79 br i1 %tobool, label %if.else, label %if.then1
82 call void @_Z1fILb1ELi1EEvPbS0_(i8* %add.ptr2, i8* %E)
86 call void @_Z1fILb0ELi1EEvPbS0_(i8* %add.ptr2, i8* %E)
93 ; CHECK-LABEL: define void @_Z1fILb1ELi0EEvPbS0_(
95 ; OLD: call void @_Z1gi(
97 ; OLD: call void @_Z1gi(
99 ; OLD: call void @_Z1fILb1ELi2EEvPbS0_(
101 ; OLD: call void @_Z1fILb0ELi2EEvPbS0_(
103 ; OLD: call void @_Z1fILb0ELi1EEvPbS0_(
106 ; NEW: call void @_Z1gi(
108 ; NEW: call void @_Z1fILb1ELi1EEvPbS0_(
110 ; NEW: call void @_Z1fILb1ELi2EEvPbS0_(
112 ; NEW: call void @_Z1fILb0ELi2EEvPbS0_(
114 define void @_Z1fILb1ELi0EEvPbS0_(i8* %B, i8* %E) {
116 call void @_Z1gi(i32 0)
117 %cmp = icmp eq i8* %B, %E
118 br i1 %cmp, label %if.end3, label %if.end
121 %0 = load i8, i8* %B, align 1
122 %tobool = icmp eq i8 %0, 0
123 %add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
124 br i1 %tobool, label %if.else, label %if.then1
127 call void @_Z1fILb1ELi1EEvPbS0_(i8* %add.ptr2, i8* %E)
131 call void @_Z1fILb0ELi1EEvPbS0_(i8* %add.ptr2, i8* %E)
138 ; CHECK-LABEL: define void @_Z1fILb0ELi1EEvPbS0_(
140 ; OLD: call void @_Z1gi(
142 ; OLD: call void @_Z1gi(
144 ; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
146 ; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
148 ; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
150 ; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
152 ; OLD: call void @_Z1fILb0ELi2EEvPbS0_(
155 ; NEW: call void @_Z1fILb1ELi2EEvPbS0_(
157 ; NEW: call void @_Z1fILb1ELi3EEvPbS0_(
159 ; NEW: call void @_Z1fILb0ELi3EEvPbS0_(
161 define void @_Z1fILb0ELi1EEvPbS0_(i8* %B, i8* %E) {
163 %cmp = icmp eq i8* %B, %E
164 br i1 %cmp, label %if.end3, label %if.end
167 %0 = load i8, i8* %B, align 1
168 %tobool = icmp eq i8 %0, 0
169 %add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
170 br i1 %tobool, label %if.else, label %if.then1
173 call void @_Z1fILb1ELi2EEvPbS0_(i8* %add.ptr2, i8* %E)
177 call void @_Z1fILb0ELi2EEvPbS0_(i8* %add.ptr2, i8* %E)
184 ; CHECK-LABEL: define void @_Z1fILb1ELi1EEvPbS0_(
186 ; OLD: call void @_Z1gi(
188 ; OLD: call void @_Z1fILb1ELi2EEvPbS0_(
190 ; OLD: call void @_Z1fILb0ELi2EEvPbS0_(
193 ; NEW: call void @_Z1gi(
195 ; NEW: call void @_Z1gi(
197 ; NEW: call void @_Z1fILb1ELi3EEvPbS0_(
199 ; NEW: call void @_Z1fILb0ELi3EEvPbS0_(
201 ; NEW: call void @_Z1fILb1ELi3EEvPbS0_(
203 ; NEW: call void @_Z1fILb0ELi3EEvPbS0_(
205 define void @_Z1fILb1ELi1EEvPbS0_(i8* %B, i8* %E) {
207 call void @_Z1gi(i32 1)
208 %cmp = icmp eq i8* %B, %E
210 br i1 %cmp, label %if.end3, label %if.end
213 %0 = load i8, i8* %B, align 1
214 %tobool = icmp eq i8 %0, 0
215 %add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
216 br i1 %tobool, label %if.else, label %if.then1
219 call void @_Z1fILb1ELi2EEvPbS0_(i8* %add.ptr2, i8* %E)
223 call void @_Z1fILb0ELi2EEvPbS0_(i8* %add.ptr2, i8* %E)
230 ; CHECK-LABEL: define void @_Z1fILb0ELi2EEvPbS0_(
232 ; OLD: call void @_Z1gi(
234 ; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
236 ; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
238 ; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
240 ; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
243 ; NEW: call void @_Z1gi(
245 ; NEW: call void @_Z1fILb1ELi0EEvPbS0_(
247 ; NEW: call void @_Z1fILb0ELi0EEvPbS0_(
249 ; NEW: call void @_Z1fILb1ELi4EEvPbS0_(
251 ; NEW: call void @_Z1fILb0ELi4EEvPbS0_(
253 define void @_Z1fILb0ELi2EEvPbS0_(i8* %B, i8* %E) {
255 %cmp = icmp eq i8* %B, %E
256 br i1 %cmp, label %if.end3, label %if.end
259 %0 = load i8, i8* %B, align 1
260 %tobool = icmp eq i8 %0, 0
261 %add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
262 br i1 %tobool, label %if.else, label %if.then1
265 call void @_Z1fILb1ELi3EEvPbS0_(i8* %add.ptr2, i8* %E)
269 call void @_Z1fILb0ELi3EEvPbS0_(i8* %add.ptr2, i8* %E)
276 ; CHECK-LABEL: define void @_Z1fILb1ELi2EEvPbS0_(
278 ; OLD: call void @_Z1gi(
280 ; OLD: call void @_Z1gi(
282 ; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
284 ; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
286 ; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
288 ; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
291 ; NEW: call void @_Z1gi(
293 ; NEW: call void @_Z1gi(
295 ; NEW: call void @_Z1fILb1ELi4EEvPbS0_(
297 ; NEW: call void @_Z1fILb0ELi4EEvPbS0_(
299 ; NEW: call void @_Z1fILb1ELi4EEvPbS0_(
301 ; NEW: call void @_Z1fILb0ELi4EEvPbS0_(
303 define void @_Z1fILb1ELi2EEvPbS0_(i8* %B, i8* %E) {
305 call void @_Z1gi(i32 2)
306 %cmp = icmp eq i8* %B, %E
307 br i1 %cmp, label %if.end3, label %if.end
310 %0 = load i8, i8* %B, align 1
311 %tobool = icmp eq i8 %0, 0
312 %add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
313 br i1 %tobool, label %if.else, label %if.then1
316 call void @_Z1fILb1ELi3EEvPbS0_(i8* %add.ptr2, i8* %E)
320 call void @_Z1fILb0ELi3EEvPbS0_(i8* %add.ptr2, i8* %E)
327 ; CHECK-LABEL: define void @_Z1fILb0ELi3EEvPbS0_(
329 ; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
331 ; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
334 ; NEW: call void @_Z1gi(
336 ; NEW: call void @_Z1fILb1ELi1EEvPbS0_(
338 ; NEW: call void @_Z1fILb0ELi1EEvPbS0_(
340 ; NEW: call void @_Z1fILb0ELi0EEvPbS0_(
342 define void @_Z1fILb0ELi3EEvPbS0_(i8* %B, i8* %E) {
344 %cmp = icmp eq i8* %B, %E
345 br i1 %cmp, label %if.end3, label %if.end
348 %0 = load i8, i8* %B, align 1
349 %tobool = icmp eq i8 %0, 0
350 %add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
351 br i1 %tobool, label %if.else, label %if.then1
354 call void @_Z1fILb1ELi4EEvPbS0_(i8* %add.ptr2, i8* %E)
358 call void @_Z1fILb0ELi4EEvPbS0_(i8* %add.ptr2, i8* %E)
365 ; CHECK-LABEL: define void @_Z1fILb1ELi3EEvPbS0_(
367 ; CHECK: call void @_Z1gi(
369 ; CHECK: call void @_Z1fILb1ELi0EEvPbS0_(
371 ; CHECK: call void @_Z1fILb0ELi0EEvPbS0_(
373 define void @_Z1fILb1ELi3EEvPbS0_(i8* %B, i8* %E) {
375 call void @_Z1gi(i32 3)
376 %cmp = icmp eq i8* %B, %E
377 br i1 %cmp, label %if.end3, label %if.end
380 %0 = load i8, i8* %B, align 1
381 %tobool = icmp eq i8 %0, 0
382 %add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
383 br i1 %tobool, label %if.else, label %if.then1
386 call void @_Z1fILb1ELi4EEvPbS0_(i8* %add.ptr2, i8* %E)
390 call void @_Z1fILb0ELi4EEvPbS0_(i8* %add.ptr2, i8* %E)
397 ; CHECK-LABEL: define void @_Z1fILb0ELi4EEvPbS0_(
399 ; CHECK: call void @_Z1fILb0ELi0EEvPbS0_(
401 define void @_Z1fILb0ELi4EEvPbS0_(i8* %B, i8* %E) {
403 call void @_Z1fILb0ELi0EEvPbS0_(i8* %B, i8* %E)
407 ; CHECK-LABEL: define void @_Z1fILb1ELi4EEvPbS0_(
409 ; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
412 ; NEW: call void @_Z1gi(
414 ; NEW: call void @_Z1fILb1ELi1EEvPbS0_(
416 ; NEW: call void @_Z1fILb0ELi1EEvPbS0_(
418 define void @_Z1fILb1ELi4EEvPbS0_(i8* %B, i8* %E) {
420 call void @_Z1fILb1ELi0EEvPbS0_(i8* %B, i8* %E)
424 ; CHECK-LABEL: define void @_Z4testPbS_(
427 define void @_Z4testPbS_(i8* %B, i8* %E) {
429 call void @_Z1fILb0ELi0EEvPbS0_(i8* %B, i8* %E)