diff mbox

Minor record_upper_bound tweek

Message ID 20121022152625.GA18262@kam.mff.cuni.cz
State New
Headers show

Commit Message

Jan Hubicka Oct. 22, 2012, 3:26 p.m. UTC
Hi,
with profile feedback we may misupdate the profile and start to believe that loops
iterate more times than they do.  This patch makes at least nb_iterations_estimate
no greater than nb_iterations_upper_bound.  This makes the unrolling/peeling/unswitching
heuristics to behave more consistently.
Bootstrapped/regtested x86_64-linux, OK?

Honza

	* tree-sssa-loop-niter.c (record_niter_bound): Be sure that realistic
	estimate is not bigger than upper bound.

Comments

Richard Biener Oct. 23, 2012, 9:31 a.m. UTC | #1
On Mon, 22 Oct 2012, Jan Hubicka wrote:

> Hi,
> with profile feedback we may misupdate the profile and start to believe that loops
> iterate more times than they do.  This patch makes at least nb_iterations_estimate
> no greater than nb_iterations_upper_bound.  This makes the unrolling/peeling/unswitching
> heuristics to behave more consistently.
> Bootstrapped/regtested x86_64-linux, OK?

Ok with ...

> Honza
> 
> 	* tree-sssa-loop-niter.c (record_niter_bound): Be sure that realistic
> 	estimate is not bigger than upper bound.
> Index: tree-ssa-loop-niter.c
> ===================================================================
> --- tree-ssa-loop-niter.c	(revision 192632)
> +++ tree-ssa-loop-niter.c	(working copy)
> @@ -2506,13 +2506,20 @@ record_niter_bound (struct loop *loop, d
>      {
>        loop->any_upper_bound = true;
>        loop->nb_iterations_upper_bound = i_bound;
> +      if (loop->any_estimate
> +	  && i_bound.ult (loop->nb_iterations_estimate))
> +        loop->nb_iterations_estimate = i_bound;
>      }
>    if (realistic
>        && (!loop->any_estimate
>  	  || i_bound.ult (loop->nb_iterations_estimate)))
>      {
>        loop->any_estimate = true;
> -      loop->nb_iterations_estimate = i_bound;
> +      if (loop->nb_iterations_upper_bound.ult (i_bound)
> +	   && loop->any_upper_bound)

testing any_upper_bound before accessing loop->nb_iterations_upper_bound

> +        loop->nb_iterations_estimate = loop->nb_iterations_upper_bound;
> +      else
> +        loop->nb_iterations_estimate = i_bound;
>      }
>  
>    /* If an upper bound is smaller than the realistic estimate of the
> 
>
diff mbox

Patch

Index: tree-ssa-loop-niter.c
===================================================================
--- tree-ssa-loop-niter.c	(revision 192632)
+++ tree-ssa-loop-niter.c	(working copy)
@@ -2506,13 +2506,20 @@  record_niter_bound (struct loop *loop, d
     {
       loop->any_upper_bound = true;
       loop->nb_iterations_upper_bound = i_bound;
+      if (loop->any_estimate
+	  && i_bound.ult (loop->nb_iterations_estimate))
+        loop->nb_iterations_estimate = i_bound;
     }
   if (realistic
       && (!loop->any_estimate
 	  || i_bound.ult (loop->nb_iterations_estimate)))
     {
       loop->any_estimate = true;
-      loop->nb_iterations_estimate = i_bound;
+      if (loop->nb_iterations_upper_bound.ult (i_bound)
+	   && loop->any_upper_bound)
+        loop->nb_iterations_estimate = loop->nb_iterations_upper_bound;
+      else
+        loop->nb_iterations_estimate = i_bound;
     }
 
   /* If an upper bound is smaller than the realistic estimate of the