https://gcc.gnu.org/g:7d652a985309ac5cd1492a505805bbd2c3781598

commit r17-4993-g7d652a985309ac5cd1492a505805bbd2c3781598
Author: Georg-Johann Lay <[email protected]>
Date:   Mon Oct 5 17:19:24 2026 +0200

    AVR: Tighten prologue_saves condition
    
    Small frame sizes are realized by a sequence of RCALL . + PUSH tmp_reg
    like:
       push r28
       push r29
       ;; SP -= 4
       rcall .
       push __tmp_reg__
       in r28, __SP_L__
       in r29, __SP_H__
    
    This patch tightens the prologue_saves condition such that it is
    only used when its invokation is shorter than the sequence above.
    
    gcc/
            * config/avr/avr.cc (avr_prologue_setup_frame): Tighten
            condition for when prologue_saves is used.

Diff:
---
 gcc/config/avr/avr.cc | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index 58cd25b60a75..f6aef849bd34 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -1544,8 +1544,14 @@ avr_prologue_setup_frame (HOST_WIDE_INT size, 
HARD_REG_SET set)
                   && !isr_p
                   && !AVR_TINY);
 
+  // Small frame sizes can be realized by RCALL . + PUSH tmp_reg.  Get the
+  // respective insn count, and only use prologue_saves when it is profitable.
+  const int pc_size = AVR_2_BYTE_PC ? 2 : 3;
+  const int n_insns = 2 + live_seq + size / pc_size + size % pc_size;
+  const int n_mini_insns = 5 + AVR_HAVE_JMP_CALL;
+
   if (minimize
-      && (frame_pointer_needed
+      && ((frame_pointer_needed && n_mini_insns < n_insns)
          || avr_outgoing_args_size () > 8
          || (AVR_2_BYTE_PC && live_seq > 6)
          || live_seq > 7))

Reply via email to