diff mbox series

Some vect_create_epilog_for_reduction refactoring

Message ID nycvar.YFH.7.76.1909201455580.5566@zhemvz.fhfr.qr
State New
Headers show
Series Some vect_create_epilog_for_reduction refactoring | expand

Commit Message

Richard Biener Sept. 20, 2019, 12:56 p.m. UTC
Plus simplification in get_initial_def_for_reduction, avoiding some
of the + 0 adjustments I've seen created.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2019-09-20  Richard Biener  <rguenther@suse.de>

	* tree-vect-loop.c (get_initial_def_for_reduction): Simplify,
	avoid adjusting by + 0 or * 1.
	(vect_create_epilog_for_reduction): Get reduction code only
	when necessary.  Deal with adjustment_def only when necessary.
diff mbox series

Patch

Index: gcc/tree-vect-loop.c
===================================================================
--- gcc/tree-vect-loop.c	(revision 275997)
+++ gcc/tree-vect-loop.c	(working copy)
@@ -4003,8 +4003,10 @@  get_initial_def_for_reduction (stmt_vec_
   gcc_assert (nested_in_vect_loop_p (loop, stmt_vinfo)
 	      || loop == (gimple_bb (stmt_vinfo->stmt))->loop_father);
 
-  vect_reduction_type reduction_type
-    = STMT_VINFO_VEC_REDUCTION_TYPE (stmt_vinfo);
+  /* ADJUSTMENT_DEF is NULL when called from
+     vect_create_epilog_for_reduction to vectorize double reduction.  */
+  if (adjustment_def)
+    *adjustment_def = NULL;
 
   switch (code)
     {
@@ -4018,11 +4020,6 @@  get_initial_def_for_reduction (stmt_vec_
     case MULT_EXPR:
     case BIT_AND_EXPR:
       {
-        /* ADJUSTMENT_DEF is NULL when called from
-           vect_create_epilog_for_reduction to vectorize double reduction.  */
-        if (adjustment_def)
-	  *adjustment_def = init_val;
-
         if (code == MULT_EXPR)
           {
             real_init_val = dconst1;
@@ -4037,10 +4034,14 @@  get_initial_def_for_reduction (stmt_vec_
         else
           def_for_init = build_int_cst (scalar_type, int_init_val);
 
-	if (adjustment_def)
-	  /* Option1: the first element is '0' or '1' as well.  */
-	  init_def = gimple_build_vector_from_val (&stmts, vectype,
-						   def_for_init);
+	if (adjustment_def || operand_equal_p (def_for_init, init_val, 0))
+	  {
+	    /* Option1: the first element is '0' or '1' as well.  */
+	    if (!operand_equal_p (def_for_init, init_val, 0))
+	      *adjustment_def = init_val;
+	    init_def = gimple_build_vector_from_val (&stmts, vectype,
+						     def_for_init);
+	  }
 	else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant ())
 	  {
 	    /* Option2 (variable length): the first element is INIT_VAL.  */
@@ -4064,16 +4065,8 @@  get_initial_def_for_reduction (stmt_vec_
     case MAX_EXPR:
     case COND_EXPR:
       {
-	if (adjustment_def)
-          {
-	    *adjustment_def = NULL_TREE;
-	    if (reduction_type != COND_REDUCTION
-		&& reduction_type != EXTRACT_LAST_REDUCTION)
-	      {
-		init_def = vect_get_vec_def_for_operand (init_val, stmt_vinfo);
-		break;
-	      }
-	  }
+	gcc_assert (useless_type_conversion_p (TREE_TYPE (vectype),
+					       TREE_TYPE (init_val)));
 	init_val = gimple_convert (&stmts, TREE_TYPE (vectype), init_val);
 	init_def = gimple_build_vector_from_val (&stmts, vectype, init_val);
       }
@@ -4304,7 +4297,6 @@  vect_create_epilog_for_reduction (vec<tr
   tree vec_dest;
   tree new_temp = NULL_TREE, new_dest, new_name, new_scalar_dest;
   gimple *epilog_stmt = NULL;
-  enum tree_code code = gimple_assign_rhs_code (stmt_info->stmt);
   gimple *exit_phi;
   tree bitsize;
   tree adjustment_def = NULL;
@@ -4645,12 +4637,6 @@  vect_create_epilog_for_reduction (vec<tr
       gcc_assert (STMT_VINFO_IN_PATTERN_P (orig_stmt_info));
       gcc_assert (STMT_VINFO_RELATED_STMT (orig_stmt_info) == stmt_info);
     }
-
-  code = gimple_assign_rhs_code (orig_stmt_info->stmt);
-  /* For MINUS_EXPR the initial vector is [init_val,0,...,0], therefore,
-     partial results are added and not subtracted.  */
-  if (code == MINUS_EXPR) 
-    code = PLUS_EXPR;
   
   scalar_dest = gimple_assign_lhs (orig_stmt_info->stmt);
   scalar_type = TREE_TYPE (scalar_dest);
@@ -4665,7 +4651,14 @@  vect_create_epilog_for_reduction (vec<tr
      in the vectorized outer-loop, or reduced to a scalar result at the end of
      the outer-loop.  */
   if (nested_in_vect_loop && !double_reduc)
-    goto vect_finalize_reduction;
+    ;
+  else
+    {
+  enum tree_code code = gimple_assign_rhs_code (orig_stmt_info->stmt);
+  /* For MINUS_EXPR the initial vector is [init_val,0,...,0], therefore,
+     partial results are added and not subtracted.  */
+  if (code == MINUS_EXPR) 
+    code = PLUS_EXPR;
 
   /* SLP reduction without reduction chain, e.g.,
      # a1 = phi <a2, a0>
@@ -5352,12 +5345,7 @@  vect_create_epilog_for_reduction (vec<tr
 	  scalar_results[0] = tmp;
 	}
     }
-  
-vect_finalize_reduction:
-
-  if (double_reduc)
-    loop = loop->inner;
-
+ 
   /* 2.5 Adjust the final result by the initial value of the reduction
 	 variable. (When such adjustment is not needed, then
 	 'adjustment_def' is zero).  For example, if code is PLUS we create:
@@ -5401,6 +5389,10 @@  vect_finalize_reduction:
 
       new_phis[0] = epilog_stmt;
     }
+    }
+
+  if (double_reduc)
+    loop = loop->inner;
 
   /* 2.6  Handle the loop-exit phis.  Replace the uses of scalar loop-exit
           phis with new adjusted scalar results, i.e., replace use <s_out0>