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

    <tr>
        <th>Summary</th>
        <td>
            'throws' ought to be explicit IR instruction
        </td>
    </tr>

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

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

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

<pre>
    This is a touch of spitballing, but...

The actual throwing of an exception ought to be an explicit (and terminal) instruction in the IR, instead of delegating this to a function call. The problem with a function call is that optimizers are not able to know that the function call definitely throws the argument in cases (and does nothing other than that) and so can't do flow analysis with it. Not unless you do something truly nasty like hard-coding the name of the `throws` implementation function; that only ought to be important when doing the conversion from IR into actual machine code. Having it as a basic conceptual instruction in the IR would be much tidier.

When would this become an issue? Well, the most obvious case would be when there is aggressive inlining going on that moves the instruction site that (definitely) throws into the same function as the instruction site that catches; in that case, it *should* be possible to turn a throw-and-catch into a suitable jump between basic blocks; there definitely wouldn't be any stack unwinding required. Right now, that would require detecting the special function, and that doesn't seem to be anything other than a horrible way to do it.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VE2P2zgM_TX2RRjDkSdpcvBhusWgvfRQFOiZlhlbjSx59ZE0_fUlpWQ-dhcLBIkdkY-Pj48a3Hjtv886CPqAiC6pWbijCKuOAxij7VTJv8SQYtM0Vfupap_K9_cZBaiYwIg4e3ehQM4DK_CXwjVqZ4VL0xwJUwxYDlajlY6iknuwo4joF23BVPIgtA3RJ5XTtCVIFF--cWU-QBgZe0SDE0SuFJkxAYM4JluyFLFtBNNavRsMLuKi4_zPCG4zzhCFI4qL_o2e2vYorIsCKItBT9ZdShDTeJ8-4lFbHdFcS9shx4Cf0oI2MnUFAcO9xdHRM2HPWR4K9QxsMzq3zTHBUY6t5IdI4eJoqDiQKtdAVHMLOjbiK_FL1mAI4uoSB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