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

    <tr>
        <th>Summary</th>
        <td>
            FastISel does not support unreachable with TrapUnreachable
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    FastISel currently aborts on `unreachable` terminators if `TrapUnreachable` is used:
```
; RUN: llc -mtriple=x86_64-- -O0 -fast-isel-abort=4 -trap-unreachable < %s | FileCheck %s

define void @test() {
; CHECK-LABEL: test:
; CHECK:       # %bb.0:
; CHECK-NEXT:    ud2
  unreachable
}
```
Nominally this is supported: https://github.com/llvm/llvm-project/blob/e95c74b423c4c78102121e0d7cd8479450a285df/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp#L1742-L1743

In practice, this fails to work on multiple levels: `fastEmit_()` is not generated by EmitFastISel. Even if it were generated, we'd run into issues with the API, because `ISD::TRAP` does not produce a register, so checking whether the function returns a valid register is not meaningful. 

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVU01v4zYQ_TXSZSCDpj590MGxnW3QIF3sZoHeFpQ4stnQpEFSdvPvO5TsxP24VCAkUvOG8-bxsbPyvX0UPjx9Rw396ByaoN9BdNYFD9ZAUrHROBT9QXQaaQUB3VEZEazzoIYIeHXi9OPvIOVh9CiTfJ2wbcLW9O865mX-AN9-vFAYtO4hOwanTpSZb_9sqp9VkWWQ_cYgG4hapjzqbGJE8QKyQOWyO1KQ5BtIeOkhqTfwqDRuDti_Tb-u5aa3xEEZhLNVEpKCBfQh4U3CV5T38Mlr88tu82v2vH7YPUd-E-yjjVs8RuYn4Xms1HUL9m9Y9rL7_fWKHSWfozS9E2tOqLf_qdOLjVJrOpFwIElp-PF0IiUmaeEQwsnHqvyRxl6Fw9gtenukhdbn2yc7OfsH9tTsY6dtRx9clX1ddAXP-6KvmyXjS75EJuteNkW9KkomeFPK4W4fFfM2VuIXNDQju9COyprt-gstbxZa9KcTCfK8rAuexXd-fwBPBk5OUFqPCd_MLQ1CaQ_BwsW6t2i446hD9AJoPKOO3UWLRSPsjir8nE_sajFjA-zRoBMkCHTvECEfXGB3RhMtqgJc0OEnNFa_EIdaghsJYqi-8n5EDxcSkZghrL8-RViHvSAnRw5P37dR63z9-m39NTKQFmcOJLAcewQBDvfK0w2Jqd5CH42ozB4uB6RN3bTzMJpJOgKH0RlPaWehyZS35FtrRxSGkoeRepkVTLFdVvSsWMVZKttcrvKVSIMKGj_v8Qevq1nu_TY3-I8bm45Ot__bTLNiNCmbsmnSQyuLZtnnQ7dkAqulaOqq4nXd5QyLvOxYmWrR0ZG2SfmQlNtUtZxxTuYr2SqvGVvkKKuBi5wz2cgckS4pHskfi1h4Yd0-de3EoRv3noKa1PKfQeG92hvE2_5iDAfrWqPeVJ9OZNuJ6V-G6YpI">