From 42373e0b05c26d047925387d71fa833540dad8f0 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Thu, 30 Jun 2011 13:27:43 +0000 Subject: [PATCH] re PR tree-optimization/46787 (Does not vectorize loop with load from scalar variable) 2011-06-30 Richard Guenther PR tree-optimization/46787 * tree-data-ref.c (dr_address_invariant_p): Remove. (find_data_references_in_stmt): Invariant accesses are ok now. * tree-vect-stmts.c (vectorizable_load): Handle invariant loads. * tree-vect-data-refs.c (vect_analyze_data_ref_access): Allow invariant loads. * gcc.dg/vect/vect-121.c: New testcase. From-SVN: r175704 --- gcc/ChangeLog | 10 ++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/vect/vect-121.c | 18 +++++++++++++++++ gcc/tree-data-ref.c | 28 --------------------------- gcc/tree-vect-data-refs.c | 4 ++-- gcc/tree-vect-stmts.c | 29 +++++++--------------------- 6 files changed, 42 insertions(+), 52 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/vect-121.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 17f1cd8681a..6189ef81ca2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2011-06-30 Richard Guenther + + PR tree-optimization/46787 + * tree-data-ref.c (dr_address_invariant_p): Remove. + (find_data_references_in_stmt): Invariant accesses are ok now. + * tree-vect-stmts.c (vectorizable_load): Handle invariant + loads. + * tree-vect-data-refs.c (vect_analyze_data_ref_access): Allow + invariant loads. + 2011-06-30 Martin Jambor PR tree-optimization/49094 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ead74b9055a..ce9314187dd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-06-30 Richard Guenther + + PR tree-optimization/46787 + * gcc.dg/vect/vect-121.c: New testcase. + 2011-06-30 Martin Jambor PR tree-optimization/49094 diff --git a/gcc/testsuite/gcc.dg/vect/vect-121.c b/gcc/testsuite/gcc.dg/vect/vect-121.c new file mode 100644 index 00000000000..9071836c558 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-121.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_float } */ + +float *x; +float parm; +float +test (int start, int end) +{ + int i; + for (i = start; i < end; ++i) + { + float tem = x[i]; + x[i] = parm * tem; + } +} + +/* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c index ebabf61c4db..d58542c91ca 100644 --- a/gcc/tree-data-ref.c +++ b/gcc/tree-data-ref.c @@ -919,21 +919,6 @@ dr_analyze_alias (struct data_reference *dr) } } -/* Returns true if the address of DR is invariant. */ - -static bool -dr_address_invariant_p (struct data_reference *dr) -{ - unsigned i; - tree idx; - - FOR_EACH_VEC_ELT (tree, DR_ACCESS_FNS (dr), i, idx) - if (tree_contains_chrecs (idx, NULL)) - return false; - - return true; -} - /* Frees data reference DR. */ void @@ -4228,19 +4213,6 @@ find_data_references_in_stmt (struct loop *nest, gimple stmt, dr = create_data_ref (nest, loop_containing_stmt (stmt), *ref->pos, stmt, ref->is_read); gcc_assert (dr != NULL); - - /* FIXME -- data dependence analysis does not work correctly for objects - with invariant addresses in loop nests. Let us fail here until the - problem is fixed. */ - if (dr_address_invariant_p (dr) && nest) - { - free_data_ref (dr); - if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, "\tFAILED as dr address is invariant\n"); - ret = false; - break; - } - VEC_safe_push (data_reference_p, heap, *datarefs, dr); } VEC_free (data_ref_loc, heap, references); diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c index 9a2c5b627e5..1a494233088 100644 --- a/gcc/tree-vect-data-refs.c +++ b/gcc/tree-vect-data-refs.c @@ -2302,9 +2302,9 @@ vect_analyze_data_ref_access (struct data_reference *dr) return false; } - /* Don't allow invariant accesses in loops. */ + /* Allow invariant loads in loops. */ if (loop_vinfo && dr_step == 0) - return false; + return DR_IS_READ (dr); if (loop && nested_in_vect_loop_p (loop, stmt)) { diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index 1d334b01b90..0d7d3dbe41d 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -4123,7 +4123,8 @@ vectorizable_load (gimple stmt, gimple_stmt_iterator *gsi, gimple *vec_stmt, && code != COMPONENT_REF && code != IMAGPART_EXPR && code != REALPART_EXPR - && code != MEM_REF) + && code != MEM_REF + && TREE_CODE_CLASS (code) != tcc_declaration) return false; if (!STMT_VINFO_DATA_REF (stmt_info)) @@ -4574,30 +4575,14 @@ vectorizable_load (gimple stmt, gimple_stmt_iterator *gsi, gimple *vec_stmt, if (inv_p && !bb_vinfo) { gcc_assert (!strided_load); - gcc_assert (nested_in_vect_loop_p (loop, stmt)); if (j == 0) { - int k; - tree t = NULL_TREE; - tree vec_inv, bitpos, bitsize = TYPE_SIZE (scalar_type); - - /* CHECKME: bitpos depends on endianess? */ - bitpos = bitsize_zero_node; - vec_inv = build3 (BIT_FIELD_REF, scalar_type, new_temp, - bitsize, bitpos); - vec_dest = vect_create_destination_var (scalar_dest, - NULL_TREE); - new_stmt = gimple_build_assign (vec_dest, vec_inv); - new_temp = make_ssa_name (vec_dest, new_stmt); - gimple_assign_set_lhs (new_stmt, new_temp); - vect_finish_stmt_generation (stmt, new_stmt, gsi); - - for (k = nunits - 1; k >= 0; --k) - t = tree_cons (NULL_TREE, new_temp, t); - /* FIXME: use build_constructor directly. */ - vec_inv = build_constructor_from_list (vectype, t); + tree vec_inv; + gimple_stmt_iterator gsi2 = *gsi; + gsi_next (&gsi2); + vec_inv = build_vector_from_val (vectype, scalar_dest); new_temp = vect_init_vector (stmt, vec_inv, - vectype, gsi); + vectype, &gsi2); new_stmt = SSA_NAME_DEF_STMT (new_temp); } else -- 2.30.2