Skip to content

[LoongArch] ICE on SIMD code with SIMD disabled #131771

Open
@xen0n

Description

@xen0n

While debugging loongson-community/discussions#87 I hit this ICE when I attempted to disable SIMD entirely.

Minimized reproducer:

// clang-20 --march=loongarch64 -mno-lsx -S -o - "x.cc"
__attribute__((__vector_size__(16))) long foo = __builtin_lsx_vinsgr2vr_w(foo, 0, 0);
; RUN: llc issue131771.ll
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "loongarch64-unknown-linux-gnu"

define void @__cxx_global_var_init() #0 {
  %1 = call <4 x i32> @llvm.loongarch.lsx.vinsgr2vr.w(<4 x i32> zeroinitializer, i32 0, i32 0)
  %2 = bitcast <4 x i32> %1 to <2 x i64>
  store <2 x i64> %2, ptr null, align 16
  ret void
}

; Function Attrs: nounwind memory(none)
declare <4 x i32> @llvm.loongarch.lsx.vinsgr2vr.w(<4 x i32>, i32, i32 immarg) #1

attributes #0 = { "target-cpu"="loongarch64" }
attributes #1 = { nounwind memory(none) }

Output:

x.cc:1:75: warning: variable 'foo' is uninitialized when used within its own initialization [-Wuninitialized]
    1 | __attribute__((__vector_size__(16))) long foo = __builtin_lsx_vinsgr2vr_w(foo, 0, 0);
      |                                           ~~~                             ^~~
fatal error: error in backend: Do not know how to split the result of this operator!

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: clang-20 -march=loongarch64 -mno-lsx -S -o - x.cc
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module 'x.cc'.
4.	Running pass 'LoongArch DAG->DAG Pattern Instruction Selection' on function '@__cxx_global_var_init'
 #0 0x00007fffe6a258c4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x7c58c4)
 #1 0x00007fffe6a2341c llvm::sys::RunSignalHandlers() (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x7c341c)
 #2 0x00007fffe69418f8 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
 #3 0x00007fffe6941894 (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x6e1894)
 #4 0x00007fffe6a1f4f4 llvm::sys::Process::Exit(int, bool) (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x7bf4f4)
 #5 0x0000555556811788 LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0
 #6 0x00007fffe695403c llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x6f403c)
 #7 0x00007fffe6953f1c (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x6f3f1c)
 #8 0x00007fffe72bd228 (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x105d228)
 #9 0x00007fffe729a3d0 llvm::DAGTypeLegalizer::run() (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x103a3d0)
#10 0x00007fffe729f214 llvm::SelectionDAG::LegalizeTypes() (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x103f214)
#11 0x00007fffe73ae430 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x114e430)
#12 0x00007fffe73adc60 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x114dc60)
#13 0x00007fffe73abfc4 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x114bfc4)
#14 0x00007fffe73aa718 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x114a718)
#15 0x00007fffe6ea7ab8 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0xc47ab8)
#16 0x00007fffe6bb58a8 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x9558a8)
#17 0x00007fffe6bbc324 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x95c324)
#18 0x00007fffe6bb5fb4 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x955fb4)
#19 0x00007fffefbd1558 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, 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*) (/usr/lib/llvm/20/bin/../lib64/libclang-cpp.so.20.1+0x1ca1558)
#20 0x00007ffff0000990 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/lib/llvm/20/bin/../lib64/libclang-cpp.so.20.1+0x20d0990)
#21 0x00007fffee6a2edc clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm/20/bin/../lib64/libclang-cpp.so.20.1+0x772edc)
#22 0x00007ffff09cd1dc clang::FrontendAction::Execute() (/usr/lib/llvm/20/bin/../lib64/libclang-cpp.so.20.1+0x2a9d1dc)
#23 0x00007ffff096115c clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm/20/bin/../lib64/libclang-cpp.so.20.1+0x2a3115c)
#24 0x00007ffff0a53618 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm/20/bin/../lib64/libclang-cpp.so.20.1+0x2b23618)
#25 0x0000555556813e04 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm/20/bin/clang-20+0x13e04)
#26 0x000055555680e318 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x00007ffff05900e4 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
#28 0x00007fffe694185c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/lib/llvm/20/bin/../lib64/libLLVM.so.20.1+0x6e185c)
#29 0x00007ffff05925d0 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/usr/lib/llvm/20/bin/../lib64/libclang-cpp.so.20.1+0x26625d0)
#30 0x00007ffff05541b4 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/usr/lib/llvm/20/bin/../lib64/libclang-cpp.so.20.1+0x26241b4)
#31 0x00007ffff05548b4 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/usr/lib/llvm/20/bin/../lib64/libclang-cpp.so.20.1+0x26248b4)
#32 0x00007ffff05685cc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/usr/lib/llvm/20/bin/../lib64/libclang-cpp.so.20.1+0x26385cc)
#33 0x000055555680f86c clang_main(int, char**, llvm::ToolContext const&) (/usr/lib/llvm/20/bin/clang-20+0xf86c)
#34 0x000055555680c7d8 main (/usr/lib/llvm/20/bin/clang-20+0xc7d8)
#35 0x00007fffe5d9d54c __libc_start_call_main /usr/src/debug/sys-libs/glibc-2.41-r1/glibc-2.41/csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#36 0x00007fffe5d9d630 call_init /usr/src/debug/sys-libs/glibc-2.41-r1/glibc-2.41/csu/../csu/libc-start.c:128:20
#37 0x00007fffe5d9d630 __libc_start_main@@GLIBC_2.36 /usr/src/debug/sys-libs/glibc-2.41-r1/glibc-2.41/csu/../csu/libc-start.c:347:5
#38 0x000055555680c888 _start (/usr/lib/llvm/20/bin/clang-20+0xc888)
clang-20: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 20.1.0
Target: loongarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/20/bin
Configuration file: /etc/clang/20/loongarch64-unknown-linux-gnu-clang.cfg
clang-20: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-20: note: diagnostic msg: /tmp/x-b7247c.cpp
clang-20: note: diagnostic msg: /tmp/x-b7247c.sh
clang-20: note: diagnostic msg: 

********************

We shouldn't crash even though the user request might be invalid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions