Should it be reported as a bug? (-O2 and cmpxchg instruction)

Andrew Haley aph@redhat.com
Fri Feb 15 11:00:00 GMT 2008


Martin Sustrik wrote:
> Hi all,
> 
> I've encountered a problem with gcc inline assembly.
> 
> Following code, when optimised with -O2 gives following machine code:
> 
>            __asm__ volatile (
>                "lock; cmpxchgl %1, %3\n\t"
>                "jz 1f\n\t"
>                "mov %2, %%eax\n\t"
>                "lock; xchgl %%eax, %3\n\t"
>                "1:\n\t"
>                : "=a" (oldval)
>                : "r" (thenval_), "r" (elseval_), "m" (value), "0" (0)
>                : "memory", "cc");
> 
> 4031a0:   31 c0                   xor    %eax,%eax
>  4031a2:   f0 0f b1 55 40          lock cmpxchg %edx,0x40(%rbp)
>  4031a7:   74 06                   je     4031af
>  4031a9:   89 c0                   mov    %eax,%eax
>  4031ab:   f0 87 45 40             lock xchg %eax,0x40(%rbp)
> 
> Note that %2 maps to %%eax (mov %2, %%eax --> mov %eax,%eax). This 
> shouldn't happen given that cmpxchg modifies the value of %%eax.
> 
> Any idea whether this should be considered a bug and reported as such?

Look for "earlyclobber" in the section Constraint Modifier Characters

Andrew.



More information about the Gcc-help mailing list