The following code (extracted from the Linux kernel) fails to compile with optimization enabled: static void load_fs(unsigned short sel) { asm("mov %0, %%fs" : : "g"(sel)); } int main(int argc, char **argv) { load_fs(0); } [bero@dhcppc1 arklinux]$ gcc test.c [bero@dhcppc1 arklinux]$ gcc -O1 test.c /tmp/ccSpA5Rm.s: Assembler messages: /tmp/ccSpA5Rm.s:13: Error: suffix or operands invalid for `mov' gcc is 4.2 SVN revision 118519 (20061106).
Not a bug in GCC but in your code; "g" says immediate values are allowed, while this asm insn only takes registers (or 16-bit memory).
invalid
If the code is invalid, the fact that it compiles with -O0 is probably a bug...
> If the code is invalid, the fact that it compiles with -O0 is probably a bug... No, GCC cannot in general detect whether your asm code is buggy. The assembler however can detect many asm bugs, as it did in this case. The reason it worked with -O0 is that with -O0 you get different generated code (namely, very inefficient code).
(In reply to comment #3) > If the code is invalid, the fact that it compiles with -O0 is probably a bug... No it is not really a bug that it compiles at -O0 either becuase "g" means "r"+"i" so the register allocator in the -O0 case is selecting "r" while in the optimize case is selecting "i".