summaryrefslogtreecommitdiff
path: root/gcc/predict.c
diff options
context:
space:
mode:
authorrakdver <rakdver@138bc75d-0d04-0410-961f-82ee72b054a4>2007-02-25 19:49:22 +0000
committerrakdver <rakdver@138bc75d-0d04-0410-961f-82ee72b054a4>2007-02-25 19:49:22 +0000
commitd500fef3c51c2582fa29d4b8c0eab75c61bcac1f (patch)
tree442c3c77bcfc1b33de609ff61cc1e7e4b84bc7e8 /gcc/predict.c
parent9af7fd5b82a9d848526e5f5edf0411d6dd2693fc (diff)
downloadgcc-d500fef3c51c2582fa29d4b8c0eab75c61bcac1f.tar.gz
* tree-ssa-loop-niter.c (compute_estimated_nb_iterations): Fix
off-by-one error. (array_at_struct_end_p): New function. (idx_infer_loop_bounds): Use it. (estimate_numbers_of_iterations_loop): Export. * predict.c (predict_loops): Use estimated_loop_iterations_int. Do not use PRED_LOOP_EXIT on exits predicted by # of iterations. (tree_estimate_probability): Call record_loop_exits. * tree-data-ref.c (get_number_of_iters_for_loop): Replaced by ... (estimated_loop_iterations, estimated_loop_iterations_int, estimated_loop_iterations_tree): New functions. (analyze_siv_subscript_cst_affine, compute_overlap_steps_for_affine_1_2, analyze_subscript_affine_affine): Use estimated_loop_iterations_int. (analyze_miv_subscript): Use estimated_loop_iterations_tree. * predict.def (PRED_LOOP_ITERATIONS): Update comment. (PRED_LOOP_ITERATIONS_GUESSED): New. * cfgloop.c (record_loop_exits): Do nothing if there are no loops. * cfgloop.h (estimate_numbers_of_iterations_loop, estimated_loop_iterations_int): Declare. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@122316 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/predict.c')
-rw-r--r--gcc/predict.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/gcc/predict.c b/gcc/predict.c
index df5d3105953..0e86c527238 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -650,6 +650,10 @@ predict_loops (void)
for (j = 0; VEC_iterate (edge, exits, j, ex); j++)
{
tree niter = NULL;
+ HOST_WIDE_INT nitercst;
+ int max = PARAM_VALUE (PARAM_MAX_PREDICTED_ITERATIONS);
+ int probability;
+ enum br_predictor predictor;
if (number_of_iterations_exit (loop, ex, &niter_desc, false))
niter = niter_desc.niter;
@@ -658,20 +662,31 @@ predict_loops (void)
if (TREE_CODE (niter) == INTEGER_CST)
{
- int probability;
- int max = PARAM_VALUE (PARAM_MAX_PREDICTED_ITERATIONS);
if (host_integerp (niter, 1)
&& compare_tree_int (niter, max-1) == -1)
- {
- HOST_WIDE_INT nitercst = tree_low_cst (niter, 1) + 1;
- probability = ((REG_BR_PROB_BASE + nitercst / 2)
- / nitercst);
- }
+ nitercst = tree_low_cst (niter, 1) + 1;
else
- probability = ((REG_BR_PROB_BASE + max / 2) / max);
+ nitercst = max;
+ predictor = PRED_LOOP_ITERATIONS;
+ }
+ /* If we have just one exit and we can derive some information about
+ the number of iterations of the loop from the statements inside
+ the loop, use it to predict this exit. */
+ else if (n_exits == 1)
+ {
+ nitercst = estimated_loop_iterations_int (loop, false);
+ if (nitercst < 0)
+ continue;
+ if (nitercst > max)
+ nitercst = max;
- predict_edge (ex, PRED_LOOP_ITERATIONS, probability);
+ predictor = PRED_LOOP_ITERATIONS_GUESSED;
}
+ else
+ continue;
+
+ probability = ((REG_BR_PROB_BASE + nitercst / 2) / nitercst);
+ predict_edge (ex, predictor, probability);
}
VEC_free (edge, heap, exits);
@@ -706,7 +721,11 @@ predict_loops (void)
/* Loop exit heuristics - predict an edge exiting the loop if the
conditional has no loop header successors as not taken. */
- if (!header_found)
+ if (!header_found
+ /* If we already used more reliable loop exit predictors, do not
+ bother with PRED_LOOP_EXIT. */
+ && !predicted_by_p (bb, PRED_LOOP_ITERATIONS_GUESSED)
+ && !predicted_by_p (bb, PRED_LOOP_ITERATIONS))
{
/* For loop with many exits we don't want to predict all exits
with the pretty large probability, because if all exits are
@@ -1258,6 +1277,7 @@ tree_estimate_probability (void)
tree_bb_level_predictions ();
mark_irreducible_loops ();
+ record_loop_exits ();
if (current_loops)
predict_loops ();