LCOV - code coverage report
Current view: top level - gcc - ipa-fnsummary.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.4 % 2961 2854
Test Date: 2026-12-05 16:10:02 Functions: 99.0 % 99 98
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 "gimple-fold.h"
      75              : #include "tree-cfg.h"
      76              : #include "tree-ssa-loop-niter.h"
      77              : #include "tree-ssa-loop.h"
      78              : #include "symbol-summary.h"
      79              : #include "sreal.h"
      80              : #include "ipa-cp.h"
      81              : #include "ipa-prop.h"
      82              : #include "ipa-fnsummary.h"
      83              : #include "cfgloop.h"
      84              : #include "tree-scalar-evolution.h"
      85              : #include "ipa-utils.h"
      86              : #include "cfgexpand.h"
      87              : #include "gimplify.h"
      88              : #include "stringpool.h"
      89              : #include "attribs.h"
      90              : #include "tree-into-ssa.h"
      91              : #include "symtab-clones.h"
      92              : #include "gimple-range.h"
      93              : #include "tree-dfa.h"
      94              : #include "attr-callback.h"
      95              : #include "callback-info.h"
      96              : 
      97              : /* Summaries.  */
      98              : fast_function_summary <ipa_fn_summary *, va_gc> *ipa_fn_summaries;
      99              : fast_function_summary <ipa_size_summary *, va_heap> *ipa_size_summaries;
     100              : fast_call_summary <ipa_call_summary *, va_heap> *ipa_call_summaries;
     101              : 
     102              : /* Edge predicates goes here.  */
     103              : static object_allocator<ipa_predicate> edge_predicate_pool ("edge predicates");
     104              : 
     105              : 
     106              : /* Dump IPA hints.  */
     107              : void
     108          245 : ipa_dump_hints (FILE *f, ipa_hints hints)
     109              : {
     110          245 :   if (!hints)
     111              :     return;
     112          161 :   fprintf (f, "IPA hints:");
     113          161 :   if (hints & INLINE_HINT_indirect_call)
     114              :     {
     115           25 :       hints &= ~INLINE_HINT_indirect_call;
     116           25 :       fprintf (f, " indirect_call");
     117              :     }
     118          161 :   if (hints & INLINE_HINT_loop_iterations)
     119              :     {
     120            4 :       hints &= ~INLINE_HINT_loop_iterations;
     121            4 :       fprintf (f, " loop_iterations");
     122              :     }
     123          161 :   if (hints & INLINE_HINT_loop_stride)
     124              :     {
     125            3 :       hints &= ~INLINE_HINT_loop_stride;
     126            3 :       fprintf (f, " loop_stride");
     127              :     }
     128          161 :   if (hints & INLINE_HINT_same_scc)
     129              :     {
     130            4 :       hints &= ~INLINE_HINT_same_scc;
     131            4 :       fprintf (f, " same_scc");
     132              :     }
     133          161 :   if (hints & INLINE_HINT_in_scc)
     134              :     {
     135           11 :       hints &= ~INLINE_HINT_in_scc;
     136           11 :       fprintf (f, " in_scc");
     137              :     }
     138          161 :   if (hints & INLINE_HINT_cross_module)
     139              :     {
     140            2 :       hints &= ~INLINE_HINT_cross_module;
     141            2 :       fprintf (f, " cross_module");
     142              :     }
     143          161 :   if (hints & INLINE_HINT_declared_inline)
     144              :     {
     145          132 :       hints &= ~INLINE_HINT_declared_inline;
     146          132 :       fprintf (f, " declared_inline");
     147              :     }
     148          161 :   if (hints & INLINE_HINT_known_hot)
     149              :     {
     150            1 :       hints &= ~INLINE_HINT_known_hot;
     151            1 :       fprintf (f, " known_hot");
     152              :     }
     153          161 :   if (hints & INLINE_HINT_builtin_constant_p)
     154              :     {
     155            4 :       hints &= ~INLINE_HINT_builtin_constant_p;
     156            4 :       fprintf (f, " builtin_constant_p");
     157              :     }
     158          161 :   gcc_assert (!hints);
     159              : }
     160              : 
     161              : 
     162              : /* Record SIZE and TIME to SUMMARY.
     163              :    The accounted code will be executed when EXEC_PRED is true.
     164              :    When NONCONST_PRED is false the code will evaluate to constant and
     165              :    will get optimized out in specialized clones of the function.
     166              :    If CALL is true account to call_size_time_table rather than
     167              :    size_time_table.   */
     168              : 
     169              : void
     170    140407285 : ipa_fn_summary::account_size_time (int size, sreal time,
     171              :                                    const ipa_predicate &exec_pred,
     172              :                                    const ipa_predicate &nonconst_pred_in,
     173              :                                    bool call)
     174              : {
     175    140407285 :   size_time_entry *e;
     176    140407285 :   bool found = false;
     177    140407285 :   int i;
     178    140407285 :   ipa_predicate nonconst_pred;
     179    140407285 :   vec<size_time_entry> *table = call ? &call_size_time_table : &size_time_table;
     180              : 
     181    140407285 :   if (exec_pred == false)
     182      5132661 :     return;
     183              : 
     184    140114515 :   nonconst_pred = nonconst_pred_in & exec_pred;
     185              : 
     186    140114515 :   if (nonconst_pred == false)
     187              :     return;
     188              : 
     189              :   /* We need to create initial empty unconditional clause, but otherwise
     190              :      we don't need to account empty times and sizes.  */
     191    163987619 :   if (!size && time == 0 && table->length ())
     192      3978691 :     return;
     193              : 
     194              :   /* Only for calls we are unaccounting what we previously recorded.  */
     195    135274624 :   gcc_checking_assert (time >= 0 || call);
     196              : 
     197    549692774 :   for (i = 0; table->iterate (i, &e); i++)
     198    517305583 :     if (e->exec_predicate == exec_pred
     199    517305583 :         && e->nonconst_predicate == nonconst_pred)
     200              :       {
     201              :         found = true;
     202              :         break;
     203              :       }
     204    135274624 :   if (i == max_size_time_table_size)
     205              :     {
     206         4896 :       i = 0;
     207         4896 :       found = true;
     208         4896 :       e = &(*table)[0];
     209         4896 :       if (dump_file && (dump_flags & TDF_DETAILS))
     210            0 :         fprintf (dump_file,
     211              :                  "\t\tReached limit on number of entries, "
     212              :                  "ignoring the predicate.");
     213              :     }
     214    135280248 :   if (dump_file && (dump_flags & TDF_DETAILS) && (time != 0 || size))
     215              :     {
     216         5293 :       fprintf (dump_file,
     217              :                "\t\tAccounting size:%3.2f, time:%3.2f on %spredicate exec:",
     218         4786 :                ((double) size) / ipa_fn_summary::size_scale,
     219              :                (time.to_double ()), found ? "" : "new ");
     220         4786 :       exec_pred.dump (dump_file, conds, 0);
     221         4786 :       if (exec_pred != nonconst_pred)
     222              :         {
     223          248 :           fprintf (dump_file, " nonconst:");
     224          248 :           nonconst_pred.dump (dump_file, conds);
     225              :         }
     226              :       else
     227         4538 :         fprintf (dump_file, "\n");
     228              :     }
     229    135274624 :   if (!found)
     230              :     {
     231     32382295 :       class size_time_entry new_entry;
     232     32382295 :       new_entry.size = size;
     233     32382295 :       new_entry.time = time;
     234     32382295 :       new_entry.exec_predicate = exec_pred;
     235     32382295 :       new_entry.nonconst_predicate = nonconst_pred;
     236     32382295 :       if (call)
     237      1455182 :         call_size_time_table.safe_push (new_entry);
     238              :       else
     239     30927113 :         size_time_table.safe_push (new_entry);
     240              :     }
     241              :   else
     242              :     {
     243    102892329 :       e->size += size;
     244    102892329 :       e->time += time;
     245              :       /* FIXME: PR bootstrap/92653 gcc_checking_assert (e->time >= -1); */
     246              :       /* Tolerate small roundoff issues.  */
     247    102892329 :       if (e->time < 0)
     248          254 :         e->time = 0;
     249              :     }
     250              : }
     251              : 
     252              : /* We proved E to be unreachable, redirect it to __builtin_unreachable.  */
     253              : 
     254              : static struct cgraph_edge *
     255       348396 : redirect_to_unreachable (struct cgraph_edge *e)
     256              : {
     257       348396 :   struct cgraph_node *callee = !e->inline_failed ? e->callee : NULL;
     258       348396 :   struct cgraph_node *target
     259       348396 :     = cgraph_node::get_create (builtin_decl_unreachable ());
     260              : 
     261       348396 :   gcc_checking_assert (lookup_attribute ("cold",
     262              :                                          DECL_ATTRIBUTES (target->decl)));
     263              : 
     264       348396 :   if (e->speculative)
     265          311 :     e = cgraph_edge::resolve_speculation (e, target->decl);
     266       348085 :   else if (!e->callee)
     267          810 :     e = cgraph_edge::make_direct (e, target);
     268              :   else
     269       347275 :     e->redirect_callee (target);
     270       348396 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
     271       348396 :   e->inline_failed = CIF_UNREACHABLE;
     272       348396 :   e->count = profile_count::zero ();
     273       348396 :   es->call_stmt_size = 0;
     274       348396 :   es->call_stmt_time = 0;
     275       348396 :   if (callee)
     276            0 :     callee->remove_symbol_and_inline_clones ();
     277       348396 :   if (e->has_callback)
     278           16 :     for (cgraph_edge *cbe = e->first_callback_edge (); cbe;
     279            5 :          cbe = cbe->next_callback_edge ())
     280              :       /* If the carrying edge is unreachable, so are the callback calls.  */
     281            5 :       redirect_to_unreachable (cbe);
     282       348396 :   return e;
     283              : }
     284              : 
     285              : /* Set predicate for edge E.  */
     286              : 
     287              : static void
     288     32173852 : edge_set_predicate (struct cgraph_edge *e, ipa_predicate *predicate)
     289              : {
     290              :   /* If the edge is determined to be never executed, redirect it
     291              :      to BUILTIN_UNREACHABLE to make it clear to IPA passes the call will
     292              :      be optimized out.  */
     293     29233322 :   if (predicate && *predicate == false
     294              :       /* When handling speculative edges, we need to do the redirection
     295              :          just once.  Do it always on the direct edge, so we do not
     296              :          attempt to resolve speculation while duplicating the edge.  */
     297     32522320 :       && (!e->speculative || e->callee))
     298       348391 :     e = redirect_to_unreachable (e);
     299              : 
     300     32173852 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
     301     61407174 :   if (predicate && *predicate != true)
     302              :     {
     303      5249281 :       if (!es->predicate)
     304      4599142 :         es->predicate = edge_predicate_pool.allocate ();
     305      5249281 :       *es->predicate = *predicate;
     306              :     }
     307              :   else
     308              :     {
     309     26924571 :       if (es->predicate)
     310       750629 :         edge_predicate_pool.remove (es->predicate);
     311     26924571 :       es->predicate = NULL;
     312              :     }
     313     32173852 : }
     314              : 
     315              : /* Set predicate for hint *P.  */
     316              : 
     317              : static void
     318       167660 : set_hint_predicate (ipa_predicate **p, ipa_predicate new_predicate)
     319              : {
     320       167660 :   if (new_predicate == false || new_predicate == true)
     321              :     {
     322         4111 :       if (*p)
     323            0 :         edge_predicate_pool.remove (*p);
     324         4111 :       *p = NULL;
     325              :     }
     326              :   else
     327              :     {
     328       163549 :       if (!*p)
     329       163549 :         *p = edge_predicate_pool.allocate ();
     330       163549 :       **p = new_predicate;
     331              :     }
     332       167660 : }
     333              : 
     334              : /* Find if NEW_PREDICATE is already in V and if so, increment its freq.
     335              :    Otherwise add a new item to the vector with this predicate and frerq equal
     336              :    to add_freq, unless the number of predicates would exceed MAX_NUM_PREDICATES
     337              :    in which case the function does nothing.  */
     338              : 
     339              : static void
     340      1156869 : add_freqcounting_predicate (vec<ipa_freqcounting_predicate, va_gc> **v,
     341              :                             const ipa_predicate &new_predicate, sreal add_freq,
     342              :                             unsigned max_num_predicates)
     343              : {
     344      1156869 :   if (new_predicate == false || new_predicate == true)
     345              :     return;
     346              :   ipa_freqcounting_predicate *f;
     347       162696 :   for (int i = 0; vec_safe_iterate (*v, i, &f); i++)
     348        79238 :     if (new_predicate == f->predicate)
     349              :       {
     350            0 :         f->freq += add_freq;
     351            0 :         return;
     352              :       }
     353       114451 :   if (vec_safe_length (*v) >= max_num_predicates)
     354              :     /* Too many different predicates to account for.  */
     355              :     return;
     356              : 
     357        83228 :   ipa_freqcounting_predicate fcp;
     358        83228 :   fcp.predicate = NULL;
     359        83228 :   set_hint_predicate (&fcp.predicate, new_predicate);
     360        83228 :   fcp.freq = add_freq;
     361        83228 :   vec_safe_push (*v, fcp);
     362        83228 :   return;
     363              : }
     364              : 
     365              : /* Compute what conditions may or may not hold given information about
     366              :    parameters.  RET_CLAUSE returns truths that may hold in a specialized copy,
     367              :    while RET_NONSPEC_CLAUSE returns truths that may hold in an nonspecialized
     368              :    copy when called in a given context.  It is a bitmask of conditions. Bit
     369              :    0 means that condition is known to be false, while bit 1 means that condition
     370              :    may or may not be true.  These differs - for example NOT_INLINED condition
     371              :    is always false in the second and also builtin_constant_p tests cannot use
     372              :    the fact that parameter is indeed a constant.
     373              : 
     374              :    When INLINE_P is true, assume that we are inlining.  AVAL contains known
     375              :    information about argument values.  The function does not modify its content
     376              :    and so AVALs could also be of type ipa_call_arg_values but so far all
     377              :    callers work with the auto version and so we avoid the conversion for
     378              :    convenience.
     379              : 
     380              :    ERROR_MARK value of an argument means compile time invariant.  */
     381              : 
     382              : /* Hashmap traits that free the cached sbitmap when an entry is removed.  */
     383              : 
     384              : struct string_char_set_hashmap_traits
     385              :   : simple_hashmap_traits<default_hash_traits<tree>, sbitmap>
     386              : {
     387              :   template <typename T>
     388              :   static inline void
     389           16 :   remove (T &entry)
     390              :   {
     391           16 :     sbitmap_free (entry.m_value);
     392           16 :     simple_hashmap_traits<default_hash_traits<tree>, sbitmap>::remove (entry);
     393              :   }
     394              : };
     395              : 
     396              : /* Map from unique STRING_CST tree nodes (longer than 256 bytes) to an
     397              :    sbitmap recording which byte values appear in the string.  */
     398              : 
     399              : static hash_map<tree, sbitmap, string_char_set_hashmap_traits>
     400              :   *string_char_set_cache;
     401              : 
     402              : /* Return the character presence bitmap for STR (with TREE_STRING_LENGTH (STR)
     403              :    > 256), populating and memoizing it on first lookup.  PREC is the character
     404              :    type precision.  */
     405              : 
     406              : static const_sbitmap
     407          140 : get_string_char_set (tree str, unsigned int prec)
     408              : {
     409          140 :   if (!string_char_set_cache)
     410            1 :     string_char_set_cache
     411            1 :       = new hash_map<tree, sbitmap, string_char_set_hashmap_traits>;
     412              : 
     413          140 :   bool existed;
     414          140 :   sbitmap &bmp = string_char_set_cache->get_or_insert (str, &existed);
     415          140 :   if (!existed)
     416              :     {
     417           16 :       unsigned int full = 1U << prec;
     418           16 :       unsigned int mask = full - 1;
     419           16 :       bmp = sbitmap_alloc (full);
     420           16 :       bitmap_clear (bmp);
     421           16 :       unsigned int len = TREE_STRING_LENGTH (str);
     422           16 :       const char *p = TREE_STRING_POINTER (str);
     423         5039 :       for (unsigned int i = 0; i < len; i++)
     424         5023 :         bitmap_set_bit (bmp, (unsigned char) p[i] & mask);
     425              :     }
     426          140 :   return bmp;
     427              : }
     428              : 
     429              : /* Return true if BMP contains any character whose ordered value with
     430              :    signedness SGN and precision PREC falls in the inclusive unsigned
     431              :    coordinate range [U_LO, U_HI].
     432              : 
     433              :    For UNSIGNED, ordered coordinate == raw byte value.
     434              :    For SIGNED, ordered coordinate == raw byte value ^ (1 << (PREC - 1)), so
     435              :    negative bytes map to [0, half - 1] (raw [half, 2*half - 1]) and
     436              :    non-negative bytes map to [half, 2*half - 1] (raw [0, half - 1]).  */
     437              : 
     438              : static bool
     439          160 : char_set_any_in_range_p (const_sbitmap bmp, unsigned int prec, signop sgn,
     440              :                           unsigned int u_lo, unsigned int u_hi)
     441              : {
     442          160 :   if (u_lo > u_hi)
     443              :     return false;
     444          160 :   if (sgn == UNSIGNED)
     445           48 :     return bitmap_any_bit_in_range_p (bmp, u_lo, u_hi);
     446              : 
     447          112 :   unsigned int half = 1U << (prec - 1);
     448              :   /* Check negative byte values in [u_lo, min (u_hi, half - 1)].  */
     449          112 :   if (u_lo < half
     450          168 :       && bitmap_any_bit_in_range_p (bmp, u_lo + half,
     451           56 :                                     MIN (u_hi, half - 1) + half))
     452              :     return true;
     453              :   /* Check non-negative byte values in [max (u_lo, half), u_hi].  */
     454           96 :   if (u_hi >= half
     455           96 :       && bitmap_any_bit_in_range_p (bmp, MAX (u_lo, half) - half, u_hi - half))
     456              :     return true;
     457              :   return false;
     458              : }
     459              : 
     460              : /* Fold comparison (ch CODE VAL) across every byte ch of constant string STR
     461              :    (interpreted with type CHAR_TYPE, defaulting to the element type of STR when
     462              :    NULL).  Return boolean_true_node or boolean_false_node if the comparison has
     463              :    the same boolean result for all bytes of STR, or NULL_TREE otherwise.  */
     464              : 
     465              : static tree
     466        62158 : fold_string_char_compare (tree str, enum tree_code code, tree val,
     467              :                           tree char_type)
     468              : {
     469            0 :   if (!char_type && str && TREE_TYPE (str)
     470        62158 :       && TREE_CODE (TREE_TYPE (str)) == ARRAY_TYPE)
     471            0 :     char_type = TREE_TYPE (TREE_TYPE (str));
     472              : 
     473        62158 :   if (!str
     474        62158 :       || TREE_CODE (str) != STRING_CST
     475        62158 :       || !val
     476        62158 :       || TREE_CODE (val) != INTEGER_CST
     477        62158 :       || !char_type
     478        62158 :       || TREE_CODE (char_type) != INTEGER_TYPE
     479       124316 :       || TYPE_PRECISION (char_type) != BITS_PER_UNIT)
     480              :     return NULL_TREE;
     481              : 
     482        62158 :   unsigned prec = TYPE_PRECISION (char_type);
     483        62158 :   signop sgn = TYPE_SIGN (char_type);
     484        62158 :   tree val_type = TREE_TYPE (val);
     485        62158 :   unsigned val_prec = TYPE_PRECISION (val_type);
     486        62158 :   signop val_sgn = TYPE_SIGN (val_type);
     487              : 
     488              :   /* Require VAL to be an integral constant whose type preserves the range
     489              :      and sign of CHAR_TYPE (either the same precision and sign, or a wider
     490              :      type that cannot reinterpret a negative signed char as large positive).  */
     491       124316 :   if (!INTEGRAL_TYPE_P (val_type)
     492        62158 :       || val_prec < prec
     493        62158 :       || (val_prec == prec ? val_sgn != sgn
     494              :                            : (sgn == SIGNED && val_sgn == UNSIGNED)))
     495              :     return NULL_TREE;
     496              : 
     497        62158 :   int len = TREE_STRING_LENGTH (str);
     498        62158 :   if (len <= 0)
     499              :     return NULL_TREE;
     500              : 
     501              :   /* First test VAL against the full representable [c_min, c_max] range of
     502              :      CHAR_TYPE so out-of-range or boundary comparisons fold without scanning
     503              :      STR.  */
     504        61998 :   wide_int wval = wi::to_wide (val);
     505        61998 :   wide_int c_min = wide_int::from (wi::min_value (prec, sgn), val_prec, sgn);
     506        61998 :   wide_int c_max = wide_int::from (wi::max_value (prec, sgn), val_prec, sgn);
     507              : 
     508        61998 :   if (wi::lt_p (wval, c_min, val_sgn))
     509              :     {
     510            0 :       if (code == EQ_EXPR || code == LT_EXPR || code == LE_EXPR)
     511            0 :         return constant_boolean_node (false, boolean_type_node);
     512            0 :       gcc_checking_assert (code == NE_EXPR || code == GT_EXPR
     513              :                            || code == GE_EXPR);
     514            0 :       return constant_boolean_node (true, boolean_type_node);
     515              :     }
     516        61998 :   if (wi::gt_p (wval, c_max, val_sgn))
     517              :     {
     518            0 :       if (code == EQ_EXPR || code == GT_EXPR || code == GE_EXPR)
     519            0 :         return constant_boolean_node (false, boolean_type_node);
     520            0 :       gcc_checking_assert (code == NE_EXPR || code == LT_EXPR
     521              :                            || code == LE_EXPR);
     522            0 :       return constant_boolean_node (true, boolean_type_node);
     523              :     }
     524        61998 :   if (wi::eq_p (wval, c_min))
     525              :     {
     526        18562 :       if (code == LT_EXPR)
     527            0 :         return constant_boolean_node (false, boolean_type_node);
     528        18562 :       if (code == GE_EXPR)
     529            0 :         return constant_boolean_node (true, boolean_type_node);
     530              :     }
     531        61998 :   if (wi::eq_p (wval, c_max))
     532              :     {
     533            0 :       if (code == GT_EXPR)
     534            0 :         return constant_boolean_node (false, boolean_type_node);
     535            0 :       if (code == LE_EXPR)
     536            0 :         return constant_boolean_node (true, boolean_type_node);
     537              :     }
     538              : 
     539              :   /* For strings longer than 256 bytes, build and memoize an sbitmap of all
     540              :      present byte values and answer queries by probing the target bit or
     541              :      lower/upper ordered coordinate ranges.  */
     542        61998 :   if (len > 256)
     543              :     {
     544          140 :       const_sbitmap bmp = get_string_char_set (str, prec);
     545          140 :       unsigned int full = 1U << prec;
     546              : 
     547          140 :       if (code == EQ_EXPR || code == NE_EXPR)
     548              :         {
     549           60 :           unsigned int raw_target
     550           60 :             = wide_int::from (wval, prec, UNSIGNED).to_uhwi ();
     551           60 :           bool has_target = bitmap_bit_p (bmp, raw_target);
     552           60 :           if (!has_target)
     553           24 :             return constant_boolean_node (code == NE_EXPR, boolean_type_node);
     554              : 
     555           36 :           bool has_other
     556              :             = ((raw_target > 0
     557           12 :                 && bitmap_any_bit_in_range_p (bmp, 0, raw_target - 1))
     558           36 :                || (raw_target + 1 < full
     559           24 :                    && bitmap_any_bit_in_range_p (bmp, raw_target + 1,
     560        61998 :                                                   full - 1)));
     561           16 :           if (!has_other)
     562           16 :             return constant_boolean_node (code == EQ_EXPR, boolean_type_node);
     563              :           return NULL_TREE;
     564              :         }
     565              : 
     566           80 :       gcc_checking_assert (code == LT_EXPR || code == LE_EXPR
     567              :                            || code == GT_EXPR || code == GE_EXPR);
     568              : 
     569              :       /* Partition the ordered coordinate domain [0, full - 1] into [0, split]
     570              :          (values <= wval for LE/GT, or < wval for LT/GE) and
     571              :          [split + 1, full - 1].  Boundary wval == c_min (with LT) and
     572              :          wval == c_max (with GT) already folded above, so split >= 0 and
     573              :          split + 1 <= full - 1 hold.  */
     574           80 :       unsigned int half = (sgn == SIGNED) ? (full >> 1) : 0;
     575           80 :       unsigned int u_val
     576           80 :         = wide_int::from (wval, prec, UNSIGNED).to_uhwi () ^ half;
     577           24 :       unsigned int split
     578           80 :         = (code == LE_EXPR || code == GT_EXPR) ? u_val : u_val - 1;
     579           80 :       bool any_lo = char_set_any_in_range_p (bmp, prec, sgn, 0, split);
     580           80 :       bool any_hi
     581           80 :         = char_set_any_in_range_p (bmp, prec, sgn, split + 1, full - 1);
     582              : 
     583           80 :       bool known_true = ((code == LT_EXPR || code == LE_EXPR) ? !any_hi
     584              :                                                               : !any_lo);
     585           80 :       bool known_false = ((code == LT_EXPR || code == LE_EXPR) ? !any_lo
     586              :                                                                : !any_hi);
     587           80 :       if (known_true)
     588           40 :         return constant_boolean_node (true, boolean_type_node);
     589           40 :       if (known_false)
     590           40 :         return constant_boolean_node (false, boolean_type_node);
     591              :       return NULL_TREE;
     592              :     }
     593              : 
     594              :   /* For short strings, check EQ/NE via memchr and inequality comparisons by
     595              :      computing the actual [wmin, wmax] byte bounds of STR.  */
     596        61858 :   const char *ptr = TREE_STRING_POINTER (str);
     597        61858 :   if (code == EQ_EXPR || code == NE_EXPR)
     598              :     {
     599        61406 :       unsigned target = wide_int::from (wval, prec, UNSIGNED).to_uhwi ();
     600        61406 :       bool has_target = memchr (ptr, target, len) != NULL;
     601        61406 :       if (!has_target)
     602        20108 :         return constant_boolean_node (code == NE_EXPR, boolean_type_node);
     603              : 
     604        42742 :       bool has_other = false;
     605        42742 :       for (int k = 0; k < len; k++)
     606        42652 :         if ((unsigned char) ptr[k] != target)
     607              :           {
     608              :             has_other = true;
     609              :             break;
     610              :           }
     611        41298 :       if (!has_other)
     612           90 :         return constant_boolean_node (code == EQ_EXPR, boolean_type_node);
     613              :       return NULL_TREE;
     614              :     }
     615              : 
     616          452 :   wide_int wmin = wi::uhwi ((unsigned char) ptr[0], prec);
     617          452 :   wide_int wmax = wmin;
     618         5948 :   for (int k = 1; k < len; k++)
     619              :     {
     620         5044 :       wide_int wk = wi::uhwi ((unsigned char) ptr[k], prec);
     621         5044 :       if (wi::lt_p (wk, wmin, sgn))
     622          548 :         wmin = wk;
     623         5044 :       if (wi::gt_p (wk, wmax, sgn))
     624          960 :         wmax = wk;
     625         5044 :     }
     626              : 
     627          452 :   wmin = wide_int::from (wmin, val_prec, sgn);
     628          452 :   wmax = wide_int::from (wmax, val_prec, sgn);
     629              : 
     630          452 :   bool known_true = false;
     631          452 :   bool known_false = false;
     632          452 :   switch (code)
     633              :     {
     634           52 :     case LT_EXPR:
     635           52 :       known_true = wi::lt_p (wmax, wval, val_sgn);
     636           52 :       known_false = wi::ge_p (wmin, wval, val_sgn);
     637           52 :       break;
     638          174 :     case LE_EXPR:
     639          174 :       known_true = wi::le_p (wmax, wval, val_sgn);
     640          174 :       known_false = wi::gt_p (wmin, wval, val_sgn);
     641          174 :       break;
     642          174 :     case GT_EXPR:
     643          174 :       known_true = wi::gt_p (wmin, wval, val_sgn);
     644          174 :       known_false = wi::le_p (wmax, wval, val_sgn);
     645          174 :       break;
     646           52 :     case GE_EXPR:
     647           52 :       known_true = wi::ge_p (wmin, wval, val_sgn);
     648           52 :       known_false = wi::lt_p (wmax, wval, val_sgn);
     649           52 :       break;
     650            0 :     default:
     651            0 :       gcc_unreachable ();
     652              :     }
     653              : 
     654          452 :   if (known_true)
     655           62 :     return constant_boolean_node (true, boolean_type_node);
     656          390 :   if (known_false)
     657           62 :     return constant_boolean_node (false, boolean_type_node);
     658              :   return NULL_TREE;
     659        62450 : }
     660              : 
     661              : /* Evaluate condition C (with c->unknown_offset set) against the argument
     662              :    values in AVALS.  If the caller argument resolves to a STRING_CST, try to
     663              :    fold the character comparison over all bytes of the string and return
     664              :    boolean_true_node or boolean_false_node when the result is independent of
     665              :    the offset, or NULL_TREE otherwise.  */
     666              : 
     667              : static tree
     668       242958 : evaluate_unknown_offset_condition (struct condition *c,
     669              :                                    ipa_auto_call_arg_values *avals)
     670              : {
     671       242958 :   gcc_checking_assert (c->agg_contents && c->unknown_offset);
     672              : 
     673              :   /* TODO: Support conversions in c->param_ops.  */
     674       242958 :   if (!vec_safe_is_empty (c->param_ops))
     675              :     return NULL_TREE;
     676              : 
     677       178865 :   if (!c->by_ref || !c->val || TREE_CODE (c->val) != INTEGER_CST)
     678              :     return NULL_TREE;
     679              : 
     680       178865 :   tree sval = avals->safe_sval_at (c->operand_num);
     681       178865 :   if (!sval || TREE_CODE (sval) != ADDR_EXPR)
     682              :     return NULL_TREE;
     683              : 
     684        66479 :   poly_int64 byte_off;
     685        66479 :   tree base = get_addr_base_and_unit_offset (TREE_OPERAND (sval, 0),
     686              :                                              &byte_off);
     687              :   /* TODO: Support general constructors of readonly variables.  */
     688        66479 :   if (!base || TREE_CODE (base) != STRING_CST)
     689              :     return NULL_TREE;
     690              : 
     691        62158 :   return fold_string_char_compare (base, c->code, c->val, c->type);
     692              : }
     693              : 
     694              : static void
     695     22962559 : evaluate_conditions_for_known_args (struct cgraph_node *node,
     696              :                                     bool inline_p,
     697              :                                     ipa_auto_call_arg_values *avals,
     698              :                                     clause_t *ret_clause,
     699              :                                     clause_t *ret_nonspec_clause,
     700              :                                     ipa_call_summary *es)
     701              : {
     702     22962559 :   clause_t clause = inline_p ? 0 : 1 << ipa_predicate::not_inlined_condition;
     703     22962559 :   clause_t nonspec_clause = 1 << ipa_predicate::not_inlined_condition;
     704     22962559 :   class ipa_fn_summary *info = ipa_fn_summaries->get (node);
     705     22962559 :   int i;
     706     22962559 :   struct condition *c;
     707              : 
     708    106689745 :   for (i = 0; vec_safe_iterate (info->conds, i, &c); i++)
     709              :     {
     710     83727186 :       tree val = NULL;
     711     83727186 :       tree res;
     712     83727186 :       int j;
     713     83727186 :       struct expr_eval_op *op;
     714              : 
     715     83727186 :       if (c->code == ipa_predicate::not_sra_candidate)
     716              :         {
     717     16633747 :           if (!inline_p
     718     16633747 :               || !es
     719     16208455 :               || (int)es->param.length () <= c->operand_num
     720     24737963 :               || !es->param[c->operand_num].points_to_possible_sra_candidate)
     721     12455317 :             clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     722     16633747 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     723     83727186 :           continue;
     724              :         }
     725              : 
     726     67093439 :       if (c->agg_contents)
     727              :         {
     728     42578609 :           if (c->code == ipa_predicate::changed
     729     27000136 :               && !c->by_ref
     730      2885908 :               && !c->unknown_offset
     731     45461689 :               && (avals->safe_sval_at(c->operand_num) == error_mark_node))
     732         2828 :             continue;
     733              : 
     734     42572953 :           if (c->unknown_offset)
     735              :             {
     736       242958 :               res = evaluate_unknown_offset_condition (c, avals);
     737       242958 :               if (res && integer_zerop (res))
     738         8665 :                 continue;
     739       234293 :               if (res && integer_onep (res))
     740              :                 {
     741        11777 :                   clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     742        11777 :                   nonspec_clause
     743        11777 :                     |= 1 << (i + ipa_predicate::first_dynamic_condition);
     744        11777 :                   continue;
     745              :                 }
     746              :             }
     747              :           else
     748              :             {
     749     42329995 :               if (tree sval = avals->safe_sval_at (c->operand_num))
     750     19244052 :                 val = ipa_find_agg_cst_from_init (sval, c->offset, c->by_ref,
     751              :                                                   c->type);
     752              :               /* ipa_argagg_value_list is indexed by byte offsets, so a
     753              :                  condition which does not start at a byte boundary (a bit-field)
     754              :                  cannot be looked up in it; the containing byte would be
     755              :                  reinterpreted as the whole field below.  */
     756     42329995 :               if (!val && (c->offset % BITS_PER_UNIT) == 0)
     757              :                 {
     758     41820055 :                   ipa_argagg_value_list avs (avals);
     759     41820055 :                   val = avs.get_value (c->operand_num, c->offset / BITS_PER_UNIT,
     760     41820055 :                                        c->by_ref, c->maybe_modified);
     761              :                 }
     762              :             }
     763              :         }
     764              :       else
     765              :         {
     766     24517658 :           val = avals->safe_sval_at (c->operand_num);
     767     24517658 :           if (val && val == error_mark_node
     768      2185864 :               && c->code != ipa_predicate::changed)
     769              :             val = NULL_TREE;
     770              :         }
     771              : 
     772     53070362 :       if (!val
     773     53250777 :           && (c->code == ipa_predicate::changed
     774              :               || c->code == ipa_predicate::is_not_constant))
     775              :         {
     776     33481530 :           clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     777     33481530 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     778     33481530 :           continue;
     779              :         }
     780     33588639 :       if (c->code == ipa_predicate::changed)
     781              :         {
     782      7998075 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     783      7998075 :           continue;
     784              :         }
     785              : 
     786     25590564 :       if (c->code == ipa_predicate::is_not_constant)
     787              :         {
     788         8779 :           nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     789         8779 :           continue;
     790              :         }
     791              : 
     792     25581785 :       if (val
     793     25581785 :           && (c->type == TREE_TYPE (val)
     794      1064827 :               || (TYPE_SIZE (c->type) == TYPE_SIZE (TREE_TYPE (val))
     795              :                   /* Avoid precision mismatch like with bit-fields where the
     796              :                      VIEW_CONVERT_EXPR does not truncate excess bits
     797              :                      appropriately.  */
     798      1004842 :                   && ((!INTEGRAL_TYPE_P (c->type)
     799       239434 :                        || type_has_mode_precision_p (c->type))
     800      1003012 :                       && (!INTEGRAL_TYPE_P (TREE_TYPE (val))
     801       237784 :                           || type_has_mode_precision_p (TREE_TYPE (val)))))))
     802              :         {
     803      5750709 :           if (c->type != TREE_TYPE (val))
     804      1002998 :             val = fold_unary (VIEW_CONVERT_EXPR, c->type, val);
     805      6285287 :           for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
     806              :             {
     807       535045 :               if (!val)
     808              :                 break;
     809       534578 :               if (!op->val[0])
     810       234228 :                 val = fold_unary (op->code, op->type, val);
     811       300350 :               else if (!op->val[1])
     812       600688 :                 val = fold_binary (op->code, op->type,
     813              :                                    op->index ? op->val[0] : val,
     814              :                                    op->index ? val : op->val[0]);
     815            6 :               else if (op->index == 0)
     816            6 :                 val = fold_ternary (op->code, op->type,
     817              :                                     val, op->val[0], op->val[1]);
     818            0 :               else if (op->index == 1)
     819            0 :                 val = fold_ternary (op->code, op->type,
     820              :                                     op->val[0], val, op->val[1]);
     821            0 :               else if (op->index == 2)
     822            0 :                 val = fold_ternary (op->code, op->type,
     823              :                                     op->val[0], op->val[1], val);
     824              :               else
     825              :                 val = NULL_TREE;
     826              :             }
     827              : 
     828      5750709 :           res = val
     829      5750709 :             ? fold_binary_to_constant (c->code, boolean_type_node, val, c->val)
     830              :             : NULL;
     831              : 
     832      5750222 :           if (res && integer_zerop (res))
     833      2909067 :             continue;
     834      2841642 :           if (res && integer_onep (res))
     835              :             {
     836      2820127 :               clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     837      2820127 :               nonspec_clause
     838      2820127 :                 |= 1 << (i + ipa_predicate::first_dynamic_condition);
     839      2820127 :               continue;
     840              :             }
     841              :         }
     842     19852591 :       if (c->operand_num < (int) avals->m_known_value_ranges.length ()
     843     12347989 :           && !c->agg_contents
     844     22052228 :           && (!val || TREE_CODE (val) != INTEGER_CST))
     845              :         {
     846      2198902 :           value_range vr (avals->m_known_value_ranges[c->operand_num]);
     847      2198902 :           if (!vr.undefined_p ()
     848      1542967 :               && !vr.varying_p ()
     849      3741869 :               && (TYPE_SIZE (c->type) == TYPE_SIZE (vr.type ())))
     850              :             {
     851      1542668 :               if (!useless_type_conversion_p (c->type, vr.type ()))
     852          552 :                 range_cast (vr, c->type);
     853              : 
     854      1964692 :               for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
     855              :                 {
     856       523648 :                   if (vr.varying_p () || vr.undefined_p ())
     857              :                     break;
     858              : 
     859       422024 :                   value_range res (op->type);
     860       422024 :                   if (!op->val[0])
     861              :                     {
     862       149671 :                       value_range varying (op->type);
     863       149671 :                       varying.set_varying (op->type);
     864       149671 :                       range_op_handler handler (op->code);
     865       149671 :                       if (!handler
     866       149671 :                           || !res.supports_type_p (op->type)
     867       299342 :                           || !handler.fold_range (res, op->type, vr, varying))
     868            0 :                         res.set_varying (op->type);
     869       149671 :                     }
     870       272353 :                   else if (!op->val[1])
     871              :                     {
     872       272181 :                       value_range op0 (TREE_TYPE (op->val[0]));
     873       272181 :                       range_op_handler handler (op->code);
     874              : 
     875       272181 :                       ipa_get_range_from_ip_invariant (op0, op->val[0], node);
     876              : 
     877       272181 :                       if (!handler
     878       272181 :                           || !res.supports_type_p (op->type)
     879       544362 :                           || !handler.fold_range (res, op->type,
     880       272181 :                                                   op->index ? op0 : vr,
     881       542594 :                                                   op->index ? vr : op0))
     882            0 :                         res.set_varying (op->type);
     883       272181 :                     }
     884              :                   else
     885          172 :                     res.set_varying (op->type);
     886       422024 :                   vr = res;
     887       422024 :                 }
     888      1542668 :               if (!vr.varying_p () && !vr.undefined_p ())
     889              :                 {
     890      1431880 :                   int_range<2> res;
     891      1431880 :                   value_range val_vr (TREE_TYPE (c->val));
     892      1431880 :                   range_op_handler handler (c->code);
     893              : 
     894      1431880 :                   ipa_get_range_from_ip_invariant (val_vr, c->val, node);
     895              : 
     896      1431880 :                   if (!handler
     897      1431880 :                       || !val_vr.supports_type_p (TREE_TYPE (c->val))
     898      2863760 :                       || !handler.fold_range (res, boolean_type_node, vr, val_vr))
     899            0 :                     res.set_varying (boolean_type_node);
     900              : 
     901      1431880 :                   if (res.zero_p ())
     902       242873 :                     continue;
     903      1431880 :                 }
     904              :             }
     905      2198902 :         }
     906              : 
     907     19609718 :       clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     908     19609718 :       nonspec_clause |= 1 << (i + ipa_predicate::first_dynamic_condition);
     909              :     }
     910     22962559 :   *ret_clause = clause;
     911     22962559 :   if (ret_nonspec_clause)
     912     19884287 :     *ret_nonspec_clause = nonspec_clause;
     913     22962559 : }
     914              : 
     915              : /* Return true if VRP will be executed on the function.
     916              :    We do not want to anticipate optimizations that will not happen.
     917              : 
     918              :    FIXME: This can be confused with -fdisable and debug counters and thus
     919              :    it should not be used for correctness (only to make heuristics work).
     920              :    This means that inliner should do its own optimizations of expressions
     921              :    that it predicts to be constant so wrong code can not be triggered by
     922              :    builtin_constant_p.  */
     923              : 
     924              : static bool
     925     12533066 : vrp_will_run_p (struct cgraph_node *node)
     926              : {
     927     12533066 :   return (opt_for_fn (node->decl, optimize)
     928     12533066 :           && !opt_for_fn (node->decl, optimize_debug)
     929     25065019 :           && opt_for_fn (node->decl, flag_tree_vrp));
     930              : }
     931              : 
     932              : /* Similarly about FRE.  */
     933              : 
     934              : static bool
     935     14745878 : fre_will_run_p (struct cgraph_node *node)
     936              : {
     937     14745878 :   return (opt_for_fn (node->decl, optimize)
     938     14745878 :           && !opt_for_fn (node->decl, optimize_debug)
     939     29489763 :           && opt_for_fn (node->decl, flag_tree_fre));
     940              : }
     941              : 
     942              : /* Work out what conditions might be true at invocation of E.
     943              :    Compute costs for inlined edge if INLINE_P is true.
     944              : 
     945              :    Return in CLAUSE_PTR the evaluated conditions and in NONSPEC_CLAUSE_PTR
     946              :    (if non-NULL) conditions evaluated for nonspecialized clone called
     947              :    in a given context.
     948              : 
     949              :    Vectors in AVALS will be populated with useful known information about
     950              :    argument values - information not known to have any uses will be omitted -
     951              :    except for m_known_contexts which will only be calculated if
     952              :    COMPUTE_CONTEXTS is true.  */
     953              : 
     954              : void
     955     22715348 : evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
     956              :                               clause_t *clause_ptr,
     957              :                               clause_t *nonspec_clause_ptr,
     958              :                               ipa_auto_call_arg_values *avals,
     959              :                               bool compute_contexts)
     960              : {
     961     22715348 :   struct cgraph_node *callee = e->callee->ultimate_alias_target ();
     962     22715348 :   class ipa_fn_summary *info = ipa_fn_summaries->get (callee);
     963     22715348 :   class ipa_edge_args *args;
     964     22715348 :   class ipa_call_summary *es = NULL;
     965              : 
     966     22715348 :   if (clause_ptr)
     967     22715348 :     *clause_ptr = inline_p ? 0 : 1 << ipa_predicate::not_inlined_condition;
     968              : 
     969     22715348 :   if (ipa_node_params_sum
     970     10258687 :       && !e->call_stmt_cannot_inline_p
     971     10258687 :       && (info->conds || compute_contexts)
     972     32974035 :       && (args = ipa_edge_args_sum->get (e)) != NULL)
     973              :     {
     974     10203432 :       struct cgraph_node *caller;
     975     10203432 :       class ipa_node_params *caller_parms_info, *callee_pi = NULL;
     976     10203432 :       int i, count = ipa_get_cs_argument_count (args);
     977     10203432 :       es = ipa_call_summaries->get (e);
     978              : 
     979     10203432 :       if (count)
     980              :         {
     981      9457200 :           if (e->caller->inlined_to)
     982              :             caller = e->caller->inlined_to;
     983              :           else
     984      7516812 :             caller = e->caller;
     985      9457200 :           caller_parms_info = ipa_node_params_sum->get (caller);
     986      9457200 :           callee_pi = ipa_node_params_sum->get (callee);
     987              : 
     988              :           /* Watch for thunks.  */
     989      9457200 :           if (callee_pi)
     990              :             /* Watch for variadic functions.  */
     991      9456826 :             count = MIN (count, ipa_get_param_count (callee_pi));
     992              :         }
     993              : 
     994      9456826 :       if (callee_pi)
     995     31225191 :         for (i = 0; i < count; i++)
     996              :           {
     997     21768365 :             struct ipa_jump_func *jf = ipa_get_ith_jump_func (args, i);
     998              : 
     999     21768365 :             if (ipa_is_param_used_by_indirect_call (callee_pi, i)
    1000     21768365 :                 || ipa_is_param_used_by_ipa_predicates (callee_pi, i))
    1001              :               {
    1002              :                 /* Determine if we know constant value of the parameter.  */
    1003     14745878 :                 tree type = ipa_get_type (callee_pi, i);
    1004     14745878 :                 tree cst = ipa_value_from_jfunc (caller_parms_info, jf, type);
    1005              : 
    1006     11827707 :                 if (!cst && e->call_stmt
    1007     26518027 :                     && i < (int)gimple_call_num_args (e->call_stmt))
    1008              :                   {
    1009     11772149 :                     cst = gimple_call_arg (e->call_stmt, i);
    1010     11772149 :                     if (!is_gimple_min_invariant (cst))
    1011              :                       cst = NULL;
    1012              :                   }
    1013      3168377 :                 if (cst)
    1014              :                   {
    1015      3112819 :                     gcc_checking_assert (TREE_CODE (cst) != TREE_BINFO);
    1016      3112819 :                     if (!avals->m_known_vals.length ())
    1017      1782991 :                       avals->m_known_vals.safe_grow_cleared (count, true);
    1018      3112819 :                     avals->m_known_vals[i] = cst;
    1019              :                   }
    1020     11633059 :                 else if (inline_p && !es->param[i].change_prob)
    1021              :                   {
    1022      4231781 :                     if (!avals->m_known_vals.length ())
    1023      3428696 :                       avals->m_known_vals.safe_grow_cleared (count, true);
    1024      4231781 :                     avals->m_known_vals[i] = error_mark_node;
    1025              :                   }
    1026              : 
    1027              :                 /* If we failed to get simple constant, try value range.  */
    1028      3112819 :                 if ((!cst || TREE_CODE (cst) != INTEGER_CST)
    1029     12533066 :                     && vrp_will_run_p (caller)
    1030     27089684 :                     && ipa_is_param_used_by_ipa_predicates (callee_pi, i))
    1031              :                   {
    1032     12301972 :                     value_range vr (type);
    1033              : 
    1034     12301972 :                     ipa_value_range_from_jfunc (vr, caller_parms_info, e, jf, type);
    1035     12301972 :                     if (!vr.undefined_p () && !vr.varying_p ())
    1036              :                       {
    1037      8719953 :                         if (!avals->m_known_value_ranges.length ())
    1038              :                           {
    1039      6320899 :                             avals->m_known_value_ranges.safe_grow_cleared (count,
    1040              :                                                                            true);
    1041     26549468 :                             for (int i = 0; i < count; ++i)
    1042     13907670 :                               avals->m_known_value_ranges[i].set_range_class
    1043     13907670 :                                 (void_type_node);
    1044              :                           }
    1045      8719953 :                         avals->m_known_value_ranges[i] = vr;
    1046              :                       }
    1047     12301972 :                   }
    1048              : 
    1049              :                 /* Determine known aggregate values.  */
    1050     14745878 :                 if (fre_will_run_p (caller))
    1051     14743481 :                   ipa_push_agg_values_from_jfunc (caller_parms_info,
    1052              :                                                   caller, &jf->agg, i,
    1053              :                                                   &avals->m_known_aggs);
    1054              :               }
    1055              : 
    1056              :             /* For calls used in polymorphic calls we further determine
    1057              :                polymorphic call context.  */
    1058     21768365 :             if (compute_contexts
    1059     21768365 :                 && ipa_is_param_used_by_polymorphic_call (callee_pi, i))
    1060              :               {
    1061       185525 :                 ipa_polymorphic_call_context
    1062       185525 :                    ctx = ipa_context_from_jfunc (caller_parms_info, e, i, jf);
    1063       371050 :                 if (!ctx.useless_p ())
    1064              :                   {
    1065       183561 :                     if (!avals->m_known_contexts.length ())
    1066       183375 :                       avals->m_known_contexts.safe_grow_cleared (count, true);
    1067       183561 :                     avals->m_known_contexts[i]
    1068       367122 :                       = ipa_context_from_jfunc (caller_parms_info, e, i, jf);
    1069              :                   }
    1070              :                }
    1071              :           }
    1072              :         else
    1073       746606 :           gcc_assert (!count || callee->thunk);
    1074              :     }
    1075     12511916 :   else if (e->call_stmt && !e->call_stmt_cannot_inline_p && info->conds)
    1076              :     {
    1077      9848708 :       int i, count = (int)gimple_call_num_args (e->call_stmt);
    1078              : 
    1079     28043918 :       for (i = 0; i < count; i++)
    1080              :         {
    1081     18195210 :           tree cst = gimple_call_arg (e->call_stmt, i);
    1082     18195210 :           if (!is_gimple_min_invariant (cst))
    1083              :             cst = NULL;
    1084      6532493 :           if (cst)
    1085              :             {
    1086      6532493 :               if (!avals->m_known_vals.length ())
    1087      4525357 :                 avals->m_known_vals.safe_grow_cleared (count, true);
    1088      6532493 :               avals->m_known_vals[i] = cst;
    1089              :             }
    1090              :         }
    1091              :     }
    1092              : 
    1093     22715348 :   evaluate_conditions_for_known_args (callee, inline_p, avals, clause_ptr,
    1094              :                                       nonspec_clause_ptr, es);
    1095     22715348 : }
    1096              : 
    1097              : 
    1098              : /* Allocate the function summary. */
    1099              : 
    1100              : static void
    1101       481460 : ipa_fn_summary_alloc (void)
    1102              : {
    1103       481460 :   gcc_checking_assert (!ipa_fn_summaries);
    1104       481460 :   ipa_size_summaries = new ipa_size_summary_t (symtab);
    1105       481460 :   ipa_fn_summaries = ipa_fn_summary_t::create_ggc (symtab);
    1106       481460 :   ipa_call_summaries = new ipa_call_summary_t (symtab);
    1107       481460 : }
    1108              : 
    1109     28200066 : ipa_call_summary::~ipa_call_summary ()
    1110              : {
    1111     28200066 :   if (predicate)
    1112      3848513 :     edge_predicate_pool.remove (predicate);
    1113              : 
    1114     28200066 :   param.release ();
    1115     28200066 : }
    1116              : 
    1117     10392973 : ipa_fn_summary::~ipa_fn_summary ()
    1118              : {
    1119     10392973 :   unsigned len = vec_safe_length (loop_iterations);
    1120     10517503 :   for (unsigned i = 0; i < len; i++)
    1121       124530 :     edge_predicate_pool.remove ((*loop_iterations)[i].predicate);
    1122     10392973 :   len = vec_safe_length (loop_strides);
    1123     10431992 :   for (unsigned i = 0; i < len; i++)
    1124        39019 :     edge_predicate_pool.remove ((*loop_strides)[i].predicate);
    1125     10392973 :   vec_free (conds);
    1126     10392973 :   call_size_time_table.release ();
    1127     10392973 :   vec_free (loop_iterations);
    1128     10392973 :   vec_free (loop_strides);
    1129     10392973 :   builtin_constant_p_parms.release ();
    1130     10392973 : }
    1131              : 
    1132              : void
    1133      7479821 : ipa_fn_summary_t::remove_callees (cgraph_node *node)
    1134              : {
    1135      7479821 :   cgraph_edge *e;
    1136     30677885 :   for (e = node->callees; e; e = e->next_callee)
    1137     23198064 :     ipa_call_summaries->remove (e);
    1138      7969796 :   for (e = node->indirect_calls; e; e = e->next_callee)
    1139       489975 :     ipa_call_summaries->remove (e);
    1140      7479821 : }
    1141              : 
    1142              : /* Duplicate predicates in loop hint vector, allocating memory for them and
    1143              :    remove and deallocate any uninteresting (true or false) ones.  Return the
    1144              :    result.  */
    1145              : 
    1146              : static vec<ipa_freqcounting_predicate, va_gc> *
    1147        30324 : remap_freqcounting_preds_after_dup (vec<ipa_freqcounting_predicate, va_gc> *v,
    1148              :                                     clause_t possible_truths)
    1149              : {
    1150        30324 :   if (vec_safe_length (v) == 0)
    1151              :     return NULL;
    1152              : 
    1153         5128 :   vec<ipa_freqcounting_predicate, va_gc> *res = v->copy ();
    1154         5128 :   int len = res->length();
    1155        12294 :   for (int i = len - 1; i >= 0; i--)
    1156              :     {
    1157         7166 :       ipa_predicate new_predicate
    1158         7166 :         = (*res)[i].predicate->remap_after_duplication (possible_truths);
    1159              :       /* We do not want to free previous predicate; it is used by node
    1160              :          origin.  */
    1161         7166 :       (*res)[i].predicate = NULL;
    1162         7166 :       set_hint_predicate (&(*res)[i].predicate, new_predicate);
    1163              : 
    1164         7166 :       if (!(*res)[i].predicate)
    1165         4111 :         res->unordered_remove (i);
    1166              :     }
    1167              : 
    1168              :   return res;
    1169              : }
    1170              : 
    1171              : 
    1172              : /* Hook that is called by cgraph.cc when a node is duplicated.  */
    1173              : void
    1174      2822696 : ipa_fn_summary_t::duplicate (cgraph_node *src,
    1175              :                              cgraph_node *dst,
    1176              :                              ipa_fn_summary *src_info,
    1177              :                              ipa_fn_summary *info)
    1178              : {
    1179      2822696 :   new (info) ipa_fn_summary (*src_info);
    1180              :   /* TODO: as an optimization, we may avoid copying conditions
    1181              :      that are known to be false or true.  */
    1182      2822696 :   info->conds = vec_safe_copy (info->conds);
    1183              : 
    1184      2822696 :   clone_info *cinfo = clone_info::get (dst);
    1185              :   /* When there are any replacements in the function body, see if we can figure
    1186              :      out that something was optimized out.  */
    1187      2822696 :   if (ipa_node_params_sum && cinfo && cinfo->tree_map)
    1188              :     {
    1189              :       /* Use SRC parm info since it may not be copied yet.  */
    1190        15162 :       ipa_node_params *parms_info = ipa_node_params_sum->get (src);
    1191        15162 :       ipa_auto_call_arg_values avals;
    1192        15162 :       int count = ipa_get_param_count (parms_info);
    1193        15162 :       int i, j;
    1194        15162 :       clause_t possible_truths;
    1195        15162 :       ipa_predicate true_pred = true;
    1196        15162 :       size_time_entry *e;
    1197        15162 :       int optimized_out_size = 0;
    1198        15162 :       bool inlined_to_p = false;
    1199        15162 :       struct cgraph_edge *edge, *next;
    1200              : 
    1201        15162 :       info->size_time_table.release ();
    1202        15162 :       avals.m_known_vals.safe_grow_cleared (count, true);
    1203        76147 :       for (i = 0; i < count; i++)
    1204              :         {
    1205              :           struct ipa_replace_map *r;
    1206              : 
    1207       149649 :           for (j = 0; vec_safe_iterate (cinfo->tree_map, j, &r); j++)
    1208              :             {
    1209        84234 :               if (r->parm_num == i)
    1210              :                 {
    1211        26231 :                   avals.m_known_vals[i] = r->new_tree;
    1212        26231 :                   break;
    1213              :                 }
    1214              :             }
    1215              :         }
    1216        15162 :       evaluate_conditions_for_known_args (dst, false,
    1217              :                                           &avals,
    1218              :                                           &possible_truths,
    1219              :                                           /* We are going to specialize,
    1220              :                                              so ignore nonspec truths.  */
    1221              :                                           NULL,
    1222              :                                           NULL);
    1223              : 
    1224        15162 :       info->account_size_time (0, 0, true_pred, true_pred);
    1225              : 
    1226              :       /* Remap size_time vectors.
    1227              :          Simplify the predicate by pruning out alternatives that are known
    1228              :          to be false.
    1229              :          TODO: as on optimization, we can also eliminate conditions known
    1230              :          to be true.  */
    1231       114932 :       for (i = 0; src_info->size_time_table.iterate (i, &e); i++)
    1232              :         {
    1233        99770 :           ipa_predicate new_exec_pred;
    1234        99770 :           ipa_predicate new_nonconst_pred;
    1235        99770 :           new_exec_pred = e->exec_predicate.remap_after_duplication
    1236        99770 :                                  (possible_truths);
    1237        99770 :           new_nonconst_pred = e->nonconst_predicate.remap_after_duplication
    1238        99770 :                                  (possible_truths);
    1239        99770 :           if (new_exec_pred == false || new_nonconst_pred == false)
    1240        20352 :             optimized_out_size += e->size;
    1241              :           else
    1242        79418 :             info->account_size_time (e->size, e->time, new_exec_pred,
    1243              :                                      new_nonconst_pred);
    1244              :         }
    1245              : 
    1246              :       /* Remap edge predicates with the same simplification as above.
    1247              :          Also copy constantness arrays.   */
    1248       187559 :       for (edge = dst->callees; edge; edge = next)
    1249              :         {
    1250       172397 :           ipa_predicate new_predicate;
    1251       172397 :           class ipa_call_summary *es = ipa_call_summaries->get (edge);
    1252       172397 :           next = edge->next_callee;
    1253              : 
    1254       172397 :           if (!edge->inline_failed)
    1255            0 :             inlined_to_p = true;
    1256       172397 :           if (!es->predicate)
    1257       157631 :             continue;
    1258        14766 :           new_predicate = es->predicate->remap_after_duplication
    1259        14766 :             (possible_truths);
    1260        14766 :           if (new_predicate == false && *es->predicate != false)
    1261         3679 :             optimized_out_size += es->call_stmt_size * ipa_fn_summary::size_scale;
    1262        14766 :           edge_set_predicate (edge, &new_predicate);
    1263              :         }
    1264              : 
    1265              :       /* Remap indirect edge predicates with the same simplification as above.
    1266              :          Also copy constantness arrays.   */
    1267        16123 :       for (edge = dst->indirect_calls; edge; edge = next)
    1268              :         {
    1269          961 :           ipa_predicate new_predicate;
    1270          961 :           class ipa_call_summary *es = ipa_call_summaries->get (edge);
    1271          961 :           next = edge->next_callee;
    1272              : 
    1273          961 :           gcc_checking_assert (edge->inline_failed);
    1274          961 :           if (!es->predicate)
    1275          783 :             continue;
    1276          178 :           new_predicate = es->predicate->remap_after_duplication
    1277          178 :                                  (possible_truths);
    1278          178 :           if (new_predicate == false && *es->predicate != false)
    1279           25 :             optimized_out_size
    1280           25 :                  += es->call_stmt_size * ipa_fn_summary::size_scale;
    1281          178 :           edge_set_predicate (edge, &new_predicate);
    1282              :         }
    1283        15162 :       info->loop_iterations
    1284        15162 :         = remap_freqcounting_preds_after_dup (info->loop_iterations,
    1285              :                                               possible_truths);
    1286        15162 :       info->loop_strides
    1287        15162 :         = remap_freqcounting_preds_after_dup (info->loop_strides,
    1288              :                                               possible_truths);
    1289        15162 :       if (info->builtin_constant_p_parms.length())
    1290              :         {
    1291           23 :           vec <int, va_heap, vl_ptr> parms = info->builtin_constant_p_parms;
    1292           23 :           int ip;
    1293           23 :           info->builtin_constant_p_parms = vNULL;
    1294           46 :           for (i = 0; parms.iterate (i, &ip); i++)
    1295           23 :             if (!avals.m_known_vals[ip])
    1296            8 :               info->builtin_constant_p_parms.safe_push (ip);
    1297              :         }
    1298              : 
    1299              :       /* If inliner or someone after inliner will ever start producing
    1300              :          non-trivial clones, we will get trouble with lack of information
    1301              :          about updating self sizes, because size vectors already contains
    1302              :          sizes of the callees.  */
    1303        15162 :       gcc_assert (!inlined_to_p || !optimized_out_size);
    1304        15162 :     }
    1305              :   else
    1306              :     {
    1307      2807534 :       info->size_time_table = src_info->size_time_table.copy ();
    1308      2807534 :       info->loop_iterations = vec_safe_copy (src_info->loop_iterations);
    1309      2807534 :       info->loop_strides = vec_safe_copy (info->loop_strides);
    1310              : 
    1311      2807534 :       info->builtin_constant_p_parms
    1312      2807534 :              = info->builtin_constant_p_parms.copy ();
    1313              : 
    1314      2807534 :       ipa_freqcounting_predicate *f;
    1315      5666067 :       for (int i = 0; vec_safe_iterate (info->loop_iterations, i, &f); i++)
    1316              :         {
    1317        50999 :           ipa_predicate p = *f->predicate;
    1318        50999 :           f->predicate = NULL;
    1319        50999 :           set_hint_predicate (&f->predicate, p);
    1320              :         }
    1321      2831899 :       for (int i = 0; vec_safe_iterate (info->loop_strides, i, &f); i++)
    1322              :         {
    1323        24365 :           ipa_predicate p = *f->predicate;
    1324        24365 :           f->predicate = NULL;
    1325        24365 :           set_hint_predicate (&f->predicate, p);
    1326              :         }
    1327              :     }
    1328      2822696 :   if (!dst->inlined_to)
    1329       145481 :     ipa_update_overall_fn_summary (dst);
    1330      2822696 : }
    1331              : 
    1332              : 
    1333              : /* Hook that is called by cgraph.cc when a node is duplicated.  */
    1334              : 
    1335              : void
    1336      4160646 : ipa_call_summary_t::duplicate (struct cgraph_edge *src,
    1337              :                                struct cgraph_edge *dst,
    1338              :                                class ipa_call_summary *srcinfo,
    1339              :                                class ipa_call_summary *info)
    1340              : {
    1341      4160646 :   new (info) ipa_call_summary (*srcinfo);
    1342      4160646 :   info->predicate = NULL;
    1343      4160646 :   edge_set_predicate (dst, srcinfo->predicate);
    1344      4160646 :   info->param = srcinfo->param.copy ();
    1345      4160646 :   if (!dst->indirect_unknown_callee && src->indirect_unknown_callee
    1346              :       /* Don't subtract the size when dealing with callback pairs, since the
    1347              :          edge has no real size.  */
    1348        36539 :       && !src->has_callback && !dst->callback)
    1349              :     {
    1350        36539 :       info->call_stmt_size -= (eni_size_weights.indirect_call_cost
    1351        36539 :                                - eni_size_weights.call_cost);
    1352        36539 :       info->call_stmt_time -= (eni_time_weights.indirect_call_cost
    1353        36539 :                                - eni_time_weights.call_cost);
    1354              :     }
    1355      4160646 : }
    1356              : 
    1357              : /* Dump edge summaries associated to NODE and recursively to all clones.
    1358              :    Indent by INDENT.  */
    1359              : 
    1360              : static void
    1361         2251 : dump_ipa_call_summary (FILE *f, int indent, struct cgraph_node *node,
    1362              :                        class ipa_fn_summary *info)
    1363              : {
    1364         2251 :   struct cgraph_edge *edge;
    1365        11478 :   for (edge = node->callees; edge; edge = edge->next_callee)
    1366              :     {
    1367         9227 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    1368         9227 :       struct cgraph_node *callee = edge->callee->ultimate_alias_target ();
    1369         9227 :       int i;
    1370              : 
    1371        18454 :       fprintf (f,
    1372              :                "%*s%s %s\n%*s  freq:%4.2f",
    1373              :                indent, "", callee->dump_name (),
    1374         9227 :                !edge->inline_failed
    1375         8608 :                ? "inlined" : cgraph_inline_failed_string (edge-> inline_failed),
    1376         9227 :                indent, "", edge->sreal_frequency ().to_double ());
    1377              : 
    1378         9227 :       if (cross_module_call_p (edge))
    1379           20 :         fprintf (f, " cross module");
    1380              : 
    1381         9227 :       if (es)
    1382         8608 :         fprintf (f, " loop depth:%2i size:%2i time: %2i",
    1383              :                  es->loop_depth, es->call_stmt_size, es->call_stmt_time);
    1384              : 
    1385         9227 :       ipa_fn_summary *s = ipa_fn_summaries->get (callee);
    1386         9227 :       ipa_size_summary *ss = ipa_size_summaries->get (callee);
    1387         9227 :       if (s != NULL)
    1388         1292 :         fprintf (f, " callee size:%2i stack:%2i",
    1389         1292 :                  (int) (ss->size / ipa_fn_summary::size_scale),
    1390         1292 :                  (int) s->estimated_stack_size);
    1391              : 
    1392         9227 :       if (es && es->predicate)
    1393              :         {
    1394         5485 :           fprintf (f, " predicate: ");
    1395         5485 :           es->predicate->dump (f, info->conds);
    1396              :         }
    1397              :       else
    1398         3742 :         fprintf (f, "\n");
    1399         9227 :       if (es && es->param.exists ())
    1400         7492 :         for (i = 0; i < (int) es->param.length (); i++)
    1401              :           {
    1402         2185 :             int prob = es->param[i].change_prob;
    1403              : 
    1404         2185 :             if (!prob)
    1405          978 :               fprintf (f, "%*s op%i is compile time invariant\n",
    1406              :                        indent + 2, "", i);
    1407         1207 :             else if (prob != REG_BR_PROB_BASE)
    1408           35 :               fprintf (f, "%*s op%i change %f%% of time\n", indent + 2, "", i,
    1409           35 :                        prob * 100.0 / REG_BR_PROB_BASE);
    1410         2185 :             if (es->param[i].points_to_local_or_readonly_memory)
    1411          591 :               fprintf (f, "%*s op%i points to local or readonly memory\n",
    1412              :                        indent + 2, "", i);
    1413         2185 :             if (es->param[i].points_to_possible_sra_candidate)
    1414          261 :               fprintf (f, "%*s op%i points to possible sra candidate\n",
    1415              :                        indent + 2, "", i);
    1416              :           }
    1417         9227 :       if (!edge->inline_failed)
    1418              :         {
    1419          619 :           ipa_size_summary *ss = ipa_size_summaries->get (callee);
    1420          619 :           fprintf (f, "%*sStack frame offset %i, callee self size %i\n",
    1421              :                    indent + 2, "",
    1422          619 :                    (int) ipa_get_stack_frame_offset (callee),
    1423          619 :                    (int) ss->estimated_self_stack_size);
    1424          619 :           dump_ipa_call_summary (f, indent + 2, callee, info);
    1425              :         }
    1426              :     }
    1427         2553 :   for (edge = node->indirect_calls; edge; edge = edge->next_callee)
    1428              :     {
    1429          302 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    1430          302 :       fprintf (f, "%*sindirect call loop depth:%2i freq:%4.2f size:%2i"
    1431              :                " time: %2i",
    1432              :                indent, "",
    1433              :                es->loop_depth,
    1434          302 :                edge->sreal_frequency ().to_double (), es->call_stmt_size,
    1435              :                es->call_stmt_time);
    1436          302 :       if (es->predicate)
    1437              :         {
    1438            6 :           fprintf (f, "predicate: ");
    1439            6 :           es->predicate->dump (f, info->conds);
    1440              :         }
    1441              :       else
    1442          296 :         fprintf (f, "\n");
    1443              :     }
    1444         2251 : }
    1445              : 
    1446              : 
    1447              : void
    1448         1846 : ipa_dump_fn_summary (FILE *f, struct cgraph_node *node)
    1449              : {
    1450         1846 :   if (node->definition)
    1451              :     {
    1452         1846 :       class ipa_fn_summary *s = ipa_fn_summaries->get (node);
    1453         1846 :       class ipa_size_summary *ss = ipa_size_summaries->get (node);
    1454         1846 :       if (s != NULL)
    1455              :         {
    1456         1632 :           size_time_entry *e;
    1457         1632 :           int i;
    1458         1632 :           fprintf (f, "IPA function summary for %s", node->dump_name ());
    1459         1632 :           if (DECL_DISREGARD_INLINE_LIMITS (node->decl))
    1460            0 :             fprintf (f, " always_inline");
    1461         1632 :           if (s->inlinable)
    1462         1370 :             fprintf (f, " inlinable");
    1463         1632 :           if (s->fp_expressions)
    1464           45 :             fprintf (f, " fp_expression");
    1465         1632 :           if (s->builtin_constant_p_parms.length ())
    1466              :             {
    1467            2 :               fprintf (f, " builtin_constant_p_parms");
    1468            4 :               for (unsigned int i = 0;
    1469            4 :                    i < s->builtin_constant_p_parms.length (); i++)
    1470            2 :                 fprintf (f, " %i", s->builtin_constant_p_parms[i]);
    1471              :             }
    1472         1632 :           fprintf (f, "\n  global time:     %f\n", s->time.to_double ());
    1473         1632 :           fprintf (f, "  self size:       %i\n", ss->self_size);
    1474         1632 :           fprintf (f, "  global size:     %i\n", ss->size);
    1475         1632 :           fprintf (f, "  min size:       %i\n", s->min_size);
    1476         1632 :           fprintf (f, "  self stack:      %i\n",
    1477         1632 :                    (int) ss->estimated_self_stack_size);
    1478         1632 :           fprintf (f, "  global stack:    %i\n", (int) s->estimated_stack_size);
    1479         1632 :           if (s->growth)
    1480          222 :             fprintf (f, "  estimated growth:%i\n", (int) s->growth);
    1481         1632 :           if (s->scc_no)
    1482            5 :             fprintf (f, "  In SCC:          %i\n", (int) s->scc_no);
    1483         7095 :           for (i = 0; s->size_time_table.iterate (i, &e); i++)
    1484              :             {
    1485         5463 :               fprintf (f, "    size:%f, time:%f",
    1486         5463 :                        (double) e->size / ipa_fn_summary::size_scale,
    1487              :                        e->time.to_double ());
    1488         5463 :               if (e->exec_predicate != true)
    1489              :                 {
    1490         3212 :                   fprintf (f, ",  executed if:");
    1491         3212 :                   e->exec_predicate.dump (f, s->conds, 0);
    1492              :                 }
    1493         5463 :               if (e->exec_predicate != e->nonconst_predicate)
    1494              :                 {
    1495         1735 :                   fprintf (f, ",  nonconst if:");
    1496         1735 :                   e->nonconst_predicate.dump (f, s->conds, 0);
    1497              :                 }
    1498         5463 :               fprintf (f, "\n");
    1499              :             }
    1500              :           ipa_freqcounting_predicate *fcp;
    1501              :           bool first_fcp = true;
    1502         1743 :           for (int i = 0; vec_safe_iterate (s->loop_iterations, i, &fcp); i++)
    1503              :             {
    1504          111 :               if (first_fcp)
    1505              :                 {
    1506           81 :                   fprintf (f, "  loop iterations:");
    1507           81 :                   first_fcp = false;
    1508              :                 }
    1509          111 :               fprintf (f, "  %3.2f for ", fcp->freq.to_double ());
    1510          111 :               fcp->predicate->dump (f, s->conds);
    1511              :             }
    1512              :           first_fcp = true;
    1513         1650 :           for (int i = 0; vec_safe_iterate (s->loop_strides, i, &fcp); i++)
    1514              :             {
    1515           18 :               if (first_fcp)
    1516              :                 {
    1517           10 :                   fprintf (f, "  loop strides:");
    1518           10 :                   first_fcp = false;
    1519              :                 }
    1520           18 :               fprintf (f, "  %3.2f for :", fcp->freq.to_double ());
    1521           18 :               fcp->predicate->dump (f, s->conds);
    1522              :             }
    1523         1632 :           fprintf (f, "  calls:\n");
    1524         1632 :           dump_ipa_call_summary (f, 4, node, s);
    1525         1632 :           fprintf (f, "\n");
    1526         1632 :           if (s->target_info)
    1527            0 :             fprintf (f, "  target_info: %x\n", s->target_info);
    1528              :         }
    1529              :       else
    1530          214 :         fprintf (f, "IPA summary for %s is missing.\n", node->dump_name ());
    1531              :     }
    1532         1846 : }
    1533              : 
    1534              : DEBUG_FUNCTION void
    1535            0 : ipa_debug_fn_summary (struct cgraph_node *node)
    1536              : {
    1537            0 :   ipa_dump_fn_summary (stderr, node);
    1538            0 : }
    1539              : 
    1540              : void
    1541          378 : ipa_dump_fn_summaries (FILE *f)
    1542              : {
    1543          378 :   struct cgraph_node *node;
    1544              : 
    1545         2549 :   FOR_EACH_DEFINED_FUNCTION (node)
    1546         2171 :     if (!node->inlined_to)
    1547         1552 :       ipa_dump_fn_summary (f, node);
    1548          378 : }
    1549              : 
    1550              : /* Callback of walk_aliased_vdefs.  Flags that it has been invoked to the
    1551              :    boolean variable pointed to by DATA.  */
    1552              : 
    1553              : static bool
    1554       974714 : mark_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef ATTRIBUTE_UNUSED,
    1555              :                void *data)
    1556              : {
    1557       974714 :   bool *b = (bool *) data;
    1558       974714 :   *b = true;
    1559       974714 :   return true;
    1560              : }
    1561              : 
    1562              : /* If OP refers to value of function parameter, return the corresponding
    1563              :    parameter.  If non-NULL, the size of the memory load (or the SSA_NAME of the
    1564              :    PARM_DECL) will be stored to *SIZE_P in that case too.  */
    1565              : 
    1566              : static tree
    1567    213789167 : unmodified_parm_1 (ipa_func_body_info *fbi, gimple *stmt, tree op,
    1568              :                    poly_int64 *size_p)
    1569              : {
    1570              :   /* SSA_NAME referring to parm default def?  */
    1571    213789167 :   if (TREE_CODE (op) == SSA_NAME
    1572    130283380 :       && SSA_NAME_IS_DEFAULT_DEF (op)
    1573    242831566 :       && TREE_CODE (SSA_NAME_VAR (op)) == PARM_DECL)
    1574              :     {
    1575     28910495 :       if (size_p)
    1576            0 :         *size_p = tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op)));
    1577     28910495 :       return SSA_NAME_VAR (op);
    1578              :     }
    1579              :   /* Non-SSA parm reference?  */
    1580    184878672 :   if (TREE_CODE (op) == PARM_DECL
    1581      1510568 :       && fbi->aa_walk_budget > 0)
    1582              :     {
    1583      1508022 :       bool modified = false;
    1584              : 
    1585      1508022 :       ao_ref refd;
    1586      1508022 :       ao_ref_init (&refd, op);
    1587      3016044 :       int walked = walk_aliased_vdefs (&refd, gimple_vuse (stmt),
    1588              :                                        mark_modified, &modified, NULL, NULL,
    1589              :                                        fbi->aa_walk_budget);
    1590      1508022 :       if (walked < 0)
    1591              :         {
    1592            8 :           fbi->aa_walk_budget = 0;
    1593       925149 :           return NULL_TREE;
    1594              :         }
    1595      1508014 :       fbi->aa_walk_budget -= walked;
    1596      1508014 :       if (!modified)
    1597              :         {
    1598       925141 :           if (size_p)
    1599            0 :             *size_p = tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op)));
    1600              :           return op;
    1601              :         }
    1602              :     }
    1603              :   return NULL_TREE;
    1604              : }
    1605              : 
    1606              : /* If OP refers to value of function parameter, return the corresponding
    1607              :    parameter.  Also traverse chains of SSA register assignments.  If non-NULL,
    1608              :    the size of the memory load (or the SSA_NAME of the PARM_DECL) will be
    1609              :    stored to *SIZE_P in that case too.  */
    1610              : 
    1611              : static tree
    1612    129275458 : unmodified_parm (ipa_func_body_info *fbi, gimple *stmt, tree op,
    1613              :                  poly_int64 *size_p)
    1614              : {
    1615    161042525 :   tree res = unmodified_parm_1 (fbi, stmt, op, size_p);
    1616    161042525 :   if (res)
    1617              :     return res;
    1618              : 
    1619    132065582 :   if (TREE_CODE (op) == SSA_NAME
    1620     76218540 :       && !SSA_NAME_IS_DEFAULT_DEF (op)
    1621    208163451 :       && gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
    1622     31767067 :     return unmodified_parm (fbi, SSA_NAME_DEF_STMT (op),
    1623     31767067 :                             gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op)),
    1624     31767067 :                             size_p);
    1625              :   return NULL_TREE;
    1626              : }
    1627              : 
    1628              : /* If OP refers to a value of a function parameter or value loaded from an
    1629              :    aggregate passed to a parameter (either by value or reference), return TRUE
    1630              :    and store the number of the parameter to *INDEX_P, the access size into
    1631              :    *SIZE_P, and information whether and how it has been loaded from an
    1632              :    aggregate into *AGGPOS.  INFO describes the function parameters, STMT is the
    1633              :    statement in which OP is used or loaded.  */
    1634              : 
    1635              : static bool
    1636     49654553 : unmodified_parm_or_parm_agg_item (struct ipa_func_body_info *fbi,
    1637              :                                   gimple *stmt, tree op, int *index_p,
    1638              :                                   poly_int64 *size_p,
    1639              :                                   struct agg_position_info *aggpos)
    1640              : {
    1641     52746642 :   tree res = unmodified_parm_1 (fbi, stmt, op, size_p);
    1642              : 
    1643     52746642 :   gcc_checking_assert (aggpos);
    1644     52746642 :   if (res)
    1645              :     {
    1646       858693 :       *index_p = ipa_get_param_decl_index (fbi->info, res);
    1647       858693 :       if (*index_p < 0)
    1648              :         return false;
    1649       858389 :       aggpos->offset = 0;
    1650       858389 :       aggpos->agg_contents = false;
    1651       858389 :       aggpos->by_ref = false;
    1652       858389 :       aggpos->maybe_modified = false;
    1653       858389 :       aggpos->unknown_offset = false;
    1654       858389 :       return true;
    1655              :     }
    1656              : 
    1657     51887949 :   if (TREE_CODE (op) == SSA_NAME)
    1658              :     {
    1659     25154345 :       if (SSA_NAME_IS_DEFAULT_DEF (op)
    1660     25154345 :           || !gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
    1661              :         return false;
    1662     10100836 :       stmt = SSA_NAME_DEF_STMT (op);
    1663     10100836 :       op = gimple_assign_rhs1 (stmt);
    1664     10100836 :       if (!REFERENCE_CLASS_P (op))
    1665              :         return unmodified_parm_or_parm_agg_item (fbi, stmt, op, index_p, size_p,
    1666              :                                                  aggpos);
    1667              :     }
    1668              : 
    1669     33742351 :   bool guaranteed_unmodified;
    1670     33742351 :   aggpos->agg_contents = true;
    1671     33742351 :   if (ipa_load_from_parm_agg (fbi, fbi->info->descriptors,
    1672              :                               stmt, op, index_p, &aggpos->offset,
    1673              :                               size_p, &aggpos->by_ref,
    1674              :                               &guaranteed_unmodified, &aggpos->unknown_offset))
    1675              :     {
    1676      5690496 :       aggpos->maybe_modified = !guaranteed_unmodified;
    1677      5690496 :       gcc_checking_assert (!aggpos->maybe_modified || aggpos->by_ref);
    1678      5690496 :       gcc_checking_assert (!aggpos->unknown_offset || aggpos->offset == -1);
    1679              :       return true;
    1680              :     }
    1681              :   return false;
    1682              : }
    1683              : 
    1684              : /* If stmt is simple load or store of value pointed to by a function parameter,
    1685              :    return its index.  */
    1686              : 
    1687              : static int
    1688    115404192 : load_or_store_of_ptr_parameter (ipa_func_body_info *fbi, gimple *stmt)
    1689              : {
    1690    115404192 :   if (!optimize)
    1691              :     return -1;
    1692     96722906 :   gassign *assign = dyn_cast <gassign *> (stmt);
    1693     57717459 :   if (!assign)
    1694              :     return -1;
    1695     57717459 :   tree param;
    1696     57717459 :   if (gimple_assign_load_p (stmt))
    1697     21049250 :     param = gimple_assign_rhs1 (stmt);
    1698     36668209 :   else if (gimple_store_p (stmt))
    1699     19500352 :     param = gimple_assign_lhs (stmt);
    1700              :   else
    1701              :     return -1;
    1702     40549602 :   tree base = get_base_address (param);
    1703     40549602 :   if (TREE_CODE (base) != MEM_REF
    1704     14031441 :       || TREE_CODE (TREE_OPERAND (base, 0)) != SSA_NAME
    1705     54576907 :       || !SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (base, 0)))
    1706              :     return -1;
    1707      7567517 :   tree p = SSA_NAME_VAR (TREE_OPERAND (base, 0));
    1708      7567517 :   if (TREE_CODE (p) != PARM_DECL)
    1709              :     return -1;
    1710      7479574 :   return ipa_get_param_decl_index (fbi->info, p);
    1711              : }
    1712              : 
    1713              : /* See if statement might disappear after inlining.
    1714              :    0 - means not eliminated
    1715              :    1 - half of statements goes away
    1716              :    2 - for sure it is eliminated.
    1717              :    We are not terribly sophisticated, basically looking for simple abstraction
    1718              :    penalty wrappers.  */
    1719              : 
    1720              : static int
    1721    115404192 : eliminated_by_inlining_prob (ipa_func_body_info *fbi, gimple *stmt)
    1722              : {
    1723    115404192 :   enum gimple_code code = gimple_code (stmt);
    1724    115404192 :   enum tree_code rhs_code;
    1725              : 
    1726    199789732 :   if (!optimize || gimple_has_volatile_ops (stmt))
    1727              :     return 0;
    1728              : 
    1729     95141514 :   switch (code)
    1730              :     {
    1731              :     case GIMPLE_RETURN:
    1732              :       return 2;
    1733     56137089 :     case GIMPLE_ASSIGN:
    1734     56137089 :       if (gimple_num_ops (stmt) != 2)
    1735              :         return 0;
    1736              : 
    1737     39807587 :       rhs_code = gimple_assign_rhs_code (stmt);
    1738              : 
    1739              :       /* Casts of parameters, loads from parameters passed by reference
    1740              :          and stores to return value or parameters are often free after
    1741              :          inlining due to SRA and further combining.
    1742              :          Assume that half of statements goes away.  */
    1743     39807587 :       if (CONVERT_EXPR_CODE_P (rhs_code)
    1744              :           || rhs_code == VIEW_CONVERT_EXPR
    1745              :           || rhs_code == ADDR_EXPR
    1746     36924766 :           || gimple_assign_rhs_class (stmt) == GIMPLE_SINGLE_RHS)
    1747              :         {
    1748     38969232 :           tree rhs = gimple_assign_rhs1 (stmt);
    1749     38969232 :           tree lhs = gimple_assign_lhs (stmt);
    1750     38969232 :           tree inner_rhs = get_base_address (rhs);
    1751     38969232 :           tree inner_lhs = get_base_address (lhs);
    1752     38969232 :           bool rhs_free = false;
    1753     38969232 :           bool lhs_free = false;
    1754              : 
    1755     38969232 :           if (!inner_rhs)
    1756            0 :             inner_rhs = rhs;
    1757     38969232 :           if (!inner_lhs)
    1758            0 :             inner_lhs = lhs;
    1759              : 
    1760              :           /* Reads of parameter are expected to be free.  */
    1761     38969232 :           if (unmodified_parm (fbi, stmt, inner_rhs, NULL))
    1762              :             rhs_free = true;
    1763              :           /* Match expressions of form &this->field. Those will most likely
    1764              :              combine with something upstream after inlining.  */
    1765     37653840 :           else if (TREE_CODE (inner_rhs) == ADDR_EXPR)
    1766              :             {
    1767      2594105 :               tree op = get_base_address (TREE_OPERAND (inner_rhs, 0));
    1768      2594105 :               if (TREE_CODE (op) == PARM_DECL)
    1769              :                 rhs_free = true;
    1770      2550029 :               else if (TREE_CODE (op) == MEM_REF
    1771      2550029 :                        && unmodified_parm (fbi, stmt, TREE_OPERAND (op, 0),
    1772              :                                            NULL))
    1773              :                 rhs_free = true;
    1774              :             }
    1775              : 
    1776              :           /* When parameter is not SSA register because its address is taken
    1777              :              and it is just copied into one, the statement will be completely
    1778              :              free after inlining (we will copy propagate backward).   */
    1779      1359468 :           if (rhs_free && is_gimple_reg (lhs))
    1780              :             return 2;
    1781              : 
    1782              :           /* Reads of parameters passed by reference
    1783              :              expected to be free (i.e. optimized out after inlining).  */
    1784     38281751 :           if (TREE_CODE (inner_rhs) == MEM_REF
    1785     38281751 :               && unmodified_parm (fbi, stmt, TREE_OPERAND (inner_rhs, 0), NULL))
    1786              :             rhs_free = true;
    1787              : 
    1788              :           /* Copying parameter passed by reference into gimple register is
    1789              :              probably also going to copy propagate, but we can't be quite
    1790              :              sure.  */
    1791     38281751 :           if (rhs_free && is_gimple_reg (lhs))
    1792              :             lhs_free = true;
    1793              : 
    1794              :           /* Whether the statement writes to the return value, either directly
    1795              :              or through the invisible reference.  */
    1796     38281751 :           bool lhs_retval
    1797     38281751 :             = (TREE_CODE (inner_lhs) == RESULT_DECL
    1798     38281751 :                || (TREE_CODE (inner_lhs) == MEM_REF
    1799      5206966 :                    && TREE_CODE (TREE_OPERAND (inner_lhs, 0)) == SSA_NAME
    1800      5205889 :                    && SSA_NAME_VAR (TREE_OPERAND (inner_lhs, 0))
    1801      2876410 :                    && (TREE_CODE (SSA_NAME_VAR (TREE_OPERAND (inner_lhs, 0)))
    1802     45809582 :                        == RESULT_DECL)));
    1803              : 
    1804              :           /* Writes to parameters, parameters passed by value and return value
    1805              :              (either directly or passed via invisible reference) are free.
    1806              : 
    1807              :              TODO: We ought to handle testcase like
    1808              :              struct a {int a,b;};
    1809              :              struct a
    1810              :              returnstruct (void)
    1811              :              {
    1812              :              struct a a ={1,2};
    1813              :              return a;
    1814              :              }
    1815              : 
    1816              :              This translate into:
    1817              : 
    1818              :              returnstruct ()
    1819              :              {
    1820              :              int a$b;
    1821              :              int a$a;
    1822              :              struct a a;
    1823              :              struct a D.2739;
    1824              : 
    1825              :              <bb 2>:
    1826              :              D.2739.a = 1;
    1827              :              D.2739.b = 2;
    1828              :              return D.2739;
    1829              : 
    1830              :              }
    1831              :              For that we either need to copy ipa-split logic detecting writes
    1832              :              to return value.  */
    1833     37344909 :           if (lhs_retval
    1834     37344909 :               || TREE_CODE (inner_lhs) == PARM_DECL
    1835     37259216 :               || (TREE_CODE (inner_lhs) == MEM_REF
    1836      5119201 :                   && unmodified_parm (fbi, stmt, TREE_OPERAND (inner_lhs, 0),
    1837              :                                       NULL)))
    1838              :             lhs_free = true;
    1839     34747781 :           if (lhs_free
    1840     38281751 :               && (is_gimple_reg (rhs) || is_gimple_min_invariant (rhs)))
    1841              :             rhs_free = true;
    1842     38281751 :           if (lhs_free && rhs_free)
    1843              :             return 1;
    1844              :           /* Credit an aggregate copy into the return value from a local
    1845              :              variable or parameter whose address is not taken as eliminated
    1846              :              by inlining.  Field accesses in the caller can allow SRA to
    1847              :              remove the copy.  */
    1848     30044964 :           if (lhs_retval
    1849       159046 :               && AGGREGATE_TYPE_P (TREE_TYPE (lhs))
    1850       159046 :               && (VAR_P (inner_rhs) || TREE_CODE (inner_rhs) == PARM_DECL)
    1851       153047 :               && auto_var_in_fn_p (inner_rhs, current_function_decl)
    1852     30193373 :               && !TREE_ADDRESSABLE (inner_rhs))
    1853              :             return 2;
    1854              :         }
    1855              :       return 0;
    1856              :     default:
    1857              :       return 0;
    1858              :     }
    1859              : }
    1860              : 
    1861              : /* Analyze EXPR if it represents a series of simple operations performed on
    1862              :    a function parameter and return true if so.  FBI, STMT, EXPR, INDEX_P and
    1863              :    AGGPOS have the same meaning like in unmodified_parm_or_parm_agg_item.
    1864              :    Type of the parameter or load from an aggregate via the parameter is
    1865              :    stored in *TYPE_P.  Operations on the parameter are recorded to
    1866              :    PARAM_OPS_P if it is not NULL.  */
    1867              : 
    1868              : static bool
    1869     37364343 : decompose_param_expr (struct ipa_func_body_info *fbi,
    1870              :                       gimple *stmt, tree expr,
    1871              :                       int *index_p, tree *type_p,
    1872              :                       struct agg_position_info *aggpos,
    1873              :                       expr_eval_ops *param_ops_p = NULL)
    1874              : {
    1875     37364343 :   int op_limit = opt_for_fn (fbi->node->decl, param_ipa_max_param_expr_ops);
    1876     37364343 :   int op_count = 0;
    1877              : 
    1878     37364343 :   if (param_ops_p)
    1879     18861624 :     *param_ops_p = NULL;
    1880              : 
    1881     49654553 :   while (true)
    1882              :     {
    1883     49654553 :       expr_eval_op eval_op;
    1884     49654553 :       unsigned rhs_count;
    1885     49654553 :       unsigned cst_count = 0;
    1886              : 
    1887     49654553 :       if (unmodified_parm_or_parm_agg_item (fbi, stmt, expr, index_p, NULL,
    1888              :                                             aggpos))
    1889              :         {
    1890      6548885 :           tree type = TREE_TYPE (expr);
    1891              : 
    1892      6548885 :           if (aggpos->agg_contents)
    1893              :             {
    1894              :               /* Stop if containing bit-field.  */
    1895      5690496 :               if (TREE_CODE (expr) == BIT_FIELD_REF
    1896      5690496 :                   || contains_bitfld_component_ref_p (expr))
    1897              :                 break;
    1898              :             }
    1899              : 
    1900      6499500 :           *type_p = type;
    1901      6499500 :           return true;
    1902              :         }
    1903              : 
    1904     43105668 :       if (TREE_CODE (expr) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (expr))
    1905              :         break;
    1906     22556216 :       stmt = SSA_NAME_DEF_STMT (expr);
    1907              : 
    1908     22556216 :       if (gcall *call = dyn_cast <gcall *> (stmt))
    1909              :         {
    1910      5362487 :           int flags = gimple_call_return_flags (call);
    1911      5362487 :           if (!(flags & ERF_RETURNS_ARG))
    1912      6538794 :             goto fail;
    1913       385205 :           int arg = flags & ERF_RETURN_ARG_MASK;
    1914       385205 :           if (arg >= (int)gimple_call_num_args (call))
    1915            0 :             goto fail;
    1916       385205 :           expr = gimple_call_arg (stmt, arg);
    1917      8683184 :           continue;
    1918       385205 :         }
    1919              : 
    1920     37792863 :       gassign *a_stmt = dyn_cast<gassign *> (stmt = SSA_NAME_DEF_STMT (expr));
    1921     13466814 :       if (!a_stmt)
    1922              :         break;
    1923              : 
    1924     13466814 :       switch (gimple_assign_rhs_class (a_stmt))
    1925              :         {
    1926      8297979 :         case GIMPLE_SINGLE_RHS:
    1927      8297979 :           expr = gimple_assign_rhs1 (a_stmt);
    1928      8297979 :           continue;
    1929              : 
    1930              :         case GIMPLE_UNARY_RHS:
    1931              :           rhs_count = 1;
    1932              :           break;
    1933              : 
    1934      3173427 :         case GIMPLE_BINARY_RHS:
    1935      3173427 :           rhs_count = 2;
    1936      3173427 :           break;
    1937              : 
    1938         1407 :         case GIMPLE_TERNARY_RHS:
    1939         1407 :           rhs_count = 3;
    1940         1407 :           break;
    1941              : 
    1942            0 :         default:
    1943            0 :           goto fail;
    1944              :         }
    1945              : 
    1946              :       /* Stop if expression is too complex.  */
    1947      5168835 :       if (op_count++ == op_limit)
    1948              :         break;
    1949              : 
    1950      5168538 :       if (param_ops_p)
    1951              :         {
    1952      5134241 :           eval_op.code = gimple_assign_rhs_code (a_stmt);
    1953      5134241 :           eval_op.type = TREE_TYPE (gimple_assign_lhs (a_stmt));
    1954      5134241 :           eval_op.val[0] = NULL_TREE;
    1955      5134241 :           eval_op.val[1] = NULL_TREE;
    1956              :         }
    1957              : 
    1958      5168538 :       expr = NULL_TREE;
    1959     11950282 :       for (unsigned i = 0; i < rhs_count; i++)
    1960              :         {
    1961      8343256 :           tree op = gimple_op (stmt, i + 1);
    1962              : 
    1963      8343256 :           gcc_assert (op && !TYPE_P (op));
    1964      8343256 :           if (is_gimple_ip_invariant (op))
    1965              :             {
    1966      1615948 :               if (++cst_count == rhs_count)
    1967         1371 :                 goto fail;
    1968              : 
    1969      1614577 :               eval_op.val[cst_count - 1] = op;
    1970              :             }
    1971      6727308 :           else if (!expr)
    1972              :             {
    1973              :               /* Found a non-constant operand, and record its index in rhs
    1974              :                  operands.  */
    1975      5167167 :               eval_op.index = i;
    1976      5167167 :               expr = op;
    1977              :             }
    1978              :           else
    1979              :             {
    1980              :               /* Found more than one non-constant operands.  */
    1981      1560141 :               goto fail;
    1982              :             }
    1983              :         }
    1984              : 
    1985      3607026 :       if (param_ops_p)
    1986      3573349 :         vec_safe_insert (*param_ops_p, 0, eval_op);
    1987              :     }
    1988              : 
    1989              :   /* Failed to decompose, free resource and return.  */
    1990     30864843 : fail:
    1991     30864843 :   if (param_ops_p)
    1992     19488467 :     vec_free (*param_ops_p);
    1993              : 
    1994              :   return false;
    1995              : }
    1996              : 
    1997              : /* Record to SUMMARY that PARM is used by builtin_constant_p.  */
    1998              : 
    1999              : static void
    2000        12085 : add_builtin_constant_p_parm (class ipa_fn_summary *summary, int parm)
    2001              : {
    2002        12085 :   int ip;
    2003              : 
    2004              :   /* Avoid duplicates.  */
    2005        12143 :   for (unsigned int i = 0;
    2006        12143 :        summary->builtin_constant_p_parms.iterate (i, &ip); i++)
    2007         5987 :     if (ip == parm)
    2008        12085 :       return;
    2009         6156 :   summary->builtin_constant_p_parms.safe_push (parm);
    2010              : }
    2011              : 
    2012              : /* If BB ends by a conditional we can turn into predicates, attach corresponding
    2013              :    predicates to the CFG edges.   */
    2014              : 
    2015              : static void
    2016     36277911 : set_cond_stmt_execution_predicate (struct ipa_func_body_info *fbi,
    2017              :                                    class ipa_fn_summary *summary,
    2018              :                                    class ipa_node_params *params_summary,
    2019              :                                    basic_block bb)
    2020              : {
    2021     36277911 :   tree op, op2;
    2022     36277911 :   int index;
    2023     36277911 :   struct agg_position_info aggpos;
    2024     36277911 :   enum tree_code code, inverted_code;
    2025     36277911 :   edge e;
    2026     36277911 :   edge_iterator ei;
    2027     36277911 :   gimple *set_stmt;
    2028     36277911 :   tree param_type;
    2029     36277911 :   expr_eval_ops param_ops;
    2030              : 
    2031     72555822 :   gcond *last = safe_dyn_cast <gcond *> (*gsi_last_bb (bb));
    2032     12040733 :   if (!last)
    2033     36264804 :     return;
    2034     12040733 :   if (!is_gimple_ip_invariant (gimple_cond_rhs (last)))
    2035              :     return;
    2036      9554323 :   op = gimple_cond_lhs (last);
    2037              : 
    2038      9554323 :   if (decompose_param_expr (fbi, last, op, &index, &param_type, &aggpos,
    2039              :                             &param_ops))
    2040              :     {
    2041      1557620 :       code = gimple_cond_code (last);
    2042      1557620 :       inverted_code = invert_tree_comparison (code, HONOR_NANS (op));
    2043              : 
    2044      4672860 :       FOR_EACH_EDGE (e, ei, bb->succs)
    2045              :         {
    2046      1557620 :           enum tree_code this_code = (e->flags & EDGE_TRUE_VALUE
    2047      3115240 :                                       ? code : inverted_code);
    2048              :           /* invert_tree_comparison will return ERROR_MARK on FP
    2049              :              comparisons that are not EQ/NE instead of returning proper
    2050              :              unordered one.  Be sure it is not confused with NON_CONSTANT.
    2051              : 
    2052              :              And if the edge's target is the final block of diamond CFG graph
    2053              :              of this conditional statement, we do not need to compute
    2054              :              predicate for the edge because the final block's predicate must
    2055              :              be at least as that of the first block of the statement.  */
    2056      3115240 :           if (this_code != ERROR_MARK
    2057      3115240 :               && !dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    2058              :             {
    2059      2639944 :               ipa_predicate p
    2060      2639944 :                 = add_condition (summary, params_summary, index,
    2061              :                                  param_type, &aggpos,
    2062              :                                  this_code, gimple_cond_rhs (last), param_ops);
    2063      2639944 :               e->aux = edge_predicate_pool.allocate ();
    2064      2639944 :               *(ipa_predicate *) e->aux = p;
    2065              :             }
    2066              :         }
    2067     36548655 :       vec_free (param_ops);
    2068              :       return;
    2069              :     }
    2070              : 
    2071      7996703 :   if (TREE_CODE (op) != SSA_NAME)
    2072              :     return;
    2073              :   /* Special case
    2074              :      if (builtin_constant_p (op))
    2075              :      constant_code
    2076              :      else
    2077              :      nonconstant_code.
    2078              :      Here we can predicate nonconstant_code.  We can't
    2079              :      really handle constant_code since we have no predicate
    2080              :      for this and also the constant code is not known to be
    2081              :      optimized away when inliner doesn't see operand is constant.
    2082              :      Other optimizers might think otherwise.  */
    2083      7995576 :   if (gimple_cond_code (last) != NE_EXPR
    2084      7995576 :       || !integer_zerop (gimple_cond_rhs (last)))
    2085              :     return;
    2086      3525243 :   set_stmt = SSA_NAME_DEF_STMT (op);
    2087      3525243 :   if (!gimple_call_builtin_p (set_stmt, BUILT_IN_CONSTANT_P)
    2088      3525243 :       || gimple_call_num_args (set_stmt) != 1)
    2089              :     return;
    2090        46462 :   op2 = gimple_call_arg (set_stmt, 0);
    2091        46462 :   if (!decompose_param_expr (fbi, set_stmt, op2, &index, &param_type, &aggpos)
    2092        46462 :       || aggpos.unknown_offset)
    2093              :     return;
    2094        13107 :   if (!aggpos.by_ref)
    2095        12023 :     add_builtin_constant_p_parm (summary, index);
    2096        39321 :   FOR_EACH_EDGE (e, ei, bb->succs) if (e->flags & EDGE_FALSE_VALUE)
    2097              :     {
    2098        13107 :       ipa_predicate p = add_condition (summary, params_summary, index,
    2099              :                                    param_type, &aggpos,
    2100              :                                    ipa_predicate::is_not_constant, NULL_TREE);
    2101        13107 :       e->aux = edge_predicate_pool.allocate ();
    2102        13107 :       *(ipa_predicate *) e->aux = p;
    2103              :     }
    2104              : }
    2105              : 
    2106              : 
    2107              : /* Compute predicates for outgoing edges of switch statement SWTCH in BB.
    2108              :    When FOR_EXECUTION_P is true, bypass computing predicates for edges whose
    2109              :    destination post-dominates BB (since BB's execution predicate already implies
    2110              :    execution of its post-dominators).  Populate *EDGE_PREDS with one predicate
    2111              :    per edge in BB->succs and return true on success.  */
    2112              : 
    2113              : static bool
    2114       133854 : compute_switch_edge_predicates (struct ipa_func_body_info *fbi,
    2115              :                                 class ipa_fn_summary *summary,
    2116              :                                 class ipa_node_params *params_summary,
    2117              :                                 basic_block bb,
    2118              :                                 gswitch *swtch,
    2119              :                                 bool for_execution_p,
    2120              :                                 vec<ipa_predicate> *edge_preds)
    2121              : {
    2122       133854 :   tree op;
    2123       133854 :   int index;
    2124       133854 :   struct agg_position_info aggpos;
    2125       133854 :   edge e;
    2126       133854 :   edge_iterator ei;
    2127       133854 :   size_t n;
    2128       133854 :   size_t case_idx;
    2129       133854 :   tree param_type;
    2130       133854 :   expr_eval_ops param_ops;
    2131              : 
    2132       133854 :   op = gimple_switch_index (swtch);
    2133       133854 :   if (!decompose_param_expr (fbi, swtch, op, &index, &param_type, &aggpos,
    2134              :                              &param_ops))
    2135              :     return false;
    2136              : 
    2137        60227 :   auto_vec<std::pair<tree, tree> > ranges;
    2138        60227 :   tree type = TREE_TYPE (op);
    2139        60227 :   int bound_limit = opt_for_fn (fbi->node->decl,
    2140              :                                 param_ipa_max_switch_predicate_bounds);
    2141        60227 :   int bound_count = 0;
    2142              :   // This can safely be an integer range, as switches can only hold
    2143              :   // integers.
    2144        60227 :   int_range<2> vr;
    2145              : 
    2146       120454 :   get_range_query (cfun)->range_of_expr (vr, op);
    2147        60227 :   if (vr.undefined_p ())
    2148            0 :     vr.set_varying (TREE_TYPE (op));
    2149        60227 :   tree vr_min, vr_max;
    2150              :   // TODO: This entire function could use a rewrite to use the irange
    2151              :   // API, instead of trying to recreate its intersection/union logic.
    2152              :   // Any use of get_legacy_range() is a serious code smell.
    2153        60227 :   value_range_kind vr_type = get_legacy_range (vr, vr_min, vr_max);
    2154        60227 :   wide_int vr_wmin = wi::to_wide (vr_min);
    2155        60227 :   wide_int vr_wmax = wi::to_wide (vr_max);
    2156              : 
    2157        60227 :   hash_map<edge, unsigned> edge_map;
    2158        60227 :   unsigned edge_idx = 0;
    2159       447658 :   FOR_EACH_EDGE (e, ei, bb->succs)
    2160              :     {
    2161       387431 :       edge_map.put (e, edge_idx++);
    2162       387431 :       edge_preds->safe_push (false);
    2163              :     }
    2164              : 
    2165        60227 :   edge default_edge = gimple_switch_edge (cfun, swtch, 0);
    2166              :   /* Set BOUND_COUNT to maximum count to bypass computing predicate for
    2167              :      default case if its target basic block is in convergence point of all
    2168              :      switch cases, which can be determined by checking whether it
    2169              :      post-dominates the switch statement.  */
    2170        60227 :   if (for_execution_p
    2171        60227 :       && dominated_by_p (CDI_POST_DOMINATORS, bb, default_edge->dest))
    2172              :     bound_count = INT_MAX;
    2173              : 
    2174        60227 :   n = gimple_switch_num_labels (swtch);
    2175       422769 :   for (case_idx = 1; case_idx < n; ++case_idx)
    2176              :     {
    2177       362542 :       tree cl = gimple_switch_label (swtch, case_idx);
    2178       362542 :       tree min = CASE_LOW (cl);
    2179       362542 :       tree max = CASE_HIGH (cl);
    2180       362542 :       ipa_predicate p;
    2181              : 
    2182       362542 :       e = gimple_switch_edge (cfun, swtch, case_idx);
    2183       362542 :       if (!for_execution_p && e == default_edge)
    2184       107103 :         continue;
    2185              : 
    2186              :       /* The case value might not have same type as switch expression,
    2187              :          extend the value based on the expression type.  */
    2188       362542 :       if (TREE_TYPE (min) != type)
    2189       131863 :         min = wide_int_to_tree (type, wi::to_widest (min));
    2190              : 
    2191       362542 :       if (!max)
    2192              :         max = min;
    2193        18972 :       else if (TREE_TYPE (max) != type)
    2194         8412 :         max = wide_int_to_tree (type, wi::to_widest (max));
    2195              : 
    2196              :       /* The case's target basic block is in convergence point of all switch
    2197              :          cases, its predicate should be at least as that of the switch
    2198              :          statement.  */
    2199       362542 :       if (for_execution_p && dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest))
    2200         5649 :         p = true;
    2201       356893 :       else if (min == max)
    2202       339877 :         p = add_condition (summary, params_summary, index, param_type,
    2203              :                            &aggpos, EQ_EXPR, min, param_ops);
    2204              :       else
    2205              :         {
    2206        17016 :           ipa_predicate p1, p2;
    2207        17016 :           p1 = add_condition (summary, params_summary, index, param_type,
    2208              :                               &aggpos, GE_EXPR, min, param_ops);
    2209        17016 :           p2 = add_condition (summary, params_summary, index, param_type,
    2210              :                               &aggpos, LE_EXPR, max, param_ops);
    2211        17016 :           p = p1 & p2;
    2212              :         }
    2213       362542 :       unsigned *slot = edge_map.get (e);
    2214       362542 :       gcc_checking_assert (slot);
    2215       362542 :       (*edge_preds)[*slot]
    2216       362542 :         = p.or_with (summary->conds, (*edge_preds)[*slot]);
    2217              : 
    2218              :       /* If there are too many disjoint case ranges, predicate for default
    2219              :          case might become too complicated.  So add a limit here.  */
    2220       362542 :       if (bound_count > bound_limit)
    2221       107103 :         continue;
    2222              : 
    2223       255439 :       bool new_range = true;
    2224              : 
    2225       255439 :       if (!ranges.is_empty ())
    2226              :         {
    2227       208706 :           wide_int curr_wmin = wi::to_wide (min);
    2228       208706 :           wide_int last_wmax = wi::to_wide (ranges.last ().second);
    2229              : 
    2230              :           /* Merge case ranges if they are continuous.  */
    2231       208706 :           if (curr_wmin == last_wmax + 1)
    2232              :             new_range = false;
    2233        50888 :           else if (vr_type == VR_ANTI_RANGE)
    2234              :             {
    2235              :               /* If two disjoint case ranges can be connected by anti-range
    2236              :                  of switch index, combine them to one range.  */
    2237          141 :               if (wi::lt_p (vr_wmax, curr_wmin - 1, TYPE_SIGN (type)))
    2238              :                 vr_type = VR_UNDEFINED;
    2239            0 :               else if (wi::le_p (vr_wmin, last_wmax + 1, TYPE_SIGN (type)))
    2240            0 :                 new_range = false;
    2241              :             }
    2242       208706 :         }
    2243              : 
    2244              :       /* Create/extend a case range.  And we count endpoints of range set,
    2245              :          this number nearly equals to number of conditions that we will create
    2246              :          for predicate of default case.  */
    2247       208706 :       if (new_range)
    2248              :         {
    2249        97621 :           bound_count += (min == max) ? 1 : 2;
    2250        97621 :           ranges.safe_push (std::make_pair (min, max));
    2251              :         }
    2252              :       else
    2253              :         {
    2254       157818 :           bound_count += (ranges.last ().first == ranges.last ().second);
    2255       157818 :           ranges.last ().second = max;
    2256              :         }
    2257              :     }
    2258              : 
    2259        60227 :   unsigned default_slot = *edge_map.get (default_edge);
    2260        60227 :   if (bound_count > bound_limit)
    2261        16482 :     (*edge_preds)[default_slot] = true;
    2262              :   else
    2263              :     {
    2264        43745 :       ipa_predicate p_seg = true;
    2265        43745 :       ipa_predicate p_all = false;
    2266              : 
    2267        43745 :       if (vr_type != VR_RANGE)
    2268              :         {
    2269        43093 :           vr_wmin = wi::to_wide (TYPE_MIN_VALUE (type));
    2270        43093 :           vr_wmax = wi::to_wide (TYPE_MAX_VALUE (type));
    2271              :         }
    2272              : 
    2273              :       /* Construct predicate to represent default range set that is negation of
    2274              :          all case ranges.  Case range is classified as containing
    2275              :          single/non-single values.  Suppose a piece of case ranges in the
    2276              :          following.
    2277              : 
    2278              :                     [D1...D2]  [S1] ... [Sn]  [D3...D4]
    2279              : 
    2280              :          To represent default case's range sets between two non-single value
    2281              :          case ranges (From D2 to D3), we construct predicate as:
    2282              : 
    2283              :                   D2 < x < D3 && x != S1 && ... && x != Sn
    2284              :        */
    2285       126750 :       for (size_t i = 0; i < ranges.length (); i++)
    2286              :         {
    2287        83186 :           tree min = ranges[i].first;
    2288        83186 :           tree max = ranges[i].second;
    2289              : 
    2290        83186 :           if (min == max)
    2291        86140 :             p_seg &= add_condition (summary, params_summary, index,
    2292              :                                     param_type, &aggpos, NE_EXPR,
    2293        43070 :                                     min, param_ops);
    2294              :           else
    2295              :             {
    2296              :               /* Do not create sub-predicate for range that is beyond low
    2297              :                  bound of switch index.  */
    2298        40116 :               if (wi::lt_p (vr_wmin, wi::to_wide (min), TYPE_SIGN (type)))
    2299              :                 {
    2300        31588 :                   p_seg &= add_condition (summary, params_summary, index,
    2301              :                                           param_type, &aggpos,
    2302        31588 :                                           LT_EXPR, min, param_ops);
    2303        31588 :                   p_all = p_all.or_with (summary->conds, p_seg);
    2304              :                 }
    2305              : 
    2306              :               /* Do not create sub-predicate for range that is beyond up bound
    2307              :                  of switch index.  */
    2308        40116 :               if (wi::le_p (vr_wmax, wi::to_wide (max), TYPE_SIGN (type)))
    2309              :                 {
    2310          181 :                   p_seg = false;
    2311          181 :                   break;
    2312              :                 }
    2313              : 
    2314        39935 :               p_seg = add_condition (summary, params_summary, index,
    2315              :                                      param_type, &aggpos, GT_EXPR,
    2316              :                                      max, param_ops);
    2317              :             }
    2318              :         }
    2319              : 
    2320        43745 :       p_all = p_all.or_with (summary->conds, p_seg);
    2321        43745 :       (*edge_preds)[default_slot]
    2322        43745 :         = p_all.or_with (summary->conds, (*edge_preds)[default_slot]);
    2323              :     }
    2324              : 
    2325        60227 :   if (!for_execution_p && default_slot != 0)
    2326           82 :     std::swap ((*edge_preds)[0], (*edge_preds)[default_slot]);
    2327              : 
    2328        60227 :   vec_free (param_ops);
    2329        60227 :   return true;
    2330        60227 : }
    2331              : 
    2332              : 
    2333              : /* If BB ends by a switch we can turn into predicates, attach corresponding
    2334              :    predicates to the CFG edges.  */
    2335              : 
    2336              : static void
    2337     36277911 : set_switch_stmt_execution_predicate (struct ipa_func_body_info *fbi,
    2338              :                                      class ipa_fn_summary *summary,
    2339              :                                      class ipa_node_params *params_summary,
    2340              :                                      basic_block bb)
    2341              : {
    2342     72555822 :   gswitch *last = safe_dyn_cast <gswitch *> (*gsi_last_bb (bb));
    2343        83549 :   if (!last)
    2344     36226890 :     return;
    2345              : 
    2346        83549 :   auto_vec<ipa_predicate, 8> edge_preds;
    2347        83549 :   if (!compute_switch_edge_predicates (fbi, summary, params_summary,
    2348              :                                        bb, last, true, &edge_preds))
    2349        32528 :     return;
    2350              : 
    2351        51021 :   edge e;
    2352        51021 :   edge_iterator ei;
    2353        51021 :   unsigned edge_idx = 0;
    2354       354201 :   FOR_EACH_EDGE (e, ei, bb->succs)
    2355              :     {
    2356       303180 :       e->aux = edge_predicate_pool.allocate ();
    2357       303180 :       *(ipa_predicate *) e->aux = edge_preds[edge_idx++];
    2358              :     }
    2359        83549 : }
    2360              : 
    2361              : 
    2362              : /* For each BB in NODE attach to its AUX pointer predicate under
    2363              :    which it is executable.  */
    2364              : 
    2365              : static void
    2366      6526878 : compute_bb_predicates (struct ipa_func_body_info *fbi,
    2367              :                        struct cgraph_node *node,
    2368              :                        class ipa_fn_summary *summary,
    2369              :                        class ipa_node_params *params_summary)
    2370              : {
    2371      6526878 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    2372      6526878 :   bool done = false;
    2373      6526878 :   basic_block bb;
    2374              : 
    2375     42804789 :   FOR_EACH_BB_FN (bb, my_function)
    2376              :     {
    2377     36277911 :       set_cond_stmt_execution_predicate (fbi, summary, params_summary, bb);
    2378     36277911 :       set_switch_stmt_execution_predicate (fbi, summary, params_summary, bb);
    2379              :     }
    2380              : 
    2381              :   /* Entry block is always executable.  */
    2382      6526878 :   ENTRY_BLOCK_PTR_FOR_FN (my_function)->aux
    2383      6526878 :     = edge_predicate_pool.allocate ();
    2384      6526878 :   *(ipa_predicate *) ENTRY_BLOCK_PTR_FOR_FN (my_function)->aux = true;
    2385              : 
    2386              :   /* A simple dataflow propagation of predicates forward in the CFG.
    2387              :      TODO: work in reverse postorder.  */
    2388     19707725 :   while (!done)
    2389              :     {
    2390     13180847 :       done = true;
    2391     91308665 :       FOR_EACH_BB_FN (bb, my_function)
    2392              :         {
    2393     78127818 :           ipa_predicate p = false;
    2394     78127818 :           edge e;
    2395     78127818 :           edge_iterator ei;
    2396     98823369 :           FOR_EACH_EDGE (e, ei, bb->preds)
    2397              :             {
    2398     83621376 :               if (e->src->aux)
    2399              :                 {
    2400     81685493 :                   ipa_predicate this_bb_predicate
    2401              :                     = *(ipa_predicate *) e->src->aux;
    2402     81685493 :                   if (e->aux)
    2403      6211335 :                     this_bb_predicate &= (*(ipa_predicate *) e->aux);
    2404     81685493 :                   p = p.or_with (summary->conds, this_bb_predicate);
    2405     81685493 :                   if (p == true)
    2406              :                     break;
    2407              :                 }
    2408              :             }
    2409     78127818 :           if (p != false)
    2410              :             {
    2411     76858696 :               basic_block pdom_bb;
    2412              : 
    2413     76858696 :               if (!bb->aux)
    2414              :                 {
    2415     28465257 :                   done = false;
    2416     28465257 :                   bb->aux = edge_predicate_pool.allocate ();
    2417     28465257 :                   *((ipa_predicate *) bb->aux) = p;
    2418              :                 }
    2419     48393439 :               else if (p != *(ipa_predicate *) bb->aux)
    2420              :                 {
    2421              :                   /* This OR operation is needed to ensure monotonous data flow
    2422              :                      in the case we hit the limit on number of clauses and the
    2423              :                      and/or operations above give approximate answers.  */
    2424       167874 :                   p = p.or_with (summary->conds, *(ipa_predicate *)bb->aux);
    2425       167874 :                   if (p != *(ipa_predicate *)bb->aux)
    2426              :                     {
    2427       137596 :                       done = false;
    2428       137596 :                       *((ipa_predicate *)bb->aux) = p;
    2429              :                     }
    2430              :                 }
    2431              : 
    2432              :               /* For switch/if statement, we can OR-combine predicates of all
    2433              :                  its cases/branches to get predicate for basic block in their
    2434              :                  convergence point, but sometimes this will generate very
    2435              :                  complicated predicate.  Actually, we can get simplified
    2436              :                  predicate in another way by using the fact that predicate
    2437              :                  for a basic block must also hold true for its post dominators.
    2438              :                  To be specific, basic block in convergence point of
    2439              :                  conditional statement should include predicate of the
    2440              :                  statement.  */
    2441     76858696 :               pdom_bb = get_immediate_dominator (CDI_POST_DOMINATORS, bb);
    2442     76858696 :               if (pdom_bb == EXIT_BLOCK_PTR_FOR_FN (my_function) || !pdom_bb)
    2443              :                 ;
    2444     39530809 :               else if (!pdom_bb->aux)
    2445              :                 {
    2446      7812628 :                   done = false;
    2447      7812628 :                   pdom_bb->aux = edge_predicate_pool.allocate ();
    2448      7812628 :                   *((ipa_predicate *)pdom_bb->aux) = p;
    2449              :                 }
    2450     31718181 :               else if (p != *(ipa_predicate *)pdom_bb->aux)
    2451              :                 {
    2452      4059625 :                   p = p.or_with (summary->conds,
    2453              :                                  *(ipa_predicate *)pdom_bb->aux);
    2454      4059625 :                   if (p != *(ipa_predicate *)pdom_bb->aux)
    2455              :                     {
    2456       162594 :                       done = false;
    2457       162594 :                       *((ipa_predicate *)pdom_bb->aux) = p;
    2458              :                     }
    2459              :                 }
    2460              :             }
    2461              :         }
    2462              :     }
    2463      6526878 : }
    2464              : 
    2465              : 
    2466              : /* Return predicate specifying when the STMT might have result that is not
    2467              :    a compile time constant.  */
    2468              : 
    2469              : static ipa_predicate
    2470      2539033 : will_be_nonconstant_expr_predicate (ipa_func_body_info *fbi,
    2471              :                                     class ipa_fn_summary *summary,
    2472              :                                     class ipa_node_params *params_summary,
    2473              :                                     tree expr,
    2474              :                                     vec<ipa_predicate> nonconstant_names)
    2475              : {
    2476      2539033 :   tree parm;
    2477      2539033 :   int index;
    2478              : 
    2479      2794991 :   while (UNARY_CLASS_P (expr))
    2480       255958 :     expr = TREE_OPERAND (expr, 0);
    2481              : 
    2482      2539033 :   parm = unmodified_parm (fbi, NULL, expr, NULL);
    2483      2539033 :   if (parm && (index = ipa_get_param_decl_index (fbi->info, parm)) >= 0)
    2484        49742 :     return add_condition (summary, params_summary, index, TREE_TYPE (parm), NULL,
    2485        49742 :                           ipa_predicate::changed, NULL_TREE);
    2486      2489291 :   if (is_gimple_min_invariant (expr))
    2487        78189 :     return false;
    2488      2411102 :   if (TREE_CODE (expr) == SSA_NAME)
    2489      2225291 :     return nonconstant_names[SSA_NAME_VERSION (expr)];
    2490       185811 :   if (BINARY_CLASS_P (expr) || COMPARISON_CLASS_P (expr))
    2491              :     {
    2492       185210 :       ipa_predicate p1
    2493       185210 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2494              :                                               params_summary,
    2495       185210 :                                               TREE_OPERAND (expr, 0),
    2496              :                                               nonconstant_names);
    2497       185210 :       if (p1 == true)
    2498        86684 :         return p1;
    2499              : 
    2500        98526 :       ipa_predicate p2
    2501        98526 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2502              :                                               params_summary,
    2503        98526 :                                               TREE_OPERAND (expr, 1),
    2504              :                                               nonconstant_names);
    2505        98526 :       return p1.or_with (summary->conds, p2);
    2506              :     }
    2507          601 :   else if (TREE_CODE (expr) == COND_EXPR)
    2508              :     {
    2509           89 :       ipa_predicate p1
    2510           89 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2511              :                                               params_summary,
    2512           89 :                                               TREE_OPERAND (expr, 0),
    2513              :                                               nonconstant_names);
    2514           89 :       if (p1 == true)
    2515           27 :         return p1;
    2516              : 
    2517           62 :       ipa_predicate p2
    2518           62 :         = will_be_nonconstant_expr_predicate (fbi, summary,
    2519              :                                               params_summary,
    2520           62 :                                               TREE_OPERAND (expr, 1),
    2521              :                                               nonconstant_names);
    2522           62 :       if (p2 == true)
    2523           62 :         return p2;
    2524            0 :       p1 = p1.or_with (summary->conds, p2);
    2525            0 :       p2 = will_be_nonconstant_expr_predicate (fbi, summary,
    2526              :                                                params_summary,
    2527            0 :                                                TREE_OPERAND (expr, 2),
    2528              :                                                nonconstant_names);
    2529            0 :       return p2.or_with (summary->conds, p1);
    2530              :     }
    2531          512 :   else if (TREE_CODE (expr) == CALL_EXPR)
    2532          512 :     return true;
    2533              :   else
    2534              :     {
    2535            0 :       debug_tree (expr);
    2536            0 :       gcc_unreachable ();
    2537              :     }
    2538              : }
    2539              : 
    2540              : 
    2541              : /* Return predicate specifying when the STMT might have result that is not
    2542              :    a compile time constant.  */
    2543              : 
    2544              : static ipa_predicate
    2545    120451898 : will_be_nonconstant_predicate (struct ipa_func_body_info *fbi,
    2546              :                                class ipa_fn_summary *summary,
    2547              :                                class ipa_node_params *params_summary,
    2548              :                                gimple *stmt,
    2549              :                                vec<ipa_predicate> nonconstant_names)
    2550              : {
    2551    120451898 :   ipa_predicate p = true;
    2552    120451898 :   ssa_op_iter iter;
    2553    120451898 :   tree use;
    2554    120451898 :   tree param_type = NULL_TREE;
    2555    120451898 :   ipa_predicate op_non_const;
    2556    120451898 :   bool is_load;
    2557    120451898 :   int base_index;
    2558    120451898 :   struct agg_position_info aggpos;
    2559              : 
    2560              :   /* What statements might be optimized away
    2561              :      when their arguments are constant.  */
    2562    120451898 :   if (gimple_code (stmt) != GIMPLE_ASSIGN
    2563              :       && gimple_code (stmt) != GIMPLE_COND
    2564              :       && gimple_code (stmt) != GIMPLE_SWITCH
    2565              :       && (gimple_code (stmt) != GIMPLE_CALL
    2566     21515431 :           || !(gimple_call_flags (stmt) & ECF_CONST)))
    2567     26909034 :     return p;
    2568              : 
    2569              :   /* Stores will stay anyway.  */
    2570     93542864 :   if (gimple_store_p (stmt))
    2571     26964389 :     return p;
    2572              : 
    2573     66578475 :   is_load = gimple_assign_load_p (stmt);
    2574              : 
    2575              :   /* Loads can be optimized when the value is known.  An unknown-offset load
    2576              :      itself can still read different values across offsets or iterations, so
    2577              :      leave nonconstant_names true for it; comparisons of it against an
    2578              :      invariant are handled below.  */
    2579     66578475 :   if (is_load)
    2580              :     {
    2581     18456257 :       tree op = gimple_assign_rhs1 (stmt);
    2582     18456257 :       if (!decompose_param_expr (fbi, stmt, op, &base_index, &param_type,
    2583              :                                  &aggpos)
    2584     18456257 :           || aggpos.unknown_offset)
    2585     13852885 :         return p;
    2586              :     }
    2587              :   else
    2588     48122218 :     base_index = -1;
    2589              : 
    2590              :   /* See if we understand all operands before we start
    2591              :      adding conditionals.  */
    2592     52725590 :   bool understood = true;
    2593     74107502 :   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2594              :     {
    2595     53062961 :       tree parm = unmodified_parm (fbi, stmt, use, NULL);
    2596              :       /* For arguments we can build a condition.  */
    2597     53062961 :       if (parm && ipa_get_param_decl_index (fbi->info, parm) >= 0)
    2598     10175215 :         continue;
    2599     42887746 :       if (TREE_CODE (use) != SSA_NAME)
    2600              :         {
    2601              :           understood = false;
    2602              :           break;
    2603              :         }
    2604              :       /* If we know when operand is constant,
    2605              :          we still can say something useful.  */
    2606     42887746 :       if (nonconstant_names[SSA_NAME_VERSION (use)] != true)
    2607     11206697 :         continue;
    2608              :       understood = false;
    2609              :       break;
    2610              :     }
    2611              : 
    2612              :   /* Even if an operand itself is non-constant (such as a load at an unknown
    2613              :      or maybe-modified offset), a comparison against an IP-invariant or a
    2614              :      switch is constant whenever at most one outcome is possible.  */
    2615     52725590 :   if (!understood)
    2616              :     {
    2617     31681049 :       if (gswitch *swtch = dyn_cast <gswitch *> (stmt))
    2618              :         {
    2619        50305 :           auto_vec<ipa_predicate, 8> edge_preds;
    2620        50305 :           if (!compute_switch_edge_predicates (fbi, summary, params_summary,
    2621              :                                                gimple_bb (swtch), swtch,
    2622              :                                                false, &edge_preds))
    2623        41099 :             return p;
    2624              : 
    2625         9206 :           unsigned n_edges = edge_preds.length ();
    2626         9206 :           if (n_edges < 2)
    2627            0 :             return false;
    2628              : 
    2629              :           unsigned n_true = 0;
    2630        88285 :           for (unsigned i = 0; i < n_edges; i++)
    2631        79537 :             if (edge_preds[i] == true && ++n_true >= 2)
    2632          458 :               return p;
    2633              : 
    2634              :           /* Switch is non-constant when at least two distinct outgoing edges
    2635              :              may be taken, i.e. for each edge m some edge j != m is not
    2636              :              excluded.  */
    2637         8748 :           auto_vec<ipa_predicate, 8> suffix_or;
    2638         8748 :           suffix_or.safe_grow_cleared (n_edges + 1, true);
    2639         8748 :           suffix_or[n_edges] = false;
    2640        83887 :           for (unsigned i = n_edges; i-- > 0;)
    2641       150278 :             suffix_or[i]
    2642        75139 :               = suffix_or[i + 1].or_with (summary->conds, edge_preds[i]);
    2643              : 
    2644         8748 :           ipa_predicate prefix_or = false;
    2645         8748 :           op_non_const = true;
    2646        83887 :           for (unsigned m = 0; m < n_edges; m++)
    2647              :             {
    2648        75139 :               ipa_predicate others
    2649        75139 :                 = prefix_or.or_with (summary->conds, suffix_or[m + 1]);
    2650        75139 :               op_non_const &= others;
    2651        75139 :               prefix_or = prefix_or.or_with (summary->conds, edge_preds[m]);
    2652              :             }
    2653         8748 :           return op_non_const;
    2654        59053 :         }
    2655              : 
    2656     31630744 :       tree lhs, rhs;
    2657     31630744 :       enum tree_code code;
    2658     31630744 :       if (gcond *cond = dyn_cast <gcond *> (stmt))
    2659              :         {
    2660     10621307 :           code = gimple_cond_code (cond);
    2661     10621307 :           lhs = gimple_cond_lhs (cond);
    2662     10621307 :           rhs = gimple_cond_rhs (cond);
    2663              :         }
    2664     21009437 :       else if (gimple_code (stmt) == GIMPLE_ASSIGN
    2665     21009437 :                && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt))
    2666              :                   == tcc_comparison)
    2667              :         {
    2668      1165491 :           code = gimple_assign_rhs_code (stmt);
    2669      1165491 :           lhs = gimple_assign_rhs1 (stmt);
    2670      1165491 :           rhs = gimple_assign_rhs2 (stmt);
    2671              :         }
    2672              :       else
    2673     19843946 :         return p;
    2674              : 
    2675     11786798 :       if (!is_gimple_ip_invariant (rhs) && is_gimple_ip_invariant (lhs))
    2676              :         {
    2677          835 :           std::swap (lhs, rhs);
    2678          835 :           code = swap_tree_comparison (code);
    2679              :         }
    2680              : 
    2681     11786798 :       expr_eval_ops param_ops = NULL;
    2682     11786798 :       if (!is_gimple_ip_invariant (rhs)
    2683     11786798 :           || !decompose_param_expr (fbi, stmt, lhs, &base_index, &param_type,
    2684              :                                     &aggpos, &param_ops))
    2685     11632254 :         return p;
    2686              : 
    2687       154544 :       enum tree_code inverted_code
    2688       154544 :         = invert_tree_comparison (code, HONOR_NANS (lhs));
    2689       154544 :       if (inverted_code == ERROR_MARK)
    2690              :         {
    2691          452 :           vec_free (param_ops);
    2692          452 :           return p;
    2693              :         }
    2694              : 
    2695       154092 :       ipa_predicate p1
    2696       154092 :         = add_condition (summary, params_summary, base_index, param_type,
    2697              :                          &aggpos, code, rhs, param_ops);
    2698       154092 :       ipa_predicate p2
    2699       154092 :         = add_condition (summary, params_summary, base_index, param_type,
    2700              :                          &aggpos, inverted_code, rhs, param_ops);
    2701       154092 :       op_non_const = p1 & p2;
    2702       154092 :       vec_free (param_ops);
    2703       154092 :       if (gimple_code (stmt) == GIMPLE_ASSIGN
    2704       154092 :           && TREE_CODE (gimple_assign_lhs (stmt)) == SSA_NAME)
    2705        10605 :         nonconstant_names[SSA_NAME_VERSION (gimple_assign_lhs (stmt))]
    2706        10605 :           = op_non_const;
    2707       154092 :       return op_non_const;
    2708              :     }
    2709              : 
    2710     21044541 :   if (is_load)
    2711      4581896 :     op_non_const =
    2712      4581896 :       add_condition (summary, params_summary,
    2713              :                      base_index, param_type, &aggpos,
    2714              :                      ipa_predicate::changed, NULL_TREE);
    2715              :   else
    2716     16462645 :     op_non_const = false;
    2717     41280550 :   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    2718              :     {
    2719     20236009 :       tree parm = unmodified_parm (fbi, stmt, use, NULL);
    2720     20236009 :       int index;
    2721              : 
    2722     20236009 :       if (parm && (index = ipa_get_param_decl_index (fbi->info, parm)) >= 0)
    2723              :         {
    2724      9682770 :           if (index != base_index)
    2725      5816889 :             p = add_condition (summary, params_summary, index,
    2726      5816889 :                                TREE_TYPE (parm), NULL,
    2727              :                                ipa_predicate::changed, NULL_TREE);
    2728              :           else
    2729      3865881 :             continue;
    2730              :         }
    2731              :       else
    2732     10553239 :         p = nonconstant_names[SSA_NAME_VERSION (use)];
    2733     16370128 :       op_non_const = p.or_with (summary->conds, op_non_const);
    2734              :     }
    2735     21044541 :   if ((gimple_code (stmt) == GIMPLE_ASSIGN || gimple_code (stmt) == GIMPLE_CALL)
    2736     17718603 :       && gimple_op (stmt, 0)
    2737     38467933 :       && TREE_CODE (gimple_op (stmt, 0)) == SSA_NAME)
    2738     17423392 :     nonconstant_names[SSA_NAME_VERSION (gimple_op (stmt, 0))]
    2739     17423392 :       = op_non_const;
    2740     21044541 :   return op_non_const;
    2741              : }
    2742              : 
    2743              : struct record_modified_bb_info
    2744              : {
    2745              :   tree op;
    2746              :   bitmap bb_set;
    2747              :   gimple *stmt;
    2748              : };
    2749              : 
    2750              : /* Value is initialized in INIT_BB and used in USE_BB.  We want to compute
    2751              :    probability how often it changes between USE_BB.
    2752              :    INIT_BB->count/USE_BB->count is an estimate, but if INIT_BB
    2753              :    is in different loop nest, we can do better.
    2754              :    This is all just estimate.  In theory we look for minimal cut separating
    2755              :    INIT_BB and USE_BB, but we only want to anticipate loop invariant motion
    2756              :    anyway.  */
    2757              : 
    2758              : static basic_block
    2759     10722845 : get_minimal_bb (basic_block init_bb, basic_block use_bb)
    2760              : {
    2761     10722845 :   class loop *l = find_common_loop (init_bb->loop_father, use_bb->loop_father);
    2762     10722845 :   if (l && l->header->count < init_bb->count)
    2763       386018 :     return l->header;
    2764              :   return init_bb;
    2765              : }
    2766              : 
    2767              : /* Callback of walk_aliased_vdefs.  Records basic blocks where the value may be
    2768              :    set except for info->stmt.  */
    2769              : 
    2770              : static bool
    2771      4953125 : record_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data)
    2772              : {
    2773      4953125 :   struct record_modified_bb_info *info =
    2774              :     (struct record_modified_bb_info *) data;
    2775      4953125 :   if (SSA_NAME_DEF_STMT (vdef) == info->stmt)
    2776              :     return false;
    2777      4925062 :   if (gimple_clobber_p (SSA_NAME_DEF_STMT (vdef)))
    2778              :     return false;
    2779      4875630 :   bitmap_set_bit (info->bb_set,
    2780      4875630 :                   SSA_NAME_IS_DEFAULT_DEF (vdef)
    2781            0 :                   ? ENTRY_BLOCK_PTR_FOR_FN (cfun)->index
    2782              :                   : get_minimal_bb
    2783      4875630 :                          (gimple_bb (SSA_NAME_DEF_STMT (vdef)),
    2784      4875630 :                           gimple_bb (info->stmt))->index);
    2785      4875630 :   if (dump_file)
    2786              :     {
    2787            0 :       fprintf (dump_file, "     Param ");
    2788            0 :       print_generic_expr (dump_file, info->op, TDF_SLIM);
    2789            0 :       fprintf (dump_file, " changed at bb %i, minimal: %i stmt: ",
    2790            0 :                gimple_bb (SSA_NAME_DEF_STMT (vdef))->index,
    2791              :                get_minimal_bb
    2792            0 :                          (gimple_bb (SSA_NAME_DEF_STMT (vdef)),
    2793            0 :                           gimple_bb (info->stmt))->index);
    2794            0 :       print_gimple_stmt (dump_file, SSA_NAME_DEF_STMT (vdef), 0);
    2795              :     }
    2796              :   return false;
    2797              : }
    2798              : 
    2799              : /* Return probability (based on REG_BR_PROB_BASE) that I-th parameter of STMT
    2800              :    will change since last invocation of STMT.
    2801              : 
    2802              :    Value 0 is reserved for compile time invariants.
    2803              :    For common parameters it is REG_BR_PROB_BASE.  For loop invariants it
    2804              :    ought to be REG_BR_PROB_BASE / estimated_iters.  */
    2805              : 
    2806              : static int
    2807     39888211 : param_change_prob (ipa_func_body_info *fbi, gimple *stmt, int i)
    2808              : {
    2809     39888211 :   tree op = gimple_call_arg (stmt, i);
    2810     39888211 :   basic_block bb = gimple_bb (stmt);
    2811              : 
    2812     39888211 :   if (TREE_CODE (op) == WITH_SIZE_EXPR)
    2813          299 :     op = TREE_OPERAND (op, 0);
    2814              : 
    2815     39888211 :   tree base = get_base_address (op);
    2816              : 
    2817              :   /* Global invariants never change.  */
    2818     39888211 :   if (is_gimple_min_invariant (base))
    2819              :     return 0;
    2820              : 
    2821              :   /* We would have to do non-trivial analysis to really work out what
    2822              :      is the probability of value to change (i.e. when init statement
    2823              :      is in a sibling loop of the call).
    2824              : 
    2825              :      We do an conservative estimate: when call is executed N times more often
    2826              :      than the statement defining value, we take the frequency 1/N.  */
    2827     19938580 :   if (TREE_CODE (base) == SSA_NAME)
    2828              :     {
    2829     17527899 :       profile_count init_count;
    2830              : 
    2831     26902674 :       if (!bb->count.nonzero_p ())
    2832              :         return REG_BR_PROB_BASE;
    2833              : 
    2834      8947394 :       if (SSA_NAME_IS_DEFAULT_DEF (base))
    2835      3100179 :         init_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2836              :       else
    2837      5847215 :         init_count = get_minimal_bb
    2838      5847215 :                       (gimple_bb (SSA_NAME_DEF_STMT (base)),
    2839              :                        gimple_bb (stmt))->count;
    2840              : 
    2841      8947394 :       if (init_count < bb->count)
    2842       466931 :         return MAX ((init_count.to_sreal_scale (bb->count)
    2843              :                      * REG_BR_PROB_BASE).to_int (), 1);
    2844              :       return REG_BR_PROB_BASE;
    2845              :     }
    2846              :   else
    2847              :     {
    2848      2410681 :       ao_ref refd;
    2849      2410681 :       profile_count max = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    2850      2410681 :       struct record_modified_bb_info info;
    2851      2410681 :       tree init = ctor_for_folding (base);
    2852              : 
    2853      2410681 :       if (init != error_mark_node)
    2854              :         return 0;
    2855      5380281 :       if (!bb->count.nonzero_p () || fbi->aa_walk_budget == 0)
    2856              :         return REG_BR_PROB_BASE;
    2857      1472531 :       if (dump_file)
    2858              :         {
    2859            0 :           fprintf (dump_file, "     Analyzing param change probability of ");
    2860            0 :           print_generic_expr (dump_file, op, TDF_SLIM);
    2861            0 :           fprintf (dump_file, "\n");
    2862              :         }
    2863      1472531 :       ao_ref_init (&refd, op);
    2864      1472531 :       info.op = op;
    2865      1472531 :       info.stmt = stmt;
    2866      1472531 :       info.bb_set = BITMAP_ALLOC (NULL);
    2867      1472531 :       int walked
    2868      2945062 :         = walk_aliased_vdefs (&refd, gimple_vuse (stmt), record_modified, &info,
    2869              :                               NULL, NULL, fbi->aa_walk_budget);
    2870      1472531 :       if (walked > 0)
    2871      1337118 :         fbi->aa_walk_budget -= walked;
    2872      1472531 :       if (walked < 0 || bitmap_bit_p (info.bb_set, bb->index))
    2873              :         {
    2874       892904 :           if (walked < 0)
    2875          212 :             fbi->aa_walk_budget = 0;
    2876       892904 :           if (dump_file)
    2877              :             {
    2878            0 :               if (walked < 0)
    2879            0 :                 fprintf (dump_file, "     Ran out of AA walking budget.\n");
    2880              :               else
    2881            0 :                 fprintf (dump_file, "     Set in same BB as used.\n");
    2882              :             }
    2883       892904 :           BITMAP_FREE (info.bb_set);
    2884       892904 :           return REG_BR_PROB_BASE;
    2885              :         }
    2886              : 
    2887       579627 :       bitmap_iterator bi;
    2888       579627 :       unsigned index;
    2889              :       /* Lookup the most frequent update of the value and believe that
    2890              :          it dominates all the other; precise analysis here is difficult.  */
    2891      1621343 :       EXECUTE_IF_SET_IN_BITMAP (info.bb_set, 0, index, bi)
    2892      1041716 :         max = profile_count::max_prefer_initialized
    2893      1041716 :                 (max, BASIC_BLOCK_FOR_FN (cfun, index)->count);
    2894       579627 :       if (dump_file)
    2895              :         {
    2896            0 :           fprintf (dump_file, "     Set with count ");
    2897            0 :           max.dump (dump_file);
    2898            0 :           fprintf (dump_file, " and used with count ");
    2899            0 :           bb->count.dump (dump_file);
    2900            0 :           fprintf (dump_file, " freq %f\n",
    2901            0 :                    max.to_sreal_scale (bb->count).to_double ());
    2902              :         }
    2903              : 
    2904       579627 :       BITMAP_FREE (info.bb_set);
    2905       579627 :       if (max < bb->count)
    2906       101662 :         return MAX ((max.to_sreal_scale (bb->count)
    2907              :                      * REG_BR_PROB_BASE).to_int (), 1);
    2908              :       return REG_BR_PROB_BASE;
    2909              :     }
    2910              : }
    2911              : 
    2912              : /* Find whether a basic block BB is the final block of a (half) diamond or
    2913              :    switch CFG sub-graph and if the predicate the condition depends on is known.
    2914              :    If so, return true and store the predicate in *P.  */
    2915              : 
    2916              : static bool
    2917      6558834 : phi_result_unknown_predicate (ipa_func_body_info *fbi,
    2918              :                               ipa_fn_summary *summary,
    2919              :                               class ipa_node_params *params_summary,
    2920              :                               basic_block bb,
    2921              :                               ipa_predicate *p,
    2922              :                               vec<ipa_predicate> nonconstant_names)
    2923              : {
    2924      6558834 :   edge e;
    2925      6558834 :   edge_iterator ei;
    2926      6558834 :   basic_block first_bb = NULL;
    2927              : 
    2928      6558834 :   if (single_pred_p (bb))
    2929              :     {
    2930        82588 :       *p = false;
    2931        82588 :       return true;
    2932              :     }
    2933              : 
    2934     14891642 :   FOR_EACH_EDGE (e, ei, bb->preds)
    2935              :     {
    2936     12753411 :       if (single_succ_p (e->src))
    2937              :         {
    2938      8545792 :           if (!single_pred_p (e->src))
    2939              :             return false;
    2940      7503112 :           if (!first_bb)
    2941      3304188 :             first_bb = single_pred (e->src);
    2942      4198924 :           else if (single_pred (e->src) != first_bb)
    2943              :             return false;
    2944              :         }
    2945              :       else
    2946              :         {
    2947      4207619 :           if (!first_bb)
    2948              :             first_bb = e->src;
    2949      1473668 :           else if (e->src != first_bb)
    2950              :             return false;
    2951              :         }
    2952              :     }
    2953              : 
    2954      2138231 :   if (!first_bb)
    2955              :     return false;
    2956              : 
    2957      2138231 :   gimple *stmt = *gsi_last_bb (first_bb);
    2958      2138231 :   if (!stmt
    2959      2138231 :       || (gimple_code (stmt) != GIMPLE_COND
    2960        45722 :           && gimple_code (stmt) != GIMPLE_SWITCH))
    2961              :     return false;
    2962              : 
    2963      2133652 :   *p = will_be_nonconstant_predicate (fbi, summary, params_summary,
    2964              :                                       stmt, nonconstant_names);
    2965      2133652 :   if (*p == true)
    2966              :     return false;
    2967              :   else
    2968       787883 :     return true;
    2969              : }
    2970              : 
    2971              : /* Given a PHI statement in a function described by inline properties SUMMARY
    2972              :    and *P being the predicate describing whether the selected PHI argument is
    2973              :    known, store a predicate for the result of the PHI statement into
    2974              :    NONCONSTANT_NAMES, if possible.  */
    2975              : 
    2976              : static void
    2977      1027022 : predicate_for_phi_result (class ipa_fn_summary *summary, gphi *phi,
    2978              :                           ipa_predicate *p,
    2979              :                           vec<ipa_predicate> nonconstant_names)
    2980              : {
    2981      1027022 :   unsigned i;
    2982              : 
    2983      1590225 :   for (i = 0; i < gimple_phi_num_args (phi); i++)
    2984              :     {
    2985      1324206 :       tree arg = gimple_phi_arg (phi, i)->def;
    2986      1324206 :       if (!is_gimple_min_invariant (arg))
    2987              :         {
    2988      1096384 :           gcc_assert (TREE_CODE (arg) == SSA_NAME);
    2989      2192768 :           *p = p->or_with (summary->conds,
    2990      1096384 :                            nonconstant_names[SSA_NAME_VERSION (arg)]);
    2991      1096384 :           if (*p == true)
    2992              :             return;
    2993              :         }
    2994              :     }
    2995              : 
    2996       266019 :   if (dump_file && (dump_flags & TDF_DETAILS))
    2997              :     {
    2998            6 :       fprintf (dump_file, "\t\tphi predicate: ");
    2999            6 :       p->dump (dump_file, summary->conds);
    3000              :     }
    3001       266019 :   nonconstant_names[SSA_NAME_VERSION (gimple_phi_result (phi))] = *p;
    3002              : }
    3003              : 
    3004              : /* For a typical usage of __builtin_expect (a<b, 1), we
    3005              :    may introduce an extra relation stmt:
    3006              :    With the builtin, we have
    3007              :      t1 = a <= b;
    3008              :      t2 = (long int) t1;
    3009              :      t3 = __builtin_expect (t2, 1);
    3010              :      if (t3 != 0)
    3011              :        goto ...
    3012              :    Without the builtin, we have
    3013              :      if (a<=b)
    3014              :        goto...
    3015              :    This affects the size/time estimation and may have
    3016              :    an impact on the earlier inlining.
    3017              :    Here find this pattern and fix it up later.  */
    3018              : 
    3019              : static gimple *
    3020     42409283 : find_foldable_builtin_expect (basic_block bb)
    3021              : {
    3022     42409283 :   gimple_stmt_iterator bsi;
    3023              : 
    3024    297630225 :   for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
    3025              :     {
    3026    212995718 :       gimple *stmt = gsi_stmt (bsi);
    3027    212995718 :       if (gimple_call_builtin_p (stmt, BUILT_IN_EXPECT)
    3028    212760360 :           || gimple_call_builtin_p (stmt, BUILT_IN_EXPECT_WITH_PROBABILITY)
    3029    425756001 :           || gimple_call_internal_p (stmt, IFN_BUILTIN_EXPECT))
    3030              :         {
    3031       373409 :           tree var = gimple_call_lhs (stmt);
    3032       373409 :           tree arg = gimple_call_arg (stmt, 0);
    3033       373409 :           use_operand_p use_p;
    3034       373409 :           gimple *use_stmt;
    3035       373409 :           bool match = false;
    3036       373409 :           bool done = false;
    3037              : 
    3038       373409 :           if (!var || !arg)
    3039            3 :             continue;
    3040       373406 :           gcc_assert (TREE_CODE (var) == SSA_NAME);
    3041              : 
    3042       745429 :           while (TREE_CODE (arg) == SSA_NAME)
    3043              :             {
    3044       745429 :               auto *stmt_tmp = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (arg));
    3045       738084 :               if (!stmt_tmp)
    3046              :                 break;
    3047       745176 :               switch (gimple_assign_rhs_code (stmt_tmp))
    3048              :                 {
    3049              :                   case LT_EXPR:
    3050              :                   case LE_EXPR:
    3051              :                   case GT_EXPR:
    3052              :                   case GE_EXPR:
    3053              :                   case EQ_EXPR:
    3054              :                   case NE_EXPR:
    3055              :                     match = true;
    3056              :                     done = true;
    3057              :                     break;
    3058              :                   CASE_CONVERT:
    3059              :                     break;
    3060              :                   default:
    3061              :                     done = true;
    3062              :                     break;
    3063              :                 }
    3064       372023 :               if (done)
    3065              :                 break;
    3066       372023 :               arg = gimple_assign_rhs1 (stmt_tmp);
    3067              :             }
    3068              : 
    3069       333406 :           if (match && single_imm_use (var, &use_p, &use_stmt)
    3070       706494 :               && gimple_code (use_stmt) == GIMPLE_COND)
    3071       184059 :             return use_stmt;
    3072              :         }
    3073              :     }
    3074              :   return NULL;
    3075              : }
    3076              : 
    3077              : /* Return true when the basic blocks contains only clobbers followed by RESX.
    3078              :    Such BBs are kept around to make removal of dead stores possible with
    3079              :    presence of EH and will be optimized out by optimize_clobbers later in the
    3080              :    game.
    3081              : 
    3082              :    NEED_EH is used to recurse in case the clobber has non-EH predecessors
    3083              :    that can be clobber only, too.. When it is false, the RESX is not necessary
    3084              :    on the end of basic block.  */
    3085              : 
    3086              : static bool
    3087     43062175 : clobber_only_eh_bb_p (basic_block bb, bool need_eh = true)
    3088              : {
    3089     43062175 :   gimple_stmt_iterator gsi = gsi_last_bb (bb);
    3090     43062175 :   edge_iterator ei;
    3091     43062175 :   edge e;
    3092              : 
    3093     43062175 :   if (need_eh)
    3094              :     {
    3095     42987943 :       if (gsi_end_p (gsi))
    3096              :         return false;
    3097     41822421 :       if (gimple_code (gsi_stmt (gsi)) != GIMPLE_RESX)
    3098              :         return false;
    3099      1163774 :       gsi_prev (&gsi);
    3100              :     }
    3101        74232 :   else if (!single_succ_p (bb))
    3102              :     return false;
    3103              : 
    3104      3069631 :   for (; !gsi_end_p (gsi); gsi_prev (&gsi))
    3105              :     {
    3106      2988872 :       gimple *stmt = gsi_stmt (gsi);
    3107      2988872 :       if (is_gimple_debug (stmt))
    3108      1004575 :         continue;
    3109      1984297 :       if (gimple_clobber_p (stmt))
    3110       942283 :         continue;
    3111      1042014 :       if (gimple_code (stmt) == GIMPLE_LABEL)
    3112              :         break;
    3113              :       return false;
    3114              :     }
    3115              : 
    3116              :   /* See if all predecessors are either throws or clobber only BBs.  */
    3117      3149514 :   FOR_EACH_EDGE (e, ei, bb->preds)
    3118      2569405 :     if (!(e->flags & EDGE_EH)
    3119      2569405 :         && !clobber_only_eh_bb_p (e->src, false))
    3120              :       return false;
    3121              : 
    3122              :   return true;
    3123              : }
    3124              : 
    3125              : /* Return true if STMT compute a floating point expression that may be affected
    3126              :    by -ffast-math and similar flags.  */
    3127              : 
    3128              : static bool
    3129     97511532 : fp_expression_p (gimple *stmt)
    3130              : {
    3131     97511532 :   ssa_op_iter i;
    3132     97511532 :   tree op;
    3133              : 
    3134    218763165 :   FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_DEF|SSA_OP_USE)
    3135    121878377 :     if (FLOAT_TYPE_P (TREE_TYPE (op)))
    3136              :       return true;
    3137              :   return false;
    3138              : }
    3139              : 
    3140              : /* Return true if T references memory location that is local
    3141              :    for the function (that means, dead after return) or read-only.  */
    3142              : 
    3143              : bool
    3144     61379478 : refs_local_or_readonly_memory_p (tree t)
    3145              : {
    3146              :   /* Non-escaping memory is fine.  */
    3147     61379478 :   t = get_base_address (t);
    3148     61379478 :   if ((TREE_CODE (t) == MEM_REF
    3149     61379478 :       || TREE_CODE (t) == TARGET_MEM_REF))
    3150     25983991 :     return points_to_local_or_readonly_memory_p (TREE_OPERAND (t, 0));
    3151              : 
    3152              :   /* Automatic variables are fine.  */
    3153     35395487 :   if (DECL_P (t)
    3154     35395487 :       && auto_var_in_fn_p (t, current_function_decl))
    3155              :     return true;
    3156              : 
    3157              :   /* Read-only variables and constants are fine.  */
    3158     11394582 :   if (CONSTANT_CLASS_P (t))
    3159              :     return true;
    3160      7846905 :   if (DECL_P (t) && TREE_READONLY (t))
    3161      1687716 :     return true;
    3162              : 
    3163              :   return false;
    3164              : }
    3165              : 
    3166              : /* Return true if T is a pointer pointing to memory location that is local
    3167              :    for the function (that means, dead after return) or read-only.  */
    3168              : 
    3169              : bool
    3170     74588303 : points_to_local_or_readonly_memory_p (tree t)
    3171              : {
    3172              :   /* See if memory location is clearly invalid.  */
    3173     74588303 :   if (integer_zerop (t))
    3174      2503204 :     return flag_delete_null_pointer_checks;
    3175     72085099 :   if (TREE_CODE (t) == SSA_NAME)
    3176              :     {
    3177              :       /* For IPA passes we can consinder accesses to return slot local
    3178              :          even if it is not local in the sense that memory is dead by
    3179              :          the end of founction.
    3180              :          The outer function will see a store in the call assignment
    3181              :          and thus this will do right thing for all uses of this
    3182              :          function in the current IPA passes (modref, pure/const discovery
    3183              :          and inlining heuristics).  */
    3184     45706551 :       if (DECL_RESULT (current_function_decl)
    3185     45706551 :           && DECL_BY_REFERENCE (DECL_RESULT (current_function_decl))
    3186     46824310 :           && t == ssa_default_def (cfun, DECL_RESULT (current_function_decl)))
    3187              :         return true;
    3188     45383224 :       return !ptr_deref_may_alias_global_p (t, false);
    3189              :     }
    3190     26378548 :   if (TREE_CODE (t) == ADDR_EXPR
    3191     26378548 :       && (TREE_CODE (TREE_OPERAND (t, 0)) != TARGET_MEM_REF
    3192         4407 :           || TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)) != INTEGER_CST))
    3193     13588232 :     return refs_local_or_readonly_memory_p (TREE_OPERAND (t, 0));
    3194              :   return false;
    3195              : }
    3196              : 
    3197              : /* Return true if T is a pointer pointing to memory location that is possible
    3198              :    sra candidate if all functions it is passed to are inlined.  */
    3199              : 
    3200              : static bool
    3201     39888211 : points_to_possible_sra_candidate_p (tree t)
    3202              : {
    3203     39888211 :   if (TREE_CODE (t) != ADDR_EXPR)
    3204              :     return false;
    3205              : 
    3206     11956812 :   t = get_base_address (TREE_OPERAND (t, 0));
    3207              : 
    3208              :   /* Automatic variables are fine.  */
    3209     11956812 :   if (DECL_P (t)
    3210     11956812 :       && auto_var_in_fn_p (t, current_function_decl))
    3211              :     return true;
    3212              :   return false;
    3213              : }
    3214              : 
    3215              : /* Return true if BB only calls builtin_unreachable.
    3216              :    We skip empty basic blocks, debug statements, clobbers and predicts.
    3217              :    CACHE is used to memoize already analyzed blocks.  */
    3218              : 
    3219              : static bool
    3220     28186252 : builtin_unreachable_bb_p (basic_block bb, vec<unsigned char> &cache)
    3221              : {
    3222     28186252 :   if (cache[bb->index])
    3223      2782748 :     return cache[bb->index] - 1;
    3224     25403504 :   gimple_stmt_iterator si;
    3225     25403504 :   auto_vec <basic_block, 4> visited_bbs;
    3226     25403504 :   bool ret = false;
    3227     26230138 :   while (true)
    3228              :     {
    3229     26230138 :       bool empty_bb = true;
    3230     26230138 :       visited_bbs.safe_push (bb);
    3231     26230138 :       cache[bb->index] = 3;
    3232     26230138 :       for (si = gsi_start_nondebug_bb (bb);
    3233     27759640 :            !gsi_end_p (si) && empty_bb;
    3234      1529502 :            gsi_next_nondebug (&si))
    3235              :         {
    3236     26369708 :           if (gimple_code (gsi_stmt (si)) != GIMPLE_PREDICT
    3237     26000105 :               && !gimple_clobber_p (gsi_stmt (si))
    3238     51243670 :               && !gimple_nop_p (gsi_stmt (si)))
    3239              :             {
    3240              :               empty_bb = false;
    3241              :               break;
    3242              :             }
    3243              :         }
    3244     26230138 :       if (!empty_bb)
    3245              :         break;
    3246              :       else
    3247      1389932 :         bb = single_succ_edge (bb)->dest;
    3248      1389932 :       if (cache[bb->index])
    3249              :         {
    3250       563298 :           ret = cache[bb->index] == 3 ? false : cache[bb->index] - 1;
    3251       563298 :           goto done;
    3252              :         }
    3253              :     }
    3254     24840206 :   if (gimple_call_builtin_p (gsi_stmt (si), BUILT_IN_UNREACHABLE)
    3255     24840206 :       || gimple_call_builtin_p (gsi_stmt (si), BUILT_IN_UNREACHABLE_TRAP))
    3256              :     ret = true;
    3257     25403504 : done:
    3258    102440650 :   for (basic_block vbb:visited_bbs)
    3259     26230138 :     cache[vbb->index] = (unsigned char)ret + 1;
    3260     25403504 :   return ret;
    3261     25403504 : }
    3262              : 
    3263              : static bool
    3264     14217127 : guards_builtin_unreachable (basic_block bb, vec<unsigned char> &cache)
    3265              : {
    3266     14217127 :   edge_iterator ei;
    3267     14217127 :   edge e;
    3268     42141005 :   FOR_EACH_EDGE (e, ei, bb->succs)
    3269     28186252 :     if (builtin_unreachable_bb_p (e->dest, cache))
    3270              :       {
    3271       262374 :         if (dump_file && (dump_flags & TDF_DETAILS))
    3272            1 :           fprintf (dump_file,
    3273              :                    "BB %i ends with conditional guarding __builtin_unreachable;"
    3274              :                    " conditinal is unnecessary\n", bb->index);
    3275              :         return true;
    3276              :       }
    3277              :   return false;
    3278              : }
    3279              : 
    3280              : #define STMT_NECESSARY GF_PLF_1
    3281              : 
    3282              : /* If STMT is not already marked necessary, mark it, and add it to the
    3283              :    worklist if ADD_TO_WORKLIST is true.  */
    3284              : 
    3285              : static inline void
    3286    178134762 : mark_stmt_necessary (gimple *stmt, auto_vec<gimple *> &worklist)
    3287              : {
    3288    178134762 :   gcc_assert (stmt);
    3289              : 
    3290    178134762 :   if (gimple_plf (stmt, STMT_NECESSARY))
    3291              :     return;
    3292              : 
    3293    147847904 :   if (dump_file && (dump_flags & TDF_DETAILS))
    3294              :     {
    3295          769 :       fprintf (dump_file, "Marking useful stmt: ");
    3296          769 :       print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
    3297          769 :       fprintf (dump_file, "\n");
    3298              :     }
    3299              : 
    3300    147847904 :   gimple_set_plf (stmt, STMT_NECESSARY, true);
    3301    147847904 :   worklist.safe_push (stmt);
    3302              : }
    3303              : 
    3304              : /* Mark the statement defining operand OP as necessary.  */
    3305              : 
    3306              : static inline void
    3307    125228990 : mark_operand_necessary (tree op, auto_vec<gimple *> &worklist)
    3308              : {
    3309    125228990 :   gimple *stmt = SSA_NAME_DEF_STMT (op);
    3310    125228990 :   if (gimple_nop_p (stmt))
    3311              :     return;
    3312    101637933 :   mark_stmt_necessary (stmt, worklist);
    3313              : }
    3314              : 
    3315              : /* Mark all statements that will remain in the body after optimizing out
    3316              :    conditionals guarding __builtin_unreachable which we keep to preserve
    3317              :    value ranges.  */
    3318              : 
    3319              : static void
    3320      7478469 : find_necessary_statements (struct cgraph_node *node)
    3321              : {
    3322      7478469 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    3323      7478469 :   auto_vec<unsigned char, 10> cache;
    3324      7478469 :   basic_block bb;
    3325      7478469 :   auto_vec<gimple *> worklist;
    3326              : 
    3327      7478469 :   cache.safe_grow_cleared (last_basic_block_for_fn (cfun));
    3328              :   /* Mark all obviously necessary statements.  */
    3329     50466412 :   FOR_EACH_BB_FN (bb, my_function)
    3330              :     {
    3331     42987943 :       for (gimple_stmt_iterator gsi = gsi_start_phis (bb);
    3332     54985876 :            !gsi_end_p (gsi); gsi_next (&gsi))
    3333     11997933 :         gimple_set_plf (gsi_stmt (gsi), STMT_NECESSARY, false);
    3334              : 
    3335    241119305 :       for (gimple_stmt_iterator bsi = gsi_start_bb (bb); !gsi_end_p (bsi);
    3336    155143419 :            gsi_next_nondebug (&bsi))
    3337              :         {
    3338    155143419 :           gimple *stmt = gsi_stmt (bsi);
    3339              : 
    3340    155143419 :           gimple_set_plf (stmt, STMT_NECESSARY, false);
    3341    155143419 :           if (gimple_has_side_effects (stmt)
    3342    126924826 :               || (is_ctrl_stmt (stmt)
    3343     22794701 :                   && (gimple_code (stmt) != GIMPLE_COND
    3344     14217127 :                       || !guards_builtin_unreachable (bb, cache)))
    3345    104392499 :               || gimple_store_p (stmt)
    3346    233811750 :               || gimple_code (stmt) == GIMPLE_ASM)
    3347     76496829 :             mark_stmt_necessary (stmt, worklist);
    3348              :         }
    3349              :     }
    3350    155326373 :   while (worklist.length () > 0)
    3351              :     {
    3352    147847904 :       gimple *stmt = worklist.pop ();
    3353              : 
    3354    147847904 :       if (dump_file && (dump_flags & TDF_DETAILS))
    3355              :         {
    3356          769 :           fprintf (dump_file, "processing: ");
    3357          769 :           print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
    3358          769 :           fprintf (dump_file, "\n");
    3359              :         }
    3360    147847904 :       if (gimple_code (stmt) == GIMPLE_PHI)
    3361     19027837 :         for (unsigned int k = 0; k < gimple_phi_num_args (stmt); k++)
    3362              :           {
    3363     13459902 :             tree arg = PHI_ARG_DEF (stmt, k);
    3364              : 
    3365     13459902 :             if (TREE_CODE (arg) == SSA_NAME)
    3366     10315026 :               mark_operand_necessary (arg, worklist);
    3367              :           }
    3368              :       else
    3369              :         {
    3370    142279969 :           ssa_op_iter iter;
    3371    142279969 :           tree use;
    3372              : 
    3373    257193933 :           FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
    3374    114913964 :             mark_operand_necessary (use, worklist);
    3375              :         }
    3376              :     }
    3377      7478469 : }
    3378              : 
    3379              : /* Analyze function body for NODE.
    3380              :    EARLY indicates run from early optimization pipeline.  */
    3381              : 
    3382              : static void
    3383      7478469 : analyze_function_body (struct cgraph_node *node, bool early)
    3384              : {
    3385      7478469 :   sreal time = opt_for_fn (node->decl, param_uninlined_function_time);
    3386              :   /* Estimate static overhead for function prologue/epilogue and alignment. */
    3387      7478469 :   int size = opt_for_fn (node->decl, param_uninlined_function_insns);
    3388              :   /* Benefits are scaled by probability of elimination that is in range
    3389              :      <0,2>.  */
    3390      7478469 :   basic_block bb;
    3391      7478469 :   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
    3392      7478469 :   sreal freq;
    3393      7478469 :   class ipa_fn_summary *info = ipa_fn_summaries->get_create (node);
    3394      7478469 :   ipa_node_params *params_summary
    3395      7478469 :     = early ? NULL : ipa_node_params_sum->get (node);
    3396      7478469 :   ipa_predicate bb_predicate;
    3397      7478469 :   struct ipa_func_body_info fbi;
    3398      7478469 :   vec<ipa_predicate> nonconstant_names = vNULL;
    3399      7478469 :   int nblocks, n;
    3400      7478469 :   int *order;
    3401      7478469 :   gimple *fix_builtin_expect_stmt;
    3402              : 
    3403      7478469 :   gcc_assert (my_function && my_function->cfg);
    3404      7478469 :   gcc_assert (cfun == my_function);
    3405              : 
    3406      7478469 :   memset(&fbi, 0, sizeof(fbi));
    3407      7478469 :   vec_free (info->conds);
    3408      7478469 :   info->conds = NULL;
    3409      7478469 :   info->size_time_table.release ();
    3410      7478469 :   info->call_size_time_table.release ();
    3411              : 
    3412              :   /* When optimizing and analyzing for IPA inliner, initialize loop optimizer
    3413              :      so we can produce proper inline hints.
    3414              : 
    3415              :      When optimizing and analyzing for early inliner, initialize node params
    3416              :      so we can produce correct BB predicates.  */
    3417              : 
    3418      7478469 :   if (opt_for_fn (node->decl, optimize))
    3419              :     {
    3420      6526878 :       calculate_dominance_info (CDI_DOMINATORS);
    3421      6526878 :       calculate_dominance_info (CDI_POST_DOMINATORS);
    3422      6526878 :       if (!early)
    3423      1420277 :         loop_optimizer_init (LOOPS_NORMAL | LOOPS_HAVE_RECORDED_EXITS);
    3424              :       else
    3425              :         {
    3426      5106601 :           ipa_check_create_node_params ();
    3427      5106601 :           ipa_initialize_node_params (node);
    3428              :         }
    3429              : 
    3430      6526878 :       if (ipa_node_params_sum)
    3431              :         {
    3432      6526878 :           fbi.node = node;
    3433      6526878 :           fbi.info = ipa_node_params_sum->get (node);
    3434      6526878 :           fbi.bb_infos = vNULL;
    3435      6526878 :           fbi.bb_infos.safe_grow_cleared (last_basic_block_for_fn (cfun), true);
    3436      6526878 :           fbi.param_count = count_formal_params (node->decl);
    3437      6526878 :           fbi.aa_walk_budget = opt_for_fn (node->decl, param_ipa_max_aa_steps);
    3438              : 
    3439      6526878 :           nonconstant_names.safe_grow_cleared
    3440      6526878 :             (SSANAMES (my_function)->length (), true);
    3441              :         }
    3442              :     }
    3443              : 
    3444      7478469 :   if (dump_file)
    3445          294 :     fprintf (dump_file, "\nAnalyzing function body size: %s\n",
    3446              :              node->dump_name ());
    3447              : 
    3448              :   /* When we run into maximal number of entries, we assign everything to the
    3449              :      constant truth case.  Be sure to have it in list. */
    3450      7478469 :   bb_predicate = true;
    3451      7478469 :   info->account_size_time (0, 0, bb_predicate, bb_predicate);
    3452              : 
    3453      7478469 :   bb_predicate = ipa_predicate::not_inlined ();
    3454      7478469 :   info->account_size_time (opt_for_fn (node->decl,
    3455              :                                 param_uninlined_function_insns)
    3456              :                            * ipa_fn_summary::size_scale,
    3457      7478469 :                            opt_for_fn (node->decl,
    3458              :                                 param_uninlined_function_time),
    3459              :                            bb_predicate,
    3460              :                            bb_predicate);
    3461              : 
    3462              :   /* Only look for target information for inlinable functions.  */
    3463      7478469 :   bool scan_for_target_info =
    3464      7478469 :     info->inlinable
    3465     13429419 :     && targetm.target_option.need_ipa_fn_target_info (node->decl,
    3466      5950950 :                                                       info->target_info);
    3467              : 
    3468      7478469 :   if (fbi.info)
    3469      6526878 :     compute_bb_predicates (&fbi, node, info, params_summary);
    3470      7478469 :   find_necessary_statements (node);
    3471      7478469 :   const profile_count entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    3472      7478469 :   order = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
    3473      7478469 :   nblocks = pre_and_rev_post_order_compute (NULL, order, false);
    3474     57944881 :   for (n = 0; n < nblocks; n++)
    3475              :     {
    3476     42987943 :       bb = BASIC_BLOCK_FOR_FN (cfun, order[n]);
    3477     42987943 :       freq = bb->count.to_sreal_scale (entry_count);
    3478     42987943 :       if (clobber_only_eh_bb_p (bb))
    3479              :         {
    3480       578660 :           if (dump_file && (dump_flags & TDF_DETAILS))
    3481            0 :             fprintf (dump_file, "\n Ignoring BB %i;"
    3482              :                      " it will be optimized away by cleanup_clobbers\n",
    3483              :                      bb->index);
    3484       578660 :           continue;
    3485              :         }
    3486              : 
    3487              :       /* TODO: Obviously predicates can be propagated down across CFG.  */
    3488     42409283 :       if (fbi.info)
    3489              :         {
    3490     35766297 :           if (bb->aux)
    3491     35766271 :             bb_predicate = *(ipa_predicate *)bb->aux;
    3492              :           else
    3493           26 :             bb_predicate = false;
    3494              :         }
    3495              :       else
    3496      6642986 :         bb_predicate = true;
    3497              : 
    3498     42409283 :       if (dump_file && (dump_flags & TDF_DETAILS))
    3499              :         {
    3500          321 :           fprintf (dump_file, "\n BB %i predicate:", bb->index);
    3501          321 :           bb_predicate.dump (dump_file, info->conds);
    3502              :         }
    3503              : 
    3504     42409283 :       if (fbi.info && nonconstant_names.exists ())
    3505              :         {
    3506     35766297 :           ipa_predicate phi_predicate;
    3507     35766297 :           bool first_phi = true;
    3508              : 
    3509     36793319 :           for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi);
    3510      1027022 :                gsi_next (&bsi))
    3511              :             {
    3512      6715385 :               if (first_phi
    3513      6715385 :                   && !phi_result_unknown_predicate (&fbi, info,
    3514              :                                                     params_summary,
    3515              :                                                     bb,
    3516              :                                                     &phi_predicate,
    3517              :                                                     nonconstant_names))
    3518              :                 break;
    3519      1027022 :               first_phi = false;
    3520      1027022 :               if (dump_file && (dump_flags & TDF_DETAILS))
    3521              :                 {
    3522           18 :                   fprintf (dump_file, "  ");
    3523           18 :                   print_gimple_stmt (dump_file, gsi_stmt (bsi), 0);
    3524              :                 }
    3525      1027022 :               predicate_for_phi_result (info, bsi.phi (), &phi_predicate,
    3526              :                                         nonconstant_names);
    3527              :             }
    3528              :         }
    3529              : 
    3530     42409283 :       fix_builtin_expect_stmt = find_foldable_builtin_expect (bb);
    3531              : 
    3532     42409283 :       for (gimple_stmt_iterator bsi = gsi_start_nondebug_bb (bb);
    3533    189126300 :            !gsi_end_p (bsi); gsi_next_nondebug (&bsi))
    3534              :         {
    3535    146717017 :           gimple *stmt = gsi_stmt (bsi);
    3536    146717017 :           if (!gimple_plf (stmt, STMT_NECESSARY))
    3537              :             {
    3538      5806510 :               if (dump_file && (dump_flags & TDF_DETAILS))
    3539              :                 {
    3540           39 :                   fprintf (dump_file, "  skipping unnecessary stmt ");
    3541           39 :                   print_gimple_stmt (dump_file, stmt, 0);
    3542              :                 }
    3543              :               /* TODO: const calls used only to produce values for
    3544              :                  builtion_unreachable guards should not be accounted.  However
    3545              :                  we still want to inline them and this does does not work well
    3546              :                  with the cost model.  For now account them as usual.  */
    3547      5806510 :               if (!is_gimple_call (stmt)
    3548      5806510 :                   || gimple_call_internal_p (stmt))
    3549      5527262 :                 continue;
    3550              :             }
    3551    141189755 :           int this_size = estimate_num_insns (stmt, &eni_size_weights);
    3552    141189755 :           int this_time = estimate_num_insns (stmt, &eni_time_weights);
    3553    141189755 :           int prob;
    3554    141189755 :           ipa_predicate will_be_nonconstant;
    3555              : 
    3556              :           /* This relation stmt should be folded after we remove
    3557              :              __builtin_expect call. Adjust the cost here.  */
    3558    141189755 :           if (stmt == fix_builtin_expect_stmt)
    3559              :             {
    3560       183621 :               this_size--;
    3561       183621 :               this_time--;
    3562              :             }
    3563              : 
    3564    141189755 :           if (dump_file && (dump_flags & TDF_DETAILS))
    3565              :             {
    3566          707 :               fprintf (dump_file, "  ");
    3567          707 :               print_gimple_stmt (dump_file, stmt, 0);
    3568          707 :               fprintf (dump_file, "\t\tfreq:%3.2f size:%3i time:%3i\n",
    3569              :                        freq.to_double (), this_size,
    3570              :                        this_time);
    3571              :             }
    3572              : 
    3573    141189755 :           struct cgraph_edge *edge;
    3574    141189755 :           if (is_gimple_call (stmt)
    3575     24828555 :               && (!gimple_call_internal_p (stmt)
    3576      1157980 :                   || gimple_call_internal_fn (stmt) == IFN_ASSUME)
    3577    164860954 :               && (edge = node->get_edge (stmt)))
    3578              :             {
    3579     23670786 :               ipa_call_summary *es = ipa_call_summaries->get_create (edge);
    3580              : 
    3581              :               /* Special case: results of BUILT_IN_CONSTANT_P will be always
    3582              :                  resolved as constant.  We however don't want to optimize
    3583              :                  out the cgraph edges.  */
    3584     23670786 :               if (nonconstant_names.exists ()
    3585     20680128 :                   && gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P)
    3586        48326 :                   && gimple_call_lhs (stmt)
    3587     23719112 :                   && TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME)
    3588              :                 {
    3589        48326 :                   ipa_predicate false_p = false;
    3590        48326 :                   nonconstant_names[SSA_NAME_VERSION (gimple_call_lhs (stmt))]
    3591        48326 :                     = false_p;
    3592              :                 }
    3593     23670786 :               if (ipa_node_params_sum)
    3594              :                 {
    3595     20692991 :                   int count = gimple_call_num_args (stmt);
    3596     20692991 :                   int i;
    3597              : 
    3598     20692991 :                   if (count)
    3599     17779293 :                     es->param.safe_grow_cleared (count, true);
    3600     60581202 :                   for (i = 0; i < count; i++)
    3601              :                     {
    3602     39888211 :                       int prob = param_change_prob (&fbi, stmt, i);
    3603     39888211 :                       gcc_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
    3604     39888211 :                       es->param[i].change_prob = prob;
    3605     39888211 :                       es->param[i].points_to_local_or_readonly_memory
    3606     39888211 :                          = points_to_local_or_readonly_memory_p
    3607     39888211 :                              (gimple_call_arg (stmt, i));
    3608     39888211 :                       es->param[i].points_to_possible_sra_candidate
    3609     39888211 :                          = points_to_possible_sra_candidate_p
    3610     39888211 :                              (gimple_call_arg (stmt, i));
    3611              :                     }
    3612              :                 }
    3613              :               /* We cannot setup VLA parameters during inlining.  */
    3614     69609103 :               for (unsigned int i = 0; i < gimple_call_num_args (stmt); ++i)
    3615     45938713 :                 if (TREE_CODE (gimple_call_arg (stmt, i)) == WITH_SIZE_EXPR)
    3616              :                   {
    3617          396 :                     edge->inline_failed = CIF_FUNCTION_NOT_INLINABLE;
    3618          396 :                     break;
    3619              :                   }
    3620     23670786 :               es->call_stmt_size = this_size;
    3621     23670786 :               es->call_stmt_time = this_time;
    3622     23670786 :               es->loop_depth = bb_loop_depth (bb);
    3623     23670786 :               edge_set_predicate (edge, &bb_predicate);
    3624     23670786 :               if (edge->speculative)
    3625              :                 {
    3626            0 :                   cgraph_edge *indirect
    3627            0 :                         = edge->speculative_call_indirect_edge ();
    3628            0 :                   ipa_call_summary *es2
    3629            0 :                          = ipa_call_summaries->get_create (indirect);
    3630            0 :                   ipa_call_summaries->duplicate (edge, indirect,
    3631              :                                                  es, es2);
    3632              : 
    3633              :                   /* Edge is the first direct call.
    3634              :                      create and duplicate call summaries for multiple
    3635              :                      speculative call targets.  */
    3636            0 :                   for (cgraph_edge *direct
    3637            0 :                          = edge->next_speculative_call_target ();
    3638            0 :                        direct;
    3639            0 :                        direct = direct->next_speculative_call_target ())
    3640              :                     {
    3641            0 :                       ipa_call_summary *es3
    3642            0 :                         = ipa_call_summaries->get_create (direct);
    3643            0 :                       ipa_call_summaries->duplicate (edge, direct,
    3644              :                                                      es, es3);
    3645              :                     }
    3646              :                 }
    3647              : 
    3648              :               /* If dealing with a carrying edge, copy its summary over to its
    3649              :                  attached edges as well.  */
    3650     23670786 :               if (edge->has_callback)
    3651              :                 {
    3652        15900 :                   cgraph_edge *cbe;
    3653        31801 :                   for (cbe = edge->first_callback_edge (); cbe;
    3654        15901 :                        cbe = cbe->next_callback_edge ())
    3655              :                     {
    3656        15901 :                       ipa_call_summary *es2 = ipa_call_summaries->get_create (cbe);
    3657        15901 :                       ipa_call_summaries->duplicate (edge, cbe, es, es2);
    3658              :                       /* Unlike speculative edges, callback edges have no real
    3659              :                          size or time; the call doesn't exist.  Reflect that in
    3660              :                          their summaries.  */
    3661        15901 :                       es2->call_stmt_size = 0;
    3662        15901 :                       es2->call_stmt_time = 0;
    3663              :                     }
    3664              :                 }
    3665              :               /* Internal calls are not in the callgraph, so edges pointing to
    3666              :                  .ASSUME bodies are not covered by the above branch, as the
    3667              :                  dispatching edge doesn't exist.  */
    3668     23654886 :               else if (edge->callback)
    3669              :                 {
    3670          211 :                   gcc_checking_assert (edge->callee->assume_function);
    3671          211 :                   es->call_stmt_size = 0;
    3672          211 :                   es->call_stmt_time = 0;
    3673              :                 }
    3674              :             }
    3675              : 
    3676              :           /* TODO: When conditional jump or switch is known to be constant, but
    3677              :              we did not translate it into the predicates, we really can account
    3678              :              just maximum of the possible paths.  */
    3679    141189755 :           if (fbi.info)
    3680    118318246 :             will_be_nonconstant
    3681    118318246 :               = will_be_nonconstant_predicate (&fbi, info, params_summary,
    3682              :                                                stmt, nonconstant_names);
    3683              :           else
    3684     22871509 :             will_be_nonconstant = true;
    3685    141189755 :           if (this_time || this_size)
    3686              :             {
    3687    115404192 :               sreal final_time = (sreal)this_time * freq;
    3688    115404192 :               prob = eliminated_by_inlining_prob (&fbi, stmt);
    3689    115404192 :               if (prob == 1 && dump_file && (dump_flags & TDF_DETAILS))
    3690           37 :                 fprintf (dump_file,
    3691              :                          "\t\t50%% will be eliminated by inlining\n");
    3692    115404192 :               if (prob == 2 && dump_file && (dump_flags & TDF_DETAILS))
    3693           70 :                 fprintf (dump_file, "\t\tWill be eliminated by inlining\n");
    3694              : 
    3695    115404192 :               ipa_predicate p = bb_predicate & will_be_nonconstant;
    3696    115404192 :               int parm = load_or_store_of_ptr_parameter (&fbi, stmt);
    3697    115404192 :               ipa_predicate sra_predicate = true;
    3698    115404192 :               if (parm != -1)
    3699     14641782 :                 sra_predicate &= add_condition (info, params_summary, parm,
    3700              :                                                 ptr_type_node, NULL,
    3701      7320891 :                                                 ipa_predicate::not_sra_candidate, NULL, 0);
    3702              : 
    3703              :               /* We can ignore statement when we proved it is never going
    3704              :                  to happen, but we cannot do that for call statements
    3705              :                  because edges are accounted specially.  */
    3706              : 
    3707    230808384 :               if (*(is_gimple_call (stmt) ? &bb_predicate : &p) != false)
    3708              :                 {
    3709    114542972 :                   time += final_time;
    3710    114542972 :                   size += this_size;
    3711              :                 }
    3712              : 
    3713              :               /* We account everything but the calls.  Calls have their own
    3714              :                  size/time info attached to cgraph edges.  This is necessary
    3715              :                  in order to make the cost disappear after inlining.  */
    3716    115404192 :               if (!is_gimple_call (stmt))
    3717              :                 {
    3718     92458117 :                   if (prob)
    3719              :                     {
    3720     15479895 :                       ipa_predicate ip
    3721     15479895 :                         = bb_predicate & ipa_predicate::not_inlined () & sra_predicate;
    3722     30959790 :                       info->account_size_time (this_size * prob,
    3723     15479895 :                                                (final_time * prob) / 2, ip,
    3724              :                                                p);
    3725              :                     }
    3726     15479895 :                   if (prob != 2)
    3727    170430018 :                     info->account_size_time (this_size * (2 - prob),
    3728     85215009 :                                              (final_time * (2 - prob) / 2),
    3729    170430018 :                                              bb_predicate & sra_predicate,
    3730              :                                              p);
    3731              :                 }
    3732              : 
    3733    115404192 :               if (!info->fp_expressions && fp_expression_p (stmt))
    3734              :                 {
    3735       626744 :                   info->fp_expressions = true;
    3736       626744 :                   if (dump_file)
    3737            9 :                     fprintf (dump_file, "   fp_expression set\n");
    3738              :                 }
    3739              :             }
    3740              : 
    3741              :           /* For target specific information, we want to scan all statements
    3742              :              rather than those statements with non-zero weights, to avoid
    3743              :              missing to scan something interesting for target information,
    3744              :              such as: internal function calls.  */
    3745    141189755 :           if (scan_for_target_info)
    3746            0 :             scan_for_target_info =
    3747            0 :               targetm.target_option.update_ipa_fn_target_info
    3748            0 :               (info->target_info, stmt);
    3749              : 
    3750              :           /* Account cost of address calculations in the statements.  */
    3751    545825218 :           for (unsigned int i = 0; i < gimple_num_ops (stmt); i++)
    3752              :             {
    3753    404635463 :               for (tree op = gimple_op (stmt, i);
    3754    779595846 :                    op && handled_component_p (op);
    3755     49254826 :                    op = TREE_OPERAND (op, 0))
    3756     49254826 :                 if ((TREE_CODE (op) == ARRAY_REF
    3757     49254826 :                      || TREE_CODE (op) == ARRAY_RANGE_REF)
    3758     49254826 :                     && TREE_CODE (TREE_OPERAND (op, 1)) == SSA_NAME)
    3759              :                   {
    3760      2471170 :                     ipa_predicate p = bb_predicate;
    3761      2471170 :                     if (fbi.info)
    3762      1941104 :                       p = p & will_be_nonconstant_expr_predicate
    3763      1941104 :                                  (&fbi, info, params_summary,
    3764      1941104 :                                   TREE_OPERAND (op, 1),
    3765      1941104 :                                   nonconstant_names);
    3766      2471170 :                     if (p != false)
    3767              :                       {
    3768      2464903 :                         time += freq;
    3769      2464903 :                         size += 1;
    3770      2464903 :                         if (dump_file)
    3771           40 :                           fprintf (dump_file,
    3772              :                                    "\t\tAccounting address calculation.\n");
    3773      2464903 :                         info->account_size_time (ipa_fn_summary::size_scale,
    3774              :                                                  freq,
    3775              :                                                  bb_predicate,
    3776              :                                                  p);
    3777              :                       }
    3778              :                   }
    3779              :             }
    3780              : 
    3781              :         }
    3782              :     }
    3783      7478469 :   free (order);
    3784              : 
    3785      7478469 :   if (nonconstant_names.exists () && !early)
    3786              :     {
    3787      1420277 :       ipa_fn_summary *s = ipa_fn_summaries->get (node);
    3788      1420277 :       unsigned max_loop_predicates = opt_for_fn (node->decl,
    3789              :                                                  param_ipa_max_loop_predicates);
    3790              : 
    3791      1420277 :       if (dump_file && (dump_flags & TDF_DETAILS))
    3792           61 :         flow_loops_dump (dump_file, NULL, 0);
    3793      1420277 :       scev_initialize ();
    3794      4908166 :       for (auto loop : loops_list (cfun, 0))
    3795              :         {
    3796       647335 :           ipa_predicate loop_iterations = true;
    3797       647335 :           sreal header_freq;
    3798       647335 :           edge ex;
    3799       647335 :           unsigned int j;
    3800       647335 :           class tree_niter_desc niter_desc;
    3801       647335 :           if (!loop->header->aux)
    3802            0 :             continue;
    3803              : 
    3804       647335 :           profile_count hdr_count = loop->header->count;
    3805       647335 :           sreal hdr_freq = hdr_count.to_sreal_scale (entry_count);
    3806              : 
    3807       647335 :           bb_predicate = *(ipa_predicate *)loop->header->aux;
    3808       647335 :           auto_vec<edge> exits = get_loop_exit_edges (loop);
    3809      2341393 :           FOR_EACH_VEC_ELT (exits, j, ex)
    3810      1046723 :             if (number_of_iterations_exit (loop, ex, &niter_desc, false)
    3811      1046723 :                 && !is_gimple_min_invariant (niter_desc.niter))
    3812              :             {
    3813       161088 :               ipa_predicate will_be_nonconstant
    3814       161088 :                 = will_be_nonconstant_expr_predicate (&fbi, info,
    3815              :                                                       params_summary,
    3816              :                                                       niter_desc.niter,
    3817              :                                                       nonconstant_names);
    3818       161088 :               if (will_be_nonconstant != true)
    3819        73949 :                 will_be_nonconstant = bb_predicate & will_be_nonconstant;
    3820       161088 :               if (will_be_nonconstant != true
    3821       235037 :                   && will_be_nonconstant != false)
    3822        70988 :                 loop_iterations &= will_be_nonconstant;
    3823              :             }
    3824       647335 :           add_freqcounting_predicate (&s->loop_iterations, loop_iterations,
    3825              :                                       hdr_freq, max_loop_predicates);
    3826       647337 :         }
    3827              : 
    3828              :       /* To avoid quadratic behavior we analyze stride predicates only
    3829              :          with respect to the containing loop.  Thus we simply iterate
    3830              :          over all defs in the outermost loop body.  */
    3831      1420277 :       for (class loop *loop = loops_for_fn (cfun)->tree_root->inner;
    3832      1929811 :            loop != NULL; loop = loop->next)
    3833              :         {
    3834       509534 :           ipa_predicate loop_stride = true;
    3835       509534 :           basic_block *body = get_loop_body (loop);
    3836       509534 :           profile_count hdr_count = loop->header->count;
    3837       509534 :           sreal hdr_freq = hdr_count.to_sreal_scale (entry_count);
    3838      3505343 :           for (unsigned i = 0; i < loop->num_nodes; i++)
    3839              :             {
    3840      2486275 :               gimple_stmt_iterator gsi;
    3841      2486275 :               if (!body[i]->aux)
    3842            8 :                 continue;
    3843              : 
    3844      2486267 :               bb_predicate = *(ipa_predicate *)body[i]->aux;
    3845     16823203 :               for (gsi = gsi_start_bb (body[i]); !gsi_end_p (gsi);
    3846     11850669 :                    gsi_next (&gsi))
    3847              :                 {
    3848     11850669 :                   auto *stmt = dyn_cast<gassign *> (gsi_stmt (gsi));
    3849     11850669 :                   if (!stmt)
    3850     11697715 :                     continue;
    3851              : 
    3852      5662467 :                   tree def = gimple_assign_lhs (stmt);
    3853      5662467 :                   if (TREE_CODE (def) != SSA_NAME)
    3854      1118478 :                     continue;
    3855              : 
    3856      4543989 :                   affine_iv iv;
    3857      9087978 :                   if (!simple_iv (loop_containing_stmt (stmt),
    3858              :                                   loop_containing_stmt (stmt),
    3859              :                                   def, &iv, true)
    3860      4543989 :                       || is_gimple_min_invariant (iv.step))
    3861      4391035 :                     continue;
    3862              : 
    3863       152954 :                   ipa_predicate will_be_nonconstant
    3864       152954 :                     = will_be_nonconstant_expr_predicate (&fbi, info,
    3865              :                                                           params_summary,
    3866              :                                                           iv.step,
    3867              :                                                           nonconstant_names);
    3868       152954 :                   if (will_be_nonconstant != true)
    3869        71427 :                     will_be_nonconstant = bb_predicate & will_be_nonconstant;
    3870       152954 :                   if (will_be_nonconstant != true
    3871       224381 :                       && will_be_nonconstant != false)
    3872        61765 :                     loop_stride = loop_stride & will_be_nonconstant;
    3873              :                 }
    3874              :             }
    3875       509534 :           add_freqcounting_predicate (&s->loop_strides, loop_stride,
    3876              :                                       hdr_freq, max_loop_predicates);
    3877       509534 :           free (body);
    3878              :         }
    3879      1420277 :       scev_finalize ();
    3880              :     }
    3881     65423350 :   FOR_ALL_BB_FN (bb, my_function)
    3882              :     {
    3883     57944881 :       edge e;
    3884     57944881 :       edge_iterator ei;
    3885              : 
    3886     57944881 :       if (bb->aux)
    3887     42804763 :         edge_predicate_pool.remove ((ipa_predicate *)bb->aux);
    3888     57944881 :       bb->aux = NULL;
    3889    123275273 :       FOR_EACH_EDGE (e, ei, bb->succs)
    3890              :         {
    3891     65330392 :           if (e->aux)
    3892      2956231 :             edge_predicate_pool.remove ((ipa_predicate *)e->aux);
    3893     65330392 :           e->aux = NULL;
    3894              :         }
    3895              :     }
    3896      7478469 :   ipa_fn_summary *s = ipa_fn_summaries->get (node);
    3897      7478469 :   ipa_size_summary *ss = ipa_size_summaries->get (node);
    3898      7478469 :   s->time = time;
    3899      7478469 :   ss->self_size = size;
    3900      7478469 :   nonconstant_names.release ();
    3901      7478469 :   ipa_release_body_info (&fbi);
    3902      7478469 :   if (opt_for_fn (node->decl, optimize))
    3903              :     {
    3904      6526878 :       if (!early)
    3905      1420277 :         loop_optimizer_finalize ();
    3906      5106601 :       else if (!ipa_edge_args_sum)
    3907      5106587 :         ipa_free_all_node_params ();
    3908      6526878 :       free_dominance_info (CDI_DOMINATORS);
    3909      6526878 :       free_dominance_info (CDI_POST_DOMINATORS);
    3910              :     }
    3911      7478469 :   if (dump_file)
    3912              :     {
    3913          294 :       fprintf (dump_file, "\n");
    3914          294 :       ipa_dump_fn_summary (dump_file, node);
    3915              :     }
    3916      7478469 : }
    3917              : 
    3918              : 
    3919              : /* Compute function summary.
    3920              :    EARLY is true when we compute parameters during early opts.  */
    3921              : 
    3922              : void
    3923      7479821 : compute_fn_summary (struct cgraph_node *node, bool early)
    3924              : {
    3925      7479821 :   HOST_WIDE_INT self_stack_size;
    3926      7479821 :   struct cgraph_edge *e;
    3927              : 
    3928      7479821 :   gcc_assert (!node->inlined_to);
    3929              : 
    3930      7479821 :   if (!ipa_fn_summaries)
    3931       224886 :     ipa_fn_summary_alloc ();
    3932              : 
    3933              :   /* Create a new ipa_fn_summary.  */
    3934      7479821 :   ((ipa_fn_summary_t *)ipa_fn_summaries)->remove_callees (node);
    3935      7479821 :   ipa_fn_summaries->remove (node);
    3936      7479821 :   class ipa_fn_summary *info = ipa_fn_summaries->get_create (node);
    3937      7479821 :   class ipa_size_summary *size_info = ipa_size_summaries->get_create (node);
    3938              : 
    3939              :   /* Estimate the stack size for the function if we're optimizing.  */
    3940     13055092 :   self_stack_size = optimize && !node->thunk
    3941     14006699 :                     ? estimated_stack_frame_size (node) : 0;
    3942      7479821 :   size_info->estimated_self_stack_size = self_stack_size;
    3943      7479821 :   info->estimated_stack_size = self_stack_size;
    3944              : 
    3945      7479821 :   if (node->thunk)
    3946              :     {
    3947         1352 :       ipa_call_summary *es = ipa_call_summaries->get_create (node->callees);
    3948         1352 :       ipa_predicate t = true;
    3949              : 
    3950         1352 :       node->can_change_signature = false;
    3951         1352 :       es->call_stmt_size = eni_size_weights.call_cost;
    3952         1352 :       es->call_stmt_time = eni_time_weights.call_cost;
    3953         4056 :       info->account_size_time (ipa_fn_summary::size_scale
    3954         1352 :                                * opt_for_fn (node->decl,
    3955              :                                  param_uninlined_function_thunk_insns),
    3956         1352 :                                opt_for_fn (node->decl,
    3957              :                                  param_uninlined_function_thunk_time), t, t);
    3958         1352 :       t = ipa_predicate::not_inlined ();
    3959         1352 :       info->account_size_time (2 * ipa_fn_summary::size_scale, 0, t, t);
    3960         1352 :       ipa_update_overall_fn_summary (node);
    3961         1352 :       size_info->self_size = size_info->size;
    3962         1352 :       if (stdarg_p (TREE_TYPE (node->decl)))
    3963              :         {
    3964            9 :           info->inlinable = false;
    3965            9 :           node->callees->inline_failed = CIF_VARIADIC_THUNK;
    3966              :         }
    3967              :       else
    3968         1343 :         info->inlinable = true;
    3969              :     }
    3970              :   else
    3971              :     {
    3972              :        /* Even is_gimple_min_invariant rely on current_function_decl.  */
    3973      7478469 :        push_cfun (DECL_STRUCT_FUNCTION (node->decl));
    3974              : 
    3975              :        /* During IPA profile merging we may be called w/o virtual SSA form
    3976              :           built.  */
    3977      7478469 :        update_ssa (TODO_update_ssa_only_virtuals);
    3978              : 
    3979              :        /* Can this function be inlined at all?  */
    3980      7478469 :        if (!opt_for_fn (node->decl, optimize)
    3981      8430060 :            && !lookup_attribute ("always_inline",
    3982       951591 :                                  DECL_ATTRIBUTES (node->decl)))
    3983       880397 :          info->inlinable = false;
    3984              :        else
    3985      6598072 :          info->inlinable = tree_inlinable_function_p (node->decl);
    3986              : 
    3987      7478469 :        bool no_signature = false;
    3988              : 
    3989              :        /* Don't allow signature changes for functions which have
    3990              :           [[gnu::musttail]] or [[clang::musttail]] calls.  Sometimes
    3991              :           (more often on targets which pass everything on the stack)
    3992              :           signature changes can result in tail calls being impossible
    3993              :           even when without the signature changes they would be ok.
    3994              :           See PR121023.  */
    3995      7478469 :        if (cfun->has_musttail)
    3996              :          {
    3997         1435 :            if (dump_file)
    3998            0 :             fprintf (dump_file, "No signature change:"
    3999              :                      " function has calls with musttail attribute.\n");
    4000              :            no_signature = true;
    4001              :          }
    4002              : 
    4003              :        /* Type attributes can use parameter indices to describe them.
    4004              :           Special case fn spec since we can safely preserve them in
    4005              :           modref summaries.  */
    4006      7478469 :        for (tree list = TYPE_ATTRIBUTES (TREE_TYPE (node->decl));
    4007      7882680 :             list && !no_signature; list = TREE_CHAIN (list))
    4008       404211 :         if (!ipa_param_adjustments::type_attribute_allowed_p
    4009       404211 :                         (get_attribute_name (list)))
    4010              :            {
    4011       159858 :              if (dump_file)
    4012              :                 {
    4013            0 :                   fprintf (dump_file, "No signature change:"
    4014              :                            " function type has unhandled attribute %s.\n",
    4015            0 :                            IDENTIFIER_POINTER (get_attribute_name (list)));
    4016              :                 }
    4017              :              no_signature = true;
    4018              :            }
    4019      7478469 :        for (tree parm = DECL_ARGUMENTS (node->decl);
    4020     22265767 :             parm && !no_signature; parm = DECL_CHAIN (parm))
    4021     14787298 :          if (variably_modified_type_p (TREE_TYPE (parm), node->decl))
    4022              :            {
    4023        16160 :              if (dump_file)
    4024              :                 {
    4025            0 :                   fprintf (dump_file, "No signature change:"
    4026              :                            " has parameter with variably modified type.\n");
    4027              :                 }
    4028              :              no_signature = true;
    4029              :            }
    4030              : 
    4031              :        /* Likewise for #pragma omp declare simd functions or functions
    4032              :           with simd attribute.  */
    4033      7478469 :        if (no_signature
    4034     14779485 :            || lookup_attribute ("omp declare simd",
    4035      7301016 :                                 DECL_ATTRIBUTES (node->decl)))
    4036       179168 :          node->can_change_signature = false;
    4037              :        else
    4038              :          {
    4039              :            /* Otherwise, inlinable functions always can change signature.  */
    4040      7299301 :            if (info->inlinable)
    4041      5870931 :              node->can_change_signature = true;
    4042              :            else
    4043              :              {
    4044              :                /* Functions calling builtin_apply cannot change signature.  */
    4045      5493277 :                for (e = node->callees; e; e = e->next_callee)
    4046              :                  {
    4047      4097761 :                    tree cdecl = e->callee->decl;
    4048      4097761 :                    if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS,
    4049              :                                                  BUILT_IN_VA_START))
    4050              :                      break;
    4051              :                  }
    4052      1428370 :                node->can_change_signature = !e;
    4053              :              }
    4054              :          }
    4055      7478469 :        analyze_function_body (node, early);
    4056      7478469 :        pop_cfun ();
    4057              :      }
    4058              : 
    4059              :   /* Inlining characteristics are maintained by the cgraph_mark_inline.  */
    4060      7479821 :   size_info->size = size_info->self_size;
    4061      7479821 :   info->estimated_stack_size = size_info->estimated_self_stack_size;
    4062              : 
    4063              :   /* Code above should compute exactly the same result as
    4064              :      ipa_update_overall_fn_summary except for case when speculative
    4065              :      edges are present since these are accounted to size but not
    4066              :      self_size. Do not compare time since different order the roundoff
    4067              :      errors result in slight changes.  */
    4068      7479821 :   ipa_update_overall_fn_summary (node);
    4069      7479821 :   if (flag_checking)
    4070              :     {
    4071      7969714 :       for (e = node->indirect_calls; e; e = e->next_callee)
    4072       489975 :        if (e->speculative)
    4073              :          break;
    4074      7479739 :       gcc_assert (e || size_info->size == size_info->self_size);
    4075              :     }
    4076      7479821 : }
    4077              : 
    4078              : 
    4079              : /* Compute parameters of functions used by inliner using
    4080              :    current_function_decl.  */
    4081              : 
    4082              : static unsigned int
    4083      5995490 : compute_fn_summary_for_current (void)
    4084              : {
    4085      5995490 :   compute_fn_summary (cgraph_node::get (current_function_decl), true);
    4086      5995490 :   return 0;
    4087              : }
    4088              : 
    4089              : /* Estimate benefit devirtualizing indirect edge IE and return true if it can
    4090              :    be devirtualized and inlined, provided m_known_vals, m_known_contexts and
    4091              :    m_known_aggs in AVALS.  Return false straight away if AVALS is NULL.  */
    4092              : 
    4093              : static bool
    4094      4956489 : estimate_edge_devirt_benefit (struct cgraph_edge *ie,
    4095              :                               int *size, int *time,
    4096              :                               ipa_call_arg_values *avals)
    4097              : {
    4098      4956489 :   tree target;
    4099      4956489 :   struct cgraph_node *callee;
    4100      4956489 :   class ipa_fn_summary *isummary;
    4101      4956489 :   enum availability avail;
    4102      4956489 :   bool speculative;
    4103              : 
    4104      4956489 :   if (!avals
    4105      4956489 :       || (!avals->m_known_vals.length() && !avals->m_known_contexts.length ()))
    4106              :     return false;
    4107      1515369 :   if (!opt_for_fn (ie->caller->decl, flag_indirect_inlining))
    4108              :     return false;
    4109              : 
    4110      1508714 :   target = ipa_get_indirect_edge_target
    4111      1508714 :     (ie->callee ? ie->speculative_call_indirect_edge () : ie,
    4112              :      avals, &speculative);
    4113      1508714 :   if (!target || speculative)
    4114              :     return false;
    4115              : 
    4116              :   /* If this is speculative call, turn its cost into 0; we will account
    4117              :      the call when processing the indirect call.  */
    4118       220097 :   if (ie->callee)
    4119              :     {
    4120         4551 :       gcc_checking_assert (ie->speculative && *size > 0);
    4121         4551 :       *size = 0;
    4122         4551 :       *time = 0;
    4123              :     }
    4124              :   else
    4125              :     {
    4126              :       /* Account for difference in cost between indirect and direct calls.  */
    4127       215546 :       *size -= (eni_size_weights.indirect_call_cost - eni_size_weights.call_cost);
    4128       215546 :       *time -= (eni_time_weights.indirect_call_cost - eni_time_weights.call_cost);
    4129              :     }
    4130       220097 :   gcc_checking_assert (*time >= 0);
    4131       220097 :   gcc_checking_assert (*size >= 0);
    4132              : 
    4133       220097 :   callee = cgraph_node::get (target);
    4134       220097 :   if (!callee || !callee->definition)
    4135              :     return false;
    4136       199391 :   callee = callee->function_symbol (&avail);
    4137       199391 :   if (avail < AVAIL_AVAILABLE)
    4138              :     return false;
    4139       199341 :   isummary = ipa_fn_summaries->get (callee);
    4140       199341 :   if (isummary == NULL)
    4141              :     return false;
    4142              : 
    4143       199327 :   return isummary->inlinable;
    4144              : }
    4145              : 
    4146              : /* Increase SIZE, MIN_SIZE (if non-NULL) and TIME for size and time needed to
    4147              :    handle edge E with probability PROB.  Set HINTS accordingly if edge may be
    4148              :    devirtualized.  AVALS, if non-NULL, describes the context of the call site
    4149              :    as far as values of parameters are concerned.  */
    4150              : 
    4151              : static inline void
    4152    207125703 : estimate_edge_size_and_time (struct cgraph_edge *e, int *size, int *min_size,
    4153              :                              sreal *time, ipa_call_arg_values *avals,
    4154              :                              ipa_hints *hints)
    4155              : {
    4156    207125703 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
    4157    207125703 :   int call_size = es->call_stmt_size;
    4158    207125703 :   int call_time = es->call_stmt_time;
    4159    207125703 :   int cur_size;
    4160              : 
    4161    202784465 :   if ((!e->callee || e->speculative)
    4162    207740954 :       && estimate_edge_devirt_benefit (e, &call_size, &call_time, avals))
    4163              :     {
    4164       199081 :       if (hints && e->maybe_hot_p ())
    4165       189545 :         *hints |= INLINE_HINT_indirect_call;
    4166              :     }
    4167    207125703 :   cur_size = call_size * ipa_fn_summary::size_scale;
    4168    207125703 :   *size += cur_size;
    4169    207125703 :   if (min_size)
    4170     28434460 :     *min_size += cur_size;
    4171    207125703 :   if (time)
    4172    196925049 :     *time += ((sreal)call_time) * e->sreal_frequency ();
    4173    207125703 : }
    4174              : 
    4175              : 
    4176              : /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all
    4177              :    calls in NODE.  POSSIBLE_TRUTHS and AVALS describe the context of the call
    4178              :    site.
    4179              : 
    4180              :    Helper for estimate_calls_size_and_time which does the same but
    4181              :    (in most cases) faster.  */
    4182              : 
    4183              : static void
    4184     73382983 : estimate_calls_size_and_time_1 (struct cgraph_node *node, int *size,
    4185              :                                 int *min_size, sreal *time,
    4186              :                                 ipa_hints *hints,
    4187              :                                 clause_t possible_truths,
    4188              :                                 ipa_call_arg_values *avals)
    4189              : {
    4190     73382983 :   struct cgraph_edge *e;
    4191    349865286 :   for (e = node->callees; e; e = e->next_callee)
    4192              :     {
    4193    276482303 :       if (!e->inline_failed)
    4194              :         {
    4195     52620155 :           gcc_checking_assert (!ipa_call_summaries->get (e));
    4196     52620155 :           estimate_calls_size_and_time_1 (e->callee, size, min_size, time,
    4197              :                                           hints, possible_truths, avals);
    4198              : 
    4199     52620155 :           continue;
    4200              :         }
    4201    223862148 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    4202              : 
    4203              :       /* Do not care about zero sized builtins.  */
    4204    223862148 :       if (!es->call_stmt_size)
    4205              :         {
    4206     30148480 :           gcc_checking_assert (!es->call_stmt_time);
    4207     30148480 :           continue;
    4208              :         }
    4209    193713668 :       if (!es->predicate
    4210    193713668 :           || es->predicate->evaluate (possible_truths))
    4211              :         {
    4212              :           /* Predicates of calls shall not use NOT_CHANGED codes,
    4213              :              so we do not need to compute probabilities.  */
    4214    191421918 :           estimate_edge_size_and_time (e, size,
    4215    191421918 :                                        es->predicate ? NULL : min_size,
    4216              :                                        time, avals, hints);
    4217              :         }
    4218              :     }
    4219     77432409 :   for (e = node->indirect_calls; e; e = e->next_callee)
    4220              :     {
    4221      4049426 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    4222      4049426 :       if (!es->predicate
    4223      4049426 :           || es->predicate->evaluate (possible_truths))
    4224      4022129 :         estimate_edge_size_and_time (e, size,
    4225      4022129 :                                      es->predicate ? NULL : min_size,
    4226              :                                      time, avals, hints);
    4227              :     }
    4228     73382983 : }
    4229              : 
    4230              : /* Populate sum->call_size_time_table for edges from NODE.  */
    4231              : 
    4232              : static void
    4233      3237892 : summarize_calls_size_and_time (struct cgraph_node *node,
    4234              :                                ipa_fn_summary *sum)
    4235              : {
    4236      3237892 :   struct cgraph_edge *e;
    4237     15165117 :   for (e = node->callees; e; e = e->next_callee)
    4238              :     {
    4239     11927225 :       if (!e->inline_failed)
    4240              :         {
    4241      1453870 :           gcc_checking_assert (!ipa_call_summaries->get (e));
    4242      1453870 :           summarize_calls_size_and_time (e->callee, sum);
    4243      1453870 :           continue;
    4244              :         }
    4245     10473355 :       int size = 0;
    4246     10473355 :       sreal time = 0;
    4247              : 
    4248     10473355 :       estimate_edge_size_and_time (e, &size, NULL, &time, NULL, NULL);
    4249              : 
    4250     10473355 :       ipa_predicate pred = true;
    4251     10473355 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    4252              : 
    4253     10473355 :       if (es->predicate)
    4254      2286349 :         pred = *es->predicate;
    4255     10473355 :       sum->account_size_time (size, time, pred, pred, true);
    4256              :     }
    4257      3557001 :   for (e = node->indirect_calls; e; e = e->next_callee)
    4258              :     {
    4259       319109 :       int size = 0;
    4260       319109 :       sreal time = 0;
    4261              : 
    4262       319109 :       estimate_edge_size_and_time (e, &size, NULL, &time, NULL, NULL);
    4263       319109 :       ipa_predicate pred = true;
    4264       319109 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    4265              : 
    4266       319109 :       if (es->predicate)
    4267        96145 :         pred = *es->predicate;
    4268       319109 :       sum->account_size_time (size, time, pred, pred, true);
    4269              :     }
    4270      3237892 : }
    4271              : 
    4272              : /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all
    4273              :    calls in NODE.  POSSIBLE_TRUTHS and AVALS (the latter if non-NULL) describe
    4274              :    context of the call site.  */
    4275              : 
    4276              : static void
    4277     20762849 : estimate_calls_size_and_time (struct cgraph_node *node, int *size,
    4278              :                               int *min_size, sreal *time,
    4279              :                               ipa_hints *hints,
    4280              :                               clause_t possible_truths,
    4281              :                               ipa_call_arg_values *avals)
    4282              : {
    4283     20762849 :   class ipa_fn_summary *sum = ipa_fn_summaries->get (node);
    4284     20762849 :   bool use_table = true;
    4285              : 
    4286     20762849 :   gcc_assert (node->callees || node->indirect_calls);
    4287              : 
    4288              :   /* During early inlining we do not calculate info for very
    4289              :      large functions and thus there is no need for producing
    4290              :      summaries.  */
    4291     20762849 :   if (!ipa_node_params_sum)
    4292              :     use_table = false;
    4293              :   /* Do not calculate summaries for simple wrappers; it is waste
    4294              :      of memory.  */
    4295     11175323 :   else if (node->callees && !node->indirect_calls
    4296     10397002 :            && node->callees->inline_failed && !node->callees->next_callee)
    4297              :     use_table = false;
    4298              :   /* If there is an indirect edge that may be optimized, we need
    4299              :      to go the slow way.  */
    4300      8964790 :   else if (avals
    4301      8964790 :            && (avals->m_known_vals.length ()
    4302      3455382 :                || avals->m_known_contexts.length ()
    4303      3301087 :                || avals->m_known_aggs.length ()))
    4304              :     {
    4305      4135615 :       ipa_node_params *params_summary = ipa_node_params_sum->get (node);
    4306      4135615 :       unsigned int nargs = params_summary
    4307      4135615 :                            ? ipa_get_param_count (params_summary) : 0;
    4308              : 
    4309     13926887 :       for (unsigned int i = 0; i < nargs && use_table; i++)
    4310              :         {
    4311      9791272 :           if (ipa_is_param_used_by_indirect_call (params_summary, i)
    4312      9791272 :               && (avals->safe_sval_at (i)
    4313       281561 :                   || (ipa_argagg_value_list (avals).value_for_index_p (i))))
    4314              :             use_table = false;
    4315      9693045 :           else if (ipa_is_param_used_by_polymorphic_call (params_summary, i)
    4316      9693045 :                    && (avals->m_known_contexts.length () > i
    4317      9943053 :                        && !avals->m_known_contexts[i].useless_p ()))
    4318              :             use_table = false;
    4319              :         }
    4320              :     }
    4321              : 
    4322              :   /* Fast path is via the call size time table.  */
    4323      4135615 :   if (use_table)
    4324              :     {
    4325              :       /* Build summary if it is absent.  */
    4326      8691796 :       if (!sum->call_size_time_table.length ())
    4327              :         {
    4328       894830 :           ipa_predicate true_pred = true;
    4329       894830 :           sum->account_size_time (0, 0, true_pred, true_pred, true);
    4330       894830 :           summarize_calls_size_and_time (node, sum);
    4331              :         }
    4332              : 
    4333      8691796 :       int old_size = *size;
    4334      8691796 :       sreal old_time = time ? *time : 0;
    4335              : 
    4336      8691796 :       if (min_size)
    4337      8691796 :         *min_size += sum->call_size_time_table[0].size;
    4338              : 
    4339      8691796 :       unsigned int i;
    4340      8691796 :       size_time_entry *e;
    4341              : 
    4342              :       /* Walk the table and account sizes and times.  */
    4343     25024415 :       for (i = 0; sum->call_size_time_table.iterate (i, &e);
    4344              :            i++)
    4345     16332619 :         if (e->exec_predicate.evaluate (possible_truths))
    4346              :           {
    4347     15342115 :             *size += e->size;
    4348     15342115 :             if (time)
    4349     12988184 :               *time += e->time;
    4350              :           }
    4351              : 
    4352              :       /* Be careful and see if both methods agree.  */
    4353           21 :       if ((flag_checking || dump_file)
    4354              :           /* Do not try to sanity check when we know we lost some
    4355              :              precision.  */
    4356      8691796 :           && sum->call_size_time_table.length ()
    4357              :              < ipa_fn_summary::max_size_time_table_size)
    4358              :         {
    4359      8691775 :           estimate_calls_size_and_time_1 (node, &old_size, NULL, &old_time, NULL,
    4360              :                                           possible_truths, avals);
    4361      8691775 :           gcc_assert (*size == old_size);
    4362     15927134 :           if (time && (*time - old_time > 1 || *time - old_time < -1)
    4363      8691810 :               && dump_file)
    4364            0 :             fprintf (dump_file, "Time mismatch in call summary %f!=%f\n",
    4365              :                      old_time.to_double (),
    4366              :                      time->to_double ());
    4367              :         }
    4368              :     }
    4369              :   /* Slow path by walking all edges.  */
    4370              :   else
    4371     12071053 :     estimate_calls_size_and_time_1 (node, size, min_size, time, hints,
    4372              :                                     possible_truths, avals);
    4373     20762849 : }
    4374              : 
    4375              : /* Main constructor for ipa call context.  Memory allocation of ARG_VALUES
    4376              :    is owned by the caller.  INLINE_PARAM_SUMMARY is also owned by the
    4377              :    caller.  */
    4378              : 
    4379     19884287 : ipa_call_context::ipa_call_context (cgraph_node *node, clause_t possible_truths,
    4380              :                                     clause_t nonspec_possible_truths,
    4381              :                                     vec<inline_param_summary>
    4382              :                                       inline_param_summary,
    4383              :                                     ipa_auto_call_arg_values *arg_values)
    4384     19884287 : : m_node (node), m_possible_truths (possible_truths),
    4385     19884287 :   m_nonspec_possible_truths (nonspec_possible_truths),
    4386     19884287 :   m_inline_param_summary (inline_param_summary),
    4387     19884287 :   m_avals (arg_values)
    4388              : {
    4389     19884287 : }
    4390              : 
    4391              : /* Set THIS to be a duplicate of CTX.  Copy all relevant info.  */
    4392              : 
    4393              : void
    4394      1991064 : ipa_cached_call_context::duplicate_from (const ipa_call_context &ctx)
    4395              : {
    4396      1991064 :   m_node = ctx.m_node;
    4397      1991064 :   m_possible_truths = ctx.m_possible_truths;
    4398      1991064 :   m_nonspec_possible_truths = ctx.m_nonspec_possible_truths;
    4399      1991064 :   ipa_node_params *params_summary = ipa_node_params_sum->get (m_node);
    4400      1991064 :   unsigned int nargs = params_summary
    4401      1991064 :                        ? ipa_get_param_count (params_summary) : 0;
    4402              : 
    4403      1991064 :   m_inline_param_summary = vNULL;
    4404              :   /* Copy the info only if there is at least one useful entry.  */
    4405      1991064 :   if (ctx.m_inline_param_summary.exists ())
    4406              :     {
    4407      1766816 :       unsigned int n = MIN (ctx.m_inline_param_summary.length (), nargs);
    4408              : 
    4409      4040998 :       for (unsigned int i = 0; i < n; i++)
    4410      3298309 :         if (ipa_is_param_used_by_ipa_predicates (params_summary, i)
    4411      4697676 :             && !ctx.m_inline_param_summary[i].useless_p ())
    4412              :           {
    4413      1024127 :             m_inline_param_summary
    4414      1024127 :                     = ctx.m_inline_param_summary.copy ();
    4415      1024127 :             break;
    4416              :           }
    4417              :     }
    4418      1991064 :   m_avals.m_known_vals = vNULL;
    4419      1991064 :   if (ctx.m_avals.m_known_vals.exists ())
    4420              :     {
    4421      1991064 :       unsigned int n = MIN (ctx.m_avals.m_known_vals.length (), nargs);
    4422              : 
    4423      4615466 :       for (unsigned int i = 0; i < n; i++)
    4424      2651996 :         if (ipa_is_param_used_by_indirect_call (params_summary, i)
    4425      2651996 :             && ctx.m_avals.m_known_vals[i])
    4426              :           {
    4427        27594 :             m_avals.m_known_vals = ctx.m_avals.m_known_vals.copy ();
    4428        27594 :             break;
    4429              :           }
    4430              :     }
    4431              : 
    4432      1991064 :   m_avals.m_known_contexts = vNULL;
    4433      1991064 :   if (ctx.m_avals.m_known_contexts.exists ())
    4434              :     {
    4435      1991064 :       unsigned int n = MIN (ctx.m_avals.m_known_contexts.length (), nargs);
    4436              : 
    4437      1993932 :       for (unsigned int i = 0; i < n; i++)
    4438        28487 :         if (ipa_is_param_used_by_polymorphic_call (params_summary, i)
    4439        28487 :             && !ctx.m_avals.m_known_contexts[i].useless_p ())
    4440              :           {
    4441        25619 :             m_avals.m_known_contexts = ctx.m_avals.m_known_contexts.copy ();
    4442        25619 :             break;
    4443              :           }
    4444              :     }
    4445              : 
    4446      1991064 :   m_avals.m_known_aggs = vNULL;
    4447      1991064 :   if (ctx.m_avals.m_known_aggs.exists ())
    4448              :     {
    4449      1991064 :       const ipa_argagg_value_list avl (&ctx.m_avals);
    4450      8626792 :       for (unsigned int i = 0; i < nargs; i++)
    4451      4647617 :         if (ipa_is_param_used_by_indirect_call (params_summary, i)
    4452      4647617 :             && avl.value_for_index_p (i))
    4453              :           {
    4454         2953 :             m_avals.m_known_aggs = ctx.m_avals.m_known_aggs.copy ();
    4455         2953 :             break;
    4456              :           }
    4457              :     }
    4458              : 
    4459      1991064 :   m_avals.m_known_value_ranges = vNULL;
    4460      1991064 : }
    4461              : 
    4462              : /* Release memory used by known_vals/contexts/aggs vectors.  and
    4463              :    inline_param_summary.  */
    4464              : 
    4465              : void
    4466      3239512 : ipa_cached_call_context::release ()
    4467              : {
    4468              :   /* See if context is initialized at first place.  */
    4469      3239512 :   if (!m_node)
    4470              :     return;
    4471      1991064 :   m_avals.m_known_aggs.release ();
    4472      1991064 :   m_avals.m_known_vals.release ();
    4473      1991064 :   m_avals.m_known_contexts.release ();
    4474      1991064 :   m_inline_param_summary.release ();
    4475              : }
    4476              : 
    4477              : /* Return true if CTX describes the same call context as THIS.  */
    4478              : 
    4479              : bool
    4480      6954302 : ipa_call_context::equal_to (const ipa_call_context &ctx)
    4481              : {
    4482      6954302 :   if (m_node != ctx.m_node
    4483      5705854 :       || m_possible_truths != ctx.m_possible_truths
    4484      5101240 :       || m_nonspec_possible_truths != ctx.m_nonspec_possible_truths)
    4485              :     return false;
    4486              : 
    4487      5101204 :   ipa_node_params *params_summary = ipa_node_params_sum->get (m_node);
    4488      5101204 :   unsigned int nargs = params_summary
    4489      5101204 :                        ? ipa_get_param_count (params_summary) : 0;
    4490              : 
    4491      5101204 :   if (m_inline_param_summary.exists () || ctx.m_inline_param_summary.exists ())
    4492              :     {
    4493     15312154 :       for (unsigned int i = 0; i < nargs; i++)
    4494              :         {
    4495     10574825 :           if (!ipa_is_param_used_by_ipa_predicates (params_summary, i))
    4496      3435091 :             continue;
    4497      7139734 :           if (i >= m_inline_param_summary.length ()
    4498      4894268 :               || m_inline_param_summary[i].useless_p ())
    4499              :             {
    4500      3228198 :               if (i < ctx.m_inline_param_summary.length ()
    4501      3228198 :                   && !ctx.m_inline_param_summary[i].useless_p ())
    4502              :                 return false;
    4503      3180790 :               continue;
    4504              :             }
    4505      3911536 :           if (i >= ctx.m_inline_param_summary.length ()
    4506      3911533 :               || ctx.m_inline_param_summary[i].useless_p ())
    4507              :             {
    4508        45553 :               if (i < m_inline_param_summary.length ()
    4509        45553 :                   && !m_inline_param_summary[i].useless_p ())
    4510              :                 return false;
    4511            0 :               continue;
    4512              :             }
    4513      3865983 :           if (!m_inline_param_summary[i].equal_to
    4514      3865983 :                  (ctx.m_inline_param_summary[i]))
    4515              :             return false;
    4516              :         }
    4517              :     }
    4518      4977440 :   if (m_avals.m_known_vals.exists () || ctx.m_avals.m_known_vals.exists ())
    4519              :     {
    4520     15350338 :       for (unsigned int i = 0; i < nargs; i++)
    4521              :         {
    4522     10384206 :           if (!ipa_is_param_used_by_indirect_call (params_summary, i))
    4523     10165554 :             continue;
    4524       218652 :           if (i >= m_avals.m_known_vals.length () || !m_avals.m_known_vals[i])
    4525              :             {
    4526       160543 :               if (i < ctx.m_avals.m_known_vals.length ()
    4527       160543 :                   && ctx.m_avals.m_known_vals[i])
    4528              :                 return false;
    4529       160452 :               continue;
    4530              :             }
    4531        58109 :           if (i >= ctx.m_avals.m_known_vals.length ()
    4532        58109 :               || !ctx.m_avals.m_known_vals[i])
    4533              :             {
    4534              :               if (i < m_avals.m_known_vals.length () && m_avals.m_known_vals[i])
    4535              :                 return false;
    4536              :               continue;
    4537              :             }
    4538        58016 :           if (m_avals.m_known_vals[i] != ctx.m_avals.m_known_vals[i])
    4539              :             return false;
    4540              :         }
    4541              :     }
    4542      4966132 :   if (m_avals.m_known_contexts.exists ()
    4543      4966132 :       || ctx.m_avals.m_known_contexts.exists ())
    4544              :     {
    4545     15333738 :       for (unsigned int i = 0; i < nargs; i++)
    4546              :         {
    4547     10369086 :           if (!ipa_is_param_used_by_polymorphic_call (params_summary, i))
    4548     10225054 :             continue;
    4549       144032 :           if (i >= m_avals.m_known_contexts.length ()
    4550       142873 :               || m_avals.m_known_contexts[i].useless_p ())
    4551              :             {
    4552         1159 :               if (i < ctx.m_avals.m_known_contexts.length ()
    4553         1159 :                   && !ctx.m_avals.m_known_contexts[i].useless_p ())
    4554              :                 return false;
    4555         1147 :               continue;
    4556              :             }
    4557       142873 :           if (i >= ctx.m_avals.m_known_contexts.length ()
    4558       142873 :               || ctx.m_avals.m_known_contexts[i].useless_p ())
    4559              :             {
    4560            8 :               if (i < m_avals.m_known_contexts.length ()
    4561            8 :                   && !m_avals.m_known_contexts[i].useless_p ())
    4562              :                 return false;
    4563            0 :               continue;
    4564              :             }
    4565       142865 :           if (!m_avals.m_known_contexts[i].equal_to
    4566       142865 :                  (ctx.m_avals.m_known_contexts[i]))
    4567              :             return false;
    4568              :         }
    4569              :     }
    4570      4964652 :   if (m_avals.m_known_aggs.exists () || ctx.m_avals.m_known_aggs.exists ())
    4571              :     {
    4572              :       unsigned i = 0, j = 0;
    4573     11772453 :       while (i < m_avals.m_known_aggs.length ()
    4574      5885474 :              || j < ctx.m_avals.m_known_aggs.length ())
    4575              :         {
    4576       922236 :           if (i >= m_avals.m_known_aggs.length ())
    4577              :             {
    4578       917333 :               int idx2 = ctx.m_avals.m_known_aggs[j].index;
    4579       917333 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx2))
    4580              :                 return false;
    4581       916773 :               j++;
    4582       916773 :               continue;
    4583       916773 :             }
    4584         4903 :           if (j >= ctx.m_avals.m_known_aggs.length ())
    4585              :             {
    4586          603 :               int idx1 = m_avals.m_known_aggs[i].index;
    4587          603 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4588              :                 return false;
    4589            8 :               i++;
    4590            8 :               continue;
    4591            8 :             }
    4592              : 
    4593         4300 :           int idx1 = m_avals.m_known_aggs[i].index;
    4594         4300 :           int idx2 = ctx.m_avals.m_known_aggs[j].index;
    4595         4300 :           if (idx1 < idx2)
    4596              :             {
    4597            0 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4598              :                 return false;
    4599            0 :               i++;
    4600            0 :               continue;
    4601              :             }
    4602         4300 :           if (idx1 > idx2)
    4603              :             {
    4604            0 :               if (ipa_is_param_used_by_indirect_call (params_summary, idx2))
    4605              :                 return false;
    4606            0 :               j++;
    4607            0 :               continue;
    4608              :             }
    4609         4300 :           if (!ipa_is_param_used_by_indirect_call (params_summary, idx1))
    4610              :             {
    4611          484 :               i++;
    4612          484 :               j++;
    4613          484 :               continue;
    4614              :             }
    4615              : 
    4616         3816 :           if ((m_avals.m_known_aggs[i].unit_offset
    4617         3816 :                != ctx.m_avals.m_known_aggs[j].unit_offset)
    4618         3808 :               || (m_avals.m_known_aggs[i].by_ref
    4619         3808 :                != ctx.m_avals.m_known_aggs[j].by_ref)
    4620         7624 :               || !operand_equal_p (m_avals.m_known_aggs[i].value,
    4621         3808 :                                    ctx.m_avals.m_known_aggs[j].value))
    4622              :             return false;
    4623         3557 :           i++;
    4624         3557 :           j++;
    4625              :         }
    4626              :     }
    4627              :   return true;
    4628              : }
    4629              : 
    4630              : /* Fill in the selected fields in ESTIMATES with value estimated for call in
    4631              :    this context.  Always compute size and min_size.  Only compute time and
    4632              :    nonspecialized_time if EST_TIMES is true.  Only compute hints if EST_HINTS
    4633              :    is true.  */
    4634              : 
    4635              : void
    4636     19851848 : ipa_call_context::estimate_size_and_time (ipa_call_estimates *estimates,
    4637              :                                           bool est_times, bool est_hints)
    4638              : {
    4639     19851848 :   class ipa_fn_summary *info = ipa_fn_summaries->get (m_node);
    4640     19851848 :   size_time_entry *e;
    4641     19851848 :   int size = 0;
    4642     19851848 :   sreal time = 0;
    4643     19851848 :   int min_size = 0;
    4644     19851848 :   ipa_hints hints = 0;
    4645     19851848 :   sreal loops_with_known_iterations = 0;
    4646     19851848 :   sreal loops_with_known_strides = 0;
    4647     19851848 :   int i;
    4648              : 
    4649     19851848 :   if (dump_file && (dump_flags & TDF_DETAILS))
    4650              :     {
    4651         2004 :       bool found = false;
    4652         2004 :       fprintf (dump_file, "   Estimating body: %s\n"
    4653              :                "   Known to be false: ", m_node->dump_name ());
    4654              : 
    4655         7918 :       for (i = ipa_predicate::not_inlined_condition;
    4656        15836 :            i < (ipa_predicate::first_dynamic_condition
    4657        13720 :                 + (int) vec_safe_length (info->conds)); i++)
    4658         5914 :         if (!(m_possible_truths & (1 << i)))
    4659              :           {
    4660         3190 :             if (found)
    4661         1243 :               fprintf (dump_file, ", ");
    4662         3190 :             found = true;
    4663         3190 :             dump_condition (dump_file, info->conds, i);
    4664              :           }
    4665              :     }
    4666              : 
    4667     19851848 :   if (m_node->callees || m_node->indirect_calls)
    4668     26430877 :     estimate_calls_size_and_time (m_node, &size, &min_size,
    4669              :                                   est_times ? &time : NULL,
    4670              :                                   est_hints ? &hints : NULL, m_possible_truths,
    4671              :                                   &m_avals);
    4672              : 
    4673     19851848 :   sreal nonspecialized_time = time;
    4674              : 
    4675     19851848 :   min_size += info->size_time_table[0].size;
    4676    152342133 :   for (i = 0; info->size_time_table.iterate (i, &e); i++)
    4677              :     {
    4678    132490285 :       bool exec = e->exec_predicate.evaluate (m_nonspec_possible_truths);
    4679              : 
    4680              :       /* Because predicates are conservative, it can happen that nonconst is 1
    4681              :          but exec is 0.  */
    4682    132490285 :       if (exec)
    4683              :         {
    4684    129567881 :           bool nonconst = e->nonconst_predicate.evaluate (m_possible_truths);
    4685              : 
    4686    129567881 :           gcc_checking_assert (e->time >= 0);
    4687    129567881 :           gcc_checking_assert (time >= 0);
    4688              : 
    4689              :           /* We compute specialized size only because size of nonspecialized
    4690              :              copy is context independent.
    4691              : 
    4692              :              The difference between nonspecialized execution and specialized is
    4693              :              that nonspecialized is not going to have optimized out computations
    4694              :              known to be constant in a specialized setting.  */
    4695    129567881 :           if (nonconst)
    4696     67192436 :             size += e->size;
    4697    129567881 :           if (!est_times)
    4698     62758132 :             continue;
    4699     66809749 :           nonspecialized_time += e->time;
    4700     66809749 :           if (!nonconst)
    4701              :             ;
    4702     34259251 :           else if (!m_inline_param_summary.exists ())
    4703              :             {
    4704      2601680 :               if (nonconst)
    4705      2601680 :                 time += e->time;
    4706              :             }
    4707              :           else
    4708              :             {
    4709     31657571 :               int prob = e->nonconst_predicate.probability
    4710     31657571 :                                                (info->conds, m_possible_truths,
    4711              :                                                 m_inline_param_summary);
    4712     31657571 :               gcc_checking_assert (prob >= 0);
    4713     31657571 :               gcc_checking_assert (prob <= REG_BR_PROB_BASE);
    4714     31657571 :               if (prob == REG_BR_PROB_BASE)
    4715     27916260 :                 time += e->time;
    4716              :               else
    4717      3741311 :                 time += e->time * prob / REG_BR_PROB_BASE;
    4718              :             }
    4719     66809749 :           gcc_checking_assert (time >= 0);
    4720              :         }
    4721              :      }
    4722     19851848 :   gcc_checking_assert (info->size_time_table[0].exec_predicate == true);
    4723     19851848 :   gcc_checking_assert (info->size_time_table[0].nonconst_predicate == true);
    4724     19851848 :   gcc_checking_assert (min_size >= 0);
    4725     19851848 :   gcc_checking_assert (size >= 0);
    4726     19851848 :   gcc_checking_assert (time >= 0);
    4727              :   /* nonspecialized_time should be always bigger than specialized time.
    4728              :      Roundoff issues however may get into the way.  */
    4729     19851848 :   gcc_checking_assert ((nonspecialized_time - time * 99 / 100) >= -1);
    4730              : 
    4731              :   /* Roundoff issues may make specialized time bigger than nonspecialized
    4732              :      time.  We do not really want that to happen because some heuristics
    4733              :      may get confused by seeing negative speedups.  */
    4734     19851848 :   if (time > nonspecialized_time)
    4735            0 :     time = nonspecialized_time;
    4736              : 
    4737     19851848 :   if (est_hints)
    4738              :     {
    4739      7157761 :       if (info->scc_no)
    4740       234357 :         hints |= INLINE_HINT_in_scc;
    4741      7157761 :       if (DECL_DECLARED_INLINE_P (m_node->decl))
    4742      4491495 :         hints |= INLINE_HINT_declared_inline;
    4743      7157761 :       if (info->builtin_constant_p_parms.length ()
    4744         9826 :           && DECL_DECLARED_INLINE_P (m_node->decl))
    4745         9637 :         hints |= INLINE_HINT_builtin_constant_p;
    4746              : 
    4747      7157761 :       ipa_freqcounting_predicate *fcp;
    4748      7737880 :       for (i = 0; vec_safe_iterate (info->loop_iterations, i, &fcp); i++)
    4749       580119 :         if (!fcp->predicate->evaluate (m_possible_truths))
    4750              :           {
    4751       378263 :             hints |= INLINE_HINT_loop_iterations;
    4752       378263 :             loops_with_known_iterations += fcp->freq;
    4753              :           }
    4754      7157761 :       estimates->loops_with_known_iterations = loops_with_known_iterations;
    4755              : 
    4756      7454086 :       for (i = 0; vec_safe_iterate (info->loop_strides, i, &fcp); i++)
    4757       296325 :         if (!fcp->predicate->evaluate (m_possible_truths))
    4758              :           {
    4759       265437 :             hints |= INLINE_HINT_loop_stride;
    4760       265437 :             loops_with_known_strides += fcp->freq;
    4761              :           }
    4762      7157761 :       estimates->loops_with_known_strides = loops_with_known_strides;
    4763              :     }
    4764              : 
    4765     19851848 :   size = RDIV (size, ipa_fn_summary::size_scale);
    4766     19851848 :   min_size = RDIV (min_size, ipa_fn_summary::size_scale);
    4767              : 
    4768     19851848 :   if (dump_file && (dump_flags & TDF_DETAILS))
    4769              :     {
    4770         2004 :       fprintf (dump_file, "\n   size:%i", (int) size);
    4771         2004 :       if (est_times)
    4772         1286 :         fprintf (dump_file, " time:%f nonspec time:%f",
    4773              :                  time.to_double (), nonspecialized_time.to_double ());
    4774         2004 :       if (est_hints)
    4775         1286 :         fprintf (dump_file, " loops with known iterations:%f "
    4776              :                  "known strides:%f", loops_with_known_iterations.to_double (),
    4777              :                  loops_with_known_strides.to_double ());
    4778         2004 :       fprintf (dump_file, "\n");
    4779              :     }
    4780     19851848 :   if (est_times)
    4781              :     {
    4782      7157761 :       estimates->time = time;
    4783      7157761 :       estimates->nonspecialized_time = nonspecialized_time;
    4784              :     }
    4785     19851848 :   estimates->size = size;
    4786     19851848 :   estimates->min_size = min_size;
    4787     19851848 :   if (est_hints)
    4788      7157761 :     estimates->hints = hints;
    4789     19851848 :   return;
    4790              : }
    4791              : 
    4792              : 
    4793              : /* Estimate size and time needed to execute callee of EDGE assuming that
    4794              :    parameters known to be constant at caller of EDGE are propagated.
    4795              :    KNOWN_VALS and KNOWN_CONTEXTS are vectors of assumed known constant values
    4796              :    and types for parameters.  */
    4797              : 
    4798              : void
    4799       232049 : estimate_ipcp_clone_size_and_time (struct cgraph_node *node,
    4800              :                                    ipa_auto_call_arg_values *avals,
    4801              :                                    ipa_call_estimates *estimates)
    4802              : {
    4803       232049 :   clause_t clause, nonspec_clause;
    4804              : 
    4805       232049 :   evaluate_conditions_for_known_args (node, false, avals, &clause,
    4806              :                                       &nonspec_clause, NULL);
    4807       232049 :   ipa_call_context ctx (node, clause, nonspec_clause, vNULL, avals);
    4808       232049 :   ctx.estimate_size_and_time (estimates);
    4809       232049 : }
    4810              : 
    4811              : /* Return stack frame offset where frame of NODE is supposed to start inside
    4812              :    of the function it is inlined to.
    4813              :    Return 0 for functions that are not inlined.  */
    4814              : 
    4815              : HOST_WIDE_INT
    4816      5257460 : ipa_get_stack_frame_offset (struct cgraph_node *node)
    4817              : {
    4818      5257460 :   HOST_WIDE_INT offset = 0;
    4819      5257460 :   if (!node->inlined_to)
    4820              :     return 0;
    4821      4178291 :   node = node->callers->caller;
    4822      5404471 :   while (true)
    4823              :     {
    4824      4791381 :       offset += ipa_size_summaries->get (node)->estimated_self_stack_size;
    4825      4791381 :       if (!node->inlined_to)
    4826              :         return offset;
    4827       613090 :       node = node->callers->caller;
    4828              :     }
    4829              : }
    4830              : 
    4831              : 
    4832              : /* Update summary information of inline clones after inlining.
    4833              :    Compute peak stack usage.  */
    4834              : 
    4835              : static void
    4836      4901990 : inline_update_callee_summaries (struct cgraph_node *node, int depth)
    4837              : {
    4838      4901990 :   struct cgraph_edge *e;
    4839              : 
    4840      4901990 :   ipa_propagate_frequency (node);
    4841      9485308 :   for (e = node->callees; e; e = e->next_callee)
    4842              :     {
    4843      4583318 :       if (!e->inline_failed)
    4844       724318 :         inline_update_callee_summaries (e->callee, depth);
    4845              :       else
    4846      3859000 :         ipa_call_summaries->get (e)->loop_depth += depth;
    4847              :     }
    4848      5018592 :   for (e = node->indirect_calls; e; e = e->next_callee)
    4849       116602 :     ipa_call_summaries->get (e)->loop_depth += depth;
    4850      4901990 : }
    4851              : 
    4852              : /* Update change_prob and points_to_local_or_readonly_memory of EDGE after
    4853              :    INLINED_EDGE has been inlined.
    4854              : 
    4855              :    When function A is inlined in B and A calls C with parameter that
    4856              :    changes with probability PROB1 and C is known to be passthrough
    4857              :    of argument if B that change with probability PROB2, the probability
    4858              :    of change is now PROB1*PROB2.  */
    4859              : 
    4860              : static void
    4861      3975912 : remap_edge_params (struct cgraph_edge *inlined_edge,
    4862              :                    struct cgraph_edge *edge)
    4863              : {
    4864      3975912 :   if (ipa_node_params_sum)
    4865              :     {
    4866      2786236 :       int i;
    4867      2786236 :       ipa_edge_args *args = ipa_edge_args_sum->get (edge);
    4868      2786236 :       if (!args)
    4869              :         return;
    4870      1591332 :       class ipa_call_summary *es = ipa_call_summaries->get (edge);
    4871      1591332 :       class ipa_call_summary *inlined_es
    4872      1591332 :         = ipa_call_summaries->get (inlined_edge);
    4873              : 
    4874      1591332 :       if (es->param.length () == 0)
    4875              :         return;
    4876              : 
    4877      9252705 :       for (i = 0; i < ipa_get_cs_argument_count (args); i++)
    4878              :         {
    4879      3119763 :           struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
    4880      3119763 :           if (jfunc->type == IPA_JF_PASS_THROUGH
    4881      2293156 :               || jfunc->type == IPA_JF_ANCESTOR)
    4882              :             {
    4883       967960 :               int id = jfunc->type == IPA_JF_PASS_THROUGH
    4884       967960 :                        ? ipa_get_jf_pass_through_formal_id (jfunc)
    4885       141353 :                        : ipa_get_jf_ancestor_formal_id (jfunc);
    4886      1935837 :               if (id < (int) inlined_es->param.length ())
    4887              :                 {
    4888       967869 :                   int prob1 = es->param[i].change_prob;
    4889       967869 :                   int prob2 = inlined_es->param[id].change_prob;
    4890       967869 :                   int prob = combine_probabilities (prob1, prob2);
    4891              : 
    4892       967869 :                   if (prob1 && prob2 && !prob)
    4893       967869 :                     prob = 1;
    4894              : 
    4895       967869 :                   es->param[i].change_prob = prob;
    4896              : 
    4897      1935738 :                   if (inlined_es
    4898       967869 :                         ->param[id].points_to_local_or_readonly_memory)
    4899       269439 :                     es->param[i].points_to_local_or_readonly_memory = true;
    4900      1935738 :                   if (inlined_es
    4901       967869 :                         ->param[id].points_to_possible_sra_candidate)
    4902       177796 :                     es->param[i].points_to_possible_sra_candidate = true;
    4903              :                 }
    4904       967960 :               if (!es->param[i].points_to_local_or_readonly_memory
    4905              :                   && jfunc->type == IPA_JF_CONST
    4906              :                   && points_to_local_or_readonly_memory_p
    4907              :                          (ipa_get_jf_constant (jfunc)))
    4908              :                 es->param[i].points_to_local_or_readonly_memory = true;
    4909              :             }
    4910              :         }
    4911              :     }
    4912              : }
    4913              : 
    4914              : /* Update edge summaries of NODE after INLINED_EDGE has been inlined.
    4915              : 
    4916              :    Remap predicates of callees of NODE.  Rest of arguments match
    4917              :    remap_predicate.
    4918              : 
    4919              :    Also update change probabilities.  */
    4920              : 
    4921              : static void
    4922      4901990 : remap_edge_summaries (struct cgraph_edge *inlined_edge,
    4923              :                       struct cgraph_node *node,
    4924              :                       class ipa_fn_summary *info,
    4925              :                       class ipa_node_params *params_summary,
    4926              :                       class ipa_fn_summary *callee_info,
    4927              :                       const vec<int> &operand_map,
    4928              :                       const vec<HOST_WIDE_INT> &offset_map,
    4929              :                       const vec<bool> &agg_preserved_map,
    4930              :                       clause_t possible_truths,
    4931              :                       ipa_predicate *toplev_predicate)
    4932              : {
    4933      4901990 :   struct cgraph_edge *e, *next;
    4934      9484834 :   for (e = node->callees; e; e = next)
    4935              :     {
    4936      4582844 :       ipa_predicate p;
    4937      4582844 :       next = e->next_callee;
    4938              : 
    4939      4582844 :       if (e->inline_failed)
    4940              :         {
    4941      3858526 :           class ipa_call_summary *es = ipa_call_summaries->get (e);
    4942      3858526 :           remap_edge_params (inlined_edge, e);
    4943              : 
    4944      3858526 :           if (es->predicate)
    4945              :             {
    4946      1356329 :               p = es->predicate->remap_after_inlining
    4947      1356329 :                                      (info, params_summary,
    4948              :                                       callee_info, operand_map,
    4949              :                                       offset_map, agg_preserved_map,
    4950              :                                       possible_truths,
    4951              :                                       *toplev_predicate);
    4952      1356329 :               edge_set_predicate (e, &p);
    4953              :             }
    4954              :           else
    4955      2502197 :             edge_set_predicate (e, toplev_predicate);
    4956              :         }
    4957              :       else
    4958       724318 :         remap_edge_summaries (inlined_edge, e->callee, info,
    4959              :                               params_summary, callee_info,
    4960              :                               operand_map, offset_map, agg_preserved_map,
    4961              :                               possible_truths, toplev_predicate);
    4962              :     }
    4963      5019376 :   for (e = node->indirect_calls; e; e = next)
    4964              :     {
    4965       117386 :       class ipa_call_summary *es = ipa_call_summaries->get (e);
    4966       117386 :       ipa_predicate p;
    4967       117386 :       next = e->next_callee;
    4968              : 
    4969       117386 :       remap_edge_params (inlined_edge, e);
    4970       117386 :       if (es->predicate)
    4971              :         {
    4972        29495 :           p = es->predicate->remap_after_inlining
    4973        29495 :                                  (info, params_summary,
    4974              :                                   callee_info, operand_map, offset_map,
    4975              :                                   agg_preserved_map,
    4976              :                                   possible_truths, *toplev_predicate);
    4977        29495 :           edge_set_predicate (e, &p);
    4978              :         }
    4979              :       else
    4980        87891 :         edge_set_predicate (e, toplev_predicate);
    4981              :     }
    4982      4901990 : }
    4983              : 
    4984              : /* Run remap_after_inlining on each predicate in V.  */
    4985              : 
    4986              : static void
    4987      8355344 : remap_freqcounting_predicate (class ipa_fn_summary *info,
    4988              :                               class ipa_node_params *params_summary,
    4989              :                               class ipa_fn_summary *callee_info,
    4990              :                               vec<ipa_freqcounting_predicate, va_gc> *v,
    4991              :                               const vec<int> &operand_map,
    4992              :                               const vec<HOST_WIDE_INT> &offset_map,
    4993              :                               const vec<bool> &agg_preserved_map,
    4994              :                               clause_t possible_truths,
    4995              :                               ipa_predicate *toplev_predicate)
    4996              : 
    4997              : {
    4998      8355344 :   ipa_freqcounting_predicate *fcp;
    4999      8387284 :   for (int i = 0; vec_safe_iterate (v, i, &fcp); i++)
    5000              :     {
    5001        31940 :       ipa_predicate p
    5002        31940 :         = fcp->predicate->remap_after_inlining (info, params_summary,
    5003              :                                                 callee_info, operand_map,
    5004              :                                                 offset_map, agg_preserved_map,
    5005              :                                                 possible_truths,
    5006              :                                                 *toplev_predicate);
    5007        44266 :       if (p != false && p != true)
    5008         3730 :         *fcp->predicate &= p;
    5009              :     }
    5010      8355344 : }
    5011              : 
    5012              : /* We inlined EDGE.  Update summary of the function we inlined into.  */
    5013              : 
    5014              : void
    5015      4177672 : ipa_merge_fn_summary_after_inlining (struct cgraph_edge *edge)
    5016              : {
    5017      4177672 :   ipa_fn_summary *callee_info = ipa_fn_summaries->get (edge->callee);
    5018      3889245 :   struct cgraph_node *to = (edge->caller->inlined_to
    5019      4177672 :                             ? edge->caller->inlined_to : edge->caller);
    5020      4177672 :   class ipa_fn_summary *info = ipa_fn_summaries->get (to);
    5021      4177672 :   clause_t clause = 0;  /* not_inline is known to be false.  */
    5022      4177672 :   size_time_entry *e;
    5023      4177672 :   auto_vec<int, 8> operand_map;
    5024      4177672 :   auto_vec<HOST_WIDE_INT, 8> offset_map;
    5025      4177672 :   auto_vec<bool, 8> agg_preserved_map;
    5026      4177672 :   int i;
    5027      4177672 :   ipa_predicate toplev_predicate;
    5028      4177672 :   class ipa_call_summary *es = ipa_call_summaries->get (edge);
    5029      4177672 :   ipa_node_params *params_summary = (ipa_node_params_sum
    5030      4177672 :                                      ? ipa_node_params_sum->get (to) : NULL);
    5031              : 
    5032      4177672 :   if (es->predicate)
    5033       418744 :     toplev_predicate = *es->predicate;
    5034              :   else
    5035      3758928 :     toplev_predicate = true;
    5036              : 
    5037      4177672 :   info->fp_expressions |= callee_info->fp_expressions;
    5038      4177672 :   info->target_info |= callee_info->target_info;
    5039              : 
    5040      4177672 :   if (callee_info->conds)
    5041              :     {
    5042      3063110 :       ipa_auto_call_arg_values avals;
    5043      3063110 :       evaluate_properties_for_edge (edge, true, &clause, NULL, &avals, false);
    5044      3063110 :     }
    5045      4177672 :   if (ipa_node_params_sum && callee_info->conds)
    5046              :     {
    5047       827133 :       ipa_edge_args *args = ipa_edge_args_sum->get (edge);
    5048       827133 :       int count = args ? ipa_get_cs_argument_count (args) : 0;
    5049       826994 :       int i;
    5050              : 
    5051       826994 :       if (count)
    5052              :         {
    5053       826994 :           operand_map.safe_grow_cleared (count, true);
    5054       826994 :           offset_map.safe_grow_cleared (count, true);
    5055       826994 :           agg_preserved_map.safe_grow_cleared (count, true);
    5056              :         }
    5057      2660673 :       for (i = 0; i < count; i++)
    5058              :         {
    5059      1833540 :           struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
    5060      1833540 :           int map = -1;
    5061              : 
    5062              :           /* TODO: handle non-NOPs when merging.  */
    5063      1833540 :           if (jfunc->type == IPA_JF_PASS_THROUGH)
    5064              :             {
    5065       298460 :               if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
    5066              :                 {
    5067       294956 :                   map = ipa_get_jf_pass_through_formal_id (jfunc);
    5068       294956 :                   agg_preserved_map[i]
    5069       589912 :                     = ipa_get_jf_pass_through_agg_preserved (jfunc);
    5070              :                 }
    5071              :             }
    5072      1535080 :           else if (jfunc->type == IPA_JF_ANCESTOR)
    5073              :             {
    5074        95678 :               HOST_WIDE_INT offset = ipa_get_jf_ancestor_offset (jfunc);
    5075        95678 :               if (offset >= 0 && offset < INT_MAX)
    5076              :                 {
    5077        95678 :                   map = ipa_get_jf_ancestor_formal_id (jfunc);
    5078        95678 :                   offset_map[i] = offset;
    5079        95678 :                   agg_preserved_map[i]
    5080       191356 :                     = ipa_get_jf_ancestor_agg_preserved (jfunc);
    5081              :                 }
    5082              :             }
    5083      1833540 :           operand_map[i] = map;
    5084      3304438 :           gcc_assert (map < ipa_get_param_count (params_summary));
    5085              :         }
    5086              : 
    5087              :       int ip;
    5088       830055 :       for (i = 0; callee_info->builtin_constant_p_parms.iterate (i, &ip); i++)
    5089         2922 :         if (ip < count && operand_map[ip] >= 0)
    5090           62 :           add_builtin_constant_p_parm (info, operand_map[ip]);
    5091              :     }
    5092      4177672 :   sreal freq = edge->sreal_frequency ();
    5093     27857388 :   for (i = 0; callee_info->size_time_table.iterate (i, &e); i++)
    5094              :     {
    5095     19502044 :       ipa_predicate p;
    5096     19502044 :       p = e->exec_predicate.remap_after_inlining
    5097     19502044 :                              (info, params_summary,
    5098              :                               callee_info, operand_map,
    5099              :                               offset_map, agg_preserved_map, clause,
    5100              :                               toplev_predicate);
    5101     19502044 :       ipa_predicate nonconstp;
    5102     19502044 :       nonconstp = e->nonconst_predicate.remap_after_inlining
    5103     19502044 :                                      (info, params_summary,
    5104              :                                       callee_info, operand_map,
    5105              :                                       offset_map, agg_preserved_map, clause,
    5106              :                                       toplev_predicate);
    5107     29505329 :       if (p != false && nonconstp != false)
    5108              :         {
    5109      9616770 :           sreal add_time = ((sreal)e->time * freq);
    5110      9616770 :           int prob = e->nonconst_predicate.probability (callee_info->conds,
    5111              :                                                         clause, es->param);
    5112      9616770 :           if (prob != REG_BR_PROB_BASE)
    5113      1101394 :             add_time = add_time * prob / REG_BR_PROB_BASE;
    5114      1101394 :           if (prob != REG_BR_PROB_BASE
    5115      1101394 :               && dump_file && (dump_flags & TDF_DETAILS))
    5116              :             {
    5117            3 :               fprintf (dump_file, "\t\tScaling time by probability:%f\n",
    5118            3 :                        (double) prob / REG_BR_PROB_BASE);
    5119              :             }
    5120      9616770 :           info->account_size_time (e->size, add_time, p, nonconstp);
    5121              :         }
    5122              :     }
    5123      4177672 :   remap_edge_summaries (edge, edge->callee, info, params_summary,
    5124              :                         callee_info, operand_map,
    5125              :                         offset_map, agg_preserved_map, clause,
    5126              :                         &toplev_predicate);
    5127      4177672 :   remap_freqcounting_predicate (info, params_summary, callee_info,
    5128              :                                 info->loop_iterations, operand_map,
    5129              :                                 offset_map, agg_preserved_map, clause,
    5130              :                                 &toplev_predicate);
    5131      4177672 :   remap_freqcounting_predicate (info, params_summary, callee_info,
    5132              :                                 info->loop_strides, operand_map,
    5133              :                                 offset_map, agg_preserved_map, clause,
    5134              :                                 &toplev_predicate);
    5135              : 
    5136      4177672 :   HOST_WIDE_INT stack_frame_offset = ipa_get_stack_frame_offset (edge->callee);
    5137      4177672 :   HOST_WIDE_INT peak = stack_frame_offset + callee_info->estimated_stack_size;
    5138              : 
    5139      4177672 :   if (info->estimated_stack_size < peak)
    5140       126847 :     info->estimated_stack_size = peak;
    5141              : 
    5142      4177672 :   inline_update_callee_summaries (edge->callee, es->loop_depth);
    5143      4177672 :   if (info->call_size_time_table.length ())
    5144              :     {
    5145       889192 :       int edge_size = 0;
    5146       889192 :       sreal edge_time = 0;
    5147              : 
    5148       889192 :       estimate_edge_size_and_time (edge, &edge_size, NULL, &edge_time, NULL, 0);
    5149              :       /* Unaccount size and time of the optimized out call.  */
    5150       889192 :       info->account_size_time (-edge_size, -edge_time,
    5151       889192 :                                es->predicate ? *es->predicate : true,
    5152       889192 :                                es->predicate ? *es->predicate : true,
    5153              :                                true);
    5154              :       /* Account new calls.  */
    5155       889192 :       summarize_calls_size_and_time (edge->callee, info);
    5156              :     }
    5157              : 
    5158              :   /* Free summaries that are not maintained for inline clones/edges.  */
    5159      4177672 :   ipa_call_summaries->remove (edge);
    5160      4177672 :   ipa_fn_summaries->remove (edge->callee);
    5161      4177672 :   ipa_remove_from_growth_caches (edge);
    5162      4177672 : }
    5163              : 
    5164              : /* For performance reasons ipa_merge_fn_summary_after_inlining is not updating
    5165              :    overall size and time.  Recompute it.
    5166              :    If RESET is true also recompute call_time_size_table.  */
    5167              : 
    5168              : void
    5169      9799353 : ipa_update_overall_fn_summary (struct cgraph_node *node, bool reset)
    5170              : {
    5171      9799353 :   class ipa_fn_summary *info = ipa_fn_summaries->get (node);
    5172      9799353 :   class ipa_size_summary *size_info = ipa_size_summaries->get (node);
    5173      9799353 :   size_time_entry *e;
    5174      9799353 :   int i;
    5175              : 
    5176      9799353 :   size_info->size = 0;
    5177      9799353 :   info->time = 0;
    5178     54933964 :   for (i = 0; info->size_time_table.iterate (i, &e); i++)
    5179              :     {
    5180     45134611 :       size_info->size += e->size;
    5181     45134611 :       info->time += e->time;
    5182              :     }
    5183      9799353 :   info->min_size = info->size_time_table[0].size;
    5184      9799353 :   if (reset)
    5185      8867743 :     info->call_size_time_table.release ();
    5186      9799353 :   if (node->callees || node->indirect_calls)
    5187      7452712 :     estimate_calls_size_and_time (node, &size_info->size, &info->min_size,
    5188              :                                   &info->time, NULL,
    5189              :                                   ~(clause_t) (1 << ipa_predicate::false_condition),
    5190              :                                   NULL);
    5191      9799353 :   size_info->size = RDIV (size_info->size, ipa_fn_summary::size_scale);
    5192      9799353 :   info->min_size = RDIV (info->min_size, ipa_fn_summary::size_scale);
    5193      9799353 : }
    5194              : 
    5195              : 
    5196              : /* This function performs intraprocedural analysis in NODE that is required to
    5197              :    inline indirect calls.  */
    5198              : 
    5199              : static void
    5200      1420273 : inline_indirect_intraprocedural_analysis (struct cgraph_node *node)
    5201              : {
    5202      1420273 :   ipa_analyze_node (node);
    5203      1420273 :   if (dump_file && (dump_flags & TDF_DETAILS))
    5204              :     {
    5205           61 :       ipa_print_node_params (dump_file, node);
    5206           61 :       ipa_print_node_jump_functions (dump_file, node);
    5207              :     }
    5208      1420273 : }
    5209              : 
    5210              : 
    5211              : /* Note function body size.  */
    5212              : 
    5213              : void
    5214      1431795 : inline_analyze_function (struct cgraph_node *node)
    5215              : {
    5216      1431795 :   push_cfun (DECL_STRUCT_FUNCTION (node->decl));
    5217              : 
    5218      1431795 :   if (dump_file)
    5219          141 :     fprintf (dump_file, "\nAnalyzing function: %s\n", node->dump_name ());
    5220      1431795 :   if (opt_for_fn (node->decl, optimize) && !node->thunk)
    5221      1420273 :     inline_indirect_intraprocedural_analysis (node);
    5222      1431795 :   compute_fn_summary (node, false);
    5223      1431795 :   if (!optimize)
    5224              :     {
    5225        10186 :       struct cgraph_edge *e;
    5226        22987 :       for (e = node->callees; e; e = e->next_callee)
    5227        12801 :         e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
    5228        10260 :       for (e = node->indirect_calls; e; e = e->next_callee)
    5229           74 :         e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
    5230              :     }
    5231              : 
    5232      1431795 :   pop_cfun ();
    5233      1431795 : }
    5234              : 
    5235              : 
    5236              : /* Called when new function is inserted to callgraph late.  */
    5237              : 
    5238              : void
    5239        20140 : ipa_fn_summary_t::insert (struct cgraph_node *node, ipa_fn_summary *)
    5240              : {
    5241        20140 :   inline_analyze_function (node);
    5242        20140 : }
    5243              : 
    5244              : /* Note function body size.  */
    5245              : 
    5246              : static void
    5247       243121 : ipa_fn_summary_generate (void)
    5248              : {
    5249       243121 :   struct cgraph_node *node;
    5250              : 
    5251      2177616 :   FOR_EACH_DEFINED_FUNCTION (node)
    5252      1934495 :     if (DECL_STRUCT_FUNCTION (node->decl))
    5253      1920650 :       node->versionable = tree_versionable_function_p (node->decl);
    5254              : 
    5255       243121 :   ipa_fn_summary_alloc ();
    5256              : 
    5257       243121 :   ipa_fn_summaries->enable_insertion_hook ();
    5258              : 
    5259       243121 :   ipa_register_cgraph_hooks ();
    5260              : 
    5261      2177616 :   FOR_EACH_DEFINED_FUNCTION (node)
    5262      1934495 :     if (!node->alias
    5263      1934495 :         && (flag_generate_lto || flag_generate_offload|| flag_wpa
    5264      1737561 :             || opt_for_fn (node->decl, optimize)))
    5265      1392711 :       inline_analyze_function (node);
    5266       243121 : }
    5267              : 
    5268              : 
    5269              : /* Write inline summary for edge E to OB.  */
    5270              : 
    5271              : static void
    5272       351617 : read_ipa_call_summary (class lto_input_block *ib, struct cgraph_edge *e,
    5273              :                        bool prevails)
    5274              : {
    5275       351617 :   class ipa_call_summary *es = prevails
    5276       351617 :                                 ? ipa_call_summaries->get_create (e) : NULL;
    5277       351617 :   ipa_predicate p;
    5278       351617 :   int length, i;
    5279              : 
    5280       351617 :   int size = streamer_read_uhwi (ib);
    5281       351617 :   int time = streamer_read_uhwi (ib);
    5282       351617 :   int depth = streamer_read_uhwi (ib);
    5283              : 
    5284       351617 :   if (es)
    5285              :     {
    5286       351564 :       es->call_stmt_size = size;
    5287       351564 :       es->call_stmt_time = time;
    5288       351564 :       es->loop_depth = depth;
    5289              :     }
    5290              : 
    5291       351617 :   bitpack_d bp = streamer_read_bitpack (ib);
    5292       351617 :   if (es)
    5293       351564 :     es->is_return_callee_uncaptured = bp_unpack_value (&bp, 1);
    5294              :   else
    5295           53 :     bp_unpack_value (&bp, 1);
    5296              : 
    5297       351617 :   p.stream_in (ib);
    5298       351617 :   if (es)
    5299       351564 :     edge_set_predicate (e, &p);
    5300       351617 :   length = streamer_read_uhwi (ib);
    5301       351617 :   if (length && es
    5302       351617 :       && (e->possibly_call_in_translation_unit_p ()
    5303              :           /* Also stream in jump functions to builtins in hope that they
    5304              :              will get fnspecs.  */
    5305       119863 :           || fndecl_built_in_p (e->callee->decl, BUILT_IN_NORMAL)))
    5306              :     {
    5307       235009 :       es->param.safe_grow_cleared (length, true);
    5308      1043033 :       for (i = 0; i < length; i++)
    5309              :         {
    5310       573015 :           es->param[i].change_prob = streamer_read_uhwi (ib);
    5311       573015 :           bitpack_d bp = streamer_read_bitpack (ib);
    5312      1719045 :           es->param[i].points_to_local_or_readonly_memory
    5313       573015 :             = bp_unpack_value (&bp, 1);
    5314      1719045 :           es->param[i].points_to_possible_sra_candidate
    5315       573015 :             = bp_unpack_value (&bp, 1);
    5316              :         }
    5317              :     }
    5318              :   else
    5319              :     {
    5320       140058 :       for (i = 0; i < length; i++)
    5321              :         {
    5322        23450 :           streamer_read_uhwi (ib);
    5323        23450 :           streamer_read_uhwi (ib);
    5324              :         }
    5325              :     }
    5326       351617 : }
    5327              : 
    5328              : 
    5329              : /* Stream in inline summaries from the section.  */
    5330              : 
    5331              : static void
    5332        14574 : inline_read_section (struct lto_file_decl_data *file_data, const char *data,
    5333              :                      size_t len)
    5334              : {
    5335        14574 :   const struct lto_function_header *header =
    5336              :     (const struct lto_function_header *) data;
    5337        14574 :   const int cfg_offset = sizeof (struct lto_function_header);
    5338        14574 :   const int main_offset = cfg_offset + header->cfg_size;
    5339        14574 :   const int string_offset = main_offset + header->main_size;
    5340        14574 :   class data_in *data_in;
    5341        14574 :   unsigned int i, count2, j;
    5342        14574 :   unsigned int f_count;
    5343              : 
    5344        14574 :   lto_input_block ib ((const char *) data + main_offset, header->main_size,
    5345        14574 :                       file_data);
    5346              : 
    5347        14574 :   data_in =
    5348        29148 :     lto_data_in_create (file_data, (const char *) data + string_offset,
    5349        14574 :                         header->string_size, vNULL);
    5350        14574 :   f_count = streamer_read_uhwi (&ib);
    5351       103903 :   for (i = 0; i < f_count; i++)
    5352              :     {
    5353        89329 :       unsigned int index;
    5354        89329 :       struct cgraph_node *node;
    5355        89329 :       class ipa_fn_summary *info;
    5356        89329 :       class ipa_node_params *params_summary;
    5357        89329 :       class ipa_size_summary *size_info;
    5358        89329 :       lto_symtab_encoder_t encoder;
    5359        89329 :       struct bitpack_d bp;
    5360        89329 :       struct cgraph_edge *e;
    5361        89329 :       ipa_predicate p;
    5362              : 
    5363        89329 :       index = streamer_read_uhwi (&ib);
    5364        89329 :       encoder = file_data->symtab_node_encoder;
    5365        89329 :       node = dyn_cast<cgraph_node *> (lto_symtab_encoder_deref (encoder,
    5366              :                                                                 index));
    5367        89329 :       info = node->prevailing_p () ? ipa_fn_summaries->get_create (node) : NULL;
    5368        89329 :       params_summary = node->prevailing_p ()
    5369        89329 :                        ? ipa_node_params_sum->get (node) : NULL;
    5370        89329 :       size_info = node->prevailing_p ()
    5371        89329 :                   ? ipa_size_summaries->get_create (node) : NULL;
    5372              : 
    5373        89329 :       int stack_size = streamer_read_uhwi (&ib);
    5374        89329 :       int size = streamer_read_uhwi (&ib);
    5375        89329 :       sreal time = sreal::stream_in (&ib);
    5376              : 
    5377        89329 :       if (info)
    5378              :         {
    5379        89269 :           info->estimated_stack_size
    5380        89269 :             = size_info->estimated_self_stack_size = stack_size;
    5381        89269 :           size_info->size = size_info->self_size = size;
    5382        89269 :           info->time = time;
    5383              :         }
    5384              : 
    5385        89329 :       bp = streamer_read_bitpack (&ib);
    5386        89329 :       if (info)
    5387              :         {
    5388        89269 :           info->inlinable = bp_unpack_value (&bp, 1);
    5389        89269 :           info->fp_expressions = bp_unpack_value (&bp, 1);
    5390        89269 :           if (!lto_stream_offload_p)
    5391        89269 :             info->target_info = streamer_read_uhwi (&ib);
    5392              :         }
    5393              :       else
    5394              :         {
    5395           60 :           bp_unpack_value (&bp, 1);
    5396           60 :           bp_unpack_value (&bp, 1);
    5397           60 :           if (!lto_stream_offload_p)
    5398           60 :             streamer_read_uhwi (&ib);
    5399              :         }
    5400              : 
    5401        89329 :       count2 = streamer_read_uhwi (&ib);
    5402        89329 :       gcc_assert (!info || !info->conds);
    5403        89269 :       if (info)
    5404        89269 :         vec_safe_reserve_exact (info->conds, count2);
    5405       171931 :       for (j = 0; j < count2; j++)
    5406              :         {
    5407        82602 :           struct condition c;
    5408        82602 :           unsigned int k, count3;
    5409        82602 :           c.operand_num = streamer_read_uhwi (&ib);
    5410        82602 :           c.code = (enum tree_code) streamer_read_uhwi (&ib);
    5411        82602 :           c.type = stream_read_tree (&ib, data_in);
    5412        82602 :           c.val = stream_read_tree (&ib, data_in);
    5413        82602 :           bp = streamer_read_bitpack (&ib);
    5414        82602 :           c.agg_contents = bp_unpack_value (&bp, 1);
    5415        82602 :           c.by_ref = bp_unpack_value (&bp, 1);
    5416        82602 :           c.maybe_modified = bp_unpack_value (&bp, 1);
    5417        82602 :           c.unknown_offset = bp_unpack_value (&bp, 1);
    5418        82602 :           if (c.unknown_offset)
    5419         1200 :             c.offset = -1;
    5420        81402 :           else if (c.agg_contents)
    5421        14293 :             c.offset = streamer_read_uhwi (&ib);
    5422              :           else
    5423        67109 :             c.offset = 0;
    5424        82602 :           count3 = streamer_read_uhwi (&ib);
    5425        82602 :           c.param_ops = NULL;
    5426        82602 :           if (info)
    5427        82594 :             vec_safe_reserve_exact (c.param_ops, count3);
    5428        82602 :           if (params_summary)
    5429        82594 :             ipa_set_param_used_by_ipa_predicates
    5430        82594 :                     (params_summary, c.operand_num, true);
    5431        86631 :           for (k = 0; k < count3; k++)
    5432              :             {
    5433         4029 :               struct expr_eval_op op;
    5434         4029 :               enum gimple_rhs_class rhs_class;
    5435         4029 :               op.code = (enum tree_code) streamer_read_uhwi (&ib);
    5436         4029 :               op.type = stream_read_tree (&ib, data_in);
    5437         4029 :               switch (rhs_class = get_gimple_rhs_class (op.code))
    5438              :                 {
    5439         1648 :                 case GIMPLE_UNARY_RHS:
    5440         1648 :                   op.index = 0;
    5441         1648 :                   op.val[0] = NULL_TREE;
    5442         1648 :                   op.val[1] = NULL_TREE;
    5443         1648 :                   break;
    5444              : 
    5445         2381 :                 case GIMPLE_BINARY_RHS:
    5446         2381 :                 case GIMPLE_TERNARY_RHS:
    5447         2381 :                   bp = streamer_read_bitpack (&ib);
    5448         2381 :                   op.index = bp_unpack_value (&bp, 2);
    5449         2381 :                   op.val[0] = stream_read_tree (&ib, data_in);
    5450         2381 :                   if (rhs_class == GIMPLE_BINARY_RHS)
    5451         2379 :                     op.val[1] = NULL_TREE;
    5452              :                   else
    5453            2 :                     op.val[1] = stream_read_tree (&ib, data_in);
    5454              :                   break;
    5455              : 
    5456            0 :                 default:
    5457            0 :                   fatal_error (UNKNOWN_LOCATION,
    5458              :                                "invalid fnsummary in LTO stream");
    5459              :                 }
    5460         4029 :               if (info)
    5461         4021 :                 c.param_ops->quick_push (op);
    5462              :             }
    5463        82602 :           if (info)
    5464        82594 :             info->conds->quick_push (c);
    5465              :         }
    5466        89329 :       count2 = streamer_read_uhwi (&ib);
    5467        89329 :       gcc_assert (!info || !info->size_time_table.length ());
    5468        89329 :       if (info && count2)
    5469        89269 :         info->size_time_table.reserve_exact (count2);
    5470       343226 :       for (j = 0; j < count2; j++)
    5471              :         {
    5472       253897 :           class size_time_entry e;
    5473              : 
    5474       253897 :           e.size = streamer_read_uhwi (&ib);
    5475       253897 :           e.time = sreal::stream_in (&ib);
    5476       253897 :           e.exec_predicate.stream_in (&ib);
    5477       253897 :           e.nonconst_predicate.stream_in (&ib);
    5478              : 
    5479       253897 :           if (info)
    5480       253769 :             info->size_time_table.quick_push (e);
    5481              :         }
    5482              : 
    5483        89329 :       count2 = streamer_read_uhwi (&ib);
    5484        90940 :       for (j = 0; j < count2; j++)
    5485              :         {
    5486         1611 :           p.stream_in (&ib);
    5487         1611 :           sreal fcp_freq = sreal::stream_in (&ib);
    5488         1611 :           if (info)
    5489              :             {
    5490         1611 :               ipa_freqcounting_predicate fcp;
    5491         1611 :               fcp.predicate = NULL;
    5492         1611 :               set_hint_predicate (&fcp.predicate, p);
    5493         1611 :               fcp.freq = fcp_freq;
    5494         1611 :               vec_safe_push (info->loop_iterations, fcp);
    5495              :             }
    5496              :         }
    5497        89329 :       count2 = streamer_read_uhwi (&ib);
    5498        89620 :       for (j = 0; j < count2; j++)
    5499              :         {
    5500          291 :           p.stream_in (&ib);
    5501          291 :           sreal fcp_freq = sreal::stream_in (&ib);
    5502          291 :           if (info)
    5503              :             {
    5504          291 :               ipa_freqcounting_predicate fcp;
    5505          291 :               fcp.predicate = NULL;
    5506          291 :               set_hint_predicate (&fcp.predicate, p);
    5507          291 :               fcp.freq = fcp_freq;
    5508          291 :               vec_safe_push (info->loop_strides, fcp);
    5509              :             }
    5510              :         }
    5511        89329 :       count2 = streamer_read_uhwi (&ib);
    5512        89329 :       if (info && count2)
    5513            8 :         info->builtin_constant_p_parms.reserve_exact (count2);
    5514        89337 :       for (j = 0; j < count2; j++)
    5515              :         {
    5516            8 :           int parm = streamer_read_uhwi (&ib);
    5517            8 :           if (info)
    5518            8 :             info->builtin_constant_p_parms.quick_push (parm);
    5519              :         }
    5520       439442 :       for (e = node->callees; e; e = e->next_callee)
    5521       350113 :         read_ipa_call_summary (&ib, e, info != NULL);
    5522        90833 :       for (e = node->indirect_calls; e; e = e->next_callee)
    5523         1504 :         read_ipa_call_summary (&ib, e, info != NULL);
    5524              :     }
    5525              : 
    5526        14574 :   lto_free_section_data (file_data, LTO_section_ipa_fn_summary, NULL, data,
    5527              :                          len);
    5528        14574 :   lto_data_in_delete (data_in);
    5529        14574 : }
    5530              : 
    5531              : 
    5532              : /* Read inline summary.  Jump functions are shared among ipa-cp
    5533              :    and inliner, so when ipa-cp is active, we don't need to write them
    5534              :    twice.  */
    5535              : 
    5536              : static void
    5537        13453 : ipa_fn_summary_read (void)
    5538              : {
    5539        13453 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    5540        13453 :   struct lto_file_decl_data *file_data;
    5541        13453 :   unsigned int j = 0;
    5542              : 
    5543        13453 :   ipa_prop_read_jump_functions ();
    5544        13453 :   ipa_fn_summary_alloc ();
    5545              : 
    5546        41480 :   while ((file_data = file_data_vec[j++]))
    5547              :     {
    5548        14574 :       size_t len;
    5549        14574 :       const char *data
    5550        14574 :         = lto_get_summary_section_data (file_data, LTO_section_ipa_fn_summary,
    5551              :                                         &len);
    5552        14574 :       if (data)
    5553        14574 :         inline_read_section (file_data, data, len);
    5554              :       else
    5555              :         /* Fatal error here.  We do not want to support compiling ltrans units
    5556              :            with different version of compiler or different flags than the WPA
    5557              :            unit, so this should never happen.  */
    5558            0 :         fatal_error (input_location,
    5559              :                      "ipa inline summary is missing in input file");
    5560              :     }
    5561        13453 :   ipa_register_cgraph_hooks ();
    5562              : 
    5563        13453 :   gcc_assert (ipa_fn_summaries);
    5564        13453 :   ipa_fn_summaries->enable_insertion_hook ();
    5565        13453 : }
    5566              : 
    5567              : 
    5568              : /* Write inline summary for edge E to OB.  */
    5569              : 
    5570              : static void
    5571       383473 : write_ipa_call_summary (struct output_block *ob, struct cgraph_edge *e)
    5572              : {
    5573       383473 :   class ipa_call_summary *es = ipa_call_summaries->get (e);
    5574       383473 :   int i;
    5575              : 
    5576       383473 :   streamer_write_uhwi (ob, es->call_stmt_size);
    5577       383473 :   streamer_write_uhwi (ob, es->call_stmt_time);
    5578       383473 :   streamer_write_uhwi (ob, es->loop_depth);
    5579              : 
    5580       383473 :   bitpack_d bp = bitpack_create (ob->main_stream);
    5581       383473 :   bp_pack_value (&bp, es->is_return_callee_uncaptured, 1);
    5582       383473 :   streamer_write_bitpack (&bp);
    5583              : 
    5584       383473 :   if (es->predicate)
    5585        11378 :     es->predicate->stream_out (ob);
    5586              :   else
    5587       372095 :     streamer_write_uhwi (ob, 0);
    5588       383473 :   streamer_write_uhwi (ob, es->param.length ());
    5589      2312736 :   for (i = 0; i < (int) es->param.length (); i++)
    5590              :     {
    5591       637320 :       streamer_write_uhwi (ob, es->param[i].change_prob);
    5592       637320 :       bp = bitpack_create (ob->main_stream);
    5593       637320 :       bp_pack_value (&bp, es->param[i].points_to_local_or_readonly_memory, 1);
    5594       637320 :       bp_pack_value (&bp, es->param[i].points_to_possible_sra_candidate, 1);
    5595       637320 :       streamer_write_bitpack (&bp);
    5596              :     }
    5597       383473 : }
    5598              : 
    5599              : 
    5600              : /* Write inline summary for node in SET.
    5601              :    Jump functions are shared among ipa-cp and inliner, so when ipa-cp is
    5602              :    active, we don't need to write them twice.  */
    5603              : 
    5604              : static void
    5605        24845 : ipa_fn_summary_write (void)
    5606              : {
    5607        24845 :   struct output_block *ob = create_output_block (LTO_section_ipa_fn_summary);
    5608        24845 :   lto_symtab_encoder_iterator lsei;
    5609        24845 :   lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
    5610        24845 :   unsigned int count = 0;
    5611              : 
    5612       133618 :   for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
    5613       108773 :        lsei_next_function_in_partition (&lsei))
    5614              :     {
    5615       108773 :       cgraph_node *cnode = lsei_cgraph_node (lsei);
    5616       108773 :       if (cnode->definition && !cnode->alias)
    5617       106291 :         count++;
    5618              :     }
    5619        24845 :   streamer_write_uhwi (ob, count);
    5620              : 
    5621       133618 :   for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
    5622       108773 :        lsei_next_function_in_partition (&lsei))
    5623              :     {
    5624       108773 :       cgraph_node *cnode = lsei_cgraph_node (lsei);
    5625       108773 :       if (cnode->definition && !cnode->alias)
    5626              :         {
    5627       106291 :           class ipa_fn_summary *info = ipa_fn_summaries->get (cnode);
    5628       106291 :           class ipa_size_summary *size_info = ipa_size_summaries->get (cnode);
    5629       106291 :           struct bitpack_d bp;
    5630       106291 :           struct cgraph_edge *edge;
    5631       106291 :           int i;
    5632       106291 :           size_time_entry *e;
    5633       106291 :           struct condition *c;
    5634              : 
    5635       106291 :           streamer_write_uhwi (ob, lto_symtab_encoder_encode (encoder, cnode));
    5636       106291 :           streamer_write_hwi (ob, size_info->estimated_self_stack_size);
    5637       106291 :           streamer_write_hwi (ob, size_info->self_size);
    5638       106291 :           info->time.stream_out (ob);
    5639       106291 :           bp = bitpack_create (ob->main_stream);
    5640       106291 :           bp_pack_value (&bp, info->inlinable, 1);
    5641       106291 :           bp_pack_value (&bp, info->fp_expressions, 1);
    5642       106291 :           streamer_write_bitpack (&bp);
    5643       106291 :           if (!lto_stream_offload_p)
    5644       106291 :             streamer_write_uhwi (ob, info->target_info);
    5645       106291 :           streamer_write_uhwi (ob, vec_safe_length (info->conds));
    5646       313081 :           for (i = 0; vec_safe_iterate (info->conds, i, &c); i++)
    5647              :             {
    5648       100499 :               int j;
    5649       100499 :               struct expr_eval_op *op;
    5650              : 
    5651       100499 :               streamer_write_uhwi (ob, c->operand_num);
    5652       100499 :               streamer_write_uhwi (ob, c->code);
    5653       100499 :               stream_write_tree (ob, c->type, true);
    5654       100499 :               stream_write_tree (ob, c->val, true);
    5655       100499 :               bp = bitpack_create (ob->main_stream);
    5656       100499 :               bp_pack_value (&bp, c->agg_contents, 1);
    5657       100499 :               bp_pack_value (&bp, c->by_ref, 1);
    5658       100499 :               bp_pack_value (&bp, c->maybe_modified, 1);
    5659       100499 :               bp_pack_value (&bp, c->unknown_offset, 1);
    5660       100499 :               streamer_write_bitpack (&bp);
    5661       100499 :               if (c->agg_contents && !c->unknown_offset)
    5662        18760 :                 streamer_write_uhwi (ob, c->offset);
    5663       100499 :               streamer_write_uhwi (ob, vec_safe_length (c->param_ops));
    5664       209199 :               for (j = 0; vec_safe_iterate (c->param_ops, j, &op); j++)
    5665              :                 {
    5666         4824 :                   streamer_write_uhwi (ob, op->code);
    5667         4824 :                   stream_write_tree (ob, op->type, true);
    5668         4824 :                   if (op->val[0])
    5669              :                     {
    5670         2869 :                       bp = bitpack_create (ob->main_stream);
    5671         2869 :                       bp_pack_value (&bp, op->index, 2);
    5672         2869 :                       streamer_write_bitpack (&bp);
    5673         2869 :                       stream_write_tree (ob, op->val[0], true);
    5674         2869 :                       if (op->val[1])
    5675            6 :                         stream_write_tree (ob, op->val[1], true);
    5676              :                     }
    5677              :                 }
    5678              :             }
    5679       106291 :           streamer_write_uhwi (ob, info->size_time_table.length ());
    5680       519537 :           for (i = 0; info->size_time_table.iterate (i, &e); i++)
    5681              :             {
    5682       306955 :               streamer_write_uhwi (ob, e->size);
    5683       306955 :               e->time.stream_out (ob);
    5684       306955 :               e->exec_predicate.stream_out (ob);
    5685       306955 :               e->nonconst_predicate.stream_out (ob);
    5686              :             }
    5687       106291 :           ipa_freqcounting_predicate *fcp;
    5688       106291 :           streamer_write_uhwi (ob, vec_safe_length (info->loop_iterations));
    5689       214892 :           for (i = 0; vec_safe_iterate (info->loop_iterations, i, &fcp); i++)
    5690              :             {
    5691         2310 :               fcp->predicate->stream_out (ob);
    5692         2310 :               fcp->freq.stream_out (ob);
    5693              :             }
    5694       106291 :           streamer_write_uhwi (ob, vec_safe_length (info->loop_strides));
    5695       212930 :           for (i = 0; vec_safe_iterate (info->loop_strides, i, &fcp); i++)
    5696              :             {
    5697          348 :               fcp->predicate->stream_out (ob);
    5698          348 :               fcp->freq.stream_out (ob);
    5699              :             }
    5700       106291 :           streamer_write_uhwi (ob, info->builtin_constant_p_parms.length ());
    5701       106291 :           int ip;
    5702       212598 :           for (i = 0; info->builtin_constant_p_parms.iterate (i, &ip);
    5703              :                i++)
    5704           16 :             streamer_write_uhwi (ob, ip);
    5705       487052 :           for (edge = cnode->callees; edge; edge = edge->next_callee)
    5706       380761 :             write_ipa_call_summary (ob, edge);
    5707       109003 :           for (edge = cnode->indirect_calls; edge; edge = edge->next_callee)
    5708         2712 :             write_ipa_call_summary (ob, edge);
    5709              :         }
    5710              :     }
    5711        24845 :   streamer_write_char_stream (ob->main_stream, 0);
    5712        24845 :   produce_asm (ob);
    5713        24845 :   destroy_output_block (ob);
    5714              : 
    5715        24845 :   ipa_prop_write_jump_functions ();
    5716        24845 : }
    5717              : 
    5718              : 
    5719              : /* Release function summary.  */
    5720              : 
    5721              : void
    5722       760100 : ipa_free_fn_summary (void)
    5723              : {
    5724       760100 :   if (!ipa_call_summaries)
    5725              :     return;
    5726       481455 :   ggc_delete (ipa_fn_summaries);
    5727       481455 :   ipa_fn_summaries = NULL;
    5728       481455 :   delete ipa_call_summaries;
    5729       481455 :   ipa_call_summaries = NULL;
    5730       481455 :   edge_predicate_pool.release ();
    5731              :   /* During IPA this is one of largest datastructures to release.  */
    5732       481455 :   if (flag_wpa)
    5733         8765 :     ggc_trim ();
    5734              : }
    5735              : 
    5736              : /* Release function summary.  */
    5737              : 
    5738              : void
    5739       760100 : ipa_free_size_summary (void)
    5740              : {
    5741       760100 :   if (!ipa_size_summaries)
    5742              :     return;
    5743       481455 :   delete ipa_size_summaries;
    5744       481455 :   ipa_size_summaries = NULL;
    5745              : }
    5746              : 
    5747              : namespace {
    5748              : 
    5749              : const pass_data pass_data_local_fn_summary =
    5750              : {
    5751              :   GIMPLE_PASS, /* type */
    5752              :   "local-fnsummary", /* name */
    5753              :   OPTGROUP_INLINE, /* optinfo_flags */
    5754              :   TV_INLINE_PARAMETERS, /* tv_id */
    5755              :   0, /* properties_required */
    5756              :   0, /* properties_provided */
    5757              :   0, /* properties_destroyed */
    5758              :   0, /* todo_flags_start */
    5759              :   0, /* todo_flags_finish */
    5760              : };
    5761              : 
    5762              : class pass_local_fn_summary : public gimple_opt_pass
    5763              : {
    5764              : public:
    5765       605970 :   pass_local_fn_summary (gcc::context *ctxt)
    5766      1211940 :     : gimple_opt_pass (pass_data_local_fn_summary, ctxt)
    5767              :   {}
    5768              : 
    5769              :   /* opt_pass methods: */
    5770       302985 :   opt_pass * clone () final override
    5771              :   {
    5772       302985 :     return new pass_local_fn_summary (m_ctxt);
    5773              :   }
    5774      5995490 :   unsigned int execute (function *) final override
    5775              :     {
    5776      5995490 :       return compute_fn_summary_for_current ();
    5777              :     }
    5778              : 
    5779              : }; // class pass_local_fn_summary
    5780              : 
    5781              : } // anon namespace
    5782              : 
    5783              : gimple_opt_pass *
    5784       302985 : make_pass_local_fn_summary (gcc::context *ctxt)
    5785              : {
    5786       302985 :   return new pass_local_fn_summary (ctxt);
    5787              : }
    5788              : 
    5789              : 
    5790              : /* Free inline summary.  */
    5791              : 
    5792              : namespace {
    5793              : 
    5794              : const pass_data pass_data_ipa_free_fn_summary =
    5795              : {
    5796              :   SIMPLE_IPA_PASS, /* type */
    5797              :   "free-fnsummary", /* name */
    5798              :   OPTGROUP_NONE, /* optinfo_flags */
    5799              :   TV_IPA_FREE_INLINE_SUMMARY, /* tv_id */
    5800              :   0, /* properties_required */
    5801              :   0, /* properties_provided */
    5802              :   0, /* properties_destroyed */
    5803              :   0, /* todo_flags_start */
    5804              :   0, /* todo_flags_finish */
    5805              : };
    5806              : 
    5807              : class pass_ipa_free_fn_summary : public simple_ipa_opt_pass
    5808              : {
    5809              : public:
    5810       605970 :   pass_ipa_free_fn_summary (gcc::context *ctxt)
    5811              :     : simple_ipa_opt_pass (pass_data_ipa_free_fn_summary, ctxt),
    5812      1211940 :       small_p (false)
    5813              :   {}
    5814              : 
    5815              :   /* opt_pass methods: */
    5816       302985 :   opt_pass *clone () final override
    5817              :   {
    5818       302985 :     return new pass_ipa_free_fn_summary (m_ctxt);
    5819              :   }
    5820       605970 :   void set_pass_param (unsigned int n, bool param) final override
    5821              :     {
    5822       605970 :       gcc_assert (n == 0);
    5823       605970 :       small_p = param;
    5824       605970 :     }
    5825       509329 :   bool gate (function *) final override { return true; }
    5826       486710 :   unsigned int execute (function *) final override
    5827              :     {
    5828       486710 :       ipa_free_fn_summary ();
    5829              :       /* Free ipa-prop structures if they are no longer needed.  */
    5830       486710 :       ipa_free_all_structures_after_iinln ();
    5831       486710 :       if (!flag_wpa)
    5832       477945 :         ipa_free_size_summary ();
    5833       486710 :       return 0;
    5834              :     }
    5835              : 
    5836              : private:
    5837              :   bool small_p;
    5838              : }; // class pass_ipa_free_fn_summary
    5839              : 
    5840              : } // anon namespace
    5841              : 
    5842              : simple_ipa_opt_pass *
    5843       302985 : make_pass_ipa_free_fn_summary (gcc::context *ctxt)
    5844              : {
    5845       302985 :   return new pass_ipa_free_fn_summary (ctxt);
    5846              : }
    5847              : 
    5848              : namespace {
    5849              : 
    5850              : const pass_data pass_data_ipa_fn_summary =
    5851              : {
    5852              :   IPA_PASS, /* type */
    5853              :   "fnsummary", /* name */
    5854              :   OPTGROUP_INLINE, /* optinfo_flags */
    5855              :   TV_IPA_FNSUMMARY, /* tv_id */
    5856              :   0, /* properties_required */
    5857              :   0, /* properties_provided */
    5858              :   0, /* properties_destroyed */
    5859              :   0, /* todo_flags_start */
    5860              :   ( TODO_dump_symtab ), /* todo_flags_finish */
    5861              : };
    5862              : 
    5863              : class pass_ipa_fn_summary : public ipa_opt_pass_d
    5864              : {
    5865              : public:
    5866       302985 :   pass_ipa_fn_summary (gcc::context *ctxt)
    5867              :     : ipa_opt_pass_d (pass_data_ipa_fn_summary, ctxt,
    5868              :                       ipa_fn_summary_generate, /* generate_summary */
    5869              :                       ipa_fn_summary_write, /* write_summary */
    5870              :                       ipa_fn_summary_read, /* read_summary */
    5871              :                       NULL, /* write_optimization_summary */
    5872              :                       NULL, /* read_optimization_summary */
    5873              :                       NULL, /* stmt_fixup */
    5874              :                       0, /* function_transform_todo_flags_start */
    5875              :                       NULL, /* function_transform */
    5876       302985 :                       NULL) /* variable_transform */
    5877       302985 :   {}
    5878              : 
    5879              :   /* opt_pass methods: */
    5880       243439 :   unsigned int execute (function *) final override { return 0; }
    5881              : 
    5882              : }; // class pass_ipa_fn_summary
    5883              : 
    5884              : } // anon namespace
    5885              : 
    5886              : ipa_opt_pass_d *
    5887       302985 : make_pass_ipa_fn_summary (gcc::context *ctxt)
    5888              : {
    5889       302985 :   return new pass_ipa_fn_summary (ctxt);
    5890              : }
    5891              : 
    5892              : /* Reset all state within ipa-fnsummary.cc so that we can rerun the compiler
    5893              :    within the same process.  For use by toplev::finalize.  */
    5894              : 
    5895              : void
    5896       272484 : ipa_fnsummary_cc_finalize (void)
    5897              : {
    5898       272484 :   ipa_free_fn_summary ();
    5899       272484 :   ipa_free_size_summary ();
    5900       272485 :   delete string_char_set_cache;
    5901       272484 :   string_char_set_cache = NULL;
    5902       272484 : }
        

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