https://bugs.llvm.org/show_bug.cgi?id=32086

            Bug ID: 32086
           Summary: Multiple moves compiled inefficiently
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

Consider:

double a[4], b[4], c[4];

void foo ()
{
  a[0] = c[0];
  a[1] = c[1];
  a[2] = c[0];
  a[3] = c[1];
  b[0] = c[2];
  b[1] = c[3];
  b[2] = c[2];
  b[3] = c[3];
}

clang compiles this with -O3 to:

foo:                                    # @foo
        mov     rax, qword ptr [rip + c]
        mov     qword ptr [rip + a], rax
        mov     rcx, qword ptr [rip + c+8]
        mov     qword ptr [rip + a+8], rcx
        mov     qword ptr [rip + a+16], rax
        mov     qword ptr [rip + a+24], rcx
        mov     rax, qword ptr [rip + c+16]
        mov     qword ptr [rip + b], rax
        mov     rcx, qword ptr [rip + c+24]
        mov     qword ptr [rip + b+8], rcx
        mov     qword ptr [rip + b+16], rax
        mov     qword ptr [rip + b+24], rcx
        ret

gcc on the other hand gives the more efficient:

foo:
        movapd  xmm1, XMMWORD PTR c[rip]
        movapd  xmm0, XMMWORD PTR c[rip+16]
        movaps  XMMWORD PTR a[rip], xmm1
        movaps  XMMWORD PTR a[rip+16], xmm1
        movaps  XMMWORD PTR b[rip], xmm0
        movaps  XMMWORD PTR b[rip+16], xmm0
        ret

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to