diff mbox

Fix PR tree-optimization/45902

Message ID OFDAAD5B4A.68EF7EC6-ONC22577B9.002675D1-C22577B9.0043BB0C@il.ibm.com
State New
Headers show

Commit Message

Ira Rosen Oct. 11, 2010, 12:19 p.m. UTC
Hi,

This patch fixes a bug in creation of a vector of constants in SLP. The
problem is in the type of created vector. It should be set to the vector
type of the statement unless it's a pointer.

Bootstrapped and tested on x86_64-suse-linux and checked that the failure
is fixed on powerpc64-suse-linux.

Committed to mainline, ok for 4.5?

Thanks,
Ira

ChangeLog:

	PR tree-optimization/45902
	* tree-vect-slp.c (vect_get_constant_vectors): Use statement's
	vector type for constants, unless it's a pointer.

testsuite/ChangeLog:

	PR tree-optimization/45902
	* gcc.dg/vect/45902.c: New test.


4.6 patch

Comments

Richard Biener Oct. 11, 2010, 12:32 p.m. UTC | #1
On Mon, Oct 11, 2010 at 2:19 PM, Ira Rosen <IRAR@il.ibm.com> wrote:
>
> Hi,
>
> This patch fixes a bug in creation of a vector of constants in SLP. The
> problem is in the type of created vector. It should be set to the vector
> type of the statement unless it's a pointer.
>
> Bootstrapped and tested on x86_64-suse-linux and checked that the failure
> is fixed on powerpc64-suse-linux.
>
> Committed to mainline, ok for 4.5?

I don't think this makes sense.  If at all the selection of which type
to use should be based on the operation code and the operand
position, but not on CONSTANT_CLASS_P or pointer-type-ness.

So - what operation code / operand position is currently mishandled?

Thanks,
Richard.

> Thanks,
> Ira
>
> ChangeLog:
>
>        PR tree-optimization/45902
>        * tree-vect-slp.c (vect_get_constant_vectors): Use statement's
>        vector type for constants, unless it's a pointer.
>
> testsuite/ChangeLog:
>
>        PR tree-optimization/45902
>        * gcc.dg/vect/45902.c: New test.
>
>
> 4.6 patch
>
> Index: tree-vect-slp.c
> ===================================================================
> --- tree-vect-slp.c     (revision 164987)
> +++ tree-vect-slp.c     (working copy)
> @@ -1894,13 +1894,20 @@ vect_get_constant_vectors (slp_tree slp_
>     }
>
>   if (CONSTANT_CLASS_P (op))
> -    constant_p = true;
> +    {
> +      constant_p = true;
> +      if (POINTER_TYPE_P (TREE_TYPE (gimple_assign_lhs (stmt))))
> +        vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
> +      else
> +        vector_type = STMT_VINFO_VECTYPE (stmt_vinfo);
> +    }
>   else
> -    constant_p = false;
> +    {
> +      constant_p = false;
> +      vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
> +    }
>
> -  vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
>   gcc_assert (vector_type);
> -
>   nunits = TYPE_VECTOR_SUBPARTS (vector_type);
>
>   /* NUMBER_OF_COPIES is the number of times we need to use the same
> values in
> Index: testsuite/gcc.dg/vect/pr45902.c
> ===================================================================
> --- testsuite/gcc.dg/vect/pr45902.c     (revision 0)
> +++ testsuite/gcc.dg/vect/pr45902.c     (revision 0)
> @@ -0,0 +1,44 @@
> +/* { dg-require-effective-target vect_int } */
> +
> +#include <stdarg.h>
> +#include <stdlib.h>
> +#include "tree-vect.h"
> +
> +#define N 128
> +
> +short res[N];
> +short a[N];
> +
> +int
> +main1 ()
> +{
> +  int i;
> +
> +  for (i = 0; i < N/4; i+=4)
> +    {
> +      res[i] = a[i] >> 8;
> +      res[i+1] = a[i+1] >> 8;
> +      res[i+2] = a[i+2] >> 8;
> +      res[i+3] = a[i+3] >> 8;
> +    }
> +}
> +
> +int
> +main ()
> +{
> +  int i;
> +
> +  for (i = 0; i < N; i++)
> +    a[i] = i;
> +
> +  main1 ();
> +
> +  for (i = 0; i < N; i++)
> +    if (res[i] != a[i] >> 8)
> +      abort ();
> +
> +  return 0;
> +}
> +
> +/* { dg-final { cleanup-tree-dump "vect" } } */
>
> 4.5 patch
>
> Index: tree-vect-slp.c
> ===================================================================
> --- tree-vect-slp.c     (revision 165269)
> +++ tree-vect-slp.c     (working copy)
> @@ -1459,13 +1459,20 @@ vect_get_constant_vectors (slp_tree slp_
>     }
>
>   if (CONSTANT_CLASS_P (op))
> -    constant_p = true;
> +    {
> +      constant_p = true;
> +      if (POINTER_TYPE_P (TREE_TYPE (gimple_assign_lhs (stmt))))
> +        vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
> +      else
> +        vector_type = STMT_VINFO_VECTYPE (stmt_vinfo);
> +    }
>   else
> -    constant_p = false;
> +    {
> +      constant_p = false;
> +      vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
> +    }
>
> -  vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
>   gcc_assert (vector_type);
> -
>   nunits = TYPE_VECTOR_SUBPARTS (vector_type);
>
>   /* NUMBER_OF_COPIES is the number of times we need to use the same
> values in
> Index: testsuite/gcc.dg/vect/pr45902.c
> ===================================================================
> --- testsuite/gcc.dg/vect/pr45902.c     (revision 0)
> +++ testsuite/gcc.dg/vect/pr45902.c     (revision 0)
> @@ -0,0 +1,44 @@
> +/* { dg-require-effective-target vect_int } */
> +
> +#include <stdarg.h>
> +#include <stdlib.h>
> +#include "tree-vect.h"
> +
> +#define N 128
> +
> +short res[N];
> +short a[N];
> +
> +int
> +main1 ()
> +{
> +  int i;
> +
> +  for (i = 0; i < N/4; i+=4)
> +    {
> +      res[i] = a[i] >> 8;
> +      res[i+1] = a[i+1] >> 8;
> +      res[i+2] = a[i+2] >> 8;
> +      res[i+3] = a[i+3] >> 8;
> +    }
> +}
> +
> +int
> +main ()
> +{
> +  int i;
> +
> +  for (i = 0; i < N; i++)
> +    a[i] = i;
> +
> +  main1 ();
> +
> +  for (i = 0; i < N; i++)
> +    if (res[i] != a[i] >> 8)
> +      abort ();
> +
> +  return 0;
> +}
> +
> +/* { dg-final { cleanup-tree-dump "vect" } } */
> +
>
>
diff mbox

Patch

Index: tree-vect-slp.c
===================================================================
--- tree-vect-slp.c     (revision 164987)
+++ tree-vect-slp.c     (working copy)
@@ -1894,13 +1894,20 @@  vect_get_constant_vectors (slp_tree slp_
     }

   if (CONSTANT_CLASS_P (op))
-    constant_p = true;
+    {
+      constant_p = true;
+      if (POINTER_TYPE_P (TREE_TYPE (gimple_assign_lhs (stmt))))
+        vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
+      else
+        vector_type = STMT_VINFO_VECTYPE (stmt_vinfo);
+    }
   else
-    constant_p = false;
+    {
+      constant_p = false;
+      vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
+    }

-  vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
   gcc_assert (vector_type);
-
   nunits = TYPE_VECTOR_SUBPARTS (vector_type);

   /* NUMBER_OF_COPIES is the number of times we need to use the same
values in
Index: testsuite/gcc.dg/vect/pr45902.c
===================================================================
--- testsuite/gcc.dg/vect/pr45902.c     (revision 0)
+++ testsuite/gcc.dg/vect/pr45902.c     (revision 0)
@@ -0,0 +1,44 @@ 
+/* { dg-require-effective-target vect_int } */
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include "tree-vect.h"
+
+#define N 128
+
+short res[N];
+short a[N];
+
+int
+main1 ()
+{
+  int i;
+
+  for (i = 0; i < N/4; i+=4)
+    {
+      res[i] = a[i] >> 8;
+      res[i+1] = a[i+1] >> 8;
+      res[i+2] = a[i+2] >> 8;
+      res[i+3] = a[i+3] >> 8;
+    }
+}
+
+int
+main ()
+{
+  int i;
+
+  for (i = 0; i < N; i++)
+    a[i] = i;
+
+  main1 ();
+
+  for (i = 0; i < N; i++)
+    if (res[i] != a[i] >> 8)
+      abort ();
+
+  return 0;
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */

4.5 patch

Index: tree-vect-slp.c
===================================================================
--- tree-vect-slp.c     (revision 165269)
+++ tree-vect-slp.c     (working copy)
@@ -1459,13 +1459,20 @@  vect_get_constant_vectors (slp_tree slp_
     }

   if (CONSTANT_CLASS_P (op))
-    constant_p = true;
+    {
+      constant_p = true;
+      if (POINTER_TYPE_P (TREE_TYPE (gimple_assign_lhs (stmt))))
+        vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
+      else
+        vector_type = STMT_VINFO_VECTYPE (stmt_vinfo);
+    }
   else
-    constant_p = false;
+    {
+      constant_p = false;
+      vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
+    }

-  vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
   gcc_assert (vector_type);
-
   nunits = TYPE_VECTOR_SUBPARTS (vector_type);

   /* NUMBER_OF_COPIES is the number of times we need to use the same
values in
Index: testsuite/gcc.dg/vect/pr45902.c
===================================================================
--- testsuite/gcc.dg/vect/pr45902.c     (revision 0)
+++ testsuite/gcc.dg/vect/pr45902.c     (revision 0)
@@ -0,0 +1,44 @@ 
+/* { dg-require-effective-target vect_int } */
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include "tree-vect.h"
+
+#define N 128
+
+short res[N];
+short a[N];
+
+int
+main1 ()
+{
+  int i;
+
+  for (i = 0; i < N/4; i+=4)
+    {
+      res[i] = a[i] >> 8;
+      res[i+1] = a[i+1] >> 8;
+      res[i+2] = a[i+2] >> 8;
+      res[i+3] = a[i+3] >> 8;
+    }
+}
+
+int
+main ()
+{
+  int i;
+
+  for (i = 0; i < N; i++)
+    a[i] = i;
+
+  main1 ();
+
+  for (i = 0; i < N; i++)
+    if (res[i] != a[i] >> 8)
+      abort ();
+
+  return 0;
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */
+