[llvm-bugs] [Bug 41047] New: Missed tail cail optimization when copying arrays

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Mar 12 11:30:36 PDT 2019


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

            Bug ID: 41047
           Summary: Missed tail cail optimization when copying arrays
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

-03, Haswell.

void memcpy_tail_call (int *__restrict__ p, int *__restrict__ q, int N)
{
  p[0] = q[N-1];
  for (int i = 1; i < N; i++)
    {
      p[i] = q[i-1];
    }
}

memcpy_tail_call(int*, int*, int):              # @memcpy_tail_call(int*, int*,
int)
        lea     eax, [rdx - 1]
        movsxd  rcx, eax
        mov     ecx, dword ptr [rsi + 4*rcx]
        mov     dword ptr [rdi], ecx
        cmp     edx, 2
        jl      .LBB0_2
        push    rax
        add     rdi, 4
        mov     edx, eax
        shl     rdx, 2
        call    memcpy
        add     rsp, 8
.LBB0_2:
        ret


GCC generates:
memcpy_tail_call(int*, int*, int):
        movsx   rax, edx
        mov     eax, DWORD PTR [rsi-4+rax*4]
        mov     DWORD PTR [rdi], eax
        cmp     edx, 1
        jle     .L3
        lea     eax, [rdx-2]
        add     rdi, 4
        lea     rdx, [4+rax*4]
        jmp     memcpy
.L3:
        ret

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190312/30bd6d3b/attachment.html>


More information about the llvm-bugs mailing list