This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: Variable "foo" is not available
On Mon, Apr 04, 2005 at 10:30:23PM +0300, Eli Zaretskii wrote:
> But this kind of code is only possible if the compiler examines all
> the callers of `bar' and finds that none of them uses the value of
> `bar's argument after `bar' returns. So such code is probably only
> possible in practice with static functions, right? Or am I missing
> something?
That would be true if the ABI labeled the stack slots as preserved
across the function call. The consensus seems to be that it does not;
at the point of the function call they become part of the callee's
stack frame and it is free to modify them.
> Also, is such optimizations really worth it? I mean, the more
> traditional code will mov the argument into a register and do the math
> there; is adding to a memory location really faster than a mov and a
> register-based add?
Yes, especially on decoding-limited processors.
Also, sibling calling does the same thing. It reuses the stack slots
to pass arguments to a new function, and then jumps to the function.
> > GCC won't reuse the slot for an unrelated variable at present.
> > However, in the future, it would be a valid optimization.
>
> Again, only if the compiler has enough information about the callers,
> right?
No, as above.
--
Daniel Jacobowitz
CodeSourcery, LLC