Commit 73367f92 by Jan Hubicka Committed by Jan Hubicka

loop-unroll.c (unroll_loop_constant_iterations): Add update of…

loop-unroll.c (unroll_loop_constant_iterations): Add update of loop->nb_iterations_upper_bound I missed in my previous commit...


	* loop-unroll.c (unroll_loop_constant_iterations): Add
	update of loop->nb_iterations_upper_bound I missed in my previous
	commit; use TRUNC_DIV_EXPR instead of FLOOR_DIV_EXPR to divide
	iteration count.
	(decide_unroll_runtime_iterations): Avoid overflow.
	(unroll_loop_runtime_iterations): Use TRUNC_DIV_EXPR instead of
	FLOOR_DIV_EXPR to update iteration bounds.
	(decide_peel_simple): Avoid integer overflow when deciding
	on number of peelings.
	(decide_unroll_stupid): Likewise.

From-SVN: r192251
parent 0b8c30f9
2012-10-09 Jan Hubicka <jh@suse.cz>
* loop-unroll.c (unroll_loop_constant_iterations): Add
update of loop->nb_iterations_upper_bound I missed in my previous
commit; use TRUNC_DIV_EXPR instead of FLOOR_DIV_EXPR to divide
iteration count.
(decide_unroll_runtime_iterations): Avoid overflow.
(unroll_loop_runtime_iterations): Use TRUNC_DIV_EXPR instead of
FLOOR_DIV_EXPR to update iteration bounds.
(decide_peel_simple): Avoid integer overflow when deciding
on number of peelings.
(decide_unroll_stupid): Likewise.
2012-10-09 Tobias Burnus <burnus@net-b.de> 2012-10-09 Tobias Burnus <burnus@net-b.de>
* lto-cgraph.c (input_node_opt_summary): Remove unused code. * lto-cgraph.c (input_node_opt_summary): Remove unused code.
......
...@@ -740,6 +740,7 @@ unroll_loop_constant_iterations (struct loop *loop) ...@@ -740,6 +740,7 @@ unroll_loop_constant_iterations (struct loop *loop)
apply_opt_in_copies (opt_info, exit_mod + 1, false, false); apply_opt_in_copies (opt_info, exit_mod + 1, false, false);
desc->niter -= exit_mod + 1; desc->niter -= exit_mod + 1;
loop->nb_iterations_upper_bound -= double_int::from_uhwi (exit_mod + 1);
if (loop->any_estimate if (loop->any_estimate
&& double_int::from_uhwi (exit_mod + 1).ule && double_int::from_uhwi (exit_mod + 1).ule
(loop->nb_iterations_estimate)) (loop->nb_iterations_estimate))
...@@ -795,14 +796,14 @@ unroll_loop_constant_iterations (struct loop *loop) ...@@ -795,14 +796,14 @@ unroll_loop_constant_iterations (struct loop *loop)
desc->niter /= max_unroll + 1; desc->niter /= max_unroll + 1;
loop->nb_iterations_upper_bound loop->nb_iterations_upper_bound
= loop->nb_iterations_upper_bound.udiv (double_int::from_uhwi (exit_mod = loop->nb_iterations_upper_bound.udiv (double_int::from_uhwi (max_unroll
+ 1), + 1),
FLOOR_DIV_EXPR); TRUNC_DIV_EXPR);
if (loop->any_estimate) if (loop->any_estimate)
loop->nb_iterations_estimate loop->nb_iterations_estimate
= loop->nb_iterations_estimate.udiv (double_int::from_uhwi (exit_mod = loop->nb_iterations_estimate.udiv (double_int::from_uhwi (max_unroll
+ 1), + 1),
FLOOR_DIV_EXPR); TRUNC_DIV_EXPR);
desc->niter_expr = GEN_INT (desc->niter); desc->niter_expr = GEN_INT (desc->niter);
/* Remove the edges. */ /* Remove the edges. */
...@@ -876,11 +877,10 @@ decide_unroll_runtime_iterations (struct loop *loop, int flags) ...@@ -876,11 +877,10 @@ decide_unroll_runtime_iterations (struct loop *loop, int flags)
return; return;
} }
/* If we have profile feedback, check whether the loop rolls. */ /* Check whether the loop rolls. */
if ((estimated_loop_iterations (loop, &iterations) if ((estimated_loop_iterations (loop, &iterations)
|| max_loop_iterations (loop, &iterations)) || max_loop_iterations (loop, &iterations))
&& iterations.fits_shwi () && iterations.ult (double_int::from_shwi (2 * nunroll)))
&& iterations.to_shwi () <= 2 * nunroll)
{ {
if (dump_file) if (dump_file)
fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n"); fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n");
...@@ -1199,12 +1199,12 @@ unroll_loop_runtime_iterations (struct loop *loop) ...@@ -1199,12 +1199,12 @@ unroll_loop_runtime_iterations (struct loop *loop)
loop->nb_iterations_upper_bound loop->nb_iterations_upper_bound
= loop->nb_iterations_upper_bound.udiv (double_int::from_uhwi (max_unroll = loop->nb_iterations_upper_bound.udiv (double_int::from_uhwi (max_unroll
+ 1), + 1),
FLOOR_DIV_EXPR); TRUNC_DIV_EXPR);
if (loop->any_estimate) if (loop->any_estimate)
loop->nb_iterations_estimate loop->nb_iterations_estimate
= loop->nb_iterations_estimate.udiv (double_int::from_uhwi (max_unroll = loop->nb_iterations_estimate.udiv (double_int::from_uhwi (max_unroll
+ 1), + 1),
FLOOR_DIV_EXPR); TRUNC_DIV_EXPR);
if (exit_at_end) if (exit_at_end)
{ {
desc->niter_expr = desc->niter_expr =
...@@ -1280,8 +1280,7 @@ decide_peel_simple (struct loop *loop, int flags) ...@@ -1280,8 +1280,7 @@ decide_peel_simple (struct loop *loop, int flags)
/* If we have realistic estimate on number of iterations, use it. */ /* If we have realistic estimate on number of iterations, use it. */
if (estimated_loop_iterations (loop, &iterations)) if (estimated_loop_iterations (loop, &iterations))
{ {
if (!iterations.fits_shwi () if (double_int::from_shwi (npeel).ule (iterations))
|| iterations.to_shwi () + 1 > npeel)
{ {
if (dump_file) if (dump_file)
{ {
...@@ -1298,8 +1297,7 @@ decide_peel_simple (struct loop *loop, int flags) ...@@ -1298,8 +1297,7 @@ decide_peel_simple (struct loop *loop, int flags)
/* If we have small enough bound on iterations, we can still peel (completely /* If we have small enough bound on iterations, we can still peel (completely
unroll). */ unroll). */
else if (max_loop_iterations (loop, &iterations) else if (max_loop_iterations (loop, &iterations)
&& iterations.fits_shwi () && iterations.ult (double_int::from_shwi (npeel)))
&& iterations.to_shwi () + 1 <= npeel)
npeel = iterations.to_shwi () + 1; npeel = iterations.to_shwi () + 1;
else else
{ {
...@@ -1446,11 +1444,10 @@ decide_unroll_stupid (struct loop *loop, int flags) ...@@ -1446,11 +1444,10 @@ decide_unroll_stupid (struct loop *loop, int flags)
return; return;
} }
/* If we have profile feedback, check whether the loop rolls. */ /* Check whether the loop rolls. */
if ((estimated_loop_iterations (loop, &iterations) if ((estimated_loop_iterations (loop, &iterations)
|| max_loop_iterations (loop, &iterations)) || max_loop_iterations (loop, &iterations))
&& iterations.fits_shwi () && iterations.ult (double_int::from_shwi (2 * nunroll)))
&& iterations.to_shwi () <= 2 * nunroll)
{ {
if (dump_file) if (dump_file)
fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n"); fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment