Add a gimple_move_vops helper function
Richard Sandiford
richard.sandiford@arm.com
Mon Aug 5 08:49:00 GMT 2019
I needed to add another instance of this idiom, so thought it'd
be worth having a helper function.
Tested on aarch64-linux-gnu, armeb-eabi and x86_64-linux-gnu.
OK to install?
Richard
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.
Index: gcc/gimple.h
===================================================================
--- gcc/gimple.h 2019-07-29 09:39:50.038162991 +0100
+++ gcc/gimple.h 2019-08-05 09:47:38.821896600 +0100
@@ -1532,6 +1532,7 @@ void gimple_assign_set_rhs_with_ops (gim
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: gcc/gimple.c
===================================================================
--- gcc/gimple.c 2019-07-29 09:39:50.034163022 +0100
+++ gcc/gimple.c 2019-08-05 09:47:38.821896600 +0100
@@ -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: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c 2019-07-12 11:33:27.712037291 +0100
+++ gcc/gimple-fold.c 2019-08-05 09:47:38.821896600 +0100
@@ -641,14 +641,7 @@ replace_call_with_call_and_fold (gimple_
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_st
= 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_st
= 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_
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_
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 (gi
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 *
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: gcc/ipa-param-manipulation.c
===================================================================
--- gcc/ipa-param-manipulation.c 2019-03-08 18:14:27.289004209 +0000
+++ gcc/ipa-param-manipulation.c 2019-08-05 09:47:38.821896600 +0100
@@ -452,14 +452,7 @@ ipa_modify_call_arguments (struct cgraph
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: gcc/tree-call-cdce.c
===================================================================
--- gcc/tree-call-cdce.c 2019-05-29 10:49:38.836703961 +0100
+++ gcc/tree-call-cdce.c 2019-08-05 09:47:38.821896600 +0100
@@ -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: gcc/tree-if-conv.c
===================================================================
--- gcc/tree-if-conv.c 2019-07-10 19:41:26.379898156 +0100
+++ gcc/tree-if-conv.c 2019-08-05 09:47:38.825896569 +0100
@@ -2141,9 +2141,7 @@ predicate_load_or_store (gimple_stmt_ite
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: gcc/tree-ssa-ccp.c
===================================================================
--- gcc/tree-ssa-ccp.c 2019-07-10 19:41:22.195931663 +0100
+++ gcc/tree-ssa-ccp.c 2019-08-05 09:47:38.825896569 +0100
@@ -2962,12 +2962,10 @@ optimize_atomic_bit_test_and (gimple_stm
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: gcc/tree-ssa-math-opts.c
===================================================================
--- gcc/tree-ssa-math-opts.c 2019-07-30 11:59:24.356803180 +0100
+++ gcc/tree-ssa-math-opts.c 2019-08-05 09:47:38.825896569 +0100
@@ -1040,14 +1040,9 @@ pass_cse_reciprocals::execute (function
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: gcc/tree-ssa-propagate.c
===================================================================
--- gcc/tree-ssa-propagate.c 2019-03-08 18:15:26.824777889 +0000
+++ gcc/tree-ssa-propagate.c 2019-08-05 09:47:38.825896569 +0100
@@ -625,8 +625,7 @@ finish_update_gimple_call (gimple_stmt_i
{
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_itera
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_itera
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: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c 2019-07-19 12:22:08.096215815 +0100
+++ gcc/tree-vect-stmts.c 2019-08-05 09:47:38.829896542 +0100
@@ -9510,8 +9510,7 @@ vectorizable_load (stmt_vec_info stmt_in
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: gcc/tree-vectorizer.c
===================================================================
--- gcc/tree-vectorizer.c 2019-07-10 19:41:26.363898284 +0100
+++ gcc/tree-vectorizer.c 2019-08-05 09:47:38.829896542 +0100
@@ -289,10 +289,7 @@ adjust_simduid_builtins (hash_table<simd
: 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;
}
More information about the Gcc-patches
mailing list