https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90273

--- Comment #18 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to rsand...@gcc.gnu.org from comment #17)
> Created attachment 46261 [details]
> Doing the removal in find_obviously_necessary_stmts
> 
> Just for the record: I'd written this over the weekend for completely
> unrelated reasons (was looking at debug info, and wanted to replicate the
> DCE that is already done in RTL).  It doesn't include the DEBUG_EXPR_DECL
> stuff, so obviously can't go in as-is, but it means that we never even add
> the redundant instructions to the worklist.

Yeah, that looks nearly equivalent (same issue with DEBUG_EXPR_DECLs though).

I think doing it in eliminate_unnecessary_stmts is slightly better for the
case where we come from 

  # DEBUG i => NULL;
  i_3 = 1;
  # DEBUG i => i_3;

and are about to DCE i_3 (I think that's not handled by my patch either
without further tweaks).  No debug-stmt support in the GIMPLE FE right now
so not so easy to test atm.  For 

int main()
{
  int i;
  i = 1, i = 2;
  return i+1;
}

with -O -g -fdisable-tree-ccp1 -fdisable-tree-fre1 -fdisable-tree-evrp we
go from

  <bb 2> :
  # DEBUG BEGIN_STMT
  # DEBUG BEGIN_STMT
  i_1 = 1;
  # DEBUG i => i_1
  i_2 = 2;
  # DEBUG i => i_2
  # DEBUG BEGIN_STMT
  _3 = 3;
  return 3;

after DSE1 to

  <bb 2> :
  # DEBUG BEGIN_STMT
  # DEBUG BEGIN_STMT
  # DEBUG i => 1
  # DEBUG i => 2
  # DEBUG BEGIN_STMT
  return 3;

after CDDCE1 which could be improved to just # DEBUG i => 2 (note the
missing DEBUG BEGIN_STMT for compound stmts).  The following would do
that trick (doing a bit more debug DCE on the testcase in this PR)

Index: gcc/tree-ssa-dce.c
===================================================================
--- gcc/tree-ssa-dce.c  (revision 270645)
+++ gcc/tree-ssa-dce.c  (working copy)
@@ -1282,11 +1283,15 @@ eliminate_unnecessary_stmts (void)
              if (!is_gimple_debug (stmt))
                something_changed = true;
              remove_dead_stmt (&gsi, bb, to_remove_edges);
+             continue;
            }
          else if (is_gimple_call (stmt))
            {

Reply via email to