LCOV - code coverage report
Current view: top level - gcc - tree-ssa-sccvn.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 95.5 % 4471 4270
Test Date: 2025-03-15 13:07:15 Functions: 94.3 % 122 115
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                 :   726979840 : vn_nary_op_hasher::hash (const vn_nary_op_s *vno1)
     159                 :             : {
     160                 :   726979840 :   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                 :   919693496 : vn_nary_op_hasher::equal (const vn_nary_op_s *vno1, const vn_nary_op_s *vno2)
     168                 :             : {
     169                 :   919693496 :   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                 :    24746387 : vn_phi_hasher::hash (const vn_phi_s *vp1)
     191                 :             : {
     192                 :    24746387 :   return vp1->hashcode;
     193                 :             : }
     194                 :             : 
     195                 :             : /* Compare two phi entries for equality, ignoring VN_TOP arguments.  */
     196                 :             : 
     197                 :             : inline bool
     198                 :    43330852 : vn_phi_hasher::equal (const vn_phi_s *vp1, const vn_phi_s *vp2)
     199                 :             : {
     200                 :    43330852 :   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                 :    21194393 : vn_reference_op_eq (const void *p1, const void *p2)
     212                 :             : {
     213                 :    21194393 :   const_vn_reference_op_t const vro1 = (const_vn_reference_op_t) p1;
     214                 :    21194393 :   const_vn_reference_op_t const vro2 = (const_vn_reference_op_t) p2;
     215                 :             : 
     216                 :    21194393 :   return (vro1->opcode == vro2->opcode
     217                 :             :           /* We do not care for differences in type qualification.  */
     218                 :    21192434 :           && (vro1->type == vro2->type
     219                 :      728149 :               || (vro1->type && vro2->type
     220                 :      728149 :                   && types_compatible_p (TYPE_MAIN_VARIANT (vro1->type),
     221                 :      728149 :                                          TYPE_MAIN_VARIANT (vro2->type))))
     222                 :    20568349 :           && expressions_equal_p (vro1->op0, vro2->op0)
     223                 :    20553810 :           && expressions_equal_p (vro1->op1, vro2->op1)
     224                 :    20553810 :           && expressions_equal_p (vro1->op2, vro2->op2)
     225                 :    41748203 :           && (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                 :  3216931426 : vn_reference_hasher::hash (const vn_reference_s *vr1)
     249                 :             : {
     250                 :  3216931426 :   return vr1->hashcode;
     251                 :             : }
     252                 :             : 
     253                 :             : inline bool
     254                 :  3842147837 : vn_reference_hasher::equal (const vn_reference_s *v, const vn_reference_s *c)
     255                 :             : {
     256                 :  3842147837 :   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                 :         401 : print_vn_reference_ops (FILE *outfile, const vec<vn_reference_op_s> ops)
     266                 :             : {
     267                 :         401 :   vn_reference_op_t vro;
     268                 :         401 :   unsigned int i;
     269                 :         401 :   fprintf (outfile, "{");
     270                 :        1898 :   for (i = 0; ops.iterate (i, &vro); i++)
     271                 :             :     {
     272                 :        1497 :       bool closebrace = false;
     273                 :        1497 :       if (vro->opcode != SSA_NAME
     274                 :        1211 :           && TREE_CODE_CLASS (vro->opcode) != tcc_declaration)
     275                 :             :         {
     276                 :        1211 :           fprintf (outfile, "%s", get_tree_code_name (vro->opcode));
     277                 :        1211 :           if (vro->op0 || vro->opcode == CALL_EXPR)
     278                 :             :             {
     279                 :        1211 :               fprintf (outfile, "<");
     280                 :        1211 :               closebrace = true;
     281                 :             :             }
     282                 :             :         }
     283                 :        1497 :       if (vro->op0 || vro->opcode == CALL_EXPR)
     284                 :             :         {
     285                 :        1497 :           if (!vro->op0)
     286                 :           0 :             fprintf (outfile, internal_fn_name ((internal_fn)vro->clique));
     287                 :             :           else
     288                 :        1497 :             print_generic_expr (outfile, vro->op0);
     289                 :        1497 :           if (vro->op1)
     290                 :             :             {
     291                 :         257 :               fprintf (outfile, ",");
     292                 :         257 :               print_generic_expr (outfile, vro->op1);
     293                 :             :             }
     294                 :        1497 :           if (vro->op2)
     295                 :             :             {
     296                 :         257 :               fprintf (outfile, ",");
     297                 :         257 :               print_generic_expr (outfile, vro->op2);
     298                 :             :             }
     299                 :             :         }
     300                 :        1497 :       if (closebrace)
     301                 :        1211 :         fprintf (outfile, ">");
     302                 :        1497 :       if (i != ops.length () - 1)
     303                 :        1096 :         fprintf (outfile, ",");
     304                 :             :     }
     305                 :         401 :   fprintf (outfile, "}");
     306                 :         401 : }
     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                 :    11021827 : vn_constant_hasher::hash (const vn_constant_s *vc1)
     337                 :             : {
     338                 :    11021827 :   return vc1->hashcode;
     339                 :             : }
     340                 :             : 
     341                 :             : /* Hash table equality function for vn_constant_t.  */
     342                 :             : 
     343                 :             : inline bool
     344                 :    13261795 : vn_constant_hasher::equal (const vn_constant_s *vc1, const vn_constant_s *vc2)
     345                 :             : {
     346                 :    13261795 :   if (vc1->hashcode != vc2->hashcode)
     347                 :             :     return false;
     348                 :             : 
     349                 :     1998852 :   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                 :       74814 : vn_valueize_for_srt (tree t, void* context ATTRIBUTE_UNUSED)
     379                 :             : {
     380                 :       74814 :   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                 :       74814 :   if (!SSA_NAME_IS_DEFAULT_DEF (t))
     387                 :       72178 :     vn_context_bb = gimple_bb (SSA_NAME_DEF_STMT (t));
     388                 :       74814 :   tree res = vn_valueize (t);
     389                 :       74814 :   vn_context_bb = saved_vn_context_bb;
     390                 :       74814 :   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                 : >11810*10^7 :   static inline bool is_empty (value_type &e) { return e == NULL; }
     420                 :             : };
     421                 :             : 
     422                 :             : hashval_t
     423                 : 38994944899 : vn_ssa_aux_hasher::hash (const value_type &entry)
     424                 :             : {
     425                 : 38994944899 :   return SSA_NAME_VERSION (entry->name);
     426                 :             : }
     427                 :             : 
     428                 :             : bool
     429                 : 44553125379 : vn_ssa_aux_hasher::equal (const value_type &entry, const compare_type &name)
     430                 :             : {
     431                 : 44553125379 :   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                 :     4915555 : has_VN_INFO (tree name)
     452                 :             : {
     453                 :     4915555 :   return vn_ssa_aux_hash->find_with_hash (name, SSA_NAME_VERSION (name));
     454                 :             : }
     455                 :             : 
     456                 :             : vn_ssa_aux_t
     457                 :  3342088481 : VN_INFO (tree name)
     458                 :             : {
     459                 :  3342088481 :   vn_ssa_aux_t *res
     460                 :  3342088481 :     = vn_ssa_aux_hash->find_slot_with_hash (name, SSA_NAME_VERSION (name),
     461                 :             :                                             INSERT);
     462                 :  3342088481 :   if (*res != NULL)
     463                 :             :     return *res;
     464                 :             : 
     465                 :   161212187 :   vn_ssa_aux_t newinfo = *res = XOBNEW (&vn_ssa_aux_obstack, struct vn_ssa_aux);
     466                 :   161212187 :   memset (newinfo, 0, sizeof (struct vn_ssa_aux));
     467                 :   161212187 :   newinfo->name = name;
     468                 :   161212187 :   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                 :   161212187 :   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                 :   161212187 :   if (SSA_NAME_IS_DEFAULT_DEF (name))
     476                 :     8753014 :     switch (TREE_CODE (SSA_NAME_VAR (name)))
     477                 :             :       {
     478                 :     1577844 :       case VAR_DECL:
     479                 :             :         /* All undefined vars are VARYING.  */
     480                 :     1577844 :         newinfo->valnum = name;
     481                 :     1577844 :         newinfo->visited = true;
     482                 :     1577844 :         break;
     483                 :             : 
     484                 :     7122999 :       case PARM_DECL:
     485                 :             :         /* Parameters are VARYING but we can record a condition
     486                 :             :            if we know it is a non-NULL pointer.  */
     487                 :     7122999 :         newinfo->visited = true;
     488                 :     7122999 :         newinfo->valnum = name;
     489                 :    10926128 :         if (POINTER_TYPE_P (TREE_TYPE (name))
     490                 :     8110112 :             && nonnull_arg_p (SSA_NAME_VAR (name)))
     491                 :             :           {
     492                 :     2081636 :             tree ops[2];
     493                 :     2081636 :             ops[0] = name;
     494                 :     2081636 :             ops[1] = build_int_cst (TREE_TYPE (name), 0);
     495                 :     2081636 :             vn_nary_op_t nary;
     496                 :             :             /* Allocate from non-unwinding stack.  */
     497                 :     2081636 :             nary = alloc_vn_nary_op_noinit (2, &vn_tables_insert_obstack);
     498                 :     2081636 :             init_vn_nary_op_from_pieces (nary, 2, NE_EXPR,
     499                 :             :                                          boolean_type_node, ops);
     500                 :     2081636 :             nary->predicated_values = 0;
     501                 :     2081636 :             nary->u.result = boolean_true_node;
     502                 :     2081636 :             vn_nary_op_insert_into (nary, valid_info->nary);
     503                 :     2081636 :             gcc_assert (nary->unwind_to == NULL);
     504                 :             :             /* Also do not link it into the undo chain.  */
     505                 :     2081636 :             last_inserted_nary = nary->next;
     506                 :     2081636 :             nary->next = (vn_nary_op_t)(void *)-1;
     507                 :     2081636 :             nary = alloc_vn_nary_op_noinit (2, &vn_tables_insert_obstack);
     508                 :     2081636 :             init_vn_nary_op_from_pieces (nary, 2, EQ_EXPR,
     509                 :             :                                          boolean_type_node, ops);
     510                 :     2081636 :             nary->predicated_values = 0;
     511                 :     2081636 :             nary->u.result = boolean_false_node;
     512                 :     2081636 :             vn_nary_op_insert_into (nary, valid_info->nary);
     513                 :     2081636 :             gcc_assert (nary->unwind_to == NULL);
     514                 :     2081636 :             last_inserted_nary = nary->next;
     515                 :     2081636 :             nary->next = (vn_nary_op_t)(void *)-1;
     516                 :     2081636 :             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                 :       52171 :       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                 :       52171 :         newinfo->visited = true;
     530                 :       52171 :         newinfo->valnum = name;
     531                 :       52171 :         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                 :  3038076368 : SSA_VAL (tree x, bool *visited = NULL)
     543                 :             : {
     544                 :  3038076368 :   vn_ssa_aux_t tem = vn_ssa_aux_hash->find_with_hash (x, SSA_NAME_VERSION (x));
     545                 :  3038076368 :   if (visited)
     546                 :  1215396192 :     *visited = tem && tem->visited;
     547                 :  3038076368 :   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                 :  1106756568 : vuse_ssa_val (tree x)
     556                 :             : {
     557                 :  1106756568 :   if (!x)
     558                 :             :     return NULL_TREE;
     559                 :             : 
     560                 :  1103699174 :   do
     561                 :             :     {
     562                 :  1103699174 :       x = SSA_VAL (x);
     563                 :  1103699174 :       gcc_assert (x != VN_TOP);
     564                 :             :     }
     565                 :  1103699174 :   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                 :   924665852 : vuse_valueize (tree vuse)
     576                 :             : {
     577                 :   924665852 :   do
     578                 :             :     {
     579                 :   924665852 :       bool visited;
     580                 :   924665852 :       vuse = SSA_VAL (vuse, &visited);
     581                 :   924665852 :       if (!visited)
     582                 :    14159213 :         return NULL_TREE;
     583                 :   910506639 :       gcc_assert (vuse != VN_TOP);
     584                 :             :     }
     585                 :   910506639 :   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                 :    95563706 : vn_get_stmt_kind (gimple *stmt)
     595                 :             : {
     596                 :    95563706 :   switch (gimple_code (stmt))
     597                 :             :     {
     598                 :             :     case GIMPLE_CALL:
     599                 :             :       return VN_REFERENCE;
     600                 :             :     case GIMPLE_PHI:
     601                 :             :       return VN_PHI;
     602                 :    95563706 :     case GIMPLE_ASSIGN:
     603                 :    95563706 :       {
     604                 :    95563706 :         enum tree_code code = gimple_assign_rhs_code (stmt);
     605                 :    95563706 :         tree rhs1 = gimple_assign_rhs1 (stmt);
     606                 :    95563706 :         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                 :    44665941 :           case GIMPLE_SINGLE_RHS:
     613                 :    44665941 :             switch (TREE_CODE_CLASS (code))
     614                 :             :               {
     615                 :    33566440 :               case tcc_reference:
     616                 :             :                 /* VOP-less references can go through unary case.  */
     617                 :    33566440 :                 if ((code == REALPART_EXPR
     618                 :             :                      || code == IMAGPART_EXPR
     619                 :    33566440 :                      || code == VIEW_CONVERT_EXPR
     620                 :    33566440 :                      || code == BIT_FIELD_REF)
     621                 :    33566440 :                     && (TREE_CODE (TREE_OPERAND (rhs1, 0)) == SSA_NAME
     622                 :      634797 :                         || is_gimple_min_invariant (TREE_OPERAND (rhs1, 0))))
     623                 :     1874942 :                   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                 :     5539597 :               default:
     633                 :     5539597 :                 if (code == ADDR_EXPR)
     634                 :     3017121 :                   return (is_gimple_min_invariant (rhs1)
     635                 :     3017121 :                           ? VN_CONSTANT : VN_REFERENCE);
     636                 :     2522476 :                 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                 :    26227612 : get_or_alloc_constant_value_id (tree constant)
     671                 :             : {
     672                 :    26227612 :   vn_constant_s **slot;
     673                 :    26227612 :   struct vn_constant_s vc;
     674                 :    26227612 :   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                 :    26227612 :   if (!constant_to_value_id)
     679                 :             :     return 0;
     680                 :             : 
     681                 :     4344414 :   vc.hashcode = vn_hash_constant_with_type (constant);
     682                 :     4344414 :   vc.constant = constant;
     683                 :     4344414 :   slot = constant_to_value_id->find_slot (&vc, INSERT);
     684                 :     4344414 :   if (*slot)
     685                 :     1983005 :     return (*slot)->value_id;
     686                 :             : 
     687                 :     2361409 :   vcp = XNEW (struct vn_constant_s);
     688                 :     2361409 :   vcp->hashcode = vc.hashcode;
     689                 :     2361409 :   vcp->constant = constant;
     690                 :     2361409 :   vcp->value_id = get_next_constant_value_id ();
     691                 :     2361409 :   *slot = vcp;
     692                 :     2361409 :   return vcp->value_id;
     693                 :             : }
     694                 :             : 
     695                 :             : /* Compute the hash for a reference operand VRO1.  */
     696                 :             : 
     697                 :             : static void
     698                 :   121612375 : vn_reference_op_compute_hash (const vn_reference_op_t vro1, inchash::hash &hstate)
     699                 :             : {
     700                 :   121612375 :   hstate.add_int (vro1->opcode);
     701                 :   121612375 :   if (vro1->opcode == CALL_EXPR && !vro1->op0)
     702                 :      499965 :     hstate.add_int (vro1->clique);
     703                 :   121612375 :   if (vro1->op0)
     704                 :   116367839 :     inchash::add_expr (vro1->op0, hstate);
     705                 :   121612375 :   if (vro1->op1)
     706                 :    10913331 :     inchash::add_expr (vro1->op1, hstate);
     707                 :   121612375 :   if (vro1->op2)
     708                 :    12563920 :     inchash::add_expr (vro1->op2, hstate);
     709                 :   121612375 : }
     710                 :             : 
     711                 :             : /* Compute a hash for the reference operation VR1 and return it.  */
     712                 :             : 
     713                 :             : static hashval_t
     714                 :   182377399 : vn_reference_compute_hash (const vn_reference_t vr1)
     715                 :             : {
     716                 :   182377399 :   inchash::hash hstate;
     717                 :   182377399 :   hashval_t result;
     718                 :   182377399 :   int i;
     719                 :   182377399 :   vn_reference_op_t vro;
     720                 :   182377399 :   poly_int64 off = -1;
     721                 :   182377399 :   bool deref = false;
     722                 :             : 
     723                 :   755380722 :   FOR_EACH_VEC_ELT (vr1->operands, i, vro)
     724                 :             :     {
     725                 :   573003323 :       if (vro->opcode == MEM_REF)
     726                 :             :         deref = true;
     727                 :   400587642 :       else if (vro->opcode != ADDR_EXPR)
     728                 :   282892845 :         deref = false;
     729                 :   573003323 :       if (maybe_ne (vro->off, -1))
     730                 :             :         {
     731                 :   340895923 :           if (known_eq (off, -1))
     732                 :   174618391 :             off = 0;
     733                 :   573003323 :           off += vro->off;
     734                 :             :         }
     735                 :             :       else
     736                 :             :         {
     737                 :   232107400 :           if (maybe_ne (off, -1)
     738                 :   232107400 :               && maybe_ne (off, 0))
     739                 :    92346462 :             hstate.add_poly_int (off);
     740                 :   232107400 :           off = -1;
     741                 :   232107400 :           if (deref
     742                 :   110662086 :               && vro->opcode == ADDR_EXPR)
     743                 :             :             {
     744                 :   110495025 :               if (vro->op0)
     745                 :             :                 {
     746                 :   110495025 :                   tree op = TREE_OPERAND (vro->op0, 0);
     747                 :   110495025 :                   hstate.add_int (TREE_CODE (op));
     748                 :   110495025 :                   inchash::add_expr (op, hstate);
     749                 :             :                 }
     750                 :             :             }
     751                 :             :           else
     752                 :   121612375 :             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                 :   182377399 :   result = hstate.end ();
     758                 :             :   /* ??? We would ICE later if we hash instead of adding that in. */
     759                 :   182377399 :   if (vr1->vuse)
     760                 :   178374348 :     result += SSA_NAME_VERSION (vr1->vuse);
     761                 :             : 
     762                 :   182377399 :   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                 :  3837944368 : vn_reference_eq (const_vn_reference_t const vr1, const_vn_reference_t const vr2)
     770                 :             : {
     771                 :  3837944368 :   unsigned i, j;
     772                 :             : 
     773                 :             :   /* Early out if this is not a hash collision.  */
     774                 :  3837944368 :   if (vr1->hashcode != vr2->hashcode)
     775                 :             :     return false;
     776                 :             : 
     777                 :             :   /* The VOP needs to be the same.  */
     778                 :    15961208 :   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                 :    15960820 :   if (maybe_ne (vr1->offset, vr2->offset)
     784                 :    15960820 :       || maybe_ne (vr1->max_size, vr2->max_size))
     785                 :             :     {
     786                 :             :       /* But nothing known in the prevailing entry is OK to be used.  */
     787                 :     5939093 :       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                 :    31881146 :   if (vr1->operands == vr2->operands)
     793                 :             :     return true;
     794                 :             : 
     795                 :    15220067 :   if (!vr1->type || !vr2->type)
     796                 :             :     {
     797                 :      484677 :       if (vr1->type != vr2->type)
     798                 :             :         return false;
     799                 :             :     }
     800                 :    14735390 :   else if (vr1->type == vr2->type)
     801                 :             :     ;
     802                 :     1673668 :   else if (COMPLETE_TYPE_P (vr1->type) != COMPLETE_TYPE_P (vr2->type)
     803                 :     1673668 :            || (COMPLETE_TYPE_P (vr1->type)
     804                 :     1673668 :                && !expressions_equal_p (TYPE_SIZE (vr1->type),
     805                 :     1673668 :                                         TYPE_SIZE (vr2->type))))
     806                 :      677525 :     return false;
     807                 :      996143 :   else if (vr1->operands[0].opcode == CALL_EXPR
     808                 :      996143 :            && !types_compatible_p (vr1->type, vr2->type))
     809                 :             :     return false;
     810                 :      996143 :   else if (INTEGRAL_TYPE_P (vr1->type)
     811                 :      384311 :            && INTEGRAL_TYPE_P (vr2->type))
     812                 :             :     {
     813                 :      377256 :       if (TYPE_PRECISION (vr1->type) != TYPE_PRECISION (vr2->type))
     814                 :             :         return false;
     815                 :             :     }
     816                 :      618887 :   else if (INTEGRAL_TYPE_P (vr1->type)
     817                 :      618887 :            && (TYPE_PRECISION (vr1->type)
     818                 :        7055 :                != TREE_INT_CST_LOW (TYPE_SIZE (vr1->type))))
     819                 :             :     return false;
     820                 :      618735 :   else if (INTEGRAL_TYPE_P (vr2->type)
     821                 :      618735 :            && (TYPE_PRECISION (vr2->type)
     822                 :        7243 :                != TREE_INT_CST_LOW (TYPE_SIZE (vr2->type))))
     823                 :             :     return false;
     824                 :        7125 :   else if (VECTOR_BOOLEAN_TYPE_P (vr1->type)
     825                 :      618141 :            && 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                 :      618141 :   else if (TYPE_MODE (vr1->type) != TYPE_MODE (vr2->type)
     845                 :      618141 :            && (!mode_can_transfer_bits (TYPE_MODE (vr1->type))
     846                 :        9437 :                || !mode_can_transfer_bits (TYPE_MODE (vr2->type))))
     847                 :        1042 :     return false;
     848                 :             : 
     849                 :             :   i = 0;
     850                 :             :   j = 0;
     851                 :    17719813 :   do
     852                 :             :     {
     853                 :    17719813 :       poly_int64 off1 = 0, off2 = 0;
     854                 :    17719813 :       vn_reference_op_t vro1, vro2;
     855                 :    17719813 :       vn_reference_op_s tem1, tem2;
     856                 :    17719813 :       bool deref1 = false, deref2 = false;
     857                 :    17719813 :       bool reverse1 = false, reverse2 = false;
     858                 :    60377254 :       for (; vr1->operands.iterate (i, &vro1); i++)
     859                 :             :         {
     860                 :    42657441 :           if (vro1->opcode == MEM_REF)
     861                 :             :             deref1 = true;
     862                 :             :           /* Do not look through a storage order barrier.  */
     863                 :    29368325 :           else if (vro1->opcode == VIEW_CONVERT_EXPR && vro1->reverse)
     864                 :        4307 :             return false;
     865                 :    42657441 :           reverse1 |= vro1->reverse;
     866                 :    42657441 :           if (known_eq (vro1->off, -1))
     867                 :             :             break;
     868                 :    24937628 :           off1 += vro1->off;
     869                 :             :         }
     870                 :    42687025 :       for (; vr2->operands.iterate (j, &vro2); j++)
     871                 :             :         {
     872                 :    42687025 :           if (vro2->opcode == MEM_REF)
     873                 :             :             deref2 = true;
     874                 :             :           /* Do not look through a storage order barrier.  */
     875                 :    29397899 :           else if (vro2->opcode == VIEW_CONVERT_EXPR && vro2->reverse)
     876                 :             :             return false;
     877                 :    42687025 :           reverse2 |= vro2->reverse;
     878                 :    42687025 :           if (known_eq (vro2->off, -1))
     879                 :             :             break;
     880                 :    24967212 :           off2 += vro2->off;
     881                 :             :         }
     882                 :    17719813 :       if (maybe_ne (off1, off2) || reverse1 != reverse2)
     883                 :             :         return false;
     884                 :    17719691 :       if (deref1 && vro1->opcode == ADDR_EXPR)
     885                 :             :         {
     886                 :     7533813 :           memset (&tem1, 0, sizeof (tem1));
     887                 :     7533813 :           tem1.op0 = TREE_OPERAND (vro1->op0, 0);
     888                 :     7533813 :           tem1.type = TREE_TYPE (tem1.op0);
     889                 :     7533813 :           tem1.opcode = TREE_CODE (tem1.op0);
     890                 :     7533813 :           vro1 = &tem1;
     891                 :     7533813 :           deref1 = false;
     892                 :             :         }
     893                 :    17719691 :       if (deref2 && vro2->opcode == ADDR_EXPR)
     894                 :             :         {
     895                 :     7533823 :           memset (&tem2, 0, sizeof (tem2));
     896                 :     7533823 :           tem2.op0 = TREE_OPERAND (vro2->op0, 0);
     897                 :     7533823 :           tem2.type = TREE_TYPE (tem2.op0);
     898                 :     7533823 :           tem2.opcode = TREE_CODE (tem2.op0);
     899                 :     7533823 :           vro2 = &tem2;
     900                 :     7533823 :           deref2 = false;
     901                 :             :         }
     902                 :    17719691 :       if (deref1 != deref2)
     903                 :             :         return false;
     904                 :    17719691 :       if (!vn_reference_op_eq (vro1, vro2))
     905                 :             :         return false;
     906                 :    17715506 :       ++j;
     907                 :    17715506 :       ++i;
     908                 :             :     }
     909                 :    35431012 :   while (vr1->operands.length () != i
     910                 :    53146518 :          || 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                 :   202653242 : 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                 :   202653242 :   tree orig = ref;
     923                 :   705568925 :   while (ref)
     924                 :             :     {
     925                 :   502915683 :       vn_reference_op_s temp;
     926                 :             : 
     927                 :   502915683 :       memset (&temp, 0, sizeof (temp));
     928                 :   502915683 :       temp.type = TREE_TYPE (ref);
     929                 :   502915683 :       temp.opcode = TREE_CODE (ref);
     930                 :   502915683 :       temp.off = -1;
     931                 :             : 
     932                 :   502915683 :       switch (temp.opcode)
     933                 :             :         {
     934                 :    13992246 :         case MODIFY_EXPR:
     935                 :    13992246 :           temp.op0 = TREE_OPERAND (ref, 1);
     936                 :    13992246 :           break;
     937                 :         137 :         case WITH_SIZE_EXPR:
     938                 :         137 :           temp.op0 = TREE_OPERAND (ref, 1);
     939                 :         137 :           temp.off = 0;
     940                 :         137 :           break;
     941                 :    98206240 :         case MEM_REF:
     942                 :             :           /* The base address gets its own vn_reference_op_s structure.  */
     943                 :    98206240 :           temp.op0 = TREE_OPERAND (ref, 1);
     944                 :    98206240 :           if (!mem_ref_offset (ref).to_shwi (&temp.off))
     945                 :           0 :             temp.off = -1;
     946                 :    98206240 :           temp.clique = MR_DEPENDENCE_CLIQUE (ref);
     947                 :    98206240 :           temp.base = MR_DEPENDENCE_BASE (ref);
     948                 :    98206240 :           temp.reverse = REF_REVERSE_STORAGE_ORDER (ref);
     949                 :    98206240 :           break;
     950                 :     2233247 :         case TARGET_MEM_REF:
     951                 :             :           /* The base address gets its own vn_reference_op_s structure.  */
     952                 :     2233247 :           temp.op0 = TMR_INDEX (ref);
     953                 :     2233247 :           temp.op1 = TMR_STEP (ref);
     954                 :     2233247 :           temp.op2 = TMR_OFFSET (ref);
     955                 :     2233247 :           temp.clique = MR_DEPENDENCE_CLIQUE (ref);
     956                 :     2233247 :           temp.base = MR_DEPENDENCE_BASE (ref);
     957                 :     2233247 :           result->safe_push (temp);
     958                 :     2233247 :           memset (&temp, 0, sizeof (temp));
     959                 :     2233247 :           temp.type = NULL_TREE;
     960                 :     2233247 :           temp.opcode = ERROR_MARK;
     961                 :     2233247 :           temp.op0 = TMR_INDEX2 (ref);
     962                 :     2233247 :           temp.off = -1;
     963                 :     2233247 :           break;
     964                 :      635063 :         case BIT_FIELD_REF:
     965                 :             :           /* Record bits, position and storage order.  */
     966                 :      635063 :           temp.op0 = TREE_OPERAND (ref, 1);
     967                 :      635063 :           temp.op1 = TREE_OPERAND (ref, 2);
     968                 :     1269627 :           if (!multiple_p (bit_field_offset (ref), BITS_PER_UNIT, &temp.off))
     969                 :         499 :             temp.off = -1;
     970                 :      635063 :           temp.reverse = REF_REVERSE_STORAGE_ORDER (ref);
     971                 :      635063 :           break;
     972                 :   142110986 :         case COMPONENT_REF:
     973                 :             :           /* The field decl is enough to unambiguously specify the field,
     974                 :             :              so use its type here.  */
     975                 :   142110986 :           temp.type = TREE_TYPE (TREE_OPERAND (ref, 1));
     976                 :   142110986 :           temp.op0 = TREE_OPERAND (ref, 1);
     977                 :   142110986 :           temp.op1 = TREE_OPERAND (ref, 2);
     978                 :   284219628 :           temp.reverse = (AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (ref, 0)))
     979                 :   284217785 :                           && TYPE_REVERSE_STORAGE_ORDER
     980                 :             :                                (TREE_TYPE (TREE_OPERAND (ref, 0))));
     981                 :   142110986 :           {
     982                 :   142110986 :             tree this_offset = component_ref_field_offset (ref);
     983                 :   142110986 :             if (this_offset
     984                 :   142110986 :                 && poly_int_tree_p (this_offset))
     985                 :             :               {
     986                 :   142108904 :                 tree bit_offset = DECL_FIELD_BIT_OFFSET (TREE_OPERAND (ref, 1));
     987                 :   142108904 :                 if (TREE_INT_CST_LOW (bit_offset) % BITS_PER_UNIT == 0)
     988                 :             :                   {
     989                 :   141570015 :                     poly_offset_int off
     990                 :   141570015 :                       = (wi::to_poly_offset (this_offset)
     991                 :   141570015 :                          + (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                 :   141570015 :                     if (TREE_CODE (orig) != ADDR_EXPR
     997                 :     4427053 :                         || (TYPE_SIZE (temp.type)
     998                 :     4414084 :                             && integer_nonzerop (TYPE_SIZE (temp.type))
     999                 :     5689081 :                             && maybe_ne (off, 0))
    1000                 :   144231723 :                         || (cfun->curr_properties & PROP_objsz))
    1001                 :   140292955 :                       off.to_shwi (&temp.off);
    1002                 :             :                   }
    1003                 :             :               }
    1004                 :             :           }
    1005                 :             :           break;
    1006                 :    36827984 :         case ARRAY_RANGE_REF:
    1007                 :    36827984 :         case ARRAY_REF:
    1008                 :    36827984 :           {
    1009                 :    36827984 :             tree eltype = TREE_TYPE (TREE_TYPE (TREE_OPERAND (ref, 0)));
    1010                 :             :             /* Record index as operand.  */
    1011                 :    36827984 :             temp.op0 = TREE_OPERAND (ref, 1);
    1012                 :             :             /* Always record lower bounds and element size.  */
    1013                 :    36827984 :             temp.op1 = array_ref_low_bound (ref);
    1014                 :             :             /* But record element size in units of the type alignment.  */
    1015                 :    36827984 :             temp.op2 = TREE_OPERAND (ref, 3);
    1016                 :    36827984 :             temp.align = eltype->type_common.align;
    1017                 :    36827984 :             if (! temp.op2)
    1018                 :    36620491 :               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                 :    36827984 :             bool avoid_oob = true;
    1025                 :    36827984 :             if (TREE_CODE (orig) != ADDR_EXPR
    1026                 :      435815 :                 || cfun->curr_properties & PROP_objsz)
    1027                 :             :               avoid_oob = false;
    1028                 :      201943 :             else if (poly_int_tree_p (temp.op0))
    1029                 :             :               {
    1030                 :       65960 :                 tree ub = array_ref_up_bound (ref);
    1031                 :       65960 :                 if (ub
    1032                 :       64334 :                     && 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                 :       56382 :                     && !integer_minus_onep (ub)
    1037                 :      130294 :                     && known_le (wi::to_poly_offset (temp.op0),
    1038                 :             :                                  wi::to_poly_offset (ub)))
    1039                 :       55535 :                   avoid_oob = false;
    1040                 :             :               }
    1041                 :    36827984 :             if (poly_int_tree_p (temp.op0)
    1042                 :    21887612 :                 && poly_int_tree_p (temp.op1)
    1043                 :    21887612 :                 && TREE_CODE (temp.op2) == INTEGER_CST
    1044                 :    58655445 :                 && !avoid_oob)
    1045                 :             :               {
    1046                 :    43635782 :                 poly_offset_int off = ((wi::to_poly_offset (temp.op0)
    1047                 :    65453673 :                                         - wi::to_poly_offset (temp.op1))
    1048                 :    43635782 :                                        * wi::to_offset (temp.op2)
    1049                 :    21817891 :                                        * vn_ref_op_align_unit (&temp));
    1050                 :    21817891 :                 off.to_shwi (&temp.off);
    1051                 :             :               }
    1052                 :    36827984 :             temp.reverse = (AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (ref, 0)))
    1053                 :    36827984 :                             && TYPE_REVERSE_STORAGE_ORDER
    1054                 :             :                                  (TREE_TYPE (TREE_OPERAND (ref, 0))));
    1055                 :             :           }
    1056                 :    36827984 :           break;
    1057                 :    81436195 :         case VAR_DECL:
    1058                 :    81436195 :           if (DECL_HARD_REGISTER (ref))
    1059                 :             :             {
    1060                 :       20046 :               temp.op0 = ref;
    1061                 :       20046 :               break;
    1062                 :             :             }
    1063                 :             :           /* Fallthru.  */
    1064                 :    85704267 :         case PARM_DECL:
    1065                 :    85704267 :         case CONST_DECL:
    1066                 :    85704267 :         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                 :    85704267 :           temp.opcode = MEM_REF;
    1070                 :    85704267 :           temp.op0 = build_int_cst (build_pointer_type (TREE_TYPE (ref)), 0);
    1071                 :    85704267 :           temp.off = 0;
    1072                 :    85704267 :           result->safe_push (temp);
    1073                 :    85704267 :           temp.opcode = ADDR_EXPR;
    1074                 :    85704267 :           temp.op0 = build1 (ADDR_EXPR, TREE_TYPE (temp.op0), ref);
    1075                 :    85704267 :           temp.type = TREE_TYPE (temp.op0);
    1076                 :    85704267 :           temp.off = -1;
    1077                 :    85704267 :           break;
    1078                 :    85568090 :         case STRING_CST:
    1079                 :    85568090 :         case INTEGER_CST:
    1080                 :    85568090 :         case POLY_INT_CST:
    1081                 :    85568090 :         case COMPLEX_CST:
    1082                 :    85568090 :         case VECTOR_CST:
    1083                 :    85568090 :         case REAL_CST:
    1084                 :    85568090 :         case FIXED_CST:
    1085                 :    85568090 :         case CONSTRUCTOR:
    1086                 :    85568090 :         case SSA_NAME:
    1087                 :    85568090 :           temp.op0 = ref;
    1088                 :    85568090 :           break;
    1089                 :    35211435 :         case ADDR_EXPR:
    1090                 :    35211435 :           if (is_gimple_min_invariant (ref))
    1091                 :             :             {
    1092                 :    31360839 :               temp.op0 = ref;
    1093                 :    31360839 :               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                 :      465526 :         case REALPART_EXPR:
    1102                 :      465526 :           temp.off = 0;
    1103                 :      465526 :           break;
    1104                 :     1466234 :         case VIEW_CONVERT_EXPR:
    1105                 :     1466234 :           temp.off = 0;
    1106                 :     1466234 :           temp.reverse = storage_order_barrier_p (ref);
    1107                 :     1466234 :           break;
    1108                 :      474182 :         case IMAGPART_EXPR:
    1109                 :             :           /* This is only interesting for its constant offset.  */
    1110                 :      474182 :           temp.off = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (ref)));
    1111                 :      474182 :           break;
    1112                 :           0 :         default:
    1113                 :           0 :           gcc_unreachable ();
    1114                 :             :         }
    1115                 :   502915683 :       result->safe_push (temp);
    1116                 :             : 
    1117                 :   502915683 :       if (REFERENCE_CLASS_P (ref)
    1118                 :   220496221 :           || TREE_CODE (ref) == MODIFY_EXPR
    1119                 :   206503975 :           || TREE_CODE (ref) == WITH_SIZE_EXPR
    1120                 :   709419521 :           || (TREE_CODE (ref) == ADDR_EXPR
    1121                 :    35211435 :               && !is_gimple_min_invariant (ref)))
    1122                 :   300262441 :         ref = TREE_OPERAND (ref, 0);
    1123                 :             :       else
    1124                 :             :         ref = NULL_TREE;
    1125                 :             :     }
    1126                 :   202653242 : }
    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                 :    12822696 : 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                 :    12822696 :   unsigned i;
    1138                 :    12822696 :   tree base = NULL_TREE;
    1139                 :    12822696 :   tree *op0_p = &base;
    1140                 :    12822696 :   poly_offset_int offset = 0;
    1141                 :    12822696 :   poly_offset_int max_size;
    1142                 :    12822696 :   poly_offset_int size = -1;
    1143                 :    12822696 :   tree size_tree = NULL_TREE;
    1144                 :             : 
    1145                 :             :   /* We don't handle calls.  */
    1146                 :    12822696 :   if (!type)
    1147                 :             :     return false;
    1148                 :             : 
    1149                 :    12822696 :   machine_mode mode = TYPE_MODE (type);
    1150                 :    12822696 :   if (mode == BLKmode)
    1151                 :      230505 :     size_tree = TYPE_SIZE (type);
    1152                 :             :   else
    1153                 :    25184382 :     size = GET_MODE_BITSIZE (mode);
    1154                 :    12592191 :   if (size_tree != NULL_TREE
    1155                 :      230505 :       && poly_int_tree_p (size_tree))
    1156                 :      230505 :     size = wi::to_poly_offset (size_tree);
    1157                 :             : 
    1158                 :             :   /* Lower the final access size from the outermost expression.  */
    1159                 :    12822696 :   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                 :    12822696 :   vn_reference_op_t op = const_cast<vn_reference_op_t>(cst_op);
    1163                 :    12822696 :   size_tree = NULL_TREE;
    1164                 :    12822696 :   if (op->opcode == COMPONENT_REF)
    1165                 :     4593067 :     size_tree = DECL_SIZE (op->op0);
    1166                 :     8229629 :   else if (op->opcode == BIT_FIELD_REF)
    1167                 :       44460 :     size_tree = op->op0;
    1168                 :     4637527 :   if (size_tree != NULL_TREE
    1169                 :     4637527 :       && poly_int_tree_p (size_tree)
    1170                 :     9275054 :       && (!known_size_p (size)
    1171                 :    12822696 :           || known_lt (wi::to_poly_offset (size_tree), size)))
    1172                 :       29821 :     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                 :    12822696 :   max_size = size;
    1177                 :             : 
    1178                 :             :   /* Compute cumulative bit-offset for nested component-refs and array-refs,
    1179                 :             :      and find the ultimate containing object.  */
    1180                 :    49938715 :   FOR_EACH_VEC_ELT (ops, i, op)
    1181                 :             :     {
    1182                 :    37255971 :       switch (op->opcode)
    1183                 :             :         {
    1184                 :             :         case CALL_EXPR:
    1185                 :             :           return false;
    1186                 :             : 
    1187                 :             :         /* Record the base objects.  */
    1188                 :    12458878 :         case MEM_REF:
    1189                 :    12458878 :           *op0_p = build2 (MEM_REF, op->type,
    1190                 :             :                            NULL_TREE, op->op0);
    1191                 :    12458878 :           MR_DEPENDENCE_CLIQUE (*op0_p) = op->clique;
    1192                 :    12458878 :           MR_DEPENDENCE_BASE (*op0_p) = op->base;
    1193                 :    12458878 :           op0_p = &TREE_OPERAND (*op0_p, 0);
    1194                 :    12458878 :           break;
    1195                 :             : 
    1196                 :      223344 :         case TARGET_MEM_REF:
    1197                 :      670032 :           *op0_p = build5 (TARGET_MEM_REF, op->type,
    1198                 :             :                            NULL_TREE, op->op2, op->op0,
    1199                 :      223344 :                            op->op1, ops[i+1].op0);
    1200                 :      223344 :           MR_DEPENDENCE_CLIQUE (*op0_p) = op->clique;
    1201                 :      223344 :           MR_DEPENDENCE_BASE (*op0_p) = op->base;
    1202                 :      223344 :           op0_p = &TREE_OPERAND (*op0_p, 0);
    1203                 :      223344 :           ++i;
    1204                 :      223344 :           break;
    1205                 :             : 
    1206                 :             :         /* Unwrap some of the wrapped decls.  */
    1207                 :     6227503 :         case ADDR_EXPR:
    1208                 :             :           /* Apart from ADDR_EXPR arguments to MEM_REF.  */
    1209                 :     6227503 :           if (base != NULL_TREE
    1210                 :     6227503 :               && TREE_CODE (base) == MEM_REF
    1211                 :     6195194 :               && op->op0
    1212                 :    12422697 :               && DECL_P (TREE_OPERAND (op->op0, 0)))
    1213                 :             :             {
    1214                 :     6192234 :               const_vn_reference_op_t pop = &ops[i-1];
    1215                 :     6192234 :               base = TREE_OPERAND (op->op0, 0);
    1216                 :     6192234 :               if (known_eq (pop->off, -1))
    1217                 :             :                 {
    1218                 :          51 :                   max_size = -1;
    1219                 :          51 :                   offset = 0;
    1220                 :             :                 }
    1221                 :             :               else
    1222                 :     6192183 :                 offset += pop->off * BITS_PER_UNIT;
    1223                 :             :               op0_p = NULL;
    1224                 :             :               break;
    1225                 :             :             }
    1226                 :             :           /* Fallthru.  */
    1227                 :     6490510 :         case PARM_DECL:
    1228                 :     6490510 :         case CONST_DECL:
    1229                 :     6490510 :         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                 :     6490510 :         case VAR_DECL:
    1233                 :             :           /* ???  And for this only have DECL_HARD_REGISTER.  */
    1234                 :     6490510 :         case STRING_CST:
    1235                 :             :           /* This can show up in ARRAY_REF bases.  */
    1236                 :     6490510 :         case INTEGER_CST:
    1237                 :     6490510 :         case SSA_NAME:
    1238                 :     6490510 :           *op0_p = op->op0;
    1239                 :     6490510 :           op0_p = NULL;
    1240                 :     6490510 :           break;
    1241                 :             : 
    1242                 :             :         /* And now the usual component-reference style ops.  */
    1243                 :       44460 :         case BIT_FIELD_REF:
    1244                 :       44460 :           offset += wi::to_poly_offset (op->op1);
    1245                 :       44460 :           break;
    1246                 :             : 
    1247                 :     7629296 :         case COMPONENT_REF:
    1248                 :     7629296 :           {
    1249                 :     7629296 :             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                 :     7629296 :             tree this_offset = DECL_FIELD_OFFSET (field);
    1254                 :             : 
    1255                 :     7629296 :             if (op->op1 || !poly_int_tree_p (this_offset))
    1256                 :         196 :               max_size = -1;
    1257                 :             :             else
    1258                 :             :               {
    1259                 :     7629100 :                 poly_offset_int woffset = (wi::to_poly_offset (this_offset)
    1260                 :     7629100 :                                            << LOG2_BITS_PER_UNIT);
    1261                 :     7629100 :                 woffset += wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
    1262                 :     7629100 :                 offset += woffset;
    1263                 :             :               }
    1264                 :             :             break;
    1265                 :             :           }
    1266                 :             : 
    1267                 :     2804811 :         case ARRAY_RANGE_REF:
    1268                 :     2804811 :         case ARRAY_REF:
    1269                 :             :           /* Use the recorded constant offset.  */
    1270                 :     2804811 :           if (maybe_eq (op->off, -1))
    1271                 :      956420 :             max_size = -1;
    1272                 :             :           else
    1273                 :     1848391 :             offset += op->off * BITS_PER_UNIT;
    1274                 :             :           break;
    1275                 :             : 
    1276                 :             :         case REALPART_EXPR:
    1277                 :             :           break;
    1278                 :             : 
    1279                 :             :         case IMAGPART_EXPR:
    1280                 :    37116019 :           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                 :    12682744 :   if (base == NULL_TREE)
    1300                 :             :     return false;
    1301                 :             : 
    1302                 :    12682744 :   ref->ref = NULL_TREE;
    1303                 :    12682744 :   ref->base = base;
    1304                 :    12682744 :   ref->ref_alias_set = set;
    1305                 :    12682744 :   ref->base_alias_set = base_set;
    1306                 :             :   /* We discount volatiles from value-numbering elsewhere.  */
    1307                 :    12682744 :   ref->volatile_p = false;
    1308                 :             : 
    1309                 :    12682744 :   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                 :    12682744 :   if (!offset.to_shwi (&ref->offset))
    1318                 :             :     {
    1319                 :           0 :       ref->offset = 0;
    1320                 :           0 :       ref->max_size = -1;
    1321                 :           0 :       return true;
    1322                 :             :     }
    1323                 :             : 
    1324                 :    12682744 :   if (!max_size.to_shwi (&ref->max_size) || maybe_lt (ref->max_size, 0))
    1325                 :      813471 :     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                 :     8698470 : copy_reference_ops_from_call (gcall *call,
    1335                 :             :                               vec<vn_reference_op_s> *result)
    1336                 :             : {
    1337                 :     8698470 :   vn_reference_op_s temp;
    1338                 :     8698470 :   unsigned i;
    1339                 :     8698470 :   tree lhs = gimple_call_lhs (call);
    1340                 :     8698470 :   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                 :     8698470 :   if (lhs && TREE_CODE (lhs) != SSA_NAME)
    1346                 :             :     {
    1347                 :      435714 :       memset (&temp, 0, sizeof (temp));
    1348                 :      435714 :       temp.opcode = MODIFY_EXPR;
    1349                 :      435714 :       temp.type = TREE_TYPE (lhs);
    1350                 :      435714 :       temp.op0 = lhs;
    1351                 :      435714 :       temp.off = -1;
    1352                 :      435714 :       result->safe_push (temp);
    1353                 :             :     }
    1354                 :             : 
    1355                 :             :   /* Copy the type, opcode, function, static chain and EH region, if any.  */
    1356                 :     8698470 :   memset (&temp, 0, sizeof (temp));
    1357                 :     8698470 :   temp.type = gimple_call_fntype (call);
    1358                 :     8698470 :   temp.opcode = CALL_EXPR;
    1359                 :     8698470 :   temp.op0 = gimple_call_fn (call);
    1360                 :     8698470 :   if (gimple_call_internal_p (call))
    1361                 :      488096 :     temp.clique = gimple_call_internal_fn (call);
    1362                 :     8698470 :   temp.op1 = gimple_call_chain (call);
    1363                 :     8698470 :   if (stmt_could_throw_p (cfun, call) && (lr = lookup_stmt_eh_lp (call)) > 0)
    1364                 :      692529 :     temp.op2 = size_int (lr);
    1365                 :     8698470 :   temp.off = -1;
    1366                 :     8698470 :   result->safe_push (temp);
    1367                 :             : 
    1368                 :             :   /* Copy the call arguments.  As they can be references as well,
    1369                 :             :      just chain them together.  */
    1370                 :    25938527 :   for (i = 0; i < gimple_call_num_args (call); ++i)
    1371                 :             :     {
    1372                 :    17240057 :       tree callarg = gimple_call_arg (call, i);
    1373                 :    17240057 :       copy_reference_ops_from_ref (callarg, result);
    1374                 :             :     }
    1375                 :     8698470 : }
    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                 :   120072637 : vn_reference_fold_indirect (vec<vn_reference_op_s> *ops,
    1381                 :             :                             unsigned int *i_p)
    1382                 :             : {
    1383                 :   120072637 :   unsigned int i = *i_p;
    1384                 :   120072637 :   vn_reference_op_t op = &(*ops)[i];
    1385                 :   120072637 :   vn_reference_op_t mem_op = &(*ops)[i - 1];
    1386                 :   120072637 :   tree addr_base;
    1387                 :   120072637 :   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                 :   120072637 :   addr_base = get_addr_base_and_unit_offset_1 (TREE_OPERAND (op->op0, 0),
    1393                 :             :                                                &addr_offset, vn_valueize);
    1394                 :   120072637 :   gcc_checking_assert (addr_base && TREE_CODE (addr_base) != MEM_REF);
    1395                 :   120072637 :   if (addr_base != TREE_OPERAND (op->op0, 0))
    1396                 :             :     {
    1397                 :      517225 :       poly_offset_int off
    1398                 :      517225 :         = (poly_offset_int::from (wi::to_poly_wide (mem_op->op0),
    1399                 :             :                                   SIGNED)
    1400                 :      517225 :            + addr_offset);
    1401                 :      517225 :       mem_op->op0 = wide_int_to_tree (TREE_TYPE (mem_op->op0), off);
    1402                 :      517225 :       op->op0 = build_fold_addr_expr (addr_base);
    1403                 :      517225 :       if (tree_fits_shwi_p (mem_op->op0))
    1404                 :      517156 :         mem_op->off = tree_to_shwi (mem_op->op0);
    1405                 :             :       else
    1406                 :          69 :         mem_op->off = -1;
    1407                 :      517225 :       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                 :    77834099 : vn_reference_maybe_forwprop_address (vec<vn_reference_op_s> *ops,
    1416                 :             :                                      unsigned int *i_p)
    1417                 :             : {
    1418                 :    77834099 :   bool changed = false;
    1419                 :    84245041 :   vn_reference_op_t op;
    1420                 :             : 
    1421                 :    84245041 :   do
    1422                 :             :     {
    1423                 :    84245041 :       unsigned int i = *i_p;
    1424                 :    84245041 :       op = &(*ops)[i];
    1425                 :    84245041 :       vn_reference_op_t mem_op = &(*ops)[i - 1];
    1426                 :    84245041 :       gimple *def_stmt;
    1427                 :    84245041 :       enum tree_code code;
    1428                 :    84245041 :       poly_offset_int off;
    1429                 :             : 
    1430                 :    84245041 :       def_stmt = SSA_NAME_DEF_STMT (op->op0);
    1431                 :    84245041 :       if (!is_gimple_assign (def_stmt))
    1432                 :    77833748 :         return changed;
    1433                 :             : 
    1434                 :    33865565 :       code = gimple_assign_rhs_code (def_stmt);
    1435                 :    33865565 :       if (code != ADDR_EXPR
    1436                 :    33865565 :           && code != POINTER_PLUS_EXPR)
    1437                 :             :         return changed;
    1438                 :             : 
    1439                 :    17616322 :       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                 :    17616322 :       if (code == ADDR_EXPR)
    1445                 :             :         {
    1446                 :      821090 :           tree addr, addr_base;
    1447                 :      821090 :           poly_int64 addr_offset;
    1448                 :             : 
    1449                 :      821090 :           addr = gimple_assign_rhs1 (def_stmt);
    1450                 :      821090 :           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                 :      821090 :           if (!addr_base
    1457                 :      202668 :               && *i_p == ops->length () - 1
    1458                 :      101334 :               && 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                 :      899605 :               && default_vn_walk_kind == VN_WALKREWRITE)
    1463                 :             :             {
    1464                 :       78417 :               auto_vec<vn_reference_op_s, 32> tem;
    1465                 :       78417 :               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                 :       78417 :               if (tem.length () >= 2
    1470                 :       78417 :                   && tem[tem.length () - 2].opcode == MEM_REF)
    1471                 :             :                 {
    1472                 :       78402 :                   vn_reference_op_t new_mem_op = &tem[tem.length () - 2];
    1473                 :       78402 :                   new_mem_op->op0
    1474                 :       78402 :                       = wide_int_to_tree (TREE_TYPE (mem_op->op0),
    1475                 :      156804 :                                           wi::to_poly_wide (new_mem_op->op0));
    1476                 :             :                 }
    1477                 :             :               else
    1478                 :          15 :                 gcc_assert (tem.last ().opcode == STRING_CST);
    1479                 :       78417 :               ops->pop ();
    1480                 :       78417 :               ops->pop ();
    1481                 :       78417 :               ops->safe_splice (tem);
    1482                 :       78417 :               --*i_p;
    1483                 :       78417 :               return true;
    1484                 :       78417 :             }
    1485                 :      742673 :           if (!addr_base
    1486                 :      719756 :               || TREE_CODE (addr_base) != MEM_REF
    1487                 :     1461564 :               || (TREE_CODE (TREE_OPERAND (addr_base, 0)) == SSA_NAME
    1488                 :      718630 :                   && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (addr_base,
    1489                 :             :                                                                     0))))
    1490                 :             :             return changed;
    1491                 :             : 
    1492                 :      718891 :           off += addr_offset;
    1493                 :      718891 :           off += mem_ref_offset (addr_base);
    1494                 :      718891 :           op->op0 = TREE_OPERAND (addr_base, 0);
    1495                 :             :         }
    1496                 :             :       else
    1497                 :             :         {
    1498                 :    16795232 :           tree ptr, ptroff;
    1499                 :    16795232 :           ptr = gimple_assign_rhs1 (def_stmt);
    1500                 :    16795232 :           ptroff = gimple_assign_rhs2 (def_stmt);
    1501                 :    16795232 :           if (TREE_CODE (ptr) != SSA_NAME
    1502                 :    15394598 :               || 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                 :    15393184 :               || SSA_VAL (ptr) == op->op0
    1507                 :    32188416 :               || !poly_int_tree_p (ptroff))
    1508                 :    11102830 :             return changed;
    1509                 :             : 
    1510                 :     5692402 :           off += wi::to_poly_offset (ptroff);
    1511                 :     5692402 :           op->op0 = ptr;
    1512                 :             :         }
    1513                 :             : 
    1514                 :     6411293 :       mem_op->op0 = wide_int_to_tree (TREE_TYPE (mem_op->op0), off);
    1515                 :     6411293 :       if (tree_fits_shwi_p (mem_op->op0))
    1516                 :     6223978 :         mem_op->off = tree_to_shwi (mem_op->op0);
    1517                 :             :       else
    1518                 :      187315 :         mem_op->off = -1;
    1519                 :             :       /* ???  Can end up with endless recursion here!?
    1520                 :             :          gcc.c-torture/execute/strcmp-1.c  */
    1521                 :     6411293 :       if (TREE_CODE (op->op0) == SSA_NAME)
    1522                 :     6411032 :         op->op0 = SSA_VAL (op->op0);
    1523                 :     6411293 :       if (TREE_CODE (op->op0) != SSA_NAME)
    1524                 :         351 :         op->opcode = TREE_CODE (op->op0);
    1525                 :             : 
    1526                 :     6411293 :       changed = true;
    1527                 :             :     }
    1528                 :             :   /* Tail-recurse.  */
    1529                 :     6411293 :   while (TREE_CODE (op->op0) == SSA_NAME);
    1530                 :             : 
    1531                 :             :   /* Fold a remaining *&.  */
    1532                 :         351 :   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                 :   100512706 : fully_constant_vn_reference_p (vn_reference_t ref)
    1543                 :             : {
    1544                 :   100512706 :   vec<vn_reference_op_s> operands = ref->operands;
    1545                 :   100512706 :   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                 :   100512706 :   op = &operands[0];
    1550                 :   100512706 :   if (op->opcode == CALL_EXPR
    1551                 :       81201 :       && (!op->op0
    1552                 :       75202 :           || (TREE_CODE (op->op0) == ADDR_EXPR
    1553                 :       75202 :               && TREE_CODE (TREE_OPERAND (op->op0, 0)) == FUNCTION_DECL
    1554                 :       75202 :               && fndecl_built_in_p (TREE_OPERAND (op->op0, 0),
    1555                 :             :                                     BUILT_IN_NORMAL)))
    1556                 :       68629 :       && operands.length () >= 2
    1557                 :   100581299 :       && operands.length () <= 3)
    1558                 :             :     {
    1559                 :       33318 :       vn_reference_op_t arg0, arg1 = NULL;
    1560                 :       33318 :       bool anyconst = false;
    1561                 :       33318 :       arg0 = &operands[1];
    1562                 :       33318 :       if (operands.length () > 2)
    1563                 :        4598 :         arg1 = &operands[2];
    1564                 :       33318 :       if (TREE_CODE_CLASS (arg0->opcode) == tcc_constant
    1565                 :       33318 :           || (arg0->opcode == ADDR_EXPR
    1566                 :       13310 :               && is_gimple_min_invariant (arg0->op0)))
    1567                 :             :         anyconst = true;
    1568                 :       33318 :       if (arg1
    1569                 :       33318 :           && (TREE_CODE_CLASS (arg1->opcode) == tcc_constant
    1570                 :        3782 :               || (arg1->opcode == ADDR_EXPR
    1571                 :         575 :                   && is_gimple_min_invariant (arg1->op0))))
    1572                 :             :         anyconst = true;
    1573                 :       31927 :       if (anyconst)
    1574                 :             :         {
    1575                 :       20592 :           combined_fn fn;
    1576                 :       20592 :           if (op->op0)
    1577                 :       20318 :             fn = as_combined_fn (DECL_FUNCTION_CODE
    1578                 :       20318 :                                         (TREE_OPERAND (op->op0, 0)));
    1579                 :             :           else
    1580                 :         274 :             fn = as_combined_fn ((internal_fn) op->clique);
    1581                 :       20592 :           tree folded;
    1582                 :       20592 :           if (arg1)
    1583                 :        1958 :             folded = fold_const_call (fn, ref->type, arg0->op0, arg1->op0);
    1584                 :             :           else
    1585                 :       18634 :             folded = fold_const_call (fn, ref->type, arg0->op0);
    1586                 :       20592 :           if (folded
    1587                 :       20592 :               && is_gimple_min_invariant (folded))
    1588                 :             :             return folded;
    1589                 :             :         }
    1590                 :             :     }
    1591                 :             : 
    1592                 :             :   /* Simplify reads from constants or constant initializers.  */
    1593                 :   100479388 :   else if (BITS_PER_UNIT == 8
    1594                 :   100479388 :            && ref->type
    1595                 :   100479388 :            && COMPLETE_TYPE_P (ref->type)
    1596                 :   200958734 :            && is_gimple_reg_type (ref->type))
    1597                 :             :     {
    1598                 :    96167914 :       poly_int64 off = 0;
    1599                 :    96167914 :       HOST_WIDE_INT size;
    1600                 :    96167914 :       if (INTEGRAL_TYPE_P (ref->type))
    1601                 :    48741637 :         size = TYPE_PRECISION (ref->type);
    1602                 :    47426277 :       else if (tree_fits_shwi_p (TYPE_SIZE (ref->type)))
    1603                 :    47426277 :         size = tree_to_shwi (TYPE_SIZE (ref->type));
    1604                 :             :       else
    1605                 :   100512706 :         return NULL_TREE;
    1606                 :    96167914 :       if (size % BITS_PER_UNIT != 0
    1607                 :    94483201 :           || size > MAX_BITSIZE_MODE_ANY_MODE)
    1608                 :             :         return NULL_TREE;
    1609                 :    94482089 :       size /= BITS_PER_UNIT;
    1610                 :    94482089 :       unsigned i;
    1611                 :   181924897 :       for (i = 0; i < operands.length (); ++i)
    1612                 :             :         {
    1613                 :   181924897 :           if (TREE_CODE_CLASS (operands[i].opcode) == tcc_constant)
    1614                 :             :             {
    1615                 :         308 :               ++i;
    1616                 :         308 :               break;
    1617                 :             :             }
    1618                 :   181924589 :           if (known_eq (operands[i].off, -1))
    1619                 :             :             return NULL_TREE;
    1620                 :   169229685 :           off += operands[i].off;
    1621                 :   169229685 :           if (operands[i].opcode == MEM_REF)
    1622                 :             :             {
    1623                 :    81786877 :               ++i;
    1624                 :    81786877 :               break;
    1625                 :             :             }
    1626                 :             :         }
    1627                 :    81787185 :       vn_reference_op_t base = &operands[--i];
    1628                 :    81787185 :       tree ctor = error_mark_node;
    1629                 :    81787185 :       tree decl = NULL_TREE;
    1630                 :    81787185 :       if (TREE_CODE_CLASS (base->opcode) == tcc_constant)
    1631                 :         308 :         ctor = base->op0;
    1632                 :    81786877 :       else if (base->opcode == MEM_REF
    1633                 :    81786877 :                && base[1].opcode == ADDR_EXPR
    1634                 :   135186209 :                && (VAR_P (TREE_OPERAND (base[1].op0, 0))
    1635                 :     3602404 :                    || TREE_CODE (TREE_OPERAND (base[1].op0, 0)) == CONST_DECL
    1636                 :     3602344 :                    || TREE_CODE (TREE_OPERAND (base[1].op0, 0)) == STRING_CST))
    1637                 :             :         {
    1638                 :    49801522 :           decl = TREE_OPERAND (base[1].op0, 0);
    1639                 :    49801522 :           if (TREE_CODE (decl) == STRING_CST)
    1640                 :             :             ctor = decl;
    1641                 :             :           else
    1642                 :    49796988 :             ctor = ctor_for_folding (decl);
    1643                 :             :         }
    1644                 :    81782651 :       if (ctor == NULL_TREE)
    1645                 :         197 :         return build_zero_cst (ref->type);
    1646                 :    81786988 :       else if (ctor != error_mark_node)
    1647                 :             :         {
    1648                 :       93496 :           HOST_WIDE_INT const_off;
    1649                 :       93496 :           if (decl)
    1650                 :             :             {
    1651                 :      186376 :               tree res = fold_ctor_reference (ref->type, ctor,
    1652                 :       93188 :                                               off * BITS_PER_UNIT,
    1653                 :       93188 :                                               size * BITS_PER_UNIT, decl);
    1654                 :       93188 :               if (res)
    1655                 :             :                 {
    1656                 :       51814 :                   STRIP_USELESS_TYPE_CONVERSION (res);
    1657                 :       51814 :                   if (is_gimple_min_invariant (res))
    1658                 :   100512706 :                     return res;
    1659                 :             :                 }
    1660                 :             :             }
    1661                 :         308 :           else if (off.is_constant (&const_off))
    1662                 :             :             {
    1663                 :         308 :               unsigned char buf[MAX_BITSIZE_MODE_ANY_MODE / BITS_PER_UNIT];
    1664                 :         308 :               int len = native_encode_expr (ctor, buf, size, const_off);
    1665                 :         308 :               if (len > 0)
    1666                 :         138 :                 return native_interpret_expr (ref->type, buf, len);
    1667                 :             :             }
    1668                 :             :         }
    1669                 :             :     }
    1670                 :             : 
    1671                 :             :   return NULL_TREE;
    1672                 :             : }
    1673                 :             : 
    1674                 :             : /* Return true if OPS contain a storage order barrier.  */
    1675                 :             : 
    1676                 :             : static bool
    1677                 :    55090077 : contains_storage_order_barrier_p (vec<vn_reference_op_s> ops)
    1678                 :             : {
    1679                 :    55090077 :   vn_reference_op_t op;
    1680                 :    55090077 :   unsigned i;
    1681                 :             : 
    1682                 :   222470124 :   FOR_EACH_VEC_ELT (ops, i, op)
    1683                 :   167380047 :     if (op->opcode == VIEW_CONVERT_EXPR && op->reverse)
    1684                 :             :       return true;
    1685                 :             : 
    1686                 :             :   return false;
    1687                 :             : }
    1688                 :             : 
    1689                 :             : /* Return true if OPS represent an access with reverse storage order.  */
    1690                 :             : 
    1691                 :             : static bool
    1692                 :    55098012 : reverse_storage_order_for_component_p (vec<vn_reference_op_s> ops)
    1693                 :             : {
    1694                 :    55098012 :   unsigned i = 0;
    1695                 :    55098012 :   if (ops[i].opcode == REALPART_EXPR || ops[i].opcode == IMAGPART_EXPR)
    1696                 :             :     ++i;
    1697                 :    55098012 :   switch (ops[i].opcode)
    1698                 :             :     {
    1699                 :    53686030 :     case ARRAY_REF:
    1700                 :    53686030 :     case COMPONENT_REF:
    1701                 :    53686030 :     case BIT_FIELD_REF:
    1702                 :    53686030 :     case MEM_REF:
    1703                 :    53686030 :       return ops[i].reverse;
    1704                 :             :     default:
    1705                 :             :       return false;
    1706                 :             :     }
    1707                 :             : }
    1708                 :             : 
    1709                 :             : /* Transform any SSA_NAME's in a vector of vn_reference_op_s
    1710                 :             :    structures into their value numbers.  This is done in-place, and
    1711                 :             :    the vector passed in is returned.  *VALUEIZED_ANYTHING will specify
    1712                 :             :    whether any operands were valueized.  */
    1713                 :             : 
    1714                 :             : static void
    1715                 :   205227199 : valueize_refs_1 (vec<vn_reference_op_s> *orig, bool *valueized_anything,
    1716                 :             :                  bool with_avail = false)
    1717                 :             : {
    1718                 :   205227199 :   *valueized_anything = false;
    1719                 :             : 
    1720                 :   840349206 :   for (unsigned i = 0; i < orig->length (); ++i)
    1721                 :             :     {
    1722                 :   635122007 : re_valueize:
    1723                 :   638188386 :       vn_reference_op_t vro = &(*orig)[i];
    1724                 :   638188386 :       if (vro->opcode == SSA_NAME
    1725                 :   549436471 :           || (vro->op0 && TREE_CODE (vro->op0) == SSA_NAME))
    1726                 :             :         {
    1727                 :   111889624 :           tree tem = with_avail ? vn_valueize (vro->op0) : SSA_VAL (vro->op0);
    1728                 :   111889624 :           if (tem != vro->op0)
    1729                 :             :             {
    1730                 :    15782022 :               *valueized_anything = true;
    1731                 :    15782022 :               vro->op0 = tem;
    1732                 :             :             }
    1733                 :             :           /* If it transforms from an SSA_NAME to a constant, update
    1734                 :             :              the opcode.  */
    1735                 :   111889624 :           if (TREE_CODE (vro->op0) != SSA_NAME && vro->opcode == SSA_NAME)
    1736                 :     1750772 :             vro->opcode = TREE_CODE (vro->op0);
    1737                 :             :         }
    1738                 :   638188386 :       if (vro->op1 && TREE_CODE (vro->op1) == SSA_NAME)
    1739                 :             :         {
    1740                 :       26161 :           tree tem = with_avail ? vn_valueize (vro->op1) : SSA_VAL (vro->op1);
    1741                 :       26161 :           if (tem != vro->op1)
    1742                 :             :             {
    1743                 :         542 :               *valueized_anything = true;
    1744                 :         542 :               vro->op1 = tem;
    1745                 :             :             }
    1746                 :             :         }
    1747                 :   638188386 :       if (vro->op2 && TREE_CODE (vro->op2) == SSA_NAME)
    1748                 :             :         {
    1749                 :      205258 :           tree tem = with_avail ? vn_valueize (vro->op2) : SSA_VAL (vro->op2);
    1750                 :      205258 :           if (tem != vro->op2)
    1751                 :             :             {
    1752                 :      119430 :               *valueized_anything = true;
    1753                 :      119430 :               vro->op2 = tem;
    1754                 :             :             }
    1755                 :             :         }
    1756                 :             :       /* If it transforms from an SSA_NAME to an address, fold with
    1757                 :             :          a preceding indirect reference.  */
    1758                 :   638188386 :       if (i > 0
    1759                 :   432889997 :           && vro->op0
    1760                 :   429497017 :           && TREE_CODE (vro->op0) == ADDR_EXPR
    1761                 :   763965011 :           && (*orig)[i - 1].opcode == MEM_REF)
    1762                 :             :         {
    1763                 :   120072376 :           if (vn_reference_fold_indirect (orig, &i))
    1764                 :      517225 :             *valueized_anything = true;
    1765                 :             :         }
    1766                 :   518116010 :       else if (i > 0
    1767                 :   312817621 :                && vro->opcode == SSA_NAME
    1768                 :   605117153 :                && (*orig)[i - 1].opcode == MEM_REF)
    1769                 :             :         {
    1770                 :    77834099 :           if (vn_reference_maybe_forwprop_address (orig, &i))
    1771                 :             :             {
    1772                 :     3066379 :               *valueized_anything = true;
    1773                 :             :               /* Re-valueize the current operand.  */
    1774                 :     3066379 :               goto re_valueize;
    1775                 :             :             }
    1776                 :             :         }
    1777                 :             :       /* If it transforms a non-constant ARRAY_REF into a constant
    1778                 :             :          one, adjust the constant offset.  */
    1779                 :   440281911 :       else if ((vro->opcode == ARRAY_REF
    1780                 :   440281911 :                 || vro->opcode == ARRAY_RANGE_REF)
    1781                 :    38926989 :                && known_eq (vro->off, -1)
    1782                 :    16322352 :                && poly_int_tree_p (vro->op0)
    1783                 :     4558390 :                && poly_int_tree_p (vro->op1)
    1784                 :   444840301 :                && TREE_CODE (vro->op2) == INTEGER_CST)
    1785                 :             :         {
    1786                 :             :             /* Prohibit value-numbering addresses of one-after-the-last
    1787                 :             :                element ARRAY_REFs the same as addresses of other components
    1788                 :             :                before the pass folding __builtin_object_size had a chance
    1789                 :             :                to run.  */
    1790                 :     4424705 :           if (!(cfun->curr_properties & PROP_objsz)
    1791                 :     5617496 :               && (*orig)[0].opcode == ADDR_EXPR)
    1792                 :             :             {
    1793                 :       32769 :               tree dom = TYPE_DOMAIN ((*orig)[i + 1].type);
    1794                 :       49850 :               if (!dom
    1795                 :       32619 :                   || !TYPE_MAX_VALUE (dom)
    1796                 :       23655 :                   || !poly_int_tree_p (TYPE_MAX_VALUE (dom))
    1797                 :       48543 :                   || integer_minus_onep (TYPE_MAX_VALUE (dom)))
    1798                 :       17888 :                 continue;
    1799                 :       15688 :               if (!known_le (wi::to_poly_offset (vro->op0),
    1800                 :             :                              wi::to_poly_offset (TYPE_MAX_VALUE (dom))))
    1801                 :         807 :                 continue;
    1802                 :             :             }
    1803                 :             : 
    1804                 :     8813634 :           poly_offset_int off = ((wi::to_poly_offset (vro->op0)
    1805                 :    13220451 :                                   - wi::to_poly_offset (vro->op1))
    1806                 :     8813634 :                                  * wi::to_offset (vro->op2)
    1807                 :     4406817 :                                  * vn_ref_op_align_unit (vro));
    1808                 :     4406817 :           off.to_shwi (&vro->off);
    1809                 :             :         }
    1810                 :             :     }
    1811                 :   205227199 : }
    1812                 :             : 
    1813                 :             : static void
    1814                 :    13781641 : valueize_refs (vec<vn_reference_op_s> *orig)
    1815                 :             : {
    1816                 :    13781641 :   bool tem;
    1817                 :           0 :   valueize_refs_1 (orig, &tem);
    1818                 :           0 : }
    1819                 :             : 
    1820                 :             : static vec<vn_reference_op_s> shared_lookup_references;
    1821                 :             : 
    1822                 :             : /* Create a vector of vn_reference_op_s structures from REF, a
    1823                 :             :    REFERENCE_CLASS_P tree.  The vector is shared among all callers of
    1824                 :             :    this function.  *VALUEIZED_ANYTHING will specify whether any
    1825                 :             :    operands were valueized.  */
    1826                 :             : 
    1827                 :             : static vec<vn_reference_op_s>
    1828                 :   166291041 : valueize_shared_reference_ops_from_ref (tree ref, bool *valueized_anything)
    1829                 :             : {
    1830                 :   166291041 :   if (!ref)
    1831                 :           0 :     return vNULL;
    1832                 :   166291041 :   shared_lookup_references.truncate (0);
    1833                 :   166291041 :   copy_reference_ops_from_ref (ref, &shared_lookup_references);
    1834                 :   166291041 :   valueize_refs_1 (&shared_lookup_references, valueized_anything);
    1835                 :   166291041 :   return shared_lookup_references;
    1836                 :             : }
    1837                 :             : 
    1838                 :             : /* Create a vector of vn_reference_op_s structures from CALL, a
    1839                 :             :    call statement.  The vector is shared among all callers of
    1840                 :             :    this function.  */
    1841                 :             : 
    1842                 :             : static vec<vn_reference_op_s>
    1843                 :     8698470 : valueize_shared_reference_ops_from_call (gcall *call)
    1844                 :             : {
    1845                 :     8698470 :   if (!call)
    1846                 :           0 :     return vNULL;
    1847                 :     8698470 :   shared_lookup_references.truncate (0);
    1848                 :     8698470 :   copy_reference_ops_from_call (call, &shared_lookup_references);
    1849                 :     8698470 :   valueize_refs (&shared_lookup_references);
    1850                 :     8698470 :   return shared_lookup_references;
    1851                 :             : }
    1852                 :             : 
    1853                 :             : /* Lookup a SCCVN reference operation VR in the current hash table.
    1854                 :             :    Returns the resulting value number if it exists in the hash table,
    1855                 :             :    NULL_TREE otherwise.  VNRESULT will be filled in with the actual
    1856                 :             :    vn_reference_t stored in the hashtable if something is found.  */
    1857                 :             : 
    1858                 :             : static tree
    1859                 :    59827039 : vn_reference_lookup_1 (vn_reference_t vr, vn_reference_t *vnresult)
    1860                 :             : {
    1861                 :    59827039 :   vn_reference_s **slot;
    1862                 :    59827039 :   hashval_t hash;
    1863                 :             : 
    1864                 :    59827039 :   hash = vr->hashcode;
    1865                 :    59827039 :   slot = valid_info->references->find_slot_with_hash (vr, hash, NO_INSERT);
    1866                 :    59827039 :   if (slot)
    1867                 :             :     {
    1868                 :     7645266 :       if (vnresult)
    1869                 :     7645266 :         *vnresult = (vn_reference_t)*slot;
    1870                 :     7645266 :       return ((vn_reference_t)*slot)->result;
    1871                 :             :     }
    1872                 :             : 
    1873                 :             :   return NULL_TREE;
    1874                 :             : }
    1875                 :             : 
    1876                 :             : 
    1877                 :             : /* Partial definition tracking support.  */
    1878                 :             : 
    1879                 :             : struct pd_range
    1880                 :             : {
    1881                 :             :   HOST_WIDE_INT offset;
    1882                 :             :   HOST_WIDE_INT size;
    1883                 :             :   pd_range *m_children[2];
    1884                 :             : };
    1885                 :             : 
    1886                 :             : struct pd_data
    1887                 :             : {
    1888                 :             :   tree rhs;
    1889                 :             :   HOST_WIDE_INT rhs_off;
    1890                 :             :   HOST_WIDE_INT offset;
    1891                 :             :   HOST_WIDE_INT size;
    1892                 :             : };
    1893                 :             : 
    1894                 :             : /* Context for alias walking.  */
    1895                 :             : 
    1896                 :             : struct vn_walk_cb_data
    1897                 :             : {
    1898                 :    56294143 :   vn_walk_cb_data (vn_reference_t vr_, tree orig_ref_, tree *last_vuse_ptr_,
    1899                 :             :                    vn_lookup_kind vn_walk_kind_, bool tbaa_p_, tree mask_,
    1900                 :             :                    bool redundant_store_removal_p_)
    1901                 :    56294143 :     : vr (vr_), last_vuse_ptr (last_vuse_ptr_), last_vuse (NULL_TREE),
    1902                 :    56294143 :       mask (mask_), masked_result (NULL_TREE), same_val (NULL_TREE),
    1903                 :    56294143 :       vn_walk_kind (vn_walk_kind_),
    1904                 :    56294143 :       tbaa_p (tbaa_p_), redundant_store_removal_p (redundant_store_removal_p_),
    1905                 :   112588286 :       saved_operands (vNULL), first_range (), first_set (-2),
    1906                 :   112588286 :       first_base_set (-2)
    1907                 :             :   {
    1908                 :    56294143 :     if (!last_vuse_ptr)
    1909                 :    25849397 :       last_vuse_ptr = &last_vuse;
    1910                 :    56294143 :     ao_ref_init (&orig_ref, orig_ref_);
    1911                 :    56294143 :     if (mask)
    1912                 :             :       {
    1913                 :      317320 :         wide_int w = wi::to_wide (mask);
    1914                 :      317320 :         unsigned int pos = 0, prec = w.get_precision ();
    1915                 :      317320 :         pd_data pd;
    1916                 :      317320 :         pd.rhs = build_constructor (NULL_TREE, NULL);
    1917                 :      317320 :         pd.rhs_off = 0;
    1918                 :             :         /* When bitwise and with a constant is done on a memory load,
    1919                 :             :            we don't really need all the bits to be defined or defined
    1920                 :             :            to constants, we don't really care what is in the position
    1921                 :             :            corresponding to 0 bits in the mask.
    1922                 :             :            So, push the ranges of those 0 bits in the mask as artificial
    1923                 :             :            zero stores and let the partial def handling code do the
    1924                 :             :            rest.  */
    1925                 :      679282 :         while (pos < prec)
    1926                 :             :           {
    1927                 :      660717 :             int tz = wi::ctz (w);
    1928                 :      660717 :             if (pos + tz > prec)
    1929                 :      298755 :               tz = prec - pos;
    1930                 :      660717 :             if (tz)
    1931                 :             :               {
    1932                 :      520910 :                 if (BYTES_BIG_ENDIAN)
    1933                 :             :                   pd.offset = prec - pos - tz;
    1934                 :             :                 else
    1935                 :      520910 :                   pd.offset = pos;
    1936                 :      520910 :                 pd.size = tz;
    1937                 :      520910 :                 void *r = push_partial_def (pd, 0, 0, 0, prec);
    1938                 :      520910 :                 gcc_assert (r == NULL_TREE);
    1939                 :             :               }
    1940                 :      660717 :             pos += tz;
    1941                 :      660717 :             if (pos == prec)
    1942                 :             :               break;
    1943                 :      361962 :             w = wi::lrshift (w, tz);
    1944                 :      361962 :             tz = wi::ctz (wi::bit_not (w));
    1945                 :      361962 :             if (pos + tz > prec)
    1946                 :           0 :               tz = prec - pos;
    1947                 :      361962 :             pos += tz;
    1948                 :      361962 :             w = wi::lrshift (w, tz);
    1949                 :             :           }
    1950                 :      317320 :       }
    1951                 :    56294143 :   }
    1952                 :             :   ~vn_walk_cb_data ();
    1953                 :             :   void *finish (alias_set_type, alias_set_type, tree);
    1954                 :             :   void *push_partial_def (pd_data pd,
    1955                 :             :                           alias_set_type, alias_set_type, HOST_WIDE_INT,
    1956                 :             :                           HOST_WIDE_INT);
    1957                 :             : 
    1958                 :             :   vn_reference_t vr;
    1959                 :             :   ao_ref orig_ref;
    1960                 :             :   tree *last_vuse_ptr;
    1961                 :             :   tree last_vuse;
    1962                 :             :   tree mask;
    1963                 :             :   tree masked_result;
    1964                 :             :   tree same_val;
    1965                 :             :   vn_lookup_kind vn_walk_kind;
    1966                 :             :   bool tbaa_p;
    1967                 :             :   bool redundant_store_removal_p;
    1968                 :             :   vec<vn_reference_op_s> saved_operands;
    1969                 :             : 
    1970                 :             :   /* The VDEFs of partial defs we come along.  */
    1971                 :             :   auto_vec<pd_data, 2> partial_defs;
    1972                 :             :   /* The first defs range to avoid splay tree setup in most cases.  */
    1973                 :             :   pd_range first_range;
    1974                 :             :   alias_set_type first_set;
    1975                 :             :   alias_set_type first_base_set;
    1976                 :             :   default_splay_tree<pd_range *> known_ranges;
    1977                 :             :   obstack ranges_obstack;
    1978                 :             :   static constexpr HOST_WIDE_INT bufsize = 64;
    1979                 :             : };
    1980                 :             : 
    1981                 :    56294143 : vn_walk_cb_data::~vn_walk_cb_data ()
    1982                 :             : {
    1983                 :    56294143 :   if (known_ranges)
    1984                 :      197213 :     obstack_free (&ranges_obstack, NULL);
    1985                 :    56294143 :   saved_operands.release ();
    1986                 :    56294143 : }
    1987                 :             : 
    1988                 :             : void *
    1989                 :     1259102 : vn_walk_cb_data::finish (alias_set_type set, alias_set_type base_set, tree val)
    1990                 :             : {
    1991                 :     1259102 :   if (first_set != -2)
    1992                 :             :     {
    1993                 :      300385 :       set = first_set;
    1994                 :      300385 :       base_set = first_base_set;
    1995                 :             :     }
    1996                 :     1259102 :   if (mask)
    1997                 :             :     {
    1998                 :         442 :       masked_result = val;
    1999                 :         442 :       return (void *) -1;
    2000                 :             :     }
    2001                 :     1258660 :   if (same_val && !operand_equal_p (val, same_val))
    2002                 :             :     return (void *) -1;
    2003                 :     1253579 :   vec<vn_reference_op_s> &operands
    2004                 :     1253579 :     = saved_operands.exists () ? saved_operands : vr->operands;
    2005                 :     1253579 :   return vn_reference_lookup_or_insert_for_pieces (last_vuse, set, base_set,
    2006                 :             :                                                    vr->offset, vr->max_size,
    2007                 :     1253579 :                                                    vr->type, operands, val);
    2008                 :             : }
    2009                 :             : 
    2010                 :             : /* Push PD to the vector of partial definitions returning a
    2011                 :             :    value when we are ready to combine things with VUSE, SET and MAXSIZEI,
    2012                 :             :    NULL when we want to continue looking for partial defs or -1
    2013                 :             :    on failure.  */
    2014                 :             : 
    2015                 :             : void *
    2016                 :      594869 : vn_walk_cb_data::push_partial_def (pd_data pd,
    2017                 :             :                                    alias_set_type set, alias_set_type base_set,
    2018                 :             :                                    HOST_WIDE_INT offseti,
    2019                 :             :                                    HOST_WIDE_INT maxsizei)
    2020                 :             : {
    2021                 :             :   /* We're using a fixed buffer for encoding so fail early if the object
    2022                 :             :      we want to interpret is bigger.  */
    2023                 :      594869 :   if (maxsizei > bufsize * BITS_PER_UNIT
    2024                 :             :       || CHAR_BIT != 8
    2025                 :             :       || BITS_PER_UNIT != 8
    2026                 :             :       /* Not prepared to handle PDP endian.  */
    2027                 :             :       || BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
    2028                 :             :     return (void *)-1;
    2029                 :             : 
    2030                 :             :   /* Turn too large constant stores into non-constant stores.  */
    2031                 :      594798 :   if (CONSTANT_CLASS_P (pd.rhs) && pd.size > bufsize * BITS_PER_UNIT)
    2032                 :           0 :     pd.rhs = error_mark_node;
    2033                 :             : 
    2034                 :             :   /* And for non-constant or CONSTRUCTOR stores shrink them to only keep at
    2035                 :             :      most a partial byte before and/or after the region.  */
    2036                 :      594798 :   if (!CONSTANT_CLASS_P (pd.rhs))
    2037                 :             :     {
    2038                 :      567936 :       if (pd.offset < offseti)
    2039                 :             :         {
    2040                 :        8503 :           HOST_WIDE_INT o = ROUND_DOWN (offseti - pd.offset, BITS_PER_UNIT);
    2041                 :        8503 :           gcc_assert (pd.size > o);
    2042                 :        8503 :           pd.size -= o;
    2043                 :        8503 :           pd.offset += o;
    2044                 :             :         }
    2045                 :      567936 :       if (pd.size > maxsizei)
    2046                 :       11160 :         pd.size = maxsizei + ((pd.size - maxsizei) % BITS_PER_UNIT);
    2047                 :             :     }
    2048                 :             : 
    2049                 :      594798 :   pd.offset -= offseti;
    2050                 :             : 
    2051                 :     1189596 :   bool pd_constant_p = (TREE_CODE (pd.rhs) == CONSTRUCTOR
    2052                 :      594798 :                         || CONSTANT_CLASS_P (pd.rhs));
    2053                 :      594798 :   pd_range *r;
    2054                 :      594798 :   if (partial_defs.is_empty ())
    2055                 :             :     {
    2056                 :             :       /* If we get a clobber upfront, fail.  */
    2057                 :      368331 :       if (TREE_CLOBBER_P (pd.rhs))
    2058                 :             :         return (void *)-1;
    2059                 :      358321 :       if (!pd_constant_p)
    2060                 :             :         return (void *)-1;
    2061                 :      331113 :       partial_defs.safe_push (pd);
    2062                 :      331113 :       first_range.offset = pd.offset;
    2063                 :      331113 :       first_range.size = pd.size;
    2064                 :      331113 :       first_set = set;
    2065                 :      331113 :       first_base_set = base_set;
    2066                 :      331113 :       last_vuse_ptr = NULL;
    2067                 :      331113 :       r = &first_range;
    2068                 :             :       /* Go check if the first partial definition was a full one in case
    2069                 :             :          the caller didn't optimize for this.  */
    2070                 :             :     }
    2071                 :             :   else
    2072                 :             :     {
    2073                 :      226467 :       if (!known_ranges)
    2074                 :             :         {
    2075                 :             :           /* ???  Optimize the case where the 2nd partial def completes
    2076                 :             :              things.  */
    2077                 :      197213 :           gcc_obstack_init (&ranges_obstack);
    2078                 :      197213 :           known_ranges.insert_max_node (&first_range);
    2079                 :             :         }
    2080                 :             :       /* Lookup the offset and see if we need to merge.  */
    2081                 :      226467 :       int comparison = known_ranges.lookup_le
    2082                 :      456125 :         ([&] (pd_range *r) { return pd.offset < r->offset; },
    2083                 :      208770 :          [&] (pd_range *r) { return pd.offset > r->offset; });
    2084                 :      226467 :       r = known_ranges.root ();
    2085                 :      226467 :       if (comparison >= 0
    2086                 :      226467 :           && ranges_known_overlap_p (r->offset, r->size + 1,
    2087                 :             :                                      pd.offset, pd.size))
    2088                 :             :         {
    2089                 :             :           /* Ignore partial defs already covered.  Here we also drop shadowed
    2090                 :             :              clobbers arriving here at the floor.  */
    2091                 :        5045 :           if (known_subrange_p (pd.offset, pd.size, r->offset, r->size))
    2092                 :             :             return NULL;
    2093                 :        4622 :           r->size = MAX (r->offset + r->size, pd.offset + pd.size) - r->offset;
    2094                 :             :         }
    2095                 :             :       else
    2096                 :             :         {
    2097                 :             :           /* pd.offset wasn't covered yet, insert the range.  */
    2098                 :      221422 :           void *addr = XOBNEW (&ranges_obstack, pd_range);
    2099                 :      221422 :           r = new (addr) pd_range { pd.offset, pd.size, {} };
    2100                 :      221422 :           known_ranges.insert_relative (comparison, r);
    2101                 :             :         }
    2102                 :             :       /* Merge r which now contains pd's range and is a member of the splay
    2103                 :             :          tree with adjacent overlapping ranges.  */
    2104                 :      226044 :       if (known_ranges.splay_next_node ())
    2105                 :       19386 :         do
    2106                 :             :           {
    2107                 :       19386 :             pd_range *rafter = known_ranges.root ();
    2108                 :       19386 :             if (!ranges_known_overlap_p (r->offset, r->size + 1,
    2109                 :       19386 :                                          rafter->offset, rafter->size))
    2110                 :             :               break;
    2111                 :       19172 :             r->size = MAX (r->offset + r->size,
    2112                 :       19172 :                            rafter->offset + rafter->size) - r->offset;
    2113                 :             :           }
    2114                 :       19172 :         while (known_ranges.remove_root_and_splay_next ());
    2115                 :             :       /* If we get a clobber, fail.  */
    2116                 :      226044 :       if (TREE_CLOBBER_P (pd.rhs))
    2117                 :             :         return (void *)-1;
    2118                 :             :       /* Non-constants are OK as long as they are shadowed by a constant.  */
    2119                 :      223985 :       if (!pd_constant_p)
    2120                 :             :         return (void *)-1;
    2121                 :      217993 :       partial_defs.safe_push (pd);
    2122                 :             :     }
    2123                 :             : 
    2124                 :             :   /* Now we have merged pd's range into the range tree.  When we have covered
    2125                 :             :      [offseti, sizei] then the tree will contain exactly one node which has
    2126                 :             :      the desired properties and it will be 'r'.  */
    2127                 :      549106 :   if (!known_subrange_p (0, maxsizei, r->offset, r->size))
    2128                 :             :     /* Continue looking for partial defs.  */
    2129                 :             :     return NULL;
    2130                 :             : 
    2131                 :             :   /* Now simply native encode all partial defs in reverse order.  */
    2132                 :        7374 :   unsigned ndefs = partial_defs.length ();
    2133                 :             :   /* We support up to 512-bit values (for V8DFmode).  */
    2134                 :        7374 :   unsigned char buffer[bufsize + 1];
    2135                 :        7374 :   unsigned char this_buffer[bufsize + 1];
    2136                 :        7374 :   int len;
    2137                 :             : 
    2138                 :        7374 :   memset (buffer, 0, bufsize + 1);
    2139                 :        7374 :   unsigned needed_len = ROUND_UP (maxsizei, BITS_PER_UNIT) / BITS_PER_UNIT;
    2140                 :       35888 :   while (!partial_defs.is_empty ())
    2141                 :             :     {
    2142                 :       21140 :       pd_data pd = partial_defs.pop ();
    2143                 :       21140 :       unsigned int amnt;
    2144                 :       21140 :       if (TREE_CODE (pd.rhs) == CONSTRUCTOR)
    2145                 :             :         {
    2146                 :             :           /* Empty CONSTRUCTOR.  */
    2147                 :        1718 :           if (pd.size >= needed_len * BITS_PER_UNIT)
    2148                 :        1718 :             len = needed_len;
    2149                 :             :           else
    2150                 :        1554 :             len = ROUND_UP (pd.size, BITS_PER_UNIT) / BITS_PER_UNIT;
    2151                 :        1718 :           memset (this_buffer, 0, len);
    2152                 :             :         }
    2153                 :       19422 :       else if (pd.rhs_off >= 0)
    2154                 :             :         {
    2155                 :       38844 :           len = native_encode_expr (pd.rhs, this_buffer, bufsize,
    2156                 :       19422 :                                     (MAX (0, -pd.offset)
    2157                 :       19422 :                                      + pd.rhs_off) / BITS_PER_UNIT);
    2158                 :       19422 :           if (len <= 0
    2159                 :       19422 :               || len < (ROUND_UP (pd.size, BITS_PER_UNIT) / BITS_PER_UNIT
    2160                 :       19422 :                         - MAX (0, -pd.offset) / BITS_PER_UNIT))
    2161                 :             :             {
    2162                 :           0 :               if (dump_file && (dump_flags & TDF_DETAILS))
    2163                 :           0 :                 fprintf (dump_file, "Failed to encode %u "
    2164                 :             :                          "partial definitions\n", ndefs);
    2165                 :           0 :               return (void *)-1;
    2166                 :             :             }
    2167                 :             :         }
    2168                 :             :       else /* negative pd.rhs_off indicates we want to chop off first bits */
    2169                 :             :         {
    2170                 :           0 :           if (-pd.rhs_off >= bufsize)
    2171                 :             :             return (void *)-1;
    2172                 :           0 :           len = native_encode_expr (pd.rhs,
    2173                 :           0 :                                     this_buffer + -pd.rhs_off / BITS_PER_UNIT,
    2174                 :           0 :                                     bufsize - -pd.rhs_off / BITS_PER_UNIT,
    2175                 :           0 :                                     MAX (0, -pd.offset) / BITS_PER_UNIT);
    2176                 :           0 :           if (len <= 0
    2177                 :           0 :               || len < (ROUND_UP (pd.size, BITS_PER_UNIT) / BITS_PER_UNIT
    2178                 :             :                         - MAX (0, -pd.offset) / BITS_PER_UNIT))
    2179                 :             :             {
    2180                 :           0 :               if (dump_file && (dump_flags & TDF_DETAILS))
    2181                 :           0 :                 fprintf (dump_file, "Failed to encode %u "
    2182                 :             :                          "partial definitions\n", ndefs);
    2183                 :           0 :               return (void *)-1;
    2184                 :             :             }
    2185                 :             :         }
    2186                 :             : 
    2187                 :       21140 :       unsigned char *p = buffer;
    2188                 :       21140 :       HOST_WIDE_INT size = pd.size;
    2189                 :       21140 :       if (pd.offset < 0)
    2190                 :         202 :         size -= ROUND_DOWN (-pd.offset, BITS_PER_UNIT);
    2191                 :       21140 :       this_buffer[len] = 0;
    2192                 :       21140 :       if (BYTES_BIG_ENDIAN)
    2193                 :             :         {
    2194                 :             :           /* LSB of this_buffer[len - 1] byte should be at
    2195                 :             :              pd.offset + pd.size - 1 bits in buffer.  */
    2196                 :             :           amnt = ((unsigned HOST_WIDE_INT) pd.offset
    2197                 :             :                   + pd.size) % BITS_PER_UNIT;
    2198                 :             :           if (amnt)
    2199                 :             :             shift_bytes_in_array_right (this_buffer, len + 1, amnt);
    2200                 :             :           unsigned char *q = this_buffer;
    2201                 :             :           unsigned int off = 0;
    2202                 :             :           if (pd.offset >= 0)
    2203                 :             :             {
    2204                 :             :               unsigned int msk;
    2205                 :             :               off = pd.offset / BITS_PER_UNIT;
    2206                 :             :               gcc_assert (off < needed_len);
    2207                 :             :               p = buffer + off;
    2208                 :             :               if (size <= amnt)
    2209                 :             :                 {
    2210                 :             :                   msk = ((1 << size) - 1) << (BITS_PER_UNIT - amnt);
    2211                 :             :                   *p = (*p & ~msk) | (this_buffer[len] & msk);
    2212                 :             :                   size = 0;
    2213                 :             :                 }
    2214                 :             :               else
    2215                 :             :                 {
    2216                 :             :                   if (TREE_CODE (pd.rhs) != CONSTRUCTOR)
    2217                 :             :                     q = (this_buffer + len
    2218                 :             :                          - (ROUND_UP (size - amnt, BITS_PER_UNIT)
    2219                 :             :                             / BITS_PER_UNIT));
    2220                 :             :                   if (pd.offset % BITS_PER_UNIT)
    2221                 :             :                     {
    2222                 :             :                       msk = -1U << (BITS_PER_UNIT
    2223                 :             :                                     - (pd.offset % BITS_PER_UNIT));
    2224                 :             :                       *p = (*p & msk) | (*q & ~msk);
    2225                 :             :                       p++;
    2226                 :             :                       q++;
    2227                 :             :                       off++;
    2228                 :             :                       size -= BITS_PER_UNIT - (pd.offset % BITS_PER_UNIT);
    2229                 :             :                       gcc_assert (size >= 0);
    2230                 :             :                     }
    2231                 :             :                 }
    2232                 :             :             }
    2233                 :             :           else if (TREE_CODE (pd.rhs) != CONSTRUCTOR)
    2234                 :             :             {
    2235                 :             :               q = (this_buffer + len
    2236                 :             :                    - (ROUND_UP (size - amnt, BITS_PER_UNIT)
    2237                 :             :                       / BITS_PER_UNIT));
    2238                 :             :               if (pd.offset % BITS_PER_UNIT)
    2239                 :             :                 {
    2240                 :             :                   q++;
    2241                 :             :                   size -= BITS_PER_UNIT - ((unsigned HOST_WIDE_INT) pd.offset
    2242                 :             :                                            % BITS_PER_UNIT);
    2243                 :             :                   gcc_assert (size >= 0);
    2244                 :             :                 }
    2245                 :             :             }
    2246                 :             :           if ((unsigned HOST_WIDE_INT) size / BITS_PER_UNIT + off
    2247                 :             :               > needed_len)
    2248                 :             :             size = (needed_len - off) * BITS_PER_UNIT;
    2249                 :             :           memcpy (p, q, size / BITS_PER_UNIT);
    2250                 :             :           if (size % BITS_PER_UNIT)
    2251                 :             :             {
    2252                 :             :               unsigned int msk
    2253                 :             :                 = -1U << (BITS_PER_UNIT - (size % BITS_PER_UNIT));
    2254                 :             :               p += size / BITS_PER_UNIT;
    2255                 :             :               q += size / BITS_PER_UNIT;
    2256                 :             :               *p = (*q & msk) | (*p & ~msk);
    2257                 :             :             }
    2258                 :             :         }
    2259                 :             :       else
    2260                 :             :         {
    2261                 :       21140 :           if (pd.offset >= 0)
    2262                 :             :             {
    2263                 :             :               /* LSB of this_buffer[0] byte should be at pd.offset bits
    2264                 :             :                  in buffer.  */
    2265                 :       20938 :               unsigned int msk;
    2266                 :       20938 :               size = MIN (size, (HOST_WIDE_INT) needed_len * BITS_PER_UNIT);
    2267                 :       20938 :               amnt = pd.offset % BITS_PER_UNIT;
    2268                 :       20938 :               if (amnt)
    2269                 :        1234 :                 shift_bytes_in_array_left (this_buffer, len + 1, amnt);
    2270                 :       20938 :               unsigned int off = pd.offset / BITS_PER_UNIT;
    2271                 :       20938 :               gcc_assert (off < needed_len);
    2272                 :       20938 :               size = MIN (size,
    2273                 :             :                           (HOST_WIDE_INT) (needed_len - off) * BITS_PER_UNIT);
    2274                 :       20938 :               p = buffer + off;
    2275                 :       20938 :               if (amnt + size < BITS_PER_UNIT)
    2276                 :             :                 {
    2277                 :             :                   /* Low amnt bits come from *p, then size bits
    2278                 :             :                      from this_buffer[0] and the remaining again from
    2279                 :             :                      *p.  */
    2280                 :         777 :                   msk = ((1 << size) - 1) << amnt;
    2281                 :         777 :                   *p = (*p & ~msk) | (this_buffer[0] & msk);
    2282                 :         777 :                   size = 0;
    2283                 :             :                 }
    2284                 :       20161 :               else if (amnt)
    2285                 :             :                 {
    2286                 :        1082 :                   msk = -1U << amnt;
    2287                 :        1082 :                   *p = (*p & ~msk) | (this_buffer[0] & msk);
    2288                 :        1082 :                   p++;
    2289                 :        1082 :                   size -= (BITS_PER_UNIT - amnt);
    2290                 :             :                 }
    2291                 :             :             }
    2292                 :             :           else
    2293                 :             :             {
    2294                 :         202 :               amnt = (unsigned HOST_WIDE_INT) pd.offset % BITS_PER_UNIT;
    2295                 :         202 :               if (amnt)
    2296                 :          16 :                 size -= BITS_PER_UNIT - amnt;
    2297                 :         202 :               size = MIN (size, (HOST_WIDE_INT) needed_len * BITS_PER_UNIT);
    2298                 :         202 :               if (amnt)
    2299                 :          16 :                 shift_bytes_in_array_left (this_buffer, len + 1, amnt);
    2300                 :             :             }
    2301                 :       21140 :           memcpy (p, this_buffer + (amnt != 0), size / BITS_PER_UNIT);
    2302                 :       21140 :           p += size / BITS_PER_UNIT;
    2303                 :       21140 :           if (size % BITS_PER_UNIT)
    2304                 :             :             {
    2305                 :         622 :               unsigned int msk = -1U << (size % BITS_PER_UNIT);
    2306                 :         622 :               *p = (this_buffer[(amnt != 0) + size / BITS_PER_UNIT]
    2307                 :         622 :                     & ~msk) | (*p & msk);
    2308                 :             :             }
    2309                 :             :         }
    2310                 :             :     }
    2311                 :             : 
    2312                 :        7374 :   tree type = vr->type;
    2313                 :             :   /* Make sure to interpret in a type that has a range covering the whole
    2314                 :             :      access size.  */
    2315                 :        7374 :   if (INTEGRAL_TYPE_P (vr->type) && maxsizei != TYPE_PRECISION (vr->type))
    2316                 :          13 :     type = build_nonstandard_integer_type (maxsizei, TYPE_UNSIGNED (type));
    2317                 :        7374 :   tree val;
    2318                 :        7374 :   if (BYTES_BIG_ENDIAN)
    2319                 :             :     {
    2320                 :             :       unsigned sz = needed_len;
    2321                 :             :       if (maxsizei % BITS_PER_UNIT)
    2322                 :             :         shift_bytes_in_array_right (buffer, needed_len,
    2323                 :             :                                     BITS_PER_UNIT
    2324                 :             :                                     - (maxsizei % BITS_PER_UNIT));
    2325                 :             :       if (INTEGRAL_TYPE_P (type))
    2326                 :             :         {
    2327                 :             :           if (TYPE_MODE (type) != BLKmode)
    2328                 :             :             sz = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type));
    2329                 :             :           else
    2330                 :             :             sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (type));
    2331                 :             :         }
    2332                 :             :       if (sz > needed_len)
    2333                 :             :         {
    2334                 :             :           memcpy (this_buffer + (sz - needed_len), buffer, needed_len);
    2335                 :             :           val = native_interpret_expr (type, this_buffer, sz);
    2336                 :             :         }
    2337                 :             :       else
    2338                 :             :         val = native_interpret_expr (type, buffer, needed_len);
    2339                 :             :     }
    2340                 :             :   else
    2341                 :        7374 :     val = native_interpret_expr (type, buffer, bufsize);
    2342                 :             :   /* If we chop off bits because the types precision doesn't match the memory
    2343                 :             :      access size this is ok when optimizing reads but not when called from
    2344                 :             :      the DSE code during elimination.  */
    2345                 :        7374 :   if (val && type != vr->type)
    2346                 :             :     {
    2347                 :          13 :       if (! int_fits_type_p (val, vr->type))
    2348                 :             :         val = NULL_TREE;
    2349                 :             :       else
    2350                 :          13 :         val = fold_convert (vr->type, val);
    2351                 :             :     }
    2352                 :             : 
    2353                 :        7370 :   if (val)
    2354                 :             :     {
    2355                 :        7370 :       if (dump_file && (dump_flags & TDF_DETAILS))
    2356                 :           0 :         fprintf (dump_file,
    2357                 :             :                  "Successfully combined %u partial definitions\n", ndefs);
    2358                 :             :       /* We are using the alias-set of the first store we encounter which
    2359                 :             :          should be appropriate here.  */
    2360                 :        7370 :       return finish (first_set, first_base_set, val);
    2361                 :             :     }
    2362                 :             :   else
    2363                 :             :     {
    2364                 :           4 :       if (dump_file && (dump_flags & TDF_DETAILS))
    2365                 :           0 :         fprintf (dump_file,
    2366                 :             :                  "Failed to interpret %u encoded partial definitions\n", ndefs);
    2367                 :           4 :       return (void *)-1;
    2368                 :             :     }
    2369                 :             : }
    2370                 :             : 
    2371                 :             : /* Callback for walk_non_aliased_vuses.  Adjusts the vn_reference_t VR_
    2372                 :             :    with the current VUSE and performs the expression lookup.  */
    2373                 :             : 
    2374                 :             : static void *
    2375                 :   931475614 : vn_reference_lookup_2 (ao_ref *op, tree vuse, void *data_)
    2376                 :             : {
    2377                 :   931475614 :   vn_walk_cb_data *data = (vn_walk_cb_data *)data_;
    2378                 :   931475614 :   vn_reference_t vr = data->vr;
    2379                 :   931475614 :   vn_reference_s **slot;
    2380                 :   931475614 :   hashval_t hash;
    2381                 :             : 
    2382                 :             :   /* If we have partial definitions recorded we have to go through
    2383                 :             :      vn_reference_lookup_3.  */
    2384                 :  1856141466 :   if (!data->partial_defs.is_empty ())
    2385                 :             :     return NULL;
    2386                 :             : 
    2387                 :   930793993 :   if (data->last_vuse_ptr)
    2388                 :             :     {
    2389                 :   912070665 :       *data->last_vuse_ptr = vuse;
    2390                 :   912070665 :       data->last_vuse = vuse;
    2391                 :             :     }
    2392                 :             : 
    2393                 :             :   /* Fixup vuse and hash.  */
    2394                 :   930793993 :   if (vr->vuse)
    2395                 :   930793993 :     vr->hashcode = vr->hashcode - SSA_NAME_VERSION (vr->vuse);
    2396                 :   930793993 :   vr->vuse = vuse_ssa_val (vuse);
    2397                 :   930793993 :   if (vr->vuse)
    2398                 :   930793993 :     vr->hashcode = vr->hashcode + SSA_NAME_VERSION (vr->vuse);
    2399                 :             : 
    2400                 :   930793993 :   hash = vr->hashcode;
    2401                 :   930793993 :   slot = valid_info->references->find_slot_with_hash (vr, hash, NO_INSERT);
    2402                 :   930793993 :   if (slot)
    2403                 :             :     {
    2404                 :     6808684 :       if ((*slot)->result && data->saved_operands.exists ())
    2405                 :      288085 :         return data->finish (vr->set, vr->base_set, (*slot)->result);
    2406                 :             :       return *slot;
    2407                 :             :     }
    2408                 :             : 
    2409                 :   923985309 :   if (SSA_NAME_IS_DEFAULT_DEF (vuse))
    2410                 :             :     {
    2411                 :    16040710 :       HOST_WIDE_INT op_offset, op_size;
    2412                 :    16040710 :       tree v = NULL_TREE;
    2413                 :    16040710 :       tree base = ao_ref_base (op);
    2414                 :             : 
    2415                 :    16040710 :       if (base
    2416                 :    16040710 :           && op->offset.is_constant (&op_offset)
    2417                 :    16040710 :           && op->size.is_constant (&op_size)
    2418                 :    16040710 :           && op->max_size_known_p ()
    2419                 :    31641047 :           && known_eq (op->size, op->max_size))
    2420                 :             :         {
    2421                 :    15309765 :           if (TREE_CODE (base) == PARM_DECL)
    2422                 :      629195 :             v = ipcp_get_aggregate_const (cfun, base, false, op_offset,
    2423                 :             :                                           op_size);
    2424                 :    14680570 :           else if (TREE_CODE (base) == MEM_REF
    2425                 :     5815885 :                    && integer_zerop (TREE_OPERAND (base, 1))
    2426                 :     4820824 :                    && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME
    2427                 :     4814855 :                    && SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (base, 0))
    2428                 :    17801508 :                    && (TREE_CODE (SSA_NAME_VAR (TREE_OPERAND (base, 0)))
    2429                 :             :                        == PARM_DECL))
    2430                 :     3074612 :             v = ipcp_get_aggregate_const (cfun,
    2431                 :     3074612 :                                           SSA_NAME_VAR (TREE_OPERAND (base, 0)),
    2432                 :             :                                           true, op_offset, op_size);
    2433                 :             :         }
    2434                 :     3703807 :       if (v)
    2435                 :        1078 :         return data->finish (vr->set, vr->base_set, v);
    2436                 :             :     }
    2437                 :             : 
    2438                 :             :   return NULL;
    2439                 :             : }
    2440                 :             : 
    2441                 :             : /* Lookup an existing or insert a new vn_reference entry into the
    2442                 :             :    value table for the VUSE, SET, TYPE, OPERANDS reference which
    2443                 :             :    has the value VALUE which is either a constant or an SSA name.  */
    2444                 :             : 
    2445                 :             : static vn_reference_t
    2446                 :     1253579 : vn_reference_lookup_or_insert_for_pieces (tree vuse,
    2447                 :             :                                           alias_set_type set,
    2448                 :             :                                           alias_set_type base_set,
    2449                 :             :                                           poly_int64 offset,
    2450                 :             :                                           poly_int64 max_size,
    2451                 :             :                                           tree type,
    2452                 :             :                                           vec<vn_reference_op_s,
    2453                 :             :                                                 va_heap> operands,
    2454                 :             :                                           tree value)
    2455                 :             : {
    2456                 :     1253579 :   vn_reference_s vr1;
    2457                 :     1253579 :   vn_reference_t result;
    2458                 :     1253579 :   unsigned value_id;
    2459                 :     1253579 :   vr1.vuse = vuse ? SSA_VAL (vuse) : NULL_TREE;
    2460                 :     1253579 :   vr1.operands = operands;
    2461                 :     1253579 :   vr1.type = type;
    2462                 :     1253579 :   vr1.set = set;
    2463                 :     1253579 :   vr1.base_set = base_set;
    2464                 :     1253579 :   vr1.offset = offset;
    2465                 :     1253579 :   vr1.max_size = max_size;
    2466                 :     1253579 :   vr1.hashcode = vn_reference_compute_hash (&vr1);
    2467                 :     1253579 :   if (vn_reference_lookup_1 (&vr1, &result))
    2468                 :        2710 :     return result;
    2469                 :             : 
    2470                 :     1250869 :   if (TREE_CODE (value) == SSA_NAME)
    2471                 :      247311 :     value_id = VN_INFO (value)->value_id;
    2472                 :             :   else
    2473                 :     1003558 :     value_id = get_or_alloc_constant_value_id (value);
    2474                 :     1250869 :   return vn_reference_insert_pieces (vuse, set, base_set, offset, max_size,
    2475                 :     1250869 :                                      type, operands.copy (), value, value_id);
    2476                 :             : }
    2477                 :             : 
    2478                 :             : /* Return a value-number for RCODE OPS... either by looking up an existing
    2479                 :             :    value-number for the possibly simplified result or by inserting the
    2480                 :             :    operation if INSERT is true.  If SIMPLIFY is false, return a value
    2481                 :             :    number for the unsimplified expression.  */
    2482                 :             : 
    2483                 :             : static tree
    2484                 :    17119572 : vn_nary_build_or_lookup_1 (gimple_match_op *res_op, bool insert,
    2485                 :             :                            bool simplify)
    2486                 :             : {
    2487                 :    17119572 :   tree result = NULL_TREE;
    2488                 :             :   /* We will be creating a value number for
    2489                 :             :        RCODE (OPS...).
    2490                 :             :      So first simplify and lookup this expression to see if it
    2491                 :             :      is already available.  */
    2492                 :             :   /* For simplification valueize.  */
    2493                 :    17119572 :   unsigned i = 0;
    2494                 :    17119572 :   if (simplify)
    2495                 :    39711253 :     for (i = 0; i < res_op->num_ops; ++i)
    2496                 :    22597011 :       if (TREE_CODE (res_op->ops[i]) == SSA_NAME)
    2497                 :             :         {
    2498                 :    14493962 :           tree tem = vn_valueize (res_op->ops[i]);
    2499                 :    14493962 :           if (!tem)
    2500                 :             :             break;
    2501                 :    14493962 :           res_op->ops[i] = tem;
    2502                 :             :         }
    2503                 :             :   /* If valueization of an operand fails (it is not available), skip
    2504                 :             :      simplification.  */
    2505                 :    17119572 :   bool res = false;
    2506                 :    17119572 :   if (i == res_op->num_ops)
    2507                 :             :     {
    2508                 :             :       /* Do not leak not available operands into the simplified expression
    2509                 :             :          when called from PRE context.  */
    2510                 :    17114242 :       if (rpo_avail)
    2511                 :    10282029 :         mprts_hook = vn_lookup_simplify_result;
    2512                 :    17114242 :       res = res_op->resimplify (NULL, vn_valueize);
    2513                 :    17114242 :       mprts_hook = NULL;
    2514                 :             :     }
    2515                 :    29491307 :   gimple *new_stmt = NULL;
    2516                 :    17114242 :   if (res
    2517                 :    17114242 :       && gimple_simplified_result_is_gimple_val (res_op))
    2518                 :             :     {
    2519                 :             :       /* The expression is already available.  */
    2520                 :     4742507 :       result = res_op->ops[0];
    2521                 :             :       /* Valueize it, simplification returns sth in AVAIL only.  */
    2522                 :     4742507 :       if (TREE_CODE (result) == SSA_NAME)
    2523                 :      267395 :         result = SSA_VAL (result);
    2524                 :             :     }
    2525                 :             :   else
    2526                 :             :     {
    2527                 :    12377065 :       tree val = vn_lookup_simplify_result (res_op);
    2528                 :    12377065 :       if (!val && insert)
    2529                 :             :         {
    2530                 :      163709 :           gimple_seq stmts = NULL;
    2531                 :      163709 :           result = maybe_push_res_to_seq (res_op, &stmts);
    2532                 :      163709 :           if (result)
    2533                 :             :             {
    2534                 :      163709 :               gcc_assert (gimple_seq_singleton_p (stmts));
    2535                 :      163709 :               new_stmt = gimple_seq_first_stmt (stmts);
    2536                 :             :             }
    2537                 :             :         }
    2538                 :             :       else
    2539                 :             :         /* The expression is already available.  */
    2540                 :             :         result = val;
    2541                 :             :     }
    2542                 :      267395 :   if (new_stmt)
    2543                 :             :     {
    2544                 :             :       /* The expression is not yet available, value-number lhs to
    2545                 :             :          the new SSA_NAME we created.  */
    2546                 :             :       /* Initialize value-number information properly.  */
    2547                 :      163709 :       vn_ssa_aux_t result_info = VN_INFO (result);
    2548                 :      163709 :       result_info->valnum = result;
    2549                 :      163709 :       result_info->value_id = get_next_value_id ();
    2550                 :      163709 :       result_info->visited = 1;
    2551                 :      163709 :       gimple_seq_add_stmt_without_update (&VN_INFO (result)->expr,
    2552                 :             :                                           new_stmt);
    2553                 :      163709 :       result_info->needs_insertion = true;
    2554                 :             :       /* ???  PRE phi-translation inserts NARYs without corresponding
    2555                 :             :          SSA name result.  Re-use those but set their result according
    2556                 :             :          to the stmt we just built.  */
    2557                 :      163709 :       vn_nary_op_t nary = NULL;
    2558                 :      163709 :       vn_nary_op_lookup_stmt (new_stmt, &nary);
    2559                 :      163709 :       if (nary)
    2560                 :             :         {
    2561                 :           0 :           gcc_assert (! nary->predicated_values && nary->u.result == NULL_TREE);
    2562                 :           0 :           nary->u.result = gimple_assign_lhs (new_stmt);
    2563                 :             :         }
    2564                 :             :       /* As all "inserted" statements are singleton SCCs, insert
    2565                 :             :          to the valid table.  This is strictly needed to
    2566                 :             :          avoid re-generating new value SSA_NAMEs for the same
    2567                 :             :          expression during SCC iteration over and over (the
    2568                 :             :          optimistic table gets cleared after each iteration).
    2569                 :             :          We do not need to insert into the optimistic table, as
    2570                 :             :          lookups there will fall back to the valid table.  */
    2571                 :             :       else
    2572                 :             :         {
    2573                 :      163709 :           unsigned int length = vn_nary_length_from_stmt (new_stmt);
    2574                 :      163709 :           vn_nary_op_t vno1
    2575                 :      163709 :             = alloc_vn_nary_op_noinit (length, &vn_tables_insert_obstack);
    2576                 :      163709 :           vno1->value_id = result_info->value_id;
    2577                 :      163709 :           vno1->length = length;
    2578                 :      163709 :           vno1->predicated_values = 0;
    2579                 :      163709 :           vno1->u.result = result;
    2580                 :      163709 :           init_vn_nary_op_from_stmt (vno1, as_a <gassign *> (new_stmt));
    2581                 :      163709 :           vn_nary_op_insert_into (vno1, valid_info->nary);
    2582                 :             :           /* Also do not link it into the undo chain.  */
    2583                 :      163709 :           last_inserted_nary = vno1->next;
    2584                 :      163709 :           vno1->next = (vn_nary_op_t)(void *)-1;
    2585                 :             :         }
    2586                 :      163709 :       if (dump_file && (dump_flags & TDF_DETAILS))
    2587                 :             :         {
    2588                 :         588 :           fprintf (dump_file, "Inserting name ");
    2589                 :         588 :           print_generic_expr (dump_file, result);
    2590                 :         588 :           fprintf (dump_file, " for expression ");
    2591                 :         588 :           print_gimple_expr (dump_file, new_stmt, 0, TDF_SLIM);
    2592                 :         588 :           fprintf (dump_file, "\n");
    2593                 :             :         }
    2594                 :             :     }
    2595                 :    17119572 :   return result;
    2596                 :             : }
    2597                 :             : 
    2598                 :             : /* Return a value-number for RCODE OPS... either by looking up an existing
    2599                 :             :    value-number for the simplified result or by inserting the operation.  */
    2600                 :             : 
    2601                 :             : static tree
    2602                 :      209809 : vn_nary_build_or_lookup (gimple_match_op *res_op)
    2603                 :             : {
    2604                 :           0 :   return vn_nary_build_or_lookup_1 (res_op, true, true);
    2605                 :             : }
    2606                 :             : 
    2607                 :             : /* Try to simplify the expression RCODE OPS... of type TYPE and return
    2608                 :             :    its value if present.  Update NARY with a simplified expression if
    2609                 :             :    it fits.  */
    2610                 :             : 
    2611                 :             : tree
    2612                 :     6826937 : vn_nary_simplify (vn_nary_op_t nary)
    2613                 :             : {
    2614                 :     6826937 :   if (nary->length > gimple_match_op::MAX_NUM_OPS
    2615                 :             :       /* For CONSTRUCTOR the vn_nary_op_t and gimple_match_op representation
    2616                 :             :          does not match.  */
    2617                 :     6826761 :       || nary->opcode == CONSTRUCTOR)
    2618                 :             :     return NULL_TREE;
    2619                 :     6826391 :   gimple_match_op op (gimple_match_cond::UNCOND, nary->opcode,
    2620                 :     6826391 :                       nary->type, nary->length);
    2621                 :     6826391 :   memcpy (op.ops, nary->op, sizeof (tree) * nary->length);
    2622                 :     6826391 :   tree res = vn_nary_build_or_lookup_1 (&op, false, true);
    2623                 :     6826391 :   if (op.code.is_tree_code ()
    2624                 :     6826391 :       && op.num_ops <= nary->length
    2625                 :    13652008 :       && (tree_code) op.code != CONSTRUCTOR)
    2626                 :             :     {
    2627                 :     6825616 :       nary->opcode = (tree_code) op.code;
    2628                 :     6825616 :       nary->length = op.num_ops;
    2629                 :    17855110 :       for (unsigned i = 0; i < op.num_ops; ++i)
    2630                 :    11029494 :         nary->op[i] = op.ops[i];
    2631                 :             :     }
    2632                 :             :   return res;
    2633                 :             : }
    2634                 :             : 
    2635                 :             : /* Elimination engine.  */
    2636                 :             : 
    2637                 :             : class eliminate_dom_walker : public dom_walker
    2638                 :             : {
    2639                 :             : public:
    2640                 :             :   eliminate_dom_walker (cdi_direction, bitmap);
    2641                 :             :   ~eliminate_dom_walker ();
    2642                 :             : 
    2643                 :             :   edge before_dom_children (basic_block) final override;
    2644                 :             :   void after_dom_children (basic_block) final override;
    2645                 :             : 
    2646                 :             :   virtual tree eliminate_avail (basic_block, tree op);
    2647                 :             :   virtual void eliminate_push_avail (basic_block, tree op);
    2648                 :             :   tree eliminate_insert (basic_block, gimple_stmt_iterator *gsi, tree val);
    2649                 :             : 
    2650                 :             :   void eliminate_stmt (basic_block, gimple_stmt_iterator *);
    2651                 :             : 
    2652                 :             :   unsigned eliminate_cleanup (bool region_p = false);
    2653                 :             : 
    2654                 :             :   bool do_pre;
    2655                 :             :   unsigned int el_todo;
    2656                 :             :   unsigned int eliminations;
    2657                 :             :   unsigned int insertions;
    2658                 :             : 
    2659                 :             :   /* SSA names that had their defs inserted by PRE if do_pre.  */
    2660                 :             :   bitmap inserted_exprs;
    2661                 :             : 
    2662                 :             :   /* Blocks with statements that have had their EH properties changed.  */
    2663                 :             :   bitmap need_eh_cleanup;
    2664                 :             : 
    2665                 :             :   /* Blocks with statements that have had their AB properties changed.  */
    2666                 :             :   bitmap need_ab_cleanup;
    2667                 :             : 
    2668                 :             :   /* Local state for the eliminate domwalk.  */
    2669                 :             :   auto_vec<gimple *> to_remove;
    2670                 :             :   auto_vec<gimple *> to_fixup;
    2671                 :             :   auto_vec<tree> avail;
    2672                 :             :   auto_vec<tree> avail_stack;
    2673                 :             : };
    2674                 :             : 
    2675                 :             : /* Adaptor to the elimination engine using RPO availability.  */
    2676                 :             : 
    2677                 :    11543748 : class rpo_elim : public eliminate_dom_walker
    2678                 :             : {
    2679                 :             : public:
    2680                 :     5771874 :   rpo_elim(basic_block entry_)
    2681                 :    11543748 :     : eliminate_dom_walker (CDI_DOMINATORS, NULL), entry (entry_),
    2682                 :    11543748 :       m_avail_freelist (NULL) {}
    2683                 :             : 
    2684                 :             :   tree eliminate_avail (basic_block, tree op) final override;
    2685                 :             : 
    2686                 :             :   void eliminate_push_avail (basic_block, tree) final override;
    2687                 :             : 
    2688                 :             :   basic_block entry;
    2689                 :             :   /* Freelist of avail entries which are allocated from the vn_ssa_aux
    2690                 :             :      obstack.  */
    2691                 :             :   vn_avail *m_avail_freelist;
    2692                 :             : };
    2693                 :             : 
    2694                 :             : /* Return true if BASE1 and BASE2 can be adjusted so they have the
    2695                 :             :    same address and adjust *OFFSET1 and *OFFSET2 accordingly.
    2696                 :             :    Otherwise return false.  */
    2697                 :             : 
    2698                 :             : static bool
    2699                 :     4998989 : adjust_offsets_for_equal_base_address (tree base1, poly_int64 *offset1,
    2700                 :             :                                        tree base2, poly_int64 *offset2)
    2701                 :             : {
    2702                 :     4998989 :   poly_int64 soff;
    2703                 :     4998989 :   if (TREE_CODE (base1) == MEM_REF
    2704                 :     2082933 :       && TREE_CODE (base2) == MEM_REF)
    2705                 :             :     {
    2706                 :     1782046 :       if (mem_ref_offset (base1).to_shwi (&soff))
    2707                 :             :         {
    2708                 :     1782046 :           base1 = TREE_OPERAND (base1, 0);
    2709                 :     1782046 :           *offset1 += soff * BITS_PER_UNIT;
    2710                 :             :         }
    2711                 :     1782046 :       if (mem_ref_offset (base2).to_shwi (&soff))
    2712                 :             :         {
    2713                 :     1782046 :           base2 = TREE_OPERAND (base2, 0);
    2714                 :     1782046 :           *offset2 += soff * BITS_PER_UNIT;
    2715                 :             :         }
    2716                 :     1782046 :       return operand_equal_p (base1, base2, 0);
    2717                 :             :     }
    2718                 :     3216943 :   return operand_equal_p (base1, base2, OEP_ADDRESS_OF);
    2719                 :             : }
    2720                 :             : 
    2721                 :             : /* Callback for walk_non_aliased_vuses.  Tries to perform a lookup
    2722                 :             :    from the statement defining VUSE and if not successful tries to
    2723                 :             :    translate *REFP and VR_ through an aggregate copy at the definition
    2724                 :             :    of VUSE.  If *DISAMBIGUATE_ONLY is true then do not perform translation
    2725                 :             :    of *REF and *VR.  If only disambiguation was performed then
    2726                 :             :    *DISAMBIGUATE_ONLY is set to true.  */
    2727                 :             : 
    2728                 :             : static void *
    2729                 :    38639233 : vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
    2730                 :             :                        translate_flags *disambiguate_only)
    2731                 :             : {
    2732                 :    38639233 :   vn_walk_cb_data *data = (vn_walk_cb_data *)data_;
    2733                 :    38639233 :   vn_reference_t vr = data->vr;
    2734                 :    38639233 :   gimple *def_stmt = SSA_NAME_DEF_STMT (vuse);
    2735                 :    38639233 :   tree base = ao_ref_base (ref);
    2736                 :    38639233 :   HOST_WIDE_INT offseti = 0, maxsizei, sizei = 0;
    2737                 :    38639233 :   static vec<vn_reference_op_s> lhs_ops;
    2738                 :    38639233 :   ao_ref lhs_ref;
    2739                 :    38639233 :   bool lhs_ref_ok = false;
    2740                 :    38639233 :   poly_int64 copy_size;
    2741                 :             : 
    2742                 :             :   /* First try to disambiguate after value-replacing in the definitions LHS.  */
    2743                 :    38639233 :   if (is_gimple_assign (def_stmt))
    2744                 :             :     {
    2745                 :    18703794 :       tree lhs = gimple_assign_lhs (def_stmt);
    2746                 :    18703794 :       bool valueized_anything = false;
    2747                 :             :       /* Avoid re-allocation overhead.  */
    2748                 :    18703794 :       lhs_ops.truncate (0);
    2749                 :    18703794 :       basic_block saved_rpo_bb = vn_context_bb;
    2750                 :    18703794 :       vn_context_bb = gimple_bb (def_stmt);
    2751                 :    18703794 :       if (*disambiguate_only <= TR_VALUEIZE_AND_DISAMBIGUATE)
    2752                 :             :         {
    2753                 :    13356250 :           copy_reference_ops_from_ref (lhs, &lhs_ops);
    2754                 :    13356250 :           valueize_refs_1 (&lhs_ops, &valueized_anything, true);
    2755                 :             :         }
    2756                 :    18703794 :       vn_context_bb = saved_rpo_bb;
    2757                 :    18703794 :       ao_ref_init (&lhs_ref, lhs);
    2758                 :    18703794 :       lhs_ref_ok = true;
    2759                 :    18703794 :       if (valueized_anything
    2760                 :     1613363 :           && ao_ref_init_from_vn_reference
    2761                 :     1613363 :                (&lhs_ref, ao_ref_alias_set (&lhs_ref),
    2762                 :     1613363 :                 ao_ref_base_alias_set (&lhs_ref), TREE_TYPE (lhs), lhs_ops)
    2763                 :    20317157 :           && !refs_may_alias_p_1 (ref, &lhs_ref, data->tbaa_p))
    2764                 :             :         {
    2765                 :     1388504 :           *disambiguate_only = TR_VALUEIZE_AND_DISAMBIGUATE;
    2766                 :     5984463 :           return NULL;
    2767                 :             :         }
    2768                 :             : 
    2769                 :             :       /* When the def is a CLOBBER we can optimistically disambiguate
    2770                 :             :          against it since any overlap it would be undefined behavior.
    2771                 :             :          Avoid this for obvious must aliases to save compile-time though.
    2772                 :             :          We also may not do this when the query is used for redundant
    2773                 :             :          store removal.  */
    2774                 :    17315290 :       if (!data->redundant_store_removal_p
    2775                 :     8908083 :           && gimple_clobber_p (def_stmt)
    2776                 :    17729193 :           && !operand_equal_p (ao_ref_base (&lhs_ref), base, OEP_ADDRESS_OF))
    2777                 :             :         {
    2778                 :      387851 :           *disambiguate_only = TR_DISAMBIGUATE;
    2779                 :      387851 :           return NULL;
    2780                 :             :         }
    2781                 :             : 
    2782                 :             :       /* Besides valueizing the LHS we can also use access-path based
    2783                 :             :          disambiguation on the original non-valueized ref.  */
    2784                 :    16927439 :       if (!ref->ref
    2785                 :             :           && lhs_ref_ok
    2786                 :     2279550 :           && data->orig_ref.ref)
    2787                 :             :         {
    2788                 :             :           /* We want to use the non-valueized LHS for this, but avoid redundant
    2789                 :             :              work.  */
    2790                 :     1459768 :           ao_ref *lref = &lhs_ref;
    2791                 :     1459768 :           ao_ref lref_alt;
    2792                 :     1459768 :           if (valueized_anything)
    2793                 :             :             {
    2794                 :       99850 :               ao_ref_init (&lref_alt, lhs);
    2795                 :       99850 :               lref = &lref_alt;
    2796                 :             :             }
    2797                 :     1459768 :           if (!refs_may_alias_p_1 (&data->orig_ref, lref, data->tbaa_p))
    2798                 :             :             {
    2799                 :      238152 :               *disambiguate_only = (valueized_anything
    2800                 :      119076 :                                     ? TR_VALUEIZE_AND_DISAMBIGUATE
    2801                 :             :                                     : TR_DISAMBIGUATE);
    2802                 :      119076 :               return NULL;
    2803                 :             :             }
    2804                 :             :         }
    2805                 :             : 
    2806                 :             :       /* If we reach a clobbering statement try to skip it and see if
    2807                 :             :          we find a VN result with exactly the same value as the
    2808                 :             :          possible clobber.  In this case we can ignore the clobber
    2809                 :             :          and return the found value.  */
    2810                 :    16808363 :       if (is_gimple_reg_type (TREE_TYPE (lhs))
    2811                 :    10178262 :           && types_compatible_p (TREE_TYPE (lhs), vr->type)
    2812                 :     7687999 :           && (ref->ref || data->orig_ref.ref)
    2813                 :     7309129 :           && !data->mask
    2814                 :     7289400 :           && data->partial_defs.is_empty ()
    2815                 :     7288522 :           && multiple_p (get_object_alignment
    2816                 :             :                            (ref->ref ? ref->ref : data->orig_ref.ref),
    2817                 :             :                            ref->size)
    2818                 :    31214358 :           && multiple_p (get_object_alignment (lhs), ref->size))
    2819                 :             :         {
    2820                 :     6928261 :           tree rhs = gimple_assign_rhs1 (def_stmt);
    2821                 :             :           /* ???  We may not compare to ahead values which might be from
    2822                 :             :              a different loop iteration but only to loop invariants.  Use
    2823                 :             :              CONSTANT_CLASS_P (unvalueized!) as conservative approximation.
    2824                 :             :              The one-hop lookup below doesn't have this issue since there's
    2825                 :             :              a virtual PHI before we ever reach a backedge to cross.
    2826                 :             :              We can skip multiple defs as long as they are from the same
    2827                 :             :              value though.  */
    2828                 :     6928261 :           if (data->same_val
    2829                 :     6928261 :               && !operand_equal_p (data->same_val, rhs))
    2830                 :             :             ;
    2831                 :     6639098 :           else if (CONSTANT_CLASS_P (rhs))
    2832                 :             :             {
    2833                 :     2642744 :               if (dump_file && (dump_flags & TDF_DETAILS))
    2834                 :             :                 {
    2835                 :        1893 :                   fprintf (dump_file,
    2836                 :             :                            "Skipping possible redundant definition ");
    2837                 :        1893 :                   print_gimple_stmt (dump_file, def_stmt, 0);
    2838                 :             :                 }
    2839                 :             :               /* Delay the actual compare of the values to the end of the walk
    2840                 :             :                  but do not update last_vuse from here.  */
    2841                 :     2642744 :               data->last_vuse_ptr = NULL;
    2842                 :     2642744 :               data->same_val = rhs;
    2843                 :     2642744 :               return NULL;
    2844                 :             :             }
    2845                 :             :           else
    2846                 :             :             {
    2847                 :     3996354 :               tree saved_vuse = vr->vuse;
    2848                 :     3996354 :               hashval_t saved_hashcode = vr->hashcode;
    2849                 :     3996354 :               if (vr->vuse)
    2850                 :     3996354 :                 vr->hashcode = vr->hashcode - SSA_NAME_VERSION (vr->vuse);
    2851                 :     7992708 :               vr->vuse = vuse_ssa_val (gimple_vuse (def_stmt));
    2852                 :     3996354 :               if (vr->vuse)
    2853                 :     3996354 :                 vr->hashcode = vr->hashcode + SSA_NAME_VERSION (vr->vuse);
    2854                 :     3996354 :               vn_reference_t vnresult = NULL;
    2855                 :             :               /* Do not use vn_reference_lookup_2 since that might perform
    2856                 :             :                  expression hashtable insertion but this lookup crosses
    2857                 :             :                  a possible may-alias making such insertion conditionally
    2858                 :             :                  invalid.  */
    2859                 :     3996354 :               vn_reference_lookup_1 (vr, &vnresult);
    2860                 :             :               /* Need to restore vr->vuse and vr->hashcode.  */
    2861                 :     3996354 :               vr->vuse = saved_vuse;
    2862                 :     3996354 :               vr->hashcode = saved_hashcode;
    2863                 :     3996354 :               if (vnresult)
    2864                 :             :                 {
    2865                 :      221343 :                   if (TREE_CODE (rhs) == SSA_NAME)
    2866                 :      216758 :                     rhs = SSA_VAL (rhs);
    2867                 :      221343 :                   if (vnresult->result
    2868                 :      221343 :                       && operand_equal_p (vnresult->result, rhs, 0))
    2869                 :       57784 :                     return vnresult;
    2870                 :             :                 }
    2871                 :             :             }
    2872                 :             :         }
    2873                 :             :     }
    2874                 :    19935439 :   else if (*disambiguate_only <= TR_VALUEIZE_AND_DISAMBIGUATE
    2875                 :    18634999 :            && gimple_call_builtin_p (def_stmt, BUILT_IN_NORMAL)
    2876                 :    21864842 :            && gimple_call_num_args (def_stmt) <= 4)
    2877                 :             :     {
    2878                 :             :       /* For builtin calls valueize its arguments and call the
    2879                 :             :          alias oracle again.  Valueization may improve points-to
    2880                 :             :          info of pointers and constify size and position arguments.
    2881                 :             :          Originally this was motivated by PR61034 which has
    2882                 :             :          conditional calls to free falsely clobbering ref because
    2883                 :             :          of imprecise points-to info of the argument.  */
    2884                 :             :       tree oldargs[4];
    2885                 :             :       bool valueized_anything = false;
    2886                 :     4630139 :       for (unsigned i = 0; i < gimple_call_num_args (def_stmt); ++i)
    2887                 :             :         {
    2888                 :     3195373 :           oldargs[i] = gimple_call_arg (def_stmt, i);
    2889                 :     3195373 :           tree val = vn_valueize (oldargs[i]);
    2890                 :     3195373 :           if (val != oldargs[i])
    2891                 :             :             {
    2892                 :      111823 :               gimple_call_set_arg (def_stmt, i, val);
    2893                 :      111823 :               valueized_anything = true;
    2894                 :             :             }
    2895                 :             :         }
    2896                 :     1434766 :       if (valueized_anything)
    2897                 :             :         {
    2898                 :      171570 :           bool res = call_may_clobber_ref_p_1 (as_a <gcall *> (def_stmt),
    2899                 :       85785 :                                                ref, data->tbaa_p);
    2900                 :      313595 :           for (unsigned i = 0; i < gimple_call_num_args (def_stmt); ++i)
    2901                 :      227810 :             gimple_call_set_arg (def_stmt, i, oldargs[i]);
    2902                 :       85785 :           if (!res)
    2903                 :             :             {
    2904                 :       23028 :               *disambiguate_only = TR_VALUEIZE_AND_DISAMBIGUATE;
    2905                 :       23028 :               return NULL;
    2906                 :             :             }
    2907                 :             :         }
    2908                 :             :     }
    2909                 :             : 
    2910                 :    34020246 :   if (*disambiguate_only > TR_TRANSLATE)
    2911                 :             :     return (void *)-1;
    2912                 :             : 
    2913                 :             :   /* If we cannot constrain the size of the reference we cannot
    2914                 :             :      test if anything kills it.  */
    2915                 :    23407288 :   if (!ref->max_size_known_p ())
    2916                 :             :     return (void *)-1;
    2917                 :             : 
    2918                 :    23003481 :   poly_int64 offset = ref->offset;
    2919                 :    23003481 :   poly_int64 maxsize = ref->max_size;
    2920                 :             : 
    2921                 :             :   /* def_stmt may-defs *ref.  See if we can derive a value for *ref
    2922                 :             :      from that definition.
    2923                 :             :      1) Memset.  */
    2924                 :    23003481 :   if (is_gimple_reg_type (vr->type)
    2925                 :    22695498 :       && (gimple_call_builtin_p (def_stmt, BUILT_IN_MEMSET)
    2926                 :    22612032 :           || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMSET_CHK))
    2927                 :       84008 :       && (integer_zerop (gimple_call_arg (def_stmt, 1))
    2928                 :       29324 :           || ((TREE_CODE (gimple_call_arg (def_stmt, 1)) == INTEGER_CST
    2929                 :        8222 :                || (INTEGRAL_TYPE_P (vr->type) && known_eq (ref->size, 8)))
    2930                 :             :               && CHAR_BIT == 8
    2931                 :             :               && BITS_PER_UNIT == 8
    2932                 :             :               && BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN
    2933                 :       28427 :               && offset.is_constant (&offseti)
    2934                 :       28427 :               && ref->size.is_constant (&sizei)
    2935                 :       28427 :               && (offseti % BITS_PER_UNIT == 0
    2936                 :          39 :                   || TREE_CODE (gimple_call_arg (def_stmt, 1)) == INTEGER_CST)))
    2937                 :       83111 :       && (poly_int_tree_p (gimple_call_arg (def_stmt, 2))
    2938                 :       34808 :           || (TREE_CODE (gimple_call_arg (def_stmt, 2)) == SSA_NAME
    2939                 :       34808 :               && poly_int_tree_p (SSA_VAL (gimple_call_arg (def_stmt, 2)))))
    2940                 :    23052324 :       && (TREE_CODE (gimple_call_arg (def_stmt, 0)) == ADDR_EXPR
    2941                 :       27340 :           || TREE_CODE (gimple_call_arg (def_stmt, 0)) == SSA_NAME))
    2942                 :             :     {
    2943                 :       48812 :       tree base2;
    2944                 :       48812 :       poly_int64 offset2, size2, maxsize2;
    2945                 :       48812 :       bool reverse;
    2946                 :       48812 :       tree ref2 = gimple_call_arg (def_stmt, 0);
    2947                 :       48812 :       if (TREE_CODE (ref2) == SSA_NAME)
    2948                 :             :         {
    2949                 :       27309 :           ref2 = SSA_VAL (ref2);
    2950                 :       27309 :           if (TREE_CODE (ref2) == SSA_NAME
    2951                 :       27309 :               && (TREE_CODE (base) != MEM_REF
    2952                 :       17709 :                   || TREE_OPERAND (base, 0) != ref2))
    2953                 :             :             {
    2954                 :       21426 :               gimple *def_stmt = SSA_NAME_DEF_STMT (ref2);
    2955                 :       21426 :               if (gimple_assign_single_p (def_stmt)
    2956                 :       21426 :                   && gimple_assign_rhs_code (def_stmt) == ADDR_EXPR)
    2957                 :         713 :                 ref2 = gimple_assign_rhs1 (def_stmt);
    2958                 :             :             }
    2959                 :             :         }
    2960                 :       48812 :       if (TREE_CODE (ref2) == ADDR_EXPR)
    2961                 :             :         {
    2962                 :       25190 :           ref2 = TREE_OPERAND (ref2, 0);
    2963                 :       25190 :           base2 = get_ref_base_and_extent (ref2, &offset2, &size2, &maxsize2,
    2964                 :             :                                            &reverse);
    2965                 :       25190 :           if (!known_size_p (maxsize2)
    2966                 :       25150 :               || !known_eq (maxsize2, size2)
    2967                 :       50266 :               || !operand_equal_p (base, base2, OEP_ADDRESS_OF))
    2968                 :       52511 :             return (void *)-1;
    2969                 :             :         }
    2970                 :       23622 :       else if (TREE_CODE (ref2) == SSA_NAME)
    2971                 :             :         {
    2972                 :       23622 :           poly_int64 soff;
    2973                 :       23622 :           if (TREE_CODE (base) != MEM_REF
    2974                 :       40834 :               || !(mem_ref_offset (base)
    2975                 :       34424 :                    << LOG2_BITS_PER_UNIT).to_shwi (&soff))
    2976                 :       20267 :             return (void *)-1;
    2977                 :       17212 :           offset += soff;
    2978                 :       17212 :           offset2 = 0;
    2979                 :       17212 :           if (TREE_OPERAND (base, 0) != ref2)
    2980                 :             :             {
    2981                 :       14303 :               gimple *def = SSA_NAME_DEF_STMT (ref2);
    2982                 :       14303 :               if (is_gimple_assign (def)
    2983                 :       13270 :                   && gimple_assign_rhs_code (def) == POINTER_PLUS_EXPR
    2984                 :       11313 :                   && gimple_assign_rhs1 (def) == TREE_OPERAND (base, 0)
    2985                 :       14779 :                   && poly_int_tree_p (gimple_assign_rhs2 (def)))
    2986                 :             :                 {
    2987                 :         446 :                   tree rhs2 = gimple_assign_rhs2 (def);
    2988                 :         446 :                   if (!(poly_offset_int::from (wi::to_poly_wide (rhs2),
    2989                 :             :                                                SIGNED)
    2990                 :         446 :                         << LOG2_BITS_PER_UNIT).to_shwi (&offset2))
    2991                 :             :                     return (void *)-1;
    2992                 :         446 :                   ref2 = gimple_assign_rhs1 (def);
    2993                 :         446 :                   if (TREE_CODE (ref2) == SSA_NAME)
    2994                 :         446 :                     ref2 = SSA_VAL (ref2);
    2995                 :             :                 }
    2996                 :             :               else
    2997                 :             :                 return (void *)-1;
    2998                 :             :             }
    2999                 :             :         }
    3000                 :             :       else
    3001                 :             :         return (void *)-1;
    3002                 :       24528 :       tree len = gimple_call_arg (def_stmt, 2);
    3003                 :       24528 :       HOST_WIDE_INT leni, offset2i;
    3004                 :       24528 :       if (TREE_CODE (len) == SSA_NAME)
    3005                 :         252 :         len = SSA_VAL (len);
    3006                 :             :       /* Sometimes the above trickery is smarter than alias analysis.  Take
    3007                 :             :          advantage of that.  */
    3008                 :       24528 :       if (!ranges_maybe_overlap_p (offset, maxsize, offset2,
    3009                 :       49056 :                                    (wi::to_poly_offset (len)
    3010                 :       24528 :                                     << LOG2_BITS_PER_UNIT)))
    3011                 :             :         return NULL;
    3012                 :       49020 :       if (data->partial_defs.is_empty ()
    3013                 :       24492 :           && known_subrange_p (offset, maxsize, offset2,
    3014                 :       24492 :                                wi::to_poly_offset (len) << LOG2_BITS_PER_UNIT))
    3015                 :             :         {
    3016                 :       24115 :           tree val;
    3017                 :       24115 :           if (integer_zerop (gimple_call_arg (def_stmt, 1)))
    3018                 :       20642 :             val = build_zero_cst (vr->type);
    3019                 :        3473 :           else if (INTEGRAL_TYPE_P (vr->type)
    3020                 :        3152 :                    && known_eq (ref->size, 8)
    3021                 :        5887 :                    && offseti % BITS_PER_UNIT == 0)
    3022                 :             :             {
    3023                 :        2414 :               gimple_match_op res_op (gimple_match_cond::UNCOND, NOP_EXPR,
    3024                 :        2414 :                                       vr->type, gimple_call_arg (def_stmt, 1));
    3025                 :        2414 :               val = vn_nary_build_or_lookup (&res_op);
    3026                 :        2414 :               if (!val
    3027                 :        2414 :                   || (TREE_CODE (val) == SSA_NAME
    3028                 :         626 :                       && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val)))
    3029                 :           0 :                 return (void *)-1;
    3030                 :             :             }
    3031                 :             :           else
    3032                 :             :             {
    3033                 :        1059 :               unsigned buflen
    3034                 :        1059 :                 = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (vr->type)) + 1;
    3035                 :        1059 :               if (INTEGRAL_TYPE_P (vr->type)
    3036                 :        1059 :                   && TYPE_MODE (vr->type) != BLKmode)
    3037                 :        1474 :                 buflen = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (vr->type)) + 1;
    3038                 :        1059 :               unsigned char *buf = XALLOCAVEC (unsigned char, buflen);
    3039                 :        1059 :               memset (buf, TREE_INT_CST_LOW (gimple_call_arg (def_stmt, 1)),
    3040                 :             :                       buflen);
    3041                 :        1059 :               if (BYTES_BIG_ENDIAN)
    3042                 :             :                 {
    3043                 :             :                   unsigned int amnt
    3044                 :             :                     = (((unsigned HOST_WIDE_INT) offseti + sizei)
    3045                 :             :                        % BITS_PER_UNIT);
    3046                 :             :                   if (amnt)
    3047                 :             :                     {
    3048                 :             :                       shift_bytes_in_array_right (buf, buflen,
    3049                 :             :                                                   BITS_PER_UNIT - amnt);
    3050                 :             :                       buf++;
    3051                 :             :                       buflen--;
    3052                 :             :                     }
    3053                 :             :                 }
    3054                 :        1059 :               else if (offseti % BITS_PER_UNIT != 0)
    3055                 :             :                 {
    3056                 :           7 :                   unsigned int amnt
    3057                 :             :                     = BITS_PER_UNIT - ((unsigned HOST_WIDE_INT) offseti
    3058                 :           7 :                                        % BITS_PER_UNIT);
    3059                 :           7 :                   shift_bytes_in_array_left (buf, buflen, amnt);
    3060                 :           7 :                   buf++;
    3061                 :           7 :                   buflen--;
    3062                 :             :                 }
    3063                 :        1059 :               val = native_interpret_expr (vr->type, buf, buflen);
    3064                 :        1059 :               if (!val)
    3065                 :             :                 return (void *)-1;
    3066                 :             :             }
    3067                 :       24115 :           return data->finish (0, 0, val);
    3068                 :             :         }
    3069                 :             :       /* For now handle clearing memory with partial defs.  */
    3070                 :         413 :       else if (known_eq (ref->size, maxsize)
    3071                 :         347 :                && integer_zerop (gimple_call_arg (def_stmt, 1))
    3072                 :          99 :                && tree_fits_poly_int64_p (len)
    3073                 :          95 :                && tree_to_poly_int64 (len).is_constant (&leni)
    3074                 :          95 :                && leni <= INTTYPE_MAXIMUM (HOST_WIDE_INT) / BITS_PER_UNIT
    3075                 :          95 :                && offset.is_constant (&offseti)
    3076                 :          95 :                && offset2.is_constant (&offset2i)
    3077                 :          95 :                && maxsize.is_constant (&maxsizei)
    3078                 :         413 :                && ranges_known_overlap_p (offseti, maxsizei, offset2i,
    3079                 :         413 :                                           leni << LOG2_BITS_PER_UNIT))
    3080                 :             :         {
    3081                 :          95 :           pd_data pd;
    3082                 :          95 :           pd.rhs = build_constructor (NULL_TREE, NULL);
    3083                 :          95 :           pd.rhs_off = 0;
    3084                 :          95 :           pd.offset = offset2i;
    3085                 :          95 :           pd.size = leni << LOG2_BITS_PER_UNIT;
    3086                 :          95 :           return data->push_partial_def (pd, 0, 0, offseti, maxsizei);
    3087                 :             :         }
    3088                 :             :     }
    3089                 :             : 
    3090                 :             :   /* 2) Assignment from an empty CONSTRUCTOR.  */
    3091                 :    22954669 :   else if (is_gimple_reg_type (vr->type)
    3092                 :    22646686 :            && gimple_assign_single_p (def_stmt)
    3093                 :     8007418 :            && gimple_assign_rhs_code (def_stmt) == CONSTRUCTOR
    3094                 :    25758899 :            && CONSTRUCTOR_NELTS (gimple_assign_rhs1 (def_stmt)) == 0)
    3095                 :             :     {
    3096                 :     2804230 :       tree base2;
    3097                 :     2804230 :       poly_int64 offset2, size2, maxsize2;
    3098                 :     2804230 :       HOST_WIDE_INT offset2i, size2i;
    3099                 :     2804230 :       gcc_assert (lhs_ref_ok);
    3100                 :     2804230 :       base2 = ao_ref_base (&lhs_ref);
    3101                 :     2804230 :       offset2 = lhs_ref.offset;
    3102                 :     2804230 :       size2 = lhs_ref.size;
    3103                 :     2804230 :       maxsize2 = lhs_ref.max_size;
    3104                 :     2804230 :       if (known_size_p (maxsize2)
    3105                 :     2803821 :           && known_eq (maxsize2, size2)
    3106                 :     5607101 :           && adjust_offsets_for_equal_base_address (base, &offset,
    3107                 :             :                                                     base2, &offset2))
    3108                 :             :         {
    3109                 :     2745334 :           if (data->partial_defs.is_empty ()
    3110                 :     2742043 :               && known_subrange_p (offset, maxsize, offset2, size2))
    3111                 :             :             {
    3112                 :             :               /* While technically undefined behavior do not optimize
    3113                 :             :                  a full read from a clobber.  */
    3114                 :     2731419 :               if (gimple_clobber_p (def_stmt))
    3115                 :     2745058 :                 return (void *)-1;
    3116                 :      839267 :               tree val = build_zero_cst (vr->type);
    3117                 :      839267 :               return data->finish (ao_ref_alias_set (&lhs_ref),
    3118                 :      839267 :                                    ao_ref_base_alias_set (&lhs_ref), val);
    3119                 :             :             }
    3120                 :       13915 :           else if (known_eq (ref->size, maxsize)
    3121                 :       13639 :                    && maxsize.is_constant (&maxsizei)
    3122                 :       13639 :                    && offset.is_constant (&offseti)
    3123                 :       13639 :                    && offset2.is_constant (&offset2i)
    3124                 :       13639 :                    && size2.is_constant (&size2i)
    3125                 :       13915 :                    && ranges_known_overlap_p (offseti, maxsizei,
    3126                 :             :                                               offset2i, size2i))
    3127                 :             :             {
    3128                 :             :               /* Let clobbers be consumed by the partial-def tracker
    3129                 :             :                  which can choose to ignore them if they are shadowed
    3130                 :             :                  by a later def.  */
    3131                 :       13639 :               pd_data pd;
    3132                 :       13639 :               pd.rhs = gimple_assign_rhs1 (def_stmt);
    3133                 :       13639 :               pd.rhs_off = 0;
    3134                 :       13639 :               pd.offset = offset2i;
    3135                 :       13639 :               pd.size = size2i;
    3136                 :       13639 :               return data->push_partial_def (pd, ao_ref_alias_set (&lhs_ref),
    3137                 :             :                                              ao_ref_base_alias_set (&lhs_ref),
    3138                 :             :                                              offseti, maxsizei);
    3139                 :             :             }
    3140                 :             :         }
    3141                 :             :     }
    3142                 :             : 
    3143                 :             :   /* 3) Assignment from a constant.  We can use folds native encode/interpret
    3144                 :             :      routines to extract the assigned bits.  */
    3145                 :    20150439 :   else if (known_eq (ref->size, maxsize)
    3146                 :    19667514 :            && is_gimple_reg_type (vr->type)
    3147                 :    19359531 :            && !reverse_storage_order_for_component_p (vr->operands)
    3148                 :    19356886 :            && !contains_storage_order_barrier_p (vr->operands)
    3149                 :    19356886 :            && gimple_assign_single_p (def_stmt)
    3150                 :             :            && CHAR_BIT == 8
    3151                 :             :            && BITS_PER_UNIT == 8
    3152                 :             :            && BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN
    3153                 :             :            /* native_encode and native_decode operate on arrays of bytes
    3154                 :             :               and so fundamentally need a compile-time size and offset.  */
    3155                 :     4914401 :            && maxsize.is_constant (&maxsizei)
    3156                 :     4914401 :            && offset.is_constant (&offseti)
    3157                 :    25064840 :            && (is_gimple_min_invariant (gimple_assign_rhs1 (def_stmt))
    3158                 :     4273726 :                || (TREE_CODE (gimple_assign_rhs1 (def_stmt)) == SSA_NAME
    3159                 :     1684845 :                    && is_gimple_min_invariant (SSA_VAL (gimple_assign_rhs1 (def_stmt))))))
    3160                 :             :     {
    3161                 :      655061 :       tree lhs = gimple_assign_lhs (def_stmt);
    3162                 :      655061 :       tree base2;
    3163                 :      655061 :       poly_int64 offset2, size2, maxsize2;
    3164                 :      655061 :       HOST_WIDE_INT offset2i, size2i;
    3165                 :      655061 :       bool reverse;
    3166                 :      655061 :       gcc_assert (lhs_ref_ok);
    3167                 :      655061 :       base2 = ao_ref_base (&lhs_ref);
    3168                 :      655061 :       offset2 = lhs_ref.offset;
    3169                 :      655061 :       size2 = lhs_ref.size;
    3170                 :      655061 :       maxsize2 = lhs_ref.max_size;
    3171                 :      655061 :       reverse = reverse_storage_order_for_component_p (lhs);
    3172                 :      655061 :       if (base2
    3173                 :      655061 :           && !reverse
    3174                 :      655061 :           && !storage_order_barrier_p (lhs)
    3175                 :      655061 :           && known_eq (maxsize2, size2)
    3176                 :      638886 :           && adjust_offsets_for_equal_base_address (base, &offset,
    3177                 :             :                                                     base2, &offset2)
    3178                 :       62609 :           && offset.is_constant (&offseti)
    3179                 :       62609 :           && offset2.is_constant (&offset2i)
    3180                 :      655061 :           && size2.is_constant (&size2i))
    3181                 :             :         {
    3182                 :       62609 :           if (data->partial_defs.is_empty ()
    3183                 :       49027 :               && known_subrange_p (offseti, maxsizei, offset2, size2))
    3184                 :             :             {
    3185                 :             :               /* We support up to 512-bit values (for V8DFmode).  */
    3186                 :       35625 :               unsigned char buffer[65];
    3187                 :       35625 :               int len;
    3188                 :             : 
    3189                 :       35625 :               tree rhs = gimple_assign_rhs1 (def_stmt);
    3190                 :       35625 :               if (TREE_CODE (rhs) == SSA_NAME)
    3191                 :        1271 :                 rhs = SSA_VAL (rhs);
    3192                 :       71250 :               len = native_encode_expr (rhs,
    3193                 :             :                                         buffer, sizeof (buffer) - 1,
    3194                 :       35625 :                                         (offseti - offset2i) / BITS_PER_UNIT);
    3195                 :       35625 :               if (len > 0 && len * BITS_PER_UNIT >= maxsizei)
    3196                 :             :                 {
    3197                 :       32634 :                   tree type = vr->type;
    3198                 :       32634 :                   unsigned char *buf = buffer;
    3199                 :       32634 :                   unsigned int amnt = 0;
    3200                 :             :                   /* Make sure to interpret in a type that has a range
    3201                 :             :                      covering the whole access size.  */
    3202                 :       32634 :                   if (INTEGRAL_TYPE_P (vr->type)
    3203                 :       32634 :                       && maxsizei != TYPE_PRECISION (vr->type))
    3204                 :        1648 :                     type = build_nonstandard_integer_type (maxsizei,
    3205                 :         824 :                                                            TYPE_UNSIGNED (type));
    3206                 :       32634 :                   if (BYTES_BIG_ENDIAN)
    3207                 :             :                     {
    3208                 :             :                       /* For big-endian native_encode_expr stored the rhs
    3209                 :             :                          such that the LSB of it is the LSB of buffer[len - 1].
    3210                 :             :                          That bit is stored into memory at position
    3211                 :             :                          offset2 + size2 - 1, i.e. in byte
    3212                 :             :                          base + (offset2 + size2 - 1) / BITS_PER_UNIT.
    3213                 :             :                          E.g. for offset2 1 and size2 14, rhs -1 and memory
    3214                 :             :                          previously cleared that is:
    3215                 :             :                          0        1
    3216                 :             :                          01111111|11111110
    3217                 :             :                          Now, if we want to extract offset 2 and size 12 from
    3218                 :             :                          it using native_interpret_expr (which actually works
    3219                 :             :                          for integral bitfield types in terms of byte size of
    3220                 :             :                          the mode), the native_encode_expr stored the value
    3221                 :             :                          into buffer as
    3222                 :             :                          XX111111|11111111
    3223                 :             :                          and returned len 2 (the X bits are outside of
    3224                 :             :                          precision).
    3225                 :             :                          Let sz be maxsize / BITS_PER_UNIT if not extracting
    3226                 :             :                          a bitfield, and GET_MODE_SIZE otherwise.
    3227                 :             :                          We need to align the LSB of the value we want to
    3228                 :             :                          extract as the LSB of buf[sz - 1].
    3229                 :             :                          The LSB from memory we need to read is at position
    3230                 :             :                          offset + maxsize - 1.  */
    3231                 :             :                       HOST_WIDE_INT sz = maxsizei / BITS_PER_UNIT;
    3232                 :             :                       if (INTEGRAL_TYPE_P (type))
    3233                 :             :                         {
    3234                 :             :                           if (TYPE_MODE (type) != BLKmode)
    3235                 :             :                             sz = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type));
    3236                 :             :                           else
    3237                 :             :                             sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (type));
    3238                 :             :                         }
    3239                 :             :                       amnt = ((unsigned HOST_WIDE_INT) offset2i + size2i
    3240                 :             :                               - offseti - maxsizei) % BITS_PER_UNIT;
    3241                 :             :                       if (amnt)
    3242                 :             :                         shift_bytes_in_array_right (buffer, len, amnt);
    3243                 :             :                       amnt = ((unsigned HOST_WIDE_INT) offset2i + size2i
    3244                 :             :                               - offseti - maxsizei - amnt) / BITS_PER_UNIT;
    3245                 :             :                       if ((unsigned HOST_WIDE_INT) sz + amnt > (unsigned) len)
    3246                 :             :                         len = 0;
    3247                 :             :                       else
    3248                 :             :                         {
    3249                 :             :                           buf = buffer + len - sz - amnt;
    3250                 :             :                           len -= (buf - buffer);
    3251                 :             :                         }
    3252                 :             :                     }
    3253                 :             :                   else
    3254                 :             :                     {
    3255                 :       32634 :                       amnt = ((unsigned HOST_WIDE_INT) offset2i
    3256                 :       32634 :                               - offseti) % BITS_PER_UNIT;
    3257                 :       32634 :                       if (amnt)
    3258                 :             :                         {
    3259                 :         324 :                           buffer[len] = 0;
    3260                 :         324 :                           shift_bytes_in_array_left (buffer, len + 1, amnt);
    3261                 :         324 :                           buf = buffer + 1;
    3262                 :             :                         }
    3263                 :             :                     }
    3264                 :       32634 :                   tree val = native_interpret_expr (type, buf, len);
    3265                 :             :                   /* If we chop off bits because the types precision doesn't
    3266                 :             :                      match the memory access size this is ok when optimizing
    3267                 :             :                      reads but not when called from the DSE code during
    3268                 :             :                      elimination.  */
    3269                 :       32634 :                   if (val
    3270                 :       32632 :                       && type != vr->type)
    3271                 :             :                     {
    3272                 :         824 :                       if (! int_fits_type_p (val, vr->type))
    3273                 :             :                         val = NULL_TREE;
    3274                 :             :                       else
    3275                 :         824 :                         val = fold_convert (vr->type, val);
    3276                 :             :                     }
    3277                 :             : 
    3278                 :       32632 :                   if (val)
    3279                 :       32632 :                     return data->finish (ao_ref_alias_set (&lhs_ref),
    3280                 :       32632 :                                          ao_ref_base_alias_set (&lhs_ref), val);
    3281                 :             :                 }
    3282                 :             :             }
    3283                 :       26984 :           else if (ranges_known_overlap_p (offseti, maxsizei, offset2i,
    3284                 :             :                                            size2i))
    3285                 :             :             {
    3286                 :       26984 :               pd_data pd;
    3287                 :       26984 :               tree rhs = gimple_assign_rhs1 (def_stmt);
    3288                 :       26984 :               if (TREE_CODE (rhs) == SSA_NAME)
    3289                 :        2408 :                 rhs = SSA_VAL (rhs);
    3290                 :       26984 :               pd.rhs = rhs;
    3291                 :       26984 :               pd.rhs_off = 0;
    3292                 :       26984 :               pd.offset = offset2i;
    3293                 :       26984 :               pd.size = size2i;
    3294                 :       26984 :               return data->push_partial_def (pd, ao_ref_alias_set (&lhs_ref),
    3295                 :             :                                              ao_ref_base_alias_set (&lhs_ref),
    3296                 :             :                                              offseti, maxsizei);
    3297                 :             :             }
    3298                 :             :         }
    3299                 :             :     }
    3300                 :             : 
    3301                 :             :   /* 4) Assignment from an SSA name which definition we may be able
    3302                 :             :      to access pieces from or we can combine to a larger entity.  */
    3303                 :    19495378 :   else if (known_eq (ref->size, maxsize)
    3304                 :    19012453 :            && is_gimple_reg_type (vr->type)
    3305                 :    18704470 :            && !reverse_storage_order_for_component_p (vr->operands)
    3306                 :    18701825 :            && !contains_storage_order_barrier_p (vr->operands)
    3307                 :    18701825 :            && gimple_assign_single_p (def_stmt)
    3308                 :    23754718 :            && TREE_CODE (gimple_assign_rhs1 (def_stmt)) == SSA_NAME)
    3309                 :             :     {
    3310                 :     1670459 :       tree lhs = gimple_assign_lhs (def_stmt);
    3311                 :     1670459 :       tree base2;
    3312                 :     1670459 :       poly_int64 offset2, size2, maxsize2;
    3313                 :     1670459 :       HOST_WIDE_INT offset2i, size2i, offseti;
    3314                 :     1670459 :       bool reverse;
    3315                 :     1670459 :       gcc_assert (lhs_ref_ok);
    3316                 :     1670459 :       base2 = ao_ref_base (&lhs_ref);
    3317                 :     1670459 :       offset2 = lhs_ref.offset;
    3318                 :     1670459 :       size2 = lhs_ref.size;
    3319                 :     1670459 :       maxsize2 = lhs_ref.max_size;
    3320                 :     1670459 :       reverse = reverse_storage_order_for_component_p (lhs);
    3321                 :     1670459 :       tree def_rhs = gimple_assign_rhs1 (def_stmt);
    3322                 :     1670459 :       if (!reverse
    3323                 :     1670459 :           && !storage_order_barrier_p (lhs)
    3324                 :     1670459 :           && known_size_p (maxsize2)
    3325                 :     1649358 :           && known_eq (maxsize2, size2)
    3326                 :     3227677 :           && adjust_offsets_for_equal_base_address (base, &offset,
    3327                 :             :                                                     base2, &offset2))
    3328                 :             :         {
    3329                 :       78389 :           if (data->partial_defs.is_empty ()
    3330                 :       72408 :               && known_subrange_p (offset, maxsize, offset2, size2)
    3331                 :             :               /* ???  We can't handle bitfield precision extracts without
    3332                 :             :                  either using an alternate type for the BIT_FIELD_REF and
    3333                 :             :                  then doing a conversion or possibly adjusting the offset
    3334                 :             :                  according to endianness.  */
    3335                 :       50077 :               && (! INTEGRAL_TYPE_P (vr->type)
    3336                 :       34960 :                   || known_eq (ref->size, TYPE_PRECISION (vr->type)))
    3337                 :       93709 :               && multiple_p (ref->size, BITS_PER_UNIT))
    3338                 :             :             {
    3339                 :       45155 :               tree val = NULL_TREE;
    3340                 :       90304 :               if (! INTEGRAL_TYPE_P (TREE_TYPE (def_rhs))
    3341                 :       49387 :                   || type_has_mode_precision_p (TREE_TYPE (def_rhs)))
    3342                 :             :                 {
    3343                 :             :                   gimple_match_op op (gimple_match_cond::UNCOND,
    3344                 :             :                                       BIT_FIELD_REF, vr->type,
    3345                 :             :                                       SSA_VAL (def_rhs),
    3346                 :             :                                       bitsize_int (ref->size),
    3347                 :       44138 :                                       bitsize_int (offset - offset2));
    3348                 :       44138 :                   val = vn_nary_build_or_lookup (&op);
    3349                 :             :                 }
    3350                 :        1017 :               else if (known_eq (ref->size, size2))
    3351                 :             :                 {
    3352                 :         995 :                   gimple_match_op op (gimple_match_cond::UNCOND,
    3353                 :             :                                       VIEW_CONVERT_EXPR, vr->type,
    3354                 :         995 :                                       SSA_VAL (def_rhs));
    3355                 :         995 :                   val = vn_nary_build_or_lookup (&op);
    3356                 :             :                 }
    3357                 :       45133 :               if (val
    3358                 :       45133 :                   && (TREE_CODE (val) != SSA_NAME
    3359                 :       44268 :                       || ! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val)))
    3360                 :       45114 :                 return data->finish (ao_ref_alias_set (&lhs_ref),
    3361                 :       78348 :                                      ao_ref_base_alias_set (&lhs_ref), val);
    3362                 :             :             }
    3363                 :       33234 :           else if (maxsize.is_constant (&maxsizei)
    3364                 :       33234 :                    && offset.is_constant (&offseti)
    3365                 :       33234 :                    && offset2.is_constant (&offset2i)
    3366                 :       33234 :                    && size2.is_constant (&size2i)
    3367                 :       33234 :                    && ranges_known_overlap_p (offset, maxsize, offset2, size2))
    3368                 :             :             {
    3369                 :       33234 :               pd_data pd;
    3370                 :       33234 :               pd.rhs = SSA_VAL (def_rhs);
    3371                 :       33234 :               pd.rhs_off = 0;
    3372                 :       33234 :               pd.offset = offset2i;
    3373                 :       33234 :               pd.size = size2i;
    3374                 :       33234 :               return data->push_partial_def (pd, ao_ref_alias_set (&lhs_ref),
    3375                 :             :                                              ao_ref_base_alias_set (&lhs_ref),
    3376                 :             :                                              offseti, maxsizei);
    3377                 :             :             }
    3378                 :             :         }
    3379                 :             :     }
    3380                 :             : 
    3381                 :             :   /* 4b) Assignment done via one of the vectorizer internal store
    3382                 :             :      functions where we may be able to access pieces from or we can
    3383                 :             :      combine to a larger entity.  */
    3384                 :    17824919 :   else if (known_eq (ref->size, maxsize)
    3385                 :    17341994 :            && is_gimple_reg_type (vr->type)
    3386                 :    17034011 :            && !reverse_storage_order_for_component_p (vr->operands)
    3387                 :    17031366 :            && !contains_storage_order_barrier_p (vr->operands)
    3388                 :    17031366 :            && is_gimple_call (def_stmt)
    3389                 :    13718341 :            && gimple_call_internal_p (def_stmt)
    3390                 :    17876339 :            && internal_store_fn_p (gimple_call_internal_fn (def_stmt)))
    3391                 :             :     {
    3392                 :          46 :       gcall *call = as_a <gcall *> (def_stmt);
    3393                 :          46 :       internal_fn fn = gimple_call_internal_fn (call);
    3394                 :             : 
    3395                 :          46 :       tree mask = NULL_TREE, len = NULL_TREE, bias = NULL_TREE;
    3396                 :          46 :       switch (fn)
    3397                 :             :         {
    3398                 :          46 :         case IFN_MASK_STORE:
    3399                 :          46 :           mask = gimple_call_arg (call, internal_fn_mask_index (fn));
    3400                 :          46 :           mask = vn_valueize (mask);
    3401                 :          46 :           if (TREE_CODE (mask) != VECTOR_CST)
    3402                 :          38 :             return (void *)-1;
    3403                 :             :           break;
    3404                 :           0 :         case IFN_LEN_STORE:
    3405                 :           0 :           {
    3406                 :           0 :             int len_index = internal_fn_len_index (fn);
    3407                 :           0 :             len = gimple_call_arg (call, len_index);
    3408                 :           0 :             bias = gimple_call_arg (call, len_index + 1);
    3409                 :           0 :             if (!tree_fits_uhwi_p (len) || !tree_fits_shwi_p (bias))
    3410                 :             :               return (void *) -1;
    3411                 :             :             break;
    3412                 :             :           }
    3413                 :             :         default:
    3414                 :             :           return (void *)-1;
    3415                 :             :         }
    3416                 :          14 :       tree def_rhs = gimple_call_arg (call,
    3417                 :          14 :                                       internal_fn_stored_value_index (fn));
    3418                 :          14 :       def_rhs = vn_valueize (def_rhs);
    3419                 :          14 :       if (TREE_CODE (def_rhs) != VECTOR_CST)
    3420                 :             :         return (void *)-1;
    3421                 :             : 
    3422                 :          14 :       ao_ref_init_from_ptr_and_size (&lhs_ref,
    3423                 :             :                                      vn_valueize (gimple_call_arg (call, 0)),
    3424                 :          14 :                                      TYPE_SIZE_UNIT (TREE_TYPE (def_rhs)));
    3425                 :          14 :       tree base2;
    3426                 :          14 :       poly_int64 offset2, size2, maxsize2;
    3427                 :          14 :       HOST_WIDE_INT offset2i, size2i, offseti;
    3428                 :          14 :       base2 = ao_ref_base (&lhs_ref);
    3429                 :          14 :       offset2 = lhs_ref.offset;
    3430                 :          14 :       size2 = lhs_ref.size;
    3431                 :          14 :       maxsize2 = lhs_ref.max_size;
    3432                 :          14 :       if (known_size_p (maxsize2)
    3433                 :          14 :           && known_eq (maxsize2, size2)
    3434                 :          14 :           && adjust_offsets_for_equal_base_address (base, &offset,
    3435                 :             :                                                     base2, &offset2)
    3436                 :           6 :           && maxsize.is_constant (&maxsizei)
    3437                 :           6 :           && offset.is_constant (&offseti)
    3438                 :           6 :           && offset2.is_constant (&offset2i)
    3439                 :          14 :           && size2.is_constant (&size2i))
    3440                 :             :         {
    3441                 :           6 :           if (!ranges_maybe_overlap_p (offset, maxsize, offset2, size2))
    3442                 :             :             /* Poor-mans disambiguation.  */
    3443                 :             :             return NULL;
    3444                 :           6 :           else if (ranges_known_overlap_p (offset, maxsize, offset2, size2))
    3445                 :             :             {
    3446                 :           6 :               pd_data pd;
    3447                 :           6 :               pd.rhs = def_rhs;
    3448                 :           6 :               tree aa = gimple_call_arg (call, 1);
    3449                 :           6 :               alias_set_type set = get_deref_alias_set (TREE_TYPE (aa));
    3450                 :           6 :               tree vectype = TREE_TYPE (def_rhs);
    3451                 :           6 :               unsigned HOST_WIDE_INT elsz
    3452                 :           6 :                 = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (vectype)));
    3453                 :           6 :               if (mask)
    3454                 :             :                 {
    3455                 :             :                   HOST_WIDE_INT start = 0, length = 0;
    3456                 :             :                   unsigned mask_idx = 0;
    3457                 :          48 :                   do
    3458                 :             :                     {
    3459                 :          48 :                       if (integer_zerop (VECTOR_CST_ELT (mask, mask_idx)))
    3460                 :             :                         {
    3461                 :          24 :                           if (length != 0)
    3462                 :             :                             {
    3463                 :          18 :                               pd.rhs_off = start;
    3464                 :          18 :                               pd.offset = offset2i + start;
    3465                 :          18 :                               pd.size = length;
    3466                 :          18 :                               if (ranges_known_overlap_p
    3467                 :          18 :                                     (offset, maxsize, pd.offset, pd.size))
    3468                 :             :                                 {
    3469                 :           0 :                                   void *res = data->push_partial_def
    3470                 :           0 :                                               (pd, set, set, offseti, maxsizei);
    3471                 :           0 :                                   if (res != NULL)
    3472                 :           6 :                                     return res;
    3473                 :             :                                 }
    3474                 :             :                             }
    3475                 :          24 :                           start = (mask_idx + 1) * elsz;
    3476                 :          24 :                           length = 0;
    3477                 :             :                         }
    3478                 :             :                       else
    3479                 :          24 :                         length += elsz;
    3480                 :          48 :                       mask_idx++;
    3481                 :             :                     }
    3482                 :          48 :                   while (known_lt (mask_idx, TYPE_VECTOR_SUBPARTS (vectype)));
    3483                 :           6 :                   if (length != 0)
    3484                 :             :                     {
    3485                 :           6 :                       pd.rhs_off = start;
    3486                 :           6 :                       pd.offset = offset2i + start;
    3487                 :           6 :                       pd.size = length;
    3488                 :           6 :                       if (ranges_known_overlap_p (offset, maxsize,
    3489                 :             :                                                   pd.offset, pd.size))
    3490                 :           2 :                         return data->push_partial_def (pd, set, set,
    3491                 :           2 :                                                        offseti, maxsizei);
    3492                 :             :                     }
    3493                 :             :                 }
    3494                 :           0 :               else if (fn == IFN_LEN_STORE)
    3495                 :             :                 {
    3496                 :           0 :                   pd.offset = offset2i;
    3497                 :           0 :                   pd.size = (tree_to_uhwi (len)
    3498                 :           0 :                              + -tree_to_shwi (bias)) * BITS_PER_UNIT;
    3499                 :           0 :                   if (BYTES_BIG_ENDIAN)
    3500                 :             :                     pd.rhs_off = pd.size - tree_to_uhwi (TYPE_SIZE (vectype));
    3501                 :             :                   else
    3502                 :           0 :                     pd.rhs_off = 0;
    3503                 :           0 :                   if (ranges_known_overlap_p (offset, maxsize,
    3504                 :             :                                               pd.offset, pd.size))
    3505                 :           0 :                     return data->push_partial_def (pd, set, set,
    3506                 :           0 :                                                    offseti, maxsizei);
    3507                 :             :                 }
    3508                 :             :               else
    3509                 :           0 :                 gcc_unreachable ();
    3510                 :           4 :               return NULL;
    3511                 :             :             }
    3512                 :             :         }
    3513                 :             :     }
    3514                 :             : 
    3515                 :             :   /* 5) For aggregate copies translate the reference through them if
    3516                 :             :      the copy kills ref.  */
    3517                 :    17824873 :   else if (data->vn_walk_kind == VN_WALKREWRITE
    3518                 :    14043426 :            && gimple_assign_single_p (def_stmt)
    3519                 :    20167234 :            && (DECL_P (gimple_assign_rhs1 (def_stmt))
    3520                 :     1919716 :                || TREE_CODE (gimple_assign_rhs1 (def_stmt)) == MEM_REF
    3521                 :     1529325 :                || handled_component_p (gimple_assign_rhs1 (def_stmt))))
    3522                 :             :     {
    3523                 :     2148033 :       tree base2;
    3524                 :     2148033 :       int i, j, k;
    3525                 :     2148033 :       auto_vec<vn_reference_op_s> rhs;
    3526                 :     2148033 :       vn_reference_op_t vro;
    3527                 :     2148033 :       ao_ref r;
    3528                 :             : 
    3529                 :     2148033 :       gcc_assert (lhs_ref_ok);
    3530                 :             : 
    3531                 :             :       /* See if the assignment kills REF.  */
    3532                 :     2148033 :       base2 = ao_ref_base (&lhs_ref);
    3533                 :     2148033 :       if (!lhs_ref.max_size_known_p ()
    3534                 :     2147868 :           || (base != base2
    3535                 :       75508 :               && (TREE_CODE (base) != MEM_REF
    3536                 :       62105 :                   || TREE_CODE (base2) != MEM_REF
    3537                 :       51550 :                   || TREE_OPERAND (base, 0) != TREE_OPERAND (base2, 0)
    3538                 :       17112 :                   || !tree_int_cst_equal (TREE_OPERAND (base, 1),
    3539                 :       17112 :                                           TREE_OPERAND (base2, 1))))
    3540                 :     4236342 :           || !stmt_kills_ref_p (def_stmt, ref))
    3541                 :      422598 :         return (void *)-1;
    3542                 :             : 
    3543                 :             :       /* Find the common base of ref and the lhs.  lhs_ops already
    3544                 :             :          contains valueized operands for the lhs.  */
    3545                 :     1725435 :       i = vr->operands.length () - 1;
    3546                 :     1725435 :       j = lhs_ops.length () - 1;
    3547                 :     1725435 :       while (j >= 0 && i >= 0
    3548                 :     4563739 :              && vn_reference_op_eq (&vr->operands[i], &lhs_ops[j]))
    3549                 :             :         {
    3550                 :     2838304 :           i--;
    3551                 :     2838304 :           j--;
    3552                 :             :         }
    3553                 :             : 
    3554                 :             :       /* ???  The innermost op should always be a MEM_REF and we already
    3555                 :             :          checked that the assignment to the lhs kills vr.  Thus for
    3556                 :             :          aggregate copies using char[] types the vn_reference_op_eq
    3557                 :             :          may fail when comparing types for compatibility.  But we really
    3558                 :             :          don't care here - further lookups with the rewritten operands
    3559                 :             :          will simply fail if we messed up types too badly.  */
    3560                 :     1725435 :       poly_int64 extra_off = 0;
    3561                 :     1725435 :       if (j == 0 && i >= 0
    3562                 :      613634 :           && lhs_ops[0].opcode == MEM_REF
    3563                 :     2337436 :           && maybe_ne (lhs_ops[0].off, -1))
    3564                 :             :         {
    3565                 :      612001 :           if (known_eq (lhs_ops[0].off, vr->operands[i].off))
    3566                 :      179522 :             i--, j--;
    3567                 :      432479 :           else if (vr->operands[i].opcode == MEM_REF
    3568                 :      432479 :                    && maybe_ne (vr->operands[i].off, -1))
    3569                 :             :             {
    3570                 :      430942 :               extra_off = vr->operands[i].off - lhs_ops[0].off;
    3571                 :      430942 :               i--, j--;
    3572                 :             :             }
    3573                 :             :         }
    3574                 :             : 
    3575                 :             :       /* i now points to the first additional op.
    3576                 :             :          ???  LHS may not be completely contained in VR, one or more
    3577                 :             :          VIEW_CONVERT_EXPRs could be in its way.  We could at least
    3578                 :             :          try handling outermost VIEW_CONVERT_EXPRs.  */
    3579                 :     1725435 :       if (j != -1)
    3580                 :             :         return (void *)-1;
    3581                 :             : 
    3582                 :             :       /* Punt if the additional ops contain a storage order barrier.  */
    3583                 :     3289409 :       for (k = i; k >= 0; k--)
    3584                 :             :         {
    3585                 :     1589975 :           vro = &vr->operands[k];
    3586                 :     1589975 :           if (vro->opcode == VIEW_CONVERT_EXPR && vro->reverse)
    3587                 :             :             return (void *)-1;
    3588                 :             :         }
    3589                 :             : 
    3590                 :             :       /* Now re-write REF to be based on the rhs of the assignment.  */
    3591                 :     1699434 :       tree rhs1 = gimple_assign_rhs1 (def_stmt);
    3592                 :     1699434 :       copy_reference_ops_from_ref (rhs1, &rhs);
    3593                 :             : 
    3594                 :             :       /* Apply an extra offset to the inner MEM_REF of the RHS.  */
    3595                 :     1699434 :       bool force_no_tbaa = false;
    3596                 :     1699434 :       if (maybe_ne (extra_off, 0))
    3597                 :             :         {
    3598                 :      430942 :           if (rhs.length () < 2)
    3599                 :             :             return (void *)-1;
    3600                 :      430942 :           int ix = rhs.length () - 2;
    3601                 :      430942 :           if (rhs[ix].opcode != MEM_REF
    3602                 :      430942 :               || known_eq (rhs[ix].off, -1))
    3603                 :             :             return (void *)-1;
    3604                 :      430942 :           rhs[ix].off += extra_off;
    3605                 :      430942 :           rhs[ix].op0 = int_const_binop (PLUS_EXPR, rhs[ix].op0,
    3606                 :      430942 :                                          build_int_cst (TREE_TYPE (rhs[ix].op0),
    3607                 :             :                                                         extra_off));
    3608                 :             :           /* When we have offsetted the RHS, reading only parts of it,
    3609                 :             :              we can no longer use the original TBAA type, force alias-set
    3610                 :             :              zero.  */
    3611                 :      430942 :           force_no_tbaa = true;
    3612                 :             :         }
    3613                 :             : 
    3614                 :             :       /* Save the operands since we need to use the original ones for
    3615                 :             :          the hash entry we use.  */
    3616                 :     1699434 :       if (!data->saved_operands.exists ())
    3617                 :     1618907 :         data->saved_operands = vr->operands.copy ();
    3618                 :             : 
    3619                 :             :       /* We need to pre-pend vr->operands[0..i] to rhs.  */
    3620                 :     1699434 :       vec<vn_reference_op_s> old = vr->operands;
    3621                 :     5098302 :       if (i + 1 + rhs.length () > vr->operands.length ())
    3622                 :     1115881 :         vr->operands.safe_grow (i + 1 + rhs.length (), true);
    3623                 :             :       else
    3624                 :      583553 :         vr->operands.truncate (i + 1 + rhs.length ());
    3625                 :     6235964 :       FOR_EACH_VEC_ELT (rhs, j, vro)
    3626                 :     4536530 :         vr->operands[i + 1 + j] = *vro;
    3627                 :     1699434 :       valueize_refs (&vr->operands);
    3628                 :     3398868 :       if (old == shared_lookup_references)
    3629                 :     1699434 :         shared_lookup_references = vr->operands;
    3630                 :     1699434 :       vr->hashcode = vn_reference_compute_hash (vr);
    3631                 :             : 
    3632                 :             :       /* Try folding the new reference to a constant.  */
    3633                 :     1699434 :       tree val = fully_constant_vn_reference_p (vr);
    3634                 :     1699434 :       if (val)
    3635                 :             :         {
    3636                 :       19239 :           if (data->partial_defs.is_empty ())
    3637                 :       19234 :             return data->finish (ao_ref_alias_set (&lhs_ref),
    3638                 :       19234 :                                  ao_ref_base_alias_set (&lhs_ref), val);
    3639                 :             :           /* This is the only interesting case for partial-def handling
    3640                 :             :              coming from targets that like to gimplify init-ctors as
    3641                 :             :              aggregate copies from constant data like aarch64 for
    3642                 :             :              PR83518.  */
    3643                 :           5 :           if (maxsize.is_constant (&maxsizei) && known_eq (ref->size, maxsize))
    3644                 :             :             {
    3645                 :           5 :               pd_data pd;
    3646                 :           5 :               pd.rhs = val;
    3647                 :           5 :               pd.rhs_off = 0;
    3648                 :           5 :               pd.offset = 0;
    3649                 :           5 :               pd.size = maxsizei;
    3650                 :           5 :               return data->push_partial_def (pd, ao_ref_alias_set (&lhs_ref),
    3651                 :             :                                              ao_ref_base_alias_set (&lhs_ref),
    3652                 :             :                                              0, maxsizei);
    3653                 :             :             }
    3654                 :             :         }
    3655                 :             : 
    3656                 :             :       /* Continuing with partial defs isn't easily possible here, we
    3657                 :             :          have to find a full def from further lookups from here.  Probably
    3658                 :             :          not worth the special-casing everywhere.  */
    3659                 :     2133117 :       if (!data->partial_defs.is_empty ())
    3660                 :             :         return (void *)-1;
    3661                 :             : 
    3662                 :             :       /* Adjust *ref from the new operands.  */
    3663                 :     1675872 :       ao_ref rhs1_ref;
    3664                 :     1675872 :       ao_ref_init (&rhs1_ref, rhs1);
    3665                 :     2923783 :       if (!ao_ref_init_from_vn_reference (&r,
    3666                 :             :                                           force_no_tbaa ? 0
    3667                 :     1247911 :                                           : ao_ref_alias_set (&rhs1_ref),
    3668                 :             :                                           force_no_tbaa ? 0
    3669                 :     1247911 :                                           : ao_ref_base_alias_set (&rhs1_ref),
    3670                 :             :                                           vr->type, vr->operands))
    3671                 :             :         return (void *)-1;
    3672                 :             :       /* This can happen with bitfields.  */
    3673                 :     1675872 :       if (maybe_ne (ref->size, r.size))
    3674                 :             :         {
    3675                 :             :           /* If the access lacks some subsetting simply apply that by
    3676                 :             :              shortening it.  That in the end can only be successful
    3677                 :             :              if we can pun the lookup result which in turn requires
    3678                 :             :              exact offsets.  */
    3679                 :           0 :           if (known_eq (r.size, r.max_size)
    3680                 :           0 :               && known_lt (ref->size, r.size))
    3681                 :           0 :             r.size = r.max_size = ref->size;
    3682                 :             :           else
    3683                 :             :             return (void *)-1;
    3684                 :             :         }
    3685                 :     1675872 :       *ref = r;
    3686                 :     1675872 :       vr->offset = r.offset;
    3687                 :     1675872 :       vr->max_size = r.max_size;
    3688                 :             : 
    3689                 :             :       /* Do not update last seen VUSE after translating.  */
    3690                 :     1675872 :       data->last_vuse_ptr = NULL;
    3691                 :             :       /* Invalidate the original access path since it now contains
    3692                 :             :          the wrong base.  */
    3693                 :     1675872 :       data->orig_ref.ref = NULL_TREE;
    3694                 :             :       /* Use the alias-set of this LHS for recording an eventual result.  */
    3695                 :     1675872 :       if (data->first_set == -2)
    3696                 :             :         {
    3697                 :     1596687 :           data->first_set = ao_ref_alias_set (&lhs_ref);
    3698                 :     1596687 :           data->first_base_set = ao_ref_base_alias_set (&lhs_ref);
    3699                 :             :         }
    3700                 :             : 
    3701                 :             :       /* Keep looking for the adjusted *REF / VR pair.  */
    3702                 :     1675872 :       return NULL;
    3703                 :     2148033 :     }
    3704                 :             : 
    3705                 :             :   /* 6) For memcpy copies translate the reference through them if the copy
    3706                 :             :      kills ref.  But we cannot (easily) do this translation if the memcpy is
    3707                 :             :      a storage order barrier, i.e. is equivalent to a VIEW_CONVERT_EXPR that
    3708                 :             :      can modify the storage order of objects (see storage_order_barrier_p).  */
    3709                 :    15676840 :   else if (data->vn_walk_kind == VN_WALKREWRITE
    3710                 :    11895393 :            && is_gimple_reg_type (vr->type)
    3711                 :             :            /* ???  Handle BCOPY as well.  */
    3712                 :    11887988 :            && (gimple_call_builtin_p (def_stmt, BUILT_IN_MEMCPY)
    3713                 :    11815664 :                || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMCPY_CHK)
    3714                 :    11815288 :                || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMPCPY)
    3715                 :    11814232 :                || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMPCPY_CHK)
    3716                 :    11813989 :                || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMMOVE)
    3717                 :    11788358 :                || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMMOVE_CHK))
    3718                 :       99935 :            && (TREE_CODE (gimple_call_arg (def_stmt, 0)) == ADDR_EXPR
    3719                 :       92020 :                || TREE_CODE (gimple_call_arg (def_stmt, 0)) == SSA_NAME)
    3720                 :       99895 :            && (TREE_CODE (gimple_call_arg (def_stmt, 1)) == ADDR_EXPR
    3721                 :       64559 :                || TREE_CODE (gimple_call_arg (def_stmt, 1)) == SSA_NAME)
    3722                 :       99880 :            && (poly_int_tree_p (gimple_call_arg (def_stmt, 2), &copy_size)
    3723                 :       52874 :                || (TREE_CODE (gimple_call_arg (def_stmt, 2)) == SSA_NAME
    3724                 :       52874 :                    && poly_int_tree_p (SSA_VAL (gimple_call_arg (def_stmt, 2)),
    3725                 :             :                                        &copy_size)))
    3726                 :             :            /* Handling this is more complicated, give up for now.  */
    3727                 :    15725415 :            && data->partial_defs.is_empty ())
    3728                 :             :     {
    3729                 :       48247 :       tree lhs, rhs;
    3730                 :       48247 :       ao_ref r;
    3731                 :       48247 :       poly_int64 rhs_offset, lhs_offset;
    3732                 :       48247 :       vn_reference_op_s op;
    3733                 :       48247 :       poly_uint64 mem_offset;
    3734                 :       48247 :       poly_int64 at, byte_maxsize;
    3735                 :             : 
    3736                 :             :       /* Only handle non-variable, addressable refs.  */
    3737                 :       48247 :       if (maybe_ne (ref->size, maxsize)
    3738                 :       47786 :           || !multiple_p (offset, BITS_PER_UNIT, &at)
    3739                 :       48247 :           || !multiple_p (maxsize, BITS_PER_UNIT, &byte_maxsize))
    3740                 :         461 :         return (void *)-1;
    3741                 :             : 
    3742                 :             :       /* Extract a pointer base and an offset for the destination.  */
    3743                 :       47786 :       lhs = gimple_call_arg (def_stmt, 0);
    3744                 :       47786 :       lhs_offset = 0;
    3745                 :       47786 :       if (TREE_CODE (lhs) == SSA_NAME)
    3746                 :             :         {
    3747                 :       40839 :           lhs = vn_valueize (lhs);
    3748                 :       40839 :           if (TREE_CODE (lhs) == SSA_NAME)
    3749                 :             :             {
    3750                 :       40109 :               gimple *def_stmt = SSA_NAME_DEF_STMT (lhs);
    3751                 :       40109 :               if (gimple_assign_single_p (def_stmt)
    3752                 :       40109 :                   && gimple_assign_rhs_code (def_stmt) == ADDR_EXPR)
    3753                 :        2178 :                 lhs = gimple_assign_rhs1 (def_stmt);
    3754                 :             :             }
    3755                 :             :         }
    3756                 :       47786 :       if (TREE_CODE (lhs) == ADDR_EXPR)
    3757                 :             :         {
    3758                 :       14030 :           if (AGGREGATE_TYPE_P (TREE_TYPE (TREE_TYPE (lhs)))
    3759                 :       13730 :               && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_TYPE (lhs))))
    3760                 :             :             return (void *)-1;
    3761                 :        9771 :           tree tem = get_addr_base_and_unit_offset (TREE_OPERAND (lhs, 0),
    3762                 :             :                                                     &lhs_offset);
    3763                 :        9771 :           if (!tem)
    3764                 :             :             return (void *)-1;
    3765                 :        9277 :           if (TREE_CODE (tem) == MEM_REF
    3766                 :        9277 :               && poly_int_tree_p (TREE_OPERAND (tem, 1), &mem_offset))
    3767                 :             :             {
    3768                 :        1684 :               lhs = TREE_OPERAND (tem, 0);
    3769                 :        1684 :               if (TREE_CODE (lhs) == SSA_NAME)
    3770                 :        1684 :                 lhs = vn_valueize (lhs);
    3771                 :        1684 :               lhs_offset += mem_offset;
    3772                 :             :             }
    3773                 :        7593 :           else if (DECL_P (tem))
    3774                 :        7593 :             lhs = build_fold_addr_expr (tem);
    3775                 :             :           else
    3776                 :             :             return (void *)-1;
    3777                 :             :         }
    3778                 :       47208 :       if (TREE_CODE (lhs) != SSA_NAME
    3779                 :        7594 :           && TREE_CODE (lhs) != ADDR_EXPR)
    3780                 :             :         return (void *)-1;
    3781                 :             : 
    3782                 :             :       /* Extract a pointer base and an offset for the source.  */
    3783                 :       47208 :       rhs = gimple_call_arg (def_stmt, 1);
    3784                 :       47208 :       rhs_offset = 0;
    3785                 :       47208 :       if (TREE_CODE (rhs) == SSA_NAME)
    3786                 :       15463 :         rhs = vn_valueize (rhs);
    3787                 :       47208 :       if (TREE_CODE (rhs) == ADDR_EXPR)
    3788                 :             :         {
    3789                 :       44369 :           if (AGGREGATE_TYPE_P (TREE_TYPE (TREE_TYPE (rhs)))
    3790                 :       33077 :               && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_TYPE (rhs))))
    3791                 :             :             return (void *)-1;
    3792                 :       32629 :           tree tem = get_addr_base_and_unit_offset (TREE_OPERAND (rhs, 0),
    3793                 :             :                                                     &rhs_offset);
    3794                 :       32629 :           if (!tem)
    3795                 :             :             return (void *)-1;
    3796                 :       32629 :           if (TREE_CODE (tem) == MEM_REF
    3797                 :       32629 :               && poly_int_tree_p (TREE_OPERAND (tem, 1), &mem_offset))
    3798                 :             :             {
    3799                 :           0 :               rhs = TREE_OPERAND (tem, 0);
    3800                 :           0 :               rhs_offset += mem_offset;
    3801                 :             :             }
    3802                 :       32629 :           else if (DECL_P (tem)
    3803                 :       27584 :                    || TREE_CODE (tem) == STRING_CST)
    3804                 :       32629 :             rhs = build_fold_addr_expr (tem);
    3805                 :             :           else
    3806                 :             :             return (void *)-1;
    3807                 :             :         }
    3808                 :       47208 :       if (TREE_CODE (rhs) == SSA_NAME)
    3809                 :       14579 :         rhs = SSA_VAL (rhs);
    3810                 :       32629 :       else if (TREE_CODE (rhs) != ADDR_EXPR)
    3811                 :             :         return (void *)-1;
    3812                 :             : 
    3813                 :             :       /* The bases of the destination and the references have to agree.  */
    3814                 :       47208 :       if (TREE_CODE (base) == MEM_REF)
    3815                 :             :         {
    3816                 :       13274 :           if (TREE_OPERAND (base, 0) != lhs
    3817                 :       13274 :               || !poly_int_tree_p (TREE_OPERAND (base, 1), &mem_offset))
    3818                 :       10174 :             return (void *) -1;
    3819                 :        9675 :           at += mem_offset;
    3820                 :             :         }
    3821                 :       33934 :       else if (!DECL_P (base)
    3822                 :       33211 :                || TREE_CODE (lhs) != ADDR_EXPR
    3823                 :       40510 :                || TREE_OPERAND (lhs, 0) != base)
    3824                 :             :         return (void *)-1;
    3825                 :             : 
    3826                 :             :       /* If the access is completely outside of the memcpy destination
    3827                 :             :          area there is no aliasing.  */
    3828                 :        9675 :       if (!ranges_maybe_overlap_p (lhs_offset, copy_size, at, byte_maxsize))
    3829                 :             :         return NULL;
    3830                 :             :       /* And the access has to be contained within the memcpy destination.  */
    3831                 :        9646 :       if (!known_subrange_p (at, byte_maxsize, lhs_offset, copy_size))
    3832                 :             :         return (void *)-1;
    3833                 :             : 
    3834                 :             :       /* Save the operands since we need to use the original ones for
    3835                 :             :          the hash entry we use.  */
    3836                 :        9395 :       if (!data->saved_operands.exists ())
    3837                 :        9062 :         data->saved_operands = vr->operands.copy ();
    3838                 :             : 
    3839                 :             :       /* Make room for 2 operands in the new reference.  */
    3840                 :        9395 :       if (vr->operands.length () < 2)
    3841                 :             :         {
    3842                 :           0 :           vec<vn_reference_op_s> old = vr->operands;
    3843                 :           0 :           vr->operands.safe_grow_cleared (2, true);
    3844                 :           0 :           if (old == shared_lookup_references)
    3845                 :           0 :             shared_lookup_references = vr->operands;
    3846                 :             :         }
    3847                 :             :       else
    3848                 :        9395 :         vr->operands.truncate (2);
    3849                 :             : 
    3850                 :             :       /* The looked-through reference is a simple MEM_REF.  */
    3851                 :        9395 :       memset (&op, 0, sizeof (op));
    3852                 :        9395 :       op.type = vr->type;
    3853                 :        9395 :       op.opcode = MEM_REF;
    3854                 :        9395 :       op.op0 = build_int_cst (ptr_type_node, at - lhs_offset + rhs_offset);
    3855                 :        9395 :       op.off = at - lhs_offset + rhs_offset;
    3856                 :        9395 :       vr->operands[0] = op;
    3857                 :        9395 :       op.type = TREE_TYPE (rhs);
    3858                 :        9395 :       op.opcode = TREE_CODE (rhs);
    3859                 :        9395 :       op.op0 = rhs;
    3860                 :        9395 :       op.off = -1;
    3861                 :        9395 :       vr->operands[1] = op;
    3862                 :        9395 :       vr->hashcode = vn_reference_compute_hash (vr);
    3863                 :             : 
    3864                 :             :       /* Try folding the new reference to a constant.  */
    3865                 :        9395 :       tree val = fully_constant_vn_reference_p (vr);
    3866                 :        9395 :       if (val)
    3867                 :        2207 :         return data->finish (0, 0, val);
    3868                 :             : 
    3869                 :             :       /* Adjust *ref from the new operands.  */
    3870                 :        7188 :       if (!ao_ref_init_from_vn_reference (&r, 0, 0, vr->type, vr->operands))
    3871                 :             :         return (void *)-1;
    3872                 :             :       /* This can happen with bitfields.  */
    3873                 :        7188 :       if (maybe_ne (ref->size, r.size))
    3874                 :             :         return (void *)-1;
    3875                 :        7188 :       *ref = r;
    3876                 :        7188 :       vr->offset = r.offset;
    3877                 :        7188 :       vr->max_size = r.max_size;
    3878                 :             : 
    3879                 :             :       /* Do not update last seen VUSE after translating.  */
    3880                 :        7188 :       data->last_vuse_ptr = NULL;
    3881                 :             :       /* Invalidate the original access path since it now contains
    3882                 :             :          the wrong base.  */
    3883                 :        7188 :       data->orig_ref.ref = NULL_TREE;
    3884                 :             :       /* Use the alias-set of this stmt for recording an eventual result.  */
    3885                 :        7188 :       if (data->first_set == -2)
    3886                 :             :         {
    3887                 :        6880 :           data->first_set = 0;
    3888                 :        6880 :           data->first_base_set = 0;
    3889                 :             :         }
    3890                 :             : 
    3891                 :             :       /* Keep looking for the adjusted *REF / VR pair.  */
    3892                 :        7188 :       return NULL;
    3893                 :             :     }
    3894                 :             : 
    3895                 :             :   /* Bail out and stop walking.  */
    3896                 :             :   return (void *)-1;
    3897                 :             : }
    3898                 :             : 
    3899                 :             : /* Return a reference op vector from OP that can be used for
    3900                 :             :    vn_reference_lookup_pieces.  The caller is responsible for releasing
    3901                 :             :    the vector.  */
    3902                 :             : 
    3903                 :             : vec<vn_reference_op_s>
    3904                 :     4864185 : vn_reference_operands_for_lookup (tree op)
    3905                 :             : {
    3906                 :     4864185 :   bool valueized;
    3907                 :     4864185 :   return valueize_shared_reference_ops_from_ref (op, &valueized).copy ();
    3908                 :             : }
    3909                 :             : 
    3910                 :             : /* Lookup a reference operation by it's parts, in the current hash table.
    3911                 :             :    Returns the resulting value number if it exists in the hash table,
    3912                 :             :    NULL_TREE otherwise.  VNRESULT will be filled in with the actual
    3913                 :             :    vn_reference_t stored in the hashtable if something is found.  */
    3914                 :             : 
    3915                 :             : tree
    3916                 :     7740266 : vn_reference_lookup_pieces (tree vuse, alias_set_type set,
    3917                 :             :                             alias_set_type base_set, tree type,
    3918                 :             :                             vec<vn_reference_op_s> operands,
    3919                 :             :                             vn_reference_t *vnresult, vn_lookup_kind kind)
    3920                 :             : {
    3921                 :     7740266 :   struct vn_reference_s vr1;
    3922                 :     7740266 :   vn_reference_t tmp;
    3923                 :     7740266 :   tree cst;
    3924                 :             : 
    3925                 :     7740266 :   if (!vnresult)
    3926                 :           0 :     vnresult = &tmp;
    3927                 :     7740266 :   *vnresult = NULL;
    3928                 :             : 
    3929                 :     7740266 :   vr1.vuse = vuse_ssa_val (vuse);
    3930                 :     7740266 :   shared_lookup_references.truncate (0);
    3931                 :    15480532 :   shared_lookup_references.safe_grow (operands.length (), true);
    3932                 :     7740266 :   memcpy (shared_lookup_references.address (),
    3933                 :     7740266 :           operands.address (),
    3934                 :             :           sizeof (vn_reference_op_s)
    3935                 :     7740266 :           * operands.length ());
    3936                 :     7740266 :   bool valueized_p;
    3937                 :     7740266 :   valueize_refs_1 (&shared_lookup_references, &valueized_p);
    3938                 :     7740266 :   vr1.operands = shared_lookup_references;
    3939                 :     7740266 :   vr1.type = type;
    3940                 :     7740266 :   vr1.set = set;
    3941                 :     7740266 :   vr1.base_set = base_set;
    3942                 :             :   /* We can pretend there's no extra info fed in since the ao_refs offset
    3943                 :             :      and max_size are computed only from the VN reference ops.  */
    3944                 :     7740266 :   vr1.offset = 0;
    3945                 :     7740266 :   vr1.max_size = -1;
    3946                 :     7740266 :   vr1.hashcode = vn_reference_compute_hash (&vr1);
    3947                 :     7740266 :   if ((cst = fully_constant_vn_reference_p (&vr1)))
    3948                 :             :     return cst;
    3949                 :             : 
    3950                 :     7721805 :   vn_reference_lookup_1 (&vr1, vnresult);
    3951                 :     7721805 :   if (!*vnresult
    3952                 :     3115412 :       && kind != VN_NOWALK
    3953                 :     3115412 :       && vr1.vuse)
    3954                 :             :     {
    3955                 :     2850066 :       ao_ref r;
    3956                 :     2850066 :       unsigned limit = param_sccvn_max_alias_queries_per_access;
    3957                 :     2850066 :       vn_walk_cb_data data (&vr1, NULL_TREE, NULL, kind, true, NULL_TREE,
    3958                 :     2850066 :                             false);
    3959                 :     2850066 :       vec<vn_reference_op_s> ops_for_ref;
    3960                 :     2850066 :       if (!valueized_p)
    3961                 :     2780108 :         ops_for_ref = vr1.operands;
    3962                 :             :       else
    3963                 :             :         {
    3964                 :             :           /* For ao_ref_from_mem we have to ensure only available SSA names
    3965                 :             :              end up in base and the only convenient way to make this work
    3966                 :             :              for PRE is to re-valueize with that in mind.  */
    3967                 :      139916 :           ops_for_ref.create (operands.length ());
    3968                 :      139916 :           ops_for_ref.quick_grow (operands.length ());
    3969                 :       69958 :           memcpy (ops_for_ref.address (),
    3970                 :       69958 :                   operands.address (),
    3971                 :             :                   sizeof (vn_reference_op_s)
    3972                 :       69958 :                   * operands.length ());
    3973                 :       69958 :           valueize_refs_1 (&ops_for_ref, &valueized_p, true);
    3974                 :             :         }
    3975                 :     2850066 :       if (ao_ref_init_from_vn_reference (&r, set, base_set, type,
    3976                 :             :                                          ops_for_ref))
    3977                 :     2785184 :         *vnresult
    3978                 :     2785184 :           = ((vn_reference_t)
    3979                 :     2785184 :              walk_non_aliased_vuses (&r, vr1.vuse, true, vn_reference_lookup_2,
    3980                 :             :                                      vn_reference_lookup_3, vuse_valueize,
    3981                 :             :                                      limit, &data));
    3982                 :     5700132 :       if (ops_for_ref != shared_lookup_references)
    3983                 :       69958 :         ops_for_ref.release ();
    3984                 :     5700132 :       gcc_checking_assert (vr1.operands == shared_lookup_references);
    3985                 :     2850066 :       if (*vnresult
    3986                 :      379678 :           && data.same_val
    3987                 :     2850066 :           && (!(*vnresult)->result
    3988                 :           0 :               || !operand_equal_p ((*vnresult)->result, data.same_val)))
    3989                 :             :         {
    3990                 :           0 :           *vnresult = NULL;
    3991                 :           0 :           return NULL_TREE;
    3992                 :             :         }
    3993                 :     2850066 :     }
    3994                 :             : 
    3995                 :     7721805 :   if (*vnresult)
    3996                 :     4986071 :      return (*vnresult)->result;
    3997                 :             : 
    3998                 :             :   return NULL_TREE;
    3999                 :             : }
    4000                 :             : 
    4001                 :             : /* Lookup OP in the current hash table, and return the resulting value
    4002                 :             :    number if it exists in the hash table.  Return NULL_TREE if it does
    4003                 :             :    not exist in the hash table or if the result field of the structure
    4004                 :             :    was NULL..  VNRESULT will be filled in with the vn_reference_t
    4005                 :             :    stored in the hashtable if one exists.  When TBAA_P is false assume
    4006                 :             :    we are looking up a store and treat it as having alias-set zero.
    4007                 :             :    *LAST_VUSE_PTR will be updated with the VUSE the value lookup succeeded.
    4008                 :             :    MASK is either NULL_TREE, or can be an INTEGER_CST if the result of the
    4009                 :             :    load is bitwise anded with MASK and so we are only interested in a subset
    4010                 :             :    of the bits and can ignore if the other bits are uninitialized or
    4011                 :             :    not initialized with constants.  When doing redundant store removal
    4012                 :             :    the caller has to set REDUNDANT_STORE_REMOVAL_P.  */
    4013                 :             : 
    4014                 :             : tree
    4015                 :    92392841 : vn_reference_lookup (tree op, tree vuse, vn_lookup_kind kind,
    4016                 :             :                      vn_reference_t *vnresult, bool tbaa_p,
    4017                 :             :                      tree *last_vuse_ptr, tree mask,
    4018                 :             :                      bool redundant_store_removal_p)
    4019                 :             : {
    4020                 :    92392841 :   vec<vn_reference_op_s> operands;
    4021                 :    92392841 :   struct vn_reference_s vr1;
    4022                 :    92392841 :   bool valueized_anything;
    4023                 :             : 
    4024                 :    92392841 :   if (vnresult)
    4025                 :    92075521 :     *vnresult = NULL;
    4026                 :             : 
    4027                 :    92392841 :   vr1.vuse = vuse_ssa_val (vuse);
    4028                 :   184785682 :   vr1.operands = operands
    4029                 :    92392841 :     = valueize_shared_reference_ops_from_ref (op, &valueized_anything);
    4030                 :             : 
    4031                 :             :   /* Handle &MEM[ptr + 5].b[1].c as POINTER_PLUS_EXPR.  Avoid doing
    4032                 :             :      this before the pass folding __builtin_object_size had a chance to run.  */
    4033                 :    92392841 :   if ((cfun->curr_properties & PROP_objsz)
    4034                 :    67364700 :       && operands[0].opcode == ADDR_EXPR
    4035                 :    93460746 :       && operands.last ().opcode == SSA_NAME)
    4036                 :             :     {
    4037                 :             :       poly_int64 off = 0;
    4038                 :             :       vn_reference_op_t vro;
    4039                 :             :       unsigned i;
    4040                 :     3337322 :       for (i = 1; operands.iterate (i, &vro); ++i)
    4041                 :             :         {
    4042                 :     3337322 :           if (vro->opcode == SSA_NAME)
    4043                 :             :             break;
    4044                 :     2325092 :           else if (known_eq (vro->off, -1))
    4045                 :             :             break;
    4046                 :     2301972 :           off += vro->off;
    4047                 :             :         }
    4048                 :     1035350 :       if (i == operands.length () - 1
    4049                 :             :           /* Make sure we the offset we accumulated in a 64bit int
    4050                 :             :              fits the address computation carried out in target
    4051                 :             :              offset precision.  */
    4052                 :     2047580 :           && (off.coeffs[0]
    4053                 :     1012230 :               == sext_hwi (off.coeffs[0], TYPE_PRECISION (sizetype))))
    4054                 :             :         {
    4055                 :     1011910 :           gcc_assert (operands[i-1].opcode == MEM_REF);
    4056                 :     1011910 :           tree ops[2];
    4057                 :     1011910 :           ops[0] = operands[i].op0;
    4058                 :     1011910 :           ops[1] = wide_int_to_tree (sizetype, off);
    4059                 :     1011910 :           tree res = vn_nary_op_lookup_pieces (2, POINTER_PLUS_EXPR,
    4060                 :     1011910 :                                                TREE_TYPE (op), ops, NULL);
    4061                 :     1011910 :           if (res)
    4062                 :             :             return res;
    4063                 :     1011910 :           return NULL_TREE;
    4064                 :             :         }
    4065                 :             :     }
    4066                 :             : 
    4067                 :    91380931 :   vr1.type = TREE_TYPE (op);
    4068                 :    91380931 :   ao_ref op_ref;
    4069                 :    91380931 :   ao_ref_init (&op_ref, op);
    4070                 :    91380931 :   vr1.set = ao_ref_alias_set (&op_ref);
    4071                 :    91380931 :   vr1.base_set = ao_ref_base_alias_set (&op_ref);
    4072                 :    91380931 :   vr1.offset = 0;
    4073                 :    91380931 :   vr1.max_size = -1;
    4074                 :    91380931 :   vr1.hashcode = vn_reference_compute_hash (&vr1);
    4075                 :    91380931 :   if (mask == NULL_TREE)
    4076                 :    91063611 :     if (tree cst = fully_constant_vn_reference_p (&vr1))
    4077                 :             :       return cst;
    4078                 :             : 
    4079                 :    91368434 :   if (kind != VN_NOWALK && vr1.vuse)
    4080                 :             :     {
    4081                 :    53444077 :       vn_reference_t wvnresult;
    4082                 :    53444077 :       ao_ref r;
    4083                 :    53444077 :       unsigned limit = param_sccvn_max_alias_queries_per_access;
    4084                 :    53444077 :       auto_vec<vn_reference_op_s> ops_for_ref;
    4085                 :    53444077 :       if (valueized_anything)
    4086                 :             :         {
    4087                 :     3988043 :           copy_reference_ops_from_ref (op, &ops_for_ref);
    4088                 :     3988043 :           bool tem;
    4089                 :     3988043 :           valueize_refs_1 (&ops_for_ref, &tem, true);
    4090                 :             :         }
    4091                 :             :       /* Make sure to use a valueized reference if we valueized anything.
    4092                 :             :          Otherwise preserve the full reference for advanced TBAA.  */
    4093                 :    53444077 :       if (!valueized_anything
    4094                 :    53444077 :           || !ao_ref_init_from_vn_reference (&r, vr1.set, vr1.base_set,
    4095                 :             :                                              vr1.type, ops_for_ref))
    4096                 :             :         {
    4097                 :    49456034 :           ao_ref_init (&r, op);
    4098                 :             :           /* Record the extra info we're getting from the full ref.  */
    4099                 :    49456034 :           ao_ref_base (&r);
    4100                 :    49456034 :           vr1.offset = r.offset;
    4101                 :    49456034 :           vr1.max_size = r.max_size;
    4102                 :             :         }
    4103                 :    53444077 :       vn_walk_cb_data data (&vr1, r.ref ? NULL_TREE : op,
    4104                 :             :                             last_vuse_ptr, kind, tbaa_p, mask,
    4105                 :   102900111 :                             redundant_store_removal_p);
    4106                 :             : 
    4107                 :    53444077 :       wvnresult
    4108                 :             :         = ((vn_reference_t)
    4109                 :    53444077 :            walk_non_aliased_vuses (&r, vr1.vuse, tbaa_p, vn_reference_lookup_2,
    4110                 :             :                                    vn_reference_lookup_3, vuse_valueize, limit,
    4111                 :             :                                    &data));
    4112                 :   106888154 :       gcc_checking_assert (vr1.operands == shared_lookup_references);
    4113                 :    53444077 :       if (wvnresult)
    4114                 :             :         {
    4115                 :     7447867 :           gcc_assert (mask == NULL_TREE);
    4116                 :     7447867 :           if (data.same_val
    4117                 :     7447867 :               && (!wvnresult->result
    4118                 :       50589 :                   || !operand_equal_p (wvnresult->result, data.same_val)))
    4119                 :       41614 :             return NULL_TREE;
    4120                 :     7406253 :           if (vnresult)
    4121                 :     7406253 :             *vnresult = wvnresult;
    4122                 :     7406253 :           return wvnresult->result;
    4123                 :             :         }
    4124                 :    45996210 :       else if (mask)
    4125                 :      317320 :         return data.masked_result;
    4126                 :             : 
    4127                 :             :       return NULL_TREE;
    4128                 :    53444077 :     }
    4129                 :             : 
    4130                 :    37924357 :   if (last_vuse_ptr)
    4131                 :      998834 :     *last_vuse_ptr = vr1.vuse;
    4132                 :    37924357 :   if (mask)
    4133                 :             :     return NULL_TREE;
    4134                 :    37924357 :   return vn_reference_lookup_1 (&vr1, vnresult);
    4135                 :             : }
    4136                 :             : 
    4137                 :             : /* Lookup CALL in the current hash table and return the entry in
    4138                 :             :    *VNRESULT if found.  Populates *VR for the hashtable lookup.  */
    4139                 :             : 
    4140                 :             : void
    4141                 :     8698470 : vn_reference_lookup_call (gcall *call, vn_reference_t *vnresult,
    4142                 :             :                           vn_reference_t vr)
    4143                 :             : {
    4144                 :     8698470 :   if (vnresult)
    4145                 :     8698470 :     *vnresult = NULL;
    4146                 :             : 
    4147                 :     8698470 :   tree vuse = gimple_vuse (call);
    4148                 :             : 
    4149                 :     8698470 :   vr->vuse = vuse ? SSA_VAL (vuse) : NULL_TREE;
    4150                 :     8698470 :   vr->operands = valueize_shared_reference_ops_from_call (call);
    4151                 :     8698470 :   tree lhs = gimple_call_lhs (call);
    4152                 :             :   /* For non-SSA return values the referece ops contain the LHS.  */
    4153                 :     4841831 :   vr->type = ((lhs && TREE_CODE (lhs) == SSA_NAME)
    4154                 :    13104587 :               ? TREE_TYPE (lhs) : NULL_TREE);
    4155                 :     8698470 :   vr->punned = false;
    4156                 :     8698470 :   vr->set = 0;
    4157                 :     8698470 :   vr->base_set = 0;
    4158                 :     8698470 :   vr->offset = 0;
    4159                 :     8698470 :   vr->max_size = -1;
    4160                 :     8698470 :   vr->hashcode = vn_reference_compute_hash (vr);
    4161                 :     8698470 :   vn_reference_lookup_1 (vr, vnresult);
    4162                 :     8698470 : }
    4163                 :             : 
    4164                 :             : /* Insert OP into the current hash table with a value number of RESULT.  */
    4165                 :             : 
    4166                 :             : static void
    4167                 :    69034015 : vn_reference_insert (tree op, tree result, tree vuse, tree vdef)
    4168                 :             : {
    4169                 :    69034015 :   vn_reference_s **slot;
    4170                 :    69034015 :   vn_reference_t vr1;
    4171                 :    69034015 :   bool tem;
    4172                 :             : 
    4173                 :    69034015 :   vec<vn_reference_op_s> operands
    4174                 :    69034015 :     = valueize_shared_reference_ops_from_ref (op, &tem);
    4175                 :             :   /* Handle &MEM[ptr + 5].b[1].c as POINTER_PLUS_EXPR.  Avoid doing this
    4176                 :             :      before the pass folding __builtin_object_size had a chance to run.  */
    4177                 :    69034015 :   if ((cfun->curr_properties & PROP_objsz)
    4178                 :    52027658 :       && operands[0].opcode == ADDR_EXPR
    4179                 :    69908608 :       && operands.last ().opcode == SSA_NAME)
    4180                 :             :     {
    4181                 :             :       poly_int64 off = 0;
    4182                 :             :       vn_reference_op_t vro;
    4183                 :             :       unsigned i;
    4184                 :     2704653 :       for (i = 1; operands.iterate (i, &vro); ++i)
    4185                 :             :         {
    4186                 :     2704653 :           if (vro->opcode == SSA_NAME)
    4187                 :             :             break;
    4188                 :     1881965 :           else if (known_eq (vro->off, -1))
    4189                 :             :             break;
    4190                 :     1860799 :           off += vro->off;
    4191                 :             :         }
    4192                 :      843854 :       if (i == operands.length () - 1
    4193                 :             :           /* Make sure we the offset we accumulated in a 64bit int
    4194                 :             :              fits the address computation carried out in target
    4195                 :             :              offset precision.  */
    4196                 :     1666542 :           && (off.coeffs[0]
    4197                 :      822688 :               == sext_hwi (off.coeffs[0], TYPE_PRECISION (sizetype))))
    4198                 :             :         {
    4199                 :      822428 :           gcc_assert (operands[i-1].opcode == MEM_REF);
    4200                 :      822428 :           tree ops[2];
    4201                 :      822428 :           ops[0] = operands[i].op0;
    4202                 :      822428 :           ops[1] = wide_int_to_tree (sizetype, off);
    4203                 :      822428 :           vn_nary_op_insert_pieces (2, POINTER_PLUS_EXPR,
    4204                 :      822428 :                                     TREE_TYPE (op), ops, result,
    4205                 :      822428 :                                     VN_INFO (result)->value_id);
    4206                 :      822428 :           return;
    4207                 :             :         }
    4208                 :             :     }
    4209                 :             : 
    4210                 :    68211587 :   vr1 = XOBNEW (&vn_tables_obstack, vn_reference_s);
    4211                 :    68211587 :   if (TREE_CODE (result) == SSA_NAME)
    4212                 :    47194715 :     vr1->value_id = VN_INFO (result)->value_id;
    4213                 :             :   else
    4214                 :    21016872 :     vr1->value_id = get_or_alloc_constant_value_id (result);
    4215                 :    68211587 :   vr1->vuse = vuse_ssa_val (vuse);
    4216                 :    68211587 :   vr1->operands = operands.copy ();
    4217                 :    68211587 :   vr1->type = TREE_TYPE (op);
    4218                 :    68211587 :   vr1->punned = false;
    4219                 :    68211587 :   ao_ref op_ref;
    4220                 :    68211587 :   ao_ref_init (&op_ref, op);
    4221                 :    68211587 :   vr1->set = ao_ref_alias_set (&op_ref);
    4222                 :    68211587 :   vr1->base_set = ao_ref_base_alias_set (&op_ref);
    4223                 :             :   /* Specifically use an unknown extent here, we're not doing any lookup
    4224                 :             :      and assume the caller didn't either (or it went VARYING).  */
    4225                 :    68211587 :   vr1->offset = 0;
    4226                 :    68211587 :   vr1->max_size = -1;
    4227                 :    68211587 :   vr1->hashcode = vn_reference_compute_hash (vr1);
    4228                 :    68211587 :   vr1->result = TREE_CODE (result) == SSA_NAME ? SSA_VAL (result) : result;
    4229                 :    68211587 :   vr1->result_vdef = vdef;
    4230                 :             : 
    4231                 :    68211587 :   slot = valid_info->references->find_slot_with_hash (vr1, vr1->hashcode,
    4232                 :             :                                                       INSERT);
    4233                 :             : 
    4234                 :             :   /* Because IL walking on reference lookup can end up visiting
    4235                 :             :      a def that is only to be visited later in iteration order
    4236                 :             :      when we are about to make an irreducible region reducible
    4237                 :             :      the def can be effectively processed and its ref being inserted
    4238                 :             :      by vn_reference_lookup_3 already.  So we cannot assert (!*slot)
    4239                 :             :      but save a lookup if we deal with already inserted refs here.  */
    4240                 :    68211587 :   if (*slot)
    4241                 :             :     {
    4242                 :             :       /* We cannot assert that we have the same value either because
    4243                 :             :          when disentangling an irreducible region we may end up visiting
    4244                 :             :          a use before the corresponding def.  That's a missed optimization
    4245                 :             :          only though.  See gcc.dg/tree-ssa/pr87126.c for example.  */
    4246                 :           0 :       if (dump_file && (dump_flags & TDF_DETAILS)
    4247                 :           0 :           && !operand_equal_p ((*slot)->result, vr1->result, 0))
    4248                 :             :         {
    4249                 :           0 :           fprintf (dump_file, "Keeping old value ");
    4250                 :           0 :           print_generic_expr (dump_file, (*slot)->result);
    4251                 :           0 :           fprintf (dump_file, " because of collision\n");
    4252                 :             :         }
    4253                 :           0 :       free_reference (vr1);
    4254                 :           0 :       obstack_free (&vn_tables_obstack, vr1);
    4255                 :           0 :       return;
    4256                 :             :     }
    4257                 :             : 
    4258                 :    68211587 :   *slot = vr1;
    4259                 :    68211587 :   vr1->next = last_inserted_ref;
    4260                 :    68211587 :   last_inserted_ref = vr1;
    4261                 :             : }
    4262                 :             : 
    4263                 :             : /* Insert a reference by it's pieces into the current hash table with
    4264                 :             :    a value number of RESULT.  Return the resulting reference
    4265                 :             :    structure we created.  */
    4266                 :             : 
    4267                 :             : vn_reference_t
    4268                 :     3383737 : vn_reference_insert_pieces (tree vuse, alias_set_type set,
    4269                 :             :                             alias_set_type base_set,
    4270                 :             :                             poly_int64 offset, poly_int64 max_size, tree type,
    4271                 :             :                             vec<vn_reference_op_s> operands,
    4272                 :             :                             tree result, unsigned int value_id)
    4273                 :             : 
    4274                 :             : {
    4275                 :     3383737 :   vn_reference_s **slot;
    4276                 :     3383737 :   vn_reference_t vr1;
    4277                 :             : 
    4278                 :     3383737 :   vr1 = XOBNEW (&vn_tables_obstack, vn_reference_s);
    4279                 :     3383737 :   vr1->value_id = value_id;
    4280                 :     3383737 :   vr1->vuse = vuse_ssa_val (vuse);
    4281                 :     3383737 :   vr1->operands = operands;
    4282                 :     3383737 :   valueize_refs (&vr1->operands);
    4283                 :     3383737 :   vr1->type = type;
    4284                 :     3383737 :   vr1->punned = false;
    4285                 :     3383737 :   vr1->set = set;
    4286                 :     3383737 :   vr1->base_set = base_set;
    4287                 :     3383737 :   vr1->offset = offset;
    4288                 :     3383737 :   vr1->max_size = max_size;
    4289                 :     3383737 :   vr1->hashcode = vn_reference_compute_hash (vr1);
    4290                 :     3383737 :   if (result && TREE_CODE (result) == SSA_NAME)
    4291                 :      247311 :     result = SSA_VAL (result);
    4292                 :     3383737 :   vr1->result = result;
    4293                 :     3383737 :   vr1->result_vdef = NULL_TREE;
    4294                 :             : 
    4295                 :     3383737 :   slot = valid_info->references->find_slot_with_hash (vr1, vr1->hashcode,
    4296                 :             :                                                       INSERT);
    4297                 :             : 
    4298                 :             :   /* At this point we should have all the things inserted that we have
    4299                 :             :      seen before, and we should never try inserting something that
    4300                 :             :      already exists.  */
    4301                 :     3383737 :   gcc_assert (!*slot);
    4302                 :             : 
    4303                 :     3383737 :   *slot = vr1;
    4304                 :     3383737 :   vr1->next = last_inserted_ref;
    4305                 :     3383737 :   last_inserted_ref = vr1;
    4306                 :     3383737 :   return vr1;
    4307                 :             : }
    4308                 :             : 
    4309                 :             : /* Compute and return the hash value for nary operation VBO1.  */
    4310                 :             : 
    4311                 :             : hashval_t
    4312                 :   281124205 : vn_nary_op_compute_hash (const vn_nary_op_t vno1)
    4313                 :             : {
    4314                 :   281124205 :   inchash::hash hstate;
    4315                 :   281124205 :   unsigned i;
    4316                 :             : 
    4317                 :   281124205 :   if (((vno1->length == 2
    4318                 :   235973284 :         && commutative_tree_code (vno1->opcode))
    4319                 :   128788527 :        || (vno1->length == 3
    4320                 :     1313661 :            && commutative_ternary_tree_code (vno1->opcode)))
    4321                 :   433461199 :       && tree_swap_operands_p (vno1->op[0], vno1->op[1]))
    4322                 :     2925960 :     std::swap (vno1->op[0], vno1->op[1]);
    4323                 :   278198245 :   else if (TREE_CODE_CLASS (vno1->opcode) == tcc_comparison
    4324                 :   278198245 :            && tree_swap_operands_p (vno1->op[0], vno1->op[1]))
    4325                 :             :     {
    4326                 :      434894 :       std::swap (vno1->op[0], vno1->op[1]);
    4327                 :      434894 :       vno1->opcode = swap_tree_comparison  (vno1->opcode);
    4328                 :             :     }
    4329                 :             : 
    4330                 :   281124205 :   hstate.add_int (vno1->opcode);
    4331                 :   801502519 :   for (i = 0; i < vno1->length; ++i)
    4332                 :   520378314 :     inchash::add_expr (vno1->op[i], hstate);
    4333                 :             : 
    4334                 :   281124205 :   return hstate.end ();
    4335                 :             : }
    4336                 :             : 
    4337                 :             : /* Compare nary operations VNO1 and VNO2 and return true if they are
    4338                 :             :    equivalent.  */
    4339                 :             : 
    4340                 :             : bool
    4341                 :   908032322 : vn_nary_op_eq (const_vn_nary_op_t const vno1, const_vn_nary_op_t const vno2)
    4342                 :             : {
    4343                 :   908032322 :   unsigned i;
    4344                 :             : 
    4345                 :   908032322 :   if (vno1->hashcode != vno2->hashcode)
    4346                 :             :     return false;
    4347                 :             : 
    4348                 :    45804981 :   if (vno1->length != vno2->length)
    4349                 :             :     return false;
    4350                 :             : 
    4351                 :    45804981 :   if (vno1->opcode != vno2->opcode
    4352                 :    45804981 :       || !types_compatible_p (vno1->type, vno2->type))
    4353                 :     1120226 :     return false;
    4354                 :             : 
    4355                 :   128933377 :   for (i = 0; i < vno1->length; ++i)
    4356                 :    84338969 :     if (!expressions_equal_p (vno1->op[i], vno2->op[i]))
    4357                 :             :       return false;
    4358                 :             : 
    4359                 :             :   /* BIT_INSERT_EXPR has an implict operand as the type precision
    4360                 :             :      of op1.  Need to check to make sure they are the same.  */
    4361                 :    44594408 :   if (vno1->opcode == BIT_INSERT_EXPR
    4362                 :         482 :       && TREE_CODE (vno1->op[1]) == INTEGER_CST
    4363                 :    44594487 :       && TYPE_PRECISION (TREE_TYPE (vno1->op[1]))
    4364                 :          79 :          != TYPE_PRECISION (TREE_TYPE (vno2->op[1])))
    4365                 :             :     return false;
    4366                 :             : 
    4367                 :             :   return true;
    4368                 :             : }
    4369                 :             : 
    4370                 :             : /* Initialize VNO from the pieces provided.  */
    4371                 :             : 
    4372                 :             : static void
    4373                 :   173497848 : init_vn_nary_op_from_pieces (vn_nary_op_t vno, unsigned int length,
    4374                 :             :                              enum tree_code code, tree type, tree *ops)
    4375                 :             : {
    4376                 :   173497848 :   vno->opcode = code;
    4377                 :   173497848 :   vno->length = length;
    4378                 :   173497848 :   vno->type = type;
    4379                 :     4163272 :   memcpy (&vno->op[0], ops, sizeof (tree) * length);
    4380                 :           0 : }
    4381                 :             : 
    4382                 :             : /* Return the number of operands for a vn_nary ops structure from STMT.  */
    4383                 :             : 
    4384                 :             : unsigned int
    4385                 :   102263575 : vn_nary_length_from_stmt (gimple *stmt)
    4386                 :             : {
    4387                 :   102263575 :   switch (gimple_assign_rhs_code (stmt))
    4388                 :             :     {
    4389                 :             :     case REALPART_EXPR:
    4390                 :             :     case IMAGPART_EXPR:
    4391                 :             :     case VIEW_CONVERT_EXPR:
    4392                 :             :       return 1;
    4393                 :             : 
    4394                 :      517914 :     case BIT_FIELD_REF:
    4395                 :      517914 :       return 3;
    4396                 :             : 
    4397                 :      490748 :     case CONSTRUCTOR:
    4398                 :      490748 :       return CONSTRUCTOR_NELTS (gimple_assign_rhs1 (stmt));
    4399                 :             : 
    4400                 :    98045551 :     default:
    4401                 :    98045551 :       return gimple_num_ops (stmt) - 1;
    4402                 :             :     }
    4403                 :             : }
    4404                 :             : 
    4405                 :             : /* Initialize VNO from STMT.  */
    4406                 :             : 
    4407                 :             : void
    4408                 :   102263575 : init_vn_nary_op_from_stmt (vn_nary_op_t vno, gassign *stmt)
    4409                 :             : {
    4410                 :   102263575 :   unsigned i;
    4411                 :             : 
    4412                 :   102263575 :   vno->opcode = gimple_assign_rhs_code (stmt);
    4413                 :   102263575 :   vno->type = TREE_TYPE (gimple_assign_lhs (stmt));
    4414                 :   102263575 :   switch (vno->opcode)
    4415                 :             :     {
    4416                 :     3209362 :     case REALPART_EXPR:
    4417                 :     3209362 :     case IMAGPART_EXPR:
    4418                 :     3209362 :     case VIEW_CONVERT_EXPR:
    4419                 :     3209362 :       vno->length = 1;
    4420                 :     3209362 :       vno->op[0] = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
    4421                 :     3209362 :       break;
    4422                 :             : 
    4423                 :      517914 :     case BIT_FIELD_REF:
    4424                 :      517914 :       vno->length = 3;
    4425                 :      517914 :       vno->op[0] = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
    4426                 :      517914 :       vno->op[1] = TREE_OPERAND (gimple_assign_rhs1 (stmt), 1);
    4427                 :      517914 :       vno->op[2] = TREE_OPERAND (gimple_assign_rhs1 (stmt), 2);
    4428                 :      517914 :       break;
    4429                 :             : 
    4430                 :      490748 :     case CONSTRUCTOR:
    4431                 :      490748 :       vno->length = CONSTRUCTOR_NELTS (gimple_assign_rhs1 (stmt));
    4432                 :     1903696 :       for (i = 0; i < vno->length; ++i)
    4433                 :     1412948 :         vno->op[i] = CONSTRUCTOR_ELT (gimple_assign_rhs1 (stmt), i)->value;
    4434                 :             :       break;
    4435                 :             : 
    4436                 :    98045551 :     default:
    4437                 :    98045551 :       gcc_checking_assert (!gimple_assign_single_p (stmt));
    4438                 :    98045551 :       vno->length = gimple_num_ops (stmt) - 1;
    4439                 :   267980655 :       for (i = 0; i < vno->length; ++i)
    4440                 :   169935104 :         vno->op[i] = gimple_op (stmt, i + 1);
    4441                 :             :     }
    4442                 :   102263575 : }
    4443                 :             : 
    4444                 :             : /* Compute the hashcode for VNO and look for it in the hash table;
    4445                 :             :    return the resulting value number if it exists in the hash table.
    4446                 :             :    Return NULL_TREE if it does not exist in the hash table or if the
    4447                 :             :    result field of the operation is NULL.  VNRESULT will contain the
    4448                 :             :    vn_nary_op_t from the hashtable if it exists.  */
    4449                 :             : 
    4450                 :             : static tree
    4451                 :   122689911 : vn_nary_op_lookup_1 (vn_nary_op_t vno, vn_nary_op_t *vnresult)
    4452                 :             : {
    4453                 :   122689911 :   vn_nary_op_s **slot;
    4454                 :             : 
    4455                 :   122689911 :   if (vnresult)
    4456                 :   115834382 :     *vnresult = NULL;
    4457                 :             : 
    4458                 :   340789288 :   for (unsigned i = 0; i < vno->length; ++i)
    4459                 :   218099377 :     if (TREE_CODE (vno->op[i]) == SSA_NAME)
    4460                 :   155163835 :       vno->op[i] = SSA_VAL (vno->op[i]);
    4461                 :             : 
    4462                 :   122689911 :   vno->hashcode = vn_nary_op_compute_hash (vno);
    4463                 :   122689911 :   slot = valid_info->nary->find_slot_with_hash (vno, vno->hashcode, NO_INSERT);
    4464                 :   122689911 :   if (!slot)
    4465                 :             :     return NULL_TREE;
    4466                 :    16240573 :   if (vnresult)
    4467                 :    15779867 :     *vnresult = *slot;
    4468                 :    16240573 :   return (*slot)->predicated_values ? NULL_TREE : (*slot)->u.result;
    4469                 :             : }
    4470                 :             : 
    4471                 :             : /* Lookup a n-ary operation by its pieces and return the resulting value
    4472                 :             :    number if it exists in the hash table.  Return NULL_TREE if it does
    4473                 :             :    not exist in the hash table or if the result field of the operation
    4474                 :             :    is NULL. VNRESULT will contain the vn_nary_op_t from the hashtable
    4475                 :             :    if it exists.  */
    4476                 :             : 
    4477                 :             : tree
    4478                 :    69785413 : vn_nary_op_lookup_pieces (unsigned int length, enum tree_code code,
    4479                 :             :                           tree type, tree *ops, vn_nary_op_t *vnresult)
    4480                 :             : {
    4481                 :    69785413 :   vn_nary_op_t vno1 = XALLOCAVAR (struct vn_nary_op_s,
    4482                 :             :                                   sizeof_vn_nary_op (length));
    4483                 :    69785413 :   init_vn_nary_op_from_pieces (vno1, length, code, type, ops);
    4484                 :    69785413 :   return vn_nary_op_lookup_1 (vno1, vnresult);
    4485                 :             : }
    4486                 :             : 
    4487                 :             : /* Lookup the rhs of STMT in the current hash table, and return the resulting
    4488                 :             :    value number if it exists in the hash table.  Return NULL_TREE if
    4489                 :             :    it does not exist in the hash table.  VNRESULT will contain the
    4490                 :             :    vn_nary_op_t from the hashtable if it exists.  */
    4491                 :             : 
    4492                 :             : tree
    4493                 :    52904498 : vn_nary_op_lookup_stmt (gimple *stmt, vn_nary_op_t *vnresult)
    4494                 :             : {
    4495                 :    52904498 :   vn_nary_op_t vno1
    4496                 :    52904498 :     = XALLOCAVAR (struct vn_nary_op_s,
    4497                 :             :                   sizeof_vn_nary_op (vn_nary_length_from_stmt (stmt)));
    4498                 :    52904498 :   init_vn_nary_op_from_stmt (vno1, as_a <gassign *> (stmt));
    4499                 :    52904498 :   return vn_nary_op_lookup_1 (vno1, vnresult);
    4500                 :             : }
    4501                 :             : 
    4502                 :             : /* Allocate a vn_nary_op_t with LENGTH operands on STACK.  */
    4503                 :             : 
    4504                 :             : vn_nary_op_t
    4505                 :   157559452 : alloc_vn_nary_op_noinit (unsigned int length, struct obstack *stack)
    4506                 :             : {
    4507                 :   157559452 :   return (vn_nary_op_t) obstack_alloc (stack, sizeof_vn_nary_op (length));
    4508                 :             : }
    4509                 :             : 
    4510                 :             : /* Allocate and initialize a vn_nary_op_t on CURRENT_INFO's
    4511                 :             :    obstack.  */
    4512                 :             : 
    4513                 :             : static vn_nary_op_t
    4514                 :   141750366 : alloc_vn_nary_op (unsigned int length, tree result, unsigned int value_id)
    4515                 :             : {
    4516                 :           0 :   vn_nary_op_t vno1 = alloc_vn_nary_op_noinit (length, &vn_tables_obstack);
    4517                 :             : 
    4518                 :   141750366 :   vno1->value_id = value_id;
    4519                 :   141750366 :   vno1->length = length;
    4520                 :   141750366 :   vno1->predicated_values = 0;
    4521                 :   141750366 :   vno1->u.result = result;
    4522                 :             : 
    4523                 :   141750366 :   return vno1;
    4524                 :             : }
    4525                 :             : 
    4526                 :             : /* Insert VNO into TABLE.  */
    4527                 :             : 
    4528                 :             : static vn_nary_op_t
    4529                 :   146077347 : vn_nary_op_insert_into (vn_nary_op_t vno, vn_nary_op_table_type *table)
    4530                 :             : {
    4531                 :   146077347 :   vn_nary_op_s **slot;
    4532                 :             : 
    4533                 :   146077347 :   gcc_assert (! vno->predicated_values
    4534                 :             :               || (! vno->u.values->next
    4535                 :             :                   && vno->u.values->n == 1));
    4536                 :             : 
    4537                 :   426996377 :   for (unsigned i = 0; i < vno->length; ++i)
    4538                 :   280919030 :     if (TREE_CODE (vno->op[i]) == SSA_NAME)
    4539                 :   183157403 :       vno->op[i] = SSA_VAL (vno->op[i]);
    4540                 :             : 
    4541                 :   146077347 :   vno->hashcode = vn_nary_op_compute_hash (vno);
    4542                 :   146077347 :   slot = table->find_slot_with_hash (vno, vno->hashcode, INSERT);
    4543                 :   146077347 :   vno->unwind_to = *slot;
    4544                 :   146077347 :   if (*slot)
    4545                 :             :     {
    4546                 :             :       /* Prefer non-predicated values.
    4547                 :             :          ???  Only if those are constant, otherwise, with constant predicated
    4548                 :             :          value, turn them into predicated values with entry-block validity
    4549                 :             :          (???  but we always find the first valid result currently).  */
    4550                 :    27478993 :       if ((*slot)->predicated_values
    4551                 :    26726302 :           && ! vno->predicated_values)
    4552                 :             :         {
    4553                 :             :           /* ???  We cannot remove *slot from the unwind stack list.
    4554                 :             :              For the moment we deal with this by skipping not found
    4555                 :             :              entries but this isn't ideal ...  */
    4556                 :       79892 :           *slot = vno;
    4557                 :             :           /* ???  Maintain a stack of states we can unwind in
    4558                 :             :              vn_nary_op_s?  But how far do we unwind?  In reality
    4559                 :             :              we need to push change records somewhere...  Or not
    4560                 :             :              unwind vn_nary_op_s and linking them but instead
    4561                 :             :              unwind the results "list", linking that, which also
    4562                 :             :              doesn't move on hashtable resize.  */
    4563                 :             :           /* We can also have a ->unwind_to recording *slot there.
    4564                 :             :              That way we can make u.values a fixed size array with
    4565                 :             :              recording the number of entries but of course we then
    4566                 :             :              have always N copies for each unwind_to-state.  Or we
    4567                 :             :              make sure to only ever append and each unwinding will
    4568                 :             :              pop off one entry (but how to deal with predicated
    4569                 :             :              replaced with non-predicated here?)  */
    4570                 :       79892 :           vno->next = last_inserted_nary;
    4571                 :       79892 :           last_inserted_nary = vno;
    4572                 :       79892 :           return vno;
    4573                 :             :         }
    4574                 :    27399101 :       else if (vno->predicated_values
    4575                 :    27395073 :                && ! (*slot)->predicated_values)
    4576                 :             :         return *slot;
    4577                 :    26650438 :       else if (vno->predicated_values
    4578                 :    26646410 :                && (*slot)->predicated_values)
    4579                 :             :         {
    4580                 :             :           /* ???  Factor this all into a insert_single_predicated_value
    4581                 :             :              routine.  */
    4582                 :    26646410 :           gcc_assert (!vno->u.values->next && vno->u.values->n == 1);
    4583                 :    26646410 :           basic_block vno_bb
    4584                 :    26646410 :             = BASIC_BLOCK_FOR_FN (cfun, vno->u.values->valid_dominated_by_p[0]);
    4585                 :    26646410 :           vn_pval *nval = vno->u.values;
    4586                 :    26646410 :           vn_pval **next = &vno->u.values;
    4587                 :    26646410 :           bool found = false;
    4588                 :    54802685 :           for (vn_pval *val = (*slot)->u.values; val; val = val->next)
    4589                 :             :             {
    4590                 :    28381632 :               if (expressions_equal_p (val->result, nval->result))
    4591                 :             :                 {
    4592                 :    11729503 :                   found = true;
    4593                 :    11729503 :                   for (unsigned i = 0; i < val->n; ++i)
    4594                 :             :                     {
    4595                 :     8149470 :                       basic_block val_bb
    4596                 :     8149470 :                         = BASIC_BLOCK_FOR_FN (cfun,
    4597                 :             :                                               val->valid_dominated_by_p[i]);
    4598                 :     8149470 :                       if (dominated_by_p (CDI_DOMINATORS, vno_bb, val_bb))
    4599                 :             :                         /* Value registered with more generic predicate.  */
    4600                 :      225357 :                         return *slot;
    4601                 :     7924113 :                       else if (flag_checking)
    4602                 :             :                         /* Shouldn't happen, we insert in RPO order.  */
    4603                 :     7924113 :                         gcc_assert (!dominated_by_p (CDI_DOMINATORS,
    4604                 :             :                                                      val_bb, vno_bb));
    4605                 :             :                     }
    4606                 :             :                   /* Append value.  */
    4607                 :     3580033 :                   *next = (vn_pval *) obstack_alloc (&vn_tables_obstack,
    4608                 :             :                                                      sizeof (vn_pval)
    4609                 :             :                                                      + val->n * sizeof (int));
    4610                 :     3580033 :                   (*next)->next = NULL;
    4611                 :     3580033 :                   (*next)->result = val->result;
    4612                 :     3580033 :                   (*next)->n = val->n + 1;
    4613                 :     3580033 :                   memcpy ((*next)->valid_dominated_by_p,
    4614                 :     3580033 :                           val->valid_dominated_by_p,
    4615                 :     3580033 :                           val->n * sizeof (int));
    4616                 :     3580033 :                   (*next)->valid_dominated_by_p[val->n] = vno_bb->index;
    4617                 :     3580033 :                   next = &(*next)->next;
    4618                 :     3580033 :                   if (dump_file && (dump_flags & TDF_DETAILS))
    4619                 :           4 :                     fprintf (dump_file, "Appending predicate to value.\n");
    4620                 :     3580033 :                   continue;
    4621                 :     3580033 :                 }
    4622                 :             :               /* Copy other predicated values.  */
    4623                 :    24576242 :               *next = (vn_pval *) obstack_alloc (&vn_tables_obstack,
    4624                 :             :                                                  sizeof (vn_pval)
    4625                 :             :                                                  + (val->n-1) * sizeof (int));
    4626                 :    24576242 :               memcpy (*next, val, sizeof (vn_pval) + (val->n-1) * sizeof (int));
    4627                 :    24576242 :               (*next)->next = NULL;
    4628                 :    24576242 :               next = &(*next)->next;
    4629                 :             :             }
    4630                 :    26421053 :           if (!found)
    4631                 :    22841020 :             *next = nval;
    4632                 :             : 
    4633                 :    26421053 :           *slot = vno;
    4634                 :    26421053 :           vno->next = last_inserted_nary;
    4635                 :    26421053 :           last_inserted_nary = vno;
    4636                 :    26421053 :           return vno;
    4637                 :             :         }
    4638                 :             : 
    4639                 :             :       /* While we do not want to insert things twice it's awkward to
    4640                 :             :          avoid it in the case where visit_nary_op pattern-matches stuff
    4641                 :             :          and ends up simplifying the replacement to itself.  We then
    4642                 :             :          get two inserts, one from visit_nary_op and one from
    4643                 :             :          vn_nary_build_or_lookup.
    4644                 :             :          So allow inserts with the same value number.  */
    4645                 :        4028 :       if ((*slot)->u.result == vno->u.result)
    4646                 :             :         return *slot;
    4647                 :             :     }
    4648                 :             : 
    4649                 :             :   /* ???  There's also optimistic vs. previous commited state merging
    4650                 :             :      that is problematic for the case of unwinding.  */
    4651                 :             : 
    4652                 :             :   /* ???  We should return NULL if we do not use 'vno' and have the
    4653                 :             :      caller release it.  */
    4654                 :   118598354 :   gcc_assert (!*slot);
    4655                 :             : 
    4656                 :   118598354 :   *slot = vno;
    4657                 :   118598354 :   vno->next = last_inserted_nary;
    4658                 :   118598354 :   last_inserted_nary = vno;
    4659                 :   118598354 :   return vno;
    4660                 :             : }
    4661                 :             : 
    4662                 :             : /* Insert a n-ary operation into the current hash table using it's
    4663                 :             :    pieces.  Return the vn_nary_op_t structure we created and put in
    4664                 :             :    the hashtable.  */
    4665                 :             : 
    4666                 :             : vn_nary_op_t
    4667                 :      822428 : vn_nary_op_insert_pieces (unsigned int length, enum tree_code code,
    4668                 :             :                           tree type, tree *ops,
    4669                 :             :                           tree result, unsigned int value_id)
    4670                 :             : {
    4671                 :      822428 :   vn_nary_op_t vno1 = alloc_vn_nary_op (length, result, value_id);
    4672                 :      822428 :   init_vn_nary_op_from_pieces (vno1, length, code, type, ops);
    4673                 :      822428 :   return vn_nary_op_insert_into (vno1, valid_info->nary);
    4674                 :             : }
    4675                 :             : 
    4676                 :             : /* Return whether we can track a predicate valid when PRED_E is executed.  */
    4677                 :             : 
    4678                 :             : static bool
    4679                 :   139261389 : can_track_predicate_on_edge (edge pred_e)
    4680                 :             : {
    4681                 :             :   /* ???  As we are currently recording the destination basic-block index in
    4682                 :             :      vn_pval.valid_dominated_by_p and using dominance for the
    4683                 :             :      validity check we cannot track predicates on all edges.  */
    4684                 :   139261389 :   if (single_pred_p (pred_e->dest))
    4685                 :             :     return true;
    4686                 :             :   /* Never record for backedges.  */
    4687                 :    10840856 :   if (pred_e->flags & EDGE_DFS_BACK)
    4688                 :             :     return false;
    4689                 :             :   /* When there's more than one predecessor we cannot track
    4690                 :             :      predicate validity based on the destination block.  The
    4691                 :             :      exception is when all other incoming edges sources are
    4692                 :             :      dominated by the destination block.  */
    4693                 :    10225740 :   edge_iterator ei;
    4694                 :    10225740 :   edge e;
    4695                 :    17824037 :   FOR_EACH_EDGE (e, ei, pred_e->dest->preds)
    4696                 :    16085701 :     if (e != pred_e && ! dominated_by_p (CDI_DOMINATORS, e->src, e->dest))
    4697                 :             :       return false;
    4698                 :             :   return true;
    4699                 :             : }
    4700                 :             : 
    4701                 :             : static vn_nary_op_t
    4702                 :    98726735 : vn_nary_op_insert_pieces_predicated (unsigned int length, enum tree_code code,
    4703                 :             :                                      tree type, tree *ops,
    4704                 :             :                                      tree result, unsigned int value_id,
    4705                 :             :                                      edge pred_e)
    4706                 :             : {
    4707                 :    98726735 :   gcc_assert (can_track_predicate_on_edge (pred_e));
    4708                 :             : 
    4709                 :       67209 :   if (dump_file && (dump_flags & TDF_DETAILS)
    4710                 :             :       /* ???  Fix dumping, but currently we only get comparisons.  */
    4711                 :    98790202 :       && TREE_CODE_CLASS (code) == tcc_comparison)
    4712                 :             :     {
    4713                 :       63467 :       fprintf (dump_file, "Recording on edge %d->%d ", pred_e->src->index,
    4714                 :       63467 :                pred_e->dest->index);
    4715                 :       63467 :       print_generic_expr (dump_file, ops[0], TDF_SLIM);
    4716                 :       63467 :       fprintf (dump_file, " %s ", get_tree_code_name (code));
    4717                 :       63467 :       print_generic_expr (dump_file, ops[1], TDF_SLIM);
    4718                 :       94900 :       fprintf (dump_file, " == %s\n",
    4719                 :       63467 :                integer_zerop (result) ? "false" : "true");
    4720                 :             :     }
    4721                 :    98726735 :   vn_nary_op_t vno1 = alloc_vn_nary_op (length, NULL_TREE, value_id);
    4722                 :    98726735 :   init_vn_nary_op_from_pieces (vno1, length, code, type, ops);
    4723                 :    98726735 :   vno1->predicated_values = 1;
    4724                 :    98726735 :   vno1->u.values = (vn_pval *) obstack_alloc (&vn_tables_obstack,
    4725                 :             :                                               sizeof (vn_pval));
    4726                 :    98726735 :   vno1->u.values->next = NULL;
    4727                 :    98726735 :   vno1->u.values->result = result;
    4728                 :    98726735 :   vno1->u.values->n = 1;
    4729                 :    98726735 :   vno1->u.values->valid_dominated_by_p[0] = pred_e->dest->index;
    4730                 :    98726735 :   return vn_nary_op_insert_into (vno1, valid_info->nary);
    4731                 :             : }
    4732                 :             : 
    4733                 :             : static bool
    4734                 :             : dominated_by_p_w_unex (basic_block bb1, basic_block bb2, bool);
    4735                 :             : 
    4736                 :             : static tree
    4737                 :     1438938 : vn_nary_op_get_predicated_value (vn_nary_op_t vno, basic_block bb,
    4738                 :             :                                  edge e = NULL)
    4739                 :             : {
    4740                 :     1438938 :   if (! vno->predicated_values)
    4741                 :           0 :     return vno->u.result;
    4742                 :     2992400 :   for (vn_pval *val = vno->u.values; val; val = val->next)
    4743                 :     5005444 :     for (unsigned i = 0; i < val->n; ++i)
    4744                 :             :       {
    4745                 :     3451982 :         basic_block cand
    4746                 :     3451982 :           = BASIC_BLOCK_FOR_FN (cfun, val->valid_dominated_by_p[i]);
    4747                 :             :         /* Do not handle backedge executability optimistically since
    4748                 :             :            when figuring out whether to iterate we do not consider
    4749                 :             :            changed predication.
    4750                 :             :            When asking for predicated values on an edge avoid looking
    4751                 :             :            at edge executability for edges forward in our iteration
    4752                 :             :            as well.  */
    4753                 :     3451982 :         if (e && (e->flags & EDGE_DFS_BACK))
    4754                 :             :           {
    4755                 :       20461 :             if (dominated_by_p (CDI_DOMINATORS, bb, cand))
    4756                 :        7715 :               return val->result;
    4757                 :             :           }
    4758                 :     3431521 :         else if (dominated_by_p_w_unex (bb, cand, false))
    4759                 :      427024 :           return val->result;
    4760                 :             :       }
    4761                 :             :   return NULL_TREE;
    4762                 :             : }
    4763                 :             : 
    4764                 :             : static tree
    4765                 :      188103 : vn_nary_op_get_predicated_value (vn_nary_op_t vno, edge e)
    4766                 :             : {
    4767                 :           0 :   return vn_nary_op_get_predicated_value (vno, e->src, e);
    4768                 :             : }
    4769                 :             : 
    4770                 :             : /* Insert the rhs of STMT into the current hash table with a value number of
    4771                 :             :    RESULT.  */
    4772                 :             : 
    4773                 :             : static vn_nary_op_t
    4774                 :    42201203 : vn_nary_op_insert_stmt (gimple *stmt, tree result)
    4775                 :             : {
    4776                 :    42201203 :   vn_nary_op_t vno1
    4777                 :    42201203 :     = alloc_vn_nary_op (vn_nary_length_from_stmt (stmt),
    4778                 :    42201203 :                         result, VN_INFO (result)->value_id);
    4779                 :    42201203 :   init_vn_nary_op_from_stmt (vno1, as_a <gassign *> (stmt));
    4780                 :    42201203 :   return vn_nary_op_insert_into (vno1, valid_info->nary);
    4781                 :             : }
    4782                 :             : 
    4783                 :             : /* Compute a hashcode for PHI operation VP1 and return it.  */
    4784                 :             : 
    4785                 :             : static inline hashval_t
    4786                 :    47408216 : vn_phi_compute_hash (vn_phi_t vp1)
    4787                 :             : {
    4788                 :    47408216 :   inchash::hash hstate;
    4789                 :    47408216 :   tree phi1op;
    4790                 :    47408216 :   tree type;
    4791                 :    47408216 :   edge e;
    4792                 :    47408216 :   edge_iterator ei;
    4793                 :             : 
    4794                 :    94816432 :   hstate.add_int (EDGE_COUNT (vp1->block->preds));
    4795                 :    47408216 :   switch (EDGE_COUNT (vp1->block->preds))
    4796                 :             :     {
    4797                 :             :     case 1:
    4798                 :             :       break;
    4799                 :    41485745 :     case 2:
    4800                 :             :       /* When this is a PHI node subject to CSE for different blocks
    4801                 :             :          avoid hashing the block index.  */
    4802                 :    41485745 :       if (vp1->cclhs)
    4803                 :             :         break;
    4804                 :             :       /* Fallthru.  */
    4805                 :    30914937 :     default:
    4806                 :    30914937 :       hstate.add_int (vp1->block->index);
    4807                 :             :     }
    4808                 :             : 
    4809                 :             :   /* If all PHI arguments are constants we need to distinguish
    4810                 :             :      the PHI node via its type.  */
    4811                 :    47408216 :   type = vp1->type;
    4812                 :    47408216 :   hstate.merge_hash (vn_hash_type (type));
    4813                 :             : 
    4814                 :   162481845 :   FOR_EACH_EDGE (e, ei, vp1->block->preds)
    4815                 :             :     {
    4816                 :             :       /* Don't hash backedge values they need to be handled as VN_TOP
    4817                 :             :          for optimistic value-numbering.  */
    4818                 :   115073629 :       if (e->flags & EDGE_DFS_BACK)
    4819                 :    25915607 :         continue;
    4820                 :             : 
    4821                 :    89158022 :       phi1op = vp1->phiargs[e->dest_idx];
    4822                 :    89158022 :       if (phi1op == VN_TOP)
    4823                 :      236154 :         continue;
    4824                 :    88921868 :       inchash::add_expr (phi1op, hstate);
    4825                 :             :     }
    4826                 :             : 
    4827                 :    47408216 :   return hstate.end ();
    4828                 :             : }
    4829                 :             : 
    4830                 :             : 
    4831                 :             : /* Return true if COND1 and COND2 represent the same condition, set
    4832                 :             :    *INVERTED_P if one needs to be inverted to make it the same as
    4833                 :             :    the other.  */
    4834                 :             : 
    4835                 :             : static bool
    4836                 :     2717468 : cond_stmts_equal_p (gcond *cond1, tree lhs1, tree rhs1,
    4837                 :             :                     gcond *cond2, tree lhs2, tree rhs2, bool *inverted_p)
    4838                 :             : {
    4839                 :     2717468 :   enum tree_code code1 = gimple_cond_code (cond1);
    4840                 :     2717468 :   enum tree_code code2 = gimple_cond_code (cond2);
    4841                 :             : 
    4842                 :     2717468 :   *inverted_p = false;
    4843                 :     2717468 :   if (code1 == code2)
    4844                 :             :     ;
    4845                 :      219590 :   else if (code1 == swap_tree_comparison (code2))
    4846                 :             :     std::swap (lhs2, rhs2);
    4847                 :      185951 :   else if (code1 == invert_tree_comparison (code2, HONOR_NANS (lhs2)))
    4848                 :       54565 :     *inverted_p = true;
    4849                 :      131386 :   else if (code1 == invert_tree_comparison
    4850                 :      131386 :                       (swap_tree_comparison (code2), HONOR_NANS (lhs2)))
    4851                 :             :     {
    4852                 :       11864 :       std::swap (lhs2, rhs2);
    4853                 :       11864 :       *inverted_p = true;
    4854                 :             :     }
    4855                 :             :   else
    4856                 :             :     return false;
    4857                 :             : 
    4858                 :     2597946 :   return ((expressions_equal_p (lhs1, lhs2)
    4859                 :      119568 :            && expressions_equal_p (rhs1, rhs2))
    4860                 :     2627724 :           || (commutative_tree_code (code1)
    4861                 :     1437906 :               && expressions_equal_p (lhs1, rhs2)
    4862                 :        3739 :               && expressions_equal_p (rhs1, lhs2)));
    4863                 :             : }
    4864                 :             : 
    4865                 :             : /* Compare two phi entries for equality, ignoring VN_TOP arguments.  */
    4866                 :             : 
    4867                 :             : static int
    4868                 :    38132573 : vn_phi_eq (const_vn_phi_t const vp1, const_vn_phi_t const vp2)
    4869                 :             : {
    4870                 :    38132573 :   if (vp1->hashcode != vp2->hashcode)
    4871                 :             :     return false;
    4872                 :             : 
    4873                 :    11027428 :   if (vp1->block != vp2->block)
    4874                 :             :     {
    4875                 :     8173326 :       if (EDGE_COUNT (vp1->block->preds) != EDGE_COUNT (vp2->block->preds))
    4876                 :             :         return false;
    4877                 :             : 
    4878                 :    34252862 :       switch (EDGE_COUNT (vp1->block->preds))
    4879                 :             :         {
    4880                 :             :         case 1:
    4881                 :             :           /* Single-arg PHIs are just copies.  */
    4882                 :             :           break;
    4883                 :             : 
    4884                 :     2724442 :         case 2:
    4885                 :     2724442 :           {
    4886                 :             :             /* Make sure both PHIs are classified as CSEable.  */
    4887                 :     2724442 :             if (! vp1->cclhs || ! vp2->cclhs)
    4888                 :             :               return false;
    4889                 :             : 
    4890                 :             :             /* Rule out backedges into the PHI.  */
    4891                 :     2724442 :             gcc_checking_assert
    4892                 :             :               (vp1->block->loop_father->header != vp1->block
    4893                 :             :                && vp2->block->loop_father->header != vp2->block);
    4894                 :             : 
    4895                 :             :             /* If the PHI nodes do not have compatible types
    4896                 :             :                they are not the same.  */
    4897                 :     2724442 :             if (!types_compatible_p (vp1->type, vp2->type))
    4898                 :             :               return false;
    4899                 :             : 
    4900                 :             :             /* If the immediate dominator end in switch stmts multiple
    4901                 :             :                values may end up in the same PHI arg via intermediate
    4902                 :             :                CFG merges.  */
    4903                 :     2717468 :             basic_block idom1
    4904                 :     2717468 :               = get_immediate_dominator (CDI_DOMINATORS, vp1->block);
    4905                 :     2717468 :             basic_block idom2
    4906                 :     2717468 :               = get_immediate_dominator (CDI_DOMINATORS, vp2->block);
    4907                 :     2717468 :             gcc_checking_assert (EDGE_COUNT (idom1->succs) == 2
    4908                 :             :                                  && EDGE_COUNT (idom2->succs) == 2);
    4909                 :             : 
    4910                 :             :             /* Verify the controlling stmt is the same.  */
    4911                 :     5434936 :             gcond *last1 = as_a <gcond *> (*gsi_last_bb (idom1));
    4912                 :     5434936 :             gcond *last2 = as_a <gcond *> (*gsi_last_bb (idom2));
    4913                 :     2717468 :             bool inverted_p;
    4914                 :     2717468 :             if (! cond_stmts_equal_p (last1, vp1->cclhs, vp1->ccrhs,
    4915                 :     2717468 :                                       last2, vp2->cclhs, vp2->ccrhs,
    4916                 :             :                                       &inverted_p))
    4917                 :             :               return false;
    4918                 :             : 
    4919                 :             :             /* Get at true/false controlled edges into the PHI.  */
    4920                 :       90055 :             edge te1, te2, fe1, fe2;
    4921                 :       90055 :             if (! extract_true_false_controlled_edges (idom1, vp1->block,
    4922                 :             :                                                        &te1, &fe1)
    4923                 :       90055 :                 || ! extract_true_false_controlled_edges (idom2, vp2->block,
    4924                 :             :                                                           &te2, &fe2))
    4925                 :       41100 :               return false;
    4926                 :             : 
    4927                 :             :             /* Swap edges if the second condition is the inverted of the
    4928                 :             :                first.  */
    4929                 :       48955 :             if (inverted_p)
    4930                 :        1999 :               std::swap (te2, fe2);
    4931                 :             : 
    4932                 :             :             /* Since we do not know which edge will be executed we have
    4933                 :             :                to be careful when matching VN_TOP.  Be conservative and
    4934                 :             :                only match VN_TOP == VN_TOP for now, we could allow
    4935                 :             :                VN_TOP on the not prevailing PHI though.  See for example
    4936                 :             :                PR102920.  */
    4937                 :       48955 :             if (! expressions_equal_p (vp1->phiargs[te1->dest_idx],
    4938                 :       48955 :                                        vp2->phiargs[te2->dest_idx], false)
    4939                 :       96172 :                 || ! expressions_equal_p (vp1->phiargs[fe1->dest_idx],
    4940                 :       47217 :                                           vp2->phiargs[fe2->dest_idx], false))
    4941                 :        1738 :               return false;
    4942                 :             : 
    4943                 :             :             return true;
    4944                 :             :           }
    4945                 :             : 
    4946                 :             :         default:
    4947                 :             :           return false;
    4948                 :             :         }
    4949                 :             :     }
    4950                 :             : 
    4951                 :             :   /* If the PHI nodes do not have compatible types
    4952                 :             :      they are not the same.  */
    4953                 :     8302986 :   if (!types_compatible_p (vp1->type, vp2->type))
    4954                 :             :     return false;
    4955                 :             : 
    4956                 :             :   /* Any phi in the same block will have it's arguments in the
    4957                 :             :      same edge order, because of how we store phi nodes.  */
    4958                 :     8301966 :   unsigned nargs = EDGE_COUNT (vp1->block->preds);
    4959                 :    19321734 :   for (unsigned i = 0; i < nargs; ++i)
    4960                 :             :     {
    4961                 :    15442023 :       tree phi1op = vp1->phiargs[i];
    4962                 :    15442023 :       tree phi2op = vp2->phiargs[i];
    4963                 :    15442023 :       if (phi1op == phi2op)
    4964                 :    10930059 :         continue;
    4965                 :     4511964 :       if (!expressions_equal_p (phi1op, phi2op, false))
    4966                 :             :         return false;
    4967                 :             :     }
    4968                 :             : 
    4969                 :             :   return true;
    4970                 :             : }
    4971                 :             : 
    4972                 :             : /* Lookup PHI in the current hash table, and return the resulting
    4973                 :             :    value number if it exists in the hash table.  Return NULL_TREE if
    4974                 :             :    it does not exist in the hash table. */
    4975                 :             : 
    4976                 :             : static tree
    4977                 :    25956201 : vn_phi_lookup (gimple *phi, bool backedges_varying_p)
    4978                 :             : {
    4979                 :    25956201 :   vn_phi_s **slot;
    4980                 :    25956201 :   struct vn_phi_s *vp1;
    4981                 :    25956201 :   edge e;
    4982                 :    25956201 :   edge_iterator ei;
    4983                 :             : 
    4984                 :    25956201 :   vp1 = XALLOCAVAR (struct vn_phi_s,
    4985                 :             :                     sizeof (struct vn_phi_s)
    4986                 :             :                     + (gimple_phi_num_args (phi) - 1) * sizeof (tree));
    4987                 :             : 
    4988                 :             :   /* Canonicalize the SSA_NAME's to their value number.  */
    4989                 :    88381721 :   FOR_EACH_EDGE (e, ei, gimple_bb (phi)->preds)
    4990                 :             :     {
    4991                 :    62425520 :       tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
    4992                 :    62425520 :       if (TREE_CODE (def) == SSA_NAME
    4993                 :    52191998 :           && (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK)))
    4994                 :             :         {
    4995                 :    49849242 :           if (!virtual_operand_p (def)
    4996                 :    49849242 :               && ssa_undefined_value_p (def, false))
    4997                 :      131220 :             def = VN_TOP;
    4998                 :             :           else
    4999                 :    49718022 :             def = SSA_VAL (def);
    5000                 :             :         }
    5001                 :    62425520 :       vp1->phiargs[e->dest_idx] = def;
    5002                 :             :     }
    5003                 :    25956201 :   vp1->type = TREE_TYPE (gimple_phi_result (phi));
    5004                 :    25956201 :   vp1->block = gimple_bb (phi);
    5005                 :             :   /* Extract values of the controlling condition.  */
    5006                 :    25956201 :   vp1->cclhs = NULL_TREE;
    5007                 :    25956201 :   vp1->ccrhs = NULL_TREE;
    5008                 :    25956201 :   if (EDGE_COUNT (vp1->block->preds) == 2
    5009                 :    25956201 :       && vp1->block->loop_father->header != vp1->block)
    5010                 :             :     {
    5011                 :     8746787 :       basic_block idom1 = get_immediate_dominator (CDI_DOMINATORS, vp1->block);
    5012                 :     8746787 :       if (EDGE_COUNT (idom1->succs) == 2)
    5013                 :    17334278 :         if (gcond *last1 = safe_dyn_cast <gcond *> (*gsi_last_bb (idom1)))
    5014                 :             :           {
    5015                 :             :             /* ???  We want to use SSA_VAL here.  But possibly not
    5016                 :             :                allow VN_TOP.  */
    5017                 :     8430789 :             vp1->cclhs = vn_valueize (gimple_cond_lhs (last1));
    5018                 :     8430789 :             vp1->ccrhs = vn_valueize (gimple_cond_rhs (last1));
    5019                 :             :           }
    5020                 :             :     }
    5021                 :    25956201 :   vp1->hashcode = vn_phi_compute_hash (vp1);
    5022                 :    25956201 :   slot = valid_info->phis->find_slot_with_hash (vp1, vp1->hashcode, NO_INSERT);
    5023                 :    25956201 :   if (!slot)
    5024                 :             :     return NULL_TREE;
    5025                 :     3926928 :   return (*slot)->result;
    5026                 :             : }
    5027                 :             : 
    5028                 :             : /* Insert PHI into the current hash table with a value number of
    5029                 :             :    RESULT.  */
    5030                 :             : 
    5031                 :             : static vn_phi_t
    5032                 :    21452015 : vn_phi_insert (gimple *phi, tree result, bool backedges_varying_p)
    5033                 :             : {
    5034                 :    21452015 :   vn_phi_s **slot;
    5035                 :    21452015 :   vn_phi_t vp1 = (vn_phi_t) obstack_alloc (&vn_tables_obstack,
    5036                 :             :                                            sizeof (vn_phi_s)
    5037                 :             :                                            + ((gimple_phi_num_args (phi) - 1)
    5038                 :             :                                               * sizeof (tree)));
    5039                 :    21452015 :   edge e;
    5040                 :    21452015 :   edge_iterator ei;
    5041                 :             : 
    5042                 :             :   /* Canonicalize the SSA_NAME's to their value number.  */
    5043                 :    74100124 :   FOR_EACH_EDGE (e, ei, gimple_bb (phi)->preds)
    5044                 :             :     {
    5045                 :    52648109 :       tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
    5046                 :    52648109 :       if (TREE_CODE (def) == SSA_NAME
    5047                 :    43408370 :           && (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK)))
    5048                 :             :         {
    5049                 :    41066005 :           if (!virtual_operand_p (def)
    5050                 :    41066005 :               && ssa_undefined_value_p (def, false))
    5051                 :      105170 :             def = VN_TOP;
    5052                 :             :           else
    5053                 :    40960835 :             def = SSA_VAL (def);
    5054                 :             :         }
    5055                 :    52648109 :       vp1->phiargs[e->dest_idx] = def;
    5056                 :             :     }
    5057                 :    21452015 :   vp1->value_id = VN_INFO (result)->value_id;
    5058                 :    21452015 :   vp1->type = TREE_TYPE (gimple_phi_result (phi));
    5059                 :    21452015 :   vp1->block = gimple_bb (phi);
    5060                 :             :   /* Extract values of the controlling condition.  */
    5061                 :    21452015 :   vp1->cclhs = NULL_TREE;
    5062                 :    21452015 :   vp1->ccrhs = NULL_TREE;
    5063                 :    21452015 :   if (EDGE_COUNT (vp1->block->preds) == 2
    5064                 :    21452015 :       && vp1->block->loop_father->header != vp1->block)
    5065                 :             :     {
    5066                 :     8362176 :       basic_block idom1 = get_immediate_dominator (CDI_DOMINATORS, vp1->block);
    5067                 :     8362176 :       if (EDGE_COUNT (idom1->succs) == 2)
    5068                 :    16570724 :         if (gcond *last1 = safe_dyn_cast <gcond *> (*gsi_last_bb (idom1)))
    5069                 :             :           {
    5070                 :             :             /* ???  We want to use SSA_VAL here.  But possibly not
    5071                 :             :                allow VN_TOP.  */
    5072                 :     8062490 :             vp1->cclhs = vn_valueize (gimple_cond_lhs (last1));
    5073                 :     8062490 :             vp1->ccrhs = vn_valueize (gimple_cond_rhs (last1));
    5074                 :             :           }
    5075                 :             :     }
    5076                 :    21452015 :   vp1->result = result;
    5077                 :    21452015 :   vp1->hashcode = vn_phi_compute_hash (vp1);
    5078                 :             : 
    5079                 :    21452015 :   slot = valid_info->phis->find_slot_with_hash (vp1, vp1->hashcode, INSERT);
    5080                 :    21452015 :   gcc_assert (!*slot);
    5081                 :             : 
    5082                 :    21452015 :   *slot = vp1;
    5083                 :    21452015 :   vp1->next = last_inserted_phi;
    5084                 :    21452015 :   last_inserted_phi = vp1;
    5085                 :    21452015 :   return vp1;
    5086                 :             : }
    5087                 :             : 
    5088                 :             : 
    5089                 :             : /* Return true if BB1 is dominated by BB2 taking into account edges
    5090                 :             :    that are not executable.  When ALLOW_BACK is false consider not
    5091                 :             :    executable backedges as executable.  */
    5092                 :             : 
    5093                 :             : static bool
    5094                 :    63055798 : dominated_by_p_w_unex (basic_block bb1, basic_block bb2, bool allow_back)
    5095                 :             : {
    5096                 :    63055798 :   edge_iterator ei;
    5097                 :    63055798 :   edge e;
    5098                 :             : 
    5099                 :    63055798 :   if (dominated_by_p (CDI_DOMINATORS, bb1, bb2))
    5100                 :             :     return true;
    5101                 :             : 
    5102                 :             :   /* Before iterating we'd like to know if there exists a
    5103                 :             :      (executable) path from bb2 to bb1 at all, if not we can
    5104                 :             :      directly return false.  For now simply iterate once.  */
    5105                 :             : 
    5106                 :             :   /* Iterate to the single executable bb1 predecessor.  */
    5107                 :    20480438 :   if (EDGE_COUNT (bb1->preds) > 1)
    5108                 :             :     {
    5109                 :     2998959 :       edge prede = NULL;
    5110                 :     6466576 :       FOR_EACH_EDGE (e, ei, bb1->preds)
    5111                 :     6056444 :         if ((e->flags & EDGE_EXECUTABLE)
    5112                 :      538818 :             || (!allow_back && (e->flags & EDGE_DFS_BACK)))
    5113                 :             :           {
    5114                 :     5587786 :             if (prede)
    5115                 :             :               {
    5116                 :             :                 prede = NULL;
    5117                 :             :                 break;
    5118                 :             :               }
    5119                 :             :             prede = e;
    5120                 :             :           }
    5121                 :     2998959 :       if (prede)
    5122                 :             :         {
    5123                 :      410132 :           bb1 = prede->src;
    5124                 :             : 
    5125                 :             :           /* Re-do the dominance check with changed bb1.  */
    5126                 :      410132 :           if (dominated_by_p (CDI_DOMINATORS, bb1, bb2))
    5127                 :             :             return true;
    5128                 :             :         }
    5129                 :             :     }
    5130                 :             : 
    5131                 :             :   /* Iterate to the single executable bb2 successor.  */
    5132                 :    20272683 :   if (EDGE_COUNT (bb2->succs) > 1)
    5133                 :             :     {
    5134                 :     5601665 :       edge succe = NULL;
    5135                 :    11336327 :       FOR_EACH_EDGE (e, ei, bb2->succs)
    5136                 :    11203600 :         if ((e->flags & EDGE_EXECUTABLE)
    5137                 :      165749 :             || (!allow_back && (e->flags & EDGE_DFS_BACK)))
    5138                 :             :           {
    5139                 :    11037899 :             if (succe)
    5140                 :             :               {
    5141                 :             :                 succe = NULL;
    5142                 :             :                 break;
    5143                 :             :               }
    5144                 :             :             succe = e;
    5145                 :             :           }
    5146                 :     5601665 :       if (succe)
    5147                 :             :         {
    5148                 :             :           /* Verify the reached block is only reached through succe.
    5149                 :             :              If there is only one edge we can spare us the dominator
    5150                 :             :              check and iterate directly.  */
    5151                 :      100023 :           if (EDGE_COUNT (succe->dest->preds) > 1)
    5152                 :             :             {
    5153                 :       70391 :               FOR_EACH_EDGE (e, ei, succe->dest->preds)
    5154                 :       54199 :                 if (e != succe
    5155                 :       35916 :                     && ((e->flags & EDGE_EXECUTABLE)
    5156                 :       26075 :                         || (!allow_back && (e->flags & EDGE_DFS_BACK))))
    5157                 :             :                   {
    5158                 :             :                     succe = NULL;
    5159                 :             :                     break;
    5160                 :             :                   }
    5161                 :             :             }
    5162                 :      100023 :           if (succe)
    5163                 :             :             {
    5164                 :       90173 :               bb2 = succe->dest;
    5165                 :             : 
    5166                 :             :               /* Re-do the dominance check with changed bb2.  */
    5167                 :       90173 :               if (dominated_by_p (CDI_DOMINATORS, bb1, bb2))
    5168                 :             :                 return true;
    5169                 :             :             }
    5170                 :             :         }
    5171                 :             :     }
    5172                 :             :   /* Iterate to the single successor of bb2 with only a single executable
    5173                 :             :      incoming edge.  */
    5174                 :    14671018 :   else if (EDGE_COUNT (bb2->succs) == 1
    5175                 :    28466372 :            && EDGE_COUNT (single_succ (bb2)->preds) > 1)
    5176                 :             :     {
    5177                 :    13993705 :       edge prede = NULL;
    5178                 :  2899531805 :       FOR_EACH_EDGE (e, ei, single_succ (bb2)->preds)
    5179                 :  2898948995 :         if ((e->flags & EDGE_EXECUTABLE)
    5180                 :  2871625369 :             || (!allow_back && (e->flags & EDGE_DFS_BACK)))
    5181                 :             :           {
    5182                 :    27326984 :             if (prede)
    5183                 :             :               {
    5184                 :             :                 prede = NULL;
    5185                 :             :                 break;
    5186                 :             :               }
    5187                 :             :             prede = e;
    5188                 :             :           }
    5189                 :             :       /* We might actually get to a query with BB2 not visited yet when
    5190                 :             :          we're querying for a predicated value.  */
    5191                 :    13993705 :       if (prede && prede->src == bb2)
    5192                 :             :         {
    5193                 :      491160 :           bb2 = prede->dest;
    5194                 :             : 
    5195                 :             :           /* Re-do the dominance check with changed bb2.  */
    5196                 :      491160 :           if (dominated_by_p (CDI_DOMINATORS, bb1, bb2))
    5197                 :             :             return true;
    5198                 :             :         }
    5199                 :             :     }
    5200                 :             : 
    5201                 :             :   /* We could now iterate updating bb1 / bb2.  */
    5202                 :             :   return false;
    5203                 :             : }
    5204                 :             : 
    5205                 :             : /* Set the value number of FROM to TO, return true if it has changed
    5206                 :             :    as a result.  */
    5207                 :             : 
    5208                 :             : static inline bool
    5209                 :   191893289 : set_ssa_val_to (tree from, tree to)
    5210                 :             : {
    5211                 :   191893289 :   vn_ssa_aux_t from_info = VN_INFO (from);
    5212                 :   191893289 :   tree currval = from_info->valnum; // SSA_VAL (from)
    5213                 :   191893289 :   poly_int64 toff, coff;
    5214                 :   191893289 :   bool curr_undefined = false;
    5215                 :   191893289 :   bool curr_invariant = false;
    5216                 :             : 
    5217                 :             :   /* The only thing we allow as value numbers are ssa_names
    5218                 :             :      and invariants.  So assert that here.  We don't allow VN_TOP
    5219                 :             :      as visiting a stmt should produce a value-number other than
    5220                 :             :      that.
    5221                 :             :      ???  Still VN_TOP can happen for unreachable code, so force
    5222                 :             :      it to varying in that case.  Not all code is prepared to
    5223                 :             :      get VN_TOP on valueization.  */
    5224                 :   191893289 :   if (to == VN_TOP)
    5225                 :             :     {
    5226                 :             :       /* ???  When iterating and visiting PHI <undef, backedge-value>
    5227                 :             :          for the first time we rightfully get VN_TOP and we need to
    5228                 :             :          preserve that to optimize for example gcc.dg/tree-ssa/ssa-sccvn-2.c.
    5229                 :             :          With SCCVN we were simply lucky we iterated the other PHI
    5230                 :             :          cycles first and thus visited the backedge-value DEF.  */
    5231                 :           0 :       if (currval == VN_TOP)
    5232                 :           0 :         goto set_and_exit;
    5233                 :           0 :       if (dump_file && (dump_flags & TDF_DETAILS))
    5234                 :           0 :         fprintf (dump_file, "Forcing value number to varying on "
    5235                 :             :                  "receiving VN_TOP\n");
    5236                 :             :       to = from;
    5237                 :             :     }
    5238                 :             : 
    5239                 :   191893289 :   gcc_checking_assert (to != NULL_TREE
    5240                 :             :                        && ((TREE_CODE (to) == SSA_NAME
    5241                 :             :                             && (to == from || SSA_VAL (to) == to))
    5242                 :             :                            || is_gimple_min_invariant (to)));
    5243                 :             : 
    5244                 :   191893289 :   if (from != to)
    5245                 :             :     {
    5246                 :    30658209 :       if (currval == from)
    5247                 :             :         {
    5248                 :       12084 :           if (dump_file && (dump_flags & TDF_DETAILS))
    5249                 :             :             {
    5250                 :           0 :               fprintf (dump_file, "Not changing value number of ");
    5251                 :           0 :               print_generic_expr (dump_file, from);
    5252                 :           0 :               fprintf (dump_file, " from VARYING to ");
    5253                 :           0 :               print_generic_expr (dump_file, to);
    5254                 :           0 :               fprintf (dump_file, "\n");
    5255                 :             :             }
    5256                 :       12084 :           return false;
    5257                 :             :         }
    5258                 :    30646125 :       curr_invariant = is_gimple_min_invariant (currval);
    5259                 :    61292250 :       curr_undefined = (TREE_CODE (currval) == SSA_NAME
    5260                 :     3706118 :                         && !virtual_operand_p (currval)
    5261                 :    34143322 :                         && ssa_undefined_value_p (currval, false));
    5262                 :    30646125 :       if (currval != VN_TOP
    5263                 :             :           && !curr_invariant
    5264                 :     5081721 :           && !curr_undefined
    5265                 :    34339468 :           && is_gimple_min_invariant (to))
    5266                 :             :         {
    5267                 :         220 :           if (dump_file && (dump_flags & TDF_DETAILS))
    5268                 :             :             {
    5269                 :           0 :               fprintf (dump_file, "Forcing VARYING instead of changing "
    5270                 :             :                        "value number of ");
    5271                 :           0 :               print_generic_expr (dump_file, from);
    5272                 :           0 :               fprintf (dump_file, " from ");
    5273                 :           0 :               print_generic_expr (dump_file, currval);
    5274                 :           0 :               fprintf (dump_file, " (non-constant) to ");
    5275                 :           0 :               print_generic_expr (dump_file, to);
    5276                 :           0 :               fprintf (dump_file, " (constant)\n");
    5277                 :             :             }
    5278                 :             :           to = from;
    5279                 :             :         }
    5280                 :    30645905 :       else if (currval != VN_TOP
    5281                 :     5081501 :                && !curr_undefined
    5282                 :     5068726 :                && TREE_CODE (to) == SSA_NAME
    5283                 :     4322535 :                && !virtual_operand_p (to)
    5284                 :    34759519 :                && ssa_undefined_value_p (to, false))
    5285                 :             :         {
    5286                 :           6 :           if (dump_file && (dump_flags & TDF_DETAILS))
    5287                 :             :             {
    5288                 :           0 :               fprintf (dump_file, "Forcing VARYING instead of changing "
    5289                 :             :                        "value number of ");
    5290                 :           0 :               print_generic_expr (dump_file, from);
    5291                 :           0 :               fprintf (dump_file, " from ");
    5292                 :           0 :               print_generic_expr (dump_file, currval);
    5293                 :           0 :               fprintf (dump_file, " (non-undefined) to ");
    5294                 :           0 :               print_generic_expr (dump_file, to);
    5295                 :           0 :               fprintf (dump_file, " (undefined)\n");
    5296                 :             :             }
    5297                 :             :           to = from;
    5298                 :             :         }
    5299                 :    30645899 :       else if (TREE_CODE (to) == SSA_NAME
    5300                 :    30645899 :                && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (to))
    5301                 :             :         to = from;
    5302                 :             :     }
    5303                 :             : 
    5304                 :   161235080 : set_and_exit:
    5305                 :   191881205 :   if (dump_file && (dump_flags & TDF_DETAILS))
    5306                 :             :     {
    5307                 :      352738 :       fprintf (dump_file, "Setting value number of ");
    5308                 :      352738 :       print_generic_expr (dump_file, from);
    5309                 :      352738 :       fprintf (dump_file, " to ");
    5310                 :      352738 :       print_generic_expr (dump_file, to);
    5311                 :             :     }
    5312                 :             : 
    5313                 :   191881205 :   if (currval != to
    5314                 :   156257301 :       && !operand_equal_p (currval, to, 0)
    5315                 :             :       /* Different undefined SSA names are not actually different.  See
    5316                 :             :          PR82320 for a testcase were we'd otherwise not terminate iteration.  */
    5317                 :   156185999 :       && !(curr_undefined
    5318                 :        3270 :            && TREE_CODE (to) == SSA_NAME
    5319                 :         872 :            && !virtual_operand_p (to)
    5320                 :         872 :            && ssa_undefined_value_p (to, false))
    5321                 :             :       /* ???  For addresses involving volatile objects or types operand_equal_p
    5322                 :             :          does not reliably detect ADDR_EXPRs as equal.  We know we are only
    5323                 :             :          getting invariant gimple addresses here, so can use
    5324                 :             :          get_addr_base_and_unit_offset to do this comparison.  */
    5325                 :   348066300 :       && !(TREE_CODE (currval) == ADDR_EXPR
    5326                 :      418990 :            && TREE_CODE (to) == ADDR_EXPR
    5327                 :          12 :            && (get_addr_base_and_unit_offset (TREE_OPERAND (currval, 0), &coff)
    5328                 :           6 :                == get_addr_base_and_unit_offset (TREE_OPERAND (to, 0), &toff))
    5329                 :           6 :            && known_eq (coff, toff)))
    5330                 :             :     {
    5331                 :   156185089 :       if (to != from
    5332                 :    26497357 :           && currval != VN_TOP
    5333                 :      936380 :           && !curr_undefined
    5334                 :             :           /* We do not want to allow lattice transitions from one value
    5335                 :             :              to another since that may lead to not terminating iteration
    5336                 :             :              (see PR95049).  Since there's no convenient way to check
    5337                 :             :              for the allowed transition of VAL -> PHI (loop entry value,
    5338                 :             :              same on two PHIs, to same PHI result) we restrict the check
    5339                 :             :              to invariants.  */
    5340                 :      936380 :           && curr_invariant
    5341                 :   156814495 :           && is_gimple_min_invariant (to))
    5342                 :             :         {
    5343                 :           0 :           if (dump_file && (dump_flags & TDF_DETAILS))
    5344                 :           0 :             fprintf (dump_file, " forced VARYING");
    5345                 :             :           to = from;
    5346                 :             :         }
    5347                 :   156185089 :       if (dump_file && (dump_flags & TDF_DETAILS))
    5348                 :      352420 :         fprintf (dump_file, " (changed)\n");
    5349                 :   156185089 :       from_info->valnum = to;
    5350                 :   156185089 :       return true;
    5351                 :             :     }
    5352                 :    35696116 :   if (dump_file && (dump_flags & TDF_DETAILS))
    5353                 :         318 :     fprintf (dump_file, "\n");
    5354                 :             :   return false;
    5355                 :             : }
    5356                 :             : 
    5357                 :             : /* Set all definitions in STMT to value number to themselves.
    5358                 :             :    Return true if a value number changed. */
    5359                 :             : 
    5360                 :             : static bool
    5361                 :   239461177 : defs_to_varying (gimple *stmt)
    5362                 :             : {
    5363                 :   239461177 :   bool changed = false;
    5364                 :   239461177 :   ssa_op_iter iter;
    5365                 :   239461177 :   def_operand_p defp;
    5366                 :             : 
    5367                 :   267429282 :   FOR_EACH_SSA_DEF_OPERAND (defp, stmt, iter, SSA_OP_ALL_DEFS)
    5368                 :             :     {
    5369                 :    27968105 :       tree def = DEF_FROM_PTR (defp);
    5370                 :    27968105 :       changed |= set_ssa_val_to (def, def);
    5371                 :             :     }
    5372                 :   239461177 :   return changed;
    5373                 :             : }
    5374                 :             : 
    5375                 :             : /* Visit a copy between LHS and RHS, return true if the value number
    5376                 :             :    changed.  */
    5377                 :             : 
    5378                 :             : static bool
    5379                 :     8063374 : visit_copy (tree lhs, tree rhs)
    5380                 :             : {
    5381                 :             :   /* Valueize.  */
    5382                 :     8063374 :   rhs = SSA_VAL (rhs);
    5383                 :             : 
    5384                 :     8063374 :   return set_ssa_val_to (lhs, rhs);
    5385                 :             : }
    5386                 :             : 
    5387                 :             : /* Lookup a value for OP in type WIDE_TYPE where the value in type of OP
    5388                 :             :    is the same.  */
    5389                 :             : 
    5390                 :             : static tree
    5391                 :     2197360 : valueized_wider_op (tree wide_type, tree op, bool allow_truncate)
    5392                 :             : {
    5393                 :     2197360 :   if (TREE_CODE (op) == SSA_NAME)
    5394                 :     1938264 :     op = vn_valueize (op);
    5395                 :             : 
    5396                 :             :   /* Either we have the op widened available.  */
    5397                 :     2197360 :   tree ops[3] = {};
    5398                 :     2197360 :   ops[0] = op;
    5399                 :     2197360 :   tree tem = vn_nary_op_lookup_pieces (1, NOP_EXPR,
    5400                 :             :                                        wide_type, ops, NULL);
    5401                 :     2197360 :   if (tem)
    5402                 :             :     return tem;
    5403                 :             : 
    5404                 :             :   /* Or the op is truncated from some existing value.  */
    5405                 :     1940663 :   if (allow_truncate && TREE_CODE (op) == SSA_NAME)
    5406                 :             :     {
    5407                 :      445034 :       gimple *def = SSA_NAME_DEF_STMT (op);
    5408                 :      445034 :       if (is_gimple_assign (def)
    5409                 :      445034 :           && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def)))
    5410                 :             :         {
    5411                 :      227911 :           tem = gimple_assign_rhs1 (def);
    5412                 :      227911 :           if (useless_type_conversion_p (wide_type, TREE_TYPE (tem)))
    5413                 :             :             {
    5414                 :      133888 :               if (TREE_CODE (tem) == SSA_NAME)
    5415                 :      133888 :                 tem = vn_valueize (tem);
    5416                 :      133888 :               return tem;
    5417                 :             :             }
    5418                 :             :         }
    5419                 :             :     }
    5420                 :             : 
    5421                 :             :   /* For constants simply extend it.  */
    5422                 :     1806775 :   if (TREE_CODE (op) == INTEGER_CST)
    5423                 :      289771 :     return wide_int_to_tree (wide_type, wi::to_widest (op));
    5424                 :             : 
    5425                 :             :   return NULL_TREE;
    5426                 :             : }
    5427                 :             : 
    5428                 :             : /* Visit a nary operator RHS, value number it, and return true if the
    5429                 :             :    value number of LHS has changed as a result.  */
    5430                 :             : 
    5431                 :             : static bool
    5432                 :    45645291 : visit_nary_op (tree lhs, gassign *stmt)
    5433                 :             : {
    5434                 :    45645291 :   vn_nary_op_t vnresult;
    5435                 :    45645291 :   tree result = vn_nary_op_lookup_stmt (stmt, &vnresult);
    5436                 :    45645291 :   if (! result && vnresult)
    5437                 :      148895 :     result = vn_nary_op_get_predicated_value (vnresult, gimple_bb (stmt));
    5438                 :    42270649 :   if (result)
    5439                 :     3443645 :     return set_ssa_val_to (lhs, result);
    5440                 :             : 
    5441                 :             :   /* Do some special pattern matching for redundancies of operations
    5442                 :             :      in different types.  */
    5443                 :    42201646 :   enum tree_code code = gimple_assign_rhs_code (stmt);
    5444                 :    42201646 :   tree type = TREE_TYPE (lhs);
    5445                 :    42201646 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    5446                 :    42201646 :   switch (code)
    5447                 :             :     {
    5448                 :     9628342 :     CASE_CONVERT:
    5449                 :             :       /* Match arithmetic done in a different type where we can easily
    5450                 :             :          substitute the result from some earlier sign-changed or widened
    5451                 :             :          operation.  */
    5452                 :     9628342 :       if (INTEGRAL_TYPE_P (type)
    5453                 :     8629532 :           && TREE_CODE (rhs1) == SSA_NAME
    5454                 :             :           /* We only handle sign-changes, zero-extension -> & mask or
    5455                 :             :              sign-extension if we know the inner operation doesn't
    5456                 :             :              overflow.  */
    5457                 :    18024856 :           && (((TYPE_UNSIGNED (TREE_TYPE (rhs1))
    5458                 :     5027037 :                 || (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    5459                 :     5025759 :                     && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (rhs1))))
    5460                 :     7669218 :                && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (rhs1)))
    5461                 :     5480582 :               || TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (rhs1))))
    5462                 :             :         {
    5463                 :     7358037 :           gassign *def = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (rhs1));
    5464                 :     5198469 :           if (def
    5465                 :     5198469 :               && (gimple_assign_rhs_code (def) == PLUS_EXPR
    5466                 :     4056164 :                   || gimple_assign_rhs_code (def) == MINUS_EXPR
    5467                 :     3934339 :                   || gimple_assign_rhs_code (def) == MULT_EXPR))
    5468                 :             :             {
    5469                 :     1796337 :               tree ops[3] = {};
    5470                 :             :               /* When requiring a sign-extension we cannot model a
    5471                 :             :                  previous truncation with a single op so don't bother.  */
    5472                 :     1796337 :               bool allow_truncate = TYPE_UNSIGNED (TREE_TYPE (rhs1));
    5473                 :             :               /* Either we have the op widened available.  */
    5474                 :     1796337 :               ops[0] = valueized_wider_op (type, gimple_assign_rhs1 (def),
    5475                 :             :                                            allow_truncate);
    5476                 :     1796337 :               if (ops[0])
    5477                 :      802046 :                 ops[1] = valueized_wider_op (type, gimple_assign_rhs2 (def),
    5478                 :             :                                              allow_truncate);
    5479                 :     1796337 :               if (ops[0] && ops[1])
    5480                 :             :                 {
    5481                 :      279333 :                   ops[0] = vn_nary_op_lookup_pieces
    5482                 :      279333 :                       (2, gimple_assign_rhs_code (def), type, ops, NULL);
    5483                 :             :                   /* We have wider operation available.  */
    5484                 :      279333 :                   if (ops[0]
    5485                 :             :                       /* If the leader is a wrapping operation we can
    5486                 :             :                          insert it for code hoisting w/o introducing
    5487                 :             :                          undefined overflow.  If it is not it has to
    5488                 :             :                          be available.  See PR86554.  */
    5489                 :      279333 :                       && (TYPE_OVERFLOW_WRAPS (TREE_TYPE (ops[0]))
    5490                 :        1841 :                           || (rpo_avail && vn_context_bb
    5491                 :        1841 :                               && rpo_avail->eliminate_avail (vn_context_bb,
    5492                 :             :                                                              ops[0]))))
    5493                 :             :                     {
    5494                 :        8742 :                       unsigned lhs_prec = TYPE_PRECISION (type);
    5495                 :        8742 :                       unsigned rhs_prec = TYPE_PRECISION (TREE_TYPE (rhs1));
    5496                 :        8742 :                       if (lhs_prec == rhs_prec
    5497                 :        8742 :                           || (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    5498                 :        1625 :                               && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (rhs1))))
    5499                 :             :                         {
    5500                 :        8190 :                           gimple_match_op match_op (gimple_match_cond::UNCOND,
    5501                 :        8190 :                                                     NOP_EXPR, type, ops[0]);
    5502                 :        8190 :                           result = vn_nary_build_or_lookup (&match_op);
    5503                 :        8190 :                           if (result)
    5504                 :             :                             {
    5505                 :        8190 :                               bool changed = set_ssa_val_to (lhs, result);
    5506                 :        8190 :                               vn_nary_op_insert_stmt (stmt, result);
    5507                 :        8190 :                               return changed;
    5508                 :             :                             }
    5509                 :             :                         }
    5510                 :             :                       else
    5511                 :             :                         {
    5512                 :         552 :                           tree mask = wide_int_to_tree
    5513                 :         552 :                             (type, wi::mask (rhs_prec, false, lhs_prec));
    5514                 :         552 :                           gimple_match_op match_op (gimple_match_cond::UNCOND,
    5515                 :             :                                                     BIT_AND_EXPR,
    5516                 :         552 :                                                     TREE_TYPE (lhs),
    5517                 :         552 :                                                     ops[0], mask);
    5518                 :         552 :                           result = vn_nary_build_or_lookup (&match_op);
    5519                 :         552 :                           if (result)
    5520                 :             :                             {
    5521                 :         552 :                               bool changed = set_ssa_val_to (lhs, result);
    5522                 :         552 :                               vn_nary_op_insert_stmt (stmt, result);
    5523                 :         552 :                               return changed;
    5524                 :             :                             }
    5525                 :             :                         }
    5526                 :             :                     }
    5527                 :             :                 }
    5528                 :             :             }
    5529                 :             :         }
    5530                 :             :       break;
    5531                 :     1471889 :     case BIT_AND_EXPR:
    5532                 :     1471889 :       if (INTEGRAL_TYPE_P (type)
    5533                 :     1444146 :           && TREE_CODE (rhs1) == SSA_NAME
    5534                 :     1444146 :           && TREE_CODE (gimple_assign_rhs2 (stmt)) == INTEGER_CST
    5535                 :      894163 :           && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1)
    5536                 :      894050 :           && default_vn_walk_kind != VN_NOWALK
    5537                 :             :           && CHAR_BIT == 8
    5538                 :             :           && BITS_PER_UNIT == 8
    5539                 :             :           && BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN
    5540                 :      893846 :           && TYPE_PRECISION (type) <= vn_walk_cb_data::bufsize * BITS_PER_UNIT
    5541                 :      893844 :           && !integer_all_onesp (gimple_assign_rhs2 (stmt))
    5542                 :     2365733 :           && !integer_zerop (gimple_assign_rhs2 (stmt)))
    5543                 :             :         {
    5544                 :      893844 :           gassign *ass = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (rhs1));
    5545                 :      659291 :           if (ass
    5546                 :      659291 :               && !gimple_has_volatile_ops (ass)
    5547                 :      657473 :               && vn_get_stmt_kind (ass) == VN_REFERENCE)
    5548                 :             :             {
    5549                 :      317320 :               tree last_vuse = gimple_vuse (ass);
    5550                 :      317320 :               tree op = gimple_assign_rhs1 (ass);
    5551                 :      951960 :               tree result = vn_reference_lookup (op, gimple_vuse (ass),
    5552                 :             :                                                  default_vn_walk_kind,
    5553                 :             :                                                  NULL, true, &last_vuse,
    5554                 :             :                                                  gimple_assign_rhs2 (stmt));
    5555                 :      317320 :               if (result
    5556                 :      317762 :                   && useless_type_conversion_p (TREE_TYPE (result),
    5557                 :         442 :                                                 TREE_TYPE (op)))
    5558                 :         442 :                 return set_ssa_val_to (lhs, result);
    5559                 :             :             }
    5560                 :             :         }
    5561                 :             :       break;
    5562                 :      320936 :     case TRUNC_DIV_EXPR:
    5563                 :      320936 :       if (TYPE_UNSIGNED (type))
    5564                 :             :         break;
    5565                 :             :       /* Fallthru.  */
    5566                 :     5040483 :     case RDIV_EXPR:
    5567                 :     5040483 :     case MULT_EXPR:
    5568                 :             :       /* Match up ([-]a){/,*}([-])b with v=a{/,*}b, replacing it with -v.  */
    5569                 :     5040483 :       if (! HONOR_SIGN_DEPENDENT_ROUNDING (type))
    5570                 :             :         {
    5571                 :     5039573 :           tree rhs[2];
    5572                 :     5039573 :           rhs[0] = rhs1;
    5573                 :     5039573 :           rhs[1] = gimple_assign_rhs2 (stmt);
    5574                 :    15112285 :           for (unsigned i = 0; i <= 1; ++i)
    5575                 :             :             {
    5576                 :    10078042 :               unsigned j = i == 0 ? 1 : 0;
    5577                 :    10078042 :               tree ops[2];
    5578                 :    10078042 :               gimple_match_op match_op (gimple_match_cond::UNCOND,
    5579                 :    10078042 :                                         NEGATE_EXPR, type, rhs[i]);
    5580                 :    10078042 :               ops[i] = vn_nary_build_or_lookup_1 (&match_op, false, true);
    5581                 :    10078042 :               ops[j] = rhs[j];
    5582                 :    10078042 :               if (ops[i]
    5583                 :    10078042 :                   && (ops[0] = vn_nary_op_lookup_pieces (2, code,
    5584                 :             :                                                          type, ops, NULL)))
    5585                 :             :                 {
    5586                 :        5330 :                   gimple_match_op match_op (gimple_match_cond::UNCOND,
    5587                 :        5330 :                                             NEGATE_EXPR, type, ops[0]);
    5588                 :        5330 :                   result = vn_nary_build_or_lookup_1 (&match_op, true, false);
    5589                 :        5330 :                   if (result)
    5590                 :             :                     {
    5591                 :        5330 :                       bool changed = set_ssa_val_to (lhs, result);
    5592                 :        5330 :                       vn_nary_op_insert_stmt (stmt, result);
    5593                 :        5330 :                       return changed;
    5594                 :             :                     }
    5595                 :             :                 }
    5596                 :             :             }
    5597                 :             :         }
    5598                 :             :       break;
    5599                 :      379184 :     case LSHIFT_EXPR:
    5600                 :             :       /* For X << C, use the value number of X * (1 << C).  */
    5601                 :      379184 :       if (INTEGRAL_TYPE_P (type)
    5602                 :      372049 :           && TYPE_OVERFLOW_WRAPS (type)
    5603                 :      595436 :           && !TYPE_SATURATING (type))
    5604                 :             :         {
    5605                 :      216252 :           tree rhs2 = gimple_assign_rhs2 (stmt);
    5606                 :      216252 :           if (TREE_CODE (rhs2) == INTEGER_CST
    5607                 :      139276 :               && tree_fits_uhwi_p (rhs2)
    5608                 :      355528 :               && tree_to_uhwi (rhs2) < TYPE_PRECISION (type))
    5609                 :             :             {
    5610                 :      139276 :               wide_int w = wi::set_bit_in_zero (tree_to_uhwi (rhs2),
    5611                 :      139276 :                                                 TYPE_PRECISION (type));
    5612                 :      139276 :               gimple_match_op match_op (gimple_match_cond::UNCOND,
    5613                 :             :                                         MULT_EXPR, type, rhs1,
    5614                 :      139276 :                                         wide_int_to_tree (type, w));
    5615                 :      139276 :               result = vn_nary_build_or_lookup (&match_op);
    5616                 :      139276 :               if (result)
    5617                 :             :                 {
    5618                 :      139276 :                   bool changed = set_ssa_val_to (lhs, result);
    5619                 :      139276 :                   if (TREE_CODE (result) == SSA_NAME)
    5620                 :      139275 :                     vn_nary_op_insert_stmt (stmt, result);
    5621                 :      139276 :                   return changed;
    5622                 :             :                 }
    5623                 :      139276 :             }
    5624                 :             :         }
    5625                 :             :       break;
    5626                 :             :     default:
    5627                 :             :       break;
    5628                 :             :     }
    5629                 :             : 
    5630                 :    42047856 :   bool changed = set_ssa_val_to (lhs, lhs);
    5631                 :    42047856 :   vn_nary_op_insert_stmt (stmt, lhs);
    5632                 :    42047856 :   return changed;
    5633                 :             : }
    5634                 :             : 
    5635                 :             : /* Visit a call STMT storing into LHS.  Return true if the value number
    5636                 :             :    of the LHS has changed as a result.  */
    5637                 :             : 
    5638                 :             : static bool
    5639                 :     8173003 : visit_reference_op_call (tree lhs, gcall *stmt)
    5640                 :             : {
    5641                 :     8173003 :   bool changed = false;
    5642                 :     8173003 :   struct vn_reference_s vr1;
    5643                 :     8173003 :   vn_reference_t vnresult = NULL;
    5644                 :     8173003 :   tree vdef = gimple_vdef (stmt);
    5645                 :     8173003 :   modref_summary *summary;
    5646                 :             : 
    5647                 :             :   /* Non-ssa lhs is handled in copy_reference_ops_from_call.  */
    5648                 :     8173003 :   if (lhs && TREE_CODE (lhs) != SSA_NAME)
    5649                 :     4283704 :     lhs = NULL_TREE;
    5650                 :             : 
    5651                 :     8173003 :   vn_reference_lookup_call (stmt, &vnresult, &vr1);
    5652                 :             : 
    5653                 :             :   /* If the lookup did not succeed for pure functions try to use
    5654                 :             :      modref info to find a candidate to CSE to.  */
    5655                 :     8173003 :   const unsigned accesses_limit = 8;
    5656                 :     8173003 :   if (!vnresult
    5657                 :     7607416 :       && !vdef
    5658                 :     7607416 :       && lhs
    5659                 :     2700931 :       && gimple_vuse (stmt)
    5660                 :     9678054 :       && (((summary = get_modref_function_summary (stmt, NULL))
    5661                 :      155841 :            && !summary->global_memory_read
    5662                 :       66178 :            && summary->load_accesses < accesses_limit)
    5663                 :     1438957 :           || gimple_call_flags (stmt) & ECF_CONST))
    5664                 :             :     {
    5665                 :             :       /* First search if we can do someting useful and build a
    5666                 :             :          vector of all loads we have to check.  */
    5667                 :       66813 :       bool unknown_memory_access = false;
    5668                 :       66813 :       auto_vec<ao_ref, accesses_limit> accesses;
    5669                 :       66813 :       unsigned load_accesses = summary ? summary->load_accesses : 0;
    5670                 :       66813 :       if (!unknown_memory_access)
    5671                 :             :         /* Add loads done as part of setting up the call arguments.
    5672                 :             :            That's also necessary for CONST functions which will
    5673                 :             :            not have a modref summary.  */
    5674                 :      197253 :         for (unsigned i = 0; i < gimple_call_num_args (stmt); ++i)
    5675                 :             :           {
    5676                 :      130440 :             tree arg = gimple_call_arg (stmt, i);
    5677                 :      130440 :             if (TREE_CODE (arg) != SSA_NAME
    5678                 :      130440 :                 && !is_gimple_min_invariant (arg))
    5679                 :             :               {
    5680                 :       47846 :                 if (accesses.length () >= accesses_limit - load_accesses)
    5681                 :             :                   {
    5682                 :             :                     unknown_memory_access = true;
    5683                 :             :                     break;
    5684                 :             :                   }
    5685                 :       23923 :                 accesses.quick_grow (accesses.length () + 1);
    5686                 :       23923 :                 ao_ref_init (&accesses.last (), arg);
    5687                 :             :               }
    5688                 :             :           }
    5689                 :       66813 :       if (summary && !unknown_memory_access)
    5690                 :             :         {
    5691                 :             :           /* Add loads as analyzed by IPA modref.  */
    5692                 :      233099 :           for (auto base_node : summary->loads->bases)
    5693                 :       58838 :             if (unknown_memory_access)
    5694                 :             :               break;
    5695                 :      238207 :             else for (auto ref_node : base_node->refs)
    5696                 :       62473 :               if (unknown_memory_access)
    5697                 :             :                 break;
    5698                 :      247859 :               else for (auto access_node : ref_node->accesses)
    5699                 :             :                 {
    5700                 :      157778 :                   accesses.quick_grow (accesses.length () + 1);
    5701                 :       78889 :                   ao_ref *r = &accesses.last ();
    5702                 :       78889 :                   if (!access_node.get_ao_ref (stmt, r))
    5703                 :             :                     {
    5704                 :             :                       /* Initialize a ref based on the argument and
    5705                 :             :                          unknown offset if possible.  */
    5706                 :       18413 :                       tree arg = access_node.get_call_arg (stmt);
    5707                 :       18413 :                       if (arg && TREE_CODE (arg) == SSA_NAME)
    5708                 :        5175 :                         arg = SSA_VAL (arg);
    5709                 :        5175 :                       if (arg
    5710                 :       18403 :                           && TREE_CODE (arg) == ADDR_EXPR
    5711                 :       13375 :                           && (arg = get_base_address (arg))
    5712                 :       18550 :                           && DECL_P (arg))
    5713                 :             :                         {
    5714                 :           0 :                           ao_ref_init (r, arg);
    5715                 :           0 :                           r->ref = NULL_TREE;
    5716                 :           0 :                           r->base = arg;
    5717                 :             :                         }
    5718                 :             :                       else
    5719                 :             :                         {
    5720                 :             :                           unknown_memory_access = true;
    5721                 :             :                           break;
    5722                 :             :                         }
    5723                 :             :                     }
    5724                 :       60476 :                   r->base_alias_set = base_node->base;
    5725                 :       60476 :                   r->ref_alias_set = ref_node->ref;
    5726                 :             :                 }
    5727                 :             :         }
    5728                 :             : 
    5729                 :             :       /* Walk the VUSE->VDEF chain optimistically trying to find an entry
    5730                 :             :          for the call in the hashtable.  */
    5731                 :       66813 :       unsigned limit = (unknown_memory_access
    5732                 :       66813 :                         ? 0
    5733                 :       48400 :                         : (param_sccvn_max_alias_queries_per_access
    5734                 :       48400 :                            / (accesses.length () + 1)));
    5735                 :       66813 :       tree saved_vuse = vr1.vuse;
    5736                 :       66813 :       hashval_t saved_hashcode = vr1.hashcode;
    5737                 :      299287 :       while (limit > 0 && !vnresult && !SSA_NAME_IS_DEFAULT_DEF (vr1.vuse))
    5738                 :             :         {
    5739                 :      246232 :           vr1.hashcode = vr1.hashcode - SSA_NAME_VERSION (vr1.vuse);
    5740                 :      246232 :           gimple *def = SSA_NAME_DEF_STMT (vr1.vuse);
    5741                 :             :           /* ???  We could use fancy stuff like in walk_non_aliased_vuses, but
    5742                 :             :              do not bother for now.  */
    5743                 :      246232 :           if (is_a <gphi *> (def))
    5744                 :             :             break;
    5745                 :      464948 :           vr1.vuse = vuse_ssa_val (gimple_vuse (def));
    5746                 :      232474 :           vr1.hashcode = vr1.hashcode + SSA_NAME_VERSION (vr1.vuse);
    5747                 :      232474 :           vn_reference_lookup_1 (&vr1, &vnresult);
    5748                 :      232474 :           limit--;
    5749                 :             :         }
    5750                 :             : 
    5751                 :             :       /* If we found a candidate to CSE to verify it is valid.  */
    5752                 :       66813 :       if (vnresult && !accesses.is_empty ())
    5753                 :             :         {
    5754                 :        1659 :           tree vuse = vuse_ssa_val (gimple_vuse (stmt));
    5755                 :        6210 :           while (vnresult && vuse != vr1.vuse)
    5756                 :             :             {
    5757                 :        2892 :               gimple *def = SSA_NAME_DEF_STMT (vuse);
    5758                 :       15079 :               for (auto &ref : accesses)
    5759                 :             :                 {
    5760                 :             :                   /* ???  stmt_may_clobber_ref_p_1 does per stmt constant
    5761                 :             :                      analysis overhead that we might be able to cache.  */
    5762                 :        7996 :                   if (stmt_may_clobber_ref_p_1 (def, &ref, true))
    5763                 :             :                     {
    5764                 :        1593 :                       vnresult = NULL;
    5765                 :        1593 :                       break;
    5766                 :             :                     }
    5767                 :             :                 }
    5768                 :        5784 :               vuse = vuse_ssa_val (gimple_vuse (def));
    5769                 :             :             }
    5770                 :             :         }
    5771                 :       66813 :       vr1.vuse = saved_vuse;
    5772                 :       66813 :       vr1.hashcode = saved_hashcode;
    5773                 :       66813 :     }
    5774                 :             : 
    5775                 :     8173003 :   if (vnresult)
    5776                 :             :     {
    5777                 :      565679 :       if (vdef)
    5778                 :             :         {
    5779                 :      176482 :           if (vnresult->result_vdef)
    5780                 :      176482 :             changed |= set_ssa_val_to (vdef, vnresult->result_vdef);
    5781                 :           0 :           else if (!lhs && gimple_call_lhs (stmt))
    5782                 :             :             /* If stmt has non-SSA_NAME lhs, value number the vdef to itself,
    5783                 :             :                as the call still acts as a lhs store.  */
    5784                 :           0 :             changed |= set_ssa_val_to (vdef, vdef);
    5785                 :             :           else
    5786                 :             :             /* If the call was discovered to be pure or const reflect
    5787                 :             :                that as far as possible.  */
    5788                 :           0 :             changed |= set_ssa_val_to (vdef,
    5789                 :             :                                        vuse_ssa_val (gimple_vuse (stmt)));
    5790                 :             :         }
    5791                 :             : 
    5792                 :      565679 :       if (!vnresult->result && lhs)
    5793                 :           0 :         vnresult->result = lhs;
    5794                 :             : 
    5795                 :      565679 :       if (vnresult->result && lhs)
    5796                 :       90561 :         changed |= set_ssa_val_to (lhs, vnresult->result);
    5797                 :             :     }
    5798                 :             :   else
    5799                 :             :     {
    5800                 :     7607324 :       vn_reference_t vr2;
    5801                 :     7607324 :       vn_reference_s **slot;
    5802                 :     7607324 :       tree vdef_val = vdef;
    5803                 :     7607324 :       if (vdef)
    5804                 :             :         {
    5805                 :             :           /* If we value numbered an indirect functions function to
    5806                 :             :              one not clobbering memory value number its VDEF to its
    5807                 :             :              VUSE.  */
    5808                 :     4616394 :           tree fn = gimple_call_fn (stmt);
    5809                 :     4616394 :           if (fn && TREE_CODE (fn) == SSA_NAME)
    5810                 :             :             {
    5811                 :      126759 :               fn = SSA_VAL (fn);
    5812                 :      126759 :               if (TREE_CODE (fn) == ADDR_EXPR
    5813                 :        1400 :                   && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
    5814                 :        1400 :                   && (flags_from_decl_or_type (TREE_OPERAND (fn, 0))
    5815                 :        1400 :                       & (ECF_CONST | ECF_PURE))
    5816                 :             :                   /* If stmt has non-SSA_NAME lhs, value number the
    5817                 :             :                      vdef to itself, as the call still acts as a lhs
    5818                 :             :                      store.  */
    5819                 :      127587 :                   && (lhs || gimple_call_lhs (stmt) == NULL_TREE))
    5820                 :        1530 :                 vdef_val = vuse_ssa_val (gimple_vuse (stmt));
    5821                 :             :             }
    5822                 :     4616394 :           changed |= set_ssa_val_to (vdef, vdef_val);
    5823                 :             :         }
    5824                 :     7607324 :       if (lhs)
    5825                 :     3798738 :         changed |= set_ssa_val_to (lhs, lhs);
    5826                 :     7607324 :       vr2 = XOBNEW (&vn_tables_obstack, vn_reference_s);
    5827                 :     7607324 :       vr2->vuse = vr1.vuse;
    5828                 :             :       /* As we are not walking the virtual operand chain we know the
    5829                 :             :          shared_lookup_references are still original so we can re-use
    5830                 :             :          them here.  */
    5831                 :     7607324 :       vr2->operands = vr1.operands.copy ();
    5832                 :     7607324 :       vr2->type = vr1.type;
    5833                 :     7607324 :       vr2->punned = vr1.punned;
    5834                 :     7607324 :       vr2->set = vr1.set;
    5835                 :     7607324 :       vr2->offset = vr1.offset;
    5836                 :     7607324 :       vr2->max_size = vr1.max_size;
    5837                 :     7607324 :       vr2->base_set = vr1.base_set;
    5838                 :     7607324 :       vr2->hashcode = vr1.hashcode;
    5839                 :     7607324 :       vr2->result = lhs;
    5840                 :     7607324 :       vr2->result_vdef = vdef_val;
    5841                 :     7607324 :       vr2->value_id = 0;
    5842                 :     7607324 :       slot = valid_info->references->find_slot_with_hash (vr2, vr2->hashcode,
    5843                 :             :                                                           INSERT);
    5844                 :     7607324 :       gcc_assert (!*slot);
    5845                 :     7607324 :       *slot = vr2;
    5846                 :     7607324 :       vr2->next = last_inserted_ref;
    5847                 :     7607324 :       last_inserted_ref = vr2;
    5848                 :             :     }
    5849                 :             : 
    5850                 :     8173003 :   return changed;
    5851                 :             : }
    5852                 :             : 
    5853                 :             : /* Visit a load from a reference operator RHS, part of STMT, value number it,
    5854                 :             :    and return true if the value number of the LHS has changed as a result.  */
    5855                 :             : 
    5856                 :             : static bool
    5857                 :    32150461 : visit_reference_op_load (tree lhs, tree op, gimple *stmt)
    5858                 :             : {
    5859                 :    32150461 :   bool changed = false;
    5860                 :    32150461 :   tree result;
    5861                 :    32150461 :   vn_reference_t res;
    5862                 :             : 
    5863                 :    32150461 :   tree vuse = gimple_vuse (stmt);
    5864                 :    32150461 :   tree last_vuse = vuse;
    5865                 :    32150461 :   result = vn_reference_lookup (op, vuse, default_vn_walk_kind, &res, true, &last_vuse);
    5866                 :             : 
    5867                 :             :   /* We handle type-punning through unions by value-numbering based
    5868                 :             :      on offset and size of the access.  Be prepared to handle a
    5869                 :             :      type-mismatch here via creating a VIEW_CONVERT_EXPR.  */
    5870                 :    32150461 :   if (result
    5871                 :    32150461 :       && !useless_type_conversion_p (TREE_TYPE (result), TREE_TYPE (op)))
    5872                 :             :     {
    5873                 :       16804 :       if (CONSTANT_CLASS_P (result))
    5874                 :        2560 :         result = const_unop (VIEW_CONVERT_EXPR, TREE_TYPE (op), result);
    5875                 :             :       else
    5876                 :             :         {
    5877                 :             :           /* We will be setting the value number of lhs to the value number
    5878                 :             :              of VIEW_CONVERT_EXPR <TREE_TYPE (result)> (result).
    5879                 :             :              So first simplify and lookup this expression to see if it
    5880                 :             :              is already available.  */
    5881                 :       14244 :           gimple_match_op res_op (gimple_match_cond::UNCOND,
    5882                 :       14244 :                                   VIEW_CONVERT_EXPR, TREE_TYPE (op), result);
    5883                 :       14244 :           result = vn_nary_build_or_lookup (&res_op);
    5884                 :       14244 :           if (result
    5885                 :       14244 :               && TREE_CODE (result) == SSA_NAME
    5886                 :       26931 :               && VN_INFO (result)->needs_insertion)
    5887                 :             :             /* Track whether this is the canonical expression for different
    5888                 :             :                typed loads.  We use that as a stopgap measure for code
    5889                 :             :                hoisting when dealing with floating point loads.  */
    5890                 :       11906 :             res->punned = true;
    5891                 :             :         }
    5892                 :             : 
    5893                 :             :       /* When building the conversion fails avoid inserting the reference
    5894                 :             :          again.  */
    5895                 :       16804 :       if (!result)
    5896                 :           0 :         return set_ssa_val_to (lhs, lhs);
    5897                 :             :     }
    5898                 :             : 
    5899                 :    32133657 :   if (result)
    5900                 :     4794248 :     changed = set_ssa_val_to (lhs, result);
    5901                 :             :   else
    5902                 :             :     {
    5903                 :    27356213 :       changed = set_ssa_val_to (lhs, lhs);
    5904                 :    27356213 :       vn_reference_insert (op, lhs, last_vuse, NULL_TREE);
    5905                 :    27356213 :       if (vuse && SSA_VAL (last_vuse) != SSA_VAL (vuse))
    5906                 :             :         {
    5907                 :     8084150 :           if (dump_file && (dump_flags & TDF_DETAILS))
    5908                 :             :             {
    5909                 :       12927 :               fprintf (dump_file, "Using extra use virtual operand ");
    5910                 :       12927 :               print_generic_expr (dump_file, last_vuse);
    5911                 :       12927 :               fprintf (dump_file, "\n");
    5912                 :             :             }
    5913                 :     8084150 :           vn_reference_insert (op, lhs, vuse, NULL_TREE);
    5914                 :             :         }
    5915                 :             :     }
    5916                 :             : 
    5917                 :             :   return changed;
    5918                 :             : }
    5919                 :             : 
    5920                 :             : 
    5921                 :             : /* Visit a store to a reference operator LHS, part of STMT, value number it,
    5922                 :             :    and return true if the value number of the LHS has changed as a result.  */
    5923                 :             : 
    5924                 :             : static bool
    5925                 :    29909598 : visit_reference_op_store (tree lhs, tree op, gimple *stmt)
    5926                 :             : {
    5927                 :    29909598 :   bool changed = false;
    5928                 :    29909598 :   vn_reference_t vnresult = NULL;
    5929                 :    29909598 :   tree assign;
    5930                 :    29909598 :   bool resultsame = false;
    5931                 :    29909598 :   tree vuse = gimple_vuse (stmt);
    5932                 :    29909598 :   tree vdef = gimple_vdef (stmt);
    5933                 :             : 
    5934                 :    29909598 :   if (TREE_CODE (op) == SSA_NAME)
    5935                 :    13542469 :     op = SSA_VAL (op);
    5936                 :             : 
    5937                 :             :   /* First we want to lookup using the *vuses* from the store and see
    5938                 :             :      if there the last store to this location with the same address
    5939                 :             :      had the same value.
    5940                 :             : 
    5941                 :             :      The vuses represent the memory state before the store.  If the
    5942                 :             :      memory state, address, and value of the store is the same as the
    5943                 :             :      last store to this location, then this store will produce the
    5944                 :             :      same memory state as that store.
    5945                 :             : 
    5946                 :             :      In this case the vdef versions for this store are value numbered to those
    5947                 :             :      vuse versions, since they represent the same memory state after
    5948                 :             :      this store.
    5949                 :             : 
    5950                 :             :      Otherwise, the vdefs for the store are used when inserting into
    5951                 :             :      the table, since the store generates a new memory state.  */
    5952                 :             : 
    5953                 :    29909598 :   vn_reference_lookup (lhs, vuse, VN_NOWALK, &vnresult, false);
    5954                 :    29909598 :   if (vnresult
    5955                 :     1534024 :       && vnresult->result)
    5956                 :             :     {
    5957                 :     1534024 :       tree result = vnresult->result;
    5958                 :     1534024 :       gcc_checking_assert (TREE_CODE (result) != SSA_NAME
    5959                 :             :                            || result == SSA_VAL (result));
    5960                 :     1534024 :       resultsame = expressions_equal_p (result, op);
    5961                 :     1534024 :       if (resultsame)
    5962                 :             :         {
    5963                 :             :           /* If the TBAA state isn't compatible for downstream reads
    5964                 :             :              we cannot value-number the VDEFs the same.  */
    5965                 :       52373 :           ao_ref lhs_ref;
    5966                 :       52373 :           ao_ref_init (&lhs_ref, lhs);
    5967                 :       52373 :           alias_set_type set = ao_ref_alias_set (&lhs_ref);
    5968                 :       52373 :           alias_set_type base_set = ao_ref_base_alias_set (&lhs_ref);
    5969                 :       52373 :           if ((vnresult->set != set
    5970                 :        2241 :                && ! alias_set_subset_of (set, vnresult->set))
    5971                 :       54242 :               || (vnresult->base_set != base_set
    5972                 :        5936 :                   && ! alias_set_subset_of (base_set, vnresult->base_set)))
    5973                 :         620 :             resultsame = false;
    5974                 :             :         }
    5975                 :             :     }
    5976                 :             : 
    5977                 :         620 :   if (!resultsame)
    5978                 :             :     {
    5979                 :    29857845 :       if (dump_file && (dump_flags & TDF_DETAILS))
    5980                 :             :         {
    5981                 :       18425 :           fprintf (dump_file, "No store match\n");
    5982                 :       18425 :           fprintf (dump_file, "Value numbering store ");
    5983                 :       18425 :           print_generic_expr (dump_file, lhs);
    5984                 :       18425 :           fprintf (dump_file, " to ");
    5985                 :       18425 :           print_generic_expr (dump_file, op);
    5986                 :       18425 :           fprintf (dump_file, "\n");
    5987                 :             :         }
    5988                 :             :       /* Have to set value numbers before insert, since insert is
    5989                 :             :          going to valueize the references in-place.  */
    5990                 :    29857845 :       if (vdef)
    5991                 :    29857845 :         changed |= set_ssa_val_to (vdef, vdef);
    5992                 :             : 
    5993                 :             :       /* Do not insert structure copies into the tables.  */
    5994                 :    29857845 :       if (is_gimple_min_invariant (op)
    5995                 :    29857845 :           || is_gimple_reg (op))
    5996                 :    26617438 :         vn_reference_insert (lhs, op, vdef, NULL);
    5997                 :             : 
    5998                 :             :       /* Only perform the following when being called from PRE
    5999                 :             :          which embeds tail merging.  */
    6000                 :    29857845 :       if (default_vn_walk_kind == VN_WALK)
    6001                 :             :         {
    6002                 :     7016032 :           assign = build2 (MODIFY_EXPR, TREE_TYPE (lhs), lhs, op);
    6003                 :     7016032 :           vn_reference_lookup (assign, vuse, VN_NOWALK, &vnresult, false);
    6004                 :     7016032 :           if (!vnresult)
    6005                 :     6976214 :             vn_reference_insert (assign, lhs, vuse, vdef);
    6006                 :             :         }
    6007                 :             :     }
    6008                 :             :   else
    6009                 :             :     {
    6010                 :             :       /* We had a match, so value number the vdef to have the value
    6011                 :             :          number of the vuse it came from.  */
    6012                 :             : 
    6013                 :       51753 :       if (dump_file && (dump_flags & TDF_DETAILS))
    6014                 :           9 :         fprintf (dump_file, "Store matched earlier value, "
    6015                 :             :                  "value numbering store vdefs to matching vuses.\n");
    6016                 :             : 
    6017                 :       51753 :       changed |= set_ssa_val_to (vdef, SSA_VAL (vuse));
    6018                 :             :     }
    6019                 :             : 
    6020                 :    29909598 :   return changed;
    6021                 :             : }
    6022                 :             : 
    6023                 :             : /* Visit and value number PHI, return true if the value number
    6024                 :             :    changed.  When BACKEDGES_VARYING_P is true then assume all
    6025                 :             :    backedge values are varying.  When INSERTED is not NULL then
    6026                 :             :    this is just a ahead query for a possible iteration, set INSERTED
    6027                 :             :    to true if we'd insert into the hashtable.  */
    6028                 :             : 
    6029                 :             : static bool
    6030                 :    32453227 : visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
    6031                 :             : {
    6032                 :    32453227 :   tree result, sameval = VN_TOP, seen_undef = NULL_TREE;
    6033                 :    32453227 :   bool seen_undef_visited = false;
    6034                 :    32453227 :   tree backedge_val = NULL_TREE;
    6035                 :    32453227 :   bool seen_non_backedge = false;
    6036                 :    32453227 :   tree sameval_base = NULL_TREE;
    6037                 :    32453227 :   poly_int64 soff, doff;
    6038                 :    32453227 :   unsigned n_executable = 0;
    6039                 :    32453227 :   edge sameval_e = NULL;
    6040                 :             : 
    6041                 :             :   /* TODO: We could check for this in initialization, and replace this
    6042                 :             :      with a gcc_assert.  */
    6043                 :    32453227 :   if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (PHI_RESULT (phi)))
    6044                 :       27637 :     return set_ssa_val_to (PHI_RESULT (phi), PHI_RESULT (phi));
    6045                 :             : 
    6046                 :             :   /* We track whether a PHI was CSEd to avoid excessive iterations
    6047                 :             :      that would be necessary only because the PHI changed arguments
    6048                 :             :      but not value.  */
    6049                 :    32425590 :   if (!inserted)
    6050                 :    25387544 :     gimple_set_plf (phi, GF_PLF_1, false);
    6051                 :             : 
    6052                 :    32425590 :   basic_block bb = gimple_bb (phi);
    6053                 :             : 
    6054                 :             :   /* For the equivalence handling below make sure to first process an
    6055                 :             :      edge with a non-constant.  */
    6056                 :    32425590 :   auto_vec<edge, 2> preds;
    6057                 :    64851180 :   preds.reserve_exact (EDGE_COUNT (bb->preds));
    6058                 :    32425590 :   bool seen_nonconstant = false;
    6059                 :   105873205 :   for (unsigned i = 0; i < EDGE_COUNT (bb->preds); ++i)
    6060                 :             :     {
    6061                 :    73447615 :       edge e = EDGE_PRED (bb, i);
    6062                 :    73447615 :       preds.quick_push (e);
    6063                 :    73447615 :       if (!seen_nonconstant)
    6064                 :             :         {
    6065                 :    39449455 :           tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
    6066                 :    39449455 :           if (TREE_CODE (def) == SSA_NAME)
    6067                 :             :             {
    6068                 :    30794384 :               seen_nonconstant = true;
    6069                 :    30794384 :               if (i != 0)
    6070                 :     5346798 :                 std::swap (preds[0], preds[i]);
    6071                 :             :             }
    6072                 :             :         }
    6073                 :             :     }
    6074                 :             : 
    6075                 :             :   /* See if all non-TOP arguments have the same value.  TOP is
    6076                 :             :      equivalent to everything, so we can ignore it.  */
    6077                 :   136295781 :   for (edge e : preds)
    6078                 :    64263253 :     if (e->flags & EDGE_EXECUTABLE)
    6079                 :             :       {
    6080                 :    59640488 :         tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
    6081                 :             : 
    6082                 :    59640488 :         if (def == PHI_RESULT (phi))
    6083                 :      318971 :           continue;
    6084                 :    59340904 :         ++n_executable;
    6085                 :    59340904 :         bool visited = true;
    6086                 :    59340904 :         if (TREE_CODE (def) == SSA_NAME)
    6087                 :             :           {
    6088                 :    47993207 :             tree val = SSA_VAL (def, &visited);
    6089                 :    47993207 :             if (SSA_NAME_IS_DEFAULT_DEF (def))
    6090                 :     2476533 :               visited = true;
    6091                 :    47993207 :             if (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK))
    6092                 :    45655036 :               def = val;
    6093                 :    47993207 :             if (e->flags & EDGE_DFS_BACK)
    6094                 :    14293758 :               backedge_val = def;
    6095                 :             :           }
    6096                 :    59340904 :         if (!(e->flags & EDGE_DFS_BACK))
    6097                 :    44868445 :           seen_non_backedge = true;
    6098                 :    59340904 :         if (def == VN_TOP)
    6099                 :             :           ;
    6100                 :             :         /* Ignore undefined defs for sameval but record one.  */
    6101                 :    59340904 :         else if (TREE_CODE (def) == SSA_NAME
    6102                 :    44852898 :                  && ! virtual_operand_p (def)
    6103                 :    81957583 :                  && ssa_undefined_value_p (def, false))
    6104                 :             :           {
    6105                 :      227488 :             if (!seen_undef
    6106                 :             :                 /* Avoid having not visited undefined defs if we also have
    6107                 :             :                    a visited one.  */
    6108                 :       31299 :                 || (!seen_undef_visited && visited))
    6109                 :             :               {
    6110                 :      196192 :                 seen_undef = def;
    6111                 :      196192 :                 seen_undef_visited = visited;
    6112                 :             :               }
    6113                 :             :           }
    6114                 :    59113416 :         else if (sameval == VN_TOP)
    6115                 :             :           {
    6116                 :             :             sameval = def;
    6117                 :             :             sameval_e = e;
    6118                 :             :           }
    6119                 :    26739707 :         else if (expressions_equal_p (def, sameval))
    6120                 :             :           sameval_e = NULL;
    6121                 :    42285283 :         else if (virtual_operand_p (def))
    6122                 :             :           {
    6123                 :             :             sameval = NULL_TREE;
    6124                 :    25244242 :             break;
    6125                 :             :           }
    6126                 :             :         else
    6127                 :             :           {
    6128                 :             :             /* We know we're arriving only with invariant addresses here,
    6129                 :             :                try harder comparing them.  We can do some caching here
    6130                 :             :                which we cannot do in expressions_equal_p.  */
    6131                 :    15624897 :             if (TREE_CODE (def) == ADDR_EXPR
    6132                 :      360547 :                 && TREE_CODE (sameval) == ADDR_EXPR
    6133                 :       99116 :                 && sameval_base != (void *)-1)
    6134                 :             :               {
    6135                 :       99116 :                 if (!sameval_base)
    6136                 :       99114 :                   sameval_base = get_addr_base_and_unit_offset
    6137                 :       99114 :                                    (TREE_OPERAND (sameval, 0), &soff);
    6138                 :       99114 :                 if (!sameval_base)
    6139                 :             :                   sameval_base = (tree)(void *)-1;
    6140                 :       99121 :                 else if ((get_addr_base_and_unit_offset
    6141                 :       99116 :                             (TREE_OPERAND (def, 0), &doff) == sameval_base)
    6142                 :       99116 :                          && known_eq (soff, doff))
    6143                 :           5 :                   continue;
    6144                 :             :               }
    6145                 :             :             /* There's also the possibility to use equivalences.  */
    6146                 :    30150213 :             if (!FLOAT_TYPE_P (TREE_TYPE (def))
    6147                 :             :                 /* But only do this if we didn't force any of sameval or
    6148                 :             :                    val to VARYING because of backedge processing rules.  */
    6149                 :    14426777 :                 && (TREE_CODE (sameval) != SSA_NAME
    6150                 :    11355283 :                     || SSA_VAL (sameval) == sameval)
    6151                 :    30051474 :                 && (TREE_CODE (def) != SSA_NAME || SSA_VAL (def) == def))
    6152                 :             :               {
    6153                 :    14426574 :                 vn_nary_op_t vnresult;
    6154                 :    14426574 :                 tree ops[2];
    6155                 :    14426574 :                 ops[0] = def;
    6156                 :    14426574 :                 ops[1] = sameval;
    6157                 :             :                 /* Canonicalize the operands order for eq below. */
    6158                 :    14426574 :                 if (tree_swap_operands_p (ops[0], ops[1]))
    6159                 :     8500929 :                   std::swap (ops[0], ops[1]);
    6160                 :    14426574 :                 tree val = vn_nary_op_lookup_pieces (2, EQ_EXPR,
    6161                 :             :                                                      boolean_type_node,
    6162                 :             :                                                      ops, &vnresult);
    6163                 :    14426574 :                 if (! val && vnresult && vnresult->predicated_values)
    6164                 :             :                   {
    6165                 :      188103 :                     val = vn_nary_op_get_predicated_value (vnresult, e);
    6166                 :      104081 :                     if (val && integer_truep (val)
    6167                 :      207583 :                         && !(sameval_e && (sameval_e->flags & EDGE_DFS_BACK)))
    6168                 :             :                       {
    6169                 :       19382 :                         if (dump_file && (dump_flags & TDF_DETAILS))
    6170                 :             :                           {
    6171                 :           2 :                             fprintf (dump_file, "Predication says ");
    6172                 :           2 :                             print_generic_expr (dump_file, def, TDF_NONE);
    6173                 :           2 :                             fprintf (dump_file, " and ");
    6174                 :           2 :                             print_generic_expr (dump_file, sameval, TDF_NONE);
    6175                 :           2 :                             fprintf (dump_file, " are equal on edge %d -> %d\n",
    6176                 :           2 :                                      e->src->index, e->dest->index);
    6177                 :             :                           }
    6178                 :       19382 :                         continue;
    6179                 :             :                       }
    6180                 :             :                   }
    6181                 :             :               }
    6182                 :             :             sameval = NULL_TREE;
    6183                 :             :             break;
    6184                 :             :           }
    6185                 :             :       }
    6186                 :             : 
    6187                 :             :   /* If the value we want to use is flowing over the backedge and we
    6188                 :             :      should take it as VARYING but it has a non-VARYING value drop to
    6189                 :             :      VARYING.
    6190                 :             :      If we value-number a virtual operand never value-number to the
    6191                 :             :      value from the backedge as that confuses the alias-walking code.
    6192                 :             :      See gcc.dg/torture/pr87176.c.  If the value is the same on a
    6193                 :             :      non-backedge everything is OK though.  */
    6194                 :    32425590 :   bool visited_p;
    6195                 :    32425590 :   if ((backedge_val
    6196                 :    32425590 :        && !seen_non_backedge
    6197                 :        1818 :        && TREE_CODE (backedge_val) == SSA_NAME
    6198                 :        1551 :        && sameval == backedge_val
    6199                 :         356 :        && (SSA_NAME_IS_VIRTUAL_OPERAND (backedge_val)
    6200                 :          57 :            || SSA_VAL (backedge_val) != backedge_val))
    6201                 :             :       /* Do not value-number a virtual operand to sth not visited though
    6202                 :             :          given that allows us to escape a region in alias walking.  */
    6203                 :    32427108 :       || (sameval
    6204                 :     7181048 :           && TREE_CODE (sameval) == SSA_NAME
    6205                 :     4288431 :           && !SSA_NAME_IS_DEFAULT_DEF (sameval)
    6206                 :     3618598 :           && SSA_NAME_IS_VIRTUAL_OPERAND (sameval)
    6207                 :     1836382 :           && (SSA_VAL (sameval, &visited_p), !visited_p)))
    6208                 :             :     /* Note this just drops to VARYING without inserting the PHI into
    6209                 :             :        the hashes.  */
    6210                 :      262065 :     result = PHI_RESULT (phi);
    6211                 :             :   /* If none of the edges was executable keep the value-number at VN_TOP,
    6212                 :             :      if only a single edge is exectuable use its value.  */
    6213                 :    32163525 :   else if (n_executable <= 1)
    6214                 :     6201968 :     result = seen_undef ? seen_undef : sameval;
    6215                 :             :   /* If we saw only undefined values and VN_TOP use one of the
    6216                 :             :      undefined values.  */
    6217                 :    25961557 :   else if (sameval == VN_TOP)
    6218                 :        5356 :     result = (seen_undef && seen_undef_visited) ? seen_undef : sameval;
    6219                 :             :   /* First see if it is equivalent to a phi node in this block.  We prefer
    6220                 :             :      this as it allows IV elimination - see PRs 66502 and 67167.  */
    6221                 :    25956201 :   else if ((result = vn_phi_lookup (phi, backedges_varying_p)))
    6222                 :             :     {
    6223                 :     3926928 :       if (!inserted
    6224                 :       70277 :           && TREE_CODE (result) == SSA_NAME
    6225                 :     3997205 :           && gimple_code (SSA_NAME_DEF_STMT (result)) == GIMPLE_PHI)
    6226                 :             :         {
    6227                 :       70277 :           gimple_set_plf (SSA_NAME_DEF_STMT (result), GF_PLF_1, true);
    6228                 :       70277 :           if (dump_file && (dump_flags & TDF_DETAILS))
    6229                 :             :             {
    6230                 :           2 :               fprintf (dump_file, "Marking CSEd to PHI node ");
    6231                 :           2 :               print_gimple_expr (dump_file, SSA_NAME_DEF_STMT (result),
    6232                 :             :                                  0, TDF_SLIM);
    6233                 :           2 :               fprintf (dump_file, "\n");
    6234                 :             :             }
    6235                 :             :         }
    6236                 :             :     }
    6237                 :             :   /* If all values are the same use that, unless we've seen undefined
    6238                 :             :      values as well and the value isn't constant.
    6239                 :             :      CCP/copyprop have the same restriction to not remove uninit warnings.  */
    6240                 :    22029273 :   else if (sameval
    6241                 :    22029273 :            && (! seen_undef || is_gimple_min_invariant (sameval)))
    6242                 :             :     result = sameval;
    6243                 :             :   else
    6244                 :             :     {
    6245                 :    21452015 :       result = PHI_RESULT (phi);
    6246                 :             :       /* Only insert PHIs that are varying, for constant value numbers
    6247                 :             :          we mess up equivalences otherwise as we are only comparing
    6248                 :             :          the immediate controlling predicates.  */
    6249                 :    21452015 :       vn_phi_insert (phi, result, backedges_varying_p);
    6250                 :    21452015 :       if (inserted)
    6251                 :     3048285 :         *inserted = true;
    6252                 :             :     }
    6253                 :             : 
    6254                 :    32425590 :   return set_ssa_val_to (PHI_RESULT (phi), result);
    6255                 :    32425590 : }
    6256                 :             : 
    6257                 :             : /* Try to simplify RHS using equivalences and constant folding.  */
    6258                 :             : 
    6259                 :             : static tree
    6260                 :   117455095 : try_to_simplify (gassign *stmt)
    6261                 :             : {
    6262                 :   117455095 :   enum tree_code code = gimple_assign_rhs_code (stmt);
    6263                 :   117455095 :   tree tem;
    6264                 :             : 
    6265                 :             :   /* For stores we can end up simplifying a SSA_NAME rhs.  Just return
    6266                 :             :      in this case, there is no point in doing extra work.  */
    6267                 :   117455095 :   if (code == SSA_NAME)
    6268                 :             :     return NULL_TREE;
    6269                 :             : 
    6270                 :             :   /* First try constant folding based on our current lattice.  */
    6271                 :   103912370 :   mprts_hook = vn_lookup_simplify_result;
    6272                 :   103912370 :   tem = gimple_fold_stmt_to_constant_1 (stmt, vn_valueize, vn_valueize);
    6273                 :   103912370 :   mprts_hook = NULL;
    6274                 :   103912370 :   if (tem
    6275                 :   103912370 :       && (TREE_CODE (tem) == SSA_NAME
    6276                 :    22745949 :           || is_gimple_min_invariant (tem)))
    6277                 :    22833672 :     return tem;
    6278                 :             : 
    6279                 :             :   return NULL_TREE;
    6280                 :             : }
    6281                 :             : 
    6282                 :             : /* Visit and value number STMT, return true if the value number
    6283                 :             :    changed.  */
    6284                 :             : 
    6285                 :             : static bool
    6286                 :   395829986 : visit_stmt (gimple *stmt, bool backedges_varying_p = false)
    6287                 :             : {
    6288                 :   395829986 :   bool changed = false;
    6289                 :             : 
    6290                 :   395829986 :   if (dump_file && (dump_flags & TDF_DETAILS))
    6291                 :             :     {
    6292                 :      363740 :       fprintf (dump_file, "Value numbering stmt = ");
    6293                 :      363740 :       print_gimple_stmt (dump_file, stmt, 0);
    6294                 :             :     }
    6295                 :             : 
    6296                 :   395829986 :   if (gimple_code (stmt) == GIMPLE_PHI)
    6297                 :    25406671 :     changed = visit_phi (stmt, NULL, backedges_varying_p);
    6298                 :   530447505 :   else if (gimple_has_volatile_ops (stmt))
    6299                 :     8691604 :     changed = defs_to_varying (stmt);
    6300                 :   361731711 :   else if (gassign *ass = dyn_cast <gassign *> (stmt))
    6301                 :             :     {
    6302                 :   122784905 :       enum tree_code code = gimple_assign_rhs_code (ass);
    6303                 :   122784905 :       tree lhs = gimple_assign_lhs (ass);
    6304                 :   122784905 :       tree rhs1 = gimple_assign_rhs1 (ass);
    6305                 :   122784905 :       tree simplified;
    6306                 :             : 
    6307                 :             :       /* Shortcut for copies. Simplifying copies is pointless,
    6308                 :             :          since we copy the expression and value they represent.  */
    6309                 :   122784905 :       if (code == SSA_NAME
    6310                 :    18872535 :           && TREE_CODE (lhs) == SSA_NAME)
    6311                 :             :         {
    6312                 :     5329810 :           changed = visit_copy (lhs, rhs1);
    6313                 :     5329810 :           goto done;
    6314                 :             :         }
    6315                 :   117455095 :       simplified = try_to_simplify (ass);
    6316                 :   117455095 :       if (simplified)
    6317                 :             :         {
    6318                 :    22833672 :           if (dump_file && (dump_flags & TDF_DETAILS))
    6319                 :             :             {
    6320                 :       13297 :               fprintf (dump_file, "RHS ");
    6321                 :       13297 :               print_gimple_expr (dump_file, ass, 0);
    6322                 :       13297 :               fprintf (dump_file, " simplified to ");
    6323                 :       13297 :               print_generic_expr (dump_file, simplified);
    6324                 :       13297 :               fprintf (dump_file, "\n");
    6325                 :             :             }
    6326                 :             :         }
    6327                 :             :       /* Setting value numbers to constants will occasionally
    6328                 :             :          screw up phi congruence because constants are not
    6329                 :             :          uniquely associated with a single ssa name that can be
    6330                 :             :          looked up.  */
    6331                 :    22833672 :       if (simplified
    6332                 :    22833672 :           && is_gimple_min_invariant (simplified)
    6333                 :    20100411 :           && TREE_CODE (lhs) == SSA_NAME)
    6334                 :             :         {
    6335                 :     6973671 :           changed = set_ssa_val_to (lhs, simplified);
    6336                 :     6973671 :           goto done;
    6337                 :             :         }
    6338                 :   110481424 :       else if (simplified
    6339                 :    15860001 :                && TREE_CODE (simplified) == SSA_NAME
    6340                 :     2733261 :                && TREE_CODE (lhs) == SSA_NAME)
    6341                 :             :         {
    6342                 :     2733261 :           changed = visit_copy (lhs, simplified);
    6343                 :     2733261 :           goto done;
    6344                 :             :         }
    6345                 :             : 
    6346                 :   107748163 :       if ((TREE_CODE (lhs) == SSA_NAME
    6347                 :             :            /* We can substitute SSA_NAMEs that are live over
    6348                 :             :               abnormal edges with their constant value.  */
    6349                 :    77838335 :            && !(gimple_assign_copy_p (ass)
    6350                 :          26 :                 && is_gimple_min_invariant (rhs1))
    6351                 :    77838309 :            && !(simplified
    6352                 :           0 :                 && is_gimple_min_invariant (simplified))
    6353                 :    77838309 :            && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
    6354                 :             :           /* Stores or copies from SSA_NAMEs that are live over
    6355                 :             :              abnormal edges are a problem.  */
    6356                 :   185585224 :           || (code == SSA_NAME
    6357                 :    13542725 :               && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1)))
    6358                 :        1504 :         changed = defs_to_varying (ass);
    6359                 :   107746659 :       else if (REFERENCE_CLASS_P (lhs)
    6360                 :   107746659 :                || DECL_P (lhs))
    6361                 :    29909598 :         changed = visit_reference_op_store (lhs, rhs1, ass);
    6362                 :    77837061 :       else if (TREE_CODE (lhs) == SSA_NAME)
    6363                 :             :         {
    6364                 :    77837061 :           if ((gimple_assign_copy_p (ass)
    6365                 :          26 :                && is_gimple_min_invariant (rhs1))
    6366                 :    77837087 :               || (simplified
    6367                 :           0 :                   && is_gimple_min_invariant (simplified)))
    6368                 :             :             {
    6369                 :           0 :               if (simplified)
    6370                 :           0 :                 changed = set_ssa_val_to (lhs, simplified);
    6371                 :             :               else
    6372                 :           0 :                 changed = set_ssa_val_to (lhs, rhs1);
    6373                 :             :             }
    6374                 :             :           else
    6375                 :             :             {
    6376                 :             :               /* Visit the original statement.  */
    6377                 :    77837061 :               switch (vn_get_stmt_kind (ass))
    6378                 :             :                 {
    6379                 :    45645291 :                 case VN_NARY:
    6380                 :    45645291 :                   changed = visit_nary_op (lhs, ass);
    6381                 :    45645291 :                   break;
    6382                 :    32150461 :                 case VN_REFERENCE:
    6383                 :    32150461 :                   changed = visit_reference_op_load (lhs, rhs1, ass);
    6384                 :    32150461 :                   break;
    6385                 :       41309 :                 default:
    6386                 :       41309 :                   changed = defs_to_varying (ass);
    6387                 :       41309 :                   break;
    6388                 :             :                 }
    6389                 :             :             }
    6390                 :             :         }
    6391                 :             :       else
    6392                 :           0 :         changed = defs_to_varying (ass);
    6393                 :             :     }
    6394                 :   238946806 :   else if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
    6395                 :             :     {
    6396                 :    23172464 :       tree lhs = gimple_call_lhs (call_stmt);
    6397                 :    23172464 :       if (lhs && TREE_CODE (lhs) == SSA_NAME)
    6398                 :             :         {
    6399                 :             :           /* Try constant folding based on our current lattice.  */
    6400                 :     7884035 :           tree simplified = gimple_fold_stmt_to_constant_1 (call_stmt,
    6401                 :             :                                                             vn_valueize);
    6402                 :     7884035 :           if (simplified)
    6403                 :             :             {
    6404                 :       52406 :               if (dump_file && (dump_flags & TDF_DETAILS))
    6405                 :             :                 {
    6406                 :           1 :                   fprintf (dump_file, "call ");
    6407                 :           1 :                   print_gimple_expr (dump_file, call_stmt, 0);
    6408                 :           1 :                   fprintf (dump_file, " simplified to ");
    6409                 :           1 :                   print_generic_expr (dump_file, simplified);
    6410                 :           1 :                   fprintf (dump_file, "\n");
    6411                 :             :                 }
    6412                 :             :             }
    6413                 :             :           /* Setting value numbers to constants will occasionally
    6414                 :             :              screw up phi congruence because constants are not
    6415                 :             :              uniquely associated with a single ssa name that can be
    6416                 :             :              looked up.  */
    6417                 :       52406 :           if (simplified
    6418                 :       52406 :               && is_gimple_min_invariant (simplified))
    6419                 :             :             {
    6420                 :       46740 :               changed = set_ssa_val_to (lhs, simplified);
    6421                 :       93480 :               if (gimple_vdef (call_stmt))
    6422                 :         647 :                 changed |= set_ssa_val_to (gimple_vdef (call_stmt),
    6423                 :             :                                            SSA_VAL (gimple_vuse (call_stmt)));
    6424                 :       46740 :               goto done;
    6425                 :             :             }
    6426                 :     7837295 :           else if (simplified
    6427                 :        5666 :                    && TREE_CODE (simplified) == SSA_NAME)
    6428                 :             :             {
    6429                 :         303 :               changed = visit_copy (lhs, simplified);
    6430                 :         606 :               if (gimple_vdef (call_stmt))
    6431                 :           0 :                 changed |= set_ssa_val_to (gimple_vdef (call_stmt),
    6432                 :             :                                            SSA_VAL (gimple_vuse (call_stmt)));
    6433                 :         303 :               goto done;
    6434                 :             :             }
    6435                 :     7836992 :           else if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
    6436                 :             :             {
    6437                 :         381 :               changed = defs_to_varying (call_stmt);
    6438                 :         381 :               goto done;
    6439                 :             :             }
    6440                 :             :         }
    6441                 :             : 
    6442                 :             :       /* Pick up flags from a devirtualization target.  */
    6443                 :    23125040 :       tree fn = gimple_call_fn (stmt);
    6444                 :    23125040 :       int extra_fnflags = 0;
    6445                 :    23125040 :       if (fn && TREE_CODE (fn) == SSA_NAME)
    6446                 :             :         {
    6447                 :      523460 :           fn = SSA_VAL (fn);
    6448                 :      523460 :           if (TREE_CODE (fn) == ADDR_EXPR
    6449                 :      523460 :               && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL)
    6450                 :        4030 :             extra_fnflags = flags_from_decl_or_type (TREE_OPERAND (fn, 0));
    6451                 :             :         }
    6452                 :    23125040 :       if ((/* Calls to the same function with the same vuse
    6453                 :             :               and the same operands do not necessarily return the same
    6454                 :             :               value, unless they're pure or const.  */
    6455                 :    23125040 :            ((gimple_call_flags (call_stmt) | extra_fnflags)
    6456                 :    23125040 :             & (ECF_PURE | ECF_CONST))
    6457                 :             :            /* If calls have a vdef, subsequent calls won't have
    6458                 :             :               the same incoming vuse.  So, if 2 calls with vdef have the
    6459                 :             :               same vuse, we know they're not subsequent.
    6460                 :             :               We can value number 2 calls to the same function with the
    6461                 :             :               same vuse and the same operands which are not subsequent
    6462                 :             :               the same, because there is no code in the program that can
    6463                 :             :               compare the 2 values...  */
    6464                 :    19678972 :            || (gimple_vdef (call_stmt)
    6465                 :             :                /* ... unless the call returns a pointer which does
    6466                 :             :                   not alias with anything else.  In which case the
    6467                 :             :                   information that the values are distinct are encoded
    6468                 :             :                   in the IL.  */
    6469                 :    19644540 :                && !(gimple_call_return_flags (call_stmt) & ERF_NOALIAS)
    6470                 :             :                /* Only perform the following when being called from PRE
    6471                 :             :                   which embeds tail merging.  */
    6472                 :    19237462 :                && default_vn_walk_kind == VN_WALK))
    6473                 :             :           /* Do not process .DEFERRED_INIT since that confuses uninit
    6474                 :             :              analysis.  */
    6475                 :    27852664 :           && !gimple_call_internal_p (call_stmt, IFN_DEFERRED_INIT))
    6476                 :     8173003 :         changed = visit_reference_op_call (lhs, call_stmt);
    6477                 :             :       else
    6478                 :    14952037 :         changed = defs_to_varying (call_stmt);
    6479                 :             :     }
    6480                 :             :   else
    6481                 :   215774342 :     changed = defs_to_varying (stmt);
    6482                 :   395829986 :  done:
    6483                 :   395829986 :   return changed;
    6484                 :             : }
    6485                 :             : 
    6486                 :             : 
    6487                 :             : /* Allocate a value number table.  */
    6488                 :             : 
    6489                 :             : static void
    6490                 :     5771874 : allocate_vn_table (vn_tables_t table, unsigned size)
    6491                 :             : {
    6492                 :     5771874 :   table->phis = new vn_phi_table_type (size);
    6493                 :     5771874 :   table->nary = new vn_nary_op_table_type (size);
    6494                 :     5771874 :   table->references = new vn_reference_table_type (size);
    6495                 :     5771874 : }
    6496                 :             : 
    6497                 :             : /* Free a value number table.  */
    6498                 :             : 
    6499                 :             : static void
    6500                 :     5771874 : free_vn_table (vn_tables_t table)
    6501                 :             : {
    6502                 :             :   /* Walk over elements and release vectors.  */
    6503                 :     5771874 :   vn_reference_iterator_type hir;
    6504                 :     5771874 :   vn_reference_t vr;
    6505                 :   139550468 :   FOR_EACH_HASH_TABLE_ELEMENT (*table->references, vr, vn_reference_t, hir)
    6506                 :    66889297 :     vr->operands.release ();
    6507                 :     5771874 :   delete table->phis;
    6508                 :     5771874 :   table->phis = NULL;
    6509                 :     5771874 :   delete table->nary;
    6510                 :     5771874 :   table->nary = NULL;
    6511                 :     5771874 :   delete table->references;
    6512                 :     5771874 :   table->references = NULL;
    6513                 :     5771874 : }
    6514                 :             : 
    6515                 :             : /* Set *ID according to RESULT.  */
    6516                 :             : 
    6517                 :             : static void
    6518                 :    32505502 : set_value_id_for_result (tree result, unsigned int *id)
    6519                 :             : {
    6520                 :    32505502 :   if (result && TREE_CODE (result) == SSA_NAME)
    6521                 :    20352085 :     *id = VN_INFO (result)->value_id;
    6522                 :     9075014 :   else if (result && is_gimple_min_invariant (result))
    6523                 :     3390296 :     *id = get_or_alloc_constant_value_id (result);
    6524                 :             :   else
    6525                 :     8763121 :     *id = get_next_value_id ();
    6526                 :    32505502 : }
    6527                 :             : 
    6528                 :             : /* Set the value ids in the valid hash tables.  */
    6529                 :             : 
    6530                 :             : static void
    6531                 :      927955 : set_hashtable_value_ids (void)
    6532                 :             : {
    6533                 :      927955 :   vn_nary_op_iterator_type hin;
    6534                 :      927955 :   vn_phi_iterator_type hip;
    6535                 :      927955 :   vn_reference_iterator_type hir;
    6536                 :      927955 :   vn_nary_op_t vno;
    6537                 :      927955 :   vn_reference_t vr;
    6538                 :      927955 :   vn_phi_t vp;
    6539                 :             : 
    6540                 :             :   /* Now set the value ids of the things we had put in the hash
    6541                 :             :      table.  */
    6542                 :             : 
    6543                 :    45455407 :   FOR_EACH_HASH_TABLE_ELEMENT (*valid_info->nary, vno, vn_nary_op_t, hin)
    6544                 :    22263726 :     if (! vno->predicated_values)
    6545                 :     7392855 :       set_value_id_for_result (vno->u.result, &vno->value_id);
    6546                 :             : 
    6547                 :     8353643 :   FOR_EACH_HASH_TABLE_ELEMENT (*valid_info->phis, vp, vn_phi_t, hip)
    6548                 :     3712844 :     set_value_id_for_result (vp->result, &vp->value_id);
    6549                 :             : 
    6550                 :    43727561 :   FOR_EACH_HASH_TABLE_ELEMENT (*valid_info->references, vr, vn_reference_t,
    6551                 :             :                                hir)
    6552                 :    21399803 :     set_value_id_for_result (vr->result, &vr->value_id);
    6553                 :      927955 : }
    6554                 :             : 
    6555                 :             : /* Return the maximum value id we have ever seen.  */
    6556                 :             : 
    6557                 :             : unsigned int
    6558                 :     1855910 : get_max_value_id (void)
    6559                 :             : {
    6560                 :     1855910 :   return next_value_id;
    6561                 :             : }
    6562                 :             : 
    6563                 :             : /* Return the maximum constant value id we have ever seen.  */
    6564                 :             : 
    6565                 :             : unsigned int
    6566                 :     1855910 : get_max_constant_value_id (void)
    6567                 :             : {
    6568                 :     1855910 :   return -next_constant_value_id;
    6569                 :             : }
    6570                 :             : 
    6571                 :             : /* Return the next unique value id.  */
    6572                 :             : 
    6573                 :             : unsigned int
    6574                 :    46119112 : get_next_value_id (void)
    6575                 :             : {
    6576                 :    46119112 :   gcc_checking_assert ((int)next_value_id > 0);
    6577                 :    46119112 :   return next_value_id++;
    6578                 :             : }
    6579                 :             : 
    6580                 :             : /* Return the next unique value id for constants.  */
    6581                 :             : 
    6582                 :             : unsigned int
    6583                 :     2361409 : get_next_constant_value_id (void)
    6584                 :             : {
    6585                 :     2361409 :   gcc_checking_assert (next_constant_value_id < 0);
    6586                 :     2361409 :   return next_constant_value_id--;
    6587                 :             : }
    6588                 :             : 
    6589                 :             : 
    6590                 :             : /* Compare two expressions E1 and E2 and return true if they are equal.
    6591                 :             :    If match_vn_top_optimistically is true then VN_TOP is equal to anything,
    6592                 :             :    otherwise VN_TOP only matches VN_TOP.  */
    6593                 :             : 
    6594                 :             : bool
    6595                 :   219471793 : expressions_equal_p (tree e1, tree e2, bool match_vn_top_optimistically)
    6596                 :             : {
    6597                 :             :   /* The obvious case.  */
    6598                 :   219471793 :   if (e1 == e2)
    6599                 :             :     return true;
    6600                 :             : 
    6601                 :             :   /* If either one is VN_TOP consider them equal.  */
    6602                 :    64938727 :   if (match_vn_top_optimistically
    6603                 :    60423395 :       && (e1 == VN_TOP || e2 == VN_TOP))
    6604                 :             :     return true;
    6605                 :             : 
    6606                 :             :   /* If only one of them is null, they cannot be equal.  While in general
    6607                 :             :      this should not happen for operations like TARGET_MEM_REF some
    6608                 :             :      operands are optional and an identity value we could substitute
    6609                 :             :      has differing semantics.  */
    6610                 :    64938727 :   if (!e1 || !e2)
    6611                 :             :     return false;
    6612                 :             : 
    6613                 :             :   /* SSA_NAME compare pointer equal.  */
    6614                 :    64938727 :   if (TREE_CODE (e1) == SSA_NAME || TREE_CODE (e2) == SSA_NAME)
    6615                 :             :     return false;
    6616                 :             : 
    6617                 :             :   /* Now perform the actual comparison.  */
    6618                 :    32613576 :   if (TREE_CODE (e1) == TREE_CODE (e2)
    6619                 :    32613576 :       && operand_equal_p (e1, e2, OEP_PURE_SAME))
    6620                 :             :     return true;
    6621                 :             : 
    6622                 :             :   return false;
    6623                 :             : }
    6624                 :             : 
    6625                 :             : 
    6626                 :             : /* Return true if the nary operation NARY may trap.  This is a copy
    6627                 :             :    of stmt_could_throw_1_p adjusted to the SCCVN IL.  */
    6628                 :             : 
    6629                 :             : bool
    6630                 :     5185435 : vn_nary_may_trap (vn_nary_op_t nary)
    6631                 :             : {
    6632                 :     5185435 :   tree type;
    6633                 :     5185435 :   tree rhs2 = NULL_TREE;
    6634                 :     5185435 :   bool honor_nans = false;
    6635                 :     5185435 :   bool honor_snans = false;
    6636                 :     5185435 :   bool fp_operation = false;
    6637                 :     5185435 :   bool honor_trapv = false;
    6638                 :     5185435 :   bool handled, ret;
    6639                 :     5185435 :   unsigned i;
    6640                 :             : 
    6641                 :     5185435 :   if (TREE_CODE_CLASS (nary->opcode) == tcc_comparison
    6642                 :             :       || TREE_CODE_CLASS (nary->opcode) == tcc_unary
    6643                 :     5185435 :       || TREE_CODE_CLASS (nary->opcode) == tcc_binary)
    6644                 :             :     {
    6645                 :     5101684 :       type = nary->type;
    6646                 :     5101684 :       fp_operation = FLOAT_TYPE_P (type);
    6647                 :     5101684 :       if (fp_operation)
    6648                 :             :         {
    6649                 :      117349 :           honor_nans = flag_trapping_math && !flag_finite_math_only;
    6650                 :      117349 :           honor_snans = flag_signaling_nans != 0;
    6651                 :             :         }
    6652                 :     4984335 :       else if (INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_TRAPS (type))
    6653                 :             :         honor_trapv = true;
    6654                 :             :     }
    6655                 :     5185435 :   if (nary->length >= 2)
    6656                 :     1983337 :     rhs2 = nary->op[1];
    6657                 :     5185435 :   ret = operation_could_trap_helper_p (nary->opcode, fp_operation,
    6658                 :             :                                        honor_trapv, honor_nans, honor_snans,
    6659                 :             :                                        rhs2, &handled);
    6660                 :     5185435 :   if (handled && ret)
    6661                 :             :     return true;
    6662                 :             : 
    6663                 :    12055566 :   for (i = 0; i < nary->length; ++i)
    6664                 :     6976720 :     if (tree_could_trap_p (nary->op[i]))
    6665                 :             :       return true;
    6666                 :             : 
    6667                 :             :   return false;
    6668                 :             : }
    6669                 :             : 
    6670                 :             : /* Return true if the reference operation REF may trap.  */
    6671                 :             : 
    6672                 :             : bool
    6673                 :     1746600 : vn_reference_may_trap (vn_reference_t ref)
    6674                 :             : {
    6675                 :     1746600 :   switch (ref->operands[0].opcode)
    6676                 :             :     {
    6677                 :             :     case MODIFY_EXPR:
    6678                 :             :     case CALL_EXPR:
    6679                 :             :       /* We do not handle calls.  */
    6680                 :             :       return true;
    6681                 :             :     case ADDR_EXPR:
    6682                 :             :       /* And toplevel address computations never trap.  */
    6683                 :             :       return false;
    6684                 :             :     default:;
    6685                 :             :     }
    6686                 :             : 
    6687                 :             :   vn_reference_op_t op;
    6688                 :             :   unsigned i;
    6689                 :     4847755 :   FOR_EACH_VEC_ELT (ref->operands, i, op)
    6690                 :             :     {
    6691                 :     4847559 :       switch (op->opcode)
    6692                 :             :         {
    6693                 :             :         case WITH_SIZE_EXPR:
    6694                 :             :         case TARGET_MEM_REF:
    6695                 :             :           /* Always variable.  */
    6696                 :             :           return true;
    6697                 :     1281953 :         case COMPONENT_REF:
    6698                 :     1281953 :           if (op->op1 && TREE_CODE (op->op1) == SSA_NAME)
    6699                 :             :             return true;
    6700                 :             :           break;
    6701                 :           8 :         case ARRAY_RANGE_REF:
    6702                 :           8 :           if (TREE_CODE (op->op0) == SSA_NAME)
    6703                 :             :             return true;
    6704                 :             :           break;
    6705                 :      239182 :         case ARRAY_REF:
    6706                 :      239182 :           {
    6707                 :      239182 :             if (TREE_CODE (op->op0) != INTEGER_CST)
    6708                 :             :               return true;
    6709                 :             : 
    6710                 :             :             /* !in_array_bounds   */
    6711                 :      211407 :             tree domain_type = TYPE_DOMAIN (ref->operands[i+1].type);
    6712                 :      211407 :             if (!domain_type)
    6713                 :             :               return true;
    6714                 :             : 
    6715                 :      211280 :             tree min = op->op1;
    6716                 :      211280 :             tree max = TYPE_MAX_VALUE (domain_type);
    6717                 :      211280 :             if (!min
    6718                 :      211280 :                 || !max
    6719                 :      198334 :                 || TREE_CODE (min) != INTEGER_CST
    6720                 :      198334 :                 || TREE_CODE (max) != INTEGER_CST)
    6721                 :             :               return true;
    6722                 :             : 
    6723                 :      196250 :             if (tree_int_cst_lt (op->op0, min)
    6724                 :      196250 :                 || tree_int_cst_lt (max, op->op0))
    6725                 :         594 :               return true;
    6726                 :             : 
    6727                 :             :             break;
    6728                 :             :           }
    6729                 :             :         case MEM_REF:
    6730                 :             :           /* Nothing interesting in itself, the base is separate.  */
    6731                 :             :           break;
    6732                 :             :         /* The following are the address bases.  */
    6733                 :             :         case SSA_NAME:
    6734                 :             :           return true;
    6735                 :     1220579 :         case ADDR_EXPR:
    6736                 :     1220579 :           if (op->op0)
    6737                 :     1220579 :             return tree_could_trap_p (TREE_OPERAND (op->op0, 0));
    6738                 :             :           return false;
    6739                 :     3155263 :         default:;
    6740                 :             :         }
    6741                 :             :     }
    6742                 :             :   return false;
    6743                 :             : }
    6744                 :             : 
    6745                 :     9781939 : eliminate_dom_walker::eliminate_dom_walker (cdi_direction direction,
    6746                 :     9781939 :                                             bitmap inserted_exprs_)
    6747                 :     9781939 :   : dom_walker (direction), do_pre (inserted_exprs_ != NULL),
    6748                 :     9781939 :     el_todo (0), eliminations (0), insertions (0),
    6749                 :     9781939 :     inserted_exprs (inserted_exprs_)
    6750                 :             : {
    6751                 :     9781939 :   need_eh_cleanup = BITMAP_ALLOC (NULL);
    6752                 :     9781939 :   need_ab_cleanup = BITMAP_ALLOC (NULL);
    6753                 :     9781939 : }
    6754                 :             : 
    6755                 :     9781939 : eliminate_dom_walker::~eliminate_dom_walker ()
    6756                 :             : {
    6757                 :     9781939 :   BITMAP_FREE (need_eh_cleanup);
    6758                 :     9781939 :   BITMAP_FREE (need_ab_cleanup);
    6759                 :     9781939 : }
    6760                 :             : 
    6761                 :             : /* Return a leader for OP that is available at the current point of the
    6762                 :             :    eliminate domwalk.  */
    6763                 :             : 
    6764                 :             : tree
    6765                 :   167283722 : eliminate_dom_walker::eliminate_avail (basic_block, tree op)
    6766                 :             : {
    6767                 :   167283722 :   tree valnum = VN_INFO (op)->valnum;
    6768                 :   167283722 :   if (TREE_CODE (valnum) == SSA_NAME)
    6769                 :             :     {
    6770                 :   162623930 :       if (SSA_NAME_IS_DEFAULT_DEF (valnum))
    6771                 :             :         return valnum;
    6772                 :   283311866 :       if (avail.length () > SSA_NAME_VERSION (valnum))
    6773                 :             :         {
    6774                 :   127244162 :           tree av = avail[SSA_NAME_VERSION (valnum)];
    6775                 :             :           /* When PRE discovers a new redundancy there's no way to unite
    6776                 :             :              the value classes so it instead inserts a copy old-val = new-val.
    6777                 :             :              Look through such copies here, providing one more level of
    6778                 :             :              simplification at elimination time.  */
    6779                 :   127244162 :           gassign *ass;
    6780                 :   222960280 :           if (av && (ass = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (av))))
    6781                 :    67877903 :             if (gimple_assign_rhs_class (ass) == GIMPLE_SINGLE_RHS)
    6782                 :             :               {
    6783                 :    36211211 :                 tree rhs1 = gimple_assign_rhs1 (ass);
    6784                 :    36211211 :                 if (CONSTANT_CLASS_P (rhs1)
    6785                 :    36211211 :                     || (TREE_CODE (rhs1) == SSA_NAME
    6786                 :       30327 :                         && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1)))
    6787                 :             :                   av = rhs1;
    6788                 :             :               }
    6789                 :   127244162 :           return av;
    6790                 :             :         }
    6791                 :             :     }
    6792                 :     4659792 :   else if (is_gimple_min_invariant (valnum))
    6793                 :             :     return valnum;
    6794                 :             :   return NULL_TREE;
    6795                 :             : }
    6796                 :             : 
    6797                 :             : /* At the current point of the eliminate domwalk make OP available.  */
    6798                 :             : 
    6799                 :             : void
    6800                 :    47387072 : eliminate_dom_walker::eliminate_push_avail (basic_block, tree op)
    6801                 :             : {
    6802                 :    47387072 :   tree valnum = VN_INFO (op)->valnum;
    6803                 :    47387072 :   if (TREE_CODE (valnum) == SSA_NAME)
    6804                 :             :     {
    6805                 :    91605215 :       if (avail.length () <= SSA_NAME_VERSION (valnum))
    6806                 :    16104603 :         avail.safe_grow_cleared (SSA_NAME_VERSION (valnum) + 1, true);
    6807                 :    47387072 :       tree pushop = op;
    6808                 :    47387072 :       if (avail[SSA_NAME_VERSION (valnum)])
    6809                 :       41662 :         pushop = avail[SSA_NAME_VERSION (valnum)];
    6810                 :    47387072 :       avail_stack.safe_push (pushop);
    6811                 :    47387072 :       avail[SSA_NAME_VERSION (valnum)] = op;
    6812                 :             :     }
    6813                 :    47387072 : }
    6814                 :             : 
    6815                 :             : /* Insert the expression recorded by SCCVN for VAL at *GSI.  Returns
    6816                 :             :    the leader for the expression if insertion was successful.  */
    6817                 :             : 
    6818                 :             : tree
    6819                 :      156746 : eliminate_dom_walker::eliminate_insert (basic_block bb,
    6820                 :             :                                         gimple_stmt_iterator *gsi, tree val)
    6821                 :             : {
    6822                 :             :   /* We can insert a sequence with a single assignment only.  */
    6823                 :      156746 :   gimple_seq stmts = VN_INFO (val)->expr;
    6824                 :      156746 :   if (!gimple_seq_singleton_p (stmts))
    6825                 :             :     return NULL_TREE;
    6826                 :      292727 :   gassign *stmt = dyn_cast <gassign *> (gimple_seq_first_stmt (stmts));
    6827                 :      156746 :   if (!stmt
    6828                 :      156746 :       || (!CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))
    6829                 :             :           && gimple_assign_rhs_code (stmt) != VIEW_CONVERT_EXPR
    6830                 :             :           && gimple_assign_rhs_code (stmt) != NEGATE_EXPR
    6831                 :             :           && gimple_assign_rhs_code (stmt) != BIT_FIELD_REF
    6832                 :             :           && (gimple_assign_rhs_code (stmt) != BIT_AND_EXPR
    6833                 :          29 :               || TREE_CODE (gimple_assign_rhs2 (stmt)) != INTEGER_CST)))
    6834                 :             :     return NULL_TREE;
    6835                 :             : 
    6836                 :       32036 :   tree op = gimple_assign_rhs1 (stmt);
    6837                 :       32036 :   if (gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR
    6838                 :       32036 :       || gimple_assign_rhs_code (stmt) == BIT_FIELD_REF)
    6839                 :       18529 :     op = TREE_OPERAND (op, 0);
    6840                 :       32036 :   tree leader = TREE_CODE (op) == SSA_NAME ? eliminate_avail (bb, op) : op;
    6841                 :       32000 :   if (!leader)
    6842                 :             :     return NULL_TREE;
    6843                 :             : 
    6844                 :       20769 :   tree res;
    6845                 :       20769 :   stmts = NULL;
    6846                 :       38390 :   if (gimple_assign_rhs_code (stmt) == BIT_FIELD_REF)
    6847                 :       32456 :     res = gimple_build (&stmts, BIT_FIELD_REF,
    6848                 :       16228 :                         TREE_TYPE (val), leader,
    6849                 :       16228 :                         TREE_OPERAND (gimple_assign_rhs1 (stmt), 1),
    6850                 :       16228 :                         TREE_OPERAND (gimple_assign_rhs1 (stmt), 2));
    6851                 :        4541 :   else if (gimple_assign_rhs_code (stmt) == BIT_AND_EXPR)
    6852                 :          58 :     res = gimple_build (&stmts, BIT_AND_EXPR,
    6853                 :          29 :                         TREE_TYPE (val), leader, gimple_assign_rhs2 (stmt));
    6854                 :             :   else
    6855                 :        4512 :     res = gimple_build (&stmts, gimple_assign_rhs_code (stmt),
    6856                 :        4512 :                         TREE_TYPE (val), leader);
    6857                 :       20769 :   if (TREE_CODE (res) != SSA_NAME
    6858                 :       20768 :       || SSA_NAME_IS_DEFAULT_DEF (res)
    6859                 :       41537 :       || gimple_bb (SSA_NAME_DEF_STMT (res)))
    6860                 :             :     {
    6861                 :           4 :       gimple_seq_discard (stmts);
    6862                 :             : 
    6863                 :             :       /* During propagation we have to treat SSA info conservatively
    6864                 :             :          and thus we can end up simplifying the inserted expression
    6865                 :             :          at elimination time to sth not defined in stmts.  */
    6866                 :             :       /* But then this is a redundancy we failed to detect.  Which means
    6867                 :             :          res now has two values.  That doesn't play well with how
    6868                 :             :          we track availability here, so give up.  */
    6869                 :           4 :       if (dump_file && (dump_flags & TDF_DETAILS))
    6870                 :             :         {
    6871                 :           0 :           if (TREE_CODE (res) == SSA_NAME)
    6872                 :           0 :             res = eliminate_avail (bb, res);
    6873                 :           0 :           if (res)
    6874                 :             :             {
    6875                 :           0 :               fprintf (dump_file, "Failed to insert expression for value ");
    6876                 :           0 :               print_generic_expr (dump_file, val);
    6877                 :           0 :               fprintf (dump_file, " which is really fully redundant to ");
    6878                 :           0 :               print_generic_expr (dump_file, res);
    6879                 :           0 :               fprintf (dump_file, "\n");
    6880                 :             :             }
    6881                 :             :         }
    6882                 :             : 
    6883                 :           4 :       return NULL_TREE;
    6884                 :             :     }
    6885                 :             :   else
    6886                 :             :     {
    6887                 :       20765 :       gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
    6888                 :       20765 :       vn_ssa_aux_t vn_info = VN_INFO (res);
    6889                 :       20765 :       vn_info->valnum = val;
    6890                 :       20765 :       vn_info->visited = true;
    6891                 :             :     }
    6892                 :             : 
    6893                 :       20765 :   insertions++;
    6894                 :       20765 :   if (dump_file && (dump_flags & TDF_DETAILS))
    6895                 :             :     {
    6896                 :         501 :       fprintf (dump_file, "Inserted ");
    6897                 :         501 :       print_gimple_stmt (dump_file, SSA_NAME_DEF_STMT (res), 0);
    6898                 :             :     }
    6899                 :             : 
    6900                 :             :   return res;
    6901                 :             : }
    6902                 :             : 
    6903                 :             : void
    6904                 :   304767670 : eliminate_dom_walker::eliminate_stmt (basic_block b, gimple_stmt_iterator *gsi)
    6905                 :             : {
    6906                 :   304767670 :   tree sprime = NULL_TREE;
    6907                 :   304767670 :   gimple *stmt = gsi_stmt (*gsi);
    6908                 :   304767670 :   tree lhs = gimple_get_lhs (stmt);
    6909                 :   112089121 :   if (lhs && TREE_CODE (lhs) == SSA_NAME
    6910                 :   155755338 :       && !gimple_has_volatile_ops (stmt)
    6911                 :             :       /* See PR43491.  Do not replace a global register variable when
    6912                 :             :          it is a the RHS of an assignment.  Do replace local register
    6913                 :             :          variables since gcc does not guarantee a local variable will
    6914                 :             :          be allocated in register.
    6915                 :             :          ???  The fix isn't effective here.  This should instead
    6916                 :             :          be ensured by not value-numbering them the same but treating
    6917                 :             :          them like volatiles?  */
    6918                 :   381591960 :       && !(gimple_assign_single_p (stmt)
    6919                 :    33483024 :            && (TREE_CODE (gimple_assign_rhs1 (stmt)) == VAR_DECL
    6920                 :     2361421 :                && DECL_HARD_REGISTER (gimple_assign_rhs1 (stmt))
    6921                 :        4155 :                && is_global_var (gimple_assign_rhs1 (stmt)))))
    6922                 :             :     {
    6923                 :    76824049 :       sprime = eliminate_avail (b, lhs);
    6924                 :    76824049 :       if (!sprime)
    6925                 :             :         {
    6926                 :             :           /* If there is no existing usable leader but SCCVN thinks
    6927                 :             :              it has an expression it wants to use as replacement,
    6928                 :             :              insert that.  */
    6929                 :    64626612 :           tree val = VN_INFO (lhs)->valnum;
    6930                 :    64626612 :           vn_ssa_aux_t vn_info;
    6931                 :    64626612 :           if (val != VN_TOP
    6932                 :    64626612 :               && TREE_CODE (val) == SSA_NAME
    6933                 :    64626612 :               && (vn_info = VN_INFO (val), true)
    6934                 :    64626612 :               && vn_info->needs_insertion
    6935                 :      333657 :               && vn_info->expr != NULL
    6936                 :    64783358 :               && (sprime = eliminate_insert (b, gsi, val)) != NULL_TREE)
    6937                 :       20765 :             eliminate_push_avail (b, sprime);
    6938                 :             :         }
    6939                 :             : 
    6940                 :             :       /* If this now constitutes a copy duplicate points-to
    6941                 :             :          and range info appropriately.  This is especially
    6942                 :             :          important for inserted code.  */
    6943                 :    64626612 :       if (sprime
    6944                 :    12218202 :           && TREE_CODE (sprime) == SSA_NAME)
    6945                 :     8501993 :         maybe_duplicate_ssa_info_at_copy (lhs, sprime);
    6946                 :             : 
    6947                 :             :       /* Inhibit the use of an inserted PHI on a loop header when
    6948                 :             :          the address of the memory reference is a simple induction
    6949                 :             :          variable.  In other cases the vectorizer won't do anything
    6950                 :             :          anyway (either it's loop invariant or a complicated
    6951                 :             :          expression).  */
    6952                 :     8501993 :       if (sprime
    6953                 :    12218202 :           && TREE_CODE (sprime) == SSA_NAME
    6954                 :     8501993 :           && do_pre
    6955                 :      844010 :           && (flag_tree_loop_vectorize || flag_tree_parallelize_loops > 1)
    6956                 :      826959 :           && loop_outer (b->loop_father)
    6957                 :      356358 :           && has_zero_uses (sprime)
    6958                 :      182196 :           && bitmap_bit_p (inserted_exprs, SSA_NAME_VERSION (sprime))
    6959                 :      182041 :           && gimple_assign_load_p (stmt))
    6960                 :             :         {
    6961                 :       92046 :           gimple *def_stmt = SSA_NAME_DEF_STMT (sprime);
    6962                 :       92046 :           basic_block def_bb = gimple_bb (def_stmt);
    6963                 :       92046 :           if (gimple_code (def_stmt) == GIMPLE_PHI
    6964                 :       92046 :               && def_bb->loop_father->header == def_bb)
    6965                 :             :             {
    6966                 :       59050 :               loop_p loop = def_bb->loop_father;
    6967                 :       59050 :               ssa_op_iter iter;
    6968                 :       59050 :               tree op;
    6969                 :       59050 :               bool found = false;
    6970                 :       72869 :               FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
    6971                 :             :                 {
    6972                 :       55439 :                   affine_iv iv;
    6973                 :       55439 :                   def_bb = gimple_bb (SSA_NAME_DEF_STMT (op));
    6974                 :       55439 :                   if (def_bb
    6975                 :       51208 :                       && flow_bb_inside_loop_p (loop, def_bb)
    6976                 :      102170 :                       && simple_iv (loop, loop, op, &iv, true))
    6977                 :             :                     {
    6978                 :       41620 :                       found = true;
    6979                 :       41620 :                       break;
    6980                 :             :                     }
    6981                 :             :                 }
    6982                 :       17430 :               if (found)
    6983                 :             :                 {
    6984                 :       41620 :                   if (dump_file && (dump_flags & TDF_DETAILS))
    6985                 :             :                     {
    6986                 :           3 :                       fprintf (dump_file, "Not replacing ");
    6987                 :           3 :                       print_gimple_expr (dump_file, stmt, 0);
    6988                 :           3 :                       fprintf (dump_file, " with ");
    6989                 :           3 :                       print_generic_expr (dump_file, sprime);
    6990                 :           3 :                       fprintf (dump_file, " which would add a loop"
    6991                 :             :                                " carried dependence to loop %d\n",
    6992                 :             :                                loop->num);
    6993                 :             :                     }
    6994                 :             :                   /* Don't keep sprime available.  */
    6995                 :       41620 :                   sprime = NULL_TREE;
    6996                 :             :                 }
    6997                 :             :             }
    6998                 :             :         }
    6999                 :             : 
    7000                 :    76824049 :       if (sprime)
    7001                 :             :         {
    7002                 :             :           /* If we can propagate the value computed for LHS into
    7003                 :             :              all uses don't bother doing anything with this stmt.  */
    7004                 :    12176582 :           if (may_propagate_copy (lhs, sprime))
    7005                 :             :             {
    7006                 :             :               /* Mark it for removal.  */
    7007                 :    12174683 :               to_remove.safe_push (stmt);
    7008                 :             : 
    7009                 :             :               /* ???  Don't count copy/constant propagations.  */
    7010                 :    12174683 :               if (gimple_assign_single_p (stmt)
    7011                 :    12174683 :                   && (TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME
    7012                 :     3995127 :                       || gimple_assign_rhs1 (stmt) == sprime))
    7013                 :    12816945 :                 return;
    7014                 :             : 
    7015                 :     6864919 :               if (dump_file && (dump_flags & TDF_DETAILS))
    7016                 :             :                 {
    7017                 :       17305 :                   fprintf (dump_file, "Replaced ");
    7018                 :       17305 :                   print_gimple_expr (dump_file, stmt, 0);
    7019                 :       17305 :                   fprintf (dump_file, " with ");
    7020                 :       17305 :                   print_generic_expr (dump_file, sprime);
    7021                 :       17305 :                   fprintf (dump_file, " in all uses of ");
    7022                 :       17305 :                   print_gimple_stmt (dump_file, stmt, 0);
    7023                 :             :                 }
    7024                 :             : 
    7025                 :     6864919 :               eliminations++;
    7026                 :     6864919 :               return;
    7027                 :             :             }
    7028                 :             : 
    7029                 :             :           /* If this is an assignment from our leader (which
    7030                 :             :              happens in the case the value-number is a constant)
    7031                 :             :              then there is nothing to do.  Likewise if we run into
    7032                 :             :              inserted code that needed a conversion because of
    7033                 :             :              our type-agnostic value-numbering of loads.  */
    7034                 :        1899 :           if ((gimple_assign_single_p (stmt)
    7035                 :           1 :                || (is_gimple_assign (stmt)
    7036                 :           1 :                    && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))
    7037                 :           0 :                        || gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR)))
    7038                 :        1900 :               && sprime == gimple_assign_rhs1 (stmt))
    7039                 :             :             return;
    7040                 :             : 
    7041                 :             :           /* Else replace its RHS.  */
    7042                 :         711 :           if (dump_file && (dump_flags & TDF_DETAILS))
    7043                 :             :             {
    7044                 :           0 :               fprintf (dump_file, "Replaced ");
    7045                 :           0 :               print_gimple_expr (dump_file, stmt, 0);
    7046                 :           0 :               fprintf (dump_file, " with ");
    7047                 :           0 :               print_generic_expr (dump_file, sprime);
    7048                 :           0 :               fprintf (dump_file, " in ");
    7049                 :           0 :               print_gimple_stmt (dump_file, stmt, 0);
    7050                 :             :             }
    7051                 :         711 :           eliminations++;
    7052                 :             : 
    7053                 :         711 :           bool can_make_abnormal_goto = (is_gimple_call (stmt)
    7054                 :         711 :                                          && stmt_can_make_abnormal_goto (stmt));
    7055                 :         711 :           gimple *orig_stmt = stmt;
    7056                 :         711 :           if (!useless_type_conversion_p (TREE_TYPE (lhs),
    7057                 :         711 :                                           TREE_TYPE (sprime)))
    7058                 :             :             {
    7059                 :             :               /* We preserve conversions to but not from function or method
    7060                 :             :                  types.  This asymmetry makes it necessary to re-instantiate
    7061                 :             :                  conversions here.  */
    7062                 :         709 :               if (POINTER_TYPE_P (TREE_TYPE (lhs))
    7063                 :         709 :                   && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (lhs))))
    7064                 :         709 :                 sprime = fold_convert (TREE_TYPE (lhs), sprime);
    7065                 :             :               else
    7066                 :           0 :                 gcc_unreachable ();
    7067                 :             :             }
    7068                 :         711 :           tree vdef = gimple_vdef (stmt);
    7069                 :         711 :           tree vuse = gimple_vuse (stmt);
    7070                 :         711 :           propagate_tree_value_into_stmt (gsi, sprime);
    7071                 :         711 :           stmt = gsi_stmt (*gsi);
    7072                 :         711 :           update_stmt (stmt);
    7073                 :             :           /* In case the VDEF on the original stmt was released, value-number
    7074                 :             :              it to the VUSE.  This is to make vuse_ssa_val able to skip
    7075                 :             :              released virtual operands.  */
    7076                 :        1422 :           if (vdef != gimple_vdef (stmt))
    7077                 :             :             {
    7078                 :           0 :               gcc_assert (SSA_NAME_IN_FREE_LIST (vdef));
    7079                 :           0 :               VN_INFO (vdef)->valnum = vuse;
    7080                 :             :             }
    7081                 :             : 
    7082                 :             :           /* If we removed EH side-effects from the statement, clean
    7083                 :             :              its EH information.  */
    7084                 :         711 :           if (maybe_clean_or_replace_eh_stmt (orig_stmt, stmt))
    7085                 :             :             {
    7086                 :           0 :               bitmap_set_bit (need_eh_cleanup,
    7087                 :           0 :                               gimple_bb (stmt)->index);
    7088                 :           0 :               if (dump_file && (dump_flags & TDF_DETAILS))
    7089                 :           0 :                 fprintf (dump_file, "  Removed EH side-effects.\n");
    7090                 :             :             }
    7091                 :             : 
    7092                 :             :           /* Likewise for AB side-effects.  */
    7093                 :         711 :           if (can_make_abnormal_goto
    7094                 :         711 :               && !stmt_can_make_abnormal_goto (stmt))
    7095                 :             :             {
    7096                 :           0 :               bitmap_set_bit (need_ab_cleanup,
    7097                 :           0 :                               gimple_bb (stmt)->index);
    7098                 :           0 :               if (dump_file && (dump_flags & TDF_DETAILS))
    7099                 :           0 :                 fprintf (dump_file, "  Removed AB side-effects.\n");
    7100                 :             :             }
    7101                 :             : 
    7102                 :         711 :           return;
    7103                 :             :         }
    7104                 :             :     }
    7105                 :             : 
    7106                 :             :   /* If the statement is a scalar store, see if the expression
    7107                 :             :      has the same value number as its rhs.  If so, the store is
    7108                 :             :      dead.  */
    7109                 :   292591088 :   if (gimple_assign_single_p (stmt)
    7110                 :   118307632 :       && !gimple_has_volatile_ops (stmt)
    7111                 :    51074166 :       && !is_gimple_reg (gimple_assign_lhs (stmt))
    7112                 :    25873741 :       && (TREE_CODE (gimple_assign_lhs (stmt)) != VAR_DECL
    7113                 :     2486917 :           || !DECL_HARD_REGISTER (gimple_assign_lhs (stmt)))
    7114                 :   318460834 :       && (TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME
    7115                 :    14788017 :           || is_gimple_min_invariant (gimple_assign_rhs1 (stmt))))
    7116                 :             :     {
    7117                 :    23127071 :       tree rhs = gimple_assign_rhs1 (stmt);
    7118                 :    23127071 :       vn_reference_t vnresult;
    7119                 :             :       /* ???  gcc.dg/torture/pr91445.c shows that we lookup a boolean
    7120                 :             :          typed load of a byte known to be 0x11 as 1 so a store of
    7121                 :             :          a boolean 1 is detected as redundant.  Because of this we
    7122                 :             :          have to make sure to lookup with a ref where its size
    7123                 :             :          matches the precision.  */
    7124                 :    23127071 :       tree lookup_lhs = lhs;
    7125                 :    46014159 :       if (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    7126                 :    12015985 :           && (TREE_CODE (lhs) != COMPONENT_REF
    7127                 :     7769790 :               || !DECL_BIT_FIELD_TYPE (TREE_OPERAND (lhs, 1)))
    7128                 :    34966964 :           && !type_has_mode_precision_p (TREE_TYPE (lhs)))
    7129                 :             :         {
    7130                 :      415566 :           if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
    7131                 :      424526 :               && TYPE_PRECISION (TREE_TYPE (lhs)) > MAX_FIXED_MODE_SIZE)
    7132                 :             :             lookup_lhs = NULL_TREE;
    7133                 :      408764 :           else if (TREE_CODE (lhs) == COMPONENT_REF
    7134                 :      408764 :                    || TREE_CODE (lhs) == MEM_REF)
    7135                 :             :             {
    7136                 :      287925 :               tree ltype = build_nonstandard_integer_type
    7137                 :      287925 :                                 (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (lhs))),
    7138                 :      287925 :                                  TYPE_UNSIGNED (TREE_TYPE (lhs)));
    7139                 :      287925 :               if (TREE_CODE (lhs) == COMPONENT_REF)
    7140                 :             :                 {
    7141                 :      218389 :                   tree foff = component_ref_field_offset (lhs);
    7142                 :      218389 :                   tree f = TREE_OPERAND (lhs, 1);
    7143                 :      218389 :                   if (!poly_int_tree_p (foff))
    7144                 :             :                     lookup_lhs = NULL_TREE;
    7145                 :             :                   else
    7146                 :      436778 :                     lookup_lhs = build3 (BIT_FIELD_REF, ltype,
    7147                 :      218389 :                                          TREE_OPERAND (lhs, 0),
    7148                 :      218389 :                                          TYPE_SIZE (TREE_TYPE (lhs)),
    7149                 :             :                                          bit_from_pos
    7150                 :      218389 :                                            (foff, DECL_FIELD_BIT_OFFSET (f)));
    7151                 :             :                 }
    7152                 :             :               else
    7153                 :       69536 :                 lookup_lhs = build2 (MEM_REF, ltype,
    7154                 :       69536 :                                      TREE_OPERAND (lhs, 0),
    7155                 :       69536 :                                      TREE_OPERAND (lhs, 1));
    7156                 :             :             }
    7157                 :             :           else
    7158                 :             :             lookup_lhs = NULL_TREE;
    7159                 :             :         }
    7160                 :    22999430 :       tree val = NULL_TREE;
    7161                 :    22999430 :       if (lookup_lhs)
    7162                 :    45998860 :         val = vn_reference_lookup (lookup_lhs, gimple_vuse (stmt),
    7163                 :             :                                    VN_WALKREWRITE, &vnresult, false,
    7164                 :             :                                    NULL, NULL_TREE, true);
    7165                 :    23127071 :       if (TREE_CODE (rhs) == SSA_NAME)
    7166                 :    11081729 :         rhs = VN_INFO (rhs)->valnum;
    7167                 :    23127071 :       if (val
    7168                 :    23127071 :           && (operand_equal_p (val, rhs, 0)
    7169                 :             :               /* Due to the bitfield lookups above we can get bit
    7170                 :             :                  interpretations of the same RHS as values here.  Those
    7171                 :             :                  are redundant as well.  */
    7172                 :     2758855 :               || (TREE_CODE (val) == SSA_NAME
    7173                 :     1688364 :                   && gimple_assign_single_p (SSA_NAME_DEF_STMT (val))
    7174                 :     1528731 :                   && (val = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (val)))
    7175                 :     1528731 :                   && TREE_CODE (val) == VIEW_CONVERT_EXPR
    7176                 :        3292 :                   && TREE_OPERAND (val, 0) == rhs)))
    7177                 :             :         {
    7178                 :             :           /* We can only remove the later store if the former aliases
    7179                 :             :              at least all accesses the later one does or if the store
    7180                 :             :              was to readonly memory storing the same value.  */
    7181                 :      195762 :           ao_ref lhs_ref;
    7182                 :      195762 :           ao_ref_init (&lhs_ref, lhs);
    7183                 :      195762 :           alias_set_type set = ao_ref_alias_set (&lhs_ref);
    7184                 :      195762 :           alias_set_type base_set = ao_ref_base_alias_set (&lhs_ref);
    7185                 :      195762 :           if (! vnresult
    7186                 :      195762 :               || ((vnresult->set == set
    7187                 :       29092 :                    || alias_set_subset_of (set, vnresult->set))
    7188                 :      193515 :                   && (vnresult->base_set == base_set
    7189                 :        8716 :                       || alias_set_subset_of (base_set, vnresult->base_set))))
    7190                 :             :             {
    7191                 :      191055 :               if (dump_file && (dump_flags & TDF_DETAILS))
    7192                 :             :                 {
    7193                 :          16 :                   fprintf (dump_file, "Deleted redundant store ");
    7194                 :          16 :                   print_gimple_stmt (dump_file, stmt, 0);
    7195                 :             :                 }
    7196                 :             : 
    7197                 :             :               /* Queue stmt for removal.  */
    7198                 :      191055 :               to_remove.safe_push (stmt);
    7199                 :      191055 :               return;
    7200                 :             :             }
    7201                 :             :         }
    7202                 :             :     }
    7203                 :             : 
    7204                 :             :   /* If this is a control statement value numbering left edges
    7205                 :             :      unexecuted on force the condition in a way consistent with
    7206                 :             :      that.  */
    7207                 :   292400033 :   if (gcond *cond = dyn_cast <gcond *> (stmt))
    7208                 :             :     {
    7209                 :    17281395 :       if ((EDGE_SUCC (b, 0)->flags & EDGE_EXECUTABLE)
    7210                 :    17281395 :           ^ (EDGE_SUCC (b, 1)->flags & EDGE_EXECUTABLE))
    7211                 :             :         {
    7212                 :      449308 :           if (dump_file && (dump_flags & TDF_DETAILS))
    7213                 :             :             {
    7214                 :          15 :               fprintf (dump_file, "Removing unexecutable edge from ");
    7215                 :          15 :               print_gimple_stmt (dump_file, stmt, 0);
    7216                 :             :             }
    7217                 :      449308 :           if (((EDGE_SUCC (b, 0)->flags & EDGE_TRUE_VALUE) != 0)
    7218                 :      449308 :               == ((EDGE_SUCC (b, 0)->flags & EDGE_EXECUTABLE) != 0))
    7219                 :      138688 :             gimple_cond_make_true (cond);
    7220                 :             :           else
    7221                 :      310620 :             gimple_cond_make_false (cond);
    7222                 :      449308 :           update_stmt (cond);
    7223                 :      449308 :           el_todo |= TODO_cleanup_cfg;
    7224                 :      449308 :           return;
    7225                 :             :         }
    7226                 :             :     }
    7227                 :             : 
    7228                 :   291950725 :   bool can_make_abnormal_goto = stmt_can_make_abnormal_goto (stmt);
    7229                 :   291950725 :   bool was_noreturn = (is_gimple_call (stmt)
    7230                 :   291950725 :                        && gimple_call_noreturn_p (stmt));
    7231                 :   291950725 :   tree vdef = gimple_vdef (stmt);
    7232                 :   291950725 :   tree vuse = gimple_vuse (stmt);
    7233                 :             : 
    7234                 :             :   /* If we didn't replace the whole stmt (or propagate the result
    7235                 :             :      into all uses), replace all uses on this stmt with their
    7236                 :             :      leaders.  */
    7237                 :   291950725 :   bool modified = false;
    7238                 :   291950725 :   use_operand_p use_p;
    7239                 :   291950725 :   ssa_op_iter iter;
    7240                 :   441147989 :   FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
    7241                 :             :     {
    7242                 :   149197264 :       tree use = USE_FROM_PTR (use_p);
    7243                 :             :       /* ???  The call code above leaves stmt operands un-updated.  */
    7244                 :   149197264 :       if (TREE_CODE (use) != SSA_NAME)
    7245                 :           0 :         continue;
    7246                 :   149197264 :       tree sprime;
    7247                 :   149197264 :       if (SSA_NAME_IS_DEFAULT_DEF (use))
    7248                 :             :         /* ???  For default defs BB shouldn't matter, but we have to
    7249                 :             :            solve the inconsistency between rpo eliminate and
    7250                 :             :            dom eliminate avail valueization first.  */
    7251                 :    24340281 :         sprime = eliminate_avail (b, use);
    7252                 :             :       else
    7253                 :             :         /* Look for sth available at the definition block of the argument.
    7254                 :             :            This avoids inconsistencies between availability there which
    7255                 :             :            decides if the stmt can be removed and availability at the
    7256                 :             :            use site.  The SSA property ensures that things available
    7257                 :             :            at the definition are also available at uses.  */
    7258                 :   124856983 :         sprime = eliminate_avail (gimple_bb (SSA_NAME_DEF_STMT (use)), use);
    7259                 :   149197264 :       if (sprime && sprime != use
    7260                 :    10860748 :           && may_propagate_copy (use, sprime, true)
    7261                 :             :           /* We substitute into debug stmts to avoid excessive
    7262                 :             :              debug temporaries created by removed stmts, but we need
    7263                 :             :              to avoid doing so for inserted sprimes as we never want
    7264                 :             :              to create debug temporaries for them.  */
    7265                 :   160057303 :           && (!inserted_exprs
    7266                 :     1010514 :               || TREE_CODE (sprime) != SSA_NAME
    7267                 :      995861 :               || !is_gimple_debug (stmt)
    7268                 :      250468 :               || !bitmap_bit_p (inserted_exprs, SSA_NAME_VERSION (sprime))))
    7269                 :             :         {
    7270                 :    10630171 :           propagate_value (use_p, sprime);
    7271                 :    10630171 :           modified = true;
    7272                 :             :         }
    7273                 :             :     }
    7274                 :             : 
    7275                 :             :   /* Fold the stmt if modified, this canonicalizes MEM_REFs we propagated
    7276                 :             :      into which is a requirement for the IPA devirt machinery.  */
    7277                 :   291950725 :   gimple *old_stmt = stmt;
    7278                 :   291950725 :   if (modified)
    7279                 :             :     {
    7280                 :             :       /* If a formerly non-invariant ADDR_EXPR is turned into an
    7281                 :             :          invariant one it was on a separate stmt.  */
    7282                 :     9846122 :       if (gimple_assign_single_p (stmt)
    7283                 :     9846122 :           && TREE_CODE (gimple_assign_rhs1 (stmt)) == ADDR_EXPR)
    7284                 :      209996 :         recompute_tree_invariant_for_addr_expr (gimple_assign_rhs1 (stmt));
    7285                 :     9846122 :       gimple_stmt_iterator prev = *gsi;
    7286                 :     9846122 :       gsi_prev (&prev);
    7287                 :     9846122 :       if (fold_stmt (gsi, follow_all_ssa_edges))
    7288                 :             :         {
    7289                 :             :           /* fold_stmt may have created new stmts inbetween
    7290                 :             :              the previous stmt and the folded stmt.  Mark
    7291                 :             :              all defs created there as varying to not confuse
    7292                 :             :              the SCCVN machinery as we're using that even during
    7293                 :             :              elimination.  */
    7294                 :      882131 :           if (gsi_end_p (prev))
    7295                 :      214774 :             prev = gsi_start_bb (b);
    7296                 :             :           else
    7297                 :      774744 :             gsi_next (&prev);
    7298                 :      882131 :           if (gsi_stmt (prev) != gsi_stmt (*gsi))
    7299                 :      102207 :             do
    7300                 :             :               {
    7301                 :       64377 :                 tree def;
    7302                 :       64377 :                 ssa_op_iter dit;
    7303                 :      125257 :                 FOR_EACH_SSA_TREE_OPERAND (def, gsi_stmt (prev),
    7304                 :             :                                            dit, SSA_OP_ALL_DEFS)
    7305                 :             :                     /* As existing DEFs may move between stmts
    7306                 :             :                        only process new ones.  */
    7307                 :       60880 :                     if (! has_VN_INFO (def))
    7308                 :             :                       {
    7309                 :       37728 :                         vn_ssa_aux_t vn_info = VN_INFO (def);
    7310                 :       37728 :                         vn_info->valnum = def;
    7311                 :       37728 :                         vn_info->visited = true;
    7312                 :             :                       }
    7313                 :       64377 :                 if (gsi_stmt (prev) == gsi_stmt (*gsi))
    7314                 :             :                   break;
    7315                 :       37830 :                 gsi_next (&prev);
    7316                 :       37830 :               }
    7317                 :             :             while (1);
    7318                 :             :         }
    7319                 :     9846122 :       stmt = gsi_stmt (*gsi);
    7320                 :             :       /* In case we folded the stmt away schedule the NOP for removal.  */
    7321                 :     9846122 :       if (gimple_nop_p (stmt))
    7322                 :         770 :         to_remove.safe_push (stmt);
    7323                 :             :     }
    7324                 :             : 
    7325                 :             :   /* Visit indirect calls and turn them into direct calls if
    7326                 :             :      possible using the devirtualization machinery.  Do this before
    7327                 :             :      checking for required EH/abnormal/noreturn cleanup as devird
    7328                 :             :      may expose more of those.  */
    7329                 :   291950725 :   if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
    7330                 :             :     {
    7331                 :    20821401 :       tree fn = gimple_call_fn (call_stmt);
    7332                 :    20821401 :       if (fn
    7333                 :    20296820 :           && flag_devirtualize
    7334                 :    40401914 :           && virtual_method_call_p (fn))
    7335                 :             :         {
    7336                 :      174372 :           tree otr_type = obj_type_ref_class (fn);
    7337                 :      174372 :           unsigned HOST_WIDE_INT otr_tok
    7338                 :      174372 :               = tree_to_uhwi (OBJ_TYPE_REF_TOKEN (fn));
    7339                 :      174372 :           tree instance;
    7340                 :      174372 :           ipa_polymorphic_call_context context (current_function_decl,
    7341                 :      174372 :                                                 fn, stmt, &instance);
    7342                 :      174372 :           context.get_dynamic_type (instance, OBJ_TYPE_REF_OBJECT (fn),
    7343                 :             :                                     otr_type, stmt, NULL);
    7344                 :      174372 :           bool final;
    7345                 :      174372 :           vec <cgraph_node *> targets
    7346                 :      174372 :               = possible_polymorphic_call_targets (obj_type_ref_class (fn),
    7347                 :             :                                                    otr_tok, context, &final);
    7348                 :      174372 :           if (dump_file)
    7349                 :          22 :             dump_possible_polymorphic_call_targets (dump_file,
    7350                 :             :                                                     obj_type_ref_class (fn),
    7351                 :             :                                                     otr_tok, context);
    7352                 :      174643 :           if (final && targets.length () <= 1 && dbg_cnt (devirt))
    7353                 :             :             {
    7354                 :          70 :               tree fn;
    7355                 :          70 :               if (targets.length () == 1)
    7356                 :          70 :                 fn = targets[0]->decl;
    7357                 :             :               else
    7358                 :           0 :                 fn = builtin_decl_unreachable ();
    7359                 :          70 :               if (dump_enabled_p ())
    7360                 :             :                 {
    7361                 :           9 :                   dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, stmt,
    7362                 :             :                                    "converting indirect call to "
    7363                 :             :                                    "function %s\n",
    7364                 :           9 :                                    lang_hooks.decl_printable_name (fn, 2));
    7365                 :             :                 }
    7366                 :          70 :               gimple_call_set_fndecl (call_stmt, fn);
    7367                 :             :               /* If changing the call to __builtin_unreachable
    7368                 :             :                  or similar noreturn function, adjust gimple_call_fntype
    7369                 :             :                  too.  */
    7370                 :          70 :               if (gimple_call_noreturn_p (call_stmt)
    7371                 :           0 :                   && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fn)))
    7372                 :           0 :                   && TYPE_ARG_TYPES (TREE_TYPE (fn))
    7373                 :          70 :                   && (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fn)))
    7374                 :           0 :                       == void_type_node))
    7375                 :           0 :                 gimple_call_set_fntype (call_stmt, TREE_TYPE (fn));
    7376                 :          70 :               maybe_remove_unused_call_args (cfun, call_stmt);
    7377                 :          70 :               modified = true;
    7378                 :             :             }
    7379                 :             :         }
    7380                 :             :     }
    7381                 :             : 
    7382                 :   291950725 :   if (modified)
    7383                 :             :     {
    7384                 :             :       /* When changing a call into a noreturn call, cfg cleanup
    7385                 :             :          is needed to fix up the noreturn call.  */
    7386                 :     9846143 :       if (!was_noreturn
    7387                 :     9846143 :           && is_gimple_call (stmt) && gimple_call_noreturn_p (stmt))
    7388                 :          56 :         to_fixup.safe_push  (stmt);
    7389                 :             :       /* When changing a condition or switch into one we know what
    7390                 :             :          edge will be executed, schedule a cfg cleanup.  */
    7391                 :     9846143 :       if ((gimple_code (stmt) == GIMPLE_COND
    7392                 :     1308723 :            && (gimple_cond_true_p (as_a <gcond *> (stmt))
    7393                 :     1304646 :                || gimple_cond_false_p (as_a <gcond *> (stmt))))
    7394                 :    11148926 :           || (gimple_code (stmt) == GIMPLE_SWITCH
    7395                 :        7537 :               && TREE_CODE (gimple_switch_index
    7396                 :             :                             (as_a <gswitch *> (stmt))) == INTEGER_CST))
    7397                 :        7554 :         el_todo |= TODO_cleanup_cfg;
    7398                 :             :       /* If we removed EH side-effects from the statement, clean
    7399                 :             :          its EH information.  */
    7400                 :     9846143 :       if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
    7401                 :             :         {
    7402                 :         804 :           bitmap_set_bit (need_eh_cleanup,
    7403                 :         804 :                           gimple_bb (stmt)->index);
    7404                 :         804 :           if (dump_file && (dump_flags & TDF_DETAILS))
    7405                 :           0 :             fprintf (dump_file, "  Removed EH side-effects.\n");
    7406                 :             :         }
    7407                 :             :       /* Likewise for AB side-effects.  */
    7408                 :     9846143 :       if (can_make_abnormal_goto
    7409                 :     9846143 :           && !stmt_can_make_abnormal_goto (stmt))
    7410                 :             :         {
    7411                 :           0 :           bitmap_set_bit (need_ab_cleanup,
    7412                 :           0 :                           gimple_bb (stmt)->index);
    7413                 :           0 :           if (dump_file && (dump_flags & TDF_DETAILS))
    7414                 :           0 :             fprintf (dump_file, "  Removed AB side-effects.\n");
    7415                 :             :         }
    7416                 :     9846143 :       update_stmt (stmt);
    7417                 :             :       /* In case the VDEF on the original stmt was released, value-number
    7418                 :             :          it to the VUSE.  This is to make vuse_ssa_val able to skip
    7419                 :             :          released virtual operands.  */
    7420                 :    12715181 :       if (vdef && SSA_NAME_IN_FREE_LIST (vdef))
    7421                 :        1456 :         VN_INFO (vdef)->valnum = vuse;
    7422                 :             :     }
    7423                 :             : 
    7424                 :             :   /* Make new values available - for fully redundant LHS we
    7425                 :             :      continue with the next stmt above and skip this.
    7426                 :             :      But avoid picking up dead defs.  */
    7427                 :   291950725 :   tree def;
    7428                 :   357892888 :   FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_DEF)
    7429                 :    65942163 :     if (! has_zero_uses (def)
    7430                 :    65942163 :         || (inserted_exprs
    7431                 :      207219 :             && bitmap_bit_p (inserted_exprs, SSA_NAME_VERSION (def))))
    7432                 :    64691179 :       eliminate_push_avail (b, def);
    7433                 :             : }
    7434                 :             : 
    7435                 :             : /* Perform elimination for the basic-block B during the domwalk.  */
    7436                 :             : 
    7437                 :             : edge
    7438                 :    38424540 : eliminate_dom_walker::before_dom_children (basic_block b)
    7439                 :             : {
    7440                 :             :   /* Mark new bb.  */
    7441                 :    38424540 :   avail_stack.safe_push (NULL_TREE);
    7442                 :             : 
    7443                 :             :   /* Skip unreachable blocks marked unreachable during the SCCVN domwalk.  */
    7444                 :    38424540 :   if (!(b->flags & BB_EXECUTABLE))
    7445                 :             :     return NULL;
    7446                 :             : 
    7447                 :    34044687 :   vn_context_bb = b;
    7448                 :             : 
    7449                 :    45031607 :   for (gphi_iterator gsi = gsi_start_phis (b); !gsi_end_p (gsi);)
    7450                 :             :     {
    7451                 :    10986920 :       gphi *phi = gsi.phi ();
    7452                 :    10986920 :       tree res = PHI_RESULT (phi);
    7453                 :             : 
    7454                 :    21973840 :       if (virtual_operand_p (res))
    7455                 :             :         {
    7456                 :     5119985 :           gsi_next (&gsi);
    7457                 :     5119985 :           continue;
    7458                 :             :         }
    7459                 :             : 
    7460                 :     5866935 :       tree sprime = eliminate_avail (b, res);
    7461                 :     5866935 :       if (sprime
    7462                 :     5866935 :           && sprime != res)
    7463                 :             :         {
    7464                 :      459177 :           if (dump_file && (dump_flags & TDF_DETAILS))
    7465                 :             :             {
    7466                 :          22 :               fprintf (dump_file, "Replaced redundant PHI node defining ");
    7467                 :          22 :               print_generic_expr (dump_file, res);
    7468                 :          22 :               fprintf (dump_file, " with ");
    7469                 :          22 :               print_generic_expr (dump_file, sprime);
    7470                 :          22 :               fprintf (dump_file, "\n");
    7471                 :             :             }
    7472                 :             : 
    7473                 :             :           /* If we inserted this PHI node ourself, it's not an elimination.  */
    7474                 :      459177 :           if (! inserted_exprs
    7475                 :      560379 :               || ! bitmap_bit_p (inserted_exprs, SSA_NAME_VERSION (res)))
    7476                 :      436024 :             eliminations++;
    7477                 :             : 
    7478                 :             :           /* If we will propagate into all uses don't bother to do
    7479                 :             :              anything.  */
    7480                 :      459177 :           if (may_propagate_copy (res, sprime))
    7481                 :             :             {
    7482                 :             :               /* Mark the PHI for removal.  */
    7483                 :      459177 :               to_remove.safe_push (phi);
    7484                 :      459177 :               gsi_next (&gsi);
    7485                 :      459177 :               continue;
    7486                 :             :             }
    7487                 :             : 
    7488                 :           0 :           remove_phi_node (&gsi, false);
    7489                 :             : 
    7490                 :           0 :           if (!useless_type_conversion_p (TREE_TYPE (res), TREE_TYPE (sprime)))
    7491                 :           0 :             sprime = fold_convert (TREE_TYPE (res), sprime);
    7492                 :           0 :           gimple *stmt = gimple_build_assign (res, sprime);
    7493                 :           0 :           gimple_stmt_iterator gsi2 = gsi_after_labels (b);
    7494                 :           0 :           gsi_insert_before (&gsi2, stmt, GSI_NEW_STMT);
    7495                 :           0 :           continue;
    7496                 :           0 :         }
    7497                 :             : 
    7498                 :     5407758 :       eliminate_push_avail (b, res);
    7499                 :     5407758 :       gsi_next (&gsi);
    7500                 :             :     }
    7501                 :             : 
    7502                 :    68089374 :   for (gimple_stmt_iterator gsi = gsi_start_bb (b);
    7503                 :   247491175 :        !gsi_end_p (gsi);
    7504                 :   213446488 :        gsi_next (&gsi))
    7505                 :   213446488 :     eliminate_stmt (b, &gsi);
    7506                 :             : 
    7507                 :             :   /* Replace destination PHI arguments.  */
    7508                 :    34044687 :   edge_iterator ei;
    7509                 :    34044687 :   edge e;
    7510                 :    80389713 :   FOR_EACH_EDGE (e, ei, b->succs)
    7511                 :    46345026 :     if (e->flags & EDGE_EXECUTABLE)
    7512                 :    45948486 :       for (gphi_iterator gsi = gsi_start_phis (e->dest);
    7513                 :    73597207 :            !gsi_end_p (gsi);
    7514                 :    27648721 :            gsi_next (&gsi))
    7515                 :             :         {
    7516                 :    27648721 :           gphi *phi = gsi.phi ();
    7517                 :    27648721 :           use_operand_p use_p = PHI_ARG_DEF_PTR_FROM_EDGE (phi, e);
    7518                 :    27648721 :           tree arg = USE_FROM_PTR (use_p);
    7519                 :    45873104 :           if (TREE_CODE (arg) != SSA_NAME
    7520                 :    27648721 :               || virtual_operand_p (arg))
    7521                 :    18224383 :             continue;
    7522                 :     9424338 :           tree sprime = eliminate_avail (b, arg);
    7523                 :    18848676 :           if (sprime && may_propagate_copy (arg, sprime,
    7524                 :     9424338 :                                             !(e->flags & EDGE_ABNORMAL)))
    7525                 :     9414328 :             propagate_value (use_p, sprime);
    7526                 :             :         }
    7527                 :             : 
    7528                 :    34044687 :   vn_context_bb = NULL;
    7529                 :             : 
    7530                 :    34044687 :   return NULL;
    7531                 :             : }
    7532                 :             : 
    7533                 :             : /* Make no longer available leaders no longer available.  */
    7534                 :             : 
    7535                 :             : void
    7536                 :    38424540 : eliminate_dom_walker::after_dom_children (basic_block)
    7537                 :             : {
    7538                 :    38424540 :   tree entry;
    7539                 :    85811612 :   while ((entry = avail_stack.pop ()) != NULL_TREE)
    7540                 :             :     {
    7541                 :    47387072 :       tree valnum = VN_INFO (entry)->valnum;
    7542                 :    47387072 :       tree old = avail[SSA_NAME_VERSION (valnum)];
    7543                 :    47387072 :       if (old == entry)
    7544                 :    47345410 :         avail[SSA_NAME_VERSION (valnum)] = NULL_TREE;
    7545                 :             :       else
    7546                 :       41662 :         avail[SSA_NAME_VERSION (valnum)] = entry;
    7547                 :             :     }
    7548                 :    38424540 : }
    7549                 :             : 
    7550                 :             : /* Remove queued stmts and perform delayed cleanups.  */
    7551                 :             : 
    7552                 :             : unsigned
    7553                 :     5752569 : eliminate_dom_walker::eliminate_cleanup (bool region_p)
    7554                 :             : {
    7555                 :     5752569 :   statistics_counter_event (cfun, "Eliminated", eliminations);
    7556                 :     5752569 :   statistics_counter_event (cfun, "Insertions", insertions);
    7557                 :             : 
    7558                 :             :   /* We cannot remove stmts during BB walk, especially not release SSA
    7559                 :             :      names there as this confuses the VN machinery.  The stmts ending
    7560                 :             :      up in to_remove are either stores or simple copies.
    7561                 :             :      Remove stmts in reverse order to make debug stmt creation possible.  */
    7562                 :    31222821 :   while (!to_remove.is_empty ())
    7563                 :             :     {
    7564                 :    13965058 :       bool do_release_defs = true;
    7565                 :    13965058 :       gimple *stmt = to_remove.pop ();
    7566                 :             : 
    7567                 :             :       /* When we are value-numbering a region we do not require exit PHIs to
    7568                 :             :          be present so we have to make sure to deal with uses outside of the
    7569                 :             :          region of stmts that we thought are eliminated.
    7570                 :             :          ??? Note we may be confused by uses in dead regions we didn't run
    7571                 :             :          elimination on.  Rather than checking individual uses we accept
    7572                 :             :          dead copies to be generated here (gcc.c-torture/execute/20060905-1.c
    7573                 :             :          contains such example).  */
    7574                 :    13965058 :       if (region_p)
    7575                 :             :         {
    7576                 :     1503351 :           if (gphi *phi = dyn_cast <gphi *> (stmt))
    7577                 :             :             {
    7578                 :      976302 :               tree lhs = gimple_phi_result (phi);
    7579                 :      976302 :               if (!has_zero_uses (lhs))
    7580                 :             :                 {
    7581                 :       17993 :                   if (dump_file && (dump_flags & TDF_DETAILS))
    7582                 :           3 :                     fprintf (dump_file, "Keeping eliminated stmt live "
    7583                 :             :                              "as copy because of out-of-region uses\n");
    7584                 :       17993 :                   tree sprime = eliminate_avail (gimple_bb (stmt), lhs);
    7585                 :       17993 :                   gimple *copy = gimple_build_assign (lhs, sprime);
    7586                 :       17993 :                   gimple_stmt_iterator gsi
    7587                 :       17993 :                     = gsi_after_labels (gimple_bb (stmt));
    7588                 :       17993 :                   gsi_insert_before (&gsi, copy, GSI_SAME_STMT);
    7589                 :       17993 :                   do_release_defs = false;
    7590                 :             :                 }
    7591                 :             :             }
    7592                 :      527049 :           else if (tree lhs = gimple_get_lhs (stmt))
    7593                 :      527049 :             if (TREE_CODE (lhs) == SSA_NAME
    7594                 :      527049 :                 && !has_zero_uses (lhs))
    7595                 :             :               {
    7596                 :         761 :                 if (dump_file && (dump_flags & TDF_DETAILS))
    7597                 :           0 :                   fprintf (dump_file, "Keeping eliminated stmt live "
    7598                 :             :                            "as copy because of out-of-region uses\n");
    7599                 :         761 :                 tree sprime = eliminate_avail (gimple_bb (stmt), lhs);
    7600                 :         761 :                 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    7601                 :         761 :                 if (is_gimple_assign (stmt))
    7602                 :             :                   {
    7603                 :         761 :                     gimple_assign_set_rhs_from_tree (&gsi, sprime);
    7604                 :         761 :                     stmt = gsi_stmt (gsi);
    7605                 :         761 :                     update_stmt (stmt);
    7606                 :         761 :                     if (maybe_clean_or_replace_eh_stmt (stmt, stmt))
    7607                 :           0 :                       bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index);
    7608                 :         761 :                     continue;
    7609                 :             :                   }
    7610                 :             :                 else
    7611                 :             :                   {
    7612                 :           0 :                     gimple *copy = gimple_build_assign (lhs, sprime);
    7613                 :           0 :                     gsi_insert_before (&gsi, copy, GSI_SAME_STMT);
    7614                 :           0 :                     do_release_defs = false;
    7615                 :             :                   }
    7616                 :             :               }
    7617                 :             :         }
    7618                 :             : 
    7619                 :    13964297 :       if (dump_file && (dump_flags & TDF_DETAILS))
    7620                 :             :         {
    7621                 :       20166 :           fprintf (dump_file, "Removing dead stmt ");
    7622                 :       20166 :           print_gimple_stmt (dump_file, stmt, 0, TDF_NONE);
    7623                 :             :         }
    7624                 :             : 
    7625                 :    13964297 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    7626                 :    13964297 :       if (gimple_code (stmt) == GIMPLE_PHI)
    7627                 :     1598550 :         remove_phi_node (&gsi, do_release_defs);
    7628                 :             :       else
    7629                 :             :         {
    7630                 :    12365747 :           basic_block bb = gimple_bb (stmt);
    7631                 :    12365747 :           unlink_stmt_vdef (stmt);
    7632                 :    12365747 :           if (gsi_remove (&gsi, true))
    7633                 :       26455 :             bitmap_set_bit (need_eh_cleanup, bb->index);
    7634                 :    12365747 :           if (is_gimple_call (stmt) && stmt_can_make_abnormal_goto (stmt))
    7635                 :           2 :             bitmap_set_bit (need_ab_cleanup, bb->index);
    7636                 :    12365747 :           if (do_release_defs)
    7637                 :    12365747 :             release_defs (stmt);
    7638                 :             :         }
    7639                 :             : 
    7640                 :             :       /* Removing a stmt may expose a forwarder block.  */
    7641                 :    13964297 :       el_todo |= TODO_cleanup_cfg;
    7642                 :             :     }
    7643                 :             : 
    7644                 :             :   /* Fixup stmts that became noreturn calls.  This may require splitting
    7645                 :             :      blocks and thus isn't possible during the dominator walk.  Do this
    7646                 :             :      in reverse order so we don't inadvertedly remove a stmt we want to
    7647                 :             :      fixup by visiting a dominating now noreturn call first.  */
    7648                 :     5752625 :   while (!to_fixup.is_empty ())
    7649                 :             :     {
    7650                 :          56 :       gimple *stmt = to_fixup.pop ();
    7651                 :             : 
    7652                 :          56 :       if (dump_file && (dump_flags & TDF_DETAILS))
    7653                 :             :         {
    7654                 :           0 :           fprintf (dump_file, "Fixing up noreturn call ");
    7655                 :           0 :           print_gimple_stmt (dump_file, stmt, 0);
    7656                 :             :         }
    7657                 :             : 
    7658                 :          56 :       if (fixup_noreturn_call (stmt))
    7659                 :          56 :         el_todo |= TODO_cleanup_cfg;
    7660                 :             :     }
    7661                 :             : 
    7662                 :     5752569 :   bool do_eh_cleanup = !bitmap_empty_p (need_eh_cleanup);
    7663                 :     5752569 :   bool do_ab_cleanup = !bitmap_empty_p (need_ab_cleanup);
    7664                 :             : 
    7665                 :     5752569 :   if (do_eh_cleanup)
    7666                 :       10334 :     gimple_purge_all_dead_eh_edges (need_eh_cleanup);
    7667                 :             : 
    7668                 :     5752569 :   if (do_ab_cleanup)
    7669                 :           2 :     gimple_purge_all_dead_abnormal_call_edges (need_ab_cleanup);
    7670                 :             : 
    7671                 :     5752569 :   if (do_eh_cleanup || do_ab_cleanup)
    7672                 :       10336 :     el_todo |= TODO_cleanup_cfg;
    7673                 :             : 
    7674                 :     5752569 :   return el_todo;
    7675                 :             : }
    7676                 :             : 
    7677                 :             : /* Eliminate fully redundant computations.  */
    7678                 :             : 
    7679                 :             : unsigned
    7680                 :     4010065 : eliminate_with_rpo_vn (bitmap inserted_exprs)
    7681                 :             : {
    7682                 :     4010065 :   eliminate_dom_walker walker (CDI_DOMINATORS, inserted_exprs);
    7683                 :             : 
    7684                 :     4010065 :   eliminate_dom_walker *saved_rpo_avail = rpo_avail;
    7685                 :     4010065 :   rpo_avail = &walker;
    7686                 :     4010065 :   walker.walk (cfun->cfg->x_entry_block_ptr);
    7687                 :     4010065 :   rpo_avail = saved_rpo_avail;
    7688                 :             : 
    7689                 :     4010065 :   return walker.eliminate_cleanup ();
    7690                 :     4010065 : }
    7691                 :             : 
    7692                 :             : static unsigned
    7693                 :             : do_rpo_vn_1 (function *fn, edge entry, bitmap exit_bbs,
    7694                 :             :              bool iterate, bool eliminate, bool skip_entry_phis,
    7695                 :             :              vn_lookup_kind kind);
    7696                 :             : 
    7697                 :             : void
    7698                 :      927955 : run_rpo_vn (vn_lookup_kind kind)
    7699                 :             : {
    7700                 :      927955 :   do_rpo_vn_1 (cfun, NULL, NULL, true, false, false, kind);
    7701                 :             : 
    7702                 :             :   /* ???  Prune requirement of these.  */
    7703                 :      927955 :   constant_to_value_id = new hash_table<vn_constant_hasher> (23);
    7704                 :             : 
    7705                 :             :   /* Initialize the value ids and prune out remaining VN_TOPs
    7706                 :             :      from dead code.  */
    7707                 :      927955 :   tree name;
    7708                 :      927955 :   unsigned i;
    7709                 :    43403269 :   FOR_EACH_SSA_NAME (i, name, cfun)
    7710                 :             :     {
    7711                 :    31878395 :       vn_ssa_aux_t info = VN_INFO (name);
    7712                 :    31878395 :       if (!info->visited
    7713                 :    31812796 :           || info->valnum == VN_TOP)
    7714                 :       65599 :         info->valnum = name;
    7715                 :    31878395 :       if (info->valnum == name)
    7716                 :    30789012 :         info->value_id = get_next_value_id ();
    7717                 :     1089383 :       else if (is_gimple_min_invariant (info->valnum))
    7718                 :       39471 :         info->value_id = get_or_alloc_constant_value_id (info->valnum);
    7719                 :             :     }
    7720                 :             : 
    7721                 :             :   /* Propagate.  */
    7722                 :    43403269 :   FOR_EACH_SSA_NAME (i, name, cfun)
    7723                 :             :     {
    7724                 :    31878395 :       vn_ssa_aux_t info = VN_INFO (name);
    7725                 :    31878395 :       if (TREE_CODE (info->valnum) == SSA_NAME
    7726                 :    31838924 :           && info->valnum != name
    7727                 :    32928307 :           && info->value_id != VN_INFO (info->valnum)->value_id)
    7728                 :     1049912 :         info->value_id = VN_INFO (info->valnum)->value_id;
    7729                 :             :     }
    7730                 :             : 
    7731                 :      927955 :   set_hashtable_value_ids ();
    7732                 :             : 
    7733                 :      927955 :   if (dump_file && (dump_flags & TDF_DETAILS))
    7734                 :             :     {
    7735                 :          14 :       fprintf (dump_file, "Value numbers:\n");
    7736                 :         407 :       FOR_EACH_SSA_NAME (i, name, cfun)
    7737                 :             :         {
    7738                 :         308 :           if (VN_INFO (name)->visited
    7739                 :         308 :               && SSA_VAL (name) != name)
    7740                 :             :             {
    7741                 :          33 :               print_generic_expr (dump_file, name);
    7742                 :          33 :               fprintf (dump_file, " = ");
    7743                 :          33 :               print_generic_expr (dump_file, SSA_VAL (name));
    7744                 :          33 :               fprintf (dump_file, " (%04d)\n", VN_INFO (name)->value_id);
    7745                 :             :             }
    7746                 :             :         }
    7747                 :             :     }
    7748                 :      927955 : }
    7749                 :             : 
    7750                 :             : /* Free VN associated data structures.  */
    7751                 :             : 
    7752                 :             : void
    7753                 :     5771874 : free_rpo_vn (void)
    7754                 :             : {
    7755                 :     5771874 :   free_vn_table (valid_info);
    7756                 :     5771874 :   XDELETE (valid_info);
    7757                 :     5771874 :   obstack_free (&vn_tables_obstack, NULL);
    7758                 :     5771874 :   obstack_free (&vn_tables_insert_obstack, NULL);
    7759                 :             : 
    7760                 :     5771874 :   vn_ssa_aux_iterator_type it;
    7761                 :     5771874 :   vn_ssa_aux_t info;
    7762                 :   328196248 :   FOR_EACH_HASH_TABLE_ELEMENT (*vn_ssa_aux_hash, info, vn_ssa_aux_t, it)
    7763                 :   161212187 :     if (info->needs_insertion)
    7764                 :     3800344 :       release_ssa_name (info->name);
    7765                 :     5771874 :   obstack_free (&vn_ssa_aux_obstack, NULL);
    7766                 :     5771874 :   delete vn_ssa_aux_hash;
    7767                 :             : 
    7768                 :     5771874 :   delete constant_to_value_id;
    7769                 :     5771874 :   constant_to_value_id = NULL;
    7770                 :     5771874 : }
    7771                 :             : 
    7772                 :             : /* Hook for maybe_push_res_to_seq, lookup the expression in the VN tables.  */
    7773                 :             : 
    7774                 :             : static tree
    7775                 :    22157396 : vn_lookup_simplify_result (gimple_match_op *res_op)
    7776                 :             : {
    7777                 :    22157396 :   if (!res_op->code.is_tree_code ())
    7778                 :             :     return NULL_TREE;
    7779                 :    22155019 :   tree *ops = res_op->ops;
    7780                 :    22155019 :   unsigned int length = res_op->num_ops;
    7781                 :    22155019 :   if (res_op->code == CONSTRUCTOR
    7782                 :             :       /* ???  We're arriving here with SCCVNs view, decomposed CONSTRUCTOR
    7783                 :             :          and GIMPLEs / match-and-simplifies, CONSTRUCTOR as GENERIC tree.  */
    7784                 :    22155019 :       && TREE_CODE (res_op->ops[0]) == CONSTRUCTOR)
    7785                 :             :     {
    7786                 :        1133 :       length = CONSTRUCTOR_NELTS (res_op->ops[0]);
    7787                 :        1133 :       ops = XALLOCAVEC (tree, length);
    7788                 :        5735 :       for (unsigned i = 0; i < length; ++i)
    7789                 :        4602 :         ops[i] = CONSTRUCTOR_ELT (res_op->ops[0], i)->value;
    7790                 :             :     }
    7791                 :    22155019 :   vn_nary_op_t vnresult = NULL;
    7792                 :    22155019 :   tree res = vn_nary_op_lookup_pieces (length, (tree_code) res_op->code,
    7793                 :             :                                        res_op->type, ops, &vnresult);
    7794                 :             :   /* If this is used from expression simplification make sure to
    7795                 :             :      return an available expression.  */
    7796                 :    22155019 :   if (res && TREE_CODE (res) == SSA_NAME && mprts_hook && rpo_avail)
    7797                 :     2080500 :     res = rpo_avail->eliminate_avail (vn_context_bb, res);
    7798                 :             :   return res;
    7799                 :             : }
    7800                 :             : 
    7801                 :             : /* Return a leader for OPs value that is valid at BB.  */
    7802                 :             : 
    7803                 :             : tree
    7804                 :   240900751 : rpo_elim::eliminate_avail (basic_block bb, tree op)
    7805                 :             : {
    7806                 :   240900751 :   bool visited;
    7807                 :   240900751 :   tree valnum = SSA_VAL (op, &visited);
    7808                 :             :   /* If we didn't visit OP then it must be defined outside of the
    7809                 :             :      region we process and also dominate it.  So it is available.  */
    7810                 :   240900751 :   if (!visited)
    7811                 :             :     return op;
    7812                 :   238924713 :   if (TREE_CODE (valnum) == SSA_NAME)
    7813                 :             :     {
    7814                 :   226060645 :       if (SSA_NAME_IS_DEFAULT_DEF (valnum))
    7815                 :             :         return valnum;
    7816                 :   219810837 :       vn_ssa_aux_t valnum_info = VN_INFO (valnum);
    7817                 :   219810837 :       vn_avail *av = valnum_info->avail;
    7818                 :   219810837 :       if (!av)
    7819                 :             :         {
    7820                 :             :           /* See above.  But when there's availability info prefer
    7821                 :             :              what we recorded there for example to preserve LC SSA.  */
    7822                 :    78657556 :           if (!valnum_info->visited)
    7823                 :             :             return valnum;
    7824                 :             :           return NULL_TREE;
    7825                 :             :         }
    7826                 :   141153281 :       if (av->location == bb->index)
    7827                 :             :         /* On tramp3d 90% of the cases are here.  */
    7828                 :    95070099 :         return ssa_name (av->leader);
    7829                 :    59624277 :       do
    7830                 :             :         {
    7831                 :    59624277 :           basic_block abb = BASIC_BLOCK_FOR_FN (cfun, av->location);
    7832                 :             :           /* ???  During elimination we have to use availability at the
    7833                 :             :              definition site of a use we try to replace.  This
    7834                 :             :              is required to not run into inconsistencies because
    7835                 :             :              of dominated_by_p_w_unex behavior and removing a definition
    7836                 :             :              while not replacing all uses.
    7837                 :             :              ???  We could try to consistently walk dominators
    7838                 :             :              ignoring non-executable regions.  The nearest common
    7839                 :             :              dominator of bb and abb is where we can stop walking.  We
    7840                 :             :              may also be able to "pre-compute" (bits of) the next immediate
    7841                 :             :              (non-)dominator during the RPO walk when marking edges as
    7842                 :             :              executable.  */
    7843                 :    59624277 :           if (dominated_by_p_w_unex (bb, abb, true))
    7844                 :             :             {
    7845                 :    42534061 :               tree leader = ssa_name (av->leader);
    7846                 :             :               /* Prevent eliminations that break loop-closed SSA.  */
    7847                 :    42534061 :               if (loops_state_satisfies_p (LOOP_CLOSED_SSA)
    7848                 :     2780577 :                   && ! SSA_NAME_IS_DEFAULT_DEF (leader)
    7849                 :    45314638 :                   && ! flow_bb_inside_loop_p (gimple_bb (SSA_NAME_DEF_STMT
    7850                 :     2780577 :                                                          (leader))->loop_father,
    7851                 :             :                                               bb))
    7852                 :             :                 return NULL_TREE;
    7853                 :    42437390 :               if (dump_file && (dump_flags & TDF_DETAILS))
    7854                 :             :                 {
    7855                 :        3369 :                   print_generic_expr (dump_file, leader);
    7856                 :        3369 :                   fprintf (dump_file, " is available for ");
    7857                 :        3369 :                   print_generic_expr (dump_file, valnum);
    7858                 :        3369 :                   fprintf (dump_file, "\n");
    7859                 :             :                 }
    7860                 :             :               /* On tramp3d 99% of the _remaining_ cases succeed at
    7861                 :             :                  the first enty.  */
    7862                 :    42437390 :               return leader;
    7863                 :             :             }
    7864                 :             :           /* ???  Can we somehow skip to the immediate dominator
    7865                 :             :              RPO index (bb_to_rpo)?  Again, maybe not worth, on
    7866                 :             :              tramp3d the worst number of elements in the vector is 9.  */
    7867                 :    17090216 :           av = av->next;
    7868                 :             :         }
    7869                 :    17090216 :       while (av);
    7870                 :             :       /* While we prefer avail we have to fallback to using the value
    7871                 :             :          directly if defined outside of the region when none of the
    7872                 :             :          available defs suit.  */
    7873                 :     3549121 :       if (!valnum_info->visited)
    7874                 :             :         return valnum;
    7875                 :             :     }
    7876                 :    12864068 :   else if (valnum != VN_TOP)
    7877                 :             :     /* valnum is is_gimple_min_invariant.  */
    7878                 :             :     return valnum;
    7879                 :             :   return NULL_TREE;
    7880                 :             : }
    7881                 :             : 
    7882                 :             : /* Make LEADER a leader for its value at BB.  */
    7883                 :             : 
    7884                 :             : void
    7885                 :    91223227 : rpo_elim::eliminate_push_avail (basic_block bb, tree leader)
    7886                 :             : {
    7887                 :    91223227 :   tree valnum = VN_INFO (leader)->valnum;
    7888                 :    91223227 :   if (valnum == VN_TOP
    7889                 :    91223227 :       || is_gimple_min_invariant (valnum))
    7890                 :           0 :     return;
    7891                 :    91223227 :   if (dump_file && (dump_flags & TDF_DETAILS))
    7892                 :             :     {
    7893                 :      284760 :       fprintf (dump_file, "Making available beyond BB%d ", bb->index);
    7894                 :      284760 :       print_generic_expr (dump_file, leader);
    7895                 :      284760 :       fprintf (dump_file, " for value ");
    7896                 :      284760 :       print_generic_expr (dump_file, valnum);
    7897                 :      284760 :       fprintf (dump_file, "\n");
    7898                 :             :     }
    7899                 :    91223227 :   vn_ssa_aux_t value = VN_INFO (valnum);
    7900                 :    91223227 :   vn_avail *av;
    7901                 :    91223227 :   if (m_avail_freelist)
    7902                 :             :     {
    7903                 :    17764665 :       av = m_avail_freelist;
    7904                 :    17764665 :       m_avail_freelist = m_avail_freelist->next;
    7905                 :             :     }
    7906                 :             :   else
    7907                 :    73458562 :     av = XOBNEW (&vn_ssa_aux_obstack, vn_avail);
    7908                 :    91223227 :   av->location = bb->index;
    7909                 :    91223227 :   av->leader = SSA_NAME_VERSION (leader);
    7910                 :    91223227 :   av->next = value->avail;
    7911                 :    91223227 :   av->next_undo = last_pushed_avail;
    7912                 :    91223227 :   last_pushed_avail = value;
    7913                 :    91223227 :   value->avail = av;
    7914                 :             : }
    7915                 :             : 
    7916                 :             : /* Valueization hook for RPO VN plus required state.  */
    7917                 :             : 
    7918                 :             : tree
    7919                 :  1758926894 : rpo_vn_valueize (tree name)
    7920                 :             : {
    7921                 :  1758926894 :   if (TREE_CODE (name) == SSA_NAME)
    7922                 :             :     {
    7923                 :  1714895948 :       vn_ssa_aux_t val = VN_INFO (name);
    7924                 :  1714895948 :       if (val)
    7925                 :             :         {
    7926                 :  1714895948 :           tree tem = val->valnum;
    7927                 :  1714895948 :           if (tem != VN_TOP && tem != name)
    7928                 :             :             {
    7929                 :    93232417 :               if (TREE_CODE (tem) != SSA_NAME)
    7930                 :             :                 return tem;
    7931                 :             :               /* For all values we only valueize to an available leader
    7932                 :             :                  which means we can use SSA name info without restriction.  */
    7933                 :    77715758 :               tem = rpo_avail->eliminate_avail (vn_context_bb, tem);
    7934                 :    77715758 :               if (tem)
    7935                 :             :                 return tem;
    7936                 :             :             }
    7937                 :             :         }
    7938                 :             :     }
    7939                 :             :   return name;
    7940                 :             : }
    7941                 :             : 
    7942                 :             : /* Insert on PRED_E predicates derived from CODE OPS being true besides the
    7943                 :             :    inverted condition.  */
    7944                 :             : 
    7945                 :             : static void
    7946                 :    25606640 : insert_related_predicates_on_edge (enum tree_code code, tree *ops, edge pred_e)
    7947                 :             : {
    7948                 :    25606640 :   switch (code)
    7949                 :             :     {
    7950                 :     1257383 :     case LT_EXPR:
    7951                 :             :       /* a < b -> a {!,<}= b */
    7952                 :     1257383 :       vn_nary_op_insert_pieces_predicated (2, NE_EXPR, boolean_type_node,
    7953                 :             :                                            ops, boolean_true_node, 0, pred_e);
    7954                 :     1257383 :       vn_nary_op_insert_pieces_predicated (2, LE_EXPR, boolean_type_node,
    7955                 :             :                                            ops, boolean_true_node, 0, pred_e);
    7956                 :             :       /* a < b -> ! a {>,=} b */
    7957                 :     1257383 :       vn_nary_op_insert_pieces_predicated (2, GT_EXPR, boolean_type_node,
    7958                 :             :                                            ops, boolean_false_node, 0, pred_e);
    7959                 :     1257383 :       vn_nary_op_insert_pieces_predicated (2, EQ_EXPR, boolean_type_node,
    7960                 :             :                                            ops, boolean_false_node, 0, pred_e);
    7961                 :     1257383 :       break;
    7962                 :     3119816 :     case GT_EXPR:
    7963                 :             :       /* a > b -> a {!,>}= b */
    7964                 :     3119816 :       vn_nary_op_insert_pieces_predicated (2, NE_EXPR, boolean_type_node,
    7965                 :             :                                            ops, boolean_true_node, 0, pred_e);
    7966                 :     3119816 :       vn_nary_op_insert_pieces_predicated (2, GE_EXPR, boolean_type_node,
    7967                 :             :                                            ops, boolean_true_node, 0, pred_e);
    7968                 :             :       /* a > b -> ! a {<,=} b */
    7969                 :     3119816 :       vn_nary_op_insert_pieces_predicated (2, LT_EXPR, boolean_type_node,
    7970                 :             :                                            ops, boolean_false_node, 0, pred_e);
    7971                 :     3119816 :       vn_nary_op_insert_pieces_predicated (2, EQ_EXPR, boolean_type_node,
    7972                 :             :                                            ops, boolean_false_node, 0, pred_e);
    7973                 :     3119816 :       break;
    7974                 :     8879966 :     case EQ_EXPR:
    7975                 :             :       /* a == b -> ! a {<,>} b */
    7976                 :     8879966 :       vn_nary_op_insert_pieces_predicated (2, LT_EXPR, boolean_type_node,
    7977                 :             :                                            ops, boolean_false_node, 0, pred_e);
    7978                 :     8879966 :       vn_nary_op_insert_pieces_predicated (2, GT_EXPR, boolean_type_node,
    7979                 :             :                                            ops, boolean_false_node, 0, pred_e);
    7980                 :     8879966 :       break;
    7981                 :             :     case LE_EXPR:
    7982                 :             :     case GE_EXPR:
    7983                 :             :     case NE_EXPR:
    7984                 :             :       /* Nothing besides inverted condition.  */
    7985                 :             :       break;
    7986                 :    25606640 :     default:;
    7987                 :             :     }
    7988                 :    25606640 : }
    7989                 :             : 
    7990                 :             : /* Insert on the TRUE_E true and FALSE_E false predicates
    7991                 :             :    derived from LHS CODE RHS.  */
    7992                 :             : 
    7993                 :             : static void
    7994                 :    21539628 : insert_predicates_for_cond (tree_code code, tree lhs, tree rhs,
    7995                 :             :                             edge true_e, edge false_e)
    7996                 :             : {
    7997                 :             :   /* If both edges are null, then there is nothing to be done. */
    7998                 :    21539628 :   if (!true_e && !false_e)
    7999                 :     1443506 :     return;
    8000                 :             : 
    8001                 :             :   /* Canonicalize the comparison if needed, putting
    8002                 :             :      the constant in the rhs.  */
    8003                 :    20363170 :   if (tree_swap_operands_p (lhs, rhs))
    8004                 :             :     {
    8005                 :       18117 :       std::swap (lhs, rhs);
    8006                 :       18117 :       code = swap_tree_comparison (code);
    8007                 :             :     }
    8008                 :             : 
    8009                 :             :   /* If the lhs is not a ssa name, don't record anything. */
    8010                 :    20363170 :   if (TREE_CODE (lhs) != SSA_NAME)
    8011                 :             :     return;
    8012                 :             : 
    8013                 :    20096122 :   tree_code icode = invert_tree_comparison (code, HONOR_NANS (lhs));
    8014                 :    20096122 :   tree ops[2];
    8015                 :    20096122 :   ops[0] = lhs;
    8016                 :    20096122 :   ops[1] = rhs;
    8017                 :    20096122 :   if (true_e)
    8018                 :    16314892 :     vn_nary_op_insert_pieces_predicated (2, code, boolean_type_node, ops,
    8019                 :             :                                          boolean_true_node, 0, true_e);
    8020                 :    20096122 :   if (false_e)
    8021                 :    15587454 :     vn_nary_op_insert_pieces_predicated (2, code, boolean_type_node, ops,
    8022                 :             :                                          boolean_false_node, 0, false_e);
    8023                 :    20096122 :   if (icode != ERROR_MARK)
    8024                 :             :     {
    8025                 :    19852462 :       if (true_e)
    8026                 :    16167699 :         vn_nary_op_insert_pieces_predicated (2, icode, boolean_type_node, ops,
    8027                 :             :                                              boolean_false_node, 0, true_e);
    8028                 :    19852462 :       if (false_e)
    8029                 :    15387962 :         vn_nary_op_insert_pieces_predicated (2, icode, boolean_type_node, ops,
    8030                 :             :                                              boolean_true_node, 0, false_e);
    8031                 :             :     }
    8032                 :             :   /* Relax for non-integers, inverted condition handled
    8033                 :             :      above.  */
    8034                 :    20096122 :   if (INTEGRAL_TYPE_P (TREE_TYPE (lhs)))
    8035                 :             :     {
    8036                 :    16058553 :       if (true_e)
    8037                 :    13209993 :         insert_related_predicates_on_edge (code, ops, true_e);
    8038                 :    16058553 :       if (false_e)
    8039                 :    12396647 :         insert_related_predicates_on_edge (icode, ops, false_e);
    8040                 :             :   }
    8041                 :    20096122 :   if (integer_zerop (rhs)
    8042                 :    20096122 :       && (code == NE_EXPR || code == EQ_EXPR))
    8043                 :             :     {
    8044                 :     8669291 :       gimple *def_stmt = SSA_NAME_DEF_STMT (lhs);
    8045                 :             :       /* (A CMP B) != 0 is the same as (A CMP B).
    8046                 :             :          (A CMP B) == 0 is just (A CMP B) with the edges swapped.  */
    8047                 :     8669291 :       if (is_gimple_assign (def_stmt)
    8048                 :     8669291 :           && TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) == tcc_comparison)
    8049                 :             :           {
    8050                 :      449205 :             tree_code nc = gimple_assign_rhs_code (def_stmt);
    8051                 :      449205 :             tree nlhs = vn_valueize (gimple_assign_rhs1 (def_stmt));
    8052                 :      449205 :             tree nrhs = vn_valueize (gimple_assign_rhs2 (def_stmt));
    8053                 :      449205 :             edge nt = true_e;
    8054                 :      449205 :             edge nf = false_e;
    8055                 :      449205 :             if (code == EQ_EXPR)
    8056                 :      325376 :               std::swap (nt, nf);
    8057                 :      449205 :             if (lhs != nlhs)
    8058                 :      449205 :               insert_predicates_for_cond (nc, nlhs, nrhs, nt, nf);
    8059                 :             :           }
    8060                 :             :       /* (a | b) == 0 ->
    8061                 :             :             on true edge assert: a == 0 & b == 0. */
    8062                 :             :       /* (a | b) != 0 ->
    8063                 :             :             on false edge assert: a == 0 & b == 0. */
    8064                 :     8669291 :       if (is_gimple_assign (def_stmt)
    8065                 :     8669291 :           && gimple_assign_rhs_code (def_stmt) == BIT_IOR_EXPR)
    8066                 :             :         {
    8067                 :      268100 :           edge e = code == EQ_EXPR ? true_e : false_e;
    8068                 :      268100 :           tree nlhs;
    8069                 :             : 
    8070                 :      268100 :           nlhs = vn_valueize (gimple_assign_rhs1 (def_stmt));
    8071                 :             :           /* A valueization of the `a` might return the old lhs
    8072                 :             :              which is already handled above. */
    8073                 :      268100 :           if (nlhs != lhs)
    8074                 :      268100 :             insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr);
    8075                 :             : 
    8076                 :             :           /* A valueization of the `b` might return the old lhs
    8077                 :             :              which is already handled above. */
    8078                 :      268100 :           nlhs = vn_valueize (gimple_assign_rhs2 (def_stmt));
    8079                 :      268100 :           if (nlhs != lhs)
    8080                 :      268100 :             insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr);
    8081                 :             :         }
    8082                 :             :     }
    8083                 :             : }
    8084                 :             : 
    8085                 :             : /* Main stmt worker for RPO VN, process BB.  */
    8086                 :             : 
    8087                 :             : static unsigned
    8088                 :    57613791 : process_bb (rpo_elim &avail, basic_block bb,
    8089                 :             :             bool bb_visited, bool iterate_phis, bool iterate, bool eliminate,
    8090                 :             :             bool do_region, bitmap exit_bbs, bool skip_phis)
    8091                 :             : {
    8092                 :    57613791 :   unsigned todo = 0;
    8093                 :    57613791 :   edge_iterator ei;
    8094                 :    57613791 :   edge e;
    8095                 :             : 
    8096                 :    57613791 :   vn_context_bb = bb;
    8097                 :             : 
    8098                 :             :   /* If we are in loop-closed SSA preserve this state.  This is
    8099                 :             :      relevant when called on regions from outside of FRE/PRE.  */
    8100                 :    57613791 :   bool lc_phi_nodes = false;
    8101                 :    57613791 :   if (!skip_phis
    8102                 :    57613791 :       && loops_state_satisfies_p (LOOP_CLOSED_SSA))
    8103                 :     3327397 :     FOR_EACH_EDGE (e, ei, bb->preds)
    8104                 :     2019845 :       if (e->src->loop_father != e->dest->loop_father
    8105                 :     2019845 :           && flow_loop_nested_p (e->dest->loop_father,
    8106                 :             :                                  e->src->loop_father))
    8107                 :             :         {
    8108                 :             :           lc_phi_nodes = true;
    8109                 :             :           break;
    8110                 :             :         }
    8111                 :             : 
    8112                 :             :   /* When we visit a loop header substitute into loop info.  */
    8113                 :    57613791 :   if (!iterate && eliminate && bb->loop_father->header == bb)
    8114                 :             :     {
    8115                 :             :       /* Keep fields in sync with substitute_in_loop_info.  */
    8116                 :      867603 :       if (bb->loop_father->nb_iterations)
    8117                 :      137867 :         bb->loop_father->nb_iterations
    8118                 :      137867 :           = simplify_replace_tree (bb->loop_father->nb_iterations,
    8119                 :             :                                    NULL_TREE, NULL_TREE, &vn_valueize_for_srt);
    8120                 :             :     }
    8121                 :             : 
    8122                 :             :   /* Value-number all defs in the basic-block.  */
    8123                 :    57613791 :   if (!skip_phis)
    8124                 :    82996439 :     for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
    8125                 :    25406671 :          gsi_next (&gsi))
    8126                 :             :       {
    8127                 :    25406671 :         gphi *phi = gsi.phi ();
    8128                 :    25406671 :         tree res = PHI_RESULT (phi);
    8129                 :    25406671 :         vn_ssa_aux_t res_info = VN_INFO (res);
    8130                 :    25406671 :         if (!bb_visited)
    8131                 :             :           {
    8132                 :    18068674 :             gcc_assert (!res_info->visited);
    8133                 :    18068674 :             res_info->valnum = VN_TOP;
    8134                 :    18068674 :             res_info->visited = true;
    8135                 :             :           }
    8136                 :             : 
    8137                 :             :         /* When not iterating force backedge values to varying.  */
    8138                 :    25406671 :         visit_stmt (phi, !iterate_phis);
    8139                 :    50813342 :         if (virtual_operand_p (res))
    8140                 :    10259760 :           continue;
    8141                 :             : 
    8142                 :             :         /* Eliminate */
    8143                 :             :         /* The interesting case is gcc.dg/tree-ssa/pr22230.c for correctness
    8144                 :             :            how we handle backedges and availability.
    8145                 :             :            And gcc.dg/tree-ssa/ssa-sccvn-2.c for optimization.  */
    8146                 :    15146911 :         tree val = res_info->valnum;
    8147                 :    15146911 :         if (res != val && !iterate && eliminate)
    8148                 :             :           {
    8149                 :     1276819 :             if (tree leader = avail.eliminate_avail (bb, res))
    8150                 :             :               {
    8151                 :     1140070 :                 if (leader != res
    8152                 :             :                     /* Preserve loop-closed SSA form.  */
    8153                 :     1140070 :                     && (! lc_phi_nodes
    8154                 :        3096 :                         || is_gimple_min_invariant (leader)))
    8155                 :             :                   {
    8156                 :     1139373 :                     if (dump_file && (dump_flags & TDF_DETAILS))
    8157                 :             :                       {
    8158                 :         197 :                         fprintf (dump_file, "Replaced redundant PHI node "
    8159                 :             :                                  "defining ");
    8160                 :         197 :                         print_generic_expr (dump_file, res);
    8161                 :         197 :                         fprintf (dump_file, " with ");
    8162                 :         197 :                         print_generic_expr (dump_file, leader);
    8163                 :         197 :                         fprintf (dump_file, "\n");
    8164                 :             :                       }
    8165                 :     1139373 :                     avail.eliminations++;
    8166                 :             : 
    8167                 :     1139373 :                     if (may_propagate_copy (res, leader))
    8168                 :             :                       {
    8169                 :             :                         /* Schedule for removal.  */
    8170                 :     1139373 :                         avail.to_remove.safe_push (phi);
    8171                 :     1139373 :                         continue;
    8172                 :             :                       }
    8173                 :             :                     /* ???  Else generate a copy stmt.  */
    8174                 :             :                   }
    8175                 :             :               }
    8176                 :             :           }
    8177                 :             :         /* Only make defs available that not already are.  But make
    8178                 :             :            sure loop-closed SSA PHI node defs are picked up for
    8179                 :             :            downstream uses.  */
    8180                 :    14007538 :         if (lc_phi_nodes
    8181                 :    14007538 :             || res == val
    8182                 :    14007538 :             || ! avail.eliminate_avail (bb, res))
    8183                 :    10693464 :           avail.eliminate_push_avail (bb, res);
    8184                 :             :       }
    8185                 :             : 
    8186                 :             :   /* For empty BBs mark outgoing edges executable.  For non-empty BBs
    8187                 :             :      we do this when processing the last stmt as we have to do this
    8188                 :             :      before elimination which otherwise forces GIMPLE_CONDs to
    8189                 :             :      if (1 != 0) style when seeing non-executable edges.  */
    8190                 :   115227582 :   if (gsi_end_p (gsi_start_bb (bb)))
    8191                 :             :     {
    8192                 :    13785521 :       FOR_EACH_EDGE (e, ei, bb->succs)
    8193                 :             :         {
    8194                 :     6892765 :           if (!(e->flags & EDGE_EXECUTABLE))
    8195                 :             :             {
    8196                 :     4773544 :               if (dump_file && (dump_flags & TDF_DETAILS))
    8197                 :        5526 :                 fprintf (dump_file,
    8198                 :             :                          "marking outgoing edge %d -> %d executable\n",
    8199                 :        5526 :                          e->src->index, e->dest->index);
    8200                 :     4773544 :               e->flags |= EDGE_EXECUTABLE;
    8201                 :     4773544 :               e->dest->flags |= BB_EXECUTABLE;
    8202                 :             :             }
    8203                 :     2119221 :           else if (!(e->dest->flags & BB_EXECUTABLE))
    8204                 :             :             {
    8205                 :           0 :               if (dump_file && (dump_flags & TDF_DETAILS))
    8206                 :           0 :                 fprintf (dump_file,
    8207                 :             :                          "marking destination block %d reachable\n",
    8208                 :             :                          e->dest->index);
    8209                 :           0 :               e->dest->flags |= BB_EXECUTABLE;
    8210                 :             :             }
    8211                 :             :         }
    8212                 :             :     }
    8213                 :   115227582 :   for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
    8214                 :   428037106 :        !gsi_end_p (gsi); gsi_next (&gsi))
    8215                 :             :     {
    8216                 :   370423315 :       ssa_op_iter i;
    8217                 :   370423315 :       tree op;
    8218                 :   370423315 :       if (!bb_visited)
    8219                 :             :         {
    8220                 :   433030694 :           FOR_EACH_SSA_TREE_OPERAND (op, gsi_stmt (gsi), i, SSA_OP_ALL_DEFS)
    8221                 :             :             {
    8222                 :   128556060 :               vn_ssa_aux_t op_info = VN_INFO (op);
    8223                 :   128556060 :               gcc_assert (!op_info->visited);
    8224                 :   128556060 :               op_info->valnum = VN_TOP;
    8225                 :   128556060 :               op_info->visited = true;
    8226                 :             :             }
    8227                 :             : 
    8228                 :             :           /* We somehow have to deal with uses that are not defined
    8229                 :             :              in the processed region.  Forcing unvisited uses to
    8230                 :             :              varying here doesn't play well with def-use following during
    8231                 :             :              expression simplification, so we deal with this by checking
    8232                 :             :              the visited flag in SSA_VAL.  */
    8233                 :             :         }
    8234                 :             : 
    8235                 :   370423315 :       visit_stmt (gsi_stmt (gsi));
    8236                 :             : 
    8237                 :   370423315 :       gimple *last = gsi_stmt (gsi);
    8238                 :   370423315 :       e = NULL;
    8239                 :   370423315 :       switch (gimple_code (last))
    8240                 :             :         {
    8241                 :      106022 :         case GIMPLE_SWITCH:
    8242                 :      106022 :           e = find_taken_edge (bb, vn_valueize (gimple_switch_index
    8243                 :      106022 :                                                 (as_a <gswitch *> (last))));
    8244                 :      106022 :           break;
    8245                 :    22453724 :         case GIMPLE_COND:
    8246                 :    22453724 :           {
    8247                 :    22453724 :             tree lhs = vn_valueize (gimple_cond_lhs (last));
    8248                 :    22453724 :             tree rhs = vn_valueize (gimple_cond_rhs (last));
    8249                 :    22453724 :             tree_code cmpcode = gimple_cond_code (last);
    8250                 :             :             /* Canonicalize the comparison if needed, putting
    8251                 :             :                the constant in the rhs.  */
    8252                 :    22453724 :             if (tree_swap_operands_p (lhs, rhs))
    8253                 :             :               {
    8254                 :      750021 :                 std::swap (lhs, rhs);
    8255                 :      750021 :                 cmpcode = swap_tree_comparison (cmpcode);
    8256                 :             :                }
    8257                 :    22453724 :             tree val = gimple_simplify (cmpcode,
    8258                 :             :                                         boolean_type_node, lhs, rhs,
    8259                 :             :                                         NULL, vn_valueize);
    8260                 :             :             /* If the condition didn't simplfy see if we have recorded
    8261                 :             :                an expression from sofar taken edges.  */
    8262                 :    22453724 :             if (! val || TREE_CODE (val) != INTEGER_CST)
    8263                 :             :               {
    8264                 :    20815936 :                 vn_nary_op_t vnresult;
    8265                 :    20815936 :                 tree ops[2];
    8266                 :    20815936 :                 ops[0] = lhs;
    8267                 :    20815936 :                 ops[1] = rhs;
    8268                 :    20815936 :                 val = vn_nary_op_lookup_pieces (2, cmpcode,
    8269                 :             :                                                 boolean_type_node, ops,
    8270                 :             :                                                 &vnresult);
    8271                 :             :                 /* Got back a ssa name, then try looking up `val != 0`
    8272                 :             :                    as it might have been recorded that way.  */
    8273                 :    20815936 :                 if (val && TREE_CODE (val) == SSA_NAME)
    8274                 :             :                   {
    8275                 :      144618 :                     ops[0] = val;
    8276                 :      144618 :                     ops[1] = build_zero_cst (TREE_TYPE (val));
    8277                 :      144618 :                     val = vn_nary_op_lookup_pieces (2, NE_EXPR,
    8278                 :             :                                                     boolean_type_node, ops,
    8279                 :             :                                                     &vnresult);
    8280                 :             :                   }
    8281                 :             :                 /* Did we get a predicated value?  */
    8282                 :    20815878 :                 if (! val && vnresult && vnresult->predicated_values)
    8283                 :             :                   {
    8284                 :     1101940 :                     val = vn_nary_op_get_predicated_value (vnresult, bb);
    8285                 :     1101940 :                     if (val && dump_file && (dump_flags & TDF_DETAILS))
    8286                 :             :                       {
    8287                 :           2 :                         fprintf (dump_file, "Got predicated value ");
    8288                 :           2 :                         print_generic_expr (dump_file, val, TDF_NONE);
    8289                 :           2 :                         fprintf (dump_file, " for ");
    8290                 :           2 :                         print_gimple_stmt (dump_file, last, TDF_SLIM);
    8291                 :             :                       }
    8292                 :             :                   }
    8293                 :             :               }
    8294                 :    20815936 :             if (val)
    8295                 :     1899501 :               e = find_taken_edge (bb, val);
    8296                 :    22453724 :             if (! e)
    8297                 :             :               {
    8298                 :             :                 /* If we didn't manage to compute the taken edge then
    8299                 :             :                    push predicated expressions for the condition itself
    8300                 :             :                    and related conditions to the hashtables.  This allows
    8301                 :             :                    simplification of redundant conditions which is
    8302                 :             :                    important as early cleanup.  */
    8303                 :    20554223 :                 edge true_e, false_e;
    8304                 :    20554223 :                 extract_true_false_edges_from_block (bb, &true_e, &false_e);
    8305                 :      471135 :                 if ((do_region && bitmap_bit_p (exit_bbs, true_e->dest->index))
    8306                 :    20750328 :                     || !can_track_predicate_on_edge (true_e))
    8307                 :     4535390 :                   true_e = NULL;
    8308                 :      471135 :                 if ((do_region && bitmap_bit_p (exit_bbs, false_e->dest->index))
    8309                 :    20726596 :                     || !can_track_predicate_on_edge (false_e))
    8310                 :     5140922 :                   false_e = NULL;
    8311                 :    20554223 :                 insert_predicates_for_cond (cmpcode, lhs, rhs, true_e, false_e);
    8312                 :             :               }
    8313                 :             :             break;
    8314                 :             :           }
    8315                 :        1359 :         case GIMPLE_GOTO:
    8316                 :        1359 :           e = find_taken_edge (bb, vn_valueize (gimple_goto_dest (last)));
    8317                 :        1359 :           break;
    8318                 :             :         default:
    8319                 :             :           e = NULL;
    8320                 :             :         }
    8321                 :   370423315 :       if (e)
    8322                 :             :         {
    8323                 :     1902924 :           todo = TODO_cleanup_cfg;
    8324                 :     1902924 :           if (!(e->flags & EDGE_EXECUTABLE))
    8325                 :             :             {
    8326                 :     1504001 :               if (dump_file && (dump_flags & TDF_DETAILS))
    8327                 :          35 :                 fprintf (dump_file,
    8328                 :             :                          "marking known outgoing %sedge %d -> %d executable\n",
    8329                 :          35 :                          e->flags & EDGE_DFS_BACK ? "back-" : "",
    8330                 :          35 :                          e->src->index, e->dest->index);
    8331                 :     1504001 :               e->flags |= EDGE_EXECUTABLE;
    8332                 :     1504001 :               e->dest->flags |= BB_EXECUTABLE;
    8333                 :             :             }
    8334                 :      398923 :           else if (!(e->dest->flags & BB_EXECUTABLE))
    8335                 :             :             {
    8336                 :       10465 :               if (dump_file && (dump_flags & TDF_DETAILS))
    8337                 :           0 :                 fprintf (dump_file,
    8338                 :             :                          "marking destination block %d reachable\n",
    8339                 :             :                          e->dest->index);
    8340                 :       10465 :               e->dest->flags |= BB_EXECUTABLE;
    8341                 :             :             }
    8342                 :             :         }
    8343                 :   737040782 :       else if (gsi_one_before_end_p (gsi))
    8344                 :             :         {
    8345                 :   120000301 :           FOR_EACH_EDGE (e, ei, bb->succs)
    8346                 :             :             {
    8347                 :    71182190 :               if (!(e->flags & EDGE_EXECUTABLE))
    8348                 :             :                 {
    8349                 :    52175549 :                   if (dump_file && (dump_flags & TDF_DETAILS))
    8350                 :       16160 :                     fprintf (dump_file,
    8351                 :             :                              "marking outgoing edge %d -> %d executable\n",
    8352                 :       16160 :                              e->src->index, e->dest->index);
    8353                 :    52175549 :                   e->flags |= EDGE_EXECUTABLE;
    8354                 :    52175549 :                   e->dest->flags |= BB_EXECUTABLE;
    8355                 :             :                 }
    8356                 :    19006641 :               else if (!(e->dest->flags & BB_EXECUTABLE))
    8357                 :             :                 {
    8358                 :     2322242 :                   if (dump_file && (dump_flags & TDF_DETAILS))
    8359                 :        5382 :                     fprintf (dump_file,
    8360                 :             :                              "marking destination block %d reachable\n",
    8361                 :             :                              e->dest->index);
    8362                 :     2322242 :                   e->dest->flags |= BB_EXECUTABLE;
    8363                 :             :                 }
    8364                 :             :             }
    8365                 :             :         }
    8366                 :             : 
    8367                 :             :       /* Eliminate.  That also pushes to avail.  */
    8368                 :   370423315 :       if (eliminate && ! iterate)
    8369                 :    91321182 :         avail.eliminate_stmt (bb, &gsi);
    8370                 :             :       else
    8371                 :             :         /* If not eliminating, make all not already available defs
    8372                 :             :            available.  But avoid picking up dead defs.  */
    8373                 :   355019623 :         FOR_EACH_SSA_TREE_OPERAND (op, gsi_stmt (gsi), i, SSA_OP_DEF)
    8374                 :    75917490 :           if (! has_zero_uses (op)
    8375                 :    75917490 :               && ! avail.eliminate_avail (bb, op))
    8376                 :    57797133 :             avail.eliminate_push_avail (bb, op);
    8377                 :             :     }
    8378                 :             : 
    8379                 :             :   /* Eliminate in destination PHI arguments.  Always substitute in dest
    8380                 :             :      PHIs, even for non-executable edges.  This handles region
    8381                 :             :      exits PHIs.  */
    8382                 :    57613791 :   if (!iterate && eliminate)
    8383                 :    31081311 :     FOR_EACH_EDGE (e, ei, bb->succs)
    8384                 :    18451357 :       for (gphi_iterator gsi = gsi_start_phis (e->dest);
    8385                 :    35157688 :            !gsi_end_p (gsi); gsi_next (&gsi))
    8386                 :             :         {
    8387                 :    16706331 :           gphi *phi = gsi.phi ();
    8388                 :    16706331 :           use_operand_p use_p = PHI_ARG_DEF_PTR_FROM_EDGE (phi, e);
    8389                 :    16706331 :           tree arg = USE_FROM_PTR (use_p);
    8390                 :    25566053 :           if (TREE_CODE (arg) != SSA_NAME
    8391                 :    16706331 :               || virtual_operand_p (arg))
    8392                 :     8859722 :             continue;
    8393                 :     7846609 :           tree sprime;
    8394                 :     7846609 :           if (SSA_NAME_IS_DEFAULT_DEF (arg))
    8395                 :             :             {
    8396                 :      107994 :               sprime = SSA_VAL (arg);
    8397                 :      107994 :               gcc_assert (TREE_CODE (sprime) != SSA_NAME
    8398                 :             :                           || SSA_NAME_IS_DEFAULT_DEF (sprime));
    8399                 :             :             }
    8400                 :             :           else
    8401                 :             :             /* Look for sth available at the definition block of the argument.
    8402                 :             :                This avoids inconsistencies between availability there which
    8403                 :             :                decides if the stmt can be removed and availability at the
    8404                 :             :                use site.  The SSA property ensures that things available
    8405                 :             :                at the definition are also available at uses.  */
    8406                 :     7738615 :             sprime = avail.eliminate_avail (gimple_bb (SSA_NAME_DEF_STMT (arg)),
    8407                 :             :                                             arg);
    8408                 :     7846609 :           if (sprime
    8409                 :     7846609 :               && sprime != arg
    8410                 :     7846609 :               && may_propagate_copy (arg, sprime, !(e->flags & EDGE_ABNORMAL)))
    8411                 :     1363085 :             propagate_value (use_p, sprime);
    8412                 :             :         }
    8413                 :             : 
    8414                 :    57613791 :   vn_context_bb = NULL;
    8415                 :    57613791 :   return todo;
    8416                 :             : }
    8417                 :             : 
    8418                 :             : /* Unwind state per basic-block.  */
    8419                 :             : 
    8420                 :             : struct unwind_state
    8421                 :             : {
    8422                 :             :   /* Times this block has been visited.  */
    8423                 :             :   unsigned visited;
    8424                 :             :   /* Whether to handle this as iteration point or whether to treat
    8425                 :             :      incoming backedge PHI values as varying.  */
    8426                 :             :   bool iterate;
    8427                 :             :   /* Maximum RPO index this block is reachable from.  */
    8428                 :             :   int max_rpo;
    8429                 :             :   /* Unwind state.  */
    8430                 :             :   void *ob_top;
    8431                 :             :   vn_reference_t ref_top;
    8432                 :             :   vn_phi_t phi_top;
    8433                 :             :   vn_nary_op_t nary_top;
    8434                 :             :   vn_avail *avail_top;
    8435                 :             : };
    8436                 :             : 
    8437                 :             : /* Unwind the RPO VN state for iteration.  */
    8438                 :             : 
    8439                 :             : static void
    8440                 :     1763821 : do_unwind (unwind_state *to, rpo_elim &avail)
    8441                 :             : {
    8442                 :     1763821 :   gcc_assert (to->iterate);
    8443                 :    32573998 :   for (; last_inserted_nary != to->nary_top;
    8444                 :    30810177 :        last_inserted_nary = last_inserted_nary->next)
    8445                 :             :     {
    8446                 :    30810177 :       vn_nary_op_t *slot;
    8447                 :    30810177 :       slot = valid_info->nary->find_slot_with_hash
    8448                 :    30810177 :         (last_inserted_nary, last_inserted_nary->hashcode, NO_INSERT);
    8449                 :             :       /* Predication causes the need to restore previous state.  */
    8450                 :    30810177 :       if ((*slot)->unwind_to)
    8451                 :     6107839 :         *slot = (*slot)->unwind_to;
    8452                 :             :       else
    8453                 :    24702338 :         valid_info->nary->clear_slot (slot);
    8454                 :             :     }
    8455                 :     6962100 :   for (; last_inserted_phi != to->phi_top;
    8456                 :     5198279 :        last_inserted_phi = last_inserted_phi->next)
    8457                 :             :     {
    8458                 :     5198279 :       vn_phi_t *slot;
    8459                 :     5198279 :       slot = valid_info->phis->find_slot_with_hash
    8460                 :     5198279 :         (last_inserted_phi, last_inserted_phi->hashcode, NO_INSERT);
    8461                 :     5198279 :       valid_info->phis->clear_slot (slot);
    8462                 :             :     }
    8463                 :    14077172 :   for (; last_inserted_ref != to->ref_top;
    8464                 :    12313351 :        last_inserted_ref = last_inserted_ref->next)
    8465                 :             :     {
    8466                 :    12313351 :       vn_reference_t *slot;
    8467                 :    12313351 :       slot = valid_info->references->find_slot_with_hash
    8468                 :    12313351 :         (last_inserted_ref, last_inserted_ref->hashcode, NO_INSERT);
    8469                 :    12313351 :       (*slot)->operands.release ();
    8470                 :    12313351 :       valid_info->references->clear_slot (slot);
    8471                 :             :     }
    8472                 :     1763821 :   obstack_free (&vn_tables_obstack, to->ob_top);
    8473                 :             : 
    8474                 :             :   /* Prune [rpo_idx, ] from avail.  */
    8475                 :    19528486 :   for (; last_pushed_avail && last_pushed_avail->avail != to->avail_top;)
    8476                 :             :     {
    8477                 :    17764665 :       vn_ssa_aux_t val = last_pushed_avail;
    8478                 :    17764665 :       vn_avail *av = val->avail;
    8479                 :    17764665 :       val->avail = av->next;
    8480                 :    17764665 :       last_pushed_avail = av->next_undo;
    8481                 :    17764665 :       av->next = avail.m_avail_freelist;
    8482                 :    17764665 :       avail.m_avail_freelist = av;
    8483                 :             :     }
    8484                 :     1763821 : }
    8485                 :             : 
    8486                 :             : /* Do VN on a SEME region specified by ENTRY and EXIT_BBS in FN.
    8487                 :             :    If ITERATE is true then treat backedges optimistically as not
    8488                 :             :    executed and iterate.  If ELIMINATE is true then perform
    8489                 :             :    elimination, otherwise leave that to the caller.  If SKIP_ENTRY_PHIS
    8490                 :             :    is true then force PHI nodes in ENTRY->dest to VARYING.  */
    8491                 :             : 
    8492                 :             : static unsigned
    8493                 :     5771874 : do_rpo_vn_1 (function *fn, edge entry, bitmap exit_bbs,
    8494                 :             :              bool iterate, bool eliminate, bool skip_entry_phis,
    8495                 :             :              vn_lookup_kind kind)
    8496                 :             : {
    8497                 :     5771874 :   unsigned todo = 0;
    8498                 :     5771874 :   default_vn_walk_kind = kind;
    8499                 :             : 
    8500                 :             :   /* We currently do not support region-based iteration when
    8501                 :             :      elimination is requested.  */
    8502                 :     5771874 :   gcc_assert (!entry || !iterate || !eliminate);
    8503                 :             :   /* When iterating we need loop info up-to-date.  */
    8504                 :     5771874 :   gcc_assert (!iterate || !loops_state_satisfies_p (LOOPS_NEED_FIXUP));
    8505                 :             : 
    8506                 :     5771874 :   bool do_region = entry != NULL;
    8507                 :     5771874 :   if (!do_region)
    8508                 :             :     {
    8509                 :     5158474 :       entry = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (fn));
    8510                 :     5158474 :       exit_bbs = BITMAP_ALLOC (NULL);
    8511                 :     5158474 :       bitmap_set_bit (exit_bbs, EXIT_BLOCK);
    8512                 :             :     }
    8513                 :             : 
    8514                 :             :   /* Clear EDGE_DFS_BACK on "all" entry edges, RPO order compute will
    8515                 :             :      re-mark those that are contained in the region.  */
    8516                 :     5771874 :   edge_iterator ei;
    8517                 :     5771874 :   edge e;
    8518                 :    11594812 :   FOR_EACH_EDGE (e, ei, entry->dest->preds)
    8519                 :     5822938 :     e->flags &= ~EDGE_DFS_BACK;
    8520                 :             : 
    8521                 :     5771874 :   int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (fn) - NUM_FIXED_BLOCKS);
    8522                 :     5771874 :   auto_vec<std::pair<int, int> > toplevel_scc_extents;
    8523                 :     5771874 :   int n = rev_post_order_and_mark_dfs_back_seme
    8524                 :     7533683 :     (fn, entry, exit_bbs, true, rpo, !iterate ? &toplevel_scc_extents : NULL);
    8525                 :             : 
    8526                 :     5771874 :   if (!do_region)
    8527                 :     5158474 :     BITMAP_FREE (exit_bbs);
    8528                 :             : 
    8529                 :             :   /* If there are any non-DFS_BACK edges into entry->dest skip
    8530                 :             :      processing PHI nodes for that block.  This supports
    8531                 :             :      value-numbering loop bodies w/o the actual loop.  */
    8532                 :    11594811 :   FOR_EACH_EDGE (e, ei, entry->dest->preds)
    8533                 :     5822938 :     if (e != entry
    8534                 :       51064 :         && !(e->flags & EDGE_DFS_BACK))
    8535                 :             :       break;
    8536                 :     5771874 :   if (e != NULL && dump_file && (dump_flags & TDF_DETAILS))
    8537                 :           0 :     fprintf (dump_file, "Region does not contain all edges into "
    8538                 :             :              "the entry block, skipping its PHIs.\n");
    8539                 :     5771874 :   skip_entry_phis |= e != NULL;
    8540                 :             : 
    8541                 :     5771874 :   int *bb_to_rpo = XNEWVEC (int, last_basic_block_for_fn (fn));
    8542                 :    52970542 :   for (int i = 0; i < n; ++i)
    8543                 :    47198668 :     bb_to_rpo[rpo[i]] = i;
    8544                 :             : 
    8545                 :     5771874 :   unwind_state *rpo_state = XNEWVEC (unwind_state, n);
    8546                 :             : 
    8547                 :     5771874 :   rpo_elim avail (entry->dest);
    8548                 :     5771874 :   rpo_avail = &avail;
    8549                 :             : 
    8550                 :             :   /* Verify we have no extra entries into the region.  */
    8551                 :     5771874 :   if (flag_checking && do_region)
    8552                 :             :     {
    8553                 :      613394 :       auto_bb_flag bb_in_region (fn);
    8554                 :     1834278 :       for (int i = 0; i < n; ++i)
    8555                 :             :         {
    8556                 :     1220884 :           basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
    8557                 :     1220884 :           bb->flags |= bb_in_region;
    8558                 :             :         }
    8559                 :             :       /* We can't merge the first two loops because we cannot rely
    8560                 :             :          on EDGE_DFS_BACK for edges not within the region.  But if
    8561                 :             :          we decide to always have the bb_in_region flag we can
    8562                 :             :          do the checking during the RPO walk itself (but then it's
    8563                 :             :          also easy to handle MEME conservatively).  */
    8564                 :     1834278 :       for (int i = 0; i < n; ++i)
    8565                 :             :         {
    8566                 :     1220884 :           basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
    8567                 :     1220884 :           edge e;
    8568                 :     1220884 :           edge_iterator ei;
    8569                 :     2665010 :           FOR_EACH_EDGE (e, ei, bb->preds)
    8570                 :     1444126 :             gcc_assert (e == entry
    8571                 :             :                         || (skip_entry_phis && bb == entry->dest)
    8572                 :             :                         || (e->src->flags & bb_in_region));
    8573                 :             :         }
    8574                 :     1834278 :       for (int i = 0; i < n; ++i)
    8575                 :             :         {
    8576                 :     1220884 :           basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
    8577                 :     1220884 :           bb->flags &= ~bb_in_region;
    8578                 :             :         }
    8579                 :      613394 :     }
    8580                 :             : 
    8581                 :             :   /* Create the VN state.  For the initial size of the various hashtables
    8582                 :             :      use a heuristic based on region size and number of SSA names.  */
    8583                 :     5771874 :   unsigned region_size = (((unsigned HOST_WIDE_INT)n * num_ssa_names)
    8584                 :     5771874 :                           / (n_basic_blocks_for_fn (fn) - NUM_FIXED_BLOCKS));
    8585                 :     5771874 :   VN_TOP = create_tmp_var_raw (void_type_node, "vn_top");
    8586                 :     5771874 :   next_value_id = 1;
    8587                 :     5771874 :   next_constant_value_id = -1;
    8588                 :             : 
    8589                 :     5771874 :   vn_ssa_aux_hash = new hash_table <vn_ssa_aux_hasher> (region_size * 2);
    8590                 :     5771874 :   gcc_obstack_init (&vn_ssa_aux_obstack);
    8591                 :             : 
    8592                 :     5771874 :   gcc_obstack_init (&vn_tables_obstack);
    8593                 :     5771874 :   gcc_obstack_init (&vn_tables_insert_obstack);
    8594                 :     5771874 :   valid_info = XCNEW (struct vn_tables_s);
    8595                 :     5771874 :   allocate_vn_table (valid_info, region_size);
    8596                 :     5771874 :   last_inserted_ref = NULL;
    8597                 :     5771874 :   last_inserted_phi = NULL;
    8598                 :     5771874 :   last_inserted_nary = NULL;
    8599                 :     5771874 :   last_pushed_avail = NULL;
    8600                 :             : 
    8601                 :     5771874 :   vn_valueize = rpo_vn_valueize;
    8602                 :             : 
    8603                 :             :   /* Initialize the unwind state and edge/BB executable state.  */
    8604                 :     5771874 :   unsigned curr_scc = 0;
    8605                 :    52970542 :   for (int i = 0; i < n; ++i)
    8606                 :             :     {
    8607                 :    47198668 :       basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
    8608                 :    47198668 :       rpo_state[i].visited = 0;
    8609                 :    47198668 :       rpo_state[i].max_rpo = i;
    8610                 :    55207379 :       if (!iterate && curr_scc < toplevel_scc_extents.length ())
    8611                 :             :         {
    8612                 :     6576282 :           if (i >= toplevel_scc_extents[curr_scc].first
    8613                 :     6576282 :               && i <= toplevel_scc_extents[curr_scc].second)
    8614                 :     3614135 :             rpo_state[i].max_rpo = toplevel_scc_extents[curr_scc].second;
    8615                 :     6576282 :           if (i == toplevel_scc_extents[curr_scc].second)
    8616                 :      669263 :             curr_scc++;
    8617                 :             :         }
    8618                 :    47198668 :       bb->flags &= ~BB_EXECUTABLE;
    8619                 :    47198668 :       bool has_backedges = false;
    8620                 :    47198668 :       edge e;
    8621                 :    47198668 :       edge_iterator ei;
    8622                 :   111972577 :       FOR_EACH_EDGE (e, ei, bb->preds)
    8623                 :             :         {
    8624                 :    64773909 :           if (e->flags & EDGE_DFS_BACK)
    8625                 :     2633319 :             has_backedges = true;
    8626                 :    64773909 :           e->flags &= ~EDGE_EXECUTABLE;
    8627                 :    64773909 :           if (iterate || e == entry || (skip_entry_phis && bb == entry->dest))
    8628                 :    64773909 :             continue;
    8629                 :             :         }
    8630                 :    47198668 :       rpo_state[i].iterate = iterate && has_backedges;
    8631                 :             :     }
    8632                 :     5771874 :   entry->flags |= EDGE_EXECUTABLE;
    8633                 :     5771874 :   entry->dest->flags |= BB_EXECUTABLE;
    8634                 :             : 
    8635                 :             :   /* As heuristic to improve compile-time we handle only the N innermost
    8636                 :             :      loops and the outermost one optimistically.  */
    8637                 :     5771874 :   if (iterate)
    8638                 :             :     {
    8639                 :     4010065 :       unsigned max_depth = param_rpo_vn_max_loop_depth;
    8640                 :    13462277 :       for (auto loop : loops_list (cfun, LI_ONLY_INNERMOST))
    8641                 :     1434108 :         if (loop_depth (loop) > max_depth)
    8642                 :        1925 :           for (unsigned i = 2;
    8643                 :        7902 :                i < loop_depth (loop) - max_depth; ++i)
    8644                 :             :             {
    8645                 :        1925 :               basic_block header = superloop_at_depth (loop, i)->header;
    8646                 :        1925 :               bool non_latch_backedge = false;
    8647                 :        1925 :               edge e;
    8648                 :        1925 :               edge_iterator ei;
    8649                 :        5806 :               FOR_EACH_EDGE (e, ei, header->preds)
    8650                 :        3881 :                 if (e->flags & EDGE_DFS_BACK)
    8651                 :             :                   {
    8652                 :             :                     /* There can be a non-latch backedge into the header
    8653                 :             :                        which is part of an outer irreducible region.  We
    8654                 :             :                        cannot avoid iterating this block then.  */
    8655                 :        1956 :                     if (!dominated_by_p (CDI_DOMINATORS,
    8656                 :        1956 :                                          e->src, e->dest))
    8657                 :             :                       {
    8658                 :          12 :                         if (dump_file && (dump_flags & TDF_DETAILS))
    8659                 :           0 :                           fprintf (dump_file, "non-latch backedge %d -> %d "
    8660                 :             :                                    "forces iteration of loop %d\n",
    8661                 :           0 :                                    e->src->index, e->dest->index, loop->num);
    8662                 :             :                         non_latch_backedge = true;
    8663                 :             :                       }
    8664                 :             :                     else
    8665                 :        1944 :                       e->flags |= EDGE_EXECUTABLE;
    8666                 :             :                   }
    8667                 :        1925 :               rpo_state[bb_to_rpo[header->index]].iterate = non_latch_backedge;
    8668                 :     4010065 :             }
    8669                 :             :     }
    8670                 :             : 
    8671                 :     5771874 :   uint64_t nblk = 0;
    8672                 :     5771874 :   int idx = 0;
    8673                 :     4010065 :   if (iterate)
    8674                 :             :     /* Go and process all blocks, iterating as necessary.  */
    8675                 :    45673703 :     do
    8676                 :             :       {
    8677                 :    45673703 :         basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[idx]);
    8678                 :             : 
    8679                 :             :         /* If the block has incoming backedges remember unwind state.  This
    8680                 :             :            is required even for non-executable blocks since in irreducible
    8681                 :             :            regions we might reach them via the backedge and re-start iterating
    8682                 :             :            from there.
    8683                 :             :            Note we can individually mark blocks with incoming backedges to
    8684                 :             :            not iterate where we then handle PHIs conservatively.  We do that
    8685                 :             :            heuristically to reduce compile-time for degenerate cases.  */
    8686                 :    45673703 :         if (rpo_state[idx].iterate)
    8687                 :             :           {
    8688                 :     4068771 :             rpo_state[idx].ob_top = obstack_alloc (&vn_tables_obstack, 0);
    8689                 :     4068771 :             rpo_state[idx].ref_top = last_inserted_ref;
    8690                 :     4068771 :             rpo_state[idx].phi_top = last_inserted_phi;
    8691                 :     4068771 :             rpo_state[idx].nary_top = last_inserted_nary;
    8692                 :     4068771 :             rpo_state[idx].avail_top
    8693                 :     4068771 :               = last_pushed_avail ? last_pushed_avail->avail : NULL;
    8694                 :             :           }
    8695                 :             : 
    8696                 :    45673703 :         if (!(bb->flags & BB_EXECUTABLE))
    8697                 :             :           {
    8698                 :      796531 :             if (dump_file && (dump_flags & TDF_DETAILS))
    8699                 :           2 :               fprintf (dump_file, "Block %d: BB%d found not executable\n",
    8700                 :             :                        idx, bb->index);
    8701                 :      796531 :             idx++;
    8702                 :     2560352 :             continue;
    8703                 :             :           }
    8704                 :             : 
    8705                 :    44877172 :         if (dump_file && (dump_flags & TDF_DETAILS))
    8706                 :         336 :           fprintf (dump_file, "Processing block %d: BB%d\n", idx, bb->index);
    8707                 :    44877172 :         nblk++;
    8708                 :    89754344 :         todo |= process_bb (avail, bb,
    8709                 :    44877172 :                             rpo_state[idx].visited != 0,
    8710                 :             :                             rpo_state[idx].iterate,
    8711                 :             :                             iterate, eliminate, do_region, exit_bbs, false);
    8712                 :    44877172 :         rpo_state[idx].visited++;
    8713                 :             : 
    8714                 :             :         /* Verify if changed values flow over executable outgoing backedges
    8715                 :             :            and those change destination PHI values (that's the thing we
    8716                 :             :            can easily verify).  Reduce over all such edges to the farthest
    8717                 :             :            away PHI.  */
    8718                 :    44877172 :         int iterate_to = -1;
    8719                 :    44877172 :         edge_iterator ei;
    8720                 :    44877172 :         edge e;
    8721                 :   108190775 :         FOR_EACH_EDGE (e, ei, bb->succs)
    8722                 :    63313603 :           if ((e->flags & (EDGE_DFS_BACK|EDGE_EXECUTABLE))
    8723                 :             :               == (EDGE_DFS_BACK|EDGE_EXECUTABLE)
    8724                 :     4083843 :               && rpo_state[bb_to_rpo[e->dest->index]].iterate)
    8725                 :             :             {
    8726                 :     4081191 :               int destidx = bb_to_rpo[e->dest->index];
    8727                 :     4081191 :               if (!rpo_state[destidx].visited)
    8728                 :             :                 {
    8729                 :         147 :                   if (dump_file && (dump_flags & TDF_DETAILS))
    8730                 :           0 :                     fprintf (dump_file, "Unvisited destination %d\n",
    8731                 :             :                              e->dest->index);
    8732                 :         147 :                   if (iterate_to == -1 || destidx < iterate_to)
    8733                 :         147 :                     iterate_to = destidx;
    8734                 :         147 :                   continue;
    8735                 :             :                 }
    8736                 :     4081044 :               if (dump_file && (dump_flags & TDF_DETAILS))
    8737                 :          53 :                 fprintf (dump_file, "Looking for changed values of backedge"
    8738                 :             :                          " %d->%d destination PHIs\n",
    8739                 :          53 :                          e->src->index, e->dest->index);
    8740                 :     4081044 :               vn_context_bb = e->dest;
    8741                 :     4081044 :               gphi_iterator gsi;
    8742                 :     4081044 :               for (gsi = gsi_start_phis (e->dest);
    8743                 :     9363636 :                    !gsi_end_p (gsi); gsi_next (&gsi))
    8744                 :             :                 {
    8745                 :     7046556 :                   bool inserted = false;
    8746                 :             :                   /* While we'd ideally just iterate on value changes
    8747                 :             :                      we CSE PHIs and do that even across basic-block
    8748                 :             :                      boundaries.  So even hashtable state changes can
    8749                 :             :                      be important (which is roughly equivalent to
    8750                 :             :                      PHI argument value changes).  To not excessively
    8751                 :             :                      iterate because of that we track whether a PHI
    8752                 :             :                      was CSEd to with GF_PLF_1.  */
    8753                 :     7046556 :                   bool phival_changed;
    8754                 :     7046556 :                   if ((phival_changed = visit_phi (gsi.phi (),
    8755                 :             :                                                    &inserted, false))
    8756                 :     8335141 :                       || (inserted && gimple_plf (gsi.phi (), GF_PLF_1)))
    8757                 :             :                     {
    8758                 :     1763964 :                       if (!phival_changed
    8759                 :     1763964 :                           && dump_file && (dump_flags & TDF_DETAILS))
    8760                 :           0 :                         fprintf (dump_file, "PHI was CSEd and hashtable "
    8761                 :             :                                  "state (changed)\n");
    8762                 :     1763964 :                       if (iterate_to == -1 || destidx < iterate_to)
    8763                 :     1763880 :                         iterate_to = destidx;
    8764                 :     1763964 :                       break;
    8765                 :             :                     }
    8766                 :             :                 }
    8767                 :     4081044 :               vn_context_bb = NULL;
    8768                 :             :             }
    8769                 :    44877172 :         if (iterate_to != -1)
    8770                 :             :           {
    8771                 :     1763821 :             do_unwind (&rpo_state[iterate_to], avail);
    8772                 :     1763821 :             idx = iterate_to;
    8773                 :     1763821 :             if (dump_file && (dump_flags & TDF_DETAILS))
    8774                 :          20 :               fprintf (dump_file, "Iterating to %d BB%d\n",
    8775                 :          20 :                        iterate_to, rpo[iterate_to]);
    8776                 :     1763821 :             continue;
    8777                 :             :           }
    8778                 :             : 
    8779                 :    43113351 :         idx++;
    8780                 :             :       }
    8781                 :    45673703 :     while (idx < n);
    8782                 :             : 
    8783                 :             :   else /* !iterate */
    8784                 :             :     {
    8785                 :             :       /* Process all blocks greedily with a worklist that enforces RPO
    8786                 :             :          processing of reachable blocks.  */
    8787                 :     1761809 :       auto_bitmap worklist;
    8788                 :     1761809 :       bitmap_set_bit (worklist, 0);
    8789                 :    16260237 :       while (!bitmap_empty_p (worklist))
    8790                 :             :         {
    8791                 :    12736619 :           int idx = bitmap_clear_first_set_bit (worklist);
    8792                 :    12736619 :           basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[idx]);
    8793                 :    12736619 :           gcc_assert ((bb->flags & BB_EXECUTABLE)
    8794                 :             :                       && !rpo_state[idx].visited);
    8795                 :             : 
    8796                 :    12736619 :           if (dump_file && (dump_flags & TDF_DETAILS))
    8797                 :       31193 :             fprintf (dump_file, "Processing block %d: BB%d\n", idx, bb->index);
    8798                 :             : 
    8799                 :             :           /* When we run into predecessor edges where we cannot trust its
    8800                 :             :              executable state mark them executable so PHI processing will
    8801                 :             :              be conservative.
    8802                 :             :              ???  Do we need to force arguments flowing over that edge
    8803                 :             :              to be varying or will they even always be?  */
    8804                 :    12736619 :           edge_iterator ei;
    8805                 :    12736619 :           edge e;
    8806                 :    30751332 :           FOR_EACH_EDGE (e, ei, bb->preds)
    8807                 :    18014713 :             if (!(e->flags & EDGE_EXECUTABLE)
    8808                 :      930816 :                 && (bb == entry->dest
    8809                 :      882710 :                     || (!rpo_state[bb_to_rpo[e->src->index]].visited
    8810                 :      854220 :                         && (rpo_state[bb_to_rpo[e->src->index]].max_rpo
    8811                 :             :                             >= (int)idx))))
    8812                 :             :               {
    8813                 :      882185 :                 if (dump_file && (dump_flags & TDF_DETAILS))
    8814                 :       10094 :                   fprintf (dump_file, "Cannot trust state of predecessor "
    8815                 :             :                            "edge %d -> %d, marking executable\n",
    8816                 :       10094 :                            e->src->index, e->dest->index);
    8817                 :      882185 :                 e->flags |= EDGE_EXECUTABLE;
    8818                 :             :               }
    8819                 :             : 
    8820                 :    12736619 :           nblk++;
    8821                 :    12736619 :           todo |= process_bb (avail, bb, false, false, false, eliminate,
    8822                 :             :                               do_region, exit_bbs,
    8823                 :    12736619 :                               skip_entry_phis && bb == entry->dest);
    8824                 :    12736619 :           rpo_state[idx].visited++;
    8825                 :             : 
    8826                 :    31317611 :           FOR_EACH_EDGE (e, ei, bb->succs)
    8827                 :    18580992 :             if ((e->flags & EDGE_EXECUTABLE)
    8828                 :    18516998 :                 && e->dest->index != EXIT_BLOCK
    8829                 :    17395090 :                 && (!do_region || !bitmap_bit_p (exit_bbs, e->dest->index))
    8830                 :    34781564 :                 && !rpo_state[bb_to_rpo[e->dest->index]].visited)
    8831                 :    15322088 :               bitmap_set_bit (worklist, bb_to_rpo[e->dest->index]);
    8832                 :             :         }
    8833                 :     1761809 :     }
    8834                 :             : 
    8835                 :             :   /* If statistics or dump file active.  */
    8836                 :     5771874 :   int nex = 0;
    8837                 :     5771874 :   unsigned max_visited = 1;
    8838                 :    52970542 :   for (int i = 0; i < n; ++i)
    8839                 :             :     {
    8840                 :    47198668 :       basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
    8841                 :    47198668 :       if (bb->flags & BB_EXECUTABLE)
    8842                 :    46770178 :         nex++;
    8843                 :    47198668 :       statistics_histogram_event (cfun, "RPO block visited times",
    8844                 :    47198668 :                                   rpo_state[i].visited);
    8845                 :    47198668 :       if (rpo_state[i].visited > max_visited)
    8846                 :             :         max_visited = rpo_state[i].visited;
    8847                 :             :     }
    8848                 :     5771874 :   unsigned nvalues = 0, navail = 0;
    8849                 :   158918213 :   for (hash_table<vn_ssa_aux_hasher>::iterator i = vn_ssa_aux_hash->begin ();
    8850                 :   312064552 :        i != vn_ssa_aux_hash->end (); ++i)
    8851                 :             :     {
    8852                 :   153146339 :       nvalues++;
    8853                 :   153146339 :       vn_avail *av = (*i)->avail;
    8854                 :   226604901 :       while (av)
    8855                 :             :         {
    8856                 :    73458562 :           navail++;
    8857                 :    73458562 :           av = av->next;
    8858                 :             :         }
    8859                 :             :     }
    8860                 :     5771874 :   statistics_counter_event (cfun, "RPO blocks", n);
    8861                 :     5771874 :   statistics_counter_event (cfun, "RPO blocks visited", nblk);
    8862                 :     5771874 :   statistics_counter_event (cfun, "RPO blocks executable", nex);
    8863                 :     5771874 :   statistics_histogram_event (cfun, "RPO iterations", 10*nblk / nex);
    8864                 :     5771874 :   statistics_histogram_event (cfun, "RPO num values", nvalues);
    8865                 :     5771874 :   statistics_histogram_event (cfun, "RPO num avail", navail);
    8866                 :     5771874 :   statistics_histogram_event (cfun, "RPO num lattice",
    8867                 :     5771874 :                               vn_ssa_aux_hash->elements ());
    8868                 :     5771874 :   if (dump_file && (dump_flags & (TDF_DETAILS|TDF_STATS)))
    8869                 :             :     {
    8870                 :       10069 :       fprintf (dump_file, "RPO iteration over %d blocks visited %" PRIu64
    8871                 :             :                " blocks in total discovering %d executable blocks iterating "
    8872                 :             :                "%d.%d times, a block was visited max. %u times\n",
    8873                 :             :                n, nblk, nex,
    8874                 :       10069 :                (int)((10*nblk / nex)/10), (int)((10*nblk / nex)%10),
    8875                 :             :                max_visited);
    8876                 :       10069 :       fprintf (dump_file, "RPO tracked %d values available at %d locations "
    8877                 :             :                "and %" PRIu64 " lattice elements\n",
    8878                 :       10069 :                nvalues, navail, (uint64_t) vn_ssa_aux_hash->elements ());
    8879                 :             :     }
    8880                 :             : 
    8881                 :     5771874 :   if (eliminate)
    8882                 :             :     {
    8883                 :             :       /* When !iterate we already performed elimination during the RPO
    8884                 :             :          walk.  */
    8885                 :     4824614 :       if (iterate)
    8886                 :             :         {
    8887                 :             :           /* Elimination for region-based VN needs to be done within the
    8888                 :             :              RPO walk.  */
    8889                 :     3082110 :           gcc_assert (! do_region);
    8890                 :             :           /* Note we can't use avail.walk here because that gets confused
    8891                 :             :              by the existing availability and it will be less efficient
    8892                 :             :              as well.  */
    8893                 :     3082110 :           todo |= eliminate_with_rpo_vn (NULL);
    8894                 :             :         }
    8895                 :             :       else
    8896                 :     1742504 :         todo |= avail.eliminate_cleanup (do_region);
    8897                 :             :     }
    8898                 :             : 
    8899                 :     5771874 :   vn_valueize = NULL;
    8900                 :     5771874 :   rpo_avail = NULL;
    8901                 :             : 
    8902                 :     5771874 :   XDELETEVEC (bb_to_rpo);
    8903                 :     5771874 :   XDELETEVEC (rpo);
    8904                 :     5771874 :   XDELETEVEC (rpo_state);
    8905                 :             : 
    8906                 :     5771874 :   return todo;
    8907                 :     5771874 : }
    8908                 :             : 
    8909                 :             : /* Region-based entry for RPO VN.  Performs value-numbering and elimination
    8910                 :             :    on the SEME region specified by ENTRY and EXIT_BBS.  If ENTRY is not
    8911                 :             :    the only edge into the region at ENTRY->dest PHI nodes in ENTRY->dest
    8912                 :             :    are not considered.
    8913                 :             :    If ITERATE is true then treat backedges optimistically as not
    8914                 :             :    executed and iterate.  If ELIMINATE is true then perform
    8915                 :             :    elimination, otherwise leave that to the caller.
    8916                 :             :    If SKIP_ENTRY_PHIS is true then force PHI nodes in ENTRY->dest to VARYING.
    8917                 :             :    KIND specifies the amount of work done for handling memory operations.  */
    8918                 :             : 
    8919                 :             : unsigned
    8920                 :      632705 : do_rpo_vn (function *fn, edge entry, bitmap exit_bbs,
    8921                 :             :            bool iterate, bool eliminate, bool skip_entry_phis,
    8922                 :             :            vn_lookup_kind kind)
    8923                 :             : {
    8924                 :      632705 :   auto_timevar tv (TV_TREE_RPO_VN);
    8925                 :      632705 :   unsigned todo = do_rpo_vn_1 (fn, entry, exit_bbs, iterate, eliminate,
    8926                 :             :                                skip_entry_phis, kind);
    8927                 :      632705 :   free_rpo_vn ();
    8928                 :     1265410 :   return todo;
    8929                 :      632705 : }
    8930                 :             : 
    8931                 :             : 
    8932                 :             : namespace {
    8933                 :             : 
    8934                 :             : const pass_data pass_data_fre =
    8935                 :             : {
    8936                 :             :   GIMPLE_PASS, /* type */
    8937                 :             :   "fre", /* name */
    8938                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    8939                 :             :   TV_TREE_FRE, /* tv_id */
    8940                 :             :   ( PROP_cfg | PROP_ssa ), /* properties_required */
    8941                 :             :   0, /* properties_provided */
    8942                 :             :   0, /* properties_destroyed */
    8943                 :             :   0, /* todo_flags_start */
    8944                 :             :   0, /* todo_flags_finish */
    8945                 :             : };
    8946                 :             : 
    8947                 :             : class pass_fre : public gimple_opt_pass
    8948                 :             : {
    8949                 :             : public:
    8950                 :     1414330 :   pass_fre (gcc::context *ctxt)
    8951                 :     2828660 :     : gimple_opt_pass (pass_data_fre, ctxt), may_iterate (true)
    8952                 :             :   {}
    8953                 :             : 
    8954                 :             :   /* opt_pass methods: */
    8955                 :     1131464 :   opt_pass * clone () final override { return new pass_fre (m_ctxt); }
    8956                 :     1414330 :   void set_pass_param (unsigned int n, bool param) final override
    8957                 :             :     {
    8958                 :     1414330 :       gcc_assert (n == 0);
    8959                 :     1414330 :       may_iterate = param;
    8960                 :     1414330 :     }
    8961                 :     4285509 :   bool gate (function *) final override
    8962                 :             :     {
    8963                 :     4285509 :       return flag_tree_fre != 0 && (may_iterate || optimize > 1);
    8964                 :             :     }
    8965                 :             :   unsigned int execute (function *) final override;
    8966                 :             : 
    8967                 :             : private:
    8968                 :             :   bool may_iterate;
    8969                 :             : }; // class pass_fre
    8970                 :             : 
    8971                 :             : unsigned int
    8972                 :     4211214 : pass_fre::execute (function *fun)
    8973                 :             : {
    8974                 :     4211214 :   unsigned todo = 0;
    8975                 :             : 
    8976                 :             :   /* At -O[1g] use the cheap non-iterating mode.  */
    8977                 :     4211214 :   bool iterate_p = may_iterate && (optimize > 1);
    8978                 :     4211214 :   calculate_dominance_info (CDI_DOMINATORS);
    8979                 :     4211214 :   if (iterate_p)
    8980                 :     3082110 :     loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
    8981                 :             : 
    8982                 :     4211214 :   todo = do_rpo_vn_1 (fun, NULL, NULL, iterate_p, true, false, VN_WALKREWRITE);
    8983                 :     4211214 :   free_rpo_vn ();
    8984                 :             : 
    8985                 :     4211214 :   if (iterate_p)
    8986                 :     3082110 :     loop_optimizer_finalize ();
    8987                 :             : 
    8988                 :     4211214 :   if (scev_initialized_p ())
    8989                 :       27919 :     scev_reset_htab ();
    8990                 :             : 
    8991                 :             :   /* For late FRE after IVOPTs and unrolling, see if we can
    8992                 :             :      remove some TREE_ADDRESSABLE and rewrite stuff into SSA.  */
    8993                 :     4211214 :   if (!may_iterate)
    8994                 :      955670 :     todo |= TODO_update_address_taken;
    8995                 :             : 
    8996                 :     4211214 :   return todo;
    8997                 :             : }
    8998                 :             : 
    8999                 :             : } // anon namespace
    9000                 :             : 
    9001                 :             : gimple_opt_pass *
    9002                 :      282866 : make_pass_fre (gcc::context *ctxt)
    9003                 :             : {
    9004                 :      282866 :   return new pass_fre (ctxt);
    9005                 :             : }
    9006                 :             : 
    9007                 :             : #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.