* RFA: RL78:
@ 2015-04-14 16:53 Nick Clifton
2015-04-14 17:02 ` DJ Delorie
0 siblings, 1 reply; 4+ messages in thread
From: Nick Clifton @ 2015-04-14 16:53 UTC (permalink / raw)
To: dj; +Cc: gcc-patches
Hi DJ,
I would like permission to apply this patch to the RL78 backend. It
tidies up a few minor bugs, specifically:
* The prologue instruction to increment the stack pointer by a large
amount was not being marked as frame related.
* The %p operand operator was not using %code when applied to a
function symbol.
* Reload could in very rare circumstances fail to compute a suitable
register class.
* The expanders in rl78.md contain constraints that are not used.
* The multiply insns in rl78.md mark operand 1 as both input and
output when in fact it is only an input.
Tested with no regressions on an rl78-elf toolchain.
OK to apply ?
Cheers
Nick
2015-04-14 Nick Clifton <nickc@redhat.com>
* config/rl78/rl78.c (rl78_expand_prologue): Mark large stack
decrement instruction as being frame related.
(rl78_print_operand_1): Handle 'p' modifier to add +0 to HL
based addresses.
If zero extending a function address enclose the operation in
%code(...).
(rl78_preferred_reload_class): New function.
(TARGET_PREFERRED_RELOAD_CLASS): Define.
* config/rl78/rl78.md: Remove useless constraints in expanders.
(mulqi3_rl78): Remove + qualifier on input-only operand 1.
(mulhi3_rl78): Likewise.
(mulhi3_g13): Likewise.
(mulsi3_rl78): Likewise.
(es_addr): Move to before the multiply patterns.
Index: config/rl78/rl78.c
===================================================================
--- config/rl78/rl78.c (revision 222096)
+++ config/rl78/rl78.c (working copy)
@@ -1322,7 +1322,7 @@
emit_move_insn (ax, sp);
emit_insn (gen_subhi3 (ax, ax, GEN_INT (fs)));
- insn = emit_move_insn (sp, ax);
+ insn = F (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))));
@@ -1570,6 +1570,7 @@
e - third QI of an SI (i.e. where the ES register gets values from)
E - fourth QI of an SI (i.e. MSB)
+ p - Add +0 to a zero-indexed HL based address.
*/
/* Implements the bulk of rl78_print_operand, below. We do it this
@@ -1644,13 +1645,16 @@
rl78_print_operand_1 (file, XEXP (XEXP (op, 0), 1), 'u');
fprintf (file, "[");
rl78_print_operand_1 (file, XEXP (XEXP (op, 0), 0), 0);
+ if (letter == 'p' && GET_CODE (XEXP (op, 0)) == REG)
+ fprintf (file, "+0");
fprintf (file, "]");
}
else
{
+ op = XEXP (op, 0);
fprintf (file, "[");
- rl78_print_operand_1 (file, XEXP (op, 0), letter);
- if (letter == 'p' && GET_CODE (XEXP (op, 0)) == REG)
+ rl78_print_operand_1 (file, op, letter);
+ if (letter == 'p' && REG_P (op) && REGNO (op) == 6)
fprintf (file, "+0");
fprintf (file, "]");
}
@@ -1772,15 +1776,41 @@
if (GET_CODE (XEXP (op, 0)) == ZERO_EXTEND)
{
- rl78_print_operand_1 (file, XEXP (op, 1), letter);
- fprintf (file, "+");
- rl78_print_operand_1 (file, XEXP (op, 0), letter);
+ if (GET_CODE (XEXP (op, 1)) == SYMBOL_REF
+ && SYMBOL_REF_DECL (XEXP (op, 1))
+ && TREE_CODE (SYMBOL_REF_DECL (XEXP (op, 1))) == FUNCTION_DECL)
+ {
+ fprintf (file, "%%code(");
+ assemble_name (file, rl78_strip_nonasm_name_encoding (XSTR (XEXP (op, 1), 0)));
+ fprintf (file, "+");
+ rl78_print_operand_1 (file, XEXP (op, 0), letter);
+ fprintf (file, ")");
+ }
+ else
+ {
+ rl78_print_operand_1 (file, XEXP (op, 1), letter);
+ fprintf (file, "+");
+ rl78_print_operand_1 (file, XEXP (op, 0), letter);
+ }
}
else
{
- rl78_print_operand_1 (file, XEXP (op, 0), letter);
- fprintf (file, "+");
- rl78_print_operand_1 (file, XEXP (op, 1), letter);
+ if (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
+ && SYMBOL_REF_DECL (XEXP (op, 0))
+ && TREE_CODE (SYMBOL_REF_DECL (XEXP (op, 0))) == FUNCTION_DECL)
+ {
+ fprintf (file, "%%code(");
+ assemble_name (file, rl78_strip_nonasm_name_encoding (XSTR (XEXP (op, 0), 0)));
+ fprintf (file, "+");
+ rl78_print_operand_1 (file, XEXP (op, 1), letter);
+ fprintf (file, ")");
+ }
+ else
+ {
+ rl78_print_operand_1 (file, XEXP (op, 0), letter);
+ fprintf (file, "+");
+ rl78_print_operand_1 (file, XEXP (op, 1), letter);
+ }
}
if (need_paren)
fprintf (file, ")");
@@ -4509,6 +4544,19 @@
return res;
}
\f
+#undef TARGET_PREFERRED_RELOAD_CLASS
+#define TARGET_PREFERRED_RELOAD_CLASS rl78_preferred_reload_class
+
+static reg_class_t
+rl78_preferred_reload_class (rtx x, reg_class_t rclass)
+{
+ if (rclass == NO_REGS)
+ rclass = V_REGS;
+
+ return rclass;
+}
+
+\f
struct gcc_target targetm = TARGET_INITIALIZER;
#include "gt-rl78.h"
Index: config/rl78/rl78.md
===================================================================
--- config/rl78/rl78.md (revision 222096)
+++ config/rl78/rl78.md (working copy)
@@ -107,7 +107,7 @@
)
(define_expand "eh_return"
- [(match_operand:HI 0 "" "")]
+ [(match_operand:HI 0 "")]
""
"rl78_expand_eh_epilogue (operands[0]);
emit_barrier ();
@@ -169,10 +169,10 @@
;; non-immediate as well.
(define_expand "nonlocal_goto"
[(set (pc)
- (unspec_volatile [(match_operand 0 "" "") ;; fp (ignore)
- (match_operand 1 "" "vi") ;; target
- (match_operand 2 "" "vi") ;; sp
- (match_operand 3 "" "vi") ;; ?
+ (unspec_volatile [(match_operand 0 "") ;; fp (ignore)
+ (match_operand 1 "") ;; target
+ (match_operand 2 "") ;; sp
+ (match_operand 3 "") ;; ?
] UNS_NONLOCAL_GOTO))
]
""
@@ -200,6 +200,14 @@
"
)
+(define_expand "es_addr"
+ [(unspec:SI [(reg:QI ES_REG)
+ (match_operand:HI 0 "")
+ ] UNS_ES_ADDR)]
+ ""
+ ""
+)
+
;;======================================================================
;;
;; "macro" insns - cases where inline chunks of code are more
@@ -243,9 +251,9 @@
)
(define_expand "subsi3"
- [(set (match_operand:SI 0 "nonimmediate_operand" "=&vm")
- (minus:SI (match_operand:SI 1 "general_operand" "vim")
- (match_operand 2 "general_operand" "vim")))
+ [(set (match_operand:SI 0 "nonimmediate_operand")
+ (minus:SI (match_operand:SI 1 "general_operand")
+ (match_operand 2 "general_operand")))
]
""
"emit_insn (gen_subsi3_internal_virt (operands[0], operands[1], operands[2]));
@@ -280,9 +288,9 @@
)
(define_expand "mulqi3"
- [(set (match_operand:QI 0 "register_operand" "")
- (mult:QI (match_operand:QI 1 "general_operand" "")
- (match_operand:QI 2 "nonmemory_operand" "")))
+ [(set (match_operand:QI 0 "register_operand")
+ (mult:QI (match_operand:QI 1 "general_operand")
+ (match_operand:QI 2 "nonmemory_operand")))
]
"" ; mulu supported by all targets
""
@@ -289,9 +297,9 @@
)
(define_expand "mulhi3"
- [(set (match_operand:HI 0 "register_operand" "")
- (mult:HI (match_operand:HI 1 "general_operand" "")
- (match_operand:HI 2 "nonmemory_operand" "")))
+ [(set (match_operand:HI 0 "register_operand")
+ (mult:HI (match_operand:HI 1 "general_operand")
+ (match_operand:HI 2 "nonmemory_operand")))
]
"! RL78_MUL_NONE"
""
@@ -298,8 +306,8 @@
)
(define_expand "mulsi3"
- [(set (match_operand:SI 0 "register_operand" "=&v")
- (mult:SI (match_operand:SI 1 "general_operand" "+vim")
+ [(set (match_operand:SI 0 "register_operand" "=&v")
+ (mult:SI (match_operand:SI 1 "general_operand" "vim")
(match_operand:SI 2 "nonmemory_operand" "vi")))
]
"! RL78_MUL_NONE"
@@ -308,7 +316,7 @@
(define_insn "*mulqi3_rl78"
[(set (match_operand:QI 0 "register_operand" "=&v")
- (mult:QI (match_operand:QI 1 "general_operand" "+viU")
+ (mult:QI (match_operand:QI 1 "general_operand" "viU")
(match_operand:QI 2 "general_operand" "vi")))
]
"" ; mulu supported by all targets
@@ -325,7 +333,7 @@
(define_insn "*mulhi3_rl78"
[(set (match_operand:HI 0 "register_operand" "=&v")
- (mult:HI (match_operand:HI 1 "general_operand" "+viU")
+ (mult:HI (match_operand:HI 1 "general_operand" "viU")
(match_operand:HI 2 "general_operand" "vi")))
]
"RL78_MUL_RL78"
@@ -340,7 +348,7 @@
(define_insn "*mulhi3_g13"
[(set (match_operand:HI 0 "register_operand" "=&v")
- (mult:HI (match_operand:HI 1 "general_operand" "+viU")
+ (mult:HI (match_operand:HI 1 "general_operand" "viU")
(match_operand:HI 2 "general_operand" "vi")))
]
"RL78_MUL_G13"
@@ -363,7 +371,7 @@
;; bits of the result).
(define_insn "mulsi3_rl78"
[(set (match_operand:SI 0 "register_operand" "=&v")
- (mult:SI (match_operand:SI 1 "general_operand" "+viU")
+ (mult:SI (match_operand:SI 1 "general_operand" "viU")
(match_operand:SI 2 "general_operand" "vi")))
]
"RL78_MUL_RL78"
@@ -432,12 +440,4 @@
movw %H0, ax
; end of mulsi macro"
[(set_attr "valloc" "macax")]
- )
-
-(define_expand "es_addr"
- [(unspec:SI [(reg:QI ES_REG)
- (match_operand:HI 0 "" "")
- ] UNS_ES_ADDR)]
- ""
- ""
)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: RFA: RL78:
2015-04-14 16:53 RFA: RL78: Nick Clifton
@ 2015-04-14 17:02 ` DJ Delorie
0 siblings, 0 replies; 4+ messages in thread
From: DJ Delorie @ 2015-04-14 17:02 UTC (permalink / raw)
To: Nick Clifton; +Cc: gcc-patches
> OK to apply ?
Ok!
> 2015-04-14 Nick Clifton <nickc@redhat.com>
>
> * config/rl78/rl78.c (rl78_expand_prologue): Mark large stack
> decrement instruction as being frame related.
> (rl78_print_operand_1): Handle 'p' modifier to add +0 to HL
> based addresses.
> If zero extending a function address enclose the operation in
> %code(...).
> (rl78_preferred_reload_class): New function.
> (TARGET_PREFERRED_RELOAD_CLASS): Define.
> * config/rl78/rl78.md: Remove useless constraints in expanders.
> (mulqi3_rl78): Remove + qualifier on input-only operand 1.
> (mulhi3_rl78): Likewise.
> (mulhi3_g13): Likewise.
> (mulsi3_rl78): Likewise.
> (es_addr): Move to before the multiply patterns.
Double check tab-vs-space in the ChangeLog entry, though...
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: RFA: RL78:
2015-06-02 16:27 Nick Clifton
@ 2015-06-03 6:00 ` DJ Delorie
0 siblings, 0 replies; 4+ messages in thread
From: DJ Delorie @ 2015-06-03 6:00 UTC (permalink / raw)
To: Nick Clifton; +Cc: gcc-patches
Ok. Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
* RFA: RL78:
@ 2015-06-02 16:27 Nick Clifton
2015-06-03 6:00 ` DJ Delorie
0 siblings, 1 reply; 4+ messages in thread
From: Nick Clifton @ 2015-06-02 16:27 UTC (permalink / raw)
To: dj; +Cc: gcc-patches
Hi DJ,
This patch contains two small improvements for the RL78 compiler:
1. A peephole to match:
movw ax, !<function_name>
movw bc, ax
call bc
with:
movw ax, !<function_name>
call ax
2. A change to avoid pushing the frame pointer register in an
interrupt handler if the handler never uses or corrupts the
frame pointer.
Tested with no regressions using an rx-elf toolchain.
OK to apply ?
Cheers
Nick
gcc/ChangeLog
2015-06-02 Nick Clifton <nickc@redhat.com>
* config/rl78/rl78-real.md: Add peepholes to avoid a register
copy when calling a function.
* config/rl78/rl78.c (need_to_save): Do not push the frame
pointer in an interrupt handler prologue if it is never used.
Index: gcc/config/rl78/rl78-real.md
===================================================================
--- gcc/config/rl78/rl78-real.md (revision 224011)
+++ gcc/config/rl78/rl78-real.md (working copy)
@@ -342,6 +342,25 @@
[(set (attr "update_Z") (const_string "clobber"))]
)
+;; Peephole to match:
+;;
+;; (set (reg1) (reg2))
+;; (call (mem (reg1)))
+;;
+;; and replace it with:
+;;
+;; (call (mem (reg2)))
+
+(define_peephole2
+ [(set (match_operand:HI 0 "register_operand") (match_operand:HI 1 "register_operand"))
+ (call (mem:HI (match_dup 0))(const_int 0))
+ ]
+ "peep2_regno_dead_p (2, REGNO (operands[0]))
+ && REGNO (operands[1]) < 8"
+ [(call (mem:HI (match_dup 1))(const_int 0))
+ ]
+)
+
(define_insn "*call_value_real"
[(set (match_operand 0 "register_operand" "=v,v")
(call (match_operand:HI 1 "memory_operand" "Wab,Wca")
@@ -353,6 +372,25 @@
[(set (attr "update_Z") (const_string "clobber"))]
)
+;; Peephole to match:
+;;
+;; (set (reg1) (reg2))
+;; (set (reg3) (call (mem (reg1))))
+;;
+;; and replace it with:
+;;
+;; (set (reg3) (call (mem (reg2))))
+
+(define_peephole2
+ [(set (match_operand:HI 0 "register_operand") (match_operand:HI 1 "register_operand"))
+ (set (match_operand:HI 2 "register_operand") (call (mem:HI (match_dup 0))(const_int 0)))
+ ]
+ "peep2_regno_dead_p (2, REGNO (operands[0]))
+ && REGNO (operands[1]) < 8"
+ [(set (match_dup 2) (call (mem:HI (match_dup 1))(const_int 0)))
+ ]
+)
+
(define_insn "*cbranchqi4_real_signed"
[(set (pc) (if_then_else
(match_operator 0 "rl78_cmp_operator_signed"
Index: gcc/config/rl78/rl78.c
===================================================================
--- gcc/config/rl78/rl78.c (revision 224011)
+++ gcc/config/rl78/rl78.c (working copy)
@@ -678,10 +678,12 @@
/* If the handler is a non-leaf function then it may call
non-interrupt aware routines which will happily clobber
- any call_used registers, so we have to preserve them. */
- if (!crtl->is_leaf && call_used_regs[regno])
+ any call_used registers, so we have to preserve them.
+ We do not have to worry about the frame pointer register
+ though, as that is handled below. */
+ if (!crtl->is_leaf && call_used_regs[regno] && regno < 22)
return true;
-
+
/* Otherwise we only have to save a register, call_used
or not, if it is used by this handler. */
return df_regs_ever_live_p (regno);
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-06-03 5:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-14 16:53 RFA: RL78: Nick Clifton
2015-04-14 17:02 ` DJ Delorie
2015-06-02 16:27 Nick Clifton
2015-06-03 6:00 ` 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).