diff mbox

Fix ICE in reduction_phi (PR tree-optimization/47060)

Message ID 20101229215405.GT16156@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Dec. 29, 2010, 9:54 p.m. UTC
Hi!

Before my recent tree-parloops.c fixes reduction_phi would return
NULL if phi was NULL and the callers were relying on that in some cases,
as shown on the testcase.  Calling gimple_uid on it will segfault though,
so the following patch checks for that explicitly.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2010-12-29  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/47060
	* tree-parloops.c (reduction_phi): Return NULL if PHI is NULL.

	* gcc.dg/autopar/pr47060.c: New test.


	Jakub

Comments

Richard Biener Dec. 29, 2010, 10:09 p.m. UTC | #1
On Wed, Dec 29, 2010 at 10:54 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> Before my recent tree-parloops.c fixes reduction_phi would return
> NULL if phi was NULL and the callers were relying on that in some cases,
> as shown on the testcase.  Calling gimple_uid on it will segfault though,
> so the following patch checks for that explicitly.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2010-12-29  Jakub Jelinek  <jakub@redhat.com>
>
>        PR tree-optimization/47060
>        * tree-parloops.c (reduction_phi): Return NULL if PHI is NULL.
>
>        * gcc.dg/autopar/pr47060.c: New test.
>
> --- gcc/tree-parloops.c.jj      2010-12-28 12:33:08.000000000 +0100
> +++ gcc/tree-parloops.c 2010-12-29 20:37:38.000000000 +0100
> @@ -205,7 +205,7 @@ reduction_phi (htab_t reduction_list, gi
>  {
>   struct reduction_info tmpred, *red;
>
> -  if (htab_elements (reduction_list) == 0)
> +  if (htab_elements (reduction_list) == 0 || phi == NULL)
>     return NULL;
>
>   tmpred.reduc_phi = phi;
> --- gcc/testsuite/gcc.dg/autopar/pr47060.c.jj   2010-12-29 20:36:02.000000000 +0100
> +++ gcc/testsuite/gcc.dg/autopar/pr47060.c      2010-12-29 20:35:23.000000000 +0100
> @@ -0,0 +1,21 @@
> +/* PR tree-optimization/47060 */
> +/* { dg-do compile } */
> +/* { dg-options "-O -ffast-math -ftree-parallelize-loops=2 -fno-tree-dce" } */
> +
> +struct S
> +{
> +  int n;
> +  float *a;
> +};
> +
> +float
> +foo (struct S *b)
> +{
> +  float c, d;
> +  int j;
> +  for (j = 0; j < b->n; j++)
> +    d += b->a[j];
> +  for (j = 0; j < b->n; j++)
> +    c += b->a[j];
> +  return d;
> +}
>
>        Jakub
>
diff mbox

Patch

--- gcc/tree-parloops.c.jj	2010-12-28 12:33:08.000000000 +0100
+++ gcc/tree-parloops.c	2010-12-29 20:37:38.000000000 +0100
@@ -205,7 +205,7 @@  reduction_phi (htab_t reduction_list, gi
 {
   struct reduction_info tmpred, *red;
 
-  if (htab_elements (reduction_list) == 0)
+  if (htab_elements (reduction_list) == 0 || phi == NULL)
     return NULL;
 
   tmpred.reduc_phi = phi;
--- gcc/testsuite/gcc.dg/autopar/pr47060.c.jj	2010-12-29 20:36:02.000000000 +0100
+++ gcc/testsuite/gcc.dg/autopar/pr47060.c	2010-12-29 20:35:23.000000000 +0100
@@ -0,0 +1,21 @@ 
+/* PR tree-optimization/47060 */
+/* { dg-do compile } */
+/* { dg-options "-O -ffast-math -ftree-parallelize-loops=2 -fno-tree-dce" } */
+
+struct S
+{
+  int n;
+  float *a;
+};
+
+float
+foo (struct S *b)
+{
+  float c, d;
+  int j;
+  for (j = 0; j < b->n; j++)
+    d += b->a[j];
+  for (j = 0; j < b->n; j++)
+    c += b->a[j];
+  return d;
+}