]> git.ipfire.org Git - thirdparty/gcc.git/commit
[PR117868][LRA]: Restrict the reuse of spill slots
authorDenis Chertykov <chertykov@gmail.com>
Mon, 20 Jan 2025 20:27:04 +0000 (00:27 +0400)
committerDenis Chertykov <chertykov@gmail.com>
Mon, 20 Jan 2025 20:27:04 +0000 (00:27 +0400)
commit5cd4605141b8b45cab95e4de8005c69273071107
tree11242609edbbf95c8cc1c8ddfd94a7e90015a792
parent96f4ba4d19a765902af7b79aa77d52c62fa2f82c
[PR117868][LRA]: Restrict the reuse of spill slots

This is an LRA bug derived from reuse spilling slots after frame pointer spilling.
The slot was created for QImode (1 byte) and it was reused after spilling of the
frame pointer for TImode register (16 bytes long) and it overlaps other slots.

Wrong things happened while `lra_spill ()'
---------------------------- part of lra-spills.cc ----------------------------
  n = assign_spill_hard_regs (pseudo_regnos, n);
  slots_num = 0;
  assign_stack_slot_num_and_sort_pseudos (pseudo_regnos, n);  <--- first call ---
  for (i = 0; i < n; i++)
    if (pseudo_slots[pseudo_regnos[i]].mem == NULL_RTX)
      assign_mem_slot (pseudo_regnos[i]);
  if ((n2 = lra_update_fp2sp_elimination (pseudo_regnos)) > 0)
    {
      /* Assign stack slots to spilled pseudos assigned to fp.  */
      assign_stack_slot_num_and_sort_pseudos (pseudo_regnos, n2);  <--- second call ---
      for (i = 0; i < n2; i++)
if (pseudo_slots[pseudo_regnos[i]].mem == NULL_RTX)
  assign_mem_slot (pseudo_regnos[i]);
    }
------------------------------------------------------------------------------

In a first call of `assign_stack_slot_num_and_sort_pseudos(...)' LRA allocates slot #17
for r93 (QImode - 1 byte).
In a second call of `assign_stack_slot_num_and_sort_pseudos(...)' LRA reuse slot #17 for
r114 (TImode - 16 bytes).
It's wrong. We can't reuse 1 byte slot #17 for 16 bytes register.

The code in patch does reuse slots only without allocated memory or only with equal or
smaller registers with equal or smaller alignment.
Also, a small fix for debugging output of slot width.
Print slot size as width, not a 0 as a size of (mem/c:BLK (...)).

PR rtl-optimization/117868
gcc/
* lra-spills.cc (assign_stack_slot_num_and_sort_pseudos): Reuse slots
only without allocated memory or only with equal or smaller registers
with equal or smaller alignment.
(lra_spill): Print slot size as width.
gcc/lra-spills.cc