public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/vrull/heads/slp-improvements)] Compact SSA names after every pass
@ 2024-01-29 23:30 Philipp Tomsich
  0 siblings, 0 replies; 2+ messages in thread
From: Philipp Tomsich @ 2024-01-29 23:30 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8601c6fefea82d7eb1da793709e1e3f2d136de5a

commit 8601c6fefea82d7eb1da793709e1e3f2d136de5a
Author: Manolis Tsamis <manolis.tsamis@vrull.eu>
Date:   Mon Jan 29 13:16:36 2024 +0100

    Compact SSA names after every pass
    
    GCC uses an SSA freelist to recycle unused SSA names in order to
    reduce the number of allocated names. While useful, this can result in
    codegen changes for virtually the same source or GIMPLE code,
    especially in the presence of dead code elimination.
    
    This commit runs the SSA compaction code (that also cleans up the free
    list) after every pass run. As a result we get improved normalization
    and more consistent code generation for part of the compiler that can
    potentially be affected by SSA name ordering (one such case was the
    SLP vectorizer).
    
    Some initial measurements show that this may have positive effects on
    compilation times.
    
    Ref #355
    
    Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>

Diff:
---
 gcc/passes.cc        |  5 ++++-
 gcc/passes.def       |  1 -
 gcc/tree-pass.h      |  1 -
 gcc/tree-ssanames.cc | 48 +-----------------------------------------------
 gcc/tree-ssanames.h  |  1 +
 5 files changed, 6 insertions(+), 50 deletions(-)

diff --git a/gcc/passes.cc b/gcc/passes.cc
index 41e0add06c91..37cf104a986d 100644
--- a/gcc/passes.cc
+++ b/gcc/passes.cc
@@ -2144,7 +2144,10 @@ execute_todo (unsigned int flags)
   /* At this point we should not have any unreachable code in the
      CFG, so it is safe to flush the pending freelist for SSA_NAMES.  */
   if (cfun && cfun->gimple_df)
-    flush_ssaname_freelist ();
+    {
+      flush_ssaname_freelist ();
+      release_free_names_and_compact_live_names (cfun);
+    }
 
   /* Always remove functions just as before inlining: IPA passes might be
      interested to see bodies of extern inline functions that are not inlined
diff --git a/gcc/passes.def b/gcc/passes.def
index 1cbbd4130970..8db7cd375745 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -111,7 +111,6 @@ along with GCC; see the file COPYING3.  If not see
 	  NEXT_PASS (pass_split_functions);
 	  NEXT_PASS (pass_strip_predict_hints, true /* early_p */);
       POP_INSERT_PASSES ()
-      NEXT_PASS (pass_release_ssa_names);
       NEXT_PASS (pass_rebuild_cgraph_edges);
       NEXT_PASS (pass_local_fn_summary);
   POP_INSERT_PASSES ()
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index 29267589eeb3..a9ae930092a3 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -651,7 +651,6 @@ extern rtl_opt_pass *make_pass_set_nothrow_function_flags (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_dwarf2_frame (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_final (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_rtl_seqabstr (gcc::context *ctxt);
-extern gimple_opt_pass *make_pass_release_ssa_names (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_early_inline (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_local_fn_summary (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_update_address_taken (gcc::context *ctxt);
diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index 1753a421a0ba..52dd91bb6b9b 100644
--- a/gcc/tree-ssanames.cc
+++ b/gcc/tree-ssanames.cc
@@ -850,7 +850,7 @@ replace_ssa_name_symbol (tree ssa_name, tree sym)
 /* Release the vector of free SSA_NAMEs and compact the vector of SSA_NAMEs
    that are live.  */
 
-static void
+void
 release_free_names_and_compact_live_names (function *fun)
 {
   unsigned i, j;
@@ -883,52 +883,6 @@ release_free_names_and_compact_live_names (function *fun)
 	     n, n * 100.0 / num_ssa_names, i - j);
 }
 
-/* Return SSA names that are unused to GGC memory and compact the SSA
-   version namespace.  This is used to keep footprint of compiler during
-   interprocedural optimization.  */
-
-namespace {
-
-const pass_data pass_data_release_ssa_names =
-{
-  GIMPLE_PASS, /* type */
-  "release_ssa", /* name */
-  OPTGROUP_NONE, /* optinfo_flags */
-  TV_TREE_SSA_OTHER, /* tv_id */
-  PROP_ssa, /* properties_required */
-  0, /* properties_provided */
-  0, /* properties_destroyed */
-  TODO_remove_unused_locals, /* todo_flags_start */
-  0, /* todo_flags_finish */
-};
-
-class pass_release_ssa_names : public gimple_opt_pass
-{
-public:
-  pass_release_ssa_names (gcc::context *ctxt)
-    : gimple_opt_pass (pass_data_release_ssa_names, ctxt)
-  {}
-
-  /* opt_pass methods: */
-  unsigned int execute (function *) final override;
-
-}; // class pass_release_ssa_names
-
-unsigned int
-pass_release_ssa_names::execute (function *fun)
-{
-  release_free_names_and_compact_live_names (fun);
-  return 0;
-}
-
-} // anon namespace
-
-gimple_opt_pass *
-make_pass_release_ssa_names (gcc::context *ctxt)
-{
-  return new pass_release_ssa_names (ctxt);
-}
-
 /* Save and restore of flow sensitive information. */
 
 /* Save off the flow sensitive info from NAME. */
diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h
index 824d8c8c2a09..89ee9ebe52e4 100644
--- a/gcc/tree-ssanames.h
+++ b/gcc/tree-ssanames.h
@@ -87,6 +87,7 @@ extern void reset_flow_sensitive_info_in_bb (basic_block);
 extern void release_defs (gimple *);
 extern void replace_ssa_name_symbol (tree, tree);
 extern void flush_ssaname_freelist (void);
+extern void release_free_names_and_compact_live_names (struct function *);
 
 
 /* Return an SSA_NAME node for variable VAR defined in statement STMT

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gcc(refs/vendors/vrull/heads/slp-improvements)] Compact SSA names after every pass
@ 2024-02-27 13:37 Philipp Tomsich
  0 siblings, 0 replies; 2+ messages in thread
From: Philipp Tomsich @ 2024-02-27 13:37 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2caf1cf12826fa7269078f18ef2a123a3c99253a

commit 2caf1cf12826fa7269078f18ef2a123a3c99253a
Author: Manolis Tsamis <manolis.tsamis@vrull.eu>
Date:   Mon Jan 29 13:16:36 2024 +0100

    Compact SSA names after every pass
    
    GCC uses an SSA freelist to recycle unused SSA names in order to
    reduce the number of allocated names. While useful, this can result in
    codegen changes for virtually the same source or GIMPLE code,
    especially in the presence of dead code elimination.
    
    This commit runs the SSA compaction code (that also cleans up the free
    list) after every pass run. As a result we get improved normalization
    and more consistent code generation for part of the compiler that can
    potentially be affected by SSA name ordering (one such case was the
    SLP vectorizer).
    
    Some initial measurements show that this may have positive effects on
    compilation times.
    
    Ref #355
    
    Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>

Diff:
---
 gcc/passes.cc        |  5 ++++-
 gcc/passes.def       |  1 -
 gcc/tree-pass.h      |  1 -
 gcc/tree-ssanames.cc | 48 +-----------------------------------------------
 gcc/tree-ssanames.h  |  1 +
 5 files changed, 6 insertions(+), 50 deletions(-)

diff --git a/gcc/passes.cc b/gcc/passes.cc
index 41e0add06c9..37cf104a986 100644
--- a/gcc/passes.cc
+++ b/gcc/passes.cc
@@ -2144,7 +2144,10 @@ execute_todo (unsigned int flags)
   /* At this point we should not have any unreachable code in the
      CFG, so it is safe to flush the pending freelist for SSA_NAMES.  */
   if (cfun && cfun->gimple_df)
-    flush_ssaname_freelist ();
+    {
+      flush_ssaname_freelist ();
+      release_free_names_and_compact_live_names (cfun);
+    }
 
   /* Always remove functions just as before inlining: IPA passes might be
      interested to see bodies of extern inline functions that are not inlined
diff --git a/gcc/passes.def b/gcc/passes.def
index 1cbbd413097..8db7cd37574 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -111,7 +111,6 @@ along with GCC; see the file COPYING3.  If not see
 	  NEXT_PASS (pass_split_functions);
 	  NEXT_PASS (pass_strip_predict_hints, true /* early_p */);
       POP_INSERT_PASSES ()
-      NEXT_PASS (pass_release_ssa_names);
       NEXT_PASS (pass_rebuild_cgraph_edges);
       NEXT_PASS (pass_local_fn_summary);
   POP_INSERT_PASSES ()
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index 29267589eeb..a9ae930092a 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -651,7 +651,6 @@ extern rtl_opt_pass *make_pass_set_nothrow_function_flags (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_dwarf2_frame (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_final (gcc::context *ctxt);
 extern rtl_opt_pass *make_pass_rtl_seqabstr (gcc::context *ctxt);
-extern gimple_opt_pass *make_pass_release_ssa_names (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_early_inline (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_local_fn_summary (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_update_address_taken (gcc::context *ctxt);
diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index 1753a421a0b..52dd91bb6b9 100644
--- a/gcc/tree-ssanames.cc
+++ b/gcc/tree-ssanames.cc
@@ -850,7 +850,7 @@ replace_ssa_name_symbol (tree ssa_name, tree sym)
 /* Release the vector of free SSA_NAMEs and compact the vector of SSA_NAMEs
    that are live.  */
 
-static void
+void
 release_free_names_and_compact_live_names (function *fun)
 {
   unsigned i, j;
@@ -883,52 +883,6 @@ release_free_names_and_compact_live_names (function *fun)
 	     n, n * 100.0 / num_ssa_names, i - j);
 }
 
-/* Return SSA names that are unused to GGC memory and compact the SSA
-   version namespace.  This is used to keep footprint of compiler during
-   interprocedural optimization.  */
-
-namespace {
-
-const pass_data pass_data_release_ssa_names =
-{
-  GIMPLE_PASS, /* type */
-  "release_ssa", /* name */
-  OPTGROUP_NONE, /* optinfo_flags */
-  TV_TREE_SSA_OTHER, /* tv_id */
-  PROP_ssa, /* properties_required */
-  0, /* properties_provided */
-  0, /* properties_destroyed */
-  TODO_remove_unused_locals, /* todo_flags_start */
-  0, /* todo_flags_finish */
-};
-
-class pass_release_ssa_names : public gimple_opt_pass
-{
-public:
-  pass_release_ssa_names (gcc::context *ctxt)
-    : gimple_opt_pass (pass_data_release_ssa_names, ctxt)
-  {}
-
-  /* opt_pass methods: */
-  unsigned int execute (function *) final override;
-
-}; // class pass_release_ssa_names
-
-unsigned int
-pass_release_ssa_names::execute (function *fun)
-{
-  release_free_names_and_compact_live_names (fun);
-  return 0;
-}
-
-} // anon namespace
-
-gimple_opt_pass *
-make_pass_release_ssa_names (gcc::context *ctxt)
-{
-  return new pass_release_ssa_names (ctxt);
-}
-
 /* Save and restore of flow sensitive information. */
 
 /* Save off the flow sensitive info from NAME. */
diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h
index 824d8c8c2a0..89ee9ebe52e 100644
--- a/gcc/tree-ssanames.h
+++ b/gcc/tree-ssanames.h
@@ -87,6 +87,7 @@ extern void reset_flow_sensitive_info_in_bb (basic_block);
 extern void release_defs (gimple *);
 extern void replace_ssa_name_symbol (tree, tree);
 extern void flush_ssaname_freelist (void);
+extern void release_free_names_and_compact_live_names (struct function *);
 
 
 /* Return an SSA_NAME node for variable VAR defined in statement STMT

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-27 13:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-29 23:30 [gcc(refs/vendors/vrull/heads/slp-improvements)] Compact SSA names after every pass Philipp Tomsich
2024-02-27 13:37 Philipp Tomsich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).