Why spill_failure() aborts the compiler when hard-registers cannot find to spill pseudo-registers?

花井志生 ruimo.uno@gmail.com
Mon Apr 24 08:08:40 GMT 2023


I am curious why spill_failure() in gcc/reload1.cc aborts the compiler.

static void
spill_failure (rtx_insn *insn, enum reg_class rclass)
{
  if (asm_noperands (PATTERN (insn)) >= 0)
    error_for_asm (insn, "cannot find a register in class %qs while "
   "reloading %<asm%>",
   reg_class_names[rclass]);
  else
    {
      error ("unable to find a register to spill in class %qs",
     reg_class_names[rclass]);

      if (dump_file)
{
  fprintf (dump_file, "\nReloads for insn # %d\n", INSN_UID (insn));
  debug_reload_to_stream (dump_file);
}
      fatal_insn ("this is the insn:", insn);
    }
}

The above code aborts the compiler with the following error, for
example (I am using m32c target because it has relatively few hardware
registers to spill).

m32c-elf-cc -B/root/r8c/newlib-4.1.0/m32c_build/m32c-elf/newlib/
-isystem /root/r8c/newlib-4.1.0/m32c_build/m32c-elf/new
lib/targ-include -isystem /root/r8c/newlib-4.1.0/newlib/libc/include
-B/root/r8c/newlib-4.1.0/m32c_build/m32c-elf/libglo
ss/m32c -L/root/r8c/newlib-4.1.0/m32c_build/m32c-elf/libgloss/libnosys
-L/root/r8c/newlib-4.1.0/libgloss/m32c    -DPACKA
GE_NAME=\"newlib\" -DPACKAGE_TARNAME=\"newlib\"
-DPACKAGE_VERSION=\"4.1.0\" -DPACKAGE_STRING=\"newlib\ 4.1.0\"
-DPACKAGE
_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -I.
-I../../../../../newlib/libc/stdlib -Os -fno-builtin
-DPREFER_SIZE_OVER_SPEED -DS
MALL_MEMORY -DMISSING_SYSCALL_NAMES -DABORT_PROVIDED -DHAVE_INIT_FINI
    -g -O2 -c -o lib_a-ldtoa.o `test -f 'ldtoa.c'
 || echo '../../../../../newlib/libc/stdlib/'`ldtoa.c
../../../../../newlib/libc/stdlib/ldtoa.c: In function '_ldtoa_r':
../../../../../newlib/libc/stdlib/ldtoa.c:2936:1: error: unable to
find a register to spill in class 'A_REGS'
 2936 | }

Regarding this documentation (Register allocation):
https://gcc.gnu.org/onlinedocs/gccint/RTL-passes.html#RTL-passes

> Reloading. This pass renumbers pseudo registers with the hardware
> registers numbers they were allocated. Pseudo registers that did not
> get hard registers are replaced with stack slots.

So if the optimizer cannot find hard-registers to spill
pseudo-registers, it is not a serious situation and happily allocate
memory slots in the stack area instead. I tried the following change
against GCC 12 and confirmed the above error has gone.

   else
     {
-      error ("unable to find a register to spill in class %qs",
-      reg_class_names[rclass]);
-
       if (dump_file)
  {
    fprintf (dump_file, "\\nReloads for insn # %d\\n", INSN_UID (insn));
    debug_reload_to_stream (dump_file);
  }
-      fatal_insn ("this is the insn:", insn);
     }

-- 
花井 志生
Ruimo Uno
(Shisei Hanai)


More information about the Gcc mailing list