While debugging PR 123285, I found it hard to read the final rtl of early ra 
pass
to understand what psedu-register was assigned to what hard register. This is 
because
the pass does not set ORIGINAL_REGNO like the other RAs do. So this does that
and also copies the other register attributes.

Bootstrappd and tested on aarch64-linux-gnu.
Note this depends on 
https://gcc.gnu.org/pipermail/gcc-patches/2026-January/706660.html.

        PR target/123829

gcc/ChangeLog:

        * config/aarch64/aarch64-early-ra.cc (early_ra::replace_regs): Set
        ORIGINAL_REGNO on the new reg and copy reg attributes from the old one.

Signed-off-by: Andrew Pinski <[email protected]>
---
 gcc/config/aarch64/aarch64-early-ra.cc | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/gcc/config/aarch64/aarch64-early-ra.cc 
b/gcc/config/aarch64/aarch64-early-ra.cc
index 8d9aeb02f39..e2adde4ed94 100644
--- a/gcc/config/aarch64/aarch64-early-ra.cc
+++ b/gcc/config/aarch64/aarch64-early-ra.cc
@@ -3238,6 +3238,18 @@ early_ra::replace_regs (rtx_insn *insn, df_ref refs)
          return true;
        }
       rtx new_rtx = gen_rtx_REG (GET_MODE (DF_REF_REG (ref)), new_regno);
+      rtx old_reg = DF_REF_REG (ref);
+      /* Copy from the old reg if needed including from a SUBREG. */
+      if (SUBREG_P (old_reg))
+       old_reg = SUBREG_REG (old_reg);
+      if (REG_P (old_reg))
+       {
+         ORIGINAL_REGNO (new_rtx) = REGNO (old_reg);
+         REG_USERVAR_P (new_rtx) = REG_USERVAR_P (old_reg);
+         REG_POINTER (new_rtx) = REG_POINTER (old_reg);
+         REG_ATTRS (new_rtx) = REG_ATTRS (old_reg);
+       }
+
       // If inside a debug insn, then generate the subreg manually as it might
       // be an invalid one for outside of a debug insn.
       if (DEBUG_INSN_P (insn)
-- 
2.43.0

Reply via email to