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

    <tr>
        <th>Summary</th>
        <td>
            [RISCV] Frame pointer corruption with RVV stack temporaries
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:RISC-V
      </td>
    </tr>

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

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

<pre>
    We encountered a corruption of the frame pointer in our downstream.

IR contains an extract vector elt from nxv16i64. SplitVecOp_EXTRACT_VECTOR_ELT creates a scalable stack temporary with size 128 bytes, align 64 bytes. Because it's a scalable vector MachineFrameInfo::CreateStackObject does not call ensureMaxAlignment. Register allocation does not reserve x8, the frame pointer register, because we don't think the stack needs realignment. Register allocation uses x8 for other things. Prologue/epilogue runs and uses x8 as a frame pointer to align the vector stack. Value in x8 is garbage in the epilogue due to register allocation using it for other things in the middle of the function.

@preames @frasercrmck @rofirrim 

@sdesmalen-arm How does SVE deal with this? Or is there something special about RISC-V here?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9k1Fv2jAQxz9N8nJqFBII4SEPlIJWaRUToGxvlRMfwatjR7YDdJ9-50C70U6TAkmc-9_97u9zpflr8R0BVa175dAgBwa1NqbvnNAK9B7cAWFvWIvQaeFjQNB6b4Drk7LOIGujIH4I4vnl_3FDCZRjQllgCvDsDKsdHLF22gBKR9l0C-p8HGUiG0ew7aRwJdbr7nn5Y7eZL3bP5XKxW2-el193UFMBh5QKbM0kqySCdax-AYdtpw0zr3AS7gBW_EIYJTlUrxQeJAtgUjQKsvFlJYJ7rFlvEYQLkulNwivbE6sPQuHKN_uo9jpI53QtBoCtr7muflIkNU48SjsgvSTvbG_wiZ3nvl6LykWwwUZYbxUF6JoNVr6rDFo0R4Rz7ik_22uuYv-1ujKfkPSKuB0JhHoZZBcfFCK3JGL_L09ZLJWEPTWqSW2GRA358s1oqZseg2SFnRgewfTD7vF3GfOG3XI6fbXYs1wtHJAiKJmkJDQnpBQWGmYq1gwLPva9CqcfZTH_xCU42qpPvG9JWsE5bd3bgPaq9rqbSQzGcefHkzqgR4In32vTkmf0avReGCNa-KCwHG3LJKo7Zlr4ok-XjduWS-Dk8WXYCMUG6QrWxrfn6Wg3dIsDItgOa0GhrNK9g83jdnFXgo8hSYjFKMvS2SSeJGnIi5TP0hkLnXASi2By76PLYPIAqxuv_zqSA8CmLD8cA4E27I0sDs511k9usqKroeC-imrd0ouUx7fbXWe0n2V6Fdb2_sCsJlNCCQ9FmufjLK2qaVVnGfKqmiVpPuVxPOH5bJ_lIR0alNbTBklSEQQqThUvjdIS4YeiSOIkiUk6ypJ8nEZ5xlg8mfFJlrBqlsdkNbZMyMjjRNo0oSkGsqpvLH2UNBL2z0dmLY0aDh75_Kx3B20Kp7uONjUcmiiGDn4DoASn1w">