From: mfortune <matthew.fort...@imgtec.com> 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. Cherry-picked 7c1bf276c0ebb45c87fe7bc30f057866d6153ec4 from https://github.com/MIPS/gcc Signed-off-by: Matthew Fortune <matthew.fort...@imgtec.com> Signed-off-by: Faraz Shahbazker <fshahbaz...@wavecomp.com> Signed-off-by: Aleksandar Rakic <aleksandar.ra...@htecgroup.com> --- 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 cf3a4e04880..535172d3406 100644 --- a/gcc/config/mips/mips.h +++ b/gcc/config/mips/mips.h @@ -2365,8 +2365,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 c04a3d9dbfa..ca4d377291e 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 -- 2.34.1