Bug 29808 - [4.2 Regression] Error: suffix or operands invalid for `mov' when optimization is enabled
Summary: [4.2 Regression] Error: suffix or operands invalid for `mov' when optimizatio...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: inline-asm (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-12 09:05 UTC by bero
Modified: 2006-11-12 17:15 UTC (History)
3 users (show)

See Also:
Host: i586-pc-linux-gnu
Target: i586-pc-linux-gnu
Build: i586-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bero 2006-11-12 09:05:57 UTC
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).
Comment 1 Segher Boessenkool 2006-11-12 11:10:10 UTC
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).
Comment 2 Richard Biener 2006-11-12 13:26:54 UTC
invalid
Comment 3 bero 2006-11-12 13:40:26 UTC
If the code is invalid, the fact that it compiles with -O0 is probably a bug...
Comment 4 Segher Boessenkool 2006-11-12 14:01:27 UTC
> 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).
Comment 5 Andrew Pinski 2006-11-12 17:15:47 UTC
(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".