[PATCH] Significantly improve Thumb code quality when the frame pointer is not eliminated

Richard Earnshaw Richard.Earnshaw@buzzard.freeserve.co.uk
Sat Aug 20 12:04:00 GMT 2005


Conventionally it seems that a frame pointer will point directly at the 
saved registers for a function frame and that any local variables on the 
stack will appear below this (assuming a descending stack model).  That 
means the local variables have a negative offset from the frame pointer.

Unfortunately, Thumb has no memory addressing modes that directly support 
negative offsets from a base pointer, and to make matters worse, 
generating even small negative constants in registers takes at least two 
instructions (load a positive constant and negate it).  So the result is 
that code quality when we need a frame pointer is truly horrendous.

This patch changes the model that we use when we need a frame pointer in 
Thumb code so that we point it at the base of the local variables: these 
then have possitive offsets from the frame pointer and can, in general, be 
accessed using base+offset addressing.  The result is that we can reduce 
code size by as much as one third (yes 33%!) in some non-trivial 
subroutines.

Tested on arm-elf, arm-eabi and bootstrapped (compiling the compiler in 
thumb code) on arm-netbsdelf.

R.

2005-08-20  Richard Earnshaw  <richard.earnshaw@arm.com>

	* arm.h (arm_stack_offsets): Add locals_base field.
	* arm.c (arm_get_frame_offsets): Compute it.
	(thumb_compute_initial_elimination offset): Make the Thumb frame
	pointer point to the base of the local variables.
	(thumb_expand_prologue): Update accordingly.
	(thumb_expand_epilogue): Likewise.

	* arm.md (thumb_movhi_clobber): Make this insn a define_expand.  Change
	mode of clobbered scratch to DImode.  Handle a case that's known to
	need this.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: thumb_frame.patch
Type: text/x-patch
Size: 8665 bytes
Desc: thumb_frame.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20050820/5d211ed5/attachment.bin>


More information about the Gcc-patches mailing list