[llvm] [PHIElimination] Reuse existing COPY in predecessor basic block (PR #131837)
Mikael Holmén via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 30 00:57:28 PDT 2025
mikaelholmen wrote:
Hello @guy-david
The following starts crashing with this patch:
```
llc -O0 -o /dev/null bbi-108462.ll -enable-subreg-liveness=1 -optimize-regalloc -mtriple=aarch64-none-linux-gnu
```
It crashes like
```
llc: ../include/llvm/CodeGen/Register.h:83: unsigned int llvm::Register::virtRegIndex() const: Assertion `isVirtual() && "Not a virtual register"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: build-all/bin/llc -O0 -o /dev/null bbi-108462.ll -enable-subreg-liveness=1 -optimize-regalloc -mtriple=aarch64-none-linux-gnu
1. Running pass 'Function Pass Manager' on module 'bbi-108462.ll'.
2. Running pass 'Register Coalescer' on function '@f3'
#0 0x000055cf75860066 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build-all/bin/llc+0x76a7066)
#1 0x000055cf7585db85 llvm::sys::RunSignalHandlers() (build-all/bin/llc+0x76a4b85)
#2 0x000055cf75860799 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f433c539d10 __restore_rt (/lib64/libpthread.so.0+0x12d10)
#4 0x00007f4339ed952f raise (/lib64/libc.so.6+0x4e52f)
#5 0x00007f4339eace65 abort (/lib64/libc.so.6+0x21e65)
#6 0x00007f4339eacd39 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d39)
#7 0x00007f4339ed1e86 (/lib64/libc.so.6+0x46e86)
#8 0x000055cf74ac72d5 llvm::CoalescerPair::setRegisters(llvm::MachineInstr const*) (build-all/bin/llc+0x690e2d5)
#9 0x000055cf74acc643 (anonymous namespace)::RegisterCoalescer::joinCopy(llvm::MachineInstr*, bool&, llvm::SmallPtrSetImpl<llvm::MachineInstr*>&) RegisterCoalescer.cpp:0:0
#10 0x000055cf74acbd38 (anonymous namespace)::RegisterCoalescer::copyCoalesceWorkList(llvm::MutableArrayRef<llvm::MachineInstr*>) RegisterCoalescer.cpp:0:0
#11 0x000055cf74ac9220 (anonymous namespace)::RegisterCoalescer::run(llvm::MachineFunction&) RegisterCoalescer.cpp:0:0
#12 0x000055cf74aca7a6 (anonymous namespace)::RegisterCoalescerLegacy::runOnMachineFunction(llvm::MachineFunction&) RegisterCoalescer.cpp:0:0
#13 0x000055cf74879de7 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (build-all/bin/llc+0x66c0de7)
#14 0x000055cf74dd6209 llvm::FPPassManager::runOnFunction(llvm::Function&) (build-all/bin/llc+0x6c1d209)
#15 0x000055cf74dde7e2 llvm::FPPassManager::runOnModule(llvm::Module&) (build-all/bin/llc+0x6c257e2)
#16 0x000055cf74dd6cc8 llvm::legacy::PassManagerImpl::run(llvm::Module&) (build-all/bin/llc+0x6c1dcc8)
#17 0x000055cf72819c70 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#18 0x000055cf72817380 main (build-all/bin/llc+0x465e380)
#19 0x00007f4339ec57e5 __libc_start_main (/lib64/libc.so.6+0x3a7e5)
#20 0x000055cf728167ee _start (build-all/bin/llc+0x465d7ee)
Abort (core dumped)
```
I originally saw the same crash without any special flags for my out-of-tree target and then saw I could reproduce on aarch64 (with added flags) as well.
PHI elimination tturns
```
dead %5:gpr64 = COPY $xzr
```
into
```
dead $noreg = COPY $xzr
```
and I think that is what then trips the coalescer over.
[bbi-108462.ll.gz](https://github.com/user-attachments/files/20975580/bbi-108462.ll.gz)
https://github.com/llvm/llvm-project/pull/131837
More information about the llvm-commits
mailing list