This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc register allocation error when reloading an asm
- From: Richard Henderson <rth at redhat dot com>
- To: "Bodart, Mitch L" <mitch dot l dot bodart at intel dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Tue, 22 Nov 2011 11:34:39 -0800
- Subject: Re: gcc register allocation error when reloading an asm
- References: <EB7CC8AE19F50143950B90CF3853203C20B65892@orsmsx509.amr.corp.intel.com>
On 11/22/2011 10:55 AM, Bodart, Mitch L wrote:
> What aspect of inline asm processing is preventing gcc from allocating
> register eax to both %0 and %1's address in the following test case?
>
> gcc -m32 -S foo.c
> foo.c: In function 'foo':
> foo.c:20: error: can't find a register in class 'GENERAL_REGS' while reloading 'asm'
>
> I could understand this error if val was an early clobber, "=&r" (val),
> as the description of "&" says such operands cannot be assigned to the
> same register as an input, or any register used in a memory address.
> But since no ampersand is present, it seems eax is available here
> for both operands.
>
> int foo(int *ptr) {
> int val;
>
> __asm__ __volatile__("junk %0, %1"
> : "=r" (val), "+m" (*ptr)
%1 is also an output operand (+), which means its address needs to be
available as an output address reload. This will conflict with normal
output reloads.
I think I know what you are trying to write: %1 as a RW memory, but
the address is latched on input; %0 as an independent output.
You could try writing this as
: "=r"(val), "=X"(*ptr) : "m"(*ptr)
instead. Untested, so there might be other gotchas...
r~