> On Mon, 23 Nov 2020, Jan Hubicka wrote:
> 
> > Hi,
> > tree-streamer-in currently calls init_tree_ssa that calls init_ssanames
> > that allocates space in ssa_names array for 50 names.  Later it streams
> > in the count and calls init_tree_ssa again, this time with correct
> > count, which is rounded up to 50 and allocated again leaking the first
> > array.
> > 
> > This patch fixes it by adding extra argument to init_tree_ssa specifing
> > whether ssa names should be initialized.  There are few places where we
> > initialize ssa and only lto streaming is special, so i think extra arg
> > works well here.
> > 
> > I am not quite sure about the 50MB default.  I think it was made before
> > ggc_free was implemented (so resizing vectors was expensive) and when we
> > had only one function in SSA form at a time.  Most of functions in C++
> > will probably need fewer than 50 SSA names until inlining.
> > 
> > This saves 21MB of WPA linking libxul.
> 
> Why do we input SSA names at WPA?

To ICF compare function bodies. It tends to load tons of small bodies.
We also may load body when merging BB profile etc.
> 
> > Bootstrapping/regtesting x86_64-linux, OK if it suceeds?
> 
> I think calling init_ssanames again is bogus.  Please simply
> do that in input_ssa_names after we know how many we need
> adding a number of SSA names to reserve argument to init_tree_ssa
> and passing that down instead.

I tried that originally but it hit ICE in init_ssa_operands.  Seems that
reloacating them is last change I need though.  Does this look better?

        * tree-cfg.c (remove_bb): Release SSA defs.
        * tree-ssa.c (verify_flow_sensitive_alias_info): Do not walk dead nodes.
        * tree-tailcall.c (eliminate_tail_call): Release SSA name.
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.47
diff -c -3 -p -r2.47 tree-cfg.c
*** tree-cfg.c  6 Sep 2004 10:07:56 -0000       2.47
--- tree-cfg.c  7 Sep 2004 13:26:46 -0000
*************** remove_bb (basic_block bb)
*** 1818,1823 ****
--- 1818,1824 ----
    for (i = bsi_start (bb); !bsi_end_p (i); bsi_remove (&i))
      {
        tree stmt = bsi_stmt (i);
+       release_defs (stmt);
  
        set_bb_for_stmt (stmt, NULL);
  
Index: tree-tailcall.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-tailcall.c,v
retrieving revision 2.23
diff -c -3 -p -r2.23 tree-tailcall.c
*** tree-tailcall.c     6 Sep 2004 10:08:13 -0000       2.23
--- tree-tailcall.c     7 Sep 2004 13:26:47 -0000
*************** eliminate_tail_call (struct tailcall *t)
*** 681,692 ****
    bsi_next (&bsi);
    while (!bsi_end_p (bsi))
      {
        /* Do not remove the return statement, so that redirect_edge_and_branch
         sees how the block ends.  */
!       if (TREE_CODE (bsi_stmt (bsi)) == RETURN_EXPR)
        break;
  
        bsi_remove (&bsi);
      }
  
    /* Replace the call by a jump to the start of function.  */
--- 681,694 ----
    bsi_next (&bsi);
    while (!bsi_end_p (bsi))
      {
+       tree t = bsi_stmt (bsi);
        /* Do not remove the return statement, so that redirect_edge_and_branch
         sees how the block ends.  */
!       if (TREE_CODE (t) == RETURN_EXPR)
        break;
  
        bsi_remove (&bsi);
+       release_defs (t);
      }
  
    /* Replace the call by a jump to the start of function.  */
*************** eliminate_tail_call (struct tailcall *t)
*** 772,777 ****
--- 774,780 ----
      }
  
    bsi_remove (&t->call_bsi);
+   release_defs (call);
  }
  
  /* Optimizes the tailcall described by T.  If OPT_TAILCALLS is true, also

Reply via email to