diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e5900bf4cce..564c56f694d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2009-07-13 Ira Rosen + + * tree-vect-loop.c (get_initial_def_for_reduction): Ensure that the + checks access only relevant statements. + (vectorizable_reduction): Likewise. + 2009-07-12 Kai Tietz * config/i386/cygming.h (TARGET_OS_CPP_BUILTINS): Define _X86_ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cb82940f6e7..08989dbf5da 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2009-07-13 Ira Rosen + + * gfortran.dg/vect/vect-6.f: New test. + 2009-07-12 Jason Merrill PR c++/36628 diff --git a/gcc/testsuite/gfortran.dg/vect/vect-6.f b/gcc/testsuite/gfortran.dg/vect/vect-6.f new file mode 100644 index 00000000000..f232dcb82d8 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/vect/vect-6.f @@ -0,0 +1,25 @@ +! { dg-do compile } + + SUBROUTINE PROPAGATE(ICI1,ICI2,I,J,J1,ELEM,NHSO,HSO + * ,MULST,IROOTS) + IMPLICIT DOUBLE PRECISION(A-H,O-Z) + COMPLEX*16 HSO,ELEM + DIMENSION HSO(NHSO,NHSO),MULST(*),IROOTS(*) + ISHIFT=MULST(ICI1)*(I-1)+1 + JSHIFT=MULST(ICI2)*(J-1)+1 + DO 200 ICI=1,ICI1-1 + ISHIFT=ISHIFT+MULST(ICI)*IROOTS(ICI) + 200 CONTINUE + DO 220 ICI=1,ICI2-1 + JSHIFT=JSHIFT+MULST(ICI)*IROOTS(ICI) + 220 CONTINUE + DO 150 MSS=MS,-MS,-2 + IND1=ISHIFT+K + IND2=JSHIFT+K + HSO(IND1,IND2)=ELEM + HSO(IND2,IND1)=DCONJG(ELEM) + 150 CONTINUE + END + +! { dg-final { cleanup-tree-dump "vect" } } + diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index c96fb04a814..1db80e43efd 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -2632,6 +2632,7 @@ get_initial_def_for_reduction (gimple stmt, tree init_val, tree init_value; REAL_VALUE_TYPE real_init_val = dconst0; int int_init_val = 0; + gimple def_stmt = NULL; gcc_assert (vectype); nunits = TYPE_VECTOR_SUBPARTS (vectype); @@ -2647,9 +2648,13 @@ get_initial_def_for_reduction (gimple stmt, tree init_val, /* In case of double reduction we only create a vector variable to be put in the reduction phi node. The actual statement creation is done in vect_create_epilog_for_reduction. */ - if (TREE_CODE (init_val) == SSA_NAME - && vinfo_for_stmt (SSA_NAME_DEF_STMT (init_val)) - && STMT_VINFO_DEF_TYPE (vinfo_for_stmt (SSA_NAME_DEF_STMT (init_val))) + if (adjustment_def && nested_in_vect_loop + && TREE_CODE (init_val) == SSA_NAME + && (def_stmt = SSA_NAME_DEF_STMT (init_val)) + && gimple_code (def_stmt) == GIMPLE_PHI + && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt)) + && vinfo_for_stmt (def_stmt) + && STMT_VINFO_DEF_TYPE (vinfo_for_stmt (def_stmt)) == vect_double_reduction_def) { *adjustment_def = NULL; @@ -3418,11 +3423,13 @@ vectorizable_reduction (gimple stmt, gimple_stmt_iterator *gsi, int reduc_index = 2; bool double_reduc = false, dummy; basic_block def_bb; - struct loop * def_stmt_loop; + struct loop * def_stmt_loop, *outer_loop = NULL; tree def_arg; + gimple def_arg_stmt; if (nested_in_vect_loop_p (loop, stmt)) { + outer_loop = loop; loop = loop->inner; nested_cycle = true; } @@ -3669,15 +3676,21 @@ vectorizable_reduction (gimple stmt, gimple_stmt_iterator *gsi, epilog_reduc_code = ERROR_MARK; } - def_bb = gimple_bb (reduc_def_stmt); - def_stmt_loop = def_bb->loop_father; - def_arg = PHI_ARG_DEF_FROM_EDGE (reduc_def_stmt, - loop_preheader_edge (def_stmt_loop)); - if (TREE_CODE (def_arg) == SSA_NAME - && vinfo_for_stmt (SSA_NAME_DEF_STMT (def_arg)) - && STMT_VINFO_DEF_TYPE (vinfo_for_stmt (SSA_NAME_DEF_STMT (def_arg))) - == vect_double_reduction_def) - double_reduc = true; + if (nested_cycle) + { + def_bb = gimple_bb (reduc_def_stmt); + def_stmt_loop = def_bb->loop_father; + def_arg = PHI_ARG_DEF_FROM_EDGE (reduc_def_stmt, + loop_preheader_edge (def_stmt_loop)); + if (TREE_CODE (def_arg) == SSA_NAME + && (def_arg_stmt = SSA_NAME_DEF_STMT (def_arg)) + && gimple_code (def_arg_stmt) == GIMPLE_PHI + && flow_bb_inside_loop_p (outer_loop, gimple_bb (def_arg_stmt)) + && vinfo_for_stmt (def_arg_stmt) + && STMT_VINFO_DEF_TYPE (vinfo_for_stmt (def_arg_stmt)) + == vect_double_reduction_def) + double_reduc = true; + } if (double_reduc && ncopies > 1) {