On Thu, 15 Nov 2018, Michael Matz wrote:
> I disagree that there's something to fix. My mental model for local reg
> vars has always been that such vars are actually an alias for that
> register, not comparable to normal automatic variables (so, much like
> global reg vars, except that they don't reserve away the register from
> regalloc). I.e. like volatile they can arbitrarily change their value.
> I don't know if other peoples mind model is similar, but it certainly is
> the model that is implemented in the GIMPLE pipeline (and if memory serves
> well of the RTL pipeline as well).
Reading the documentation certainly does not make that impression to me.
In any case, can you elaborate a bit further please:
1. Regarding the comparison to 'volatile' qualifier. Suppose you have an
automatic variable 'int v;' in a correct program. The variable is only used
for some arithmetic, never passed to asms, does not have its address taken.
Thus, changing its
declaration to 'volatile int v;' would not make the program invalid. Now,
can declaring it as 'register int v asm("%rbx");' (with a callee-saved
register) make the program invalid? My reading of the documentation is
that it would provide a regalloc hint and have no ill effects.
2. Are testcases given in PR 87984 valid? Quoting the latest example:
int f(void)
{
int o=0, i;
for (i=0; i<3; i++) {
register int a asm("eax");
a = 1;
asm("add %1, %0" : "+r"(o) : "r"(a));
asm("xor %%eax, %%eax" ::: "eax");
}
return o;
}
This follows both your model and the documentation to the letter, and
yet will return 1 rather than 3.
I disagree that it is practical to implement your model on GIMPLE.
Thanks.
Alexander