[llvm] [LoongArch] Add patterns for vstelm instructions (PR #139201)

Lu Weining via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 18:01:41 PDT 2025


SixWeining wrote:

This change causes SPEC2017 521.wrf_r fails to build with `-O3 -mlasx`:
```
LLVM ERROR: Error while trying to spill R6 from class GPR: Cannot scavenge register without an emergency spill slot!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang -fc1 -triple loongarch64-unknown-linux-gnu -emit-obj -I /home/llvm-ci/upstream/llvm-test-suite-139201/_build/External/SPEC/CFP2017rate/521.wrf_r -I /home/llvm-ci/upstream/llvm-test-suite-139201/External/SPEC/cpu2017-v1.1.5/benchspec/CPU/521.wrf_r/src -I /home/llvm-ci/upstream/llvm-test-suite-139201/External/SPEC/cpu2017-v1.1.5/benchspec/CPU/521.wrf_r/src/netcdf/include -I /home/llvm-ci/upstream/llvm-test-suite-139201/External/SPEC/cpu2017-v1.1.5/benchspec/CPU/521.wrf_r/src/inc -ffixed-line-length=72 -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu loongarch64 -target-feature +64bit -target-feature +f -target-feature +d -target-feature +ual -target-feature +lsx -target-feature +lasx -vectorize-loops -vectorize-slp -fversion-loops-for-stride -module-dir External/SPEC/CFP2017rate/521.wrf_r -resource-dir /home/llvm-ci/upstream/llvm-project-139201/_build/lib/clang/21 -mframe-pointer=none -O3 -o External/SPEC/CFP2017rate/521.wrf_r/CMakeFiles/wrf_specpp_rate.dir/module_ra_rrtm.F90.o -x f95 External/SPEC/CFP2017rate/521.wrf_r/CMakeFiles/wrf_specpp_rate.dir/module_ra_rrtm.F90-pp.f90
1.	Running pass 'Function Pass Manager' on module 'FIRModule'.
2.	Running pass 'Prologue/Epilogue Insertion & Frame Finalization' on function '@_QMmodule_ra_rrtmPtaugb12'
 #0 0x0000555559ea6ef0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x1d06ef0)
 #1 0x0000555559ea4bbc llvm::sys::RunSignalHandlers() (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x1d04bbc)
 #2 0x0000555559ea7a7c SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007ffffc03cf94 (linux-vdso.so.1+0xf94)
 #4 0x00002aaaad5d8440 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00002aaaad583f7c raise ./signal/../sysdeps/posix/raise.c:27:6
 #6 0x00002aaaad56d2e4 abort ./stdlib/abort.c:81:3
 #7 0x0000555559e46528 llvm::report_fatal_error(llvm::Twine const&, bool) (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x1ca6528)
 #8 0x000055555c945180 llvm::RegScavenger::scavengeRegisterBackwards(llvm::TargetRegisterClass const&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, bool, int, bool) (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x47a5180)
 #9 0x000055555c945708 llvm::RegScavenger::scavengeRegisterBackwards(llvm::TargetRegisterClass const&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, bool, int, bool) (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x47a5708)
#10 0x000055555c9460a4 scavengeVReg(llvm::MachineRegisterInfo&, llvm::RegScavenger&, llvm::Register, bool) RegisterScavenging.cpp:0:0
#11 0x000055555c945c24 scavengeFrameVirtualRegsInBlock(llvm::MachineRegisterInfo&, llvm::RegScavenger&, llvm::MachineBasicBlock&) RegisterScavenging.cpp:0:0
#12 0x000055555c945888 llvm::scavengeFrameVirtualRegs(llvm::MachineFunction&, llvm::RegScavenger&) (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x47a5888)
#13 0x000055555c8e8904 (anonymous namespace)::PEIImpl::run(llvm::MachineFunction&) PrologEpilogInserter.cpp:0:0
#14 0x000055555c8e9230 (anonymous namespace)::PEILegacy::runOnMachineFunction(llvm::MachineFunction&) PrologEpilogInserter.cpp:0:0
#15 0x000055555c7fdc60 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x465dc60)
#16 0x000055555ecfc670 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x6b5c670)
#17 0x000055555ed03b04 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x6b63b04)
#18 0x000055555ecfd214 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x6b5d214)
#19 0x0000555559eeb7e0 generateMachineCodeOrAssemblyImpl(clang::DiagnosticsEngine&, llvm::TargetMachine&, Fortran::frontend::BackendActionTy, llvm::Module&, Fortran::frontend::CodeGenOptions const&, llvm::raw_pwrite_stream&) FrontendActions.cpp:0:0
#20 0x0000555559eeb4e0 Fortran::frontend::CodeGenAction::executeAction() (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x1d4b4e0)
#21 0x0000555559edd7e0 Fortran::frontend::FrontendAction::execute() (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x1d3d7e0)
#22 0x0000555559ebe140 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x1d1e140)
#23 0x0000555559ee176c Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x1d4176c)
#24 0x0000555559cfa814 fc1_main(llvm::ArrayRef<char const*>, char const*) (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x1b5a814)
#25 0x0000555559cf9afc main (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x1b59afc)
#26 0x00002aaaad56d8b0 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#27 0x00002aaaad56d998 call_init ./csu/../csu/libc-start.c:128:20
#28 0x00002aaaad56d998 __libc_start_main ./csu/../csu/libc-start.c:347:5
#29 0x0000555559cf89c8 L0 (/home/llvm-ci/upstream/llvm-project-139201/_build/bin/flang+0x1b589c8)
flang-21: error: unable to execute command: Aborted
flang-21: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 21.0.0git
Target: loongarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/llvm-ci/upstream/llvm-project-139201/_build/bin
flang-21: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-21: note: diagnostic msg: /tmp/module_ra_rrtm-ddc6a8
flang-21: note: diagnostic msg: /tmp/module_ra_rrtm-ddc6a8.sh
flang-21: note: diagnostic msg: 

********************
```

A reduced llvm ir is attached. 
[reduced.ll.txt](https://github.com/user-attachments/files/20988893/reduced.ll.txt)


https://github.com/llvm/llvm-project/pull/139201


More information about the llvm-commits mailing list