This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Speedup into SSA (not committed) for PR 8361, PR 15855, PR 13766
- From: Diego Novillo <dnovillo at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Mark Mitchell <mark at codesourcery dot com>
- Date: Thu, 09 Dec 2004 18:06:21 -0500
- Subject: Speedup into SSA (not committed) for PR 8361, PR 15855, PR 13766
- Organization: Red Hat Canada
This patch adds a shortcut to avoid processing statements that don't
need renaming when the renamer is called multiple times.
The compile time benefits of this patch are measurable, and in the
process it uncovered a couple of bugs in SRA and the vectorizer. These
are the compile time speedups I got with this patch:
Into SSA Overall
cc-i-files +18.3% +0.2%
DLV (PR 8361) +15.9% +3.3%
MICO (PR 13766) +21.9% +2.3%
tramp3d (PR ?) +20.9% +7.8%
PR 15855 +26.0% +1.4%
Mark, I'm deferring to you. The patch is only a compile time
improvement and fixes no regressions. If you prefer, I can hold on to
it until mainline is out of the regression-only state.
Thanks. Diego.
2004-12-09 Diego Novillo <dnovillo@redhat.com>
* tree-into-ssa.c (REWRITE_THIS_STMT): Define.
(mark_def_sites): Clear REWRITE_THIS_STMT for statements that
don't need any operands rewritten.
(rewrite_stmt): Ignore statements that don't need to be
rewritten.
(rewrite_operand): Validate that an existing SSA_NAME is
identical to the current reaching definition of the operand.
2004-12-09 Diego Novillo <dnovillo@redhat.com>
* tree-sra.c (mark_all_v_defs): Also mark VUSEs for renaming.
* tree-vectorizer.c (vectorizable_load): Mark call-clobbered
variables for renaming if we just introduced a CALL_EXPR.
Index: tree-into-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-into-ssa.c,v
retrieving revision 2.34
diff -d -c -p -u -r2.34 tree-into-ssa.c
--- tree-into-ssa.c 29 Nov 2004 20:02:07 -0000 2.34
+++ tree-into-ssa.c 9 Dec 2004 22:41:50 -0000
@@ -166,6 +166,12 @@ static inline struct def_blocks_d *get_d
static inline struct def_blocks_d *find_def_blocks_for (tree);
static void htab_statistics (FILE *, htab_t);
+/* Use TREE_VISITED to keep track of which statements we want to
+ rename. When renaming a subset of the variables, not all
+ statements will be processed. This is decided in mark_def_sites. */
+#define REWRITE_THIS_STMT(T) TREE_VISITED (T)
+
+
/* Get the information associated with NAME. */
static inline struct ssa_name_info *
@@ -379,14 +385,20 @@ mark_def_sites (struct dom_walk_data *wa
stmt = bsi_stmt (bsi);
get_stmt_operands (stmt);
+ REWRITE_THIS_STMT (stmt) = 0;
+
/* If a variable is used before being set, then the variable is live
across a block boundary, so mark it live-on-entry to BB. */
- FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE | SSA_OP_VUSE | SSA_OP_VMUSTDEFKILL)
+ FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
+ SSA_OP_USE | SSA_OP_VUSE | SSA_OP_VMUSTDEFKILL)
{
- if (prepare_use_operand_for_rename (use_p, &uid)
- && !TEST_BIT (kills, uid))
- set_livein_block (USE_FROM_PTR (use_p), bb);
+ if (prepare_use_operand_for_rename (use_p, &uid))
+ {
+ REWRITE_THIS_STMT (stmt) = 1;
+ if (!TEST_BIT (kills, uid))
+ set_livein_block (USE_FROM_PTR (use_p), bb);
+ }
}
/* Note that virtual definitions are irrelevant for computing KILLS
@@ -394,7 +406,6 @@ mark_def_sites (struct dom_walk_data *wa
variable. However, the operand of a virtual definitions is a use
of the variable, so it may cause the variable to be considered
live-on-entry. */
-
FOR_EACH_SSA_MAYDEF_OPERAND (def_p, use_p, stmt, iter)
{
if (prepare_use_operand_for_rename (use_p, &uid))
@@ -406,22 +417,24 @@ mark_def_sites (struct dom_walk_data *wa
set_livein_block (USE_FROM_PTR (use_p), bb);
set_def_block (DEF_FROM_PTR (def_p), bb, false, false);
+ REWRITE_THIS_STMT (stmt) = 1;
}
}
- /* Now process the virtual must-defs made by this statement. */
+ /* Now process the defs and must-defs made by this statement. */
FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_DEF | SSA_OP_VMUSTDEF)
{
if (prepare_def_operand_for_rename (def, &uid))
{
set_def_block (def, bb, false, false);
SET_BIT (kills, uid);
+ REWRITE_THIS_STMT (stmt) = 1;
}
}
-
}
-/* Ditto, but works over ssa names. */
+
+/* Same as mark_def_sites, but works over SSA names. */
static void
ssa_mark_def_sites (struct dom_walk_data *walk_data,
@@ -807,7 +820,7 @@ rewrite_add_phi_arguments (struct dom_wa
phi nodes we want to add arguments for. */
static void
-rewrite_virtual_phi_arguments (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
+rewrite_virtual_phi_arguments (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
basic_block bb)
{
edge e;
@@ -1099,6 +1112,11 @@ rewrite_stmt (struct dom_walk_data *walk
stmt = bsi_stmt (si);
ann = stmt_ann (stmt);
+ /* If mark_def_sites decided that we don't need to rewrite this
+ statement, ignore it. */
+ if (!REWRITE_THIS_STMT (stmt))
+ return;
+
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, "Renaming statement ");
@@ -1126,7 +1144,8 @@ rewrite_stmt (struct dom_walk_data *walk
}
}
-/* Ditto, for rewriting ssa names. */
+
+/* Same as rewrite_stmt, for rewriting ssa names. */
static void
ssa_rewrite_stmt (struct dom_walk_data *walk_data,
@@ -1180,8 +1199,21 @@ ssa_rewrite_stmt (struct dom_walk_data *
static inline void
rewrite_operand (use_operand_p op_p)
{
- if (TREE_CODE (USE_FROM_PTR (op_p)) != SSA_NAME)
- SET_USE (op_p, get_reaching_def (USE_FROM_PTR (op_p)));
+ tree var = USE_FROM_PTR (op_p);
+ if (TREE_CODE (var) != SSA_NAME)
+ SET_USE (op_p, get_reaching_def (var));
+ else
+ {
+#if defined ENABLE_CHECKING
+ /* If we get to this point, VAR is an SSA_NAME. If VAR's symbol
+ was marked for renaming, make sure that its reaching
+ definition is VAR itself. Otherwise, something has gone
+ wrong. */
+ tree sym = SSA_NAME_VAR (var);
+ if (bitmap_bit_p (vars_to_rename, var_ann (sym)->uid))
+ gcc_assert (var == get_reaching_def (SSA_NAME_VAR (var)));
+#endif
+ }
}
/* Register DEF (an SSA_NAME) to be a new definition for its underlying
@@ -1509,8 +1541,9 @@ mark_def_site_blocks (void)
/* We no longer need this bitmap, clear and free it. */
sbitmap_free (mark_def_sites_global_data.kills);
-
}
+
+
/* Main entry point into the SSA builder. The renaming process
proceeds in five main phases:
Index: tree-sra.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-sra.c,v
retrieving revision 2.46
diff -d -c -p -u -r2.46 tree-sra.c
--- tree-sra.c 24 Nov 2004 20:21:29 -0000 2.46
+++ tree-sra.c 9 Dec 2004 22:41:50 -0000
@@ -1417,7 +1417,7 @@ mark_all_v_defs (tree stmt)
get_stmt_operands (stmt);
- FOR_EACH_SSA_TREE_OPERAND (sym, stmt, iter, SSA_OP_VIRTUAL_DEFS)
+ FOR_EACH_SSA_TREE_OPERAND (sym, stmt, iter, SSA_OP_ALL_VIRTUALS)
{
if (TREE_CODE (sym) == SSA_NAME)
sym = SSA_NAME_VAR (sym);
Index: tree-vectorizer.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-vectorizer.c,v
retrieving revision 2.47
diff -d -c -p -u -r2.47 tree-vectorizer.c
--- tree-vectorizer.c 2 Dec 2004 14:00:30 -0000 2.47
+++ tree-vectorizer.c 9 Dec 2004 22:41:51 -0000
@@ -2633,6 +2633,9 @@ vectorizable_load (tree stmt, block_stmt
{
/* Create permutation mask, if required, in loop preheader. */
tree builtin_decl;
+ unsigned i;
+ bitmap_iterator bi;
+
params = build_tree_list (NULL_TREE, init_addr);
vec_dest = vect_create_destination_var (scalar_dest, vectype);
builtin_decl = targetm.vectorize.builtin_mask_for_load ();
@@ -2643,6 +2646,14 @@ vectorizable_load (tree stmt, block_stmt
new_bb = bsi_insert_on_edge_immediate (pe, new_stmt);
gcc_assert (!new_bb);
magic = TREE_OPERAND (new_stmt, 0);
+
+ /* Since we have just created a CALL_EXPR, we may need to
+ rename call-clobbered variables. */
+ EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars, 0, i, bi)
+ {
+ tree var = referenced_var (i);
+ bitmap_set_bit (vars_to_rename, var_ann (var)->uid);
+ }
}
else
{