From 54269f054f818c6bc958242809b5f766dc758cf4 Mon Sep 17 00:00:00 2001 From: Ira Rosen Date: Mon, 16 Jun 2008 10:39:07 +0000 Subject: re PR tree-optimization/36493 (vectorizer aliasing bug) PR tree-optimization/36493 * tree-vect-transform.c (vect_create_data_ref_ptr): Remove TYPE from the arguments list. Use VECTYPE to create vector pointer. (vectorizable_store): Fail if accesses through a pointer to vectype do not alias the original memory reference operands. Call vect_create_data_ref_ptr without the removed argument. (vectorizable_load): Likewise. (vect_setup_realignment): Call vect_create_data_ref_ptr without the removed argument. From-SVN: r136843 --- gcc/ChangeLog | 12 +++++++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/vect/pr36493.c | 23 +++++++++++++++++ gcc/tree-vect-transform.c | 49 ++++++++++++++++++++++++++++--------- 4 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr36493.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 777743a..6b6a931 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2008-06-16 Ira Rosen + + PR tree-optimization/36493 + * tree-vect-transform.c (vect_create_data_ref_ptr): Remove TYPE from + the arguments list. Use VECTYPE to create vector pointer. + (vectorizable_store): Fail if accesses through a pointer to vectype + do not alias the original memory reference operands. + Call vect_create_data_ref_ptr without the removed argument. + (vectorizable_load): Likewise. + (vect_setup_realignment): Call vect_create_data_ref_ptr without the + removed argument. + 2008-06-015 Andy Hutchinson PR target/36336 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6084985..e97e60b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-06-16 Ira Rosen + + PR tree-optimization/36493 + * gcc.dg/vect/pr36493.c: New testcase. + 2008-06-15 Jerry DeLisle PR fortran/36515 diff --git a/gcc/testsuite/gcc.dg/vect/pr36493.c b/gcc/testsuite/gcc.dg/vect/pr36493.c new file mode 100644 index 0000000..d96e962 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr36493.c @@ -0,0 +1,23 @@ +/* { dg-require-effective-target vect_int } */ + +#include "tree-vect.h" + +int +main (void) +{ + int i; + long x[12] __attribute__((aligned(16))); + + x[0] = 1; + for (i = 0; i < 12; i++) + x[i] = i; + + if (x[0] != 0) + 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-transform.c b/gcc/tree-vect-transform.c index 450af30..4110b335 100644 --- a/gcc/tree-vect-transform.c +++ b/gcc/tree-vect-transform.c @@ -49,7 +49,7 @@ along with GCC; see the file COPYING3. If not see static bool vect_transform_stmt (tree, block_stmt_iterator *, bool *, slp_tree); static tree vect_create_destination_var (tree, tree); static tree vect_create_data_ref_ptr - (tree, struct loop*, tree, tree *, tree *, bool, tree, bool *); + (tree, struct loop*, tree, tree *, tree *, bool, bool *); static tree vect_create_addr_base_for_vector_ref (tree, tree *, tree, struct loop *); static tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *); @@ -951,7 +951,6 @@ vect_create_addr_base_for_vector_ref (tree stmt, by the data-ref in STMT. 4. ONLY_INIT: indicate if vp is to be updated in the loop, or remain pointing to the initial address. - 5. TYPE: if not NULL indicates the required type of the data-ref Output: 1. Declare a new ptr to vector_type, and have it point to the base of the @@ -981,7 +980,7 @@ vect_create_addr_base_for_vector_ref (tree stmt, static tree vect_create_data_ref_ptr (tree stmt, struct loop *at_loop, tree offset, tree *initial_address, tree *ptr_incr, - bool only_init, tree type, bool *inv_p) + bool only_init, bool *inv_p) { tree base_name; stmt_vec_info stmt_info = vinfo_for_stmt (stmt); @@ -1040,10 +1039,8 @@ vect_create_data_ref_ptr (tree stmt, struct loop *at_loop, } /** (1) Create the new vector-pointer variable: **/ - if (type) - vect_ptr_type = build_pointer_type (type); - else - vect_ptr_type = build_pointer_type (vectype); + vect_ptr_type = build_pointer_type (vectype); + vect_ptr = vect_get_new_vect_var (vect_ptr_type, vect_pointer_var, get_name (base_name)); add_referenced_var (vect_ptr); @@ -4756,6 +4753,24 @@ vectorizable_store (tree stmt, block_stmt_iterator *bsi, tree *vec_stmt, return false; } + /* If accesses through a pointer to vectype do not alias the original + memory reference we have a problem. */ + if (get_alias_set (vectype) != get_alias_set (TREE_TYPE (scalar_dest)) + && !alias_set_subset_of (get_alias_set (vectype), + get_alias_set (TREE_TYPE (scalar_dest)))) + { + if (vect_print_dump_info (REPORT_DETAILS)) + fprintf (vect_dump, "vector type does not alias scalar type"); + return false; + } + + if (!useless_type_conversion_p (TREE_TYPE (op), TREE_TYPE (scalar_dest))) + { + if (vect_print_dump_info (REPORT_DETAILS)) + fprintf (vect_dump, "operands of different types"); + return false; + } + vec_mode = TYPE_MODE (vectype); /* FORNOW. In some cases can vectorize even if data-type not supported (e.g. - array initialization with 0). */ @@ -4930,9 +4945,10 @@ vectorizable_store (tree stmt, block_stmt_iterator *bsi, tree *vec_stmt, next_stmt = DR_GROUP_NEXT_DR (vinfo_for_stmt (next_stmt)); } } + dataref_ptr = vect_create_data_ref_ptr (first_stmt, NULL, NULL_TREE, - &dummy, &ptr_incr, false, - TREE_TYPE (vec_oprnd), &inv_p); + &dummy, &ptr_incr, false, + &inv_p); gcc_assert (!inv_p); } else @@ -5170,7 +5186,7 @@ vect_setup_realignment (tree stmt, block_stmt_iterator *bsi, pe = loop_preheader_edge (loop_for_initial_load); vec_dest = vect_create_destination_var (scalar_dest, vectype); ptr = vect_create_data_ref_ptr (stmt, loop_for_initial_load, NULL_TREE, - &init_addr, &inc, true, NULL_TREE, &inv_p); + &init_addr, &inc, true, &inv_p); data_ref = build1 (ALIGN_INDIRECT_REF, vectype, ptr); new_stmt = build_gimple_modify_stmt (vec_dest, data_ref); new_temp = make_ssa_name (vec_dest, new_stmt); @@ -5619,6 +5635,17 @@ vectorizable_load (tree stmt, block_stmt_iterator *bsi, tree *vec_stmt, return false; } + /* If accesses through a pointer to vectype do not alias the original + memory reference we have a problem. */ + if (get_alias_set (vectype) != get_alias_set (scalar_type) + && !alias_set_subset_of (get_alias_set (vectype), + get_alias_set (scalar_type))) + { + if (vect_print_dump_info (REPORT_DETAILS)) + fprintf (vect_dump, "vector type does not alias scalar type"); + return false; + } + /* Check if the load is a part of an interleaving chain. */ if (STMT_VINFO_STRIDED_ACCESS (stmt_info)) { @@ -5811,7 +5838,7 @@ vectorizable_load (tree stmt, block_stmt_iterator *bsi, tree *vec_stmt, dataref_ptr = vect_create_data_ref_ptr (first_stmt, at_loop, offset, &dummy, &ptr_incr, false, - NULL_TREE, &inv_p); + &inv_p); else dataref_ptr = bump_vector_ptr (dataref_ptr, ptr_incr, bsi, stmt, NULL_TREE); -- cgit v1.1