* RFA: RL78: Minor prologue and epilogue enhancements
@ 2015-01-26 18:43 Nick Clifton
2015-01-27 0:03 ` DJ Delorie
0 siblings, 1 reply; 2+ messages in thread
From: Nick Clifton @ 2015-01-26 18:43 UTC (permalink / raw)
To: dj; +Cc: gcc-patches
Hi DJ,
The patch below contains two minor enhancements for the RL78 prologue
and epilogue code. The first is for when a large amount of local
stack space needs to be allocated. Rather than generating a long
sequence of SUB SP, #<byte> instructions, the patched codes moves SP
into AX, performs a single subtraction there, and then moves AX back
into SP.
The second optimization is for the G10. It allows the BC, DE and HL
registers to be pushed and popped directly, rather than via moving
them into AX first.
Tested with no regressions on an rl78-elf toolchain.
OK to apply ?
Cheers
Nick
2015-01-26 Nick Clifton <nickc@redhat.com>
* config/rl78/rl78.c (rl78_expand_prologue): In G10 mode push the
BC, DE and HL registers directly, not via AX.
When decrementing the stack pointer by a large amount, transfer SP
into AX and perform the subtraction there.
(rl78_expand_epilogue): Perform the inverse of the above
enhancements.
Index: gcc/config/rl78/rl78.c
===================================================================
--- gcc/config/rl78/rl78.c (revision 220126)
+++ gcc/config/rl78/rl78.c (working copy)
@@ -1230,6 +1230,7 @@
{
int i, fs;
rtx sp = gen_rtx_REG (HImode, STACK_POINTER_REGNUM);
+ rtx ax = gen_rtx_REG (HImode, AX_REG);
int rb = 0;
if (rl78_is_naked_func ())
@@ -1253,15 +1254,19 @@
for (i = 0; i < 16; i++)
if (cfun->machine->need_to_push [i])
{
+ int reg = i * 2;
+
if (TARGET_G10)
{
- if (i != 0)
- emit_move_insn (gen_rtx_REG (HImode, AX_REG), gen_rtx_REG (HImode, i * 2));
- F (emit_insn (gen_push (gen_rtx_REG (HImode, AX_REG))));
+ if (reg >= 8)
+ {
+ emit_move_insn (ax, gen_rtx_REG (HImode, reg));
+ reg = AX_REG;
+ }
}
else
{
- int need_bank = i / 4;
+ int need_bank = i/4;
if (need_bank != rb)
{
@@ -1268,9 +1273,9 @@
emit_insn (gen_sel_rb (GEN_INT (need_bank)));
rb = need_bank;
}
- F (emit_insn (gen_push (gen_rtx_REG (HImode, i * 2))));
+ }
- }
+ F (emit_insn (gen_push (gen_rtx_REG (HImode, reg))));
}
if (rb != 0)
@@ -1280,23 +1285,41 @@
if (is_interrupt_func (cfun->decl) && cfun->machine->uses_es)
{
emit_insn (gen_movqi_from_es (gen_rtx_REG (QImode, A_REG)));
- F (emit_insn (gen_push (gen_rtx_REG (HImode, AX_REG))));
+ F (emit_insn (gen_push (ax)));
}
if (frame_pointer_needed)
{
- F (emit_move_insn (gen_rtx_REG (HImode, AX_REG),
- gen_rtx_REG (HImode, STACK_POINTER_REGNUM)));
- F (emit_move_insn (gen_rtx_REG (HImode, FRAME_POINTER_REGNUM),
- gen_rtx_REG (HImode, AX_REG)));
+ F (emit_move_insn (ax, sp));
+ F (emit_move_insn (gen_rtx_REG (HImode, FRAME_POINTER_REGNUM), ax));
}
fs = cfun->machine->framesize_locals + cfun->machine->framesize_outgoing;
- while (fs > 0)
+ if (fs > 0)
{
- int fs_byte = (fs > 254) ? 254 : fs;
- F (emit_insn (gen_subhi3 (sp, sp, GEN_INT (fs_byte))));
- fs -= fs_byte;
+ /* If we need to subtract more than 254*3 then it is faster and
+ smaller to move SP into AX and perform the subtraction there. */
+ if (fs > 254 * 3)
+ {
+ rtx insn;
+
+ emit_move_insn (ax, sp);
+ emit_insn (gen_subhi3 (ax, ax, GEN_INT (fs)));
+ insn = emit_move_insn (sp, ax);
+ add_reg_note (insn, REG_FRAME_RELATED_EXPR,
+ gen_rtx_SET (SImode, sp,
+ gen_rtx_PLUS (HImode, sp, GEN_INT (-fs))));
+ }
+ else
+ {
+ while (fs > 0)
+ {
+ int fs_byte = (fs > 254) ? 254 : fs;
+
+ F (emit_insn (gen_subhi3 (sp, sp, GEN_INT (fs_byte))));
+ fs -= fs_byte;
+ }
+ }
}
}
@@ -1306,6 +1329,7 @@
{
int i, fs;
rtx sp = gen_rtx_REG (HImode, STACK_POINTER_REGNUM);
+ rtx ax = gen_rtx_REG (HImode, AX_REG);
int rb = 0;
if (rl78_is_naked_func ())
@@ -1313,20 +1337,27 @@
if (frame_pointer_needed)
{
- emit_move_insn (gen_rtx_REG (HImode, AX_REG),
- gen_rtx_REG (HImode, FRAME_POINTER_REGNUM));
- emit_move_insn (gen_rtx_REG (HImode, STACK_POINTER_REGNUM),
- gen_rtx_REG (HImode, AX_REG));
+ emit_move_insn (ax, gen_rtx_REG (HImode, FRAME_POINTER_REGNUM));
+ emit_move_insn (sp, ax);
}
else
{
fs = cfun->machine->framesize_locals + cfun->machine->framesize_outgoing;
- while (fs > 0)
+ if (fs > 254 * 3)
{
- int fs_byte = (fs > 254) ? 254 : fs;
+ emit_move_insn (ax, sp);
+ emit_insn (gen_addhi3 (ax, ax, GEN_INT (fs)));
+ emit_move_insn (sp, ax);
+ }
+ else
+ {
+ while (fs > 0)
+ {
+ int fs_byte = (fs > 254) ? 254 : fs;
- emit_insn (gen_addhi3 (sp, sp, GEN_INT (fs_byte)));
- fs -= fs_byte;
+ emit_insn (gen_addhi3 (sp, sp, GEN_INT (fs_byte)));
+ fs -= fs_byte;
+ }
}
}
@@ -1343,11 +1374,11 @@
if (TARGET_G10)
{
- rtx ax = gen_rtx_REG (HImode, AX_REG);
-
- emit_insn (gen_pop (ax));
- if (i != 0)
+ if (i < 8)
+ emit_insn (gen_pop (dest));
+ else
{
+ emit_insn (gen_pop (ax));
emit_move_insn (dest, ax);
/* Generate a USE of the pop'd register so that DCE will not eliminate the move. */
emit_insn (gen_use (dest));
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: RFA: RL78: Minor prologue and epilogue enhancements
2015-01-26 18:43 RFA: RL78: Minor prologue and epilogue enhancements Nick Clifton
@ 2015-01-27 0:03 ` DJ Delorie
0 siblings, 0 replies; 2+ messages in thread
From: DJ Delorie @ 2015-01-27 0:03 UTC (permalink / raw)
To: Nick Clifton; +Cc: gcc-patches
> OK to apply ?
Ok.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-01-26 23:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-26 18:43 RFA: RL78: Minor prologue and epilogue enhancements Nick Clifton
2015-01-27 0:03 ` DJ Delorie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).