LCOV - code coverage report
Current view: top level - gcc - ipa-fnsummary.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.4 % 2672 2576
Test Date: 2026-02-28 14:20:25 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    133990719 : 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    133990719 :   size_time_entry *e;
     173    133990719 :   bool found = false;
     174    133990719 :   int i;
     175    133990719 :   ipa_predicate nonconst_pred;
     176    133990719 :   vec<size_time_entry> *table = call ? &call_size_time_table : &size_time_table;
     177              : 
     178    133990719 :   if (exec_pred == false)
     179      4641684 :     return;
     180              : 
     181    133735149 :   nonconst_pred = nonconst_pred_in & exec_pred;
     182              : 
     183    133735149 :   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    156386572 :   if (!size && time == 0 && table->length ())
     189      3676285 :     return;
     190              : 
     191              :   /* Only for calls we are unaccounting what we previously recorded.  */
     192    129349035 :   gcc_checking_assert (time >= 0 || call);
     193              : 
     194    471510728 :   for (i = 0; table->iterate (i, &e); i++)
     195    442405979 :     if (e->exec_predicate == exec_pred
     196    442405979 :         && e->nonconst_predicate == nonconst_pred)
     197              :       {
     198              :         found = true;
     199              :         break;
     200              :       }
     201    129349035 :   if (i == max_size_time_table_size)
     202              :     {
     203            0 :       i = 0;
     204            0 :       found = true;
     205            0 :       e = &(*table)[0];
     206            0 :       if (dump_file && (dump_flags & TDF_DETAILS))
     207            0 :         fprintf (dump_file,
     208              :                  "\t\tReached limit on number of entries, "
     209              :                  "ignoring the predicate.");
     210              :     }
     211    129353309 :   if (dump_file && (dump_flags & TDF_DETAILS) && (time != 0 || size))
     212              :     {
     213         3997 :       fprintf (dump_file,
     214              :                "\t\tAccounting size:%3.2f, time:%3.2f on %spredicate exec:",
     215         3766 :                ((double) size) / ipa_fn_summary::size_scale,
     216              :                (time.to_double ()), found ? "" : "new ");
     217         3766 :       exec_pred.dump (dump_file, conds, 0);
     218         3766 :       if (exec_pred != nonconst_pred)
     219              :         {
     220           84 :           fprintf (dump_file, " nonconst:");
     221           84 :           nonconst_pred.dump (dump_file, conds);
     222              :         }
     223              :       else
     224         3682 :         fprintf (dump_file, "\n");
     225              :     }
     226    129349035 :   if (!found)
     227              :     {
     228     29104749 :       class size_time_entry new_entry;
     229     29104749 :       new_entry.size = size;
     230     29104749 :       new_entry.time = time;
     231     29104749 :       new_entry.exec_predicate = exec_pred;
     232     29104749 :       new_entry.nonconst_predicate = nonconst_pred;
     233     29104749 :       if (call)
     234      1334738 :         call_size_time_table.safe_push (new_entry);
     235              :       else
     236     27770011 :         size_time_table.safe_push (new_entry);
     237              :     }
     238              :   else
     239              :     {
     240    100244286 :       e->size += size;
     241    100244286 :       e->time += time;
     242              :       /* FIXME: PR bootstrap/92653 gcc_checking_assert (e->time >= -1); */
     243              :       /* Tolerate small roundoff issues.  */
     244    100244286 :       if (e->time < 0)
     245          109 :         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       270618 : redirect_to_unreachable (struct cgraph_edge *e)
     253              : {
     254       270618 :   struct cgraph_node *callee = !e->inline_failed ? e->callee : NULL;
     255       270618 :   struct cgraph_node *target
     256       270618 :     = cgraph_node::get_create (builtin_decl_unreachable ());
     257              : 
     258       270618 :   gcc_checking_assert (lookup_attribute ("cold",
     259              :                                          DECL_ATTRIBUTES (target->decl)));
     260              : 
     261       270618 :   if (e->speculative)
     262          314 :     e = cgraph_edge::resolve_speculation (e, target->decl);
     263       270304 :   else if (!e->callee)
     264          762 :     e = cgraph_edge::make_direct (e, target);
     265              :   else
     266       269542 :     e->redirect_callee (target);
     267       270618 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
     268       270618 :   e->inline_failed = CIF_UNREACHABLE;
     269       270618 :   e->count = profile_count::zero ();
     270       270618 :   es->call_stmt_size = 0;
     271       270618 :   es->call_stmt_time = 0;
     272       270618 :   if (callee)
     273            0 :     callee->remove_symbol_and_inline_clones ();
     274       270618 :   if (e->has_callback)
     275            4 :     for (cgraph_edge *cbe = e->first_callback_edge (); cbe;
     276            1 :          cbe = cbe->next_callback_edge ())
     277              :       /* If the carrying edge is unreachable, so are the callback calls.  */
     278            1 :       redirect_to_unreachable (cbe);
     279       270618 :   return e;
     280              : }
     281              : 
     282              : /* Set predicate for edge E.  */
     283              : 
     284              : static void
     285     30318633 : 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     27726652 :   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     30589326 :       && (!e->speculative || e->callee))
     295       270617 :     e = redirect_to_unreachable (e);
     296              : 
     297     30318633 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
     298     58045285 :   if (predicate && *predicate != true)
     299              :     {
     300      4526697 :       if (!es->predicate)
     301      4056274 :         es->predicate = edge_predicate_pool.allocate ();
     302      4526697 :       *es->predicate = *predicate;
     303              :     }
     304              :   else
     305              :     {
     306     25791936 :       if (es->predicate)
     307       776396 :         edge_predicate_pool.remove (es->predicate);
     308     25791936 :       es->predicate = NULL;
     309              :     }
     310     30318633 : }
     311              : 
     312              : /* Set predicate for hint *P.  */
     313              : 
     314              : static void
     315       148519 : set_hint_predicate (ipa_predicate **p, ipa_predicate new_predicate)
     316              : {
     317       148519 :   if (new_predicate == false || new_predicate == true)
     318              :     {
     319         3015 :       if (*p)
     320            0 :         edge_predicate_pool.remove (*p);
     321         3015 :       *p = NULL;
     322              :     }
     323              :   else
     324              :     {
     325       145504 :       if (!*p)
     326       145504 :         *p = edge_predicate_pool.allocate ();
     327       145504 :       **p = new_predicate;
     328              :     }
     329       148519 : }
     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      1108128 : 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      1108128 :   if (new_predicate == false || new_predicate == true)
     342              :     return;
     343              :   ipa_freqcounting_predicate *f;
     344       140120 :   for (int i = 0; vec_safe_iterate (*v, i, &f); i++)
     345        71590 :     if (new_predicate == f->predicate)
     346              :       {
     347            0 :         f->freq += add_freq;
     348            0 :         return;
     349              :       }
     350        94384 :   if (vec_safe_length (*v) >= max_num_predicates)
     351              :     /* Too many different predicates to account for.  */
     352              :     return;
     353              : 
     354        68258 :   ipa_freqcounting_predicate fcp;
     355        68258 :   fcp.predicate = NULL;
     356        68258 :   set_hint_predicate (&fcp.predicate, new_predicate);
     357        68258 :   fcp.freq = add_freq;
     358        68258 :   vec_safe_push (*v, fcp);
     359        68258 :   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     21746886 : 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     21746886 :   clause_t clause = inline_p ? 0 : 1 << ipa_predicate::not_inlined_condition;
     388     21746886 :   clause_t nonspec_clause = 1 << ipa_predicate::not_inlined_condition;
     389     21746886 :   class ipa_fn_summary *info = ipa_fn_summaries->get (node);
     390     21746886 :   int i;
     391     21746886 :   struct condition *c;
     392              : 
     393     90561795 :   for (i = 0; vec_safe_iterate (info->conds, i, &c); i++)
     394              :     {
     395     68814909 :       tree val = NULL;
     396     68814909 :       tree res;
     397     68814909 :       int j;
     398     68814909 :       struct expr_eval_op *op;
     399              : 
     400     68814909 :       if (c->code == ipa_predicate::not_sra_candidate)
     401              :         {
     402     16080005 :           if (!inline_p
     403     16080005 :               || !es
     404     15984159 :               || (int)es->param.length () <= c->operand_num
     405     24072053 :               || !es->param[c->operand_num].points_to_possible_sra_candidate)
     406     12049560 :             clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     407     16080005 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     408     68814909 :           continue;
     409              :         }
     410              : 
     411     52734904 :       if (c->agg_contents)
     412              :         {
     413     28399738 :           if (c->code == ipa_predicate::changed
     414     18108773 :               && !c->by_ref
     415     30825336 :               && (avals->safe_sval_at(c->operand_num) == error_mark_node))
     416         5208 :             continue;
     417              : 
     418     28389322 :           if (tree sval = avals->safe_sval_at (c->operand_num))
     419     13242138 :             val = ipa_find_agg_cst_from_init (sval, c->offset, c->by_ref);
     420     13242138 :           if (!val)
     421              :             {
     422     28381794 :               ipa_argagg_value_list avs (avals);
     423     28381794 :               val = avs.get_value (c->operand_num, c->offset / BITS_PER_UNIT,
     424     28381794 :                                    c->by_ref);
     425              :             }
     426              :         }
     427              :       else
     428              :         {
     429     24340374 :           val = avals->safe_sval_at (c->operand_num);
     430     24340374 :           if (val && val == error_mark_node
     431      2239734 :               && c->code != ipa_predicate::changed)
     432              :             val = NULL_TREE;
     433              :         }
     434              : 
     435     40114237 :       if (!val
     436     39348779 :           && (c->code == ipa_predicate::changed
     437              :               || c->code == ipa_predicate::is_not_constant))
     438              :         {
     439     24834244 :           clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     440     24834244 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     441     24834244 :           continue;
     442              :         }
     443     27895452 :       if (c->code == ipa_predicate::changed)
     444              :         {
     445      7448452 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     446      7448452 :           continue;
     447              :         }
     448              : 
     449     20447000 :       if (c->code == ipa_predicate::is_not_constant)
     450              :         {
     451         2984 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     452         2984 :           continue;
     453              :         }
     454              : 
     455     20444016 :       if (val && TYPE_SIZE (c->type) == TYPE_SIZE (TREE_TYPE (val)))
     456              :         {
     457      5884411 :           if (c->type != TREE_TYPE (val))
     458      1187810 :             val = fold_unary (VIEW_CONVERT_EXPR, c->type, val);
     459      6253959 :           for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
     460              :             {
     461       369990 :               if (!val)
     462              :                 break;
     463       369548 :               if (!op->val[0])
     464       122030 :                 val = fold_unary (op->code, op->type, val);
     465       247518 :               else if (!op->val[1])
     466       495036 :                 val = fold_binary (op->code, op->type,
     467              :                                    op->index ? op->val[0] : val,
     468              :                                    op->index ? val : op->val[0]);
     469            0 :               else if (op->index == 0)
     470            0 :                 val = fold_ternary (op->code, op->type,
     471              :                                     val, op->val[0], op->val[1]);
     472            0 :               else if (op->index == 1)
     473            0 :                 val = fold_ternary (op->code, op->type,
     474              :                                     op->val[0], val, op->val[1]);
     475            0 :               else if (op->index == 2)
     476            0 :                 val = fold_ternary (op->code, op->type,
     477              :                                     op->val[0], op->val[1], val);
     478              :               else
     479              :                 val = NULL_TREE;
     480              :             }
     481              : 
     482      5884411 :           res = val
     483      5884411 :             ? fold_binary_to_constant (c->code, boolean_type_node, val, c->val)
     484              :             : NULL;
     485              : 
     486      5883949 :           if (res && integer_zerop (res))
     487      3046883 :             continue;
     488      2837528 :           if (res && integer_onep (res))
     489              :             {
     490      2814888 :               clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     491      2814888 :               nonspec_clause
     492      2814888 :                 |= 1 << (i + ipa_predicate::first_dynamic_condition);
     493      2814888 :               continue;
     494              :             }
     495              :         }
     496     14582245 :       if (c->operand_num < (int) avals->m_known_value_ranges.length ()
     497      8427860 :           && !c->agg_contents
     498     16694654 :           && (!val || TREE_CODE (val) != INTEGER_CST))
     499              :         {
     500      2112323 :           value_range vr (avals->m_known_value_ranges[c->operand_num]);
     501      2112323 :           if (!vr.undefined_p ()
     502      1247142 :               && !vr.varying_p ()
     503      3359465 :               && (TYPE_SIZE (c->type) == TYPE_SIZE (vr.type ())))
     504              :             {
     505      1246437 :               if (!useless_type_conversion_p (c->type, vr.type ()))
     506          853 :                 range_cast (vr, c->type);
     507              : 
     508      1555819 :               for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
     509              :                 {
     510       347384 :                   if (vr.varying_p () || vr.undefined_p ())
     511              :                     break;
     512              : 
     513       309382 :                   value_range res (op->type);
     514       309382 :                   if (!op->val[0])
     515              :                     {
     516       112693 :                       value_range varying (op->type);
     517       112693 :                       varying.set_varying (op->type);
     518       112693 :                       range_op_handler handler (op->code);
     519       112693 :                       if (!handler
     520       112693 :                           || !res.supports_type_p (op->type)
     521       225386 :                           || !handler.fold_range (res, op->type, vr, varying))
     522            0 :                         res.set_varying (op->type);
     523       112693 :                     }
     524       196689 :                   else if (!op->val[1])
     525              :                     {
     526       196517 :                       value_range op0 (TREE_TYPE (op->val[0]));
     527       196517 :                       range_op_handler handler (op->code);
     528              : 
     529       196517 :                       ipa_get_range_from_ip_invariant (op0, op->val[0], node);
     530              : 
     531       196517 :                       if (!handler
     532       196517 :                           || !res.supports_type_p (op->type)
     533       393034 :                           || !handler.fold_range (res, op->type,
     534       196517 :                                                   op->index ? op0 : vr,
     535       392468 :                                                   op->index ? vr : op0))
     536            0 :                         res.set_varying (op->type);
     537       196517 :                     }
     538              :                   else
     539          172 :                     res.set_varying (op->type);
     540       309382 :                   vr = res;
     541       309382 :                 }
     542      1246437 :               if (!vr.varying_p () && !vr.undefined_p ())
     543              :                 {
     544      1198622 :                   int_range<2> res;
     545      1198622 :                   value_range val_vr (TREE_TYPE (c->val));
     546      1198622 :                   range_op_handler handler (c->code);
     547              : 
     548      1198622 :                   ipa_get_range_from_ip_invariant (val_vr, c->val, node);
     549              : 
     550      1198622 :                   if (!handler
     551      1198622 :                       || !val_vr.supports_type_p (TREE_TYPE (c->val))
     552      2397244 :                       || !handler.fold_range (res, boolean_type_node, vr, val_vr))
     553            0 :                     res.set_varying (boolean_type_node);
     554              : 
     555      1198622 :                   if (res.zero_p ())
     556       206056 :                     continue;
     557      1198622 :                 }
     558              :             }
     559      2112323 :         }
     560              : 
     561     14376189 :       clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     562     14376189 :       nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     563              :     }
     564     21746886 :   *ret_clause = clause;
     565     21746886 :   if (ret_nonspec_clause)
     566     18897251 :     *ret_nonspec_clause = nonspec_clause;
     567     21746886 : }
     568              : 
     569              : /* Return true if VRP will be exectued on the function.
     570              :    We do not want to anticipate optimizations that will not happen.
     571              : 
     572              :    FIXME: This can be confused with -fdisable and debug counters and thus
     573              :    it should not be used for correctness (only to make heuristics work).
     574              :    This means that inliner should do its own optimizations of expressions
     575              :    that it predicts to be constant so wrong code can not be triggered by
     576              :    builtin_constant_p.  */
     577              : 
     578              : static bool
     579     11798914 : vrp_will_run_p (struct cgraph_node *node)
     580              : {
     581     11798914 :   return (opt_for_fn (node->decl, optimize)
     582     11798914 :           && !opt_for_fn (node->decl, optimize_debug)
     583     23596611 :           && opt_for_fn (node->decl, flag_tree_vrp));
     584              : }
     585              : 
     586              : /* Similarly about FRE.  */
     587              : 
     588              : static bool
     589     14114895 : fre_will_run_p (struct cgraph_node *node)
     590              : {
     591     14114895 :   return (opt_for_fn (node->decl, optimize)
     592     14114895 :           && !opt_for_fn (node->decl, optimize_debug)
     593     28227509 :           && opt_for_fn (node->decl, flag_tree_fre));
     594              : }
     595              : 
     596              : /* Work out what conditions might be true at invocation of E.
     597              :    Compute costs for inlined edge if INLINE_P is true.
     598              : 
     599              :    Return in CLAUSE_PTR the evaluated conditions and in NONSPEC_CLAUSE_PTR
     600              :    (if non-NULL) conditions evaluated for nonspecialized clone called
     601              :    in a given context.
     602              : 
     603              :    Vectors in AVALS will be populated with useful known information about
     604              :    argument values - information not known to have any uses will be omitted -
     605              :    except for m_known_contexts which will only be calculated if
     606              :    COMPUTE_CONTEXTS is true.  */
     607              : 
     608              : void
     609     21449828 : evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
     610              :                               clause_t *clause_ptr,
     611              :                               clause_t *nonspec_clause_ptr,
     612              :                               ipa_auto_call_arg_values *avals,
     613              :                               bool compute_contexts)
     614              : {
     615     21449828 :   struct cgraph_node *callee = e->callee->ultimate_alias_target ();
     616     21449828 :   class ipa_fn_summary *info = ipa_fn_summaries->get (callee);
     617     21449828 :   class ipa_edge_args *args;
     618     21449828 :   class ipa_call_summary *es = NULL;
     619              : 
     620     21449828 :   if (clause_ptr)
     621     21449828 :     *clause_ptr = inline_p ? 0 : 1 << ipa_predicate::not_inlined_condition;
     622              : 
     623     21449828 :   if (ipa_node_params_sum
     624      9795010 :       && !e->call_stmt_cannot_inline_p
     625      9795010 :       && (info->conds || compute_contexts)
     626     31244838 :       && (args = ipa_edge_args_sum->get (e)) != NULL)
     627              :     {
     628      9740594 :       struct cgraph_node *caller;
     629      9740594 :       class ipa_node_params *caller_parms_info, *callee_pi = NULL;
     630      9740594 :       int i, count = ipa_get_cs_argument_count (args);
     631      9740594 :       es = ipa_call_summaries->get (e);
     632              : 
     633      9740594 :       if (count)
     634              :         {
     635      9056751 :           if (e->caller->inlined_to)
     636              :             caller = e->caller->inlined_to;
     637              :           else
     638      7370116 :             caller = e->caller;
     639      9056751 :           caller_parms_info = ipa_node_params_sum->get (caller);
     640      9056751 :           callee_pi = ipa_node_params_sum->get (callee);
     641              : 
     642              :           /* Watch for thunks.  */
     643      9056751 :           if (callee_pi)
     644              :             /* Watch for variadic functions.  */
     645      9056410 :             count = MIN (count, ipa_get_param_count (callee_pi));
     646              :         }
     647              : 
     648      9056410 :       if (callee_pi)
     649     29773389 :         for (i = 0; i < count; i++)
     650              :           {
     651     20716979 :             struct ipa_jump_func *jf = ipa_get_ith_jump_func (args, i);
     652              : 
     653     20716979 :             if (ipa_is_param_used_by_indirect_call (callee_pi, i)
     654     20716979 :                 || ipa_is_param_used_by_ipa_predicates (callee_pi, i))
     655              :               {
     656              :                 /* Determine if we know constant value of the parameter.  */
     657     14114895 :                 tree type = ipa_get_type (callee_pi, i);
     658     14114895 :                 tree cst = ipa_value_from_jfunc (caller_parms_info, jf, type);
     659              : 
     660     10972516 :                 if (!cst && e->call_stmt
     661     25037823 :                     && i < (int)gimple_call_num_args (e->call_stmt))
     662              :                   {
     663     10922928 :                     cst = gimple_call_arg (e->call_stmt, i);
     664     10922928 :                     if (!is_gimple_min_invariant (cst))
     665              :                       cst = NULL;
     666              :                   }
     667      3368676 :                 if (cst)
     668              :                   {
     669      3319088 :                     gcc_checking_assert (TREE_CODE (cst) != TREE_BINFO);
     670      3319088 :                     if (!avals->m_known_vals.length ())
     671      1778745 :                       avals->m_known_vals.safe_grow_cleared (count, true);
     672      3319088 :                     avals->m_known_vals[i] = cst;
     673              :                   }
     674     10795807 :                 else if (inline_p && !es->param[i].change_prob)
     675              :                   {
     676      4080341 :                     if (!avals->m_known_vals.length ())
     677      3388256 :                       avals->m_known_vals.safe_grow_cleared (count, true);
     678      4080341 :                     avals->m_known_vals[i] = error_mark_node;
     679              :                   }
     680              : 
     681              :                 /* If we failed to get simple constant, try value range.  */
     682      3319088 :                 if ((!cst || TREE_CODE (cst) != INTEGER_CST)
     683     11798914 :                     && vrp_will_run_p (caller)
     684     25752121 :                     && ipa_is_param_used_by_ipa_predicates (callee_pi, i))
     685              :                   {
     686     11596886 :                     value_range vr (type);
     687              : 
     688     11596886 :                     ipa_value_range_from_jfunc (vr, caller_parms_info, e, jf, type);
     689     11596886 :                     if (!vr.undefined_p () && !vr.varying_p ())
     690              :                       {
     691      8214141 :                         if (!avals->m_known_value_ranges.length ())
     692              :                           {
     693      5908751 :                             avals->m_known_value_ranges.safe_grow_cleared (count,
     694              :                                                                            true);
     695     18828899 :                             for (int i = 0; i < count; ++i)
     696     12920148 :                               avals->m_known_value_ranges[i].set_type (void_type_node);
     697              :                           }
     698      8214141 :                         avals->m_known_value_ranges[i] = vr;
     699              :                       }
     700     11596886 :                   }
     701              : 
     702              :                 /* Determine known aggregate values.  */
     703     14114895 :                 if (fre_will_run_p (caller))
     704     14112210 :                   ipa_push_agg_values_from_jfunc (caller_parms_info,
     705              :                                                   caller, &jf->agg, i,
     706              :                                                   &avals->m_known_aggs);
     707              :               }
     708              : 
     709              :             /* For calls used in polymorphic calls we further determine
     710              :                polymorphic call context.  */
     711     20716979 :             if (compute_contexts
     712     20716979 :                 && ipa_is_param_used_by_polymorphic_call (callee_pi, i))
     713              :               {
     714       157296 :                 ipa_polymorphic_call_context
     715       157296 :                    ctx = ipa_context_from_jfunc (caller_parms_info, e, i, jf);
     716       314592 :                 if (!ctx.useless_p ())
     717              :                   {
     718       155348 :                     if (!avals->m_known_contexts.length ())
     719       155211 :                       avals->m_known_contexts.safe_grow_cleared (count, true);
     720       155348 :                     avals->m_known_contexts[i]
     721       310696 :                       = ipa_context_from_jfunc (caller_parms_info, e, i, jf);
     722              :                   }
     723              :                }
     724              :           }
     725              :         else
     726       684184 :           gcc_assert (!count || callee->thunk);
     727              :     }
     728     11709234 :   else if (e->call_stmt && !e->call_stmt_cannot_inline_p && info->conds)
     729              :     {
     730      9173787 :       int i, count = (int)gimple_call_num_args (e->call_stmt);
     731              : 
     732     26092358 :       for (i = 0; i < count; i++)
     733              :         {
     734     16918571 :           tree cst = gimple_call_arg (e->call_stmt, i);
     735     16918571 :           if (!is_gimple_min_invariant (cst))
     736              :             cst = NULL;
     737      6002064 :           if (cst)
     738              :             {
     739      6002064 :               if (!avals->m_known_vals.length ())
     740      4146087 :                 avals->m_known_vals.safe_grow_cleared (count, true);
     741      6002064 :               avals->m_known_vals[i] = cst;
     742              :             }
     743              :         }
     744              :     }
     745              : 
     746     21449828 :   evaluate_conditions_for_known_args (callee, inline_p, avals, clause_ptr,
     747              :                                       nonspec_clause_ptr, es);
     748     21449828 : }
     749              : 
     750              : 
     751              : /* Allocate the function summary. */
     752              : 
     753              : static void
     754       454060 : ipa_fn_summary_alloc (void)
     755              : {
     756       454060 :   gcc_checking_assert (!ipa_fn_summaries);
     757       454060 :   ipa_size_summaries = new ipa_size_summary_t (symtab);
     758       454060 :   ipa_fn_summaries = ipa_fn_summary_t::create_ggc (symtab);
     759       454060 :   ipa_call_summaries = new ipa_call_summary_t (symtab);
     760       454060 : }
     761              : 
     762     26701302 : ipa_call_summary::~ipa_call_summary ()
     763              : {
     764     26701302 :   if (predicate)
     765      3279878 :     edge_predicate_pool.remove (predicate);
     766              : 
     767     26701302 :   param.release ();
     768     26701302 : }
     769              : 
     770      9837558 : ipa_fn_summary::~ipa_fn_summary ()
     771              : {
     772      9837558 :   unsigned len = vec_safe_length (loop_iterations);
     773      9949716 :   for (unsigned i = 0; i < len; i++)
     774       112158 :     edge_predicate_pool.remove ((*loop_iterations)[i].predicate);
     775      9837558 :   len = vec_safe_length (loop_strides);
     776      9870904 :   for (unsigned i = 0; i < len; i++)
     777        33346 :     edge_predicate_pool.remove ((*loop_strides)[i].predicate);
     778      9837558 :   vec_free (conds);
     779      9837558 :   call_size_time_table.release ();
     780      9837558 :   vec_free (loop_iterations);
     781      9837558 :   vec_free (loop_strides);
     782      9837558 :   builtin_constant_p_parms.release ();
     783      9837558 : }
     784              : 
     785              : void
     786      7126596 : ipa_fn_summary_t::remove_callees (cgraph_node *node)
     787              : {
     788      7126596 :   cgraph_edge *e;
     789     29332790 :   for (e = node->callees; e; e = e->next_callee)
     790     22206194 :     ipa_call_summaries->remove (e);
     791      7607204 :   for (e = node->indirect_calls; e; e = e->next_callee)
     792       480608 :     ipa_call_summaries->remove (e);
     793      7126596 : }
     794              : 
     795              : /* Duplicate predicates in loop hint vector, allocating memory for them and
     796              :    remove and deallocate any uninteresting (true or false) ones.  Return the
     797              :    result.  */
     798              : 
     799              : static vec<ipa_freqcounting_predicate, va_gc> *
     800        29388 : remap_freqcounting_preds_after_dup (vec<ipa_freqcounting_predicate, va_gc> *v,
     801              :                                     clause_t possible_truths)
     802              : {
     803        29388 :   if (vec_safe_length (v) == 0)
     804              :     return NULL;
     805              : 
     806         4715 :   vec<ipa_freqcounting_predicate, va_gc> *res = v->copy ();
     807         4715 :   int len = res->length();
     808        11077 :   for (int i = len - 1; i >= 0; i--)
     809              :     {
     810         6362 :       ipa_predicate new_predicate
     811         6362 :         = (*res)[i].predicate->remap_after_duplication (possible_truths);
     812              :       /* We do not want to free previous predicate; it is used by node
     813              :          origin.  */
     814         6362 :       (*res)[i].predicate = NULL;
     815         6362 :       set_hint_predicate (&(*res)[i].predicate, new_predicate);
     816              : 
     817         6362 :       if (!(*res)[i].predicate)
     818         3015 :         res->unordered_remove (i);
     819              :     }
     820              : 
     821              :   return res;
     822              : }
     823              : 
     824              : 
     825              : /* Hook that is called by cgraph.cc when a node is duplicated.  */
     826              : void
     827      2624050 : ipa_fn_summary_t::duplicate (cgraph_node *src,
     828              :                              cgraph_node *dst,
     829              :                              ipa_fn_summary *src_info,
     830              :                              ipa_fn_summary *info)
     831              : {
     832      2624050 :   new (info) ipa_fn_summary (*src_info);
     833              :   /* TODO: as an optimization, we may avoid copying conditions
     834              :      that are known to be false or true.  */
     835      2624050 :   info->conds = vec_safe_copy (info->conds);
     836              : 
     837      2624050 :   clone_info *cinfo = clone_info::get (dst);
     838              :   /* When there are any replacements in the function body, see if we can figure
     839              :      out that something was optimized out.  */
     840      2624050 :   if (ipa_node_params_sum && cinfo && cinfo->tree_map)
     841              :     {
     842              :       /* Use SRC parm info since it may not be copied yet.  */
     843        14694 :       ipa_node_params *parms_info = ipa_node_params_sum->get (src);
     844        14694 :       ipa_auto_call_arg_values avals;
     845        14694 :       int count = ipa_get_param_count (parms_info);
     846        14694 :       int i, j;
     847        14694 :       clause_t possible_truths;
     848        14694 :       ipa_predicate true_pred = true;
     849        14694 :       size_time_entry *e;
     850        14694 :       int optimized_out_size = 0;
     851        14694 :       bool inlined_to_p = false;
     852        14694 :       struct cgraph_edge *edge, *next;
     853              : 
     854        14694 :       info->size_time_table.release ();
     855        14694 :       avals.m_known_vals.safe_grow_cleared (count, true);
     856        59972 :       for (i = 0; i < count; i++)
     857              :         {
     858              :           struct ipa_replace_map *r;
     859              : 
     860       148848 :           for (j = 0; vec_safe_iterate (cinfo->tree_map, j, &r); j++)
     861              :             {
     862        83926 :               if (r->parm_num == i)
     863              :                 {
     864        25634 :                   avals.m_known_vals[i] = r->new_tree;
     865        25634 :                   break;
     866              :                 }
     867              :             }
     868              :         }
     869        14694 :       evaluate_conditions_for_known_args (dst, false,
     870              :                                           &avals,
     871              :                                           &possible_truths,
     872              :                                           /* We are going to specialize,
     873              :                                              so ignore nonspec truths.  */
     874              :                                           NULL,
     875              :                                           NULL);
     876              : 
     877        14694 :       info->account_size_time (0, 0, true_pred, true_pred);
     878              : 
     879              :       /* Remap size_time vectors.
     880              :          Simplify the predicate by pruning out alternatives that are known
     881              :          to be false.
     882              :          TODO: as on optimization, we can also eliminate conditions known
     883              :          to be true.  */
     884       105321 :       for (i = 0; src_info->size_time_table.iterate (i, &e); i++)
     885              :         {
     886        90627 :           ipa_predicate new_exec_pred;
     887        90627 :           ipa_predicate new_nonconst_pred;
     888        90627 :           new_exec_pred = e->exec_predicate.remap_after_duplication
     889        90627 :                                  (possible_truths);
     890        90627 :           new_nonconst_pred = e->nonconst_predicate.remap_after_duplication
     891        90627 :                                  (possible_truths);
     892        90627 :           if (new_exec_pred == false || new_nonconst_pred == false)
     893        13040 :             optimized_out_size += e->size;
     894              :           else
     895        77587 :             info->account_size_time (e->size, e->time, new_exec_pred,
     896              :                                      new_nonconst_pred);
     897              :         }
     898              : 
     899              :       /* Remap edge predicates with the same simplification as above.
     900              :          Also copy constantness arrays.   */
     901       190460 :       for (edge = dst->callees; edge; edge = next)
     902              :         {
     903       175766 :           ipa_predicate new_predicate;
     904       175766 :           class ipa_call_summary *es = ipa_call_summaries->get (edge);
     905       175766 :           next = edge->next_callee;
     906              : 
     907       175766 :           if (!edge->inline_failed)
     908            0 :             inlined_to_p = true;
     909       175766 :           if (!es->predicate)
     910       159809 :             continue;
     911        15957 :           new_predicate = es->predicate->remap_after_duplication
     912        15957 :             (possible_truths);
     913        15957 :           if (new_predicate == false && *es->predicate != false)
     914         4492 :             optimized_out_size += es->call_stmt_size * ipa_fn_summary::size_scale;
     915        15957 :           edge_set_predicate (edge, &new_predicate);
     916              :         }
     917              : 
     918              :       /* Remap indirect edge predicates with the same simplification as above.
     919              :          Also copy constantness arrays.   */
     920        15598 :       for (edge = dst->indirect_calls; edge; edge = next)
     921              :         {
     922          904 :           ipa_predicate new_predicate;
     923          904 :           class ipa_call_summary *es = ipa_call_summaries->get (edge);
     924          904 :           next = edge->next_callee;
     925              : 
     926          904 :           gcc_checking_assert (edge->inline_failed);
     927          904 :           if (!es->predicate)
     928          783 :             continue;
     929          121 :           new_predicate = es->predicate->remap_after_duplication
     930          121 :                                  (possible_truths);
     931          121 :           if (new_predicate == false && *es->predicate != false)
     932           24 :             optimized_out_size
     933           24 :                  += es->call_stmt_size * ipa_fn_summary::size_scale;
     934          121 :           edge_set_predicate (edge, &new_predicate);
     935              :         }
     936        14694 :       info->loop_iterations
     937        14694 :         = remap_freqcounting_preds_after_dup (info->loop_iterations,
     938              :                                               possible_truths);
     939        14694 :       info->loop_strides
     940        14694 :         = remap_freqcounting_preds_after_dup (info->loop_strides,
     941              :                                               possible_truths);
     942        14694 :       if (info->builtin_constant_p_parms.length())
     943              :         {
     944           22 :           vec <int, va_heap, vl_ptr> parms = info->builtin_constant_p_parms;
     945           22 :           int ip;
     946           22 :           info->builtin_constant_p_parms = vNULL;
     947           44 :           for (i = 0; parms.iterate (i, &ip); i++)
     948           22 :             if (!avals.m_known_vals[ip])
     949            4 :               info->builtin_constant_p_parms.safe_push (ip);
     950              :         }
     951              : 
     952              :       /* If inliner or someone after inliner will ever start producing
     953              :          non-trivial clones, we will get trouble with lack of information
     954              :          about updating self sizes, because size vectors already contains
     955              :          sizes of the callees.  */
     956        14694 :       gcc_assert (!inlined_to_p || !optimized_out_size);
     957        14694 :     }
     958              :   else
     959              :     {
     960      2609356 :       info->size_time_table = src_info->size_time_table.copy ();
     961      2609356 :       info->loop_iterations = vec_safe_copy (src_info->loop_iterations);
     962      2609356 :       info->loop_strides = vec_safe_copy (info->loop_strides);
     963              : 
     964      2609356 :       info->builtin_constant_p_parms
     965      2609356 :              = info->builtin_constant_p_parms.copy ();
     966              : 
     967      2609356 :       ipa_freqcounting_predicate *f;
     968      2657773 :       for (int i = 0; vec_safe_iterate (info->loop_iterations, i, &f); i++)
     969              :         {
     970        48417 :           ipa_predicate p = *f->predicate;
     971        48417 :           f->predicate = NULL;
     972        48417 :           set_hint_predicate (&f->predicate, p);
     973              :         }
     974      2633205 :       for (int i = 0; vec_safe_iterate (info->loop_strides, i, &f); i++)
     975              :         {
     976        23849 :           ipa_predicate p = *f->predicate;
     977        23849 :           f->predicate = NULL;
     978        23849 :           set_hint_predicate (&f->predicate, p);
     979              :         }
     980              :     }
     981      2624050 :   if (!dst->inlined_to)
     982       132762 :     ipa_update_overall_fn_summary (dst);
     983      2624050 : }
     984              : 
     985              : 
     986              : /* Hook that is called by cgraph.cc when a node is duplicated.  */
     987              : 
     988              : void
     989      3662137 : ipa_call_summary_t::duplicate (struct cgraph_edge *src,
     990              :                                struct cgraph_edge *dst,
     991              :                                class ipa_call_summary *srcinfo,
     992              :                                class ipa_call_summary *info)
     993              : {
     994      3662137 :   new (info) ipa_call_summary (*srcinfo);
     995      3662137 :   info->predicate = NULL;
     996      3662137 :   edge_set_predicate (dst, srcinfo->predicate);
     997      3662137 :   info->param = srcinfo->param.copy ();
     998      3662137 :   if (!dst->indirect_unknown_callee && src->indirect_unknown_callee
     999              :       /* Don't subtract the size when dealing with callback pairs, since the
    1000              :          edge has no real size.  */
    1001        23981 :       && !src->has_callback && !dst->callback)
    1002              :     {
    1003        23981 :       info->call_stmt_size -= (eni_size_weights.indirect_call_cost
    1004        23981 :                                - eni_size_weights.call_cost);
    1005        23981 :       info->call_stmt_time -= (eni_time_weights.indirect_call_cost
    1006        23981 :                                - eni_time_weights.call_cost);
    1007              :     }
    1008      3662137 : }
    1009              : 
    1010              : /* Dump edge summaries associated to NODE and recursively to all clones.
    1011              :    Indent by INDENT.  */
    1012              : 
    1013              : static void
    1014         1984 : dump_ipa_call_summary (FILE *f, int indent, struct cgraph_node *node,
    1015              :                        class ipa_fn_summary *info)
    1016              : {
    1017         1984 :   struct cgraph_edge *edge;
    1018         9822 :   for (edge = node->callees; edge; edge = edge->next_callee)
    1019              :     {
    1020         7838 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    1021         7838 :       struct cgraph_node *callee = edge->callee->ultimate_alias_target ();
    1022         7838 :       int i;
    1023              : 
    1024        15676 :       fprintf (f,
    1025              :                "%*s%s %s\n%*s  freq:%4.2f",
    1026              :                indent, "", callee->dump_name (),
    1027         7838 :                !edge->inline_failed
    1028         7284 :                ? "inlined" : cgraph_inline_failed_string (edge-> inline_failed),
    1029         7838 :                indent, "", edge->sreal_frequency ().to_double ());
    1030              : 
    1031         7838 :       if (cross_module_call_p (edge))
    1032            4 :         fprintf (f, " cross module");
    1033              : 
    1034         7838 :       if (es)
    1035         7284 :         fprintf (f, " loop depth:%2i size:%2i time: %2i",
    1036              :                  es->loop_depth, es->call_stmt_size, es->call_stmt_time);
    1037              : 
    1038         7838 :       ipa_fn_summary *s = ipa_fn_summaries->get (callee);
    1039         7838 :       ipa_size_summary *ss = ipa_size_summaries->get (callee);
    1040         7838 :       if (s != NULL)
    1041          623 :         fprintf (f, " callee size:%2i stack:%2i",
    1042          623 :                  (int) (ss->size / ipa_fn_summary::size_scale),
    1043          623 :                  (int) s->estimated_stack_size);
    1044              : 
    1045         7838 :       if (es && es->predicate)
    1046              :         {
    1047         4627 :           fprintf (f, " predicate: ");
    1048         4627 :           es->predicate->dump (f, info->conds);
    1049              :         }
    1050              :       else
    1051         3211 :         fprintf (f, "\n");
    1052         7838 :       if (es && es->param.exists ())
    1053         5390 :         for (i = 0; i < (int) es->param.length (); i++)
    1054              :           {
    1055         1590 :             int prob = es->param[i].change_prob;
    1056              : 
    1057         1590 :             if (!prob)
    1058          606 :               fprintf (f, "%*s op%i is compile time invariant\n",
    1059              :                        indent + 2, "", i);
    1060          984 :             else if (prob != REG_BR_PROB_BASE)
    1061           35 :               fprintf (f, "%*s op%i change %f%% of time\n", indent + 2, "", i,
    1062           35 :                        prob * 100.0 / REG_BR_PROB_BASE);
    1063         1590 :             if (es->param[i].points_to_local_or_readonly_memory)
    1064          406 :               fprintf (f, "%*s op%i points to local or readonly memory\n",
    1065              :                        indent + 2, "", i);
    1066         1590 :             if (es->param[i].points_to_possible_sra_candidate)
    1067          225 :               fprintf (f, "%*s op%i points to possible sra candidate\n",
    1068              :                        indent + 2, "", i);
    1069              :           }
    1070         7838 :       if (!edge->inline_failed)
    1071              :         {
    1072          554 :           ipa_size_summary *ss = ipa_size_summaries->get (callee);
    1073          554 :           fprintf (f, "%*sStack frame offset %i, callee self size %i\n",
    1074              :                    indent + 2, "",
    1075          554 :                    (int) ipa_get_stack_frame_offset (callee),
    1076          554 :                    (int) ss->estimated_self_stack_size);
    1077          554 :           dump_ipa_call_summary (f, indent + 2, callee, info);
    1078              :         }
    1079              :     }
    1080         2282 :   for (edge = node->indirect_calls; edge; edge = edge->next_callee)
    1081              :     {
    1082          298 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    1083          298 :       fprintf (f, "%*sindirect call loop depth:%2i freq:%4.2f size:%2i"
    1084              :                " time: %2i",
    1085              :                indent, "",
    1086              :                es->loop_depth,
    1087          298 :                edge->sreal_frequency ().to_double (), es->call_stmt_size,
    1088              :                es->call_stmt_time);
    1089          298 :       if (es->predicate)
    1090              :         {
    1091            6 :           fprintf (f, "predicate: ");
    1092            6 :           es->predicate->dump (f, info->conds);
    1093              :         }
    1094              :       else
    1095          292 :         fprintf (f, "\n");
    1096              :     }
    1097         1984 : }
    1098              : 
    1099              : 
    1100              : void
    1101         1633 : ipa_dump_fn_summary (FILE *f, struct cgraph_node *node)
    1102              : {
    1103         1633 :   if (node->definition)
    1104              :     {
    1105         1633 :       class ipa_fn_summary *s = ipa_fn_summaries->get (node);
    1106         1633 :       class ipa_size_summary *ss = ipa_size_summaries->get (node);
    1107         1633 :       if (s != NULL)
    1108              :         {
    1109         1430 :           size_time_entry *e;
    1110         1430 :           int i;
    1111         1430 :           fprintf (f, "IPA function summary for %s", node->dump_name ());
    1112         1430 :           if (DECL_DISREGARD_INLINE_LIMITS (node->decl))
    1113            0 :             fprintf (f, " always_inline");
    1114         1430 :           if (s->inlinable)
    1115         1243 :             fprintf (f, " inlinable");
    1116         1430 :           if (s->fp_expressions)
    1117           45 :             fprintf (f, " fp_expression");
    1118         1430 :           if (s->builtin_constant_p_parms.length ())
    1119              :             {
    1120            2 :               fprintf (f, " builtin_constant_p_parms");
    1121            4 :               for (unsigned int i = 0;
    1122            4 :                    i < s->builtin_constant_p_parms.length (); i++)
    1123            2 :                 fprintf (f, " %i", s->builtin_constant_p_parms[i]);
    1124              :             }
    1125         1430 :           fprintf (f, "\n  global time:     %f\n", s->time.to_double ());
    1126         1430 :           fprintf (f, "  self size:       %i\n", ss->self_size);
    1127         1430 :           fprintf (f, "  global size:     %i\n", ss->size);
    1128         1430 :           fprintf (f, "  min size:       %i\n", s->min_size);
    1129         1430 :           fprintf (f, "  self stack:      %i\n",
    1130         1430 :                    (int) ss->estimated_self_stack_size);
    1131         1430 :           fprintf (f, "  global stack:    %i\n", (int) s->estimated_stack_size);
    1132         1430 :           if (s->growth)
    1133          161 :             fprintf (f, "  estimated growth:%i\n", (int) s->growth);
    1134         1430 :           if (s->scc_no)
    1135            5 :             fprintf (f, "  In SCC:          %i\n", (int) s->scc_no);
    1136         5978 :           for (i = 0; s->size_time_table.iterate (i, &e); i++)
    1137              :             {
    1138         4548 :               fprintf (f, "    size:%f, time:%f",
    1139         4548 :                        (double) e->size / ipa_fn_summary::size_scale,
    1140              :                        e->time.to_double ());
    1141         4548 :               if (e->exec_predicate != true)
    1142              :                 {
    1143         2659 :                   fprintf (f, ",  executed if:");
    1144         2659 :                   e->exec_predicate.dump (f, s->conds, 0);
    1145              :                 }
    1146         4548 :               if (e->exec_predicate != e->nonconst_predicate)
    1147              :                 {
    1148         1189 :                   fprintf (f, ",  nonconst if:");
    1149         1189 :                   e->nonconst_predicate.dump (f, s->conds, 0);
    1150              :                 }
    1151         4548 :               fprintf (f, "\n");
    1152              :             }
    1153              :           ipa_freqcounting_predicate *fcp;
    1154              :           bool first_fcp = true;
    1155         1542 :           for (int i = 0; vec_safe_iterate (s->loop_iterations, i, &fcp); i++)
    1156              :             {
    1157          112 :               if (first_fcp)
    1158              :                 {
    1159           79 :                   fprintf (f, "  loop iterations:");
    1160           79 :                   first_fcp = false;
    1161              :                 }
    1162          112 :               fprintf (f, "  %3.2f for ", fcp->freq.to_double ());
    1163          112 :               fcp->predicate->dump (f, s->conds);
    1164              :             }
    1165              :           first_fcp = true;
    1166         1450 :           for (int i = 0; vec_safe_iterate (s->loop_strides, i, &fcp); i++)
    1167              :             {
    1168           20 :               if (first_fcp)
    1169              :                 {
    1170           11 :                   fprintf (f, "  loop strides:");
    1171           11 :                   first_fcp = false;
    1172              :                 }
    1173           20 :               fprintf (f, "  %3.2f for :", fcp->freq.to_double ());
    1174           20 :               fcp->predicate->dump (f, s->conds);
    1175              :             }
    1176         1430 :           fprintf (f, "  calls:\n");
    1177         1430 :           dump_ipa_call_summary (f, 4, node, s);
    1178         1430 :           fprintf (f, "\n");
    1179         1430 :           if (s->target_info)
    1180            0 :             fprintf (f, "  target_info: %x\n", s->target_info);
    1181              :         }
    1182              :       else
    1183          203 :         fprintf (f, "IPA summary for %s is missing.\n", node->dump_name ());
    1184              :     }
    1185         1633 : }
    1186              : 
    1187              : DEBUG_FUNCTION void
    1188            0 : ipa_debug_fn_summary (struct cgraph_node *node)
    1189              : {
    1190            0 :   ipa_dump_fn_summary (stderr, node);
    1191            0 : }
    1192              : 
    1193              : void
    1194          356 : ipa_dump_fn_summaries (FILE *f)
    1195              : {
    1196          356 :   struct cgraph_node *node;
    1197              : 
    1198         2296 :   FOR_EACH_DEFINED_FUNCTION (node)
    1199         1940 :     if (!node->inlined_to)
    1200         1386 :       ipa_dump_fn_summary (f, node);
    1201          356 : }
    1202              : 
    1203              : /* Callback of walk_aliased_vdefs.  Flags that it has been invoked to the
    1204              :    boolean variable pointed to by DATA.  */
    1205              : 
    1206              : static bool
    1207       849884 : mark_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef ATTRIBUTE_UNUSED,
    1208              :                void *data)
    1209              : {
    1210       849884 :   bool *b = (bool *) data;
    1211       849884 :   *b = true;
    1212       849884 :   return true;
    1213              : }
    1214              : 
    1215              : /* If OP refers to value of function parameter, return the corresponding
    1216              :    parameter.  If non-NULL, the size of the memory load (or the SSA_NAME of the
    1217              :    PARM_DECL) will be stored to *SIZE_P in that case too.  */
    1218              : 
    1219              : static tree
    1220    182891701 : unmodified_parm_1 (ipa_func_body_info *fbi, gimple *stmt, tree op,
    1221              :                    poly_int64 *size_p)
    1222              : {
    1223              :   /* SSA_NAME referring to parm default def?  */
    1224    182891701 :   if (TREE_CODE (op) == SSA_NAME
    1225    107033139 :       && SSA_NAME_IS_DEFAULT_DEF (op)
    1226    208197074 :       && TREE_CODE (SSA_NAME_VAR (op)) == PARM_DECL)
    1227              :     {
    1228     25106762 :       if (size_p)
    1229            0 :         *size_p = tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op)));
    1230     25106762 :       return SSA_NAME_VAR (op);
    1231              :     }
    1232              :   /* Non-SSA parm reference?  */
    1233    157784939 :   if (TREE_CODE (op) == PARM_DECL
    1234      1456574 :       && fbi->aa_walk_budget > 0)
    1235              :     {
    1236      1454028 :       bool modified = false;
    1237              : 
    1238      1454028 :       ao_ref refd;
    1239      1454028 :       ao_ref_init (&refd, op);
    1240      2908056 :       int walked = walk_aliased_vdefs (&refd, gimple_vuse (stmt),
    1241              :                                        mark_modified, &modified, NULL, NULL,
    1242              :                                        fbi->aa_walk_budget);
    1243      1454028 :       if (walked < 0)
    1244              :         {
    1245            8 :           fbi->aa_walk_budget = 0;
    1246       928252 :           return NULL_TREE;
    1247              :         }
    1248      1454020 :       fbi->aa_walk_budget -= walked;
    1249      1454020 :       if (!modified)
    1250              :         {
    1251       928244 :           if (size_p)
    1252            0 :             *size_p = tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op)));
    1253       928244 :           return op;
    1254              :         }
    1255              :     }
    1256              :   return NULL_TREE;
    1257              : }
    1258              : 
    1259              : /* If OP refers to value of function parameter, return the corresponding
    1260              :    parameter.  Also traverse chains of SSA register assignments.  If non-NULL,
    1261              :    the size of the memory load (or the SSA_NAME of the PARM_DECL) will be
    1262              :    stored to *SIZE_P in that case too.  */
    1263              : 
    1264              : static tree
    1265    119496981 : unmodified_parm (ipa_func_body_info *fbi, gimple *stmt, tree op,
    1266              :                  poly_int64 *size_p)
    1267              : {
    1268    148653797 :   tree res = unmodified_parm_1 (fbi, stmt, op, size_p);
    1269    148653797 :   if (res)
    1270              :     return res;
    1271              : 
    1272    123432955 :   if (TREE_CODE (op) == SSA_NAME
    1273     70079413 :       && !SSA_NAME_IS_DEFAULT_DEF (op)
    1274    193318232 :       && gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
    1275     29156816 :     return unmodified_parm (fbi, SSA_NAME_DEF_STMT (op),
    1276     29156816 :                             gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op)),
    1277     29156816 :                             size_p);
    1278              :   return NULL_TREE;
    1279              : }
    1280              : 
    1281              : /* If OP refers to a value of a function parameter or value loaded from an
    1282              :    aggregate passed to a parameter (either by value or reference), return TRUE
    1283              :    and store the number of the parameter to *INDEX_P, the access size into
    1284              :    *SIZE_P, and information whether and how it has been loaded from an
    1285              :    aggregate into *AGGPOS.  INFO describes the function parameters, STMT is the
    1286              :    statement in which OP is used or loaded.  */
    1287              : 
    1288              : static bool
    1289     32787596 : unmodified_parm_or_parm_agg_item (struct ipa_func_body_info *fbi,
    1290              :                                   gimple *stmt, tree op, int *index_p,
    1291              :                                   poly_int64 *size_p,
    1292              :                                   struct agg_position_info *aggpos)
    1293              : {
    1294     34237904 :   tree res = unmodified_parm_1 (fbi, stmt, op, size_p);
    1295              : 
    1296     34237904 :   gcc_checking_assert (aggpos);
    1297     34237904 :   if (res)
    1298              :     {
    1299       814164 :       *index_p = ipa_get_param_decl_index (fbi->info, res);
    1300       814164 :       if (*index_p < 0)
    1301              :         return false;
    1302       814035 :       aggpos->agg_contents = false;
    1303       814035 :       aggpos->by_ref = false;
    1304       814035 :       return true;
    1305              :     }
    1306              : 
    1307     33423740 :   if (TREE_CODE (op) == SSA_NAME)
    1308              :     {
    1309     11846964 :       if (SSA_NAME_IS_DEFAULT_DEF (op)
    1310     11846964 :           || !gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
    1311              :         return false;
    1312      4780968 :       stmt = SSA_NAME_DEF_STMT (op);
    1313      4780968 :       op = gimple_assign_rhs1 (stmt);
    1314      4780968 :       if (!REFERENCE_CLASS_P (op))
    1315              :         return unmodified_parm_or_parm_agg_item (fbi, stmt, op, index_p, size_p,
    1316              :                                                  aggpos);
    1317              :     }
    1318              : 
    1319     24907436 :   aggpos->agg_contents = true;
    1320     24907436 :   return ipa_load_from_parm_agg (fbi, fbi->info->descriptors,
    1321              :                                  stmt, op, index_p, &aggpos->offset,
    1322     24907436 :                                  size_p, &aggpos->by_ref);
    1323              : }
    1324              : 
    1325              : /* If stmt is simple load or store of value pointed to by a function parmaeter,
    1326              :    return its index.  */
    1327              : 
    1328              : static int
    1329    110702677 : load_or_store_of_ptr_parameter (ipa_func_body_info *fbi, gimple *stmt)
    1330              : {
    1331    110702677 :   if (!optimize)
    1332              :     return -1;
    1333    158751825 :   gassign *assign = dyn_cast <gassign *> (stmt);
    1334     55224632 :   if (!assign)
    1335              :     return -1;
    1336     55224632 :   tree param;
    1337     55224632 :   if (gimple_assign_load_p (stmt))
    1338     20324262 :     param = gimple_assign_rhs1 (stmt);
    1339     34900370 :   else if (gimple_store_p (stmt))
    1340     18497744 :     param = gimple_assign_lhs (stmt);
    1341              :   else
    1342              :     return -1;
    1343     38822006 :   tree base = get_base_address (param);
    1344     38822006 :   if (TREE_CODE (base) != MEM_REF
    1345     13462155 :       || TREE_CODE (TREE_OPERAND (base, 0)) != SSA_NAME
    1346     52280053 :       || !SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (base, 0)))
    1347              :     return -1;
    1348      7259898 :   tree p = SSA_NAME_VAR (TREE_OPERAND (base, 0));
    1349      7259898 :   if (TREE_CODE (p) != PARM_DECL)
    1350              :     return -1;
    1351      7175484 :   return ipa_get_param_decl_index (fbi->info, p);
    1352              : }
    1353              : 
    1354              : /* See if statement might disappear after inlining.
    1355              :    0 - means not eliminated
    1356              :    1 - half of statements goes away
    1357              :    2 - for sure it is eliminated.
    1358              :    We are not terribly sophisticated, basically looking for simple abstraction
    1359              :    penalty wrappers.  */
    1360              : 
    1361              : static int
    1362    110702677 : eliminated_by_inlining_prob (ipa_func_body_info *fbi, gimple *stmt)
    1363              : {
    1364    110702677 :   enum gimple_code code = gimple_code (stmt);
    1365    110702677 :   enum tree_code rhs_code;
    1366              : 
    1367    110702677 :   if (!optimize)
    1368              :     return 0;
    1369              : 
    1370     92695234 :   switch (code)
    1371              :     {
    1372              :     case GIMPLE_RETURN:
    1373              :       return 2;
    1374     55224632 :     case GIMPLE_ASSIGN:
    1375     55224632 :       if (gimple_num_ops (stmt) != 2)
    1376              :         return 0;
    1377              : 
    1378     39625294 :       rhs_code = gimple_assign_rhs_code (stmt);
    1379              : 
    1380              :       /* Casts of parameters, loads from parameters passed by reference
    1381              :          and stores to return value or parameters are often free after
    1382              :          inlining due to SRA and further combining.
    1383              :          Assume that half of statements goes away.  */
    1384     39625294 :       if (CONVERT_EXPR_CODE_P (rhs_code)
    1385              :           || rhs_code == VIEW_CONVERT_EXPR
    1386              :           || rhs_code == ADDR_EXPR
    1387     36863184 :           || gimple_assign_rhs_class (stmt) == GIMPLE_SINGLE_RHS)
    1388              :         {
    1389     38822006 :           tree rhs = gimple_assign_rhs1 (stmt);
    1390     38822006 :           tree lhs = gimple_assign_lhs (stmt);
    1391     38822006 :           tree inner_rhs = get_base_address (rhs);
    1392     38822006 :           tree inner_lhs = get_base_address (lhs);
    1393     38822006 :           bool rhs_free = false;
    1394     38822006 :           bool lhs_free = false;
    1395              : 
    1396     38822006 :           if (!inner_rhs)
    1397            0 :             inner_rhs = rhs;
    1398     38822006 :           if (!inner_lhs)
    1399            0 :             inner_lhs = lhs;
    1400              : 
    1401              :           /* Reads of parameter are expected to be free.  */
    1402     38822006 :           if (unmodified_parm (fbi, stmt, inner_rhs, NULL))
    1403              :             rhs_free = true;
    1404              :           /* Match expressions of form &this->field. Those will most likely
    1405              :              combine with something upstream after inlining.  */
    1406     37561343 :           else if (TREE_CODE (inner_rhs) == ADDR_EXPR)
    1407              :             {
    1408      2464070 :               tree op = get_base_address (TREE_OPERAND (inner_rhs, 0));
    1409      2464070 :               if (TREE_CODE (op) == PARM_DECL)
    1410              :                 rhs_free = true;
    1411      2425116 :               else if (TREE_CODE (op) == MEM_REF
    1412      2425116 :                        && unmodified_parm (fbi, stmt, TREE_OPERAND (op, 0),
    1413              :                                            NULL))
    1414              :                 rhs_free = true;
    1415              :             }
    1416              : 
    1417              :           /* When parameter is not SSA register because its address is taken
    1418              :              and it is just copied into one, the statement will be completely
    1419              :              free after inlining (we will copy propagate backward).   */
    1420      1299617 :           if (rhs_free && is_gimple_reg (lhs))
    1421              :             return 2;
    1422              : 
    1423              :           /* Reads of parameters passed by reference
    1424              :              expected to be free (i.e. optimized out after inlining).  */
    1425     38148470 :           if (TREE_CODE (inner_rhs) == MEM_REF
    1426     38148470 :               && unmodified_parm (fbi, stmt, TREE_OPERAND (inner_rhs, 0), NULL))
    1427              :             rhs_free = true;
    1428              : 
    1429              :           /* Copying parameter passed by reference into gimple register is
    1430              :              probably also going to copy propagate, but we can't be quite
    1431              :              sure.  */
    1432     38148470 :           if (rhs_free && is_gimple_reg (lhs))
    1433              :             lhs_free = true;
    1434              : 
    1435              :           /* Writes to parameters, parameters passed by value and return value
    1436              :              (either directly or passed via invisible reference) are free.
    1437              : 
    1438              :              TODO: We ought to handle testcase like
    1439              :              struct a {int a,b;};
    1440              :              struct a
    1441              :              returnstruct (void)
    1442              :              {
    1443              :              struct a a ={1,2};
    1444              :              return a;
    1445              :              }
    1446              : 
    1447              :              This translate into:
    1448              : 
    1449              :              returnstruct ()
    1450              :              {
    1451              :              int a$b;
    1452              :              int a$a;
    1453              :              struct a a;
    1454              :              struct a D.2739;
    1455              : 
    1456              :              <bb 2>:
    1457              :              D.2739.a = 1;
    1458              :              D.2739.b = 2;
    1459              :              return D.2739;
    1460              : 
    1461              :              }
    1462              :              For that we either need to copy ipa-split logic detecting writes
    1463              :              to return value.  */
    1464     38148470 :           if (TREE_CODE (inner_lhs) == PARM_DECL
    1465     38059354 :               || TREE_CODE (inner_lhs) == RESULT_DECL
    1466     75371939 :               || (TREE_CODE (inner_lhs) == MEM_REF
    1467      4997147 :                   && (unmodified_parm (fbi, stmt, TREE_OPERAND (inner_lhs, 0),
    1468              :                                        NULL)
    1469      2578139 :                       || (TREE_CODE (TREE_OPERAND (inner_lhs, 0)) == SSA_NAME
    1470      2576950 :                           && SSA_NAME_VAR (TREE_OPERAND (inner_lhs, 0))
    1471       360577 :                           && TREE_CODE (SSA_NAME_VAR (TREE_OPERAND
    1472              :                                                       (inner_lhs,
    1473              :                                                        0))) == RESULT_DECL))))
    1474              :             lhs_free = true;
    1475     34723307 :           if (lhs_free
    1476     38148470 :               && (is_gimple_reg (rhs) || is_gimple_min_invariant (rhs)))
    1477              :             rhs_free = true;
    1478     38148470 :           if (lhs_free && rhs_free)
    1479              :             return 1;
    1480              :         }
    1481              :       return 0;
    1482              :     default:
    1483              :       return 0;
    1484              :     }
    1485              : }
    1486              : 
    1487              : /* Analyze EXPR if it represents a series of simple operations performed on
    1488              :    a function parameter and return true if so.  FBI, STMT, EXPR, INDEX_P and
    1489              :    AGGPOS have the same meaning like in unmodified_parm_or_parm_agg_item.
    1490              :    Type of the parameter or load from an aggregate via the parameter is
    1491              :    stored in *TYPE_P.  Operations on the parameter are recorded to
    1492              :    PARAM_OPS_P if it is not NULL.  */
    1493              : 
    1494              : static bool
    1495     27026813 : decompose_param_expr (struct ipa_func_body_info *fbi,
    1496              :                       gimple *stmt, tree expr,
    1497              :                       int *index_p, tree *type_p,
    1498              :                       struct agg_position_info *aggpos,
    1499              :                       expr_eval_ops *param_ops_p = NULL)
    1500              : {
    1501     27026813 :   int op_limit = opt_for_fn (fbi->node->decl, param_ipa_max_param_expr_ops);
    1502     27026813 :   int op_count = 0;
    1503              : 
    1504     27026813 :   if (param_ops_p)
    1505      9235850 :     *param_ops_p = NULL;
    1506              : 
    1507     32787596 :   while (true)
    1508              :     {
    1509     32787596 :       expr_eval_op eval_op;
    1510     32787596 :       unsigned rhs_count;
    1511     32787596 :       unsigned cst_count = 0;
    1512              : 
    1513     32787596 :       if (unmodified_parm_or_parm_agg_item (fbi, stmt, expr, index_p, NULL,
    1514              :                                             aggpos))
    1515              :         {
    1516      4609100 :           tree type = TREE_TYPE (expr);
    1517              : 
    1518      4609100 :           if (aggpos->agg_contents)
    1519              :             {
    1520              :               /* Stop if containing bit-field.  */
    1521      3795065 :               if (TREE_CODE (expr) == BIT_FIELD_REF
    1522      3795065 :                   || contains_bitfld_component_ref_p (expr))
    1523              :                 break;
    1524              :             }
    1525              : 
    1526      4580759 :           *type_p = type;
    1527      4580759 :           return true;
    1528              :         }
    1529              : 
    1530     28178496 :       if (TREE_CODE (expr) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (expr))
    1531              :         break;
    1532     10505508 :       stmt = SSA_NAME_DEF_STMT (expr);
    1533              : 
    1534     10505508 :       if (gcall *call = dyn_cast <gcall *> (stmt))
    1535              :         {
    1536      2464255 :           int flags = gimple_call_return_flags (call);
    1537      2464255 :           if (!(flags & ERF_RETURNS_ARG))
    1538      3060894 :             goto fail;
    1539       207518 :           int arg = flags & ERF_RETURN_ARG_MASK;
    1540       207518 :           if (arg >= (int)gimple_call_num_args (call))
    1541            0 :             goto fail;
    1542       207518 :           expr = gimple_call_arg (stmt, arg);
    1543      3988077 :           continue;
    1544       207518 :         }
    1545              : 
    1546      8041253 :       if (!is_gimple_assign (stmt = SSA_NAME_DEF_STMT (expr)))
    1547              :         break;
    1548              : 
    1549      6357497 :       switch (gimple_assign_rhs_class (stmt))
    1550              :         {
    1551      3780559 :         case GIMPLE_SINGLE_RHS:
    1552      3780559 :           expr = gimple_assign_rhs1 (stmt);
    1553      3780559 :           continue;
    1554              : 
    1555              :         case GIMPLE_UNARY_RHS:
    1556              :           rhs_count = 1;
    1557              :           break;
    1558              : 
    1559      1549964 :         case GIMPLE_BINARY_RHS:
    1560      1549964 :           rhs_count = 2;
    1561      1549964 :           break;
    1562              : 
    1563          642 :         case GIMPLE_TERNARY_RHS:
    1564          642 :           rhs_count = 3;
    1565          642 :           break;
    1566              : 
    1567            0 :         default:
    1568            0 :           goto fail;
    1569              :         }
    1570              : 
    1571              :       /* Stop if expression is too complex.  */
    1572      2576938 :       if (op_count++ == op_limit)
    1573              :         break;
    1574              : 
    1575      2576863 :       if (param_ops_p)
    1576              :         {
    1577      2575350 :           eval_op.code = gimple_assign_rhs_code (stmt);
    1578      2575350 :           eval_op.type = TREE_TYPE (gimple_assign_lhs (stmt));
    1579      2575350 :           eval_op.val[0] = NULL_TREE;
    1580      2575350 :           eval_op.val[1] = NULL_TREE;
    1581              :         }
    1582              : 
    1583              :       expr = NULL_TREE;
    1584      5900189 :       for (unsigned i = 0; i < rhs_count; i++)
    1585              :         {
    1586      4127483 :           tree op = gimple_op (stmt, i + 1);
    1587              : 
    1588      4127483 :           gcc_assert (op && !TYPE_P (op));
    1589      4127483 :           if (is_gimple_ip_invariant (op))
    1590              :             {
    1591       748805 :               if (++cst_count == rhs_count)
    1592         1171 :                 goto fail;
    1593              : 
    1594       747634 :               eval_op.val[cst_count - 1] = op;
    1595              :             }
    1596      3378678 :           else if (!expr)
    1597              :             {
    1598              :               /* Found a non-constant operand, and record its index in rhs
    1599              :                  operands.  */
    1600      2575692 :               eval_op.index = i;
    1601      2575692 :               expr = op;
    1602              :             }
    1603              :           else
    1604              :             {
    1605              :               /* Found more than one non-constant operands.  */
    1606       802986 :               goto fail;
    1607              :             }
    1608              :         }
    1609              : 
    1610      1772706 :       if (param_ops_p)
    1611      1771447 :         vec_safe_insert (*param_ops_p, 0, eval_op);
    1612              :     }
    1613              : 
    1614              :   /* Failed to decompose, free resource and return.  */
    1615     22446054 : fail:
    1616     22446054 :   if (param_ops_p)
    1617      9045828 :     vec_free (*param_ops_p);
    1618              : 
    1619              :   return false;
    1620              : }
    1621              : 
    1622              : /* Record to SUMMARY that PARM is used by builtin_constant_p.  */
    1623              : 
    1624              : static void
    1625        10558 : add_builtin_constant_p_parm (class ipa_fn_summary *summary, int parm)
    1626              : {
    1627        10558 :   int ip;
    1628              : 
    1629              :   /* Avoid duplicates.  */
    1630        10576 :   for (unsigned int i = 0;
    1631        10576 :        summary->builtin_constant_p_parms.iterate (i, &ip); i++)
    1632         5117 :     if (ip == parm)
    1633        10558 :       return;
    1634         5459 :   summary->builtin_constant_p_parms.safe_push (parm);
    1635              : }
    1636              : 
    1637              : /* If BB ends by a conditional we can turn into predicates, attach corresponding
    1638              :    predicates to the CFG edges.   */
    1639              : 
    1640              : static void
    1641     34903476 : set_cond_stmt_execution_predicate (struct ipa_func_body_info *fbi,
    1642              :                                    class ipa_fn_summary *summary,
    1643              :                                    class ipa_node_params *params_summary,
    1644              :                                    basic_block bb)
    1645              : {
    1646     34903476 :   tree op, op2;
    1647     34903476 :   int index;
    1648     34903476 :   struct agg_position_info aggpos;
    1649     34903476 :   enum tree_code code, inverted_code;
    1650     34903476 :   edge e;
    1651     34903476 :   edge_iterator ei;
    1652     34903476 :   gimple *set_stmt;
    1653     34903476 :   tree param_type;
    1654     34903476 :   expr_eval_ops param_ops;
    1655              : 
    1656     69806952 :   gcond *last = safe_dyn_cast <gcond *> (*gsi_last_bb (bb));
    1657     11578975 :   if (!last)
    1658     34892918 :     return;
    1659     11578975 :   if (!is_gimple_ip_invariant (gimple_cond_rhs (last)))
    1660              :     return;
    1661      9153483 :   op = gimple_cond_lhs (last);
    1662              : 
    1663      9153483 :   if (decompose_param_expr (fbi, last, op, &index, &param_type, &aggpos,
    1664              :                             &param_ops))
    1665              :     {
    1666      1308885 :       code = gimple_cond_code (last);
    1667      1308885 :       inverted_code = invert_tree_comparison (code, HONOR_NANS (op));
    1668              : 
    1669      3926655 :       FOR_EACH_EDGE (e, ei, bb->succs)
    1670              :         {
    1671      1308885 :           enum tree_code this_code = (e->flags & EDGE_TRUE_VALUE
    1672      2617770 :                                       ? code : inverted_code);
    1673              :           /* invert_tree_comparison will return ERROR_MARK on FP
    1674              :              comparisons that are not EQ/NE instead of returning proper
    1675              :              unordered one.  Be sure it is not confused with NON_CONSTANT.
    1676              : 
    1677              :              And if the edge's target is the final block of diamond CFG graph
    1678              :              of this conditional statement, we do not need to compute
    1679              :              predicate for the edge because the final block's predicate must
    1680              :              be at least as that of the first block of the statement.  */
    1681      2617770 :           if (this_code != ERROR_MARK
    1682      2617770 :               && !dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    1683              :             {
    1684      2206282 :               ipa_predicate p
    1685      2206282 :                 = add_condition (summary, params_summary, index,
    1686              :                                  param_type, &aggpos,
    1687              :                                  this_code, gimple_cond_rhs (last), param_ops);
    1688      2206282 :               e->aux = edge_predicate_pool.allocate ();
    1689      2206282 :               *(ipa_predicate *) e->aux = p;
    1690              :             }
    1691              :         }
    1692      1308885 :       vec_free (param_ops);
    1693      1308885 :       return;
    1694              :     }
    1695              : 
    1696      7844598 :   if (TREE_CODE (op) != SSA_NAME)
    1697              :     return;
    1698              :   /* Special case
    1699              :      if (builtin_constant_p (op))
    1700              :      constant_code
    1701              :      else
    1702              :      nonconstant_code.
    1703              :      Here we can predicate nonconstant_code.  We can't
    1704              :      really handle constant_code since we have no predicate
    1705              :      for this and also the constant code is not known to be
    1706              :      optimized away when inliner doesn't see operand is constant.
    1707              :      Other optimizers might think otherwise.  */
    1708      7843527 :   if (gimple_cond_code (last) != NE_EXPR
    1709      7843527 :       || !integer_zerop (gimple_cond_rhs (last)))
    1710      4451543 :     return;
    1711      3391984 :   set_stmt = SSA_NAME_DEF_STMT (op);
    1712      3391984 :   if (!gimple_call_builtin_p (set_stmt, BUILT_IN_CONSTANT_P)
    1713      3391984 :       || gimple_call_num_args (set_stmt) != 1)
    1714              :     return;
    1715        11708 :   op2 = gimple_call_arg (set_stmt, 0);
    1716        11708 :   if (!decompose_param_expr (fbi, set_stmt, op2, &index, &param_type, &aggpos))
    1717              :     return;
    1718        10558 :   if (!aggpos.by_ref)
    1719        10525 :     add_builtin_constant_p_parm (summary, index);
    1720        31674 :   FOR_EACH_EDGE (e, ei, bb->succs) if (e->flags & EDGE_FALSE_VALUE)
    1721              :     {
    1722        10558 :       ipa_predicate p = add_condition (summary, params_summary, index,
    1723              :                                    param_type, &aggpos,
    1724              :                                    ipa_predicate::is_not_constant, NULL_TREE);
    1725        10558 :       e->aux = edge_predicate_pool.allocate ();
    1726        10558 :       *(ipa_predicate *) e->aux = p;
    1727              :     }
    1728              : }
    1729              : 
    1730              : 
    1731              : /* If BB ends by a switch we can turn into predicates, attach corresponding
    1732              :    predicates to the CFG edges.   */
    1733              : 
    1734              : static void
    1735     34903476 : set_switch_stmt_execution_predicate (struct ipa_func_body_info *fbi,
    1736              :                                      class ipa_fn_summary *summary,
    1737              :                                      class ipa_node_params *params_summary,
    1738              :                                      basic_block bb)
    1739              : {
    1740     34903476 :   tree op;
    1741     34903476 :   int index;
    1742     34903476 :   struct agg_position_info aggpos;
    1743     34903476 :   edge e;
    1744     34903476 :   edge_iterator ei;
    1745     34903476 :   size_t n;
    1746     34903476 :   size_t case_idx;
    1747     34903476 :   tree param_type;
    1748     34903476 :   expr_eval_ops param_ops;
    1749              : 
    1750     69806952 :   gswitch *last = safe_dyn_cast <gswitch *> (*gsi_last_bb (bb));
    1751        82367 :   if (!last)
    1752     34871949 :     return;
    1753        82367 :   op = gimple_switch_index (last);
    1754        82367 :   if (!decompose_param_expr (fbi, last, op, &index, &param_type, &aggpos,
    1755              :                              &param_ops))
    1756              :     return;
    1757              : 
    1758        46857 :   auto_vec<std::pair<tree, tree> > ranges;
    1759        46857 :   tree type = TREE_TYPE (op);
    1760        46857 :   int bound_limit = opt_for_fn (fbi->node->decl,
    1761              :                                 param_ipa_max_switch_predicate_bounds);
    1762        46857 :   int bound_count = 0;
    1763              :   // This can safely be an integer range, as switches can only hold
    1764              :   // integers.
    1765        46857 :   int_range<2> vr;
    1766              : 
    1767        93714 :   get_range_query (cfun)->range_of_expr (vr, op);
    1768        46857 :   if (vr.undefined_p ())
    1769            0 :     vr.set_varying (TREE_TYPE (op));
    1770        46857 :   tree vr_min, vr_max;
    1771              :   // TODO: This entire function could use a rewrite to use the irange
    1772              :   // API, instead of trying to recreate its intersection/union logic.
    1773              :   // Any use of get_legacy_range() is a serious code smell.
    1774        46857 :   value_range_kind vr_type = get_legacy_range (vr, vr_min, vr_max);
    1775        46857 :   wide_int vr_wmin = wi::to_wide (vr_min);
    1776        46857 :   wide_int vr_wmax = wi::to_wide (vr_max);
    1777              : 
    1778       326428 :   FOR_EACH_EDGE (e, ei, bb->succs)
    1779              :     {
    1780       279571 :       e->aux = edge_predicate_pool.allocate ();
    1781       279571 :       *(ipa_predicate *) e->aux = false;
    1782              :     }
    1783              : 
    1784        46857 :   e = gimple_switch_edge (cfun, last, 0);
    1785              :   /* Set BOUND_COUNT to maximum count to bypass computing predicate for
    1786              :      default case if its target basic block is in convergence point of all
    1787              :      switch cases, which can be determined by checking whether it
    1788              :      post-dominates the switch statement.  */
    1789        46857 :   if (dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    1790        12604 :     bound_count = INT_MAX;
    1791              : 
    1792        46857 :   n = gimple_switch_num_labels (last);
    1793       311639 :   for (case_idx = 1; case_idx < n; ++case_idx)
    1794              :     {
    1795       264782 :       tree cl = gimple_switch_label (last, case_idx);
    1796       264782 :       tree min = CASE_LOW (cl);
    1797       264782 :       tree max = CASE_HIGH (cl);
    1798       264782 :       ipa_predicate p;
    1799              : 
    1800       264782 :       e = gimple_switch_edge (cfun, last, case_idx);
    1801              : 
    1802              :       /* The case value might not have same type as switch expression,
    1803              :          extend the value based on the expression type.  */
    1804       264782 :       if (TREE_TYPE (min) != type)
    1805        50585 :         min = wide_int_to_tree (type, wi::to_wide (min));
    1806              : 
    1807       264782 :       if (!max)
    1808              :         max = min;
    1809        14609 :       else if (TREE_TYPE (max) != type)
    1810         5760 :         max = wide_int_to_tree (type, wi::to_wide (max));
    1811              : 
    1812              :       /* The case's target basic block is in convergence point of all switch
    1813              :          cases, its predicate should be at least as that of the switch
    1814              :          statement.  */
    1815       264782 :       if (dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    1816         5024 :         p = true;
    1817       259758 :       else if (min == max)
    1818       246841 :         p = add_condition (summary, params_summary, index, param_type,
    1819              :                            &aggpos, EQ_EXPR, min, param_ops);
    1820              :       else
    1821              :         {
    1822        12917 :           ipa_predicate p1, p2;
    1823        12917 :           p1 = add_condition (summary, params_summary, index, param_type,
    1824              :                               &aggpos, GE_EXPR, min, param_ops);
    1825        12917 :           p2 = add_condition (summary,  params_summary,index, param_type,
    1826              :                               &aggpos, LE_EXPR, max, param_ops);
    1827        12917 :           p = p1 & p2;
    1828              :         }
    1829       264782 :       *(ipa_predicate *) e->aux
    1830       264782 :         = p.or_with (summary->conds, *(ipa_predicate *) e->aux);
    1831              : 
    1832              :       /* If there are too many disjoint case ranges, predicate for default
    1833              :          case might become too complicated.  So add a limit here.  */
    1834       264782 :       if (bound_count > bound_limit)
    1835        96253 :         continue;
    1836              : 
    1837       168529 :       bool new_range = true;
    1838              : 
    1839       168529 :       if (!ranges.is_empty ())
    1840              :         {
    1841       134276 :           wide_int curr_wmin = wi::to_wide (min);
    1842       134276 :           wide_int last_wmax = wi::to_wide (ranges.last ().second);
    1843              : 
    1844              :           /* Merge case ranges if they are continuous.  */
    1845       134276 :           if (curr_wmin == last_wmax + 1)
    1846              :             new_range = false;
    1847        45950 :           else if (vr_type == VR_ANTI_RANGE)
    1848              :             {
    1849              :               /* If two disjoint case ranges can be connected by anti-range
    1850              :                  of switch index, combine them to one range.  */
    1851           79 :               if (wi::lt_p (vr_wmax, curr_wmin - 1, TYPE_SIGN (type)))
    1852              :                 vr_type = VR_UNDEFINED;
    1853            0 :               else if (wi::le_p (vr_wmin, last_wmax + 1, TYPE_SIGN (type)))
    1854            0 :                 new_range = false;
    1855              :             }
    1856       134276 :         }
    1857              : 
    1858              :       /* Create/extend a case range.  And we count endpoints of range set,
    1859              :          this number nearly equals to number of conditions that we will create
    1860              :          for predicate of default case.  */
    1861       134276 :       if (new_range)
    1862              :         {
    1863        80203 :           bound_count += (min == max) ? 1 : 2;
    1864        80203 :           ranges.safe_push (std::make_pair (min, max));
    1865              :         }
    1866              :       else
    1867              :         {
    1868        88326 :           bound_count += (ranges.last ().first == ranges.last ().second);
    1869        88326 :           ranges.last ().second = max;
    1870              :         }
    1871              :     }
    1872              : 
    1873        46857 :   e = gimple_switch_edge (cfun, last, 0);
    1874        46857 :   if (bound_count > bound_limit)
    1875              :     {
    1876        15330 :       *(ipa_predicate *) e->aux = true;
    1877        15330 :       vec_free (param_ops);
    1878        15330 :       return;
    1879              :     }
    1880              : 
    1881        31527 :   ipa_predicate p_seg = true;
    1882        31527 :   ipa_predicate p_all = false;
    1883              : 
    1884        31527 :   if (vr_type != VR_RANGE)
    1885              :     {
    1886        31006 :       vr_wmin = wi::to_wide (TYPE_MIN_VALUE (type));
    1887        31006 :       vr_wmax = wi::to_wide (TYPE_MAX_VALUE (type));
    1888              :     }
    1889              : 
    1890              :   /* Construct predicate to represent default range set that is negation of
    1891              :      all case ranges.  Case range is classified as containing single/non-single
    1892              :      values.  Suppose a piece of case ranges in the following.
    1893              : 
    1894              :                 [D1...D2]  [S1] ... [Sn]  [D3...D4]
    1895              : 
    1896              :      To represent default case's range sets between two non-single value
    1897              :      case ranges (From D2 to D3), we construct predicate as:
    1898              : 
    1899              :               D2 < x < D3 && x != S1 && ... && x != Sn
    1900              :    */
    1901        98202 :   for (size_t i = 0; i < ranges.length (); i++)
    1902              :     {
    1903        66770 :       tree min = ranges[i].first;
    1904        66770 :       tree max = ranges[i].second;
    1905              : 
    1906        66770 :       if (min == max)
    1907        83126 :         p_seg &= add_condition (summary, params_summary, index,
    1908              :                                 param_type, &aggpos, NE_EXPR,
    1909        41563 :                                 min, param_ops);
    1910              :       else
    1911              :         {
    1912              :           /* Do not create sub-predicate for range that is beyond low bound
    1913              :              of switch index.  */
    1914        25207 :           if (wi::lt_p (vr_wmin, wi::to_wide (min), TYPE_SIGN (type)))
    1915              :             {
    1916        17747 :               p_seg &= add_condition (summary, params_summary, index,
    1917              :                                       param_type, &aggpos,
    1918        17747 :                                       LT_EXPR, min, param_ops);
    1919        17747 :               p_all = p_all.or_with (summary->conds, p_seg);
    1920              :             }
    1921              : 
    1922              :           /* Do not create sub-predicate for range that is beyond up bound
    1923              :              of switch index.  */
    1924        25207 :           if (wi::le_p (vr_wmax, wi::to_wide (max), TYPE_SIGN (type)))
    1925              :             {
    1926           95 :               p_seg = false;
    1927           95 :               break;
    1928              :             }
    1929              : 
    1930        25112 :           p_seg = add_condition (summary, params_summary, index,
    1931              :                                  param_type, &aggpos, GT_EXPR,
    1932              :                                  max, param_ops);
    1933              :         }
    1934              :     }
    1935              : 
    1936        31527 :   p_all = p_all.or_with (summary->conds, p_seg);
    1937        31527 :   *(ipa_predicate *) e->aux
    1938        31527 :     = p_all.or_with (summary->conds, *(ipa_predicate *) e->aux);
    1939              : 
    1940        37989 :   vec_free (param_ops);
    1941        46857 : }
    1942              : 
    1943              : 
    1944              : /* For each BB in NODE attach to its AUX pointer predicate under
    1945              :    which it is executable.  */
    1946              : 
    1947              : static void
    1948      6243817 : compute_bb_predicates (struct ipa_func_body_info *fbi,
    1949              :                        struct cgraph_node *node,
    1950              :                        class ipa_fn_summary *summary,
    1951              :                        class ipa_node_params *params_summary)
    1952              : {
    1953      6243817 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    1954      6243817 :   bool done = false;
    1955      6243817 :   basic_block bb;
    1956              : 
    1957     41147293 :   FOR_EACH_BB_FN (bb, my_function)
    1958              :     {
    1959     34903476 :       set_cond_stmt_execution_predicate (fbi, summary, params_summary, bb);
    1960     34903476 :       set_switch_stmt_execution_predicate (fbi, summary, params_summary, bb);
    1961              :     }
    1962              : 
    1963              :   /* Entry block is always executable.  */
    1964      6243817 :   ENTRY_BLOCK_PTR_FOR_FN (my_function)->aux
    1965      6243817 :     = edge_predicate_pool.allocate ();
    1966      6243817 :   *(ipa_predicate *) ENTRY_BLOCK_PTR_FOR_FN (my_function)->aux = true;
    1967              : 
    1968              :   /* A simple dataflow propagation of predicates forward in the CFG.
    1969              :      TODO: work in reverse postorder.  */
    1970     18850473 :   while (!done)
    1971              :     {
    1972     12606656 :       done = true;
    1973     87513915 :       FOR_EACH_BB_FN (bb, my_function)
    1974              :         {
    1975     74907259 :           ipa_predicate p = false;
    1976     74907259 :           edge e;
    1977     74907259 :           edge_iterator ei;
    1978     92980557 :           FOR_EACH_EDGE (e, ei, bb->preds)
    1979              :             {
    1980     79646410 :               if (e->src->aux)
    1981              :                 {
    1982     77896345 :                   ipa_predicate this_bb_predicate
    1983              :                     = *(ipa_predicate *) e->src->aux;
    1984     77896345 :                   if (e->aux)
    1985      5199769 :                     this_bb_predicate &= (*(ipa_predicate *) e->aux);
    1986     77896345 :                   p = p.or_with (summary->conds, this_bb_predicate);
    1987     77896345 :                   if (p == true)
    1988              :                     break;
    1989              :                 }
    1990              :             }
    1991     74907259 :           if (p != false)
    1992              :             {
    1993     73765035 :               basic_block pdom_bb;
    1994              : 
    1995     73765035 :               if (!bb->aux)
    1996              :                 {
    1997     27314655 :                   done = false;
    1998     27314655 :                   bb->aux = edge_predicate_pool.allocate ();
    1999     27314655 :                   *((ipa_predicate *) bb->aux) = p;
    2000              :                 }
    2001     46450380 :               else if (p != *(ipa_predicate *) bb->aux)
    2002              :                 {
    2003              :                   /* This OR operation is needed to ensure monotonous data flow
    2004              :                      in the case we hit the limit on number of clauses and the
    2005              :                      and/or operations above give approximate answers.  */
    2006       129501 :                   p = p.or_with (summary->conds, *(ipa_predicate *)bb->aux);
    2007       129501 :                   if (p != *(ipa_predicate *)bb->aux)
    2008              :                     {
    2009       106068 :                       done = false;
    2010       106068 :                       *((ipa_predicate *)bb->aux) = p;
    2011              :                     }
    2012              :                 }
    2013              : 
    2014              :               /* For switch/if statement, we can OR-combine predicates of all
    2015              :                  its cases/branches to get predicate for basic block in their
    2016              :                  convergence point, but sometimes this will generate very
    2017              :                  complicated predicate.  Actually, we can get simplified
    2018              :                  predicate in another way by using the fact that predicate
    2019              :                  for a basic block must also hold true for its post dominators.
    2020              :                  To be specific, basic block in convergence point of
    2021              :                  conditional statement should include predicate of the
    2022              :                  statement.  */
    2023     73765035 :               pdom_bb = get_immediate_dominator (CDI_POST_DOMINATORS, bb);
    2024     73765035 :               if (pdom_bb == EXIT_BLOCK_PTR_FOR_FN (my_function) || !pdom_bb)
    2025              :                 ;
    2026     38052247 :               else if (!pdom_bb->aux)
    2027              :                 {
    2028      7588807 :                   done = false;
    2029      7588807 :                   pdom_bb->aux = edge_predicate_pool.allocate ();
    2030      7588807 :                   *((ipa_predicate *)pdom_bb->aux) = p;
    2031              :                 }
    2032     30463440 :               else if (p != *(ipa_predicate *)pdom_bb->aux)
    2033              :                 {
    2034      3414882 :                   p = p.or_with (summary->conds,
    2035              :                                  *(ipa_predicate *)pdom_bb->aux);
    2036      3414882 :                   if (p != *(ipa_predicate *)pdom_bb->aux)
    2037              :                     {
    2038       154940 :                       done = false;
    2039       154940 :                       *((ipa_predicate *)pdom_bb->aux) = p;
    2040              :                     }
    2041              :                 }
    2042              :             }
    2043              :         }
    2044              :     }
    2045      6243817 : }
    2046              : 
    2047              : 
    2048              : /* Return predicate specifying when the STMT might have result that is not
    2049              :    a compile time constant.  */
    2050              : 
    2051              : static ipa_predicate
    2052      4244607 : will_be_nonconstant_expr_predicate (ipa_func_body_info *fbi,
    2053              :                                     class ipa_fn_summary *summary,
    2054              :                                     class ipa_node_params *params_summary,
    2055              :                                     tree expr,
    2056              :                                     vec<ipa_predicate> nonconstant_names)
    2057              : {
    2058      4244607 :   tree parm;
    2059      4244607 :   int index;
    2060              : 
    2061      4492636 :   while (UNARY_CLASS_P (expr))
    2062       248029 :     expr = TREE_OPERAND (expr, 0);
    2063              : 
    2064      4244607 :   parm = unmodified_parm (fbi, NULL, expr, NULL);
    2065      4244607 :   if (parm && (index = ipa_get_param_decl_index (fbi->info, parm)) >= 0)
    2066       228940 :     return add_condition (summary, params_summary, index, TREE_TYPE (parm), NULL,
    2067       228940 :                           ipa_predicate::changed, NULL_TREE);
    2068      4015667 :   if (is_gimple_min_invariant (expr))
    2069        62403 :     return false;
    2070      3953264 :   if (TREE_CODE (expr) == SSA_NAME)
    2071      3771064 :     return nonconstant_names[SSA_NAME_VERSION (expr)];
    2072       182200 :   if (BINARY_CLASS_P (expr) || COMPARISON_CLASS_P (expr))
    2073              :     {
    2074       181588 :       ipa_predicate p1
    2075       181588 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2076              :                                               params_summary,
    2077       181588 :                                               TREE_OPERAND (expr, 0),
    2078              :                                               nonconstant_names);
    2079       181588 :       if (p1 == true)
    2080       106290 :         return p1;
    2081              : 
    2082        75298 :       ipa_predicate p2
    2083        75298 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2084              :                                               params_summary,
    2085        75298 :                                               TREE_OPERAND (expr, 1),
    2086              :                                               nonconstant_names);
    2087        75298 :       return p1.or_with (summary->conds, p2);
    2088              :     }
    2089          612 :   else if (TREE_CODE (expr) == COND_EXPR)
    2090              :     {
    2091          184 :       ipa_predicate p1
    2092          184 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2093              :                                               params_summary,
    2094          184 :                                               TREE_OPERAND (expr, 0),
    2095              :                                               nonconstant_names);
    2096          184 :       if (p1 == true)
    2097           33 :         return p1;
    2098              : 
    2099          151 :       ipa_predicate p2
    2100          151 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2101              :                                               params_summary,
    2102          151 :                                               TREE_OPERAND (expr, 1),
    2103              :                                               nonconstant_names);
    2104          151 :       if (p2 == true)
    2105          151 :         return p2;
    2106            0 :       p1 = p1.or_with (summary->conds, p2);
    2107            0 :       p2 = will_be_nonconstant_expr_predicate (fbi, summary,
    2108              :                                                params_summary,
    2109            0 :                                                TREE_OPERAND (expr, 2),
    2110              :                                                nonconstant_names);
    2111            0 :       return p2.or_with (summary->conds, p1);
    2112              :     }
    2113          428 :   else if (TREE_CODE (expr) == CALL_EXPR)
    2114          428 :     return true;
    2115              :   else
    2116              :     {
    2117            0 :       debug_tree (expr);
    2118            0 :       gcc_unreachable ();
    2119              :     }
    2120              : }
    2121              : 
    2122              : 
    2123              : /* Return predicate specifying when the STMT might have result that is not
    2124              :    a compile time constant.  */
    2125              : 
    2126              : static ipa_predicate
    2127    113054209 : will_be_nonconstant_predicate (struct ipa_func_body_info *fbi,
    2128              :                                class ipa_fn_summary *summary,
    2129              :                                class ipa_node_params *params_summary,
    2130              :                                gimple *stmt,
    2131              :                                vec<ipa_predicate> nonconstant_names)
    2132              : {
    2133    113054209 :   ipa_predicate p = true;
    2134    113054209 :   ssa_op_iter iter;
    2135    113054209 :   tree use;
    2136    113054209 :   tree param_type = NULL_TREE;
    2137    113054209 :   ipa_predicate op_non_const;
    2138    113054209 :   bool is_load;
    2139    113054209 :   int base_index;
    2140    113054209 :   struct agg_position_info aggpos;
    2141              : 
    2142              :   /* What statements might be optimized away
    2143              :      when their arguments are constant.  */
    2144    113054209 :   if (gimple_code (stmt) != GIMPLE_ASSIGN
    2145     38829545 :       && gimple_code (stmt) != GIMPLE_COND
    2146     27507394 :       && gimple_code (stmt) != GIMPLE_SWITCH
    2147    140479236 :       && (gimple_code (stmt) != GIMPLE_CALL
    2148     20589128 :           || !(gimple_call_flags (stmt) & ECF_CONST)))
    2149     25815008 :     return p;
    2150              : 
    2151              :   /* Stores will stay anyway.  */
    2152     87239201 :   if (gimple_store_p (stmt))
    2153     25476734 :     return p;
    2154              : 
    2155     61762467 :   is_load = gimple_assign_load_p (stmt);
    2156              : 
    2157              :   /* Loads can be optimized when the value is known.  */
    2158     61762467 :   if (is_load)
    2159              :     {
    2160     17779255 :       tree op = gimple_assign_rhs1 (stmt);
    2161     17779255 :       if (!decompose_param_expr (fbi, stmt, op, &base_index, &param_type,
    2162              :                                  &aggpos))
    2163     14564796 :         return p;
    2164              :     }
    2165              :   else
    2166     43983212 :     base_index = -1;
    2167              : 
    2168              :   /* See if we understand all operands before we start
    2169              :      adding conditionals.  */
    2170     63791085 :   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2171              :     {
    2172     46875655 :       tree parm = unmodified_parm (fbi, stmt, use, NULL);
    2173              :       /* For arguments we can build a condition.  */
    2174     46875655 :       if (parm && ipa_get_param_decl_index (fbi->info, parm) >= 0)
    2175      8385129 :         continue;
    2176     38490526 :       if (TREE_CODE (use) != SSA_NAME)
    2177            0 :         return p;
    2178              :       /* If we know when operand is constant,
    2179              :          we still can say something useful.  */
    2180     38490526 :       if (nonconstant_names[SSA_NAME_VERSION (use)] != true)
    2181      8208285 :         continue;
    2182     30282241 :       return p;
    2183              :     }
    2184              : 
    2185     16915430 :   if (is_load)
    2186      3214378 :     op_non_const =
    2187      3214378 :       add_condition (summary, params_summary,
    2188              :                      base_index, param_type, &aggpos,
    2189              :                      ipa_predicate::changed, NULL_TREE);
    2190              :   else
    2191     13701052 :     op_non_const = false;
    2192     32471993 :   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2193              :     {
    2194     15556563 :       tree parm = unmodified_parm (fbi, stmt, use, NULL);
    2195     15556563 :       int index;
    2196              : 
    2197     15556563 :       if (parm && (index = ipa_get_param_decl_index (fbi->info, parm)) >= 0)
    2198              :         {
    2199      7892138 :           if (index != base_index)
    2200      5373116 :             p = add_condition (summary, params_summary, index,
    2201      5373116 :                                TREE_TYPE (parm), NULL,
    2202              :                                ipa_predicate::changed, NULL_TREE);
    2203              :           else
    2204      2519022 :             continue;
    2205              :         }
    2206              :       else
    2207      7664425 :         p = nonconstant_names[SSA_NAME_VERSION (use)];
    2208     13037541 :       op_non_const = p.or_with (summary->conds, op_non_const);
    2209              :     }
    2210     16915430 :   if ((gimple_code (stmt) == GIMPLE_ASSIGN || gimple_code (stmt) == GIMPLE_CALL)
    2211     14754515 :       && gimple_op (stmt, 0)
    2212     31377185 :       && TREE_CODE (gimple_op (stmt, 0)) == SSA_NAME)
    2213     14461755 :     nonconstant_names[SSA_NAME_VERSION (gimple_op (stmt, 0))]
    2214     14461755 :       = op_non_const;
    2215     16915430 :   return op_non_const;
    2216              : }
    2217              : 
    2218              : struct record_modified_bb_info
    2219              : {
    2220              :   tree op;
    2221              :   bitmap bb_set;
    2222              :   gimple *stmt;
    2223              : };
    2224              : 
    2225              : /* Value is initialized in INIT_BB and used in USE_BB.  We want to compute
    2226              :    probability how often it changes between USE_BB.
    2227              :    INIT_BB->count/USE_BB->count is an estimate, but if INIT_BB
    2228              :    is in different loop nest, we can do better.
    2229              :    This is all just estimate.  In theory we look for minimal cut separating
    2230              :    INIT_BB and USE_BB, but we only want to anticipate loop invariant motion
    2231              :    anyway.  */
    2232              : 
    2233              : static basic_block
    2234     10370757 : get_minimal_bb (basic_block init_bb, basic_block use_bb)
    2235              : {
    2236     10370757 :   class loop *l = find_common_loop (init_bb->loop_father, use_bb->loop_father);
    2237     10370757 :   if (l && l->header->count < init_bb->count)
    2238       371748 :     return l->header;
    2239              :   return init_bb;
    2240              : }
    2241              : 
    2242              : /* Callback of walk_aliased_vdefs.  Records basic blocks where the value may be
    2243              :    set except for info->stmt.  */
    2244              : 
    2245              : static bool
    2246      4825829 : record_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data)
    2247              : {
    2248      4825829 :   struct record_modified_bb_info *info =
    2249              :     (struct record_modified_bb_info *) data;
    2250      4825829 :   if (SSA_NAME_DEF_STMT (vdef) == info->stmt)
    2251              :     return false;
    2252      4797255 :   if (gimple_clobber_p (SSA_NAME_DEF_STMT (vdef)))
    2253              :     return false;
    2254      4750355 :   bitmap_set_bit (info->bb_set,
    2255      4750355 :                   SSA_NAME_IS_DEFAULT_DEF (vdef)
    2256            0 :                   ? ENTRY_BLOCK_PTR_FOR_FN (cfun)->index
    2257              :                   : get_minimal_bb
    2258      4750355 :                          (gimple_bb (SSA_NAME_DEF_STMT (vdef)),
    2259      4750355 :                           gimple_bb (info->stmt))->index);
    2260      4750355 :   if (dump_file)
    2261              :     {
    2262            0 :       fprintf (dump_file, "     Param ");
    2263            0 :       print_generic_expr (dump_file, info->op, TDF_SLIM);
    2264            0 :       fprintf (dump_file, " changed at bb %i, minimal: %i stmt: ",
    2265            0 :                gimple_bb (SSA_NAME_DEF_STMT (vdef))->index,
    2266              :                get_minimal_bb
    2267            0 :                          (gimple_bb (SSA_NAME_DEF_STMT (vdef)),
    2268            0 :                           gimple_bb (info->stmt))->index);
    2269            0 :       print_gimple_stmt (dump_file, SSA_NAME_DEF_STMT (vdef), 0);
    2270              :     }
    2271              :   return false;
    2272              : }
    2273              : 
    2274              : /* Return probability (based on REG_BR_PROB_BASE) that I-th parameter of STMT
    2275              :    will change since last invocation of STMT.
    2276              : 
    2277              :    Value 0 is reserved for compile time invariants.
    2278              :    For common parameters it is REG_BR_PROB_BASE.  For loop invariants it
    2279              :    ought to be REG_BR_PROB_BASE / estimated_iters.  */
    2280              : 
    2281              : static int
    2282     38120168 : param_change_prob (ipa_func_body_info *fbi, gimple *stmt, int i)
    2283              : {
    2284     38120168 :   tree op = gimple_call_arg (stmt, i);
    2285     38120168 :   basic_block bb = gimple_bb (stmt);
    2286              : 
    2287     38120168 :   if (TREE_CODE (op) == WITH_SIZE_EXPR)
    2288          299 :     op = TREE_OPERAND (op, 0);
    2289              : 
    2290     38120168 :   tree base = get_base_address (op);
    2291              : 
    2292              :   /* Global invariants never change.  */
    2293     38120168 :   if (is_gimple_min_invariant (base))
    2294              :     return 0;
    2295              : 
    2296              :   /* We would have to do non-trivial analysis to really work out what
    2297              :      is the probability of value to change (i.e. when init statement
    2298              :      is in a sibling loop of the call).
    2299              : 
    2300              :      We do an conservative estimate: when call is executed N times more often
    2301              :      than the statement defining value, we take the frequency 1/N.  */
    2302     19141107 :   if (TREE_CODE (base) == SSA_NAME)
    2303              :     {
    2304     16851915 :       profile_count init_count;
    2305              : 
    2306     25632230 :       if (!bb->count.nonzero_p ())
    2307              :         return REG_BR_PROB_BASE;
    2308              : 
    2309      8635897 :       if (SSA_NAME_IS_DEFAULT_DEF (base))
    2310      3015495 :         init_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2311              :       else
    2312      5620402 :         init_count = get_minimal_bb
    2313      5620402 :                       (gimple_bb (SSA_NAME_DEF_STMT (base)),
    2314              :                        gimple_bb (stmt))->count;
    2315              : 
    2316      8635897 :       if (init_count < bb->count)
    2317       451141 :         return MAX ((init_count.to_sreal_scale (bb->count)
    2318              :                      * REG_BR_PROB_BASE).to_int (), 1);
    2319              :       return REG_BR_PROB_BASE;
    2320              :     }
    2321              :   else
    2322              :     {
    2323      2289192 :       ao_ref refd;
    2324      2289192 :       profile_count max = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2325      2289192 :       struct record_modified_bb_info info;
    2326      2289192 :       tree init = ctor_for_folding (base);
    2327              : 
    2328      2289192 :       if (init != error_mark_node)
    2329              :         return 0;
    2330      5078540 :       if (!bb->count.nonzero_p () || fbi->aa_walk_budget == 0)
    2331              :         return REG_BR_PROB_BASE;
    2332      1407666 :       if (dump_file)
    2333              :         {
    2334            0 :           fprintf (dump_file, "     Analyzing param change probability of ");
    2335            0 :           print_generic_expr (dump_file, op, TDF_SLIM);
    2336            0 :           fprintf (dump_file, "\n");
    2337              :         }
    2338      1407666 :       ao_ref_init (&refd, op);
    2339      1407666 :       info.op = op;
    2340      1407666 :       info.stmt = stmt;
    2341      1407666 :       info.bb_set = BITMAP_ALLOC (NULL);
    2342      1407666 :       int walked
    2343      2815332 :         = walk_aliased_vdefs (&refd, gimple_vuse (stmt), record_modified, &info,
    2344              :                               NULL, NULL, fbi->aa_walk_budget);
    2345      1407666 :       if (walked > 0)
    2346      1278658 :         fbi->aa_walk_budget -= walked;
    2347      1407666 :       if (walked < 0 || bitmap_bit_p (info.bb_set, bb->index))
    2348              :         {
    2349       867729 :           if (walked < 0)
    2350          206 :             fbi->aa_walk_budget = 0;
    2351       867729 :           if (dump_file)
    2352              :             {
    2353            0 :               if (walked < 0)
    2354            0 :                 fprintf (dump_file, "     Ran out of AA walking budget.\n");
    2355              :               else
    2356            0 :                 fprintf (dump_file, "     Set in same BB as used.\n");
    2357              :             }
    2358       867729 :           BITMAP_FREE (info.bb_set);
    2359       867729 :           return REG_BR_PROB_BASE;
    2360              :         }
    2361              : 
    2362       539937 :       bitmap_iterator bi;
    2363       539937 :       unsigned index;
    2364              :       /* Lookup the most frequent update of the value and believe that
    2365              :          it dominates all the other; precise analysis here is difficult.  */
    2366      1526322 :       EXECUTE_IF_SET_IN_BITMAP (info.bb_set, 0, index, bi)
    2367       986385 :         max = profile_count::max_prefer_initialized
    2368       986385 :                 (max, BASIC_BLOCK_FOR_FN (cfun, index)->count);
    2369       539937 :       if (dump_file)
    2370              :         {
    2371            0 :           fprintf (dump_file, "     Set with count ");
    2372            0 :           max.dump (dump_file);
    2373            0 :           fprintf (dump_file, " and used with count ");
    2374            0 :           bb->count.dump (dump_file);
    2375            0 :           fprintf (dump_file, " freq %f\n",
    2376            0 :                    max.to_sreal_scale (bb->count).to_double ());
    2377              :         }
    2378              : 
    2379       539937 :       BITMAP_FREE (info.bb_set);
    2380       539937 :       if (max < bb->count)
    2381        91036 :         return MAX ((max.to_sreal_scale (bb->count)
    2382              :                      * REG_BR_PROB_BASE).to_int (), 1);
    2383              :       return REG_BR_PROB_BASE;
    2384              :     }
    2385              : }
    2386              : 
    2387              : /* Find whether a basic block BB is the final block of a (half) diamond CFG
    2388              :    sub-graph and if the predicate the condition depends on is known.  If so,
    2389              :    return true and store the pointer the predicate in *P.  */
    2390              : 
    2391              : static bool
    2392      6345752 : phi_result_unknown_predicate (ipa_func_body_info *fbi,
    2393              :                               ipa_fn_summary *summary,
    2394              :                               class ipa_node_params *params_summary,
    2395              :                               basic_block bb,
    2396              :                               ipa_predicate *p,
    2397              :                               vec<ipa_predicate> nonconstant_names)
    2398              : {
    2399      6345752 :   edge e;
    2400      6345752 :   edge_iterator ei;
    2401      6345752 :   basic_block first_bb = NULL;
    2402              : 
    2403      6345752 :   if (single_pred_p (bb))
    2404              :     {
    2405        20379 :       *p = false;
    2406        20379 :       return true;
    2407              :     }
    2408              : 
    2409     14582762 :   FOR_EACH_EDGE (e, ei, bb->preds)
    2410              :     {
    2411     12454451 :       if (single_succ_p (e->src))
    2412              :         {
    2413     13046235 :           if (!single_pred_p (e->src))
    2414              :             return false;
    2415      7315694 :           if (!first_bb)
    2416      3186584 :             first_bb = single_pred (e->src);
    2417      4129110 :           else if (single_pred (e->src) != first_bb)
    2418              :             return false;
    2419              :         }
    2420              :       else
    2421              :         {
    2422      4146112 :           if (!first_bb)
    2423              :             first_bb = e->src;
    2424      1423771 :           else if (e->src != first_bb)
    2425              :             return false;
    2426              :         }
    2427              :     }
    2428              : 
    2429      2128311 :   if (!first_bb)
    2430              :     return false;
    2431              : 
    2432      4256622 :   gcond *stmt = safe_dyn_cast <gcond *> (*gsi_last_bb (first_bb));
    2433      2081776 :   if (!stmt
    2434      2081776 :       || !is_gimple_ip_invariant (gimple_cond_rhs (stmt)))
    2435       309314 :     return false;
    2436              : 
    2437      1818997 :   *p = will_be_nonconstant_expr_predicate (fbi, summary, params_summary,
    2438              :                                            gimple_cond_lhs (stmt),
    2439              :                                            nonconstant_names);
    2440      1818997 :   if (*p == true)
    2441              :     return false;
    2442              :   else
    2443              :     return true;
    2444              : }
    2445              : 
    2446              : /* Given a PHI statement in a function described by inline properties SUMMARY
    2447              :    and *P being the predicate describing whether the selected PHI argument is
    2448              :    known, store a predicate for the result of the PHI statement into
    2449              :    NONCONSTANT_NAMES, if possible.  */
    2450              : 
    2451              : static void
    2452       698402 : predicate_for_phi_result (class ipa_fn_summary *summary, gphi *phi,
    2453              :                           ipa_predicate *p,
    2454              :                           vec<ipa_predicate> nonconstant_names)
    2455              : {
    2456       698402 :   unsigned i;
    2457              : 
    2458       992631 :   for (i = 0; i < gimple_phi_num_args (phi); i++)
    2459              :     {
    2460       871940 :       tree arg = gimple_phi_arg (phi, i)->def;
    2461       871940 :       if (!is_gimple_min_invariant (arg))
    2462              :         {
    2463       749331 :           gcc_assert (TREE_CODE (arg) == SSA_NAME);
    2464      1498662 :           *p = p->or_with (summary->conds,
    2465       749331 :                            nonconstant_names[SSA_NAME_VERSION (arg)]);
    2466       749331 :           if (*p == true)
    2467              :             return;
    2468              :         }
    2469              :     }
    2470              : 
    2471       120691 :   if (dump_file && (dump_flags & TDF_DETAILS))
    2472              :     {
    2473            3 :       fprintf (dump_file, "\t\tphi predicate: ");
    2474            3 :       p->dump (dump_file, summary->conds);
    2475              :     }
    2476       120691 :   nonconstant_names[SSA_NAME_VERSION (gimple_phi_result (phi))] = *p;
    2477              : }
    2478              : 
    2479              : /* For a typical usage of __builtin_expect (a<b, 1), we
    2480              :    may introduce an extra relation stmt:
    2481              :    With the builtin, we have
    2482              :      t1 = a <= b;
    2483              :      t2 = (long int) t1;
    2484              :      t3 = __builtin_expect (t2, 1);
    2485              :      if (t3 != 0)
    2486              :        goto ...
    2487              :    Without the builtin, we have
    2488              :      if (a<=b)
    2489              :        goto...
    2490              :    This affects the size/time estimation and may have
    2491              :    an impact on the earlier inlining.
    2492              :    Here find this pattern and fix it up later.  */
    2493              : 
    2494              : static gimple *
    2495     40766049 : find_foldable_builtin_expect (basic_block bb)
    2496              : {
    2497     40766049 :   gimple_stmt_iterator bsi;
    2498              : 
    2499    280150933 :   for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
    2500              :     {
    2501    198778961 :       gimple *stmt = gsi_stmt (bsi);
    2502    198778961 :       if (gimple_call_builtin_p (stmt, BUILT_IN_EXPECT)
    2503    198569223 :           || gimple_call_builtin_p (stmt, BUILT_IN_EXPECT_WITH_PROBABILITY)
    2504    397348119 :           || gimple_call_internal_p (stmt, IFN_BUILTIN_EXPECT))
    2505              :         {
    2506       340738 :           tree var = gimple_call_lhs (stmt);
    2507       340738 :           tree arg = gimple_call_arg (stmt, 0);
    2508       340738 :           use_operand_p use_p;
    2509       340738 :           gimple *use_stmt;
    2510       340738 :           bool match = false;
    2511       340738 :           bool done = false;
    2512              : 
    2513       340738 :           if (!var || !arg)
    2514            3 :             continue;
    2515       340735 :           gcc_assert (TREE_CODE (var) == SSA_NAME);
    2516              : 
    2517       680164 :           while (TREE_CODE (arg) == SSA_NAME)
    2518              :             {
    2519       680164 :               gimple *stmt_tmp = SSA_NAME_DEF_STMT (arg);
    2520       680164 :               if (!is_gimple_assign (stmt_tmp))
    2521              :                 break;
    2522       672839 :               switch (gimple_assign_rhs_code (stmt_tmp))
    2523              :                 {
    2524              :                   case LT_EXPR:
    2525              :                   case LE_EXPR:
    2526              :                   case GT_EXPR:
    2527              :                   case GE_EXPR:
    2528              :                   case EQ_EXPR:
    2529              :                   case NE_EXPR:
    2530              :                     match = true;
    2531              :                     done = true;
    2532              :                     break;
    2533              :                   CASE_CONVERT:
    2534              :                     break;
    2535              :                   default:
    2536              :                     done = true;
    2537              :                     break;
    2538              :                 }
    2539       339429 :               if (done)
    2540              :                 break;
    2541       339429 :               arg = gimple_assign_rhs1 (stmt_tmp);
    2542              :             }
    2543              : 
    2544       305688 :           if (match && single_imm_use (var, &use_p, &use_stmt)
    2545       645980 :               && gimple_code (use_stmt) == GIMPLE_COND)
    2546       160126 :             return use_stmt;
    2547              :         }
    2548              :     }
    2549              :   return NULL;
    2550              : }
    2551              : 
    2552              : /* Return true when the basic blocks contains only clobbers followed by RESX.
    2553              :    Such BBs are kept around to make removal of dead stores possible with
    2554              :    presence of EH and will be optimized out by optimize_clobbers later in the
    2555              :    game.
    2556              : 
    2557              :    NEED_EH is used to recurse in case the clobber has non-EH predecessors
    2558              :    that can be clobber only, too.. When it is false, the RESX is not necessary
    2559              :    on the end of basic block.  */
    2560              : 
    2561              : static bool
    2562     41354376 : clobber_only_eh_bb_p (basic_block bb, bool need_eh = true)
    2563              : {
    2564     41354376 :   gimple_stmt_iterator gsi = gsi_last_bb (bb);
    2565     41354376 :   edge_iterator ei;
    2566     41354376 :   edge e;
    2567              : 
    2568     41354376 :   if (need_eh)
    2569              :     {
    2570     41286771 :       if (gsi_end_p (gsi))
    2571              :         return false;
    2572     40164452 :       if (gimple_code (gsi_stmt (gsi)) != GIMPLE_RESX)
    2573              :         return false;
    2574      1009773 :       gsi_prev (&gsi);
    2575              :     }
    2576     40834119 :   else if (!single_succ_p (bb))
    2577              :     return false;
    2578              : 
    2579      4492697 :   for (; !gsi_end_p (gsi); gsi_prev (&gsi))
    2580              :     {
    2581      2691220 :       gimple *stmt = gsi_stmt (gsi);
    2582      2691220 :       if (is_gimple_debug (stmt))
    2583       883960 :         continue;
    2584      1807260 :       if (gimple_clobber_p (stmt))
    2585       856543 :         continue;
    2586       950717 :       if (gimple_code (stmt) == GIMPLE_LABEL)
    2587              :         break;
    2588              :       return false;
    2589              :     }
    2590              : 
    2591              :   /* See if all predecessors are either throws or clobber only BBs.  */
    2592      2968723 :   FOR_EACH_EDGE (e, ei, bb->preds)
    2593      2446548 :     if (!(e->flags & EDGE_EH)
    2594      2446548 :         && !clobber_only_eh_bb_p (e->src, false))
    2595              :       return false;
    2596              : 
    2597              :   return true;
    2598              : }
    2599              : 
    2600              : /* Return true if STMT compute a floating point expression that may be affected
    2601              :    by -ffast-math and similar flags.  */
    2602              : 
    2603              : static bool
    2604     93485125 : fp_expression_p (gimple *stmt)
    2605              : {
    2606     93485125 :   ssa_op_iter i;
    2607     93485125 :   tree op;
    2608              : 
    2609    209965492 :   FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_DEF|SSA_OP_USE)
    2610    117076134 :     if (FLOAT_TYPE_P (TREE_TYPE (op)))
    2611              :       return true;
    2612              :   return false;
    2613              : }
    2614              : 
    2615              : /* Return true if T references memory location that is local
    2616              :    for the function (that means, dead after return) or read-only.  */
    2617              : 
    2618              : bool
    2619     58356515 : refs_local_or_readonly_memory_p (tree t)
    2620              : {
    2621              :   /* Non-escaping memory is fine.  */
    2622     58356515 :   t = get_base_address (t);
    2623     58356515 :   if ((TREE_CODE (t) == MEM_REF
    2624     58356515 :       || TREE_CODE (t) == TARGET_MEM_REF))
    2625     24684412 :     return points_to_local_or_readonly_memory_p (TREE_OPERAND (t, 0));
    2626              : 
    2627              :   /* Automatic variables are fine.  */
    2628     33672103 :   if (DECL_P (t)
    2629     33672103 :       && auto_var_in_fn_p (t, current_function_decl))
    2630              :     return true;
    2631              : 
    2632              :   /* Read-only variables are fine.  */
    2633     10949496 :   if (DECL_P (t) && TREE_READONLY (t))
    2634              :     return true;
    2635              : 
    2636              :   return false;
    2637              : }
    2638              : 
    2639              : /* Return true if T is a pointer pointing to memory location that is local
    2640              :    for the function (that means, dead after return) or read-only.  */
    2641              : 
    2642              : bool
    2643     71386476 : points_to_local_or_readonly_memory_p (tree t)
    2644              : {
    2645              :   /* See if memory location is clearly invalid.  */
    2646     71386476 :   if (integer_zerop (t))
    2647      2423867 :     return flag_delete_null_pointer_checks;
    2648     68962609 :   if (TREE_CODE (t) == SSA_NAME)
    2649              :     {
    2650              :       /* For IPA passes we can consinder accesses to return slot local
    2651              :          even if it is not local in the sense that memory is dead by
    2652              :          the end of founction.
    2653              :          The outer function will see a store in the call assignment
    2654              :          and thus this will do right thing for all uses of this
    2655              :          function in the current IPA passes (modref, pure/const discovery
    2656              :          and inlining heuristics).  */
    2657     43661927 :       if (DECL_RESULT (current_function_decl)
    2658     43661927 :           && DECL_BY_REFERENCE (DECL_RESULT (current_function_decl))
    2659     44695459 :           && t == ssa_default_def (cfun, DECL_RESULT (current_function_decl)))
    2660              :         return true;
    2661     43354805 :       return !ptr_deref_may_alias_global_p (t, false);
    2662              :     }
    2663     25300682 :   if (TREE_CODE (t) == ADDR_EXPR
    2664     25300682 :       && (TREE_CODE (TREE_OPERAND (t, 0)) != TARGET_MEM_REF
    2665         4527 :           || TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)) != INTEGER_CST))
    2666     12996385 :     return refs_local_or_readonly_memory_p (TREE_OPERAND (t, 0));
    2667              :   return false;
    2668              : }
    2669              : 
    2670              : /* Return true if T is a pointer pointing to memory location that is possible
    2671              :    sra candidate if all functions it is passed to are inlined.  */
    2672              : 
    2673              : static bool
    2674     38120168 : points_to_possible_sra_candidate_p (tree t)
    2675              : {
    2676     38120168 :   if (TREE_CODE (t) != ADDR_EXPR)
    2677              :     return false;
    2678              : 
    2679     11296803 :   t = get_base_address (TREE_OPERAND (t, 0));
    2680              : 
    2681              :   /* Automatic variables are fine.  */
    2682     11296803 :   if (DECL_P (t)
    2683     11296803 :       && auto_var_in_fn_p (t, current_function_decl))
    2684              :     return true;
    2685              :   return false;
    2686              : }
    2687              : 
    2688              : /* Return true if BB only calls builtin_unreachable.
    2689              :    We skip empty basic blocks, debug statements, clobbers and predicts.
    2690              :    CACHE is used to memoize already analyzed blocks.  */
    2691              : 
    2692              : static bool
    2693     27113366 : builtin_unreachable_bb_p (basic_block bb, vec<unsigned char> &cache)
    2694              : {
    2695     27113366 :   if (cache[bb->index])
    2696      2531744 :     return cache[bb->index] - 1;
    2697     24581622 :   gimple_stmt_iterator si;
    2698     24581622 :   auto_vec <basic_block, 4> visited_bbs;
    2699     24581622 :   bool ret = false;
    2700     25382836 :   while (true)
    2701              :     {
    2702     25382836 :       bool empty_bb = true;
    2703     25382836 :       visited_bbs.safe_push (bb);
    2704     25382836 :       cache[bb->index] = 3;
    2705     25382836 :       for (si = gsi_start_nondebug_bb (bb);
    2706     26852959 :            !gsi_end_p (si) && empty_bb;
    2707      1470123 :            gsi_next_nondebug (&si))
    2708              :         {
    2709     25491121 :           if (gimple_code (gsi_stmt (si)) != GIMPLE_PREDICT
    2710     25123498 :               && !gimple_clobber_p (gsi_stmt (si))
    2711     49545377 :               && !gimple_nop_p (gsi_stmt (si)))
    2712              :             {
    2713              :               empty_bb = false;
    2714              :               break;
    2715              :             }
    2716              :         }
    2717     25382836 :       if (!empty_bb)
    2718              :         break;
    2719              :       else
    2720      1361838 :         bb = single_succ_edge (bb)->dest;
    2721      1361838 :       if (cache[bb->index])
    2722              :         {
    2723       560624 :           ret = cache[bb->index] == 3 ? false : cache[bb->index] - 1;
    2724       560624 :           goto done;
    2725              :         }
    2726              :     }
    2727     24020998 :   if (gimple_call_builtin_p (gsi_stmt (si), BUILT_IN_UNREACHABLE)
    2728     24020998 :       || gimple_call_builtin_p (gsi_stmt (si), BUILT_IN_UNREACHABLE_TRAP))
    2729              :     ret = true;
    2730     24581622 : done:
    2731     99127702 :   for (basic_block vbb:visited_bbs)
    2732     25382836 :     cache[vbb->index] = (unsigned char)ret + 1;
    2733     24581622 :   return ret;
    2734     24581622 : }
    2735              : 
    2736              : static bool
    2737     13677525 : guards_builtin_unreachable (basic_block bb, vec<unsigned char> &cache)
    2738              : {
    2739     13677525 :   edge_iterator ei;
    2740     13677525 :   edge e;
    2741     40532283 :   FOR_EACH_EDGE (e, ei, bb->succs)
    2742     27113366 :     if (builtin_unreachable_bb_p (e->dest, cache))
    2743              :       {
    2744       258608 :         if (dump_file && (dump_flags & TDF_DETAILS))
    2745            1 :           fprintf (dump_file,
    2746              :                    "BB %i ends with conditional guarding __builtin_unreachable;"
    2747              :                    " conditinal is unnecesary\n", bb->index);
    2748       258608 :         return true;
    2749              :       }
    2750              :   return false;
    2751              : }
    2752              : 
    2753              : #define STMT_NECESSARY GF_PLF_1
    2754              : 
    2755              : /* If STMT is not already marked necessary, mark it, and add it to the
    2756              :    worklist if ADD_TO_WORKLIST is true.  */
    2757              : 
    2758              : static inline void
    2759    170396482 : mark_stmt_necessary (gimple *stmt, auto_vec<gimple *> &worklist)
    2760              : {
    2761    170396482 :   gcc_assert (stmt);
    2762              : 
    2763    170396482 :   if (gimple_plf (stmt, STMT_NECESSARY))
    2764              :     return;
    2765              : 
    2766    141276186 :   if (dump_file && (dump_flags & TDF_DETAILS))
    2767              :     {
    2768          207 :       fprintf (dump_file, "Marking useful stmt: ");
    2769          207 :       print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
    2770          207 :       fprintf (dump_file, "\n");
    2771              :     }
    2772              : 
    2773    141276186 :   gimple_set_plf (stmt, STMT_NECESSARY, true);
    2774    141276186 :   worklist.safe_push (stmt);
    2775              : }
    2776              : 
    2777              : /* Mark the statement defining operand OP as necessary.  */
    2778              : 
    2779              : static inline void
    2780    120152058 : mark_operand_necessary (tree op, auto_vec<gimple *> &worklist)
    2781              : {
    2782    120152058 :   gimple *stmt = SSA_NAME_DEF_STMT (op);
    2783    120152058 :   if (gimple_nop_p (stmt))
    2784              :     return;
    2785     97509022 :   mark_stmt_necessary (stmt, worklist);
    2786              : }
    2787              : 
    2788              : /* Mark all statements that will remain in the body after optimizing out
    2789              :    conditionals guarding __builtin_unreachable which we keep to preserve
    2790              :    value ranges.  */
    2791              : 
    2792              : static void
    2793      7125308 : find_necessary_statements (struct cgraph_node *node)
    2794              : {
    2795      7125308 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    2796      7125308 :   auto_vec<unsigned char, 10> cache;
    2797      7125308 :   basic_block bb;
    2798      7125308 :   auto_vec<gimple *> worklist;
    2799              : 
    2800      7125308 :   cache.safe_grow_cleared (last_basic_block_for_fn (cfun));
    2801              :   /* Mark all obviously necessary statements.  */
    2802     48412079 :   FOR_EACH_BB_FN (bb, my_function)
    2803              :     {
    2804     41286771 :       for (gimple_stmt_iterator gsi = gsi_start_phis (bb);
    2805     52850563 :            !gsi_end_p (gsi); gsi_next (&gsi))
    2806     11563792 :         gimple_set_plf (gsi_stmt (gsi), STMT_NECESSARY, false);
    2807              : 
    2808    230683107 :       for (gimple_stmt_iterator bsi = gsi_start_bb (bb); !gsi_end_p (bsi);
    2809    148109565 :            gsi_next_nondebug (&bsi))
    2810              :         {
    2811    148109565 :           gimple *stmt = gsi_stmt (bsi);
    2812              : 
    2813    148109565 :           gimple_set_plf (stmt, STMT_NECESSARY, false);
    2814    148109565 :           if (gimple_has_side_effects (stmt)
    2815    121394832 :               || (is_ctrl_stmt (stmt)
    2816     21808387 :                   && (gimple_code (stmt) != GIMPLE_COND
    2817     13677525 :                       || !guards_builtin_unreachable (bb, cache)))
    2818     99845053 :               || gimple_store_p (stmt)
    2819    223353356 :               || gimple_code (stmt) == GIMPLE_ASM)
    2820     72887460 :             mark_stmt_necessary (stmt, worklist);
    2821              :         }
    2822              :     }
    2823    148401494 :   while (worklist.length () > 0)
    2824              :     {
    2825    141276186 :       gimple *stmt = worklist.pop ();
    2826              : 
    2827    141276186 :       if (dump_file && (dump_flags & TDF_DETAILS))
    2828              :         {
    2829          207 :           fprintf (dump_file, "processing: ");
    2830          207 :           print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
    2831          207 :           fprintf (dump_file, "\n");
    2832              :         }
    2833    141276186 :       if (gimple_code (stmt) == GIMPLE_PHI)
    2834     18304517 :         for (unsigned int k = 0; k < gimple_phi_num_args (stmt); k++)
    2835              :           {
    2836     12961101 :             tree arg = PHI_ARG_DEF (stmt, k);
    2837              : 
    2838     12961101 :             if (TREE_CODE (arg) == SSA_NAME)
    2839      9947009 :               mark_operand_necessary (arg, worklist);
    2840              :           }
    2841              :       else
    2842              :         {
    2843    135932770 :           ssa_op_iter iter;
    2844    135932770 :           tree use;
    2845              : 
    2846    246137819 :           FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2847    110205049 :             mark_operand_necessary (use, worklist);
    2848              :         }
    2849              :     }
    2850      7125308 : }
    2851              : 
    2852              : /* Analyze function body for NODE.
    2853              :    EARLY indicates run from early optimization pipeline.  */
    2854              : 
    2855              : static void
    2856      7125308 : analyze_function_body (struct cgraph_node *node, bool early)
    2857              : {
    2858      7125308 :   sreal time = opt_for_fn (node->decl, param_uninlined_function_time);
    2859              :   /* Estimate static overhead for function prologue/epilogue and alignment. */
    2860      7125308 :   int size = opt_for_fn (node->decl, param_uninlined_function_insns);
    2861              :   /* Benefits are scaled by probability of elimination that is in range
    2862              :      <0,2>.  */
    2863      7125308 :   basic_block bb;
    2864      7125308 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    2865      7125308 :   sreal freq;
    2866      7125308 :   class ipa_fn_summary *info = ipa_fn_summaries->get_create (node);
    2867      7125308 :   ipa_node_params *params_summary
    2868      7125308 :     = early ? NULL : ipa_node_params_sum->get (node);
    2869      7125308 :   ipa_predicate bb_predicate;
    2870      7125308 :   struct ipa_func_body_info fbi;
    2871      7125308 :   vec<ipa_predicate> nonconstant_names = vNULL;
    2872      7125308 :   int nblocks, n;
    2873      7125308 :   int *order;
    2874      7125308 :   gimple *fix_builtin_expect_stmt;
    2875              : 
    2876      7125308 :   gcc_assert (my_function && my_function->cfg);
    2877      7125308 :   gcc_assert (cfun == my_function);
    2878              : 
    2879      7125308 :   memset(&fbi, 0, sizeof(fbi));
    2880      7125308 :   vec_free (info->conds);
    2881      7125308 :   info->conds = NULL;
    2882      7125308 :   info->size_time_table.release ();
    2883      7125308 :   info->call_size_time_table.release ();
    2884              : 
    2885              :   /* When optimizing and analyzing for IPA inliner, initialize loop optimizer
    2886              :      so we can produce proper inline hints.
    2887              : 
    2888              :      When optimizing and analyzing for early inliner, initialize node params
    2889              :      so we can produce correct BB predicates.  */
    2890              : 
    2891      7125308 :   if (opt_for_fn (node->decl, optimize))
    2892              :     {
    2893      6243817 :       calculate_dominance_info (CDI_DOMINATORS);
    2894      6243817 :       calculate_dominance_info (CDI_POST_DOMINATORS);
    2895      6243817 :       if (!early)
    2896      1372124 :         loop_optimizer_init (LOOPS_NORMAL | LOOPS_HAVE_RECORDED_EXITS);
    2897              :       else
    2898              :         {
    2899      4871693 :           ipa_check_create_node_params ();
    2900      4871693 :           ipa_initialize_node_params (node);
    2901              :         }
    2902              : 
    2903      6243817 :       if (ipa_node_params_sum)
    2904              :         {
    2905      6243817 :           fbi.node = node;
    2906      6243817 :           fbi.info = ipa_node_params_sum->get (node);
    2907      6243817 :           fbi.bb_infos = vNULL;
    2908      6243817 :           fbi.bb_infos.safe_grow_cleared (last_basic_block_for_fn (cfun), true);
    2909      6243817 :           fbi.param_count = count_formal_params (node->decl);
    2910      6243817 :           fbi.aa_walk_budget = opt_for_fn (node->decl, param_ipa_max_aa_steps);
    2911              : 
    2912      6243817 :           nonconstant_names.safe_grow_cleared
    2913      6243817 :             (SSANAMES (my_function)->length (), true);
    2914              :         }
    2915              :     }
    2916              : 
    2917      7125308 :   if (dump_file)
    2918          247 :     fprintf (dump_file, "\nAnalyzing function body size: %s\n",
    2919              :              node->dump_name ());
    2920              : 
    2921              :   /* When we run into maximal number of entries, we assign everything to the
    2922              :      constant truth case.  Be sure to have it in list. */
    2923      7125308 :   bb_predicate = true;
    2924      7125308 :   info->account_size_time (0, 0, bb_predicate, bb_predicate);
    2925              : 
    2926      7125308 :   bb_predicate = ipa_predicate::not_inlined ();
    2927      7125308 :   info->account_size_time (opt_for_fn (node->decl,
    2928              :                                 param_uninlined_function_insns)
    2929              :                            * ipa_fn_summary::size_scale,
    2930      7125308 :                            opt_for_fn (node->decl,
    2931              :                                 param_uninlined_function_time),
    2932              :                            bb_predicate,
    2933              :                            bb_predicate);
    2934              : 
    2935              :   /* Only look for target information for inlinable functions.  */
    2936      7125308 :   bool scan_for_target_info =
    2937      7125308 :     info->inlinable
    2938     12795782 :     && targetm.target_option.need_ipa_fn_target_info (node->decl,
    2939      5670474 :                                                       info->target_info);
    2940              : 
    2941      7125308 :   if (fbi.info)
    2942      6243817 :     compute_bb_predicates (&fbi, node, info, params_summary);
    2943      7125308 :   find_necessary_statements (node);
    2944      7125308 :   const profile_count entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2945      7125308 :   order = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
    2946      7125308 :   nblocks = pre_and_rev_post_order_compute (NULL, order, false);
    2947     48412079 :   for (n = 0; n < nblocks; n++)
    2948              :     {
    2949     41286771 :       bb = BASIC_BLOCK_FOR_FN (cfun, order[n]);
    2950     41286771 :       freq = bb->count.to_sreal_scale (entry_count);
    2951     41286771 :       if (clobber_only_eh_bb_p (bb))
    2952              :         {
    2953       520722 :           if (dump_file && (dump_flags & TDF_DETAILS))
    2954            0 :             fprintf (dump_file, "\n Ignoring BB %i;"
    2955              :                      " it will be optimized away by cleanup_clobbers\n",
    2956              :                      bb->index);
    2957       520722 :           continue;
    2958              :         }
    2959              : 
    2960              :       /* TODO: Obviously predicates can be propagated down across CFG.  */
    2961     40766049 :       if (fbi.info)
    2962              :         {
    2963     34442930 :           if (bb->aux)
    2964     34442916 :             bb_predicate = *(ipa_predicate *)bb->aux;
    2965              :           else
    2966           14 :             bb_predicate = false;
    2967              :         }
    2968              :       else
    2969      6323119 :         bb_predicate = true;
    2970              : 
    2971     40766049 :       if (dump_file && (dump_flags & TDF_DETAILS))
    2972              :         {
    2973           67 :           fprintf (dump_file, "\n BB %i predicate:", bb->index);
    2974           67 :           bb_predicate.dump (dump_file, info->conds);
    2975              :         }
    2976              : 
    2977     40766049 :       if (fbi.info && nonconstant_names.exists ())
    2978              :         {
    2979     34442930 :           ipa_predicate phi_predicate;
    2980     34442930 :           bool first_phi = true;
    2981              : 
    2982     35141332 :           for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi);
    2983       698402 :                gsi_next (&bsi))
    2984              :             {
    2985      6428943 :               if (first_phi
    2986      6428943 :                   && !phi_result_unknown_predicate (&fbi, info,
    2987              :                                                     params_summary,
    2988              :                                                     bb,
    2989              :                                                     &phi_predicate,
    2990              :                                                     nonconstant_names))
    2991              :                 break;
    2992       698402 :               first_phi = false;
    2993       698402 :               if (dump_file && (dump_flags & TDF_DETAILS))
    2994              :                 {
    2995            3 :                   fprintf (dump_file, "  ");
    2996            3 :                   print_gimple_stmt (dump_file, gsi_stmt (bsi), 0);
    2997              :                 }
    2998       698402 :               predicate_for_phi_result (info, bsi.phi (), &phi_predicate,
    2999              :                                         nonconstant_names);
    3000              :             }
    3001              :         }
    3002              : 
    3003     40766049 :       fix_builtin_expect_stmt = find_foldable_builtin_expect (bb);
    3004              : 
    3005     40766049 :       for (gimple_stmt_iterator bsi = gsi_start_nondebug_bb (bb);
    3006    180969318 :            !gsi_end_p (bsi); gsi_next_nondebug (&bsi))
    3007              :         {
    3008    140203269 :           gimple *stmt = gsi_stmt (bsi);
    3009    140203269 :           if (!gimple_plf (stmt, STMT_NECESSARY))
    3010              :             {
    3011      5511958 :               if (dump_file && (dump_flags & TDF_DETAILS))
    3012              :                 {
    3013           19 :                   fprintf (dump_file, "  skipping unnecesary stmt ");
    3014           19 :                   print_gimple_stmt (dump_file, stmt, 0);
    3015              :                 }
    3016              :               /* TODO: const calls used only to produce values for
    3017              :                  builtion_unreachable guards should not be accounted.  However
    3018              :                  we still want to inline them and this does does not work well
    3019              :                  with the cost model.  For now account them as usual.  */
    3020      5511958 :               if (!is_gimple_call (stmt)
    3021      5511958 :                   || gimple_call_internal_p (stmt))
    3022      5237958 :                 continue;
    3023              :             }
    3024    134965311 :           int this_size = estimate_num_insns (stmt, &eni_size_weights);
    3025    134965311 :           int this_time = estimate_num_insns (stmt, &eni_time_weights);
    3026    134965311 :           int prob;
    3027    134965311 :           ipa_predicate will_be_nonconstant;
    3028              : 
    3029              :           /* This relation stmt should be folded after we remove
    3030              :              __builtin_expect call. Adjust the cost here.  */
    3031    134965311 :           if (stmt == fix_builtin_expect_stmt)
    3032              :             {
    3033       159688 :               this_size--;
    3034       159688 :               this_time--;
    3035              :             }
    3036              : 
    3037    134965311 :           if (dump_file && (dump_flags & TDF_DETAILS))
    3038              :             {
    3039          201 :               fprintf (dump_file, "  ");
    3040          201 :               print_gimple_stmt (dump_file, stmt, 0);
    3041          201 :               fprintf (dump_file, "\t\tfreq:%3.2f size:%3i time:%3i\n",
    3042              :                        freq.to_double (), this_size,
    3043              :                        this_time);
    3044              :             }
    3045              : 
    3046    134965311 :           if (is_gimple_call (stmt)
    3047    134965311 :               && !gimple_call_internal_p (stmt))
    3048              :             {
    3049     22670447 :               struct cgraph_edge *edge = node->get_edge (stmt);
    3050     22670447 :               ipa_call_summary *es = ipa_call_summaries->get_create (edge);
    3051              : 
    3052              :               /* Special case: results of BUILT_IN_CONSTANT_P will be always
    3053              :                  resolved as constant.  We however don't want to optimize
    3054              :                  out the cgraph edges.  */
    3055     22670447 :               if (nonconstant_names.exists ()
    3056     19827849 :                   && gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P)
    3057         8733 :                   && gimple_call_lhs (stmt)
    3058     22679180 :                   && TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME)
    3059              :                 {
    3060         8733 :                   ipa_predicate false_p = false;
    3061         8733 :                   nonconstant_names[SSA_NAME_VERSION (gimple_call_lhs (stmt))]
    3062         8733 :                     = false_p;
    3063              :                 }
    3064     22670447 :               if (ipa_node_params_sum)
    3065              :                 {
    3066     19840620 :                   int count = gimple_call_num_args (stmt);
    3067     19840620 :                   int i;
    3068              : 
    3069     19840620 :                   if (count)
    3070     16944507 :                     es->param.safe_grow_cleared (count, true);
    3071     57960788 :                   for (i = 0; i < count; i++)
    3072              :                     {
    3073     38120168 :                       int prob = param_change_prob (&fbi, stmt, i);
    3074     38120168 :                       gcc_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
    3075     38120168 :                       es->param[i].change_prob = prob;
    3076     38120168 :                       es->param[i].points_to_local_or_readonly_memory
    3077     38120168 :                          = points_to_local_or_readonly_memory_p
    3078     38120168 :                              (gimple_call_arg (stmt, i));
    3079     38120168 :                       es->param[i].points_to_possible_sra_candidate
    3080     38120168 :                          = points_to_possible_sra_candidate_p
    3081     38120168 :                              (gimple_call_arg (stmt, i));
    3082              :                     }
    3083              :                 }
    3084              :               /* We cannot setup VLA parameters during inlining.  */
    3085     66550812 :               for (unsigned int i = 0; i < gimple_call_num_args (stmt); ++i)
    3086     43880761 :                 if (TREE_CODE (gimple_call_arg (stmt, i)) == WITH_SIZE_EXPR)
    3087              :                   {
    3088          396 :                     edge->inline_failed = CIF_FUNCTION_NOT_INLINABLE;
    3089          396 :                     break;
    3090              :                   }
    3091     22670447 :               es->call_stmt_size = this_size;
    3092     22670447 :               es->call_stmt_time = this_time;
    3093     22670447 :               es->loop_depth = bb_loop_depth (bb);
    3094     22670447 :               edge_set_predicate (edge, &bb_predicate);
    3095     22670447 :               if (edge->speculative)
    3096              :                 {
    3097            0 :                   cgraph_edge *indirect
    3098            0 :                         = edge->speculative_call_indirect_edge ();
    3099            0 :                   ipa_call_summary *es2
    3100            0 :                          = ipa_call_summaries->get_create (indirect);
    3101            0 :                   ipa_call_summaries->duplicate (edge, indirect,
    3102              :                                                  es, es2);
    3103              : 
    3104              :                   /* Edge is the first direct call.
    3105              :                      create and duplicate call summaries for multiple
    3106              :                      speculative call targets.  */
    3107            0 :                   for (cgraph_edge *direct
    3108            0 :                          = edge->next_speculative_call_target ();
    3109            0 :                        direct;
    3110            0 :                        direct = direct->next_speculative_call_target ())
    3111              :                     {
    3112            0 :                       ipa_call_summary *es3
    3113            0 :                         = ipa_call_summaries->get_create (direct);
    3114            0 :                       ipa_call_summaries->duplicate (edge, direct,
    3115              :                                                      es, es3);
    3116              :                     }
    3117              :                 }
    3118              : 
    3119              :               /* If dealing with a carrying edge, copy its summary over to its
    3120              :                  attached edges as well.  */
    3121     22670447 :               if (edge->has_callback)
    3122              :                 {
    3123        15067 :                   cgraph_edge *cbe;
    3124        30134 :                   for (cbe = edge->first_callback_edge (); cbe;
    3125        15067 :                        cbe = cbe->next_callback_edge ())
    3126              :                     {
    3127        15067 :                       ipa_call_summary *es2 = ipa_call_summaries->get_create (cbe);
    3128        15067 :                       ipa_call_summaries->duplicate (edge, cbe, es, es2);
    3129              :                       /* Unlike speculative edges, callback edges have no real
    3130              :                          size or time; the call doesn't exist.  Reflect that in
    3131              :                          their summaries.  */
    3132        15067 :                       es2->call_stmt_size = 0;
    3133        15067 :                       es2->call_stmt_time = 0;
    3134              :                     }
    3135              :                 }
    3136              :             }
    3137              : 
    3138              :           /* TODO: When conditional jump or switch is known to be constant, but
    3139              :              we did not translate it into the predicates, we really can account
    3140              :              just maximum of the possible paths.  */
    3141    134965311 :           if (fbi.info)
    3142    113054209 :             will_be_nonconstant
    3143    113054209 :               = will_be_nonconstant_predicate (&fbi, info, params_summary,
    3144              :                                                stmt, nonconstant_names);
    3145              :           else
    3146     21911102 :             will_be_nonconstant = true;
    3147    134965311 :           if (this_time || this_size)
    3148              :             {
    3149    110702677 :               sreal final_time = (sreal)this_time * freq;
    3150    110702677 :               prob = eliminated_by_inlining_prob (&fbi, stmt);
    3151    110702677 :               if (prob == 1 && dump_file && (dump_flags & TDF_DETAILS))
    3152           11 :                 fprintf (dump_file,
    3153              :                          "\t\t50%% will be eliminated by inlining\n");
    3154    110702677 :               if (prob == 2 && dump_file && (dump_flags & TDF_DETAILS))
    3155           18 :                 fprintf (dump_file, "\t\tWill be eliminated by inlining\n");
    3156              : 
    3157    110702677 :               ipa_predicate p = bb_predicate & will_be_nonconstant;
    3158    110702677 :               int parm = load_or_store_of_ptr_parameter (&fbi, stmt);
    3159    110702677 :               ipa_predicate sra_predicate = true;
    3160    110702677 :               if (parm != -1)
    3161     14038044 :                 sra_predicate &= add_condition (info, params_summary, parm,
    3162              :                                                 ptr_type_node, NULL,
    3163      7019022 :                                                 ipa_predicate::not_sra_candidate, NULL, 0);
    3164              : 
    3165              :               /* We can ignore statement when we proved it is never going
    3166              :                  to happen, but we cannot do that for call statements
    3167              :                  because edges are accounted specially.  */
    3168              : 
    3169    221405354 :               if (*(is_gimple_call (stmt) ? &bb_predicate : &p) != false)
    3170              :                 {
    3171    109992848 :                   time += final_time;
    3172    109992848 :                   size += this_size;
    3173              :                 }
    3174              : 
    3175              :               /* We account everything but the calls.  Calls have their own
    3176              :                  size/time info attached to cgraph edges.  This is necessary
    3177              :                  in order to make the cost disappear after inlining.  */
    3178    110702677 :               if (!is_gimple_call (stmt))
    3179              :                 {
    3180     88678906 :                   if (prob)
    3181              :                     {
    3182     14767606 :                       ipa_predicate ip
    3183     14767606 :                         = bb_predicate & ipa_predicate::not_inlined () & sra_predicate;
    3184     29535212 :                       info->account_size_time (this_size * prob,
    3185     14767606 :                                                (final_time * prob) / 2, ip,
    3186              :                                                p);
    3187              :                     }
    3188     14767606 :                   if (prob != 2)
    3189    163728090 :                     info->account_size_time (this_size * (2 - prob),
    3190     81864045 :                                              (final_time * (2 - prob) / 2),
    3191    163728090 :                                              bb_predicate & sra_predicate,
    3192              :                                              p);
    3193              :                 }
    3194              : 
    3195    110702677 :               if (!info->fp_expressions && fp_expression_p (stmt))
    3196              :                 {
    3197       595767 :                   info->fp_expressions = true;
    3198       595767 :                   if (dump_file)
    3199            9 :                     fprintf (dump_file, "   fp_expression set\n");
    3200              :                 }
    3201              :             }
    3202              : 
    3203              :           /* For target specific information, we want to scan all statements
    3204              :              rather than those statements with non-zero weights, to avoid
    3205              :              missing to scan something interesting for target information,
    3206              :              such as: internal function calls.  */
    3207    134965311 :           if (scan_for_target_info)
    3208            0 :             scan_for_target_info =
    3209            0 :               targetm.target_option.update_ipa_fn_target_info
    3210            0 :               (info->target_info, stmt);
    3211              : 
    3212              :           /* Account cost of address calculations in the statements.  */
    3213    521863473 :           for (unsigned int i = 0; i < gimple_num_ops (stmt); i++)
    3214              :             {
    3215    386898162 :               for (tree op = gimple_op (stmt, i);
    3216    744876254 :                    op && handled_component_p (op);
    3217     46638881 :                    op = TREE_OPERAND (op, 0))
    3218     46638881 :                 if ((TREE_CODE (op) == ARRAY_REF
    3219     46638881 :                      || TREE_CODE (op) == ARRAY_RANGE_REF)
    3220     46638881 :                     && TREE_CODE (TREE_OPERAND (op, 1)) == SSA_NAME)
    3221              :                   {
    3222      2381026 :                     ipa_predicate p = bb_predicate;
    3223      2381026 :                     if (fbi.info)
    3224      1862940 :                       p = p & will_be_nonconstant_expr_predicate
    3225      1862940 :                                  (&fbi, info, params_summary,
    3226      1862940 :                                   TREE_OPERAND (op, 1),
    3227      1862940 :                                   nonconstant_names);
    3228      2381026 :                     if (p != false)
    3229              :                       {
    3230      2375324 :                         time += freq;
    3231      2375324 :                         size += 1;
    3232      2375324 :                         if (dump_file)
    3233           24 :                           fprintf (dump_file,
    3234              :                                    "\t\tAccounting address calculation.\n");
    3235      2375324 :                         info->account_size_time (ipa_fn_summary::size_scale,
    3236              :                                                  freq,
    3237              :                                                  bb_predicate,
    3238              :                                                  p);
    3239              :                       }
    3240              :                   }
    3241              :             }
    3242              : 
    3243              :         }
    3244              :     }
    3245      7125308 :   free (order);
    3246              : 
    3247      7125308 :   if (nonconstant_names.exists () && !early)
    3248              :     {
    3249      1372124 :       ipa_fn_summary *s = ipa_fn_summaries->get (node);
    3250      1372124 :       unsigned max_loop_predicates = opt_for_fn (node->decl,
    3251              :                                                  param_ipa_max_loop_predicates);
    3252              : 
    3253      1372124 :       if (dump_file && (dump_flags & TDF_DETAILS))
    3254           14 :         flow_loops_dump (dump_file, NULL, 0);
    3255      1372124 :       scev_initialize ();
    3256      4737060 :       for (auto loop : loops_list (cfun, 0))
    3257              :         {
    3258       620688 :           ipa_predicate loop_iterations = true;
    3259       620688 :           sreal header_freq;
    3260       620688 :           edge ex;
    3261       620688 :           unsigned int j;
    3262       620688 :           class tree_niter_desc niter_desc;
    3263       620688 :           if (!loop->header->aux)
    3264            0 :             continue;
    3265              : 
    3266       620688 :           profile_count hdr_count = loop->header->count;
    3267       620688 :           sreal hdr_freq = hdr_count.to_sreal_scale (entry_count);
    3268              : 
    3269       620688 :           bb_predicate = *(ipa_predicate *)loop->header->aux;
    3270       620688 :           auto_vec<edge> exits = get_loop_exit_edges (loop);
    3271      1621815 :           FOR_EACH_VEC_ELT (exits, j, ex)
    3272      1001127 :             if (number_of_iterations_exit (loop, ex, &niter_desc, false)
    3273      1001127 :                 && !is_gimple_min_invariant (niter_desc.niter))
    3274              :             {
    3275       153695 :               ipa_predicate will_be_nonconstant
    3276       153695 :                 = will_be_nonconstant_expr_predicate (&fbi, info,
    3277              :                                                       params_summary,
    3278              :                                                       niter_desc.niter,
    3279              :                                                       nonconstant_names);
    3280       153695 :               if (will_be_nonconstant != true)
    3281        61752 :                 will_be_nonconstant = bb_predicate & will_be_nonconstant;
    3282       153695 :               if (will_be_nonconstant != true
    3283       215447 :                   && will_be_nonconstant != false)
    3284        61197 :                 loop_iterations &= will_be_nonconstant;
    3285              :             }
    3286       620688 :           add_freqcounting_predicate (&s->loop_iterations, loop_iterations,
    3287              :                                       hdr_freq, max_loop_predicates);
    3288       620688 :         }
    3289              : 
    3290              :       /* To avoid quadratic behavior we analyze stride predicates only
    3291              :          with respect to the containing loop.  Thus we simply iterate
    3292              :          over all defs in the outermost loop body.  */
    3293      1372124 :       for (class loop *loop = loops_for_fn (cfun)->tree_root->inner;
    3294      1859564 :            loop != NULL; loop = loop->next)
    3295              :         {
    3296       487440 :           ipa_predicate loop_stride = true;
    3297       487440 :           basic_block *body = get_loop_body (loop);
    3298       487440 :           profile_count hdr_count = loop->header->count;
    3299       487440 :           sreal hdr_freq = hdr_count.to_sreal_scale (entry_count);
    3300      2873087 :           for (unsigned i = 0; i < loop->num_nodes; i++)
    3301              :             {
    3302      2385647 :               gimple_stmt_iterator gsi;
    3303      2385647 :               if (!body[i]->aux)
    3304            7 :                 continue;
    3305              : 
    3306      2385640 :               bb_predicate = *(ipa_predicate *)body[i]->aux;
    3307     15720652 :               for (gsi = gsi_start_bb (body[i]); !gsi_end_p (gsi);
    3308     10949372 :                    gsi_next (&gsi))
    3309              :                 {
    3310     10949372 :                   gimple *stmt = gsi_stmt (gsi);
    3311              : 
    3312     10949372 :                   if (!is_gimple_assign (stmt))
    3313     10797618 :                     continue;
    3314              : 
    3315      5358049 :                   tree def = gimple_assign_lhs (stmt);
    3316      5358049 :                   if (TREE_CODE (def) != SSA_NAME)
    3317      1017685 :                     continue;
    3318              : 
    3319      4340364 :                   affine_iv iv;
    3320      8680728 :                   if (!simple_iv (loop_containing_stmt (stmt),
    3321              :                                   loop_containing_stmt (stmt),
    3322              :                                   def, &iv, true)
    3323      4340364 :                       || is_gimple_min_invariant (iv.step))
    3324      4188610 :                     continue;
    3325              : 
    3326       151754 :                   ipa_predicate will_be_nonconstant
    3327       151754 :                     = will_be_nonconstant_expr_predicate (&fbi, info,
    3328              :                                                           params_summary,
    3329              :                                                           iv.step,
    3330              :                                                           nonconstant_names);
    3331       151754 :                   if (will_be_nonconstant != true)
    3332        53544 :                     will_be_nonconstant = bb_predicate & will_be_nonconstant;
    3333       151754 :                   if (will_be_nonconstant != true
    3334       205298 :                       && will_be_nonconstant != false)
    3335        34672 :                     loop_stride = loop_stride & will_be_nonconstant;
    3336              :                 }
    3337              :             }
    3338       487440 :           add_freqcounting_predicate (&s->loop_strides, loop_stride,
    3339              :                                       hdr_freq, max_loop_predicates);
    3340       487440 :           free (body);
    3341              :         }
    3342      1372124 :       scev_finalize ();
    3343              :     }
    3344     62662695 :   FOR_ALL_BB_FN (bb, my_function)
    3345              :     {
    3346     55537387 :       edge e;
    3347     55537387 :       edge_iterator ei;
    3348              : 
    3349     55537387 :       if (bb->aux)
    3350     41147279 :         edge_predicate_pool.remove ((ipa_predicate *)bb->aux);
    3351     55537387 :       bb->aux = NULL;
    3352    118222872 :       FOR_EACH_EDGE (e, ei, bb->succs)
    3353              :         {
    3354     62685485 :           if (e->aux)
    3355      2496411 :             edge_predicate_pool.remove ((ipa_predicate *)e->aux);
    3356     62685485 :           e->aux = NULL;
    3357              :         }
    3358              :     }
    3359      7125308 :   ipa_fn_summary *s = ipa_fn_summaries->get (node);
    3360      7125308 :   ipa_size_summary *ss = ipa_size_summaries->get (node);
    3361      7125308 :   s->time = time;
    3362      7125308 :   ss->self_size = size;
    3363      7125308 :   nonconstant_names.release ();
    3364      7125308 :   ipa_release_body_info (&fbi);
    3365      7125308 :   if (opt_for_fn (node->decl, optimize))
    3366              :     {
    3367      6243817 :       if (!early)
    3368      1372124 :         loop_optimizer_finalize ();
    3369      4871693 :       else if (!ipa_edge_args_sum)
    3370      4871679 :         ipa_free_all_node_params ();
    3371      6243817 :       free_dominance_info (CDI_DOMINATORS);
    3372      6243817 :       free_dominance_info (CDI_POST_DOMINATORS);
    3373              :     }
    3374      7125308 :   if (dump_file)
    3375              :     {
    3376          247 :       fprintf (dump_file, "\n");
    3377          247 :       ipa_dump_fn_summary (dump_file, node);
    3378              :     }
    3379      7125308 : }
    3380              : 
    3381              : 
    3382              : /* Compute function summary.
    3383              :    EARLY is true when we compute parameters during early opts.  */
    3384              : 
    3385              : void
    3386      7126596 : compute_fn_summary (struct cgraph_node *node, bool early)
    3387              : {
    3388      7126596 :   HOST_WIDE_INT self_stack_size;
    3389      7126596 :   struct cgraph_edge *e;
    3390              : 
    3391      7126596 :   gcc_assert (!node->inlined_to);
    3392              : 
    3393      7126596 :   if (!ipa_fn_summaries)
    3394       212052 :     ipa_fn_summary_alloc ();
    3395              : 
    3396              :   /* Create a new ipa_fn_summary.  */
    3397      7126596 :   ((ipa_fn_summary_t *)ipa_fn_summaries)->remove_callees (node);
    3398      7126596 :   ipa_fn_summaries->remove (node);
    3399      7126596 :   class ipa_fn_summary *info = ipa_fn_summaries->get_create (node);
    3400      7126596 :   class ipa_size_summary *size_info = ipa_size_summaries->get_create (node);
    3401              : 
    3402              :   /* Estimate the stack size for the function if we're optimizing.  */
    3403     12488906 :   self_stack_size = optimize && !node->thunk
    3404     13370413 :                     ? estimated_stack_frame_size (node) : 0;
    3405      7126596 :   size_info->estimated_self_stack_size = self_stack_size;
    3406      7126596 :   info->estimated_stack_size = self_stack_size;
    3407              : 
    3408      7126596 :   if (node->thunk)
    3409              :     {
    3410         1288 :       ipa_call_summary *es = ipa_call_summaries->get_create (node->callees);
    3411         1288 :       ipa_predicate t = true;
    3412              : 
    3413         1288 :       node->can_change_signature = false;
    3414         1288 :       es->call_stmt_size = eni_size_weights.call_cost;
    3415         1288 :       es->call_stmt_time = eni_time_weights.call_cost;
    3416         3864 :       info->account_size_time (ipa_fn_summary::size_scale
    3417         1288 :                                * opt_for_fn (node->decl,
    3418              :                                  param_uninlined_function_thunk_insns),
    3419         1288 :                                opt_for_fn (node->decl,
    3420              :                                  param_uninlined_function_thunk_time), t, t);
    3421         1288 :       t = ipa_predicate::not_inlined ();
    3422         1288 :       info->account_size_time (2 * ipa_fn_summary::size_scale, 0, t, t);
    3423         1288 :       ipa_update_overall_fn_summary (node);
    3424         1288 :       size_info->self_size = size_info->size;
    3425         1288 :       if (stdarg_p (TREE_TYPE (node->decl)))
    3426              :         {
    3427            9 :           info->inlinable = false;
    3428            9 :           node->callees->inline_failed = CIF_VARIADIC_THUNK;
    3429              :         }
    3430              :       else
    3431         1279 :         info->inlinable = true;
    3432              :     }
    3433              :   else
    3434              :     {
    3435              :        /* Even is_gimple_min_invariant rely on current_function_decl.  */
    3436      7125308 :        push_cfun (DECL_STRUCT_FUNCTION (node->decl));
    3437              : 
    3438              :        /* During IPA profile merging we may be called w/o virtual SSA form
    3439              :           built.  */
    3440      7125308 :        update_ssa (TODO_update_ssa_only_virtuals);
    3441              : 
    3442              :        /* Can this function be inlined at all?  */
    3443      7125308 :        if (!opt_for_fn (node->decl, optimize)
    3444      8006799 :            && !lookup_attribute ("always_inline",
    3445       881491 :                                  DECL_ATTRIBUTES (node->decl)))
    3446       814133 :          info->inlinable = false;
    3447              :        else
    3448      6311175 :          info->inlinable = tree_inlinable_function_p (node->decl);
    3449              : 
    3450      7125308 :        bool no_signature = false;
    3451              : 
    3452              :        /* Don't allow signature changes for functions which have
    3453              :           [[gnu::musttail]] or [[clang::musttail]] calls.  Sometimes
    3454              :           (more often on targets which pass everything on the stack)
    3455              :           signature changes can result in tail calls being impossible
    3456              :           even when without the signature changes they would be ok.
    3457              :           See PR121023.  */
    3458      7125308 :        if (cfun->has_musttail)
    3459              :          {
    3460         1410 :            if (dump_file)
    3461            0 :             fprintf (dump_file, "No signature change:"
    3462              :                      " function has calls with musttail attribute.\n");
    3463              :            no_signature = true;
    3464              :          }
    3465              : 
    3466              :        /* Type attributes can use parameter indices to describe them.
    3467              :           Special case fn spec since we can safely preserve them in
    3468              :           modref summaries.  */
    3469      7125308 :        for (tree list = TYPE_ATTRIBUTES (TREE_TYPE (node->decl));
    3470      7513454 :             list && !no_signature; list = TREE_CHAIN (list))
    3471       388146 :         if (!ipa_param_adjustments::type_attribute_allowed_p
    3472       388146 :                         (get_attribute_name (list)))
    3473              :            {
    3474       157376 :              if (dump_file)
    3475              :                 {
    3476            0 :                   fprintf (dump_file, "No signature change:"
    3477              :                            " function type has unhandled attribute %s.\n",
    3478            0 :                            IDENTIFIER_POINTER (get_attribute_name (list)));
    3479              :                 }
    3480              :              no_signature = true;
    3481              :            }
    3482      7125308 :        for (tree parm = DECL_ARGUMENTS (node->decl);
    3483     21310663 :             parm && !no_signature; parm = DECL_CHAIN (parm))
    3484     14185355 :          if (variably_modified_type_p (TREE_TYPE (parm), node->decl))
    3485              :            {
    3486        15547 :              if (dump_file)
    3487              :                 {
    3488            0 :                   fprintf (dump_file, "No signature change:"
    3489              :                            " has parameter with variably modified type.\n");
    3490              :                 }
    3491              :              no_signature = true;
    3492              :            }
    3493              : 
    3494              :        /* Likewise for #pragma omp declare simd functions or functions
    3495              :           with simd attribute.  */
    3496      7125308 :        if (no_signature
    3497     14076283 :            || lookup_attribute ("omp declare simd",
    3498      6950975 :                                 DECL_ATTRIBUTES (node->decl)))
    3499       176021 :          node->can_change_signature = false;
    3500              :        else
    3501              :          {
    3502              :            /* Otherwise, inlinable functions always can change signature.  */
    3503      6949287 :            if (info->inlinable)
    3504      5591583 :              node->can_change_signature = true;
    3505              :            else
    3506              :              {
    3507              :                /* Functions calling builtin_apply cannot change signature.  */
    3508      5343127 :                for (e = node->callees; e; e = e->next_callee)
    3509              :                  {
    3510      4017945 :                    tree cdecl = e->callee->decl;
    3511      4017945 :                    if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS,
    3512              :                                                  BUILT_IN_VA_START))
    3513              :                      break;
    3514              :                  }
    3515      1357704 :                node->can_change_signature = !e;
    3516              :              }
    3517              :          }
    3518      7125308 :        analyze_function_body (node, early);
    3519      7125308 :        pop_cfun ();
    3520              :      }
    3521              : 
    3522              :   /* Inlining characteristics are maintained by the cgraph_mark_inline.  */
    3523      7126596 :   size_info->size = size_info->self_size;
    3524      7126596 :   info->estimated_stack_size = size_info->estimated_self_stack_size;
    3525              : 
    3526              :   /* Code above should compute exactly the same result as
    3527              :      ipa_update_overall_fn_summary except for case when speculative
    3528              :      edges are present since these are accounted to size but not
    3529              :      self_size. Do not compare time since different order the roundoff
    3530              :      errors result in slight changes.  */
    3531      7126596 :   ipa_update_overall_fn_summary (node);
    3532      7126596 :   if (flag_checking)
    3533              :     {
    3534      7607122 :       for (e = node->indirect_calls; e; e = e->next_callee)
    3535       480608 :        if (e->speculative)
    3536              :          break;
    3537      7126514 :       gcc_assert (e || size_info->size == size_info->self_size);
    3538              :     }
    3539      7126596 : }
    3540              : 
    3541              : 
    3542              : /* Compute parameters of functions used by inliner using
    3543              :    current_function_decl.  */
    3544              : 
    3545              : static unsigned int
    3546      5696735 : compute_fn_summary_for_current (void)
    3547              : {
    3548      5696735 :   compute_fn_summary (cgraph_node::get (current_function_decl), true);
    3549      5696735 :   return 0;
    3550              : }
    3551              : 
    3552              : /* Estimate benefit devirtualizing indirect edge IE and return true if it can
    3553              :    be devirtualized and inlined, provided m_known_vals, m_known_contexts and
    3554              :    m_known_aggs in AVALS.  Return false straight away if AVALS is NULL.  */
    3555              : 
    3556              : static bool
    3557      4781076 : estimate_edge_devirt_benefit (struct cgraph_edge *ie,
    3558              :                               int *size, int *time,
    3559              :                               ipa_call_arg_values *avals)
    3560              : {
    3561      4781076 :   tree target;
    3562      4781076 :   struct cgraph_node *callee;
    3563      4781076 :   class ipa_fn_summary *isummary;
    3564      4781076 :   enum availability avail;
    3565      4781076 :   bool speculative;
    3566              : 
    3567      4781076 :   if (!avals
    3568      5993500 :       || (!avals->m_known_vals.length() && !avals->m_known_contexts.length ()))
    3569              :     return false;
    3570      1420139 :   if (!opt_for_fn (ie->caller->decl, flag_indirect_inlining))
    3571              :     return false;
    3572              : 
    3573      1413873 :   target = ipa_get_indirect_edge_target
    3574      1413873 :     (ie->callee ? ie->speculative_call_indirect_edge () : ie,
    3575              :      avals, &speculative);
    3576      1413873 :   if (!target || speculative)
    3577              :     return false;
    3578              : 
    3579              :   /* If this is speculative call, turn its cost into 0; we will account
    3580              :      the call when processing the indirect call.  */
    3581       228358 :   if (ie->callee)
    3582              :     {
    3583         7976 :       gcc_checking_assert (ie->speculative && *size > 0);
    3584         7976 :       *size = 0;
    3585         7976 :       *time = 0;
    3586              :     }
    3587              :   else
    3588              :     {
    3589              :       /* Account for difference in cost between indirect and direct calls.  */
    3590       220382 :       *size -= (eni_size_weights.indirect_call_cost - eni_size_weights.call_cost);
    3591       220382 :       *time -= (eni_time_weights.indirect_call_cost - eni_time_weights.call_cost);
    3592              :     }
    3593       228358 :   gcc_checking_assert (*time >= 0);
    3594       228358 :   gcc_checking_assert (*size >= 0);
    3595              : 
    3596       228358 :   callee = cgraph_node::get (target);
    3597       228358 :   if (!callee || !callee->definition)
    3598              :     return false;
    3599       207753 :   callee = callee->function_symbol (&avail);
    3600       207753 :   if (avail < AVAIL_AVAILABLE)
    3601              :     return false;
    3602       207727 :   isummary = ipa_fn_summaries->get (callee);
    3603       207727 :   if (isummary == NULL)
    3604              :     return false;
    3605              : 
    3606       207715 :   return isummary->inlinable;
    3607              : }
    3608              : 
    3609              : /* Increase SIZE, MIN_SIZE (if non-NULL) and TIME for size and time needed to
    3610              :    handle edge E with probability PROB.  Set HINTS accordingly if edge may be
    3611              :    devirtualized.  AVALS, if non-NULL, describes the context of the call site
    3612              :    as far as values of parameters are concerened.  */
    3613              : 
    3614              : static inline void
    3615    201773986 : estimate_edge_size_and_time (struct cgraph_edge *e, int *size, int *min_size,
    3616              :                              sreal *time, ipa_call_arg_values *avals,
    3617              :                              ipa_hints *hints)
    3618              : {
    3619    201773986 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
    3620    201773986 :   int call_size = es->call_stmt_size;
    3621    201773986 :   int call_time = es->call_stmt_time;
    3622    201773986 :   int cur_size;
    3623              : 
    3624    197618969 :   if ((!e->callee || e->speculative)
    3625    202400045 :       && estimate_edge_devirt_benefit (e, &call_size, &call_time, avals))
    3626              :     {
    3627       207373 :       if (hints && e->maybe_hot_p ())
    3628       197298 :         *hints |= INLINE_HINT_indirect_call;
    3629              :     }
    3630    201773986 :   cur_size = call_size * ipa_fn_summary::size_scale;
    3631    201773986 :   *size += cur_size;
    3632    201773986 :   if (min_size)
    3633     27066347 :     *min_size += cur_size;
    3634    201773986 :   if (time)
    3635    192399960 :     *time += ((sreal)call_time) * e->sreal_frequency ();
    3636    201773986 : }
    3637              : 
    3638              : 
    3639              : /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all
    3640              :    calls in NODE.  POSSIBLE_TRUTHS and AVALS describe the context of the call
    3641              :    site.
    3642              : 
    3643              :    Helper for estimate_calls_size_and_time which does the same but
    3644              :    (in most cases) faster.  */
    3645              : 
    3646              : static void
    3647     64313094 : estimate_calls_size_and_time_1 (struct cgraph_node *node, int *size,
    3648              :                                 int *min_size, sreal *time,
    3649              :                                 ipa_hints *hints,
    3650              :                                 clause_t possible_truths,
    3651              :                                 ipa_call_arg_values *avals)
    3652              : {
    3653     64313094 :   struct cgraph_edge *e;
    3654    322209634 :   for (e = node->callees; e; e = e->next_callee)
    3655              :     {
    3656    257896540 :       if (!e->inline_failed)
    3657              :         {
    3658     44701003 :           gcc_checking_assert (!ipa_call_summaries->get (e));
    3659     44701003 :           estimate_calls_size_and_time_1 (e->callee, size, min_size, time,
    3660              :                                           hints, possible_truths, avals);
    3661              : 
    3662     44701003 :           continue;
    3663              :         }
    3664    213195537 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3665              : 
    3666              :       /* Do not care about zero sized builtins.  */
    3667    213195537 :       if (!es->call_stmt_size)
    3668              :         {
    3669     23826579 :           gcc_checking_assert (!es->call_stmt_time);
    3670     23826579 :           continue;
    3671              :         }
    3672    189368958 :       if (!es->predicate
    3673    189368958 :           || es->predicate->evaluate (possible_truths))
    3674              :         {
    3675              :           /* Predicates of calls shall not use NOT_CHANGED codes,
    3676              :              so we do not need to compute probabilities.  */
    3677    186801685 :           estimate_edge_size_and_time (e, size,
    3678    186801685 :                                        es->predicate ? NULL : min_size,
    3679              :                                        time, avals, hints);
    3680              :         }
    3681              :     }
    3682     68163076 :   for (e = node->indirect_calls; e; e = e->next_callee)
    3683              :     {
    3684      3849982 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3685      3849982 :       if (!es->predicate
    3686      3849982 :           || es->predicate->evaluate (possible_truths))
    3687      3819868 :         estimate_edge_size_and_time (e, size,
    3688      3819868 :                                      es->predicate ? NULL : min_size,
    3689              :                                      time, avals, hints);
    3690              :     }
    3691     64313094 : }
    3692              : 
    3693              : /* Populate sum->call_size_time_table for edges from NODE.  */
    3694              : 
    3695              : static void
    3696      3017426 : summarize_calls_size_and_time (struct cgraph_node *node,
    3697              :                                ipa_fn_summary *sum)
    3698              : {
    3699      3017426 :   struct cgraph_edge *e;
    3700     14330341 :   for (e = node->callees; e; e = e->next_callee)
    3701              :     {
    3702     11312915 :       if (!e->inline_failed)
    3703              :         {
    3704      1324359 :           gcc_checking_assert (!ipa_call_summaries->get (e));
    3705      1324359 :           summarize_calls_size_and_time (e->callee, sum);
    3706      1324359 :           continue;
    3707              :         }
    3708      9988556 :       int size = 0;
    3709      9988556 :       sreal time = 0;
    3710              : 
    3711      9988556 :       estimate_edge_size_and_time (e, &size, NULL, &time, NULL, NULL);
    3712              : 
    3713      9988556 :       ipa_predicate pred = true;
    3714      9988556 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3715              : 
    3716      9988556 :       if (es->predicate)
    3717      1893654 :         pred = *es->predicate;
    3718      9988556 :       sum->account_size_time (size, time, pred, pred, true);
    3719              :     }
    3720      3352575 :   for (e = node->indirect_calls; e; e = e->next_callee)
    3721              :     {
    3722       335149 :       int size = 0;
    3723       335149 :       sreal time = 0;
    3724              : 
    3725       335149 :       estimate_edge_size_and_time (e, &size, NULL, &time, NULL, NULL);
    3726       335149 :       ipa_predicate pred = true;
    3727       335149 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    3728              : 
    3729       335149 :       if (es->predicate)
    3730       106744 :         pred = *es->predicate;
    3731       335149 :       sum->account_size_time (size, time, pred, pred, true);
    3732              :     }
    3733      3017426 : }
    3734              : 
    3735              : /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all
    3736              :    calls in NODE.  POSSIBLE_TRUTHS and AVALS (the latter if non-NULL) describe
    3737              :    context of the call site.  */
    3738              : 
    3739              : static void
    3740     19612112 : estimate_calls_size_and_time (struct cgraph_node *node, int *size,
    3741              :                               int *min_size, sreal *time,
    3742              :                               ipa_hints *hints,
    3743              :                               clause_t possible_truths,
    3744              :                               ipa_call_arg_values *avals)
    3745              : {
    3746     19612112 :   class ipa_fn_summary *sum = ipa_fn_summaries->get (node);
    3747     19612112 :   bool use_table = true;
    3748              : 
    3749     19612112 :   gcc_assert (node->callees || node->indirect_calls);
    3750              : 
    3751              :   /* During early inlining we do not calculate info for very
    3752              :      large functions and thus there is no need for producing
    3753              :      summaries.  */
    3754     19612112 :   if (!ipa_node_params_sum)
    3755              :     use_table = false;
    3756              :   /* Do not calculate summaries for simple wrappers; it is waste
    3757              :      of memory.  */
    3758     10623058 :   else if (node->callees && !node->indirect_calls
    3759      9895296 :            && node->callees->inline_failed && !node->callees->next_callee)
    3760              :     use_table = false;
    3761              :   /* If there is an indirect edge that may be optimized, we need
    3762              :      to go the slow way.  */
    3763      8525737 :   else if (avals
    3764      8525737 :            && (avals->m_known_vals.length ()
    3765      3128324 :                || avals->m_known_contexts.length ()
    3766      2993827 :                || avals->m_known_aggs.length ()))
    3767              :     {
    3768      4024843 :       ipa_node_params *params_summary = ipa_node_params_sum->get (node);
    3769      4024843 :       unsigned int nargs = params_summary
    3770      4024843 :                            ? ipa_get_param_count (params_summary) : 0;
    3771              : 
    3772     13591618 :       for (unsigned int i = 0; i < nargs && use_table; i++)
    3773              :         {
    3774      9566775 :           if (ipa_is_param_used_by_indirect_call (params_summary, i)
    3775      9566775 :               && (avals->safe_sval_at (i)
    3776       252751 :                   || (ipa_argagg_value_list (avals).value_for_index_p (i))))
    3777              :             use_table = false;
    3778      9467799 :           else if (ipa_is_param_used_by_polymorphic_call (params_summary, i)
    3779      9467799 :                    && (avals->m_known_contexts.length () > i
    3780      9712436 :                        && !avals->m_known_contexts[i].useless_p ()))
    3781              :             use_table = false;
    3782              :         }
    3783              :     }
    3784              : 
    3785              :   /* Fast path is via the call size time table.  */
    3786      4024843 :   if (use_table)
    3787              :     {
    3788              :       /* Build summary if it is absent.  */
    3789      8281269 :       if (!sum->call_size_time_table.length ())
    3790              :         {
    3791       864339 :           ipa_predicate true_pred = true;
    3792       864339 :           sum->account_size_time (0, 0, true_pred, true_pred, true);
    3793       864339 :           summarize_calls_size_and_time (node, sum);
    3794              :         }
    3795              : 
    3796      8281269 :       int old_size = *size;
    3797      8281269 :       sreal old_time = time ? *time : 0;
    3798              : 
    3799      8281269 :       if (min_size)
    3800      8281269 :         *min_size += sum->call_size_time_table[0].size;
    3801              : 
    3802              :       unsigned int i;
    3803              :       size_time_entry *e;
    3804              : 
    3805              :       /* Walk the table and account sizes and times.  */
    3806     22382830 :       for (i = 0; sum->call_size_time_table.iterate (i, &e);
    3807              :            i++)
    3808     14101561 :         if (e->exec_predicate.evaluate (possible_truths))
    3809              :           {
    3810     12962869 :             *size += e->size;
    3811     12962869 :             if (time)
    3812     10867576 :               *time += e->time;
    3813              :           }
    3814              : 
    3815              :       /* Be careful and see if both methods agree.  */
    3816           21 :       if ((flag_checking || dump_file)
    3817              :           /* Do not try to sanity check when we know we lost some
    3818              :              precision.  */
    3819      8281269 :           && sum->call_size_time_table.length ()
    3820              :              < ipa_fn_summary::max_size_time_table_size)
    3821              :         {
    3822      8281248 :           estimate_calls_size_and_time_1 (node, &old_size, NULL, &old_time, NULL,
    3823              :                                           possible_truths, avals);
    3824      8281248 :           gcc_assert (*size == old_size);
    3825     15193816 :           if (time && (*time - old_time > 1 || *time - old_time < -1)
    3826      8281277 :               && dump_file)
    3827            0 :             fprintf (dump_file, "Time mismatch in call summary %f!=%f\n",
    3828              :                      old_time.to_double (),
    3829              :                      time->to_double ());
    3830              :         }
    3831              :     }
    3832              :   /* Slow path by walking all edges.  */
    3833              :   else
    3834     11330843 :     estimate_calls_size_and_time_1 (node, size, min_size, time, hints,
    3835              :                                     possible_truths, avals);
    3836     19612112 : }
    3837              : 
    3838              : /* Main constructor for ipa call context.  Memory allocation of ARG_VALUES
    3839              :    is owned by the caller.  INLINE_PARAM_SUMMARY is also owned by the
    3840              :    caller.  */
    3841              : 
    3842     18897251 : ipa_call_context::ipa_call_context (cgraph_node *node, clause_t possible_truths,
    3843              :                                     clause_t nonspec_possible_truths,
    3844              :                                     vec<inline_param_summary>
    3845              :                                       inline_param_summary,
    3846     18897251 :                                     ipa_auto_call_arg_values *arg_values)
    3847     18897251 : : m_node (node), m_possible_truths (possible_truths),
    3848     18897251 :   m_nonspec_possible_truths (nonspec_possible_truths),
    3849     18897251 :   m_inline_param_summary (inline_param_summary),
    3850     18897251 :   m_avals (arg_values)
    3851              : {
    3852     18897251 : }
    3853              : 
    3854              : /* Set THIS to be a duplicate of CTX.  Copy all relevant info.  */
    3855              : 
    3856              : void
    3857      1855623 : ipa_cached_call_context::duplicate_from (const ipa_call_context &ctx)
    3858              : {
    3859      1855623 :   m_node = ctx.m_node;
    3860      1855623 :   m_possible_truths = ctx.m_possible_truths;
    3861      1855623 :   m_nonspec_possible_truths = ctx.m_nonspec_possible_truths;
    3862      1855623 :   ipa_node_params *params_summary = ipa_node_params_sum->get (m_node);
    3863      1855623 :   unsigned int nargs = params_summary
    3864      1855623 :                        ? ipa_get_param_count (params_summary) : 0;
    3865              : 
    3866      1855623 :   m_inline_param_summary = vNULL;
    3867              :   /* Copy the info only if there is at least one useful entry.  */
    3868      1855623 :   if (ctx.m_inline_param_summary.exists ())
    3869              :     {
    3870      1655378 :       unsigned int n = MIN (ctx.m_inline_param_summary.length (), nargs);
    3871              : 
    3872      3777150 :       for (unsigned int i = 0; i < n; i++)
    3873      3100546 :         if (ipa_is_param_used_by_ipa_predicates (params_summary, i)
    3874      4404615 :             && !ctx.m_inline_param_summary[i].useless_p ())
    3875              :           {
    3876       978774 :             m_inline_param_summary
    3877       978774 :                     = ctx.m_inline_param_summary.copy ();
    3878       978774 :             break;
    3879              :           }
    3880              :     }
    3881      1855623 :   m_avals.m_known_vals = vNULL;
    3882      1855623 :   if (ctx.m_avals.m_known_vals.exists ())
    3883              :     {
    3884      1855623 :       unsigned int n = MIN (ctx.m_avals.m_known_vals.length (), nargs);
    3885              : 
    3886      4395194 :       for (unsigned int i = 0; i < n; i++)
    3887      2568265 :         if (ipa_is_param_used_by_indirect_call (params_summary, i)
    3888      2568265 :             && ctx.m_avals.m_known_vals[i])
    3889              :           {
    3890        28694 :             m_avals.m_known_vals = ctx.m_avals.m_known_vals.copy ();
    3891        28694 :             break;
    3892              :           }
    3893              :     }
    3894              : 
    3895      1855623 :   m_avals.m_known_contexts = vNULL;
    3896      1855623 :   if (ctx.m_avals.m_known_contexts.exists ())
    3897              :     {
    3898      1855623 :       unsigned int n = MIN (ctx.m_avals.m_known_contexts.length (), nargs);
    3899              : 
    3900      1856955 :       for (unsigned int i = 0; i < n; i++)
    3901        22579 :         if (ipa_is_param_used_by_polymorphic_call (params_summary, i)
    3902        22579 :             && !ctx.m_avals.m_known_contexts[i].useless_p ())
    3903              :           {
    3904        21247 :             m_avals.m_known_contexts = ctx.m_avals.m_known_contexts.copy ();
    3905        21247 :             break;
    3906              :           }
    3907              :     }
    3908              : 
    3909      1855623 :   m_avals.m_known_aggs = vNULL;
    3910      1855623 :   if (ctx.m_avals.m_known_aggs.exists ())
    3911              :     {
    3912      1855623 :       const ipa_argagg_value_list avl (&ctx.m_avals);
    3913      6241100 :       for (unsigned int i = 0; i < nargs; i++)
    3914      4389201 :         if (ipa_is_param_used_by_indirect_call (params_summary, i)
    3915      4389201 :             && avl.value_for_index_p (i))
    3916              :           {
    3917         3724 :             m_avals.m_known_aggs = ctx.m_avals.m_known_aggs.copy ();
    3918         3724 :             break;
    3919              :           }
    3920              :     }
    3921              : 
    3922      1855623 :   m_avals.m_known_value_ranges = vNULL;
    3923      1855623 : }
    3924              : 
    3925              : /* Release memory used by known_vals/contexts/aggs vectors.  and
    3926              :    inline_param_summary.  */
    3927              : 
    3928              : void
    3929      3022213 : ipa_cached_call_context::release ()
    3930              : {
    3931              :   /* See if context is initialized at first place.  */
    3932      3022213 :   if (!m_node)
    3933              :     return;
    3934      1855623 :   m_avals.m_known_aggs.release ();
    3935      1855623 :   m_avals.m_known_vals.release ();
    3936      1855623 :   m_avals.m_known_contexts.release ();
    3937      1855623 :   m_inline_param_summary.release ();
    3938              : }
    3939              : 
    3940              : /* Return true if CTX describes the same call context as THIS.  */
    3941              : 
    3942              : bool
    3943      6670193 : ipa_call_context::equal_to (const ipa_call_context &ctx)
    3944              : {
    3945      6670193 :   if (m_node != ctx.m_node
    3946      5503603 :       || m_possible_truths != ctx.m_possible_truths
    3947      4940547 :       || m_nonspec_possible_truths != ctx.m_nonspec_possible_truths)
    3948              :     return false;
    3949              : 
    3950      4940547 :   ipa_node_params *params_summary = ipa_node_params_sum->get (m_node);
    3951      4940547 :   unsigned int nargs = params_summary
    3952      4940547 :                        ? ipa_get_param_count (params_summary) : 0;
    3953              : 
    3954      4940547 :   if (m_inline_param_summary.exists () || ctx.m_inline_param_summary.exists ())
    3955              :     {
    3956     14817620 :       for (unsigned int i = 0; i < nargs; i++)
    3957              :         {
    3958     10201777 :           if (!ipa_is_param_used_by_ipa_predicates (params_summary, i))
    3959      3225513 :             continue;
    3960      6976264 :           if (i >= m_inline_param_summary.length ()
    3961      5038269 :               || m_inline_param_summary[i].useless_p ())
    3962              :             {
    3963      2850241 :               if (i < ctx.m_inline_param_summary.length ()
    3964      2850241 :                   && !ctx.m_inline_param_summary[i].useless_p ())
    3965              :                 return false;
    3966      2806074 :               continue;
    3967              :             }
    3968      4126023 :           if (i >= ctx.m_inline_param_summary.length ()
    3969      4126020 :               || ctx.m_inline_param_summary[i].useless_p ())
    3970              :             {
    3971        42561 :               if (i < m_inline_param_summary.length ()
    3972        42561 :                   && !m_inline_param_summary[i].useless_p ())
    3973              :                 return false;
    3974            0 :               continue;
    3975              :             }
    3976      4083462 :           if (!m_inline_param_summary[i].equal_to
    3977      4083462 :                  (ctx.m_inline_param_summary[i]))
    3978              :             return false;
    3979              :         }
    3980              :     }
    3981      4827815 :   if (m_avals.m_known_vals.exists () || ctx.m_avals.m_known_vals.exists ())
    3982              :     {
    3983     14829174 :       for (unsigned int i = 0; i < nargs; i++)
    3984              :         {
    3985     10011793 :           if (!ipa_is_param_used_by_indirect_call (params_summary, i))
    3986      9819364 :             continue;
    3987       192429 :           if (i >= m_avals.m_known_vals.length () || !m_avals.m_known_vals[i])
    3988              :             {
    3989       135301 :               if (i < ctx.m_avals.m_known_vals.length ()
    3990       135301 :                   && ctx.m_avals.m_known_vals[i])
    3991              :                 return false;
    3992       135220 :               continue;
    3993              :             }
    3994        57128 :           if (i >= ctx.m_avals.m_known_vals.length ()
    3995        57128 :               || !ctx.m_avals.m_known_vals[i])
    3996              :             {
    3997              :               if (i < m_avals.m_known_vals.length () && m_avals.m_known_vals[i])
    3998              :                 return false;
    3999              :               continue;
    4000              :             }
    4001        57044 :           if (m_avals.m_known_vals[i] != ctx.m_avals.m_known_vals[i])
    4002              :             return false;
    4003              :         }
    4004              :     }
    4005      4817381 :   if (m_avals.m_known_contexts.exists ()
    4006      4817381 :       || ctx.m_avals.m_known_contexts.exists ())
    4007              :     {
    4008     14814278 :       for (unsigned int i = 0; i < nargs; i++)
    4009              :         {
    4010      9998307 :           if (!ipa_is_param_used_by_polymorphic_call (params_summary, i))
    4011      9877952 :             continue;
    4012       120355 :           if (i >= m_avals.m_known_contexts.length ()
    4013       119188 :               || m_avals.m_known_contexts[i].useless_p ())
    4014              :             {
    4015         1167 :               if (i < ctx.m_avals.m_known_contexts.length ()
    4016         1167 :                   && !ctx.m_avals.m_known_contexts[i].useless_p ())
    4017              :                 return false;
    4018         1158 :               continue;
    4019              :             }
    4020       119188 :           if (i >= ctx.m_avals.m_known_contexts.length ()
    4021       119188 :               || ctx.m_avals.m_known_contexts[i].useless_p ())
    4022              :             {
    4023            8 :               if (i < m_avals.m_known_contexts.length ()
    4024      1855631 :                   && !m_avals.m_known_contexts[i].useless_p ())
    4025              :                 return false;
    4026            0 :               continue;
    4027              :             }
    4028       119180 :           if (!m_avals.m_known_contexts[i].equal_to
    4029       119180 :                  (ctx.m_avals.m_known_contexts[i]))
    4030              :             return false;
    4031              :         }
    4032              :     }
    4033      4815971 :   if (m_avals.m_known_aggs.exists () || ctx.m_avals.m_known_aggs.exists ())
    4034              :     {
    4035              :       unsigned i = 0, j = 0;
    4036     10984648 :       while (i < m_avals.m_known_aggs.length ()
    4037      5491357 :              || j < ctx.m_avals.m_known_aggs.length ())
    4038              :         {
    4039       676787 :           if (i >= m_avals.m_known_aggs.length ())
    4040              :             {
    4041       669838 :               int idx2 = ctx.m_avals.m_known_aggs[j].index;
    4042       669838 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx2))
    4043              :                 return false;
    4044       669238 :               j++;
    4045       669238 :               continue;
    4046       669238 :             }
    4047         6949 :           if (j >= ctx.m_avals.m_known_aggs.length ())
    4048              :             {
    4049          631 :               int idx1 = m_avals.m_known_aggs[i].index;
    4050          631 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4051              :                 return false;
    4052            8 :               i++;
    4053            8 :               continue;
    4054            8 :             }
    4055              : 
    4056         6318 :           int idx1 = m_avals.m_known_aggs[i].index;
    4057         6318 :           int idx2 = ctx.m_avals.m_known_aggs[j].index;
    4058         6318 :           if (idx1 < idx2)
    4059              :             {
    4060            0 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4061              :                 return false;
    4062            0 :               i++;
    4063            0 :               continue;
    4064              :             }
    4065         6318 :           if (idx1 > idx2)
    4066              :             {
    4067            0 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx2))
    4068              :                 return false;
    4069            0 :               j++;
    4070            0 :               continue;
    4071              :             }
    4072         6318 :           if (!ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4073              :             {
    4074          342 :               i++;
    4075          342 :               j++;
    4076          342 :               continue;
    4077              :             }
    4078              : 
    4079         5976 :           if ((m_avals.m_known_aggs[i].unit_offset
    4080         5976 :                != ctx.m_avals.m_known_aggs[j].unit_offset)
    4081         5968 :               || (m_avals.m_known_aggs[i].by_ref
    4082         5968 :                != ctx.m_avals.m_known_aggs[j].by_ref)
    4083        11944 :               || !operand_equal_p (m_avals.m_known_aggs[i].value,
    4084         5968 :                                    ctx.m_avals.m_known_aggs[j].value))
    4085          178 :             return false;
    4086         5798 :           i++;
    4087         5798 :           j++;
    4088              :         }
    4089              :     }
    4090              :   return true;
    4091              : }
    4092              : 
    4093              : /* Fill in the selected fields in ESTIMATES with value estimated for call in
    4094              :    this context.  Always compute size and min_size.  Only compute time and
    4095              :    nonspecialized_time if EST_TIMES is true.  Only compute hints if EST_HINTS
    4096              :    is true.  */
    4097              : 
    4098              : void
    4099     18866692 : ipa_call_context::estimate_size_and_time (ipa_call_estimates *estimates,
    4100              :                                           bool est_times, bool est_hints)
    4101              : {
    4102     18866692 :   class ipa_fn_summary *info = ipa_fn_summaries->get (m_node);
    4103     18866692 :   size_time_entry *e;
    4104     18866692 :   int size = 0;
    4105     18866692 :   sreal time = 0;
    4106     18866692 :   int min_size = 0;
    4107     18866692 :   ipa_hints hints = 0;
    4108     18866692 :   sreal loops_with_known_iterations = 0;
    4109     18866692 :   sreal loops_with_known_strides = 0;
    4110     18866692 :   int i;
    4111              : 
    4112     18866692 :   if (dump_file && (dump_flags & TDF_DETAILS))
    4113              :     {
    4114         1332 :       bool found = false;
    4115         1332 :       fprintf (dump_file, "   Estimating body: %s\n"
    4116              :                "   Known to be false: ", m_node->dump_name ());
    4117              : 
    4118         4287 :       for (i = ipa_predicate::not_inlined_condition;
    4119         8574 :            i < (ipa_predicate::first_dynamic_condition
    4120         7002 :                 + (int) vec_safe_length (info->conds)); i++)
    4121         2955 :         if (!(m_possible_truths & (1 << i)))
    4122              :           {
    4123         1769 :             if (found)
    4124          504 :               fprintf (dump_file, ", ");
    4125         1769 :             found = true;
    4126         1769 :             dump_condition (dump_file, info->conds, i);
    4127              :           }
    4128              :     }
    4129              : 
    4130     18866692 :   if (m_node->callees || m_node->indirect_calls)
    4131     24767605 :     estimate_calls_size_and_time (m_node, &size, &min_size,
    4132              :                                   est_times ? &time : NULL,
    4133              :                                   est_hints ? &hints : NULL, m_possible_truths,
    4134              :                                   &m_avals);
    4135              : 
    4136     18866692 :   sreal nonspecialized_time = time;
    4137              : 
    4138     18866692 :   min_size += info->size_time_table[0].size;
    4139    130367950 :   for (i = 0; info->size_time_table.iterate (i, &e); i++)
    4140              :     {
    4141    111501258 :       bool exec = e->exec_predicate.evaluate (m_nonspec_possible_truths);
    4142              : 
    4143              :       /* Because predicates are conservative, it can happen that nonconst is 1
    4144              :          but exec is 0.  */
    4145    111501258 :       if (exec)
    4146              :         {
    4147    108919581 :           bool nonconst = e->nonconst_predicate.evaluate (m_possible_truths);
    4148              : 
    4149    108919581 :           gcc_checking_assert (e->time >= 0);
    4150    108919581 :           gcc_checking_assert (time >= 0);
    4151              : 
    4152              :           /* We compute specialized size only because size of nonspecialized
    4153              :              copy is context independent.
    4154              : 
    4155              :              The difference between nonspecialized execution and specialized is
    4156              :              that nonspecialized is not going to have optimized out computations
    4157              :              known to be constant in a specialized setting.  */
    4158    108919581 :           if (nonconst)
    4159     54829739 :             size += e->size;
    4160    108919581 :           if (!est_times)
    4161     56259332 :             continue;
    4162     52660249 :           nonspecialized_time += e->time;
    4163     52660249 :           if (!nonconst)
    4164              :             ;
    4165     25285063 :           else if (!m_inline_param_summary.exists ())
    4166              :             {
    4167      2511181 :               if (nonconst)
    4168      2511181 :                 time += e->time;
    4169              :             }
    4170              :           else
    4171              :             {
    4172     22773882 :               int prob = e->nonconst_predicate.probability
    4173     22773882 :                                                (info->conds, m_possible_truths,
    4174              :                                                 m_inline_param_summary);
    4175     22773882 :               gcc_checking_assert (prob >= 0);
    4176     22773882 :               gcc_checking_assert (prob <= REG_BR_PROB_BASE);
    4177     22773882 :               if (prob == REG_BR_PROB_BASE)
    4178     19365034 :                 time += e->time;
    4179              :               else
    4180      3408848 :                 time += e->time * prob / REG_BR_PROB_BASE;
    4181              :             }
    4182     52660249 :           gcc_checking_assert (time >= 0);
    4183              :         }
    4184              :      }
    4185     18866692 :   gcc_checking_assert (info->size_time_table[0].exec_predicate == true);
    4186     18866692 :   gcc_checking_assert (info->size_time_table[0].nonconst_predicate == true);
    4187     18866692 :   gcc_checking_assert (min_size >= 0);
    4188     18866692 :   gcc_checking_assert (size >= 0);
    4189     18866692 :   gcc_checking_assert (time >= 0);
    4190              :   /* nonspecialized_time should be always bigger than specialized time.
    4191              :      Roundoff issues however may get into the way.  */
    4192     18866692 :   gcc_checking_assert ((nonspecialized_time - time * 99 / 100) >= -1);
    4193              : 
    4194              :   /* Roundoff issues may make specialized time bigger than nonspecialized
    4195              :      time.  We do not really want that to happen because some heuristics
    4196              :      may get confused by seeing negative speedups.  */
    4197     18866692 :   if (time > nonspecialized_time)
    4198            0 :     time = nonspecialized_time;
    4199              : 
    4200     18866692 :   if (est_hints)
    4201              :     {
    4202      6925799 :       if (info->scc_no)
    4203       163575 :         hints |= INLINE_HINT_in_scc;
    4204      6925799 :       if (DECL_DECLARED_INLINE_P (m_node->decl))
    4205      4315994 :         hints |= INLINE_HINT_declared_inline;
    4206      6925799 :       if (info->builtin_constant_p_parms.length ()
    4207         8643 :           && DECL_DECLARED_INLINE_P (m_node->decl))
    4208         8585 :         hints |= INLINE_HINT_builtin_constant_p;
    4209              : 
    4210              :       ipa_freqcounting_predicate *fcp;
    4211      7476967 :       for (i = 0; vec_safe_iterate (info->loop_iterations, i, &fcp); i++)
    4212       551168 :         if (!fcp->predicate->evaluate (m_possible_truths))
    4213              :           {
    4214       370829 :             hints |= INLINE_HINT_loop_iterations;
    4215       370829 :             loops_with_known_iterations += fcp->freq;
    4216              :           }
    4217      6925799 :       estimates->loops_with_known_iterations = loops_with_known_iterations;
    4218              : 
    4219      7207185 :       for (i = 0; vec_safe_iterate (info->loop_strides, i, &fcp); i++)
    4220       281386 :         if (!fcp->predicate->evaluate (m_possible_truths))
    4221              :           {
    4222       260818 :             hints |= INLINE_HINT_loop_stride;
    4223       260818 :             loops_with_known_strides += fcp->freq;
    4224              :           }
    4225      6925799 :       estimates->loops_with_known_strides = loops_with_known_strides;
    4226              :     }
    4227              : 
    4228     18866692 :   size = RDIV (size, ipa_fn_summary::size_scale);
    4229     18866692 :   min_size = RDIV (min_size, ipa_fn_summary::size_scale);
    4230              : 
    4231     18866692 :   if (dump_file && (dump_flags & TDF_DETAILS))
    4232              :     {
    4233         1332 :       fprintf (dump_file, "\n   size:%i", (int) size);
    4234         1332 :       if (est_times)
    4235         1090 :         fprintf (dump_file, " time:%f nonspec time:%f",
    4236              :                  time.to_double (), nonspecialized_time.to_double ());
    4237         1332 :       if (est_hints)
    4238         1090 :         fprintf (dump_file, " loops with known iterations:%f "
    4239              :                  "known strides:%f", loops_with_known_iterations.to_double (),
    4240              :                  loops_with_known_strides.to_double ());
    4241         1332 :       fprintf (dump_file, "\n");
    4242              :     }
    4243     18866692 :   if (est_times)
    4244              :     {
    4245      6925799 :       estimates->time = time;
    4246      6925799 :       estimates->nonspecialized_time = nonspecialized_time;
    4247              :     }
    4248     18866692 :   estimates->size = size;
    4249     18866692 :   estimates->min_size = min_size;
    4250     18866692 :   if (est_hints)
    4251      6925799 :     estimates->hints = hints;
    4252     18866692 :   return;
    4253              : }
    4254              : 
    4255              : 
    4256              : /* Estimate size and time needed to execute callee of EDGE assuming that
    4257              :    parameters known to be constant at caller of EDGE are propagated.
    4258              :    KNOWN_VALS and KNOWN_CONTEXTS are vectors of assumed known constant values
    4259              :    and types for parameters.  */
    4260              : 
    4261              : void
    4262       282364 : estimate_ipcp_clone_size_and_time (struct cgraph_node *node,
    4263              :                                    ipa_auto_call_arg_values *avals,
    4264              :                                    ipa_call_estimates *estimates)
    4265              : {
    4266       282364 :   clause_t clause, nonspec_clause;
    4267              : 
    4268       282364 :   evaluate_conditions_for_known_args (node, false, avals, &clause,
    4269              :                                       &nonspec_clause, NULL);
    4270       282364 :   ipa_call_context ctx (node, clause, nonspec_clause, vNULL, avals);
    4271       282364 :   ctx.estimate_size_and_time (estimates);
    4272       282364 : }
    4273              : 
    4274              : /* Return stack frame offset where frame of NODE is supposed to start inside
    4275              :    of the function it is inlined to.
    4276              :    Return 0 for functions that are not inlined.  */
    4277              : 
    4278              : HOST_WIDE_INT
    4279      5044498 : ipa_get_stack_frame_offset (struct cgraph_node *node)
    4280              : {
    4281      5044498 :   HOST_WIDE_INT offset = 0;
    4282      5044498 :   if (!node->inlined_to)
    4283              :     return 0;
    4284      3900648 :   node = node->callers->caller;
    4285      4841374 :   while (true)
    4286              :     {
    4287      4841374 :       offset += ipa_size_summaries->get (node)->estimated_self_stack_size;
    4288      4371011 :       if (!node->inlined_to)
    4289              :         return offset;
    4290       470363 :       node = node->callers->caller;
    4291              :     }
    4292              : }
    4293              : 
    4294              : 
    4295              : /* Update summary information of inline clones after inlining.
    4296              :    Compute peak stack usage.  */
    4297              : 
    4298              : static void
    4299      4570428 : inline_update_callee_summaries (struct cgraph_node *node, int depth)
    4300              : {
    4301      4570428 :   struct cgraph_edge *e;
    4302              : 
    4303      4570428 :   ipa_propagate_frequency (node);
    4304      8757531 :   for (e = node->callees; e; e = e->next_callee)
    4305              :     {
    4306      4187103 :       if (!e->inline_failed)
    4307       670334 :         inline_update_callee_summaries (e->callee, depth);
    4308              :       else
    4309      3516769 :         ipa_call_summaries->get (e)->loop_depth += depth;
    4310              :     }
    4311      4676673 :   for (e = node->indirect_calls; e; e = e->next_callee)
    4312       106245 :     ipa_call_summaries->get (e)->loop_depth += depth;
    4313      4570428 : }
    4314              : 
    4315              : /* Update change_prob and points_to_local_or_readonly_memory of EDGE after
    4316              :    INLINED_EDGE has been inlined.
    4317              : 
    4318              :    When function A is inlined in B and A calls C with parameter that
    4319              :    changes with probability PROB1 and C is known to be passthrough
    4320              :    of argument if B that change with probability PROB2, the probability
    4321              :    of change is now PROB1*PROB2.  */
    4322              : 
    4323              : static void
    4324      3623327 : remap_edge_params (struct cgraph_edge *inlined_edge,
    4325              :                    struct cgraph_edge *edge)
    4326              : {
    4327      3623327 :   if (ipa_node_params_sum)
    4328              :     {
    4329      2616477 :       int i;
    4330      2616477 :       ipa_edge_args *args = ipa_edge_args_sum->get (edge);
    4331      2616477 :       if (!args)
    4332              :         return;
    4333      1465611 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    4334      1465611 :       class ipa_call_summary *inlined_es
    4335      1465611 :         = ipa_call_summaries->get (inlined_edge);
    4336              : 
    4337      1465611 :       if (es->param.length () == 0)
    4338              :         return;
    4339              : 
    4340      8519916 :       for (i = 0; i < ipa_get_cs_argument_count (args); i++)
    4341              :         {
    4342      2869201 :           struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
    4343      2869201 :           if (jfunc->type == IPA_JF_PASS_THROUGH
    4344      2128882 :               || jfunc->type == IPA_JF_ANCESTOR)
    4345              :             {
    4346       874787 :               int id = jfunc->type == IPA_JF_PASS_THROUGH
    4347       874787 :                        ? ipa_get_jf_pass_through_formal_id (jfunc)
    4348       134468 :                        : ipa_get_jf_ancestor_formal_id (jfunc);
    4349      1749482 :               if (id < (int) inlined_es->param.length ())
    4350              :                 {
    4351       874687 :                   int prob1 = es->param[i].change_prob;
    4352       874687 :                   int prob2 = inlined_es->param[id].change_prob;
    4353       874687 :                   int prob = combine_probabilities (prob1, prob2);
    4354              : 
    4355       874687 :                   if (prob1 && prob2 && !prob)
    4356       874687 :                     prob = 1;
    4357              : 
    4358       874687 :                   es->param[i].change_prob = prob;
    4359              : 
    4360      1749374 :                   if (inlined_es
    4361       874687 :                         ->param[id].points_to_local_or_readonly_memory)
    4362       200525 :                     es->param[i].points_to_local_or_readonly_memory = true;
    4363      1749374 :                   if (inlined_es
    4364       874687 :                         ->param[id].points_to_possible_sra_candidate)
    4365       169512 :                     es->param[i].points_to_possible_sra_candidate = true;
    4366              :                 }
    4367       874787 :               if (!es->param[i].points_to_local_or_readonly_memory
    4368              :                   && jfunc->type == IPA_JF_CONST
    4369              :                   && points_to_local_or_readonly_memory_p
    4370              :                          (ipa_get_jf_constant (jfunc)))
    4371              :                 es->param[i].points_to_local_or_readonly_memory = true;
    4372              :             }
    4373              :         }
    4374              :     }
    4375              : }
    4376              : 
    4377              : /* Update edge summaries of NODE after INLINED_EDGE has been inlined.
    4378              : 
    4379              :    Remap predicates of callees of NODE.  Rest of arguments match
    4380              :    remap_predicate.
    4381              : 
    4382              :    Also update change probabilities.  */
    4383              : 
    4384              : static void
    4385      4570428 : remap_edge_summaries (struct cgraph_edge *inlined_edge,
    4386              :                       struct cgraph_node *node,
    4387              :                       class ipa_fn_summary *info,
    4388              :                       class ipa_node_params *params_summary,
    4389              :                       class ipa_fn_summary *callee_info,
    4390              :                       const vec<int> &operand_map,
    4391              :                       const vec<HOST_WIDE_INT> &offset_map,
    4392              :                       clause_t possible_truths,
    4393              :                       ipa_predicate *toplev_predicate)
    4394              : {
    4395      4570428 :   struct cgraph_edge *e, *next;
    4396      8757107 :   for (e = node->callees; e; e = next)
    4397              :     {
    4398      4186679 :       ipa_predicate p;
    4399      4186679 :       next = e->next_callee;
    4400              : 
    4401      4186679 :       if (e->inline_failed)
    4402              :         {
    4403      3516345 :           class ipa_call_summary *es = ipa_call_summaries->get (e);
    4404      3516345 :           remap_edge_params (inlined_edge, e);
    4405              : 
    4406      3516345 :           if (es->predicate)
    4407              :             {
    4408      1203357 :               p = es->predicate->remap_after_inlining
    4409      1203357 :                                      (info, params_summary,
    4410              :                                       callee_info, operand_map,
    4411              :                                       offset_map, possible_truths,
    4412              :                                       *toplev_predicate);
    4413      1203357 :               edge_set_predicate (e, &p);
    4414              :             }
    4415              :           else
    4416      2312988 :             edge_set_predicate (e, toplev_predicate);
    4417              :         }
    4418              :       else
    4419       670334 :         remap_edge_summaries (inlined_edge, e->callee, info,
    4420              :                               params_summary, callee_info,
    4421              :                               operand_map, offset_map, possible_truths,
    4422              :                               toplev_predicate);
    4423              :     }
    4424      4677410 :   for (e = node->indirect_calls; e; e = next)
    4425              :     {
    4426       106982 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    4427       106982 :       ipa_predicate p;
    4428       106982 :       next = e->next_callee;
    4429              : 
    4430       106982 :       remap_edge_params (inlined_edge, e);
    4431       106982 :       if (es->predicate)
    4432              :         {
    4433        27384 :           p = es->predicate->remap_after_inlining
    4434        27384 :                                  (info, params_summary,
    4435              :                                   callee_info, operand_map, offset_map,
    4436              :                                   possible_truths, *toplev_predicate);
    4437        27384 :           edge_set_predicate (e, &p);
    4438              :         }
    4439              :       else
    4440        79598 :         edge_set_predicate (e, toplev_predicate);
    4441              :     }
    4442      4570428 : }
    4443              : 
    4444              : /* Run remap_after_inlining on each predicate in V.  */
    4445              : 
    4446              : static void
    4447      7800188 : remap_freqcounting_predicate (class ipa_fn_summary *info,
    4448              :                               class ipa_node_params *params_summary,
    4449              :                               class ipa_fn_summary *callee_info,
    4450              :                               vec<ipa_freqcounting_predicate, va_gc> *v,
    4451              :                               const vec<int> &operand_map,
    4452              :                               const vec<HOST_WIDE_INT> &offset_map,
    4453              :                               clause_t possible_truths,
    4454              :                               ipa_predicate *toplev_predicate)
    4455              : 
    4456              : {
    4457      7800188 :   ipa_freqcounting_predicate *fcp;
    4458      7827554 :   for (int i = 0; vec_safe_iterate (v, i, &fcp); i++)
    4459              :     {
    4460        27366 :       ipa_predicate p
    4461        27366 :         = fcp->predicate->remap_after_inlining (info, params_summary,
    4462              :                                                 callee_info, operand_map,
    4463              :                                                 offset_map, possible_truths,
    4464              :                                                 *toplev_predicate);
    4465        38145 :       if (p != false && p != true)
    4466         2820 :         *fcp->predicate &= p;
    4467              :     }
    4468      7800188 : }
    4469              : 
    4470              : /* We inlined EDGE.  Update summary of the function we inlined into.  */
    4471              : 
    4472              : void
    4473      3900094 : ipa_merge_fn_summary_after_inlining (struct cgraph_edge *edge)
    4474              : {
    4475      3900094 :   ipa_fn_summary *callee_info = ipa_fn_summaries->get (edge->callee);
    4476      3663656 :   struct cgraph_node *to = (edge->caller->inlined_to
    4477      3900094 :                             ? edge->caller->inlined_to : edge->caller);
    4478      3900094 :   class ipa_fn_summary *info = ipa_fn_summaries->get (to);
    4479      3900094 :   clause_t clause = 0;  /* not_inline is known to be false.  */
    4480      3900094 :   size_time_entry *e;
    4481      3900094 :   auto_vec<int, 8> operand_map;
    4482      3900094 :   auto_vec<HOST_WIDE_INT, 8> offset_map;
    4483      3900094 :   int i;
    4484      3900094 :   ipa_predicate toplev_predicate;
    4485      3900094 :   class ipa_call_summary *es = ipa_call_summaries->get (edge);
    4486      3900094 :   ipa_node_params *params_summary = (ipa_node_params_sum
    4487      3900094 :                                      ? ipa_node_params_sum->get (to) : NULL);
    4488              : 
    4489      3900094 :   if (es->predicate)
    4490       347178 :     toplev_predicate = *es->predicate;
    4491              :   else
    4492      3552916 :     toplev_predicate = true;
    4493              : 
    4494      3900094 :   info->fp_expressions |= callee_info->fp_expressions;
    4495      3900094 :   info->target_info |= callee_info->target_info;
    4496              : 
    4497      3900094 :   if (callee_info->conds)
    4498              :     {
    4499      2834941 :       ipa_auto_call_arg_values avals;
    4500      2834941 :       evaluate_properties_for_edge (edge, true, &clause, NULL, &avals, false);
    4501      2834941 :     }
    4502      3900094 :   if (ipa_node_params_sum && callee_info->conds)
    4503              :     {
    4504       770398 :       ipa_edge_args *args = ipa_edge_args_sum->get (edge);
    4505       770398 :       int count = args ? ipa_get_cs_argument_count (args) : 0;
    4506       770258 :       int i;
    4507              : 
    4508       770258 :       if (count)
    4509              :         {
    4510       770258 :           operand_map.safe_grow_cleared (count, true);
    4511       770258 :           offset_map.safe_grow_cleared (count, true);
    4512              :         }
    4513      2456832 :       for (i = 0; i < count; i++)
    4514              :         {
    4515      1686434 :           struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
    4516      1686434 :           int map = -1;
    4517              : 
    4518              :           /* TODO: handle non-NOPs when merging.  */
    4519      1686434 :           if (jfunc->type == IPA_JF_PASS_THROUGH)
    4520              :             {
    4521       288493 :               if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
    4522       285565 :                 map = ipa_get_jf_pass_through_formal_id (jfunc);
    4523       288493 :               if (!ipa_get_jf_pass_through_agg_preserved (jfunc))
    4524       192135 :                 offset_map[i] = -1;
    4525              :             }
    4526      1397941 :           else if (jfunc->type == IPA_JF_ANCESTOR)
    4527              :             {
    4528        87478 :               HOST_WIDE_INT offset = ipa_get_jf_ancestor_offset (jfunc);
    4529        87478 :               if (offset >= 0 && offset < INT_MAX)
    4530              :                 {
    4531        87478 :                   map = ipa_get_jf_ancestor_formal_id (jfunc);
    4532        87478 :                   if (!ipa_get_jf_ancestor_agg_preserved (jfunc))
    4533        52563 :                     offset = -1;
    4534        87478 :                   offset_map[i] = offset;
    4535              :                 }
    4536              :             }
    4537      1686434 :           operand_map[i] = map;
    4538      3060533 :           gcc_assert (map < ipa_get_param_count (params_summary));
    4539              :         }
    4540              : 
    4541              :       int ip;
    4542       772847 :       for (i = 0; callee_info->builtin_constant_p_parms.iterate (i, &ip); i++)
    4543         2449 :         if (ip < count && operand_map[ip] >= 0)
    4544           33 :           add_builtin_constant_p_parm (info, operand_map[ip]);
    4545              :     }
    4546      3900094 :   sreal freq = edge->sreal_frequency ();
    4547     21485350 :   for (i = 0; callee_info->size_time_table.iterate (i, &e); i++)
    4548              :     {
    4549     17585256 :       ipa_predicate p;
    4550     17585256 :       p = e->exec_predicate.remap_after_inlining
    4551     17585256 :                              (info, params_summary,
    4552              :                               callee_info, operand_map,
    4553              :                               offset_map, clause,
    4554              :                               toplev_predicate);
    4555     17585256 :       ipa_predicate nonconstp;
    4556     17585256 :       nonconstp = e->nonconst_predicate.remap_after_inlining
    4557     17585256 :                                      (info, params_summary,
    4558              :                                       callee_info, operand_map,
    4559              :                                       offset_map, clause,
    4560              :                                       toplev_predicate);
    4561     26510092 :       if (p != false && nonconstp != false)
    4562              :         {
    4563      8621499 :           sreal add_time = ((sreal)e->time * freq);
    4564      8621499 :           int prob = e->nonconst_predicate.probability (callee_info->conds,
    4565              :                                                         clause, es->param);
    4566      8621499 :           if (prob != REG_BR_PROB_BASE)
    4567      1068068 :             add_time = add_time * prob / REG_BR_PROB_BASE;
    4568      1068068 :           if (prob != REG_BR_PROB_BASE
    4569      1068068 :               && dump_file && (dump_flags & TDF_DETAILS))
    4570              :             {
    4571           13 :               fprintf (dump_file, "\t\tScaling time by probability:%f\n",
    4572           13 :                        (double) prob / REG_BR_PROB_BASE);
    4573              :             }
    4574      8621499 :           info->account_size_time (e->size, add_time, p, nonconstp);
    4575              :         }
    4576              :     }
    4577      3900094 :   remap_edge_summaries (edge, edge->callee, info, params_summary,
    4578              :                         callee_info, operand_map,
    4579              :                         offset_map, clause, &toplev_predicate);
    4580      3900094 :   remap_freqcounting_predicate (info, params_summary, callee_info,
    4581              :                                 info->loop_iterations, operand_map,
    4582              :                                 offset_map, clause, &toplev_predicate);
    4583      3900094 :   remap_freqcounting_predicate (info, params_summary, callee_info,
    4584              :                                 info->loop_strides, operand_map,
    4585              :                                 offset_map, clause, &toplev_predicate);
    4586              : 
    4587      3900094 :   HOST_WIDE_INT stack_frame_offset = ipa_get_stack_frame_offset (edge->callee);
    4588      3900094 :   HOST_WIDE_INT peak = stack_frame_offset + callee_info->estimated_stack_size;
    4589              : 
    4590      3900094 :   if (info->estimated_stack_size < peak)
    4591       124935 :     info->estimated_stack_size = peak;
    4592              : 
    4593      3900094 :   inline_update_callee_summaries (edge->callee, es->loop_depth);
    4594      3900094 :   if (info->call_size_time_table.length ())
    4595              :     {
    4596       828728 :       int edge_size = 0;
    4597       828728 :       sreal edge_time = 0;
    4598              : 
    4599       828728 :       estimate_edge_size_and_time (edge, &edge_size, NULL, &edge_time, NULL, 0);
    4600              :       /* Unaccount size and time of the optimized out call.  */
    4601       828728 :       info->account_size_time (-edge_size, -edge_time,
    4602       828728 :                                es->predicate ? *es->predicate : true,
    4603       828728 :                                es->predicate ? *es->predicate : true,
    4604              :                                true);
    4605              :       /* Account new calls.  */
    4606       828728 :       summarize_calls_size_and_time (edge->callee, info);
    4607              :     }
    4608              : 
    4609              :   /* Free summaries that are not maintained for inline clones/edges.  */
    4610      3900094 :   ipa_call_summaries->remove (edge);
    4611      3900094 :   ipa_fn_summaries->remove (edge->callee);
    4612      3900094 :   ipa_remove_from_growth_caches (edge);
    4613      3900094 : }
    4614              : 
    4615              : /* For performance reasons ipa_merge_fn_summary_after_inlining is not updating
    4616              :    overall size and time.  Recompute it.
    4617              :    If RESET is true also recompute call_time_size_table.  */
    4618              : 
    4619              : void
    4620      9290705 : ipa_update_overall_fn_summary (struct cgraph_node *node, bool reset)
    4621              : {
    4622      9290705 :   class ipa_fn_summary *info = ipa_fn_summaries->get (node);
    4623      9290705 :   class ipa_size_summary *size_info = ipa_size_summaries->get (node);
    4624      9290705 :   size_time_entry *e;
    4625      9290705 :   int i;
    4626              : 
    4627      9290705 :   size_info->size = 0;
    4628      9290705 :   info->time = 0;
    4629     47580331 :   for (i = 0; info->size_time_table.iterate (i, &e); i++)
    4630              :     {
    4631     38289626 :       size_info->size += e->size;
    4632     38289626 :       info->time += e->time;
    4633              :     }
    4634      9290705 :   info->min_size = info->size_time_table[0].size;
    4635      9290705 :   if (reset)
    4636      8420230 :     info->call_size_time_table.release ();
    4637      9290705 :   if (node->callees || node->indirect_calls)
    4638      7075495 :     estimate_calls_size_and_time (node, &size_info->size, &info->min_size,
    4639              :                                   &info->time, NULL,
    4640              :                                   ~(clause_t) (1 << ipa_predicate::false_condition),
    4641              :                                   NULL);
    4642      9290705 :   size_info->size = RDIV (size_info->size, ipa_fn_summary::size_scale);
    4643      9290705 :   info->min_size = RDIV (info->min_size, ipa_fn_summary::size_scale);
    4644      9290705 : }
    4645              : 
    4646              : 
    4647              : /* This function performs intraprocedural analysis in NODE that is required to
    4648              :    inline indirect calls.  */
    4649              : 
    4650              : static void
    4651      1372120 : inline_indirect_intraprocedural_analysis (struct cgraph_node *node)
    4652              : {
    4653      1372120 :   ipa_analyze_node (node);
    4654      1372120 :   if (dump_file && (dump_flags & TDF_DETAILS))
    4655              :     {
    4656           14 :       ipa_print_node_params (dump_file, node);
    4657           14 :       ipa_print_node_jump_functions (dump_file, node);
    4658              :     }
    4659      1372120 : }
    4660              : 
    4661              : 
    4662              : /* Note function body size.  */
    4663              : 
    4664              : void
    4665      1382790 : inline_analyze_function (struct cgraph_node *node)
    4666              : {
    4667      1382790 :   push_cfun (DECL_STRUCT_FUNCTION (node->decl));
    4668              : 
    4669      1382790 :   if (dump_file)
    4670           94 :     fprintf (dump_file, "\nAnalyzing function: %s\n", node->dump_name ());
    4671      1382790 :   if (opt_for_fn (node->decl, optimize) && !node->thunk)
    4672      1372120 :     inline_indirect_intraprocedural_analysis (node);
    4673      1382790 :   compute_fn_summary (node, false);
    4674      1382790 :   if (!optimize)
    4675              :     {
    4676         9398 :       struct cgraph_edge *e;
    4677        22110 :       for (e = node->callees; e; e = e->next_callee)
    4678        12712 :         e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
    4679         9469 :       for (e = node->indirect_calls; e; e = e->next_callee)
    4680           71 :         e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
    4681              :     }
    4682              : 
    4683      1382790 :   pop_cfun ();
    4684      1382790 : }
    4685              : 
    4686              : 
    4687              : /* Called when new function is inserted to callgraph late.  */
    4688              : 
    4689              : void
    4690        19205 : ipa_fn_summary_t::insert (struct cgraph_node *node, ipa_fn_summary *)
    4691              : {
    4692        19205 :   inline_analyze_function (node);
    4693        19205 : }
    4694              : 
    4695              : /* Note function body size.  */
    4696              : 
    4697              : static void
    4698       229806 : ipa_fn_summary_generate (void)
    4699              : {
    4700       229806 :   struct cgraph_node *node;
    4701              : 
    4702      2081294 :   FOR_EACH_DEFINED_FUNCTION (node)
    4703      1851488 :     if (DECL_STRUCT_FUNCTION (node->decl))
    4704      1838339 :       node->versionable = tree_versionable_function_p (node->decl);
    4705              : 
    4706       229806 :   ipa_fn_summary_alloc ();
    4707              : 
    4708       229806 :   ipa_fn_summaries->enable_insertion_hook ();
    4709              : 
    4710       229806 :   ipa_register_cgraph_hooks ();
    4711              : 
    4712      2081294 :   FOR_EACH_DEFINED_FUNCTION (node)
    4713      1851488 :     if (!node->alias
    4714      1851488 :         && (flag_generate_lto || flag_generate_offload|| flag_wpa
    4715      1661999 :             || opt_for_fn (node->decl, optimize)))
    4716      1345514 :       inline_analyze_function (node);
    4717       229806 : }
    4718              : 
    4719              : 
    4720              : /* Write inline summary for edge E to OB.  */
    4721              : 
    4722              : static void
    4723       346693 : read_ipa_call_summary (class lto_input_block *ib, struct cgraph_edge *e,
    4724              :                        bool prevails)
    4725              : {
    4726       346693 :   class ipa_call_summary *es = prevails
    4727       346693 :                                 ? ipa_call_summaries->get_create (e) : NULL;
    4728       346693 :   ipa_predicate p;
    4729       346693 :   int length, i;
    4730              : 
    4731       346693 :   int size = streamer_read_uhwi (ib);
    4732       346693 :   int time = streamer_read_uhwi (ib);
    4733       346693 :   int depth = streamer_read_uhwi (ib);
    4734              : 
    4735       346693 :   if (es)
    4736              :     {
    4737       346644 :       es->call_stmt_size = size;
    4738       346644 :       es->call_stmt_time = time;
    4739       346644 :       es->loop_depth = depth;
    4740              :     }
    4741              : 
    4742       346693 :   bitpack_d bp = streamer_read_bitpack (ib);
    4743       346693 :   if (es)
    4744       346644 :     es->is_return_callee_uncaptured = bp_unpack_value (&bp, 1);
    4745              :   else
    4746           49 :     bp_unpack_value (&bp, 1);
    4747              : 
    4748       346693 :   p.stream_in (ib);
    4749       346693 :   if (es)
    4750       346644 :     edge_set_predicate (e, &p);
    4751       346693 :   length = streamer_read_uhwi (ib);
    4752       346693 :   if (length && es
    4753       346693 :       && (e->possibly_call_in_translation_unit_p ()
    4754              :           /* Also stream in jump functions to builtins in hope that they
    4755              :              will get fnspecs.  */
    4756       118505 :           || fndecl_built_in_p (e->callee->decl, BUILT_IN_NORMAL)))
    4757              :     {
    4758       231953 :       es->param.safe_grow_cleared (length, true);
    4759       798484 :       for (i = 0; i < length; i++)
    4760              :         {
    4761       566531 :           es->param[i].change_prob = streamer_read_uhwi (ib);
    4762       566531 :           bitpack_d bp = streamer_read_bitpack (ib);
    4763      1699593 :           es->param[i].points_to_local_or_readonly_memory
    4764       566531 :             = bp_unpack_value (&bp, 1);
    4765      1699593 :           es->param[i].points_to_possible_sra_candidate
    4766       566531 :             = bp_unpack_value (&bp, 1);
    4767              :         }
    4768              :     }
    4769              :   else
    4770              :     {
    4771       137319 :       for (i = 0; i < length; i++)
    4772              :         {
    4773        22579 :           streamer_read_uhwi (ib);
    4774        22579 :           streamer_read_uhwi (ib);
    4775              :         }
    4776              :     }
    4777       346693 : }
    4778              : 
    4779              : 
    4780              : /* Stream in inline summaries from the section.  */
    4781              : 
    4782              : static void
    4783        13257 : inline_read_section (struct lto_file_decl_data *file_data, const char *data,
    4784              :                      size_t len)
    4785              : {
    4786        13257 :   const struct lto_function_header *header =
    4787              :     (const struct lto_function_header *) data;
    4788        13257 :   const int cfg_offset = sizeof (struct lto_function_header);
    4789        13257 :   const int main_offset = cfg_offset + header->cfg_size;
    4790        13257 :   const int string_offset = main_offset + header->main_size;
    4791        13257 :   class data_in *data_in;
    4792        13257 :   unsigned int i, count2, j;
    4793        13257 :   unsigned int f_count;
    4794              : 
    4795        13257 :   lto_input_block ib ((const char *) data + main_offset, header->main_size,
    4796        13257 :                       file_data);
    4797              : 
    4798        13257 :   data_in =
    4799        26514 :     lto_data_in_create (file_data, (const char *) data + string_offset,
    4800        13257 :                         header->string_size, vNULL);
    4801        13257 :   f_count = streamer_read_uhwi (&ib);
    4802        99102 :   for (i = 0; i < f_count; i++)
    4803              :     {
    4804        85845 :       unsigned int index;
    4805        85845 :       struct cgraph_node *node;
    4806        85845 :       class ipa_fn_summary *info;
    4807        85845 :       class ipa_node_params *params_summary;
    4808        85845 :       class ipa_size_summary *size_info;
    4809        85845 :       lto_symtab_encoder_t encoder;
    4810        85845 :       struct bitpack_d bp;
    4811        85845 :       struct cgraph_edge *e;
    4812        85845 :       ipa_predicate p;
    4813              : 
    4814        85845 :       index = streamer_read_uhwi (&ib);
    4815        85845 :       encoder = file_data->symtab_node_encoder;
    4816        85845 :       node = dyn_cast<cgraph_node *> (lto_symtab_encoder_deref (encoder,
    4817              :                                                                 index));
    4818        85845 :       info = node->prevailing_p () ? ipa_fn_summaries->get_create (node) : NULL;
    4819        85845 :       params_summary = node->prevailing_p ()
    4820        85845 :                        ? ipa_node_params_sum->get (node) : NULL;
    4821        85845 :       size_info = node->prevailing_p ()
    4822        85845 :                   ? ipa_size_summaries->get_create (node) : NULL;
    4823              : 
    4824        85845 :       int stack_size = streamer_read_uhwi (&ib);
    4825        85845 :       int size = streamer_read_uhwi (&ib);
    4826        85845 :       sreal time = sreal::stream_in (&ib);
    4827              : 
    4828        85845 :       if (info)
    4829              :         {
    4830        85787 :           info->estimated_stack_size
    4831        85787 :             = size_info->estimated_self_stack_size = stack_size;
    4832        85787 :           size_info->size = size_info->self_size = size;
    4833        85787 :           info->time = time;
    4834              :         }
    4835              : 
    4836        85845 :       bp = streamer_read_bitpack (&ib);
    4837        85845 :       if (info)
    4838              :         {
    4839        85787 :           info->inlinable = bp_unpack_value (&bp, 1);
    4840        85787 :           info->fp_expressions = bp_unpack_value (&bp, 1);
    4841        85787 :           if (!lto_stream_offload_p)
    4842        85787 :             info->target_info = streamer_read_uhwi (&ib);
    4843              :         }
    4844              :       else
    4845              :         {
    4846           58 :           bp_unpack_value (&bp, 1);
    4847           58 :           bp_unpack_value (&bp, 1);
    4848           58 :           if (!lto_stream_offload_p)
    4849           58 :             streamer_read_uhwi (&ib);
    4850              :         }
    4851              : 
    4852        85845 :       count2 = streamer_read_uhwi (&ib);
    4853        85845 :       gcc_assert (!info || !info->conds);
    4854        85787 :       if (info)
    4855        85787 :         vec_safe_reserve_exact (info->conds, count2);
    4856       162468 :       for (j = 0; j < count2; j++)
    4857              :         {
    4858        76623 :           struct condition c;
    4859        76623 :           unsigned int k, count3;
    4860        76623 :           c.operand_num = streamer_read_uhwi (&ib);
    4861        76623 :           c.code = (enum tree_code) streamer_read_uhwi (&ib);
    4862        76623 :           c.type = stream_read_tree (&ib, data_in);
    4863        76623 :           c.val = stream_read_tree (&ib, data_in);
    4864        76623 :           bp = streamer_read_bitpack (&ib);
    4865        76623 :           c.agg_contents = bp_unpack_value (&bp, 1);
    4866        76623 :           c.by_ref = bp_unpack_value (&bp, 1);
    4867        76623 :           if (c.agg_contents)
    4868        12385 :             c.offset = streamer_read_uhwi (&ib);
    4869        76623 :           count3 = streamer_read_uhwi (&ib);
    4870        76623 :           c.param_ops = NULL;
    4871        76623 :           if (info)
    4872        76623 :             vec_safe_reserve_exact (c.param_ops, count3);
    4873        76623 :           if (params_summary)
    4874        76623 :             ipa_set_param_used_by_ipa_predicates
    4875        76623 :                     (params_summary, c.operand_num, true);
    4876        80119 :           for (k = 0; k < count3; k++)
    4877              :             {
    4878         3496 :               struct expr_eval_op op;
    4879         3496 :               enum gimple_rhs_class rhs_class;
    4880         3496 :               op.code = (enum tree_code) streamer_read_uhwi (&ib);
    4881         3496 :               op.type = stream_read_tree (&ib, data_in);
    4882         3496 :               switch (rhs_class = get_gimple_rhs_class (op.code))
    4883              :                 {
    4884         1397 :                 case GIMPLE_UNARY_RHS:
    4885         1397 :                   op.index = 0;
    4886         1397 :                   op.val[0] = NULL_TREE;
    4887         1397 :                   op.val[1] = NULL_TREE;
    4888         1397 :                   break;
    4889              : 
    4890         2099 :                 case GIMPLE_BINARY_RHS:
    4891         2099 :                 case GIMPLE_TERNARY_RHS:
    4892         2099 :                   bp = streamer_read_bitpack (&ib);
    4893         2099 :                   op.index = bp_unpack_value (&bp, 2);
    4894         2099 :                   op.val[0] = stream_read_tree (&ib, data_in);
    4895         2099 :                   if (rhs_class == GIMPLE_BINARY_RHS)
    4896         2099 :                     op.val[1] = NULL_TREE;
    4897              :                   else
    4898            0 :                     op.val[1] = stream_read_tree (&ib, data_in);
    4899              :                   break;
    4900              : 
    4901            0 :                 default:
    4902            0 :                   fatal_error (UNKNOWN_LOCATION,
    4903              :                                "invalid fnsummary in LTO stream");
    4904              :                 }
    4905         3496 :               if (info)
    4906         3496 :                 c.param_ops->quick_push (op);
    4907              :             }
    4908        76623 :           if (info)
    4909        76623 :             info->conds->quick_push (c);
    4910              :         }
    4911        85845 :       count2 = streamer_read_uhwi (&ib);
    4912        85845 :       gcc_assert (!info || !info->size_time_table.length ());
    4913        85845 :       if (info && count2)
    4914        85787 :         info->size_time_table.reserve_exact (count2);
    4915       326144 :       for (j = 0; j < count2; j++)
    4916              :         {
    4917       240299 :           class size_time_entry e;
    4918              : 
    4919       240299 :           e.size = streamer_read_uhwi (&ib);
    4920       240299 :           e.time = sreal::stream_in (&ib);
    4921       240299 :           e.exec_predicate.stream_in (&ib);
    4922       240299 :           e.nonconst_predicate.stream_in (&ib);
    4923              : 
    4924       240299 :           if (info)
    4925       240183 :             info->size_time_table.quick_push (e);
    4926              :         }
    4927              : 
    4928        85845 :       count2 = streamer_read_uhwi (&ib);
    4929        87191 :       for (j = 0; j < count2; j++)
    4930              :         {
    4931         1346 :           p.stream_in (&ib);
    4932         1346 :           sreal fcp_freq = sreal::stream_in (&ib);
    4933         1346 :           if (info)
    4934              :             {
    4935         1346 :               ipa_freqcounting_predicate fcp;
    4936         1346 :               fcp.predicate = NULL;
    4937         1346 :               set_hint_predicate (&fcp.predicate, p);
    4938         1346 :               fcp.freq = fcp_freq;
    4939         1346 :               vec_safe_push (info->loop_iterations, fcp);
    4940              :             }
    4941              :         }
    4942        85845 :       count2 = streamer_read_uhwi (&ib);
    4943        86132 :       for (j = 0; j < count2; j++)
    4944              :         {
    4945          287 :           p.stream_in (&ib);
    4946          287 :           sreal fcp_freq = sreal::stream_in (&ib);
    4947          287 :           if (info)
    4948              :             {
    4949          287 :               ipa_freqcounting_predicate fcp;
    4950          287 :               fcp.predicate = NULL;
    4951          287 :               set_hint_predicate (&fcp.predicate, p);
    4952          287 :               fcp.freq = fcp_freq;
    4953          287 :               vec_safe_push (info->loop_strides, fcp);
    4954              :             }
    4955              :         }
    4956        85845 :       count2 = streamer_read_uhwi (&ib);
    4957        85845 :       if (info && count2)
    4958            6 :         info->builtin_constant_p_parms.reserve_exact (count2);
    4959        85851 :       for (j = 0; j < count2; j++)
    4960              :         {
    4961            6 :           int parm = streamer_read_uhwi (&ib);
    4962            6 :           if (info)
    4963            6 :             info->builtin_constant_p_parms.quick_push (parm);
    4964              :         }
    4965       431070 :       for (e = node->callees; e; e = e->next_callee)
    4966       345225 :         read_ipa_call_summary (&ib, e, info != NULL);
    4967        87313 :       for (e = node->indirect_calls; e; e = e->next_callee)
    4968         1468 :         read_ipa_call_summary (&ib, e, info != NULL);
    4969              :     }
    4970              : 
    4971        13257 :   lto_free_section_data (file_data, LTO_section_ipa_fn_summary, NULL, data,
    4972              :                          len);
    4973        13257 :   lto_data_in_delete (data_in);
    4974        13257 : }
    4975              : 
    4976              : 
    4977              : /* Read inline summary.  Jump functions are shared among ipa-cp
    4978              :    and inliner, so when ipa-cp is active, we don't need to write them
    4979              :    twice.  */
    4980              : 
    4981              : static void
    4982        12202 : ipa_fn_summary_read (void)
    4983              : {
    4984        12202 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    4985        12202 :   struct lto_file_decl_data *file_data;
    4986        12202 :   unsigned int j = 0;
    4987              : 
    4988        12202 :   ipa_prop_read_jump_functions ();
    4989        12202 :   ipa_fn_summary_alloc ();
    4990              : 
    4991        37661 :   while ((file_data = file_data_vec[j++]))
    4992              :     {
    4993        13257 :       size_t len;
    4994        13257 :       const char *data
    4995        13257 :         = lto_get_summary_section_data (file_data, LTO_section_ipa_fn_summary,
    4996              :                                         &len);
    4997        13257 :       if (data)
    4998        13257 :         inline_read_section (file_data, data, len);
    4999              :       else
    5000              :         /* Fatal error here.  We do not want to support compiling ltrans units
    5001              :            with different version of compiler or different flags than the WPA
    5002              :            unit, so this should never happen.  */
    5003            0 :         fatal_error (input_location,
    5004              :                      "ipa inline summary is missing in input file");
    5005              :     }
    5006        12202 :   ipa_register_cgraph_hooks ();
    5007              : 
    5008        12202 :   gcc_assert (ipa_fn_summaries);
    5009        12202 :   ipa_fn_summaries->enable_insertion_hook ();
    5010        12202 : }
    5011              : 
    5012              : 
    5013              : /* Write inline summary for edge E to OB.  */
    5014              : 
    5015              : static void
    5016       378072 : write_ipa_call_summary (struct output_block *ob, struct cgraph_edge *e)
    5017              : {
    5018       378072 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
    5019       378072 :   int i;
    5020              : 
    5021       378072 :   streamer_write_uhwi (ob, es->call_stmt_size);
    5022       378072 :   streamer_write_uhwi (ob, es->call_stmt_time);
    5023       378072 :   streamer_write_uhwi (ob, es->loop_depth);
    5024              : 
    5025       378072 :   bitpack_d bp = bitpack_create (ob->main_stream);
    5026       378072 :   bp_pack_value (&bp, es->is_return_callee_uncaptured, 1);
    5027       378072 :   streamer_write_bitpack (&bp);
    5028              : 
    5029       378072 :   if (es->predicate)
    5030        10495 :     es->predicate->stream_out (ob);
    5031              :   else
    5032       367577 :     streamer_write_uhwi (ob, 0);
    5033       378072 :   streamer_write_uhwi (ob, es->param.length ());
    5034      2282127 :   for (i = 0; i < (int) es->param.length (); i++)
    5035              :     {
    5036       629350 :       streamer_write_uhwi (ob, es->param[i].change_prob);
    5037       629350 :       bp = bitpack_create (ob->main_stream);
    5038       629350 :       bp_pack_value (&bp, es->param[i].points_to_local_or_readonly_memory, 1);
    5039       629350 :       bp_pack_value (&bp, es->param[i].points_to_possible_sra_candidate, 1);
    5040       629350 :       streamer_write_bitpack (&bp);
    5041              :     }
    5042       378072 : }
    5043              : 
    5044              : 
    5045              : /* Write inline summary for node in SET.
    5046              :    Jump functions are shared among ipa-cp and inliner, so when ipa-cp is
    5047              :    active, we don't need to write them twice.  */
    5048              : 
    5049              : static void
    5050        23036 : ipa_fn_summary_write (void)
    5051              : {
    5052        23036 :   struct output_block *ob = create_output_block (LTO_section_ipa_fn_summary);
    5053        23036 :   lto_symtab_encoder_iterator lsei;
    5054        23036 :   lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
    5055        23036 :   unsigned int count = 0;
    5056              : 
    5057       127583 :   for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
    5058       104547 :        lsei_next_function_in_partition (&lsei))
    5059              :     {
    5060       104547 :       cgraph_node *cnode = lsei_cgraph_node (lsei);
    5061       104547 :       if (cnode->definition && !cnode->alias)
    5062       102136 :         count++;
    5063              :     }
    5064        23036 :   streamer_write_uhwi (ob, count);
    5065              : 
    5066       127583 :   for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
    5067       104547 :        lsei_next_function_in_partition (&lsei))
    5068              :     {
    5069       104547 :       cgraph_node *cnode = lsei_cgraph_node (lsei);
    5070       104547 :       if (cnode->definition && !cnode->alias)
    5071              :         {
    5072       102136 :           class ipa_fn_summary *info = ipa_fn_summaries->get (cnode);
    5073       102136 :           class ipa_size_summary *size_info = ipa_size_summaries->get (cnode);
    5074       102136 :           struct bitpack_d bp;
    5075       102136 :           struct cgraph_edge *edge;
    5076       102136 :           int i;
    5077       102136 :           size_time_entry *e;
    5078       102136 :           struct condition *c;
    5079              : 
    5080       102136 :           streamer_write_uhwi (ob, lto_symtab_encoder_encode (encoder, cnode));
    5081       102136 :           streamer_write_hwi (ob, size_info->estimated_self_stack_size);
    5082       102136 :           streamer_write_hwi (ob, size_info->self_size);
    5083       102136 :           info->time.stream_out (ob);
    5084       102136 :           bp = bitpack_create (ob->main_stream);
    5085       102136 :           bp_pack_value (&bp, info->inlinable, 1);
    5086       102136 :           bp_pack_value (&bp, info->fp_expressions, 1);
    5087       102136 :           streamer_write_bitpack (&bp);
    5088       102136 :           if (!lto_stream_offload_p)
    5089       102136 :             streamer_write_uhwi (ob, info->target_info);
    5090       102136 :           streamer_write_uhwi (ob, vec_safe_length (info->conds));
    5091       194348 :           for (i = 0; vec_safe_iterate (info->conds, i, &c); i++)
    5092              :             {
    5093        92212 :               int j;
    5094        92212 :               struct expr_eval_op *op;
    5095              : 
    5096        92212 :               streamer_write_uhwi (ob, c->operand_num);
    5097        92212 :               streamer_write_uhwi (ob, c->code);
    5098        92212 :               stream_write_tree (ob, c->type, true);
    5099        92212 :               stream_write_tree (ob, c->val, true);
    5100        92212 :               bp = bitpack_create (ob->main_stream);
    5101        92212 :               bp_pack_value (&bp, c->agg_contents, 1);
    5102        92212 :               bp_pack_value (&bp, c->by_ref, 1);
    5103        92212 :               streamer_write_bitpack (&bp);
    5104        92212 :               if (c->agg_contents)
    5105        15544 :                 streamer_write_uhwi (ob, c->offset);
    5106        92212 :               streamer_write_uhwi (ob, vec_safe_length (c->param_ops));
    5107       191379 :               for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
    5108              :                 {
    5109         4068 :                   streamer_write_uhwi (ob, op->code);
    5110         4068 :                   stream_write_tree (ob, op->type, true);
    5111         4068 :                   if (op->val[0])
    5112              :                     {
    5113         2458 :                       bp = bitpack_create (ob->main_stream);
    5114         2458 :                       bp_pack_value (&bp, op->index, 2);
    5115         2458 :                       streamer_write_bitpack (&bp);
    5116         2458 :                       stream_write_tree (ob, op->val[0], true);
    5117         2458 :                       if (op->val[1])
    5118            4 :                         stream_write_tree (ob, op->val[1], true);
    5119              :                     }
    5120              :                 }
    5121              :             }
    5122       102136 :           streamer_write_uhwi (ob, info->size_time_table.length ());
    5123       493650 :           for (i = 0; info->size_time_table.iterate (i, &e); i++)
    5124              :             {
    5125       289378 :               streamer_write_uhwi (ob, e->size);
    5126       289378 :               e->time.stream_out (ob);
    5127       289378 :               e->exec_predicate.stream_out (ob);
    5128       289378 :               e->nonconst_predicate.stream_out (ob);
    5129              :             }
    5130       102136 :           ipa_freqcounting_predicate *fcp;
    5131       102136 :           streamer_write_uhwi (ob, vec_safe_length (info->loop_iterations));
    5132       206240 :           for (i = 0; vec_safe_iterate (info->loop_iterations, i, &fcp); i++)
    5133              :             {
    5134         1968 :               fcp->predicate->stream_out (ob);
    5135         1968 :               fcp->freq.stream_out (ob);
    5136              :             }
    5137       102136 :           streamer_write_uhwi (ob, vec_safe_length (info->loop_strides));
    5138       204611 :           for (i = 0; vec_safe_iterate (info->loop_strides, i, &fcp); i++)
    5139              :             {
    5140          339 :               fcp->predicate->stream_out (ob);
    5141          339 :               fcp->freq.stream_out (ob);
    5142              :             }
    5143       102136 :           streamer_write_uhwi (ob, info->builtin_constant_p_parms.length ());
    5144       102136 :           int ip;
    5145       204286 :           for (i = 0; info->builtin_constant_p_parms.iterate (i, &ip);
    5146              :                i++)
    5147           14 :             streamer_write_uhwi (ob, ip);
    5148       477536 :           for (edge = cnode->callees; edge; edge = edge->next_callee)
    5149       375400 :             write_ipa_call_summary (ob, edge);
    5150       104808 :           for (edge = cnode->indirect_calls; edge; edge = edge->next_callee)
    5151         2672 :             write_ipa_call_summary (ob, edge);
    5152              :         }
    5153              :     }
    5154        23036 :   streamer_write_char_stream (ob->main_stream, 0);
    5155        23036 :   produce_asm (ob);
    5156        23036 :   destroy_output_block (ob);
    5157              : 
    5158        23036 :   ipa_prop_write_jump_functions ();
    5159        23036 : }
    5160              : 
    5161              : 
    5162              : /* Release function summary.  */
    5163              : 
    5164              : void
    5165       717481 : ipa_free_fn_summary (void)
    5166              : {
    5167       717481 :   if (!ipa_call_summaries)
    5168              :     return;
    5169       454055 :   ggc_delete (ipa_fn_summaries);
    5170       454055 :   ipa_fn_summaries = NULL;
    5171       454055 :   delete ipa_call_summaries;
    5172       454055 :   ipa_call_summaries = NULL;
    5173       454055 :   edge_predicate_pool.release ();
    5174              :   /* During IPA this is one of largest datastructures to release.  */
    5175       454055 :   if (flag_wpa)
    5176         7817 :     ggc_trim ();
    5177              : }
    5178              : 
    5179              : /* Release function summary.  */
    5180              : 
    5181              : void
    5182       717481 : ipa_free_size_summary (void)
    5183              : {
    5184       717481 :   if (!ipa_size_summaries)
    5185              :     return;
    5186       454055 :   delete ipa_size_summaries;
    5187       454055 :   ipa_size_summaries = NULL;
    5188              : }
    5189              : 
    5190              : namespace {
    5191              : 
    5192              : const pass_data pass_data_local_fn_summary =
    5193              : {
    5194              :   GIMPLE_PASS, /* type */
    5195              :   "local-fnsummary", /* name */
    5196              :   OPTGROUP_INLINE, /* optinfo_flags */
    5197              :   TV_INLINE_PARAMETERS, /* tv_id */
    5198              :   0, /* properties_required */
    5199              :   0, /* properties_provided */
    5200              :   0, /* properties_destroyed */
    5201              :   0, /* todo_flags_start */
    5202              :   0, /* todo_flags_finish */
    5203              : };
    5204              : 
    5205              : class pass_local_fn_summary : public gimple_opt_pass
    5206              : {
    5207              : public:
    5208       571444 :   pass_local_fn_summary (gcc::context *ctxt)
    5209      1142888 :     : gimple_opt_pass (pass_data_local_fn_summary, ctxt)
    5210              :   {}
    5211              : 
    5212              :   /* opt_pass methods: */
    5213       285722 :   opt_pass * clone () final override
    5214              :   {
    5215       285722 :     return new pass_local_fn_summary (m_ctxt);
    5216              :   }
    5217      5696735 :   unsigned int execute (function *) final override
    5218              :     {
    5219      5696735 :       return compute_fn_summary_for_current ();
    5220              :     }
    5221              : 
    5222              : }; // class pass_local_fn_summary
    5223              : 
    5224              : } // anon namespace
    5225              : 
    5226              : gimple_opt_pass *
    5227       285722 : make_pass_local_fn_summary (gcc::context *ctxt)
    5228              : {
    5229       285722 :   return new pass_local_fn_summary (ctxt);
    5230              : }
    5231              : 
    5232              : 
    5233              : /* Free inline summary.  */
    5234              : 
    5235              : namespace {
    5236              : 
    5237              : const pass_data pass_data_ipa_free_fn_summary =
    5238              : {
    5239              :   SIMPLE_IPA_PASS, /* type */
    5240              :   "free-fnsummary", /* name */
    5241              :   OPTGROUP_NONE, /* optinfo_flags */
    5242              :   TV_IPA_FREE_INLINE_SUMMARY, /* tv_id */
    5243              :   0, /* properties_required */
    5244              :   0, /* properties_provided */
    5245              :   0, /* properties_destroyed */
    5246              :   0, /* todo_flags_start */
    5247              :   0, /* todo_flags_finish */
    5248              : };
    5249              : 
    5250              : class pass_ipa_free_fn_summary : public simple_ipa_opt_pass
    5251              : {
    5252              : public:
    5253       571444 :   pass_ipa_free_fn_summary (gcc::context *ctxt)
    5254       571444 :     : simple_ipa_opt_pass (pass_data_ipa_free_fn_summary, ctxt),
    5255      1142888 :       small_p (false)
    5256              :   {}
    5257              : 
    5258              :   /* opt_pass methods: */
    5259       285722 :   opt_pass *clone () final override
    5260              :   {
    5261       285722 :     return new pass_ipa_free_fn_summary (m_ctxt);
    5262              :   }
    5263       571444 :   void set_pass_param (unsigned int n, bool param) final override
    5264              :     {
    5265       571444 :       gcc_assert (n == 0);
    5266       571444 :       small_p = param;
    5267       571444 :     }
    5268       480420 :   bool gate (function *) final override { return true; }
    5269       460018 :   unsigned int execute (function *) final override
    5270              :     {
    5271       460018 :       ipa_free_fn_summary ();
    5272              :       /* Free ipa-prop structures if they are no longer needed.  */
    5273       460018 :       ipa_free_all_structures_after_iinln ();
    5274       460018 :       if (!flag_wpa)
    5275       452201 :         ipa_free_size_summary ();
    5276       460018 :       return 0;
    5277              :     }
    5278              : 
    5279              : private:
    5280              :   bool small_p;
    5281              : }; // class pass_ipa_free_fn_summary
    5282              : 
    5283              : } // anon namespace
    5284              : 
    5285              : simple_ipa_opt_pass *
    5286       285722 : make_pass_ipa_free_fn_summary (gcc::context *ctxt)
    5287              : {
    5288       285722 :   return new pass_ipa_free_fn_summary (ctxt);
    5289              : }
    5290              : 
    5291              : namespace {
    5292              : 
    5293              : const pass_data pass_data_ipa_fn_summary =
    5294              : {
    5295              :   IPA_PASS, /* type */
    5296              :   "fnsummary", /* name */
    5297              :   OPTGROUP_INLINE, /* optinfo_flags */
    5298              :   TV_IPA_FNSUMMARY, /* tv_id */
    5299              :   0, /* properties_required */
    5300              :   0, /* properties_provided */
    5301              :   0, /* properties_destroyed */
    5302              :   0, /* todo_flags_start */
    5303              :   ( TODO_dump_symtab ), /* todo_flags_finish */
    5304              : };
    5305              : 
    5306              : class pass_ipa_fn_summary : public ipa_opt_pass_d
    5307              : {
    5308              : public:
    5309       285722 :   pass_ipa_fn_summary (gcc::context *ctxt)
    5310              :     : ipa_opt_pass_d (pass_data_ipa_fn_summary, ctxt,
    5311              :                       ipa_fn_summary_generate, /* generate_summary */
    5312              :                       ipa_fn_summary_write, /* write_summary */
    5313              :                       ipa_fn_summary_read, /* read_summary */
    5314              :                       NULL, /* write_optimization_summary */
    5315              :                       NULL, /* read_optimization_summary */
    5316              :                       NULL, /* stmt_fixup */
    5317              :                       0, /* function_transform_todo_flags_start */
    5318              :                       NULL, /* function_transform */
    5319       285722 :                       NULL) /* variable_transform */
    5320       285722 :   {}
    5321              : 
    5322              :   /* opt_pass methods: */
    5323       230063 :   unsigned int execute (function *) final override { return 0; }
    5324              : 
    5325              : }; // class pass_ipa_fn_summary
    5326              : 
    5327              : } // anon namespace
    5328              : 
    5329              : ipa_opt_pass_d *
    5330       285722 : make_pass_ipa_fn_summary (gcc::context *ctxt)
    5331              : {
    5332       285722 :   return new pass_ipa_fn_summary (ctxt);
    5333              : }
    5334              : 
    5335              : /* Reset all state within ipa-fnsummary.cc so that we can rerun the compiler
    5336              :    within the same process.  For use by toplev::finalize.  */
    5337              : 
    5338              : void
    5339       256621 : ipa_fnsummary_cc_finalize (void)
    5340              : {
    5341       256621 :   ipa_free_fn_summary ();
    5342       256621 :   ipa_free_size_summary ();
    5343       256621 : }
        

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.