On Sat, Mar 29, 2014 at 2:26 AM, Cong Hou <co...@google.com> wrote: > This patch is fixing PR60656. Elements in a vector with > vect_used_by_reduction property cannot be reordered if the use chain > with this property does not have the same operation. > > Bootstrapped and tested on a x86-64 machine. > > OK for trunk?
Ok, but please add a comment before the check that explains why we reject this at this point. Thanks, Richard. > > thanks, > Cong > > > diff --git a/gcc/ChangeLog b/gcc/ChangeLog > index e1d8666..d7d5b82 100644 > --- a/gcc/ChangeLog > +++ b/gcc/ChangeLog > @@ -1,3 +1,11 @@ > +2014-03-28 Cong Hou <co...@google.com> > + > + PR tree-optimization/60656 > + * tree-vect-stmts.c (supportable_widening_operation): > + Fix a bug that elements in a vector with vect_used_by_reduction > + property are incorrectly reordered when the operation on it is not > + consistant with the one in reduction operation. > + > 2014-03-10 Jakub Jelinek <ja...@redhat.com> > > PR ipa/60457 > diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog > index 41b6875..414a745 100644 > --- a/gcc/testsuite/ChangeLog > +++ b/gcc/testsuite/ChangeLog > @@ -1,3 +1,8 @@ > +2014-03-28 Cong Hou <co...@google.com> > + > + PR tree-optimization/60656 > + * gcc.dg/vect/pr60656.c: New test. > + > 2014-03-10 Jakub Jelinek <ja...@redhat.com> > > PR ipa/60457 > diff --git a/gcc/testsuite/gcc.dg/vect/pr60656.c > b/gcc/testsuite/gcc.dg/vect/pr60656.c > new file mode 100644 > index 0000000..ebaab62 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/vect/pr60656.c > @@ -0,0 +1,45 @@ > +/* { dg-require-effective-target vect_int } */ > + > +#include "tree-vect.h" > + > +__attribute__ ((noinline)) long > +foo () > +{ > + int v[] = {5000, 5001, 5002, 5003}; > + long s = 0; > + int i; > + > + for(i = 0; i < 4; ++i) > + { > + long P = v[i]; > + s += P*P*P; > + } > + return s; > +} > + > +long > +bar () > +{ > + int v[] = {5000, 5001, 5002, 5003}; > + long s = 0; > + int i; > + > + for(i = 0; i < 4; ++i) > + { > + long P = v[i]; > + s += P*P*P; > + __asm__ volatile (""); > + } > + return s; > +} > + > +int main() > +{ > + if (foo () != bar ()) > + abort (); > + return 0; > +} > + > +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */ > +/* { dg-final { cleanup-tree-dump "vect" } } */ > + > diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c > index 70fb411..7442d0c 100644 > --- a/gcc/tree-vect-stmts.c > +++ b/gcc/tree-vect-stmts.c > @@ -7827,7 +7827,16 @@ supportable_widening_operation (enum tree_code > code, gimple stmt, > stmt, vectype_out, vectype_in, > code1, code2, multi_step_cvt, > interm_types)) > - return true; > + { > + tree lhs = gimple_assign_lhs (stmt); > + use_operand_p dummy; > + gimple use_stmt; > + stmt_vec_info use_stmt_info = NULL; > + if (single_imm_use (lhs, &dummy, &use_stmt) > + && (use_stmt_info = vinfo_for_stmt (use_stmt)) > + && STMT_VINFO_DEF_TYPE (use_stmt_info) == vect_reduction_def) > + return true; > + } > c1 = VEC_WIDEN_MULT_LO_EXPR; > c2 = VEC_WIDEN_MULT_HI_EXPR; > break;