<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 - Unnecessary spills when passing a struct argument by value"
   href="https://bugs.llvm.org/show_bug.cgi?id=46798">46798</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unnecessary spills when passing a struct argument by value
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

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

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

        <tr>
          <th>Reporter</th>
          <td>riyaz@synopsys.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23763" name="attach_23763" title="C test case to reproduce the problem">attachment 23763</a> <a href="attachment.cgi?id=23763&action=edit" title="C test case to reproduce the problem">[details]</a></span>
C test case to reproduce the problem

Clang generates unnecessary spills of %xmm0 and %rax for the attached test
case. See below (and attached test) for details. 

The issue goes away if an __attribute__((align(8)) is added to the variable
blah.

// Test case:
// compile: clang -O3 -S -emit-llvm -o test.s test.c 

typedef struct { int a; int b; int c; int d; int e; int f; } T;
extern int foo(T a);

extern T blah;

int boo() {
    return foo(blah);
}

Code generated by gcc:

        subq    $40, %rsp
        movq    blah+16(%rip), %rax
        movdqu  blah(%rip), %xmm0
        movq    %rax, 16(%rsp)
        movups  %xmm0, (%rsp)
        call    foo
        addq    $40, %rsp
        ret

Code generated by "clang -O3"

        subq    $56, %rsp
        movq    blah+16(%rip), %rax
        movq    %rax, 48(%rsp)      ; unnecessary
        movups  blah(%rip), %xmm0
        movaps  %xmm0, 32(%rsp)     ; unnecessary
        movq    48(%rsp), %rax      ; unnecessary
        movq    %rax, 16(%rsp)
        movaps  32(%rsp), %xmm0     ; unnecessary
        movups  %xmm0, (%rsp)
        callq   foo
        addq    $56, %rsp
        retq</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>