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

    <tr>
        <th>Summary</th>
        <td>
            GlobalISel Assertion failure with intrinsic returning `token` type
        </td>
    </tr>

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

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

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

<pre>
    Small reproducer:
```llvm
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
target triple = "arm64-apple-darwin21.6.0"

define void @__init__() gc "statepoint-example" {
  %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @builtins.__init__, i32 0, i32 0, i32 0, i32 0) [ "deopt"() ]
  ret void
}

declare void @builtins.__init__()

declare token @llvm.experimental.gc.statepoint.p0(i64 immarg, i32 immarg, ptr, i32 immarg, i32 immarg, ...)
```
This can be run with `llc -O0` which will cause GlobalISel to be used which will cause an assertion failure here:
https://github.com/llvm/llvm-project/blob/cfd2c5ce580fce744f6fd6ba34e869cab05e94c3/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp#L207-L208

While statepoints (and I believe essentially all intrinsics returning `token`?) are currently not supported, the assertion failure leads to a crash instead of the fallback to fastisel which would otherwise make compilation succeed. 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVE1vnDwQ_jVwsRax5vvAYdtVqkiVKjWVelwZewC_MTayTdL013cMm7B9mx6KELaH-XzmGXdGvLQPE1OKWJitEQsHG2WnKD1H6Skq0-1V6mnaRJ7ZATwRzDPFXsziSZSdSUQpHCa0MwdZ5riW-UEeaY07_B50RjfZQ5BR-psrb-Ws4NUNsxPqsRlFB8Hss9T0mJRJ-ma1fQX0UgN5MlKQKE8vF6m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