This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] diagnose unsupported uses of hardware register variables (PR 88000)
On Wed, 14 Nov 2018, Segher Boessenkool wrote:
> > I think with "=g" rather than "+g" this example is ok.
>
> No, it needs the register var as an input. That is the whole *point*.
Hm. I think I see what you meant, but "+g" is not correct either: the
asm, by intent, depends *on the current value in the 'sp' hardreg*, not
*on the current value of some automatic variable that is supposed to be
passed on the 'sp' hardreg to the asm* (which is what expressed by the
input constraint).
Consider what would happen in the scenario demonstrated in PR 89784:
suppose you have (e.g. after inlining 'retsp' in a loop):
for (int i=0; i<2; i++)
{
register long sp asm ("%rsp");
asm ("" : "+r" (sp));
<code using sp>
}
and then after unrolling
register long sp asm ("%rsp");
asm ("" : "+r" (sp));
<code using sp>
asm ("" : "+r" (sp));
<code using sp>
where only the first asm has an uninitialized input, and the second asm
implies restoring hardreg %rsp to the value in variable sp.
So at a minimum you'd need to use two separate register variables:
register long sp_in asm ("%rsp");
register long sp asm ("%rsp");
asm ("" : "=r" (sp) : "r" (sp_in));
Alexander