LCOV - code coverage report
Current view: top level - gcc - tree-ssa.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 86.1 % 1140 981
Test Date: 2026-11-14 16:39:50 Functions: 97.3 % 37 36
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Miscellaneous SSA utility functions.
       2              :    Copyright (C) 2001-2026 Free Software Foundation, Inc.
       3              : 
       4              : This file is part of GCC.
       5              : 
       6              : GCC is free software; you can redistribute it and/or modify
       7              : it under the terms of the GNU General Public License as published by
       8              : the Free Software Foundation; either version 3, or (at your option)
       9              : any later version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful,
      12              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14              : GNU General Public License for more details.
      15              : 
      16              : You should have received a copy of the GNU General Public License
      17              : along with GCC; see the file COPYING3.  If not see
      18              : <http://www.gnu.org/licenses/>.  */
      19              : 
      20              : #include "config.h"
      21              : #include "system.h"
      22              : #include "coretypes.h"
      23              : #include "backend.h"
      24              : #include "tree.h"
      25              : #include "gimple.h"
      26              : #include "cfghooks.h"
      27              : #include "tree-pass.h"
      28              : #include "ssa.h"
      29              : #include "gimple-pretty-print.h"
      30              : #include "diagnostic-core.h"
      31              : #include "fold-const.h"
      32              : #include "stor-layout.h"
      33              : #include "gimple-iterator.h"
      34              : #include "gimple-fold.h"
      35              : #include "gimplify.h"
      36              : #include "gimple-walk.h"
      37              : #include "tree-ssa-loop-manip.h"
      38              : #include "tree-into-ssa.h"
      39              : #include "tree-ssa.h"
      40              : #include "cfgloop.h"
      41              : #include "cfgexpand.h"
      42              : #include "tree-cfg.h"
      43              : #include "tree-dfa.h"
      44              : #include "stringpool.h"
      45              : #include "attribs.h"
      46              : #include "asan.h"
      47              : 
      48              : /* Pointer map of variable mappings, keyed by edge.  */
      49              : static hash_map<edge, auto_vec<edge_var_map> > *edge_var_maps;
      50              : 
      51              : 
      52              : /* Add a mapping with PHI RESULT and PHI DEF associated with edge E.  */
      53              : 
      54              : void
      55     11965623 : redirect_edge_var_map_add (edge e, tree result, tree def, location_t locus)
      56              : {
      57     11965623 :   edge_var_map new_node;
      58              : 
      59     11965623 :   if (edge_var_maps == NULL)
      60        71188 :     edge_var_maps = new hash_map<edge, auto_vec<edge_var_map> >;
      61              : 
      62     11965623 :   auto_vec<edge_var_map> &slot = edge_var_maps->get_or_insert (e);
      63     11965623 :   new_node.def = def;
      64     11965623 :   new_node.result = result;
      65     11965623 :   new_node.locus = locus;
      66              : 
      67     11965623 :   slot.safe_push (new_node);
      68     11965623 : }
      69              : 
      70              : 
      71              : /* Clear the var mappings in edge E.  */
      72              : 
      73              : void
      74    145881105 : redirect_edge_var_map_clear (edge e)
      75              : {
      76    145881105 :   if (!edge_var_maps)
      77              :     return;
      78              : 
      79    129846423 :   auto_vec<edge_var_map> *head = edge_var_maps->get (e);
      80              : 
      81    129846423 :   if (head)
      82     10766340 :     head->release ();
      83              : }
      84              : 
      85              : 
      86              : /* Duplicate the redirected var mappings in OLDE in NEWE.
      87              : 
      88              :    This assumes a hash_map can have multiple edges mapping to the same
      89              :    var_map (many to one mapping), since we don't remove the previous mappings.
      90              :    */
      91              : 
      92              : void
      93       449191 : redirect_edge_var_map_dup (edge newe, edge olde)
      94              : {
      95       449191 :   if (!edge_var_maps)
      96              :     return;
      97              : 
      98       418433 :   auto_vec<edge_var_map> *new_head = &edge_var_maps->get_or_insert (newe);
      99       418433 :   auto_vec<edge_var_map> *old_head = edge_var_maps->get (olde);
     100       418433 :   if (!old_head)
     101              :     return;
     102              : 
     103         8053 :   new_head->safe_splice (*old_head);
     104              : }
     105              : 
     106              : 
     107              : /* Return the variable mappings for a given edge.  If there is none, return
     108              :    NULL.  */
     109              : 
     110              : vec<edge_var_map> *
     111      8272931 : redirect_edge_var_map_vector (edge e)
     112              : {
     113              :   /* Hey, what kind of idiot would... you'd be surprised.  */
     114      8272931 :   if (!edge_var_maps)
     115              :     return NULL;
     116              : 
     117      8246858 :   auto_vec<edge_var_map> *slot = edge_var_maps->get (e);
     118      8246858 :   if (!slot)
     119              :     return NULL;
     120              : 
     121              :   return slot;
     122              : }
     123              : 
     124              : /* Clear the edge variable mappings.  */
     125              : 
     126              : void
     127    943294293 : redirect_edge_var_map_empty (void)
     128              : {
     129    943294293 :   if (edge_var_maps)
     130    252292645 :     edge_var_maps->empty ();
     131    943294293 : }
     132              : 
     133              : 
     134              : /* Remove the corresponding arguments from the PHI nodes in E's
     135              :    destination block and redirect it to DEST.  Return redirected edge.
     136              :    The list of removed arguments is stored in a vector accessed
     137              :    through edge_var_maps.  */
     138              : 
     139              : edge
     140     66120003 : ssa_redirect_edge (edge e, basic_block dest)
     141              : {
     142     66120003 :   gphi_iterator gsi;
     143     66120003 :   gphi *phi;
     144              : 
     145     66120003 :   redirect_edge_var_map_clear (e);
     146              : 
     147              :   /* Remove the appropriate PHI arguments in E's destination block.
     148              :      If we are redirecting a copied edge the destination has not
     149              :      got PHI argument space reserved nor an interesting argument.  */
     150     66120003 :   if (! (e->dest->flags & BB_DUPLICATED))
     151     76893543 :     for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
     152              :       {
     153     12771097 :         tree def;
     154     12771097 :         location_t locus;
     155              : 
     156     12771097 :         phi = gsi.phi ();
     157     12771097 :         def = gimple_phi_arg_def (phi, e->dest_idx);
     158     12771097 :         locus = gimple_phi_arg_location (phi, e->dest_idx);
     159              : 
     160     12771097 :         if (def == NULL_TREE)
     161      1724782 :           continue;
     162              : 
     163     11046315 :         redirect_edge_var_map_add (e, gimple_phi_result (phi), def, locus);
     164              :       }
     165              : 
     166     66120003 :   e = redirect_edge_succ_nodup (e, dest);
     167              : 
     168     66120003 :   return e;
     169              : }
     170              : 
     171              : 
     172              : /* Add PHI arguments queued in PENDING_STMT list on edge E to edge
     173              :    E->dest.  */
     174              : 
     175              : void
     176      3427861 : flush_pending_stmts (edge e)
     177              : {
     178      3427861 :   gphi *phi;
     179      3427861 :   edge_var_map *vm;
     180      3427861 :   int i;
     181      3427861 :   gphi_iterator gsi;
     182              : 
     183      3427861 :   vec<edge_var_map> *v = redirect_edge_var_map_vector (e);
     184      3427861 :   if (!v)
     185       355602 :     return;
     186              : 
     187      3072259 :   for (gsi = gsi_start_phis (e->dest), i = 0;
     188      8467657 :        !gsi_end_p (gsi) && v->iterate (i, &vm);
     189      5395398 :        gsi_next (&gsi), i++)
     190              :     {
     191      5395398 :       tree def;
     192              : 
     193      5395398 :       phi = gsi.phi ();
     194      5395398 :       def = redirect_edge_var_map_def (vm);
     195      5395398 :       add_phi_arg (phi, def, e, redirect_edge_var_map_location (vm));
     196              :     }
     197              : 
     198      3072259 :   redirect_edge_var_map_clear (e);
     199              : }
     200              : 
     201              : /* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a
     202              :    GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an
     203              :    expression with a different value.
     204              : 
     205              :    This will update any annotations (say debug bind stmts) referring
     206              :    to the original LHS, so that they use the RHS instead.  This is
     207              :    done even if NLHS and LHS are the same, for it is understood that
     208              :    the RHS will be modified afterwards, and NLHS will not be assigned
     209              :    an equivalent value.
     210              : 
     211              :    Adjusting any non-annotation uses of the LHS, if needed, is a
     212              :    responsibility of the caller.
     213              : 
     214              :    The effect of this call should be pretty much the same as that of
     215              :    inserting a copy of STMT before STMT, and then removing the
     216              :    original stmt, at which time gsi_remove() would have update
     217              :    annotations, but using this function saves all the inserting,
     218              :    copying and removing.  */
     219              : 
     220              : void
     221           51 : gimple_replace_ssa_lhs (gimple *stmt, tree nlhs)
     222              : {
     223           51 :   if (MAY_HAVE_DEBUG_BIND_STMTS)
     224              :     {
     225            0 :       tree lhs = gimple_get_lhs (stmt);
     226              : 
     227            0 :       gcc_assert (SSA_NAME_DEF_STMT (lhs) == stmt);
     228              : 
     229            0 :       insert_debug_temp_for_var_def (NULL, lhs);
     230              :     }
     231              : 
     232           51 :   gimple_set_lhs (stmt, nlhs);
     233           51 : }
     234              : 
     235              : 
     236              : /* Given a tree for an expression for which we might want to emit
     237              :    locations or values in debug information (generally a variable, but
     238              :    we might deal with other kinds of trees in the future), return the
     239              :    tree that should be used as the variable of a DEBUG_BIND STMT or
     240              :    VAR_LOCATION INSN or NOTE.  Return NULL if VAR is not to be tracked.  */
     241              : 
     242              : tree
     243    379546337 : target_for_debug_bind (tree var)
     244              : {
     245    379548599 :   if (!MAY_HAVE_DEBUG_BIND_STMTS)
     246              :     return NULL_TREE;
     247              : 
     248    357466794 :   if (TREE_CODE (var) == SSA_NAME)
     249              :     {
     250     16760882 :       var = SSA_NAME_VAR (var);
     251              :       if (var == NULL_TREE)
     252              :         return NULL_TREE;
     253              :     }
     254              : 
     255    303850404 :   if ((!VAR_P (var) || VAR_DECL_IS_VIRTUAL_OPERAND (var))
     256    366486439 :       && TREE_CODE (var) != PARM_DECL)
     257              :     return NULL_TREE;
     258              : 
     259    301825343 :   if (DECL_HAS_VALUE_EXPR_P (var))
     260         2262 :     return target_for_debug_bind (DECL_VALUE_EXPR (var));
     261              : 
     262    301823081 :   if (DECL_IGNORED_P (var))
     263              :     return NULL_TREE;
     264              : 
     265              :   /* var-tracking only tracks registers.  */
     266    278916782 :   if (!is_gimple_reg_type (TREE_TYPE (var)))
     267      9406353 :     return NULL_TREE;
     268              : 
     269              :   return var;
     270              : }
     271              : 
     272              : /* Called via walk_tree, look for SSA_NAMEs that have already been
     273              :    released.  */
     274              : 
     275              : tree
     276     10137156 : find_released_ssa_name (tree *tp, int *walk_subtrees, void *data_)
     277              : {
     278     10137156 :   struct walk_stmt_info *wi = (struct walk_stmt_info *) data_;
     279              : 
     280     10137156 :   if (wi && wi->is_lhs)
     281              :     return NULL_TREE;
     282              : 
     283     10092224 :   if (TREE_CODE (*tp) == SSA_NAME)
     284              :     {
     285      1623070 :       if (SSA_NAME_IN_FREE_LIST (*tp))
     286              :         return *tp;
     287              : 
     288      1603969 :       *walk_subtrees = 0;
     289              :     }
     290      8469154 :   else if (IS_TYPE_OR_DECL_P (*tp))
     291        39330 :     *walk_subtrees = 0;
     292              : 
     293              :   return NULL_TREE;
     294              : }
     295              : 
     296              : /* Insert a DEBUG BIND stmt before the DEF of VAR if VAR is referenced
     297              :    by other DEBUG stmts, and replace uses of the DEF with the
     298              :    newly-created debug temp.  */
     299              : 
     300              : void
     301     92834324 : insert_debug_temp_for_var_def (gimple_stmt_iterator *gsi, tree var)
     302              : {
     303     92834324 :   imm_use_iterator imm_iter;
     304     92834324 :   use_operand_p use_p;
     305     92834324 :   gimple *stmt;
     306     92834324 :   gimple *def_stmt = NULL;
     307     92834324 :   int usecount = 0;
     308     92834324 :   tree value = NULL;
     309              : 
     310     92834324 :   if (!MAY_HAVE_DEBUG_BIND_STMTS)
     311     89292567 :     return;
     312              : 
     313              :   /* If this name has already been registered for replacement, do nothing
     314              :      as anything that uses this name isn't in SSA form.  */
     315     92834324 :   if (name_registered_for_update_p (var))
     316              :     return;
     317              : 
     318              :   /* Check whether there are debug stmts that reference this variable and,
     319              :      if there are, decide whether we should use a debug temp.  */
     320    102867562 :   FOR_EACH_IMM_USE_FAST (use_p, imm_iter, var)
     321              :     {
     322     11719584 :       stmt = USE_STMT (use_p);
     323              : 
     324     11719584 :       if (!gimple_debug_bind_p (stmt))
     325      7689390 :         continue;
     326              : 
     327      4030194 :       if (usecount++)
     328              :         break;
     329              : 
     330      3541757 :       if (gimple_debug_bind_get_value (stmt) != var)
     331              :         {
     332              :           /* Count this as an additional use, so as to make sure we
     333              :              use a temp unless VAR's definition has a SINGLE_RHS that
     334              :              can be shared.  */
     335       741454 :           usecount++;
     336       741454 :           break;
     337              :         }
     338     92377869 :     }
     339              : 
     340     92377869 :   if (!usecount)
     341              :     return;
     342              : 
     343      3541757 :   if (gsi)
     344      3090247 :     def_stmt = gsi_stmt (*gsi);
     345              :   else
     346       451510 :     def_stmt = SSA_NAME_DEF_STMT (var);
     347              : 
     348              :   /* If we didn't get an insertion point, and the stmt has already
     349              :      been removed, we won't be able to insert the debug bind stmt, so
     350              :      we'll have to drop debug information.  */
     351      3541757 :   if (gimple_code (def_stmt) == GIMPLE_PHI)
     352              :     {
     353       177552 :       value = degenerate_phi_result (as_a <gphi *> (def_stmt));
     354       177552 :       if (value && walk_tree (&value, find_released_ssa_name, NULL, NULL))
     355           79 :         value = NULL;
     356              :       /* error_mark_node is what fixup_noreturn_call changes PHI arguments
     357              :          to.  */
     358       177473 :       else if (value == error_mark_node)
     359            0 :         value = NULL;
     360              :     }
     361      3364205 :   else if (gimple_clobber_p (def_stmt))
     362              :     /* We can end up here when rewriting a decl into SSA and coming
     363              :        along a clobber for the original decl.  Turn that into
     364              :        # DEBUG decl => NULL  */
     365      1295044 :     value = NULL;
     366      2069161 :   else if (is_gimple_assign (def_stmt))
     367              :     {
     368      1979757 :       bool no_value = false;
     369              : 
     370      1979757 :       if (!dom_info_available_p (CDI_DOMINATORS))
     371              :         {
     372        63954 :           struct walk_stmt_info wi;
     373              : 
     374        63954 :           memset (&wi, 0, sizeof (wi));
     375              : 
     376              :           /* When removing blocks without following reverse dominance
     377              :              order, we may sometimes encounter SSA_NAMEs that have
     378              :              already been released, referenced in other SSA_DEFs that
     379              :              we're about to release.  Consider:
     380              : 
     381              :              <bb X>:
     382              :              v_1 = foo;
     383              : 
     384              :              <bb Y>:
     385              :              w_2 = v_1 + bar;
     386              :              # DEBUG w => w_2
     387              : 
     388              :              If we deleted BB X first, propagating the value of w_2
     389              :              won't do us any good.  It's too late to recover their
     390              :              original definition of v_1: when it was deleted, it was
     391              :              only referenced in other DEFs, it couldn't possibly know
     392              :              it should have been retained, and propagating every
     393              :              single DEF just in case it might have to be propagated
     394              :              into a DEBUG STMT would probably be too wasteful.
     395              : 
     396              :              When dominator information is not readily available, we
     397              :              check for and accept some loss of debug information.  But
     398              :              if it is available, there's no excuse for us to remove
     399              :              blocks in the wrong order, so we don't even check for
     400              :              dead SSA NAMEs.  SSA verification shall catch any
     401              :              errors.  */
     402        63927 :           if ((!gsi && !gimple_bb (def_stmt))
     403       127881 :               || walk_gimple_op (def_stmt, find_released_ssa_name, &wi))
     404        19022 :             no_value = true;
     405              :         }
     406              : 
     407        63954 :       if (!no_value)
     408      1960735 :         value = gimple_assign_rhs_to_tree (def_stmt);
     409              :     }
     410              : 
     411      3541757 :   if (value)
     412              :     {
     413              :       /* If there's a single use of VAR, and VAR is the entire debug
     414              :          expression (usecount would have been incremented again
     415              :          otherwise), then we can propagate VALUE into this single use,
     416              :          avoiding the temp.
     417              : 
     418              :          We can also avoid using a temp if VALUE can be shared and
     419              :          propagated into all uses, without generating expressions that
     420              :          wouldn't be valid gimple RHSs.
     421              : 
     422              :          Other cases that would require unsharing or non-gimple RHSs
     423              :          are deferred to a debug temp, although we could avoid temps
     424              :          at the expense of duplication of expressions.  */
     425              : 
     426      1989399 :       if (usecount == 1
     427      1106373 :           || gimple_code (def_stmt) == GIMPLE_PHI
     428      1097313 :           || CONSTANT_CLASS_P (value)
     429      3084051 :           || is_gimple_reg (value))
     430              :         ;
     431              :       else
     432              :         {
     433      1092645 :           gdebug *def_temp;
     434      1092645 :           tree vexpr = build_debug_expr_decl (TREE_TYPE (value));
     435              : 
     436      1092645 :           def_temp = gimple_build_debug_bind (vexpr,
     437              :                                               unshare_expr (value),
     438              :                                               def_stmt);
     439              : 
     440              :           /* FIXME: Is setting the mode really necessary? */
     441      1092645 :           if (DECL_P (value))
     442         2866 :             SET_DECL_MODE (vexpr, DECL_MODE (value));
     443              :           else
     444      1089779 :             SET_DECL_MODE (vexpr, TYPE_MODE (TREE_TYPE (value)));
     445              : 
     446      1092645 :           if (gsi)
     447       866642 :             gsi_insert_before (gsi, def_temp, GSI_SAME_STMT);
     448              :           else
     449              :             {
     450       226003 :               gimple_stmt_iterator ngsi = gsi_for_stmt (def_stmt);
     451       226003 :               gsi_insert_before (&ngsi, def_temp, GSI_SAME_STMT);
     452              :             }
     453              : 
     454      1092645 :           value = vexpr;
     455              :         }
     456              :     }
     457              : 
     458     10175963 :   FOR_EACH_IMM_USE_STMT (stmt, imm_iter, var)
     459              :     {
     460      6634206 :       if (!gimple_debug_bind_p (stmt))
     461       918032 :         continue;
     462              : 
     463      5716174 :       if (value)
     464              :         {
     465      7991202 :           FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
     466      3995601 :             SET_USE (use_p, unshare_expr (value));
     467              :           /* If we didn't replace uses with a debug decl fold the
     468              :              resulting expression.  Otherwise we end up with invalid IL.  */
     469      3994249 :           if (TREE_CODE (value) != DEBUG_EXPR_DECL)
     470              :             {
     471       923108 :               gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
     472       923108 :               fold_stmt_inplace (&gsi);
     473              :             }
     474              :         }
     475              :       else
     476      1721925 :         gimple_debug_bind_reset_value (stmt);
     477              : 
     478      5716174 :       update_stmt (stmt);
     479      3541757 :     }
     480              : }
     481              : 
     482              : 
     483              : /* Insert a DEBUG BIND stmt before STMT for each DEF referenced by
     484              :    other DEBUG stmts, and replace uses of the DEF with the
     485              :    newly-created debug temp.  */
     486              : 
     487              : void
     488    172203744 : insert_debug_temps_for_defs (gimple_stmt_iterator *gsi)
     489              : {
     490    172203744 :   gimple *stmt;
     491    172203744 :   ssa_op_iter op_iter;
     492    172203744 :   def_operand_p def_p;
     493              : 
     494    172203744 :   if (!MAY_HAVE_DEBUG_BIND_STMTS)
     495     46322286 :     return;
     496              : 
     497    125881458 :   stmt = gsi_stmt (*gsi);
     498              : 
     499    288014578 :   FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, op_iter, SSA_OP_DEF)
     500              :     {
     501     36251662 :       tree var = DEF_FROM_PTR (def_p);
     502              : 
     503     36251662 :       if (TREE_CODE (var) != SSA_NAME)
     504       149955 :         continue;
     505              : 
     506     36101707 :       insert_debug_temp_for_var_def (gsi, var);
     507              :     }
     508              : }
     509              : 
     510              : /* Reset all debug stmts that use SSA_NAME(s) defined in STMT.  */
     511              : 
     512              : void
     513         7942 : reset_debug_uses (gimple *stmt)
     514              : {
     515         7942 :   ssa_op_iter op_iter;
     516         7942 :   def_operand_p def_p;
     517         7942 :   imm_use_iterator imm_iter;
     518         7942 :   gimple *use_stmt;
     519              : 
     520         7942 :   if (!MAY_HAVE_DEBUG_BIND_STMTS)
     521          259 :     return;
     522              : 
     523        20567 :   FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, op_iter, SSA_OP_DEF)
     524              :     {
     525         5201 :       tree var = DEF_FROM_PTR (def_p);
     526              : 
     527         5201 :       if (TREE_CODE (var) != SSA_NAME)
     528            0 :         continue;
     529              : 
     530        11728 :       FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, var)
     531              :         {
     532         6527 :           if (!gimple_debug_bind_p (use_stmt))
     533         6442 :             continue;
     534              : 
     535           85 :           gimple_debug_bind_reset_value (use_stmt);
     536           85 :           update_stmt (use_stmt);
     537         5201 :         }
     538              :     }
     539              : }
     540              : 
     541              : /* Delete SSA DEFs for SSA versions in the TOREMOVE bitmap, removing
     542              :    dominated stmts before their dominators, so that release_ssa_defs
     543              :    stands a chance of propagating DEFs into debug bind stmts.  */
     544              : 
     545              : void
     546       248445 : release_defs_bitset (bitmap toremove)
     547              : {
     548       248445 :   unsigned j;
     549       248445 :   bitmap_iterator bi;
     550              : 
     551              :   /* Performing a topological sort is probably overkill, this will
     552              :      most likely run in slightly superlinear time, rather than the
     553              :      pathological quadratic worst case.
     554              :      But iterate from max SSA name version to min one because
     555              :      that mimics allocation order during code generation behavior best.
     556              :      Use an array for this which we compact on-the-fly with a NULL
     557              :      marker moving towards the end of the vector.  */
     558       248445 :   auto_vec<tree, 16> names;
     559       248445 :   names.reserve (bitmap_count_bits (toremove) + 1);
     560       248445 :   names.quick_push (NULL_TREE);
     561      2767628 :   EXECUTE_IF_SET_IN_BITMAP (toremove, 0, j, bi)
     562      2519183 :     names.quick_push (ssa_name (j));
     563              : 
     564       248445 :   bitmap_tree_view (toremove);
     565       764741 :   while (!bitmap_empty_p (toremove))
     566              :     {
     567       267851 :       j = names.length () - 1;
     568      3578739 :       for (unsigned i = names.length () - 1; names[i];)
     569              :         {
     570      3310888 :           bool remove_now = true;
     571      3310888 :           tree var = names[i];
     572      3310888 :           gimple *stmt;
     573      3310888 :           imm_use_iterator uit;
     574              : 
     575      4012241 :           FOR_EACH_IMM_USE_STMT (stmt, uit, var)
     576              :             {
     577      1493058 :               ssa_op_iter dit;
     578      1493058 :               def_operand_p def_p;
     579              : 
     580              :               /* We can't propagate PHI nodes into debug stmts.  */
     581      1493058 :               if (gimple_code (stmt) == GIMPLE_PHI
     582      1493058 :                   || is_gimple_debug (stmt))
     583       701353 :                 continue;
     584              : 
     585              :               /* If we find another definition to remove that uses
     586              :                  the one we're looking at, defer the removal of this
     587              :                  one, so that it can be propagated into debug stmts
     588              :                  after the other is.  */
     589       791705 :               FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, dit, SSA_OP_DEF)
     590              :                 {
     591       791705 :                   tree odef = DEF_FROM_PTR (def_p);
     592              : 
     593       791705 :                   if (bitmap_bit_p (toremove, SSA_NAME_VERSION (odef)))
     594              :                     {
     595              :                       remove_now = false;
     596              :                       break;
     597              :                     }
     598              :                 }
     599              : 
     600       791705 :               if (!remove_now)
     601              :                 break;
     602      3310888 :             }
     603              : 
     604      3310888 :           if (remove_now)
     605              :             {
     606      2519183 :               gimple *def = SSA_NAME_DEF_STMT (var);
     607      2519183 :               gimple_stmt_iterator gsi = gsi_for_stmt (def);
     608              : 
     609      2519183 :               if (gimple_code (def) == GIMPLE_PHI)
     610       642458 :                 remove_phi_node (&gsi, true);
     611              :               else
     612              :                 {
     613      1876725 :                   gsi_remove (&gsi, true);
     614      1876725 :                   release_defs (def);
     615              :                 }
     616      2519183 :               bitmap_clear_bit (toremove, SSA_NAME_VERSION (var));
     617              :             }
     618              :           else
     619       791705 :             --i;
     620      3310888 :           if (--j != i)
     621      3117246 :             names[i] = names[j];
     622              :         }
     623              :     }
     624       248445 :   bitmap_list_view (toremove);
     625       248445 : }
     626              : 
     627              : /* Disable warnings about missing quoting in GCC diagnostics for
     628              :    the verification errors.  Their format strings don't follow GCC
     629              :    diagnostic conventions and the calls are ultimately followed by
     630              :    one to internal_error.  */
     631              : #if __GNUC__ >= 10
     632              : #  pragma GCC diagnostic push
     633              : #  pragma GCC diagnostic ignored "-Wformat-diag"
     634              : #endif
     635              : 
     636              : /* Verify virtual SSA form.  */
     637              : 
     638              : bool
     639    228210229 : verify_vssa (basic_block bb_start, tree current_vdef, sbitmap visited)
     640              : {
     641    228210229 :   bool err = false;
     642              : 
     643    228210229 :   struct state_t {
     644              :     basic_block bb;
     645              :     tree        vdef;
     646              :   } state;
     647              : 
     648    228210229 :   auto_vec<state_t, 3> worklist;
     649    228210229 :   state.bb = bb_start;
     650    228210229 :   state.vdef = current_vdef;
     651    228210229 :   worklist.safe_push (state);
     652              : 
     653   2888080922 :   while (!worklist.is_empty ())
     654              :     {
     655   2431660464 :       const auto &state = worklist.pop ();
     656   2431660464 :       const auto &bb = state.bb;
     657   2431660464 :       current_vdef = state.vdef;
     658              : 
     659   2431660464 :       if (!bitmap_set_bit (visited, bb->index))
     660    113461951 :         continue;
     661              : 
     662              :       /* Pick up the single virtual PHI def.  */
     663   2318198513 :       gphi *phi = NULL;
     664   2982330671 :       for (gphi_iterator si = gsi_start_phis (bb); !gsi_end_p (si);
     665    664132158 :            gsi_next (&si))
     666              :         {
     667    664132158 :           tree res = gimple_phi_result (si.phi ());
     668   1639608749 :           if (virtual_operand_p (res))
     669              :             {
     670    311344433 :               if (phi)
     671              :                 {
     672            0 :                   error ("multiple virtual PHI nodes in BB %d", bb->index);
     673            0 :                   print_gimple_stmt (stderr, phi, 0);
     674            0 :                   print_gimple_stmt (stderr, si.phi (), 0);
     675            0 :                   err = true;
     676              :                 }
     677              :               else
     678              :                 phi = si.phi ();
     679              :             }
     680              :         }
     681   2318198513 :       if (phi)
     682              :         {
     683    311344433 :           current_vdef = gimple_phi_result (phi);
     684    311344433 :           if (TREE_CODE (current_vdef) != SSA_NAME)
     685              :             {
     686            0 :               error ("virtual definition is not an SSA name");
     687            0 :               print_gimple_stmt (stderr, phi, 0);
     688            0 :               err = true;
     689              :             }
     690              :         }
     691              : 
     692              :       /* Verify stmts.  */
     693  17584598597 :       for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
     694  12948201571 :            gsi_next (&gsi))
     695              :         {
     696  12948201571 :           gimple *stmt = gsi_stmt (gsi);
     697  18341536814 :           tree vuse = gimple_vuse (stmt);
     698   5328205800 :           if (vuse)
     699              :             {
     700   3565285766 :               if (vuse != current_vdef)
     701              :                 {
     702            0 :                   error ("stmt with wrong VUSE");
     703            0 :                   print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
     704            0 :                   fprintf (stderr, "expected ");
     705            0 :                   print_generic_expr (stderr, current_vdef);
     706            0 :                   fprintf (stderr, "\n");
     707            0 :                   err = true;
     708              :                 }
     709  16513487337 :               tree vdef = gimple_vdef (stmt);
     710   3565285766 :               if (vdef)
     711              :                 {
     712   2234340954 :                   current_vdef = vdef;
     713   2234340954 :                   if (TREE_CODE (current_vdef) != SSA_NAME)
     714              :                     {
     715            0 :                       error ("virtual definition is not an SSA name");
     716            0 :                       print_gimple_stmt (stderr, phi, 0);
     717            0 :                       err = true;
     718              :                     }
     719              :                 }
     720              :             }
     721              :         }
     722              : 
     723              :       /* Verify destination PHI uses and add successors to worklist.  */
     724   2318198513 :       edge_iterator ei;
     725   2318198513 :       edge e;
     726   5128130866 :       FOR_EACH_EDGE (e, ei, bb->succs)
     727              :         {
     728   2809932353 :           gphi *phi = get_virtual_phi (e->dest);
     729   2809932353 :           if (phi
     730   2809932353 :              && PHI_ARG_DEF_FROM_EDGE (phi, e) != current_vdef)
     731              :             {
     732            0 :               error ("PHI node with wrong VUSE on edge from BB %d",
     733            0 :                      e->src->index);
     734            0 :               print_gimple_stmt (stderr, phi, 0, TDF_VOPS);
     735            0 :               fprintf (stderr, "expected ");
     736            0 :               print_generic_expr (stderr, current_vdef);
     737            0 :               fprintf (stderr, "\n");
     738            0 :               err = true;
     739              :             }
     740              : 
     741              :           /* Add successor BB along with current vdef to worklist.  */
     742   2809932353 :           if (!bitmap_bit_p (visited, e->dest->index))
     743              :             {
     744   2203450235 :               state_t new_state;
     745   2203450235 :               new_state.bb = e->dest;
     746   2203450235 :               new_state.vdef = current_vdef;
     747              : 
     748   2203450235 :               worklist.safe_push (new_state);
     749              :             }
     750              :         }
     751              :     }
     752    228210229 :   return err;
     753    228210229 : }
     754              : 
     755              : /* Return true if SSA_NAME is malformed and mark it visited.
     756              : 
     757              :    IS_VIRTUAL is true if this SSA_NAME was found inside a virtual
     758              :       operand.  */
     759              : 
     760              : static bool
     761  13995425045 : verify_ssa_name (tree ssa_name, bool is_virtual)
     762              : {
     763  13995425045 :   if (TREE_CODE (ssa_name) != SSA_NAME)
     764              :     {
     765            0 :       error ("expected an SSA_NAME object");
     766            0 :       return true;
     767              :     }
     768              : 
     769  13995425045 :   if (SSA_NAME_IN_FREE_LIST (ssa_name))
     770              :     {
     771            0 :       error ("found an SSA_NAME that had been released into the free pool");
     772            0 :       return true;
     773              :     }
     774              : 
     775  13995425045 :   if (SSA_NAME_VAR (ssa_name) != NULL_TREE
     776   8366259331 :       && TREE_TYPE (ssa_name) != TREE_TYPE (SSA_NAME_VAR (ssa_name)))
     777              :     {
     778            0 :       error ("type mismatch between an SSA_NAME and its symbol");
     779            0 :       return true;
     780              :     }
     781              : 
     782  13995425045 :   if (is_virtual && !virtual_operand_p (ssa_name))
     783              :     {
     784            0 :       error ("found a virtual definition for a GIMPLE register");
     785            0 :       return true;
     786              :     }
     787              : 
     788  13995425045 :   if (is_virtual && SSA_NAME_VAR (ssa_name) != gimple_vop (cfun))
     789              :     {
     790            0 :       error ("virtual SSA name for non-VOP decl");
     791            0 :       return true;
     792              :     }
     793              : 
     794  13995425045 :   if (!is_virtual && virtual_operand_p (ssa_name))
     795              :     {
     796            0 :       error ("found a real definition for a non-register");
     797            0 :       return true;
     798              :     }
     799              : 
     800  13995425045 :   if (SSA_NAME_IS_DEFAULT_DEF (ssa_name)
     801  13995425045 :       && !gimple_nop_p (SSA_NAME_DEF_STMT (ssa_name)))
     802              :     {
     803            0 :       error ("found a default name with a non-empty defining statement");
     804            0 :       return true;
     805              :     }
     806              : 
     807              :   return false;
     808              : }
     809              : 
     810              : 
     811              : /* Return true if the definition of SSA_NAME at block BB is malformed.
     812              : 
     813              :    STMT is the statement where SSA_NAME is created.
     814              : 
     815              :    DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME
     816              :       version numbers.  If DEFINITION_BLOCK[SSA_NAME_VERSION] is set,
     817              :       it means that the block in that array slot contains the
     818              :       definition of SSA_NAME.
     819              : 
     820              :    IS_VIRTUAL is true if SSA_NAME is created by a VDEF.  */
     821              : 
     822              : static bool
     823   5957954726 : verify_def (basic_block bb, basic_block *definition_block, tree ssa_name,
     824              :             gimple *stmt, bool is_virtual)
     825              : {
     826   5957954726 :   if (verify_ssa_name (ssa_name, is_virtual))
     827            0 :     goto err;
     828              : 
     829   5957954726 :   if (SSA_NAME_VAR (ssa_name)
     830   3271679490 :       && TREE_CODE (SSA_NAME_VAR (ssa_name)) == RESULT_DECL
     831            0 :       && DECL_BY_REFERENCE (SSA_NAME_VAR (ssa_name)))
     832              :     {
     833            0 :       error ("RESULT_DECL should be read only when DECL_BY_REFERENCE is set");
     834            0 :       goto err;
     835              :     }
     836              : 
     837   5957954726 :   if (definition_block[SSA_NAME_VERSION (ssa_name)])
     838              :     {
     839            0 :       error ("SSA_NAME created in two different blocks %i and %i",
     840            0 :              definition_block[SSA_NAME_VERSION (ssa_name)]->index, bb->index);
     841            0 :       goto err;
     842              :     }
     843              : 
     844   5957954726 :   definition_block[SSA_NAME_VERSION (ssa_name)] = bb;
     845              : 
     846   5957954726 :   if (SSA_NAME_DEF_STMT (ssa_name) != stmt)
     847              :     {
     848            0 :       error ("SSA_NAME_DEF_STMT is wrong");
     849            0 :       fprintf (stderr, "Expected definition statement:\n");
     850            0 :       print_gimple_stmt (stderr, SSA_NAME_DEF_STMT (ssa_name), 4, TDF_VOPS);
     851            0 :       fprintf (stderr, "\nActual definition statement:\n");
     852            0 :       print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
     853            0 :       goto err;
     854              :     }
     855              : 
     856              :   return false;
     857              : 
     858            0 : err:
     859            0 :   fprintf (stderr, "while verifying SSA_NAME ");
     860            0 :   print_generic_expr (stderr, ssa_name);
     861            0 :   fprintf (stderr, " in statement\n");
     862            0 :   print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
     863              : 
     864            0 :   return true;
     865              : }
     866              : 
     867              : 
     868              : /* Return true if the use of SSA_NAME at statement STMT in block BB is
     869              :    malformed.
     870              : 
     871              :    DEF_BB is the block where SSA_NAME was found to be created.
     872              : 
     873              :    IDOM contains immediate dominator information for the flowgraph.
     874              : 
     875              :    CHECK_ABNORMAL is true if the caller wants to check whether this use
     876              :       is flowing through an abnormal edge (only used when checking PHI
     877              :       arguments).
     878              : 
     879              :    If NAMES_DEFINED_IN_BB is not NULL, it contains a bitmap of ssa names
     880              :      that are defined before STMT in basic block BB.  */
     881              : 
     882              : static bool
     883  11379446182 : verify_use (basic_block bb, basic_block def_bb, use_operand_p use_p,
     884              :             gimple *stmt, bool check_abnormal, bitmap names_defined_in_bb)
     885              : {
     886  11379446182 :   bool err = false;
     887  11379446182 :   tree ssa_name = USE_FROM_PTR (use_p);
     888              : 
     889  11379446182 :   if (!TREE_VISITED (ssa_name))
     890   6349428786 :     if (verify_imm_links (stderr, ssa_name))
     891  11379446182 :       err = true;
     892              : 
     893  11379446182 :   TREE_VISITED (ssa_name) = 1;
     894              : 
     895  11379446182 :   if (gimple_nop_p (SSA_NAME_DEF_STMT (ssa_name))
     896  11379446182 :       && SSA_NAME_IS_DEFAULT_DEF (ssa_name))
     897              :     ; /* Default definitions have empty statements.  Nothing to do.  */
     898   9777148540 :   else if (!def_bb)
     899              :     {
     900            0 :       error ("missing definition");
     901            0 :       err = true;
     902              :     }
     903   9777148540 :   else if (bb != def_bb
     904   9777148540 :            && !dominated_by_p (CDI_DOMINATORS, bb, def_bb))
     905              :     {
     906            0 :       error ("definition in block %i does not dominate use in block %i",
     907              :              def_bb->index, bb->index);
     908            0 :       err = true;
     909              :     }
     910   9777148540 :   else if (bb == def_bb
     911   9777148540 :            && names_defined_in_bb != NULL
     912  15635943126 :            && !bitmap_bit_p (names_defined_in_bb, SSA_NAME_VERSION (ssa_name)))
     913              :     {
     914            0 :       error ("definition in block %i follows the use", def_bb->index);
     915            0 :       err = true;
     916              :     }
     917              : 
     918  11379446182 :   if (check_abnormal
     919  11387233695 :       && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
     920              :     {
     921            0 :       error ("SSA_NAME_OCCURS_IN_ABNORMAL_PHI should be set");
     922            0 :       err = true;
     923              :     }
     924              : 
     925              :   /* Make sure the use is in an appropriate list by checking the previous
     926              :      element to make sure it's the same.  */
     927  11379446182 :   if (use_p->prev == NULL)
     928              :     {
     929            0 :       error ("no immediate_use list");
     930            0 :       err = true;
     931              :     }
     932              :   else
     933              :     {
     934  11379446182 :       tree listvar;
     935  11379446182 :       if (use_p->prev->use == NULL)
     936   6349428786 :         listvar = use_p->prev->loc.ssa_name;
     937              :       else
     938   5030017396 :         listvar = USE_FROM_PTR (use_p->prev);
     939  11379446182 :       if (listvar != ssa_name)
     940              :         {
     941            0 :           error ("wrong immediate use list");
     942            0 :           err = true;
     943              :         }
     944              :     }
     945              : 
     946  11379446182 :   if (err)
     947              :     {
     948            0 :       fprintf (stderr, "for SSA_NAME: ");
     949            0 :       print_generic_expr (stderr, ssa_name, TDF_VOPS);
     950            0 :       fprintf (stderr, " in statement:\n");
     951            0 :       print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
     952              :     }
     953              : 
     954  11379446182 :   return err;
     955              : }
     956              : 
     957              : 
     958              : /* Return true if any of the arguments for PHI node PHI at block BB is
     959              :    malformed.
     960              : 
     961              :    DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME
     962              :       version numbers.  If DEFINITION_BLOCK[SSA_NAME_VERSION] is set,
     963              :       it means that the block in that array slot contains the
     964              :       definition of SSA_NAME.  */
     965              : 
     966              : static bool
     967    664143671 : verify_phi_args (gphi *phi, basic_block bb, basic_block *definition_block)
     968              : {
     969    664143671 :   edge e;
     970    664143671 :   bool err = false;
     971    664143671 :   size_t i, phi_num_args = gimple_phi_num_args (phi);
     972              : 
     973   1328287342 :   if (EDGE_COUNT (bb->preds) != phi_num_args)
     974              :     {
     975            0 :       error ("incoming edge count does not match number of PHI arguments");
     976            0 :       err = true;
     977            0 :       goto error;
     978              :     }
     979              : 
     980   2349569560 :   for (i = 0; i < phi_num_args; i++)
     981              :     {
     982   1685425889 :       use_operand_p op_p = gimple_phi_arg_imm_use_ptr (phi, i);
     983   1685425889 :       tree op = USE_FROM_PTR (op_p);
     984              : 
     985   1685425889 :       e = EDGE_PRED (bb, i);
     986              : 
     987   1685425889 :       if (op == NULL_TREE)
     988              :         {
     989            0 :           error ("PHI argument is missing for edge %d->%d",
     990            0 :                  e->src->index,
     991            0 :                  e->dest->index);
     992            0 :           err = true;
     993            0 :           goto error;
     994              :         }
     995              : 
     996   1685425889 :       if (TREE_CODE (op) != SSA_NAME && !is_gimple_min_invariant (op))
     997              :         {
     998            0 :           error ("PHI argument is not SSA_NAME, or invariant");
     999            0 :           err = true;
    1000              :         }
    1001              : 
    1002   1685425889 :       if ((e->flags & EDGE_ABNORMAL) && TREE_CODE (op) != SSA_NAME)
    1003              :         {
    1004            0 :           error ("PHI argument on abnormal edge is not SSA_NAME");
    1005            0 :           err = true;
    1006              :         }
    1007              : 
    1008   1685425889 :       if (TREE_CODE (op) == SSA_NAME)
    1009              :         {
    1010   2907284288 :           err = verify_ssa_name (op, virtual_operand_p (gimple_phi_result (phi)));
    1011   1453642144 :           err |= verify_use (e->src, definition_block[SSA_NAME_VERSION (op)],
    1012   1453642144 :                              op_p, phi, e->flags & EDGE_ABNORMAL, NULL);
    1013              :         }
    1014              : 
    1015   1685425889 :       if (TREE_CODE (op) == ADDR_EXPR)
    1016              :         {
    1017     11904892 :           tree base = TREE_OPERAND (op, 0);
    1018     16063994 :           while (handled_component_p (base))
    1019      4159102 :             base = TREE_OPERAND (base, 0);
    1020     11904892 :           if ((VAR_P (base)
    1021              :                || TREE_CODE (base) == PARM_DECL
    1022              :                || TREE_CODE (base) == RESULT_DECL)
    1023      5501034 :               && !TREE_ADDRESSABLE (base))
    1024              :             {
    1025            0 :               error ("address taken, but ADDRESSABLE bit not set");
    1026            0 :               err = true;
    1027              :             }
    1028              :         }
    1029              : 
    1030   1685425889 :       if (e->dest != bb)
    1031              :         {
    1032            0 :           error ("wrong edge %d->%d for PHI argument",
    1033            0 :                  e->src->index, e->dest->index);
    1034            0 :           err = true;
    1035              :         }
    1036              : 
    1037   1685425889 :       if (err)
    1038              :         {
    1039            0 :           fprintf (stderr, "PHI argument\n");
    1040            0 :           print_generic_stmt (stderr, op, TDF_VOPS);
    1041            0 :           goto error;
    1042              :         }
    1043              :     }
    1044              : 
    1045    664143671 : error:
    1046    664143671 :   if (err)
    1047              :     {
    1048            0 :       fprintf (stderr, "for PHI node\n");
    1049            0 :       print_gimple_stmt (stderr, phi, 0, TDF_VOPS|TDF_MEMSYMS);
    1050              :     }
    1051              : 
    1052              : 
    1053    664143671 :   return err;
    1054              : }
    1055              : 
    1056              : 
    1057              : /* Verify common invariants in the SSA web.
    1058              :    TODO: verify the variable annotations.  */
    1059              : 
    1060              : DEBUG_FUNCTION void
    1061    228316154 : verify_ssa (bool check_modified_stmt, bool check_ssa_operands)
    1062              : {
    1063    228316154 :   basic_block bb;
    1064    456632308 :   basic_block *definition_block = XCNEWVEC (basic_block, num_ssa_names);
    1065    228316154 :   ssa_op_iter iter;
    1066    228316154 :   tree op;
    1067    228316154 :   enum dom_state orig_dom_state = dom_info_state (CDI_DOMINATORS);
    1068    228316154 :   auto_bitmap names_defined_in_bb;
    1069              : 
    1070    228316154 :   gcc_assert (!need_ssa_update_p (cfun));
    1071              : 
    1072    228316154 :   timevar_push (TV_TREE_SSA_VERIFY);
    1073              : 
    1074    228316154 :     {
    1075              :       /* Keep track of SSA names present in the IL.  */
    1076    228316154 :       size_t i;
    1077    228316154 :       tree name;
    1078    228316154 :       hash_map <const void *, tree> ssa_info;
    1079              : 
    1080   8954371349 :       FOR_EACH_SSA_NAME (i, name, cfun)
    1081              :         {
    1082   6583828175 :           gimple *stmt;
    1083   6583828175 :           TREE_VISITED (name) = 0;
    1084              : 
    1085  13167656350 :           verify_ssa_name (name, virtual_operand_p (name));
    1086              : 
    1087   6583828175 :           stmt = SSA_NAME_DEF_STMT (name);
    1088   6583828175 :           if (!gimple_nop_p (stmt))
    1089              :             {
    1090   5957954726 :               basic_block bb = gimple_bb (stmt);
    1091   5957954726 :               if (verify_def (bb, definition_block,
    1092              :                               name, stmt, virtual_operand_p (name)))
    1093            0 :                 goto err;
    1094              :             }
    1095              : 
    1096   6583828175 :           const pt_solution *pt_info = ssa_name_pt_solution (name);
    1097    832162153 :           if (pt_info)
    1098              :             {
    1099    767614631 :               bool existed;
    1100    767614631 :               tree &val = ssa_info.get_or_insert (pt_info, &existed);
    1101    767614631 :               if (existed)
    1102              :                 {
    1103            0 :                   error ("shared SSA name pt_solution info");
    1104            0 :                   print_generic_expr (stderr, val);
    1105            0 :                   fprintf (stderr, " and ");
    1106            0 :                   print_generic_expr (stderr, name);
    1107            0 :                   fprintf (stderr, "\n");
    1108            0 :                   goto err;
    1109              :                 }
    1110              :               else
    1111    767614631 :                 val = name;
    1112              :             }
    1113   6583828175 :           const void *info = SSA_NAME_RANGE_INFO (name);
    1114   6583828175 :           if (info)
    1115              :             {
    1116   1467449536 :               bool existed;
    1117   1467449536 :               tree &val = ssa_info.get_or_insert (info, &existed);
    1118   1467449536 :               if (existed)
    1119              :                 {
    1120            0 :                   error ("shared SSA name info");
    1121            0 :                   print_generic_expr (stderr, val);
    1122            0 :                   fprintf (stderr, " and ");
    1123            0 :                   print_generic_expr (stderr, name);
    1124            0 :                   fprintf (stderr, "\n");
    1125            0 :                   goto err;
    1126              :                 }
    1127              :               else
    1128   1467449536 :                 val = name;
    1129              :             }
    1130              :         }
    1131            0 :     }
    1132              : 
    1133    228316154 :   calculate_dominance_info (CDI_DOMINATORS);
    1134              : 
    1135              :   /* Now verify all the uses and make sure they agree with the definitions
    1136              :      found in the previous pass.  */
    1137   2094564087 :   FOR_EACH_BB_FN (bb, cfun)
    1138              :     {
    1139   1866247933 :       edge e;
    1140   1866247933 :       edge_iterator ei;
    1141              : 
    1142              :       /* Make sure that all edges have a clear 'aux' field.  */
    1143   4452287343 :       FOR_EACH_EDGE (e, ei, bb->preds)
    1144              :         {
    1145   2586039410 :           if (e->aux)
    1146              :             {
    1147            0 :               error ("AUX pointer initialized for edge %d->%d", e->src->index,
    1148            0 :                       e->dest->index);
    1149            0 :               goto err;
    1150              :             }
    1151              :         }
    1152              : 
    1153              :       /* Verify the arguments for every PHI node in the block.  */
    1154   2530391604 :       for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    1155              :         {
    1156    664143671 :           gphi *phi = gsi.phi ();
    1157    664143671 :           if (verify_phi_args (phi, bb, definition_block))
    1158            0 :             goto err;
    1159              : 
    1160    664143671 :           bitmap_set_bit (names_defined_in_bb,
    1161    664143671 :                           SSA_NAME_VERSION (gimple_phi_result (phi)));
    1162              :         }
    1163              : 
    1164              :       /* Now verify all the uses and vuses in every statement of the block.  */
    1165  16680850126 :       for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
    1166  12948354260 :            gsi_next (&gsi))
    1167              :         {
    1168  12948354260 :           gimple *stmt = gsi_stmt (gsi);
    1169  12948354260 :           use_operand_p use_p;
    1170              : 
    1171  25822662568 :           if (check_modified_stmt && gimple_modified_p (stmt))
    1172              :             {
    1173            0 :               error ("stmt (%p) marked modified after optimization pass: ",
    1174              :                      (void *)stmt);
    1175            0 :               print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
    1176            0 :               goto err;
    1177              :             }
    1178              : 
    1179  12948354260 :           if (check_ssa_operands && verify_ssa_operands (cfun, stmt))
    1180              :             {
    1181            0 :               print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
    1182            0 :               goto err;
    1183              :             }
    1184              : 
    1185  12948354260 :           if (gimple_debug_bind_p (stmt)
    1186   6717072494 :               && !gimple_debug_bind_has_value_p (stmt))
    1187   2228690137 :             continue;
    1188              : 
    1189  20645468161 :           FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE|SSA_OP_VUSE)
    1190              :             {
    1191   9925804038 :               op = USE_FROM_PTR (use_p);
    1192   9925804038 :               if (verify_use (bb, definition_block[SSA_NAME_VERSION (op)],
    1193              :                               use_p, stmt, false, names_defined_in_bb))
    1194            0 :                 goto err;
    1195              :             }
    1196              : 
    1197  16001705471 :           FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_ALL_DEFS)
    1198              :             {
    1199   5282041348 :               if (SSA_NAME_DEF_STMT (op) != stmt)
    1200              :                 {
    1201            0 :                   error ("SSA_NAME_DEF_STMT is wrong");
    1202            0 :                   fprintf (stderr, "Expected definition statement:\n");
    1203            0 :                   print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
    1204            0 :                   fprintf (stderr, "\nActual definition statement:\n");
    1205            0 :                   print_gimple_stmt (stderr, SSA_NAME_DEF_STMT (op),
    1206              :                                      4, TDF_VOPS);
    1207            0 :                   goto err;
    1208              :                 }
    1209   5282041348 :               bitmap_set_bit (names_defined_in_bb, SSA_NAME_VERSION (op));
    1210              :             }
    1211              :         }
    1212              : 
    1213   1866247933 :       bitmap_clear (names_defined_in_bb);
    1214              :     }
    1215              : 
    1216    228316154 :   free (definition_block);
    1217              : 
    1218    228316154 :   if (gimple_vop (cfun)
    1219    228316154 :       && ssa_default_def (cfun, gimple_vop (cfun)))
    1220              :     {
    1221    228210229 :       auto_sbitmap visited (last_basic_block_for_fn (cfun) + 1);
    1222    228210229 :       bitmap_clear (visited);
    1223    228210229 :       if (verify_vssa (ENTRY_BLOCK_PTR_FOR_FN (cfun),
    1224              :                        ssa_default_def (cfun, gimple_vop (cfun)), visited))
    1225            0 :         goto err;
    1226    228210229 :     }
    1227              : 
    1228              :   /* Restore the dominance information to its prior known state, so
    1229              :      that we do not perturb the compiler's subsequent behavior.  */
    1230    228316154 :   if (orig_dom_state == DOM_NONE)
    1231     74360165 :     free_dominance_info (CDI_DOMINATORS);
    1232              :   else
    1233    153955989 :     set_dom_info_availability (CDI_DOMINATORS, orig_dom_state);
    1234              : 
    1235    228316154 :   timevar_pop (TV_TREE_SSA_VERIFY);
    1236    228316154 :   return;
    1237              : 
    1238            0 : err:
    1239            0 :   internal_error ("verify_ssa failed");
    1240    228316154 : }
    1241              : 
    1242              : #if __GNUC__ >= 10
    1243              : #  pragma GCC diagnostic pop
    1244              : #endif
    1245              : 
    1246              : /* Initialize global DFA and SSA structures.
    1247              :    If SIZE is non-zero allocated ssa names array of a given size.  */
    1248              : 
    1249              : void
    1250      3424286 : init_tree_ssa (struct function *fn, int size)
    1251              : {
    1252      3424286 :   fn->gimple_df = ggc_cleared_alloc<gimple_df> ();
    1253      3424286 :   fn->gimple_df->default_defs = hash_table<ssa_name_hasher>::create_ggc (20);
    1254      3424286 :   pt_solution_reset (&fn->gimple_df->escaped);
    1255      3424286 :   pt_solution_reset (&fn->gimple_df->escaped_return);
    1256      3424286 :   init_ssanames (fn, size);
    1257      3424286 : }
    1258              : 
    1259              : /* Deallocate memory associated with SSA data structures for FNDECL.  */
    1260              : 
    1261              : void
    1262      3313395 : delete_tree_ssa (struct function *fn)
    1263              : {
    1264      3313395 :   fini_ssanames (fn);
    1265              : 
    1266              :   /* We no longer maintain the SSA operand cache at this point.  */
    1267      3313395 :   if (ssa_operands_active (fn))
    1268      3289289 :     fini_ssa_operands (fn);
    1269              : 
    1270      3313395 :   fn->gimple_df->default_defs->empty ();
    1271      3313395 :   fn->gimple_df->default_defs = NULL;
    1272      3313395 :   pt_solution_reset (&fn->gimple_df->escaped);
    1273      3313395 :   pt_solution_reset (&fn->gimple_df->escaped_return);
    1274      3313395 :   if (fn->gimple_df->decls_to_pointers != NULL)
    1275        43169 :     delete fn->gimple_df->decls_to_pointers;
    1276      3313395 :   fn->gimple_df->decls_to_pointers = NULL;
    1277      3313395 :   fn->gimple_df = NULL;
    1278              : 
    1279              :   /* We no longer need the edge variable maps.  */
    1280      3313395 :   redirect_edge_var_map_empty ();
    1281      3313395 : }
    1282              : 
    1283              : /* Return true if EXPR is a useless type conversion, otherwise return
    1284              :    false.  */
    1285              : 
    1286              : bool
    1287   1007917444 : tree_ssa_useless_type_conversion (tree expr)
    1288              : {
    1289   1007917444 :   tree outer_type, inner_type;
    1290              : 
    1291              :   /* If we have an assignment that merely uses a NOP_EXPR to change
    1292              :      the top of the RHS to the type of the LHS and the type conversion
    1293              :      is "safe", then strip away the type conversion so that we can
    1294              :      enter LHS = RHS into the const_and_copies table.  */
    1295   1007917444 :   if (!CONVERT_EXPR_P (expr)
    1296    931098455 :       && TREE_CODE (expr) != VIEW_CONVERT_EXPR
    1297    930021848 :       && TREE_CODE (expr) != NON_LVALUE_EXPR)
    1298              :     return false;
    1299              : 
    1300     78464158 :   outer_type = TREE_TYPE (expr);
    1301     78464158 :   inner_type = TREE_TYPE (TREE_OPERAND (expr, 0));
    1302              : 
    1303     78464158 :   if (inner_type == error_mark_node)
    1304              :     return false;
    1305              : 
    1306     78464115 :   return useless_type_conversion_p (outer_type, inner_type);
    1307              : }
    1308              : 
    1309              : /* Strip conversions from EXP according to
    1310              :    tree_ssa_useless_type_conversion and return the resulting
    1311              :    expression.  */
    1312              : 
    1313              : tree
    1314    972350866 : tree_ssa_strip_useless_type_conversions (tree exp)
    1315              : {
    1316    994590349 :   while (tree_ssa_useless_type_conversion (exp))
    1317     22239483 :     exp = TREE_OPERAND (exp, 0);
    1318    972350866 :   return exp;
    1319              : }
    1320              : 
    1321              : /* Return true if T, as SSA_NAME, has an implicit default defined value.  */
    1322              : 
    1323              : bool
    1324    390641128 : ssa_defined_default_def_p (tree t)
    1325              : {
    1326    390641128 :   tree var = SSA_NAME_VAR (t);
    1327              : 
    1328    150285765 :   if (!var)
    1329              :     ;
    1330              :   /* Parameters get their initial value from the function entry.  */
    1331    150285765 :   else if (TREE_CODE (var) == PARM_DECL)
    1332              :     return true;
    1333              :   /* When returning by reference the return address is actually a hidden
    1334              :      parameter.  */
    1335    118611688 :   else if (TREE_CODE (var) == RESULT_DECL && DECL_BY_REFERENCE (var))
    1336              :     return true;
    1337              :   /* Hard register variables get their initial value from the ether.  */
    1338    118397554 :   else if (VAR_P (var) && DECL_HARD_REGISTER (var))
    1339            0 :     return true;
    1340              : 
    1341              :   return false;
    1342              : }
    1343              : 
    1344              : 
    1345              : /* Return true if T, an SSA_NAME, has an undefined value.  PARTIAL is what
    1346              :    should be returned if the value is only partially undefined.  */
    1347              : 
    1348              : bool
    1349    390301719 : ssa_undefined_value_p (tree t, bool partial)
    1350              : {
    1351    390301719 :   gimple *def_stmt;
    1352              : 
    1353    780603438 :   gcc_checking_assert (!virtual_operand_p (t));
    1354              : 
    1355    390301719 :   if (ssa_defined_default_def_p (t))
    1356              :     return false;
    1357              : 
    1358              :   /* The value is undefined iff its definition statement is empty.  */
    1359    358478111 :   def_stmt = SSA_NAME_DEF_STMT (t);
    1360    358478111 :   if (gimple_nop_p (def_stmt))
    1361              :     return true;
    1362              : 
    1363              :   /* The value is undefined if the definition statement is a call
    1364              :      to .DEFERRED_INIT function.  Except for AUTO_INIT_CXX26 which is
    1365              :      undefined but needs to have the same value in all uses.  */
    1366    348124502 :   if (gimple_call_internal_p (def_stmt, IFN_DEFERRED_INIT))
    1367              :     {
    1368        40563 :       if (tree_to_uhwi (gimple_call_arg (def_stmt, 1)) & AUTO_INIT_CXX26)
    1369              :         return false;
    1370              :       else
    1371              :         return true;
    1372              :     }
    1373              : 
    1374              :   /* The value is partially undefined if the definition statement is
    1375              :      a REALPART_EXPR or IMAGPART_EXPR and its operand is defined by
    1376              :      the call to .DEFERRED_INIT function.  This is for handling the
    1377              :      following case:
    1378              : 
    1379              :   1 typedef _Complex float C;
    1380              :   2 C foo (int cond)
    1381              :   3 {
    1382              :   4   C f;
    1383              :   5   __imag__ f = 0;
    1384              :   6   if (cond)
    1385              :   7     {
    1386              :   8       __real__ f = 1;
    1387              :   9       return f;
    1388              :  10     }
    1389              :  11   return f;
    1390              :  12 }
    1391              : 
    1392              :     with -ftrivial-auto-var-init, compiler will insert the following
    1393              :     artificial initialization:
    1394              :   f = .DEFERRED_INIT (f, 2);
    1395              :   _1 = REALPART_EXPR <f>;
    1396              : 
    1397              :     we should treat the definition _1 = REALPART_EXPR <f> as undefined.  */
    1398     53462090 :   if (partial && is_gimple_assign (def_stmt)
    1399    389023275 :       && (gimple_assign_rhs_code (def_stmt) == REALPART_EXPR
    1400     40622269 :           || gimple_assign_rhs_code (def_stmt) == IMAGPART_EXPR))
    1401              :     {
    1402       676746 :       tree real_imag_part = TREE_OPERAND (gimple_assign_rhs1 (def_stmt), 0);
    1403       676746 :       if (TREE_CODE (real_imag_part) == SSA_NAME
    1404       676746 :          && gimple_call_internal_p (SSA_NAME_DEF_STMT (real_imag_part),
    1405              :                                     IFN_DEFERRED_INIT))
    1406              :         return true;
    1407              :     }
    1408              : 
    1409              :   /* Check if the complex was not only partially defined.  */
    1410     53461945 :   if (partial && is_gimple_assign (def_stmt)
    1411    389022985 :       && gimple_assign_rhs_code (def_stmt) == COMPLEX_EXPR)
    1412              :     {
    1413        18401 :       tree rhs1, rhs2;
    1414              : 
    1415        18401 :       rhs1 = gimple_assign_rhs1 (def_stmt);
    1416        18401 :       rhs2 = gimple_assign_rhs2 (def_stmt);
    1417        18059 :       return (TREE_CODE (rhs1) == SSA_NAME && ssa_undefined_value_p (rhs1))
    1418        36419 :              || (TREE_CODE (rhs2) == SSA_NAME && ssa_undefined_value_p (rhs2));
    1419              :     }
    1420              :   return false;
    1421              : }
    1422              : 
    1423              : 
    1424              : /* Return TRUE iff there are any non-PHI uses of VAR that dominate the
    1425              :    end of BB.  If we return TRUE and BB is a loop header, then VAR we
    1426              :    be assumed to be defined within the loop, even if it is marked as
    1427              :    maybe-undefined.  */
    1428              : 
    1429              : bool
    1430       331541 : ssa_name_any_use_dominates_bb_p (tree var, basic_block bb)
    1431              : {
    1432       331541 :   imm_use_iterator iter;
    1433       331541 :   use_operand_p use_p;
    1434      1084003 :   FOR_EACH_IMM_USE_FAST (use_p, iter, var)
    1435              :     {
    1436       776468 :       if (is_a <gphi *> (USE_STMT (use_p))
    1437       776468 :           || is_gimple_debug (USE_STMT (use_p)))
    1438       705571 :         continue;
    1439        70897 :       basic_block dombb = gimple_bb (USE_STMT (use_p));
    1440        70897 :       if (dominated_by_p (CDI_DOMINATORS, bb, dombb))
    1441        24006 :         return true;
    1442        24006 :     }
    1443              : 
    1444       307535 :   return false;
    1445              : }
    1446              : 
    1447              : /* Mark as maybe_undef any SSA_NAMEs that are unsuitable as ivopts
    1448              :    candidates for potentially involving undefined behavior.  */
    1449              : 
    1450              : void
    1451     12406286 : mark_ssa_maybe_undefs (void)
    1452              : {
    1453     12406286 :   auto_vec<tree> queue;
    1454              : 
    1455              :   /* Scan all SSA_NAMEs, marking the definitely-undefined ones as
    1456              :      maybe-undefined and queuing them for propagation, while clearing
    1457              :      the mark on others.  */
    1458     12406286 :   unsigned int i;
    1459     12406286 :   tree var;
    1460    613623026 :   FOR_EACH_SSA_NAME (i, var, cfun)
    1461              :     {
    1462    405974340 :       if (SSA_NAME_IS_VIRTUAL_OPERAND (var)
    1463    405974340 :           || !ssa_undefined_value_p (var, false))
    1464    397742800 :         ssa_name_set_maybe_undef (var, false);
    1465              :       else
    1466              :         {
    1467      8231540 :           ssa_name_set_maybe_undef (var);
    1468      8231540 :           queue.safe_push (var);
    1469      8231540 :           if (dump_file && (dump_flags & TDF_DETAILS))
    1470          138 :             fprintf (dump_file, "marking _%i as maybe-undef\n",
    1471           69 :                      SSA_NAME_VERSION (var));
    1472              :         }
    1473              :     }
    1474              : 
    1475              :   /* Now propagate maybe-undefined from a DEF to any other PHI that
    1476              :      uses it, as long as there isn't any intervening use of DEF.  */
    1477     22151412 :   while (!queue.is_empty ())
    1478              :     {
    1479      8535908 :       var = queue.pop ();
    1480      8535908 :       imm_use_iterator iter;
    1481      8535908 :       use_operand_p use_p;
    1482     10067124 :       FOR_EACH_IMM_USE_FAST (use_p, iter, var)
    1483              :         {
    1484              :           /* Any uses of VAR that aren't PHI args imply VAR must be
    1485              :              defined, otherwise undefined behavior would have been
    1486              :              definitely invoked.  Only PHI args may hold
    1487              :              maybe-undefined values without invoking undefined
    1488              :              behavior for that reason alone.  */
    1489      1531216 :           if (!is_a <gphi *> (USE_STMT (use_p)))
    1490      1226848 :             continue;
    1491       545863 :           gphi *phi = as_a <gphi *> (USE_STMT (use_p));
    1492              : 
    1493       545863 :           tree def = gimple_phi_result (phi);
    1494       545863 :           if (ssa_name_maybe_undef_p (def))
    1495       223232 :             continue;
    1496              : 
    1497              :           /* Look for any uses of the maybe-unused SSA_NAME that
    1498              :              dominates the block that reaches the incoming block
    1499              :              corresponding to the PHI arg in which it is mentioned.
    1500              :              That means we can assume the SSA_NAME is defined in that
    1501              :              path, so we only mark a PHI result as maybe-undef if we
    1502              :              find an unused reaching SSA_NAME.  */
    1503       322631 :           int idx = phi_arg_index_from_use (use_p);
    1504       322631 :           basic_block bb = gimple_phi_arg_edge (phi, idx)->src;
    1505       322631 :           if (ssa_name_any_use_dominates_bb_p (var, bb))
    1506        18263 :             continue;
    1507              : 
    1508       304368 :           ssa_name_set_maybe_undef (def);
    1509       304368 :           queue.safe_push (def);
    1510       304368 :           if (dump_file && (dump_flags & TDF_DETAILS))
    1511            0 :             fprintf (dump_file, "marking _%i as maybe-undef because of _%i\n",
    1512            0 :                      SSA_NAME_VERSION (def), SSA_NAME_VERSION (var));
    1513      8535908 :         }
    1514              :     }
    1515     12406286 : }
    1516              : 
    1517              : 
    1518              : /* If necessary, rewrite the base of the reference tree *TP from
    1519              :    a MEM_REF to a plain or converted symbol.  */
    1520              : 
    1521              : static void
    1522     24171845 : maybe_rewrite_mem_ref_base (tree *tp, bitmap suitable_for_renaming)
    1523              : {
    1524     24171845 :   tree sym;
    1525              : 
    1526     27561935 :   while (handled_component_p (*tp))
    1527      3390090 :     tp = &TREE_OPERAND (*tp, 0);
    1528     24171845 :   if (TREE_CODE (*tp) == MEM_REF
    1529      1737103 :       && TREE_CODE (TREE_OPERAND (*tp, 0)) == ADDR_EXPR
    1530       313652 :       && (sym = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0))
    1531       313652 :       && DECL_P (sym)
    1532       313202 :       && !TREE_ADDRESSABLE (sym)
    1533       182604 :       && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym))
    1534        58335 :       && is_gimple_reg_type (TREE_TYPE (*tp))
    1535     24230170 :       && ! VOID_TYPE_P (TREE_TYPE (*tp)))
    1536              :     {
    1537        58325 :       if (VECTOR_TYPE_P (TREE_TYPE (sym))
    1538         1438 :           && useless_type_conversion_p (TREE_TYPE (*tp),
    1539         1438 :                                         TREE_TYPE (TREE_TYPE (sym)))
    1540        58705 :           && multiple_p (mem_ref_offset (*tp),
    1541          380 :                          wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (*tp)))))
    1542              :         {
    1543          758 :           *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym,
    1544          379 :                         TYPE_SIZE (TREE_TYPE (*tp)),
    1545              :                         int_const_binop (MULT_EXPR,
    1546          758 :                                          bitsize_int (BITS_PER_UNIT),
    1547          379 :                                          TREE_OPERAND (*tp, 1)));
    1548              :         }
    1549        57946 :       else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
    1550         1056 :                && useless_type_conversion_p (TREE_TYPE (*tp),
    1551         1056 :                                              TREE_TYPE (TREE_TYPE (sym)))
    1552        57951 :                && (integer_zerop (TREE_OPERAND (*tp, 1))
    1553            3 :                    || tree_int_cst_equal (TREE_OPERAND (*tp, 1),
    1554            3 :                                           TYPE_SIZE_UNIT (TREE_TYPE (*tp)))))
    1555              :         {
    1556            6 :           *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
    1557              :                         ? REALPART_EXPR : IMAGPART_EXPR,
    1558            4 :                         TREE_TYPE (*tp), sym);
    1559              :         }
    1560        57942 :       else if (integer_zerop (TREE_OPERAND (*tp, 1))
    1561        57942 :                && DECL_SIZE (sym) == TYPE_SIZE (TREE_TYPE (*tp)))
    1562              :         {
    1563        57578 :           if (!useless_type_conversion_p (TREE_TYPE (*tp),
    1564        57578 :                                           TREE_TYPE (sym)))
    1565        12530 :             *tp = build1 (VIEW_CONVERT_EXPR,
    1566        12530 :                           TREE_TYPE (*tp), sym);
    1567              :           else
    1568        45048 :             *tp = sym;
    1569              :         }
    1570          364 :       else if (DECL_SIZE (sym)
    1571          364 :                && TREE_CODE (DECL_SIZE (sym)) == INTEGER_CST
    1572          364 :                && (known_subrange_p
    1573          364 :                    (mem_ref_offset (*tp),
    1574          364 :                     wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (*tp))),
    1575          364 :                     0, wi::to_offset (DECL_SIZE_UNIT (sym))))
    1576          364 :                && (! INTEGRAL_TYPE_P (TREE_TYPE (*tp))
    1577          347 :                    || (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp)))
    1578          694 :                        == TYPE_PRECISION (TREE_TYPE (*tp))))
    1579          364 :                && (! INTEGRAL_TYPE_P (TREE_TYPE (sym))
    1580          169 :                    || type_has_mode_precision_p (TREE_TYPE (sym)))
    1581          728 :                && wi::umod_trunc (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp))),
    1582          728 :                                   BITS_PER_UNIT) == 0)
    1583              :         {
    1584          728 :           *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym,
    1585          364 :                         TYPE_SIZE (TREE_TYPE (*tp)),
    1586              :                         wide_int_to_tree (bitsizetype,
    1587          364 :                                           mem_ref_offset (*tp)
    1588          728 :                                           << LOG2_BITS_PER_UNIT));
    1589              :         }
    1590              :     }
    1591     24171845 : }
    1592              : 
    1593              : /* For a tree REF return its base if it is the base of a MEM_REF
    1594              :    that cannot be rewritten into SSA form.  Otherwise return NULL_TREE.  */
    1595              : 
    1596              : static tree
    1597    307336701 : non_rewritable_mem_ref_base (tree ref)
    1598              : {
    1599    307336701 :   tree base;
    1600              : 
    1601              :   /* A plain decl does not need it set.  */
    1602    307336701 :   if (DECL_P (ref))
    1603              :     return NULL_TREE;
    1604              : 
    1605    276488482 :   switch (TREE_CODE (ref))
    1606              :     {
    1607      2954462 :     case REALPART_EXPR:
    1608      2954462 :     case IMAGPART_EXPR:
    1609      2954462 :     case BIT_FIELD_REF:
    1610      2954462 :       if (DECL_P (TREE_OPERAND (ref, 0)))
    1611              :         return NULL_TREE;
    1612              :       break;
    1613      2497423 :     case VIEW_CONVERT_EXPR:
    1614      2497423 :       if (DECL_P (TREE_OPERAND (ref, 0)))
    1615              :         {
    1616      1087993 :           if (TYPE_SIZE (TREE_TYPE (ref))
    1617      1087993 :               != TYPE_SIZE (TREE_TYPE (TREE_OPERAND  (ref, 0))))
    1618          676 :             return TREE_OPERAND (ref, 0);
    1619              :           return NULL_TREE;
    1620              :         }
    1621              :       break;
    1622              :     /* We would need to rewrite ARRAY_REFs or COMPONENT_REFs and even
    1623              :        more so multiple levels of handled components.  */
    1624    274901754 :     default:;
    1625              :     }
    1626              : 
    1627    274901754 :   base = ref;
    1628              : 
    1629              :   /* But watch out for MEM_REFs we cannot lower to a
    1630              :      VIEW_CONVERT_EXPR or a BIT_FIELD_REF.  */
    1631    274901754 :   if (TREE_CODE (base) == MEM_REF
    1632    274901754 :       && TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
    1633              :     {
    1634      6451727 :       tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
    1635      6451727 :       if (! DECL_P (decl))
    1636              :         return NULL_TREE;
    1637      6404832 :       if (! is_gimple_reg_type (TREE_TYPE (base))
    1638      6216660 :           || VOID_TYPE_P (TREE_TYPE (base))
    1639     12621492 :           || TREE_THIS_VOLATILE (decl) != TREE_THIS_VOLATILE (base))
    1640              :         return decl;
    1641      6215413 :       if ((VECTOR_TYPE_P (TREE_TYPE (decl))
    1642      6212442 :            || TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
    1643         4437 :           && useless_type_conversion_p (TREE_TYPE (base),
    1644         4437 :                                         TREE_TYPE (TREE_TYPE (decl)))
    1645         1107 :           && known_ge (mem_ref_offset (base), 0)
    1646         1060 :           && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
    1647              :                        mem_ref_offset (base))
    1648      6216467 :           && multiple_p (mem_ref_offset (base),
    1649         1054 :                          wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (base)))))
    1650         1052 :         return NULL_TREE;
    1651              :       /* For same sizes and zero offset we can use a VIEW_CONVERT_EXPR.  */
    1652      6214361 :       if (integer_zerop (TREE_OPERAND (base, 1))
    1653      6214361 :           && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (base)))
    1654              :         return NULL_TREE;
    1655              :       /* For integral typed extracts we can use a BIT_FIELD_REF.  */
    1656      5548621 :       if (DECL_SIZE (decl)
    1657      5544244 :           && TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST
    1658      5544244 :           && (known_subrange_p
    1659      5544244 :               (mem_ref_offset (base),
    1660      5544244 :                wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (base))),
    1661      5544244 :                0, wi::to_poly_offset (DECL_SIZE_UNIT (decl))))
    1662              :           /* ???  We can't handle bitfield precision extracts without
    1663              :              either using an alternate type for the BIT_FIELD_REF and
    1664              :              then doing a conversion or possibly adjusting the offset
    1665              :              according to endianness.  */
    1666      5541772 :           && (! INTEGRAL_TYPE_P (TREE_TYPE (base))
    1667      2957531 :               || (wi::to_offset (TYPE_SIZE (TREE_TYPE (base)))
    1668      5915062 :                   == TYPE_PRECISION (TREE_TYPE (base))))
    1669              :           /* ???  Likewise for extracts from bitfields, we'd have
    1670              :              to pun the base object to a size precision mode first.  */
    1671      5535290 :           && (! INTEGRAL_TYPE_P (TREE_TYPE (decl))
    1672        43046 :               || type_has_mode_precision_p (TREE_TYPE (decl)))
    1673     11047313 :           && wi::umod_trunc (wi::to_offset (TYPE_SIZE (TREE_TYPE (base))),
    1674     10997384 :                              BITS_PER_UNIT) == 0)
    1675      5498692 :         return NULL_TREE;
    1676        49929 :       return decl;
    1677              :     }
    1678              : 
    1679              :   /* We cannot rewrite a decl in the base.  */
    1680    268450027 :   base = get_base_address (ref);
    1681    268450027 :   if (DECL_P (base))
    1682              :     return base;
    1683              : 
    1684              :   /* We cannot rewrite TARGET_MEM_REFs.  */
    1685    248070654 :   else if (TREE_CODE (base) == TARGET_MEM_REF
    1686    248070654 :            && TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
    1687              :     {
    1688            0 :       tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
    1689            0 :       if (! DECL_P (decl))
    1690              :         return NULL_TREE;
    1691            0 :       return decl;
    1692              :     }
    1693              : 
    1694              :   return NULL_TREE;
    1695              : }
    1696              : 
    1697              : /* For an lvalue tree LHS return true if it cannot be rewritten into SSA form.
    1698              :    Otherwise return true.  */
    1699              : 
    1700              : static bool
    1701    108480244 : non_rewritable_lvalue_p (tree lhs)
    1702              : {
    1703              :   /* A plain decl is always rewritable.  */
    1704    108480244 :   if (DECL_P (lhs))
    1705              :     return false;
    1706              : 
    1707              :   /* We can re-write REALPART_EXPR and IMAGPART_EXPR sets in
    1708              :      a reasonably efficient manner... */
    1709     63194954 :   if ((TREE_CODE (lhs) == REALPART_EXPR
    1710     63194954 :        || TREE_CODE (lhs) == IMAGPART_EXPR)
    1711     63194954 :       && DECL_P (TREE_OPERAND (lhs, 0)))
    1712              :     return false;
    1713              : 
    1714              :   /* ???  The following could be relaxed allowing component
    1715              :      references that do not change the access size.  */
    1716     63162982 :   if (TREE_CODE (lhs) == MEM_REF
    1717     63162982 :       && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR)
    1718              :     {
    1719      7525176 :       tree decl = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0);
    1720              : 
    1721              :       /* A decl that is wrapped inside a MEM-REF that covers
    1722              :          it full is also rewritable.  */
    1723      7525176 :       if (integer_zerop (TREE_OPERAND (lhs, 1))
    1724      2193683 :           && DECL_P (decl)
    1725      2193623 :           && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (lhs))
    1726              :           /* If the dynamic type of the decl has larger precision than
    1727              :              the decl itself we can't use the decls type for SSA rewriting.  */
    1728       572256 :           && ((! INTEGRAL_TYPE_P (TREE_TYPE (decl))
    1729        14213 :                || compare_tree_int (DECL_SIZE (decl),
    1730        14213 :                                     TYPE_PRECISION (TREE_TYPE (decl))) == 0)
    1731          817 :               || (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    1732          796 :                   && (TYPE_PRECISION (TREE_TYPE (decl))
    1733          796 :                       >= TYPE_PRECISION (TREE_TYPE (lhs)))))
    1734              :           /* Make sure we are not re-writing non-float copying into float
    1735              :              copying as that can incur normalization.  */
    1736       572100 :           && (! FLOAT_TYPE_P (TREE_TYPE (decl))
    1737         4846 :               || types_compatible_p (TREE_TYPE (lhs), TREE_TYPE (decl)))
    1738      8093021 :           && (TREE_THIS_VOLATILE (decl) == TREE_THIS_VOLATILE (lhs)))
    1739              :         return false;
    1740              : 
    1741              :       /* A vector-insert using a MEM_REF or ARRAY_REF is rewritable
    1742              :          using a BIT_INSERT_EXPR.  */
    1743      6957817 :       if (DECL_P (decl)
    1744      6957751 :           && VECTOR_TYPE_P (TREE_TYPE (decl))
    1745         3000 :           && TYPE_MODE (TREE_TYPE (decl)) != BLKmode
    1746          284 :           && known_ge (mem_ref_offset (lhs), 0)
    1747          249 :           && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
    1748              :                        mem_ref_offset (lhs))
    1749          249 :           && multiple_p (mem_ref_offset (lhs),
    1750          249 :                          wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (lhs))))
    1751     13915568 :           && known_ge (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (decl))),
    1752              :                        wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (lhs)))))
    1753              :         {
    1754          248 :           poly_uint64 lhs_bits, nelts;
    1755          248 :           if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)), &lhs_bits)
    1756          250 :               && multiple_p (lhs_bits,
    1757              :                              tree_to_uhwi
    1758          248 :                                (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl)))),
    1759              :                              &nelts)
    1760          268 :               && valid_vector_subparts_p (nelts))
    1761              :             {
    1762          228 :               if (known_eq (nelts, 1u))
    1763          228 :                 return false;
    1764              :               /* For sub-vector inserts the insert vector mode has to be
    1765              :                  supported.  */
    1766          175 :               tree vtype = build_vector_type (TREE_TYPE (TREE_TYPE (decl)),
    1767          175 :                                               nelts);
    1768          175 :               if (TYPE_MODE (vtype) != BLKmode)
    1769              :                 return false;
    1770              :             }
    1771              :         }
    1772              :     }
    1773              : 
    1774              :   /* A vector-insert using a BIT_FIELD_REF is rewritable using
    1775              :      BIT_INSERT_EXPR.  */
    1776     62595395 :   if (TREE_CODE (lhs) == BIT_FIELD_REF
    1777        22604 :       && DECL_P (TREE_OPERAND (lhs, 0))
    1778        16963 :       && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (lhs, 0)))
    1779        16909 :       && TYPE_MODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) != BLKmode
    1780         4300 :       && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
    1781         4300 :                           TYPE_SIZE_UNIT
    1782              :                             (TREE_TYPE (TREE_TYPE (TREE_OPERAND (lhs, 0)))), 0)
    1783     62599694 :       && (tree_to_uhwi (TREE_OPERAND (lhs, 2))
    1784         4299 :           % tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs)))) == 0)
    1785         4299 :     return false;
    1786              : 
    1787              :   return true;
    1788              : }
    1789              : 
    1790              : /* When possible, clear TREE_ADDRESSABLE bit, set or clear DECL_NOT_GIMPLE_REG_P
    1791              :    and mark the variable VAR for conversion into SSA.  Return true when updating
    1792              :    stmts is required.  */
    1793              : 
    1794              : static void
    1795    110189203 : maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
    1796              :                     bitmap suitable_for_renaming)
    1797              : {
    1798              :   /* Global Variables, result decls cannot be changed.  */
    1799    110189203 :   if (is_global_var (var)
    1800    108534382 :       || TREE_CODE (var) == RESULT_DECL
    1801    218723585 :       || bitmap_bit_p (addresses_taken, DECL_UID (var)))
    1802              :     return;
    1803              : 
    1804     99190308 :   bool maybe_reg = false;
    1805     99190308 :   if (TREE_ADDRESSABLE (var))
    1806              :     {
    1807      1585162 :       TREE_ADDRESSABLE (var) = 0;
    1808      1585162 :       maybe_reg = true;
    1809      1585162 :       if (dump_file)
    1810              :         {
    1811           71 :           fprintf (dump_file, "No longer having address taken: ");
    1812           71 :           print_generic_expr (dump_file, var);
    1813           71 :           fprintf (dump_file, "\n");
    1814              :         }
    1815              :     }
    1816              : 
    1817              :   /* For register type decls if we do not have any partial defs
    1818              :      we cannot express in SSA form mark them as DECL_NOT_GIMPLE_REG_P
    1819              :      as to avoid SSA rewrite.  For the others go ahead and mark
    1820              :      them for renaming.  */
    1821     99190308 :   if (is_gimple_reg_type (TREE_TYPE (var)))
    1822              :     {
    1823     82616572 :       if (bitmap_bit_p (not_reg_needs, DECL_UID (var)))
    1824              :         {
    1825        36610 :           DECL_NOT_GIMPLE_REG_P (var) = 1;
    1826        36610 :           if (dump_file)
    1827              :             {
    1828            4 :               fprintf (dump_file, "Has partial defs: ");
    1829            4 :               print_generic_expr (dump_file, var);
    1830            4 :               fprintf (dump_file, "\n");
    1831              :             }
    1832              :         }
    1833    165114284 :       else if (BITINT_TYPE_P (TREE_TYPE (var))
    1834        45658 :                && (cfun->curr_properties & PROP_gimple_lbitint) != 0
    1835     82606748 :                && TYPE_PRECISION (TREE_TYPE (var)) > MAX_FIXED_MODE_SIZE)
    1836              :         {
    1837              :           /* Don't rewrite large/huge _BitInt vars after _BitInt lowering
    1838              :              into SSA form.  */
    1839         2999 :           DECL_NOT_GIMPLE_REG_P (var) = 1;
    1840         2999 :           if (dump_file)
    1841              :             {
    1842            0 :               fprintf (dump_file, "_BitInt var after its lowering: ");
    1843            0 :               print_generic_expr (dump_file, var);
    1844            0 :               fprintf (dump_file, "\n");
    1845              :             }
    1846              :         }
    1847     82576963 :       else if (DECL_NOT_GIMPLE_REG_P (var))
    1848              :         {
    1849         9024 :           maybe_reg = true;
    1850         9024 :           DECL_NOT_GIMPLE_REG_P (var) = 0;
    1851              :         }
    1852     82616572 :       if (maybe_reg)
    1853              :         {
    1854       538730 :           if (is_gimple_reg (var))
    1855              :             {
    1856       530837 :               if (dump_file)
    1857              :                 {
    1858           19 :                   fprintf (dump_file, "Now a gimple register: ");
    1859           19 :                   print_generic_expr (dump_file, var);
    1860           19 :                   fprintf (dump_file, "\n");
    1861              :                 }
    1862       530837 :               bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
    1863              :             }
    1864              :           else
    1865         7893 :             DECL_NOT_GIMPLE_REG_P (var) = 1;
    1866              :         }
    1867              :     }
    1868              : }
    1869              : 
    1870              : /* Return true when STMT is ASAN mark where second argument is an address
    1871              :    of a local variable.  */
    1872              : 
    1873              : static bool
    1874     61136610 : is_asan_mark_p (gimple *stmt)
    1875              : {
    1876     61136610 :   if (!gimple_call_internal_p (stmt, IFN_ASAN_MARK))
    1877              :     return false;
    1878              : 
    1879        57787 :   tree addr = get_base_address (gimple_call_arg (stmt, 1));
    1880        57787 :   if (TREE_CODE (addr) == ADDR_EXPR
    1881        57787 :       && VAR_P (TREE_OPERAND (addr, 0)))
    1882              :     {
    1883        57583 :       tree var = TREE_OPERAND (addr, 0);
    1884        57583 :       if (lookup_attribute (ASAN_USE_AFTER_SCOPE_ATTRIBUTE,
    1885        57583 :                             DECL_ATTRIBUTES (var)))
    1886              :         return false;
    1887              : 
    1888        52564 :       unsigned addressable = TREE_ADDRESSABLE (var);
    1889        52564 :       TREE_ADDRESSABLE (var) = 0;
    1890        52564 :       bool r = is_gimple_reg (var);
    1891        52564 :       TREE_ADDRESSABLE (var) = addressable;
    1892        52564 :       return r;
    1893              :     }
    1894              : 
    1895              :   return false;
    1896              : }
    1897              : 
    1898              : /* Helper for set_addresses_taken.  If the base of ADDR is a DECL,
    1899              :    set the bit for its uid in the bitmap passed as DATA and return
    1900              :    true; otherwise return false.  */
    1901              : 
    1902              : static bool
    1903     56088536 : set_addresses_taken_1 (gimple *, tree addr, tree, void *data)
    1904              : {
    1905     56088536 :   bitmap addresses_taken = (bitmap)data;
    1906     56088536 :   addr = get_base_address (addr);
    1907     56088536 :   if (addr && DECL_P (addr))
    1908              :     {
    1909     35658724 :       bitmap_set_bit (addresses_taken, DECL_UID (addr));
    1910     35658724 :       return true;
    1911              :     }
    1912              :   return false;
    1913              : }
    1914              : 
    1915              : /* Set the bit for the uid of all DECLs that have their address taken in
    1916              :    STMT in the ADDRESSES_TAKEN bitmap.  Return true if there are any.  */
    1917              : 
    1918              : static bool
    1919    887717039 : set_addresses_taken (gimple *stmt, bitmap addresses_taken)
    1920              : {
    1921    887717039 :   return walk_stmt_load_store_addr_ops (stmt, addresses_taken, NULL, NULL,
    1922    887717039 :                                         set_addresses_taken_1);
    1923              : }
    1924              : 
    1925              : /* Compute TREE_ADDRESSABLE and whether we have unhandled partial defs
    1926              :    for local variables.  */
    1927              : 
    1928              : void
    1929     12893789 : execute_update_addresses_taken (void)
    1930              : {
    1931     12893789 :   basic_block bb;
    1932     12893789 :   auto_bitmap addresses_taken;
    1933     12893789 :   auto_bitmap not_reg_needs;
    1934     12893789 :   auto_bitmap suitable_for_renaming;
    1935     12893789 :   bool optimistic_not_addressable = false;
    1936     12893789 :   tree var;
    1937     12893789 :   unsigned i;
    1938              : 
    1939     12893789 :   timevar_push (TV_ADDRESS_TAKEN);
    1940              : 
    1941              :   /* Collect into ADDRESSES_TAKEN all variables whose address is taken within
    1942              :      the function body.  */
    1943    128296928 :   FOR_EACH_BB_FN (bb, cfun)
    1944              :     {
    1945   1118544829 :       for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
    1946    887738551 :            gsi_next (&gsi))
    1947              :         {
    1948    887738551 :           gimple *stmt = gsi_stmt (gsi);
    1949    887738551 :           enum gimple_code code = gimple_code (stmt);
    1950    887738551 :           tree decl;
    1951              : 
    1952    887738551 :           if (code == GIMPLE_CALL)
    1953              :             {
    1954     58687927 :               if (optimize_atomic_compare_exchange_p (stmt))
    1955              :                 {
    1956              :                   /* For __atomic_compare_exchange_N if the second argument
    1957              :                      is &var, don't mark var addressable;
    1958              :                      if it becomes non-addressable, we'll rewrite it into
    1959              :                      ATOMIC_COMPARE_EXCHANGE call.  */
    1960         5830 :                   tree arg = gimple_call_arg (stmt, 1);
    1961         5830 :                   gimple_call_set_arg (stmt, 1, null_pointer_node);
    1962         5830 :                   set_addresses_taken (stmt, addresses_taken);
    1963         5830 :                   gimple_call_set_arg (stmt, 1, arg);
    1964              :                   /* Remember we have to check again below.  */
    1965         5830 :                   optimistic_not_addressable = true;
    1966              :                 }
    1967     58682097 :               else if (is_asan_mark_p (stmt)
    1968     58682097 :                        || gimple_call_internal_p (stmt, IFN_GOMP_SIMT_ENTER))
    1969              :                 ;
    1970     58662022 :               else if (gimple_call_internal_p (stmt, IFN_ASSUME))
    1971              :                 {
    1972              :                   /* An address-taken arguments are not relevant for aliasing
    1973              :                      and we never expand the call (and need the address).
    1974              :                      But we can't use a register.  */
    1975         2984 :                   for (unsigned i = 1; i < gimple_call_num_args (stmt); ++i)
    1976              :                     {
    1977         1547 :                       tree arg = gimple_call_arg (stmt, i);
    1978         1547 :                       if (TREE_CODE (arg) == ADDR_EXPR)
    1979           16 :                         bitmap_set_bit (not_reg_needs,
    1980            8 :                                         DECL_UID (get_base_address
    1981              :                                                     (TREE_OPERAND (arg, 0))));
    1982              :                     }
    1983              :                 }
    1984              :               else
    1985     58660585 :                 set_addresses_taken (stmt, addresses_taken);
    1986              :             }
    1987              :           else
    1988              :             /* Note all addresses taken by the stmt.  */
    1989    829050624 :             set_addresses_taken (stmt, addresses_taken);
    1990              : 
    1991              :           /* If we have a call or an assignment, see if the lhs contains
    1992              :              a local decl that requires not to be a gimple register.  */
    1993    887738551 :           if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
    1994              :             {
    1995    330464349 :               tree lhs = gimple_get_lhs (stmt);
    1996    330464349 :               if (lhs
    1997    295181006 :                   && TREE_CODE (lhs) != SSA_NAME
    1998    438952900 :                   && ((code == GIMPLE_CALL && ! DECL_P (lhs))
    1999    108373424 :                       || non_rewritable_lvalue_p (lhs)))
    2000              :                 {
    2001     62696022 :                   decl = get_base_address (lhs);
    2002     62696022 :                   if (DECL_P (decl))
    2003     43724843 :                     bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    2004              :                 }
    2005              :             }
    2006              : 
    2007    887738551 :           if (gimple_assign_single_p (stmt))
    2008              :             {
    2009    183812495 :               tree rhs = gimple_assign_rhs1 (stmt);
    2010    183812495 :               if ((decl = non_rewritable_mem_ref_base (rhs)))
    2011     20405487 :                 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    2012              :             }
    2013              : 
    2014    703926056 :           else if (code == GIMPLE_CALL)
    2015              :             {
    2016    174529902 :               for (i = 0; i < gimple_call_num_args (stmt); ++i)
    2017              :                 {
    2018    115841975 :                   tree arg = gimple_call_arg (stmt, i);
    2019    115841975 :                   if ((decl = non_rewritable_mem_ref_base (arg)))
    2020       173092 :                     bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    2021              :                 }
    2022              :             }
    2023              : 
    2024    645238129 :           else if (code == GIMPLE_ASM)
    2025              :             {
    2026       687224 :               gasm *asm_stmt = as_a <gasm *> (stmt);
    2027      2063424 :               for (i = 0; i < gimple_asm_noutputs (asm_stmt); ++i)
    2028              :                 {
    2029       688976 :                   tree link = gimple_asm_output_op (asm_stmt, i);
    2030       688976 :                   tree lhs = TREE_VALUE (link);
    2031       688976 :                   if (TREE_CODE (lhs) != SSA_NAME)
    2032              :                     {
    2033       180254 :                       decl = get_base_address (lhs);
    2034       180254 :                       if (DECL_P (decl)
    2035       180254 :                           && (non_rewritable_lvalue_p (lhs)
    2036              :                               /* We cannot move required conversions from
    2037              :                                  the lhs to the rhs in asm statements, so
    2038              :                                  require we do not need any.  */
    2039        96619 :                               || !useless_type_conversion_p
    2040        96619 :                                     (TREE_TYPE (lhs), TREE_TYPE (decl))))
    2041        10811 :                         bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    2042              :                     }
    2043              :                 }
    2044      1147034 :               for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
    2045              :                 {
    2046       459810 :                   tree link = gimple_asm_input_op (asm_stmt, i);
    2047       459810 :                   if ((decl = non_rewritable_mem_ref_base (TREE_VALUE (link))))
    2048         1323 :                     bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    2049              :                 }
    2050              :             }
    2051              :         }
    2052              : 
    2053    153958963 :       for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
    2054     38555824 :            gsi_next (&gsi))
    2055              :         {
    2056     38555824 :           gphi *phi = gsi.phi ();
    2057              : 
    2058    176822571 :           for (i = 0; i < gimple_phi_num_args (phi); i++)
    2059              :             {
    2060     99710923 :               tree op = PHI_ARG_DEF (phi, i);
    2061     99710923 :               if (TREE_CODE (op) == ADDR_EXPR)
    2062       787467 :                 set_addresses_taken_1 (phi, TREE_OPERAND (op, 0), op,
    2063       787467 :                                        (void *)addresses_taken);
    2064              :             }
    2065              :         }
    2066              :     }
    2067              : 
    2068              :   /* We cannot iterate over all referenced vars because that can contain
    2069              :      unused vars from BLOCK trees, which causes code generation differences
    2070              :      for -g vs. -g0.  */
    2071     39855927 :   for (var = DECL_ARGUMENTS (cfun->decl); var; var = DECL_CHAIN (var))
    2072     26962138 :     maybe_optimize_var (var, addresses_taken, not_reg_needs,
    2073              :                         suitable_for_renaming);
    2074              : 
    2075     96120854 :   FOR_EACH_VEC_SAFE_ELT (cfun->local_decls, i, var)
    2076     83227065 :     maybe_optimize_var (var, addresses_taken, not_reg_needs,
    2077              :                         suitable_for_renaming);
    2078              : 
    2079              :   /* Operand caches need to be recomputed for operands referencing the updated
    2080              :      variables and operands need to be rewritten to expose bare symbols.  */
    2081     12893789 :   if (!bitmap_empty_p (suitable_for_renaming)
    2082     12893789 :       || optimistic_not_addressable)
    2083              :     {
    2084      5692433 :       FOR_EACH_BB_FN (bb, cfun)
    2085     48471098 :         for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
    2086              :           {
    2087     37529890 :             gimple *stmt = gsi_stmt (gsi);
    2088              : 
    2089              :             /* Re-write TARGET_MEM_REFs of symbols we want to
    2090              :                rewrite into SSA form.  */
    2091     37529890 :             if (gimple_assign_single_p (stmt))
    2092              :               {
    2093     12477480 :                 tree lhs = gimple_assign_lhs (stmt);
    2094     12477480 :                 tree rhs, *rhsp = gimple_assign_rhs1_ptr (stmt);
    2095     12477480 :                 tree sym;
    2096              : 
    2097              :                 /* Rewrite LHS IMAG/REALPART_EXPR similar to
    2098              :                    gimplify_modify_expr_complex_part.  */
    2099     12477480 :                 if ((TREE_CODE (lhs) == IMAGPART_EXPR
    2100     12477480 :                      || TREE_CODE (lhs) == REALPART_EXPR)
    2101         3641 :                     && DECL_P (TREE_OPERAND (lhs, 0))
    2102     12480080 :                     && bitmap_bit_p (suitable_for_renaming,
    2103         2600 :                                      DECL_UID (TREE_OPERAND (lhs, 0))))
    2104              :                   {
    2105         2522 :                     tree other = make_ssa_name (TREE_TYPE (lhs));
    2106         3792 :                     tree lrhs = build1 (TREE_CODE (lhs) == IMAGPART_EXPR
    2107              :                                         ? REALPART_EXPR : IMAGPART_EXPR,
    2108         2522 :                                         TREE_TYPE (other),
    2109         2522 :                                         TREE_OPERAND (lhs, 0));
    2110         2522 :                     suppress_warning (lrhs);
    2111         2522 :                     gimple *load = gimple_build_assign (other, lrhs);
    2112         2522 :                     location_t loc = gimple_location (stmt);
    2113         2522 :                     gimple_set_location (load, loc);
    2114         5044 :                     gimple_set_vuse (load, gimple_vuse (stmt));
    2115         2522 :                     gsi_insert_before (&gsi, load, GSI_SAME_STMT);
    2116         2522 :                     gimple_assign_set_lhs (stmt, TREE_OPERAND (lhs, 0));
    2117         2522 :                     gimple_assign_set_rhs_with_ops
    2118         3792 :                       (&gsi, COMPLEX_EXPR,
    2119              :                        TREE_CODE (lhs) == IMAGPART_EXPR
    2120         1270 :                        ? other : gimple_assign_rhs1 (stmt),
    2121         2522 :                        TREE_CODE (lhs) == IMAGPART_EXPR
    2122         1252 :                        ? gimple_assign_rhs1 (stmt) : other, NULL_TREE);
    2123         2522 :                     stmt = gsi_stmt (gsi);
    2124         2522 :                     unlink_stmt_vdef (stmt);
    2125         2522 :                     update_stmt (stmt);
    2126         2522 :                     continue;
    2127         2522 :                   }
    2128              : 
    2129              :                 /* Rewrite a vector insert via a BIT_FIELD_REF on the LHS
    2130              :                    into a BIT_INSERT_EXPR.  */
    2131     12474958 :                 if (TREE_CODE (lhs) == BIT_FIELD_REF
    2132          917 :                     && DECL_P (TREE_OPERAND (lhs, 0))
    2133          859 :                     && bitmap_bit_p (suitable_for_renaming,
    2134          859 :                                      DECL_UID (TREE_OPERAND (lhs, 0)))
    2135          716 :                     && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (lhs, 0)))
    2136          716 :                     && TYPE_MODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) != BLKmode
    2137          716 :                     && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
    2138          716 :                                         TYPE_SIZE_UNIT (TREE_TYPE
    2139              :                                           (TREE_TYPE (TREE_OPERAND (lhs, 0)))),
    2140              :                                         0)
    2141     12475674 :                     && (tree_to_uhwi (TREE_OPERAND (lhs, 2))
    2142          716 :                         % tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs))) == 0))
    2143              :                   {
    2144          716 :                     tree var = TREE_OPERAND (lhs, 0);
    2145          716 :                     tree val = gimple_assign_rhs1 (stmt);
    2146          716 :                     if (! types_compatible_p (TREE_TYPE (TREE_TYPE (var)),
    2147          716 :                                               TREE_TYPE (val)))
    2148              :                       {
    2149            0 :                         tree tem = make_ssa_name (TREE_TYPE (TREE_TYPE (var)));
    2150            0 :                         gimple *pun
    2151            0 :                           = gimple_build_assign (tem,
    2152              :                                                  build1 (VIEW_CONVERT_EXPR,
    2153            0 :                                                          TREE_TYPE (tem), val));
    2154            0 :                         gsi_insert_before (&gsi, pun, GSI_SAME_STMT);
    2155            0 :                         val = tem;
    2156              :                       }
    2157          716 :                     tree bitpos = TREE_OPERAND (lhs, 2);
    2158          716 :                     gimple_assign_set_lhs (stmt, var);
    2159          716 :                     gimple_assign_set_rhs_with_ops
    2160          716 :                       (&gsi, BIT_INSERT_EXPR, var, val, bitpos);
    2161          716 :                     stmt = gsi_stmt (gsi);
    2162          716 :                     unlink_stmt_vdef (stmt);
    2163          716 :                     update_stmt (stmt);
    2164          716 :                     continue;
    2165          716 :                   }
    2166              : 
    2167              :                 /* Rewrite a vector insert using a MEM_REF on the LHS
    2168              :                    into a BIT_INSERT_EXPR.  */
    2169     12474242 :                 if (TREE_CODE (lhs) == MEM_REF
    2170       475684 :                     && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
    2171       113203 :                     && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0))
    2172       113203 :                     && DECL_P (sym)
    2173       113203 :                     && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym))
    2174         8425 :                     && VECTOR_TYPE_P (TREE_TYPE (sym))
    2175          183 :                     && TYPE_MODE (TREE_TYPE (sym)) != BLKmode
    2176              :                     /* If it is a full replacement we can do better below.  */
    2177          177 :                     && maybe_ne (wi::to_poly_offset
    2178          177 :                                    (TYPE_SIZE_UNIT (TREE_TYPE (lhs))),
    2179              :                                  wi::to_poly_offset
    2180          177 :                                    (TYPE_SIZE_UNIT (TREE_TYPE (sym))))
    2181           79 :                     && known_ge (mem_ref_offset (lhs), 0)
    2182           79 :                     && known_gt (wi::to_poly_offset
    2183              :                                    (TYPE_SIZE_UNIT (TREE_TYPE (sym))),
    2184              :                                  mem_ref_offset (lhs))
    2185     12474321 :                     && multiple_p (mem_ref_offset (lhs),
    2186              :                                    wi::to_poly_offset
    2187     12474242 :                                      (TYPE_SIZE_UNIT (TREE_TYPE (lhs)))))
    2188              :                   {
    2189           79 :                     tree val = gimple_assign_rhs1 (stmt);
    2190           79 :                     if (! types_compatible_p (TREE_TYPE (val),
    2191           79 :                                               TREE_TYPE (TREE_TYPE (sym))))
    2192              :                       {
    2193           58 :                         poly_uint64 lhs_bits, nelts;
    2194           58 :                         tree temtype = TREE_TYPE (TREE_TYPE (sym));
    2195           58 :                         if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)),
    2196              :                                              &lhs_bits)
    2197          174 :                             && multiple_p (lhs_bits,
    2198              :                                            tree_to_uhwi
    2199           58 :                                              (TYPE_SIZE (TREE_TYPE
    2200              :                                                            (TREE_TYPE (sym)))),
    2201              :                                            &nelts)
    2202           58 :                             && maybe_ne (nelts, 1u)
    2203          148 :                             && valid_vector_subparts_p (nelts))
    2204           32 :                           temtype = build_vector_type (temtype, nelts);
    2205           58 :                         tree tem = make_ssa_name (temtype);
    2206           58 :                         gimple *pun
    2207           58 :                           = gimple_build_assign (tem,
    2208              :                                                  build1 (VIEW_CONVERT_EXPR,
    2209           58 :                                                          TREE_TYPE (tem), val));
    2210           58 :                         gsi_insert_before (&gsi, pun, GSI_SAME_STMT);
    2211           58 :                         val = tem;
    2212              :                       }
    2213           79 :                     tree bitpos
    2214           79 :                       = wide_int_to_tree (bitsizetype,
    2215           79 :                                           mem_ref_offset (lhs) * BITS_PER_UNIT);
    2216           79 :                     gimple_assign_set_lhs (stmt, sym);
    2217           79 :                     gimple_assign_set_rhs_with_ops
    2218           79 :                       (&gsi, BIT_INSERT_EXPR, sym, val, bitpos);
    2219           79 :                     stmt = gsi_stmt (gsi);
    2220           79 :                     unlink_stmt_vdef (stmt);
    2221           79 :                     update_stmt (stmt);
    2222           79 :                     continue;
    2223           79 :                   }
    2224              : 
    2225              :                 /* We shouldn't have any fancy wrapping of
    2226              :                    component-refs on the LHS, but look through
    2227              :                    VIEW_CONVERT_EXPRs as that is easy.  */
    2228     12474168 :                 while (TREE_CODE (lhs) == VIEW_CONVERT_EXPR)
    2229            5 :                   lhs = TREE_OPERAND (lhs, 0);
    2230     12474163 :                 if (TREE_CODE (lhs) == MEM_REF
    2231       475610 :                     && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
    2232       113124 :                     && integer_zerop (TREE_OPERAND (lhs, 1))
    2233        49383 :                     && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0))
    2234        49383 :                     && DECL_P (sym)
    2235        49383 :                     && !TREE_ADDRESSABLE (sym)
    2236     12504068 :                     && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym)))
    2237              :                   lhs = sym;
    2238              :                 else
    2239     12465817 :                   lhs = gimple_assign_lhs (stmt);
    2240              : 
    2241              :                 /* Rewrite the RHS and make sure the resulting assignment
    2242              :                    is validly typed.  */
    2243     12474163 :                 maybe_rewrite_mem_ref_base (rhsp, suitable_for_renaming);
    2244     12474163 :                 rhs = gimple_assign_rhs1 (stmt);
    2245     12474163 :                 if (gimple_assign_lhs (stmt) != lhs
    2246     12482509 :                     && !useless_type_conversion_p (TREE_TYPE (lhs),
    2247         8346 :                                                    TREE_TYPE (rhs)))
    2248              :                   {
    2249         4124 :                     if (gimple_clobber_p (stmt))
    2250              :                       {
    2251           11 :                         rhs = build_constructor (TREE_TYPE (lhs), NULL);
    2252           11 :                         TREE_THIS_VOLATILE (rhs) = 1;
    2253              :                       }
    2254              :                     else
    2255         4113 :                       rhs = fold_build1 (VIEW_CONVERT_EXPR,
    2256              :                                          TREE_TYPE (lhs), rhs);
    2257              :                   }
    2258     12474163 :                 if (gimple_assign_lhs (stmt) != lhs)
    2259         8346 :                   gimple_assign_set_lhs (stmt, lhs);
    2260              : 
    2261     12474163 :                 if (gimple_assign_rhs1 (stmt) != rhs)
    2262              :                   {
    2263         4124 :                     gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    2264         4124 :                     gimple_assign_set_rhs_from_tree (&gsi, rhs);
    2265              :                   }
    2266              :               }
    2267              : 
    2268     25052410 :             else if (gimple_code (stmt) == GIMPLE_CALL)
    2269              :               {
    2270      2460343 :                 unsigned i;
    2271      2460343 :                 if (optimize_atomic_compare_exchange_p (stmt))
    2272              :                   {
    2273         5830 :                     tree expected = gimple_call_arg (stmt, 1);
    2274         5830 :                     tree decl = TREE_OPERAND (expected, 0);
    2275         5830 :                     if (bitmap_bit_p (suitable_for_renaming, DECL_UID (decl)))
    2276              :                       {
    2277         5787 :                         fold_builtin_atomic_compare_exchange (&gsi);
    2278         5787 :                         continue;
    2279              :                       }
    2280           43 :                     else if (!TREE_ADDRESSABLE (decl))
    2281              :                       /* If there are partial defs of the decl we may
    2282              :                          have cleared the addressable bit but set
    2283              :                          DECL_NOT_GIMPLE_REG_P.  We have to restore
    2284              :                          TREE_ADDRESSABLE here.  */
    2285           27 :                       TREE_ADDRESSABLE (decl) = 1;
    2286              :                   }
    2287      2454513 :                 else if (is_asan_mark_p (stmt))
    2288              :                   {
    2289          392 :                     tree var = TREE_OPERAND (gimple_call_arg (stmt, 1), 0);
    2290          392 :                     if (bitmap_bit_p (suitable_for_renaming, DECL_UID (var)))
    2291              :                       {
    2292          344 :                         unlink_stmt_vdef (stmt);
    2293          344 :                         if (asan_mark_p (stmt, ASAN_MARK_POISON))
    2294              :                           {
    2295          177 :                             gcall *call
    2296          177 :                               = gimple_build_call_internal (IFN_ASAN_POISON, 0);
    2297          177 :                             gimple_call_set_lhs (call, var);
    2298          177 :                             gsi_replace (&gsi, call, true);
    2299              :                           }
    2300              :                         else
    2301              :                           {
    2302              :                             /* In ASAN_MARK (UNPOISON, &b, ...) the variable
    2303              :                                is uninitialized.  Avoid dependencies on
    2304              :                                previous out of scope value.  */
    2305          167 :                             tree clobber = build_clobber (TREE_TYPE (var));
    2306          167 :                             gimple *g = gimple_build_assign (var, clobber);
    2307          167 :                             gsi_replace (&gsi, g, true);
    2308              :                           }
    2309          344 :                         continue;
    2310          344 :                       }
    2311              :                   }
    2312      2454121 :                 else if (gimple_call_internal_p (stmt, IFN_GOMP_SIMT_ENTER))
    2313            0 :                   for (i = 1; i < gimple_call_num_args (stmt); i++)
    2314              :                     {
    2315            0 :                       tree *argp = gimple_call_arg_ptr (stmt, i);
    2316            0 :                       if (*argp == null_pointer_node)
    2317            0 :                         continue;
    2318            0 :                       gcc_assert (TREE_CODE (*argp) == ADDR_EXPR
    2319              :                                   && VAR_P (TREE_OPERAND (*argp, 0)));
    2320            0 :                       tree var = TREE_OPERAND (*argp, 0);
    2321            0 :                       if (bitmap_bit_p (suitable_for_renaming, DECL_UID (var)))
    2322            0 :                         *argp = null_pointer_node;
    2323              :                     }
    2324      6875447 :                 for (i = 0; i < gimple_call_num_args (stmt); ++i)
    2325              :                   {
    2326      4421235 :                     tree *argp = gimple_call_arg_ptr (stmt, i);
    2327      4421235 :                     maybe_rewrite_mem_ref_base (argp, suitable_for_renaming);
    2328              :                   }
    2329              :               }
    2330              : 
    2331     22592067 :             else if (gimple_code (stmt) == GIMPLE_ASM)
    2332              :               {
    2333        11709 :                 gasm *asm_stmt = as_a <gasm *> (stmt);
    2334        11709 :                 unsigned i;
    2335        62141 :                 for (i = 0; i < gimple_asm_noutputs (asm_stmt); ++i)
    2336              :                   {
    2337        38723 :                     tree link = gimple_asm_output_op (asm_stmt, i);
    2338        38723 :                     maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
    2339              :                                                 suitable_for_renaming);
    2340              :                   }
    2341        27012 :                 for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
    2342              :                   {
    2343        15303 :                     tree link = gimple_asm_input_op (asm_stmt, i);
    2344        15303 :                     maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
    2345              :                                                 suitable_for_renaming);
    2346              :                   }
    2347              :               }
    2348              : 
    2349     22580358 :             else if (gimple_debug_bind_p (stmt)
    2350     16790572 :                      && gimple_debug_bind_has_value_p (stmt))
    2351              :               {
    2352      7222421 :                 tree *valuep = gimple_debug_bind_get_value_ptr (stmt);
    2353      7222421 :                 tree decl;
    2354      7222421 :                 maybe_rewrite_mem_ref_base (valuep, suitable_for_renaming);
    2355      7222421 :                 decl = non_rewritable_mem_ref_base (*valuep);
    2356      7222421 :                 if (decl
    2357      7222421 :                     && bitmap_bit_p (suitable_for_renaming, DECL_UID (decl)))
    2358           10 :                   gimple_debug_bind_reset_value (stmt);
    2359              :               }
    2360              : 
    2361     51143855 :             if (gimple_references_memory_p (stmt)
    2362     32562176 :                 || is_gimple_debug (stmt))
    2363     21748838 :               update_stmt (stmt);
    2364              : 
    2365     37520442 :             gsi_next (&gsi);
    2366              :           }
    2367              : 
    2368              :       /* Update SSA form here, we are called as non-pass as well.  */
    2369       221829 :       if (number_of_loops (cfun) > 1
    2370       221829 :           && loops_state_satisfies_p (LOOP_CLOSED_SSA))
    2371          148 :         rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
    2372              :       else
    2373       221681 :         update_ssa (TODO_update_ssa);
    2374              :     }
    2375              : 
    2376     12893789 :   timevar_pop (TV_ADDRESS_TAKEN);
    2377     12893789 : }
    2378              : 
    2379              : namespace {
    2380              : 
    2381              : const pass_data pass_data_update_address_taken =
    2382              : {
    2383              :   GIMPLE_PASS, /* type */
    2384              :   "addressables", /* name */
    2385              :   OPTGROUP_NONE, /* optinfo_flags */
    2386              :   TV_ADDRESS_TAKEN, /* tv_id */
    2387              :   PROP_ssa, /* properties_required */
    2388              :   0, /* properties_provided */
    2389              :   0, /* properties_destroyed */
    2390              :   0, /* todo_flags_start */
    2391              :   TODO_update_address_taken, /* todo_flags_finish */
    2392              : };
    2393              : 
    2394              : class pass_update_address_taken : public gimple_opt_pass
    2395              : {
    2396              : public:
    2397            0 :   pass_update_address_taken (gcc::context *ctxt)
    2398            0 :     : gimple_opt_pass (pass_data_update_address_taken, ctxt)
    2399              :   {}
    2400              : 
    2401              :   /* opt_pass methods: */
    2402              : 
    2403              : }; // class pass_update_address_taken
    2404              : 
    2405              : } // anon namespace
    2406              : 
    2407              : gimple_opt_pass *
    2408            0 : make_pass_update_address_taken (gcc::context *ctxt)
    2409              : {
    2410            0 :   return new pass_update_address_taken (ctxt);
    2411              : }
        

Generated by: LCOV version 2.5.0-beta

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