LCOV - code coverage report
Current view: top level - gcc - cselib.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.5 % 1616 1511
Test Date: 2026-05-30 15:37:04 Functions: 98.4 % 63 62
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Common subexpression elimination library for GNU compiler.
       2              :    Copyright (C) 1987-2026 Free Software Foundation, Inc.
       3              : 
       4              : This file is part of GCC.
       5              : 
       6              : GCC is free software; you can redistribute it and/or modify it under
       7              : the terms of the GNU General Public License as published by the Free
       8              : Software Foundation; either version 3, or (at your option) any later
       9              : version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14              : for more details.
      15              : 
      16              : You should have received a copy of the GNU General Public License
      17              : along with GCC; see the file COPYING3.  If not see
      18              : <http://www.gnu.org/licenses/>.  */
      19              : 
      20              : #include "config.h"
      21              : #include "system.h"
      22              : #include "coretypes.h"
      23              : #include "backend.h"
      24              : #include "target.h"
      25              : #include "rtl.h"
      26              : #include "tree.h"
      27              : #include "df.h"
      28              : #include "memmodel.h"
      29              : #include "tm_p.h"
      30              : #include "regs.h"
      31              : #include "emit-rtl.h"
      32              : #include "dumpfile.h"
      33              : #include "cselib.h"
      34              : #include "function-abi.h"
      35              : #include "alias.h"
      36              : #include "predict.h"
      37              : #include "rtl-iter.h"
      38              : 
      39              : /* A list of cselib_val structures.  */
      40              : struct elt_list
      41              : {
      42              :   struct elt_list *next;
      43              :   cselib_val *elt;
      44              : };
      45              : 
      46              : static bool cselib_record_memory;
      47              : static bool cselib_preserve_constants;
      48              : static bool cselib_any_perm_equivs;
      49              : static inline void promote_debug_loc (struct elt_loc_list *l);
      50              : static struct elt_list *new_elt_list (struct elt_list *, cselib_val *);
      51              : static void new_elt_loc_list (cselib_val *, rtx);
      52              : static void unchain_one_value (cselib_val *);
      53              : static void unchain_one_elt_list (struct elt_list **);
      54              : static void unchain_one_elt_loc_list (struct elt_loc_list **);
      55              : static void remove_useless_values (void);
      56              : static hashval_t cselib_hash_rtx (rtx, int, machine_mode);
      57              : static cselib_val *new_cselib_val (unsigned int, machine_mode, rtx);
      58              : static void add_mem_for_addr (cselib_val *, cselib_val *, rtx);
      59              : static cselib_val *cselib_lookup_mem (rtx, int);
      60              : static void cselib_invalidate_regno (unsigned int, machine_mode);
      61              : static void cselib_invalidate_mem (rtx);
      62              : static void cselib_record_set (rtx, cselib_val *, cselib_val *);
      63              : static void cselib_record_sets (rtx_insn *);
      64              : static rtx autoinc_split (rtx, rtx *, machine_mode);
      65              : 
      66              : #define PRESERVED_VALUE_P(RTX) \
      67              :   (RTL_FLAG_CHECK1 ("PRESERVED_VALUE_P", (RTX), VALUE)->unchanging)
      68              : 
      69              : #define SP_BASED_VALUE_P(RTX) \
      70              :   (RTL_FLAG_CHECK1 ("SP_BASED_VALUE_P", (RTX), VALUE)->jump)
      71              : 
      72              : #define SP_DERIVED_VALUE_P(RTX) \
      73              :   (RTL_FLAG_CHECK1 ("SP_DERIVED_VALUE_P", (RTX), VALUE)->call)
      74              : 
      75              : struct expand_value_data
      76              : {
      77              :   bitmap regs_active;
      78              :   cselib_expand_callback callback;
      79              :   void *callback_arg;
      80              :   bool dummy;
      81              : };
      82              : 
      83              : static rtx cselib_expand_value_rtx_1 (rtx, struct expand_value_data *, int);
      84              : 
      85              : /* This is a global so we don't have to pass this through every function.
      86              :    It is used in new_elt_loc_list to set SETTING_INSN.  */
      87              : static rtx_insn *cselib_current_insn;
      88              : 
      89              : /* There are three ways in which cselib can look up an rtx:
      90              :    - for a REG, the reg_values table (which is indexed by regno) is used
      91              :    - for a MEM, we recursively look up its address and then follow the
      92              :      addr_list of that value
      93              :    - for everything else, we compute a hash value and go through the hash
      94              :      table.  Since different rtx's can still have the same hash value,
      95              :      this involves walking the table entries for a given value and comparing
      96              :      the locations of the entries with the rtx we are looking up.  */
      97              : 
      98              : struct cselib_hasher : nofree_ptr_hash <cselib_val>
      99              : {
     100              :   struct key {
     101              :     /* The rtx value and its mode (needed separately for constant
     102              :        integers).  */
     103              :     machine_mode mode;
     104              :     rtx x;
     105              :     /* The mode of the contaning MEM, if any, otherwise VOIDmode.  */
     106              :     machine_mode memmode;
     107              :   };
     108              :   typedef key *compare_type;
     109              :   static inline hashval_t hash (const cselib_val *);
     110              :   static inline bool equal (const cselib_val *, const key *);
     111              : };
     112              : 
     113              : /* The hash function for our hash table.  The value is always computed with
     114              :    cselib_hash_rtx when adding an element; this function just extracts the
     115              :    hash value from a cselib_val structure.  */
     116              : 
     117              : inline hashval_t
     118    101431948 : cselib_hasher::hash (const cselib_val *v)
     119              : {
     120    101431948 :   return v->hash;
     121              : }
     122              : 
     123              : /* The equality test for our hash table.  The first argument V is a table
     124              :    element (i.e. a cselib_val), while the second arg X is an rtx.  We know
     125              :    that all callers of htab_find_slot_with_hash will wrap CONST_INTs into a
     126              :    CONST of an appropriate mode.  */
     127              : 
     128              : inline bool
     129    578559231 : cselib_hasher::equal (const cselib_val *v, const key *x_arg)
     130              : {
     131    578559231 :   struct elt_loc_list *l;
     132    578559231 :   rtx x = x_arg->x;
     133    578559231 :   machine_mode mode = x_arg->mode;
     134    578559231 :   machine_mode memmode = x_arg->memmode;
     135              : 
     136    578559231 :   if (mode != GET_MODE (v->val_rtx))
     137              :     return false;
     138              : 
     139    468304141 :   if (GET_CODE (x) == VALUE)
     140     12841623 :     return x == v->val_rtx;
     141              : 
     142    465048992 :   if (SP_DERIVED_VALUE_P (v->val_rtx) && GET_MODE (x) == Pmode)
     143              :     {
     144     17726992 :       rtx xoff = NULL;
     145     17726992 :       if (autoinc_split (x, &xoff, memmode) == v->val_rtx && xoff == NULL_RTX)
     146      7917774 :         return true;
     147              :     }
     148              : 
     149              :   /* We don't guarantee that distinct rtx's have different hash values,
     150              :      so we need to do a comparison.  */
     151    771910226 :   for (l = v->locs; l; l = l->next)
     152    502641222 :     if (l->setting_insn && DEBUG_INSN_P (l->setting_insn)
     153     39983890 :         && (!cselib_current_insn || !DEBUG_INSN_P (cselib_current_insn)))
     154              :       {
     155     11350782 :         rtx_insn *save_cselib_current_insn = cselib_current_insn;
     156              :         /* If l is so far a debug only loc, without debug stmts it
     157              :            would never be compared to x at all, so temporarily pretend
     158              :            current instruction is that DEBUG_INSN so that we don't
     159              :            promote other debug locs even for unsuccessful comparison.  */
     160     11350782 :         cselib_current_insn = l->setting_insn;
     161     11350782 :         bool match = rtx_equal_for_cselib_1 (l->loc, x, memmode, 0);
     162     11350782 :         cselib_current_insn = save_cselib_current_insn;
     163     11350782 :         if (match)
     164              :           {
     165       893568 :             promote_debug_loc (l);
     166       893568 :             return true;
     167              :           }
     168              :       }
     169    491290440 :     else if (rtx_equal_for_cselib_1 (l->loc, x, memmode, 0))
     170              :       return true;
     171              : 
     172              :   return false;
     173              : }
     174              : 
     175              : /* A table that enables us to look up elts by their value.  */
     176              : static hash_table<cselib_hasher> *cselib_hash_table;
     177              : 
     178              : /* A table to hold preserved values.  */
     179              : static hash_table<cselib_hasher> *cselib_preserved_hash_table;
     180              : 
     181              : /* The subset of cselib_preserved_hash_table that might have useless locations.
     182              :    It excludes values for which all_locs_preserved_p is true.
     183              : 
     184              :    This is an important compile-time optimization for inputs that have
     185              :    many preserved values and many basic blocks (such as insn-extract.cc
     186              :    at the time of writing, especially with RTL checking enabled).
     187              :    If remove_useless_values iterated over the whole hash table for every
     188              :    block, it would repeat a lot of useless and cache-unfriendly work.  */
     189              : static vec<cselib_val *> cselib_preserved_prune_list;
     190              : 
     191              : /* The unique id that the next create value will take.  */
     192              : static unsigned int next_uid;
     193              : 
     194              : /* The number of registers we had when the varrays were last resized.  */
     195              : static unsigned int cselib_nregs;
     196              : 
     197              : /* Count values without known locations, or with only locations that
     198              :    wouldn't have been known except for debug insns.  Whenever this
     199              :    grows too big, we remove these useless values from the table.
     200              : 
     201              :    Counting values with only debug values is a bit tricky.  We don't
     202              :    want to increment n_useless_values when we create a value for a
     203              :    debug insn, for this would get n_useless_values out of sync, but we
     204              :    want increment it if all locs in the list that were ever referenced
     205              :    in nondebug insns are removed from the list.
     206              : 
     207              :    In the general case, once we do that, we'd have to stop accepting
     208              :    nondebug expressions in the loc list, to avoid having two values
     209              :    equivalent that, without debug insns, would have been made into
     210              :    separate values.  However, because debug insns never introduce
     211              :    equivalences themselves (no assignments), the only means for
     212              :    growing loc lists is through nondebug assignments.  If the locs
     213              :    also happen to be referenced in debug insns, it will work just fine.
     214              : 
     215              :    A consequence of this is that there's at most one debug-only loc in
     216              :    each loc list.  If we keep it in the first entry, testing whether
     217              :    we have a debug-only loc list takes O(1).
     218              : 
     219              :    Furthermore, since any additional entry in a loc list containing a
     220              :    debug loc would have to come from an assignment (nondebug) that
     221              :    references both the initial debug loc and the newly-equivalent loc,
     222              :    the initial debug loc would be promoted to a nondebug loc, and the
     223              :    loc list would not contain debug locs any more.
     224              : 
     225              :    So the only case we have to be careful with in order to keep
     226              :    n_useless_values in sync between debug and nondebug compilations is
     227              :    to avoid incrementing n_useless_values when removing the single loc
     228              :    from a value that turns out to not appear outside debug values.  We
     229              :    increment n_useless_debug_values instead, and leave such values
     230              :    alone until, for other reasons, we garbage-collect useless
     231              :    values.  */
     232              : static int n_useless_values;
     233              : static int n_useless_debug_values;
     234              : 
     235              : /* Count values whose locs have been taken exclusively from debug
     236              :    insns for the entire life of the value.  */
     237              : static int n_debug_values;
     238              : 
     239              : /* Number of useless values before we remove them from the hash table.  */
     240              : #define MAX_USELESS_VALUES 32
     241              : 
     242              : /* This table maps from register number to values.  It does not
     243              :    contain pointers to cselib_val structures, but rather elt_lists.
     244              :    The purpose is to be able to refer to the same register in
     245              :    different modes.  The first element of the list defines the mode in
     246              :    which the register was set; if the mode is unknown or the value is
     247              :    no longer valid in that mode, ELT will be NULL for the first
     248              :    element.  */
     249              : static struct elt_list **reg_values;
     250              : static unsigned int reg_values_size;
     251              : #define REG_VALUES(i) reg_values[i]
     252              : 
     253              : /* The largest number of hard regs used by any entry added to the
     254              :    REG_VALUES table.  Cleared on each cselib_clear_table() invocation.  */
     255              : static unsigned int max_value_regs;
     256              : 
     257              : /* Here the set of indices I with REG_VALUES(I) != 0 is saved.  This is used
     258              :    in cselib_clear_table() for fast emptying.  */
     259              : static unsigned int *used_regs;
     260              : static unsigned int n_used_regs;
     261              : 
     262              : /* We pass this to cselib_invalidate_mem to invalidate all of
     263              :    memory for a non-const call instruction and memory below stack pointer
     264              :    for const/pure calls.  */
     265              : static GTY(()) rtx callmem[2];
     266              : 
     267              : /* Set by discard_useless_locs if it deleted the last location of any
     268              :    value.  */
     269              : static int values_became_useless;
     270              : 
     271              : /* Used as stop element of the containing_mem list so we can check
     272              :    presence in the list by checking the next pointer.  */
     273              : static cselib_val dummy_val;
     274              : 
     275              : /* If non-NULL, value of the eliminated arg_pointer_rtx or frame_pointer_rtx
     276              :    that is constant through the whole function and should never be
     277              :    eliminated.  */
     278              : static cselib_val *cfa_base_preserved_val;
     279              : static unsigned int cfa_base_preserved_regno = INVALID_REGNUM;
     280              : 
     281              : /* Used to list all values that contain memory reference.
     282              :    May or may not contain the useless values - the list is compacted
     283              :    each time memory is invalidated.  */
     284              : static cselib_val *first_containing_mem = &dummy_val;
     285              : 
     286              : static object_allocator<elt_list> elt_list_pool ("elt_list");
     287              : static object_allocator<elt_loc_list> elt_loc_list_pool ("elt_loc_list");
     288              : static object_allocator<cselib_val> cselib_val_pool ("cselib_val_list");
     289              : 
     290              : static pool_allocator value_pool ("value", RTX_CODE_SIZE (VALUE));
     291              : 
     292              : /* If nonnull, cselib will call this function before freeing useless
     293              :    VALUEs.  A VALUE is deemed useless if its "locs" field is null.  */
     294              : void (*cselib_discard_hook) (cselib_val *);
     295              : 
     296              : /* If nonnull, cselib will call this function before recording sets or
     297              :    even clobbering outputs of INSN.  All the recorded sets will be
     298              :    represented in the array sets[n_sets].  new_val_min can be used to
     299              :    tell whether values present in sets are introduced by this
     300              :    instruction.  */
     301              : void (*cselib_record_sets_hook) (rtx_insn *insn, struct cselib_set *sets,
     302              :                                  int n_sets);
     303              : 
     304              : 
     305              : 
     306              : /* Allocate a struct elt_list and fill in its two elements with the
     307              :    arguments.  */
     308              : 
     309              : static inline struct elt_list *
     310    484267746 : new_elt_list (struct elt_list *next, cselib_val *elt)
     311              : {
     312    968535492 :   elt_list *el = elt_list_pool.allocate ();
     313    484267746 :   el->next = next;
     314    484267746 :   el->elt = elt;
     315    484267746 :   return el;
     316              : }
     317              : 
     318              : /* Record that all_locs_preserved_p might no longer hold for VAL.  */
     319              : 
     320              : static inline void
     321    722081881 : cselib_clear_all_locs_preserved (cselib_val *val)
     322              : {
     323    722081881 :   if (val->all_locs_preserved_p)
     324              :     {
     325      7675335 :       val->all_locs_preserved_p = false;
     326      7675335 :       if (val->in_preserved_table_p)
     327              :         /* VAL would have been removed from cselib_preserved_prune_list
     328              :            but now needs to be considered by remove_useless_values.  */
     329      7621811 :         cselib_preserved_prune_list.safe_push (val);
     330              :     }
     331    722081881 : }
     332              : 
     333              : /* Allocate a struct elt_loc_list with LOC and prepend it to VAL's loc
     334              :    list.  */
     335              : 
     336              : static inline void
     337    718153143 : new_elt_loc_list (cselib_val *val, rtx loc)
     338              : {
     339    722086432 :   struct elt_loc_list *el, *next = val->locs;
     340              : 
     341    722086432 :   gcc_checking_assert (!next || !next->setting_insn
     342              :                        || !DEBUG_INSN_P (next->setting_insn)
     343              :                        || cselib_current_insn == next->setting_insn);
     344              : 
     345              :   /* If we're creating the first loc in a debug insn context, we've
     346              :      just created a debug value.  Count it.  */
     347    422806865 :   if (!next && cselib_current_insn && DEBUG_INSN_P (cselib_current_insn))
     348      6779331 :     n_debug_values++;
     349              : 
     350    722086432 :   val = canonical_cselib_val (val);
     351    722086432 :   next = val->locs;
     352              : 
     353    722086432 :   if (GET_CODE (loc) == VALUE)
     354              :     {
     355      7871559 :       loc = canonical_cselib_val (CSELIB_VAL_PTR (loc))->val_rtx;
     356      7871559 :       auto *loc_val = CSELIB_VAL_PTR (loc);
     357              : 
     358      7871559 :       gcc_checking_assert (PRESERVED_VALUE_P (loc)
     359              :                            == PRESERVED_VALUE_P (val->val_rtx));
     360              : 
     361      7871559 :       if (val->val_rtx == loc)
     362              :         return;
     363      7866793 :       else if (val->uid > loc_val->uid)
     364              :         {
     365              :           /* Reverse the insertion.  */
     366              :           new_elt_loc_list (loc_val, val->val_rtx);
     367              :           return;
     368              :         }
     369              : 
     370      3933504 :       gcc_checking_assert (val->uid < loc_val->uid);
     371              : 
     372      3933504 :       if (loc_val->locs)
     373              :         {
     374              :           /* Bring all locs from LOC to VAL.  */
     375      2980142 :           for (el = loc_val->locs; el->next; el = el->next)
     376              :             {
     377              :               /* Adjust values that have LOC as canonical so that VAL
     378              :                  becomes their canonical.  */
     379           43 :               if (el->loc && GET_CODE (el->loc) == VALUE)
     380              :                 {
     381            0 :                   auto *el_val = CSELIB_VAL_PTR (el->loc);
     382            0 :                   gcc_checking_assert (el_val->locs->loc == loc);
     383            0 :                   el_val->locs->loc = val->val_rtx;
     384            0 :                   cselib_clear_all_locs_preserved (el_val);
     385              :                 }
     386              :             }
     387      2980099 :           el->next = val->locs;
     388      2980099 :           next = val->locs = loc_val->locs;
     389              :         }
     390              : 
     391      3933504 :       if (loc_val->addr_list)
     392              :         {
     393              :           /* Bring in addr_list into canonical node.  */
     394              :           struct elt_list *last = loc_val->addr_list;
     395            7 :           while (last->next)
     396              :             last = last->next;
     397            7 :           last->next = val->addr_list;
     398            7 :           val->addr_list = loc_val->addr_list;
     399            7 :           loc_val->addr_list = NULL;
     400              :         }
     401              : 
     402      3933504 :       if (loc_val->next_containing_mem != NULL
     403            0 :           && val->next_containing_mem == NULL)
     404              :         {
     405              :           /* Add VAL to the containing_mem list after LOC.  LOC will
     406              :              be removed when we notice it doesn't contain any
     407              :              MEMs.  */
     408            0 :           val->next_containing_mem = loc_val->next_containing_mem;
     409            0 :           loc_val->next_containing_mem = val;
     410              :         }
     411              : 
     412              :       /* Chain LOC back to VAL.  */
     413      3933504 :       el = elt_loc_list_pool.allocate ();
     414      3933504 :       el->loc = val->val_rtx;
     415      3933504 :       el->setting_insn = cselib_current_insn;
     416      3933504 :       el->next = NULL;
     417      3933504 :       loc_val->locs = el;
     418      3933504 :       cselib_clear_all_locs_preserved (loc_val);
     419              :     }
     420              : 
     421    718148377 :   el = elt_loc_list_pool.allocate ();
     422    718148377 :   el->loc = loc;
     423    718148377 :   el->setting_insn = cselib_current_insn;
     424    718148377 :   el->next = next;
     425    718148377 :   val->locs = el;
     426    718148377 :   cselib_clear_all_locs_preserved (val);
     427              : }
     428              : 
     429              : /* Promote loc L to a nondebug cselib_current_insn if L is marked as
     430              :    originating from a debug insn, maintaining the debug values
     431              :    count.  */
     432              : 
     433              : static inline void
     434   1229905564 : promote_debug_loc (struct elt_loc_list *l)
     435              : {
     436   1229905564 :   if (l && l->setting_insn && DEBUG_INSN_P (l->setting_insn)
     437     22570529 :       && (!cselib_current_insn || !DEBUG_INSN_P (cselib_current_insn)))
     438              :     {
     439      2568234 :       n_debug_values--;
     440      2568234 :       l->setting_insn = cselib_current_insn;
     441      2568234 :       if (cselib_preserve_constants && l->next)
     442              :         {
     443        21028 :           gcc_assert (l->next->setting_insn
     444              :                       && DEBUG_INSN_P (l->next->setting_insn)
     445              :                       && !l->next->next);
     446        21028 :           l->next->setting_insn = cselib_current_insn;
     447              :         }
     448              :       else
     449      2547206 :         gcc_assert (!l->next);
     450              :     }
     451   1229905564 : }
     452              : 
     453              : /* The elt_list at *PL is no longer needed.  Unchain it and free its
     454              :    storage.  */
     455              : 
     456              : static inline void
     457     80031553 : unchain_one_elt_list (struct elt_list **pl)
     458              : {
     459     80031553 :   struct elt_list *l = *pl;
     460              : 
     461     80031553 :   *pl = l->next;
     462    117416833 :   elt_list_pool.remove (l);
     463     42646273 : }
     464              : 
     465              : /* Likewise for elt_loc_lists.  */
     466              : 
     467              : static void
     468    222446192 : unchain_one_elt_loc_list (struct elt_loc_list **pl)
     469              : {
     470    222446192 :   struct elt_loc_list *l = *pl;
     471              : 
     472    222446192 :   *pl = l->next;
     473            0 :   elt_loc_list_pool.remove (l);
     474     38659320 : }
     475              : 
     476              : /* Likewise for cselib_vals.  This also frees the addr_list associated with
     477              :    V.  */
     478              : 
     479              : static void
     480      2361673 : unchain_one_value (cselib_val *v)
     481              : {
     482      2381075 :   while (v->addr_list)
     483        19402 :     unchain_one_elt_list (&v->addr_list);
     484              : 
     485      2361673 :   cselib_val_pool.remove (v);
     486      2361673 : }
     487              : 
     488              : /* Remove all entries from the hash table.  Also used during
     489              :    initialization.  */
     490              : 
     491              : void
     492     60729021 : cselib_clear_table (void)
     493              : {
     494     60729021 :   cselib_reset_table (1);
     495     60729021 : }
     496              : 
     497              : /* Return TRUE if V is a constant, a function invariant or a VALUE
     498              :    equivalence; FALSE otherwise.  */
     499              : 
     500              : static bool
     501     57748956 : invariant_or_equiv_p (cselib_val *v)
     502              : {
     503     57748956 :   struct elt_loc_list *l;
     504              : 
     505     57748956 :   if (v == cfa_base_preserved_val)
     506              :     return true;
     507              : 
     508              :   /* Keep VALUE equivalences around.  */
     509     80229036 :   for (l = v->locs; l; l = l->next)
     510     38753352 :     if (GET_CODE (l->loc) == VALUE)
     511              :       return true;
     512              : 
     513     41475684 :   if (v->locs != NULL
     514     22785198 :       && v->locs->next == NULL)
     515              :     {
     516     22731031 :       if (CONSTANT_P (v->locs->loc)
     517     22731031 :           && (GET_CODE (v->locs->loc) != CONST
     518       173839 :               || !references_value_p (v->locs->loc)))
     519      3484480 :         return true;
     520              :       /* Although a debug expr may be bound to different expressions,
     521              :          we can preserve it as if it was constant, to get unification
     522              :          and proper merging within var-tracking.  */
     523     19246551 :       if (GET_CODE (v->locs->loc) == DEBUG_EXPR
     524     17697035 :           || GET_CODE (v->locs->loc) == DEBUG_IMPLICIT_PTR
     525     17214496 :           || GET_CODE (v->locs->loc) == ENTRY_VALUE
     526     17214271 :           || GET_CODE (v->locs->loc) == DEBUG_PARAMETER_REF)
     527              :         return true;
     528              : 
     529              :       /* (plus (value V) (const_int C)) is invariant iff V is invariant.  */
     530     17196923 :       if (GET_CODE (v->locs->loc) == PLUS
     531     10731985 :           && CONST_INT_P (XEXP (v->locs->loc, 1))
     532      9580542 :           && GET_CODE (XEXP (v->locs->loc, 0)) == VALUE
     533     26017692 :           && invariant_or_equiv_p (CSELIB_VAL_PTR (XEXP (v->locs->loc, 0))))
     534              :         return true;
     535              :     }
     536              : 
     537              :   return false;
     538              : }
     539              : 
     540              : /* Remove from hash table all VALUEs except constants, function
     541              :    invariants and VALUE equivalences.  */
     542              : 
     543              : int
     544     44570456 : preserve_constants_and_equivs (cselib_val **x, void *info ATTRIBUTE_UNUSED)
     545              : {
     546     44570456 :   cselib_val *v = *x;
     547              : 
     548     44570456 :   if (invariant_or_equiv_p (v))
     549              :     {
     550     17449649 :       cselib_hasher::key lookup = {
     551     17449649 :         GET_MODE (v->val_rtx), v->val_rtx, VOIDmode
     552     17449649 :       };
     553     17449649 :       cselib_val **slot
     554     34899298 :         = cselib_preserved_hash_table->find_slot_with_hash (&lookup,
     555     17449649 :                                                             v->hash, INSERT);
     556     17449649 :       gcc_assert (!*slot);
     557     17449649 :       *slot = v;
     558     17449649 :       v->in_preserved_table_p = true;
     559     17449649 :       if (!v->all_locs_preserved_p)
     560            0 :         cselib_preserved_prune_list.safe_push (v);
     561              :     }
     562              : 
     563     44570456 :   cselib_hash_table->clear_slot (x);
     564              : 
     565     44570456 :   return 1;
     566              : }
     567              : 
     568              : /* Remove all entries from the hash table, arranging for the next
     569              :    value to be numbered NUM.  */
     570              : 
     571              : void
     572    100161416 : cselib_reset_table (unsigned int num)
     573              : {
     574    100161416 :   unsigned int i;
     575              : 
     576    100161416 :   max_value_regs = 0;
     577              : 
     578    100161416 :   if (cfa_base_preserved_val)
     579              :     {
     580      4357731 :       unsigned int regno = cfa_base_preserved_regno;
     581      4357731 :       unsigned int new_used_regs = 0;
     582     31045355 :       for (i = 0; i < n_used_regs; i++)
     583     26687624 :         if (used_regs[i] == regno)
     584              :           {
     585      4357731 :             new_used_regs = 1;
     586      4357731 :             continue;
     587              :           }
     588              :         else
     589     22329893 :           REG_VALUES (used_regs[i]) = 0;
     590      4357731 :       gcc_assert (new_used_regs == 1);
     591      4357731 :       n_used_regs = new_used_regs;
     592      4357731 :       used_regs[0] = regno;
     593      4357731 :       max_value_regs
     594      4357731 :         = hard_regno_nregs (regno,
     595      4357731 :                             GET_MODE (cfa_base_preserved_val->locs->loc));
     596              : 
     597              :       /* If cfa_base is sp + const_int, need to preserve also the
     598              :          SP_DERIVED_VALUE_P value.  */
     599      4357731 :       for (struct elt_loc_list *l = cfa_base_preserved_val->locs;
     600      8715462 :            l; l = l->next)
     601      8715462 :         if (GET_CODE (l->loc) == PLUS
     602      4357731 :             && GET_CODE (XEXP (l->loc, 0)) == VALUE
     603      4357731 :             && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
     604     13073193 :             && CONST_INT_P (XEXP (l->loc, 1)))
     605              :           {
     606      4357731 :             if (! invariant_or_equiv_p (CSELIB_VAL_PTR (XEXP (l->loc, 0))))
     607              :               {
     608            0 :                 rtx val = cfa_base_preserved_val->val_rtx;
     609            0 :                 rtx_insn *save_cselib_current_insn = cselib_current_insn;
     610            0 :                 cselib_current_insn = l->setting_insn;
     611            0 :                 new_elt_loc_list (CSELIB_VAL_PTR (XEXP (l->loc, 0)),
     612            0 :                                   plus_constant (Pmode, val,
     613            0 :                                                  -UINTVAL (XEXP (l->loc, 1))));
     614            0 :                 cselib_current_insn = save_cselib_current_insn;
     615              :               }
     616              :             break;
     617              :           }
     618              :     }
     619              :   else
     620              :     {
     621    367949029 :       for (i = 0; i < n_used_regs; i++)
     622    272145344 :         REG_VALUES (used_regs[i]) = 0;
     623     95803685 :       n_used_regs = 0;
     624              :     }
     625              : 
     626    100161416 :   if (cselib_preserve_constants)
     627     48928187 :     cselib_hash_table->traverse <void *, preserve_constants_and_equivs> (NULL);
     628              :   else
     629              :     {
     630     95803685 :       cselib_hash_table->empty ();
     631     95803685 :       gcc_checking_assert (!cselib_any_perm_equivs);
     632              :     }
     633              : 
     634    100161416 :   n_useless_values = 0;
     635    100161416 :   n_useless_debug_values = 0;
     636    100161416 :   n_debug_values = 0;
     637              : 
     638    100161416 :   next_uid = num;
     639              : 
     640    100161416 :   first_containing_mem = &dummy_val;
     641    100161416 : }
     642              : 
     643              : /* Return the number of the next value that will be generated.  */
     644              : 
     645              : unsigned int
     646      4856955 : cselib_get_next_uid (void)
     647              : {
     648      4856955 :   return next_uid;
     649              : }
     650              : 
     651              : /* Search for X, whose hashcode is HASH, in CSELIB_HASH_TABLE,
     652              :    INSERTing if requested.  When X is part of the address of a MEM,
     653              :    MEMMODE should specify the mode of the MEM.  */
     654              : 
     655              : static cselib_val **
     656    714914603 : cselib_find_slot (machine_mode mode, rtx x, hashval_t hash,
     657              :                   enum insert_option insert, machine_mode memmode)
     658              : {
     659    714914603 :   cselib_val **slot = NULL;
     660    714914603 :   cselib_hasher::key lookup = { mode, x, memmode };
     661    714914603 :   hash &= cselib_val::HASH_MASK;
     662    714914603 :   if (cselib_preserve_constants)
     663    161712925 :     slot = cselib_preserved_hash_table->find_slot_with_hash (&lookup, hash,
     664              :                                                              NO_INSERT);
     665    161712925 :   if (!slot)
     666    659629290 :     slot = cselib_hash_table->find_slot_with_hash (&lookup, hash, insert);
     667    714914603 :   return slot;
     668              : }
     669              : 
     670              : /* Return true if X contains a VALUE rtx.  If ONLY_USELESS is set, we
     671              :    only return true for values which point to a cselib_val whose value
     672              :    element has been set to zero, which implies the cselib_val will be
     673              :    removed.  */
     674              : 
     675              : bool
     676      2057806 : references_value_p (const_rtx x)
     677              : {
     678      2057806 :   subrtx_iterator::array_type array;
     679      4888146 :   FOR_EACH_SUBRTX (iter, array, x, ALL)
     680      2830340 :     if (GET_CODE (*iter) == VALUE)
     681            0 :       return true;
     682      2057806 :   return false;
     683      2057806 : }
     684              : 
     685              : /* Return true if V is a useless VALUE and can be discarded as such.  */
     686              : 
     687              : static bool
     688    711121426 : cselib_useless_value_p (cselib_val *v)
     689              : {
     690    711121426 :   return (v->locs == 0
     691     79184060 :           && !PRESERVED_VALUE_P (v->val_rtx)
     692    756946193 :           && !SP_DERIVED_VALUE_P (v->val_rtx));
     693              : }
     694              : 
     695              : /* For all locations found in V, delete locations that reference useless
     696              :    values (i.e. values without any location).  */
     697              : 
     698              : static void
     699     66412486 : discard_useless_locs (cselib_val *v)
     700              : {
     701     66412486 :   struct elt_loc_list **p = &v->locs;
     702     66412486 :   bool had_locs = v->locs != NULL;
     703     66412486 :   rtx_insn *setting_insn = v->locs ? v->locs->setting_insn : NULL;
     704              : 
     705     66412486 :   if (v->all_locs_preserved_p)
     706              :     return;
     707              : 
     708              :   bool all_locs_preserved_p = true;
     709    103771202 :   while (*p)
     710              :     {
     711              :       /* True if every value referenced by (*p)->loc is preserved.  */
     712     45786928 :       bool preserved_p = true;
     713     45786928 :       bool keep_p = true;
     714     45786928 :       subrtx_iterator::array_type array;
     715    153717713 :       FOR_EACH_SUBRTX (iter, array, (*p)->loc, ALL)
     716              :         {
     717    109204825 :           const_rtx x = *iter;
     718    109204825 :           if (GET_CODE (x) == VALUE && !PRESERVED_VALUE_P (x))
     719              :             {
     720      4670548 :               preserved_p = false;
     721      4670548 :               if (CSELIB_VAL_PTR (x)->locs == 0)
     722              :                 {
     723              :                   keep_p = false;
     724              :                   break;
     725              :                 }
     726              :             }
     727              :         }
     728     45786928 :       if (keep_p)
     729              :         {
     730     44512888 :           all_locs_preserved_p &= preserved_p;
     731     44512888 :           p = &(*p)->next;
     732              :         }
     733              :       else
     734      1274040 :         unchain_one_elt_loc_list (p);
     735     45786928 :     }
     736              : 
     737     57984274 :   if (all_locs_preserved_p)
     738     55029461 :     v->all_locs_preserved_p = true;
     739              : 
     740     57984274 :   if (had_locs && cselib_useless_value_p (v))
     741              :     {
     742      1141464 :       if (setting_insn && DEBUG_INSN_P (setting_insn))
     743            2 :         n_useless_debug_values++;
     744              :       else
     745      1141462 :         n_useless_values++;
     746      1141464 :       values_became_useless = 1;
     747              :     }
     748              : }
     749              : 
     750              : /* A hash-table traversal callback for the above.  */
     751              : 
     752              : int
     753     58790675 : discard_useless_locs (cselib_val **x, void *info ATTRIBUTE_UNUSED)
     754              : {
     755     58790675 :   discard_useless_locs (*x);
     756     58790675 :   return 1;
     757              : }
     758              : 
     759              : /* If X is a value with no locations, remove it from the hashtable.  */
     760              : 
     761              : int
     762     48423750 : discard_useless_values (cselib_val **x, void *info ATTRIBUTE_UNUSED)
     763              : {
     764     48423750 :   cselib_val *v = *x;
     765              : 
     766     48423750 :   if (v->locs == 0 && cselib_useless_value_p (v))
     767              :     {
     768      2361673 :       if (cselib_discard_hook)
     769       523474 :         cselib_discard_hook (v);
     770              : 
     771      2361673 :       CSELIB_VAL_PTR (v->val_rtx) = NULL;
     772      2361673 :       cselib_hash_table->clear_slot (x);
     773      2361673 :       unchain_one_value (v);
     774      2361673 :       n_useless_values--;
     775              :     }
     776              : 
     777     48423750 :   return 1;
     778              : }
     779              : 
     780              : /* Clean out useless values (i.e. those which no longer have locations
     781              :    associated with them) from the hash table.  */
     782              : 
     783              : static void
     784      4386480 : remove_useless_values (void)
     785              : {
     786      4440114 :   cselib_val **p, *v;
     787              : 
     788              :   /* First pass: eliminate locations that reference the value.  That in
     789              :      turn can make more values useless.  */
     790      4440114 :   do
     791              :     {
     792      4440114 :       values_became_useless = 0;
     793     63230789 :       cselib_hash_table->traverse <void *, discard_useless_locs> (NULL);
     794              :     }
     795      4440114 :   while (values_became_useless);
     796              : 
     797              :   /* Second pass: actually remove the values.  */
     798              : 
     799      4386480 :   p = &first_containing_mem;
     800      4508954 :   for (v = *p; v != &dummy_val; v = v->next_containing_mem)
     801       122474 :     if (v->locs && v == canonical_cselib_val (v))
     802              :       {
     803       119227 :         *p = v;
     804       119227 :         p = &(*p)->next_containing_mem;
     805              :       }
     806      4386480 :   *p = &dummy_val;
     807              : 
     808      4386480 :   if (cselib_preserve_constants)
     809              :     {
     810              :       /* Apply discard_useless_locs to each element of
     811              :          cselib_preserved_prune_list.  Remove from consideration any values
     812              :          whose locations only reference preserved values, since those
     813              :          locations will never be useless in their current form.  */
     814      4357731 :       unsigned int len = cselib_preserved_prune_list.length ();
     815      4357731 :       unsigned int dest_i = 0;
     816      4357731 :       unsigned int src_i = 0;
     817     11979542 :       for (; src_i < len; ++src_i)
     818              :         {
     819      7621811 :           auto *val = cselib_preserved_prune_list[src_i];
     820      7621811 :           discard_useless_locs (val);
     821      7621811 :           if (!val->all_locs_preserved_p)
     822              :             {
     823            0 :               if (dest_i < src_i)
     824            0 :                 cselib_preserved_prune_list[dest_i] = val;
     825            0 :               dest_i += 1;
     826              :             }
     827              :         }
     828      4357731 :       if (src_i != dest_i)
     829      3626687 :         cselib_preserved_prune_list.truncate (dest_i);
     830              :     }
     831      4386480 :   gcc_assert (!values_became_useless);
     832              : 
     833      4386480 :   n_useless_values += n_useless_debug_values;
     834      4386480 :   n_debug_values -= n_useless_debug_values;
     835      4386480 :   n_useless_debug_values = 0;
     836              : 
     837     52810230 :   cselib_hash_table->traverse <void *, discard_useless_values> (NULL);
     838              : 
     839      4386480 :   gcc_assert (!n_useless_values);
     840      4386480 : }
     841              : 
     842              : /* Arrange for a value to not be removed from the hash table even if
     843              :    it becomes useless.  */
     844              : 
     845              : void
     846     45200801 : cselib_preserve_value (cselib_val *v)
     847              : {
     848     45200801 :   PRESERVED_VALUE_P (v->val_rtx) = 1;
     849     45200801 : }
     850              : 
     851              : /* Test whether a value is preserved.  */
     852              : 
     853              : bool
     854    263002773 : cselib_preserved_value_p (cselib_val *v)
     855              : {
     856    263002773 :   return PRESERVED_VALUE_P (v->val_rtx);
     857              : }
     858              : 
     859              : /* Arrange for a REG value to be assumed constant through the whole function,
     860              :    never invalidated and preserved across cselib_reset_table calls.  */
     861              : 
     862              : void
     863       997943 : cselib_preserve_cfa_base_value (cselib_val *v, unsigned int regno)
     864              : {
     865       997943 :   if (cselib_preserve_constants
     866       997943 :       && v->locs
     867       997943 :       && REG_P (v->locs->loc))
     868              :     {
     869       499517 :       cfa_base_preserved_val = v;
     870       499517 :       cfa_base_preserved_regno = regno;
     871              :     }
     872       997943 : }
     873              : 
     874              : /* Clean all non-constant expressions in the hash table, but retain
     875              :    their values.  */
     876              : 
     877              : void
     878      4357731 : cselib_preserve_only_values (void)
     879              : {
     880      4357731 :   int i;
     881              : 
     882    405268983 :   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
     883    400911252 :     cselib_invalidate_regno (i, reg_raw_mode[i]);
     884              : 
     885      4357731 :   cselib_invalidate_mem (callmem[0]);
     886              : 
     887      4357731 :   remove_useless_values ();
     888              : 
     889      4357731 :   gcc_assert (first_containing_mem == &dummy_val);
     890      4357731 : }
     891              : 
     892              : /* Arrange for a value to be marked as based on stack pointer
     893              :    for find_base_term purposes.  */
     894              : 
     895              : void
     896      1920845 : cselib_set_value_sp_based (cselib_val *v)
     897              : {
     898      1920845 :   SP_BASED_VALUE_P (v->val_rtx) = 1;
     899      1920845 : }
     900              : 
     901              : /* Test whether a value is based on stack pointer for
     902              :    find_base_term purposes.  */
     903              : 
     904              : bool
     905    836556869 : cselib_sp_based_value_p (cselib_val *v)
     906              : {
     907    836556869 :   return SP_BASED_VALUE_P (v->val_rtx);
     908              : }
     909              : 
     910              : /* Return the mode in which a register was last set.  If X is not a
     911              :    register, return its mode.  If the mode in which the register was
     912              :    set is not known, or the value was already clobbered, return
     913              :    VOIDmode.  */
     914              : 
     915              : machine_mode
     916    112610525 : cselib_reg_set_mode (const_rtx x)
     917              : {
     918    112610525 :   if (!REG_P (x))
     919     34008228 :     return GET_MODE (x);
     920              : 
     921     78602297 :   if (REG_VALUES (REGNO (x)) == NULL
     922     78602297 :       || REG_VALUES (REGNO (x))->elt == NULL)
     923              :     return VOIDmode;
     924              : 
     925     23839378 :   return GET_MODE (REG_VALUES (REGNO (x))->elt->val_rtx);
     926              : }
     927              : 
     928              : /* If x is a PLUS or an autoinc operation, expand the operation,
     929              :    storing the offset, if any, in *OFF.  */
     930              : 
     931              : static rtx
     932   1746972623 : autoinc_split (rtx x, rtx *off, machine_mode memmode)
     933              : {
     934   1746972623 :   switch (GET_CODE (x))
     935              :     {
     936    905429130 :     case PLUS:
     937    905429130 :       *off = XEXP (x, 1);
     938    905429130 :       x = XEXP (x, 0);
     939    905429130 :       break;
     940              : 
     941     13886904 :     case PRE_DEC:
     942     13886904 :       if (memmode == VOIDmode)
     943              :         return x;
     944              : 
     945     27773808 :       *off = gen_int_mode (-GET_MODE_SIZE (memmode), GET_MODE (x));
     946     13886904 :       x = XEXP (x, 0);
     947     13886904 :       break;
     948              : 
     949            0 :     case PRE_INC:
     950            0 :       if (memmode == VOIDmode)
     951              :         return x;
     952              : 
     953            0 :       *off = gen_int_mode (GET_MODE_SIZE (memmode), GET_MODE (x));
     954            0 :       x = XEXP (x, 0);
     955            0 :       break;
     956              : 
     957      1627912 :     case PRE_MODIFY:
     958      1627912 :       x = XEXP (x, 1);
     959      1627912 :       break;
     960              : 
     961      1847783 :     case POST_DEC:
     962      1847783 :     case POST_INC:
     963      1847783 :     case POST_MODIFY:
     964      1847783 :       x = XEXP (x, 0);
     965      1847783 :       break;
     966              : 
     967              :     default:
     968              :       break;
     969              :     }
     970              : 
     971   1746972623 :   if (GET_MODE (x) == Pmode
     972   1697919655 :       && (REG_P (x) || MEM_P (x) || GET_CODE (x) == VALUE)
     973   2655951291 :       && (*off == NULL_RTX || CONST_INT_P (*off)))
     974              :     {
     975    904330613 :       cselib_val *e;
     976    904330613 :       if (GET_CODE (x) == VALUE)
     977    607870492 :         e = CSELIB_VAL_PTR (x);
     978              :       else
     979    296460121 :         e = cselib_lookup (x, GET_MODE (x), 0, memmode);
     980    904330613 :       if (e)
     981              :         {
     982    895106198 :           if (SP_DERIVED_VALUE_P (e->val_rtx)
     983    895106198 :               && (*off == NULL_RTX || *off == const0_rtx))
     984              :             {
     985        63713 :               *off = NULL_RTX;
     986        63713 :               return e->val_rtx;
     987              :             }
     988   1934614194 :           for (struct elt_loc_list *l = e->locs; l; l = l->next)
     989   1557593168 :             if (GET_CODE (l->loc) == PLUS
     990    681604147 :                 && GET_CODE (XEXP (l->loc, 0)) == VALUE
     991    680330480 :                 && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
     992   2075616781 :                 && CONST_INT_P (XEXP (l->loc, 1)))
     993              :               {
     994    518021459 :                 if (*off == NULL_RTX)
     995      1468609 :                   *off = XEXP (l->loc, 1);
     996              :                 else
     997    516552850 :                   *off = plus_constant (Pmode, *off,
     998    516552850 :                                         INTVAL (XEXP (l->loc, 1)));
     999    518021459 :                 if (*off == const0_rtx)
    1000    350650329 :                   *off = NULL_RTX;
    1001    518021459 :                 return XEXP (l->loc, 0);
    1002              :               }
    1003              :         }
    1004              :     }
    1005              :   return x;
    1006              : }
    1007              : 
    1008              : /* Return true if we can prove that X and Y contain the same value,
    1009              :    taking our gathered information into account.  MEMMODE holds the
    1010              :    mode of the enclosing MEM, if any, as required to deal with autoinc
    1011              :    addressing modes.  If X and Y are not (known to be) part of
    1012              :    addresses, MEMMODE should be VOIDmode.  */
    1013              : 
    1014              : bool
    1015   1304354061 : rtx_equal_for_cselib_1 (rtx x, rtx y, machine_mode memmode, int depth)
    1016              : {
    1017   1774473347 :   enum rtx_code code;
    1018   1774473347 :   const char *fmt;
    1019   1774473347 :   int i;
    1020              : 
    1021   1774473347 :   if (REG_P (x) || MEM_P (x))
    1022              :     {
    1023    151055057 :       cselib_val *e = cselib_lookup (x, GET_MODE (x), 0, memmode);
    1024              : 
    1025    151055057 :       if (e)
    1026    127856610 :         x = e->val_rtx;
    1027              :     }
    1028              : 
    1029   1774473347 :   if (REG_P (y) || MEM_P (y))
    1030              :     {
    1031    142413752 :       cselib_val *e = cselib_lookup (y, GET_MODE (y), 0, memmode);
    1032              : 
    1033    142413752 :       if (e)
    1034    130480095 :         y = e->val_rtx;
    1035              :     }
    1036              : 
    1037   1774473347 :   if (x == y)
    1038              :     return true;
    1039              : 
    1040   1449107444 :   if (GET_CODE (x) == VALUE)
    1041              :     {
    1042    523031189 :       cselib_val *e = canonical_cselib_val (CSELIB_VAL_PTR (x));
    1043    523031189 :       struct elt_loc_list *l;
    1044              : 
    1045    523031189 :       if (GET_CODE (y) == VALUE)
    1046     31882395 :         return e == canonical_cselib_val (CSELIB_VAL_PTR (y));
    1047              : 
    1048    491148794 :       if ((SP_DERIVED_VALUE_P (x)
    1049    150545109 :            || SP_DERIVED_VALUE_P (e->val_rtx))
    1050    531000513 :           && GET_MODE (y) == Pmode)
    1051              :         {
    1052    343272620 :           rtx yoff = NULL;
    1053    343272620 :           rtx yr = autoinc_split (y, &yoff, memmode);
    1054    343272620 :           if ((yr == x || yr == e->val_rtx) && yoff == NULL_RTX)
    1055        54027 :             return true;
    1056              :         }
    1057              : 
    1058    491094767 :       if (depth == 128)
    1059              :         return false;
    1060              : 
    1061   1610869258 :       for (l = e->locs; l; l = l->next)
    1062              :         {
    1063   1143083748 :           rtx t = l->loc;
    1064              : 
    1065              :           /* Avoid infinite recursion.  We know we have the canonical
    1066              :              value, so we can just skip any values in the equivalence
    1067              :              list.  */
    1068   1143083748 :           if (REG_P (t) || MEM_P (t) || GET_CODE (t) == VALUE)
    1069    707560909 :             continue;
    1070    435522839 :           else if (rtx_equal_for_cselib_1 (t, y, memmode, depth + 1))
    1071              :             return true;
    1072              :         }
    1073              : 
    1074              :       return false;
    1075              :     }
    1076    926076255 :   else if (GET_CODE (y) == VALUE)
    1077              :     {
    1078     46567600 :       cselib_val *e = canonical_cselib_val (CSELIB_VAL_PTR (y));
    1079     46567600 :       struct elt_loc_list *l;
    1080              : 
    1081     46567600 :       if ((SP_DERIVED_VALUE_P (y)
    1082     44360416 :            || SP_DERIVED_VALUE_P (e->val_rtx))
    1083     46966219 :           && GET_MODE (x) == Pmode)
    1084              :         {
    1085      2141309 :           rtx xoff = NULL;
    1086      2141309 :           rtx xr = autoinc_split (x, &xoff, memmode);
    1087      2141309 :           if ((xr == y || xr == e->val_rtx) && xoff == NULL_RTX)
    1088          163 :             return true;
    1089              :         }
    1090              : 
    1091     46567437 :       if (depth == 128)
    1092              :         return false;
    1093              : 
    1094    111874133 :       for (l = e->locs; l; l = l->next)
    1095              :         {
    1096     65360319 :           rtx t = l->loc;
    1097              : 
    1098     65360319 :           if (REG_P (t) || MEM_P (t) || GET_CODE (t) == VALUE)
    1099     56250857 :             continue;
    1100      9109462 :           else if (rtx_equal_for_cselib_1 (x, t, memmode, depth + 1))
    1101              :             return true;
    1102              :         }
    1103              : 
    1104              :       return false;
    1105              :     }
    1106              : 
    1107    879508655 :   if (GET_MODE (x) != GET_MODE (y))
    1108              :     return false;
    1109              : 
    1110    842271421 :   if (GET_CODE (x) != GET_CODE (y)
    1111    842271421 :       || (GET_CODE (x) == PLUS
    1112    341709891 :           && GET_MODE (x) == Pmode
    1113    245476683 :           && CONST_INT_P (XEXP (x, 1))
    1114    234765492 :           && CONST_INT_P (XEXP (y, 1))))
    1115              :     {
    1116    691915851 :       rtx xorig = x, yorig = y;
    1117    691915851 :       rtx xoff = NULL, yoff = NULL;
    1118              : 
    1119    691915851 :       x = autoinc_split (x, &xoff, memmode);
    1120    691915851 :       y = autoinc_split (y, &yoff, memmode);
    1121              : 
    1122              :       /* Don't recurse if nothing changed.  */
    1123    691915851 :       if (x != xorig || y != yorig)
    1124              :         {
    1125    652512710 :           if (!xoff != !yoff)
    1126    222443417 :             return false;
    1127              : 
    1128    569413595 :           if (xoff && !rtx_equal_for_cselib_1 (xoff, yoff, memmode, depth))
    1129              :             return false;
    1130              : 
    1131    469472434 :           return rtx_equal_for_cselib_1 (x, y, memmode, depth);
    1132              :         }
    1133              : 
    1134     39403141 :       if (GET_CODE (xorig) != GET_CODE (yorig))
    1135              :         return false;
    1136              :     }
    1137              : 
    1138              :   /* These won't be handled correctly by the code below.  */
    1139    150355570 :   switch (GET_CODE (x))
    1140              :     {
    1141              :     CASE_CONST_UNIQUE:
    1142              :     case DEBUG_EXPR:
    1143              :       return false;
    1144              : 
    1145              :     case CONST_VECTOR:
    1146              :       if (!same_vector_encodings_p (x, y))
    1147              :         return false;
    1148              :       break;
    1149              : 
    1150      2194725 :     case DEBUG_IMPLICIT_PTR:
    1151      2194725 :       return DEBUG_IMPLICIT_PTR_DECL (x)
    1152      2194725 :              == DEBUG_IMPLICIT_PTR_DECL (y);
    1153              : 
    1154         5474 :     case DEBUG_PARAMETER_REF:
    1155         5474 :       return DEBUG_PARAMETER_REF_DECL (x)
    1156         5474 :              == DEBUG_PARAMETER_REF_DECL (y);
    1157              : 
    1158       625811 :     case ENTRY_VALUE:
    1159              :       /* ENTRY_VALUEs are function invariant, it is thus undesirable to
    1160              :          use rtx_equal_for_cselib_1 to compare the operands.  */
    1161       625811 :       return rtx_equal_p (ENTRY_VALUE_EXP (x), ENTRY_VALUE_EXP (y));
    1162              : 
    1163          105 :     case LABEL_REF:
    1164          105 :       return label_ref_label (x) == label_ref_label (y);
    1165              : 
    1166          193 :     case REG:
    1167          193 :       return REGNO (x) == REGNO (y);
    1168              : 
    1169       646852 :     case MEM:
    1170              :       /* We have to compare any autoinc operations in the addresses
    1171              :          using this MEM's mode.  */
    1172       646852 :       return rtx_equal_for_cselib_1 (XEXP (x, 0), XEXP (y, 0), GET_MODE (x),
    1173       646852 :                                      depth);
    1174              : 
    1175              :     default:
    1176              :       break;
    1177              :     }
    1178              : 
    1179     40146694 :   code = GET_CODE (x);
    1180     40146694 :   fmt = GET_RTX_FORMAT (code);
    1181              : 
    1182     70095891 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1183              :     {
    1184     58852141 :       int j;
    1185              : 
    1186     58852141 :       switch (fmt[i])
    1187              :         {
    1188            0 :         case 'w':
    1189            0 :           if (XWINT (x, i) != XWINT (y, i))
    1190              :             return false;
    1191              :           break;
    1192              : 
    1193       577429 :         case 'n':
    1194       577429 :         case 'i':
    1195       577429 :           if (XINT (x, i) != XINT (y, i))
    1196              :             return false;
    1197              :           break;
    1198              : 
    1199         5305 :         case 'L':
    1200         5305 :           if (XLOC (x, i) != XLOC (y, i))
    1201              :             return false;
    1202              :           break;
    1203              : 
    1204       604902 :         case 'p':
    1205       604902 :           if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y)))
    1206              :             return false;
    1207              :           break;
    1208              : 
    1209      1470112 :         case 'V':
    1210      1470112 :         case 'E':
    1211              :           /* Two vectors must have the same length.  */
    1212      1470112 :           if (XVECLEN (x, i) != XVECLEN (y, i))
    1213              :             return false;
    1214              : 
    1215              :           /* And the corresponding elements must match.  */
    1216      3608357 :           for (j = 0; j < XVECLEN (x, i); j++)
    1217      3000368 :             if (! rtx_equal_for_cselib_1 (XVECEXP (x, i, j),
    1218      3000368 :                                           XVECEXP (y, i, j), memmode, depth))
    1219              :               return false;
    1220              :           break;
    1221              : 
    1222     43815559 :         case 'e':
    1223     43815559 :           if (i == 1
    1224     27648828 :               && targetm.commutative_p (x, UNKNOWN)
    1225     20083696 :               && rtx_equal_for_cselib_1 (XEXP (x, 1), XEXP (y, 0), memmode,
    1226              :                                          depth)
    1227     43991863 :               && rtx_equal_for_cselib_1 (XEXP (x, 0), XEXP (y, 1), memmode,
    1228              :                                          depth))
    1229              :             return true;
    1230     43728990 :           if (! rtx_equal_for_cselib_1 (XEXP (x, i), XEXP (y, i), memmode,
    1231              :                                         depth))
    1232              :             return false;
    1233              :           break;
    1234              : 
    1235      6297730 :         case 'S':
    1236      6297730 :         case 's':
    1237      6297730 :           if (strcmp (XSTR (x, i), XSTR (y, i)))
    1238              :             return false;
    1239              :           break;
    1240              : 
    1241              :         case 'u':
    1242              :           /* These are just backpointers, so they don't matter.  */
    1243              :           break;
    1244              : 
    1245              :         case '0':
    1246              :         case 't':
    1247              :           break;
    1248              : 
    1249              :           /* It is believed that rtx's at this level will never
    1250              :              contain anything but integers and other rtx's,
    1251              :              except for within LABEL_REFs and SYMBOL_REFs.  */
    1252            0 :         default:
    1253            0 :           gcc_unreachable ();
    1254              :         }
    1255              :     }
    1256              :   return true;
    1257              : }
    1258              : 
    1259              : /* Wrapper for rtx_equal_for_cselib_p to determine whether a SET is
    1260              :    truly redundant, taking into account aliasing information.  */
    1261              : bool
    1262    112610525 : cselib_redundant_set_p (rtx set)
    1263              : {
    1264    112610525 :   gcc_assert (GET_CODE (set) == SET);
    1265    112610525 :   rtx dest = SET_DEST (set);
    1266    112610525 :   if (cselib_reg_set_mode (dest) != GET_MODE (dest))
    1267              :     return false;
    1268              : 
    1269     53899384 :   rtx src = SET_SRC (set);
    1270      4024968 :   if ((MEM_P (src) && MEM_VOLATILE_P (src))
    1271     57855391 :        || !rtx_equal_for_cselib_p (dest, src))
    1272     53485818 :     return false;
    1273              : 
    1274       413566 :   while (GET_CODE (dest) == SUBREG
    1275       413566 :          || GET_CODE (dest) == ZERO_EXTRACT
    1276       827132 :          || GET_CODE (dest) == STRICT_LOW_PART)
    1277            0 :     dest = XEXP (dest, 0);
    1278              : 
    1279       413566 :   if (!flag_strict_aliasing || !MEM_P (dest))
    1280              :     return true;
    1281              : 
    1282        36872 :   if (MEM_VOLATILE_P (dest))
    1283              :     return false;
    1284              : 
    1285              :   /* For a store we need to check that suppressing it will not change
    1286              :      the effective alias set.  */
    1287        36872 :   rtx dest_addr = XEXP (dest, 0);
    1288              : 
    1289              :   /* Lookup the equivalents to the original dest (rather than just the
    1290              :      MEM).  */
    1291        73744 :   cselib_val *src_val = cselib_lookup (SET_DEST (set),
    1292        36872 :                                        GET_MODE (SET_DEST (set)),
    1293              :                                        0, VOIDmode);
    1294              : 
    1295        36872 :   if (src_val)
    1296              :     {
    1297              :       /* Walk the list of source equivalents to find the MEM accessing
    1298              :          the same location.  */
    1299        83932 :       for (elt_loc_list *l = src_val->locs; l; l = l->next)
    1300              :         {
    1301        83932 :           rtx src_equiv = l->loc;
    1302        83932 :           while (GET_CODE (src_equiv) == SUBREG
    1303        83932 :                  || GET_CODE (src_equiv) == ZERO_EXTRACT
    1304       167870 :                  || GET_CODE (src_equiv) == STRICT_LOW_PART)
    1305            6 :             src_equiv = XEXP (src_equiv, 0);
    1306              : 
    1307        83932 :           if (MEM_P (src_equiv))
    1308              :             {
    1309              :               /* Match the MEMs by comparing the addresses.  We can
    1310              :                  only remove the later store if the earlier aliases at
    1311              :                  least all the accesses of the later one.  */
    1312        44690 :               if (rtx_equal_for_cselib_1 (dest_addr, XEXP (src_equiv, 0),
    1313        44690 :                                           GET_MODE (dest), 0))
    1314        36866 :                 return mems_same_for_tbaa_p (src_equiv, dest);
    1315              :             }
    1316              :         }
    1317              :     }
    1318              : 
    1319              :   /* We failed to find a recorded value in the cselib history, so try
    1320              :      the source of this set; this catches cases such as *p = *q when p
    1321              :      and q have the same value.  */
    1322            6 :   while (GET_CODE (src) == SUBREG)
    1323            0 :     src = XEXP (src, 0);
    1324              : 
    1325            6 :   if (MEM_P (src)
    1326            6 :       && rtx_equal_for_cselib_1 (dest_addr, XEXP (src, 0), GET_MODE (dest), 0))
    1327            6 :     return mems_same_for_tbaa_p (src, dest);
    1328              : 
    1329              :   return false;
    1330              : }
    1331              : 
    1332              : /* Helper function for cselib_hash_rtx.  Arguments like for cselib_hash_rtx,
    1333              :    except that it hashes (plus:P x c).  */
    1334              : 
    1335              : static hashval_t
    1336    284184748 : cselib_hash_plus_const_int (rtx x, HOST_WIDE_INT c, int create,
    1337              :                             machine_mode memmode)
    1338              : {
    1339    284184748 :   cselib_val *e = cselib_lookup (x, GET_MODE (x), create, memmode);
    1340    284184748 :   if (! e)
    1341              :     return 0;
    1342              : 
    1343    271108790 :   if (! SP_DERIVED_VALUE_P (e->val_rtx))
    1344    439854114 :     for (struct elt_loc_list *l = e->locs; l; l = l->next)
    1345    355448180 :       if (GET_CODE (l->loc) == PLUS
    1346    130501229 :           && GET_CODE (XEXP (l->loc, 0)) == VALUE
    1347    129734019 :           && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
    1348    478441124 :           && CONST_INT_P (XEXP (l->loc, 1)))
    1349              :         {
    1350    122990126 :           e = CSELIB_VAL_PTR (XEXP (l->loc, 0));
    1351    122990126 :           c = trunc_int_for_mode (c + UINTVAL (XEXP (l->loc, 1)), Pmode);
    1352    122990126 :           break;
    1353              :         }
    1354    271108790 :   if (c == 0)
    1355      8120332 :     return e->hash;
    1356              : 
    1357    262988458 :   inchash::hash hash;
    1358    262988458 :   hash.add_int (PLUS);
    1359    262988458 :   hash.add_int (GET_MODE (x));
    1360    262988458 :   hash.merge_hash (e->hash);
    1361    262988458 :   hash.add_hwi (c);
    1362              : 
    1363    262988458 :   return hash.end () ? hash.end () : 1 + (unsigned int) PLUS;
    1364              : }
    1365              : 
    1366              : /* Hash an rtx.  Return 0 if we couldn't hash the rtx.
    1367              :    For registers and memory locations, we look up their cselib_val structure
    1368              :    and return its VALUE element.
    1369              :    Possible reasons for return 0 are: the object is volatile, or we couldn't
    1370              :    find a register or memory location in the table and CREATE is zero.  If
    1371              :    CREATE is nonzero, table elts are created for regs and mem.
    1372              :    N.B. this hash function returns the same hash value for RTXes that
    1373              :    differ only in the order of operands, thus it is suitable for comparisons
    1374              :    that take commutativity into account.
    1375              :    If we wanted to also support associative rules, we'd have to use a different
    1376              :    strategy to avoid returning spurious 0, e.g. return ~(~0U >> 1) .
    1377              :    MEMMODE indicates the mode of an enclosing MEM, and it's only
    1378              :    used to compute autoinc values.
    1379              :    We used to have a MODE argument for hashing for CONST_INTs, but that
    1380              :    didn't make sense, since it caused spurious hash differences between
    1381              :     (set (reg:SI 1) (const_int))
    1382              :     (plus:SI (reg:SI 2) (reg:SI 1))
    1383              :    and
    1384              :     (plus:SI (reg:SI 2) (const_int))
    1385              :    If the mode is important in any context, it must be checked specifically
    1386              :    in a comparison anyway, since relying on hash differences is unsafe.  */
    1387              : 
    1388              : static hashval_t
    1389    988221824 : cselib_hash_rtx (rtx x, int create, machine_mode memmode)
    1390              : {
    1391    988221824 :   cselib_val *e;
    1392    988221824 :   poly_int64 offset;
    1393    988221824 :   int i, j;
    1394    988221824 :   enum rtx_code code;
    1395    988221824 :   const char *fmt;
    1396    988221824 :   inchash::hash hash;
    1397              : 
    1398    988221824 :   code = GET_CODE (x);
    1399    988221824 :   hash.add_int (code);
    1400    988221824 :   hash.add_int (GET_MODE (x));
    1401              : 
    1402    988221824 :   switch (code)
    1403              :     {
    1404       428595 :     case VALUE:
    1405       428595 :       e = CSELIB_VAL_PTR (x);
    1406       428595 :       return e->hash;
    1407              : 
    1408    215928419 :     case MEM:
    1409    215928419 :     case REG:
    1410    215928419 :       e = cselib_lookup (x, GET_MODE (x), create, memmode);
    1411    215928419 :       if (! e)
    1412              :         return 0;
    1413              : 
    1414    191654673 :       return e->hash;
    1415              : 
    1416     13679416 :     case DEBUG_EXPR:
    1417     13679416 :       hash.add_int (DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x)));
    1418     13679416 :       return hash.end () ? hash.end() : (unsigned int) DEBUG_EXPR;
    1419              : 
    1420      2831196 :     case DEBUG_IMPLICIT_PTR:
    1421      2831196 :       hash.add_int (DECL_UID (DEBUG_IMPLICIT_PTR_DECL (x)));
    1422      2831196 :       return hash.end () ? hash.end () : (unsigned int) DEBUG_IMPLICIT_PTR;
    1423              : 
    1424        39906 :     case DEBUG_PARAMETER_REF:
    1425        39906 :       hash.add_int (DECL_UID (DEBUG_PARAMETER_REF_DECL (x)));
    1426        39906 :       return hash.end () ? hash.end () : (unsigned int) DEBUG_PARAMETER_REF;
    1427              : 
    1428      1382342 :     case ENTRY_VALUE:
    1429              :       /* ENTRY_VALUEs are function invariant, thus try to avoid
    1430              :          recursing on argument if ENTRY_VALUE is one of the
    1431              :          forms emitted by expand_debug_expr, otherwise
    1432              :          ENTRY_VALUE hash would depend on the current value
    1433              :          in some register or memory.  */
    1434      1382342 :       if (REG_P (ENTRY_VALUE_EXP (x)))
    1435      1365085 :         hash.add_int ((unsigned int) REG
    1436      1365085 :                       + (unsigned int) GET_MODE (ENTRY_VALUE_EXP (x))
    1437      1365085 :                       + (unsigned int) REGNO (ENTRY_VALUE_EXP (x)));
    1438        17257 :       else if (MEM_P (ENTRY_VALUE_EXP (x))
    1439        17257 :                && REG_P (XEXP (ENTRY_VALUE_EXP (x), 0)))
    1440        17257 :         hash.add_int ((unsigned int) MEM
    1441        17257 :                       + (unsigned int) GET_MODE (XEXP (ENTRY_VALUE_EXP (x), 0))
    1442        17257 :                       + (unsigned int) REGNO (XEXP (ENTRY_VALUE_EXP (x), 0)));
    1443              :       else
    1444            0 :         hash.add_int (cselib_hash_rtx (ENTRY_VALUE_EXP (x), create, memmode));
    1445      1382342 :       return hash.end () ? hash.end () : (unsigned int) ENTRY_VALUE;
    1446              : 
    1447    171638286 :     case CONST_INT:
    1448    171638286 :       hash.add_hwi (UINTVAL (x));
    1449    171638286 :       return hash.end () ? hash.end () : (unsigned int) CONST_INT;
    1450              : 
    1451              :     case CONST_WIDE_INT:
    1452      2921844 :       for (i = 0; i < CONST_WIDE_INT_NUNITS (x); i++)
    1453      1949745 :         hash.add_hwi (CONST_WIDE_INT_ELT (x, i));
    1454       972099 :       return hash.end () ? hash.end () : (unsigned int) CONST_WIDE_INT;
    1455              : 
    1456              :     case CONST_POLY_INT:
    1457              :       {
    1458            0 :         for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
    1459            0 :           hash.add_wide_int (CONST_POLY_INT_COEFFS (x)[i]);
    1460            0 :         return hash.end () ? hash.end () : (unsigned int) CONST_POLY_INT;
    1461              :       }
    1462              : 
    1463      3493282 :     case CONST_DOUBLE:
    1464              :       /* This is like the general case, except that it only counts
    1465              :          the integers representing the constant.  */
    1466      3493282 :       if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (x) == VOIDmode)
    1467              :         {
    1468              :           hash.add_hwi (CONST_DOUBLE_LOW (x));
    1469              :           hash.add_hwi (CONST_DOUBLE_HIGH (x));
    1470              :         }
    1471              :       else
    1472      3493282 :         hash.merge_hash (real_hash (CONST_DOUBLE_REAL_VALUE (x)));
    1473      3493282 :       return hash.end () ? hash.end () : (unsigned int) CONST_DOUBLE;
    1474              : 
    1475            0 :     case CONST_FIXED:
    1476            0 :       hash.merge_hash (fixed_hash (CONST_FIXED_VALUE (x)));
    1477            0 :       return hash.end () ? hash.end () : (unsigned int) CONST_FIXED;
    1478              : 
    1479      3109311 :     case CONST_VECTOR:
    1480      3109311 :       {
    1481      3109311 :         int units;
    1482      3109311 :         rtx elt;
    1483              : 
    1484      3109311 :         units = const_vector_encoded_nelts (x);
    1485              : 
    1486      8081878 :         for (i = 0; i < units; ++i)
    1487              :           {
    1488      4972567 :             elt = CONST_VECTOR_ENCODED_ELT (x, i);
    1489      4972567 :             hash.merge_hash (cselib_hash_rtx (elt, 0, memmode));
    1490              :           }
    1491              : 
    1492      3109311 :         return hash.end () ? hash.end () : (unsigned int) CONST_VECTOR;
    1493              :       }
    1494              : 
    1495              :       /* Assume there is only one rtx object for any given label.  */
    1496       136245 :     case LABEL_REF:
    1497              :       /* We don't hash on the address of the CODE_LABEL to avoid bootstrap
    1498              :          differences and differences between each stage's debugging dumps.  */
    1499       136245 :       hash.add_int (CODE_LABEL_NUMBER (label_ref_label (x)));
    1500       136245 :       return hash.end () ? hash.end () : (unsigned int) LABEL_REF;
    1501              : 
    1502     64884734 :     case SYMBOL_REF:
    1503     64884734 :       {
    1504              :         /* Don't hash on the symbol's address to avoid bootstrap differences.
    1505              :            Different hash values may cause expressions to be recorded in
    1506              :            different orders and thus different registers to be used in the
    1507              :            final assembler.  This also avoids differences in the dump files
    1508              :            between various stages.  */
    1509     64884734 :         const char *p = (const char *) XSTR (x, 0);
    1510              : 
    1511     64884734 :         if (*p)
    1512     64884734 :           hash.add (p, strlen (p));
    1513              : 
    1514     64884734 :         return hash.end () ? hash.end () : (unsigned int) SYMBOL_REF;
    1515              :       }
    1516              : 
    1517     17585903 :     case PRE_DEC:
    1518     17585903 :     case PRE_INC:
    1519     17585903 :       {
    1520              :         /* We can't compute these without knowing the MEM mode.  */
    1521     17585903 :         gcc_assert (memmode != VOIDmode);
    1522     35171806 :         offset = GET_MODE_SIZE (memmode);
    1523     17585903 :         if (code == PRE_DEC)
    1524     17585903 :           offset = -offset;
    1525              :         /* Adjust the hash so that (mem:MEMMODE (pre_* (reg))) hashes
    1526              :            like (mem:MEMMODE (plus (reg) (const_int I))).  */
    1527     17585903 :         if (GET_MODE (x) == Pmode
    1528     17585903 :             && (REG_P (XEXP (x, 0))
    1529              :                 || MEM_P (XEXP (x, 0))
    1530              :                 || GET_CODE (XEXP (x, 0)) == VALUE))
    1531              :           {
    1532     17585903 :             HOST_WIDE_INT c;
    1533     17585903 :             if (offset.is_constant (&c))
    1534     17585903 :               return cselib_hash_plus_const_int (XEXP (x, 0),
    1535              :                                                  trunc_int_for_mode (c, Pmode),
    1536              :                                                  create, memmode);
    1537              :           }
    1538              : 
    1539            0 :         hashval_t tem_hash = cselib_hash_rtx (XEXP (x, 0), create, memmode);
    1540            0 :         if (tem_hash == 0)
    1541              :           return 0;
    1542            0 :         hash.merge_hash (tem_hash);
    1543            0 :         tem_hash = cselib_hash_rtx (gen_int_mode (offset, GET_MODE (x)),
    1544              :                                     create, memmode);
    1545            0 :         if (tem_hash == 0)
    1546              :           return 0;
    1547            0 :         hash.merge_hash (tem_hash);
    1548            0 :         return hash.end () ? hash.end () : 1 + (unsigned) PLUS;
    1549              :       }
    1550              : 
    1551       508441 :     case PRE_MODIFY:
    1552       508441 :       {
    1553       508441 :         gcc_assert (memmode != VOIDmode);
    1554       508441 :         hashval_t tem_hash = cselib_hash_rtx (XEXP (x, 1), create, memmode);
    1555       508441 :         if (tem_hash == 0)
    1556              :           return 0;
    1557       501857 :         hash.merge_hash (tem_hash);
    1558       501857 :         return hash.end () ? hash.end () : 1 + (unsigned) PRE_MODIFY;
    1559              :       }
    1560              : 
    1561      1790377 :     case POST_DEC:
    1562      1790377 :     case POST_INC:
    1563      1790377 :     case POST_MODIFY:
    1564      1790377 :       {
    1565      1790377 :         gcc_assert (memmode != VOIDmode);
    1566      1790377 :         hashval_t tem_hash = cselib_hash_rtx (XEXP (x, 0), create, memmode);
    1567      1790377 :         if (tem_hash == 0)
    1568              :           return 0;
    1569      1790377 :         hash.merge_hash (tem_hash);
    1570      1790377 :         return hash.end () ? hash.end () : 1 + (unsigned) code;
    1571              :       }
    1572              : 
    1573              :     case PC:
    1574              :     case CALL:
    1575              :     case UNSPEC_VOLATILE:
    1576              :       return 0;
    1577              : 
    1578       468018 :     case ASM_OPERANDS:
    1579       468018 :       if (MEM_VOLATILE_P (x))
    1580              :         return 0;
    1581              : 
    1582              :       break;
    1583              : 
    1584    321014127 :     case PLUS:
    1585    321014127 :       if (GET_MODE (x) == Pmode
    1586    310173652 :           && (REG_P (XEXP (x, 0))
    1587              :               || MEM_P (XEXP (x, 0))
    1588              :               || GET_CODE (XEXP (x, 0)) == VALUE)
    1589    606198470 :           && CONST_INT_P (XEXP (x, 1)))
    1590    266598845 :         return cselib_hash_plus_const_int (XEXP (x, 0), INTVAL (XEXP (x, 1)),
    1591    266598845 :                                            create, memmode);
    1592              :       break;
    1593              : 
    1594              :     default:
    1595              :       break;
    1596              :     }
    1597              : 
    1598    208116744 :   i = GET_RTX_LENGTH (code) - 1;
    1599    208116744 :   fmt = GET_RTX_FORMAT (code);
    1600              : 
    1601    208116744 :   if (COMMUTATIVE_P (x))
    1602              :     {
    1603     79157828 :       gcc_assert (i == 1 && fmt[0] == 'e' && fmt[1] == 'e');
    1604     79157828 :       hashval_t tem1_hash = cselib_hash_rtx (XEXP (x, 1), create, memmode);
    1605     79157828 :       if (tem1_hash == 0)
    1606              :         return 0;
    1607     73703657 :       hashval_t tem0_hash = cselib_hash_rtx (XEXP (x, 0), create, memmode);
    1608     73703657 :       if (tem0_hash == 0)
    1609              :         return 0;
    1610     70017554 :       hash.add_commutative (tem0_hash, tem1_hash);
    1611     70017554 :       return hash.end () ? hash.end () : 1 + (unsigned int) GET_CODE (x);
    1612              :     }
    1613              : 
    1614    339457509 :   for (; i >= 0; i--)
    1615              :     {
    1616    228520822 :       switch (fmt[i])
    1617              :         {
    1618    207637218 :         case 'e':
    1619    207637218 :           {
    1620    207637218 :             rtx tem = XEXP (x, i);
    1621    207637218 :             hashval_t tem_hash = cselib_hash_rtx (tem, create, memmode);
    1622    207637218 :             if (tem_hash == 0)
    1623              :               return 0;
    1624    190550781 :             hash.merge_hash (tem_hash);
    1625              :           }
    1626    190550781 :           break;
    1627              :         case 'E':
    1628     26432426 :           for (j = 0; j < XVECLEN (x, i); j++)
    1629              :             {
    1630     18543078 :               hashval_t tem_hash
    1631     18543078 :                 = cselib_hash_rtx (XVECEXP (x, i, j), create, memmode);
    1632     18543078 :               if (tem_hash == 0)
    1633              :                 return 0;
    1634     17607286 :               hash.merge_hash (tem_hash);
    1635              :             }
    1636              :           break;
    1637              : 
    1638       594566 :         case 's':
    1639       594566 :           {
    1640       594566 :             const char *p = (const char *) XSTR (x, i);
    1641              : 
    1642       594566 :             if (p && *p)
    1643       560572 :               hash.add (p, strlen (p));
    1644              :             break;
    1645              :           }
    1646              : 
    1647      5348503 :         case 'i':
    1648      5348503 :           hash.add_hwi (XINT (x, i));
    1649      5348503 :           break;
    1650              : 
    1651       244771 :         case 'L':
    1652       244771 :           hash.add_hwi (XLOC (x, i));
    1653       244771 :           break;
    1654              : 
    1655      5870624 :         case 'p':
    1656      5870624 :           hash.add_int (constant_lower_bound (SUBREG_BYTE (x)));
    1657      5870624 :           break;
    1658              : 
    1659              :         case '0':
    1660              :         case 't':
    1661              :           /* unused */
    1662              :           break;
    1663              : 
    1664            0 :         default:
    1665            0 :           gcc_unreachable ();
    1666              :         }
    1667              :     }
    1668              : 
    1669    110936687 :   return hash.end () ? hash.end () : 1 + (unsigned int) GET_CODE (x);
    1670              : }
    1671              : 
    1672              : /* Create a new value structure for VALUE and initialize it.  The mode of the
    1673              :    value is MODE.  */
    1674              : 
    1675              : static inline cselib_val *
    1676    417461539 : new_cselib_val (hashval_t hash, machine_mode mode, rtx x)
    1677              : {
    1678    417461539 :   cselib_val *e = cselib_val_pool.allocate ();
    1679              : 
    1680    417461539 :   gcc_assert (hash);
    1681    417461539 :   gcc_assert (next_uid);
    1682              : 
    1683    417461539 :   e->hash = hash;
    1684    417461539 :   e->in_preserved_table_p = false;
    1685    417461539 :   e->all_locs_preserved_p = false;
    1686    417461539 :   e->uid = next_uid++;
    1687              :   /* We use an alloc pool to allocate this RTL construct because it
    1688              :      accounts for about 8% of the overall memory usage.  We know
    1689              :      precisely when we can have VALUE RTXen (when cselib is active)
    1690              :      so we don't need to put them in garbage collected memory.
    1691              :      ??? Why should a VALUE be an RTX in the first place?  */
    1692    417461539 :   e->val_rtx = (rtx_def*) value_pool.allocate ();
    1693    417461539 :   memset (e->val_rtx, 0, RTX_HDR_SIZE);
    1694    417461539 :   PUT_CODE (e->val_rtx, VALUE);
    1695    417461539 :   PUT_MODE (e->val_rtx, mode);
    1696    417461539 :   CSELIB_VAL_PTR (e->val_rtx) = e;
    1697    417461539 :   e->addr_list = 0;
    1698    417461539 :   e->locs = 0;
    1699    417461539 :   e->next_containing_mem = 0;
    1700              : 
    1701    417461539 :   scalar_int_mode int_mode;
    1702    544186027 :   if (REG_P (x) && is_int_mode (mode, &int_mode)
    1703    126724488 :       && GET_MODE_SIZE (int_mode) > 1
    1704    120716347 :       && REG_VALUES (REGNO (x)) != NULL
    1705    424286999 :       && (!cselib_current_insn || !DEBUG_INSN_P (cselib_current_insn)))
    1706              :     {
    1707      6677096 :       rtx copy = shallow_copy_rtx (x);
    1708      6677096 :       scalar_int_mode narrow_mode_iter;
    1709     23984793 :       FOR_EACH_MODE_UNTIL (narrow_mode_iter, int_mode)
    1710              :         {
    1711     17307697 :           PUT_MODE_RAW (copy, narrow_mode_iter);
    1712     17307697 :           cselib_val *v = cselib_lookup (copy, narrow_mode_iter, 0, VOIDmode);
    1713     17307697 :           if (v)
    1714              :             {
    1715       758793 :               rtx sub = lowpart_subreg (narrow_mode_iter, e->val_rtx, int_mode);
    1716       758793 :               if (sub)
    1717       758793 :                 new_elt_loc_list (v, sub);
    1718              :             }
    1719              :         }
    1720              :     }
    1721              : 
    1722    417461539 :   if (dump_file && (dump_flags & TDF_CSELIB))
    1723              :     {
    1724            0 :       fprintf (dump_file, "cselib value %u:%u ", e->uid, hash);
    1725            0 :       if (flag_dump_noaddr || flag_dump_unnumbered)
    1726            0 :         fputs ("# ", dump_file);
    1727              :       else
    1728            0 :         fprintf (dump_file, "%p ", (void*)e);
    1729            0 :       print_rtl_single (dump_file, x);
    1730            0 :       fputc ('\n', dump_file);
    1731              :     }
    1732              : 
    1733    417461539 :   return e;
    1734              : }
    1735              : 
    1736              : /* ADDR_ELT is a value that is used as address.  MEM_ELT is the value that
    1737              :    contains the data at this address.  X is a MEM that represents the
    1738              :    value.  Update the two value structures to represent this situation.  */
    1739              : 
    1740              : static void
    1741     52765706 : add_mem_for_addr (cselib_val *addr_elt, cselib_val *mem_elt, rtx x)
    1742              : {
    1743     52765706 :   addr_elt = canonical_cselib_val (addr_elt);
    1744     52765706 :   mem_elt = canonical_cselib_val (mem_elt);
    1745              : 
    1746              :   /* Avoid duplicates.  */
    1747     52765706 :   addr_space_t as = MEM_ADDR_SPACE (x);
    1748     95112499 :   for (elt_loc_list *l = mem_elt->locs; l; l = l->next)
    1749     42346793 :     if (MEM_P (l->loc)
    1750     12982752 :         && CSELIB_VAL_PTR (XEXP (l->loc, 0)) == addr_elt
    1751     42346793 :         && MEM_ADDR_SPACE (l->loc) == as)
    1752              :       {
    1753            0 :         promote_debug_loc (l);
    1754            0 :         return;
    1755              :       }
    1756              : 
    1757     52765706 :   addr_elt->addr_list = new_elt_list (addr_elt->addr_list, mem_elt);
    1758     52765706 :   new_elt_loc_list (mem_elt,
    1759              :                     replace_equiv_address_nv (x, addr_elt->val_rtx));
    1760     52765706 :   if (mem_elt->next_containing_mem == NULL)
    1761              :     {
    1762     46209069 :       mem_elt->next_containing_mem = first_containing_mem;
    1763     46209069 :       first_containing_mem = mem_elt;
    1764              :     }
    1765              : }
    1766              : 
    1767              : /* Subroutine of cselib_lookup.  Return a value for X, which is a MEM rtx.
    1768              :    If CREATE, make a new one if we haven't seen it before.  */
    1769              : 
    1770              : static cselib_val *
    1771    239327955 : cselib_lookup_mem (rtx x, int create)
    1772              : {
    1773    239327955 :   machine_mode mode = GET_MODE (x);
    1774    239327955 :   machine_mode addr_mode;
    1775    239327955 :   cselib_val **slot;
    1776    239327955 :   cselib_val *addr;
    1777    239327955 :   cselib_val *mem_elt;
    1778              : 
    1779    474908603 :   if (MEM_VOLATILE_P (x) || mode == BLKmode
    1780    235381851 :       || !cselib_record_memory
    1781    428819892 :       || (FLOAT_MODE_P (mode) && flag_float_store))
    1782              :     return 0;
    1783              : 
    1784    189479277 :   addr_mode = GET_MODE (XEXP (x, 0));
    1785    189479277 :   if (addr_mode == VOIDmode)
    1786      1299265 :     addr_mode = Pmode;
    1787              : 
    1788              :   /* Look up the value for the address.  */
    1789    189479277 :   addr = cselib_lookup (XEXP (x, 0), addr_mode, create, mode);
    1790    189479277 :   if (! addr)
    1791              :     return 0;
    1792    116844656 :   addr = canonical_cselib_val (addr);
    1793              : 
    1794              :   /* Find a value that describes a value of our mode at that address.  */
    1795    116844656 :   addr_space_t as = MEM_ADDR_SPACE (x);
    1796    119276026 :   for (elt_list *l = addr->addr_list; l; l = l->next)
    1797     73937568 :     if (GET_MODE (l->elt->val_rtx) == mode)
    1798              :       {
    1799     77892045 :         for (elt_loc_list *l2 = l->elt->locs; l2; l2 = l2->next)
    1800     81987710 :           if (MEM_P (l2->loc) && MEM_ADDR_SPACE (l2->loc) == as)
    1801              :             {
    1802     71506198 :               promote_debug_loc (l->elt->locs);
    1803     71506198 :               return l->elt;
    1804              :             }
    1805              :       }
    1806              : 
    1807     45338458 :   if (! create)
    1808              :     return 0;
    1809              : 
    1810     28426529 :   mem_elt = new_cselib_val (next_uid, mode, x);
    1811     28426529 :   add_mem_for_addr (addr, mem_elt, x);
    1812     28426529 :   slot = cselib_find_slot (mode, x, mem_elt->hash, INSERT, VOIDmode);
    1813     28426529 :   *slot = mem_elt;
    1814     28426529 :   return mem_elt;
    1815              : }
    1816              : 
    1817              : /* Search through the possible substitutions in P.  We prefer a non reg
    1818              :    substitution because this allows us to expand the tree further.  If
    1819              :    we find, just a reg, take the lowest regno.  There may be several
    1820              :    non-reg results, we just take the first one because they will all
    1821              :    expand to the same place.  */
    1822              : 
    1823              : static rtx
    1824     24523158 : expand_loc (struct elt_loc_list *p, struct expand_value_data *evd,
    1825              :             int max_depth)
    1826              : {
    1827     24523158 :   rtx reg_result = NULL;
    1828     24523158 :   unsigned int regno = UINT_MAX;
    1829     24523158 :   struct elt_loc_list *p_in = p;
    1830              : 
    1831     53278912 :   for (; p; p = p->next)
    1832              :     {
    1833              :       /* Return these right away to avoid returning stack pointer based
    1834              :          expressions for frame pointer and vice versa, which is something
    1835              :          that would confuse DSE.  See the comment in cselib_expand_value_rtx_1
    1836              :          for more details.  */
    1837     32712376 :       if (REG_P (p->loc)
    1838     32712376 :           && (REGNO (p->loc) == STACK_POINTER_REGNUM
    1839              :               || REGNO (p->loc) == FRAME_POINTER_REGNUM
    1840              :               || REGNO (p->loc) == HARD_FRAME_POINTER_REGNUM
    1841     25955874 :               || REGNO (p->loc) == cfa_base_preserved_regno))
    1842              :         return p->loc;
    1843              :       /* Avoid infinite recursion trying to expand a reg into a
    1844              :          the same reg.  */
    1845     32205276 :       if ((REG_P (p->loc))
    1846     25950319 :           && (REGNO (p->loc) < regno)
    1847     57851163 :           && !bitmap_bit_p (evd->regs_active, REGNO (p->loc)))
    1848              :         {
    1849      4534570 :           reg_result = p->loc;
    1850      4534570 :           regno = REGNO (p->loc);
    1851              :         }
    1852              :       /* Avoid infinite recursion and do not try to expand the
    1853              :          value.  */
    1854     27670706 :       else if (GET_CODE (p->loc) == VALUE
    1855       351865 :                && CSELIB_VAL_PTR (p->loc)->locs == p_in)
    1856            0 :         continue;
    1857     27670706 :       else if (!REG_P (p->loc))
    1858              :         {
    1859      6254957 :           rtx result, note;
    1860      6254957 :           if (dump_file && (dump_flags & TDF_CSELIB))
    1861              :             {
    1862            0 :               print_inline_rtx (dump_file, p->loc, 0);
    1863            0 :               fprintf (dump_file, "\n");
    1864              :             }
    1865      6254957 :           if (GET_CODE (p->loc) == LO_SUM
    1866            0 :               && GET_CODE (XEXP (p->loc, 1)) == SYMBOL_REF
    1867            0 :               && p->setting_insn
    1868            0 :               && (note = find_reg_note (p->setting_insn, REG_EQUAL, NULL_RTX))
    1869      6254957 :               && XEXP (note, 0) == XEXP (p->loc, 1))
    1870              :             return XEXP (p->loc, 1);
    1871      6254957 :           result = cselib_expand_value_rtx_1 (p->loc, evd, max_depth - 1);
    1872      6254957 :           if (result)
    1873              :             return result;
    1874              :         }
    1875              : 
    1876              :     }
    1877              : 
    1878     20566536 :   if (regno != UINT_MAX)
    1879              :     {
    1880      3776172 :       rtx result;
    1881      3776172 :       if (dump_file && (dump_flags & TDF_CSELIB))
    1882            0 :         fprintf (dump_file, "r%d\n", regno);
    1883              : 
    1884      3776172 :       result = cselib_expand_value_rtx_1 (reg_result, evd, max_depth - 1);
    1885      3776172 :       if (result)
    1886              :         return result;
    1887              :     }
    1888              : 
    1889     17719440 :   if (dump_file && (dump_flags & TDF_CSELIB))
    1890              :     {
    1891            0 :       if (reg_result)
    1892              :         {
    1893            0 :           print_inline_rtx (dump_file, reg_result, 0);
    1894            0 :           fprintf (dump_file, "\n");
    1895              :         }
    1896              :       else
    1897            0 :         fprintf (dump_file, "NULL\n");
    1898              :     }
    1899              :   return reg_result;
    1900              : }
    1901              : 
    1902              : 
    1903              : /* Forward substitute and expand an expression out to its roots.
    1904              :    This is the opposite of common subexpression.  Because local value
    1905              :    numbering is such a weak optimization, the expanded expression is
    1906              :    pretty much unique (not from a pointer equals point of view but
    1907              :    from a tree shape point of view.
    1908              : 
    1909              :    This function returns NULL if the expansion fails.  The expansion
    1910              :    will fail if there is no value number for one of the operands or if
    1911              :    one of the operands has been overwritten between the current insn
    1912              :    and the beginning of the basic block.  For instance x has no
    1913              :    expansion in:
    1914              : 
    1915              :    r1 <- r1 + 3
    1916              :    x <- r1 + 8
    1917              : 
    1918              :    REGS_ACTIVE is a scratch bitmap that should be clear when passing in.
    1919              :    It is clear on return.  */
    1920              : 
    1921              : rtx
    1922     37381323 : cselib_expand_value_rtx (rtx orig, bitmap regs_active, int max_depth)
    1923              : {
    1924     37381323 :   struct expand_value_data evd;
    1925              : 
    1926     37381323 :   evd.regs_active = regs_active;
    1927     37381323 :   evd.callback = NULL;
    1928     37381323 :   evd.callback_arg = NULL;
    1929     37381323 :   evd.dummy = false;
    1930              : 
    1931     37381323 :   return cselib_expand_value_rtx_1 (orig, &evd, max_depth);
    1932              : }
    1933              : 
    1934              : /* Same as cselib_expand_value_rtx, but using a callback to try to
    1935              :    resolve some expressions.  The CB function should return ORIG if it
    1936              :    can't or does not want to deal with a certain RTX.  Any other
    1937              :    return value, including NULL, will be used as the expansion for
    1938              :    VALUE, without any further changes.  */
    1939              : 
    1940              : rtx
    1941     90203768 : cselib_expand_value_rtx_cb (rtx orig, bitmap regs_active, int max_depth,
    1942              :                             cselib_expand_callback cb, void *data)
    1943              : {
    1944     90203768 :   struct expand_value_data evd;
    1945              : 
    1946     90203768 :   evd.regs_active = regs_active;
    1947     90203768 :   evd.callback = cb;
    1948     90203768 :   evd.callback_arg = data;
    1949     90203768 :   evd.dummy = false;
    1950              : 
    1951     90203768 :   return cselib_expand_value_rtx_1 (orig, &evd, max_depth);
    1952              : }
    1953              : 
    1954              : /* Similar to cselib_expand_value_rtx_cb, but no rtxs are actually copied
    1955              :    or simplified.  Useful to find out whether cselib_expand_value_rtx_cb
    1956              :    would return NULL or non-NULL, without allocating new rtx.  */
    1957              : 
    1958              : bool
    1959            0 : cselib_dummy_expand_value_rtx_cb (rtx orig, bitmap regs_active, int max_depth,
    1960              :                                   cselib_expand_callback cb, void *data)
    1961              : {
    1962            0 :   struct expand_value_data evd;
    1963              : 
    1964            0 :   evd.regs_active = regs_active;
    1965            0 :   evd.callback = cb;
    1966            0 :   evd.callback_arg = data;
    1967            0 :   evd.dummy = true;
    1968              : 
    1969            0 :   return cselib_expand_value_rtx_1 (orig, &evd, max_depth) != NULL;
    1970              : }
    1971              : 
    1972              : /* Internal implementation of cselib_expand_value_rtx and
    1973              :    cselib_expand_value_rtx_cb.  */
    1974              : 
    1975              : static rtx
    1976    209681451 : cselib_expand_value_rtx_1 (rtx orig, struct expand_value_data *evd,
    1977              :                            int max_depth)
    1978              : {
    1979    209681451 :   rtx copy, scopy;
    1980    209681451 :   int i, j;
    1981    209681451 :   RTX_CODE code;
    1982    209681451 :   const char *format_ptr;
    1983    209681451 :   machine_mode mode;
    1984              : 
    1985    209681451 :   code = GET_CODE (orig);
    1986              : 
    1987              :   /* For the context of dse, if we end up expand into a huge tree, we
    1988              :      will not have a useful address, so we might as well just give up
    1989              :      quickly.  */
    1990    209681451 :   if (max_depth <= 0)
    1991              :     return NULL;
    1992              : 
    1993    206851775 :   switch (code)
    1994              :     {
    1995     51189549 :     case REG:
    1996     51189549 :       {
    1997     51189549 :         struct elt_list *l = REG_VALUES (REGNO (orig));
    1998              : 
    1999     51189549 :         if (l && l->elt == NULL)
    2000     25305159 :           l = l->next;
    2001     51204549 :         for (; l; l = l->next)
    2002     38460320 :           if (GET_MODE (l->elt->val_rtx) == GET_MODE (orig))
    2003              :             {
    2004     38445320 :               rtx result;
    2005     38445320 :               unsigned regno = REGNO (orig);
    2006              : 
    2007              :               /* The only thing that we are not willing to do (this
    2008              :                  is requirement of dse and if others potential uses
    2009              :                  need this function we should add a parm to control
    2010              :                  it) is that we will not substitute the
    2011              :                  STACK_POINTER_REGNUM, FRAME_POINTER or the
    2012              :                  HARD_FRAME_POINTER.
    2013              : 
    2014              :                  These expansions confuses the code that notices that
    2015              :                  stores into the frame go dead at the end of the
    2016              :                  function and that the frame is not effected by calls
    2017              :                  to subroutines.  If you allow the
    2018              :                  STACK_POINTER_REGNUM substitution, then dse will
    2019              :                  think that parameter pushing also goes dead which is
    2020              :                  wrong.  If you allow the FRAME_POINTER or the
    2021              :                  HARD_FRAME_POINTER then you lose the opportunity to
    2022              :                  make the frame assumptions.  */
    2023     38445320 :               if (regno == STACK_POINTER_REGNUM
    2024     38445320 :                   || regno == FRAME_POINTER_REGNUM
    2025     20782782 :                   || regno == HARD_FRAME_POINTER_REGNUM
    2026     20272825 :                   || regno == cfa_base_preserved_regno)
    2027              :                 return orig;
    2028              : 
    2029     19968473 :               bitmap_set_bit (evd->regs_active, regno);
    2030              : 
    2031     19968473 :               if (dump_file && (dump_flags & TDF_CSELIB))
    2032            0 :                 fprintf (dump_file, "expanding: r%d into: ", regno);
    2033              : 
    2034     19968473 :               result = expand_loc (l->elt->locs, evd, max_depth);
    2035     19968473 :               bitmap_clear_bit (evd->regs_active, regno);
    2036              : 
    2037     19968473 :               if (result)
    2038              :                 return result;
    2039              :               else
    2040              :                 return orig;
    2041              :             }
    2042              :         return orig;
    2043              :       }
    2044              : 
    2045              :     CASE_CONST_ANY:
    2046              :     case SYMBOL_REF:
    2047              :     case CODE_LABEL:
    2048              :     case PC:
    2049              :     case SCRATCH:
    2050              :       /* SCRATCH must be shared because they represent distinct values.  */
    2051              :       return orig;
    2052            0 :     case CLOBBER:
    2053            0 :       if (REG_P (XEXP (orig, 0)) && HARD_REGISTER_NUM_P (REGNO (XEXP (orig, 0))))
    2054              :         return orig;
    2055              :       break;
    2056              : 
    2057       285845 :     case CONST:
    2058       285845 :       if (shared_const_p (orig))
    2059              :         return orig;
    2060              :       break;
    2061              : 
    2062       929136 :     case SUBREG:
    2063       929136 :       {
    2064       929136 :         rtx subreg;
    2065              : 
    2066       929136 :         if (evd->callback)
    2067              :           {
    2068       836822 :             subreg = evd->callback (orig, evd->regs_active, max_depth,
    2069              :                                     evd->callback_arg);
    2070       836822 :             if (subreg != orig)
    2071              :               return subreg;
    2072              :           }
    2073              : 
    2074        92314 :         subreg = cselib_expand_value_rtx_1 (SUBREG_REG (orig), evd,
    2075              :                                             max_depth - 1);
    2076        92314 :         if (!subreg)
    2077              :           return NULL;
    2078       100972 :         scopy = simplify_gen_subreg (GET_MODE (orig), subreg,
    2079        50486 :                                      GET_MODE (SUBREG_REG (orig)),
    2080        50486 :                                      SUBREG_BYTE (orig));
    2081        50486 :         if (scopy == NULL
    2082        49404 :             || (GET_CODE (scopy) == SUBREG
    2083        45447 :                 && !REG_P (SUBREG_REG (scopy))
    2084         5890 :                 && !MEM_P (SUBREG_REG (scopy))))
    2085              :           return NULL;
    2086              : 
    2087              :         return scopy;
    2088              :       }
    2089              : 
    2090     72318982 :     case VALUE:
    2091     72318982 :       {
    2092     72318982 :         rtx result;
    2093              : 
    2094     72318982 :         if (dump_file && (dump_flags & TDF_CSELIB))
    2095              :           {
    2096            0 :             fputs ("\nexpanding ", dump_file);
    2097            0 :             print_rtl_single (dump_file, orig);
    2098            0 :             fputs (" into...", dump_file);
    2099              :           }
    2100              : 
    2101     72318982 :         if (evd->callback)
    2102              :           {
    2103     67764297 :             result = evd->callback (orig, evd->regs_active, max_depth,
    2104              :                                     evd->callback_arg);
    2105              : 
    2106     67764297 :             if (result != orig)
    2107              :               return result;
    2108              :           }
    2109              : 
    2110      4554685 :         result = expand_loc (CSELIB_VAL_PTR (orig)->locs, evd, max_depth);
    2111      4554685 :         return result;
    2112              :       }
    2113              : 
    2114      6269791 :     case DEBUG_EXPR:
    2115      6269791 :       if (evd->callback)
    2116      6269791 :         return evd->callback (orig, evd->regs_active, max_depth,
    2117      6269791 :                               evd->callback_arg);
    2118              :       return orig;
    2119              : 
    2120              :     default:
    2121              :       break;
    2122              :     }
    2123              : 
    2124              :   /* Copy the various flags, fields, and other information.  We assume
    2125              :      that all fields need copying, and then clear the fields that should
    2126              :      not be copied.  That is the sensible default behavior, and forces
    2127              :      us to explicitly document why we are *not* copying a flag.  */
    2128     45486018 :   if (evd->dummy)
    2129              :     copy = NULL;
    2130              :   else
    2131     45486018 :     copy = shallow_copy_rtx (orig);
    2132              : 
    2133     45486018 :   format_ptr = GET_RTX_FORMAT (code);
    2134              : 
    2135    119488860 :   for (i = 0; i < GET_RTX_LENGTH (code); i++)
    2136     78271202 :     switch (*format_ptr++)
    2137              :       {
    2138     71496211 :       case 'e':
    2139     71496211 :         if (XEXP (orig, i) != NULL)
    2140              :           {
    2141     71496211 :             rtx result = cselib_expand_value_rtx_1 (XEXP (orig, i), evd,
    2142              :                                                     max_depth - 1);
    2143     71496211 :             if (!result)
    2144              :               return NULL;
    2145     67261815 :             if (copy)
    2146     67261815 :               XEXP (copy, i) = result;
    2147              :           }
    2148              :         break;
    2149              : 
    2150       298437 :       case 'E':
    2151       298437 :       case 'V':
    2152       298437 :         if (XVEC (orig, i) != NULL)
    2153              :           {
    2154       298437 :             if (copy)
    2155       298437 :               XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
    2156       741179 :             for (j = 0; j < XVECLEN (orig, i); j++)
    2157              :               {
    2158       476706 :                 rtx result = cselib_expand_value_rtx_1 (XVECEXP (orig, i, j),
    2159              :                                                         evd, max_depth - 1);
    2160       476706 :                 if (!result)
    2161              :                   return NULL;
    2162       442742 :                 if (copy)
    2163       442742 :                   XVECEXP (copy, i, j) = result;
    2164              :               }
    2165              :           }
    2166              :         break;
    2167              : 
    2168              :       case 't':
    2169              :       case 'w':
    2170              :       case 'i':
    2171              :       case 'L':
    2172              :       case 's':
    2173              :       case 'S':
    2174              :       case 'T':
    2175              :       case 'u':
    2176              :       case 'B':
    2177              :       case '0':
    2178              :         /* These are left unchanged.  */
    2179              :         break;
    2180              : 
    2181            0 :       default:
    2182            0 :         gcc_unreachable ();
    2183              :       }
    2184              : 
    2185     41217658 :   if (evd->dummy)
    2186              :     return orig;
    2187              : 
    2188     41217658 :   mode = GET_MODE (copy);
    2189              :   /* If an operand has been simplified into CONST_INT, which doesn't
    2190              :      have a mode and the mode isn't derivable from whole rtx's mode,
    2191              :      try simplify_*_operation first with mode from original's operand
    2192              :      and as a fallback wrap CONST_INT into gen_rtx_CONST.  */
    2193     41217658 :   scopy = copy;
    2194     41217658 :   switch (GET_RTX_CLASS (code))
    2195              :     {
    2196       744407 :     case RTX_UNARY:
    2197       744407 :       if (CONST_INT_P (XEXP (copy, 0))
    2198        50347 :           && GET_MODE (XEXP (orig, 0)) != VOIDmode)
    2199              :         {
    2200        50339 :           scopy = simplify_unary_operation (code, mode, XEXP (copy, 0),
    2201              :                                             GET_MODE (XEXP (orig, 0)));
    2202        50339 :           if (scopy)
    2203              :             return scopy;
    2204              :         }
    2205              :       break;
    2206              :     case RTX_COMM_ARITH:
    2207              :     case RTX_BIN_ARITH:
    2208              :       /* These expressions can derive operand modes from the whole rtx's mode.  */
    2209              :       break;
    2210        94716 :     case RTX_TERNARY:
    2211        94716 :     case RTX_BITFIELD_OPS:
    2212        94716 :       if (CONST_INT_P (XEXP (copy, 0))
    2213           77 :           && GET_MODE (XEXP (orig, 0)) != VOIDmode)
    2214              :         {
    2215            1 :           scopy = simplify_ternary_operation (code, mode,
    2216              :                                               GET_MODE (XEXP (orig, 0)),
    2217              :                                               XEXP (copy, 0), XEXP (copy, 1),
    2218              :                                               XEXP (copy, 2));
    2219            1 :           if (scopy)
    2220              :             return scopy;
    2221              :         }
    2222              :       break;
    2223       201912 :     case RTX_COMPARE:
    2224       201912 :     case RTX_COMM_COMPARE:
    2225       201912 :       if (CONST_INT_P (XEXP (copy, 0))
    2226          456 :           && GET_MODE (XEXP (copy, 1)) == VOIDmode
    2227          171 :           && (GET_MODE (XEXP (orig, 0)) != VOIDmode
    2228            5 :               || GET_MODE (XEXP (orig, 1)) != VOIDmode))
    2229              :         {
    2230          171 :           scopy = simplify_relational_operation (code, mode,
    2231              :                                                  (GET_MODE (XEXP (orig, 0))
    2232              :                                                   != VOIDmode)
    2233              :                                                  ? GET_MODE (XEXP (orig, 0))
    2234            5 :                                                  : GET_MODE (XEXP (orig, 1)),
    2235              :                                                  XEXP (copy, 0),
    2236              :                                                  XEXP (copy, 1));
    2237          171 :           if (scopy)
    2238              :             return scopy;
    2239              :         }
    2240              :       break;
    2241              :     default:
    2242              :       break;
    2243              :     }
    2244     41167148 :   scopy = simplify_rtx (copy);
    2245     41167148 :   if (scopy)
    2246      4974729 :     return scopy;
    2247              :   return copy;
    2248              : }
    2249              : 
    2250              : /* Walk rtx X and replace all occurrences of REG and MEM subexpressions
    2251              :    with VALUE expressions.  This way, it becomes independent of changes
    2252              :    to registers and memory.
    2253              :    X isn't actually modified; if modifications are needed, new rtl is
    2254              :    allocated.  However, the return value can share rtl with X.
    2255              :    If X is within a MEM, MEMMODE must be the mode of the MEM.  */
    2256              : 
    2257              : rtx
    2258    588388303 : cselib_subst_to_values (rtx x, machine_mode memmode)
    2259              : {
    2260    596103619 :   enum rtx_code code = GET_CODE (x);
    2261    596103619 :   const char *fmt = GET_RTX_FORMAT (code);
    2262    596103619 :   cselib_val *e;
    2263    596103619 :   struct elt_list *l;
    2264    596103619 :   rtx copy = x;
    2265    596103619 :   int i;
    2266    596103619 :   poly_int64 offset;
    2267              : 
    2268    596103619 :   switch (code)
    2269              :     {
    2270    233275814 :     case REG:
    2271    233275814 :       l = REG_VALUES (REGNO (x));
    2272    233275814 :       if (l && l->elt == NULL)
    2273    133920716 :         l = l->next;
    2274    235536771 :       for (; l; l = l->next)
    2275    235536771 :         if (GET_MODE (l->elt->val_rtx) == GET_MODE (x))
    2276              :           return l->elt->val_rtx;
    2277              : 
    2278            0 :       gcc_unreachable ();
    2279              : 
    2280      6122502 :     case MEM:
    2281      6122502 :       e = cselib_lookup_mem (x, 0);
    2282              :       /* This used to happen for autoincrements, but we deal with them
    2283              :          properly now.  Remove the if stmt for the next release.  */
    2284      6122502 :       if (! e)
    2285              :         {
    2286              :           /* Assign a value that doesn't match any other.  */
    2287            0 :           e = new_cselib_val (next_uid, GET_MODE (x), x);
    2288              :         }
    2289      6122502 :       return e->val_rtx;
    2290              : 
    2291       673989 :     case ENTRY_VALUE:
    2292       673989 :       e = cselib_lookup (x, GET_MODE (x), 0, memmode);
    2293       673989 :       if (! e)
    2294              :         break;
    2295          934 :       return e->val_rtx;
    2296              : 
    2297              :     CASE_CONST_ANY:
    2298              :       return x;
    2299              : 
    2300      6380526 :     case PRE_DEC:
    2301      6380526 :     case PRE_INC:
    2302      6380526 :       gcc_assert (memmode != VOIDmode);
    2303     12761052 :       offset = GET_MODE_SIZE (memmode);
    2304      6380526 :       if (code == PRE_DEC)
    2305      6380526 :         offset = -offset;
    2306      6380526 :       return cselib_subst_to_values (plus_constant (GET_MODE (x),
    2307              :                                                     XEXP (x, 0), offset),
    2308      6380526 :                                      memmode);
    2309              : 
    2310       381577 :     case PRE_MODIFY:
    2311       381577 :       gcc_assert (memmode != VOIDmode);
    2312       381577 :       return cselib_subst_to_values (XEXP (x, 1), memmode);
    2313              : 
    2314       953213 :     case POST_DEC:
    2315       953213 :     case POST_INC:
    2316       953213 :     case POST_MODIFY:
    2317       953213 :       gcc_assert (memmode != VOIDmode);
    2318       953213 :       return cselib_subst_to_values (XEXP (x, 0), memmode);
    2319              : 
    2320    116265167 :     case PLUS:
    2321    151709307 :       if (GET_MODE (x) == Pmode && CONST_INT_P (XEXP (x, 1)))
    2322              :         {
    2323     94433113 :           rtx t = cselib_subst_to_values (XEXP (x, 0), memmode);
    2324     94433113 :           if (GET_CODE (t) == VALUE)
    2325              :             {
    2326     88528100 :               if (SP_DERIVED_VALUE_P (t) && XEXP (x, 1) == const0_rtx)
    2327              :                 return t;
    2328     88528100 :               for (struct elt_loc_list *l = CSELIB_VAL_PTR (t)->locs;
    2329    186995581 :                    l; l = l->next)
    2330    119899952 :                 if (GET_CODE (l->loc) == PLUS
    2331     25226899 :                     && GET_CODE (XEXP (l->loc, 0)) == VALUE
    2332     25008829 :                     && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
    2333    141333677 :                     && CONST_INT_P (XEXP (l->loc, 1)))
    2334     35294253 :                   return plus_constant (Pmode, l->loc, INTVAL (XEXP (x, 1)));
    2335              :             }
    2336     73000642 :           if (t != XEXP (x, 0))
    2337              :             {
    2338     68646965 :               copy = shallow_copy_rtx (x);
    2339     68646965 :               XEXP (copy, 0) = t;
    2340              :             }
    2341     73000642 :           return copy;
    2342              :         }
    2343              : 
    2344              :     default:
    2345              :       break;
    2346              :     }
    2347              : 
    2348    475950115 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    2349              :     {
    2350    310769559 :       if (fmt[i] == 'e')
    2351              :         {
    2352    228544967 :           rtx t = cselib_subst_to_values (XEXP (x, i), memmode);
    2353              : 
    2354    228544967 :           if (t != XEXP (x, i))
    2355              :             {
    2356    167387971 :               if (x == copy)
    2357    118656855 :                 copy = shallow_copy_rtx (x);
    2358    167387971 :               XEXP (copy, i) = t;
    2359              :             }
    2360              :         }
    2361     82224592 :       else if (fmt[i] == 'E')
    2362              :         {
    2363              :           int j;
    2364              : 
    2365     18994274 :           for (j = 0; j < XVECLEN (x, i); j++)
    2366              :             {
    2367     13400553 :               rtx t = cselib_subst_to_values (XVECEXP (x, i, j), memmode);
    2368              : 
    2369     13400553 :               if (t != XVECEXP (x, i, j))
    2370              :                 {
    2371      2579858 :                   if (XVEC (x, i) == XVEC (copy, i))
    2372              :                     {
    2373      1926849 :                       if (x == copy)
    2374      1926849 :                         copy = shallow_copy_rtx (x);
    2375      1926849 :                       XVEC (copy, i) = shallow_copy_rtvec (XVEC (x, i));
    2376              :                     }
    2377      2579858 :                   XVECEXP (copy, i, j) = t;
    2378              :                 }
    2379              :             }
    2380              :         }
    2381              :     }
    2382              : 
    2383              :   return copy;
    2384              : }
    2385              : 
    2386              : /* Wrapper for cselib_subst_to_values, that indicates X is in INSN.  */
    2387              : 
    2388              : rtx
    2389         1463 : cselib_subst_to_values_from_insn (rtx x, machine_mode memmode, rtx_insn *insn)
    2390              : {
    2391         1463 :   rtx ret;
    2392         1463 :   gcc_assert (!cselib_current_insn);
    2393         1463 :   cselib_current_insn = insn;
    2394         1463 :   ret = cselib_subst_to_values (x, memmode);
    2395         1463 :   cselib_current_insn = NULL;
    2396         1463 :   return ret;
    2397              : }
    2398              : 
    2399              : /* Look up the rtl expression X in our tables and return the value it
    2400              :    has.  If CREATE is zero, we return NULL if we don't know the value.
    2401              :    Otherwise, we create a new one if possible, using mode MODE if X
    2402              :    doesn't have a mode (i.e. because it's a constant).  When X is part
    2403              :    of an address, MEMMODE should be the mode of the enclosing MEM if
    2404              :    we're tracking autoinc expressions.  */
    2405              : 
    2406              : static cselib_val *
    2407   2420397336 : cselib_lookup_1 (rtx x, machine_mode mode,
    2408              :                  int create, machine_mode memmode)
    2409              : {
    2410   2420397336 :   cselib_val **slot;
    2411   2420397336 :   cselib_val *e;
    2412              : 
    2413   2420397336 :   if (GET_MODE (x) != VOIDmode)
    2414   2337114166 :     mode = GET_MODE (x);
    2415              : 
    2416   2420397336 :   if (GET_CODE (x) == VALUE)
    2417     64886419 :     return CSELIB_VAL_PTR (x);
    2418              : 
    2419   2355510917 :   if (REG_P (x))
    2420              :     {
    2421   1520396806 :       struct elt_list *l;
    2422   1520396806 :       unsigned int i = REGNO (x);
    2423              : 
    2424   1520396806 :       l = REG_VALUES (i);
    2425   1520396806 :       if (l && l->elt == NULL)
    2426    634742539 :         l = l->next;
    2427   1540791331 :       for (; l; l = l->next)
    2428   1177900323 :         if (mode == GET_MODE (l->elt->val_rtx))
    2429              :           {
    2430   1157505798 :             promote_debug_loc (l->elt->locs);
    2431   1157505798 :             return l->elt;
    2432              :           }
    2433              : 
    2434    362891008 :       if (! create)
    2435              :         return 0;
    2436              : 
    2437    137026803 :       if (i < FIRST_PSEUDO_REGISTER)
    2438              :         {
    2439     78030771 :           unsigned int n = hard_regno_nregs (i, mode);
    2440              : 
    2441     78030771 :           if (n > max_value_regs)
    2442     26975945 :             max_value_regs = n;
    2443              :         }
    2444              : 
    2445    137026803 :       e = new_cselib_val (next_uid, GET_MODE (x), x);
    2446    161541066 :       if (GET_MODE (x) == Pmode && x == stack_pointer_rtx)
    2447     12040519 :         SP_DERIVED_VALUE_P (e->val_rtx) = 1;
    2448    137026803 :       new_elt_loc_list (e, x);
    2449              : 
    2450    137026803 :       scalar_int_mode int_mode;
    2451    137026803 :       if (REG_VALUES (i) == 0)
    2452              :         {
    2453              :           /* Maintain the invariant that the first entry of
    2454              :              REG_VALUES, if present, must be the value used to set the
    2455              :              register, or NULL.  */
    2456    127120741 :           used_regs[n_used_regs++] = i;
    2457    127120741 :           REG_VALUES (i) = new_elt_list (REG_VALUES (i), NULL);
    2458              :         }
    2459      9906062 :       else if (cselib_preserve_constants
    2460      9906062 :                && is_int_mode (mode, &int_mode))
    2461              :         {
    2462              :           /* During var-tracking, try harder to find equivalences
    2463              :              for SUBREGs.  If a setter sets say a DImode register
    2464              :              and user uses that register only in SImode, add a lowpart
    2465              :              subreg location.  */
    2466      1544974 :           struct elt_list *lwider = NULL;
    2467      1544974 :           scalar_int_mode lmode;
    2468      1544974 :           l = REG_VALUES (i);
    2469      1544974 :           if (l && l->elt == NULL)
    2470      1001968 :             l = l->next;
    2471      2326972 :           for (; l; l = l->next)
    2472       781998 :             if (is_int_mode (GET_MODE (l->elt->val_rtx), &lmode)
    2473      1099892 :                 && GET_MODE_SIZE (lmode) > GET_MODE_SIZE (int_mode)
    2474       267346 :                 && (lwider == NULL
    2475         5076 :                     || partial_subreg_p (lmode,
    2476         5076 :                                          GET_MODE (lwider->elt->val_rtx))))
    2477              :               {
    2478       266740 :                 struct elt_loc_list *el;
    2479       283178 :                 if (i < FIRST_PSEUDO_REGISTER
    2480       266740 :                     && hard_regno_nregs (i, lmode) != 1)
    2481        16438 :                   continue;
    2482       489727 :                 for (el = l->elt->locs; el; el = el->next)
    2483       456919 :                   if (!REG_P (el->loc))
    2484              :                     break;
    2485       250302 :                 if (el)
    2486       781998 :                   lwider = l;
    2487              :               }
    2488      1544974 :           if (lwider)
    2489              :             {
    2490       426050 :               rtx sub = lowpart_subreg (int_mode, lwider->elt->val_rtx,
    2491       213025 :                                         GET_MODE (lwider->elt->val_rtx));
    2492       213025 :               if (sub)
    2493       213025 :                 new_elt_loc_list (e, sub);
    2494              :             }
    2495              :         }
    2496    137026803 :       REG_VALUES (i)->next = new_elt_list (REG_VALUES (i)->next, e);
    2497    137026803 :       slot = cselib_find_slot (mode, x, e->hash, INSERT, memmode);
    2498    137026803 :       *slot = e;
    2499    137026803 :       return e;
    2500              :     }
    2501              : 
    2502    835114111 :   if (MEM_P (x))
    2503    233205453 :     return cselib_lookup_mem (x, create);
    2504              : 
    2505    601908658 :   hashval_t hashval = cselib_hash_rtx (x, create, memmode);
    2506              :   /* Can't even create if hashing is not possible.  */
    2507    601908658 :   if (! hashval)
    2508              :     return 0;
    2509              : 
    2510    772577122 :   slot = cselib_find_slot (mode, x, hashval,
    2511              :                            create ? INSERT : NO_INSERT, memmode);
    2512    549461271 :   if (slot == 0)
    2513              :     return 0;
    2514              : 
    2515    438200938 :   e = (cselib_val *) *slot;
    2516    438200938 :   if (e)
    2517              :     return e;
    2518              : 
    2519    252008207 :   e = new_cselib_val (hashval, mode, x);
    2520              : 
    2521              :   /* We have to fill the slot before calling cselib_subst_to_values:
    2522              :      the hash table is inconsistent until we do so, and
    2523              :      cselib_subst_to_values will need to do lookups.  */
    2524    252008207 :   *slot = e;
    2525    252008207 :   rtx v = cselib_subst_to_values (x, memmode);
    2526              : 
    2527              :   /* If cselib_preserve_constants, we might get a SP_DERIVED_VALUE_P
    2528              :      VALUE that isn't in the hash tables anymore.  */
    2529    252008207 :   if (GET_CODE (v) == VALUE && SP_DERIVED_VALUE_P (v) && PRESERVED_VALUE_P (v))
    2530            0 :     PRESERVED_VALUE_P (e->val_rtx) = 1;
    2531              : 
    2532    252008207 :   new_elt_loc_list (e, v);
    2533    252008207 :   return e;
    2534              : }
    2535              : 
    2536              : /* Wrapper for cselib_lookup, that indicates X is in INSN.  */
    2537              : 
    2538              : cselib_val *
    2539      6235937 : cselib_lookup_from_insn (rtx x, machine_mode mode,
    2540              :                          int create, machine_mode memmode, rtx_insn *insn)
    2541              : {
    2542      6235937 :   cselib_val *ret;
    2543              : 
    2544      6235937 :   gcc_assert (!cselib_current_insn);
    2545      6235937 :   cselib_current_insn = insn;
    2546              : 
    2547      6235937 :   ret = cselib_lookup (x, mode, create, memmode);
    2548              : 
    2549      6235937 :   cselib_current_insn = NULL;
    2550              : 
    2551      6235937 :   return ret;
    2552              : }
    2553              : 
    2554              : /* Wrapper for cselib_lookup_1, that logs the lookup result and
    2555              :    maintains invariants related with debug insns.  */
    2556              : 
    2557              : cselib_val *
    2558   2419325022 : cselib_lookup (rtx x, machine_mode mode,
    2559              :                int create, machine_mode memmode)
    2560              : {
    2561   2419325022 :   cselib_val *ret = cselib_lookup_1 (x, mode, create, memmode);
    2562              : 
    2563              :   /* ??? Should we return NULL if we're not to create an entry, the
    2564              :      found loc is a debug loc and cselib_current_insn is not DEBUG?
    2565              :      If so, we should also avoid converting val to non-DEBUG; probably
    2566              :      easiest setting cselib_current_insn to NULL before the call
    2567              :      above.  */
    2568              : 
    2569   2419325022 :   if (dump_file && (dump_flags & TDF_CSELIB))
    2570              :     {
    2571            0 :       fputs ("cselib lookup ", dump_file);
    2572            0 :       print_inline_rtx (dump_file, x, 2);
    2573            0 :       fprintf (dump_file, " => %u:%u\n",
    2574              :                ret ? ret->uid : 0,
    2575            0 :                ret ? ret->hash : 0);
    2576              :     }
    2577              : 
    2578   2419325022 :   return ret;
    2579              : }
    2580              : 
    2581              : /* Invalidate the value at *L, which is part of REG_VALUES (REGNO).  */
    2582              : 
    2583              : static void
    2584    183786872 : cselib_invalidate_regno_val (unsigned int regno, struct elt_list **l)
    2585              : {
    2586    183786872 :   cselib_val *v = (*l)->elt;
    2587    183786872 :   if (*l == REG_VALUES (regno))
    2588              :     {
    2589              :       /* Maintain the invariant that the first entry of
    2590              :          REG_VALUES, if present, must be the value used to set
    2591              :          the register, or NULL.  This is also nice because
    2592              :          then we won't push the same regno onto user_regs
    2593              :          multiple times.  */
    2594    141160001 :       (*l)->elt = NULL;
    2595    141160001 :       l = &(*l)->next;
    2596              :     }
    2597              :   else
    2598     42626871 :     unchain_one_elt_list (l);
    2599              : 
    2600    183786872 :   v = canonical_cselib_val (v);
    2601              : 
    2602    183786872 :   bool had_locs = v->locs != NULL;
    2603    183786872 :   rtx_insn *setting_insn = v->locs ? v->locs->setting_insn : NULL;
    2604              : 
    2605              :   /* Now, we clear the mapping from value to reg.  It must exist, so
    2606              :      this code will crash intentionally if it doesn't.  */
    2607    183786872 :   for (elt_loc_list **p = &v->locs; ; p = &(*p)->next)
    2608              :     {
    2609    211837304 :       rtx x = (*p)->loc;
    2610              : 
    2611    211837304 :       if (REG_P (x) && REGNO (x) == regno)
    2612              :         {
    2613    183786872 :           unchain_one_elt_loc_list (p);
    2614    183786872 :           break;
    2615              :         }
    2616     28050432 :     }
    2617              : 
    2618    183786872 :   if (had_locs && cselib_useless_value_p (v))
    2619              :     {
    2620     21459124 :       if (setting_insn && DEBUG_INSN_P (setting_insn))
    2621            0 :         n_useless_debug_values++;
    2622              :       else
    2623     21459124 :         n_useless_values++;
    2624              :     }
    2625    183786872 : }
    2626              : 
    2627              : /* Invalidate any entries in reg_values that overlap REGNO.  This is called
    2628              :    if REGNO is changing.  MODE is the mode of the assignment to REGNO, which
    2629              :    is used to determine how many hard registers are being changed.  If MODE
    2630              :    is VOIDmode, then only REGNO is being changed; this is used when
    2631              :    invalidating call clobbered registers across a call.  */
    2632              : 
    2633              : static void
    2634    798550014 : cselib_invalidate_regno (unsigned int regno, machine_mode mode)
    2635              : {
    2636    798550014 :   unsigned int endregno;
    2637    798550014 :   unsigned int i;
    2638              : 
    2639              :   /* If we see pseudos after reload, something is _wrong_.  */
    2640    798550014 :   gcc_assert (!reload_completed || regno < FIRST_PSEUDO_REGISTER
    2641              :               || reg_renumber[regno] < 0);
    2642              : 
    2643              :   /* Determine the range of registers that must be invalidated.  For
    2644              :      pseudos, only REGNO is affected.  For hard regs, we must take MODE
    2645              :      into account, and we must also invalidate lower register numbers
    2646              :      if they contain values that overlap REGNO.  */
    2647    221447236 :   if (regno < FIRST_PSEUDO_REGISTER)
    2648              :     {
    2649    694633711 :       gcc_assert (mode != VOIDmode);
    2650              : 
    2651    694633711 :       if (regno < max_value_regs)
    2652              :         i = 0;
    2653              :       else
    2654    653497689 :         i = regno - max_value_regs;
    2655              : 
    2656    694633711 :       endregno = end_hard_regno (mode, regno);
    2657              :     }
    2658              :   else
    2659              :     {
    2660    103916303 :       i = regno;
    2661    103916303 :       endregno = regno + 1;
    2662              :     }
    2663              : 
    2664   2213118222 :   for (; i < endregno; i++)
    2665              :     {
    2666   1414568208 :       struct elt_list **l = &REG_VALUES (i);
    2667              : 
    2668              :       /* Go through all known values for this reg; if it overlaps the range
    2669              :          we're invalidating, remove the value.  */
    2670   1799239253 :       while (*l)
    2671              :         {
    2672    384671045 :           cselib_val *v = (*l)->elt;
    2673    384671045 :           unsigned int this_last = i;
    2674              : 
    2675    384671045 :           if (i < FIRST_PSEUDO_REGISTER && v != NULL)
    2676    167217337 :             this_last = end_hard_regno (GET_MODE (v->val_rtx), i) - 1;
    2677              : 
    2678    384671045 :           if (this_last < regno || v == NULL
    2679    118072298 :               || (v == cfa_base_preserved_val
    2680      4359367 :                   && i == cfa_base_preserved_regno))
    2681              :             {
    2682    270956478 :               l = &(*l)->next;
    2683    270956478 :               continue;
    2684              :             }
    2685              : 
    2686              :           /* We have an overlap.  */
    2687    113714567 :           cselib_invalidate_regno_val (i, l);
    2688              :         }
    2689              :     }
    2690    798550014 : }
    2691              : 
    2692              : /* Invalidate any locations in the table which are changed because of a
    2693              :    store to MEM_RTX.  If this is called because of a non-const call
    2694              :    instruction, MEM_RTX is (mem:BLK const0_rtx).  */
    2695              : 
    2696              : static void
    2697    114389863 : cselib_invalidate_mem (rtx mem_rtx)
    2698              : {
    2699    114389863 :   cselib_val **vp, *v, *next;
    2700    114389863 :   int num_mems = 0;
    2701    114389863 :   rtx mem_addr;
    2702              : 
    2703    114389863 :   mem_addr = canon_rtx (get_addr (XEXP (mem_rtx, 0)));
    2704    114389863 :   mem_rtx = canon_rtx (mem_rtx);
    2705              : 
    2706    114389863 :   vp = &first_containing_mem;
    2707    285827294 :   for (v = *vp; v != &dummy_val; v = next)
    2708              :     {
    2709    171437431 :       bool has_mem = false;
    2710    171437431 :       struct elt_loc_list **p = &v->locs;
    2711    171437431 :       bool had_locs = v->locs != NULL;
    2712    171437431 :       rtx_insn *setting_insn = v->locs ? v->locs->setting_insn : NULL;
    2713    171437431 :       rtx sp_base = NULL_RTX;
    2714    171437431 :       HOST_WIDE_INT sp_off = 0;
    2715              : 
    2716    511558858 :       while (*p)
    2717              :         {
    2718    340121427 :           rtx x = (*p)->loc;
    2719    340121427 :           cselib_val *addr;
    2720    340121427 :           struct elt_list **mem_chain;
    2721              : 
    2722              :           /* MEMs may occur in locations only at the top level; below
    2723              :              that every MEM or REG is substituted by its VALUE.  */
    2724    340121427 :           if (!MEM_P (x))
    2725              :             {
    2726    103132248 :               p = &(*p)->next;
    2727    103132248 :               continue;
    2728              :             }
    2729              : 
    2730              :           /* When invalidating memory below the stack pointer for const/pure
    2731              :              calls and alloca/VLAs aren't used, attempt to optimize.  Values
    2732              :              stored into area sometimes below the stack pointer shouldn't be
    2733              :              addressable and should be stored just through stack pointer
    2734              :              derived expressions, so don't invalidate MEMs not using stack
    2735              :              derived addresses, or if the MEMs clearly aren't below the stack
    2736              :              pointer.  This isn't a fully conservative approach, the hope is
    2737              :              that invalidating more MEMs than this isn't actually needed.  */
    2738    236989179 :           if (mem_rtx == callmem[1]
    2739      2948041 :               && num_mems < param_max_cselib_memory_locations
    2740      2947983 :               && GET_CODE (XEXP (x, 0)) == VALUE
    2741      2947983 :               && !cfun->calls_alloca)
    2742              :             {
    2743      2900210 :               cselib_val *v2 = CSELIB_VAL_PTR (XEXP (x, 0));
    2744      2900210 :               rtx x_base = NULL_RTX;
    2745      2900210 :               HOST_WIDE_INT x_off = 0;
    2746      2900210 :               if (SP_DERIVED_VALUE_P (v2->val_rtx))
    2747              :                 x_base = v2->val_rtx;
    2748              :               else
    2749      4607029 :                 for (struct elt_loc_list *l = v2->locs; l; l = l->next)
    2750      2873404 :                   if (GET_CODE (l->loc) == PLUS
    2751      1549249 :                       && GET_CODE (XEXP (l->loc, 0)) == VALUE
    2752      1447201 :                       && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
    2753      3965236 :                       && CONST_INT_P (XEXP (l->loc, 1)))
    2754              :                     {
    2755      1091818 :                       x_base = XEXP (l->loc, 0);
    2756      1091818 :                       x_off = INTVAL (XEXP (l->loc, 1));
    2757      1091818 :                       break;
    2758              :                     }
    2759              :               /* If x_base is NULL here, don't invalidate x as its address
    2760              :                  isn't derived from sp such that it could be in outgoing
    2761              :                  argument area of some call in !ACCUMULATE_OUTGOING_ARGS
    2762              :                  function.  */
    2763      2900210 :               if (x_base)
    2764              :                 {
    2765      1166585 :                   if (sp_base == NULL_RTX)
    2766              :                     {
    2767      2144628 :                       if (cselib_val *v3
    2768      1075394 :                           = cselib_lookup_1 (stack_pointer_rtx, Pmode, 0,
    2769              :                                              VOIDmode))
    2770              :                         {
    2771      1067919 :                           if (SP_DERIVED_VALUE_P (v3->val_rtx))
    2772              :                             sp_base = v3->val_rtx;
    2773              :                           else
    2774       280910 :                             for (struct elt_loc_list *l = v3->locs;
    2775       563534 :                                  l; l = l->next)
    2776       563520 :                               if (GET_CODE (l->loc) == PLUS
    2777       280896 :                                   && GET_CODE (XEXP (l->loc, 0)) == VALUE
    2778       280896 :                                   && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
    2779       844416 :                                   && CONST_INT_P (XEXP (l->loc, 1)))
    2780              :                                 {
    2781       280896 :                                   sp_base = XEXP (l->loc, 0);
    2782       280896 :                                   sp_off = INTVAL (XEXP (l->loc, 1));
    2783       280896 :                                   break;
    2784              :                                 }
    2785              :                         }
    2786      1072314 :                       if (sp_base == NULL_RTX)
    2787         4409 :                         sp_base = pc_rtx;
    2788              :                     }
    2789              :                   /* Otherwise, if x_base and sp_base are the same,
    2790              :                      we know that x_base + x_off is the x's address and
    2791              :                      sp_base + sp_off is current value of stack pointer,
    2792              :                      so try to determine if x is certainly not below stack
    2793              :                      pointer.  */
    2794      1166585 :                   if (sp_base == x_base)
    2795              :                     {
    2796      1159663 :                       if (STACK_GROWS_DOWNWARD)
    2797              :                         {
    2798      1159663 :                           HOST_WIDE_INT off = sp_off;
    2799              : #ifdef STACK_ADDRESS_OFFSET
    2800              :                           /* On SPARC take stack pointer bias into account as
    2801              :                              well.  */
    2802              :                           off += (STACK_ADDRESS_OFFSET
    2803              :                                   - FIRST_PARM_OFFSET (current_function_decl));
    2804              : #endif
    2805      1159663 :                           if (x_off >= off)
    2806              :                             /* x is at or above the current stack pointer,
    2807              :                                no need to invalidate it.  */
    2808              :                             x_base = NULL_RTX;
    2809              :                         }
    2810              :                       else
    2811              :                         {
    2812              :                           HOST_WIDE_INT sz;
    2813              :                           enum machine_mode mode = GET_MODE (x);
    2814              :                           if ((MEM_SIZE_KNOWN_P (x)
    2815              :                                && MEM_SIZE (x).is_constant (&sz))
    2816              :                               || (mode != BLKmode
    2817              :                                   && GET_MODE_SIZE (mode).is_constant (&sz)))
    2818              :                             if (x_off < sp_off
    2819              :                                 && ((HOST_WIDE_INT) ((unsigned HOST_WIDE_INT)
    2820              :                                                      x_off + sz) <= sp_off))
    2821              :                               /* x's end is below or at the current stack
    2822              :                                  pointer in !STACK_GROWS_DOWNWARD target,
    2823              :                                  no need to invalidate it.  */
    2824              :                               x_base = NULL_RTX;
    2825              :                          }
    2826              :                     }
    2827              :                 }
    2828      2892527 :               if (x_base == NULL_RTX)
    2829              :                 {
    2830      2892527 :                   has_mem = true;
    2831      2892527 :                   num_mems++;
    2832      2892527 :                   p = &(*p)->next;
    2833      2892527 :                   continue;
    2834              :                 }
    2835              :             }
    2836              : 
    2837    430808024 :           if (num_mems < param_max_cselib_memory_locations
    2838    468127975 :               && ! canon_anti_dependence (x, false, mem_rtx,
    2839    234031323 :                                           GET_MODE (mem_rtx), mem_addr))
    2840              :             {
    2841    196711372 :               has_mem = true;
    2842    196711372 :               num_mems++;
    2843    196711372 :               p = &(*p)->next;
    2844    196711372 :               continue;
    2845              :             }
    2846              : 
    2847              :           /* This one overlaps.  */
    2848              :           /* We must have a mapping from this MEM's address to the
    2849              :              value (E).  Remove that, too.  */
    2850     37385280 :           addr = cselib_lookup (XEXP (x, 0), VOIDmode, 0, GET_MODE (x));
    2851     37385280 :           addr = canonical_cselib_val (addr);
    2852     37385280 :           gcc_checking_assert (v == canonical_cselib_val (v));
    2853     37385280 :           mem_chain = &addr->addr_list;
    2854     37390234 :           for (;;)
    2855              :             {
    2856     37387757 :               cselib_val *canon = canonical_cselib_val ((*mem_chain)->elt);
    2857              : 
    2858     37387757 :               if (canon == v)
    2859              :                 {
    2860     37385280 :                   unchain_one_elt_list (mem_chain);
    2861     37385280 :                   break;
    2862              :                 }
    2863              : 
    2864              :               /* Record canonicalized elt.  */
    2865         2477 :               (*mem_chain)->elt = canon;
    2866              : 
    2867         2477 :               mem_chain = &(*mem_chain)->next;
    2868         2477 :             }
    2869              : 
    2870     37385280 :           unchain_one_elt_loc_list (p);
    2871              :         }
    2872              : 
    2873    171437431 :       if (had_locs && cselib_useless_value_p (v))
    2874              :         {
    2875      8675241 :           if (setting_insn && DEBUG_INSN_P (setting_insn))
    2876            0 :             n_useless_debug_values++;
    2877              :           else
    2878      8675241 :             n_useless_values++;
    2879              :         }
    2880              : 
    2881    171437431 :       next = v->next_containing_mem;
    2882    171437431 :       if (has_mem)
    2883              :         {
    2884    138928275 :           *vp = v;
    2885    138928275 :           vp = &(*vp)->next_containing_mem;
    2886              :         }
    2887              :       else
    2888     32509156 :         v->next_containing_mem = NULL;
    2889              :     }
    2890    114389863 :   *vp = &dummy_val;
    2891    114389863 : }
    2892              : 
    2893              : /* Invalidate DEST.  */
    2894              : 
    2895              : void
    2896    521930435 : cselib_invalidate_rtx (rtx dest)
    2897              : {
    2898    521930435 :   while (GET_CODE (dest) == SUBREG
    2899    521930435 :          || GET_CODE (dest) == ZERO_EXTRACT
    2900   1043867489 :          || GET_CODE (dest) == STRICT_LOW_PART)
    2901         6619 :     dest = XEXP (dest, 0);
    2902              : 
    2903    521930435 :   if (REG_P (dest))
    2904    397638762 :     cselib_invalidate_regno (REGNO (dest), GET_MODE (dest));
    2905    124291673 :   else if (MEM_P (dest))
    2906     75928498 :     cselib_invalidate_mem (dest);
    2907    521930435 : }
    2908              : 
    2909              : /* A wrapper for cselib_invalidate_rtx to be called via note_stores.  */
    2910              : 
    2911              : static void
    2912    505934450 : cselib_invalidate_rtx_note_stores (rtx dest, const_rtx,
    2913              :                                    void *data ATTRIBUTE_UNUSED)
    2914              : {
    2915    505934450 :   cselib_invalidate_rtx (dest);
    2916    505934450 : }
    2917              : 
    2918              : /* Record the result of a SET instruction.  DEST is being set; the source
    2919              :    contains the value described by SRC_ELT.  If DEST is a MEM, DEST_ADDR_ELT
    2920              :    describes its address.  */
    2921              : 
    2922              : static void
    2923    363096995 : cselib_record_set (rtx dest, cselib_val *src_elt, cselib_val *dest_addr_elt)
    2924              : {
    2925    363096995 :   if (src_elt == 0 || side_effects_p (dest))
    2926     66362074 :     return;
    2927              : 
    2928    296734921 :   if (REG_P (dest))
    2929              :     {
    2930    272395744 :       unsigned int dreg = REGNO (dest);
    2931    272395744 :       if (dreg < FIRST_PSEUDO_REGISTER)
    2932              :         {
    2933    200061635 :           unsigned int n = REG_NREGS (dest);
    2934              : 
    2935    200061635 :           if (n > max_value_regs)
    2936     25583040 :             max_value_regs = n;
    2937              :         }
    2938              : 
    2939    272395744 :       if (REG_VALUES (dreg) == 0)
    2940              :         {
    2941    167354496 :           used_regs[n_used_regs++] = dreg;
    2942    167354496 :           REG_VALUES (dreg) = new_elt_list (REG_VALUES (dreg), src_elt);
    2943              :         }
    2944              :       else
    2945              :         {
    2946              :           /* The register should have been invalidated.  */
    2947    105041248 :           gcc_assert (REG_VALUES (dreg)->elt == 0);
    2948    105041248 :           REG_VALUES (dreg)->elt = src_elt;
    2949              :         }
    2950              : 
    2951    272395744 :       if (cselib_useless_value_p (src_elt))
    2952        41830 :         n_useless_values--;
    2953    272395744 :       new_elt_loc_list (src_elt, dest);
    2954              :     }
    2955     24339177 :   else if (MEM_P (dest) && dest_addr_elt != 0
    2956     24339177 :            && cselib_record_memory)
    2957              :     {
    2958     24339177 :       if (cselib_useless_value_p (src_elt))
    2959           46 :         n_useless_values--;
    2960     24339177 :       add_mem_for_addr (dest_addr_elt, src_elt, dest);
    2961              :     }
    2962              : }
    2963              : 
    2964              : /* Make ELT and X's VALUE equivalent to each other at INSN.  */
    2965              : 
    2966              : void
    2967      3854731 : cselib_add_permanent_equiv (cselib_val *elt, rtx x, rtx_insn *insn)
    2968              : {
    2969      3854731 :   cselib_val *nelt;
    2970      3854731 :   rtx_insn *save_cselib_current_insn = cselib_current_insn;
    2971              : 
    2972      3854731 :   gcc_checking_assert (elt);
    2973      3854731 :   gcc_checking_assert (PRESERVED_VALUE_P (elt->val_rtx));
    2974      3854731 :   gcc_checking_assert (!side_effects_p (x));
    2975              : 
    2976      3854731 :   cselib_current_insn = insn;
    2977              : 
    2978      3854731 :   nelt = cselib_lookup (x, GET_MODE (elt->val_rtx), 1, VOIDmode);
    2979              : 
    2980      3854731 :   if (nelt != elt)
    2981              :     {
    2982      2984865 :       cselib_any_perm_equivs = true;
    2983              : 
    2984      2984865 :       if (!PRESERVED_VALUE_P (nelt->val_rtx))
    2985      2979877 :         cselib_preserve_value (nelt);
    2986              : 
    2987      2984865 :       new_elt_loc_list (nelt, elt->val_rtx);
    2988              :     }
    2989              : 
    2990      3854731 :   cselib_current_insn = save_cselib_current_insn;
    2991      3854731 : }
    2992              : 
    2993              : /* Return TRUE if any permanent equivalences have been recorded since
    2994              :    the table was last initialized.  */
    2995              : bool
    2996   1391403760 : cselib_have_permanent_equivalences (void)
    2997              : {
    2998   1391403760 :   return cselib_any_perm_equivs;
    2999              : }
    3000              : 
    3001              : /* Record stack_pointer_rtx to be equal to
    3002              :    (plus:P cfa_base_preserved_val offset).  Used by var-tracking
    3003              :    at the start of basic blocks for !frame_pointer_needed functions.  */
    3004              : 
    3005              : void
    3006      3426247 : cselib_record_sp_cfa_base_equiv (HOST_WIDE_INT offset, rtx_insn *insn)
    3007              : {
    3008      3426247 :   rtx sp_derived_value = NULL_RTX;
    3009      6852494 :   for (struct elt_loc_list *l = cfa_base_preserved_val->locs; l; l = l->next)
    3010      6852494 :     if (GET_CODE (l->loc) == VALUE
    3011      6852494 :         && SP_DERIVED_VALUE_P (l->loc))
    3012              :       {
    3013              :         sp_derived_value = l->loc;
    3014              :         break;
    3015              :       }
    3016      6852494 :     else if (GET_CODE (l->loc) == PLUS
    3017      3426247 :              && GET_CODE (XEXP (l->loc, 0)) == VALUE
    3018      3426247 :              && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
    3019     10278741 :              && CONST_INT_P (XEXP (l->loc, 1)))
    3020              :       {
    3021      3426247 :         sp_derived_value = XEXP (l->loc, 0);
    3022      3426247 :         offset = offset + UINTVAL (XEXP (l->loc, 1));
    3023      3426247 :         break;
    3024              :       }
    3025      3426247 :   if (sp_derived_value == NULL_RTX)
    3026              :     return;
    3027      3426247 :   cselib_val *val
    3028      3426247 :     = cselib_lookup_from_insn (plus_constant (Pmode, sp_derived_value, offset),
    3029      3426247 :                                Pmode, 1, VOIDmode, insn);
    3030      3426247 :   if (val != NULL)
    3031              :     {
    3032      3426247 :       PRESERVED_VALUE_P (val->val_rtx) = 1;
    3033      3426247 :       cselib_record_set (stack_pointer_rtx, val, NULL);
    3034              :     }
    3035              : }
    3036              : 
    3037              : /* Return true if V is SP_DERIVED_VALUE_P (or SP_DERIVED_VALUE_P + CONST_INT)
    3038              :    that can be expressed using cfa_base_preserved_val + CONST_INT.  */
    3039              : 
    3040              : bool
    3041     30528413 : cselib_sp_derived_value_p (cselib_val *v)
    3042              : {
    3043     30528413 :   if (!SP_DERIVED_VALUE_P (v->val_rtx))
    3044     67255761 :     for (struct elt_loc_list *l = v->locs; l; l = l->next)
    3045     37240755 :       if (GET_CODE (l->loc) == PLUS
    3046      7038304 :           && GET_CODE (XEXP (l->loc, 0)) == VALUE
    3047      6818771 :           && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
    3048     42272437 :           && CONST_INT_P (XEXP (l->loc, 1)))
    3049      5031682 :         v = CSELIB_VAL_PTR (XEXP (l->loc, 0));
    3050     30528413 :   if (!SP_DERIVED_VALUE_P (v->val_rtx))
    3051              :     return false;
    3052     11388102 :   for (struct elt_loc_list *l = v->locs; l; l = l->next)
    3053     11388102 :     if (l->loc == cfa_base_preserved_val->val_rtx)
    3054              :       return true;
    3055     11388102 :     else if (GET_CODE (l->loc) == PLUS
    3056      5545089 :              && XEXP (l->loc, 0) == cfa_base_preserved_val->val_rtx
    3057      5545089 :              && CONST_INT_P (XEXP (l->loc, 1)))
    3058              :       return true;
    3059              :   return false;
    3060              : }
    3061              : 
    3062              : /* There is no good way to determine how many elements there can be
    3063              :    in a PARALLEL.  Since it's fairly cheap, use a really large number.  */
    3064              : #define MAX_SETS (FIRST_PSEUDO_REGISTER * 2)
    3065              : 
    3066              : struct cselib_record_autoinc_data
    3067              : {
    3068              :   struct cselib_set *sets;
    3069              :   int n_sets;
    3070              : };
    3071              : 
    3072              : /* Callback for for_each_inc_dec.  Records in ARG the SETs implied by
    3073              :    autoinc RTXs: SRC plus SRCOFF if non-NULL is stored in DEST.  */
    3074              : 
    3075              : static int
    3076     13439306 : cselib_record_autoinc_cb (rtx mem ATTRIBUTE_UNUSED, rtx op ATTRIBUTE_UNUSED,
    3077              :                           rtx dest, rtx src, rtx srcoff, void *arg)
    3078              : {
    3079     13439306 :   struct cselib_record_autoinc_data *data;
    3080     13439306 :   data = (struct cselib_record_autoinc_data *)arg;
    3081              : 
    3082     13439306 :   data->sets[data->n_sets].dest = dest;
    3083              : 
    3084     13439306 :   if (srcoff)
    3085     13068629 :     data->sets[data->n_sets].src = gen_rtx_PLUS (GET_MODE (src), src, srcoff);
    3086              :   else
    3087       370677 :     data->sets[data->n_sets].src = src;
    3088              : 
    3089     13439306 :   data->n_sets++;
    3090              : 
    3091     13439306 :   return 0;
    3092              : }
    3093              : 
    3094              : /* Record the effects of any sets and autoincs in INSN.  */
    3095              : static void
    3096    880741121 : cselib_record_sets (rtx_insn *insn)
    3097              : {
    3098    880741121 :   int n_sets = 0;
    3099    880741121 :   int i;
    3100    880741121 :   struct cselib_set sets[MAX_SETS];
    3101    880741121 :   rtx cond = 0;
    3102    880741121 :   int n_sets_before_autoinc;
    3103    880741121 :   int n_strict_low_parts = 0;
    3104    880741121 :   struct cselib_record_autoinc_data data;
    3105              : 
    3106    880741121 :   rtx body = PATTERN (insn);
    3107    880741121 :   if (GET_CODE (body) == COND_EXEC)
    3108              :     {
    3109            0 :       cond = COND_EXEC_TEST (body);
    3110            0 :       body = COND_EXEC_CODE (body);
    3111              :     }
    3112              : 
    3113              :   /* Find all sets.  */
    3114    880741121 :   if (GET_CODE (body) == SET)
    3115              :     {
    3116    367275350 :       sets[0].src = SET_SRC (body);
    3117    367275350 :       sets[0].dest = SET_DEST (body);
    3118    367275350 :       n_sets = 1;
    3119              :     }
    3120    513465771 :   else if (GET_CODE (body) == PARALLEL)
    3121              :     {
    3122              :       /* Look through the PARALLEL and record the values being
    3123              :          set, if possible.  Also handle any CLOBBERs.  */
    3124    208672224 :       for (i = XVECLEN (body, 0) - 1; i >= 0; --i)
    3125              :         {
    3126    140710729 :           rtx x = XVECEXP (body, 0, i);
    3127              : 
    3128    140710729 :           if (GET_CODE (x) == SET)
    3129              :             {
    3130     73596922 :               sets[n_sets].src = SET_SRC (x);
    3131     73596922 :               sets[n_sets].dest = SET_DEST (x);
    3132     73596922 :               n_sets++;
    3133              :             }
    3134              :         }
    3135              :     }
    3136              : 
    3137    367275350 :   if (n_sets == 1
    3138    429496348 :       && MEM_P (sets[0].src)
    3139     62125167 :       && !cselib_record_memory
    3140    107840661 :       && MEM_READONLY_P (sets[0].src))
    3141              :     {
    3142      3225236 :       rtx note = find_reg_equal_equiv_note (insn);
    3143              : 
    3144      3225236 :       if (note && CONSTANT_P (XEXP (note, 0)))
    3145      2041786 :         sets[0].src = XEXP (note, 0);
    3146              :     }
    3147              : 
    3148    880741121 :   data.sets = sets;
    3149    880741121 :   data.n_sets = n_sets_before_autoinc = n_sets;
    3150    880741121 :   for_each_inc_dec (PATTERN (insn), cselib_record_autoinc_cb, &data);
    3151    880741121 :   n_sets = data.n_sets;
    3152              : 
    3153              :   /* Look up the values that are read.  Do this before invalidating the
    3154              :      locations that are written.  */
    3155   1335052699 :   for (i = 0; i < n_sets; i++)
    3156              :     {
    3157    454311578 :       rtx dest = sets[i].dest;
    3158    454311578 :       rtx orig = dest;
    3159              : 
    3160              :       /* A STRICT_LOW_PART can be ignored; we'll record the equivalence for
    3161              :          the low part after invalidating any knowledge about larger modes.  */
    3162    454311578 :       if (GET_CODE (sets[i].dest) == STRICT_LOW_PART)
    3163        50996 :         sets[i].dest = dest = XEXP (dest, 0);
    3164              : 
    3165              :       /* We don't know how to record anything but REG or MEM.  */
    3166    454311578 :       if (REG_P (dest)
    3167    123139095 :           || (MEM_P (dest) && cselib_record_memory))
    3168              :         {
    3169    359670748 :           rtx src = sets[i].src;
    3170    359670748 :           if (cond)
    3171            0 :             src = gen_rtx_IF_THEN_ELSE (GET_MODE (dest), cond, src, dest);
    3172    359670748 :           sets[i].src_elt = cselib_lookup (src, GET_MODE (dest), 1, VOIDmode);
    3173    359670748 :           if (MEM_P (dest))
    3174              :             {
    3175     28498265 :               machine_mode address_mode = get_address_mode (dest);
    3176              : 
    3177     28498265 :               sets[i].dest_addr_elt = cselib_lookup (XEXP (dest, 0),
    3178              :                                                      address_mode, 1,
    3179     28498265 :                                                      GET_MODE (dest));
    3180              :             }
    3181              :           else
    3182    331172483 :             sets[i].dest_addr_elt = 0;
    3183              :         }
    3184              : 
    3185              :       /* Improve handling of STRICT_LOW_PART if the current value is known
    3186              :          to be const0_rtx, then the low bits will be set to dest and higher
    3187              :          bits will remain zero.  Used in code like:
    3188              : 
    3189              :          {di:SI=0;clobber flags:CC;}
    3190              :          flags:CCNO=cmp(bx:SI,0)
    3191              :          strict_low_part(di:QI)=flags:CCNO<=0
    3192              : 
    3193              :          where we can note both that di:QI=flags:CCNO<=0 and
    3194              :          also that because di:SI is known to be 0 and strict_low_part(di:QI)
    3195              :          preserves the upper bits that di:SI=zero_extend(flags:CCNO<=0).  */
    3196    454311578 :       scalar_int_mode mode;
    3197    454311578 :       if (dest != orig
    3198        50996 :           && cselib_record_sets_hook
    3199        16095 :           && REG_P (dest)
    3200        16095 :           && HARD_REGISTER_P (dest)
    3201        16095 :           && sets[i].src_elt
    3202    454327673 :           && is_a <scalar_int_mode> (GET_MODE (dest), &mode)
    3203    454327673 :           && n_sets + n_strict_low_parts < MAX_SETS)
    3204              :         {
    3205        16095 :           opt_scalar_int_mode wider_mode_iter;
    3206        40272 :           FOR_EACH_WIDER_MODE (wider_mode_iter, mode)
    3207              :             {
    3208        40272 :               scalar_int_mode wider_mode = wider_mode_iter.require ();
    3209        47725 :               if (GET_MODE_PRECISION (wider_mode) > BITS_PER_WORD)
    3210              :                 break;
    3211              : 
    3212        39012 :               rtx reg = gen_lowpart (wider_mode, dest);
    3213        39012 :               if (!REG_P (reg))
    3214              :                 break;
    3215              : 
    3216        38987 :               cselib_val *v = cselib_lookup (reg, wider_mode, 0, VOIDmode);
    3217        38987 :               if (!v)
    3218        24177 :                 continue;
    3219              : 
    3220        15751 :               struct elt_loc_list *l;
    3221        33316 :               for (l = v->locs; l; l = l->next)
    3222        32375 :                 if (l->loc == const0_rtx)
    3223              :                   break;
    3224              : 
    3225          941 :               if (!l)
    3226          941 :                 continue;
    3227              : 
    3228        14810 :               sets[n_sets + n_strict_low_parts].dest = reg;
    3229        14810 :               sets[n_sets + n_strict_low_parts].src = dest;
    3230        14810 :               sets[n_sets + n_strict_low_parts++].src_elt = sets[i].src_elt;
    3231        14810 :               break;
    3232              :             }
    3233              :         }
    3234              :     }
    3235              : 
    3236    880741121 :   if (cselib_record_sets_hook)
    3237     79178379 :     cselib_record_sets_hook (insn, sets, n_sets);
    3238              : 
    3239              :   /* Invalidate all locations written by this insn.  Note that the elts we
    3240              :      looked up in the previous loop aren't affected, just some of their
    3241              :      locations may go away.  */
    3242    880741121 :   note_pattern_stores (body, cselib_invalidate_rtx_note_stores, NULL);
    3243              : 
    3244   1774921548 :   for (i = n_sets_before_autoinc; i < n_sets; i++)
    3245     13439306 :     cselib_invalidate_rtx (sets[i].dest);
    3246              : 
    3247              :   /* If this is an asm, look for duplicate sets.  This can happen when the
    3248              :      user uses the same value as an output multiple times.  This is valid
    3249              :      if the outputs are not actually used thereafter.  Treat this case as
    3250              :      if the value isn't actually set.  We do this by smashing the destination
    3251              :      to pc_rtx, so that we won't record the value later.  */
    3252    880741121 :   if (n_sets >= 2 && asm_noperands (body) >= 0)
    3253              :     {
    3254       497192 :       for (i = 0; i < n_sets; i++)
    3255              :         {
    3256       385046 :           rtx dest = sets[i].dest;
    3257       385046 :           if (REG_P (dest) || MEM_P (dest))
    3258              :             {
    3259       385013 :               int j;
    3260       903163 :               for (j = i + 1; j < n_sets; j++)
    3261       518150 :                 if (rtx_equal_p (dest, sets[j].dest))
    3262              :                   {
    3263            0 :                     sets[i].dest = pc_rtx;
    3264            0 :                     sets[j].dest = pc_rtx;
    3265              :                   }
    3266              :             }
    3267              :         }
    3268              :     }
    3269              : 
    3270              :   /* Now enter the equivalences in our tables.  */
    3271   1335052699 :   for (i = 0; i < n_sets; i++)
    3272              :     {
    3273    454311578 :       rtx dest = sets[i].dest;
    3274    454311578 :       if (REG_P (dest)
    3275    123139095 :           || (MEM_P (dest) && cselib_record_memory))
    3276    359670748 :         cselib_record_set (dest, sets[i].src_elt, sets[i].dest_addr_elt);
    3277              :     }
    3278              : 
    3279              :   /* And deal with STRICT_LOW_PART.  */
    3280    880755931 :   for (i = 0; i < n_strict_low_parts; i++)
    3281              :     {
    3282        14810 :       if (! PRESERVED_VALUE_P (sets[n_sets + i].src_elt->val_rtx))
    3283            0 :         continue;
    3284        14810 :       machine_mode dest_mode = GET_MODE (sets[n_sets + i].dest);
    3285        14810 :       cselib_val *v
    3286        14810 :         = cselib_lookup (sets[n_sets + i].dest, dest_mode, 1, VOIDmode);
    3287        14810 :       cselib_preserve_value (v);
    3288        14810 :       rtx r = gen_rtx_ZERO_EXTEND (dest_mode,
    3289              :                                    sets[n_sets + i].src_elt->val_rtx);
    3290        14810 :       cselib_add_permanent_equiv (v, r, insn);
    3291              :     }
    3292    880741121 : }
    3293              : 
    3294              : /* Return true if INSN in the prologue initializes hard_frame_pointer_rtx.  */
    3295              : 
    3296              : bool
    3297     40773351 : fp_setter_insn (rtx_insn *insn)
    3298              : {
    3299     40773351 :   rtx expr, pat = NULL_RTX;
    3300              : 
    3301     40773351 :   if (!RTX_FRAME_RELATED_P (insn))
    3302              :     return false;
    3303              : 
    3304       623468 :   expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
    3305       623468 :   if (expr)
    3306           62 :     pat = XEXP (expr, 0);
    3307       623468 :   if (!modified_in_p (hard_frame_pointer_rtx, pat ? pat : insn))
    3308              :     return false;
    3309              : 
    3310              :   /* Don't return true for frame pointer restores in the epilogue.  */
    3311       153050 :   if (find_reg_note (insn, REG_CFA_RESTORE, hard_frame_pointer_rtx))
    3312              :     return false;
    3313              :   return true;
    3314              : }
    3315              : 
    3316              : /* V is one of the values in REG_VALUES (REGNO).  Return true if it
    3317              :    would be invalidated by CALLEE_ABI.  */
    3318              : 
    3319              : static bool
    3320    113076434 : cselib_invalidated_by_call_p (const function_abi &callee_abi,
    3321              :                               unsigned int regno, cselib_val *v)
    3322              : {
    3323    113076434 :   machine_mode mode = GET_MODE (v->val_rtx);
    3324    113076434 :   if (mode == VOIDmode)
    3325              :     {
    3326            0 :       v = REG_VALUES (regno)->elt;
    3327            0 :       if (!v)
    3328              :         /* If we don't know what the mode of the constant value is, and we
    3329              :            don't know what mode the register was set in, conservatively
    3330              :            assume that the register is clobbered.  The value's going to be
    3331              :            essentially useless in this case anyway.  */
    3332              :         return true;
    3333            0 :       mode = GET_MODE (v->val_rtx);
    3334              :     }
    3335    113076434 :   return callee_abi.clobbers_reg_p (mode, regno);
    3336              : }
    3337              : 
    3338              : /* Record the effects of INSN.  */
    3339              : 
    3340              : void
    3341   1015189461 : cselib_process_insn (rtx_insn *insn)
    3342              : {
    3343   1015189461 :   int i;
    3344   1015189461 :   rtx x;
    3345              : 
    3346   1015189461 :   cselib_current_insn = insn;
    3347              : 
    3348              :   /* Forget everything at a CODE_LABEL or a setjmp.  */
    3349   1015189461 :   if ((LABEL_P (insn)
    3350    980118862 :        || (CALL_P (insn)
    3351     33966047 :            && find_reg_note (insn, REG_SETJMP, NULL)))
    3352   1015193752 :       && !cselib_preserve_constants)
    3353              :     {
    3354     35074664 :       cselib_reset_table (next_uid);
    3355     35074664 :       cselib_current_insn = NULL;
    3356     35074664 :       return;
    3357              :     }
    3358              : 
    3359    980114797 :   if (! INSN_P (insn))
    3360              :     {
    3361     99373676 :       cselib_current_insn = NULL;
    3362     99373676 :       return;
    3363              :     }
    3364              : 
    3365              :   /* If this is a call instruction, forget anything stored in a
    3366              :      call clobbered register, or, if this is not a const call, in
    3367              :      memory.  */
    3368    880741121 :   if (CALL_P (insn))
    3369              :     {
    3370     33961982 :       function_abi callee_abi = insn_callee_abi (insn);
    3371   3158464326 :       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    3372              :         {
    3373   3124502344 :           elt_list **l = &REG_VALUES (i);
    3374   3344498626 :           while (*l)
    3375              :             {
    3376    219996282 :               cselib_val *v = (*l)->elt;
    3377    219996282 :               if (v && cselib_invalidated_by_call_p (callee_abi, i, v))
    3378     70072305 :                 cselib_invalidate_regno_val (i, l);
    3379              :               else
    3380    149923977 :                 l = &(*l)->next;
    3381              :             }
    3382              :         }
    3383              : 
    3384              :       /* Since it is not clear how cselib is going to be used, be
    3385              :          conservative here and treat looping pure or const functions
    3386              :          as if they were regular functions.  */
    3387     33961982 :       if (RTL_LOOPING_CONST_OR_PURE_CALL_P (insn)
    3388     33961982 :           || !(RTL_CONST_OR_PURE_CALL_P (insn)))
    3389     30960901 :         cselib_invalidate_mem (callmem[0]);
    3390              :       else
    3391              :         {
    3392              :           /* For const/pure calls, invalidate any argument slots because
    3393              :              they are owned by the callee.  */
    3394      8644413 :           for (x = CALL_INSN_FUNCTION_USAGE (insn); x; x = XEXP (x, 1))
    3395      5643332 :             if (GET_CODE (XEXP (x, 0)) == USE
    3396      5643056 :                 && MEM_P (XEXP (XEXP (x, 0), 0)))
    3397       142095 :               cselib_invalidate_mem (XEXP (XEXP (x, 0), 0));
    3398              :           /* And invalidate memory below the stack (or above for
    3399              :              !STACK_GROWS_DOWNWARD), as even const/pure call can invalidate
    3400              :              that.  Do this only if !ACCUMULATE_OUTGOING_ARGS or if
    3401              :              cfun->calls_alloca, otherwise the stack pointer shouldn't be
    3402              :              changing in the middle of the function and nothing should be
    3403              :              stored below the stack pointer.  */
    3404      3001081 :           if (!ACCUMULATE_OUTGOING_ARGS || cfun->calls_alloca)
    3405      3000638 :             cselib_invalidate_mem (callmem[1]);
    3406              :         }
    3407              :     }
    3408              : 
    3409    880741121 :   cselib_record_sets (insn);
    3410              : 
    3411              :   /* Look for any CLOBBERs in CALL_INSN_FUNCTION_USAGE, but only
    3412              :      after we have processed the insn.  */
    3413    880741121 :   if (CALL_P (insn))
    3414              :     {
    3415    102070245 :       for (x = CALL_INSN_FUNCTION_USAGE (insn); x; x = XEXP (x, 1))
    3416     68108263 :         if (GET_CODE (XEXP (x, 0)) == CLOBBER)
    3417      1858939 :           cselib_invalidate_rtx (XEXP (XEXP (x, 0), 0));
    3418              : 
    3419              :       /* Flush everything on setjmp.  */
    3420     33961982 :       if (cselib_preserve_constants
    3421     33961982 :           && find_reg_note (insn, REG_SETJMP, NULL))
    3422              :         {
    3423          226 :           cselib_preserve_only_values ();
    3424          226 :           cselib_reset_table (next_uid);
    3425              :         }
    3426              :     }
    3427              : 
    3428              :   /* On setter of the hard frame pointer if frame_pointer_needed,
    3429              :      invalidate stack_pointer_rtx, so that sp and {,h}fp based
    3430              :      VALUEs are distinct.  */
    3431    880741121 :   if (reload_completed
    3432    403541975 :       && frame_pointer_needed
    3433    921394921 :       && fp_setter_insn (insn))
    3434        93200 :     cselib_invalidate_rtx (stack_pointer_rtx);
    3435              : 
    3436    880741121 :   cselib_current_insn = NULL;
    3437              : 
    3438    880741121 :   if (n_useless_values > MAX_USELESS_VALUES
    3439              :       /* remove_useless_values is linear in the hash table size.  Avoid
    3440              :          quadratic behavior for very large hashtables with very few
    3441              :          useless elements.  */
    3442    880741121 :       && ((unsigned int)n_useless_values
    3443      2078866 :           > (cselib_hash_table->elements () - n_debug_values) / 4))
    3444        28749 :     remove_useless_values ();
    3445              : }
    3446              : 
    3447              : /* Initialize cselib for one pass.  The caller must also call
    3448              :    init_alias_analysis.  */
    3449              : 
    3450              : void
    3451     10186400 : cselib_init (int record_what)
    3452              : {
    3453     10186400 :   cselib_record_memory = record_what & CSELIB_RECORD_MEMORY;
    3454     10186400 :   cselib_preserve_constants = record_what & CSELIB_PRESERVE_CONSTANTS;
    3455     10186400 :   cselib_any_perm_equivs = false;
    3456              : 
    3457              :   /* (mem:BLK (scratch)) is a special mechanism to conflict with everything,
    3458              :      see canon_true_dependence.  This is only created once.  */
    3459     10186400 :   if (! callmem[0])
    3460       145568 :     callmem[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
    3461              :   /* Similarly create a MEM representing roughly everything below
    3462              :      the stack for STACK_GROWS_DOWNWARD targets or everything above
    3463              :      it otherwise.  Do this only when !ACCUMULATE_OUTGOING_ARGS or
    3464              :      if cfun->calls_alloca, otherwise the stack pointer shouldn't be
    3465              :      changing in the middle of the function and nothing should be stored
    3466              :      below the stack pointer.  */
    3467     10186400 :   if (!callmem[1] && (!ACCUMULATE_OUTGOING_ARGS || cfun->calls_alloca))
    3468              :     {
    3469       145313 :       if (STACK_GROWS_DOWNWARD)
    3470              :         {
    3471       145313 :           unsigned HOST_WIDE_INT off = -(GET_MODE_MASK (Pmode) >> 1);
    3472              : #ifdef STACK_ADDRESS_OFFSET
    3473              :           /* On SPARC take stack pointer bias into account as well.  */
    3474              :           off += (STACK_ADDRESS_OFFSET
    3475              :                   - FIRST_PARM_OFFSET (current_function_decl));
    3476              : #endif
    3477       145313 :           callmem[1] = plus_constant (Pmode, stack_pointer_rtx, off);
    3478              :         }
    3479              :       else
    3480              :         callmem[1] = stack_pointer_rtx;
    3481       145313 :       callmem[1] = gen_rtx_MEM (BLKmode, callmem[1]);
    3482       150730 :       set_mem_size (callmem[1], GET_MODE_MASK (Pmode) >> 1);
    3483              :     }
    3484              : 
    3485     10186400 :   cselib_nregs = max_reg_num ();
    3486              : 
    3487              :   /* We preserve reg_values to allow expensive clearing of the whole thing.
    3488              :      Reallocate it however if it happens to be too large.  */
    3489     10186400 :   if (!reg_values || reg_values_size < cselib_nregs
    3490      9886939 :       || (reg_values_size > 10 && reg_values_size > cselib_nregs * 4))
    3491              :     {
    3492       314853 :       free (reg_values);
    3493              :       /* Some space for newly emit instructions so we don't end up
    3494              :          reallocating in between passes.  */
    3495       314853 :       reg_values_size = cselib_nregs + (63 + cselib_nregs) / 16;
    3496       314853 :       reg_values = XCNEWVEC (struct elt_list *, reg_values_size);
    3497              :     }
    3498     10186400 :   used_regs = XNEWVEC (unsigned int, cselib_nregs);
    3499     10186400 :   n_used_regs = 0;
    3500              :   /* FIXME: enable sanitization (PR87845) */
    3501     10186400 :   cselib_hash_table
    3502     10186400 :     = new hash_table<cselib_hasher> (31, /* ggc */ false,
    3503     10186400 :                                      /* sanitize_eq_and_hash */ false);
    3504     10186400 :   if (cselib_preserve_constants)
    3505       499517 :     cselib_preserved_hash_table
    3506       499517 :       = new hash_table<cselib_hasher> (31, /* ggc */ false,
    3507       499517 :                                        /* sanitize_eq_and_hash */ false);
    3508     10186400 :   next_uid = 1;
    3509     10186400 : }
    3510              : 
    3511              : /* Called when the current user is done with cselib.  */
    3512              : 
    3513              : void
    3514     10186400 : cselib_finish (void)
    3515              : {
    3516     10186400 :   bool preserved = cselib_preserve_constants;
    3517     10186400 :   cselib_discard_hook = NULL;
    3518     10186400 :   cselib_preserve_constants = false;
    3519     10186400 :   cselib_any_perm_equivs = false;
    3520     10186400 :   cfa_base_preserved_val = NULL;
    3521     10186400 :   cfa_base_preserved_regno = INVALID_REGNUM;
    3522     10186400 :   elt_list_pool.release ();
    3523     10186400 :   elt_loc_list_pool.release ();
    3524     10186400 :   cselib_val_pool.release ();
    3525     10186400 :   value_pool.release ();
    3526     10186400 :   cselib_clear_table ();
    3527     10186400 :   delete cselib_hash_table;
    3528     10186400 :   cselib_hash_table = NULL;
    3529     10186400 :   if (preserved)
    3530       499517 :     delete cselib_preserved_hash_table;
    3531     10186400 :   cselib_preserved_prune_list.release ();
    3532     10186400 :   cselib_preserved_hash_table = NULL;
    3533     10186400 :   free (used_regs);
    3534     10186400 :   used_regs = 0;
    3535     10186400 :   n_useless_values = 0;
    3536     10186400 :   n_useless_debug_values = 0;
    3537     10186400 :   n_debug_values = 0;
    3538     10186400 :   next_uid = 0;
    3539     10186400 : }
    3540              : 
    3541              : /* Dump the cselib_val V to FILE *OUT.  */
    3542              : 
    3543              : int
    3544           93 : dump_cselib_val (cselib_val *v, FILE *out)
    3545              : {
    3546           93 :   bool need_lf = true;
    3547              : 
    3548           93 :   print_inline_rtx (out, v->val_rtx, 0);
    3549              : 
    3550           93 :   if (v->locs)
    3551              :     {
    3552           86 :       struct elt_loc_list *l = v->locs;
    3553           86 :       if (need_lf)
    3554              :         {
    3555           86 :           fputc ('\n', out);
    3556           86 :           need_lf = false;
    3557              :         }
    3558           86 :       fputs (" locs:", out);
    3559          149 :       do
    3560              :         {
    3561          149 :           if (l->setting_insn)
    3562          149 :             fprintf (out, "\n  from insn %i ",
    3563          149 :                      INSN_UID (l->setting_insn));
    3564              :           else
    3565            0 :             fprintf (out, "\n   ");
    3566          149 :           print_inline_rtx (out, l->loc, 4);
    3567              :         }
    3568          149 :       while ((l = l->next));
    3569           86 :       fputc ('\n', out);
    3570              :     }
    3571              :   else
    3572              :     {
    3573            7 :       fputs (" no locs", out);
    3574            7 :       need_lf = true;
    3575              :     }
    3576              : 
    3577           93 :   if (v->addr_list)
    3578              :     {
    3579            6 :       struct elt_list *e = v->addr_list;
    3580            6 :       if (need_lf)
    3581              :         {
    3582            0 :           fputc ('\n', out);
    3583            0 :           need_lf = false;
    3584              :         }
    3585            6 :       fputs (" addr list:", out);
    3586            6 :       do
    3587              :         {
    3588            6 :           fputs ("\n  ", out);
    3589            6 :           print_inline_rtx (out, e->elt->val_rtx, 2);
    3590              :         }
    3591            6 :       while ((e = e->next));
    3592            6 :       fputc ('\n', out);
    3593              :     }
    3594              :   else
    3595              :     {
    3596           87 :       fputs (" no addrs", out);
    3597           87 :       need_lf = true;
    3598              :     }
    3599              : 
    3600           93 :   if (v->next_containing_mem == &dummy_val)
    3601            6 :     fputs (" last mem\n", out);
    3602           87 :   else if (v->next_containing_mem)
    3603              :     {
    3604            0 :       fputs (" next mem ", out);
    3605            0 :       print_inline_rtx (out, v->next_containing_mem->val_rtx, 2);
    3606            0 :       fputc ('\n', out);
    3607              :     }
    3608           87 :   else if (need_lf)
    3609           81 :     fputc ('\n', out);
    3610              : 
    3611           93 :   return 1;
    3612              : }
    3613              : 
    3614              : /* Dump the cselib_val *X to FILE *OUT.  */
    3615              : 
    3616              : static int
    3617           93 : dump_cselib_val_ptr (cselib_val **x, FILE *out)
    3618              : {
    3619           93 :   cselib_val *v = *x;
    3620           93 :   return dump_cselib_val (v, out);
    3621              : }
    3622              : 
    3623              : /* Dump to OUT everything in the CSELIB table.  */
    3624              : 
    3625              : void
    3626           11 : dump_cselib_table (FILE *out)
    3627              : {
    3628           11 :   fprintf (out, "cselib hash table:\n");
    3629          104 :   cselib_hash_table->traverse <FILE *, dump_cselib_val_ptr> (out);
    3630           11 :   if (cselib_preserved_hash_table)
    3631              :     {
    3632           11 :       fprintf (out, "cselib preserved hash table:\n");
    3633           11 :       cselib_preserved_hash_table->traverse <FILE *, dump_cselib_val_ptr> (out);
    3634              :     }
    3635           11 :   if (first_containing_mem != &dummy_val)
    3636              :     {
    3637            6 :       fputs ("first mem ", out);
    3638            6 :       print_inline_rtx (out, first_containing_mem->val_rtx, 2);
    3639            6 :       fputc ('\n', out);
    3640              :     }
    3641           11 :   fprintf (out, "next uid %i\n", next_uid);
    3642           11 : }
    3643              : 
    3644              : #include "gt-cselib.h"
        

Generated by: LCOV version 2.4-beta

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