From 54ff9178dda11f7d5768aa66a1c3df4ff7e80e76 Mon Sep 17 00:00:00 2001 From: dorit Date: Fri, 26 Sep 2008 06:28:01 +0000 Subject: [PATCH] PR tree-optimization/37574 * tree-vectorizer.c (vect_is_simple_use): Fix indentation. * tree-vect-transform.c (vect_get_constant_vectors): Use vectype instead of vector_type for constants. Take computation out of loop. (vect_get_vec_def_for_operand): Use only vectype for constant case, and use only vector_type for invariant case. (get_initial_def_for_reduction): Use vectype instead of vector_type. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@140685 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 10 +++++ gcc/testsuite/ChangeLog | 6 +++ gcc/testsuite/gcc.dg/vect/ggc-pr37574.c | 20 +++++++++ gcc/testsuite/gcc.dg/vect/vect.exp | 6 +++ gcc/tree-vect-transform.c | 77 +++++++++++++++++++-------------- gcc/tree-vectorizer.c | 4 +- 6 files changed, 88 insertions(+), 35 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/ggc-pr37574.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 66031cc..21c6216 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2008-09-26 Dorit Nuzman + + PR tree-optimization/37574 + * tree-vectorizer.c (vect_is_simple_use): Fix indentation. + * tree-vect-transform.c (vect_get_constant_vectors): Use vectype + instead of vector_type for constants. Take computation out of loop. + (vect_get_vec_def_for_operand): Use only vectype for constant case, + and use only vector_type for invariant case. + (get_initial_def_for_reduction): Use vectype instead of vector_type. + 2008-09-25 Jakub Jelinek PR c/37645 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 959ab49..abada34 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2008-09-26 Dorit Nuzman + + PR tree-optimization/37574 + * gcc.dg/vect/ggc-pr37574.c: New test. + * gcc.dg/vect/vect.exp: Compile some tests with ggc flags. + 2008-09-25 Jakub Jelinek PR c/37645 diff --git a/gcc/testsuite/gcc.dg/vect/ggc-pr37574.c b/gcc/testsuite/gcc.dg/vect/ggc-pr37574.c new file mode 100644 index 0000000..b95bfafe1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/ggc-pr37574.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ + +#include + +unsigned short in[40 +128]; +int main (void) { + int i = 0, j = 0; + unsigned int diff; + unsigned int s=0,sum=0; + for (i = 0; i < 40;i++) + { + diff = 0; + for (j = 0; j < 128;j+=8) + diff += in[j+i]; + s += ((unsigned short)diff>>3); + } + if (s != sum) + return -1; + return 0; +} diff --git a/gcc/testsuite/gcc.dg/vect/vect.exp b/gcc/testsuite/gcc.dg/vect/vect.exp index e67b2e4..f7253c6 100644 --- a/gcc/testsuite/gcc.dg/vect/vect.exp +++ b/gcc/testsuite/gcc.dg/vect/vect.exp @@ -242,6 +242,12 @@ lappend DEFAULT_VECTCFLAGS "-Os" dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/Os-vect-*.\[cS\]]] \ "" $DEFAULT_VECTCFLAGS +# With --param ggc-min-expand=0 --param ggc-min-heapsize=0 +set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS +lappend DEFAULT_VECTCFLAGS "--param" "ggc-min-expand=0" "--param" "ggc-min-heapsize=0" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/ggc-*.\[cS\]]] \ + "" $DEFAULT_VECTCFLAGS + # With -O3 set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS lappend DEFAULT_VECTCFLAGS "-O3" diff --git a/gcc/tree-vect-transform.c b/gcc/tree-vect-transform.c index d004aad..3ce3015 100644 --- a/gcc/tree-vect-transform.c +++ b/gcc/tree-vect-transform.c @@ -1401,7 +1401,7 @@ vect_get_constant_vectors (slp_tree slp_node, VEC(tree,heap) **vec_oprnds, gimple stmt = VEC_index (gimple, stmts, 0); stmt_vec_info stmt_vinfo = vinfo_for_stmt (stmt); tree vectype = STMT_VINFO_VECTYPE (stmt_vinfo); - int nunits = TYPE_VECTOR_SUBPARTS (vectype); + int nunits; tree vec_cst; tree t = NULL_TREE; int j, number_of_places_left_in_vector; @@ -1410,12 +1410,33 @@ vect_get_constant_vectors (slp_tree slp_node, VEC(tree,heap) **vec_oprnds, int group_size = VEC_length (gimple, stmts); unsigned int vec_num, i; int number_of_copies = 1; - bool is_store = false; VEC (tree, heap) *voprnds = VEC_alloc (tree, heap, number_of_vectors); - bool constant_p; + bool constant_p, is_store; if (STMT_VINFO_DATA_REF (stmt_vinfo)) - is_store = true; + { + is_store = true; + op = gimple_assign_rhs1 (stmt); + } + else + { + is_store = false; + op = gimple_op (stmt, op_num + 1); + } + + if (CONSTANT_CLASS_P (op)) + { + vector_type = vectype; + constant_p = true; + } + else + { + vector_type = get_vectype_for_scalar_type (TREE_TYPE (op)); + gcc_assert (vector_type); + constant_p = false; + } + + nunits = TYPE_VECTOR_SUBPARTS (vector_type); /* NUMBER_OF_COPIES is the number of times we need to use the same values in created vectors. It is greater than 1 if unrolling is performed. @@ -1436,18 +1457,15 @@ vect_get_constant_vectors (slp_tree slp_node, VEC(tree,heap) **vec_oprnds, number_of_copies = least_common_multiple (nunits, group_size) / group_size; number_of_places_left_in_vector = nunits; - constant_p = true; for (j = 0; j < number_of_copies; j++) { for (i = group_size - 1; VEC_iterate (gimple, stmts, i, stmt); i--) { - if (is_store) - op = gimple_assign_rhs1 (stmt); - else - op = gimple_op (stmt, op_num + 1); - if (!CONSTANT_CLASS_P (op)) - constant_p = false; - + if (is_store) + op = gimple_assign_rhs1 (stmt); + else + op = gimple_op (stmt, op_num + 1); + /* Create 'vect_ = {op0,op1,...,opn}'. */ t = tree_cons (NULL_TREE, op, t); @@ -1457,16 +1475,12 @@ vect_get_constant_vectors (slp_tree slp_node, VEC(tree,heap) **vec_oprnds, { number_of_places_left_in_vector = nunits; - vector_type = get_vectype_for_scalar_type (TREE_TYPE (op)); - gcc_assert (vector_type); if (constant_p) vec_cst = build_vector (vector_type, t); else vec_cst = build_constructor_from_list (vector_type, t); - constant_p = true; VEC_quick_push (tree, voprnds, - vect_init_vector (stmt, vec_cst, vector_type, - NULL)); + vect_init_vector (stmt, vec_cst, vector_type, NULL)); t = NULL_TREE; } } @@ -1886,7 +1900,7 @@ vect_get_vec_def_for_operand (tree op, gimple stmt, tree *scalar_def) stmt_vec_info def_stmt_info = NULL; stmt_vec_info stmt_vinfo = vinfo_for_stmt (stmt); tree vectype = STMT_VINFO_VECTYPE (stmt_vinfo); - int nunits = TYPE_VECTOR_SUBPARTS (vectype); + unsigned int nunits = TYPE_VECTOR_SUBPARTS (vectype); loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_vinfo); tree vec_inv; tree vec_cst; @@ -1935,16 +1949,17 @@ vect_get_vec_def_for_operand (tree op, gimple stmt, tree *scalar_def) { t = tree_cons (NULL_TREE, op, t); } - vector_type = get_vectype_for_scalar_type (TREE_TYPE (op)); - gcc_assert (vector_type); - vec_cst = build_vector (vector_type, t); - - return vect_init_vector (stmt, vec_cst, vector_type, NULL); + vec_cst = build_vector (vectype, t); + return vect_init_vector (stmt, vec_cst, vectype, NULL); } /* Case 2: operand is defined outside the loop - loop invariant. */ case vect_invariant_def: { + vector_type = get_vectype_for_scalar_type (TREE_TYPE (def)); + gcc_assert (vector_type); + nunits = TYPE_VECTOR_SUBPARTS (vector_type); + if (scalar_def) *scalar_def = def; @@ -1958,8 +1973,6 @@ vect_get_vec_def_for_operand (tree op, gimple stmt, tree *scalar_def) } /* FIXME: use build_constructor directly. */ - vector_type = get_vectype_for_scalar_type (TREE_TYPE (def)); - gcc_assert (vector_type); vec_inv = build_constructor_from_list (vector_type, t); return vect_init_vector (stmt, vec_inv, vector_type, NULL); } @@ -2222,6 +2235,7 @@ get_initial_def_for_reduction (gimple stmt, tree init_val, tree *adjustment_def) struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo); tree vectype = STMT_VINFO_VECTYPE (stmt_vinfo); int nunits = TYPE_VECTOR_SUBPARTS (vectype); + tree scalar_type = TREE_TYPE (vectype); enum tree_code code = gimple_assign_rhs_code (stmt); tree type = TREE_TYPE (init_val); tree vecdef; @@ -2229,7 +2243,6 @@ get_initial_def_for_reduction (gimple stmt, tree init_val, tree *adjustment_def) tree init_def; tree t = NULL_TREE; int i; - tree vector_type; bool nested_in_vect_loop = false; gcc_assert (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type) || SCALAR_FLOAT_TYPE_P (type)); @@ -2250,15 +2263,14 @@ get_initial_def_for_reduction (gimple stmt, tree init_val, tree *adjustment_def) else *adjustment_def = init_val; /* Create a vector of zeros for init_def. */ - if (SCALAR_FLOAT_TYPE_P (type)) - def_for_init = build_real (type, dconst0); + if (SCALAR_FLOAT_TYPE_P (scalar_type)) + def_for_init = build_real (scalar_type, dconst0); else - def_for_init = build_int_cst (type, 0); + def_for_init = build_int_cst (scalar_type, 0); + for (i = nunits - 1; i >= 0; --i) t = tree_cons (NULL_TREE, def_for_init, t); - vector_type = get_vectype_for_scalar_type (TREE_TYPE (def_for_init)); - gcc_assert (vector_type); - init_def = build_vector (vector_type, t); + init_def = build_vector (vectype, t); break; case MIN_EXPR: @@ -6008,7 +6020,6 @@ vect_create_mask_and_perm (gimple stmt, gimple next_scalar_stmt, for (i = mask_nunits - 1; i >= 0; --i) t = tree_cons (NULL_TREE, build_int_cst (mask_element_type, mask_array[i]), t); - mask_vec = build_vector (mask_type, t); mask = vect_init_vector (stmt, mask_vec, mask_type, NULL); diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c index 47821e8..9a3a9f3 100644 --- a/gcc/tree-vectorizer.c +++ b/gcc/tree-vectorizer.c @@ -2036,11 +2036,11 @@ vect_is_simple_use (tree operand, loop_vec_info loop_vinfo, gimple *def_stmt, return true; } if (is_gimple_min_invariant (operand)) - { + { *def = operand; *dt = vect_invariant_def; return true; - } + } if (TREE_CODE (operand) == PAREN_EXPR) { -- 2.7.4