This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: does gcc remember register values through into functions?
On Sat, Jan 15, 2005 at 10:59:19AM +0100, Marcel Cox wrote:
> > My guess is that gcc does not assume specific values in
> > any registers, except for registers that carry parameters
> > and serve as stack pointer, when it enters a function. But
> > I hope to be sure about this. Any hints and suggestions
> > would be appreciated.
>
> Well, that not quite the case. It's actually the platform's ABI that
> determines what happens to the various registers. Most ABIs specify
> that functions can only destroy certain registers while for others,
> their original value has to be saved if the function modifies the
> register.
I agree with you on this -- in a function call gcc may
destroy the values in some registers. However, I was
actually asking about another scenario -- does gcc
remember the values in some registers? Below is an
example:
char a;
void f()
{
a++;
}
int main()
{
a = 252;
f();
}
If gcc chooses a register r16 to store a's value,
can gcc use r16 directly in the compiled code
of function f, so that it avoids a memory load
for variable a? This optimization should be valid
if f is only called in main.
I guess, in this case, gcc cannot assume that
r16's value is a's value, since it cannot guarantee
another C file, perhaps separately compiled, does
not call f without first using r16 to store a's
value.
My question is: is there any case where gcc's optimization
process does assume that some registers have some
specific values when entering a function?
Sorry that my previous post might not have stated the
question clearly. Again, your suggestions and hints
will be appreciated.
lin
--
Lin Gu
Department of Computer Science
University of Virginia
Tel: 434-825-3115
Web: http://www.cs.virginia.edu/~lg6e
--------------------------------------