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 892f7aa5ef1c7357fc7c9b9b309c0c4eca9eec69..3d3a2fad9040a826241e437b525b0ec6351c7910 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 be83620deee4d9cf2283802c6abad0d12de487a8..c3128e75d8bae103fb169562e048cf19716221c9 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 a0eac8703bd69134502dff0edb384d609a1efdb0..633ef512a199644ab1789525f5e3763b58ca6a83 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 c82fdf7131690b3af9693ff54e23462e3cd427b6..55f5d0d33d979d790d508bc14ac5d54063b06f94 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 037253a87fea0f81b4a04a1f42a34a99fbf88782..11908d31a566945f621949ea53f9cd448db63be2 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 9e3372fe56c3d8df26a9a48f7cbdaaf812e0941d..57eed67b0f6a66561a3ad143d994a5c9f4a458ca 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 d9e540f1d5af9c9a7b8e90367a6431da565d3968..da67e39e03af23506d873b592e7afb43df96ae60 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 4dd703558b1ba00216c12a68b5dccfdc880c73e0..f25e6c8c9a99aa13f68a3fd32b0f99dfa5bdc4d1 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 3e0b238af8e80e1d2d39c16b7a2dccf3d9c5eec6..5fea155b71ba0d18fd28ebd4f365764b6aa5f5e8 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 6b78dc1c06c22dd4987c610932086985be0679ce..0862f83e9a19f1318996e58e05e9981be713e5aa 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 601a6f55fbff388c89f88d994e790aebf2bf960e..1e2dfe5d22dc6715ba0ca633f6ef98ca4abbc797 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 173e6b51652fd023893b38da786ff28f827553b5..dc1815247441768eeca60cc2a147e3050f1b1e0d 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;
                }