[X86][RegAlloc] "ran out of registers" on a statepoint with many deopt operands
llc fails to allocate registers for a function whose only call is a gc.statepoint carrying 15 live deopt values. Deopt operands are allowed to
live in stack slots, so allocation should succeed by spilling some of them. Instead greedy reports "ran out of registers", and the basic allocator hits an assertion in InlineSpiller::reMaterializeFor. Both go away with -restrict-statepoint-remat=true (default false), which points at rematerialization of statepoint operands.
Reproducer
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.11.0"
define void @test(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h, i32 %i, i32 %j, i32 %k, i32 %l, i32 %m, i32 %n, i32 %o, i32 %p, i32 %q, i32 %r, i32 %s, i32 %u, i32 %v) gc "statepoint-example" {
entry:
%g64 = zext i32 %g to i64
%h64 = zext i32 %h to i64
%i64 = zext i32 %i to i64
%j64 = zext i32 %j to i64
%k64 = zext i32 %k to i64
%l64 = zext i32 %l to i64
%m64 = zext i32 %m to i64
%n64 = zext i32 %n to i64
%o64 = zext i32 %o to i64
%p64 = zext i32 %p to i64
%q64 = zext i32 %q to i64
%r64 = zext i32 %r to i64
%s64 = zext i32 %s to i64
%u64 = zext i32 %u to i64
%v64 = zext i32 %v to i64
%statepoint_token1 = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) null, i32 0, i32 2, i32 0, i32 0) [ "deopt"(i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 %g64, i64 %h64, i64 %i64, i64 %j64, i64 %k64, i64 %l64, i64 %m64, i64 %n64, i64 %o64, i64 %p64, i64 %q64, i64 %r64, i64 %s64, i64 0, i64 %u64, i64 %v64, i64 0, i64 0, i64 0, i64 0) ]
ret void
}
declare token @llvm.experimental.gc.statepoint.p0(i64 immarg, i32 immarg, ptr, i32 immarg, i32 immarg, ...)
$ llc reduced.ll -o /dev/null
error: <unknown>:0:0: ran out of registers during register allocation in function 'test'
With the basic allocator:
$ llc -regalloc=basic reduced.ll -o /dev/null
llc: llvm/lib/CodeGen/InlineSpiller.cpp:708: bool {anonymous}::InlineSpiller::reMaterializeFor(llvm::LiveInterval&, llvm::MachineInstr&): Assertion `OrigVNI && "corrupted sub-interval"' failed.
...
2. Running pass 'Basic Register Allocator' on function '@test'
llc options |
result |
|---|---|
| (defaults) | ran out of registers |
-code-model=large |
ran out of registers |
-regalloc=basic |
assertion in InlineSpiller::reMaterializeFor |
-restrict-statepoint-remat=true |
ok |
-regalloc=basic -restrict-statepoint-remat=true |
ok |
Notes
Reduced with llvm-reduce from llvm/test/CodeGen/X86/statepoint-live-in-remat.ll.
That test passes only because its RUN line pins -restrict-statepoint-remat=true: with the default (false) and -code-model=large, the unreduced test fails the same way.
Reproduced on main at 22dabdd89d75, also with -mtriple=x86_64-unknown-linux-gnu.
Proposed patch: https://github.com/llvm/llvm-project/pull/235107