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

    <tr>
        <th>Summary</th>
        <td>
            [X86] LLVM ERROR: cannot select with `-fglobal-isel -finstrument-functions -flto`
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          patrick-rivos
      </td>
    </tr>
</table>

<pre>
    Testcase:
```c
int main() {}
```

Backtrace (from godbolt):
```
clang: warning: -fglobal-isel support for the 'x86_64' architecture is incomplete [-Wglobal-isel]
LLVM ERROR: cannot select: %2:gpr(p0) = G_INTRINSIC intrinsic(@llvm.returnaddress), 0 (in function: main)
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-20240408/bin/ld.lld --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -pie -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /app/output.s /lib/x86_64-linux-gnu/Scrt1.o /lib/x86_64-linux-gnu/crti.o /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.1/crtbeginS.o -L./lib -L/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/../lib/x86_64-unknown-linux-gnu -L/opt/compiler-explorer/clang-assertions-trunk-20240408/lib/clang/19/lib/x86_64-unknown-linux-gnu -L/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.1 -L/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.1/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.1/../../../../x86_64-linux-gnu/lib -L/lib -L/usr/lib -plugin-opt=mcpu=x86-64 -plugin-opt=-global-isel=1 /tmp/example-a842c4.o -rpath ./lib -rpath /opt/compiler-explorer/gcc-snapshot/lib64 -rpath /opt/compiler-explorer/gcc-snapshot/lib32 -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.1/crtendS.o /lib/x86_64-linux-gnu/crtn.o
1.      Running pass 'Function Pass Manager' on module 'ld-temp.o'.
2.      Running pass 'InstructionSelect' on function '@main'
 #0 0x00000000009c2928 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x9c2928)
 #1 0x00000000009c007c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fef58842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007fef588969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007fef58842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007fef588287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x0000000000823a2d (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x823a2d)
 #7 0x0000000002a792eb reportGISelDiagnostic(llvm::DiagnosticSeverity, llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, llvm::MachineOptimizationRemarkMissed&) Utils.cpp:0:0
 #8 0x0000000002a83313 llvm::reportGISelFailure(llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, char const*, llvm::StringRef, llvm::MachineInstr const&) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x2a83313)
 #9 0x00000000029f67f7 llvm::InstructionSelect::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x29f67f7)
#10 0x00000000035f4611 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#11 0x00000000050ced73 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x50ced73)
#12 0x00000000050cefb1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x50cefb1)
#13 0x00000000050cf815 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x50cf815)
#14 0x0000000002f7b8fd codegen(llvm::lto::Config const&, llvm::TargetMachine*, std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex const&) LTOBackend.cpp:0:0
#15 0x0000000002f7d145 llvm::lto::backend(llvm::lto::Config const&, std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex&) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x2f7d145)
#16 0x0000000002f6f658 llvm::lto::LTO::runRegularLTO(std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x2f6f658)
#17 0x0000000002f6fbbc llvm::lto::LTO::run(std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, std::function<llvm::Expected<std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>> (unsigned int, llvm::StringRef, llvm::Twine const&)>) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x2f6fbbc)
#18 0x0000000000b89259 lld::elf::BitcodeCompiler::compile() (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0xb89259)
#19 0x0000000000aeaf5f void lld::elf::LinkerDriver::compileBitcodeFiles<llvm::object::ELFType<(llvm::endianness)1, true>>(bool) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0xaeaf5f)
#20 0x0000000000b00f3b void lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::endianness)1, true>>(llvm::opt::InputArgList&) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0xb00f3b)
#21 0x0000000000b0d264 lld::elf::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0xb0d264)
#22 0x0000000000b0ea52 lld::elf::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0xb0ea52)
#23 0x00000000009f8e1b lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x9f8e1b)
#24 0x0000000000934c81 lld_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x934c81)
#25 0x000000000082d5d4 main (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x82d5d4)
#26 0x00007fef58829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#27 0x00007fef58829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#28 0x000000000093460e _start (/opt/compiler-explorer/clang-assertions-trunk-20240408/bin/ld.lld+0x93460e)
clang: error: unable to execute command: Aborted (core dumped)
clang: error: linker command failed due to signal (use -v to see invocation)
Compiler returned: 254
```

Godbolt: https://godbolt.org/z/6K4j7W759
Works in LLVM 17.

Found via fuzzer

Possibly related to RISC-V failure: #88057
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWl1T47jS_jXmRuWUI3_mggsgZF_qZXamCGf33KVkqe1okSUfSWZgfv0pWc6HQ2BgdjIXW2eKgURWdz_9dEstySLG8FoCnAfpZZDOz0hn10qft8RqTh9CzR-VOSsVez6_B2MpMRDEF0E0D6KLIIv8D_XfubSoIVwGuAjwDAX5ZZDPD7oOX_vfl4Q-WE0ooAAXlVYNqhUrlbABnr004r9SQWQdxBfoK9GS-49hVQtVEhFyAwKZrm2VtqhSGtm1050_FdkqSwKcI6LpmlugttOAuEFcUtW0AiygIL0M_9xTFKQD9tvbPz6h67u7z3fOGCVSKosMCKDWNQQ4xUF8Ubc6wEUb9Z7Hc_Tb6ub3-7ub35c3V4hLq7k0nDpmkkiIx2aiwXZaEsY0GOMcxlcockRwiapOUsuVdOo9oTMP5cvt9cXyGpmubLhFBJVdjTT07lqF1ta2xhGHFwFe1Nyuu3JCVRPghTM5_Albrf5y2PGCG9OBCfACEckcF6Jj0JNGNTFrVG4CNPHml5bQB8S6pt2GJ5oE0eyLVrUmDSK67hqQ1nheFqp1VhzDXIAO4akVSoN2bS6MITEGtHPUhFZ38iHEEU6iJCoCvCid2wvBJkIwFIZrYtahsc8Cgnheyw6FIazDSpMGwjXTKGwQiGrlI43ClgMK2bMkDaeh4PIBtAMkeOnyYCGYa-yewqciC7NkYtQEo1C5LqRtHfLOtp2dmEEowAuveRCrZRfgxZJqO52oN_tQbbnv8joZNaWhkaQ1a2W3umpKj2ucJpNoMvWqS6i5XE4UCm8nXhKFtz-F-Mnk0KtOPkj1Ve6w_H1TXr8f0ngxnf1tkz_C5Cl0bgg8-NWnn7d3PGH2nx1KdEZ_R26_x6H0L_HvSP9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