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-09-19 16:22:48 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    138915862 : 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    138915862 :   size_time_entry *e;
     173    138915862 :   bool found = false;
     174    138915862 :   int i;
     175    138915862 :   ipa_predicate nonconst_pred;
     176    138915862 :   vec<size_time_entry> *table = call ? &call_size_time_table : &size_time_table;
     177              : 
     178    138915862 :   if (exec_pred == false)
     179      5100543 :     return;
     180              : 
     181    138620664 :   nonconst_pred = nonconst_pred_in & exec_pred;
     182              : 
     183    138620664 :   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    162734833 :   if (!size && time == 0 && table->length ())
     189      4043844 :     return;
     190              : 
     191              :   /* Only for calls we are unaccounting what we previously recorded.  */
     192    133815319 :   gcc_checking_assert (time >= 0 || call);
     193              : 
     194    486769530 :   for (i = 0; table->iterate (i, &e); i++)
     195    456411855 :     if (e->exec_predicate == exec_pred
     196    456411855 :         && e->nonconst_predicate == nonconst_pred)
     197              :       {
     198              :         found = true;
     199              :         break;
     200              :       }
     201    133815319 :   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    133819556 :   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    133815319 :   if (!found)
     227              :     {
     228     30352779 :       class size_time_entry new_entry;
     229     30352779 :       new_entry.size = size;
     230     30352779 :       new_entry.time = time;
     231     30352779 :       new_entry.exec_predicate = exec_pred;
     232     30352779 :       new_entry.nonconst_predicate = nonconst_pred;
     233     30352779 :       if (call)
     234      1377346 :         call_size_time_table.safe_push (new_entry);
     235              :       else
     236     28975433 :         size_time_table.safe_push (new_entry);
     237              :     }
     238              :   else
     239              :     {
     240    103462540 :       e->size += size;
     241    103462540 :       e->time += time;
     242              :       /* FIXME: PR bootstrap/92653 gcc_checking_assert (e->time >= -1); */
     243              :       /* Tolerate small roundoff issues.  */
     244    103462540 :       if (e->time < 0)
     245          216 :         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       350766 : redirect_to_unreachable (struct cgraph_edge *e)
     253              : {
     254       350766 :   struct cgraph_node *callee = !e->inline_failed ? e->callee : NULL;
     255       350766 :   struct cgraph_node *target
     256       350766 :     = cgraph_node::get_create (builtin_decl_unreachable ());
     257              : 
     258       350766 :   gcc_checking_assert (lookup_attribute ("cold",
     259              :                                          DECL_ATTRIBUTES (target->decl)));
     260              : 
     261       350766 :   if (e->speculative)
     262          311 :     e = cgraph_edge::resolve_speculation (e, target->decl);
     263       350455 :   else if (!e->callee)
     264          785 :     e = cgraph_edge::make_direct (e, target);
     265              :   else
     266       349670 :     e->redirect_callee (target);
     267       350766 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
     268       350766 :   e->inline_failed = CIF_UNREACHABLE;
     269       350766 :   e->count = profile_count::zero ();
     270       350766 :   es->call_stmt_size = 0;
     271       350766 :   es->call_stmt_time = 0;
     272       350766 :   if (callee)
     273            0 :     callee->remove_symbol_and_inline_clones ();
     274       350766 :   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       350766 :   return e;
     280              : }
     281              : 
     282              : /* Set predicate for edge E.  */
     283              : 
     284              : static void
     285     32070441 : 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     29093386 :   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     32421282 :       && (!e->speculative || e->callee))
     295       350764 :     e = redirect_to_unreachable (e);
     296              : 
     297     32070441 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
     298     61163827 :   if (predicate && *predicate != true)
     299              :     {
     300      4774520 :       if (!es->predicate)
     301      4248885 :         es->predicate = edge_predicate_pool.allocate ();
     302      4774520 :       *es->predicate = *predicate;
     303              :     }
     304              :   else
     305              :     {
     306     27295921 :       if (es->predicate)
     307       865717 :         edge_predicate_pool.remove (es->predicate);
     308     27295921 :       es->predicate = NULL;
     309              :     }
     310     32070441 : }
     311              : 
     312              : /* Set predicate for hint *P.  */
     313              : 
     314              : static void
     315       152549 : set_hint_predicate (ipa_predicate **p, ipa_predicate new_predicate)
     316              : {
     317       152549 :   if (new_predicate == false || new_predicate == true)
     318              :     {
     319         2947 :       if (*p)
     320            0 :         edge_predicate_pool.remove (*p);
     321         2947 :       *p = NULL;
     322              :     }
     323              :   else
     324              :     {
     325       149602 :       if (!*p)
     326       149602 :         *p = edge_predicate_pool.allocate ();
     327       149602 :       **p = new_predicate;
     328              :     }
     329       152549 : }
     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      1131654 : 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      1131654 :   if (new_predicate == false || new_predicate == true)
     342              :     return;
     343              :   ipa_freqcounting_predicate *f;
     344       143363 :   for (int i = 0; vec_safe_iterate (*v, i, &f); i++)
     345        72050 :     if (new_predicate == f->predicate)
     346              :       {
     347            0 :         f->freq += add_freq;
     348            0 :         return;
     349              :       }
     350        97484 :   if (vec_safe_length (*v) >= max_num_predicates)
     351              :     /* Too many different predicates to account for.  */
     352              :     return;
     353              : 
     354        71041 :   ipa_freqcounting_predicate fcp;
     355        71041 :   fcp.predicate = NULL;
     356        71041 :   set_hint_predicate (&fcp.predicate, new_predicate);
     357        71041 :   fcp.freq = add_freq;
     358        71041 :   vec_safe_push (*v, fcp);
     359        71041 :   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     23049327 : 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     23049327 :   clause_t clause = inline_p ? 0 : 1 << ipa_predicate::not_inlined_condition;
     388     23049327 :   clause_t nonspec_clause = 1 << ipa_predicate::not_inlined_condition;
     389     23049327 :   class ipa_fn_summary *info = ipa_fn_summaries->get (node);
     390     23049327 :   int i;
     391     23049327 :   struct condition *c;
     392              : 
     393     95617139 :   for (i = 0; vec_safe_iterate (info->conds, i, &c); i++)
     394              :     {
     395     72567812 :       tree val = NULL;
     396     72567812 :       tree res;
     397     72567812 :       int j;
     398     72567812 :       struct expr_eval_op *op;
     399              : 
     400     72567812 :       if (c->code == ipa_predicate::not_sra_candidate)
     401              :         {
     402     16899396 :           if (!inline_p
     403     16899396 :               || !es
     404     16742191 :               || (int)es->param.length () <= c->operand_num
     405     25270470 :               || !es->param[c->operand_num].points_to_possible_sra_candidate)
     406     12582921 :             clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     407     16899396 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     408     72567812 :           continue;
     409              :         }
     410              : 
     411     55668416 :       if (c->agg_contents)
     412              :         {
     413     30903662 :           if (c->code == ipa_predicate::changed
     414     19757356 :               && !c->by_ref
     415     33763487 :               && (avals->safe_sval_at(c->operand_num) == error_mark_node))
     416         3466 :             continue;
     417              : 
     418     30896730 :           if (tree sval = avals->safe_sval_at (c->operand_num))
     419     14445034 :             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     30896730 :           if (!val && (c->offset % BITS_PER_UNIT) == 0)
     425              :             {
     426     30859895 :               ipa_argagg_value_list avs (avals);
     427     30859895 :               val = avs.get_value (c->operand_num, c->offset / BITS_PER_UNIT,
     428     30859895 :                                    c->by_ref);
     429              :             }
     430              :         }
     431              :       else
     432              :         {
     433     24768220 :           val = avals->safe_sval_at (c->operand_num);
     434     24768220 :           if (val && val == error_mark_node
     435      2308949 :               && c->code != ipa_predicate::changed)
     436              :             val = NULL_TREE;
     437              :         }
     438              : 
     439     42239055 :       if (!val
     440     42118321 :           && (c->code == ipa_predicate::changed
     441              :               || c->code == ipa_predicate::is_not_constant))
     442              :         {
     443     26648153 :           clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     444     26648153 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     445     26648153 :           continue;
     446              :         }
     447     29016797 :       if (c->code == ipa_predicate::changed)
     448              :         {
     449      7800343 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     450      7800343 :           continue;
     451              :         }
     452              : 
     453     21216454 :       if (c->code == ipa_predicate::is_not_constant)
     454              :         {
     455         8693 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     456         8693 :           continue;
     457              :         }
     458              : 
     459     21207761 :       if (val
     460     21207761 :           && (c->type == TREE_TYPE (val)
     461      1023143 :               || (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       942249 :                   && ((!INTEGRAL_TYPE_P (c->type)
     466       238476 :                        || type_has_mode_precision_p (c->type))
     467       940526 :                       && (!INTEGRAL_TYPE_P (TREE_TYPE (val))
     468       236933 :                           || type_has_mode_precision_p (TREE_TYPE (val)))))))
     469              :         {
     470      5654962 :           if (c->type != TREE_TYPE (val))
     471       940512 :             val = fold_unary (VIEW_CONVERT_EXPR, c->type, val);
     472      6181225 :           for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
     473              :             {
     474       526728 :               if (!val)
     475              :                 break;
     476       526263 :               if (!op->val[0])
     477       225806 :                 val = fold_unary (op->code, op->type, val);
     478       300457 :               else if (!op->val[1])
     479       600914 :                 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      5654962 :           res = val
     496      5654962 :             ? fold_binary_to_constant (c->code, boolean_type_node, val, c->val)
     497              :             : NULL;
     498              : 
     499      5654477 :           if (res && integer_zerop (res))
     500      2881667 :             continue;
     501      2773295 :           if (res && integer_onep (res))
     502              :             {
     503      2750623 :               clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     504      2750623 :               nonspec_clause
     505      2750623 :                 |= 1 << (i + ipa_predicate::first_dynamic_condition);
     506      2750623 :               continue;
     507              :             }
     508              :         }
     509     15575471 :       if (c->operand_num < (int) avals->m_known_value_ranges.length ()
     510      9103823 :           && !c->agg_contents
     511     17779745 :           && (!val || TREE_CODE (val) != INTEGER_CST))
     512              :         {
     513      2203539 :           value_range vr (avals->m_known_value_ranges[c->operand_num]);
     514      2203539 :           if (!vr.undefined_p ()
     515      1547087 :               && !vr.varying_p ()
     516      3750626 :               && (TYPE_SIZE (c->type) == TYPE_SIZE (vr.type ())))
     517              :             {
     518      1546562 :               if (!useless_type_conversion_p (c->type, vr.type ()))
     519          512 :                 range_cast (vr, c->type);
     520              : 
     521      1981739 :               for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
     522              :                 {
     523       539600 :                   if (vr.varying_p () || vr.undefined_p ())
     524              :                     break;
     525              : 
     526       435177 :                   value_range res (op->type);
     527       435177 :                   if (!op->val[0])
     528              :                     {
     529       155412 :                       value_range varying (op->type);
     530       155412 :                       varying.set_varying (op->type);
     531       155412 :                       range_op_handler handler (op->code);
     532       155412 :                       if (!handler
     533       155412 :                           || !res.supports_type_p (op->type)
     534       310824 :                           || !handler.fold_range (res, op->type, vr, varying))
     535            0 :                         res.set_varying (op->type);
     536       155412 :                     }
     537       279765 :                   else if (!op->val[1])
     538              :                     {
     539       279593 :                       value_range op0 (TREE_TYPE (op->val[0]));
     540       279593 :                       range_op_handler handler (op->code);
     541              : 
     542       279593 :                       ipa_get_range_from_ip_invariant (op0, op->val[0], node);
     543              : 
     544       279593 :                       if (!handler
     545       279593 :                           || !res.supports_type_p (op->type)
     546       559186 :                           || !handler.fold_range (res, op->type,
     547       279593 :                                                   op->index ? op0 : vr,
     548       557418 :                                                   op->index ? vr : op0))
     549            0 :                         res.set_varying (op->type);
     550       279593 :                     }
     551              :                   else
     552          172 :                     res.set_varying (op->type);
     553       435177 :                   vr = res;
     554       435177 :                 }
     555      1546562 :               if (!vr.varying_p () && !vr.undefined_p ())
     556              :                 {
     557      1433122 :                   int_range<2> res;
     558      1433122 :                   value_range val_vr (TREE_TYPE (c->val));
     559      1433122 :                   range_op_handler handler (c->code);
     560              : 
     561      1433122 :                   ipa_get_range_from_ip_invariant (val_vr, c->val, node);
     562              : 
     563      1433122 :                   if (!handler
     564      1433122 :                       || !val_vr.supports_type_p (TREE_TYPE (c->val))
     565      2866244 :                       || !handler.fold_range (res, boolean_type_node, vr, val_vr))
     566            0 :                     res.set_varying (boolean_type_node);
     567              : 
     568      1433122 :                   if (res.zero_p ())
     569       243838 :                     continue;
     570      1433122 :                 }
     571              :             }
     572      2203539 :         }
     573              : 
     574     15331633 :       clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     575     15331633 :       nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     576              :     }
     577     23049327 :   *ret_clause = clause;
     578     23049327 :   if (ret_nonspec_clause)
     579     19954048 :     *ret_nonspec_clause = nonspec_clause;
     580     23049327 : }
     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     12653978 : vrp_will_run_p (struct cgraph_node *node)
     593              : {
     594     12653978 :   return (opt_for_fn (node->decl, optimize)
     595     12653978 :           && !opt_for_fn (node->decl, optimize_debug)
     596     25307188 :           && opt_for_fn (node->decl, flag_tree_vrp));
     597              : }
     598              : 
     599              : /* Similarly about FRE.  */
     600              : 
     601              : static bool
     602     14922564 : fre_will_run_p (struct cgraph_node *node)
     603              : {
     604     14922564 :   return (opt_for_fn (node->decl, optimize)
     605     14922564 :           && !opt_for_fn (node->decl, optimize_debug)
     606     29843486 :           && 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     22803546 : 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     22803546 :   struct cgraph_node *callee = e->callee->ultimate_alias_target ();
     629     22803546 :   class ipa_fn_summary *info = ipa_fn_summaries->get (callee);
     630     22803546 :   class ipa_edge_args *args;
     631     22803546 :   class ipa_call_summary *es = NULL;
     632              : 
     633     22803546 :   if (clause_ptr)
     634     22803546 :     *clause_ptr = inline_p ? 0 : 1 << ipa_predicate::not_inlined_condition;
     635              : 
     636     22803546 :   if (ipa_node_params_sum
     637     10389742 :       && !e->call_stmt_cannot_inline_p
     638     10389742 :       && (info->conds || compute_contexts)
     639     33193288 :       && (args = ipa_edge_args_sum->get (e)) != NULL)
     640              :     {
     641     10335141 :       struct cgraph_node *caller;
     642     10335141 :       class ipa_node_params *caller_parms_info, *callee_pi = NULL;
     643     10335141 :       int i, count = ipa_get_cs_argument_count (args);
     644     10335141 :       es = ipa_call_summaries->get (e);
     645              : 
     646     10335141 :       if (count)
     647              :         {
     648      9621275 :           if (e->caller->inlined_to)
     649              :             caller = e->caller->inlined_to;
     650              :           else
     651      7670457 :             caller = e->caller;
     652      9621275 :           caller_parms_info = ipa_node_params_sum->get (caller);
     653      9621275 :           callee_pi = ipa_node_params_sum->get (callee);
     654              : 
     655              :           /* Watch for thunks.  */
     656      9621275 :           if (callee_pi)
     657              :             /* Watch for variadic functions.  */
     658      9620901 :             count = MIN (count, ipa_get_param_count (callee_pi));
     659              :         }
     660              : 
     661      9620901 :       if (callee_pi)
     662     31475589 :         for (i = 0; i < count; i++)
     663              :           {
     664     21854688 :             struct ipa_jump_func *jf = ipa_get_ith_jump_func (args, i);
     665              : 
     666     21854688 :             if (ipa_is_param_used_by_indirect_call (callee_pi, i)
     667     21854688 :                 || ipa_is_param_used_by_ipa_predicates (callee_pi, i))
     668              :               {
     669              :                 /* Determine if we know constant value of the parameter.  */
     670     14922564 :                 tree type = ipa_get_type (callee_pi, i);
     671     14922564 :                 tree cst = ipa_value_from_jfunc (caller_parms_info, jf, type);
     672              : 
     673     11955963 :                 if (!cst && e->call_stmt
     674     26825802 :                     && i < (int)gimple_call_num_args (e->call_stmt))
     675              :                   {
     676     11903238 :                     cst = gimple_call_arg (e->call_stmt, i);
     677     11903238 :                     if (!is_gimple_min_invariant (cst))
     678              :                       cst = NULL;
     679              :                   }
     680      3217956 :                 if (cst)
     681              :                   {
     682      3165231 :                     gcc_checking_assert (TREE_CODE (cst) != TREE_BINFO);
     683      3165231 :                     if (!avals->m_known_vals.length ())
     684      1828608 :                       avals->m_known_vals.safe_grow_cleared (count, true);
     685      3165231 :                     avals->m_known_vals[i] = cst;
     686              :                   }
     687     11757333 :                 else if (inline_p && !es->param[i].change_prob)
     688              :                   {
     689      4350348 :                     if (!avals->m_known_vals.length ())
     690      3559514 :                       avals->m_known_vals.safe_grow_cleared (count, true);
     691      4350348 :                     avals->m_known_vals[i] = error_mark_node;
     692              :                   }
     693              : 
     694              :                 /* If we failed to get simple constant, try value range.  */
     695      3165231 :                 if ((!cst || TREE_CODE (cst) != INTEGER_CST)
     696     12653978 :                     && vrp_will_run_p (caller)
     697     27410658 :                     && ipa_is_param_used_by_ipa_predicates (callee_pi, i))
     698              :                   {
     699     12447268 :                     value_range vr (type);
     700              : 
     701     12447268 :                     ipa_value_range_from_jfunc (vr, caller_parms_info, e, jf, type);
     702     12447268 :                     if (!vr.undefined_p () && !vr.varying_p ())
     703              :                       {
     704      8859301 :                         if (!avals->m_known_value_ranges.length ())
     705              :                           {
     706      6478789 :                             avals->m_known_value_ranges.safe_grow_cleared (count,
     707              :                                                                            true);
     708     26987043 :                             for (int i = 0; i < count; ++i)
     709     14029465 :                               avals->m_known_value_ranges[i].set_range_class
     710     14029465 :                                 (void_type_node);
     711              :                           }
     712      8859301 :                         avals->m_known_value_ranges[i] = vr;
     713              :                       }
     714     12447268 :                   }
     715              : 
     716              :                 /* Determine known aggregate values.  */
     717     14922564 :                 if (fre_will_run_p (caller))
     718     14920518 :                   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     21854688 :             if (compute_contexts
     726     21854688 :                 && ipa_is_param_used_by_polymorphic_call (callee_pi, i))
     727              :               {
     728       176239 :                 ipa_polymorphic_call_context
     729       176239 :                    ctx = ipa_context_from_jfunc (caller_parms_info, e, i, jf);
     730       352478 :                 if (!ctx.useless_p ())
     731              :                   {
     732       174271 :                     if (!avals->m_known_contexts.length ())
     733       174134 :                       avals->m_known_contexts.safe_grow_cleared (count, true);
     734       174271 :                     avals->m_known_contexts[i]
     735       348542 :                       = ipa_context_from_jfunc (caller_parms_info, e, i, jf);
     736              :                   }
     737              :                }
     738              :           }
     739              :         else
     740       714240 :           gcc_assert (!count || callee->thunk);
     741              :     }
     742     12468405 :   else if (e->call_stmt && !e->call_stmt_cannot_inline_p && info->conds)
     743              :     {
     744      9806831 :       int i, count = (int)gimple_call_num_args (e->call_stmt);
     745              : 
     746     27882922 :       for (i = 0; i < count; i++)
     747              :         {
     748     18076091 :           tree cst = gimple_call_arg (e->call_stmt, i);
     749     18076091 :           if (!is_gimple_min_invariant (cst))
     750              :             cst = NULL;
     751      6427505 :           if (cst)
     752              :             {
     753      6427505 :               if (!avals->m_known_vals.length ())
     754      4459968 :                 avals->m_known_vals.safe_grow_cleared (count, true);
     755      6427505 :               avals->m_known_vals[i] = cst;
     756              :             }
     757              :         }
     758              :     }
     759              : 
     760     22803546 :   evaluate_conditions_for_known_args (callee, inline_p, avals, clause_ptr,
     761              :                                       nonspec_clause_ptr, es);
     762     22803546 : }
     763              : 
     764              : 
     765              : /* Allocate the function summary. */
     766              : 
     767              : static void
     768       468121 : ipa_fn_summary_alloc (void)
     769              : {
     770       468121 :   gcc_checking_assert (!ipa_fn_summaries);
     771       468121 :   ipa_size_summaries = new ipa_size_summary_t (symtab);
     772       468121 :   ipa_fn_summaries = ipa_fn_summary_t::create_ggc (symtab);
     773       468121 :   ipa_call_summaries = new ipa_call_summary_t (symtab);
     774       468121 : }
     775              : 
     776     28053247 : ipa_call_summary::~ipa_call_summary ()
     777              : {
     778     28053247 :   if (predicate)
     779      3383168 :     edge_predicate_pool.remove (predicate);
     780              : 
     781     28053247 :   param.release ();
     782     28053247 : }
     783              : 
     784     10404745 : ipa_fn_summary::~ipa_fn_summary ()
     785              : {
     786     10404745 :   unsigned len = vec_safe_length (loop_iterations);
     787     10518652 :   for (unsigned i = 0; i < len; i++)
     788       113907 :     edge_predicate_pool.remove ((*loop_iterations)[i].predicate);
     789     10404745 :   len = vec_safe_length (loop_strides);
     790     10440440 :   for (unsigned i = 0; i < len; i++)
     791        35695 :     edge_predicate_pool.remove ((*loop_strides)[i].predicate);
     792     10404745 :   vec_free (conds);
     793     10404745 :   call_size_time_table.release ();
     794     10404745 :   vec_free (loop_iterations);
     795     10404745 :   vec_free (loop_strides);
     796     10404745 :   builtin_constant_p_parms.release ();
     797     10404745 : }
     798              : 
     799              : void
     800      7484735 : ipa_fn_summary_t::remove_callees (cgraph_node *node)
     801              : {
     802      7484735 :   cgraph_edge *e;
     803     30526095 :   for (e = node->callees; e; e = e->next_callee)
     804     23041360 :     ipa_call_summaries->remove (e);
     805      7967367 :   for (e = node->indirect_calls; e; e = e->next_callee)
     806       482632 :     ipa_call_summaries->remove (e);
     807      7484735 : }
     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        28516 : remap_freqcounting_preds_after_dup (vec<ipa_freqcounting_predicate, va_gc> *v,
     815              :                                     clause_t possible_truths)
     816              : {
     817        28516 :   if (vec_safe_length (v) == 0)
     818              :     return NULL;
     819              : 
     820         4691 :   vec<ipa_freqcounting_predicate, va_gc> *res = v->copy ();
     821         4691 :   int len = res->length();
     822        10871 :   for (int i = len - 1; i >= 0; i--)
     823              :     {
     824         6180 :       ipa_predicate new_predicate
     825         6180 :         = (*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         6180 :       (*res)[i].predicate = NULL;
     829         6180 :       set_hint_predicate (&(*res)[i].predicate, new_predicate);
     830              : 
     831         6180 :       if (!(*res)[i].predicate)
     832         2947 :         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      2831813 : 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      2831813 :   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      2831813 :   info->conds = vec_safe_copy (info->conds);
     850              : 
     851      2831813 :   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      2831813 :   if (ipa_node_params_sum && cinfo && cinfo->tree_map)
     855              :     {
     856              :       /* Use SRC parm info since it may not be copied yet.  */
     857        14258 :       ipa_node_params *parms_info = ipa_node_params_sum->get (src);
     858        14258 :       ipa_auto_call_arg_values avals;
     859        14258 :       int count = ipa_get_param_count (parms_info);
     860        14258 :       int i, j;
     861        14258 :       clause_t possible_truths;
     862        14258 :       ipa_predicate true_pred = true;
     863        14258 :       size_time_entry *e;
     864        14258 :       int optimized_out_size = 0;
     865        14258 :       bool inlined_to_p = false;
     866        14258 :       struct cgraph_edge *edge, *next;
     867              : 
     868        14258 :       info->size_time_table.release ();
     869        14258 :       avals.m_known_vals.safe_grow_cleared (count, true);
     870        71587 :       for (i = 0; i < count; i++)
     871              :         {
     872              :           struct ipa_replace_map *r;
     873              : 
     874       140691 :           for (j = 0; vec_safe_iterate (cinfo->tree_map, j, &r); j++)
     875              :             {
     876        79172 :               if (r->parm_num == i)
     877              :                 {
     878        24623 :                   avals.m_known_vals[i] = r->new_tree;
     879        24623 :                   break;
     880              :                 }
     881              :             }
     882              :         }
     883        14258 :       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        14258 :       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        99323 :       for (i = 0; src_info->size_time_table.iterate (i, &e); i++)
     899              :         {
     900        85065 :           ipa_predicate new_exec_pred;
     901        85065 :           ipa_predicate new_nonconst_pred;
     902        85065 :           new_exec_pred = e->exec_predicate.remap_after_duplication
     903        85065 :                                  (possible_truths);
     904        85065 :           new_nonconst_pred = e->nonconst_predicate.remap_after_duplication
     905        85065 :                                  (possible_truths);
     906        85065 :           if (new_exec_pred == false || new_nonconst_pred == false)
     907        11811 :             optimized_out_size += e->size;
     908              :           else
     909        73254 :             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       183745 :       for (edge = dst->callees; edge; edge = next)
     916              :         {
     917       169487 :           ipa_predicate new_predicate;
     918       169487 :           class ipa_call_summary *es = ipa_call_summaries->get (edge);
     919       169487 :           next = edge->next_callee;
     920              : 
     921       169487 :           if (!edge->inline_failed)
     922            0 :             inlined_to_p = true;
     923       169487 :           if (!es->predicate)
     924       156993 :             continue;
     925        12494 :           new_predicate = es->predicate->remap_after_duplication
     926        12494 :             (possible_truths);
     927        12494 :           if (new_predicate == false && *es->predicate != false)
     928         3203 :             optimized_out_size += es->call_stmt_size * ipa_fn_summary::size_scale;
     929        12494 :           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        15154 :       for (edge = dst->indirect_calls; edge; edge = next)
     935              :         {
     936          896 :           ipa_predicate new_predicate;
     937          896 :           class ipa_call_summary *es = ipa_call_summaries->get (edge);
     938          896 :           next = edge->next_callee;
     939              : 
     940          896 :           gcc_checking_assert (edge->inline_failed);
     941          896 :           if (!es->predicate)
     942          792 :             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        14258 :       info->loop_iterations
     951        14258 :         = remap_freqcounting_preds_after_dup (info->loop_iterations,
     952              :                                               possible_truths);
     953        14258 :       info->loop_strides
     954        14258 :         = remap_freqcounting_preds_after_dup (info->loop_strides,
     955              :                                               possible_truths);
     956        14258 :       if (info->builtin_constant_p_parms.length())
     957              :         {
     958           22 :           vec <int, va_heap, vl_ptr> parms = info->builtin_constant_p_parms;
     959           22 :           int ip;
     960           22 :           info->builtin_constant_p_parms = vNULL;
     961           44 :           for (i = 0; parms.iterate (i, &ip); i++)
     962           22 :             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        14258 :       gcc_assert (!inlined_to_p || !optimized_out_size);
     971        14258 :     }
     972              :   else
     973              :     {
     974      2817555 :       info->size_time_table = src_info->size_time_table.copy ();
     975      2817555 :       info->loop_iterations = vec_safe_copy (src_info->loop_iterations);
     976      2817555 :       info->loop_strides = vec_safe_copy (info->loop_strides);
     977              : 
     978      2817555 :       info->builtin_constant_p_parms
     979      2817555 :              = info->builtin_constant_p_parms.copy ();
     980              : 
     981      2817555 :       ipa_freqcounting_predicate *f;
     982      5684506 :       for (int i = 0; vec_safe_iterate (info->loop_iterations, i, &f); i++)
     983              :         {
     984        49396 :           ipa_predicate p = *f->predicate;
     985        49396 :           f->predicate = NULL;
     986        49396 :           set_hint_predicate (&f->predicate, p);
     987              :         }
     988      2841807 :       for (int i = 0; vec_safe_iterate (info->loop_strides, i, &f); i++)
     989              :         {
     990        24252 :           ipa_predicate p = *f->predicate;
     991        24252 :           f->predicate = NULL;
     992        24252 :           set_hint_predicate (&f->predicate, p);
     993              :         }
     994              :     }
     995      2831813 :   if (!dst->inlined_to)
     996       148343 :     ipa_update_overall_fn_summary (dst);
     997      2831813 : }
     998              : 
     999              : 
    1000              : /* Hook that is called by cgraph.cc when a node is duplicated.  */
    1001              : 
    1002              : void
    1003      4180429 : 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      4180429 :   new (info) ipa_call_summary (*srcinfo);
    1009      4180429 :   info->predicate = NULL;
    1010      4180429 :   edge_set_predicate (dst, srcinfo->predicate);
    1011      4180429 :   info->param = srcinfo->param.copy ();
    1012      4180429 :   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        24001 :       && !src->has_callback && !dst->callback)
    1016              :     {
    1017        24001 :       info->call_stmt_size -= (eni_size_weights.indirect_call_cost
    1018        24001 :                                - eni_size_weights.call_cost);
    1019        24001 :       info->call_stmt_time -= (eni_time_weights.indirect_call_cost
    1020        24001 :                                - eni_time_weights.call_cost);
    1021              :     }
    1022      4180429 : }
    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       844858 : mark_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef ATTRIBUTE_UNUSED,
    1222              :                void *data)
    1223              : {
    1224       844858 :   bool *b = (bool *) data;
    1225       844858 :   *b = true;
    1226       844858 :   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    189618436 : 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    189618436 :   if (TREE_CODE (op) == SSA_NAME
    1239    111309302 :       && SSA_NAME_IS_DEFAULT_DEF (op)
    1240    215955675 :       && TREE_CODE (SSA_NAME_VAR (op)) == PARM_DECL)
    1241              :     {
    1242     26123753 :       if (size_p)
    1243            0 :         *size_p = tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op)));
    1244     26123753 :       return SSA_NAME_VAR (op);
    1245              :     }
    1246              :   /* Non-SSA parm reference?  */
    1247    163494683 :   if (TREE_CODE (op) == PARM_DECL
    1248      1427599 :       && fbi->aa_walk_budget > 0)
    1249              :     {
    1250      1425053 :       bool modified = false;
    1251              : 
    1252      1425053 :       ao_ref refd;
    1253      1425053 :       ao_ref_init (&refd, op);
    1254      2850106 :       int walked = walk_aliased_vdefs (&refd, gimple_vuse (stmt),
    1255              :                                        mark_modified, &modified, NULL, NULL,
    1256              :                                        fbi->aa_walk_budget);
    1257      1425053 :       if (walked < 0)
    1258              :         {
    1259            8 :           fbi->aa_walk_budget = 0;
    1260       913969 :           return NULL_TREE;
    1261              :         }
    1262      1425045 :       fbi->aa_walk_budget -= walked;
    1263      1425045 :       if (!modified)
    1264              :         {
    1265       913961 :           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    124018633 : unmodified_parm (ipa_func_body_info *fbi, gimple *stmt, tree op,
    1280              :                  poly_int64 *size_p)
    1281              : {
    1282    154167187 :   tree res = unmodified_parm_1 (fbi, stmt, op, size_p);
    1283    154167187 :   if (res)
    1284              :     return res;
    1285              : 
    1286    127987354 :   if (TREE_CODE (op) == SSA_NAME
    1287     72798890 :       && !SSA_NAME_IS_DEFAULT_DEF (op)
    1288    200577502 :       && gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
    1289     30148554 :     return unmodified_parm (fbi, SSA_NAME_DEF_STMT (op),
    1290     30148554 :                             gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op)),
    1291     30148554 :                             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     33993513 : 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     35451249 :   tree res = unmodified_parm_1 (fbi, stmt, op, size_p);
    1309              : 
    1310     35451249 :   gcc_checking_assert (aggpos);
    1311     35451249 :   if (res)
    1312              :     {
    1313       857881 :       *index_p = ipa_get_param_decl_index (fbi->info, res);
    1314       857881 :       if (*index_p < 0)
    1315              :         return false;
    1316       857751 :       aggpos->agg_contents = false;
    1317       857751 :       aggpos->by_ref = false;
    1318       857751 :       return true;
    1319              :     }
    1320              : 
    1321     34593368 :   if (TREE_CODE (op) == SSA_NAME)
    1322              :     {
    1323     12386659 :       if (SSA_NAME_IS_DEFAULT_DEF (op)
    1324     12386659 :           || !gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
    1325              :         return false;
    1326      4947854 :       stmt = SSA_NAME_DEF_STMT (op);
    1327      4947854 :       op = gimple_assign_rhs1 (stmt);
    1328      4947854 :       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     25696827 :   aggpos->agg_contents = true;
    1334     25696827 :   return ipa_load_from_parm_agg (fbi, fbi->info->descriptors,
    1335              :                                  stmt, op, index_p, &aggpos->offset,
    1336     25696827 :                                  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    114053989 : load_or_store_of_ptr_parameter (ipa_func_body_info *fbi, gimple *stmt)
    1344              : {
    1345    114053989 :   if (!optimize)
    1346              :     return -1;
    1347     95686820 :   gassign *assign = dyn_cast <gassign *> (stmt);
    1348     56859745 :   if (!assign)
    1349              :     return -1;
    1350     56859745 :   tree param;
    1351     56859745 :   if (gimple_assign_load_p (stmt))
    1352     20837925 :     param = gimple_assign_rhs1 (stmt);
    1353     36021820 :   else if (gimple_store_p (stmt))
    1354     19106871 :     param = gimple_assign_lhs (stmt);
    1355              :   else
    1356              :     return -1;
    1357     39944796 :   tree base = get_base_address (param);
    1358     39944796 :   if (TREE_CODE (base) != MEM_REF
    1359     13922870 :       || TREE_CODE (TREE_OPERAND (base, 0)) != SSA_NAME
    1360     53863544 :       || !SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (base, 0)))
    1361              :     return -1;
    1362      7540637 :   tree p = SSA_NAME_VAR (TREE_OPERAND (base, 0));
    1363      7540637 :   if (TREE_CODE (p) != PARM_DECL)
    1364              :     return -1;
    1365      7448986 :   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    114053989 : eliminated_by_inlining_prob (ipa_func_body_info *fbi, gimple *stmt)
    1377              : {
    1378    114053989 :   enum gimple_code code = gimple_code (stmt);
    1379    114053989 :   enum tree_code rhs_code;
    1380              : 
    1381    114053989 :   if (!optimize)
    1382              :     return 0;
    1383              : 
    1384     95686820 :   switch (code)
    1385              :     {
    1386              :     case GIMPLE_RETURN:
    1387              :       return 2;
    1388     56859745 :     case GIMPLE_ASSIGN:
    1389     56859745 :       if (gimple_num_ops (stmt) != 2)
    1390              :         return 0;
    1391              : 
    1392     40769167 :       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     40769167 :       if (CONVERT_EXPR_CODE_P (rhs_code)
    1399              :           || rhs_code == VIEW_CONVERT_EXPR
    1400              :           || rhs_code == ADDR_EXPR
    1401     37898611 :           || gimple_assign_rhs_class (stmt) == GIMPLE_SINGLE_RHS)
    1402              :         {
    1403     39944796 :           tree rhs = gimple_assign_rhs1 (stmt);
    1404     39944796 :           tree lhs = gimple_assign_lhs (stmt);
    1405     39944796 :           tree inner_rhs = get_base_address (rhs);
    1406     39944796 :           tree inner_lhs = get_base_address (lhs);
    1407     39944796 :           bool rhs_free = false;
    1408     39944796 :           bool lhs_free = false;
    1409              : 
    1410     39944796 :           if (!inner_rhs)
    1411            0 :             inner_rhs = rhs;
    1412     39944796 :           if (!inner_lhs)
    1413            0 :             inner_lhs = lhs;
    1414              : 
    1415              :           /* Reads of parameter are expected to be free.  */
    1416     39944796 :           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     38625900 :           else if (TREE_CODE (inner_rhs) == ADDR_EXPR)
    1421              :             {
    1422      2582136 :               tree op = get_base_address (TREE_OPERAND (inner_rhs, 0));
    1423      2582136 :               if (TREE_CODE (op) == PARM_DECL)
    1424              :                 rhs_free = true;
    1425      2537863 :               else if (TREE_CODE (op) == MEM_REF
    1426      2537863 :                        && 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      1363169 :           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     39259861 :           if (TREE_CODE (inner_rhs) == MEM_REF
    1440     39259861 :               && 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     39259861 :           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     39259861 :           if (TREE_CODE (inner_lhs) == PARM_DECL
    1479     39169996 :               || TREE_CODE (inner_lhs) == RESULT_DECL
    1480     77581925 :               || (TREE_CODE (inner_lhs) == MEM_REF
    1481      5206641 :                   && (unmodified_parm (fbi, stmt, TREE_OPERAND (inner_lhs, 0),
    1482              :                                        NULL)
    1483      2680105 :                       || (TREE_CODE (TREE_OPERAND (inner_lhs, 0)) == SSA_NAME
    1484      2678917 :                           && SSA_NAME_VAR (TREE_OPERAND (inner_lhs, 0))
    1485       379099 :                           && TREE_CODE (SSA_NAME_VAR (TREE_OPERAND
    1486              :                                                       (inner_lhs,
    1487              :                                                        0))) == RESULT_DECL))))
    1488              :             lhs_free = true;
    1489     35704072 :           if (lhs_free
    1490     39259861 :               && (is_gimple_reg (rhs) || is_gimple_min_invariant (rhs)))
    1491              :             rhs_free = true;
    1492     39259861 :           if (lhs_free && rhs_free)
    1493      8226738 :             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     27877261 : 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     27877261 :   int op_limit = opt_for_fn (fbi->node->decl, param_ipa_max_param_expr_ops);
    1516     27877261 :   int op_count = 0;
    1517              : 
    1518     27877261 :   if (param_ops_p)
    1519      9579862 :     *param_ops_p = NULL;
    1520              : 
    1521     33993513 :   while (true)
    1522              :     {
    1523     33993513 :       expr_eval_op eval_op;
    1524     33993513 :       unsigned rhs_count;
    1525     33993513 :       unsigned cst_count = 0;
    1526              : 
    1527     33993513 :       if (unmodified_parm_or_parm_agg_item (fbi, stmt, expr, index_p, NULL,
    1528              :                                             aggpos))
    1529              :         {
    1530      4761403 :           tree type = TREE_TYPE (expr);
    1531              : 
    1532      4761403 :           if (aggpos->agg_contents)
    1533              :             {
    1534              :               /* Stop if containing bit-field.  */
    1535      3903652 :               if (TREE_CODE (expr) == BIT_FIELD_REF
    1536      3903652 :                   || contains_bitfld_component_ref_p (expr))
    1537              :                 break;
    1538              :             }
    1539              : 
    1540      4734174 :           *type_p = type;
    1541      4734174 :           return true;
    1542              :         }
    1543              : 
    1544     29232110 :       if (TREE_CODE (expr) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (expr))
    1545              :         break;
    1546     11029321 :       stmt = SSA_NAME_DEF_STMT (expr);
    1547              : 
    1548     11029321 :       if (gcall *call = dyn_cast <gcall *> (stmt))
    1549              :         {
    1550      2596437 :           int flags = gimple_call_return_flags (call);
    1551      2596437 :           if (!(flags & ERF_RETURNS_ARG))
    1552      3192244 :             goto fail;
    1553       235366 :           int arg = flags & ERF_RETURN_ARG_MASK;
    1554       235366 :           if (arg >= (int)gimple_call_num_args (call))
    1555            0 :             goto fail;
    1556       235366 :           expr = gimple_call_arg (stmt, arg);
    1557      4174812 :           continue;
    1558       235366 :         }
    1559              : 
    1560      8432884 :       if (!is_gimple_assign (stmt = SSA_NAME_DEF_STMT (expr)))
    1561              :         break;
    1562              : 
    1563      6712146 :       switch (gimple_assign_rhs_class (stmt))
    1564              :         {
    1565      3939446 :         case GIMPLE_SINGLE_RHS:
    1566      3939446 :           expr = gimple_assign_rhs1 (stmt);
    1567      3939446 :           continue;
    1568              : 
    1569              :         case GIMPLE_UNARY_RHS:
    1570              :           rhs_count = 1;
    1571              :           break;
    1572              : 
    1573      1685097 :         case GIMPLE_BINARY_RHS:
    1574      1685097 :           rhs_count = 2;
    1575      1685097 :           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      2772700 :       if (op_count++ == op_limit)
    1587              :         break;
    1588              : 
    1589      2772613 :       if (param_ops_p)
    1590              :         {
    1591      2738316 :           eval_op.code = gimple_assign_rhs_code (stmt);
    1592      2738316 :           eval_op.type = TREE_TYPE (gimple_assign_lhs (stmt));
    1593      2738316 :           eval_op.val[0] = NULL_TREE;
    1594      2738316 :           eval_op.val[1] = NULL_TREE;
    1595              :         }
    1596              : 
    1597      2772613 :       expr = NULL_TREE;
    1598      6399852 :       for (unsigned i = 0; i < rhs_count; i++)
    1599              :         {
    1600      4458412 :           tree op = gimple_op (stmt, i + 1);
    1601              : 
    1602      4458412 :           gcc_assert (op && !TYPE_P (op));
    1603      4458412 :           if (is_gimple_ip_invariant (op))
    1604              :             {
    1605       856944 :               if (++cst_count == rhs_count)
    1606         1159 :                 goto fail;
    1607              : 
    1608       855785 :               eval_op.val[cst_count - 1] = op;
    1609              :             }
    1610      3601468 :           else if (!expr)
    1611              :             {
    1612              :               /* Found a non-constant operand, and record its index in rhs
    1613              :                  operands.  */
    1614      2771454 :               eval_op.index = i;
    1615      2771454 :               expr = op;
    1616              :             }
    1617              :           else
    1618              :             {
    1619              :               /* Found more than one non-constant operands.  */
    1620       830014 :               goto fail;
    1621              :             }
    1622              :         }
    1623              : 
    1624      1941440 :       if (param_ops_p)
    1625      1907763 :         vec_safe_insert (*param_ops_p, 0, eval_op);
    1626              :     }
    1627              : 
    1628              :   /* Failed to decompose, free resource and return.  */
    1629     23143087 : fail:
    1630     23143087 :   if (param_ops_p)
    1631      9382602 :     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        12009 : add_builtin_constant_p_parm (class ipa_fn_summary *summary, int parm)
    1640              : {
    1641        12009 :   int ip;
    1642              : 
    1643              :   /* Avoid duplicates.  */
    1644        12067 :   for (unsigned int i = 0;
    1645        12067 :        summary->builtin_constant_p_parms.iterate (i, &ip); i++)
    1646         5955 :     if (ip == parm)
    1647        12009 :       return;
    1648         6112 :   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     36025489 : 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     36025489 :   tree op, op2;
    1661     36025489 :   int index;
    1662     36025489 :   struct agg_position_info aggpos;
    1663     36025489 :   enum tree_code code, inverted_code;
    1664     36025489 :   edge e;
    1665     36025489 :   edge_iterator ei;
    1666     36025489 :   gimple *set_stmt;
    1667     36025489 :   tree param_type;
    1668     36025489 :   expr_eval_ops param_ops;
    1669              : 
    1670     72050978 :   gcond *last = safe_dyn_cast <gcond *> (*gsi_last_bb (bb));
    1671     11953107 :   if (!last)
    1672     36012469 :     return;
    1673     11953107 :   if (!is_gimple_ip_invariant (gimple_cond_rhs (last)))
    1674              :     return;
    1675      9497976 :   op = gimple_cond_lhs (last);
    1676              : 
    1677      9497976 :   if (decompose_param_expr (fbi, last, op, &index, &param_type, &aggpos,
    1678              :                             &param_ops))
    1679              :     {
    1680      1368747 :       code = gimple_cond_code (last);
    1681      1368747 :       inverted_code = invert_tree_comparison (code, HONOR_NANS (op));
    1682              : 
    1683      4106241 :       FOR_EACH_EDGE (e, ei, bb->succs)
    1684              :         {
    1685      1368747 :           enum tree_code this_code = (e->flags & EDGE_TRUE_VALUE
    1686      2737494 :                                       ? 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      2737494 :           if (this_code != ERROR_MARK
    1696      2737494 :               && !dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    1697              :             {
    1698      2329130 :               ipa_predicate p
    1699      2329130 :                 = add_condition (summary, params_summary, index,
    1700              :                                  param_type, &aggpos,
    1701              :                                  this_code, gimple_cond_rhs (last), param_ops);
    1702      2329130 :               e->aux = edge_predicate_pool.allocate ();
    1703      2329130 :               *(ipa_predicate *) e->aux = p;
    1704              :             }
    1705              :         }
    1706     36244071 :       vec_free (param_ops);
    1707              :       return;
    1708              :     }
    1709              : 
    1710      8129229 :   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      8128144 :   if (gimple_cond_code (last) != NE_EXPR
    1723      8128144 :       || !integer_zerop (gimple_cond_rhs (last)))
    1724              :     return;
    1725      3578163 :   set_stmt = SSA_NAME_DEF_STMT (op);
    1726      3578163 :   if (!gimple_call_builtin_p (set_stmt, BUILT_IN_CONSTANT_P)
    1727      3578163 :       || gimple_call_num_args (set_stmt) != 1)
    1728              :     return;
    1729        46400 :   op2 = gimple_call_arg (set_stmt, 0);
    1730        46400 :   if (!decompose_param_expr (fbi, set_stmt, op2, &index, &param_type, &aggpos))
    1731              :     return;
    1732        13020 :   if (!aggpos.by_ref)
    1733        11961 :     add_builtin_constant_p_parm (summary, index);
    1734        39060 :   FOR_EACH_EDGE (e, ei, bb->succs) if (e->flags & EDGE_FALSE_VALUE)
    1735              :     {
    1736        13020 :       ipa_predicate p = add_condition (summary, params_summary, index,
    1737              :                                    param_type, &aggpos,
    1738              :                                    ipa_predicate::is_not_constant, NULL_TREE);
    1739        13020 :       e->aux = edge_predicate_pool.allocate ();
    1740        13020 :       *(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     36025489 : 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     36025489 :   tree op;
    1755     36025489 :   int index;
    1756     36025489 :   struct agg_position_info aggpos;
    1757     36025489 :   edge e;
    1758     36025489 :   edge_iterator ei;
    1759     36025489 :   size_t n;
    1760     36025489 :   size_t case_idx;
    1761     36025489 :   tree param_type;
    1762     36025489 :   expr_eval_ops param_ops;
    1763              : 
    1764     72050978 :   gswitch *last = safe_dyn_cast <gswitch *> (*gsi_last_bb (bb));
    1765        81886 :   if (!last)
    1766     35995966 :     return;
    1767        81886 :   op = gimple_switch_index (last);
    1768        81886 :   if (!decompose_param_expr (fbi, last, op, &index, &param_type, &aggpos,
    1769              :                              &param_ops))
    1770              :     return;
    1771              : 
    1772        44635 :   auto_vec<std::pair<tree, tree> > ranges;
    1773        44635 :   tree type = TREE_TYPE (op);
    1774        44635 :   int bound_limit = opt_for_fn (fbi->node->decl,
    1775              :                                 param_ipa_max_switch_predicate_bounds);
    1776        44635 :   int bound_count = 0;
    1777              :   // This can safely be an integer range, as switches can only hold
    1778              :   // integers.
    1779        44635 :   int_range<2> vr;
    1780              : 
    1781        89270 :   get_range_query (cfun)->range_of_expr (vr, op);
    1782        44635 :   if (vr.undefined_p ())
    1783            0 :     vr.set_varying (TREE_TYPE (op));
    1784        44635 :   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        44635 :   value_range_kind vr_type = get_legacy_range (vr, vr_min, vr_max);
    1789        44635 :   wide_int vr_wmin = wi::to_wide (vr_min);
    1790        44635 :   wide_int vr_wmax = wi::to_wide (vr_max);
    1791              : 
    1792       308831 :   FOR_EACH_EDGE (e, ei, bb->succs)
    1793              :     {
    1794       264196 :       e->aux = edge_predicate_pool.allocate ();
    1795       264196 :       *(ipa_predicate *) e->aux = false;
    1796              :     }
    1797              : 
    1798        44635 :   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        44635 :   if (dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    1804        12603 :     bound_count = INT_MAX;
    1805              : 
    1806        44635 :   n = gimple_switch_num_labels (last);
    1807       295307 :   for (case_idx = 1; case_idx < n; ++case_idx)
    1808              :     {
    1809       250672 :       tree cl = gimple_switch_label (last, case_idx);
    1810       250672 :       tree min = CASE_LOW (cl);
    1811       250672 :       tree max = CASE_HIGH (cl);
    1812       250672 :       ipa_predicate p;
    1813              : 
    1814       250672 :       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       250672 :       if (TREE_TYPE (min) != type)
    1819        44908 :         min = wide_int_to_tree (type, wi::to_wide (min));
    1820              : 
    1821       250672 :       if (!max)
    1822              :         max = min;
    1823        12477 :       else if (TREE_TYPE (max) != type)
    1824         3427 :         max = wide_int_to_tree (type, wi::to_wide (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       250672 :       if (dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    1830         5189 :         p = true;
    1831       245483 :       else if (min == max)
    1832       234922 :         p = add_condition (summary, params_summary, index, param_type,
    1833              :                            &aggpos, EQ_EXPR, min, param_ops);
    1834              :       else
    1835              :         {
    1836        10561 :           ipa_predicate p1, p2;
    1837        10561 :           p1 = add_condition (summary, params_summary, index, param_type,
    1838              :                               &aggpos, GE_EXPR, min, param_ops);
    1839        10561 :           p2 = add_condition (summary,  params_summary,index, param_type,
    1840              :                               &aggpos, LE_EXPR, max, param_ops);
    1841        10561 :           p = p1 & p2;
    1842              :         }
    1843       250672 :       *(ipa_predicate *) e->aux
    1844       250672 :         = 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       250672 :       if (bound_count > bound_limit)
    1849        97925 :         continue;
    1850              : 
    1851       152747 :       bool new_range = true;
    1852              : 
    1853       152747 :       if (!ranges.is_empty ())
    1854              :         {
    1855       120715 :           wide_int curr_wmin = wi::to_wide (min);
    1856       120715 :           wide_int last_wmax = wi::to_wide (ranges.last ().second);
    1857              : 
    1858              :           /* Merge case ranges if they are continuous.  */
    1859       120715 :           if (curr_wmin == last_wmax + 1)
    1860              :             new_range = false;
    1861        41874 :           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       120715 :         }
    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       120715 :       if (new_range)
    1876              :         {
    1877        73906 :           bound_count += (min == max) ? 1 : 2;
    1878        73906 :           ranges.safe_push (std::make_pair (min, max));
    1879              :         }
    1880              :       else
    1881              :         {
    1882        78841 :           bound_count += (ranges.last ().first == ranges.last ().second);
    1883        78841 :           ranges.last ().second = max;
    1884              :         }
    1885              :     }
    1886              : 
    1887        44635 :   e = gimple_switch_edge (cfun, last, 0);
    1888        44635 :   if (bound_count > bound_limit)
    1889              :     {
    1890        15112 :       *(ipa_predicate *) e->aux = true;
    1891        15112 :       vec_free (param_ops);
    1892        15112 :       return;
    1893              :     }
    1894              : 
    1895        29523 :   ipa_predicate p_seg = true;
    1896        29523 :   ipa_predicate p_all = false;
    1897              : 
    1898        29523 :   if (vr_type != VR_RANGE)
    1899              :     {
    1900        28923 :       vr_wmin = wi::to_wide (TYPE_MIN_VALUE (type));
    1901        28923 :       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        90996 :   for (size_t i = 0; i < ranges.length (); i++)
    1916              :     {
    1917        61568 :       tree min = ranges[i].first;
    1918        61568 :       tree max = ranges[i].second;
    1919              : 
    1920        61568 :       if (min == max)
    1921        73378 :         p_seg &= add_condition (summary, params_summary, index,
    1922              :                                 param_type, &aggpos, NE_EXPR,
    1923        36689 :                                 min, param_ops);
    1924              :       else
    1925              :         {
    1926              :           /* Do not create sub-predicate for range that is beyond low bound
    1927              :              of switch index.  */
    1928        24879 :           if (wi::lt_p (vr_wmin, wi::to_wide (min), TYPE_SIGN (type)))
    1929              :             {
    1930        17797 :               p_seg &= add_condition (summary, params_summary, index,
    1931              :                                       param_type, &aggpos,
    1932        17797 :                                       LT_EXPR, min, param_ops);
    1933        17797 :               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        24879 :           if (wi::le_p (vr_wmax, wi::to_wide (max), TYPE_SIGN (type)))
    1939              :             {
    1940           95 :               p_seg = false;
    1941           95 :               break;
    1942              :             }
    1943              : 
    1944        24784 :           p_seg = add_condition (summary, params_summary, index,
    1945              :                                  param_type, &aggpos, GT_EXPR,
    1946              :                                  max, param_ops);
    1947              :         }
    1948              :     }
    1949              : 
    1950        29523 :   p_all = p_all.or_with (summary->conds, p_seg);
    1951        29523 :   *(ipa_predicate *) e->aux
    1952        29523 :     = p_all.or_with (summary->conds, *(ipa_predicate *) e->aux);
    1953              : 
    1954        36100 :   vec_free (param_ops);
    1955        44635 : }
    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      6560932 : 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      6560932 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    1968      6560932 :   bool done = false;
    1969      6560932 :   basic_block bb;
    1970              : 
    1971     42586421 :   FOR_EACH_BB_FN (bb, my_function)
    1972              :     {
    1973     36025489 :       set_cond_stmt_execution_predicate (fbi, summary, params_summary, bb);
    1974     36025489 :       set_switch_stmt_execution_predicate (fbi, summary, params_summary, bb);
    1975              :     }
    1976              : 
    1977              :   /* Entry block is always executable.  */
    1978      6560932 :   ENTRY_BLOCK_PTR_FOR_FN (my_function)->aux
    1979      6560932 :     = edge_predicate_pool.allocate ();
    1980      6560932 :   *(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     19802445 :   while (!done)
    1985              :     {
    1986     13241513 :       done = true;
    1987     90387516 :       FOR_EACH_BB_FN (bb, my_function)
    1988              :         {
    1989     77146003 :           ipa_predicate p = false;
    1990     77146003 :           edge e;
    1991     77146003 :           edge_iterator ei;
    1992     95534551 :           FOR_EACH_EDGE (e, ei, bb->preds)
    1993              :             {
    1994     81990353 :               if (e->src->aux)
    1995              :                 {
    1996     80257628 :                   ipa_predicate this_bb_predicate
    1997              :                     = *(ipa_predicate *) e->src->aux;
    1998     80257628 :                   if (e->aux)
    1999      5416356 :                     this_bb_predicate &= (*(ipa_predicate *) e->aux);
    2000     80257628 :                   p = p.or_with (summary->conds, this_bb_predicate);
    2001     80257628 :                   if (p == true)
    2002              :                     break;
    2003              :                 }
    2004              :             }
    2005     77146003 :           if (p != false)
    2006              :             {
    2007     76018979 :               basic_block pdom_bb;
    2008              : 
    2009     76018979 :               if (!bb->aux)
    2010              :                 {
    2011     28316355 :                   done = false;
    2012     28316355 :                   bb->aux = edge_predicate_pool.allocate ();
    2013     28316355 :                   *((ipa_predicate *) bb->aux) = p;
    2014              :                 }
    2015     47702624 :               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       128793 :                   p = p.or_with (summary->conds, *(ipa_predicate *)bb->aux);
    2021       128793 :                   if (p != *(ipa_predicate *)bb->aux)
    2022              :                     {
    2023       104192 :                       done = false;
    2024       104192 :                       *((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     76018979 :               pdom_bb = get_immediate_dominator (CDI_POST_DOMINATORS, bb);
    2038     76018979 :               if (pdom_bb == EXIT_BLOCK_PTR_FOR_FN (my_function) || !pdom_bb)
    2039              :                 ;
    2040     38817682 :               else if (!pdom_bb->aux)
    2041              :                 {
    2042      7709120 :                   done = false;
    2043      7709120 :                   pdom_bb->aux = edge_predicate_pool.allocate ();
    2044      7709120 :                   *((ipa_predicate *)pdom_bb->aux) = p;
    2045              :                 }
    2046     31108562 :               else if (p != *(ipa_predicate *)pdom_bb->aux)
    2047              :                 {
    2048      3447539 :                   p = p.or_with (summary->conds,
    2049              :                                  *(ipa_predicate *)pdom_bb->aux);
    2050      3447539 :                   if (p != *(ipa_predicate *)pdom_bb->aux)
    2051              :                     {
    2052       141600 :                       done = false;
    2053       141600 :                       *((ipa_predicate *)pdom_bb->aux) = p;
    2054              :                     }
    2055              :                 }
    2056              :             }
    2057              :         }
    2058              :     }
    2059      6560932 : }
    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      4274359 : 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      4274359 :   tree parm;
    2073      4274359 :   int index;
    2074              : 
    2075      4519713 :   while (UNARY_CLASS_P (expr))
    2076       245354 :     expr = TREE_OPERAND (expr, 0);
    2077              : 
    2078      4274359 :   parm = unmodified_parm (fbi, NULL, expr, NULL);
    2079      4274359 :   if (parm && (index = ipa_get_param_decl_index (fbi->info, parm)) >= 0)
    2080       223775 :     return add_condition (summary, params_summary, index, TREE_TYPE (parm), NULL,
    2081       223775 :                           ipa_predicate::changed, NULL_TREE);
    2082      4050584 :   if (is_gimple_min_invariant (expr))
    2083        63584 :     return false;
    2084      3987000 :   if (TREE_CODE (expr) == SSA_NAME)
    2085      3805643 :     return nonconstant_names[SSA_NAME_VERSION (expr)];
    2086       181357 :   if (BINARY_CLASS_P (expr) || COMPARISON_CLASS_P (expr))
    2087              :     {
    2088       180683 :       ipa_predicate p1
    2089       180683 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2090              :                                               params_summary,
    2091       180683 :                                               TREE_OPERAND (expr, 0),
    2092              :                                               nonconstant_names);
    2093       180683 :       if (p1 == true)
    2094       103933 :         return p1;
    2095              : 
    2096        76750 :       ipa_predicate p2
    2097        76750 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2098              :                                               params_summary,
    2099        76750 :                                               TREE_OPERAND (expr, 1),
    2100              :                                               nonconstant_names);
    2101        76750 :       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    117083517 : 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    117083517 :   ipa_predicate p = true;
    2148    117083517 :   ssa_op_iter iter;
    2149    117083517 :   tree use;
    2150    117083517 :   tree param_type = NULL_TREE;
    2151    117083517 :   ipa_predicate op_non_const;
    2152    117083517 :   bool is_load;
    2153    117083517 :   int base_index;
    2154    117083517 :   struct agg_position_info aggpos;
    2155              : 
    2156              :   /* What statements might be optimized away
    2157              :      when their arguments are constant.  */
    2158    117083517 :   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     21398794 :           || !(gimple_call_flags (stmt) & ECF_CONST)))
    2163     26830624 :     return p;
    2164              : 
    2165              :   /* Stores will stay anyway.  */
    2166     90252893 :   if (gimple_store_p (stmt))
    2167     26540469 :     return p;
    2168              : 
    2169     63712424 :   is_load = gimple_assign_load_p (stmt);
    2170              : 
    2171              :   /* Loads can be optimized when the value is known.  */
    2172     63712424 :   if (is_load)
    2173              :     {
    2174     18250999 :       tree op = gimple_assign_rhs1 (stmt);
    2175     18250999 :       if (!decompose_param_expr (fbi, stmt, op, &base_index, &param_type,
    2176              :                                  &aggpos))
    2177     14943227 :         return p;
    2178              :     }
    2179              :   else
    2180     45461425 :     base_index = -1;
    2181              : 
    2182              :   /* See if we understand all operands before we start
    2183              :      adding conditionals.  */
    2184     66534855 :   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2185              :     {
    2186     48613997 :       tree parm = unmodified_parm (fbi, stmt, use, NULL);
    2187              :       /* For arguments we can build a condition.  */
    2188     48613997 :       if (parm && ipa_get_param_decl_index (fbi->info, parm) >= 0)
    2189      8701686 :         continue;
    2190     39912311 :       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     39912311 :       if (nonconstant_names[SSA_NAME_VERSION (use)] != true)
    2195      9063972 :         continue;
    2196     30848339 :       return p;
    2197              :     }
    2198              : 
    2199     17920858 :   if (is_load)
    2200      3307691 :     op_non_const =
    2201      3307691 :       add_condition (summary, params_summary,
    2202              :                      base_index, param_type, &aggpos,
    2203              :                      ipa_predicate::changed, NULL_TREE);
    2204              :   else
    2205     14613167 :     op_non_const = false;
    2206     34640706 :   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2207              :     {
    2208     16719848 :       tree parm = unmodified_parm (fbi, stmt, use, NULL);
    2209     16719848 :       int index;
    2210              : 
    2211     16719848 :       if (parm && (index = ipa_get_param_decl_index (fbi->info, parm)) >= 0)
    2212              :         {
    2213      8202523 :           if (index != base_index)
    2214      5600177 :             p = add_condition (summary, params_summary, index,
    2215      5600177 :                                TREE_TYPE (parm), NULL,
    2216              :                                ipa_predicate::changed, NULL_TREE);
    2217              :           else
    2218      2602346 :             continue;
    2219              :         }
    2220              :       else
    2221      8517325 :         p = nonconstant_names[SSA_NAME_VERSION (use)];
    2222     14117502 :       op_non_const = p.or_with (summary->conds, op_non_const);
    2223              :     }
    2224     17920858 :   if ((gimple_code (stmt) == GIMPLE_ASSIGN || gimple_code (stmt) == GIMPLE_CALL)
    2225     15565400 :       && gimple_op (stmt, 0)
    2226     33181056 :       && TREE_CODE (gimple_op (stmt, 0)) == SSA_NAME)
    2227     15260198 :     nonconstant_names[SSA_NAME_VERSION (gimple_op (stmt, 0))]
    2228     15260198 :       = op_non_const;
    2229     17920858 :   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     10693496 : get_minimal_bb (basic_block init_bb, basic_block use_bb)
    2249              : {
    2250     10693496 :   class loop *l = find_common_loop (init_bb->loop_father, use_bb->loop_father);
    2251     10693496 :   if (l && l->header->count < init_bb->count)
    2252       386097 :     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      4952756 : record_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data)
    2261              : {
    2262      4952756 :   struct record_modified_bb_info *info =
    2263              :     (struct record_modified_bb_info *) data;
    2264      4952756 :   if (SSA_NAME_DEF_STMT (vdef) == info->stmt)
    2265              :     return false;
    2266      4924573 :   if (gimple_clobber_p (SSA_NAME_DEF_STMT (vdef)))
    2267              :     return false;
    2268      4874992 :   bitmap_set_bit (info->bb_set,
    2269      4874992 :                   SSA_NAME_IS_DEFAULT_DEF (vdef)
    2270            0 :                   ? ENTRY_BLOCK_PTR_FOR_FN (cfun)->index
    2271              :                   : get_minimal_bb
    2272      4874992 :                          (gimple_bb (SSA_NAME_DEF_STMT (vdef)),
    2273      4874992 :                           gimple_bb (info->stmt))->index);
    2274      4874992 :   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     39633232 : param_change_prob (ipa_func_body_info *fbi, gimple *stmt, int i)
    2297              : {
    2298     39633232 :   tree op = gimple_call_arg (stmt, i);
    2299     39633232 :   basic_block bb = gimple_bb (stmt);
    2300              : 
    2301     39633232 :   if (TREE_CODE (op) == WITH_SIZE_EXPR)
    2302          299 :     op = TREE_OPERAND (op, 0);
    2303              : 
    2304     39633232 :   tree base = get_base_address (op);
    2305              : 
    2306              :   /* Global invariants never change.  */
    2307     39633232 :   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     19903368 :   if (TREE_CODE (base) == SSA_NAME)
    2317              :     {
    2318     17506127 :       profile_count init_count;
    2319              : 
    2320     26857862 :       if (!bb->count.nonzero_p ())
    2321              :         return REG_BR_PROB_BASE;
    2322              : 
    2323      8945684 :       if (SSA_NAME_IS_DEFAULT_DEF (base))
    2324      3127180 :         init_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2325              :       else
    2326      5818504 :         init_count = get_minimal_bb
    2327      5818504 :                       (gimple_bb (SSA_NAME_DEF_STMT (base)),
    2328              :                        gimple_bb (stmt))->count;
    2329              : 
    2330      8945684 :       if (init_count < bb->count)
    2331       461063 :         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      2397241 :       ao_ref refd;
    2338      2397241 :       profile_count max = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2339      2397241 :       struct record_modified_bb_info info;
    2340      2397241 :       tree init = ctor_for_folding (base);
    2341              : 
    2342      2397241 :       if (init != error_mark_node)
    2343              :         return 0;
    2344      5358791 :       if (!bb->count.nonzero_p () || fbi->aa_walk_budget == 0)
    2345              :         return REG_BR_PROB_BASE;
    2346      1469611 :       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      1469611 :       ao_ref_init (&refd, op);
    2353      1469611 :       info.op = op;
    2354      1469611 :       info.stmt = stmt;
    2355      1469611 :       info.bb_set = BITMAP_ALLOC (NULL);
    2356      1469611 :       int walked
    2357      2939222 :         = walk_aliased_vdefs (&refd, gimple_vuse (stmt), record_modified, &info,
    2358              :                               NULL, NULL, fbi->aa_walk_budget);
    2359      1469611 :       if (walked > 0)
    2360      1335628 :         fbi->aa_walk_budget -= walked;
    2361      1469611 :       if (walked < 0 || bitmap_bit_p (info.bb_set, bb->index))
    2362              :         {
    2363       895365 :           if (walked < 0)
    2364          206 :             fbi->aa_walk_budget = 0;
    2365       895365 :           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       895365 :           BITMAP_FREE (info.bb_set);
    2373       895365 :           return REG_BR_PROB_BASE;
    2374              :         }
    2375              : 
    2376       574246 :       bitmap_iterator bi;
    2377       574246 :       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      1612694 :       EXECUTE_IF_SET_IN_BITMAP (info.bb_set, 0, index, bi)
    2381      1038448 :         max = profile_count::max_prefer_initialized
    2382      1038448 :                 (max, BASIC_BLOCK_FOR_FN (cfun, index)->count);
    2383       574246 :       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       574246 :       BITMAP_FREE (info.bb_set);
    2394       574246 :       if (max < bb->count)
    2395        95442 :         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      6482553 : 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      6482553 :   edge e;
    2414      6482553 :   edge_iterator ei;
    2415      6482553 :   basic_block first_bb = NULL;
    2416              : 
    2417      6482553 :   if (single_pred_p (bb))
    2418              :     {
    2419        83158 :       *p = false;
    2420        83158 :       return true;
    2421              :     }
    2422              : 
    2423     14724759 :   FOR_EACH_EDGE (e, ei, bb->preds)
    2424              :     {
    2425     12603436 :       if (single_succ_p (e->src))
    2426              :         {
    2427      8429392 :           if (!single_pred_p (e->src))
    2428              :             return false;
    2429      7411810 :           if (!first_bb)
    2430      3257688 :             first_bb = single_pred (e->src);
    2431      4154122 :           else if (single_pred (e->src) != first_bb)
    2432              :             return false;
    2433              :         }
    2434              :       else
    2435              :         {
    2436      4174044 :           if (!first_bb)
    2437              :             first_bb = e->src;
    2438      1461533 :           else if (e->src != first_bb)
    2439              :             return false;
    2440              :         }
    2441              :     }
    2442              : 
    2443      2121323 :   if (!first_bb)
    2444              :     return false;
    2445              : 
    2446      4242646 :   gcond *stmt = safe_dyn_cast <gcond *> (*gsi_last_bb (first_bb));
    2447      2076538 :   if (!stmt
    2448      2076538 :       || !is_gimple_ip_invariant (gimple_cond_rhs (stmt)))
    2449              :     return false;
    2450              : 
    2451      1819653 :   *p = will_be_nonconstant_expr_predicate (fbi, summary, params_summary,
    2452              :                                            gimple_cond_lhs (stmt),
    2453              :                                            nonconstant_names);
    2454      1819653 :   if (*p == true)
    2455              :     return false;
    2456              :   else
    2457       607257 :     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       788438 : predicate_for_phi_result (class ipa_fn_summary *summary, gphi *phi,
    2467              :                           ipa_predicate *p,
    2468              :                           vec<ipa_predicate> nonconstant_names)
    2469              : {
    2470       788438 :   unsigned i;
    2471              : 
    2472      1109023 :   for (i = 0; i < gimple_phi_num_args (phi); i++)
    2473              :     {
    2474       950288 :       tree arg = gimple_phi_arg (phi, i)->def;
    2475       950288 :       if (!is_gimple_min_invariant (arg))
    2476              :         {
    2477       798231 :           gcc_assert (TREE_CODE (arg) == SSA_NAME);
    2478      1596462 :           *p = p->or_with (summary->conds,
    2479       798231 :                            nonconstant_names[SSA_NAME_VERSION (arg)]);
    2480       798231 :           if (*p == true)
    2481              :             return;
    2482              :         }
    2483              :     }
    2484              : 
    2485       158735 :   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       158735 :   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     42021189 : find_foldable_builtin_expect (basic_block bb)
    2510              : {
    2511     42021189 :   gimple_stmt_iterator bsi;
    2512              : 
    2513    295041495 :   for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
    2514              :     {
    2515    211186992 :       gimple *stmt = gsi_stmt (bsi);
    2516    211186992 :       if (gimple_call_builtin_p (stmt, BUILT_IN_EXPECT)
    2517    210946944 :           || gimple_call_builtin_p (stmt, BUILT_IN_EXPECT_WITH_PROBABILITY)
    2518    422133859 :           || gimple_call_internal_p (stmt, IFN_BUILTIN_EXPECT))
    2519              :         {
    2520       373190 :           tree var = gimple_call_lhs (stmt);
    2521       373190 :           tree arg = gimple_call_arg (stmt, 0);
    2522       373190 :           use_operand_p use_p;
    2523       373190 :           gimple *use_stmt;
    2524       373190 :           bool match = false;
    2525       373190 :           bool done = false;
    2526              : 
    2527       373190 :           if (!var || !arg)
    2528            3 :             continue;
    2529       373187 :           gcc_assert (TREE_CODE (var) == SSA_NAME);
    2530              : 
    2531       745007 :           while (TREE_CODE (arg) == SSA_NAME)
    2532              :             {
    2533       745007 :               gimple *stmt_tmp = SSA_NAME_DEF_STMT (arg);
    2534       745007 :               if (!is_gimple_assign (stmt_tmp))
    2535              :                 break;
    2536       737659 :               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       371820 :               if (done)
    2554              :                 break;
    2555       371820 :               arg = gimple_assign_rhs1 (stmt_tmp);
    2556              :             }
    2557              : 
    2558       336185 :           if (match && single_imm_use (var, &use_p, &use_stmt)
    2559       709054 :               && gimple_code (use_stmt) == GIMPLE_COND)
    2560       187875 :             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     42671662 : clobber_only_eh_bb_p (basic_block bb, bool need_eh = true)
    2577              : {
    2578     42671662 :   gimple_stmt_iterator gsi = gsi_last_bb (bb);
    2579     42671662 :   edge_iterator ei;
    2580     42671662 :   edge e;
    2581              : 
    2582     42671662 :   if (need_eh)
    2583              :     {
    2584     42601512 :       if (gsi_end_p (gsi))
    2585              :         return false;
    2586     41452738 :       if (gimple_code (gsi_stmt (gsi)) != GIMPLE_RESX)
    2587              :         return false;
    2588      1160009 :       gsi_prev (&gsi);
    2589              :     }
    2590        70150 :   else if (!single_succ_p (bb))
    2591              :     return false;
    2592              : 
    2593      3058363 :   for (; !gsi_end_p (gsi); gsi_prev (&gsi))
    2594              :     {
    2595      2981732 :       gimple *stmt = gsi_stmt (gsi);
    2596      2981732 :       if (is_gimple_debug (stmt))
    2597       996204 :         continue;
    2598      1985528 :       if (gimple_clobber_p (stmt))
    2599       939077 :         continue;
    2600      1046451 :       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      3121647 :   FOR_EACH_EDGE (e, ei, bb->preds)
    2607      2539822 :     if (!(e->flags & EDGE_EH)
    2608      2539822 :         && !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     96388256 : fp_expression_p (gimple *stmt)
    2619              : {
    2620     96388256 :   ssa_op_iter i;
    2621     96388256 :   tree op;
    2622              : 
    2623    216365377 :   FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_DEF|SSA_OP_USE)
    2624    120595055 :     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     61014225 : refs_local_or_readonly_memory_p (tree t)
    2634              : {
    2635              :   /* Non-escaping memory is fine.  */
    2636     61014225 :   t = get_base_address (t);
    2637     61014225 :   if ((TREE_CODE (t) == MEM_REF
    2638     61014225 :       || TREE_CODE (t) == TARGET_MEM_REF))
    2639     25789063 :     return points_to_local_or_readonly_memory_p (TREE_OPERAND (t, 0));
    2640              : 
    2641              :   /* Automatic variables are fine.  */
    2642     35225162 :   if (DECL_P (t)
    2643     35225162 :       && auto_var_in_fn_p (t, current_function_decl))
    2644              :     return true;
    2645              : 
    2646              :   /* Read-only variables are fine.  */
    2647     11352587 :   if (DECL_P (t) && TREE_READONLY (t))
    2648      1672555 :     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     74275840 : points_to_local_or_readonly_memory_p (tree t)
    2658              : {
    2659              :   /* See if memory location is clearly invalid.  */
    2660     74275840 :   if (integer_zerop (t))
    2661      2486403 :     return flag_delete_null_pointer_checks;
    2662     71789437 :   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     45496197 :       if (DECL_RESULT (current_function_decl)
    2672     45496197 :           && DECL_BY_REFERENCE (DECL_RESULT (current_function_decl))
    2673     46629538 :           && t == ssa_default_def (cfun, DECL_RESULT (current_function_decl)))
    2674              :         return true;
    2675     45160416 :       return !ptr_deref_may_alias_global_p (t, false);
    2676              :     }
    2677     26293240 :   if (TREE_CODE (t) == ADDR_EXPR
    2678     26293240 :       && (TREE_CODE (TREE_OPERAND (t, 0)) != TARGET_MEM_REF
    2679         4692 :           || TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)) != INTEGER_CST))
    2680     13631035 :     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     39633232 : points_to_possible_sra_candidate_p (tree t)
    2689              : {
    2690     39633232 :   if (TREE_CODE (t) != ADDR_EXPR)
    2691              :     return false;
    2692              : 
    2693     11837942 :   t = get_base_address (TREE_OPERAND (t, 0));
    2694              : 
    2695              :   /* Automatic variables are fine.  */
    2696     11837942 :   if (DECL_P (t)
    2697     11837942 :       && 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     27935183 : builtin_unreachable_bb_p (basic_block bb, vec<unsigned char> &cache)
    2708              : {
    2709     27935183 :   if (cache[bb->index])
    2710      2757374 :     return cache[bb->index] - 1;
    2711     25177809 :   gimple_stmt_iterator si;
    2712     25177809 :   auto_vec <basic_block, 4> visited_bbs;
    2713     25177809 :   bool ret = false;
    2714     25989892 :   while (true)
    2715              :     {
    2716     25989892 :       bool empty_bb = true;
    2717     25989892 :       visited_bbs.safe_push (bb);
    2718     25989892 :       cache[bb->index] = 3;
    2719     25989892 :       for (si = gsi_start_nondebug_bb (bb);
    2720     27510325 :            !gsi_end_p (si) && empty_bb;
    2721      1520433 :            gsi_next_nondebug (&si))
    2722              :         {
    2723     26134433 :           if (gimple_code (gsi_stmt (si)) != GIMPLE_PREDICT
    2724     25758727 :               && !gimple_clobber_p (gsi_stmt (si))
    2725     50781864 :               && !gimple_nop_p (gsi_stmt (si)))
    2726              :             {
    2727              :               empty_bb = false;
    2728              :               break;
    2729              :             }
    2730              :         }
    2731     25989892 :       if (!empty_bb)
    2732              :         break;
    2733              :       else
    2734      1375892 :         bb = single_succ_edge (bb)->dest;
    2735      1375892 :       if (cache[bb->index])
    2736              :         {
    2737       563809 :           ret = cache[bb->index] == 3 ? false : cache[bb->index] - 1;
    2738       563809 :           goto done;
    2739              :         }
    2740              :     }
    2741     24614000 :   if (gimple_call_builtin_p (gsi_stmt (si), BUILT_IN_UNREACHABLE)
    2742     24614000 :       || gimple_call_builtin_p (gsi_stmt (si), BUILT_IN_UNREACHABLE_TRAP))
    2743              :     ret = true;
    2744     25177809 : done:
    2745    101523319 :   for (basic_block vbb:visited_bbs)
    2746     25989892 :     cache[vbb->index] = (unsigned char)ret + 1;
    2747     25177809 :   return ret;
    2748     25177809 : }
    2749              : 
    2750              : static bool
    2751     14096919 : guards_builtin_unreachable (basic_block bb, vec<unsigned char> &cache)
    2752              : {
    2753     14096919 :   edge_iterator ei;
    2754     14096919 :   edge e;
    2755     41758834 :   FOR_EACH_EDGE (e, ei, bb->succs)
    2756     27935183 :     if (builtin_unreachable_bb_p (e->dest, cache))
    2757              :       {
    2758       273268 :         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    175861636 : mark_stmt_necessary (gimple *stmt, auto_vec<gimple *> &worklist)
    2774              : {
    2775    175861636 :   gcc_assert (stmt);
    2776              : 
    2777    175861636 :   if (gimple_plf (stmt, STMT_NECESSARY))
    2778              :     return;
    2779              : 
    2780    146048216 :   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    146048216 :   gimple_set_plf (stmt, STMT_NECESSARY, true);
    2788    146048216 :   worklist.safe_push (stmt);
    2789              : }
    2790              : 
    2791              : /* Mark the statement defining operand OP as necessary.  */
    2792              : 
    2793              : static inline void
    2794    123839461 : mark_operand_necessary (tree op, auto_vec<gimple *> &worklist)
    2795              : {
    2796    123839461 :   gimple *stmt = SSA_NAME_DEF_STMT (op);
    2797    123839461 :   if (gimple_nop_p (stmt))
    2798              :     return;
    2799    100230723 :   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      7483419 : find_necessary_statements (struct cgraph_node *node)
    2808              : {
    2809      7483419 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    2810      7483419 :   auto_vec<unsigned char, 10> cache;
    2811      7483419 :   basic_block bb;
    2812      7483419 :   auto_vec<gimple *> worklist;
    2813              : 
    2814      7483419 :   cache.safe_grow_cleared (last_basic_block_for_fn (cfun));
    2815              :   /* Mark all obviously necessary statements.  */
    2816     50084931 :   FOR_EACH_BB_FN (bb, my_function)
    2817              :     {
    2818     42601512 :       for (gimple_stmt_iterator gsi = gsi_start_phis (bb);
    2819     54407319 :            !gsi_end_p (gsi); gsi_next (&gsi))
    2820     11805807 :         gimple_set_plf (gsi_stmt (gsi), STMT_NECESSARY, false);
    2821              : 
    2822    238639514 :       for (gimple_stmt_iterator bsi = gsi_start_bb (bb); !gsi_end_p (bsi);
    2823    153436490 :            gsi_next_nondebug (&bsi))
    2824              :         {
    2825    153436490 :           gimple *stmt = gsi_stmt (bsi);
    2826              : 
    2827    153436490 :           gimple_set_plf (stmt, STMT_NECESSARY, false);
    2828    153436490 :           if (gimple_has_side_effects (stmt)
    2829    125635530 :               || (is_ctrl_stmt (stmt)
    2830     22678020 :                   && (gimple_code (stmt) != GIMPLE_COND
    2831     14096919 :                       || !guards_builtin_unreachable (bb, cache)))
    2832    103230778 :               || gimple_store_p (stmt)
    2833    231263756 :               || gimple_code (stmt) == GIMPLE_ASM)
    2834     75630913 :             mark_stmt_necessary (stmt, worklist);
    2835              :         }
    2836              :     }
    2837    153531635 :   while (worklist.length () > 0)
    2838              :     {
    2839    146048216 :       gimple *stmt = worklist.pop ();
    2840              : 
    2841    146048216 :       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    146048216 :       if (gimple_code (stmt) == GIMPLE_PHI)
    2848     18618257 :         for (unsigned int k = 0; k < gimple_phi_num_args (stmt); k++)
    2849              :           {
    2850     13174638 :             tree arg = PHI_ARG_DEF (stmt, k);
    2851              : 
    2852     13174638 :             if (TREE_CODE (arg) == SSA_NAME)
    2853     10080405 :               mark_operand_necessary (arg, worklist);
    2854              :           }
    2855              :       else
    2856              :         {
    2857    140604597 :           ssa_op_iter iter;
    2858    140604597 :           tree use;
    2859              : 
    2860    254363653 :           FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2861    113759056 :             mark_operand_necessary (use, worklist);
    2862              :         }
    2863              :     }
    2864      7483419 : }
    2865              : 
    2866              : /* Analyze function body for NODE.
    2867              :    EARLY indicates run from early optimization pipeline.  */
    2868              : 
    2869              : static void
    2870      7483419 : analyze_function_body (struct cgraph_node *node, bool early)
    2871              : {
    2872      7483419 :   sreal time = opt_for_fn (node->decl, param_uninlined_function_time);
    2873              :   /* Estimate static overhead for function prologue/epilogue and alignment. */
    2874      7483419 :   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      7483419 :   basic_block bb;
    2878      7483419 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    2879      7483419 :   sreal freq;
    2880      7483419 :   class ipa_fn_summary *info = ipa_fn_summaries->get_create (node);
    2881      7483419 :   ipa_node_params *params_summary
    2882      7483419 :     = early ? NULL : ipa_node_params_sum->get (node);
    2883      7483419 :   ipa_predicate bb_predicate;
    2884      7483419 :   struct ipa_func_body_info fbi;
    2885      7483419 :   vec<ipa_predicate> nonconstant_names = vNULL;
    2886      7483419 :   int nblocks, n;
    2887      7483419 :   int *order;
    2888      7483419 :   gimple *fix_builtin_expect_stmt;
    2889              : 
    2890      7483419 :   gcc_assert (my_function && my_function->cfg);
    2891      7483419 :   gcc_assert (cfun == my_function);
    2892              : 
    2893      7483419 :   memset(&fbi, 0, sizeof(fbi));
    2894      7483419 :   vec_free (info->conds);
    2895      7483419 :   info->conds = NULL;
    2896      7483419 :   info->size_time_table.release ();
    2897      7483419 :   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      7483419 :   if (opt_for_fn (node->decl, optimize))
    2906              :     {
    2907      6560932 :       calculate_dominance_info (CDI_DOMINATORS);
    2908      6560932 :       calculate_dominance_info (CDI_POST_DOMINATORS);
    2909      6560932 :       if (!early)
    2910      1418182 :         loop_optimizer_init (LOOPS_NORMAL | LOOPS_HAVE_RECORDED_EXITS);
    2911              :       else
    2912              :         {
    2913      5142750 :           ipa_check_create_node_params ();
    2914      5142750 :           ipa_initialize_node_params (node);
    2915              :         }
    2916              : 
    2917      6560932 :       if (ipa_node_params_sum)
    2918              :         {
    2919      6560932 :           fbi.node = node;
    2920      6560932 :           fbi.info = ipa_node_params_sum->get (node);
    2921      6560932 :           fbi.bb_infos = vNULL;
    2922      6560932 :           fbi.bb_infos.safe_grow_cleared (last_basic_block_for_fn (cfun), true);
    2923      6560932 :           fbi.param_count = count_formal_params (node->decl);
    2924      6560932 :           fbi.aa_walk_budget = opt_for_fn (node->decl, param_ipa_max_aa_steps);
    2925              : 
    2926      6560932 :           nonconstant_names.safe_grow_cleared
    2927      6560932 :             (SSANAMES (my_function)->length (), true);
    2928              :         }
    2929              :     }
    2930              : 
    2931      7483419 :   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      7483419 :   bb_predicate = true;
    2938      7483419 :   info->account_size_time (0, 0, bb_predicate, bb_predicate);
    2939              : 
    2940      7483419 :   bb_predicate = ipa_predicate::not_inlined ();
    2941      7483419 :   info->account_size_time (opt_for_fn (node->decl,
    2942              :                                 param_uninlined_function_insns)
    2943              :                            * ipa_fn_summary::size_scale,
    2944      7483419 :                            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      7483419 :   bool scan_for_target_info =
    2951      7483419 :     info->inlinable
    2952     13455475 :     && targetm.target_option.need_ipa_fn_target_info (node->decl,
    2953      5972056 :                                                       info->target_info);
    2954              : 
    2955      7483419 :   if (fbi.info)
    2956      6560932 :     compute_bb_predicates (&fbi, node, info, params_summary);
    2957      7483419 :   find_necessary_statements (node);
    2958      7483419 :   const profile_count entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2959      7483419 :   order = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
    2960      7483419 :   nblocks = pre_and_rev_post_order_compute (NULL, order, false);
    2961     57568350 :   for (n = 0; n < nblocks; n++)
    2962              :     {
    2963     42601512 :       bb = BASIC_BLOCK_FOR_FN (cfun, order[n]);
    2964     42601512 :       freq = bb->count.to_sreal_scale (entry_count);
    2965     42601512 :       if (clobber_only_eh_bb_p (bb))
    2966              :         {
    2967       580323 :           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       580323 :           continue;
    2972              :         }
    2973              : 
    2974              :       /* TODO: Obviously predicates can be propagated down across CFG.  */
    2975     42021189 :       if (fbi.info)
    2976              :         {
    2977     35509929 :           if (bb->aux)
    2978     35509915 :             bb_predicate = *(ipa_predicate *)bb->aux;
    2979              :           else
    2980           14 :             bb_predicate = false;
    2981              :         }
    2982              :       else
    2983      6511260 :         bb_predicate = true;
    2984              : 
    2985     42021189 :       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     42021189 :       if (fbi.info && nonconstant_names.exists ())
    2992              :         {
    2993     35509929 :           ipa_predicate phi_predicate;
    2994     35509929 :           bool first_phi = true;
    2995              : 
    2996     36298367 :           for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi);
    2997       788438 :                gsi_next (&bsi))
    2998              :             {
    2999      6580576 :               if (first_phi
    3000      6580576 :                   && !phi_result_unknown_predicate (&fbi, info,
    3001              :                                                     params_summary,
    3002              :                                                     bb,
    3003              :                                                     &phi_predicate,
    3004              :                                                     nonconstant_names))
    3005              :                 break;
    3006       788438 :               first_phi = false;
    3007       788438 :               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       788438 :               predicate_for_phi_result (info, bsi.phi (), &phi_predicate,
    3013              :                                         nonconstant_names);
    3014              :             }
    3015              :         }
    3016              : 
    3017     42021189 :       fix_builtin_expect_stmt = find_foldable_builtin_expect (bb);
    3018              : 
    3019     42021189 :       for (gimple_stmt_iterator bsi = gsi_start_nondebug_bb (bb);
    3020    186997531 :            !gsi_end_p (bsi); gsi_next_nondebug (&bsi))
    3021              :         {
    3022    144976342 :           gimple *stmt = gsi_stmt (bsi);
    3023    144976342 :           if (!gimple_plf (stmt, STMT_NECESSARY))
    3024              :             {
    3025      5737908 :               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      5737908 :               if (!is_gimple_call (stmt)
    3035      5737908 :                   || gimple_call_internal_p (stmt))
    3036      5448987 :                 continue;
    3037              :             }
    3038    139527355 :           int this_size = estimate_num_insns (stmt, &eni_size_weights);
    3039    139527355 :           int this_time = estimate_num_insns (stmt, &eni_time_weights);
    3040    139527355 :           int prob;
    3041    139527355 :           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    139527355 :           if (stmt == fix_builtin_expect_stmt)
    3046              :             {
    3047       187437 :               this_size--;
    3048       187437 :               this_time--;
    3049              :             }
    3050              : 
    3051    139527355 :           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    139527355 :           if (is_gimple_call (stmt)
    3061    139527355 :               && !gimple_call_internal_p (stmt))
    3062              :             {
    3063     23507549 :               struct cgraph_edge *edge = node->get_edge (stmt);
    3064     23507549 :               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     23507549 :               if (nonconstant_names.exists ()
    3070     20578026 :                   && gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P)
    3071        48232 :                   && gimple_call_lhs (stmt)
    3072     23555781 :                   && TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME)
    3073              :                 {
    3074        48232 :                   ipa_predicate false_p = false;
    3075        48232 :                   nonconstant_names[SSA_NAME_VERSION (gimple_call_lhs (stmt))]
    3076        48232 :                     = false_p;
    3077              :                 }
    3078     23507549 :               if (ipa_node_params_sum)
    3079              :                 {
    3080     20590843 :                   int count = gimple_call_num_args (stmt);
    3081     20590843 :                   int i;
    3082              : 
    3083     20590843 :                   if (count)
    3084     17700218 :                     es->param.safe_grow_cleared (count, true);
    3085     60224075 :                   for (i = 0; i < count; i++)
    3086              :                     {
    3087     39633232 :                       int prob = param_change_prob (&fbi, stmt, i);
    3088     39633232 :                       gcc_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
    3089     39633232 :                       es->param[i].change_prob = prob;
    3090     39633232 :                       es->param[i].points_to_local_or_readonly_memory
    3091     39633232 :                          = points_to_local_or_readonly_memory_p
    3092     39633232 :                              (gimple_call_arg (stmt, i));
    3093     39633232 :                       es->param[i].points_to_possible_sra_candidate
    3094     39633232 :                          = points_to_possible_sra_candidate_p
    3095     39633232 :                              (gimple_call_arg (stmt, i));
    3096              :                     }
    3097              :                 }
    3098              :               /* We cannot setup VLA parameters during inlining.  */
    3099     69073331 :               for (unsigned int i = 0; i < gimple_call_num_args (stmt); ++i)
    3100     45566178 :                 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     23507549 :               es->call_stmt_size = this_size;
    3106     23507549 :               es->call_stmt_time = this_time;
    3107     23507549 :               es->loop_depth = bb_loop_depth (bb);
    3108     23507549 :               edge_set_predicate (edge, &bb_predicate);
    3109     23507549 :               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     23507549 :               if (edge->has_callback)
    3136              :                 {
    3137        15126 :                   cgraph_edge *cbe;
    3138        30253 :                   for (cbe = edge->first_callback_edge (); cbe;
    3139        15127 :                        cbe = cbe->next_callback_edge ())
    3140              :                     {
    3141        15127 :                       ipa_call_summary *es2 = ipa_call_summaries->get_create (cbe);
    3142        15127 :                       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        15127 :                       es2->call_stmt_size = 0;
    3147        15127 :                       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    139527355 :           if (fbi.info)
    3156    117083517 :             will_be_nonconstant
    3157    117083517 :               = will_be_nonconstant_predicate (&fbi, info, params_summary,
    3158              :                                                stmt, nonconstant_names);
    3159              :           else
    3160     22443838 :             will_be_nonconstant = true;
    3161    139527355 :           if (this_time || this_size)
    3162              :             {
    3163    114053989 :               sreal final_time = (sreal)this_time * freq;
    3164    114053989 :               prob = eliminated_by_inlining_prob (&fbi, stmt);
    3165    114053989 :               if (prob == 1 && dump_file && (dump_flags & TDF_DETAILS))
    3166           11 :                 fprintf (dump_file,
    3167              :                          "\t\t50%% will be eliminated by inlining\n");
    3168    114053989 :               if (prob == 2 && dump_file && (dump_flags & TDF_DETAILS))
    3169           20 :                 fprintf (dump_file, "\t\tWill be eliminated by inlining\n");
    3170              : 
    3171    114053989 :               ipa_predicate p = bb_predicate & will_be_nonconstant;
    3172    114053989 :               int parm = load_or_store_of_ptr_parameter (&fbi, stmt);
    3173    114053989 :               ipa_predicate sra_predicate = true;
    3174    114053989 :               if (parm != -1)
    3175     14581006 :                 sra_predicate &= add_condition (info, params_summary, parm,
    3176              :                                                 ptr_type_node, NULL,
    3177      7290503 :                                                 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    228107978 :               if (*(is_gimple_call (stmt) ? &bb_predicate : &p) != false)
    3184              :                 {
    3185    113292488 :                   time += final_time;
    3186    113292488 :                   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    114053989 :               if (!is_gimple_call (stmt))
    3193              :                 {
    3194     91279903 :                   if (prob)
    3195              :                     {
    3196     15364809 :                       ipa_predicate ip
    3197     15364809 :                         = bb_predicate & ipa_predicate::not_inlined () & sra_predicate;
    3198     30729618 :                       info->account_size_time (this_size * prob,
    3199     15364809 :                                                (final_time * prob) / 2, ip,
    3200              :                                                p);
    3201              :                     }
    3202     15364809 :                   if (prob != 2)
    3203    168283664 :                     info->account_size_time (this_size * (2 - prob),
    3204     84141832 :                                              (final_time * (2 - prob) / 2),
    3205    168283664 :                                              bb_predicate & sra_predicate,
    3206              :                                              p);
    3207              :                 }
    3208              : 
    3209    114053989 :               if (!info->fp_expressions && fp_expression_p (stmt))
    3210              :                 {
    3211       617934 :                   info->fp_expressions = true;
    3212       617934 :                   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    139527355 :           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    539681951 :           for (unsigned int i = 0; i < gimple_num_ops (stmt); i++)
    3228              :             {
    3229    400154596 :               for (tree op = gimple_op (stmt, i);
    3230    770286173 :                    op && handled_component_p (op);
    3231     48354285 :                    op = TREE_OPERAND (op, 0))
    3232     48354285 :                 if ((TREE_CODE (op) == ARRAY_REF
    3233     48354285 :                      || TREE_CODE (op) == ARRAY_RANGE_REF)
    3234     48354285 :                     && TREE_CODE (TREE_OPERAND (op, 1)) == SSA_NAME)
    3235              :                   {
    3236      2417114 :                     ipa_predicate p = bb_predicate;
    3237      2417114 :                     if (fbi.info)
    3238      1891006 :                       p = p & will_be_nonconstant_expr_predicate
    3239      1891006 :                                  (&fbi, info, params_summary,
    3240      1891006 :                                   TREE_OPERAND (op, 1),
    3241      1891006 :                                   nonconstant_names);
    3242      2417114 :                     if (p != false)
    3243              :                       {
    3244      2411692 :                         time += freq;
    3245      2411692 :                         size += 1;
    3246      2411692 :                         if (dump_file)
    3247           24 :                           fprintf (dump_file,
    3248              :                                    "\t\tAccounting address calculation.\n");
    3249      2411692 :                         info->account_size_time (ipa_fn_summary::size_scale,
    3250              :                                                  freq,
    3251              :                                                  bb_predicate,
    3252              :                                                  p);
    3253              :                       }
    3254              :                   }
    3255              :             }
    3256              : 
    3257              :         }
    3258              :     }
    3259      7483419 :   free (order);
    3260              : 
    3261      7483419 :   if (nonconstant_names.exists () && !early)
    3262              :     {
    3263      1418182 :       ipa_fn_summary *s = ipa_fn_summaries->get (node);
    3264      1418182 :       unsigned max_loop_predicates = opt_for_fn (node->decl,
    3265              :                                                  param_ipa_max_loop_predicates);
    3266              : 
    3267      1418182 :       if (dump_file && (dump_flags & TDF_DETAILS))
    3268           16 :         flow_loops_dump (dump_file, NULL, 0);
    3269      1418182 :       scev_initialize ();
    3270      4886735 :       for (auto loop : loops_list (cfun, 0))
    3271              :         {
    3272       632189 :           ipa_predicate loop_iterations = true;
    3273       632189 :           sreal header_freq;
    3274       632189 :           edge ex;
    3275       632189 :           unsigned int j;
    3276       632189 :           class tree_niter_desc niter_desc;
    3277       632189 :           if (!loop->header->aux)
    3278            0 :             continue;
    3279              : 
    3280       632189 :           profile_count hdr_count = loop->header->count;
    3281       632189 :           sreal hdr_freq = hdr_count.to_sreal_scale (entry_count);
    3282              : 
    3283       632189 :           bb_predicate = *(ipa_predicate *)loop->header->aux;
    3284       632189 :           auto_vec<edge> exits = get_loop_exit_edges (loop);
    3285      2293980 :           FOR_EACH_VEC_ELT (exits, j, ex)
    3286      1029602 :             if (number_of_iterations_exit (loop, ex, &niter_desc, false)
    3287      1029602 :                 && !is_gimple_min_invariant (niter_desc.niter))
    3288              :             {
    3289       155501 :               ipa_predicate will_be_nonconstant
    3290       155501 :                 = will_be_nonconstant_expr_predicate (&fbi, info,
    3291              :                                                       params_summary,
    3292              :                                                       niter_desc.niter,
    3293              :                                                       nonconstant_names);
    3294       155501 :               if (will_be_nonconstant != true)
    3295        62506 :                 will_be_nonconstant = bb_predicate & will_be_nonconstant;
    3296       155501 :               if (will_be_nonconstant != true
    3297       218007 :                   && will_be_nonconstant != false)
    3298        61953 :                 loop_iterations &= will_be_nonconstant;
    3299              :             }
    3300       632189 :           add_freqcounting_predicate (&s->loop_iterations, loop_iterations,
    3301              :                                       hdr_freq, max_loop_predicates);
    3302       632191 :         }
    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      1418182 :       for (class loop *loop = loops_for_fn (cfun)->tree_root->inner;
    3308      1917647 :            loop != NULL; loop = loop->next)
    3309              :         {
    3310       499465 :           ipa_predicate loop_stride = true;
    3311       499465 :           basic_block *body = get_loop_body (loop);
    3312       499465 :           profile_count hdr_count = loop->header->count;
    3313       499465 :           sreal hdr_freq = hdr_count.to_sreal_scale (entry_count);
    3314      3432315 :           for (unsigned i = 0; i < loop->num_nodes; i++)
    3315              :             {
    3316      2433385 :               gimple_stmt_iterator gsi;
    3317      2433385 :               if (!body[i]->aux)
    3318            7 :                 continue;
    3319              : 
    3320      2433378 :               bb_predicate = *(ipa_predicate *)body[i]->aux;
    3321     16465398 :               for (gsi = gsi_start_bb (body[i]); !gsi_end_p (gsi);
    3322     11598642 :                    gsi_next (&gsi))
    3323              :                 {
    3324     11598642 :                   gimple *stmt = gsi_stmt (gsi);
    3325              : 
    3326     11598642 :                   if (!is_gimple_assign (stmt))
    3327     11448215 :                     continue;
    3328              : 
    3329      5488892 :                   tree def = gimple_assign_lhs (stmt);
    3330      5488892 :                   if (TREE_CODE (def) != SSA_NAME)
    3331      1047446 :                     continue;
    3332              : 
    3333      4441446 :                   affine_iv iv;
    3334      8882892 :                   if (!simple_iv (loop_containing_stmt (stmt),
    3335              :                                   loop_containing_stmt (stmt),
    3336              :                                   def, &iv, true)
    3337      4441446 :                       || is_gimple_min_invariant (iv.step))
    3338      4291019 :                     continue;
    3339              : 
    3340       150427 :                   ipa_predicate will_be_nonconstant
    3341       150427 :                     = will_be_nonconstant_expr_predicate (&fbi, info,
    3342              :                                                           params_summary,
    3343              :                                                           iv.step,
    3344              :                                                           nonconstant_names);
    3345       150427 :                   if (will_be_nonconstant != true)
    3346        55290 :                     will_be_nonconstant = bb_predicate & will_be_nonconstant;
    3347       150427 :                   if (will_be_nonconstant != true
    3348       205717 :                       && will_be_nonconstant != false)
    3349        45695 :                     loop_stride = loop_stride & will_be_nonconstant;
    3350              :                 }
    3351              :             }
    3352       499465 :           add_freqcounting_predicate (&s->loop_strides, loop_stride,
    3353              :                                       hdr_freq, max_loop_predicates);
    3354       499465 :           free (body);
    3355              :         }
    3356      1418182 :       scev_finalize ();
    3357              :     }
    3358     65051769 :   FOR_ALL_BB_FN (bb, my_function)
    3359              :     {
    3360     57568350 :       edge e;
    3361     57568350 :       edge_iterator ei;
    3362              : 
    3363     57568350 :       if (bb->aux)
    3364     42586407 :         edge_predicate_pool.remove ((ipa_predicate *)bb->aux);
    3365     57568350 :       bb->aux = NULL;
    3366    122314092 :       FOR_EACH_EDGE (e, ei, bb->succs)
    3367              :         {
    3368     64745742 :           if (e->aux)
    3369      2606346 :             edge_predicate_pool.remove ((ipa_predicate *)e->aux);
    3370     64745742 :           e->aux = NULL;
    3371              :         }
    3372              :     }
    3373      7483419 :   ipa_fn_summary *s = ipa_fn_summaries->get (node);
    3374      7483419 :   ipa_size_summary *ss = ipa_size_summaries->get (node);
    3375      7483419 :   s->time = time;
    3376      7483419 :   ss->self_size = size;
    3377      7483419 :   nonconstant_names.release ();
    3378      7483419 :   ipa_release_body_info (&fbi);
    3379      7483419 :   if (opt_for_fn (node->decl, optimize))
    3380              :     {
    3381      6560932 :       if (!early)
    3382      1418182 :         loop_optimizer_finalize ();
    3383      5142750 :       else if (!ipa_edge_args_sum)
    3384      5142736 :         ipa_free_all_node_params ();
    3385      6560932 :       free_dominance_info (CDI_DOMINATORS);
    3386      6560932 :       free_dominance_info (CDI_POST_DOMINATORS);
    3387              :     }
    3388      7483419 :   if (dump_file)
    3389              :     {
    3390          249 :       fprintf (dump_file, "\n");
    3391          249 :       ipa_dump_fn_summary (dump_file, node);
    3392              :     }
    3393      7483419 : }
    3394              : 
    3395              : 
    3396              : /* Compute function summary.
    3397              :    EARLY is true when we compute parameters during early opts.  */
    3398              : 
    3399              : void
    3400      7484735 : compute_fn_summary (struct cgraph_node *node, bool early)
    3401              : {
    3402      7484735 :   HOST_WIDE_INT self_stack_size;
    3403      7484735 :   struct cgraph_edge *e;
    3404              : 
    3405      7484735 :   gcc_assert (!node->inlined_to);
    3406              : 
    3407      7484735 :   if (!ipa_fn_summaries)
    3408       218693 :     ipa_fn_summary_alloc ();
    3409              : 
    3410              :   /* Create a new ipa_fn_summary.  */
    3411      7484735 :   ((ipa_fn_summary_t *)ipa_fn_summaries)->remove_callees (node);
    3412      7484735 :   ipa_fn_summaries->remove (node);
    3413      7484735 :   class ipa_fn_summary *info = ipa_fn_summaries->get_create (node);
    3414      7484735 :   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     13123164 :   self_stack_size = optimize && !node->thunk
    3418     14045667 :                     ? estimated_stack_frame_size (node) : 0;
    3419      7484735 :   size_info->estimated_self_stack_size = self_stack_size;
    3420      7484735 :   info->estimated_stack_size = self_stack_size;
    3421              : 
    3422      7484735 :   if (node->thunk)
    3423              :     {
    3424         1316 :       ipa_call_summary *es = ipa_call_summaries->get_create (node->callees);
    3425         1316 :       ipa_predicate t = true;
    3426              : 
    3427         1316 :       node->can_change_signature = false;
    3428         1316 :       es->call_stmt_size = eni_size_weights.call_cost;
    3429         1316 :       es->call_stmt_time = eni_time_weights.call_cost;
    3430         3948 :       info->account_size_time (ipa_fn_summary::size_scale
    3431         1316 :                                * opt_for_fn (node->decl,
    3432              :                                  param_uninlined_function_thunk_insns),
    3433         1316 :                                opt_for_fn (node->decl,
    3434              :                                  param_uninlined_function_thunk_time), t, t);
    3435         1316 :       t = ipa_predicate::not_inlined ();
    3436         1316 :       info->account_size_time (2 * ipa_fn_summary::size_scale, 0, t, t);
    3437         1316 :       ipa_update_overall_fn_summary (node);
    3438         1316 :       size_info->self_size = size_info->size;
    3439         1316 :       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         1307 :         info->inlinable = true;
    3446              :     }
    3447              :   else
    3448              :     {
    3449              :        /* Even is_gimple_min_invariant rely on current_function_decl.  */
    3450      7483419 :        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      7483419 :        update_ssa (TODO_update_ssa_only_virtuals);
    3455              : 
    3456              :        /* Can this function be inlined at all?  */
    3457      7483419 :        if (!opt_for_fn (node->decl, optimize)
    3458      8405906 :            && !lookup_attribute ("always_inline",
    3459       922487 :                                  DECL_ATTRIBUTES (node->decl)))
    3460       851397 :          info->inlinable = false;
    3461              :        else
    3462      6632022 :          info->inlinable = tree_inlinable_function_p (node->decl);
    3463              : 
    3464      7483419 :        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      7483419 :        if (cfun->has_musttail)
    3473              :          {
    3474         1441 :            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      7483419 :        for (tree list = TYPE_ATTRIBUTES (TREE_TYPE (node->decl));
    3484      7883422 :             list && !no_signature; list = TREE_CHAIN (list))
    3485       400003 :         if (!ipa_param_adjustments::type_attribute_allowed_p
    3486       400003 :                         (get_attribute_name (list)))
    3487              :            {
    3488       159304 :              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      7483419 :        for (tree parm = DECL_ARGUMENTS (node->decl);
    3497     22321908 :             parm && !no_signature; parm = DECL_CHAIN (parm))
    3498     14838489 :          if (variably_modified_type_p (TREE_TYPE (parm), node->decl))
    3499              :            {
    3500        15944 :              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      7483419 :        if (no_signature
    3511     14790149 :            || lookup_attribute ("omp declare simd",
    3512      7306730 :                                 DECL_ATTRIBUTES (node->decl)))
    3513       178383 :          node->can_change_signature = false;
    3514              :        else
    3515              :          {
    3516              :            /* Otherwise, inlinable functions always can change signature.  */
    3517      7305036 :            if (info->inlinable)
    3518      5892181 :              node->can_change_signature = true;
    3519              :            else
    3520              :              {
    3521              :                /* Functions calling builtin_apply cannot change signature.  */
    3522      5457303 :                for (e = node->callees; e; e = e->next_callee)
    3523              :                  {
    3524      4077218 :                    tree cdecl = e->callee->decl;
    3525      4077218 :                    if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS,
    3526              :                                                  BUILT_IN_VA_START))
    3527              :                      break;
    3528              :                  }
    3529      1412855 :                node->can_change_signature = !e;
    3530              :              }
    3531              :          }
    3532      7483419 :        analyze_function_body (node, early);
    3533      7483419 :        pop_cfun ();
    3534              :      }
    3535              : 
    3536              :   /* Inlining characteristics are maintained by the cgraph_mark_inline.  */
    3537      7484735 :   size_info->size = size_info->self_size;
    3538      7484735 :   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      7484735 :   ipa_update_overall_fn_summary (node);
    3546      7484735 :   if (flag_checking)
    3547              :     {
    3548      7967285 :       for (e = node->indirect_calls; e; e = e->next_callee)
    3549       482632 :        if (e->speculative)
    3550              :          break;
    3551      7484653 :       gcc_assert (e || size_info->size == size_info->self_size);
    3552              :     }
    3553      7484735 : }
    3554              : 
    3555              : 
    3556              : /* Compute parameters of functions used by inliner using
    3557              :    current_function_decl.  */
    3558              : 
    3559              : static unsigned int
    3560      6002610 : compute_fn_summary_for_current (void)
    3561              : {
    3562      6002610 :   compute_fn_summary (cgraph_node::get (current_function_decl), true);
    3563      6002610 :   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      4892000 : estimate_edge_devirt_benefit (struct cgraph_edge *ie,
    3572              :                               int *size, int *time,
    3573              :                               ipa_call_arg_values *avals)
    3574              : {
    3575      4892000 :   tree target;
    3576      4892000 :   struct cgraph_node *callee;
    3577      4892000 :   class ipa_fn_summary *isummary;
    3578      4892000 :   enum availability avail;
    3579      4892000 :   bool speculative;
    3580              : 
    3581      4892000 :   if (!avals
    3582      4892000 :       || (!avals->m_known_vals.length() && !avals->m_known_contexts.length ()))
    3583              :     return false;
    3584      1479281 :   if (!opt_for_fn (ie->caller->decl, flag_indirect_inlining))
    3585              :     return false;
    3586              : 
    3587      1472818 :   target = ipa_get_indirect_edge_target
    3588      1472818 :     (ie->callee ? ie->speculative_call_indirect_edge () : ie,
    3589              :      avals, &speculative);
    3590      1472818 :   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       219121 :   if (ie->callee)
    3596              :     {
    3597         4402 :       gcc_checking_assert (ie->speculative && *size > 0);
    3598         4402 :       *size = 0;
    3599         4402 :       *time = 0;
    3600              :     }
    3601              :   else
    3602              :     {
    3603              :       /* Account for difference in cost between indirect and direct calls.  */
    3604       214719 :       *size -= (eni_size_weights.indirect_call_cost - eni_size_weights.call_cost);
    3605       214719 :       *time -= (eni_time_weights.indirect_call_cost - eni_time_weights.call_cost);
    3606              :     }
    3607       219121 :   gcc_checking_assert (*time >= 0);
    3608       219121 :   gcc_checking_assert (*size >= 0);
    3609              : 
    3610       219121 :   callee = cgraph_node::get (target);
    3611       219121 :   if (!callee || !callee->definition)
    3612              :     return false;
    3613       198486 :   callee = callee->function_symbol (&avail);
    3614       198486 :   if (avail < AVAIL_AVAILABLE)
    3615              :     return false;
    3616       198460 :   isummary = ipa_fn_summaries->get (callee);
    3617       198460 :   if (isummary == NULL)
    3618              :     return false;
    3619              : 
    3620       198446 :   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    219482537 : 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    219482537 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
    3634    219482537 :   int call_size = es->call_stmt_size;
    3635    219482537 :   int call_time = es->call_stmt_time;
    3636    219482537 :   int cur_size;
    3637              : 
    3638    215200127 :   if ((!e->callee || e->speculative)
    3639    220092127 :       && estimate_edge_devirt_benefit (e, &call_size, &call_time, avals))
    3640              :     {
    3641       198200 :       if (hints && e->maybe_hot_p ())
    3642       188982 :         *hints |= INLINE_HINT_indirect_call;
    3643              :     }
    3644    219482537 :   cur_size = call_size * ipa_fn_summary::size_scale;
    3645    219482537 :   *size += cur_size;
    3646    219482537 :   if (min_size)
    3647     29197213 :     *min_size += cur_size;
    3648    219482537 :   if (time)
    3649    209497479 :     *time += ((sreal)call_time) * e->sreal_frequency ();
    3650    219482537 : }
    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     79712958 : 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     79712958 :   struct cgraph_edge *e;
    3668    378377107 :   for (e = node->callees; e; e = e->next_callee)
    3669              :     {
    3670    298664149 :       if (!e->inline_failed)
    3671              :         {
    3672     58820099 :           gcc_checking_assert (!ipa_call_summaries->get (e));
    3673     58820099 :           estimate_calls_size_and_time_1 (e->callee, size, min_size, time,
    3674              :                                           hints, possible_truths, avals);
    3675              : 
    3676     58820099 :           continue;
    3677              :         }
    3678    239844050 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3679              : 
    3680              :       /* Do not care about zero sized builtins.  */
    3681    239844050 :       if (!es->call_stmt_size)
    3682              :         {
    3683     33501532 :           gcc_checking_assert (!es->call_stmt_time);
    3684     33501532 :           continue;
    3685              :         }
    3686    206342518 :       if (!es->predicate
    3687    206342518 :           || 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    203880387 :           estimate_edge_size_and_time (e, size,
    3692    203880387 :                                        es->predicate ? NULL : min_size,
    3693              :                                        time, avals, hints);
    3694              :         }
    3695              :     }
    3696     83710561 :   for (e = node->indirect_calls; e; e = e->next_callee)
    3697              :     {
    3698      3997603 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3699      3997603 :       if (!es->predicate
    3700      3997603 :           || es->predicate->evaluate (possible_truths))
    3701      3965585 :         estimate_edge_size_and_time (e, size,
    3702      3965585 :                                      es->predicate ? NULL : min_size,
    3703              :                                      time, avals, hints);
    3704              :     }
    3705     79712958 : }
    3706              : 
    3707              : /* Populate sum->call_size_time_table for edges from NODE.  */
    3708              : 
    3709              : static void
    3710      3327922 : summarize_calls_size_and_time (struct cgraph_node *node,
    3711              :                                ipa_fn_summary *sum)
    3712              : {
    3713      3327922 :   struct cgraph_edge *e;
    3714     15264722 :   for (e = node->callees; e; e = e->next_callee)
    3715              :     {
    3716     11936800 :       if (!e->inline_failed)
    3717              :         {
    3718      1524334 :           gcc_checking_assert (!ipa_call_summaries->get (e));
    3719      1524334 :           summarize_calls_size_and_time (e->callee, sum);
    3720      1524334 :           continue;
    3721              :         }
    3722     10412466 :       int size = 0;
    3723     10412466 :       sreal time = 0;
    3724              : 
    3725     10412466 :       estimate_edge_size_and_time (e, &size, NULL, &time, NULL, NULL);
    3726              : 
    3727     10412466 :       ipa_predicate pred = true;
    3728     10412466 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3729              : 
    3730     10412466 :       if (es->predicate)
    3731      1915567 :         pred = *es->predicate;
    3732     10412466 :       sum->account_size_time (size, time, pred, pred, true);
    3733              :     }
    3734      3644747 :   for (e = node->indirect_calls; e; e = e->next_callee)
    3735              :     {
    3736       316825 :       int size = 0;
    3737       316825 :       sreal time = 0;
    3738              : 
    3739       316825 :       estimate_edge_size_and_time (e, &size, NULL, &time, NULL, NULL);
    3740       316825 :       ipa_predicate pred = true;
    3741       316825 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3742              : 
    3743       316825 :       if (es->predicate)
    3744        81414 :         pred = *es->predicate;
    3745       316825 :       sum->account_size_time (size, time, pred, pred, true);
    3746              :     }
    3747      3327922 : }
    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     20892880 : 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     20892880 :   class ipa_fn_summary *sum = ipa_fn_summaries->get (node);
    3761     20892880 :   bool use_table = true;
    3762              : 
    3763     20892880 :   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     20892880 :   if (!ipa_node_params_sum)
    3769              :     use_table = false;
    3770              :   /* Do not calculate summaries for simple wrappers; it is waste
    3771              :      of memory.  */
    3772     11324783 :   else if (node->callees && !node->indirect_calls
    3773     10564268 :            && 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      9098431 :   else if (avals
    3778      9098431 :            && (avals->m_known_vals.length ()
    3779      3399184 :                || avals->m_known_contexts.length ()
    3780      3252298 :                || avals->m_known_aggs.length ()))
    3781              :     {
    3782      4296568 :       ipa_node_params *params_summary = ipa_node_params_sum->get (node);
    3783      4296568 :       unsigned int nargs = params_summary
    3784      4296568 :                            ? ipa_get_param_count (params_summary) : 0;
    3785              : 
    3786     14273334 :       for (unsigned int i = 0; i < nargs && use_table; i++)
    3787              :         {
    3788      9976766 :           if (ipa_is_param_used_by_indirect_call (params_summary, i)
    3789      9976766 :               && (avals->safe_sval_at (i)
    3790       270944 :                   || (ipa_argagg_value_list (avals).value_for_index_p (i))))
    3791              :             use_table = false;
    3792      9880076 :           else if (ipa_is_param_used_by_polymorphic_call (params_summary, i)
    3793      9880076 :                    && (avals->m_known_contexts.length () > i
    3794     10119447 :                        && !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      4296568 :   if (use_table)
    3801              :     {
    3802              :       /* Build summary if it is absent.  */
    3803      8835974 :       if (!sum->call_size_time_table.length ())
    3804              :         {
    3805       896314 :           ipa_predicate true_pred = true;
    3806       896314 :           sum->account_size_time (0, 0, true_pred, true_pred, true);
    3807       896314 :           summarize_calls_size_and_time (node, sum);
    3808              :         }
    3809              : 
    3810      8835974 :       int old_size = *size;
    3811      8835974 :       sreal old_time = time ? *time : 0;
    3812              : 
    3813      8835974 :       if (min_size)
    3814      8835974 :         *min_size += sum->call_size_time_table[0].size;
    3815              : 
    3816      8835974 :       unsigned int i;
    3817      8835974 :       size_time_entry *e;
    3818              : 
    3819              :       /* Walk the table and account sizes and times.  */
    3820     23293345 :       for (i = 0; sum->call_size_time_table.iterate (i, &e);
    3821              :            i++)
    3822     14457371 :         if (e->exec_predicate.evaluate (possible_truths))
    3823              :           {
    3824     13533780 :             *size += e->size;
    3825     13533780 :             if (time)
    3826     11359702 :               *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      8835974 :           && sum->call_size_time_table.length ()
    3834              :              < ipa_fn_summary::max_size_time_table_size)
    3835              :         {
    3836      8835953 :           estimate_calls_size_and_time_1 (node, &old_size, NULL, &old_time, NULL,
    3837              :                                           possible_truths, avals);
    3838      8835953 :           gcc_assert (*size == old_size);
    3839     16240399 :           if (time && (*time - old_time > 1 || *time - old_time < -1)
    3840      8835980 :               && 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     12056906 :     estimate_calls_size_and_time_1 (node, size, min_size, time, hints,
    3849              :                                     possible_truths, avals);
    3850     20892880 : }
    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     19954048 : 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     19954048 : : m_node (node), m_possible_truths (possible_truths),
    3862     19954048 :   m_nonspec_possible_truths (nonspec_possible_truths),
    3863     19954048 :   m_inline_param_summary (inline_param_summary),
    3864     19954048 :   m_avals (arg_values)
    3865              : {
    3866     19954048 : }
    3867              : 
    3868              : /* Set THIS to be a duplicate of CTX.  Copy all relevant info.  */
    3869              : 
    3870              : void
    3871      2009410 : ipa_cached_call_context::duplicate_from (const ipa_call_context &ctx)
    3872              : {
    3873      2009410 :   m_node = ctx.m_node;
    3874      2009410 :   m_possible_truths = ctx.m_possible_truths;
    3875      2009410 :   m_nonspec_possible_truths = ctx.m_nonspec_possible_truths;
    3876      2009410 :   ipa_node_params *params_summary = ipa_node_params_sum->get (m_node);
    3877      2009410 :   unsigned int nargs = params_summary
    3878      2009410 :                        ? ipa_get_param_count (params_summary) : 0;
    3879              : 
    3880      2009410 :   m_inline_param_summary = vNULL;
    3881              :   /* Copy the info only if there is at least one useful entry.  */
    3882      2009410 :   if (ctx.m_inline_param_summary.exists ())
    3883              :     {
    3884      1790087 :       unsigned int n = MIN (ctx.m_inline_param_summary.length (), nargs);
    3885              : 
    3886      4099997 :       for (unsigned int i = 0; i < n; i++)
    3887      3349254 :         if (ipa_is_param_used_by_ipa_predicates (params_summary, i)
    3888      4780066 :             && !ctx.m_inline_param_summary[i].useless_p ())
    3889              :           {
    3890      1039344 :             m_inline_param_summary
    3891      1039344 :                     = ctx.m_inline_param_summary.copy ();
    3892      1039344 :             break;
    3893              :           }
    3894              :     }
    3895      2009410 :   m_avals.m_known_vals = vNULL;
    3896      2009410 :   if (ctx.m_avals.m_known_vals.exists ())
    3897              :     {
    3898      2009410 :       unsigned int n = MIN (ctx.m_avals.m_known_vals.length (), nargs);
    3899              : 
    3900      4666531 :       for (unsigned int i = 0; i < n; i++)
    3901      2683948 :         if (ipa_is_param_used_by_indirect_call (params_summary, i)
    3902      2683948 :             && ctx.m_avals.m_known_vals[i])
    3903              :           {
    3904        26827 :             m_avals.m_known_vals = ctx.m_avals.m_known_vals.copy ();
    3905        26827 :             break;
    3906              :           }
    3907              :     }
    3908              : 
    3909      2009410 :   m_avals.m_known_contexts = vNULL;
    3910      2009410 :   if (ctx.m_avals.m_known_contexts.exists ())
    3911              :     {
    3912      2009410 :       unsigned int n = MIN (ctx.m_avals.m_known_contexts.length (), nargs);
    3913              : 
    3914      2011427 :       for (unsigned int i = 0; i < n; i++)
    3915        26720 :         if (ipa_is_param_used_by_polymorphic_call (params_summary, i)
    3916        26720 :             && !ctx.m_avals.m_known_contexts[i].useless_p ())
    3917              :           {
    3918        24703 :             m_avals.m_known_contexts = ctx.m_avals.m_known_contexts.copy ();
    3919        24703 :             break;
    3920              :           }
    3921              :     }
    3922              : 
    3923      2009410 :   m_avals.m_known_aggs = vNULL;
    3924      2009410 :   if (ctx.m_avals.m_known_aggs.exists ())
    3925              :     {
    3926      2009410 :       const ipa_argagg_value_list avl (&ctx.m_avals);
    3927      6678506 :       for (unsigned int i = 0; i < nargs; i++)
    3928      4672020 :         if (ipa_is_param_used_by_indirect_call (params_summary, i)
    3929      4672020 :             && avl.value_for_index_p (i))
    3930              :           {
    3931         2924 :             m_avals.m_known_aggs = ctx.m_avals.m_known_aggs.copy ();
    3932         2924 :             break;
    3933              :           }
    3934              :     }
    3935              : 
    3936      2009410 :   m_avals.m_known_value_ranges = vNULL;
    3937      2009410 : }
    3938              : 
    3939              : /* Release memory used by known_vals/contexts/aggs vectors.  and
    3940              :    inline_param_summary.  */
    3941              : 
    3942              : void
    3943      3270908 : ipa_cached_call_context::release ()
    3944              : {
    3945              :   /* See if context is initialized at first place.  */
    3946      3270908 :   if (!m_node)
    3947              :     return;
    3948      2009410 :   m_avals.m_known_aggs.release ();
    3949      2009410 :   m_avals.m_known_vals.release ();
    3950      2009410 :   m_avals.m_known_contexts.release ();
    3951      2009410 :   m_inline_param_summary.release ();
    3952              : }
    3953              : 
    3954              : /* Return true if CTX describes the same call context as THIS.  */
    3955              : 
    3956              : bool
    3957      7098152 : ipa_call_context::equal_to (const ipa_call_context &ctx)
    3958              : {
    3959      7098152 :   if (m_node != ctx.m_node
    3960      5836654 :       || m_possible_truths != ctx.m_possible_truths
    3961      5220533 :       || m_nonspec_possible_truths != ctx.m_nonspec_possible_truths)
    3962              :     return false;
    3963              : 
    3964      5220533 :   ipa_node_params *params_summary = ipa_node_params_sum->get (m_node);
    3965      5220533 :   unsigned int nargs = params_summary
    3966      5220533 :                        ? ipa_get_param_count (params_summary) : 0;
    3967              : 
    3968      5220533 :   if (m_inline_param_summary.exists () || ctx.m_inline_param_summary.exists ())
    3969              :     {
    3970     15550030 :       for (unsigned int i = 0; i < nargs; i++)
    3971              :         {
    3972     10665883 :           if (!ipa_is_param_used_by_ipa_predicates (params_summary, i))
    3973      3348536 :             continue;
    3974      7317347 :           if (i >= m_inline_param_summary.length ()
    3975      5091902 :               || m_inline_param_summary[i].useless_p ())
    3976              :             {
    3977      3229647 :               if (i < ctx.m_inline_param_summary.length ()
    3978      3229647 :                   && !ctx.m_inline_param_summary[i].useless_p ())
    3979              :                 return false;
    3980      3184137 :               continue;
    3981              :             }
    3982      4087700 :           if (i >= ctx.m_inline_param_summary.length ()
    3983      4087697 :               || ctx.m_inline_param_summary[i].useless_p ())
    3984              :             {
    3985        44896 :               if (i < m_inline_param_summary.length ()
    3986        44896 :                   && !m_inline_param_summary[i].useless_p ())
    3987              :                 return false;
    3988            0 :               continue;
    3989              :             }
    3990      4042804 :           if (!m_inline_param_summary[i].equal_to
    3991      4042804 :                  (ctx.m_inline_param_summary[i]))
    3992              :             return false;
    3993              :         }
    3994              :     }
    3995      5102286 :   if (m_avals.m_known_vals.exists () || ctx.m_avals.m_known_vals.exists ())
    3996              :     {
    3997     15570341 :       for (unsigned int i = 0; i < nargs; i++)
    3998              :         {
    3999     10478781 :           if (!ipa_is_param_used_by_indirect_call (params_summary, i))
    4000     10268481 :             continue;
    4001       210300 :           if (i >= m_avals.m_known_vals.length () || !m_avals.m_known_vals[i])
    4002              :             {
    4003       152811 :               if (i < ctx.m_avals.m_known_vals.length ()
    4004       152811 :                   && ctx.m_avals.m_known_vals[i])
    4005              :                 return false;
    4006       152722 :               continue;
    4007              :             }
    4008        57489 :           if (i >= ctx.m_avals.m_known_vals.length ()
    4009        57489 :               || !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        57399 :           if (m_avals.m_known_vals[i] != ctx.m_avals.m_known_vals[i])
    4016              :             return false;
    4017              :         }
    4018              :     }
    4019      5091560 :   if (m_avals.m_known_contexts.exists ()
    4020      5091560 :       || ctx.m_avals.m_known_contexts.exists ())
    4021              :     {
    4022     15555091 :       for (unsigned int i = 0; i < nargs; i++)
    4023              :         {
    4024     10464944 :           if (!ipa_is_param_used_by_polymorphic_call (params_summary, i))
    4025     10328155 :             continue;
    4026       136789 :           if (i >= m_avals.m_known_contexts.length ()
    4027       135627 :               || 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       135627 :           if (i >= ctx.m_avals.m_known_contexts.length ()
    4035       135627 :               || 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       135619 :           if (!m_avals.m_known_contexts[i].equal_to
    4043       135619 :                  (ctx.m_avals.m_known_contexts[i]))
    4044              :             return false;
    4045              :         }
    4046              :     }
    4047      5090147 :   if (m_avals.m_known_aggs.exists () || ctx.m_avals.m_known_aggs.exists ())
    4048              :     {
    4049              :       unsigned i = 0, j = 0;
    4050     12060486 :       while (i < m_avals.m_known_aggs.length ()
    4051      6029484 :              || j < ctx.m_avals.m_known_aggs.length ())
    4052              :         {
    4053       940742 :           if (i >= m_avals.m_known_aggs.length ())
    4054              :             {
    4055       935844 :               int idx2 = ctx.m_avals.m_known_aggs[j].index;
    4056       935844 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx2))
    4057              :                 return false;
    4058       935290 :               j++;
    4059       935290 :               continue;
    4060       935290 :             }
    4061         4898 :           if (j >= ctx.m_avals.m_known_aggs.length ())
    4062              :             {
    4063          600 :               int idx1 = m_avals.m_known_aggs[i].index;
    4064          600 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4065              :                 return false;
    4066            8 :               i++;
    4067            8 :               continue;
    4068            8 :             }
    4069              : 
    4070         4298 :           int idx1 = m_avals.m_known_aggs[i].index;
    4071         4298 :           int idx2 = ctx.m_avals.m_known_aggs[j].index;
    4072         4298 :           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         4298 :           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         4298 :           if (!ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4087              :             {
    4088          482 :               i++;
    4089          482 :               j++;
    4090          482 :               continue;
    4091              :             }
    4092              : 
    4093         3816 :           if ((m_avals.m_known_aggs[i].unit_offset
    4094         3816 :                != ctx.m_avals.m_known_aggs[j].unit_offset)
    4095         3808 :               || (m_avals.m_known_aggs[i].by_ref
    4096         3808 :                != ctx.m_avals.m_known_aggs[j].by_ref)
    4097         7624 :               || !operand_equal_p (m_avals.m_known_aggs[i].value,
    4098         3808 :                                    ctx.m_avals.m_known_aggs[j].value))
    4099              :             return false;
    4100         3557 :           i++;
    4101         3557 :           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     19922187 : ipa_call_context::estimate_size_and_time (ipa_call_estimates *estimates,
    4114              :                                           bool est_times, bool est_hints)
    4115              : {
    4116     19922187 :   class ipa_fn_summary *info = ipa_fn_summaries->get (m_node);
    4117     19922187 :   size_time_entry *e;
    4118     19922187 :   int size = 0;
    4119     19922187 :   sreal time = 0;
    4120     19922187 :   int min_size = 0;
    4121     19922187 :   ipa_hints hints = 0;
    4122     19922187 :   sreal loops_with_known_iterations = 0;
    4123     19922187 :   sreal loops_with_known_strides = 0;
    4124     19922187 :   int i;
    4125              : 
    4126     19922187 :   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     19922187 :   if (m_node->callees || m_node->indirect_calls)
    4145     26412400 :     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     19922187 :   sreal nonspecialized_time = time;
    4151              : 
    4152     19922187 :   min_size += info->size_time_table[0].size;
    4153    136872298 :   for (i = 0; info->size_time_table.iterate (i, &e); i++)
    4154              :     {
    4155    116950111 :       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    116950111 :       if (exec)
    4160              :         {
    4161    114434874 :           bool nonconst = e->nonconst_predicate.evaluate (m_possible_truths);
    4162              : 
    4163    114434874 :           gcc_checking_assert (e->time >= 0);
    4164    114434874 :           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    114434874 :           if (nonconst)
    4173     57614905 :             size += e->size;
    4174    114434874 :           if (!est_times)
    4175     59190740 :             continue;
    4176     55244134 :           nonspecialized_time += e->time;
    4177     55244134 :           if (!nonconst)
    4178              :             ;
    4179     26588190 :           else if (!m_inline_param_summary.exists ())
    4180              :             {
    4181      2424741 :               if (nonconst)
    4182      2424741 :                 time += e->time;
    4183              :             }
    4184              :           else
    4185              :             {
    4186     24163449 :               int prob = e->nonconst_predicate.probability
    4187     24163449 :                                                (info->conds, m_possible_truths,
    4188              :                                                 m_inline_param_summary);
    4189     24163449 :               gcc_checking_assert (prob >= 0);
    4190     24163449 :               gcc_checking_assert (prob <= REG_BR_PROB_BASE);
    4191     24163449 :               if (prob == REG_BR_PROB_BASE)
    4192     19971513 :                 time += e->time;
    4193              :               else
    4194      4191936 :                 time += e->time * prob / REG_BR_PROB_BASE;
    4195              :             }
    4196     55244134 :           gcc_checking_assert (time >= 0);
    4197              :         }
    4198              :      }
    4199     19922187 :   gcc_checking_assert (info->size_time_table[0].exec_predicate == true);
    4200     19922187 :   gcc_checking_assert (info->size_time_table[0].nonconst_predicate == true);
    4201     19922187 :   gcc_checking_assert (min_size >= 0);
    4202     19922187 :   gcc_checking_assert (size >= 0);
    4203     19922187 :   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     19922187 :   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     19922187 :   if (time > nonspecialized_time)
    4212            0 :     time = nonspecialized_time;
    4213              : 
    4214     19922187 :   if (est_hints)
    4215              :     {
    4216      7301615 :       if (info->scc_no)
    4217       233795 :         hints |= INLINE_HINT_in_scc;
    4218      7301615 :       if (DECL_DECLARED_INLINE_P (m_node->decl))
    4219      4656222 :         hints |= INLINE_HINT_declared_inline;
    4220      7301615 :       if (info->builtin_constant_p_parms.length ()
    4221         9549 :           && DECL_DECLARED_INLINE_P (m_node->decl))
    4222         9491 :         hints |= INLINE_HINT_builtin_constant_p;
    4223              : 
    4224      7301615 :       ipa_freqcounting_predicate *fcp;
    4225      7853829 :       for (i = 0; vec_safe_iterate (info->loop_iterations, i, &fcp); i++)
    4226       552214 :         if (!fcp->predicate->evaluate (m_possible_truths))
    4227              :           {
    4228       371070 :             hints |= INLINE_HINT_loop_iterations;
    4229       371070 :             loops_with_known_iterations += fcp->freq;
    4230              :           }
    4231      7301615 :       estimates->loops_with_known_iterations = loops_with_known_iterations;
    4232              : 
    4233      7593847 :       for (i = 0; vec_safe_iterate (info->loop_strides, i, &fcp); i++)
    4234       292232 :         if (!fcp->predicate->evaluate (m_possible_truths))
    4235              :           {
    4236       262468 :             hints |= INLINE_HINT_loop_stride;
    4237       262468 :             loops_with_known_strides += fcp->freq;
    4238              :           }
    4239      7301615 :       estimates->loops_with_known_strides = loops_with_known_strides;
    4240              :     }
    4241              : 
    4242     19922187 :   size = RDIV (size, ipa_fn_summary::size_scale);
    4243     19922187 :   min_size = RDIV (min_size, ipa_fn_summary::size_scale);
    4244              : 
    4245     19922187 :   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     19922187 :   if (est_times)
    4258              :     {
    4259      7301615 :       estimates->time = time;
    4260      7301615 :       estimates->nonspecialized_time = nonspecialized_time;
    4261              :     }
    4262     19922187 :   estimates->size = size;
    4263     19922187 :   estimates->min_size = min_size;
    4264     19922187 :   if (est_hints)
    4265      7301615 :     estimates->hints = hints;
    4266     19922187 :   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       231523 : estimate_ipcp_clone_size_and_time (struct cgraph_node *node,
    4277              :                                    ipa_auto_call_arg_values *avals,
    4278              :                                    ipa_call_estimates *estimates)
    4279              : {
    4280       231523 :   clause_t clause, nonspec_clause;
    4281              : 
    4282       231523 :   evaluate_conditions_for_known_args (node, false, avals, &clause,
    4283              :                                       &nonspec_clause, NULL);
    4284       231523 :   ipa_call_context ctx (node, clause, nonspec_clause, vNULL, avals);
    4285       231523 :   ctx.estimate_size_and_time (estimates);
    4286       231523 : }
    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      5274487 : ipa_get_stack_frame_offset (struct cgraph_node *node)
    4294              : {
    4295      5274487 :   HOST_WIDE_INT offset = 0;
    4296      5274487 :   if (!node->inlined_to)
    4297              :     return 0;
    4298      4202530 :   node = node->callers->caller;
    4299      5444662 :   while (true)
    4300              :     {
    4301      4823596 :       offset += ipa_size_summaries->get (node)->estimated_self_stack_size;
    4302      4823596 :       if (!node->inlined_to)
    4303              :         return offset;
    4304       621066 :       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      4960254 : inline_update_callee_summaries (struct cgraph_node *node, int depth)
    4314              : {
    4315      4960254 :   struct cgraph_edge *e;
    4316              : 
    4317      4960254 :   ipa_propagate_frequency (node);
    4318      9633658 :   for (e = node->callees; e; e = e->next_callee)
    4319              :     {
    4320      4673404 :       if (!e->inline_failed)
    4321       758277 :         inline_update_callee_summaries (e->callee, depth);
    4322              :       else
    4323      3915127 :         ipa_call_summaries->get (e)->loop_depth += depth;
    4324              :     }
    4325      5066359 :   for (e = node->indirect_calls; e; e = e->next_callee)
    4326       106105 :     ipa_call_summaries->get (e)->loop_depth += depth;
    4327      4960254 : }
    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      4021542 : remap_edge_params (struct cgraph_edge *inlined_edge,
    4339              :                    struct cgraph_edge *edge)
    4340              : {
    4341      4021542 :   if (ipa_node_params_sum)
    4342              :     {
    4343      2833200 :       int i;
    4344      2833200 :       ipa_edge_args *args = ipa_edge_args_sum->get (edge);
    4345      2833200 :       if (!args)
    4346              :         return;
    4347      1610071 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    4348      1610071 :       class ipa_call_summary *inlined_es
    4349      1610071 :         = ipa_call_summaries->get (inlined_edge);
    4350              : 
    4351      1610071 :       if (es->param.length () == 0)
    4352              :         return;
    4353              : 
    4354      9385858 :       for (i = 0; i < ipa_get_cs_argument_count (args); i++)
    4355              :         {
    4356      3162810 :           struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
    4357      3162810 :           if (jfunc->type == IPA_JF_PASS_THROUGH
    4358      2323547 :               || jfunc->type == IPA_JF_ANCESTOR)
    4359              :             {
    4360       985112 :               int id = jfunc->type == IPA_JF_PASS_THROUGH
    4361       985112 :                        ? ipa_get_jf_pass_through_formal_id (jfunc)
    4362       145849 :                        : ipa_get_jf_ancestor_formal_id (jfunc);
    4363      1970141 :               if (id < (int) inlined_es->param.length ())
    4364              :                 {
    4365       985021 :                   int prob1 = es->param[i].change_prob;
    4366       985021 :                   int prob2 = inlined_es->param[id].change_prob;
    4367       985021 :                   int prob = combine_probabilities (prob1, prob2);
    4368              : 
    4369       985021 :                   if (prob1 && prob2 && !prob)
    4370       985021 :                     prob = 1;
    4371              : 
    4372       985021 :                   es->param[i].change_prob = prob;
    4373              : 
    4374      1970042 :                   if (inlined_es
    4375       985021 :                         ->param[id].points_to_local_or_readonly_memory)
    4376       215521 :                     es->param[i].points_to_local_or_readonly_memory = true;
    4377      1970042 :                   if (inlined_es
    4378       985021 :                         ->param[id].points_to_possible_sra_candidate)
    4379       178846 :                     es->param[i].points_to_possible_sra_candidate = true;
    4380              :                 }
    4381       985112 :               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      4960254 : 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      4960254 :   struct cgraph_edge *e, *next;
    4410      9633205 :   for (e = node->callees; e; e = next)
    4411              :     {
    4412      4672951 :       ipa_predicate p;
    4413      4672951 :       next = e->next_callee;
    4414              : 
    4415      4672951 :       if (e->inline_failed)
    4416              :         {
    4417      3914674 :           class ipa_call_summary *es = ipa_call_summaries->get (e);
    4418      3914674 :           remap_edge_params (inlined_edge, e);
    4419              : 
    4420      3914674 :           if (es->predicate)
    4421              :             {
    4422      1351489 :               p = es->predicate->remap_after_inlining
    4423      1351489 :                                      (info, params_summary,
    4424              :                                       callee_info, operand_map,
    4425              :                                       offset_map, possible_truths,
    4426              :                                       *toplev_predicate);
    4427      1351489 :               edge_set_predicate (e, &p);
    4428              :             }
    4429              :           else
    4430      2563185 :             edge_set_predicate (e, toplev_predicate);
    4431              :         }
    4432              :       else
    4433       758277 :         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      5067122 :   for (e = node->indirect_calls; e; e = next)
    4439              :     {
    4440       106868 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    4441       106868 :       ipa_predicate p;
    4442       106868 :       next = e->next_callee;
    4443              : 
    4444       106868 :       remap_edge_params (inlined_edge, e);
    4445       106868 :       if (es->predicate)
    4446              :         {
    4447        27265 :           p = es->predicate->remap_after_inlining
    4448        27265 :                                  (info, params_summary,
    4449              :                                   callee_info, operand_map, offset_map,
    4450              :                                   possible_truths, *toplev_predicate);
    4451        27265 :           edge_set_predicate (e, &p);
    4452              :         }
    4453              :       else
    4454        79603 :         edge_set_predicate (e, toplev_predicate);
    4455              :     }
    4456      4960254 : }
    4457              : 
    4458              : /* Run remap_after_inlining on each predicate in V.  */
    4459              : 
    4460              : static void
    4461      8403954 : 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      8403954 :   ipa_freqcounting_predicate *fcp;
    4472      8431259 :   for (int i = 0; vec_safe_iterate (v, i, &fcp); i++)
    4473              :     {
    4474        27305 :       ipa_predicate p
    4475        27305 :         = fcp->predicate->remap_after_inlining (info, params_summary,
    4476              :                                                 callee_info, operand_map,
    4477              :                                                 offset_map, possible_truths,
    4478              :                                                 *toplev_predicate);
    4479        37844 :       if (p != false && p != true)
    4480         2639 :         *fcp->predicate &= p;
    4481              :     }
    4482      8403954 : }
    4483              : 
    4484              : /* We inlined EDGE.  Update summary of the function we inlined into.  */
    4485              : 
    4486              : void
    4487      4201977 : ipa_merge_fn_summary_after_inlining (struct cgraph_edge *edge)
    4488              : {
    4489      4201977 :   ipa_fn_summary *callee_info = ipa_fn_summaries->get (edge->callee);
    4490      3907063 :   struct cgraph_node *to = (edge->caller->inlined_to
    4491      4201977 :                             ? edge->caller->inlined_to : edge->caller);
    4492      4201977 :   class ipa_fn_summary *info = ipa_fn_summaries->get (to);
    4493      4201977 :   clause_t clause = 0;  /* not_inline is known to be false.  */
    4494      4201977 :   size_time_entry *e;
    4495      4201977 :   auto_vec<int, 8> operand_map;
    4496      4201977 :   auto_vec<HOST_WIDE_INT, 8> offset_map;
    4497      4201977 :   int i;
    4498      4201977 :   ipa_predicate toplev_predicate;
    4499      4201977 :   class ipa_call_summary *es = ipa_call_summaries->get (edge);
    4500      4201977 :   ipa_node_params *params_summary = (ipa_node_params_sum
    4501      4201977 :                                      ? ipa_node_params_sum->get (to) : NULL);
    4502              : 
    4503      4201977 :   if (es->predicate)
    4504       359263 :     toplev_predicate = *es->predicate;
    4505              :   else
    4506      3842714 :     toplev_predicate = true;
    4507              : 
    4508      4201977 :   info->fp_expressions |= callee_info->fp_expressions;
    4509      4201977 :   info->target_info |= callee_info->target_info;
    4510              : 
    4511      4201977 :   if (callee_info->conds)
    4512              :     {
    4513      3081021 :       ipa_auto_call_arg_values avals;
    4514      3081021 :       evaluate_properties_for_edge (edge, true, &clause, NULL, &avals, false);
    4515      3081021 :     }
    4516      4201977 :   if (ipa_node_params_sum && callee_info->conds)
    4517              :     {
    4518       846213 :       ipa_edge_args *args = ipa_edge_args_sum->get (edge);
    4519       846213 :       int count = args ? ipa_get_cs_argument_count (args) : 0;
    4520       846074 :       int i;
    4521              : 
    4522       846074 :       if (count)
    4523              :         {
    4524       846074 :           operand_map.safe_grow_cleared (count, true);
    4525       846074 :           offset_map.safe_grow_cleared (count, true);
    4526              :         }
    4527      2709881 :       for (i = 0; i < count; i++)
    4528              :         {
    4529      1863668 :           struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
    4530      1863668 :           int map = -1;
    4531              : 
    4532              :           /* TODO: handle non-NOPs when merging.  */
    4533      1863668 :           if (jfunc->type == IPA_JF_PASS_THROUGH)
    4534              :             {
    4535       300631 :               if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
    4536       297061 :                 map = ipa_get_jf_pass_through_formal_id (jfunc);
    4537       300631 :               if (!ipa_get_jf_pass_through_agg_preserved (jfunc))
    4538       202188 :                 offset_map[i] = -1;
    4539              :             }
    4540      1563037 :           else if (jfunc->type == IPA_JF_ANCESTOR)
    4541              :             {
    4542        95538 :               HOST_WIDE_INT offset = ipa_get_jf_ancestor_offset (jfunc);
    4543        95538 :               if (offset >= 0 && offset < INT_MAX)
    4544              :                 {
    4545        95538 :                   map = ipa_get_jf_ancestor_formal_id (jfunc);
    4546        95538 :                   if (!ipa_get_jf_ancestor_agg_preserved (jfunc))
    4547        56426 :                     offset = -1;
    4548        95538 :                   offset_map[i] = offset;
    4549              :                 }
    4550              :             }
    4551      1863668 :           operand_map[i] = map;
    4552      3375981 :           gcc_assert (map < ipa_get_param_count (params_summary));
    4553              :         }
    4554              : 
    4555              :       int ip;
    4556       849077 :       for (i = 0; callee_info->builtin_constant_p_parms.iterate (i, &ip); i++)
    4557         2864 :         if (ip < count && operand_map[ip] >= 0)
    4558           48 :           add_builtin_constant_p_parm (info, operand_map[ip]);
    4559              :     }
    4560      4201977 :   sreal freq = edge->sreal_frequency ();
    4561     27416045 :   for (i = 0; callee_info->size_time_table.iterate (i, &e); i++)
    4562              :     {
    4563     19012091 :       ipa_predicate p;
    4564     19012091 :       p = e->exec_predicate.remap_after_inlining
    4565     19012091 :                              (info, params_summary,
    4566              :                               callee_info, operand_map,
    4567              :                               offset_map, clause,
    4568              :                               toplev_predicate);
    4569     19012091 :       ipa_predicate nonconstp;
    4570     19012091 :       nonconstp = e->nonconst_predicate.remap_after_inlining
    4571     19012091 :                                      (info, params_summary,
    4572              :                                       callee_info, operand_map,
    4573              :                                       offset_map, clause,
    4574              :                                       toplev_predicate);
    4575     28755498 :       if (p != false && nonconstp != false)
    4576              :         {
    4577      9407668 :           sreal add_time = ((sreal)e->time * freq);
    4578      9407668 :           int prob = e->nonconst_predicate.probability (callee_info->conds,
    4579              :                                                         clause, es->param);
    4580      9407668 :           if (prob != REG_BR_PROB_BASE)
    4581      1141378 :             add_time = add_time * prob / REG_BR_PROB_BASE;
    4582      1141378 :           if (prob != REG_BR_PROB_BASE
    4583      1141378 :               && 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      9407668 :           info->account_size_time (e->size, add_time, p, nonconstp);
    4589              :         }
    4590              :     }
    4591      4201977 :   remap_edge_summaries (edge, edge->callee, info, params_summary,
    4592              :                         callee_info, operand_map,
    4593              :                         offset_map, clause, &toplev_predicate);
    4594      4201977 :   remap_freqcounting_predicate (info, params_summary, callee_info,
    4595              :                                 info->loop_iterations, operand_map,
    4596              :                                 offset_map, clause, &toplev_predicate);
    4597      4201977 :   remap_freqcounting_predicate (info, params_summary, callee_info,
    4598              :                                 info->loop_strides, operand_map,
    4599              :                                 offset_map, clause, &toplev_predicate);
    4600              : 
    4601      4201977 :   HOST_WIDE_INT stack_frame_offset = ipa_get_stack_frame_offset (edge->callee);
    4602      4201977 :   HOST_WIDE_INT peak = stack_frame_offset + callee_info->estimated_stack_size;
    4603              : 
    4604      4201977 :   if (info->estimated_stack_size < peak)
    4605       124266 :     info->estimated_stack_size = peak;
    4606              : 
    4607      4201977 :   inline_update_callee_summaries (edge->callee, es->loop_depth);
    4608      4201977 :   if (info->call_size_time_table.length ())
    4609              :     {
    4610       907274 :       int edge_size = 0;
    4611       907274 :       sreal edge_time = 0;
    4612              : 
    4613       907274 :       estimate_edge_size_and_time (edge, &edge_size, NULL, &edge_time, NULL, 0);
    4614              :       /* Unaccount size and time of the optimized out call.  */
    4615       907274 :       info->account_size_time (-edge_size, -edge_time,
    4616       907274 :                                es->predicate ? *es->predicate : true,
    4617       907274 :                                es->predicate ? *es->predicate : true,
    4618              :                                true);
    4619              :       /* Account new calls.  */
    4620       907274 :       summarize_calls_size_and_time (edge->callee, info);
    4621              :     }
    4622              : 
    4623              :   /* Free summaries that are not maintained for inline clones/edges.  */
    4624      4201977 :   ipa_call_summaries->remove (edge);
    4625      4201977 :   ipa_fn_summaries->remove (edge->callee);
    4626      4201977 :   ipa_remove_from_growth_caches (edge);
    4627      4201977 : }
    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      9833359 : ipa_update_overall_fn_summary (struct cgraph_node *node, bool reset)
    4635              : {
    4636      9833359 :   class ipa_fn_summary *info = ipa_fn_summaries->get (node);
    4637      9833359 :   class ipa_size_summary *size_info = ipa_size_summaries->get (node);
    4638      9833359 :   size_time_entry *e;
    4639      9833359 :   int i;
    4640              : 
    4641      9833359 :   size_info->size = 0;
    4642      9833359 :   info->time = 0;
    4643     49881838 :   for (i = 0; info->size_time_table.iterate (i, &e); i++)
    4644              :     {
    4645     40048479 :       size_info->size += e->size;
    4646     40048479 :       info->time += e->time;
    4647              :     }
    4648      9833359 :   info->min_size = info->size_time_table[0].size;
    4649      9833359 :   if (reset)
    4650      8882442 :     info->call_size_time_table.release ();
    4651      9833359 :   if (node->callees || node->indirect_calls)
    4652      7489004 :     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      9833359 :   size_info->size = RDIV (size_info->size, ipa_fn_summary::size_scale);
    4657      9833359 :   info->min_size = RDIV (info->min_size, ipa_fn_summary::size_scale);
    4658      9833359 : }
    4659              : 
    4660              : 
    4661              : /* This function performs intraprocedural analysis in NODE that is required to
    4662              :    inline indirect calls.  */
    4663              : 
    4664              : static void
    4665      1418179 : inline_indirect_intraprocedural_analysis (struct cgraph_node *node)
    4666              : {
    4667      1418179 :   ipa_analyze_node (node);
    4668      1418179 :   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      1418179 : }
    4674              : 
    4675              : 
    4676              : /* Note function body size.  */
    4677              : 
    4678              : void
    4679      1428855 : inline_analyze_function (struct cgraph_node *node)
    4680              : {
    4681      1428855 :   push_cfun (DECL_STRUCT_FUNCTION (node->decl));
    4682              : 
    4683      1428855 :   if (dump_file)
    4684           96 :     fprintf (dump_file, "\nAnalyzing function: %s\n", node->dump_name ());
    4685      1428855 :   if (opt_for_fn (node->decl, optimize) && !node->thunk)
    4686      1418179 :     inline_indirect_intraprocedural_analysis (node);
    4687      1428855 :   compute_fn_summary (node, false);
    4688      1428855 :   if (!optimize)
    4689              :     {
    4690         9376 :       struct cgraph_edge *e;
    4691        22131 :       for (e = node->callees; e; e = e->next_callee)
    4692        12755 :         e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
    4693         9450 :       for (e = node->indirect_calls; e; e = e->next_callee)
    4694           74 :         e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
    4695              :     }
    4696              : 
    4697      1428855 :   pop_cfun ();
    4698      1428855 : }
    4699              : 
    4700              : 
    4701              : /* Called when new function is inserted to callgraph late.  */
    4702              : 
    4703              : void
    4704        19765 : ipa_fn_summary_t::insert (struct cgraph_node *node, ipa_fn_summary *)
    4705              : {
    4706        19765 :   inline_analyze_function (node);
    4707        19765 : }
    4708              : 
    4709              : /* Note function body size.  */
    4710              : 
    4711              : static void
    4712       236960 : ipa_fn_summary_generate (void)
    4713              : {
    4714       236960 :   struct cgraph_node *node;
    4715              : 
    4716      2157823 :   FOR_EACH_DEFINED_FUNCTION (node)
    4717      1920863 :     if (DECL_STRUCT_FUNCTION (node->decl))
    4718      1907169 :       node->versionable = tree_versionable_function_p (node->decl);
    4719              : 
    4720       236960 :   ipa_fn_summary_alloc ();
    4721              : 
    4722       236960 :   ipa_fn_summaries->enable_insertion_hook ();
    4723              : 
    4724       236960 :   ipa_register_cgraph_hooks ();
    4725              : 
    4726      2157823 :   FOR_EACH_DEFINED_FUNCTION (node)
    4727      1920863 :     if (!node->alias
    4728      1920863 :         && (flag_generate_lto || flag_generate_offload|| flag_wpa
    4729      1724838 :             || opt_for_fn (node->decl, optimize)))
    4730      1390485 :       inline_analyze_function (node);
    4731       236960 : }
    4732              : 
    4733              : 
    4734              : /* Write inline summary for edge E to OB.  */
    4735              : 
    4736              : static void
    4737       348372 : read_ipa_call_summary (class lto_input_block *ib, struct cgraph_edge *e,
    4738              :                        bool prevails)
    4739              : {
    4740       348372 :   class ipa_call_summary *es = prevails
    4741       348372 :                                 ? ipa_call_summaries->get_create (e) : NULL;
    4742       348372 :   ipa_predicate p;
    4743       348372 :   int length, i;
    4744              : 
    4745       348372 :   int size = streamer_read_uhwi (ib);
    4746       348372 :   int time = streamer_read_uhwi (ib);
    4747       348372 :   int depth = streamer_read_uhwi (ib);
    4748              : 
    4749       348372 :   if (es)
    4750              :     {
    4751       348323 :       es->call_stmt_size = size;
    4752       348323 :       es->call_stmt_time = time;
    4753       348323 :       es->loop_depth = depth;
    4754              :     }
    4755              : 
    4756       348372 :   bitpack_d bp = streamer_read_bitpack (ib);
    4757       348372 :   if (es)
    4758       348323 :     es->is_return_callee_uncaptured = bp_unpack_value (&bp, 1);
    4759              :   else
    4760           49 :     bp_unpack_value (&bp, 1);
    4761              : 
    4762       348372 :   p.stream_in (ib);
    4763       348372 :   if (es)
    4764       348323 :     edge_set_predicate (e, &p);
    4765       348372 :   length = streamer_read_uhwi (ib);
    4766       348372 :   if (length && es
    4767       348372 :       && (e->possibly_call_in_translation_unit_p ()
    4768              :           /* Also stream in jump functions to builtins in hope that they
    4769              :              will get fnspecs.  */
    4770       119094 :           || fndecl_built_in_p (e->callee->decl, BUILT_IN_NORMAL)))
    4771              :     {
    4772       233087 :       es->param.safe_grow_cleared (length, true);
    4773      1034898 :       for (i = 0; i < length; i++)
    4774              :         {
    4775       568724 :           es->param[i].change_prob = streamer_read_uhwi (ib);
    4776       568724 :           bitpack_d bp = streamer_read_bitpack (ib);
    4777      1706172 :           es->param[i].points_to_local_or_readonly_memory
    4778       568724 :             = bp_unpack_value (&bp, 1);
    4779      1706172 :           es->param[i].points_to_possible_sra_candidate
    4780       568724 :             = bp_unpack_value (&bp, 1);
    4781              :         }
    4782              :     }
    4783              :   else
    4784              :     {
    4785       138294 :       for (i = 0; i < length; i++)
    4786              :         {
    4787        23009 :           streamer_read_uhwi (ib);
    4788        23009 :           streamer_read_uhwi (ib);
    4789              :         }
    4790              :     }
    4791       348372 : }
    4792              : 
    4793              : 
    4794              : /* Stream in inline summaries from the section.  */
    4795              : 
    4796              : static void
    4797        13560 : inline_read_section (struct lto_file_decl_data *file_data, const char *data,
    4798              :                      size_t len)
    4799              : {
    4800        13560 :   const struct lto_function_header *header =
    4801              :     (const struct lto_function_header *) data;
    4802        13560 :   const int cfg_offset = sizeof (struct lto_function_header);
    4803        13560 :   const int main_offset = cfg_offset + header->cfg_size;
    4804        13560 :   const int string_offset = main_offset + header->main_size;
    4805        13560 :   class data_in *data_in;
    4806        13560 :   unsigned int i, count2, j;
    4807        13560 :   unsigned int f_count;
    4808              : 
    4809        13560 :   lto_input_block ib ((const char *) data + main_offset, header->main_size,
    4810        13560 :                       file_data);
    4811              : 
    4812        13560 :   data_in =
    4813        27120 :     lto_data_in_create (file_data, (const char *) data + string_offset,
    4814        13560 :                         header->string_size, vNULL);
    4815        13560 :   f_count = streamer_read_uhwi (&ib);
    4816       100664 :   for (i = 0; i < f_count; i++)
    4817              :     {
    4818        87104 :       unsigned int index;
    4819        87104 :       struct cgraph_node *node;
    4820        87104 :       class ipa_fn_summary *info;
    4821        87104 :       class ipa_node_params *params_summary;
    4822        87104 :       class ipa_size_summary *size_info;
    4823        87104 :       lto_symtab_encoder_t encoder;
    4824        87104 :       struct bitpack_d bp;
    4825        87104 :       struct cgraph_edge *e;
    4826        87104 :       ipa_predicate p;
    4827              : 
    4828        87104 :       index = streamer_read_uhwi (&ib);
    4829        87104 :       encoder = file_data->symtab_node_encoder;
    4830        87104 :       node = dyn_cast<cgraph_node *> (lto_symtab_encoder_deref (encoder,
    4831              :                                                                 index));
    4832        87104 :       info = node->prevailing_p () ? ipa_fn_summaries->get_create (node) : NULL;
    4833        87104 :       params_summary = node->prevailing_p ()
    4834        87104 :                        ? ipa_node_params_sum->get (node) : NULL;
    4835        87104 :       size_info = node->prevailing_p ()
    4836        87104 :                   ? ipa_size_summaries->get_create (node) : NULL;
    4837              : 
    4838        87104 :       int stack_size = streamer_read_uhwi (&ib);
    4839        87104 :       int size = streamer_read_uhwi (&ib);
    4840        87104 :       sreal time = sreal::stream_in (&ib);
    4841              : 
    4842        87104 :       if (info)
    4843              :         {
    4844        87046 :           info->estimated_stack_size
    4845        87046 :             = size_info->estimated_self_stack_size = stack_size;
    4846        87046 :           size_info->size = size_info->self_size = size;
    4847        87046 :           info->time = time;
    4848              :         }
    4849              : 
    4850        87104 :       bp = streamer_read_bitpack (&ib);
    4851        87104 :       if (info)
    4852              :         {
    4853        87046 :           info->inlinable = bp_unpack_value (&bp, 1);
    4854        87046 :           info->fp_expressions = bp_unpack_value (&bp, 1);
    4855        87046 :           if (!lto_stream_offload_p)
    4856        87046 :             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        87104 :       count2 = streamer_read_uhwi (&ib);
    4867        87104 :       gcc_assert (!info || !info->conds);
    4868        87046 :       if (info)
    4869        87046 :         vec_safe_reserve_exact (info->conds, count2);
    4870       165205 :       for (j = 0; j < count2; j++)
    4871              :         {
    4872        78101 :           struct condition c;
    4873        78101 :           unsigned int k, count3;
    4874        78101 :           c.operand_num = streamer_read_uhwi (&ib);
    4875        78101 :           c.code = (enum tree_code) streamer_read_uhwi (&ib);
    4876        78101 :           c.type = stream_read_tree (&ib, data_in);
    4877        78101 :           c.val = stream_read_tree (&ib, data_in);
    4878        78101 :           bp = streamer_read_bitpack (&ib);
    4879        78101 :           c.agg_contents = bp_unpack_value (&bp, 1);
    4880        78101 :           c.by_ref = bp_unpack_value (&bp, 1);
    4881        78101 :           if (c.agg_contents)
    4882        12554 :             c.offset = streamer_read_uhwi (&ib);
    4883        78101 :           count3 = streamer_read_uhwi (&ib);
    4884        78101 :           c.param_ops = NULL;
    4885        78101 :           if (info)
    4886        78101 :             vec_safe_reserve_exact (c.param_ops, count3);
    4887        78101 :           if (params_summary)
    4888        78101 :             ipa_set_param_used_by_ipa_predicates
    4889        78101 :                     (params_summary, c.operand_num, true);
    4890        81844 :           for (k = 0; k < count3; k++)
    4891              :             {
    4892         3743 :               struct expr_eval_op op;
    4893         3743 :               enum gimple_rhs_class rhs_class;
    4894         3743 :               op.code = (enum tree_code) streamer_read_uhwi (&ib);
    4895         3743 :               op.type = stream_read_tree (&ib, data_in);
    4896         3743 :               switch (rhs_class = get_gimple_rhs_class (op.code))
    4897              :                 {
    4898         1562 :                 case GIMPLE_UNARY_RHS:
    4899         1562 :                   op.index = 0;
    4900         1562 :                   op.val[0] = NULL_TREE;
    4901         1562 :                   op.val[1] = NULL_TREE;
    4902         1562 :                   break;
    4903              : 
    4904         2181 :                 case GIMPLE_BINARY_RHS:
    4905         2181 :                 case GIMPLE_TERNARY_RHS:
    4906         2181 :                   bp = streamer_read_bitpack (&ib);
    4907         2181 :                   op.index = bp_unpack_value (&bp, 2);
    4908         2181 :                   op.val[0] = stream_read_tree (&ib, data_in);
    4909         2181 :                   if (rhs_class == GIMPLE_BINARY_RHS)
    4910         2181 :                     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         3743 :               if (info)
    4920         3743 :                 c.param_ops->quick_push (op);
    4921              :             }
    4922        78101 :           if (info)
    4923        78101 :             info->conds->quick_push (c);
    4924              :         }
    4925        87104 :       count2 = streamer_read_uhwi (&ib);
    4926        87104 :       gcc_assert (!info || !info->size_time_table.length ());
    4927        87104 :       if (info && count2)
    4928        87046 :         info->size_time_table.reserve_exact (count2);
    4929       331102 :       for (j = 0; j < count2; j++)
    4930              :         {
    4931       243998 :           class size_time_entry e;
    4932              : 
    4933       243998 :           e.size = streamer_read_uhwi (&ib);
    4934       243998 :           e.time = sreal::stream_in (&ib);
    4935       243998 :           e.exec_predicate.stream_in (&ib);
    4936       243998 :           e.nonconst_predicate.stream_in (&ib);
    4937              : 
    4938       243998 :           if (info)
    4939       243882 :             info->size_time_table.quick_push (e);
    4940              :         }
    4941              : 
    4942        87104 :       count2 = streamer_read_uhwi (&ib);
    4943        88494 :       for (j = 0; j < count2; j++)
    4944              :         {
    4945         1390 :           p.stream_in (&ib);
    4946         1390 :           sreal fcp_freq = sreal::stream_in (&ib);
    4947         1390 :           if (info)
    4948              :             {
    4949         1390 :               ipa_freqcounting_predicate fcp;
    4950         1390 :               fcp.predicate = NULL;
    4951         1390 :               set_hint_predicate (&fcp.predicate, p);
    4952         1390 :               fcp.freq = fcp_freq;
    4953         1390 :               vec_safe_push (info->loop_iterations, fcp);
    4954              :             }
    4955              :         }
    4956        87104 :       count2 = streamer_read_uhwi (&ib);
    4957        87394 :       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        87104 :       count2 = streamer_read_uhwi (&ib);
    4971        87104 :       if (info && count2)
    4972            8 :         info->builtin_constant_p_parms.reserve_exact (count2);
    4973        87112 :       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       433981 :       for (e = node->callees; e; e = e->next_callee)
    4980       346877 :         read_ipa_call_summary (&ib, e, info != NULL);
    4981        88599 :       for (e = node->indirect_calls; e; e = e->next_callee)
    4982         1495 :         read_ipa_call_summary (&ib, e, info != NULL);
    4983              :     }
    4984              : 
    4985        13560 :   lto_free_section_data (file_data, LTO_section_ipa_fn_summary, NULL, data,
    4986              :                          len);
    4987        13560 :   lto_data_in_delete (data_in);
    4988        13560 : }
    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        12468 : ipa_fn_summary_read (void)
    4997              : {
    4998        12468 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    4999        12468 :   struct lto_file_decl_data *file_data;
    5000        12468 :   unsigned int j = 0;
    5001              : 
    5002        12468 :   ipa_prop_read_jump_functions ();
    5003        12468 :   ipa_fn_summary_alloc ();
    5004              : 
    5005        38496 :   while ((file_data = file_data_vec[j++]))
    5006              :     {
    5007        13560 :       size_t len;
    5008        13560 :       const char *data
    5009        13560 :         = lto_get_summary_section_data (file_data, LTO_section_ipa_fn_summary,
    5010              :                                         &len);
    5011        13560 :       if (data)
    5012        13560 :         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        12468 :   ipa_register_cgraph_hooks ();
    5021              : 
    5022        12468 :   gcc_assert (ipa_fn_summaries);
    5023        12468 :   ipa_fn_summaries->enable_insertion_hook ();
    5024        12468 : }
    5025              : 
    5026              : 
    5027              : /* Write inline summary for edge E to OB.  */
    5028              : 
    5029              : static void
    5030       380101 : write_ipa_call_summary (struct output_block *ob, struct cgraph_edge *e)
    5031              : {
    5032       380101 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
    5033       380101 :   int i;
    5034              : 
    5035       380101 :   streamer_write_uhwi (ob, es->call_stmt_size);
    5036       380101 :   streamer_write_uhwi (ob, es->call_stmt_time);
    5037       380101 :   streamer_write_uhwi (ob, es->loop_depth);
    5038              : 
    5039       380101 :   bitpack_d bp = bitpack_create (ob->main_stream);
    5040       380101 :   bp_pack_value (&bp, es->is_return_callee_uncaptured, 1);
    5041       380101 :   streamer_write_bitpack (&bp);
    5042              : 
    5043       380101 :   if (es->predicate)
    5044        10753 :     es->predicate->stream_out (ob);
    5045              :   else
    5046       369348 :     streamer_write_uhwi (ob, 0);
    5047       380101 :   streamer_write_uhwi (ob, es->param.length ());
    5048      2294106 :   for (i = 0; i < (int) es->param.length (); i++)
    5049              :     {
    5050       632482 :       streamer_write_uhwi (ob, es->param[i].change_prob);
    5051       632482 :       bp = bitpack_create (ob->main_stream);
    5052       632482 :       bp_pack_value (&bp, es->param[i].points_to_local_or_readonly_memory, 1);
    5053       632482 :       bp_pack_value (&bp, es->param[i].points_to_possible_sra_candidate, 1);
    5054       632482 :       streamer_write_bitpack (&bp);
    5055              :     }
    5056       380101 : }
    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        23539 : ipa_fn_summary_write (void)
    5065              : {
    5066        23539 :   struct output_block *ob = create_output_block (LTO_section_ipa_fn_summary);
    5067        23539 :   lto_symtab_encoder_iterator lsei;
    5068        23539 :   lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
    5069        23539 :   unsigned int count = 0;
    5070              : 
    5071       129746 :   for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
    5072       106207 :        lsei_next_function_in_partition (&lsei))
    5073              :     {
    5074       106207 :       cgraph_node *cnode = lsei_cgraph_node (lsei);
    5075       106207 :       if (cnode->definition && !cnode->alias)
    5076       103739 :         count++;
    5077              :     }
    5078        23539 :   streamer_write_uhwi (ob, count);
    5079              : 
    5080       129746 :   for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
    5081       106207 :        lsei_next_function_in_partition (&lsei))
    5082              :     {
    5083       106207 :       cgraph_node *cnode = lsei_cgraph_node (lsei);
    5084       106207 :       if (cnode->definition && !cnode->alias)
    5085              :         {
    5086       103739 :           class ipa_fn_summary *info = ipa_fn_summaries->get (cnode);
    5087       103739 :           class ipa_size_summary *size_info = ipa_size_summaries->get (cnode);
    5088       103739 :           struct bitpack_d bp;
    5089       103739 :           struct cgraph_edge *edge;
    5090       103739 :           int i;
    5091       103739 :           size_time_entry *e;
    5092       103739 :           struct condition *c;
    5093              : 
    5094       103739 :           streamer_write_uhwi (ob, lto_symtab_encoder_encode (encoder, cnode));
    5095       103739 :           streamer_write_hwi (ob, size_info->estimated_self_stack_size);
    5096       103739 :           streamer_write_hwi (ob, size_info->self_size);
    5097       103739 :           info->time.stream_out (ob);
    5098       103739 :           bp = bitpack_create (ob->main_stream);
    5099       103739 :           bp_pack_value (&bp, info->inlinable, 1);
    5100       103739 :           bp_pack_value (&bp, info->fp_expressions, 1);
    5101       103739 :           streamer_write_bitpack (&bp);
    5102       103739 :           if (!lto_stream_offload_p)
    5103       103739 :             streamer_write_uhwi (ob, info->target_info);
    5104       103739 :           streamer_write_uhwi (ob, vec_safe_length (info->conds));
    5105       301692 :           for (i = 0; vec_safe_iterate (info->conds, i, &c); i++)
    5106              :             {
    5107        94214 :               int j;
    5108        94214 :               struct expr_eval_op *op;
    5109              : 
    5110        94214 :               streamer_write_uhwi (ob, c->operand_num);
    5111        94214 :               streamer_write_uhwi (ob, c->code);
    5112        94214 :               stream_write_tree (ob, c->type, true);
    5113        94214 :               stream_write_tree (ob, c->val, true);
    5114        94214 :               bp = bitpack_create (ob->main_stream);
    5115        94214 :               bp_pack_value (&bp, c->agg_contents, 1);
    5116        94214 :               bp_pack_value (&bp, c->by_ref, 1);
    5117        94214 :               streamer_write_bitpack (&bp);
    5118        94214 :               if (c->agg_contents)
    5119        15813 :                 streamer_write_uhwi (ob, c->offset);
    5120        94214 :               streamer_write_uhwi (ob, vec_safe_length (c->param_ops));
    5121       195894 :               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         2579 :                       bp = bitpack_create (ob->main_stream);
    5128         2579 :                       bp_pack_value (&bp, op->index, 2);
    5129         2579 :                       streamer_write_bitpack (&bp);
    5130         2579 :                       stream_write_tree (ob, op->val[0], true);
    5131         2579 :                       if (op->val[1])
    5132            4 :                         stream_write_tree (ob, op->val[1], true);
    5133              :                     }
    5134              :                 }
    5135              :             }
    5136       103739 :           streamer_write_uhwi (ob, info->size_time_table.length ());
    5137       501773 :           for (i = 0; info->size_time_table.iterate (i, &e); i++)
    5138              :             {
    5139       294295 :               streamer_write_uhwi (ob, e->size);
    5140       294295 :               e->time.stream_out (ob);
    5141       294295 :               e->exec_predicate.stream_out (ob);
    5142       294295 :               e->nonconst_predicate.stream_out (ob);
    5143              :             }
    5144       103739 :           ipa_freqcounting_predicate *fcp;
    5145       103739 :           streamer_write_uhwi (ob, vec_safe_length (info->loop_iterations));
    5146       209515 :           for (i = 0; vec_safe_iterate (info->loop_iterations, i, &fcp); i++)
    5147              :             {
    5148         2037 :               fcp->predicate->stream_out (ob);
    5149         2037 :               fcp->freq.stream_out (ob);
    5150              :             }
    5151       103739 :           streamer_write_uhwi (ob, vec_safe_length (info->loop_strides));
    5152       207824 :           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       103739 :           streamer_write_uhwi (ob, info->builtin_constant_p_parms.length ());
    5158       103739 :           int ip;
    5159       207494 :           for (i = 0; info->builtin_constant_p_parms.iterate (i, &ip);
    5160              :                i++)
    5161           16 :             streamer_write_uhwi (ob, ip);
    5162       481137 :           for (edge = cnode->callees; edge; edge = edge->next_callee)
    5163       377398 :             write_ipa_call_summary (ob, edge);
    5164       106442 :           for (edge = cnode->indirect_calls; edge; edge = edge->next_callee)
    5165         2703 :             write_ipa_call_summary (ob, edge);
    5166              :         }
    5167              :     }
    5168        23539 :   streamer_write_char_stream (ob->main_stream, 0);
    5169        23539 :   produce_asm (ob);
    5170        23539 :   destroy_output_block (ob);
    5171              : 
    5172        23539 :   ipa_prop_write_jump_functions ();
    5173        23539 : }
    5174              : 
    5175              : 
    5176              : /* Release function summary.  */
    5177              : 
    5178              : void
    5179       739834 : ipa_free_fn_summary (void)
    5180              : {
    5181       739834 :   if (!ipa_call_summaries)
    5182              :     return;
    5183       468116 :   ggc_delete (ipa_fn_summaries);
    5184       468116 :   ipa_fn_summaries = NULL;
    5185       468116 :   delete ipa_call_summaries;
    5186       468116 :   ipa_call_summaries = NULL;
    5187       468116 :   edge_predicate_pool.release ();
    5188              :   /* During IPA this is one of largest datastructures to release.  */
    5189       468116 :   if (flag_wpa)
    5190         7948 :     ggc_trim ();
    5191              : }
    5192              : 
    5193              : /* Release function summary.  */
    5194              : 
    5195              : void
    5196       739834 : ipa_free_size_summary (void)
    5197              : {
    5198       739834 :   if (!ipa_size_summaries)
    5199              :     return;
    5200       468116 :   delete ipa_size_summaries;
    5201       468116 :   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       589174 :   pass_local_fn_summary (gcc::context *ctxt)
    5223      1178348 :     : gimple_opt_pass (pass_data_local_fn_summary, ctxt)
    5224              :   {}
    5225              : 
    5226              :   /* opt_pass methods: */
    5227       294587 :   opt_pass * clone () final override
    5228              :   {
    5229       294587 :     return new pass_local_fn_summary (m_ctxt);
    5230              :   }
    5231      6002610 :   unsigned int execute (function *) final override
    5232              :     {
    5233      6002610 :       return compute_fn_summary_for_current ();
    5234              :     }
    5235              : 
    5236              : }; // class pass_local_fn_summary
    5237              : 
    5238              : } // anon namespace
    5239              : 
    5240              : gimple_opt_pass *
    5241       294587 : make_pass_local_fn_summary (gcc::context *ctxt)
    5242              : {
    5243       294587 :   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       589174 :   pass_ipa_free_fn_summary (gcc::context *ctxt)
    5268              :     : simple_ipa_opt_pass (pass_data_ipa_free_fn_summary, ctxt),
    5269      1178348 :       small_p (false)
    5270              :   {}
    5271              : 
    5272              :   /* opt_pass methods: */
    5273       294587 :   opt_pass *clone () final override
    5274              :   {
    5275       294587 :     return new pass_ipa_free_fn_summary (m_ctxt);
    5276              :   }
    5277       589174 :   void set_pass_param (unsigned int n, bool param) final override
    5278              :     {
    5279       589174 :       gcc_assert (n == 0);
    5280       589174 :       small_p = param;
    5281       589174 :     }
    5282       495204 :   bool gate (function *) final override { return true; }
    5283       474393 :   unsigned int execute (function *) final override
    5284              :     {
    5285       474393 :       ipa_free_fn_summary ();
    5286              :       /* Free ipa-prop structures if they are no longer needed.  */
    5287       474393 :       ipa_free_all_structures_after_iinln ();
    5288       474393 :       if (!flag_wpa)
    5289       466445 :         ipa_free_size_summary ();
    5290       474393 :       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       294587 : make_pass_ipa_free_fn_summary (gcc::context *ctxt)
    5301              : {
    5302       294587 :   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       294587 :   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       294587 :                       NULL) /* variable_transform */
    5334       294587 :   {}
    5335              : 
    5336              :   /* opt_pass methods: */
    5337       237284 :   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       294587 : make_pass_ipa_fn_summary (gcc::context *ctxt)
    5345              : {
    5346       294587 :   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       264541 : ipa_fnsummary_cc_finalize (void)
    5354              : {
    5355       264541 :   ipa_free_fn_summary ();
    5356       264541 :   ipa_free_size_summary ();
    5357       264541 : }
        

Generated by: LCOV version 2.4-beta

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