<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/89576>89576</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LLVM ERROR: Error while trying to spill X8 from class GPR64: Cannot scavenge register without an emergency spill slot!
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DigOrDog
</td>
</tr>
</table>
<pre>
# Description
The following code crashes aarch64 backend with "Error while trying to spill X8 from class GPR64: Cannot scavenge register without an emergency spill slot!!".
It's interesting that the command with -mtriple=aarch64 -O=2 results in an error, but the command with **-mtriple=aarch64 -O=0 does not produce an error**.
# Minimal Reproduction
https://godbolt.org/z/KcWovEv7q
## code
```
define double @f(i8 %0, i32 %1, i1 %L1, ptr %G.4, ptr %G.2, ptr %G.6, ptr %A4, ptr %A, ptr %G.8, ptr %G.9, ptr %G.11, ptr %G.13, ptr %G2, ptr %G3, ptr %G7, ptr %G5, ptr %G) {
BB:
%A42 = alloca i1, i32 0, align 1
br label %BB1
BB1: ; preds = %BB1, %BB
store i8 %0, ptr %A, align 1
store i1 true, ptr %A4, align 1
store i32 65536, ptr %G.8, align 4
store i1 false, ptr %G.9, align 1
%G6 = getelementptr double, ptr %A42, i8 42
store ptr %G.13, ptr %G6, align 8
store i32 %1, ptr %G.6, align 4
store float 0.000000e+00, ptr %G.11, align 4
br i1 %L1, label %BB1, label %BB6
BB6: ; preds = %BB1
store i1 false, ptr %G.4, align 1
store i1 false, ptr %G2, align 1
store ptr %G3, ptr %G7, align 8
store i1 false, ptr %G.2, align 1
store ptr %G5, ptr %G, align 8
ret double 0.000000e+00
}
```
## Stack Trace
```
LLVM ERROR: Error while trying to spill X8 from class GPR64: 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: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -mtriple=aarch64 -O=2 <source>
1. Running pass 'Function Pass Manager' on module '<source>'.
2. Running pass 'Prologue/Epilogue Insertion & Frame Finalization' on function '@f'
#0 0x000000000394da58 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x394da58)
#1 0x000000000394b1ac SignalHandler(int) Signals.cpp:0:0
#2 0x00007f0184842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x00007f01848969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#4 0x00007f0184842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#5 0x00007f01848287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#6 0x0000000000720037 (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x720037)
#7 0x0000000002b7af8e llvm::RegScavenger::spill(llvm::Register, llvm::TargetRegisterClass const&, int, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2b7af8e)
#8 0x0000000002b7b862 llvm::RegScavenger::scavengeRegisterBackwards(llvm::TargetRegisterClass const&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, bool, int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2b7b862)
#9 0x0000000002b7c910 scavengeFrameVirtualRegsInBlock(llvm::MachineRegisterInfo&, llvm::RegScavenger&, llvm::MachineBasicBlock&) RegisterScavenging.cpp:0:0
#10 0x0000000002b7cda3 llvm::scavengeFrameVirtualRegs(llvm::MachineFunction&, llvm::RegScavenger&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2b7cda3)
#11 0x0000000002ae3047 (anonymous namespace)::PEI::runOnMachineFunction(llvm::MachineFunction&) PrologEpilogInserter.cpp:0:0
#12 0x0000000002961c51 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#13 0x0000000002f20a13 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2f20a13)
#14 0x0000000002f20c51 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2f20c51)
#15 0x0000000002f214b5 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2f214b5)
#16 0x0000000000828c2c compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#17 0x0000000000727676 main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x727676)
#18 0x00007f0184829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#19 0x00007f0184829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#20 0x000000000081f74e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x81f74e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWF1z4yoS_TX4hbILIVkfD36w43g2tTM1qWRqdt9SCCGZDQItoElyf_0WSE6E7Uw2u657Xbl3hASnT59udYOIMbyRjK3AcgOW2xnp7V7p1ZY33_VWNbNSVS8rgGO4ZYZq3lmuJEBbgNY_9gzWSgj1xGUDqaoYpJqYPTOQEE33aQJLQh-ZrOATt3sIML7WWmn4tOeCQatf3DqroOm4EPCfOay1aiEVxBj45fYuTUC8hldESmWhoeQXkw2DmjXcWKY9puotJBKylumGSfoyQhmhLMCR_8OLge3w_xsLcGYgl5ZpZqwnsCcW2j2DVLUtOZCdt1bzTjAQbw_OzL-DeIuhZqYX1mF4084jgK9g2Z9BAXgN8Po9LAQrxQx07nVaVT1lE0S3MKDuYvCNS94SAe_YsOAtGHtrOwPiNcA7gHeNqkol7ELpBuDdHwDv_k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