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

    <tr>
        <th>Summary</th>
        <td>
            [CodeGenPrepare] GC relocate is incorrectly tied to the statepoint
        </td>
    </tr>

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

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

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

<pre>
    Godbolt link: https://godbolt.org/z/39frWe6ja

Run opt -codegenprepare on the test
[bug.ll.txt](https://github.com/llvm/llvm-project/files/9000568/bug.ll.txt)

Failure looks like:
```
gc relocate is incorrectly tied to the statepoint
  %tmp5 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token undef, i32 1, i32 1) ; (opt: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::GCStatepointInst; From = const llvm::Value]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -codegenprepare <source>
1.      Running pass 'Function Pass Manager' on module '<source>'.
2.      Running pass 'Module Verifier' on function '@widget'
 #0 0x000055b0e8778c2f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x000055b0e877665c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f7ef27743c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #3 0x00007f7ef224103b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4303b)
 #4 0x00007f7ef2220859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f7ef2220729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f7ef2232006 (/lib/x86_64-linux-gnu/libc.so.6+0x34006)
 #7 0x000055b0e7e89fab llvm::GCProjectionInst::getStatepoint() const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2c89fab)
 #8 0x000055b0e7e8a376 llvm::GCRelocateInst::getBasePtr() const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2c8a376)
 #9 0x000055b0e7d56a5c (anonymous namespace)::AssemblyWriter::printInfoComment(llvm::Value const&) AsmWriter.cpp:0:0
#10 0x000055b0e7d59f92 (anonymous namespace)::AssemblyWriter::printInstruction(llvm::Instruction const&) AsmWriter.cpp:0:0
#11 0x000055b0e7d62199 llvm::Value::print(llvm::raw_ostream&, llvm::ModuleSlotTracker&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2b62199)
#12 0x000055b0e7f24beb llvm::VerifierSupport::Write(llvm::Value const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2d24beb)
#13 0x000055b0e7f2bb28 void llvm::VerifierSupport::CheckFailed<llvm::CallBase, llvm::Value*>(llvm::Twine const&, llvm::CallBase const&, llvm::Value* const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2d2bb28)
#14 0x000055b0e7f40313 (anonymous namespace)::Verifier::visitCallBase(llvm::CallBase&) Verifier.cpp:0:0
#15 0x000055b0e7f43561 (anonymous namespace)::Verifier::visitCallInst(llvm::CallInst&) Verifier.cpp:0:0
#16 0x000055b0e7f48734 llvm::InstVisitor<(anonymous namespace)::Verifier, void>::visit(llvm::Function&) Verifier.cpp:0:0
#17 0x000055b0e7f48a98 (anonymous namespace)::Verifier::verify(llvm::Function const&) Verifier.cpp:0:0
#18 0x000055b0e7f49185 (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) Verifier.cpp:0:0
#19 0x000055b0e7ead366 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2cad366)
#20 0x000055b0e7ead6b9 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2cad6b9)
#21 0x000055b0e7eae019 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2cae019)
#22 0x000055b0e5dee67f main (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xbee67f)
#23 0x00007f7ef22220b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b3)
#24 0x000055b0e5ea542a _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xca542a)
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9WFtvnDgU_jXMizUIzP1hHiaTJlup1Y6aqH2MDBjGHYORMU2yv36PzVwwyTZJm640F_DlO9-5G3JRPq6uRZkLrhBn7d4J1minVNfDhYOv4FOPs66QNdz9A98gq-Q3Gn8njnfpeOvx98vQItEptCxESWvadpJ2RFIkWqR2FCnaq8Py6CIfapdzVz0oJ7p0cDoTyNRuyN1CNHDD-Y_j37KT4jstFNxWjNMe_jPP86I4hasJJM6mvK4I4wPw4ELse1BxT7WgcUHsHT7mti6QpFwURFHEesTaQkgJ8vgjUoyWSAmjSa9gQSdYe9AHIQdHquki5ASXqCCco0LwsigQSxEpS9l3pKCgpa-Z4TVyQk-r49KHjkrW0FYR7taFexTudj4DlVIl9rRFQ1vSysEbxAKM_MlFBvIuQHYKVtdeAyNIIdRTYx1MCPrwoaTngZuh64TUKzakV6yt3R3gREmq0UpacPXYad5kUEKLM9vAdsG6gPUwAfIAZ22oRBf34DZ0K4wVzkuvNzcne31sYRtw1vtGYwkYmSz-SvhAdUgAgXXfU6kYhA84iPXECTa3wgk-gFxYZmTiGD7whw0fmH8c5_UkkfWgTYtEZTzZdESxnEMgGqXAftjBCaogOmjpjp7cfvqwvvmA-iFvmEIEQUxBRGgbad-_OUhZ3w8mShFpS3QwvwmhQpJ-h3JS7JWE2DiIB0MVe1QO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