https://gcc.gnu.org/g:78124a426ab72f0bc0bcb9301b7cc98b4db6db3a

commit r17-5981-g78124a426ab72f0bc0bcb9301b7cc98b4db6db3a
Author: Vladimir N. Makarov <[email protected]>
Date:   Thu Nov 5 07:40:39 2026 -0500

    [PR 128400][LRA]: Spill plus for memory only if there is no reg target
    
    The previous fix for PR128251 skipped goal_alt guard and this resulted
    spilling plus when it can be reloaded into a reg.  The patch fixes it and
    decreases code size of SPEC2017 imagick by 0.7%.
    
    gcc/ChangeLog:
    
            PR rtl-optimization/128400
            * lra-constraints.cc (curr_insn_transform): Spill plus for memory
            only if there is no reg target.  Reuse reload pseudo.

Diff:
---
 gcc/lra-constraints.cc | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc
index 3d5731a77064..e07905579f08 100644
--- a/gcc/lra-constraints.cc
+++ b/gcc/lra-constraints.cc
@@ -5318,8 +5318,8 @@ curr_insn_transform (bool check_only_p)
          *loc = new_reg;
          lra_update_dup (curr_id, i);
        }
-      else if (goal_alt_matched[i][0] == -1 && goal_alt_offmemok[i]
-              && reg_plus_const_p (op))
+      else if (goal_alt_matched[i][0] == -1 && goal_alt[i] == NO_REGS
+              && goal_alt_offmemok[i] && reg_plus_const_p (op))
        {
          /* Materialize the sum probably produced by elimination of a register
             and then spill it into memory to satisfy the memory constraint.  */
@@ -5329,19 +5329,17 @@ curr_insn_transform (bool check_only_p)
                              curr_insn);
          rtx mem_pseudo;
 
+         push_to_sequence (before);
          if (get_reload_reg (curr_static_id->operand[i].type, mode, op,
                              rclass, NULL, false, false, "elimination sum",
                              &new_reg))
-           {
-             push_to_sequence (before);
-             lra_emit_move (new_reg, op);
-             mem_pseudo = lra_create_new_reg (mode, NULL_RTX, NO_REGS,
-                                              NULL, "elimination sum mem");
-             emit_insn (emit_spill_move (true, mem_pseudo, new_reg));
-             before = end_sequence ();
-             *curr_id->operand_loc[i] = mem_pseudo;
-             lra_update_dup (curr_id, i);
-           }
+           lra_emit_move (new_reg, op);
+         mem_pseudo = lra_create_new_reg (mode, NULL_RTX, NO_REGS,
+                                          NULL, "elimination sum mem");
+         emit_insn (emit_spill_move (true, mem_pseudo, new_reg));
+         before = end_sequence ();
+         *curr_id->operand_loc[i] = mem_pseudo;
+         lra_update_dup (curr_id, i);
        }
       else if (goal_alt_matched[i][0] == -1)
        {

Reply via email to