Hi,

On Sat, 27 Feb 2010, Joern Rennecke wrote:

> > >I wonder whether there is a plan to optimize code such as this:
> > >
> > >extern int ffff(const int x);
> > >void hhhh() {
> > >   ffff(444);
> > >   ffff(444);
> > >   }
> > >
> > >by not pushing the constant argument twice.  It seems safe to do so,
> > >because the function called will not modify its argument on the stack.
> >
> >I can think of one case where this is not true. Sibcalling where
> >arguments are the same size and the order are different or just
> >different in general.
> 
> In that case, the sibcall optimization really actually goes against the
> function declaration.  It's basically an ABI decision if we consider that
> valid.

Most (all?) ABI(s) make the outgoing parameter passing area on the stack 
belong to the called function (there as incoming paramater area), with no 
differentiation between const or non-const arguments.  Hence the callee 
may do whatever it likes with it, including reading out the passed 
parameter into somewhere else (register) and reuse the stack space for 
some temporary calculations.  The 'const' concept of language doesn't 
change this.

So, no, we can't do the transformation the OP suggested.

> If it's not valid for a target, then the push optimization should
> be safe; this might be indicated by a target hook.

... or that.  But it could be set only for very few ABIs (are there any?).


Ciao,
Michael.

Reply via email to