This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Remove RTL branch prediction as a separate pass
- From: Steven Bosscher <stevenb dot gcc at gmail dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 12 Mar 2006 17:56:04 +0100
- Subject: [PATCH] Remove RTL branch prediction as a separate pass
Hi,
With loop.c out of the way, we never have PROFILE_ABSENT
unless we're not predicting branches at all. This means
that pass_branch_prob is dead.
I have verified this first by making eestimate_probability
abort when it is called, just to be sure. Then I crafted
the patch below. Bootstrapped and tested on x86_64-linux.
This should give us a small speedup because we don't have
to compute dominators and find loops anymore for no reason.
Is this patch OK for mainline?
Gr.
Steven
<date> Steven Bosscher <stevenb.gcc@gmail.com>
* predict.c (estimate_probability): Remove.
* profile.c (rest_of_handle_branch_prob, pass_branch_prob): Remove.
* basic-block.h (estimate_probability): Remove prototype.
* passes.c (finish_optimization_passes): Dump branch prediction or
profiling heuristics to the .profile tree dump.
(init_optimization_passes): Unqueue pass_branch_prob.
* doc/invoke.texi (-fdump-rtl-bp): Remove.
Index: predict.c
===================================================================
--- predict.c (revision 111977)
+++ predict.c (working copy)
@@ -826,85 +826,6 @@ bb_estimate_probability_locally (basic_b
}
}
-/* Statically estimate the probability that a branch will be taken and
produce
- estimated profile. When profile feedback is present never executed
portions
- of function gets estimated. */
-
-void
-estimate_probability (struct loops *loops_info)
-{
- basic_block bb;
-
- connect_infinite_loops_to_exit ();
- calculate_dominance_info (CDI_DOMINATORS);
- calculate_dominance_info (CDI_POST_DOMINATORS);
-
- predict_loops (loops_info, true);
-
- iv_analysis_done ();
-
- /* Attempt to predict conditional jumps using a number of heuristics. */
- FOR_EACH_BB (bb)
- {
- rtx last_insn = BB_END (bb);
- edge e;
- edge_iterator ei;
-
- if (! can_predict_insn_p (last_insn))
- continue;
-
- FOR_EACH_EDGE (e, ei, bb->succs)
- {
- /* Predict early returns to be probable, as we've already taken
- care for error returns and other are often used for fast paths
- trought function. */
- if ((e->dest == EXIT_BLOCK_PTR
- || (single_succ_p (e->dest)
- && single_succ (e->dest) == EXIT_BLOCK_PTR))
- && !predicted_by_p (bb, PRED_NULL_RETURN)
- && !predicted_by_p (bb, PRED_CONST_RETURN)
- && !predicted_by_p (bb, PRED_NEGATIVE_RETURN)
- && !last_basic_block_p (e->dest))
- predict_edge_def (e, PRED_EARLY_RETURN, TAKEN);
-
- /* Look for block we are guarding (i.e. we dominate it,
- but it doesn't postdominate us). */
- if (e->dest != EXIT_BLOCK_PTR && e->dest != bb
- && dominated_by_p (CDI_DOMINATORS, e->dest, e->src)
- && !dominated_by_p (CDI_POST_DOMINATORS, e->src, e->dest))
- {
- rtx insn;
-
- /* The call heuristic claims that a guarded function call
- is improbable. This is because such calls are often used
- to signal exceptional situations such as printing error
- messages. */
- for (insn = BB_HEAD (e->dest); insn != NEXT_INSN (BB_END (e->dest));
- insn = NEXT_INSN (insn))
- if (CALL_P (insn)
- /* Constant and pure calls are hardly used to signalize
- something exceptional. */
- && ! CONST_OR_PURE_CALL_P (insn))
- {
- predict_edge_def (e, PRED_CALL, NOT_TAKEN);
- break;
- }
- }
- }
- bb_estimate_probability_locally (bb);
- }
-
- /* Attach the combined probability to each conditional jump. */
- FOR_EACH_BB (bb)
- combine_predictions_for_insn (BB_END (bb), bb);
-
- remove_fake_edges ();
- estimate_bb_frequencies (loops_info);
- free_dominance_info (CDI_POST_DOMINATORS);
- if (profile_status == PROFILE_ABSENT)
- profile_status = PROFILE_GUESSED;
-}
-
/* Set edge->probability for each successor edge of BB. */
void
guess_outgoing_edge_probabilities (basic_block bb)
Index: profile.c
===================================================================
--- profile.c (revision 111977)
+++ profile.c (working copy)
@@ -1336,46 +1336,3 @@ tree_register_profile_hooks (void)
profile_hooks = &tree_profile_hooks;
}
-
-/* Do branch profiling and static profile estimation passes. */
-static unsigned int
-rest_of_handle_branch_prob (void)
-{
- struct loops loops;
-
- /* Discover and record the loop depth at the head of each basic
- block. The loop infrastructure does the real job for us. */
- flow_loops_find (&loops);
-
- if (dump_file)
- flow_loops_dump (&loops, dump_file, NULL, 0);
-
- /* Estimate using heuristics if no profiling info is available. */
- if (flag_guess_branch_prob
- && profile_status == PROFILE_ABSENT)
- estimate_probability (&loops);
-
- flow_loops_free (&loops);
- free_dominance_info (CDI_DOMINATORS);
- return 0;
-}
-
-struct tree_opt_pass pass_branch_prob =
-{
- "bp", /* name */
- NULL, /* gate */
- rest_of_handle_branch_prob, /* execute */
- NULL, /* sub */
- NULL, /* next */
- 0, /* static_pass_number */
- TV_BRANCH_PROB, /* tv_id */
- 0, /* properties_required */
- 0, /* properties_provided */
- 0, /* properties_destroyed */
- 0, /* todo_flags_start */
- TODO_dump_func, /* todo_flags_finish */
- 'b' /* letter */
-};
-
-
-
Index: basic-block.h
===================================================================
--- basic-block.h (revision 111977)
+++ basic-block.h (working copy)
@@ -869,7 +869,6 @@ extern struct edge_list *pre_edge_rev_lc
extern void compute_available (sbitmap *, sbitmap *, sbitmap *, sbitmap *);
/* In predict.c */
-extern void estimate_probability (struct loops *);
extern void expected_value_to_br_prob (void);
extern bool maybe_hot_bb_p (basic_block);
extern bool probably_cold_bb_p (basic_block);
Index: passes.c
===================================================================
--- passes.c (revision 111977)
+++ passes.c (working copy)
@@ -216,10 +216,10 @@ finish_optimization_passes (void)
timevar_push (TV_DUMP);
if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
{
- dump_file = dump_begin (pass_branch_prob.static_pass_number, NULL);
+ dump_file = dump_begin (pass_profile.static_pass_number, NULL);
end_branch_prob ();
if (dump_file)
- dump_end (pass_branch_prob.static_pass_number, dump_file);
+ dump_end (pass_profile.static_pass_number, dump_file);
}
if (optimize > 0)
@@ -635,7 +635,6 @@ init_optimization_passes (void)
NEXT_PASS (pass_gcse);
NEXT_PASS (pass_jump_bypass);
NEXT_PASS (pass_cfg);
- NEXT_PASS (pass_branch_prob);
NEXT_PASS (pass_rtl_ifcvt);
NEXT_PASS (pass_tracer);
/* Perform loop optimizations. It might be better to do them a bit
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi (revision 111977)
+++ doc/invoke.texi (working copy)
@@ -3712,12 +3712,6 @@ letters for use in @var{letters} and @va
@opindex dA
Annotate the assembler output with miscellaneous debugging information.
-@item -db
-@itemx -fdump-rtl-bp
-@opindex db
-@opindex fdump-rtl-bp
-Dump after computing branch probabilities, to @file{@var{file}.09.bp}.
-
@item -dB
@itemx -fdump-rtl-bbro
@opindex dB