This improves compile-time of PR60291 at -O1 from 210s to 85s,
getting remove unused locals out of the profile.  There walking
DECL_INITIAL of globals is quadratic when that is refered to from
multiple functions.  We've had the same issue with
add_referenced_vars when that still existed.

Bootstrapped and tested on x86_64-unknown-linux-gnu, ok for trunk
and branch?

I've verified that I can still properly debug

int **
foo (void)
{
  static int a = 0;
  static int *b = &a;
  static int **c = &b;
  return c;
}
int main()
{
  return **foo();
}

(step into foo and print a, b and c).  Note that even with 4.8
right now

int **
foo (void)
{
  int **q;
    {
      static int a = 0;
      static int *b = &a;
      static int **c = &b;
      q = c;
    }
  return q;
}
int main()
{
  return **foo();
}

is broken (with -O1 -fno-inline, with inlining both cases are
broken).  But that all doesn't regress with the following and
if we fix it then we should fix it another way, not by walking
global initializers.

Thanks,
Richard.

2014-02-21  Richard Biener  <rguent...@suse.de>

        PR middle-end/60291
        * tree-ssa-live.c (mark_all_vars_used_1): Do not walk
        DECL_INITIAL.

Index: gcc/tree-ssa-live.c
===================================================================
*** gcc/tree-ssa-live.c (revision 207960)
--- gcc/tree-ssa-live.c (working copy)
*************** mark_all_vars_used_1 (tree *tp, int *wal
*** 432,443 ****
    /* Only need to mark VAR_DECLS; parameters and return results are not
       eliminated as unused.  */
    if (TREE_CODE (t) == VAR_DECL)
!     {
!       /* When a global var becomes used for the first time also walk its
!          initializer (non global ones don't have any).  */
!       if (set_is_used (t) && is_global_var (t))
!       mark_all_vars_used (&DECL_INITIAL (t));
!     }
    /* remove_unused_scope_block_p requires information about labels
       which are not DECL_IGNORED_P to tell if they might be used in the IL.  */
    else if (TREE_CODE (t) == LABEL_DECL)
--- 432,438 ----
    /* Only need to mark VAR_DECLS; parameters and return results are not
       eliminated as unused.  */
    if (TREE_CODE (t) == VAR_DECL)
!     set_is_used (t);
    /* remove_unused_scope_block_p requires information about labels
       which are not DECL_IGNORED_P to tell if they might be used in the IL.  */
    else if (TREE_CODE (t) == LABEL_DECL)

Reply via email to