[llvm-dev] RFC: We should stop merging allocas in the inliner
Chandler Carruth via llvm-dev
llvm-dev at lists.llvm.org
Tue Aug 2 01:01:55 PDT 2016
On Mon, Aug 1, 2016 at 7:23 PM Gerolf Hoflehner via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> > On Jul 31, 2016, at 9:47 PM, Chandler Carruth via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
> > Chris added alloca merging in the inliner a looooong time ago, 2009. The
> reason he added it was because at the time we didn't do stack coloring and
> without it we had serious stack size problems in LLVM.
> > Since then, a few rather important things have changed:
> > - We have reasonably powerful stack coloring support in the backend
> based on lifetime markers
> > - Clang (the primary frontend I'm aware of that hit issues with this) is
> now emitting lifetime markers for essentially everything
> > - Clang even has front-end based -O0 stack reuse tricks
> > - AliasAnalysis has become even more important (extended to codegen time
> etc) and relies heavily on distinguishing between allocas.
> > - We have lots of tools like the sanitizers that directly reason about
> allocas to catch bugs in user programs.
> > The first two changes pretty much completely obviate the need for alloca
> merging as far as I'm aware, and the second two changes make the
> information loss caused by this practice, IMO, really bad.
> > Even if there are problems exposed by turning off alloca merging in the
> inliner, they are almost certainly deficiencies in stack coloring, Clang,
> or other parts of the optimizer that we should fix rather than continue to
> > Thoughts? The code changes are easy and mechanical. My plan would be:
> I like the principal idea.
> > 1) Add a flag to turn this off.
> > 2) Run benchmarks with flag to make sure things are actually working.
> > 3) Change default for the flag, make sure chaos doesn't ensue.
> What does this imply? Just run-time? I’d like to see stack size data w/
> and w/o the change and - just in case - an investigation/fix of the
Sure, I'll do both some benchmarks and also look at some stack sizes.
> Any thoughts about compile-time and code size?
I think compile-time regressions are certainly possible with heavier use of
AA and stack coloring, but we'd likely be hitting those through other
patterns than just this one already. It doesn't seem likely this will
really cause much churn there, but certainly if reports come in, we will
have a flag that we can toggle until things are fixed.
> You probably also want to collect the data across more than one platform.
I'll certainly collect it for the platforms I have access to and such, but
hopefully those interested in other platforms and worried about stack space
can also do some testing. That's why I want to add a flag so its super easy
to check whether this regresses something you care about.
> > 4) Delete the (quite substantial) complexity associated with this and
> the flag.
> You might need to allow target specific behavior for some grace period.
I really don't think this warrants a long grace period much less target
The goal is simplification. We have lots of infrastructure for a target to
control how stack coloring and layout is done. Honestly, I suspect most of
the stack objects already go down this path. It is only array type allocas
that we even bother with this merging for right now, so I'm not expecting
any dramatic changes.
Clearly, if folks report problems, we'll turn it back on and have to sort
out what happened, but I think we can take a pretty simple approach to get
from here to there...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev