LCOV - code coverage report
Current view: top level - gcc - ipa-fnsummary.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.4 % 2672 2576
Test Date: 2026-03-28 14:25:54 Functions: 98.9 % 94 93
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Function summary pass.
       2              :    Copyright (C) 2003-2026 Free Software Foundation, Inc.
       3              :    Contributed by Jan Hubicka
       4              : 
       5              : This file is part of GCC.
       6              : 
       7              : GCC is free software; you can redistribute it and/or modify it under
       8              : the terms of the GNU General Public License as published by the Free
       9              : Software Foundation; either version 3, or (at your option) any later
      10              : version.
      11              : 
      12              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15              : for more details.
      16              : 
      17              : You should have received a copy of the GNU General Public License
      18              : along with GCC; see the file COPYING3.  If not see
      19              : <http://www.gnu.org/licenses/>.  */
      20              : 
      21              : /* Analysis of function bodies used by inter-procedural passes
      22              : 
      23              :    We estimate for each function
      24              :      - function body size and size after specializing into given context
      25              :      - average function execution time in a given context
      26              :      - function frame size
      27              :    For each call
      28              :      - call statement size, time and how often the parameters change
      29              : 
      30              :    ipa_fn_summary data structures store above information locally (i.e.
      31              :    parameters of the function itself) and globally (i.e. parameters of
      32              :    the function created by applying all the inline decisions already
      33              :    present in the callgraph).
      34              : 
      35              :    We provide access to the ipa_fn_summary data structure and
      36              :    basic logic updating the parameters when inlining is performed.
      37              : 
      38              :    The summaries are context sensitive.  Context means
      39              :      1) partial assignment of known constant values of operands
      40              :      2) whether function is inlined into the call or not.
      41              :    It is easy to add more variants.  To represent function size and time
      42              :    that depends on context (i.e. it is known to be optimized away when
      43              :    context is known either by inlining or from IP-CP and cloning),
      44              :    we use predicates.
      45              : 
      46              :    estimate_edge_size_and_time can be used to query
      47              :    function size/time in the given context.  ipa_merge_fn_summary_after_inlining merges
      48              :    properties of caller and callee after inlining.
      49              : 
      50              :    Finally pass_inline_parameters is exported.  This is used to drive
      51              :    computation of function parameters used by the early inliner. IPA
      52              :    inlined performs analysis via its analyze_function method. */
      53              : 
      54              : #include "config.h"
      55              : #define INCLUDE_VECTOR
      56              : #include "system.h"
      57              : #include "coretypes.h"
      58              : #include "backend.h"
      59              : #include "target.h"
      60              : #include "tree.h"
      61              : #include "gimple.h"
      62              : #include "alloc-pool.h"
      63              : #include "tree-pass.h"
      64              : #include "ssa.h"
      65              : #include "tree-streamer.h"
      66              : #include "cgraph.h"
      67              : #include "diagnostic.h"
      68              : #include "fold-const.h"
      69              : #include "print-tree.h"
      70              : #include "tree-inline.h"
      71              : #include "gimple-pretty-print.h"
      72              : #include "cfganal.h"
      73              : #include "gimple-iterator.h"
      74              : #include "tree-cfg.h"
      75              : #include "tree-ssa-loop-niter.h"
      76              : #include "tree-ssa-loop.h"
      77              : #include "symbol-summary.h"
      78              : #include "sreal.h"
      79              : #include "ipa-cp.h"
      80              : #include "ipa-prop.h"
      81              : #include "ipa-fnsummary.h"
      82              : #include "cfgloop.h"
      83              : #include "tree-scalar-evolution.h"
      84              : #include "ipa-utils.h"
      85              : #include "cfgexpand.h"
      86              : #include "gimplify.h"
      87              : #include "stringpool.h"
      88              : #include "attribs.h"
      89              : #include "tree-into-ssa.h"
      90              : #include "symtab-clones.h"
      91              : #include "gimple-range.h"
      92              : #include "tree-dfa.h"
      93              : 
      94              : /* Summaries.  */
      95              : fast_function_summary <ipa_fn_summary *, va_gc> *ipa_fn_summaries;
      96              : fast_function_summary <ipa_size_summary *, va_heap> *ipa_size_summaries;
      97              : fast_call_summary <ipa_call_summary *, va_heap> *ipa_call_summaries;
      98              : 
      99              : /* Edge predicates goes here.  */
     100              : static object_allocator<ipa_predicate> edge_predicate_pool ("edge predicates");
     101              : 
     102              : 
     103              : /* Dump IPA hints.  */
     104              : void
     105          185 : ipa_dump_hints (FILE *f, ipa_hints hints)
     106              : {
     107          185 :   if (!hints)
     108              :     return;
     109          148 :   fprintf (f, "IPA hints:");
     110          148 :   if (hints & INLINE_HINT_indirect_call)
     111              :     {
     112           23 :       hints &= ~INLINE_HINT_indirect_call;
     113           23 :       fprintf (f, " indirect_call");
     114              :     }
     115          148 :   if (hints & INLINE_HINT_loop_iterations)
     116              :     {
     117            3 :       hints &= ~INLINE_HINT_loop_iterations;
     118            3 :       fprintf (f, " loop_iterations");
     119              :     }
     120          148 :   if (hints & INLINE_HINT_loop_stride)
     121              :     {
     122            3 :       hints &= ~INLINE_HINT_loop_stride;
     123            3 :       fprintf (f, " loop_stride");
     124              :     }
     125          148 :   if (hints & INLINE_HINT_same_scc)
     126              :     {
     127            4 :       hints &= ~INLINE_HINT_same_scc;
     128            4 :       fprintf (f, " same_scc");
     129              :     }
     130          148 :   if (hints & INLINE_HINT_in_scc)
     131              :     {
     132           11 :       hints &= ~INLINE_HINT_in_scc;
     133           11 :       fprintf (f, " in_scc");
     134              :     }
     135          148 :   if (hints & INLINE_HINT_cross_module)
     136              :     {
     137            2 :       hints &= ~INLINE_HINT_cross_module;
     138            2 :       fprintf (f, " cross_module");
     139              :     }
     140          148 :   if (hints & INLINE_HINT_declared_inline)
     141              :     {
     142          122 :       hints &= ~INLINE_HINT_declared_inline;
     143          122 :       fprintf (f, " declared_inline");
     144              :     }
     145          148 :   if (hints & INLINE_HINT_known_hot)
     146              :     {
     147            1 :       hints &= ~INLINE_HINT_known_hot;
     148            1 :       fprintf (f, " known_hot");
     149              :     }
     150          148 :   if (hints & INLINE_HINT_builtin_constant_p)
     151              :     {
     152            4 :       hints &= ~INLINE_HINT_builtin_constant_p;
     153            4 :       fprintf (f, " builtin_constant_p");
     154              :     }
     155          148 :   gcc_assert (!hints);
     156              : }
     157              : 
     158              : 
     159              : /* Record SIZE and TIME to SUMMARY.
     160              :    The accounted code will be executed when EXEC_PRED is true.
     161              :    When NONCONST_PRED is false the code will evaluate to constant and
     162              :    will get optimized out in specialized clones of the function.
     163              :    If CALL is true account to call_size_time_table rather than
     164              :    size_time_table.   */
     165              : 
     166              : void
     167    134370491 : ipa_fn_summary::account_size_time (int size, sreal time,
     168              :                                    const ipa_predicate &exec_pred,
     169              :                                    const ipa_predicate &nonconst_pred_in,
     170              :                                    bool call)
     171              : {
     172    134370491 :   size_time_entry *e;
     173    134370491 :   bool found = false;
     174    134370491 :   int i;
     175    134370491 :   ipa_predicate nonconst_pred;
     176    134370491 :   vec<size_time_entry> *table = call ? &call_size_time_table : &size_time_table;
     177              : 
     178    134370491 :   if (exec_pred == false)
     179      4667156 :     return;
     180              : 
     181    134110342 :   nonconst_pred = nonconst_pred_in & exec_pred;
     182              : 
     183    134110342 :   if (nonconst_pred == false)
     184              :     return;
     185              : 
     186              :   /* We need to create initial empty unconditional clause, but otherwise
     187              :      we don't need to account empty times and sizes.  */
     188    156796404 :   if (!size && time == 0 && table->length ())
     189      3693857 :     return;
     190              : 
     191              :   /* Only for calls we are unaccounting what we previously recorded.  */
     192    129703335 :   gcc_checking_assert (time >= 0 || call);
     193              : 
     194    470475630 :   for (i = 0; table->iterate (i, &e); i++)
     195    441461912 :     if (e->exec_predicate == exec_pred
     196    441461912 :         && e->nonconst_predicate == nonconst_pred)
     197              :       {
     198              :         found = true;
     199              :         break;
     200              :       }
     201    129703335 :   if (i == max_size_time_table_size)
     202              :     {
     203            0 :       i = 0;
     204            0 :       found = true;
     205            0 :       e = &(*table)[0];
     206            0 :       if (dump_file && (dump_flags & TDF_DETAILS))
     207            0 :         fprintf (dump_file,
     208              :                  "\t\tReached limit on number of entries, "
     209              :                  "ignoring the predicate.");
     210              :     }
     211    129707609 :   if (dump_file && (dump_flags & TDF_DETAILS) && (time != 0 || size))
     212              :     {
     213         3997 :       fprintf (dump_file,
     214              :                "\t\tAccounting size:%3.2f, time:%3.2f on %spredicate exec:",
     215         3766 :                ((double) size) / ipa_fn_summary::size_scale,
     216              :                (time.to_double ()), found ? "" : "new ");
     217         3766 :       exec_pred.dump (dump_file, conds, 0);
     218         3766 :       if (exec_pred != nonconst_pred)
     219              :         {
     220           84 :           fprintf (dump_file, " nonconst:");
     221           84 :           nonconst_pred.dump (dump_file, conds);
     222              :         }
     223              :       else
     224         3682 :         fprintf (dump_file, "\n");
     225              :     }
     226    129703335 :   if (!found)
     227              :     {
     228     29013718 :       class size_time_entry new_entry;
     229     29013718 :       new_entry.size = size;
     230     29013718 :       new_entry.time = time;
     231     29013718 :       new_entry.exec_predicate = exec_pred;
     232     29013718 :       new_entry.nonconst_predicate = nonconst_pred;
     233     29013718 :       if (call)
     234      1329689 :         call_size_time_table.safe_push (new_entry);
     235              :       else
     236     27684029 :         size_time_table.safe_push (new_entry);
     237              :     }
     238              :   else
     239              :     {
     240    100689617 :       e->size += size;
     241    100689617 :       e->time += time;
     242              :       /* FIXME: PR bootstrap/92653 gcc_checking_assert (e->time >= -1); */
     243              :       /* Tolerate small roundoff issues.  */
     244    100689617 :       if (e->time < 0)
     245          113 :         e->time = 0;
     246              :     }
     247              : }
     248              : 
     249              : /* We proved E to be unreachable, redirect it to __builtin_unreachable.  */
     250              : 
     251              : static struct cgraph_edge *
     252       281010 : redirect_to_unreachable (struct cgraph_edge *e)
     253              : {
     254       281010 :   struct cgraph_node *callee = !e->inline_failed ? e->callee : NULL;
     255       281010 :   struct cgraph_node *target
     256       281010 :     = cgraph_node::get_create (builtin_decl_unreachable ());
     257              : 
     258       281010 :   gcc_checking_assert (lookup_attribute ("cold",
     259              :                                          DECL_ATTRIBUTES (target->decl)));
     260              : 
     261       281010 :   if (e->speculative)
     262          314 :     e = cgraph_edge::resolve_speculation (e, target->decl);
     263       280696 :   else if (!e->callee)
     264          762 :     e = cgraph_edge::make_direct (e, target);
     265              :   else
     266       279934 :     e->redirect_callee (target);
     267       281010 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
     268       281010 :   e->inline_failed = CIF_UNREACHABLE;
     269       281010 :   e->count = profile_count::zero ();
     270       281010 :   es->call_stmt_size = 0;
     271       281010 :   es->call_stmt_time = 0;
     272       281010 :   if (callee)
     273            0 :     callee->remove_symbol_and_inline_clones ();
     274       281010 :   if (e->has_callback)
     275            4 :     for (cgraph_edge *cbe = e->first_callback_edge (); cbe;
     276            1 :          cbe = cbe->next_callback_edge ())
     277              :       /* If the carrying edge is unreachable, so are the callback calls.  */
     278            1 :       redirect_to_unreachable (cbe);
     279       281010 :   return e;
     280              : }
     281              : 
     282              : /* Set predicate for edge E.  */
     283              : 
     284              : static void
     285     30437756 : edge_set_predicate (struct cgraph_edge *e, ipa_predicate *predicate)
     286              : {
     287              :   /* If the edge is determined to be never executed, redirect it
     288              :      to BUILTIN_UNREACHABLE to make it clear to IPA passes the call will
     289              :      be optimized out.  */
     290     27795320 :   if (predicate && *predicate == false
     291              :       /* When handling speculative edges, we need to do the redirection
     292              :          just once.  Do it always on the direct edge, so we do not
     293              :          attempt to resolve speculation while duplicating the edge.  */
     294     30718841 :       && (!e->speculative || e->callee))
     295       281009 :     e = redirect_to_unreachable (e);
     296              : 
     297     30437756 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
     298     58233076 :   if (predicate && *predicate != true)
     299              :     {
     300      4515872 :       if (!es->predicate)
     301      4041748 :         es->predicate = edge_predicate_pool.allocate ();
     302      4515872 :       *es->predicate = *predicate;
     303              :     }
     304              :   else
     305              :     {
     306     25921884 :       if (es->predicate)
     307       773790 :         edge_predicate_pool.remove (es->predicate);
     308     25921884 :       es->predicate = NULL;
     309              :     }
     310     30437756 : }
     311              : 
     312              : /* Set predicate for hint *P.  */
     313              : 
     314              : static void
     315       148361 : set_hint_predicate (ipa_predicate **p, ipa_predicate new_predicate)
     316              : {
     317       148361 :   if (new_predicate == false || new_predicate == true)
     318              :     {
     319         3015 :       if (*p)
     320            0 :         edge_predicate_pool.remove (*p);
     321         3015 :       *p = NULL;
     322              :     }
     323              :   else
     324              :     {
     325       145346 :       if (!*p)
     326       145346 :         *p = edge_predicate_pool.allocate ();
     327       145346 :       **p = new_predicate;
     328              :     }
     329       148361 : }
     330              : 
     331              : /* Find if NEW_PREDICATE is already in V and if so, increment its freq.
     332              :    Otherwise add a new item to the vector with this predicate and frerq equal
     333              :    to add_freq, unless the number of predicates would exceed MAX_NUM_PREDICATES
     334              :    in which case the function does nothing.  */
     335              : 
     336              : static void
     337      1107677 : add_freqcounting_predicate (vec<ipa_freqcounting_predicate, va_gc> **v,
     338              :                             const ipa_predicate &new_predicate, sreal add_freq,
     339              :                             unsigned max_num_predicates)
     340              : {
     341      1107677 :   if (new_predicate == false || new_predicate == true)
     342              :     return;
     343              :   ipa_freqcounting_predicate *f;
     344       139762 :   for (int i = 0; vec_safe_iterate (*v, i, &f); i++)
     345        71596 :     if (new_predicate == f->predicate)
     346              :       {
     347            0 :         f->freq += add_freq;
     348            0 :         return;
     349              :       }
     350        94026 :   if (vec_safe_length (*v) >= max_num_predicates)
     351              :     /* Too many different predicates to account for.  */
     352              :     return;
     353              : 
     354        67894 :   ipa_freqcounting_predicate fcp;
     355        67894 :   fcp.predicate = NULL;
     356        67894 :   set_hint_predicate (&fcp.predicate, new_predicate);
     357        67894 :   fcp.freq = add_freq;
     358        67894 :   vec_safe_push (*v, fcp);
     359        67894 :   return;
     360              : }
     361              : 
     362              : /* Compute what conditions may or may not hold given information about
     363              :    parameters.  RET_CLAUSE returns truths that may hold in a specialized copy,
     364              :    while RET_NONSPEC_CLAUSE returns truths that may hold in an nonspecialized
     365              :    copy when called in a given context.  It is a bitmask of conditions. Bit
     366              :    0 means that condition is known to be false, while bit 1 means that condition
     367              :    may or may not be true.  These differs - for example NOT_INLINED condition
     368              :    is always false in the second and also builtin_constant_p tests cannot use
     369              :    the fact that parameter is indeed a constant.
     370              : 
     371              :    When INLINE_P is true, assume that we are inlining.  AVAL contains known
     372              :    information about argument values.  The function does not modify its content
     373              :    and so AVALs could also be of type ipa_call_arg_values but so far all
     374              :    callers work with the auto version and so we avoid the conversion for
     375              :    convenience.
     376              : 
     377              :    ERROR_MARK value of an argument means compile time invariant.  */
     378              : 
     379              : static void
     380     21617917 : evaluate_conditions_for_known_args (struct cgraph_node *node,
     381              :                                     bool inline_p,
     382              :                                     ipa_auto_call_arg_values *avals,
     383              :                                     clause_t *ret_clause,
     384              :                                     clause_t *ret_nonspec_clause,
     385              :                                     ipa_call_summary *es)
     386              : {
     387     21617917 :   clause_t clause = inline_p ? 0 : 1 << ipa_predicate::not_inlined_condition;
     388     21617917 :   clause_t nonspec_clause = 1 << ipa_predicate::not_inlined_condition;
     389     21617917 :   class ipa_fn_summary *info = ipa_fn_summaries->get (node);
     390     21617917 :   int i;
     391     21617917 :   struct condition *c;
     392              : 
     393     89947565 :   for (i = 0; vec_safe_iterate (info->conds, i, &c); i++)
     394              :     {
     395     68329648 :       tree val = NULL;
     396     68329648 :       tree res;
     397     68329648 :       int j;
     398     68329648 :       struct expr_eval_op *op;
     399              : 
     400     68329648 :       if (c->code == ipa_predicate::not_sra_candidate)
     401              :         {
     402     15925383 :           if (!inline_p
     403     15925383 :               || !es
     404     15682667 :               || (int)es->param.length () <= c->operand_num
     405     23766685 :               || !es->param[c->operand_num].points_to_possible_sra_candidate)
     406     11983476 :             clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     407     15925383 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     408     68329648 :           continue;
     409              :         }
     410              : 
     411     52404265 :       if (c->agg_contents)
     412              :         {
     413     28345265 :           if (c->code == ipa_predicate::changed
     414     18056092 :               && !c->by_ref
     415     30908606 :               && (avals->safe_sval_at(c->operand_num) == error_mark_node))
     416         5208 :             continue;
     417              : 
     418     28334849 :           if (tree sval = avals->safe_sval_at (c->operand_num))
     419     12993026 :             val = ipa_find_agg_cst_from_init (sval, c->offset, c->by_ref);
     420     12993026 :           if (!val)
     421              :             {
     422     28324566 :               ipa_argagg_value_list avs (avals);
     423     28324566 :               val = avs.get_value (c->operand_num, c->offset / BITS_PER_UNIT,
     424     28324566 :                                    c->by_ref);
     425              :             }
     426              :         }
     427              :       else
     428              :         {
     429     24064208 :           val = avals->safe_sval_at (c->operand_num);
     430     24064208 :           if (val && val == error_mark_node
     431      2125274 :               && c->code != ipa_predicate::changed)
     432              :             val = NULL_TREE;
     433              :         }
     434              : 
     435     39865173 :       if (!val
     436     39084051 :           && (c->code == ipa_predicate::changed
     437              :               || c->code == ipa_predicate::is_not_constant))
     438              :         {
     439     24622655 :           clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     440     24622655 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     441     24622655 :           continue;
     442              :         }
     443     27776402 :       if (c->code == ipa_predicate::changed)
     444              :         {
     445      7406477 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     446      7406477 :           continue;
     447              :         }
     448              : 
     449     20369925 :       if (c->code == ipa_predicate::is_not_constant)
     450              :         {
     451         5539 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     452         5539 :           continue;
     453              :         }
     454              : 
     455     20364386 :       if (val && TYPE_SIZE (c->type) == TYPE_SIZE (TREE_TYPE (val)))
     456              :         {
     457      5859692 :           if (c->type != TREE_TYPE (val))
     458      1132146 :             val = fold_unary (VIEW_CONVERT_EXPR, c->type, val);
     459      6284172 :           for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
     460              :             {
     461       424922 :               if (!val)
     462              :                 break;
     463       424480 :               if (!op->val[0])
     464       154618 :                 val = fold_unary (op->code, op->type, val);
     465       269862 :               else if (!op->val[1])
     466       539724 :                 val = fold_binary (op->code, op->type,
     467              :                                    op->index ? op->val[0] : val,
     468              :                                    op->index ? val : op->val[0]);
     469            0 :               else if (op->index == 0)
     470            0 :                 val = fold_ternary (op->code, op->type,
     471              :                                     val, op->val[0], op->val[1]);
     472            0 :               else if (op->index == 1)
     473            0 :                 val = fold_ternary (op->code, op->type,
     474              :                                     op->val[0], val, op->val[1]);
     475            0 :               else if (op->index == 2)
     476            0 :                 val = fold_ternary (op->code, op->type,
     477              :                                     op->val[0], op->val[1], val);
     478              :               else
     479              :                 val = NULL_TREE;
     480              :             }
     481              : 
     482      5859692 :           res = val
     483      5859692 :             ? fold_binary_to_constant (c->code, boolean_type_node, val, c->val)
     484              :             : NULL;
     485              : 
     486      5859230 :           if (res && integer_zerop (res))
     487      3011344 :             continue;
     488      2848348 :           if (res && integer_onep (res))
     489              :             {
     490      2825708 :               clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     491      2825708 :               nonspec_clause
     492      2825708 :                 |= 1 << (i + ipa_predicate::first_dynamic_condition);
     493      2825708 :               continue;
     494              :             }
     495              :         }
     496     14527334 :       if (c->operand_num < (int) avals->m_known_value_ranges.length ()
     497      8310153 :           && !c->agg_contents
     498     16614740 :           && (!val || TREE_CODE (val) != INTEGER_CST))
     499              :         {
     500      2087320 :           value_range vr (avals->m_known_value_ranges[c->operand_num]);
     501      2087320 :           if (!vr.undefined_p ()
     502      1245322 :               && !vr.varying_p ()
     503      3332642 :               && (TYPE_SIZE (c->type) == TYPE_SIZE (vr.type ())))
     504              :             {
     505      1244602 :               if (!useless_type_conversion_p (c->type, vr.type ()))
     506          902 :                 range_cast (vr, c->type);
     507              : 
     508      1552499 :               for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
     509              :                 {
     510       345762 :                   if (vr.varying_p () || vr.undefined_p ())
     511              :                     break;
     512              : 
     513       307897 :                   value_range res (op->type);
     514       307897 :                   if (!op->val[0])
     515              :                     {
     516       112169 :                       value_range varying (op->type);
     517       112169 :                       varying.set_varying (op->type);
     518       112169 :                       range_op_handler handler (op->code);
     519       112169 :                       if (!handler
     520       112169 :                           || !res.supports_type_p (op->type)
     521       224338 :                           || !handler.fold_range (res, op->type, vr, varying))
     522            0 :                         res.set_varying (op->type);
     523       112169 :                     }
     524       195728 :                   else if (!op->val[1])
     525              :                     {
     526       195556 :                       value_range op0 (TREE_TYPE (op->val[0]));
     527       195556 :                       range_op_handler handler (op->code);
     528              : 
     529       195556 :                       ipa_get_range_from_ip_invariant (op0, op->val[0], node);
     530              : 
     531       195556 :                       if (!handler
     532       195556 :                           || !res.supports_type_p (op->type)
     533       391112 :                           || !handler.fold_range (res, op->type,
     534       195556 :                                                   op->index ? op0 : vr,
     535       390548 :                                                   op->index ? vr : op0))
     536            0 :                         res.set_varying (op->type);
     537       195556 :                     }
     538              :                   else
     539          172 :                     res.set_varying (op->type);
     540       307897 :                   vr = res;
     541       307897 :                 }
     542      1244602 :               if (!vr.varying_p () && !vr.undefined_p ())
     543              :                 {
     544      1196922 :                   int_range<2> res;
     545      1196922 :                   value_range val_vr (TREE_TYPE (c->val));
     546      1196922 :                   range_op_handler handler (c->code);
     547              : 
     548      1196922 :                   ipa_get_range_from_ip_invariant (val_vr, c->val, node);
     549              : 
     550      1196922 :                   if (!handler
     551      1196922 :                       || !val_vr.supports_type_p (TREE_TYPE (c->val))
     552      2393844 :                       || !handler.fold_range (res, boolean_type_node, vr, val_vr))
     553            0 :                     res.set_varying (boolean_type_node);
     554              : 
     555      1196922 :                   if (res.zero_p ())
     556       205949 :                     continue;
     557      1196922 :                 }
     558              :             }
     559      2087320 :         }
     560              : 
     561     14321385 :       clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     562     14321385 :       nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     563              :     }
     564     21617917 :   *ret_clause = clause;
     565     21617917 :   if (ret_nonspec_clause)
     566     18768317 :     *ret_nonspec_clause = nonspec_clause;
     567     21617917 : }
     568              : 
     569              : /* Return true if VRP will be exectued on the function.
     570              :    We do not want to anticipate optimizations that will not happen.
     571              : 
     572              :    FIXME: This can be confused with -fdisable and debug counters and thus
     573              :    it should not be used for correctness (only to make heuristics work).
     574              :    This means that inliner should do its own optimizations of expressions
     575              :    that it predicts to be constant so wrong code can not be triggered by
     576              :    builtin_constant_p.  */
     577              : 
     578              : static bool
     579     11721359 : vrp_will_run_p (struct cgraph_node *node)
     580              : {
     581     11721359 :   return (opt_for_fn (node->decl, optimize)
     582     11721359 :           && !opt_for_fn (node->decl, optimize_debug)
     583     23441501 :           && opt_for_fn (node->decl, flag_tree_vrp));
     584              : }
     585              : 
     586              : /* Similarly about FRE.  */
     587              : 
     588              : static bool
     589     14032668 : fre_will_run_p (struct cgraph_node *node)
     590              : {
     591     14032668 :   return (opt_for_fn (node->decl, optimize)
     592     14032668 :           && !opt_for_fn (node->decl, optimize_debug)
     593     28063055 :           && opt_for_fn (node->decl, flag_tree_fre));
     594              : }
     595              : 
     596              : /* Work out what conditions might be true at invocation of E.
     597              :    Compute costs for inlined edge if INLINE_P is true.
     598              : 
     599              :    Return in CLAUSE_PTR the evaluated conditions and in NONSPEC_CLAUSE_PTR
     600              :    (if non-NULL) conditions evaluated for nonspecialized clone called
     601              :    in a given context.
     602              : 
     603              :    Vectors in AVALS will be populated with useful known information about
     604              :    argument values - information not known to have any uses will be omitted -
     605              :    except for m_known_contexts which will only be calculated if
     606              :    COMPUTE_CONTEXTS is true.  */
     607              : 
     608              : void
     609     21321478 : evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
     610              :                               clause_t *clause_ptr,
     611              :                               clause_t *nonspec_clause_ptr,
     612              :                               ipa_auto_call_arg_values *avals,
     613              :                               bool compute_contexts)
     614              : {
     615     21321478 :   struct cgraph_node *callee = e->callee->ultimate_alias_target ();
     616     21321478 :   class ipa_fn_summary *info = ipa_fn_summaries->get (callee);
     617     21321478 :   class ipa_edge_args *args;
     618     21321478 :   class ipa_call_summary *es = NULL;
     619              : 
     620     21321478 :   if (clause_ptr)
     621     21321478 :     *clause_ptr = inline_p ? 0 : 1 << ipa_predicate::not_inlined_condition;
     622              : 
     623     21321478 :   if (ipa_node_params_sum
     624      9691235 :       && !e->call_stmt_cannot_inline_p
     625      9691235 :       && (info->conds || compute_contexts)
     626     31012713 :       && (args = ipa_edge_args_sum->get (e)) != NULL)
     627              :     {
     628      9636778 :       struct cgraph_node *caller;
     629      9636778 :       class ipa_node_params *caller_parms_info, *callee_pi = NULL;
     630      9636778 :       int i, count = ipa_get_cs_argument_count (args);
     631      9636778 :       es = ipa_call_summaries->get (e);
     632              : 
     633      9636778 :       if (count)
     634              :         {
     635      8951664 :           if (e->caller->inlined_to)
     636              :             caller = e->caller->inlined_to;
     637              :           else
     638      7251132 :             caller = e->caller;
     639      8951664 :           caller_parms_info = ipa_node_params_sum->get (caller);
     640      8951664 :           callee_pi = ipa_node_params_sum->get (callee);
     641              : 
     642              :           /* Watch for thunks.  */
     643      8951664 :           if (callee_pi)
     644              :             /* Watch for variadic functions.  */
     645      8951323 :             count = MIN (count, ipa_get_param_count (callee_pi));
     646              :         }
     647              : 
     648      8951323 :       if (callee_pi)
     649     29608954 :         for (i = 0; i < count; i++)
     650              :           {
     651     20657631 :             struct ipa_jump_func *jf = ipa_get_ith_jump_func (args, i);
     652              : 
     653     20657631 :             if (ipa_is_param_used_by_indirect_call (callee_pi, i)
     654     20657631 :                 || ipa_is_param_used_by_ipa_predicates (callee_pi, i))
     655              :               {
     656              :                 /* Determine if we know constant value of the parameter.  */
     657     14032668 :                 tree type = ipa_get_type (callee_pi, i);
     658     14032668 :                 tree cst = ipa_value_from_jfunc (caller_parms_info, jf, type);
     659              : 
     660     10934667 :                 if (!cst && e->call_stmt
     661     24917044 :                     && i < (int)gimple_call_num_args (e->call_stmt))
     662              :                   {
     663     10884376 :                     cst = gimple_call_arg (e->call_stmt, i);
     664     10884376 :                     if (!is_gimple_min_invariant (cst))
     665              :                       cst = NULL;
     666              :                   }
     667      3330575 :                 if (cst)
     668              :                   {
     669      3280284 :                     gcc_checking_assert (TREE_CODE (cst) != TREE_BINFO);
     670      3280284 :                     if (!avals->m_known_vals.length ())
     671      1770943 :                       avals->m_known_vals.safe_grow_cleared (count, true);
     672      3280284 :                     avals->m_known_vals[i] = cst;
     673              :                   }
     674     10752384 :                 else if (inline_p && !es->param[i].change_prob)
     675              :                   {
     676      3991591 :                     if (!avals->m_known_vals.length ())
     677      3285248 :                       avals->m_known_vals.safe_grow_cleared (count, true);
     678      3991591 :                     avals->m_known_vals[i] = error_mark_node;
     679              :                   }
     680              : 
     681              :                 /* If we failed to get simple constant, try value range.  */
     682      3280284 :                 if ((!cst || TREE_CODE (cst) != INTEGER_CST)
     683     11721359 :                     && vrp_will_run_p (caller)
     684     25591905 :                     && ipa_is_param_used_by_ipa_predicates (callee_pi, i))
     685              :                   {
     686     11518871 :                     value_range vr (type);
     687              : 
     688     11518871 :                     ipa_value_range_from_jfunc (vr, caller_parms_info, e, jf, type);
     689     11518871 :                     if (!vr.undefined_p () && !vr.varying_p ())
     690              :                       {
     691      8069521 :                         if (!avals->m_known_value_ranges.length ())
     692              :                           {
     693      5800086 :                             avals->m_known_value_ranges.safe_grow_cleared (count,
     694              :                                                                            true);
     695     18640895 :                             for (int i = 0; i < count; ++i)
     696     12840809 :                               avals->m_known_value_ranges[i].set_type (void_type_node);
     697              :                           }
     698      8069521 :                         avals->m_known_value_ranges[i] = vr;
     699              :                       }
     700     11518871 :                   }
     701              : 
     702              :                 /* Determine known aggregate values.  */
     703     14032668 :                 if (fre_will_run_p (caller))
     704     14029983 :                   ipa_push_agg_values_from_jfunc (caller_parms_info,
     705              :                                                   caller, &jf->agg, i,
     706              :                                                   &avals->m_known_aggs);
     707              :               }
     708              : 
     709              :             /* For calls used in polymorphic calls we further determine
     710              :                polymorphic call context.  */
     711     20657631 :             if (compute_contexts
     712     20657631 :                 && ipa_is_param_used_by_polymorphic_call (callee_pi, i))
     713              :               {
     714       162825 :                 ipa_polymorphic_call_context
     715       162825 :                    ctx = ipa_context_from_jfunc (caller_parms_info, e, i, jf);
     716       325650 :                 if (!ctx.useless_p ())
     717              :                   {
     718       160877 :                     if (!avals->m_known_contexts.length ())
     719       160740 :                       avals->m_known_contexts.safe_grow_cleared (count, true);
     720       160877 :                     avals->m_known_contexts[i]
     721       321754 :                       = ipa_context_from_jfunc (caller_parms_info, e, i, jf);
     722              :                   }
     723              :                }
     724              :           }
     725              :         else
     726       685455 :           gcc_assert (!count || callee->thunk);
     727              :     }
     728     11684700 :   else if (e->call_stmt && !e->call_stmt_cannot_inline_p && info->conds)
     729              :     {
     730      9180372 :       int i, count = (int)gimple_call_num_args (e->call_stmt);
     731              : 
     732     26125970 :       for (i = 0; i < count; i++)
     733              :         {
     734     16945598 :           tree cst = gimple_call_arg (e->call_stmt, i);
     735     16945598 :           if (!is_gimple_min_invariant (cst))
     736              :             cst = NULL;
     737      6040878 :           if (cst)
     738              :             {
     739      6040878 :               if (!avals->m_known_vals.length ())
     740      4176583 :                 avals->m_known_vals.safe_grow_cleared (count, true);
     741      6040878 :               avals->m_known_vals[i] = cst;
     742              :             }
     743              :         }
     744              :     }
     745              : 
     746     21321478 :   evaluate_conditions_for_known_args (callee, inline_p, avals, clause_ptr,
     747              :                                       nonspec_clause_ptr, es);
     748     21321478 : }
     749              : 
     750              : 
     751              : /* Allocate the function summary. */
     752              : 
     753              : static void
     754       458494 : ipa_fn_summary_alloc (void)
     755              : {
     756       458494 :   gcc_checking_assert (!ipa_fn_summaries);
     757       458494 :   ipa_size_summaries = new ipa_size_summary_t (symtab);
     758       458494 :   ipa_fn_summaries = ipa_fn_summary_t::create_ggc (symtab);
     759       458494 :   ipa_call_summaries = new ipa_call_summary_t (symtab);
     760       458494 : }
     761              : 
     762     26795070 : ipa_call_summary::~ipa_call_summary ()
     763              : {
     764     26795070 :   if (predicate)
     765      3267958 :     edge_predicate_pool.remove (predicate);
     766              : 
     767     26795070 :   param.release ();
     768     26795070 : }
     769              : 
     770      9829571 : ipa_fn_summary::~ipa_fn_summary ()
     771              : {
     772      9829571 :   unsigned len = vec_safe_length (loop_iterations);
     773      9941528 :   for (unsigned i = 0; i < len; i++)
     774       111957 :     edge_predicate_pool.remove ((*loop_iterations)[i].predicate);
     775      9829571 :   len = vec_safe_length (loop_strides);
     776      9862960 :   for (unsigned i = 0; i < len; i++)
     777        33389 :     edge_predicate_pool.remove ((*loop_strides)[i].predicate);
     778      9829571 :   vec_free (conds);
     779      9829571 :   call_size_time_table.release ();
     780      9829571 :   vec_free (loop_iterations);
     781      9829571 :   vec_free (loop_strides);
     782      9829571 :   builtin_constant_p_parms.release ();
     783      9829571 : }
     784              : 
     785              : void
     786      7130084 : ipa_fn_summary_t::remove_callees (cgraph_node *node)
     787              : {
     788      7130084 :   cgraph_edge *e;
     789     29373839 :   for (e = node->callees; e; e = e->next_callee)
     790     22243755 :     ipa_call_summaries->remove (e);
     791      7609940 :   for (e = node->indirect_calls; e; e = e->next_callee)
     792       479856 :     ipa_call_summaries->remove (e);
     793      7130084 : }
     794              : 
     795              : /* Duplicate predicates in loop hint vector, allocating memory for them and
     796              :    remove and deallocate any uninteresting (true or false) ones.  Return the
     797              :    result.  */
     798              : 
     799              : static vec<ipa_freqcounting_predicate, va_gc> *
     800        29428 : remap_freqcounting_preds_after_dup (vec<ipa_freqcounting_predicate, va_gc> *v,
     801              :                                     clause_t possible_truths)
     802              : {
     803        29428 :   if (vec_safe_length (v) == 0)
     804              :     return NULL;
     805              : 
     806         4715 :   vec<ipa_freqcounting_predicate, va_gc> *res = v->copy ();
     807         4715 :   int len = res->length();
     808        11079 :   for (int i = len - 1; i >= 0; i--)
     809              :     {
     810         6364 :       ipa_predicate new_predicate
     811         6364 :         = (*res)[i].predicate->remap_after_duplication (possible_truths);
     812              :       /* We do not want to free previous predicate; it is used by node
     813              :          origin.  */
     814         6364 :       (*res)[i].predicate = NULL;
     815         6364 :       set_hint_predicate (&(*res)[i].predicate, new_predicate);
     816              : 
     817         6364 :       if (!(*res)[i].predicate)
     818         3015 :         res->unordered_remove (i);
     819              :     }
     820              : 
     821              :   return res;
     822              : }
     823              : 
     824              : 
     825              : /* Hook that is called by cgraph.cc when a node is duplicated.  */
     826              : void
     827      2612443 : ipa_fn_summary_t::duplicate (cgraph_node *src,
     828              :                              cgraph_node *dst,
     829              :                              ipa_fn_summary *src_info,
     830              :                              ipa_fn_summary *info)
     831              : {
     832      2612443 :   new (info) ipa_fn_summary (*src_info);
     833              :   /* TODO: as an optimization, we may avoid copying conditions
     834              :      that are known to be false or true.  */
     835      2612443 :   info->conds = vec_safe_copy (info->conds);
     836              : 
     837      2612443 :   clone_info *cinfo = clone_info::get (dst);
     838              :   /* When there are any replacements in the function body, see if we can figure
     839              :      out that something was optimized out.  */
     840      2612443 :   if (ipa_node_params_sum && cinfo && cinfo->tree_map)
     841              :     {
     842              :       /* Use SRC parm info since it may not be copied yet.  */
     843        14714 :       ipa_node_params *parms_info = ipa_node_params_sum->get (src);
     844        14714 :       ipa_auto_call_arg_values avals;
     845        14714 :       int count = ipa_get_param_count (parms_info);
     846        14714 :       int i, j;
     847        14714 :       clause_t possible_truths;
     848        14714 :       ipa_predicate true_pred = true;
     849        14714 :       size_time_entry *e;
     850        14714 :       int optimized_out_size = 0;
     851        14714 :       bool inlined_to_p = false;
     852        14714 :       struct cgraph_edge *edge, *next;
     853              : 
     854        14714 :       info->size_time_table.release ();
     855        14714 :       avals.m_known_vals.safe_grow_cleared (count, true);
     856        60028 :       for (i = 0; i < count; i++)
     857              :         {
     858              :           struct ipa_replace_map *r;
     859              : 
     860       148940 :           for (j = 0; vec_safe_iterate (cinfo->tree_map, j, &r); j++)
     861              :             {
     862        83966 :               if (r->parm_num == i)
     863              :                 {
     864        25654 :                   avals.m_known_vals[i] = r->new_tree;
     865        25654 :                   break;
     866              :                 }
     867              :             }
     868              :         }
     869        14714 :       evaluate_conditions_for_known_args (dst, false,
     870              :                                           &avals,
     871              :                                           &possible_truths,
     872              :                                           /* We are going to specialize,
     873              :                                              so ignore nonspec truths.  */
     874              :                                           NULL,
     875              :                                           NULL);
     876              : 
     877        14714 :       info->account_size_time (0, 0, true_pred, true_pred);
     878              : 
     879              :       /* Remap size_time vectors.
     880              :          Simplify the predicate by pruning out alternatives that are known
     881              :          to be false.
     882              :          TODO: as on optimization, we can also eliminate conditions known
     883              :          to be true.  */
     884       105327 :       for (i = 0; src_info->size_time_table.iterate (i, &e); i++)
     885              :         {
     886        90613 :           ipa_predicate new_exec_pred;
     887        90613 :           ipa_predicate new_nonconst_pred;
     888        90613 :           new_exec_pred = e->exec_predicate.remap_after_duplication
     889        90613 :                                  (possible_truths);
     890        90613 :           new_nonconst_pred = e->nonconst_predicate.remap_after_duplication
     891        90613 :                                  (possible_truths);
     892        90613 :           if (new_exec_pred == false || new_nonconst_pred == false)
     893        13048 :             optimized_out_size += e->size;
     894              :           else
     895        77565 :             info->account_size_time (e->size, e->time, new_exec_pred,
     896              :                                      new_nonconst_pred);
     897              :         }
     898              : 
     899              :       /* Remap edge predicates with the same simplification as above.
     900              :          Also copy constantness arrays.   */
     901       190484 :       for (edge = dst->callees; edge; edge = next)
     902              :         {
     903       175770 :           ipa_predicate new_predicate;
     904       175770 :           class ipa_call_summary *es = ipa_call_summaries->get (edge);
     905       175770 :           next = edge->next_callee;
     906              : 
     907       175770 :           if (!edge->inline_failed)
     908            0 :             inlined_to_p = true;
     909       175770 :           if (!es->predicate)
     910       159841 :             continue;
     911        15929 :           new_predicate = es->predicate->remap_after_duplication
     912        15929 :             (possible_truths);
     913        15929 :           if (new_predicate == false && *es->predicate != false)
     914         4492 :             optimized_out_size += es->call_stmt_size * ipa_fn_summary::size_scale;
     915        15929 :           edge_set_predicate (edge, &new_predicate);
     916              :         }
     917              : 
     918              :       /* Remap indirect edge predicates with the same simplification as above.
     919              :          Also copy constantness arrays.   */
     920        15618 :       for (edge = dst->indirect_calls; edge; edge = next)
     921              :         {
     922          904 :           ipa_predicate new_predicate;
     923          904 :           class ipa_call_summary *es = ipa_call_summaries->get (edge);
     924          904 :           next = edge->next_callee;
     925              : 
     926          904 :           gcc_checking_assert (edge->inline_failed);
     927          904 :           if (!es->predicate)
     928          783 :             continue;
     929          121 :           new_predicate = es->predicate->remap_after_duplication
     930          121 :                                  (possible_truths);
     931          121 :           if (new_predicate == false && *es->predicate != false)
     932           24 :             optimized_out_size
     933           24 :                  += es->call_stmt_size * ipa_fn_summary::size_scale;
     934          121 :           edge_set_predicate (edge, &new_predicate);
     935              :         }
     936        14714 :       info->loop_iterations
     937        14714 :         = remap_freqcounting_preds_after_dup (info->loop_iterations,
     938              :                                               possible_truths);
     939        14714 :       info->loop_strides
     940        14714 :         = remap_freqcounting_preds_after_dup (info->loop_strides,
     941              :                                               possible_truths);
     942        14714 :       if (info->builtin_constant_p_parms.length())
     943              :         {
     944           22 :           vec <int, va_heap, vl_ptr> parms = info->builtin_constant_p_parms;
     945           22 :           int ip;
     946           22 :           info->builtin_constant_p_parms = vNULL;
     947           44 :           for (i = 0; parms.iterate (i, &ip); i++)
     948           22 :             if (!avals.m_known_vals[ip])
     949            4 :               info->builtin_constant_p_parms.safe_push (ip);
     950              :         }
     951              : 
     952              :       /* If inliner or someone after inliner will ever start producing
     953              :          non-trivial clones, we will get trouble with lack of information
     954              :          about updating self sizes, because size vectors already contains
     955              :          sizes of the callees.  */
     956        14714 :       gcc_assert (!inlined_to_p || !optimized_out_size);
     957        14714 :     }
     958              :   else
     959              :     {
     960      2597729 :       info->size_time_table = src_info->size_time_table.copy ();
     961      2597729 :       info->loop_iterations = vec_safe_copy (src_info->loop_iterations);
     962      2597729 :       info->loop_strides = vec_safe_copy (info->loop_strides);
     963              : 
     964      2597729 :       info->builtin_constant_p_parms
     965      2597729 :              = info->builtin_constant_p_parms.copy ();
     966              : 
     967      2597729 :       ipa_freqcounting_predicate *f;
     968      2646337 :       for (int i = 0; vec_safe_iterate (info->loop_iterations, i, &f); i++)
     969              :         {
     970        48608 :           ipa_predicate p = *f->predicate;
     971        48608 :           f->predicate = NULL;
     972        48608 :           set_hint_predicate (&f->predicate, p);
     973              :         }
     974      2621591 :       for (int i = 0; vec_safe_iterate (info->loop_strides, i, &f); i++)
     975              :         {
     976        23862 :           ipa_predicate p = *f->predicate;
     977        23862 :           f->predicate = NULL;
     978        23862 :           set_hint_predicate (&f->predicate, p);
     979              :         }
     980              :     }
     981      2612443 :   if (!dst->inlined_to)
     982       131637 :     ipa_update_overall_fn_summary (dst);
     983      2612443 : }
     984              : 
     985              : 
     986              : /* Hook that is called by cgraph.cc when a node is duplicated.  */
     987              : 
     988              : void
     989      3718420 : ipa_call_summary_t::duplicate (struct cgraph_edge *src,
     990              :                                struct cgraph_edge *dst,
     991              :                                class ipa_call_summary *srcinfo,
     992              :                                class ipa_call_summary *info)
     993              : {
     994      3718420 :   new (info) ipa_call_summary (*srcinfo);
     995      3718420 :   info->predicate = NULL;
     996      3718420 :   edge_set_predicate (dst, srcinfo->predicate);
     997      3718420 :   info->param = srcinfo->param.copy ();
     998      3718420 :   if (!dst->indirect_unknown_callee && src->indirect_unknown_callee
     999              :       /* Don't subtract the size when dealing with callback pairs, since the
    1000              :          edge has no real size.  */
    1001        23751 :       && !src->has_callback && !dst->callback)
    1002              :     {
    1003        23751 :       info->call_stmt_size -= (eni_size_weights.indirect_call_cost
    1004        23751 :                                - eni_size_weights.call_cost);
    1005        23751 :       info->call_stmt_time -= (eni_time_weights.indirect_call_cost
    1006        23751 :                                - eni_time_weights.call_cost);
    1007              :     }
    1008      3718420 : }
    1009              : 
    1010              : /* Dump edge summaries associated to NODE and recursively to all clones.
    1011              :    Indent by INDENT.  */
    1012              : 
    1013              : static void
    1014         1984 : dump_ipa_call_summary (FILE *f, int indent, struct cgraph_node *node,
    1015              :                        class ipa_fn_summary *info)
    1016              : {
    1017         1984 :   struct cgraph_edge *edge;
    1018         9822 :   for (edge = node->callees; edge; edge = edge->next_callee)
    1019              :     {
    1020         7838 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    1021         7838 :       struct cgraph_node *callee = edge->callee->ultimate_alias_target ();
    1022         7838 :       int i;
    1023              : 
    1024        15676 :       fprintf (f,
    1025              :                "%*s%s %s\n%*s  freq:%4.2f",
    1026              :                indent, "", callee->dump_name (),
    1027         7838 :                !edge->inline_failed
    1028         7284 :                ? "inlined" : cgraph_inline_failed_string (edge-> inline_failed),
    1029         7838 :                indent, "", edge->sreal_frequency ().to_double ());
    1030              : 
    1031         7838 :       if (cross_module_call_p (edge))
    1032            4 :         fprintf (f, " cross module");
    1033              : 
    1034         7838 :       if (es)
    1035         7284 :         fprintf (f, " loop depth:%2i size:%2i time: %2i",
    1036              :                  es->loop_depth, es->call_stmt_size, es->call_stmt_time);
    1037              : 
    1038         7838 :       ipa_fn_summary *s = ipa_fn_summaries->get (callee);
    1039         7838 :       ipa_size_summary *ss = ipa_size_summaries->get (callee);
    1040         7838 :       if (s != NULL)
    1041          623 :         fprintf (f, " callee size:%2i stack:%2i",
    1042          623 :                  (int) (ss->size / ipa_fn_summary::size_scale),
    1043          623 :                  (int) s->estimated_stack_size);
    1044              : 
    1045         7838 :       if (es && es->predicate)
    1046              :         {
    1047         4627 :           fprintf (f, " predicate: ");
    1048         4627 :           es->predicate->dump (f, info->conds);
    1049              :         }
    1050              :       else
    1051         3211 :         fprintf (f, "\n");
    1052         7838 :       if (es && es->param.exists ())
    1053         5390 :         for (i = 0; i < (int) es->param.length (); i++)
    1054              :           {
    1055         1590 :             int prob = es->param[i].change_prob;
    1056              : 
    1057         1590 :             if (!prob)
    1058          606 :               fprintf (f, "%*s op%i is compile time invariant\n",
    1059              :                        indent + 2, "", i);
    1060          984 :             else if (prob != REG_BR_PROB_BASE)
    1061           35 :               fprintf (f, "%*s op%i change %f%% of time\n", indent + 2, "", i,
    1062           35 :                        prob * 100.0 / REG_BR_PROB_BASE);
    1063         1590 :             if (es->param[i].points_to_local_or_readonly_memory)
    1064          406 :               fprintf (f, "%*s op%i points to local or readonly memory\n",
    1065              :                        indent + 2, "", i);
    1066         1590 :             if (es->param[i].points_to_possible_sra_candidate)
    1067          225 :               fprintf (f, "%*s op%i points to possible sra candidate\n",
    1068              :                        indent + 2, "", i);
    1069              :           }
    1070         7838 :       if (!edge->inline_failed)
    1071              :         {
    1072          554 :           ipa_size_summary *ss = ipa_size_summaries->get (callee);
    1073          554 :           fprintf (f, "%*sStack frame offset %i, callee self size %i\n",
    1074              :                    indent + 2, "",
    1075          554 :                    (int) ipa_get_stack_frame_offset (callee),
    1076          554 :                    (int) ss->estimated_self_stack_size);
    1077          554 :           dump_ipa_call_summary (f, indent + 2, callee, info);
    1078              :         }
    1079              :     }
    1080         2282 :   for (edge = node->indirect_calls; edge; edge = edge->next_callee)
    1081              :     {
    1082          298 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    1083          298 :       fprintf (f, "%*sindirect call loop depth:%2i freq:%4.2f size:%2i"
    1084              :                " time: %2i",
    1085              :                indent, "",
    1086              :                es->loop_depth,
    1087          298 :                edge->sreal_frequency ().to_double (), es->call_stmt_size,
    1088              :                es->call_stmt_time);
    1089          298 :       if (es->predicate)
    1090              :         {
    1091            6 :           fprintf (f, "predicate: ");
    1092            6 :           es->predicate->dump (f, info->conds);
    1093              :         }
    1094              :       else
    1095          292 :         fprintf (f, "\n");
    1096              :     }
    1097         1984 : }
    1098              : 
    1099              : 
    1100              : void
    1101         1633 : ipa_dump_fn_summary (FILE *f, struct cgraph_node *node)
    1102              : {
    1103         1633 :   if (node->definition)
    1104              :     {
    1105         1633 :       class ipa_fn_summary *s = ipa_fn_summaries->get (node);
    1106         1633 :       class ipa_size_summary *ss = ipa_size_summaries->get (node);
    1107         1633 :       if (s != NULL)
    1108              :         {
    1109         1430 :           size_time_entry *e;
    1110         1430 :           int i;
    1111         1430 :           fprintf (f, "IPA function summary for %s", node->dump_name ());
    1112         1430 :           if (DECL_DISREGARD_INLINE_LIMITS (node->decl))
    1113            0 :             fprintf (f, " always_inline");
    1114         1430 :           if (s->inlinable)
    1115         1243 :             fprintf (f, " inlinable");
    1116         1430 :           if (s->fp_expressions)
    1117           45 :             fprintf (f, " fp_expression");
    1118         1430 :           if (s->builtin_constant_p_parms.length ())
    1119              :             {
    1120            2 :               fprintf (f, " builtin_constant_p_parms");
    1121            4 :               for (unsigned int i = 0;
    1122            4 :                    i < s->builtin_constant_p_parms.length (); i++)
    1123            2 :                 fprintf (f, " %i", s->builtin_constant_p_parms[i]);
    1124              :             }
    1125         1430 :           fprintf (f, "\n  global time:     %f\n", s->time.to_double ());
    1126         1430 :           fprintf (f, "  self size:       %i\n", ss->self_size);
    1127         1430 :           fprintf (f, "  global size:     %i\n", ss->size);
    1128         1430 :           fprintf (f, "  min size:       %i\n", s->min_size);
    1129         1430 :           fprintf (f, "  self stack:      %i\n",
    1130         1430 :                    (int) ss->estimated_self_stack_size);
    1131         1430 :           fprintf (f, "  global stack:    %i\n", (int) s->estimated_stack_size);
    1132         1430 :           if (s->growth)
    1133          161 :             fprintf (f, "  estimated growth:%i\n", (int) s->growth);
    1134         1430 :           if (s->scc_no)
    1135            5 :             fprintf (f, "  In SCC:          %i\n", (int) s->scc_no);
    1136         5972 :           for (i = 0; s->size_time_table.iterate (i, &e); i++)
    1137              :             {
    1138         4542 :               fprintf (f, "    size:%f, time:%f",
    1139         4542 :                        (double) e->size / ipa_fn_summary::size_scale,
    1140              :                        e->time.to_double ());
    1141         4542 :               if (e->exec_predicate != true)
    1142              :                 {
    1143         2655 :                   fprintf (f, ",  executed if:");
    1144         2655 :                   e->exec_predicate.dump (f, s->conds, 0);
    1145              :                 }
    1146         4542 :               if (e->exec_predicate != e->nonconst_predicate)
    1147              :                 {
    1148         1187 :                   fprintf (f, ",  nonconst if:");
    1149         1187 :                   e->nonconst_predicate.dump (f, s->conds, 0);
    1150              :                 }
    1151         4542 :               fprintf (f, "\n");
    1152              :             }
    1153              :           ipa_freqcounting_predicate *fcp;
    1154              :           bool first_fcp = true;
    1155         1542 :           for (int i = 0; vec_safe_iterate (s->loop_iterations, i, &fcp); i++)
    1156              :             {
    1157          112 :               if (first_fcp)
    1158              :                 {
    1159           79 :                   fprintf (f, "  loop iterations:");
    1160           79 :                   first_fcp = false;
    1161              :                 }
    1162          112 :               fprintf (f, "  %3.2f for ", fcp->freq.to_double ());
    1163          112 :               fcp->predicate->dump (f, s->conds);
    1164              :             }
    1165              :           first_fcp = true;
    1166         1450 :           for (int i = 0; vec_safe_iterate (s->loop_strides, i, &fcp); i++)
    1167              :             {
    1168           20 :               if (first_fcp)
    1169              :                 {
    1170           11 :                   fprintf (f, "  loop strides:");
    1171           11 :                   first_fcp = false;
    1172              :                 }
    1173           20 :               fprintf (f, "  %3.2f for :", fcp->freq.to_double ());
    1174           20 :               fcp->predicate->dump (f, s->conds);
    1175              :             }
    1176         1430 :           fprintf (f, "  calls:\n");
    1177         1430 :           dump_ipa_call_summary (f, 4, node, s);
    1178         1430 :           fprintf (f, "\n");
    1179         1430 :           if (s->target_info)
    1180            0 :             fprintf (f, "  target_info: %x\n", s->target_info);
    1181              :         }
    1182              :       else
    1183          203 :         fprintf (f, "IPA summary for %s is missing.\n", node->dump_name ());
    1184              :     }
    1185         1633 : }
    1186              : 
    1187              : DEBUG_FUNCTION void
    1188            0 : ipa_debug_fn_summary (struct cgraph_node *node)
    1189              : {
    1190            0 :   ipa_dump_fn_summary (stderr, node);
    1191            0 : }
    1192              : 
    1193              : void
    1194          356 : ipa_dump_fn_summaries (FILE *f)
    1195              : {
    1196          356 :   struct cgraph_node *node;
    1197              : 
    1198         2296 :   FOR_EACH_DEFINED_FUNCTION (node)
    1199         1940 :     if (!node->inlined_to)
    1200         1386 :       ipa_dump_fn_summary (f, node);
    1201          356 : }
    1202              : 
    1203              : /* Callback of walk_aliased_vdefs.  Flags that it has been invoked to the
    1204              :    boolean variable pointed to by DATA.  */
    1205              : 
    1206              : static bool
    1207       852407 : mark_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef ATTRIBUTE_UNUSED,
    1208              :                void *data)
    1209              : {
    1210       852407 :   bool *b = (bool *) data;
    1211       852407 :   *b = true;
    1212       852407 :   return true;
    1213              : }
    1214              : 
    1215              : /* If OP refers to value of function parameter, return the corresponding
    1216              :    parameter.  If non-NULL, the size of the memory load (or the SSA_NAME of the
    1217              :    PARM_DECL) will be stored to *SIZE_P in that case too.  */
    1218              : 
    1219              : static tree
    1220    183430198 : unmodified_parm_1 (ipa_func_body_info *fbi, gimple *stmt, tree op,
    1221              :                    poly_int64 *size_p)
    1222              : {
    1223              :   /* SSA_NAME referring to parm default def?  */
    1224    183430198 :   if (TREE_CODE (op) == SSA_NAME
    1225    107266033 :       && SSA_NAME_IS_DEFAULT_DEF (op)
    1226    208590578 :       && TREE_CODE (SSA_NAME_VAR (op)) == PARM_DECL)
    1227              :     {
    1228     24962150 :       if (size_p)
    1229            0 :         *size_p = tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op)));
    1230     24962150 :       return SSA_NAME_VAR (op);
    1231              :     }
    1232              :   /* Non-SSA parm reference?  */
    1233    158468048 :   if (TREE_CODE (op) == PARM_DECL
    1234      1458895 :       && fbi->aa_walk_budget > 0)
    1235              :     {
    1236      1456349 :       bool modified = false;
    1237              : 
    1238      1456349 :       ao_ref refd;
    1239      1456349 :       ao_ref_init (&refd, op);
    1240      2912698 :       int walked = walk_aliased_vdefs (&refd, gimple_vuse (stmt),
    1241              :                                        mark_modified, &modified, NULL, NULL,
    1242              :                                        fbi->aa_walk_budget);
    1243      1456349 :       if (walked < 0)
    1244              :         {
    1245            8 :           fbi->aa_walk_budget = 0;
    1246       929026 :           return NULL_TREE;
    1247              :         }
    1248      1456341 :       fbi->aa_walk_budget -= walked;
    1249      1456341 :       if (!modified)
    1250              :         {
    1251       929018 :           if (size_p)
    1252            0 :             *size_p = tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op)));
    1253       929018 :           return op;
    1254              :         }
    1255              :     }
    1256              :   return NULL_TREE;
    1257              : }
    1258              : 
    1259              : /* If OP refers to value of function parameter, return the corresponding
    1260              :    parameter.  Also traverse chains of SSA register assignments.  If non-NULL,
    1261              :    the size of the memory load (or the SSA_NAME of the PARM_DECL) will be
    1262              :    stored to *SIZE_P in that case too.  */
    1263              : 
    1264              : static tree
    1265    119737087 : unmodified_parm (ipa_func_body_info *fbi, gimple *stmt, tree op,
    1266              :                  poly_int64 *size_p)
    1267              : {
    1268    149033141 :   tree res = unmodified_parm_1 (fbi, stmt, op, size_p);
    1269    149033141 :   if (res)
    1270              :     return res;
    1271              : 
    1272    123953161 :   if (TREE_CODE (op) == SSA_NAME
    1273     70372079 :       && !SSA_NAME_IS_DEFAULT_DEF (op)
    1274    194131505 :       && gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
    1275     29296054 :     return unmodified_parm (fbi, SSA_NAME_DEF_STMT (op),
    1276     29296054 :                             gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op)),
    1277     29296054 :                             size_p);
    1278              :   return NULL_TREE;
    1279              : }
    1280              : 
    1281              : /* If OP refers to a value of a function parameter or value loaded from an
    1282              :    aggregate passed to a parameter (either by value or reference), return TRUE
    1283              :    and store the number of the parameter to *INDEX_P, the access size into
    1284              :    *SIZE_P, and information whether and how it has been loaded from an
    1285              :    aggregate into *AGGPOS.  INFO describes the function parameters, STMT is the
    1286              :    statement in which OP is used or loaded.  */
    1287              : 
    1288              : static bool
    1289     32946766 : unmodified_parm_or_parm_agg_item (struct ipa_func_body_info *fbi,
    1290              :                                   gimple *stmt, tree op, int *index_p,
    1291              :                                   poly_int64 *size_p,
    1292              :                                   struct agg_position_info *aggpos)
    1293              : {
    1294     34397057 :   tree res = unmodified_parm_1 (fbi, stmt, op, size_p);
    1295              : 
    1296     34397057 :   gcc_checking_assert (aggpos);
    1297     34397057 :   if (res)
    1298              :     {
    1299       811188 :       *index_p = ipa_get_param_decl_index (fbi->info, res);
    1300       811188 :       if (*index_p < 0)
    1301              :         return false;
    1302       811058 :       aggpos->agg_contents = false;
    1303       811058 :       aggpos->by_ref = false;
    1304       811058 :       return true;
    1305              :     }
    1306              : 
    1307     33585869 :   if (TREE_CODE (op) == SSA_NAME)
    1308              :     {
    1309     11931804 :       if (SSA_NAME_IS_DEFAULT_DEF (op)
    1310     11931804 :           || !gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
    1311              :         return false;
    1312      4824925 :       stmt = SSA_NAME_DEF_STMT (op);
    1313      4824925 :       op = gimple_assign_rhs1 (stmt);
    1314      4824925 :       if (!REFERENCE_CLASS_P (op))
    1315              :         return unmodified_parm_or_parm_agg_item (fbi, stmt, op, index_p, size_p,
    1316              :                                                  aggpos);
    1317              :     }
    1318              : 
    1319     25028699 :   aggpos->agg_contents = true;
    1320     25028699 :   return ipa_load_from_parm_agg (fbi, fbi->info->descriptors,
    1321              :                                  stmt, op, index_p, &aggpos->offset,
    1322     25028699 :                                  size_p, &aggpos->by_ref);
    1323              : }
    1324              : 
    1325              : /* If stmt is simple load or store of value pointed to by a function parmaeter,
    1326              :    return its index.  */
    1327              : 
    1328              : static int
    1329    111023735 : load_or_store_of_ptr_parameter (ipa_func_body_info *fbi, gimple *stmt)
    1330              : {
    1331    111023735 :   if (!optimize)
    1332              :     return -1;
    1333    159225786 :   gassign *assign = dyn_cast <gassign *> (stmt);
    1334     55369289 :   if (!assign)
    1335              :     return -1;
    1336     55369289 :   tree param;
    1337     55369289 :   if (gimple_assign_load_p (stmt))
    1338     20355087 :     param = gimple_assign_rhs1 (stmt);
    1339     35014202 :   else if (gimple_store_p (stmt))
    1340     18573434 :     param = gimple_assign_lhs (stmt);
    1341              :   else
    1342              :     return -1;
    1343     38928521 :   tree base = get_base_address (param);
    1344     38928521 :   if (TREE_CODE (base) != MEM_REF
    1345     13479884 :       || TREE_CODE (TREE_OPERAND (base, 0)) != SSA_NAME
    1346     52404301 :       || !SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (base, 0)))
    1347              :     return -1;
    1348      7251338 :   tree p = SSA_NAME_VAR (TREE_OPERAND (base, 0));
    1349      7251338 :   if (TREE_CODE (p) != PARM_DECL)
    1350              :     return -1;
    1351      7167238 :   return ipa_get_param_decl_index (fbi->info, p);
    1352              : }
    1353              : 
    1354              : /* See if statement might disappear after inlining.
    1355              :    0 - means not eliminated
    1356              :    1 - half of statements goes away
    1357              :    2 - for sure it is eliminated.
    1358              :    We are not terribly sophisticated, basically looking for simple abstraction
    1359              :    penalty wrappers.  */
    1360              : 
    1361              : static int
    1362    111023735 : eliminated_by_inlining_prob (ipa_func_body_info *fbi, gimple *stmt)
    1363              : {
    1364    111023735 :   enum gimple_code code = gimple_code (stmt);
    1365    111023735 :   enum tree_code rhs_code;
    1366              : 
    1367    111023735 :   if (!optimize)
    1368              :     return 0;
    1369              : 
    1370     92820185 :   switch (code)
    1371              :     {
    1372              :     case GIMPLE_RETURN:
    1373              :       return 2;
    1374     55369289 :     case GIMPLE_ASSIGN:
    1375     55369289 :       if (gimple_num_ops (stmt) != 2)
    1376              :         return 0;
    1377              : 
    1378     39736325 :       rhs_code = gimple_assign_rhs_code (stmt);
    1379              : 
    1380              :       /* Casts of parameters, loads from parameters passed by reference
    1381              :          and stores to return value or parameters are often free after
    1382              :          inlining due to SRA and further combining.
    1383              :          Assume that half of statements goes away.  */
    1384     39736325 :       if (CONVERT_EXPR_CODE_P (rhs_code)
    1385              :           || rhs_code == VIEW_CONVERT_EXPR
    1386              :           || rhs_code == ADDR_EXPR
    1387     36946750 :           || gimple_assign_rhs_class (stmt) == GIMPLE_SINGLE_RHS)
    1388              :         {
    1389     38928521 :           tree rhs = gimple_assign_rhs1 (stmt);
    1390     38928521 :           tree lhs = gimple_assign_lhs (stmt);
    1391     38928521 :           tree inner_rhs = get_base_address (rhs);
    1392     38928521 :           tree inner_lhs = get_base_address (lhs);
    1393     38928521 :           bool rhs_free = false;
    1394     38928521 :           bool lhs_free = false;
    1395              : 
    1396     38928521 :           if (!inner_rhs)
    1397            0 :             inner_rhs = rhs;
    1398     38928521 :           if (!inner_lhs)
    1399            0 :             inner_lhs = lhs;
    1400              : 
    1401              :           /* Reads of parameter are expected to be free.  */
    1402     38928521 :           if (unmodified_parm (fbi, stmt, inner_rhs, NULL))
    1403              :             rhs_free = true;
    1404              :           /* Match expressions of form &this->field. Those will most likely
    1405              :              combine with something upstream after inlining.  */
    1406     37668296 :           else if (TREE_CODE (inner_rhs) == ADDR_EXPR)
    1407              :             {
    1408      2491230 :               tree op = get_base_address (TREE_OPERAND (inner_rhs, 0));
    1409      2491230 :               if (TREE_CODE (op) == PARM_DECL)
    1410              :                 rhs_free = true;
    1411      2451707 :               else if (TREE_CODE (op) == MEM_REF
    1412      2451707 :                        && unmodified_parm (fbi, stmt, TREE_OPERAND (op, 0),
    1413              :                                            NULL))
    1414              :                 rhs_free = true;
    1415              :             }
    1416              : 
    1417              :           /* When parameter is not SSA register because its address is taken
    1418              :              and it is just copied into one, the statement will be completely
    1419              :              free after inlining (we will copy propagate backward).   */
    1420      1299748 :           if (rhs_free && is_gimple_reg (lhs))
    1421              :             return 2;
    1422              : 
    1423              :           /* Reads of parameters passed by reference
    1424              :              expected to be free (i.e. optimized out after inlining).  */
    1425     38253197 :           if (TREE_CODE (inner_rhs) == MEM_REF
    1426     38253197 :               && unmodified_parm (fbi, stmt, TREE_OPERAND (inner_rhs, 0), NULL))
    1427              :             rhs_free = true;
    1428              : 
    1429              :           /* Copying parameter passed by reference into gimple register is
    1430              :              probably also going to copy propagate, but we can't be quite
    1431              :              sure.  */
    1432     38253197 :           if (rhs_free && is_gimple_reg (lhs))
    1433              :             lhs_free = true;
    1434              : 
    1435              :           /* Writes to parameters, parameters passed by value and return value
    1436              :              (either directly or passed via invisible reference) are free.
    1437              : 
    1438              :              TODO: We ought to handle testcase like
    1439              :              struct a {int a,b;};
    1440              :              struct a
    1441              :              returnstruct (void)
    1442              :              {
    1443              :              struct a a ={1,2};
    1444              :              return a;
    1445              :              }
    1446              : 
    1447              :              This translate into:
    1448              : 
    1449              :              returnstruct ()
    1450              :              {
    1451              :              int a$b;
    1452              :              int a$a;
    1453              :              struct a a;
    1454              :              struct a D.2739;
    1455              : 
    1456              :              <bb 2>:
    1457              :              D.2739.a = 1;
    1458              :              D.2739.b = 2;
    1459              :              return D.2739;
    1460              : 
    1461              :              }
    1462              :              For that we either need to copy ipa-split logic detecting writes
    1463              :              to return value.  */
    1464     38253197 :           if (TREE_CODE (inner_lhs) == PARM_DECL
    1465     38162946 :               || TREE_CODE (inner_lhs) == RESULT_DECL
    1466     75579416 :               || (TREE_CODE (inner_lhs) == MEM_REF
    1467      5022867 :                   && (unmodified_parm (fbi, stmt, TREE_OPERAND (inner_lhs, 0),
    1468              :                                        NULL)
    1469      2600751 :                       || (TREE_CODE (TREE_OPERAND (inner_lhs, 0)) == SSA_NAME
    1470      2599562 :                           && SSA_NAME_VAR (TREE_OPERAND (inner_lhs, 0))
    1471       360907 :                           && TREE_CODE (SSA_NAME_VAR (TREE_OPERAND
    1472              :                                                       (inner_lhs,
    1473              :                                                        0))) == RESULT_DECL))))
    1474              :             lhs_free = true;
    1475     34823263 :           if (lhs_free
    1476     38253197 :               && (is_gimple_reg (rhs) || is_gimple_min_invariant (rhs)))
    1477              :             rhs_free = true;
    1478     38253197 :           if (lhs_free && rhs_free)
    1479              :             return 1;
    1480              :         }
    1481              :       return 0;
    1482              :     default:
    1483              :       return 0;
    1484              :     }
    1485              : }
    1486              : 
    1487              : /* Analyze EXPR if it represents a series of simple operations performed on
    1488              :    a function parameter and return true if so.  FBI, STMT, EXPR, INDEX_P and
    1489              :    AGGPOS have the same meaning like in unmodified_parm_or_parm_agg_item.
    1490              :    Type of the parameter or load from an aggregate via the parameter is
    1491              :    stored in *TYPE_P.  Operations on the parameter are recorded to
    1492              :    PARAM_OPS_P if it is not NULL.  */
    1493              : 
    1494              : static bool
    1495     27114769 : decompose_param_expr (struct ipa_func_body_info *fbi,
    1496              :                       gimple *stmt, tree expr,
    1497              :                       int *index_p, tree *type_p,
    1498              :                       struct agg_position_info *aggpos,
    1499              :                       expr_eval_ops *param_ops_p = NULL)
    1500              : {
    1501     27114769 :   int op_limit = opt_for_fn (fbi->node->decl, param_ipa_max_param_expr_ops);
    1502     27114769 :   int op_count = 0;
    1503              : 
    1504     27114769 :   if (param_ops_p)
    1505      9280992 :     *param_ops_p = NULL;
    1506              : 
    1507     32946766 :   while (true)
    1508              :     {
    1509     32946766 :       expr_eval_op eval_op;
    1510     32946766 :       unsigned rhs_count;
    1511     32946766 :       unsigned cst_count = 0;
    1512              : 
    1513     32946766 :       if (unmodified_parm_or_parm_agg_item (fbi, stmt, expr, index_p, NULL,
    1514              :                                             aggpos))
    1515              :         {
    1516      4576628 :           tree type = TREE_TYPE (expr);
    1517              : 
    1518      4576628 :           if (aggpos->agg_contents)
    1519              :             {
    1520              :               /* Stop if containing bit-field.  */
    1521      3765570 :               if (TREE_CODE (expr) == BIT_FIELD_REF
    1522      3765570 :                   || contains_bitfld_component_ref_p (expr))
    1523              :                 break;
    1524              :             }
    1525              : 
    1526      4545064 :           *type_p = type;
    1527      4545064 :           return true;
    1528              :         }
    1529              : 
    1530     28370138 :       if (TREE_CODE (expr) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (expr))
    1531              :         break;
    1532     10595846 :       stmt = SSA_NAME_DEF_STMT (expr);
    1533              : 
    1534     10595846 :       if (gcall *call = dyn_cast <gcall *> (stmt))
    1535              :         {
    1536      2489089 :           int flags = gimple_call_return_flags (call);
    1537      2489089 :           if (!(flags & ERF_RETURNS_ARG))
    1538      3079086 :             goto fail;
    1539       209414 :           int arg = flags & ERF_RETURN_ARG_MASK;
    1540       209414 :           if (arg >= (int)gimple_call_num_args (call))
    1541            0 :             goto fail;
    1542       209414 :           expr = gimple_call_arg (stmt, arg);
    1543      4038763 :           continue;
    1544       209414 :         }
    1545              : 
    1546      8106757 :       if (!is_gimple_assign (stmt = SSA_NAME_DEF_STMT (expr)))
    1547              :         break;
    1548              : 
    1549      6422069 :       switch (gimple_assign_rhs_class (stmt))
    1550              :         {
    1551      3829349 :         case GIMPLE_SINGLE_RHS:
    1552      3829349 :           expr = gimple_assign_rhs1 (stmt);
    1553      3829349 :           continue;
    1554              : 
    1555              :         case GIMPLE_UNARY_RHS:
    1556              :           rhs_count = 1;
    1557              :           break;
    1558              : 
    1559      1563503 :         case GIMPLE_BINARY_RHS:
    1560      1563503 :           rhs_count = 2;
    1561      1563503 :           break;
    1562              : 
    1563          642 :         case GIMPLE_TERNARY_RHS:
    1564          642 :           rhs_count = 3;
    1565          642 :           break;
    1566              : 
    1567            0 :         default:
    1568            0 :           goto fail;
    1569              :         }
    1570              : 
    1571              :       /* Stop if expression is too complex.  */
    1572      2592720 :       if (op_count++ == op_limit)
    1573              :         break;
    1574              : 
    1575      2592645 :       if (param_ops_p)
    1576              :         {
    1577      2575993 :           eval_op.code = gimple_assign_rhs_code (stmt);
    1578      2575993 :           eval_op.type = TREE_TYPE (gimple_assign_lhs (stmt));
    1579      2575993 :           eval_op.val[0] = NULL_TREE;
    1580      2575993 :           eval_op.val[1] = NULL_TREE;
    1581              :         }
    1582              : 
    1583              :       expr = NULL_TREE;
    1584      5950038 :       for (unsigned i = 0; i < rhs_count; i++)
    1585              :         {
    1586      4156804 :           tree op = gimple_op (stmt, i + 1);
    1587              : 
    1588      4156804 :           gcc_assert (op && !TYPE_P (op));
    1589      4156804 :           if (is_gimple_ip_invariant (op))
    1590              :             {
    1591       767042 :               if (++cst_count == rhs_count)
    1592         1147 :                 goto fail;
    1593              : 
    1594       765895 :               eval_op.val[cst_count - 1] = op;
    1595              :             }
    1596      3389762 :           else if (!expr)
    1597              :             {
    1598              :               /* Found a non-constant operand, and record its index in rhs
    1599              :                  operands.  */
    1600      2591498 :               eval_op.index = i;
    1601      2591498 :               expr = op;
    1602              :             }
    1603              :           else
    1604              :             {
    1605              :               /* Found more than one non-constant operands.  */
    1606       798264 :               goto fail;
    1607              :             }
    1608              :         }
    1609              : 
    1610      1793234 :       if (param_ops_p)
    1611      1777027 :         vec_safe_insert (*param_ops_p, 0, eval_op);
    1612              :     }
    1613              : 
    1614              :   /* Failed to decompose, free resource and return.  */
    1615     22569705 : fail:
    1616     22569705 :   if (param_ops_p)
    1617      9101198 :     vec_free (*param_ops_p);
    1618              : 
    1619              :   return false;
    1620              : }
    1621              : 
    1622              : /* Record to SUMMARY that PARM is used by builtin_constant_p.  */
    1623              : 
    1624              : static void
    1625        10804 : add_builtin_constant_p_parm (class ipa_fn_summary *summary, int parm)
    1626              : {
    1627        10804 :   int ip;
    1628              : 
    1629              :   /* Avoid duplicates.  */
    1630        10842 :   for (unsigned int i = 0;
    1631        10842 :        summary->builtin_constant_p_parms.iterate (i, &ip); i++)
    1632         5212 :     if (ip == parm)
    1633        10804 :       return;
    1634         5630 :   summary->builtin_constant_p_parms.safe_push (parm);
    1635              : }
    1636              : 
    1637              : /* If BB ends by a conditional we can turn into predicates, attach corresponding
    1638              :    predicates to the CFG edges.   */
    1639              : 
    1640              : static void
    1641     34909912 : set_cond_stmt_execution_predicate (struct ipa_func_body_info *fbi,
    1642              :                                    class ipa_fn_summary *summary,
    1643              :                                    class ipa_node_params *params_summary,
    1644              :                                    basic_block bb)
    1645              : {
    1646     34909912 :   tree op, op2;
    1647     34909912 :   int index;
    1648     34909912 :   struct agg_position_info aggpos;
    1649     34909912 :   enum tree_code code, inverted_code;
    1650     34909912 :   edge e;
    1651     34909912 :   edge_iterator ei;
    1652     34909912 :   gimple *set_stmt;
    1653     34909912 :   tree param_type;
    1654     34909912 :   expr_eval_ops param_ops;
    1655              : 
    1656     69819824 :   gcond *last = safe_dyn_cast <gcond *> (*gsi_last_bb (bb));
    1657     11615655 :   if (!last)
    1658     34898653 :     return;
    1659     11615655 :   if (!is_gimple_ip_invariant (gimple_cond_rhs (last)))
    1660              :     return;
    1661      9198566 :   op = gimple_cond_lhs (last);
    1662              : 
    1663      9198566 :   if (decompose_param_expr (fbi, last, op, &index, &param_type, &aggpos,
    1664              :                             &param_ops))
    1665              :     {
    1666      1300411 :       code = gimple_cond_code (last);
    1667      1300411 :       inverted_code = invert_tree_comparison (code, HONOR_NANS (op));
    1668              : 
    1669      3901233 :       FOR_EACH_EDGE (e, ei, bb->succs)
    1670              :         {
    1671      1300411 :           enum tree_code this_code = (e->flags & EDGE_TRUE_VALUE
    1672      2600822 :                                       ? code : inverted_code);
    1673              :           /* invert_tree_comparison will return ERROR_MARK on FP
    1674              :              comparisons that are not EQ/NE instead of returning proper
    1675              :              unordered one.  Be sure it is not confused with NON_CONSTANT.
    1676              : 
    1677              :              And if the edge's target is the final block of diamond CFG graph
    1678              :              of this conditional statement, we do not need to compute
    1679              :              predicate for the edge because the final block's predicate must
    1680              :              be at least as that of the first block of the statement.  */
    1681      2600822 :           if (this_code != ERROR_MARK
    1682      2600822 :               && !dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    1683              :             {
    1684      2190197 :               ipa_predicate p
    1685      2190197 :                 = add_condition (summary, params_summary, index,
    1686              :                                  param_type, &aggpos,
    1687              :                                  this_code, gimple_cond_rhs (last), param_ops);
    1688      2190197 :               e->aux = edge_predicate_pool.allocate ();
    1689      2190197 :               *(ipa_predicate *) e->aux = p;
    1690              :             }
    1691              :         }
    1692      1300411 :       vec_free (param_ops);
    1693      1300411 :       return;
    1694              :     }
    1695              : 
    1696      7898155 :   if (TREE_CODE (op) != SSA_NAME)
    1697              :     return;
    1698              :   /* Special case
    1699              :      if (builtin_constant_p (op))
    1700              :      constant_code
    1701              :      else
    1702              :      nonconstant_code.
    1703              :      Here we can predicate nonconstant_code.  We can't
    1704              :      really handle constant_code since we have no predicate
    1705              :      for this and also the constant code is not known to be
    1706              :      optimized away when inliner doesn't see operand is constant.
    1707              :      Other optimizers might think otherwise.  */
    1708      7897084 :   if (gimple_cond_code (last) != NE_EXPR
    1709      7897084 :       || !integer_zerop (gimple_cond_rhs (last)))
    1710      4468970 :     return;
    1711      3428114 :   set_stmt = SSA_NAME_DEF_STMT (op);
    1712      3428114 :   if (!gimple_call_builtin_p (set_stmt, BUILT_IN_CONSTANT_P)
    1713      3428114 :       || gimple_call_num_args (set_stmt) != 1)
    1714              :     return;
    1715        27768 :   op2 = gimple_call_arg (set_stmt, 0);
    1716        27768 :   if (!decompose_param_expr (fbi, set_stmt, op2, &index, &param_type, &aggpos))
    1717              :     return;
    1718        11259 :   if (!aggpos.by_ref)
    1719        10768 :     add_builtin_constant_p_parm (summary, index);
    1720        33777 :   FOR_EACH_EDGE (e, ei, bb->succs) if (e->flags & EDGE_FALSE_VALUE)
    1721              :     {
    1722        11259 :       ipa_predicate p = add_condition (summary, params_summary, index,
    1723              :                                    param_type, &aggpos,
    1724              :                                    ipa_predicate::is_not_constant, NULL_TREE);
    1725        11259 :       e->aux = edge_predicate_pool.allocate ();
    1726        11259 :       *(ipa_predicate *) e->aux = p;
    1727              :     }
    1728              : }
    1729              : 
    1730              : 
    1731              : /* If BB ends by a switch we can turn into predicates, attach corresponding
    1732              :    predicates to the CFG edges.   */
    1733              : 
    1734              : static void
    1735     34909912 : set_switch_stmt_execution_predicate (struct ipa_func_body_info *fbi,
    1736              :                                      class ipa_fn_summary *summary,
    1737              :                                      class ipa_node_params *params_summary,
    1738              :                                      basic_block bb)
    1739              : {
    1740     34909912 :   tree op;
    1741     34909912 :   int index;
    1742     34909912 :   struct agg_position_info aggpos;
    1743     34909912 :   edge e;
    1744     34909912 :   edge_iterator ei;
    1745     34909912 :   size_t n;
    1746     34909912 :   size_t case_idx;
    1747     34909912 :   tree param_type;
    1748     34909912 :   expr_eval_ops param_ops;
    1749              : 
    1750     69819824 :   gswitch *last = safe_dyn_cast <gswitch *> (*gsi_last_bb (bb));
    1751        82426 :   if (!last)
    1752     34878026 :     return;
    1753        82426 :   op = gimple_switch_index (last);
    1754        82426 :   if (!decompose_param_expr (fbi, last, op, &index, &param_type, &aggpos,
    1755              :                              &param_ops))
    1756              :     return;
    1757              : 
    1758        47216 :   auto_vec<std::pair<tree, tree> > ranges;
    1759        47216 :   tree type = TREE_TYPE (op);
    1760        47216 :   int bound_limit = opt_for_fn (fbi->node->decl,
    1761              :                                 param_ipa_max_switch_predicate_bounds);
    1762        47216 :   int bound_count = 0;
    1763              :   // This can safely be an integer range, as switches can only hold
    1764              :   // integers.
    1765        47216 :   int_range<2> vr;
    1766              : 
    1767        94432 :   get_range_query (cfun)->range_of_expr (vr, op);
    1768        47216 :   if (vr.undefined_p ())
    1769            0 :     vr.set_varying (TREE_TYPE (op));
    1770        47216 :   tree vr_min, vr_max;
    1771              :   // TODO: This entire function could use a rewrite to use the irange
    1772              :   // API, instead of trying to recreate its intersection/union logic.
    1773              :   // Any use of get_legacy_range() is a serious code smell.
    1774        47216 :   value_range_kind vr_type = get_legacy_range (vr, vr_min, vr_max);
    1775        47216 :   wide_int vr_wmin = wi::to_wide (vr_min);
    1776        47216 :   wide_int vr_wmax = wi::to_wide (vr_max);
    1777              : 
    1778       328285 :   FOR_EACH_EDGE (e, ei, bb->succs)
    1779              :     {
    1780       281069 :       e->aux = edge_predicate_pool.allocate ();
    1781       281069 :       *(ipa_predicate *) e->aux = false;
    1782              :     }
    1783              : 
    1784        47216 :   e = gimple_switch_edge (cfun, last, 0);
    1785              :   /* Set BOUND_COUNT to maximum count to bypass computing predicate for
    1786              :      default case if its target basic block is in convergence point of all
    1787              :      switch cases, which can be determined by checking whether it
    1788              :      post-dominates the switch statement.  */
    1789        47216 :   if (dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    1790        12604 :     bound_count = INT_MAX;
    1791              : 
    1792        47216 :   n = gimple_switch_num_labels (last);
    1793       313501 :   for (case_idx = 1; case_idx < n; ++case_idx)
    1794              :     {
    1795       266285 :       tree cl = gimple_switch_label (last, case_idx);
    1796       266285 :       tree min = CASE_LOW (cl);
    1797       266285 :       tree max = CASE_HIGH (cl);
    1798       266285 :       ipa_predicate p;
    1799              : 
    1800       266285 :       e = gimple_switch_edge (cfun, last, case_idx);
    1801              : 
    1802              :       /* The case value might not have same type as switch expression,
    1803              :          extend the value based on the expression type.  */
    1804       266285 :       if (TREE_TYPE (min) != type)
    1805        52405 :         min = wide_int_to_tree (type, wi::to_wide (min));
    1806              : 
    1807       266285 :       if (!max)
    1808              :         max = min;
    1809        15337 :       else if (TREE_TYPE (max) != type)
    1810         6488 :         max = wide_int_to_tree (type, wi::to_wide (max));
    1811              : 
    1812              :       /* The case's target basic block is in convergence point of all switch
    1813              :          cases, its predicate should be at least as that of the switch
    1814              :          statement.  */
    1815       266285 :       if (dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    1816         5024 :         p = true;
    1817       261261 :       else if (min == max)
    1818       247616 :         p = add_condition (summary, params_summary, index, param_type,
    1819              :                            &aggpos, EQ_EXPR, min, param_ops);
    1820              :       else
    1821              :         {
    1822        13645 :           ipa_predicate p1, p2;
    1823        13645 :           p1 = add_condition (summary, params_summary, index, param_type,
    1824              :                               &aggpos, GE_EXPR, min, param_ops);
    1825        13645 :           p2 = add_condition (summary,  params_summary,index, param_type,
    1826              :                               &aggpos, LE_EXPR, max, param_ops);
    1827        13645 :           p = p1 & p2;
    1828              :         }
    1829       266285 :       *(ipa_predicate *) e->aux
    1830       266285 :         = p.or_with (summary->conds, *(ipa_predicate *) e->aux);
    1831              : 
    1832              :       /* If there are too many disjoint case ranges, predicate for default
    1833              :          case might become too complicated.  So add a limit here.  */
    1834       266285 :       if (bound_count > bound_limit)
    1835        96253 :         continue;
    1836              : 
    1837       170032 :       bool new_range = true;
    1838              : 
    1839       170032 :       if (!ranges.is_empty ())
    1840              :         {
    1841       135420 :           wide_int curr_wmin = wi::to_wide (min);
    1842       135420 :           wide_int last_wmax = wi::to_wide (ranges.last ().second);
    1843              : 
    1844              :           /* Merge case ranges if they are continuous.  */
    1845       135420 :           if (curr_wmin == last_wmax + 1)
    1846              :             new_range = false;
    1847        46296 :           else if (vr_type == VR_ANTI_RANGE)
    1848              :             {
    1849              :               /* If two disjoint case ranges can be connected by anti-range
    1850              :                  of switch index, combine them to one range.  */
    1851           79 :               if (wi::lt_p (vr_wmax, curr_wmin - 1, TYPE_SIGN (type)))
    1852              :                 vr_type = VR_UNDEFINED;
    1853            0 :               else if (wi::le_p (vr_wmin, last_wmax + 1, TYPE_SIGN (type)))
    1854            0 :                 new_range = false;
    1855              :             }
    1856       135420 :         }
    1857              : 
    1858              :       /* Create/extend a case range.  And we count endpoints of range set,
    1859              :          this number nearly equals to number of conditions that we will create
    1860              :          for predicate of default case.  */
    1861       135420 :       if (new_range)
    1862              :         {
    1863        80908 :           bound_count += (min == max) ? 1 : 2;
    1864        80908 :           ranges.safe_push (std::make_pair (min, max));
    1865              :         }
    1866              :       else
    1867              :         {
    1868        89124 :           bound_count += (ranges.last ().first == ranges.last ().second);
    1869        89124 :           ranges.last ().second = max;
    1870              :         }
    1871              :     }
    1872              : 
    1873        47216 :   e = gimple_switch_edge (cfun, last, 0);
    1874        47216 :   if (bound_count > bound_limit)
    1875              :     {
    1876        15330 :       *(ipa_predicate *) e->aux = true;
    1877        15330 :       vec_free (param_ops);
    1878        15330 :       return;
    1879              :     }
    1880              : 
    1881        31886 :   ipa_predicate p_seg = true;
    1882        31886 :   ipa_predicate p_all = false;
    1883              : 
    1884        31886 :   if (vr_type != VR_RANGE)
    1885              :     {
    1886        31365 :       vr_wmin = wi::to_wide (TYPE_MIN_VALUE (type));
    1887        31365 :       vr_wmax = wi::to_wide (TYPE_MAX_VALUE (type));
    1888              :     }
    1889              : 
    1890              :   /* Construct predicate to represent default range set that is negation of
    1891              :      all case ranges.  Case range is classified as containing single/non-single
    1892              :      values.  Suppose a piece of case ranges in the following.
    1893              : 
    1894              :                 [D1...D2]  [S1] ... [Sn]  [D3...D4]
    1895              : 
    1896              :      To represent default case's range sets between two non-single value
    1897              :      case ranges (From D2 to D3), we construct predicate as:
    1898              : 
    1899              :               D2 < x < D3 && x != S1 && ... && x != Sn
    1900              :    */
    1901        99266 :   for (size_t i = 0; i < ranges.length (); i++)
    1902              :     {
    1903        67475 :       tree min = ranges[i].first;
    1904        67475 :       tree max = ranges[i].second;
    1905              : 
    1906        67475 :       if (min == max)
    1907        83856 :         p_seg &= add_condition (summary, params_summary, index,
    1908              :                                 param_type, &aggpos, NE_EXPR,
    1909        41928 :                                 min, param_ops);
    1910              :       else
    1911              :         {
    1912              :           /* Do not create sub-predicate for range that is beyond low bound
    1913              :              of switch index.  */
    1914        25547 :           if (wi::lt_p (vr_wmin, wi::to_wide (min), TYPE_SIGN (type)))
    1915              :             {
    1916        18093 :               p_seg &= add_condition (summary, params_summary, index,
    1917              :                                       param_type, &aggpos,
    1918        18093 :                                       LT_EXPR, min, param_ops);
    1919        18093 :               p_all = p_all.or_with (summary->conds, p_seg);
    1920              :             }
    1921              : 
    1922              :           /* Do not create sub-predicate for range that is beyond up bound
    1923              :              of switch index.  */
    1924        25547 :           if (wi::le_p (vr_wmax, wi::to_wide (max), TYPE_SIGN (type)))
    1925              :             {
    1926           95 :               p_seg = false;
    1927           95 :               break;
    1928              :             }
    1929              : 
    1930        25452 :           p_seg = add_condition (summary, params_summary, index,
    1931              :                                  param_type, &aggpos, GT_EXPR,
    1932              :                                  max, param_ops);
    1933              :         }
    1934              :     }
    1935              : 
    1936        31886 :   p_all = p_all.or_with (summary->conds, p_seg);
    1937        31886 :   *(ipa_predicate *) e->aux
    1938        31886 :     = p_all.or_with (summary->conds, *(ipa_predicate *) e->aux);
    1939              : 
    1940        38348 :   vec_free (param_ops);
    1941        47216 : }
    1942              : 
    1943              : 
    1944              : /* For each BB in NODE attach to its AUX pointer predicate under
    1945              :    which it is executable.  */
    1946              : 
    1947              : static void
    1948      6221162 : compute_bb_predicates (struct ipa_func_body_info *fbi,
    1949              :                        struct cgraph_node *node,
    1950              :                        class ipa_fn_summary *summary,
    1951              :                        class ipa_node_params *params_summary)
    1952              : {
    1953      6221162 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    1954      6221162 :   bool done = false;
    1955      6221162 :   basic_block bb;
    1956              : 
    1957     41131074 :   FOR_EACH_BB_FN (bb, my_function)
    1958              :     {
    1959     34909912 :       set_cond_stmt_execution_predicate (fbi, summary, params_summary, bb);
    1960     34909912 :       set_switch_stmt_execution_predicate (fbi, summary, params_summary, bb);
    1961              :     }
    1962              : 
    1963              :   /* Entry block is always executable.  */
    1964      6221162 :   ENTRY_BLOCK_PTR_FOR_FN (my_function)->aux
    1965      6221162 :     = edge_predicate_pool.allocate ();
    1966      6221162 :   *(ipa_predicate *) ENTRY_BLOCK_PTR_FOR_FN (my_function)->aux = true;
    1967              : 
    1968              :   /* A simple dataflow propagation of predicates forward in the CFG.
    1969              :      TODO: work in reverse postorder.  */
    1970     18782234 :   while (!done)
    1971              :     {
    1972     12561072 :       done = true;
    1973     87462363 :       FOR_EACH_BB_FN (bb, my_function)
    1974              :         {
    1975     74901291 :           ipa_predicate p = false;
    1976     74901291 :           edge e;
    1977     74901291 :           edge_iterator ei;
    1978     92923934 :           FOR_EACH_EDGE (e, ei, bb->preds)
    1979              :             {
    1980     79637939 :               if (e->src->aux)
    1981              :                 {
    1982     77892165 :                   ipa_predicate this_bb_predicate
    1983              :                     = *(ipa_predicate *) e->src->aux;
    1984     77892165 :                   if (e->aux)
    1985      5171431 :                     this_bb_predicate &= (*(ipa_predicate *) e->aux);
    1986     77892165 :                   p = p.or_with (summary->conds, this_bb_predicate);
    1987     77892165 :                   if (p == true)
    1988              :                     break;
    1989              :                 }
    1990              :             }
    1991     74901291 :           if (p != false)
    1992              :             {
    1993     73762188 :               basic_block pdom_bb;
    1994              : 
    1995     73762188 :               if (!bb->aux)
    1996              :                 {
    1997     27324309 :                   done = false;
    1998     27324309 :                   bb->aux = edge_predicate_pool.allocate ();
    1999     27324309 :                   *((ipa_predicate *) bb->aux) = p;
    2000              :                 }
    2001     46437879 :               else if (p != *(ipa_predicate *) bb->aux)
    2002              :                 {
    2003              :                   /* This OR operation is needed to ensure monotonous data flow
    2004              :                      in the case we hit the limit on number of clauses and the
    2005              :                      and/or operations above give approximate answers.  */
    2006       128764 :                   p = p.or_with (summary->conds, *(ipa_predicate *)bb->aux);
    2007       128764 :                   if (p != *(ipa_predicate *)bb->aux)
    2008              :                     {
    2009       105067 :                       done = false;
    2010       105067 :                       *((ipa_predicate *)bb->aux) = p;
    2011              :                     }
    2012              :                 }
    2013              : 
    2014              :               /* For switch/if statement, we can OR-combine predicates of all
    2015              :                  its cases/branches to get predicate for basic block in their
    2016              :                  convergence point, but sometimes this will generate very
    2017              :                  complicated predicate.  Actually, we can get simplified
    2018              :                  predicate in another way by using the fact that predicate
    2019              :                  for a basic block must also hold true for its post dominators.
    2020              :                  To be specific, basic block in convergence point of
    2021              :                  conditional statement should include predicate of the
    2022              :                  statement.  */
    2023     73762188 :               pdom_bb = get_immediate_dominator (CDI_POST_DOMINATORS, bb);
    2024     73762188 :               if (pdom_bb == EXIT_BLOCK_PTR_FOR_FN (my_function) || !pdom_bb)
    2025              :                 ;
    2026     38114920 :               else if (!pdom_bb->aux)
    2027              :                 {
    2028      7585589 :                   done = false;
    2029      7585589 :                   pdom_bb->aux = edge_predicate_pool.allocate ();
    2030      7585589 :                   *((ipa_predicate *)pdom_bb->aux) = p;
    2031              :                 }
    2032     30529331 :               else if (p != *(ipa_predicate *)pdom_bb->aux)
    2033              :                 {
    2034      3393867 :                   p = p.or_with (summary->conds,
    2035              :                                  *(ipa_predicate *)pdom_bb->aux);
    2036      3393867 :                   if (p != *(ipa_predicate *)pdom_bb->aux)
    2037              :                     {
    2038       155516 :                       done = false;
    2039       155516 :                       *((ipa_predicate *)pdom_bb->aux) = p;
    2040              :                     }
    2041              :                 }
    2042              :             }
    2043              :         }
    2044              :     }
    2045      6221162 : }
    2046              : 
    2047              : 
    2048              : /* Return predicate specifying when the STMT might have result that is not
    2049              :    a compile time constant.  */
    2050              : 
    2051              : static ipa_predicate
    2052      4250889 : will_be_nonconstant_expr_predicate (ipa_func_body_info *fbi,
    2053              :                                     class ipa_fn_summary *summary,
    2054              :                                     class ipa_node_params *params_summary,
    2055              :                                     tree expr,
    2056              :                                     vec<ipa_predicate> nonconstant_names)
    2057              : {
    2058      4250889 :   tree parm;
    2059      4250889 :   int index;
    2060              : 
    2061      4510756 :   while (UNARY_CLASS_P (expr))
    2062       259867 :     expr = TREE_OPERAND (expr, 0);
    2063              : 
    2064      4250889 :   parm = unmodified_parm (fbi, NULL, expr, NULL);
    2065      4250889 :   if (parm && (index = ipa_get_param_decl_index (fbi->info, parm)) >= 0)
    2066       228140 :     return add_condition (summary, params_summary, index, TREE_TYPE (parm), NULL,
    2067       228140 :                           ipa_predicate::changed, NULL_TREE);
    2068      4022749 :   if (is_gimple_min_invariant (expr))
    2069        62220 :     return false;
    2070      3960529 :   if (TREE_CODE (expr) == SSA_NAME)
    2071      3778384 :     return nonconstant_names[SSA_NAME_VERSION (expr)];
    2072       182145 :   if (BINARY_CLASS_P (expr) || COMPARISON_CLASS_P (expr))
    2073              :     {
    2074       181519 :       ipa_predicate p1
    2075       181519 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2076              :                                               params_summary,
    2077       181519 :                                               TREE_OPERAND (expr, 0),
    2078              :                                               nonconstant_names);
    2079       181519 :       if (p1 == true)
    2080       106456 :         return p1;
    2081              : 
    2082        75063 :       ipa_predicate p2
    2083        75063 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2084              :                                               params_summary,
    2085        75063 :                                               TREE_OPERAND (expr, 1),
    2086              :                                               nonconstant_names);
    2087        75063 :       return p1.or_with (summary->conds, p2);
    2088              :     }
    2089          626 :   else if (TREE_CODE (expr) == COND_EXPR)
    2090              :     {
    2091          184 :       ipa_predicate p1
    2092          184 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2093              :                                               params_summary,
    2094          184 :                                               TREE_OPERAND (expr, 0),
    2095              :                                               nonconstant_names);
    2096          184 :       if (p1 == true)
    2097           33 :         return p1;
    2098              : 
    2099          151 :       ipa_predicate p2
    2100          151 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2101              :                                               params_summary,
    2102          151 :                                               TREE_OPERAND (expr, 1),
    2103              :                                               nonconstant_names);
    2104          151 :       if (p2 == true)
    2105          151 :         return p2;
    2106            0 :       p1 = p1.or_with (summary->conds, p2);
    2107            0 :       p2 = will_be_nonconstant_expr_predicate (fbi, summary,
    2108              :                                                params_summary,
    2109            0 :                                                TREE_OPERAND (expr, 2),
    2110              :                                                nonconstant_names);
    2111            0 :       return p2.or_with (summary->conds, p1);
    2112              :     }
    2113          442 :   else if (TREE_CODE (expr) == CALL_EXPR)
    2114          442 :     return true;
    2115              :   else
    2116              :     {
    2117            0 :       debug_tree (expr);
    2118            0 :       gcc_unreachable ();
    2119              :     }
    2120              : }
    2121              : 
    2122              : 
    2123              : /* Return predicate specifying when the STMT might have result that is not
    2124              :    a compile time constant.  */
    2125              : 
    2126              : static ipa_predicate
    2127    113260921 : will_be_nonconstant_predicate (struct ipa_func_body_info *fbi,
    2128              :                                class ipa_fn_summary *summary,
    2129              :                                class ipa_node_params *params_summary,
    2130              :                                gimple *stmt,
    2131              :                                vec<ipa_predicate> nonconstant_names)
    2132              : {
    2133    113260921 :   ipa_predicate p = true;
    2134    113260921 :   ssa_op_iter iter;
    2135    113260921 :   tree use;
    2136    113260921 :   tree param_type = NULL_TREE;
    2137    113260921 :   ipa_predicate op_non_const;
    2138    113260921 :   bool is_load;
    2139    113260921 :   int base_index;
    2140    113260921 :   struct agg_position_info aggpos;
    2141              : 
    2142              :   /* What statements might be optimized away
    2143              :      when their arguments are constant.  */
    2144    113260921 :   if (gimple_code (stmt) != GIMPLE_ASSIGN
    2145     38835469 :       && gimple_code (stmt) != GIMPLE_COND
    2146     27470723 :       && gimple_code (stmt) != GIMPLE_SWITCH
    2147    140649218 :       && (gimple_code (stmt) != GIMPLE_CALL
    2148     20582780 :           || !(gimple_call_flags (stmt) & ECF_CONST)))
    2149     25748502 :     return p;
    2150              : 
    2151              :   /* Stores will stay anyway.  */
    2152     87512419 :   if (gimple_store_p (stmt))
    2153     25577587 :     return p;
    2154              : 
    2155     61934832 :   is_load = gimple_assign_load_p (stmt);
    2156              : 
    2157              :   /* Loads can be optimized when the value is known.  */
    2158     61934832 :   if (is_load)
    2159              :     {
    2160     17806009 :       tree op = gimple_assign_rhs1 (stmt);
    2161     17806009 :       if (!decompose_param_expr (fbi, stmt, op, &base_index, &param_type,
    2162              :                                  &aggpos))
    2163     14619831 :         return p;
    2164              :     }
    2165              :   else
    2166     44128823 :     base_index = -1;
    2167              : 
    2168              :   /* See if we understand all operands before we start
    2169              :      adding conditionals.  */
    2170     63907090 :   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2171              :     {
    2172     46982915 :       tree parm = unmodified_parm (fbi, stmt, use, NULL);
    2173              :       /* For arguments we can build a condition.  */
    2174     46982915 :       if (parm && ipa_get_param_decl_index (fbi->info, parm) >= 0)
    2175      8319633 :         continue;
    2176     38663282 :       if (TREE_CODE (use) != SSA_NAME)
    2177            0 :         return p;
    2178              :       /* If we know when operand is constant,
    2179              :          we still can say something useful.  */
    2180     38663282 :       if (nonconstant_names[SSA_NAME_VERSION (use)] != true)
    2181      8272456 :         continue;
    2182     30390826 :       return p;
    2183              :     }
    2184              : 
    2185     16924175 :   if (is_load)
    2186      3186097 :     op_non_const =
    2187      3186097 :       add_condition (summary, params_summary,
    2188              :                      base_index, param_type, &aggpos,
    2189              :                      ipa_predicate::changed, NULL_TREE);
    2190              :   else
    2191     13738078 :     op_non_const = false;
    2192     32485731 :   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2193              :     {
    2194     15561556 :       tree parm = unmodified_parm (fbi, stmt, use, NULL);
    2195     15561556 :       int index;
    2196              : 
    2197     15561556 :       if (parm && (index = ipa_get_param_decl_index (fbi->info, parm)) >= 0)
    2198              :         {
    2199      7829134 :           if (index != base_index)
    2200      5339894 :             p = add_condition (summary, params_summary, index,
    2201      5339894 :                                TREE_TYPE (parm), NULL,
    2202              :                                ipa_predicate::changed, NULL_TREE);
    2203              :           else
    2204      2489240 :             continue;
    2205              :         }
    2206              :       else
    2207      7732422 :         p = nonconstant_names[SSA_NAME_VERSION (use)];
    2208     13072316 :       op_non_const = p.or_with (summary->conds, op_non_const);
    2209              :     }
    2210     16924175 :   if ((gimple_code (stmt) == GIMPLE_ASSIGN || gimple_code (stmt) == GIMPLE_CALL)
    2211     14739594 :       && gimple_op (stmt, 0)
    2212     31376312 :       && TREE_CODE (gimple_op (stmt, 0)) == SSA_NAME)
    2213     14452137 :     nonconstant_names[SSA_NAME_VERSION (gimple_op (stmt, 0))]
    2214     14452137 :       = op_non_const;
    2215     16924175 :   return op_non_const;
    2216              : }
    2217              : 
    2218              : struct record_modified_bb_info
    2219              : {
    2220              :   tree op;
    2221              :   bitmap bb_set;
    2222              :   gimple *stmt;
    2223              : };
    2224              : 
    2225              : /* Value is initialized in INIT_BB and used in USE_BB.  We want to compute
    2226              :    probability how often it changes between USE_BB.
    2227              :    INIT_BB->count/USE_BB->count is an estimate, but if INIT_BB
    2228              :    is in different loop nest, we can do better.
    2229              :    This is all just estimate.  In theory we look for minimal cut separating
    2230              :    INIT_BB and USE_BB, but we only want to anticipate loop invariant motion
    2231              :    anyway.  */
    2232              : 
    2233              : static basic_block
    2234     10390766 : get_minimal_bb (basic_block init_bb, basic_block use_bb)
    2235              : {
    2236     10390766 :   class loop *l = find_common_loop (init_bb->loop_father, use_bb->loop_father);
    2237     10390766 :   if (l && l->header->count < init_bb->count)
    2238       371511 :     return l->header;
    2239              :   return init_bb;
    2240              : }
    2241              : 
    2242              : /* Callback of walk_aliased_vdefs.  Records basic blocks where the value may be
    2243              :    set except for info->stmt.  */
    2244              : 
    2245              : static bool
    2246      4843890 : record_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data)
    2247              : {
    2248      4843890 :   struct record_modified_bb_info *info =
    2249              :     (struct record_modified_bb_info *) data;
    2250      4843890 :   if (SSA_NAME_DEF_STMT (vdef) == info->stmt)
    2251              :     return false;
    2252      4815366 :   if (gimple_clobber_p (SSA_NAME_DEF_STMT (vdef)))
    2253              :     return false;
    2254      4766370 :   bitmap_set_bit (info->bb_set,
    2255      4766370 :                   SSA_NAME_IS_DEFAULT_DEF (vdef)
    2256            0 :                   ? ENTRY_BLOCK_PTR_FOR_FN (cfun)->index
    2257              :                   : get_minimal_bb
    2258      4766370 :                          (gimple_bb (SSA_NAME_DEF_STMT (vdef)),
    2259      4766370 :                           gimple_bb (info->stmt))->index);
    2260      4766370 :   if (dump_file)
    2261              :     {
    2262            0 :       fprintf (dump_file, "     Param ");
    2263            0 :       print_generic_expr (dump_file, info->op, TDF_SLIM);
    2264            0 :       fprintf (dump_file, " changed at bb %i, minimal: %i stmt: ",
    2265            0 :                gimple_bb (SSA_NAME_DEF_STMT (vdef))->index,
    2266              :                get_minimal_bb
    2267            0 :                          (gimple_bb (SSA_NAME_DEF_STMT (vdef)),
    2268            0 :                           gimple_bb (info->stmt))->index);
    2269            0 :       print_gimple_stmt (dump_file, SSA_NAME_DEF_STMT (vdef), 0);
    2270              :     }
    2271              :   return false;
    2272              : }
    2273              : 
    2274              : /* Return probability (based on REG_BR_PROB_BASE) that I-th parameter of STMT
    2275              :    will change since last invocation of STMT.
    2276              : 
    2277              :    Value 0 is reserved for compile time invariants.
    2278              :    For common parameters it is REG_BR_PROB_BASE.  For loop invariants it
    2279              :    ought to be REG_BR_PROB_BASE / estimated_iters.  */
    2280              : 
    2281              : static int
    2282     38138362 : param_change_prob (ipa_func_body_info *fbi, gimple *stmt, int i)
    2283              : {
    2284     38138362 :   tree op = gimple_call_arg (stmt, i);
    2285     38138362 :   basic_block bb = gimple_bb (stmt);
    2286              : 
    2287     38138362 :   if (TREE_CODE (op) == WITH_SIZE_EXPR)
    2288          299 :     op = TREE_OPERAND (op, 0);
    2289              : 
    2290     38138362 :   tree base = get_base_address (op);
    2291              : 
    2292              :   /* Global invariants never change.  */
    2293     38138362 :   if (is_gimple_min_invariant (base))
    2294              :     return 0;
    2295              : 
    2296              :   /* We would have to do non-trivial analysis to really work out what
    2297              :      is the probability of value to change (i.e. when init statement
    2298              :      is in a sibling loop of the call).
    2299              : 
    2300              :      We do an conservative estimate: when call is executed N times more often
    2301              :      than the statement defining value, we take the frequency 1/N.  */
    2302     19129391 :   if (TREE_CODE (base) == SSA_NAME)
    2303              :     {
    2304     16829479 :       profile_count init_count;
    2305              : 
    2306     25608354 :       if (!bb->count.nonzero_p ())
    2307              :         return REG_BR_PROB_BASE;
    2308              : 
    2309      8625193 :       if (SSA_NAME_IS_DEFAULT_DEF (base))
    2310      3000797 :         init_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2311              :       else
    2312      5624396 :         init_count = get_minimal_bb
    2313      5624396 :                       (gimple_bb (SSA_NAME_DEF_STMT (base)),
    2314              :                        gimple_bb (stmt))->count;
    2315              : 
    2316      8625193 :       if (init_count < bb->count)
    2317       450523 :         return MAX ((init_count.to_sreal_scale (bb->count)
    2318              :                      * REG_BR_PROB_BASE).to_int (), 1);
    2319              :       return REG_BR_PROB_BASE;
    2320              :     }
    2321              :   else
    2322              :     {
    2323      2299912 :       ao_ref refd;
    2324      2299912 :       profile_count max = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2325      2299912 :       struct record_modified_bb_info info;
    2326      2299912 :       tree init = ctor_for_folding (base);
    2327              : 
    2328      2299912 :       if (init != error_mark_node)
    2329              :         return 0;
    2330      5101654 :       if (!bb->count.nonzero_p () || fbi->aa_walk_budget == 0)
    2331              :         return REG_BR_PROB_BASE;
    2332      1413627 :       if (dump_file)
    2333              :         {
    2334            0 :           fprintf (dump_file, "     Analyzing param change probability of ");
    2335            0 :           print_generic_expr (dump_file, op, TDF_SLIM);
    2336            0 :           fprintf (dump_file, "\n");
    2337              :         }
    2338      1413627 :       ao_ref_init (&refd, op);
    2339      1413627 :       info.op = op;
    2340      1413627 :       info.stmt = stmt;
    2341      1413627 :       info.bb_set = BITMAP_ALLOC (NULL);
    2342      1413627 :       int walked
    2343      2827254 :         = walk_aliased_vdefs (&refd, gimple_vuse (stmt), record_modified, &info,
    2344              :                               NULL, NULL, fbi->aa_walk_budget);
    2345      1413627 :       if (walked > 0)
    2346      1285478 :         fbi->aa_walk_budget -= walked;
    2347      1413627 :       if (walked < 0 || bitmap_bit_p (info.bb_set, bb->index))
    2348              :         {
    2349       871668 :           if (walked < 0)
    2350          206 :             fbi->aa_walk_budget = 0;
    2351       871668 :           if (dump_file)
    2352              :             {
    2353            0 :               if (walked < 0)
    2354            0 :                 fprintf (dump_file, "     Ran out of AA walking budget.\n");
    2355              :               else
    2356            0 :                 fprintf (dump_file, "     Set in same BB as used.\n");
    2357              :             }
    2358       871668 :           BITMAP_FREE (info.bb_set);
    2359       871668 :           return REG_BR_PROB_BASE;
    2360              :         }
    2361              : 
    2362       541959 :       bitmap_iterator bi;
    2363       541959 :       unsigned index;
    2364              :       /* Lookup the most frequent update of the value and believe that
    2365              :          it dominates all the other; precise analysis here is difficult.  */
    2366      1531766 :       EXECUTE_IF_SET_IN_BITMAP (info.bb_set, 0, index, bi)
    2367       989807 :         max = profile_count::max_prefer_initialized
    2368       989807 :                 (max, BASIC_BLOCK_FOR_FN (cfun, index)->count);
    2369       541959 :       if (dump_file)
    2370              :         {
    2371            0 :           fprintf (dump_file, "     Set with count ");
    2372            0 :           max.dump (dump_file);
    2373            0 :           fprintf (dump_file, " and used with count ");
    2374            0 :           bb->count.dump (dump_file);
    2375            0 :           fprintf (dump_file, " freq %f\n",
    2376            0 :                    max.to_sreal_scale (bb->count).to_double ());
    2377              :         }
    2378              : 
    2379       541959 :       BITMAP_FREE (info.bb_set);
    2380       541959 :       if (max < bb->count)
    2381        91076 :         return MAX ((max.to_sreal_scale (bb->count)
    2382              :                      * REG_BR_PROB_BASE).to_int (), 1);
    2383              :       return REG_BR_PROB_BASE;
    2384              :     }
    2385              : }
    2386              : 
    2387              : /* Find whether a basic block BB is the final block of a (half) diamond CFG
    2388              :    sub-graph and if the predicate the condition depends on is known.  If so,
    2389              :    return true and store the pointer the predicate in *P.  */
    2390              : 
    2391              : static bool
    2392      6342837 : phi_result_unknown_predicate (ipa_func_body_info *fbi,
    2393              :                               ipa_fn_summary *summary,
    2394              :                               class ipa_node_params *params_summary,
    2395              :                               basic_block bb,
    2396              :                               ipa_predicate *p,
    2397              :                               vec<ipa_predicate> nonconstant_names)
    2398              : {
    2399      6342837 :   edge e;
    2400      6342837 :   edge_iterator ei;
    2401      6342837 :   basic_block first_bb = NULL;
    2402              : 
    2403      6342837 :   if (single_pred_p (bb))
    2404              :     {
    2405        20014 :       *p = false;
    2406        20014 :       return true;
    2407              :     }
    2408              : 
    2409     14584796 :   FOR_EACH_EDGE (e, ei, bb->preds)
    2410              :     {
    2411     12448876 :       if (single_succ_p (e->src))
    2412              :         {
    2413     13049676 :           if (!single_pred_p (e->src))
    2414              :             return false;
    2415      7322388 :           if (!first_bb)
    2416      3193553 :             first_bb = single_pred (e->src);
    2417      4128835 :           else if (single_pred (e->src) != first_bb)
    2418              :             return false;
    2419              :         }
    2420              :       else
    2421              :         {
    2422      4132356 :           if (!first_bb)
    2423              :             first_bb = e->src;
    2424      1420271 :           else if (e->src != first_bb)
    2425              :             return false;
    2426              :         }
    2427              :     }
    2428              : 
    2429      2135920 :   if (!first_bb)
    2430              :     return false;
    2431              : 
    2432      4271840 :   gcond *stmt = safe_dyn_cast <gcond *> (*gsi_last_bb (first_bb));
    2433      2089464 :   if (!stmt
    2434      2089464 :       || !is_gimple_ip_invariant (gimple_cond_rhs (stmt)))
    2435       308770 :     return false;
    2436              : 
    2437      1827150 :   *p = will_be_nonconstant_expr_predicate (fbi, summary, params_summary,
    2438              :                                            gimple_cond_lhs (stmt),
    2439              :                                            nonconstant_names);
    2440      1827150 :   if (*p == true)
    2441              :     return false;
    2442              :   else
    2443              :     return true;
    2444              : }
    2445              : 
    2446              : /* Given a PHI statement in a function described by inline properties SUMMARY
    2447              :    and *P being the predicate describing whether the selected PHI argument is
    2448              :    known, store a predicate for the result of the PHI statement into
    2449              :    NONCONSTANT_NAMES, if possible.  */
    2450              : 
    2451              : static void
    2452       698287 : predicate_for_phi_result (class ipa_fn_summary *summary, gphi *phi,
    2453              :                           ipa_predicate *p,
    2454              :                           vec<ipa_predicate> nonconstant_names)
    2455              : {
    2456       698287 :   unsigned i;
    2457              : 
    2458       996381 :   for (i = 0; i < gimple_phi_num_args (phi); i++)
    2459              :     {
    2460       873850 :       tree arg = gimple_phi_arg (phi, i)->def;
    2461       873850 :       if (!is_gimple_min_invariant (arg))
    2462              :         {
    2463       749226 :           gcc_assert (TREE_CODE (arg) == SSA_NAME);
    2464      1498452 :           *p = p->or_with (summary->conds,
    2465       749226 :                            nonconstant_names[SSA_NAME_VERSION (arg)]);
    2466       749226 :           if (*p == true)
    2467              :             return;
    2468              :         }
    2469              :     }
    2470              : 
    2471       122531 :   if (dump_file && (dump_flags & TDF_DETAILS))
    2472              :     {
    2473            3 :       fprintf (dump_file, "\t\tphi predicate: ");
    2474            3 :       p->dump (dump_file, summary->conds);
    2475              :     }
    2476       122531 :   nonconstant_names[SSA_NAME_VERSION (gimple_phi_result (phi))] = *p;
    2477              : }
    2478              : 
    2479              : /* For a typical usage of __builtin_expect (a<b, 1), we
    2480              :    may introduce an extra relation stmt:
    2481              :    With the builtin, we have
    2482              :      t1 = a <= b;
    2483              :      t2 = (long int) t1;
    2484              :      t3 = __builtin_expect (t2, 1);
    2485              :      if (t3 != 0)
    2486              :        goto ...
    2487              :    Without the builtin, we have
    2488              :      if (a<=b)
    2489              :        goto...
    2490              :    This affects the size/time estimation and may have
    2491              :    an impact on the earlier inlining.
    2492              :    Here find this pattern and fix it up later.  */
    2493              : 
    2494              : static gimple *
    2495     40873100 : find_foldable_builtin_expect (basic_block bb)
    2496              : {
    2497     40873100 :   gimple_stmt_iterator bsi;
    2498              : 
    2499    281612647 :   for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
    2500              :     {
    2501    200028695 :       gimple *stmt = gsi_stmt (bsi);
    2502    200028695 :       if (gimple_call_builtin_p (stmt, BUILT_IN_EXPECT)
    2503    199817096 :           || gimple_call_builtin_p (stmt, BUILT_IN_EXPECT_WITH_PROBABILITY)
    2504    399845726 :           || gimple_call_internal_p (stmt, IFN_BUILTIN_EXPECT))
    2505              :         {
    2506       342897 :           tree var = gimple_call_lhs (stmt);
    2507       342897 :           tree arg = gimple_call_arg (stmt, 0);
    2508       342897 :           use_operand_p use_p;
    2509       342897 :           gimple *use_stmt;
    2510       342897 :           bool match = false;
    2511       342897 :           bool done = false;
    2512              : 
    2513       342897 :           if (!var || !arg)
    2514            3 :             continue;
    2515       342894 :           gcc_assert (TREE_CODE (var) == SSA_NAME);
    2516              : 
    2517       684482 :           while (TREE_CODE (arg) == SSA_NAME)
    2518              :             {
    2519       684482 :               gimple *stmt_tmp = SSA_NAME_DEF_STMT (arg);
    2520       684482 :               if (!is_gimple_assign (stmt_tmp))
    2521              :                 break;
    2522       677178 :               switch (gimple_assign_rhs_code (stmt_tmp))
    2523              :                 {
    2524              :                   case LT_EXPR:
    2525              :                   case LE_EXPR:
    2526              :                   case GT_EXPR:
    2527              :                   case GE_EXPR:
    2528              :                   case EQ_EXPR:
    2529              :                   case NE_EXPR:
    2530              :                     match = true;
    2531              :                     done = true;
    2532              :                     break;
    2533              :                   CASE_CONVERT:
    2534              :                     break;
    2535              :                   default:
    2536              :                     done = true;
    2537              :                     break;
    2538              :                 }
    2539       341588 :               if (done)
    2540              :                 break;
    2541       341588 :               arg = gimple_assign_rhs1 (stmt_tmp);
    2542              :             }
    2543              : 
    2544       307928 :           if (match && single_imm_use (var, &use_p, &use_stmt)
    2545       650402 :               && gimple_code (use_stmt) == GIMPLE_COND)
    2546       162248 :             return use_stmt;
    2547              :         }
    2548              :     }
    2549              :   return NULL;
    2550              : }
    2551              : 
    2552              : /* Return true when the basic blocks contains only clobbers followed by RESX.
    2553              :    Such BBs are kept around to make removal of dead stores possible with
    2554              :    presence of EH and will be optimized out by optimize_clobbers later in the
    2555              :    game.
    2556              : 
    2557              :    NEED_EH is used to recurse in case the clobber has non-EH predecessors
    2558              :    that can be clobber only, too.. When it is false, the RESX is not necessary
    2559              :    on the end of basic block.  */
    2560              : 
    2561              : static bool
    2562     41466436 : clobber_only_eh_bb_p (basic_block bb, bool need_eh = true)
    2563              : {
    2564     41466436 :   gimple_stmt_iterator gsi = gsi_last_bb (bb);
    2565     41466436 :   edge_iterator ei;
    2566     41466436 :   edge e;
    2567              : 
    2568     41466436 :   if (need_eh)
    2569              :     {
    2570     41398844 :       if (gsi_end_p (gsi))
    2571              :         return false;
    2572     40273073 :       if (gimple_code (gsi_stmt (gsi)) != GIMPLE_RESX)
    2573              :         return false;
    2574      1006118 :       gsi_prev (&gsi);
    2575              :     }
    2576     40941162 :   else if (!single_succ_p (bb))
    2577              :     return false;
    2578              : 
    2579      4478630 :   for (; !gsi_end_p (gsi); gsi_prev (&gsi))
    2580              :     {
    2581      2682378 :       gimple *stmt = gsi_stmt (gsi);
    2582      2682378 :       if (is_gimple_debug (stmt))
    2583       867606 :         continue;
    2584      1814772 :       if (gimple_clobber_p (stmt))
    2585       867685 :         continue;
    2586       947087 :       if (gimple_code (stmt) == GIMPLE_LABEL)
    2587              :         break;
    2588              :       return false;
    2589              :     }
    2590              : 
    2591              :   /* See if all predecessors are either throws or clobber only BBs.  */
    2592      3001370 :   FOR_EACH_EDGE (e, ei, bb->preds)
    2593      2474166 :     if (!(e->flags & EDGE_EH)
    2594      2474166 :         && !clobber_only_eh_bb_p (e->src, false))
    2595              :       return false;
    2596              : 
    2597              :   return true;
    2598              : }
    2599              : 
    2600              : /* Return true if STMT compute a floating point expression that may be affected
    2601              :    by -ffast-math and similar flags.  */
    2602              : 
    2603              : static bool
    2604     93718446 : fp_expression_p (gimple *stmt)
    2605              : {
    2606     93718446 :   ssa_op_iter i;
    2607     93718446 :   tree op;
    2608              : 
    2609    210452380 :   FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_DEF|SSA_OP_USE)
    2610    117331192 :     if (FLOAT_TYPE_P (TREE_TYPE (op)))
    2611              :       return true;
    2612              :   return false;
    2613              : }
    2614              : 
    2615              : /* Return true if T references memory location that is local
    2616              :    for the function (that means, dead after return) or read-only.  */
    2617              : 
    2618              : bool
    2619     58473304 : refs_local_or_readonly_memory_p (tree t)
    2620              : {
    2621              :   /* Non-escaping memory is fine.  */
    2622     58473304 :   t = get_base_address (t);
    2623     58473304 :   if ((TREE_CODE (t) == MEM_REF
    2624     58473304 :       || TREE_CODE (t) == TARGET_MEM_REF))
    2625     24719035 :     return points_to_local_or_readonly_memory_p (TREE_OPERAND (t, 0));
    2626              : 
    2627              :   /* Automatic variables are fine.  */
    2628     33754269 :   if (DECL_P (t)
    2629     33754269 :       && auto_var_in_fn_p (t, current_function_decl))
    2630              :     return true;
    2631              : 
    2632              :   /* Read-only variables are fine.  */
    2633     10972387 :   if (DECL_P (t) && TREE_READONLY (t))
    2634              :     return true;
    2635              : 
    2636              :   return false;
    2637              : }
    2638              : 
    2639              : /* Return true if T is a pointer pointing to memory location that is local
    2640              :    for the function (that means, dead after return) or read-only.  */
    2641              : 
    2642              : bool
    2643     71417270 : points_to_local_or_readonly_memory_p (tree t)
    2644              : {
    2645              :   /* See if memory location is clearly invalid.  */
    2646     71417270 :   if (integer_zerop (t))
    2647      2425700 :     return flag_delete_null_pointer_checks;
    2648     68991570 :   if (TREE_CODE (t) == SSA_NAME)
    2649              :     {
    2650              :       /* For IPA passes we can consinder accesses to return slot local
    2651              :          even if it is not local in the sense that memory is dead by
    2652              :          the end of founction.
    2653              :          The outer function will see a store in the call assignment
    2654              :          and thus this will do right thing for all uses of this
    2655              :          function in the current IPA passes (modref, pure/const discovery
    2656              :          and inlining heuristics).  */
    2657     43676405 :       if (DECL_RESULT (current_function_decl)
    2658     43676405 :           && DECL_BY_REFERENCE (DECL_RESULT (current_function_decl))
    2659     44695252 :           && t == ssa_default_def (cfun, DECL_RESULT (current_function_decl)))
    2660              :         return true;
    2661     43373754 :       return !ptr_deref_may_alias_global_p (t, false);
    2662              :     }
    2663     25315165 :   if (TREE_CODE (t) == ADDR_EXPR
    2664     25315165 :       && (TREE_CODE (TREE_OPERAND (t, 0)) != TARGET_MEM_REF
    2665         4527 :           || TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)) != INTEGER_CST))
    2666     13000906 :     return refs_local_or_readonly_memory_p (TREE_OPERAND (t, 0));
    2667              :   return false;
    2668              : }
    2669              : 
    2670              : /* Return true if T is a pointer pointing to memory location that is possible
    2671              :    sra candidate if all functions it is passed to are inlined.  */
    2672              : 
    2673              : static bool
    2674     38138362 : points_to_possible_sra_candidate_p (tree t)
    2675              : {
    2676     38138362 :   if (TREE_CODE (t) != ADDR_EXPR)
    2677              :     return false;
    2678              : 
    2679     11312164 :   t = get_base_address (TREE_OPERAND (t, 0));
    2680              : 
    2681              :   /* Automatic variables are fine.  */
    2682     11312164 :   if (DECL_P (t)
    2683     11312164 :       && auto_var_in_fn_p (t, current_function_decl))
    2684              :     return true;
    2685              :   return false;
    2686              : }
    2687              : 
    2688              : /* Return true if BB only calls builtin_unreachable.
    2689              :    We skip empty basic blocks, debug statements, clobbers and predicts.
    2690              :    CACHE is used to memoize already analyzed blocks.  */
    2691              : 
    2692              : static bool
    2693     27242131 : builtin_unreachable_bb_p (basic_block bb, vec<unsigned char> &cache)
    2694              : {
    2695     27242131 :   if (cache[bb->index])
    2696      2577309 :     return cache[bb->index] - 1;
    2697     24664822 :   gimple_stmt_iterator si;
    2698     24664822 :   auto_vec <basic_block, 4> visited_bbs;
    2699     24664822 :   bool ret = false;
    2700     25467118 :   while (true)
    2701              :     {
    2702     25467118 :       bool empty_bb = true;
    2703     25467118 :       visited_bbs.safe_push (bb);
    2704     25467118 :       cache[bb->index] = 3;
    2705     25467118 :       for (si = gsi_start_nondebug_bb (bb);
    2706     26939655 :            !gsi_end_p (si) && empty_bb;
    2707      1472537 :            gsi_next_nondebug (&si))
    2708              :         {
    2709     25574907 :           if (gimple_code (gsi_stmt (si)) != GIMPLE_PREDICT
    2710     25206735 :               && !gimple_clobber_p (gsi_stmt (si))
    2711     49710535 :               && !gimple_nop_p (gsi_stmt (si)))
    2712              :             {
    2713              :               empty_bb = false;
    2714              :               break;
    2715              :             }
    2716              :         }
    2717     25467118 :       if (!empty_bb)
    2718              :         break;
    2719              :       else
    2720      1364748 :         bb = single_succ_edge (bb)->dest;
    2721      1364748 :       if (cache[bb->index])
    2722              :         {
    2723       562452 :           ret = cache[bb->index] == 3 ? false : cache[bb->index] - 1;
    2724       562452 :           goto done;
    2725              :         }
    2726              :     }
    2727     24102370 :   if (gimple_call_builtin_p (gsi_stmt (si), BUILT_IN_UNREACHABLE)
    2728     24102370 :       || gimple_call_builtin_p (gsi_stmt (si), BUILT_IN_UNREACHABLE_TRAP))
    2729              :     ret = true;
    2730     24664822 : done:
    2731     99461584 :   for (basic_block vbb:visited_bbs)
    2732     25467118 :     cache[vbb->index] = (unsigned char)ret + 1;
    2733     24664822 :   return ret;
    2734     24664822 : }
    2735              : 
    2736              : static bool
    2737     13738937 : guards_builtin_unreachable (basic_block bb, vec<unsigned char> &cache)
    2738              : {
    2739     13738937 :   edge_iterator ei;
    2740     13738937 :   edge e;
    2741     40728361 :   FOR_EACH_EDGE (e, ei, bb->succs)
    2742     27242131 :     if (builtin_unreachable_bb_p (e->dest, cache))
    2743              :       {
    2744       252707 :         if (dump_file && (dump_flags & TDF_DETAILS))
    2745            1 :           fprintf (dump_file,
    2746              :                    "BB %i ends with conditional guarding __builtin_unreachable;"
    2747              :                    " conditinal is unnecesary\n", bb->index);
    2748       252707 :         return true;
    2749              :       }
    2750              :   return false;
    2751              : }
    2752              : 
    2753              : #define STMT_NECESSARY GF_PLF_1
    2754              : 
    2755              : /* If STMT is not already marked necessary, mark it, and add it to the
    2756              :    worklist if ADD_TO_WORKLIST is true.  */
    2757              : 
    2758              : static inline void
    2759    171098802 : mark_stmt_necessary (gimple *stmt, auto_vec<gimple *> &worklist)
    2760              : {
    2761    171098802 :   gcc_assert (stmt);
    2762              : 
    2763    171098802 :   if (gimple_plf (stmt, STMT_NECESSARY))
    2764              :     return;
    2765              : 
    2766    141841082 :   if (dump_file && (dump_flags & TDF_DETAILS))
    2767              :     {
    2768          207 :       fprintf (dump_file, "Marking useful stmt: ");
    2769          207 :       print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
    2770          207 :       fprintf (dump_file, "\n");
    2771              :     }
    2772              : 
    2773    141841082 :   gimple_set_plf (stmt, STMT_NECESSARY, true);
    2774    141841082 :   worklist.safe_push (stmt);
    2775              : }
    2776              : 
    2777              : /* Mark the statement defining operand OP as necessary.  */
    2778              : 
    2779              : static inline void
    2780    120546657 : mark_operand_necessary (tree op, auto_vec<gimple *> &worklist)
    2781              : {
    2782    120546657 :   gimple *stmt = SSA_NAME_DEF_STMT (op);
    2783    120546657 :   if (gimple_nop_p (stmt))
    2784              :     return;
    2785     97961313 :   mark_stmt_necessary (stmt, worklist);
    2786              : }
    2787              : 
    2788              : /* Mark all statements that will remain in the body after optimizing out
    2789              :    conditionals guarding __builtin_unreachable which we keep to preserve
    2790              :    value ranges.  */
    2791              : 
    2792              : static void
    2793      7128796 : find_necessary_statements (struct cgraph_node *node)
    2794              : {
    2795      7128796 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    2796      7128796 :   auto_vec<unsigned char, 10> cache;
    2797      7128796 :   basic_block bb;
    2798      7128796 :   auto_vec<gimple *> worklist;
    2799              : 
    2800      7128796 :   cache.safe_grow_cleared (last_basic_block_for_fn (cfun));
    2801              :   /* Mark all obviously necessary statements.  */
    2802     48527640 :   FOR_EACH_BB_FN (bb, my_function)
    2803              :     {
    2804     41398844 :       for (gimple_stmt_iterator gsi = gsi_start_phis (bb);
    2805     52986805 :            !gsi_end_p (gsi); gsi_next (&gsi))
    2806     11587961 :         gimple_set_plf (gsi_stmt (gsi), STMT_NECESSARY, false);
    2807              : 
    2808    231481565 :       for (gimple_stmt_iterator bsi = gsi_start_bb (bb); !gsi_end_p (bsi);
    2809    148683877 :            gsi_next_nondebug (&bsi))
    2810              :         {
    2811    148683877 :           gimple *stmt = gsi_stmt (bsi);
    2812              : 
    2813    148683877 :           gimple_set_plf (stmt, STMT_NECESSARY, false);
    2814    148683877 :           if (gimple_has_side_effects (stmt)
    2815    121904224 :               || (is_ctrl_stmt (stmt)
    2816     21869323 :                   && (gimple_code (stmt) != GIMPLE_COND
    2817     13738937 :                       || !guards_builtin_unreachable (bb, cache)))
    2818    100287608 :               || gimple_store_p (stmt)
    2819    224251923 :               || gimple_code (stmt) == GIMPLE_ASM)
    2820     73137489 :             mark_stmt_necessary (stmt, worklist);
    2821              :         }
    2822              :     }
    2823    148969878 :   while (worklist.length () > 0)
    2824              :     {
    2825    141841082 :       gimple *stmt = worklist.pop ();
    2826              : 
    2827    141841082 :       if (dump_file && (dump_flags & TDF_DETAILS))
    2828              :         {
    2829          207 :           fprintf (dump_file, "processing: ");
    2830          207 :           print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
    2831          207 :           fprintf (dump_file, "\n");
    2832              :         }
    2833    141841082 :       if (gimple_code (stmt) == GIMPLE_PHI)
    2834     18367061 :         for (unsigned int k = 0; k < gimple_phi_num_args (stmt); k++)
    2835              :           {
    2836     13005568 :             tree arg = PHI_ARG_DEF (stmt, k);
    2837              : 
    2838     13005568 :             if (TREE_CODE (arg) == SSA_NAME)
    2839      9981836 :               mark_operand_necessary (arg, worklist);
    2840              :           }
    2841              :       else
    2842              :         {
    2843    136479589 :           ssa_op_iter iter;
    2844    136479589 :           tree use;
    2845              : 
    2846    247044410 :           FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2847    110564821 :             mark_operand_necessary (use, worklist);
    2848              :         }
    2849              :     }
    2850      7128796 : }
    2851              : 
    2852              : /* Analyze function body for NODE.
    2853              :    EARLY indicates run from early optimization pipeline.  */
    2854              : 
    2855              : static void
    2856      7128796 : analyze_function_body (struct cgraph_node *node, bool early)
    2857              : {
    2858      7128796 :   sreal time = opt_for_fn (node->decl, param_uninlined_function_time);
    2859              :   /* Estimate static overhead for function prologue/epilogue and alignment. */
    2860      7128796 :   int size = opt_for_fn (node->decl, param_uninlined_function_insns);
    2861              :   /* Benefits are scaled by probability of elimination that is in range
    2862              :      <0,2>.  */
    2863      7128796 :   basic_block bb;
    2864      7128796 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    2865      7128796 :   sreal freq;
    2866      7128796 :   class ipa_fn_summary *info = ipa_fn_summaries->get_create (node);
    2867      7128796 :   ipa_node_params *params_summary
    2868      7128796 :     = early ? NULL : ipa_node_params_sum->get (node);
    2869      7128796 :   ipa_predicate bb_predicate;
    2870      7128796 :   struct ipa_func_body_info fbi;
    2871      7128796 :   vec<ipa_predicate> nonconstant_names = vNULL;
    2872      7128796 :   int nblocks, n;
    2873      7128796 :   int *order;
    2874      7128796 :   gimple *fix_builtin_expect_stmt;
    2875              : 
    2876      7128796 :   gcc_assert (my_function && my_function->cfg);
    2877      7128796 :   gcc_assert (cfun == my_function);
    2878              : 
    2879      7128796 :   memset(&fbi, 0, sizeof(fbi));
    2880      7128796 :   vec_free (info->conds);
    2881      7128796 :   info->conds = NULL;
    2882      7128796 :   info->size_time_table.release ();
    2883      7128796 :   info->call_size_time_table.release ();
    2884              : 
    2885              :   /* When optimizing and analyzing for IPA inliner, initialize loop optimizer
    2886              :      so we can produce proper inline hints.
    2887              : 
    2888              :      When optimizing and analyzing for early inliner, initialize node params
    2889              :      so we can produce correct BB predicates.  */
    2890              : 
    2891      7128796 :   if (opt_for_fn (node->decl, optimize))
    2892              :     {
    2893      6221162 :       calculate_dominance_info (CDI_DOMINATORS);
    2894      6221162 :       calculate_dominance_info (CDI_POST_DOMINATORS);
    2895      6221162 :       if (!early)
    2896      1366448 :         loop_optimizer_init (LOOPS_NORMAL | LOOPS_HAVE_RECORDED_EXITS);
    2897              :       else
    2898              :         {
    2899      4854714 :           ipa_check_create_node_params ();
    2900      4854714 :           ipa_initialize_node_params (node);
    2901              :         }
    2902              : 
    2903      6221162 :       if (ipa_node_params_sum)
    2904              :         {
    2905      6221162 :           fbi.node = node;
    2906      6221162 :           fbi.info = ipa_node_params_sum->get (node);
    2907      6221162 :           fbi.bb_infos = vNULL;
    2908      6221162 :           fbi.bb_infos.safe_grow_cleared (last_basic_block_for_fn (cfun), true);
    2909      6221162 :           fbi.param_count = count_formal_params (node->decl);
    2910      6221162 :           fbi.aa_walk_budget = opt_for_fn (node->decl, param_ipa_max_aa_steps);
    2911              : 
    2912      6221162 :           nonconstant_names.safe_grow_cleared
    2913      6221162 :             (SSANAMES (my_function)->length (), true);
    2914              :         }
    2915              :     }
    2916              : 
    2917      7128796 :   if (dump_file)
    2918          247 :     fprintf (dump_file, "\nAnalyzing function body size: %s\n",
    2919              :              node->dump_name ());
    2920              : 
    2921              :   /* When we run into maximal number of entries, we assign everything to the
    2922              :      constant truth case.  Be sure to have it in list. */
    2923      7128796 :   bb_predicate = true;
    2924      7128796 :   info->account_size_time (0, 0, bb_predicate, bb_predicate);
    2925              : 
    2926      7128796 :   bb_predicate = ipa_predicate::not_inlined ();
    2927      7128796 :   info->account_size_time (opt_for_fn (node->decl,
    2928              :                                 param_uninlined_function_insns)
    2929              :                            * ipa_fn_summary::size_scale,
    2930      7128796 :                            opt_for_fn (node->decl,
    2931              :                                 param_uninlined_function_time),
    2932              :                            bb_predicate,
    2933              :                            bb_predicate);
    2934              : 
    2935              :   /* Only look for target information for inlinable functions.  */
    2936      7128796 :   bool scan_for_target_info =
    2937      7128796 :     info->inlinable
    2938     12788856 :     && targetm.target_option.need_ipa_fn_target_info (node->decl,
    2939      5660060 :                                                       info->target_info);
    2940              : 
    2941      7128796 :   if (fbi.info)
    2942      6221162 :     compute_bb_predicates (&fbi, node, info, params_summary);
    2943      7128796 :   find_necessary_statements (node);
    2944      7128796 :   const profile_count entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2945      7128796 :   order = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
    2946      7128796 :   nblocks = pre_and_rev_post_order_compute (NULL, order, false);
    2947     48527640 :   for (n = 0; n < nblocks; n++)
    2948              :     {
    2949     41398844 :       bb = BASIC_BLOCK_FOR_FN (cfun, order[n]);
    2950     41398844 :       freq = bb->count.to_sreal_scale (entry_count);
    2951     41398844 :       if (clobber_only_eh_bb_p (bb))
    2952              :         {
    2953       525744 :           if (dump_file && (dump_flags & TDF_DETAILS))
    2954            0 :             fprintf (dump_file, "\n Ignoring BB %i;"
    2955              :                      " it will be optimized away by cleanup_clobbers\n",
    2956              :                      bb->index);
    2957       525744 :           continue;
    2958              :         }
    2959              : 
    2960              :       /* TODO: Obviously predicates can be propagated down across CFG.  */
    2961     40873100 :       if (fbi.info)
    2962              :         {
    2963     34446572 :           if (bb->aux)
    2964     34446558 :             bb_predicate = *(ipa_predicate *)bb->aux;
    2965              :           else
    2966           14 :             bb_predicate = false;
    2967              :         }
    2968              :       else
    2969      6426528 :         bb_predicate = true;
    2970              : 
    2971     40873100 :       if (dump_file && (dump_flags & TDF_DETAILS))
    2972              :         {
    2973           67 :           fprintf (dump_file, "\n BB %i predicate:", bb->index);
    2974           67 :           bb_predicate.dump (dump_file, info->conds);
    2975              :         }
    2976              : 
    2977     40873100 :       if (fbi.info && nonconstant_names.exists ())
    2978              :         {
    2979     34446572 :           ipa_predicate phi_predicate;
    2980     34446572 :           bool first_phi = true;
    2981              : 
    2982     35144859 :           for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi);
    2983       698287 :                gsi_next (&bsi))
    2984              :             {
    2985      6425575 :               if (first_phi
    2986      6425575 :                   && !phi_result_unknown_predicate (&fbi, info,
    2987              :                                                     params_summary,
    2988              :                                                     bb,
    2989              :                                                     &phi_predicate,
    2990              :                                                     nonconstant_names))
    2991              :                 break;
    2992       698287 :               first_phi = false;
    2993       698287 :               if (dump_file && (dump_flags & TDF_DETAILS))
    2994              :                 {
    2995            3 :                   fprintf (dump_file, "  ");
    2996            3 :                   print_gimple_stmt (dump_file, gsi_stmt (bsi), 0);
    2997              :                 }
    2998       698287 :               predicate_for_phi_result (info, bsi.phi (), &phi_predicate,
    2999              :                                         nonconstant_names);
    3000              :             }
    3001              :         }
    3002              : 
    3003     40873100 :       fix_builtin_expect_stmt = find_foldable_builtin_expect (bb);
    3004              : 
    3005     40873100 :       for (gimple_stmt_iterator bsi = gsi_start_nondebug_bb (bb);
    3006    181621968 :            !gsi_end_p (bsi); gsi_next_nondebug (&bsi))
    3007              :         {
    3008    140748868 :           gimple *stmt = gsi_stmt (bsi);
    3009    140748868 :           if (!gimple_plf (stmt, STMT_NECESSARY))
    3010              :             {
    3011      5529321 :               if (dump_file && (dump_flags & TDF_DETAILS))
    3012              :                 {
    3013           19 :                   fprintf (dump_file, "  skipping unnecesary stmt ");
    3014           19 :                   print_gimple_stmt (dump_file, stmt, 0);
    3015              :                 }
    3016              :               /* TODO: const calls used only to produce values for
    3017              :                  builtion_unreachable guards should not be accounted.  However
    3018              :                  we still want to inline them and this does does not work well
    3019              :                  with the cost model.  For now account them as usual.  */
    3020      5529321 :               if (!is_gimple_call (stmt)
    3021      5529321 :                   || gimple_call_internal_p (stmt))
    3022      5261713 :                 continue;
    3023              :             }
    3024    135487155 :           int this_size = estimate_num_insns (stmt, &eni_size_weights);
    3025    135487155 :           int this_time = estimate_num_insns (stmt, &eni_time_weights);
    3026    135487155 :           int prob;
    3027    135487155 :           ipa_predicate will_be_nonconstant;
    3028              : 
    3029              :           /* This relation stmt should be folded after we remove
    3030              :              __builtin_expect call. Adjust the cost here.  */
    3031    135487155 :           if (stmt == fix_builtin_expect_stmt)
    3032              :             {
    3033       161810 :               this_size--;
    3034       161810 :               this_time--;
    3035              :             }
    3036              : 
    3037    135487155 :           if (dump_file && (dump_flags & TDF_DETAILS))
    3038              :             {
    3039          201 :               fprintf (dump_file, "  ");
    3040          201 :               print_gimple_stmt (dump_file, stmt, 0);
    3041          201 :               fprintf (dump_file, "\t\tfreq:%3.2f size:%3i time:%3i\n",
    3042              :                        freq.to_double (), this_size,
    3043              :                        this_time);
    3044              :             }
    3045              : 
    3046    135487155 :           if (is_gimple_call (stmt)
    3047    135487155 :               && !gimple_call_internal_p (stmt))
    3048              :             {
    3049     22707243 :               struct cgraph_edge *edge = node->get_edge (stmt);
    3050     22707243 :               ipa_call_summary *es = ipa_call_summaries->get_create (edge);
    3051              : 
    3052              :               /* Special case: results of BUILT_IN_CONSTANT_P will be always
    3053              :                  resolved as constant.  We however don't want to optimize
    3054              :                  out the cgraph edges.  */
    3055     22707243 :               if (nonconstant_names.exists ()
    3056     19812382 :                   && gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P)
    3057        28386 :                   && gimple_call_lhs (stmt)
    3058     22735629 :                   && TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME)
    3059              :                 {
    3060        28386 :                   ipa_predicate false_p = false;
    3061        28386 :                   nonconstant_names[SSA_NAME_VERSION (gimple_call_lhs (stmt))]
    3062        28386 :                     = false_p;
    3063              :                 }
    3064     22707243 :               if (ipa_node_params_sum)
    3065              :                 {
    3066     19825162 :                   int count = gimple_call_num_args (stmt);
    3067     19825162 :                   int i;
    3068              : 
    3069     19825162 :                   if (count)
    3070     16933828 :                     es->param.safe_grow_cleared (count, true);
    3071     57963524 :                   for (i = 0; i < count; i++)
    3072              :                     {
    3073     38138362 :                       int prob = param_change_prob (&fbi, stmt, i);
    3074     38138362 :                       gcc_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
    3075     38138362 :                       es->param[i].change_prob = prob;
    3076     38138362 :                       es->param[i].points_to_local_or_readonly_memory
    3077     38138362 :                          = points_to_local_or_readonly_memory_p
    3078     38138362 :                              (gimple_call_arg (stmt, i));
    3079     38138362 :                       es->param[i].points_to_possible_sra_candidate
    3080     38138362 :                          = points_to_possible_sra_candidate_p
    3081     38138362 :                              (gimple_call_arg (stmt, i));
    3082              :                     }
    3083              :                 }
    3084              :               /* We cannot setup VLA parameters during inlining.  */
    3085     66722113 :               for (unsigned int i = 0; i < gimple_call_num_args (stmt); ++i)
    3086     44015266 :                 if (TREE_CODE (gimple_call_arg (stmt, i)) == WITH_SIZE_EXPR)
    3087              :                   {
    3088          396 :                     edge->inline_failed = CIF_FUNCTION_NOT_INLINABLE;
    3089          396 :                     break;
    3090              :                   }
    3091     22707243 :               es->call_stmt_size = this_size;
    3092     22707243 :               es->call_stmt_time = this_time;
    3093     22707243 :               es->loop_depth = bb_loop_depth (bb);
    3094     22707243 :               edge_set_predicate (edge, &bb_predicate);
    3095     22707243 :               if (edge->speculative)
    3096              :                 {
    3097            0 :                   cgraph_edge *indirect
    3098            0 :                         = edge->speculative_call_indirect_edge ();
    3099            0 :                   ipa_call_summary *es2
    3100            0 :                          = ipa_call_summaries->get_create (indirect);
    3101            0 :                   ipa_call_summaries->duplicate (edge, indirect,
    3102              :                                                  es, es2);
    3103              : 
    3104              :                   /* Edge is the first direct call.
    3105              :                      create and duplicate call summaries for multiple
    3106              :                      speculative call targets.  */
    3107            0 :                   for (cgraph_edge *direct
    3108            0 :                          = edge->next_speculative_call_target ();
    3109            0 :                        direct;
    3110            0 :                        direct = direct->next_speculative_call_target ())
    3111              :                     {
    3112            0 :                       ipa_call_summary *es3
    3113            0 :                         = ipa_call_summaries->get_create (direct);
    3114            0 :                       ipa_call_summaries->duplicate (edge, direct,
    3115              :                                                      es, es3);
    3116              :                     }
    3117              :                 }
    3118              : 
    3119              :               /* If dealing with a carrying edge, copy its summary over to its
    3120              :                  attached edges as well.  */
    3121     22707243 :               if (edge->has_callback)
    3122              :                 {
    3123        15080 :                   cgraph_edge *cbe;
    3124        30160 :                   for (cbe = edge->first_callback_edge (); cbe;
    3125        15080 :                        cbe = cbe->next_callback_edge ())
    3126              :                     {
    3127        15080 :                       ipa_call_summary *es2 = ipa_call_summaries->get_create (cbe);
    3128        15080 :                       ipa_call_summaries->duplicate (edge, cbe, es, es2);
    3129              :                       /* Unlike speculative edges, callback edges have no real
    3130              :                          size or time; the call doesn't exist.  Reflect that in
    3131              :                          their summaries.  */
    3132        15080 :                       es2->call_stmt_size = 0;
    3133        15080 :                       es2->call_stmt_time = 0;
    3134              :                     }
    3135              :                 }
    3136              :             }
    3137              : 
    3138              :           /* TODO: When conditional jump or switch is known to be constant, but
    3139              :              we did not translate it into the predicates, we really can account
    3140              :              just maximum of the possible paths.  */
    3141    135487155 :           if (fbi.info)
    3142    113260921 :             will_be_nonconstant
    3143    113260921 :               = will_be_nonconstant_predicate (&fbi, info, params_summary,
    3144              :                                                stmt, nonconstant_names);
    3145              :           else
    3146     22226234 :             will_be_nonconstant = true;
    3147    135487155 :           if (this_time || this_size)
    3148              :             {
    3149    111023735 :               sreal final_time = (sreal)this_time * freq;
    3150    111023735 :               prob = eliminated_by_inlining_prob (&fbi, stmt);
    3151    111023735 :               if (prob == 1 && dump_file && (dump_flags & TDF_DETAILS))
    3152           11 :                 fprintf (dump_file,
    3153              :                          "\t\t50%% will be eliminated by inlining\n");
    3154    111023735 :               if (prob == 2 && dump_file && (dump_flags & TDF_DETAILS))
    3155           18 :                 fprintf (dump_file, "\t\tWill be eliminated by inlining\n");
    3156              : 
    3157    111023735 :               ipa_predicate p = bb_predicate & will_be_nonconstant;
    3158    111023735 :               int parm = load_or_store_of_ptr_parameter (&fbi, stmt);
    3159    111023735 :               ipa_predicate sra_predicate = true;
    3160    111023735 :               if (parm != -1)
    3161     14021424 :                 sra_predicate &= add_condition (info, params_summary, parm,
    3162              :                                                 ptr_type_node, NULL,
    3163      7010712 :                                                 ipa_predicate::not_sra_candidate, NULL, 0);
    3164              : 
    3165              :               /* We can ignore statement when we proved it is never going
    3166              :                  to happen, but we cannot do that for call statements
    3167              :                  because edges are accounted specially.  */
    3168              : 
    3169    222047470 :               if (*(is_gimple_call (stmt) ? &bb_predicate : &p) != false)
    3170              :                 {
    3171    110310585 :                   time += final_time;
    3172    110310585 :                   size += this_size;
    3173              :                 }
    3174              : 
    3175              :               /* We account everything but the calls.  Calls have their own
    3176              :                  size/time info attached to cgraph edges.  This is necessary
    3177              :                  in order to make the cost disappear after inlining.  */
    3178    111023735 :               if (!is_gimple_call (stmt))
    3179              :                 {
    3180     88979812 :                   if (prob)
    3181              :                     {
    3182     14735298 :                       ipa_predicate ip
    3183     14735298 :                         = bb_predicate & ipa_predicate::not_inlined () & sra_predicate;
    3184     29470596 :                       info->account_size_time (this_size * prob,
    3185     14735298 :                                                (final_time * prob) / 2, ip,
    3186              :                                                p);
    3187              :                     }
    3188     14735298 :                   if (prob != 2)
    3189    164372278 :                     info->account_size_time (this_size * (2 - prob),
    3190     82186139 :                                              (final_time * (2 - prob) / 2),
    3191    164372278 :                                              bb_predicate & sra_predicate,
    3192              :                                              p);
    3193              :                 }
    3194              : 
    3195    111023735 :               if (!info->fp_expressions && fp_expression_p (stmt))
    3196              :                 {
    3197       597258 :                   info->fp_expressions = true;
    3198       597258 :                   if (dump_file)
    3199            9 :                     fprintf (dump_file, "   fp_expression set\n");
    3200              :                 }
    3201              :             }
    3202              : 
    3203              :           /* For target specific information, we want to scan all statements
    3204              :              rather than those statements with non-zero weights, to avoid
    3205              :              missing to scan something interesting for target information,
    3206              :              such as: internal function calls.  */
    3207    135487155 :           if (scan_for_target_info)
    3208            0 :             scan_for_target_info =
    3209            0 :               targetm.target_option.update_ipa_fn_target_info
    3210            0 :               (info->target_info, stmt);
    3211              : 
    3212              :           /* Account cost of address calculations in the statements.  */
    3213    523850873 :           for (unsigned int i = 0; i < gimple_num_ops (stmt); i++)
    3214              :             {
    3215    388363718 :               for (tree op = gimple_op (stmt, i);
    3216    747746741 :                    op && handled_component_p (op);
    3217     46779897 :                    op = TREE_OPERAND (op, 0))
    3218     46779897 :                 if ((TREE_CODE (op) == ARRAY_REF
    3219     46779897 :                      || TREE_CODE (op) == ARRAY_RANGE_REF)
    3220     46779897 :                     && TREE_CODE (TREE_OPERAND (op, 1)) == SSA_NAME)
    3221              :                   {
    3222      2379167 :                     ipa_predicate p = bb_predicate;
    3223      2379167 :                     if (fbi.info)
    3224      1861193 :                       p = p & will_be_nonconstant_expr_predicate
    3225      1861193 :                                  (&fbi, info, params_summary,
    3226      1861193 :                                   TREE_OPERAND (op, 1),
    3227      1861193 :                                   nonconstant_names);
    3228      2379167 :                     if (p != false)
    3229              :                       {
    3230      2373465 :                         time += freq;
    3231      2373465 :                         size += 1;
    3232      2373465 :                         if (dump_file)
    3233           24 :                           fprintf (dump_file,
    3234              :                                    "\t\tAccounting address calculation.\n");
    3235      2373465 :                         info->account_size_time (ipa_fn_summary::size_scale,
    3236              :                                                  freq,
    3237              :                                                  bb_predicate,
    3238              :                                                  p);
    3239              :                       }
    3240              :                   }
    3241              :             }
    3242              : 
    3243              :         }
    3244              :     }
    3245      7128796 :   free (order);
    3246              : 
    3247      7128796 :   if (nonconstant_names.exists () && !early)
    3248              :     {
    3249      1366448 :       ipa_fn_summary *s = ipa_fn_summaries->get (node);
    3250      1366448 :       unsigned max_loop_predicates = opt_for_fn (node->decl,
    3251              :                                                  param_ipa_max_loop_predicates);
    3252              : 
    3253      1366448 :       if (dump_file && (dump_flags & TDF_DETAILS))
    3254           14 :         flow_loops_dump (dump_file, NULL, 0);
    3255      1366448 :       scev_initialize ();
    3256      4719837 :       for (auto loop : loops_list (cfun, 0))
    3257              :         {
    3258       620493 :           ipa_predicate loop_iterations = true;
    3259       620493 :           sreal header_freq;
    3260       620493 :           edge ex;
    3261       620493 :           unsigned int j;
    3262       620493 :           class tree_niter_desc niter_desc;
    3263       620493 :           if (!loop->header->aux)
    3264            0 :             continue;
    3265              : 
    3266       620493 :           profile_count hdr_count = loop->header->count;
    3267       620493 :           sreal hdr_freq = hdr_count.to_sreal_scale (entry_count);
    3268              : 
    3269       620493 :           bb_predicate = *(ipa_predicate *)loop->header->aux;
    3270       620493 :           auto_vec<edge> exits = get_loop_exit_edges (loop);
    3271      1620863 :           FOR_EACH_VEC_ELT (exits, j, ex)
    3272      1000370 :             if (number_of_iterations_exit (loop, ex, &niter_desc, false)
    3273      1000370 :                 && !is_gimple_min_invariant (niter_desc.niter))
    3274              :             {
    3275       153793 :               ipa_predicate will_be_nonconstant
    3276       153793 :                 = will_be_nonconstant_expr_predicate (&fbi, info,
    3277              :                                                       params_summary,
    3278              :                                                       niter_desc.niter,
    3279              :                                                       nonconstant_names);
    3280       153793 :               if (will_be_nonconstant != true)
    3281        61362 :                 will_be_nonconstant = bb_predicate & will_be_nonconstant;
    3282       153793 :               if (will_be_nonconstant != true
    3283       215155 :                   && will_be_nonconstant != false)
    3284        60807 :                 loop_iterations &= will_be_nonconstant;
    3285              :             }
    3286       620493 :           add_freqcounting_predicate (&s->loop_iterations, loop_iterations,
    3287              :                                       hdr_freq, max_loop_predicates);
    3288       620493 :         }
    3289              : 
    3290              :       /* To avoid quadratic behavior we analyze stride predicates only
    3291              :          with respect to the containing loop.  Thus we simply iterate
    3292              :          over all defs in the outermost loop body.  */
    3293      1366448 :       for (class loop *loop = loops_for_fn (cfun)->tree_root->inner;
    3294      1853632 :            loop != NULL; loop = loop->next)
    3295              :         {
    3296       487184 :           ipa_predicate loop_stride = true;
    3297       487184 :           basic_block *body = get_loop_body (loop);
    3298       487184 :           profile_count hdr_count = loop->header->count;
    3299       487184 :           sreal hdr_freq = hdr_count.to_sreal_scale (entry_count);
    3300      2874041 :           for (unsigned i = 0; i < loop->num_nodes; i++)
    3301              :             {
    3302      2386857 :               gimple_stmt_iterator gsi;
    3303      2386857 :               if (!body[i]->aux)
    3304            7 :                 continue;
    3305              : 
    3306      2386850 :               bb_predicate = *(ipa_predicate *)body[i]->aux;
    3307     15742775 :               for (gsi = gsi_start_bb (body[i]); !gsi_end_p (gsi);
    3308     10969075 :                    gsi_next (&gsi))
    3309              :                 {
    3310     10969075 :                   gimple *stmt = gsi_stmt (gsi);
    3311              : 
    3312     10969075 :                   if (!is_gimple_assign (stmt))
    3313     10817239 :                     continue;
    3314              : 
    3315      5371000 :                   tree def = gimple_assign_lhs (stmt);
    3316      5371000 :                   if (TREE_CODE (def) != SSA_NAME)
    3317      1022456 :                     continue;
    3318              : 
    3319      4348544 :                   affine_iv iv;
    3320      8697088 :                   if (!simple_iv (loop_containing_stmt (stmt),
    3321              :                                   loop_containing_stmt (stmt),
    3322              :                                   def, &iv, true)
    3323      4348544 :                       || is_gimple_min_invariant (iv.step))
    3324      4196708 :                     continue;
    3325              : 
    3326       151836 :                   ipa_predicate will_be_nonconstant
    3327       151836 :                     = will_be_nonconstant_expr_predicate (&fbi, info,
    3328              :                                                           params_summary,
    3329              :                                                           iv.step,
    3330              :                                                           nonconstant_names);
    3331       151836 :                   if (will_be_nonconstant != true)
    3332        53626 :                     will_be_nonconstant = bb_predicate & will_be_nonconstant;
    3333       151836 :                   if (will_be_nonconstant != true
    3334       205462 :                       && will_be_nonconstant != false)
    3335        34754 :                     loop_stride = loop_stride & will_be_nonconstant;
    3336              :                 }
    3337              :             }
    3338       487184 :           add_freqcounting_predicate (&s->loop_strides, loop_stride,
    3339              :                                       hdr_freq, max_loop_predicates);
    3340       487184 :           free (body);
    3341              :         }
    3342      1366448 :       scev_finalize ();
    3343              :     }
    3344     62785232 :   FOR_ALL_BB_FN (bb, my_function)
    3345              :     {
    3346     55656436 :       edge e;
    3347     55656436 :       edge_iterator ei;
    3348              : 
    3349     55656436 :       if (bb->aux)
    3350     41131060 :         edge_predicate_pool.remove ((ipa_predicate *)bb->aux);
    3351     55656436 :       bb->aux = NULL;
    3352    118534491 :       FOR_EACH_EDGE (e, ei, bb->succs)
    3353              :         {
    3354     62878055 :           if (e->aux)
    3355      2482525 :             edge_predicate_pool.remove ((ipa_predicate *)e->aux);
    3356     62878055 :           e->aux = NULL;
    3357              :         }
    3358              :     }
    3359      7128796 :   ipa_fn_summary *s = ipa_fn_summaries->get (node);
    3360      7128796 :   ipa_size_summary *ss = ipa_size_summaries->get (node);
    3361      7128796 :   s->time = time;
    3362      7128796 :   ss->self_size = size;
    3363      7128796 :   nonconstant_names.release ();
    3364      7128796 :   ipa_release_body_info (&fbi);
    3365      7128796 :   if (opt_for_fn (node->decl, optimize))
    3366              :     {
    3367      6221162 :       if (!early)
    3368      1366448 :         loop_optimizer_finalize ();
    3369      4854714 :       else if (!ipa_edge_args_sum)
    3370      4854700 :         ipa_free_all_node_params ();
    3371      6221162 :       free_dominance_info (CDI_DOMINATORS);
    3372      6221162 :       free_dominance_info (CDI_POST_DOMINATORS);
    3373              :     }
    3374      7128796 :   if (dump_file)
    3375              :     {
    3376          247 :       fprintf (dump_file, "\n");
    3377          247 :       ipa_dump_fn_summary (dump_file, node);
    3378              :     }
    3379      7128796 : }
    3380              : 
    3381              : 
    3382              : /* Compute function summary.
    3383              :    EARLY is true when we compute parameters during early opts.  */
    3384              : 
    3385              : void
    3386      7130084 : compute_fn_summary (struct cgraph_node *node, bool early)
    3387              : {
    3388      7130084 :   HOST_WIDE_INT self_stack_size;
    3389      7130084 :   struct cgraph_edge *e;
    3390              : 
    3391      7130084 :   gcc_assert (!node->inlined_to);
    3392              : 
    3393      7130084 :   if (!ipa_fn_summaries)
    3394       214325 :     ipa_fn_summary_alloc ();
    3395              : 
    3396              :   /* Create a new ipa_fn_summary.  */
    3397      7130084 :   ((ipa_fn_summary_t *)ipa_fn_summaries)->remove_callees (node);
    3398      7130084 :   ipa_fn_summaries->remove (node);
    3399      7130084 :   class ipa_fn_summary *info = ipa_fn_summaries->get_create (node);
    3400      7130084 :   class ipa_size_summary *size_info = ipa_size_summaries->get_create (node);
    3401              : 
    3402              :   /* Estimate the stack size for the function if we're optimizing.  */
    3403     12443596 :   self_stack_size = optimize && !node->thunk
    3404     13351246 :                     ? estimated_stack_frame_size (node) : 0;
    3405      7130084 :   size_info->estimated_self_stack_size = self_stack_size;
    3406      7130084 :   info->estimated_stack_size = self_stack_size;
    3407              : 
    3408      7130084 :   if (node->thunk)
    3409              :     {
    3410         1288 :       ipa_call_summary *es = ipa_call_summaries->get_create (node->callees);
    3411         1288 :       ipa_predicate t = true;
    3412              : 
    3413         1288 :       node->can_change_signature = false;
    3414         1288 :       es->call_stmt_size = eni_size_weights.call_cost;
    3415         1288 :       es->call_stmt_time = eni_time_weights.call_cost;
    3416         3864 :       info->account_size_time (ipa_fn_summary::size_scale
    3417         1288 :                                * opt_for_fn (node->decl,
    3418              :                                  param_uninlined_function_thunk_insns),
    3419         1288 :                                opt_for_fn (node->decl,
    3420              :                                  param_uninlined_function_thunk_time), t, t);
    3421         1288 :       t = ipa_predicate::not_inlined ();
    3422         1288 :       info->account_size_time (2 * ipa_fn_summary::size_scale, 0, t, t);
    3423         1288 :       ipa_update_overall_fn_summary (node);
    3424         1288 :       size_info->self_size = size_info->size;
    3425         1288 :       if (stdarg_p (TREE_TYPE (node->decl)))
    3426              :         {
    3427            9 :           info->inlinable = false;
    3428            9 :           node->callees->inline_failed = CIF_VARIADIC_THUNK;
    3429              :         }
    3430              :       else
    3431         1279 :         info->inlinable = true;
    3432              :     }
    3433              :   else
    3434              :     {
    3435              :        /* Even is_gimple_min_invariant rely on current_function_decl.  */
    3436      7128796 :        push_cfun (DECL_STRUCT_FUNCTION (node->decl));
    3437              : 
    3438              :        /* During IPA profile merging we may be called w/o virtual SSA form
    3439              :           built.  */
    3440      7128796 :        update_ssa (TODO_update_ssa_only_virtuals);
    3441              : 
    3442              :        /* Can this function be inlined at all?  */
    3443      7128796 :        if (!opt_for_fn (node->decl, optimize)
    3444      8036430 :            && !lookup_attribute ("always_inline",
    3445       907634 :                                  DECL_ATTRIBUTES (node->decl)))
    3446       840070 :          info->inlinable = false;
    3447              :        else
    3448      6288726 :          info->inlinable = tree_inlinable_function_p (node->decl);
    3449              : 
    3450      7128796 :        bool no_signature = false;
    3451              : 
    3452              :        /* Don't allow signature changes for functions which have
    3453              :           [[gnu::musttail]] or [[clang::musttail]] calls.  Sometimes
    3454              :           (more often on targets which pass everything on the stack)
    3455              :           signature changes can result in tail calls being impossible
    3456              :           even when without the signature changes they would be ok.
    3457              :           See PR121023.  */
    3458      7128796 :        if (cfun->has_musttail)
    3459              :          {
    3460         1412 :            if (dump_file)
    3461            0 :             fprintf (dump_file, "No signature change:"
    3462              :                      " function has calls with musttail attribute.\n");
    3463              :            no_signature = true;
    3464              :          }
    3465              : 
    3466              :        /* Type attributes can use parameter indices to describe them.
    3467              :           Special case fn spec since we can safely preserve them in
    3468              :           modref summaries.  */
    3469      7128796 :        for (tree list = TYPE_ATTRIBUTES (TREE_TYPE (node->decl));
    3470      7517284 :             list && !no_signature; list = TREE_CHAIN (list))
    3471       388488 :         if (!ipa_param_adjustments::type_attribute_allowed_p
    3472       388488 :                         (get_attribute_name (list)))
    3473              :            {
    3474       157218 :              if (dump_file)
    3475              :                 {
    3476            0 :                   fprintf (dump_file, "No signature change:"
    3477              :                            " function type has unhandled attribute %s.\n",
    3478            0 :                            IDENTIFIER_POINTER (get_attribute_name (list)));
    3479              :                 }
    3480              :              no_signature = true;
    3481              :            }
    3482      7128796 :        for (tree parm = DECL_ARGUMENTS (node->decl);
    3483     21311596 :             parm && !no_signature; parm = DECL_CHAIN (parm))
    3484     14182800 :          if (variably_modified_type_p (TREE_TYPE (parm), node->decl))
    3485              :            {
    3486        15549 :              if (dump_file)
    3487              :                 {
    3488            0 :                   fprintf (dump_file, "No signature change:"
    3489              :                            " has parameter with variably modified type.\n");
    3490              :                 }
    3491              :              no_signature = true;
    3492              :            }
    3493              : 
    3494              :        /* Likewise for #pragma omp declare simd functions or functions
    3495              :           with simd attribute.  */
    3496      7128796 :        if (no_signature
    3497     14083413 :            || lookup_attribute ("omp declare simd",
    3498      6954617 :                                 DECL_ATTRIBUTES (node->decl)))
    3499       175867 :          node->can_change_signature = false;
    3500              :        else
    3501              :          {
    3502              :            /* Otherwise, inlinable functions always can change signature.  */
    3503      6952929 :            if (info->inlinable)
    3504      5581255 :              node->can_change_signature = true;
    3505              :            else
    3506              :              {
    3507              :                /* Functions calling builtin_apply cannot change signature.  */
    3508      5386681 :                for (e = node->callees; e; e = e->next_callee)
    3509              :                  {
    3510      4047571 :                    tree cdecl = e->callee->decl;
    3511      4047571 :                    if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS,
    3512              :                                                  BUILT_IN_VA_START))
    3513              :                      break;
    3514              :                  }
    3515      1371674 :                node->can_change_signature = !e;
    3516              :              }
    3517              :          }
    3518      7128796 :        analyze_function_body (node, early);
    3519      7128796 :        pop_cfun ();
    3520              :      }
    3521              : 
    3522              :   /* Inlining characteristics are maintained by the cgraph_mark_inline.  */
    3523      7130084 :   size_info->size = size_info->self_size;
    3524      7130084 :   info->estimated_stack_size = size_info->estimated_self_stack_size;
    3525              : 
    3526              :   /* Code above should compute exactly the same result as
    3527              :      ipa_update_overall_fn_summary except for case when speculative
    3528              :      edges are present since these are accounted to size but not
    3529              :      self_size. Do not compare time since different order the roundoff
    3530              :      errors result in slight changes.  */
    3531      7130084 :   ipa_update_overall_fn_summary (node);
    3532      7130084 :   if (flag_checking)
    3533              :     {
    3534      7609858 :       for (e = node->indirect_calls; e; e = e->next_callee)
    3535       479856 :        if (e->speculative)
    3536              :          break;
    3537      7130002 :       gcc_assert (e || size_info->size == size_info->self_size);
    3538              :     }
    3539      7130084 : }
    3540              : 
    3541              : 
    3542              : /* Compute parameters of functions used by inliner using
    3543              :    current_function_decl.  */
    3544              : 
    3545              : static unsigned int
    3546      5706041 : compute_fn_summary_for_current (void)
    3547              : {
    3548      5706041 :   compute_fn_summary (cgraph_node::get (current_function_decl), true);
    3549      5706041 :   return 0;
    3550              : }
    3551              : 
    3552              : /* Estimate benefit devirtualizing indirect edge IE and return true if it can
    3553              :    be devirtualized and inlined, provided m_known_vals, m_known_contexts and
    3554              :    m_known_aggs in AVALS.  Return false straight away if AVALS is NULL.  */
    3555              : 
    3556              : static bool
    3557      4794472 : estimate_edge_devirt_benefit (struct cgraph_edge *ie,
    3558              :                               int *size, int *time,
    3559              :                               ipa_call_arg_values *avals)
    3560              : {
    3561      4794472 :   tree target;
    3562      4794472 :   struct cgraph_node *callee;
    3563      4794472 :   class ipa_fn_summary *isummary;
    3564      4794472 :   enum availability avail;
    3565      4794472 :   bool speculative;
    3566              : 
    3567      4794472 :   if (!avals
    3568      6020695 :       || (!avals->m_known_vals.length() && !avals->m_known_contexts.length ()))
    3569              :     return false;
    3570      1428546 :   if (!opt_for_fn (ie->caller->decl, flag_indirect_inlining))
    3571              :     return false;
    3572              : 
    3573      1422249 :   target = ipa_get_indirect_edge_target
    3574      1422249 :     (ie->callee ? ie->speculative_call_indirect_edge () : ie,
    3575              :      avals, &speculative);
    3576      1422249 :   if (!target || speculative)
    3577              :     return false;
    3578              : 
    3579              :   /* If this is speculative call, turn its cost into 0; we will account
    3580              :      the call when processing the indirect call.  */
    3581       222966 :   if (ie->callee)
    3582              :     {
    3583         7061 :       gcc_checking_assert (ie->speculative && *size > 0);
    3584         7061 :       *size = 0;
    3585         7061 :       *time = 0;
    3586              :     }
    3587              :   else
    3588              :     {
    3589              :       /* Account for difference in cost between indirect and direct calls.  */
    3590       215905 :       *size -= (eni_size_weights.indirect_call_cost - eni_size_weights.call_cost);
    3591       215905 :       *time -= (eni_time_weights.indirect_call_cost - eni_time_weights.call_cost);
    3592              :     }
    3593       222966 :   gcc_checking_assert (*time >= 0);
    3594       222966 :   gcc_checking_assert (*size >= 0);
    3595              : 
    3596       222966 :   callee = cgraph_node::get (target);
    3597       222966 :   if (!callee || !callee->definition)
    3598              :     return false;
    3599       202361 :   callee = callee->function_symbol (&avail);
    3600       202361 :   if (avail < AVAIL_AVAILABLE)
    3601              :     return false;
    3602       202335 :   isummary = ipa_fn_summaries->get (callee);
    3603       202335 :   if (isummary == NULL)
    3604              :     return false;
    3605              : 
    3606       202323 :   return isummary->inlinable;
    3607              : }
    3608              : 
    3609              : /* Increase SIZE, MIN_SIZE (if non-NULL) and TIME for size and time needed to
    3610              :    handle edge E with probability PROB.  Set HINTS accordingly if edge may be
    3611              :    devirtualized.  AVALS, if non-NULL, describes the context of the call site
    3612              :    as far as values of parameters are concerened.  */
    3613              : 
    3614              : static inline void
    3615    197033574 : estimate_edge_size_and_time (struct cgraph_edge *e, int *size, int *min_size,
    3616              :                              sreal *time, ipa_call_arg_values *avals,
    3617              :                              ipa_hints *hints)
    3618              : {
    3619    197033574 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
    3620    197033574 :   int call_size = es->call_stmt_size;
    3621    197033574 :   int call_time = es->call_stmt_time;
    3622    197033574 :   int cur_size;
    3623              : 
    3624    192959306 :   if ((!e->callee || e->speculative)
    3625    197753778 :       && estimate_edge_devirt_benefit (e, &call_size, &call_time, avals))
    3626              :     {
    3627       201981 :       if (hints && e->maybe_hot_p ())
    3628       192000 :         *hints |= INLINE_HINT_indirect_call;
    3629              :     }
    3630    197033574 :   cur_size = call_size * ipa_fn_summary::size_scale;
    3631    197033574 :   *size += cur_size;
    3632    197033574 :   if (min_size)
    3633     27287119 :     *min_size += cur_size;
    3634    197033574 :   if (time)
    3635    187650262 :     *time += ((sreal)call_time) * e->sreal_frequency ();
    3636    197033574 : }
    3637              : 
    3638              : 
    3639              : /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all
    3640              :    calls in NODE.  POSSIBLE_TRUTHS and AVALS describe the context of the call
    3641              :    site.
    3642              : 
    3643              :    Helper for estimate_calls_size_and_time which does the same but
    3644              :    (in most cases) faster.  */
    3645              : 
    3646              : static void
    3647     62566637 : estimate_calls_size_and_time_1 (struct cgraph_node *node, int *size,
    3648              :                                 int *min_size, sreal *time,
    3649              :                                 ipa_hints *hints,
    3650              :                                 clause_t possible_truths,
    3651              :                                 ipa_call_arg_values *avals)
    3652              : {
    3653     62566637 :   struct cgraph_edge *e;
    3654    312945444 :   for (e = node->callees; e; e = e->next_callee)
    3655              :     {
    3656    250378807 :       if (!e->inline_failed)
    3657              :         {
    3658     43078813 :           gcc_checking_assert (!ipa_call_summaries->get (e));
    3659     43078813 :           estimate_calls_size_and_time_1 (e->callee, size, min_size, time,
    3660              :                                           hints, possible_truths, avals);
    3661              : 
    3662     43078813 :           continue;
    3663              :         }
    3664    207299994 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3665              : 
    3666              :       /* Do not care about zero sized builtins.  */
    3667    207299994 :       if (!es->call_stmt_size)
    3668              :         {
    3669     22841609 :           gcc_checking_assert (!es->call_stmt_time);
    3670     22841609 :           continue;
    3671              :         }
    3672    184458385 :       if (!es->predicate
    3673    184458385 :           || es->predicate->evaluate (possible_truths))
    3674              :         {
    3675              :           /* Predicates of calls shall not use NOT_CHANGED codes,
    3676              :              so we do not need to compute probabilities.  */
    3677    182041822 :           estimate_edge_size_and_time (e, size,
    3678    182041822 :                                        es->predicate ? NULL : min_size,
    3679              :                                        time, avals, hints);
    3680              :         }
    3681              :     }
    3682     66332205 :   for (e = node->indirect_calls; e; e = e->next_callee)
    3683              :     {
    3684      3765568 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3685      3765568 :       if (!es->predicate
    3686      3765568 :           || es->predicate->evaluate (possible_truths))
    3687      3737670 :         estimate_edge_size_and_time (e, size,
    3688      3737670 :                                      es->predicate ? NULL : min_size,
    3689              :                                      time, avals, hints);
    3690              :     }
    3691     62566637 : }
    3692              : 
    3693              : /* Populate sum->call_size_time_table for edges from NODE.  */
    3694              : 
    3695              : static void
    3696      3066356 : summarize_calls_size_and_time (struct cgraph_node *node,
    3697              :                                ipa_fn_summary *sum)
    3698              : {
    3699      3066356 :   struct cgraph_edge *e;
    3700     14542145 :   for (e = node->callees; e; e = e->next_callee)
    3701              :     {
    3702     11475789 :       if (!e->inline_failed)
    3703              :         {
    3704      1381211 :           gcc_checking_assert (!ipa_call_summaries->get (e));
    3705      1381211 :           summarize_calls_size_and_time (e->callee, sum);
    3706      1381211 :           continue;
    3707              :         }
    3708     10094578 :       int size = 0;
    3709     10094578 :       sreal time = 0;
    3710              : 
    3711     10094578 :       estimate_edge_size_and_time (e, &size, NULL, &time, NULL, NULL);
    3712              : 
    3713     10094578 :       ipa_predicate pred = true;
    3714     10094578 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3715              : 
    3716     10094578 :       if (es->predicate)
    3717      1889442 :         pred = *es->predicate;
    3718     10094578 :       sum->account_size_time (size, time, pred, pred, true);
    3719              :     }
    3720      3402954 :   for (e = node->indirect_calls; e; e = e->next_callee)
    3721              :     {
    3722       336598 :       int size = 0;
    3723       336598 :       sreal time = 0;
    3724              : 
    3725       336598 :       estimate_edge_size_and_time (e, &size, NULL, &time, NULL, NULL);
    3726       336598 :       ipa_predicate pred = true;
    3727       336598 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3728              : 
    3729       336598 :       if (es->predicate)
    3730       103808 :         pred = *es->predicate;
    3731       336598 :       sum->account_size_time (size, time, pred, pred, true);
    3732              :     }
    3733      3066356 : }
    3734              : 
    3735              : /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all
    3736              :    calls in NODE.  POSSIBLE_TRUTHS and AVALS (the latter if non-NULL) describe
    3737              :    context of the call site.  */
    3738              : 
    3739              : static void
    3740     19487845 : estimate_calls_size_and_time (struct cgraph_node *node, int *size,
    3741              :                               int *min_size, sreal *time,
    3742              :                               ipa_hints *hints,
    3743              :                               clause_t possible_truths,
    3744              :                               ipa_call_arg_values *avals)
    3745              : {
    3746     19487845 :   class ipa_fn_summary *sum = ipa_fn_summaries->get (node);
    3747     19487845 :   bool use_table = true;
    3748              : 
    3749     19487845 :   gcc_assert (node->callees || node->indirect_calls);
    3750              : 
    3751              :   /* During early inlining we do not calculate info for very
    3752              :      large functions and thus there is no need for producing
    3753              :      summaries.  */
    3754     19487845 :   if (!ipa_node_params_sum)
    3755              :     use_table = false;
    3756              :   /* Do not calculate summaries for simple wrappers; it is waste
    3757              :      of memory.  */
    3758     10515798 :   else if (node->callees && !node->indirect_calls
    3759      9779646 :            && node->callees->inline_failed && !node->callees->next_callee)
    3760              :     use_table = false;
    3761              :   /* If there is an indirect edge that may be optimized, we need
    3762              :      to go the slow way.  */
    3763      8425523 :   else if (avals
    3764      8425523 :            && (avals->m_known_vals.length ()
    3765      3146084 :                || avals->m_known_contexts.length ()
    3766      3005204 :                || avals->m_known_aggs.length ()))
    3767              :     {
    3768      3946376 :       ipa_node_params *params_summary = ipa_node_params_sum->get (node);
    3769      3946376 :       unsigned int nargs = params_summary
    3770      3946376 :                            ? ipa_get_param_count (params_summary) : 0;
    3771              : 
    3772     13477244 :       for (unsigned int i = 0; i < nargs && use_table; i++)
    3773              :         {
    3774      9530868 :           if (ipa_is_param_used_by_indirect_call (params_summary, i)
    3775      9530868 :               && (avals->safe_sval_at (i)
    3776       259302 :                   || (ipa_argagg_value_list (avals).value_for_index_p (i))))
    3777              :             use_table = false;
    3778      9431746 :           else if (ipa_is_param_used_by_polymorphic_call (params_summary, i)
    3779      9431746 :                    && (avals->m_known_contexts.length () > i
    3780      9682933 :                        && !avals->m_known_contexts[i].useless_p ()))
    3781              :             use_table = false;
    3782              :         }
    3783              :     }
    3784              : 
    3785              :   /* Fast path is via the call size time table.  */
    3786      3946376 :   if (use_table)
    3787              :     {
    3788              :       /* Build summary if it is absent.  */
    3789      8174507 :       if (!sum->call_size_time_table.length ())
    3790              :         {
    3791       862239 :           ipa_predicate true_pred = true;
    3792       862239 :           sum->account_size_time (0, 0, true_pred, true_pred, true);
    3793       862239 :           summarize_calls_size_and_time (node, sum);
    3794              :         }
    3795              : 
    3796      8174507 :       int old_size = *size;
    3797      8174507 :       sreal old_time = time ? *time : 0;
    3798              : 
    3799      8174507 :       if (min_size)
    3800      8174507 :         *min_size += sum->call_size_time_table[0].size;
    3801              : 
    3802              :       unsigned int i;
    3803              :       size_time_entry *e;
    3804              : 
    3805              :       /* Walk the table and account sizes and times.  */
    3806     22064512 :       for (i = 0; sum->call_size_time_table.iterate (i, &e);
    3807              :            i++)
    3808     13890005 :         if (e->exec_predicate.evaluate (possible_truths))
    3809              :           {
    3810     12794266 :             *size += e->size;
    3811     12794266 :             if (time)
    3812     10703229 :               *time += e->time;
    3813              :           }
    3814              : 
    3815              :       /* Be careful and see if both methods agree.  */
    3816           21 :       if ((flag_checking || dump_file)
    3817              :           /* Do not try to sanity check when we know we lost some
    3818              :              precision.  */
    3819      8174507 :           && sum->call_size_time_table.length ()
    3820              :              < ipa_fn_summary::max_size_time_table_size)
    3821              :         {
    3822      8174486 :           estimate_calls_size_and_time_1 (node, &old_size, NULL, &old_time, NULL,
    3823              :                                           possible_truths, avals);
    3824      8174486 :           gcc_assert (*size == old_size);
    3825     14983753 :           if (time && (*time - old_time > 1 || *time - old_time < -1)
    3826      8174515 :               && dump_file)
    3827            0 :             fprintf (dump_file, "Time mismatch in call summary %f!=%f\n",
    3828              :                      old_time.to_double (),
    3829              :                      time->to_double ());
    3830              :         }
    3831              :     }
    3832              :   /* Slow path by walking all edges.  */
    3833              :   else
    3834     11313338 :     estimate_calls_size_and_time_1 (node, size, min_size, time, hints,
    3835              :                                     possible_truths, avals);
    3836     19487845 : }
    3837              : 
    3838              : /* Main constructor for ipa call context.  Memory allocation of ARG_VALUES
    3839              :    is owned by the caller.  INLINE_PARAM_SUMMARY is also owned by the
    3840              :    caller.  */
    3841              : 
    3842     18768317 : ipa_call_context::ipa_call_context (cgraph_node *node, clause_t possible_truths,
    3843              :                                     clause_t nonspec_possible_truths,
    3844              :                                     vec<inline_param_summary>
    3845              :                                       inline_param_summary,
    3846     18768317 :                                     ipa_auto_call_arg_values *arg_values)
    3847     18768317 : : m_node (node), m_possible_truths (possible_truths),
    3848     18768317 :   m_nonspec_possible_truths (nonspec_possible_truths),
    3849     18768317 :   m_inline_param_summary (inline_param_summary),
    3850     18768317 :   m_avals (arg_values)
    3851              : {
    3852     18768317 : }
    3853              : 
    3854              : /* Set THIS to be a duplicate of CTX.  Copy all relevant info.  */
    3855              : 
    3856              : void
    3857      1849066 : ipa_cached_call_context::duplicate_from (const ipa_call_context &ctx)
    3858              : {
    3859      1849066 :   m_node = ctx.m_node;
    3860      1849066 :   m_possible_truths = ctx.m_possible_truths;
    3861      1849066 :   m_nonspec_possible_truths = ctx.m_nonspec_possible_truths;
    3862      1849066 :   ipa_node_params *params_summary = ipa_node_params_sum->get (m_node);
    3863      1849066 :   unsigned int nargs = params_summary
    3864      1849066 :                        ? ipa_get_param_count (params_summary) : 0;
    3865              : 
    3866      1849066 :   m_inline_param_summary = vNULL;
    3867              :   /* Copy the info only if there is at least one useful entry.  */
    3868      1849066 :   if (ctx.m_inline_param_summary.exists ())
    3869              :     {
    3870      1647466 :       unsigned int n = MIN (ctx.m_inline_param_summary.length (), nargs);
    3871              : 
    3872      3766096 :       for (unsigned int i = 0; i < n; i++)
    3873      3088641 :         if (ipa_is_param_used_by_ipa_predicates (params_summary, i)
    3874      4378256 :             && !ctx.m_inline_param_summary[i].useless_p ())
    3875              :           {
    3876       970011 :             m_inline_param_summary
    3877       970011 :                     = ctx.m_inline_param_summary.copy ();
    3878       970011 :             break;
    3879              :           }
    3880              :     }
    3881      1849066 :   m_avals.m_known_vals = vNULL;
    3882      1849066 :   if (ctx.m_avals.m_known_vals.exists ())
    3883              :     {
    3884      1849066 :       unsigned int n = MIN (ctx.m_avals.m_known_vals.length (), nargs);
    3885              : 
    3886      4379886 :       for (unsigned int i = 0; i < n; i++)
    3887      2559090 :         if (ipa_is_param_used_by_indirect_call (params_summary, i)
    3888      2559090 :             && ctx.m_avals.m_known_vals[i])
    3889              :           {
    3890        28270 :             m_avals.m_known_vals = ctx.m_avals.m_known_vals.copy ();
    3891        28270 :             break;
    3892              :           }
    3893              :     }
    3894              : 
    3895      1849066 :   m_avals.m_known_contexts = vNULL;
    3896      1849066 :   if (ctx.m_avals.m_known_contexts.exists ())
    3897              :     {
    3898      1849066 :       unsigned int n = MIN (ctx.m_avals.m_known_contexts.length (), nargs);
    3899              : 
    3900      1850398 :       for (unsigned int i = 0; i < n; i++)
    3901        23545 :         if (ipa_is_param_used_by_polymorphic_call (params_summary, i)
    3902        23545 :             && !ctx.m_avals.m_known_contexts[i].useless_p ())
    3903              :           {
    3904        22213 :             m_avals.m_known_contexts = ctx.m_avals.m_known_contexts.copy ();
    3905        22213 :             break;
    3906              :           }
    3907              :     }
    3908              : 
    3909      1849066 :   m_avals.m_known_aggs = vNULL;
    3910      1849066 :   if (ctx.m_avals.m_known_aggs.exists ())
    3911              :     {
    3912      1849066 :       const ipa_argagg_value_list avl (&ctx.m_avals);
    3913      6237847 :       for (unsigned int i = 0; i < nargs; i++)
    3914      4391994 :         if (ipa_is_param_used_by_indirect_call (params_summary, i)
    3915      4391994 :             && avl.value_for_index_p (i))
    3916              :           {
    3917         3213 :             m_avals.m_known_aggs = ctx.m_avals.m_known_aggs.copy ();
    3918         3213 :             break;
    3919              :           }
    3920              :     }
    3921              : 
    3922      1849066 :   m_avals.m_known_value_ranges = vNULL;
    3923      1849066 : }
    3924              : 
    3925              : /* Release memory used by known_vals/contexts/aggs vectors.  and
    3926              :    inline_param_summary.  */
    3927              : 
    3928              : void
    3929      3011795 : ipa_cached_call_context::release ()
    3930              : {
    3931              :   /* See if context is initialized at first place.  */
    3932      3011795 :   if (!m_node)
    3933              :     return;
    3934      1849066 :   m_avals.m_known_aggs.release ();
    3935      1849066 :   m_avals.m_known_vals.release ();
    3936      1849066 :   m_avals.m_known_contexts.release ();
    3937      1849066 :   m_inline_param_summary.release ();
    3938              : }
    3939              : 
    3940              : /* Return true if CTX describes the same call context as THIS.  */
    3941              : 
    3942              : bool
    3943      6579563 : ipa_call_context::equal_to (const ipa_call_context &ctx)
    3944              : {
    3945      6579563 :   if (m_node != ctx.m_node
    3946      5416834 :       || m_possible_truths != ctx.m_possible_truths
    3947      4860299 :       || m_nonspec_possible_truths != ctx.m_nonspec_possible_truths)
    3948              :     return false;
    3949              : 
    3950      4860299 :   ipa_node_params *params_summary = ipa_node_params_sum->get (m_node);
    3951      4860299 :   unsigned int nargs = params_summary
    3952      4860299 :                        ? ipa_get_param_count (params_summary) : 0;
    3953              : 
    3954      4860299 :   if (m_inline_param_summary.exists () || ctx.m_inline_param_summary.exists ())
    3955              :     {
    3956     14686871 :       for (unsigned int i = 0; i < nargs; i++)
    3957              :         {
    3958     10154758 :           if (!ipa_is_param_used_by_ipa_predicates (params_summary, i))
    3959      3237279 :             continue;
    3960      6917479 :           if (i >= m_inline_param_summary.length ()
    3961      4931480 :               || m_inline_param_summary[i].useless_p ())
    3962              :             {
    3963      2908398 :               if (i < ctx.m_inline_param_summary.length ()
    3964      2908398 :                   && !ctx.m_inline_param_summary[i].useless_p ())
    3965              :                 return false;
    3966      2862733 :               continue;
    3967              :             }
    3968      4009081 :           if (i >= ctx.m_inline_param_summary.length ()
    3969      4009078 :               || ctx.m_inline_param_summary[i].useless_p ())
    3970              :             {
    3971        44482 :               if (i < m_inline_param_summary.length ()
    3972        44482 :                   && !m_inline_param_summary[i].useless_p ())
    3973              :                 return false;
    3974            0 :               continue;
    3975              :             }
    3976      3964599 :           if (!m_inline_param_summary[i].equal_to
    3977      3964599 :                  (ctx.m_inline_param_summary[i]))
    3978              :             return false;
    3979              :         }
    3980              :     }
    3981      4743950 :   if (m_avals.m_known_vals.exists () || ctx.m_avals.m_known_vals.exists ())
    3982              :     {
    3983     14691816 :       for (unsigned int i = 0; i < nargs; i++)
    3984              :         {
    3985      9958311 :           if (!ipa_is_param_used_by_indirect_call (params_summary, i))
    3986      9759829 :             continue;
    3987       198482 :           if (i >= m_avals.m_known_vals.length () || !m_avals.m_known_vals[i])
    3988              :             {
    3989       140768 :               if (i < ctx.m_avals.m_known_vals.length ()
    3990       140768 :                   && ctx.m_avals.m_known_vals[i])
    3991              :                 return false;
    3992       140687 :               continue;
    3993              :             }
    3994        57714 :           if (i >= ctx.m_avals.m_known_vals.length ()
    3995        57714 :               || !ctx.m_avals.m_known_vals[i])
    3996              :             {
    3997              :               if (i < m_avals.m_known_vals.length () && m_avals.m_known_vals[i])
    3998              :                 return false;
    3999              :               continue;
    4000              :             }
    4001        57630 :           if (m_avals.m_known_vals[i] != ctx.m_avals.m_known_vals[i])
    4002              :             return false;
    4003              :         }
    4004              :     }
    4005      4733505 :   if (m_avals.m_known_contexts.exists ()
    4006      4733505 :       || ctx.m_avals.m_known_contexts.exists ())
    4007              :     {
    4008     14676503 :       for (unsigned int i = 0; i < nargs; i++)
    4009              :         {
    4010      9944605 :           if (!ipa_is_param_used_by_polymorphic_call (params_summary, i))
    4011      9819161 :             continue;
    4012       125444 :           if (i >= m_avals.m_known_contexts.length ()
    4013       124277 :               || m_avals.m_known_contexts[i].useless_p ())
    4014              :             {
    4015         1167 :               if (i < ctx.m_avals.m_known_contexts.length ()
    4016         1167 :                   && !ctx.m_avals.m_known_contexts[i].useless_p ())
    4017              :                 return false;
    4018         1158 :               continue;
    4019              :             }
    4020       124277 :           if (i >= ctx.m_avals.m_known_contexts.length ()
    4021       124277 :               || ctx.m_avals.m_known_contexts[i].useless_p ())
    4022              :             {
    4023            8 :               if (i < m_avals.m_known_contexts.length ()
    4024      1849074 :                   && !m_avals.m_known_contexts[i].useless_p ())
    4025              :                 return false;
    4026            0 :               continue;
    4027              :             }
    4028       124269 :           if (!m_avals.m_known_contexts[i].equal_to
    4029       124269 :                  (ctx.m_avals.m_known_contexts[i]))
    4030              :             return false;
    4031              :         }
    4032              :     }
    4033      4731898 :   if (m_avals.m_known_aggs.exists () || ctx.m_avals.m_known_aggs.exists ())
    4034              :     {
    4035              :       unsigned i = 0, j = 0;
    4036     10981192 :       while (i < m_avals.m_known_aggs.length ()
    4037      5489840 :              || j < ctx.m_avals.m_known_aggs.length ())
    4038              :         {
    4039       759343 :           if (i >= m_avals.m_known_aggs.length ())
    4040              :             {
    4041       754504 :               int idx2 = ctx.m_avals.m_known_aggs[j].index;
    4042       754504 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx2))
    4043              :                 return false;
    4044       753904 :               j++;
    4045       753904 :               continue;
    4046       753904 :             }
    4047         4839 :           if (j >= ctx.m_avals.m_known_aggs.length ())
    4048              :             {
    4049          631 :               int idx1 = m_avals.m_known_aggs[i].index;
    4050          631 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4051              :                 return false;
    4052            8 :               i++;
    4053            8 :               continue;
    4054            8 :             }
    4055              : 
    4056         4208 :           int idx1 = m_avals.m_known_aggs[i].index;
    4057         4208 :           int idx2 = ctx.m_avals.m_known_aggs[j].index;
    4058         4208 :           if (idx1 < idx2)
    4059              :             {
    4060            0 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4061              :                 return false;
    4062            0 :               i++;
    4063            0 :               continue;
    4064              :             }
    4065         4208 :           if (idx1 > idx2)
    4066              :             {
    4067            0 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx2))
    4068              :                 return false;
    4069            0 :               j++;
    4070            0 :               continue;
    4071              :             }
    4072         4208 :           if (!ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4073              :             {
    4074          342 :               i++;
    4075          342 :               j++;
    4076          342 :               continue;
    4077              :             }
    4078              : 
    4079         3866 :           if ((m_avals.m_known_aggs[i].unit_offset
    4080         3866 :                != ctx.m_avals.m_known_aggs[j].unit_offset)
    4081         3858 :               || (m_avals.m_known_aggs[i].by_ref
    4082         3858 :                != ctx.m_avals.m_known_aggs[j].by_ref)
    4083         7724 :               || !operand_equal_p (m_avals.m_known_aggs[i].value,
    4084         3858 :                                    ctx.m_avals.m_known_aggs[j].value))
    4085          178 :             return false;
    4086         3688 :           i++;
    4087         3688 :           j++;
    4088              :         }
    4089              :     }
    4090              :   return true;
    4091              : }
    4092              : 
    4093              : /* Fill in the selected fields in ESTIMATES with value estimated for call in
    4094              :    this context.  Always compute size and min_size.  Only compute time and
    4095              :    nonspecialized_time if EST_TIMES is true.  Only compute hints if EST_HINTS
    4096              :    is true.  */
    4097              : 
    4098              : void
    4099     18737776 : ipa_call_context::estimate_size_and_time (ipa_call_estimates *estimates,
    4100              :                                           bool est_times, bool est_hints)
    4101              : {
    4102     18737776 :   class ipa_fn_summary *info = ipa_fn_summaries->get (m_node);
    4103     18737776 :   size_time_entry *e;
    4104     18737776 :   int size = 0;
    4105     18737776 :   sreal time = 0;
    4106     18737776 :   int min_size = 0;
    4107     18737776 :   ipa_hints hints = 0;
    4108     18737776 :   sreal loops_with_known_iterations = 0;
    4109     18737776 :   sreal loops_with_known_strides = 0;
    4110     18737776 :   int i;
    4111              : 
    4112     18737776 :   if (dump_file && (dump_flags & TDF_DETAILS))
    4113              :     {
    4114         1332 :       bool found = false;
    4115         1332 :       fprintf (dump_file, "   Estimating body: %s\n"
    4116              :                "   Known to be false: ", m_node->dump_name ());
    4117              : 
    4118         4287 :       for (i = ipa_predicate::not_inlined_condition;
    4119         8574 :            i < (ipa_predicate::first_dynamic_condition
    4120         7002 :                 + (int) vec_safe_length (info->conds)); i++)
    4121         2955 :         if (!(m_possible_truths & (1 << i)))
    4122              :           {
    4123         1769 :             if (found)
    4124          504 :               fprintf (dump_file, ", ");
    4125         1769 :             found = true;
    4126         1769 :             dump_condition (dump_file, info->conds, i);
    4127              :           }
    4128              :     }
    4129              : 
    4130     18737776 :   if (m_node->callees || m_node->indirect_calls)
    4131     24604177 :     estimate_calls_size_and_time (m_node, &size, &min_size,
    4132              :                                   est_times ? &time : NULL,
    4133              :                                   est_hints ? &hints : NULL, m_possible_truths,
    4134              :                                   &m_avals);
    4135              : 
    4136     18737776 :   sreal nonspecialized_time = time;
    4137              : 
    4138     18737776 :   min_size += info->size_time_table[0].size;
    4139    129417089 :   for (i = 0; info->size_time_table.iterate (i, &e); i++)
    4140              :     {
    4141    110679313 :       bool exec = e->exec_predicate.evaluate (m_nonspec_possible_truths);
    4142              : 
    4143              :       /* Because predicates are conservative, it can happen that nonconst is 1
    4144              :          but exec is 0.  */
    4145    110679313 :       if (exec)
    4146              :         {
    4147    108090597 :           bool nonconst = e->nonconst_predicate.evaluate (m_possible_truths);
    4148              : 
    4149    108090597 :           gcc_checking_assert (e->time >= 0);
    4150    108090597 :           gcc_checking_assert (time >= 0);
    4151              : 
    4152              :           /* We compute specialized size only because size of nonspecialized
    4153              :              copy is context independent.
    4154              : 
    4155              :              The difference between nonspecialized execution and specialized is
    4156              :              that nonspecialized is not going to have optimized out computations
    4157              :              known to be constant in a specialized setting.  */
    4158    108090597 :           if (nonconst)
    4159     54527757 :             size += e->size;
    4160    108090597 :           if (!est_times)
    4161     56126444 :             continue;
    4162     51964153 :           nonspecialized_time += e->time;
    4163     51964153 :           if (!nonconst)
    4164              :             ;
    4165     25064750 :           else if (!m_inline_param_summary.exists ())
    4166              :             {
    4167      2508942 :               if (nonconst)
    4168      2508942 :                 time += e->time;
    4169              :             }
    4170              :           else
    4171              :             {
    4172     22555808 :               int prob = e->nonconst_predicate.probability
    4173     22555808 :                                                (info->conds, m_possible_truths,
    4174              :                                                 m_inline_param_summary);
    4175     22555808 :               gcc_checking_assert (prob >= 0);
    4176     22555808 :               gcc_checking_assert (prob <= REG_BR_PROB_BASE);
    4177     22555808 :               if (prob == REG_BR_PROB_BASE)
    4178     19277380 :                 time += e->time;
    4179              :               else
    4180      3278428 :                 time += e->time * prob / REG_BR_PROB_BASE;
    4181              :             }
    4182     51964153 :           gcc_checking_assert (time >= 0);
    4183              :         }
    4184              :      }
    4185     18737776 :   gcc_checking_assert (info->size_time_table[0].exec_predicate == true);
    4186     18737776 :   gcc_checking_assert (info->size_time_table[0].nonconst_predicate == true);
    4187     18737776 :   gcc_checking_assert (min_size >= 0);
    4188     18737776 :   gcc_checking_assert (size >= 0);
    4189     18737776 :   gcc_checking_assert (time >= 0);
    4190              :   /* nonspecialized_time should be always bigger than specialized time.
    4191              :      Roundoff issues however may get into the way.  */
    4192     18737776 :   gcc_checking_assert ((nonspecialized_time - time * 99 / 100) >= -1);
    4193              : 
    4194              :   /* Roundoff issues may make specialized time bigger than nonspecialized
    4195              :      time.  We do not really want that to happen because some heuristics
    4196              :      may get confused by seeing negative speedups.  */
    4197     18737776 :   if (time > nonspecialized_time)
    4198            0 :     time = nonspecialized_time;
    4199              : 
    4200     18737776 :   if (est_hints)
    4201              :     {
    4202      6834548 :       if (info->scc_no)
    4203       206173 :         hints |= INLINE_HINT_in_scc;
    4204      6834548 :       if (DECL_DECLARED_INLINE_P (m_node->decl))
    4205      4244295 :         hints |= INLINE_HINT_declared_inline;
    4206      6834548 :       if (info->builtin_constant_p_parms.length ()
    4207         8966 :           && DECL_DECLARED_INLINE_P (m_node->decl))
    4208         8908 :         hints |= INLINE_HINT_builtin_constant_p;
    4209              : 
    4210              :       ipa_freqcounting_predicate *fcp;
    4211      7385224 :       for (i = 0; vec_safe_iterate (info->loop_iterations, i, &fcp); i++)
    4212       550676 :         if (!fcp->predicate->evaluate (m_possible_truths))
    4213              :           {
    4214       370791 :             hints |= INLINE_HINT_loop_iterations;
    4215       370791 :             loops_with_known_iterations += fcp->freq;
    4216              :           }
    4217      6834548 :       estimates->loops_with_known_iterations = loops_with_known_iterations;
    4218              : 
    4219      7116058 :       for (i = 0; vec_safe_iterate (info->loop_strides, i, &fcp); i++)
    4220       281510 :         if (!fcp->predicate->evaluate (m_possible_truths))
    4221              :           {
    4222       260838 :             hints |= INLINE_HINT_loop_stride;
    4223       260838 :             loops_with_known_strides += fcp->freq;
    4224              :           }
    4225      6834548 :       estimates->loops_with_known_strides = loops_with_known_strides;
    4226              :     }
    4227              : 
    4228     18737776 :   size = RDIV (size, ipa_fn_summary::size_scale);
    4229     18737776 :   min_size = RDIV (min_size, ipa_fn_summary::size_scale);
    4230              : 
    4231     18737776 :   if (dump_file && (dump_flags & TDF_DETAILS))
    4232              :     {
    4233         1332 :       fprintf (dump_file, "\n   size:%i", (int) size);
    4234         1332 :       if (est_times)
    4235         1090 :         fprintf (dump_file, " time:%f nonspec time:%f",
    4236              :                  time.to_double (), nonspecialized_time.to_double ());
    4237         1332 :       if (est_hints)
    4238         1090 :         fprintf (dump_file, " loops with known iterations:%f "
    4239              :                  "known strides:%f", loops_with_known_iterations.to_double (),
    4240              :                  loops_with_known_strides.to_double ());
    4241         1332 :       fprintf (dump_file, "\n");
    4242              :     }
    4243     18737776 :   if (est_times)
    4244              :     {
    4245      6834548 :       estimates->time = time;
    4246      6834548 :       estimates->nonspecialized_time = nonspecialized_time;
    4247              :     }
    4248     18737776 :   estimates->size = size;
    4249     18737776 :   estimates->min_size = min_size;
    4250     18737776 :   if (est_hints)
    4251      6834548 :     estimates->hints = hints;
    4252     18737776 :   return;
    4253              : }
    4254              : 
    4255              : 
    4256              : /* Estimate size and time needed to execute callee of EDGE assuming that
    4257              :    parameters known to be constant at caller of EDGE are propagated.
    4258              :    KNOWN_VALS and KNOWN_CONTEXTS are vectors of assumed known constant values
    4259              :    and types for parameters.  */
    4260              : 
    4261              : void
    4262       281725 : estimate_ipcp_clone_size_and_time (struct cgraph_node *node,
    4263              :                                    ipa_auto_call_arg_values *avals,
    4264              :                                    ipa_call_estimates *estimates)
    4265              : {
    4266       281725 :   clause_t clause, nonspec_clause;
    4267              : 
    4268       281725 :   evaluate_conditions_for_known_args (node, false, avals, &clause,
    4269              :                                       &nonspec_clause, NULL);
    4270       281725 :   ipa_call_context ctx (node, clause, nonspec_clause, vNULL, avals);
    4271       281725 :   ctx.estimate_size_and_time (estimates);
    4272       281725 : }
    4273              : 
    4274              : /* Return stack frame offset where frame of NODE is supposed to start inside
    4275              :    of the function it is inlined to.
    4276              :    Return 0 for functions that are not inlined.  */
    4277              : 
    4278              : HOST_WIDE_INT
    4279      5029174 : ipa_get_stack_frame_offset (struct cgraph_node *node)
    4280              : {
    4281      5029174 :   HOST_WIDE_INT offset = 0;
    4282      5029174 :   if (!node->inlined_to)
    4283              :     return 0;
    4284      3887413 :   node = node->callers->caller;
    4285      4825057 :   while (true)
    4286              :     {
    4287      4825057 :       offset += ipa_size_summaries->get (node)->estimated_self_stack_size;
    4288      4356235 :       if (!node->inlined_to)
    4289              :         return offset;
    4290       468822 :       node = node->callers->caller;
    4291              :     }
    4292              : }
    4293              : 
    4294              : 
    4295              : /* Update summary information of inline clones after inlining.
    4296              :    Compute peak stack usage.  */
    4297              : 
    4298              : static void
    4299      4552416 : inline_update_callee_summaries (struct cgraph_node *node, int depth)
    4300              : {
    4301      4552416 :   struct cgraph_edge *e;
    4302              : 
    4303      4552416 :   ipa_propagate_frequency (node);
    4304      8763676 :   for (e = node->callees; e; e = e->next_callee)
    4305              :     {
    4306      4211260 :       if (!e->inline_failed)
    4307       665557 :         inline_update_callee_summaries (e->callee, depth);
    4308              :       else
    4309      3545703 :         ipa_call_summaries->get (e)->loop_depth += depth;
    4310              :     }
    4311      4655423 :   for (e = node->indirect_calls; e; e = e->next_callee)
    4312       103007 :     ipa_call_summaries->get (e)->loop_depth += depth;
    4313      4552416 : }
    4314              : 
    4315              : /* Update change_prob and points_to_local_or_readonly_memory of EDGE after
    4316              :    INLINED_EDGE has been inlined.
    4317              : 
    4318              :    When function A is inlined in B and A calls C with parameter that
    4319              :    changes with probability PROB1 and C is known to be passthrough
    4320              :    of argument if B that change with probability PROB2, the probability
    4321              :    of change is now PROB1*PROB2.  */
    4322              : 
    4323              : static void
    4324      3649023 : remap_edge_params (struct cgraph_edge *inlined_edge,
    4325              :                    struct cgraph_edge *edge)
    4326              : {
    4327      3649023 :   if (ipa_node_params_sum)
    4328              :     {
    4329      2618044 :       int i;
    4330      2618044 :       ipa_edge_args *args = ipa_edge_args_sum->get (edge);
    4331      2618044 :       if (!args)
    4332              :         return;
    4333      1463244 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    4334      1463244 :       class ipa_call_summary *inlined_es
    4335      1463244 :         = ipa_call_summaries->get (inlined_edge);
    4336              : 
    4337      1463244 :       if (es->param.length () == 0)
    4338              :         return;
    4339              : 
    4340      8515630 :       for (i = 0; i < ipa_get_cs_argument_count (args); i++)
    4341              :         {
    4342      2869558 :           struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
    4343      2869558 :           if (jfunc->type == IPA_JF_PASS_THROUGH
    4344      2127871 :               || jfunc->type == IPA_JF_ANCESTOR)
    4345              :             {
    4346       874422 :               int id = jfunc->type == IPA_JF_PASS_THROUGH
    4347       874422 :                        ? ipa_get_jf_pass_through_formal_id (jfunc)
    4348       132735 :                        : ipa_get_jf_ancestor_formal_id (jfunc);
    4349      1748752 :               if (id < (int) inlined_es->param.length ())
    4350              :                 {
    4351       874322 :                   int prob1 = es->param[i].change_prob;
    4352       874322 :                   int prob2 = inlined_es->param[id].change_prob;
    4353       874322 :                   int prob = combine_probabilities (prob1, prob2);
    4354              : 
    4355       874322 :                   if (prob1 && prob2 && !prob)
    4356       874322 :                     prob = 1;
    4357              : 
    4358       874322 :                   es->param[i].change_prob = prob;
    4359              : 
    4360      1748644 :                   if (inlined_es
    4361       874322 :                         ->param[id].points_to_local_or_readonly_memory)
    4362       203563 :                     es->param[i].points_to_local_or_readonly_memory = true;
    4363      1748644 :                   if (inlined_es
    4364       874322 :                         ->param[id].points_to_possible_sra_candidate)
    4365       172651 :                     es->param[i].points_to_possible_sra_candidate = true;
    4366              :                 }
    4367       874422 :               if (!es->param[i].points_to_local_or_readonly_memory
    4368              :                   && jfunc->type == IPA_JF_CONST
    4369              :                   && points_to_local_or_readonly_memory_p
    4370              :                          (ipa_get_jf_constant (jfunc)))
    4371              :                 es->param[i].points_to_local_or_readonly_memory = true;
    4372              :             }
    4373              :         }
    4374              :     }
    4375              : }
    4376              : 
    4377              : /* Update edge summaries of NODE after INLINED_EDGE has been inlined.
    4378              : 
    4379              :    Remap predicates of callees of NODE.  Rest of arguments match
    4380              :    remap_predicate.
    4381              : 
    4382              :    Also update change probabilities.  */
    4383              : 
    4384              : static void
    4385      4552416 : remap_edge_summaries (struct cgraph_edge *inlined_edge,
    4386              :                       struct cgraph_node *node,
    4387              :                       class ipa_fn_summary *info,
    4388              :                       class ipa_node_params *params_summary,
    4389              :                       class ipa_fn_summary *callee_info,
    4390              :                       const vec<int> &operand_map,
    4391              :                       const vec<HOST_WIDE_INT> &offset_map,
    4392              :                       clause_t possible_truths,
    4393              :                       ipa_predicate *toplev_predicate)
    4394              : {
    4395      4552416 :   struct cgraph_edge *e, *next;
    4396      8763252 :   for (e = node->callees; e; e = next)
    4397              :     {
    4398      4210836 :       ipa_predicate p;
    4399      4210836 :       next = e->next_callee;
    4400              : 
    4401      4210836 :       if (e->inline_failed)
    4402              :         {
    4403      3545279 :           class ipa_call_summary *es = ipa_call_summaries->get (e);
    4404      3545279 :           remap_edge_params (inlined_edge, e);
    4405              : 
    4406      3545279 :           if (es->predicate)
    4407              :             {
    4408      1205505 :               p = es->predicate->remap_after_inlining
    4409      1205505 :                                      (info, params_summary,
    4410              :                                       callee_info, operand_map,
    4411              :                                       offset_map, possible_truths,
    4412              :                                       *toplev_predicate);
    4413      1205505 :               edge_set_predicate (e, &p);
    4414              :             }
    4415              :           else
    4416      2339774 :             edge_set_predicate (e, toplev_predicate);
    4417              :         }
    4418              :       else
    4419       665557 :         remap_edge_summaries (inlined_edge, e->callee, info,
    4420              :                               params_summary, callee_info,
    4421              :                               operand_map, offset_map, possible_truths,
    4422              :                               toplev_predicate);
    4423              :     }
    4424      4656160 :   for (e = node->indirect_calls; e; e = next)
    4425              :     {
    4426       103744 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    4427       103744 :       ipa_predicate p;
    4428       103744 :       next = e->next_callee;
    4429              : 
    4430       103744 :       remap_edge_params (inlined_edge, e);
    4431       103744 :       if (es->predicate)
    4432              :         {
    4433        26359 :           p = es->predicate->remap_after_inlining
    4434        26359 :                                  (info, params_summary,
    4435              :                                   callee_info, operand_map, offset_map,
    4436              :                                   possible_truths, *toplev_predicate);
    4437        26359 :           edge_set_predicate (e, &p);
    4438              :         }
    4439              :       else
    4440        77385 :         edge_set_predicate (e, toplev_predicate);
    4441              :     }
    4442      4552416 : }
    4443              : 
    4444              : /* Run remap_after_inlining on each predicate in V.  */
    4445              : 
    4446              : static void
    4447      7773718 : remap_freqcounting_predicate (class ipa_fn_summary *info,
    4448              :                               class ipa_node_params *params_summary,
    4449              :                               class ipa_fn_summary *callee_info,
    4450              :                               vec<ipa_freqcounting_predicate, va_gc> *v,
    4451              :                               const vec<int> &operand_map,
    4452              :                               const vec<HOST_WIDE_INT> &offset_map,
    4453              :                               clause_t possible_truths,
    4454              :                               ipa_predicate *toplev_predicate)
    4455              : 
    4456              : {
    4457      7773718 :   ipa_freqcounting_predicate *fcp;
    4458      7800614 :   for (int i = 0; vec_safe_iterate (v, i, &fcp); i++)
    4459              :     {
    4460        26896 :       ipa_predicate p
    4461        26896 :         = fcp->predicate->remap_after_inlining (info, params_summary,
    4462              :                                                 callee_info, operand_map,
    4463              :                                                 offset_map, possible_truths,
    4464              :                                                 *toplev_predicate);
    4465        37601 :       if (p != false && p != true)
    4466         2763 :         *fcp->predicate &= p;
    4467              :     }
    4468      7773718 : }
    4469              : 
    4470              : /* We inlined EDGE.  Update summary of the function we inlined into.  */
    4471              : 
    4472              : void
    4473      3886859 : ipa_merge_fn_summary_after_inlining (struct cgraph_edge *edge)
    4474              : {
    4475      3886859 :   ipa_fn_summary *callee_info = ipa_fn_summaries->get (edge->callee);
    4476      3651678 :   struct cgraph_node *to = (edge->caller->inlined_to
    4477      3886859 :                             ? edge->caller->inlined_to : edge->caller);
    4478      3886859 :   class ipa_fn_summary *info = ipa_fn_summaries->get (to);
    4479      3886859 :   clause_t clause = 0;  /* not_inline is known to be false.  */
    4480      3886859 :   size_time_entry *e;
    4481      3886859 :   auto_vec<int, 8> operand_map;
    4482      3886859 :   auto_vec<HOST_WIDE_INT, 8> offset_map;
    4483      3886859 :   int i;
    4484      3886859 :   ipa_predicate toplev_predicate;
    4485      3886859 :   class ipa_call_summary *es = ipa_call_summaries->get (edge);
    4486      3886859 :   ipa_node_params *params_summary = (ipa_node_params_sum
    4487      3886859 :                                      ? ipa_node_params_sum->get (to) : NULL);
    4488              : 
    4489      3886859 :   if (es->predicate)
    4490       346317 :     toplev_predicate = *es->predicate;
    4491              :   else
    4492      3540542 :     toplev_predicate = true;
    4493              : 
    4494      3886859 :   info->fp_expressions |= callee_info->fp_expressions;
    4495      3886859 :   info->target_info |= callee_info->target_info;
    4496              : 
    4497      3886859 :   if (callee_info->conds)
    4498              :     {
    4499      2834886 :       ipa_auto_call_arg_values avals;
    4500      2834886 :       evaluate_properties_for_edge (edge, true, &clause, NULL, &avals, false);
    4501      2834886 :     }
    4502      3886859 :   if (ipa_node_params_sum && callee_info->conds)
    4503              :     {
    4504       764138 :       ipa_edge_args *args = ipa_edge_args_sum->get (edge);
    4505       764138 :       int count = args ? ipa_get_cs_argument_count (args) : 0;
    4506       763996 :       int i;
    4507              : 
    4508       763996 :       if (count)
    4509              :         {
    4510       763996 :           operand_map.safe_grow_cleared (count, true);
    4511       763996 :           offset_map.safe_grow_cleared (count, true);
    4512              :         }
    4513      2441731 :       for (i = 0; i < count; i++)
    4514              :         {
    4515      1677593 :           struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
    4516      1677593 :           int map = -1;
    4517              : 
    4518              :           /* TODO: handle non-NOPs when merging.  */
    4519      1677593 :           if (jfunc->type == IPA_JF_PASS_THROUGH)
    4520              :             {
    4521       287624 :               if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
    4522       284687 :                 map = ipa_get_jf_pass_through_formal_id (jfunc);
    4523       287624 :               if (!ipa_get_jf_pass_through_agg_preserved (jfunc))
    4524       191710 :                 offset_map[i] = -1;
    4525              :             }
    4526      1389969 :           else if (jfunc->type == IPA_JF_ANCESTOR)
    4527              :             {
    4528        86375 :               HOST_WIDE_INT offset = ipa_get_jf_ancestor_offset (jfunc);
    4529        86375 :               if (offset >= 0 && offset < INT_MAX)
    4530              :                 {
    4531        86375 :                   map = ipa_get_jf_ancestor_formal_id (jfunc);
    4532        86375 :                   if (!ipa_get_jf_ancestor_agg_preserved (jfunc))
    4533        51517 :                     offset = -1;
    4534        86375 :                   offset_map[i] = offset;
    4535              :                 }
    4536              :             }
    4537      1677593 :           operand_map[i] = map;
    4538      3038954 :           gcc_assert (map < ipa_get_param_count (params_summary));
    4539              :         }
    4540              : 
    4541              :       int ip;
    4542       766741 :       for (i = 0; callee_info->builtin_constant_p_parms.iterate (i, &ip); i++)
    4543         2603 :         if (ip < count && operand_map[ip] >= 0)
    4544           36 :           add_builtin_constant_p_parm (info, operand_map[ip]);
    4545              :     }
    4546      3886859 :   sreal freq = edge->sreal_frequency ();
    4547     21446955 :   for (i = 0; callee_info->size_time_table.iterate (i, &e); i++)
    4548              :     {
    4549     17560096 :       ipa_predicate p;
    4550     17560096 :       p = e->exec_predicate.remap_after_inlining
    4551     17560096 :                              (info, params_summary,
    4552              :                               callee_info, operand_map,
    4553              :                               offset_map, clause,
    4554              :                               toplev_predicate);
    4555     17560096 :       ipa_predicate nonconstp;
    4556     17560096 :       nonconstp = e->nonconst_predicate.remap_after_inlining
    4557     17560096 :                                      (info, params_summary,
    4558              :                                       callee_info, operand_map,
    4559              :                                       offset_map, clause,
    4560              :                                       toplev_predicate);
    4561     26477982 :       if (p != false && nonconstp != false)
    4562              :         {
    4563      8606821 :           sreal add_time = ((sreal)e->time * freq);
    4564      8606821 :           int prob = e->nonconst_predicate.probability (callee_info->conds,
    4565              :                                                         clause, es->param);
    4566      8606821 :           if (prob != REG_BR_PROB_BASE)
    4567      1075401 :             add_time = add_time * prob / REG_BR_PROB_BASE;
    4568      1075401 :           if (prob != REG_BR_PROB_BASE
    4569      1075401 :               && dump_file && (dump_flags & TDF_DETAILS))
    4570              :             {
    4571           13 :               fprintf (dump_file, "\t\tScaling time by probability:%f\n",
    4572           13 :                        (double) prob / REG_BR_PROB_BASE);
    4573              :             }
    4574      8606821 :           info->account_size_time (e->size, add_time, p, nonconstp);
    4575              :         }
    4576              :     }
    4577      3886859 :   remap_edge_summaries (edge, edge->callee, info, params_summary,
    4578              :                         callee_info, operand_map,
    4579              :                         offset_map, clause, &toplev_predicate);
    4580      3886859 :   remap_freqcounting_predicate (info, params_summary, callee_info,
    4581              :                                 info->loop_iterations, operand_map,
    4582              :                                 offset_map, clause, &toplev_predicate);
    4583      3886859 :   remap_freqcounting_predicate (info, params_summary, callee_info,
    4584              :                                 info->loop_strides, operand_map,
    4585              :                                 offset_map, clause, &toplev_predicate);
    4586              : 
    4587      3886859 :   HOST_WIDE_INT stack_frame_offset = ipa_get_stack_frame_offset (edge->callee);
    4588      3886859 :   HOST_WIDE_INT peak = stack_frame_offset + callee_info->estimated_stack_size;
    4589              : 
    4590      3886859 :   if (info->estimated_stack_size < peak)
    4591       125806 :     info->estimated_stack_size = peak;
    4592              : 
    4593      3886859 :   inline_update_callee_summaries (edge->callee, es->loop_depth);
    4594      3886859 :   if (info->call_size_time_table.length ())
    4595              :     {
    4596       822906 :       int edge_size = 0;
    4597       822906 :       sreal edge_time = 0;
    4598              : 
    4599       822906 :       estimate_edge_size_and_time (edge, &edge_size, NULL, &edge_time, NULL, 0);
    4600              :       /* Unaccount size and time of the optimized out call.  */
    4601       822906 :       info->account_size_time (-edge_size, -edge_time,
    4602       822906 :                                es->predicate ? *es->predicate : true,
    4603       822906 :                                es->predicate ? *es->predicate : true,
    4604              :                                true);
    4605              :       /* Account new calls.  */
    4606       822906 :       summarize_calls_size_and_time (edge->callee, info);
    4607              :     }
    4608              : 
    4609              :   /* Free summaries that are not maintained for inline clones/edges.  */
    4610      3886859 :   ipa_call_summaries->remove (edge);
    4611      3886859 :   ipa_fn_summaries->remove (edge->callee);
    4612      3886859 :   ipa_remove_from_growth_caches (edge);
    4613      3886859 : }
    4614              : 
    4615              : /* For performance reasons ipa_merge_fn_summary_after_inlining is not updating
    4616              :    overall size and time.  Recompute it.
    4617              :    If RESET is true also recompute call_time_size_table.  */
    4618              : 
    4619              : void
    4620      9287524 : ipa_update_overall_fn_summary (struct cgraph_node *node, bool reset)
    4621              : {
    4622      9287524 :   class ipa_fn_summary *info = ipa_fn_summaries->get (node);
    4623      9287524 :   class ipa_size_summary *size_info = ipa_size_summaries->get (node);
    4624      9287524 :   size_time_entry *e;
    4625      9287524 :   int i;
    4626              : 
    4627      9287524 :   size_info->size = 0;
    4628      9287524 :   info->time = 0;
    4629     47439095 :   for (i = 0; info->size_time_table.iterate (i, &e); i++)
    4630              :     {
    4631     38151571 :       size_info->size += e->size;
    4632     38151571 :       info->time += e->time;
    4633              :     }
    4634      9287524 :   info->min_size = info->size_time_table[0].size;
    4635      9287524 :   if (reset)
    4636      8423311 :     info->call_size_time_table.release ();
    4637      9287524 :   if (node->callees || node->indirect_calls)
    4638      7066352 :     estimate_calls_size_and_time (node, &size_info->size, &info->min_size,
    4639              :                                   &info->time, NULL,
    4640              :                                   ~(clause_t) (1 << ipa_predicate::false_condition),
    4641              :                                   NULL);
    4642      9287524 :   size_info->size = RDIV (size_info->size, ipa_fn_summary::size_scale);
    4643      9287524 :   info->min_size = RDIV (info->min_size, ipa_fn_summary::size_scale);
    4644      9287524 : }
    4645              : 
    4646              : 
    4647              : /* This function performs intraprocedural analysis in NODE that is required to
    4648              :    inline indirect calls.  */
    4649              : 
    4650              : static void
    4651      1366444 : inline_indirect_intraprocedural_analysis (struct cgraph_node *node)
    4652              : {
    4653      1366444 :   ipa_analyze_node (node);
    4654      1366444 :   if (dump_file && (dump_flags & TDF_DETAILS))
    4655              :     {
    4656           14 :       ipa_print_node_params (dump_file, node);
    4657           14 :       ipa_print_node_jump_functions (dump_file, node);
    4658              :     }
    4659      1366444 : }
    4660              : 
    4661              : 
    4662              : /* Note function body size.  */
    4663              : 
    4664              : void
    4665      1377053 : inline_analyze_function (struct cgraph_node *node)
    4666              : {
    4667      1377053 :   push_cfun (DECL_STRUCT_FUNCTION (node->decl));
    4668              : 
    4669      1377053 :   if (dump_file)
    4670           94 :     fprintf (dump_file, "\nAnalyzing function: %s\n", node->dump_name ());
    4671      1377053 :   if (opt_for_fn (node->decl, optimize) && !node->thunk)
    4672      1366444 :     inline_indirect_intraprocedural_analysis (node);
    4673      1377053 :   compute_fn_summary (node, false);
    4674      1377053 :   if (!optimize)
    4675              :     {
    4676         9337 :       struct cgraph_edge *e;
    4677        22058 :       for (e = node->callees; e; e = e->next_callee)
    4678        12721 :         e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
    4679         9408 :       for (e = node->indirect_calls; e; e = e->next_callee)
    4680           71 :         e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
    4681              :     }
    4682              : 
    4683      1377053 :   pop_cfun ();
    4684      1377053 : }
    4685              : 
    4686              : 
    4687              : /* Called when new function is inserted to callgraph late.  */
    4688              : 
    4689              : void
    4690        19208 : ipa_fn_summary_t::insert (struct cgraph_node *node, ipa_fn_summary *)
    4691              : {
    4692        19208 :   inline_analyze_function (node);
    4693        19208 : }
    4694              : 
    4695              : /* Note function body size.  */
    4696              : 
    4697              : static void
    4698       231958 : ipa_fn_summary_generate (void)
    4699              : {
    4700       231958 :   struct cgraph_node *node;
    4701              : 
    4702      2089840 :   FOR_EACH_DEFINED_FUNCTION (node)
    4703      1857882 :     if (DECL_STRUCT_FUNCTION (node->decl))
    4704      1844727 :       node->versionable = tree_versionable_function_p (node->decl);
    4705              : 
    4706       231958 :   ipa_fn_summary_alloc ();
    4707              : 
    4708       231958 :   ipa_fn_summaries->enable_insertion_hook ();
    4709              : 
    4710       231958 :   ipa_register_cgraph_hooks ();
    4711              : 
    4712      2089840 :   FOR_EACH_DEFINED_FUNCTION (node)
    4713      1857882 :     if (!node->alias
    4714      1857882 :         && (flag_generate_lto || flag_generate_offload|| flag_wpa
    4715      1669143 :             || opt_for_fn (node->decl, optimize)))
    4716      1339771 :       inline_analyze_function (node);
    4717       231958 : }
    4718              : 
    4719              : 
    4720              : /* Write inline summary for edge E to OB.  */
    4721              : 
    4722              : static void
    4723       347069 : read_ipa_call_summary (class lto_input_block *ib, struct cgraph_edge *e,
    4724              :                        bool prevails)
    4725              : {
    4726       347069 :   class ipa_call_summary *es = prevails
    4727       347069 :                                 ? ipa_call_summaries->get_create (e) : NULL;
    4728       347069 :   ipa_predicate p;
    4729       347069 :   int length, i;
    4730              : 
    4731       347069 :   int size = streamer_read_uhwi (ib);
    4732       347069 :   int time = streamer_read_uhwi (ib);
    4733       347069 :   int depth = streamer_read_uhwi (ib);
    4734              : 
    4735       347069 :   if (es)
    4736              :     {
    4737       347020 :       es->call_stmt_size = size;
    4738       347020 :       es->call_stmt_time = time;
    4739       347020 :       es->loop_depth = depth;
    4740              :     }
    4741              : 
    4742       347069 :   bitpack_d bp = streamer_read_bitpack (ib);
    4743       347069 :   if (es)
    4744       347020 :     es->is_return_callee_uncaptured = bp_unpack_value (&bp, 1);
    4745              :   else
    4746           49 :     bp_unpack_value (&bp, 1);
    4747              : 
    4748       347069 :   p.stream_in (ib);
    4749       347069 :   if (es)
    4750       347020 :     edge_set_predicate (e, &p);
    4751       347069 :   length = streamer_read_uhwi (ib);
    4752       347069 :   if (length && es
    4753       347069 :       && (e->possibly_call_in_translation_unit_p ()
    4754              :           /* Also stream in jump functions to builtins in hope that they
    4755              :              will get fnspecs.  */
    4756       118706 :           || fndecl_built_in_p (e->callee->decl, BUILT_IN_NORMAL)))
    4757              :     {
    4758       232215 :       es->param.safe_grow_cleared (length, true);
    4759       799402 :       for (i = 0; i < length; i++)
    4760              :         {
    4761       567187 :           es->param[i].change_prob = streamer_read_uhwi (ib);
    4762       567187 :           bitpack_d bp = streamer_read_bitpack (ib);
    4763      1701561 :           es->param[i].points_to_local_or_readonly_memory
    4764       567187 :             = bp_unpack_value (&bp, 1);
    4765      1701561 :           es->param[i].points_to_possible_sra_candidate
    4766       567187 :             = bp_unpack_value (&bp, 1);
    4767              :         }
    4768              :     }
    4769              :   else
    4770              :     {
    4771       137540 :       for (i = 0; i < length; i++)
    4772              :         {
    4773        22686 :           streamer_read_uhwi (ib);
    4774        22686 :           streamer_read_uhwi (ib);
    4775              :         }
    4776              :     }
    4777       347069 : }
    4778              : 
    4779              : 
    4780              : /* Stream in inline summaries from the section.  */
    4781              : 
    4782              : static void
    4783        13266 : inline_read_section (struct lto_file_decl_data *file_data, const char *data,
    4784              :                      size_t len)
    4785              : {
    4786        13266 :   const struct lto_function_header *header =
    4787              :     (const struct lto_function_header *) data;
    4788        13266 :   const int cfg_offset = sizeof (struct lto_function_header);
    4789        13266 :   const int main_offset = cfg_offset + header->cfg_size;
    4790        13266 :   const int string_offset = main_offset + header->main_size;
    4791        13266 :   class data_in *data_in;
    4792        13266 :   unsigned int i, count2, j;
    4793        13266 :   unsigned int f_count;
    4794              : 
    4795        13266 :   lto_input_block ib ((const char *) data + main_offset, header->main_size,
    4796        13266 :                       file_data);
    4797              : 
    4798        13266 :   data_in =
    4799        26532 :     lto_data_in_create (file_data, (const char *) data + string_offset,
    4800        13266 :                         header->string_size, vNULL);
    4801        13266 :   f_count = streamer_read_uhwi (&ib);
    4802        99243 :   for (i = 0; i < f_count; i++)
    4803              :     {
    4804        85977 :       unsigned int index;
    4805        85977 :       struct cgraph_node *node;
    4806        85977 :       class ipa_fn_summary *info;
    4807        85977 :       class ipa_node_params *params_summary;
    4808        85977 :       class ipa_size_summary *size_info;
    4809        85977 :       lto_symtab_encoder_t encoder;
    4810        85977 :       struct bitpack_d bp;
    4811        85977 :       struct cgraph_edge *e;
    4812        85977 :       ipa_predicate p;
    4813              : 
    4814        85977 :       index = streamer_read_uhwi (&ib);
    4815        85977 :       encoder = file_data->symtab_node_encoder;
    4816        85977 :       node = dyn_cast<cgraph_node *> (lto_symtab_encoder_deref (encoder,
    4817              :                                                                 index));
    4818        85977 :       info = node->prevailing_p () ? ipa_fn_summaries->get_create (node) : NULL;
    4819        85977 :       params_summary = node->prevailing_p ()
    4820        85977 :                        ? ipa_node_params_sum->get (node) : NULL;
    4821        85977 :       size_info = node->prevailing_p ()
    4822        85977 :                   ? ipa_size_summaries->get_create (node) : NULL;
    4823              : 
    4824        85977 :       int stack_size = streamer_read_uhwi (&ib);
    4825        85977 :       int size = streamer_read_uhwi (&ib);
    4826        85977 :       sreal time = sreal::stream_in (&ib);
    4827              : 
    4828        85977 :       if (info)
    4829              :         {
    4830        85919 :           info->estimated_stack_size
    4831        85919 :             = size_info->estimated_self_stack_size = stack_size;
    4832        85919 :           size_info->size = size_info->self_size = size;
    4833        85919 :           info->time = time;
    4834              :         }
    4835              : 
    4836        85977 :       bp = streamer_read_bitpack (&ib);
    4837        85977 :       if (info)
    4838              :         {
    4839        85919 :           info->inlinable = bp_unpack_value (&bp, 1);
    4840        85919 :           info->fp_expressions = bp_unpack_value (&bp, 1);
    4841        85919 :           if (!lto_stream_offload_p)
    4842        85919 :             info->target_info = streamer_read_uhwi (&ib);
    4843              :         }
    4844              :       else
    4845              :         {
    4846           58 :           bp_unpack_value (&bp, 1);
    4847           58 :           bp_unpack_value (&bp, 1);
    4848           58 :           if (!lto_stream_offload_p)
    4849           58 :             streamer_read_uhwi (&ib);
    4850              :         }
    4851              : 
    4852        85977 :       count2 = streamer_read_uhwi (&ib);
    4853        85977 :       gcc_assert (!info || !info->conds);
    4854        85919 :       if (info)
    4855        85919 :         vec_safe_reserve_exact (info->conds, count2);
    4856       162832 :       for (j = 0; j < count2; j++)
    4857              :         {
    4858        76855 :           struct condition c;
    4859        76855 :           unsigned int k, count3;
    4860        76855 :           c.operand_num = streamer_read_uhwi (&ib);
    4861        76855 :           c.code = (enum tree_code) streamer_read_uhwi (&ib);
    4862        76855 :           c.type = stream_read_tree (&ib, data_in);
    4863        76855 :           c.val = stream_read_tree (&ib, data_in);
    4864        76855 :           bp = streamer_read_bitpack (&ib);
    4865        76855 :           c.agg_contents = bp_unpack_value (&bp, 1);
    4866        76855 :           c.by_ref = bp_unpack_value (&bp, 1);
    4867        76855 :           if (c.agg_contents)
    4868        12451 :             c.offset = streamer_read_uhwi (&ib);
    4869        76855 :           count3 = streamer_read_uhwi (&ib);
    4870        76855 :           c.param_ops = NULL;
    4871        76855 :           if (info)
    4872        76855 :             vec_safe_reserve_exact (c.param_ops, count3);
    4873        76855 :           if (params_summary)
    4874        76855 :             ipa_set_param_used_by_ipa_predicates
    4875        76855 :                     (params_summary, c.operand_num, true);
    4876        80361 :           for (k = 0; k < count3; k++)
    4877              :             {
    4878         3506 :               struct expr_eval_op op;
    4879         3506 :               enum gimple_rhs_class rhs_class;
    4880         3506 :               op.code = (enum tree_code) streamer_read_uhwi (&ib);
    4881         3506 :               op.type = stream_read_tree (&ib, data_in);
    4882         3506 :               switch (rhs_class = get_gimple_rhs_class (op.code))
    4883              :                 {
    4884         1401 :                 case GIMPLE_UNARY_RHS:
    4885         1401 :                   op.index = 0;
    4886         1401 :                   op.val[0] = NULL_TREE;
    4887         1401 :                   op.val[1] = NULL_TREE;
    4888         1401 :                   break;
    4889              : 
    4890         2105 :                 case GIMPLE_BINARY_RHS:
    4891         2105 :                 case GIMPLE_TERNARY_RHS:
    4892         2105 :                   bp = streamer_read_bitpack (&ib);
    4893         2105 :                   op.index = bp_unpack_value (&bp, 2);
    4894         2105 :                   op.val[0] = stream_read_tree (&ib, data_in);
    4895         2105 :                   if (rhs_class == GIMPLE_BINARY_RHS)
    4896         2105 :                     op.val[1] = NULL_TREE;
    4897              :                   else
    4898            0 :                     op.val[1] = stream_read_tree (&ib, data_in);
    4899              :                   break;
    4900              : 
    4901            0 :                 default:
    4902            0 :                   fatal_error (UNKNOWN_LOCATION,
    4903              :                                "invalid fnsummary in LTO stream");
    4904              :                 }
    4905         3506 :               if (info)
    4906         3506 :                 c.param_ops->quick_push (op);
    4907              :             }
    4908        76855 :           if (info)
    4909        76855 :             info->conds->quick_push (c);
    4910              :         }
    4911        85977 :       count2 = streamer_read_uhwi (&ib);
    4912        85977 :       gcc_assert (!info || !info->size_time_table.length ());
    4913        85977 :       if (info && count2)
    4914        85919 :         info->size_time_table.reserve_exact (count2);
    4915       326815 :       for (j = 0; j < count2; j++)
    4916              :         {
    4917       240838 :           class size_time_entry e;
    4918              : 
    4919       240838 :           e.size = streamer_read_uhwi (&ib);
    4920       240838 :           e.time = sreal::stream_in (&ib);
    4921       240838 :           e.exec_predicate.stream_in (&ib);
    4922       240838 :           e.nonconst_predicate.stream_in (&ib);
    4923              : 
    4924       240838 :           if (info)
    4925       240722 :             info->size_time_table.quick_push (e);
    4926              :         }
    4927              : 
    4928        85977 :       count2 = streamer_read_uhwi (&ib);
    4929        87323 :       for (j = 0; j < count2; j++)
    4930              :         {
    4931         1346 :           p.stream_in (&ib);
    4932         1346 :           sreal fcp_freq = sreal::stream_in (&ib);
    4933         1346 :           if (info)
    4934              :             {
    4935         1346 :               ipa_freqcounting_predicate fcp;
    4936         1346 :               fcp.predicate = NULL;
    4937         1346 :               set_hint_predicate (&fcp.predicate, p);
    4938         1346 :               fcp.freq = fcp_freq;
    4939         1346 :               vec_safe_push (info->loop_iterations, fcp);
    4940              :             }
    4941              :         }
    4942        85977 :       count2 = streamer_read_uhwi (&ib);
    4943        86264 :       for (j = 0; j < count2; j++)
    4944              :         {
    4945          287 :           p.stream_in (&ib);
    4946          287 :           sreal fcp_freq = sreal::stream_in (&ib);
    4947          287 :           if (info)
    4948              :             {
    4949          287 :               ipa_freqcounting_predicate fcp;
    4950          287 :               fcp.predicate = NULL;
    4951          287 :               set_hint_predicate (&fcp.predicate, p);
    4952          287 :               fcp.freq = fcp_freq;
    4953          287 :               vec_safe_push (info->loop_strides, fcp);
    4954              :             }
    4955              :         }
    4956        85977 :       count2 = streamer_read_uhwi (&ib);
    4957        85977 :       if (info && count2)
    4958            6 :         info->builtin_constant_p_parms.reserve_exact (count2);
    4959        85983 :       for (j = 0; j < count2; j++)
    4960              :         {
    4961            6 :           int parm = streamer_read_uhwi (&ib);
    4962            6 :           if (info)
    4963            6 :             info->builtin_constant_p_parms.quick_push (parm);
    4964              :         }
    4965       431568 :       for (e = node->callees; e; e = e->next_callee)
    4966       345591 :         read_ipa_call_summary (&ib, e, info != NULL);
    4967        87455 :       for (e = node->indirect_calls; e; e = e->next_callee)
    4968         1478 :         read_ipa_call_summary (&ib, e, info != NULL);
    4969              :     }
    4970              : 
    4971        13266 :   lto_free_section_data (file_data, LTO_section_ipa_fn_summary, NULL, data,
    4972              :                          len);
    4973        13266 :   lto_data_in_delete (data_in);
    4974        13266 : }
    4975              : 
    4976              : 
    4977              : /* Read inline summary.  Jump functions are shared among ipa-cp
    4978              :    and inliner, so when ipa-cp is active, we don't need to write them
    4979              :    twice.  */
    4980              : 
    4981              : static void
    4982        12211 : ipa_fn_summary_read (void)
    4983              : {
    4984        12211 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    4985        12211 :   struct lto_file_decl_data *file_data;
    4986        12211 :   unsigned int j = 0;
    4987              : 
    4988        12211 :   ipa_prop_read_jump_functions ();
    4989        12211 :   ipa_fn_summary_alloc ();
    4990              : 
    4991        37688 :   while ((file_data = file_data_vec[j++]))
    4992              :     {
    4993        13266 :       size_t len;
    4994        13266 :       const char *data
    4995        13266 :         = lto_get_summary_section_data (file_data, LTO_section_ipa_fn_summary,
    4996              :                                         &len);
    4997        13266 :       if (data)
    4998        13266 :         inline_read_section (file_data, data, len);
    4999              :       else
    5000              :         /* Fatal error here.  We do not want to support compiling ltrans units
    5001              :            with different version of compiler or different flags than the WPA
    5002              :            unit, so this should never happen.  */
    5003            0 :         fatal_error (input_location,
    5004              :                      "ipa inline summary is missing in input file");
    5005              :     }
    5006        12211 :   ipa_register_cgraph_hooks ();
    5007              : 
    5008        12211 :   gcc_assert (ipa_fn_summaries);
    5009        12211 :   ipa_fn_summaries->enable_insertion_hook ();
    5010        12211 : }
    5011              : 
    5012              : 
    5013              : /* Write inline summary for edge E to OB.  */
    5014              : 
    5015              : static void
    5016       378474 : write_ipa_call_summary (struct output_block *ob, struct cgraph_edge *e)
    5017              : {
    5018       378474 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
    5019       378474 :   int i;
    5020              : 
    5021       378474 :   streamer_write_uhwi (ob, es->call_stmt_size);
    5022       378474 :   streamer_write_uhwi (ob, es->call_stmt_time);
    5023       378474 :   streamer_write_uhwi (ob, es->loop_depth);
    5024              : 
    5025       378474 :   bitpack_d bp = bitpack_create (ob->main_stream);
    5026       378474 :   bp_pack_value (&bp, es->is_return_callee_uncaptured, 1);
    5027       378474 :   streamer_write_bitpack (&bp);
    5028              : 
    5029       378474 :   if (es->predicate)
    5030        10565 :     es->predicate->stream_out (ob);
    5031              :   else
    5032       367909 :     streamer_write_uhwi (ob, 0);
    5033       378474 :   streamer_write_uhwi (ob, es->param.length ());
    5034      2284857 :   for (i = 0; i < (int) es->param.length (); i++)
    5035              :     {
    5036       630141 :       streamer_write_uhwi (ob, es->param[i].change_prob);
    5037       630141 :       bp = bitpack_create (ob->main_stream);
    5038       630141 :       bp_pack_value (&bp, es->param[i].points_to_local_or_readonly_memory, 1);
    5039       630141 :       bp_pack_value (&bp, es->param[i].points_to_possible_sra_candidate, 1);
    5040       630141 :       streamer_write_bitpack (&bp);
    5041              :     }
    5042       378474 : }
    5043              : 
    5044              : 
    5045              : /* Write inline summary for node in SET.
    5046              :    Jump functions are shared among ipa-cp and inliner, so when ipa-cp is
    5047              :    active, we don't need to write them twice.  */
    5048              : 
    5049              : static void
    5050        22999 : ipa_fn_summary_write (void)
    5051              : {
    5052        22999 :   struct output_block *ob = create_output_block (LTO_section_ipa_fn_summary);
    5053        22999 :   lto_symtab_encoder_iterator lsei;
    5054        22999 :   lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
    5055        22999 :   unsigned int count = 0;
    5056              : 
    5057       127664 :   for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
    5058       104665 :        lsei_next_function_in_partition (&lsei))
    5059              :     {
    5060       104665 :       cgraph_node *cnode = lsei_cgraph_node (lsei);
    5061       104665 :       if (cnode->definition && !cnode->alias)
    5062       102232 :         count++;
    5063              :     }
    5064        22999 :   streamer_write_uhwi (ob, count);
    5065              : 
    5066       127664 :   for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
    5067       104665 :        lsei_next_function_in_partition (&lsei))
    5068              :     {
    5069       104665 :       cgraph_node *cnode = lsei_cgraph_node (lsei);
    5070       104665 :       if (cnode->definition && !cnode->alias)
    5071              :         {
    5072       102232 :           class ipa_fn_summary *info = ipa_fn_summaries->get (cnode);
    5073       102232 :           class ipa_size_summary *size_info = ipa_size_summaries->get (cnode);
    5074       102232 :           struct bitpack_d bp;
    5075       102232 :           struct cgraph_edge *edge;
    5076       102232 :           int i;
    5077       102232 :           size_time_entry *e;
    5078       102232 :           struct condition *c;
    5079              : 
    5080       102232 :           streamer_write_uhwi (ob, lto_symtab_encoder_encode (encoder, cnode));
    5081       102232 :           streamer_write_hwi (ob, size_info->estimated_self_stack_size);
    5082       102232 :           streamer_write_hwi (ob, size_info->self_size);
    5083       102232 :           info->time.stream_out (ob);
    5084       102232 :           bp = bitpack_create (ob->main_stream);
    5085       102232 :           bp_pack_value (&bp, info->inlinable, 1);
    5086       102232 :           bp_pack_value (&bp, info->fp_expressions, 1);
    5087       102232 :           streamer_write_bitpack (&bp);
    5088       102232 :           if (!lto_stream_offload_p)
    5089       102232 :             streamer_write_uhwi (ob, info->target_info);
    5090       102232 :           streamer_write_uhwi (ob, vec_safe_length (info->conds));
    5091       194698 :           for (i = 0; vec_safe_iterate (info->conds, i, &c); i++)
    5092              :             {
    5093        92466 :               int j;
    5094        92466 :               struct expr_eval_op *op;
    5095              : 
    5096        92466 :               streamer_write_uhwi (ob, c->operand_num);
    5097        92466 :               streamer_write_uhwi (ob, c->code);
    5098        92466 :               stream_write_tree (ob, c->type, true);
    5099        92466 :               stream_write_tree (ob, c->val, true);
    5100        92466 :               bp = bitpack_create (ob->main_stream);
    5101        92466 :               bp_pack_value (&bp, c->agg_contents, 1);
    5102        92466 :               bp_pack_value (&bp, c->by_ref, 1);
    5103        92466 :               streamer_write_bitpack (&bp);
    5104        92466 :               if (c->agg_contents)
    5105        15610 :                 streamer_write_uhwi (ob, c->offset);
    5106        92466 :               streamer_write_uhwi (ob, vec_safe_length (c->param_ops));
    5107       191907 :               for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
    5108              :                 {
    5109         4080 :                   streamer_write_uhwi (ob, op->code);
    5110         4080 :                   stream_write_tree (ob, op->type, true);
    5111         4080 :                   if (op->val[0])
    5112              :                     {
    5113         2466 :                       bp = bitpack_create (ob->main_stream);
    5114         2466 :                       bp_pack_value (&bp, op->index, 2);
    5115         2466 :                       streamer_write_bitpack (&bp);
    5116         2466 :                       stream_write_tree (ob, op->val[0], true);
    5117         2466 :                       if (op->val[1])
    5118            4 :                         stream_write_tree (ob, op->val[1], true);
    5119              :                     }
    5120              :                 }
    5121              :             }
    5122       102232 :           streamer_write_uhwi (ob, info->size_time_table.length ());
    5123       494321 :           for (i = 0; info->size_time_table.iterate (i, &e); i++)
    5124              :             {
    5125       289857 :               streamer_write_uhwi (ob, e->size);
    5126       289857 :               e->time.stream_out (ob);
    5127       289857 :               e->exec_predicate.stream_out (ob);
    5128       289857 :               e->nonconst_predicate.stream_out (ob);
    5129              :             }
    5130       102232 :           ipa_freqcounting_predicate *fcp;
    5131       102232 :           streamer_write_uhwi (ob, vec_safe_length (info->loop_iterations));
    5132       206434 :           for (i = 0; vec_safe_iterate (info->loop_iterations, i, &fcp); i++)
    5133              :             {
    5134         1970 :               fcp->predicate->stream_out (ob);
    5135         1970 :               fcp->freq.stream_out (ob);
    5136              :             }
    5137       102232 :           streamer_write_uhwi (ob, vec_safe_length (info->loop_strides));
    5138       204803 :           for (i = 0; vec_safe_iterate (info->loop_strides, i, &fcp); i++)
    5139              :             {
    5140          339 :               fcp->predicate->stream_out (ob);
    5141          339 :               fcp->freq.stream_out (ob);
    5142              :             }
    5143       102232 :           streamer_write_uhwi (ob, info->builtin_constant_p_parms.length ());
    5144       102232 :           int ip;
    5145       204478 :           for (i = 0; info->builtin_constant_p_parms.iterate (i, &ip);
    5146              :                i++)
    5147           14 :             streamer_write_uhwi (ob, ip);
    5148       478024 :           for (edge = cnode->callees; edge; edge = edge->next_callee)
    5149       375792 :             write_ipa_call_summary (ob, edge);
    5150       104914 :           for (edge = cnode->indirect_calls; edge; edge = edge->next_callee)
    5151         2682 :             write_ipa_call_summary (ob, edge);
    5152              :         }
    5153              :     }
    5154        22999 :   streamer_write_char_stream (ob->main_stream, 0);
    5155        22999 :   produce_asm (ob);
    5156        22999 :   destroy_output_block (ob);
    5157              : 
    5158        22999 :   ipa_prop_write_jump_functions ();
    5159        22999 : }
    5160              : 
    5161              : 
    5162              : /* Release function summary.  */
    5163              : 
    5164              : void
    5165       724005 : ipa_free_fn_summary (void)
    5166              : {
    5167       724005 :   if (!ipa_call_summaries)
    5168              :     return;
    5169       458489 :   ggc_delete (ipa_fn_summaries);
    5170       458489 :   ipa_fn_summaries = NULL;
    5171       458489 :   delete ipa_call_summaries;
    5172       458489 :   ipa_call_summaries = NULL;
    5173       458489 :   edge_predicate_pool.release ();
    5174              :   /* During IPA this is one of largest datastructures to release.  */
    5175       458489 :   if (flag_wpa)
    5176         7815 :     ggc_trim ();
    5177              : }
    5178              : 
    5179              : /* Release function summary.  */
    5180              : 
    5181              : void
    5182       724005 : ipa_free_size_summary (void)
    5183              : {
    5184       724005 :   if (!ipa_size_summaries)
    5185              :     return;
    5186       458489 :   delete ipa_size_summaries;
    5187       458489 :   ipa_size_summaries = NULL;
    5188              : }
    5189              : 
    5190              : namespace {
    5191              : 
    5192              : const pass_data pass_data_local_fn_summary =
    5193              : {
    5194              :   GIMPLE_PASS, /* type */
    5195              :   "local-fnsummary", /* name */
    5196              :   OPTGROUP_INLINE, /* optinfo_flags */
    5197              :   TV_INLINE_PARAMETERS, /* tv_id */
    5198              :   0, /* properties_required */
    5199              :   0, /* properties_provided */
    5200              :   0, /* properties_destroyed */
    5201              :   0, /* todo_flags_start */
    5202              :   0, /* todo_flags_finish */
    5203              : };
    5204              : 
    5205              : class pass_local_fn_summary : public gimple_opt_pass
    5206              : {
    5207              : public:
    5208       575744 :   pass_local_fn_summary (gcc::context *ctxt)
    5209      1151488 :     : gimple_opt_pass (pass_data_local_fn_summary, ctxt)
    5210              :   {}
    5211              : 
    5212              :   /* opt_pass methods: */
    5213       287872 :   opt_pass * clone () final override
    5214              :   {
    5215       287872 :     return new pass_local_fn_summary (m_ctxt);
    5216              :   }
    5217      5706041 :   unsigned int execute (function *) final override
    5218              :     {
    5219      5706041 :       return compute_fn_summary_for_current ();
    5220              :     }
    5221              : 
    5222              : }; // class pass_local_fn_summary
    5223              : 
    5224              : } // anon namespace
    5225              : 
    5226              : gimple_opt_pass *
    5227       287872 : make_pass_local_fn_summary (gcc::context *ctxt)
    5228              : {
    5229       287872 :   return new pass_local_fn_summary (ctxt);
    5230              : }
    5231              : 
    5232              : 
    5233              : /* Free inline summary.  */
    5234              : 
    5235              : namespace {
    5236              : 
    5237              : const pass_data pass_data_ipa_free_fn_summary =
    5238              : {
    5239              :   SIMPLE_IPA_PASS, /* type */
    5240              :   "free-fnsummary", /* name */
    5241              :   OPTGROUP_NONE, /* optinfo_flags */
    5242              :   TV_IPA_FREE_INLINE_SUMMARY, /* tv_id */
    5243              :   0, /* properties_required */
    5244              :   0, /* properties_provided */
    5245              :   0, /* properties_destroyed */
    5246              :   0, /* todo_flags_start */
    5247              :   0, /* todo_flags_finish */
    5248              : };
    5249              : 
    5250              : class pass_ipa_free_fn_summary : public simple_ipa_opt_pass
    5251              : {
    5252              : public:
    5253       575744 :   pass_ipa_free_fn_summary (gcc::context *ctxt)
    5254       575744 :     : simple_ipa_opt_pass (pass_data_ipa_free_fn_summary, ctxt),
    5255      1151488 :       small_p (false)
    5256              :   {}
    5257              : 
    5258              :   /* opt_pass methods: */
    5259       287872 :   opt_pass *clone () final override
    5260              :   {
    5261       287872 :     return new pass_ipa_free_fn_summary (m_ctxt);
    5262              :   }
    5263       575744 :   void set_pass_param (unsigned int n, bool param) final override
    5264              :     {
    5265       575744 :       gcc_assert (n == 0);
    5266       575744 :       small_p = param;
    5267       575744 :     }
    5268       484798 :   bool gate (function *) final override { return true; }
    5269       464387 :   unsigned int execute (function *) final override
    5270              :     {
    5271       464387 :       ipa_free_fn_summary ();
    5272              :       /* Free ipa-prop structures if they are no longer needed.  */
    5273       464387 :       ipa_free_all_structures_after_iinln ();
    5274       464387 :       if (!flag_wpa)
    5275       456572 :         ipa_free_size_summary ();
    5276       464387 :       return 0;
    5277              :     }
    5278              : 
    5279              : private:
    5280              :   bool small_p;
    5281              : }; // class pass_ipa_free_fn_summary
    5282              : 
    5283              : } // anon namespace
    5284              : 
    5285              : simple_ipa_opt_pass *
    5286       287872 : make_pass_ipa_free_fn_summary (gcc::context *ctxt)
    5287              : {
    5288       287872 :   return new pass_ipa_free_fn_summary (ctxt);
    5289              : }
    5290              : 
    5291              : namespace {
    5292              : 
    5293              : const pass_data pass_data_ipa_fn_summary =
    5294              : {
    5295              :   IPA_PASS, /* type */
    5296              :   "fnsummary", /* name */
    5297              :   OPTGROUP_INLINE, /* optinfo_flags */
    5298              :   TV_IPA_FNSUMMARY, /* tv_id */
    5299              :   0, /* properties_required */
    5300              :   0, /* properties_provided */
    5301              :   0, /* properties_destroyed */
    5302              :   0, /* todo_flags_start */
    5303              :   ( TODO_dump_symtab ), /* todo_flags_finish */
    5304              : };
    5305              : 
    5306              : class pass_ipa_fn_summary : public ipa_opt_pass_d
    5307              : {
    5308              : public:
    5309       287872 :   pass_ipa_fn_summary (gcc::context *ctxt)
    5310              :     : ipa_opt_pass_d (pass_data_ipa_fn_summary, ctxt,
    5311              :                       ipa_fn_summary_generate, /* generate_summary */
    5312              :                       ipa_fn_summary_write, /* write_summary */
    5313              :                       ipa_fn_summary_read, /* read_summary */
    5314              :                       NULL, /* write_optimization_summary */
    5315              :                       NULL, /* read_optimization_summary */
    5316              :                       NULL, /* stmt_fixup */
    5317              :                       0, /* function_transform_todo_flags_start */
    5318              :                       NULL, /* function_transform */
    5319       287872 :                       NULL) /* variable_transform */
    5320       287872 :   {}
    5321              : 
    5322              :   /* opt_pass methods: */
    5323       232280 :   unsigned int execute (function *) final override { return 0; }
    5324              : 
    5325              : }; // class pass_ipa_fn_summary
    5326              : 
    5327              : } // anon namespace
    5328              : 
    5329              : ipa_opt_pass_d *
    5330       287872 : make_pass_ipa_fn_summary (gcc::context *ctxt)
    5331              : {
    5332       287872 :   return new pass_ipa_fn_summary (ctxt);
    5333              : }
    5334              : 
    5335              : /* Reset all state within ipa-fnsummary.cc so that we can rerun the compiler
    5336              :    within the same process.  For use by toplev::finalize.  */
    5337              : 
    5338              : void
    5339       258766 : ipa_fnsummary_cc_finalize (void)
    5340              : {
    5341       258766 :   ipa_free_fn_summary ();
    5342       258766 :   ipa_free_size_summary ();
    5343       258766 : }
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.