<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62137>62137</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            AArch64 SelectionDAG issue with byval Arguments
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AArch64,
            llvm:codegen
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          lenary
      </td>
    </tr>
</table>

<pre>
    If you run `llvm/test/CodeGen/Generic/2010-11-04-BigByval.ll` through `llc` with the default target set to aarch64, you get an error when EXPENSIVE_CHECKS is enabled.

The issue comes down to the fact that the new stack-allocated copy will need to be made using `memcpy`, which ends up nesting two `CALLSEQ_START`/`CALLSEQ_END` regions, the one for the call with the `byval` arg, and the one for the memcpy (Prolog-Epilog insertion assumes they are not nested, because they represent how big the stack needs to be, and are turned into the stack pointer adjustments, so the stack pointer can be different within these sequences for the call) This issue has tried to be solved in the past (e.g. in https://reviews.llvm.org/D42006), but this was reverted because it caused SPEC failures.

How other backends (e.g. RISC-V) solve this is to do byval argument copying *before* the CALLSEQ_START, and leave emitting the pointer argument value to the call handling code within the call sequence. 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVM1u2zoTfRp6M7AhUbISL7RQHDsNvqLIVwfF3RWUOBLZ0qQvfyz47S-GttsG924MmZyfM-ccjghBTxaxZesntn5eiBSV861BK_xl0Tt5aV9HuLgEPllgTWHM-cj4PmKIjO-3TuILWsb3L2jR64HxPS_KYlmWy6JePunp6XIWZmUMawqIyrs0qWuZgU5mHRVEhSBxFMlEiMJPGCFghOhACD-opmZ8myHQjbCA3jsPs0ILu7_edl8Or99237efdtv_HUAHQCt6g3LFimdWdNffd4WgQ0gIgztiAOlmSw2o9SiGCFGJmP9ZnCFEMfxcCmPcICJKGNzpArM2BiyipLwe4SgkQgraTjTPEY_D6cKagrDOSg8K0Mo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