LCOV - code coverage report
Current view: top level - gcc - tree-ssa-sccvn.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 95.6 % 4584 4383
Test Date: 2025-09-20 13:40:47 Functions: 94.3 % 123 116
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* SCC value numbering for trees
       2                 :             :    Copyright (C) 2006-2025 Free Software Foundation, Inc.
       3                 :             :    Contributed by Daniel Berlin <dan@dberlin.org>
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify
       8                 :             : it under the terms of the GNU General Public License as published by
       9                 :             : the Free Software Foundation; either version 3, or (at your option)
      10                 :             : any later version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful,
      13                 :             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :             : GNU General Public License for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : #include "config.h"
      22                 :             : #include "system.h"
      23                 :             : #include "coretypes.h"
      24                 :             : #include "backend.h"
      25                 :             : #include "rtl.h"
      26                 :             : #include "tree.h"
      27                 :             : #include "gimple.h"
      28                 :             : #include "ssa.h"
      29                 :             : #include "expmed.h"
      30                 :             : #include "insn-config.h"
      31                 :             : #include "memmodel.h"
      32                 :             : #include "emit-rtl.h"
      33                 :             : #include "cgraph.h"
      34                 :             : #include "gimple-pretty-print.h"
      35                 :             : #include "splay-tree-utils.h"
      36                 :             : #include "alias.h"
      37                 :             : #include "fold-const.h"
      38                 :             : #include "stor-layout.h"
      39                 :             : #include "cfganal.h"
      40                 :             : #include "tree-inline.h"
      41                 :             : #include "internal-fn.h"
      42                 :             : #include "gimple-iterator.h"
      43                 :             : #include "gimple-fold.h"
      44                 :             : #include "tree-eh.h"
      45                 :             : #include "gimplify.h"
      46                 :             : #include "flags.h"
      47                 :             : #include "dojump.h"
      48                 :             : #include "explow.h"
      49                 :             : #include "calls.h"
      50                 :             : #include "varasm.h"
      51                 :             : #include "stmt.h"
      52                 :             : #include "expr.h"
      53                 :             : #include "tree-dfa.h"
      54                 :             : #include "tree-ssa.h"
      55                 :             : #include "dumpfile.h"
      56                 :             : #include "cfgloop.h"
      57                 :             : #include "tree-ssa-propagate.h"
      58                 :             : #include "tree-cfg.h"
      59                 :             : #include "domwalk.h"
      60                 :             : #include "gimple-match.h"
      61                 :             : #include "stringpool.h"
      62                 :             : #include "attribs.h"
      63                 :             : #include "tree-pass.h"
      64                 :             : #include "statistics.h"
      65                 :             : #include "langhooks.h"
      66                 :             : #include "ipa-utils.h"
      67                 :             : #include "dbgcnt.h"
      68                 :             : #include "tree-cfgcleanup.h"
      69                 :             : #include "tree-ssa-loop.h"
      70                 :             : #include "tree-scalar-evolution.h"
      71                 :             : #include "tree-ssa-loop-niter.h"
      72                 :             : #include "builtins.h"
      73                 :             : #include "fold-const-call.h"
      74                 :             : #include "ipa-modref-tree.h"
      75                 :             : #include "ipa-modref.h"
      76                 :             : #include "tree-ssa-sccvn.h"
      77                 :             : #include "alloc-pool.h"
      78                 :             : #include "symbol-summary.h"
      79                 :             : #include "sreal.h"
      80                 :             : #include "ipa-cp.h"
      81                 :             : #include "ipa-prop.h"
      82                 :             : #include "target.h"
      83                 :             : 
      84                 :             : /* This algorithm is based on the SCC algorithm presented by Keith
      85                 :             :    Cooper and L. Taylor Simpson in "SCC-Based Value numbering"
      86                 :             :    (http://citeseer.ist.psu.edu/41805.html).  In
      87                 :             :    straight line code, it is equivalent to a regular hash based value
      88                 :             :    numbering that is performed in reverse postorder.
      89                 :             : 
      90                 :             :    For code with cycles, there are two alternatives, both of which
      91                 :             :    require keeping the hashtables separate from the actual list of
      92                 :             :    value numbers for SSA names.
      93                 :             : 
      94                 :             :    1. Iterate value numbering in an RPO walk of the blocks, removing
      95                 :             :    all the entries from the hashtable after each iteration (but
      96                 :             :    keeping the SSA name->value number mapping between iterations).
      97                 :             :    Iterate until it does not change.
      98                 :             : 
      99                 :             :    2. Perform value numbering as part of an SCC walk on the SSA graph,
     100                 :             :    iterating only the cycles in the SSA graph until they do not change
     101                 :             :    (using a separate, optimistic hashtable for value numbering the SCC
     102                 :             :    operands).
     103                 :             : 
     104                 :             :    The second is not just faster in practice (because most SSA graph
     105                 :             :    cycles do not involve all the variables in the graph), it also has
     106                 :             :    some nice properties.
     107                 :             : 
     108                 :             :    One of these nice properties is that when we pop an SCC off the
     109                 :             :    stack, we are guaranteed to have processed all the operands coming from
     110                 :             :    *outside of that SCC*, so we do not need to do anything special to
     111                 :             :    ensure they have value numbers.
     112                 :             : 
     113                 :             :    Another nice property is that the SCC walk is done as part of a DFS
     114                 :             :    of the SSA graph, which makes it easy to perform combining and
     115                 :             :    simplifying operations at the same time.
     116                 :             : 
     117                 :             :    The code below is deliberately written in a way that makes it easy
     118                 :             :    to separate the SCC walk from the other work it does.
     119                 :             : 
     120                 :             :    In order to propagate constants through the code, we track which
     121                 :             :    expressions contain constants, and use those while folding.  In
     122                 :             :    theory, we could also track expressions whose value numbers are
     123                 :             :    replaced, in case we end up folding based on expression
     124                 :             :    identities.
     125                 :             : 
     126                 :             :    In order to value number memory, we assign value numbers to vuses.
     127                 :             :    This enables us to note that, for example, stores to the same
     128                 :             :    address of the same value from the same starting memory states are
     129                 :             :    equivalent.
     130                 :             :    TODO:
     131                 :             : 
     132                 :             :    1. We can iterate only the changing portions of the SCC's, but
     133                 :             :    I have not seen an SCC big enough for this to be a win.
     134                 :             :    2. If you differentiate between phi nodes for loops and phi nodes
     135                 :             :    for if-then-else, you can properly consider phi nodes in different
     136                 :             :    blocks for equivalence.
     137                 :             :    3. We could value number vuses in more cases, particularly, whole
     138                 :             :    structure copies.
     139                 :             : */
     140                 :             : 
     141                 :             : /* There's no BB_EXECUTABLE but we can use BB_VISITED.  */
     142                 :             : #define BB_EXECUTABLE BB_VISITED
     143                 :             : 
     144                 :             : static vn_lookup_kind default_vn_walk_kind;
     145                 :             : 
     146                 :             : /* vn_nary_op hashtable helpers.  */
     147                 :             : 
     148                 :             : struct vn_nary_op_hasher : nofree_ptr_hash <vn_nary_op_s>
     149                 :             : {
     150                 :             :   typedef vn_nary_op_s *compare_type;
     151                 :             :   static inline hashval_t hash (const vn_nary_op_s *);
     152                 :             :   static inline bool equal (const vn_nary_op_s *, const vn_nary_op_s *);
     153                 :             : };
     154                 :             : 
     155                 :             : /* Return the computed hashcode for nary operation P1.  */
     156                 :             : 
     157                 :             : inline hashval_t
     158                 :   763181468 : vn_nary_op_hasher::hash (const vn_nary_op_s *vno1)
     159                 :             : {
     160                 :   763181468 :   return vno1->hashcode;
     161                 :             : }
     162                 :             : 
     163                 :             : /* Compare nary operations P1 and P2 and return true if they are
     164                 :             :    equivalent.  */
     165                 :             : 
     166                 :             : inline bool
     167                 :   968655197 : vn_nary_op_hasher::equal (const vn_nary_op_s *vno1, const vn_nary_op_s *vno2)
     168                 :             : {
     169                 :   968655197 :   return vno1 == vno2 || vn_nary_op_eq (vno1, vno2);
     170                 :             : }
     171                 :             : 
     172                 :             : typedef hash_table<vn_nary_op_hasher> vn_nary_op_table_type;
     173                 :             : typedef vn_nary_op_table_type::iterator vn_nary_op_iterator_type;
     174                 :             : 
     175                 :             : 
     176                 :             : /* vn_phi hashtable helpers.  */
     177                 :             : 
     178                 :             : static int
     179                 :             : vn_phi_eq (const_vn_phi_t const vp1, const_vn_phi_t const vp2);
     180                 :             : 
     181                 :             : struct vn_phi_hasher : nofree_ptr_hash <vn_phi_s>
     182                 :             : {
     183                 :             :   static inline hashval_t hash (const vn_phi_s *);
     184                 :             :   static inline bool equal (const vn_phi_s *, const vn_phi_s *);
     185                 :             : };
     186                 :             : 
     187                 :             : /* Return the computed hashcode for phi operation P1.  */
     188                 :             : 
     189                 :             : inline hashval_t
     190                 :    27181681 : vn_phi_hasher::hash (const vn_phi_s *vp1)
     191                 :             : {
     192                 :    27181681 :   return vp1->hashcode;
     193                 :             : }
     194                 :             : 
     195                 :             : /* Compare two phi entries for equality, ignoring VN_TOP arguments.  */
     196                 :             : 
     197                 :             : inline bool
     198                 :    48783013 : vn_phi_hasher::equal (const vn_phi_s *vp1, const vn_phi_s *vp2)
     199                 :             : {
     200                 :    48783013 :   return vp1 == vp2 || vn_phi_eq (vp1, vp2);
     201                 :             : }
     202                 :             : 
     203                 :             : typedef hash_table<vn_phi_hasher> vn_phi_table_type;
     204                 :             : typedef vn_phi_table_type::iterator vn_phi_iterator_type;
     205                 :             : 
     206                 :             : 
     207                 :             : /* Compare two reference operands P1 and P2 for equality.  Return true if
     208                 :             :    they are equal, and false otherwise.  */
     209                 :             : 
     210                 :             : static int
     211                 :    23482024 : vn_reference_op_eq (const void *p1, const void *p2)
     212                 :             : {
     213                 :    23482024 :   const_vn_reference_op_t const vro1 = (const_vn_reference_op_t) p1;
     214                 :    23482024 :   const_vn_reference_op_t const vro2 = (const_vn_reference_op_t) p2;
     215                 :             : 
     216                 :    23482024 :   return (vro1->opcode == vro2->opcode
     217                 :             :           /* We do not care for differences in type qualification.  */
     218                 :    23480164 :           && (vro1->type == vro2->type
     219                 :     1102743 :               || (vro1->type && vro2->type
     220                 :     1102743 :                   && types_compatible_p (TYPE_MAIN_VARIANT (vro1->type),
     221                 :     1102743 :                                          TYPE_MAIN_VARIANT (vro2->type))))
     222                 :    22517743 :           && expressions_equal_p (vro1->op0, vro2->op0)
     223                 :    22504088 :           && expressions_equal_p (vro1->op1, vro2->op1)
     224                 :    22504088 :           && expressions_equal_p (vro1->op2, vro2->op2)
     225                 :    45986112 :           && (vro1->opcode != CALL_EXPR || vro1->clique == vro2->clique));
     226                 :             : }
     227                 :             : 
     228                 :             : /* Free a reference operation structure VP.  */
     229                 :             : 
     230                 :             : static inline void
     231                 :           0 : free_reference (vn_reference_s *vr)
     232                 :             : {
     233                 :           0 :   vr->operands.release ();
     234                 :             : }
     235                 :             : 
     236                 :             : 
     237                 :             : /* vn_reference hashtable helpers.  */
     238                 :             : 
     239                 :             : struct vn_reference_hasher : nofree_ptr_hash <vn_reference_s>
     240                 :             : {
     241                 :             :   static inline hashval_t hash (const vn_reference_s *);
     242                 :             :   static inline bool equal (const vn_reference_s *, const vn_reference_s *);
     243                 :             : };
     244                 :             : 
     245                 :             : /* Return the hashcode for a given reference operation P1.  */
     246                 :             : 
     247                 :             : inline hashval_t
     248                 :  3747505317 : vn_reference_hasher::hash (const vn_reference_s *vr1)
     249                 :             : {
     250                 :  3747505317 :   return vr1->hashcode;
     251                 :             : }
     252                 :             : 
     253                 :             : inline bool
     254                 :  4454756759 : vn_reference_hasher::equal (const vn_reference_s *v, const vn_reference_s *c)
     255                 :             : {
     256                 :  4454756759 :   return v == c || vn_reference_eq (v, c);
     257                 :             : }
     258                 :             : 
     259                 :             : typedef hash_table<vn_reference_hasher> vn_reference_table_type;
     260                 :             : typedef vn_reference_table_type::iterator vn_reference_iterator_type;
     261                 :             : 
     262                 :             : /* Pretty-print OPS to OUTFILE.  */
     263                 :             : 
     264                 :             : void
     265                 :         305 : print_vn_reference_ops (FILE *outfile, const vec<vn_reference_op_s> ops)
     266                 :             : {
     267                 :         305 :   vn_reference_op_t vro;
     268                 :         305 :   unsigned int i;
     269                 :         305 :   fprintf (outfile, "{");
     270                 :        1346 :   for (i = 0; ops.iterate (i, &vro); i++)
     271                 :             :     {
     272                 :        1041 :       bool closebrace = false;
     273                 :        1041 :       if (vro->opcode != SSA_NAME
     274                 :         839 :           && TREE_CODE_CLASS (vro->opcode) != tcc_declaration)
     275                 :             :         {
     276                 :         839 :           fprintf (outfile, "%s", get_tree_code_name (vro->opcode));
     277                 :         839 :           if (vro->op0 || vro->opcode == CALL_EXPR)
     278                 :             :             {
     279                 :         839 :               fprintf (outfile, "<");
     280                 :         839 :               closebrace = true;
     281                 :             :             }
     282                 :             :         }
     283                 :        1041 :       if (vro->op0 || vro->opcode == CALL_EXPR)
     284                 :             :         {
     285                 :        1041 :           if (!vro->op0)
     286                 :           0 :             fprintf (outfile, internal_fn_name ((internal_fn)vro->clique));
     287                 :             :           else
     288                 :        1041 :             print_generic_expr (outfile, vro->op0);
     289                 :        1041 :           if (vro->op1)
     290                 :             :             {
     291                 :         173 :               fprintf (outfile, ",");
     292                 :         173 :               print_generic_expr (outfile, vro->op1);
     293                 :             :             }
     294                 :        1041 :           if (vro->op2)
     295                 :             :             {
     296                 :         173 :               fprintf (outfile, ",");
     297                 :         173 :               print_generic_expr (outfile, vro->op2);
     298                 :             :             }
     299                 :             :         }
     300                 :        1041 :       if (closebrace)
     301                 :         839 :         fprintf (outfile, ">");
     302                 :        1041 :       if (i != ops.length () - 1)
     303                 :         736 :         fprintf (outfile, ",");
     304                 :             :     }
     305                 :         305 :   fprintf (outfile, "}");
     306                 :         305 : }
     307                 :             : 
     308                 :             : DEBUG_FUNCTION void
     309                 :           0 : debug_vn_reference_ops (const vec<vn_reference_op_s> ops)
     310                 :             : {
     311                 :           0 :   print_vn_reference_ops (stderr, ops);
     312                 :           0 :   fputc ('\n', stderr);
     313                 :           0 : }
     314                 :             : 
     315                 :             : /* The set of VN hashtables.  */
     316                 :             : 
     317                 :             : typedef struct vn_tables_s
     318                 :             : {
     319                 :             :   vn_nary_op_table_type *nary;
     320                 :             :   vn_phi_table_type *phis;
     321                 :             :   vn_reference_table_type *references;
     322                 :             : } *vn_tables_t;
     323                 :             : 
     324                 :             : 
     325                 :             : /* vn_constant hashtable helpers.  */
     326                 :             : 
     327                 :             : struct vn_constant_hasher : free_ptr_hash <vn_constant_s>
     328                 :             : {
     329                 :             :   static inline hashval_t hash (const vn_constant_s *);
     330                 :             :   static inline bool equal (const vn_constant_s *, const vn_constant_s *);
     331                 :             : };
     332                 :             : 
     333                 :             : /* Hash table hash function for vn_constant_t.  */
     334                 :             : 
     335                 :             : inline hashval_t
     336                 :    12135563 : vn_constant_hasher::hash (const vn_constant_s *vc1)
     337                 :             : {
     338                 :    12135563 :   return vc1->hashcode;
     339                 :             : }
     340                 :             : 
     341                 :             : /* Hash table equality function for vn_constant_t.  */
     342                 :             : 
     343                 :             : inline bool
     344                 :    14666987 : vn_constant_hasher::equal (const vn_constant_s *vc1, const vn_constant_s *vc2)
     345                 :             : {
     346                 :    14666987 :   if (vc1->hashcode != vc2->hashcode)
     347                 :             :     return false;
     348                 :             : 
     349                 :     2231226 :   return vn_constant_eq_with_type (vc1->constant, vc2->constant);
     350                 :             : }
     351                 :             : 
     352                 :             : static hash_table<vn_constant_hasher> *constant_to_value_id;
     353                 :             : 
     354                 :             : 
     355                 :             : /* Obstack we allocate the vn-tables elements from.  */
     356                 :             : static obstack vn_tables_obstack;
     357                 :             : /* Special obstack we never unwind.  */
     358                 :             : static obstack vn_tables_insert_obstack;
     359                 :             : 
     360                 :             : static vn_reference_t last_inserted_ref;
     361                 :             : static vn_phi_t last_inserted_phi;
     362                 :             : static vn_nary_op_t last_inserted_nary;
     363                 :             : static vn_ssa_aux_t last_pushed_avail;
     364                 :             : 
     365                 :             : /* Valid hashtables storing information we have proven to be
     366                 :             :    correct.  */
     367                 :             : static vn_tables_t valid_info;
     368                 :             : 
     369                 :             : /* Global RPO state for access from hooks.  */
     370                 :             : static class eliminate_dom_walker *rpo_avail;
     371                 :             : basic_block vn_context_bb;
     372                 :             : 
     373                 :             : 
     374                 :             : /* Valueization hook for simplify_replace_tree.  Valueize NAME if it is
     375                 :             :    an SSA name, otherwise just return it.  */
     376                 :             : tree (*vn_valueize) (tree);
     377                 :             : static tree
     378                 :       77932 : vn_valueize_for_srt (tree t, void* context ATTRIBUTE_UNUSED)
     379                 :             : {
     380                 :       77932 :   basic_block saved_vn_context_bb = vn_context_bb;
     381                 :             :   /* Look for sth available at the definition block of the argument.
     382                 :             :      This avoids inconsistencies between availability there which
     383                 :             :      decides if the stmt can be removed and availability at the
     384                 :             :      use site.  The SSA property ensures that things available
     385                 :             :      at the definition are also available at uses.  */
     386                 :       77932 :   if (!SSA_NAME_IS_DEFAULT_DEF (t))
     387                 :       75130 :     vn_context_bb = gimple_bb (SSA_NAME_DEF_STMT (t));
     388                 :       77932 :   tree res = vn_valueize (t);
     389                 :       77932 :   vn_context_bb = saved_vn_context_bb;
     390                 :       77932 :   return res;
     391                 :             : }
     392                 :             : 
     393                 :             : 
     394                 :             : /* This represents the top of the VN lattice, which is the universal
     395                 :             :    value.  */
     396                 :             : 
     397                 :             : tree VN_TOP;
     398                 :             : 
     399                 :             : /* Unique counter for our value ids.  */
     400                 :             : 
     401                 :             : static unsigned int next_value_id;
     402                 :             : static int next_constant_value_id;
     403                 :             : 
     404                 :             : 
     405                 :             : /* Table of vn_ssa_aux_t's, one per ssa_name.  The vn_ssa_aux_t objects
     406                 :             :    are allocated on an obstack for locality reasons, and to free them
     407                 :             :    without looping over the vec.  */
     408                 :             : 
     409                 :             : struct vn_ssa_aux_hasher : typed_noop_remove <vn_ssa_aux_t>
     410                 :             : {
     411                 :             :   typedef vn_ssa_aux_t value_type;
     412                 :             :   typedef tree compare_type;
     413                 :             :   static inline hashval_t hash (const value_type &);
     414                 :             :   static inline bool equal (const value_type &, const compare_type &);
     415                 :             :   static inline void mark_deleted (value_type &) {}
     416                 :             :   static const bool empty_zero_p = true;
     417                 :           0 :   static inline void mark_empty (value_type &e) { e = NULL; }
     418                 :             :   static inline bool is_deleted (value_type &) { return false; }
     419                 : >12858*10^7 :   static inline bool is_empty (value_type &e) { return e == NULL; }
     420                 :             : };
     421                 :             : 
     422                 :             : hashval_t
     423                 : 42314206859 : vn_ssa_aux_hasher::hash (const value_type &entry)
     424                 :             : {
     425                 : 42314206859 :   return SSA_NAME_VERSION (entry->name);
     426                 :             : }
     427                 :             : 
     428                 :             : bool
     429                 : 48389930578 : vn_ssa_aux_hasher::equal (const value_type &entry, const compare_type &name)
     430                 :             : {
     431                 : 48389930578 :   return name == entry->name;
     432                 :             : }
     433                 :             : 
     434                 :             : static hash_table<vn_ssa_aux_hasher> *vn_ssa_aux_hash;
     435                 :             : typedef hash_table<vn_ssa_aux_hasher>::iterator vn_ssa_aux_iterator_type;
     436                 :             : static struct obstack vn_ssa_aux_obstack;
     437                 :             : 
     438                 :             : static vn_nary_op_t vn_nary_op_insert_stmt (gimple *, tree);
     439                 :             : static vn_nary_op_t vn_nary_op_insert_into (vn_nary_op_t,
     440                 :             :                                             vn_nary_op_table_type *);
     441                 :             : static void init_vn_nary_op_from_pieces (vn_nary_op_t, unsigned int,
     442                 :             :                                          enum tree_code, tree, tree *);
     443                 :             : static tree vn_lookup_simplify_result (gimple_match_op *);
     444                 :             : static vn_reference_t vn_reference_lookup_or_insert_for_pieces
     445                 :             :           (tree, alias_set_type, alias_set_type, poly_int64, poly_int64, tree,
     446                 :             :            vec<vn_reference_op_s, va_heap>, tree);
     447                 :             : 
     448                 :             : /* Return whether there is value numbering information for a given SSA name.  */
     449                 :             : 
     450                 :             : bool
     451                 :     5219317 : has_VN_INFO (tree name)
     452                 :             : {
     453                 :     5219317 :   return vn_ssa_aux_hash->find_with_hash (name, SSA_NAME_VERSION (name));
     454                 :             : }
     455                 :             : 
     456                 :             : vn_ssa_aux_t
     457                 :  3595238169 : VN_INFO (tree name)
     458                 :             : {
     459                 :  3595238169 :   vn_ssa_aux_t *res
     460                 :  3595238169 :     = vn_ssa_aux_hash->find_slot_with_hash (name, SSA_NAME_VERSION (name),
     461                 :             :                                             INSERT);
     462                 :  3595238169 :   if (*res != NULL)
     463                 :             :     return *res;
     464                 :             : 
     465                 :   174332755 :   vn_ssa_aux_t newinfo = *res = XOBNEW (&vn_ssa_aux_obstack, struct vn_ssa_aux);
     466                 :   174332755 :   memset (newinfo, 0, sizeof (struct vn_ssa_aux));
     467                 :   174332755 :   newinfo->name = name;
     468                 :   174332755 :   newinfo->valnum = VN_TOP;
     469                 :             :   /* We are using the visited flag to handle uses with defs not within the
     470                 :             :      region being value-numbered.  */
     471                 :   174332755 :   newinfo->visited = false;
     472                 :             : 
     473                 :             :   /* Given we create the VN_INFOs on-demand now we have to do initialization
     474                 :             :      different than VN_TOP here.  */
     475                 :   174332755 :   if (SSA_NAME_IS_DEFAULT_DEF (name))
     476                 :     9370233 :     switch (TREE_CODE (SSA_NAME_VAR (name)))
     477                 :             :       {
     478                 :     1667974 :       case VAR_DECL:
     479                 :             :         /* All undefined vars are VARYING.  */
     480                 :     1667974 :         newinfo->valnum = name;
     481                 :     1667974 :         newinfo->visited = true;
     482                 :     1667974 :         break;
     483                 :             : 
     484                 :     7639513 :       case PARM_DECL:
     485                 :             :         /* Parameters are VARYING but we can record a condition
     486                 :             :            if we know it is a non-NULL pointer.  */
     487                 :     7639513 :         newinfo->visited = true;
     488                 :     7639513 :         newinfo->valnum = name;
     489                 :    11690494 :         if (POINTER_TYPE_P (TREE_TYPE (name))
     490                 :     8792275 :             && nonnull_arg_p (SSA_NAME_VAR (name)))
     491                 :             :           {
     492                 :     2430443 :             tree ops[2];
     493                 :     2430443 :             ops[0] = name;
     494                 :     2430443 :             ops[1] = build_int_cst (TREE_TYPE (name), 0);
     495                 :     2430443 :             vn_nary_op_t nary;
     496                 :             :             /* Allocate from non-unwinding stack.  */
     497                 :     2430443 :             nary = alloc_vn_nary_op_noinit (2, &vn_tables_insert_obstack);
     498                 :     2430443 :             init_vn_nary_op_from_pieces (nary, 2, NE_EXPR,
     499                 :             :                                          boolean_type_node, ops);
     500                 :     2430443 :             nary->predicated_values = 0;
     501                 :     2430443 :             nary->u.result = boolean_true_node;
     502                 :     2430443 :             vn_nary_op_insert_into (nary, valid_info->nary);
     503                 :     2430443 :             gcc_assert (nary->unwind_to == NULL);
     504                 :             :             /* Also do not link it into the undo chain.  */
     505                 :     2430443 :             last_inserted_nary = nary->next;
     506                 :     2430443 :             nary->next = (vn_nary_op_t)(void *)-1;
     507                 :     2430443 :             nary = alloc_vn_nary_op_noinit (2, &vn_tables_insert_obstack);
     508                 :     2430443 :             init_vn_nary_op_from_pieces (nary, 2, EQ_EXPR,
     509                 :             :                                          boolean_type_node, ops);
     510                 :     2430443 :             nary->predicated_values = 0;
     511                 :     2430443 :             nary->u.result = boolean_false_node;
     512                 :     2430443 :             vn_nary_op_insert_into (nary, valid_info->nary);
     513                 :     2430443 :             gcc_assert (nary->unwind_to == NULL);
     514                 :     2430443 :             last_inserted_nary = nary->next;
     515                 :     2430443 :             nary->next = (vn_nary_op_t)(void *)-1;
     516                 :     2430443 :             if (dump_file && (dump_flags & TDF_DETAILS))
     517                 :             :               {
     518                 :          35 :                 fprintf (dump_file, "Recording ");
     519                 :          35 :                 print_generic_expr (dump_file, name, TDF_SLIM);
     520                 :          35 :                 fprintf (dump_file, " != 0\n");
     521                 :             :               }
     522                 :             :           }
     523                 :             :         break;
     524                 :             : 
     525                 :       62746 :       case RESULT_DECL:
     526                 :             :         /* If the result is passed by invisible reference the default
     527                 :             :            def is initialized, otherwise it's uninitialized.  Still
     528                 :             :            undefined is varying.  */
     529                 :       62746 :         newinfo->visited = true;
     530                 :       62746 :         newinfo->valnum = name;
     531                 :       62746 :         break;
     532                 :             : 
     533                 :           0 :       default:
     534                 :           0 :         gcc_unreachable ();
     535                 :             :       }
     536                 :             :   return newinfo;
     537                 :             : }
     538                 :             : 
     539                 :             : /* Return the SSA value of X.  */
     540                 :             : 
     541                 :             : inline tree
     542                 :  3363324380 : SSA_VAL (tree x, bool *visited = NULL)
     543                 :             : {
     544                 :  3363324380 :   vn_ssa_aux_t tem = vn_ssa_aux_hash->find_with_hash (x, SSA_NAME_VERSION (x));
     545                 :  3363324380 :   if (visited)
     546                 :  1351181710 :     *visited = tem && tem->visited;
     547                 :  3363324380 :   return tem && tem->visited ? tem->valnum : x;
     548                 :             : }
     549                 :             : 
     550                 :             : /* Return the SSA value of the VUSE x, supporting released VDEFs
     551                 :             :    during elimination which will value-number the VDEF to the
     552                 :             :    associated VUSE (but not substitute in the whole lattice).  */
     553                 :             : 
     554                 :             : static inline tree
     555                 :  1238293768 : vuse_ssa_val (tree x)
     556                 :             : {
     557                 :  1238293768 :   if (!x)
     558                 :             :     return NULL_TREE;
     559                 :             : 
     560                 :  1234741731 :   do
     561                 :             :     {
     562                 :  1234741731 :       x = SSA_VAL (x);
     563                 :  1234741731 :       gcc_assert (x != VN_TOP);
     564                 :             :     }
     565                 :  1234741731 :   while (SSA_NAME_IN_FREE_LIST (x));
     566                 :             : 
     567                 :             :   return x;
     568                 :             : }
     569                 :             : 
     570                 :             : /* Similar to the above but used as callback for walk_non_aliased_vuses
     571                 :             :    and thus should stop at unvisited VUSE to not walk across region
     572                 :             :    boundaries.  */
     573                 :             : 
     574                 :             : static tree
     575                 :  1038056349 : vuse_valueize (tree vuse)
     576                 :             : {
     577                 :  1038056349 :   do
     578                 :             :     {
     579                 :  1038056349 :       bool visited;
     580                 :  1038056349 :       vuse = SSA_VAL (vuse, &visited);
     581                 :  1038056349 :       if (!visited)
     582                 :    15313785 :         return NULL_TREE;
     583                 :  1022742564 :       gcc_assert (vuse != VN_TOP);
     584                 :             :     }
     585                 :  1022742564 :   while (SSA_NAME_IN_FREE_LIST (vuse));
     586                 :             :   return vuse;
     587                 :             : }
     588                 :             : 
     589                 :             : 
     590                 :             : /* Return the vn_kind the expression computed by the stmt should be
     591                 :             :    associated with.  */
     592                 :             : 
     593                 :             : enum vn_kind
     594                 :   102710821 : vn_get_stmt_kind (gimple *stmt)
     595                 :             : {
     596                 :   102710821 :   switch (gimple_code (stmt))
     597                 :             :     {
     598                 :             :     case GIMPLE_CALL:
     599                 :             :       return VN_REFERENCE;
     600                 :             :     case GIMPLE_PHI:
     601                 :             :       return VN_PHI;
     602                 :   102710821 :     case GIMPLE_ASSIGN:
     603                 :   102710821 :       {
     604                 :   102710821 :         enum tree_code code = gimple_assign_rhs_code (stmt);
     605                 :   102710821 :         tree rhs1 = gimple_assign_rhs1 (stmt);
     606                 :   102710821 :         switch (get_gimple_rhs_class (code))
     607                 :             :           {
     608                 :             :           case GIMPLE_UNARY_RHS:
     609                 :             :           case GIMPLE_BINARY_RHS:
     610                 :             :           case GIMPLE_TERNARY_RHS:
     611                 :             :             return VN_NARY;
     612                 :    48661248 :           case GIMPLE_SINGLE_RHS:
     613                 :    48661248 :             switch (TREE_CODE_CLASS (code))
     614                 :             :               {
     615                 :    36579963 :               case tcc_reference:
     616                 :             :                 /* VOP-less references can go through unary case.  */
     617                 :    36579963 :                 if ((code == REALPART_EXPR
     618                 :             :                      || code == IMAGPART_EXPR
     619                 :    36579963 :                      || code == VIEW_CONVERT_EXPR
     620                 :    36579963 :                      || code == BIT_FIELD_REF)
     621                 :    36579963 :                     && (TREE_CODE (TREE_OPERAND (rhs1, 0)) == SSA_NAME
     622                 :      728297 :                         || is_gimple_min_invariant (TREE_OPERAND (rhs1, 0))))
     623                 :     1936828 :                   return VN_NARY;
     624                 :             : 
     625                 :             :                 /* Fallthrough.  */
     626                 :             :               case tcc_declaration:
     627                 :             :                 return VN_REFERENCE;
     628                 :             : 
     629                 :             :               case tcc_constant:
     630                 :             :                 return VN_CONSTANT;
     631                 :             : 
     632                 :     6038521 :               default:
     633                 :     6038521 :                 if (code == ADDR_EXPR)
     634                 :     3368545 :                   return (is_gimple_min_invariant (rhs1)
     635                 :     3368545 :                           ? VN_CONSTANT : VN_REFERENCE);
     636                 :     2669976 :                 else if (code == CONSTRUCTOR)
     637                 :             :                   return VN_NARY;
     638                 :             :                 return VN_NONE;
     639                 :             :               }
     640                 :             :           default:
     641                 :             :             return VN_NONE;
     642                 :             :           }
     643                 :             :       }
     644                 :             :     default:
     645                 :             :       return VN_NONE;
     646                 :             :     }
     647                 :             : }
     648                 :             : 
     649                 :             : /* Lookup a value id for CONSTANT and return it.  If it does not
     650                 :             :    exist returns 0.  */
     651                 :             : 
     652                 :             : unsigned int
     653                 :           0 : get_constant_value_id (tree constant)
     654                 :             : {
     655                 :           0 :   vn_constant_s **slot;
     656                 :           0 :   struct vn_constant_s vc;
     657                 :             : 
     658                 :           0 :   vc.hashcode = vn_hash_constant_with_type (constant);
     659                 :           0 :   vc.constant = constant;
     660                 :           0 :   slot = constant_to_value_id->find_slot (&vc, NO_INSERT);
     661                 :           0 :   if (slot)
     662                 :           0 :     return (*slot)->value_id;
     663                 :             :   return 0;
     664                 :             : }
     665                 :             : 
     666                 :             : /* Lookup a value id for CONSTANT, and if it does not exist, create a
     667                 :             :    new one and return it.  If it does exist, return it.  */
     668                 :             : 
     669                 :             : unsigned int
     670                 :    28810161 : get_or_alloc_constant_value_id (tree constant)
     671                 :             : {
     672                 :    28810161 :   vn_constant_s **slot;
     673                 :    28810161 :   struct vn_constant_s vc;
     674                 :    28810161 :   vn_constant_t vcp;
     675                 :             : 
     676                 :             :   /* If the hashtable isn't initialized we're not running from PRE and thus
     677                 :             :      do not need value-ids.  */
     678                 :    28810161 :   if (!constant_to_value_id)
     679                 :             :     return 0;
     680                 :             : 
     681                 :     4777222 :   vc.hashcode = vn_hash_constant_with_type (constant);
     682                 :     4777222 :   vc.constant = constant;
     683                 :     4777222 :   slot = constant_to_value_id->find_slot (&vc, INSERT);
     684                 :     4777222 :   if (*slot)
     685                 :     2215212 :     return (*slot)->value_id;
     686                 :             : 
     687                 :     2562010 :   vcp = XNEW (struct vn_constant_s);
     688                 :     2562010 :   vcp->hashcode = vc.hashcode;
     689                 :     2562010 :   vcp->constant = constant;
     690                 :     2562010 :   vcp->value_id = get_next_constant_value_id ();
     691                 :     2562010 :   *slot = vcp;
     692                 :     2562010 :   return vcp->value_id;
     693                 :             : }
     694                 :             : 
     695                 :             : /* Compute the hash for a reference operand VRO1.  */
     696                 :             : 
     697                 :             : static void
     698                 :   133744311 : vn_reference_op_compute_hash (const vn_reference_op_t vro1, inchash::hash &hstate)
     699                 :             : {
     700                 :   133744311 :   hstate.add_int (vro1->opcode);
     701                 :   133744311 :   if (vro1->opcode == CALL_EXPR && !vro1->op0)
     702                 :      517213 :     hstate.add_int (vro1->clique);
     703                 :   133744311 :   if (vro1->op0)
     704                 :   127429365 :     inchash::add_expr (vro1->op0, hstate);
     705                 :   133744311 :   if (vro1->op1)
     706                 :    11316838 :     inchash::add_expr (vro1->op1, hstate);
     707                 :   133744311 :   if (vro1->op2)
     708                 :    13169014 :     inchash::add_expr (vro1->op2, hstate);
     709                 :   133744311 : }
     710                 :             : 
     711                 :             : /* Compute a hash for the reference operation VR1 and return it.  */
     712                 :             : 
     713                 :             : static hashval_t
     714                 :   200446820 : vn_reference_compute_hash (const vn_reference_t vr1)
     715                 :             : {
     716                 :   200446820 :   inchash::hash hstate;
     717                 :   200446820 :   hashval_t result;
     718                 :   200446820 :   int i;
     719                 :   200446820 :   vn_reference_op_t vro;
     720                 :   200446820 :   poly_offset_int off = -1;
     721                 :   200446820 :   bool deref = false;
     722                 :             : 
     723                 :   815094626 :   FOR_EACH_VEC_ELT (vr1->operands, i, vro)
     724                 :             :     {
     725                 :   614647806 :       if (vro->opcode == MEM_REF)
     726                 :             :         deref = true;
     727                 :   424832190 :       else if (vro->opcode != ADDR_EXPR)
     728                 :   296643740 :         deref = false;
     729                 :   614647806 :       if (maybe_ne (vro->off, -1))
     730                 :             :         {
     731                 :   360837551 :           if (known_eq (off, -1))
     732                 :   191959586 :             off = 0;
     733                 :   614647806 :           off += vro->off;
     734                 :             :         }
     735                 :             :       else
     736                 :             :         {
     737                 :   253810255 :           if (maybe_ne (off, -1)
     738                 :   253810255 :               && maybe_ne (off, 0))
     739                 :   102042767 :             hstate.add_poly_hwi (off.force_shwi ());
     740                 :   253810255 :           off = -1;
     741                 :   253810255 :           if (deref
     742                 :   120303536 :               && vro->opcode == ADDR_EXPR)
     743                 :             :             {
     744                 :   120065944 :               if (vro->op0)
     745                 :             :                 {
     746                 :   120065944 :                   tree op = TREE_OPERAND (vro->op0, 0);
     747                 :   120065944 :                   hstate.add_int (TREE_CODE (op));
     748                 :   120065944 :                   inchash::add_expr (op, hstate);
     749                 :             :                 }
     750                 :             :             }
     751                 :             :           else
     752                 :   133744311 :             vn_reference_op_compute_hash (vro, hstate);
     753                 :             :         }
     754                 :             :     }
     755                 :             :   /* Do not hash vr1->offset or vr1->max_size, we want to get collisions
     756                 :             :      to be able to identify compatible results.  */
     757                 :   200446820 :   result = hstate.end ();
     758                 :             :   /* ??? We would ICE later if we hash instead of adding that in. */
     759                 :   200446820 :   if (vr1->vuse)
     760                 :   195536525 :     result += SSA_NAME_VERSION (vr1->vuse);
     761                 :             : 
     762                 :   200446820 :   return result;
     763                 :             : }
     764                 :             : 
     765                 :             : /* Return true if reference operations VR1 and VR2 are equivalent.  This
     766                 :             :    means they have the same set of operands and vuses.  */
     767                 :             : 
     768                 :             : bool
     769                 :  4449804054 : vn_reference_eq (const_vn_reference_t const vr1, const_vn_reference_t const vr2)
     770                 :             : {
     771                 :  4449804054 :   unsigned i, j;
     772                 :             : 
     773                 :             :   /* Early out if this is not a hash collision.  */
     774                 :  4449804054 :   if (vr1->hashcode != vr2->hashcode)
     775                 :             :     return false;
     776                 :             : 
     777                 :             :   /* The VOP needs to be the same.  */
     778                 :    18151242 :   if (vr1->vuse != vr2->vuse)
     779                 :             :     return false;
     780                 :             : 
     781                 :             :   /* The offset/max_size used for the ao_ref during lookup has to be
     782                 :             :      the same.  */
     783                 :    18150741 :   if (maybe_ne (vr1->offset, vr2->offset)
     784                 :    18150741 :       || maybe_ne (vr1->max_size, vr2->max_size))
     785                 :             :     {
     786                 :             :       /* But nothing known in the prevailing entry is OK to be used.  */
     787                 :     6789924 :       if (maybe_ne (vr1->offset, 0) || known_size_p (vr1->max_size))
     788                 :             :         return false;
     789                 :             :     }
     790                 :             : 
     791                 :             :   /* If the operands are the same we are done.  */
     792                 :    36219964 :   if (vr1->operands == vr2->operands)
     793                 :             :     return true;
     794                 :             : 
     795                 :    17279776 :   if (!vr1->type || !vr2->type)
     796                 :             :     {
     797                 :      585361 :       if (vr1->type != vr2->type)
     798                 :             :         return false;
     799                 :             :     }
     800                 :    16694415 :   else if (vr1->type == vr2->type)
     801                 :             :     ;
     802                 :     2194794 :   else if (COMPLETE_TYPE_P (vr1->type) != COMPLETE_TYPE_P (vr2->type)
     803                 :     2194794 :            || (COMPLETE_TYPE_P (vr1->type)
     804                 :     2194794 :                && !expressions_equal_p (TYPE_SIZE (vr1->type),
     805                 :     2194794 :                                         TYPE_SIZE (vr2->type))))
     806                 :      796032 :     return false;
     807                 :     1398762 :   else if (vr1->operands[0].opcode == CALL_EXPR
     808                 :     1398762 :            && !types_compatible_p (vr1->type, vr2->type))
     809                 :             :     return false;
     810                 :     1398762 :   else if (INTEGRAL_TYPE_P (vr1->type)
     811                 :      581779 :            && INTEGRAL_TYPE_P (vr2->type))
     812                 :             :     {
     813                 :      540492 :       if (TYPE_PRECISION (vr1->type) != TYPE_PRECISION (vr2->type))
     814                 :             :         return false;
     815                 :             :     }
     816                 :      858270 :   else if (INTEGRAL_TYPE_P (vr1->type)
     817                 :      858270 :            && (TYPE_PRECISION (vr1->type)
     818                 :       41287 :                != TREE_INT_CST_LOW (TYPE_SIZE (vr1->type))))
     819                 :             :     return false;
     820                 :      858136 :   else if (INTEGRAL_TYPE_P (vr2->type)
     821                 :      858136 :            && (TYPE_PRECISION (vr2->type)
     822                 :        9797 :                != TREE_INT_CST_LOW (TYPE_SIZE (vr2->type))))
     823                 :             :     return false;
     824                 :        7410 :   else if (VECTOR_BOOLEAN_TYPE_P (vr1->type)
     825                 :      857542 :            && VECTOR_BOOLEAN_TYPE_P (vr2->type))
     826                 :             :     {
     827                 :             :       /* Vector boolean types can have padding, verify we are dealing with
     828                 :             :          the same number of elements, aka the precision of the types.
     829                 :             :          For example, In most architecture the precision_size of vbool*_t
     830                 :             :          types are caculated like below:
     831                 :             :          precision_size = type_size * 8
     832                 :             : 
     833                 :             :          Unfortunately, the RISC-V will adjust the precision_size for the
     834                 :             :          vbool*_t in order to align the ISA as below:
     835                 :             :          type_size      = [1, 1, 1, 1,  2,  4,  8]
     836                 :             :          precision_size = [1, 2, 4, 8, 16, 32, 64]
     837                 :             : 
     838                 :             :          Then the precision_size of RISC-V vbool*_t will not be the multiple
     839                 :             :          of the type_size.  We take care of this case consolidated here.  */
     840                 :           0 :       if (maybe_ne (TYPE_VECTOR_SUBPARTS (vr1->type),
     841                 :           0 :                     TYPE_VECTOR_SUBPARTS (vr2->type)))
     842                 :             :         return false;
     843                 :             :     }
     844                 :      857542 :   else if (TYPE_MODE (vr1->type) != TYPE_MODE (vr2->type)
     845                 :      857542 :            && (!mode_can_transfer_bits (TYPE_MODE (vr1->type))
     846                 :       43884 :                || !mode_can_transfer_bits (TYPE_MODE (vr2->type))))
     847                 :        1058 :     return false;
     848                 :             : 
     849                 :             :   i = 0;
     850                 :             :   j = 0;
     851                 :    19798488 :   do
     852                 :             :     {
     853                 :    19798488 :       poly_offset_int off1 = 0, off2 = 0;
     854                 :    19798488 :       vn_reference_op_t vro1, vro2;
     855                 :    19798488 :       vn_reference_op_s tem1, tem2;
     856                 :    19798488 :       bool deref1 = false, deref2 = false;
     857                 :    19798488 :       bool reverse1 = false, reverse2 = false;
     858                 :    67354642 :       for (; vr1->operands.iterate (i, &vro1); i++)
     859                 :             :         {
     860                 :    47556154 :           if (vro1->opcode == MEM_REF)
     861                 :             :             deref1 = true;
     862                 :             :           /* Do not look through a storage order barrier.  */
     863                 :    32526344 :           else if (vro1->opcode == VIEW_CONVERT_EXPR && vro1->reverse)
     864                 :        6039 :             return false;
     865                 :    47556154 :           reverse1 |= vro1->reverse;
     866                 :    47556154 :           if (known_eq (vro1->off, -1))
     867                 :             :             break;
     868                 :    27757666 :           off1 += vro1->off;
     869                 :             :         }
     870                 :    47724028 :       for (; vr2->operands.iterate (j, &vro2); j++)
     871                 :             :         {
     872                 :    47724028 :           if (vro2->opcode == MEM_REF)
     873                 :             :             deref2 = true;
     874                 :             :           /* Do not look through a storage order barrier.  */
     875                 :    32694208 :           else if (vro2->opcode == VIEW_CONVERT_EXPR && vro2->reverse)
     876                 :             :             return false;
     877                 :    47724028 :           reverse2 |= vro2->reverse;
     878                 :    47724028 :           if (known_eq (vro2->off, -1))
     879                 :             :             break;
     880                 :    27925540 :           off2 += vro2->off;
     881                 :             :         }
     882                 :    19798488 :       if (maybe_ne (off1, off2) || reverse1 != reverse2)
     883                 :             :         return false;
     884                 :    19798442 :       if (deref1 && vro1->opcode == ADDR_EXPR)
     885                 :             :         {
     886                 :     8356875 :           memset (&tem1, 0, sizeof (tem1));
     887                 :     8356875 :           tem1.op0 = TREE_OPERAND (vro1->op0, 0);
     888                 :     8356875 :           tem1.type = TREE_TYPE (tem1.op0);
     889                 :     8356875 :           tem1.opcode = TREE_CODE (tem1.op0);
     890                 :     8356875 :           vro1 = &tem1;
     891                 :     8356875 :           deref1 = false;
     892                 :             :         }
     893                 :    19798442 :       if (deref2 && vro2->opcode == ADDR_EXPR)
     894                 :             :         {
     895                 :     8356885 :           memset (&tem2, 0, sizeof (tem2));
     896                 :     8356885 :           tem2.op0 = TREE_OPERAND (vro2->op0, 0);
     897                 :     8356885 :           tem2.type = TREE_TYPE (tem2.op0);
     898                 :     8356885 :           tem2.opcode = TREE_CODE (tem2.op0);
     899                 :     8356885 :           vro2 = &tem2;
     900                 :     8356885 :           deref2 = false;
     901                 :             :         }
     902                 :    19798442 :       if (deref1 != deref2)
     903                 :             :         return false;
     904                 :    19798442 :       if (!vn_reference_op_eq (vro1, vro2))
     905                 :             :         return false;
     906                 :    19792449 :       ++j;
     907                 :    19792449 :       ++i;
     908                 :             :     }
     909                 :    39584898 :   while (vr1->operands.length () != i
     910                 :    59377347 :          || vr2->operands.length () != j);
     911                 :             : 
     912                 :             :   return true;
     913                 :             : }
     914                 :             : 
     915                 :             : /* Copy the operations present in load/store REF into RESULT, a vector of
     916                 :             :    vn_reference_op_s's.  */
     917                 :             : 
     918                 :             : static void
     919                 :   222349801 : copy_reference_ops_from_ref (tree ref, vec<vn_reference_op_s> *result)
     920                 :             : {
     921                 :             :   /* For non-calls, store the information that makes up the address.  */
     922                 :   222349801 :   tree orig = ref;
     923                 :   770303902 :   while (ref)
     924                 :             :     {
     925                 :   547954101 :       vn_reference_op_s temp;
     926                 :             : 
     927                 :   547954101 :       memset (&temp, 0, sizeof (temp));
     928                 :   547954101 :       temp.type = TREE_TYPE (ref);
     929                 :   547954101 :       temp.opcode = TREE_CODE (ref);
     930                 :   547954101 :       temp.off = -1;
     931                 :             : 
     932                 :   547954101 :       switch (temp.opcode)
     933                 :             :         {
     934                 :    15099622 :         case MODIFY_EXPR:
     935                 :    15099622 :           temp.op0 = TREE_OPERAND (ref, 1);
     936                 :    15099622 :           break;
     937                 :         137 :         case WITH_SIZE_EXPR:
     938                 :         137 :           temp.op0 = TREE_OPERAND (ref, 1);
     939                 :         137 :           temp.off = 0;
     940                 :         137 :           break;
     941                 :   117943876 :         case MEM_REF:
     942                 :             :           /* The base address gets its own vn_reference_op_s structure.  */
     943                 :   117943876 :           temp.op0 = TREE_OPERAND (ref, 1);
     944                 :   117943876 :           if (!mem_ref_offset (ref).to_shwi (&temp.off))
     945                 :           0 :             temp.off = -1;
     946                 :   117943876 :           temp.clique = MR_DEPENDENCE_CLIQUE (ref);
     947                 :   117943876 :           temp.base = MR_DEPENDENCE_BASE (ref);
     948                 :   117943876 :           temp.reverse = REF_REVERSE_STORAGE_ORDER (ref);
     949                 :   117943876 :           break;
     950                 :     2519609 :         case TARGET_MEM_REF:
     951                 :             :           /* The base address gets its own vn_reference_op_s structure.  */
     952                 :     2519609 :           temp.op0 = TMR_INDEX (ref);
     953                 :     2519609 :           temp.op1 = TMR_STEP (ref);
     954                 :     2519609 :           temp.op2 = TMR_OFFSET (ref);
     955                 :     2519609 :           temp.clique = MR_DEPENDENCE_CLIQUE (ref);
     956                 :     2519609 :           temp.base = MR_DEPENDENCE_BASE (ref);
     957                 :     2519609 :           result->safe_push (temp);
     958                 :     2519609 :           memset (&temp, 0, sizeof (temp));
     959                 :     2519609 :           temp.type = NULL_TREE;
     960                 :     2519609 :           temp.opcode = ERROR_MARK;
     961                 :     2519609 :           temp.op0 = TMR_INDEX2 (ref);
     962                 :     2519609 :           temp.off = -1;
     963                 :     2519609 :           break;
     964                 :      855813 :         case BIT_FIELD_REF:
     965                 :             :           /* Record bits, position and storage order.  */
     966                 :      855813 :           temp.op0 = TREE_OPERAND (ref, 1);
     967                 :      855813 :           temp.op1 = TREE_OPERAND (ref, 2);
     968                 :     1710866 :           if (!multiple_p (bit_field_offset (ref), BITS_PER_UNIT, &temp.off))
     969                 :         760 :             temp.off = -1;
     970                 :      855813 :           temp.reverse = REF_REVERSE_STORAGE_ORDER (ref);
     971                 :      855813 :           break;
     972                 :   145105825 :         case COMPONENT_REF:
     973                 :             :           /* The field decl is enough to unambiguously specify the field,
     974                 :             :              so use its type here.  */
     975                 :   145105825 :           temp.type = TREE_TYPE (TREE_OPERAND (ref, 1));
     976                 :   145105825 :           temp.op0 = TREE_OPERAND (ref, 1);
     977                 :   145105825 :           temp.op1 = TREE_OPERAND (ref, 2);
     978                 :   290209306 :           temp.reverse = (AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (ref, 0)))
     979                 :   290209023 :                           && TYPE_REVERSE_STORAGE_ORDER
     980                 :             :                                (TREE_TYPE (TREE_OPERAND (ref, 0))));
     981                 :   145105825 :           {
     982                 :   145105825 :             tree this_offset = component_ref_field_offset (ref);
     983                 :   145105825 :             if (this_offset
     984                 :   145105825 :                 && poly_int_tree_p (this_offset))
     985                 :             :               {
     986                 :   145103731 :                 tree bit_offset = DECL_FIELD_BIT_OFFSET (TREE_OPERAND (ref, 1));
     987                 :   145103731 :                 if (TREE_INT_CST_LOW (bit_offset) % BITS_PER_UNIT == 0)
     988                 :             :                   {
     989                 :   144448149 :                     poly_offset_int off
     990                 :   144448149 :                       = (wi::to_poly_offset (this_offset)
     991                 :   144448149 :                          + (wi::to_offset (bit_offset) >> LOG2_BITS_PER_UNIT));
     992                 :             :                     /* Prohibit value-numbering zero offset components
     993                 :             :                        of addresses the same before the pass folding
     994                 :             :                        __builtin_object_size had a chance to run.  Likewise
     995                 :             :                        for components of zero size at arbitrary offset.  */
     996                 :   144448149 :                     if (TREE_CODE (orig) != ADDR_EXPR
     997                 :     5105797 :                         || (TYPE_SIZE (temp.type)
     998                 :     5093323 :                             && integer_nonzerop (TYPE_SIZE (temp.type))
     999                 :     6602969 :                             && maybe_ne (off, 0))
    1000                 :   147526907 :                         || (cfun->curr_properties & PROP_objsz))
    1001                 :   142936372 :                       off.to_shwi (&temp.off);
    1002                 :             :                   }
    1003                 :             :               }
    1004                 :             :           }
    1005                 :             :           break;
    1006                 :    37332069 :         case ARRAY_RANGE_REF:
    1007                 :    37332069 :         case ARRAY_REF:
    1008                 :    37332069 :           {
    1009                 :    37332069 :             tree eltype = TREE_TYPE (TREE_TYPE (TREE_OPERAND (ref, 0)));
    1010                 :             :             /* Record index as operand.  */
    1011                 :    37332069 :             temp.op0 = TREE_OPERAND (ref, 1);
    1012                 :             :             /* Always record lower bounds and element size.  */
    1013                 :    37332069 :             temp.op1 = array_ref_low_bound (ref);
    1014                 :             :             /* But record element size in units of the type alignment.  */
    1015                 :    37332069 :             temp.op2 = TREE_OPERAND (ref, 3);
    1016                 :    37332069 :             temp.align = eltype->type_common.align;
    1017                 :    37332069 :             if (! temp.op2)
    1018                 :    37123591 :               temp.op2 = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (eltype),
    1019                 :             :                                      size_int (TYPE_ALIGN_UNIT (eltype)));
    1020                 :             :             /* Prohibit value-numbering addresses of one-after-the-last
    1021                 :             :                element ARRAY_REFs the same as addresses of other components
    1022                 :             :                before the pass folding __builtin_object_size had a chance
    1023                 :             :                to run.  */
    1024                 :    37332069 :             bool avoid_oob = true;
    1025                 :    37332069 :             if (TREE_CODE (orig) != ADDR_EXPR
    1026                 :      448781 :                 || cfun->curr_properties & PROP_objsz)
    1027                 :             :               avoid_oob = false;
    1028                 :      215549 :             else if (poly_int_tree_p (temp.op0))
    1029                 :             :               {
    1030                 :       73219 :                 tree ub = array_ref_up_bound (ref);
    1031                 :       73219 :                 if (ub
    1032                 :       71593 :                     && poly_int_tree_p (ub)
    1033                 :             :                     /* ???  The C frontend for T[0] uses [0:] and the
    1034                 :             :                        C++ frontend [0:-1U].  See layout_type for how
    1035                 :             :                        awkward this is.  */
    1036                 :       63694 :                     && !integer_minus_onep (ub)
    1037                 :      144812 :                     && known_le (wi::to_poly_offset (temp.op0),
    1038                 :             :                                  wi::to_poly_offset (ub)))
    1039                 :       62847 :                   avoid_oob = false;
    1040                 :             :               }
    1041                 :    37332069 :             if (poly_int_tree_p (temp.op0)
    1042                 :    21637101 :                 && poly_int_tree_p (temp.op1)
    1043                 :    21637077 :                 && TREE_CODE (temp.op2) == INTEGER_CST
    1044                 :    58908960 :                 && !avoid_oob)
    1045                 :             :               {
    1046                 :    43134748 :                 poly_offset_int off = ((wi::to_poly_offset (temp.op0)
    1047                 :    64702122 :                                         - wi::to_poly_offset (temp.op1))
    1048                 :    43134748 :                                        * wi::to_offset (temp.op2)
    1049                 :    21567374 :                                        * vn_ref_op_align_unit (&temp));
    1050                 :    21567374 :                 off.to_shwi (&temp.off);
    1051                 :             :               }
    1052                 :    37332069 :             temp.reverse = (AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (ref, 0)))
    1053                 :    37332069 :                             && TYPE_REVERSE_STORAGE_ORDER
    1054                 :             :                                  (TREE_TYPE (TREE_OPERAND (ref, 0))));
    1055                 :             :           }
    1056                 :    37332069 :           break;
    1057                 :    81379785 :         case VAR_DECL:
    1058                 :    81379785 :           if (DECL_HARD_REGISTER (ref))
    1059                 :             :             {
    1060                 :       20195 :               temp.op0 = ref;
    1061                 :       20195 :               break;
    1062                 :             :             }
    1063                 :             :           /* Fallthru.  */
    1064                 :    84799490 :         case PARM_DECL:
    1065                 :    84799490 :         case CONST_DECL:
    1066                 :    84799490 :         case RESULT_DECL:
    1067                 :             :           /* Canonicalize decls to MEM[&decl] which is what we end up with
    1068                 :             :              when valueizing MEM[ptr] with ptr = &decl.  */
    1069                 :    84799490 :           temp.opcode = MEM_REF;
    1070                 :    84799490 :           temp.op0 = build_int_cst (build_pointer_type (TREE_TYPE (ref)), 0);
    1071                 :    84799490 :           temp.off = 0;
    1072                 :    84799490 :           result->safe_push (temp);
    1073                 :    84799490 :           temp.opcode = ADDR_EXPR;
    1074                 :    84799490 :           temp.op0 = build1 (ADDR_EXPR, TREE_TYPE (temp.op0), ref);
    1075                 :    84799490 :           temp.type = TREE_TYPE (temp.op0);
    1076                 :    84799490 :           temp.off = -1;
    1077                 :    84799490 :           break;
    1078                 :    94775425 :         case STRING_CST:
    1079                 :    94775425 :         case INTEGER_CST:
    1080                 :    94775425 :         case POLY_INT_CST:
    1081                 :    94775425 :         case COMPLEX_CST:
    1082                 :    94775425 :         case VECTOR_CST:
    1083                 :    94775425 :         case REAL_CST:
    1084                 :    94775425 :         case FIXED_CST:
    1085                 :    94775425 :         case CONSTRUCTOR:
    1086                 :    94775425 :         case SSA_NAME:
    1087                 :    94775425 :           temp.op0 = ref;
    1088                 :    94775425 :           break;
    1089                 :    47063786 :         case ADDR_EXPR:
    1090                 :    47063786 :           if (is_gimple_min_invariant (ref))
    1091                 :             :             {
    1092                 :    42754691 :               temp.op0 = ref;
    1093                 :    42754691 :               break;
    1094                 :             :             }
    1095                 :             :           break;
    1096                 :             :           /* These are only interesting for their operands, their
    1097                 :             :              existence, and their type.  They will never be the last
    1098                 :             :              ref in the chain of references (IE they require an
    1099                 :             :              operand), so we don't have to put anything
    1100                 :             :              for op* as it will be handled by the iteration  */
    1101                 :      472905 :         case REALPART_EXPR:
    1102                 :      472905 :           temp.off = 0;
    1103                 :      472905 :           break;
    1104                 :     1485704 :         case VIEW_CONVERT_EXPR:
    1105                 :     1485704 :           temp.off = 0;
    1106                 :     1485704 :           temp.reverse = storage_order_barrier_p (ref);
    1107                 :     1485704 :           break;
    1108                 :      479645 :         case IMAGPART_EXPR:
    1109                 :             :           /* This is only interesting for its constant offset.  */
    1110                 :      479645 :           temp.off = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (ref)));
    1111                 :      479645 :           break;
    1112                 :           0 :         default:
    1113                 :           0 :           gcc_unreachable ();
    1114                 :             :         }
    1115                 :   547954101 :       result->safe_push (temp);
    1116                 :             : 
    1117                 :   547954101 :       if (REFERENCE_CLASS_P (ref)
    1118                 :   241758655 :           || TREE_CODE (ref) == MODIFY_EXPR
    1119                 :   226659033 :           || TREE_CODE (ref) == WITH_SIZE_EXPR
    1120                 :   774612997 :           || (TREE_CODE (ref) == ADDR_EXPR
    1121                 :    47063786 :               && !is_gimple_min_invariant (ref)))
    1122                 :   325604300 :         ref = TREE_OPERAND (ref, 0);
    1123                 :             :       else
    1124                 :             :         ref = NULL_TREE;
    1125                 :             :     }
    1126                 :   222349801 : }
    1127                 :             : 
    1128                 :             : /* Build a alias-oracle reference abstraction in *REF from the vn_reference
    1129                 :             :    operands in *OPS, the reference alias set SET and the reference type TYPE.
    1130                 :             :    Return true if something useful was produced.  */
    1131                 :             : 
    1132                 :             : bool
    1133                 :    14175130 : ao_ref_init_from_vn_reference (ao_ref *ref,
    1134                 :             :                                alias_set_type set, alias_set_type base_set,
    1135                 :             :                                tree type, const vec<vn_reference_op_s> &ops)
    1136                 :             : {
    1137                 :    14175130 :   unsigned i;
    1138                 :    14175130 :   tree base = NULL_TREE;
    1139                 :    14175130 :   tree *op0_p = &base;
    1140                 :    14175130 :   poly_offset_int offset = 0;
    1141                 :    14175130 :   poly_offset_int max_size;
    1142                 :    14175130 :   poly_offset_int size = -1;
    1143                 :    14175130 :   tree size_tree = NULL_TREE;
    1144                 :             : 
    1145                 :             :   /* We don't handle calls.  */
    1146                 :    14175130 :   if (!type)
    1147                 :             :     return false;
    1148                 :             : 
    1149                 :    14175130 :   machine_mode mode = TYPE_MODE (type);
    1150                 :    14175130 :   if (mode == BLKmode)
    1151                 :      254386 :     size_tree = TYPE_SIZE (type);
    1152                 :             :   else
    1153                 :    27841488 :     size = GET_MODE_BITSIZE (mode);
    1154                 :    13920744 :   if (size_tree != NULL_TREE
    1155                 :      254386 :       && poly_int_tree_p (size_tree))
    1156                 :      254386 :     size = wi::to_poly_offset (size_tree);
    1157                 :             : 
    1158                 :             :   /* Lower the final access size from the outermost expression.  */
    1159                 :    14175130 :   const_vn_reference_op_t cst_op = &ops[0];
    1160                 :             :   /* Cast away constness for the sake of the const-unsafe
    1161                 :             :      FOR_EACH_VEC_ELT().  */
    1162                 :    14175130 :   vn_reference_op_t op = const_cast<vn_reference_op_t>(cst_op);
    1163                 :    14175130 :   size_tree = NULL_TREE;
    1164                 :    14175130 :   if (op->opcode == COMPONENT_REF)
    1165                 :     4900269 :     size_tree = DECL_SIZE (op->op0);
    1166                 :     9274861 :   else if (op->opcode == BIT_FIELD_REF)
    1167                 :       86555 :     size_tree = op->op0;
    1168                 :     4986824 :   if (size_tree != NULL_TREE
    1169                 :     4986824 :       && poly_int_tree_p (size_tree)
    1170                 :     9973648 :       && (!known_size_p (size)
    1171                 :    14175130 :           || known_lt (wi::to_poly_offset (size_tree), size)))
    1172                 :       55861 :     size = wi::to_poly_offset (size_tree);
    1173                 :             : 
    1174                 :             :   /* Initially, maxsize is the same as the accessed element size.
    1175                 :             :      In the following it will only grow (or become -1).  */
    1176                 :    14175130 :   max_size = size;
    1177                 :             : 
    1178                 :             :   /* Compute cumulative bit-offset for nested component-refs and array-refs,
    1179                 :             :      and find the ultimate containing object.  */
    1180                 :    54500422 :   FOR_EACH_VEC_ELT (ops, i, op)
    1181                 :             :     {
    1182                 :    40467476 :       switch (op->opcode)
    1183                 :             :         {
    1184                 :             :         case CALL_EXPR:
    1185                 :             :           return false;
    1186                 :             : 
    1187                 :             :         /* Record the base objects.  */
    1188                 :    13735038 :         case MEM_REF:
    1189                 :    13735038 :           *op0_p = build2 (MEM_REF, op->type,
    1190                 :             :                            NULL_TREE, op->op0);
    1191                 :    13735038 :           MR_DEPENDENCE_CLIQUE (*op0_p) = op->clique;
    1192                 :    13735038 :           MR_DEPENDENCE_BASE (*op0_p) = op->base;
    1193                 :    13735038 :           op0_p = &TREE_OPERAND (*op0_p, 0);
    1194                 :    13735038 :           break;
    1195                 :             : 
    1196                 :      297380 :         case TARGET_MEM_REF:
    1197                 :      892140 :           *op0_p = build5 (TARGET_MEM_REF, op->type,
    1198                 :             :                            NULL_TREE, op->op2, op->op0,
    1199                 :      297380 :                            op->op1, ops[i+1].op0);
    1200                 :      297380 :           MR_DEPENDENCE_CLIQUE (*op0_p) = op->clique;
    1201                 :      297380 :           MR_DEPENDENCE_BASE (*op0_p) = op->base;
    1202                 :      297380 :           op0_p = &TREE_OPERAND (*op0_p, 0);
    1203                 :      297380 :           ++i;
    1204                 :      297380 :           break;
    1205                 :             : 
    1206                 :             :         /* Unwrap some of the wrapped decls.  */
    1207                 :     6693491 :         case ADDR_EXPR:
    1208                 :             :           /* Apart from ADDR_EXPR arguments to MEM_REF.  */
    1209                 :     6693491 :           if (base != NULL_TREE
    1210                 :     6693491 :               && TREE_CODE (base) == MEM_REF
    1211                 :     6658878 :               && op->op0
    1212                 :    13352369 :               && DECL_P (TREE_OPERAND (op->op0, 0)))
    1213                 :             :             {
    1214                 :     6655869 :               const_vn_reference_op_t pop = &ops[i-1];
    1215                 :     6655869 :               base = TREE_OPERAND (op->op0, 0);
    1216                 :     6655869 :               if (known_eq (pop->off, -1))
    1217                 :             :                 {
    1218                 :          55 :                   max_size = -1;
    1219                 :          55 :                   offset = 0;
    1220                 :             :                 }
    1221                 :             :               else
    1222                 :    19967442 :                 offset += poly_offset_int (pop->off) * BITS_PER_UNIT;
    1223                 :             :               op0_p = NULL;
    1224                 :             :               break;
    1225                 :             :             }
    1226                 :             :           /* Fallthru.  */
    1227                 :     7377077 :         case PARM_DECL:
    1228                 :     7377077 :         case CONST_DECL:
    1229                 :     7377077 :         case RESULT_DECL:
    1230                 :             :           /* ???  We shouldn't see these, but un-canonicalize what
    1231                 :             :              copy_reference_ops_from_ref does when visiting MEM_REF.  */
    1232                 :     7377077 :         case VAR_DECL:
    1233                 :             :           /* ???  And for this only have DECL_HARD_REGISTER.  */
    1234                 :     7377077 :         case STRING_CST:
    1235                 :             :           /* This can show up in ARRAY_REF bases.  */
    1236                 :     7377077 :         case INTEGER_CST:
    1237                 :     7377077 :         case SSA_NAME:
    1238                 :     7377077 :           *op0_p = op->op0;
    1239                 :     7377077 :           op0_p = NULL;
    1240                 :     7377077 :           break;
    1241                 :             : 
    1242                 :             :         /* And now the usual component-reference style ops.  */
    1243                 :       86555 :         case BIT_FIELD_REF:
    1244                 :       86555 :           offset += wi::to_poly_offset (op->op1);
    1245                 :       86555 :           break;
    1246                 :             : 
    1247                 :     8008694 :         case COMPONENT_REF:
    1248                 :     8008694 :           {
    1249                 :     8008694 :             tree field = op->op0;
    1250                 :             :             /* We do not have a complete COMPONENT_REF tree here so we
    1251                 :             :                cannot use component_ref_field_offset.  Do the interesting
    1252                 :             :                parts manually.  */
    1253                 :     8008694 :             tree this_offset = DECL_FIELD_OFFSET (field);
    1254                 :             : 
    1255                 :     8008694 :             if (op->op1 || !poly_int_tree_p (this_offset))
    1256                 :         236 :               max_size = -1;
    1257                 :             :             else
    1258                 :             :               {
    1259                 :     8008458 :                 poly_offset_int woffset = (wi::to_poly_offset (this_offset)
    1260                 :     8008458 :                                            << LOG2_BITS_PER_UNIT);
    1261                 :     8008458 :                 woffset += wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
    1262                 :     8008458 :                 offset += woffset;
    1263                 :             :               }
    1264                 :             :             break;
    1265                 :             :           }
    1266                 :             : 
    1267                 :     2875579 :         case ARRAY_RANGE_REF:
    1268                 :     2875579 :         case ARRAY_REF:
    1269                 :             :           /* Use the recorded constant offset.  */
    1270                 :     2875579 :           if (maybe_eq (op->off, -1))
    1271                 :     1001347 :             max_size = -1;
    1272                 :             :           else
    1273                 :     5622696 :             offset += poly_offset_int (op->off) * BITS_PER_UNIT;
    1274                 :             :           break;
    1275                 :             : 
    1276                 :             :         case REALPART_EXPR:
    1277                 :             :           break;
    1278                 :             : 
    1279                 :             :         case IMAGPART_EXPR:
    1280                 :    40325292 :           offset += size;
    1281                 :             :           break;
    1282                 :             : 
    1283                 :             :         case VIEW_CONVERT_EXPR:
    1284                 :             :           break;
    1285                 :             : 
    1286                 :             :         case POLY_INT_CST:
    1287                 :             :         case COMPLEX_CST:
    1288                 :             :         case VECTOR_CST:
    1289                 :             :         case REAL_CST:
    1290                 :             :         case FIXED_CST:
    1291                 :             :         case CONSTRUCTOR:
    1292                 :             :           return false;
    1293                 :             : 
    1294                 :             :         default:
    1295                 :             :           return false;
    1296                 :             :         }
    1297                 :             :     }
    1298                 :             : 
    1299                 :    14032946 :   if (base == NULL_TREE)
    1300                 :             :     return false;
    1301                 :             : 
    1302                 :    14032946 :   ref->ref = NULL_TREE;
    1303                 :    14032946 :   ref->base = base;
    1304                 :    14032946 :   ref->ref_alias_set = set;
    1305                 :    14032946 :   ref->base_alias_set = base_set;
    1306                 :             :   /* We discount volatiles from value-numbering elsewhere.  */
    1307                 :    14032946 :   ref->volatile_p = false;
    1308                 :             : 
    1309                 :    14032946 :   if (!size.to_shwi (&ref->size) || maybe_lt (ref->size, 0))
    1310                 :             :     {
    1311                 :           0 :       ref->offset = 0;
    1312                 :           0 :       ref->size = -1;
    1313                 :           0 :       ref->max_size = -1;
    1314                 :           0 :       return true;
    1315                 :             :     }
    1316                 :             : 
    1317                 :    14032946 :   if (!offset.to_shwi (&ref->offset))
    1318                 :             :     {
    1319                 :          26 :       ref->offset = 0;
    1320                 :          26 :       ref->max_size = -1;
    1321                 :          26 :       return true;
    1322                 :             :     }
    1323                 :             : 
    1324                 :    14032920 :   if (!max_size.to_shwi (&ref->max_size) || maybe_lt (ref->max_size, 0))
    1325                 :      858301 :     ref->max_size = -1;
    1326                 :             : 
    1327                 :             :   return true;
    1328                 :             : }
    1329                 :             : 
    1330                 :             : /* Copy the operations present in load/store/call REF into RESULT, a vector of
    1331                 :             :    vn_reference_op_s's.  */
    1332                 :             : 
    1333                 :             : static void
    1334                 :     9233941 : copy_reference_ops_from_call (gcall *call,
    1335                 :             :                               vec<vn_reference_op_s> *result)
    1336                 :             : {
    1337                 :     9233941 :   vn_reference_op_s temp;
    1338                 :     9233941 :   unsigned i;
    1339                 :     9233941 :   tree lhs = gimple_call_lhs (call);
    1340                 :     9233941 :   int lr;
    1341                 :             : 
    1342                 :             :   /* If 2 calls have a different non-ssa lhs, vdef value numbers should be
    1343                 :             :      different.  By adding the lhs here in the vector, we ensure that the
    1344                 :             :      hashcode is different, guaranteeing a different value number.  */
    1345                 :     9233941 :   if (lhs && TREE_CODE (lhs) != SSA_NAME)
    1346                 :             :     {
    1347                 :      442774 :       memset (&temp, 0, sizeof (temp));
    1348                 :      442774 :       temp.opcode = MODIFY_EXPR;
    1349                 :      442774 :       temp.type = TREE_TYPE (lhs);
    1350                 :      442774 :       temp.op0 = lhs;
    1351                 :      442774 :       temp.off = -1;
    1352                 :      442774 :       result->safe_push (temp);
    1353                 :             :     }
    1354                 :             : 
    1355                 :             :   /* Copy the type, opcode, function, static chain and EH region, if any.  */
    1356                 :     9233941 :   memset (&temp, 0, sizeof (temp));
    1357                 :     9233941 :   temp.type = gimple_call_fntype (call);
    1358                 :     9233941 :   temp.opcode = CALL_EXPR;
    1359                 :     9233941 :   temp.op0 = gimple_call_fn (call);
    1360                 :     9233941 :   if (gimple_call_internal_p (call))
    1361                 :      504764 :     temp.clique = gimple_call_internal_fn (call);
    1362                 :     9233941 :   temp.op1 = gimple_call_chain (call);
    1363                 :     9233941 :   if (stmt_could_throw_p (cfun, call) && (lr = lookup_stmt_eh_lp (call)) > 0)
    1364                 :      748125 :     temp.op2 = size_int (lr);
    1365                 :     9233941 :   temp.off = -1;
    1366                 :     9233941 :   result->safe_push (temp);
    1367                 :             : 
    1368                 :             :   /* Copy the call arguments.  As they can be references as well,
    1369                 :             :      just chain them together.  */
    1370                 :    27107922 :   for (i = 0; i < gimple_call_num_args (call); ++i)
    1371                 :             :     {
    1372                 :    17873981 :       tree callarg = gimple_call_arg (call, i);
    1373                 :    17873981 :       copy_reference_ops_from_ref (callarg, result);
    1374                 :             :     }
    1375                 :     9233941 : }
    1376                 :             : 
    1377                 :             : /* Fold *& at position *I_P in a vn_reference_op_s vector *OPS.  Updates
    1378                 :             :    *I_P to point to the last element of the replacement.  */
    1379                 :             : static bool
    1380                 :   131175703 : vn_reference_fold_indirect (vec<vn_reference_op_s> *ops,
    1381                 :             :                             unsigned int *i_p)
    1382                 :             : {
    1383                 :   131175703 :   unsigned int i = *i_p;
    1384                 :   131175703 :   vn_reference_op_t op = &(*ops)[i];
    1385                 :   131175703 :   vn_reference_op_t mem_op = &(*ops)[i - 1];
    1386                 :   131175703 :   tree addr_base;
    1387                 :   131175703 :   poly_int64 addr_offset = 0;
    1388                 :             : 
    1389                 :             :   /* The only thing we have to do is from &OBJ.foo.bar add the offset
    1390                 :             :      from .foo.bar to the preceding MEM_REF offset and replace the
    1391                 :             :      address with &OBJ.  */
    1392                 :   131175703 :   addr_base = get_addr_base_and_unit_offset_1 (TREE_OPERAND (op->op0, 0),
    1393                 :             :                                                &addr_offset, vn_valueize);
    1394                 :   131175703 :   gcc_checking_assert (addr_base && TREE_CODE (addr_base) != MEM_REF);
    1395                 :   131175703 :   if (addr_base != TREE_OPERAND (op->op0, 0))
    1396                 :             :     {
    1397                 :      656513 :       poly_offset_int off
    1398                 :      656513 :         = (poly_offset_int::from (wi::to_poly_wide (mem_op->op0),
    1399                 :             :                                   SIGNED)
    1400                 :      656513 :            + addr_offset);
    1401                 :      656513 :       mem_op->op0 = wide_int_to_tree (TREE_TYPE (mem_op->op0), off);
    1402                 :      656513 :       op->op0 = build_fold_addr_expr (addr_base);
    1403                 :      656513 :       if (tree_fits_shwi_p (mem_op->op0))
    1404                 :      656444 :         mem_op->off = tree_to_shwi (mem_op->op0);
    1405                 :             :       else
    1406                 :          69 :         mem_op->off = -1;
    1407                 :      656513 :       return true;
    1408                 :             :     }
    1409                 :             :   return false;
    1410                 :             : }
    1411                 :             : 
    1412                 :             : /* Fold *& at position *I_P in a vn_reference_op_s vector *OPS.  Updates
    1413                 :             :    *I_P to point to the last element of the replacement.  */
    1414                 :             : static bool
    1415                 :    87041506 : vn_reference_maybe_forwprop_address (vec<vn_reference_op_s> *ops,
    1416                 :             :                                      unsigned int *i_p)
    1417                 :             : {
    1418                 :    87041506 :   bool changed = false;
    1419                 :    93575668 :   vn_reference_op_t op;
    1420                 :             : 
    1421                 :    93575668 :   do
    1422                 :             :     {
    1423                 :    93575668 :       unsigned int i = *i_p;
    1424                 :    93575668 :       op = &(*ops)[i];
    1425                 :    93575668 :       vn_reference_op_t mem_op = &(*ops)[i - 1];
    1426                 :    93575668 :       gimple *def_stmt;
    1427                 :    93575668 :       enum tree_code code;
    1428                 :    93575668 :       poly_offset_int off;
    1429                 :             : 
    1430                 :    93575668 :       def_stmt = SSA_NAME_DEF_STMT (op->op0);
    1431                 :    93575668 :       if (!is_gimple_assign (def_stmt))
    1432                 :    87039555 :         return changed;
    1433                 :             : 
    1434                 :    37013741 :       code = gimple_assign_rhs_code (def_stmt);
    1435                 :    37013741 :       if (code != ADDR_EXPR
    1436                 :    37013741 :           && code != POINTER_PLUS_EXPR)
    1437                 :             :         return changed;
    1438                 :             : 
    1439                 :    18773990 :       off = poly_offset_int::from (wi::to_poly_wide (mem_op->op0), SIGNED);
    1440                 :             : 
    1441                 :             :       /* The only thing we have to do is from &OBJ.foo.bar add the offset
    1442                 :             :          from .foo.bar to the preceding MEM_REF offset and replace the
    1443                 :             :          address with &OBJ.  */
    1444                 :    18773990 :       if (code == ADDR_EXPR)
    1445                 :             :         {
    1446                 :      931024 :           tree addr, addr_base;
    1447                 :      931024 :           poly_int64 addr_offset;
    1448                 :             : 
    1449                 :      931024 :           addr = gimple_assign_rhs1 (def_stmt);
    1450                 :      931024 :           addr_base = get_addr_base_and_unit_offset_1 (TREE_OPERAND (addr, 0),
    1451                 :             :                                                        &addr_offset,
    1452                 :             :                                                        vn_valueize);
    1453                 :             :           /* If that didn't work because the address isn't invariant propagate
    1454                 :             :              the reference tree from the address operation in case the current
    1455                 :             :              dereference isn't offsetted.  */
    1456                 :      931024 :           if (!addr_base
    1457                 :      269952 :               && *i_p == ops->length () - 1
    1458                 :      134976 :               && known_eq (off, 0)
    1459                 :             :               /* This makes us disable this transform for PRE where the
    1460                 :             :                  reference ops might be also used for code insertion which
    1461                 :             :                  is invalid.  */
    1462                 :     1015638 :               && default_vn_walk_kind == VN_WALKREWRITE)
    1463                 :             :             {
    1464                 :       84516 :               auto_vec<vn_reference_op_s, 32> tem;
    1465                 :       84516 :               copy_reference_ops_from_ref (TREE_OPERAND (addr, 0), &tem);
    1466                 :             :               /* Make sure to preserve TBAA info.  The only objects not
    1467                 :             :                  wrapped in MEM_REFs that can have their address taken are
    1468                 :             :                  STRING_CSTs.  */
    1469                 :       84516 :               if (tem.length () >= 2
    1470                 :       84516 :                   && tem[tem.length () - 2].opcode == MEM_REF)
    1471                 :             :                 {
    1472                 :       84501 :                   vn_reference_op_t new_mem_op = &tem[tem.length () - 2];
    1473                 :       84501 :                   new_mem_op->op0
    1474                 :       84501 :                       = wide_int_to_tree (TREE_TYPE (mem_op->op0),
    1475                 :      169002 :                                           wi::to_poly_wide (new_mem_op->op0));
    1476                 :             :                 }
    1477                 :             :               else
    1478                 :          15 :                 gcc_assert (tem.last ().opcode == STRING_CST);
    1479                 :       84516 :               ops->pop ();
    1480                 :       84516 :               ops->pop ();
    1481                 :       84516 :               ops->safe_splice (tem);
    1482                 :       84516 :               --*i_p;
    1483                 :       84516 :               return true;
    1484                 :       84516 :             }
    1485                 :      846508 :           if (!addr_base
    1486                 :      796048 :               || TREE_CODE (addr_base) != MEM_REF
    1487                 :     1640687 :               || (TREE_CODE (TREE_OPERAND (addr_base, 0)) == SSA_NAME
    1488                 :      792318 :                   && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (addr_base,
    1489                 :             :                                                                     0))))
    1490                 :             :             return changed;
    1491                 :             : 
    1492                 :      794179 :           off += addr_offset;
    1493                 :      794179 :           off += mem_ref_offset (addr_base);
    1494                 :      794179 :           op->op0 = TREE_OPERAND (addr_base, 0);
    1495                 :             :         }
    1496                 :             :       else
    1497                 :             :         {
    1498                 :    17842966 :           tree ptr, ptroff;
    1499                 :    17842966 :           ptr = gimple_assign_rhs1 (def_stmt);
    1500                 :    17842966 :           ptroff = gimple_assign_rhs2 (def_stmt);
    1501                 :    17842966 :           if (TREE_CODE (ptr) != SSA_NAME
    1502                 :    16137908 :               || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ptr)
    1503                 :             :               /* Make sure to not endlessly recurse.
    1504                 :             :                  See gcc.dg/tree-ssa/20040408-1.c for an example.  Can easily
    1505                 :             :                  happen when we value-number a PHI to its backedge value.  */
    1506                 :    16136494 :               || SSA_VAL (ptr) == op->op0
    1507                 :    33979460 :               || !poly_int_tree_p (ptroff))
    1508                 :    12101032 :             return changed;
    1509                 :             : 
    1510                 :     5741934 :           off += wi::to_poly_offset (ptroff);
    1511                 :     5741934 :           op->op0 = ptr;
    1512                 :             :         }
    1513                 :             : 
    1514                 :     6536113 :       mem_op->op0 = wide_int_to_tree (TREE_TYPE (mem_op->op0), off);
    1515                 :     6536113 :       if (tree_fits_shwi_p (mem_op->op0))
    1516                 :     6275089 :         mem_op->off = tree_to_shwi (mem_op->op0);
    1517                 :             :       else
    1518                 :      261024 :         mem_op->off = -1;
    1519                 :             :       /* ???  Can end up with endless recursion here!?
    1520                 :             :          gcc.c-torture/execute/strcmp-1.c  */
    1521                 :     6536113 :       if (TREE_CODE (op->op0) == SSA_NAME)
    1522                 :     6534252 :         op->op0 = SSA_VAL (op->op0);
    1523                 :     6536113 :       if (TREE_CODE (op->op0) != SSA_NAME)
    1524                 :        1951 :         op->opcode = TREE_CODE (op->op0);
    1525                 :             : 
    1526                 :     6536113 :       changed = true;
    1527                 :             :     }
    1528                 :             :   /* Tail-recurse.  */
    1529                 :     6536113 :   while (TREE_CODE (op->op0) == SSA_NAME);
    1530                 :             : 
    1531                 :             :   /* Fold a remaining *&.  */
    1532                 :        1951 :   if (TREE_CODE (op->op0) == ADDR_EXPR)
    1533                 :         261 :     vn_reference_fold_indirect (ops, i_p);
    1534                 :             : 
    1535                 :             :   return changed;
    1536                 :             : }
    1537                 :             : 
    1538                 :             : /* Optimize the reference REF to a constant if possible or return
    1539                 :             :    NULL_TREE if not.  */
    1540                 :             : 
    1541                 :             : tree
    1542                 :   110659455 : fully_constant_vn_reference_p (vn_reference_t ref)
    1543                 :             : {
    1544                 :   110659455 :   vec<vn_reference_op_s> operands = ref->operands;
    1545                 :   110659455 :   vn_reference_op_t op;
    1546                 :             : 
    1547                 :             :   /* Try to simplify the translated expression if it is
    1548                 :             :      a call to a builtin function with at most two arguments.  */
    1549                 :   110659455 :   op = &operands[0];
    1550                 :   110659455 :   if (op->opcode == CALL_EXPR
    1551                 :       84858 :       && (!op->op0
    1552                 :       78536 :           || (TREE_CODE (op->op0) == ADDR_EXPR
    1553                 :       78536 :               && TREE_CODE (TREE_OPERAND (op->op0, 0)) == FUNCTION_DECL
    1554                 :       78536 :               && fndecl_built_in_p (TREE_OPERAND (op->op0, 0),
    1555                 :             :                                     BUILT_IN_NORMAL)))
    1556                 :       68637 :       && operands.length () >= 2
    1557                 :   110728056 :       && operands.length () <= 3)
    1558                 :             :     {
    1559                 :       35582 :       vn_reference_op_t arg0, arg1 = NULL;
    1560                 :       35582 :       bool anyconst = false;
    1561                 :       35582 :       arg0 = &operands[1];
    1562                 :       35582 :       if (operands.length () > 2)
    1563                 :        4667 :         arg1 = &operands[2];
    1564                 :       35582 :       if (TREE_CODE_CLASS (arg0->opcode) == tcc_constant
    1565                 :       35582 :           || (arg0->opcode == ADDR_EXPR
    1566                 :       13456 :               && is_gimple_min_invariant (arg0->op0)))
    1567                 :             :         anyconst = true;
    1568                 :       35582 :       if (arg1
    1569                 :       35582 :           && (TREE_CODE_CLASS (arg1->opcode) == tcc_constant
    1570                 :        3858 :               || (arg1->opcode == ADDR_EXPR
    1571                 :         579 :                   && is_gimple_min_invariant (arg1->op0))))
    1572                 :             :         anyconst = true;
    1573                 :       34194 :       if (anyconst)
    1574                 :             :         {
    1575                 :       20857 :           combined_fn fn;
    1576                 :       20857 :           if (op->op0)
    1577                 :       20546 :             fn = as_combined_fn (DECL_FUNCTION_CODE
    1578                 :       20546 :                                         (TREE_OPERAND (op->op0, 0)));
    1579                 :             :           else
    1580                 :         311 :             fn = as_combined_fn ((internal_fn) op->clique);
    1581                 :       20857 :           tree folded;
    1582                 :       20857 :           if (arg1)
    1583                 :        1981 :             folded = fold_const_call (fn, ref->type, arg0->op0, arg1->op0);
    1584                 :             :           else
    1585                 :       18876 :             folded = fold_const_call (fn, ref->type, arg0->op0);
    1586                 :       20857 :           if (folded
    1587                 :       20857 :               && is_gimple_min_invariant (folded))
    1588                 :             :             return folded;
    1589                 :             :         }
    1590                 :             :     }
    1591                 :             : 
    1592                 :             :   /* Simplify reads from constants or constant initializers.  */
    1593                 :   110623873 :   else if (BITS_PER_UNIT == 8
    1594                 :   110623873 :            && ref->type
    1595                 :   110623873 :            && COMPLETE_TYPE_P (ref->type)
    1596                 :   221247704 :            && is_gimple_reg_type (ref->type))
    1597                 :             :     {
    1598                 :   105835898 :       poly_int64 off = 0;
    1599                 :   105835898 :       HOST_WIDE_INT size;
    1600                 :   105835898 :       if (INTEGRAL_TYPE_P (ref->type))
    1601                 :    53686224 :         size = TYPE_PRECISION (ref->type);
    1602                 :    52149674 :       else if (tree_fits_shwi_p (TYPE_SIZE (ref->type)))
    1603                 :    52149674 :         size = tree_to_shwi (TYPE_SIZE (ref->type));
    1604                 :             :       else
    1605                 :   110659455 :         return NULL_TREE;
    1606                 :   105835898 :       if (size % BITS_PER_UNIT != 0
    1607                 :   103809881 :           || size > MAX_BITSIZE_MODE_ANY_MODE)
    1608                 :             :         return NULL_TREE;
    1609                 :   103808568 :       size /= BITS_PER_UNIT;
    1610                 :   103808568 :       unsigned i;
    1611                 :   191657193 :       for (i = 0; i < operands.length (); ++i)
    1612                 :             :         {
    1613                 :   191657193 :           if (TREE_CODE_CLASS (operands[i].opcode) == tcc_constant)
    1614                 :             :             {
    1615                 :         309 :               ++i;
    1616                 :         309 :               break;
    1617                 :             :             }
    1618                 :   191656884 :           if (operands[i].reverse)
    1619                 :             :             return NULL_TREE;
    1620                 :   191648538 :           if (known_eq (operands[i].off, -1))
    1621                 :             :             return NULL_TREE;
    1622                 :   177870844 :           off += operands[i].off;
    1623                 :   177870844 :           if (operands[i].opcode == MEM_REF)
    1624                 :             :             {
    1625                 :    90022219 :               ++i;
    1626                 :    90022219 :               break;
    1627                 :             :             }
    1628                 :             :         }
    1629                 :    90022528 :       vn_reference_op_t base = &operands[--i];
    1630                 :    90022528 :       tree ctor = error_mark_node;
    1631                 :    90022528 :       tree decl = NULL_TREE;
    1632                 :    90022528 :       if (TREE_CODE_CLASS (base->opcode) == tcc_constant)
    1633                 :         309 :         ctor = base->op0;
    1634                 :    90022219 :       else if (base->opcode == MEM_REF
    1635                 :    90022219 :                && base[1].opcode == ADDR_EXPR
    1636                 :   148065136 :                && (VAR_P (TREE_OPERAND (base[1].op0, 0))
    1637                 :     3654371 :                    || TREE_CODE (TREE_OPERAND (base[1].op0, 0)) == CONST_DECL
    1638                 :     3654311 :                    || TREE_CODE (TREE_OPERAND (base[1].op0, 0)) == STRING_CST))
    1639                 :             :         {
    1640                 :    54393487 :           decl = TREE_OPERAND (base[1].op0, 0);
    1641                 :    54393487 :           if (TREE_CODE (decl) == STRING_CST)
    1642                 :             :             ctor = decl;
    1643                 :             :           else
    1644                 :    54388606 :             ctor = ctor_for_folding (decl);
    1645                 :             :         }
    1646                 :    90017647 :       if (ctor == NULL_TREE)
    1647                 :         379 :         return build_zero_cst (ref->type);
    1648                 :    90022149 :       else if (ctor != error_mark_node)
    1649                 :             :         {
    1650                 :      104690 :           HOST_WIDE_INT const_off;
    1651                 :      104690 :           if (decl)
    1652                 :             :             {
    1653                 :      208762 :               tree res = fold_ctor_reference (ref->type, ctor,
    1654                 :      104381 :                                               off * BITS_PER_UNIT,
    1655                 :      104381 :                                               size * BITS_PER_UNIT, decl);
    1656                 :      104381 :               if (res)
    1657                 :             :                 {
    1658                 :       53956 :                   STRIP_USELESS_TYPE_CONVERSION (res);
    1659                 :       53956 :                   if (is_gimple_min_invariant (res))
    1660                 :   110659455 :                     return res;
    1661                 :             :                 }
    1662                 :             :             }
    1663                 :         309 :           else if (off.is_constant (&const_off))
    1664                 :             :             {
    1665                 :         309 :               unsigned char buf[MAX_BITSIZE_MODE_ANY_MODE / BITS_PER_UNIT];
    1666                 :         309 :               int len = native_encode_expr (ctor, buf, size, const_off);
    1667                 :         309 :               if (len > 0)
    1668                 :         139 :                 return native_interpret_expr (ref->type, buf, len);
    1669                 :             :             }
    1670                 :             :         }
    1671                 :             :     }
    1672                 :             : 
    1673                 :             :   return NULL_TREE;
    1674                 :             : }
    1675                 :             : 
    1676                 :             : /* Return true if OPS contain a storage order barrier.  */
    1677                 :             : 
    1678                 :             : static bool
    1679                 :    58628241 : contains_storage_order_barrier_p (vec<vn_reference_op_s> ops)
    1680                 :             : {
    1681                 :    58628241 :   vn_reference_op_t op;
    1682                 :    58628241 :   unsigned i;
    1683                 :             : 
    1684                 :   229788254 :   FOR_EACH_VEC_ELT (ops, i, op)
    1685                 :   171160013 :     if (op->opcode == VIEW_CONVERT_EXPR && op->reverse)
    1686                 :             :       return true;
    1687                 :             : 
    1688                 :             :   return false;
    1689                 :             : }
    1690                 :             : 
    1691                 :             : /* Return true if OPS represent an access with reverse storage order.  */
    1692                 :             : 
    1693                 :             : static bool
    1694                 :    58636422 : reverse_storage_order_for_component_p (vec<vn_reference_op_s> ops)
    1695                 :             : {
    1696                 :    58636422 :   unsigned i = 0;
    1697                 :    58636422 :   if (ops[i].opcode == REALPART_EXPR || ops[i].opcode == IMAGPART_EXPR)
    1698                 :             :     ++i;
    1699                 :    58636422 :   switch (ops[i].opcode)
    1700                 :             :     {
    1701                 :    56582995 :     case ARRAY_REF:
    1702                 :    56582995 :     case COMPONENT_REF:
    1703                 :    56582995 :     case BIT_FIELD_REF:
    1704                 :    56582995 :     case MEM_REF:
    1705                 :    56582995 :       return ops[i].reverse;
    1706                 :             :     default:
    1707                 :             :       return false;
    1708                 :             :     }
    1709                 :             : }
    1710                 :             : 
    1711                 :             : /* Transform any SSA_NAME's in a vector of vn_reference_op_s
    1712                 :             :    structures into their value numbers.  This is done in-place, and
    1713                 :             :    the vector passed in is returned.  *VALUEIZED_ANYTHING will specify
    1714                 :             :    whether any operands were valueized.  */
    1715                 :             : 
    1716                 :             : static void
    1717                 :   225822709 : valueize_refs_1 (vec<vn_reference_op_s> *orig, bool *valueized_anything,
    1718                 :             :                  bool with_avail = false)
    1719                 :             : {
    1720                 :   225822709 :   *valueized_anything = false;
    1721                 :             : 
    1722                 :   908001591 :   for (unsigned i = 0; i < orig->length (); ++i)
    1723                 :             :     {
    1724                 :   682178882 : re_valueize:
    1725                 :   685739072 :       vn_reference_op_t vro = &(*orig)[i];
    1726                 :   685739072 :       if (vro->opcode == SSA_NAME
    1727                 :   586823947 :           || (vro->op0 && TREE_CODE (vro->op0) == SSA_NAME))
    1728                 :             :         {
    1729                 :   123305894 :           tree tem = with_avail ? vn_valueize (vro->op0) : SSA_VAL (vro->op0);
    1730                 :   123305894 :           if (tem != vro->op0)
    1731                 :             :             {
    1732                 :    17640558 :               *valueized_anything = true;
    1733                 :    17640558 :               vro->op0 = tem;
    1734                 :             :             }
    1735                 :             :           /* If it transforms from an SSA_NAME to a constant, update
    1736                 :             :              the opcode.  */
    1737                 :   123305894 :           if (TREE_CODE (vro->op0) != SSA_NAME && vro->opcode == SSA_NAME)
    1738                 :     2048430 :             vro->opcode = TREE_CODE (vro->op0);
    1739                 :             :         }
    1740                 :   685739072 :       if (vro->op1 && TREE_CODE (vro->op1) == SSA_NAME)
    1741                 :             :         {
    1742                 :       26283 :           tree tem = with_avail ? vn_valueize (vro->op1) : SSA_VAL (vro->op1);
    1743                 :       26283 :           if (tem != vro->op1)
    1744                 :             :             {
    1745                 :         546 :               *valueized_anything = true;
    1746                 :         546 :               vro->op1 = tem;
    1747                 :             :             }
    1748                 :             :         }
    1749                 :   685739072 :       if (vro->op2 && TREE_CODE (vro->op2) == SSA_NAME)
    1750                 :             :         {
    1751                 :      205425 :           tree tem = with_avail ? vn_valueize (vro->op2) : SSA_VAL (vro->op2);
    1752                 :      205425 :           if (tem != vro->op2)
    1753                 :             :             {
    1754                 :      119502 :               *valueized_anything = true;
    1755                 :      119502 :               vro->op2 = tem;
    1756                 :             :             }
    1757                 :             :         }
    1758                 :             :       /* If it transforms from an SSA_NAME to an address, fold with
    1759                 :             :          a preceding indirect reference.  */
    1760                 :   685739072 :       if (i > 0
    1761                 :   459837432 :           && vro->op0
    1762                 :   456356536 :           && TREE_CODE (vro->op0) == ADDR_EXPR
    1763                 :   822821728 :           && (*orig)[i - 1].opcode == MEM_REF)
    1764                 :             :         {
    1765                 :   131175442 :           if (vn_reference_fold_indirect (orig, &i))
    1766                 :      656513 :             *valueized_anything = true;
    1767                 :             :         }
    1768                 :   554563630 :       else if (i > 0
    1769                 :   328661990 :                && vro->opcode == SSA_NAME
    1770                 :   651430325 :                && (*orig)[i - 1].opcode == MEM_REF)
    1771                 :             :         {
    1772                 :    87041506 :           if (vn_reference_maybe_forwprop_address (orig, &i))
    1773                 :             :             {
    1774                 :     3560190 :               *valueized_anything = true;
    1775                 :             :               /* Re-valueize the current operand.  */
    1776                 :     3560190 :               goto re_valueize;
    1777                 :             :             }
    1778                 :             :         }
    1779                 :             :       /* If it transforms a non-constant ARRAY_REF into a constant
    1780                 :             :          one, adjust the constant offset.  */
    1781                 :   467522124 :       else if ((vro->opcode == ARRAY_REF
    1782                 :   467522124 :                 || vro->opcode == ARRAY_RANGE_REF)
    1783                 :    39511492 :                && known_eq (vro->off, -1)
    1784                 :    17141848 :                && poly_int_tree_p (vro->op0)
    1785                 :     4586454 :                && poly_int_tree_p (vro->op1)
    1786                 :   472108578 :                && TREE_CODE (vro->op2) == INTEGER_CST)
    1787                 :             :         {
    1788                 :             :             /* Prohibit value-numbering addresses of one-after-the-last
    1789                 :             :                element ARRAY_REFs the same as addresses of other components
    1790                 :             :                before the pass folding __builtin_object_size had a chance
    1791                 :             :                to run.  */
    1792                 :     4452754 :           if (!(cfun->curr_properties & PROP_objsz)
    1793                 :     5663702 :               && (*orig)[0].opcode == ADDR_EXPR)
    1794                 :             :             {
    1795                 :       34051 :               tree dom = TYPE_DOMAIN ((*orig)[i + 1].type);
    1796                 :       51657 :               if (!dom
    1797                 :       33901 :                   || !TYPE_MAX_VALUE (dom)
    1798                 :       24367 :                   || !poly_int_tree_p (TYPE_MAX_VALUE (dom))
    1799                 :       50586 :                   || integer_minus_onep (TYPE_MAX_VALUE (dom)))
    1800                 :       18413 :                 continue;
    1801                 :       16445 :               if (!known_le (wi::to_poly_offset (vro->op0),
    1802                 :             :                              wi::to_poly_offset (TYPE_MAX_VALUE (dom))))
    1803                 :         807 :                 continue;
    1804                 :             :             }
    1805                 :             : 
    1806                 :     8868682 :           poly_offset_int off = ((wi::to_poly_offset (vro->op0)
    1807                 :    13303023 :                                   - wi::to_poly_offset (vro->op1))
    1808                 :     8868682 :                                  * wi::to_offset (vro->op2)
    1809                 :     4434341 :                                  * vn_ref_op_align_unit (vro));
    1810                 :     4434341 :           off.to_shwi (&vro->off);
    1811                 :             :         }
    1812                 :             :     }
    1813                 :   225822709 : }
    1814                 :             : 
    1815                 :             : static void
    1816                 :    14822842 : valueize_refs (vec<vn_reference_op_s> *orig)
    1817                 :             : {
    1818                 :    14822842 :   bool tem;
    1819                 :           0 :   valueize_refs_1 (orig, &tem);
    1820                 :           0 : }
    1821                 :             : 
    1822                 :             : static vec<vn_reference_op_s> shared_lookup_references;
    1823                 :             : 
    1824                 :             : /* Create a vector of vn_reference_op_s structures from REF, a
    1825                 :             :    REFERENCE_CLASS_P tree.  The vector is shared among all callers of
    1826                 :             :    this function.  *VALUEIZED_ANYTHING will specify whether any
    1827                 :             :    operands were valueized.  */
    1828                 :             : 
    1829                 :             : static vec<vn_reference_op_s>
    1830                 :   182563250 : valueize_shared_reference_ops_from_ref (tree ref, bool *valueized_anything)
    1831                 :             : {
    1832                 :   182563250 :   if (!ref)
    1833                 :           0 :     return vNULL;
    1834                 :   182563250 :   shared_lookup_references.truncate (0);
    1835                 :   182563250 :   copy_reference_ops_from_ref (ref, &shared_lookup_references);
    1836                 :   182563250 :   valueize_refs_1 (&shared_lookup_references, valueized_anything);
    1837                 :   182563250 :   return shared_lookup_references;
    1838                 :             : }
    1839                 :             : 
    1840                 :             : /* Create a vector of vn_reference_op_s structures from CALL, a
    1841                 :             :    call statement.  The vector is shared among all callers of
    1842                 :             :    this function.  */
    1843                 :             : 
    1844                 :             : static vec<vn_reference_op_s>
    1845                 :     9233941 : valueize_shared_reference_ops_from_call (gcall *call)
    1846                 :             : {
    1847                 :     9233941 :   if (!call)
    1848                 :           0 :     return vNULL;
    1849                 :     9233941 :   shared_lookup_references.truncate (0);
    1850                 :     9233941 :   copy_reference_ops_from_call (call, &shared_lookup_references);
    1851                 :     9233941 :   valueize_refs (&shared_lookup_references);
    1852                 :     9233941 :   return shared_lookup_references;
    1853                 :             : }
    1854                 :             : 
    1855                 :             : /* Lookup a SCCVN reference operation VR in the current hash table.
    1856                 :             :    Returns the resulting value number if it exists in the hash table,
    1857                 :             :    NULL_TREE otherwise.  VNRESULT will be filled in with the actual
    1858                 :             :    vn_reference_t stored in the hashtable if something is found.  */
    1859                 :             : 
    1860                 :             : static tree
    1861                 :    65848666 : vn_reference_lookup_1 (vn_reference_t vr, vn_reference_t *vnresult)
    1862                 :             : {
    1863                 :    65848666 :   vn_reference_s **slot;
    1864                 :    65848666 :   hashval_t hash;
    1865                 :             : 
    1866                 :    65848666 :   hash = vr->hashcode;
    1867                 :    65848666 :   slot = valid_info->references->find_slot_with_hash (vr, hash, NO_INSERT);
    1868                 :    65848666 :   if (slot)
    1869                 :             :     {
    1870                 :     8574620 :       if (vnresult)
    1871                 :     8574620 :         *vnresult = (vn_reference_t)*slot;
    1872                 :     8574620 :       return ((vn_reference_t)*slot)->result;
    1873                 :             :     }
    1874                 :             : 
    1875                 :             :   return NULL_TREE;
    1876                 :             : }
    1877                 :             : 
    1878                 :             : 
    1879                 :             : /* Partial definition tracking support.  */
    1880                 :             : 
    1881                 :             : struct pd_range
    1882                 :             : {
    1883                 :             :   HOST_WIDE_INT offset;
    1884                 :             :   HOST_WIDE_INT size;
    1885                 :             :   pd_range *m_children[2];
    1886                 :             : };
    1887                 :             : 
    1888                 :             : struct pd_data
    1889                 :             : {
    1890                 :             :   tree rhs;
    1891                 :             :   HOST_WIDE_INT rhs_off;
    1892                 :             :   HOST_WIDE_INT offset;
    1893                 :             :   HOST_WIDE_INT size;
    1894                 :             : };
    1895                 :             : 
    1896                 :             : /* Context for alias walking.  */
    1897                 :             : 
    1898                 :             : struct vn_walk_cb_data
    1899                 :             : {
    1900                 :    61830053 :   vn_walk_cb_data (vn_reference_t vr_, tree orig_ref_, tree *last_vuse_ptr_,
    1901                 :             :                    vn_lookup_kind vn_walk_kind_, bool tbaa_p_, tree mask_,
    1902                 :             :                    bool redundant_store_removal_p_)
    1903                 :    61830053 :     : vr (vr_), last_vuse_ptr (last_vuse_ptr_), last_vuse (NULL_TREE),
    1904                 :    61830053 :       mask (mask_), masked_result (NULL_TREE), same_val (NULL_TREE),
    1905                 :    61830053 :       vn_walk_kind (vn_walk_kind_),
    1906                 :    61830053 :       tbaa_p (tbaa_p_), redundant_store_removal_p (redundant_store_removal_p_),
    1907                 :   123660106 :       saved_operands (vNULL), first_range (), first_set (-2),
    1908                 :   123660106 :       first_base_set (-2)
    1909                 :             :   {
    1910                 :    61830053 :     if (!last_vuse_ptr)
    1911                 :    28610550 :       last_vuse_ptr = &last_vuse;
    1912                 :    61830053 :     ao_ref_init (&orig_ref, orig_ref_);
    1913                 :    61830053 :     if (mask)
    1914                 :             :       {
    1915                 :      364026 :         wide_int w = wi::to_wide (mask);
    1916                 :      364026 :         unsigned int pos = 0, prec = w.get_precision ();
    1917                 :      364026 :         pd_data pd;
    1918                 :      364026 :         pd.rhs = build_constructor (NULL_TREE, NULL);
    1919                 :      364026 :         pd.rhs_off = 0;
    1920                 :             :         /* When bitwise and with a constant is done on a memory load,
    1921                 :             :            we don't really need all the bits to be defined or defined
    1922                 :             :            to constants, we don't really care what is in the position
    1923                 :             :            corresponding to 0 bits in the mask.
    1924                 :             :            So, push the ranges of those 0 bits in the mask as artificial
    1925                 :             :            zero stores and let the partial def handling code do the
    1926                 :             :            rest.  */
    1927                 :      776588 :         while (pos < prec)
    1928                 :             :           {
    1929                 :      756448 :             int tz = wi::ctz (w);
    1930                 :      756448 :             if (pos + tz > prec)
    1931                 :      343886 :               tz = prec - pos;
    1932                 :      756448 :             if (tz)
    1933                 :             :               {
    1934                 :      583334 :                 if (BYTES_BIG_ENDIAN)
    1935                 :             :                   pd.offset = prec - pos - tz;
    1936                 :             :                 else
    1937                 :      583334 :                   pd.offset = pos;
    1938                 :      583334 :                 pd.size = tz;
    1939                 :      583334 :                 void *r = push_partial_def (pd, 0, 0, 0, prec);
    1940                 :      583334 :                 gcc_assert (r == NULL_TREE);
    1941                 :             :               }
    1942                 :      756448 :             pos += tz;
    1943                 :      756448 :             if (pos == prec)
    1944                 :             :               break;
    1945                 :      412562 :             w = wi::lrshift (w, tz);
    1946                 :      412562 :             tz = wi::ctz (wi::bit_not (w));
    1947                 :      412562 :             if (pos + tz > prec)
    1948                 :           0 :               tz = prec - pos;
    1949                 :      412562 :             pos += tz;
    1950                 :      412562 :             w = wi::lrshift (w, tz);
    1951                 :             :           }
    1952                 :      364026 :       }
    1953                 :    61830053 :   }
    1954                 :             :   ~vn_walk_cb_data ();
    1955                 :             :   void *finish (alias_set_type, alias_set_type, tree);
    1956                 :             :   void *push_partial_def (pd_data pd,
    1957                 :             :                           alias_set_type, alias_set_type, HOST_WIDE_INT,
    1958                 :             :                           HOST_WIDE_INT);
    1959                 :             : 
    1960                 :             :   vn_reference_t vr;
    1961                 :             :   ao_ref orig_ref;
    1962                 :             :   tree *last_vuse_ptr;
    1963                 :             :   tree last_vuse;
    1964                 :             :   tree mask;
    1965                 :             :   tree masked_result;
    1966                 :             :   tree same_val;
    1967                 :             :   vn_lookup_kind vn_walk_kind;
    1968                 :             :   bool tbaa_p;
    1969                 :             :   bool redundant_store_removal_p;
    1970                 :             :   vec<vn_reference_op_s> saved_operands;
    1971                 :             : 
    1972                 :             :   /* The VDEFs of partial defs we come along.  */
    1973                 :             :   auto_vec<pd_data, 2> partial_defs;
    1974                 :             :   /* The first defs range to avoid splay tree setup in most cases.  */
    1975                 :             :   pd_range first_range;
    1976                 :             :   alias_set_type first_set;
    1977                 :             :   alias_set_type first_base_set;
    1978                 :             :   default_splay_tree<pd_range *> known_ranges;
    1979                 :             :   obstack ranges_obstack;
    1980                 :             :   static constexpr HOST_WIDE_INT bufsize = 64;
    1981                 :             : };
    1982                 :             : 
    1983                 :    61830053 : vn_walk_cb_data::~vn_walk_cb_data ()
    1984                 :             : {
    1985                 :    61830053 :   if (known_ranges)
    1986                 :      212346 :     obstack_free (&ranges_obstack, NULL);
    1987                 :    61830053 :   saved_operands.release ();
    1988                 :    61830053 : }
    1989                 :             : 
    1990                 :             : void *
    1991                 :     1445366 : vn_walk_cb_data::finish (alias_set_type set, alias_set_type base_set, tree val)
    1992                 :             : {
    1993                 :     1445366 :   if (first_set != -2)
    1994                 :             :     {
    1995                 :      352742 :       set = first_set;
    1996                 :      352742 :       base_set = first_base_set;
    1997                 :             :     }
    1998                 :     1445366 :   if (mask)
    1999                 :             :     {
    2000                 :         687 :       masked_result = val;
    2001                 :         687 :       return (void *) -1;
    2002                 :             :     }
    2003                 :     1444679 :   if (same_val && !operand_equal_p (val, same_val))
    2004                 :             :     return (void *) -1;
    2005                 :     1441041 :   vec<vn_reference_op_s> &operands
    2006                 :     1441041 :     = saved_operands.exists () ? saved_operands : vr->operands;
    2007                 :     1441041 :   return vn_reference_lookup_or_insert_for_pieces (last_vuse, set, base_set,
    2008                 :             :                                                    vr->offset, vr->max_size,
    2009                 :     1441041 :                                                    vr->type, operands, val);
    2010                 :             : }
    2011                 :             : 
    2012                 :             : /* Push PD to the vector of partial definitions returning a
    2013                 :             :    value when we are ready to combine things with VUSE, SET and MAXSIZEI,
    2014                 :             :    NULL when we want to continue looking for partial defs or -1
    2015                 :             :    on failure.  */
    2016                 :             : 
    2017                 :             : void *
    2018                 :      670991 : vn_walk_cb_data::push_partial_def (pd_data pd,
    2019                 :             :                                    alias_set_type set, alias_set_type base_set,
    2020                 :             :                                    HOST_WIDE_INT offseti,
    2021                 :             :                                    HOST_WIDE_INT maxsizei)
    2022                 :             : {
    2023                 :             :   /* We're using a fixed buffer for encoding so fail early if the object
    2024                 :             :      we want to interpret is bigger.  */
    2025                 :      670991 :   if (maxsizei > bufsize * BITS_PER_UNIT
    2026                 :             :       || CHAR_BIT != 8
    2027                 :             :       || BITS_PER_UNIT != 8
    2028                 :             :       /* Not prepared to handle PDP endian.  */
    2029                 :             :       || BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
    2030                 :             :     return (void *)-1;
    2031                 :             : 
    2032                 :             :   /* Turn too large constant stores into non-constant stores.  */
    2033                 :      670920 :   if (CONSTANT_CLASS_P (pd.rhs) && pd.size > bufsize * BITS_PER_UNIT)
    2034                 :           0 :     pd.rhs = error_mark_node;
    2035                 :             : 
    2036                 :             :   /* And for non-constant or CONSTRUCTOR stores shrink them to only keep at
    2037                 :             :      most a partial byte before and/or after the region.  */
    2038                 :      670920 :   if (!CONSTANT_CLASS_P (pd.rhs))
    2039                 :             :     {
    2040                 :      636986 :       if (pd.offset < offseti)
    2041                 :             :         {
    2042                 :       10110 :           HOST_WIDE_INT o = ROUND_DOWN (offseti - pd.offset, BITS_PER_UNIT);
    2043                 :       10110 :           gcc_assert (pd.size > o);
    2044                 :       10110 :           pd.size -= o;
    2045                 :       10110 :           pd.offset += o;
    2046                 :             :         }
    2047                 :      636986 :       if (pd.size > maxsizei)
    2048                 :       11499 :         pd.size = maxsizei + ((pd.size - maxsizei) % BITS_PER_UNIT);
    2049                 :             :     }
    2050                 :             : 
    2051                 :      670920 :   pd.offset -= offseti;
    2052                 :             : 
    2053                 :     1341840 :   bool pd_constant_p = (TREE_CODE (pd.rhs) == CONSTRUCTOR
    2054                 :      670920 :                         || CONSTANT_CLASS_P (pd.rhs));
    2055                 :      670920 :   pd_range *r;
    2056                 :      670920 :   if (partial_defs.is_empty ())
    2057                 :             :     {
    2058                 :             :       /* If we get a clobber upfront, fail.  */
    2059                 :      425443 :       if (TREE_CLOBBER_P (pd.rhs))
    2060                 :             :         return (void *)-1;
    2061                 :      413372 :       if (!pd_constant_p)
    2062                 :             :         return (void *)-1;
    2063                 :      383314 :       partial_defs.safe_push (pd);
    2064                 :      383314 :       first_range.offset = pd.offset;
    2065                 :      383314 :       first_range.size = pd.size;
    2066                 :      383314 :       first_set = set;
    2067                 :      383314 :       first_base_set = base_set;
    2068                 :      383314 :       last_vuse_ptr = NULL;
    2069                 :      383314 :       r = &first_range;
    2070                 :             :       /* Go check if the first partial definition was a full one in case
    2071                 :             :          the caller didn't optimize for this.  */
    2072                 :             :     }
    2073                 :             :   else
    2074                 :             :     {
    2075                 :      245477 :       if (!known_ranges)
    2076                 :             :         {
    2077                 :             :           /* ???  Optimize the case where the 2nd partial def completes
    2078                 :             :              things.  */
    2079                 :      212346 :           gcc_obstack_init (&ranges_obstack);
    2080                 :      212346 :           known_ranges.insert_max_node (&first_range);
    2081                 :             :         }
    2082                 :             :       /* Lookup the offset and see if we need to merge.  */
    2083                 :      245477 :       int comparison = known_ranges.lookup_le
    2084                 :      495515 :         ([&] (pd_range *r) { return pd.offset < r->offset; },
    2085                 :      225831 :          [&] (pd_range *r) { return pd.offset > r->offset; });
    2086                 :      245477 :       r = known_ranges.root ();
    2087                 :      245477 :       if (comparison >= 0
    2088                 :      245477 :           && ranges_known_overlap_p (r->offset, r->size + 1,
    2089                 :             :                                      pd.offset, pd.size))
    2090                 :             :         {
    2091                 :             :           /* Ignore partial defs already covered.  Here we also drop shadowed
    2092                 :             :              clobbers arriving here at the floor.  */
    2093                 :        6205 :           if (known_subrange_p (pd.offset, pd.size, r->offset, r->size))
    2094                 :             :             return NULL;
    2095                 :        5438 :           r->size = MAX (r->offset + r->size, pd.offset + pd.size) - r->offset;
    2096                 :             :         }
    2097                 :             :       else
    2098                 :             :         {
    2099                 :             :           /* pd.offset wasn't covered yet, insert the range.  */
    2100                 :      239272 :           void *addr = XOBNEW (&ranges_obstack, pd_range);
    2101                 :      239272 :           r = new (addr) pd_range { pd.offset, pd.size, {} };
    2102                 :      239272 :           known_ranges.insert_relative (comparison, r);
    2103                 :             :         }
    2104                 :             :       /* Merge r which now contains pd's range and is a member of the splay
    2105                 :             :          tree with adjacent overlapping ranges.  */
    2106                 :      244710 :       if (known_ranges.splay_next_node ())
    2107                 :       21704 :         do
    2108                 :             :           {
    2109                 :       21704 :             pd_range *rafter = known_ranges.root ();
    2110                 :       21704 :             if (!ranges_known_overlap_p (r->offset, r->size + 1,
    2111                 :       21704 :                                          rafter->offset, rafter->size))
    2112                 :             :               break;
    2113                 :       21318 :             r->size = MAX (r->offset + r->size,
    2114                 :       21318 :                            rafter->offset + rafter->size) - r->offset;
    2115                 :             :           }
    2116                 :       21318 :         while (known_ranges.remove_root_and_splay_next ());
    2117                 :             :       /* If we get a clobber, fail.  */
    2118                 :      244710 :       if (TREE_CLOBBER_P (pd.rhs))
    2119                 :             :         return (void *)-1;
    2120                 :             :       /* Non-constants are OK as long as they are shadowed by a constant.  */
    2121                 :      242040 :       if (!pd_constant_p)
    2122                 :             :         return (void *)-1;
    2123                 :      235028 :       partial_defs.safe_push (pd);
    2124                 :             :     }
    2125                 :             : 
    2126                 :             :   /* Now we have merged pd's range into the range tree.  When we have covered
    2127                 :             :      [offseti, sizei] then the tree will contain exactly one node which has
    2128                 :             :      the desired properties and it will be 'r'.  */
    2129                 :      618342 :   if (!known_subrange_p (0, maxsizei, r->offset, r->size))
    2130                 :             :     /* Continue looking for partial defs.  */
    2131                 :             :     return NULL;
    2132                 :             : 
    2133                 :             :   /* Now simply native encode all partial defs in reverse order.  */
    2134                 :        8220 :   unsigned ndefs = partial_defs.length ();
    2135                 :             :   /* We support up to 512-bit values (for V8DFmode).  */
    2136                 :        8220 :   unsigned char buffer[bufsize + 1];
    2137                 :        8220 :   unsigned char this_buffer[bufsize + 1];
    2138                 :        8220 :   int len;
    2139                 :             : 
    2140                 :        8220 :   memset (buffer, 0, bufsize + 1);
    2141                 :        8220 :   unsigned needed_len = ROUND_UP (maxsizei, BITS_PER_UNIT) / BITS_PER_UNIT;
    2142                 :       39965 :   while (!partial_defs.is_empty ())
    2143                 :             :     {
    2144                 :       23525 :       pd_data pd = partial_defs.pop ();
    2145                 :       23525 :       unsigned int amnt;
    2146                 :       23525 :       if (TREE_CODE (pd.rhs) == CONSTRUCTOR)
    2147                 :             :         {
    2148                 :             :           /* Empty CONSTRUCTOR.  */
    2149                 :        2182 :           if (pd.size >= needed_len * BITS_PER_UNIT)
    2150                 :        2182 :             len = needed_len;
    2151                 :             :           else
    2152                 :        2010 :             len = ROUND_UP (pd.size, BITS_PER_UNIT) / BITS_PER_UNIT;
    2153                 :        2182 :           memset (this_buffer, 0, len);
    2154                 :             :         }
    2155                 :       21343 :       else if (pd.rhs_off >= 0)
    2156                 :             :         {
    2157                 :       42686 :           len = native_encode_expr (pd.rhs, this_buffer, bufsize,
    2158                 :       21343 :                                     (MAX (0, -pd.offset)
    2159                 :       21343 :                                      + pd.rhs_off) / BITS_PER_UNIT);
    2160                 :       21343 :           if (len <= 0
    2161                 :       21343 :               || len < (ROUND_UP (pd.size, BITS_PER_UNIT) / BITS_PER_UNIT
    2162                 :       21343 :                         - MAX (0, -pd.offset) / BITS_PER_UNIT))
    2163                 :             :             {
    2164                 :           0 :               if (dump_file && (dump_flags & TDF_DETAILS))
    2165                 :           0 :                 fprintf (dump_file, "Failed to encode %u "
    2166                 :             :                          "partial definitions\n", ndefs);
    2167                 :           0 :               return (void *)-1;
    2168                 :             :             }
    2169                 :             :         }
    2170                 :             :       else /* negative pd.rhs_off indicates we want to chop off first bits */
    2171                 :             :         {
    2172                 :           0 :           if (-pd.rhs_off >= bufsize)
    2173                 :             :             return (void *)-1;
    2174                 :           0 :           len = native_encode_expr (pd.rhs,
    2175                 :           0 :                                     this_buffer + -pd.rhs_off / BITS_PER_UNIT,
    2176                 :           0 :                                     bufsize - -pd.rhs_off / BITS_PER_UNIT,
    2177                 :           0 :                                     MAX (0, -pd.offset) / BITS_PER_UNIT);
    2178                 :           0 :           if (len <= 0
    2179                 :           0 :               || len < (ROUND_UP (pd.size, BITS_PER_UNIT) / BITS_PER_UNIT
    2180                 :           0 :                         - MAX (0, -pd.offset) / BITS_PER_UNIT))
    2181                 :             :             {
    2182                 :           0 :               if (dump_file && (dump_flags & TDF_DETAILS))
    2183                 :           0 :                 fprintf (dump_file, "Failed to encode %u "
    2184                 :             :                          "partial definitions\n", ndefs);
    2185                 :           0 :               return (void *)-1;
    2186                 :             :             }
    2187                 :             :         }
    2188                 :             : 
    2189                 :       23525 :       unsigned char *p = buffer;
    2190                 :       23525 :       HOST_WIDE_INT size = pd.size;
    2191                 :       23525 :       if (pd.offset < 0)
    2192                 :         225 :         size -= ROUND_DOWN (-pd.offset, BITS_PER_UNIT);
    2193                 :       23525 :       this_buffer[len] = 0;
    2194                 :       23525 :       if (BYTES_BIG_ENDIAN)
    2195                 :             :         {
    2196                 :             :           /* LSB of this_buffer[len - 1] byte should be at
    2197                 :             :              pd.offset + pd.size - 1 bits in buffer.  */
    2198                 :             :           amnt = ((unsigned HOST_WIDE_INT) pd.offset
    2199                 :             :                   + pd.size) % BITS_PER_UNIT;
    2200                 :             :           if (amnt)
    2201                 :             :             shift_bytes_in_array_right (this_buffer, len + 1, amnt);
    2202                 :             :           unsigned char *q = this_buffer;
    2203                 :             :           unsigned int off = 0;
    2204                 :             :           if (pd.offset >= 0)
    2205                 :             :             {
    2206                 :             :               unsigned int msk;
    2207                 :             :               off = pd.offset / BITS_PER_UNIT;
    2208                 :             :               gcc_assert (off < needed_len);
    2209                 :             :               p = buffer + off;
    2210                 :             :               if (size <= amnt)
    2211                 :             :                 {
    2212                 :             :                   msk = ((1 << size) - 1) << (BITS_PER_UNIT - amnt);
    2213                 :             :                   *p = (*p & ~msk) | (this_buffer[len] & msk);
    2214                 :             :                   size = 0;
    2215                 :             :                 }
    2216                 :             :               else
    2217                 :             :                 {
    2218                 :             :                   if (TREE_CODE (pd.rhs) != CONSTRUCTOR)
    2219                 :             :                     q = (this_buffer + len
    2220                 :             :                          - (ROUND_UP (size - amnt, BITS_PER_UNIT)
    2221                 :             :                             / BITS_PER_UNIT));
    2222                 :             :                   if (pd.offset % BITS_PER_UNIT)
    2223                 :             :                     {
    2224                 :             :                       msk = -1U << (BITS_PER_UNIT
    2225                 :             :                                     - (pd.offset % BITS_PER_UNIT));
    2226                 :             :                       *p = (*p & msk) | (*q & ~msk);
    2227                 :             :                       p++;
    2228                 :             :                       q++;
    2229                 :             :                       off++;
    2230                 :             :                       size -= BITS_PER_UNIT - (pd.offset % BITS_PER_UNIT);
    2231                 :             :                       gcc_assert (size >= 0);
    2232                 :             :                     }
    2233                 :             :                 }
    2234                 :             :             }
    2235                 :             :           else if (TREE_CODE (pd.rhs) != CONSTRUCTOR)
    2236                 :             :             {
    2237                 :             :               q = (this_buffer + len
    2238                 :             :                    - (ROUND_UP (size - amnt, BITS_PER_UNIT)
    2239                 :             :                       / BITS_PER_UNIT));
    2240                 :             :               if (pd.offset % BITS_PER_UNIT)
    2241                 :             :                 {
    2242                 :             :                   q++;
    2243                 :             :                   size -= BITS_PER_UNIT - ((unsigned HOST_WIDE_INT) pd.offset
    2244                 :             :                                            % BITS_PER_UNIT);
    2245                 :             :                   gcc_assert (size >= 0);
    2246                 :             :                 }
    2247                 :             :             }
    2248                 :             :           if ((unsigned HOST_WIDE_INT) size / BITS_PER_UNIT + off
    2249                 :             :               > needed_len)
    2250                 :             :             size = (needed_len - off) * BITS_PER_UNIT;
    2251                 :             :           memcpy (p, q, size / BITS_PER_UNIT);
    2252                 :             :           if (size % BITS_PER_UNIT)
    2253                 :             :             {
    2254                 :             :               unsigned int msk
    2255                 :             :                 = -1U << (BITS_PER_UNIT - (size % BITS_PER_UNIT));
    2256                 :             :               p += size / BITS_PER_UNIT;
    2257                 :             :               q += size / BITS_PER_UNIT;
    2258                 :             :               *p = (*q & msk) | (*p & ~msk);
    2259                 :             :             }
    2260                 :             :         }
    2261                 :             :       else
    2262                 :             :         {
    2263                 :       23525 :           if (pd.offset >= 0)
    2264                 :             :             {
    2265                 :             :               /* LSB of this_buffer[0] byte should be at pd.offset bits
    2266                 :             :                  in buffer.  */
    2267                 :       23300 :               unsigned int msk;
    2268                 :       23300 :               size = MIN (size, (HOST_WIDE_INT) needed_len * BITS_PER_UNIT);
    2269                 :       23300 :               amnt = pd.offset % BITS_PER_UNIT;
    2270                 :       23300 :               if (amnt)
    2271                 :        1783 :                 shift_bytes_in_array_left (this_buffer, len + 1, amnt);
    2272                 :       23300 :               unsigned int off = pd.offset / BITS_PER_UNIT;
    2273                 :       23300 :               gcc_assert (off < needed_len);
    2274                 :       23300 :               size = MIN (size,
    2275                 :             :                           (HOST_WIDE_INT) (needed_len - off) * BITS_PER_UNIT);
    2276                 :       23300 :               p = buffer + off;
    2277                 :       23300 :               if (amnt + size < BITS_PER_UNIT)
    2278                 :             :                 {
    2279                 :             :                   /* Low amnt bits come from *p, then size bits
    2280                 :             :                      from this_buffer[0] and the remaining again from
    2281                 :             :                      *p.  */
    2282                 :        1365 :                   msk = ((1 << size) - 1) << amnt;
    2283                 :        1365 :                   *p = (*p & ~msk) | (this_buffer[0] & msk);
    2284                 :        1365 :                   size = 0;
    2285                 :             :                 }
    2286                 :       21935 :               else if (amnt)
    2287                 :             :                 {
    2288                 :        1360 :                   msk = -1U << amnt;
    2289                 :        1360 :                   *p = (*p & ~msk) | (this_buffer[0] & msk);
    2290                 :        1360 :                   p++;
    2291                 :        1360 :                   size -= (BITS_PER_UNIT - amnt);
    2292                 :             :                 }
    2293                 :             :             }
    2294                 :             :           else
    2295                 :             :             {
    2296                 :         225 :               amnt = (unsigned HOST_WIDE_INT) pd.offset % BITS_PER_UNIT;
    2297                 :         225 :               if (amnt)
    2298                 :          16 :                 size -= BITS_PER_UNIT - amnt;
    2299                 :         225 :               size = MIN (size, (HOST_WIDE_INT) needed_len * BITS_PER_UNIT);
    2300                 :         225 :               if (amnt)
    2301                 :          16 :                 shift_bytes_in_array_left (this_buffer, len + 1, amnt);
    2302                 :             :             }
    2303                 :       23525 :           memcpy (p, this_buffer + (amnt != 0), size / BITS_PER_UNIT);
    2304                 :       23525 :           p += size / BITS_PER_UNIT;
    2305                 :       23525 :           if (size % BITS_PER_UNIT)
    2306                 :             :             {
    2307                 :         619 :               unsigned int msk = -1U << (size % BITS_PER_UNIT);
    2308                 :         619 :               *p = (this_buffer[(amnt != 0) + size / BITS_PER_UNIT]
    2309                 :         619 :                     & ~msk) | (*p & msk);
    2310                 :             :             }
    2311                 :             :         }
    2312                 :             :     }
    2313                 :             : 
    2314                 :        8220 :   tree type = vr->type;
    2315                 :             :   /* Make sure to interpret in a type that has a range covering the whole
    2316                 :             :      access size.  */
    2317                 :        8220 :   if (INTEGRAL_TYPE_P (vr->type) && maxsizei != TYPE_PRECISION (vr->type))
    2318                 :          13 :     type = build_nonstandard_integer_type (maxsizei, TYPE_UNSIGNED (type));
    2319                 :        8220 :   tree val;
    2320                 :        8220 :   if (BYTES_BIG_ENDIAN)
    2321                 :             :     {
    2322                 :             :       unsigned sz = needed_len;
    2323                 :             :       if (maxsizei % BITS_PER_UNIT)
    2324                 :             :         shift_bytes_in_array_right (buffer, needed_len,
    2325                 :             :                                     BITS_PER_UNIT
    2326                 :             :                                     - (maxsizei % BITS_PER_UNIT));
    2327                 :             :       if (INTEGRAL_TYPE_P (type))
    2328                 :             :         {
    2329                 :             :           if (TYPE_MODE (type) != BLKmode)
    2330                 :             :             sz = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type));
    2331                 :             :           else
    2332                 :             :             sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (type));
    2333                 :             :         }
    2334                 :             :       if (sz > needed_len)
    2335                 :             :         {
    2336                 :             :           memcpy (this_buffer + (sz - needed_len), buffer, needed_len);
    2337                 :             :           val = native_interpret_expr (type, this_buffer, sz);
    2338                 :             :         }
    2339                 :             :       else
    2340                 :             :         val = native_interpret_expr (type, buffer, needed_len);
    2341                 :             :     }
    2342                 :             :   else
    2343                 :        8220 :     val = native_interpret_expr (type, buffer, bufsize);
    2344                 :             :   /* If we chop off bits because the types precision doesn't match the memory
    2345                 :             :      access size this is ok when optimizing reads but not when called from
    2346                 :             :      the DSE code during elimination.  */
    2347                 :        8220 :   if (val && type != vr->type)
    2348                 :             :     {
    2349                 :          13 :       if (! int_fits_type_p (val, vr->type))
    2350                 :             :         val = NULL_TREE;
    2351                 :             :       else
    2352                 :          13 :         val = fold_convert (vr->type, val);
    2353                 :             :     }
    2354                 :             : 
    2355                 :        8216 :   if (val)
    2356                 :             :     {
    2357                 :        8216 :       if (dump_file && (dump_flags & TDF_DETAILS))
    2358                 :           0 :         fprintf (dump_file,
    2359                 :             :                  "Successfully combined %u partial definitions\n", ndefs);
    2360                 :             :       /* We are using the alias-set of the first store we encounter which
    2361                 :             :          should be appropriate here.  */
    2362                 :        8216 :       return finish (first_set, first_base_set, val);
    2363                 :             :     }
    2364                 :             :   else
    2365                 :             :     {
    2366                 :           4 :       if (dump_file && (dump_flags & TDF_DETAILS))
    2367                 :           0 :         fprintf (dump_file,
    2368                 :             :                  "Failed to interpret %u encoded partial definitions\n", ndefs);
    2369                 :           4 :       return (void *)-1;
    2370                 :             :     }
    2371                 :             : }
    2372                 :             : 
    2373                 :             : /* Callback for walk_non_aliased_vuses.  Adjusts the vn_reference_t VR_
    2374                 :             :    with the current VUSE and performs the expression lookup.  */
    2375                 :             : 
    2376                 :             : static void *
    2377                 :  1045799814 : vn_reference_lookup_2 (ao_ref *op, tree vuse, void *data_)
    2378                 :             : {
    2379                 :  1045799814 :   vn_walk_cb_data *data = (vn_walk_cb_data *)data_;
    2380                 :  1045799814 :   vn_reference_t vr = data->vr;
    2381                 :  1045799814 :   vn_reference_s **slot;
    2382                 :  1045799814 :   hashval_t hash;
    2383                 :             : 
    2384                 :             :   /* If we have partial definitions recorded we have to go through
    2385                 :             :      vn_reference_lookup_3.  */
    2386                 :  2083856163 :   if (!data->partial_defs.is_empty ())
    2387                 :             :     return NULL;
    2388                 :             : 
    2389                 :  1044877479 :   if (data->last_vuse_ptr)
    2390                 :             :     {
    2391                 :  1023435351 :       *data->last_vuse_ptr = vuse;
    2392                 :  1023435351 :       data->last_vuse = vuse;
    2393                 :             :     }
    2394                 :             : 
    2395                 :             :   /* Fixup vuse and hash.  */
    2396                 :  1044877479 :   if (vr->vuse)
    2397                 :  1044877479 :     vr->hashcode = vr->hashcode - SSA_NAME_VERSION (vr->vuse);
    2398                 :  1044877479 :   vr->vuse = vuse_ssa_val (vuse);
    2399                 :  1044877479 :   if (vr->vuse)
    2400                 :  1044877479 :     vr->hashcode = vr->hashcode + SSA_NAME_VERSION (vr->vuse);
    2401                 :             : 
    2402                 :  1044877479 :   hash = vr->hashcode;
    2403                 :  1044877479 :   slot = valid_info->references->find_slot_with_hash (vr, hash, NO_INSERT);
    2404                 :  1044877479 :   if (slot)
    2405                 :             :     {
    2406                 :     7742304 :       if ((*slot)->result && data->saved_operands.exists ())
    2407                 :      339232 :         return data->finish (vr->set, vr->base_set, (*slot)->result);
    2408                 :             :       return *slot;
    2409                 :             :     }
    2410                 :             : 
    2411                 :  1037135175 :   if (SSA_NAME_IS_DEFAULT_DEF (vuse))
    2412                 :             :     {
    2413                 :    17197309 :       HOST_WIDE_INT op_offset, op_size;
    2414                 :    17197309 :       tree v = NULL_TREE;
    2415                 :    17197309 :       tree base = ao_ref_base (op);
    2416                 :             : 
    2417                 :    17197309 :       if (base
    2418                 :    17197309 :           && op->offset.is_constant (&op_offset)
    2419                 :    17197309 :           && op->size.is_constant (&op_size)
    2420                 :    17197309 :           && op->max_size_known_p ()
    2421                 :    33948457 :           && known_eq (op->size, op->max_size))
    2422                 :             :         {
    2423                 :    16458374 :           if (TREE_CODE (base) == PARM_DECL)
    2424                 :      706167 :             v = ipcp_get_aggregate_const (cfun, base, false, op_offset,
    2425                 :             :                                           op_size);
    2426                 :    15752207 :           else if (TREE_CODE (base) == MEM_REF
    2427                 :     6355084 :                    && integer_zerop (TREE_OPERAND (base, 1))
    2428                 :     5163199 :                    && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME
    2429                 :     5157236 :                    && SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (base, 0))
    2430                 :    19112291 :                    && (TREE_CODE (SSA_NAME_VAR (TREE_OPERAND (base, 0)))
    2431                 :             :                        == PARM_DECL))
    2432                 :     3305821 :             v = ipcp_get_aggregate_const (cfun,
    2433                 :     3305821 :                                           SSA_NAME_VAR (TREE_OPERAND (base, 0)),
    2434                 :             :                                           true, op_offset, op_size);
    2435                 :             :         }
    2436                 :     4011988 :       if (v)
    2437                 :        1161 :         return data->finish (vr->set, vr->base_set, v);
    2438                 :             :     }
    2439                 :             : 
    2440                 :             :   return NULL;
    2441                 :             : }
    2442                 :             : 
    2443                 :             : /* Lookup an existing or insert a new vn_reference entry into the
    2444                 :             :    value table for the VUSE, SET, TYPE, OPERANDS reference which
    2445                 :             :    has the value VALUE which is either a constant or an SSA name.  */
    2446                 :             : 
    2447                 :             : static vn_reference_t
    2448                 :     1441041 : vn_reference_lookup_or_insert_for_pieces (tree vuse,
    2449                 :             :                                           alias_set_type set,
    2450                 :             :                                           alias_set_type base_set,
    2451                 :             :                                           poly_int64 offset,
    2452                 :             :                                           poly_int64 max_size,
    2453                 :             :                                           tree type,
    2454                 :             :                                           vec<vn_reference_op_s,
    2455                 :             :                                                 va_heap> operands,
    2456                 :             :                                           tree value)
    2457                 :             : {
    2458                 :     1441041 :   vn_reference_s vr1;
    2459                 :     1441041 :   vn_reference_t result;
    2460                 :     1441041 :   unsigned value_id;
    2461                 :     1441041 :   vr1.vuse = vuse ? SSA_VAL (vuse) : NULL_TREE;
    2462                 :     1441041 :   vr1.operands = operands;
    2463                 :     1441041 :   vr1.type = type;
    2464                 :     1441041 :   vr1.set = set;
    2465                 :     1441041 :   vr1.base_set = base_set;
    2466                 :     1441041 :   vr1.offset = offset;
    2467                 :     1441041 :   vr1.max_size = max_size;
    2468                 :     1441041 :   vr1.hashcode = vn_reference_compute_hash (&vr1);
    2469                 :     1441041 :   if (vn_reference_lookup_1 (&vr1, &result))
    2470                 :        4758 :     return result;
    2471                 :             : 
    2472                 :     1436283 :   if (TREE_CODE (value) == SSA_NAME)
    2473                 :      280464 :     value_id = VN_INFO (value)->value_id;
    2474                 :             :   else
    2475                 :     1155819 :     value_id = get_or_alloc_constant_value_id (value);
    2476                 :     1436283 :   return vn_reference_insert_pieces (vuse, set, base_set, offset, max_size,
    2477                 :     1436283 :                                      type, operands.copy (), value, value_id);
    2478                 :             : }
    2479                 :             : 
    2480                 :             : /* Return a value-number for RCODE OPS... either by looking up an existing
    2481                 :             :    value-number for the possibly simplified result or by inserting the
    2482                 :             :    operation if INSERT is true.  If SIMPLIFY is false, return a value
    2483                 :             :    number for the unsimplified expression.  */
    2484                 :             : 
    2485                 :             : static tree
    2486                 :    18140560 : vn_nary_build_or_lookup_1 (gimple_match_op *res_op, bool insert,
    2487                 :             :                            bool simplify)
    2488                 :             : {
    2489                 :    18140560 :   tree result = NULL_TREE;
    2490                 :             :   /* We will be creating a value number for
    2491                 :             :        RCODE (OPS...).
    2492                 :             :      So first simplify and lookup this expression to see if it
    2493                 :             :      is already available.  */
    2494                 :             :   /* For simplification valueize.  */
    2495                 :    18140560 :   unsigned i = 0;
    2496                 :    18140560 :   if (simplify)
    2497                 :    42144347 :     for (i = 0; i < res_op->num_ops; ++i)
    2498                 :    24009536 :       if (TREE_CODE (res_op->ops[i]) == SSA_NAME)
    2499                 :             :         {
    2500                 :    15368213 :           tree tem = vn_valueize (res_op->ops[i]);
    2501                 :    15368213 :           if (!tem)
    2502                 :             :             break;
    2503                 :    15368213 :           res_op->ops[i] = tem;
    2504                 :             :         }
    2505                 :             :   /* If valueization of an operand fails (it is not available), skip
    2506                 :             :      simplification.  */
    2507                 :    18140560 :   bool res = false;
    2508                 :    18140560 :   if (i == res_op->num_ops)
    2509                 :             :     {
    2510                 :             :       /* Do not leak not available operands into the simplified expression
    2511                 :             :          when called from PRE context.  */
    2512                 :    18134811 :       if (rpo_avail)
    2513                 :    10771677 :         mprts_hook = vn_lookup_simplify_result;
    2514                 :    18134811 :       res = res_op->resimplify (NULL, vn_valueize);
    2515                 :    18134811 :       mprts_hook = NULL;
    2516                 :             :     }
    2517                 :    31215995 :   gimple *new_stmt = NULL;
    2518                 :    18134811 :   if (res
    2519                 :    18134811 :       && gimple_simplified_result_is_gimple_val (res_op))
    2520                 :             :     {
    2521                 :             :       /* The expression is already available.  */
    2522                 :     5059376 :       result = res_op->ops[0];
    2523                 :             :       /* Valueize it, simplification returns sth in AVAIL only.  */
    2524                 :     5059376 :       if (TREE_CODE (result) == SSA_NAME)
    2525                 :      285741 :         result = SSA_VAL (result);
    2526                 :             :     }
    2527                 :             :   else
    2528                 :             :     {
    2529                 :    13081184 :       tree val = vn_lookup_simplify_result (res_op);
    2530                 :    13081184 :       if (!val && insert)
    2531                 :             :         {
    2532                 :      137786 :           gimple_seq stmts = NULL;
    2533                 :      137786 :           result = maybe_push_res_to_seq (res_op, &stmts);
    2534                 :      137786 :           if (result)
    2535                 :             :             {
    2536                 :      137786 :               gcc_assert (gimple_seq_singleton_p (stmts));
    2537                 :      137786 :               new_stmt = gimple_seq_first_stmt (stmts);
    2538                 :             :             }
    2539                 :             :         }
    2540                 :             :       else
    2541                 :             :         /* The expression is already available.  */
    2542                 :             :         result = val;
    2543                 :             :     }
    2544                 :      285741 :   if (new_stmt)
    2545                 :             :     {
    2546                 :             :       /* The expression is not yet available, value-number lhs to
    2547                 :             :          the new SSA_NAME we created.  */
    2548                 :             :       /* Initialize value-number information properly.  */
    2549                 :      137786 :       vn_ssa_aux_t result_info = VN_INFO (result);
    2550                 :      137786 :       result_info->valnum = result;
    2551                 :      137786 :       result_info->value_id = get_next_value_id ();
    2552                 :      137786 :       result_info->visited = 1;
    2553                 :      137786 :       gimple_seq_add_stmt_without_update (&VN_INFO (result)->expr,
    2554                 :             :                                           new_stmt);
    2555                 :      137786 :       result_info->needs_insertion = true;
    2556                 :             :       /* ???  PRE phi-translation inserts NARYs without corresponding
    2557                 :             :          SSA name result.  Re-use those but set their result according
    2558                 :             :          to the stmt we just built.  */
    2559                 :      137786 :       vn_nary_op_t nary = NULL;
    2560                 :      137786 :       vn_nary_op_lookup_stmt (new_stmt, &nary);
    2561                 :      137786 :       if (nary)
    2562                 :             :         {
    2563                 :           0 :           gcc_assert (! nary->predicated_values && nary->u.result == NULL_TREE);
    2564                 :           0 :           nary->u.result = gimple_assign_lhs (new_stmt);
    2565                 :             :         }
    2566                 :             :       /* As all "inserted" statements are singleton SCCs, insert
    2567                 :             :          to the valid table.  This is strictly needed to
    2568                 :             :          avoid re-generating new value SSA_NAMEs for the same
    2569                 :             :          expression during SCC iteration over and over (the
    2570                 :             :          optimistic table gets cleared after each iteration).
    2571                 :             :          We do not need to insert into the optimistic table, as
    2572                 :             :          lookups there will fall back to the valid table.  */
    2573                 :             :       else
    2574                 :             :         {
    2575                 :      137786 :           unsigned int length = vn_nary_length_from_stmt (new_stmt);
    2576                 :      137786 :           vn_nary_op_t vno1
    2577                 :      137786 :             = alloc_vn_nary_op_noinit (length, &vn_tables_insert_obstack);
    2578                 :      137786 :           vno1->value_id = result_info->value_id;
    2579                 :      137786 :           vno1->length = length;
    2580                 :      137786 :           vno1->predicated_values = 0;
    2581                 :      137786 :           vno1->u.result = result;
    2582                 :      137786 :           init_vn_nary_op_from_stmt (vno1, as_a <gassign *> (new_stmt));
    2583                 :      137786 :           vn_nary_op_insert_into (vno1, valid_info->nary);
    2584                 :             :           /* Also do not link it into the undo chain.  */
    2585                 :      137786 :           last_inserted_nary = vno1->next;
    2586                 :      137786 :           vno1->next = (vn_nary_op_t)(void *)-1;
    2587                 :             :         }
    2588                 :      137786 :       if (dump_file && (dump_flags & TDF_DETAILS))
    2589                 :             :         {
    2590                 :         588 :           fprintf (dump_file, "Inserting name ");
    2591                 :         588 :           print_generic_expr (dump_file, result);
    2592                 :         588 :           fprintf (dump_file, " for expression ");
    2593                 :         588 :           print_gimple_expr (dump_file, new_stmt, 0, TDF_SLIM);
    2594                 :         588 :           fprintf (dump_file, "\n");
    2595                 :             :         }
    2596                 :             :     }
    2597                 :    18140560 :   return result;
    2598                 :             : }
    2599                 :             : 
    2600                 :             : /* Return a value-number for RCODE OPS... either by looking up an existing
    2601                 :             :    value-number for the simplified result or by inserting the operation.  */
    2602                 :             : 
    2603                 :             : static tree
    2604                 :      180965 : vn_nary_build_or_lookup (gimple_match_op *res_op)
    2605                 :             : {
    2606                 :           0 :   return vn_nary_build_or_lookup_1 (res_op, true, true);
    2607                 :             : }
    2608                 :             : 
    2609                 :             : /* Try to simplify the expression RCODE OPS... of type TYPE and return
    2610                 :             :    its value if present.  Update NARY with a simplified expression if
    2611                 :             :    it fits.  */
    2612                 :             : 
    2613                 :             : tree
    2614                 :     7357644 : vn_nary_simplify (vn_nary_op_t nary)
    2615                 :             : {
    2616                 :     7357644 :   if (nary->length > gimple_match_op::MAX_NUM_OPS
    2617                 :             :       /* For CONSTRUCTOR the vn_nary_op_t and gimple_match_op representation
    2618                 :             :          does not match.  */
    2619                 :     7357468 :       || nary->opcode == CONSTRUCTOR)
    2620                 :             :     return NULL_TREE;
    2621                 :     7357080 :   gimple_match_op op (gimple_match_cond::UNCOND, nary->opcode,
    2622                 :     7357080 :                       nary->type, nary->length);
    2623                 :     7357080 :   memcpy (op.ops, nary->op, sizeof (tree) * nary->length);
    2624                 :     7357080 :   tree res = vn_nary_build_or_lookup_1 (&op, false, true);
    2625                 :     7357080 :   if (op.code.is_tree_code ()
    2626                 :     7357080 :       && op.num_ops <= nary->length
    2627                 :    14713225 :       && (tree_code) op.code != CONSTRUCTOR)
    2628                 :             :     {
    2629                 :     7356144 :       nary->opcode = (tree_code) op.code;
    2630                 :     7356144 :       nary->length = op.num_ops;
    2631                 :    19274302 :       for (unsigned i = 0; i < op.num_ops; ++i)
    2632                 :    11918158 :         nary->op[i] = op.ops[i];
    2633                 :             :     }
    2634                 :             :   return res;
    2635                 :             : }
    2636                 :             : 
    2637                 :             : /* Elimination engine.  */
    2638                 :             : 
    2639                 :             : class eliminate_dom_walker : public dom_walker
    2640                 :             : {
    2641                 :             : public:
    2642                 :             :   eliminate_dom_walker (cdi_direction, bitmap);
    2643                 :             :   ~eliminate_dom_walker ();
    2644                 :             : 
    2645                 :             :   edge before_dom_children (basic_block) final override;
    2646                 :             :   void after_dom_children (basic_block) final override;
    2647                 :             : 
    2648                 :             :   virtual tree eliminate_avail (basic_block, tree op);
    2649                 :             :   virtual void eliminate_push_avail (basic_block, tree op);
    2650                 :             :   tree eliminate_insert (basic_block, gimple_stmt_iterator *gsi, tree val);
    2651                 :             : 
    2652                 :             :   void eliminate_stmt (basic_block, gimple_stmt_iterator *);
    2653                 :             : 
    2654                 :             :   unsigned eliminate_cleanup (bool region_p = false);
    2655                 :             : 
    2656                 :             :   bool do_pre;
    2657                 :             :   unsigned int el_todo;
    2658                 :             :   unsigned int eliminations;
    2659                 :             :   unsigned int insertions;
    2660                 :             : 
    2661                 :             :   /* SSA names that had their defs inserted by PRE if do_pre.  */
    2662                 :             :   bitmap inserted_exprs;
    2663                 :             : 
    2664                 :             :   /* Blocks with statements that have had their EH properties changed.  */
    2665                 :             :   bitmap need_eh_cleanup;
    2666                 :             : 
    2667                 :             :   /* Blocks with statements that have had their AB properties changed.  */
    2668                 :             :   bitmap need_ab_cleanup;
    2669                 :             : 
    2670                 :             :   /* Local state for the eliminate domwalk.  */
    2671                 :             :   auto_vec<gimple *> to_remove;
    2672                 :             :   auto_vec<gimple *> to_fixup;
    2673                 :             :   auto_vec<tree> avail;
    2674                 :             :   auto_vec<tree> avail_stack;
    2675                 :             : };
    2676                 :             : 
    2677                 :             : /* Adaptor to the elimination engine using RPO availability.  */
    2678                 :             : 
    2679                 :    12409638 : class rpo_elim : public eliminate_dom_walker
    2680                 :             : {
    2681                 :             : public:
    2682                 :     6204819 :   rpo_elim(basic_block entry_)
    2683                 :    12409638 :     : eliminate_dom_walker (CDI_DOMINATORS, NULL), entry (entry_),
    2684                 :    12409638 :       m_avail_freelist (NULL) {}
    2685                 :             : 
    2686                 :             :   tree eliminate_avail (basic_block, tree op) final override;
    2687                 :             : 
    2688                 :             :   void eliminate_push_avail (basic_block, tree) final override;
    2689                 :             : 
    2690                 :             :   basic_block entry;
    2691                 :             :   /* Freelist of avail entries which are allocated from the vn_ssa_aux
    2692                 :             :      obstack.  */
    2693                 :             :   vn_avail *m_avail_freelist;
    2694                 :             : };
    2695                 :             : 
    2696                 :             : /* Return true if BASE1 and BASE2 can be adjusted so they have the
    2697                 :             :    same address and adjust *OFFSET1 and *OFFSET2 accordingly.
    2698                 :             :    Otherwise return false.  */
    2699                 :             : 
    2700                 :             : static bool
    2701                 :     8509221 : adjust_offsets_for_equal_base_address (tree base1, poly_int64 *offset1,
    2702                 :             :                                        tree base2, poly_int64 *offset2)
    2703                 :             : {
    2704                 :     8509221 :   poly_int64 soff;
    2705                 :     8509221 :   if (TREE_CODE (base1) == MEM_REF
    2706                 :     3704041 :       && TREE_CODE (base2) == MEM_REF)
    2707                 :             :     {
    2708                 :     2983178 :       if (mem_ref_offset (base1).to_shwi (&soff))
    2709                 :             :         {
    2710                 :     2983178 :           base1 = TREE_OPERAND (base1, 0);
    2711                 :     2983178 :           *offset1 += soff * BITS_PER_UNIT;
    2712                 :             :         }
    2713                 :     2983178 :       if (mem_ref_offset (base2).to_shwi (&soff))
    2714                 :             :         {
    2715                 :     2983178 :           base2 = TREE_OPERAND (base2, 0);
    2716                 :     2983178 :           *offset2 += soff * BITS_PER_UNIT;
    2717                 :             :         }
    2718                 :     2983178 :       return operand_equal_p (base1, base2, 0);
    2719                 :             :     }
    2720                 :     5526043 :   return operand_equal_p (base1, base2, OEP_ADDRESS_OF);
    2721                 :             : }
    2722                 :             : 
    2723                 :             : /* Callback for walk_non_aliased_vuses.  Tries to perform a lookup
    2724                 :             :    from the statement defining VUSE and if not successful tries to
    2725                 :             :    translate *REFP and VR_ through an aggregate copy at the definition
    2726                 :             :    of VUSE.  If *DISAMBIGUATE_ONLY is true then do not perform translation
    2727                 :             :    of *REF and *VR.  If only disambiguation was performed then
    2728                 :             :    *DISAMBIGUATE_ONLY is set to true.  */
    2729                 :             : 
    2730                 :             : static void *
    2731                 :    43677028 : vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
    2732                 :             :                        translate_flags *disambiguate_only)
    2733                 :             : {
    2734                 :    43677028 :   vn_walk_cb_data *data = (vn_walk_cb_data *)data_;
    2735                 :    43677028 :   vn_reference_t vr = data->vr;
    2736                 :    43677028 :   gimple *def_stmt = SSA_NAME_DEF_STMT (vuse);
    2737                 :    43677028 :   tree base = ao_ref_base (ref);
    2738                 :    43677028 :   HOST_WIDE_INT offseti = 0, maxsizei, sizei = 0;
    2739                 :    43677028 :   static vec<vn_reference_op_s> lhs_ops;
    2740                 :    43677028 :   ao_ref lhs_ref;
    2741                 :    43677028 :   bool lhs_ref_ok = false;
    2742                 :    43677028 :   poly_int64 copy_size;
    2743                 :             : 
    2744                 :             :   /* First try to disambiguate after value-replacing in the definitions LHS.  */
    2745                 :    43677028 :   if (is_gimple_assign (def_stmt))
    2746                 :             :     {
    2747                 :    22238781 :       tree lhs = gimple_assign_lhs (def_stmt);
    2748                 :    22238781 :       bool valueized_anything = false;
    2749                 :             :       /* Avoid re-allocation overhead.  */
    2750                 :    22238781 :       lhs_ops.truncate (0);
    2751                 :    22238781 :       basic_block saved_rpo_bb = vn_context_bb;
    2752                 :    22238781 :       vn_context_bb = gimple_bb (def_stmt);
    2753                 :    22238781 :       if (*disambiguate_only <= TR_VALUEIZE_AND_DISAMBIGUATE)
    2754                 :             :         {
    2755                 :    15534179 :           copy_reference_ops_from_ref (lhs, &lhs_ops);
    2756                 :    15534179 :           valueize_refs_1 (&lhs_ops, &valueized_anything, true);
    2757                 :             :         }
    2758                 :    22238781 :       vn_context_bb = saved_rpo_bb;
    2759                 :    22238781 :       ao_ref_init (&lhs_ref, lhs);
    2760                 :    22238781 :       lhs_ref_ok = true;
    2761                 :    22238781 :       if (valueized_anything
    2762                 :     1771596 :           && ao_ref_init_from_vn_reference
    2763                 :     1771596 :                (&lhs_ref, ao_ref_alias_set (&lhs_ref),
    2764                 :     1771596 :                 ao_ref_base_alias_set (&lhs_ref), TREE_TYPE (lhs), lhs_ops)
    2765                 :    24010377 :           && !refs_may_alias_p_1 (ref, &lhs_ref, data->tbaa_p))
    2766                 :             :         {
    2767                 :     1491308 :           *disambiguate_only = TR_VALUEIZE_AND_DISAMBIGUATE;
    2768                 :     7776464 :           return NULL;
    2769                 :             :         }
    2770                 :             : 
    2771                 :             :       /* When the def is a CLOBBER we can optimistically disambiguate
    2772                 :             :          against it since any overlap it would be undefined behavior.
    2773                 :             :          Avoid this for obvious must aliases to save compile-time though.
    2774                 :             :          We also may not do this when the query is used for redundant
    2775                 :             :          store removal.  */
    2776                 :    20747473 :       if (!data->redundant_store_removal_p
    2777                 :    10658323 :           && gimple_clobber_p (def_stmt)
    2778                 :    21272932 :           && !operand_equal_p (ao_ref_base (&lhs_ref), base, OEP_ADDRESS_OF))
    2779                 :             :         {
    2780                 :      496023 :           *disambiguate_only = TR_DISAMBIGUATE;
    2781                 :      496023 :           return NULL;
    2782                 :             :         }
    2783                 :             : 
    2784                 :             :       /* Besides valueizing the LHS we can also use access-path based
    2785                 :             :          disambiguation on the original non-valueized ref.  */
    2786                 :    20251450 :       if (!ref->ref
    2787                 :             :           && lhs_ref_ok
    2788                 :     2657369 :           && data->orig_ref.ref)
    2789                 :             :         {
    2790                 :             :           /* We want to use the non-valueized LHS for this, but avoid redundant
    2791                 :             :              work.  */
    2792                 :     1799986 :           ao_ref *lref = &lhs_ref;
    2793                 :     1799986 :           ao_ref lref_alt;
    2794                 :     1799986 :           if (valueized_anything)
    2795                 :             :             {
    2796                 :      119110 :               ao_ref_init (&lref_alt, lhs);
    2797                 :      119110 :               lref = &lref_alt;
    2798                 :             :             }
    2799                 :     1799986 :           if (!refs_may_alias_p_1 (&data->orig_ref, lref, data->tbaa_p))
    2800                 :             :             {
    2801                 :      246656 :               *disambiguate_only = (valueized_anything
    2802                 :      123328 :                                     ? TR_VALUEIZE_AND_DISAMBIGUATE
    2803                 :             :                                     : TR_DISAMBIGUATE);
    2804                 :      123328 :               return NULL;
    2805                 :             :             }
    2806                 :             :         }
    2807                 :             : 
    2808                 :             :       /* If we reach a clobbering statement try to skip it and see if
    2809                 :             :          we find a VN result with exactly the same value as the
    2810                 :             :          possible clobber.  In this case we can ignore the clobber
    2811                 :             :          and return the found value.  */
    2812                 :    20128122 :       if (!gimple_has_volatile_ops (def_stmt)
    2813                 :    17161411 :           && ((is_gimple_reg_type (TREE_TYPE (lhs))
    2814                 :    12614147 :                && types_compatible_p (TREE_TYPE (lhs), vr->type)
    2815                 :     9643351 :                && !storage_order_barrier_p (lhs)
    2816                 :     9643351 :                && !reverse_storage_order_for_component_p (lhs))
    2817                 :     7518062 :               || TREE_CODE (gimple_assign_rhs1 (def_stmt)) == CONSTRUCTOR)
    2818                 :    10682792 :           && (ref->ref || data->orig_ref.ref)
    2819                 :    10264122 :           && !data->mask
    2820                 :    10242436 :           && data->partial_defs.is_empty ()
    2821                 :    10240312 :           && multiple_p (get_object_alignment
    2822                 :             :                            (ref->ref ? ref->ref : data->orig_ref.ref),
    2823                 :             :                            ref->size)
    2824                 :    42967425 :           && multiple_p (get_object_alignment (lhs), ref->size))
    2825                 :             :         {
    2826                 :     9852389 :           HOST_WIDE_INT offset2i, size2i;
    2827                 :     9852389 :           poly_int64 offset = ref->offset;
    2828                 :     9852389 :           poly_int64 maxsize = ref->max_size;
    2829                 :             : 
    2830                 :     9852389 :           gcc_assert (lhs_ref_ok);
    2831                 :     9852389 :           tree base2 = ao_ref_base (&lhs_ref);
    2832                 :     9852389 :           poly_int64 offset2 = lhs_ref.offset;
    2833                 :     9852389 :           poly_int64 size2 = lhs_ref.size;
    2834                 :     9852389 :           poly_int64 maxsize2 = lhs_ref.max_size;
    2835                 :             : 
    2836                 :     9852389 :           tree rhs = gimple_assign_rhs1 (def_stmt);
    2837                 :     9852389 :           if (TREE_CODE (rhs) == CONSTRUCTOR)
    2838                 :     1014682 :             rhs = integer_zero_node;
    2839                 :             :           /* ???  We may not compare to ahead values which might be from
    2840                 :             :              a different loop iteration but only to loop invariants.  Use
    2841                 :             :              CONSTANT_CLASS_P (unvalueized!) as conservative approximation.
    2842                 :             :              The one-hop lookup below doesn't have this issue since there's
    2843                 :             :              a virtual PHI before we ever reach a backedge to cross.
    2844                 :             :              We can skip multiple defs as long as they are from the same
    2845                 :             :              value though.  */
    2846                 :     9852389 :           if (data->same_val
    2847                 :     9852389 :               && !operand_equal_p (data->same_val, rhs))
    2848                 :             :             ;
    2849                 :             :           /* When this is a (partial) must-def, leave it to handling
    2850                 :             :              below in case we are interested in the value.  */
    2851                 :     9572567 :           else if (!(*disambiguate_only > TR_TRANSLATE)
    2852                 :     3297254 :                    && base2
    2853                 :     3297254 :                    && known_eq (maxsize2, size2)
    2854                 :     2319236 :                    && adjust_offsets_for_equal_base_address (base, &offset,
    2855                 :             :                                                              base2, &offset2)
    2856                 :     1123182 :                    && offset2.is_constant (&offset2i)
    2857                 :     1123182 :                    && size2.is_constant (&size2i)
    2858                 :     1123182 :                    && maxsize.is_constant (&maxsizei)
    2859                 :     1123182 :                    && offset.is_constant (&offseti)
    2860                 :    10695749 :                    && ranges_known_overlap_p (offseti, maxsizei, offset2i,
    2861                 :             :                                               size2i))
    2862                 :             :             ;
    2863                 :     8534914 :           else if (CONSTANT_CLASS_P (rhs))
    2864                 :             :             {
    2865                 :     4111475 :               if (dump_file && (dump_flags & TDF_DETAILS))
    2866                 :             :                 {
    2867                 :        1902 :                   fprintf (dump_file,
    2868                 :             :                            "Skipping possible redundant definition ");
    2869                 :        1902 :                   print_gimple_stmt (dump_file, def_stmt, 0);
    2870                 :             :                 }
    2871                 :             :               /* Delay the actual compare of the values to the end of the walk
    2872                 :             :                  but do not update last_vuse from here.  */
    2873                 :     4111475 :               data->last_vuse_ptr = NULL;
    2874                 :     4111475 :               data->same_val = rhs;
    2875                 :     4174497 :               return NULL;
    2876                 :             :             }
    2877                 :             :           else
    2878                 :             :             {
    2879                 :     4423439 :               tree saved_vuse = vr->vuse;
    2880                 :     4423439 :               hashval_t saved_hashcode = vr->hashcode;
    2881                 :     4423439 :               if (vr->vuse)
    2882                 :     4423439 :                 vr->hashcode = vr->hashcode - SSA_NAME_VERSION (vr->vuse);
    2883                 :     8846878 :               vr->vuse = vuse_ssa_val (gimple_vuse (def_stmt));
    2884                 :     4423439 :               if (vr->vuse)
    2885                 :     4423439 :                 vr->hashcode = vr->hashcode + SSA_NAME_VERSION (vr->vuse);
    2886                 :     4423439 :               vn_reference_t vnresult = NULL;
    2887                 :             :               /* Do not use vn_reference_lookup_2 since that might perform
    2888                 :             :                  expression hashtable insertion but this lookup crosses
    2889                 :             :                  a possible may-alias making such insertion conditionally
    2890                 :             :                  invalid.  */
    2891                 :     4423439 :               vn_reference_lookup_1 (vr, &vnresult);
    2892                 :             :               /* Need to restore vr->vuse and vr->hashcode.  */
    2893                 :     4423439 :               vr->vuse = saved_vuse;
    2894                 :     4423439 :               vr->hashcode = saved_hashcode;
    2895                 :     4423439 :               if (vnresult)
    2896                 :             :                 {
    2897                 :      244671 :                   if (TREE_CODE (rhs) == SSA_NAME)
    2898                 :      243108 :                     rhs = SSA_VAL (rhs);
    2899                 :      244671 :                   if (vnresult->result
    2900                 :      244671 :                       && operand_equal_p (vnresult->result, rhs, 0))
    2901                 :       63022 :                     return vnresult;
    2902                 :             :                 }
    2903                 :             :             }
    2904                 :             :         }
    2905                 :             :     }
    2906                 :    21438247 :   else if (*disambiguate_only <= TR_VALUEIZE_AND_DISAMBIGUATE
    2907                 :    20013965 :            && gimple_call_builtin_p (def_stmt, BUILT_IN_NORMAL)
    2908                 :    23527272 :            && gimple_call_num_args (def_stmt) <= 4)
    2909                 :             :     {
    2910                 :             :       /* For builtin calls valueize its arguments and call the
    2911                 :             :          alias oracle again.  Valueization may improve points-to
    2912                 :             :          info of pointers and constify size and position arguments.
    2913                 :             :          Originally this was motivated by PR61034 which has
    2914                 :             :          conditional calls to free falsely clobbering ref because
    2915                 :             :          of imprecise points-to info of the argument.  */
    2916                 :             :       tree oldargs[4];
    2917                 :             :       bool valueized_anything = false;
    2918                 :     5116345 :       for (unsigned i = 0; i < gimple_call_num_args (def_stmt); ++i)
    2919                 :             :         {
    2920                 :     3546530 :           oldargs[i] = gimple_call_arg (def_stmt, i);
    2921                 :     3546530 :           tree val = vn_valueize (oldargs[i]);
    2922                 :     3546530 :           if (val != oldargs[i])
    2923                 :             :             {
    2924                 :      132095 :               gimple_call_set_arg (def_stmt, i, val);
    2925                 :      132095 :               valueized_anything = true;
    2926                 :             :             }
    2927                 :             :         }
    2928                 :     1569815 :       if (valueized_anything)
    2929                 :             :         {
    2930                 :      200044 :           bool res = call_may_clobber_ref_p_1 (as_a <gcall *> (def_stmt),
    2931                 :      100022 :                                                ref, data->tbaa_p);
    2932                 :      369119 :           for (unsigned i = 0; i < gimple_call_num_args (def_stmt); ++i)
    2933                 :      269097 :             gimple_call_set_arg (def_stmt, i, oldargs[i]);
    2934                 :      100022 :           if (!res)
    2935                 :             :             {
    2936                 :       25893 :               *disambiguate_only = TR_VALUEIZE_AND_DISAMBIGUATE;
    2937                 :       25893 :               return NULL;
    2938                 :             :             }
    2939                 :             :         }
    2940                 :             :     }
    2941                 :             : 
    2942                 :    37365979 :   if (*disambiguate_only > TR_TRANSLATE)
    2943                 :             :     return (void *)-1;
    2944                 :             : 
    2945                 :             :   /* If we cannot constrain the size of the reference we cannot
    2946                 :             :      test if anything kills it.  */
    2947                 :    25638992 :   if (!ref->max_size_known_p ())
    2948                 :             :     return (void *)-1;
    2949                 :             : 
    2950                 :    25228847 :   poly_int64 offset = ref->offset;
    2951                 :    25228847 :   poly_int64 maxsize = ref->max_size;
    2952                 :             : 
    2953                 :             :   /* def_stmt may-defs *ref.  See if we can derive a value for *ref
    2954                 :             :      from that definition.
    2955                 :             :      1) Memset.  */
    2956                 :    25228847 :   if (is_gimple_reg_type (vr->type)
    2957                 :    24910779 :       && (gimple_call_builtin_p (def_stmt, BUILT_IN_MEMSET)
    2958                 :    24823668 :           || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMSET_CHK))
    2959                 :       87653 :       && (integer_zerop (gimple_call_arg (def_stmt, 1))
    2960                 :       32243 :           || ((TREE_CODE (gimple_call_arg (def_stmt, 1)) == INTEGER_CST
    2961                 :        8204 :                || (INTEGRAL_TYPE_P (vr->type) && known_eq (ref->size, 8)))
    2962                 :             :               && CHAR_BIT == 8
    2963                 :             :               && BITS_PER_UNIT == 8
    2964                 :             :               && BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN
    2965                 :       31387 :               && offset.is_constant (&offseti)
    2966                 :       31387 :               && ref->size.is_constant (&sizei)
    2967                 :       31387 :               && (offseti % BITS_PER_UNIT == 0
    2968                 :          39 :                   || TREE_CODE (gimple_call_arg (def_stmt, 1)) == INTEGER_CST)))
    2969                 :       86797 :       && (poly_int_tree_p (gimple_call_arg (def_stmt, 2))
    2970                 :       36176 :           || (TREE_CODE (gimple_call_arg (def_stmt, 2)) == SSA_NAME
    2971                 :       36176 :               && poly_int_tree_p (SSA_VAL (gimple_call_arg (def_stmt, 2)))))
    2972                 :    25280006 :       && (TREE_CODE (gimple_call_arg (def_stmt, 0)) == ADDR_EXPR
    2973                 :       27862 :           || TREE_CODE (gimple_call_arg (def_stmt, 0)) == SSA_NAME))
    2974                 :             :     {
    2975                 :       51118 :       tree base2;
    2976                 :       51118 :       poly_int64 offset2, size2, maxsize2;
    2977                 :       51118 :       bool reverse;
    2978                 :       51118 :       tree ref2 = gimple_call_arg (def_stmt, 0);
    2979                 :       51118 :       if (TREE_CODE (ref2) == SSA_NAME)
    2980                 :             :         {
    2981                 :       27821 :           ref2 = SSA_VAL (ref2);
    2982                 :       27821 :           if (TREE_CODE (ref2) == SSA_NAME
    2983                 :       27821 :               && (TREE_CODE (base) != MEM_REF
    2984                 :       18054 :                   || TREE_OPERAND (base, 0) != ref2))
    2985                 :             :             {
    2986                 :       21708 :               gimple *def_stmt = SSA_NAME_DEF_STMT (ref2);
    2987                 :       21708 :               if (gimple_assign_single_p (def_stmt)
    2988                 :       21708 :                   && gimple_assign_rhs_code (def_stmt) == ADDR_EXPR)
    2989                 :         720 :                 ref2 = gimple_assign_rhs1 (def_stmt);
    2990                 :             :             }
    2991                 :             :         }
    2992                 :       51118 :       if (TREE_CODE (ref2) == ADDR_EXPR)
    2993                 :             :         {
    2994                 :       26993 :           ref2 = TREE_OPERAND (ref2, 0);
    2995                 :       26993 :           base2 = get_ref_base_and_extent (ref2, &offset2, &size2, &maxsize2,
    2996                 :             :                                            &reverse);
    2997                 :       26993 :           if (!known_size_p (maxsize2)
    2998                 :       26953 :               || !known_eq (maxsize2, size2)
    2999                 :       53872 :               || !operand_equal_p (base, base2, OEP_ADDRESS_OF))
    3000                 :       54999 :             return (void *)-1;
    3001                 :             :         }
    3002                 :       24125 :       else if (TREE_CODE (ref2) == SSA_NAME)
    3003                 :             :         {
    3004                 :       24125 :           poly_int64 soff;
    3005                 :       24125 :           if (TREE_CODE (base) != MEM_REF
    3006                 :       41673 :               || !(mem_ref_offset (base)
    3007                 :       35096 :                    << LOG2_BITS_PER_UNIT).to_shwi (&soff))
    3008                 :       20503 :             return (void *)-1;
    3009                 :       17548 :           offset += soff;
    3010                 :       17548 :           offset2 = 0;
    3011                 :       17548 :           if (TREE_OPERAND (base, 0) != ref2)
    3012                 :             :             {
    3013                 :       14411 :               gimple *def = SSA_NAME_DEF_STMT (ref2);
    3014                 :       14411 :               if (is_gimple_assign (def)
    3015                 :       13331 :                   && gimple_assign_rhs_code (def) == POINTER_PLUS_EXPR
    3016                 :       11374 :                   && gimple_assign_rhs1 (def) == TREE_OPERAND (base, 0)
    3017                 :       14926 :                   && poly_int_tree_p (gimple_assign_rhs2 (def)))
    3018                 :             :                 {
    3019                 :         485 :                   tree rhs2 = gimple_assign_rhs2 (def);
    3020                 :         485 :                   if (!(poly_offset_int::from (wi::to_poly_wide (rhs2),
    3021                 :             :                                                SIGNED)
    3022                 :         485 :                         << LOG2_BITS_PER_UNIT).to_shwi (&offset2))
    3023                 :             :                     return (void *)-1;
    3024                 :         485 :                   ref2 = gimple_assign_rhs1 (def);
    3025                 :         485 :                   if (TREE_CODE (ref2) == SSA_NAME)
    3026                 :         485 :                     ref2 = SSA_VAL (ref2);
    3027                 :             :                 }
    3028                 :             :               else
    3029                 :             :                 return (void *)-1;
    3030                 :             :             }
    3031                 :             :         }
    3032                 :             :       else
    3033                 :             :         return (void *)-1;
    3034                 :       26377 :       tree len = gimple_call_arg (def_stmt, 2);
    3035                 :       26377 :       HOST_WIDE_INT leni, offset2i;
    3036                 :       26377 :       if (TREE_CODE (len) == SSA_NAME)
    3037                 :         254 :         len = SSA_VAL (len);
    3038                 :             :       /* Sometimes the above trickery is smarter than alias analysis.  Take
    3039                 :             :          advantage of that.  */
    3040                 :       26377 :       if (!ranges_maybe_overlap_p (offset, maxsize, offset2,
    3041                 :       52754 :                                    (wi::to_poly_offset (len)
    3042                 :       26377 :                                     << LOG2_BITS_PER_UNIT)))
    3043                 :             :         return NULL;
    3044                 :       52715 :       if (data->partial_defs.is_empty ()
    3045                 :       26338 :           && known_subrange_p (offset, maxsize, offset2,
    3046                 :       26338 :                                wi::to_poly_offset (len) << LOG2_BITS_PER_UNIT))
    3047                 :             :         {
    3048                 :       25910 :           tree val;
    3049                 :       25910 :           if (integer_zerop (gimple_call_arg (def_stmt, 1)))
    3050                 :       20811 :             val = build_zero_cst (vr->type);
    3051                 :        5099 :           else if (INTEGRAL_TYPE_P (vr->type)
    3052                 :        3982 :                    && known_eq (ref->size, 8)
    3053                 :        8319 :                    && offseti % BITS_PER_UNIT == 0)
    3054                 :             :             {
    3055                 :        3220 :               gimple_match_op res_op (gimple_match_cond::UNCOND, NOP_EXPR,
    3056                 :        3220 :                                       vr->type, gimple_call_arg (def_stmt, 1));
    3057                 :        3220 :               val = vn_nary_build_or_lookup (&res_op);
    3058                 :        3220 :               if (!val
    3059                 :        3220 :                   || (TREE_CODE (val) == SSA_NAME
    3060                 :         626 :                       && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val)))
    3061                 :           0 :                 return (void *)-1;
    3062                 :             :             }
    3063                 :             :           else
    3064                 :             :             {
    3065                 :        1879 :               unsigned buflen
    3066                 :        1879 :                 = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (vr->type)) + 1;
    3067                 :        1879 :               if (INTEGRAL_TYPE_P (vr->type)
    3068                 :        1879 :                   && TYPE_MODE (vr->type) != BLKmode)
    3069                 :        1522 :                 buflen = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (vr->type)) + 1;
    3070                 :        1879 :               unsigned char *buf = XALLOCAVEC (unsigned char, buflen);
    3071                 :        1879 :               memset (buf, TREE_INT_CST_LOW (gimple_call_arg (def_stmt, 1)),
    3072                 :             :                       buflen);
    3073                 :        1879 :               if (BYTES_BIG_ENDIAN)
    3074                 :             :                 {
    3075                 :             :                   unsigned int amnt
    3076                 :             :                     = (((unsigned HOST_WIDE_INT) offseti + sizei)
    3077                 :             :                        % BITS_PER_UNIT);
    3078                 :             :                   if (amnt)
    3079                 :             :                     {
    3080                 :             :                       shift_bytes_in_array_right (buf, buflen,
    3081                 :             :                                                   BITS_PER_UNIT - amnt);
    3082                 :             :                       buf++;
    3083                 :             :                       buflen--;
    3084                 :             :                     }
    3085                 :             :                 }
    3086                 :        1879 :               else if (offseti % BITS_PER_UNIT != 0)
    3087                 :             :                 {
    3088                 :           7 :                   unsigned int amnt
    3089                 :             :                     = BITS_PER_UNIT - ((unsigned HOST_WIDE_INT) offseti
    3090                 :           7 :                                        % BITS_PER_UNIT);
    3091                 :           7 :                   shift_bytes_in_array_left (buf, buflen, amnt);
    3092                 :           7 :                   buf++;
    3093                 :           7 :                   buflen--;
    3094                 :             :                 }
    3095                 :        1879 :               val = native_interpret_expr (vr->type, buf, buflen);
    3096                 :        1879 :               if (!val)
    3097                 :             :                 return (void *)-1;
    3098                 :             :             }
    3099                 :       25910 :           return data->finish (0, 0, val);
    3100                 :             :         }
    3101                 :             :       /* For now handle clearing memory with partial defs.  */
    3102                 :         467 :       else if (known_eq (ref->size, maxsize)
    3103                 :         397 :                && integer_zerop (gimple_call_arg (def_stmt, 1))
    3104                 :         114 :                && tree_fits_poly_int64_p (len)
    3105                 :         110 :                && tree_to_poly_int64 (len).is_constant (&leni)
    3106                 :         110 :                && leni <= INTTYPE_MAXIMUM (HOST_WIDE_INT) / BITS_PER_UNIT
    3107                 :         110 :                && offset.is_constant (&offseti)
    3108                 :         110 :                && offset2.is_constant (&offset2i)
    3109                 :         110 :                && maxsize.is_constant (&maxsizei)
    3110                 :         467 :                && ranges_known_overlap_p (offseti, maxsizei, offset2i,
    3111                 :         467 :                                           leni << LOG2_BITS_PER_UNIT))
    3112                 :             :         {
    3113                 :         110 :           pd_data pd;
    3114                 :         110 :           pd.rhs = build_constructor (NULL_TREE, NULL);
    3115                 :         110 :           pd.rhs_off = 0;
    3116                 :         110 :           pd.offset = offset2i;
    3117                 :         110 :           pd.size = leni << LOG2_BITS_PER_UNIT;
    3118                 :         110 :           return data->push_partial_def (pd, 0, 0, offseti, maxsizei);
    3119                 :             :         }
    3120                 :             :     }
    3121                 :             : 
    3122                 :             :   /* 2) Assignment from an empty CONSTRUCTOR.  */
    3123                 :    25177729 :   else if (is_gimple_reg_type (vr->type)
    3124                 :    24859661 :            && gimple_assign_single_p (def_stmt)
    3125                 :     9371989 :            && gimple_assign_rhs_code (def_stmt) == CONSTRUCTOR
    3126                 :     3581994 :            && CONSTRUCTOR_NELTS (gimple_assign_rhs1 (def_stmt)) == 0
    3127                 :    28759723 :            && !TREE_THIS_VOLATILE (gimple_assign_lhs (def_stmt)))
    3128                 :             :     {
    3129                 :     3581994 :       tree base2;
    3130                 :     3581994 :       poly_int64 offset2, size2, maxsize2;
    3131                 :     3581994 :       HOST_WIDE_INT offset2i, size2i;
    3132                 :     3581994 :       gcc_assert (lhs_ref_ok);
    3133                 :     3581994 :       base2 = ao_ref_base (&lhs_ref);
    3134                 :     3581994 :       offset2 = lhs_ref.offset;
    3135                 :     3581994 :       size2 = lhs_ref.size;
    3136                 :     3581994 :       maxsize2 = lhs_ref.max_size;
    3137                 :     3581994 :       if (known_size_p (maxsize2)
    3138                 :     3581815 :           && known_eq (maxsize2, size2)
    3139                 :     7163763 :           && adjust_offsets_for_equal_base_address (base, &offset,
    3140                 :             :                                                     base2, &offset2))
    3141                 :             :         {
    3142                 :     3549119 :           if (data->partial_defs.is_empty ()
    3143                 :     3545172 :               && known_subrange_p (offset, maxsize, offset2, size2))
    3144                 :             :             {
    3145                 :             :               /* While technically undefined behavior do not optimize
    3146                 :             :                  a full read from a clobber.  */
    3147                 :     3532689 :               if (gimple_clobber_p (def_stmt))
    3148                 :     3549069 :                 return (void *)-1;
    3149                 :      962718 :               tree val = build_zero_cst (vr->type);
    3150                 :      962718 :               return data->finish (ao_ref_alias_set (&lhs_ref),
    3151                 :      962718 :                                    ao_ref_base_alias_set (&lhs_ref), val);
    3152                 :             :             }
    3153                 :       16430 :           else if (known_eq (ref->size, maxsize)
    3154                 :       16380 :                    && maxsize.is_constant (&maxsizei)
    3155                 :       16380 :                    && offset.is_constant (&offseti)
    3156                 :       16380 :                    && offset2.is_constant (&offset2i)
    3157                 :       16380 :                    && size2.is_constant (&size2i)
    3158                 :       16430 :                    && ranges_known_overlap_p (offseti, maxsizei,
    3159                 :             :                                               offset2i, size2i))
    3160                 :             :             {
    3161                 :             :               /* Let clobbers be consumed by the partial-def tracker
    3162                 :             :                  which can choose to ignore them if they are shadowed
    3163                 :             :                  by a later def.  */
    3164                 :       16380 :               pd_data pd;
    3165                 :       16380 :               pd.rhs = gimple_assign_rhs1 (def_stmt);
    3166                 :       16380 :               pd.rhs_off = 0;
    3167                 :       16380 :               pd.offset = offset2i;
    3168                 :       16380 :               pd.size = size2i;
    3169                 :       16380 :               return data->push_partial_def (pd, ao_ref_alias_set (&lhs_ref),
    3170                 :             :                                              ao_ref_base_alias_set (&lhs_ref),
    3171                 :             :                                              offseti, maxsizei);
    3172                 :             :             }
    3173                 :             :         }
    3174                 :             :     }
    3175                 :             : 
    3176                 :             :   /* 3) Assignment from a constant.  We can use folds native encode/interpret
    3177                 :             :      routines to extract the assigned bits.  */
    3178                 :    21595735 :   else if (known_eq (ref->size, maxsize)
    3179                 :    21051701 :            && is_gimple_reg_type (vr->type)
    3180                 :    20733633 :            && !reverse_storage_order_for_component_p (vr->operands)
    3181                 :    20730906 :            && !contains_storage_order_barrier_p (vr->operands)
    3182                 :    20730906 :            && gimple_assign_single_p (def_stmt)
    3183                 :     5446053 :            && !TREE_THIS_VOLATILE (gimple_assign_lhs (def_stmt))
    3184                 :             :            && CHAR_BIT == 8
    3185                 :             :            && BITS_PER_UNIT == 8
    3186                 :             :            && BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN
    3187                 :             :            /* native_encode and native_decode operate on arrays of bytes
    3188                 :             :               and so fundamentally need a compile-time size and offset.  */
    3189                 :     5443188 :            && maxsize.is_constant (&maxsizei)
    3190                 :     5443188 :            && offset.is_constant (&offseti)
    3191                 :    27038923 :            && (is_gimple_min_invariant (gimple_assign_rhs1 (def_stmt))
    3192                 :     4650030 :                || (TREE_CODE (gimple_assign_rhs1 (def_stmt)) == SSA_NAME
    3193                 :     1963351 :                    && is_gimple_min_invariant (SSA_VAL (gimple_assign_rhs1 (def_stmt))))))
    3194                 :             :     {
    3195                 :      807968 :       tree lhs = gimple_assign_lhs (def_stmt);
    3196                 :      807968 :       tree base2;
    3197                 :      807968 :       poly_int64 offset2, size2, maxsize2;
    3198                 :      807968 :       HOST_WIDE_INT offset2i, size2i;
    3199                 :      807968 :       bool reverse;
    3200                 :      807968 :       gcc_assert (lhs_ref_ok);
    3201                 :      807968 :       base2 = ao_ref_base (&lhs_ref);
    3202                 :      807968 :       offset2 = lhs_ref.offset;
    3203                 :      807968 :       size2 = lhs_ref.size;
    3204                 :      807968 :       maxsize2 = lhs_ref.max_size;
    3205                 :      807968 :       reverse = reverse_storage_order_for_component_p (lhs);
    3206                 :      807968 :       if (base2
    3207                 :      807968 :           && !reverse
    3208                 :      807140 :           && !storage_order_barrier_p (lhs)
    3209                 :      807140 :           && known_eq (maxsize2, size2)
    3210                 :      781563 :           && adjust_offsets_for_equal_base_address (base, &offset,
    3211                 :             :                                                     base2, &offset2)
    3212                 :       79026 :           && offset.is_constant (&offseti)
    3213                 :       79026 :           && offset2.is_constant (&offset2i)
    3214                 :      807968 :           && size2.is_constant (&size2i))
    3215                 :             :         {
    3216                 :       79026 :           if (data->partial_defs.is_empty ()
    3217                 :       63856 :               && known_subrange_p (offseti, maxsizei, offset2, size2))
    3218                 :             :             {
    3219                 :             :               /* We support up to 512-bit values (for V8DFmode).  */
    3220                 :       44981 :               unsigned char buffer[65];
    3221                 :       44981 :               int len;
    3222                 :             : 
    3223                 :       44981 :               tree rhs = gimple_assign_rhs1 (def_stmt);
    3224                 :       44981 :               if (TREE_CODE (rhs) == SSA_NAME)
    3225                 :        1314 :                 rhs = SSA_VAL (rhs);
    3226                 :       89962 :               len = native_encode_expr (rhs,
    3227                 :             :                                         buffer, sizeof (buffer) - 1,
    3228                 :       44981 :                                         (offseti - offset2i) / BITS_PER_UNIT);
    3229                 :       44981 :               if (len > 0 && len * BITS_PER_UNIT >= maxsizei)
    3230                 :             :                 {
    3231                 :       41960 :                   tree type = vr->type;
    3232                 :       41960 :                   unsigned char *buf = buffer;
    3233                 :       41960 :                   unsigned int amnt = 0;
    3234                 :             :                   /* Make sure to interpret in a type that has a range
    3235                 :             :                      covering the whole access size.  */
    3236                 :       41960 :                   if (INTEGRAL_TYPE_P (vr->type)
    3237                 :       41960 :                       && maxsizei != TYPE_PRECISION (vr->type))
    3238                 :        1722 :                     type = build_nonstandard_integer_type (maxsizei,
    3239                 :         861 :                                                            TYPE_UNSIGNED (type));
    3240                 :       41960 :                   if (BYTES_BIG_ENDIAN)
    3241                 :             :                     {
    3242                 :             :                       /* For big-endian native_encode_expr stored the rhs
    3243                 :             :                          such that the LSB of it is the LSB of buffer[len - 1].
    3244                 :             :                          That bit is stored into memory at position
    3245                 :             :                          offset2 + size2 - 1, i.e. in byte
    3246                 :             :                          base + (offset2 + size2 - 1) / BITS_PER_UNIT.
    3247                 :             :                          E.g. for offset2 1 and size2 14, rhs -1 and memory
    3248                 :             :                          previously cleared that is:
    3249                 :             :                          0        1
    3250                 :             :                          01111111|11111110
    3251                 :             :                          Now, if we want to extract offset 2 and size 12 from
    3252                 :             :                          it using native_interpret_expr (which actually works
    3253                 :             :                          for integral bitfield types in terms of byte size of
    3254                 :             :                          the mode), the native_encode_expr stored the value
    3255                 :             :                          into buffer as
    3256                 :             :                          XX111111|11111111
    3257                 :             :                          and returned len 2 (the X bits are outside of
    3258                 :             :                          precision).
    3259                 :             :                          Let sz be maxsize / BITS_PER_UNIT if not extracting
    3260                 :             :                          a bitfield, and GET_MODE_SIZE otherwise.
    3261                 :             :                          We need to align the LSB of the value we want to
    3262                 :             :                          extract as the LSB of buf[sz - 1].
    3263                 :             :                          The LSB from memory we need to read is at position
    3264                 :             :                          offset + maxsize - 1.  */
    3265                 :             :                       HOST_WIDE_INT sz = maxsizei / BITS_PER_UNIT;
    3266                 :             :                       if (INTEGRAL_TYPE_P (type))
    3267                 :             :                         {
    3268                 :             :                           if (TYPE_MODE (type) != BLKmode)
    3269                 :             :                             sz = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type));
    3270                 :             :                           else
    3271                 :             :                             sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (type));
    3272                 :             :                         }
    3273                 :             :                       amnt = ((unsigned HOST_WIDE_INT) offset2i + size2i
    3274                 :             :                               - offseti - maxsizei) % BITS_PER_UNIT;
    3275                 :             :                       if (amnt)
    3276                 :             :                         shift_bytes_in_array_right (buffer, len, amnt);
    3277                 :             :                       amnt = ((unsigned HOST_WIDE_INT) offset2i + size2i
    3278                 :             :                               - offseti - maxsizei - amnt) / BITS_PER_UNIT;
    3279                 :             :                       if ((unsigned HOST_WIDE_INT) sz + amnt > (unsigned) len)
    3280                 :             :                         len = 0;
    3281                 :             :                       else
    3282                 :             :                         {
    3283                 :             :                           buf = buffer + len - sz - amnt;
    3284                 :             :                           len -= (buf - buffer);
    3285                 :             :                         }
    3286                 :             :                     }
    3287                 :             :                   else
    3288                 :             :                     {
    3289                 :       41960 :                       amnt = ((unsigned HOST_WIDE_INT) offset2i
    3290                 :       41960 :                               - offseti) % BITS_PER_UNIT;
    3291                 :       41960 :                       if (amnt)
    3292                 :             :                         {
    3293                 :         305 :                           buffer[len] = 0;
    3294                 :         305 :                           shift_bytes_in_array_left (buffer, len + 1, amnt);
    3295                 :         305 :                           buf = buffer + 1;
    3296                 :             :                         }
    3297                 :             :                     }
    3298                 :       41960 :                   tree val = native_interpret_expr (type, buf, len);
    3299                 :             :                   /* If we chop off bits because the types precision doesn't
    3300                 :             :                      match the memory access size this is ok when optimizing
    3301                 :             :                      reads but not when called from the DSE code during
    3302                 :             :                      elimination.  */
    3303                 :       41960 :                   if (val
    3304                 :       41958 :                       && type != vr->type)
    3305                 :             :                     {
    3306                 :         861 :                       if (! int_fits_type_p (val, vr->type))
    3307                 :             :                         val = NULL_TREE;
    3308                 :             :                       else
    3309                 :         861 :                         val = fold_convert (vr->type, val);
    3310                 :             :                     }
    3311                 :             : 
    3312                 :       41958 :                   if (val)
    3313                 :       41958 :                     return data->finish (ao_ref_alias_set (&lhs_ref),
    3314                 :       41958 :                                          ao_ref_base_alias_set (&lhs_ref), val);
    3315                 :             :                 }
    3316                 :             :             }
    3317                 :       34045 :           else if (ranges_known_overlap_p (offseti, maxsizei, offset2i,
    3318                 :             :                                            size2i))
    3319                 :             :             {
    3320                 :       34045 :               pd_data pd;
    3321                 :       34045 :               tree rhs = gimple_assign_rhs1 (def_stmt);
    3322                 :       34045 :               if (TREE_CODE (rhs) == SSA_NAME)
    3323                 :        2578 :                 rhs = SSA_VAL (rhs);
    3324                 :       34045 :               pd.rhs = rhs;
    3325                 :       34045 :               pd.rhs_off = 0;
    3326                 :       34045 :               pd.offset = offset2i;
    3327                 :       34045 :               pd.size = size2i;
    3328                 :       34045 :               return data->push_partial_def (pd, ao_ref_alias_set (&lhs_ref),
    3329                 :             :                                              ao_ref_base_alias_set (&lhs_ref),
    3330                 :             :                                              offseti, maxsizei);
    3331                 :             :             }
    3332                 :             :         }
    3333                 :             :     }
    3334                 :             : 
    3335                 :             :   /* 4) Assignment from an SSA name which definition we may be able
    3336                 :             :      to access pieces from or we can combine to a larger entity.  */
    3337                 :    20787767 :   else if (known_eq (ref->size, maxsize)
    3338                 :    20243733 :            && is_gimple_reg_type (vr->type)
    3339                 :    19925665 :            && !reverse_storage_order_for_component_p (vr->operands)
    3340                 :    19922938 :            && !contains_storage_order_barrier_p (vr->operands)
    3341                 :    19922938 :            && gimple_assign_single_p (def_stmt)
    3342                 :     4638085 :            && !TREE_THIS_VOLATILE (gimple_assign_lhs (def_stmt))
    3343                 :    25422987 :            && TREE_CODE (gimple_assign_rhs1 (def_stmt)) == SSA_NAME)
    3344                 :             :     {
    3345                 :     1948541 :       tree lhs = gimple_assign_lhs (def_stmt);
    3346                 :     1948541 :       tree base2;
    3347                 :     1948541 :       poly_int64 offset2, size2, maxsize2;
    3348                 :     1948541 :       HOST_WIDE_INT offset2i, size2i, offseti;
    3349                 :     1948541 :       bool reverse;
    3350                 :     1948541 :       gcc_assert (lhs_ref_ok);
    3351                 :     1948541 :       base2 = ao_ref_base (&lhs_ref);
    3352                 :     1948541 :       offset2 = lhs_ref.offset;
    3353                 :     1948541 :       size2 = lhs_ref.size;
    3354                 :     1948541 :       maxsize2 = lhs_ref.max_size;
    3355                 :     1948541 :       reverse = reverse_storage_order_for_component_p (lhs);
    3356                 :     1948541 :       tree def_rhs = gimple_assign_rhs1 (def_stmt);
    3357                 :     1948541 :       if (!reverse
    3358                 :     1948329 :           && !storage_order_barrier_p (lhs)
    3359                 :     1948329 :           && known_size_p (maxsize2)
    3360                 :     1924897 :           && known_eq (maxsize2, size2)
    3361                 :     3775180 :           && adjust_offsets_for_equal_base_address (base, &offset,
    3362                 :             :                                                     base2, &offset2))
    3363                 :             :         {
    3364                 :       80878 :           if (data->partial_defs.is_empty ()
    3365                 :       73856 :               && known_subrange_p (offset, maxsize, offset2, size2)
    3366                 :             :               /* ???  We can't handle bitfield precision extracts without
    3367                 :             :                  either using an alternate type for the BIT_FIELD_REF and
    3368                 :             :                  then doing a conversion or possibly adjusting the offset
    3369                 :             :                  according to endianness.  */
    3370                 :       48762 :               && (! INTEGRAL_TYPE_P (vr->type)
    3371                 :       35200 :                   || known_eq (ref->size, TYPE_PRECISION (vr->type)))
    3372                 :       91046 :               && multiple_p (ref->size, BITS_PER_UNIT))
    3373                 :             :             {
    3374                 :       43767 :               tree val = NULL_TREE;
    3375                 :       87528 :               if (! INTEGRAL_TYPE_P (TREE_TYPE (def_rhs))
    3376                 :       48203 :                   || type_has_mode_precision_p (TREE_TYPE (def_rhs)))
    3377                 :             :                 {
    3378                 :       42639 :                   gimple_match_op op (gimple_match_cond::UNCOND,
    3379                 :       42639 :                                       BIT_FIELD_REF, vr->type,
    3380                 :             :                                       SSA_VAL (def_rhs),
    3381                 :             :                                       bitsize_int (ref->size),
    3382                 :       42639 :                                       bitsize_int (offset - offset2));
    3383                 :       42639 :                   val = vn_nary_build_or_lookup (&op);
    3384                 :             :                 }
    3385                 :        1128 :               else if (known_eq (ref->size, size2))
    3386                 :             :                 {
    3387                 :        1106 :                   gimple_match_op op (gimple_match_cond::UNCOND,
    3388                 :        1106 :                                       VIEW_CONVERT_EXPR, vr->type,
    3389                 :        1106 :                                       SSA_VAL (def_rhs));
    3390                 :        1106 :                   val = vn_nary_build_or_lookup (&op);
    3391                 :             :                 }
    3392                 :       43745 :               if (val
    3393                 :       43745 :                   && (TREE_CODE (val) != SSA_NAME
    3394                 :       42749 :                       || ! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val)))
    3395                 :       43726 :                 return data->finish (ao_ref_alias_set (&lhs_ref),
    3396                 :       80837 :                                      ao_ref_base_alias_set (&lhs_ref), val);
    3397                 :             :             }
    3398                 :       37111 :           else if (maxsize.is_constant (&maxsizei)
    3399                 :       37111 :                    && offset.is_constant (&offseti)
    3400                 :       37111 :                    && offset2.is_constant (&offset2i)
    3401                 :       37111 :                    && size2.is_constant (&size2i)
    3402                 :       37111 :                    && ranges_known_overlap_p (offset, maxsize, offset2, size2))
    3403                 :             :             {
    3404                 :       37111 :               pd_data pd;
    3405                 :       37111 :               pd.rhs = SSA_VAL (def_rhs);
    3406                 :       37111 :               pd.rhs_off = 0;
    3407                 :       37111 :               pd.offset = offset2i;
    3408                 :       37111 :               pd.size = size2i;
    3409                 :       37111 :               return data->push_partial_def (pd, ao_ref_alias_set (&lhs_ref),
    3410                 :             :                                              ao_ref_base_alias_set (&lhs_ref),
    3411                 :             :                                              offseti, maxsizei);
    3412                 :             :             }
    3413                 :             :         }
    3414                 :             :     }
    3415                 :             : 
    3416                 :             :   /* 4b) Assignment done via one of the vectorizer internal store
    3417                 :             :      functions where we may be able to access pieces from or we can
    3418                 :             :      combine to a larger entity.  */
    3419                 :    18839226 :   else if (known_eq (ref->size, maxsize)
    3420                 :    18295192 :            && is_gimple_reg_type (vr->type)
    3421                 :    17977124 :            && !reverse_storage_order_for_component_p (vr->operands)
    3422                 :    17974397 :            && !contains_storage_order_barrier_p (vr->operands)
    3423                 :    17974397 :            && is_gimple_call (def_stmt)
    3424                 :    14536348 :            && gimple_call_internal_p (def_stmt)
    3425                 :    18892187 :            && internal_store_fn_p (gimple_call_internal_fn (def_stmt)))
    3426                 :             :     {
    3427                 :          46 :       gcall *call = as_a <gcall *> (def_stmt);
    3428                 :          46 :       internal_fn fn = gimple_call_internal_fn (call);
    3429                 :             : 
    3430                 :          46 :       tree mask = NULL_TREE, len = NULL_TREE, bias = NULL_TREE;
    3431                 :          46 :       switch (fn)
    3432                 :             :         {
    3433                 :          46 :         case IFN_MASK_STORE:
    3434                 :          46 :           mask = gimple_call_arg (call, internal_fn_mask_index (fn));
    3435                 :          46 :           mask = vn_valueize (mask);
    3436                 :          46 :           if (TREE_CODE (mask) != VECTOR_CST)
    3437                 :          38 :             return (void *)-1;
    3438                 :             :           break;
    3439                 :           0 :         case IFN_LEN_STORE:
    3440                 :           0 :           {
    3441                 :           0 :             int len_index = internal_fn_len_index (fn);
    3442                 :           0 :             len = gimple_call_arg (call, len_index);
    3443                 :           0 :             bias = gimple_call_arg (call, len_index + 1);
    3444                 :           0 :             if (!tree_fits_uhwi_p (len) || !tree_fits_shwi_p (bias))
    3445                 :             :               return (void *) -1;
    3446                 :             :             break;
    3447                 :             :           }
    3448                 :             :         default:
    3449                 :             :           return (void *)-1;
    3450                 :             :         }
    3451                 :          14 :       tree def_rhs = gimple_call_arg (call,
    3452                 :          14 :                                       internal_fn_stored_value_index (fn));
    3453                 :          14 :       def_rhs = vn_valueize (def_rhs);
    3454                 :          14 :       if (TREE_CODE (def_rhs) != VECTOR_CST)
    3455                 :             :         return (void *)-1;
    3456                 :             : 
    3457                 :          14 :       ao_ref_init_from_ptr_and_size (&lhs_ref,
    3458                 :             :                                      vn_valueize (gimple_call_arg (call, 0)),
    3459                 :          14 :                                      TYPE_SIZE_UNIT (TREE_TYPE (def_rhs)));
    3460                 :          14 :       tree base2;
    3461                 :          14 :       poly_int64 offset2, size2, maxsize2;
    3462                 :          14 :       HOST_WIDE_INT offset2i, size2i, offseti;
    3463                 :          14 :       base2 = ao_ref_base (&lhs_ref);
    3464                 :          14 :       offset2 = lhs_ref.offset;
    3465                 :          14 :       size2 = lhs_ref.size;
    3466                 :          14 :       maxsize2 = lhs_ref.max_size;
    3467                 :          14 :       if (known_size_p (maxsize2)
    3468                 :          14 :           && known_eq (maxsize2, size2)
    3469                 :          14 :           && adjust_offsets_for_equal_base_address (base, &offset,
    3470                 :             :                                                     base2, &offset2)
    3471                 :           6 :           && maxsize.is_constant (&maxsizei)
    3472                 :           6 :           && offset.is_constant (&offseti)
    3473                 :           6 :           && offset2.is_constant (&offset2i)
    3474                 :          14 :           && size2.is_constant (&size2i))
    3475                 :             :         {
    3476                 :           6 :           if (!ranges_maybe_overlap_p (offset, maxsize, offset2, size2))
    3477                 :             :             /* Poor-mans disambiguation.  */
    3478                 :             :             return NULL;
    3479                 :           6 :           else if (ranges_known_overlap_p (offset, maxsize, offset2, size2))
    3480                 :             :             {
    3481                 :           6 :               pd_data pd;
    3482                 :           6 :               pd.rhs = def_rhs;
    3483                 :           6 :               tree aa = gimple_call_arg (call, 1);
    3484                 :           6 :               alias_set_type set = get_deref_alias_set (TREE_TYPE (aa));
    3485                 :           6 :               tree vectype = TREE_TYPE (def_rhs);
    3486                 :           6 :               unsigned HOST_WIDE_INT elsz
    3487                 :           6 :                 = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (vectype)));
    3488                 :           6 :               if (mask)
    3489                 :             :                 {
    3490                 :             :                   HOST_WIDE_INT start = 0, length = 0;
    3491                 :             :                   unsigned mask_idx = 0;
    3492                 :          48 :                   do
    3493                 :             :                     {
    3494                 :          48 :                       if (integer_zerop (VECTOR_CST_ELT (mask, mask_idx)))
    3495                 :             :                         {
    3496                 :          24 :                           if (length != 0)
    3497                 :             :                             {
    3498                 :          18 :                               pd.rhs_off = start;
    3499                 :          18 :                               pd.offset = offset2i + start;
    3500                 :          18 :                               pd.size = length;
    3501                 :          18 :                               if (ranges_known_overlap_p
    3502                 :          18 :                                     (offset, maxsize, pd.offset, pd.size))
    3503                 :             :                                 {
    3504                 :           0 :                                   void *res = data->push_partial_def
    3505                 :           0 :                                               (pd, set, set, offseti, maxsizei);
    3506                 :           0 :                                   if (res != NULL)
    3507                 :           6 :                                     return res;
    3508                 :             :                                 }
    3509                 :             :                             }
    3510                 :          24 :                           start = (mask_idx + 1) * elsz;
    3511                 :          24 :                           length = 0;
    3512                 :             :                         }
    3513                 :             :                       else
    3514                 :          24 :                         length += elsz;
    3515                 :          48 :                       mask_idx++;
    3516                 :             :                     }
    3517                 :          48 :                   while (known_lt (mask_idx, TYPE_VECTOR_SUBPARTS (vectype)));
    3518                 :           6 :                   if (length != 0)
    3519                 :             :                     {
    3520                 :           6 :                       pd.rhs_off = start;
    3521                 :           6 :                       pd.offset = offset2i + start;
    3522                 :           6 :                       pd.size = length;
    3523                 :           6 :                       if (ranges_known_overlap_p (offset, maxsize,
    3524                 :             :                                                   pd.offset, pd.size))
    3525                 :           2 :                         return data->push_partial_def (pd, set, set,
    3526                 :           2 :                                                        offseti, maxsizei);
    3527                 :             :                     }
    3528                 :             :                 }
    3529                 :           0 :               else if (fn == IFN_LEN_STORE)
    3530                 :             :                 {
    3531                 :           0 :                   pd.offset = offset2i;
    3532                 :           0 :                   pd.size = (tree_to_uhwi (len)
    3533                 :           0 :                              + -tree_to_shwi (bias)) * BITS_PER_UNIT;
    3534                 :           0 :                   if (BYTES_BIG_ENDIAN)
    3535                 :             :                     pd.rhs_off = pd.size - tree_to_uhwi (TYPE_SIZE (vectype));
    3536                 :             :                   else
    3537                 :           0 :                     pd.rhs_off = 0;
    3538                 :           0 :                   if (ranges_known_overlap_p (offset, maxsize,
    3539                 :             :                                               pd.offset, pd.size))
    3540                 :           0 :                     return data->push_partial_def (pd, set, set,
    3541                 :           0 :                                                    offseti, maxsizei);
    3542                 :             :                 }
    3543                 :             :               else
    3544                 :           0 :                 gcc_unreachable ();
    3545                 :           4 :               return NULL;
    3546                 :             :             }
    3547                 :             :         }
    3548                 :             :     }
    3549                 :             : 
    3550                 :             :   /* 5) For aggregate copies translate the reference through them if
    3551                 :             :      the copy kills ref.  */
    3552                 :    18839180 :   else if (data->vn_walk_kind == VN_WALKREWRITE
    3553                 :    14801356 :            && gimple_assign_single_p (def_stmt)
    3554                 :     2478933 :            && !gimple_has_volatile_ops (def_stmt)
    3555                 :    21315888 :            && (DECL_P (gimple_assign_rhs1 (def_stmt))
    3556                 :     1992372 :                || TREE_CODE (gimple_assign_rhs1 (def_stmt)) == MEM_REF
    3557                 :     1594803 :                || handled_component_p (gimple_assign_rhs1 (def_stmt))))
    3558                 :             :     {
    3559                 :     2245897 :       tree base2;
    3560                 :     2245897 :       int i, j, k;
    3561                 :     2245897 :       auto_vec<vn_reference_op_s> rhs;
    3562                 :     2245897 :       vn_reference_op_t vro;
    3563                 :     2245897 :       ao_ref r;
    3564                 :             : 
    3565                 :     2245897 :       gcc_assert (lhs_ref_ok);
    3566                 :             : 
    3567                 :             :       /* See if the assignment kills REF.  */
    3568                 :     2245897 :       base2 = ao_ref_base (&lhs_ref);
    3569                 :     2245897 :       if (!lhs_ref.max_size_known_p ()
    3570                 :     2245550 :           || (base != base2
    3571                 :       95454 :               && (TREE_CODE (base) != MEM_REF
    3572                 :       81917 :                   || TREE_CODE (base2) != MEM_REF
    3573                 :       69141 :                   || TREE_OPERAND (base, 0) != TREE_OPERAND (base2, 0)
    3574                 :       32074 :                   || !tree_int_cst_equal (TREE_OPERAND (base, 1),
    3575                 :       32074 :                                           TREE_OPERAND (base2, 1))))
    3576                 :     4426484 :           || !stmt_kills_ref_p (def_stmt, ref))
    3577                 :      420505 :         return (void *)-1;
    3578                 :             : 
    3579                 :             :       /* Find the common base of ref and the lhs.  lhs_ops already
    3580                 :             :          contains valueized operands for the lhs.  */
    3581                 :     1825392 :       poly_int64 extra_off = 0;
    3582                 :     1825392 :       i = vr->operands.length () - 1;
    3583                 :     1825392 :       j = lhs_ops.length () - 1;
    3584                 :             : 
    3585                 :             :       /* The base should be always equal due to the above check.  */
    3586                 :     1825392 :       if (! vn_reference_op_eq (&vr->operands[i], &lhs_ops[j]))
    3587                 :             :         return (void *)-1;
    3588                 :     1825224 :       i--, j--;
    3589                 :             : 
    3590                 :             :       /* The 2nd component should always exist and be a MEM_REF.  */
    3591                 :     1825224 :       if (!(i >= 0 && j >= 0))
    3592                 :             :         ;
    3593                 :     1825224 :       else if (vn_reference_op_eq (&vr->operands[i], &lhs_ops[j]))
    3594                 :      855394 :         i--, j--;
    3595                 :      969830 :       else if (vr->operands[i].opcode == MEM_REF
    3596                 :      968290 :                && lhs_ops[j].opcode == MEM_REF
    3597                 :      968290 :                && known_ne (lhs_ops[j].off, -1)
    3598                 :     1938120 :                && known_ne (vr->operands[i].off, -1))
    3599                 :             :         {
    3600                 :      968290 :           bool found = false;
    3601                 :             :           /* When we ge a mismatch at a MEM_REF that is not the sole component
    3602                 :             :              try finding a match in one of the outer components and continue
    3603                 :             :              stripping there.  This happens when addresses of components get
    3604                 :             :              forwarded into dereferences.  */
    3605                 :      968290 :           if (i > 0)
    3606                 :             :             {
    3607                 :      101572 :               int temi = i - 1;
    3608                 :      101572 :               extra_off = vr->operands[i].off;
    3609                 :      101572 :               while (temi >= 0
    3610                 :      220696 :                      && known_ne (vr->operands[temi].off, -1))
    3611                 :             :                 {
    3612                 :      120427 :                   if (vr->operands[temi].type
    3613                 :      120427 :                       && lhs_ops[j].type
    3614                 :      240854 :                       && (TYPE_MAIN_VARIANT (vr->operands[temi].type)
    3615                 :      120427 :                           == TYPE_MAIN_VARIANT (lhs_ops[j].type)))
    3616                 :             :                     {
    3617                 :        1303 :                       i = temi;
    3618                 :             :                       /* Strip the component that was type matched to
    3619                 :             :                          the MEM_REF.  */
    3620                 :        1303 :                       extra_off += vr->operands[i].off - lhs_ops[j].off;
    3621                 :        1303 :                       i--, j--;
    3622                 :             :                       /* Strip further equal components.  */
    3623                 :        1303 :                       found = true;
    3624                 :        1303 :                       break;
    3625                 :             :                     }
    3626                 :      119124 :                   extra_off += vr->operands[temi].off;
    3627                 :      119124 :                   temi--;
    3628                 :             :                 }
    3629                 :             :             }
    3630                 :      968290 :           if (!found && j > 0)
    3631                 :             :             {
    3632                 :       26032 :               int temj = j - 1;
    3633                 :       26032 :               extra_off = -lhs_ops[j].off;
    3634                 :       26032 :               while (temj >= 0
    3635                 :       49696 :                      && known_ne (lhs_ops[temj].off, -1))
    3636                 :             :                 {
    3637                 :       27887 :                   if (vr->operands[i].type
    3638                 :       27887 :                       && lhs_ops[temj].type
    3639                 :       55774 :                       && (TYPE_MAIN_VARIANT (vr->operands[i].type)
    3640                 :       27887 :                           == TYPE_MAIN_VARIANT (lhs_ops[temj].type)))
    3641                 :             :                     {
    3642                 :        4223 :                       j = temj;
    3643                 :             :                       /* Strip the component that was type matched to
    3644                 :             :                          the MEM_REF.  */
    3645                 :        4223 :                       extra_off += vr->operands[i].off - lhs_ops[j].off;
    3646                 :        4223 :                       i--, j--;
    3647                 :             :                       /* Strip further equal components.  */
    3648                 :        4223 :                       found = true;
    3649                 :        4223 :                       break;
    3650                 :             :                     }
    3651                 :       23664 :                   extra_off += -lhs_ops[temj].off;
    3652                 :       23664 :                   temj--;
    3653                 :             :                 }
    3654                 :             :             }
    3655                 :             :           /* When the LHS is already at the outermost level simply
    3656                 :             :              adjust for any offset difference.  Further lookups
    3657                 :             :              will fail when there's too gross of a type compatibility
    3658                 :             :              issue.  */
    3659                 :      968290 :           if (!found && j == 0)
    3660                 :             :             {
    3661                 :      940955 :               extra_off = vr->operands[i].off - lhs_ops[j].off;
    3662                 :      940955 :               i--, j--;
    3663                 :      940955 :               found = true;
    3664                 :             :             }
    3665                 :             :           /* If we did find a match we'd eventually append a MEM_REF
    3666                 :             :              as component.  Don't.  */
    3667                 :      968290 :           if (!found)
    3668                 :             :             return (void *)-1;
    3669                 :             :         }
    3670                 :             :       else
    3671                 :             :         return (void *)-1;
    3672                 :             : 
    3673                 :             :       /* Strip further common components, attempting to consume lhs_ops
    3674                 :             :          in full.  */
    3675                 :     1832896 :       while (j >= 0 && i >= 0
    3676                 :     1832896 :              && vn_reference_op_eq (&vr->operands[i], &lhs_ops[j]))
    3677                 :             :         {
    3678                 :       31021 :           i--;
    3679                 :       31021 :           j--;
    3680                 :             :         }
    3681                 :             : 
    3682                 :             :       /* When we still didn't manage to strip off all components from
    3683                 :             :          lhs_op, opportunistically continue for those we can handle
    3684                 :             :          via extra_off.  Note this is an attempt to fixup secondary
    3685                 :             :          copies after we hit the !found && j == 0 case above.  */
    3686                 :             :       while (j != -1
    3687                 :     1804529 :              && known_ne (lhs_ops[j].off, -1U))
    3688                 :             :         {
    3689                 :        2654 :           extra_off += -lhs_ops[j].off;
    3690                 :        2654 :           j--;
    3691                 :             :         }
    3692                 :             : 
    3693                 :             :       /* i now points to the first additional op.
    3694                 :             :          ???  LHS may not be completely contained in VR, one or more
    3695                 :             :          VIEW_CONVERT_EXPRs could be in its way.  We could at least
    3696                 :             :          try handling outermost VIEW_CONVERT_EXPRs.  */
    3697                 :     1801875 :       if (j != -1)
    3698                 :             :         return (void *)-1;
    3699                 :             : 
    3700                 :             :       /* Punt if the additional ops contain a storage order barrier.  */
    3701                 :     2938313 :       for (k = i; k >= 0; k--)
    3702                 :             :         {
    3703                 :     1136438 :           vro = &vr->operands[k];
    3704                 :     1136438 :           if (vro->opcode == VIEW_CONVERT_EXPR && vro->reverse)
    3705                 :             :             return (void *)-1;
    3706                 :             :         }
    3707                 :             : 
    3708                 :             :       /* Now re-write REF to be based on the rhs of the assignment.  */
    3709                 :     1801875 :       tree rhs1 = gimple_assign_rhs1 (def_stmt);
    3710                 :     1801875 :       copy_reference_ops_from_ref (rhs1, &rhs);
    3711                 :             : 
    3712                 :             :       /* Apply an extra offset to the inner MEM_REF of the RHS.  */
    3713                 :     1801875 :       bool force_no_tbaa = false;
    3714                 :     1801875 :       if (maybe_ne (extra_off, 0))
    3715                 :             :         {
    3716                 :      647982 :           if (rhs.length () < 2)
    3717                 :             :             return (void *)-1;
    3718                 :      647982 :           int ix = rhs.length () - 2;
    3719                 :      647982 :           if (rhs[ix].opcode != MEM_REF
    3720                 :      647982 :               || known_eq (rhs[ix].off, -1))
    3721                 :             :             return (void *)-1;
    3722                 :      647978 :           rhs[ix].off += extra_off;
    3723                 :      647978 :           rhs[ix].op0 = int_const_binop (PLUS_EXPR, rhs[ix].op0,
    3724                 :      647978 :                                          build_int_cst (TREE_TYPE (rhs[ix].op0),
    3725                 :             :                                                         extra_off));
    3726                 :             :           /* When we have offsetted the RHS, reading only parts of it,
    3727                 :             :              we can no longer use the original TBAA type, force alias-set
    3728                 :             :              zero.  */
    3729                 :      647978 :           force_no_tbaa = true;
    3730                 :             :         }
    3731                 :             : 
    3732                 :             :       /* Save the operands since we need to use the original ones for
    3733                 :             :          the hash entry we use.  */
    3734                 :     1801871 :       if (!data->saved_operands.exists ())
    3735                 :     1728041 :         data->saved_operands = vr->operands.copy ();
    3736                 :             : 
    3737                 :             :       /* We need to pre-pend vr->operands[0..i] to rhs.  */
    3738                 :     1801871 :       vec<vn_reference_op_s> old = vr->operands;
    3739                 :     5405613 :       if (i + 1 + rhs.length () > vr->operands.length ())
    3740                 :     1143059 :         vr->operands.safe_grow (i + 1 + rhs.length (), true);
    3741                 :             :       else
    3742                 :      658812 :         vr->operands.truncate (i + 1 + rhs.length ());
    3743                 :     6585404 :       FOR_EACH_VEC_ELT (rhs, j, vro)
    3744                 :     4783533 :         vr->operands[i + 1 + j] = *vro;
    3745                 :     1801871 :       valueize_refs (&vr->operands);
    3746                 :     3603742 :       if (old == shared_lookup_references)
    3747                 :     1801871 :         shared_lookup_references = vr->operands;
    3748                 :     1801871 :       vr->hashcode = vn_reference_compute_hash (vr);
    3749                 :             : 
    3750                 :             :       /* Try folding the new reference to a constant.  */
    3751                 :     1801871 :       tree val = fully_constant_vn_reference_p (vr);
    3752                 :     1801871 :       if (val)
    3753                 :             :         {
    3754                 :       20552 :           if (data->partial_defs.is_empty ())
    3755                 :       20543 :             return data->finish (ao_ref_alias_set (&lhs_ref),
    3756                 :       20543 :                                  ao_ref_base_alias_set (&lhs_ref), val);
    3757                 :             :           /* This is the only interesting case for partial-def handling
    3758                 :             :              coming from targets that like to gimplify init-ctors as
    3759                 :             :              aggregate copies from constant data like aarch64 for
    3760                 :             :              PR83518.  */
    3761                 :           9 :           if (maxsize.is_constant (&maxsizei) && known_eq (ref->size, maxsize))
    3762                 :             :             {
    3763                 :           9 :               pd_data pd;
    3764                 :           9 :               pd.rhs = val;
    3765                 :           9 :               pd.rhs_off = 0;
    3766                 :           9 :               pd.offset = 0;
    3767                 :           9 :               pd.size = maxsizei;
    3768                 :           9 :               return data->push_partial_def (pd, ao_ref_alias_set (&lhs_ref),
    3769                 :             :                                              ao_ref_base_alias_set (&lhs_ref),
    3770                 :             :                                              0, maxsizei);
    3771                 :             :             }
    3772                 :             :         }
    3773                 :             : 
    3774                 :             :       /* Continuing with partial defs isn't easily possible here, we
    3775                 :             :          have to find a full def from further lookups from here.  Probably
    3776                 :             :          not worth the special-casing everywhere.  */
    3777                 :     2232177 :       if (!data->partial_defs.is_empty ())
    3778                 :             :         return (void *)-1;
    3779                 :             : 
    3780                 :             :       /* Adjust *ref from the new operands.  */
    3781                 :     1774487 :       ao_ref rhs1_ref;
    3782                 :     1774487 :       ao_ref_init (&rhs1_ref, rhs1);
    3783                 :     2904411 :       if (!ao_ref_init_from_vn_reference (&r,
    3784                 :             :                                           force_no_tbaa ? 0
    3785                 :     1129924 :                                           : ao_ref_alias_set (&rhs1_ref),
    3786                 :             :                                           force_no_tbaa ? 0
    3787                 :     1129924 :                                           : ao_ref_base_alias_set (&rhs1_ref),
    3788                 :             :                                           vr->type, vr->operands))
    3789                 :             :         return (void *)-1;
    3790                 :             :       /* This can happen with bitfields.  */
    3791                 :     1774487 :       if (maybe_ne (ref->size, r.size))
    3792                 :             :         {
    3793                 :             :           /* If the access lacks some subsetting simply apply that by
    3794                 :             :              shortening it.  That in the end can only be successful
    3795                 :             :              if we can pun the lookup result which in turn requires
    3796                 :             :              exact offsets.  */
    3797                 :           0 :           if (known_eq (r.size, r.max_size)
    3798                 :           0 :               && known_lt (ref->size, r.size))
    3799                 :           0 :             r.size = r.max_size = ref->size;
    3800                 :             :           else
    3801                 :             :             return (void *)-1;
    3802                 :             :         }
    3803                 :     1774487 :       *ref = r;
    3804                 :     1774487 :       vr->offset = r.offset;
    3805                 :     1774487 :       vr->max_size = r.max_size;
    3806                 :             : 
    3807                 :             :       /* Do not update last seen VUSE after translating.  */
    3808                 :     1774487 :       data->last_vuse_ptr = NULL;
    3809                 :             :       /* Invalidate the original access path since it now contains
    3810                 :             :          the wrong base.  */
    3811                 :     1774487 :       data->orig_ref.ref = NULL_TREE;
    3812                 :             :       /* Use the alias-set of this LHS for recording an eventual result.  */
    3813                 :     1774487 :       if (data->first_set == -2)
    3814                 :             :         {
    3815                 :     1701882 :           data->first_set = ao_ref_alias_set (&lhs_ref);
    3816                 :     1701882 :           data->first_base_set = ao_ref_base_alias_set (&lhs_ref);
    3817                 :             :         }
    3818                 :             : 
    3819                 :             :       /* Keep looking for the adjusted *REF / VR pair.  */
    3820                 :     1774487 :       return NULL;
    3821                 :     2245897 :     }
    3822                 :             : 
    3823                 :             :   /* 6) For memcpy copies translate the reference through them if the copy
    3824                 :             :      kills ref.  But we cannot (easily) do this translation if the memcpy is
    3825                 :             :      a storage order barrier, i.e. is equivalent to a VIEW_CONVERT_EXPR that
    3826                 :             :      can modify the storage order of objects (see storage_order_barrier_p).  */
    3827                 :    16593283 :   else if (data->vn_walk_kind == VN_WALKREWRITE
    3828                 :    12555459 :            && is_gimple_reg_type (vr->type)
    3829                 :             :            /* ???  Handle BCOPY as well.  */
    3830                 :    12547901 :            && (gimple_call_builtin_p (def_stmt, BUILT_IN_MEMCPY)
    3831                 :    12464584 :                || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMCPY_CHK)
    3832                 :    12464162 :                || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMPCPY)
    3833                 :    12462976 :                || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMPCPY_CHK)
    3834                 :    12462733 :                || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMMOVE)
    3835                 :    12435727 :                || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMMOVE_CHK))
    3836                 :      112502 :            && (TREE_CODE (gimple_call_arg (def_stmt, 0)) == ADDR_EXPR
    3837                 :      103727 :                || TREE_CODE (gimple_call_arg (def_stmt, 0)) == SSA_NAME)
    3838                 :      112466 :            && (TREE_CODE (gimple_call_arg (def_stmt, 1)) == ADDR_EXPR
    3839                 :       73072 :                || TREE_CODE (gimple_call_arg (def_stmt, 1)) == SSA_NAME)
    3840                 :      112451 :            && (poly_int_tree_p (gimple_call_arg (def_stmt, 2), &copy_size)
    3841                 :       60128 :                || (TREE_CODE (gimple_call_arg (def_stmt, 2)) == SSA_NAME
    3842                 :       60128 :                    && poly_int_tree_p (SSA_VAL (gimple_call_arg (def_stmt, 2)),
    3843                 :             :                                        &copy_size)))
    3844                 :             :            /* Handling this is more complicated, give up for now.  */
    3845                 :    16647270 :            && data->partial_defs.is_empty ())
    3846                 :             :     {
    3847                 :       53674 :       tree lhs, rhs;
    3848                 :       53674 :       ao_ref r;
    3849                 :       53674 :       poly_int64 rhs_offset, lhs_offset;
    3850                 :       53674 :       vn_reference_op_s op;
    3851                 :       53674 :       poly_uint64 mem_offset;
    3852                 :       53674 :       poly_int64 at, byte_maxsize;
    3853                 :             : 
    3854                 :             :       /* Only handle non-variable, addressable refs.  */
    3855                 :       53674 :       if (maybe_ne (ref->size, maxsize)
    3856                 :       53220 :           || !multiple_p (offset, BITS_PER_UNIT, &at)
    3857                 :       53674 :           || !multiple_p (maxsize, BITS_PER_UNIT, &byte_maxsize))
    3858                 :         454 :         return (void *)-1;
    3859                 :             : 
    3860                 :             :       /* Extract a pointer base and an offset for the destination.  */
    3861                 :       53220 :       lhs = gimple_call_arg (def_stmt, 0);
    3862                 :       53220 :       lhs_offset = 0;
    3863                 :       53220 :       if (TREE_CODE (lhs) == SSA_NAME)
    3864                 :             :         {
    3865                 :       45616 :           lhs = vn_valueize (lhs);
    3866                 :       45616 :           if (TREE_CODE (lhs) == SSA_NAME)
    3867                 :             :             {
    3868                 :       45323 :               gimple *def_stmt = SSA_NAME_DEF_STMT (lhs);
    3869                 :       45323 :               if (gimple_assign_single_p (def_stmt)
    3870                 :       45323 :                   && gimple_assign_rhs_code (def_stmt) == ADDR_EXPR)
    3871                 :        2182 :                 lhs = gimple_assign_rhs1 (def_stmt);
    3872                 :             :             }
    3873                 :             :         }
    3874                 :       53220 :       if (TREE_CODE (lhs) == ADDR_EXPR)
    3875                 :             :         {
    3876                 :       14281 :           if (AGGREGATE_TYPE_P (TREE_TYPE (TREE_TYPE (lhs)))
    3877                 :       13992 :               && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_TYPE (lhs))))
    3878                 :             :             return (void *)-1;
    3879                 :        9939 :           tree tem = get_addr_base_and_unit_offset (TREE_OPERAND (lhs, 0),
    3880                 :             :                                                     &lhs_offset);
    3881                 :        9939 :           if (!tem)
    3882                 :             :             return (void *)-1;
    3883                 :        9445 :           if (TREE_CODE (tem) == MEM_REF
    3884                 :        9445 :               && poly_int_tree_p (TREE_OPERAND (tem, 1), &mem_offset))
    3885                 :             :             {
    3886                 :        1688 :               lhs = TREE_OPERAND (tem, 0);
    3887                 :        1688 :               if (TREE_CODE (lhs) == SSA_NAME)
    3888                 :        1688 :                 lhs = vn_valueize (lhs);
    3889                 :        1688 :               lhs_offset += mem_offset;
    3890                 :             :             }
    3891                 :        7757 :           else if (DECL_P (tem))
    3892                 :        7757 :             lhs = build_fold_addr_expr (tem);
    3893                 :             :           else
    3894                 :             :             return (void *)-1;
    3895                 :             :         }
    3896                 :       52586 :       if (TREE_CODE (lhs) != SSA_NAME
    3897                 :        7758 :           && TREE_CODE (lhs) != ADDR_EXPR)
    3898                 :             :         return (void *)-1;
    3899                 :             : 
    3900                 :             :       /* Extract a pointer base and an offset for the source.  */
    3901                 :       52586 :       rhs = gimple_call_arg (def_stmt, 1);
    3902                 :       52586 :       rhs_offset = 0;
    3903                 :       52586 :       if (TREE_CODE (rhs) == SSA_NAME)
    3904                 :       17154 :         rhs = vn_valueize (rhs);
    3905                 :       52586 :       if (TREE_CODE (rhs) == ADDR_EXPR)
    3906                 :             :         {
    3907                 :       48021 :           if (AGGREGATE_TYPE_P (TREE_TYPE (TREE_TYPE (rhs)))
    3908                 :       36762 :               && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_TYPE (rhs))))
    3909                 :             :             return (void *)-1;
    3910                 :       36318 :           tree tem = get_addr_base_and_unit_offset (TREE_OPERAND (rhs, 0),
    3911                 :             :                                                     &rhs_offset);
    3912                 :       36318 :           if (!tem)
    3913                 :             :             return (void *)-1;
    3914                 :       36318 :           if (TREE_CODE (tem) == MEM_REF
    3915                 :       36318 :               && poly_int_tree_p (TREE_OPERAND (tem, 1), &mem_offset))
    3916                 :             :             {
    3917                 :           0 :               rhs = TREE_OPERAND (tem, 0);
    3918                 :           0 :               rhs_offset += mem_offset;
    3919                 :             :             }
    3920                 :       36318 :           else if (DECL_P (tem)
    3921                 :       31517 :                    || TREE_CODE (tem) == STRING_CST)
    3922                 :       36318 :             rhs = build_fold_addr_expr (tem);
    3923                 :             :           else
    3924                 :             :             return (void *)-1;
    3925                 :             :         }
    3926                 :       52586 :       if (TREE_CODE (rhs) == SSA_NAME)
    3927                 :       16268 :         rhs = SSA_VAL (rhs);
    3928                 :       36318 :       else if (TREE_CODE (rhs) != ADDR_EXPR)
    3929                 :             :         return (void *)-1;
    3930                 :             : 
    3931                 :             :       /* The bases of the destination and the references have to agree.  */
    3932                 :       52586 :       if (TREE_CODE (base) == MEM_REF)
    3933                 :             :         {
    3934                 :       13657 :           if (TREE_OPERAND (base, 0) != lhs
    3935                 :       13657 :               || !poly_int_tree_p (TREE_OPERAND (base, 1), &mem_offset))
    3936                 :       10385 :             return (void *) -1;
    3937                 :        9891 :           at += mem_offset;
    3938                 :             :         }
    3939                 :       38929 :       else if (!DECL_P (base)
    3940                 :       38100 :                || TREE_CODE (lhs) != ADDR_EXPR
    3941                 :       45549 :                || TREE_OPERAND (lhs, 0) != base)
    3942                 :             :         return (void *)-1;
    3943                 :             : 
    3944                 :             :       /* If the access is completely outside of the memcpy destination
    3945                 :             :          area there is no aliasing.  */
    3946                 :        9891 :       if (!ranges_maybe_overlap_p (lhs_offset, copy_size, at, byte_maxsize))
    3947                 :             :         return NULL;
    3948                 :             :       /* And the access has to be contained within the memcpy destination.  */
    3949                 :        9856 :       if (!known_subrange_p (at, byte_maxsize, lhs_offset, copy_size))
    3950                 :             :         return (void *)-1;
    3951                 :             : 
    3952                 :             :       /* Save the operands since we need to use the original ones for
    3953                 :             :          the hash entry we use.  */
    3954                 :        9503 :       if (!data->saved_operands.exists ())
    3955                 :        9156 :         data->saved_operands = vr->operands.copy ();
    3956                 :             : 
    3957                 :             :       /* Make room for 2 operands in the new reference.  */
    3958                 :        9503 :       if (vr->operands.length () < 2)
    3959                 :             :         {
    3960                 :           0 :           vec<vn_reference_op_s> old = vr->operands;
    3961                 :           0 :           vr->operands.safe_grow_cleared (2, true);
    3962                 :           0 :           if (old == shared_lookup_references)
    3963                 :           0 :             shared_lookup_references = vr->operands;
    3964                 :             :         }
    3965                 :             :       else
    3966                 :        9503 :         vr->operands.truncate (2);
    3967                 :             : 
    3968                 :             :       /* The looked-through reference is a simple MEM_REF.  */
    3969                 :        9503 :       memset (&op, 0, sizeof (op));
    3970                 :        9503 :       op.type = vr->type;
    3971                 :        9503 :       op.opcode = MEM_REF;
    3972                 :        9503 :       op.op0 = build_int_cst (ptr_type_node, at - lhs_offset + rhs_offset);
    3973                 :        9503 :       op.off = at - lhs_offset + rhs_offset;
    3974                 :        9503 :       vr->operands[0] = op;
    3975                 :        9503 :       op.type = TREE_TYPE (rhs);
    3976                 :        9503 :       op.opcode = TREE_CODE (rhs);
    3977                 :        9503 :       op.op0 = rhs;
    3978                 :        9503 :       op.off = -1;
    3979                 :        9503 :       vr->operands[1] = op;
    3980                 :        9503 :       vr->hashcode = vn_reference_compute_hash (vr);
    3981                 :             : 
    3982                 :             :       /* Try folding the new reference to a constant.  */
    3983                 :        9503 :       tree val = fully_constant_vn_reference_p (vr);
    3984                 :        9503 :       if (val)
    3985                 :        1902 :         return data->finish (0, 0, val);
    3986                 :             : 
    3987                 :             :       /* Adjust *ref from the new operands.  */
    3988                 :        7601 :       if (!ao_ref_init_from_vn_reference (&r, 0, 0, vr->type, vr->operands))
    3989                 :             :         return (void *)-1;
    3990                 :             :       /* This can happen with bitfields.  */
    3991                 :        7601 :       if (maybe_ne (ref->size, r.size))
    3992                 :             :         return (void *)-1;
    3993                 :        7601 :       *ref = r;
    3994                 :        7601 :       vr->offset = r.offset;
    3995                 :        7601 :       vr->max_size = r.max_size;
    3996                 :             : 
    3997                 :             :       /* Do not update last seen VUSE after translating.  */
    3998                 :        7601 :       data->last_vuse_ptr = NULL;
    3999                 :             :       /* Invalidate the original access path since it now contains
    4000                 :             :          the wrong base.  */
    4001                 :        7601 :       data->orig_ref.ref = NULL_TREE;
    4002                 :             :       /* Use the alias-set of this stmt for recording an eventual result.  */
    4003                 :        7601 :       if (data->first_set == -2)
    4004                 :             :         {
    4005                 :        7294 :           data->first_set = 0;
    4006                 :        7294 :           data->first_base_set = 0;
    4007                 :             :         }
    4008                 :             : 
    4009                 :             :       /* Keep looking for the adjusted *REF / VR pair.  */
    4010                 :        7601 :       return NULL;
    4011                 :             :     }
    4012                 :             : 
    4013                 :             :   /* Bail out and stop walking.  */
    4014                 :             :   return (void *)-1;
    4015                 :             : }
    4016                 :             : 
    4017                 :             : /* Return a reference op vector from OP that can be used for
    4018                 :             :    vn_reference_lookup_pieces.  The caller is responsible for releasing
    4019                 :             :    the vector.  */
    4020                 :             : 
    4021                 :             : vec<vn_reference_op_s>
    4022                 :     5328688 : vn_reference_operands_for_lookup (tree op)
    4023                 :             : {
    4024                 :     5328688 :   bool valueized;
    4025                 :     5328688 :   return valueize_shared_reference_ops_from_ref (op, &valueized).copy ();
    4026                 :             : }
    4027                 :             : 
    4028                 :             : /* Lookup a reference operation by it's parts, in the current hash table.
    4029                 :             :    Returns the resulting value number if it exists in the hash table,
    4030                 :             :    NULL_TREE otherwise.  VNRESULT will be filled in with the actual
    4031                 :             :    vn_reference_t stored in the hashtable if something is found.  */
    4032                 :             : 
    4033                 :             : tree
    4034                 :     8320919 : vn_reference_lookup_pieces (tree vuse, alias_set_type set,
    4035                 :             :                             alias_set_type base_set, tree type,
    4036                 :             :                             vec<vn_reference_op_s> operands,
    4037                 :             :                             vn_reference_t *vnresult, vn_lookup_kind kind)
    4038                 :             : {
    4039                 :     8320919 :   struct vn_reference_s vr1;
    4040                 :     8320919 :   vn_reference_t tmp;
    4041                 :     8320919 :   tree cst;
    4042                 :             : 
    4043                 :     8320919 :   if (!vnresult)
    4044                 :           0 :     vnresult = &tmp;
    4045                 :     8320919 :   *vnresult = NULL;
    4046                 :             : 
    4047                 :     8320919 :   vr1.vuse = vuse_ssa_val (vuse);
    4048                 :     8320919 :   shared_lookup_references.truncate (0);
    4049                 :    16641838 :   shared_lookup_references.safe_grow (operands.length (), true);
    4050                 :     8320919 :   memcpy (shared_lookup_references.address (),
    4051                 :     8320919 :           operands.address (),
    4052                 :             :           sizeof (vn_reference_op_s)
    4053                 :     8320919 :           * operands.length ());
    4054                 :     8320919 :   bool valueized_p;
    4055                 :     8320919 :   valueize_refs_1 (&shared_lookup_references, &valueized_p);
    4056                 :     8320919 :   vr1.operands = shared_lookup_references;
    4057                 :     8320919 :   vr1.type = type;
    4058                 :     8320919 :   vr1.set = set;
    4059                 :     8320919 :   vr1.base_set = base_set;
    4060                 :             :   /* We can pretend there's no extra info fed in since the ao_refs offset
    4061                 :             :      and max_size are computed only from the VN reference ops.  */
    4062                 :     8320919 :   vr1.offset = 0;
    4063                 :     8320919 :   vr1.max_size = -1;
    4064                 :     8320919 :   vr1.hashcode = vn_reference_compute_hash (&vr1);
    4065                 :     8320919 :   if ((cst = fully_constant_vn_reference_p (&vr1)))
    4066                 :             :     return cst;
    4067                 :             : 
    4068                 :     8301598 :   vn_reference_lookup_1 (&vr1, vnresult);
    4069                 :     8301598 :   if (!*vnresult
    4070                 :     3169882 :       && kind != VN_NOWALK
    4071                 :     3169882 :       && vr1.vuse)
    4072                 :             :     {
    4073                 :     3146243 :       ao_ref r;
    4074                 :     3146243 :       unsigned limit = param_sccvn_max_alias_queries_per_access;
    4075                 :     3146243 :       vn_walk_cb_data data (&vr1, NULL_TREE, NULL, kind, true, NULL_TREE,
    4076                 :     3146243 :                             false);
    4077                 :     3146243 :       vec<vn_reference_op_s> ops_for_ref;
    4078                 :     3146243 :       if (!valueized_p)
    4079                 :     3056724 :         ops_for_ref = vr1.operands;
    4080                 :             :       else
    4081                 :             :         {
    4082                 :             :           /* For ao_ref_from_mem we have to ensure only available SSA names
    4083                 :             :              end up in base and the only convenient way to make this work
    4084                 :             :              for PRE is to re-valueize with that in mind.  */
    4085                 :      179038 :           ops_for_ref.create (operands.length ());
    4086                 :      179038 :           ops_for_ref.quick_grow (operands.length ());
    4087                 :       89519 :           memcpy (ops_for_ref.address (),
    4088                 :       89519 :                   operands.address (),
    4089                 :             :                   sizeof (vn_reference_op_s)
    4090                 :       89519 :                   * operands.length ());
    4091                 :       89519 :           valueize_refs_1 (&ops_for_ref, &valueized_p, true);
    4092                 :             :         }
    4093                 :     3146243 :       if (ao_ref_init_from_vn_reference (&r, set, base_set, type,
    4094                 :             :                                          ops_for_ref))
    4095                 :     3079356 :         *vnresult
    4096                 :     3079356 :           = ((vn_reference_t)
    4097                 :     3079356 :              walk_non_aliased_vuses (&r, vr1.vuse, true, vn_reference_lookup_2,
    4098                 :             :                                      vn_reference_lookup_3, vuse_valueize,
    4099                 :             :                                      limit, &data));
    4100                 :     6292486 :       if (ops_for_ref != shared_lookup_references)
    4101                 :       89519 :         ops_for_ref.release ();
    4102                 :     6292486 :       gcc_checking_assert (vr1.operands == shared_lookup_references);
    4103                 :     3146243 :       if (*vnresult
    4104                 :      448007 :           && data.same_val
    4105                 :     3146243 :           && (!(*vnresult)->result
    4106                 :           0 :               || !operand_equal_p ((*vnresult)->result, data.same_val)))
    4107                 :             :         {
    4108                 :           0 :           *vnresult = NULL;
    4109                 :           0 :           return NULL_TREE;
    4110                 :             :         }
    4111                 :     3146243 :     }
    4112                 :             : 
    4113                 :     8301598 :   if (*vnresult)
    4114                 :     5579723 :      return (*vnresult)->result;
    4115                 :             : 
    4116                 :             :   return NULL_TREE;
    4117                 :             : }
    4118                 :             : 
    4119                 :             : /* When OPERANDS is an ADDR_EXPR that can be possibly expressed as a
    4120                 :             :    POINTER_PLUS_EXPR return true and fill in its operands in OPS.  */
    4121                 :             : 
    4122                 :             : bool
    4123                 :     2360076 : vn_pp_nary_for_addr (const vec<vn_reference_op_s>& operands, tree ops[2])
    4124                 :             : {
    4125                 :     4720152 :   gcc_assert (operands[0].opcode == ADDR_EXPR
    4126                 :             :               && operands.last ().opcode == SSA_NAME);
    4127                 :             :   poly_int64 off = 0;
    4128                 :             :   vn_reference_op_t vro;
    4129                 :             :   unsigned i;
    4130                 :     7685565 :   for (i = 1; operands.iterate (i, &vro); ++i)
    4131                 :             :     {
    4132                 :     7685565 :       if (vro->opcode == SSA_NAME)
    4133                 :             :         break;
    4134                 :     5371391 :       else if (known_eq (vro->off, -1))
    4135                 :             :         break;
    4136                 :     5325489 :       off += vro->off;
    4137                 :             :     }
    4138                 :     2360076 :   if (i == operands.length () - 1
    4139                 :     2314174 :       && maybe_ne (off, 0)
    4140                 :             :       /* Make sure we the offset we accumulated in a 64bit int
    4141                 :             :          fits the address computation carried out in target
    4142                 :             :          offset precision.  */
    4143                 :     3939329 :       && (off.coeffs[0]
    4144                 :     1579253 :           == sext_hwi (off.coeffs[0], TYPE_PRECISION (sizetype))))
    4145                 :             :     {
    4146                 :     1578447 :       gcc_assert (operands[i-1].opcode == MEM_REF);
    4147                 :     1578447 :       ops[0] = operands[i].op0;
    4148                 :     1578447 :       ops[1] = wide_int_to_tree (sizetype, off);
    4149                 :     1578447 :       return true;
    4150                 :             :     }
    4151                 :             :   return false;
    4152                 :             : }
    4153                 :             : 
    4154                 :             : /* Lookup OP in the current hash table, and return the resulting value
    4155                 :             :    number if it exists in the hash table.  Return NULL_TREE if it does
    4156                 :             :    not exist in the hash table or if the result field of the structure
    4157                 :             :    was NULL..  VNRESULT will be filled in with the vn_reference_t
    4158                 :             :    stored in the hashtable if one exists.  When TBAA_P is false assume
    4159                 :             :    we are looking up a store and treat it as having alias-set zero.
    4160                 :             :    *LAST_VUSE_PTR will be updated with the VUSE the value lookup succeeded.
    4161                 :             :    MASK is either NULL_TREE, or can be an INTEGER_CST if the result of the
    4162                 :             :    load is bitwise anded with MASK and so we are only interested in a subset
    4163                 :             :    of the bits and can ignore if the other bits are uninitialized or
    4164                 :             :    not initialized with constants.  When doing redundant store removal
    4165                 :             :    the caller has to set REDUNDANT_STORE_REMOVAL_P.  */
    4166                 :             : 
    4167                 :             : tree
    4168                 :   101663160 : vn_reference_lookup (tree op, tree vuse, vn_lookup_kind kind,
    4169                 :             :                      vn_reference_t *vnresult, bool tbaa_p,
    4170                 :             :                      tree *last_vuse_ptr, tree mask,
    4171                 :             :                      bool redundant_store_removal_p)
    4172                 :             : {
    4173                 :   101663160 :   vec<vn_reference_op_s> operands;
    4174                 :   101663160 :   struct vn_reference_s vr1;
    4175                 :   101663160 :   bool valueized_anything;
    4176                 :             : 
    4177                 :   101663160 :   if (vnresult)
    4178                 :   101222296 :     *vnresult = NULL;
    4179                 :             : 
    4180                 :   101663160 :   vr1.vuse = vuse_ssa_val (vuse);
    4181                 :   203326320 :   vr1.operands = operands
    4182                 :   101663160 :     = valueize_shared_reference_ops_from_ref (op, &valueized_anything);
    4183                 :             : 
    4184                 :             :   /* Handle &MEM[ptr + 5].b[1].c as POINTER_PLUS_EXPR.  Avoid doing
    4185                 :             :      this before the pass folding __builtin_object_size had a chance to run.  */
    4186                 :   101663160 :   if ((cfun->curr_properties & PROP_objsz)
    4187                 :    73660761 :       && operands[0].opcode == ADDR_EXPR
    4188                 :   102845370 :       && operands.last ().opcode == SSA_NAME)
    4189                 :             :     {
    4190                 :     1148633 :       tree ops[2];
    4191                 :     1148633 :       if (vn_pp_nary_for_addr (operands, ops))
    4192                 :             :         {
    4193                 :      771972 :           tree res = vn_nary_op_lookup_pieces (2, POINTER_PLUS_EXPR,
    4194                 :      771972 :                                                TREE_TYPE (op), ops, NULL);
    4195                 :      771972 :           if (res)
    4196                 :      771972 :             return res;
    4197                 :      771972 :           return NULL_TREE;
    4198                 :             :         }
    4199                 :             :     }
    4200                 :             : 
    4201                 :   100891188 :   vr1.type = TREE_TYPE (op);
    4202                 :   100891188 :   ao_ref op_ref;
    4203                 :   100891188 :   ao_ref_init (&op_ref, op);
    4204                 :   100891188 :   vr1.set = ao_ref_alias_set (&op_ref);
    4205                 :   100891188 :   vr1.base_set = ao_ref_base_alias_set (&op_ref);
    4206                 :   100891188 :   vr1.offset = 0;
    4207                 :   100891188 :   vr1.max_size = -1;
    4208                 :   100891188 :   vr1.hashcode = vn_reference_compute_hash (&vr1);
    4209                 :   100891188 :   if (mask == NULL_TREE)
    4210                 :   100527162 :     if (tree cst = fully_constant_vn_reference_p (&vr1))
    4211                 :             :       return cst;
    4212                 :             : 
    4213                 :   100878074 :   if (kind != VN_NOWALK && vr1.vuse)
    4214                 :             :     {
    4215                 :    58683810 :       vn_reference_t wvnresult;
    4216                 :    58683810 :       ao_ref r;
    4217                 :    58683810 :       unsigned limit = param_sccvn_max_alias_queries_per_access;
    4218                 :    58683810 :       auto_vec<vn_reference_op_s> ops_for_ref;
    4219                 :    58683810 :       if (valueized_anything)
    4220                 :             :         {
    4221                 :     4492000 :           copy_reference_ops_from_ref (op, &ops_for_ref);
    4222                 :     4492000 :           bool tem;
    4223                 :     4492000 :           valueize_refs_1 (&ops_for_ref, &tem, true);
    4224                 :             :         }
    4225                 :             :       /* Make sure to use a valueized reference if we valueized anything.
    4226                 :             :          Otherwise preserve the full reference for advanced TBAA.  */
    4227                 :    58683810 :       if (!valueized_anything
    4228                 :    58683810 :           || !ao_ref_init_from_vn_reference (&r, vr1.set, vr1.base_set,
    4229                 :             :                                              vr1.type, ops_for_ref))
    4230                 :             :         {
    4231                 :    54191810 :           ao_ref_init (&r, op);
    4232                 :             :           /* Record the extra info we're getting from the full ref.  */
    4233                 :    54191810 :           ao_ref_base (&r);
    4234                 :    54191810 :           vr1.offset = r.offset;
    4235                 :    54191810 :           vr1.max_size = r.max_size;
    4236                 :             :         }
    4237                 :    58683810 :       vn_walk_cb_data data (&vr1, r.ref ? NULL_TREE : op,
    4238                 :             :                             last_vuse_ptr, kind, tbaa_p, mask,
    4239                 :   112875620 :                             redundant_store_removal_p);
    4240                 :             : 
    4241                 :    58683810 :       wvnresult
    4242                 :             :         = ((vn_reference_t)
    4243                 :    58683810 :            walk_non_aliased_vuses (&r, vr1.vuse, tbaa_p, vn_reference_lookup_2,
    4244                 :             :                                    vn_reference_lookup_3, vuse_valueize, limit,
    4245                 :             :                                    &data));
    4246                 :   117367620 :       gcc_checking_assert (vr1.operands == shared_lookup_references);
    4247                 :    58683810 :       if (wvnresult)
    4248                 :             :         {
    4249                 :     8454954 :           gcc_assert (mask == NULL_TREE);
    4250                 :     8454954 :           if (data.same_val
    4251                 :     8454954 :               && (!wvnresult->result
    4252                 :       66362 :                   || !operand_equal_p (wvnresult->result, data.same_val)))
    4253                 :       46501 :             return NULL_TREE;
    4254                 :     8408453 :           if (vnresult)
    4255                 :     8407278 :             *vnresult = wvnresult;
    4256                 :     8408453 :           return wvnresult->result;
    4257                 :             :         }
    4258                 :    50228856 :       else if (mask)
    4259                 :      364026 :         return data.masked_result;
    4260                 :             : 
    4261                 :             :       return NULL_TREE;
    4262                 :    58683810 :     }
    4263                 :             : 
    4264                 :    42194264 :   if (last_vuse_ptr)
    4265                 :     1477101 :     *last_vuse_ptr = vr1.vuse;
    4266                 :    42194264 :   if (mask)
    4267                 :             :     return NULL_TREE;
    4268                 :    42194264 :   return vn_reference_lookup_1 (&vr1, vnresult);
    4269                 :             : }
    4270                 :             : 
    4271                 :             : /* Lookup CALL in the current hash table and return the entry in
    4272                 :             :    *VNRESULT if found.  Populates *VR for the hashtable lookup.  */
    4273                 :             : 
    4274                 :             : void
    4275                 :     9233941 : vn_reference_lookup_call (gcall *call, vn_reference_t *vnresult,
    4276                 :             :                           vn_reference_t vr)
    4277                 :             : {
    4278                 :     9233941 :   if (vnresult)
    4279                 :     9233941 :     *vnresult = NULL;
    4280                 :             : 
    4281                 :     9233941 :   tree vuse = gimple_vuse (call);
    4282                 :             : 
    4283                 :     9233941 :   vr->vuse = vuse ? SSA_VAL (vuse) : NULL_TREE;
    4284                 :     9233941 :   vr->operands = valueize_shared_reference_ops_from_call (call);
    4285                 :     9233941 :   tree lhs = gimple_call_lhs (call);
    4286                 :             :   /* For non-SSA return values the referece ops contain the LHS.  */
    4287                 :     4989120 :   vr->type = ((lhs && TREE_CODE (lhs) == SSA_NAME)
    4288                 :    13780287 :               ? TREE_TYPE (lhs) : NULL_TREE);
    4289                 :     9233941 :   vr->punned = false;
    4290                 :     9233941 :   vr->set = 0;
    4291                 :     9233941 :   vr->base_set = 0;
    4292                 :     9233941 :   vr->offset = 0;
    4293                 :     9233941 :   vr->max_size = -1;
    4294                 :     9233941 :   vr->hashcode = vn_reference_compute_hash (vr);
    4295                 :     9233941 :   vn_reference_lookup_1 (vr, vnresult);
    4296                 :     9233941 : }
    4297                 :             : 
    4298                 :             : /* Insert OP into the current hash table with a value number of RESULT.  */
    4299                 :             : 
    4300                 :             : static void
    4301                 :    75571402 : vn_reference_insert (tree op, tree result, tree vuse, tree vdef)
    4302                 :             : {
    4303                 :    75571402 :   vn_reference_s **slot;
    4304                 :    75571402 :   vn_reference_t vr1;
    4305                 :    75571402 :   bool tem;
    4306                 :             : 
    4307                 :    75571402 :   vec<vn_reference_op_s> operands
    4308                 :    75571402 :     = valueize_shared_reference_ops_from_ref (op, &tem);
    4309                 :             :   /* Handle &MEM[ptr + 5].b[1].c as POINTER_PLUS_EXPR.  Avoid doing this
    4310                 :             :      before the pass folding __builtin_object_size had a chance to run.  */
    4311                 :    75571402 :   if ((cfun->curr_properties & PROP_objsz)
    4312                 :    56695267 :       && operands[0].opcode == ADDR_EXPR
    4313                 :    76530499 :       && operands.last ().opcode == SSA_NAME)
    4314                 :             :     {
    4315                 :      928184 :       tree ops[2];
    4316                 :      928184 :       if (vn_pp_nary_for_addr (operands, ops))
    4317                 :             :         {
    4318                 :      610075 :           vn_nary_op_insert_pieces (2, POINTER_PLUS_EXPR,
    4319                 :      610075 :                                     TREE_TYPE (op), ops, result,
    4320                 :      610075 :                                     VN_INFO (result)->value_id);
    4321                 :      610075 :           return;
    4322                 :             :         }
    4323                 :             :     }
    4324                 :             : 
    4325                 :    74961327 :   vr1 = XOBNEW (&vn_tables_obstack, vn_reference_s);
    4326                 :    74961327 :   if (TREE_CODE (result) == SSA_NAME)
    4327                 :    51926429 :     vr1->value_id = VN_INFO (result)->value_id;
    4328                 :             :   else
    4329                 :    23034898 :     vr1->value_id = get_or_alloc_constant_value_id (result);
    4330                 :    74961327 :   vr1->vuse = vuse_ssa_val (vuse);
    4331                 :    74961327 :   vr1->operands = operands.copy ();
    4332                 :    74961327 :   vr1->type = TREE_TYPE (op);
    4333                 :    74961327 :   vr1->punned = false;
    4334                 :    74961327 :   ao_ref op_ref;
    4335                 :    74961327 :   ao_ref_init (&op_ref, op);
    4336                 :    74961327 :   vr1->set = ao_ref_alias_set (&op_ref);
    4337                 :    74961327 :   vr1->base_set = ao_ref_base_alias_set (&op_ref);
    4338                 :             :   /* Specifically use an unknown extent here, we're not doing any lookup
    4339                 :             :      and assume the caller didn't either (or it went VARYING).  */
    4340                 :    74961327 :   vr1->offset = 0;
    4341                 :    74961327 :   vr1->max_size = -1;
    4342                 :    74961327 :   vr1->hashcode = vn_reference_compute_hash (vr1);
    4343                 :    74961327 :   vr1->result = TREE_CODE (result) == SSA_NAME ? SSA_VAL (result) : result;
    4344                 :    74961327 :   vr1->result_vdef = vdef;
    4345                 :             : 
    4346                 :    74961327 :   slot = valid_info->references->find_slot_with_hash (vr1, vr1->hashcode,
    4347                 :             :                                                       INSERT);
    4348                 :             : 
    4349                 :             :   /* Because IL walking on reference lookup can end up visiting
    4350                 :             :      a def that is only to be visited later in iteration order
    4351                 :             :      when we are about to make an irreducible region reducible
    4352                 :             :      the def can be effectively processed and its ref being inserted
    4353                 :             :      by vn_reference_lookup_3 already.  So we cannot assert (!*slot)
    4354                 :             :      but save a lookup if we deal with already inserted refs here.  */
    4355                 :    74961327 :   if (*slot)
    4356                 :             :     {
    4357                 :             :       /* We cannot assert that we have the same value either because
    4358                 :             :          when disentangling an irreducible region we may end up visiting
    4359                 :             :          a use before the corresponding def.  That's a missed optimization
    4360                 :             :          only though.  See gcc.dg/tree-ssa/pr87126.c for example.  */
    4361                 :           0 :       if (dump_file && (dump_flags & TDF_DETAILS)
    4362                 :           0 :           && !operand_equal_p ((*slot)->result, vr1->result, 0))
    4363                 :             :         {
    4364                 :           0 :           fprintf (dump_file, "Keeping old value ");
    4365                 :           0 :           print_generic_expr (dump_file, (*slot)->result);
    4366                 :           0 :           fprintf (dump_file, " because of collision\n");
    4367                 :             :         }
    4368                 :           0 :       free_reference (vr1);
    4369                 :           0 :       obstack_free (&vn_tables_obstack, vr1);
    4370                 :           0 :       return;
    4371                 :             :     }
    4372                 :             : 
    4373                 :    74961327 :   *slot = vr1;
    4374                 :    74961327 :   vr1->next = last_inserted_ref;
    4375                 :    74961327 :   last_inserted_ref = vr1;
    4376                 :             : }
    4377                 :             : 
    4378                 :             : /* Insert a reference by it's pieces into the current hash table with
    4379                 :             :    a value number of RESULT.  Return the resulting reference
    4380                 :             :    structure we created.  */
    4381                 :             : 
    4382                 :             : vn_reference_t
    4383                 :     3787030 : vn_reference_insert_pieces (tree vuse, alias_set_type set,
    4384                 :             :                             alias_set_type base_set,
    4385                 :             :                             poly_int64 offset, poly_int64 max_size, tree type,
    4386                 :             :                             vec<vn_reference_op_s> operands,
    4387                 :             :                             tree result, unsigned int value_id)
    4388                 :             : 
    4389                 :             : {
    4390                 :     3787030 :   vn_reference_s **slot;
    4391                 :     3787030 :   vn_reference_t vr1;
    4392                 :             : 
    4393                 :     3787030 :   vr1 = XOBNEW (&vn_tables_obstack, vn_reference_s);
    4394                 :     3787030 :   vr1->value_id = value_id;
    4395                 :     3787030 :   vr1->vuse = vuse_ssa_val (vuse);
    4396                 :     3787030 :   vr1->operands = operands;
    4397                 :     3787030 :   valueize_refs (&vr1->operands);
    4398                 :     3787030 :   vr1->type = type;
    4399                 :     3787030 :   vr1->punned = false;
    4400                 :     3787030 :   vr1->set = set;
    4401                 :     3787030 :   vr1->base_set = base_set;
    4402                 :     3787030 :   vr1->offset = offset;
    4403                 :     3787030 :   vr1->max_size = max_size;
    4404                 :     3787030 :   vr1->hashcode = vn_reference_compute_hash (vr1);
    4405                 :     3787030 :   if (result && TREE_CODE (result) == SSA_NAME)
    4406                 :      280464 :     result = SSA_VAL (result);
    4407                 :     3787030 :   vr1->result = result;
    4408                 :     3787030 :   vr1->result_vdef = NULL_TREE;
    4409                 :             : 
    4410                 :     3787030 :   slot = valid_info->references->find_slot_with_hash (vr1, vr1->hashcode,
    4411                 :             :                                                       INSERT);
    4412                 :             : 
    4413                 :             :   /* At this point we should have all the things inserted that we have
    4414                 :             :      seen before, and we should never try inserting something that
    4415                 :             :      already exists.  */
    4416                 :     3787030 :   gcc_assert (!*slot);
    4417                 :             : 
    4418                 :     3787030 :   *slot = vr1;
    4419                 :     3787030 :   vr1->next = last_inserted_ref;
    4420                 :     3787030 :   last_inserted_ref = vr1;
    4421                 :     3787030 :   return vr1;
    4422                 :             : }
    4423                 :             : 
    4424                 :             : /* Compute and return the hash value for nary operation VBO1.  */
    4425                 :             : 
    4426                 :             : hashval_t
    4427                 :   302935686 : vn_nary_op_compute_hash (const vn_nary_op_t vno1)
    4428                 :             : {
    4429                 :   302935686 :   inchash::hash hstate;
    4430                 :   302935686 :   unsigned i;
    4431                 :             : 
    4432                 :   302935686 :   if (((vno1->length == 2
    4433                 :   255708327 :         && commutative_tree_code (vno1->opcode))
    4434                 :   138643275 :        || (vno1->length == 3
    4435                 :     1377832 :            && commutative_ternary_tree_code (vno1->opcode)))
    4436                 :   467229986 :       && tree_swap_operands_p (vno1->op[0], vno1->op[1]))
    4437                 :     3078037 :     std::swap (vno1->op[0], vno1->op[1]);
    4438                 :   299857649 :   else if (TREE_CODE_CLASS (vno1->opcode) == tcc_comparison
    4439                 :   299857649 :            && tree_swap_operands_p (vno1->op[0], vno1->op[1]))
    4440                 :             :     {
    4441                 :      469576 :       std::swap (vno1->op[0], vno1->op[1]);
    4442                 :      469576 :       vno1->opcode = swap_tree_comparison  (vno1->opcode);
    4443                 :             :     }
    4444                 :             : 
    4445                 :   302935686 :   hstate.add_int (vno1->opcode);
    4446                 :   864982953 :   for (i = 0; i < vno1->length; ++i)
    4447                 :   562047267 :     inchash::add_expr (vno1->op[i], hstate);
    4448                 :             : 
    4449                 :   302935686 :   return hstate.end ();
    4450                 :             : }
    4451                 :             : 
    4452                 :             : /* Compare nary operations VNO1 and VNO2 and return true if they are
    4453                 :             :    equivalent.  */
    4454                 :             : 
    4455                 :             : bool
    4456                 :   956749034 : vn_nary_op_eq (const_vn_nary_op_t const vno1, const_vn_nary_op_t const vno2)
    4457                 :             : {
    4458                 :   956749034 :   unsigned i;
    4459                 :             : 
    4460                 :   956749034 :   if (vno1->hashcode != vno2->hashcode)
    4461                 :             :     return false;
    4462                 :             : 
    4463                 :    50007228 :   if (vno1->length != vno2->length)
    4464                 :             :     return false;
    4465                 :             : 
    4466                 :    50007228 :   if (vno1->opcode != vno2->opcode
    4467                 :    50007228 :       || !types_compatible_p (vno1->type, vno2->type))
    4468                 :     1193171 :     return false;
    4469                 :             : 
    4470                 :   141048641 :   for (i = 0; i < vno1->length; ++i)
    4471                 :    92329924 :     if (!expressions_equal_p (vno1->op[i], vno2->op[i]))
    4472                 :             :       return false;
    4473                 :             : 
    4474                 :             :   /* BIT_INSERT_EXPR has an implict operand as the type precision
    4475                 :             :      of op1.  Need to check to make sure they are the same.  */
    4476                 :    48718717 :   if (vno1->opcode == BIT_INSERT_EXPR
    4477                 :         506 :       && TREE_CODE (vno1->op[1]) == INTEGER_CST
    4478                 :    48718802 :       && TYPE_PRECISION (TREE_TYPE (vno1->op[1]))
    4479                 :          85 :          != TYPE_PRECISION (TREE_TYPE (vno2->op[1])))
    4480                 :             :     return false;
    4481                 :             : 
    4482                 :             :   return true;
    4483                 :             : }
    4484                 :             : 
    4485                 :             : /* Initialize VNO from the pieces provided.  */
    4486                 :             : 
    4487                 :             : static void
    4488                 :   188694399 : init_vn_nary_op_from_pieces (vn_nary_op_t vno, unsigned int length,
    4489                 :             :                              enum tree_code code, tree type, tree *ops)
    4490                 :             : {
    4491                 :   188694399 :   vno->opcode = code;
    4492                 :   188694399 :   vno->length = length;
    4493                 :   188694399 :   vno->type = type;
    4494                 :     4860886 :   memcpy (&vno->op[0], ops, sizeof (tree) * length);
    4495                 :           0 : }
    4496                 :             : 
    4497                 :             : /* Return the number of operands for a vn_nary ops structure from STMT.  */
    4498                 :             : 
    4499                 :             : unsigned int
    4500                 :   108245404 : vn_nary_length_from_stmt (gimple *stmt)
    4501                 :             : {
    4502                 :   108245404 :   switch (gimple_assign_rhs_code (stmt))
    4503                 :             :     {
    4504                 :             :     case REALPART_EXPR:
    4505                 :             :     case IMAGPART_EXPR:
    4506                 :             :     case VIEW_CONVERT_EXPR:
    4507                 :             :       return 1;
    4508                 :             : 
    4509                 :      514371 :     case BIT_FIELD_REF:
    4510                 :      514371 :       return 3;
    4511                 :             : 
    4512                 :      492163 :     case CONSTRUCTOR:
    4513                 :      492163 :       return CONSTRUCTOR_NELTS (gimple_assign_rhs1 (stmt));
    4514                 :             : 
    4515                 :   103962460 :     default:
    4516                 :   103962460 :       return gimple_num_ops (stmt) - 1;
    4517                 :             :     }
    4518                 :             : }
    4519                 :             : 
    4520                 :             : /* Initialize VNO from STMT.  */
    4521                 :             : 
    4522                 :             : void
    4523                 :   108245404 : init_vn_nary_op_from_stmt (vn_nary_op_t vno, gassign *stmt)
    4524                 :             : {
    4525                 :   108245404 :   unsigned i;
    4526                 :             : 
    4527                 :   108245404 :   vno->opcode = gimple_assign_rhs_code (stmt);
    4528                 :   108245404 :   vno->type = TREE_TYPE (gimple_assign_lhs (stmt));
    4529                 :   108245404 :   switch (vno->opcode)
    4530                 :             :     {
    4531                 :     3276410 :     case REALPART_EXPR:
    4532                 :     3276410 :     case IMAGPART_EXPR:
    4533                 :     3276410 :     case VIEW_CONVERT_EXPR:
    4534                 :     3276410 :       vno->length = 1;
    4535                 :     3276410 :       vno->op[0] = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
    4536                 :     3276410 :       break;
    4537                 :             : 
    4538                 :      514371 :     case BIT_FIELD_REF:
    4539                 :      514371 :       vno->length = 3;
    4540                 :      514371 :       vno->op[0] = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
    4541                 :      514371 :       vno->op[1] = TREE_OPERAND (gimple_assign_rhs1 (stmt), 1);
    4542                 :      514371 :       vno->op[2] = TREE_OPERAND (gimple_assign_rhs1 (stmt), 2);
    4543                 :      514371 :       break;
    4544                 :             : 
    4545                 :      492163 :     case CONSTRUCTOR:
    4546                 :      492163 :       vno->length = CONSTRUCTOR_NELTS (gimple_assign_rhs1 (stmt));
    4547                 :     1900857 :       for (i = 0; i < vno->length; ++i)
    4548                 :     1408694 :         vno->op[i] = CONSTRUCTOR_ELT (gimple_assign_rhs1 (stmt), i)->value;
    4549                 :             :       break;
    4550                 :             : 
    4551                 :   103962460 :     default:
    4552                 :   103962460 :       gcc_checking_assert (!gimple_assign_single_p (stmt));
    4553                 :   103962460 :       vno->length = gimple_num_ops (stmt) - 1;
    4554                 :   284610282 :       for (i = 0; i < vno->length; ++i)
    4555                 :   180647822 :         vno->op[i] = gimple_op (stmt, i + 1);
    4556                 :             :     }
    4557                 :   108245404 : }
    4558                 :             : 
    4559                 :             : /* Compute the hashcode for VNO and look for it in the hash table;
    4560                 :             :    return the resulting value number if it exists in the hash table.
    4561                 :             :    Return NULL_TREE if it does not exist in the hash table or if the
    4562                 :             :    result field of the operation is NULL.  VNRESULT will contain the
    4563                 :             :    vn_nary_op_t from the hashtable if it exists.  */
    4564                 :             : 
    4565                 :             : static tree
    4566                 :   130804853 : vn_nary_op_lookup_1 (vn_nary_op_t vno, vn_nary_op_t *vnresult)
    4567                 :             : {
    4568                 :   130804853 :   vn_nary_op_s **slot;
    4569                 :             : 
    4570                 :   130804853 :   if (vnresult)
    4571                 :   123692033 :     *vnresult = NULL;
    4572                 :             : 
    4573                 :   363808584 :   for (unsigned i = 0; i < vno->length; ++i)
    4574                 :   233003731 :     if (TREE_CODE (vno->op[i]) == SSA_NAME)
    4575                 :   165133120 :       vno->op[i] = SSA_VAL (vno->op[i]);
    4576                 :             : 
    4577                 :   130804853 :   vno->hashcode = vn_nary_op_compute_hash (vno);
    4578                 :   130804853 :   slot = valid_info->nary->find_slot_with_hash (vno, vno->hashcode, NO_INSERT);
    4579                 :   130804853 :   if (!slot)
    4580                 :             :     return NULL_TREE;
    4581                 :    17389821 :   if (vnresult)
    4582                 :    16926907 :     *vnresult = *slot;
    4583                 :    17389821 :   return (*slot)->predicated_values ? NULL_TREE : (*slot)->u.result;
    4584                 :             : }
    4585                 :             : 
    4586                 :             : /* Lookup a n-ary operation by its pieces and return the resulting value
    4587                 :             :    number if it exists in the hash table.  Return NULL_TREE if it does
    4588                 :             :    not exist in the hash table or if the result field of the operation
    4589                 :             :    is NULL. VNRESULT will contain the vn_nary_op_t from the hashtable
    4590                 :             :    if it exists.  */
    4591                 :             : 
    4592                 :             : tree
    4593                 :    74813177 : vn_nary_op_lookup_pieces (unsigned int length, enum tree_code code,
    4594                 :             :                           tree type, tree *ops, vn_nary_op_t *vnresult)
    4595                 :             : {
    4596                 :    74813177 :   vn_nary_op_t vno1 = XALLOCAVAR (struct vn_nary_op_s,
    4597                 :             :                                   sizeof_vn_nary_op (length));
    4598                 :    74813177 :   init_vn_nary_op_from_pieces (vno1, length, code, type, ops);
    4599                 :    74813177 :   return vn_nary_op_lookup_1 (vno1, vnresult);
    4600                 :             : }
    4601                 :             : 
    4602                 :             : /* Lookup the rhs of STMT in the current hash table, and return the resulting
    4603                 :             :    value number if it exists in the hash table.  Return NULL_TREE if
    4604                 :             :    it does not exist in the hash table.  VNRESULT will contain the
    4605                 :             :    vn_nary_op_t from the hashtable if it exists.  */
    4606                 :             : 
    4607                 :             : tree
    4608                 :    55991676 : vn_nary_op_lookup_stmt (gimple *stmt, vn_nary_op_t *vnresult)
    4609                 :             : {
    4610                 :    55991676 :   vn_nary_op_t vno1
    4611                 :    55991676 :     = XALLOCAVAR (struct vn_nary_op_s,
    4612                 :             :                   sizeof_vn_nary_op (vn_nary_length_from_stmt (stmt)));
    4613                 :    55991676 :   init_vn_nary_op_from_stmt (vno1, as_a <gassign *> (stmt));
    4614                 :    55991676 :   return vn_nary_op_lookup_1 (vno1, vnresult);
    4615                 :             : }
    4616                 :             : 
    4617                 :             : /* Allocate a vn_nary_op_t with LENGTH operands on STACK.  */
    4618                 :             : 
    4619                 :             : vn_nary_op_t
    4620                 :   171161042 : alloc_vn_nary_op_noinit (unsigned int length, struct obstack *stack)
    4621                 :             : {
    4622                 :   171161042 :   return (vn_nary_op_t) obstack_alloc (stack, sizeof_vn_nary_op (length));
    4623                 :             : }
    4624                 :             : 
    4625                 :             : /* Allocate and initialize a vn_nary_op_t on CURRENT_INFO's
    4626                 :             :    obstack.  */
    4627                 :             : 
    4628                 :             : static vn_nary_op_t
    4629                 :   153679181 : alloc_vn_nary_op (unsigned int length, tree result, unsigned int value_id)
    4630                 :             : {
    4631                 :           0 :   vn_nary_op_t vno1 = alloc_vn_nary_op_noinit (length, &vn_tables_obstack);
    4632                 :             : 
    4633                 :   153679181 :   vno1->value_id = value_id;
    4634                 :   153679181 :   vno1->length = length;
    4635                 :   153679181 :   vno1->predicated_values = 0;
    4636                 :   153679181 :   vno1->u.result = result;
    4637                 :             : 
    4638                 :   153679181 :   return vno1;
    4639                 :             : }
    4640                 :             : 
    4641                 :             : /* Insert VNO into TABLE.  */
    4642                 :             : 
    4643                 :             : static vn_nary_op_t
    4644                 :   158677853 : vn_nary_op_insert_into (vn_nary_op_t vno, vn_nary_op_table_type *table)
    4645                 :             : {
    4646                 :   158677853 :   vn_nary_op_s **slot;
    4647                 :             : 
    4648                 :   158677853 :   gcc_assert (! vno->predicated_values
    4649                 :             :               || (! vno->u.values->next
    4650                 :             :                   && vno->u.values->n == 1));
    4651                 :             : 
    4652                 :   464345553 :   for (unsigned i = 0; i < vno->length; ++i)
    4653                 :   305667700 :     if (TREE_CODE (vno->op[i]) == SSA_NAME)
    4654                 :   198775025 :       vno->op[i] = SSA_VAL (vno->op[i]);
    4655                 :             : 
    4656                 :   158677853 :   vno->hashcode = vn_nary_op_compute_hash (vno);
    4657                 :   158677853 :   slot = table->find_slot_with_hash (vno, vno->hashcode, INSERT);
    4658                 :   158677853 :   vno->unwind_to = *slot;
    4659                 :   158677853 :   if (*slot)
    4660                 :             :     {
    4661                 :             :       /* Prefer non-predicated values.
    4662                 :             :          ???  Only if those are constant, otherwise, with constant predicated
    4663                 :             :          value, turn them into predicated values with entry-block validity
    4664                 :             :          (???  but we always find the first valid result currently).  */
    4665                 :    30359105 :       if ((*slot)->predicated_values
    4666                 :    29602086 :           && ! vno->predicated_values)
    4667                 :             :         {
    4668                 :             :           /* ???  We cannot remove *slot from the unwind stack list.
    4669                 :             :              For the moment we deal with this by skipping not found
    4670                 :             :              entries but this isn't ideal ...  */
    4671                 :       82419 :           *slot = vno;
    4672                 :             :           /* ???  Maintain a stack of states we can unwind in
    4673                 :             :              vn_nary_op_s?  But how far do we unwind?  In reality
    4674                 :             :              we need to push change records somewhere...  Or not
    4675                 :             :              unwind vn_nary_op_s and linking them but instead
    4676                 :             :              unwind the results "list", linking that, which also
    4677                 :             :              doesn't move on hashtable resize.  */
    4678                 :             :           /* We can also have a ->unwind_to recording *slot there.
    4679                 :             :              That way we can make u.values a fixed size array with
    4680                 :             :              recording the number of entries but of course we then
    4681                 :             :              have always N copies for each unwind_to-state.  Or we
    4682                 :             :              make sure to only ever append and each unwinding will
    4683                 :             :              pop off one entry (but how to deal with predicated
    4684                 :             :              replaced with non-predicated here?)  */
    4685                 :       82419 :           vno->next = last_inserted_nary;
    4686                 :       82419 :           last_inserted_nary = vno;
    4687                 :       82419 :           return vno;
    4688                 :             :         }
    4689                 :    30276686 :       else if (vno->predicated_values
    4690                 :    30272640 :                && ! (*slot)->predicated_values)
    4691                 :             :         return *slot;
    4692                 :    29523713 :       else if (vno->predicated_values
    4693                 :    29519667 :                && (*slot)->predicated_values)
    4694                 :             :         {
    4695                 :             :           /* ???  Factor this all into a insert_single_predicated_value
    4696                 :             :              routine.  */
    4697                 :    29519667 :           gcc_assert (!vno->u.values->next && vno->u.values->n == 1);
    4698                 :    29519667 :           basic_block vno_bb
    4699                 :    29519667 :             = BASIC_BLOCK_FOR_FN (cfun, vno->u.values->valid_dominated_by_p[0]);
    4700                 :    29519667 :           vn_pval *nval = vno->u.values;
    4701                 :    29519667 :           vn_pval **next = &vno->u.values;
    4702                 :    29519667 :           vn_pval *ins = NULL;
    4703                 :    29519667 :           vn_pval *ins_at = NULL;
    4704                 :             :           /* Find an existing value to append to.  */
    4705                 :    55818021 :           for (vn_pval *val = (*slot)->u.values; val; val = val->next)
    4706                 :             :             {
    4707                 :    30455904 :               if (expressions_equal_p (val->result, nval->result))
    4708                 :             :                 {
    4709                 :             :                   /* Limit the number of places we register a predicate
    4710                 :             :                      as valid.  */
    4711                 :     4157550 :                   if (val->n > 8)
    4712                 :      120770 :                     return *slot;
    4713                 :    10200322 :                   for (unsigned i = 0; i < val->n; ++i)
    4714                 :             :                     {
    4715                 :     6395917 :                       basic_block val_bb
    4716                 :     6395917 :                         = BASIC_BLOCK_FOR_FN (cfun,
    4717                 :             :                                               val->valid_dominated_by_p[i]);
    4718                 :     6395917 :                       if (dominated_by_p (CDI_DOMINATORS, vno_bb, val_bb))
    4719                 :             :                         /* Value registered with more generic predicate.  */
    4720                 :      232375 :                         return *slot;
    4721                 :     6163542 :                       else if (flag_checking)
    4722                 :             :                         /* Shouldn't happen, we insert in RPO order.  */
    4723                 :     6163542 :                         gcc_assert (!dominated_by_p (CDI_DOMINATORS,
    4724                 :             :                                                      val_bb, vno_bb));
    4725                 :             :                     }
    4726                 :             :                   /* Append the location.  */
    4727                 :     3804405 :                   ins_at = val;
    4728                 :     3804405 :                   ins = (vn_pval *) obstack_alloc (&vn_tables_obstack,
    4729                 :             :                                                    sizeof (vn_pval)
    4730                 :             :                                                    + val->n * sizeof (int));
    4731                 :     3804405 :                   ins->next = NULL;
    4732                 :     3804405 :                   ins->result = val->result;
    4733                 :     3804405 :                   ins->n = val->n + 1;
    4734                 :     3804405 :                   memcpy (ins->valid_dominated_by_p,
    4735                 :     3804405 :                           val->valid_dominated_by_p,
    4736                 :     3804405 :                           val->n * sizeof (int));
    4737                 :     3804405 :                   ins->valid_dominated_by_p[val->n] = vno_bb->index;
    4738                 :     3804405 :                   if (dump_file && (dump_flags & TDF_DETAILS))
    4739                 :           4 :                     fprintf (dump_file, "Appending predicate to value.\n");
    4740                 :             :                   break;
    4741                 :             :                 }
    4742                 :             :             }
    4743                 :             :           /* Copy the rest of the value chain.  */
    4744                 :    60061943 :           for (vn_pval *val = (*slot)->u.values; val; val = val->next)
    4745                 :             :             {
    4746                 :    30895421 :               if (val == ins_at)
    4747                 :             :                 /* Replace the node we appended to.  */
    4748                 :     3804405 :                 *next = ins;
    4749                 :             :               else
    4750                 :             :                 {
    4751                 :             :                   /* Copy other predicated values.  */
    4752                 :    27091016 :                   *next = (vn_pval *) obstack_alloc (&vn_tables_obstack,
    4753                 :             :                                                      sizeof (vn_pval)
    4754                 :             :                                                      + ((val->n-1)
    4755                 :             :                                                         * sizeof (int)));
    4756                 :    27091016 :                   memcpy (*next, val,
    4757                 :    27091016 :                           sizeof (vn_pval) + (val->n-1) * sizeof (int));
    4758                 :    27091016 :                   (*next)->next = NULL;
    4759                 :             :                 }
    4760                 :    30895421 :               next = &(*next)->next;
    4761                 :             :             }
    4762                 :             :           /* Append the value if we didn't find it.  */
    4763                 :    29166522 :           if (!ins_at)
    4764                 :    25362117 :             *next = nval;
    4765                 :    29166522 :           *slot = vno;
    4766                 :    29166522 :           vno->next = last_inserted_nary;
    4767                 :    29166522 :           last_inserted_nary = vno;
    4768                 :    29166522 :           return vno;
    4769                 :             :         }
    4770                 :             : 
    4771                 :             :       /* While we do not want to insert things twice it's awkward to
    4772                 :             :          avoid it in the case where visit_nary_op pattern-matches stuff
    4773                 :             :          and ends up simplifying the replacement to itself.  We then
    4774                 :             :          get two inserts, one from visit_nary_op and one from
    4775                 :             :          vn_nary_build_or_lookup.
    4776                 :             :          So allow inserts with the same value number.  */
    4777                 :        4046 :       if ((*slot)->u.result == vno->u.result)
    4778                 :             :         return *slot;
    4779                 :             :     }
    4780                 :             : 
    4781                 :             :   /* ???  There's also optimistic vs. previous commited state merging
    4782                 :             :      that is problematic for the case of unwinding.  */
    4783                 :             : 
    4784                 :             :   /* ???  We should return NULL if we do not use 'vno' and have the
    4785                 :             :      caller release it.  */
    4786                 :   128318748 :   gcc_assert (!*slot);
    4787                 :             : 
    4788                 :   128318748 :   *slot = vno;
    4789                 :   128318748 :   vno->next = last_inserted_nary;
    4790                 :   128318748 :   last_inserted_nary = vno;
    4791                 :   128318748 :   return vno;
    4792                 :             : }
    4793                 :             : 
    4794                 :             : /* Insert a n-ary operation into the current hash table using it's
    4795                 :             :    pieces.  Return the vn_nary_op_t structure we created and put in
    4796                 :             :    the hashtable.  */
    4797                 :             : 
    4798                 :             : vn_nary_op_t
    4799                 :      610075 : vn_nary_op_insert_pieces (unsigned int length, enum tree_code code,
    4800                 :             :                           tree type, tree *ops,
    4801                 :             :                           tree result, unsigned int value_id)
    4802                 :             : {
    4803                 :      610075 :   vn_nary_op_t vno1 = alloc_vn_nary_op (length, result, value_id);
    4804                 :      610075 :   init_vn_nary_op_from_pieces (vno1, length, code, type, ops);
    4805                 :      610075 :   return vn_nary_op_insert_into (vno1, valid_info->nary);
    4806                 :             : }
    4807                 :             : 
    4808                 :             : /* Return whether we can track a predicate valid when PRED_E is executed.  */
    4809                 :             : 
    4810                 :             : static bool
    4811                 :   152706481 : can_track_predicate_on_edge (edge pred_e)
    4812                 :             : {
    4813                 :             :   /* ???  As we are currently recording the destination basic-block index in
    4814                 :             :      vn_pval.valid_dominated_by_p and using dominance for the
    4815                 :             :      validity check we cannot track predicates on all edges.  */
    4816                 :   152706481 :   if (single_pred_p (pred_e->dest))
    4817                 :             :     return true;
    4818                 :             :   /* Never record for backedges.  */
    4819                 :    11843907 :   if (pred_e->flags & EDGE_DFS_BACK)
    4820                 :             :     return false;
    4821                 :             :   /* When there's more than one predecessor we cannot track
    4822                 :             :      predicate validity based on the destination block.  The
    4823                 :             :      exception is when all other incoming edges sources are
    4824                 :             :      dominated by the destination block.  */
    4825                 :    11186714 :   edge_iterator ei;
    4826                 :    11186714 :   edge e;
    4827                 :    19443663 :   FOR_EACH_EDGE (e, ei, pred_e->dest->preds)
    4828                 :    17602378 :     if (e != pred_e && ! dominated_by_p (CDI_DOMINATORS, e->src, e->dest))
    4829                 :             :       return false;
    4830                 :             :   return true;
    4831                 :             : }
    4832                 :             : 
    4833                 :             : static vn_nary_op_t
    4834                 :   108410261 : vn_nary_op_insert_pieces_predicated (unsigned int length, enum tree_code code,
    4835                 :             :                                      tree type, tree *ops,
    4836                 :             :                                      tree result, unsigned int value_id,
    4837                 :             :                                      edge pred_e)
    4838                 :             : {
    4839                 :   108410261 :   if (flag_checking)
    4840                 :   108409425 :     gcc_assert (can_track_predicate_on_edge (pred_e));
    4841                 :             : 
    4842                 :       69787 :   if (dump_file && (dump_flags & TDF_DETAILS)
    4843                 :             :       /* ???  Fix dumping, but currently we only get comparisons.  */
    4844                 :   108476096 :       && TREE_CODE_CLASS (code) == tcc_comparison)
    4845                 :             :     {
    4846                 :       65835 :       fprintf (dump_file, "Recording on edge %d->%d ", pred_e->src->index,
    4847                 :       65835 :                pred_e->dest->index);
    4848                 :       65835 :       print_generic_expr (dump_file, ops[0], TDF_SLIM);
    4849                 :       65835 :       fprintf (dump_file, " %s ", get_tree_code_name (code));
    4850                 :       65835 :       print_generic_expr (dump_file, ops[1], TDF_SLIM);
    4851                 :       98437 :       fprintf (dump_file, " == %s\n",
    4852                 :       65835 :                integer_zerop (result) ? "false" : "true");
    4853                 :             :     }
    4854                 :   108410261 :   vn_nary_op_t vno1 = alloc_vn_nary_op (length, NULL_TREE, value_id);
    4855                 :   108410261 :   init_vn_nary_op_from_pieces (vno1, length, code, type, ops);
    4856                 :   108410261 :   vno1->predicated_values = 1;
    4857                 :   108410261 :   vno1->u.values = (vn_pval *) obstack_alloc (&vn_tables_obstack,
    4858                 :             :                                               sizeof (vn_pval));
    4859                 :   108410261 :   vno1->u.values->next = NULL;
    4860                 :   108410261 :   vno1->u.values->result = result;
    4861                 :   108410261 :   vno1->u.values->n = 1;
    4862                 :   108410261 :   vno1->u.values->valid_dominated_by_p[0] = pred_e->dest->index;
    4863                 :   108410261 :   return vn_nary_op_insert_into (vno1, valid_info->nary);
    4864                 :             : }
    4865                 :             : 
    4866                 :             : static bool
    4867                 :             : dominated_by_p_w_unex (basic_block bb1, basic_block bb2, bool);
    4868                 :             : 
    4869                 :             : static tree
    4870                 :     1613305 : vn_nary_op_get_predicated_value (vn_nary_op_t vno, basic_block bb,
    4871                 :             :                                  edge e = NULL)
    4872                 :             : {
    4873                 :     1613305 :   if (! vno->predicated_values)
    4874                 :           0 :     return vno->u.result;
    4875                 :     3339017 :   for (vn_pval *val = vno->u.values; val; val = val->next)
    4876                 :     5047645 :     for (unsigned i = 0; i < val->n; ++i)
    4877                 :             :       {
    4878                 :     3321933 :         basic_block cand
    4879                 :     3321933 :           = BASIC_BLOCK_FOR_FN (cfun, val->valid_dominated_by_p[i]);
    4880                 :             :         /* Do not handle backedge executability optimistically since
    4881                 :             :            when figuring out whether to iterate we do not consider
    4882                 :             :            changed predication.
    4883                 :             :            When asking for predicated values on an edge avoid looking
    4884                 :             :            at edge executability for edges forward in our iteration
    4885                 :             :            as well.  */
    4886                 :     3321933 :         if (e && (e->flags & EDGE_DFS_BACK))
    4887                 :             :           {
    4888                 :       21426 :             if (dominated_by_p (CDI_DOMINATORS, bb, cand))
    4889                 :        7736 :               return val->result;
    4890                 :             :           }
    4891                 :     3300507 :         else if (dominated_by_p_w_unex (bb, cand, false))
    4892                 :      493883 :           return val->result;
    4893                 :             :       }
    4894                 :             :   return NULL_TREE;
    4895                 :             : }
    4896                 :             : 
    4897                 :             : static tree
    4898                 :      205840 : vn_nary_op_get_predicated_value (vn_nary_op_t vno, edge e)
    4899                 :             : {
    4900                 :           0 :   return vn_nary_op_get_predicated_value (vno, e->src, e);
    4901                 :             : }
    4902                 :             : 
    4903                 :             : /* Insert the rhs of STMT into the current hash table with a value number of
    4904                 :             :    RESULT.  */
    4905                 :             : 
    4906                 :             : static vn_nary_op_t
    4907                 :    44658845 : vn_nary_op_insert_stmt (gimple *stmt, tree result)
    4908                 :             : {
    4909                 :    44658845 :   vn_nary_op_t vno1
    4910                 :    44658845 :     = alloc_vn_nary_op (vn_nary_length_from_stmt (stmt),
    4911                 :    44658845 :                         result, VN_INFO (result)->value_id);
    4912                 :    44658845 :   init_vn_nary_op_from_stmt (vno1, as_a <gassign *> (stmt));
    4913                 :    44658845 :   return vn_nary_op_insert_into (vno1, valid_info->nary);
    4914                 :             : }
    4915                 :             : 
    4916                 :             : /* Compute a hashcode for PHI operation VP1 and return it.  */
    4917                 :             : 
    4918                 :             : static inline hashval_t
    4919                 :    51767530 : vn_phi_compute_hash (vn_phi_t vp1)
    4920                 :             : {
    4921                 :    51767530 :   inchash::hash hstate;
    4922                 :    51767530 :   tree phi1op;
    4923                 :    51767530 :   tree type;
    4924                 :    51767530 :   edge e;
    4925                 :    51767530 :   edge_iterator ei;
    4926                 :             : 
    4927                 :   103535060 :   hstate.add_int (EDGE_COUNT (vp1->block->preds));
    4928                 :    51767530 :   switch (EDGE_COUNT (vp1->block->preds))
    4929                 :             :     {
    4930                 :             :     case 1:
    4931                 :             :       break;
    4932                 :    45183987 :     case 2:
    4933                 :             :       /* When this is a PHI node subject to CSE for different blocks
    4934                 :             :          avoid hashing the block index.  */
    4935                 :    45183987 :       if (vp1->cclhs)
    4936                 :             :         break;
    4937                 :             :       /* Fallthru.  */
    4938                 :    33617042 :     default:
    4939                 :    33617042 :       hstate.add_int (vp1->block->index);
    4940                 :             :     }
    4941                 :             : 
    4942                 :             :   /* If all PHI arguments are constants we need to distinguish
    4943                 :             :      the PHI node via its type.  */
    4944                 :    51767530 :   type = vp1->type;
    4945                 :    51767530 :   hstate.merge_hash (vn_hash_type (type));
    4946                 :             : 
    4947                 :   177066128 :   FOR_EACH_EDGE (e, ei, vp1->block->preds)
    4948                 :             :     {
    4949                 :             :       /* Don't hash backedge values they need to be handled as VN_TOP
    4950                 :             :          for optimistic value-numbering.  */
    4951                 :   125298598 :       if (e->flags & EDGE_DFS_BACK)
    4952                 :    27865058 :         continue;
    4953                 :             : 
    4954                 :    97433540 :       phi1op = vp1->phiargs[e->dest_idx];
    4955                 :    97433540 :       if (phi1op == VN_TOP)
    4956                 :      237535 :         continue;
    4957                 :    97196005 :       inchash::add_expr (phi1op, hstate);
    4958                 :             :     }
    4959                 :             : 
    4960                 :    51767530 :   return hstate.end ();
    4961                 :             : }
    4962                 :             : 
    4963                 :             : 
    4964                 :             : /* Return true if COND1 and COND2 represent the same condition, set
    4965                 :             :    *INVERTED_P if one needs to be inverted to make it the same as
    4966                 :             :    the other.  */
    4967                 :             : 
    4968                 :             : static bool
    4969                 :     4024637 : cond_stmts_equal_p (gcond *cond1, tree lhs1, tree rhs1,
    4970                 :             :                     gcond *cond2, tree lhs2, tree rhs2, bool *inverted_p)
    4971                 :             : {
    4972                 :     4024637 :   enum tree_code code1 = gimple_cond_code (cond1);
    4973                 :     4024637 :   enum tree_code code2 = gimple_cond_code (cond2);
    4974                 :             : 
    4975                 :     4024637 :   *inverted_p = false;
    4976                 :     4024637 :   if (code1 == code2)
    4977                 :             :     ;
    4978                 :      317780 :   else if (code1 == swap_tree_comparison (code2))
    4979                 :             :     std::swap (lhs2, rhs2);
    4980                 :      281137 :   else if (code1 == invert_tree_comparison (code2, HONOR_NANS (lhs2)))
    4981                 :      143277 :     *inverted_p = true;
    4982                 :      137860 :   else if (code1 == invert_tree_comparison
    4983                 :      137860 :                       (swap_tree_comparison (code2), HONOR_NANS (lhs2)))
    4984                 :             :     {
    4985                 :       10682 :       std::swap (lhs2, rhs2);
    4986                 :       10682 :       *inverted_p = true;
    4987                 :             :     }
    4988                 :             :   else
    4989                 :             :     return false;
    4990                 :             : 
    4991                 :     3897459 :   return ((expressions_equal_p (lhs1, lhs2)
    4992                 :      162469 :            && expressions_equal_p (rhs1, rhs2))
    4993                 :     3926260 :           || (commutative_tree_code (code1)
    4994                 :     1957438 :               && expressions_equal_p (lhs1, rhs2)
    4995                 :        3576 :               && expressions_equal_p (rhs1, lhs2)));
    4996                 :             : }
    4997                 :             : 
    4998                 :             : /* Compare two phi entries for equality, ignoring VN_TOP arguments.  */
    4999                 :             : 
    5000                 :             : static int
    5001                 :    43167844 : vn_phi_eq (const_vn_phi_t const vp1, const_vn_phi_t const vp2)
    5002                 :             : {
    5003                 :    43167844 :   if (vp1->hashcode != vp2->hashcode)
    5004                 :             :     return false;
    5005                 :             : 
    5006                 :    13274673 :   if (vp1->block != vp2->block)
    5007                 :             :     {
    5008                 :    12096081 :       if (EDGE_COUNT (vp1->block->preds) != EDGE_COUNT (vp2->block->preds))
    5009                 :             :         return false;
    5010                 :             : 
    5011                 :    38979407 :       switch (EDGE_COUNT (vp1->block->preds))
    5012                 :             :         {
    5013                 :             :         case 1:
    5014                 :             :           /* Single-arg PHIs are just copies.  */
    5015                 :             :           break;
    5016                 :             : 
    5017                 :     4032027 :         case 2:
    5018                 :     4032027 :           {
    5019                 :             :             /* Make sure both PHIs are classified as CSEable.  */
    5020                 :     4032027 :             if (! vp1->cclhs || ! vp2->cclhs)
    5021                 :             :               return false;
    5022                 :             : 
    5023                 :             :             /* Rule out backedges into the PHI.  */
    5024                 :     4032027 :             gcc_checking_assert
    5025                 :             :               (vp1->block->loop_father->header != vp1->block
    5026                 :             :                && vp2->block->loop_father->header != vp2->block);
    5027                 :             : 
    5028                 :             :             /* If the PHI nodes do not have compatible types
    5029                 :             :                they are not the same.  */
    5030                 :     4032027 :             if (!types_compatible_p (vp1->type, vp2->type))
    5031                 :             :               return false;
    5032                 :             : 
    5033                 :             :             /* If the immediate dominator end in switch stmts multiple
    5034                 :             :                values may end up in the same PHI arg via intermediate
    5035                 :             :                CFG merges.  */
    5036                 :     4024637 :             basic_block idom1
    5037                 :     4024637 :               = get_immediate_dominator (CDI_DOMINATORS, vp1->block);
    5038                 :     4024637 :             basic_block idom2
    5039                 :     4024637 :               = get_immediate_dominator (CDI_DOMINATORS, vp2->block);
    5040                 :     4024637 :             gcc_checking_assert (EDGE_COUNT (idom1->succs) == 2
    5041                 :             :                                  && EDGE_COUNT (idom2->succs) == 2);
    5042                 :             : 
    5043                 :             :             /* Verify the controlling stmt is the same.  */
    5044                 :     8049274 :             gcond *last1 = as_a <gcond *> (*gsi_last_bb (idom1));
    5045                 :     8049274 :             gcond *last2 = as_a <gcond *> (*gsi_last_bb (idom2));
    5046                 :     4024637 :             bool inverted_p;
    5047                 :     4024637 :             if (! cond_stmts_equal_p (last1, vp1->cclhs, vp1->ccrhs,
    5048                 :     4024637 :                                       last2, vp2->cclhs, vp2->ccrhs,
    5049                 :             :                                       &inverted_p))
    5050                 :             :               return false;
    5051                 :             : 
    5052                 :             :             /* Get at true/false controlled edges into the PHI.  */
    5053                 :      133807 :             edge te1, te2, fe1, fe2;
    5054                 :      133807 :             if (! extract_true_false_controlled_edges (idom1, vp1->block,
    5055                 :             :                                                        &te1, &fe1)
    5056                 :      133807 :                 || ! extract_true_false_controlled_edges (idom2, vp2->block,
    5057                 :             :                                                           &te2, &fe2))
    5058                 :       82814 :               return false;
    5059                 :             : 
    5060                 :             :             /* Swap edges if the second condition is the inverted of the
    5061                 :             :                first.  */
    5062                 :       50993 :             if (inverted_p)
    5063                 :        1999 :               std::swap (te2, fe2);
    5064                 :             : 
    5065                 :             :             /* Since we do not know which edge will be executed we have
    5066                 :             :                to be careful when matching VN_TOP.  Be conservative and
    5067                 :             :                only match VN_TOP == VN_TOP for now, we could allow
    5068                 :             :                VN_TOP on the not prevailing PHI though.  See for example
    5069                 :             :                PR102920.  */
    5070                 :       50993 :             if (! expressions_equal_p (vp1->phiargs[te1->dest_idx],
    5071                 :       50993 :                                        vp2->phiargs[te2->dest_idx], false)
    5072                 :      100248 :                 || ! expressions_equal_p (vp1->phiargs[fe1->dest_idx],
    5073                 :       49255 :                                           vp2->phiargs[fe2->dest_idx], false))
    5074                 :        1738 :               return false;
    5075                 :             : 
    5076                 :             :             return true;
    5077                 :             :           }
    5078                 :             : 
    5079                 :             :         default:
    5080                 :             :           return false;
    5081                 :             :         }
    5082                 :             :     }
    5083                 :             : 
    5084                 :             :   /* If the PHI nodes do not have compatible types
    5085                 :             :      they are not the same.  */
    5086                 :     9242646 :   if (!types_compatible_p (vp1->type, vp2->type))
    5087                 :             :     return false;
    5088                 :             : 
    5089                 :             :   /* Any phi in the same block will have it's arguments in the
    5090                 :             :      same edge order, because of how we store phi nodes.  */
    5091                 :     9241626 :   unsigned nargs = EDGE_COUNT (vp1->block->preds);
    5092                 :    21055736 :   for (unsigned i = 0; i < nargs; ++i)
    5093                 :             :     {
    5094                 :    16867299 :       tree phi1op = vp1->phiargs[i];
    5095                 :    16867299 :       tree phi2op = vp2->phiargs[i];
    5096                 :    16867299 :       if (phi1op == phi2op)
    5097                 :    11719538 :         continue;
    5098                 :     5147761 :       if (!expressions_equal_p (phi1op, phi2op, false))
    5099                 :             :         return false;
    5100                 :             :     }
    5101                 :             : 
    5102                 :             :   return true;
    5103                 :             : }
    5104                 :             : 
    5105                 :             : /* Lookup PHI in the current hash table, and return the resulting
    5106                 :             :    value number if it exists in the hash table.  Return NULL_TREE if
    5107                 :             :    it does not exist in the hash table. */
    5108                 :             : 
    5109                 :             : static tree
    5110                 :    28339551 : vn_phi_lookup (gimple *phi, bool backedges_varying_p)
    5111                 :             : {
    5112                 :    28339551 :   vn_phi_s **slot;
    5113                 :    28339551 :   struct vn_phi_s *vp1;
    5114                 :    28339551 :   edge e;
    5115                 :    28339551 :   edge_iterator ei;
    5116                 :             : 
    5117                 :    28339551 :   vp1 = XALLOCAVAR (struct vn_phi_s,
    5118                 :             :                     sizeof (struct vn_phi_s)
    5119                 :             :                     + (gimple_phi_num_args (phi) - 1) * sizeof (tree));
    5120                 :             : 
    5121                 :             :   /* Canonicalize the SSA_NAME's to their value number.  */
    5122                 :    96295289 :   FOR_EACH_EDGE (e, ei, gimple_bb (phi)->preds)
    5123                 :             :     {
    5124                 :    67955738 :       tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
    5125                 :    67955738 :       if (TREE_CODE (def) == SSA_NAME
    5126                 :    56912990 :           && (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK)))
    5127                 :             :         {
    5128                 :    54383791 :           if (!virtual_operand_p (def)
    5129                 :    54383791 :               && ssa_undefined_value_p (def, false))
    5130                 :      132128 :             def = VN_TOP;
    5131                 :             :           else
    5132                 :    54251663 :             def = SSA_VAL (def);
    5133                 :             :         }
    5134                 :    67955738 :       vp1->phiargs[e->dest_idx] = def;
    5135                 :             :     }
    5136                 :    28339551 :   vp1->type = TREE_TYPE (gimple_phi_result (phi));
    5137                 :    28339551 :   vp1->block = gimple_bb (phi);
    5138                 :             :   /* Extract values of the controlling condition.  */
    5139                 :    28339551 :   vp1->cclhs = NULL_TREE;
    5140                 :    28339551 :   vp1->ccrhs = NULL_TREE;
    5141                 :    28339551 :   if (EDGE_COUNT (vp1->block->preds) == 2
    5142                 :    28339551 :       && vp1->block->loop_father->header != vp1->block)
    5143                 :             :     {
    5144                 :     9642894 :       basic_block idom1 = get_immediate_dominator (CDI_DOMINATORS, vp1->block);
    5145                 :     9642894 :       if (EDGE_COUNT (idom1->succs) == 2)
    5146                 :    19119684 :         if (gcond *last1 = safe_dyn_cast <gcond *> (*gsi_last_bb (idom1)))
    5147                 :             :           {
    5148                 :             :             /* ???  We want to use SSA_VAL here.  But possibly not
    5149                 :             :                allow VN_TOP.  */
    5150                 :     9279207 :             vp1->cclhs = vn_valueize (gimple_cond_lhs (last1));
    5151                 :     9279207 :             vp1->ccrhs = vn_valueize (gimple_cond_rhs (last1));
    5152                 :             :           }
    5153                 :             :     }
    5154                 :    28339551 :   vp1->hashcode = vn_phi_compute_hash (vp1);
    5155                 :    28339551 :   slot = valid_info->phis->find_slot_with_hash (vp1, vp1->hashcode, NO_INSERT);
    5156                 :    28339551 :   if (!slot)
    5157                 :             :     return NULL_TREE;
    5158                 :     4237692 :   return (*slot)->result;
    5159                 :             : }
    5160                 :             : 
    5161                 :             : /* Insert PHI into the current hash table with a value number of
    5162                 :             :    RESULT.  */
    5163                 :             : 
    5164                 :             : static vn_phi_t
    5165                 :    23427979 : vn_phi_insert (gimple *phi, tree result, bool backedges_varying_p)
    5166                 :             : {
    5167                 :    23427979 :   vn_phi_s **slot;
    5168                 :    23427979 :   vn_phi_t vp1 = (vn_phi_t) obstack_alloc (&vn_tables_obstack,
    5169                 :             :                                            sizeof (vn_phi_s)
    5170                 :             :                                            + ((gimple_phi_num_args (phi) - 1)
    5171                 :             :                                               * sizeof (tree)));
    5172                 :    23427979 :   edge e;
    5173                 :    23427979 :   edge_iterator ei;
    5174                 :             : 
    5175                 :             :   /* Canonicalize the SSA_NAME's to their value number.  */
    5176                 :    80770839 :   FOR_EACH_EDGE (e, ei, gimple_bb (phi)->preds)
    5177                 :             :     {
    5178                 :    57342860 :       tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
    5179                 :    57342860 :       if (TREE_CODE (def) == SSA_NAME
    5180                 :    47359499 :           && (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK)))
    5181                 :             :         {
    5182                 :    44830691 :           if (!virtual_operand_p (def)
    5183                 :    44830691 :               && ssa_undefined_value_p (def, false))
    5184                 :      105643 :             def = VN_TOP;
    5185                 :             :           else
    5186                 :    44725048 :             def = SSA_VAL (def);
    5187                 :             :         }
    5188                 :    57342860 :       vp1->phiargs[e->dest_idx] = def;
    5189                 :             :     }
    5190                 :    23427979 :   vp1->value_id = VN_INFO (result)->value_id;
    5191                 :    23427979 :   vp1->type = TREE_TYPE (gimple_phi_result (phi));
    5192                 :    23427979 :   vp1->block = gimple_bb (phi);
    5193                 :             :   /* Extract values of the controlling condition.  */
    5194                 :    23427979 :   vp1->cclhs = NULL_TREE;
    5195                 :    23427979 :   vp1->ccrhs = NULL_TREE;
    5196                 :    23427979 :   if (EDGE_COUNT (vp1->block->preds) == 2
    5197                 :    23427979 :       && vp1->block->loop_father->header != vp1->block)
    5198                 :             :     {
    5199                 :     9206354 :       basic_block idom1 = get_immediate_dominator (CDI_DOMINATORS, vp1->block);
    5200                 :     9206354 :       if (EDGE_COUNT (idom1->succs) == 2)
    5201                 :    18254566 :         if (gcond *last1 = safe_dyn_cast <gcond *> (*gsi_last_bb (idom1)))
    5202                 :             :           {
    5203                 :             :             /* ???  We want to use SSA_VAL here.  But possibly not
    5204                 :             :                allow VN_TOP.  */
    5205                 :     8871281 :             vp1->cclhs = vn_valueize (gimple_cond_lhs (last1));
    5206                 :     8871281 :             vp1->ccrhs = vn_valueize (gimple_cond_rhs (last1));
    5207                 :             :           }
    5208                 :             :     }
    5209                 :    23427979 :   vp1->result = result;
    5210                 :    23427979 :   vp1->hashcode = vn_phi_compute_hash (vp1);
    5211                 :             : 
    5212                 :    23427979 :   slot = valid_info->phis->find_slot_with_hash (vp1, vp1->hashcode, INSERT);
    5213                 :    23427979 :   gcc_assert (!*slot);
    5214                 :             : 
    5215                 :    23427979 :   *slot = vp1;
    5216                 :    23427979 :   vp1->next = last_inserted_phi;
    5217                 :    23427979 :   last_inserted_phi = vp1;
    5218                 :    23427979 :   return vp1;
    5219                 :             : }
    5220                 :             : 
    5221                 :             : 
    5222                 :             : /* Return true if BB1 is dominated by BB2 taking into account edges
    5223                 :             :    that are not executable.  When ALLOW_BACK is false consider not
    5224                 :             :    executable backedges as executable.  */
    5225                 :             : 
    5226                 :             : static bool
    5227                 :    68041799 : dominated_by_p_w_unex (basic_block bb1, basic_block bb2, bool allow_back)
    5228                 :             : {
    5229                 :    68041799 :   edge_iterator ei;
    5230                 :    68041799 :   edge e;
    5231                 :             : 
    5232                 :    68041799 :   if (dominated_by_p (CDI_DOMINATORS, bb1, bb2))
    5233                 :             :     return true;
    5234                 :             : 
    5235                 :             :   /* Before iterating we'd like to know if there exists a
    5236                 :             :      (executable) path from bb2 to bb1 at all, if not we can
    5237                 :             :      directly return false.  For now simply iterate once.  */
    5238                 :             : 
    5239                 :             :   /* Iterate to the single executable bb1 predecessor.  */
    5240                 :    20988423 :   if (EDGE_COUNT (bb1->preds) > 1)
    5241                 :             :     {
    5242                 :     2974972 :       edge prede = NULL;
    5243                 :     6417677 :       FOR_EACH_EDGE (e, ei, bb1->preds)
    5244                 :     6011334 :         if ((e->flags & EDGE_EXECUTABLE)
    5245                 :      547065 :             || (!allow_back && (e->flags & EDGE_DFS_BACK)))
    5246                 :             :           {
    5247                 :     5543601 :             if (prede)
    5248                 :             :               {
    5249                 :             :                 prede = NULL;
    5250                 :             :                 break;
    5251                 :             :               }
    5252                 :             :             prede = e;
    5253                 :             :           }
    5254                 :     2974972 :       if (prede)
    5255                 :             :         {
    5256                 :      406343 :           bb1 = prede->src;
    5257                 :             : 
    5258                 :             :           /* Re-do the dominance check with changed bb1.  */
    5259                 :      406343 :           if (dominated_by_p (CDI_DOMINATORS, bb1, bb2))
    5260                 :             :             return true;
    5261                 :             :         }
    5262                 :             :     }
    5263                 :             : 
    5264                 :             :   /* Iterate to the single executable bb2 successor.  */
    5265                 :    20750845 :   if (EDGE_COUNT (bb2->succs) > 1)
    5266                 :             :     {
    5267                 :     5946042 :       edge succe = NULL;
    5268                 :    12035078 :       FOR_EACH_EDGE (e, ei, bb2->succs)
    5269                 :    11892348 :         if ((e->flags & EDGE_EXECUTABLE)
    5270                 :      178110 :             || (!allow_back && (e->flags & EDGE_DFS_BACK)))
    5271                 :             :           {
    5272                 :    11714289 :             if (succe)
    5273                 :             :               {
    5274                 :             :                 succe = NULL;
    5275                 :             :                 break;
    5276                 :             :               }
    5277                 :             :             succe = e;
    5278                 :             :           }
    5279                 :     5946042 :       if (succe
    5280                 :             :           /* Limit the number of edges we check, we should bring in
    5281                 :             :              context from the iteration and compute the single
    5282                 :             :              executable incoming edge when visiting a block.  */
    5283                 :     5946042 :           && EDGE_COUNT (succe->dest->preds) < 8)
    5284                 :             :         {
    5285                 :             :           /* Verify the reached block is only reached through succe.
    5286                 :             :              If there is only one edge we can spare us the dominator
    5287                 :             :              check and iterate directly.  */
    5288                 :      107349 :           if (EDGE_COUNT (succe->dest->preds) > 1)
    5289                 :             :             {
    5290                 :       54861 :               FOR_EACH_EDGE (e, ei, succe->dest->preds)
    5291                 :       41583 :                 if (e != succe
    5292                 :       26202 :                     && ((e->flags & EDGE_EXECUTABLE)
    5293                 :       18109 :                         || (!allow_back && (e->flags & EDGE_DFS_BACK))))
    5294                 :             :                   {
    5295                 :             :                     succe = NULL;
    5296                 :             :                     break;
    5297                 :             :                   }
    5298                 :             :             }
    5299                 :      107349 :           if (succe)
    5300                 :             :             {
    5301                 :       99247 :               bb2 = succe->dest;
    5302                 :             : 
    5303                 :             :               /* Re-do the dominance check with changed bb2.  */
    5304                 :       99247 :               if (dominated_by_p (CDI_DOMINATORS, bb1, bb2))
    5305                 :             :                 return true;
    5306                 :             :             }
    5307                 :             :         }
    5308                 :             :     }
    5309                 :             :   /* Iterate to the single successor of bb2 with only a single executable
    5310                 :             :      incoming edge.  */
    5311                 :    14804803 :   else if (EDGE_COUNT (bb2->succs) == 1
    5312                 :    14314844 :            && EDGE_COUNT (single_succ (bb2)->preds) > 1
    5313                 :             :            /* Limit the number of edges we check, we should bring in
    5314                 :             :               context from the iteration and compute the single
    5315                 :             :               executable incoming edge when visiting a block.  */
    5316                 :    28863820 :            && EDGE_COUNT (single_succ (bb2)->preds) < 8)
    5317                 :             :     {
    5318                 :     5055110 :       edge prede = NULL;
    5319                 :    11469633 :       FOR_EACH_EDGE (e, ei, single_succ (bb2)->preds)
    5320                 :    10889772 :         if ((e->flags & EDGE_EXECUTABLE)
    5321                 :     1414339 :             || (!allow_back && (e->flags & EDGE_DFS_BACK)))
    5322                 :             :           {
    5323                 :     9479464 :             if (prede)
    5324                 :             :               {
    5325                 :             :                 prede = NULL;
    5326                 :             :                 break;
    5327                 :             :               }
    5328                 :             :             prede = e;
    5329                 :             :           }
    5330                 :             :       /* We might actually get to a query with BB2 not visited yet when
    5331                 :             :          we're querying for a predicated value.  */
    5332                 :     5055110 :       if (prede && prede->src == bb2)
    5333                 :             :         {
    5334                 :      515640 :           bb2 = prede->dest;
    5335                 :             : 
    5336                 :             :           /* Re-do the dominance check with changed bb2.  */
    5337                 :      515640 :           if (dominated_by_p (CDI_DOMINATORS, bb1, bb2))
    5338                 :             :             return true;
    5339                 :             :         }
    5340                 :             :     }
    5341                 :             : 
    5342                 :             :   /* We could now iterate updating bb1 / bb2.  */
    5343                 :             :   return false;
    5344                 :             : }
    5345                 :             : 
    5346                 :             : /* Set the value number of FROM to TO, return true if it has changed
    5347                 :             :    as a result.  */
    5348                 :             : 
    5349                 :             : static inline bool
    5350                 :   207026545 : set_ssa_val_to (tree from, tree to)
    5351                 :             : {
    5352                 :   207026545 :   vn_ssa_aux_t from_info = VN_INFO (from);
    5353                 :   207026545 :   tree currval = from_info->valnum; // SSA_VAL (from)
    5354                 :   207026545 :   poly_int64 toff, coff;
    5355                 :   207026545 :   bool curr_undefined = false;
    5356                 :   207026545 :   bool curr_invariant = false;
    5357                 :             : 
    5358                 :             :   /* The only thing we allow as value numbers are ssa_names
    5359                 :             :      and invariants.  So assert that here.  We don't allow VN_TOP
    5360                 :             :      as visiting a stmt should produce a value-number other than
    5361                 :             :      that.
    5362                 :             :      ???  Still VN_TOP can happen for unreachable code, so force
    5363                 :             :      it to varying in that case.  Not all code is prepared to
    5364                 :             :      get VN_TOP on valueization.  */
    5365                 :   207026545 :   if (to == VN_TOP)
    5366                 :             :     {
    5367                 :             :       /* ???  When iterating and visiting PHI <undef, backedge-value>
    5368                 :             :          for the first time we rightfully get VN_TOP and we need to
    5369                 :             :          preserve that to optimize for example gcc.dg/tree-ssa/ssa-sccvn-2.c.
    5370                 :             :          With SCCVN we were simply lucky we iterated the other PHI
    5371                 :             :          cycles first and thus visited the backedge-value DEF.  */
    5372                 :           0 :       if (currval == VN_TOP)
    5373                 :           0 :         goto set_and_exit;
    5374                 :           0 :       if (dump_file && (dump_flags & TDF_DETAILS))
    5375                 :           0 :         fprintf (dump_file, "Forcing value number to varying on "
    5376                 :             :                  "receiving VN_TOP\n");
    5377                 :             :       to = from;
    5378                 :             :     }
    5379                 :             : 
    5380                 :   207026545 :   gcc_checking_assert (to != NULL_TREE
    5381                 :             :                        && ((TREE_CODE (to) == SSA_NAME
    5382                 :             :                             && (to == from || SSA_VAL (to) == to))
    5383                 :             :                            || is_gimple_min_invariant (to)));
    5384                 :             : 
    5385                 :   207026545 :   if (from != to)
    5386                 :             :     {
    5387                 :    32399955 :       if (currval == from)
    5388                 :             :         {
    5389                 :       15360 :           if (dump_file && (dump_flags & TDF_DETAILS))
    5390                 :             :             {
    5391                 :           0 :               fprintf (dump_file, "Not changing value number of ");
    5392                 :           0 :               print_generic_expr (dump_file, from);
    5393                 :           0 :               fprintf (dump_file, " from VARYING to ");
    5394                 :           0 :               print_generic_expr (dump_file, to);
    5395                 :           0 :               fprintf (dump_file, "\n");
    5396                 :             :             }
    5397                 :       15360 :           return false;
    5398                 :             :         }
    5399                 :    32384595 :       curr_invariant = is_gimple_min_invariant (currval);
    5400                 :    64769190 :       curr_undefined = (TREE_CODE (currval) == SSA_NAME
    5401                 :     3829516 :                         && !virtual_operand_p (currval)
    5402                 :    35974638 :                         && ssa_undefined_value_p (currval, false));
    5403                 :    32384595 :       if (currval != VN_TOP
    5404                 :             :           && !curr_invariant
    5405                 :     5309287 :           && !curr_undefined
    5406                 :    36200436 :           && is_gimple_min_invariant (to))
    5407                 :             :         {
    5408                 :         218 :           if (dump_file && (dump_flags & TDF_DETAILS))
    5409                 :             :             {
    5410                 :           0 :               fprintf (dump_file, "Forcing VARYING instead of changing "
    5411                 :             :                        "value number of ");
    5412                 :           0 :               print_generic_expr (dump_file, from);
    5413                 :           0 :               fprintf (dump_file, " from ");
    5414                 :           0 :               print_generic_expr (dump_file, currval);
    5415                 :           0 :               fprintf (dump_file, " (non-constant) to ");
    5416                 :           0 :               print_generic_expr (dump_file, to);
    5417                 :           0 :               fprintf (dump_file, " (constant)\n");
    5418                 :             :             }
    5419                 :             :           to = from;
    5420                 :             :         }
    5421                 :    32384377 :       else if (currval != VN_TOP
    5422                 :     5309069 :                && !curr_undefined
    5423                 :     5295394 :                && TREE_CODE (to) == SSA_NAME
    5424                 :     4459441 :                && !virtual_operand_p (to)
    5425                 :    36604345 :                && ssa_undefined_value_p (to, false))
    5426                 :             :         {
    5427                 :           6 :           if (dump_file && (dump_flags & TDF_DETAILS))
    5428                 :             :             {
    5429                 :           0 :               fprintf (dump_file, "Forcing VARYING instead of changing "
    5430                 :             :                        "value number of ");
    5431                 :           0 :               print_generic_expr (dump_file, from);
    5432                 :           0 :               fprintf (dump_file, " from ");
    5433                 :           0 :               print_generic_expr (dump_file, currval);
    5434                 :           0 :               fprintf (dump_file, " (non-undefined) to ");
    5435                 :           0 :               print_generic_expr (dump_file, to);
    5436                 :           0 :               fprintf (dump_file, " (undefined)\n");
    5437                 :             :             }
    5438                 :             :           to = from;
    5439                 :             :         }
    5440                 :    32384371 :       else if (TREE_CODE (to) == SSA_NAME
    5441                 :    32384371 :                && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (to))
    5442                 :             :         to = from;
    5443                 :             :     }
    5444                 :             : 
    5445                 :   174626590 : set_and_exit:
    5446                 :   207011185 :   if (dump_file && (dump_flags & TDF_DETAILS))
    5447                 :             :     {
    5448                 :      370933 :       fprintf (dump_file, "Setting value number of ");
    5449                 :      370933 :       print_generic_expr (dump_file, from);
    5450                 :      370933 :       fprintf (dump_file, " to ");
    5451                 :      370933 :       print_generic_expr (dump_file, to);
    5452                 :             :     }
    5453                 :             : 
    5454                 :   207011185 :   if (currval != to
    5455                 :   169019071 :       && !operand_equal_p (currval, to, 0)
    5456                 :             :       /* Different undefined SSA names are not actually different.  See
    5457                 :             :          PR82320 for a testcase were we'd otherwise not terminate iteration.  */
    5458                 :   168951676 :       && !(curr_undefined
    5459                 :        4145 :            && TREE_CODE (to) == SSA_NAME
    5460                 :        1407 :            && !virtual_operand_p (to)
    5461                 :        1407 :            && ssa_undefined_value_p (to, false))
    5462                 :             :       /* ???  For addresses involving volatile objects or types operand_equal_p
    5463                 :             :          does not reliably detect ADDR_EXPRs as equal.  We know we are only
    5464                 :             :          getting invariant gimple addresses here, so can use
    5465                 :             :          get_addr_base_and_unit_offset to do this comparison.  */
    5466                 :   375961422 :       && !(TREE_CODE (currval) == ADDR_EXPR
    5467                 :      470866 :            && TREE_CODE (to) == ADDR_EXPR
    5468                 :          12 :            && (get_addr_base_and_unit_offset (TREE_OPERAND (currval, 0), &coff)
    5469                 :           6 :                == get_addr_base_and_unit_offset (TREE_OPERAND (to, 0), &toff))
    5470                 :           6 :            && known_eq (coff, toff)))
    5471                 :             :     {
    5472                 :   168950231 :       if (to != from
    5473                 :    28068897 :           && currval != VN_TOP
    5474                 :      997067 :           && !curr_undefined
    5475                 :             :           /* We do not want to allow lattice transitions from one value
    5476                 :             :              to another since that may lead to not terminating iteration
    5477                 :             :              (see PR95049).  Since there's no convenient way to check
    5478                 :             :              for the allowed transition of VAL -> PHI (loop entry value,
    5479                 :             :              same on two PHIs, to same PHI result) we restrict the check
    5480                 :             :              to invariants.  */
    5481                 :      997067 :           && curr_invariant
    5482                 :   169594043 :           && is_gimple_min_invariant (to))
    5483                 :             :         {
    5484                 :           0 :           if (dump_file && (dump_flags & TDF_DETAILS))
    5485                 :           0 :             fprintf (dump_file, " forced VARYING");
    5486                 :             :           to = from;
    5487                 :             :         }
    5488                 :   168950231 :       if (dump_file && (dump_flags & TDF_DETAILS))
    5489                 :      370615 :         fprintf (dump_file, " (changed)\n");
    5490                 :   168950231 :       from_info->valnum = to;
    5491                 :   168950231 :       return true;
    5492                 :             :     }
    5493                 :    38060954 :   if (dump_file && (dump_flags & TDF_DETAILS))
    5494                 :         318 :     fprintf (dump_file, "\n");
    5495                 :             :   return false;
    5496                 :             : }
    5497                 :             : 
    5498                 :             : /* Set all definitions in STMT to value number to themselves.
    5499                 :             :    Return true if a value number changed. */
    5500                 :             : 
    5501                 :             : static bool
    5502                 :   289749415 : defs_to_varying (gimple *stmt)
    5503                 :             : {
    5504                 :   289749415 :   bool changed = false;
    5505                 :   289749415 :   ssa_op_iter iter;
    5506                 :   289749415 :   def_operand_p defp;
    5507                 :             : 
    5508                 :   320449096 :   FOR_EACH_SSA_DEF_OPERAND (defp, stmt, iter, SSA_OP_ALL_DEFS)
    5509                 :             :     {
    5510                 :    30699681 :       tree def = DEF_FROM_PTR (defp);
    5511                 :    30699681 :       changed |= set_ssa_val_to (def, def);
    5512                 :             :     }
    5513                 :   289749415 :   return changed;
    5514                 :             : }
    5515                 :             : 
    5516                 :             : /* Visit a copy between LHS and RHS, return true if the value number
    5517                 :             :    changed.  */
    5518                 :             : 
    5519                 :             : static bool
    5520                 :     7910577 : visit_copy (tree lhs, tree rhs)
    5521                 :             : {
    5522                 :             :   /* Valueize.  */
    5523                 :     7910577 :   rhs = SSA_VAL (rhs);
    5524                 :             : 
    5525                 :     7910577 :   return set_ssa_val_to (lhs, rhs);
    5526                 :             : }
    5527                 :             : 
    5528                 :             : /* Lookup a value for OP in type WIDE_TYPE where the value in type of OP
    5529                 :             :    is the same.  */
    5530                 :             : 
    5531                 :             : static tree
    5532                 :     2410286 : valueized_wider_op (tree wide_type, tree op, bool allow_truncate)
    5533                 :             : {
    5534                 :     2410286 :   if (TREE_CODE (op) == SSA_NAME)
    5535                 :     2102469 :     op = vn_valueize (op);
    5536                 :             : 
    5537                 :             :   /* Either we have the op widened available.  */
    5538                 :     2410286 :   tree ops[3] = {};
    5539                 :     2410286 :   ops[0] = op;
    5540                 :     2410286 :   tree tem = vn_nary_op_lookup_pieces (1, NOP_EXPR,
    5541                 :             :                                        wide_type, ops, NULL);
    5542                 :     2410286 :   if (tem)
    5543                 :             :     return tem;
    5544                 :             : 
    5545                 :             :   /* Or the op is truncated from some existing value.  */
    5546                 :     2124502 :   if (allow_truncate && TREE_CODE (op) == SSA_NAME)
    5547                 :             :     {
    5548                 :      535035 :       gimple *def = SSA_NAME_DEF_STMT (op);
    5549                 :      535035 :       if (is_gimple_assign (def)
    5550                 :      535035 :           && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def)))
    5551                 :             :         {
    5552                 :      279135 :           tem = gimple_assign_rhs1 (def);
    5553                 :      279135 :           if (useless_type_conversion_p (wide_type, TREE_TYPE (tem)))
    5554                 :             :             {
    5555                 :      170529 :               if (TREE_CODE (tem) == SSA_NAME)
    5556                 :      170529 :                 tem = vn_valueize (tem);
    5557                 :      170529 :               return tem;
    5558                 :             :             }
    5559                 :             :         }
    5560                 :             :     }
    5561                 :             : 
    5562                 :             :   /* For constants simply extend it.  */
    5563                 :     1953973 :   if (TREE_CODE (op) == INTEGER_CST)
    5564                 :      339993 :     return wide_int_to_tree (wide_type, wi::to_widest (op));
    5565                 :             : 
    5566                 :             :   return NULL_TREE;
    5567                 :             : }
    5568                 :             : 
    5569                 :             : /* Visit a nary operator RHS, value number it, and return true if the
    5570                 :             :    value number of LHS has changed as a result.  */
    5571                 :             : 
    5572                 :             : static bool
    5573                 :    48289394 : visit_nary_op (tree lhs, gassign *stmt)
    5574                 :             : {
    5575                 :    48289394 :   vn_nary_op_t vnresult;
    5576                 :    48289394 :   tree result = vn_nary_op_lookup_stmt (stmt, &vnresult);
    5577                 :    48289394 :   if (! result && vnresult)
    5578                 :      153138 :     result = vn_nary_op_get_predicated_value (vnresult, gimple_bb (stmt));
    5579                 :    44731024 :   if (result)
    5580                 :     3629089 :     return set_ssa_val_to (lhs, result);
    5581                 :             : 
    5582                 :             :   /* Do some special pattern matching for redundancies of operations
    5583                 :             :      in different types.  */
    5584                 :    44660305 :   enum tree_code code = gimple_assign_rhs_code (stmt);
    5585                 :    44660305 :   tree type = TREE_TYPE (lhs);
    5586                 :    44660305 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    5587                 :    44660305 :   switch (code)
    5588                 :             :     {
    5589                 :    10029087 :     CASE_CONVERT:
    5590                 :             :       /* Match arithmetic done in a different type where we can easily
    5591                 :             :          substitute the result from some earlier sign-changed or widened
    5592                 :             :          operation.  */
    5593                 :    10029087 :       if (INTEGRAL_TYPE_P (type)
    5594                 :     8994836 :           && TREE_CODE (rhs1) == SSA_NAME
    5595                 :             :           /* We only handle sign-changes, zero-extension -> & mask or
    5596                 :             :              sign-extension if we know the inner operation doesn't
    5597                 :             :              overflow.  */
    5598                 :    18788906 :           && (((TYPE_UNSIGNED (TREE_TYPE (rhs1))
    5599                 :     5264600 :                 || (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    5600                 :     5263396 :                     && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (rhs1))))
    5601                 :     8031283 :                && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (rhs1)))
    5602                 :     5910040 :               || TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (rhs1))))
    5603                 :             :         {
    5604                 :     7636938 :           gassign *def = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (rhs1));
    5605                 :     5503929 :           if (def
    5606                 :     5503929 :               && (gimple_assign_rhs_code (def) == PLUS_EXPR
    5607                 :     4271608 :                   || gimple_assign_rhs_code (def) == MINUS_EXPR
    5608                 :     4137187 :                   || gimple_assign_rhs_code (def) == MULT_EXPR))
    5609                 :             :             {
    5610                 :     1944742 :               tree ops[3] = {};
    5611                 :             :               /* When requiring a sign-extension we cannot model a
    5612                 :             :                  previous truncation with a single op so don't bother.  */
    5613                 :     1944742 :               bool allow_truncate = TYPE_UNSIGNED (TREE_TYPE (rhs1));
    5614                 :             :               /* Either we have the op widened available.  */
    5615                 :     1944742 :               ops[0] = valueized_wider_op (type, gimple_assign_rhs1 (def),
    5616                 :             :                                            allow_truncate);
    5617                 :     1944742 :               if (ops[0])
    5618                 :      931088 :                 ops[1] = valueized_wider_op (type, gimple_assign_rhs2 (def),
    5619                 :             :                                              allow_truncate);
    5620                 :     1944742 :               if (ops[0] && ops[1])
    5621                 :             :                 {
    5622                 :      330762 :                   ops[0] = vn_nary_op_lookup_pieces
    5623                 :      330762 :                       (2, gimple_assign_rhs_code (def), type, ops, NULL);
    5624                 :             :                   /* We have wider operation available.  */
    5625                 :      330762 :                   if (ops[0]
    5626                 :             :                       /* If the leader is a wrapping operation we can
    5627                 :             :                          insert it for code hoisting w/o introducing
    5628                 :             :                          undefined overflow.  If it is not it has to
    5629                 :             :                          be available.  See PR86554.  */
    5630                 :      330762 :                       && (TYPE_OVERFLOW_WRAPS (TREE_TYPE (ops[0]))
    5631                 :        1915 :                           || (rpo_avail && vn_context_bb
    5632                 :        1915 :                               && rpo_avail->eliminate_avail (vn_context_bb,
    5633                 :             :                                                              ops[0]))))
    5634                 :             :                     {
    5635                 :        9015 :                       unsigned lhs_prec = TYPE_PRECISION (type);
    5636                 :        9015 :                       unsigned rhs_prec = TYPE_PRECISION (TREE_TYPE (rhs1));
    5637                 :        9015 :                       if (lhs_prec == rhs_prec
    5638                 :        9015 :                           || (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    5639                 :        1670 :                               && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (rhs1))))
    5640                 :             :                         {
    5641                 :        8422 :                           gimple_match_op match_op (gimple_match_cond::UNCOND,
    5642                 :        8422 :                                                     NOP_EXPR, type, ops[0]);
    5643                 :        8422 :                           result = vn_nary_build_or_lookup (&match_op);
    5644                 :        8422 :                           if (result)
    5645                 :             :                             {
    5646                 :        8422 :                               bool changed = set_ssa_val_to (lhs, result);
    5647                 :        8422 :                               if (TREE_CODE (result) == SSA_NAME)
    5648                 :        8422 :                                 vn_nary_op_insert_stmt (stmt, result);
    5649                 :        8422 :                               return changed;
    5650                 :             :                             }
    5651                 :             :                         }
    5652                 :             :                       else
    5653                 :             :                         {
    5654                 :         593 :                           tree mask = wide_int_to_tree
    5655                 :         593 :                             (type, wi::mask (rhs_prec, false, lhs_prec));
    5656                 :         593 :                           gimple_match_op match_op (gimple_match_cond::UNCOND,
    5657                 :         593 :                                                     BIT_AND_EXPR,
    5658                 :         593 :                                                     TREE_TYPE (lhs),
    5659                 :         593 :                                                     ops[0], mask);
    5660                 :         593 :                           result = vn_nary_build_or_lookup (&match_op);
    5661                 :         593 :                           if (result)
    5662                 :             :                             {
    5663                 :         593 :                               bool changed = set_ssa_val_to (lhs, result);
    5664                 :         593 :                               if (TREE_CODE (result) == SSA_NAME)
    5665                 :         593 :                                 vn_nary_op_insert_stmt (stmt, result);
    5666                 :         593 :                               return changed;
    5667                 :             :                             }
    5668                 :             :                         }
    5669                 :             :                     }
    5670                 :             :                 }
    5671                 :             :             }
    5672                 :             :         }
    5673                 :             :       break;
    5674                 :     1577388 :     case BIT_AND_EXPR:
    5675                 :     1577388 :       if (INTEGRAL_TYPE_P (type)
    5676                 :     1549491 :           && TREE_CODE (rhs1) == SSA_NAME
    5677                 :     1549491 :           && TREE_CODE (gimple_assign_rhs2 (stmt)) == INTEGER_CST
    5678                 :      975391 :           && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1)
    5679                 :      975273 :           && default_vn_walk_kind != VN_NOWALK
    5680                 :             :           && CHAR_BIT == 8
    5681                 :             :           && BITS_PER_UNIT == 8
    5682                 :             :           && BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN
    5683                 :      975065 :           && TYPE_PRECISION (type) <= vn_walk_cb_data::bufsize * BITS_PER_UNIT
    5684                 :      975063 :           && !integer_all_onesp (gimple_assign_rhs2 (stmt))
    5685                 :     2552451 :           && !integer_zerop (gimple_assign_rhs2 (stmt)))
    5686                 :             :         {
    5687                 :      975063 :           gassign *ass = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (rhs1));
    5688                 :      724699 :           if (ass
    5689                 :      724699 :               && !gimple_has_volatile_ops (ass)
    5690                 :      723253 :               && vn_get_stmt_kind (ass) == VN_REFERENCE)
    5691                 :             :             {
    5692                 :      364026 :               tree last_vuse = gimple_vuse (ass);
    5693                 :      364026 :               tree op = gimple_assign_rhs1 (ass);
    5694                 :     1092078 :               tree result = vn_reference_lookup (op, gimple_vuse (ass),
    5695                 :             :                                                  default_vn_walk_kind,
    5696                 :             :                                                  NULL, true, &last_vuse,
    5697                 :             :                                                  gimple_assign_rhs2 (stmt));
    5698                 :      364026 :               if (result
    5699                 :      364713 :                   && useless_type_conversion_p (TREE_TYPE (result),
    5700                 :         687 :                                                 TREE_TYPE (op)))
    5701                 :         687 :                 return set_ssa_val_to (lhs, result);
    5702                 :             :             }
    5703                 :             :         }
    5704                 :             :       break;
    5705                 :      212334 :     case BIT_FIELD_REF:
    5706                 :      212334 :       if (TREE_CODE (TREE_OPERAND (rhs1, 0)) == SSA_NAME)
    5707                 :             :         {
    5708                 :      212314 :           tree op0 = TREE_OPERAND (rhs1, 0);
    5709                 :      212314 :           gassign *ass = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (op0));
    5710                 :      172446 :           if (ass
    5711                 :      172446 :               && !gimple_has_volatile_ops (ass)
    5712                 :      172363 :               && vn_get_stmt_kind (ass) == VN_REFERENCE)
    5713                 :             :             {
    5714                 :       84037 :               tree last_vuse = gimple_vuse (ass);
    5715                 :       84037 :               tree op = gimple_assign_rhs1 (ass);
    5716                 :             :               /* Avoid building invalid and unexpected refs.  */
    5717                 :       84037 :               if (TREE_CODE (op) != TARGET_MEM_REF
    5718                 :             :                   && TREE_CODE (op) != BIT_FIELD_REF
    5719                 :             :                   && TREE_CODE (op) != REALPART_EXPR
    5720                 :             :                   && TREE_CODE (op) != IMAGPART_EXPR)
    5721                 :             :                 {
    5722                 :       76838 :                   tree op = build3 (BIT_FIELD_REF, TREE_TYPE (rhs1),
    5723                 :             :                                     gimple_assign_rhs1 (ass),
    5724                 :       76838 :                                     TREE_OPERAND (rhs1, 1),
    5725                 :       76838 :                                     TREE_OPERAND (rhs1, 2));
    5726                 :      153676 :                   tree result = vn_reference_lookup (op, gimple_vuse (ass),
    5727                 :             :                                                      default_vn_walk_kind,
    5728                 :             :                                                      NULL, true, &last_vuse);
    5729                 :       76838 :                   if (result
    5730                 :       76838 :                       && useless_type_conversion_p (type, TREE_TYPE (result)))
    5731                 :        1175 :                     return set_ssa_val_to (lhs, result);
    5732                 :       76078 :                   else if (result
    5733                 :         415 :                            && TYPE_SIZE (type)
    5734                 :         415 :                            && TYPE_SIZE (TREE_TYPE (result))
    5735                 :       76493 :                            && operand_equal_p (TYPE_SIZE (type),
    5736                 :         415 :                                                TYPE_SIZE (TREE_TYPE (result))))
    5737                 :             :                     {
    5738                 :         415 :                       gimple_match_op match_op (gimple_match_cond::UNCOND,
    5739                 :         415 :                                                 VIEW_CONVERT_EXPR,
    5740                 :         415 :                                                 type, result);
    5741                 :         415 :                       result = vn_nary_build_or_lookup (&match_op);
    5742                 :         415 :                       if (result)
    5743                 :             :                         {
    5744                 :         415 :                           bool changed = set_ssa_val_to (lhs, result);
    5745                 :         415 :                           if (TREE_CODE (result) == SSA_NAME)
    5746                 :         403 :                             vn_nary_op_insert_stmt (stmt, result);
    5747                 :         415 :                           return changed;
    5748                 :             :                         }
    5749                 :             :                     }
    5750                 :             :                 }
    5751                 :             :             }
    5752                 :             :         }
    5753                 :             :       break;
    5754                 :      335366 :     case TRUNC_DIV_EXPR:
    5755                 :      335366 :       if (TYPE_UNSIGNED (type))
    5756                 :             :         break;
    5757                 :             :       /* Fallthru.  */
    5758                 :     5299849 :     case RDIV_EXPR:
    5759                 :     5299849 :     case MULT_EXPR:
    5760                 :             :       /* Match up ([-]a){/,*}([-])b with v=a{/,*}b, replacing it with -v.  */
    5761                 :     5299849 :       if (! HONOR_SIGN_DEPENDENT_ROUNDING (type))
    5762                 :             :         {
    5763                 :     5298939 :           tree rhs[2];
    5764                 :     5298939 :           rhs[0] = rhs1;
    5765                 :     5298939 :           rhs[1] = gimple_assign_rhs2 (stmt);
    5766                 :    15889956 :           for (unsigned i = 0; i <= 1; ++i)
    5767                 :             :             {
    5768                 :    10596766 :               unsigned j = i == 0 ? 1 : 0;
    5769                 :    10596766 :               tree ops[2];
    5770                 :    10596766 :               gimple_match_op match_op (gimple_match_cond::UNCOND,
    5771                 :    10596766 :                                         NEGATE_EXPR, type, rhs[i]);
    5772                 :    10596766 :               ops[i] = vn_nary_build_or_lookup_1 (&match_op, false, true);
    5773                 :    10596766 :               ops[j] = rhs[j];
    5774                 :    10596766 :               if (ops[i]
    5775                 :    10596766 :                   && (ops[0] = vn_nary_op_lookup_pieces (2, code,
    5776                 :             :                                                          type, ops, NULL)))
    5777                 :             :                 {
    5778                 :        5749 :                   gimple_match_op match_op (gimple_match_cond::UNCOND,
    5779                 :        5749 :                                             NEGATE_EXPR, type, ops[0]);
    5780                 :        5749 :                   result = vn_nary_build_or_lookup_1 (&match_op, true, false);
    5781                 :        5749 :                   if (result)
    5782                 :             :                     {
    5783                 :        5749 :                       bool changed = set_ssa_val_to (lhs, result);
    5784                 :        5749 :                       if (TREE_CODE (result) == SSA_NAME)
    5785                 :        5749 :                         vn_nary_op_insert_stmt (stmt, result);
    5786                 :        5749 :                       return changed;
    5787                 :             :                     }
    5788                 :             :                 }
    5789                 :             :             }
    5790                 :             :         }
    5791                 :             :       break;
    5792                 :      351083 :     case LSHIFT_EXPR:
    5793                 :             :       /* For X << C, use the value number of X * (1 << C).  */
    5794                 :      351083 :       if (INTEGRAL_TYPE_P (type)
    5795                 :      343420 :           && TYPE_OVERFLOW_WRAPS (type)
    5796                 :      537282 :           && !TYPE_SATURATING (type))
    5797                 :             :         {
    5798                 :      186199 :           tree rhs2 = gimple_assign_rhs2 (stmt);
    5799                 :      186199 :           if (TREE_CODE (rhs2) == INTEGER_CST
    5800                 :      108132 :               && tree_fits_uhwi_p (rhs2)
    5801                 :      294331 :               && tree_to_uhwi (rhs2) < TYPE_PRECISION (type))
    5802                 :             :             {
    5803                 :      108132 :               wide_int w = wi::set_bit_in_zero (tree_to_uhwi (rhs2),
    5804                 :      108132 :                                                 TYPE_PRECISION (type));
    5805                 :      216264 :               gimple_match_op match_op (gimple_match_cond::UNCOND,
    5806                 :      108132 :                                         MULT_EXPR, type, rhs1,
    5807                 :      108132 :                                         wide_int_to_tree (type, w));
    5808                 :      108132 :               result = vn_nary_build_or_lookup (&match_op);
    5809                 :      108132 :               if (result)
    5810                 :             :                 {
    5811                 :      108132 :                   bool changed = set_ssa_val_to (lhs, result);
    5812                 :      108132 :                   if (TREE_CODE (result) == SSA_NAME)
    5813                 :      108131 :                     vn_nary_op_insert_stmt (stmt, result);
    5814                 :      108132 :                   return changed;
    5815                 :             :                 }
    5816                 :      108132 :             }
    5817                 :             :         }
    5818                 :             :       break;
    5819                 :             :     default:
    5820                 :             :       break;
    5821                 :             :     }
    5822                 :             : 
    5823                 :    44535547 :   bool changed = set_ssa_val_to (lhs, lhs);
    5824                 :    44535547 :   vn_nary_op_insert_stmt (stmt, lhs);
    5825                 :    44535547 :   return changed;
    5826                 :             : }
    5827                 :             : 
    5828                 :             : /* Visit a call STMT storing into LHS.  Return true if the value number
    5829                 :             :    of the LHS has changed as a result.  */
    5830                 :             : 
    5831                 :             : static bool
    5832                 :     8694956 : visit_reference_op_call (tree lhs, gcall *stmt)
    5833                 :             : {
    5834                 :     8694956 :   bool changed = false;
    5835                 :     8694956 :   struct vn_reference_s vr1;
    5836                 :     8694956 :   vn_reference_t vnresult = NULL;
    5837                 :     8694956 :   tree vdef = gimple_vdef (stmt);
    5838                 :     8694956 :   modref_summary *summary;
    5839                 :             : 
    5840                 :             :   /* Non-ssa lhs is handled in copy_reference_ops_from_call.  */
    5841                 :     8694956 :   if (lhs && TREE_CODE (lhs) != SSA_NAME)
    5842                 :     4678994 :     lhs = NULL_TREE;
    5843                 :             : 
    5844                 :     8694956 :   vn_reference_lookup_call (stmt, &vnresult, &vr1);
    5845                 :             : 
    5846                 :             :   /* If the lookup did not succeed for pure functions try to use
    5847                 :             :      modref info to find a candidate to CSE to.  */
    5848                 :     8694956 :   const unsigned accesses_limit = 8;
    5849                 :     8694956 :   if (!vnresult
    5850                 :     8020706 :       && !vdef
    5851                 :     8020706 :       && lhs
    5852                 :     2776246 :       && gimple_vuse (stmt)
    5853                 :    10252859 :       && (((summary = get_modref_function_summary (stmt, NULL))
    5854                 :      215290 :            && !summary->global_memory_read
    5855                 :       80161 :            && summary->load_accesses < accesses_limit)
    5856                 :     1477880 :           || gimple_call_flags (stmt) & ECF_CONST))
    5857                 :             :     {
    5858                 :             :       /* First search if we can do someting useful and build a
    5859                 :             :          vector of all loads we have to check.  */
    5860                 :       80766 :       bool unknown_memory_access = false;
    5861                 :       80766 :       auto_vec<ao_ref, accesses_limit> accesses;
    5862                 :       80766 :       unsigned load_accesses = summary ? summary->load_accesses : 0;
    5863                 :       80766 :       if (!unknown_memory_access)
    5864                 :             :         /* Add loads done as part of setting up the call arguments.
    5865                 :             :            That's also necessary for CONST functions which will
    5866                 :             :            not have a modref summary.  */
    5867                 :      230088 :         for (unsigned i = 0; i < gimple_call_num_args (stmt); ++i)
    5868                 :             :           {
    5869                 :      149330 :             tree arg = gimple_call_arg (stmt, i);
    5870                 :      149330 :             if (TREE_CODE (arg) != SSA_NAME
    5871                 :      149330 :                 && !is_gimple_min_invariant (arg))
    5872                 :             :               {
    5873                 :       49038 :                 if (accesses.length () >= accesses_limit - load_accesses)
    5874                 :             :                   {
    5875                 :             :                     unknown_memory_access = true;
    5876                 :             :                     break;
    5877                 :             :                   }
    5878                 :       24511 :                 accesses.quick_grow (accesses.length () + 1);
    5879                 :       24511 :                 ao_ref_init (&accesses.last (), arg);
    5880                 :             :               }
    5881                 :             :           }
    5882                 :       80766 :       if (summary && !unknown_memory_access)
    5883                 :             :         {
    5884                 :             :           /* Add loads as analyzed by IPA modref.  */
    5885                 :      268871 :           for (auto base_node : summary->loads->bases)
    5886                 :       66691 :             if (unknown_memory_access)
    5887                 :             :               break;
    5888                 :      272428 :             else for (auto ref_node : base_node->refs)
    5889                 :       73063 :               if (unknown_memory_access)
    5890                 :             :                 break;
    5891                 :      298845 :               else for (auto access_node : ref_node->accesses)
    5892                 :             :                 {
    5893                 :      196376 :                   accesses.quick_grow (accesses.length () + 1);
    5894                 :       98188 :                   ao_ref *r = &accesses.last ();
    5895                 :       98188 :                   if (!access_node.get_ao_ref (stmt, r))
    5896                 :             :                     {
    5897                 :             :                       /* Initialize a ref based on the argument and
    5898                 :             :                          unknown offset if possible.  */
    5899                 :       18496 :                       tree arg = access_node.get_call_arg (stmt);
    5900                 :       18496 :                       if (arg && TREE_CODE (arg) == SSA_NAME)
    5901                 :        5440 :                         arg = SSA_VAL (arg);
    5902                 :        5440 :                       if (arg
    5903                 :       18486 :                           && TREE_CODE (arg) == ADDR_EXPR
    5904                 :       13163 :                           && (arg = get_base_address (arg))
    5905                 :       18603 :                           && DECL_P (arg))
    5906                 :             :                         {
    5907                 :           0 :                           ao_ref_init (r, arg);
    5908                 :           0 :                           r->ref = NULL_TREE;
    5909                 :           0 :                           r->base = arg;
    5910                 :             :                         }
    5911                 :             :                       else
    5912                 :             :                         {
    5913                 :             :                           unknown_memory_access = true;
    5914                 :             :                           break;
    5915                 :             :                         }
    5916                 :             :                     }
    5917                 :       79692 :                   r->base_alias_set = base_node->base;
    5918                 :       79692 :                   r->ref_alias_set = ref_node->ref;
    5919                 :             :                 }
    5920                 :             :         }
    5921                 :             : 
    5922                 :             :       /* Walk the VUSE->VDEF chain optimistically trying to find an entry
    5923                 :             :          for the call in the hashtable.  */
    5924                 :       80766 :       unsigned limit = (unknown_memory_access
    5925                 :       80766 :                         ? 0
    5926                 :       62262 :                         : (param_sccvn_max_alias_queries_per_access
    5927                 :       62262 :                            / (accesses.length () + 1)));
    5928                 :       80766 :       tree saved_vuse = vr1.vuse;
    5929                 :       80766 :       hashval_t saved_hashcode = vr1.hashcode;
    5930                 :      335149 :       while (limit > 0 && !vnresult && !SSA_NAME_IS_DEFAULT_DEF (vr1.vuse))
    5931                 :             :         {
    5932                 :      270456 :           vr1.hashcode = vr1.hashcode - SSA_NAME_VERSION (vr1.vuse);
    5933                 :      270456 :           gimple *def = SSA_NAME_DEF_STMT (vr1.vuse);
    5934                 :             :           /* ???  We could use fancy stuff like in walk_non_aliased_vuses, but
    5935                 :             :              do not bother for now.  */
    5936                 :      270456 :           if (is_a <gphi *> (def))
    5937                 :             :             break;
    5938                 :      508766 :           vr1.vuse = vuse_ssa_val (gimple_vuse (def));
    5939                 :      254383 :           vr1.hashcode = vr1.hashcode + SSA_NAME_VERSION (vr1.vuse);
    5940                 :      254383 :           vn_reference_lookup_1 (&vr1, &vnresult);
    5941                 :      254383 :           limit--;
    5942                 :             :         }
    5943                 :             : 
    5944                 :             :       /* If we found a candidate to CSE to verify it is valid.  */
    5945                 :       80766 :       if (vnresult && !accesses.is_empty ())
    5946                 :             :         {
    5947                 :        1774 :           tree vuse = vuse_ssa_val (gimple_vuse (stmt));
    5948                 :        6711 :           while (vnresult && vuse != vr1.vuse)
    5949                 :             :             {
    5950                 :        3163 :               gimple *def = SSA_NAME_DEF_STMT (vuse);
    5951                 :       16818 :               for (auto &ref : accesses)
    5952                 :             :                 {
    5953                 :             :                   /* ???  stmt_may_clobber_ref_p_1 does per stmt constant
    5954                 :             :                      analysis overhead that we might be able to cache.  */
    5955                 :        8937 :                   if (stmt_may_clobber_ref_p_1 (def, &ref, true))
    5956                 :             :                     {
    5957                 :        1608 :                       vnresult = NULL;
    5958                 :        1608 :                       break;
    5959                 :             :                     }
    5960                 :             :                 }
    5961                 :        6326 :               vuse = vuse_ssa_val (gimple_vuse (def));
    5962                 :             :             }
    5963                 :             :         }
    5964                 :       80766 :       vr1.vuse = saved_vuse;
    5965                 :       80766 :       vr1.hashcode = saved_hashcode;
    5966                 :       80766 :     }
    5967                 :             : 
    5968                 :     8694956 :   if (vnresult)
    5969                 :             :     {
    5970                 :      674440 :       if (vdef)
    5971                 :             :         {
    5972                 :      175416 :           if (vnresult->result_vdef)
    5973                 :      175416 :             changed |= set_ssa_val_to (vdef, vnresult->result_vdef);
    5974                 :           0 :           else if (!lhs && gimple_call_lhs (stmt))
    5975                 :             :             /* If stmt has non-SSA_NAME lhs, value number the vdef to itself,
    5976                 :             :                as the call still acts as a lhs store.  */
    5977                 :           0 :             changed |= set_ssa_val_to (vdef, vdef);
    5978                 :             :           else
    5979                 :             :             /* If the call was discovered to be pure or const reflect
    5980                 :             :                that as far as possible.  */
    5981                 :           0 :             changed |= set_ssa_val_to (vdef,
    5982                 :             :                                        vuse_ssa_val (gimple_vuse (stmt)));
    5983                 :             :         }
    5984                 :             : 
    5985                 :      674440 :       if (!vnresult->result && lhs)
    5986                 :           0 :         vnresult->result = lhs;
    5987                 :             : 
    5988                 :      674440 :       if (vnresult->result && lhs)
    5989                 :       98708 :         changed |= set_ssa_val_to (lhs, vnresult->result);
    5990                 :             :     }
    5991                 :             :   else
    5992                 :             :     {
    5993                 :     8020516 :       vn_reference_t vr2;
    5994                 :     8020516 :       vn_reference_s **slot;
    5995                 :     8020516 :       tree vdef_val = vdef;
    5996                 :     8020516 :       if (vdef)
    5997                 :             :         {
    5998                 :             :           /* If we value numbered an indirect functions function to
    5999                 :             :              one not clobbering memory value number its VDEF to its
    6000                 :             :              VUSE.  */
    6001                 :     4913323 :           tree fn = gimple_call_fn (stmt);
    6002                 :     4913323 :           if (fn && TREE_CODE (fn) == SSA_NAME)
    6003                 :             :             {
    6004                 :      129264 :               fn = SSA_VAL (fn);
    6005                 :      129264 :               if (TREE_CODE (fn) == ADDR_EXPR
    6006                 :        1752 :                   && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
    6007                 :        1752 :                   && (flags_from_decl_or_type (TREE_OPERAND (fn, 0))
    6008                 :        1752 :                       & (ECF_CONST | ECF_PURE))
    6009                 :             :                   /* If stmt has non-SSA_NAME lhs, value number the
    6010                 :             :                      vdef to itself, as the call still acts as a lhs
    6011                 :             :                      store.  */
    6012                 :      130425 :                   && (lhs || gimple_call_lhs (stmt) == NULL_TREE))
    6013                 :        2188 :                 vdef_val = vuse_ssa_val (gimple_vuse (stmt));
    6014                 :             :             }
    6015                 :     4913323 :           changed |= set_ssa_val_to (vdef, vdef_val);
    6016                 :             :         }
    6017                 :     8020516 :       if (lhs)
    6018                 :     3917254 :         changed |= set_ssa_val_to (lhs, lhs);
    6019                 :     8020516 :       vr2 = XOBNEW (&vn_tables_obstack, vn_reference_s);
    6020                 :     8020516 :       vr2->vuse = vr1.vuse;
    6021                 :             :       /* As we are not walking the virtual operand chain we know the
    6022                 :             :          shared_lookup_references are still original so we can re-use
    6023                 :             :          them here.  */
    6024                 :     8020516 :       vr2->operands = vr1.operands.copy ();
    6025                 :     8020516 :       vr2->type = vr1.type;
    6026                 :     8020516 :       vr2->punned = vr1.punned;
    6027                 :     8020516 :       vr2->set = vr1.set;
    6028                 :     8020516 :       vr2->offset = vr1.offset;
    6029                 :     8020516 :       vr2->max_size = vr1.max_size;
    6030                 :     8020516 :       vr2->base_set = vr1.base_set;
    6031                 :     8020516 :       vr2->hashcode = vr1.hashcode;
    6032                 :     8020516 :       vr2->result = lhs;
    6033                 :     8020516 :       vr2->result_vdef = vdef_val;
    6034                 :     8020516 :       vr2->value_id = 0;
    6035                 :     8020516 :       slot = valid_info->references->find_slot_with_hash (vr2, vr2->hashcode,
    6036                 :             :                                                           INSERT);
    6037                 :     8020516 :       gcc_assert (!*slot);
    6038                 :     8020516 :       *slot = vr2;
    6039                 :     8020516 :       vr2->next = last_inserted_ref;
    6040                 :     8020516 :       last_inserted_ref = vr2;
    6041                 :             :     }
    6042                 :             : 
    6043                 :     8694956 :   return changed;
    6044                 :             : }
    6045                 :             : 
    6046                 :             : /* Visit a load from a reference operator RHS, part of STMT, value number it,
    6047                 :             :    and return true if the value number of the LHS has changed as a result.  */
    6048                 :             : 
    6049                 :             : static bool
    6050                 :    35040501 : visit_reference_op_load (tree lhs, tree op, gimple *stmt)
    6051                 :             : {
    6052                 :    35040501 :   bool changed = false;
    6053                 :    35040501 :   tree result;
    6054                 :    35040501 :   vn_reference_t res;
    6055                 :             : 
    6056                 :    35040501 :   tree vuse = gimple_vuse (stmt);
    6057                 :    35040501 :   tree last_vuse = vuse;
    6058                 :    35040501 :   result = vn_reference_lookup (op, vuse, default_vn_walk_kind, &res, true, &last_vuse);
    6059                 :             : 
    6060                 :             :   /* We handle type-punning through unions by value-numbering based
    6061                 :             :      on offset and size of the access.  Be prepared to handle a
    6062                 :             :      type-mismatch here via creating a VIEW_CONVERT_EXPR.  */
    6063                 :    35040501 :   if (result
    6064                 :    35040501 :       && !useless_type_conversion_p (TREE_TYPE (result), TREE_TYPE (op)))
    6065                 :             :     {
    6066                 :       20311 :       if (CONSTANT_CLASS_P (result))
    6067                 :        3873 :         result = const_unop (VIEW_CONVERT_EXPR, TREE_TYPE (op), result);
    6068                 :             :       else
    6069                 :             :         {
    6070                 :             :           /* We will be setting the value number of lhs to the value number
    6071                 :             :              of VIEW_CONVERT_EXPR <TREE_TYPE (result)> (result).
    6072                 :             :              So first simplify and lookup this expression to see if it
    6073                 :             :              is already available.  */
    6074                 :       16438 :           gimple_match_op res_op (gimple_match_cond::UNCOND,
    6075                 :       16438 :                                   VIEW_CONVERT_EXPR, TREE_TYPE (op), result);
    6076                 :       16438 :           result = vn_nary_build_or_lookup (&res_op);
    6077                 :       16438 :           if (result
    6078                 :       16438 :               && TREE_CODE (result) == SSA_NAME
    6079                 :       31203 :               && VN_INFO (result)->needs_insertion)
    6080                 :             :             /* Track whether this is the canonical expression for different
    6081                 :             :                typed loads.  We use that as a stopgap measure for code
    6082                 :             :                hoisting when dealing with floating point loads.  */
    6083                 :       13934 :             res->punned = true;
    6084                 :             :         }
    6085                 :             : 
    6086                 :             :       /* When building the conversion fails avoid inserting the reference
    6087                 :             :          again.  */
    6088                 :       20311 :       if (!result)
    6089                 :           0 :         return set_ssa_val_to (lhs, lhs);
    6090                 :             :     }
    6091                 :             : 
    6092                 :    35020190 :   if (result)
    6093                 :     5472443 :     changed = set_ssa_val_to (lhs, result);
    6094                 :             :   else
    6095                 :             :     {
    6096                 :    29568058 :       changed = set_ssa_val_to (lhs, lhs);
    6097                 :    29568058 :       vn_reference_insert (op, lhs, last_vuse, NULL_TREE);
    6098                 :    29568058 :       if (vuse && SSA_VAL (last_vuse) != SSA_VAL (vuse))
    6099                 :             :         {
    6100                 :     9042671 :           if (dump_file && (dump_flags & TDF_DETAILS))
    6101                 :             :             {
    6102                 :       14250 :               fprintf (dump_file, "Using extra use virtual operand ");
    6103                 :       14250 :               print_generic_expr (dump_file, last_vuse);
    6104                 :       14250 :               fprintf (dump_file, "\n");
    6105                 :             :             }
    6106                 :     9042671 :           vn_reference_insert (op, lhs, vuse, NULL_TREE);
    6107                 :             :         }
    6108                 :             :     }
    6109                 :             : 
    6110                 :             :   return changed;
    6111                 :             : }
    6112                 :             : 
    6113                 :             : 
    6114                 :             : /* Visit a store to a reference operator LHS, part of STMT, value number it,
    6115                 :             :    and return true if the value number of the LHS has changed as a result.  */
    6116                 :             : 
    6117                 :             : static bool
    6118                 :    33143737 : visit_reference_op_store (tree lhs, tree op, gimple *stmt)
    6119                 :             : {
    6120                 :    33143737 :   bool changed = false;
    6121                 :    33143737 :   vn_reference_t vnresult = NULL;
    6122                 :    33143737 :   tree assign;
    6123                 :    33143737 :   bool resultsame = false;
    6124                 :    33143737 :   tree vuse = gimple_vuse (stmt);
    6125                 :    33143737 :   tree vdef = gimple_vdef (stmt);
    6126                 :             : 
    6127                 :    33143737 :   if (TREE_CODE (op) == SSA_NAME)
    6128                 :    15013666 :     op = SSA_VAL (op);
    6129                 :             : 
    6130                 :             :   /* First we want to lookup using the *vuses* from the store and see
    6131                 :             :      if there the last store to this location with the same address
    6132                 :             :      had the same value.
    6133                 :             : 
    6134                 :             :      The vuses represent the memory state before the store.  If the
    6135                 :             :      memory state, address, and value of the store is the same as the
    6136                 :             :      last store to this location, then this store will produce the
    6137                 :             :      same memory state as that store.
    6138                 :             : 
    6139                 :             :      In this case the vdef versions for this store are value numbered to those
    6140                 :             :      vuse versions, since they represent the same memory state after
    6141                 :             :      this store.
    6142                 :             : 
    6143                 :             :      Otherwise, the vdefs for the store are used when inserting into
    6144                 :             :      the table, since the store generates a new memory state.  */
    6145                 :             : 
    6146                 :    33143737 :   vn_reference_lookup (lhs, vuse, VN_NOWALK, &vnresult, false);
    6147                 :    33143737 :   if (vnresult
    6148                 :     1705697 :       && vnresult->result)
    6149                 :             :     {
    6150                 :     1705697 :       tree result = vnresult->result;
    6151                 :     1705697 :       gcc_checking_assert (TREE_CODE (result) != SSA_NAME
    6152                 :             :                            || result == SSA_VAL (result));
    6153                 :     1705697 :       resultsame = expressions_equal_p (result, op);
    6154                 :     1705697 :       if (resultsame)
    6155                 :             :         {
    6156                 :             :           /* If the TBAA state isn't compatible for downstream reads
    6157                 :             :              we cannot value-number the VDEFs the same.  */
    6158                 :       52323 :           ao_ref lhs_ref;
    6159                 :       52323 :           ao_ref_init (&lhs_ref, lhs);
    6160                 :       52323 :           alias_set_type set = ao_ref_alias_set (&lhs_ref);
    6161                 :       52323 :           alias_set_type base_set = ao_ref_base_alias_set (&lhs_ref);
    6162                 :       52323 :           if ((vnresult->set != set
    6163                 :         742 :                && ! alias_set_subset_of (set, vnresult->set))
    6164                 :       52842 :               || (vnresult->base_set != base_set
    6165                 :        6300 :                   && ! alias_set_subset_of (base_set, vnresult->base_set)))
    6166                 :         781 :             resultsame = false;
    6167                 :             :         }
    6168                 :             :     }
    6169                 :             : 
    6170                 :         781 :   if (!resultsame)
    6171                 :             :     {
    6172                 :    33092195 :       if (dump_file && (dump_flags & TDF_DETAILS))
    6173                 :             :         {
    6174                 :       19173 :           fprintf (dump_file, "No store match\n");
    6175                 :       19173 :           fprintf (dump_file, "Value numbering store ");
    6176                 :       19173 :           print_generic_expr (dump_file, lhs);
    6177                 :       19173 :           fprintf (dump_file, " to ");
    6178                 :       19173 :           print_generic_expr (dump_file, op);
    6179                 :       19173 :           fprintf (dump_file, "\n");
    6180                 :             :         }
    6181                 :             :       /* Have to set value numbers before insert, since insert is
    6182                 :             :          going to valueize the references in-place.  */
    6183                 :    33092195 :       if (vdef)
    6184                 :    33092195 :         changed |= set_ssa_val_to (vdef, vdef);
    6185                 :             : 
    6186                 :             :       /* Do not insert structure copies into the tables.  */
    6187                 :    33092195 :       if (is_gimple_min_invariant (op)
    6188                 :    33092195 :           || is_gimple_reg (op))
    6189                 :    29434650 :         vn_reference_insert (lhs, op, vdef, NULL);
    6190                 :             : 
    6191                 :             :       /* Only perform the following when being called from PRE
    6192                 :             :          which embeds tail merging.  */
    6193                 :    33092195 :       if (default_vn_walk_kind == VN_WALK)
    6194                 :             :         {
    6195                 :     7573599 :           assign = build2 (MODIFY_EXPR, TREE_TYPE (lhs), lhs, op);
    6196                 :     7573599 :           vn_reference_lookup (assign, vuse, VN_NOWALK, &vnresult, false);
    6197                 :     7573599 :           if (!vnresult)
    6198                 :     7526023 :             vn_reference_insert (assign, lhs, vuse, vdef);
    6199                 :             :         }
    6200                 :             :     }
    6201                 :             :   else
    6202                 :             :     {
    6203                 :             :       /* We had a match, so value number the vdef to have the value
    6204                 :             :          number of the vuse it came from.  */
    6205                 :             : 
    6206                 :       51542 :       if (dump_file && (dump_flags & TDF_DETAILS))
    6207                 :           9 :         fprintf (dump_file, "Store matched earlier value, "
    6208                 :             :                  "value numbering store vdefs to matching vuses.\n");
    6209                 :             : 
    6210                 :       51542 :       changed |= set_ssa_val_to (vdef, SSA_VAL (vuse));
    6211                 :             :     }
    6212                 :             : 
    6213                 :    33143737 :   return changed;
    6214                 :             : }
    6215                 :             : 
    6216                 :             : /* Visit and value number PHI, return true if the value number
    6217                 :             :    changed.  When BACKEDGES_VARYING_P is true then assume all
    6218                 :             :    backedge values are varying.  When INSERTED is not NULL then
    6219                 :             :    this is just a ahead query for a possible iteration, set INSERTED
    6220                 :             :    to true if we'd insert into the hashtable.  */
    6221                 :             : 
    6222                 :             : static bool
    6223                 :    35431550 : visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
    6224                 :             : {
    6225                 :    35431550 :   tree result, sameval = VN_TOP, seen_undef = NULL_TREE;
    6226                 :    35431550 :   bool seen_undef_visited = false;
    6227                 :    35431550 :   tree backedge_val = NULL_TREE;
    6228                 :    35431550 :   bool seen_non_backedge = false;
    6229                 :    35431550 :   tree sameval_base = NULL_TREE;
    6230                 :    35431550 :   poly_int64 soff, doff;
    6231                 :    35431550 :   unsigned n_executable = 0;
    6232                 :    35431550 :   edge sameval_e = NULL;
    6233                 :             : 
    6234                 :             :   /* TODO: We could check for this in initialization, and replace this
    6235                 :             :      with a gcc_assert.  */
    6236                 :    35431550 :   if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (PHI_RESULT (phi)))
    6237                 :       29164 :     return set_ssa_val_to (PHI_RESULT (phi), PHI_RESULT (phi));
    6238                 :             : 
    6239                 :             :   /* We track whether a PHI was CSEd to avoid excessive iterations
    6240                 :             :      that would be necessary only because the PHI changed arguments
    6241                 :             :      but not value.  */
    6242                 :    35402386 :   if (!inserted)
    6243                 :    27811666 :     gimple_set_plf (phi, GF_PLF_1, false);
    6244                 :             : 
    6245                 :    35402386 :   basic_block bb = gimple_bb (phi);
    6246                 :             : 
    6247                 :             :   /* For the equivalence handling below make sure to first process an
    6248                 :             :      edge with a non-constant.  */
    6249                 :    35402386 :   auto_vec<edge, 2> preds;
    6250                 :    70804772 :   preds.reserve_exact (EDGE_COUNT (bb->preds));
    6251                 :    35402386 :   bool seen_nonconstant = false;
    6252                 :   115363771 :   for (unsigned i = 0; i < EDGE_COUNT (bb->preds); ++i)
    6253                 :             :     {
    6254                 :    79961385 :       edge e = EDGE_PRED (bb, i);
    6255                 :    79961385 :       preds.quick_push (e);
    6256                 :    79961385 :       if (!seen_nonconstant)
    6257                 :             :         {
    6258                 :    42924221 :           tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
    6259                 :    42924221 :           if (TREE_CODE (def) == SSA_NAME)
    6260                 :             :             {
    6261                 :    33584687 :               seen_nonconstant = true;
    6262                 :    33584687 :               if (i != 0)
    6263                 :     5662763 :                 std::swap (preds[0], preds[i]);
    6264                 :             :             }
    6265                 :             :         }
    6266                 :             :     }
    6267                 :             : 
    6268                 :             :   /* See if all non-TOP arguments have the same value.  TOP is
    6269                 :             :      equivalent to everything, so we can ignore it.  */
    6270                 :   148783565 :   for (edge e : preds)
    6271                 :    70099824 :     if (e->flags & EDGE_EXECUTABLE)
    6272                 :             :       {
    6273                 :    65084647 :         tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
    6274                 :             : 
    6275                 :    65084647 :         if (def == PHI_RESULT (phi))
    6276                 :      330341 :           continue;
    6277                 :    64774391 :         ++n_executable;
    6278                 :    64774391 :         bool visited = true;
    6279                 :    64774391 :         if (TREE_CODE (def) == SSA_NAME)
    6280                 :             :           {
    6281                 :    52536846 :             tree val = SSA_VAL (def, &visited);
    6282                 :    52536846 :             if (SSA_NAME_IS_DEFAULT_DEF (def))
    6283                 :     2669722 :               visited = true;
    6284                 :    52536846 :             if (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK))
    6285                 :    50012290 :               def = val;
    6286                 :    52536846 :             if (e->flags & EDGE_DFS_BACK)
    6287                 :    15437986 :               backedge_val = def;
    6288                 :             :           }
    6289                 :    64774391 :         if (!(e->flags & EDGE_DFS_BACK))
    6290                 :    49149489 :           seen_non_backedge = true;
    6291                 :    64774391 :         if (def == VN_TOP)
    6292                 :             :           ;
    6293                 :             :         /* Ignore undefined defs for sameval but record one.  */
    6294                 :    64774391 :         else if (TREE_CODE (def) == SSA_NAME
    6295                 :    49112424 :                  && ! virtual_operand_p (def)
    6296                 :    89631797 :                  && ssa_undefined_value_p (def, false))
    6297                 :             :           {
    6298                 :      232575 :             if (!seen_undef
    6299                 :             :                 /* Avoid having not visited undefined defs if we also have
    6300                 :             :                    a visited one.  */
    6301                 :       26171 :                 || (!seen_undef_visited && visited))
    6302                 :             :               {
    6303                 :      206407 :                 seen_undef = def;
    6304                 :      206407 :                 seen_undef_visited = visited;
    6305                 :             :               }
    6306                 :             :           }
    6307                 :    64541816 :         else if (sameval == VN_TOP)
    6308                 :             :           {
    6309                 :             :             sameval = def;
    6310                 :             :             sameval_e = e;
    6311                 :             :           }
    6312                 :    29193685 :         else if (expressions_equal_p (def, sameval))
    6313                 :             :           sameval_e = NULL;
    6314                 :    46220322 :         else if (virtual_operand_p (def))
    6315                 :             :           {
    6316                 :             :             sameval = NULL_TREE;
    6317                 :    27523417 :             break;
    6318                 :             :           }
    6319                 :             :         else
    6320                 :             :           {
    6321                 :             :             /* We know we're arriving only with invariant addresses here,
    6322                 :             :                try harder comparing them.  We can do some caching here
    6323                 :             :                which we cannot do in expressions_equal_p.  */
    6324                 :    17035316 :             if (TREE_CODE (def) == ADDR_EXPR
    6325                 :      428522 :                 && TREE_CODE (sameval) == ADDR_EXPR
    6326                 :      119091 :                 && sameval_base != (void *)-1)
    6327                 :             :               {
    6328                 :      119091 :                 if (!sameval_base)
    6329                 :      119089 :                   sameval_base = get_addr_base_and_unit_offset
    6330                 :      119089 :                                    (TREE_OPERAND (sameval, 0), &soff);
    6331                 :      119089 :                 if (!sameval_base)
    6332                 :             :                   sameval_base = (tree)(void *)-1;
    6333                 :      119096 :                 else if ((get_addr_base_and_unit_offset
    6334                 :      119091 :                             (TREE_OPERAND (def, 0), &doff) == sameval_base)
    6335                 :      119091 :                          && known_eq (soff, doff))
    6336                 :           5 :                   continue;
    6337                 :             :               }
    6338                 :             :             /* There's also the possibility to use equivalences.  */
    6339                 :    32961544 :             if (!FLOAT_TYPE_P (TREE_TYPE (def))
    6340                 :             :                 /* But only do this if we didn't force any of sameval or
    6341                 :             :                    val to VARYING because of backedge processing rules.  */
    6342                 :    15818156 :                 && (TREE_CODE (sameval) != SSA_NAME
    6343                 :    12498714 :                     || SSA_VAL (sameval) == sameval)
    6344                 :    32853152 :                 && (TREE_CODE (def) != SSA_NAME || SSA_VAL (def) == def))
    6345                 :             :               {
    6346                 :    15817828 :                 vn_nary_op_t vnresult;
    6347                 :    15817828 :                 tree ops[2];
    6348                 :    15817828 :                 ops[0] = def;
    6349                 :    15817828 :                 ops[1] = sameval;
    6350                 :             :                 /* Canonicalize the operands order for eq below. */
    6351                 :    15817828 :                 if (tree_swap_operands_p (ops[0], ops[1]))
    6352                 :     9465307 :                   std::swap (ops[0], ops[1]);
    6353                 :    15817828 :                 tree val = vn_nary_op_lookup_pieces (2, EQ_EXPR,
    6354                 :             :                                                      boolean_type_node,
    6355                 :             :                                                      ops, &vnresult);
    6356                 :    15817828 :                 if (! val && vnresult && vnresult->predicated_values)
    6357                 :             :                   {
    6358                 :      205840 :                     val = vn_nary_op_get_predicated_value (vnresult, e);
    6359                 :      114646 :                     if (val && integer_truep (val)
    6360                 :      226024 :                         && !(sameval_e && (sameval_e->flags & EDGE_DFS_BACK)))
    6361                 :             :                       {
    6362                 :       20080 :                         if (dump_file && (dump_flags & TDF_DETAILS))
    6363                 :             :                           {
    6364                 :           2 :                             fprintf (dump_file, "Predication says ");
    6365                 :           2 :                             print_generic_expr (dump_file, def, TDF_NONE);
    6366                 :           2 :                             fprintf (dump_file, " and ");
    6367                 :           2 :                             print_generic_expr (dump_file, sameval, TDF_NONE);
    6368                 :           2 :                             fprintf (dump_file, " are equal on edge %d -> %d\n",
    6369                 :           2 :                                      e->src->index, e->dest->index);
    6370                 :             :                           }
    6371                 :       20080 :                         continue;
    6372                 :             :                       }
    6373                 :             :                   }
    6374                 :             :               }
    6375                 :             :             sameval = NULL_TREE;
    6376                 :             :             break;
    6377                 :             :           }
    6378                 :             :       }
    6379                 :             : 
    6380                 :             :   /* If the value we want to use is flowing over the backedge and we
    6381                 :             :      should take it as VARYING but it has a non-VARYING value drop to
    6382                 :             :      VARYING.
    6383                 :             :      If we value-number a virtual operand never value-number to the
    6384                 :             :      value from the backedge as that confuses the alias-walking code.
    6385                 :             :      See gcc.dg/torture/pr87176.c.  If the value is the same on a
    6386                 :             :      non-backedge everything is OK though.  */
    6387                 :    35402386 :   bool visited_p;
    6388                 :    35402386 :   if ((backedge_val
    6389                 :    35402386 :        && !seen_non_backedge
    6390                 :        2258 :        && TREE_CODE (backedge_val) == SSA_NAME
    6391                 :        1991 :        && sameval == backedge_val
    6392                 :         356 :        && (SSA_NAME_IS_VIRTUAL_OPERAND (backedge_val)
    6393                 :          57 :            || SSA_VAL (backedge_val) != backedge_val))
    6394                 :             :       /* Do not value-number a virtual operand to sth not visited though
    6395                 :             :          given that allows us to escape a region in alias walking.  */
    6396                 :    35404344 :       || (sameval
    6397                 :     7878669 :           && TREE_CODE (sameval) == SSA_NAME
    6398                 :     4730165 :           && !SSA_NAME_IS_DEFAULT_DEF (sameval)
    6399                 :     4009137 :           && SSA_NAME_IS_VIRTUAL_OPERAND (sameval)
    6400                 :     2008433 :           && (SSA_VAL (sameval, &visited_p), !visited_p)))
    6401                 :             :     /* Note this just drops to VARYING without inserting the PHI into
    6402                 :             :        the hashes.  */
    6403                 :      288035 :     result = PHI_RESULT (phi);
    6404                 :             :   /* If none of the edges was executable keep the value-number at VN_TOP,
    6405                 :             :      if only a single edge is exectuable use its value.  */
    6406                 :    35114351 :   else if (n_executable <= 1)
    6407                 :     6769494 :     result = seen_undef ? seen_undef : sameval;
    6408                 :             :   /* If we saw only undefined values and VN_TOP use one of the
    6409                 :             :      undefined values.  */
    6410                 :    28344857 :   else if (sameval == VN_TOP)
    6411                 :     7399731 :     result = (seen_undef && seen_undef_visited) ? seen_undef : sameval;
    6412                 :             :   /* First see if it is equivalent to a phi node in this block.  We prefer
    6413                 :             :      this as it allows IV elimination - see PRs 66502 and 67167.  */
    6414                 :    28339551 :   else if ((result = vn_phi_lookup (phi, backedges_varying_p)))
    6415                 :             :     {
    6416                 :     4237692 :       if (!inserted
    6417                 :       72565 :           && TREE_CODE (result) == SSA_NAME
    6418                 :     4310257 :           && gimple_code (SSA_NAME_DEF_STMT (result)) == GIMPLE_PHI)
    6419                 :             :         {
    6420                 :       72565 :           gimple_set_plf (SSA_NAME_DEF_STMT (result), GF_PLF_1, true);
    6421                 :       72565 :           if (dump_file && (dump_flags & TDF_DETAILS))
    6422                 :             :             {
    6423                 :           2 :               fprintf (dump_file, "Marking CSEd to PHI node ");
    6424                 :           2 :               print_gimple_expr (dump_file, SSA_NAME_DEF_STMT (result),
    6425                 :             :                                  0, TDF_SLIM);
    6426                 :           2 :               fprintf (dump_file, "\n");
    6427                 :             :             }
    6428                 :             :         }
    6429                 :             :     }
    6430                 :             :   /* If all values are the same use that, unless we've seen undefined
    6431                 :             :      values as well and the value isn't constant.
    6432                 :             :      CCP/copyprop have the same restriction to not remove uninit warnings.  */
    6433                 :    24101859 :   else if (sameval
    6434                 :    24101859 :            && (! seen_undef || is_gimple_min_invariant (sameval)))
    6435                 :             :     result = sameval;
    6436                 :             :   else
    6437                 :             :     {
    6438                 :    23427979 :       result = PHI_RESULT (phi);
    6439                 :             :       /* Only insert PHIs that are varying, for constant value numbers
    6440                 :             :          we mess up equivalences otherwise as we are only comparing
    6441                 :             :          the immediate controlling predicates.  */
    6442                 :    23427979 :       vn_phi_insert (phi, result, backedges_varying_p);
    6443                 :    23427979 :       if (inserted)
    6444                 :     3271520 :         *inserted = true;
    6445                 :             :     }
    6446                 :             : 
    6447                 :    35402386 :   return set_ssa_val_to (PHI_RESULT (phi), result);
    6448                 :    35402386 : }
    6449                 :             : 
    6450                 :             : /* Try to simplify RHS using equivalences and constant folding.  */
    6451                 :             : 
    6452                 :             : static tree
    6453                 :   126720379 : try_to_simplify (gassign *stmt)
    6454                 :             : {
    6455                 :   126720379 :   enum tree_code code = gimple_assign_rhs_code (stmt);
    6456                 :   126720379 :   tree tem;
    6457                 :             : 
    6458                 :             :   /* For stores we can end up simplifying a SSA_NAME rhs.  Just return
    6459                 :             :      in this case, there is no point in doing extra work.  */
    6460                 :   126720379 :   if (code == SSA_NAME)
    6461                 :             :     return NULL_TREE;
    6462                 :             : 
    6463                 :             :   /* First try constant folding based on our current lattice.  */
    6464                 :   111706456 :   mprts_hook = vn_lookup_simplify_result;
    6465                 :   111706456 :   tem = gimple_fold_stmt_to_constant_1 (stmt, vn_valueize, vn_valueize);
    6466                 :   111706456 :   mprts_hook = NULL;
    6467                 :   111706456 :   if (tem
    6468                 :   111706456 :       && (TREE_CODE (tem) == SSA_NAME
    6469                 :    24776826 :           || is_gimple_min_invariant (tem)))
    6470                 :    24666690 :     return tem;
    6471                 :             : 
    6472                 :             :   return NULL_TREE;
    6473                 :             : }
    6474                 :             : 
    6475                 :             : /* Visit and value number STMT, return true if the value number
    6476                 :             :    changed.  */
    6477                 :             : 
    6478                 :             : static bool
    6479                 :   458066104 : visit_stmt (gimple *stmt, bool backedges_varying_p = false)
    6480                 :             : {
    6481                 :   458066104 :   bool changed = false;
    6482                 :             : 
    6483                 :   458066104 :   if (dump_file && (dump_flags & TDF_DETAILS))
    6484                 :             :     {
    6485                 :      382397 :       fprintf (dump_file, "Value numbering stmt = ");
    6486                 :      382397 :       print_gimple_stmt (dump_file, stmt, 0);
    6487                 :             :     }
    6488                 :             : 
    6489                 :   458066104 :   if (gimple_code (stmt) == GIMPLE_PHI)
    6490                 :    27831845 :     changed = visit_phi (stmt, NULL, backedges_varying_p);
    6491                 :   602677396 :   else if (gimple_has_volatile_ops (stmt))
    6492                 :    10271833 :     changed = defs_to_varying (stmt);
    6493                 :   419962426 :   else if (gassign *ass = dyn_cast <gassign *> (stmt))
    6494                 :             :     {
    6495                 :   131788366 :       enum tree_code code = gimple_assign_rhs_code (ass);
    6496                 :   131788366 :       tree lhs = gimple_assign_lhs (ass);
    6497                 :   131788366 :       tree rhs1 = gimple_assign_rhs1 (ass);
    6498                 :   131788366 :       tree simplified;
    6499                 :             : 
    6500                 :             :       /* Shortcut for copies. Simplifying copies is pointless,
    6501                 :             :          since we copy the expression and value they represent.  */
    6502                 :   131788366 :       if (code == SSA_NAME
    6503                 :    20081910 :           && TREE_CODE (lhs) == SSA_NAME)
    6504                 :             :         {
    6505                 :     5067987 :           changed = visit_copy (lhs, rhs1);
    6506                 :     5067987 :           goto done;
    6507                 :             :         }
    6508                 :   126720379 :       simplified = try_to_simplify (ass);
    6509                 :   126720379 :       if (simplified)
    6510                 :             :         {
    6511                 :    24666690 :           if (dump_file && (dump_flags & TDF_DETAILS))
    6512                 :             :             {
    6513                 :       13612 :               fprintf (dump_file, "RHS ");
    6514                 :       13612 :               print_gimple_expr (dump_file, ass, 0);
    6515                 :       13612 :               fprintf (dump_file, " simplified to ");
    6516                 :       13612 :               print_generic_expr (dump_file, simplified);
    6517                 :       13612 :               fprintf (dump_file, "\n");
    6518                 :             :             }
    6519                 :             :         }
    6520                 :             :       /* Setting value numbers to constants will occasionally
    6521                 :             :          screw up phi congruence because constants are not
    6522                 :             :          uniquely associated with a single ssa name that can be
    6523                 :             :          looked up.  */
    6524                 :    24666690 :       if (simplified
    6525                 :    24666690 :           && is_gimple_min_invariant (simplified)
    6526                 :    21824401 :           && TREE_CODE (lhs) == SSA_NAME)
    6527                 :             :         {
    6528                 :     7351855 :           changed = set_ssa_val_to (lhs, simplified);
    6529                 :     7351855 :           goto done;
    6530                 :             :         }
    6531                 :   119368524 :       else if (simplified
    6532                 :    17314835 :                && TREE_CODE (simplified) == SSA_NAME
    6533                 :     2842289 :                && TREE_CODE (lhs) == SSA_NAME)
    6534                 :             :         {
    6535                 :     2842289 :           changed = visit_copy (lhs, simplified);
    6536                 :     2842289 :           goto done;
    6537                 :             :         }
    6538                 :             : 
    6539                 :   116526235 :       if ((TREE_CODE (lhs) == SSA_NAME
    6540                 :             :            /* We can substitute SSA_NAMEs that are live over
    6541                 :             :               abnormal edges with their constant value.  */
    6542                 :    83382267 :            && !(gimple_assign_copy_p (ass)
    6543                 :          26 :                 && is_gimple_min_invariant (rhs1))
    6544                 :    83382241 :            && !(simplified
    6545                 :           0 :                 && is_gimple_min_invariant (simplified))
    6546                 :    83382241 :            && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
    6547                 :             :           /* Stores or copies from SSA_NAMEs that are live over
    6548                 :             :              abnormal edges are a problem.  */
    6549                 :   199907229 :           || (code == SSA_NAME
    6550                 :    15013923 :               && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1)))
    6551                 :        1504 :         changed = defs_to_varying (ass);
    6552                 :   116524731 :       else if (REFERENCE_CLASS_P (lhs)
    6553                 :   116524731 :                || DECL_P (lhs))
    6554                 :    33143737 :         changed = visit_reference_op_store (lhs, rhs1, ass);
    6555                 :    83380994 :       else if (TREE_CODE (lhs) == SSA_NAME)
    6556                 :             :         {
    6557                 :    83380994 :           if ((gimple_assign_copy_p (ass)
    6558                 :          26 :                && is_gimple_min_invariant (rhs1))
    6559                 :    83381020 :               || (simplified
    6560                 :           0 :                   && is_gimple_min_invariant (simplified)))
    6561                 :             :             {
    6562                 :           0 :               if (simplified)
    6563                 :           0 :                 changed = set_ssa_val_to (lhs, simplified);
    6564                 :             :               else
    6565                 :           0 :                 changed = set_ssa_val_to (lhs, rhs1);
    6566                 :             :             }
    6567                 :             :           else
    6568                 :             :             {
    6569                 :             :               /* Visit the original statement.  */
    6570                 :    83380994 :               switch (vn_get_stmt_kind (ass))
    6571                 :             :                 {
    6572                 :    48289394 :                 case VN_NARY:
    6573                 :    48289394 :                   changed = visit_nary_op (lhs, ass);
    6574                 :    48289394 :                   break;
    6575                 :    35040501 :                 case VN_REFERENCE:
    6576                 :    35040501 :                   changed = visit_reference_op_load (lhs, rhs1, ass);
    6577                 :    35040501 :                   break;
    6578                 :       51099 :                 default:
    6579                 :       51099 :                   changed = defs_to_varying (ass);
    6580                 :       51099 :                   break;
    6581                 :             :                 }
    6582                 :             :             }
    6583                 :             :         }
    6584                 :             :       else
    6585                 :           0 :         changed = defs_to_varying (ass);
    6586                 :             :     }
    6587                 :   288174060 :   else if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
    6588                 :             :     {
    6589                 :    24634797 :       tree lhs = gimple_call_lhs (call_stmt);
    6590                 :    24634797 :       if (lhs && TREE_CODE (lhs) == SSA_NAME)
    6591                 :             :         {
    6592                 :             :           /* Try constant folding based on our current lattice.  */
    6593                 :     8220643 :           tree simplified = gimple_fold_stmt_to_constant_1 (call_stmt,
    6594                 :             :                                                             vn_valueize);
    6595                 :     8220643 :           if (simplified)
    6596                 :             :             {
    6597                 :       60447 :               if (dump_file && (dump_flags & TDF_DETAILS))
    6598                 :             :                 {
    6599                 :           1 :                   fprintf (dump_file, "call ");
    6600                 :           1 :                   print_gimple_expr (dump_file, call_stmt, 0);
    6601                 :           1 :                   fprintf (dump_file, " simplified to ");
    6602                 :           1 :                   print_generic_expr (dump_file, simplified);
    6603                 :           1 :                   fprintf (dump_file, "\n");
    6604                 :             :                 }
    6605                 :             :             }
    6606                 :             :           /* Setting value numbers to constants will occasionally
    6607                 :             :              screw up phi congruence because constants are not
    6608                 :             :              uniquely associated with a single ssa name that can be
    6609                 :             :              looked up.  */
    6610                 :       60447 :           if (simplified
    6611                 :       60447 :               && is_gimple_min_invariant (simplified))
    6612                 :             :             {
    6613                 :       53824 :               changed = set_ssa_val_to (lhs, simplified);
    6614                 :      107648 :               if (gimple_vdef (call_stmt))
    6615                 :         725 :                 changed |= set_ssa_val_to (gimple_vdef (call_stmt),
    6616                 :             :                                            SSA_VAL (gimple_vuse (call_stmt)));
    6617                 :       53824 :               goto done;
    6618                 :             :             }
    6619                 :     8166819 :           else if (simplified
    6620                 :        6623 :                    && TREE_CODE (simplified) == SSA_NAME)
    6621                 :             :             {
    6622                 :         301 :               changed = visit_copy (lhs, simplified);
    6623                 :         602 :               if (gimple_vdef (call_stmt))
    6624                 :           0 :                 changed |= set_ssa_val_to (gimple_vdef (call_stmt),
    6625                 :             :                                            SSA_VAL (gimple_vuse (call_stmt)));
    6626                 :         301 :               goto done;
    6627                 :             :             }
    6628                 :     8166518 :           else if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
    6629                 :             :             {
    6630                 :         381 :               changed = defs_to_varying (call_stmt);
    6631                 :         381 :               goto done;
    6632                 :             :             }
    6633                 :             :         }
    6634                 :             : 
    6635                 :             :       /* Pick up flags from a devirtualization target.  */
    6636                 :    24580291 :       tree fn = gimple_call_fn (stmt);
    6637                 :    24580291 :       int extra_fnflags = 0;
    6638                 :    24580291 :       if (fn && TREE_CODE (fn) == SSA_NAME)
    6639                 :             :         {
    6640                 :      533198 :           fn = SSA_VAL (fn);
    6641                 :      533198 :           if (TREE_CODE (fn) == ADDR_EXPR
    6642                 :      533198 :               && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL)
    6643                 :        4866 :             extra_fnflags = flags_from_decl_or_type (TREE_OPERAND (fn, 0));
    6644                 :             :         }
    6645                 :    24580291 :       if ((/* Calls to the same function with the same vuse
    6646                 :             :               and the same operands do not necessarily return the same
    6647                 :             :               value, unless they're pure or const.  */
    6648                 :    24580291 :            ((gimple_call_flags (call_stmt) | extra_fnflags)
    6649                 :    24580291 :             & (ECF_PURE | ECF_CONST))
    6650                 :             :            /* If calls have a vdef, subsequent calls won't have
    6651                 :             :               the same incoming vuse.  So, if 2 calls with vdef have the
    6652                 :             :               same vuse, we know they're not subsequent.
    6653                 :             :               We can value number 2 calls to the same function with the
    6654                 :             :               same vuse and the same operands which are not subsequent
    6655                 :             :               the same, because there is no code in the program that can
    6656                 :             :               compare the 2 values...  */
    6657                 :    20906325 :            || (gimple_vdef (call_stmt)
    6658                 :             :                /* ... unless the call returns a pointer which does
    6659                 :             :                   not alias with anything else.  In which case the
    6660                 :             :                   information that the values are distinct are encoded
    6661                 :             :                   in the IL.  */
    6662                 :    20871582 :                && !(gimple_call_return_flags (call_stmt) & ERF_NOALIAS)
    6663                 :             :                /* Only perform the following when being called from PRE
    6664                 :             :                   which embeds tail merging.  */
    6665                 :    20429976 :                && default_vn_walk_kind == VN_WALK))
    6666                 :             :           /* Do not process .DEFERRED_INIT since that confuses uninit
    6667                 :             :              analysis.  */
    6668                 :    29601992 :           && !gimple_call_internal_p (call_stmt, IFN_DEFERRED_INIT))
    6669                 :     8694956 :         changed = visit_reference_op_call (lhs, call_stmt);
    6670                 :             :       else
    6671                 :    15885335 :         changed = defs_to_varying (call_stmt);
    6672                 :             :     }
    6673                 :             :   else
    6674                 :   263539263 :     changed = defs_to_varying (stmt);
    6675                 :   458066104 :  done:
    6676                 :   458066104 :   return changed;
    6677                 :             : }
    6678                 :             : 
    6679                 :             : 
    6680                 :             : /* Allocate a value number table.  */
    6681                 :             : 
    6682                 :             : static void
    6683                 :     6204819 : allocate_vn_table (vn_tables_t table, unsigned size)
    6684                 :             : {
    6685                 :     6204819 :   table->phis = new vn_phi_table_type (size);
    6686                 :     6204819 :   table->nary = new vn_nary_op_table_type (size);
    6687                 :     6204819 :   table->references = new vn_reference_table_type (size);
    6688                 :     6204819 : }
    6689                 :             : 
    6690                 :             : /* Free a value number table.  */
    6691                 :             : 
    6692                 :             : static void
    6693                 :     6204819 : free_vn_table (vn_tables_t table)
    6694                 :             : {
    6695                 :             :   /* Walk over elements and release vectors.  */
    6696                 :     6204819 :   vn_reference_iterator_type hir;
    6697                 :     6204819 :   vn_reference_t vr;
    6698                 :   152937305 :   FOR_EACH_HASH_TABLE_ELEMENT (*table->references, vr, vn_reference_t, hir)
    6699                 :    73366243 :     vr->operands.release ();
    6700                 :     6204819 :   delete table->phis;
    6701                 :     6204819 :   table->phis = NULL;
    6702                 :     6204819 :   delete table->nary;
    6703                 :     6204819 :   table->nary = NULL;
    6704                 :     6204819 :   delete table->references;
    6705                 :     6204819 :   table->references = NULL;
    6706                 :     6204819 : }
    6707                 :             : 
    6708                 :             : /* Set *ID according to RESULT.  */
    6709                 :             : 
    6710                 :             : static void
    6711                 :    35173731 : set_value_id_for_result (tree result, unsigned int *id)
    6712                 :             : {
    6713                 :    35173731 :   if (result && TREE_CODE (result) == SSA_NAME)
    6714                 :    21958533 :     *id = VN_INFO (result)->value_id;
    6715                 :     9905963 :   else if (result && is_gimple_min_invariant (result))
    6716                 :     3750711 :     *id = get_or_alloc_constant_value_id (result);
    6717                 :             :   else
    6718                 :     9464487 :     *id = get_next_value_id ();
    6719                 :    35173731 : }
    6720                 :             : 
    6721                 :             : /* Set the value ids in the valid hash tables.  */
    6722                 :             : 
    6723                 :             : static void
    6724                 :      966333 : set_hashtable_value_ids (void)
    6725                 :             : {
    6726                 :      966333 :   vn_nary_op_iterator_type hin;
    6727                 :      966333 :   vn_phi_iterator_type hip;
    6728                 :      966333 :   vn_reference_iterator_type hir;
    6729                 :      966333 :   vn_nary_op_t vno;
    6730                 :      966333 :   vn_reference_t vr;
    6731                 :      966333 :   vn_phi_t vp;
    6732                 :             : 
    6733                 :             :   /* Now set the value ids of the things we had put in the hash
    6734                 :             :      table.  */
    6735                 :             : 
    6736                 :    49553763 :   FOR_EACH_HASH_TABLE_ELEMENT (*valid_info->nary, vno, vn_nary_op_t, hin)
    6737                 :    24293715 :     if (! vno->predicated_values)
    6738                 :     7847323 :       set_value_id_for_result (vno->u.result, &vno->value_id);
    6739                 :             : 
    6740                 :     9224031 :   FOR_EACH_HASH_TABLE_ELEMENT (*valid_info->phis, vp, vn_phi_t, hip)
    6741                 :     4128849 :     set_value_id_for_result (vp->result, &vp->value_id);
    6742                 :             : 
    6743                 :    47361451 :   FOR_EACH_HASH_TABLE_ELEMENT (*valid_info->references, vr, vn_reference_t,
    6744                 :             :                                hir)
    6745                 :    23197559 :     set_value_id_for_result (vr->result, &vr->value_id);
    6746                 :      966333 : }
    6747                 :             : 
    6748                 :             : /* Return the maximum value id we have ever seen.  */
    6749                 :             : 
    6750                 :             : unsigned int
    6751                 :     1932666 : get_max_value_id (void)
    6752                 :             : {
    6753                 :     1932666 :   return next_value_id;
    6754                 :             : }
    6755                 :             : 
    6756                 :             : /* Return the maximum constant value id we have ever seen.  */
    6757                 :             : 
    6758                 :             : unsigned int
    6759                 :     1932666 : get_max_constant_value_id (void)
    6760                 :             : {
    6761                 :     1932666 :   return -next_constant_value_id;
    6762                 :             : }
    6763                 :             : 
    6764                 :             : /* Return the next unique value id.  */
    6765                 :             : 
    6766                 :             : unsigned int
    6767                 :    49811808 : get_next_value_id (void)
    6768                 :             : {
    6769                 :    49811808 :   gcc_checking_assert ((int)next_value_id > 0);
    6770                 :    49811808 :   return next_value_id++;
    6771                 :             : }
    6772                 :             : 
    6773                 :             : /* Return the next unique value id for constants.  */
    6774                 :             : 
    6775                 :             : unsigned int
    6776                 :     2562010 : get_next_constant_value_id (void)
    6777                 :             : {
    6778                 :     2562010 :   gcc_checking_assert (next_constant_value_id < 0);
    6779                 :     2562010 :   return next_constant_value_id--;
    6780                 :             : }
    6781                 :             : 
    6782                 :             : 
    6783                 :             : /* Compare two expressions E1 and E2 and return true if they are equal.
    6784                 :             :    If match_vn_top_optimistically is true then VN_TOP is equal to anything,
    6785                 :             :    otherwise VN_TOP only matches VN_TOP.  */
    6786                 :             : 
    6787                 :             : bool
    6788                 :   241447582 : expressions_equal_p (tree e1, tree e2, bool match_vn_top_optimistically)
    6789                 :             : {
    6790                 :             :   /* The obvious case.  */
    6791                 :   241447582 :   if (e1 == e2)
    6792                 :             :     return true;
    6793                 :             : 
    6794                 :             :   /* If either one is VN_TOP consider them equal.  */
    6795                 :    72016710 :   if (match_vn_top_optimistically
    6796                 :    66865207 :       && (e1 == VN_TOP || e2 == VN_TOP))
    6797                 :             :     return true;
    6798                 :             : 
    6799                 :             :   /* If only one of them is null, they cannot be equal.  While in general
    6800                 :             :      this should not happen for operations like TARGET_MEM_REF some
    6801                 :             :      operands are optional and an identity value we could substitute
    6802                 :             :      has differing semantics.  */
    6803                 :    72016710 :   if (!e1 || !e2)
    6804                 :             :     return false;
    6805                 :             : 
    6806                 :             :   /* SSA_NAME compare pointer equal.  */
    6807                 :    72016710 :   if (TREE_CODE (e1) == SSA_NAME || TREE_CODE (e2) == SSA_NAME)
    6808                 :             :     return false;
    6809                 :             : 
    6810                 :             :   /* Now perform the actual comparison.  */
    6811                 :    35061104 :   if (TREE_CODE (e1) == TREE_CODE (e2)
    6812                 :    35061104 :       && operand_equal_p (e1, e2, OEP_PURE_SAME))
    6813                 :             :     return true;
    6814                 :             : 
    6815                 :             :   return false;
    6816                 :             : }
    6817                 :             : 
    6818                 :             : 
    6819                 :             : /* Return true if the nary operation NARY may trap.  This is a copy
    6820                 :             :    of stmt_could_throw_1_p adjusted to the SCCVN IL.  */
    6821                 :             : 
    6822                 :             : bool
    6823                 :     5371756 : vn_nary_may_trap (vn_nary_op_t nary)
    6824                 :             : {
    6825                 :     5371756 :   tree type;
    6826                 :     5371756 :   tree rhs2 = NULL_TREE;
    6827                 :     5371756 :   bool honor_nans = false;
    6828                 :     5371756 :   bool honor_snans = false;
    6829                 :     5371756 :   bool fp_operation = false;
    6830                 :     5371756 :   bool honor_trapv = false;
    6831                 :     5371756 :   bool handled, ret;
    6832                 :     5371756 :   unsigned i;
    6833                 :             : 
    6834                 :     5371756 :   if (TREE_CODE_CLASS (nary->opcode) == tcc_comparison
    6835                 :             :       || TREE_CODE_CLASS (nary->opcode) == tcc_unary
    6836                 :     5371756 :       || TREE_CODE_CLASS (nary->opcode) == tcc_binary)
    6837                 :             :     {
    6838                 :     5285348 :       type = nary->type;
    6839                 :     5285348 :       fp_operation = FLOAT_TYPE_P (type);
    6840                 :     5285348 :       if (fp_operation)
    6841                 :             :         {
    6842                 :      118115 :           honor_nans = flag_trapping_math && !flag_finite_math_only;
    6843                 :      118115 :           honor_snans = flag_signaling_nans != 0;
    6844                 :             :         }
    6845                 :     5167233 :       else if (INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_TRAPS (type))
    6846                 :             :         honor_trapv = true;
    6847                 :             :     }
    6848                 :     5371756 :   if (nary->length >= 2)
    6849                 :     2180318 :     rhs2 = nary->op[1];
    6850                 :     5371756 :   ret = operation_could_trap_helper_p (nary->opcode, fp_operation,
    6851                 :             :                                        honor_trapv, honor_nans, honor_snans,
    6852                 :             :                                        rhs2, &handled);
    6853                 :     5371756 :   if (handled && ret)
    6854                 :             :     return true;
    6855                 :             : 
    6856                 :    12603859 :   for (i = 0; i < nary->length; ++i)
    6857                 :     7349085 :     if (tree_could_trap_p (nary->op[i]))
    6858                 :             :       return true;
    6859                 :             : 
    6860                 :             :   return false;
    6861                 :             : }
    6862                 :             : 
    6863                 :             : /* Return true if the reference operation REF may trap.  */
    6864                 :             : 
    6865                 :             : bool
    6866                 :     1871504 : vn_reference_may_trap (vn_reference_t ref)
    6867                 :             : {
    6868                 :     1871504 :   switch (ref->operands[0].opcode)
    6869                 :             :     {
    6870                 :             :     case MODIFY_EXPR:
    6871                 :             :     case CALL_EXPR:
    6872                 :             :       /* We do not handle calls.  */
    6873                 :             :       return true;
    6874                 :             :     case ADDR_EXPR:
    6875                 :             :       /* And toplevel address computations never trap.  */
    6876                 :             :       return false;
    6877                 :             :     default:;
    6878                 :             :     }
    6879                 :             : 
    6880                 :             :   vn_reference_op_t op;
    6881                 :             :   unsigned i;
    6882                 :     4983030 :   FOR_EACH_VEC_ELT (ref->operands, i, op)
    6883                 :             :     {
    6884                 :     4982828 :       switch (op->opcode)
    6885                 :             :         {
    6886                 :             :         case WITH_SIZE_EXPR:
    6887                 :             :         case TARGET_MEM_REF:
    6888                 :             :           /* Always variable.  */
    6889                 :             :           return true;
    6890                 :     1236348 :         case COMPONENT_REF:
    6891                 :     1236348 :           if (op->op1 && TREE_CODE (op->op1) == SSA_NAME)
    6892                 :             :             return true;
    6893                 :             :           break;
    6894                 :           0 :         case ARRAY_RANGE_REF:
    6895                 :           0 :           if (TREE_CODE (op->op0) == SSA_NAME)
    6896                 :             :             return true;
    6897                 :             :           break;
    6898                 :      243466 :         case ARRAY_REF:
    6899                 :      243466 :           {
    6900                 :      243466 :             if (TREE_CODE (op->op0) != INTEGER_CST)
    6901                 :             :               return true;
    6902                 :             : 
    6903                 :             :             /* !in_array_bounds   */
    6904                 :      213158 :             tree domain_type = TYPE_DOMAIN (ref->operands[i+1].type);
    6905                 :      213158 :             if (!domain_type)
    6906                 :             :               return true;
    6907                 :             : 
    6908                 :      213027 :             tree min = op->op1;
    6909                 :      213027 :             tree max = TYPE_MAX_VALUE (domain_type);
    6910                 :      213027 :             if (!min
    6911                 :      213027 :                 || !max
    6912                 :      199867 :                 || TREE_CODE (min) != INTEGER_CST
    6913                 :      199867 :                 || TREE_CODE (max) != INTEGER_CST)
    6914                 :             :               return true;
    6915                 :             : 
    6916                 :      197319 :             if (tree_int_cst_lt (op->op0, min)
    6917                 :      197319 :                 || tree_int_cst_lt (max, op->op0))
    6918                 :         598 :               return true;
    6919                 :             : 
    6920                 :             :             break;
    6921                 :             :           }
    6922                 :             :         case MEM_REF:
    6923                 :             :           /* Nothing interesting in itself, the base is separate.  */
    6924                 :             :           break;
    6925                 :             :         /* The following are the address bases.  */
    6926                 :             :         case SSA_NAME:
    6927                 :             :           return true;
    6928                 :     1235579 :         case ADDR_EXPR:
    6929                 :     1235579 :           if (op->op0)
    6930                 :     1235579 :             return tree_could_trap_p (TREE_OPERAND (op->op0, 0));
    6931                 :             :           return false;
    6932                 :     3200613 :         default:;
    6933                 :             :         }
    6934                 :             :     }
    6935                 :             :   return false;
    6936                 :             : }
    6937                 :             : 
    6938                 :    10544851 : eliminate_dom_walker::eliminate_dom_walker (cdi_direction direction,
    6939                 :    10544851 :                                             bitmap inserted_exprs_)
    6940                 :    10544851 :   : dom_walker (direction), do_pre (inserted_exprs_ != NULL),
    6941                 :    10544851 :     el_todo (0), eliminations (0), insertions (0),
    6942                 :    10544851 :     inserted_exprs (inserted_exprs_)
    6943                 :             : {
    6944                 :    10544851 :   need_eh_cleanup = BITMAP_ALLOC (NULL);
    6945                 :    10544851 :   need_ab_cleanup = BITMAP_ALLOC (NULL);
    6946                 :    10544851 : }
    6947                 :             : 
    6948                 :    10544851 : eliminate_dom_walker::~eliminate_dom_walker ()
    6949                 :             : {
    6950                 :    10544851 :   BITMAP_FREE (need_eh_cleanup);
    6951                 :    10544851 :   BITMAP_FREE (need_ab_cleanup);
    6952                 :    10544851 : }
    6953                 :             : 
    6954                 :             : /* Return a leader for OP that is available at the current point of the
    6955                 :             :    eliminate domwalk.  */
    6956                 :             : 
    6957                 :             : tree
    6958                 :   182844258 : eliminate_dom_walker::eliminate_avail (basic_block, tree op)
    6959                 :             : {
    6960                 :   182844258 :   tree valnum = VN_INFO (op)->valnum;
    6961                 :   182844258 :   if (TREE_CODE (valnum) == SSA_NAME)
    6962                 :             :     {
    6963                 :   177755790 :       if (SSA_NAME_IS_DEFAULT_DEF (valnum))
    6964                 :             :         return valnum;
    6965                 :   308863681 :       if (avail.length () > SSA_NAME_VERSION (valnum))
    6966                 :             :         {
    6967                 :   139122387 :           tree av = avail[SSA_NAME_VERSION (valnum)];
    6968                 :             :           /* When PRE discovers a new redundancy there's no way to unite
    6969                 :             :              the value classes so it instead inserts a copy old-val = new-val.
    6970                 :             :              Look through such copies here, providing one more level of
    6971                 :             :              simplification at elimination time.  */
    6972                 :   139122387 :           gassign *ass;
    6973                 :   244315703 :           if (av && (ass = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (av))))
    6974                 :    74415409 :             if (gimple_assign_rhs_class (ass) == GIMPLE_SINGLE_RHS)
    6975                 :             :               {
    6976                 :    39917975 :                 tree rhs1 = gimple_assign_rhs1 (ass);
    6977                 :    39917975 :                 if (CONSTANT_CLASS_P (rhs1)
    6978                 :    39917975 :                     || (TREE_CODE (rhs1) == SSA_NAME
    6979                 :        9126 :                         && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1)))
    6980                 :             :                   av = rhs1;
    6981                 :             :               }
    6982                 :   139122387 :           return av;
    6983                 :             :         }
    6984                 :             :     }
    6985                 :     5088468 :   else if (is_gimple_min_invariant (valnum))
    6986                 :             :     return valnum;
    6987                 :             :   return NULL_TREE;
    6988                 :             : }
    6989                 :             : 
    6990                 :             : /* At the current point of the eliminate domwalk make OP available.  */
    6991                 :             : 
    6992                 :             : void
    6993                 :    50642998 : eliminate_dom_walker::eliminate_push_avail (basic_block, tree op)
    6994                 :             : {
    6995                 :    50642998 :   tree valnum = VN_INFO (op)->valnum;
    6996                 :    50642998 :   if (TREE_CODE (valnum) == SSA_NAME)
    6997                 :             :     {
    6998                 :    97895555 :       if (avail.length () <= SSA_NAME_VERSION (valnum))
    6999                 :    17040178 :         avail.safe_grow_cleared (SSA_NAME_VERSION (valnum) + 1, true);
    7000                 :    50642998 :       tree pushop = op;
    7001                 :    50642998 :       if (avail[SSA_NAME_VERSION (valnum)])
    7002                 :       43290 :         pushop = avail[SSA_NAME_VERSION (valnum)];
    7003                 :    50642998 :       avail_stack.safe_push (pushop);
    7004                 :    50642998 :       avail[SSA_NAME_VERSION (valnum)] = op;
    7005                 :             :     }
    7006                 :    50642998 : }
    7007                 :             : 
    7008                 :             : /* Insert the expression recorded by SCCVN for VAL at *GSI.  Returns
    7009                 :             :    the leader for the expression if insertion was successful.  */
    7010                 :             : 
    7011                 :             : tree
    7012                 :      127131 : eliminate_dom_walker::eliminate_insert (basic_block bb,
    7013                 :             :                                         gimple_stmt_iterator *gsi, tree val)
    7014                 :             : {
    7015                 :             :   /* We can insert a sequence with a single assignment only.  */
    7016                 :      127131 :   gimple_seq stmts = VN_INFO (val)->expr;
    7017                 :      127131 :   if (!gimple_seq_singleton_p (stmts))
    7018                 :             :     return NULL_TREE;
    7019                 :      232245 :   gassign *stmt = dyn_cast <gassign *> (gimple_seq_first_stmt (stmts));
    7020                 :      127131 :   if (!stmt
    7021                 :      127131 :       || (!CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))
    7022                 :             :           && gimple_assign_rhs_code (stmt) != VIEW_CONVERT_EXPR
    7023                 :             :           && gimple_assign_rhs_code (stmt) != NEGATE_EXPR
    7024                 :             :           && gimple_assign_rhs_code (stmt) != BIT_FIELD_REF
    7025                 :             :           && (gimple_assign_rhs_code (stmt) != BIT_AND_EXPR
    7026                 :          75 :               || TREE_CODE (gimple_assign_rhs2 (stmt)) != INTEGER_CST)))
    7027                 :             :     return NULL_TREE;
    7028                 :             : 
    7029                 :       35046 :   tree op = gimple_assign_rhs1 (stmt);
    7030                 :       35046 :   if (gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR
    7031                 :       35046 :       || gimple_assign_rhs_code (stmt) == BIT_FIELD_REF)
    7032                 :       19252 :     op = TREE_OPERAND (op, 0);
    7033                 :       35046 :   tree leader = TREE_CODE (op) == SSA_NAME ? eliminate_avail (bb, op) : op;
    7034                 :       35000 :   if (!leader)
    7035                 :             :     return NULL_TREE;
    7036                 :             : 
    7037                 :       22021 :   tree res;
    7038                 :       22021 :   stmts = NULL;
    7039                 :       40374 :   if (gimple_assign_rhs_code (stmt) == BIT_FIELD_REF)
    7040                 :       32926 :     res = gimple_build (&stmts, BIT_FIELD_REF,
    7041                 :       16463 :                         TREE_TYPE (val), leader,
    7042                 :       16463 :                         TREE_OPERAND (gimple_assign_rhs1 (stmt), 1),
    7043                 :       16463 :                         TREE_OPERAND (gimple_assign_rhs1 (stmt), 2));
    7044                 :        5558 :   else if (gimple_assign_rhs_code (stmt) == BIT_AND_EXPR)
    7045                 :         150 :     res = gimple_build (&stmts, BIT_AND_EXPR,
    7046                 :          75 :                         TREE_TYPE (val), leader, gimple_assign_rhs2 (stmt));
    7047                 :             :   else
    7048                 :        5483 :     res = gimple_build (&stmts, gimple_assign_rhs_code (stmt),
    7049                 :        5483 :                         TREE_TYPE (val), leader);
    7050                 :       22021 :   if (TREE_CODE (res) != SSA_NAME
    7051                 :       22020 :       || SSA_NAME_IS_DEFAULT_DEF (res)
    7052                 :       44041 :       || gimple_bb (SSA_NAME_DEF_STMT (res)))
    7053                 :             :     {
    7054                 :           4 :       gimple_seq_discard (stmts);
    7055                 :             : 
    7056                 :             :       /* During propagation we have to treat SSA info conservatively
    7057                 :             :          and thus we can end up simplifying the inserted expression
    7058                 :             :          at elimination time to sth not defined in stmts.  */
    7059                 :             :       /* But then this is a redundancy we failed to detect.  Which means
    7060                 :             :          res now has two values.  That doesn't play well with how
    7061                 :             :          we track availability here, so give up.  */
    7062                 :           4 :       if (dump_file && (dump_flags & TDF_DETAILS))
    7063                 :             :         {
    7064                 :           0 :           if (TREE_CODE (res) == SSA_NAME)
    7065                 :           0 :             res = eliminate_avail (bb, res);
    7066                 :           0 :           if (res)
    7067                 :             :             {
    7068                 :           0 :               fprintf (dump_file, "Failed to insert expression for value ");
    7069                 :           0 :               print_generic_expr (dump_file, val);
    7070                 :           0 :               fprintf (dump_file, " which is really fully redundant to ");
    7071                 :           0 :               print_generic_expr (dump_file, res);
    7072                 :           0 :               fprintf (dump_file, "\n");
    7073                 :             :             }
    7074                 :             :         }
    7075                 :             : 
    7076                 :           4 :       return NULL_TREE;
    7077                 :             :     }
    7078                 :             :   else
    7079                 :             :     {
    7080                 :       22017 :       gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
    7081                 :       22017 :       vn_ssa_aux_t vn_info = VN_INFO (res);
    7082                 :       22017 :       vn_info->valnum = val;
    7083                 :       22017 :       vn_info->visited = true;
    7084                 :             :     }
    7085                 :             : 
    7086                 :       22017 :   insertions++;
    7087                 :       22017 :   if (dump_file && (dump_flags & TDF_DETAILS))
    7088                 :             :     {
    7089                 :         501 :       fprintf (dump_file, "Inserted ");
    7090                 :         501 :       print_gimple_stmt (dump_file, SSA_NAME_DEF_STMT (res), 0);
    7091                 :             :     }
    7092                 :             : 
    7093                 :             :   return res;
    7094                 :             : }
    7095                 :             : 
    7096                 :             : void
    7097                 :   354747350 : eliminate_dom_walker::eliminate_stmt (basic_block b, gimple_stmt_iterator *gsi)
    7098                 :             : {
    7099                 :   354747350 :   tree sprime = NULL_TREE;
    7100                 :   354747350 :   gimple *stmt = gsi_stmt (*gsi);
    7101                 :   354747350 :   tree lhs = gimple_get_lhs (stmt);
    7102                 :   121324290 :   if (lhs && TREE_CODE (lhs) == SSA_NAME
    7103                 :   165409980 :       && !gimple_has_volatile_ops (stmt)
    7104                 :             :       /* See PR43491.  Do not replace a global register variable when
    7105                 :             :          it is a the RHS of an assignment.  Do replace local register
    7106                 :             :          variables since gcc does not guarantee a local variable will
    7107                 :             :          be allocated in register.
    7108                 :             :          ???  The fix isn't effective here.  This should instead
    7109                 :             :          be ensured by not value-numbering them the same but treating
    7110                 :             :          them like volatiles?  */
    7111                 :   436393462 :       && !(gimple_assign_single_p (stmt)
    7112                 :    35701661 :            && (TREE_CODE (gimple_assign_rhs1 (stmt)) == VAR_DECL
    7113                 :     2534988 :                && DECL_HARD_REGISTER (gimple_assign_rhs1 (stmt))
    7114                 :        4172 :                && is_global_var (gimple_assign_rhs1 (stmt)))))
    7115                 :             :     {
    7116                 :    81645868 :       sprime = eliminate_avail (b, lhs);
    7117                 :    81645868 :       if (!sprime)
    7118                 :             :         {
    7119                 :             :           /* If there is no existing usable leader but SCCVN thinks
    7120                 :             :              it has an expression it wants to use as replacement,
    7121                 :             :              insert that.  */
    7122                 :    68974357 :           tree val = VN_INFO (lhs)->valnum;
    7123                 :    68974357 :           vn_ssa_aux_t vn_info;
    7124                 :    68974357 :           if (val != VN_TOP
    7125                 :    68974357 :               && TREE_CODE (val) == SSA_NAME
    7126                 :    68974357 :               && (vn_info = VN_INFO (val), true)
    7127                 :    68974357 :               && vn_info->needs_insertion
    7128                 :      327391 :               && vn_info->expr != NULL
    7129                 :    69101488 :               && (sprime = eliminate_insert (b, gsi, val)) != NULL_TREE)
    7130                 :       22017 :             eliminate_push_avail (b, sprime);
    7131                 :             :         }
    7132                 :             : 
    7133                 :             :       /* If this now constitutes a copy duplicate points-to
    7134                 :             :          and range info appropriately.  This is especially
    7135                 :             :          important for inserted code.  */
    7136                 :    68974357 :       if (sprime
    7137                 :    12693528 :           && TREE_CODE (sprime) == SSA_NAME)
    7138                 :     8774397 :         maybe_duplicate_ssa_info_at_copy (lhs, sprime);
    7139                 :             : 
    7140                 :             :       /* Inhibit the use of an inserted PHI on a loop header when
    7141                 :             :          the address of the memory reference is a simple induction
    7142                 :             :          variable.  In other cases the vectorizer won't do anything
    7143                 :             :          anyway (either it's loop invariant or a complicated
    7144                 :             :          expression).  */
    7145                 :     8774397 :       if (sprime
    7146                 :    12693528 :           && TREE_CODE (sprime) == SSA_NAME
    7147                 :     8774397 :           && do_pre
    7148                 :      932694 :           && (flag_tree_loop_vectorize || flag_tree_parallelize_loops > 1)
    7149                 :      914476 :           && loop_outer (b->loop_father)
    7150                 :      369681 :           && has_zero_uses (sprime)
    7151                 :      181674 :           && bitmap_bit_p (inserted_exprs, SSA_NAME_VERSION (sprime))
    7152                 :      181521 :           && gimple_assign_load_p (stmt))
    7153                 :             :         {
    7154                 :      100388 :           gimple *def_stmt = SSA_NAME_DEF_STMT (sprime);
    7155                 :      100388 :           basic_block def_bb = gimple_bb (def_stmt);
    7156                 :      100388 :           if (gimple_code (def_stmt) == GIMPLE_PHI
    7157                 :      100388 :               && def_bb->loop_father->header == def_bb)
    7158                 :             :             {
    7159                 :       63258 :               loop_p loop = def_bb->loop_father;
    7160                 :       63258 :               ssa_op_iter iter;
    7161                 :       63258 :               tree op;
    7162                 :       63258 :               bool found = false;
    7163                 :       79072 :               FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
    7164                 :             :                 {
    7165                 :       59062 :                   affine_iv iv;
    7166                 :       59062 :                   def_bb = gimple_bb (SSA_NAME_DEF_STMT (op));
    7167                 :       59062 :                   if (def_bb
    7168                 :       53876 :                       && flow_bb_inside_loop_p (loop, def_bb)
    7169                 :      108337 :                       && simple_iv (loop, loop, op, &iv, true))
    7170                 :             :                     {
    7171                 :       43248 :                       found = true;
    7172                 :       43248 :                       break;
    7173                 :             :                     }
    7174                 :             :                 }
    7175                 :       20010 :               if (found)
    7176                 :             :                 {
    7177                 :       43248 :                   if (dump_file && (dump_flags & TDF_DETAILS))
    7178                 :             :                     {
    7179                 :           3 :                       fprintf (dump_file, "Not replacing ");
    7180                 :           3 :                       print_gimple_expr (dump_file, stmt, 0);
    7181                 :           3 :                       fprintf (dump_file, " with ");
    7182                 :           3 :                       print_generic_expr (dump_file, sprime);
    7183                 :           3 :                       fprintf (dump_file, " which would add a loop"
    7184                 :             :                                " carried dependence to loop %d\n",
    7185                 :             :                                loop->num);
    7186                 :             :                     }
    7187                 :             :                   /* Don't keep sprime available.  */
    7188                 :       43248 :                   sprime = NULL_TREE;
    7189                 :             :                 }
    7190                 :             :             }
    7191                 :             :         }
    7192                 :             : 
    7193                 :    81645868 :       if (sprime)
    7194                 :             :         {
    7195                 :             :           /* If we can propagate the value computed for LHS into
    7196                 :             :              all uses don't bother doing anything with this stmt.  */
    7197                 :    12650280 :           if (may_propagate_copy (lhs, sprime))
    7198                 :             :             {
    7199                 :             :               /* Mark it for removal.  */
    7200                 :    12648247 :               to_remove.safe_push (stmt);
    7201                 :             : 
    7202                 :             :               /* ???  Don't count copy/constant propagations.  */
    7203                 :    12648247 :               if (gimple_assign_single_p (stmt)
    7204                 :    12648247 :                   && (TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME
    7205                 :     4424459 :                       || gimple_assign_rhs1 (stmt) == sprime))
    7206                 :    13402030 :                 return;
    7207                 :             : 
    7208                 :     7544964 :               if (dump_file && (dump_flags & TDF_DETAILS))
    7209                 :             :                 {
    7210                 :       17716 :                   fprintf (dump_file, "Replaced ");
    7211                 :       17716 :                   print_gimple_expr (dump_file, stmt, 0);
    7212                 :       17716 :                   fprintf (dump_file, " with ");
    7213                 :       17716 :                   print_generic_expr (dump_file, sprime);
    7214                 :       17716 :                   fprintf (dump_file, " in all uses of ");
    7215                 :       17716 :                   print_gimple_stmt (dump_file, stmt, 0);
    7216                 :             :                 }
    7217                 :             : 
    7218                 :     7544964 :               eliminations++;
    7219                 :     7544964 :               return;
    7220                 :             :             }
    7221                 :             : 
    7222                 :             :           /* If this is an assignment from our leader (which
    7223                 :             :              happens in the case the value-number is a constant)
    7224                 :             :              then there is nothing to do.  Likewise if we run into
    7225                 :             :              inserted code that needed a conversion because of
    7226                 :             :              our type-agnostic value-numbering of loads.  */
    7227                 :        2033 :           if ((gimple_assign_single_p (stmt)
    7228                 :           1 :                || (is_gimple_assign (stmt)
    7229                 :           1 :                    && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))
    7230                 :           0 :                        || gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR)))
    7231                 :        2034 :               && sprime == gimple_assign_rhs1 (stmt))
    7232                 :             :             return;
    7233                 :             : 
    7234                 :             :           /* Else replace its RHS.  */
    7235                 :         718 :           if (dump_file && (dump_flags & TDF_DETAILS))
    7236                 :             :             {
    7237                 :           0 :               fprintf (dump_file, "Replaced ");
    7238                 :           0 :               print_gimple_expr (dump_file, stmt, 0);
    7239                 :           0 :               fprintf (dump_file, " with ");
    7240                 :           0 :               print_generic_expr (dump_file, sprime);
    7241                 :           0 :               fprintf (dump_file, " in ");
    7242                 :           0 :               print_gimple_stmt (dump_file, stmt, 0);
    7243                 :             :             }
    7244                 :         718 :           eliminations++;
    7245                 :             : 
    7246                 :         718 :           bool can_make_abnormal_goto = (is_gimple_call (stmt)
    7247                 :         718 :                                          && stmt_can_make_abnormal_goto (stmt));
    7248                 :         718 :           gimple *orig_stmt = stmt;
    7249                 :         718 :           if (!useless_type_conversion_p (TREE_TYPE (lhs),
    7250                 :         718 :                                           TREE_TYPE (sprime)))
    7251                 :             :             {
    7252                 :             :               /* We preserve conversions to but not from function or method
    7253                 :             :                  types.  This asymmetry makes it necessary to re-instantiate
    7254                 :             :                  conversions here.  */
    7255                 :         716 :               if (POINTER_TYPE_P (TREE_TYPE (lhs))
    7256                 :         716 :                   && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (lhs))))
    7257                 :         716 :                 sprime = fold_convert (TREE_TYPE (lhs), sprime);
    7258                 :             :               else
    7259                 :           0 :                 gcc_unreachable ();
    7260                 :             :             }
    7261                 :         718 :           tree vdef = gimple_vdef (stmt);
    7262                 :         718 :           tree vuse = gimple_vuse (stmt);
    7263                 :         718 :           propagate_tree_value_into_stmt (gsi, sprime);
    7264                 :         718 :           stmt = gsi_stmt (*gsi);
    7265                 :         718 :           update_stmt (stmt);
    7266                 :             :           /* In case the VDEF on the original stmt was released, value-number
    7267                 :             :              it to the VUSE.  This is to make vuse_ssa_val able to skip
    7268                 :             :              released virtual operands.  */
    7269                 :        1436 :           if (vdef != gimple_vdef (stmt))
    7270                 :             :             {
    7271                 :           0 :               gcc_assert (SSA_NAME_IN_FREE_LIST (vdef));
    7272                 :           0 :               VN_INFO (vdef)->valnum = vuse;
    7273                 :             :             }
    7274                 :             : 
    7275                 :             :           /* If we removed EH side-effects from the statement, clean
    7276                 :             :              its EH information.  */
    7277                 :         718 :           if (maybe_clean_or_replace_eh_stmt (orig_stmt, stmt))
    7278                 :             :             {
    7279                 :           0 :               bitmap_set_bit (need_eh_cleanup,
    7280                 :           0 :                               gimple_bb (stmt)->index);
    7281                 :           0 :               if (dump_file && (dump_flags & TDF_DETAILS))
    7282                 :           0 :                 fprintf (dump_file, "  Removed EH side-effects.\n");
    7283                 :             :             }
    7284                 :             : 
    7285                 :             :           /* Likewise for AB side-effects.  */
    7286                 :         718 :           if (can_make_abnormal_goto
    7287                 :         718 :               && !stmt_can_make_abnormal_goto (stmt))
    7288                 :             :             {
    7289                 :           0 :               bitmap_set_bit (need_ab_cleanup,
    7290                 :           0 :                               gimple_bb (stmt)->index);
    7291                 :           0 :               if (dump_file && (dump_flags & TDF_DETAILS))
    7292                 :           0 :                 fprintf (dump_file, "  Removed AB side-effects.\n");
    7293                 :             :             }
    7294                 :             : 
    7295                 :         718 :           return;
    7296                 :             :         }
    7297                 :             :     }
    7298                 :             : 
    7299                 :             :   /* If the statement is a scalar store, see if the expression
    7300                 :             :      has the same value number as its rhs.  If so, the store is
    7301                 :             :      dead.  */
    7302                 :   342097070 :   if (gimple_assign_single_p (stmt)
    7303                 :   131028578 :       && !gimple_has_volatile_ops (stmt)
    7304                 :    55939516 :       && !is_gimple_reg (gimple_assign_lhs (stmt))
    7305                 :    28738608 :       && (TREE_CODE (gimple_assign_lhs (stmt)) != VAR_DECL
    7306                 :     2876923 :           || !DECL_HARD_REGISTER (gimple_assign_lhs (stmt)))
    7307                 :   370831669 :       && (TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME
    7308                 :    16447357 :           || is_gimple_min_invariant (gimple_assign_rhs1 (stmt))))
    7309                 :             :     {
    7310                 :    25600714 :       tree rhs = gimple_assign_rhs1 (stmt);
    7311                 :    25600714 :       vn_reference_t vnresult;
    7312                 :             :       /* ???  gcc.dg/torture/pr91445.c shows that we lookup a boolean
    7313                 :             :          typed load of a byte known to be 0x11 as 1 so a store of
    7314                 :             :          a boolean 1 is detected as redundant.  Because of this we
    7315                 :             :          have to make sure to lookup with a ref where its size
    7316                 :             :          matches the precision.  */
    7317                 :    25600714 :       tree lookup_lhs = lhs;
    7318                 :    50902312 :       if (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    7319                 :    13330846 :           && (TREE_CODE (lhs) != COMPONENT_REF
    7320                 :     8151555 :               || !DECL_BIT_FIELD_TYPE (TREE_OPERAND (lhs, 1)))
    7321                 :    38655155 :           && !type_has_mode_precision_p (TREE_TYPE (lhs)))
    7322                 :             :         {
    7323                 :      435029 :           if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
    7324                 :      444066 :               && TYPE_PRECISION (TREE_TYPE (lhs)) > MAX_FIXED_MODE_SIZE)
    7325                 :             :             lookup_lhs = NULL_TREE;
    7326                 :      428182 :           else if (TREE_CODE (lhs) == COMPONENT_REF
    7327                 :      428182 :                    || TREE_CODE (lhs) == MEM_REF)
    7328                 :             :             {
    7329                 :      298774 :               tree ltype = build_nonstandard_integer_type
    7330                 :      298774 :                                 (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (lhs))),
    7331                 :      298774 :                                  TYPE_UNSIGNED (TREE_TYPE (lhs)));
    7332                 :      298774 :               if (TREE_CODE (lhs) == COMPONENT_REF)
    7333                 :             :                 {
    7334                 :      227072 :                   tree foff = component_ref_field_offset (lhs);
    7335                 :      227072 :                   tree f = TREE_OPERAND (lhs, 1);
    7336                 :      227072 :                   if (!poly_int_tree_p (foff))
    7337                 :             :                     lookup_lhs = NULL_TREE;
    7338                 :             :                   else
    7339                 :      454144 :                     lookup_lhs = build3 (BIT_FIELD_REF, ltype,
    7340                 :      227072 :                                          TREE_OPERAND (lhs, 0),
    7341                 :      227072 :                                          TYPE_SIZE (TREE_TYPE (lhs)),
    7342                 :             :                                          bit_from_pos
    7343                 :      227072 :                                            (foff, DECL_FIELD_BIT_OFFSET (f)));
    7344                 :             :                 }
    7345                 :             :               else
    7346                 :       71702 :                 lookup_lhs = build2 (MEM_REF, ltype,
    7347                 :       71702 :                                      TREE_OPERAND (lhs, 0),
    7348                 :       71702 :                                      TREE_OPERAND (lhs, 1));
    7349                 :             :             }
    7350                 :             :           else
    7351                 :             :             lookup_lhs = NULL_TREE;
    7352                 :             :         }
    7353                 :    25464459 :       tree val = NULL_TREE;
    7354                 :    25464459 :       if (lookup_lhs)
    7355                 :    50928918 :         val = vn_reference_lookup (lookup_lhs, gimple_vuse (stmt),
    7356                 :             :                                    VN_WALKREWRITE, &vnresult, false,
    7357                 :             :                                    NULL, NULL_TREE, true);
    7358                 :    25600714 :       if (TREE_CODE (rhs) == SSA_NAME)
    7359                 :    12287242 :         rhs = VN_INFO (rhs)->valnum;
    7360                 :    25600714 :       if (val
    7361                 :    25600714 :           && (operand_equal_p (val, rhs, 0)
    7362                 :             :               /* Due to the bitfield lookups above we can get bit
    7363                 :             :                  interpretations of the same RHS as values here.  Those
    7364                 :             :                  are redundant as well.  */
    7365                 :     3106762 :               || (TREE_CODE (val) == SSA_NAME
    7366                 :     1906285 :                   && gimple_assign_single_p (SSA_NAME_DEF_STMT (val))
    7367                 :     1730709 :                   && (val = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (val)))
    7368                 :     1730709 :                   && TREE_CODE (val) == VIEW_CONVERT_EXPR
    7369                 :        3516 :                   && TREE_OPERAND (val, 0) == rhs)))
    7370                 :             :         {
    7371                 :             :           /* We can only remove the later store if the former aliases
    7372                 :             :              at least all accesses the later one does or if the store
    7373                 :             :              was to readonly memory storing the same value.  */
    7374                 :      218547 :           ao_ref lhs_ref;
    7375                 :      218547 :           ao_ref_init (&lhs_ref, lhs);
    7376                 :      218547 :           alias_set_type set = ao_ref_alias_set (&lhs_ref);
    7377                 :      218547 :           alias_set_type base_set = ao_ref_base_alias_set (&lhs_ref);
    7378                 :      218547 :           if (! vnresult
    7379                 :      218547 :               || ((vnresult->set == set
    7380                 :       29009 :                    || alias_set_subset_of (set, vnresult->set))
    7381                 :      214567 :                   && (vnresult->base_set == base_set
    7382                 :       10278 :                       || alias_set_subset_of (base_set, vnresult->base_set))))
    7383                 :             :             {
    7384                 :      211749 :               if (dump_file && (dump_flags & TDF_DETAILS))
    7385                 :             :                 {
    7386                 :          16 :                   fprintf (dump_file, "Deleted redundant store ");
    7387                 :          16 :                   print_gimple_stmt (dump_file, stmt, 0);
    7388                 :             :                 }
    7389                 :             : 
    7390                 :             :               /* Queue stmt for removal.  */
    7391                 :      211749 :               to_remove.safe_push (stmt);
    7392                 :      211749 :               return;
    7393                 :             :             }
    7394                 :             :         }
    7395                 :             :     }
    7396                 :             : 
    7397                 :             :   /* If this is a control statement value numbering left edges
    7398                 :             :      unexecuted on force the condition in a way consistent with
    7399                 :             :      that.  */
    7400                 :   341885321 :   if (gcond *cond = dyn_cast <gcond *> (stmt))
    7401                 :             :     {
    7402                 :    18937296 :       if ((EDGE_SUCC (b, 0)->flags & EDGE_EXECUTABLE)
    7403                 :    18937296 :           ^ (EDGE_SUCC (b, 1)->flags & EDGE_EXECUTABLE))
    7404                 :             :         {
    7405                 :      540001 :           if (dump_file && (dump_flags & TDF_DETAILS))
    7406                 :             :             {
    7407                 :          15 :               fprintf (dump_file, "Removing unexecutable edge from ");
    7408                 :          15 :               print_gimple_stmt (dump_file, stmt, 0);
    7409                 :             :             }
    7410                 :      540001 :           if (((EDGE_SUCC (b, 0)->flags & EDGE_TRUE_VALUE) != 0)
    7411                 :      540001 :               == ((EDGE_SUCC (b, 0)->flags & EDGE_EXECUTABLE) != 0))
    7412                 :      218681 :             gimple_cond_make_true (cond);
    7413                 :             :           else
    7414                 :      321320 :             gimple_cond_make_false (cond);
    7415                 :      540001 :           update_stmt (cond);
    7416                 :      540001 :           el_todo |= TODO_cleanup_cfg;
    7417                 :      540001 :           return;
    7418                 :             :         }
    7419                 :             :     }
    7420                 :             : 
    7421                 :   341345320 :   bool can_make_abnormal_goto = stmt_can_make_abnormal_goto (stmt);
    7422                 :   341345320 :   bool was_noreturn = (is_gimple_call (stmt)
    7423                 :   341345320 :                        && gimple_call_noreturn_p (stmt));
    7424                 :   341345320 :   tree vdef = gimple_vdef (stmt);
    7425                 :   341345320 :   tree vuse = gimple_vuse (stmt);
    7426                 :             : 
    7427                 :             :   /* If we didn't replace the whole stmt (or propagate the result
    7428                 :             :      into all uses), replace all uses on this stmt with their
    7429                 :             :      leaders.  */
    7430                 :   341345320 :   bool modified = false;
    7431                 :   341345320 :   use_operand_p use_p;
    7432                 :   341345320 :   ssa_op_iter iter;
    7433                 :   505895571 :   FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
    7434                 :             :     {
    7435                 :   164550251 :       tree use = USE_FROM_PTR (use_p);
    7436                 :             :       /* ???  The call code above leaves stmt operands un-updated.  */
    7437                 :   164550251 :       if (TREE_CODE (use) != SSA_NAME)
    7438                 :           0 :         continue;
    7439                 :   164550251 :       tree sprime;
    7440                 :   164550251 :       if (SSA_NAME_IS_DEFAULT_DEF (use))
    7441                 :             :         /* ???  For default defs BB shouldn't matter, but we have to
    7442                 :             :            solve the inconsistency between rpo eliminate and
    7443                 :             :            dom eliminate avail valueization first.  */
    7444                 :    26902487 :         sprime = eliminate_avail (b, use);
    7445                 :             :       else
    7446                 :             :         /* Look for sth available at the definition block of the argument.
    7447                 :             :            This avoids inconsistencies between availability there which
    7448                 :             :            decides if the stmt can be removed and availability at the
    7449                 :             :            use site.  The SSA property ensures that things available
    7450                 :             :            at the definition are also available at uses.  */
    7451                 :   137647764 :         sprime = eliminate_avail (gimple_bb (SSA_NAME_DEF_STMT (use)), use);
    7452                 :   164550251 :       if (sprime && sprime != use
    7453                 :    12327660 :           && may_propagate_copy (use, sprime, true)
    7454                 :             :           /* We substitute into debug stmts to avoid excessive
    7455                 :             :              debug temporaries created by removed stmts, but we need
    7456                 :             :              to avoid doing so for inserted sprimes as we never want
    7457                 :             :              to create debug temporaries for them.  */
    7458                 :   176877195 :           && (!inserted_exprs
    7459                 :     1186619 :               || TREE_CODE (sprime) != SSA_NAME
    7460                 :     1165704 :               || !is_gimple_debug (stmt)
    7461                 :      353882 :               || !bitmap_bit_p (inserted_exprs, SSA_NAME_VERSION (sprime))))
    7462                 :             :         {
    7463                 :    11998993 :           propagate_value (use_p, sprime);
    7464                 :    11998993 :           modified = true;
    7465                 :             :         }
    7466                 :             :     }
    7467                 :             : 
    7468                 :             :   /* Fold the stmt if modified, this canonicalizes MEM_REFs we propagated
    7469                 :             :      into which is a requirement for the IPA devirt machinery.  */
    7470                 :   341345320 :   gimple *old_stmt = stmt;
    7471                 :   341345320 :   if (modified)
    7472                 :             :     {
    7473                 :             :       /* If a formerly non-invariant ADDR_EXPR is turned into an
    7474                 :             :          invariant one it was on a separate stmt.  */
    7475                 :    11149989 :       if (gimple_assign_single_p (stmt)
    7476                 :    11149989 :           && TREE_CODE (gimple_assign_rhs1 (stmt)) == ADDR_EXPR)
    7477                 :      252150 :         recompute_tree_invariant_for_addr_expr (gimple_assign_rhs1 (stmt));
    7478                 :    11149989 :       gimple_stmt_iterator prev = *gsi;
    7479                 :    11149989 :       gsi_prev (&prev);
    7480                 :    11149989 :       if (fold_stmt (gsi, follow_all_ssa_edges))
    7481                 :             :         {
    7482                 :             :           /* fold_stmt may have created new stmts inbetween
    7483                 :             :              the previous stmt and the folded stmt.  Mark
    7484                 :             :              all defs created there as varying to not confuse
    7485                 :             :              the SCCVN machinery as we're using that even during
    7486                 :             :              elimination.  */
    7487                 :      949078 :           if (gsi_end_p (prev))
    7488                 :      217752 :             prev = gsi_start_bb (b);
    7489                 :             :           else
    7490                 :      840202 :             gsi_next (&prev);
    7491                 :      949078 :           if (gsi_stmt (prev) != gsi_stmt (*gsi))
    7492                 :       82396 :             do
    7493                 :             :               {
    7494                 :       51116 :                 tree def;
    7495                 :       51116 :                 ssa_op_iter dit;
    7496                 :       98416 :                 FOR_EACH_SSA_TREE_OPERAND (def, gsi_stmt (prev),
    7497                 :             :                                            dit, SSA_OP_ALL_DEFS)
    7498                 :             :                     /* As existing DEFs may move between stmts
    7499                 :             :                        only process new ones.  */
    7500                 :       47300 :                     if (! has_VN_INFO (def))
    7501                 :             :                       {
    7502                 :       31178 :                         vn_ssa_aux_t vn_info = VN_INFO (def);
    7503                 :       31178 :                         vn_info->valnum = def;
    7504                 :       31178 :                         vn_info->visited = true;
    7505                 :             :                       }
    7506                 :       51116 :                 if (gsi_stmt (prev) == gsi_stmt (*gsi))
    7507                 :             :                   break;
    7508                 :       31280 :                 gsi_next (&prev);
    7509                 :       31280 :               }
    7510                 :             :             while (1);
    7511                 :             :         }
    7512                 :    11149989 :       stmt = gsi_stmt (*gsi);
    7513                 :             :       /* In case we folded the stmt away schedule the NOP for removal.  */
    7514                 :    11149989 :       if (gimple_nop_p (stmt))
    7515                 :         808 :         to_remove.safe_push (stmt);
    7516                 :             :     }
    7517                 :             : 
    7518                 :             :   /* Visit indirect calls and turn them into direct calls if
    7519                 :             :      possible using the devirtualization machinery.  Do this before
    7520                 :             :      checking for required EH/abnormal/noreturn cleanup as devird
    7521                 :             :      may expose more of those.  */
    7522                 :   341345320 :   if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
    7523                 :             :     {
    7524                 :    22177249 :       tree fn = gimple_call_fn (call_stmt);
    7525                 :    22177249 :       if (fn
    7526                 :    21635766 :           && flag_devirtualize
    7527                 :    43084802 :           && virtual_method_call_p (fn))
    7528                 :             :         {
    7529                 :      206691 :           tree otr_type = obj_type_ref_class (fn);
    7530                 :      206691 :           unsigned HOST_WIDE_INT otr_tok
    7531                 :      206691 :               = tree_to_uhwi (OBJ_TYPE_REF_TOKEN (fn));
    7532                 :      206691 :           tree instance;
    7533                 :      206691 :           ipa_polymorphic_call_context context (current_function_decl,
    7534                 :      206691 :                                                 fn, stmt, &instance);
    7535                 :      206691 :           context.get_dynamic_type (instance, OBJ_TYPE_REF_OBJECT (fn),
    7536                 :             :                                     otr_type, stmt, NULL);
    7537                 :      206691 :           bool final;
    7538                 :      206691 :           vec <cgraph_node *> targets
    7539                 :      206691 :               = possible_polymorphic_call_targets (obj_type_ref_class (fn),
    7540                 :             :                                                    otr_tok, context, &final);
    7541                 :      206691 :           if (dump_file)
    7542                 :          22 :             dump_possible_polymorphic_call_targets (dump_file,
    7543                 :             :                                                     obj_type_ref_class (fn),
    7544                 :             :                                                     otr_tok, context);
    7545                 :      206995 :           if (final && targets.length () <= 1 && dbg_cnt (devirt))
    7546                 :             :             {
    7547                 :         103 :               tree fn;
    7548                 :         103 :               if (targets.length () == 1)
    7549                 :         103 :                 fn = targets[0]->decl;
    7550                 :             :               else
    7551                 :           0 :                 fn = builtin_decl_unreachable ();
    7552                 :         103 :               if (dump_enabled_p ())
    7553                 :             :                 {
    7554                 :           9 :                   dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, stmt,
    7555                 :             :                                    "converting indirect call to "
    7556                 :             :                                    "function %s\n",
    7557                 :           9 :                                    lang_hooks.decl_printable_name (fn, 2));
    7558                 :             :                 }
    7559                 :         103 :               gimple_call_set_fndecl (call_stmt, fn);
    7560                 :             :               /* If changing the call to __builtin_unreachable
    7561                 :             :                  or similar noreturn function, adjust gimple_call_fntype
    7562                 :             :                  too.  */
    7563                 :         103 :               if (gimple_call_noreturn_p (call_stmt)
    7564                 :           0 :                   && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fn)))
    7565                 :           0 :                   && TYPE_ARG_TYPES (TREE_TYPE (fn))
    7566                 :         103 :                   && (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fn)))
    7567                 :           0 :                       == void_type_node))
    7568                 :           0 :                 gimple_call_set_fntype (call_stmt, TREE_TYPE (fn));
    7569                 :         103 :               maybe_remove_unused_call_args (cfun, call_stmt);
    7570                 :         103 :               modified = true;
    7571                 :             :             }
    7572                 :             :         }
    7573                 :             :     }
    7574                 :             : 
    7575                 :   341345320 :   if (modified)
    7576                 :             :     {
    7577                 :             :       /* When changing a call into a noreturn call, cfg cleanup
    7578                 :             :          is needed to fix up the noreturn call.  */
    7579                 :    11150010 :       if (!was_noreturn
    7580                 :    11150010 :           && is_gimple_call (stmt) && gimple_call_noreturn_p (stmt))
    7581                 :          56 :         to_fixup.safe_push  (stmt);
    7582                 :             :       /* When changing a condition or switch into one we know what
    7583                 :             :          edge will be executed, schedule a cfg cleanup.  */
    7584                 :    11150010 :       if ((gimple_code (stmt) == GIMPLE_COND
    7585                 :     1463925 :            && (gimple_cond_true_p (as_a <gcond *> (stmt))
    7586                 :     1457694 :                || gimple_cond_false_p (as_a <gcond *> (stmt))))
    7587                 :    12606467 :           || (gimple_code (stmt) == GIMPLE_SWITCH
    7588                 :        8759 :               && TREE_CODE (gimple_switch_index
    7589                 :             :                             (as_a <gswitch *> (stmt))) == INTEGER_CST))
    7590                 :        9311 :         el_todo |= TODO_cleanup_cfg;
    7591                 :             :       /* If we removed EH side-effects from the statement, clean
    7592                 :             :          its EH information.  */
    7593                 :    11150010 :       if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
    7594                 :             :         {
    7595                 :        1640 :           bitmap_set_bit (need_eh_cleanup,
    7596                 :        1640 :                           gimple_bb (stmt)->index);
    7597                 :        1640 :           if (dump_file && (dump_flags & TDF_DETAILS))
    7598                 :           0 :             fprintf (dump_file, "  Removed EH side-effects.\n");
    7599                 :             :         }
    7600                 :             :       /* Likewise for AB side-effects.  */
    7601                 :    11150010 :       if (can_make_abnormal_goto
    7602                 :    11150010 :           && !stmt_can_make_abnormal_goto (stmt))
    7603                 :             :         {
    7604                 :           0 :           bitmap_set_bit (need_ab_cleanup,
    7605                 :           0 :                           gimple_bb (stmt)->index);
    7606                 :           0 :           if (dump_file && (dump_flags & TDF_DETAILS))
    7607                 :           0 :             fprintf (dump_file, "  Removed AB side-effects.\n");
    7608                 :             :         }
    7609                 :    11150010 :       update_stmt (stmt);
    7610                 :             :       /* In case the VDEF on the original stmt was released, value-number
    7611                 :             :          it to the VUSE.  This is to make vuse_ssa_val able to skip
    7612                 :             :          released virtual operands.  */
    7613                 :    14368352 :       if (vdef && SSA_NAME_IN_FREE_LIST (vdef))
    7614                 :        1847 :         VN_INFO (vdef)->valnum = vuse;
    7615                 :             :     }
    7616                 :             : 
    7617                 :             :   /* Make new values available - for fully redundant LHS we
    7618                 :             :      continue with the next stmt above and skip this.
    7619                 :             :      But avoid picking up dead defs.  */
    7620                 :   341345320 :   tree def;
    7621                 :   411645670 :   FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_DEF)
    7622                 :    70300350 :     if (! has_zero_uses (def)
    7623                 :    70300350 :         || (inserted_exprs
    7624                 :      212269 :             && bitmap_bit_p (inserted_exprs, SSA_NAME_VERSION (def))))
    7625                 :    68961059 :       eliminate_push_avail (b, def);
    7626                 :             : }
    7627                 :             : 
    7628                 :             : /* Perform elimination for the basic-block B during the domwalk.  */
    7629                 :             : 
    7630                 :             : edge
    7631                 :    42108906 : eliminate_dom_walker::before_dom_children (basic_block b)
    7632                 :             : {
    7633                 :             :   /* Mark new bb.  */
    7634                 :    42108906 :   avail_stack.safe_push (NULL_TREE);
    7635                 :             : 
    7636                 :             :   /* Skip unreachable blocks marked unreachable during the SCCVN domwalk.  */
    7637                 :    42108906 :   if (!(b->flags & BB_EXECUTABLE))
    7638                 :             :     return NULL;
    7639                 :             : 
    7640                 :    37321824 :   vn_context_bb = b;
    7641                 :             : 
    7642                 :    49403212 :   for (gphi_iterator gsi = gsi_start_phis (b); !gsi_end_p (gsi);)
    7643                 :             :     {
    7644                 :    12081388 :       gphi *phi = gsi.phi ();
    7645                 :    12081388 :       tree res = PHI_RESULT (phi);
    7646                 :             : 
    7647                 :    24162776 :       if (virtual_operand_p (res))
    7648                 :             :         {
    7649                 :     5620899 :           gsi_next (&gsi);
    7650                 :     5620899 :           continue;
    7651                 :             :         }
    7652                 :             : 
    7653                 :     6460489 :       tree sprime = eliminate_avail (b, res);
    7654                 :     6460489 :       if (sprime
    7655                 :     6460489 :           && sprime != res)
    7656                 :             :         {
    7657                 :      512934 :           if (dump_file && (dump_flags & TDF_DETAILS))
    7658                 :             :             {
    7659                 :          22 :               fprintf (dump_file, "Replaced redundant PHI node defining ");
    7660                 :          22 :               print_generic_expr (dump_file, res);
    7661                 :          22 :               fprintf (dump_file, " with ");
    7662                 :          22 :               print_generic_expr (dump_file, sprime);
    7663                 :          22 :               fprintf (dump_file, "\n");
    7664                 :             :             }
    7665                 :             : 
    7666                 :             :           /* If we inserted this PHI node ourself, it's not an elimination.  */
    7667                 :      512934 :           if (! inserted_exprs
    7668                 :      627728 :               || ! bitmap_bit_p (inserted_exprs, SSA_NAME_VERSION (res)))
    7669                 :      483653 :             eliminations++;
    7670                 :             : 
    7671                 :             :           /* If we will propagate into all uses don't bother to do
    7672                 :             :              anything.  */
    7673                 :      512934 :           if (may_propagate_copy (res, sprime))
    7674                 :             :             {
    7675                 :             :               /* Mark the PHI for removal.  */
    7676                 :      512934 :               to_remove.safe_push (phi);
    7677                 :      512934 :               gsi_next (&gsi);
    7678                 :      512934 :               continue;
    7679                 :             :             }
    7680                 :             : 
    7681                 :           0 :           remove_phi_node (&gsi, false);
    7682                 :             : 
    7683                 :           0 :           if (!useless_type_conversion_p (TREE_TYPE (res), TREE_TYPE (sprime)))
    7684                 :           0 :             sprime = fold_convert (TREE_TYPE (res), sprime);
    7685                 :           0 :           gimple *stmt = gimple_build_assign (res, sprime);
    7686                 :           0 :           gimple_stmt_iterator gsi2 = gsi_after_labels (b);
    7687                 :           0 :           gsi_insert_before (&gsi2, stmt, GSI_NEW_STMT);
    7688                 :           0 :           continue;
    7689                 :           0 :         }
    7690                 :             : 
    7691                 :     5947555 :       eliminate_push_avail (b, res);
    7692                 :     5947555 :       gsi_next (&gsi);
    7693                 :             :     }
    7694                 :             : 
    7695                 :    74643648 :   for (gimple_stmt_iterator gsi = gsi_start_bb (b);
    7696                 :   286008124 :        !gsi_end_p (gsi);
    7697                 :   248686300 :        gsi_next (&gsi))
    7698                 :   248686300 :     eliminate_stmt (b, &gsi);
    7699                 :             : 
    7700                 :             :   /* Replace destination PHI arguments.  */
    7701                 :    37321824 :   edge_iterator ei;
    7702                 :    37321824 :   edge e;
    7703                 :    88009833 :   FOR_EACH_EDGE (e, ei, b->succs)
    7704                 :    50688009 :     if (e->flags & EDGE_EXECUTABLE)
    7705                 :    50210855 :       for (gphi_iterator gsi = gsi_start_phis (e->dest);
    7706                 :    80497404 :            !gsi_end_p (gsi);
    7707                 :    30286549 :            gsi_next (&gsi))
    7708                 :             :         {
    7709                 :    30286549 :           gphi *phi = gsi.phi ();
    7710                 :    30286549 :           use_operand_p use_p = PHI_ARG_DEF_PTR_FROM_EDGE (phi, e);
    7711                 :    30286549 :           tree arg = USE_FROM_PTR (use_p);
    7712                 :    50142538 :           if (TREE_CODE (arg) != SSA_NAME
    7713                 :    30286549 :               || virtual_operand_p (arg))
    7714                 :    19855989 :             continue;
    7715                 :    10430560 :           tree sprime = eliminate_avail (b, arg);
    7716                 :    20861120 :           if (sprime && may_propagate_copy (arg, sprime,
    7717                 :    10430560 :                                             !(e->flags & EDGE_ABNORMAL)))
    7718                 :    10419258 :             propagate_value (use_p, sprime);
    7719                 :             :         }
    7720                 :             : 
    7721                 :    37321824 :   vn_context_bb = NULL;
    7722                 :             : 
    7723                 :    37321824 :   return NULL;
    7724                 :             : }
    7725                 :             : 
    7726                 :             : /* Make no longer available leaders no longer available.  */
    7727                 :             : 
    7728                 :             : void
    7729                 :    42108906 : eliminate_dom_walker::after_dom_children (basic_block)
    7730                 :             : {
    7731                 :    42108906 :   tree entry;
    7732                 :    92751904 :   while ((entry = avail_stack.pop ()) != NULL_TREE)
    7733                 :             :     {
    7734                 :    50642998 :       tree valnum = VN_INFO (entry)->valnum;
    7735                 :    50642998 :       tree old = avail[SSA_NAME_VERSION (valnum)];
    7736                 :    50642998 :       if (old == entry)
    7737                 :    50599708 :         avail[SSA_NAME_VERSION (valnum)] = NULL_TREE;
    7738                 :             :       else
    7739                 :       43290 :         avail[SSA_NAME_VERSION (valnum)] = entry;
    7740                 :             :     }
    7741                 :    42108906 : }
    7742                 :             : 
    7743                 :             : /* Remove queued stmts and perform delayed cleanups.  */
    7744                 :             : 
    7745                 :             : unsigned
    7746                 :     6185483 : eliminate_dom_walker::eliminate_cleanup (bool region_p)
    7747                 :             : {
    7748                 :     6185483 :   statistics_counter_event (cfun, "Eliminated", eliminations);
    7749                 :     6185483 :   statistics_counter_event (cfun, "Insertions", insertions);
    7750                 :             : 
    7751                 :             :   /* We cannot remove stmts during BB walk, especially not release SSA
    7752                 :             :      names there as this confuses the VN machinery.  The stmts ending
    7753                 :             :      up in to_remove are either stores or simple copies.
    7754                 :             :      Remove stmts in reverse order to make debug stmt creation possible.  */
    7755                 :    33207208 :   while (!to_remove.is_empty ())
    7756                 :             :     {
    7757                 :    14650703 :       bool do_release_defs = true;
    7758                 :    14650703 :       gimple *stmt = to_remove.pop ();
    7759                 :             : 
    7760                 :             :       /* When we are value-numbering a region we do not require exit PHIs to
    7761                 :             :          be present so we have to make sure to deal with uses outside of the
    7762                 :             :          region of stmts that we thought are eliminated.
    7763                 :             :          ??? Note we may be confused by uses in dead regions we didn't run
    7764                 :             :          elimination on.  Rather than checking individual uses we accept
    7765                 :             :          dead copies to be generated here (gcc.c-torture/execute/20060905-1.c
    7766                 :             :          contains such example).  */
    7767                 :    14650703 :       if (region_p)
    7768                 :             :         {
    7769                 :     1661221 :           if (gphi *phi = dyn_cast <gphi *> (stmt))
    7770                 :             :             {
    7771                 :     1083870 :               tree lhs = gimple_phi_result (phi);
    7772                 :     1083870 :               if (!has_zero_uses (lhs))
    7773                 :             :                 {
    7774                 :       20827 :                   if (dump_file && (dump_flags & TDF_DETAILS))
    7775                 :           3 :                     fprintf (dump_file, "Keeping eliminated stmt live "
    7776                 :             :                              "as copy because of out-of-region uses\n");
    7777                 :       20827 :                   tree sprime = eliminate_avail (gimple_bb (stmt), lhs);
    7778                 :       20827 :                   gimple *copy = gimple_build_assign (lhs, sprime);
    7779                 :       20827 :                   gimple_stmt_iterator gsi
    7780                 :       20827 :                     = gsi_after_labels (gimple_bb (stmt));
    7781                 :       20827 :                   gsi_insert_before (&gsi, copy, GSI_SAME_STMT);
    7782                 :       20827 :                   do_release_defs = false;
    7783                 :             :                 }
    7784                 :             :             }
    7785                 :      577351 :           else if (tree lhs = gimple_get_lhs (stmt))
    7786                 :      577351 :             if (TREE_CODE (lhs) == SSA_NAME
    7787                 :      577351 :                 && !has_zero_uses (lhs))
    7788                 :             :               {
    7789                 :        1064 :                 if (dump_file && (dump_flags & TDF_DETAILS))
    7790                 :           0 :                   fprintf (dump_file, "Keeping eliminated stmt live "
    7791                 :             :                            "as copy because of out-of-region uses\n");
    7792                 :        1064 :                 tree sprime = eliminate_avail (gimple_bb (stmt), lhs);
    7793                 :        1064 :                 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    7794                 :        1064 :                 if (is_gimple_assign (stmt))
    7795                 :             :                   {
    7796                 :        1064 :                     gimple_assign_set_rhs_from_tree (&gsi, sprime);
    7797                 :        1064 :                     stmt = gsi_stmt (gsi);
    7798                 :        1064 :                     update_stmt (stmt);
    7799                 :        1064 :                     if (maybe_clean_or_replace_eh_stmt (stmt, stmt))
    7800                 :           0 :                       bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index);
    7801                 :        1064 :                     continue;
    7802                 :             :                   }
    7803                 :             :                 else
    7804                 :             :                   {
    7805                 :           0 :                     gimple *copy = gimple_build_assign (lhs, sprime);
    7806                 :           0 :                     gsi_insert_before (&gsi, copy, GSI_SAME_STMT);
    7807                 :           0 :                     do_release_defs = false;
    7808                 :             :                   }
    7809                 :             :               }
    7810                 :             :         }
    7811                 :             : 
    7812                 :    14649639 :       if (dump_file && (dump_flags & TDF_DETAILS))
    7813                 :             :         {
    7814                 :       20670 :           fprintf (dump_file, "Removing dead stmt ");
    7815                 :       20670 :           print_gimple_stmt (dump_file, stmt, 0, TDF_NONE);
    7816                 :             :         }
    7817                 :             : 
    7818                 :    14649639 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    7819                 :    14649639 :       if (gimple_code (stmt) == GIMPLE_PHI)
    7820                 :     1789899 :         remove_phi_node (&gsi, do_release_defs);
    7821                 :             :       else
    7822                 :             :         {
    7823                 :    12859740 :           basic_block bb = gimple_bb (stmt);
    7824                 :    12859740 :           unlink_stmt_vdef (stmt);
    7825                 :    12859740 :           if (gsi_remove (&gsi, true))
    7826                 :       26508 :             bitmap_set_bit (need_eh_cleanup, bb->index);
    7827                 :    12859740 :           if (is_gimple_call (stmt) && stmt_can_make_abnormal_goto (stmt))
    7828                 :           2 :             bitmap_set_bit (need_ab_cleanup, bb->index);
    7829                 :    12859740 :           if (do_release_defs)
    7830                 :    12859740 :             release_defs (stmt);
    7831                 :             :         }
    7832                 :             : 
    7833                 :             :       /* Removing a stmt may expose a forwarder block.  */
    7834                 :    14649639 :       el_todo |= TODO_cleanup_cfg;
    7835                 :             :     }
    7836                 :             : 
    7837                 :             :   /* Fixup stmts that became noreturn calls.  This may require splitting
    7838                 :             :      blocks and thus isn't possible during the dominator walk.  Do this
    7839                 :             :      in reverse order so we don't inadvertedly remove a stmt we want to
    7840                 :             :      fixup by visiting a dominating now noreturn call first.  */
    7841                 :     6185539 :   while (!to_fixup.is_empty ())
    7842                 :             :     {
    7843                 :          56 :       gimple *stmt = to_fixup.pop ();
    7844                 :             : 
    7845                 :          56 :       if (dump_file && (dump_flags & TDF_DETAILS))
    7846                 :             :         {
    7847                 :           0 :           fprintf (dump_file, "Fixing up noreturn call ");
    7848                 :           0 :           print_gimple_stmt (dump_file, stmt, 0);
    7849                 :             :         }
    7850                 :             : 
    7851                 :          56 :       if (fixup_noreturn_call (stmt))
    7852                 :          56 :         el_todo |= TODO_cleanup_cfg;
    7853                 :             :     }
    7854                 :             : 
    7855                 :     6185483 :   bool do_eh_cleanup = !bitmap_empty_p (need_eh_cleanup);
    7856                 :     6185483 :   bool do_ab_cleanup = !bitmap_empty_p (need_ab_cleanup);
    7857                 :             : 
    7858                 :     6185483 :   if (do_eh_cleanup)
    7859                 :       10703 :     gimple_purge_all_dead_eh_edges (need_eh_cleanup);
    7860                 :             : 
    7861                 :     6185483 :   if (do_ab_cleanup)
    7862                 :           2 :     gimple_purge_all_dead_abnormal_call_edges (need_ab_cleanup);
    7863                 :             : 
    7864                 :     6185483 :   if (do_eh_cleanup || do_ab_cleanup)
    7865                 :       10705 :     el_todo |= TODO_cleanup_cfg;
    7866                 :             : 
    7867                 :     6185483 :   return el_todo;
    7868                 :             : }
    7869                 :             : 
    7870                 :             : /* Eliminate fully redundant computations.  */
    7871                 :             : 
    7872                 :             : unsigned
    7873                 :     4340032 : eliminate_with_rpo_vn (bitmap inserted_exprs)
    7874                 :             : {
    7875                 :     4340032 :   eliminate_dom_walker walker (CDI_DOMINATORS, inserted_exprs);
    7876                 :             : 
    7877                 :     4340032 :   eliminate_dom_walker *saved_rpo_avail = rpo_avail;
    7878                 :     4340032 :   rpo_avail = &walker;
    7879                 :     4340032 :   walker.walk (cfun->cfg->x_entry_block_ptr);
    7880                 :     4340032 :   rpo_avail = saved_rpo_avail;
    7881                 :             : 
    7882                 :     4340032 :   return walker.eliminate_cleanup ();
    7883                 :     4340032 : }
    7884                 :             : 
    7885                 :             : static unsigned
    7886                 :             : do_rpo_vn_1 (function *fn, edge entry, bitmap exit_bbs,
    7887                 :             :              bool iterate, bool eliminate, bool skip_entry_phis,
    7888                 :             :              vn_lookup_kind kind);
    7889                 :             : 
    7890                 :             : void
    7891                 :      966333 : run_rpo_vn (vn_lookup_kind kind)
    7892                 :             : {
    7893                 :      966333 :   do_rpo_vn_1 (cfun, NULL, NULL, true, false, false, kind);
    7894                 :             : 
    7895                 :             :   /* ???  Prune requirement of these.  */
    7896                 :      966333 :   constant_to_value_id = new hash_table<vn_constant_hasher> (23);
    7897                 :             : 
    7898                 :             :   /* Initialize the value ids and prune out remaining VN_TOPs
    7899                 :             :      from dead code.  */
    7900                 :      966333 :   tree name;
    7901                 :      966333 :   unsigned i;
    7902                 :    47617361 :   FOR_EACH_SSA_NAME (i, name, cfun)
    7903                 :             :     {
    7904                 :    34397110 :       vn_ssa_aux_t info = VN_INFO (name);
    7905                 :    34397110 :       if (!info->visited
    7906                 :    34318011 :           || info->valnum == VN_TOP)
    7907                 :       79099 :         info->valnum = name;
    7908                 :    34397110 :       if (info->valnum == name)
    7909                 :    33209753 :         info->value_id = get_next_value_id ();
    7910                 :     1187357 :       else if (is_gimple_min_invariant (info->valnum))
    7911                 :       44901 :         info->value_id = get_or_alloc_constant_value_id (info->valnum);
    7912                 :             :     }
    7913                 :             : 
    7914                 :             :   /* Propagate.  */
    7915                 :    47617361 :   FOR_EACH_SSA_NAME (i, name, cfun)
    7916                 :             :     {
    7917                 :    34397110 :       vn_ssa_aux_t info = VN_INFO (name);
    7918                 :    34397110 :       if (TREE_CODE (info->valnum) == SSA_NAME
    7919                 :    34352209 :           && info->valnum != name
    7920                 :    35539566 :           && info->value_id != VN_INFO (info->valnum)->value_id)
    7921                 :     1142456 :         info->value_id = VN_INFO (info->valnum)->value_id;
    7922                 :             :     }
    7923                 :             : 
    7924                 :      966333 :   set_hashtable_value_ids ();
    7925                 :             : 
    7926                 :      966333 :   if (dump_file && (dump_flags & TDF_DETAILS))
    7927                 :             :     {
    7928                 :          14 :       fprintf (dump_file, "Value numbers:\n");
    7929                 :         407 :       FOR_EACH_SSA_NAME (i, name, cfun)
    7930                 :             :         {
    7931                 :         308 :           if (VN_INFO (name)->visited
    7932                 :         308 :               && SSA_VAL (name) != name)
    7933                 :             :             {
    7934                 :          33 :               print_generic_expr (dump_file, name);
    7935                 :          33 :               fprintf (dump_file, " = ");
    7936                 :          33 :               print_generic_expr (dump_file, SSA_VAL (name));
    7937                 :          33 :               fprintf (dump_file, " (%04d)\n", VN_INFO (name)->value_id);
    7938                 :             :             }
    7939                 :             :         }
    7940                 :             :     }
    7941                 :      966333 : }
    7942                 :             : 
    7943                 :             : /* Free VN associated data structures.  */
    7944                 :             : 
    7945                 :             : void
    7946                 :     6204819 : free_rpo_vn (void)
    7947                 :             : {
    7948                 :     6204819 :   free_vn_table (valid_info);
    7949                 :     6204819 :   XDELETE (valid_info);
    7950                 :     6204819 :   obstack_free (&vn_tables_obstack, NULL);
    7951                 :     6204819 :   obstack_free (&vn_tables_insert_obstack, NULL);
    7952                 :             : 
    7953                 :     6204819 :   vn_ssa_aux_iterator_type it;
    7954                 :     6204819 :   vn_ssa_aux_t info;
    7955                 :   354870329 :   FOR_EACH_HASH_TABLE_ELEMENT (*vn_ssa_aux_hash, info, vn_ssa_aux_t, it)
    7956                 :   174332755 :     if (info->needs_insertion)
    7957                 :     4049489 :       release_ssa_name (info->name);
    7958                 :     6204819 :   obstack_free (&vn_ssa_aux_obstack, NULL);
    7959                 :     6204819 :   delete vn_ssa_aux_hash;
    7960                 :             : 
    7961                 :     6204819 :   delete constant_to_value_id;
    7962                 :     6204819 :   constant_to_value_id = NULL;
    7963                 :     6204819 : }
    7964                 :             : 
    7965                 :             : /* Hook for maybe_push_res_to_seq, lookup the expression in the VN tables.  */
    7966                 :             : 
    7967                 :             : static tree
    7968                 :    22935176 : vn_lookup_simplify_result (gimple_match_op *res_op)
    7969                 :             : {
    7970                 :    22935176 :   if (!res_op->code.is_tree_code ())
    7971                 :             :     return NULL_TREE;
    7972                 :    22931701 :   tree *ops = res_op->ops;
    7973                 :    22931701 :   unsigned int length = res_op->num_ops;
    7974                 :    22931701 :   if (res_op->code == CONSTRUCTOR
    7975                 :             :       /* ???  We're arriving here with SCCVNs view, decomposed CONSTRUCTOR
    7976                 :             :          and GIMPLEs / match-and-simplifies, CONSTRUCTOR as GENERIC tree.  */
    7977                 :    22931701 :       && TREE_CODE (res_op->ops[0]) == CONSTRUCTOR)
    7978                 :             :     {
    7979                 :        1195 :       length = CONSTRUCTOR_NELTS (res_op->ops[0]);
    7980                 :        1195 :       ops = XALLOCAVEC (tree, length);
    7981                 :        5897 :       for (unsigned i = 0; i < length; ++i)
    7982                 :        4702 :         ops[i] = CONSTRUCTOR_ELT (res_op->ops[0], i)->value;
    7983                 :             :     }
    7984                 :    22931701 :   vn_nary_op_t vnresult = NULL;
    7985                 :    22931701 :   tree res = vn_nary_op_lookup_pieces (length, (tree_code) res_op->code,
    7986                 :             :                                        res_op->type, ops, &vnresult);
    7987                 :             :   /* If this is used from expression simplification make sure to
    7988                 :             :      return an available expression.  */
    7989                 :    22931701 :   if (res && TREE_CODE (res) == SSA_NAME && mprts_hook && rpo_avail)
    7990                 :     2158733 :     res = rpo_avail->eliminate_avail (vn_context_bb, res);
    7991                 :             :   return res;
    7992                 :             : }
    7993                 :             : 
    7994                 :             : /* Return a leader for OPs value that is valid at BB.  */
    7995                 :             : 
    7996                 :             : tree
    7997                 :   258580082 : rpo_elim::eliminate_avail (basic_block bb, tree op)
    7998                 :             : {
    7999                 :   258580082 :   bool visited;
    8000                 :   258580082 :   tree valnum = SSA_VAL (op, &visited);
    8001                 :             :   /* If we didn't visit OP then it must be defined outside of the
    8002                 :             :      region we process and also dominate it.  So it is available.  */
    8003                 :   258580082 :   if (!visited)
    8004                 :             :     return op;
    8005                 :   256440869 :   if (TREE_CODE (valnum) == SSA_NAME)
    8006                 :             :     {
    8007                 :   242695951 :       if (SSA_NAME_IS_DEFAULT_DEF (valnum))
    8008                 :             :         return valnum;
    8009                 :   235911037 :       vn_ssa_aux_t valnum_info = VN_INFO (valnum);
    8010                 :   235911037 :       vn_avail *av = valnum_info->avail;
    8011                 :   235911037 :       if (!av)
    8012                 :             :         {
    8013                 :             :           /* See above.  But when there's availability info prefer
    8014                 :             :              what we recorded there for example to preserve LC SSA.  */
    8015                 :    83720961 :           if (!valnum_info->visited)
    8016                 :             :             return valnum;
    8017                 :             :           return NULL_TREE;
    8018                 :             :         }
    8019                 :   152190076 :       if (av->location == bb->index)
    8020                 :             :         /* On tramp3d 90% of the cases are here.  */
    8021                 :   101357533 :         return ssa_name (av->leader);
    8022                 :    64741292 :       do
    8023                 :             :         {
    8024                 :    64741292 :           basic_block abb = BASIC_BLOCK_FOR_FN (cfun, av->location);
    8025                 :             :           /* ???  During elimination we have to use availability at the
    8026                 :             :              definition site of a use we try to replace.  This
    8027                 :             :              is required to not run into inconsistencies because
    8028                 :             :              of dominated_by_p_w_unex behavior and removing a definition
    8029                 :             :              while not replacing all uses.
    8030                 :             :              ???  We could try to consistently walk dominators
    8031                 :             :              ignoring non-executable regions.  The nearest common
    8032                 :             :              dominator of bb and abb is where we can stop walking.  We
    8033                 :             :              may also be able to "pre-compute" (bits of) the next immediate
    8034                 :             :              (non-)dominator during the RPO walk when marking edges as
    8035                 :             :              executable.  */
    8036                 :    64741292 :           if (dominated_by_p_w_unex (bb, abb, true))
    8037                 :             :             {
    8038                 :    46968323 :               tree leader = ssa_name (av->leader);
    8039                 :             :               /* Prevent eliminations that break loop-closed SSA.  */
    8040                 :    46968323 :               if (loops_state_satisfies_p (LOOP_CLOSED_SSA)
    8041                 :     3041221 :                   && ! SSA_NAME_IS_DEFAULT_DEF (leader)
    8042                 :    50009544 :                   && ! flow_bb_inside_loop_p (gimple_bb (SSA_NAME_DEF_STMT
    8043                 :     3041221 :                                                          (leader))->loop_father,
    8044                 :             :                                               bb))
    8045                 :             :                 return NULL_TREE;
    8046                 :    46860500 :               if (dump_file && (dump_flags & TDF_DETAILS))
    8047                 :             :                 {
    8048                 :        3399 :                   print_generic_expr (dump_file, leader);
    8049                 :        3399 :                   fprintf (dump_file, " is available for ");
    8050                 :        3399 :                   print_generic_expr (dump_file, valnum);
    8051                 :        3399 :                   fprintf (dump_file, "\n");
    8052                 :             :                 }
    8053                 :             :               /* On tramp3d 99% of the _remaining_ cases succeed at
    8054                 :             :                  the first enty.  */
    8055                 :    46860500 :               return leader;
    8056                 :             :             }
    8057                 :             :           /* ???  Can we somehow skip to the immediate dominator
    8058                 :             :              RPO index (bb_to_rpo)?  Again, maybe not worth, on
    8059                 :             :              tramp3d the worst number of elements in the vector is 9.  */
    8060                 :    17772969 :           av = av->next;
    8061                 :             :         }
    8062                 :    17772969 :       while (av);
    8063                 :             :       /* While we prefer avail we have to fallback to using the value
    8064                 :             :          directly if defined outside of the region when none of the
    8065                 :             :          available defs suit.  */
    8066                 :     3864220 :       if (!valnum_info->visited)
    8067                 :             :         return valnum;
    8068                 :             :     }
    8069                 :    13744918 :   else if (valnum != VN_TOP)
    8070                 :             :     /* valnum is is_gimple_min_invariant.  */
    8071                 :             :     return valnum;
    8072                 :             :   return NULL_TREE;
    8073                 :             : }
    8074                 :             : 
    8075                 :             : /* Make LEADER a leader for its value at BB.  */
    8076                 :             : 
    8077                 :             : void
    8078                 :    97468116 : rpo_elim::eliminate_push_avail (basic_block bb, tree leader)
    8079                 :             : {
    8080                 :    97468116 :   tree valnum = VN_INFO (leader)->valnum;
    8081                 :    97468116 :   if (valnum == VN_TOP
    8082                 :    97468116 :       || is_gimple_min_invariant (valnum))
    8083                 :           0 :     return;
    8084                 :    97468116 :   if (dump_file && (dump_flags & TDF_DETAILS))
    8085                 :             :     {
    8086                 :      300825 :       fprintf (dump_file, "Making available beyond BB%d ", bb->index);
    8087                 :      300825 :       print_generic_expr (dump_file, leader);
    8088                 :      300825 :       fprintf (dump_file, " for value ");
    8089                 :      300825 :       print_generic_expr (dump_file, valnum);
    8090                 :      300825 :       fprintf (dump_file, "\n");
    8091                 :             :     }
    8092                 :    97468116 :   vn_ssa_aux_t value = VN_INFO (valnum);
    8093                 :    97468116 :   vn_avail *av;
    8094                 :    97468116 :   if (m_avail_freelist)
    8095                 :             :     {
    8096                 :    18879931 :       av = m_avail_freelist;
    8097                 :    18879931 :       m_avail_freelist = m_avail_freelist->next;
    8098                 :             :     }
    8099                 :             :   else
    8100                 :    78588185 :     av = XOBNEW (&vn_ssa_aux_obstack, vn_avail);
    8101                 :    97468116 :   av->location = bb->index;
    8102                 :    97468116 :   av->leader = SSA_NAME_VERSION (leader);
    8103                 :    97468116 :   av->next = value->avail;
    8104                 :    97468116 :   av->next_undo = last_pushed_avail;
    8105                 :    97468116 :   last_pushed_avail = value;
    8106                 :    97468116 :   value->avail = av;
    8107                 :             : }
    8108                 :             : 
    8109                 :             : /* Valueization hook for RPO VN plus required state.  */
    8110                 :             : 
    8111                 :             : tree
    8112                 :  1888452127 : rpo_vn_valueize (tree name)
    8113                 :             : {
    8114                 :  1888452127 :   if (TREE_CODE (name) == SSA_NAME)
    8115                 :             :     {
    8116                 :  1840978847 :       vn_ssa_aux_t val = VN_INFO (name);
    8117                 :  1840978847 :       if (val)
    8118                 :             :         {
    8119                 :  1840978847 :           tree tem = val->valnum;
    8120                 :  1840978847 :           if (tem != VN_TOP && tem != name)
    8121                 :             :             {
    8122                 :   100056233 :               if (TREE_CODE (tem) != SSA_NAME)
    8123                 :             :                 return tem;
    8124                 :             :               /* For all values we only valueize to an available leader
    8125                 :             :                  which means we can use SSA name info without restriction.  */
    8126                 :    83560975 :               tem = rpo_avail->eliminate_avail (vn_context_bb, tem);
    8127                 :    83560975 :               if (tem)
    8128                 :             :                 return tem;
    8129                 :             :             }
    8130                 :             :         }
    8131                 :             :     }
    8132                 :             :   return name;
    8133                 :             : }
    8134                 :             : 
    8135                 :             : /* Insert on PRED_E predicates derived from CODE OPS being true besides the
    8136                 :             :    inverted condition.  */
    8137                 :             : 
    8138                 :             : static void
    8139                 :    27696064 : insert_related_predicates_on_edge (enum tree_code code, tree *ops, edge pred_e)
    8140                 :             : {
    8141                 :    27696064 :   switch (code)
    8142                 :             :     {
    8143                 :     1345692 :     case LT_EXPR:
    8144                 :             :       /* a < b -> a {!,<}= b */
    8145                 :     1345692 :       vn_nary_op_insert_pieces_predicated (2, NE_EXPR, boolean_type_node,
    8146                 :             :                                            ops, boolean_true_node, 0, pred_e);
    8147                 :     1345692 :       vn_nary_op_insert_pieces_predicated (2, LE_EXPR, boolean_type_node,
    8148                 :             :                                            ops, boolean_true_node, 0, pred_e);
    8149                 :             :       /* a < b -> ! a {>,=} b */
    8150                 :     1345692 :       vn_nary_op_insert_pieces_predicated (2, GT_EXPR, boolean_type_node,
    8151                 :             :                                            ops, boolean_false_node, 0, pred_e);
    8152                 :     1345692 :       vn_nary_op_insert_pieces_predicated (2, EQ_EXPR, boolean_type_node,
    8153                 :             :                                            ops, boolean_false_node, 0, pred_e);
    8154                 :     1345692 :       break;
    8155                 :     3490970 :     case GT_EXPR:
    8156                 :             :       /* a > b -> a {!,>}= b */
    8157                 :     3490970 :       vn_nary_op_insert_pieces_predicated (2, NE_EXPR, boolean_type_node,
    8158                 :             :                                            ops, boolean_true_node, 0, pred_e);
    8159                 :     3490970 :       vn_nary_op_insert_pieces_predicated (2, GE_EXPR, boolean_type_node,
    8160                 :             :                                            ops, boolean_true_node, 0, pred_e);
    8161                 :             :       /* a > b -> ! a {<,=} b */
    8162                 :     3490970 :       vn_nary_op_insert_pieces_predicated (2, LT_EXPR, boolean_type_node,
    8163                 :             :                                            ops, boolean_false_node, 0, pred_e);
    8164                 :     3490970 :       vn_nary_op_insert_pieces_predicated (2, EQ_EXPR, boolean_type_node,
    8165                 :             :                                            ops, boolean_false_node, 0, pred_e);
    8166                 :     3490970 :       break;
    8167                 :     9461641 :     case EQ_EXPR:
    8168                 :             :       /* a == b -> ! a {<,>} b */
    8169                 :     9461641 :       vn_nary_op_insert_pieces_predicated (2, LT_EXPR, boolean_type_node,
    8170                 :             :                                            ops, boolean_false_node, 0, pred_e);
    8171                 :     9461641 :       vn_nary_op_insert_pieces_predicated (2, GT_EXPR, boolean_type_node,
    8172                 :             :                                            ops, boolean_false_node, 0, pred_e);
    8173                 :     9461641 :       break;
    8174                 :             :     case LE_EXPR:
    8175                 :             :     case GE_EXPR:
    8176                 :             :     case NE_EXPR:
    8177                 :             :       /* Nothing besides inverted condition.  */
    8178                 :             :       break;
    8179                 :    27696064 :     default:;
    8180                 :             :     }
    8181                 :    27696064 : }
    8182                 :             : 
    8183                 :             : /* Insert on the TRUE_E true and FALSE_E false predicates
    8184                 :             :    derived from LHS CODE RHS.  */
    8185                 :             : 
    8186                 :             : static void
    8187                 :    23454844 : insert_predicates_for_cond (tree_code code, tree lhs, tree rhs,
    8188                 :             :                             edge true_e, edge false_e)
    8189                 :             : {
    8190                 :             :   /* If both edges are null, then there is nothing to be done. */
    8191                 :    23454844 :   if (!true_e && !false_e)
    8192                 :     1311605 :     return;
    8193                 :             : 
    8194                 :             :   /* Canonicalize the comparison if needed, putting
    8195                 :             :      the constant in the rhs.  */
    8196                 :    22146615 :   if (tree_swap_operands_p (lhs, rhs))
    8197                 :             :     {
    8198                 :       16631 :       std::swap (lhs, rhs);
    8199                 :       16631 :       code = swap_tree_comparison (code);
    8200                 :             :     }
    8201                 :             : 
    8202                 :             :   /* If the lhs is not a ssa name, don't record anything. */
    8203                 :    22146615 :   if (TREE_CODE (lhs) != SSA_NAME)
    8204                 :             :     return;
    8205                 :             : 
    8206                 :    22143239 :   tree_code icode = invert_tree_comparison (code, HONOR_NANS (lhs));
    8207                 :    22143239 :   tree ops[2];
    8208                 :    22143239 :   ops[0] = lhs;
    8209                 :    22143239 :   ops[1] = rhs;
    8210                 :    22143239 :   if (true_e)
    8211                 :    18135914 :     vn_nary_op_insert_pieces_predicated (2, code, boolean_type_node, ops,
    8212                 :             :                                          boolean_true_node, 0, true_e);
    8213                 :    22143239 :   if (false_e)
    8214                 :    17112953 :     vn_nary_op_insert_pieces_predicated (2, code, boolean_type_node, ops,
    8215                 :             :                                          boolean_false_node, 0, false_e);
    8216                 :    22143239 :   if (icode != ERROR_MARK)
    8217                 :             :     {
    8218                 :    21891939 :       if (true_e)
    8219                 :    17984425 :         vn_nary_op_insert_pieces_predicated (2, icode, boolean_type_node, ops,
    8220                 :             :                                              boolean_false_node, 0, true_e);
    8221                 :    21891939 :       if (false_e)
    8222                 :    16907039 :         vn_nary_op_insert_pieces_predicated (2, icode, boolean_type_node, ops,
    8223                 :             :                                              boolean_true_node, 0, false_e);
    8224                 :             :     }
    8225                 :             :   /* Relax for non-integers, inverted condition handled
    8226                 :             :      above.  */
    8227                 :    22143239 :   if (INTEGRAL_TYPE_P (TREE_TYPE (lhs)))
    8228                 :             :     {
    8229                 :    17372286 :       if (true_e)
    8230                 :    14298958 :         insert_related_predicates_on_edge (code, ops, true_e);
    8231                 :    17372286 :       if (false_e)
    8232                 :    13397106 :         insert_related_predicates_on_edge (icode, ops, false_e);
    8233                 :             :   }
    8234                 :    22143239 :   if (integer_zerop (rhs)
    8235                 :    22143239 :       && (code == NE_EXPR || code == EQ_EXPR))
    8236                 :             :     {
    8237                 :     9217304 :       gimple *def_stmt = SSA_NAME_DEF_STMT (lhs);
    8238                 :             :       /* (A CMP B) != 0 is the same as (A CMP B).
    8239                 :             :          (A CMP B) == 0 is just (A CMP B) with the edges swapped.  */
    8240                 :     9217304 :       if (is_gimple_assign (def_stmt)
    8241                 :     9217304 :           && TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) == tcc_comparison)
    8242                 :             :           {
    8243                 :      455233 :             tree_code nc = gimple_assign_rhs_code (def_stmt);
    8244                 :      455233 :             tree nlhs = vn_valueize (gimple_assign_rhs1 (def_stmt));
    8245                 :      455233 :             tree nrhs = vn_valueize (gimple_assign_rhs2 (def_stmt));
    8246                 :      455233 :             edge nt = true_e;
    8247                 :      455233 :             edge nf = false_e;
    8248                 :      455233 :             if (code == EQ_EXPR)
    8249                 :      325436 :               std::swap (nt, nf);
    8250                 :      455233 :             if (lhs != nlhs)
    8251                 :      455233 :               insert_predicates_for_cond (nc, nlhs, nrhs, nt, nf);
    8252                 :             :           }
    8253                 :             :       /* (a | b) == 0 ->
    8254                 :             :             on true edge assert: a == 0 & b == 0. */
    8255                 :             :       /* (a | b) != 0 ->
    8256                 :             :             on false edge assert: a == 0 & b == 0. */
    8257                 :     9217304 :       if (is_gimple_assign (def_stmt)
    8258                 :     9217304 :           && gimple_assign_rhs_code (def_stmt) == BIT_IOR_EXPR)
    8259                 :             :         {
    8260                 :      266755 :           edge e = code == EQ_EXPR ? true_e : false_e;
    8261                 :      266755 :           tree nlhs;
    8262                 :             : 
    8263                 :      266755 :           nlhs = vn_valueize (gimple_assign_rhs1 (def_stmt));
    8264                 :             :           /* A valueization of the `a` might return the old lhs
    8265                 :             :              which is already handled above. */
    8266                 :      266755 :           if (nlhs != lhs)
    8267                 :      266755 :             insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr);
    8268                 :             : 
    8269                 :             :           /* A valueization of the `b` might return the old lhs
    8270                 :             :              which is already handled above. */
    8271                 :      266755 :           nlhs = vn_valueize (gimple_assign_rhs2 (def_stmt));
    8272                 :      266755 :           if (nlhs != lhs)
    8273                 :      266755 :             insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr);
    8274                 :             :         }
    8275                 :             :     }
    8276                 :             : }
    8277                 :             : 
    8278                 :             : /* Main stmt worker for RPO VN, process BB.  */
    8279                 :             : 
    8280                 :             : static unsigned
    8281                 :    62918979 : process_bb (rpo_elim &avail, basic_block bb,
    8282                 :             :             bool bb_visited, bool iterate_phis, bool iterate, bool eliminate,
    8283                 :             :             bool do_region, bitmap exit_bbs, bool skip_phis)
    8284                 :             : {
    8285                 :    62918979 :   unsigned todo = 0;
    8286                 :    62918979 :   edge_iterator ei;
    8287                 :    62918979 :   edge e;
    8288                 :             : 
    8289                 :    62918979 :   vn_context_bb = bb;
    8290                 :             : 
    8291                 :             :   /* If we are in loop-closed SSA preserve this state.  This is
    8292                 :             :      relevant when called on regions from outside of FRE/PRE.  */
    8293                 :    62918979 :   bool lc_phi_nodes = false;
    8294                 :    62918979 :   if (!skip_phis
    8295                 :    62918979 :       && loops_state_satisfies_p (LOOP_CLOSED_SSA))
    8296                 :     3650415 :     FOR_EACH_EDGE (e, ei, bb->preds)
    8297                 :     2217611 :       if (e->src->loop_father != e->dest->loop_father
    8298                 :     2217611 :           && flow_loop_nested_p (e->dest->loop_father,
    8299                 :             :                                  e->src->loop_father))
    8300                 :             :         {
    8301                 :             :           lc_phi_nodes = true;
    8302                 :             :           break;
    8303                 :             :         }
    8304                 :             : 
    8305                 :             :   /* When we visit a loop header substitute into loop info.  */
    8306                 :    62918979 :   if (!iterate && eliminate && bb->loop_father->header == bb)
    8307                 :             :     {
    8308                 :             :       /* Keep fields in sync with substitute_in_loop_info.  */
    8309                 :      938439 :       if (bb->loop_father->nb_iterations)
    8310                 :      147005 :         bb->loop_father->nb_iterations
    8311                 :      147005 :           = simplify_replace_tree (bb->loop_father->nb_iterations,
    8312                 :             :                                    NULL_TREE, NULL_TREE, &vn_valueize_for_srt);
    8313                 :             :     }
    8314                 :             : 
    8315                 :             :   /* Value-number all defs in the basic-block.  */
    8316                 :    62918979 :   if (!skip_phis)
    8317                 :    90724562 :     for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
    8318                 :    27831845 :          gsi_next (&gsi))
    8319                 :             :       {
    8320                 :    27831845 :         gphi *phi = gsi.phi ();
    8321                 :    27831845 :         tree res = PHI_RESULT (phi);
    8322                 :    27831845 :         vn_ssa_aux_t res_info = VN_INFO (res);
    8323                 :    27831845 :         if (!bb_visited)
    8324                 :             :           {
    8325                 :    19859467 :             gcc_assert (!res_info->visited);
    8326                 :    19859467 :             res_info->valnum = VN_TOP;
    8327                 :    19859467 :             res_info->visited = true;
    8328                 :             :           }
    8329                 :             : 
    8330                 :             :         /* When not iterating force backedge values to varying.  */
    8331                 :    27831845 :         visit_stmt (phi, !iterate_phis);
    8332                 :    55663690 :         if (virtual_operand_p (res))
    8333                 :    11204587 :           continue;
    8334                 :             : 
    8335                 :             :         /* Eliminate */
    8336                 :             :         /* The interesting case is gcc.dg/tree-ssa/pr22230.c for correctness
    8337                 :             :            how we handle backedges and availability.
    8338                 :             :            And gcc.dg/tree-ssa/ssa-sccvn-2.c for optimization.  */
    8339                 :    16627258 :         tree val = res_info->valnum;
    8340                 :    16627258 :         if (res != val && !iterate && eliminate)
    8341                 :             :           {
    8342                 :     1428012 :             if (tree leader = avail.eliminate_avail (bb, res))
    8343                 :             :               {
    8344                 :     1277715 :                 if (leader != res
    8345                 :             :                     /* Preserve loop-closed SSA form.  */
    8346                 :     1277715 :                     && (! lc_phi_nodes
    8347                 :        3385 :                         || is_gimple_min_invariant (leader)))
    8348                 :             :                   {
    8349                 :     1276965 :                     if (dump_file && (dump_flags & TDF_DETAILS))
    8350                 :             :                       {
    8351                 :         195 :                         fprintf (dump_file, "Replaced redundant PHI node "
    8352                 :             :                                  "defining ");
    8353                 :         195 :                         print_generic_expr (dump_file, res);
    8354                 :         195 :                         fprintf (dump_file, " with ");
    8355                 :         195 :                         print_generic_expr (dump_file, leader);
    8356                 :         195 :                         fprintf (dump_file, "\n");
    8357                 :             :                       }
    8358                 :     1276965 :                     avail.eliminations++;
    8359                 :             : 
    8360                 :     1276965 :                     if (may_propagate_copy (res, leader))
    8361                 :             :                       {
    8362                 :             :                         /* Schedule for removal.  */
    8363                 :     1276965 :                         avail.to_remove.safe_push (phi);
    8364                 :     1276965 :                         continue;
    8365                 :             :                       }
    8366                 :             :                     /* ???  Else generate a copy stmt.  */
    8367                 :             :                   }
    8368                 :             :               }
    8369                 :             :           }
    8370                 :             :         /* Only make defs available that not already are.  But make
    8371                 :             :            sure loop-closed SSA PHI node defs are picked up for
    8372                 :             :            downstream uses.  */
    8373                 :    15350293 :         if (lc_phi_nodes
    8374                 :    15350293 :             || res == val
    8375                 :    15350293 :             || ! avail.eliminate_avail (bb, res))
    8376                 :    11719245 :           avail.eliminate_push_avail (bb, res);
    8377                 :             :       }
    8378                 :             : 
    8379                 :             :   /* For empty BBs mark outgoing edges executable.  For non-empty BBs
    8380                 :             :      we do this when processing the last stmt as we have to do this
    8381                 :             :      before elimination which otherwise forces GIMPLE_CONDs to
    8382                 :             :      if (1 != 0) style when seeing non-executable edges.  */
    8383                 :   125837958 :   if (gsi_end_p (gsi_start_bb (bb)))
    8384                 :             :     {
    8385                 :    14953848 :       FOR_EACH_EDGE (e, ei, bb->succs)
    8386                 :             :         {
    8387                 :     7476924 :           if (!(e->flags & EDGE_EXECUTABLE))
    8388                 :             :             {
    8389                 :     5194962 :               if (dump_file && (dump_flags & TDF_DETAILS))
    8390                 :        5685 :                 fprintf (dump_file,
    8391                 :             :                          "marking outgoing edge %d -> %d executable\n",
    8392                 :        5685 :                          e->src->index, e->dest->index);
    8393                 :     5194962 :               e->flags |= EDGE_EXECUTABLE;
    8394                 :     5194962 :               e->dest->flags |= BB_EXECUTABLE;
    8395                 :             :             }
    8396                 :     2281962 :           else if (!(e->dest->flags & BB_EXECUTABLE))
    8397                 :             :             {
    8398                 :           0 :               if (dump_file && (dump_flags & TDF_DETAILS))
    8399                 :           0 :                 fprintf (dump_file,
    8400                 :             :                          "marking destination block %d reachable\n",
    8401                 :             :                          e->dest->index);
    8402                 :           0 :               e->dest->flags |= BB_EXECUTABLE;
    8403                 :             :             }
    8404                 :             :         }
    8405                 :             :     }
    8406                 :   125837958 :   for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
    8407                 :   493153238 :        !gsi_end_p (gsi); gsi_next (&gsi))
    8408                 :             :     {
    8409                 :   430234259 :       ssa_op_iter i;
    8410                 :   430234259 :       tree op;
    8411                 :   430234259 :       if (!bb_visited)
    8412                 :             :         {
    8413                 :   493238126 :           FOR_EACH_SSA_TREE_OPERAND (op, gsi_stmt (gsi), i, SSA_OP_ALL_DEFS)
    8414                 :             :             {
    8415                 :   138834896 :               vn_ssa_aux_t op_info = VN_INFO (op);
    8416                 :   138834896 :               gcc_assert (!op_info->visited);
    8417                 :   138834896 :               op_info->valnum = VN_TOP;
    8418                 :   138834896 :               op_info->visited = true;
    8419                 :             :             }
    8420                 :             : 
    8421                 :             :           /* We somehow have to deal with uses that are not defined
    8422                 :             :              in the processed region.  Forcing unvisited uses to
    8423                 :             :              varying here doesn't play well with def-use following during
    8424                 :             :              expression simplification, so we deal with this by checking
    8425                 :             :              the visited flag in SSA_VAL.  */
    8426                 :             :         }
    8427                 :             : 
    8428                 :   430234259 :       visit_stmt (gsi_stmt (gsi));
    8429                 :             : 
    8430                 :   430234259 :       gimple *last = gsi_stmt (gsi);
    8431                 :   430234259 :       e = NULL;
    8432                 :   430234259 :       switch (gimple_code (last))
    8433                 :             :         {
    8434                 :      122511 :         case GIMPLE_SWITCH:
    8435                 :      122511 :           e = find_taken_edge (bb, vn_valueize (gimple_switch_index
    8436                 :      122511 :                                                 (as_a <gswitch *> (last))));
    8437                 :      122511 :           break;
    8438                 :    24582683 :         case GIMPLE_COND:
    8439                 :    24582683 :           {
    8440                 :    24582683 :             tree lhs = vn_valueize (gimple_cond_lhs (last));
    8441                 :    24582683 :             tree rhs = vn_valueize (gimple_cond_rhs (last));
    8442                 :    24582683 :             tree_code cmpcode = gimple_cond_code (last);
    8443                 :             :             /* Canonicalize the comparison if needed, putting
    8444                 :             :                the constant in the rhs.  */
    8445                 :    24582683 :             if (tree_swap_operands_p (lhs, rhs))
    8446                 :             :               {
    8447                 :      831896 :                 std::swap (lhs, rhs);
    8448                 :      831896 :                 cmpcode = swap_tree_comparison (cmpcode);
    8449                 :             :                }
    8450                 :    24582683 :             tree val = gimple_simplify (cmpcode,
    8451                 :             :                                         boolean_type_node, lhs, rhs,
    8452                 :             :                                         NULL, vn_valueize);
    8453                 :             :             /* If the condition didn't simplfy see if we have recorded
    8454                 :             :                an expression from sofar taken edges.  */
    8455                 :    24582683 :             if (! val || TREE_CODE (val) != INTEGER_CST)
    8456                 :             :               {
    8457                 :    22782370 :                 vn_nary_op_t vnresult;
    8458                 :    22782370 :                 tree ops[2];
    8459                 :    22782370 :                 ops[0] = lhs;
    8460                 :    22782370 :                 ops[1] = rhs;
    8461                 :    22782370 :                 val = vn_nary_op_lookup_pieces (2, cmpcode,
    8462                 :             :                                                 boolean_type_node, ops,
    8463                 :             :                                                 &vnresult);
    8464                 :             :                 /* Got back a ssa name, then try looking up `val != 0`
    8465                 :             :                    as it might have been recorded that way.  */
    8466                 :    22782370 :                 if (val && TREE_CODE (val) == SSA_NAME)
    8467                 :             :                   {
    8468                 :      144105 :                     ops[0] = val;
    8469                 :      144105 :                     ops[1] = build_zero_cst (TREE_TYPE (val));
    8470                 :      144105 :                     val = vn_nary_op_lookup_pieces (2, NE_EXPR,
    8471                 :             :                                                     boolean_type_node, ops,
    8472                 :             :                                                     &vnresult);
    8473                 :             :                   }
    8474                 :             :                 /* Did we get a predicated value?  */
    8475                 :    22782355 :                 if (! val && vnresult && vnresult->predicated_values)
    8476                 :             :                   {
    8477                 :     1254327 :                     val = vn_nary_op_get_predicated_value (vnresult, bb);
    8478                 :     1254327 :                     if (val && dump_file && (dump_flags & TDF_DETAILS))
    8479                 :             :                       {
    8480                 :           2 :                         fprintf (dump_file, "Got predicated value ");
    8481                 :           2 :                         print_generic_expr (dump_file, val, TDF_NONE);
    8482                 :           2 :                         fprintf (dump_file, " for ");
    8483                 :           2 :                         print_gimple_stmt (dump_file, last, TDF_SLIM);
    8484                 :             :                       }
    8485                 :             :                   }
    8486                 :             :               }
    8487                 :    22782370 :             if (val)
    8488                 :     2116582 :               e = find_taken_edge (bb, val);
    8489                 :    24582683 :             if (! e)
    8490                 :             :               {
    8491                 :             :                 /* If we didn't manage to compute the taken edge then
    8492                 :             :                    push predicated expressions for the condition itself
    8493                 :             :                    and related conditions to the hashtables.  This allows
    8494                 :             :                    simplification of redundant conditions which is
    8495                 :             :                    important as early cleanup.  */
    8496                 :    22466101 :                 edge true_e, false_e;
    8497                 :    22466101 :                 extract_true_false_edges_from_block (bb, &true_e, &false_e);
    8498                 :      518692 :                 if ((do_region && bitmap_bit_p (exit_bbs, true_e->dest->index))
    8499                 :    22679842 :                     || !can_track_predicate_on_edge (true_e))
    8500                 :     4867686 :                   true_e = NULL;
    8501                 :      518692 :                 if ((do_region && bitmap_bit_p (exit_bbs, false_e->dest->index))
    8502                 :    22654598 :                     || !can_track_predicate_on_edge (false_e))
    8503                 :     5770082 :                   false_e = NULL;
    8504                 :    22466101 :                 insert_predicates_for_cond (cmpcode, lhs, rhs, true_e, false_e);
    8505                 :             :               }
    8506                 :             :             break;
    8507                 :             :           }
    8508                 :        1359 :         case GIMPLE_GOTO:
    8509                 :        1359 :           e = find_taken_edge (bb, vn_valueize (gimple_goto_dest (last)));
    8510                 :        1359 :           break;
    8511                 :             :         default:
    8512                 :             :           e = NULL;
    8513                 :             :         }
    8514                 :   430234259 :       if (e)
    8515                 :             :         {
    8516                 :     2120309 :           todo = TODO_cleanup_cfg;
    8517                 :     2120309 :           if (!(e->flags & EDGE_EXECUTABLE))
    8518                 :             :             {
    8519                 :     1672335 :               if (dump_file && (dump_flags & TDF_DETAILS))
    8520                 :          35 :                 fprintf (dump_file,
    8521                 :             :                          "marking known outgoing %sedge %d -> %d executable\n",
    8522                 :          35 :                          e->flags & EDGE_DFS_BACK ? "back-" : "",
    8523                 :          35 :                          e->src->index, e->dest->index);
    8524                 :     1672335 :               e->flags |= EDGE_EXECUTABLE;
    8525                 :     1672335 :               e->dest->flags |= BB_EXECUTABLE;
    8526                 :             :             }
    8527                 :      447974 :           else if (!(e->dest->flags & BB_EXECUTABLE))
    8528                 :             :             {
    8529                 :       11828 :               if (dump_file && (dump_flags & TDF_DETAILS))
    8530                 :           0 :                 fprintf (dump_file,
    8531                 :             :                          "marking destination block %d reachable\n",
    8532                 :             :                          e->dest->index);
    8533                 :       11828 :               e->dest->flags |= BB_EXECUTABLE;
    8534                 :             :             }
    8535                 :             :         }
    8536                 :   856227900 :       else if (gsi_one_before_end_p (gsi))
    8537                 :             :         {
    8538                 :   130882277 :           FOR_EACH_EDGE (e, ei, bb->succs)
    8539                 :             :             {
    8540                 :    77560531 :               if (!(e->flags & EDGE_EXECUTABLE))
    8541                 :             :                 {
    8542                 :    57031263 :                   if (dump_file && (dump_flags & TDF_DETAILS))
    8543                 :       17047 :                     fprintf (dump_file,
    8544                 :             :                              "marking outgoing edge %d -> %d executable\n",
    8545                 :       17047 :                              e->src->index, e->dest->index);
    8546                 :    57031263 :                   e->flags |= EDGE_EXECUTABLE;
    8547                 :    57031263 :                   e->dest->flags |= BB_EXECUTABLE;
    8548                 :             :                 }
    8549                 :    20529268 :               else if (!(e->dest->flags & BB_EXECUTABLE))
    8550                 :             :                 {
    8551                 :     2592397 :                   if (dump_file && (dump_flags & TDF_DETAILS))
    8552                 :        5637 :                     fprintf (dump_file,
    8553                 :             :                              "marking destination block %d reachable\n",
    8554                 :             :                              e->dest->index);
    8555                 :     2592397 :                   e->dest->flags |= BB_EXECUTABLE;
    8556                 :             :                 }
    8557                 :             :             }
    8558                 :             :         }
    8559                 :             : 
    8560                 :             :       /* Eliminate.  That also pushes to avail.  */
    8561                 :   430234259 :       if (eliminate && ! iterate)
    8562                 :   106061050 :         avail.eliminate_stmt (bb, &gsi);
    8563                 :             :       else
    8564                 :             :         /* If not eliminating, make all not already available defs
    8565                 :             :            available.  But avoid picking up dead defs.  */
    8566                 :   404395520 :         FOR_EACH_SSA_TREE_OPERAND (op, gsi_stmt (gsi), i, SSA_OP_DEF)
    8567                 :    80222311 :           if (! has_zero_uses (op)
    8568                 :    80222311 :               && ! avail.eliminate_avail (bb, op))
    8569                 :    61461238 :             avail.eliminate_push_avail (bb, op);
    8570                 :             :     }
    8571                 :             : 
    8572                 :             :   /* Eliminate in destination PHI arguments.  Always substitute in dest
    8573                 :             :      PHIs, even for non-executable edges.  This handles region
    8574                 :             :      exits PHIs.  */
    8575                 :    62918979 :   if (!iterate && eliminate)
    8576                 :    33912188 :     FOR_EACH_EDGE (e, ei, bb->succs)
    8577                 :    20149245 :       for (gphi_iterator gsi = gsi_start_phis (e->dest);
    8578                 :    38508886 :            !gsi_end_p (gsi); gsi_next (&gsi))
    8579                 :             :         {
    8580                 :    18359641 :           gphi *phi = gsi.phi ();
    8581                 :    18359641 :           use_operand_p use_p = PHI_ARG_DEF_PTR_FROM_EDGE (phi, e);
    8582                 :    18359641 :           tree arg = USE_FROM_PTR (use_p);
    8583                 :    28049656 :           if (TREE_CODE (arg) != SSA_NAME
    8584                 :    18359641 :               || virtual_operand_p (arg))
    8585                 :     9690015 :             continue;
    8586                 :     8669626 :           tree sprime;
    8587                 :     8669626 :           if (SSA_NAME_IS_DEFAULT_DEF (arg))
    8588                 :             :             {
    8589                 :      115335 :               sprime = SSA_VAL (arg);
    8590                 :      115335 :               gcc_assert (TREE_CODE (sprime) != SSA_NAME
    8591                 :             :                           || SSA_NAME_IS_DEFAULT_DEF (sprime));
    8592                 :             :             }
    8593                 :             :           else
    8594                 :             :             /* Look for sth available at the definition block of the argument.
    8595                 :             :                This avoids inconsistencies between availability there which
    8596                 :             :                decides if the stmt can be removed and availability at the
    8597                 :             :                use site.  The SSA property ensures that things available
    8598                 :             :                at the definition are also available at uses.  */
    8599                 :     8554291 :             sprime = avail.eliminate_avail (gimple_bb (SSA_NAME_DEF_STMT (arg)),
    8600                 :             :                                             arg);
    8601                 :     8669626 :           if (sprime
    8602                 :     8669626 :               && sprime != arg
    8603                 :     8669626 :               && may_propagate_copy (arg, sprime, !(e->flags & EDGE_ABNORMAL)))
    8604                 :     1518680 :             propagate_value (use_p, sprime);
    8605                 :             :         }
    8606                 :             : 
    8607                 :    62918979 :   vn_context_bb = NULL;
    8608                 :    62918979 :   return todo;
    8609                 :             : }
    8610                 :             : 
    8611                 :             : /* Unwind state per basic-block.  */
    8612                 :             : 
    8613                 :             : struct unwind_state
    8614                 :             : {
    8615                 :             :   /* Times this block has been visited.  */
    8616                 :             :   unsigned visited;
    8617                 :             :   /* Whether to handle this as iteration point or whether to treat
    8618                 :             :      incoming backedge PHI values as varying.  */
    8619                 :             :   bool iterate;
    8620                 :             :   /* Maximum RPO index this block is reachable from.  */
    8621                 :             :   int max_rpo;
    8622                 :             :   /* Unwind state.  */
    8623                 :             :   void *ob_top;
    8624                 :             :   vn_reference_t ref_top;
    8625                 :             :   vn_phi_t phi_top;
    8626                 :             :   vn_nary_op_t nary_top;
    8627                 :             :   vn_avail *avail_top;
    8628                 :             : };
    8629                 :             : 
    8630                 :             : /* Unwind the RPO VN state for iteration.  */
    8631                 :             : 
    8632                 :             : static void
    8633                 :     1907293 : do_unwind (unwind_state *to, rpo_elim &avail)
    8634                 :             : {
    8635                 :     1907293 :   gcc_assert (to->iterate);
    8636                 :    35096974 :   for (; last_inserted_nary != to->nary_top;
    8637                 :    33189681 :        last_inserted_nary = last_inserted_nary->next)
    8638                 :             :     {
    8639                 :    33189681 :       vn_nary_op_t *slot;
    8640                 :    33189681 :       slot = valid_info->nary->find_slot_with_hash
    8641                 :    33189681 :         (last_inserted_nary, last_inserted_nary->hashcode, NO_INSERT);
    8642                 :             :       /* Predication causes the need to restore previous state.  */
    8643                 :    33189681 :       if ((*slot)->unwind_to)
    8644                 :     6671844 :         *slot = (*slot)->unwind_to;
    8645                 :             :       else
    8646                 :    26517837 :         valid_info->nary->clear_slot (slot);
    8647                 :             :     }
    8648                 :     7522462 :   for (; last_inserted_phi != to->phi_top;
    8649                 :     5615169 :        last_inserted_phi = last_inserted_phi->next)
    8650                 :             :     {
    8651                 :     5615169 :       vn_phi_t *slot;
    8652                 :     5615169 :       slot = valid_info->phis->find_slot_with_hash
    8653                 :     5615169 :         (last_inserted_phi, last_inserted_phi->hashcode, NO_INSERT);
    8654                 :     5615169 :       valid_info->phis->clear_slot (slot);
    8655                 :             :     }
    8656                 :    15309923 :   for (; last_inserted_ref != to->ref_top;
    8657                 :    13402630 :        last_inserted_ref = last_inserted_ref->next)
    8658                 :             :     {
    8659                 :    13402630 :       vn_reference_t *slot;
    8660                 :    13402630 :       slot = valid_info->references->find_slot_with_hash
    8661                 :    13402630 :         (last_inserted_ref, last_inserted_ref->hashcode, NO_INSERT);
    8662                 :    13402630 :       (*slot)->operands.release ();
    8663                 :    13402630 :       valid_info->references->clear_slot (slot);
    8664                 :             :     }
    8665                 :     1907293 :   obstack_free (&vn_tables_obstack, to->ob_top);
    8666                 :             : 
    8667                 :             :   /* Prune [rpo_idx, ] from avail.  */
    8668                 :    20787224 :   for (; last_pushed_avail && last_pushed_avail->avail != to->avail_top;)
    8669                 :             :     {
    8670                 :    18879931 :       vn_ssa_aux_t val = last_pushed_avail;
    8671                 :    18879931 :       vn_avail *av = val->avail;
    8672                 :    18879931 :       val->avail = av->next;
    8673                 :    18879931 :       last_pushed_avail = av->next_undo;
    8674                 :    18879931 :       av->next = avail.m_avail_freelist;
    8675                 :    18879931 :       avail.m_avail_freelist = av;
    8676                 :             :     }
    8677                 :     1907293 : }
    8678                 :             : 
    8679                 :             : /* Do VN on a SEME region specified by ENTRY and EXIT_BBS in FN.
    8680                 :             :    If ITERATE is true then treat backedges optimistically as not
    8681                 :             :    executed and iterate.  If ELIMINATE is true then perform
    8682                 :             :    elimination, otherwise leave that to the caller.  If SKIP_ENTRY_PHIS
    8683                 :             :    is true then force PHI nodes in ENTRY->dest to VARYING.  */
    8684                 :             : 
    8685                 :             : static unsigned
    8686                 :     6204819 : do_rpo_vn_1 (function *fn, edge entry, bitmap exit_bbs,
    8687                 :             :              bool iterate, bool eliminate, bool skip_entry_phis,
    8688                 :             :              vn_lookup_kind kind)
    8689                 :             : {
    8690                 :     6204819 :   unsigned todo = 0;
    8691                 :     6204819 :   default_vn_walk_kind = kind;
    8692                 :             : 
    8693                 :             :   /* We currently do not support region-based iteration when
    8694                 :             :      elimination is requested.  */
    8695                 :     6204819 :   gcc_assert (!entry || !iterate || !eliminate);
    8696                 :             :   /* When iterating we need loop info up-to-date.  */
    8697                 :     6204819 :   gcc_assert (!iterate || !loops_state_satisfies_p (LOOPS_NEED_FIXUP));
    8698                 :             : 
    8699                 :     6204819 :   bool do_region = entry != NULL;
    8700                 :     6204819 :   if (!do_region)
    8701                 :             :     {
    8702                 :     5535687 :       entry = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (fn));
    8703                 :     5535687 :       exit_bbs = BITMAP_ALLOC (NULL);
    8704                 :     5535687 :       bitmap_set_bit (exit_bbs, EXIT_BLOCK);
    8705                 :             :     }
    8706                 :             : 
    8707                 :             :   /* Clear EDGE_DFS_BACK on "all" entry edges, RPO order compute will
    8708                 :             :      re-mark those that are contained in the region.  */
    8709                 :     6204819 :   edge_iterator ei;
    8710                 :     6204819 :   edge e;
    8711                 :    12464710 :   FOR_EACH_EDGE (e, ei, entry->dest->preds)
    8712                 :     6259891 :     e->flags &= ~EDGE_DFS_BACK;
    8713                 :             : 
    8714                 :     6204819 :   int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (fn) - NUM_FIXED_BLOCKS);
    8715                 :     6204819 :   auto_vec<std::pair<int, int> > toplevel_scc_extents;
    8716                 :     6204819 :   int n = rev_post_order_and_mark_dfs_back_seme
    8717                 :     8069606 :     (fn, entry, exit_bbs, true, rpo, !iterate ? &toplevel_scc_extents : NULL);
    8718                 :             : 
    8719                 :     6204819 :   if (!do_region)
    8720                 :     5535687 :     BITMAP_FREE (exit_bbs);
    8721                 :             : 
    8722                 :             :   /* If there are any non-DFS_BACK edges into entry->dest skip
    8723                 :             :      processing PHI nodes for that block.  This supports
    8724                 :             :      value-numbering loop bodies w/o the actual loop.  */
    8725                 :    12464709 :   FOR_EACH_EDGE (e, ei, entry->dest->preds)
    8726                 :     6259891 :     if (e != entry
    8727                 :       55072 :         && !(e->flags & EDGE_DFS_BACK))
    8728                 :             :       break;
    8729                 :     6204819 :   if (e != NULL && dump_file && (dump_flags & TDF_DETAILS))
    8730                 :           0 :     fprintf (dump_file, "Region does not contain all edges into "
    8731                 :             :              "the entry block, skipping its PHIs.\n");
    8732                 :     6204819 :   skip_entry_phis |= e != NULL;
    8733                 :             : 
    8734                 :     6204819 :   int *bb_to_rpo = XNEWVEC (int, last_basic_block_for_fn (fn));
    8735                 :    57895441 :   for (int i = 0; i < n; ++i)
    8736                 :    51690622 :     bb_to_rpo[rpo[i]] = i;
    8737                 :             : 
    8738                 :     6204819 :   unwind_state *rpo_state = XNEWVEC (unwind_state, n);
    8739                 :             : 
    8740                 :     6204819 :   rpo_elim avail (entry->dest);
    8741                 :     6204819 :   rpo_avail = &avail;
    8742                 :             : 
    8743                 :             :   /* Verify we have no extra entries into the region.  */
    8744                 :     6204819 :   if (flag_checking && do_region)
    8745                 :             :     {
    8746                 :      669126 :       auto_bb_flag bb_in_region (fn);
    8747                 :     2008351 :       for (int i = 0; i < n; ++i)
    8748                 :             :         {
    8749                 :     1339225 :           basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
    8750                 :     1339225 :           bb->flags |= bb_in_region;
    8751                 :             :         }
    8752                 :             :       /* We can't merge the first two loops because we cannot rely
    8753                 :             :          on EDGE_DFS_BACK for edges not within the region.  But if
    8754                 :             :          we decide to always have the bb_in_region flag we can
    8755                 :             :          do the checking during the RPO walk itself (but then it's
    8756                 :             :          also easy to handle MEME conservatively).  */
    8757                 :     2008351 :       for (int i = 0; i < n; ++i)
    8758                 :             :         {
    8759                 :     1339225 :           basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
    8760                 :     1339225 :           edge e;
    8761                 :     1339225 :           edge_iterator ei;
    8762                 :     2921943 :           FOR_EACH_EDGE (e, ei, bb->preds)
    8763                 :     1582718 :             gcc_assert (e == entry
    8764                 :             :                         || (skip_entry_phis && bb == entry->dest)
    8765                 :             :                         || (e->src->flags & bb_in_region));
    8766                 :             :         }
    8767                 :     2008351 :       for (int i = 0; i < n; ++i)
    8768                 :             :         {
    8769                 :     1339225 :           basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
    8770                 :     1339225 :           bb->flags &= ~bb_in_region;
    8771                 :             :         }
    8772                 :      669126 :     }
    8773                 :             : 
    8774                 :             :   /* Create the VN state.  For the initial size of the various hashtables
    8775                 :             :      use a heuristic based on region size and number of SSA names.  */
    8776                 :     6204819 :   unsigned region_size = (((unsigned HOST_WIDE_INT)n * num_ssa_names)
    8777                 :     6204819 :                           / (n_basic_blocks_for_fn (fn) - NUM_FIXED_BLOCKS));
    8778                 :     6204819 :   VN_TOP = create_tmp_var_raw (void_type_node, "vn_top");
    8779                 :     6204819 :   next_value_id = 1;
    8780                 :     6204819 :   next_constant_value_id = -1;
    8781                 :             : 
    8782                 :     6204819 :   vn_ssa_aux_hash = new hash_table <vn_ssa_aux_hasher> (region_size * 2);
    8783                 :     6204819 :   gcc_obstack_init (&vn_ssa_aux_obstack);
    8784                 :             : 
    8785                 :     6204819 :   gcc_obstack_init (&vn_tables_obstack);
    8786                 :     6204819 :   gcc_obstack_init (&vn_tables_insert_obstack);
    8787                 :     6204819 :   valid_info = XCNEW (struct vn_tables_s);
    8788                 :     6204819 :   allocate_vn_table (valid_info, region_size);
    8789                 :     6204819 :   last_inserted_ref = NULL;
    8790                 :     6204819 :   last_inserted_phi = NULL;
    8791                 :     6204819 :   last_inserted_nary = NULL;
    8792                 :     6204819 :   last_pushed_avail = NULL;
    8793                 :             : 
    8794                 :     6204819 :   vn_valueize = rpo_vn_valueize;
    8795                 :             : 
    8796                 :             :   /* Initialize the unwind state and edge/BB executable state.  */
    8797                 :     6204819 :   unsigned curr_scc = 0;
    8798                 :    57895441 :   for (int i = 0; i < n; ++i)
    8799                 :             :     {
    8800                 :    51690622 :       basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
    8801                 :    51690622 :       rpo_state[i].visited = 0;
    8802                 :    51690622 :       rpo_state[i].max_rpo = i;
    8803                 :    60451714 :       if (!iterate && curr_scc < toplevel_scc_extents.length ())
    8804                 :             :         {
    8805                 :     7215873 :           if (i >= toplevel_scc_extents[curr_scc].first
    8806                 :     7215873 :               && i <= toplevel_scc_extents[curr_scc].second)
    8807                 :     3925839 :             rpo_state[i].max_rpo = toplevel_scc_extents[curr_scc].second;
    8808                 :     7215873 :           if (i == toplevel_scc_extents[curr_scc].second)
    8809                 :      721939 :             curr_scc++;
    8810                 :             :         }
    8811                 :    51690622 :       bb->flags &= ~BB_EXECUTABLE;
    8812                 :    51690622 :       bool has_backedges = false;
    8813                 :    51690622 :       edge e;
    8814                 :    51690622 :       edge_iterator ei;
    8815                 :   122527141 :       FOR_EACH_EDGE (e, ei, bb->preds)
    8816                 :             :         {
    8817                 :    70836519 :           if (e->flags & EDGE_DFS_BACK)
    8818                 :     2843778 :             has_backedges = true;
    8819                 :    70836519 :           e->flags &= ~EDGE_EXECUTABLE;
    8820                 :    70836519 :           if (iterate || e == entry || (skip_entry_phis && bb == entry->dest))
    8821                 :    70836519 :             continue;
    8822                 :             :         }
    8823                 :    51690622 :       rpo_state[i].iterate = iterate && has_backedges;
    8824                 :             :     }
    8825                 :     6204819 :   entry->flags |= EDGE_EXECUTABLE;
    8826                 :     6204819 :   entry->dest->flags |= BB_EXECUTABLE;
    8827                 :             : 
    8828                 :             :   /* As heuristic to improve compile-time we handle only the N innermost
    8829                 :             :      loops and the outermost one optimistically.  */
    8830                 :     6204819 :   if (iterate)
    8831                 :             :     {
    8832                 :     4340032 :       unsigned max_depth = param_rpo_vn_max_loop_depth;
    8833                 :    14567845 :       for (auto loop : loops_list (cfun, LI_ONLY_INNERMOST))
    8834                 :     1550041 :         if (loop_depth (loop) > max_depth)
    8835                 :        1949 :           for (unsigned i = 2;
    8836                 :        8482 :                i < loop_depth (loop) - max_depth; ++i)
    8837                 :             :             {
    8838                 :        1949 :               basic_block header = superloop_at_depth (loop, i)->header;
    8839                 :        1949 :               bool non_latch_backedge = false;
    8840                 :        1949 :               edge e;
    8841                 :        1949 :               edge_iterator ei;
    8842                 :        5878 :               FOR_EACH_EDGE (e, ei, header->preds)
    8843                 :        3929 :                 if (e->flags & EDGE_DFS_BACK)
    8844                 :             :                   {
    8845                 :             :                     /* There can be a non-latch backedge into the header
    8846                 :             :                        which is part of an outer irreducible region.  We
    8847                 :             :                        cannot avoid iterating this block then.  */
    8848                 :        1980 :                     if (!dominated_by_p (CDI_DOMINATORS,
    8849                 :        1980 :                                          e->src, e->dest))
    8850                 :             :                       {
    8851                 :          12 :                         if (dump_file && (dump_flags & TDF_DETAILS))
    8852                 :           0 :                           fprintf (dump_file, "non-latch backedge %d -> %d "
    8853                 :             :                                    "forces iteration of loop %d\n",
    8854                 :           0 :                                    e->src->index, e->dest->index, loop->num);
    8855                 :             :                         non_latch_backedge = true;
    8856                 :             :                       }
    8857                 :             :                     else
    8858                 :        1968 :                       e->flags |= EDGE_EXECUTABLE;
    8859                 :             :                   }
    8860                 :        1949 :               rpo_state[bb_to_rpo[header->index]].iterate = non_latch_backedge;
    8861                 :     4340032 :             }
    8862                 :             :     }
    8863                 :             : 
    8864                 :     6204819 :   uint64_t nblk = 0;
    8865                 :     6204819 :   int idx = 0;
    8866                 :     4340032 :   if (iterate)
    8867                 :             :     /* Go and process all blocks, iterating as necessary.  */
    8868                 :    49949041 :     do
    8869                 :             :       {
    8870                 :    49949041 :         basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[idx]);
    8871                 :             : 
    8872                 :             :         /* If the block has incoming backedges remember unwind state.  This
    8873                 :             :            is required even for non-executable blocks since in irreducible
    8874                 :             :            regions we might reach them via the backedge and re-start iterating
    8875                 :             :            from there.
    8876                 :             :            Note we can individually mark blocks with incoming backedges to
    8877                 :             :            not iterate where we then handle PHIs conservatively.  We do that
    8878                 :             :            heuristically to reduce compile-time for degenerate cases.  */
    8879                 :    49949041 :         if (rpo_state[idx].iterate)
    8880                 :             :           {
    8881                 :     4398367 :             rpo_state[idx].ob_top = obstack_alloc (&vn_tables_obstack, 0);
    8882                 :     4398367 :             rpo_state[idx].ref_top = last_inserted_ref;
    8883                 :     4398367 :             rpo_state[idx].phi_top = last_inserted_phi;
    8884                 :     4398367 :             rpo_state[idx].nary_top = last_inserted_nary;
    8885                 :     4398367 :             rpo_state[idx].avail_top
    8886                 :     4398367 :               = last_pushed_avail ? last_pushed_avail->avail : NULL;
    8887                 :             :           }
    8888                 :             : 
    8889                 :    49949041 :         if (!(bb->flags & BB_EXECUTABLE))
    8890                 :             :           {
    8891                 :      898170 :             if (dump_file && (dump_flags & TDF_DETAILS))
    8892                 :           2 :               fprintf (dump_file, "Block %d: BB%d found not executable\n",
    8893                 :             :                        idx, bb->index);
    8894                 :      898170 :             idx++;
    8895                 :     2805463 :             continue;
    8896                 :             :           }
    8897                 :             : 
    8898                 :    49050871 :         if (dump_file && (dump_flags & TDF_DETAILS))
    8899                 :         336 :           fprintf (dump_file, "Processing block %d: BB%d\n", idx, bb->index);
    8900                 :    49050871 :         nblk++;
    8901                 :    98101742 :         todo |= process_bb (avail, bb,
    8902                 :    49050871 :                             rpo_state[idx].visited != 0,
    8903                 :             :                             rpo_state[idx].iterate,
    8904                 :             :                             iterate, eliminate, do_region, exit_bbs, false);
    8905                 :    49050871 :         rpo_state[idx].visited++;
    8906                 :             : 
    8907                 :             :         /* Verify if changed values flow over executable outgoing backedges
    8908                 :             :            and those change destination PHI values (that's the thing we
    8909                 :             :            can easily verify).  Reduce over all such edges to the farthest
    8910                 :             :            away PHI.  */
    8911                 :    49050871 :         int iterate_to = -1;
    8912                 :    49050871 :         edge_iterator ei;
    8913                 :    49050871 :         edge e;
    8914                 :   118065666 :         FOR_EACH_EDGE (e, ei, bb->succs)
    8915                 :    69014795 :           if ((e->flags & (EDGE_DFS_BACK|EDGE_EXECUTABLE))
    8916                 :             :               == (EDGE_DFS_BACK|EDGE_EXECUTABLE)
    8917                 :     4408267 :               && rpo_state[bb_to_rpo[e->dest->index]].iterate)
    8918                 :             :             {
    8919                 :     4405599 :               int destidx = bb_to_rpo[e->dest->index];
    8920                 :     4405599 :               if (!rpo_state[destidx].visited)
    8921                 :             :                 {
    8922                 :         147 :                   if (dump_file && (dump_flags & TDF_DETAILS))
    8923                 :           0 :                     fprintf (dump_file, "Unvisited destination %d\n",
    8924                 :             :                              e->dest->index);
    8925                 :         147 :                   if (iterate_to == -1 || destidx < iterate_to)
    8926                 :         147 :                     iterate_to = destidx;
    8927                 :         147 :                   continue;
    8928                 :             :                 }
    8929                 :     4405452 :               if (dump_file && (dump_flags & TDF_DETAILS))
    8930                 :          53 :                 fprintf (dump_file, "Looking for changed values of backedge"
    8931                 :             :                          " %d->%d destination PHIs\n",
    8932                 :          53 :                          e->src->index, e->dest->index);
    8933                 :     4405452 :               vn_context_bb = e->dest;
    8934                 :     4405452 :               gphi_iterator gsi;
    8935                 :     4405452 :               for (gsi = gsi_start_phis (e->dest);
    8936                 :    10097720 :                    !gsi_end_p (gsi); gsi_next (&gsi))
    8937                 :             :                 {
    8938                 :     7599705 :                   bool inserted = false;
    8939                 :             :                   /* While we'd ideally just iterate on value changes
    8940                 :             :                      we CSE PHIs and do that even across basic-block
    8941                 :             :                      boundaries.  So even hashtable state changes can
    8942                 :             :                      be important (which is roughly equivalent to
    8943                 :             :                      PHI argument value changes).  To not excessively
    8944                 :             :                      iterate because of that we track whether a PHI
    8945                 :             :                      was CSEd to with GF_PLF_1.  */
    8946                 :     7599705 :                   bool phival_changed;
    8947                 :     7599705 :                   if ((phival_changed = visit_phi (gsi.phi (),
    8948                 :             :                                                    &inserted, false))
    8949                 :     8968398 :                       || (inserted && gimple_plf (gsi.phi (), GF_PLF_1)))
    8950                 :             :                     {
    8951                 :     1907437 :                       if (!phival_changed
    8952                 :     1907437 :                           && dump_file && (dump_flags & TDF_DETAILS))
    8953                 :           0 :                         fprintf (dump_file, "PHI was CSEd and hashtable "
    8954                 :             :                                  "state (changed)\n");
    8955                 :     1907437 :                       if (iterate_to == -1 || destidx < iterate_to)
    8956                 :     1907353 :                         iterate_to = destidx;
    8957                 :     1907437 :                       break;
    8958                 :             :                     }
    8959                 :             :                 }
    8960                 :     4405452 :               vn_context_bb = NULL;
    8961                 :             :             }
    8962                 :    49050871 :         if (iterate_to != -1)
    8963                 :             :           {
    8964                 :     1907293 :             do_unwind (&rpo_state[iterate_to], avail);
    8965                 :     1907293 :             idx = iterate_to;
    8966                 :     1907293 :             if (dump_file && (dump_flags & TDF_DETAILS))
    8967                 :          20 :               fprintf (dump_file, "Iterating to %d BB%d\n",
    8968                 :          20 :                        iterate_to, rpo[iterate_to]);
    8969                 :     1907293 :             continue;
    8970                 :             :           }
    8971                 :             : 
    8972                 :    47143578 :         idx++;
    8973                 :             :       }
    8974                 :    49949041 :     while (idx < n);
    8975                 :             : 
    8976                 :             :   else /* !iterate */
    8977                 :             :     {
    8978                 :             :       /* Process all blocks greedily with a worklist that enforces RPO
    8979                 :             :          processing of reachable blocks.  */
    8980                 :     1864787 :       auto_bitmap worklist;
    8981                 :     1864787 :       bitmap_set_bit (worklist, 0);
    8982                 :    17597682 :       while (!bitmap_empty_p (worklist))
    8983                 :             :         {
    8984                 :    13868108 :           int idx = bitmap_clear_first_set_bit (worklist);
    8985                 :    13868108 :           basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[idx]);
    8986                 :    13868108 :           gcc_assert ((bb->flags & BB_EXECUTABLE)
    8987                 :             :                       && !rpo_state[idx].visited);
    8988                 :             : 
    8989                 :    13868108 :           if (dump_file && (dump_flags & TDF_DETAILS))
    8990                 :       32406 :             fprintf (dump_file, "Processing block %d: BB%d\n", idx, bb->index);
    8991                 :             : 
    8992                 :             :           /* When we run into predecessor edges where we cannot trust its
    8993                 :             :              executable state mark them executable so PHI processing will
    8994                 :             :              be conservative.
    8995                 :             :              ???  Do we need to force arguments flowing over that edge
    8996                 :             :              to be varying or will they even always be?  */
    8997                 :    13868108 :           edge_iterator ei;
    8998                 :    13868108 :           edge e;
    8999                 :    33529141 :           FOR_EACH_EDGE (e, ei, bb->preds)
    9000                 :    19661033 :             if (!(e->flags & EDGE_EXECUTABLE)
    9001                 :     1012319 :                 && (bb == entry->dest
    9002                 :      960294 :                     || (!rpo_state[bb_to_rpo[e->src->index]].visited
    9003                 :      925731 :                         && (rpo_state[bb_to_rpo[e->src->index]].max_rpo
    9004                 :             :                             >= (int)idx))))
    9005                 :             :               {
    9006                 :      954095 :                 if (dump_file && (dump_flags & TDF_DETAILS))
    9007                 :       10407 :                   fprintf (dump_file, "Cannot trust state of predecessor "
    9008                 :             :                            "edge %d -> %d, marking executable\n",
    9009                 :       10407 :                            e->src->index, e->dest->index);
    9010                 :      954095 :                 e->flags |= EDGE_EXECUTABLE;
    9011                 :             :               }
    9012                 :             : 
    9013                 :    13868108 :           nblk++;
    9014                 :    13868108 :           todo |= process_bb (avail, bb, false, false, false, eliminate,
    9015                 :             :                               do_region, exit_bbs,
    9016                 :    13868108 :                               skip_entry_phis && bb == entry->dest);
    9017                 :    13868108 :           rpo_state[idx].visited++;
    9018                 :             : 
    9019                 :    34145796 :           FOR_EACH_EDGE (e, ei, bb->succs)
    9020                 :    20277688 :             if ((e->flags & EDGE_EXECUTABLE)
    9021                 :    20202801 :                 && e->dest->index != EXIT_BLOCK
    9022                 :    19037104 :                 && (!do_region || !bitmap_bit_p (exit_bbs, e->dest->index))
    9023                 :    38010898 :                 && !rpo_state[bb_to_rpo[e->dest->index]].visited)
    9024                 :    16783927 :               bitmap_set_bit (worklist, bb_to_rpo[e->dest->index]);
    9025                 :             :         }
    9026                 :     1864787 :     }
    9027                 :             : 
    9028                 :             :   /* If statistics or dump file active.  */
    9029                 :     6204819 :   int nex = 0;
    9030                 :     6204819 :   unsigned max_visited = 1;
    9031                 :    57895441 :   for (int i = 0; i < n; ++i)
    9032                 :             :     {
    9033                 :    51690622 :       basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
    9034                 :    51690622 :       if (bb->flags & BB_EXECUTABLE)
    9035                 :    51178692 :         nex++;
    9036                 :    51690622 :       statistics_histogram_event (cfun, "RPO block visited times",
    9037                 :    51690622 :                                   rpo_state[i].visited);
    9038                 :    51690622 :       if (rpo_state[i].visited > max_visited)
    9039                 :             :         max_visited = rpo_state[i].visited;
    9040                 :             :     }
    9041                 :     6204819 :   unsigned nvalues = 0, navail = 0;
    9042                 :   171840716 :   for (hash_table<vn_ssa_aux_hasher>::iterator i = vn_ssa_aux_hash->begin ();
    9043                 :   337476613 :        i != vn_ssa_aux_hash->end (); ++i)
    9044                 :             :     {
    9045                 :   165635897 :       nvalues++;
    9046                 :   165635897 :       vn_avail *av = (*i)->avail;
    9047                 :   244224082 :       while (av)
    9048                 :             :         {
    9049                 :    78588185 :           navail++;
    9050                 :    78588185 :           av = av->next;
    9051                 :             :         }
    9052                 :             :     }
    9053                 :     6204819 :   statistics_counter_event (cfun, "RPO blocks", n);
    9054                 :     6204819 :   statistics_counter_event (cfun, "RPO blocks visited", nblk);
    9055                 :     6204819 :   statistics_counter_event (cfun, "RPO blocks executable", nex);
    9056                 :     6204819 :   statistics_histogram_event (cfun, "RPO iterations", 10*nblk / nex);
    9057                 :     6204819 :   statistics_histogram_event (cfun, "RPO num values", nvalues);
    9058                 :     6204819 :   statistics_histogram_event (cfun, "RPO num avail", navail);
    9059                 :     6204819 :   statistics_histogram_event (cfun, "RPO num lattice",
    9060                 :     6204819 :                               vn_ssa_aux_hash->elements ());
    9061                 :     6204819 :   if (dump_file && (dump_flags & (TDF_DETAILS|TDF_STATS)))
    9062                 :             :     {
    9063                 :       10373 :       fprintf (dump_file, "RPO iteration over %d blocks visited %" PRIu64
    9064                 :             :                " blocks in total discovering %d executable blocks iterating "
    9065                 :             :                "%d.%d times, a block was visited max. %u times\n",
    9066                 :             :                n, nblk, nex,
    9067                 :       10373 :                (int)((10*nblk / nex)/10), (int)((10*nblk / nex)%10),
    9068                 :             :                max_visited);
    9069                 :       10373 :       fprintf (dump_file, "RPO tracked %d values available at %d locations "
    9070                 :             :                "and %" PRIu64 " lattice elements\n",
    9071                 :       10373 :                nvalues, navail, (uint64_t) vn_ssa_aux_hash->elements ());
    9072                 :             :     }
    9073                 :             : 
    9074                 :     6204819 :   if (eliminate)
    9075                 :             :     {
    9076                 :             :       /* When !iterate we already performed elimination during the RPO
    9077                 :             :          walk.  */
    9078                 :     5219150 :       if (iterate)
    9079                 :             :         {
    9080                 :             :           /* Elimination for region-based VN needs to be done within the
    9081                 :             :              RPO walk.  */
    9082                 :     3373699 :           gcc_assert (! do_region);
    9083                 :             :           /* Note we can't use avail.walk here because that gets confused
    9084                 :             :              by the existing availability and it will be less efficient
    9085                 :             :              as well.  */
    9086                 :     3373699 :           todo |= eliminate_with_rpo_vn (NULL);
    9087                 :             :         }
    9088                 :             :       else
    9089                 :     1845451 :         todo |= avail.eliminate_cleanup (do_region);
    9090                 :             :     }
    9091                 :             : 
    9092                 :     6204819 :   vn_valueize = NULL;
    9093                 :     6204819 :   rpo_avail = NULL;
    9094                 :             : 
    9095                 :     6204819 :   XDELETEVEC (bb_to_rpo);
    9096                 :     6204819 :   XDELETEVEC (rpo);
    9097                 :     6204819 :   XDELETEVEC (rpo_state);
    9098                 :             : 
    9099                 :     6204819 :   return todo;
    9100                 :     6204819 : }
    9101                 :             : 
    9102                 :             : /* Region-based entry for RPO VN.  Performs value-numbering and elimination
    9103                 :             :    on the SEME region specified by ENTRY and EXIT_BBS.  If ENTRY is not
    9104                 :             :    the only edge into the region at ENTRY->dest PHI nodes in ENTRY->dest
    9105                 :             :    are not considered.
    9106                 :             :    If ITERATE is true then treat backedges optimistically as not
    9107                 :             :    executed and iterate.  If ELIMINATE is true then perform
    9108                 :             :    elimination, otherwise leave that to the caller.
    9109                 :             :    If SKIP_ENTRY_PHIS is true then force PHI nodes in ENTRY->dest to VARYING.
    9110                 :             :    KIND specifies the amount of work done for handling memory operations.  */
    9111                 :             : 
    9112                 :             : unsigned
    9113                 :      688468 : do_rpo_vn (function *fn, edge entry, bitmap exit_bbs,
    9114                 :             :            bool iterate, bool eliminate, bool skip_entry_phis,
    9115                 :             :            vn_lookup_kind kind)
    9116                 :             : {
    9117                 :      688468 :   auto_timevar tv (TV_TREE_RPO_VN);
    9118                 :      688468 :   unsigned todo = do_rpo_vn_1 (fn, entry, exit_bbs, iterate, eliminate,
    9119                 :             :                                skip_entry_phis, kind);
    9120                 :      688468 :   free_rpo_vn ();
    9121                 :     1376936 :   return todo;
    9122                 :      688468 : }
    9123                 :             : 
    9124                 :             : 
    9125                 :             : namespace {
    9126                 :             : 
    9127                 :             : const pass_data pass_data_fre =
    9128                 :             : {
    9129                 :             :   GIMPLE_PASS, /* type */
    9130                 :             :   "fre", /* name */
    9131                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    9132                 :             :   TV_TREE_FRE, /* tv_id */
    9133                 :             :   ( PROP_cfg | PROP_ssa ), /* properties_required */
    9134                 :             :   0, /* properties_provided */
    9135                 :             :   0, /* properties_destroyed */
    9136                 :             :   0, /* todo_flags_start */
    9137                 :             :   0, /* todo_flags_finish */
    9138                 :             : };
    9139                 :             : 
    9140                 :             : class pass_fre : public gimple_opt_pass
    9141                 :             : {
    9142                 :             : public:
    9143                 :     1428445 :   pass_fre (gcc::context *ctxt)
    9144                 :     2856890 :     : gimple_opt_pass (pass_data_fre, ctxt), may_iterate (true)
    9145                 :             :   {}
    9146                 :             : 
    9147                 :             :   /* opt_pass methods: */
    9148                 :     1142756 :   opt_pass * clone () final override { return new pass_fre (m_ctxt); }
    9149                 :     1428445 :   void set_pass_param (unsigned int n, bool param) final override
    9150                 :             :     {
    9151                 :     1428445 :       gcc_assert (n == 0);
    9152                 :     1428445 :       may_iterate = param;
    9153                 :     1428445 :     }
    9154                 :     4627861 :   bool gate (function *) final override
    9155                 :             :     {
    9156                 :     4627861 :       return flag_tree_fre != 0 && (may_iterate || optimize > 1);
    9157                 :             :     }
    9158                 :             :   unsigned int execute (function *) final override;
    9159                 :             : 
    9160                 :             : private:
    9161                 :             :   bool may_iterate;
    9162                 :             : }; // class pass_fre
    9163                 :             : 
    9164                 :             : unsigned int
    9165                 :     4550018 : pass_fre::execute (function *fun)
    9166                 :             : {
    9167                 :     4550018 :   unsigned todo = 0;
    9168                 :             : 
    9169                 :             :   /* At -O[1g] use the cheap non-iterating mode.  */
    9170                 :     4550018 :   bool iterate_p = may_iterate && (optimize > 1);
    9171                 :     4550018 :   calculate_dominance_info (CDI_DOMINATORS);
    9172                 :     4550018 :   if (iterate_p)
    9173                 :     3373699 :     loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
    9174                 :             : 
    9175                 :     4550018 :   todo = do_rpo_vn_1 (fun, NULL, NULL, iterate_p, true, false, VN_WALKREWRITE);
    9176                 :     4550018 :   free_rpo_vn ();
    9177                 :             : 
    9178                 :     4550018 :   if (iterate_p)
    9179                 :     3373699 :     loop_optimizer_finalize ();
    9180                 :             : 
    9181                 :     4550018 :   if (scev_initialized_p ())
    9182                 :       29341 :     scev_reset_htab ();
    9183                 :             : 
    9184                 :             :   /* For late FRE after IVOPTs and unrolling, see if we can
    9185                 :             :      remove some TREE_ADDRESSABLE and rewrite stuff into SSA.  */
    9186                 :     4550018 :   if (!may_iterate)
    9187                 :      995449 :     todo |= TODO_update_address_taken;
    9188                 :             : 
    9189                 :     4550018 :   return todo;
    9190                 :             : }
    9191                 :             : 
    9192                 :             : } // anon namespace
    9193                 :             : 
    9194                 :             : gimple_opt_pass *
    9195                 :      285689 : make_pass_fre (gcc::context *ctxt)
    9196                 :             : {
    9197                 :      285689 :   return new pass_fre (ctxt);
    9198                 :             : }
    9199                 :             : 
    9200                 :             : #undef BB_EXECUTABLE
        

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