https://gcc.gnu.org/g:767f65cf82b516656dda95802a83bf905550f0b3
commit r16-3118-g767f65cf82b516656dda95802a83bf905550f0b3 Author: Matthew Fortune <matthew.fort...@imgtec.com> Date: Sun Aug 10 11:20:30 2025 -0600 Add -mgrow-frame-downwards Grow the local frame down instead of up for mips16 code size. By growing the frame downwards we get spill slots created at the lowest address rather than highest address in a local frame. The benefit being that when the frame is large the spill slots can still be accessed using a 16bit instruction whereas it is less important for large local variables to be accessed using short instructions as they are (probably) accessed less frequently. This is default on for MIPS16. gcc/ * config/mips/mips.h (FRAME_GROWS_DOWNWARD) Allow the frame to grow downwards for mips16 when -mgrow-frame-downwards is set. * config/mips/mips.opt: Add -mgrow-frame-downwards option. Diff: --- gcc/config/mips/mips.h | 10 ++++++++-- gcc/config/mips/mips.opt | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h index e224ade2a1aa..494f14cc18fa 100644 --- a/gcc/config/mips/mips.h +++ b/gcc/config/mips/mips.h @@ -2363,8 +2363,14 @@ enum reg_class #define STACK_GROWS_DOWNWARD 1 -#define FRAME_GROWS_DOWNWARD (flag_stack_protect != 0 \ - || (flag_sanitize & SANITIZE_ADDRESS) != 0) +/* Growing the frame downwards allows us to put spills closest to + the stack pointer which is good as they are likely to be accessed + frequently. We can also arrange for normal stack usage to place + scalars last so that they too are close to the stack pointer. */ +#define FRAME_GROWS_DOWNWARD ((TARGET_MIPS16 \ + && TARGET_FRAME_GROWS_DOWNWARDS) \ + || (flag_stack_protect != 0 \ + || (flag_sanitize & SANITIZE_ADDRESS) != 0)) /* Size of the area allocated in the frame to save the GP. */ diff --git a/gcc/config/mips/mips.opt b/gcc/config/mips/mips.opt index e24565469d99..f07db5ad7f4a 100644 --- a/gcc/config/mips/mips.opt +++ b/gcc/config/mips/mips.opt @@ -473,6 +473,10 @@ mframe-header-opt Target Var(flag_frame_header_optimization) Optimization Optimize frame header. +mgrow-frame-downwards +Target Var(TARGET_FRAME_GROWS_DOWNWARDS) Init(1) Undocumented +Change the behaviour to grow the frame downwards. + noasmopt Driver