aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vrp.c
diff options
context:
space:
mode:
authorZdenek Dvorak <ook@ucw.cz>2011-06-14 16:29:58 +0200
committerTom de Vries <vries@gcc.gnu.org>2011-06-14 14:29:58 +0000
commitb4a9343cf59f4ccb03c5be05a9314ff1f45712b4 (patch)
tree988a19c68464433ba5e738e385eec5930b88c556 /gcc/tree-vrp.c
parentd2640c430fcce5cd42c60f361eb3f0ac1a048a48 (diff)
downloadgcc-b4a9343cf59f4ccb03c5be05a9314ff1f45712b4.zip
gcc-b4a9343cf59f4ccb03c5be05a9314ff1f45712b4.tar.gz
gcc-b4a9343cf59f4ccb03c5be05a9314ff1f45712b4.tar.bz2
re PR middle-end/45098 (Missed induction variable optimization)
2011-06-14 Zdenek Dvorak <ook@ucw.cz> Tom de Vries <tom@codesourcery.com> PR target/45098 * cfgloop.h (nb_iterations_upper_bound, nb_iterations_estimate): Document changed semantics. (max_stmt_executions, max_stmt_executions_int): Declare. * tree-data-ref.c (estimated_loop_iterations) (estimated_loop_iterations_int): Move functions... * tree-ssa-loop-niter.c (estimated_loop_iterations) (estimated_loop_iterations_int): here. (record_estimate): Change nb_iterations_upper_bound and nb_iterations_estimate semantics. (max_stmt_executions, max_stmt_executions_int): New function. * tree-data-ref.c (estimated_loop_iterations_tree): Rename to ... (max_stmt_executions_tree): this. (analyze_miv_subscript): Use max_stmt_executions_tree instead of estimated_loop_iterations_tree. tree-ssa-loop-ivopts.c (avg_loop_niter): Use max_stmt_executions_int instead of estimated_loop_iterations_int. * predict.c (predict_loops): Idem. * tree-parloops.c (parallelize_loops): Idem. * tree-data-ref.c (analyze_siv_subscript_cst_affine) (compute_overlap_steps_for_affine_1_2, analyze_subscript_affine_affine) (init_omega_for_ddr_1): Idem. * tree-ssa-loop-prefetch.c (determine_loop_nest_reuse) (loop_prefetch_arrays): Idem * graphite-sese-to-poly.c (build_loop_iteration_domains): Use max_stmt_executions instead of estimated_loop_iterations. * tree-data-ref.c (estimated_loop_iterations_tree): Idem. * tree-vrp.c (adjust_range_with_scev): Use estimated_loop_iterations instead of nb_iterations_upper_bound. Co-Authored-By: Tom de Vries <tom@codesourcery.com> From-SVN: r175022
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r--gcc/tree-vrp.c62
1 files changed, 30 insertions, 32 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index f40d0d4..0ca27ef 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -3403,44 +3403,42 @@ adjust_range_with_scev (value_range_t *vr, struct loop *loop,
tmax = TYPE_MAX_VALUE (type);
/* Try to use estimated number of iterations for the loop to constrain the
- final value in the evolution.
- We are interested in the number of executions of the latch, while
- nb_iterations_upper_bound includes the last execution of the exit test. */
+ final value in the evolution. */
if (TREE_CODE (step) == INTEGER_CST
- && loop->any_upper_bound
- && !double_int_zero_p (loop->nb_iterations_upper_bound)
&& is_gimple_val (init)
&& (TREE_CODE (init) != SSA_NAME
|| get_value_range (init)->type == VR_RANGE))
{
- value_range_t maxvr = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL };
- double_int dtmp;
- bool unsigned_p = TYPE_UNSIGNED (TREE_TYPE (step));
- int overflow = 0;
-
- dtmp = double_int_mul_with_sign (tree_to_double_int (step),
- double_int_sub (
- loop->nb_iterations_upper_bound,
- double_int_one),
- unsigned_p, &overflow);
- /* If the multiplication overflowed we can't do a meaningful
- adjustment. Likewise if the result doesn't fit in the type
- of the induction variable. For a signed type we have to
- check whether the result has the expected signedness which
- is that of the step as nb_iterations_upper_bound is unsigned. */
- if (!overflow
- && double_int_fits_to_tree_p (TREE_TYPE (init), dtmp)
- && (unsigned_p
- || ((dtmp.high ^ TREE_INT_CST_HIGH (step)) >= 0)))
- {
- tem = double_int_to_tree (TREE_TYPE (init), dtmp);
- extract_range_from_binary_expr (&maxvr, PLUS_EXPR,
- TREE_TYPE (init), init, tem);
- /* Likewise if the addition did. */
- if (maxvr.type == VR_RANGE)
+ double_int nit;
+
+ if (estimated_loop_iterations (loop, true, &nit))
+ {
+ value_range_t maxvr = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL };
+ double_int dtmp;
+ bool unsigned_p = TYPE_UNSIGNED (TREE_TYPE (step));
+ int overflow = 0;
+
+ dtmp = double_int_mul_with_sign (tree_to_double_int (step), nit,
+ unsigned_p, &overflow);
+ /* If the multiplication overflowed we can't do a meaningful
+ adjustment. Likewise if the result doesn't fit in the type
+ of the induction variable. For a signed type we have to
+ check whether the result has the expected signedness which
+ is that of the step as number of iterations is unsigned. */
+ if (!overflow
+ && double_int_fits_to_tree_p (TREE_TYPE (init), dtmp)
+ && (unsigned_p
+ || ((dtmp.high ^ TREE_INT_CST_HIGH (step)) >= 0)))
{
- tmin = maxvr.min;
- tmax = maxvr.max;
+ tem = double_int_to_tree (TREE_TYPE (init), dtmp);
+ extract_range_from_binary_expr (&maxvr, PLUS_EXPR,
+ TREE_TYPE (init), init, tem);
+ /* Likewise if the addition did. */
+ if (maxvr.type == VR_RANGE)
+ {
+ tmin = maxvr.min;
+ tmax = maxvr.max;
+ }
}
}
}