1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-24 05:23:45 +02:00
llvm-mirror/test/Transforms/Inline
Chandler Carruth ef741a9d22 [PM/Inliner] Make the new PM's inliner process call edges across an
entire SCC before iterating on newly-introduced call edges resulting
from any inlined function bodies.

This more closely matches the behavior of the old PM's inliner. While it
wasn't really clear to me initially, this behavior is actually essential
to the inliner behaving reasonably in its current design.

Because the inliner is fundamentally a bottom-up inliner and all of its
cost modeling is designed around that it often runs into trouble within
an SCC where we don't have any meaningful bottom-up ordering to use. In
addition to potentially cyclic, infinite inlining that we block with the
inline history mechanism, it can also take seemingly simple call graph
patterns within an SCC and turn them into *insanely* large functions by
accidentally working top-down across the SCC without any of the
threshold limitations that traditional top-down inliners use.

Consider this diabolical monster.cpp file that Richard Smith came up
with to help demonstrate this issue:
```
template <int N> extern const char *str;

void g(const char *);

template <bool K, int N> void f(bool *B, bool *E) {
  if (K)
    g(str<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); }

extern bool *arr, *end;
void test() { f<false, 0>(arr, end); }
```

When compiled with '-DMAX=N' for various values of N, this will create an SCC
with a reasonably large number of functions. Previously, the inliner would try
to exhaust the inlining candidates in a single function before moving on. This,
unfortunately, turns it into a top-down inliner within the SCC. Because our
thresholds were never built for that, we will incrementally decide that it is
always worth inlining and proceed to flatten the entire SCC into that one
function.

What's worse, we'll then proceed to the next function, and do the exact same
thing except we'll skip the first function, and so on. And at each step, we'll
also make some of the constant factors larger, which is awesome.

The fix in this patch is the obvious one which makes the new PM's inliner use
the same technique used by the old PM: consider all the call edges across the
entire SCC before beginning to process call edges introduced by inlining. The
result of this is essentially to distribute the inlining across the SCC so that
every function incrementally grows toward the inline thresholds rather than
allowing the inliner to grow one of the functions vastly beyond the threshold.
The code for this is a bit awkward, but it works out OK.

We could consider in the future doing something more powerful here such as
prioritized order (via lowest cost and/or profile info) and/or a code-growth
budget per SCC. However, both of those would require really substantial work
both to design the system in a way that wouldn't break really useful
abstraction decomposition properties of the current inliner and to be tuned
across a reasonably diverse set of code and workloads. It also seems really
risky in many ways. I have only found a single real-world file that triggers
the bad behavior here and it is generated code that has a pretty pathological
pattern. I'm not worried about the inliner not doing an *awesome* job here as
long as it does *ok*. On the other hand, the cases that will be tricky to get
right in a prioritized scheme with a budget will be more common and idiomatic
for at least some frontends (C++ and Rust at least). So while these approaches
are still really interesting, I'm not in a huge rush to go after them. Staying
even closer to the existing PM's behavior, especially when this easy to do,
seems like the right short to medium term approach.

I don't really have a test case that makes sense yet... I'll try to find a
variant of the IR produced by the monster template metaprogram that is both
small enough to be sane and large enough to clearly show when we get this wrong
in the future. But I'm not confident this exists. And the behavior change here
*should* be unobservable without snooping on debug logging. So there isn't
really much to test.

The test case updates come from two incidental changes:
1) We now visit functions in an SCC in the opposite order. I don't think there
   really is a "right" order here, so I just update the test cases.
2) We no longer compute some analyses when an SCC has no call instructions that
   we consider for inlining.

llvm-svn: 297374
2017-03-09 11:35:40 +00:00
..
AArch64 Recommit "[InlineCost] Use TTI to check if GEP is free." #3 2017-01-20 18:51:22 +00:00
X86 [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
2003-09-14-InlineValue.ll
2003-09-22-PHINodeInlineFail.ll
2003-09-22-PHINodesInExceptionDest.ll
2003-09-22-PHINodesInNormalInvokeDest.ll
2003-10-13-AllocaDominanceProblem.ll
2004-04-15-InlineDeletesCall.ll
2004-04-20-InlineLinkOnce.ll
2004-10-17-InlineFunctionWithoutReturn.ll
2006-01-14-CallGraphUpdate.ll
2006-07-12-InlinePruneCGUpdate.ll
2006-11-09-InlineCGUpdate-2.ll
2006-11-09-InlineCGUpdate.ll
2007-04-15-InlineEH.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
2007-06-25-WeakInline.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
2007-12-19-InlineNoUnwind.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
2008-09-02-NoInline.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
2009-01-08-NoInlineDynamicAlloca.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
2009-01-13-RecursiveInlineCrash.ll
2009-05-07-CallUsingSelfCrash.ll
2010-05-12-ValueMap.ll
align.ll
alloca_test.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
alloca-bonus.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
alloca-dbgdeclare-merge.ll
alloca-dbgdeclare.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
alloca-in-scc.ll
alloca-merge-align.ll
always-inline.ll [PM] Teach the always inliner in the new pass manager to support 2016-12-26 23:43:27 +00:00
arg-attr-propagation.ll Revert r296366 "[InlineFunction] add nonnull assumptions based on argument attributes" 2017-02-27 22:33:02 +00:00
array_merge.ll
array-alloca.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
attributes.ll [PM] Teach the inliner in the new PM to merge attributes after inlining. 2016-12-27 03:39:54 +00:00
basictest.ll [PM] Provide an initial, minimal port of the inliner to the new pass manager. 2016-12-20 03:15:32 +00:00
bfi-update.ll Fix a bug in caller's BFI update code after inlining. 2017-02-14 22:49:28 +00:00
blockaddress.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
byval_lifetime.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
byval-tail-call.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
byval.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
callgraph-update.ll
casts.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
cfg_preserve_test.ll [Inliner] Modernize all of the inliner tests that were using grep. 2016-12-27 02:47:37 +00:00
cgscc-incremental-invalidate.ll [PM/Inliner] Make the new PM's inliner process call edges across an 2017-03-09 11:35:40 +00:00
cgscc-invalidate.ll [PM/Inliner] Make the new PM's inliner process call edges across an 2017-03-09 11:35:40 +00:00
cgscc-update.ll [PM] Teach the inliner's call graph update to handle inserting new edges 2016-12-28 03:13:12 +00:00
clear-analyses.ll [PH] Replace uses of AssertingVH from members of analysis results with 2017-01-24 12:55:57 +00:00
comdat-ipo.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
crash2.ll
crash-lifetime-marker.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
crash.ll
debug-info-duplicate-calls.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
debug-invoke.ll
delete-call.ll
deopt-bundles.ll
deoptimize-intrinsic-cconv.ll
deoptimize-intrinsic.ll
devirtualize-2.ll [PM] Introduce a devirtualization iteration layer for the new PM. 2016-12-28 11:07:33 +00:00
devirtualize-3.ll
devirtualize.ll
dynamic_alloca_test.ll
ephemeral.ll
externally_available.ll [Inliner] Modernize all of the inliner tests that were using grep. 2016-12-27 02:47:37 +00:00
frameescape.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
function-count-update-2.ll Improve PGO support for the new inliner 2017-01-20 22:44:04 +00:00
function-count-update-3.ll Improve PGO support for the new inliner 2017-01-20 22:44:04 +00:00
function-count-update.ll Improve PGO support for the new inliner 2017-01-20 22:44:04 +00:00
guard-intrinsic.ll
gvn-inline-iteration.ll
ignore-debug-info.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inalloca-not-static.ll [PM] Wire up another test to the new pass manager. 2016-12-27 06:46:16 +00:00
inline_cleanup.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline_constprop.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline_dbg_declare.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline_dce.ll [Inliner] Modernize all of the inliner tests that were using grep. 2016-12-27 02:47:37 +00:00
inline_invoke.ll [PM] Move the collection of call sites to a more appropriate place 2016-12-27 01:24:50 +00:00
inline_minisize.ll
inline_prune.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline_returns_twice.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline_ssp.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline_stats.ll
inline_unreachable-2.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline_unreachable.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline-assume.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline-byval-bonus.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline-cold-callee.ll Improve PGO support for the new inliner 2017-01-20 22:44:04 +00:00
inline-cold-callsite.ll Improve PGO support for the new inliner 2017-01-20 22:44:04 +00:00
inline-cold.ll
inline-constexpr-addrspacecast-argument.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline-fast-math-flags.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline-fp.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline-funclets.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline-hot-callee.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline-hot-callsite-2.ll Improve PGO support for the new inliner 2017-01-20 22:44:04 +00:00
inline-hot-callsite.ll Improve PGO support for the new inliner 2017-01-20 22:44:04 +00:00
inline-indirect.ll
inline-invoke-tail.ll [Inliner] Fix a test where I typo'ed 'CHECK' as 'CHCEK' when converting 2017-01-04 11:15:01 +00:00
inline-invoke-with-asm-call.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline-musttail-varargs.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline-optnone.ll
inline-optsize.ll
inline-tail.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
inline-threshold.ll
inline-vla.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
invoke_test-1.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
invoke_test-2.ll [Inliner] Modernize all of the inliner tests that were using grep. 2016-12-27 02:47:37 +00:00
invoke_test-3.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
invoke-cleanup.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
invoke-combine-clauses.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
invoke-cost.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
last-call-bonus.ll Do not apply redundant LastCallToStaticBonus 2017-02-14 17:30:05 +00:00
last-callsite.ll [PM] Provide an initial, minimal port of the inliner to the new pass manager. 2016-12-20 03:15:32 +00:00
lifetime-no-datalayout.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
lifetime.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
local-as-metadata-undominated-use.ll Revert "Strip debug info when inlining into a nodebug function." 2017-03-07 17:28:57 +00:00
nested-inline.ll [PM] Provide an initial, minimal port of the inliner to the new pass manager. 2016-12-20 03:15:32 +00:00
noalias2.ll
noalias-calls.ll
noalias-cs.ll
noalias.ll
noinline-recursive-fn.ll [PM] Add one of the features left out of the initial inliner patch: 2016-12-27 06:46:20 +00:00
noinline.ll
nonnull.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
null-function.ll
optimization-remarks-passed-yaml.ll
optimization-remarks-with-hotness.ll [Inliner] Fold analysis remarks into missed remarks 2017-01-30 16:22:45 +00:00
optimization-remarks-yaml.ll
optimization-remarks.ll [Inliner] Fold analysis remarks into missed remarks 2017-01-30 16:22:45 +00:00
parallel-loop-md.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
partial-inline-act.ll
pr21206.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
pr22285.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
pr26698.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
pr28298.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
PR4909.ll
profile-meta.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
ptr-diff.ll
recursive.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
store-sroa.ll
switch.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
vector-bonus.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00
zero-cost.ll [PM] Turn on the new PM's inliner in addition to the current one for 2016-12-27 07:18:43 +00:00