<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 - Redundant Restore of $x0 when memcpy always returns the first argument."
   href="https://bugs.llvm.org/show_bug.cgi?id=38849">38849</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Redundant Restore of $x0 when memcpy always returns the first argument.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>hiraditya@msn.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ cat test.cpp

struct BigStruct {
  int x[64];
};

void structByValue(BigStruct s);

void callStructByValue(int unused, int unused2, BigStruct s) {
  structByValue(s);
}


$ ./bin/clang++ -O3 -arch arm64 redundant-reg.cpp -S -o -


        .section        __TEXT,__text,regular,pure_instructions
        .ios_version_min 5, 0
        .globl  __Z17callStructByValueii9BigStruct ; -- Begin function
_Z17callStructByValueii9BigStruct
        .p2align        2
__Z17callStructByValueii9BigStruct:     ; @_Z17callStructByValueii9BigStruct
        .cfi_startproc
; %bb.0:                                ; %entry
        sub     sp, sp, #288            ; =288
        stp     x28, x27, [sp, #256]    ; 8-byte Folded Spill
        stp     x29, x30, [sp, #272]    ; 8-byte Folded Spill
        add     x29, sp, #272           ; =272
        .cfi_def_cfa w29, 16
        .cfi_offset w30, -8
        .cfi_offset w29, -16
        .cfi_offset w27, -24
        .cfi_offset w28, -32
        mov     x8, x2  
        mov     x0, sp <<<<------------------- Copy
        orr     w2, wzr, #0x100
        mov     x1, x8
        bl      _memcpy
        mov     x0, sp <<<<------------------- Copy
        bl      __Z13structByValue9BigStruct
        ldp     x29, x30, [sp, #272]    ; 8-byte Folded Reload
        ldp     x28, x27, [sp, #256]    ; 8-byte Folded Reload
        add     sp, sp, #288            ; =288
        ret
        .cfi_endproc
                                        ; -- End function

.subsections_via_symbols

We could just do remove the second 'mov x0, sp' as memcpy is guaranteed to
return the pointer to desination.
<a href="http://man7.org/linux/man-pages/man3/memcpy.3.html">http://man7.org/linux/man-pages/man3/memcpy.3.html</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>