http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50317

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-11-28 
13:11:49 UTC ---
Created attachment 25933
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25933
gcc47-pr50317-1.patch

One way to fix this regression is schedule another update_addresses_taken
before cddce.  Already in *copyprop1 the var has address taken only solely in
debug stmts, and by dropping TREE_ADDRESSABLE on it the right thing happens
(except that {CLOBBER} stuff messes it up, see patch I'm going to attach
momentarily).

I've tried:

--- gcc/tree-ssa-dce.c.jj 2011-11-08 23:35:12.000000000 +0100
+++ gcc/tree-ssa-dce.c      2011-11-28 12:35:55.745657320 +0100
@@ -1215,6 +1215,25 @@ remove_dead_stmt (gimple_stmt_iterator *
          ei_next (&ei);
     }

+  /* If this is a store into a variable that is being optimized away,
+     add a debug bind stmt if possible.  */
+  if (MAY_HAVE_DEBUG_STMTS
+      && gimple_assign_single_p (stmt)
+      && is_gimple_val (gimple_assign_rhs1 (stmt)))
+    {
+      tree lhs = gimple_assign_lhs (stmt);
+      if ((TREE_CODE (lhs) == VAR_DECL || TREE_CODE (lhs) == PARM_DECL)
+         && !DECL_IGNORED_P (lhs)
+         && is_gimple_reg_type (TREE_TYPE (lhs))
+         && !DECL_HAS_VALUE_EXPR_P (lhs))
+       {
+         tree rhs = gimple_assign_rhs1 (stmt);
+         gimple note
+           = gimple_build_debug_bind (lhs, unshare_expr (rhs), stmt);
+         gsi_insert_after (i, note, GSI_SAME_STMT);
+       }
+    }
+
   unlink_stmt_vdef (stmt);
   gsi_remove (i, true);
   release_defs (stmt);

as an alternative, but leads to ICEs, at some later point we'd need to
somewhere determine if the var mentioned in the debug stmts on the RHS which is
still TREE_ADDRESSABLE is ever referenced in non-debug stmts or not.  If not,
we'd want to drop TREE_ADDRESSABLE bit from it, otherwise e.g. at expansion
time we could just ignore the debug stmt, because it is not
target_for_debug_bind when it is TREE_ADDRESSABLE.

Reply via email to