Thanks for the quick response Richard!

Unfortunately the source change suggestion didn't work, but that's OK because I 
can make the asm work by eliminating some register pressure.

Bottom line is I was looking to find out if there was a compiler problem under 
the hood.

Sounds like the answer is no, or atleast, nothing that's going to be fixed 
anytime soon.

thanks again!
Mitch

> -----Original Message-----
> From: Richard Henderson [mailto:r...@redhat.com]
> Sent: Tuesday, November 22, 2011 11:35 AM
> To: Bodart, Mitch L
> Cc: gcc@gcc.gnu.org
> Subject: Re: gcc register allocation error when reloading an asm
> 
> 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~

Reply via email to