===================================================================
@@ -2764,6 +2764,10 @@ iv_number_of_iterations (struct loop *lo
{
if (!desc->niter_max)
desc->niter_max = determine_max_iter (loop, desc, old_niter);
+ if (loop->any_upper_bound
+ && double_int_fits_in_uhwi_p (loop->nb_iterations_upper_bound)
+ && loop->nb_iterations_upper_bound.low < desc->niter_max)
+ desc->niter_max = loop->nb_iterations_upper_bound.low;
/* simplify_using_initial_values does a copy propagation on the registers
in the expression for the number of iterations. This prolongs life
===================================================================
@@ -859,7 +859,8 @@ decide_unroll_runtime_iterations (struct
}
/* If we have profile feedback, check whether the loop rolls. */
- if (loop->header->count && expected_loop_iterations (loop) < 2 * nunroll)
+ if ((loop->header->count && expected_loop_iterations (loop) < 2 * nunroll)
+ || desc->niter_max < 2 * nunroll)
{
if (dump_file)
fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n");
===================================================================
@@ -1383,6 +1383,10 @@ number_of_iterations_cond (struct loop *
gcc_unreachable ();
}
+ if (loop->any_upper_bound
+ && double_int_ucmp (loop->nb_iterations_upper_bound, niter->max) < 0)
+ niter->max = loop->nb_iterations_upper_bound;
+
mpz_clear (bnds.up);
mpz_clear (bnds.below);
@@ -3030,7 +3034,7 @@ estimate_numbers_of_iterations_loop (str
if (loop->estimate_state != EST_NOT_COMPUTED)
return;
loop->estimate_state = EST_AVAILABLE;
- loop->any_upper_bound = false;
+ /* loop->any_upper_bound = false; */
loop->any_estimate = false;
exits = get_loop_exit_edges (loop);
===================================================================
@@ -1801,6 +1801,8 @@ loop_prefetch_arrays (struct loop *loop)
ahead = (PREFETCH_LATENCY + time - 1) / time;
est_niter = max_stmt_executions_int (loop, false);
+ if (est_niter == -1)
+ est_niter = max_stmt_executions_int (loop, true);
/* Prefetching is not likely to be profitable if the trip count to ahead
ratio is too small. */
===================================================================
@@ -2206,6 +2206,12 @@ vect_do_peeling_for_alignment (loop_vec_
#ifdef ENABLE_CHECKING
slpeel_verify_cfg_after_peeling (new_loop, loop);
#endif
+ new_loop->any_upper_bound = true;
+ new_loop->nb_iterations_upper_bound = uhwi_to_double_int (MAX (LOOP_VINFO_VECT_FACTOR (loop_vinfo), min_profitable_iters));
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, "Setting upper bound of nb iterations for prologue "
+ "loop to %d\n", MAX (LOOP_VINFO_VECT_FACTOR (loop_vinfo),
+ min_profitable_iters));
/* Update number of times loop executes. */
n_iters = LOOP_VINFO_NITERS (loop_vinfo);