LCOV - code coverage report
Current view: top level - gcc - ipa-fnsummary.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.6 % 2675 2583
Test Date: 2026-10-17 16:30:31 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    140012569 : 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    140012569 :   size_time_entry *e;
     173    140012569 :   bool found = false;
     174    140012569 :   int i;
     175    140012569 :   ipa_predicate nonconst_pred;
     176    140012569 :   vec<size_time_entry> *table = call ? &call_size_time_table : &size_time_table;
     177              : 
     178    140012569 :   if (exec_pred == false)
     179      5180643 :     return;
     180              : 
     181    139710955 :   nonconst_pred = nonconst_pred_in & exec_pred;
     182              : 
     183    139710955 :   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    164090039 :   if (!size && time == 0 && table->length ())
     189      4113729 :     return;
     190              : 
     191              :   /* Only for calls we are unaccounting what we previously recorded.  */
     192    134831926 :   gcc_checking_assert (time >= 0 || call);
     193              : 
     194    488884316 :   for (i = 0; table->iterate (i, &e); i++)
     195    458274118 :     if (e->exec_predicate == exec_pred
     196    458274118 :         && e->nonconst_predicate == nonconst_pred)
     197              :       {
     198              :         found = true;
     199              :         break;
     200              :       }
     201    134831926 :   if (i == max_size_time_table_size)
     202              :     {
     203         4896 :       i = 0;
     204         4896 :       found = true;
     205         4896 :       e = &(*table)[0];
     206         4896 :       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    134836163 :   if (dump_file && (dump_flags & TDF_DETAILS) && (time != 0 || size))
     212              :     {
     213         3963 :       fprintf (dump_file,
     214              :                "\t\tAccounting size:%3.2f, time:%3.2f on %spredicate exec:",
     215         3730 :                ((double) size) / ipa_fn_summary::size_scale,
     216              :                (time.to_double ()), found ? "" : "new ");
     217         3730 :       exec_pred.dump (dump_file, conds, 0);
     218         3730 :       if (exec_pred != nonconst_pred)
     219              :         {
     220           84 :           fprintf (dump_file, " nonconst:");
     221           84 :           nonconst_pred.dump (dump_file, conds);
     222              :         }
     223              :       else
     224         3646 :         fprintf (dump_file, "\n");
     225              :     }
     226    134831926 :   if (!found)
     227              :     {
     228     30605302 :       class size_time_entry new_entry;
     229     30605302 :       new_entry.size = size;
     230     30605302 :       new_entry.time = time;
     231     30605302 :       new_entry.exec_predicate = exec_pred;
     232     30605302 :       new_entry.nonconst_predicate = nonconst_pred;
     233     30605302 :       if (call)
     234      1389079 :         call_size_time_table.safe_push (new_entry);
     235              :       else
     236     29216223 :         size_time_table.safe_push (new_entry);
     237              :     }
     238              :   else
     239              :     {
     240    104226624 :       e->size += size;
     241    104226624 :       e->time += time;
     242              :       /* FIXME: PR bootstrap/92653 gcc_checking_assert (e->time >= -1); */
     243              :       /* Tolerate small roundoff issues.  */
     244    104226624 :       if (e->time < 0)
     245          232 :         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       359511 : redirect_to_unreachable (struct cgraph_edge *e)
     253              : {
     254       359511 :   struct cgraph_node *callee = !e->inline_failed ? e->callee : NULL;
     255       359511 :   struct cgraph_node *target
     256       359511 :     = cgraph_node::get_create (builtin_decl_unreachable ());
     257              : 
     258       359511 :   gcc_checking_assert (lookup_attribute ("cold",
     259              :                                          DECL_ATTRIBUTES (target->decl)));
     260              : 
     261       359511 :   if (e->speculative)
     262          311 :     e = cgraph_edge::resolve_speculation (e, target->decl);
     263       359200 :   else if (!e->callee)
     264          785 :     e = cgraph_edge::make_direct (e, target);
     265              :   else
     266       358415 :     e->redirect_callee (target);
     267       359511 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
     268       359511 :   e->inline_failed = CIF_UNREACHABLE;
     269       359511 :   e->count = profile_count::zero ();
     270       359511 :   es->call_stmt_size = 0;
     271       359511 :   es->call_stmt_time = 0;
     272       359511 :   if (callee)
     273            0 :     callee->remove_symbol_and_inline_clones ();
     274       359511 :   if (e->has_callback)
     275            6 :     for (cgraph_edge *cbe = e->first_callback_edge (); cbe;
     276            2 :          cbe = cbe->next_callback_edge ())
     277              :       /* If the carrying edge is unreachable, so are the callback calls.  */
     278            2 :       redirect_to_unreachable (cbe);
     279       359511 :   return e;
     280              : }
     281              : 
     282              : /* Set predicate for edge E.  */
     283              : 
     284              : static void
     285     32654531 : 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     29546920 :   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     33014117 :       && (!e->speculative || e->callee))
     295       359509 :     e = redirect_to_unreachable (e);
     296              : 
     297     32654531 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
     298     62201451 :   if (predicate && *predicate != true)
     299              :     {
     300      4832708 :       if (!es->predicate)
     301      4296655 :         es->predicate = edge_predicate_pool.allocate ();
     302      4832708 :       *es->predicate = *predicate;
     303              :     }
     304              :   else
     305              :     {
     306     27821823 :       if (es->predicate)
     307       886522 :         edge_predicate_pool.remove (es->predicate);
     308     27821823 :       es->predicate = NULL;
     309              :     }
     310     32654531 : }
     311              : 
     312              : /* Set predicate for hint *P.  */
     313              : 
     314              : static void
     315       153310 : set_hint_predicate (ipa_predicate **p, ipa_predicate new_predicate)
     316              : {
     317       153310 :   if (new_predicate == false || new_predicate == true)
     318              :     {
     319         2936 :       if (*p)
     320            0 :         edge_predicate_pool.remove (*p);
     321         2936 :       *p = NULL;
     322              :     }
     323              :   else
     324              :     {
     325       150374 :       if (!*p)
     326       150374 :         *p = edge_predicate_pool.allocate ();
     327       150374 :       **p = new_predicate;
     328              :     }
     329       153310 : }
     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      1138185 : 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      1138185 :   if (new_predicate == false || new_predicate == true)
     342              :     return;
     343              :   ipa_freqcounting_predicate *f;
     344       143816 :   for (int i = 0; vec_safe_iterate (*v, i, &f); i++)
     345        72155 :     if (new_predicate == f->predicate)
     346              :       {
     347            0 :         f->freq += add_freq;
     348            0 :         return;
     349              :       }
     350        97930 :   if (vec_safe_length (*v) >= max_num_predicates)
     351              :     /* Too many different predicates to account for.  */
     352              :     return;
     353              : 
     354        71389 :   ipa_freqcounting_predicate fcp;
     355        71389 :   fcp.predicate = NULL;
     356        71389 :   set_hint_predicate (&fcp.predicate, new_predicate);
     357        71389 :   fcp.freq = add_freq;
     358        71389 :   vec_safe_push (*v, fcp);
     359        71389 :   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     23719748 : 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     23719748 :   clause_t clause = inline_p ? 0 : 1 << ipa_predicate::not_inlined_condition;
     388     23719748 :   clause_t nonspec_clause = 1 << ipa_predicate::not_inlined_condition;
     389     23719748 :   class ipa_fn_summary *info = ipa_fn_summaries->get (node);
     390     23719748 :   int i;
     391     23719748 :   struct condition *c;
     392              : 
     393     98258881 :   for (i = 0; vec_safe_iterate (info->conds, i, &c); i++)
     394              :     {
     395     74539133 :       tree val = NULL;
     396     74539133 :       tree res;
     397     74539133 :       int j;
     398     74539133 :       struct expr_eval_op *op;
     399              : 
     400     74539133 :       if (c->code == ipa_predicate::not_sra_candidate)
     401              :         {
     402     17405714 :           if (!inline_p
     403     17405714 :               || !es
     404     17410221 :               || (int)es->param.length () <= c->operand_num
     405     26110803 :               || !es->param[c->operand_num].points_to_possible_sra_candidate)
     406     12934119 :             clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     407     17405714 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     408     74539133 :           continue;
     409              :         }
     410              : 
     411     57133419 :       if (c->agg_contents)
     412              :         {
     413     31699900 :           if (c->code == ipa_predicate::changed
     414     20232722 :               && !c->by_ref
     415     34573401 :               && (avals->safe_sval_at(c->operand_num) == error_mark_node))
     416         3466 :             continue;
     417              : 
     418     31692968 :           if (tree sval = avals->safe_sval_at (c->operand_num))
     419     14933389 :             val = ipa_find_agg_cst_from_init (sval, c->offset, c->by_ref);
     420              :           /* ipa_argagg_value_list is indexed by byte offsets, so a condition
     421              :              which does not start at a byte boundary (a bit-field) cannot be
     422              :              looked up in it; the containing byte would be reinterpreted as
     423              :              the whole field below.  */
     424     31692968 :           if (!val && (c->offset % BITS_PER_UNIT) == 0)
     425              :             {
     426     31655517 :               ipa_argagg_value_list avs (avals);
     427     31655517 :               val = avs.get_value (c->operand_num, c->offset / BITS_PER_UNIT,
     428     31655517 :                                    c->by_ref);
     429              :             }
     430              :         }
     431              :       else
     432              :         {
     433     25436985 :           val = avals->safe_sval_at (c->operand_num);
     434     25436985 :           if (val && val == error_mark_node
     435      2419650 :               && c->code != ipa_predicate::changed)
     436              :             val = NULL_TREE;
     437              :         }
     438              : 
     439     43425033 :       if (!val
     440     43175119 :           && (c->code == ipa_predicate::changed
     441              :               || c->code == ipa_predicate::is_not_constant))
     442              :         {
     443     27309995 :           clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     444     27309995 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     445     27309995 :           continue;
     446              :         }
     447     29819958 :       if (c->code == ipa_predicate::changed)
     448              :         {
     449      8035428 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     450      8035428 :           continue;
     451              :         }
     452              : 
     453     21784530 :       if (c->code == ipa_predicate::is_not_constant)
     454              :         {
     455         8779 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     456         8779 :           continue;
     457              :         }
     458              : 
     459     21775751 :       if (val
     460     21775751 :           && (c->type == TREE_TYPE (val)
     461      1175408 :               || (TYPE_SIZE (c->type) == TYPE_SIZE (TREE_TYPE (val))
     462              :                   /* Avoid precision mismatch like with bit-fields where the
     463              :                      VIEW_CONVERT_EXPR does not truncate excess bits
     464              :                      appropriately.  */
     465      1093074 :                   && ((!INTEGRAL_TYPE_P (c->type)
     466       241409 :                        || type_has_mode_precision_p (c->type))
     467      1091351 :                       && (!INTEGRAL_TYPE_P (TREE_TYPE (val))
     468       239866 :                           || type_has_mode_precision_p (TREE_TYPE (val)))))))
     469              :         {
     470      5826556 :           if (c->type != TREE_TYPE (val))
     471      1091337 :             val = fold_unary (VIEW_CONVERT_EXPR, c->type, val);
     472      6354788 :           for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
     473              :             {
     474       528697 :               if (!val)
     475              :                 break;
     476       528232 :               if (!op->val[0])
     477       226902 :                 val = fold_unary (op->code, op->type, val);
     478       301330 :               else if (!op->val[1])
     479       602660 :                 val = fold_binary (op->code, op->type,
     480              :                                    op->index ? op->val[0] : val,
     481              :                                    op->index ? val : op->val[0]);
     482            0 :               else if (op->index == 0)
     483            0 :                 val = fold_ternary (op->code, op->type,
     484              :                                     val, op->val[0], op->val[1]);
     485            0 :               else if (op->index == 1)
     486            0 :                 val = fold_ternary (op->code, op->type,
     487              :                                     op->val[0], val, op->val[1]);
     488            0 :               else if (op->index == 2)
     489            0 :                 val = fold_ternary (op->code, op->type,
     490              :                                     op->val[0], op->val[1], val);
     491              :               else
     492              :                 val = NULL_TREE;
     493              :             }
     494              : 
     495      5826556 :           res = val
     496      5826556 :             ? fold_binary_to_constant (c->code, boolean_type_node, val, c->val)
     497              :             : NULL;
     498              : 
     499      5826071 :           if (res && integer_zerop (res))
     500      2966944 :             continue;
     501      2859612 :           if (res && integer_onep (res))
     502              :             {
     503      2836940 :               clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     504      2836940 :               nonspec_clause
     505      2836940 :                 |= 1 << (i + ipa_predicate::first_dynamic_condition);
     506      2836940 :               continue;
     507              :             }
     508              :         }
     509     15971867 :       if (c->operand_num < (int) avals->m_known_value_ranges.length ()
     510      9417216 :           && !c->agg_contents
     511     18243728 :           && (!val || TREE_CODE (val) != INTEGER_CST))
     512              :         {
     513      2271126 :           value_range vr (avals->m_known_value_ranges[c->operand_num]);
     514      2271126 :           if (!vr.undefined_p ()
     515      1601770 :               && !vr.varying_p ()
     516      3872896 :               && (TYPE_SIZE (c->type) == TYPE_SIZE (vr.type ())))
     517              :             {
     518      1601233 :               if (!useless_type_conversion_p (c->type, vr.type ()))
     519          512 :                 range_cast (vr, c->type);
     520              : 
     521      2039940 :               for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
     522              :                 {
     523       544789 :                   if (vr.varying_p () || vr.undefined_p ())
     524              :                     break;
     525              : 
     526       438707 :                   value_range res (op->type);
     527       438707 :                   if (!op->val[0])
     528              :                     {
     529       156485 :                       value_range varying (op->type);
     530       156485 :                       varying.set_varying (op->type);
     531       156485 :                       range_op_handler handler (op->code);
     532       156485 :                       if (!handler
     533       156485 :                           || !res.supports_type_p (op->type)
     534       312970 :                           || !handler.fold_range (res, op->type, vr, varying))
     535            0 :                         res.set_varying (op->type);
     536       156485 :                     }
     537       282222 :                   else if (!op->val[1])
     538              :                     {
     539       282050 :                       value_range op0 (TREE_TYPE (op->val[0]));
     540       282050 :                       range_op_handler handler (op->code);
     541              : 
     542       282050 :                       ipa_get_range_from_ip_invariant (op0, op->val[0], node);
     543              : 
     544       282050 :                       if (!handler
     545       282050 :                           || !res.supports_type_p (op->type)
     546       564100 :                           || !handler.fold_range (res, op->type,
     547       282050 :                                                   op->index ? op0 : vr,
     548       562332 :                                                   op->index ? vr : op0))
     549            0 :                         res.set_varying (op->type);
     550       282050 :                     }
     551              :                   else
     552          172 :                     res.set_varying (op->type);
     553       438707 :                   vr = res;
     554       438707 :                 }
     555      1601233 :               if (!vr.varying_p () && !vr.undefined_p ())
     556              :                 {
     557      1485982 :                   int_range<2> res;
     558      1485982 :                   value_range val_vr (TREE_TYPE (c->val));
     559      1485982 :                   range_op_handler handler (c->code);
     560              : 
     561      1485982 :                   ipa_get_range_from_ip_invariant (val_vr, c->val, node);
     562              : 
     563      1485982 :                   if (!handler
     564      1485982 :                       || !val_vr.supports_type_p (TREE_TYPE (c->val))
     565      2971964 :                       || !handler.fold_range (res, boolean_type_node, vr, val_vr))
     566            0 :                     res.set_varying (boolean_type_node);
     567              : 
     568      1485982 :                   if (res.zero_p ())
     569       249904 :                     continue;
     570      1485982 :                 }
     571              :             }
     572      2271126 :         }
     573              : 
     574     15721963 :       clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     575     15721963 :       nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     576              :     }
     577     23719748 :   *ret_clause = clause;
     578     23719748 :   if (ret_nonspec_clause)
     579     20570058 :     *ret_nonspec_clause = nonspec_clause;
     580     23719748 : }
     581              : 
     582              : /* Return true if VRP will be executed on the function.
     583              :    We do not want to anticipate optimizations that will not happen.
     584              : 
     585              :    FIXME: This can be confused with -fdisable and debug counters and thus
     586              :    it should not be used for correctness (only to make heuristics work).
     587              :    This means that inliner should do its own optimizations of expressions
     588              :    that it predicts to be constant so wrong code can not be triggered by
     589              :    builtin_constant_p.  */
     590              : 
     591              : static bool
     592     13090931 : vrp_will_run_p (struct cgraph_node *node)
     593              : {
     594     13090931 :   return (opt_for_fn (node->decl, optimize)
     595     13090931 :           && !opt_for_fn (node->decl, optimize_debug)
     596     26181094 :           && opt_for_fn (node->decl, flag_tree_vrp));
     597              : }
     598              : 
     599              : /* Similarly about FRE.  */
     600              : 
     601              : static bool
     602     15374459 : fre_will_run_p (struct cgraph_node *node)
     603              : {
     604     15374459 :   return (opt_for_fn (node->decl, optimize)
     605     15374459 :           && !opt_for_fn (node->decl, optimize_debug)
     606     30747276 :           && opt_for_fn (node->decl, flag_tree_fre));
     607              : }
     608              : 
     609              : /* Work out what conditions might be true at invocation of E.
     610              :    Compute costs for inlined edge if INLINE_P is true.
     611              : 
     612              :    Return in CLAUSE_PTR the evaluated conditions and in NONSPEC_CLAUSE_PTR
     613              :    (if non-NULL) conditions evaluated for nonspecialized clone called
     614              :    in a given context.
     615              : 
     616              :    Vectors in AVALS will be populated with useful known information about
     617              :    argument values - information not known to have any uses will be omitted -
     618              :    except for m_known_contexts which will only be calculated if
     619              :    COMPUTE_CONTEXTS is true.  */
     620              : 
     621              : void
     622     23473189 : evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
     623              :                               clause_t *clause_ptr,
     624              :                               clause_t *nonspec_clause_ptr,
     625              :                               ipa_auto_call_arg_values *avals,
     626              :                               bool compute_contexts)
     627              : {
     628     23473189 :   struct cgraph_node *callee = e->callee->ultimate_alias_target ();
     629     23473189 :   class ipa_fn_summary *info = ipa_fn_summaries->get (callee);
     630     23473189 :   class ipa_edge_args *args;
     631     23473189 :   class ipa_call_summary *es = NULL;
     632              : 
     633     23473189 :   if (clause_ptr)
     634     23473189 :     *clause_ptr = inline_p ? 0 : 1 << ipa_predicate::not_inlined_condition;
     635              : 
     636     23473189 :   if (ipa_node_params_sum
     637     10751464 :       && !e->call_stmt_cannot_inline_p
     638     10751464 :       && (info->conds || compute_contexts)
     639     34224653 :       && (args = ipa_edge_args_sum->get (e)) != NULL)
     640              :     {
     641     10696632 :       struct cgraph_node *caller;
     642     10696632 :       class ipa_node_params *caller_parms_info, *callee_pi = NULL;
     643     10696632 :       int i, count = ipa_get_cs_argument_count (args);
     644     10696632 :       es = ipa_call_summaries->get (e);
     645              : 
     646     10696632 :       if (count)
     647              :         {
     648      9963890 :           if (e->caller->inlined_to)
     649              :             caller = e->caller->inlined_to;
     650              :           else
     651      7958952 :             caller = e->caller;
     652      9963890 :           caller_parms_info = ipa_node_params_sum->get (caller);
     653      9963890 :           callee_pi = ipa_node_params_sum->get (callee);
     654              : 
     655              :           /* Watch for thunks.  */
     656      9963890 :           if (callee_pi)
     657              :             /* Watch for variadic functions.  */
     658      9963516 :             count = MIN (count, ipa_get_param_count (callee_pi));
     659              :         }
     660              : 
     661      9963516 :       if (callee_pi)
     662     32520962 :         for (i = 0; i < count; i++)
     663              :           {
     664     22557446 :             struct ipa_jump_func *jf = ipa_get_ith_jump_func (args, i);
     665              : 
     666     22557446 :             if (ipa_is_param_used_by_indirect_call (callee_pi, i)
     667     22557446 :                 || ipa_is_param_used_by_ipa_predicates (callee_pi, i))
     668              :               {
     669              :                 /* Determine if we know constant value of the parameter.  */
     670     15374459 :                 tree type = ipa_get_type (callee_pi, i);
     671     15374459 :                 tree cst = ipa_value_from_jfunc (caller_parms_info, jf, type);
     672              : 
     673     12334063 :                 if (!cst && e->call_stmt
     674     27655558 :                     && i < (int)gimple_call_num_args (e->call_stmt))
     675              :                   {
     676     12281099 :                     cst = gimple_call_arg (e->call_stmt, i);
     677     12281099 :                     if (!is_gimple_min_invariant (cst))
     678              :                       cst = NULL;
     679              :                   }
     680      3290141 :                 if (cst)
     681              :                   {
     682      3237177 :                     gcc_checking_assert (TREE_CODE (cst) != TREE_BINFO);
     683      3237177 :                     if (!avals->m_known_vals.length ())
     684      1885455 :                       avals->m_known_vals.safe_grow_cleared (count, true);
     685      3237177 :                     avals->m_known_vals[i] = cst;
     686              :                   }
     687     12137282 :                 else if (inline_p && !es->param[i].change_prob)
     688              :                   {
     689      4511846 :                     if (!avals->m_known_vals.length ())
     690      3696440 :                       avals->m_known_vals.safe_grow_cleared (count, true);
     691      4511846 :                     avals->m_known_vals[i] = error_mark_node;
     692              :                   }
     693              : 
     694              :                 /* If we failed to get simple constant, try value range.  */
     695      3237177 :                 if ((!cst || TREE_CODE (cst) != INTEGER_CST)
     696     13090931 :                     && vrp_will_run_p (caller)
     697     28298710 :                     && ipa_is_param_used_by_ipa_predicates (callee_pi, i))
     698              :                   {
     699     12883365 :                     value_range vr (type);
     700              : 
     701     12883365 :                     ipa_value_range_from_jfunc (vr, caller_parms_info, e, jf, type);
     702     12883365 :                     if (!vr.undefined_p () && !vr.varying_p ())
     703              :                       {
     704      9223605 :                         if (!avals->m_known_value_ranges.length ())
     705              :                           {
     706      6772888 :                             avals->m_known_value_ranges.safe_grow_cleared (count,
     707              :                                                                            true);
     708     28169647 :                             for (int i = 0; i < count; ++i)
     709     14623871 :                               avals->m_known_value_ranges[i].set_range_class
     710     14623871 :                                 (void_type_node);
     711              :                           }
     712      9223605 :                         avals->m_known_value_ranges[i] = vr;
     713              :                       }
     714     12883365 :                   }
     715              : 
     716              :                 /* Determine known aggregate values.  */
     717     15374459 :                 if (fre_will_run_p (caller))
     718     15372413 :                   ipa_push_agg_values_from_jfunc (caller_parms_info,
     719              :                                                   caller, &jf->agg, i,
     720              :                                                   &avals->m_known_aggs);
     721              :               }
     722              : 
     723              :             /* For calls used in polymorphic calls we further determine
     724              :                polymorphic call context.  */
     725     22557446 :             if (compute_contexts
     726     22557446 :                 && ipa_is_param_used_by_polymorphic_call (callee_pi, i))
     727              :               {
     728       186250 :                 ipa_polymorphic_call_context
     729       186250 :                    ctx = ipa_context_from_jfunc (caller_parms_info, e, i, jf);
     730       372500 :                 if (!ctx.useless_p ())
     731              :                   {
     732       184282 :                     if (!avals->m_known_contexts.length ())
     733       184108 :                       avals->m_known_contexts.safe_grow_cleared (count, true);
     734       184282 :                     avals->m_known_contexts[i]
     735       368564 :                       = ipa_context_from_jfunc (caller_parms_info, e, i, jf);
     736              :                   }
     737              :                }
     738              :           }
     739              :         else
     740       733116 :           gcc_assert (!count || callee->thunk);
     741              :     }
     742     12776557 :   else if (e->call_stmt && !e->call_stmt_cannot_inline_p && info->conds)
     743              :     {
     744     10007545 :       int i, count = (int)gimple_call_num_args (e->call_stmt);
     745              : 
     746     28450352 :       for (i = 0; i < count; i++)
     747              :         {
     748     18442807 :           tree cst = gimple_call_arg (e->call_stmt, i);
     749     18442807 :           if (!is_gimple_min_invariant (cst))
     750              :             cst = NULL;
     751      6593467 :           if (cst)
     752              :             {
     753      6593467 :               if (!avals->m_known_vals.length ())
     754      4571635 :                 avals->m_known_vals.safe_grow_cleared (count, true);
     755      6593467 :               avals->m_known_vals[i] = cst;
     756              :             }
     757              :         }
     758              :     }
     759              : 
     760     23473189 :   evaluate_conditions_for_known_args (callee, inline_p, avals, clause_ptr,
     761              :                                       nonspec_clause_ptr, es);
     762     23473189 : }
     763              : 
     764              : 
     765              : /* Allocate the function summary. */
     766              : 
     767              : static void
     768       468191 : ipa_fn_summary_alloc (void)
     769              : {
     770       468191 :   gcc_checking_assert (!ipa_fn_summaries);
     771       468191 :   ipa_size_summaries = new ipa_size_summary_t (symtab);
     772       468191 :   ipa_fn_summaries = ipa_fn_summary_t::create_ggc (symtab);
     773       468191 :   ipa_call_summaries = new ipa_call_summary_t (symtab);
     774       468191 : }
     775              : 
     776     28515844 : ipa_call_summary::~ipa_call_summary ()
     777              : {
     778     28515844 :   if (predicate)
     779      3410133 :     edge_predicate_pool.remove (predicate);
     780              : 
     781     28515844 :   param.release ();
     782     28515844 : }
     783              : 
     784     10539515 : ipa_fn_summary::~ipa_fn_summary ()
     785              : {
     786     10539515 :   unsigned len = vec_safe_length (loop_iterations);
     787     10654012 :   for (unsigned i = 0; i < len; i++)
     788       114497 :     edge_predicate_pool.remove ((*loop_iterations)[i].predicate);
     789     10539515 :   len = vec_safe_length (loop_strides);
     790     10575392 :   for (unsigned i = 0; i < len; i++)
     791        35877 :     edge_predicate_pool.remove ((*loop_strides)[i].predicate);
     792     10539515 :   vec_free (conds);
     793     10539515 :   call_size_time_table.release ();
     794     10539515 :   vec_free (loop_iterations);
     795     10539515 :   vec_free (loop_strides);
     796     10539515 :   builtin_constant_p_parms.release ();
     797     10539515 : }
     798              : 
     799              : void
     800      7541322 : ipa_fn_summary_t::remove_callees (cgraph_node *node)
     801              : {
     802      7541322 :   cgraph_edge *e;
     803     30879729 :   for (e = node->callees; e; e = e->next_callee)
     804     23338407 :     ipa_call_summaries->remove (e);
     805      8026506 :   for (e = node->indirect_calls; e; e = e->next_callee)
     806       485184 :     ipa_call_summaries->remove (e);
     807      7541322 : }
     808              : 
     809              : /* Duplicate predicates in loop hint vector, allocating memory for them and
     810              :    remove and deallocate any uninteresting (true or false) ones.  Return the
     811              :    result.  */
     812              : 
     813              : static vec<ipa_freqcounting_predicate, va_gc> *
     814        28662 : remap_freqcounting_preds_after_dup (vec<ipa_freqcounting_predicate, va_gc> *v,
     815              :                                     clause_t possible_truths)
     816              : {
     817        28662 :   if (vec_safe_length (v) == 0)
     818              :     return NULL;
     819              : 
     820         4694 :   vec<ipa_freqcounting_predicate, va_gc> *res = v->copy ();
     821         4694 :   int len = res->length();
     822        10881 :   for (int i = len - 1; i >= 0; i--)
     823              :     {
     824         6187 :       ipa_predicate new_predicate
     825         6187 :         = (*res)[i].predicate->remap_after_duplication (possible_truths);
     826              :       /* We do not want to free previous predicate; it is used by node
     827              :          origin.  */
     828         6187 :       (*res)[i].predicate = NULL;
     829         6187 :       set_hint_predicate (&(*res)[i].predicate, new_predicate);
     830              : 
     831         6187 :       if (!(*res)[i].predicate)
     832         2936 :         res->unordered_remove (i);
     833              :     }
     834              : 
     835              :   return res;
     836              : }
     837              : 
     838              : 
     839              : /* Hook that is called by cgraph.cc when a node is duplicated.  */
     840              : void
     841      2909798 : ipa_fn_summary_t::duplicate (cgraph_node *src,
     842              :                              cgraph_node *dst,
     843              :                              ipa_fn_summary *src_info,
     844              :                              ipa_fn_summary *info)
     845              : {
     846      2909798 :   new (info) ipa_fn_summary (*src_info);
     847              :   /* TODO: as an optimization, we may avoid copying conditions
     848              :      that are known to be false or true.  */
     849      2909798 :   info->conds = vec_safe_copy (info->conds);
     850              : 
     851      2909798 :   clone_info *cinfo = clone_info::get (dst);
     852              :   /* When there are any replacements in the function body, see if we can figure
     853              :      out that something was optimized out.  */
     854      2909798 :   if (ipa_node_params_sum && cinfo && cinfo->tree_map)
     855              :     {
     856              :       /* Use SRC parm info since it may not be copied yet.  */
     857        14331 :       ipa_node_params *parms_info = ipa_node_params_sum->get (src);
     858        14331 :       ipa_auto_call_arg_values avals;
     859        14331 :       int count = ipa_get_param_count (parms_info);
     860        14331 :       int i, j;
     861        14331 :       clause_t possible_truths;
     862        14331 :       ipa_predicate true_pred = true;
     863        14331 :       size_time_entry *e;
     864        14331 :       int optimized_out_size = 0;
     865        14331 :       bool inlined_to_p = false;
     866        14331 :       struct cgraph_edge *edge, *next;
     867              : 
     868        14331 :       info->size_time_table.release ();
     869        14331 :       avals.m_known_vals.safe_grow_cleared (count, true);
     870        71872 :       for (i = 0; i < count; i++)
     871              :         {
     872              :           struct ipa_replace_map *r;
     873              : 
     874       141072 :           for (j = 0; vec_safe_iterate (cinfo->tree_map, j, &r); j++)
     875              :             {
     876        79381 :               if (r->parm_num == i)
     877              :                 {
     878        24729 :                   avals.m_known_vals[i] = r->new_tree;
     879        24729 :                   break;
     880              :                 }
     881              :             }
     882              :         }
     883        14331 :       evaluate_conditions_for_known_args (dst, false,
     884              :                                           &avals,
     885              :                                           &possible_truths,
     886              :                                           /* We are going to specialize,
     887              :                                              so ignore nonspec truths.  */
     888              :                                           NULL,
     889              :                                           NULL);
     890              : 
     891        14331 :       info->account_size_time (0, 0, true_pred, true_pred);
     892              : 
     893              :       /* Remap size_time vectors.
     894              :          Simplify the predicate by pruning out alternatives that are known
     895              :          to be false.
     896              :          TODO: as on optimization, we can also eliminate conditions known
     897              :          to be true.  */
     898        99719 :       for (i = 0; src_info->size_time_table.iterate (i, &e); i++)
     899              :         {
     900        85388 :           ipa_predicate new_exec_pred;
     901        85388 :           ipa_predicate new_nonconst_pred;
     902        85388 :           new_exec_pred = e->exec_predicate.remap_after_duplication
     903        85388 :                                  (possible_truths);
     904        85388 :           new_nonconst_pred = e->nonconst_predicate.remap_after_duplication
     905        85388 :                                  (possible_truths);
     906        85388 :           if (new_exec_pred == false || new_nonconst_pred == false)
     907        11885 :             optimized_out_size += e->size;
     908              :           else
     909        73503 :             info->account_size_time (e->size, e->time, new_exec_pred,
     910              :                                      new_nonconst_pred);
     911              :         }
     912              : 
     913              :       /* Remap edge predicates with the same simplification as above.
     914              :          Also copy constantness arrays.   */
     915       183949 :       for (edge = dst->callees; edge; edge = next)
     916              :         {
     917       169618 :           ipa_predicate new_predicate;
     918       169618 :           class ipa_call_summary *es = ipa_call_summaries->get (edge);
     919       169618 :           next = edge->next_callee;
     920              : 
     921       169618 :           if (!edge->inline_failed)
     922            0 :             inlined_to_p = true;
     923       169618 :           if (!es->predicate)
     924       157087 :             continue;
     925        12531 :           new_predicate = es->predicate->remap_after_duplication
     926        12531 :             (possible_truths);
     927        12531 :           if (new_predicate == false && *es->predicate != false)
     928         3245 :             optimized_out_size += es->call_stmt_size * ipa_fn_summary::size_scale;
     929        12531 :           edge_set_predicate (edge, &new_predicate);
     930              :         }
     931              : 
     932              :       /* Remap indirect edge predicates with the same simplification as above.
     933              :          Also copy constantness arrays.   */
     934        15242 :       for (edge = dst->indirect_calls; edge; edge = next)
     935              :         {
     936          911 :           ipa_predicate new_predicate;
     937          911 :           class ipa_call_summary *es = ipa_call_summaries->get (edge);
     938          911 :           next = edge->next_callee;
     939              : 
     940          911 :           gcc_checking_assert (edge->inline_failed);
     941          911 :           if (!es->predicate)
     942          807 :             continue;
     943          104 :           new_predicate = es->predicate->remap_after_duplication
     944          104 :                                  (possible_truths);
     945          104 :           if (new_predicate == false && *es->predicate != false)
     946           21 :             optimized_out_size
     947           21 :                  += es->call_stmt_size * ipa_fn_summary::size_scale;
     948          104 :           edge_set_predicate (edge, &new_predicate);
     949              :         }
     950        14331 :       info->loop_iterations
     951        14331 :         = remap_freqcounting_preds_after_dup (info->loop_iterations,
     952              :                                               possible_truths);
     953        14331 :       info->loop_strides
     954        14331 :         = remap_freqcounting_preds_after_dup (info->loop_strides,
     955              :                                               possible_truths);
     956        14331 :       if (info->builtin_constant_p_parms.length())
     957              :         {
     958           23 :           vec <int, va_heap, vl_ptr> parms = info->builtin_constant_p_parms;
     959           23 :           int ip;
     960           23 :           info->builtin_constant_p_parms = vNULL;
     961           46 :           for (i = 0; parms.iterate (i, &ip); i++)
     962           23 :             if (!avals.m_known_vals[ip])
     963            8 :               info->builtin_constant_p_parms.safe_push (ip);
     964              :         }
     965              : 
     966              :       /* If inliner or someone after inliner will ever start producing
     967              :          non-trivial clones, we will get trouble with lack of information
     968              :          about updating self sizes, because size vectors already contains
     969              :          sizes of the callees.  */
     970        14331 :       gcc_assert (!inlined_to_p || !optimized_out_size);
     971        14331 :     }
     972              :   else
     973              :     {
     974      2895467 :       info->size_time_table = src_info->size_time_table.copy ();
     975      2895467 :       info->loop_iterations = vec_safe_copy (src_info->loop_iterations);
     976      2895467 :       info->loop_strides = vec_safe_copy (info->loop_strides);
     977              : 
     978      2895467 :       info->builtin_constant_p_parms
     979      2895467 :              = info->builtin_constant_p_parms.copy ();
     980              : 
     981      2895467 :       ipa_freqcounting_predicate *f;
     982      5840637 :       for (int i = 0; vec_safe_iterate (info->loop_iterations, i, &f); i++)
     983              :         {
     984        49703 :           ipa_predicate p = *f->predicate;
     985        49703 :           f->predicate = NULL;
     986        49703 :           set_hint_predicate (&f->predicate, p);
     987              :         }
     988      2919784 :       for (int i = 0; vec_safe_iterate (info->loop_strides, i, &f); i++)
     989              :         {
     990        24317 :           ipa_predicate p = *f->predicate;
     991        24317 :           f->predicate = NULL;
     992        24317 :           set_hint_predicate (&f->predicate, p);
     993              :         }
     994              :     }
     995      2909798 :   if (!dst->inlined_to)
     996       150246 :     ipa_update_overall_fn_summary (dst);
     997      2909798 : }
     998              : 
     999              : 
    1000              : /* Hook that is called by cgraph.cc when a node is duplicated.  */
    1001              : 
    1002              : void
    1003      4342838 : ipa_call_summary_t::duplicate (struct cgraph_edge *src,
    1004              :                                struct cgraph_edge *dst,
    1005              :                                class ipa_call_summary *srcinfo,
    1006              :                                class ipa_call_summary *info)
    1007              : {
    1008      4342838 :   new (info) ipa_call_summary (*srcinfo);
    1009      4342838 :   info->predicate = NULL;
    1010      4342838 :   edge_set_predicate (dst, srcinfo->predicate);
    1011      4342838 :   info->param = srcinfo->param.copy ();
    1012      4342838 :   if (!dst->indirect_unknown_callee && src->indirect_unknown_callee
    1013              :       /* Don't subtract the size when dealing with callback pairs, since the
    1014              :          edge has no real size.  */
    1015        39219 :       && !src->has_callback && !dst->callback)
    1016              :     {
    1017        39219 :       info->call_stmt_size -= (eni_size_weights.indirect_call_cost
    1018        39219 :                                - eni_size_weights.call_cost);
    1019        39219 :       info->call_stmt_time -= (eni_time_weights.indirect_call_cost
    1020        39219 :                                - eni_time_weights.call_cost);
    1021              :     }
    1022      4342838 : }
    1023              : 
    1024              : /* Dump edge summaries associated to NODE and recursively to all clones.
    1025              :    Indent by INDENT.  */
    1026              : 
    1027              : static void
    1028         1969 : dump_ipa_call_summary (FILE *f, int indent, struct cgraph_node *node,
    1029              :                        class ipa_fn_summary *info)
    1030              : {
    1031         1969 :   struct cgraph_edge *edge;
    1032         9787 :   for (edge = node->callees; edge; edge = edge->next_callee)
    1033              :     {
    1034         7818 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    1035         7818 :       struct cgraph_node *callee = edge->callee->ultimate_alias_target ();
    1036         7818 :       int i;
    1037              : 
    1038        15636 :       fprintf (f,
    1039              :                "%*s%s %s\n%*s  freq:%4.2f",
    1040              :                indent, "", callee->dump_name (),
    1041         7818 :                !edge->inline_failed
    1042         7265 :                ? "inlined" : cgraph_inline_failed_string (edge-> inline_failed),
    1043         7818 :                indent, "", edge->sreal_frequency ().to_double ());
    1044              : 
    1045         7818 :       if (cross_module_call_p (edge))
    1046            4 :         fprintf (f, " cross module");
    1047              : 
    1048         7818 :       if (es)
    1049         7265 :         fprintf (f, " loop depth:%2i size:%2i time: %2i",
    1050              :                  es->loop_depth, es->call_stmt_size, es->call_stmt_time);
    1051              : 
    1052         7818 :       ipa_fn_summary *s = ipa_fn_summaries->get (callee);
    1053         7818 :       ipa_size_summary *ss = ipa_size_summaries->get (callee);
    1054         7818 :       if (s != NULL)
    1055          620 :         fprintf (f, " callee size:%2i stack:%2i",
    1056          620 :                  (int) (ss->size / ipa_fn_summary::size_scale),
    1057          620 :                  (int) s->estimated_stack_size);
    1058              : 
    1059         7818 :       if (es && es->predicate)
    1060              :         {
    1061         4627 :           fprintf (f, " predicate: ");
    1062         4627 :           es->predicate->dump (f, info->conds);
    1063              :         }
    1064              :       else
    1065         3191 :         fprintf (f, "\n");
    1066         7818 :       if (es && es->param.exists ())
    1067         5348 :         for (i = 0; i < (int) es->param.length (); i++)
    1068              :           {
    1069         1582 :             int prob = es->param[i].change_prob;
    1070              : 
    1071         1582 :             if (!prob)
    1072          620 :               fprintf (f, "%*s op%i is compile time invariant\n",
    1073              :                        indent + 2, "", i);
    1074          962 :             else if (prob != REG_BR_PROB_BASE)
    1075           35 :               fprintf (f, "%*s op%i change %f%% of time\n", indent + 2, "", i,
    1076           35 :                        prob * 100.0 / REG_BR_PROB_BASE);
    1077         1582 :             if (es->param[i].points_to_local_or_readonly_memory)
    1078          351 :               fprintf (f, "%*s op%i points to local or readonly memory\n",
    1079              :                        indent + 2, "", i);
    1080         1582 :             if (es->param[i].points_to_possible_sra_candidate)
    1081          227 :               fprintf (f, "%*s op%i points to possible sra candidate\n",
    1082              :                        indent + 2, "", i);
    1083              :           }
    1084         7818 :       if (!edge->inline_failed)
    1085              :         {
    1086          553 :           ipa_size_summary *ss = ipa_size_summaries->get (callee);
    1087          553 :           fprintf (f, "%*sStack frame offset %i, callee self size %i\n",
    1088              :                    indent + 2, "",
    1089          553 :                    (int) ipa_get_stack_frame_offset (callee),
    1090          553 :                    (int) ss->estimated_self_stack_size);
    1091          553 :           dump_ipa_call_summary (f, indent + 2, callee, info);
    1092              :         }
    1093              :     }
    1094         2267 :   for (edge = node->indirect_calls; edge; edge = edge->next_callee)
    1095              :     {
    1096          298 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    1097          298 :       fprintf (f, "%*sindirect call loop depth:%2i freq:%4.2f size:%2i"
    1098              :                " time: %2i",
    1099              :                indent, "",
    1100              :                es->loop_depth,
    1101          298 :                edge->sreal_frequency ().to_double (), es->call_stmt_size,
    1102              :                es->call_stmt_time);
    1103          298 :       if (es->predicate)
    1104              :         {
    1105            6 :           fprintf (f, "predicate: ");
    1106            6 :           es->predicate->dump (f, info->conds);
    1107              :         }
    1108              :       else
    1109          292 :         fprintf (f, "\n");
    1110              :     }
    1111         1969 : }
    1112              : 
    1113              : 
    1114              : void
    1115         1628 : ipa_dump_fn_summary (FILE *f, struct cgraph_node *node)
    1116              : {
    1117         1628 :   if (node->definition)
    1118              :     {
    1119         1628 :       class ipa_fn_summary *s = ipa_fn_summaries->get (node);
    1120         1628 :       class ipa_size_summary *ss = ipa_size_summaries->get (node);
    1121         1628 :       if (s != NULL)
    1122              :         {
    1123         1416 :           size_time_entry *e;
    1124         1416 :           int i;
    1125         1416 :           fprintf (f, "IPA function summary for %s", node->dump_name ());
    1126         1416 :           if (DECL_DISREGARD_INLINE_LIMITS (node->decl))
    1127            0 :             fprintf (f, " always_inline");
    1128         1416 :           if (s->inlinable)
    1129         1235 :             fprintf (f, " inlinable");
    1130         1416 :           if (s->fp_expressions)
    1131           44 :             fprintf (f, " fp_expression");
    1132         1416 :           if (s->builtin_constant_p_parms.length ())
    1133              :             {
    1134            2 :               fprintf (f, " builtin_constant_p_parms");
    1135            4 :               for (unsigned int i = 0;
    1136            4 :                    i < s->builtin_constant_p_parms.length (); i++)
    1137            2 :                 fprintf (f, " %i", s->builtin_constant_p_parms[i]);
    1138              :             }
    1139         1416 :           fprintf (f, "\n  global time:     %f\n", s->time.to_double ());
    1140         1416 :           fprintf (f, "  self size:       %i\n", ss->self_size);
    1141         1416 :           fprintf (f, "  global size:     %i\n", ss->size);
    1142         1416 :           fprintf (f, "  min size:       %i\n", s->min_size);
    1143         1416 :           fprintf (f, "  self stack:      %i\n",
    1144         1416 :                    (int) ss->estimated_self_stack_size);
    1145         1416 :           fprintf (f, "  global stack:    %i\n", (int) s->estimated_stack_size);
    1146         1416 :           if (s->growth)
    1147          168 :             fprintf (f, "  estimated growth:%i\n", (int) s->growth);
    1148         1416 :           if (s->scc_no)
    1149            5 :             fprintf (f, "  In SCC:          %i\n", (int) s->scc_no);
    1150         5908 :           for (i = 0; s->size_time_table.iterate (i, &e); i++)
    1151              :             {
    1152         4492 :               fprintf (f, "    size:%f, time:%f",
    1153         4492 :                        (double) e->size / ipa_fn_summary::size_scale,
    1154              :                        e->time.to_double ());
    1155         4492 :               if (e->exec_predicate != true)
    1156              :                 {
    1157         2623 :                   fprintf (f, ",  executed if:");
    1158         2623 :                   e->exec_predicate.dump (f, s->conds, 0);
    1159              :                 }
    1160         4492 :               if (e->exec_predicate != e->nonconst_predicate)
    1161              :                 {
    1162         1167 :                   fprintf (f, ",  nonconst if:");
    1163         1167 :                   e->nonconst_predicate.dump (f, s->conds, 0);
    1164              :                 }
    1165         4492 :               fprintf (f, "\n");
    1166              :             }
    1167              :           ipa_freqcounting_predicate *fcp;
    1168              :           bool first_fcp = true;
    1169         1522 :           for (int i = 0; vec_safe_iterate (s->loop_iterations, i, &fcp); i++)
    1170              :             {
    1171          106 :               if (first_fcp)
    1172              :                 {
    1173           78 :                   fprintf (f, "  loop iterations:");
    1174           78 :                   first_fcp = false;
    1175              :                 }
    1176          106 :               fprintf (f, "  %3.2f for ", fcp->freq.to_double ());
    1177          106 :               fcp->predicate->dump (f, s->conds);
    1178              :             }
    1179              :           first_fcp = true;
    1180         1434 :           for (int i = 0; vec_safe_iterate (s->loop_strides, i, &fcp); i++)
    1181              :             {
    1182           18 :               if (first_fcp)
    1183              :                 {
    1184           10 :                   fprintf (f, "  loop strides:");
    1185           10 :                   first_fcp = false;
    1186              :                 }
    1187           18 :               fprintf (f, "  %3.2f for :", fcp->freq.to_double ());
    1188           18 :               fcp->predicate->dump (f, s->conds);
    1189              :             }
    1190         1416 :           fprintf (f, "  calls:\n");
    1191         1416 :           dump_ipa_call_summary (f, 4, node, s);
    1192         1416 :           fprintf (f, "\n");
    1193         1416 :           if (s->target_info)
    1194            0 :             fprintf (f, "  target_info: %x\n", s->target_info);
    1195              :         }
    1196              :       else
    1197          212 :         fprintf (f, "IPA summary for %s is missing.\n", node->dump_name ());
    1198              :     }
    1199         1628 : }
    1200              : 
    1201              : DEBUG_FUNCTION void
    1202            0 : ipa_debug_fn_summary (struct cgraph_node *node)
    1203              : {
    1204            0 :   ipa_dump_fn_summary (stderr, node);
    1205            0 : }
    1206              : 
    1207              : void
    1208          356 : ipa_dump_fn_summaries (FILE *f)
    1209              : {
    1210          356 :   struct cgraph_node *node;
    1211              : 
    1212         2288 :   FOR_EACH_DEFINED_FUNCTION (node)
    1213         1932 :     if (!node->inlined_to)
    1214         1379 :       ipa_dump_fn_summary (f, node);
    1215          356 : }
    1216              : 
    1217              : /* Callback of walk_aliased_vdefs.  Flags that it has been invoked to the
    1218              :    boolean variable pointed to by DATA.  */
    1219              : 
    1220              : static bool
    1221       851285 : mark_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef ATTRIBUTE_UNUSED,
    1222              :                void *data)
    1223              : {
    1224       851285 :   bool *b = (bool *) data;
    1225       851285 :   *b = true;
    1226       851285 :   return true;
    1227              : }
    1228              : 
    1229              : /* If OP refers to value of function parameter, return the corresponding
    1230              :    parameter.  If non-NULL, the size of the memory load (or the SSA_NAME of the
    1231              :    PARM_DECL) will be stored to *SIZE_P in that case too.  */
    1232              : 
    1233              : static tree
    1234    190785864 : unmodified_parm_1 (ipa_func_body_info *fbi, gimple *stmt, tree op,
    1235              :                    poly_int64 *size_p)
    1236              : {
    1237              :   /* SSA_NAME referring to parm default def?  */
    1238    190785864 :   if (TREE_CODE (op) == SSA_NAME
    1239    112012605 :       && SSA_NAME_IS_DEFAULT_DEF (op)
    1240    217400075 :       && TREE_CODE (SSA_NAME_VAR (op)) == PARM_DECL)
    1241              :     {
    1242     26402551 :       if (size_p)
    1243            0 :         *size_p = tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op)));
    1244     26402551 :       return SSA_NAME_VAR (op);
    1245              :     }
    1246              :   /* Non-SSA parm reference?  */
    1247    164383313 :   if (TREE_CODE (op) == PARM_DECL
    1248      1433639 :       && fbi->aa_walk_budget > 0)
    1249              :     {
    1250      1431093 :       bool modified = false;
    1251              : 
    1252      1431093 :       ao_ref refd;
    1253      1431093 :       ao_ref_init (&refd, op);
    1254      2862186 :       int walked = walk_aliased_vdefs (&refd, gimple_vuse (stmt),
    1255              :                                        mark_modified, &modified, NULL, NULL,
    1256              :                                        fbi->aa_walk_budget);
    1257      1431093 :       if (walked < 0)
    1258              :         {
    1259            8 :           fbi->aa_walk_budget = 0;
    1260       917095 :           return NULL_TREE;
    1261              :         }
    1262      1431085 :       fbi->aa_walk_budget -= walked;
    1263      1431085 :       if (!modified)
    1264              :         {
    1265       917087 :           if (size_p)
    1266            0 :             *size_p = tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op)));
    1267              :           return op;
    1268              :         }
    1269              :     }
    1270              :   return NULL_TREE;
    1271              : }
    1272              : 
    1273              : /* If OP refers to value of function parameter, return the corresponding
    1274              :    parameter.  Also traverse chains of SSA register assignments.  If non-NULL,
    1275              :    the size of the memory load (or the SSA_NAME of the PARM_DECL) will be
    1276              :    stored to *SIZE_P in that case too.  */
    1277              : 
    1278              : static tree
    1279    124811754 : unmodified_parm (ipa_func_body_info *fbi, gimple *stmt, tree op,
    1280              :                  poly_int64 *size_p)
    1281              : {
    1282    155098040 :   tree res = unmodified_parm_1 (fbi, stmt, op, size_p);
    1283    155098040 :   if (res)
    1284              :     return res;
    1285              : 
    1286    128641760 :   if (TREE_CODE (op) == SSA_NAME
    1287     73150658 :       && !SSA_NAME_IS_DEFAULT_DEF (op)
    1288    201585517 :       && gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
    1289     30286286 :     return unmodified_parm (fbi, SSA_NAME_DEF_STMT (op),
    1290     30286286 :                             gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op)),
    1291     30286286 :                             size_p);
    1292              :   return NULL_TREE;
    1293              : }
    1294              : 
    1295              : /* If OP refers to a value of a function parameter or value loaded from an
    1296              :    aggregate passed to a parameter (either by value or reference), return TRUE
    1297              :    and store the number of the parameter to *INDEX_P, the access size into
    1298              :    *SIZE_P, and information whether and how it has been loaded from an
    1299              :    aggregate into *AGGPOS.  INFO describes the function parameters, STMT is the
    1300              :    statement in which OP is used or loaded.  */
    1301              : 
    1302              : static bool
    1303     34224270 : unmodified_parm_or_parm_agg_item (struct ipa_func_body_info *fbi,
    1304              :                                   gimple *stmt, tree op, int *index_p,
    1305              :                                   poly_int64 *size_p,
    1306              :                                   struct agg_position_info *aggpos)
    1307              : {
    1308     35687824 :   tree res = unmodified_parm_1 (fbi, stmt, op, size_p);
    1309              : 
    1310     35687824 :   gcc_checking_assert (aggpos);
    1311     35687824 :   if (res)
    1312              :     {
    1313       863358 :       *index_p = ipa_get_param_decl_index (fbi->info, res);
    1314       863358 :       if (*index_p < 0)
    1315              :         return false;
    1316       863228 :       aggpos->agg_contents = false;
    1317       863228 :       aggpos->by_ref = false;
    1318       863228 :       return true;
    1319              :     }
    1320              : 
    1321     34824466 :   if (TREE_CODE (op) == SSA_NAME)
    1322              :     {
    1323     12459396 :       if (SSA_NAME_IS_DEFAULT_DEF (op)
    1324     12459396 :           || !gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
    1325              :         return false;
    1326      4976836 :       stmt = SSA_NAME_DEF_STMT (op);
    1327      4976836 :       op = gimple_assign_rhs1 (stmt);
    1328      4976836 :       if (!REFERENCE_CLASS_P (op))
    1329              :         return unmodified_parm_or_parm_agg_item (fbi, stmt, op, index_p, size_p,
    1330              :                                                  aggpos);
    1331              :     }
    1332              : 
    1333     25878352 :   aggpos->agg_contents = true;
    1334     25878352 :   return ipa_load_from_parm_agg (fbi, fbi->info->descriptors,
    1335              :                                  stmt, op, index_p, &aggpos->offset,
    1336     25878352 :                                  size_p, &aggpos->by_ref);
    1337              : }
    1338              : 
    1339              : /* If stmt is simple load or store of value pointed to by a function parameter,
    1340              :    return its index.  */
    1341              : 
    1342              : static int
    1343    114793716 : load_or_store_of_ptr_parameter (ipa_func_body_info *fbi, gimple *stmt)
    1344              : {
    1345    114793716 :   if (!optimize)
    1346              :     return -1;
    1347     96431095 :   gassign *assign = dyn_cast <gassign *> (stmt);
    1348     57162398 :   if (!assign)
    1349              :     return -1;
    1350     57162398 :   tree param;
    1351     57162398 :   if (gimple_assign_load_p (stmt))
    1352     20977994 :     param = gimple_assign_rhs1 (stmt);
    1353     36184404 :   else if (gimple_store_p (stmt))
    1354     19192818 :     param = gimple_assign_lhs (stmt);
    1355              :   else
    1356              :     return -1;
    1357     40170812 :   tree base = get_base_address (param);
    1358     40170812 :   if (TREE_CODE (base) != MEM_REF
    1359     14069355 :       || TREE_CODE (TREE_OPERAND (base, 0)) != SSA_NAME
    1360     54236037 :       || !SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (base, 0)))
    1361              :     return -1;
    1362      7636000 :   tree p = SSA_NAME_VAR (TREE_OPERAND (base, 0));
    1363      7636000 :   if (TREE_CODE (p) != PARM_DECL)
    1364              :     return -1;
    1365      7546553 :   return ipa_get_param_decl_index (fbi->info, p);
    1366              : }
    1367              : 
    1368              : /* See if statement might disappear after inlining.
    1369              :    0 - means not eliminated
    1370              :    1 - half of statements goes away
    1371              :    2 - for sure it is eliminated.
    1372              :    We are not terribly sophisticated, basically looking for simple abstraction
    1373              :    penalty wrappers.  */
    1374              : 
    1375              : static int
    1376    114793716 : eliminated_by_inlining_prob (ipa_func_body_info *fbi, gimple *stmt)
    1377              : {
    1378    114793716 :   enum gimple_code code = gimple_code (stmt);
    1379    114793716 :   enum tree_code rhs_code;
    1380              : 
    1381    114793716 :   if (!optimize)
    1382              :     return 0;
    1383              : 
    1384     96431095 :   switch (code)
    1385              :     {
    1386              :     case GIMPLE_RETURN:
    1387              :       return 2;
    1388     57162398 :     case GIMPLE_ASSIGN:
    1389     57162398 :       if (gimple_num_ops (stmt) != 2)
    1390              :         return 0;
    1391              : 
    1392     41000975 :       rhs_code = gimple_assign_rhs_code (stmt);
    1393              : 
    1394              :       /* Casts of parameters, loads from parameters passed by reference
    1395              :          and stores to return value or parameters are often free after
    1396              :          inlining due to SRA and further combining.
    1397              :          Assume that half of statements goes away.  */
    1398     41000975 :       if (CONVERT_EXPR_CODE_P (rhs_code)
    1399              :           || rhs_code == VIEW_CONVERT_EXPR
    1400              :           || rhs_code == ADDR_EXPR
    1401     38121094 :           || gimple_assign_rhs_class (stmt) == GIMPLE_SINGLE_RHS)
    1402              :         {
    1403     40170812 :           tree rhs = gimple_assign_rhs1 (stmt);
    1404     40170812 :           tree lhs = gimple_assign_lhs (stmt);
    1405     40170812 :           tree inner_rhs = get_base_address (rhs);
    1406     40170812 :           tree inner_lhs = get_base_address (lhs);
    1407     40170812 :           bool rhs_free = false;
    1408     40170812 :           bool lhs_free = false;
    1409              : 
    1410     40170812 :           if (!inner_rhs)
    1411            0 :             inner_rhs = rhs;
    1412     40170812 :           if (!inner_lhs)
    1413            0 :             inner_lhs = lhs;
    1414              : 
    1415              :           /* Reads of parameter are expected to be free.  */
    1416     40170812 :           if (unmodified_parm (fbi, stmt, inner_rhs, NULL))
    1417              :             rhs_free = true;
    1418              :           /* Match expressions of form &this->field. Those will most likely
    1419              :              combine with something upstream after inlining.  */
    1420     38843849 :           else if (TREE_CODE (inner_rhs) == ADDR_EXPR)
    1421              :             {
    1422      2591495 :               tree op = get_base_address (TREE_OPERAND (inner_rhs, 0));
    1423      2591495 :               if (TREE_CODE (op) == PARM_DECL)
    1424              :                 rhs_free = true;
    1425      2547129 :               else if (TREE_CODE (op) == MEM_REF
    1426      2547129 :                        && unmodified_parm (fbi, stmt, TREE_OPERAND (op, 0),
    1427              :                                            NULL))
    1428              :                 rhs_free = true;
    1429              :             }
    1430              : 
    1431              :           /* When parameter is not SSA register because its address is taken
    1432              :              and it is just copied into one, the statement will be completely
    1433              :              free after inlining (we will copy propagate backward).   */
    1434      1371329 :           if (rhs_free && is_gimple_reg (lhs))
    1435              :             return 2;
    1436              : 
    1437              :           /* Reads of parameters passed by reference
    1438              :              expected to be free (i.e. optimized out after inlining).  */
    1439     39483751 :           if (TREE_CODE (inner_rhs) == MEM_REF
    1440     39483751 :               && unmodified_parm (fbi, stmt, TREE_OPERAND (inner_rhs, 0), NULL))
    1441              :             rhs_free = true;
    1442              : 
    1443              :           /* Copying parameter passed by reference into gimple register is
    1444              :              probably also going to copy propagate, but we can't be quite
    1445              :              sure.  */
    1446     39483751 :           if (rhs_free && is_gimple_reg (lhs))
    1447              :             lhs_free = true;
    1448              : 
    1449              :           /* Writes to parameters, parameters passed by value and return value
    1450              :              (either directly or passed via invisible reference) are free.
    1451              : 
    1452              :              TODO: We ought to handle testcase like
    1453              :              struct a {int a,b;};
    1454              :              struct a
    1455              :              returnstruct (void)
    1456              :              {
    1457              :              struct a a ={1,2};
    1458              :              return a;
    1459              :              }
    1460              : 
    1461              :              This translate into:
    1462              : 
    1463              :              returnstruct ()
    1464              :              {
    1465              :              int a$b;
    1466              :              int a$a;
    1467              :              struct a a;
    1468              :              struct a D.2739;
    1469              : 
    1470              :              <bb 2>:
    1471              :              D.2739.a = 1;
    1472              :              D.2739.b = 2;
    1473              :              return D.2739;
    1474              : 
    1475              :              }
    1476              :              For that we either need to copy ipa-split logic detecting writes
    1477              :              to return value.  */
    1478     39483751 :           if (TREE_CODE (inner_lhs) == PARM_DECL
    1479     39393770 :               || TREE_CODE (inner_lhs) == RESULT_DECL
    1480     78028833 :               || (TREE_CODE (inner_lhs) == MEM_REF
    1481      5246944 :                   && (unmodified_parm (fbi, stmt, TREE_OPERAND (inner_lhs, 0),
    1482              :                                        NULL)
    1483      2691254 :                       || (TREE_CODE (TREE_OPERAND (inner_lhs, 0)) == SSA_NAME
    1484      2690056 :                           && SSA_NAME_VAR (TREE_OPERAND (inner_lhs, 0))
    1485       378303 :                           && TREE_CODE (SSA_NAME_VAR (TREE_OPERAND
    1486              :                                                       (inner_lhs,
    1487              :                                                        0))) == RESULT_DECL))))
    1488              :             lhs_free = true;
    1489     35900044 :           if (lhs_free
    1490     39483751 :               && (is_gimple_reg (rhs) || is_gimple_min_invariant (rhs)))
    1491              :             rhs_free = true;
    1492     39483751 :           if (lhs_free && rhs_free)
    1493      8321053 :             return 1;
    1494              :         }
    1495              :       return 0;
    1496              :     default:
    1497              :       return 0;
    1498              :     }
    1499              : }
    1500              : 
    1501              : /* Analyze EXPR if it represents a series of simple operations performed on
    1502              :    a function parameter and return true if so.  FBI, STMT, EXPR, INDEX_P and
    1503              :    AGGPOS have the same meaning like in unmodified_parm_or_parm_agg_item.
    1504              :    Type of the parameter or load from an aggregate via the parameter is
    1505              :    stored in *TYPE_P.  Operations on the parameter are recorded to
    1506              :    PARAM_OPS_P if it is not NULL.  */
    1507              : 
    1508              : static bool
    1509     28070493 : decompose_param_expr (struct ipa_func_body_info *fbi,
    1510              :                       gimple *stmt, tree expr,
    1511              :                       int *index_p, tree *type_p,
    1512              :                       struct agg_position_info *aggpos,
    1513              :                       expr_eval_ops *param_ops_p = NULL)
    1514              : {
    1515     28070493 :   int op_limit = opt_for_fn (fbi->node->decl, param_ipa_max_param_expr_ops);
    1516     28070493 :   int op_count = 0;
    1517              : 
    1518     28070493 :   if (param_ops_p)
    1519      9637891 :     *param_ops_p = NULL;
    1520              : 
    1521     34224270 :   while (true)
    1522              :     {
    1523     34224270 :       expr_eval_op eval_op;
    1524     34224270 :       unsigned rhs_count;
    1525     34224270 :       unsigned cst_count = 0;
    1526              : 
    1527     34224270 :       if (unmodified_parm_or_parm_agg_item (fbi, stmt, expr, index_p, NULL,
    1528              :                                             aggpos))
    1529              :         {
    1530      4800648 :           tree type = TREE_TYPE (expr);
    1531              : 
    1532      4800648 :           if (aggpos->agg_contents)
    1533              :             {
    1534              :               /* Stop if containing bit-field.  */
    1535      3937420 :               if (TREE_CODE (expr) == BIT_FIELD_REF
    1536      3937420 :                   || contains_bitfld_component_ref_p (expr))
    1537              :                 break;
    1538              :             }
    1539              : 
    1540      4773123 :           *type_p = type;
    1541      4773123 :           return true;
    1542              :         }
    1543              : 
    1544     29423622 :       if (TREE_CODE (expr) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (expr))
    1545              :         break;
    1546     11094417 :       stmt = SSA_NAME_DEF_STMT (expr);
    1547              : 
    1548     11094417 :       if (gcall *call = dyn_cast <gcall *> (stmt))
    1549              :         {
    1550      2612096 :           int flags = gimple_call_return_flags (call);
    1551      2612096 :           if (!(flags & ERF_RETURNS_ARG))
    1552      3211124 :             goto fail;
    1553       236510 :           int arg = flags & ERF_RETURN_ARG_MASK;
    1554       236510 :           if (arg >= (int)gimple_call_num_args (call))
    1555            0 :             goto fail;
    1556       236510 :           expr = gimple_call_arg (stmt, arg);
    1557      4200550 :           continue;
    1558       236510 :         }
    1559              : 
    1560      8482321 :       if (!is_gimple_assign (stmt = SSA_NAME_DEF_STMT (expr)))
    1561              :         break;
    1562              : 
    1563      6752893 :       switch (gimple_assign_rhs_class (stmt))
    1564              :         {
    1565      3964040 :         case GIMPLE_SINGLE_RHS:
    1566      3964040 :           expr = gimple_assign_rhs1 (stmt);
    1567      3964040 :           continue;
    1568              : 
    1569              :         case GIMPLE_UNARY_RHS:
    1570              :           rhs_count = 1;
    1571              :           break;
    1572              : 
    1573      1694527 :         case GIMPLE_BINARY_RHS:
    1574      1694527 :           rhs_count = 2;
    1575      1694527 :           break;
    1576              : 
    1577          696 :         case GIMPLE_TERNARY_RHS:
    1578          696 :           rhs_count = 3;
    1579          696 :           break;
    1580              : 
    1581            0 :         default:
    1582            0 :           goto fail;
    1583              :         }
    1584              : 
    1585              :       /* Stop if expression is too complex.  */
    1586      2788853 :       if (op_count++ == op_limit)
    1587              :         break;
    1588              : 
    1589      2788765 :       if (param_ops_p)
    1590              :         {
    1591      2754468 :           eval_op.code = gimple_assign_rhs_code (stmt);
    1592      2754468 :           eval_op.type = TREE_TYPE (gimple_assign_lhs (stmt));
    1593      2754468 :           eval_op.val[0] = NULL_TREE;
    1594      2754468 :           eval_op.val[1] = NULL_TREE;
    1595              :         }
    1596              : 
    1597      2788765 :       expr = NULL_TREE;
    1598      6437220 :       for (unsigned i = 0; i < rhs_count; i++)
    1599              :         {
    1600      4483993 :           tree op = gimple_op (stmt, i + 1);
    1601              : 
    1602      4483993 :           gcc_assert (op && !TYPE_P (op));
    1603      4483993 :           if (is_gimple_ip_invariant (op))
    1604              :             {
    1605       862008 :               if (++cst_count == rhs_count)
    1606         1159 :                 goto fail;
    1607              : 
    1608       860849 :               eval_op.val[cst_count - 1] = op;
    1609              :             }
    1610      3621985 :           else if (!expr)
    1611              :             {
    1612              :               /* Found a non-constant operand, and record its index in rhs
    1613              :                  operands.  */
    1614      2787606 :               eval_op.index = i;
    1615      2787606 :               expr = op;
    1616              :             }
    1617              :           else
    1618              :             {
    1619              :               /* Found more than one non-constant operands.  */
    1620       834379 :               goto fail;
    1621              :             }
    1622              :         }
    1623              : 
    1624      1953227 :       if (param_ops_p)
    1625      1919550 :         vec_safe_insert (*param_ops_p, 0, eval_op);
    1626              :     }
    1627              : 
    1628              :   /* Failed to decompose, free resource and return.  */
    1629     23297370 : fail:
    1630     23297370 :   if (param_ops_p)
    1631      9439881 :     vec_free (*param_ops_p);
    1632              : 
    1633              :   return false;
    1634              : }
    1635              : 
    1636              : /* Record to SUMMARY that PARM is used by builtin_constant_p.  */
    1637              : 
    1638              : static void
    1639        12113 : add_builtin_constant_p_parm (class ipa_fn_summary *summary, int parm)
    1640              : {
    1641        12113 :   int ip;
    1642              : 
    1643              :   /* Avoid duplicates.  */
    1644        12171 :   for (unsigned int i = 0;
    1645        12171 :        summary->builtin_constant_p_parms.iterate (i, &ip); i++)
    1646         6001 :     if (ip == parm)
    1647        12113 :       return;
    1648         6170 :   summary->builtin_constant_p_parms.safe_push (parm);
    1649              : }
    1650              : 
    1651              : /* If BB ends by a conditional we can turn into predicates, attach corresponding
    1652              :    predicates to the CFG edges.   */
    1653              : 
    1654              : static void
    1655     36383130 : set_cond_stmt_execution_predicate (struct ipa_func_body_info *fbi,
    1656              :                                    class ipa_fn_summary *summary,
    1657              :                                    class ipa_node_params *params_summary,
    1658              :                                    basic_block bb)
    1659              : {
    1660     36383130 :   tree op, op2;
    1661     36383130 :   int index;
    1662     36383130 :   struct agg_position_info aggpos;
    1663     36383130 :   enum tree_code code, inverted_code;
    1664     36383130 :   edge e;
    1665     36383130 :   edge_iterator ei;
    1666     36383130 :   gimple *set_stmt;
    1667     36383130 :   tree param_type;
    1668     36383130 :   expr_eval_ops param_ops;
    1669              : 
    1670     72766260 :   gcond *last = safe_dyn_cast <gcond *> (*gsi_last_bb (bb));
    1671     12018711 :   if (!last)
    1672     36370020 :     return;
    1673     12018711 :   if (!is_gimple_ip_invariant (gimple_cond_rhs (last)))
    1674              :     return;
    1675      9554208 :   op = gimple_cond_lhs (last);
    1676              : 
    1677      9554208 :   if (decompose_param_expr (fbi, last, op, &index, &param_type, &aggpos,
    1678              :                             &param_ops))
    1679              :     {
    1680      1377812 :       code = gimple_cond_code (last);
    1681      1377812 :       inverted_code = invert_tree_comparison (code, HONOR_NANS (op));
    1682              : 
    1683      4133436 :       FOR_EACH_EDGE (e, ei, bb->succs)
    1684              :         {
    1685      1377812 :           enum tree_code this_code = (e->flags & EDGE_TRUE_VALUE
    1686      2755624 :                                       ? code : inverted_code);
    1687              :           /* invert_tree_comparison will return ERROR_MARK on FP
    1688              :              comparisons that are not EQ/NE instead of returning proper
    1689              :              unordered one.  Be sure it is not confused with NON_CONSTANT.
    1690              : 
    1691              :              And if the edge's target is the final block of diamond CFG graph
    1692              :              of this conditional statement, we do not need to compute
    1693              :              predicate for the edge because the final block's predicate must
    1694              :              be at least as that of the first block of the statement.  */
    1695      2755624 :           if (this_code != ERROR_MARK
    1696      2755624 :               && !dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    1697              :             {
    1698      2345047 :               ipa_predicate p
    1699      2345047 :                 = add_condition (summary, params_summary, index,
    1700              :                                  param_type, &aggpos,
    1701              :                                  this_code, gimple_cond_rhs (last), param_ops);
    1702      2345047 :               e->aux = edge_predicate_pool.allocate ();
    1703      2345047 :               *(ipa_predicate *) e->aux = p;
    1704              :             }
    1705              :         }
    1706     36602561 :       vec_free (param_ops);
    1707              :       return;
    1708              :     }
    1709              : 
    1710      8176396 :   if (TREE_CODE (op) != SSA_NAME)
    1711              :     return;
    1712              :   /* Special case
    1713              :      if (builtin_constant_p (op))
    1714              :      constant_code
    1715              :      else
    1716              :      nonconstant_code.
    1717              :      Here we can predicate nonconstant_code.  We can't
    1718              :      really handle constant_code since we have no predicate
    1719              :      for this and also the constant code is not known to be
    1720              :      optimized away when inliner doesn't see operand is constant.
    1721              :      Other optimizers might think otherwise.  */
    1722      8175311 :   if (gimple_cond_code (last) != NE_EXPR
    1723      8175311 :       || !integer_zerop (gimple_cond_rhs (last)))
    1724              :     return;
    1725      3606482 :   set_stmt = SSA_NAME_DEF_STMT (op);
    1726      3606482 :   if (!gimple_call_builtin_p (set_stmt, BUILT_IN_CONSTANT_P)
    1727      3606482 :       || gimple_call_num_args (set_stmt) != 1)
    1728              :     return;
    1729        46490 :   op2 = gimple_call_arg (set_stmt, 0);
    1730        46490 :   if (!decompose_param_expr (fbi, set_stmt, op2, &index, &param_type, &aggpos))
    1731              :     return;
    1732        13110 :   if (!aggpos.by_ref)
    1733        12051 :     add_builtin_constant_p_parm (summary, index);
    1734        39330 :   FOR_EACH_EDGE (e, ei, bb->succs) if (e->flags & EDGE_FALSE_VALUE)
    1735              :     {
    1736        13110 :       ipa_predicate p = add_condition (summary, params_summary, index,
    1737              :                                    param_type, &aggpos,
    1738              :                                    ipa_predicate::is_not_constant, NULL_TREE);
    1739        13110 :       e->aux = edge_predicate_pool.allocate ();
    1740        13110 :       *(ipa_predicate *) e->aux = p;
    1741              :     }
    1742              : }
    1743              : 
    1744              : 
    1745              : /* If BB ends by a switch we can turn into predicates, attach corresponding
    1746              :    predicates to the CFG edges.   */
    1747              : 
    1748              : static void
    1749     36383130 : set_switch_stmt_execution_predicate (struct ipa_func_body_info *fbi,
    1750              :                                      class ipa_fn_summary *summary,
    1751              :                                      class ipa_node_params *params_summary,
    1752              :                                      basic_block bb)
    1753              : {
    1754     36383130 :   tree op;
    1755     36383130 :   int index;
    1756     36383130 :   struct agg_position_info aggpos;
    1757     36383130 :   edge e;
    1758     36383130 :   edge_iterator ei;
    1759     36383130 :   size_t n;
    1760     36383130 :   size_t case_idx;
    1761     36383130 :   tree param_type;
    1762     36383130 :   expr_eval_ops param_ops;
    1763              : 
    1764     72766260 :   gswitch *last = safe_dyn_cast <gswitch *> (*gsi_last_bb (bb));
    1765        83683 :   if (!last)
    1766     36353471 :     return;
    1767        83683 :   op = gimple_switch_index (last);
    1768        83683 :   if (!decompose_param_expr (fbi, last, op, &index, &param_type, &aggpos,
    1769              :                              &param_ops))
    1770              :     return;
    1771              : 
    1772        44826 :   auto_vec<std::pair<tree, tree> > ranges;
    1773        44826 :   tree type = TREE_TYPE (op);
    1774        44826 :   int bound_limit = opt_for_fn (fbi->node->decl,
    1775              :                                 param_ipa_max_switch_predicate_bounds);
    1776        44826 :   int bound_count = 0;
    1777              :   // This can safely be an integer range, as switches can only hold
    1778              :   // integers.
    1779        44826 :   int_range<2> vr;
    1780              : 
    1781        89652 :   get_range_query (cfun)->range_of_expr (vr, op);
    1782        44826 :   if (vr.undefined_p ())
    1783            0 :     vr.set_varying (TREE_TYPE (op));
    1784        44826 :   tree vr_min, vr_max;
    1785              :   // TODO: This entire function could use a rewrite to use the irange
    1786              :   // API, instead of trying to recreate its intersection/union logic.
    1787              :   // Any use of get_legacy_range() is a serious code smell.
    1788        44826 :   value_range_kind vr_type = get_legacy_range (vr, vr_min, vr_max);
    1789        44826 :   wide_int vr_wmin = wi::to_wide (vr_min);
    1790        44826 :   wide_int vr_wmax = wi::to_wide (vr_max);
    1791              : 
    1792       310060 :   FOR_EACH_EDGE (e, ei, bb->succs)
    1793              :     {
    1794       265234 :       e->aux = edge_predicate_pool.allocate ();
    1795       265234 :       *(ipa_predicate *) e->aux = false;
    1796              :     }
    1797              : 
    1798        44826 :   e = gimple_switch_edge (cfun, last, 0);
    1799              :   /* Set BOUND_COUNT to maximum count to bypass computing predicate for
    1800              :      default case if its target basic block is in convergence point of all
    1801              :      switch cases, which can be determined by checking whether it
    1802              :      post-dominates the switch statement.  */
    1803        44826 :   if (dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    1804        12642 :     bound_count = INT_MAX;
    1805              : 
    1806        44826 :   n = gimple_switch_num_labels (last);
    1807       296446 :   for (case_idx = 1; case_idx < n; ++case_idx)
    1808              :     {
    1809       251620 :       tree cl = gimple_switch_label (last, case_idx);
    1810       251620 :       tree min = CASE_LOW (cl);
    1811       251620 :       tree max = CASE_HIGH (cl);
    1812       251620 :       ipa_predicate p;
    1813              : 
    1814       251620 :       e = gimple_switch_edge (cfun, last, case_idx);
    1815              : 
    1816              :       /* The case value might not have same type as switch expression,
    1817              :          extend the value based on the expression type.  */
    1818       251620 :       if (TREE_TYPE (min) != type)
    1819        45166 :         min = wide_int_to_tree (type, wi::to_widest (min));
    1820              : 
    1821       251620 :       if (!max)
    1822              :         max = min;
    1823        12605 :       else if (TREE_TYPE (max) != type)
    1824         3521 :         max = wide_int_to_tree (type, wi::to_widest (max));
    1825              : 
    1826              :       /* The case's target basic block is in convergence point of all switch
    1827              :          cases, its predicate should be at least as that of the switch
    1828              :          statement.  */
    1829       251620 :       if (dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    1830         5229 :         p = true;
    1831       246391 :       else if (min == max)
    1832       235726 :         p = add_condition (summary, params_summary, index, param_type,
    1833              :                            &aggpos, EQ_EXPR, min, param_ops);
    1834              :       else
    1835              :         {
    1836        10665 :           ipa_predicate p1, p2;
    1837        10665 :           p1 = add_condition (summary, params_summary, index, param_type,
    1838              :                               &aggpos, GE_EXPR, min, param_ops);
    1839        10665 :           p2 = add_condition (summary,  params_summary,index, param_type,
    1840              :                               &aggpos, LE_EXPR, max, param_ops);
    1841        10665 :           p = p1 & p2;
    1842              :         }
    1843       251620 :       *(ipa_predicate *) e->aux
    1844       251620 :         = p.or_with (summary->conds, *(ipa_predicate *) e->aux);
    1845              : 
    1846              :       /* If there are too many disjoint case ranges, predicate for default
    1847              :          case might become too complicated.  So add a limit here.  */
    1848       251620 :       if (bound_count > bound_limit)
    1849        98039 :         continue;
    1850              : 
    1851       153581 :       bool new_range = true;
    1852              : 
    1853       153581 :       if (!ranges.is_empty ())
    1854              :         {
    1855       121397 :           wide_int curr_wmin = wi::to_wide (min);
    1856       121397 :           wide_int last_wmax = wi::to_wide (ranges.last ().second);
    1857              : 
    1858              :           /* Merge case ranges if they are continuous.  */
    1859       121397 :           if (curr_wmin == last_wmax + 1)
    1860              :             new_range = false;
    1861        42120 :           else if (vr_type == VR_ANTI_RANGE)
    1862              :             {
    1863              :               /* If two disjoint case ranges can be connected by anti-range
    1864              :                  of switch index, combine them to one range.  */
    1865          141 :               if (wi::lt_p (vr_wmax, curr_wmin - 1, TYPE_SIGN (type)))
    1866              :                 vr_type = VR_UNDEFINED;
    1867            0 :               else if (wi::le_p (vr_wmin, last_wmax + 1, TYPE_SIGN (type)))
    1868            0 :                 new_range = false;
    1869              :             }
    1870       121397 :         }
    1871              : 
    1872              :       /* Create/extend a case range.  And we count endpoints of range set,
    1873              :          this number nearly equals to number of conditions that we will create
    1874              :          for predicate of default case.  */
    1875       121397 :       if (new_range)
    1876              :         {
    1877        74304 :           bound_count += (min == max) ? 1 : 2;
    1878        74304 :           ranges.safe_push (std::make_pair (min, max));
    1879              :         }
    1880              :       else
    1881              :         {
    1882        79277 :           bound_count += (ranges.last ().first == ranges.last ().second);
    1883        79277 :           ranges.last ().second = max;
    1884              :         }
    1885              :     }
    1886              : 
    1887        44826 :   e = gimple_switch_edge (cfun, last, 0);
    1888        44826 :   if (bound_count > bound_limit)
    1889              :     {
    1890        15167 :       *(ipa_predicate *) e->aux = true;
    1891        15167 :       vec_free (param_ops);
    1892        15167 :       return;
    1893              :     }
    1894              : 
    1895        29659 :   ipa_predicate p_seg = true;
    1896        29659 :   ipa_predicate p_all = false;
    1897              : 
    1898        29659 :   if (vr_type != VR_RANGE)
    1899              :     {
    1900        29059 :       vr_wmin = wi::to_wide (TYPE_MIN_VALUE (type));
    1901        29059 :       vr_wmax = wi::to_wide (TYPE_MAX_VALUE (type));
    1902              :     }
    1903              : 
    1904              :   /* Construct predicate to represent default range set that is negation of
    1905              :      all case ranges.  Case range is classified as containing single/non-single
    1906              :      values.  Suppose a piece of case ranges in the following.
    1907              : 
    1908              :                 [D1...D2]  [S1] ... [Sn]  [D3...D4]
    1909              : 
    1910              :      To represent default case's range sets between two non-single value
    1911              :      case ranges (From D2 to D3), we construct predicate as:
    1912              : 
    1913              :               D2 < x < D3 && x != S1 && ... && x != Sn
    1914              :    */
    1915        91448 :   for (size_t i = 0; i < ranges.length (); i++)
    1916              :     {
    1917        61886 :       tree min = ranges[i].first;
    1918        61886 :       tree max = ranges[i].second;
    1919              : 
    1920        61886 :       if (min == max)
    1921        73726 :         p_seg &= add_condition (summary, params_summary, index,
    1922              :                                 param_type, &aggpos, NE_EXPR,
    1923        36863 :                                 min, param_ops);
    1924              :       else
    1925              :         {
    1926              :           /* Do not create sub-predicate for range that is beyond low bound
    1927              :              of switch index.  */
    1928        25023 :           if (wi::lt_p (vr_wmin, wi::to_wide (min), TYPE_SIGN (type)))
    1929              :             {
    1930        17915 :               p_seg &= add_condition (summary, params_summary, index,
    1931              :                                       param_type, &aggpos,
    1932        17915 :                                       LT_EXPR, min, param_ops);
    1933        17915 :               p_all = p_all.or_with (summary->conds, p_seg);
    1934              :             }
    1935              : 
    1936              :           /* Do not create sub-predicate for range that is beyond up bound
    1937              :              of switch index.  */
    1938        25023 :           if (wi::le_p (vr_wmax, wi::to_wide (max), TYPE_SIGN (type)))
    1939              :             {
    1940           97 :               p_seg = false;
    1941           97 :               break;
    1942              :             }
    1943              : 
    1944        24926 :           p_seg = add_condition (summary, params_summary, index,
    1945              :                                  param_type, &aggpos, GT_EXPR,
    1946              :                                  max, param_ops);
    1947              :         }
    1948              :     }
    1949              : 
    1950        29659 :   p_all = p_all.or_with (summary->conds, p_seg);
    1951        29659 :   *(ipa_predicate *) e->aux
    1952        29659 :     = p_all.or_with (summary->conds, *(ipa_predicate *) e->aux);
    1953              : 
    1954        36252 :   vec_free (param_ops);
    1955        44826 : }
    1956              : 
    1957              : 
    1958              : /* For each BB in NODE attach to its AUX pointer predicate under
    1959              :    which it is executable.  */
    1960              : 
    1961              : static void
    1962      6620354 : compute_bb_predicates (struct ipa_func_body_info *fbi,
    1963              :                        struct cgraph_node *node,
    1964              :                        class ipa_fn_summary *summary,
    1965              :                        class ipa_node_params *params_summary)
    1966              : {
    1967      6620354 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    1968      6620354 :   bool done = false;
    1969      6620354 :   basic_block bb;
    1970              : 
    1971     43003484 :   FOR_EACH_BB_FN (bb, my_function)
    1972              :     {
    1973     36383130 :       set_cond_stmt_execution_predicate (fbi, summary, params_summary, bb);
    1974     36383130 :       set_switch_stmt_execution_predicate (fbi, summary, params_summary, bb);
    1975              :     }
    1976              : 
    1977              :   /* Entry block is always executable.  */
    1978      6620354 :   ENTRY_BLOCK_PTR_FOR_FN (my_function)->aux
    1979      6620354 :     = edge_predicate_pool.allocate ();
    1980      6620354 :   *(ipa_predicate *) ENTRY_BLOCK_PTR_FOR_FN (my_function)->aux = true;
    1981              : 
    1982              :   /* A simple dataflow propagation of predicates forward in the CFG.
    1983              :      TODO: work in reverse postorder.  */
    1984     19981403 :   while (!done)
    1985              :     {
    1986     13361049 :       done = true;
    1987     91247187 :       FOR_EACH_BB_FN (bb, my_function)
    1988              :         {
    1989     77886138 :           ipa_predicate p = false;
    1990     77886138 :           edge e;
    1991     77886138 :           edge_iterator ei;
    1992     96355224 :           FOR_EACH_EDGE (e, ei, bb->preds)
    1993              :             {
    1994     82753170 :               if (e->src->aux)
    1995              :                 {
    1996     81013276 :                   ipa_predicate this_bb_predicate
    1997              :                     = *(ipa_predicate *) e->src->aux;
    1998     81013276 :                   if (e->aux)
    1999      5450894 :                     this_bb_predicate &= (*(ipa_predicate *) e->aux);
    2000     81013276 :                   p = p.or_with (summary->conds, this_bb_predicate);
    2001     81013276 :                   if (p == true)
    2002              :                     break;
    2003              :                 }
    2004              :             }
    2005     77886138 :           if (p != false)
    2006              :             {
    2007     76753914 :               basic_block pdom_bb;
    2008              : 
    2009     76753914 :               if (!bb->aux)
    2010              :                 {
    2011     28604885 :                   done = false;
    2012     28604885 :                   bb->aux = edge_predicate_pool.allocate ();
    2013     28604885 :                   *((ipa_predicate *) bb->aux) = p;
    2014              :                 }
    2015     48149029 :               else if (p != *(ipa_predicate *) bb->aux)
    2016              :                 {
    2017              :                   /* This OR operation is needed to ensure monotonous data flow
    2018              :                      in the case we hit the limit on number of clauses and the
    2019              :                      and/or operations above give approximate answers.  */
    2020       129195 :                   p = p.or_with (summary->conds, *(ipa_predicate *)bb->aux);
    2021       129195 :                   if (p != *(ipa_predicate *)bb->aux)
    2022              :                     {
    2023       104526 :                       done = false;
    2024       104526 :                       *((ipa_predicate *)bb->aux) = p;
    2025              :                     }
    2026              :                 }
    2027              : 
    2028              :               /* For switch/if statement, we can OR-combine predicates of all
    2029              :                  its cases/branches to get predicate for basic block in their
    2030              :                  convergence point, but sometimes this will generate very
    2031              :                  complicated predicate.  Actually, we can get simplified
    2032              :                  predicate in another way by using the fact that predicate
    2033              :                  for a basic block must also hold true for its post dominators.
    2034              :                  To be specific, basic block in convergence point of
    2035              :                  conditional statement should include predicate of the
    2036              :                  statement.  */
    2037     76753914 :               pdom_bb = get_immediate_dominator (CDI_POST_DOMINATORS, bb);
    2038     76753914 :               if (pdom_bb == EXIT_BLOCK_PTR_FOR_FN (my_function) || !pdom_bb)
    2039              :                 ;
    2040     39249017 :               else if (!pdom_bb->aux)
    2041              :                 {
    2042      7778229 :                   done = false;
    2043      7778229 :                   pdom_bb->aux = edge_predicate_pool.allocate ();
    2044      7778229 :                   *((ipa_predicate *)pdom_bb->aux) = p;
    2045              :                 }
    2046     31470788 :               else if (p != *(ipa_predicate *)pdom_bb->aux)
    2047              :                 {
    2048      3465000 :                   p = p.or_with (summary->conds,
    2049              :                                  *(ipa_predicate *)pdom_bb->aux);
    2050      3465000 :                   if (p != *(ipa_predicate *)pdom_bb->aux)
    2051              :                     {
    2052       142045 :                       done = false;
    2053       142045 :                       *((ipa_predicate *)pdom_bb->aux) = p;
    2054              :                     }
    2055              :                 }
    2056              :             }
    2057              :         }
    2058              :     }
    2059      6620354 : }
    2060              : 
    2061              : 
    2062              : /* Return predicate specifying when the STMT might have result that is not
    2063              :    a compile time constant.  */
    2064              : 
    2065              : static ipa_predicate
    2066      4289912 : will_be_nonconstant_expr_predicate (ipa_func_body_info *fbi,
    2067              :                                     class ipa_fn_summary *summary,
    2068              :                                     class ipa_node_params *params_summary,
    2069              :                                     tree expr,
    2070              :                                     vec<ipa_predicate> nonconstant_names)
    2071              : {
    2072      4289912 :   tree parm;
    2073      4289912 :   int index;
    2074              : 
    2075      4535849 :   while (UNARY_CLASS_P (expr))
    2076       245937 :     expr = TREE_OPERAND (expr, 0);
    2077              : 
    2078      4289912 :   parm = unmodified_parm (fbi, NULL, expr, NULL);
    2079      4289912 :   if (parm && (index = ipa_get_param_decl_index (fbi->info, parm)) >= 0)
    2080       225937 :     return add_condition (summary, params_summary, index, TREE_TYPE (parm), NULL,
    2081       225937 :                           ipa_predicate::changed, NULL_TREE);
    2082      4063975 :   if (is_gimple_min_invariant (expr))
    2083        63920 :     return false;
    2084      4000055 :   if (TREE_CODE (expr) == SSA_NAME)
    2085      3818299 :     return nonconstant_names[SSA_NAME_VERSION (expr)];
    2086       181756 :   if (BINARY_CLASS_P (expr) || COMPARISON_CLASS_P (expr))
    2087              :     {
    2088       181082 :       ipa_predicate p1
    2089       181082 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2090              :                                               params_summary,
    2091       181082 :                                               TREE_OPERAND (expr, 0),
    2092              :                                               nonconstant_names);
    2093       181082 :       if (p1 == true)
    2094       103915 :         return p1;
    2095              : 
    2096        77167 :       ipa_predicate p2
    2097        77167 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2098              :                                               params_summary,
    2099        77167 :                                               TREE_OPERAND (expr, 1),
    2100              :                                               nonconstant_names);
    2101        77167 :       return p1.or_with (summary->conds, p2);
    2102              :     }
    2103          674 :   else if (TREE_CODE (expr) == COND_EXPR)
    2104              :     {
    2105          188 :       ipa_predicate p1
    2106          188 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2107              :                                               params_summary,
    2108          188 :                                               TREE_OPERAND (expr, 0),
    2109              :                                               nonconstant_names);
    2110          188 :       if (p1 == true)
    2111           37 :         return p1;
    2112              : 
    2113          151 :       ipa_predicate p2
    2114          151 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2115              :                                               params_summary,
    2116          151 :                                               TREE_OPERAND (expr, 1),
    2117              :                                               nonconstant_names);
    2118          151 :       if (p2 == true)
    2119          151 :         return p2;
    2120            0 :       p1 = p1.or_with (summary->conds, p2);
    2121            0 :       p2 = will_be_nonconstant_expr_predicate (fbi, summary,
    2122              :                                                params_summary,
    2123            0 :                                                TREE_OPERAND (expr, 2),
    2124              :                                                nonconstant_names);
    2125            0 :       return p2.or_with (summary->conds, p1);
    2126              :     }
    2127          486 :   else if (TREE_CODE (expr) == CALL_EXPR)
    2128          486 :     return true;
    2129              :   else
    2130              :     {
    2131            0 :       debug_tree (expr);
    2132            0 :       gcc_unreachable ();
    2133              :     }
    2134              : }
    2135              : 
    2136              : 
    2137              : /* Return predicate specifying when the STMT might have result that is not
    2138              :    a compile time constant.  */
    2139              : 
    2140              : static ipa_predicate
    2141    118055891 : will_be_nonconstant_predicate (struct ipa_func_body_info *fbi,
    2142              :                                class ipa_fn_summary *summary,
    2143              :                                class ipa_node_params *params_summary,
    2144              :                                gimple *stmt,
    2145              :                                vec<ipa_predicate> nonconstant_names)
    2146              : {
    2147    118055891 :   ipa_predicate p = true;
    2148    118055891 :   ssa_op_iter iter;
    2149    118055891 :   tree use;
    2150    118055891 :   tree param_type = NULL_TREE;
    2151    118055891 :   ipa_predicate op_non_const;
    2152    118055891 :   bool is_load;
    2153    118055891 :   int base_index;
    2154    118055891 :   struct agg_position_info aggpos;
    2155              : 
    2156              :   /* What statements might be optimized away
    2157              :      when their arguments are constant.  */
    2158    118055891 :   if (gimple_code (stmt) != GIMPLE_ASSIGN
    2159              :       && gimple_code (stmt) != GIMPLE_COND
    2160              :       && gimple_code (stmt) != GIMPLE_SWITCH
    2161              :       && (gimple_code (stmt) != GIMPLE_CALL
    2162     21703507 :           || !(gimple_call_flags (stmt) & ECF_CONST)))
    2163     27214604 :     return p;
    2164              : 
    2165              :   /* Stores will stay anyway.  */
    2166     90841287 :   if (gimple_store_p (stmt))
    2167     26728268 :     return p;
    2168              : 
    2169     64113019 :   is_load = gimple_assign_load_p (stmt);
    2170              : 
    2171              :   /* Loads can be optimized when the value is known.  */
    2172     64113019 :   if (is_load)
    2173              :     {
    2174     18386112 :       tree op = gimple_assign_rhs1 (stmt);
    2175     18386112 :       if (!decompose_param_expr (fbi, stmt, op, &base_index, &param_type,
    2176              :                                  &aggpos))
    2177     15048737 :         return p;
    2178              :     }
    2179              :   else
    2180     45726907 :     base_index = -1;
    2181              : 
    2182              :   /* See if we understand all operands before we start
    2183              :      adding conditionals.  */
    2184     66952580 :   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2185              :     {
    2186     48902030 :       tree parm = unmodified_parm (fbi, stmt, use, NULL);
    2187              :       /* For arguments we can build a condition.  */
    2188     48902030 :       if (parm && ipa_get_param_decl_index (fbi->info, parm) >= 0)
    2189      8787122 :         continue;
    2190     40114908 :       if (TREE_CODE (use) != SSA_NAME)
    2191            0 :         return p;
    2192              :       /* If we know when operand is constant,
    2193              :          we still can say something useful.  */
    2194     40114908 :       if (nonconstant_names[SSA_NAME_VERSION (use)] != true)
    2195      9101176 :         continue;
    2196     31013732 :       return p;
    2197              :     }
    2198              : 
    2199     18050550 :   if (is_load)
    2200      3337294 :     op_non_const =
    2201      3337294 :       add_condition (summary, params_summary,
    2202              :                      base_index, param_type, &aggpos,
    2203              :                      ipa_predicate::changed, NULL_TREE);
    2204              :   else
    2205     14713256 :     op_non_const = false;
    2206     34885877 :   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2207              :     {
    2208     16835327 :       tree parm = unmodified_parm (fbi, stmt, use, NULL);
    2209     16835327 :       int index;
    2210              : 
    2211     16835327 :       if (parm && (index = ipa_get_param_decl_index (fbi->info, parm)) >= 0)
    2212              :         {
    2213      8284903 :           if (index != base_index)
    2214      5655322 :             p = add_condition (summary, params_summary, index,
    2215      5655322 :                                TREE_TYPE (parm), NULL,
    2216              :                                ipa_predicate::changed, NULL_TREE);
    2217              :           else
    2218      2629581 :             continue;
    2219              :         }
    2220              :       else
    2221      8550424 :         p = nonconstant_names[SSA_NAME_VERSION (use)];
    2222     14205746 :       op_non_const = p.or_with (summary->conds, op_non_const);
    2223              :     }
    2224     18050550 :   if ((gimple_code (stmt) == GIMPLE_ASSIGN || gimple_code (stmt) == GIMPLE_CALL)
    2225     15682999 :       && gimple_op (stmt, 0)
    2226     33421350 :       && TREE_CODE (gimple_op (stmt, 0)) == SSA_NAME)
    2227     15370800 :     nonconstant_names[SSA_NAME_VERSION (gimple_op (stmt, 0))]
    2228     15370800 :       = op_non_const;
    2229     18050550 :   return op_non_const;
    2230              : }
    2231              : 
    2232              : struct record_modified_bb_info
    2233              : {
    2234              :   tree op;
    2235              :   bitmap bb_set;
    2236              :   gimple *stmt;
    2237              : };
    2238              : 
    2239              : /* Value is initialized in INIT_BB and used in USE_BB.  We want to compute
    2240              :    probability how often it changes between USE_BB.
    2241              :    INIT_BB->count/USE_BB->count is an estimate, but if INIT_BB
    2242              :    is in different loop nest, we can do better.
    2243              :    This is all just estimate.  In theory we look for minimal cut separating
    2244              :    INIT_BB and USE_BB, but we only want to anticipate loop invariant motion
    2245              :    anyway.  */
    2246              : 
    2247              : static basic_block
    2248     10776873 : get_minimal_bb (basic_block init_bb, basic_block use_bb)
    2249              : {
    2250     10776873 :   class loop *l = find_common_loop (init_bb->loop_father, use_bb->loop_father);
    2251     10776873 :   if (l && l->header->count < init_bb->count)
    2252       387310 :     return l->header;
    2253              :   return init_bb;
    2254              : }
    2255              : 
    2256              : /* Callback of walk_aliased_vdefs.  Records basic blocks where the value may be
    2257              :    set except for info->stmt.  */
    2258              : 
    2259              : static bool
    2260      4960102 : record_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data)
    2261              : {
    2262      4960102 :   struct record_modified_bb_info *info =
    2263              :     (struct record_modified_bb_info *) data;
    2264      4960102 :   if (SSA_NAME_DEF_STMT (vdef) == info->stmt)
    2265              :     return false;
    2266      4931881 :   if (gimple_clobber_p (SSA_NAME_DEF_STMT (vdef)))
    2267              :     return false;
    2268      4881393 :   bitmap_set_bit (info->bb_set,
    2269      4881393 :                   SSA_NAME_IS_DEFAULT_DEF (vdef)
    2270            0 :                   ? ENTRY_BLOCK_PTR_FOR_FN (cfun)->index
    2271              :                   : get_minimal_bb
    2272      4881393 :                          (gimple_bb (SSA_NAME_DEF_STMT (vdef)),
    2273      4881393 :                           gimple_bb (info->stmt))->index);
    2274      4881393 :   if (dump_file)
    2275              :     {
    2276            0 :       fprintf (dump_file, "     Param ");
    2277            0 :       print_generic_expr (dump_file, info->op, TDF_SLIM);
    2278            0 :       fprintf (dump_file, " changed at bb %i, minimal: %i stmt: ",
    2279            0 :                gimple_bb (SSA_NAME_DEF_STMT (vdef))->index,
    2280              :                get_minimal_bb
    2281            0 :                          (gimple_bb (SSA_NAME_DEF_STMT (vdef)),
    2282            0 :                           gimple_bb (info->stmt))->index);
    2283            0 :       print_gimple_stmt (dump_file, SSA_NAME_DEF_STMT (vdef), 0);
    2284              :     }
    2285              :   return false;
    2286              : }
    2287              : 
    2288              : /* Return probability (based on REG_BR_PROB_BASE) that I-th parameter of STMT
    2289              :    will change since last invocation of STMT.
    2290              : 
    2291              :    Value 0 is reserved for compile time invariants.
    2292              :    For common parameters it is REG_BR_PROB_BASE.  For loop invariants it
    2293              :    ought to be REG_BR_PROB_BASE / estimated_iters.  */
    2294              : 
    2295              : static int
    2296     40154494 : param_change_prob (ipa_func_body_info *fbi, gimple *stmt, int i)
    2297              : {
    2298     40154494 :   tree op = gimple_call_arg (stmt, i);
    2299     40154494 :   basic_block bb = gimple_bb (stmt);
    2300              : 
    2301     40154494 :   if (TREE_CODE (op) == WITH_SIZE_EXPR)
    2302          299 :     op = TREE_OPERAND (op, 0);
    2303              : 
    2304     40154494 :   tree base = get_base_address (op);
    2305              : 
    2306              :   /* Global invariants never change.  */
    2307     40154494 :   if (is_gimple_min_invariant (base))
    2308              :     return 0;
    2309              : 
    2310              :   /* We would have to do non-trivial analysis to really work out what
    2311              :      is the probability of value to change (i.e. when init statement
    2312              :      is in a sibling loop of the call).
    2313              : 
    2314              :      We do an conservative estimate: when call is executed N times more often
    2315              :      than the statement defining value, we take the frequency 1/N.  */
    2316     20157818 :   if (TREE_CODE (base) == SSA_NAME)
    2317              :     {
    2318     17750233 :       profile_count init_count;
    2319              : 
    2320     27234912 :       if (!bb->count.nonzero_p ())
    2321              :         return REG_BR_PROB_BASE;
    2322              : 
    2323      9059010 :       if (SSA_NAME_IS_DEFAULT_DEF (base))
    2324      3163530 :         init_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2325              :       else
    2326      5895480 :         init_count = get_minimal_bb
    2327      5895480 :                       (gimple_bb (SSA_NAME_DEF_STMT (base)),
    2328              :                        gimple_bb (stmt))->count;
    2329              : 
    2330      9059010 :       if (init_count < bb->count)
    2331       471387 :         return MAX ((init_count.to_sreal_scale (bb->count)
    2332              :                      * REG_BR_PROB_BASE).to_int (), 1);
    2333              :       return REG_BR_PROB_BASE;
    2334              :     }
    2335              :   else
    2336              :     {
    2337      2407585 :       ao_ref refd;
    2338      2407585 :       profile_count max = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2339      2407585 :       struct record_modified_bb_info info;
    2340      2407585 :       tree init = ctor_for_folding (base);
    2341              : 
    2342      2407585 :       if (init != error_mark_node)
    2343              :         return 0;
    2344      5380921 :       if (!bb->count.nonzero_p () || fbi->aa_walk_budget == 0)
    2345              :         return REG_BR_PROB_BASE;
    2346      1475502 :       if (dump_file)
    2347              :         {
    2348            0 :           fprintf (dump_file, "     Analyzing param change probability of ");
    2349            0 :           print_generic_expr (dump_file, op, TDF_SLIM);
    2350            0 :           fprintf (dump_file, "\n");
    2351              :         }
    2352      1475502 :       ao_ref_init (&refd, op);
    2353      1475502 :       info.op = op;
    2354      1475502 :       info.stmt = stmt;
    2355      1475502 :       info.bb_set = BITMAP_ALLOC (NULL);
    2356      1475502 :       int walked
    2357      2951004 :         = walk_aliased_vdefs (&refd, gimple_vuse (stmt), record_modified, &info,
    2358              :                               NULL, NULL, fbi->aa_walk_budget);
    2359      1475502 :       if (walked > 0)
    2360      1340891 :         fbi->aa_walk_budget -= walked;
    2361      1475502 :       if (walked < 0 || bitmap_bit_p (info.bb_set, bb->index))
    2362              :         {
    2363       897432 :           if (walked < 0)
    2364          206 :             fbi->aa_walk_budget = 0;
    2365       897432 :           if (dump_file)
    2366              :             {
    2367            0 :               if (walked < 0)
    2368            0 :                 fprintf (dump_file, "     Ran out of AA walking budget.\n");
    2369              :               else
    2370            0 :                 fprintf (dump_file, "     Set in same BB as used.\n");
    2371              :             }
    2372       897432 :           BITMAP_FREE (info.bb_set);
    2373       897432 :           return REG_BR_PROB_BASE;
    2374              :         }
    2375              : 
    2376       578070 :       bitmap_iterator bi;
    2377       578070 :       unsigned index;
    2378              :       /* Lookup the most frequent update of the value and believe that
    2379              :          it dominates all the other; precise analysis here is difficult.  */
    2380      1618708 :       EXECUTE_IF_SET_IN_BITMAP (info.bb_set, 0, index, bi)
    2381      1040638 :         max = profile_count::max_prefer_initialized
    2382      1040638 :                 (max, BASIC_BLOCK_FOR_FN (cfun, index)->count);
    2383       578070 :       if (dump_file)
    2384              :         {
    2385            0 :           fprintf (dump_file, "     Set with count ");
    2386            0 :           max.dump (dump_file);
    2387            0 :           fprintf (dump_file, " and used with count ");
    2388            0 :           bb->count.dump (dump_file);
    2389            0 :           fprintf (dump_file, " freq %f\n",
    2390            0 :                    max.to_sreal_scale (bb->count).to_double ());
    2391              :         }
    2392              : 
    2393       578070 :       BITMAP_FREE (info.bb_set);
    2394       578070 :       if (max < bb->count)
    2395        96990 :         return MAX ((max.to_sreal_scale (bb->count)
    2396              :                      * REG_BR_PROB_BASE).to_int (), 1);
    2397              :       return REG_BR_PROB_BASE;
    2398              :     }
    2399              : }
    2400              : 
    2401              : /* Find whether a basic block BB is the final block of a (half) diamond CFG
    2402              :    sub-graph and if the predicate the condition depends on is known.  If so,
    2403              :    return true and store the pointer the predicate in *P.  */
    2404              : 
    2405              : static bool
    2406      6538250 : phi_result_unknown_predicate (ipa_func_body_info *fbi,
    2407              :                               ipa_fn_summary *summary,
    2408              :                               class ipa_node_params *params_summary,
    2409              :                               basic_block bb,
    2410              :                               ipa_predicate *p,
    2411              :                               vec<ipa_predicate> nonconstant_names)
    2412              : {
    2413      6538250 :   edge e;
    2414      6538250 :   edge_iterator ei;
    2415      6538250 :   basic_block first_bb = NULL;
    2416              : 
    2417      6538250 :   if (single_pred_p (bb))
    2418              :     {
    2419        83586 :       *p = false;
    2420        83586 :       return true;
    2421              :     }
    2422              : 
    2423     14844295 :   FOR_EACH_EDGE (e, ei, bb->preds)
    2424              :     {
    2425     12711544 :       if (single_succ_p (e->src))
    2426              :         {
    2427      8495905 :           if (!single_pred_p (e->src))
    2428              :             return false;
    2429      7464538 :           if (!first_bb)
    2430      3278770 :             first_bb = single_pred (e->src);
    2431      4185768 :           else if (single_pred (e->src) != first_bb)
    2432              :             return false;
    2433              :         }
    2434              :       else
    2435              :         {
    2436      4215639 :           if (!first_bb)
    2437              :             first_bb = e->src;
    2438      1474465 :           else if (e->src != first_bb)
    2439              :             return false;
    2440              :         }
    2441              :     }
    2442              : 
    2443      2132751 :   if (!first_bb)
    2444              :     return false;
    2445              : 
    2446      4265502 :   gcond *stmt = safe_dyn_cast <gcond *> (*gsi_last_bb (first_bb));
    2447      2087276 :   if (!stmt
    2448      2087276 :       || !is_gimple_ip_invariant (gimple_cond_rhs (stmt)))
    2449              :     return false;
    2450              : 
    2451      1829192 :   *p = will_be_nonconstant_expr_predicate (fbi, summary, params_summary,
    2452              :                                            gimple_cond_lhs (stmt),
    2453              :                                            nonconstant_names);
    2454      1829192 :   if (*p == true)
    2455              :     return false;
    2456              :   else
    2457       611289 :     return true;
    2458              : }
    2459              : 
    2460              : /* Given a PHI statement in a function described by inline properties SUMMARY
    2461              :    and *P being the predicate describing whether the selected PHI argument is
    2462              :    known, store a predicate for the result of the PHI statement into
    2463              :    NONCONSTANT_NAMES, if possible.  */
    2464              : 
    2465              : static void
    2466       793606 : predicate_for_phi_result (class ipa_fn_summary *summary, gphi *phi,
    2467              :                           ipa_predicate *p,
    2468              :                           vec<ipa_predicate> nonconstant_names)
    2469              : {
    2470       793606 :   unsigned i;
    2471              : 
    2472      1116505 :   for (i = 0; i < gimple_phi_num_args (phi); i++)
    2473              :     {
    2474       956850 :       tree arg = gimple_phi_arg (phi, i)->def;
    2475       956850 :       if (!is_gimple_min_invariant (arg))
    2476              :         {
    2477       803932 :           gcc_assert (TREE_CODE (arg) == SSA_NAME);
    2478      1607864 :           *p = p->or_with (summary->conds,
    2479       803932 :                            nonconstant_names[SSA_NAME_VERSION (arg)]);
    2480       803932 :           if (*p == true)
    2481              :             return;
    2482              :         }
    2483              :     }
    2484              : 
    2485       159655 :   if (dump_file && (dump_flags & TDF_DETAILS))
    2486              :     {
    2487            3 :       fprintf (dump_file, "\t\tphi predicate: ");
    2488            3 :       p->dump (dump_file, summary->conds);
    2489              :     }
    2490       159655 :   nonconstant_names[SSA_NAME_VERSION (gimple_phi_result (phi))] = *p;
    2491              : }
    2492              : 
    2493              : /* For a typical usage of __builtin_expect (a<b, 1), we
    2494              :    may introduce an extra relation stmt:
    2495              :    With the builtin, we have
    2496              :      t1 = a <= b;
    2497              :      t2 = (long int) t1;
    2498              :      t3 = __builtin_expect (t2, 1);
    2499              :      if (t3 != 0)
    2500              :        goto ...
    2501              :    Without the builtin, we have
    2502              :      if (a<=b)
    2503              :        goto...
    2504              :    This affects the size/time estimation and may have
    2505              :    an impact on the earlier inlining.
    2506              :    Here find this pattern and fix it up later.  */
    2507              : 
    2508              : static gimple *
    2509     42360596 : find_foldable_builtin_expect (basic_block bb)
    2510              : {
    2511     42360596 :   gimple_stmt_iterator bsi;
    2512              : 
    2513    298048002 :   for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
    2514              :     {
    2515    213515628 :       gimple *stmt = gsi_stmt (bsi);
    2516    213515628 :       if (gimple_call_builtin_p (stmt, BUILT_IN_EXPECT)
    2517    213274432 :           || gimple_call_builtin_p (stmt, BUILT_IN_EXPECT_WITH_PROBABILITY)
    2518    426789983 :           || gimple_call_internal_p (stmt, IFN_BUILTIN_EXPECT))
    2519              :         {
    2520       374827 :           tree var = gimple_call_lhs (stmt);
    2521       374827 :           tree arg = gimple_call_arg (stmt, 0);
    2522       374827 :           use_operand_p use_p;
    2523       374827 :           gimple *use_stmt;
    2524       374827 :           bool match = false;
    2525       374827 :           bool done = false;
    2526              : 
    2527       374827 :           if (!var || !arg)
    2528            3 :             continue;
    2529       374824 :           gcc_assert (TREE_CODE (var) == SSA_NAME);
    2530              : 
    2531       748281 :           while (TREE_CODE (arg) == SSA_NAME)
    2532              :             {
    2533       748281 :               gimple *stmt_tmp = SSA_NAME_DEF_STMT (arg);
    2534       748281 :               if (!is_gimple_assign (stmt_tmp))
    2535              :                 break;
    2536       740904 :               switch (gimple_assign_rhs_code (stmt_tmp))
    2537              :                 {
    2538              :                   case LT_EXPR:
    2539              :                   case LE_EXPR:
    2540              :                   case GT_EXPR:
    2541              :                   case GE_EXPR:
    2542              :                   case EQ_EXPR:
    2543              :                   case NE_EXPR:
    2544              :                     match = true;
    2545              :                     done = true;
    2546              :                     break;
    2547              :                   CASE_CONVERT:
    2548              :                     break;
    2549              :                   default:
    2550              :                     done = true;
    2551              :                     break;
    2552              :                 }
    2553       373457 :               if (done)
    2554              :                 break;
    2555       373457 :               arg = gimple_assign_rhs1 (stmt_tmp);
    2556              :             }
    2557              : 
    2558       337763 :           if (match && single_imm_use (var, &use_p, &use_stmt)
    2559       712269 :               && gimple_code (use_stmt) == GIMPLE_COND)
    2560       188818 :             return use_stmt;
    2561              :         }
    2562              :     }
    2563              :   return NULL;
    2564              : }
    2565              : 
    2566              : /* Return true when the basic blocks contains only clobbers followed by RESX.
    2567              :    Such BBs are kept around to make removal of dead stores possible with
    2568              :    presence of EH and will be optimized out by optimize_clobbers later in the
    2569              :    game.
    2570              : 
    2571              :    NEED_EH is used to recurse in case the clobber has non-EH predecessors
    2572              :    that can be clobber only, too.. When it is false, the RESX is not necessary
    2573              :    on the end of basic block.  */
    2574              : 
    2575              : static bool
    2576     43022427 : clobber_only_eh_bb_p (basic_block bb, bool need_eh = true)
    2577              : {
    2578     43022427 :   gimple_stmt_iterator gsi = gsi_last_bb (bb);
    2579     43022427 :   edge_iterator ei;
    2580     43022427 :   edge e;
    2581              : 
    2582     43022427 :   if (need_eh)
    2583              :     {
    2584     42950563 :       if (gsi_end_p (gsi))
    2585              :         return false;
    2586     41796244 :       if (gimple_code (gsi_stmt (gsi)) != GIMPLE_RESX)
    2587              :         return false;
    2588      1201351 :       gsi_prev (&gsi);
    2589              :     }
    2590        71864 :   else if (!single_succ_p (bb))
    2591              :     return false;
    2592              : 
    2593      3223595 :   for (; !gsi_end_p (gsi); gsi_prev (&gsi))
    2594              :     {
    2595      3145246 :       gimple *stmt = gsi_stmt (gsi);
    2596      3145246 :       if (is_gimple_debug (stmt))
    2597      1100053 :         continue;
    2598      2045193 :       if (gimple_clobber_p (stmt))
    2599       960788 :         continue;
    2600      1084405 :       if (gimple_code (stmt) == GIMPLE_LABEL)
    2601              :         break;
    2602              :       return false;
    2603              :     }
    2604              : 
    2605              :   /* See if all predecessors are either throws or clobber only BBs.  */
    2606      3158122 :   FOR_EACH_EDGE (e, ei, bb->preds)
    2607      2566653 :     if (!(e->flags & EDGE_EH)
    2608      2566653 :         && !clobber_only_eh_bb_p (e->src, false))
    2609              :       return false;
    2610              : 
    2611              :   return true;
    2612              : }
    2613              : 
    2614              : /* Return true if STMT compute a floating point expression that may be affected
    2615              :    by -ffast-math and similar flags.  */
    2616              : 
    2617              : static bool
    2618     96993095 : fp_expression_p (gimple *stmt)
    2619              : {
    2620     96993095 :   ssa_op_iter i;
    2621     96993095 :   tree op;
    2622              : 
    2623    217751462 :   FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_DEF|SSA_OP_USE)
    2624    121379516 :     if (FLOAT_TYPE_P (TREE_TYPE (op)))
    2625              :       return true;
    2626              :   return false;
    2627              : }
    2628              : 
    2629              : /* Return true if T references memory location that is local
    2630              :    for the function (that means, dead after return) or read-only.  */
    2631              : 
    2632              : bool
    2633     61772955 : refs_local_or_readonly_memory_p (tree t)
    2634              : {
    2635              :   /* Non-escaping memory is fine.  */
    2636     61772955 :   t = get_base_address (t);
    2637     61772955 :   if ((TREE_CODE (t) == MEM_REF
    2638     61772955 :       || TREE_CODE (t) == TARGET_MEM_REF))
    2639     26107997 :     return points_to_local_or_readonly_memory_p (TREE_OPERAND (t, 0));
    2640              : 
    2641              :   /* Automatic variables are fine.  */
    2642     35664958 :   if (DECL_P (t)
    2643     35664958 :       && auto_var_in_fn_p (t, current_function_decl))
    2644              :     return true;
    2645              : 
    2646              :   /* Read-only variables are fine.  */
    2647     11504221 :   if (DECL_P (t) && TREE_READONLY (t))
    2648      1679860 :     return true;
    2649              : 
    2650              :   return false;
    2651              : }
    2652              : 
    2653              : /* Return true if T is a pointer pointing to memory location that is local
    2654              :    for the function (that means, dead after return) or read-only.  */
    2655              : 
    2656              : bool
    2657     75253272 : points_to_local_or_readonly_memory_p (tree t)
    2658              : {
    2659              :   /* See if memory location is clearly invalid.  */
    2660     75253272 :   if (integer_zerop (t))
    2661      2499576 :     return flag_delete_null_pointer_checks;
    2662     72753696 :   if (TREE_CODE (t) == SSA_NAME)
    2663              :     {
    2664              :       /* For IPA passes we can consinder accesses to return slot local
    2665              :          even if it is not local in the sense that memory is dead by
    2666              :          the end of founction.
    2667              :          The outer function will see a store in the call assignment
    2668              :          and thus this will do right thing for all uses of this
    2669              :          function in the current IPA passes (modref, pure/const discovery
    2670              :          and inlining heuristics).  */
    2671     46086746 :       if (DECL_RESULT (current_function_decl)
    2672     46086746 :           && DECL_BY_REFERENCE (DECL_RESULT (current_function_decl))
    2673     47236022 :           && t == ssa_default_def (cfun, DECL_RESULT (current_function_decl)))
    2674              :         return true;
    2675     45749758 :       return !ptr_deref_may_alias_global_p (t, false);
    2676              :     }
    2677     26666950 :   if (TREE_CODE (t) == ADDR_EXPR
    2678     26666950 :       && (TREE_CODE (TREE_OPERAND (t, 0)) != TARGET_MEM_REF
    2679         4407 :           || TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)) != INTEGER_CST))
    2680     13895387 :     return refs_local_or_readonly_memory_p (TREE_OPERAND (t, 0));
    2681              :   return false;
    2682              : }
    2683              : 
    2684              : /* Return true if T is a pointer pointing to memory location that is possible
    2685              :    sra candidate if all functions it is passed to are inlined.  */
    2686              : 
    2687              : static bool
    2688     40154494 : points_to_possible_sra_candidate_p (tree t)
    2689              : {
    2690     40154494 :   if (TREE_CODE (t) != ADDR_EXPR)
    2691              :     return false;
    2692              : 
    2693     12063452 :   t = get_base_address (TREE_OPERAND (t, 0));
    2694              : 
    2695              :   /* Automatic variables are fine.  */
    2696     12063452 :   if (DECL_P (t)
    2697     12063452 :       && auto_var_in_fn_p (t, current_function_decl))
    2698              :     return true;
    2699              :   return false;
    2700              : }
    2701              : 
    2702              : /* Return true if BB only calls builtin_unreachable.
    2703              :    We skip empty basic blocks, debug statements, clobbers and predicts.
    2704              :    CACHE is used to memoize already analyzed blocks.  */
    2705              : 
    2706              : static bool
    2707     28055591 : builtin_unreachable_bb_p (basic_block bb, vec<unsigned char> &cache)
    2708              : {
    2709     28055591 :   if (cache[bb->index])
    2710      2774571 :     return cache[bb->index] - 1;
    2711     25281020 :   gimple_stmt_iterator si;
    2712     25281020 :   auto_vec <basic_block, 4> visited_bbs;
    2713     25281020 :   bool ret = false;
    2714     26096155 :   while (true)
    2715              :     {
    2716     26096155 :       bool empty_bb = true;
    2717     26096155 :       visited_bbs.safe_push (bb);
    2718     26096155 :       cache[bb->index] = 3;
    2719     26096155 :       for (si = gsi_start_nondebug_bb (bb);
    2720     27616452 :            !gsi_end_p (si) && empty_bb;
    2721      1520297 :            gsi_next_nondebug (&si))
    2722              :         {
    2723     26244379 :           if (gimple_code (gsi_stmt (si)) != GIMPLE_PREDICT
    2724     25875996 :               && !gimple_clobber_p (gsi_stmt (si))
    2725     51001924 :               && !gimple_nop_p (gsi_stmt (si)))
    2726              :             {
    2727              :               empty_bb = false;
    2728              :               break;
    2729              :             }
    2730              :         }
    2731     26096155 :       if (!empty_bb)
    2732              :         break;
    2733              :       else
    2734      1372073 :         bb = single_succ_edge (bb)->dest;
    2735      1372073 :       if (cache[bb->index])
    2736              :         {
    2737       556938 :           ret = cache[bb->index] == 3 ? false : cache[bb->index] - 1;
    2738       556938 :           goto done;
    2739              :         }
    2740              :     }
    2741     24724082 :   if (gimple_call_builtin_p (gsi_stmt (si), BUILT_IN_UNREACHABLE)
    2742     24724082 :       || gimple_call_builtin_p (gsi_stmt (si), BUILT_IN_UNREACHABLE_TRAP))
    2743              :     ret = true;
    2744     25281020 : done:
    2745    101939215 :   for (basic_block vbb:visited_bbs)
    2746     26096155 :     cache[vbb->index] = (unsigned char)ret + 1;
    2747     25281020 :   return ret;
    2748     25281020 : }
    2749              : 
    2750              : static bool
    2751     14160878 : guards_builtin_unreachable (basic_block bb, vec<unsigned char> &cache)
    2752              : {
    2753     14160878 :   edge_iterator ei;
    2754     14160878 :   edge e;
    2755     41935945 :   FOR_EACH_EDGE (e, ei, bb->succs)
    2756     28055591 :     if (builtin_unreachable_bb_p (e->dest, cache))
    2757              :       {
    2758       280524 :         if (dump_file && (dump_flags & TDF_DETAILS))
    2759            1 :           fprintf (dump_file,
    2760              :                    "BB %i ends with conditional guarding __builtin_unreachable;"
    2761              :                    " conditinal is unnecessary\n", bb->index);
    2762              :         return true;
    2763              :       }
    2764              :   return false;
    2765              : }
    2766              : 
    2767              : #define STMT_NECESSARY GF_PLF_1
    2768              : 
    2769              : /* If STMT is not already marked necessary, mark it, and add it to the
    2770              :    worklist if ADD_TO_WORKLIST is true.  */
    2771              : 
    2772              : static inline void
    2773    177049784 : mark_stmt_necessary (gimple *stmt, auto_vec<gimple *> &worklist)
    2774              : {
    2775    177049784 :   gcc_assert (stmt);
    2776              : 
    2777    177049784 :   if (gimple_plf (stmt, STMT_NECESSARY))
    2778              :     return;
    2779              : 
    2780    147048185 :   if (dump_file && (dump_flags & TDF_DETAILS))
    2781              :     {
    2782          211 :       fprintf (dump_file, "Marking useful stmt: ");
    2783          211 :       print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
    2784          211 :       fprintf (dump_file, "\n");
    2785              :     }
    2786              : 
    2787    147048185 :   gimple_set_plf (stmt, STMT_NECESSARY, true);
    2788    147048185 :   worklist.safe_push (stmt);
    2789              : }
    2790              : 
    2791              : /* Mark the statement defining operand OP as necessary.  */
    2792              : 
    2793              : static inline void
    2794    124652605 : mark_operand_necessary (tree op, auto_vec<gimple *> &worklist)
    2795              : {
    2796    124652605 :   gimple *stmt = SSA_NAME_DEF_STMT (op);
    2797    124652605 :   if (gimple_nop_p (stmt))
    2798              :     return;
    2799    100791452 :   mark_stmt_necessary (stmt, worklist);
    2800              : }
    2801              : 
    2802              : /* Mark all statements that will remain in the body after optimizing out
    2803              :    conditionals guarding __builtin_unreachable which we keep to preserve
    2804              :    value ranges.  */
    2805              : 
    2806              : static void
    2807      7539970 : find_necessary_statements (struct cgraph_node *node)
    2808              : {
    2809      7539970 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    2810      7539970 :   auto_vec<unsigned char, 10> cache;
    2811      7539970 :   basic_block bb;
    2812      7539970 :   auto_vec<gimple *> worklist;
    2813              : 
    2814      7539970 :   cache.safe_grow_cleared (last_basic_block_for_fn (cfun));
    2815              :   /* Mark all obviously necessary statements.  */
    2816     50490533 :   FOR_EACH_BB_FN (bb, my_function)
    2817              :     {
    2818     42950563 :       for (gimple_stmt_iterator gsi = gsi_start_phis (bb);
    2819     54835996 :            !gsi_end_p (gsi); gsi_next (&gsi))
    2820     11885433 :         gimple_set_plf (gsi_stmt (gsi), STMT_NECESSARY, false);
    2821              : 
    2822    240478339 :       for (gimple_stmt_iterator bsi = gsi_start_bb (bb); !gsi_end_p (bsi);
    2823    154577213 :            gsi_next_nondebug (&bsi))
    2824              :         {
    2825    154577213 :           gimple *stmt = gsi_stmt (bsi);
    2826              : 
    2827    154577213 :           gimple_set_plf (stmt, STMT_NECESSARY, false);
    2828    154577213 :           if (gimple_has_side_effects (stmt)
    2829    126406390 :               || (is_ctrl_stmt (stmt)
    2830     22839392 :                   && (gimple_code (stmt) != GIMPLE_COND
    2831     14160878 :                       || !guards_builtin_unreachable (bb, cache)))
    2832    103847522 :               || gimple_store_p (stmt)
    2833    232917779 :               || gimple_code (stmt) == GIMPLE_ASM)
    2834     76258332 :             mark_stmt_necessary (stmt, worklist);
    2835              :         }
    2836              :     }
    2837    154588155 :   while (worklist.length () > 0)
    2838              :     {
    2839    147048185 :       gimple *stmt = worklist.pop ();
    2840              : 
    2841    147048185 :       if (dump_file && (dump_flags & TDF_DETAILS))
    2842              :         {
    2843          211 :           fprintf (dump_file, "processing: ");
    2844          211 :           print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
    2845          211 :           fprintf (dump_file, "\n");
    2846              :         }
    2847    147048185 :       if (gimple_code (stmt) == GIMPLE_PHI)
    2848     18733761 :         for (unsigned int k = 0; k < gimple_phi_num_args (stmt); k++)
    2849              :           {
    2850     13259151 :             tree arg = PHI_ARG_DEF (stmt, k);
    2851              : 
    2852     13259151 :             if (TREE_CODE (arg) == SSA_NAME)
    2853     10151007 :               mark_operand_necessary (arg, worklist);
    2854              :           }
    2855              :       else
    2856              :         {
    2857    141573575 :           ssa_op_iter iter;
    2858    141573575 :           tree use;
    2859              : 
    2860    256075173 :           FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2861    114501598 :             mark_operand_necessary (use, worklist);
    2862              :         }
    2863              :     }
    2864      7539970 : }
    2865              : 
    2866              : /* Analyze function body for NODE.
    2867              :    EARLY indicates run from early optimization pipeline.  */
    2868              : 
    2869              : static void
    2870      7539970 : analyze_function_body (struct cgraph_node *node, bool early)
    2871              : {
    2872      7539970 :   sreal time = opt_for_fn (node->decl, param_uninlined_function_time);
    2873              :   /* Estimate static overhead for function prologue/epilogue and alignment. */
    2874      7539970 :   int size = opt_for_fn (node->decl, param_uninlined_function_insns);
    2875              :   /* Benefits are scaled by probability of elimination that is in range
    2876              :      <0,2>.  */
    2877      7539970 :   basic_block bb;
    2878      7539970 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    2879      7539970 :   sreal freq;
    2880      7539970 :   class ipa_fn_summary *info = ipa_fn_summaries->get_create (node);
    2881      7539970 :   ipa_node_params *params_summary
    2882      7539970 :     = early ? NULL : ipa_node_params_sum->get (node);
    2883      7539970 :   ipa_predicate bb_predicate;
    2884      7539970 :   struct ipa_func_body_info fbi;
    2885      7539970 :   vec<ipa_predicate> nonconstant_names = vNULL;
    2886      7539970 :   int nblocks, n;
    2887      7539970 :   int *order;
    2888      7539970 :   gimple *fix_builtin_expect_stmt;
    2889              : 
    2890      7539970 :   gcc_assert (my_function && my_function->cfg);
    2891      7539970 :   gcc_assert (cfun == my_function);
    2892              : 
    2893      7539970 :   memset(&fbi, 0, sizeof(fbi));
    2894      7539970 :   vec_free (info->conds);
    2895      7539970 :   info->conds = NULL;
    2896      7539970 :   info->size_time_table.release ();
    2897      7539970 :   info->call_size_time_table.release ();
    2898              : 
    2899              :   /* When optimizing and analyzing for IPA inliner, initialize loop optimizer
    2900              :      so we can produce proper inline hints.
    2901              : 
    2902              :      When optimizing and analyzing for early inliner, initialize node params
    2903              :      so we can produce correct BB predicates.  */
    2904              : 
    2905      7539970 :   if (opt_for_fn (node->decl, optimize))
    2906              :     {
    2907      6620354 :       calculate_dominance_info (CDI_DOMINATORS);
    2908      6620354 :       calculate_dominance_info (CDI_POST_DOMINATORS);
    2909      6620354 :       if (!early)
    2910      1428114 :         loop_optimizer_init (LOOPS_NORMAL | LOOPS_HAVE_RECORDED_EXITS);
    2911              :       else
    2912              :         {
    2913      5192240 :           ipa_check_create_node_params ();
    2914      5192240 :           ipa_initialize_node_params (node);
    2915              :         }
    2916              : 
    2917      6620354 :       if (ipa_node_params_sum)
    2918              :         {
    2919      6620354 :           fbi.node = node;
    2920      6620354 :           fbi.info = ipa_node_params_sum->get (node);
    2921      6620354 :           fbi.bb_infos = vNULL;
    2922      6620354 :           fbi.bb_infos.safe_grow_cleared (last_basic_block_for_fn (cfun), true);
    2923      6620354 :           fbi.param_count = count_formal_params (node->decl);
    2924      6620354 :           fbi.aa_walk_budget = opt_for_fn (node->decl, param_ipa_max_aa_steps);
    2925              : 
    2926      6620354 :           nonconstant_names.safe_grow_cleared
    2927      6620354 :             (SSANAMES (my_function)->length (), true);
    2928              :         }
    2929              :     }
    2930              : 
    2931      7539970 :   if (dump_file)
    2932          249 :     fprintf (dump_file, "\nAnalyzing function body size: %s\n",
    2933              :              node->dump_name ());
    2934              : 
    2935              :   /* When we run into maximal number of entries, we assign everything to the
    2936              :      constant truth case.  Be sure to have it in list. */
    2937      7539970 :   bb_predicate = true;
    2938      7539970 :   info->account_size_time (0, 0, bb_predicate, bb_predicate);
    2939              : 
    2940      7539970 :   bb_predicate = ipa_predicate::not_inlined ();
    2941      7539970 :   info->account_size_time (opt_for_fn (node->decl,
    2942              :                                 param_uninlined_function_insns)
    2943              :                            * ipa_fn_summary::size_scale,
    2944      7539970 :                            opt_for_fn (node->decl,
    2945              :                                 param_uninlined_function_time),
    2946              :                            bb_predicate,
    2947              :                            bb_predicate);
    2948              : 
    2949              :   /* Only look for target information for inlinable functions.  */
    2950      7539970 :   bool scan_for_target_info =
    2951      7539970 :     info->inlinable
    2952     13568492 :     && targetm.target_option.need_ipa_fn_target_info (node->decl,
    2953      6028522 :                                                       info->target_info);
    2954              : 
    2955      7539970 :   if (fbi.info)
    2956      6620354 :     compute_bb_predicates (&fbi, node, info, params_summary);
    2957      7539970 :   find_necessary_statements (node);
    2958      7539970 :   const profile_count entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2959      7539970 :   order = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
    2960      7539970 :   nblocks = pre_and_rev_post_order_compute (NULL, order, false);
    2961     58030503 :   for (n = 0; n < nblocks; n++)
    2962              :     {
    2963     42950563 :       bb = BASIC_BLOCK_FOR_FN (cfun, order[n]);
    2964     42950563 :       freq = bb->count.to_sreal_scale (entry_count);
    2965     42950563 :       if (clobber_only_eh_bb_p (bb))
    2966              :         {
    2967       589967 :           if (dump_file && (dump_flags & TDF_DETAILS))
    2968            0 :             fprintf (dump_file, "\n Ignoring BB %i;"
    2969              :                      " it will be optimized away by cleanup_clobbers\n",
    2970              :                      bb->index);
    2971       589967 :           continue;
    2972              :         }
    2973              : 
    2974              :       /* TODO: Obviously predicates can be propagated down across CFG.  */
    2975     42360596 :       if (fbi.info)
    2976              :         {
    2977     35857718 :           if (bb->aux)
    2978     35857702 :             bb_predicate = *(ipa_predicate *)bb->aux;
    2979              :           else
    2980           16 :             bb_predicate = false;
    2981              :         }
    2982              :       else
    2983      6502878 :         bb_predicate = true;
    2984              : 
    2985     42360596 :       if (dump_file && (dump_flags & TDF_DETAILS))
    2986              :         {
    2987           69 :           fprintf (dump_file, "\n BB %i predicate:", bb->index);
    2988           69 :           bb_predicate.dump (dump_file, info->conds);
    2989              :         }
    2990              : 
    2991     42360596 :       if (fbi.info && nonconstant_names.exists ())
    2992              :         {
    2993     35857718 :           ipa_predicate phi_predicate;
    2994     35857718 :           bool first_phi = true;
    2995              : 
    2996     36651324 :           for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi);
    2997       793606 :                gsi_next (&bsi))
    2998              :             {
    2999      6636981 :               if (first_phi
    3000      6636981 :                   && !phi_result_unknown_predicate (&fbi, info,
    3001              :                                                     params_summary,
    3002              :                                                     bb,
    3003              :                                                     &phi_predicate,
    3004              :                                                     nonconstant_names))
    3005              :                 break;
    3006       793606 :               first_phi = false;
    3007       793606 :               if (dump_file && (dump_flags & TDF_DETAILS))
    3008              :                 {
    3009            3 :                   fprintf (dump_file, "  ");
    3010            3 :                   print_gimple_stmt (dump_file, gsi_stmt (bsi), 0);
    3011              :                 }
    3012       793606 :               predicate_for_phi_result (info, bsi.phi (), &phi_predicate,
    3013              :                                         nonconstant_names);
    3014              :             }
    3015              :         }
    3016              : 
    3017     42360596 :       fix_builtin_expect_stmt = find_foldable_builtin_expect (bb);
    3018              : 
    3019     42360596 :       for (gimple_stmt_iterator bsi = gsi_start_nondebug_bb (bb);
    3020    188350431 :            !gsi_end_p (bsi); gsi_next_nondebug (&bsi))
    3021              :         {
    3022    145989835 :           gimple *stmt = gsi_stmt (bsi);
    3023    145989835 :           if (!gimple_plf (stmt, STMT_NECESSARY))
    3024              :             {
    3025      5802845 :               if (dump_file && (dump_flags & TDF_DETAILS))
    3026              :                 {
    3027           19 :                   fprintf (dump_file, "  skipping unnecessary stmt ");
    3028           19 :                   print_gimple_stmt (dump_file, stmt, 0);
    3029              :                 }
    3030              :               /* TODO: const calls used only to produce values for
    3031              :                  builtion_unreachable guards should not be accounted.  However
    3032              :                  we still want to inline them and this does does not work well
    3033              :                  with the cost model.  For now account them as usual.  */
    3034      5802845 :               if (!is_gimple_call (stmt)
    3035      5802845 :                   || gimple_call_internal_p (stmt))
    3036      5507416 :                 continue;
    3037              :             }
    3038    140482419 :           int this_size = estimate_num_insns (stmt, &eni_size_weights);
    3039    140482419 :           int this_time = estimate_num_insns (stmt, &eni_time_weights);
    3040    140482419 :           int prob;
    3041    140482419 :           ipa_predicate will_be_nonconstant;
    3042              : 
    3043              :           /* This relation stmt should be folded after we remove
    3044              :              __builtin_expect call. Adjust the cost here.  */
    3045    140482419 :           if (stmt == fix_builtin_expect_stmt)
    3046              :             {
    3047       188380 :               this_size--;
    3048       188380 :               this_time--;
    3049              :             }
    3050              : 
    3051    140482419 :           if (dump_file && (dump_flags & TDF_DETAILS))
    3052              :             {
    3053          205 :               fprintf (dump_file, "  ");
    3054          205 :               print_gimple_stmt (dump_file, stmt, 0);
    3055          205 :               fprintf (dump_file, "\t\tfreq:%3.2f size:%3i time:%3i\n",
    3056              :                        freq.to_double (), this_size,
    3057              :                        this_time);
    3058              :             }
    3059              : 
    3060    140482419 :           if (is_gimple_call (stmt)
    3061    140482419 :               && !gimple_call_internal_p (stmt))
    3062              :             {
    3063     23807106 :               struct cgraph_edge *edge = node->get_edge (stmt);
    3064     23807106 :               ipa_call_summary *es = ipa_call_summaries->get_create (edge);
    3065              : 
    3066              :               /* Special case: results of BUILT_IN_CONSTANT_P will be always
    3067              :                  resolved as constant.  We however don't want to optimize
    3068              :                  out the cgraph edges.  */
    3069     23807106 :               if (nonconstant_names.exists ()
    3070     20881207 :                   && gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P)
    3071        48294 :                   && gimple_call_lhs (stmt)
    3072     23855400 :                   && TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME)
    3073              :                 {
    3074        48294 :                   ipa_predicate false_p = false;
    3075        48294 :                   nonconstant_names[SSA_NAME_VERSION (gimple_call_lhs (stmt))]
    3076        48294 :                     = false_p;
    3077              :                 }
    3078     23807106 :               if (ipa_node_params_sum)
    3079              :                 {
    3080     20894028 :                   int count = gimple_call_num_args (stmt);
    3081     20894028 :                   int i;
    3082              : 
    3083     20894028 :                   if (count)
    3084     17984259 :                     es->param.safe_grow_cleared (count, true);
    3085     61048522 :                   for (i = 0; i < count; i++)
    3086              :                     {
    3087     40154494 :                       int prob = param_change_prob (&fbi, stmt, i);
    3088     40154494 :                       gcc_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
    3089     40154494 :                       es->param[i].change_prob = prob;
    3090     40154494 :                       es->param[i].points_to_local_or_readonly_memory
    3091     40154494 :                          = points_to_local_or_readonly_memory_p
    3092     40154494 :                              (gimple_call_arg (stmt, i));
    3093     40154494 :                       es->param[i].points_to_possible_sra_candidate
    3094     40154494 :                          = points_to_possible_sra_candidate_p
    3095     40154494 :                              (gimple_call_arg (stmt, i));
    3096              :                     }
    3097              :                 }
    3098              :               /* We cannot setup VLA parameters during inlining.  */
    3099     69882822 :               for (unsigned int i = 0; i < gimple_call_num_args (stmt); ++i)
    3100     46076112 :                 if (TREE_CODE (gimple_call_arg (stmt, i)) == WITH_SIZE_EXPR)
    3101              :                   {
    3102          396 :                     edge->inline_failed = CIF_FUNCTION_NOT_INLINABLE;
    3103          396 :                     break;
    3104              :                   }
    3105     23807106 :               es->call_stmt_size = this_size;
    3106     23807106 :               es->call_stmt_time = this_time;
    3107     23807106 :               es->loop_depth = bb_loop_depth (bb);
    3108     23807106 :               edge_set_predicate (edge, &bb_predicate);
    3109     23807106 :               if (edge->speculative)
    3110              :                 {
    3111            0 :                   cgraph_edge *indirect
    3112            0 :                         = edge->speculative_call_indirect_edge ();
    3113            0 :                   ipa_call_summary *es2
    3114            0 :                          = ipa_call_summaries->get_create (indirect);
    3115            0 :                   ipa_call_summaries->duplicate (edge, indirect,
    3116              :                                                  es, es2);
    3117              : 
    3118              :                   /* Edge is the first direct call.
    3119              :                      create and duplicate call summaries for multiple
    3120              :                      speculative call targets.  */
    3121            0 :                   for (cgraph_edge *direct
    3122            0 :                          = edge->next_speculative_call_target ();
    3123            0 :                        direct;
    3124            0 :                        direct = direct->next_speculative_call_target ())
    3125              :                     {
    3126            0 :                       ipa_call_summary *es3
    3127            0 :                         = ipa_call_summaries->get_create (direct);
    3128            0 :                       ipa_call_summaries->duplicate (edge, direct,
    3129              :                                                      es, es3);
    3130              :                     }
    3131              :                 }
    3132              : 
    3133              :               /* If dealing with a carrying edge, copy its summary over to its
    3134              :                  attached edges as well.  */
    3135     23807106 :               if (edge->has_callback)
    3136              :                 {
    3137        15132 :                   cgraph_edge *cbe;
    3138        30265 :                   for (cbe = edge->first_callback_edge (); cbe;
    3139        15133 :                        cbe = cbe->next_callback_edge ())
    3140              :                     {
    3141        15133 :                       ipa_call_summary *es2 = ipa_call_summaries->get_create (cbe);
    3142        15133 :                       ipa_call_summaries->duplicate (edge, cbe, es, es2);
    3143              :                       /* Unlike speculative edges, callback edges have no real
    3144              :                          size or time; the call doesn't exist.  Reflect that in
    3145              :                          their summaries.  */
    3146        15133 :                       es2->call_stmt_size = 0;
    3147        15133 :                       es2->call_stmt_time = 0;
    3148              :                     }
    3149              :                 }
    3150              :             }
    3151              : 
    3152              :           /* TODO: When conditional jump or switch is known to be constant, but
    3153              :              we did not translate it into the predicates, we really can account
    3154              :              just maximum of the possible paths.  */
    3155    140482419 :           if (fbi.info)
    3156    118055891 :             will_be_nonconstant
    3157    118055891 :               = will_be_nonconstant_predicate (&fbi, info, params_summary,
    3158              :                                                stmt, nonconstant_names);
    3159              :           else
    3160     22426528 :             will_be_nonconstant = true;
    3161    140482419 :           if (this_time || this_size)
    3162              :             {
    3163    114793716 :               sreal final_time = (sreal)this_time * freq;
    3164    114793716 :               prob = eliminated_by_inlining_prob (&fbi, stmt);
    3165    114793716 :               if (prob == 1 && dump_file && (dump_flags & TDF_DETAILS))
    3166           11 :                 fprintf (dump_file,
    3167              :                          "\t\t50%% will be eliminated by inlining\n");
    3168    114793716 :               if (prob == 2 && dump_file && (dump_flags & TDF_DETAILS))
    3169           20 :                 fprintf (dump_file, "\t\tWill be eliminated by inlining\n");
    3170              : 
    3171    114793716 :               ipa_predicate p = bb_predicate & will_be_nonconstant;
    3172    114793716 :               int parm = load_or_store_of_ptr_parameter (&fbi, stmt);
    3173    114793716 :               ipa_predicate sra_predicate = true;
    3174    114793716 :               if (parm != -1)
    3175     14776036 :                 sra_predicate &= add_condition (info, params_summary, parm,
    3176              :                                                 ptr_type_node, NULL,
    3177      7388018 :                                                 ipa_predicate::not_sra_candidate, NULL, 0);
    3178              : 
    3179              :               /* We can ignore statement when we proved it is never going
    3180              :                  to happen, but we cannot do that for call statements
    3181              :                  because edges are accounted specially.  */
    3182              : 
    3183    229587432 :               if (*(is_gimple_call (stmt) ? &bb_predicate : &p) != false)
    3184              :                 {
    3185    114028416 :                   time += final_time;
    3186    114028416 :                   size += this_size;
    3187              :                 }
    3188              : 
    3189              :               /* We account everything but the calls.  Calls have their own
    3190              :                  size/time info attached to cgraph edges.  This is necessary
    3191              :                  in order to make the cost disappear after inlining.  */
    3192    114793716 :               if (!is_gimple_call (stmt))
    3193              :                 {
    3194     91730985 :                   if (prob)
    3195              :                     {
    3196     15520014 :                       ipa_predicate ip
    3197     15520014 :                         = bb_predicate & ipa_predicate::not_inlined () & sra_predicate;
    3198     31040028 :                       info->account_size_time (this_size * prob,
    3199     15520014 :                                                (final_time * prob) / 2, ip,
    3200              :                                                p);
    3201              :                     }
    3202     15520014 :                   if (prob != 2)
    3203    169064048 :                     info->account_size_time (this_size * (2 - prob),
    3204     84532024 :                                              (final_time * (2 - prob) / 2),
    3205    169064048 :                                              bb_predicate & sra_predicate,
    3206              :                                              p);
    3207              :                 }
    3208              : 
    3209    114793716 :               if (!info->fp_expressions && fp_expression_p (stmt))
    3210              :                 {
    3211       621149 :                   info->fp_expressions = true;
    3212       621149 :                   if (dump_file)
    3213            9 :                     fprintf (dump_file, "   fp_expression set\n");
    3214              :                 }
    3215              :             }
    3216              : 
    3217              :           /* For target specific information, we want to scan all statements
    3218              :              rather than those statements with non-zero weights, to avoid
    3219              :              missing to scan something interesting for target information,
    3220              :              such as: internal function calls.  */
    3221    140482419 :           if (scan_for_target_info)
    3222            0 :             scan_for_target_info =
    3223            0 :               targetm.target_option.update_ipa_fn_target_info
    3224            0 :               (info->target_info, stmt);
    3225              : 
    3226              :           /* Account cost of address calculations in the statements.  */
    3227    543500196 :           for (unsigned int i = 0; i < gimple_num_ops (stmt); i++)
    3228              :             {
    3229    403017777 :               for (tree op = gimple_op (stmt, i);
    3230    775616435 :                    op && handled_component_p (op);
    3231     48636262 :                    op = TREE_OPERAND (op, 0))
    3232     48636262 :                 if ((TREE_CODE (op) == ARRAY_REF
    3233     48636262 :                      || TREE_CODE (op) == ARRAY_RANGE_REF)
    3234     48636262 :                     && TREE_CODE (TREE_OPERAND (op, 1)) == SSA_NAME)
    3235              :                   {
    3236      2421772 :                     ipa_predicate p = bb_predicate;
    3237      2421772 :                     if (fbi.info)
    3238      1895496 :                       p = p & will_be_nonconstant_expr_predicate
    3239      1895496 :                                  (&fbi, info, params_summary,
    3240      1895496 :                                   TREE_OPERAND (op, 1),
    3241      1895496 :                                   nonconstant_names);
    3242      2421772 :                     if (p != false)
    3243              :                       {
    3244      2416350 :                         time += freq;
    3245      2416350 :                         size += 1;
    3246      2416350 :                         if (dump_file)
    3247           24 :                           fprintf (dump_file,
    3248              :                                    "\t\tAccounting address calculation.\n");
    3249      2416350 :                         info->account_size_time (ipa_fn_summary::size_scale,
    3250              :                                                  freq,
    3251              :                                                  bb_predicate,
    3252              :                                                  p);
    3253              :                       }
    3254              :                   }
    3255              :             }
    3256              : 
    3257              :         }
    3258              :     }
    3259      7539970 :   free (order);
    3260              : 
    3261      7539970 :   if (nonconstant_names.exists () && !early)
    3262              :     {
    3263      1428114 :       ipa_fn_summary *s = ipa_fn_summaries->get (node);
    3264      1428114 :       unsigned max_loop_predicates = opt_for_fn (node->decl,
    3265              :                                                  param_ipa_max_loop_predicates);
    3266              : 
    3267      1428114 :       if (dump_file && (dump_flags & TDF_DETAILS))
    3268           16 :         flow_loops_dump (dump_file, NULL, 0);
    3269      1428114 :       scev_initialize ();
    3270      4920099 :       for (auto loop : loops_list (cfun, 0))
    3271              :         {
    3272       635757 :           ipa_predicate loop_iterations = true;
    3273       635757 :           sreal header_freq;
    3274       635757 :           edge ex;
    3275       635757 :           unsigned int j;
    3276       635757 :           class tree_niter_desc niter_desc;
    3277       635757 :           if (!loop->header->aux)
    3278            0 :             continue;
    3279              : 
    3280       635757 :           profile_count hdr_count = loop->header->count;
    3281       635757 :           sreal hdr_freq = hdr_count.to_sreal_scale (entry_count);
    3282              : 
    3283       635757 :           bb_predicate = *(ipa_predicate *)loop->header->aux;
    3284       635757 :           auto_vec<edge> exits = get_loop_exit_edges (loop);
    3285      2308833 :           FOR_EACH_VEC_ELT (exits, j, ex)
    3286      1037319 :             if (number_of_iterations_exit (loop, ex, &niter_desc, false)
    3287      1037319 :                 && !is_gimple_min_invariant (niter_desc.niter))
    3288              :             {
    3289       155947 :               ipa_predicate will_be_nonconstant
    3290       155947 :                 = will_be_nonconstant_expr_predicate (&fbi, info,
    3291              :                                                       params_summary,
    3292              :                                                       niter_desc.niter,
    3293              :                                                       nonconstant_names);
    3294       155947 :               if (will_be_nonconstant != true)
    3295        62750 :                 will_be_nonconstant = bb_predicate & will_be_nonconstant;
    3296       155947 :               if (will_be_nonconstant != true
    3297       218697 :                   && will_be_nonconstant != false)
    3298        62197 :                 loop_iterations &= will_be_nonconstant;
    3299              :             }
    3300       635757 :           add_freqcounting_predicate (&s->loop_iterations, loop_iterations,
    3301              :                                       hdr_freq, max_loop_predicates);
    3302       635759 :         }
    3303              : 
    3304              :       /* To avoid quadratic behavior we analyze stride predicates only
    3305              :          with respect to the containing loop.  Thus we simply iterate
    3306              :          over all defs in the outermost loop body.  */
    3307      1428114 :       for (class loop *loop = loops_for_fn (cfun)->tree_root->inner;
    3308      1930542 :            loop != NULL; loop = loop->next)
    3309              :         {
    3310       502428 :           ipa_predicate loop_stride = true;
    3311       502428 :           basic_block *body = get_loop_body (loop);
    3312       502428 :           profile_count hdr_count = loop->header->count;
    3313       502428 :           sreal hdr_freq = hdr_count.to_sreal_scale (entry_count);
    3314      3457137 :           for (unsigned i = 0; i < loop->num_nodes; i++)
    3315              :             {
    3316      2452281 :               gimple_stmt_iterator gsi;
    3317      2452281 :               if (!body[i]->aux)
    3318            8 :                 continue;
    3319              : 
    3320      2452273 :               bb_predicate = *(ipa_predicate *)body[i]->aux;
    3321     16653482 :               for (gsi = gsi_start_bb (body[i]); !gsi_end_p (gsi);
    3322     11748936 :                    gsi_next (&gsi))
    3323              :                 {
    3324     11748936 :                   gimple *stmt = gsi_stmt (gsi);
    3325              : 
    3326     11748936 :                   if (!is_gimple_assign (stmt))
    3327     11598247 :                     continue;
    3328              : 
    3329      5527885 :                   tree def = gimple_assign_lhs (stmt);
    3330      5527885 :                   if (TREE_CODE (def) != SSA_NAME)
    3331      1056595 :                     continue;
    3332              : 
    3333      4471290 :                   affine_iv iv;
    3334      8942580 :                   if (!simple_iv (loop_containing_stmt (stmt),
    3335              :                                   loop_containing_stmt (stmt),
    3336              :                                   def, &iv, true)
    3337      4471290 :                       || is_gimple_min_invariant (iv.step))
    3338      4320601 :                     continue;
    3339              : 
    3340       150689 :                   ipa_predicate will_be_nonconstant
    3341       150689 :                     = will_be_nonconstant_expr_predicate (&fbi, info,
    3342              :                                                           params_summary,
    3343              :                                                           iv.step,
    3344              :                                                           nonconstant_names);
    3345       150689 :                   if (will_be_nonconstant != true)
    3346        55815 :                     will_be_nonconstant = bb_predicate & will_be_nonconstant;
    3347       150689 :                   if (will_be_nonconstant != true
    3348       206504 :                       && will_be_nonconstant != false)
    3349        46220 :                     loop_stride = loop_stride & will_be_nonconstant;
    3350              :                 }
    3351              :             }
    3352       502428 :           add_freqcounting_predicate (&s->loop_strides, loop_stride,
    3353              :                                       hdr_freq, max_loop_predicates);
    3354       502428 :           free (body);
    3355              :         }
    3356      1428114 :       scev_finalize ();
    3357              :     }
    3358     65570473 :   FOR_ALL_BB_FN (bb, my_function)
    3359              :     {
    3360     58030503 :       edge e;
    3361     58030503 :       edge_iterator ei;
    3362              : 
    3363     58030503 :       if (bb->aux)
    3364     43003468 :         edge_predicate_pool.remove ((ipa_predicate *)bb->aux);
    3365     58030503 :       bb->aux = NULL;
    3366    123340508 :       FOR_EACH_EDGE (e, ei, bb->succs)
    3367              :         {
    3368     65310005 :           if (e->aux)
    3369      2623391 :             edge_predicate_pool.remove ((ipa_predicate *)e->aux);
    3370     65310005 :           e->aux = NULL;
    3371              :         }
    3372              :     }
    3373      7539970 :   ipa_fn_summary *s = ipa_fn_summaries->get (node);
    3374      7539970 :   ipa_size_summary *ss = ipa_size_summaries->get (node);
    3375      7539970 :   s->time = time;
    3376      7539970 :   ss->self_size = size;
    3377      7539970 :   nonconstant_names.release ();
    3378      7539970 :   ipa_release_body_info (&fbi);
    3379      7539970 :   if (opt_for_fn (node->decl, optimize))
    3380              :     {
    3381      6620354 :       if (!early)
    3382      1428114 :         loop_optimizer_finalize ();
    3383      5192240 :       else if (!ipa_edge_args_sum)
    3384      5192226 :         ipa_free_all_node_params ();
    3385      6620354 :       free_dominance_info (CDI_DOMINATORS);
    3386      6620354 :       free_dominance_info (CDI_POST_DOMINATORS);
    3387              :     }
    3388      7539970 :   if (dump_file)
    3389              :     {
    3390          249 :       fprintf (dump_file, "\n");
    3391          249 :       ipa_dump_fn_summary (dump_file, node);
    3392              :     }
    3393      7539970 : }
    3394              : 
    3395              : 
    3396              : /* Compute function summary.
    3397              :    EARLY is true when we compute parameters during early opts.  */
    3398              : 
    3399              : void
    3400      7541322 : compute_fn_summary (struct cgraph_node *node, bool early)
    3401              : {
    3402      7541322 :   HOST_WIDE_INT self_stack_size;
    3403      7541322 :   struct cgraph_edge *e;
    3404              : 
    3405      7541322 :   gcc_assert (!node->inlined_to);
    3406              : 
    3407      7541322 :   if (!ipa_fn_summaries)
    3408       218751 :     ipa_fn_summary_alloc ();
    3409              : 
    3410              :   /* Create a new ipa_fn_summary.  */
    3411      7541322 :   ((ipa_fn_summary_t *)ipa_fn_summaries)->remove_callees (node);
    3412      7541322 :   ipa_fn_summaries->remove (node);
    3413      7541322 :   class ipa_fn_summary *info = ipa_fn_summaries->get_create (node);
    3414      7541322 :   class ipa_size_summary *size_info = ipa_size_summaries->get_create (node);
    3415              : 
    3416              :   /* Estimate the stack size for the function if we're optimizing.  */
    3417     13242044 :   self_stack_size = optimize && !node->thunk
    3418     14161676 :                     ? estimated_stack_frame_size (node) : 0;
    3419      7541322 :   size_info->estimated_self_stack_size = self_stack_size;
    3420      7541322 :   info->estimated_stack_size = self_stack_size;
    3421              : 
    3422      7541322 :   if (node->thunk)
    3423              :     {
    3424         1352 :       ipa_call_summary *es = ipa_call_summaries->get_create (node->callees);
    3425         1352 :       ipa_predicate t = true;
    3426              : 
    3427         1352 :       node->can_change_signature = false;
    3428         1352 :       es->call_stmt_size = eni_size_weights.call_cost;
    3429         1352 :       es->call_stmt_time = eni_time_weights.call_cost;
    3430         4056 :       info->account_size_time (ipa_fn_summary::size_scale
    3431         1352 :                                * opt_for_fn (node->decl,
    3432              :                                  param_uninlined_function_thunk_insns),
    3433         1352 :                                opt_for_fn (node->decl,
    3434              :                                  param_uninlined_function_thunk_time), t, t);
    3435         1352 :       t = ipa_predicate::not_inlined ();
    3436         1352 :       info->account_size_time (2 * ipa_fn_summary::size_scale, 0, t, t);
    3437         1352 :       ipa_update_overall_fn_summary (node);
    3438         1352 :       size_info->self_size = size_info->size;
    3439         1352 :       if (stdarg_p (TREE_TYPE (node->decl)))
    3440              :         {
    3441            9 :           info->inlinable = false;
    3442            9 :           node->callees->inline_failed = CIF_VARIADIC_THUNK;
    3443              :         }
    3444              :       else
    3445         1343 :         info->inlinable = true;
    3446              :     }
    3447              :   else
    3448              :     {
    3449              :        /* Even is_gimple_min_invariant rely on current_function_decl.  */
    3450      7539970 :        push_cfun (DECL_STRUCT_FUNCTION (node->decl));
    3451              : 
    3452              :        /* During IPA profile merging we may be called w/o virtual SSA form
    3453              :           built.  */
    3454      7539970 :        update_ssa (TODO_update_ssa_only_virtuals);
    3455              : 
    3456              :        /* Can this function be inlined at all?  */
    3457      7539970 :        if (!opt_for_fn (node->decl, optimize)
    3458      8459586 :            && !lookup_attribute ("always_inline",
    3459       919616 :                                  DECL_ATTRIBUTES (node->decl)))
    3460       848522 :          info->inlinable = false;
    3461              :        else
    3462      6691448 :          info->inlinable = tree_inlinable_function_p (node->decl);
    3463              : 
    3464      7539970 :        bool no_signature = false;
    3465              : 
    3466              :        /* Don't allow signature changes for functions which have
    3467              :           [[gnu::musttail]] or [[clang::musttail]] calls.  Sometimes
    3468              :           (more often on targets which pass everything on the stack)
    3469              :           signature changes can result in tail calls being impossible
    3470              :           even when without the signature changes they would be ok.
    3471              :           See PR121023.  */
    3472      7539970 :        if (cfun->has_musttail)
    3473              :          {
    3474         1445 :            if (dump_file)
    3475            0 :             fprintf (dump_file, "No signature change:"
    3476              :                      " function has calls with musttail attribute.\n");
    3477              :            no_signature = true;
    3478              :          }
    3479              : 
    3480              :        /* Type attributes can use parameter indices to describe them.
    3481              :           Special case fn spec since we can safely preserve them in
    3482              :           modref summaries.  */
    3483      7539970 :        for (tree list = TYPE_ATTRIBUTES (TREE_TYPE (node->decl));
    3484      7941504 :             list && !no_signature; list = TREE_CHAIN (list))
    3485       401534 :         if (!ipa_param_adjustments::type_attribute_allowed_p
    3486       401534 :                         (get_attribute_name (list)))
    3487              :            {
    3488       159549 :              if (dump_file)
    3489              :                 {
    3490            0 :                   fprintf (dump_file, "No signature change:"
    3491              :                            " function type has unhandled attribute %s.\n",
    3492            0 :                            IDENTIFIER_POINTER (get_attribute_name (list)));
    3493              :                 }
    3494              :              no_signature = true;
    3495              :            }
    3496      7539970 :        for (tree parm = DECL_ARGUMENTS (node->decl);
    3497     22482830 :             parm && !no_signature; parm = DECL_CHAIN (parm))
    3498     14942860 :          if (variably_modified_type_p (TREE_TYPE (parm), node->decl))
    3499              :            {
    3500        15974 :              if (dump_file)
    3501              :                 {
    3502            0 :                   fprintf (dump_file, "No signature change:"
    3503              :                            " has parameter with variably modified type.\n");
    3504              :                 }
    3505              :              no_signature = true;
    3506              :            }
    3507              : 
    3508              :        /* Likewise for #pragma omp declare simd functions or functions
    3509              :           with simd attribute.  */
    3510      7539970 :        if (no_signature
    3511     14902972 :            || lookup_attribute ("omp declare simd",
    3512      7363002 :                                 DECL_ATTRIBUTES (node->decl)))
    3513       178680 :          node->can_change_signature = false;
    3514              :        else
    3515              :          {
    3516              :            /* Otherwise, inlinable functions always can change signature.  */
    3517      7361290 :            if (info->inlinable)
    3518      5948505 :              node->can_change_signature = true;
    3519              :            else
    3520              :              {
    3521              :                /* Functions calling builtin_apply cannot change signature.  */
    3522      5455717 :                for (e = node->callees; e; e = e->next_callee)
    3523              :                  {
    3524      4075699 :                    tree cdecl = e->callee->decl;
    3525      4075699 :                    if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS,
    3526              :                                                  BUILT_IN_VA_START))
    3527              :                      break;
    3528              :                  }
    3529      1412785 :                node->can_change_signature = !e;
    3530              :              }
    3531              :          }
    3532      7539970 :        analyze_function_body (node, early);
    3533      7539970 :        pop_cfun ();
    3534              :      }
    3535              : 
    3536              :   /* Inlining characteristics are maintained by the cgraph_mark_inline.  */
    3537      7541322 :   size_info->size = size_info->self_size;
    3538      7541322 :   info->estimated_stack_size = size_info->estimated_self_stack_size;
    3539              : 
    3540              :   /* Code above should compute exactly the same result as
    3541              :      ipa_update_overall_fn_summary except for case when speculative
    3542              :      edges are present since these are accounted to size but not
    3543              :      self_size. Do not compare time since different order the roundoff
    3544              :      errors result in slight changes.  */
    3545      7541322 :   ipa_update_overall_fn_summary (node);
    3546      7541322 :   if (flag_checking)
    3547              :     {
    3548      8026424 :       for (e = node->indirect_calls; e; e = e->next_callee)
    3549       485184 :        if (e->speculative)
    3550              :          break;
    3551      7541240 :       gcc_assert (e || size_info->size == size_info->self_size);
    3552              :     }
    3553      7541322 : }
    3554              : 
    3555              : 
    3556              : /* Compute parameters of functions used by inliner using
    3557              :    current_function_decl.  */
    3558              : 
    3559              : static unsigned int
    3560      6048724 : compute_fn_summary_for_current (void)
    3561              : {
    3562      6048724 :   compute_fn_summary (cgraph_node::get (current_function_decl), true);
    3563      6048724 :   return 0;
    3564              : }
    3565              : 
    3566              : /* Estimate benefit devirtualizing indirect edge IE and return true if it can
    3567              :    be devirtualized and inlined, provided m_known_vals, m_known_contexts and
    3568              :    m_known_aggs in AVALS.  Return false straight away if AVALS is NULL.  */
    3569              : 
    3570              : static bool
    3571      5014473 : estimate_edge_devirt_benefit (struct cgraph_edge *ie,
    3572              :                               int *size, int *time,
    3573              :                               ipa_call_arg_values *avals)
    3574              : {
    3575      5014473 :   tree target;
    3576      5014473 :   struct cgraph_node *callee;
    3577      5014473 :   class ipa_fn_summary *isummary;
    3578      5014473 :   enum availability avail;
    3579      5014473 :   bool speculative;
    3580              : 
    3581      5014473 :   if (!avals
    3582      5014473 :       || (!avals->m_known_vals.length() && !avals->m_known_contexts.length ()))
    3583              :     return false;
    3584      1513558 :   if (!opt_for_fn (ie->caller->decl, flag_indirect_inlining))
    3585              :     return false;
    3586              : 
    3587      1507107 :   target = ipa_get_indirect_edge_target
    3588      1507107 :     (ie->callee ? ie->speculative_call_indirect_edge () : ie,
    3589              :      avals, &speculative);
    3590      1507107 :   if (!target || speculative)
    3591              :     return false;
    3592              : 
    3593              :   /* If this is speculative call, turn its cost into 0; we will account
    3594              :      the call when processing the indirect call.  */
    3595       219585 :   if (ie->callee)
    3596              :     {
    3597         4549 :       gcc_checking_assert (ie->speculative && *size > 0);
    3598         4549 :       *size = 0;
    3599         4549 :       *time = 0;
    3600              :     }
    3601              :   else
    3602              :     {
    3603              :       /* Account for difference in cost between indirect and direct calls.  */
    3604       215036 :       *size -= (eni_size_weights.indirect_call_cost - eni_size_weights.call_cost);
    3605       215036 :       *time -= (eni_time_weights.indirect_call_cost - eni_time_weights.call_cost);
    3606              :     }
    3607       219585 :   gcc_checking_assert (*time >= 0);
    3608       219585 :   gcc_checking_assert (*size >= 0);
    3609              : 
    3610       219585 :   callee = cgraph_node::get (target);
    3611       219585 :   if (!callee || !callee->definition)
    3612              :     return false;
    3613       198950 :   callee = callee->function_symbol (&avail);
    3614       198950 :   if (avail < AVAIL_AVAILABLE)
    3615              :     return false;
    3616       198900 :   isummary = ipa_fn_summaries->get (callee);
    3617       198900 :   if (isummary == NULL)
    3618              :     return false;
    3619              : 
    3620       198886 :   return isummary->inlinable;
    3621              : }
    3622              : 
    3623              : /* Increase SIZE, MIN_SIZE (if non-NULL) and TIME for size and time needed to
    3624              :    handle edge E with probability PROB.  Set HINTS accordingly if edge may be
    3625              :    devirtualized.  AVALS, if non-NULL, describes the context of the call site
    3626              :    as far as values of parameters are concerned.  */
    3627              : 
    3628              : static inline void
    3629    224797427 : estimate_edge_size_and_time (struct cgraph_edge *e, int *size, int *min_size,
    3630              :                              sreal *time, ipa_call_arg_values *avals,
    3631              :                              ipa_hints *hints)
    3632              : {
    3633    224797427 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
    3634    224797427 :   int call_size = es->call_stmt_size;
    3635    224797427 :   int call_time = es->call_stmt_time;
    3636    224797427 :   int cur_size;
    3637              : 
    3638    220394200 :   if ((!e->callee || e->speculative)
    3639    225408673 :       && estimate_edge_devirt_benefit (e, &call_size, &call_time, avals))
    3640              :     {
    3641       198640 :       if (hints && e->maybe_hot_p ())
    3642       189281 :         *hints |= INLINE_HINT_indirect_call;
    3643              :     }
    3644    224797427 :   cur_size = call_size * ipa_fn_summary::size_scale;
    3645    224797427 :   *size += cur_size;
    3646    224797427 :   if (min_size)
    3647     30023475 :     *min_size += cur_size;
    3648    224797427 :   if (time)
    3649    214379943 :     *time += ((sreal)call_time) * e->sreal_frequency ();
    3650    224797427 : }
    3651              : 
    3652              : 
    3653              : /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all
    3654              :    calls in NODE.  POSSIBLE_TRUTHS and AVALS describe the context of the call
    3655              :    site.
    3656              : 
    3657              :    Helper for estimate_calls_size_and_time which does the same but
    3658              :    (in most cases) faster.  */
    3659              : 
    3660              : static void
    3661     81999689 : estimate_calls_size_and_time_1 (struct cgraph_node *node, int *size,
    3662              :                                 int *min_size, sreal *time,
    3663              :                                 ipa_hints *hints,
    3664              :                                 clause_t possible_truths,
    3665              :                                 ipa_call_arg_values *avals)
    3666              : {
    3667     81999689 :   struct cgraph_edge *e;
    3668    388707505 :   for (e = node->callees; e; e = e->next_callee)
    3669              :     {
    3670    306707816 :       if (!e->inline_failed)
    3671              :         {
    3672     60513998 :           gcc_checking_assert (!ipa_call_summaries->get (e));
    3673     60513998 :           estimate_calls_size_and_time_1 (e->callee, size, min_size, time,
    3674              :                                           hints, possible_truths, avals);
    3675              : 
    3676     60513998 :           continue;
    3677              :         }
    3678    246193818 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3679              : 
    3680              :       /* Do not care about zero sized builtins.  */
    3681    246193818 :       if (!es->call_stmt_size)
    3682              :         {
    3683     34789181 :           gcc_checking_assert (!es->call_stmt_time);
    3684     34789181 :           continue;
    3685              :         }
    3686    211404637 :       if (!es->predicate
    3687    211404637 :           || es->predicate->evaluate (possible_truths))
    3688              :         {
    3689              :           /* Predicates of calls shall not use NOT_CHANGED codes,
    3690              :              so we do not need to compute probabilities.  */
    3691    208840565 :           estimate_edge_size_and_time (e, size,
    3692    208840565 :                                        es->predicate ? NULL : min_size,
    3693              :                                        time, avals, hints);
    3694              :         }
    3695              :     }
    3696     86114376 :   for (e = node->indirect_calls; e; e = e->next_callee)
    3697              :     {
    3698      4114687 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3699      4114687 :       if (!es->predicate
    3700      4114687 :           || es->predicate->evaluate (possible_truths))
    3701      4082505 :         estimate_edge_size_and_time (e, size,
    3702      4082505 :                                      es->predicate ? NULL : min_size,
    3703              :                                      time, avals, hints);
    3704              :     }
    3705     81999689 : }
    3706              : 
    3707              : /* Populate sum->call_size_time_table for edges from NODE.  */
    3708              : 
    3709              : static void
    3710      3337887 : summarize_calls_size_and_time (struct cgraph_node *node,
    3711              :                                ipa_fn_summary *sum)
    3712              : {
    3713      3337887 :   struct cgraph_edge *e;
    3714     15473369 :   for (e = node->callees; e; e = e->next_callee)
    3715              :     {
    3716     12135482 :       if (!e->inline_failed)
    3717              :         {
    3718      1507786 :           gcc_checking_assert (!ipa_call_summaries->get (e));
    3719      1507786 :           summarize_calls_size_and_time (e->callee, sum);
    3720      1507786 :           continue;
    3721              :         }
    3722     10627696 :       int size = 0;
    3723     10627696 :       sreal time = 0;
    3724              : 
    3725     10627696 :       estimate_edge_size_and_time (e, &size, NULL, &time, NULL, NULL);
    3726              : 
    3727     10627696 :       ipa_predicate pred = true;
    3728     10627696 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3729              : 
    3730     10627696 :       if (es->predicate)
    3731      1938183 :         pred = *es->predicate;
    3732     10627696 :       sum->account_size_time (size, time, pred, pred, true);
    3733              :     }
    3734      3658609 :   for (e = node->indirect_calls; e; e = e->next_callee)
    3735              :     {
    3736       320722 :       int size = 0;
    3737       320722 :       sreal time = 0;
    3738              : 
    3739       320722 :       estimate_edge_size_and_time (e, &size, NULL, &time, NULL, NULL);
    3740       320722 :       ipa_predicate pred = true;
    3741       320722 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3742              : 
    3743       320722 :       if (es->predicate)
    3744        82675 :         pred = *es->predicate;
    3745       320722 :       sum->account_size_time (size, time, pred, pred, true);
    3746              :     }
    3747      3337887 : }
    3748              : 
    3749              : /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all
    3750              :    calls in NODE.  POSSIBLE_TRUTHS and AVALS (the latter if non-NULL) describe
    3751              :    context of the call site.  */
    3752              : 
    3753              : static void
    3754     21485712 : estimate_calls_size_and_time (struct cgraph_node *node, int *size,
    3755              :                               int *min_size, sreal *time,
    3756              :                               ipa_hints *hints,
    3757              :                               clause_t possible_truths,
    3758              :                               ipa_call_arg_values *avals)
    3759              : {
    3760     21485712 :   class ipa_fn_summary *sum = ipa_fn_summaries->get (node);
    3761     21485712 :   bool use_table = true;
    3762              : 
    3763     21485712 :   gcc_assert (node->callees || node->indirect_calls);
    3764              : 
    3765              :   /* During early inlining we do not calculate info for very
    3766              :      large functions and thus there is no need for producing
    3767              :      summaries.  */
    3768     21485712 :   if (!ipa_node_params_sum)
    3769              :     use_table = false;
    3770              :   /* Do not calculate summaries for simple wrappers; it is waste
    3771              :      of memory.  */
    3772     11690130 :   else if (node->callees && !node->indirect_calls
    3773     10913292 :            && node->callees->inline_failed && !node->callees->next_callee)
    3774              :     use_table = false;
    3775              :   /* If there is an indirect edge that may be optimized, we need
    3776              :      to go the slow way.  */
    3777      9445720 :   else if (avals
    3778      9445720 :            && (avals->m_known_vals.length ()
    3779      3540179 :                || avals->m_known_contexts.length ()
    3780      3384944 :                || avals->m_known_aggs.length ()))
    3781              :     {
    3782      4486191 :       ipa_node_params *params_summary = ipa_node_params_sum->get (node);
    3783      4486191 :       unsigned int nargs = params_summary
    3784      4486191 :                            ? ipa_get_param_count (params_summary) : 0;
    3785              : 
    3786     14817061 :       for (unsigned int i = 0; i < nargs && use_table; i++)
    3787              :         {
    3788     10330870 :           if (ipa_is_param_used_by_indirect_call (params_summary, i)
    3789     10330870 :               && (avals->safe_sval_at (i)
    3790       280983 :                   || (ipa_argagg_value_list (avals).value_for_index_p (i))))
    3791              :             use_table = false;
    3792     10233958 :           else if (ipa_is_param_used_by_polymorphic_call (params_summary, i)
    3793     10233958 :                    && (avals->m_known_contexts.length () > i
    3794     10482504 :                        && !avals->m_known_contexts[i].useless_p ()))
    3795              :             use_table = false;
    3796              :         }
    3797              :     }
    3798              : 
    3799              :   /* Fast path is via the call size time table.  */
    3800      4486191 :   if (use_table)
    3801              :     {
    3802              :       /* Build summary if it is absent.  */
    3803      9173240 :       if (!sum->call_size_time_table.length ())
    3804              :         {
    3805       904162 :           ipa_predicate true_pred = true;
    3806       904162 :           sum->account_size_time (0, 0, true_pred, true_pred, true);
    3807       904162 :           summarize_calls_size_and_time (node, sum);
    3808              :         }
    3809              : 
    3810      9173240 :       int old_size = *size;
    3811      9173240 :       sreal old_time = time ? *time : 0;
    3812              : 
    3813      9173240 :       if (min_size)
    3814      9173240 :         *min_size += sum->call_size_time_table[0].size;
    3815              : 
    3816      9173240 :       unsigned int i;
    3817      9173240 :       size_time_entry *e;
    3818              : 
    3819              :       /* Walk the table and account sizes and times.  */
    3820     24150162 :       for (i = 0; sum->call_size_time_table.iterate (i, &e);
    3821              :            i++)
    3822     14976922 :         if (e->exec_predicate.evaluate (possible_truths))
    3823              :           {
    3824     14001065 :             *size += e->size;
    3825     14001065 :             if (time)
    3826     11757343 :               *time += e->time;
    3827              :           }
    3828              : 
    3829              :       /* Be careful and see if both methods agree.  */
    3830           21 :       if ((flag_checking || dump_file)
    3831              :           /* Do not try to sanity check when we know we lost some
    3832              :              precision.  */
    3833      9173240 :           && sum->call_size_time_table.length ()
    3834              :              < ipa_fn_summary::max_size_time_table_size)
    3835              :         {
    3836      9173219 :           estimate_calls_size_and_time_1 (node, &old_size, NULL, &old_time, NULL,
    3837              :                                           possible_truths, avals);
    3838      9173219 :           gcc_assert (*size == old_size);
    3839     16864086 :           if (time && (*time - old_time > 1 || *time - old_time < -1)
    3840      9173252 :               && dump_file)
    3841            0 :             fprintf (dump_file, "Time mismatch in call summary %f!=%f\n",
    3842              :                      old_time.to_double (),
    3843              :                      time->to_double ());
    3844              :         }
    3845              :     }
    3846              :   /* Slow path by walking all edges.  */
    3847              :   else
    3848     12312472 :     estimate_calls_size_and_time_1 (node, size, min_size, time, hints,
    3849              :                                     possible_truths, avals);
    3850     21485712 : }
    3851              : 
    3852              : /* Main constructor for ipa call context.  Memory allocation of ARG_VALUES
    3853              :    is owned by the caller.  INLINE_PARAM_SUMMARY is also owned by the
    3854              :    caller.  */
    3855              : 
    3856     20570058 : ipa_call_context::ipa_call_context (cgraph_node *node, clause_t possible_truths,
    3857              :                                     clause_t nonspec_possible_truths,
    3858              :                                     vec<inline_param_summary>
    3859              :                                       inline_param_summary,
    3860              :                                     ipa_auto_call_arg_values *arg_values)
    3861     20570058 : : m_node (node), m_possible_truths (possible_truths),
    3862     20570058 :   m_nonspec_possible_truths (nonspec_possible_truths),
    3863     20570058 :   m_inline_param_summary (inline_param_summary),
    3864     20570058 :   m_avals (arg_values)
    3865              : {
    3866     20570058 : }
    3867              : 
    3868              : /* Set THIS to be a duplicate of CTX.  Copy all relevant info.  */
    3869              : 
    3870              : void
    3871      2066273 : ipa_cached_call_context::duplicate_from (const ipa_call_context &ctx)
    3872              : {
    3873      2066273 :   m_node = ctx.m_node;
    3874      2066273 :   m_possible_truths = ctx.m_possible_truths;
    3875      2066273 :   m_nonspec_possible_truths = ctx.m_nonspec_possible_truths;
    3876      2066273 :   ipa_node_params *params_summary = ipa_node_params_sum->get (m_node);
    3877      2066273 :   unsigned int nargs = params_summary
    3878      2066273 :                        ? ipa_get_param_count (params_summary) : 0;
    3879              : 
    3880      2066273 :   m_inline_param_summary = vNULL;
    3881              :   /* Copy the info only if there is at least one useful entry.  */
    3882      2066273 :   if (ctx.m_inline_param_summary.exists ())
    3883              :     {
    3884      1844325 :       unsigned int n = MIN (ctx.m_inline_param_summary.length (), nargs);
    3885              : 
    3886      4198550 :       for (unsigned int i = 0; i < n; i++)
    3887      3429437 :         if (ipa_is_param_used_by_ipa_predicates (params_summary, i)
    3888      4890864 :             && !ctx.m_inline_param_summary[i].useless_p ())
    3889              :           {
    3890      1075212 :             m_inline_param_summary
    3891      1075212 :                     = ctx.m_inline_param_summary.copy ();
    3892      1075212 :             break;
    3893              :           }
    3894              :     }
    3895      2066273 :   m_avals.m_known_vals = vNULL;
    3896      2066273 :   if (ctx.m_avals.m_known_vals.exists ())
    3897              :     {
    3898      2066273 :       unsigned int n = MIN (ctx.m_avals.m_known_vals.length (), nargs);
    3899              : 
    3900      4781903 :       for (unsigned int i = 0; i < n; i++)
    3901      2742574 :         if (ipa_is_param_used_by_indirect_call (params_summary, i)
    3902      2742574 :             && ctx.m_avals.m_known_vals[i])
    3903              :           {
    3904        26944 :             m_avals.m_known_vals = ctx.m_avals.m_known_vals.copy ();
    3905        26944 :             break;
    3906              :           }
    3907              :     }
    3908              : 
    3909      2066273 :   m_avals.m_known_contexts = vNULL;
    3910      2066273 :   if (ctx.m_avals.m_known_contexts.exists ())
    3911              :     {
    3912      2066273 :       unsigned int n = MIN (ctx.m_avals.m_known_contexts.length (), nargs);
    3913              : 
    3914      2069141 :       for (unsigned int i = 0; i < n; i++)
    3915        28804 :         if (ipa_is_param_used_by_polymorphic_call (params_summary, i)
    3916        28804 :             && !ctx.m_avals.m_known_contexts[i].useless_p ())
    3917              :           {
    3918        25936 :             m_avals.m_known_contexts = ctx.m_avals.m_known_contexts.copy ();
    3919        25936 :             break;
    3920              :           }
    3921              :     }
    3922              : 
    3923      2066273 :   m_avals.m_known_aggs = vNULL;
    3924      2066273 :   if (ctx.m_avals.m_known_aggs.exists ())
    3925              :     {
    3926      2066273 :       const ipa_argagg_value_list avl (&ctx.m_avals);
    3927      6851857 :       for (unsigned int i = 0; i < nargs; i++)
    3928      4788534 :         if (ipa_is_param_used_by_indirect_call (params_summary, i)
    3929      4788534 :             && avl.value_for_index_p (i))
    3930              :           {
    3931         2950 :             m_avals.m_known_aggs = ctx.m_avals.m_known_aggs.copy ();
    3932         2950 :             break;
    3933              :           }
    3934              :     }
    3935              : 
    3936      2066273 :   m_avals.m_known_value_ranges = vNULL;
    3937      2066273 : }
    3938              : 
    3939              : /* Release memory used by known_vals/contexts/aggs vectors.  and
    3940              :    inline_param_summary.  */
    3941              : 
    3942              : void
    3943      3353316 : ipa_cached_call_context::release ()
    3944              : {
    3945              :   /* See if context is initialized at first place.  */
    3946      3353316 :   if (!m_node)
    3947              :     return;
    3948      2066273 :   m_avals.m_known_aggs.release ();
    3949      2066273 :   m_avals.m_known_vals.release ();
    3950      2066273 :   m_avals.m_known_contexts.release ();
    3951      2066273 :   m_inline_param_summary.release ();
    3952              : }
    3953              : 
    3954              : /* Return true if CTX describes the same call context as THIS.  */
    3955              : 
    3956              : bool
    3957      7383756 : ipa_call_context::equal_to (const ipa_call_context &ctx)
    3958              : {
    3959      7383756 :   if (m_node != ctx.m_node
    3960      6096713 :       || m_possible_truths != ctx.m_possible_truths
    3961      5463596 :       || m_nonspec_possible_truths != ctx.m_nonspec_possible_truths)
    3962              :     return false;
    3963              : 
    3964      5463596 :   ipa_node_params *params_summary = ipa_node_params_sum->get (m_node);
    3965      5463596 :   unsigned int nargs = params_summary
    3966      5463596 :                        ? ipa_get_param_count (params_summary) : 0;
    3967              : 
    3968      5463596 :   if (m_inline_param_summary.exists () || ctx.m_inline_param_summary.exists ())
    3969              :     {
    3970     16226850 :       for (unsigned int i = 0; i < nargs; i++)
    3971              :         {
    3972     11128157 :           if (!ipa_is_param_used_by_ipa_predicates (params_summary, i))
    3973      3527824 :             continue;
    3974      7600333 :           if (i >= m_inline_param_summary.length ()
    3975      5277840 :               || m_inline_param_summary[i].useless_p ())
    3976              :             {
    3977      3351104 :               if (i < ctx.m_inline_param_summary.length ()
    3978      3351104 :                   && !ctx.m_inline_param_summary[i].useless_p ())
    3979              :                 return false;
    3980      3299157 :               continue;
    3981              :             }
    3982      4249229 :           if (i >= ctx.m_inline_param_summary.length ()
    3983      4249226 :               || ctx.m_inline_param_summary[i].useless_p ())
    3984              :             {
    3985        49674 :               if (i < m_inline_param_summary.length ()
    3986        49674 :                   && !m_inline_param_summary[i].useless_p ())
    3987              :                 return false;
    3988            0 :               continue;
    3989              :             }
    3990      4199555 :           if (!m_inline_param_summary[i].equal_to
    3991      4199555 :                  (ctx.m_inline_param_summary[i]))
    3992              :             return false;
    3993              :         }
    3994              :     }
    3995      5331102 :   if (m_avals.m_known_vals.exists () || ctx.m_avals.m_known_vals.exists ())
    3996              :     {
    3997     16246886 :       for (unsigned int i = 0; i < nargs; i++)
    3998              :         {
    3999     10926511 :           if (!ipa_is_param_used_by_indirect_call (params_summary, i))
    4000     10707918 :             continue;
    4001       218593 :           if (i >= m_avals.m_known_vals.length () || !m_avals.m_known_vals[i])
    4002              :             {
    4003       161057 :               if (i < ctx.m_avals.m_known_vals.length ()
    4004       161057 :                   && ctx.m_avals.m_known_vals[i])
    4005              :                 return false;
    4006       160968 :               continue;
    4007              :             }
    4008        57536 :           if (i >= ctx.m_avals.m_known_vals.length ()
    4009        57536 :               || !ctx.m_avals.m_known_vals[i])
    4010              :             {
    4011              :               if (i < m_avals.m_known_vals.length () && m_avals.m_known_vals[i])
    4012              :                 return false;
    4013              :               continue;
    4014              :             }
    4015        57446 :           if (m_avals.m_known_vals[i] != ctx.m_avals.m_known_vals[i])
    4016              :             return false;
    4017              :         }
    4018              :     }
    4019      5320375 :   if (m_avals.m_known_contexts.exists ()
    4020      5320375 :       || ctx.m_avals.m_known_contexts.exists ())
    4021              :     {
    4022     16231505 :       for (unsigned int i = 0; i < nargs; i++)
    4023              :         {
    4024     10912608 :           if (!ipa_is_param_used_by_polymorphic_call (params_summary, i))
    4025     10768020 :             continue;
    4026       144588 :           if (i >= m_avals.m_known_contexts.length ()
    4027       143426 :               || m_avals.m_known_contexts[i].useless_p ())
    4028              :             {
    4029         1162 :               if (i < ctx.m_avals.m_known_contexts.length ()
    4030         1162 :                   && !ctx.m_avals.m_known_contexts[i].useless_p ())
    4031              :                 return false;
    4032         1150 :               continue;
    4033              :             }
    4034       143426 :           if (i >= ctx.m_avals.m_known_contexts.length ()
    4035       143426 :               || ctx.m_avals.m_known_contexts[i].useless_p ())
    4036              :             {
    4037            8 :               if (i < m_avals.m_known_contexts.length ()
    4038            8 :                   && !m_avals.m_known_contexts[i].useless_p ())
    4039              :                 return false;
    4040            0 :               continue;
    4041              :             }
    4042       143418 :           if (!m_avals.m_known_contexts[i].equal_to
    4043       143418 :                  (ctx.m_avals.m_known_contexts[i]))
    4044              :             return false;
    4045              :         }
    4046              :     }
    4047      5318897 :   if (m_avals.m_known_aggs.exists () || ctx.m_avals.m_known_aggs.exists ())
    4048              :     {
    4049              :       unsigned i = 0, j = 0;
    4050     12519357 :       while (i < m_avals.m_known_aggs.length ()
    4051      6258915 :              || j < ctx.m_avals.m_known_aggs.length ())
    4052              :         {
    4053       941432 :           if (i >= m_avals.m_known_aggs.length ())
    4054              :             {
    4055       936506 :               int idx2 = ctx.m_avals.m_known_aggs[j].index;
    4056       936506 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx2))
    4057              :                 return false;
    4058       935946 :               j++;
    4059       935946 :               continue;
    4060       935946 :             }
    4061         4926 :           if (j >= ctx.m_avals.m_known_aggs.length ())
    4062              :             {
    4063          603 :               int idx1 = m_avals.m_known_aggs[i].index;
    4064          603 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4065              :                 return false;
    4066            8 :               i++;
    4067            8 :               continue;
    4068            8 :             }
    4069              : 
    4070         4323 :           int idx1 = m_avals.m_known_aggs[i].index;
    4071         4323 :           int idx2 = ctx.m_avals.m_known_aggs[j].index;
    4072         4323 :           if (idx1 < idx2)
    4073              :             {
    4074            0 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4075              :                 return false;
    4076            0 :               i++;
    4077            0 :               continue;
    4078              :             }
    4079         4323 :           if (idx1 > idx2)
    4080              :             {
    4081            0 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx2))
    4082              :                 return false;
    4083            0 :               j++;
    4084            0 :               continue;
    4085              :             }
    4086         4323 :           if (!ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4087              :             {
    4088          482 :               i++;
    4089          482 :               j++;
    4090          482 :               continue;
    4091              :             }
    4092              : 
    4093         3841 :           if ((m_avals.m_known_aggs[i].unit_offset
    4094         3841 :                != ctx.m_avals.m_known_aggs[j].unit_offset)
    4095         3833 :               || (m_avals.m_known_aggs[i].by_ref
    4096         3833 :                != ctx.m_avals.m_known_aggs[j].by_ref)
    4097         7674 :               || !operand_equal_p (m_avals.m_known_aggs[i].value,
    4098         3833 :                                    ctx.m_avals.m_known_aggs[j].value))
    4099              :             return false;
    4100         3582 :           i++;
    4101         3582 :           j++;
    4102              :         }
    4103              :     }
    4104              :   return true;
    4105              : }
    4106              : 
    4107              : /* Fill in the selected fields in ESTIMATES with value estimated for call in
    4108              :    this context.  Always compute size and min_size.  Only compute time and
    4109              :    nonspecialized_time if EST_TIMES is true.  Only compute hints if EST_HINTS
    4110              :    is true.  */
    4111              : 
    4112              : void
    4113     20537548 : ipa_call_context::estimate_size_and_time (ipa_call_estimates *estimates,
    4114              :                                           bool est_times, bool est_hints)
    4115              : {
    4116     20537548 :   class ipa_fn_summary *info = ipa_fn_summaries->get (m_node);
    4117     20537548 :   size_time_entry *e;
    4118     20537548 :   int size = 0;
    4119     20537548 :   sreal time = 0;
    4120     20537548 :   int min_size = 0;
    4121     20537548 :   ipa_hints hints = 0;
    4122     20537548 :   sreal loops_with_known_iterations = 0;
    4123     20537548 :   sreal loops_with_known_strides = 0;
    4124     20537548 :   int i;
    4125              : 
    4126     20537548 :   if (dump_file && (dump_flags & TDF_DETAILS))
    4127              :     {
    4128         1317 :       bool found = false;
    4129         1317 :       fprintf (dump_file, "   Estimating body: %s\n"
    4130              :                "   Known to be false: ", m_node->dump_name ());
    4131              : 
    4132         4267 :       for (i = ipa_predicate::not_inlined_condition;
    4133         8534 :            i < (ipa_predicate::first_dynamic_condition
    4134         6984 :                 + (int) vec_safe_length (info->conds)); i++)
    4135         2950 :         if (!(m_possible_truths & (1 << i)))
    4136              :           {
    4137         1783 :             if (found)
    4138          519 :               fprintf (dump_file, ", ");
    4139         1783 :             found = true;
    4140         1783 :             dump_condition (dump_file, info->conds, i);
    4141              :           }
    4142              :     }
    4143              : 
    4144     20537548 :   if (m_node->callees || m_node->indirect_calls)
    4145     27400966 :     estimate_calls_size_and_time (m_node, &size, &min_size,
    4146              :                                   est_times ? &time : NULL,
    4147              :                                   est_hints ? &hints : NULL, m_possible_truths,
    4148              :                                   &m_avals);
    4149              : 
    4150     20537548 :   sreal nonspecialized_time = time;
    4151              : 
    4152     20537548 :   min_size += info->size_time_table[0].size;
    4153    140584894 :   for (i = 0; info->size_time_table.iterate (i, &e); i++)
    4154              :     {
    4155    120047346 :       bool exec = e->exec_predicate.evaluate (m_nonspec_possible_truths);
    4156              : 
    4157              :       /* Because predicates are conservative, it can happen that nonconst is 1
    4158              :          but exec is 0.  */
    4159    120047346 :       if (exec)
    4160              :         {
    4161    117514321 :           bool nonconst = e->nonconst_predicate.evaluate (m_possible_truths);
    4162              : 
    4163    117514321 :           gcc_checking_assert (e->time >= 0);
    4164    117514321 :           gcc_checking_assert (time >= 0);
    4165              : 
    4166              :           /* We compute specialized size only because size of nonspecialized
    4167              :              copy is context independent.
    4168              : 
    4169              :              The difference between nonspecialized execution and specialized is
    4170              :              that nonspecialized is not going to have optimized out computations
    4171              :              known to be constant in a specialized setting.  */
    4172    117514321 :           if (nonconst)
    4173     59018420 :             size += e->size;
    4174    117514321 :           if (!est_times)
    4175     60527963 :             continue;
    4176     56986358 :           nonspecialized_time += e->time;
    4177     56986358 :           if (!nonconst)
    4178              :             ;
    4179     27348378 :           else if (!m_inline_param_summary.exists ())
    4180              :             {
    4181      2446207 :               if (nonconst)
    4182      2446207 :                 time += e->time;
    4183              :             }
    4184              :           else
    4185              :             {
    4186     24902171 :               int prob = e->nonconst_predicate.probability
    4187     24902171 :                                                (info->conds, m_possible_truths,
    4188              :                                                 m_inline_param_summary);
    4189     24902171 :               gcc_checking_assert (prob >= 0);
    4190     24902171 :               gcc_checking_assert (prob <= REG_BR_PROB_BASE);
    4191     24902171 :               if (prob == REG_BR_PROB_BASE)
    4192     20548859 :                 time += e->time;
    4193              :               else
    4194      4353312 :                 time += e->time * prob / REG_BR_PROB_BASE;
    4195              :             }
    4196     56986358 :           gcc_checking_assert (time >= 0);
    4197              :         }
    4198              :      }
    4199     20537548 :   gcc_checking_assert (info->size_time_table[0].exec_predicate == true);
    4200     20537548 :   gcc_checking_assert (info->size_time_table[0].nonconst_predicate == true);
    4201     20537548 :   gcc_checking_assert (min_size >= 0);
    4202     20537548 :   gcc_checking_assert (size >= 0);
    4203     20537548 :   gcc_checking_assert (time >= 0);
    4204              :   /* nonspecialized_time should be always bigger than specialized time.
    4205              :      Roundoff issues however may get into the way.  */
    4206     20537548 :   gcc_checking_assert ((nonspecialized_time - time * 99 / 100) >= -1);
    4207              : 
    4208              :   /* Roundoff issues may make specialized time bigger than nonspecialized
    4209              :      time.  We do not really want that to happen because some heuristics
    4210              :      may get confused by seeing negative speedups.  */
    4211     20537548 :   if (time > nonspecialized_time)
    4212            0 :     time = nonspecialized_time;
    4213              : 
    4214     20537548 :   if (est_hints)
    4215              :     {
    4216      7587275 :       if (info->scc_no)
    4217       234139 :         hints |= INLINE_HINT_in_scc;
    4218      7587275 :       if (DECL_DECLARED_INLINE_P (m_node->decl))
    4219      4857897 :         hints |= INLINE_HINT_declared_inline;
    4220      7587275 :       if (info->builtin_constant_p_parms.length ()
    4221         9822 :           && DECL_DECLARED_INLINE_P (m_node->decl))
    4222         9633 :         hints |= INLINE_HINT_builtin_constant_p;
    4223              : 
    4224      7587275 :       ipa_freqcounting_predicate *fcp;
    4225      8141632 :       for (i = 0; vec_safe_iterate (info->loop_iterations, i, &fcp); i++)
    4226       554357 :         if (!fcp->predicate->evaluate (m_possible_truths))
    4227              :           {
    4228       371967 :             hints |= INLINE_HINT_loop_iterations;
    4229       371967 :             loops_with_known_iterations += fcp->freq;
    4230              :           }
    4231      7587275 :       estimates->loops_with_known_iterations = loops_with_known_iterations;
    4232              : 
    4233      7881180 :       for (i = 0; vec_safe_iterate (info->loop_strides, i, &fcp); i++)
    4234       293905 :         if (!fcp->predicate->evaluate (m_possible_truths))
    4235              :           {
    4236       263317 :             hints |= INLINE_HINT_loop_stride;
    4237       263317 :             loops_with_known_strides += fcp->freq;
    4238              :           }
    4239      7587275 :       estimates->loops_with_known_strides = loops_with_known_strides;
    4240              :     }
    4241              : 
    4242     20537548 :   size = RDIV (size, ipa_fn_summary::size_scale);
    4243     20537548 :   min_size = RDIV (min_size, ipa_fn_summary::size_scale);
    4244              : 
    4245     20537548 :   if (dump_file && (dump_flags & TDF_DETAILS))
    4246              :     {
    4247         1317 :       fprintf (dump_file, "\n   size:%i", (int) size);
    4248         1317 :       if (est_times)
    4249         1080 :         fprintf (dump_file, " time:%f nonspec time:%f",
    4250              :                  time.to_double (), nonspecialized_time.to_double ());
    4251         1317 :       if (est_hints)
    4252         1080 :         fprintf (dump_file, " loops with known iterations:%f "
    4253              :                  "known strides:%f", loops_with_known_iterations.to_double (),
    4254              :                  loops_with_known_strides.to_double ());
    4255         1317 :       fprintf (dump_file, "\n");
    4256              :     }
    4257     20537548 :   if (est_times)
    4258              :     {
    4259      7587275 :       estimates->time = time;
    4260      7587275 :       estimates->nonspecialized_time = nonspecialized_time;
    4261              :     }
    4262     20537548 :   estimates->size = size;
    4263     20537548 :   estimates->min_size = min_size;
    4264     20537548 :   if (est_hints)
    4265      7587275 :     estimates->hints = hints;
    4266     20537548 :   return;
    4267              : }
    4268              : 
    4269              : 
    4270              : /* Estimate size and time needed to execute callee of EDGE assuming that
    4271              :    parameters known to be constant at caller of EDGE are propagated.
    4272              :    KNOWN_VALS and KNOWN_CONTEXTS are vectors of assumed known constant values
    4273              :    and types for parameters.  */
    4274              : 
    4275              : void
    4276       232228 : estimate_ipcp_clone_size_and_time (struct cgraph_node *node,
    4277              :                                    ipa_auto_call_arg_values *avals,
    4278              :                                    ipa_call_estimates *estimates)
    4279              : {
    4280       232228 :   clause_t clause, nonspec_clause;
    4281              : 
    4282       232228 :   evaluate_conditions_for_known_args (node, false, avals, &clause,
    4283              :                                       &nonspec_clause, NULL);
    4284       232228 :   ipa_call_context ctx (node, clause, nonspec_clause, vNULL, avals);
    4285       232228 :   ctx.estimate_size_and_time (estimates);
    4286       232228 : }
    4287              : 
    4288              : /* Return stack frame offset where frame of NODE is supposed to start inside
    4289              :    of the function it is inlined to.
    4290              :    Return 0 for functions that are not inlined.  */
    4291              : 
    4292              : HOST_WIDE_INT
    4293      5383320 : ipa_get_stack_frame_offset (struct cgraph_node *node)
    4294              : {
    4295      5383320 :   HOST_WIDE_INT offset = 0;
    4296      5383320 :   if (!node->inlined_to)
    4297              :     return 0;
    4298      4297339 :   node = node->callers->caller;
    4299      5564929 :   while (true)
    4300              :     {
    4301      4931134 :       offset += ipa_size_summaries->get (node)->estimated_self_stack_size;
    4302      4931134 :       if (!node->inlined_to)
    4303              :         return offset;
    4304       633795 :       node = node->callers->caller;
    4305              :     }
    4306              : }
    4307              : 
    4308              : 
    4309              : /* Update summary information of inline clones after inlining.
    4310              :    Compute peak stack usage.  */
    4311              : 
    4312              : static void
    4313      5069845 : inline_update_callee_summaries (struct cgraph_node *node, int depth)
    4314              : {
    4315      5069845 :   struct cgraph_edge *e;
    4316              : 
    4317      5069845 :   ipa_propagate_frequency (node);
    4318      9864197 :   for (e = node->callees; e; e = e->next_callee)
    4319              :     {
    4320      4794352 :       if (!e->inline_failed)
    4321       773059 :         inline_update_callee_summaries (e->callee, depth);
    4322              :       else
    4323      4021293 :         ipa_call_summaries->get (e)->loop_depth += depth;
    4324              :     }
    4325      5191397 :   for (e = node->indirect_calls; e; e = e->next_callee)
    4326       121552 :     ipa_call_summaries->get (e)->loop_depth += depth;
    4327      5069845 : }
    4328              : 
    4329              : /* Update change_prob and points_to_local_or_readonly_memory of EDGE after
    4330              :    INLINED_EDGE has been inlined.
    4331              : 
    4332              :    When function A is inlined in B and A calls C with parameter that
    4333              :    changes with probability PROB1 and C is known to be passthrough
    4334              :    of argument if B that change with probability PROB2, the probability
    4335              :    of change is now PROB1*PROB2.  */
    4336              : 
    4337              : static void
    4338      4143155 : remap_edge_params (struct cgraph_edge *inlined_edge,
    4339              :                    struct cgraph_edge *edge)
    4340              : {
    4341      4143155 :   if (ipa_node_params_sum)
    4342              :     {
    4343      2906970 :       int i;
    4344      2906970 :       ipa_edge_args *args = ipa_edge_args_sum->get (edge);
    4345      2906970 :       if (!args)
    4346              :         return;
    4347      1658060 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    4348      1658060 :       class ipa_call_summary *inlined_es
    4349      1658060 :         = ipa_call_summaries->get (inlined_edge);
    4350              : 
    4351      1658060 :       if (es->param.length () == 0)
    4352              :         return;
    4353              : 
    4354      9636646 :       for (i = 0; i < ipa_get_cs_argument_count (args); i++)
    4355              :         {
    4356      3244829 :           struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
    4357      3244829 :           if (jfunc->type == IPA_JF_PASS_THROUGH
    4358      2385752 :               || jfunc->type == IPA_JF_ANCESTOR)
    4359              :             {
    4360      1009063 :               int id = jfunc->type == IPA_JF_PASS_THROUGH
    4361      1009063 :                        ? ipa_get_jf_pass_through_formal_id (jfunc)
    4362       149986 :                        : ipa_get_jf_ancestor_formal_id (jfunc);
    4363      2018043 :               if (id < (int) inlined_es->param.length ())
    4364              :                 {
    4365      1008972 :                   int prob1 = es->param[i].change_prob;
    4366      1008972 :                   int prob2 = inlined_es->param[id].change_prob;
    4367      1008972 :                   int prob = combine_probabilities (prob1, prob2);
    4368              : 
    4369      1008972 :                   if (prob1 && prob2 && !prob)
    4370      1008972 :                     prob = 1;
    4371              : 
    4372      1008972 :                   es->param[i].change_prob = prob;
    4373              : 
    4374      2017944 :                   if (inlined_es
    4375      1008972 :                         ->param[id].points_to_local_or_readonly_memory)
    4376       221045 :                     es->param[i].points_to_local_or_readonly_memory = true;
    4377      2017944 :                   if (inlined_es
    4378      1008972 :                         ->param[id].points_to_possible_sra_candidate)
    4379       183699 :                     es->param[i].points_to_possible_sra_candidate = true;
    4380              :                 }
    4381      1009063 :               if (!es->param[i].points_to_local_or_readonly_memory
    4382              :                   && jfunc->type == IPA_JF_CONST
    4383              :                   && points_to_local_or_readonly_memory_p
    4384              :                          (ipa_get_jf_constant (jfunc)))
    4385              :                 es->param[i].points_to_local_or_readonly_memory = true;
    4386              :             }
    4387              :         }
    4388              :     }
    4389              : }
    4390              : 
    4391              : /* Update edge summaries of NODE after INLINED_EDGE has been inlined.
    4392              : 
    4393              :    Remap predicates of callees of NODE.  Rest of arguments match
    4394              :    remap_predicate.
    4395              : 
    4396              :    Also update change probabilities.  */
    4397              : 
    4398              : static void
    4399      5069845 : remap_edge_summaries (struct cgraph_edge *inlined_edge,
    4400              :                       struct cgraph_node *node,
    4401              :                       class ipa_fn_summary *info,
    4402              :                       class ipa_node_params *params_summary,
    4403              :                       class ipa_fn_summary *callee_info,
    4404              :                       const vec<int> &operand_map,
    4405              :                       const vec<HOST_WIDE_INT> &offset_map,
    4406              :                       clause_t possible_truths,
    4407              :                       ipa_predicate *toplev_predicate)
    4408              : {
    4409      5069845 :   struct cgraph_edge *e, *next;
    4410      9863744 :   for (e = node->callees; e; e = next)
    4411              :     {
    4412      4793899 :       ipa_predicate p;
    4413      4793899 :       next = e->next_callee;
    4414              : 
    4415      4793899 :       if (e->inline_failed)
    4416              :         {
    4417      4020840 :           class ipa_call_summary *es = ipa_call_summaries->get (e);
    4418      4020840 :           remap_edge_params (inlined_edge, e);
    4419              : 
    4420      4020840 :           if (es->predicate)
    4421              :             {
    4422      1382523 :               p = es->predicate->remap_after_inlining
    4423      1382523 :                                      (info, params_summary,
    4424              :                                       callee_info, operand_map,
    4425              :                                       offset_map, possible_truths,
    4426              :                                       *toplev_predicate);
    4427      1382523 :               edge_set_predicate (e, &p);
    4428              :             }
    4429              :           else
    4430      2638317 :             edge_set_predicate (e, toplev_predicate);
    4431              :         }
    4432              :       else
    4433       773059 :         remap_edge_summaries (inlined_edge, e->callee, info,
    4434              :                               params_summary, callee_info,
    4435              :                               operand_map, offset_map, possible_truths,
    4436              :                               toplev_predicate);
    4437              :     }
    4438      5192160 :   for (e = node->indirect_calls; e; e = next)
    4439              :     {
    4440       122315 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    4441       122315 :       ipa_predicate p;
    4442       122315 :       next = e->next_callee;
    4443              : 
    4444       122315 :       remap_edge_params (inlined_edge, e);
    4445       122315 :       if (es->predicate)
    4446              :         {
    4447        27417 :           p = es->predicate->remap_after_inlining
    4448        27417 :                                  (info, params_summary,
    4449              :                                   callee_info, operand_map, offset_map,
    4450              :                                   possible_truths, *toplev_predicate);
    4451        27417 :           edge_set_predicate (e, &p);
    4452              :         }
    4453              :       else
    4454        94898 :         edge_set_predicate (e, toplev_predicate);
    4455              :     }
    4456      5069845 : }
    4457              : 
    4458              : /* Run remap_after_inlining on each predicate in V.  */
    4459              : 
    4460              : static void
    4461      8593572 : remap_freqcounting_predicate (class ipa_fn_summary *info,
    4462              :                               class ipa_node_params *params_summary,
    4463              :                               class ipa_fn_summary *callee_info,
    4464              :                               vec<ipa_freqcounting_predicate, va_gc> *v,
    4465              :                               const vec<int> &operand_map,
    4466              :                               const vec<HOST_WIDE_INT> &offset_map,
    4467              :                               clause_t possible_truths,
    4468              :                               ipa_predicate *toplev_predicate)
    4469              : 
    4470              : {
    4471      8593572 :   ipa_freqcounting_predicate *fcp;
    4472      8621141 :   for (int i = 0; vec_safe_iterate (v, i, &fcp); i++)
    4473              :     {
    4474        27569 :       ipa_predicate p
    4475        27569 :         = fcp->predicate->remap_after_inlining (info, params_summary,
    4476              :                                                 callee_info, operand_map,
    4477              :                                                 offset_map, possible_truths,
    4478              :                                                 *toplev_predicate);
    4479        38231 :       if (p != false && p != true)
    4480         2665 :         *fcp->predicate &= p;
    4481              :     }
    4482      8593572 : }
    4483              : 
    4484              : /* We inlined EDGE.  Update summary of the function we inlined into.  */
    4485              : 
    4486              : void
    4487      4296786 : ipa_merge_fn_summary_after_inlining (struct cgraph_edge *edge)
    4488              : {
    4489      4296786 :   ipa_fn_summary *callee_info = ipa_fn_summaries->get (edge->callee);
    4490      3994954 :   struct cgraph_node *to = (edge->caller->inlined_to
    4491      4296786 :                             ? edge->caller->inlined_to : edge->caller);
    4492      4296786 :   class ipa_fn_summary *info = ipa_fn_summaries->get (to);
    4493      4296786 :   clause_t clause = 0;  /* not_inline is known to be false.  */
    4494      4296786 :   size_time_entry *e;
    4495      4296786 :   auto_vec<int, 8> operand_map;
    4496      4296786 :   auto_vec<HOST_WIDE_INT, 8> offset_map;
    4497      4296786 :   int i;
    4498      4296786 :   ipa_predicate toplev_predicate;
    4499      4296786 :   class ipa_call_summary *es = ipa_call_summaries->get (edge);
    4500      4296786 :   ipa_node_params *params_summary = (ipa_node_params_sum
    4501      4296786 :                                      ? ipa_node_params_sum->get (to) : NULL);
    4502              : 
    4503      4296786 :   if (es->predicate)
    4504       362667 :     toplev_predicate = *es->predicate;
    4505              :   else
    4506      3934119 :     toplev_predicate = true;
    4507              : 
    4508      4296786 :   info->fp_expressions |= callee_info->fp_expressions;
    4509      4296786 :   info->target_info |= callee_info->target_info;
    4510              : 
    4511      4296786 :   if (callee_info->conds)
    4512              :     {
    4513      3135359 :       ipa_auto_call_arg_values avals;
    4514      3135359 :       evaluate_properties_for_edge (edge, true, &clause, NULL, &avals, false);
    4515      3135359 :     }
    4516      4296786 :   if (ipa_node_params_sum && callee_info->conds)
    4517              :     {
    4518       863572 :       ipa_edge_args *args = ipa_edge_args_sum->get (edge);
    4519       863572 :       int count = args ? ipa_get_cs_argument_count (args) : 0;
    4520       863433 :       int i;
    4521              : 
    4522       863433 :       if (count)
    4523              :         {
    4524       863433 :           operand_map.safe_grow_cleared (count, true);
    4525       863433 :           offset_map.safe_grow_cleared (count, true);
    4526              :         }
    4527      2763539 :       for (i = 0; i < count; i++)
    4528              :         {
    4529      1899967 :           struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
    4530      1899967 :           int map = -1;
    4531              : 
    4532              :           /* TODO: handle non-NOPs when merging.  */
    4533      1899967 :           if (jfunc->type == IPA_JF_PASS_THROUGH)
    4534              :             {
    4535       305043 :               if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
    4536       301458 :                 map = ipa_get_jf_pass_through_formal_id (jfunc);
    4537       305043 :               if (!ipa_get_jf_pass_through_agg_preserved (jfunc))
    4538       204976 :                 offset_map[i] = -1;
    4539              :             }
    4540      1594924 :           else if (jfunc->type == IPA_JF_ANCESTOR)
    4541              :             {
    4542        98655 :               HOST_WIDE_INT offset = ipa_get_jf_ancestor_offset (jfunc);
    4543        98655 :               if (offset >= 0 && offset < INT_MAX)
    4544              :                 {
    4545        98655 :                   map = ipa_get_jf_ancestor_formal_id (jfunc);
    4546        98655 :                   if (!ipa_get_jf_ancestor_agg_preserved (jfunc))
    4547        59988 :                     offset = -1;
    4548        98655 :                   offset_map[i] = offset;
    4549              :                 }
    4550              :             }
    4551      1899967 :           operand_map[i] = map;
    4552      3444144 :           gcc_assert (map < ipa_get_param_count (params_summary));
    4553              :         }
    4554              : 
    4555              :       int ip;
    4556       866492 :       for (i = 0; callee_info->builtin_constant_p_parms.iterate (i, &ip); i++)
    4557         2920 :         if (ip < count && operand_map[ip] >= 0)
    4558           62 :           add_builtin_constant_p_parm (info, operand_map[ip]);
    4559              :     }
    4560      4296786 :   sreal freq = edge->sreal_frequency ();
    4561     27984243 :   for (i = 0; callee_info->size_time_table.iterate (i, &e); i++)
    4562              :     {
    4563     19390671 :       ipa_predicate p;
    4564     19390671 :       p = e->exec_predicate.remap_after_inlining
    4565     19390671 :                              (info, params_summary,
    4566              :                               callee_info, operand_map,
    4567              :                               offset_map, clause,
    4568              :                               toplev_predicate);
    4569     19390671 :       ipa_predicate nonconstp;
    4570     19390671 :       nonconstp = e->nonconst_predicate.remap_after_inlining
    4571     19390671 :                                      (info, params_summary,
    4572              :                                       callee_info, operand_map,
    4573              :                                       offset_map, clause,
    4574              :                                       toplev_predicate);
    4575     29325021 :       if (p != false && nonconstp != false)
    4576              :         {
    4577      9595184 :           sreal add_time = ((sreal)e->time * freq);
    4578      9595184 :           int prob = e->nonconst_predicate.probability (callee_info->conds,
    4579              :                                                         clause, es->param);
    4580      9595184 :           if (prob != REG_BR_PROB_BASE)
    4581      1166814 :             add_time = add_time * prob / REG_BR_PROB_BASE;
    4582      1166814 :           if (prob != REG_BR_PROB_BASE
    4583      1166814 :               && dump_file && (dump_flags & TDF_DETAILS))
    4584              :             {
    4585            3 :               fprintf (dump_file, "\t\tScaling time by probability:%f\n",
    4586            3 :                        (double) prob / REG_BR_PROB_BASE);
    4587              :             }
    4588      9595184 :           info->account_size_time (e->size, add_time, p, nonconstp);
    4589              :         }
    4590              :     }
    4591      4296786 :   remap_edge_summaries (edge, edge->callee, info, params_summary,
    4592              :                         callee_info, operand_map,
    4593              :                         offset_map, clause, &toplev_predicate);
    4594      4296786 :   remap_freqcounting_predicate (info, params_summary, callee_info,
    4595              :                                 info->loop_iterations, operand_map,
    4596              :                                 offset_map, clause, &toplev_predicate);
    4597      4296786 :   remap_freqcounting_predicate (info, params_summary, callee_info,
    4598              :                                 info->loop_strides, operand_map,
    4599              :                                 offset_map, clause, &toplev_predicate);
    4600              : 
    4601      4296786 :   HOST_WIDE_INT stack_frame_offset = ipa_get_stack_frame_offset (edge->callee);
    4602      4296786 :   HOST_WIDE_INT peak = stack_frame_offset + callee_info->estimated_stack_size;
    4603              : 
    4604      4296786 :   if (info->estimated_stack_size < peak)
    4605       126447 :     info->estimated_stack_size = peak;
    4606              : 
    4607      4296786 :   inline_update_callee_summaries (edge->callee, es->loop_depth);
    4608      4296786 :   if (info->call_size_time_table.length ())
    4609              :     {
    4610       925939 :       int edge_size = 0;
    4611       925939 :       sreal edge_time = 0;
    4612              : 
    4613       925939 :       estimate_edge_size_and_time (edge, &edge_size, NULL, &edge_time, NULL, 0);
    4614              :       /* Unaccount size and time of the optimized out call.  */
    4615       925939 :       info->account_size_time (-edge_size, -edge_time,
    4616       925939 :                                es->predicate ? *es->predicate : true,
    4617       925939 :                                es->predicate ? *es->predicate : true,
    4618              :                                true);
    4619              :       /* Account new calls.  */
    4620       925939 :       summarize_calls_size_and_time (edge->callee, info);
    4621              :     }
    4622              : 
    4623              :   /* Free summaries that are not maintained for inline clones/edges.  */
    4624      4296786 :   ipa_call_summaries->remove (edge);
    4625      4296786 :   ipa_fn_summaries->remove (edge->callee);
    4626      4296786 :   ipa_remove_from_growth_caches (edge);
    4627      4296786 : }
    4628              : 
    4629              : /* For performance reasons ipa_merge_fn_summary_after_inlining is not updating
    4630              :    overall size and time.  Recompute it.
    4631              :    If RESET is true also recompute call_time_size_table.  */
    4632              : 
    4633              : void
    4634      9928264 : ipa_update_overall_fn_summary (struct cgraph_node *node, bool reset)
    4635              : {
    4636      9928264 :   class ipa_fn_summary *info = ipa_fn_summaries->get (node);
    4637      9928264 :   class ipa_size_summary *size_info = ipa_size_summaries->get (node);
    4638      9928264 :   size_time_entry *e;
    4639      9928264 :   int i;
    4640              : 
    4641      9928264 :   size_info->size = 0;
    4642      9928264 :   info->time = 0;
    4643     50384517 :   for (i = 0; info->size_time_table.iterate (i, &e); i++)
    4644              :     {
    4645     40456253 :       size_info->size += e->size;
    4646     40456253 :       info->time += e->time;
    4647              :     }
    4648      9928264 :   info->min_size = info->size_time_table[0].size;
    4649      9928264 :   if (reset)
    4650      8957910 :     info->call_size_time_table.release ();
    4651      9928264 :   if (node->callees || node->indirect_calls)
    4652      7565696 :     estimate_calls_size_and_time (node, &size_info->size, &info->min_size,
    4653              :                                   &info->time, NULL,
    4654              :                                   ~(clause_t) (1 << ipa_predicate::false_condition),
    4655              :                                   NULL);
    4656      9928264 :   size_info->size = RDIV (size_info->size, ipa_fn_summary::size_scale);
    4657      9928264 :   info->min_size = RDIV (info->min_size, ipa_fn_summary::size_scale);
    4658      9928264 : }
    4659              : 
    4660              : 
    4661              : /* This function performs intraprocedural analysis in NODE that is required to
    4662              :    inline indirect calls.  */
    4663              : 
    4664              : static void
    4665      1428110 : inline_indirect_intraprocedural_analysis (struct cgraph_node *node)
    4666              : {
    4667      1428110 :   ipa_analyze_node (node);
    4668      1428110 :   if (dump_file && (dump_flags & TDF_DETAILS))
    4669              :     {
    4670           16 :       ipa_print_node_params (dump_file, node);
    4671           16 :       ipa_print_node_jump_functions (dump_file, node);
    4672              :     }
    4673      1428110 : }
    4674              : 
    4675              : 
    4676              : /* Note function body size.  */
    4677              : 
    4678              : void
    4679      1438641 : inline_analyze_function (struct cgraph_node *node)
    4680              : {
    4681      1438641 :   push_cfun (DECL_STRUCT_FUNCTION (node->decl));
    4682              : 
    4683      1438641 :   if (dump_file)
    4684           96 :     fprintf (dump_file, "\nAnalyzing function: %s\n", node->dump_name ());
    4685      1438641 :   if (opt_for_fn (node->decl, optimize) && !node->thunk)
    4686      1428110 :     inline_indirect_intraprocedural_analysis (node);
    4687      1438641 :   compute_fn_summary (node, false);
    4688      1438641 :   if (!optimize)
    4689              :     {
    4690         9195 :       struct cgraph_edge *e;
    4691        21954 :       for (e = node->callees; e; e = e->next_callee)
    4692        12759 :         e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
    4693         9269 :       for (e = node->indirect_calls; e; e = e->next_callee)
    4694           74 :         e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
    4695              :     }
    4696              : 
    4697      1438641 :   pop_cfun ();
    4698      1438641 : }
    4699              : 
    4700              : 
    4701              : /* Called when new function is inserted to callgraph late.  */
    4702              : 
    4703              : void
    4704        19874 : ipa_fn_summary_t::insert (struct cgraph_node *node, ipa_fn_summary *)
    4705              : {
    4706        19874 :   inline_analyze_function (node);
    4707        19874 : }
    4708              : 
    4709              : /* Note function body size.  */
    4710              : 
    4711              : static void
    4712       237038 : ipa_fn_summary_generate (void)
    4713              : {
    4714       237038 :   struct cgraph_node *node;
    4715              : 
    4716      2167642 :   FOR_EACH_DEFINED_FUNCTION (node)
    4717      1930604 :     if (DECL_STRUCT_FUNCTION (node->decl))
    4718      1916817 :       node->versionable = tree_versionable_function_p (node->decl);
    4719              : 
    4720       237038 :   ipa_fn_summary_alloc ();
    4721              : 
    4722       237038 :   ipa_fn_summaries->enable_insertion_hook ();
    4723              : 
    4724       237038 :   ipa_register_cgraph_hooks ();
    4725              : 
    4726      2167642 :   FOR_EACH_DEFINED_FUNCTION (node)
    4727      1930604 :     if (!node->alias
    4728      1930604 :         && (flag_generate_lto || flag_generate_offload|| flag_wpa
    4729      1733165 :             || opt_for_fn (node->decl, optimize)))
    4730      1400089 :       inline_analyze_function (node);
    4731       237038 : }
    4732              : 
    4733              : 
    4734              : /* Write inline summary for edge E to OB.  */
    4735              : 
    4736              : static void
    4737       348846 : read_ipa_call_summary (class lto_input_block *ib, struct cgraph_edge *e,
    4738              :                        bool prevails)
    4739              : {
    4740       348846 :   class ipa_call_summary *es = prevails
    4741       348846 :                                 ? ipa_call_summaries->get_create (e) : NULL;
    4742       348846 :   ipa_predicate p;
    4743       348846 :   int length, i;
    4744              : 
    4745       348846 :   int size = streamer_read_uhwi (ib);
    4746       348846 :   int time = streamer_read_uhwi (ib);
    4747       348846 :   int depth = streamer_read_uhwi (ib);
    4748              : 
    4749       348846 :   if (es)
    4750              :     {
    4751       348797 :       es->call_stmt_size = size;
    4752       348797 :       es->call_stmt_time = time;
    4753       348797 :       es->loop_depth = depth;
    4754              :     }
    4755              : 
    4756       348846 :   bitpack_d bp = streamer_read_bitpack (ib);
    4757       348846 :   if (es)
    4758       348797 :     es->is_return_callee_uncaptured = bp_unpack_value (&bp, 1);
    4759              :   else
    4760           49 :     bp_unpack_value (&bp, 1);
    4761              : 
    4762       348846 :   p.stream_in (ib);
    4763       348846 :   if (es)
    4764       348797 :     edge_set_predicate (e, &p);
    4765       348846 :   length = streamer_read_uhwi (ib);
    4766       348846 :   if (length && es
    4767       348846 :       && (e->possibly_call_in_translation_unit_p ()
    4768              :           /* Also stream in jump functions to builtins in hope that they
    4769              :              will get fnspecs.  */
    4770       119155 :           || fndecl_built_in_p (e->callee->decl, BUILT_IN_NORMAL)))
    4771              :     {
    4772       233342 :       es->param.safe_grow_cleared (length, true);
    4773      1036021 :       for (i = 0; i < length; i++)
    4774              :         {
    4775       569337 :           es->param[i].change_prob = streamer_read_uhwi (ib);
    4776       569337 :           bitpack_d bp = streamer_read_bitpack (ib);
    4777      1708011 :           es->param[i].points_to_local_or_readonly_memory
    4778       569337 :             = bp_unpack_value (&bp, 1);
    4779      1708011 :           es->param[i].points_to_possible_sra_candidate
    4780       569337 :             = bp_unpack_value (&bp, 1);
    4781              :         }
    4782              :     }
    4783              :   else
    4784              :     {
    4785       138576 :       for (i = 0; i < length; i++)
    4786              :         {
    4787        23072 :           streamer_read_uhwi (ib);
    4788        23072 :           streamer_read_uhwi (ib);
    4789              :         }
    4790              :     }
    4791       348846 : }
    4792              : 
    4793              : 
    4794              : /* Stream in inline summaries from the section.  */
    4795              : 
    4796              : static void
    4797        13494 : inline_read_section (struct lto_file_decl_data *file_data, const char *data,
    4798              :                      size_t len)
    4799              : {
    4800        13494 :   const struct lto_function_header *header =
    4801              :     (const struct lto_function_header *) data;
    4802        13494 :   const int cfg_offset = sizeof (struct lto_function_header);
    4803        13494 :   const int main_offset = cfg_offset + header->cfg_size;
    4804        13494 :   const int string_offset = main_offset + header->main_size;
    4805        13494 :   class data_in *data_in;
    4806        13494 :   unsigned int i, count2, j;
    4807        13494 :   unsigned int f_count;
    4808              : 
    4809        13494 :   lto_input_block ib ((const char *) data + main_offset, header->main_size,
    4810        13494 :                       file_data);
    4811              : 
    4812        13494 :   data_in =
    4813        26988 :     lto_data_in_create (file_data, (const char *) data + string_offset,
    4814        13494 :                         header->string_size, vNULL);
    4815        13494 :   f_count = streamer_read_uhwi (&ib);
    4816       100760 :   for (i = 0; i < f_count; i++)
    4817              :     {
    4818        87266 :       unsigned int index;
    4819        87266 :       struct cgraph_node *node;
    4820        87266 :       class ipa_fn_summary *info;
    4821        87266 :       class ipa_node_params *params_summary;
    4822        87266 :       class ipa_size_summary *size_info;
    4823        87266 :       lto_symtab_encoder_t encoder;
    4824        87266 :       struct bitpack_d bp;
    4825        87266 :       struct cgraph_edge *e;
    4826        87266 :       ipa_predicate p;
    4827              : 
    4828        87266 :       index = streamer_read_uhwi (&ib);
    4829        87266 :       encoder = file_data->symtab_node_encoder;
    4830        87266 :       node = dyn_cast<cgraph_node *> (lto_symtab_encoder_deref (encoder,
    4831              :                                                                 index));
    4832        87266 :       info = node->prevailing_p () ? ipa_fn_summaries->get_create (node) : NULL;
    4833        87266 :       params_summary = node->prevailing_p ()
    4834        87266 :                        ? ipa_node_params_sum->get (node) : NULL;
    4835        87266 :       size_info = node->prevailing_p ()
    4836        87266 :                   ? ipa_size_summaries->get_create (node) : NULL;
    4837              : 
    4838        87266 :       int stack_size = streamer_read_uhwi (&ib);
    4839        87266 :       int size = streamer_read_uhwi (&ib);
    4840        87266 :       sreal time = sreal::stream_in (&ib);
    4841              : 
    4842        87266 :       if (info)
    4843              :         {
    4844        87208 :           info->estimated_stack_size
    4845        87208 :             = size_info->estimated_self_stack_size = stack_size;
    4846        87208 :           size_info->size = size_info->self_size = size;
    4847        87208 :           info->time = time;
    4848              :         }
    4849              : 
    4850        87266 :       bp = streamer_read_bitpack (&ib);
    4851        87266 :       if (info)
    4852              :         {
    4853        87208 :           info->inlinable = bp_unpack_value (&bp, 1);
    4854        87208 :           info->fp_expressions = bp_unpack_value (&bp, 1);
    4855        87208 :           if (!lto_stream_offload_p)
    4856        87208 :             info->target_info = streamer_read_uhwi (&ib);
    4857              :         }
    4858              :       else
    4859              :         {
    4860           58 :           bp_unpack_value (&bp, 1);
    4861           58 :           bp_unpack_value (&bp, 1);
    4862           58 :           if (!lto_stream_offload_p)
    4863           58 :             streamer_read_uhwi (&ib);
    4864              :         }
    4865              : 
    4866        87266 :       count2 = streamer_read_uhwi (&ib);
    4867        87266 :       gcc_assert (!info || !info->conds);
    4868        87208 :       if (info)
    4869        87208 :         vec_safe_reserve_exact (info->conds, count2);
    4870       165708 :       for (j = 0; j < count2; j++)
    4871              :         {
    4872        78442 :           struct condition c;
    4873        78442 :           unsigned int k, count3;
    4874        78442 :           c.operand_num = streamer_read_uhwi (&ib);
    4875        78442 :           c.code = (enum tree_code) streamer_read_uhwi (&ib);
    4876        78442 :           c.type = stream_read_tree (&ib, data_in);
    4877        78442 :           c.val = stream_read_tree (&ib, data_in);
    4878        78442 :           bp = streamer_read_bitpack (&ib);
    4879        78442 :           c.agg_contents = bp_unpack_value (&bp, 1);
    4880        78442 :           c.by_ref = bp_unpack_value (&bp, 1);
    4881        78442 :           if (c.agg_contents)
    4882        12568 :             c.offset = streamer_read_uhwi (&ib);
    4883        78442 :           count3 = streamer_read_uhwi (&ib);
    4884        78442 :           c.param_ops = NULL;
    4885        78442 :           if (info)
    4886        78442 :             vec_safe_reserve_exact (c.param_ops, count3);
    4887        78442 :           if (params_summary)
    4888        78442 :             ipa_set_param_used_by_ipa_predicates
    4889        78442 :                     (params_summary, c.operand_num, true);
    4890        82195 :           for (k = 0; k < count3; k++)
    4891              :             {
    4892         3753 :               struct expr_eval_op op;
    4893         3753 :               enum gimple_rhs_class rhs_class;
    4894         3753 :               op.code = (enum tree_code) streamer_read_uhwi (&ib);
    4895         3753 :               op.type = stream_read_tree (&ib, data_in);
    4896         3753 :               switch (rhs_class = get_gimple_rhs_class (op.code))
    4897              :                 {
    4898         1565 :                 case GIMPLE_UNARY_RHS:
    4899         1565 :                   op.index = 0;
    4900         1565 :                   op.val[0] = NULL_TREE;
    4901         1565 :                   op.val[1] = NULL_TREE;
    4902         1565 :                   break;
    4903              : 
    4904         2188 :                 case GIMPLE_BINARY_RHS:
    4905         2188 :                 case GIMPLE_TERNARY_RHS:
    4906         2188 :                   bp = streamer_read_bitpack (&ib);
    4907         2188 :                   op.index = bp_unpack_value (&bp, 2);
    4908         2188 :                   op.val[0] = stream_read_tree (&ib, data_in);
    4909         2188 :                   if (rhs_class == GIMPLE_BINARY_RHS)
    4910         2188 :                     op.val[1] = NULL_TREE;
    4911              :                   else
    4912            0 :                     op.val[1] = stream_read_tree (&ib, data_in);
    4913              :                   break;
    4914              : 
    4915            0 :                 default:
    4916            0 :                   fatal_error (UNKNOWN_LOCATION,
    4917              :                                "invalid fnsummary in LTO stream");
    4918              :                 }
    4919         3753 :               if (info)
    4920         3753 :                 c.param_ops->quick_push (op);
    4921              :             }
    4922        78442 :           if (info)
    4923        78442 :             info->conds->quick_push (c);
    4924              :         }
    4925        87266 :       count2 = streamer_read_uhwi (&ib);
    4926        87266 :       gcc_assert (!info || !info->size_time_table.length ());
    4927        87266 :       if (info && count2)
    4928        87208 :         info->size_time_table.reserve_exact (count2);
    4929       331865 :       for (j = 0; j < count2; j++)
    4930              :         {
    4931       244599 :           class size_time_entry e;
    4932              : 
    4933       244599 :           e.size = streamer_read_uhwi (&ib);
    4934       244599 :           e.time = sreal::stream_in (&ib);
    4935       244599 :           e.exec_predicate.stream_in (&ib);
    4936       244599 :           e.nonconst_predicate.stream_in (&ib);
    4937              : 
    4938       244599 :           if (info)
    4939       244483 :             info->size_time_table.quick_push (e);
    4940              :         }
    4941              : 
    4942        87266 :       count2 = streamer_read_uhwi (&ib);
    4943        88690 :       for (j = 0; j < count2; j++)
    4944              :         {
    4945         1424 :           p.stream_in (&ib);
    4946         1424 :           sreal fcp_freq = sreal::stream_in (&ib);
    4947         1424 :           if (info)
    4948              :             {
    4949         1424 :               ipa_freqcounting_predicate fcp;
    4950         1424 :               fcp.predicate = NULL;
    4951         1424 :               set_hint_predicate (&fcp.predicate, p);
    4952         1424 :               fcp.freq = fcp_freq;
    4953         1424 :               vec_safe_push (info->loop_iterations, fcp);
    4954              :             }
    4955              :         }
    4956        87266 :       count2 = streamer_read_uhwi (&ib);
    4957        87556 :       for (j = 0; j < count2; j++)
    4958              :         {
    4959          290 :           p.stream_in (&ib);
    4960          290 :           sreal fcp_freq = sreal::stream_in (&ib);
    4961          290 :           if (info)
    4962              :             {
    4963          290 :               ipa_freqcounting_predicate fcp;
    4964          290 :               fcp.predicate = NULL;
    4965          290 :               set_hint_predicate (&fcp.predicate, p);
    4966          290 :               fcp.freq = fcp_freq;
    4967          290 :               vec_safe_push (info->loop_strides, fcp);
    4968              :             }
    4969              :         }
    4970        87266 :       count2 = streamer_read_uhwi (&ib);
    4971        87266 :       if (info && count2)
    4972            8 :         info->builtin_constant_p_parms.reserve_exact (count2);
    4973        87274 :       for (j = 0; j < count2; j++)
    4974              :         {
    4975            8 :           int parm = streamer_read_uhwi (&ib);
    4976            8 :           if (info)
    4977            8 :             info->builtin_constant_p_parms.quick_push (parm);
    4978              :         }
    4979       434615 :       for (e = node->callees; e; e = e->next_callee)
    4980       347349 :         read_ipa_call_summary (&ib, e, info != NULL);
    4981        88763 :       for (e = node->indirect_calls; e; e = e->next_callee)
    4982         1497 :         read_ipa_call_summary (&ib, e, info != NULL);
    4983              :     }
    4984              : 
    4985        13494 :   lto_free_section_data (file_data, LTO_section_ipa_fn_summary, NULL, data,
    4986              :                          len);
    4987        13494 :   lto_data_in_delete (data_in);
    4988        13494 : }
    4989              : 
    4990              : 
    4991              : /* Read inline summary.  Jump functions are shared among ipa-cp
    4992              :    and inliner, so when ipa-cp is active, we don't need to write them
    4993              :    twice.  */
    4994              : 
    4995              : static void
    4996        12402 : ipa_fn_summary_read (void)
    4997              : {
    4998        12402 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    4999        12402 :   struct lto_file_decl_data *file_data;
    5000        12402 :   unsigned int j = 0;
    5001              : 
    5002        12402 :   ipa_prop_read_jump_functions ();
    5003        12402 :   ipa_fn_summary_alloc ();
    5004              : 
    5005        38298 :   while ((file_data = file_data_vec[j++]))
    5006              :     {
    5007        13494 :       size_t len;
    5008        13494 :       const char *data
    5009        13494 :         = lto_get_summary_section_data (file_data, LTO_section_ipa_fn_summary,
    5010              :                                         &len);
    5011        13494 :       if (data)
    5012        13494 :         inline_read_section (file_data, data, len);
    5013              :       else
    5014              :         /* Fatal error here.  We do not want to support compiling ltrans units
    5015              :            with different version of compiler or different flags than the WPA
    5016              :            unit, so this should never happen.  */
    5017            0 :         fatal_error (input_location,
    5018              :                      "ipa inline summary is missing in input file");
    5019              :     }
    5020        12402 :   ipa_register_cgraph_hooks ();
    5021              : 
    5022        12402 :   gcc_assert (ipa_fn_summaries);
    5023        12402 :   ipa_fn_summaries->enable_insertion_hook ();
    5024        12402 : }
    5025              : 
    5026              : 
    5027              : /* Write inline summary for edge E to OB.  */
    5028              : 
    5029              : static void
    5030       380584 : write_ipa_call_summary (struct output_block *ob, struct cgraph_edge *e)
    5031              : {
    5032       380584 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
    5033       380584 :   int i;
    5034              : 
    5035       380584 :   streamer_write_uhwi (ob, es->call_stmt_size);
    5036       380584 :   streamer_write_uhwi (ob, es->call_stmt_time);
    5037       380584 :   streamer_write_uhwi (ob, es->loop_depth);
    5038              : 
    5039       380584 :   bitpack_d bp = bitpack_create (ob->main_stream);
    5040       380584 :   bp_pack_value (&bp, es->is_return_callee_uncaptured, 1);
    5041       380584 :   streamer_write_bitpack (&bp);
    5042              : 
    5043       380584 :   if (es->predicate)
    5044        10758 :     es->predicate->stream_out (ob);
    5045              :   else
    5046       369826 :     streamer_write_uhwi (ob, 0);
    5047       380584 :   streamer_write_uhwi (ob, es->param.length ());
    5048      2296731 :   for (i = 0; i < (int) es->param.length (); i++)
    5049              :     {
    5050       633168 :       streamer_write_uhwi (ob, es->param[i].change_prob);
    5051       633168 :       bp = bitpack_create (ob->main_stream);
    5052       633168 :       bp_pack_value (&bp, es->param[i].points_to_local_or_readonly_memory, 1);
    5053       633168 :       bp_pack_value (&bp, es->param[i].points_to_possible_sra_candidate, 1);
    5054       633168 :       streamer_write_bitpack (&bp);
    5055              :     }
    5056       380584 : }
    5057              : 
    5058              : 
    5059              : /* Write inline summary for node in SET.
    5060              :    Jump functions are shared among ipa-cp and inliner, so when ipa-cp is
    5061              :    active, we don't need to write them twice.  */
    5062              : 
    5063              : static void
    5064        23417 : ipa_fn_summary_write (void)
    5065              : {
    5066        23417 :   struct output_block *ob = create_output_block (LTO_section_ipa_fn_summary);
    5067        23417 :   lto_symtab_encoder_iterator lsei;
    5068        23417 :   lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
    5069        23417 :   unsigned int count = 0;
    5070              : 
    5071       129762 :   for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
    5072       106345 :        lsei_next_function_in_partition (&lsei))
    5073              :     {
    5074       106345 :       cgraph_node *cnode = lsei_cgraph_node (lsei);
    5075       106345 :       if (cnode->definition && !cnode->alias)
    5076       103865 :         count++;
    5077              :     }
    5078        23417 :   streamer_write_uhwi (ob, count);
    5079              : 
    5080       129762 :   for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
    5081       106345 :        lsei_next_function_in_partition (&lsei))
    5082              :     {
    5083       106345 :       cgraph_node *cnode = lsei_cgraph_node (lsei);
    5084       106345 :       if (cnode->definition && !cnode->alias)
    5085              :         {
    5086       103865 :           class ipa_fn_summary *info = ipa_fn_summaries->get (cnode);
    5087       103865 :           class ipa_size_summary *size_info = ipa_size_summaries->get (cnode);
    5088       103865 :           struct bitpack_d bp;
    5089       103865 :           struct cgraph_edge *edge;
    5090       103865 :           int i;
    5091       103865 :           size_time_entry *e;
    5092       103865 :           struct condition *c;
    5093              : 
    5094       103865 :           streamer_write_uhwi (ob, lto_symtab_encoder_encode (encoder, cnode));
    5095       103865 :           streamer_write_hwi (ob, size_info->estimated_self_stack_size);
    5096       103865 :           streamer_write_hwi (ob, size_info->self_size);
    5097       103865 :           info->time.stream_out (ob);
    5098       103865 :           bp = bitpack_create (ob->main_stream);
    5099       103865 :           bp_pack_value (&bp, info->inlinable, 1);
    5100       103865 :           bp_pack_value (&bp, info->fp_expressions, 1);
    5101       103865 :           streamer_write_bitpack (&bp);
    5102       103865 :           if (!lto_stream_offload_p)
    5103       103865 :             streamer_write_uhwi (ob, info->target_info);
    5104       103865 :           streamer_write_uhwi (ob, vec_safe_length (info->conds));
    5105       302305 :           for (i = 0; vec_safe_iterate (info->conds, i, &c); i++)
    5106              :             {
    5107        94575 :               int j;
    5108        94575 :               struct expr_eval_op *op;
    5109              : 
    5110        94575 :               streamer_write_uhwi (ob, c->operand_num);
    5111        94575 :               streamer_write_uhwi (ob, c->code);
    5112        94575 :               stream_write_tree (ob, c->type, true);
    5113        94575 :               stream_write_tree (ob, c->val, true);
    5114        94575 :               bp = bitpack_create (ob->main_stream);
    5115        94575 :               bp_pack_value (&bp, c->agg_contents, 1);
    5116        94575 :               bp_pack_value (&bp, c->by_ref, 1);
    5117        94575 :               streamer_write_bitpack (&bp);
    5118        94575 :               if (c->agg_contents)
    5119        15825 :                 streamer_write_uhwi (ob, c->offset);
    5120        94575 :               streamer_write_uhwi (ob, vec_safe_length (c->param_ops));
    5121       196617 :               for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
    5122              :                 {
    5123         4415 :                   streamer_write_uhwi (ob, op->code);
    5124         4415 :                   stream_write_tree (ob, op->type, true);
    5125         4415 :                   if (op->val[0])
    5126              :                     {
    5127         2576 :                       bp = bitpack_create (ob->main_stream);
    5128         2576 :                       bp_pack_value (&bp, op->index, 2);
    5129         2576 :                       streamer_write_bitpack (&bp);
    5130         2576 :                       stream_write_tree (ob, op->val[0], true);
    5131         2576 :                       if (op->val[1])
    5132            4 :                         stream_write_tree (ob, op->val[1], true);
    5133              :                     }
    5134              :                 }
    5135              :             }
    5136       103865 :           streamer_write_uhwi (ob, info->size_time_table.length ());
    5137       502567 :           for (i = 0; info->size_time_table.iterate (i, &e); i++)
    5138              :             {
    5139       294837 :               streamer_write_uhwi (ob, e->size);
    5140       294837 :               e->time.stream_out (ob);
    5141       294837 :               e->exec_predicate.stream_out (ob);
    5142       294837 :               e->nonconst_predicate.stream_out (ob);
    5143              :             }
    5144       103865 :           ipa_freqcounting_predicate *fcp;
    5145       103865 :           streamer_write_uhwi (ob, vec_safe_length (info->loop_iterations));
    5146       209811 :           for (i = 0; vec_safe_iterate (info->loop_iterations, i, &fcp); i++)
    5147              :             {
    5148         2081 :               fcp->predicate->stream_out (ob);
    5149         2081 :               fcp->freq.stream_out (ob);
    5150              :             }
    5151       103865 :           streamer_write_uhwi (ob, vec_safe_length (info->loop_strides));
    5152       208076 :           for (i = 0; vec_safe_iterate (info->loop_strides, i, &fcp); i++)
    5153              :             {
    5154          346 :               fcp->predicate->stream_out (ob);
    5155          346 :               fcp->freq.stream_out (ob);
    5156              :             }
    5157       103865 :           streamer_write_uhwi (ob, info->builtin_constant_p_parms.length ());
    5158       103865 :           int ip;
    5159       207746 :           for (i = 0; info->builtin_constant_p_parms.iterate (i, &ip);
    5160              :                i++)
    5161           16 :             streamer_write_uhwi (ob, ip);
    5162       481744 :           for (edge = cnode->callees; edge; edge = edge->next_callee)
    5163       377879 :             write_ipa_call_summary (ob, edge);
    5164       106570 :           for (edge = cnode->indirect_calls; edge; edge = edge->next_callee)
    5165         2705 :             write_ipa_call_summary (ob, edge);
    5166              :         }
    5167              :     }
    5168        23417 :   streamer_write_char_stream (ob->main_stream, 0);
    5169        23417 :   produce_asm (ob);
    5170        23417 :   destroy_output_block (ob);
    5171              : 
    5172        23417 :   ipa_prop_write_jump_functions ();
    5173        23417 : }
    5174              : 
    5175              : 
    5176              : /* Release function summary.  */
    5177              : 
    5178              : void
    5179       740013 : ipa_free_fn_summary (void)
    5180              : {
    5181       740013 :   if (!ipa_call_summaries)
    5182              :     return;
    5183       468186 :   ggc_delete (ipa_fn_summaries);
    5184       468186 :   ipa_fn_summaries = NULL;
    5185       468186 :   delete ipa_call_summaries;
    5186       468186 :   ipa_call_summaries = NULL;
    5187       468186 :   edge_predicate_pool.release ();
    5188              :   /* During IPA this is one of largest datastructures to release.  */
    5189       468186 :   if (flag_wpa)
    5190         7862 :     ggc_trim ();
    5191              : }
    5192              : 
    5193              : /* Release function summary.  */
    5194              : 
    5195              : void
    5196       740013 : ipa_free_size_summary (void)
    5197              : {
    5198       740013 :   if (!ipa_size_summaries)
    5199              :     return;
    5200       468186 :   delete ipa_size_summaries;
    5201       468186 :   ipa_size_summaries = NULL;
    5202              : }
    5203              : 
    5204              : namespace {
    5205              : 
    5206              : const pass_data pass_data_local_fn_summary =
    5207              : {
    5208              :   GIMPLE_PASS, /* type */
    5209              :   "local-fnsummary", /* name */
    5210              :   OPTGROUP_INLINE, /* optinfo_flags */
    5211              :   TV_INLINE_PARAMETERS, /* tv_id */
    5212              :   0, /* properties_required */
    5213              :   0, /* properties_provided */
    5214              :   0, /* properties_destroyed */
    5215              :   0, /* todo_flags_start */
    5216              :   0, /* todo_flags_finish */
    5217              : };
    5218              : 
    5219              : class pass_local_fn_summary : public gimple_opt_pass
    5220              : {
    5221              : public:
    5222       589072 :   pass_local_fn_summary (gcc::context *ctxt)
    5223      1178144 :     : gimple_opt_pass (pass_data_local_fn_summary, ctxt)
    5224              :   {}
    5225              : 
    5226              :   /* opt_pass methods: */
    5227       294536 :   opt_pass * clone () final override
    5228              :   {
    5229       294536 :     return new pass_local_fn_summary (m_ctxt);
    5230              :   }
    5231      6048724 :   unsigned int execute (function *) final override
    5232              :     {
    5233      6048724 :       return compute_fn_summary_for_current ();
    5234              :     }
    5235              : 
    5236              : }; // class pass_local_fn_summary
    5237              : 
    5238              : } // anon namespace
    5239              : 
    5240              : gimple_opt_pass *
    5241       294536 : make_pass_local_fn_summary (gcc::context *ctxt)
    5242              : {
    5243       294536 :   return new pass_local_fn_summary (ctxt);
    5244              : }
    5245              : 
    5246              : 
    5247              : /* Free inline summary.  */
    5248              : 
    5249              : namespace {
    5250              : 
    5251              : const pass_data pass_data_ipa_free_fn_summary =
    5252              : {
    5253              :   SIMPLE_IPA_PASS, /* type */
    5254              :   "free-fnsummary", /* name */
    5255              :   OPTGROUP_NONE, /* optinfo_flags */
    5256              :   TV_IPA_FREE_INLINE_SUMMARY, /* tv_id */
    5257              :   0, /* properties_required */
    5258              :   0, /* properties_provided */
    5259              :   0, /* properties_destroyed */
    5260              :   0, /* todo_flags_start */
    5261              :   0, /* todo_flags_finish */
    5262              : };
    5263              : 
    5264              : class pass_ipa_free_fn_summary : public simple_ipa_opt_pass
    5265              : {
    5266              : public:
    5267       589072 :   pass_ipa_free_fn_summary (gcc::context *ctxt)
    5268              :     : simple_ipa_opt_pass (pass_data_ipa_free_fn_summary, ctxt),
    5269      1178144 :       small_p (false)
    5270              :   {}
    5271              : 
    5272              :   /* opt_pass methods: */
    5273       294536 :   opt_pass *clone () final override
    5274              :   {
    5275       294536 :     return new pass_ipa_free_fn_summary (m_ctxt);
    5276              :   }
    5277       589072 :   void set_pass_param (unsigned int n, bool param) final override
    5278              :     {
    5279       589072 :       gcc_assert (n == 0);
    5280       589072 :       small_p = param;
    5281       589072 :     }
    5282       495310 :   bool gate (function *) final override { return true; }
    5283       474651 :   unsigned int execute (function *) final override
    5284              :     {
    5285       474651 :       ipa_free_fn_summary ();
    5286              :       /* Free ipa-prop structures if they are no longer needed.  */
    5287       474651 :       ipa_free_all_structures_after_iinln ();
    5288       474651 :       if (!flag_wpa)
    5289       466789 :         ipa_free_size_summary ();
    5290       474651 :       return 0;
    5291              :     }
    5292              : 
    5293              : private:
    5294              :   bool small_p;
    5295              : }; // class pass_ipa_free_fn_summary
    5296              : 
    5297              : } // anon namespace
    5298              : 
    5299              : simple_ipa_opt_pass *
    5300       294536 : make_pass_ipa_free_fn_summary (gcc::context *ctxt)
    5301              : {
    5302       294536 :   return new pass_ipa_free_fn_summary (ctxt);
    5303              : }
    5304              : 
    5305              : namespace {
    5306              : 
    5307              : const pass_data pass_data_ipa_fn_summary =
    5308              : {
    5309              :   IPA_PASS, /* type */
    5310              :   "fnsummary", /* name */
    5311              :   OPTGROUP_INLINE, /* optinfo_flags */
    5312              :   TV_IPA_FNSUMMARY, /* tv_id */
    5313              :   0, /* properties_required */
    5314              :   0, /* properties_provided */
    5315              :   0, /* properties_destroyed */
    5316              :   0, /* todo_flags_start */
    5317              :   ( TODO_dump_symtab ), /* todo_flags_finish */
    5318              : };
    5319              : 
    5320              : class pass_ipa_fn_summary : public ipa_opt_pass_d
    5321              : {
    5322              : public:
    5323       294536 :   pass_ipa_fn_summary (gcc::context *ctxt)
    5324              :     : ipa_opt_pass_d (pass_data_ipa_fn_summary, ctxt,
    5325              :                       ipa_fn_summary_generate, /* generate_summary */
    5326              :                       ipa_fn_summary_write, /* write_summary */
    5327              :                       ipa_fn_summary_read, /* read_summary */
    5328              :                       NULL, /* write_optimization_summary */
    5329              :                       NULL, /* read_optimization_summary */
    5330              :                       NULL, /* stmt_fixup */
    5331              :                       0, /* function_transform_todo_flags_start */
    5332              :                       NULL, /* function_transform */
    5333       294536 :                       NULL) /* variable_transform */
    5334       294536 :   {}
    5335              : 
    5336              :   /* opt_pass methods: */
    5337       237464 :   unsigned int execute (function *) final override { return 0; }
    5338              : 
    5339              : }; // class pass_ipa_fn_summary
    5340              : 
    5341              : } // anon namespace
    5342              : 
    5343              : ipa_opt_pass_d *
    5344       294536 : make_pass_ipa_fn_summary (gcc::context *ctxt)
    5345              : {
    5346       294536 :   return new pass_ipa_fn_summary (ctxt);
    5347              : }
    5348              : 
    5349              : /* Reset all state within ipa-fnsummary.cc so that we can rerun the compiler
    5350              :    within the same process.  For use by toplev::finalize.  */
    5351              : 
    5352              : void
    5353       264460 : ipa_fnsummary_cc_finalize (void)
    5354              : {
    5355       264460 :   ipa_free_fn_summary ();
    5356       264460 :   ipa_free_size_summary ();
    5357       264460 : }
        

Generated by: LCOV version 2.5.0-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.