http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57299

--- Comment #6 from Chris Mihelich <umbricola at gmail dot com> ---
Ah, but "=m" and "m" operands shouldn't need any register at all: their purpose
is just to declare that a specific piece of memory is written or read in the
assembly code, a declaration that helps the optimizer avoid mistakes.  The GCC
manual sketches this pattern thus:

Note that in the following example the memory input is necessary, otherwise GCC
might optimize the store to x away:

     int foo ()
     {
       int x = 42;
       int *y = &x;
       int result;
       asm ("magic stuff accessing an 'int' pointed to by '%1'"
            : "=&d" (r) : "a" (y), "m" (*y));
       return result;
     }

Clearly this code is not trying to put the pointer y into a second register
that it doesn't use.  The point is to prevent the initialization of x with 42
from being deleted as (apparently) useless.  There is no indication in the
manual that this "m" (*y) would occupy a register, nor is there any good reason
for a register to be consumed in this case.

I agree with your interpretation in this one sense: GCC appears to be assigning
registers to the "m" and "=m" values as you suggest.  That makes my test case
need six registers (not four) instead of the two it really needs.  That is the
defect I was trying to describe.

Reply via email to