[llvm-bugs] [Bug 47574] New: Improve codegen for struct init

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 18 01:06:24 PDT 2020


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

            Bug ID: 47574
           Summary: Improve codegen for struct init
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: WebAssembly
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

#include <string.h>
#include <stdlib.h>

struct X
{
  char mem0[10];
  char mem1[10];
};


void bar (struct X);


void
foo1()
{
  struct X x = { };
  bar (x);
}

void
foo2 ()
{
  struct X x;
  memset (&x, 0, sizeof x);
  bar (x);
}

void
foo3 ()
{
  struct X *x = calloc (sizeof (struct X), 1);
  bar (*x);
}

Clang -O3:

foo1:                                   # @foo1
        sub     rsp, 56
        xorps   xmm0, xmm0
        movaps  xmmword ptr [rsp + 32], xmm0
        mov     dword ptr [rsp + 48], 0
        mov     eax, dword ptr [rsp + 48]
        mov     dword ptr [rsp + 16], eax
        movaps  xmm0, xmmword ptr [rsp + 32]
        movups  xmmword ptr [rsp], xmm0
        call    bar
        add     rsp, 56
        ret
foo2:                                   # @foo2
        sub     rsp, 56
        xorps   xmm0, xmm0
        movaps  xmmword ptr [rsp + 32], xmm0
        mov     dword ptr [rsp + 48], 0
        mov     eax, dword ptr [rsp + 48]
        mov     dword ptr [rsp + 16], eax
        movaps  xmm0, xmmword ptr [rsp + 32]
        movups  xmmword ptr [rsp], xmm0
        call    bar
        add     rsp, 56
        ret
foo3:                                   # @foo3
        sub     rsp, 56
        mov     edi, 20
        mov     esi, 1
        call    calloc
        mov     ecx, dword ptr [rax + 16]
        mov     dword ptr [rsp + 48], ecx
        movups  xmm0, xmmword ptr [rax]
        movaps  xmmword ptr [rsp + 32], xmm0
        mov     eax, dword ptr [rsp + 48]
        mov     dword ptr [rsp + 16], eax
        movaps  xmm0, xmmword ptr [rsp + 32]
        movups  xmmword ptr [rsp], xmm0
        call    bar
        add     rsp, 56
        ret


GCC -O3:

foo1:
        sub     rsp, 72
        pxor    xmm0, xmm0
        mov     DWORD PTR [rsp+16], 0
        movups  XMMWORD PTR [rsp], xmm0
        call    bar
        add     rsp, 72
        ret
foo2:
        sub     rsp, 72
        pxor    xmm0, xmm0
        mov     DWORD PTR [rsp+48], 0
        mov     DWORD PTR [rsp+16], 0
        movaps  XMMWORD PTR [rsp+32], xmm0
        movups  XMMWORD PTR [rsp], xmm0
        call    bar
        add     rsp, 72
        ret
foo3:
        sub     rsp, 8
        mov     esi, 1
        mov     edi, 20
        call    calloc
        sub     rsp, 32
        movdqu  xmm0, XMMWORD PTR [rax]
        movups  XMMWORD PTR [rsp], xmm0
        mov     eax, DWORD PTR [rax+16]
        mov     DWORD PTR [rsp+16], eax
        call    bar
        add     rsp, 40
        ret

https://godbolt.org/z/WEEdzs

-- 
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/20200918/0dd17d59/attachment-0001.html>


More information about the llvm-bugs mailing list