Richard Guenther wrote:
> On Wed, Aug 3, 2011 at 3:27 PM, Michael Matz <[email protected]> wrote:
>> 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" ;-/
Definitely yes. As I wrote above, if you see asm it's not unlikely that it
is a piece of performance critical code.
> I'd say we should start rejecting all these bogus constructs by default
> (maybe accepting them with -fpermissive and then, well, maybe generate
> some dwim code). That is, local register var decls are only valid
> with an initializer, they are implicitly constant (you can't re-assign to
> them).
> Reserved registers are a no-go (like %esp), either global or local.
Would that help? Like in code
static inline void foo (int arg)
{
register const int reg asm ("r1") = arg;
asm ("..."::"r"(reg));
}
And with output constraints like "=r,0" or "+r". Or in local blocks:
static inline void foo (int arg)
{
register const int reg asm ("r1") = arg;
...
{
register const int reg2 asm ("r1") = reg;
asm ("..."::"r"(reg2));
}
}
Do the current optimizers shred inline asm with ordinary constraints
but without local registers?
If yes, there is a considerable problem in the optimizers and/or in GCC.
If not, why can't local register variables work similarly, i.e. propagate
the register information into respective asms and forget about it for
the variables?
Johann
> Richard.
>
>> Ciao,
>> Michael.