Issue 243545
Summary [ARM] LOB intrinsic emitted when instruction selection does not support it
Labels new issue
Assignees
Reporter adamgemmell
    With `+lob` enabled on `thumbv8m.main-none-eabihf`, LLVM [emits `%llvm.start.loop.iterations`](https://github.com/llvm/llvm-project/blob/9d0476eab3f424b60123333f27afb2fa6ca6e1a2/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp#L2339). However, unless the `+v8.1m.main` feature is also enabled, [LLVM cannot select an instruction for this intrinsic](https://github.com/llvm/llvm-project/blob/9d0476eab3f424b60123333f27afb2fa6ca6e1a2/llvm/lib/Target/ARM/ARMInstrThumb2.td#L5685).

### Reproducer

https://godbolt.org/z/a9949dWE3

```
unsigned sum(const unsigned *p, unsigned n) {
      unsigned s = 0;
      for (unsigned i = 0; i < n; ++i)
          s += p[i];
      return s;
}
```

```
$ clang --target=thumbv8m.main-none-eabihf -O2 -Xclang -target-feature -Xclang +lob [...]
```

### Expected

Compilation succeeds

### Observed

```
fatal error: error in backend: Cannot select: intrinsic %llvm.start.loop.iterations
```

Observed on LLVM 23.1.0 in Rust as well as the lastest trunk on godbolt:

```
clang version 24.0.0git (https://github.com/llvm/llvm-project.git 08177dab26af5f6b6cbf678c1c9f49a115f64f84)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /cefs/6d/6d6b30198cf77d3f3f431686_clang-trunk-20261117/bin
Compiler returned: 0
```

<details><summary>Full output</summary>
<p>

```
fatal error: error in backend: Cannot select: intrinsic %llvm.start.loop.iterations
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics --target=thumbv8m.main-none-eabihf -Xclang -target-feature -Xclang +lob -O2 <source>
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module '<source>'.
4.	Running pass 'ARM Instruction Selection' on function '@_Z3sumPKjj'
 #0 0x0000000004854d98 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4854d98)
 #1 0x0000000004852a7c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4852a7c)
 #2 0x00000000047902a3 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x47902a3)
 #3 0x000000000484a3ce llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x484a3ce)
 #4 0x000000000178bd3b LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0
 #5 0x0000000004799e63 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4799e63)
 #6 0x0000000005f1869d llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f1869d)
 #7 0x0000000005f2043d llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int, unsigned char const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f2043d)
 #8 0x000000000245670d (anonymous namespace)::ARMDAGToDAGISel::Select(llvm::SDNode*) ARMISelDAGToDAG.cpp:0:0
 #9 0x0000000005f17694 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f17694)
#10 0x0000000005f25002 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f25002)
#11 0x0000000005f272a1 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f272a1)
#12 0x0000000005f28ce5 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f28ce5)
#13 0x000000000245e884 (anonymous namespace)::ARMDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) ARMISelDAGToDAG.cpp:0:0
#14 0x0000000005f17301 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f17301)
#15 0x0000000003c43225 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3c43225)
#16 0x0000000004175e72 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4175e72)
#17 0x0000000004176251 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4176251)
#18 0x0000000004176d66 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4176d66)
#19 0x0000000005ae6578 runCodeGenPipelineLegacy(llvm::TargetMachine&, llvm::Module&, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream*, llvm::CodeGenFileType, bool, llvm::ModuleSummaryIndex const*, bool) RunCodeGen.cpp:0:0
#20 0x0000000005ae66e9 llvm::runCodeGenPipeline(llvm::TargetMachine&, llvm::Module&, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream*, llvm::CodeGenFileType, bool, bool, llvm::ModuleSummaryIndex const*, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5ae66e9)
#21 0x0000000004bf4e2b (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#22 0x0000000004bf52f4 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4bf52f4)
#23 0x000000000522522a clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x522522a)
#24 0x000000000836468c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x836468c)
#25 0x0000000005226055 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5226055)
#26 0x0000000005558981 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5558981)
#27 0x00000000054ea2d5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x54ea2d5)
#28 0x000000000562a06b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x562a06b)
#29 0x000000000178dd38 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x178dd38)
#30 0x0000000001785ccb ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#31 0x0000000001785d73 int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#32 0x00000000052a2689 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#33 0x00000000047901a3 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x47901a3)
#34 0x00000000052a30cd clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#35 0x0000000005262212 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5262212)
#36 0x0000000005265184 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5265184)
#37 0x000000000527327c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x527327c)
#38 0x000000000178a7d1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x178a7d1)
#39 0x00000000017196c3 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0x17196c3)
#40 0x00007644dce2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#41 0x00007644dce2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#42 0x0000000001785775 _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0x1785775)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70
```

</p>
</details>
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to