]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add -mgrow-frame-downwards master trunk
authorMatthew Fortune <matthew.fortune@imgtec.com>
Sun, 10 Aug 2025 17:20:30 +0000 (11:20 -0600)
committerJeff Law <jlaw@ventanamicro.com>
Sun, 10 Aug 2025 17:20:30 +0000 (11:20 -0600)
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.

gcc/config/mips/mips.h
gcc/config/mips/mips.opt

index e224ade2a1aae52e0e2e239fe6cb5ca7a5f6f96b..494f14cc18fa65af2bd162768c6d125920fda2b9 100644 (file)
@@ -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.  */
 
index e24565469d99b9e385e578e22c81ceded1b3861e..f07db5ad7f4ad8fe2fb76737ff9a2d5a13030019 100644 (file)
@@ -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