1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
| ; This test creates a monster SCC with a very pernicious call graph. It builds
; a cycle of cross-connected pairs of functions with interesting inlining
; decisions throughout, but ultimately trivial code complexity.
;
; Typically, a greedy approach to inlining works well for bottom-up inliners
; such as LLVM's. However, there is no way to be bottom-up over an SCC: it's
; a cycle! Greedily inlining as much as possible into each function of this
; *SCC* will have the disasterous effect of inlining all N-1 functions into the
; first one visited, N-2 functions into the second one visited, N-3 into the
; third, and so on. This is because until inlining occurs, each function in
; isolation appears to be an excellent inline candidate.
;
; Note that the exact number of calls in each function doesn't really matter.
; It is mostly a function of cost thresholds and visit order. Because this is an
; SCC there is no "right" or "wrong" answer here as long as no function blows up
; to be *huge*. The specific concerning pattern is if one or more functions get
; more than 16 calls in them.
;
; This test is extracted from the following C++ program compiled with Clang.
; The IR is simplified with SROA, instcombine, and simplify-cfg. Then C++
; linkage stuff, attributes, target specific things, metadata and comments were
; removed. The order of the fuctions is also made more predictable than Clang's
; output order.
;
; void g(int);
;
; template <bool K, int N> void f(bool *B, bool *E) {
; if (K)
; g(N);
; if (B == E)
; return;
; if (*B)
; f<true, N + 1>(B + 1, E);
; else
; f<false, N + 1>(B + 1, E);
; }
; template <> void f<false, MAX>(bool *B, bool *E) { return f<false, 0>(B, E); }
; template <> void f<true, MAX>(bool *B, bool *E) { return f<true, 0>(B, E); }
;
; void test(bool *B, bool *E) { f<false, 0>(B, E); }
;
; RUN: opt -S < %s -inline -inline-threshold=150 | FileCheck %s --check-prefixes=CHECK,OLD
; RUN: opt -S < %s -passes=inline -inline-threshold=150 | FileCheck %s --check-prefixes=CHECK,NEW
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
declare void @_Z1gi(i32)
; CHECK-LABEL: define void @_Z1fILb0ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1gi(
; OLD-NOT: call
; OLD: call void @_Z1fILb1ELi2EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi2EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi1EEvPbS0_(
; OLD-NOT: call
; NEW-NOT: call
; NEW: call void @_Z1gi(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi2EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi2EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi2EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi2EEvPbS0_(
; NEW-NOT: call
define void @_Z1fILb0ELi0EEvPbS0_(i8* %B, i8* %E) {
entry:
%cmp = icmp eq i8* %B, %E
br i1 %cmp, label %if.end3, label %if.end
if.end:
%0 = load i8, i8* %B, align 1
%tobool = icmp eq i8 %0, 0
%add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
br i1 %tobool, label %if.else, label %if.then1
if.then1:
call void @_Z1fILb1ELi1EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.else:
call void @_Z1fILb0ELi1EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.end3:
ret void
}
; CHECK-LABEL: define void @_Z1fILb1ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1gi(
; OLD-NOT: call
; OLD: call void @_Z1gi(
; OLD-NOT: call
; OLD: call void @_Z1fILb1ELi2EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi2EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi1EEvPbS0_(
; OLD-NOT: call
; NEW-NOT: call
; NEW: call void @_Z1gi(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi1EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi2EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi2EEvPbS0_(
; NEW-NOT: call
define void @_Z1fILb1ELi0EEvPbS0_(i8* %B, i8* %E) {
entry:
call void @_Z1gi(i32 0)
%cmp = icmp eq i8* %B, %E
br i1 %cmp, label %if.end3, label %if.end
if.end:
%0 = load i8, i8* %B, align 1
%tobool = icmp eq i8 %0, 0
%add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
br i1 %tobool, label %if.else, label %if.then1
if.then1:
call void @_Z1fILb1ELi1EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.else:
call void @_Z1fILb0ELi1EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.end3:
ret void
}
; CHECK-LABEL: define void @_Z1fILb0ELi1EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1gi(
; OLD-NOT: call
; OLD: call void @_Z1gi(
; OLD-NOT: call
; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi2EEvPbS0_(
; OLD-NOT: call
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi2EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi3EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi3EEvPbS0_(
; NEW-NOT: call
define void @_Z1fILb0ELi1EEvPbS0_(i8* %B, i8* %E) {
entry:
%cmp = icmp eq i8* %B, %E
br i1 %cmp, label %if.end3, label %if.end
if.end:
%0 = load i8, i8* %B, align 1
%tobool = icmp eq i8 %0, 0
%add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
br i1 %tobool, label %if.else, label %if.then1
if.then1:
call void @_Z1fILb1ELi2EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.else:
call void @_Z1fILb0ELi2EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.end3:
ret void
}
; CHECK-LABEL: define void @_Z1fILb1ELi1EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1gi(
; OLD-NOT: call
; OLD: call void @_Z1fILb1ELi2EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi2EEvPbS0_(
; OLD-NOT: call
; NEW-NOT: call
; NEW: call void @_Z1gi(
; NEW-NOT: call
; NEW: call void @_Z1gi(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi3EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi3EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi3EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi3EEvPbS0_(
; NEW-NOT: call
define void @_Z1fILb1ELi1EEvPbS0_(i8* %B, i8* %E) {
entry:
call void @_Z1gi(i32 1)
%cmp = icmp eq i8* %B, %E
; CHECK-NOT: call
br i1 %cmp, label %if.end3, label %if.end
if.end:
%0 = load i8, i8* %B, align 1
%tobool = icmp eq i8 %0, 0
%add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
br i1 %tobool, label %if.else, label %if.then1
if.then1:
call void @_Z1fILb1ELi2EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.else:
call void @_Z1fILb0ELi2EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.end3:
ret void
}
; CHECK-LABEL: define void @_Z1fILb0ELi2EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1gi(
; OLD-NOT: call
; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
; OLD-NOT: call
; NEW-NOT: call
; NEW: call void @_Z1gi(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi0EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi0EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi4EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi4EEvPbS0_(
; NEW-NOT: call
define void @_Z1fILb0ELi2EEvPbS0_(i8* %B, i8* %E) {
entry:
%cmp = icmp eq i8* %B, %E
br i1 %cmp, label %if.end3, label %if.end
if.end:
%0 = load i8, i8* %B, align 1
%tobool = icmp eq i8 %0, 0
%add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
br i1 %tobool, label %if.else, label %if.then1
if.then1:
call void @_Z1fILb1ELi3EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.else:
call void @_Z1fILb0ELi3EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.end3:
ret void
}
; CHECK-LABEL: define void @_Z1fILb1ELi2EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1gi(
; OLD-NOT: call
; OLD: call void @_Z1gi(
; OLD-NOT: call
; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
; OLD-NOT: call
; NEW-NOT: call
; NEW: call void @_Z1gi(
; NEW-NOT: call
; NEW: call void @_Z1gi(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi4EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi4EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi4EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi4EEvPbS0_(
; NEW-NOT: call
define void @_Z1fILb1ELi2EEvPbS0_(i8* %B, i8* %E) {
entry:
call void @_Z1gi(i32 2)
%cmp = icmp eq i8* %B, %E
br i1 %cmp, label %if.end3, label %if.end
if.end:
%0 = load i8, i8* %B, align 1
%tobool = icmp eq i8 %0, 0
%add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
br i1 %tobool, label %if.else, label %if.then1
if.then1:
call void @_Z1fILb1ELi3EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.else:
call void @_Z1fILb0ELi3EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.end3:
ret void
}
; CHECK-LABEL: define void @_Z1fILb0ELi3EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb0ELi0EEvPbS0_(
; OLD-NOT: call
; NEW-NOT: call
; NEW: call void @_Z1gi(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi1EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi1EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi0EEvPbS0_(
; NEW-NOT: call
define void @_Z1fILb0ELi3EEvPbS0_(i8* %B, i8* %E) {
entry:
%cmp = icmp eq i8* %B, %E
br i1 %cmp, label %if.end3, label %if.end
if.end:
%0 = load i8, i8* %B, align 1
%tobool = icmp eq i8 %0, 0
%add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
br i1 %tobool, label %if.else, label %if.then1
if.then1:
call void @_Z1fILb1ELi4EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.else:
call void @_Z1fILb0ELi4EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.end3:
ret void
}
; CHECK-LABEL: define void @_Z1fILb1ELi3EEvPbS0_(
; CHECK-NOT: call
; CHECK: call void @_Z1gi(
; CHECK-NOT: call
; CHECK: call void @_Z1fILb1ELi0EEvPbS0_(
; CHECK-NOT: call
; CHECK: call void @_Z1fILb0ELi0EEvPbS0_(
; CHECK-NOT: call
define void @_Z1fILb1ELi3EEvPbS0_(i8* %B, i8* %E) {
entry:
call void @_Z1gi(i32 3)
%cmp = icmp eq i8* %B, %E
br i1 %cmp, label %if.end3, label %if.end
if.end:
%0 = load i8, i8* %B, align 1
%tobool = icmp eq i8 %0, 0
%add.ptr2 = getelementptr inbounds i8, i8* %B, i64 1
br i1 %tobool, label %if.else, label %if.then1
if.then1:
call void @_Z1fILb1ELi4EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.else:
call void @_Z1fILb0ELi4EEvPbS0_(i8* %add.ptr2, i8* %E)
br label %if.end3
if.end3:
ret void
}
; CHECK-LABEL: define void @_Z1fILb0ELi4EEvPbS0_(
; CHECK-NOT: call
; CHECK: call void @_Z1fILb0ELi0EEvPbS0_(
; CHECK-NOT: call
define void @_Z1fILb0ELi4EEvPbS0_(i8* %B, i8* %E) {
entry:
call void @_Z1fILb0ELi0EEvPbS0_(i8* %B, i8* %E)
ret void
}
; CHECK-LABEL: define void @_Z1fILb1ELi4EEvPbS0_(
; OLD-NOT: call
; OLD: call void @_Z1fILb1ELi0EEvPbS0_(
; OLD-NOT: call
; NEW-NOT: call
; NEW: call void @_Z1gi(
; NEW-NOT: call
; NEW: call void @_Z1fILb1ELi1EEvPbS0_(
; NEW-NOT: call
; NEW: call void @_Z1fILb0ELi1EEvPbS0_(
; NEW-NOT: call
define void @_Z1fILb1ELi4EEvPbS0_(i8* %B, i8* %E) {
entry:
call void @_Z1fILb1ELi0EEvPbS0_(i8* %B, i8* %E)
ret void
}
; CHECK-LABEL: define void @_Z4testPbS_(
; CHECK: call
; CHECK-NOT: call
define void @_Z4testPbS_(i8* %B, i8* %E) {
entry:
call void @_Z1fILb0ELi0EEvPbS0_(i8* %B, i8* %E)
ret void
}
|