On Wed, 25 Sep 2019 at 23:44, Richard Biener <rguent...@suse.de> wrote:
>
> On Wed, 25 Sep 2019, Prathamesh Kulkarni wrote:
>
> > On Fri, 20 Sep 2019 at 15:20, Jeff Law <l...@redhat.com> wrote:
> > >
> > > On 9/19/19 10:19 AM, Prathamesh Kulkarni wrote:
> > > > Hi,
> > > > For PR91532, the dead store is trivially deleted if we place dse pass
> > > > between ifcvt and vect. Would it be OK to add another instance of dse 
> > > > there ?
> > > > Or should we add an ad-hoc "basic-block dse" sub-pass to ifcvt that
> > > > will clean up the dead store ?
> > > I'd hesitate to add another DSE pass.  If there's one nearby could we
> > > move the existing pass?
> > Well I think the nearest one is just after pass_warn_restrict. Not
> > sure if it's a good
> > idea to move it up from there ?
>
> You'll need it inbetween ifcvt and vect so it would be disabled
> w/o vectorization, so no, that doesn't work.
>
> ifcvt already invokes SEME region value-numbering so if we had
> MESE region DSE it could use that.  Not sure if you feel like
> refactoring DSE to work on regions - it currently uses a DOM
> walk which isn't suited for that.
>
> if-conversion has a little "local" dead predicate compute removal
> thingy (not that I like that), eventually it can be enhanced to
> do the DSE you want?  Eventually it should be moved after the local
> CSE invocation though.
Hi,
Thanks for the suggestions.
For now, would it be OK to do "dse" on loop header in
tree_if_conversion, as in the attached patch ?
The patch does local dse in a new function ifcvt_local_dse instead of
ifcvt_local_dce, because it needed to be done after RPO VN which
eliminates:
Removing dead stmt _ifc__62 = *_55;
and makes the following store dead:
*_55 = _ifc__61;

Thanks,
Prathamesh
>
> Richard.
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index 40ad4c5947a..69dd9d88991 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -120,6 +120,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "fold-const.h"
 #include "tree-ssa-sccvn.h"
 #include "tree-cfgcleanup.h"
+#include "tree-ssa-dse.h"
 
 /* Only handle PHIs with no more arguments unless we are asked to by
    simd pragma.  */
@@ -2975,6 +2976,25 @@ ifcvt_local_dce (basic_block bb)
     }
 }
 
+static void
+ifcvt_local_dse (basic_block bb)
+{
+  gimple_stmt_iterator gsi;
+  for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+    {
+      gimple *stmt = gsi_stmt (gsi);
+      if (gimple_store_p (stmt))
+	{
+	  tree lhs = gimple_get_lhs (stmt);
+	  ao_ref write;
+	  ao_ref_init (&write, lhs);
+	  if (dse_classify_store (&write, stmt, false, NULL)
+	      == DSE_STORE_DEAD)
+	    delete_dead_or_redundant_assignment (&gsi, "dead");
+	}
+    }
+}
+
 /* If-convert LOOP when it is legal.  For the moment this pass has no
    profitability analysis.  Returns non-zero todo flags when something
    changed.  */
@@ -3071,6 +3091,7 @@ tree_if_conversion (class loop *loop, vec<gimple *> *preds)
   bitmap_set_bit (exit_bbs, single_exit (loop)->dest->index);
   bitmap_set_bit (exit_bbs, loop->latch->index);
   todo |= do_rpo_vn (cfun, loop_preheader_edge (loop), exit_bbs);
+  ifcvt_local_dse (loop->header);
   BITMAP_FREE (exit_bbs);
 
   todo |= TODO_cleanup_cfg;
diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
index ba67884a825..0185bcbfce7 100644
--- a/gcc/tree-ssa-dse.c
+++ b/gcc/tree-ssa-dse.c
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "params.h"
 #include "alias.h"
 #include "tree-ssa-loop.h"
+#include "tree-ssa-dse.h"
 
 /* This file implements dead store elimination.
 
@@ -76,21 +77,13 @@ along with GCC; see the file COPYING3.  If not see
    fact, they are the same transformation applied to different views of
    the CFG.  */
 
-static void delete_dead_or_redundant_assignment (gimple_stmt_iterator *, const char *);
+void delete_dead_or_redundant_assignment (gimple_stmt_iterator *, const char *);
 static void delete_dead_or_redundant_call (gimple_stmt_iterator *, const char *);
 
 /* Bitmap of blocks that have had EH statements cleaned.  We should
    remove their dead edges eventually.  */
 static bitmap need_eh_cleanup;
 
-/* Return value from dse_classify_store */
-enum dse_store_status
-{
-  DSE_STORE_LIVE,
-  DSE_STORE_MAYBE_PARTIAL_DEAD,
-  DSE_STORE_DEAD
-};
-
 /* STMT is a statement that may write into memory.  Analyze it and
    initialize WRITE to describe how STMT affects memory.
 
@@ -662,10 +655,10 @@ dse_optimize_redundant_stores (gimple *stmt)
    if only clobber statements influenced the classification result.
    Returns the classification.  */
 
-static dse_store_status
+dse_store_status
 dse_classify_store (ao_ref *ref, gimple *stmt,
 		    bool byte_tracking_enabled, sbitmap live_bytes,
-		    bool *by_clobber_p = NULL)
+		    bool *by_clobber_p)
 {
   gimple *temp;
   int cnt = 0;
@@ -901,7 +894,7 @@ delete_dead_or_redundant_call (gimple_stmt_iterator *gsi, const char *type)
 
 /* Delete a dead store at GSI, which is a gimple assignment. */
 
-static void
+void
 delete_dead_or_redundant_assignment (gimple_stmt_iterator *gsi, const char *type)
 {
   gimple *stmt = gsi_stmt (*gsi);

Reply via email to