From de1923f9f4d5344694c22ca883aeb15caf635734 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 23 Aug 2024 13:44:29 +0200 Subject: [PATCH] tree-optimization/116463 - complex lowering leaves around dead stmts Complex lowering generally replaces existing complex defs with COMPLEX_EXPRs but those might be dead when it can always refer to components from the lattice. This in turn can pessimize followup transforms like forwprop and reassoc, the following makes sure to get rid of dead COMPLEX_EXPRs generated by using simple_dce_from_worklist. PR tree-optimization/116463 * tree-complex.cc: Include tree-ssa-dce.h. (dce_worklist): New global. (update_complex_assignment): Add SSA def to the DCE worklist. (tree_lower_complex): Perform DCE. --- gcc/tree-complex.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gcc/tree-complex.cc b/gcc/tree-complex.cc index dfb45b9d91c..7480c07640e 100644 --- a/gcc/tree-complex.cc +++ b/gcc/tree-complex.cc @@ -46,6 +46,7 @@ along with GCC; see the file COPYING3. If not see #include "case-cfn-macros.h" #include "builtins.h" #include "optabs-tree.h" +#include "tree-ssa-dce.h" /* For each complex ssa name, a lattice value. We're interested in finding out whether a complex number is degenerate in some way, having only real @@ -88,6 +89,9 @@ static vec phis_to_revisit; /* BBs that need EH cleanup. */ static bitmap need_eh_cleanup; +/* SSA defs we should try to DCE. */ +static bitmap dce_worklist; + /* Lookup UID in the complex_variable_components hashtable and return the associated tree. */ static tree @@ -731,6 +735,7 @@ update_complex_assignment (gimple_stmt_iterator *gsi, tree r, tree i) update_stmt (stmt); if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt)) bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index); + bitmap_set_bit (dce_worklist, SSA_NAME_VERSION (gimple_assign_lhs (stmt))); update_complex_components (gsi, gsi_stmt (*gsi), r, i); } @@ -1962,6 +1967,7 @@ tree_lower_complex (void) complex_propagate.ssa_propagate (); need_eh_cleanup = BITMAP_ALLOC (NULL); + dce_worklist = BITMAP_ALLOC (NULL); complex_variable_components = new int_tree_htab_type (10); @@ -2008,6 +2014,9 @@ tree_lower_complex (void) gsi_commit_edge_inserts (); + simple_dce_from_worklist (dce_worklist, need_eh_cleanup); + BITMAP_FREE (dce_worklist); + unsigned todo = gimple_purge_all_dead_eh_edges (need_eh_cleanup) ? TODO_cleanup_cfg : 0; BITMAP_FREE (need_eh_cleanup);