This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, moxie] Allocate stack space with dec instruction
- From: Anthony Green <green at moxielogic dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 09 Sep 2009 18:10:42 -0400
- Subject: [Patch, moxie] Allocate stack space with dec instruction
I'm committing the following patch to the moxie port to improve stack
allocation. It frees up a register and generates shorter instruction
sequences most of the time.
Instead of decreasing the stack pointer by loading an immediate into
another register and subtracting that from $sp, we simply use the short
"dec $sp, N" instruction to subtract N from $sp. N must be less than
256. If N is >= 256, we generate a sequence of dec instructions. The
next obvious change would be to fall back to the old sequence when N >
some value, but the vast majority of stack allocations I'm seeing so far
fit in one or two decs, so this is down low on the TODO list.
AG
2009-09-09 Anthony Green <green@moxielogic.com>
* config/moxie/moxie.c (moxie_expand_prologue): Use dec
instruction to allocate stack space.
Index: gcc/config/moxie/moxie.c
===================================================================
--- gcc/config/moxie/moxie.c (revision 151510)
+++ gcc/config/moxie/moxie.c (working copy)
@@ -273,25 +273,22 @@
if (cfun->machine->size_for_adjusting_sp > 0)
{
- if (cfun->machine->size_for_adjusting_sp <= 255)
+ int i = cfun->machine->size_for_adjusting_sp;
+ while (i > 255)
{
insn = emit_insn (gen_subsi3 (stack_pointer_rtx,
stack_pointer_rtx,
- GEN_INT (cfun->machine->size_for_adjusting_sp)));
+ GEN_INT (255)));
RTX_FRAME_RELATED_P (insn) = 1;
+ i -= 255;
}
- else
+ if (i > 0)
{
- insn =
- emit_insn (gen_movsi
- (gen_rtx_REG (Pmode, MOXIE_R5),
- GEN_INT (-cfun->machine->size_for_adjusting_sp)));
- RTX_FRAME_RELATED_P (insn) = 1;
- insn = emit_insn (gen_addsi3 (stack_pointer_rtx,
+ insn = emit_insn (gen_subsi3 (stack_pointer_rtx,
stack_pointer_rtx,
- gen_rtx_REG (Pmode, MOXIE_R5)));
+ GEN_INT (i)));
RTX_FRAME_RELATED_P (insn) = 1;
- }
+ }
}
}