http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58945
Bug ID: 58945 Summary: Improve atomic_compare_and_swap*_doubleword pattern Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: ubizjak at gmail dot com Created attachment 31126 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31126&action=edit Patch to simplify atomic_compare_and_swap<dwi>_doubleword pattern Currently, gcc generates lots of unnecessary moves for following testcase (actually gcc.dg/atomic-store-6.c): --cut here-- __int128_t i; int main() { __atomic_store_16(&i, -1, 0); if (i != -1) __builtin_abort(); return 0; } --cut here-- gcc -O2 -mcx16: movq i(%rip), %rsi movq $-1, %rcx movq i+8(%rip), %rdi .L2: movq %rsi, %rax movq %rdi, %rdx movq %rcx, %rbx lock cmpxchg16b i(%rip) movq %rdx, %rdi movq %rax, %rsi jne .L2 I have experimented with sync x86_64 pattern, to see if we can simplify atomic_compare_and_swap<dwi>_doubleword pattern, so it would work with real doublemode values and this way remove unnecessary register moves. However, I have hit an ICE in assing_by_spills that prevents me from using these simplifications: gcc -O2 -mcx16 atomic-store-6.c: In function ‘main’: atomic-store-6.c:13:1: internal compiler error: in assign_by_spills, at lra-assigns.c:1281 } ^ 0x883e7f assign_by_spills ../../gcc-svn/trunk/gcc/lra-assigns.c:1281 0x884320 lra_assign() ../../gcc-svn/trunk/gcc/lra-assigns.c:1439 Please submit a full bug report, I believe that the pattern is correct, and LRA is tripping on some unknown issue.