This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix fallout of PR37491 fix


This fixes the fallout from the fix for PR37491.  The vectorizer
disregards restrict qualification from the original data-ref pointer
if building the vectorized data pointer.  The following patch fixes
that and makes sure to initialize and copy DECL_POINTER_ALIAS_SET
(otherwise the alias machinery will break down, as using alias sets
for restrict vs. non-restrict pointers isn't really ok).

It also moves the alias sanity checks to where they actually belong,
so we can test the new reference vs. the original reference.  But
this means the check is now an assert as we cannot safely abort
vectorization there.

Bootstrapped on x86_64-unknown-linux-gnu, tested with -m64 and -m32.
Ira is testing ppc currently.

Richard.

2008-09-22  Richard Guenther  <rguenther@suse.de>

	PR middle-end/37491
	* tree-vect-transform.c (vect_create_data_ref_ptr): Properly
	build restrict-qualified pointers.
	(vectorizable_store): Move alias check later.
	(vectorizable_load): Likewise.

Index: gcc/tree-vect-transform.c
===================================================================
*** gcc/tree-vect-transform.c	(revision 140546)
--- gcc/tree-vect-transform.c	(working copy)
*************** vect_create_data_ref_ptr (gimple stmt, s
*** 1077,1084 ****
--- 1077,1095 ----
    else
      vect_ptr_type = build_pointer_type (vectype);
  
+   if (TREE_CODE (DR_BASE_ADDRESS (dr)) == SSA_NAME
+       && TYPE_RESTRICT (TREE_TYPE (DR_BASE_ADDRESS (dr))))
+     vect_ptr_type = build_qualified_type (vect_ptr_type, TYPE_QUAL_RESTRICT);
    vect_ptr = vect_get_new_vect_var (vect_ptr_type, vect_pointer_var,
                                      get_name (base_name));
+   if (TREE_CODE (DR_BASE_ADDRESS (dr)) == SSA_NAME
+       && TYPE_RESTRICT (TREE_TYPE (DR_BASE_ADDRESS (dr))))
+     {
+       get_alias_set (base_name);
+       DECL_POINTER_ALIAS_SET (vect_ptr)
+ 	= DECL_POINTER_ALIAS_SET (SSA_NAME_VAR (DR_BASE_ADDRESS (dr)));
+     }
+ 
    add_referenced_var (vect_ptr);
  
    /** (2) Add aliasing information to the new vector-pointer:
*************** vect_create_data_ref_ptr (gimple stmt, s
*** 1175,1181 ****
  
        create_iv (vect_ptr_init,
  		 fold_convert (vect_ptr_type, step),
! 		 NULL_TREE, loop, &incr_gsi, insert_after,
  		 &indx_before_incr, &indx_after_incr);
        incr = gsi_stmt (incr_gsi);
        set_vinfo_for_stmt (incr, new_stmt_vec_info (incr, loop_vinfo));
--- 1186,1192 ----
  
        create_iv (vect_ptr_init,
  		 fold_convert (vect_ptr_type, step),
! 		 vect_ptr, loop, &incr_gsi, insert_after,
  		 &indx_before_incr, &indx_after_incr);
        incr = gsi_stmt (incr_gsi);
        set_vinfo_for_stmt (incr, new_stmt_vec_info (incr, loop_vinfo));
*************** vect_create_data_ref_ptr (gimple stmt, s
*** 1206,1212 ****
      {
        standard_iv_increment_position (containing_loop, &incr_gsi,
  				      &insert_after);
!       create_iv (vptr, fold_convert (vect_ptr_type, DR_STEP (dr)), NULL_TREE, 
  		 containing_loop, &incr_gsi, insert_after, &indx_before_incr,
  		 &indx_after_incr);
        incr = gsi_stmt (incr_gsi);
--- 1217,1223 ----
      {
        standard_iv_increment_position (containing_loop, &incr_gsi,
  				      &insert_after);
!       create_iv (vptr, fold_convert (vect_ptr_type, DR_STEP (dr)), vect_ptr, 
  		 containing_loop, &incr_gsi, insert_after, &indx_before_incr,
  		 &indx_after_incr);
        incr = gsi_stmt (incr_gsi);
*************** vectorizable_store (gimple stmt, gimple_
*** 5178,5194 ****
        return false;
      }
  
-   /* If accesses through a pointer to vectype do not alias the original
-      memory reference we have a problem.  This should never be the case.  */
-   if (get_alias_set (vectype) != get_alias_set (scalar_dest)
-       && !alias_set_subset_of (get_alias_set (vectype), 
-                                get_alias_set (scalar_dest)))
-     {
-       if (vect_print_dump_info (REPORT_DETAILS))
-         fprintf (vect_dump, "???  vector type does not alias scalar type");
-       return false;
-     }
- 
    /* The scalar rhs type needs to be trivially convertible to the vector
       component type.  This should always be the case.  */
    if (!useless_type_conversion_p (TREE_TYPE (vectype), TREE_TYPE (op)))
--- 5189,5194 ----
*************** vectorizable_store (gimple stmt, gimple_
*** 5428,5433 ****
--- 5428,5439 ----
  	    vec_oprnd = VEC_index (tree, result_chain, i);
  
  	  data_ref = build_fold_indirect_ref (dataref_ptr);
+ 	  /* If accesses through a pointer to vectype do not alias the original
+ 	     memory reference we have a problem.  This should never happen.  */
+ 	  gcc_assert (get_alias_set (data_ref) == get_alias_set (gimple_assign_lhs (stmt))
+ 		      || alias_set_subset_of (get_alias_set (data_ref), 
+ 					      get_alias_set (gimple_assign_lhs (stmt))));
+ 
  	  /* Arguments are ready. Create the new vector stmt.  */
  	  new_stmt = gimple_build_assign (data_ref, vec_oprnd);
  	  vect_finish_stmt_generation (stmt, new_stmt, gsi);
*************** vectorizable_load (gimple stmt, gimple_s
*** 6388,6404 ****
        return false;
      }
  
-   /* If accesses through a pointer to vectype do not alias the original
-      memory reference we have a problem.  This should never happen.  */
-   if (get_alias_set (vectype) != get_alias_set (gimple_assign_rhs1 (stmt))
-       && !alias_set_subset_of (get_alias_set (vectype),
-                                get_alias_set (gimple_assign_rhs1 (stmt))))
-     {
-       if (vect_print_dump_info (REPORT_DETAILS))
-         fprintf (vect_dump, "???  vector type does not alias scalar type");
-       return false;
-     }
- 
    /* The vector component type needs to be trivially convertible to the
       scalar lhs.  This should always be the case.  */
    if (!useless_type_conversion_p (TREE_TYPE (scalar_dest), TREE_TYPE (vectype)))
--- 6394,6399 ----
*************** vectorizable_load (gimple stmt, gimple_s
*** 6662,6667 ****
--- 6657,6667 ----
  	    default:
  	      gcc_unreachable ();
  	    }
+ 	  /* If accesses through a pointer to vectype do not alias the original
+ 	     memory reference we have a problem.  This should never happen.  */
+ 	  gcc_assert (get_alias_set (data_ref) == get_alias_set (gimple_assign_rhs1 (stmt))
+ 		      || alias_set_subset_of (get_alias_set (data_ref),
+ 					      get_alias_set (gimple_assign_rhs1 (stmt))));
  	  vec_dest = vect_create_destination_var (scalar_dest, vectype);
  	  new_stmt = gimple_build_assign (vec_dest, data_ref);
  	  new_temp = make_ssa_name (vec_dest, new_stmt);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]