stack height reduction in tree-SSA

Jeffrey A Law law@redhat.com
Wed Sep 1 16:49:00 GMT 2004


On Wed, 2004-09-01 at 04:39, Joseph S. Myers wrote:
> On Wed, 1 Sep 2004, Giovanni Bajo wrote:
> 
> > void foo(void)
> > {
> >    int a, b;
> > 
> >    a = get();
> >    use_it(&a);
> > 
> >    b = get();
> >    use_it(&b);
> > }
> > 
> > could be optimized to use only one variable on the stack. I have the secret
> 
> In this example, a is still live during the second calls to get() and 
> use_it(); the first call to use_it() could have saved a's address.
> 
> A variable's life won't exceed its scope (meaning the block in which it is 
> declared, including the parts before its declaration) even if its address 
> is taken.  If its address is not taken (or if the address is taken but 
> only in such a way as not to escape) then you can ignore the scope and 
> just observe when it is live.
The optimizers are not aware of scoping within a function.  So
consider something like

test ()
{
  int a;

  {
    int z = whatever
    a = c;
  }

  use a
}

Copy propagation will turn the "use a" into a "use c" -- it knows
no reason not to make that transformation because it does not 
(and should not) know about variable scoping.

We've discussed various means of trying to tackle the problem of
sharing stack slots to mitigate the stack space problems.  If
someone is interested in tackling this problem, I'd suggest
they ping Richard Henderson who seemed to have the best handle
on a potential solution when we last discussed it as a group
a few months ago.

jeff



More information about the Gcc mailing list