https://gcc.gnu.org/g:84e61c03c97908ea03409beeaa27f2f1736f1102

commit r14-12903-g84e61c03c97908ea03409beeaa27f2f1736f1102
Author: Alexey Lapshin <[email protected]>
Date:   Mon Sep 28 23:59:53 2026 +0700

    xtensa: Don't index reg_renumber before LRA in xt_true_regnum
    
    xt_true_regnum is used by move expanders and insn conditions, which
    IRA invokes through emit_move_insn and recog_memoized when emitting
    moves for regional allocation.  At that point reg_renumber has not
    been resized to cover the new pseudos, so indexing it reads out of
    bounds.  Before LRA starts reg_renumber holds no final assignments,
    so only consult it once LRA is in progress or reload has completed.
    
    gcc/ChangeLog:
            PR target/107549
    
            * config/xtensa/xtensa.cc (xt_true_regnum): Don't index
            reg_renumber before LRA starts.
    
    (cherry picked from commit cd15f0e559442c9b387d3cb7c6ce07d7109b825e)

Diff:
---
 gcc/config/xtensa/xtensa.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index 9beac9324679..c9860728f7e6 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -488,9 +488,12 @@ xt_true_regnum (rtx x)
 {
   if (REG_P (x))
     {
+      /* Before LRA, reg_renumber need not cover pseudos created since it
+        was last resized (e.g. by ira_emit during regional allocation).  */
       if (! HARD_REGISTER_P (x)
          && reg_renumber
-         && (lra_in_progress || reg_renumber[REGNO (x)] >= 0))
+         && (lra_in_progress
+             || (reload_completed && reg_renumber[REGNO (x)] >= 0)))
        return reg_renumber[REGNO (x)];
       return REGNO (x);
     }

Reply via email to