<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Improve codegen for struct init"
   href="https://bugs.llvm.org/show_bug.cgi?id=47574">47574</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Improve codegen for struct init
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: WebAssembly
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#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

<a href="https://godbolt.org/z/WEEdzs">https://godbolt.org/z/WEEdzs</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>