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

    <tr>
        <th>Summary</th>
        <td>
            [CodeGen] Machine Late Instructions Cleanup Pass recursion
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Hi!

We observed that the method MachineLateInstrsCleanup::clearKillsForDef does a recursive traversal of machine basic block predecessors. While this usually is no big deal, we encountered a case where we had a recursion depth of way over 10,000 calls, which resulted in a stack overflow.

As far as we understood the code, this is part of an optimization: If an instruction is considered as redundant, remove it, and adjust flags for this. We assume that a deep recursion can happen if the previous def is very far away from the redundant def, so our assumption is that in this case the optimization won't help much anyway.

My question is: Is our understanding of the code correct, that when the recursion gets too deep, we can simply stop with clearKillsForDef and keep the redundant instruction? And is anyone else aware of recursion problems caused by clearKillsForDef?

Thanks,
Torsten
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxklE-P4ygQxT8NuZQmcvDk38GHbLey29odaQ8j9bkM5cA0Bi8FibyffgVObzKaSyIbqPfej3Ihs714ok5sfxPb1xXmZELsvofIifyb6cmv-qDn7g8r5EY0r6I5Lb_vBKFnilfSkAwmSIZgpGSChm-ojPX0FyZ685wivzhCnyfRnkR7Uo4w_mmd43OIrzSADsSAEEnlyPZKkCJeKTI6CAOMSzHoka2C3gX1AVMkTYqYQ-Q1vBvrCJKxDJkzOjeDZfABensBTeiEfIEbAXkVsk8USQOCQia4GYpU1gzqh4XgQdOUTJG_4QzhShE2jZAvTdOAQue4ljRWGYjE2SXSYD0gcEL1UQ8MLtzWz8RODANGQC562WuKnELQFZwKmkrJGsIyTBhTUUcPYUp2tP9issGL9gRv9a0tXLMqL8t-FTxbvSRjiKSz1-hTKRlpDFcCWx_Qa0D9I3OCweGFYQixiq7hnQCZ80jLdSJooumJiEIPBqeJPNihmp4iXW3IDJqGYuJKcV4iFmhDDGPd9r-bsq-Y4AAhx0Vt-kxQRa1fCNS7KWefw8MteCH3CQy5CcasDKCfbzj_RPnbDP9k4nvZCoyr3J04em39pbD95A4qxEgqLfwxlabwd-ef4S-UGFIIFcq9nQoQtuPkZuAUJrjZZOCX5i7EPwrJn1E83Z9oz3DyukBAPwdPQI6pQIxUfD5cTDH0jsbCJzNp6Odf9ER7fqbx3aD_KM16f1y-65XuWn1sj7iibrOXm3Z33Mt2ZbrN0Pd0aBqSfXtAuT2oo9R4oKbRPelDu7KdbOTXZr85NrvNVrZrtVN4OPYNSt3u9oe9-NrQiNatnbuO6xAvK8ucqTsed81h5bAnx3XYSOnpBnVRSFlmT-zKmS99vrD42jjLiR9Vkk2uTqmXoOl38mL7-jlmoMwZeHsAZbjPG_gbmR_8Vjm6zqQ0lbYQ8izk-WKTyf1ahVHIcxG7_32ZYvhRe-JcLbKQ5yXCtZP_BQAA___cSMw1">