GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
avr Performance Win

Optimize AVR prologue_saves for small frames

AVR prologue code generation is tightened to only use prologue_saves when it's shorter than alternatives.

The AVR code generation for function prologues has been refined to be more efficient for small stack frames. The prologue_saves mechanism is now only invoked when its generated code sequence is shorter than an alternative using RCALL and PUSH instructions. This optimization avoids generating unnecessarily verbose prologue code for simple function entry sequences.

In Details

This commit modifies avr_prologue_setup_frame in avr.cc to tighten the condition for using prologue_saves. The prologue_saves mechanism is a specific way to save registers onto the stack during function entry. The change ensures it's only used when it results in a shorter instruction sequence compared to a sequence of PUSH instructions followed by a RCALL to a trampoline that handles the rest of the setup. This optimization targets small frame sizes where the overhead of prologue_saves might outweigh its benefits.

For Context
AVR
A family of microcontrollers developed by Atmel (now Microchip Technology). GCC supports compiling code for these processors.
prologue_saves
A specific code generation strategy in the AVR backend for saving registers onto the stack at the beginning of a function call.
RCALL
A relative call instruction on AVR microcontrollers, similar to a CALL instruction but with a shorter, relative displacement.
PUSH
An instruction that pushes a value onto the stack.
stack frame
A region of memory on the call stack used to store information for a single function call, including local variables, function parameters, and return addresses.
Filed Under: avrcode-generationoptimizationprologue