This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Optimization and inline assembly in GCC 4.0/MIPS
At 16 Oct 2006 11:52:49 -0700,
Ian Lance Taylor wrote:
>
> You've told gcc that the inline assembler code cares about the value
> of 'm', but you haven't told it that it cares about the value of
> 'm[0]', 'm[1]', etc.
>
> This exact case is covered in the documentation:
>
> 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));
OK, but in my case _syscall2 is generically defined so I cannot give
individual input restrictions. If I parse the documentation correctly,
If your assembler instructions access memory in an unpredictable
fashion, add `memory' to the list of clobbered registers. This
will cause GCC to not keep memory values cached in registers across
the assembler instruction and not optimize stores or loads to that
memory.
clobbering "memory" should then force GCC to avoid optimizing accesses
away ("not optimize stores or loads to that memory"). I think I
understand this now, thanks.
// Simon