aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-loop-niter.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2012-04-12 08:35:01 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2012-04-12 08:35:01 +0000
commit652c4c71a1b1f0c92b6a06305d82c354b72e16e0 (patch)
tree609890225d25b25313d4652ae56016555d5edca9 /gcc/tree-ssa-loop-niter.c
parent0c924efa4bd23c9a0668a8a34eada8446ff41021 (diff)
downloadgcc-652c4c71a1b1f0c92b6a06305d82c354b72e16e0.zip
gcc-652c4c71a1b1f0c92b6a06305d82c354b72e16e0.tar.gz
gcc-652c4c71a1b1f0c92b6a06305d82c354b72e16e0.tar.bz2
cfgloop.h (estimated_loop_iterations_int): Ditch 'conservative' parameter.
2012-04-12 Richard Guenther <rguenther@suse.de> * cfgloop.h (estimated_loop_iterations_int): Ditch 'conservative' parameter. (max_stmt_executions_int): Likewise. (estimated_loop_iterations): Likewise. (max_stmt_executions): Likewise. (max_loop_iterations): Declare. (max_loop_iterations_int): Likewise. (estimated_stmt_executions): Likewise. (estimated_stmt_executions_int): Likewise. * tree-ssa-loop-niter.c (estimated_loop_iterations): Split parts to ... (max_loop_iterations): ... this. (estimated_loop_iterations_int): Split parts to ... (max_loop_iterations_int): ... this. (max_stmt_executions_int): Split parts to ... (estimated_stmt_executions_int): ... this. (max_stmt_executions): Split parts to ... (estimated_stmt_executions): ... this. * graphite-sese-to-poly.c (build_loop_iteration_domains): Adjust. * predict.c (predict_loops): Likewise. * tree-data-ref.c (max_stmt_executions_tree): Likewise. (analyze_siv_subscript_cst_affine): Likewise. (compute_overlap_steps_for_affine_1_2): Likewise. (analyze_subscript_affine_affine): Likewise. (init_omega_for_ddr_1): Likewise. * tree-parloops.c (parallelize_loops): Likewise. * tree-ssa-loop-ivopts.c (avg_loop_niter): Likewise. (may_eliminate_iv): Likewise. * tree-ssa-loop-prefetch.c (determine_loop_nest_reuse): Likewise. (loop_prefetch_arrays): Likewise. * tree-vrp.c (adjust_range_with_scev): Likewise. From-SVN: r186372
Diffstat (limited to 'gcc/tree-ssa-loop-niter.c')
-rw-r--r--gcc/tree-ssa-loop-niter.c106
1 files changed, 83 insertions, 23 deletions
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 4acfc67..2529b36 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -3052,25 +3052,28 @@ estimate_numbers_of_iterations_loop (struct loop *loop, bool use_undefined_p)
the function returns false, otherwise returns true. */
bool
-estimated_loop_iterations (struct loop *loop, bool conservative,
- double_int *nit)
+estimated_loop_iterations (struct loop *loop, double_int *nit)
{
estimate_numbers_of_iterations_loop (loop, true);
- if (conservative)
- {
- if (!loop->any_upper_bound)
- return false;
+ if (!loop->any_estimate)
+ return false;
- *nit = loop->nb_iterations_upper_bound;
- }
- else
- {
- if (!loop->any_estimate)
- return false;
+ *nit = loop->nb_iterations_estimate;
+ return true;
+}
- *nit = loop->nb_iterations_estimate;
- }
+/* Sets NIT to an upper bound for the maximum number of executions of the
+ latch of the LOOP. If we have no reliable estimate, the function returns
+ false, otherwise returns true. */
+
+bool
+max_loop_iterations (struct loop *loop, double_int *nit)
+{
+ estimate_numbers_of_iterations_loop (loop, true);
+ if (!loop->any_upper_bound)
+ return false;
+ *nit = loop->nb_iterations_upper_bound;
return true;
}
@@ -3079,12 +3082,32 @@ estimated_loop_iterations (struct loop *loop, bool conservative,
on the number of iterations of LOOP could not be derived, returns -1. */
HOST_WIDE_INT
-estimated_loop_iterations_int (struct loop *loop, bool conservative)
+estimated_loop_iterations_int (struct loop *loop)
+{
+ double_int nit;
+ HOST_WIDE_INT hwi_nit;
+
+ if (!estimated_loop_iterations (loop, &nit))
+ return -1;
+
+ if (!double_int_fits_in_shwi_p (nit))
+ return -1;
+ hwi_nit = double_int_to_shwi (nit);
+
+ return hwi_nit < 0 ? -1 : hwi_nit;
+}
+
+/* Similar to max_loop_iterations, but returns the estimate only
+ if it fits to HOST_WIDE_INT. If this is not the case, or the estimate
+ on the number of iterations of LOOP could not be derived, returns -1. */
+
+HOST_WIDE_INT
+max_loop_iterations_int (struct loop *loop)
{
double_int nit;
HOST_WIDE_INT hwi_nit;
- if (!estimated_loop_iterations (loop, conservative, &nit))
+ if (!max_loop_iterations (loop, &nit))
return -1;
if (!double_int_fits_in_shwi_p (nit))
@@ -3099,9 +3122,9 @@ estimated_loop_iterations_int (struct loop *loop, bool conservative)
the number of execution of the latch by one. */
HOST_WIDE_INT
-max_stmt_executions_int (struct loop *loop, bool conservative)
+max_stmt_executions_int (struct loop *loop)
{
- HOST_WIDE_INT nit = estimated_loop_iterations_int (loop, conservative);
+ HOST_WIDE_INT nit = max_loop_iterations_int (loop);
HOST_WIDE_INT snit;
if (nit == -1)
@@ -3113,17 +3136,54 @@ max_stmt_executions_int (struct loop *loop, bool conservative)
return snit < 0 ? -1 : snit;
}
+/* Returns an estimate for the number of executions of statements
+ in the LOOP. For statements before the loop exit, this exceeds
+ the number of execution of the latch by one. */
+
+HOST_WIDE_INT
+estimated_stmt_executions_int (struct loop *loop)
+{
+ HOST_WIDE_INT nit = estimated_loop_iterations_int (loop);
+ HOST_WIDE_INT snit;
+
+ if (nit == -1)
+ return -1;
+
+ snit = (HOST_WIDE_INT) ((unsigned HOST_WIDE_INT) nit + 1);
+
+ /* If the computation overflows, return -1. */
+ return snit < 0 ? -1 : snit;
+}
+
+/* Sets NIT to the estimated maximum number of executions of the latch of the
+ LOOP, plus one. If we have no reliable estimate, the function returns
+ false, otherwise returns true. */
+
+bool
+max_stmt_executions (struct loop *loop, double_int *nit)
+{
+ double_int nit_minus_one;
+
+ if (!max_loop_iterations (loop, nit))
+ return false;
+
+ nit_minus_one = *nit;
+
+ *nit = double_int_add (*nit, double_int_one);
+
+ return double_int_ucmp (*nit, nit_minus_one) > 0;
+}
+
/* Sets NIT to the estimated number of executions of the latch of the
- LOOP, plus one. If CONSERVATIVE is true, we must be sure that NIT is at
- least as large as the number of iterations. If we have no reliable
- estimate, the function returns false, otherwise returns true. */
+ LOOP, plus one. If we have no reliable estimate, the function returns
+ false, otherwise returns true. */
bool
-max_stmt_executions (struct loop *loop, bool conservative, double_int *nit)
+estimated_stmt_executions (struct loop *loop, double_int *nit)
{
double_int nit_minus_one;
- if (!estimated_loop_iterations (loop, conservative, nit))
+ if (!estimated_loop_iterations (loop, nit))
return false;
nit_minus_one = *nit;