LCOV - code coverage report
Current view: top level - gcc - tree-ssa.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 86.4 % 1116 964
Test Date: 2026-05-11 19:44:49 Functions: 97.1 % 35 34
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     11651823 : redirect_edge_var_map_add (edge e, tree result, tree def, location_t locus)
      56              : {
      57     11651823 :   edge_var_map new_node;
      58              : 
      59     11651823 :   if (edge_var_maps == NULL)
      60        68527 :     edge_var_maps = new hash_map<edge, auto_vec<edge_var_map> >;
      61              : 
      62     11651823 :   auto_vec<edge_var_map> &slot = edge_var_maps->get_or_insert (e);
      63     11651823 :   new_node.def = def;
      64     11651823 :   new_node.result = result;
      65     11651823 :   new_node.locus = locus;
      66              : 
      67     11651823 :   slot.safe_push (new_node);
      68     11651823 : }
      69              : 
      70              : 
      71              : /* Clear the var mappings in edge E.  */
      72              : 
      73              : void
      74    138986956 : redirect_edge_var_map_clear (edge e)
      75              : {
      76    138986956 :   if (!edge_var_maps)
      77              :     return;
      78              : 
      79    123492301 :   auto_vec<edge_var_map> *head = edge_var_maps->get (e);
      80              : 
      81    123492301 :   if (head)
      82     10421848 :     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       422529 : redirect_edge_var_map_dup (edge newe, edge olde)
      94              : {
      95       422529 :   if (!edge_var_maps)
      96              :     return;
      97              : 
      98       392806 :   auto_vec<edge_var_map> *new_head = &edge_var_maps->get_or_insert (newe);
      99       392806 :   auto_vec<edge_var_map> *old_head = edge_var_maps->get (olde);
     100       392806 :   if (!old_head)
     101              :     return;
     102              : 
     103         7702 :   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      8094723 : redirect_edge_var_map_vector (edge e)
     112              : {
     113              :   /* Hey, what kind of idiot would... you'd be surprised.  */
     114      8094723 :   if (!edge_var_maps)
     115              :     return NULL;
     116              : 
     117      8068113 :   auto_vec<edge_var_map> *slot = edge_var_maps->get (e);
     118      8068113 :   if (!slot)
     119              :     return NULL;
     120              : 
     121              :   return slot;
     122              : }
     123              : 
     124              : /* Clear the edge variable mappings.  */
     125              : 
     126              : void
     127    899414738 : redirect_edge_var_map_empty (void)
     128              : {
     129    899414738 :   if (edge_var_maps)
     130    244927121 :     edge_var_maps->empty ();
     131    899414738 : }
     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     63051830 : ssa_redirect_edge (edge e, basic_block dest)
     141              : {
     142     63051830 :   gphi_iterator gsi;
     143     63051830 :   gphi *phi;
     144              : 
     145     63051830 :   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     63051830 :   if (! (e->dest->flags & BB_DUPLICATED))
     151     73477561 :     for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
     152              :       {
     153     12293905 :         tree def;
     154     12293905 :         location_t locus;
     155              : 
     156     12293905 :         phi = gsi.phi ();
     157     12293905 :         def = gimple_phi_arg_def (phi, e->dest_idx);
     158     12293905 :         locus = gimple_phi_arg_location (phi, e->dest_idx);
     159              : 
     160     12293905 :         if (def == NULL_TREE)
     161      1539441 :           continue;
     162              : 
     163     10754464 :         redirect_edge_var_map_add (e, gimple_phi_result (phi), def, locus);
     164              :       }
     165              : 
     166     63051830 :   e = redirect_edge_succ_nodup (e, dest);
     167              : 
     168     63051830 :   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      3305006 : flush_pending_stmts (edge e)
     177              : {
     178      3305006 :   gphi *phi;
     179      3305006 :   edge_var_map *vm;
     180      3305006 :   int i;
     181      3305006 :   gphi_iterator gsi;
     182              : 
     183      3305006 :   vec<edge_var_map> *v = redirect_edge_var_map_vector (e);
     184      3305006 :   if (!v)
     185       343468 :     return;
     186              : 
     187      2961538 :   for (gsi = gsi_start_phis (e->dest), i = 0;
     188      8084675 :        !gsi_end_p (gsi) && v->iterate (i, &vm);
     189      5123137 :        gsi_next (&gsi), i++)
     190              :     {
     191      5123137 :       tree def;
     192              : 
     193      5123137 :       phi = gsi.phi ();
     194      5123137 :       def = redirect_edge_var_map_def (vm);
     195      5123137 :       add_phi_arg (phi, def, e, redirect_edge_var_map_location (vm));
     196              :     }
     197              : 
     198      2961538 :   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    345085451 : target_for_debug_bind (tree var)
     244              : {
     245    345087484 :   if (!MAY_HAVE_DEBUG_BIND_STMTS)
     246              :     return NULL_TREE;
     247              : 
     248    323737208 :   if (TREE_CODE (var) == SSA_NAME)
     249              :     {
     250     15988948 :       var = SSA_NAME_VAR (var);
     251              :       if (var == NULL_TREE)
     252              :         return NULL_TREE;
     253              :     }
     254              : 
     255    272183706 :   if ((!VAR_P (var) || VAR_DECL_IS_VIRTUAL_OPERAND (var))
     256    331668410 :       && TREE_CODE (var) != PARM_DECL)
     257              :     return NULL_TREE;
     258              : 
     259    271296847 :   if (DECL_HAS_VALUE_EXPR_P (var))
     260         2033 :     return target_for_debug_bind (DECL_VALUE_EXPR (var));
     261              : 
     262    271294814 :   if (DECL_IGNORED_P (var))
     263              :     return NULL_TREE;
     264              : 
     265              :   /* var-tracking only tracks registers.  */
     266    249426078 :   if (!is_gimple_reg_type (TREE_TYPE (var)))
     267      8800342 :     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     10921073 : find_released_ssa_name (tree *tp, int *walk_subtrees, void *data_)
     277              : {
     278     10921073 :   struct walk_stmt_info *wi = (struct walk_stmt_info *) data_;
     279              : 
     280     10921073 :   if (wi && wi->is_lhs)
     281              :     return NULL_TREE;
     282              : 
     283     10887810 :   if (TREE_CODE (*tp) == SSA_NAME)
     284              :     {
     285      1774389 :       if (SSA_NAME_IN_FREE_LIST (*tp))
     286              :         return *tp;
     287              : 
     288      1760570 :       *walk_subtrees = 0;
     289              :     }
     290      9113421 :   else if (IS_TYPE_OR_DECL_P (*tp))
     291        36200 :     *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     87800916 : insert_debug_temp_for_var_def (gimple_stmt_iterator *gsi, tree var)
     302              : {
     303     87800916 :   imm_use_iterator imm_iter;
     304     87800916 :   use_operand_p use_p;
     305     87800916 :   gimple *stmt;
     306     87800916 :   gimple *def_stmt = NULL;
     307     87800916 :   int usecount = 0;
     308     87800916 :   tree value = NULL;
     309              : 
     310     87800916 :   if (!MAY_HAVE_DEBUG_BIND_STMTS)
     311     84455547 :     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     87800916 :   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    184719385 :   FOR_EACH_IMM_USE_FAST (use_p, imm_iter, var)
     321              :     {
     322     11210971 :       stmt = USE_STMT (use_p);
     323              : 
     324     11210971 :       if (!gimple_debug_bind_p (stmt))
     325      7391045 :         continue;
     326              : 
     327      3819926 :       if (usecount++)
     328              :         break;
     329              : 
     330      3345369 :       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              :           usecount++;
     336              :           break;
     337              :         }
     338     87329234 :     }
     339              : 
     340     87329234 :   if (!usecount)
     341              :     return;
     342              : 
     343      3345369 :   if (gsi)
     344      2933887 :     def_stmt = gsi_stmt (*gsi);
     345              :   else
     346       411482 :     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      3345369 :   if (gimple_code (def_stmt) == GIMPLE_PHI)
     352              :     {
     353       156489 :       value = degenerate_phi_result (as_a <gphi *> (def_stmt));
     354       156489 :       if (value && walk_tree (&value, find_released_ssa_name, NULL, NULL))
     355          123 :         value = NULL;
     356              :       /* error_mark_node is what fixup_noreturn_call changes PHI arguments
     357              :          to.  */
     358       156366 :       else if (value == error_mark_node)
     359            0 :         value = NULL;
     360              :     }
     361      3188880 :   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      1247642 :     value = NULL;
     366      1941238 :   else if (is_gimple_assign (def_stmt))
     367              :     {
     368      1876570 :       bool no_value = false;
     369              : 
     370      1876570 :       if (!dom_info_available_p (CDI_DOMINATORS))
     371              :         {
     372        46959 :           struct walk_stmt_info wi;
     373              : 
     374        46959 :           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        46932 :           if ((!gsi && !gimple_bb (def_stmt))
     403        93891 :               || walk_gimple_op (def_stmt, find_released_ssa_name, &wi))
     404        13696 :             no_value = true;
     405              :         }
     406              : 
     407        46959 :       if (!no_value)
     408      1862874 :         value = gimple_assign_rhs_to_tree (def_stmt);
     409              :     }
     410              : 
     411      3345369 :   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      1889900 :       if (usecount == 1
     427      1045064 :           || gimple_code (def_stmt) == GIMPLE_PHI
     428      1036325 :           || CONSTANT_CLASS_P (value)
     429      2924994 :           || is_gimple_reg (value))
     430              :         ;
     431              :       else
     432              :         {
     433      1033524 :           gdebug *def_temp;
     434      1033524 :           tree vexpr = build_debug_expr_decl (TREE_TYPE (value));
     435              : 
     436      1033524 :           def_temp = gimple_build_debug_bind (vexpr,
     437              :                                               unshare_expr (value),
     438              :                                               def_stmt);
     439              : 
     440              :           /* FIXME: Is setting the mode really necessary? */
     441      1033524 :           if (DECL_P (value))
     442         2821 :             SET_DECL_MODE (vexpr, DECL_MODE (value));
     443              :           else
     444      1030703 :             SET_DECL_MODE (vexpr, TYPE_MODE (TREE_TYPE (value)));
     445              : 
     446      1033524 :           if (gsi)
     447       816923 :             gsi_insert_before (gsi, def_temp, GSI_SAME_STMT);
     448              :           else
     449              :             {
     450       216601 :               gimple_stmt_iterator ngsi = gsi_for_stmt (def_stmt);
     451       216601 :               gsi_insert_before (&ngsi, def_temp, GSI_SAME_STMT);
     452              :             }
     453              : 
     454      1033524 :           value = vexpr;
     455              :         }
     456              :     }
     457              : 
     458     12959542 :   FOR_EACH_IMM_USE_STMT (stmt, imm_iter, var)
     459              :     {
     460      6268804 :       if (!gimple_debug_bind_p (stmt))
     461       872129 :         continue;
     462              : 
     463      5396675 :       if (value)
     464              :         {
     465     11371355 :           FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
     466      3790648 :             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      3790059 :           if (TREE_CODE (value) != DEBUG_EXPR_DECL)
     470              :             {
     471       876728 :               gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
     472       876728 :               fold_stmt_inplace (&gsi);
     473              :             }
     474              :         }
     475              :       else
     476      1606616 :         gimple_debug_bind_reset_value (stmt);
     477              : 
     478      5396675 :       update_stmt (stmt);
     479      3345369 :     }
     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    161580682 : insert_debug_temps_for_defs (gimple_stmt_iterator *gsi)
     489              : {
     490    161580682 :   gimple *stmt;
     491    161580682 :   ssa_op_iter op_iter;
     492    161580682 :   def_operand_p def_p;
     493              : 
     494    161580682 :   if (!MAY_HAVE_DEBUG_BIND_STMTS)
     495     44737978 :     return;
     496              : 
     497    116842704 :   stmt = gsi_stmt (*gsi);
     498              : 
     499    268104908 :   FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, op_iter, SSA_OP_DEF)
     500              :     {
     501     34419500 :       tree var = DEF_FROM_PTR (def_p);
     502              : 
     503     34419500 :       if (TREE_CODE (var) != SSA_NAME)
     504       149609 :         continue;
     505              : 
     506     34269891 :       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         7328 : reset_debug_uses (gimple *stmt)
     514              : {
     515         7328 :   ssa_op_iter op_iter;
     516         7328 :   def_operand_p def_p;
     517         7328 :   imm_use_iterator imm_iter;
     518         7328 :   gimple *use_stmt;
     519              : 
     520         7328 :   if (!MAY_HAVE_DEBUG_BIND_STMTS)
     521          177 :     return;
     522              : 
     523        19080 :   FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, op_iter, SSA_OP_DEF)
     524              :     {
     525         4778 :       tree var = DEF_FROM_PTR (def_p);
     526              : 
     527         4778 :       if (TREE_CODE (var) != SSA_NAME)
     528            0 :         continue;
     529              : 
     530        14919 :       FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, var)
     531              :         {
     532         5363 :           if (!gimple_debug_bind_p (use_stmt))
     533         5281 :             continue;
     534              : 
     535           82 :           gimple_debug_bind_reset_value (use_stmt);
     536           82 :           update_stmt (use_stmt);
     537         4778 :         }
     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       239985 : release_defs_bitset (bitmap toremove)
     547              : {
     548       239985 :   unsigned j;
     549       239985 :   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       239985 :   auto_vec<tree, 16> names;
     559       239985 :   names.reserve (bitmap_count_bits (toremove) + 1);
     560       239985 :   names.quick_push (NULL_TREE);
     561      2703972 :   EXECUTE_IF_SET_IN_BITMAP (toremove, 0, j, bi)
     562      2463987 :     names.quick_push (ssa_name (j));
     563              : 
     564       239985 :   bitmap_tree_view (toremove);
     565       742506 :   while (!bitmap_empty_p (toremove))
     566              :     {
     567       262536 :       j = names.length () - 1;
     568      3518218 :       for (unsigned i = names.length () - 1; names[i];)
     569              :         {
     570      3255682 :           bool remove_now = true;
     571      3255682 :           tree var = names[i];
     572      3255682 :           gimple *stmt;
     573      3255682 :           imm_use_iterator uit;
     574              : 
     575      7191862 :           FOR_EACH_IMM_USE_STMT (stmt, uit, var)
     576              :             {
     577      1472193 :               ssa_op_iter dit;
     578      1472193 :               def_operand_p def_p;
     579              : 
     580              :               /* We can't propagate PHI nodes into debug stmts.  */
     581      1472193 :               if (gimple_code (stmt) == GIMPLE_PHI
     582      1472193 :                   || is_gimple_debug (stmt))
     583       680498 :                 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       791695 :               FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, dit, SSA_OP_DEF)
     590              :                 {
     591       791695 :                   tree odef = DEF_FROM_PTR (def_p);
     592              : 
     593       791695 :                   if (bitmap_bit_p (toremove, SSA_NAME_VERSION (odef)))
     594              :                     {
     595              :                       remove_now = false;
     596              :                       break;
     597              :                     }
     598              :                 }
     599              : 
     600       791695 :               if (!remove_now)
     601              :                 break;
     602      3255682 :             }
     603              : 
     604      3255682 :           if (remove_now)
     605              :             {
     606      2463987 :               gimple *def = SSA_NAME_DEF_STMT (var);
     607      2463987 :               gimple_stmt_iterator gsi = gsi_for_stmt (def);
     608              : 
     609      2463987 :               if (gimple_code (def) == GIMPLE_PHI)
     610       627791 :                 remove_phi_node (&gsi, true);
     611              :               else
     612              :                 {
     613      1836196 :                   gsi_remove (&gsi, true);
     614      1836196 :                   release_defs (def);
     615              :                 }
     616      2463987 :               bitmap_clear_bit (toremove, SSA_NAME_VERSION (var));
     617              :             }
     618              :           else
     619       791695 :             --i;
     620      3255682 :           if (--j != i)
     621      3070238 :             names[i] = names[j];
     622              :         }
     623              :     }
     624       239985 :   bitmap_list_view (toremove);
     625       239985 : }
     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    220496585 : verify_vssa (basic_block bb_start, tree current_vdef, sbitmap visited)
     640              : {
     641    220496585 :   bool err = false;
     642              : 
     643    220496585 :   struct state_t {
     644              :     basic_block bb;
     645              :     tree        vdef;
     646              :   } state;
     647              : 
     648    220496585 :   auto_vec<state_t, 3> worklist;
     649    220496585 :   state.bb = bb_start;
     650    220496585 :   state.vdef = current_vdef;
     651    220496585 :   worklist.safe_push (state);
     652              : 
     653   2782508983 :   while (!worklist.is_empty ())
     654              :     {
     655   2341515813 :       const auto &state = worklist.pop ();
     656   2341515813 :       const auto &bb = state.bb;
     657   2341515813 :       current_vdef = state.vdef;
     658              : 
     659   2341515813 :       if (!bitmap_set_bit (visited, bb->index))
     660    113564904 :         continue;
     661              : 
     662              :       /* Pick up the single virtual PHI def.  */
     663   2227950909 :       gphi *phi = NULL;
     664   2870834827 :       for (gphi_iterator si = gsi_start_phis (bb); !gsi_end_p (si);
     665    642883918 :            gsi_next (&si))
     666              :         {
     667    642883918 :           tree res = gimple_phi_result (si.phi ());
     668   1587527961 :           if (virtual_operand_p (res))
     669              :             {
     670    301760125 :               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   2227950909 :       if (phi)
     682              :         {
     683    301760125 :           current_vdef = gimple_phi_result (phi);
     684    301760125 :           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  16485395361 :       for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
     694  12029493543 :            gsi_next (&gsi))
     695              :         {
     696  12029493543 :           gimple *stmt = gsi_stmt (gsi);
     697  17184966442 :           tree vuse = gimple_vuse (stmt);
     698   5095376185 :           if (vuse)
     699              :             {
     700   3407107359 :               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  15436600902 :               tree vdef = gimple_vdef (stmt);
     710   3407107359 :               if (vdef)
     711              :                 {
     712   2124443804 :                   current_vdef = vdef;
     713   2124443804 :                   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   2227950909 :       edge_iterator ei;
     725   2227950909 :       edge e;
     726   4927058868 :       FOR_EACH_EDGE (e, ei, bb->succs)
     727              :         {
     728   2699107959 :           gphi *phi = get_virtual_phi (e->dest);
     729   2699107959 :           if (phi
     730   2699107959 :              && 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   2699107959 :           if (!bitmap_bit_p (visited, e->dest->index))
     743              :             {
     744   2121019228 :               state_t new_state;
     745   2121019228 :               new_state.bb = e->dest;
     746   2121019228 :               new_state.vdef = current_vdef;
     747              : 
     748   2121019228 :               worklist.safe_push (new_state);
     749              :             }
     750              :         }
     751              :     }
     752    220496585 :   return err;
     753    220496585 : }
     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  13418937802 : verify_ssa_name (tree ssa_name, bool is_virtual)
     762              : {
     763  13418937802 :   if (TREE_CODE (ssa_name) != SSA_NAME)
     764              :     {
     765            0 :       error ("expected an SSA_NAME object");
     766            0 :       return true;
     767              :     }
     768              : 
     769  13418937802 :   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  13418937802 :   if (SSA_NAME_VAR (ssa_name) != NULL_TREE
     776   8005359956 :       && 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  13418937802 :   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  13418937802 :   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  13418937802 :   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  13418937802 :   if (SSA_NAME_IS_DEFAULT_DEF (ssa_name)
     801  13418937802 :       && !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   5704534734 : verify_def (basic_block bb, basic_block *definition_block, tree ssa_name,
     824              :             gimple *stmt, bool is_virtual)
     825              : {
     826   5704534734 :   if (verify_ssa_name (ssa_name, is_virtual))
     827            0 :     goto err;
     828              : 
     829   5704534734 :   if (SSA_NAME_VAR (ssa_name)
     830   3123397547 :       && 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   5704534734 :   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   5704534734 :   definition_block[SSA_NAME_VERSION (ssa_name)] = bb;
     845              : 
     846   5704534734 :   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  10892999475 : 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  10892999475 :   bool err = false;
     887  10892999475 :   tree ssa_name = USE_FROM_PTR (use_p);
     888              : 
     889  10892999475 :   if (!TREE_VISITED (ssa_name))
     890   6083085554 :     if (verify_imm_links (stderr, ssa_name))
     891  10892999475 :       err = true;
     892              : 
     893  10892999475 :   TREE_VISITED (ssa_name) = 1;
     894              : 
     895  10892999475 :   if (gimple_nop_p (SSA_NAME_DEF_STMT (ssa_name))
     896  10892999475 :       && SSA_NAME_IS_DEFAULT_DEF (ssa_name))
     897              :     ; /* Default definitions have empty statements.  Nothing to do.  */
     898   9354731899 :   else if (!def_bb)
     899              :     {
     900            0 :       error ("missing definition");
     901            0 :       err = true;
     902              :     }
     903   9354731899 :   else if (bb != def_bb
     904   9354731899 :            && !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   9354731899 :   else if (bb == def_bb
     911   9354731899 :            && names_defined_in_bb != NULL
     912  14944764243 :            && !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  10892999475 :   if (check_abnormal
     919  10900714732 :       && !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  10892999475 :   if (use_p->prev == NULL)
     928              :     {
     929            0 :       error ("no immediate_use list");
     930            0 :       err = true;
     931              :     }
     932              :   else
     933              :     {
     934  10892999475 :       tree listvar;
     935  10892999475 :       if (use_p->prev->use == NULL)
     936   6083085554 :         listvar = use_p->prev->loc.ssa_name;
     937              :       else
     938   4809913921 :         listvar = USE_FROM_PTR (use_p->prev);
     939  10892999475 :       if (listvar != ssa_name)
     940              :         {
     941            0 :           error ("wrong immediate use list");
     942            0 :           err = true;
     943              :         }
     944              :     }
     945              : 
     946  10892999475 :   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  10892999475 :   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    642895023 : verify_phi_args (gphi *phi, basic_block bb, basic_block *definition_block)
     968              : {
     969    642895023 :   edge e;
     970    642895023 :   bool err = false;
     971    642895023 :   size_t i, phi_num_args = gimple_phi_num_args (phi);
     972              : 
     973   1285790046 :   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   2272030734 :   for (i = 0; i < phi_num_args; i++)
     981              :     {
     982   1629135711 :       use_operand_p op_p = gimple_phi_arg_imm_use_ptr (phi, i);
     983   1629135711 :       tree op = USE_FROM_PTR (op_p);
     984              : 
     985   1629135711 :       e = EDGE_PRED (bb, i);
     986              : 
     987   1629135711 :       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   1629135711 :       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   1629135711 :       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   1629135711 :       if (TREE_CODE (op) == SSA_NAME)
    1009              :         {
    1010   2814325796 :           err = verify_ssa_name (op, virtual_operand_p (gimple_phi_result (phi)));
    1011   1407162898 :           err |= verify_use (e->src, definition_block[SSA_NAME_VERSION (op)],
    1012   1407162898 :                              op_p, phi, e->flags & EDGE_ABNORMAL, NULL);
    1013              :         }
    1014              : 
    1015   1629135711 :       if (TREE_CODE (op) == ADDR_EXPR)
    1016              :         {
    1017     11016561 :           tree base = TREE_OPERAND (op, 0);
    1018     14990806 :           while (handled_component_p (base))
    1019      3974245 :             base = TREE_OPERAND (base, 0);
    1020     11016561 :           if ((VAR_P (base)
    1021              :                || TREE_CODE (base) == PARM_DECL
    1022              :                || TREE_CODE (base) == RESULT_DECL)
    1023      5413837 :               && !TREE_ADDRESSABLE (base))
    1024              :             {
    1025            0 :               error ("address taken, but ADDRESSABLE bit not set");
    1026            0 :               err = true;
    1027              :             }
    1028              :         }
    1029              : 
    1030   1629135711 :       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   1629135711 :       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    642895023 : error:
    1046    642895023 :   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    642895023 :   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    220602752 : verify_ssa (bool check_modified_stmt, bool check_ssa_operands)
    1062              : {
    1063    220602752 :   basic_block bb;
    1064    441205504 :   basic_block *definition_block = XCNEWVEC (basic_block, num_ssa_names);
    1065    220602752 :   ssa_op_iter iter;
    1066    220602752 :   tree op;
    1067    220602752 :   enum dom_state orig_dom_state = dom_info_state (CDI_DOMINATORS);
    1068    220602752 :   auto_bitmap names_defined_in_bb;
    1069              : 
    1070    220602752 :   gcc_assert (!need_ssa_update_p (cfun));
    1071              : 
    1072    220602752 :   timevar_push (TV_TREE_SSA_VERIFY);
    1073              : 
    1074    220602752 :     {
    1075              :       /* Keep track of SSA names present in the IL.  */
    1076    220602752 :       size_t i;
    1077    220602752 :       tree name;
    1078    220602752 :       hash_map <void *, tree> ssa_info;
    1079              : 
    1080   8369662790 :       FOR_EACH_SSA_NAME (i, name, cfun)
    1081              :         {
    1082   6307240170 :           gimple *stmt;
    1083   6307240170 :           TREE_VISITED (name) = 0;
    1084              : 
    1085  12614480340 :           verify_ssa_name (name, virtual_operand_p (name));
    1086              : 
    1087   6307240170 :           stmt = SSA_NAME_DEF_STMT (name);
    1088   6307240170 :           if (!gimple_nop_p (stmt))
    1089              :             {
    1090   5704534734 :               basic_block bb = gimple_bb (stmt);
    1091   5704534734 :               if (verify_def (bb, definition_block,
    1092   5704534734 :                               name, stmt, virtual_operand_p (name)))
    1093            0 :                 goto err;
    1094              :             }
    1095              : 
    1096   6307240170 :           void *info = NULL;
    1097   6307240170 :           if (POINTER_TYPE_P (TREE_TYPE (name)))
    1098   1120795392 :             info = SSA_NAME_PTR_INFO (name);
    1099   5186444778 :           else if (INTEGRAL_TYPE_P (TREE_TYPE (name)))
    1100   2181862357 :             info = SSA_NAME_RANGE_INFO (name);
    1101   6307240170 :           if (info)
    1102              :             {
    1103   1315819944 :               bool existed;
    1104   1315819944 :               tree &val = ssa_info.get_or_insert (info, &existed);
    1105   1315819944 :               if (existed)
    1106              :                 {
    1107            0 :                   error ("shared SSA name info");
    1108            0 :                   print_generic_expr (stderr, val);
    1109            0 :                   fprintf (stderr, " and ");
    1110            0 :                   print_generic_expr (stderr, name);
    1111            0 :                   fprintf (stderr, "\n");
    1112            0 :                   goto err;
    1113              :                 }
    1114              :               else
    1115   1315819944 :                 val = name;
    1116              :             }
    1117              :         }
    1118            0 :     }
    1119              : 
    1120    220602752 :   calculate_dominance_info (CDI_DOMINATORS);
    1121              : 
    1122              :   /* Now verify all the uses and make sure they agree with the definitions
    1123              :      found in the previous pass.  */
    1124   2011935661 :   FOR_EACH_BB_FN (bb, cfun)
    1125              :     {
    1126   1791332909 :       edge e;
    1127   1791332909 :       edge_iterator ei;
    1128              : 
    1129              :       /* Make sure that all edges have a clear 'aux' field.  */
    1130   4274172842 :       FOR_EACH_EDGE (e, ei, bb->preds)
    1131              :         {
    1132   2482839933 :           if (e->aux)
    1133              :             {
    1134            0 :               error ("AUX pointer initialized for edge %d->%d", e->src->index,
    1135            0 :                       e->dest->index);
    1136            0 :               goto err;
    1137              :             }
    1138              :         }
    1139              : 
    1140              :       /* Verify the arguments for every PHI node in the block.  */
    1141   2434227932 :       for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    1142              :         {
    1143    642895023 :           gphi *phi = gsi.phi ();
    1144    642895023 :           if (verify_phi_args (phi, bb, definition_block))
    1145            0 :             goto err;
    1146              : 
    1147    642895023 :           bitmap_set_bit (names_defined_in_bb,
    1148    642895023 :                           SSA_NAME_VERSION (gimple_phi_result (phi)));
    1149              :         }
    1150              : 
    1151              :       /* Now verify all the uses and vuses in every statement of the block.  */
    1152  15612312277 :       for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
    1153  12029646459 :            gsi_next (&gsi))
    1154              :         {
    1155  12029646459 :           gimple *stmt = gsi_stmt (gsi);
    1156  12029646459 :           use_operand_p use_p;
    1157              : 
    1158  23991313078 :           if (check_modified_stmt && gimple_modified_p (stmt))
    1159              :             {
    1160            0 :               error ("stmt (%p) marked modified after optimization pass: ",
    1161              :                      (void *)stmt);
    1162            0 :               print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
    1163            0 :               goto err;
    1164              :             }
    1165              : 
    1166  12029646459 :           if (check_ssa_operands && verify_ssa_operands (cfun, stmt))
    1167              :             {
    1168            0 :               print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
    1169            0 :               goto err;
    1170              :             }
    1171              : 
    1172  12029646459 :           if (gimple_debug_bind_p (stmt)
    1173   6070022837 :               && !gimple_debug_bind_has_value_p (stmt))
    1174   2017049665 :             continue;
    1175              : 
    1176  19498433371 :           FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE|SSA_OP_VUSE)
    1177              :             {
    1178   9485836577 :               op = USE_FROM_PTR (use_p);
    1179   9485836577 :               if (verify_use (bb, definition_block[SSA_NAME_VERSION (op)],
    1180              :                               use_p, stmt, false, names_defined_in_bb))
    1181            0 :                 goto err;
    1182              :             }
    1183              : 
    1184  15062627388 :           FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_ALL_DEFS)
    1185              :             {
    1186   5050030594 :               if (SSA_NAME_DEF_STMT (op) != stmt)
    1187              :                 {
    1188            0 :                   error ("SSA_NAME_DEF_STMT is wrong");
    1189            0 :                   fprintf (stderr, "Expected definition statement:\n");
    1190            0 :                   print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
    1191            0 :                   fprintf (stderr, "\nActual definition statement:\n");
    1192            0 :                   print_gimple_stmt (stderr, SSA_NAME_DEF_STMT (op),
    1193              :                                      4, TDF_VOPS);
    1194            0 :                   goto err;
    1195              :                 }
    1196   5050030594 :               bitmap_set_bit (names_defined_in_bb, SSA_NAME_VERSION (op));
    1197              :             }
    1198              :         }
    1199              : 
    1200   1791332909 :       bitmap_clear (names_defined_in_bb);
    1201              :     }
    1202              : 
    1203    220602752 :   free (definition_block);
    1204              : 
    1205    220602752 :   if (gimple_vop (cfun)
    1206    220602752 :       && ssa_default_def (cfun, gimple_vop (cfun)))
    1207              :     {
    1208    220496585 :       auto_sbitmap visited (last_basic_block_for_fn (cfun) + 1);
    1209    220496585 :       bitmap_clear (visited);
    1210    220496585 :       if (verify_vssa (ENTRY_BLOCK_PTR_FOR_FN (cfun),
    1211              :                        ssa_default_def (cfun, gimple_vop (cfun)), visited))
    1212            0 :         goto err;
    1213    220496585 :     }
    1214              : 
    1215              :   /* Restore the dominance information to its prior known state, so
    1216              :      that we do not perturb the compiler's subsequent behavior.  */
    1217    220602752 :   if (orig_dom_state == DOM_NONE)
    1218     71763764 :     free_dominance_info (CDI_DOMINATORS);
    1219              :   else
    1220    148838988 :     set_dom_info_availability (CDI_DOMINATORS, orig_dom_state);
    1221              : 
    1222    220602752 :   timevar_pop (TV_TREE_SSA_VERIFY);
    1223    220602752 :   return;
    1224              : 
    1225            0 : err:
    1226            0 :   internal_error ("verify_ssa failed");
    1227    220602752 : }
    1228              : 
    1229              : #if __GNUC__ >= 10
    1230              : #  pragma GCC diagnostic pop
    1231              : #endif
    1232              : 
    1233              : /* Initialize global DFA and SSA structures.
    1234              :    If SIZE is non-zero allocated ssa names array of a given size.  */
    1235              : 
    1236              : void
    1237      3265403 : init_tree_ssa (struct function *fn, int size)
    1238              : {
    1239      3265403 :   fn->gimple_df = ggc_cleared_alloc<gimple_df> ();
    1240      3265403 :   fn->gimple_df->default_defs = hash_table<ssa_name_hasher>::create_ggc (20);
    1241      3265403 :   pt_solution_reset (&fn->gimple_df->escaped);
    1242      3265403 :   pt_solution_reset (&fn->gimple_df->escaped_return);
    1243      3265403 :   init_ssanames (fn, size);
    1244      3265403 : }
    1245              : 
    1246              : /* Deallocate memory associated with SSA data structures for FNDECL.  */
    1247              : 
    1248              : void
    1249      3159827 : delete_tree_ssa (struct function *fn)
    1250              : {
    1251      3159827 :   fini_ssanames (fn);
    1252              : 
    1253              :   /* We no longer maintain the SSA operand cache at this point.  */
    1254      3159827 :   if (ssa_operands_active (fn))
    1255      3136683 :     fini_ssa_operands (fn);
    1256              : 
    1257      3159827 :   fn->gimple_df->default_defs->empty ();
    1258      3159827 :   fn->gimple_df->default_defs = NULL;
    1259      3159827 :   pt_solution_reset (&fn->gimple_df->escaped);
    1260      3159827 :   pt_solution_reset (&fn->gimple_df->escaped_return);
    1261      3159827 :   if (fn->gimple_df->decls_to_pointers != NULL)
    1262        39865 :     delete fn->gimple_df->decls_to_pointers;
    1263      3159827 :   fn->gimple_df->decls_to_pointers = NULL;
    1264      3159827 :   fn->gimple_df = NULL;
    1265              : 
    1266              :   /* We no longer need the edge variable maps.  */
    1267      3159827 :   redirect_edge_var_map_empty ();
    1268      3159827 : }
    1269              : 
    1270              : /* Return true if EXPR is a useless type conversion, otherwise return
    1271              :    false.  */
    1272              : 
    1273              : bool
    1274    960263766 : tree_ssa_useless_type_conversion (tree expr)
    1275              : {
    1276    960263766 :   tree outer_type, inner_type;
    1277              : 
    1278              :   /* If we have an assignment that merely uses a NOP_EXPR to change
    1279              :      the top of the RHS to the type of the LHS and the type conversion
    1280              :      is "safe", then strip away the type conversion so that we can
    1281              :      enter LHS = RHS into the const_and_copies table.  */
    1282    960263766 :   if (!CONVERT_EXPR_P (expr)
    1283    886859493 :       && TREE_CODE (expr) != VIEW_CONVERT_EXPR
    1284    885831072 :       && TREE_CODE (expr) != NON_LVALUE_EXPR)
    1285              :     return false;
    1286              : 
    1287     74978244 :   outer_type = TREE_TYPE (expr);
    1288     74978244 :   inner_type = TREE_TYPE (TREE_OPERAND (expr, 0));
    1289              : 
    1290     74978244 :   if (inner_type == error_mark_node)
    1291              :     return false;
    1292              : 
    1293     74978201 :   return useless_type_conversion_p (outer_type, inner_type);
    1294              : }
    1295              : 
    1296              : /* Strip conversions from EXP according to
    1297              :    tree_ssa_useless_type_conversion and return the resulting
    1298              :    expression.  */
    1299              : 
    1300              : tree
    1301    926140293 : tree_ssa_strip_useless_type_conversions (tree exp)
    1302              : {
    1303    947469432 :   while (tree_ssa_useless_type_conversion (exp))
    1304     21329139 :     exp = TREE_OPERAND (exp, 0);
    1305    926140293 :   return exp;
    1306              : }
    1307              : 
    1308              : /* Return true if T, as SSA_NAME, has an implicit default defined value.  */
    1309              : 
    1310              : bool
    1311    363472880 : ssa_defined_default_def_p (tree t)
    1312              : {
    1313    363472880 :   tree var = SSA_NAME_VAR (t);
    1314              : 
    1315    144263162 :   if (!var)
    1316              :     ;
    1317              :   /* Parameters get their initial value from the function entry.  */
    1318    144263162 :   else if (TREE_CODE (var) == PARM_DECL)
    1319              :     return true;
    1320              :   /* When returning by reference the return address is actually a hidden
    1321              :      parameter.  */
    1322    111898219 :   else if (TREE_CODE (var) == RESULT_DECL && DECL_BY_REFERENCE (var))
    1323              :     return true;
    1324              :   /* Hard register variables get their initial value from the ether.  */
    1325    111696999 :   else if (VAR_P (var) && DECL_HARD_REGISTER (var))
    1326            0 :     return true;
    1327              : 
    1328              :   return false;
    1329              : }
    1330              : 
    1331              : 
    1332              : /* Return true if T, an SSA_NAME, has an undefined value.  PARTIAL is what
    1333              :    should be returned if the value is only partially undefined.  */
    1334              : 
    1335              : bool
    1336    361153307 : ssa_undefined_value_p (tree t, bool partial)
    1337              : {
    1338    361153307 :   gimple *def_stmt;
    1339              : 
    1340    722306614 :   gcc_checking_assert (!virtual_operand_p (t));
    1341              : 
    1342    361153307 :   if (ssa_defined_default_def_p (t))
    1343              :     return false;
    1344              : 
    1345              :   /* The value is undefined iff its definition statement is empty.  */
    1346    330645193 :   def_stmt = SSA_NAME_DEF_STMT (t);
    1347    330645193 :   if (gimple_nop_p (def_stmt))
    1348              :     return true;
    1349              : 
    1350              :   /* The value is undefined if the definition statement is a call
    1351              :      to .DEFERRED_INIT function.  */
    1352    324236045 :   if (gimple_call_internal_p (def_stmt, IFN_DEFERRED_INIT))
    1353              :     return true;
    1354              : 
    1355              :   /* The value is partially undefined if the definition statement is
    1356              :      a REALPART_EXPR or IMAGPART_EXPR and its operand is defined by
    1357              :      the call to .DEFERRED_INIT function.  This is for handling the
    1358              :      following case:
    1359              : 
    1360              :   1 typedef _Complex float C;
    1361              :   2 C foo (int cond)
    1362              :   3 {
    1363              :   4   C f;
    1364              :   5   __imag__ f = 0;
    1365              :   6   if (cond)
    1366              :   7     {
    1367              :   8       __real__ f = 1;
    1368              :   9       return f;
    1369              :  10     }
    1370              :  11   return f;
    1371              :  12 }
    1372              : 
    1373              :     with -ftrivial-auto-var-init, compiler will insert the following
    1374              :     artificial initialization:
    1375              :   f = .DEFERRED_INIT (f, 2);
    1376              :   _1 = REALPART_EXPR <f>;
    1377              : 
    1378              :     we should treat the definition _1 = REALPART_EXPR <f> as undefined.  */
    1379     51455739 :   if (partial && is_gimple_assign (def_stmt)
    1380    363550048 :       && (gimple_assign_rhs_code (def_stmt) == REALPART_EXPR
    1381     39063214 :           || gimple_assign_rhs_code (def_stmt) == IMAGPART_EXPR))
    1382              :     {
    1383       604303 :       tree real_imag_part = TREE_OPERAND (gimple_assign_rhs1 (def_stmt), 0);
    1384       604303 :       if (TREE_CODE (real_imag_part) == SSA_NAME
    1385       604303 :          && gimple_call_internal_p (SSA_NAME_DEF_STMT (real_imag_part),
    1386              :                                     IFN_DEFERRED_INIT))
    1387              :         return true;
    1388              :     }
    1389              : 
    1390              :   /* Check if the complex was not only partially defined.  */
    1391     51455594 :   if (partial && is_gimple_assign (def_stmt)
    1392    363549758 :       && gimple_assign_rhs_code (def_stmt) == COMPLEX_EXPR)
    1393              :     {
    1394        17482 :       tree rhs1, rhs2;
    1395              : 
    1396        17482 :       rhs1 = gimple_assign_rhs1 (def_stmt);
    1397        17482 :       rhs2 = gimple_assign_rhs2 (def_stmt);
    1398        17146 :       return (TREE_CODE (rhs1) == SSA_NAME && ssa_undefined_value_p (rhs1))
    1399        34587 :              || (TREE_CODE (rhs2) == SSA_NAME && ssa_undefined_value_p (rhs2));
    1400              :     }
    1401              :   return false;
    1402              : }
    1403              : 
    1404              : 
    1405              : /* Return TRUE iff there are any non-PHI uses of VAR that dominate the
    1406              :    end of BB.  If we return TRUE and BB is a loop header, then VAR we
    1407              :    be assumed to be defined within the loop, even if it is marked as
    1408              :    maybe-undefined.  */
    1409              : 
    1410              : bool
    1411       320334 : ssa_name_any_use_dominates_bb_p (tree var, basic_block bb)
    1412              : {
    1413       320334 :   imm_use_iterator iter;
    1414       320334 :   use_operand_p use_p;
    1415      1297604 :   FOR_EACH_IMM_USE_FAST (use_p, iter, var)
    1416              :     {
    1417       679718 :       if (is_a <gphi *> (USE_STMT (use_p))
    1418       679718 :           || is_gimple_debug (USE_STMT (use_p)))
    1419       616046 :         continue;
    1420        63672 :       basic_block dombb = gimple_bb (USE_STMT (use_p));
    1421        63672 :       if (dominated_by_p (CDI_DOMINATORS, bb, dombb))
    1422        22782 :         return true;
    1423        22782 :     }
    1424              : 
    1425       297552 :   return false;
    1426              : }
    1427              : 
    1428              : /* Mark as maybe_undef any SSA_NAMEs that are unsuitable as ivopts
    1429              :    candidates for potentially involving undefined behavior.  */
    1430              : 
    1431              : void
    1432     11806829 : mark_ssa_maybe_undefs (void)
    1433              : {
    1434     11806829 :   auto_vec<tree> queue;
    1435              : 
    1436              :   /* Scan all SSA_NAMEs, marking the definitely-undefined ones as
    1437              :      maybe-undefined and queuing them for propagation, while clearing
    1438              :      the mark on others.  */
    1439     11806829 :   unsigned int i;
    1440     11806829 :   tree var;
    1441    555610803 :   FOR_EACH_SSA_NAME (i, var, cfun)
    1442              :     {
    1443    365222233 :       if (SSA_NAME_IS_VIRTUAL_OPERAND (var)
    1444    365222233 :           || !ssa_undefined_value_p (var, false))
    1445    360850410 :         ssa_name_set_maybe_undef (var, false);
    1446              :       else
    1447              :         {
    1448      4371823 :           ssa_name_set_maybe_undef (var);
    1449      4371823 :           queue.safe_push (var);
    1450      4371823 :           if (dump_file && (dump_flags & TDF_DETAILS))
    1451           42 :             fprintf (dump_file, "marking _%i as maybe-undef\n",
    1452           21 :                      SSA_NAME_VERSION (var));
    1453              :         }
    1454              :     }
    1455              : 
    1456              :   /* Now propagate maybe-undefined from a DEF to any other PHI that
    1457              :      uses it, as long as there isn't any intervening use of DEF.  */
    1458     17501075 :   while (!queue.is_empty ())
    1459              :     {
    1460      4666269 :       var = queue.pop ();
    1461      4666269 :       imm_use_iterator iter;
    1462      4666269 :       use_operand_p use_p;
    1463     10727623 :       FOR_EACH_IMM_USE_FAST (use_p, iter, var)
    1464              :         {
    1465              :           /* Any uses of VAR that aren't PHI args imply VAR must be
    1466              :              defined, otherwise undefined behavior would have been
    1467              :              definitely invoked.  Only PHI args may hold
    1468              :              maybe-undefined values without invoking undefined
    1469              :              behavior for that reason alone.  */
    1470      1395085 :           if (!is_a <gphi *> (USE_STMT (use_p)))
    1471      1100639 :             continue;
    1472       500208 :           gphi *phi = as_a <gphi *> (USE_STMT (use_p));
    1473              : 
    1474       500208 :           tree def = gimple_phi_result (phi);
    1475       500208 :           if (ssa_name_maybe_undef_p (def))
    1476       188565 :             continue;
    1477              : 
    1478              :           /* Look for any uses of the maybe-unused SSA_NAME that
    1479              :              dominates the block that reaches the incoming block
    1480              :              corresponding to the PHI arg in which it is mentioned.
    1481              :              That means we can assume the SSA_NAME is defined in that
    1482              :              path, so we only mark a PHI result as maybe-undef if we
    1483              :              find an unused reaching SSA_NAME.  */
    1484       311643 :           int idx = phi_arg_index_from_use (use_p);
    1485       311643 :           basic_block bb = gimple_phi_arg_edge (phi, idx)->src;
    1486       311643 :           if (ssa_name_any_use_dominates_bb_p (var, bb))
    1487        17197 :             continue;
    1488              : 
    1489       294446 :           ssa_name_set_maybe_undef (def);
    1490       294446 :           queue.safe_push (def);
    1491       294446 :           if (dump_file && (dump_flags & TDF_DETAILS))
    1492            0 :             fprintf (dump_file, "marking _%i as maybe-undef because of _%i\n",
    1493            0 :                      SSA_NAME_VERSION (def), SSA_NAME_VERSION (var));
    1494      4666269 :         }
    1495              :     }
    1496     11806829 : }
    1497              : 
    1498              : 
    1499              : /* If necessary, rewrite the base of the reference tree *TP from
    1500              :    a MEM_REF to a plain or converted symbol.  */
    1501              : 
    1502              : static void
    1503     30223302 : maybe_rewrite_mem_ref_base (tree *tp, bitmap suitable_for_renaming)
    1504              : {
    1505     30223302 :   tree sym;
    1506              : 
    1507     34136612 :   while (handled_component_p (*tp))
    1508      3913310 :     tp = &TREE_OPERAND (*tp, 0);
    1509     30223302 :   if (TREE_CODE (*tp) == MEM_REF
    1510      2073469 :       && TREE_CODE (TREE_OPERAND (*tp, 0)) == ADDR_EXPR
    1511       392413 :       && (sym = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0))
    1512       392413 :       && DECL_P (sym)
    1513       391983 :       && !TREE_ADDRESSABLE (sym)
    1514       182717 :       && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym))
    1515        55590 :       && is_gimple_reg_type (TREE_TYPE (*tp))
    1516     30278882 :       && ! VOID_TYPE_P (TREE_TYPE (*tp)))
    1517              :     {
    1518        55580 :       if (VECTOR_TYPE_P (TREE_TYPE (sym))
    1519         1084 :           && useless_type_conversion_p (TREE_TYPE (*tp),
    1520         1084 :                                         TREE_TYPE (TREE_TYPE (sym)))
    1521        55830 :           && multiple_p (mem_ref_offset (*tp),
    1522          250 :                          wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (*tp)))))
    1523              :         {
    1524          498 :           *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym,
    1525          249 :                         TYPE_SIZE (TREE_TYPE (*tp)),
    1526              :                         int_const_binop (MULT_EXPR,
    1527          498 :                                          bitsize_int (BITS_PER_UNIT),
    1528          249 :                                          TREE_OPERAND (*tp, 1)));
    1529              :         }
    1530        55331 :       else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
    1531         1055 :                && useless_type_conversion_p (TREE_TYPE (*tp),
    1532         1055 :                                              TREE_TYPE (TREE_TYPE (sym)))
    1533        55336 :                && (integer_zerop (TREE_OPERAND (*tp, 1))
    1534            3 :                    || tree_int_cst_equal (TREE_OPERAND (*tp, 1),
    1535            3 :                                           TYPE_SIZE_UNIT (TREE_TYPE (*tp)))))
    1536              :         {
    1537            6 :           *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
    1538              :                         ? REALPART_EXPR : IMAGPART_EXPR,
    1539            4 :                         TREE_TYPE (*tp), sym);
    1540              :         }
    1541        55327 :       else if (integer_zerop (TREE_OPERAND (*tp, 1))
    1542        55327 :                && DECL_SIZE (sym) == TYPE_SIZE (TREE_TYPE (*tp)))
    1543              :         {
    1544        54967 :           if (!useless_type_conversion_p (TREE_TYPE (*tp),
    1545        54967 :                                           TREE_TYPE (sym)))
    1546        12227 :             *tp = build1 (VIEW_CONVERT_EXPR,
    1547        12227 :                           TREE_TYPE (*tp), sym);
    1548              :           else
    1549        42740 :             *tp = sym;
    1550              :         }
    1551          360 :       else if (DECL_SIZE (sym)
    1552          360 :                && TREE_CODE (DECL_SIZE (sym)) == INTEGER_CST
    1553          360 :                && (known_subrange_p
    1554          360 :                    (mem_ref_offset (*tp),
    1555          360 :                     wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (*tp))),
    1556          360 :                     0, wi::to_offset (DECL_SIZE_UNIT (sym))))
    1557          360 :                && (! INTEGRAL_TYPE_P (TREE_TYPE (*tp))
    1558          346 :                    || (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp)))
    1559          692 :                        == TYPE_PRECISION (TREE_TYPE (*tp))))
    1560          360 :                && (! INTEGRAL_TYPE_P (TREE_TYPE (sym))
    1561          169 :                    || type_has_mode_precision_p (TREE_TYPE (sym)))
    1562          720 :                && wi::umod_trunc (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp))),
    1563          720 :                                   BITS_PER_UNIT) == 0)
    1564              :         {
    1565          720 :           *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym,
    1566          360 :                         TYPE_SIZE (TREE_TYPE (*tp)),
    1567              :                         wide_int_to_tree (bitsizetype,
    1568          360 :                                           mem_ref_offset (*tp)
    1569          720 :                                           << LOG2_BITS_PER_UNIT));
    1570              :         }
    1571              :     }
    1572     30223302 : }
    1573              : 
    1574              : /* For a tree REF return its base if it is the base of a MEM_REF
    1575              :    that cannot be rewritten into SSA form.  Otherwise return NULL_TREE.  */
    1576              : 
    1577              : static tree
    1578    296105486 : non_rewritable_mem_ref_base (tree ref)
    1579              : {
    1580    296105486 :   tree base;
    1581              : 
    1582              :   /* A plain decl does not need it set.  */
    1583    296105486 :   if (DECL_P (ref))
    1584              :     return NULL_TREE;
    1585              : 
    1586    265483197 :   switch (TREE_CODE (ref))
    1587              :     {
    1588      2541165 :     case REALPART_EXPR:
    1589      2541165 :     case IMAGPART_EXPR:
    1590      2541165 :     case BIT_FIELD_REF:
    1591      2541165 :       if (DECL_P (TREE_OPERAND (ref, 0)))
    1592              :         return NULL_TREE;
    1593              :       break;
    1594      2441038 :     case VIEW_CONVERT_EXPR:
    1595      2441038 :       if (DECL_P (TREE_OPERAND (ref, 0)))
    1596              :         {
    1597      1095759 :           if (TYPE_SIZE (TREE_TYPE (ref))
    1598      1095759 :               != TYPE_SIZE (TREE_TYPE (TREE_OPERAND  (ref, 0))))
    1599          676 :             return TREE_OPERAND (ref, 0);
    1600              :           return NULL_TREE;
    1601              :         }
    1602              :       break;
    1603              :     /* We would need to rewrite ARRAY_REFs or COMPONENT_REFs and even
    1604              :        more so multiple levels of handled components.  */
    1605    263925738 :     default:;
    1606              :     }
    1607              : 
    1608    263925738 :   base = ref;
    1609              : 
    1610              :   /* But watch out for MEM_REFs we cannot lower to a
    1611              :      VIEW_CONVERT_EXPR or a BIT_FIELD_REF.  */
    1612    263925738 :   if (TREE_CODE (base) == MEM_REF
    1613    263925738 :       && TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
    1614              :     {
    1615      6257787 :       tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
    1616      6257787 :       if (! DECL_P (decl))
    1617              :         return NULL_TREE;
    1618      6223851 :       if (! is_gimple_reg_type (TREE_TYPE (base))
    1619      6053918 :           || VOID_TYPE_P (TREE_TYPE (base))
    1620     12277769 :           || TREE_THIS_VOLATILE (decl) != TREE_THIS_VOLATILE (base))
    1621              :         return decl;
    1622      6052694 :       if ((VECTOR_TYPE_P (TREE_TYPE (decl))
    1623      6050582 :            || TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
    1624         3504 :           && useless_type_conversion_p (TREE_TYPE (base),
    1625         3504 :                                         TREE_TYPE (TREE_TYPE (decl)))
    1626          433 :           && known_ge (mem_ref_offset (base), 0)
    1627          386 :           && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
    1628              :                        mem_ref_offset (base))
    1629      6053074 :           && multiple_p (mem_ref_offset (base),
    1630          380 :                          wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (base)))))
    1631          378 :         return NULL_TREE;
    1632              :       /* For same sizes and zero offset we can use a VIEW_CONVERT_EXPR.  */
    1633      6052316 :       if (integer_zerop (TREE_OPERAND (base, 1))
    1634      6052316 :           && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (base)))
    1635              :         return NULL_TREE;
    1636              :       /* For integral typed extracts we can use a BIT_FIELD_REF.  */
    1637      5426397 :       if (DECL_SIZE (decl)
    1638      5421868 :           && TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST
    1639      5421868 :           && (known_subrange_p
    1640      5421868 :               (mem_ref_offset (base),
    1641      5421868 :                wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (base))),
    1642      5421868 :                0, wi::to_poly_offset (DECL_SIZE_UNIT (decl))))
    1643              :           /* ???  We can't handle bitfield precision extracts without
    1644              :              either using an alternate type for the BIT_FIELD_REF and
    1645              :              then doing a conversion or possibly adjusting the offset
    1646              :              according to endianness.  */
    1647      5419454 :           && (! INTEGRAL_TYPE_P (TREE_TYPE (base))
    1648      2896636 :               || (wi::to_offset (TYPE_SIZE (TREE_TYPE (base)))
    1649      5793272 :                   == TYPE_PRECISION (TREE_TYPE (base))))
    1650              :           /* ???  Likewise for extracts from bitfields, we'd have
    1651              :              to pun the base object to a size precision mode first.  */
    1652      5413993 :           && (! INTEGRAL_TYPE_P (TREE_TYPE (decl))
    1653        40697 :               || type_has_mode_precision_p (TREE_TYPE (decl)))
    1654     10805347 :           && wi::umod_trunc (wi::to_offset (TYPE_SIZE (TREE_TYPE (base))),
    1655     10757900 :                              BITS_PER_UNIT) == 0)
    1656      5378950 :         return NULL_TREE;
    1657        47447 :       return decl;
    1658              :     }
    1659              : 
    1660              :   /* We cannot rewrite a decl in the base.  */
    1661    257667951 :   base = get_base_address (ref);
    1662    257667951 :   if (DECL_P (base))
    1663              :     return base;
    1664              : 
    1665              :   /* We cannot rewrite TARGET_MEM_REFs.  */
    1666    238331413 :   else if (TREE_CODE (base) == TARGET_MEM_REF
    1667    238331413 :            && TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
    1668              :     {
    1669            0 :       tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
    1670            0 :       if (! DECL_P (decl))
    1671              :         return NULL_TREE;
    1672              :       return decl;
    1673              :     }
    1674              : 
    1675              :   return NULL_TREE;
    1676              : }
    1677              : 
    1678              : /* For an lvalue tree LHS return true if it cannot be rewritten into SSA form.
    1679              :    Otherwise return true.  */
    1680              : 
    1681              : static bool
    1682    102198812 : non_rewritable_lvalue_p (tree lhs)
    1683              : {
    1684              :   /* A plain decl is always rewritable.  */
    1685    102198812 :   if (DECL_P (lhs))
    1686              :     return false;
    1687              : 
    1688              :   /* We can re-write REALPART_EXPR and IMAGPART_EXPR sets in
    1689              :      a reasonably efficient manner... */
    1690     59912742 :   if ((TREE_CODE (lhs) == REALPART_EXPR
    1691     59912742 :        || TREE_CODE (lhs) == IMAGPART_EXPR)
    1692     59912742 :       && DECL_P (TREE_OPERAND (lhs, 0)))
    1693              :     return false;
    1694              : 
    1695              :   /* ???  The following could be relaxed allowing component
    1696              :      references that do not change the access size.  */
    1697     59881678 :   if (TREE_CODE (lhs) == MEM_REF
    1698     59881678 :       && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR)
    1699              :     {
    1700      7162584 :       tree decl = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0);
    1701              : 
    1702              :       /* A decl that is wrapped inside a MEM-REF that covers
    1703              :          it full is also rewritable.  */
    1704      7162584 :       if (integer_zerop (TREE_OPERAND (lhs, 1))
    1705      2091922 :           && DECL_P (decl)
    1706      2091862 :           && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (lhs))
    1707              :           /* If the dynamic type of the decl has larger precision than
    1708              :              the decl itself we can't use the decls type for SSA rewriting.  */
    1709       545597 :           && ((! INTEGRAL_TYPE_P (TREE_TYPE (decl))
    1710        13733 :                || compare_tree_int (DECL_SIZE (decl),
    1711        13733 :                                     TYPE_PRECISION (TREE_TYPE (decl))) == 0)
    1712          814 :               || (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    1713          793 :                   && (TYPE_PRECISION (TREE_TYPE (decl))
    1714          793 :                       >= TYPE_PRECISION (TREE_TYPE (lhs)))))
    1715              :           /* Make sure we are not re-writing non-float copying into float
    1716              :              copying as that can incur normalization.  */
    1717       545444 :           && (! FLOAT_TYPE_P (TREE_TYPE (decl))
    1718         4950 :               || types_compatible_p (TREE_TYPE (lhs), TREE_TYPE (decl)))
    1719      7703785 :           && (TREE_THIS_VOLATILE (decl) == TREE_THIS_VOLATILE (lhs)))
    1720              :         return false;
    1721              : 
    1722              :       /* A vector-insert using a MEM_REF or ARRAY_REF is rewritable
    1723              :          using a BIT_INSERT_EXPR.  */
    1724      6621869 :       if (DECL_P (decl)
    1725      6621803 :           && VECTOR_TYPE_P (TREE_TYPE (decl))
    1726         1715 :           && TYPE_MODE (TREE_TYPE (decl)) != BLKmode
    1727          289 :           && known_ge (mem_ref_offset (lhs), 0)
    1728          254 :           && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
    1729              :                        mem_ref_offset (lhs))
    1730          254 :           && multiple_p (mem_ref_offset (lhs),
    1731          254 :                          wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (lhs))))
    1732     13243672 :           && known_ge (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (decl))),
    1733              :                        wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (lhs)))))
    1734              :         {
    1735          253 :           poly_uint64 lhs_bits, nelts;
    1736          253 :           if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)), &lhs_bits)
    1737          255 :               && multiple_p (lhs_bits,
    1738              :                              tree_to_uhwi
    1739          253 :                                (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl)))),
    1740              :                              &nelts)
    1741          273 :               && valid_vector_subparts_p (nelts))
    1742              :             {
    1743          233 :               if (known_eq (nelts, 1u))
    1744          233 :                 return false;
    1745              :               /* For sub-vector inserts the insert vector mode has to be
    1746              :                  supported.  */
    1747          175 :               tree vtype = build_vector_type (TREE_TYPE (TREE_TYPE (decl)),
    1748          175 :                                               nelts);
    1749          175 :               if (TYPE_MODE (vtype) != BLKmode)
    1750              :                 return false;
    1751              :             }
    1752              :         }
    1753              :     }
    1754              : 
    1755              :   /* A vector-insert using a BIT_FIELD_REF is rewritable using
    1756              :      BIT_INSERT_EXPR.  */
    1757     59340730 :   if (TREE_CODE (lhs) == BIT_FIELD_REF
    1758        19054 :       && DECL_P (TREE_OPERAND (lhs, 0))
    1759        13423 :       && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (lhs, 0)))
    1760        13369 :       && TYPE_MODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) != BLKmode
    1761         1576 :       && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
    1762         1576 :                           TYPE_SIZE_UNIT
    1763              :                             (TREE_TYPE (TREE_TYPE (TREE_OPERAND (lhs, 0)))), 0)
    1764     59342305 :       && (tree_to_uhwi (TREE_OPERAND (lhs, 2))
    1765         1575 :           % tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs)))) == 0)
    1766              :     return false;
    1767              : 
    1768              :   return true;
    1769              : }
    1770              : 
    1771              : /* When possible, clear TREE_ADDRESSABLE bit, set or clear DECL_NOT_GIMPLE_REG_P
    1772              :    and mark the variable VAR for conversion into SSA.  Return true when updating
    1773              :    stmts is required.  */
    1774              : 
    1775              : static void
    1776    105360080 : maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
    1777              :                     bitmap suitable_for_renaming)
    1778              : {
    1779              :   /* Global Variables, result decls cannot be changed.  */
    1780    105360080 :   if (is_global_var (var)
    1781    103732485 :       || TREE_CODE (var) == RESULT_DECL
    1782    209092565 :       || bitmap_bit_p (addresses_taken, DECL_UID (var)))
    1783     10411587 :     return;
    1784              : 
    1785     94948493 :   bool maybe_reg = false;
    1786     94948493 :   if (TREE_ADDRESSABLE (var))
    1787              :     {
    1788      1510147 :       TREE_ADDRESSABLE (var) = 0;
    1789      1510147 :       maybe_reg = true;
    1790      1510147 :       if (dump_file)
    1791              :         {
    1792           69 :           fprintf (dump_file, "No longer having address taken: ");
    1793           69 :           print_generic_expr (dump_file, var);
    1794           69 :           fprintf (dump_file, "\n");
    1795              :         }
    1796              :     }
    1797              : 
    1798              :   /* For register type decls if we do not have any partial defs
    1799              :      we cannot express in SSA form mark them as DECL_NOT_GIMPLE_REG_P
    1800              :      as to avoid SSA rewrite.  For the others go ahead and mark
    1801              :      them for renaming.  */
    1802     94948493 :   if (is_gimple_reg_type (TREE_TYPE (var)))
    1803              :     {
    1804     79498074 :       if (bitmap_bit_p (not_reg_needs, DECL_UID (var)))
    1805              :         {
    1806        33286 :           DECL_NOT_GIMPLE_REG_P (var) = 1;
    1807        33286 :           if (dump_file)
    1808              :             {
    1809            4 :               fprintf (dump_file, "Has partial defs: ");
    1810            4 :               print_generic_expr (dump_file, var);
    1811            4 :               fprintf (dump_file, "\n");
    1812              :             }
    1813              :         }
    1814     79464788 :       else if (TREE_CODE (TREE_TYPE (var)) == BITINT_TYPE
    1815        39809 :                && (cfun->curr_properties & PROP_gimple_lbitint) != 0
    1816     79484776 :                && TYPE_PRECISION (TREE_TYPE (var)) > MAX_FIXED_MODE_SIZE)
    1817              :         {
    1818              :           /* Don't rewrite large/huge _BitInt vars after _BitInt lowering
    1819              :              into SSA form.  */
    1820         2218 :           DECL_NOT_GIMPLE_REG_P (var) = 1;
    1821         2218 :           if (dump_file)
    1822              :             {
    1823            0 :               fprintf (dump_file, "_BitInt var after its lowering: ");
    1824            0 :               print_generic_expr (dump_file, var);
    1825            0 :               fprintf (dump_file, "\n");
    1826              :             }
    1827              :         }
    1828     79462570 :       else if (DECL_NOT_GIMPLE_REG_P (var))
    1829              :         {
    1830         7981 :           maybe_reg = true;
    1831         7981 :           DECL_NOT_GIMPLE_REG_P (var) = 0;
    1832              :         }
    1833     79498074 :       if (maybe_reg)
    1834              :         {
    1835       548563 :           if (is_gimple_reg (var))
    1836              :             {
    1837       541090 :               if (dump_file)
    1838              :                 {
    1839           16 :                   fprintf (dump_file, "Now a gimple register: ");
    1840           16 :                   print_generic_expr (dump_file, var);
    1841           16 :                   fprintf (dump_file, "\n");
    1842              :                 }
    1843       541090 :               bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
    1844              :             }
    1845              :           else
    1846         7473 :             DECL_NOT_GIMPLE_REG_P (var) = 1;
    1847              :         }
    1848              :     }
    1849              : }
    1850              : 
    1851              : /* Return true when STMT is ASAN mark where second argument is an address
    1852              :    of a local variable.  */
    1853              : 
    1854              : static bool
    1855     59118488 : is_asan_mark_p (gimple *stmt)
    1856              : {
    1857     59118488 :   if (!gimple_call_internal_p (stmt, IFN_ASAN_MARK))
    1858              :     return false;
    1859              : 
    1860        57571 :   tree addr = get_base_address (gimple_call_arg (stmt, 1));
    1861        57571 :   if (TREE_CODE (addr) == ADDR_EXPR
    1862        57571 :       && VAR_P (TREE_OPERAND (addr, 0)))
    1863              :     {
    1864        57367 :       tree var = TREE_OPERAND (addr, 0);
    1865        57367 :       if (lookup_attribute (ASAN_USE_AFTER_SCOPE_ATTRIBUTE,
    1866        57367 :                             DECL_ATTRIBUTES (var)))
    1867              :         return false;
    1868              : 
    1869        52356 :       unsigned addressable = TREE_ADDRESSABLE (var);
    1870        52356 :       TREE_ADDRESSABLE (var) = 0;
    1871        52356 :       bool r = is_gimple_reg (var);
    1872        52356 :       TREE_ADDRESSABLE (var) = addressable;
    1873        52356 :       return r;
    1874              :     }
    1875              : 
    1876              :   return false;
    1877              : }
    1878              : 
    1879              : /* Compute TREE_ADDRESSABLE and whether we have unhandled partial defs
    1880              :    for local variables.  */
    1881              : 
    1882              : void
    1883     12444493 : execute_update_addresses_taken (void)
    1884              : {
    1885     12444493 :   basic_block bb;
    1886     12444493 :   auto_bitmap addresses_taken;
    1887     12444493 :   auto_bitmap not_reg_needs;
    1888     12444493 :   auto_bitmap suitable_for_renaming;
    1889     12444493 :   bool optimistic_not_addressable = false;
    1890     12444493 :   tree var;
    1891     12444493 :   unsigned i;
    1892              : 
    1893     12444493 :   timevar_push (TV_ADDRESS_TAKEN);
    1894              : 
    1895              :   /* Collect into ADDRESSES_TAKEN all variables whose address is taken within
    1896              :      the function body.  */
    1897    121999123 :   FOR_EACH_BB_FN (bb, cfun)
    1898              :     {
    1899   1039273396 :       for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
    1900    820164136 :            gsi_next (&gsi))
    1901              :         {
    1902    820164136 :           gimple *stmt = gsi_stmt (gsi);
    1903    820164136 :           enum gimple_code code = gimple_code (stmt);
    1904    820164136 :           tree decl;
    1905              : 
    1906    820164136 :           if (code == GIMPLE_CALL)
    1907              :             {
    1908     56144170 :               if (optimize_atomic_compare_exchange_p (stmt))
    1909              :                 {
    1910              :                   /* For __atomic_compare_exchange_N if the second argument
    1911              :                      is &var, don't mark var addressable;
    1912              :                      if it becomes non-addressable, we'll rewrite it into
    1913              :                      ATOMIC_COMPARE_EXCHANGE call.  */
    1914         5781 :                   tree arg = gimple_call_arg (stmt, 1);
    1915         5781 :                   gimple_call_set_arg (stmt, 1, null_pointer_node);
    1916         5781 :                   gimple_ior_addresses_taken (addresses_taken, stmt);
    1917         5781 :                   gimple_call_set_arg (stmt, 1, arg);
    1918              :                   /* Remember we have to check again below.  */
    1919         5781 :                   optimistic_not_addressable = true;
    1920              :                 }
    1921     56138389 :               else if (is_asan_mark_p (stmt)
    1922     56138389 :                        || gimple_call_internal_p (stmt, IFN_GOMP_SIMT_ENTER))
    1923              :                 ;
    1924              :               else
    1925     56117425 :                 gimple_ior_addresses_taken (addresses_taken, stmt);
    1926              :             }
    1927              :           else
    1928              :             /* Note all addresses taken by the stmt.  */
    1929    764019966 :             gimple_ior_addresses_taken (addresses_taken, stmt);
    1930              : 
    1931              :           /* If we have a call or an assignment, see if the lhs contains
    1932              :              a local decl that requires not to be a gimple register.  */
    1933    820164136 :           if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
    1934              :             {
    1935    314084259 :               tree lhs = gimple_get_lhs (stmt);
    1936    314084259 :               if (lhs
    1937    280314390 :                   && TREE_CODE (lhs) != SSA_NAME
    1938    416283578 :                   && ((code == GIMPLE_CALL && ! DECL_P (lhs))
    1939    102091421 :                       || non_rewritable_lvalue_p (lhs)))
    1940              :                 {
    1941     59434815 :                   decl = get_base_address (lhs);
    1942     59434815 :                   if (DECL_P (decl))
    1943     41325815 :                     bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    1944              :                 }
    1945              :             }
    1946              : 
    1947    820164136 :           if (gimple_assign_single_p (stmt))
    1948              :             {
    1949    174253024 :               tree rhs = gimple_assign_rhs1 (stmt);
    1950    174253024 :               if ((decl = non_rewritable_mem_ref_base (rhs)))
    1951     19358030 :                 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    1952              :             }
    1953              : 
    1954    645911112 :           else if (code == GIMPLE_CALL)
    1955              :             {
    1956    166379552 :               for (i = 0; i < gimple_call_num_args (stmt); ++i)
    1957              :                 {
    1958    110235382 :                   tree arg = gimple_call_arg (stmt, i);
    1959    110235382 :                   if ((decl = non_rewritable_mem_ref_base (arg)))
    1960       157714 :                     bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    1961              :                 }
    1962              :             }
    1963              : 
    1964    589766942 :           else if (code == GIMPLE_ASM)
    1965              :             {
    1966       731304 :               gasm *asm_stmt = as_a <gasm *> (stmt);
    1967      1388062 :               for (i = 0; i < gimple_asm_noutputs (asm_stmt); ++i)
    1968              :                 {
    1969       656758 :                   tree link = gimple_asm_output_op (asm_stmt, i);
    1970       656758 :                   tree lhs = TREE_VALUE (link);
    1971       656758 :                   if (TREE_CODE (lhs) != SSA_NAME)
    1972              :                     {
    1973       169013 :                       decl = get_base_address (lhs);
    1974       169013 :                       if (DECL_P (decl)
    1975       169013 :                           && (non_rewritable_lvalue_p (lhs)
    1976              :                               /* We cannot move required conversions from
    1977              :                                  the lhs to the rhs in asm statements, so
    1978              :                                  require we do not need any.  */
    1979        95153 :                               || !useless_type_conversion_p
    1980        95153 :                                     (TREE_TYPE (lhs), TREE_TYPE (decl))))
    1981        12784 :                         bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    1982              :                     }
    1983              :                 }
    1984      1163484 :               for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
    1985              :                 {
    1986       432180 :                   tree link = gimple_asm_input_op (asm_stmt, i);
    1987       432180 :                   if ((decl = non_rewritable_mem_ref_base (TREE_VALUE (link))))
    1988         3343 :                     bitmap_set_bit (not_reg_needs, DECL_UID (decl));
    1989              :                 }
    1990              :             }
    1991              :         }
    1992              : 
    1993    146450989 :       for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
    1994     36896359 :            gsi_next (&gsi))
    1995              :         {
    1996     36896359 :           size_t i;
    1997     36896359 :           gphi *phi = gsi.phi ();
    1998              : 
    1999    132654629 :           for (i = 0; i < gimple_phi_num_args (phi); i++)
    2000              :             {
    2001     95758270 :               tree op = PHI_ARG_DEF (phi, i), var;
    2002     95758270 :               if (TREE_CODE (op) == ADDR_EXPR
    2003       747044 :                   && (var = get_base_address (TREE_OPERAND (op, 0))) != NULL
    2004     96505314 :                   && DECL_P (var))
    2005       567343 :                 bitmap_set_bit (addresses_taken, DECL_UID (var));
    2006              :             }
    2007              :         }
    2008              :     }
    2009              : 
    2010              :   /* We cannot iterate over all referenced vars because that can contain
    2011              :      unused vars from BLOCK trees, which causes code generation differences
    2012              :      for -g vs. -g0.  */
    2013     38541317 :   for (var = DECL_ARGUMENTS (cfun->decl); var; var = DECL_CHAIN (var))
    2014     26096824 :     maybe_optimize_var (var, addresses_taken, not_reg_needs,
    2015              :                         suitable_for_renaming);
    2016              : 
    2017     91707749 :   FOR_EACH_VEC_SAFE_ELT (cfun->local_decls, i, var)
    2018     79263256 :     maybe_optimize_var (var, addresses_taken, not_reg_needs,
    2019              :                         suitable_for_renaming);
    2020              : 
    2021              :   /* Operand caches need to be recomputed for operands referencing the updated
    2022              :      variables and operands need to be rewritten to expose bare symbols.  */
    2023     12444493 :   if (!bitmap_empty_p (suitable_for_renaming)
    2024     12444493 :       || optimistic_not_addressable)
    2025              :     {
    2026      6849560 :       FOR_EACH_BB_FN (bb, cfun)
    2027     64170298 :         for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
    2028              :           {
    2029     50910028 :             gimple *stmt = gsi_stmt (gsi);
    2030              : 
    2031              :             /* Re-write TARGET_MEM_REFs of symbols we want to
    2032              :                rewrite into SSA form.  */
    2033     50910028 :             if (gimple_assign_single_p (stmt))
    2034              :               {
    2035     13948458 :                 tree lhs = gimple_assign_lhs (stmt);
    2036     13948458 :                 tree rhs, *rhsp = gimple_assign_rhs1_ptr (stmt);
    2037     13948458 :                 tree sym;
    2038              : 
    2039              :                 /* Rewrite LHS IMAG/REALPART_EXPR similar to
    2040              :                    gimplify_modify_expr_complex_part.  */
    2041     13948458 :                 if ((TREE_CODE (lhs) == IMAGPART_EXPR
    2042     13948458 :                      || TREE_CODE (lhs) == REALPART_EXPR)
    2043         2217 :                     && DECL_P (TREE_OPERAND (lhs, 0))
    2044     13949942 :                     && bitmap_bit_p (suitable_for_renaming,
    2045         1484 :                                      DECL_UID (TREE_OPERAND (lhs, 0))))
    2046              :                   {
    2047         1410 :                     tree other = make_ssa_name (TREE_TYPE (lhs));
    2048         2124 :                     tree lrhs = build1 (TREE_CODE (lhs) == IMAGPART_EXPR
    2049              :                                         ? REALPART_EXPR : IMAGPART_EXPR,
    2050         1410 :                                         TREE_TYPE (other),
    2051         1410 :                                         TREE_OPERAND (lhs, 0));
    2052         1410 :                     suppress_warning (lrhs);
    2053         1410 :                     gimple *load = gimple_build_assign (other, lrhs);
    2054         1410 :                     location_t loc = gimple_location (stmt);
    2055         1410 :                     gimple_set_location (load, loc);
    2056         2820 :                     gimple_set_vuse (load, gimple_vuse (stmt));
    2057         1410 :                     gsi_insert_before (&gsi, load, GSI_SAME_STMT);
    2058         1410 :                     gimple_assign_set_lhs (stmt, TREE_OPERAND (lhs, 0));
    2059         1410 :                     gimple_assign_set_rhs_with_ops
    2060         2124 :                       (&gsi, COMPLEX_EXPR,
    2061              :                        TREE_CODE (lhs) == IMAGPART_EXPR
    2062          714 :                        ? other : gimple_assign_rhs1 (stmt),
    2063         1410 :                        TREE_CODE (lhs) == IMAGPART_EXPR
    2064          696 :                        ? gimple_assign_rhs1 (stmt) : other, NULL_TREE);
    2065         1410 :                     stmt = gsi_stmt (gsi);
    2066         1410 :                     unlink_stmt_vdef (stmt);
    2067         1410 :                     update_stmt (stmt);
    2068         1410 :                     continue;
    2069         1410 :                   }
    2070              : 
    2071              :                 /* Rewrite a vector insert via a BIT_FIELD_REF on the LHS
    2072              :                    into a BIT_INSERT_EXPR.  */
    2073     13947048 :                 if (TREE_CODE (lhs) == BIT_FIELD_REF
    2074          820 :                     && DECL_P (TREE_OPERAND (lhs, 0))
    2075          762 :                     && bitmap_bit_p (suitable_for_renaming,
    2076          762 :                                      DECL_UID (TREE_OPERAND (lhs, 0)))
    2077          636 :                     && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (lhs, 0)))
    2078          636 :                     && TYPE_MODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) != BLKmode
    2079          636 :                     && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
    2080          636 :                                         TYPE_SIZE_UNIT (TREE_TYPE
    2081              :                                           (TREE_TYPE (TREE_OPERAND (lhs, 0)))),
    2082              :                                         0)
    2083     13947684 :                     && (tree_to_uhwi (TREE_OPERAND (lhs, 2))
    2084          636 :                         % tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs))) == 0))
    2085              :                   {
    2086          636 :                     tree var = TREE_OPERAND (lhs, 0);
    2087          636 :                     tree val = gimple_assign_rhs1 (stmt);
    2088          636 :                     if (! types_compatible_p (TREE_TYPE (TREE_TYPE (var)),
    2089          636 :                                               TREE_TYPE (val)))
    2090              :                       {
    2091            0 :                         tree tem = make_ssa_name (TREE_TYPE (TREE_TYPE (var)));
    2092            0 :                         gimple *pun
    2093            0 :                           = gimple_build_assign (tem,
    2094              :                                                  build1 (VIEW_CONVERT_EXPR,
    2095            0 :                                                          TREE_TYPE (tem), val));
    2096            0 :                         gsi_insert_before (&gsi, pun, GSI_SAME_STMT);
    2097            0 :                         val = tem;
    2098              :                       }
    2099          636 :                     tree bitpos = TREE_OPERAND (lhs, 2);
    2100          636 :                     gimple_assign_set_lhs (stmt, var);
    2101          636 :                     gimple_assign_set_rhs_with_ops
    2102          636 :                       (&gsi, BIT_INSERT_EXPR, var, val, bitpos);
    2103          636 :                     stmt = gsi_stmt (gsi);
    2104          636 :                     unlink_stmt_vdef (stmt);
    2105          636 :                     update_stmt (stmt);
    2106          636 :                     continue;
    2107          636 :                   }
    2108              : 
    2109              :                 /* Rewrite a vector insert using a MEM_REF on the LHS
    2110              :                    into a BIT_INSERT_EXPR.  */
    2111     13946412 :                 if (TREE_CODE (lhs) == MEM_REF
    2112       610866 :                     && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
    2113       134416 :                     && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0))
    2114       134416 :                     && DECL_P (sym)
    2115       134416 :                     && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym))
    2116         8426 :                     && VECTOR_TYPE_P (TREE_TYPE (sym))
    2117          160 :                     && TYPE_MODE (TREE_TYPE (sym)) != BLKmode
    2118              :                     /* If it is a full replacement we can do better below.  */
    2119          156 :                     && maybe_ne (wi::to_poly_offset
    2120          156 :                                    (TYPE_SIZE_UNIT (TREE_TYPE (lhs))),
    2121              :                                  wi::to_poly_offset
    2122          156 :                                    (TYPE_SIZE_UNIT (TREE_TYPE (sym))))
    2123           82 :                     && known_ge (mem_ref_offset (lhs), 0)
    2124           82 :                     && known_gt (wi::to_poly_offset
    2125              :                                    (TYPE_SIZE_UNIT (TREE_TYPE (sym))),
    2126              :                                  mem_ref_offset (lhs))
    2127     13946494 :                     && multiple_p (mem_ref_offset (lhs),
    2128              :                                    wi::to_poly_offset
    2129     13946412 :                                      (TYPE_SIZE_UNIT (TREE_TYPE (lhs)))))
    2130              :                   {
    2131           82 :                     tree val = gimple_assign_rhs1 (stmt);
    2132           82 :                     if (! types_compatible_p (TREE_TYPE (val),
    2133           82 :                                               TREE_TYPE (TREE_TYPE (sym))))
    2134              :                       {
    2135           56 :                         poly_uint64 lhs_bits, nelts;
    2136           56 :                         tree temtype = TREE_TYPE (TREE_TYPE (sym));
    2137           56 :                         if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)),
    2138              :                                              &lhs_bits)
    2139           56 :                             && multiple_p (lhs_bits,
    2140              :                                            tree_to_uhwi
    2141           56 :                                              (TYPE_SIZE (TREE_TYPE
    2142              :                                                            (TREE_TYPE (sym)))),
    2143              :                                            &nelts)
    2144           56 :                             && maybe_ne (nelts, 1u)
    2145           56 :                             && valid_vector_subparts_p (nelts))
    2146           30 :                           temtype = build_vector_type (temtype, nelts);
    2147           56 :                         tree tem = make_ssa_name (temtype);
    2148           56 :                         gimple *pun
    2149           56 :                           = gimple_build_assign (tem,
    2150              :                                                  build1 (VIEW_CONVERT_EXPR,
    2151           56 :                                                          TREE_TYPE (tem), val));
    2152           56 :                         gsi_insert_before (&gsi, pun, GSI_SAME_STMT);
    2153           56 :                         val = tem;
    2154              :                       }
    2155           82 :                     tree bitpos
    2156           82 :                       = wide_int_to_tree (bitsizetype,
    2157           82 :                                           mem_ref_offset (lhs) * BITS_PER_UNIT);
    2158           82 :                     gimple_assign_set_lhs (stmt, sym);
    2159           82 :                     gimple_assign_set_rhs_with_ops
    2160           82 :                       (&gsi, BIT_INSERT_EXPR, sym, val, bitpos);
    2161           82 :                     stmt = gsi_stmt (gsi);
    2162           82 :                     unlink_stmt_vdef (stmt);
    2163           82 :                     update_stmt (stmt);
    2164           82 :                     continue;
    2165           82 :                   }
    2166              : 
    2167              :                 /* We shouldn't have any fancy wrapping of
    2168              :                    component-refs on the LHS, but look through
    2169              :                    VIEW_CONVERT_EXPRs as that is easy.  */
    2170     13946340 :                 while (TREE_CODE (lhs) == VIEW_CONVERT_EXPR)
    2171           10 :                   lhs = TREE_OPERAND (lhs, 0);
    2172     13946330 :                 if (TREE_CODE (lhs) == MEM_REF
    2173       610789 :                     && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
    2174       134334 :                     && integer_zerop (TREE_OPERAND (lhs, 1))
    2175        57671 :                     && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0))
    2176        57671 :                     && DECL_P (sym)
    2177        57671 :                     && !TREE_ADDRESSABLE (sym)
    2178     13982209 :                     && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym)))
    2179              :                   lhs = sym;
    2180              :                 else
    2181     13937986 :                   lhs = gimple_assign_lhs (stmt);
    2182              : 
    2183              :                 /* Rewrite the RHS and make sure the resulting assignment
    2184              :                    is validly typed.  */
    2185     13946330 :                 maybe_rewrite_mem_ref_base (rhsp, suitable_for_renaming);
    2186     13946330 :                 rhs = gimple_assign_rhs1 (stmt);
    2187     13946330 :                 if (gimple_assign_lhs (stmt) != lhs
    2188     13954674 :                     && !useless_type_conversion_p (TREE_TYPE (lhs),
    2189         8344 :                                                    TREE_TYPE (rhs)))
    2190              :                   {
    2191         3795 :                     if (gimple_clobber_p (stmt))
    2192              :                       {
    2193           11 :                         rhs = build_constructor (TREE_TYPE (lhs), NULL);
    2194           11 :                         TREE_THIS_VOLATILE (rhs) = 1;
    2195              :                       }
    2196              :                     else
    2197         3784 :                       rhs = fold_build1 (VIEW_CONVERT_EXPR,
    2198              :                                          TREE_TYPE (lhs), rhs);
    2199              :                   }
    2200     13946330 :                 if (gimple_assign_lhs (stmt) != lhs)
    2201         8344 :                   gimple_assign_set_lhs (stmt, lhs);
    2202              : 
    2203     13946330 :                 if (gimple_assign_rhs1 (stmt) != rhs)
    2204              :                   {
    2205         3795 :                     gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    2206         3795 :                     gimple_assign_set_rhs_from_tree (&gsi, rhs);
    2207              :                   }
    2208              :               }
    2209              : 
    2210     36961570 :             else if (gimple_code (stmt) == GIMPLE_CALL)
    2211              :               {
    2212      2985880 :                 unsigned i;
    2213      2985880 :                 if (optimize_atomic_compare_exchange_p (stmt))
    2214              :                   {
    2215         5781 :                     tree expected = gimple_call_arg (stmt, 1);
    2216         5781 :                     tree decl = TREE_OPERAND (expected, 0);
    2217         5781 :                     if (bitmap_bit_p (suitable_for_renaming, DECL_UID (decl)))
    2218              :                       {
    2219         5706 :                         fold_builtin_atomic_compare_exchange (&gsi);
    2220         5706 :                         continue;
    2221              :                       }
    2222           75 :                     else if (!TREE_ADDRESSABLE (decl))
    2223              :                       /* If there are partial defs of the decl we may
    2224              :                          have cleared the addressable bit but set
    2225              :                          DECL_NOT_GIMPLE_REG_P.  We have to restore
    2226              :                          TREE_ADDRESSABLE here.  */
    2227           27 :                       TREE_ADDRESSABLE (decl) = 1;
    2228              :                   }
    2229      2980099 :                 else if (is_asan_mark_p (stmt))
    2230              :                   {
    2231          724 :                     tree var = TREE_OPERAND (gimple_call_arg (stmt, 1), 0);
    2232          724 :                     if (bitmap_bit_p (suitable_for_renaming, DECL_UID (var)))
    2233              :                       {
    2234          676 :                         unlink_stmt_vdef (stmt);
    2235          676 :                         if (asan_mark_p (stmt, ASAN_MARK_POISON))
    2236              :                           {
    2237          366 :                             gcall *call
    2238          366 :                               = gimple_build_call_internal (IFN_ASAN_POISON, 0);
    2239          366 :                             gimple_call_set_lhs (call, var);
    2240          366 :                             gsi_replace (&gsi, call, true);
    2241              :                           }
    2242              :                         else
    2243              :                           {
    2244              :                             /* In ASAN_MARK (UNPOISON, &b, ...) the variable
    2245              :                                is uninitialized.  Avoid dependencies on
    2246              :                                previous out of scope value.  */
    2247          310 :                             tree clobber = build_clobber (TREE_TYPE (var));
    2248          310 :                             gimple *g = gimple_build_assign (var, clobber);
    2249          310 :                             gsi_replace (&gsi, g, true);
    2250              :                           }
    2251          676 :                         continue;
    2252          676 :                       }
    2253              :                   }
    2254      2979375 :                 else if (gimple_call_internal_p (stmt, IFN_GOMP_SIMT_ENTER))
    2255            0 :                   for (i = 1; i < gimple_call_num_args (stmt); i++)
    2256              :                     {
    2257            0 :                       tree *argp = gimple_call_arg_ptr (stmt, i);
    2258            0 :                       if (*argp == null_pointer_node)
    2259            0 :                         continue;
    2260            0 :                       gcc_assert (TREE_CODE (*argp) == ADDR_EXPR
    2261              :                                   && VAR_P (TREE_OPERAND (*argp, 0)));
    2262            0 :                       tree var = TREE_OPERAND (*argp, 0);
    2263            0 :                       if (bitmap_bit_p (suitable_for_renaming, DECL_UID (var)))
    2264            0 :                         *argp = null_pointer_node;
    2265              :                     }
    2266      8019978 :                 for (i = 0; i < gimple_call_num_args (stmt); ++i)
    2267              :                   {
    2268      5040480 :                     tree *argp = gimple_call_arg_ptr (stmt, i);
    2269      5040480 :                     maybe_rewrite_mem_ref_base (argp, suitable_for_renaming);
    2270              :                   }
    2271              :               }
    2272              : 
    2273     33975690 :             else if (gimple_code (stmt) == GIMPLE_ASM)
    2274              :               {
    2275        11084 :                 gasm *asm_stmt = as_a <gasm *> (stmt);
    2276        11084 :                 unsigned i;
    2277        48339 :                 for (i = 0; i < gimple_asm_noutputs (asm_stmt); ++i)
    2278              :                   {
    2279        37255 :                     tree link = gimple_asm_output_op (asm_stmt, i);
    2280        37255 :                     maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
    2281              :                                                 suitable_for_renaming);
    2282              :                   }
    2283        25421 :                 for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
    2284              :                   {
    2285        14337 :                     tree link = gimple_asm_input_op (asm_stmt, i);
    2286        14337 :                     maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
    2287              :                                                 suitable_for_renaming);
    2288              :                   }
    2289              :               }
    2290              : 
    2291     33964606 :             else if (gimple_debug_bind_p (stmt)
    2292     27143288 :                      && gimple_debug_bind_has_value_p (stmt))
    2293              :               {
    2294     11184900 :                 tree *valuep = gimple_debug_bind_get_value_ptr (stmt);
    2295     11184900 :                 tree decl;
    2296     11184900 :                 maybe_rewrite_mem_ref_base (valuep, suitable_for_renaming);
    2297     11184900 :                 decl = non_rewritable_mem_ref_base (*valuep);
    2298     11184900 :                 if (decl
    2299     11184900 :                     && bitmap_bit_p (suitable_for_renaming, DECL_UID (decl)))
    2300           10 :                   gimple_debug_bind_reset_value (stmt);
    2301              :               }
    2302              : 
    2303     65389704 :             if (gimple_references_memory_p (stmt)
    2304     44400619 :                 || is_gimple_debug (stmt))
    2305     33644187 :               update_stmt (stmt);
    2306              : 
    2307     50901518 :             gsi_next (&gsi);
    2308              :           }
    2309              : 
    2310              :       /* Update SSA form here, we are called as non-pass as well.  */
    2311       219425 :       if (number_of_loops (cfun) > 1
    2312       219425 :           && loops_state_satisfies_p (LOOP_CLOSED_SSA))
    2313           66 :         rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
    2314              :       else
    2315       219359 :         update_ssa (TODO_update_ssa);
    2316              :     }
    2317              : 
    2318     12444493 :   timevar_pop (TV_ADDRESS_TAKEN);
    2319     12444493 : }
    2320              : 
    2321              : namespace {
    2322              : 
    2323              : const pass_data pass_data_update_address_taken =
    2324              : {
    2325              :   GIMPLE_PASS, /* type */
    2326              :   "addressables", /* name */
    2327              :   OPTGROUP_NONE, /* optinfo_flags */
    2328              :   TV_ADDRESS_TAKEN, /* tv_id */
    2329              :   PROP_ssa, /* properties_required */
    2330              :   0, /* properties_provided */
    2331              :   0, /* properties_destroyed */
    2332              :   0, /* todo_flags_start */
    2333              :   TODO_update_address_taken, /* todo_flags_finish */
    2334              : };
    2335              : 
    2336              : class pass_update_address_taken : public gimple_opt_pass
    2337              : {
    2338              : public:
    2339            0 :   pass_update_address_taken (gcc::context *ctxt)
    2340            0 :     : gimple_opt_pass (pass_data_update_address_taken, ctxt)
    2341              :   {}
    2342              : 
    2343              :   /* opt_pass methods: */
    2344              : 
    2345              : }; // class pass_update_address_taken
    2346              : 
    2347              : } // anon namespace
    2348              : 
    2349              : gimple_opt_pass *
    2350            0 : make_pass_update_address_taken (gcc::context *ctxt)
    2351              : {
    2352            0 :   return new pass_update_address_taken (ctxt);
    2353              : }
        

Generated by: LCOV version 2.4-beta

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