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.

Bootstrapped and tested on x86_64-unknown-linux-gnu, this will cause
the following fallout which is similar to the aarch64 fallout in
PR116463, complex SLP recognition being somewhat fragile.  I'll track
this there.  Pushed.

FAIL: gcc.target/i386/avx512fp16-vector-complex-float.c scan-assembler-not 
vfma
dd[123]*ph[ \\\\t]
FAIL: gcc.target/i386/avx512fp16-vector-complex-float.c 
scan-assembler-times vf
maddcph[ \\\\t] 1
FAIL: gcc.target/i386/part-vect-complexhf.c scan-assembler-times 
vfmaddcph[ \\\\t] 1


        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<gphi *> 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);
-- 
2.43.0

Reply via email to