Hi,
On Wed, 3 Aug 2011, Richard Guenther wrote:
> > Yes, that's reasonable. As I understand the docs, in code like
> >
> > void foo ()
> > {
> > register int var asm ("r1") = 10;
> > asm (";; use r1");
> > }
> >
> > there is nothing that connects var to the asm and assuming that
> > r1 holds 10 in the asm is a user error.
> >
> > The only place where the asm attached to a variable needs to have
> > effect are the inline asm sequences that explicitly refer to
> > respective variables. If there is no inline asm referencing a
> > local register variable, there is on difference to a non-register
> > auto variable; there could even be a warning that in such a case
> > that
> >
> > register int var asm ("r1") = 10;
> >
> > is equivalent to
> >
> > int var = 10;
> >
> > This would render local register variables even more functional
> > because no one needed to care if there were implicit library calls or
> > things like that.
>
> Yes, I like that idea.
I do too. Except it doesn't work :)
There's a common idiom of accessing registers read-only by declaring local
register vars. E.g. to (*grasp*) the stack pointer. There won't be a DEF
for that register var, and hence at use-points we couldn't reload any
sensible values into those registers (and we really shouldn't clobber the
stack pointer in this way).
We could introduce that special semantic only for non-reserved registers,
and require no writes to register vars for reserved registers.
Or we could simply do:
if (any_local_reg_vars)
optimize = 0;
But I already see people wanting to _do_ optimization also with local reg
vars, "just not the wrong optimizations" ;-/
Ciao,
Michael.