Add a gimple_move_vops helper function
authorRichard Sandiford <richard.sandiford@arm.com>
Mon, 5 Aug 2019 16:46:48 +0000 (16:46 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Mon, 5 Aug 2019 16:46:48 +0000 (16:46 +0000)
I needed to add another instance of this idiom, so thought it'd
be worth having a helper function.

2019-08-05  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
* gimple.h (gimple_move_vops): Declare.
* gimple.c (gimple_move_vops): New function
* gimple-fold.c (replace_call_with_call_and_fold)
(gimple_fold_builtin_memory_op, gimple_fold_builtin_memset)
(gimple_fold_builtin_stpcpy, fold_builtin_atomic_compare_exchange)
(gimple_fold_call): Use it.
* ipa-param-manipulation.c (ipa_modify_call_arguments): Likewise.
* tree-call-cdce.c (use_internal_fn): Likewise.
* tree-if-conv.c (predicate_load_or_store): Likewise.
* tree-ssa-ccp.c (optimize_atomic_bit_test_and): Likewise.
* tree-ssa-math-opts.c (pass_cse_reciprocals::execute): Likewise.
* tree-ssa-propagate.c (finish_update_gimple_call): Likewise.
(update_call_from_tree): Likewise.
* tree-vect-stmts.c (vectorizable_load): Likewise.
* tree-vectorizer.c (adjust_simduid_builtins): Likewise.

From-SVN: r274117

12 files changed:
gcc/ChangeLog
gcc/gimple-fold.c
gcc/gimple.c
gcc/gimple.h
gcc/ipa-param-manipulation.c
gcc/tree-call-cdce.c
gcc/tree-if-conv.c
gcc/tree-ssa-ccp.c
gcc/tree-ssa-math-opts.c
gcc/tree-ssa-propagate.c
gcc/tree-vect-stmts.c
gcc/tree-vectorizer.c

index 892f7aa..3d3a2fa 100644 (file)
@@ -1,3 +1,21 @@
+2019-08-05  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * gimple.h (gimple_move_vops): Declare.
+       * gimple.c (gimple_move_vops): New function
+       * gimple-fold.c (replace_call_with_call_and_fold)
+       (gimple_fold_builtin_memory_op, gimple_fold_builtin_memset)
+       (gimple_fold_builtin_stpcpy, fold_builtin_atomic_compare_exchange)
+       (gimple_fold_call): Use it.
+       * ipa-param-manipulation.c (ipa_modify_call_arguments): Likewise.
+       * tree-call-cdce.c (use_internal_fn): Likewise.
+       * tree-if-conv.c (predicate_load_or_store): Likewise.
+       * tree-ssa-ccp.c (optimize_atomic_bit_test_and): Likewise.
+       * tree-ssa-math-opts.c (pass_cse_reciprocals::execute): Likewise.
+       * tree-ssa-propagate.c (finish_update_gimple_call): Likewise.
+       (update_call_from_tree): Likewise.
+       * tree-vect-stmts.c (vectorizable_load): Likewise.
+       * tree-vectorizer.c (adjust_simduid_builtins): Likewise.
+
 2019-08-05  Martin Liska  <mliska@suse.cz>
 
        PR c++/91334
index be83620..c3128e7 100644 (file)
@@ -641,14 +641,7 @@ replace_call_with_call_and_fold (gimple_stmt_iterator *gsi, gimple *repl)
   gimple *stmt = gsi_stmt (*gsi);
   gimple_call_set_lhs (repl, gimple_call_lhs (stmt));
   gimple_set_location (repl, gimple_location (stmt));
-  if (gimple_vdef (stmt)
-      && TREE_CODE (gimple_vdef (stmt)) == SSA_NAME)
-    {
-      gimple_set_vdef (repl, gimple_vdef (stmt));
-      SSA_NAME_DEF_STMT (gimple_vdef (repl)) = repl;
-    }
-  if (gimple_vuse (stmt))
-    gimple_set_vuse (repl, gimple_vuse (stmt));
+  gimple_move_vops (repl, stmt);
   gsi_replace (gsi, repl, false);
   fold_stmt (gsi);
 }
@@ -832,11 +825,7 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
                        = gimple_build_assign (fold_build2 (MEM_REF, desttype,
                                                            dest, off0),
                                               srcmem);
-                     gimple_set_vuse (new_stmt, gimple_vuse (stmt));
-                     gimple_set_vdef (new_stmt, gimple_vdef (stmt));
-                     if (gimple_vdef (new_stmt)
-                         && TREE_CODE (gimple_vdef (new_stmt)) == SSA_NAME)
-                       SSA_NAME_DEF_STMT (gimple_vdef (new_stmt)) = new_stmt;
+                     gimple_move_vops (new_stmt, stmt);
                      if (!lhs)
                        {
                          gsi_replace (gsi, new_stmt, false);
@@ -1097,11 +1086,7 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
        = gimple_build_assign (fold_build2 (MEM_REF, desttype, dest, off0),
                               fold_build2 (MEM_REF, srctype, src, off0));
 set_vop_and_replace:
-      gimple_set_vuse (new_stmt, gimple_vuse (stmt));
-      gimple_set_vdef (new_stmt, gimple_vdef (stmt));
-      if (gimple_vdef (new_stmt)
-         && TREE_CODE (gimple_vdef (new_stmt)) == SSA_NAME)
-       SSA_NAME_DEF_STMT (gimple_vdef (new_stmt)) = new_stmt;
+      gimple_move_vops (new_stmt, stmt);
       if (!lhs)
        {
          gsi_replace (gsi, new_stmt, false);
@@ -1273,13 +1258,7 @@ gimple_fold_builtin_memset (gimple_stmt_iterator *gsi, tree c, tree len)
 
   var = fold_build2 (MEM_REF, etype, dest, build_int_cst (ptr_type_node, 0));
   gimple *store = gimple_build_assign (var, build_int_cst_type (etype, cval));
-  gimple_set_vuse (store, gimple_vuse (stmt));
-  tree vdef = gimple_vdef (stmt);
-  if (vdef && TREE_CODE (vdef) == SSA_NAME)
-    {
-      gimple_set_vdef (store, gimple_vdef (stmt));
-      SSA_NAME_DEF_STMT (gimple_vdef (stmt)) = store;
-    }
+  gimple_move_vops (store, stmt);
   gsi_insert_before (gsi, store, GSI_SAME_STMT);
   if (gimple_call_lhs (stmt))
     {
@@ -2982,11 +2961,7 @@ gimple_fold_builtin_stpcpy (gimple_stmt_iterator *gsi)
                        tem, build_int_cst (size_type_node, 1));
   gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   gcall *repl = gimple_build_call (fn, 3, dest, src, lenp1);
-  gimple_set_vuse (repl, gimple_vuse (stmt));
-  gimple_set_vdef (repl, gimple_vdef (stmt));
-  if (gimple_vdef (repl)
-      && TREE_CODE (gimple_vdef (repl)) == SSA_NAME)
-    SSA_NAME_DEF_STMT (gimple_vdef (repl)) = repl;
+  gimple_move_vops (repl, stmt);
   gsi_insert_before (gsi, repl, GSI_SAME_STMT);
   /* Replace the result with dest + len.  */
   stmts = NULL;
@@ -4134,9 +4109,7 @@ fold_builtin_atomic_compare_exchange (gimple_stmt_iterator *gsi)
                                  gimple_call_arg (stmt, 5));
   tree lhs = make_ssa_name (ctype);
   gimple_call_set_lhs (g, lhs);
-  gimple_set_vdef (g, gimple_vdef (stmt));
-  gimple_set_vuse (g, gimple_vuse (stmt));
-  SSA_NAME_DEF_STMT (gimple_vdef (g)) = g;
+  gimple_move_vops (g, stmt);
   tree oldlhs = gimple_call_lhs (stmt);
   if (stmt_can_throw_internal (cfun, stmt))
     {
@@ -4315,8 +4288,7 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace)
                      SSA_NAME_DEF_STMT (lhs) = gimple_build_nop ();
                      set_ssa_default_def (cfun, var, lhs);
                    }
-                 gimple_set_vuse (new_stmt, gimple_vuse (stmt));
-                 gimple_set_vdef (new_stmt, gimple_vdef (stmt));
+                 gimple_move_vops (new_stmt, stmt);
                  gsi_replace (gsi, new_stmt, false);
                  return true;
                }
index a0eac87..633ef51 100644 (file)
@@ -2057,6 +2057,18 @@ gimple_copy (gimple *stmt)
   return copy;
 }
 
+/* Move OLD_STMT's vuse and vdef operands to NEW_STMT, on the assumption
+   that OLD_STMT is about to be removed.  */
+
+void
+gimple_move_vops (gimple *new_stmt, gimple *old_stmt)
+{
+  tree vdef = gimple_vdef (old_stmt);
+  gimple_set_vuse (new_stmt, gimple_vuse (old_stmt));
+  gimple_set_vdef (new_stmt, vdef);
+  if (vdef && TREE_CODE (vdef) == SSA_NAME)
+    SSA_NAME_DEF_STMT (vdef) = new_stmt;
+}
 
 /* Return true if statement S has side-effects.  We consider a
    statement to have side effects if:
index c82fdf7..55f5d0d 100644 (file)
@@ -1532,6 +1532,7 @@ void gimple_assign_set_rhs_with_ops (gimple_stmt_iterator *, enum tree_code,
 tree gimple_get_lhs (const gimple *);
 void gimple_set_lhs (gimple *, tree);
 gimple *gimple_copy (gimple *);
+void gimple_move_vops (gimple *, gimple *);
 bool gimple_has_side_effects (const gimple *);
 bool gimple_could_trap_p_1 (gimple *, bool, bool);
 bool gimple_could_trap_p (gimple *);
index 037253a..11908d3 100644 (file)
@@ -452,14 +452,7 @@ ipa_modify_call_arguments (struct cgraph_edge *cs, gcall *stmt,
   gimple_call_set_chain (new_stmt, gimple_call_chain (stmt));
   gimple_call_copy_flags (new_stmt, stmt);
   if (gimple_in_ssa_p (cfun))
-    {
-      gimple_set_vuse (new_stmt, gimple_vuse (stmt));
-      if (gimple_vdef (stmt))
-       {
-         gimple_set_vdef (new_stmt, gimple_vdef (stmt));
-         SSA_NAME_DEF_STMT (gimple_vdef (new_stmt)) = new_stmt;
-       }
-    }
+    gimple_move_vops (new_stmt, stmt);
 
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
index 9e3372f..57eed67 100644 (file)
@@ -1118,9 +1118,7 @@ use_internal_fn (gcall *call)
        {
          gimple_stmt_iterator gsi = gsi_for_stmt (call);
          gcall *new_call = gimple_build_call_internal (IFN_SET_EDOM, 0);
-         gimple_set_vuse (new_call, gimple_vuse (call));
-         gimple_set_vdef (new_call, gimple_vdef (call));
-         SSA_NAME_DEF_STMT (gimple_vdef (new_call)) = new_call;
+         gimple_move_vops (new_call, call);
          gimple_set_location (new_call, gimple_location (call));
          gsi_replace (&gsi, new_call, false);
          call = new_call;
index d9e540f..da67e39 100644 (file)
@@ -2141,9 +2141,7 @@ predicate_load_or_store (gimple_stmt_iterator *gsi, gassign *stmt, tree mask)
       new_stmt
        = gimple_build_call_internal (IFN_MASK_STORE, 4, addr, ptr,
                                      mask, rhs);
-      gimple_set_vuse (new_stmt, gimple_vuse (stmt));
-      gimple_set_vdef (new_stmt, gimple_vdef (stmt));
-      SSA_NAME_DEF_STMT (gimple_vdef (new_stmt)) = new_stmt;
+      gimple_move_vops (new_stmt, stmt);
     }
   gimple_call_set_nothrow (new_stmt, true);
   return new_stmt;
index 4dd7035..f25e6c8 100644 (file)
@@ -2962,12 +2962,10 @@ optimize_atomic_bit_test_and (gimple_stmt_iterator *gsip,
                                    bit, flag);
   gimple_call_set_lhs (g, new_lhs);
   gimple_set_location (g, gimple_location (call));
-  gimple_set_vuse (g, gimple_vuse (call));
-  gimple_set_vdef (g, gimple_vdef (call));
+  gimple_move_vops (g, call);
   bool throws = stmt_can_throw_internal (cfun, call);
   gimple_call_set_nothrow (as_a <gcall *> (g),
                           gimple_call_nothrow_p (as_a <gcall *> (call)));
-  SSA_NAME_DEF_STMT (gimple_vdef (call)) = g;
   gimple_stmt_iterator gsi = *gsip;
   gsi_insert_after (&gsi, g, GSI_NEW_STMT);
   edge e = NULL;
index 3e0b238..5fea155 100644 (file)
@@ -1040,14 +1040,9 @@ pass_cse_reciprocals::execute (function *fun)
                      else
                        stmt2 = gimple_build_call_internal_vec (ifn, args);
                      gimple_call_set_lhs (stmt2, arg1);
-                     if (gimple_vdef (call))
-                       {
-                         gimple_set_vdef (stmt2, gimple_vdef (call));
-                         SSA_NAME_DEF_STMT (gimple_vdef (stmt2)) = stmt2;
-                       }
+                     gimple_move_vops (stmt2, call);
                      gimple_call_set_nothrow (stmt2,
                                               gimple_call_nothrow_p (call));
-                     gimple_set_vuse (stmt2, gimple_vuse (call));
                      gimple_stmt_iterator gsi2 = gsi_for_stmt (call);
                      gsi_replace (&gsi2, stmt2, true);
                    }
index 6b78dc1..0862f83 100644 (file)
@@ -625,8 +625,7 @@ finish_update_gimple_call (gimple_stmt_iterator *si_p, gimple *new_stmt,
 {
   gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt));
   move_ssa_defining_stmt_for_defs (new_stmt, stmt);
-  gimple_set_vuse (new_stmt, gimple_vuse (stmt));
-  gimple_set_vdef (new_stmt, gimple_vdef (stmt));
+  gimple_move_vops (new_stmt, stmt);
   gimple_set_location (new_stmt, gimple_location (stmt));
   if (gimple_block (new_stmt) == NULL_TREE)
     gimple_set_block (new_stmt, gimple_block (stmt));
@@ -706,8 +705,7 @@ update_call_from_tree (gimple_stmt_iterator *si_p, tree expr)
           STRIP_USELESS_TYPE_CONVERSION (expr);
           new_stmt = gimple_build_assign (lhs, expr);
           move_ssa_defining_stmt_for_defs (new_stmt, stmt);
-         gimple_set_vuse (new_stmt, gimple_vuse (stmt));
-         gimple_set_vdef (new_stmt, gimple_vdef (stmt));
+         gimple_move_vops (new_stmt, stmt);
         }
       else if (!TREE_SIDE_EFFECTS (expr))
         {
@@ -732,8 +730,7 @@ update_call_from_tree (gimple_stmt_iterator *si_p, tree expr)
          else
            lhs = create_tmp_var (TREE_TYPE (expr));
           new_stmt = gimple_build_assign (lhs, expr);
-         gimple_set_vuse (new_stmt, gimple_vuse (stmt));
-         gimple_set_vdef (new_stmt, gimple_vdef (stmt));
+         gimple_move_vops (new_stmt, stmt);
           move_ssa_defining_stmt_for_defs (new_stmt, stmt);
         }
       gimple_set_location (new_stmt, gimple_location (stmt));
index 601a6f5..1e2dfe5 100644 (file)
@@ -9510,8 +9510,7 @@ vectorizable_load (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
                    new_stmt = gimple_build_assign (vec_dest, data_ref);
                    new_temp = make_ssa_name (vec_dest, new_stmt);
                    gimple_assign_set_lhs (new_stmt, new_temp);
-                   gimple_set_vdef (new_stmt, gimple_vdef (stmt_info->stmt));
-                   gimple_set_vuse (new_stmt, gimple_vuse (stmt_info->stmt));
+                   gimple_move_vops (new_stmt, stmt_info->stmt);
                    vect_finish_stmt_generation (stmt_info, new_stmt, gsi);
                    msq = new_temp;
 
index 173e6b5..dc18152 100644 (file)
@@ -289,10 +289,7 @@ adjust_simduid_builtins (hash_table<simduid_to_vf> *htab)
                       : BUILT_IN_GOMP_ORDERED_END);
                  gimple *g
                    = gimple_build_call (builtin_decl_explicit (bcode), 0);
-                 tree vdef = gimple_vdef (stmt);
-                 gimple_set_vdef (g, vdef);
-                 SSA_NAME_DEF_STMT (vdef) = g;
-                 gimple_set_vuse (g, gimple_vuse (stmt));
+                 gimple_move_vops (g, stmt);
                  gsi_replace (&i, g, true);
                  continue;
                }