[Bug inline-asm/97708] Inline asm does not use the local register asm specified with register ... asm() as input

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Nov 3 22:09:36 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97708

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
That is how GCC deals with all reloading, so I don't understand what is
surprising about it.
If you ask for something to be in register (or register class) xyz and it isn't
there, it is copied there.
Look at e.g.:
void
foo (void)
{
  register int a __asm ("eax") = 1;
  __asm ("# %0 " : : "r" (a));
  __asm ("# %0 " : : "a" (a));
  __asm ("# %0 " : : "c" (a));
//  __asm ("# %0 " : : "m" (a));
}

In the first case, "r" constraint allows the "eax" register in which the
(local) register variable lives, so it goes there.  In the second case
likewise, it is the only register in which it can go.  In the third case, you
ask for it to be passed in the ecx register and so the compiler does that.  The
commented out case errors out because "m" essentially requires taking the
address of the passed object, which is not valid for register variables.  But
e.g. "g" which doesn't require just mem can handle also non-mems and will be in
that case essentially treated just like "r", because the address of it can't be
taken.


More information about the Gcc-bugs mailing list