public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] predict_loop fix (PR tree-optimization/48189)
@ 2013-01-08 20:05 Jakub Jelinek
  2013-01-09  8:53 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2013-01-08 20:05 UTC (permalink / raw)
  To: Richard Biener, Jan Hubicka; +Cc: gcc-patches

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.

--- 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] predict_loop fix (PR tree-optimization/48189)
  2013-01-08 20:05 [PATCH] predict_loop fix (PR tree-optimization/48189) Jakub Jelinek
@ 2013-01-09  8:53 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2013-01-09  8:53 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jan Hubicka, gcc-patches

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
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imend

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-01-09  8:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-08 20:05 [PATCH] predict_loop fix (PR tree-optimization/48189) Jakub Jelinek
2013-01-09  8:53 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).