diff mbox series

[01/46] Move special cases out of get_initial_def_for_reduction

Message ID 87sh49rmdl.fsf@arm.com
State New
Headers show
Series Remove vinfo_for_stmt etc. | expand

Commit Message

Richard Sandiford July 24, 2018, 9:52 a.m. UTC
This minor clean-up avoids repeating the test for double reductions
and also moves the vect_get_vec_def_for_operand call to the same
function as the corresponding vect_get_vec_def_for_stmt_copy.


2018-07-24  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* tree-vect-loop.c (get_initial_def_for_reduction): Move special
	cases for nested loops from here to ...
	(vect_create_epilog_for_reduction): ...here.  Only call
	vect_is_simple_use for inner-loop reductions.

Comments

Richard Biener July 25, 2018, 8:42 a.m. UTC | #1
On Tue, Jul 24, 2018 at 11:53 AM Richard Sandiford
<richard.sandiford@arm.com> wrote:
>
> This minor clean-up avoids repeating the test for double reductions
> and also moves the vect_get_vec_def_for_operand call to the same
> function as the corresponding vect_get_vec_def_for_stmt_copy.

OK.

>
> 2018-07-24  Richard Sandiford  <richard.sandiford@arm.com>
>
> gcc/
>         * tree-vect-loop.c (get_initial_def_for_reduction): Move special
>         cases for nested loops from here to ...
>         (vect_create_epilog_for_reduction): ...here.  Only call
>         vect_is_simple_use for inner-loop reductions.
>
> Index: gcc/tree-vect-loop.c
> ===================================================================
> --- gcc/tree-vect-loop.c        2018-07-13 10:11:14.429843575 +0100
> +++ gcc/tree-vect-loop.c        2018-07-24 10:22:02.965552667 +0100
> @@ -4113,10 +4113,8 @@ get_initial_def_for_reduction (gimple *s
>    enum tree_code code = gimple_assign_rhs_code (stmt);
>    tree def_for_init;
>    tree init_def;
> -  bool nested_in_vect_loop = false;
>    REAL_VALUE_TYPE real_init_val = dconst0;
>    int int_init_val = 0;
> -  gimple *def_stmt = NULL;
>    gimple_seq stmts = NULL;
>
>    gcc_assert (vectype);
> @@ -4124,39 +4122,12 @@ get_initial_def_for_reduction (gimple *s
>    gcc_assert (POINTER_TYPE_P (scalar_type) || INTEGRAL_TYPE_P (scalar_type)
>               || SCALAR_FLOAT_TYPE_P (scalar_type));
>
> -  if (nested_in_vect_loop_p (loop, stmt))
> -    nested_in_vect_loop = true;
> -  else
> -    gcc_assert (loop == (gimple_bb (stmt))->loop_father);
> -
> -  /* In case of double reduction we only create a vector variable to be put
> -     in the reduction phi node.  The actual statement creation is done in
> -     vect_create_epilog_for_reduction.  */
> -  if (adjustment_def && nested_in_vect_loop
> -      && TREE_CODE (init_val) == SSA_NAME
> -      && (def_stmt = SSA_NAME_DEF_STMT (init_val))
> -      && gimple_code (def_stmt) == GIMPLE_PHI
> -      && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt))
> -      && vinfo_for_stmt (def_stmt)
> -      && STMT_VINFO_DEF_TYPE (vinfo_for_stmt (def_stmt))
> -          == vect_double_reduction_def)
> -    {
> -      *adjustment_def = NULL;
> -      return vect_create_destination_var (init_val, vectype);
> -    }
> +  gcc_assert (nested_in_vect_loop_p (loop, stmt)
> +             || loop == (gimple_bb (stmt))->loop_father);
>
>    vect_reduction_type reduction_type
>      = STMT_VINFO_VEC_REDUCTION_TYPE (stmt_vinfo);
>
> -  /* In case of a nested reduction do not use an adjustment def as
> -     that case is not supported by the epilogue generation correctly
> -     if ncopies is not one.  */
> -  if (adjustment_def && nested_in_vect_loop)
> -    {
> -      *adjustment_def = NULL;
> -      return vect_get_vec_def_for_operand (init_val, stmt);
> -    }
> -
>    switch (code)
>      {
>      case WIDEN_SUM_EXPR:
> @@ -4586,9 +4557,22 @@ vect_create_epilog_for_reduction (vec<tr
>               || (induc_code == MIN_EXPR
>                   && tree_int_cst_lt (induc_val, initial_def))))
>         induc_val = initial_def;
> -      vect_is_simple_use (initial_def, loop_vinfo, &initial_def_dt);
> -      vec_initial_def = get_initial_def_for_reduction (stmt, initial_def,
> -                                                      &adjustment_def);
> +
> +      if (double_reduc)
> +       /* In case of double reduction we only create a vector variable
> +          to be put in the reduction phi node.  The actual statement
> +          creation is done later in this function.  */
> +       vec_initial_def = vect_create_destination_var (initial_def, vectype);
> +      else if (nested_in_vect_loop)
> +       {
> +         /* Do not use an adjustment def as that case is not supported
> +            correctly if ncopies is not one.  */
> +         vect_is_simple_use (initial_def, loop_vinfo, &initial_def_dt);
> +         vec_initial_def = vect_get_vec_def_for_operand (initial_def, stmt);
> +       }
> +      else
> +       vec_initial_def = get_initial_def_for_reduction (stmt, initial_def,
> +                                                        &adjustment_def);
>        vec_initial_defs.create (1);
>        vec_initial_defs.quick_push (vec_initial_def);
>      }
diff mbox series

Patch

Index: gcc/tree-vect-loop.c
===================================================================
--- gcc/tree-vect-loop.c	2018-07-13 10:11:14.429843575 +0100
+++ gcc/tree-vect-loop.c	2018-07-24 10:22:02.965552667 +0100
@@ -4113,10 +4113,8 @@  get_initial_def_for_reduction (gimple *s
   enum tree_code code = gimple_assign_rhs_code (stmt);
   tree def_for_init;
   tree init_def;
-  bool nested_in_vect_loop = false;
   REAL_VALUE_TYPE real_init_val = dconst0;
   int int_init_val = 0;
-  gimple *def_stmt = NULL;
   gimple_seq stmts = NULL;
 
   gcc_assert (vectype);
@@ -4124,39 +4122,12 @@  get_initial_def_for_reduction (gimple *s
   gcc_assert (POINTER_TYPE_P (scalar_type) || INTEGRAL_TYPE_P (scalar_type)
 	      || SCALAR_FLOAT_TYPE_P (scalar_type));
 
-  if (nested_in_vect_loop_p (loop, stmt))
-    nested_in_vect_loop = true;
-  else
-    gcc_assert (loop == (gimple_bb (stmt))->loop_father);
-
-  /* In case of double reduction we only create a vector variable to be put
-     in the reduction phi node.  The actual statement creation is done in
-     vect_create_epilog_for_reduction.  */
-  if (adjustment_def && nested_in_vect_loop
-      && TREE_CODE (init_val) == SSA_NAME
-      && (def_stmt = SSA_NAME_DEF_STMT (init_val))
-      && gimple_code (def_stmt) == GIMPLE_PHI
-      && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt))
-      && vinfo_for_stmt (def_stmt)
-      && STMT_VINFO_DEF_TYPE (vinfo_for_stmt (def_stmt))
-          == vect_double_reduction_def)
-    {
-      *adjustment_def = NULL;
-      return vect_create_destination_var (init_val, vectype);
-    }
+  gcc_assert (nested_in_vect_loop_p (loop, stmt)
+	      || loop == (gimple_bb (stmt))->loop_father);
 
   vect_reduction_type reduction_type
     = STMT_VINFO_VEC_REDUCTION_TYPE (stmt_vinfo);
 
-  /* In case of a nested reduction do not use an adjustment def as
-     that case is not supported by the epilogue generation correctly
-     if ncopies is not one.  */
-  if (adjustment_def && nested_in_vect_loop)
-    {
-      *adjustment_def = NULL;
-      return vect_get_vec_def_for_operand (init_val, stmt);
-    }
-
   switch (code)
     {
     case WIDEN_SUM_EXPR:
@@ -4586,9 +4557,22 @@  vect_create_epilog_for_reduction (vec<tr
 	      || (induc_code == MIN_EXPR
 		  && tree_int_cst_lt (induc_val, initial_def))))
 	induc_val = initial_def;
-      vect_is_simple_use (initial_def, loop_vinfo, &initial_def_dt);
-      vec_initial_def = get_initial_def_for_reduction (stmt, initial_def,
-						       &adjustment_def);
+
+      if (double_reduc)
+	/* In case of double reduction we only create a vector variable
+	   to be put in the reduction phi node.  The actual statement
+	   creation is done later in this function.  */
+	vec_initial_def = vect_create_destination_var (initial_def, vectype);
+      else if (nested_in_vect_loop)
+	{
+	  /* Do not use an adjustment def as that case is not supported
+	     correctly if ncopies is not one.  */
+	  vect_is_simple_use (initial_def, loop_vinfo, &initial_def_dt);
+	  vec_initial_def = vect_get_vec_def_for_operand (initial_def, stmt);
+	}
+      else
+	vec_initial_def = get_initial_def_for_reduction (stmt, initial_def,
+							 &adjustment_def);
       vec_initial_defs.create (1);
       vec_initial_defs.quick_push (vec_initial_def);
     }