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] Vectorizer TLC


The following makes us create less useless statements (as can be seen
from the needed change to recip-vec-sqrtf-avx.c where we now fully
unroll one of the loops).

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2015-06-16  Richard Biener  <rguenther@suse.de>

	* tree-vect-stmts.c (vectorizable_store): Adjust.
	(vectorizable_load): Likewise.
	* tree-vect-data-refs.c (vect_create_addr_base_for_vector_ref):
	Simplify.
	(vect_create_data_ref_ptr): Likewise.
	(bump_vector_ptr): Adjust.

	* gcc.target/i386/recip-vec-sqrtf-avx.c: Disable unrolling.

Index: gcc/tree-vect-stmts.c
===================================================================
*** gcc/tree-vect-stmts.c	(revision 224324)
--- gcc/tree-vect-stmts.c	(working copy)
*************** vectorizable_store (gimple stmt, gimple_
*** 5572,5582 ****
  		   vect_permute_store_chain().  */
  		vec_oprnd = result_chain[i];
  
! 	      data_ref = build2 (MEM_REF, TREE_TYPE (vec_oprnd), dataref_ptr,
! 				 dataref_offset
! 				 ? dataref_offset
! 				 : build_int_cst (reference_alias_ptr_type
! 						  (DR_REF (first_dr)), 0));
  	      align = TYPE_ALIGN_UNIT (vectype);
  	      if (aligned_access_p (first_dr))
  		misalign = 0;
--- 5572,5583 ----
  		   vect_permute_store_chain().  */
  		vec_oprnd = result_chain[i];
  
! 	      data_ref = fold_build2 (MEM_REF, TREE_TYPE (vec_oprnd),
! 				      dataref_ptr,
! 				      dataref_offset
! 				      ? dataref_offset
! 				      : build_int_cst (reference_alias_ptr_type
! 						       (DR_REF (first_dr)), 0));
  	      align = TYPE_ALIGN_UNIT (vectype);
  	      if (aligned_access_p (first_dr))
  		misalign = 0;
*************** vectorizable_store (gimple stmt, gimple_
*** 5595,5601 ****
  					  TYPE_ALIGN (elem_type));
  		  misalign = DR_MISALIGNMENT (first_dr);
  		}
! 	      if (dataref_offset == NULL_TREE)
  		set_ptr_info_alignment (get_ptr_info (dataref_ptr), align,
  					misalign);
  
--- 5596,5603 ----
  					  TYPE_ALIGN (elem_type));
  		  misalign = DR_MISALIGNMENT (first_dr);
  		}
! 	      if (dataref_offset == NULL_TREE
! 		  && TREE_CODE (dataref_ptr) == SSA_NAME)
  		set_ptr_info_alignment (get_ptr_info (dataref_ptr), align,
  					misalign);
  
*************** vectorizable_load (gimple stmt, gimple_s
*** 6637,6647 ****
  		    unsigned int align, misalign;
  
  		    data_ref
! 		      = build2 (MEM_REF, vectype, dataref_ptr,
! 				dataref_offset
! 				? dataref_offset
! 				: build_int_cst (reference_alias_ptr_type
! 						 (DR_REF (first_dr)), 0));
  		    align = TYPE_ALIGN_UNIT (vectype);
  		    if (alignment_support_scheme == dr_aligned)
  		      {
--- 6645,6655 ----
  		    unsigned int align, misalign;
  
  		    data_ref
! 		      = fold_build2 (MEM_REF, vectype, dataref_ptr,
! 				     dataref_offset
! 				     ? dataref_offset
! 				     : build_int_cst (reference_alias_ptr_type
! 						      (DR_REF (first_dr)), 0));
  		    align = TYPE_ALIGN_UNIT (vectype);
  		    if (alignment_support_scheme == dr_aligned)
  		      {
*************** vectorizable_load (gimple stmt, gimple_s
*** 6663,6669 ****
  						TYPE_ALIGN (elem_type));
  			misalign = DR_MISALIGNMENT (first_dr);
  		      }
! 		    if (dataref_offset == NULL_TREE)
  		      set_ptr_info_alignment (get_ptr_info (dataref_ptr),
  					      align, misalign);
  		    break;
--- 6671,6678 ----
  						TYPE_ALIGN (elem_type));
  			misalign = DR_MISALIGNMENT (first_dr);
  		      }
! 		    if (dataref_offset == NULL_TREE
! 			&& TREE_CODE (dataref_ptr) == SSA_NAME)
  		      set_ptr_info_alignment (get_ptr_info (dataref_ptr),
  					      align, misalign);
  		    break;
*************** vectorizable_load (gimple stmt, gimple_s
*** 6680,6686 ****
  						    dr_explicit_realign,
  						    dataref_ptr, NULL);
  
! 		    ptr = copy_ssa_name (dataref_ptr);
  		    new_stmt = gimple_build_assign
  				 (ptr, BIT_AND_EXPR, dataref_ptr,
  				  build_int_cst
--- 6689,6698 ----
  						    dr_explicit_realign,
  						    dataref_ptr, NULL);
  
! 		    if (TREE_CODE (dataref_ptr) == SSA_NAME)
! 		      ptr = copy_ssa_name (dataref_ptr);
! 		    else
! 		      ptr = make_ssa_name (TREE_TYPE (dataref_ptr));
  		    new_stmt = gimple_build_assign
  				 (ptr, BIT_AND_EXPR, dataref_ptr,
  				  build_int_cst
*************** vectorizable_load (gimple stmt, gimple_s
*** 6710,6716 ****
  				  build_int_cst
  				  (TREE_TYPE (ptr),
  				   -(HOST_WIDE_INT)TYPE_ALIGN_UNIT (vectype)));
! 		    ptr = copy_ssa_name (dataref_ptr, new_stmt);
  		    gimple_assign_set_lhs (new_stmt, ptr);
  		    vect_finish_stmt_generation (stmt, new_stmt, gsi);
  		    data_ref
--- 6722,6728 ----
  				  build_int_cst
  				  (TREE_TYPE (ptr),
  				   -(HOST_WIDE_INT)TYPE_ALIGN_UNIT (vectype)));
! 		    ptr = copy_ssa_name (ptr, new_stmt);
  		    gimple_assign_set_lhs (new_stmt, ptr);
  		    vect_finish_stmt_generation (stmt, new_stmt, gsi);
  		    data_ref
*************** vectorizable_load (gimple stmt, gimple_s
*** 6720,6726 ****
  		    break;
  		  }
  		case dr_explicit_realign_optimized:
! 		  new_temp = copy_ssa_name (dataref_ptr);
  		  new_stmt = gimple_build_assign
  			       (new_temp, BIT_AND_EXPR, dataref_ptr,
  				build_int_cst
--- 6732,6741 ----
  		    break;
  		  }
  		case dr_explicit_realign_optimized:
! 		  if (TREE_CODE (dataref_ptr) == SSA_NAME)
! 		    new_temp = copy_ssa_name (dataref_ptr);
! 		  else
! 		    new_temp = make_ssa_name (TREE_TYPE (dataref_ptr));
  		  new_stmt = gimple_build_assign
  			       (new_temp, BIT_AND_EXPR, dataref_ptr,
  				build_int_cst
Index: gcc/tree-vect-data-refs.c
===================================================================
*** gcc/tree-vect-data-refs.c	(revision 224324)
--- gcc/tree-vect-data-refs.c	(working copy)
*************** vect_create_addr_base_for_vector_ref (gi
*** 3956,3968 ****
      }
  
    vect_ptr_type = build_pointer_type (STMT_VINFO_VECTYPE (stmt_info));
-   addr_base = fold_convert (vect_ptr_type, addr_base);
    dest = vect_get_new_vect_var (vect_ptr_type, vect_pointer_var, base_name);
!   addr_base = force_gimple_operand (addr_base, &seq, false, dest);
    gimple_seq_add_seq (new_stmt_list, seq);
  
    if (DR_PTR_INFO (dr)
!       && TREE_CODE (addr_base) == SSA_NAME)
      {
        vect_duplicate_ssa_name_ptr_info (addr_base, dr, stmt_info);
        if (offset || byte_offset)
--- 3956,3968 ----
      }
  
    vect_ptr_type = build_pointer_type (STMT_VINFO_VECTYPE (stmt_info));
    dest = vect_get_new_vect_var (vect_ptr_type, vect_pointer_var, base_name);
!   addr_base = force_gimple_operand (addr_base, &seq, true, dest);
    gimple_seq_add_seq (new_stmt_list, seq);
  
    if (DR_PTR_INFO (dr)
!       && TREE_CODE (addr_base) == SSA_NAME
!       && !SSA_NAME_PTR_INFO (addr_base))
      {
        vect_duplicate_ssa_name_ptr_info (addr_base, dr, stmt_info);
        if (offset || byte_offset)
*************** vect_create_data_ref_ptr (gimple stmt, t
*** 4048,4054 ****
    tree aggr_ptr_type;
    tree aggr_ptr;
    tree new_temp;
-   gimple vec_stmt;
    gimple_seq new_stmt_list = NULL;
    edge pe = NULL;
    basic_block new_bb;
--- 4048,4053 ----
*************** vect_create_data_ref_ptr (gimple stmt, t
*** 4196,4223 ****
      }
  
    *initial_address = new_temp;
! 
!   /* Create: p = (aggr_type *) initial_base  */
!   if (TREE_CODE (new_temp) != SSA_NAME
!       || !useless_type_conversion_p (aggr_ptr_type, TREE_TYPE (new_temp)))
!     {
!       vec_stmt = gimple_build_assign (aggr_ptr,
! 				      fold_convert (aggr_ptr_type, new_temp));
!       aggr_ptr_init = make_ssa_name (aggr_ptr, vec_stmt);
!       /* Copy the points-to information if it exists. */
!       if (DR_PTR_INFO (dr))
! 	vect_duplicate_ssa_name_ptr_info (aggr_ptr_init, dr, stmt_info);
!       gimple_assign_set_lhs (vec_stmt, aggr_ptr_init);
!       if (pe)
! 	{
! 	  new_bb = gsi_insert_on_edge_immediate (pe, vec_stmt);
! 	  gcc_assert (!new_bb);
! 	}
!       else
! 	gsi_insert_before (gsi, vec_stmt, GSI_SAME_STMT);
!     }
!   else
!     aggr_ptr_init = new_temp;
  
    /* (3) Handle the updating of the aggregate-pointer inside the loop.
       This is needed when ONLY_INIT is false, and also when AT_LOOP is the
--- 4195,4201 ----
      }
  
    *initial_address = new_temp;
!   aggr_ptr_init = new_temp;
  
    /* (3) Handle the updating of the aggregate-pointer inside the loop.
       This is needed when ONLY_INIT is false, and also when AT_LOOP is the
*************** bump_vector_ptr (tree dataref_ptr, gimpl
*** 4342,4348 ****
    if (bump)
      update = bump;
  
!   new_dataref_ptr = copy_ssa_name (dataref_ptr);
    incr_stmt = gimple_build_assign (new_dataref_ptr, POINTER_PLUS_EXPR,
  				   dataref_ptr, update);
    vect_finish_stmt_generation (stmt, incr_stmt, gsi);
--- 4320,4329 ----
    if (bump)
      update = bump;
  
!   if (TREE_CODE (dataref_ptr) == SSA_NAME)
!     new_dataref_ptr = copy_ssa_name (dataref_ptr);
!   else
!     new_dataref_ptr = make_ssa_name (TREE_TYPE (dataref_ptr));
    incr_stmt = gimple_build_assign (new_dataref_ptr, POINTER_PLUS_EXPR,
  				   dataref_ptr, update);
    vect_finish_stmt_generation (stmt, incr_stmt, gsi);
Index: gcc/testsuite/gcc.target/i386/recip-vec-sqrtf-avx.c
===================================================================
--- gcc/testsuite/gcc.target/i386/recip-vec-sqrtf-avx.c	(revision 224513)
+++ gcc/testsuite/gcc.target/i386/recip-vec-sqrtf-avx.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -ffast-math -ftree-vectorize -mavx -mtune=generic -mfpmath=sse -mrecip" } */
+/* { dg-options "-O2 -ffast-math -ftree-vectorize -mavx -mtune=generic -mfpmath=sse -mrecip --param max-completely-peel-times=1" } */
 
 float a[32];
 float b[32];


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