The following patch solves

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123223

The patch was successfully bootstrapped on x86-64 with --enable-checking=yes,rtl,extra

commit 0ab14cf1b4c0c129e6bc7b208686b9caa942a597
Author: Vladimir N. Makarov <[email protected]>
Date:   Fri Dec 19 13:22:49 2025 -0500

    [PR123223, LRA]: Fix ICE of GCC built with checking rtl
    
    The latest PR55212 patch improving dealing with scratch pseudos does not
    check reload rtx on reg when recognizing scratch pseudos.  This
    results in failure of GCC built with checking rtl.
    
    gcc/ChangeLog:
    
            PR rtl-optimization/123223
            * lra-constraints.cc (match_reload, curr_insn_transform): Check
            rtx on REG when testing scratch pseudos.

diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc
index 910f3fba8f4..18b2c50e1e4 100644
--- a/gcc/lra-constraints.cc
+++ b/gcc/lra-constraints.cc
@@ -1243,11 +1243,10 @@ match_reload (signed char out, signed char *ins, signed char *outs,
     return;
   /* See a comment for the input operand above.  */
   narrow_reload_pseudo_class (out_rtx, goal_class);
-  if (find_reg_note (curr_insn, REG_UNUSED, out_rtx) == NULL_RTX
-      && !ira_former_scratch_p (REGNO (SUBREG_P (out_rtx)
-				       ? SUBREG_REG (out_rtx) : out_rtx)))
+  reg = SUBREG_P (out_rtx) ? SUBREG_REG (out_rtx) : out_rtx;
+  if (find_reg_note (curr_insn, REG_UNUSED, reg) == NULL_RTX
+      && (!REG_P (reg) || !ira_former_scratch_p (REGNO (reg))))
     {
-      reg = SUBREG_P (out_rtx) ? SUBREG_REG (out_rtx) : out_rtx;
       start_sequence ();
       /* If we had strict_low_part, use it also in reload to keep other
 	 parts unchanged but do it only for regs as strict_low_part
@@ -4861,7 +4860,7 @@ curr_insn_transform (bool check_only_p)
 	      && find_reg_note (curr_insn, REG_UNUSED, old) == NULL_RTX
 	      /* OLD can be an equivalent constant here.  */
 	      && !CONSTANT_P (old)
-	      && !ira_former_scratch_p (REGNO (old)))
+	      && (!REG_P(old) || !ira_former_scratch_p (REGNO (old))))
 	    {
 	      start_sequence ();
 	      lra_emit_move (type == OP_INOUT ? copy_rtx (old) : old, new_reg);

Reply via email to