Patchwork predict_loop fix (PR tree-optimization/48189)

login
register
mail settings
Submitter Jakub Jelinek
Date Jan. 8, 2013, 8:05 p.m.
Message ID <20130108200540.GO7269@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/210490/
State New
Headers show

Comments

Jakub Jelinek - Jan. 8, 2013, 8:05 p.m.
Hi!

This is Steven's patch from the PR plus mine hunk, bootstrapped/regtested on
x86_64-linux and i686-linux, ok for trunk?

2013-01-08  Steven Bosscher  <steven@gcc.gnu.org>
	    Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/48189
	* predict.c (predict_loops): If max is 0, don't call compare_tree_int.
	If nitercst is 0, don't predict the exit edge.

	* gcc.dg/pr48189.c: New test.


	Jakub
Richard Guenther - Jan. 9, 2013, 8:51 a.m.
On Tue, 8 Jan 2013, Jakub Jelinek wrote:

> Hi!
> 
> This is Steven's patch from the PR plus mine hunk, bootstrapped/regtested on
> x86_64-linux and i686-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2013-01-08  Steven Bosscher  <steven@gcc.gnu.org>
> 	    Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/48189
> 	* predict.c (predict_loops): If max is 0, don't call compare_tree_int.
> 	If nitercst is 0, don't predict the exit edge.
> 
> 	* gcc.dg/pr48189.c: New test.
> 
> --- gcc/predict.c.jj	2013-01-04 13:44:35.000000000 +0100
> +++ gcc/predict.c	2013-01-08 15:58:15.552884491 +0100
> @@ -1434,7 +1434,8 @@ predict_loops (void)
>  	  if (TREE_CODE (niter) == INTEGER_CST)
>  	    {
>  	      if (host_integerp (niter, 1)
> -		  && compare_tree_int (niter, max-1) == -1)
> +		  && max
> +		  && compare_tree_int (niter, max - 1) == -1)
>  		nitercst = tree_low_cst (niter, 1) + 1;
>  	      else
>  		nitercst = max;
> @@ -1456,6 +1457,11 @@ predict_loops (void)
>  	  else
>  	    continue;
>  
> +	  /* If the prediction for number of iterations is zero, do not
> +	     predict the exit edges.  */
> +	  if (nitercst == 0)
> +	    continue;
> +
>  	  probability = ((REG_BR_PROB_BASE + nitercst / 2) / nitercst);
>  	  predict_edge (ex, predictor, probability);
>  	}
> --- gcc/testsuite/gcc.dg/pr48189.c.jj	2013-01-08 15:59:38.319433008 +0100
> +++ gcc/testsuite/gcc.dg/pr48189.c	2013-01-08 15:52:31.000000000 +0100
> @@ -0,0 +1,13 @@
> +/* PR tree-optimization/48189 */
> +/* { dg-do compile } */
> +/* { dg-options "-O --param max-predicted-iterations=0" } */
> +
> +struct S { int s[8]; };
> +  
> +void
> +foo (int *x, struct S *y)
> +{
> +  int i;
> +  for (i = 0; y[i].s[i]; i++)
> +    *x++ = y[i].s[i];
> +}
> 
> 	Jakub
> 
>

Patch

--- gcc/predict.c.jj	2013-01-04 13:44:35.000000000 +0100
+++ gcc/predict.c	2013-01-08 15:58:15.552884491 +0100
@@ -1434,7 +1434,8 @@  predict_loops (void)
 	  if (TREE_CODE (niter) == INTEGER_CST)
 	    {
 	      if (host_integerp (niter, 1)
-		  && compare_tree_int (niter, max-1) == -1)
+		  && max
+		  && compare_tree_int (niter, max - 1) == -1)
 		nitercst = tree_low_cst (niter, 1) + 1;
 	      else
 		nitercst = max;
@@ -1456,6 +1457,11 @@  predict_loops (void)
 	  else
 	    continue;
 
+	  /* If the prediction for number of iterations is zero, do not
+	     predict the exit edges.  */
+	  if (nitercst == 0)
+	    continue;
+
 	  probability = ((REG_BR_PROB_BASE + nitercst / 2) / nitercst);
 	  predict_edge (ex, predictor, probability);
 	}
--- gcc/testsuite/gcc.dg/pr48189.c.jj	2013-01-08 15:59:38.319433008 +0100
+++ gcc/testsuite/gcc.dg/pr48189.c	2013-01-08 15:52:31.000000000 +0100
@@ -0,0 +1,13 @@ 
+/* PR tree-optimization/48189 */
+/* { dg-do compile } */
+/* { dg-options "-O --param max-predicted-iterations=0" } */
+
+struct S { int s[8]; };
+  
+void
+foo (int *x, struct S *y)
+{
+  int i;
+  for (i = 0; y[i].s[i]; i++)
+    *x++ = y[i].s[i];
+}