On Tue, 2014-09-02 at 19:50 +0200, Andi Kleen wrote:
> > I suspect the bulk of them currently are coming from the safe_as_a
> > <rtx_insn *> calls within NEXT_INSN and PREV_INSN; do you happen to have
> > information handy on that?
>
> Yes that's right:
>
> - 1.03% lto1 [.] bool
> is_a_helper<rtx_insn*>::test<rtx_def>(rtx_def*)
> ▒
> - bool is_a_helper<rtx_insn*>::test<rtx_def>(rtx_def*)
> ▒
> - 92.20% bool is_a<rtx_insn*, rtx_def>(rtx_def*)
> ▒
> - 98.53% rtx_insn* safe_as_a<rtx_insn*, rtx_def>(rtx_def*)
> ▒
> - 73.28% NEXT_INSN(rtx_insn const*)
> ▒
The is_a_helper for rtx_insn * is non-trivial, so it may be worth
avoiding it, even when inlined.
The attached patch rewrites the inline NEXT_INSN/PREV_INSN to avoid
doing the safe_as_a, instead tightening up the interface so that one can
only set them to an insn, and introducing a new XINSN access macro and
corresponding rt_insn member of the union.
Bootstrapped on x86_64-unknown-linux-gnu (Fedora 20), and has been
rebuilt as part of a config-list.mk build for all working configurations
(albeit with other patches for the latter case).
OK for trunk?
gcc/
* rtl.h (union rtunion): Add new member "rt_insn", of type
rtx_insn *.
(XINSN): New accessor macro, accessing as an rtx_insn *,
requiring code "u".
(PREV_INSN, NEXT_INSN): Eliminate the checked cast to rtx_insn *
and instead directly use XINSN.
(SET_PREV_INSN, SET_NEXT_INSN): Strengthen the return type from
rtx & to rtx_insn *&, using XINSN internally.
(NEXT_INSN): Eliminate the checked cast and instead directly use
XINSN.
* cfgrtl.c (fixup_abnormal_edges): Use NULL rather than NULL_RTX
when assigning to SET_PREV_INSN/SET_NEXT_INSN.
* haifa-sched.c (remove_notes): Likewise.
* sel-sched-ir.c (sel_remove_insn): Likewise.
(get_bb_note_from_pool): Likewise.
* config/ia64/ia64.c (ia64_init_dfa_pre_cycle_insn): Likewise.
(ia64_reorg): Likewise.
>From 6e60e29211314b5865bc7b5b05d586777d96815f Mon Sep 17 00:00:00 2001
From: David Malcolm <[email protected]>
Date: Wed, 3 Sep 2014 11:01:37 -0400
Subject: [PATCH 01/32] Add XINSN macro and use it within NEXT_INSN/PREV_INSN
gcc/
* rtl.h (union rtunion): Add new member "rt_insn", of type
rtx_insn *.
(XINSN): New accessor macro, accessing as an rtx_insn *,
requiring code "u".
(PREV_INSN, NEXT_INSN): Eliminate the checked cast to rtx_insn *
and instead directly use XINSN.
(SET_PREV_INSN, SET_NEXT_INSN): Strengthen the return type from
rtx & to rtx_insn *&, using XINSN internally.
(NEXT_INSN): Eliminate the checked cast and instead directly use
XINSN.
* cfgrtl.c (fixup_abnormal_edges): Use NULL rather than NULL_RTX
when assigning to SET_PREV_INSN/SET_NEXT_INSN.
* haifa-sched.c (remove_notes): Likewise.
* sel-sched-ir.c (sel_remove_insn): Likewise.
(get_bb_note_from_pool): Likewise.
* config/ia64/ia64.c (ia64_init_dfa_pre_cycle_insn): Likewise.
(ia64_reorg): Likewise.
---
gcc/cfgrtl.c | 4 ++--
gcc/config/ia64/ia64.c | 6 +++---
gcc/haifa-sched.c | 2 +-
gcc/rtl.h | 16 ++++++++--------
gcc/sel-sched-ir.c | 8 ++++----
5 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index bc6c965..7a03d78 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -3279,8 +3279,8 @@ fixup_abnormal_edges (void)
{
/* We're not deleting it, we're moving it. */
INSN_DELETED_P (insn) = 0;
- SET_PREV_INSN (insn) = NULL_RTX;
- SET_NEXT_INSN (insn) = NULL_RTX;
+ SET_PREV_INSN (insn) = NULL;
+ SET_NEXT_INSN (insn) = NULL;
insert_insn_on_edge (insn, e);
inserted = true;
diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c
index 2ed5ddd..e73a489 100644
--- a/gcc/config/ia64/ia64.c
+++ b/gcc/config/ia64/ia64.c
@@ -9496,10 +9496,10 @@ ia64_init_dfa_pre_cycle_insn (void)
prev_cycle_state = xmalloc (dfa_state_size);
}
dfa_pre_cycle_insn = make_insn_raw (gen_pre_cycle ());
- SET_PREV_INSN (dfa_pre_cycle_insn) = SET_NEXT_INSN (dfa_pre_cycle_insn) = NULL_RTX;
+ SET_PREV_INSN (dfa_pre_cycle_insn) = SET_NEXT_INSN (dfa_pre_cycle_insn) = NULL;
recog_memoized (dfa_pre_cycle_insn);
dfa_stop_insn = make_insn_raw (gen_insn_group_barrier (GEN_INT (3)));
- SET_PREV_INSN (dfa_stop_insn) = SET_NEXT_INSN (dfa_stop_insn) = NULL_RTX;
+ SET_PREV_INSN (dfa_stop_insn) = SET_NEXT_INSN (dfa_stop_insn) = NULL;
recog_memoized (dfa_stop_insn);
}
@@ -9687,7 +9687,7 @@ ia64_reorg (void)
initiate_bundle_states ();
ia64_nop = make_insn_raw (gen_nop ());
- SET_PREV_INSN (ia64_nop) = SET_NEXT_INSN (ia64_nop) = NULL_RTX;
+ SET_PREV_INSN (ia64_nop) = SET_NEXT_INSN (ia64_nop) = NULL;
recog_memoized (ia64_nop);
clocks_length = get_max_uid () + 1;
stops_p = XCNEWVEC (char, clocks_length);
diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c
index 1ebfcdb..9ebe8f0 100644
--- a/gcc/haifa-sched.c
+++ b/gcc/haifa-sched.c
@@ -4069,7 +4069,7 @@ remove_notes (rtx_insn *head, rtx_insn *tail)
/* Add the note to list that ends at NOTE_LIST. */
SET_PREV_INSN (insn) = note_list;
- SET_NEXT_INSN (insn) = NULL_RTX;
+ SET_NEXT_INSN (insn) = NULL;
if (note_list)
SET_NEXT_INSN (note_list) = insn;
note_list = insn;
diff --git a/gcc/rtl.h b/gcc/rtl.h
index beeed2f..27751db 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -195,6 +195,7 @@ union rtunion
unsigned int rt_uint;
const char *rt_str;
rtx rt_rtx;
+ rtx_insn *rt_insn;
rtvec rt_rtvec;
enum machine_mode rt_type;
addr_diff_vec_flags rt_addr_diff_vec_flags;
@@ -1208,6 +1209,7 @@ extern void rtl_check_failed_flag (const char *, const_rtx, const char *,
#define XUINT(RTX, N) (RTL_CHECK2 (RTX, N, 'i', 'n').rt_uint)
#define XSTR(RTX, N) (RTL_CHECK2 (RTX, N, 's', 'S').rt_str)
#define XEXP(RTX, N) (RTL_CHECK2 (RTX, N, 'e', 'u').rt_rtx)
+#define XINSN(RTX, N) (RTL_CHECK1 (RTX, N, 'u').rt_insn)
#define XVEC(RTX, N) (RTL_CHECK2 (RTX, N, 'E', 'V').rt_rtvec)
#define XMODE(RTX, N) (RTL_CHECK1 (RTX, N, 'M').rt_type)
#define XTREE(RTX, N) (RTL_CHECK1 (RTX, N, 't').rt_tree)
@@ -1323,24 +1325,22 @@ inline int& INSN_UID (rtx insn)
inline rtx_insn *PREV_INSN (const rtx_insn *insn)
{
- rtx prev = XEXP (insn, 0);
- return safe_as_a <rtx_insn *> (prev);
+ return XINSN (insn, 0);
}
-inline rtx& SET_PREV_INSN (rtx_insn *insn)
+inline rtx_insn *& SET_PREV_INSN (rtx_insn *insn)
{
- return XEXP (insn, 0);
+ return XINSN (insn, 0);
}
inline rtx_insn *NEXT_INSN (const rtx_insn *insn)
{
- rtx next = XEXP (insn, 1);
- return safe_as_a <rtx_insn *> (next);
+ return XINSN (insn, 1);
}
-inline rtx& SET_NEXT_INSN (rtx_insn *insn)
+inline rtx_insn *& SET_NEXT_INSN (rtx_insn *insn)
{
- return XEXP (insn, 1);
+ return XINSN (insn, 1);
}
inline basic_block BLOCK_FOR_INSN (const_rtx insn)
diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c
index 02dc8f2..b40b424 100644
--- a/gcc/sel-sched-ir.c
+++ b/gcc/sel-sched-ir.c
@@ -3948,8 +3948,8 @@ sel_remove_insn (insn_t insn, bool only_disconnect, bool full_tidying)
/* It is necessary to NULL these fields in case we are going to re-insert
INSN into the insns stream, as will usually happen in the ONLY_DISCONNECT
case, but also for NOPs that we will return to the nop pool. */
- SET_PREV_INSN (insn) = NULL_RTX;
- SET_NEXT_INSN (insn) = NULL_RTX;
+ SET_PREV_INSN (insn) = NULL;
+ SET_NEXT_INSN (insn) = NULL;
set_block_for_insn (insn, NULL);
return tidy_control_flow (bb, full_tidying);
@@ -4991,8 +4991,8 @@ get_bb_note_from_pool (void)
{
rtx_note *note = bb_note_pool.pop ();
- SET_PREV_INSN (note) = NULL_RTX;
- SET_NEXT_INSN (note) = NULL_RTX;
+ SET_PREV_INSN (note) = NULL;
+ SET_NEXT_INSN (note) = NULL;
return note;
}
--
1.8.5.3