LCOV - code coverage report
Current view: top level - gcc - ipa-predicate.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 91.5 % 351 321
Test Date: 2026-12-05 16:10:02 Functions: 93.3 % 15 14
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* IPA predicates.
       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              : #include "config.h"
      22              : #include "system.h"
      23              : #include "coretypes.h"
      24              : #include "backend.h"
      25              : #include "tree.h"
      26              : #include "cgraph.h"
      27              : #include "tree-vrp.h"
      28              : #include "alloc-pool.h"
      29              : #include "symbol-summary.h"
      30              : #include "sreal.h"
      31              : #include "ipa-cp.h"
      32              : #include "ipa-prop.h"
      33              : #include "ipa-fnsummary.h"
      34              : #include "real.h"
      35              : #include "fold-const.h"
      36              : #include "tree-pretty-print.h"
      37              : #include "gimple.h"
      38              : #include "gimplify.h"
      39              : #include "data-streamer.h"
      40              : 
      41              : 
      42              : /* Check whether two set of operations have same effects.  */
      43              : static bool
      44     23503942 : expr_eval_ops_equal_p (expr_eval_ops ops1, expr_eval_ops ops2)
      45              : {
      46     23503942 :   if (ops1)
      47              :     {
      48      2418963 :       if (!ops2 || ops1->length () != ops2->length ())
      49              :         return false;
      50              : 
      51      3081596 :       for (unsigned i = 0; i < ops1->length (); i++)
      52              :         {
      53      2198525 :           expr_eval_op &op1 = (*ops1)[i];
      54      2198525 :           expr_eval_op &op2 = (*ops2)[i];
      55              : 
      56      2198525 :           if (op1.code != op2.code
      57      1938893 :               || op1.index != op2.index
      58      1938893 :               || !vrp_operand_equal_p (op1.val[0], op2.val[0])
      59      1247488 :               || !vrp_operand_equal_p (op1.val[1], op2.val[1])
      60      3446013 :               || !types_compatible_p (op1.type, op2.type))
      61              :             return false;
      62              :         }
      63              :       return true;
      64              :     }
      65     21084979 :   return !ops2;
      66              : }
      67              : 
      68              : /* Add clause CLAUSE into the predicate P.
      69              :    When CONDITIONS is NULL do not perform checking whether NEW_CLAUSE
      70              :    is obviously true.  This is useful only when NEW_CLAUSE is known to be
      71              :    sane.  */
      72              : 
      73              : void
      74     62085438 : ipa_predicate::add_clause (conditions conditions, clause_t new_clause)
      75              : {
      76     62085438 :   int i;
      77     62085438 :   int i2;
      78     62085438 :   int insert_here = -1;
      79     62085438 :   int c1, c2;
      80              : 
      81              :   /* True clause.  */
      82     62085438 :   if (!new_clause)
      83              :     return;
      84              : 
      85              :   /* False clause makes the whole predicate false.  Kill the other variants.  */
      86     62085438 :   if (new_clause == (1 << ipa_predicate::false_condition))
      87              :     {
      88            0 :       *this = false;
      89            0 :       return;
      90              :     }
      91     62085438 :   if (*this == false)
      92              :     return;
      93              : 
      94              :   /* No one should be silly enough to add false into nontrivial clauses.  */
      95     62085438 :   gcc_checking_assert (!(new_clause & (1 << ipa_predicate::false_condition)));
      96              : 
      97              :   /* Look where to insert the new_clause.  At the same time prune out
      98              :      new_clauses of P that are implied by the new new_clause and thus
      99              :      redundant.  */
     100    166154004 :   for (i = 0, i2 = 0; i <= max_clauses; i++)
     101              :     {
     102    166154004 :       m_clause[i2] = m_clause[i];
     103              : 
     104    166154004 :       if (!m_clause[i])
     105              :         break;
     106              : 
     107              :       /* If m_clause[i] implies new_clause, there is nothing to add.  */
     108    117874844 :       if ((m_clause[i] & new_clause) == m_clause[i])
     109              :         {
     110              :           /* We had nothing to add, none of clauses should've become
     111              :              redundant.  */
     112     13806278 :           gcc_checking_assert (i == i2);
     113              :           return;
     114              :         }
     115              : 
     116    104068566 :       if (m_clause[i] < new_clause && insert_here < 0)
     117    104068566 :         insert_here = i2;
     118              : 
     119              :       /* If new_clause implies clause[i], then clause[i] becomes redundant.
     120              :          Otherwise the clause[i] has to stay.  */
     121    104068566 :       if ((m_clause[i] & new_clause) != new_clause)
     122     99672033 :         i2++;
     123              :     }
     124              : 
     125              :   /* Look for clauses that are obviously true.  I.e.
     126              :      op0 == 5 || op0 != 5.  */
     127     48279160 :   if (conditions)
     128    386125705 :     for (c1 = ipa_predicate::first_dynamic_condition;
     129    400512655 :          c1 < num_conditions; c1++)
     130              :       {
     131    387801865 :         condition *cc1;
     132    387801865 :         if (!(new_clause & (1 << c1)))
     133    348665554 :           continue;
     134     39136311 :         cc1 = &(*conditions)[c1 - ipa_predicate::first_dynamic_condition];
     135              :         /* We have no way to represent !changed and !is_not_constant
     136              :            and thus there is no point for looking for them.  */
     137     39136311 :         if (cc1->code == changed || cc1->code == is_not_constant || cc1->code == not_sra_candidate)
     138      8056723 :           continue;
     139    688118126 :         for (c2 = c1 + 1; c2 < num_conditions; c2++)
     140    658714698 :           if (new_clause & (1 << c2))
     141              :             {
     142     59752523 :               condition *cc2 =
     143     59752523 :                 &(*conditions)[c2 - ipa_predicate::first_dynamic_condition];
     144     59752523 :               if (cc1->operand_num == cc2->operand_num
     145     52009347 :                   && vrp_operand_equal_p (cc1->val, cc2->val)
     146      4976846 :                   && cc2->code != is_not_constant
     147      4976846 :                   && cc2->code != not_sra_candidate
     148      4976846 :                   && cc2->code != changed
     149      4976846 :                   && expr_eval_ops_equal_p (cc1->param_ops, cc2->param_ops)
     150      3534977 :                   && cc2->agg_contents == cc1->agg_contents
     151      3232964 :                   && cc2->by_ref == cc1->by_ref
     152      3228258 :                   && (!cc1->agg_contents
     153      2240400 :                       || (cc1->unknown_offset == cc2->unknown_offset
     154      2232620 :                           && (cc1->unknown_offset || cc2->offset == cc1->offset)
     155      1685626 :                           && cc2->maybe_modified == cc1->maybe_modified))
     156      2605473 :                   && types_compatible_p (cc2->type, cc1->type)
     157     62355860 :                   && cc1->code == invert_tree_comparison (cc2->code,
     158      2603337 :                                                           HONOR_NANS (cc1->val)))
     159              :                 return;
     160              :             }
     161              :       }
     162              : 
     163              : 
     164              :   /* We run out of variants.  Be conservative in positive direction.  */
     165     46603000 :   if (i2 == max_clauses)
     166              :     return;
     167              :   /* Keep clauses in decreasing order. This makes equivalence testing easy.  */
     168     46182201 :   m_clause[i2 + 1] = 0;
     169     46182201 :   if (insert_here >= 0)
     170     53687871 :     for (; i2 > insert_here; i2--)
     171     31644599 :       m_clause[i2] = m_clause[i2 - 1];
     172              :   else
     173              :     insert_here = i2;
     174     46182201 :   m_clause[insert_here] = new_clause;
     175              : }
     176              : 
     177              : 
     178              : /* Do THIS &= P.  */
     179              : 
     180              : ipa_predicate &
     181    468306409 : ipa_predicate::operator &= (const ipa_predicate &p)
     182              : {
     183              :   /* Avoid busy work.  */
     184    468306409 :   if (p == false || *this == true)
     185              :     {
     186    355049611 :       *this = p;
     187    355049611 :       return *this;
     188              :     }
     189    113256798 :   if (*this == false || p == true || this == &p)
     190              :     return *this;
     191              : 
     192              :   int i;
     193              : 
     194              :   /* See how far ipa_predicates match.  */
     195     84136286 :   for (i = 0; m_clause[i] && m_clause[i] == p.m_clause[i]; i++)
     196              :     {
     197     32748889 :       gcc_checking_assert (i < max_clauses);
     198              :     }
     199              : 
     200              :   /* Combine the ipa_predicates rest.  */
     201     93543776 :   for (; p.m_clause[i]; i++)
     202              :     {
     203     42156379 :       gcc_checking_assert (i < max_clauses);
     204     42156379 :       add_clause (NULL, p.m_clause[i]);
     205              :     }
     206              :   return *this;
     207              : }
     208              : 
     209              : 
     210              : 
     211              : /* Return THIS | P2.  */
     212              : 
     213              : ipa_predicate
     214    135506011 : ipa_predicate::or_with (conditions conditions,
     215              :                         const ipa_predicate &p) const
     216              : {
     217              :   /* Avoid busy work.  */
     218    135506011 :   if (p == false || *this == true || *this == p)
     219     19217706 :     return *this;
     220    116288305 :   if (*this == false || p == true)
     221    109637334 :     return p;
     222              : 
     223              :   /* OK, combine the predicates.  */
     224      6650971 :   ipa_predicate out = true;
     225              : 
     226     16542506 :   for (int i = 0; m_clause[i]; i++)
     227     29552936 :     for (int j = 0; p.m_clause[j]; j++)
     228              :       {
     229     19661401 :         gcc_checking_assert (i < max_clauses && j < max_clauses);
     230     19661401 :         out.add_clause (conditions, m_clause[i] | p.m_clause[j]);
     231              :       }
     232      6650971 :   return out;
     233              : }
     234              : 
     235              : 
     236              : /* Having partial truth assignment in POSSIBLE_TRUTHS, return false
     237              :    if predicate P is known to be false.  */
     238              : 
     239              : bool
     240    313501765 : ipa_predicate::evaluate (clause_t possible_truths) const
     241              : {
     242    313501765 :   int i;
     243              : 
     244              :   /* True remains true.  */
     245    313501765 :   if (*this == true)
     246              :     return true;
     247              : 
     248    250187087 :   gcc_assert (!(possible_truths & (1 << ipa_predicate::false_condition)));
     249              : 
     250              :   /* See if we can find clause we can disprove.  */
     251    617310582 :   for (i = 0; m_clause[i]; i++)
     252              :     {
     253    436374595 :       gcc_checking_assert (i < max_clauses);
     254    436374595 :       if (!(m_clause[i] & possible_truths))
     255              :         return false;
     256              :     }
     257              :   return true;
     258              : }
     259              : 
     260              : /* Return the probability in range 0...REG_BR_PROB_BASE that the predicated
     261              :    instruction will be recomputed per invocation of the inlined call.  */
     262              : 
     263              : int
     264     41274341 : ipa_predicate::probability (conditions conds,
     265              :                         clause_t possible_truths,
     266              :                         vec<inline_param_summary> inline_param_summary) const
     267              : {
     268     41274341 :   int i;
     269     41274341 :   int combined_prob = REG_BR_PROB_BASE;
     270              : 
     271              :   /* True remains true.  */
     272     41274341 :   if (*this == true)
     273              :     return REG_BR_PROB_BASE;
     274              : 
     275     30624657 :   if (*this == false)
     276              :     return 0;
     277              : 
     278     30624657 :   gcc_assert (!(possible_truths & (1 << ipa_predicate::false_condition)));
     279              : 
     280              :   /* See if we can find clause we can disprove.  */
     281     83968212 :   for (i = 0; m_clause[i]; i++)
     282              :     {
     283     57797992 :       gcc_checking_assert (i < max_clauses);
     284     57797992 :       if (!(m_clause[i] & possible_truths))
     285              :         return 0;
     286              :       else
     287              :         {
     288     57797992 :           int this_prob = 0;
     289     57797992 :           int i2;
     290     57797992 :           if (!inline_param_summary.exists ())
     291              :             return REG_BR_PROB_BASE;
     292   1907324100 :           for (i2 = 0; i2 < num_conditions; i2++)
     293   1849526400 :             if ((m_clause[i] & possible_truths) & (1 << i2))
     294              :               {
     295     72545497 :                 if (i2 >= ipa_predicate::first_dynamic_condition)
     296              :                   {
     297     72545497 :                     condition *c =
     298     72545497 :                       &(*conds)[i2 - ipa_predicate::first_dynamic_condition];
     299     72545497 :                     if (c->code == ipa_predicate::changed
     300     28353191 :                         && !c->maybe_modified
     301     19484885 :                         && !c->unknown_offset
     302     92030382 :                         && (c->operand_num <
     303     19484885 :                             (int) inline_param_summary.length ()))
     304              :                       {
     305     19484883 :                         int iprob =
     306     19484883 :                           inline_param_summary[c->operand_num].change_prob;
     307   1849526400 :                         this_prob = MAX (this_prob, iprob);
     308              :                       }
     309              :                     else
     310              :                       this_prob = REG_BR_PROB_BASE;
     311              :                   }
     312              :                 else
     313              :                   this_prob = REG_BR_PROB_BASE;
     314              :               }
     315     57797700 :           combined_prob = MIN (this_prob, combined_prob);
     316     57797700 :           if (!combined_prob)
     317              :             return 0;
     318              :         }
     319              :     }
     320              :   return combined_prob;
     321              : }
     322              : 
     323              : 
     324              : /* Dump conditional COND.  */
     325              : 
     326              : void
     327        21557 : dump_condition (FILE *f, conditions conditions, int cond)
     328              : {
     329        21557 :   condition *c;
     330        21557 :   if (cond == ipa_predicate::false_condition)
     331         2837 :     fprintf (f, "false");
     332        18720 :   else if (cond == ipa_predicate::not_inlined_condition)
     333         4821 :     fprintf (f, "not inlined");
     334              :   else
     335              :     {
     336        13899 :       c = &(*conditions)[cond - ipa_predicate::first_dynamic_condition];
     337        13899 :       fprintf (f, "op%i", c->operand_num);
     338        13899 :       if (c->agg_contents)
     339              :         {
     340         6110 :           if (c->unknown_offset)
     341         3153 :             fprintf (f, "[%s%sunknown_offset]",
     342         3153 :                      c->by_ref ? "ref " : "",
     343         3153 :                      c->maybe_modified ? "maybe_modified " : "");
     344              :           else
     345         2957 :             fprintf (f, "[%s%soffset: " HOST_WIDE_INT_PRINT_DEC "]",
     346         2957 :                      c->by_ref ? "ref " : "",
     347         2957 :                      c->maybe_modified ? "maybe_modified " : "",
     348              :                      c->offset);
     349              :         }
     350              : 
     351        15177 :       for (unsigned i = 0; i < vec_safe_length (c->param_ops); i++)
     352              :         {
     353         1278 :           expr_eval_op &op = (*(c->param_ops))[i];
     354         1278 :           const char *op_name = op_symbol_code (op.code);
     355              : 
     356         1278 :           if (op_name == op_symbol_code (ERROR_MARK))
     357          320 :             op_name = get_tree_code_name (op.code);
     358              : 
     359         1278 :           fprintf (f, ",(");
     360              : 
     361         1278 :           if (!op.val[0])
     362              :             {
     363          320 :               switch (op.code)
     364              :                 {
     365          320 :                 case FLOAT_EXPR:
     366          320 :                 case FIX_TRUNC_EXPR:
     367          320 :                 case FIXED_CONVERT_EXPR:
     368          320 :                 case VIEW_CONVERT_EXPR:
     369          320 :                 CASE_CONVERT:
     370          320 :                   if (op.code == VIEW_CONVERT_EXPR)
     371            0 :                     fprintf (f, "VCE");
     372          320 :                   fprintf (f, "(");
     373          320 :                   print_generic_expr (f, op.type);
     374          320 :                   fprintf (f, ")" );
     375          320 :                   break;
     376              : 
     377            0 :                 default:
     378            0 :                   fprintf (f, "%s", op_name);
     379              :                 }
     380          320 :               fprintf (f, " #");
     381              :             }
     382          958 :           else if (!op.val[1])
     383              :             {
     384          958 :               if (op.index)
     385              :                 {
     386           62 :                   print_generic_expr (f, op.val[0]);
     387           62 :                   fprintf (f, " %s #", op_name);
     388              :                 }
     389              :               else
     390              :                 {
     391          896 :                   fprintf (f, "# %s ", op_name);
     392          896 :                   print_generic_expr (f, op.val[0]);
     393              :                 }
     394              :             }
     395              :           else
     396              :             {
     397            0 :               fprintf (f, "%s ", op_name);
     398            0 :               switch (op.index)
     399              :                 {
     400            0 :                 case 0:
     401            0 :                   fprintf (f, "#, ");
     402            0 :                   print_generic_expr (f, op.val[0]);
     403            0 :                   fprintf (f, ", ");
     404            0 :                   print_generic_expr (f, op.val[1]);
     405            0 :                   break;
     406              : 
     407            0 :                 case 1:
     408            0 :                   print_generic_expr (f, op.val[0]);
     409            0 :                   fprintf (f, ", #, ");
     410            0 :                   print_generic_expr (f, op.val[1]);
     411            0 :                   break;
     412              : 
     413            0 :                 case 2:
     414            0 :                   print_generic_expr (f, op.val[0]);
     415            0 :                   fprintf (f, ", ");
     416            0 :                   print_generic_expr (f, op.val[1]);
     417            0 :                   fprintf (f, ", #");
     418            0 :                   break;
     419              : 
     420            0 :                 default:
     421            0 :                   fprintf (f, "*, *, *");
     422              :                 }
     423              :             }
     424         1278 :           fprintf (f, ")");
     425              :         }
     426              : 
     427        13899 :       if (c->code == ipa_predicate::is_not_constant)
     428              :         {
     429           18 :           fprintf (f, " not constant");
     430           18 :           return;
     431              :         }
     432        13881 :       if (c->code == ipa_predicate::changed)
     433              :         {
     434         2766 :           fprintf (f, " changed");
     435         2766 :           return;
     436              :         }
     437        11115 :       if (c->code == ipa_predicate::not_sra_candidate)
     438              :         {
     439         2278 :           fprintf (f, " not sra candidate");
     440         2278 :           return;
     441              :         }
     442         8837 :       fprintf (f, " %s ", op_symbol_code (c->code));
     443         8837 :       print_generic_expr (f, c->val);
     444              :     }
     445              : }
     446              : 
     447              : 
     448              : /* Dump clause CLAUSE.  */
     449              : 
     450              : static void
     451        21477 : dump_clause (FILE *f, conditions conds, clause_t clause)
     452              : {
     453        21477 :   int i;
     454        21477 :   bool found = false;
     455        21477 :   fprintf (f, "(");
     456        21477 :   if (!clause)
     457         4124 :     fprintf (f, "true");
     458       708741 :   for (i = 0; i < ipa_predicate::num_conditions; i++)
     459       687264 :     if (clause & (1 << i))
     460              :       {
     461        18367 :         if (found)
     462         1014 :           fprintf (f, " || ");
     463        18367 :         found = true;
     464        18367 :         dump_condition (f, conds, i);
     465              :       }
     466        21477 :   fprintf (f, ")");
     467        21477 : }
     468              : 
     469              : 
     470              : /* Dump THIS to F.  CONDS a vector of conditions used when evaluating
     471              :    ipa_predicates.  When NL is true new line is output at the end of dump.  */
     472              : 
     473              : void
     474        15928 : ipa_predicate::dump (FILE *f, conditions conds, bool nl) const
     475              : {
     476        15928 :   int i;
     477        15928 :   if (*this == true)
     478         4124 :     dump_clause (f, conds, 0);
     479              :   else
     480        29157 :     for (i = 0; m_clause[i]; i++)
     481              :       {
     482        17353 :         if (i)
     483         5549 :           fprintf (f, " && ");
     484        17353 :         dump_clause (f, conds, m_clause[i]);
     485              :       }
     486        15928 :   if (nl)
     487         6195 :     fprintf (f, "\n");
     488        15928 : }
     489              : 
     490              : 
     491              : void
     492            0 : ipa_predicate::debug (conditions conds) const
     493              : {
     494            0 :   dump (stderr, conds);
     495            0 : }
     496              : 
     497              : 
     498              : /* Remap predicate THIS of former function to be predicate of duplicated function.
     499              :    POSSIBLE_TRUTHS is clause of possible truths in the duplicated node,
     500              :    INFO is inline summary of the duplicated node.  */
     501              : 
     502              : ipa_predicate
     503       221650 : ipa_predicate::remap_after_duplication (clause_t possible_truths)
     504              : {
     505       221650 :   int j;
     506       221650 :   ipa_predicate out = true;
     507       489308 :   for (j = 0; m_clause[j]; j++)
     508       301500 :     if (!(possible_truths & m_clause[j]))
     509        33842 :       return false;
     510              :     else
     511       267658 :       out.add_clause (NULL, possible_truths & m_clause[j]);
     512       187808 :   return out;
     513              : }
     514              : 
     515              : 
     516              : /* Translate all conditions from callee representation into caller
     517              :    representation and symbolically evaluate predicate THIS into new predicate.
     518              : 
     519              :    INFO is ipa_fn_summary of function we are adding predicate into, CALLEE_INFO
     520              :    is summary of function predicate P is from. OPERAND_MAP is array giving
     521              :    callee formal IDs the caller formal IDs. POSSSIBLE_TRUTHS is clause of all
     522              :    callee conditions that may be true in caller context.  TOPLEV_PREDICATE is
     523              :    predicate under which callee is executed.  OFFSET_MAP is an array of
     524              :    offsets that need to be added to conditions.  AGG_PRESERVED_MAP indicates
     525              :    whether memory referenced by each parameter is guaranteed to be preserved
     526              :    until the call; when false for a by-reference condition, maybe_modified is
     527              :    set on the remapped condition.  */
     528              : 
     529              : ipa_predicate
     530     40421852 : ipa_predicate::remap_after_inlining (class ipa_fn_summary *info,
     531              :                                  class ipa_node_params *params_summary,
     532              :                                  class ipa_fn_summary *callee_info,
     533              :                                  const vec<int> &operand_map,
     534              :                                  const vec<HOST_WIDE_INT> &offset_map,
     535              :                                  const vec<bool> &agg_preserved_map,
     536              :                                  clause_t possible_truths,
     537              :                                  const ipa_predicate &toplev_predicate)
     538              : {
     539     40421852 :   int i;
     540     40421852 :   ipa_predicate out = true;
     541              : 
     542              :   /* True ipa_predicate is easy.  */
     543     40421852 :   if (*this == true)
     544     10079602 :     return toplev_predicate;
     545     80536809 :   for (i = 0; m_clause[i]; i++)
     546              :     {
     547     50194559 :       clause_t clause = m_clause[i];
     548     50194559 :       int cond;
     549     50194559 :       ipa_predicate clause_predicate = false;
     550              : 
     551     50194559 :       gcc_assert (i < max_clauses);
     552              : 
     553   1656420447 :       for (cond = 0; cond < num_conditions; cond++)
     554              :         /* Do we have condition we can't disprove?   */
     555   1606225888 :         if (clause & possible_truths & (1 << cond))
     556              :           {
     557     31320944 :             ipa_predicate cond_predicate;
     558              :             /* Work out if the condition can translate to predicate in the
     559              :                inlined function.  */
     560     31320944 :             if (cond >= ipa_predicate::first_dynamic_condition)
     561              :               {
     562     31320944 :                 struct condition *c;
     563              : 
     564     31320944 :                 int index = cond - ipa_predicate::first_dynamic_condition;
     565     31320944 :                 c = &(*callee_info->conds)[index];
     566              :                 /* See if we can remap condition operand to caller's operand.
     567              :                    Otherwise give up.  */
     568     31320944 :                 if (!operand_map.exists ()
     569     31320944 :                     || (int) operand_map.length () <= c->operand_num
     570     16536433 :                     || operand_map[c->operand_num] == -1
     571              :                     /* TODO: For non-aggregate conditions, adding an offset is
     572              :                        basically an arithmetic jump function processing which
     573              :                        we should support in future.  */
     574      6080285 :                     || ((!c->agg_contents || !c->by_ref)
     575      2274399 :                         && offset_map[c->operand_num] > 0)
     576     36997674 :                     || (c->agg_contents
     577      3868441 :                         && !c->unknown_offset
     578      7686942 :                         && !wi::fits_shwi_p (offset_int (c->offset)
     579     33331156 :                                              + offset_map[c->operand_num])))
     580     25644214 :                   cond_predicate = true;
     581              :                 else
     582              :                   {
     583      5676730 :                     struct agg_position_info ap;
     584      5676730 :                     HOST_WIDE_INT offset_delta = offset_map[c->operand_num];
     585      5676730 :                     gcc_checking_assert (offset_delta >= 0);
     586      5676730 :                     gcc_assert (!c->agg_contents
     587              :                                 || c->by_ref || offset_delta == 0);
     588      5676730 :                     if (c->unknown_offset)
     589        24970 :                       ap.offset = -1;
     590              :                     else
     591      5651760 :                       ap.offset = c->agg_contents ? c->offset + offset_delta : 0;
     592      5676730 :                     ap.agg_contents = c->agg_contents;
     593      5676730 :                     ap.by_ref = c->by_ref;
     594      5676730 :                     ap.maybe_modified
     595     11353460 :                       = c->maybe_modified
     596      5676730 :                         || (c->agg_contents && c->by_ref
     597      3403257 :                             && !agg_preserved_map[c->operand_num]);
     598      5676730 :                     ap.unknown_offset = c->unknown_offset;
     599     11353460 :                     cond_predicate = add_condition (info, params_summary,
     600      5676730 :                                                     operand_map[c->operand_num],
     601      5676730 :                                                     c->type, &ap, c->code,
     602              :                                                     c->val, c->param_ops);
     603              :                   }
     604              :               }
     605              :             /* Fixed conditions remains same, construct single
     606              :                condition predicate.  */
     607              :             else
     608            0 :               cond_predicate = ipa_predicate::predicate_testing_cond (cond);
     609     31320944 :             clause_predicate = clause_predicate.or_with (info->conds,
     610              :                                                          cond_predicate);
     611              :           }
     612     50194559 :       out &= clause_predicate;
     613              :     }
     614     30342250 :   out &= toplev_predicate;
     615     30342250 :   return out;
     616              : }
     617              : 
     618              : 
     619              : /* Read predicate from IB.  */
     620              : 
     621              : void
     622       861313 : ipa_predicate::stream_in (class lto_input_block *ib)
     623              : {
     624       861313 :   clause_t clause;
     625       861313 :   int k = 0;
     626              : 
     627      1255689 :   do
     628              :     {
     629      1255689 :       gcc_assert (k <= max_clauses);
     630      1255689 :       clause = m_clause[k++] = streamer_read_uhwi (ib);
     631              :     }
     632      1255689 :   while (clause);
     633              : 
     634              :   /* Zero-initialize the remaining clauses in OUT.  */
     635      7357441 :   while (k <= max_clauses)
     636      6496128 :     m_clause[k++] = 0;
     637       861313 : }
     638              : 
     639              : 
     640              : /* Write predicate P to OB.  */
     641              : 
     642              : void
     643       627946 : ipa_predicate::stream_out (struct output_block *ob)
     644              : {
     645       627946 :   int j;
     646      1118621 :   for (j = 0; m_clause[j]; j++)
     647              :     {
     648       490675 :       gcc_assert (j < max_clauses);
     649       490675 :       streamer_write_uhwi (ob, m_clause[j]);
     650              :     }
     651       627946 :   streamer_write_uhwi (ob, 0);
     652       627946 : }
     653              : 
     654              : 
     655              : /* Add condition to condition list SUMMARY.  OPERAND_NUM, TYPE, CODE, VAL and
     656              :    PARAM_OPS correspond to fields of condition structure.  AGGPOS describes
     657              :    whether the used operand is loaded from an aggregate and where in the
     658              :    aggregate it is.  It can be NULL, which means this not a load from an
     659              :    aggregate.  */
     660              : 
     661              : ipa_predicate
     662     26895885 : add_condition (class ipa_fn_summary *summary,
     663              :                class ipa_node_params *params_summary,
     664              :                int operand_num,
     665              :                tree type, struct agg_position_info *aggpos,
     666              :                enum tree_code code, tree val, expr_eval_ops param_ops)
     667              : {
     668     26895885 :   int i, j;
     669     26895885 :   struct condition *c;
     670     26895885 :   struct condition new_cond;
     671     26895885 :   HOST_WIDE_INT offset;
     672     26895885 :   bool agg_contents, by_ref, maybe_modified, unknown_offset;
     673     26895885 :   expr_eval_op *op;
     674              : 
     675     26895885 :   if (params_summary)
     676     11586028 :     ipa_set_param_used_by_ipa_predicates (params_summary, operand_num, true);
     677              : 
     678     26895885 :   if (aggpos)
     679              :     {
     680     13708363 :       agg_contents = aggpos->agg_contents;
     681     13708363 :       offset = agg_contents ? aggpos->offset : 0;
     682     13708363 :       by_ref = aggpos->by_ref;
     683     13708363 :       maybe_modified = aggpos->maybe_modified;
     684     13708363 :       unknown_offset = aggpos->unknown_offset;
     685              :     }
     686              :   else
     687              :     {
     688              :       offset = 0;
     689              :       agg_contents = false;
     690              :       by_ref = false;
     691              :       maybe_modified = false;
     692              :       unknown_offset = false;
     693              :     }
     694              : 
     695     26895885 :   gcc_checking_assert (operand_num >= 0);
     696     26895885 :   gcc_checking_assert (!maybe_modified || (agg_contents && by_ref));
     697     26895885 :   gcc_checking_assert (!unknown_offset || (agg_contents && offset == -1));
     698     26895885 :   gcc_checking_assert (!agg_contents || unknown_offset || offset >= 0);
     699    163138524 :   for (i = 0; vec_safe_iterate (summary->conds, i, &c); i++)
     700              :     {
     701    149294676 :       if (c->operand_num == operand_num
     702     89298137 :           && c->code == code
     703     30762413 :           && types_compatible_p (c->type, type)
     704     26226018 :           && vrp_operand_equal_p (c->val, val)
     705     19537835 :           && c->agg_contents == agg_contents
     706     18527096 :           && expr_eval_ops_equal_p (c->param_ops, param_ops)
     707    167349839 :           && (!agg_contents
     708      9687165 :               || (c->offset == offset
     709      5483646 :                   && c->by_ref == by_ref
     710      5464441 :                   && c->maybe_modified == maybe_modified
     711      4684039 :                   && c->unknown_offset == unknown_offset)))
     712     13052037 :         return ipa_predicate::predicate_testing_cond (i);
     713              :     }
     714              :   /* Too many conditions.  Give up and return constant true.  */
     715     13843848 :   if (i == ipa_predicate::num_conditions - ipa_predicate::first_dynamic_condition)
     716       592761 :     return true;
     717              : 
     718     13251087 :   new_cond.operand_num = operand_num;
     719     13251087 :   new_cond.code = code;
     720     13251087 :   new_cond.type = unshare_expr_without_location (type);
     721     13251087 :   new_cond.val = val ? unshare_expr_without_location (val) : val;
     722     13251087 :   new_cond.agg_contents = agg_contents;
     723     13251087 :   new_cond.by_ref = by_ref;
     724     13251087 :   new_cond.maybe_modified = maybe_modified;
     725     13251087 :   new_cond.unknown_offset = unknown_offset;
     726     13251087 :   new_cond.offset = offset;
     727     13251087 :   new_cond.param_ops = vec_safe_copy (param_ops);
     728              : 
     729     14058713 :   for (j = 0; vec_safe_iterate (new_cond.param_ops, j, &op); j++)
     730              :     {
     731       807626 :       if (op->val[0])
     732       438028 :         op->val[0] = unshare_expr_without_location (op->val[0]);
     733       807626 :       if (op->val[1])
     734           36 :         op->val[1] = unshare_expr_without_location (op->val[1]);
     735              :     }
     736              : 
     737     13251087 :   vec_safe_push (summary->conds, new_cond);
     738              : 
     739     13251087 :   return ipa_predicate::predicate_testing_cond (i);
     740              : }
        

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.