This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: RFA: New optimization: Convert local statics into non-statics
> On Mon, Jul 21, 2008 at 12:43:12PM -0400, Daniel Berlin wrote:
> > On Mon, Jul 21, 2008 at 11:52 AM, Nathan Froyd <froydnj@codesourcery.com> wrote:
> > > The correct handling of statics in the presence of function calls works
> > > on a variable-by-variable basis, so running it (with a minor tweak to
> > > fix a bug discovered while testing this *blush*) this silly extension of
> > > Michael's testcase:
> > >
> > > int foo(int i) {
> > > static int s = 0;
> > > static int r;
> > >
> > > if (bar(i))
> > > s = 1;
> > > r = s;
> > >
> > > return s + r;
> > > }
> > >
> > > int bar(int i) {
> > > if (i) { foo(i-1); return 0; }
> > > return 1;
> > > }
> > >
> > > will eliminate R but leave S alone.
> >
> > Given that PRE will now (as of about a week or so ago) eliminate the
> > extra loads, and a coming patch will eliminate any extra stores, how
> > much benefit is there really to performing this optimization (which
> > would be off by default, apparently)?
> >
> > (I'm not trying to be snarky, i'm trying to figure out whether I would
> > support it being on by default if it could be made safe).
>
> I don't think there's a lot of extra benefit. In the example above, the
> wins of the optimization over PRE are:
>
> - We avoid the store to r; r becomes a normal local variable and we
> simply (after forward-propagation) find it to be dead;
If we was able to do load+store PRE as early optimization (I would love
to, but we would need alias analysis working at that stage), then we
might just add simple pas for removal of write only static vars at IPA
level to catch this case in more generic matter.
Honza
>
> - We don't allocate .bss space for r.
>
> I haven't looked at the assembly produced by mainline and
> mainline+optimization for the well-known benchmark this optimization was
> targetted at; I suspect the story there is much the same, but with
> greater benefit since remove-local-statics can avoid stores where PRE
> cannot.
>
> -Nathan