* [patch] Fix PR tree-optimization/45902
@ 2010-10-11 12:32 Ira Rosen
2010-10-11 12:56 ` Richard Guenther
0 siblings, 1 reply; 9+ messages in thread
From: Ira Rosen @ 2010-10-11 12:32 UTC (permalink / raw)
To: gcc-patches
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
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" } } */
+
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch] Fix PR tree-optimization/45902
2010-10-11 12:32 [patch] Fix PR tree-optimization/45902 Ira Rosen
@ 2010-10-11 12:56 ` Richard Guenther
2010-10-11 13:05 ` Ira Rosen
0 siblings, 1 reply; 9+ messages in thread
From: Richard Guenther @ 2010-10-11 12:56 UTC (permalink / raw)
To: Ira Rosen; +Cc: gcc-patches
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" } } */
> +
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch] Fix PR tree-optimization/45902
2010-10-11 12:56 ` Richard Guenther
@ 2010-10-11 13:05 ` Ira Rosen
2010-10-11 14:09 ` Richard Guenther
0 siblings, 1 reply; 9+ messages in thread
From: Ira Rosen @ 2010-10-11 13:05 UTC (permalink / raw)
To: Richard Guenther; +Cc: gcc-patches
Richard Guenther <richard.guenther@gmail.com> wrote on 11/10/2010 02:32:08
PM:
>
> 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?
This function creates vectors of constants or loop invariants. If it's a
variable (loop invariant), we know exactly the type, hence the check for
CONSTANT_CLASS_P.
I guess instead of checking the type we can check if it's POINTER_PLUS_EXPR
to catch the cases where we need the operand's type instead of the stmt's
vectype.
Does this make sense?
Index: tree-vect-slp.c
===================================================================
--- tree-vect-slp.c (revision 165302)
+++ tree-vect-slp.c (working copy)
@@ -1836,10 +1836,10 @@ vect_get_constant_vectors (slp_tree slp_
VEC (tree, heap) *voprnds = VEC_alloc (tree, heap, number_of_vectors);
bool constant_p, is_store;
tree neutral_op = NULL;
+ enum tree_code code = gimple_assign_rhs_code (stmt);
if (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def)
{
- enum tree_code code = gimple_assign_rhs_code (stmt);
if (reduc_index == -1)
{
VEC_free (tree, heap, *vec_oprnds);
@@ -1895,18 +1895,14 @@ vect_get_constant_vectors (slp_tree slp_
}
if (CONSTANT_CLASS_P (op))
- {
- 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);
- }
+ constant_p = true;
else
- {
- constant_p = false;
- vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
- }
+ constant_p = false;
+
+ if (code == POINTER_PLUS_EXPR)
+ vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
+ else
+ vector_type = STMT_VINFO_VECTYPE (stmt_vinfo);
gcc_assert (vector_type);
nunits = TYPE_VECTOR_SUBPARTS (vector_type);
Thanks,
Ira
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch] Fix PR tree-optimization/45902
2010-10-11 13:05 ` Ira Rosen
@ 2010-10-11 14:09 ` Richard Guenther
2010-10-11 20:55 ` Ira Rosen
0 siblings, 1 reply; 9+ messages in thread
From: Richard Guenther @ 2010-10-11 14:09 UTC (permalink / raw)
To: Ira Rosen; +Cc: gcc-patches
On Mon, Oct 11, 2010 at 3:03 PM, Ira Rosen <IRAR@il.ibm.com> wrote:
> Richard Guenther <richard.guenther@gmail.com> wrote on 11/10/2010 02:32:08
> PM:
>
>>
>> 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?
>
> This function creates vectors of constants or loop invariants. If it's a
> variable (loop invariant), we know exactly the type, hence the check for
> CONSTANT_CLASS_P.
>
> I guess instead of checking the type we can check if it's POINTER_PLUS_EXPR
> to catch the cases where we need the operand's type instead of the stmt's
> vectype.
>
> Does this make sense?
That makes more sense, with ...
> Index: tree-vect-slp.c
> ===================================================================
> --- tree-vect-slp.c (revision 165302)
> +++ tree-vect-slp.c (working copy)
> @@ -1836,10 +1836,10 @@ vect_get_constant_vectors (slp_tree slp_
> VEC (tree, heap) *voprnds = VEC_alloc (tree, heap, number_of_vectors);
> bool constant_p, is_store;
> tree neutral_op = NULL;
> + enum tree_code code = gimple_assign_rhs_code (stmt);
>
> if (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def)
> {
> - enum tree_code code = gimple_assign_rhs_code (stmt);
> if (reduc_index == -1)
> {
> VEC_free (tree, heap, *vec_oprnds);
> @@ -1895,18 +1895,14 @@ vect_get_constant_vectors (slp_tree slp_
> }
>
> if (CONSTANT_CLASS_P (op))
> - {
> - 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);
> - }
> + constant_p = true;
> else
> - {
> - constant_p = false;
> - vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
> - }
> + constant_p = false;
> +
> + if (code == POINTER_PLUS_EXPR)
checking
&& op_num == 2
(with a possible fixup for the reduction case where that doesn't seem to
be prevailing).
Thanks,
Richard.
> + vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
> + else
> + vector_type = STMT_VINFO_VECTYPE (stmt_vinfo);
>
> gcc_assert (vector_type);
> nunits = TYPE_VECTOR_SUBPARTS (vector_type);
>
> Thanks,
> Ira
>
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch] Fix PR tree-optimization/45902
2010-10-11 14:09 ` Richard Guenther
@ 2010-10-11 20:55 ` Ira Rosen
2010-10-12 10:13 ` Richard Guenther
0 siblings, 1 reply; 9+ messages in thread
From: Ira Rosen @ 2010-10-11 20:55 UTC (permalink / raw)
To: Richard Guenther; +Cc: gcc-patches
Richard Guenther <richard.guenther@gmail.com> wrote on 11/10/2010 04:03:07
PM:
>
> On Mon, Oct 11, 2010 at 3:03 PM, Ira Rosen <IRAR@il.ibm.com> wrote:
> > Richard Guenther <richard.guenther@gmail.com> wrote on 11/10/2010
02:32:08
> > PM:
> >
> >>
> >> 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?
> >
> > This function creates vectors of constants or loop invariants. If it's
a
> > variable (loop invariant), we know exactly the type, hence the check
for
> > CONSTANT_CLASS_P.
> >
> > I guess instead of checking the type we can check if it's
POINTER_PLUS_EXPR
> > to catch the cases where we need the operand's type instead of the
stmt's
> > vectype.
> >
> > Does this make sense?
>
> That makes more sense, with ...
>
> > Index: tree-vect-slp.c
> > ===================================================================
> > --- tree-vect-slp.c (revision 165302)
> > +++ tree-vect-slp.c (working copy)
> > @@ -1836,10 +1836,10 @@ vect_get_constant_vectors (slp_tree slp_
> > VEC (tree, heap) *voprnds = VEC_alloc (tree, heap,
number_of_vectors);
> > bool constant_p, is_store;
> > tree neutral_op = NULL;
> > + enum tree_code code = gimple_assign_rhs_code (stmt);
> >
> > if (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def)
> > {
> > - enum tree_code code = gimple_assign_rhs_code (stmt);
> > if (reduc_index == -1)
> > {
> > VEC_free (tree, heap, *vec_oprnds);
> > @@ -1895,18 +1895,14 @@ vect_get_constant_vectors (slp_tree slp_
> > }
> >
> > if (CONSTANT_CLASS_P (op))
> > - {
> > - 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);
> > - }
> > + constant_p = true;
> > else
> > - {
> > - constant_p = false;
> > - vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
> > - }
> > + constant_p = false;
> > +
> > + if (code == POINTER_PLUS_EXPR)
>
> checking
>
> && op_num == 2
But if it's the first operand then its type is the type of the stmt, i.e.,
we get the same type anyway, right?
Thanks,
Ira
>
> (with a possible fixup for the reduction case where that doesn't seem to
> be prevailing).
>
> Thanks,
> Richard.
>
> > + vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
> > + else
> > + vector_type = STMT_VINFO_VECTYPE (stmt_vinfo);
> >
> > gcc_assert (vector_type);
> > nunits = TYPE_VECTOR_SUBPARTS (vector_type);
> >
> > Thanks,
> > Ira
> >
> >
> >
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch] Fix PR tree-optimization/45902
2010-10-11 20:55 ` Ira Rosen
@ 2010-10-12 10:13 ` Richard Guenther
2010-10-13 7:52 ` Ira Rosen
0 siblings, 1 reply; 9+ messages in thread
From: Richard Guenther @ 2010-10-12 10:13 UTC (permalink / raw)
To: Ira Rosen; +Cc: gcc-patches
On Mon, Oct 11, 2010 at 10:48 PM, Ira Rosen <IRAR@il.ibm.com> wrote:
>
>
> Richard Guenther <richard.guenther@gmail.com> wrote on 11/10/2010 04:03:07
> PM:
>
>>
>> On Mon, Oct 11, 2010 at 3:03 PM, Ira Rosen <IRAR@il.ibm.com> wrote:
>> > Richard Guenther <richard.guenther@gmail.com> wrote on 11/10/2010
> 02:32:08
>> > PM:
>> >
>> >>
>> >> 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?
>> >
>> > This function creates vectors of constants or loop invariants. If it's
> a
>> > variable (loop invariant), we know exactly the type, hence the check
> for
>> > CONSTANT_CLASS_P.
>> >
>> > I guess instead of checking the type we can check if it's
> POINTER_PLUS_EXPR
>> > to catch the cases where we need the operand's type instead of the
> stmt's
>> > vectype.
>> >
>> > Does this make sense?
>>
>> That makes more sense, with ...
>>
>> > Index: tree-vect-slp.c
>> > ===================================================================
>> > --- tree-vect-slp.c (revision 165302)
>> > +++ tree-vect-slp.c (working copy)
>> > @@ -1836,10 +1836,10 @@ vect_get_constant_vectors (slp_tree slp_
>> > VEC (tree, heap) *voprnds = VEC_alloc (tree, heap,
> number_of_vectors);
>> > bool constant_p, is_store;
>> > tree neutral_op = NULL;
>> > + enum tree_code code = gimple_assign_rhs_code (stmt);
>> >
>> > if (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def)
>> > {
>> > - enum tree_code code = gimple_assign_rhs_code (stmt);
>> > if (reduc_index == -1)
>> > {
>> > VEC_free (tree, heap, *vec_oprnds);
>> > @@ -1895,18 +1895,14 @@ vect_get_constant_vectors (slp_tree slp_
>> > }
>> >
>> > if (CONSTANT_CLASS_P (op))
>> > - {
>> > - 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);
>> > - }
>> > + constant_p = true;
>> > else
>> > - {
>> > - constant_p = false;
>> > - vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
>> > - }
>> > + constant_p = false;
>> > +
>> > + if (code == POINTER_PLUS_EXPR)
>>
>> checking
>>
>> && op_num == 2
>
> But if it's the first operand then its type is the type of the stmt, i.e.,
> we get the same type anyway, right?
Yes. So your patch looks ok, possibly with a comment that looking
at either operand is ok.
Thanks,
Richard.
> Thanks,
> Ira
>
>>
>> (with a possible fixup for the reduction case where that doesn't seem to
>> be prevailing).
>>
>> Thanks,
>> Richard.
>>
>> > + vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
>> > + else
>> > + vector_type = STMT_VINFO_VECTYPE (stmt_vinfo);
>> >
>> > gcc_assert (vector_type);
>> > nunits = TYPE_VECTOR_SUBPARTS (vector_type);
>> >
>> > Thanks,
>> > Ira
>> >
>> >
>> >
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch] Fix PR tree-optimization/45902
2010-10-12 10:13 ` Richard Guenther
@ 2010-10-13 7:52 ` Ira Rosen
2010-10-16 18:48 ` H.J. Lu
0 siblings, 1 reply; 9+ messages in thread
From: Ira Rosen @ 2010-10-13 7:52 UTC (permalink / raw)
To: Richard Guenther; +Cc: gcc-patches
Richard Guenther <richard.guenther@gmail.com> wrote on 12/10/2010 12:08:31
PM:
> >
> > But if it's the first operand then its type is the type of the stmt,
i.e.,
> > we get the same type anyway, right?
>
> Yes. So your patch looks ok, possibly with a comment that looking
> at either operand is ok.
>
I committed the following:
* tree-vect-slp.c (vect_get_constant_vectors): Fix comment.
Use operand's type for POINTER_PLUS_EXPR.
Index: tree-vect-slp.c
===================================================================
--- tree-vect-slp.c (revision 165411)
+++ tree-vect-slp.c (working copy)
@@ -1811,8 +1811,8 @@ vect_update_slp_costs_according_to_vf (l
/* For constant and loop invariant defs of SLP_NODE this function returns
(vector) defs (VEC_OPRNDS) that will be used in the vectorized stmts.
- OP_NUM determines if we gather defs for operand 0 or operand 1 of the
scalar
- stmts. NUMBER_OF_VECTORS is the number of vector defs to create.
+ OP_NUM determines if we gather defs for operand 0 or operand 1 of the
RHS of
+ scalar stmts. NUMBER_OF_VECTORS is the number of vector defs to
create.
REDUC_INDEX is the index of the reduction operand in the statements,
unless
it is -1. */
@@ -1836,10 +1836,10 @@ vect_get_constant_vectors (slp_tree slp_
VEC (tree, heap) *voprnds = VEC_alloc (tree, heap, number_of_vectors);
bool constant_p, is_store;
tree neutral_op = NULL;
+ enum tree_code code = gimple_assign_rhs_code (stmt);
if (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def)
{
- enum tree_code code = gimple_assign_rhs_code (stmt);
if (reduc_index == -1)
{
VEC_free (tree, heap, *vec_oprnds);
@@ -1895,18 +1895,18 @@ vect_get_constant_vectors (slp_tree slp_
}
if (CONSTANT_CLASS_P (op))
- {
- 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);
- }
+ constant_p = true;
else
- {
- constant_p = false;
- vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
- }
+ constant_p = false;
+
+ /* For POINTER_PLUS_EXPR we use the type of the constant/invariant
itself.
+ If OP is the first operand of POINTER_PLUS_EXPR, its type is the type
of
+ the statement, so it's OK to use OP's type for both first and second
+ operands. */
+ if (code == POINTER_PLUS_EXPR)
+ vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
+ else
+ vector_type = STMT_VINFO_VECTYPE (stmt_vinfo);
gcc_assert (vector_type);
nunits = TYPE_VECTOR_SUBPARTS (vector_type);
And here is an updated patch for 4.5.
Bootstrapped and tested on x86_64-suse-linux.
OK to commit?
Thanks,
Ira
ChangeLog:
PR tree-optimization/45902
* tree-vect-slp.c (vect_get_constant_vectors): Use operand's type
for POINTER_PLUS_EXPR.
testsuite/ChangeLog:
PR tree-optimization/45902
* gcc.dg/vect/45902.c: New test.
Index: tree-vect-slp.c
===================================================================
--- tree-vect-slp.c (revision 165366)
+++ tree-vect-slp.c (working copy)
@@ -1446,6 +1446,7 @@ vect_get_constant_vectors (slp_tree slp_
int number_of_copies = 1;
VEC (tree, heap) *voprnds = VEC_alloc (tree, heap, number_of_vectors);
bool constant_p, is_store;
+ enum tree_code code = gimple_assign_rhs_code (stmt);
if (STMT_VINFO_DATA_REF (stmt_vinfo))
{
@@ -1463,9 +1464,16 @@ vect_get_constant_vectors (slp_tree slp_
else
constant_p = false;
- vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
- gcc_assert (vector_type);
+ /* For POINTER_PLUS_EXPR we use the type of the constant/invariant
itself.
+ If OP is the first operand of POINTER_PLUS_EXPR, its type is the type
of
+ the statement, so it's OK to use OP's type for both first and second
+ operands. */
+ if (code == POINTER_PLUS_EXPR)
+ vector_type = get_vectype_for_scalar_type (TREE_TYPE (op));
+ else
+ vector_type = STMT_VINFO_VECTYPE (stmt_vinfo);
+ 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,43 @@
+/* { 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" } } */
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch] Fix PR tree-optimization/45902
2010-10-13 7:52 ` Ira Rosen
@ 2010-10-16 18:48 ` H.J. Lu
2010-10-17 0:30 ` H.J. Lu
0 siblings, 1 reply; 9+ messages in thread
From: H.J. Lu @ 2010-10-16 18:48 UTC (permalink / raw)
To: Ira Rosen; +Cc: Richard Guenther, gcc-patches
On Wed, Oct 13, 2010 at 12:43 AM, Ira Rosen <IRAR@il.ibm.com> wrote:
>
>
> Richard Guenther <richard.guenther@gmail.com> wrote on 12/10/2010 12:08:31
> PM:
>
>> >
>> > But if it's the first operand then its type is the type of the stmt,
> i.e.,
>> > we get the same type anyway, right?
>>
>> Yes. So your patch looks ok, possibly with a comment that looking
>> at either operand is ok.
>>
>
> I committed the following:
>
> * tree-vect-slp.c (vect_get_constant_vectors): Fix comment.
> Use operand's type for POINTER_PLUS_EXPR.
>
>
This caused:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46049
--
H.J.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch] Fix PR tree-optimization/45902
2010-10-16 18:48 ` H.J. Lu
@ 2010-10-17 0:30 ` H.J. Lu
0 siblings, 0 replies; 9+ messages in thread
From: H.J. Lu @ 2010-10-17 0:30 UTC (permalink / raw)
To: Ira Rosen; +Cc: Richard Guenther, gcc-patches
On Sat, Oct 16, 2010 at 10:45 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, Oct 13, 2010 at 12:43 AM, Ira Rosen <IRAR@il.ibm.com> wrote:
>>
>>
>> Richard Guenther <richard.guenther@gmail.com> wrote on 12/10/2010 12:08:31
>> PM:
>>
>>> >
>>> > But if it's the first operand then its type is the type of the stmt,
>> i.e.,
>>> > we get the same type anyway, right?
>>>
>>> Yes. So your patch looks ok, possibly with a comment that looking
>>> at either operand is ok.
>>>
>>
>> I committed the following:
>>
>> * tree-vect-slp.c (vect_get_constant_vectors): Fix comment.
>> Use operand's type for POINTER_PLUS_EXPR.
>>
>>
>
> This caused:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46049
>
>
It also caused:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46052
--
H.J.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-10-16 23:15 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-11 12:32 [patch] Fix PR tree-optimization/45902 Ira Rosen
2010-10-11 12:56 ` Richard Guenther
2010-10-11 13:05 ` Ira Rosen
2010-10-11 14:09 ` Richard Guenther
2010-10-11 20:55 ` Ira Rosen
2010-10-12 10:13 ` Richard Guenther
2010-10-13 7:52 ` Ira Rosen
2010-10-16 18:48 ` H.J. Lu
2010-10-17 0:30 ` H.J. Lu
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).