[42/46] Add vec_info::replace_stmt

Message ID 87va95kkrb.fsf@arm.com
State New
Headers show
Series
  • Remove vinfo_for_stmt etc.
Related show

Commit Message

Richard Sandiford July 24, 2018, 10:09 a.m.
This patch adds a helper for replacing a stmt_vec_info's statement with
a new statement.


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

gcc/
	* tree-vectorizer.h (vec_info::replace_stmt): Declare.
	* tree-vectorizer.c (vec_info::replace_stmt): New function.
	* tree-vect-slp.c (vect_remove_slp_scalar_calls): Use it.
	* tree-vect-stmts.c (vectorizable_call): Likewise.
	(vectorizable_simd_clone_call): Likewise.

Comments

Richard Biener July 31, 2018, 12:03 p.m. | #1
On Tue, Jul 24, 2018 at 12:09 PM Richard Sandiford
<richard.sandiford@arm.com> wrote:
>

> This patch adds a helper for replacing a stmt_vec_info's statement with

> a new statement.


OK.

>

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

>

> gcc/

>         * tree-vectorizer.h (vec_info::replace_stmt): Declare.

>         * tree-vectorizer.c (vec_info::replace_stmt): New function.

>         * tree-vect-slp.c (vect_remove_slp_scalar_calls): Use it.

>         * tree-vect-stmts.c (vectorizable_call): Likewise.

>         (vectorizable_simd_clone_call): Likewise.

>

> Index: gcc/tree-vectorizer.h

> ===================================================================

> --- gcc/tree-vectorizer.h       2018-07-24 10:24:19.544339803 +0100

> +++ gcc/tree-vectorizer.h       2018-07-24 10:24:22.684311906 +0100

> @@ -242,6 +242,7 @@ struct vec_info {

>    stmt_vec_info lookup_single_use (tree);

>    stmt_vec_info lookup_dr (data_reference *);

>    void remove_stmt (stmt_vec_info);

> +  void replace_stmt (gimple_stmt_iterator *, stmt_vec_info, gimple *);

>

>    /* The type of vectorization.  */

>    vec_kind kind;

> Index: gcc/tree-vectorizer.c

> ===================================================================

> --- gcc/tree-vectorizer.c       2018-07-24 10:24:19.544339803 +0100

> +++ gcc/tree-vectorizer.c       2018-07-24 10:24:22.684311906 +0100

> @@ -591,6 +591,22 @@ vec_info::remove_stmt (stmt_vec_info stm

>    free_stmt_vec_info (stmt_info);

>  }

>

> +/* Replace the statement at GSI by NEW_STMT, both the vectorization

> +   information and the function itself.  STMT_INFO describes the statement

> +   at GSI.  */

> +

> +void

> +vec_info::replace_stmt (gimple_stmt_iterator *gsi, stmt_vec_info stmt_info,

> +                       gimple *new_stmt)

> +{

> +  gimple *old_stmt = stmt_info->stmt;

> +  gcc_assert (!stmt_info->pattern_stmt_p && old_stmt == gsi_stmt (*gsi));

> +  set_vinfo_for_stmt (old_stmt, NULL);

> +  set_vinfo_for_stmt (new_stmt, stmt_info);

> +  stmt_info->stmt = new_stmt;

> +  gsi_replace (gsi, new_stmt, true);

> +}

> +

>  /* A helper function to free scev and LOOP niter information, as well as

>     clear loop constraint LOOP_C_FINITE.  */

>

> Index: gcc/tree-vect-slp.c

> ===================================================================

> --- gcc/tree-vect-slp.c 2018-07-24 10:24:19.540339838 +0100

> +++ gcc/tree-vect-slp.c 2018-07-24 10:24:22.680311942 +0100

> @@ -4048,11 +4048,8 @@ vect_remove_slp_scalar_calls (slp_tree n

>         continue;

>        lhs = gimple_call_lhs (stmt);

>        new_stmt = gimple_build_assign (lhs, build_zero_cst (TREE_TYPE (lhs)));

> -      set_vinfo_for_stmt (new_stmt, stmt_info);

> -      set_vinfo_for_stmt (stmt, NULL);

> -      STMT_VINFO_STMT (stmt_info) = new_stmt;

>        gsi = gsi_for_stmt (stmt);

> -      gsi_replace (&gsi, new_stmt, false);

> +      stmt_info->vinfo->replace_stmt (&gsi, stmt_info, new_stmt);

>        SSA_NAME_DEF_STMT (gimple_assign_lhs (new_stmt)) = new_stmt;

>      }

>  }

> Index: gcc/tree-vect-stmts.c

> ===================================================================

> --- gcc/tree-vect-stmts.c       2018-07-24 10:24:19.544339803 +0100

> +++ gcc/tree-vect-stmts.c       2018-07-24 10:24:22.684311906 +0100

> @@ -3629,10 +3629,7 @@ vectorizable_call (stmt_vec_info stmt_in

>

>    gassign *new_stmt

>      = gimple_build_assign (lhs, build_zero_cst (TREE_TYPE (lhs)));

> -  set_vinfo_for_stmt (new_stmt, stmt_info);

> -  set_vinfo_for_stmt (stmt_info->stmt, NULL);

> -  STMT_VINFO_STMT (stmt_info) = new_stmt;

> -  gsi_replace (gsi, new_stmt, false);

> +  vinfo->replace_stmt (gsi, stmt_info, new_stmt);

>

>    return true;

>  }

> @@ -4370,10 +4367,7 @@ vectorizable_simd_clone_call (stmt_vec_i

>      }

>    else

>      new_stmt = gimple_build_nop ();

> -  set_vinfo_for_stmt (new_stmt, stmt_info);

> -  set_vinfo_for_stmt (stmt, NULL);

> -  STMT_VINFO_STMT (stmt_info) = new_stmt;

> -  gsi_replace (gsi, new_stmt, true);

> +  vinfo->replace_stmt (gsi, stmt_info, new_stmt);

>    unlink_stmt_vdef (stmt);

>

>    return true;

Patch

Index: gcc/tree-vectorizer.h
===================================================================
--- gcc/tree-vectorizer.h	2018-07-24 10:24:19.544339803 +0100
+++ gcc/tree-vectorizer.h	2018-07-24 10:24:22.684311906 +0100
@@ -242,6 +242,7 @@  struct vec_info {
   stmt_vec_info lookup_single_use (tree);
   stmt_vec_info lookup_dr (data_reference *);
   void remove_stmt (stmt_vec_info);
+  void replace_stmt (gimple_stmt_iterator *, stmt_vec_info, gimple *);
 
   /* The type of vectorization.  */
   vec_kind kind;
Index: gcc/tree-vectorizer.c
===================================================================
--- gcc/tree-vectorizer.c	2018-07-24 10:24:19.544339803 +0100
+++ gcc/tree-vectorizer.c	2018-07-24 10:24:22.684311906 +0100
@@ -591,6 +591,22 @@  vec_info::remove_stmt (stmt_vec_info stm
   free_stmt_vec_info (stmt_info);
 }
 
+/* Replace the statement at GSI by NEW_STMT, both the vectorization
+   information and the function itself.  STMT_INFO describes the statement
+   at GSI.  */
+
+void
+vec_info::replace_stmt (gimple_stmt_iterator *gsi, stmt_vec_info stmt_info,
+			gimple *new_stmt)
+{
+  gimple *old_stmt = stmt_info->stmt;
+  gcc_assert (!stmt_info->pattern_stmt_p && old_stmt == gsi_stmt (*gsi));
+  set_vinfo_for_stmt (old_stmt, NULL);
+  set_vinfo_for_stmt (new_stmt, stmt_info);
+  stmt_info->stmt = new_stmt;
+  gsi_replace (gsi, new_stmt, true);
+}
+
 /* A helper function to free scev and LOOP niter information, as well as
    clear loop constraint LOOP_C_FINITE.  */
 
Index: gcc/tree-vect-slp.c
===================================================================
--- gcc/tree-vect-slp.c	2018-07-24 10:24:19.540339838 +0100
+++ gcc/tree-vect-slp.c	2018-07-24 10:24:22.680311942 +0100
@@ -4048,11 +4048,8 @@  vect_remove_slp_scalar_calls (slp_tree n
 	continue;
       lhs = gimple_call_lhs (stmt);
       new_stmt = gimple_build_assign (lhs, build_zero_cst (TREE_TYPE (lhs)));
-      set_vinfo_for_stmt (new_stmt, stmt_info);
-      set_vinfo_for_stmt (stmt, NULL);
-      STMT_VINFO_STMT (stmt_info) = new_stmt;
       gsi = gsi_for_stmt (stmt);
-      gsi_replace (&gsi, new_stmt, false);
+      stmt_info->vinfo->replace_stmt (&gsi, stmt_info, new_stmt);
       SSA_NAME_DEF_STMT (gimple_assign_lhs (new_stmt)) = new_stmt;
     }
 }
Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c	2018-07-24 10:24:19.544339803 +0100
+++ gcc/tree-vect-stmts.c	2018-07-24 10:24:22.684311906 +0100
@@ -3629,10 +3629,7 @@  vectorizable_call (stmt_vec_info stmt_in
 
   gassign *new_stmt
     = gimple_build_assign (lhs, build_zero_cst (TREE_TYPE (lhs)));
-  set_vinfo_for_stmt (new_stmt, stmt_info);
-  set_vinfo_for_stmt (stmt_info->stmt, NULL);
-  STMT_VINFO_STMT (stmt_info) = new_stmt;
-  gsi_replace (gsi, new_stmt, false);
+  vinfo->replace_stmt (gsi, stmt_info, new_stmt);
 
   return true;
 }
@@ -4370,10 +4367,7 @@  vectorizable_simd_clone_call (stmt_vec_i
     }
   else
     new_stmt = gimple_build_nop ();
-  set_vinfo_for_stmt (new_stmt, stmt_info);
-  set_vinfo_for_stmt (stmt, NULL);
-  STMT_VINFO_STMT (stmt_info) = new_stmt;
-  gsi_replace (gsi, new_stmt, true);
+  vinfo->replace_stmt (gsi, stmt_info, new_stmt);
   unlink_stmt_vdef (stmt);
 
   return true;