LCOV - code coverage report
Current view: top level - gcc - cselib.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.6 % 1631 1527
Test Date: 2026-12-05 16:10:02 Functions: 98.5 % 66 65
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 containing 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    106694617 : cselib_hasher::hash (const cselib_val *v)
     119              : {
     120    106694617 :   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    606883212 : cselib_hasher::equal (const cselib_val *v, const key *x_arg)
     130              : {
     131    606883212 :   struct elt_loc_list *l;
     132    606883212 :   rtx x = x_arg->x;
     133    606883212 :   machine_mode mode = x_arg->mode;
     134    606883212 :   machine_mode memmode = x_arg->memmode;
     135              : 
     136    606883212 :   if (mode != GET_MODE (v->val_rtx))
     137              :     return false;
     138              : 
     139    488907553 :   if (GET_CODE (x) == VALUE)
     140     13340539 :     return x == v->val_rtx;
     141              : 
     142    485783899 :   if (SP_DERIVED_VALUE_P (v->val_rtx) && GET_MODE (x) == Pmode)
     143              :     {
     144     18498705 :       rtx xoff = NULL;
     145     18498705 :       if (autoinc_split (x, &xoff, memmode) == v->val_rtx && xoff == NULL_RTX)
     146      8011593 :         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    803030498 :   for (l = v->locs; l; l = l->next)
     152    521708092 :     if (l->setting_insn && DEBUG_INSN_P (l->setting_insn)
     153     42015963 :         && (!cselib_current_insn || !DEBUG_INSN_P (cselib_current_insn)))
     154              :       {
     155     11797956 :         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     11797956 :         cselib_current_insn = l->setting_insn;
     161     11797956 :         bool match = rtx_equal_for_cselib_1 (l->loc, x, memmode, 0);
     162     11797956 :         cselib_current_insn = save_cselib_current_insn;
     163     11797956 :         if (match)
     164              :           {
     165       909038 :             promote_debug_loc (l);
     166       909038 :             return true;
     167              :           }
     168              :       }
     169    509910136 :     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    502894354 : new_elt_list (struct elt_list *next, cselib_val *elt)
     311              : {
     312   1005788708 :   elt_list *el = elt_list_pool.allocate ();
     313    502894354 :   el->next = next;
     314    502894354 :   el->elt = elt;
     315    502894354 :   return el;
     316              : }
     317              : 
     318              : /* Record that all_locs_preserved_p might no longer hold for VAL.  */
     319              : 
     320              : static inline void
     321    751042612 : cselib_clear_all_locs_preserved (cselib_val *val)
     322              : {
     323    751042612 :   if (val->all_locs_preserved_p)
     324              :     {
     325      7954124 :       val->all_locs_preserved_p = false;
     326      7954124 :       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      7902109 :         cselib_preserved_prune_list.safe_push (val);
     330              :     }
     331    751042612 : }
     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    747050414 : new_elt_loc_list (cselib_val *val, rtx loc)
     338              : {
     339    751048610 :   struct elt_loc_list *el, *next = val->locs;
     340              : 
     341    751048610 :   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    439124547 :   if (!next && cselib_current_insn && DEBUG_INSN_P (cselib_current_insn))
     348      7044184 :     n_debug_values++;
     349              : 
     350    751048610 :   val = canonical_cselib_val (val);
     351    751048610 :   next = val->locs;
     352              : 
     353    751048610 :   if (GET_CODE (loc) == VALUE)
     354              :     {
     355      8002782 :       loc = canonical_cselib_val (CSELIB_VAL_PTR (loc))->val_rtx;
     356      8002782 :       auto *loc_val = CSELIB_VAL_PTR (loc);
     357              : 
     358      8002782 :       gcc_checking_assert (PRESERVED_VALUE_P (loc)
     359              :                            == PRESERVED_VALUE_P (val->val_rtx));
     360              : 
     361      8002782 :       if (val->val_rtx == loc)
     362              :         return;
     363      7996588 :       else if (CSELIB_VAL_UID (val->val_rtx) > CSELIB_VAL_UID (loc))
     364              :         {
     365              :           /* Reverse the insertion.  */
     366              :           new_elt_loc_list (loc_val, val->val_rtx);
     367              :           return;
     368              :         }
     369              : 
     370      3998392 :       gcc_checking_assert (CSELIB_VAL_UID (val->val_rtx)
     371              :                            < CSELIB_VAL_UID (loc));
     372              : 
     373      3998392 :       if (loc_val->locs)
     374              :         {
     375              :           /* Bring all locs from LOC to VAL.  */
     376      3033409 :           for (el = loc_val->locs; el->next; el = el->next)
     377              :             {
     378              :               /* Adjust values that have LOC as canonical so that VAL
     379              :                  becomes their canonical.  */
     380           26 :               if (el->loc && GET_CODE (el->loc) == VALUE)
     381              :                 {
     382            0 :                   auto *el_val = CSELIB_VAL_PTR (el->loc);
     383            0 :                   gcc_checking_assert (el_val->locs->loc == loc);
     384            0 :                   el_val->locs->loc = val->val_rtx;
     385            0 :                   cselib_clear_all_locs_preserved (el_val);
     386              :                 }
     387              :             }
     388      3033383 :           el->next = val->locs;
     389      3033383 :           next = val->locs = loc_val->locs;
     390              :         }
     391              : 
     392      3998392 :       if (loc_val->addr_list)
     393              :         {
     394              :           /* Bring in addr_list into canonical node.  */
     395              :           struct elt_list *last = loc_val->addr_list;
     396            6 :           while (last->next)
     397              :             last = last->next;
     398            6 :           last->next = val->addr_list;
     399            6 :           val->addr_list = loc_val->addr_list;
     400            6 :           loc_val->addr_list = NULL;
     401              :         }
     402              : 
     403      3998392 :       if (loc_val->next_containing_mem != NULL
     404            2 :           && val->next_containing_mem == NULL)
     405              :         {
     406              :           /* Add VAL to the containing_mem list after LOC.  LOC will
     407              :              be removed when we notice it doesn't contain any
     408              :              MEMs.  */
     409            1 :           val->next_containing_mem = loc_val->next_containing_mem;
     410            1 :           loc_val->next_containing_mem = val;
     411              :         }
     412              : 
     413              :       /* Chain LOC back to VAL.  */
     414      3998392 :       el = elt_loc_list_pool.allocate ();
     415      3998392 :       el->loc = val->val_rtx;
     416      3998392 :       el->setting_insn = cselib_current_insn;
     417      3998392 :       el->next = NULL;
     418      3998392 :       loc_val->locs = el;
     419      3998392 :       cselib_clear_all_locs_preserved (loc_val);
     420              :     }
     421              : 
     422    747044220 :   el = elt_loc_list_pool.allocate ();
     423    747044220 :   el->loc = loc;
     424    747044220 :   el->setting_insn = cselib_current_insn;
     425    747044220 :   el->next = next;
     426    747044220 :   val->locs = el;
     427    747044220 :   cselib_clear_all_locs_preserved (val);
     428              : }
     429              : 
     430              : /* Promote loc L to a nondebug cselib_current_insn if L is marked as
     431              :    originating from a debug insn, maintaining the debug values
     432              :    count.  */
     433              : 
     434              : static inline void
     435   1280265297 : promote_debug_loc (struct elt_loc_list *l)
     436              : {
     437   1280265297 :   if (l && l->setting_insn && DEBUG_INSN_P (l->setting_insn)
     438     22409024 :       && (!cselib_current_insn || !DEBUG_INSN_P (cselib_current_insn)))
     439              :     {
     440      2601291 :       n_debug_values--;
     441      2601291 :       l->setting_insn = cselib_current_insn;
     442      2601291 :       if (cselib_preserve_constants && l->next)
     443              :         {
     444        23381 :           gcc_assert (l->next->setting_insn
     445              :                       && DEBUG_INSN_P (l->next->setting_insn)
     446              :                       && !l->next->next);
     447        23381 :           l->next->setting_insn = cselib_current_insn;
     448              :         }
     449              :       else
     450      2577910 :         gcc_assert (!l->next);
     451              :     }
     452   1280265297 : }
     453              : 
     454              : /* The elt_list at *PL is no longer needed.  Unchain it and free its
     455              :    storage.  */
     456              : 
     457              : static inline void
     458     82415359 : unchain_one_elt_list (struct elt_list **pl)
     459              : {
     460     82415359 :   struct elt_list *l = *pl;
     461              : 
     462     82415359 :   *pl = l->next;
     463    120482031 :   elt_list_pool.remove (l);
     464              : }
     465              : 
     466              : /* Likewise for elt_loc_lists.  */
     467              : 
     468              : static void
     469    231208453 : unchain_one_elt_loc_list (struct elt_loc_list **pl)
     470              : {
     471    231208453 :   struct elt_loc_list *l = *pl;
     472              : 
     473    231208453 :   *pl = l->next;
     474            0 :   elt_loc_list_pool.remove (l);
     475            0 : }
     476              : 
     477              : /* Likewise for cselib_vals.  This also frees the addr_list associated with
     478              :    V.  */
     479              : 
     480              : static void
     481      2441600 : unchain_one_value (cselib_val *v)
     482              : {
     483      2460761 :   while (v->addr_list)
     484        19161 :     unchain_one_elt_list (&v->addr_list);
     485              : 
     486      2441600 :   cselib_val_pool.remove (v);
     487      2441600 : }
     488              : 
     489              : /* Remove all entries from the hash table.  Also used during
     490              :    initialization.  */
     491              : 
     492              : void
     493     62639050 : cselib_clear_table (void)
     494              : {
     495     62639050 :   cselib_reset_table (1);
     496     62639050 : }
     497              : 
     498              : /* Return TRUE if V is a constant, a function invariant or a VALUE
     499              :    equivalence; FALSE otherwise.  */
     500              : 
     501              : static bool
     502     50288571 : invariant_or_equiv_p (cselib_val *v)
     503              : {
     504     59274961 :   struct elt_loc_list *l;
     505              : 
     506     59274961 :   if (v == cfa_base_preserved_val)
     507              :     return true;
     508              : 
     509              :   /* Keep VALUE equivalences around.  */
     510     82469130 :   for (l = v->locs; l; l = l->next)
     511     39813725 :     if (GET_CODE (l->loc) == VALUE)
     512              :       return true;
     513              : 
     514     42655405 :   if (v->locs != NULL
     515     23498480 :       && v->locs->next == NULL)
     516              :     {
     517     23441344 :       if (CONSTANT_P (v->locs->loc)
     518     23441344 :           && (GET_CODE (v->locs->loc) != CONST
     519       171545 :               || !references_value_p (v->locs->loc)))
     520              :         return true;
     521              :       /* Although a debug expr may be bound to different expressions,
     522              :          we can preserve it as if it was constant, to get unification
     523              :          and proper merging within var-tracking.  */
     524     19778755 :       if (GET_CODE (v->locs->loc) == DEBUG_EXPR
     525     18159104 :           || GET_CODE (v->locs->loc) == DEBUG_IMPLICIT_PTR
     526     17637231 :           || GET_CODE (v->locs->loc) == ENTRY_VALUE
     527     17637030 :           || GET_CODE (v->locs->loc) == DEBUG_PARAMETER_REF)
     528              :         return true;
     529              : 
     530              :       /* (plus (value V) (const_int C)) is invariant iff V is invariant.  */
     531     17621018 :       if (GET_CODE (v->locs->loc) == PLUS
     532     10870915 :           && CONST_INT_P (XEXP (v->locs->loc, 1))
     533      9724015 :           && GET_CODE (XEXP (v->locs->loc, 0)) == VALUE
     534     26607408 :           && invariant_or_equiv_p (CSELIB_VAL_PTR (XEXP (v->locs->loc, 0))))
     535              :         return true;
     536              :     }
     537              : 
     538              :   return false;
     539              : }
     540              : 
     541              : /* Remove from hash table all VALUEs except constants, function
     542              :    invariants and VALUE equivalences.  */
     543              : 
     544              : int
     545     45821985 : preserve_constants_and_equivs (cselib_val **x, void *info ATTRIBUTE_UNUSED)
     546              : {
     547     45821985 :   cselib_val *v = *x;
     548              : 
     549     45821985 :   if (invariant_or_equiv_p (v))
     550              :     {
     551     17973296 :       cselib_hasher::key lookup = {
     552     17973296 :         GET_MODE (v->val_rtx), v->val_rtx, VOIDmode
     553     17973296 :       };
     554     17973296 :       cselib_val **slot
     555     35946592 :         = cselib_preserved_hash_table->find_slot_with_hash (&lookup,
     556     17973296 :                                                             v->hash, INSERT);
     557     17973296 :       gcc_assert (!*slot);
     558     17973296 :       *slot = v;
     559     17973296 :       v->in_preserved_table_p = true;
     560     17973296 :       if (!v->all_locs_preserved_p)
     561            0 :         cselib_preserved_prune_list.safe_push (v);
     562              :     }
     563              : 
     564     45821985 :   cselib_hash_table->clear_slot (x);
     565              : 
     566     45821985 :   return 1;
     567              : }
     568              : 
     569              : /* Remove all entries from the hash table, arranging for the next
     570              :    value to be numbered NUM.  */
     571              : 
     572              : void
     573    103375040 : cselib_reset_table (unsigned int num)
     574              : {
     575    103375040 :   unsigned int i;
     576              : 
     577    103375040 :   max_value_regs = 0;
     578              : 
     579    103375040 :   if (cfa_base_preserved_val)
     580              :     {
     581      4466586 :       unsigned int regno = cfa_base_preserved_regno;
     582      4466586 :       unsigned int new_used_regs = 0;
     583     31891043 :       for (i = 0; i < n_used_regs; i++)
     584     27424457 :         if (used_regs[i] == regno)
     585              :           {
     586      4466586 :             new_used_regs = 1;
     587      4466586 :             continue;
     588              :           }
     589              :         else
     590     22957871 :           REG_VALUES (used_regs[i]) = 0;
     591      4466586 :       gcc_assert (new_used_regs == 1);
     592      4466586 :       n_used_regs = new_used_regs;
     593      4466586 :       used_regs[0] = regno;
     594      4466586 :       max_value_regs
     595      4466586 :         = hard_regno_nregs (regno,
     596      4466586 :                             GET_MODE (cfa_base_preserved_val->locs->loc));
     597              : 
     598              :       /* If cfa_base is sp + const_int, need to preserve also the
     599              :          SP_DERIVED_VALUE_P value.  */
     600      4466586 :       for (struct elt_loc_list *l = cfa_base_preserved_val->locs;
     601      8933172 :            l; l = l->next)
     602      8933172 :         if (GET_CODE (l->loc) == PLUS
     603      4466586 :             && GET_CODE (XEXP (l->loc, 0)) == VALUE
     604      4466586 :             && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
     605     13399758 :             && CONST_INT_P (XEXP (l->loc, 1)))
     606              :           {
     607      4466586 :             if (! invariant_or_equiv_p (CSELIB_VAL_PTR (XEXP (l->loc, 0))))
     608              :               {
     609            0 :                 rtx val = cfa_base_preserved_val->val_rtx;
     610            0 :                 rtx_insn *save_cselib_current_insn = cselib_current_insn;
     611            0 :                 cselib_current_insn = l->setting_insn;
     612            0 :                 new_elt_loc_list (CSELIB_VAL_PTR (XEXP (l->loc, 0)),
     613            0 :                                   plus_constant (Pmode, val,
     614            0 :                                                  -UINTVAL (XEXP (l->loc, 1))));
     615            0 :                 cselib_current_insn = save_cselib_current_insn;
     616              :               }
     617              :             break;
     618              :           }
     619              :     }
     620              :   else
     621              :     {
     622    382485961 :       for (i = 0; i < n_used_regs; i++)
     623    283577507 :         REG_VALUES (used_regs[i]) = 0;
     624     98908454 :       n_used_regs = 0;
     625              :     }
     626              : 
     627    103375040 :   if (cselib_preserve_constants)
     628     50288571 :     cselib_hash_table->traverse <void *, preserve_constants_and_equivs> (NULL);
     629              :   else
     630              :     {
     631     98908454 :       cselib_hash_table->empty ();
     632     98908454 :       gcc_checking_assert (!cselib_any_perm_equivs);
     633              :     }
     634              : 
     635    103375040 :   n_useless_values = 0;
     636    103375040 :   n_useless_debug_values = 0;
     637    103375040 :   n_debug_values = 0;
     638              : 
     639    103375040 :   next_uid = num;
     640              : 
     641    103375040 :   first_containing_mem = &dummy_val;
     642    103375040 : }
     643              : 
     644              : /* Return the number of the next value that will be generated.  */
     645              : 
     646              : unsigned int
     647      4969590 : cselib_get_next_uid (void)
     648              : {
     649      4969590 :   return next_uid;
     650              : }
     651              : 
     652              : /* Search for X, whose hashcode is HASH, in CSELIB_HASH_TABLE,
     653              :    INSERTing if requested.  When X is part of the address of a MEM,
     654              :    MEMMODE should specify the mode of the MEM.  */
     655              : 
     656              : static cselib_val **
     657    751305618 : cselib_find_slot (machine_mode mode, rtx x, hashval_t hash,
     658              :                   enum insert_option insert, machine_mode memmode)
     659              : {
     660    751305618 :   cselib_val **slot = NULL;
     661    751305618 :   cselib_hasher::key lookup = { mode, x, memmode };
     662    751305618 :   if (cselib_preserve_constants)
     663    165969354 :     slot = cselib_preserved_hash_table->find_slot_with_hash (&lookup, hash,
     664              :                                                              NO_INSERT);
     665    165969354 :   if (!slot)
     666    693945598 :     slot = cselib_hash_table->find_slot_with_hash (&lookup, hash, insert);
     667    751305618 :   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      2184152 : references_value_p (const_rtx x)
     677              : {
     678      2184152 :   subrtx_iterator::array_type array;
     679      5223029 :   FOR_EACH_SUBRTX (iter, array, x, ALL)
     680      3038877 :     if (GET_CODE (*iter) == VALUE)
     681            0 :       return true;
     682      2184152 :   return false;
     683      2184152 : }
     684              : 
     685              : /* Return true if V is a useless VALUE and can be discarded as such.  */
     686              : 
     687              : static bool
     688    739352858 : cselib_useless_value_p (cselib_val *v)
     689              : {
     690    739352858 :   return (v->locs == 0
     691     81572032 :           && !PRESERVED_VALUE_P (v->val_rtx)
     692    786766756 :           && !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     68222289 : discard_useless_locs (cselib_val *v)
     700              : {
     701     68222289 :   struct elt_loc_list **p = &v->locs;
     702     68222289 :   bool had_locs = v->locs != NULL;
     703     68222289 :   rtx_insn *setting_insn = v->locs ? v->locs->setting_insn : NULL;
     704              : 
     705     68222289 :   if (v->all_locs_preserved_p)
     706              :     return;
     707              : 
     708              :   bool all_locs_preserved_p = true;
     709    106928923 :   while (*p)
     710              :     {
     711              :       /* True if every value referenced by (*p)->loc is preserved.  */
     712     47211550 :       bool preserved_p = true;
     713     47211550 :       bool keep_p = true;
     714     47211550 :       subrtx_iterator::array_type array;
     715    158702458 :       FOR_EACH_SUBRTX (iter, array, (*p)->loc, ALL)
     716              :         {
     717    112831530 :           const_rtx x = *iter;
     718    112831530 :           if (GET_CODE (x) == VALUE && !PRESERVED_VALUE_P (x))
     719              :             {
     720      4906175 :               preserved_p = false;
     721      4906175 :               if (CSELIB_VAL_PTR (x)->locs == 0)
     722              :                 {
     723              :                   keep_p = false;
     724              :                   break;
     725              :                 }
     726              :             }
     727              :         }
     728     47211550 :       if (keep_p)
     729              :         {
     730     45870928 :           all_locs_preserved_p &= preserved_p;
     731     45870928 :           p = &(*p)->next;
     732              :         }
     733              :       else
     734      1340622 :         unchain_one_elt_loc_list (p);
     735     47211550 :     }
     736              : 
     737     59717373 :   if (all_locs_preserved_p)
     738     56626677 :     v->all_locs_preserved_p = true;
     739              : 
     740     59717373 :   if (had_locs && cselib_useless_value_p (v))
     741              :     {
     742      1205935 :       if (setting_insn && DEBUG_INSN_P (setting_insn))
     743            2 :         n_useless_debug_values++;
     744              :       else
     745      1205933 :         n_useless_values++;
     746      1205935 :       values_became_useless = 1;
     747              :     }
     748              : }
     749              : 
     750              : /* A hash-table traversal callback for the above.  */
     751              : 
     752              : int
     753     60320180 : discard_useless_locs (cselib_val **x, void *info ATTRIBUTE_UNUSED)
     754              : {
     755     60320180 :   discard_useless_locs (*x);
     756     60320180 :   return 1;
     757              : }
     758              : 
     759              : /* If X is a value with no locations, remove it from the hashtable.  */
     760              : 
     761              : int
     762     49766492 : discard_useless_values (cselib_val **x, void *info ATTRIBUTE_UNUSED)
     763              : {
     764     49766492 :   cselib_val *v = *x;
     765              : 
     766     49766492 :   if (v->locs == 0 && cselib_useless_value_p (v))
     767              :     {
     768      2441600 :       if (cselib_discard_hook)
     769       578883 :         cselib_discard_hook (v);
     770              : 
     771      2441600 :       CSELIB_VAL_PTR (v->val_rtx) = NULL;
     772      2441600 :       cselib_hash_table->clear_slot (x);
     773      2441600 :       unchain_one_value (v);
     774      2441600 :       n_useless_values--;
     775              :     }
     776              : 
     777     49766492 :   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      4495445 : remove_useless_values (void)
     785              : {
     786      4550483 :   cselib_val **p, *v;
     787              : 
     788              :   /* First pass: eliminate locations that reference the value.  That in
     789              :      turn can make more values useless.  */
     790      4550483 :   do
     791              :     {
     792      4550483 :       values_became_useless = 0;
     793     64870663 :       cselib_hash_table->traverse <void *, discard_useless_locs> (NULL);
     794              :     }
     795      4550483 :   while (values_became_useless);
     796              : 
     797              :   /* Second pass: actually remove the values.  */
     798              : 
     799      4495445 :   p = &first_containing_mem;
     800      4622646 :   for (v = *p; v != &dummy_val; v = v->next_containing_mem)
     801       127201 :     if (v->locs && v == canonical_cselib_val (v))
     802              :       {
     803       124199 :         *p = v;
     804       124199 :         p = &(*p)->next_containing_mem;
     805              :       }
     806      4495445 :   *p = &dummy_val;
     807              : 
     808      4495445 :   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      4466586 :       unsigned int len = cselib_preserved_prune_list.length ();
     815      4466586 :       unsigned int dest_i = 0;
     816      4466586 :       unsigned int src_i = 0;
     817     12368695 :       for (; src_i < len; ++src_i)
     818              :         {
     819      7902109 :           auto *val = cselib_preserved_prune_list[src_i];
     820      7902109 :           discard_useless_locs (val);
     821      7902109 :           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      4466586 :       if (src_i != dest_i)
     829      3731263 :         cselib_preserved_prune_list.truncate (dest_i);
     830              :     }
     831      4495445 :   gcc_assert (!values_became_useless);
     832              : 
     833      4495445 :   n_useless_values += n_useless_debug_values;
     834      4495445 :   n_debug_values -= n_useless_debug_values;
     835      4495445 :   n_useless_debug_values = 0;
     836              : 
     837     54261937 :   cselib_hash_table->traverse <void *, discard_useless_values> (NULL);
     838              : 
     839      4495445 :   gcc_assert (!n_useless_values);
     840      4495445 : }
     841              : 
     842              : /* Arrange for a value to not be removed from the hash table even if
     843              :    it becomes useless.  */
     844              : 
     845              : void
     846     46413383 : cselib_preserve_value (cselib_val *v)
     847              : {
     848     46413383 :   PRESERVED_VALUE_P (v->val_rtx) = 1;
     849     46413383 : }
     850              : 
     851              : /* Test whether a value is preserved.  */
     852              : 
     853              : bool
     854    271095431 : cselib_preserved_value_p (cselib_val *v)
     855              : {
     856    271095431 :   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      1005519 : cselib_preserve_cfa_base_value (cselib_val *v, unsigned int regno)
     864              : {
     865      1005519 :   if (cselib_preserve_constants
     866      1005519 :       && v->locs
     867      1005519 :       && REG_P (v->locs->loc))
     868              :     {
     869       503306 :       cfa_base_preserved_val = v;
     870       503306 :       cfa_base_preserved_regno = regno;
     871              :     }
     872      1005519 : }
     873              : 
     874              : /* Clean all non-constant expressions in the hash table, but retain
     875              :    their values.  */
     876              : 
     877              : void
     878      4466586 : cselib_preserve_only_values (void)
     879              : {
     880      4466586 :   int i;
     881              : 
     882    424325670 :   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
     883    419859084 :     cselib_invalidate_regno (i, reg_raw_mode[i]);
     884              : 
     885      4466586 :   cselib_invalidate_mem (callmem[0]);
     886              : 
     887      4466586 :   remove_useless_values ();
     888              : 
     889      4466586 :   gcc_assert (first_containing_mem == &dummy_val);
     890      4466586 : }
     891              : 
     892              : /* Arrange for a value to be marked as based on stack pointer
     893              :    for find_base_term purposes.  */
     894              : 
     895              : void
     896      1944255 : cselib_set_value_sp_based (cselib_val *v)
     897              : {
     898      1944255 :   SP_BASED_VALUE_P (v->val_rtx) = 1;
     899      1944255 : }
     900              : 
     901              : /* Test whether a value is based on stack pointer for
     902              :    find_base_term purposes.  */
     903              : 
     904              : bool
     905    850298575 : cselib_sp_based_value_p (cselib_val *v)
     906              : {
     907    850298575 :   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    116971970 : cselib_reg_set_mode (const_rtx x)
     917              : {
     918    116971970 :   if (!REG_P (x))
     919     35038138 :     return GET_MODE (x);
     920              : 
     921     81933832 :   if (REG_VALUES (REGNO (x)) == NULL
     922     81933832 :       || REG_VALUES (REGNO (x))->elt == NULL)
     923              :     return VOIDmode;
     924              : 
     925     24979473 :   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   1528232071 : autoinc_split (rtx x, rtx *off, machine_mode memmode)
     933              : {
     934   1528232071 :   switch (GET_CODE (x))
     935              :     {
     936    844095759 :     case PLUS:
     937    844095759 :       *off = XEXP (x, 1);
     938    844095759 :       x = XEXP (x, 0);
     939    844095759 :       break;
     940              : 
     941     12865620 :     case PRE_DEC:
     942     12865620 :       if (memmode == VOIDmode)
     943              :         return x;
     944              : 
     945     25731240 :       *off = gen_int_mode (-GET_MODE_SIZE (memmode), GET_MODE (x));
     946     12865620 :       x = XEXP (x, 0);
     947     12865620 :       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      1726352 :     case PRE_MODIFY:
     958      1726352 :       x = XEXP (x, 1);
     959      1726352 :       break;
     960              : 
     961      1890407 :     case POST_DEC:
     962      1890407 :     case POST_INC:
     963      1890407 :     case POST_MODIFY:
     964      1890407 :       x = XEXP (x, 0);
     965      1890407 :       break;
     966              : 
     967              :     default:
     968              :       break;
     969              :     }
     970              : 
     971   1528232071 :   if (GET_MODE (x) == Pmode
     972   1476338205 :       && (REG_P (x) || MEM_P (x) || GET_CODE (x) == VALUE)
     973   2374626936 :       && (*off == NULL_RTX || CONST_INT_P (*off)))
     974              :     {
     975    841439547 :       cselib_val *e;
     976    841439547 :       if (GET_CODE (x) == VALUE)
     977    537582863 :         e = CSELIB_VAL_PTR (x);
     978              :       else
     979    303856684 :         e = cselib_lookup (x, GET_MODE (x), 0, memmode);
     980    841439547 :       if (e)
     981              :         {
     982    831916310 :           if (SP_DERIVED_VALUE_P (e->val_rtx)
     983    831916310 :               && (*off == NULL_RTX || *off == const0_rtx))
     984              :             {
     985        74884 :               *off = NULL_RTX;
     986        74884 :               return e->val_rtx;
     987              :             }
     988   1816498172 :           for (struct elt_loc_list *l = e->locs; l; l = l->next)
     989   1422072326 :             if (GET_CODE (l->loc) == PLUS
     990    604951178 :                 && GET_CODE (XEXP (l->loc, 0)) == VALUE
     991    604070253 :                 && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
     992   1859495815 :                 && CONST_INT_P (XEXP (l->loc, 1)))
     993              :               {
     994    437415580 :                 if (*off == NULL_RTX)
     995      1538399 :                   *off = XEXP (l->loc, 1);
     996              :                 else
     997    435877181 :                   *off = plus_constant (Pmode, *off,
     998    435877181 :                                         INTVAL (XEXP (l->loc, 1)));
     999    437415580 :                 if (*off == const0_rtx)
    1000    270010224 :                   *off = NULL_RTX;
    1001    437415580 :                 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   1259057465 : rtx_equal_for_cselib_1 (rtx x, rtx y, machine_mode memmode, int depth)
    1016              : {
    1017   1654605253 :   enum rtx_code code;
    1018   1654605253 :   const char *fmt;
    1019   1654605253 :   int i;
    1020              : 
    1021   1654605253 :   if (REG_P (x) || MEM_P (x))
    1022              :     {
    1023    157133211 :       cselib_val *e = cselib_lookup (x, GET_MODE (x), 0, memmode);
    1024              : 
    1025    157133211 :       if (e)
    1026    133128614 :         x = e->val_rtx;
    1027              :     }
    1028              : 
    1029   1654605253 :   if (REG_P (y) || MEM_P (y))
    1030              :     {
    1031    147902760 :       cselib_val *e = cselib_lookup (y, GET_MODE (y), 0, memmode);
    1032              : 
    1033    147902760 :       if (e)
    1034    135712927 :         y = e->val_rtx;
    1035              :     }
    1036              : 
    1037   1654605253 :   if (x == y)
    1038              :     return true;
    1039              : 
    1040   1314980255 :   if (GET_CODE (x) == VALUE)
    1041              :     {
    1042    448849892 :       cselib_val *e = canonical_cselib_val (CSELIB_VAL_PTR (x));
    1043    448849892 :       struct elt_loc_list *l;
    1044              : 
    1045    448849892 :       if (GET_CODE (y) == VALUE)
    1046     32532998 :         return e == canonical_cselib_val (CSELIB_VAL_PTR (y));
    1047              : 
    1048    416316894 :       if ((SP_DERIVED_VALUE_P (x)
    1049    156779827 :            || SP_DERIVED_VALUE_P (e->val_rtx))
    1050    460508224 :           && GET_MODE (y) == Pmode)
    1051              :         {
    1052    262016359 :           rtx yoff = NULL;
    1053    262016359 :           rtx yr = autoinc_split (y, &yoff, memmode);
    1054    262016359 :           if ((yr == x || yr == e->val_rtx) && yoff == NULL_RTX)
    1055        53217 :             return true;
    1056              :         }
    1057              : 
    1058    416263677 :       if (depth == 128)
    1059              :         return false;
    1060              : 
    1061   1280404276 :       for (l = e->locs; l; l = l->next)
    1062              :         {
    1063    887575838 :           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    887575838 :           if (REG_P (t) || MEM_P (t) || GET_CODE (t) == VALUE)
    1069    529691564 :             continue;
    1070    357884274 :           else if (rtx_equal_for_cselib_1 (t, y, memmode, depth + 1))
    1071              :             return true;
    1072              :         }
    1073              : 
    1074              :       return false;
    1075              :     }
    1076    866130363 :   else if (GET_CODE (y) == VALUE)
    1077              :     {
    1078     47700257 :       cselib_val *e = canonical_cselib_val (CSELIB_VAL_PTR (y));
    1079     47700257 :       struct elt_loc_list *l;
    1080              : 
    1081     47700257 :       if ((SP_DERIVED_VALUE_P (y)
    1082     45340286 :            || SP_DERIVED_VALUE_P (e->val_rtx))
    1083     48139917 :           && GET_MODE (x) == Pmode)
    1084              :         {
    1085      2281349 :           rtx xoff = NULL;
    1086      2281349 :           rtx xr = autoinc_split (x, &xoff, memmode);
    1087      2281349 :           if ((xr == y || xr == e->val_rtx) && xoff == NULL_RTX)
    1088          167 :             return true;
    1089              :         }
    1090              : 
    1091     47700090 :       if (depth == 128)
    1092              :         return false;
    1093              : 
    1094    115992678 :       for (l = e->locs; l; l = l->next)
    1095              :         {
    1096     68369388 :           rtx t = l->loc;
    1097              : 
    1098     68369388 :           if (REG_P (t) || MEM_P (t) || GET_CODE (t) == VALUE)
    1099     59087582 :             continue;
    1100      9281806 :           else if (rtx_equal_for_cselib_1 (x, t, memmode, depth + 1))
    1101              :             return true;
    1102              :         }
    1103              : 
    1104              :       return false;
    1105              :     }
    1106              : 
    1107    818430106 :   if (GET_MODE (x) != GET_MODE (y))
    1108              :     return false;
    1109              : 
    1110    777494223 :   if (GET_CODE (x) != GET_CODE (y)
    1111    777494223 :       || (GET_CODE (x) == PLUS
    1112    355223699 :           && GET_MODE (x) == Pmode
    1113    255050215 :           && CONST_INT_P (XEXP (x, 1))
    1114    244198819 :           && CONST_INT_P (XEXP (y, 1))))
    1115              :     {
    1116    622717829 :       rtx xorig = x, yorig = y;
    1117    622717829 :       rtx xoff = NULL, yoff = NULL;
    1118              : 
    1119    622717829 :       x = autoinc_split (x, &xoff, memmode);
    1120    622717829 :       y = autoinc_split (y, &yoff, memmode);
    1121              : 
    1122              :       /* Don't recurse if nothing changed.  */
    1123    622717829 :       if (x != xorig || y != yorig)
    1124              :         {
    1125    581670961 :           if (!xoff != !yoff)
    1126    227817206 :             return false;
    1127              : 
    1128    497529358 :           if (xoff && !rtx_equal_for_cselib_1 (xoff, yoff, memmode, depth))
    1129              :             return false;
    1130              : 
    1131              :           return rtx_equal_for_cselib_1 (x, y, memmode, depth);
    1132              :         }
    1133              : 
    1134     41046868 :       if (GET_CODE (xorig) != GET_CODE (yorig))
    1135              :         return false;
    1136              :     }
    1137              : 
    1138              :   /* These won't be handled correctly by the code below.  */
    1139    154776394 :   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      2368366 :     case DEBUG_IMPLICIT_PTR:
    1151      2368366 :       return DEBUG_IMPLICIT_PTR_DECL (x)
    1152      2368366 :              == DEBUG_IMPLICIT_PTR_DECL (y);
    1153              : 
    1154         4952 :     case DEBUG_PARAMETER_REF:
    1155         4952 :       return DEBUG_PARAMETER_REF_DECL (x)
    1156         4952 :              == DEBUG_PARAMETER_REF_DECL (y);
    1157              : 
    1158       305328 :     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       305328 :       return rtx_equal_p (ENTRY_VALUE_EXP (x), ENTRY_VALUE_EXP (y));
    1162              : 
    1163          244 :     case LABEL_REF:
    1164          244 :       return label_ref_label (x) == label_ref_label (y);
    1165              : 
    1166          187 :     case REG:
    1167          187 :       return REGNO (x) == REGNO (y);
    1168              : 
    1169       647165 :     case MEM:
    1170              :       /* We have to compare any autoinc operations in the addresses
    1171              :          using this MEM's mode.  */
    1172       647165 :       return rtx_equal_for_cselib_1 (XEXP (x, 0), XEXP (y, 0), GET_MODE (x),
    1173       647165 :                                      depth);
    1174              : 
    1175              :     default:
    1176              :       break;
    1177              :     }
    1178              : 
    1179     41172206 :   code = GET_CODE (x);
    1180     41172206 :   fmt = GET_RTX_FORMAT (code);
    1181              : 
    1182     71176445 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1183              :     {
    1184     59643453 :       int j;
    1185              : 
    1186     59643453 :       switch (fmt[i])
    1187              :         {
    1188            0 :         case 'w':
    1189            0 :           if (XWINT (x, i) != XWINT (y, i))
    1190              :             return false;
    1191              :           break;
    1192              : 
    1193       625471 :         case 'n':
    1194       625471 :         case 'i':
    1195       625471 :           if (XINT (x, i) != XINT (y, i))
    1196              :             return false;
    1197              :           break;
    1198              : 
    1199         5650 :         case 'L':
    1200         5650 :           if (XLOC (x, i) != XLOC (y, i))
    1201              :             return false;
    1202              :           break;
    1203              : 
    1204       625526 :         case 'p':
    1205       625526 :           if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y)))
    1206              :             return false;
    1207              :           break;
    1208              : 
    1209      1646620 :         case 'V':
    1210      1646620 :         case 'E':
    1211              :           /* Two vectors must have the same length.  */
    1212      1646620 :           if (XVECLEN (x, i) != XVECLEN (y, i))
    1213              :             return false;
    1214              : 
    1215              :           /* And the corresponding elements must match.  */
    1216      4084130 :           for (j = 0; j < XVECLEN (x, i); j++)
    1217      3401079 :             if (! rtx_equal_for_cselib_1 (XVECEXP (x, i, j),
    1218      3401079 :                                           XVECEXP (y, i, j), memmode, depth))
    1219              :               return false;
    1220              :           break;
    1221              : 
    1222     45482658 :         case 'e':
    1223     45482658 :           if (i == 1
    1224     28837983 :               && targetm.commutative_p (x, UNKNOWN)
    1225     20603734 :               && rtx_equal_for_cselib_1 (XEXP (x, 1), XEXP (y, 0), memmode,
    1226              :                                          depth)
    1227     45787316 :               && rtx_equal_for_cselib_1 (XEXP (x, 0), XEXP (y, 1), memmode,
    1228              :                                          depth))
    1229              :             return true;
    1230     45276568 :           if (! rtx_equal_for_cselib_1 (XEXP (x, i), XEXP (y, i), memmode,
    1231              :                                         depth))
    1232              :             return false;
    1233              :           break;
    1234              : 
    1235      5705214 :         case 'S':
    1236      5705214 :         case 's':
    1237      5705214 :           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    116971970 : cselib_redundant_set_p (rtx set)
    1263              : {
    1264    116971970 :   gcc_assert (GET_CODE (set) == SET);
    1265    116971970 :   rtx dest = SET_DEST (set);
    1266    116971970 :   if (cselib_reg_set_mode (dest) != GET_MODE (dest))
    1267              :     return false;
    1268              : 
    1269     55936902 :   rtx src = SET_SRC (set);
    1270      4020794 :   if ((MEM_P (src) && MEM_VOLATILE_P (src))
    1271     59881507 :        || !rtx_equal_for_cselib_p (dest, src))
    1272              :     return false;
    1273              : 
    1274       440828 :   while (GET_CODE (dest) == SUBREG
    1275       440824 :          || GET_CODE (dest) == ZERO_EXTRACT
    1276       881652 :          || GET_CODE (dest) == STRICT_LOW_PART)
    1277            4 :     dest = XEXP (dest, 0);
    1278              : 
    1279       440824 :   if (!flag_strict_aliasing || !MEM_P (dest))
    1280              :     return true;
    1281              : 
    1282        30800 :   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        30800 :   rtx dest_addr = XEXP (dest, 0);
    1288              : 
    1289              :   /* Lookup the equivalents to the original dest (rather than just the
    1290              :      MEM).  */
    1291        61600 :   cselib_val *src_val = cselib_lookup (SET_DEST (set),
    1292        30800 :                                        GET_MODE (SET_DEST (set)),
    1293              :                                        0, VOIDmode);
    1294              : 
    1295        30800 :   if (src_val)
    1296              :     {
    1297              :       /* Walk the list of source equivalents to find the MEM accessing
    1298              :          the same location.  */
    1299        67200 :       for (elt_loc_list *l = src_val->locs; l; l = l->next)
    1300              :         {
    1301        67200 :           rtx src_equiv = l->loc;
    1302        67200 :           while (GET_CODE (src_equiv) == SUBREG
    1303        67200 :                  || GET_CODE (src_equiv) == ZERO_EXTRACT
    1304       134402 :                  || GET_CODE (src_equiv) == STRICT_LOW_PART)
    1305            2 :             src_equiv = XEXP (src_equiv, 0);
    1306              : 
    1307        67200 :           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        34747 :               if (rtx_equal_for_cselib_1 (dest_addr, XEXP (src_equiv, 0),
    1313        34747 :                                           GET_MODE (dest), 0))
    1314        30794 :                 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    301642623 : cselib_hash_plus_const_int (rtx x, HOST_WIDE_INT c, int create,
    1337              :                             machine_mode memmode)
    1338              : {
    1339    301642623 :   cselib_val *e = cselib_lookup (x, GET_MODE (x), create, memmode);
    1340    301642623 :   if (! e)
    1341              :     return 0;
    1342              : 
    1343    285913466 :   if (! SP_DERIVED_VALUE_P (e->val_rtx))
    1344    457891790 :     for (struct elt_loc_list *l = e->locs; l; l = l->next)
    1345    367860712 :       if (GET_CODE (l->loc) == PLUS
    1346    132678380 :           && GET_CODE (XEXP (l->loc, 0)) == VALUE
    1347    132112658 :           && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
    1348    493774286 :           && CONST_INT_P (XEXP (l->loc, 1)))
    1349              :         {
    1350    125901007 :           e = CSELIB_VAL_PTR (XEXP (l->loc, 0));
    1351    125901007 :           c = trunc_int_for_mode (c + UINTVAL (XEXP (l->loc, 1)), Pmode);
    1352    125901007 :           break;
    1353              :         }
    1354    285913466 :   if (c == 0)
    1355      8213495 :     return e->hash;
    1356              : 
    1357    277699971 :   inchash::hash hash;
    1358    277699971 :   hash.add_int (PLUS);
    1359    277699971 :   hash.add_int (GET_MODE (x));
    1360    277699971 :   hash.merge_hash (e->hash);
    1361    277699971 :   hash.add_hwi (c);
    1362              : 
    1363    277699971 :   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   1044594237 : cselib_hash_rtx (rtx x, int create, machine_mode memmode)
    1390              : {
    1391   1044594237 :   cselib_val *e;
    1392   1044594237 :   poly_int64 offset;
    1393   1044594237 :   int i, j;
    1394   1044594237 :   enum rtx_code code;
    1395   1044594237 :   const char *fmt;
    1396   1044594237 :   inchash::hash hash;
    1397              : 
    1398   1044594237 :   code = GET_CODE (x);
    1399   1044594237 :   hash.add_int (code);
    1400   1044594237 :   hash.add_int (GET_MODE (x));
    1401              : 
    1402   1044594237 :   switch (code)
    1403              :     {
    1404       435510 :     case VALUE:
    1405       435510 :       e = CSELIB_VAL_PTR (x);
    1406       435510 :       return e->hash;
    1407              : 
    1408    226052124 :     case MEM:
    1409    226052124 :     case REG:
    1410    226052124 :       e = cselib_lookup (x, GET_MODE (x), create, memmode);
    1411    226052124 :       if (! e)
    1412              :         return 0;
    1413              : 
    1414    200380606 :       return e->hash;
    1415              : 
    1416     14289663 :     case DEBUG_EXPR:
    1417     14289663 :       hash.add_int (DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x)));
    1418     14289663 :       return hash.end () ? hash.end() : (unsigned int) DEBUG_EXPR;
    1419              : 
    1420      3051800 :     case DEBUG_IMPLICIT_PTR:
    1421      3051800 :       hash.add_int (DECL_UID (DEBUG_IMPLICIT_PTR_DECL (x)));
    1422      3051800 :       return hash.end () ? hash.end () : (unsigned int) DEBUG_IMPLICIT_PTR;
    1423              : 
    1424        36700 :     case DEBUG_PARAMETER_REF:
    1425        36700 :       hash.add_int (DECL_UID (DEBUG_PARAMETER_REF_DECL (x)));
    1426        36700 :       return hash.end () ? hash.end () : (unsigned int) DEBUG_PARAMETER_REF;
    1427              : 
    1428      1399195 :     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      1399195 :       if (REG_P (ENTRY_VALUE_EXP (x)))
    1435      1382055 :         hash.add_int ((unsigned int) REG
    1436      1382055 :                       + (unsigned int) GET_MODE (ENTRY_VALUE_EXP (x))
    1437      1382055 :                       + (unsigned int) REGNO (ENTRY_VALUE_EXP (x)));
    1438        17140 :       else if (MEM_P (ENTRY_VALUE_EXP (x))
    1439        17140 :                && REG_P (XEXP (ENTRY_VALUE_EXP (x), 0)))
    1440        17140 :         hash.add_int ((unsigned int) MEM
    1441        17140 :                       + (unsigned int) GET_MODE (XEXP (ENTRY_VALUE_EXP (x), 0))
    1442        17140 :                       + (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      1399195 :       return hash.end () ? hash.end () : (unsigned int) ENTRY_VALUE;
    1446              : 
    1447    181630993 :     case CONST_INT:
    1448    181630993 :       hash.add_hwi (UINTVAL (x));
    1449    181630993 :       return hash.end () ? hash.end () : (unsigned int) CONST_INT;
    1450              : 
    1451              :     case CONST_WIDE_INT:
    1452      3091622 :       for (i = 0; i < CONST_WIDE_INT_NUNITS (x); i++)
    1453      2062941 :         hash.add_hwi (CONST_WIDE_INT_ELT (x, i));
    1454      1028681 :       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      3678900 :     case CONST_DOUBLE:
    1464              :       /* This is like the general case, except that it only counts
    1465              :          the integers representing the constant.  */
    1466      3678900 :       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      3678900 :         hash.merge_hash (real_hash (CONST_DOUBLE_REAL_VALUE (x)));
    1473      3678900 :       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      3608337 :     case CONST_VECTOR:
    1480      3608337 :       {
    1481      3608337 :         int units;
    1482      3608337 :         rtx elt;
    1483              : 
    1484      3608337 :         units = const_vector_encoded_nelts (x);
    1485              : 
    1486      9156541 :         for (i = 0; i < units; ++i)
    1487              :           {
    1488      5548204 :             elt = CONST_VECTOR_ENCODED_ELT (x, i);
    1489      5548204 :             hash.merge_hash (cselib_hash_rtx (elt, 0, memmode));
    1490              :           }
    1491              : 
    1492      3608337 :         return hash.end () ? hash.end () : (unsigned int) CONST_VECTOR;
    1493              :       }
    1494              : 
    1495              :       /* Assume there is only one rtx object for any given label.  */
    1496       146387 :     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       146387 :       hash.add_int (CODE_LABEL_NUMBER (label_ref_label (x)));
    1500       146387 :       return hash.end () ? hash.end () : (unsigned int) LABEL_REF;
    1501              : 
    1502     70010232 :     case SYMBOL_REF:
    1503     70010232 :       {
    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     70010232 :         const char *p = (const char *) XSTR (x, 0);
    1510              : 
    1511     70010232 :         if (*p)
    1512     70010232 :           hash.add (p, strlen (p));
    1513              : 
    1514     70010232 :         return hash.end () ? hash.end () : (unsigned int) SYMBOL_REF;
    1515              :       }
    1516              : 
    1517     17708034 :     case PRE_DEC:
    1518     17708034 :     case PRE_INC:
    1519     17708034 :       {
    1520              :         /* We can't compute these without knowing the MEM mode.  */
    1521     17708034 :         gcc_assert (memmode != VOIDmode);
    1522     35416068 :         offset = GET_MODE_SIZE (memmode);
    1523     17708034 :         if (code == PRE_DEC)
    1524     17708034 :           offset = -offset;
    1525              :         /* Adjust the hash so that (mem:MEMMODE (pre_* (reg))) hashes
    1526              :            like (mem:MEMMODE (plus (reg) (const_int I))).  */
    1527     17708034 :         if (GET_MODE (x) == Pmode
    1528     17708034 :             && (REG_P (XEXP (x, 0))
    1529              :                 || MEM_P (XEXP (x, 0))
    1530              :                 || GET_CODE (XEXP (x, 0)) == VALUE))
    1531              :           {
    1532     17708034 :             HOST_WIDE_INT c;
    1533     17708034 :             if (offset.is_constant (&c))
    1534     17708034 :               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       521457 :     case PRE_MODIFY:
    1552       521457 :       {
    1553       521457 :         gcc_assert (memmode != VOIDmode);
    1554       521457 :         hashval_t tem_hash = cselib_hash_rtx (XEXP (x, 1), create, memmode);
    1555       521457 :         if (tem_hash == 0)
    1556              :           return 0;
    1557       514841 :         hash.merge_hash (tem_hash);
    1558       514841 :         return hash.end () ? hash.end () : 1 + (unsigned) PRE_MODIFY;
    1559              :       }
    1560              : 
    1561      1850251 :     case POST_DEC:
    1562      1850251 :     case POST_INC:
    1563      1850251 :     case POST_MODIFY:
    1564      1850251 :       {
    1565      1850251 :         gcc_assert (memmode != VOIDmode);
    1566      1850251 :         hashval_t tem_hash = cselib_hash_rtx (XEXP (x, 0), create, memmode);
    1567      1850251 :         if (tem_hash == 0)
    1568              :           return 0;
    1569      1850251 :         hash.merge_hash (tem_hash);
    1570      1850251 :         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       493782 :     case ASM_OPERANDS:
    1579       493782 :       if (MEM_VOLATILE_P (x))
    1580              :         return 0;
    1581              : 
    1582              :       break;
    1583              : 
    1584    340494892 :     case PLUS:
    1585    340494892 :       if (GET_MODE (x) == Pmode
    1586    328928976 :           && (REG_P (XEXP (x, 0))
    1587              :               || MEM_P (XEXP (x, 0))
    1588              :               || GET_CODE (XEXP (x, 0)) == VALUE)
    1589    643422876 :           && CONST_INT_P (XEXP (x, 1)))
    1590    283934589 :         return cselib_hash_plus_const_int (XEXP (x, 0), INTVAL (XEXP (x, 1)),
    1591    283934589 :                                            create, memmode);
    1592              :       break;
    1593              : 
    1594              :     default:
    1595              :       break;
    1596              :     }
    1597              : 
    1598    219511444 :   i = GET_RTX_LENGTH (code) - 1;
    1599    219511444 :   fmt = GET_RTX_FORMAT (code);
    1600              : 
    1601    219511444 :   if (COMMUTATIVE_P (x))
    1602              :     {
    1603     82659505 :       gcc_assert (i == 1 && fmt[0] == 'e' && fmt[1] == 'e');
    1604     82659505 :       hashval_t tem1_hash = cselib_hash_rtx (XEXP (x, 1), create, memmode);
    1605     82659505 :       if (tem1_hash == 0)
    1606              :         return 0;
    1607     76698431 :       hashval_t tem0_hash = cselib_hash_rtx (XEXP (x, 0), create, memmode);
    1608     76698431 :       if (tem0_hash == 0)
    1609              :         return 0;
    1610     72779075 :       hash.add_commutative (tem0_hash, tem1_hash);
    1611     72779075 :       return hash.end () ? hash.end () : 1 + (unsigned int) GET_CODE (x);
    1612              :     }
    1613              : 
    1614    360473850 :   for (; i >= 0; i--)
    1615              :     {
    1616    242549277 :       switch (fmt[i])
    1617              :         {
    1618    220166766 :         case 'e':
    1619    220166766 :           {
    1620    220166766 :             rtx tem = XEXP (x, i);
    1621    220166766 :             hashval_t tem_hash = cselib_hash_rtx (tem, create, memmode);
    1622    220166766 :             if (tem_hash == 0)
    1623              :               return 0;
    1624    202194456 :             hash.merge_hash (tem_hash);
    1625              :           }
    1626    202194456 :           break;
    1627              :         case 'E':
    1628     28625166 :           for (j = 0; j < XVECLEN (x, i); j++)
    1629              :             {
    1630     20118514 :               hashval_t tem_hash
    1631     20118514 :                 = cselib_hash_rtx (XVECEXP (x, i, j), create, memmode);
    1632     20118514 :               if (tem_hash == 0)
    1633              :                 return 0;
    1634     19163458 :               hash.merge_hash (tem_hash);
    1635              :             }
    1636              :           break;
    1637              : 
    1638       522813 :         case 's':
    1639       522813 :           {
    1640       522813 :             const char *p = (const char *) XSTR (x, i);
    1641              : 
    1642       522813 :             if (p && *p)
    1643       490416 :               hash.add (p, strlen (p));
    1644              :             break;
    1645              :           }
    1646              : 
    1647      5749044 :         case 'i':
    1648      5749044 :           hash.add_hwi (XINT (x, i));
    1649      5749044 :           break;
    1650              : 
    1651       246131 :         case 'L':
    1652       246131 :           hash.add_hwi (XLOC (x, i));
    1653       246131 :           break;
    1654              : 
    1655      6402815 :         case 'p':
    1656      6402815 :           hash.add_int (constant_lower_bound (SUBREG_BYTE (x)));
    1657      6402815 :           break;
    1658              : 
    1659              :         case '0':
    1660              :         case 't':
    1661              :           /* unused */
    1662              :           break;
    1663              : 
    1664            0 :         default:
    1665            0 :           gcc_unreachable ();
    1666              :         }
    1667              :     }
    1668              : 
    1669    117924573 :   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    433733486 : new_cselib_val (hashval_t hash, machine_mode mode, rtx x)
    1677              : {
    1678    433733486 :   cselib_val *e = cselib_val_pool.allocate ();
    1679              : 
    1680    433733486 :   gcc_assert (hash);
    1681    433733486 :   gcc_assert (next_uid);
    1682              : 
    1683    433733486 :   e->hash = hash;
    1684    433733486 :   e->in_preserved_table_p = false;
    1685    433733486 :   e->all_locs_preserved_p = false;
    1686              :   /* We use an alloc pool to allocate this RTL construct because it
    1687              :      accounts for about 8% of the overall memory usage.  We know
    1688              :      precisely when we can have VALUE RTXen (when cselib is active)
    1689              :      so we don't need to put them in garbage collected memory.
    1690              :      ??? Why should a VALUE be an RTX in the first place?  */
    1691    433733486 :   e->val_rtx = (rtx_def*) value_pool.allocate ();
    1692    433733486 :   memset (e->val_rtx, 0, RTX_HDR_SIZE);
    1693    433733486 :   PUT_CODE (e->val_rtx, VALUE);
    1694    433733486 :   PUT_MODE (e->val_rtx, mode);
    1695    433733486 :   CSELIB_VAL_PTR (e->val_rtx) = e;
    1696    433733486 :   CSELIB_VAL_UID (e->val_rtx) = next_uid++;
    1697    433733486 :   e->addr_list = 0;
    1698    433733486 :   e->locs = 0;
    1699    433733486 :   e->next_containing_mem = 0;
    1700              : 
    1701    433733486 :   scalar_int_mode int_mode;
    1702    131527973 :   if (REG_P (x) && is_int_mode (mode, &int_mode)
    1703    131527973 :       && GET_MODE_SIZE (int_mode) > 1
    1704    125048353 :       && REG_VALUES (REGNO (x)) != NULL
    1705    440817886 :       && (!cselib_current_insn || !DEBUG_INSN_P (cselib_current_insn)))
    1706              :     {
    1707      6926498 :       rtx copy = shallow_copy_rtx (x);
    1708      6926498 :       scalar_int_mode narrow_mode_iter;
    1709     24949385 :       FOR_EACH_MODE_UNTIL (narrow_mode_iter, int_mode)
    1710              :         {
    1711     18022887 :           PUT_MODE_RAW (copy, narrow_mode_iter);
    1712     18022887 :           cselib_val *v = cselib_lookup (copy, narrow_mode_iter, 0, VOIDmode);
    1713     18022887 :           if (v)
    1714              :             {
    1715       759920 :               rtx sub = lowpart_subreg (narrow_mode_iter, e->val_rtx, int_mode);
    1716       759920 :               if (sub)
    1717       759920 :                 new_elt_loc_list (v, sub);
    1718              :             }
    1719              :         }
    1720              :     }
    1721              : 
    1722    433733486 :   if (dump_file && (dump_flags & TDF_CSELIB))
    1723              :     {
    1724            0 :       fprintf (dump_file, "cselib value %u:%u ",
    1725            0 :                CSELIB_VAL_UID (e->val_rtx), hash);
    1726            0 :       if (flag_dump_noaddr || flag_dump_unnumbered)
    1727            0 :         fputs ("# ", dump_file);
    1728              :       else
    1729            0 :         fprintf (dump_file, "%p ", (void*)e);
    1730            0 :       print_rtl_single (dump_file, x);
    1731            0 :       fputc ('\n', dump_file);
    1732              :     }
    1733              : 
    1734    433733486 :   return e;
    1735              : }
    1736              : 
    1737              : /* ADDR_ELT is a value that is used as address.  MEM_ELT is the value that
    1738              :    contains the data at this address.  X is a MEM that represents the
    1739              :    value.  Update the two value structures to represent this situation.  */
    1740              : 
    1741              : static void
    1742     54005294 : add_mem_for_addr (cselib_val *addr_elt, cselib_val *mem_elt, rtx x)
    1743              : {
    1744     54005294 :   addr_elt = canonical_cselib_val (addr_elt);
    1745     54005294 :   mem_elt = canonical_cselib_val (mem_elt);
    1746              : 
    1747              :   /* Avoid duplicates.  */
    1748     54005294 :   addr_space_t as = MEM_ADDR_SPACE (x);
    1749     99350994 :   for (elt_loc_list *l = mem_elt->locs; l; l = l->next)
    1750     45345700 :     if (MEM_P (l->loc)
    1751     15001338 :         && CSELIB_VAL_PTR (XEXP (l->loc, 0)) == addr_elt
    1752     45345700 :         && MEM_ADDR_SPACE (l->loc) == as)
    1753              :       {
    1754            0 :         promote_debug_loc (l);
    1755            0 :         return;
    1756              :       }
    1757              : 
    1758     54005294 :   addr_elt->addr_list = new_elt_list (addr_elt->addr_list, mem_elt);
    1759     54005294 :   new_elt_loc_list (mem_elt,
    1760              :                     replace_equiv_address_nv (x, addr_elt->val_rtx));
    1761     54005294 :   if (mem_elt->next_containing_mem == NULL)
    1762              :     {
    1763     47254614 :       mem_elt->next_containing_mem = first_containing_mem;
    1764     47254614 :       first_containing_mem = mem_elt;
    1765              :     }
    1766              : }
    1767              : 
    1768              : /* Return the canonical value for the address of X, which is a MEM rtx.
    1769              :    If CREATE, make a new value for the address if we haven't seen it
    1770              :    before.  Return null if cselib does not record X or if the address
    1771              :    has no value.  */
    1772              : 
    1773              : static cselib_val *
    1774    261658587 : cselib_lookup_mem_addr (rtx x, int create)
    1775              : {
    1776    261658587 :   machine_mode mode = GET_MODE (x);
    1777              : 
    1778    519406808 :   if (MEM_VOLATILE_P (x) || mode == BLKmode
    1779    257542191 :       || !cselib_record_memory
    1780    472093995 :       || (FLOAT_MODE_P (mode) && flag_float_store))
    1781              :     return NULL;
    1782              : 
    1783    210421208 :   machine_mode addr_mode = GET_MODE (XEXP (x, 0));
    1784    210421208 :   if (addr_mode == VOIDmode)
    1785      1004899 :     addr_mode = Pmode;
    1786              : 
    1787              :   /* Look up the value for the address.  */
    1788    210421208 :   cselib_val *addr = cselib_lookup (XEXP (x, 0), addr_mode, create, mode);
    1789    210421208 :   return addr ? canonical_cselib_val (addr) : NULL;
    1790              : }
    1791              : 
    1792              : /* Return true if V has a memory location at address ADDR in address
    1793              :    space AS.  */
    1794              : 
    1795              : static bool
    1796     73880141 : cselib_has_mem_loc_p (cselib_val *v, cselib_val *addr, addr_space_t as)
    1797              : {
    1798     88602534 :   for (elt_loc_list *l = v->locs; l; l = l->next)
    1799     92683908 :     if (MEM_P (l->loc) && MEM_ADDR_SPACE (l->loc) == as)
    1800              :       {
    1801              :         /* add_mem_for_addr gives each memory location a VALUE address.  */
    1802     80729248 :         rtx loc_addr = XEXP (l->loc, 0);
    1803     80729248 :         gcc_checking_assert (GET_CODE (loc_addr) == VALUE);
    1804     80729248 :         if (canonical_cselib_val (CSELIB_VAL_PTR (loc_addr)) == addr)
    1805              :           return true;
    1806              :       }
    1807              :   return false;
    1808              : }
    1809              : 
    1810              : /* Subroutine of cselib_lookup.  Return a value for X, which is a MEM rtx.
    1811              :    If CREATE, make a new one if we haven't seen it before.  */
    1812              : 
    1813              : static cselib_val *
    1814    246004854 : cselib_lookup_mem (rtx x, int create)
    1815              : {
    1816    246004854 :   machine_mode mode = GET_MODE (x);
    1817    246004854 :   cselib_val **slot;
    1818    246004854 :   cselib_val *addr;
    1819    246004854 :   cselib_val *mem_elt;
    1820              : 
    1821    246004854 :   addr = cselib_lookup_mem_addr (x, create);
    1822    246004854 :   if (! addr)
    1823              :     return 0;
    1824              : 
    1825              :   /* Find a value that describes a value of our mode at that address.  */
    1826    122504630 :   for (elt_list *l = addr->addr_list; l; l = l->next)
    1827     76284939 :     if (GET_MODE (l->elt->val_rtx) == mode
    1828    150139836 :         && cselib_has_mem_loc_p (l->elt, addr, MEM_ADDR_SPACE (x)))
    1829              :       {
    1830     73854879 :         promote_debug_loc (l->elt->locs);
    1831     73854879 :         return l->elt;
    1832              :       }
    1833              : 
    1834     46219691 :   if (! create)
    1835              :     return 0;
    1836              : 
    1837     29021442 :   mem_elt = new_cselib_val (next_uid, mode, x);
    1838     29021442 :   add_mem_for_addr (addr, mem_elt, x);
    1839     29021442 :   slot = cselib_find_slot (mode, x, mem_elt->hash, INSERT, VOIDmode);
    1840     29021442 :   *slot = mem_elt;
    1841     29021442 :   return mem_elt;
    1842              : }
    1843              : 
    1844              : /* Add to VALUES the values that describe the contents of X, which is a MEM
    1845              :    rtx, in other modes of the same size.  Like cselib_lookup_mem, ignore
    1846              :    floating-point modes if -ffloat-store.  */
    1847              : 
    1848              : void
    1849     15653733 : cselib_lookup_mem_other_modes (rtx x, vec<cselib_val *> &values)
    1850              : {
    1851     15653733 :   cselib_val *addr = cselib_lookup_mem_addr (x, 0);
    1852     15653733 :   if (!addr)
    1853              :     return;
    1854              : 
    1855      4561771 :   machine_mode mode = GET_MODE (x);
    1856      5581298 :   for (elt_list *l = addr->addr_list; l; l = l->next)
    1857              :     {
    1858      1019527 :       machine_mode val_mode = GET_MODE (l->elt->val_rtx);
    1859      1019527 :       if (val_mode != mode
    1860       749054 :           && known_eq (GET_MODE_SIZE (val_mode), GET_MODE_SIZE (mode))
    1861        25244 :           && !(FLOAT_MODE_P (val_mode) && flag_float_store)
    1862      1044771 :           && cselib_has_mem_loc_p (l->elt, addr, MEM_ADDR_SPACE (x)))
    1863              :         {
    1864        25238 :           promote_debug_loc (l->elt->locs);
    1865        25238 :           values.safe_push (l->elt);
    1866              :         }
    1867              :     }
    1868              : }
    1869              : 
    1870              : /* Search through the possible substitutions in P.  We prefer a non reg
    1871              :    substitution because this allows us to expand the tree further.  If
    1872              :    we find, just a reg, take the lowest regno.  There may be several
    1873              :    non-reg results, we just take the first one because they will all
    1874              :    expand to the same place.  */
    1875              : 
    1876              : static rtx
    1877     24849179 : expand_loc (struct elt_loc_list *p, struct expand_value_data *evd,
    1878              :             int max_depth)
    1879              : {
    1880     24849179 :   rtx reg_result = NULL;
    1881     24849179 :   unsigned int regno = UINT_MAX;
    1882     24849179 :   struct elt_loc_list *p_in = p;
    1883              : 
    1884     53988456 :   for (; p; p = p->next)
    1885              :     {
    1886              :       /* Return these right away to avoid returning stack pointer based
    1887              :          expressions for frame pointer and vice versa, which is something
    1888              :          that would confuse DSE.  See the comment in cselib_expand_value_rtx_1
    1889              :          for more details.  */
    1890     33061965 :       if (REG_P (p->loc)
    1891     33061965 :           && (REGNO (p->loc) == STACK_POINTER_REGNUM
    1892              :               || REGNO (p->loc) == FRAME_POINTER_REGNUM
    1893              :               || REGNO (p->loc) == HARD_FRAME_POINTER_REGNUM
    1894     26338069 :               || REGNO (p->loc) == cfa_base_preserved_regno))
    1895              :         return p->loc;
    1896              :       /* Avoid infinite recursion trying to expand a reg into a
    1897              :          the same reg.  */
    1898     32545878 :       if ((REG_P (p->loc))
    1899     26332144 :           && (REGNO (p->loc) < regno)
    1900     58570899 :           && !bitmap_bit_p (evd->regs_active, REGNO (p->loc)))
    1901              :         {
    1902      4501284 :           reg_result = p->loc;
    1903      4501284 :           regno = REGNO (p->loc);
    1904              :         }
    1905              :       /* Avoid infinite recursion and do not try to expand the
    1906              :          value.  */
    1907     28044594 :       else if (GET_CODE (p->loc) == VALUE
    1908       361641 :                && CSELIB_VAL_PTR (p->loc)->locs == p_in)
    1909            0 :         continue;
    1910     28044594 :       else if (!REG_P (p->loc))
    1911              :         {
    1912      6213734 :           rtx result, note;
    1913      6213734 :           if (dump_file && (dump_flags & TDF_CSELIB))
    1914              :             {
    1915            0 :               print_inline_rtx (dump_file, p->loc, 0);
    1916            0 :               fprintf (dump_file, "\n");
    1917              :             }
    1918      6213734 :           if (GET_CODE (p->loc) == LO_SUM
    1919            0 :               && GET_CODE (XEXP (p->loc, 1)) == SYMBOL_REF
    1920            0 :               && p->setting_insn
    1921            0 :               && (note = find_reg_note (p->setting_insn, REG_EQUAL, NULL_RTX))
    1922      6213734 :               && XEXP (note, 0) == XEXP (p->loc, 1))
    1923              :             return XEXP (p->loc, 1);
    1924      6213734 :           result = cselib_expand_value_rtx_1 (p->loc, evd, max_depth - 1);
    1925      6213734 :           if (result)
    1926              :             return result;
    1927              :         }
    1928              : 
    1929              :     }
    1930              : 
    1931     20926491 :   if (regno != UINT_MAX)
    1932              :     {
    1933      3725327 :       rtx result;
    1934      3725327 :       if (dump_file && (dump_flags & TDF_CSELIB))
    1935            0 :         fprintf (dump_file, "r%d\n", regno);
    1936              : 
    1937      3725327 :       result = cselib_expand_value_rtx_1 (reg_result, evd, max_depth - 1);
    1938      3725327 :       if (result)
    1939              :         return result;
    1940              :     }
    1941              : 
    1942     18059644 :   if (dump_file && (dump_flags & TDF_CSELIB))
    1943              :     {
    1944            0 :       if (reg_result)
    1945              :         {
    1946            0 :           print_inline_rtx (dump_file, reg_result, 0);
    1947            0 :           fprintf (dump_file, "\n");
    1948              :         }
    1949              :       else
    1950            0 :         fprintf (dump_file, "NULL\n");
    1951              :     }
    1952              :   return reg_result;
    1953              : }
    1954              : 
    1955              : 
    1956              : /* Forward substitute and expand an expression out to its roots.
    1957              :    This is the opposite of common subexpression.  Because local value
    1958              :    numbering is such a weak optimization, the expanded expression is
    1959              :    pretty much unique (not from a pointer equals point of view but
    1960              :    from a tree shape point of view.
    1961              : 
    1962              :    This function returns NULL if the expansion fails.  The expansion
    1963              :    will fail if there is no value number for one of the operands or if
    1964              :    one of the operands has been overwritten between the current insn
    1965              :    and the beginning of the basic block.  For instance x has no
    1966              :    expansion in:
    1967              : 
    1968              :    r1 <- r1 + 3
    1969              :    x <- r1 + 8
    1970              : 
    1971              :    REGS_ACTIVE is a scratch bitmap that should be clear when passing in.
    1972              :    It is clear on return.  */
    1973              : 
    1974              : rtx
    1975     38238354 : cselib_expand_value_rtx (rtx orig, bitmap regs_active, int max_depth)
    1976              : {
    1977     38238354 :   struct expand_value_data evd;
    1978              : 
    1979     38238354 :   evd.regs_active = regs_active;
    1980     38238354 :   evd.callback = NULL;
    1981     38238354 :   evd.callback_arg = NULL;
    1982     38238354 :   evd.dummy = false;
    1983              : 
    1984     38238354 :   return cselib_expand_value_rtx_1 (orig, &evd, max_depth);
    1985              : }
    1986              : 
    1987              : /* Same as cselib_expand_value_rtx, but using a callback to try to
    1988              :    resolve some expressions.  The CB function should return ORIG if it
    1989              :    can't or does not want to deal with a certain RTX.  Any other
    1990              :    return value, including NULL, will be used as the expansion for
    1991              :    VALUE, without any further changes.  */
    1992              : 
    1993              : rtx
    1994     96896002 : cselib_expand_value_rtx_cb (rtx orig, bitmap regs_active, int max_depth,
    1995              :                             cselib_expand_callback cb, void *data)
    1996              : {
    1997     96896002 :   struct expand_value_data evd;
    1998              : 
    1999     96896002 :   evd.regs_active = regs_active;
    2000     96896002 :   evd.callback = cb;
    2001     96896002 :   evd.callback_arg = data;
    2002     96896002 :   evd.dummy = false;
    2003              : 
    2004     96896002 :   return cselib_expand_value_rtx_1 (orig, &evd, max_depth);
    2005              : }
    2006              : 
    2007              : /* Similar to cselib_expand_value_rtx_cb, but no rtxs are actually copied
    2008              :    or simplified.  Useful to find out whether cselib_expand_value_rtx_cb
    2009              :    would return NULL or non-NULL, without allocating new rtx.  */
    2010              : 
    2011              : bool
    2012            0 : cselib_dummy_expand_value_rtx_cb (rtx orig, bitmap regs_active, int max_depth,
    2013              :                                   cselib_expand_callback cb, void *data)
    2014              : {
    2015            0 :   struct expand_value_data evd;
    2016              : 
    2017            0 :   evd.regs_active = regs_active;
    2018            0 :   evd.callback = cb;
    2019            0 :   evd.callback_arg = data;
    2020            0 :   evd.dummy = true;
    2021              : 
    2022            0 :   return cselib_expand_value_rtx_1 (orig, &evd, max_depth) != NULL;
    2023              : }
    2024              : 
    2025              : /* Internal implementation of cselib_expand_value_rtx and
    2026              :    cselib_expand_value_rtx_cb.  */
    2027              : 
    2028              : static rtx
    2029    218540633 : cselib_expand_value_rtx_1 (rtx orig, struct expand_value_data *evd,
    2030              :                            int max_depth)
    2031              : {
    2032    218540633 :   rtx copy, scopy;
    2033    218540633 :   int i, j;
    2034    218540633 :   RTX_CODE code;
    2035    218540633 :   const char *format_ptr;
    2036    218540633 :   machine_mode mode;
    2037              : 
    2038    218540633 :   code = GET_CODE (orig);
    2039              : 
    2040              :   /* For the context of dse, if we end up expand into a huge tree, we
    2041              :      will not have a useful address, so we might as well just give up
    2042              :      quickly.  */
    2043    218540633 :   if (max_depth <= 0)
    2044              :     return NULL;
    2045              : 
    2046    215819234 :   switch (code)
    2047              :     {
    2048     52304721 :     case REG:
    2049     52304721 :       {
    2050     52304721 :         struct elt_list *l = REG_VALUES (REGNO (orig));
    2051              : 
    2052     52304721 :         if (l && l->elt == NULL)
    2053     26113910 :           l = l->next;
    2054     52319201 :         for (; l; l = l->next)
    2055     39217913 :           if (GET_MODE (l->elt->val_rtx) == GET_MODE (orig))
    2056              :             {
    2057     39203433 :               rtx result;
    2058     39203433 :               unsigned regno = REGNO (orig);
    2059              : 
    2060              :               /* The only thing that we are not willing to do (this
    2061              :                  is requirement of dse and if others potential uses
    2062              :                  need this function we should add a parm to control
    2063              :                  it) is that we will not substitute the
    2064              :                  STACK_POINTER_REGNUM, FRAME_POINTER or the
    2065              :                  HARD_FRAME_POINTER.
    2066              : 
    2067              :                  These expansions confuses the code that notices that
    2068              :                  stores into the frame go dead at the end of the
    2069              :                  function and that the frame is not effected by calls
    2070              :                  to subroutines.  If you allow the
    2071              :                  STACK_POINTER_REGNUM substitution, then dse will
    2072              :                  think that parameter pushing also goes dead which is
    2073              :                  wrong.  If you allow the FRAME_POINTER or the
    2074              :                  HARD_FRAME_POINTER then you lose the opportunity to
    2075              :                  make the frame assumptions.  */
    2076     39203433 :               if (regno == STACK_POINTER_REGNUM
    2077     39203433 :                   || regno == FRAME_POINTER_REGNUM
    2078     21185545 :                   || regno == HARD_FRAME_POINTER_REGNUM
    2079     20649740 :                   || regno == cfa_base_preserved_regno)
    2080              :                 return orig;
    2081              : 
    2082     20335928 :               bitmap_set_bit (evd->regs_active, regno);
    2083              : 
    2084     20335928 :               if (dump_file && (dump_flags & TDF_CSELIB))
    2085            0 :                 fprintf (dump_file, "expanding: r%d into: ", regno);
    2086              : 
    2087     20335928 :               result = expand_loc (l->elt->locs, evd, max_depth);
    2088     20335928 :               bitmap_clear_bit (evd->regs_active, regno);
    2089              : 
    2090     20335928 :               if (result)
    2091              :                 return result;
    2092              :               else
    2093     16263561 :                 return orig;
    2094              :             }
    2095              :         return orig;
    2096              :       }
    2097              : 
    2098              :     CASE_CONST_ANY:
    2099              :     case SYMBOL_REF:
    2100              :     case CODE_LABEL:
    2101              :     case PC:
    2102              :     case SCRATCH:
    2103              :       /* SCRATCH must be shared because they represent distinct values.  */
    2104              :       return orig;
    2105            0 :     case CLOBBER:
    2106            0 :       if (REG_P (XEXP (orig, 0)) && HARD_REGISTER_NUM_P (REGNO (XEXP (orig, 0))))
    2107              :         return orig;
    2108              :       break;
    2109              : 
    2110       274455 :     case CONST:
    2111       274455 :       if (shared_const_p (orig))
    2112              :         return orig;
    2113              :       break;
    2114              : 
    2115       953765 :     case SUBREG:
    2116       953765 :       {
    2117       953765 :         rtx subreg;
    2118              : 
    2119       953765 :         if (evd->callback)
    2120              :           {
    2121       857870 :             subreg = evd->callback (orig, evd->regs_active, max_depth,
    2122              :                                     evd->callback_arg);
    2123       857870 :             if (subreg != orig)
    2124              :               return subreg;
    2125              :           }
    2126              : 
    2127        95895 :         subreg = cselib_expand_value_rtx_1 (SUBREG_REG (orig), evd,
    2128              :                                             max_depth - 1);
    2129        95895 :         if (!subreg)
    2130              :           return NULL;
    2131       104252 :         scopy = simplify_gen_subreg (GET_MODE (orig), subreg,
    2132        52126 :                                      GET_MODE (SUBREG_REG (orig)),
    2133        52126 :                                      SUBREG_BYTE (orig));
    2134        52126 :         if (scopy == NULL
    2135        51725 :             || (GET_CODE (scopy) == SUBREG
    2136        49016 :                 && !REG_P (SUBREG_REG (scopy))
    2137         6222 :                 && !MEM_P (SUBREG_REG (scopy))))
    2138         6623 :           return NULL;
    2139              : 
    2140              :         return scopy;
    2141              :       }
    2142              : 
    2143     77256520 :     case VALUE:
    2144     77256520 :       {
    2145     77256520 :         rtx result;
    2146              : 
    2147     77256520 :         if (dump_file && (dump_flags & TDF_CSELIB))
    2148              :           {
    2149            0 :             fputs ("\nexpanding ", dump_file);
    2150            0 :             print_rtl_single (dump_file, orig);
    2151            0 :             fputs (" into...", dump_file);
    2152              :           }
    2153              : 
    2154     77256520 :         if (evd->callback)
    2155              :           {
    2156     72743269 :             result = evd->callback (orig, evd->regs_active, max_depth,
    2157              :                                     evd->callback_arg);
    2158              : 
    2159     72743269 :             if (result != orig)
    2160              :               return result;
    2161              :           }
    2162              : 
    2163      4513251 :         result = expand_loc (CSELIB_VAL_PTR (orig)->locs, evd, max_depth);
    2164      4513251 :         return result;
    2165              :       }
    2166              : 
    2167      6612029 :     case DEBUG_EXPR:
    2168      6612029 :       if (evd->callback)
    2169      6612029 :         return evd->callback (orig, evd->regs_active, max_depth,
    2170      6612029 :                               evd->callback_arg);
    2171              :       return orig;
    2172              : 
    2173              :     default:
    2174              :       break;
    2175              :     }
    2176              : 
    2177              :   /* Copy the various flags, fields, and other information.  We assume
    2178              :      that all fields need copying, and then clear the fields that should
    2179              :      not be copied.  That is the sensible default behavior, and forces
    2180              :      us to explicitly document why we are *not* copying a flag.  */
    2181     46309028 :   if (evd->dummy)
    2182              :     copy = NULL;
    2183              :   else
    2184     46309028 :     copy = shallow_copy_rtx (orig);
    2185              : 
    2186     46309028 :   format_ptr = GET_RTX_FORMAT (code);
    2187              : 
    2188    121694018 :   for (i = 0; i < GET_RTX_LENGTH (code); i++)
    2189     79753625 :     switch (*format_ptr++)
    2190              :       {
    2191     72861442 :       case 'e':
    2192     72861442 :         if (XEXP (orig, i) != NULL)
    2193              :           {
    2194     72861442 :             rtx result = cselib_expand_value_rtx_1 (XEXP (orig, i), evd,
    2195              :                                                     max_depth - 1);
    2196     72861442 :             if (!result)
    2197              :               return NULL;
    2198     68528227 :             if (copy)
    2199     68528227 :               XEXP (copy, i) = result;
    2200              :           }
    2201              :         break;
    2202              : 
    2203       305901 :       case 'E':
    2204       305901 :       case 'V':
    2205       305901 :         if (XVEC (orig, i) != NULL)
    2206              :           {
    2207       305901 :             if (copy)
    2208       305901 :               XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
    2209       780360 :             for (j = 0; j < XVECLEN (orig, i); j++)
    2210              :               {
    2211       509879 :                 rtx result = cselib_expand_value_rtx_1 (XVECEXP (orig, i, j),
    2212              :                                                         evd, max_depth - 1);
    2213       509879 :                 if (!result)
    2214              :                   return NULL;
    2215       474459 :                 if (copy)
    2216       474459 :                   XVECEXP (copy, i, j) = result;
    2217              :               }
    2218              :           }
    2219              :         break;
    2220              : 
    2221              :       case 't':
    2222              :       case 'w':
    2223              :       case 'i':
    2224              :       case 'L':
    2225              :       case 's':
    2226              :       case 'S':
    2227              :       case 'T':
    2228              :       case 'u':
    2229              :       case 'B':
    2230              :       case '0':
    2231              :         /* These are left unchanged.  */
    2232              :         break;
    2233              : 
    2234            0 :       default:
    2235            0 :         gcc_unreachable ();
    2236              :       }
    2237              : 
    2238     41940393 :   if (evd->dummy)
    2239              :     return orig;
    2240              : 
    2241     41940393 :   mode = GET_MODE (copy);
    2242              :   /* If an operand has been simplified into CONST_INT, which doesn't
    2243              :      have a mode and the mode isn't derivable from whole rtx's mode,
    2244              :      try simplify_*_operation first with mode from original's operand
    2245              :      and as a fallback wrap CONST_INT into gen_rtx_CONST.  */
    2246     41940393 :   scopy = copy;
    2247     41940393 :   switch (GET_RTX_CLASS (code))
    2248              :     {
    2249       657480 :     case RTX_UNARY:
    2250       657480 :       if (CONST_INT_P (XEXP (copy, 0))
    2251        51116 :           && GET_MODE (XEXP (orig, 0)) != VOIDmode)
    2252              :         {
    2253        51108 :           scopy = simplify_unary_operation (code, mode, XEXP (copy, 0),
    2254              :                                             GET_MODE (XEXP (orig, 0)));
    2255        51108 :           if (scopy)
    2256              :             return scopy;
    2257              :         }
    2258              :       break;
    2259              :     case RTX_COMM_ARITH:
    2260              :     case RTX_BIN_ARITH:
    2261              :       /* These expressions can derive operand modes from the whole rtx's mode.  */
    2262              :       break;
    2263        79103 :     case RTX_TERNARY:
    2264        79103 :     case RTX_BITFIELD_OPS:
    2265        79103 :       if (CONST_INT_P (XEXP (copy, 0))
    2266           78 :           && GET_MODE (XEXP (orig, 0)) != VOIDmode)
    2267              :         {
    2268            1 :           scopy = simplify_ternary_operation (code, mode,
    2269              :                                               GET_MODE (XEXP (orig, 0)),
    2270              :                                               XEXP (copy, 0), XEXP (copy, 1),
    2271              :                                               XEXP (copy, 2));
    2272            1 :           if (scopy)
    2273              :             return scopy;
    2274              :         }
    2275              :       break;
    2276       197505 :     case RTX_COMPARE:
    2277       197505 :     case RTX_COMM_COMPARE:
    2278       197505 :       if (CONST_INT_P (XEXP (copy, 0))
    2279          546 :           && GET_MODE (XEXP (copy, 1)) == VOIDmode
    2280          187 :           && (GET_MODE (XEXP (orig, 0)) != VOIDmode
    2281            6 :               || GET_MODE (XEXP (orig, 1)) != VOIDmode))
    2282              :         {
    2283          187 :           scopy = simplify_relational_operation (code, mode,
    2284              :                                                  (GET_MODE (XEXP (orig, 0))
    2285              :                                                   != VOIDmode)
    2286              :                                                  ? GET_MODE (XEXP (orig, 0))
    2287            6 :                                                  : GET_MODE (XEXP (orig, 1)),
    2288              :                                                  XEXP (copy, 0),
    2289              :                                                  XEXP (copy, 1));
    2290          187 :           if (scopy)
    2291              :             return scopy;
    2292              :         }
    2293              :       break;
    2294              :     default:
    2295              :       break;
    2296              :     }
    2297     41889098 :   scopy = simplify_rtx (copy);
    2298     41889098 :   if (scopy)
    2299      4815240 :     return scopy;
    2300              :   return copy;
    2301              : }
    2302              : 
    2303              : /* Walk rtx X and replace all occurrences of REG and MEM subexpressions
    2304              :    with VALUE expressions.  This way, it becomes independent of changes
    2305              :    to registers and memory.
    2306              :    X isn't actually modified; if modifications are needed, new rtl is
    2307              :    allocated.  However, the return value can share rtl with X.
    2308              :    If X is within a MEM, MEMMODE must be the mode of the MEM.  */
    2309              : 
    2310              : rtx
    2311    613264408 : cselib_subst_to_values (rtx x, machine_mode memmode)
    2312              : {
    2313    621076259 :   enum rtx_code code = GET_CODE (x);
    2314    621076259 :   const char *fmt = GET_RTX_FORMAT (code);
    2315    621076259 :   cselib_val *e;
    2316    621076259 :   struct elt_list *l;
    2317    621076259 :   rtx copy = x;
    2318    621076259 :   int i;
    2319    621076259 :   poly_int64 offset;
    2320              : 
    2321    621076259 :   switch (code)
    2322              :     {
    2323    242380457 :     case REG:
    2324    242380457 :       l = REG_VALUES (REGNO (x));
    2325    242380457 :       if (l && l->elt == NULL)
    2326    138678023 :         l = l->next;
    2327    244865773 :       for (; l; l = l->next)
    2328    244865773 :         if (GET_MODE (l->elt->val_rtx) == GET_MODE (x))
    2329              :           return l->elt->val_rtx;
    2330              : 
    2331            0 :       gcc_unreachable ();
    2332              : 
    2333      6351358 :     case MEM:
    2334      6351358 :       e = cselib_lookup_mem (x, 0);
    2335              :       /* This used to happen for autoincrements, but we deal with them
    2336              :          properly now.  Remove the if stmt for the next release.  */
    2337      6351358 :       if (! e)
    2338              :         {
    2339              :           /* Assign a value that doesn't match any other.  */
    2340            0 :           e = new_cselib_val (next_uid, GET_MODE (x), x);
    2341              :         }
    2342      6351358 :       return e->val_rtx;
    2343              : 
    2344       681598 :     case ENTRY_VALUE:
    2345       681598 :       e = cselib_lookup (x, GET_MODE (x), 0, memmode);
    2346       681598 :       if (! e)
    2347              :         break;
    2348          925 :       return e->val_rtx;
    2349              : 
    2350              :     CASE_CONST_ANY:
    2351              :       return x;
    2352              : 
    2353      6455659 :     case PRE_DEC:
    2354      6455659 :     case PRE_INC:
    2355      6455659 :       gcc_assert (memmode != VOIDmode);
    2356     12911318 :       offset = GET_MODE_SIZE (memmode);
    2357      6455659 :       if (code == PRE_DEC)
    2358      6455659 :         offset = -offset;
    2359      6455659 :       return cselib_subst_to_values (plus_constant (GET_MODE (x),
    2360              :                                                     XEXP (x, 0), offset),
    2361      6455659 :                                      memmode);
    2362              : 
    2363       391405 :     case PRE_MODIFY:
    2364       391405 :       gcc_assert (memmode != VOIDmode);
    2365       391405 :       return cselib_subst_to_values (XEXP (x, 1), memmode);
    2366              : 
    2367       964787 :     case POST_DEC:
    2368       964787 :     case POST_INC:
    2369       964787 :     case POST_MODIFY:
    2370       964787 :       gcc_assert (memmode != VOIDmode);
    2371       964787 :       return cselib_subst_to_values (XEXP (x, 0), memmode);
    2372              : 
    2373    119235102 :     case PLUS:
    2374    154945912 :       if (GET_MODE (x) == Pmode && CONST_INT_P (XEXP (x, 1)))
    2375              :         {
    2376     96895256 :           rtx t = cselib_subst_to_values (XEXP (x, 0), memmode);
    2377     96895256 :           if (GET_CODE (t) == VALUE)
    2378              :             {
    2379     91054141 :               if (SP_DERIVED_VALUE_P (t) && XEXP (x, 1) == const0_rtx)
    2380              :                 return t;
    2381     91054141 :               for (struct elt_loc_list *l = CSELIB_VAL_PTR (t)->locs;
    2382    191925585 :                    l; l = l->next)
    2383    122573218 :                 if (GET_CODE (l->loc) == PLUS
    2384     25081623 :                     && GET_CODE (XEXP (l->loc, 0)) == VALUE
    2385     24938696 :                     && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
    2386    144278197 :                     && CONST_INT_P (XEXP (l->loc, 1)))
    2387     35609129 :                   return plus_constant (Pmode, l->loc, INTVAL (XEXP (x, 1)));
    2388              :             }
    2389     75193482 :           if (t != XEXP (x, 0))
    2390              :             {
    2391     70701032 :               copy = shallow_copy_rtx (x);
    2392     70701032 :               XEXP (copy, 0) = t;
    2393              :             }
    2394              :           return copy;
    2395              :         }
    2396              : 
    2397              :     default:
    2398              :       break;
    2399              :     }
    2400              : 
    2401    498093601 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    2402              :     {
    2403    325287993 :       if (fmt[i] == 'e')
    2404              :         {
    2405    239596947 :           rtx t = cselib_subst_to_values (XEXP (x, i), memmode);
    2406              : 
    2407    239596947 :           if (t != XEXP (x, i))
    2408              :             {
    2409    175306784 :               if (x == copy)
    2410    124479500 :                 copy = shallow_copy_rtx (x);
    2411    175306784 :               XEXP (copy, i) = t;
    2412              :             }
    2413              :         }
    2414     85691046 :       else if (fmt[i] == 'E')
    2415              :         {
    2416              :           int j;
    2417              : 
    2418     20279368 :           for (j = 0; j < XVECLEN (x, i); j++)
    2419              :             {
    2420     14412380 :               rtx t = cselib_subst_to_values (XVECEXP (x, i, j), memmode);
    2421              : 
    2422     14412380 :               if (t != XVECEXP (x, i, j))
    2423              :                 {
    2424      2693776 :                   if (XVEC (x, i) == XVEC (copy, i))
    2425              :                     {
    2426      2019443 :                       if (x == copy)
    2427      2019443 :                         copy = shallow_copy_rtx (x);
    2428      2019443 :                       XVEC (copy, i) = shallow_copy_rtvec (XVEC (x, i));
    2429              :                     }
    2430      2693776 :                   XVECEXP (copy, i, j) = t;
    2431              :                 }
    2432              :             }
    2433              :         }
    2434              :     }
    2435              : 
    2436              :   return copy;
    2437              : }
    2438              : 
    2439              : /* Wrapper for cselib_subst_to_values, that indicates X is in INSN.  */
    2440              : 
    2441              : rtx
    2442         1463 : cselib_subst_to_values_from_insn (rtx x, machine_mode memmode, rtx_insn *insn)
    2443              : {
    2444         1463 :   rtx ret;
    2445         1463 :   gcc_assert (!cselib_current_insn);
    2446         1463 :   cselib_current_insn = insn;
    2447         1463 :   ret = cselib_subst_to_values (x, memmode);
    2448         1463 :   cselib_current_insn = NULL;
    2449         1463 :   return ret;
    2450              : }
    2451              : 
    2452              : /* Look up the rtl expression X in our tables and return the value it
    2453              :    has.  If CREATE is zero, we return NULL if we don't know the value.
    2454              :    Otherwise, we create a new one if possible, using mode MODE if X
    2455              :    doesn't have a mode (i.e. because it's a constant).  When X is part
    2456              :    of an address, MEMMODE should be the mode of the enclosing MEM if
    2457              :    we're tracking autoinc expressions.  */
    2458              : 
    2459              : static cselib_val *
    2460   2530018142 : cselib_lookup_1 (rtx x, machine_mode mode,
    2461              :                  int create, machine_mode memmode)
    2462              : {
    2463   2530018142 :   cselib_val **slot;
    2464   2530018142 :   cselib_val *e;
    2465              : 
    2466   2530018142 :   if (GET_MODE (x) != VOIDmode)
    2467   2442337146 :     mode = GET_MODE (x);
    2468              : 
    2469   2530018142 :   if (GET_CODE (x) == VALUE)
    2470     67350621 :     return CSELIB_VAL_PTR (x);
    2471              : 
    2472   2462667521 :   if (REG_P (x))
    2473              :     {
    2474   1585982916 :       struct elt_list *l;
    2475   1585982916 :       unsigned int i = REGNO (x);
    2476              : 
    2477   1585982916 :       l = REG_VALUES (i);
    2478   1585982916 :       if (l && l->elt == NULL)
    2479    664462146 :         l = l->next;
    2480   1607440139 :       for (; l; l = l->next)
    2481   1226933365 :         if (mode == GET_MODE (l->elt->val_rtx))
    2482              :           {
    2483   1205476142 :             promote_debug_loc (l->elt->locs);
    2484   1205476142 :             return l->elt;
    2485              :           }
    2486              : 
    2487    380506774 :       if (! create)
    2488              :         return 0;
    2489              : 
    2490    142353682 :       if (i < FIRST_PSEUDO_REGISTER)
    2491              :         {
    2492     80643501 :           unsigned int n = hard_regno_nregs (i, mode);
    2493              : 
    2494     80643501 :           if (n > max_value_regs)
    2495     27745400 :             max_value_regs = n;
    2496              :         }
    2497              : 
    2498    142353682 :       e = new_cselib_val (next_uid, GET_MODE (x), x);
    2499    167031133 :       if (GET_MODE (x) == Pmode && x == stack_pointer_rtx)
    2500     12333243 :         SP_DERIVED_VALUE_P (e->val_rtx) = 1;
    2501    142353682 :       new_elt_loc_list (e, x);
    2502              : 
    2503    142353682 :       scalar_int_mode int_mode;
    2504    142353682 :       if (REG_VALUES (i) == 0)
    2505              :         {
    2506              :           /* Maintain the invariant that the first entry of
    2507              :              REG_VALUES, if present, must be the value used to set the
    2508              :              register, or NULL.  */
    2509    131962017 :           used_regs[n_used_regs++] = i;
    2510    131962017 :           REG_VALUES (i) = new_elt_list (REG_VALUES (i), NULL);
    2511              :         }
    2512     10391665 :       else if (cselib_preserve_constants
    2513     10391665 :                && is_int_mode (mode, &int_mode))
    2514              :         {
    2515              :           /* During var-tracking, try harder to find equivalences
    2516              :              for SUBREGs.  If a setter sets say a DImode register
    2517              :              and user uses that register only in SImode, add a lowpart
    2518              :              subreg location.  */
    2519      1617676 :           struct elt_list *lwider = NULL;
    2520      1617676 :           scalar_int_mode lmode;
    2521      1617676 :           l = REG_VALUES (i);
    2522      1617676 :           if (l && l->elt == NULL)
    2523      1047864 :             l = l->next;
    2524      2425323 :           for (; l; l = l->next)
    2525       807647 :             if (is_int_mode (GET_MODE (l->elt->val_rtx), &lmode)
    2526      1153018 :                 && GET_MODE_SIZE (lmode) > GET_MODE_SIZE (int_mode)
    2527       282618 :                 && (lwider == NULL
    2528         1776 :                     || partial_subreg_p (lmode,
    2529         1776 :                                          GET_MODE (lwider->elt->val_rtx))))
    2530              :               {
    2531       282512 :                 struct elt_loc_list *el;
    2532       301409 :                 if (i < FIRST_PSEUDO_REGISTER
    2533       282512 :                     && hard_regno_nregs (i, lmode) != 1)
    2534        18897 :                   continue;
    2535       517500 :                 for (el = l->elt->locs; el; el = el->next)
    2536       486087 :                   if (!REG_P (el->loc))
    2537              :                     break;
    2538       263615 :                 if (el)
    2539       807647 :                   lwider = l;
    2540              :               }
    2541      1617676 :           if (lwider)
    2542              :             {
    2543       461064 :               rtx sub = lowpart_subreg (int_mode, lwider->elt->val_rtx,
    2544       230532 :                                         GET_MODE (lwider->elt->val_rtx));
    2545       230532 :               if (sub)
    2546       230532 :                 new_elt_loc_list (e, sub);
    2547              :             }
    2548              :         }
    2549    142353682 :       REG_VALUES (i)->next = new_elt_list (REG_VALUES (i)->next, e);
    2550    142353682 :       slot = cselib_find_slot (mode, x, e->hash, INSERT, memmode);
    2551    142353682 :       *slot = e;
    2552    142353682 :       return e;
    2553              :     }
    2554              : 
    2555    876684605 :   if (MEM_P (x))
    2556    239653496 :     return cselib_lookup_mem (x, create);
    2557              : 
    2558    637031109 :   hashval_t hashval = cselib_hash_rtx (x, create, memmode);
    2559              :   /* Can't even create if hashing is not possible.  */
    2560    637031109 :   if (! hashval)
    2561              :     return 0;
    2562              : 
    2563    820560223 :   slot = cselib_find_slot (mode, x, hashval,
    2564              :                            create ? INSERT : NO_INSERT, memmode);
    2565    579930494 :   if (slot == 0)
    2566              :     return 0;
    2567              : 
    2568    456602268 :   e = (cselib_val *) *slot;
    2569    456602268 :   if (e)
    2570              :     return e;
    2571              : 
    2572    262358362 :   e = new_cselib_val (hashval, mode, x);
    2573              : 
    2574              :   /* We have to fill the slot before calling cselib_subst_to_values:
    2575              :      the hash table is inconsistent until we do so, and
    2576              :      cselib_subst_to_values will need to do lookups.  */
    2577    262358362 :   *slot = e;
    2578    262358362 :   rtx v = cselib_subst_to_values (x, memmode);
    2579              : 
    2580              :   /* If cselib_preserve_constants, we might get a SP_DERIVED_VALUE_P
    2581              :      VALUE that isn't in the hash tables anymore.  */
    2582    262358362 :   if (GET_CODE (v) == VALUE && SP_DERIVED_VALUE_P (v) && PRESERVED_VALUE_P (v))
    2583            0 :     PRESERVED_VALUE_P (e->val_rtx) = 1;
    2584              : 
    2585    262358362 :   new_elt_loc_list (e, v);
    2586    262358362 :   return e;
    2587              : }
    2588              : 
    2589              : /* Wrapper for cselib_lookup, that indicates X is in INSN.  */
    2590              : 
    2591              : cselib_val *
    2592      6358521 : cselib_lookup_from_insn (rtx x, machine_mode mode,
    2593              :                          int create, machine_mode memmode, rtx_insn *insn)
    2594              : {
    2595      6358521 :   cselib_val *ret;
    2596              : 
    2597      6358521 :   gcc_assert (!cselib_current_insn);
    2598      6358521 :   cselib_current_insn = insn;
    2599              : 
    2600      6358521 :   ret = cselib_lookup (x, mode, create, memmode);
    2601              : 
    2602      6358521 :   cselib_current_insn = NULL;
    2603              : 
    2604      6358521 :   return ret;
    2605              : }
    2606              : 
    2607              : /* Wrapper for cselib_lookup_1, that logs the lookup result and
    2608              :    maintains invariants related with debug insns.  */
    2609              : 
    2610              : cselib_val *
    2611   2528982838 : cselib_lookup (rtx x, machine_mode mode,
    2612              :                int create, machine_mode memmode)
    2613              : {
    2614   2528982838 :   cselib_val *ret = cselib_lookup_1 (x, mode, create, memmode);
    2615              : 
    2616              :   /* ??? Should we return NULL if we're not to create an entry, the
    2617              :      found loc is a debug loc and cselib_current_insn is not DEBUG?
    2618              :      If so, we should also avoid converting val to non-DEBUG; probably
    2619              :      easiest setting cselib_current_insn to NULL before the call
    2620              :      above.  */
    2621              : 
    2622   2528982838 :   if (dump_file && (dump_flags & TDF_CSELIB))
    2623              :     {
    2624            0 :       fputs ("cselib lookup ", dump_file);
    2625            0 :       print_inline_rtx (dump_file, x, 2);
    2626            0 :       fprintf (dump_file, " => %u:%u\n",
    2627            0 :                ret ? CSELIB_VAL_UID (ret->val_rtx) : 0,
    2628              :                ret ? ret->hash : 0);
    2629              :     }
    2630              : 
    2631   2528982838 :   return ret;
    2632              : }
    2633              : 
    2634              : /* Invalidate the value at *L, which is part of REG_VALUES (REGNO).  */
    2635              : 
    2636              : static void
    2637    191801159 : cselib_invalidate_regno_val (unsigned int regno, struct elt_list **l)
    2638              : {
    2639    191801159 :   cselib_val *v = (*l)->elt;
    2640    191801159 :   if (*l == REG_VALUES (regno))
    2641              :     {
    2642              :       /* Maintain the invariant that the first entry of
    2643              :          REG_VALUES, if present, must be the value used to set
    2644              :          the register, or NULL.  This is also nice because
    2645              :          then we won't push the same regno onto user_regs
    2646              :          multiple times.  */
    2647    147471633 :       (*l)->elt = NULL;
    2648    147471633 :       l = &(*l)->next;
    2649              :     }
    2650              :   else
    2651     44329526 :     unchain_one_elt_list (l);
    2652              : 
    2653    191801159 :   v = canonical_cselib_val (v);
    2654              : 
    2655    191801159 :   bool had_locs = v->locs != NULL;
    2656    191801159 :   rtx_insn *setting_insn = v->locs ? v->locs->setting_insn : NULL;
    2657              : 
    2658              :   /* Now, we clear the mapping from value to reg.  It must exist, so
    2659              :      this code will crash intentionally if it doesn't.  */
    2660    191801159 :   for (elt_loc_list **p = &v->locs; ; p = &(*p)->next)
    2661              :     {
    2662    220758652 :       rtx x = (*p)->loc;
    2663              : 
    2664    220758652 :       if (REG_P (x) && REGNO (x) == regno)
    2665              :         {
    2666    191801159 :           unchain_one_elt_loc_list (p);
    2667    191801159 :           break;
    2668              :         }
    2669     28957493 :     }
    2670              : 
    2671    191801159 :   if (had_locs && cselib_useless_value_p (v))
    2672              :     {
    2673     22439092 :       if (setting_insn && DEBUG_INSN_P (setting_insn))
    2674            0 :         n_useless_debug_values++;
    2675              :       else
    2676     22439092 :         n_useless_values++;
    2677              :     }
    2678    191801159 : }
    2679              : 
    2680              : /* Invalidate any entries in reg_values that overlap REGNO.  This is called
    2681              :    if REGNO is changing.  MODE is the mode of the assignment to REGNO, which
    2682              :    is used to determine how many hard registers are being changed.  If MODE
    2683              :    is VOIDmode, then only REGNO is being changed; this is used when
    2684              :    invalidating call clobbered registers across a call.  */
    2685              : 
    2686              : static void
    2687    832224314 : cselib_invalidate_regno (unsigned int regno, machine_mode mode)
    2688              : {
    2689    832224314 :   unsigned int endregno;
    2690    832224314 :   unsigned int i;
    2691              : 
    2692              :   /* If we see pseudos after reload, something is _wrong_.  */
    2693    832224314 :   gcc_assert (!reload_completed || regno < FIRST_PSEUDO_REGISTER
    2694              :               || reg_renumber[regno] < 0);
    2695              : 
    2696              :   /* Determine the range of registers that must be invalidated.  For
    2697              :      pseudos, only REGNO is affected.  For hard regs, we must take MODE
    2698              :      into account, and we must also invalidate lower register numbers
    2699              :      if they contain values that overlap REGNO.  */
    2700    230570406 :   if (regno < FIRST_PSEUDO_REGISTER)
    2701              :     {
    2702    723517405 :       gcc_assert (mode != VOIDmode);
    2703              : 
    2704    723517405 :       if (regno < max_value_regs)
    2705              :         i = 0;
    2706              :       else
    2707    680518112 :         i = regno - max_value_regs;
    2708              : 
    2709    723517405 :       endregno = end_hard_regno (mode, regno);
    2710              :     }
    2711              :   else
    2712              :     {
    2713    108706909 :       i = regno;
    2714    108706909 :       endregno = regno + 1;
    2715              :     }
    2716              : 
    2717   2306244069 :   for (; i < endregno; i++)
    2718              :     {
    2719   1474019755 :       struct elt_list **l = &REG_VALUES (i);
    2720              : 
    2721              :       /* Go through all known values for this reg; if it overlaps the range
    2722              :          we're invalidating, remove the value.  */
    2723   1873862964 :       while (*l)
    2724              :         {
    2725    399843209 :           cselib_val *v = (*l)->elt;
    2726    399843209 :           unsigned int this_last = i;
    2727              : 
    2728    399843209 :           if (i < FIRST_PSEUDO_REGISTER && v != NULL)
    2729    173450434 :             this_last = end_hard_regno (GET_MODE (v->val_rtx), i) - 1;
    2730              : 
    2731    399843209 :           if (this_last < regno || v == NULL
    2732    122508934 :               || (v == cfa_base_preserved_val
    2733      4468244 :                   && i == cfa_base_preserved_regno))
    2734              :             {
    2735    281800861 :               l = &(*l)->next;
    2736    281800861 :               continue;
    2737              :             }
    2738              : 
    2739              :           /* We have an overlap.  */
    2740    118042348 :           cselib_invalidate_regno_val (i, l);
    2741              :         }
    2742              :     }
    2743    832224314 : }
    2744              : 
    2745              : /* Invalidate any locations in the table which are changed because of a
    2746              :    store to MEM_RTX.  If this is called because of a non-const call
    2747              :    instruction, MEM_RTX is (mem:BLK const0_rtx).  */
    2748              : 
    2749              : static void
    2750    117919731 : cselib_invalidate_mem (rtx mem_rtx)
    2751              : {
    2752    117919731 :   cselib_val **vp, *v, *next;
    2753    117919731 :   int num_mems = 0;
    2754    117919731 :   rtx mem_addr;
    2755              : 
    2756    117919731 :   mem_addr = canon_rtx (get_addr (XEXP (mem_rtx, 0)));
    2757    117919731 :   mem_rtx = canon_rtx (mem_rtx);
    2758              : 
    2759    117919731 :   vp = &first_containing_mem;
    2760    295222713 :   for (v = *vp; v != &dummy_val; v = next)
    2761              :     {
    2762    177302982 :       bool has_mem = false;
    2763    177302982 :       struct elt_loc_list **p = &v->locs;
    2764    177302982 :       bool had_locs = v->locs != NULL;
    2765    177302982 :       rtx_insn *setting_insn = v->locs ? v->locs->setting_insn : NULL;
    2766    177302982 :       rtx sp_base = NULL_RTX;
    2767    177302982 :       HOST_WIDE_INT sp_off = 0;
    2768              : 
    2769    530528305 :       while (*p)
    2770              :         {
    2771    353225323 :           rtx x = (*p)->loc;
    2772    353225323 :           cselib_val *addr;
    2773    353225323 :           struct elt_list **mem_chain;
    2774              : 
    2775              :           /* MEMs may occur in locations only at the top level; below
    2776              :              that every MEM or REG is substituted by its VALUE.  */
    2777    353225323 :           if (!MEM_P (x))
    2778              :             {
    2779    106304742 :               p = &(*p)->next;
    2780    106304742 :               continue;
    2781              :             }
    2782              : 
    2783              :           /* When invalidating memory below the stack pointer for const/pure
    2784              :              calls and alloca/VLAs aren't used, attempt to optimize.  Values
    2785              :              stored into area sometimes below the stack pointer shouldn't be
    2786              :              addressable and should be stored just through stack pointer
    2787              :              derived expressions, so don't invalidate MEMs not using stack
    2788              :              derived addresses, or if the MEMs clearly aren't below the stack
    2789              :              pointer.  This isn't a fully conservative approach, the hope is
    2790              :              that invalidating more MEMs than this isn't actually needed.  */
    2791    246920581 :           if (mem_rtx == callmem[1]
    2792      2904170 :               && num_mems < param_max_cselib_memory_locations
    2793      2904112 :               && GET_CODE (XEXP (x, 0)) == VALUE
    2794      2904112 :               && !cfun->calls_alloca)
    2795              :             {
    2796      2853032 :               cselib_val *v2 = CSELIB_VAL_PTR (XEXP (x, 0));
    2797      2853032 :               rtx x_base = NULL_RTX;
    2798      2853032 :               HOST_WIDE_INT x_off = 0;
    2799      2853032 :               if (SP_DERIVED_VALUE_P (v2->val_rtx))
    2800              :                 x_base = v2->val_rtx;
    2801              :               else
    2802      4544258 :                 for (struct elt_loc_list *l = v2->locs; l; l = l->next)
    2803      2825240 :                   if (GET_CODE (l->loc) == PLUS
    2804      1492063 :                       && GET_CODE (XEXP (l->loc, 0)) == VALUE
    2805      1404262 :                       && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
    2806      3881447 :                       && CONST_INT_P (XEXP (l->loc, 1)))
    2807              :                     {
    2808      1056183 :                       x_base = XEXP (l->loc, 0);
    2809      1056183 :                       x_off = INTVAL (XEXP (l->loc, 1));
    2810      1056183 :                       break;
    2811              :                     }
    2812              :               /* If x_base is NULL here, don't invalidate x as its address
    2813              :                  isn't derived from sp such that it could be in outgoing
    2814              :                  argument area of some call in !ACCUMULATE_OUTGOING_ARGS
    2815              :                  function.  */
    2816      2853032 :               if (x_base)
    2817              :                 {
    2818      1134014 :                   if (sp_base == NULL_RTX)
    2819              :                     {
    2820      2070608 :                       if (cselib_val *v3
    2821      1038555 :                           = cselib_lookup_1 (stack_pointer_rtx, Pmode, 0,
    2822              :                                              VOIDmode))
    2823              :                         {
    2824      1030570 :                           if (SP_DERIVED_VALUE_P (v3->val_rtx))
    2825              :                             sp_base = v3->val_rtx;
    2826              :                           else
    2827       277759 :                             for (struct elt_loc_list *l = v3->locs;
    2828       558023 :                                  l; l = l->next)
    2829       558023 :                               if (GET_CODE (l->loc) == PLUS
    2830       277759 :                                   && GET_CODE (XEXP (l->loc, 0)) == VALUE
    2831       277759 :                                   && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
    2832       835782 :                                   && CONST_INT_P (XEXP (l->loc, 1)))
    2833              :                                 {
    2834       277759 :                                   sp_base = XEXP (l->loc, 0);
    2835       277759 :                                   sp_off = INTVAL (XEXP (l->loc, 1));
    2836       277759 :                                   break;
    2837              :                                 }
    2838              :                         }
    2839      1035304 :                       if (sp_base == NULL_RTX)
    2840         4734 :                         sp_base = pc_rtx;
    2841              :                     }
    2842              :                   /* Otherwise, if x_base and sp_base are the same,
    2843              :                      we know that x_base + x_off is the x's address and
    2844              :                      sp_base + sp_off is current value of stack pointer,
    2845              :                      so try to determine if x is certainly not below stack
    2846              :                      pointer.  */
    2847      1134014 :                   if (sp_base == x_base)
    2848              :                     {
    2849      1126478 :                       if (STACK_GROWS_DOWNWARD)
    2850              :                         {
    2851      1126478 :                           HOST_WIDE_INT off = sp_off;
    2852              : #ifdef STACK_ADDRESS_OFFSET
    2853              :                           /* On SPARC take stack pointer bias into account as
    2854              :                              well.  */
    2855              :                           off += (STACK_ADDRESS_OFFSET
    2856              :                                   - FIRST_PARM_OFFSET (current_function_decl));
    2857              : #endif
    2858      1126478 :                           if (x_off >= off)
    2859              :                             /* x is at or above the current stack pointer,
    2860              :                                no need to invalidate it.  */
    2861              :                             x_base = NULL_RTX;
    2862              :                         }
    2863              :                       else
    2864              :                         {
    2865              :                           HOST_WIDE_INT sz;
    2866              :                           enum machine_mode mode = GET_MODE (x);
    2867              :                           if ((MEM_SIZE_KNOWN_P (x)
    2868              :                                && MEM_SIZE (x).is_constant (&sz))
    2869              :                               || (mode != BLKmode
    2870              :                                   && GET_MODE_SIZE (mode).is_constant (&sz)))
    2871              :                             if (x_off < sp_off
    2872              :                                 && ((HOST_WIDE_INT) ((unsigned HOST_WIDE_INT)
    2873              :                                                      x_off + sz) <= sp_off))
    2874              :                               /* x's end is below or at the current stack
    2875              :                                  pointer in !STACK_GROWS_DOWNWARD target,
    2876              :                                  no need to invalidate it.  */
    2877              :                               x_base = NULL_RTX;
    2878              :                          }
    2879              :                     }
    2880              :                 }
    2881      2844766 :               if (x_base == NULL_RTX)
    2882              :                 {
    2883      2844766 :                   has_mem = true;
    2884      2844766 :                   num_mems++;
    2885      2844766 :                   p = &(*p)->next;
    2886      2844766 :                   continue;
    2887              :                 }
    2888              :             }
    2889              : 
    2890    450084958 :           if (num_mems < param_max_cselib_memory_locations
    2891    488073895 :               && ! canon_anti_dependence (x, false, mem_rtx,
    2892    243998080 :                                           GET_MODE (mem_rtx), mem_addr))
    2893              :             {
    2894    206009143 :               has_mem = true;
    2895    206009143 :               num_mems++;
    2896    206009143 :               p = &(*p)->next;
    2897    206009143 :               continue;
    2898              :             }
    2899              : 
    2900              :           /* This one overlaps.  */
    2901              :           /* We must have a mapping from this MEM's address to the
    2902              :              value (E).  Remove that, too.  */
    2903     38066672 :           addr = cselib_lookup (XEXP (x, 0), VOIDmode, 0, GET_MODE (x));
    2904     38066672 :           addr = canonical_cselib_val (addr);
    2905     38066672 :           gcc_checking_assert (v == canonical_cselib_val (v));
    2906     38066672 :           mem_chain = &addr->addr_list;
    2907     38071764 :           for (;;)
    2908              :             {
    2909     38069218 :               cselib_val *canon = canonical_cselib_val ((*mem_chain)->elt);
    2910              : 
    2911     38069218 :               if (canon == v)
    2912              :                 {
    2913     38066672 :                   unchain_one_elt_list (mem_chain);
    2914     38066672 :                   break;
    2915              :                 }
    2916              : 
    2917              :               /* Record canonicalized elt.  */
    2918         2546 :               (*mem_chain)->elt = canon;
    2919              : 
    2920         2546 :               mem_chain = &(*mem_chain)->next;
    2921         2546 :             }
    2922              : 
    2923     38066672 :           unchain_one_elt_loc_list (p);
    2924              :         }
    2925              : 
    2926    177302982 :       if (had_locs && cselib_useless_value_p (v))
    2927              :         {
    2928      8940867 :           if (setting_insn && DEBUG_INSN_P (setting_insn))
    2929            0 :             n_useless_debug_values++;
    2930              :           else
    2931      8940867 :             n_useless_values++;
    2932              :         }
    2933              : 
    2934    177302982 :       next = v->next_containing_mem;
    2935    177302982 :       if (has_mem)
    2936              :         {
    2937    144230157 :           *vp = v;
    2938    144230157 :           vp = &(*vp)->next_containing_mem;
    2939              :         }
    2940              :       else
    2941     33072825 :         v->next_containing_mem = NULL;
    2942              :     }
    2943    117919731 :   *vp = &dummy_val;
    2944    117919731 : }
    2945              : 
    2946              : /* Invalidate DEST.  */
    2947              : 
    2948              : void
    2949    540351748 : cselib_invalidate_rtx (rtx dest)
    2950              : {
    2951    540351748 :   while (GET_CODE (dest) == SUBREG
    2952    540351748 :          || GET_CODE (dest) == ZERO_EXTRACT
    2953   1080708377 :          || GET_CODE (dest) == STRICT_LOW_PART)
    2954         4881 :     dest = XEXP (dest, 0);
    2955              : 
    2956    540351748 :   if (REG_P (dest))
    2957    412365230 :     cselib_invalidate_regno (REGNO (dest), GET_MODE (dest));
    2958    127986518 :   else if (MEM_P (dest))
    2959     78164529 :     cselib_invalidate_mem (dest);
    2960    540351748 : }
    2961              : 
    2962              : /* A wrapper for cselib_invalidate_rtx to be called via note_stores.  */
    2963              : 
    2964              : static void
    2965    526070569 : cselib_invalidate_rtx_note_stores (rtx dest, const_rtx,
    2966              :                                    void *data ATTRIBUTE_UNUSED)
    2967              : {
    2968    526070569 :   cselib_invalidate_rtx (dest);
    2969    526070569 : }
    2970              : 
    2971              : /* Record the result of a SET instruction.  DEST is being set; the source
    2972              :    contains the value described by SRC_ELT.  If DEST is a MEM, DEST_ADDR_ELT
    2973              :    describes its address.  */
    2974              : 
    2975              : static void
    2976    377553762 : cselib_record_set (rtx dest, cselib_val *src_elt, cselib_val *dest_addr_elt)
    2977              : {
    2978    377553762 :   if (src_elt == 0 || side_effects_p (dest))
    2979              :     return;
    2980              : 
    2981    309286899 :   if (REG_P (dest))
    2982              :     {
    2983    284303047 :       unsigned int dreg = REGNO (dest);
    2984    284303047 :       if (dreg < FIRST_PSEUDO_REGISTER)
    2985              :         {
    2986    208008569 :           unsigned int n = REG_NREGS (dest);
    2987              : 
    2988    208008569 :           if (n > max_value_regs)
    2989     26577180 :             max_value_regs = n;
    2990              :         }
    2991              : 
    2992    284303047 :       if (REG_VALUES (dreg) == 0)
    2993              :         {
    2994    174573361 :           used_regs[n_used_regs++] = dreg;
    2995    174573361 :           REG_VALUES (dreg) = new_elt_list (REG_VALUES (dreg), src_elt);
    2996              :         }
    2997              :       else
    2998              :         {
    2999              :           /* The register should have been invalidated.  */
    3000    109729686 :           gcc_assert (REG_VALUES (dreg)->elt == 0);
    3001    109729686 :           REG_VALUES (dreg)->elt = src_elt;
    3002              :         }
    3003              : 
    3004    284303047 :       if (cselib_useless_value_p (src_elt))
    3005        41540 :         n_useless_values--;
    3006    284303047 :       new_elt_loc_list (src_elt, dest);
    3007              :     }
    3008     24983852 :   else if (MEM_P (dest) && dest_addr_elt != 0
    3009     24983852 :            && cselib_record_memory)
    3010              :     {
    3011     24983852 :       if (cselib_useless_value_p (src_elt))
    3012           16 :         n_useless_values--;
    3013     24983852 :       add_mem_for_addr (dest_addr_elt, src_elt, dest);
    3014              :     }
    3015              : }
    3016              : 
    3017              : /* Make ELT and X's VALUE equivalent to each other at INSN.  */
    3018              : 
    3019              : void
    3020      3912278 : cselib_add_permanent_equiv (cselib_val *elt, rtx x, rtx_insn *insn)
    3021              : {
    3022      3912278 :   cselib_val *nelt;
    3023      3912278 :   rtx_insn *save_cselib_current_insn = cselib_current_insn;
    3024              : 
    3025      3912278 :   gcc_checking_assert (elt);
    3026      3912278 :   gcc_checking_assert (PRESERVED_VALUE_P (elt->val_rtx));
    3027      3912278 :   gcc_checking_assert (!side_effects_p (x));
    3028              : 
    3029      3912278 :   cselib_current_insn = insn;
    3030              : 
    3031      3912278 :   nelt = cselib_lookup (x, GET_MODE (elt->val_rtx), 1, VOIDmode);
    3032              : 
    3033      3912278 :   if (nelt != elt)
    3034              :     {
    3035      3039577 :       cselib_any_perm_equivs = true;
    3036              : 
    3037      3039577 :       if (!PRESERVED_VALUE_P (nelt->val_rtx))
    3038      3033173 :         cselib_preserve_value (nelt);
    3039              : 
    3040      3039577 :       new_elt_loc_list (nelt, elt->val_rtx);
    3041              :     }
    3042              : 
    3043      3912278 :   cselib_current_insn = save_cselib_current_insn;
    3044      3912278 : }
    3045              : 
    3046              : /* Return TRUE if any permanent equivalences have been recorded since
    3047              :    the table was last initialized.  */
    3048              : bool
    3049   1413100233 : cselib_have_permanent_equivalences (void)
    3050              : {
    3051   1413100233 :   return cselib_any_perm_equivs;
    3052              : }
    3053              : 
    3054              : /* Record stack_pointer_rtx to be equal to
    3055              :    (plus:P cfa_base_preserved_val offset).  Used by var-tracking
    3056              :    at the start of basic blocks for !frame_pointer_needed functions.  */
    3057              : 
    3058              : void
    3059      3529116 : cselib_record_sp_cfa_base_equiv (HOST_WIDE_INT offset, rtx_insn *insn)
    3060              : {
    3061      3529116 :   rtx sp_derived_value = NULL_RTX;
    3062      7058232 :   for (struct elt_loc_list *l = cfa_base_preserved_val->locs; l; l = l->next)
    3063      7058232 :     if (GET_CODE (l->loc) == VALUE
    3064      7058232 :         && SP_DERIVED_VALUE_P (l->loc))
    3065              :       {
    3066              :         sp_derived_value = l->loc;
    3067              :         break;
    3068              :       }
    3069      7058232 :     else if (GET_CODE (l->loc) == PLUS
    3070      3529116 :              && GET_CODE (XEXP (l->loc, 0)) == VALUE
    3071      3529116 :              && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
    3072     10587348 :              && CONST_INT_P (XEXP (l->loc, 1)))
    3073              :       {
    3074      3529116 :         sp_derived_value = XEXP (l->loc, 0);
    3075      3529116 :         offset = offset + UINTVAL (XEXP (l->loc, 1));
    3076      3529116 :         break;
    3077              :       }
    3078      3529116 :   if (sp_derived_value == NULL_RTX)
    3079              :     return;
    3080      3529116 :   cselib_val *val
    3081      3529116 :     = cselib_lookup_from_insn (plus_constant (Pmode, sp_derived_value, offset),
    3082      3529116 :                                Pmode, 1, VOIDmode, insn);
    3083      3529116 :   if (val != NULL)
    3084              :     {
    3085      3529116 :       PRESERVED_VALUE_P (val->val_rtx) = 1;
    3086      3529116 :       cselib_record_set (stack_pointer_rtx, val, NULL);
    3087              :     }
    3088              : }
    3089              : 
    3090              : /* Return true if V is SP_DERIVED_VALUE_P (or SP_DERIVED_VALUE_P + CONST_INT)
    3091              :    that can be expressed using cfa_base_preserved_val + CONST_INT.  */
    3092              : 
    3093              : bool
    3094     31561581 : cselib_sp_derived_value_p (cselib_val *v)
    3095              : {
    3096     31561581 :   if (!SP_DERIVED_VALUE_P (v->val_rtx))
    3097     69635237 :     for (struct elt_loc_list *l = v->locs; l; l = l->next)
    3098     38591480 :       if (GET_CODE (l->loc) == PLUS
    3099      7278054 :           && GET_CODE (XEXP (l->loc, 0)) == VALUE
    3100      7035799 :           && SP_DERIVED_VALUE_P (XEXP (l->loc, 0))
    3101     43746490 :           && CONST_INT_P (XEXP (l->loc, 1)))
    3102      5155010 :         v = CSELIB_VAL_PTR (XEXP (l->loc, 0));
    3103     31561581 :   if (!SP_DERIVED_VALUE_P (v->val_rtx))
    3104              :     return false;
    3105     11643490 :   for (struct elt_loc_list *l = v->locs; l; l = l->next)
    3106     11643490 :     if (l->loc == cfa_base_preserved_val->val_rtx)
    3107              :       return true;
    3108     11643490 :     else if (GET_CODE (l->loc) == PLUS
    3109      5672834 :              && XEXP (l->loc, 0) == cfa_base_preserved_val->val_rtx
    3110      5672834 :              && CONST_INT_P (XEXP (l->loc, 1)))
    3111              :       return true;
    3112              :   return false;
    3113              : }
    3114              : 
    3115              : /* There is no good way to determine how many elements there can be
    3116              :    in a PARALLEL.  Since it's fairly cheap, use a really large number.  */
    3117              : #define MAX_SETS (FIRST_PSEUDO_REGISTER * 2)
    3118              : 
    3119              : struct cselib_record_autoinc_data
    3120              : {
    3121              :   struct cselib_set *sets;
    3122              :   int n_sets;
    3123              : };
    3124              : 
    3125              : /* Callback for for_each_inc_dec.  Records in ARG the SETs implied by
    3126              :    autoinc RTXs: SRC plus SRCOFF if non-NULL is stored in DEST.  */
    3127              : 
    3128              : static int
    3129     13568582 : cselib_record_autoinc_cb (rtx mem ATTRIBUTE_UNUSED, rtx op ATTRIBUTE_UNUSED,
    3130              :                           rtx dest, rtx src, rtx srcoff, void *arg)
    3131              : {
    3132     13568582 :   struct cselib_record_autoinc_data *data;
    3133     13568582 :   data = (struct cselib_record_autoinc_data *)arg;
    3134              : 
    3135     13568582 :   data->sets[data->n_sets].dest = dest;
    3136              : 
    3137     13568582 :   if (srcoff)
    3138     13186649 :     data->sets[data->n_sets].src = gen_rtx_PLUS (GET_MODE (src), src, srcoff);
    3139              :   else
    3140       381933 :     data->sets[data->n_sets].src = src;
    3141              : 
    3142     13568582 :   data->n_sets++;
    3143              : 
    3144     13568582 :   return 0;
    3145              : }
    3146              : 
    3147              : /* Record the effects of any sets and autoincs in INSN.  */
    3148              : static void
    3149    923852518 : cselib_record_sets (rtx_insn *insn)
    3150              : {
    3151    923852518 :   int n_sets = 0;
    3152    923852518 :   int i;
    3153    923852518 :   struct cselib_set sets[MAX_SETS];
    3154    923852518 :   rtx cond = 0;
    3155    923852518 :   int n_sets_before_autoinc;
    3156    923852518 :   int n_strict_low_parts = 0;
    3157    923852518 :   struct cselib_record_autoinc_data data;
    3158              : 
    3159    923852518 :   rtx body = PATTERN (insn);
    3160    923852518 :   if (GET_CODE (body) == COND_EXEC)
    3161              :     {
    3162            0 :       cond = COND_EXEC_TEST (body);
    3163            0 :       body = COND_EXEC_CODE (body);
    3164              :     }
    3165              : 
    3166              :   /* Find all sets.  */
    3167    923852518 :   if (GET_CODE (body) == SET)
    3168              :     {
    3169    380953409 :       sets[0].src = SET_SRC (body);
    3170    380953409 :       sets[0].dest = SET_DEST (body);
    3171    380953409 :       n_sets = 1;
    3172              :     }
    3173    542899109 :   else if (GET_CODE (body) == PARALLEL)
    3174              :     {
    3175              :       /* Look through the PARALLEL and record the values being
    3176              :          set, if possible.  Also handle any CLOBBERs.  */
    3177    218266861 :       for (i = XVECLEN (body, 0) - 1; i >= 0; --i)
    3178              :         {
    3179    147225416 :           rtx x = XVECEXP (body, 0, i);
    3180              : 
    3181    147225416 :           if (GET_CODE (x) == SET)
    3182              :             {
    3183     77079834 :               sets[n_sets].src = SET_SRC (x);
    3184     77079834 :               sets[n_sets].dest = SET_DEST (x);
    3185     77079834 :               n_sets++;
    3186              :             }
    3187              :         }
    3188              :     }
    3189              : 
    3190    380953409 :   if (n_sets == 1
    3191    445950147 :       && MEM_P (sets[0].src)
    3192     63228683 :       && !cselib_record_memory
    3193    111629817 :       && MEM_READONLY_P (sets[0].src))
    3194              :     {
    3195      3369126 :       rtx note = find_reg_equal_equiv_note (insn);
    3196              : 
    3197      3369126 :       if (note && CONSTANT_P (XEXP (note, 0)))
    3198      2143343 :         sets[0].src = XEXP (note, 0);
    3199              :     }
    3200              : 
    3201    923852518 :   data.sets = sets;
    3202    923852518 :   data.n_sets = n_sets_before_autoinc = n_sets;
    3203    923852518 :   for_each_inc_dec (PATTERN (insn), cselib_record_autoinc_cb, &data);
    3204    923852518 :   n_sets = data.n_sets;
    3205              : 
    3206              :   /* Look up the values that are read.  Do this before invalidating the
    3207              :      locations that are written.  */
    3208   1395454343 :   for (i = 0; i < n_sets; i++)
    3209              :     {
    3210    471601825 :       rtx dest = sets[i].dest;
    3211    471601825 :       rtx orig = dest;
    3212              : 
    3213              :       /* A STRICT_LOW_PART can be ignored; we'll record the equivalence for
    3214              :          the low part after invalidating any knowledge about larger modes.  */
    3215    471601825 :       if (GET_CODE (sets[i].dest) == STRICT_LOW_PART)
    3216        47730 :         sets[i].dest = dest = XEXP (dest, 0);
    3217              : 
    3218              :       /* We don't know how to record anything but REG or MEM.  */
    3219    471601825 :       if (REG_P (dest)
    3220    126871523 :           || (MEM_P (dest) && cselib_record_memory))
    3221              :         {
    3222    374024646 :           rtx src = sets[i].src;
    3223    374024646 :           if (cond)
    3224            0 :             src = gen_rtx_IF_THEN_ELSE (GET_MODE (dest), cond, src, dest);
    3225    374024646 :           sets[i].src_elt = cselib_lookup (src, GET_MODE (dest), 1, VOIDmode);
    3226    374024646 :           if (MEM_P (dest))
    3227              :             {
    3228     29294344 :               machine_mode address_mode = get_address_mode (dest);
    3229              : 
    3230     29294344 :               sets[i].dest_addr_elt = cselib_lookup (XEXP (dest, 0),
    3231              :                                                      address_mode, 1,
    3232     29294344 :                                                      GET_MODE (dest));
    3233              :             }
    3234              :           else
    3235    344730302 :             sets[i].dest_addr_elt = 0;
    3236              :         }
    3237              : 
    3238              :       /* Improve handling of STRICT_LOW_PART if the current value is known
    3239              :          to be const0_rtx, then the low bits will be set to dest and higher
    3240              :          bits will remain zero.  Used in code like:
    3241              : 
    3242              :          {di:SI=0;clobber flags:CC;}
    3243              :          flags:CCNO=cmp(bx:SI,0)
    3244              :          strict_low_part(di:QI)=flags:CCNO<=0
    3245              : 
    3246              :          where we can note both that di:QI=flags:CCNO<=0 and
    3247              :          also that because di:SI is known to be 0 and strict_low_part(di:QI)
    3248              :          preserves the upper bits that di:SI=zero_extend(flags:CCNO<=0).  */
    3249    471601825 :       scalar_int_mode mode;
    3250    471601825 :       if (dest != orig
    3251        47730 :           && cselib_record_sets_hook
    3252        17549 :           && REG_P (dest)
    3253        17549 :           && HARD_REGISTER_P (dest)
    3254        17549 :           && sets[i].src_elt
    3255    471619374 :           && is_a <scalar_int_mode> (GET_MODE (dest), &mode)
    3256    471619374 :           && n_sets + n_strict_low_parts < MAX_SETS)
    3257              :         {
    3258        17549 :           opt_scalar_int_mode wider_mode_iter;
    3259        43602 :           FOR_EACH_WIDER_MODE (wider_mode_iter, mode)
    3260              :             {
    3261        43602 :               scalar_int_mode wider_mode = wider_mode_iter.require ();
    3262        52174 :               if (GET_MODE_PRECISION (wider_mode) > BITS_PER_WORD)
    3263              :                 break;
    3264              : 
    3265        42466 :               rtx reg = gen_lowpart (wider_mode, dest);
    3266        42466 :               if (!REG_P (reg))
    3267              :                 break;
    3268              : 
    3269        42401 :               cselib_val *v = cselib_lookup (reg, wider_mode, 0, VOIDmode);
    3270        42401 :               if (!v)
    3271        26053 :                 continue;
    3272              : 
    3273        17206 :               struct elt_loc_list *l;
    3274        36137 :               for (l = v->locs; l; l = l->next)
    3275        35279 :                 if (l->loc == const0_rtx)
    3276              :                   break;
    3277              : 
    3278          858 :               if (!l)
    3279          858 :                 continue;
    3280              : 
    3281        16348 :               sets[n_sets + n_strict_low_parts].dest = reg;
    3282        16348 :               sets[n_sets + n_strict_low_parts].src = dest;
    3283        16348 :               sets[n_sets + n_strict_low_parts++].src_elt = sets[i].src_elt;
    3284        16348 :               break;
    3285              :             }
    3286              :         }
    3287              :     }
    3288              : 
    3289    923852518 :   if (cselib_record_sets_hook)
    3290     82770807 :     cselib_record_sets_hook (insn, sets, n_sets);
    3291              : 
    3292              :   /* Invalidate all locations written by this insn.  Note that the elts we
    3293              :      looked up in the previous loop aren't affected, just some of their
    3294              :      locations may go away.  */
    3295    923852518 :   note_pattern_stores (body, cselib_invalidate_rtx_note_stores, NULL);
    3296              : 
    3297   1861273618 :   for (i = n_sets_before_autoinc; i < n_sets; i++)
    3298     13568582 :     cselib_invalidate_rtx (sets[i].dest);
    3299              : 
    3300              :   /* If this is an asm, look for duplicate sets.  This can happen when the
    3301              :      user uses the same value as an output multiple times.  This is valid
    3302              :      if the outputs are not actually used thereafter.  Treat this case as
    3303              :      if the value isn't actually set.  We do this by smashing the destination
    3304              :      to pc_rtx, so that we won't record the value later.  */
    3305    923852518 :   if (n_sets >= 2 && asm_noperands (body) >= 0)
    3306              :     {
    3307       535638 :       for (i = 0; i < n_sets; i++)
    3308              :         {
    3309       413149 :           rtx dest = sets[i].dest;
    3310       413149 :           if (REG_P (dest) || MEM_P (dest))
    3311              :             {
    3312       413116 :               int j;
    3313       960950 :               for (j = i + 1; j < n_sets; j++)
    3314       547834 :                 if (rtx_equal_p (dest, sets[j].dest))
    3315              :                   {
    3316            0 :                     sets[i].dest = pc_rtx;
    3317            0 :                     sets[j].dest = pc_rtx;
    3318              :                   }
    3319              :             }
    3320              :         }
    3321              :     }
    3322              : 
    3323              :   /* Now enter the equivalences in our tables.  */
    3324   1395454343 :   for (i = 0; i < n_sets; i++)
    3325              :     {
    3326    471601825 :       rtx dest = sets[i].dest;
    3327    471601825 :       if (REG_P (dest)
    3328    126871523 :           || (MEM_P (dest) && cselib_record_memory))
    3329    374024646 :         cselib_record_set (dest, sets[i].src_elt, sets[i].dest_addr_elt);
    3330              :     }
    3331              : 
    3332              :   /* And deal with STRICT_LOW_PART.  */
    3333    923868866 :   for (i = 0; i < n_strict_low_parts; i++)
    3334              :     {
    3335        16348 :       if (! PRESERVED_VALUE_P (sets[n_sets + i].src_elt->val_rtx))
    3336            0 :         continue;
    3337        16348 :       machine_mode dest_mode = GET_MODE (sets[n_sets + i].dest);
    3338        16348 :       cselib_val *v
    3339        16348 :         = cselib_lookup (sets[n_sets + i].dest, dest_mode, 1, VOIDmode);
    3340        16348 :       cselib_preserve_value (v);
    3341        16348 :       rtx r = gen_rtx_ZERO_EXTEND (dest_mode,
    3342              :                                    sets[n_sets + i].src_elt->val_rtx);
    3343        16348 :       cselib_add_permanent_equiv (v, r, insn);
    3344              :     }
    3345    923852518 : }
    3346              : 
    3347              : /* Return true if INSN in the prologue initializes hard_frame_pointer_rtx.  */
    3348              : 
    3349              : bool
    3350     41281298 : fp_setter_insn (rtx_insn *insn)
    3351              : {
    3352     41281298 :   rtx expr, pat = NULL_RTX;
    3353              : 
    3354     41281298 :   if (!RTX_FRAME_RELATED_P (insn))
    3355              :     return false;
    3356              : 
    3357       633214 :   expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
    3358       633214 :   if (expr)
    3359           75 :     pat = XEXP (expr, 0);
    3360       633214 :   if (!modified_in_p (hard_frame_pointer_rtx, pat ? pat : insn))
    3361              :     return false;
    3362              : 
    3363              :   /* Don't return true for frame pointer restores in the epilogue.  */
    3364       157373 :   if (find_reg_note (insn, REG_CFA_RESTORE, hard_frame_pointer_rtx))
    3365        41732 :     return false;
    3366              :   return true;
    3367              : }
    3368              : 
    3369              : /* V is one of the values in REG_VALUES (REGNO).  Return true if it
    3370              :    would be invalidated by CALLEE_ABI.  */
    3371              : 
    3372              : static bool
    3373    117785962 : cselib_invalidated_by_call_p (const function_abi &callee_abi,
    3374              :                               unsigned int regno, cselib_val *v)
    3375              : {
    3376    117785962 :   machine_mode mode = GET_MODE (v->val_rtx);
    3377    117785962 :   if (mode == VOIDmode)
    3378              :     {
    3379            0 :       v = REG_VALUES (regno)->elt;
    3380            0 :       if (!v)
    3381              :         /* If we don't know what the mode of the constant value is, and we
    3382              :            don't know what mode the register was set in, conservatively
    3383              :            assume that the register is clobbered.  The value's going to be
    3384              :            essentially useless in this case anyway.  */
    3385              :         return true;
    3386            0 :       mode = GET_MODE (v->val_rtx);
    3387              :     }
    3388    117785962 :   return callee_abi.clobbers_reg_p (mode, regno);
    3389              : }
    3390              : 
    3391              : /* Record the effects of INSN.  */
    3392              : 
    3393              : void
    3394   1062486305 : cselib_process_insn (rtx_insn *insn)
    3395              : {
    3396   1062486305 :   int i;
    3397   1062486305 :   rtx x;
    3398              : 
    3399   1062486305 :   cselib_current_insn = insn;
    3400              : 
    3401              :   /* Forget everything at a CODE_LABEL or a setjmp.  */
    3402   1062486305 :   if ((LABEL_P (insn)
    3403   1026221192 :        || (CALL_P (insn)
    3404     35149823 :            && find_reg_note (insn, REG_SETJMP, NULL)))
    3405   1062490832 :       && !cselib_preserve_constants)
    3406              :     {
    3407     36269404 :       cselib_reset_table (next_uid);
    3408     36269404 :       cselib_current_insn = NULL;
    3409     36269404 :       return;
    3410              :     }
    3411              : 
    3412   1026216901 :   if (! INSN_P (insn))
    3413              :     {
    3414    102364383 :       cselib_current_insn = NULL;
    3415    102364383 :       return;
    3416              :     }
    3417              : 
    3418              :   /* If this is a call instruction, forget anything stored in a
    3419              :      call clobbered register, or, if this is not a const call, in
    3420              :      memory.  */
    3421    923852518 :   if (auto call = dyn_cast<rtx_call_insn *> (insn))
    3422              :     {
    3423     35145532 :       function_abi callee_abi = insn_callee_abi (call);
    3424   3373971072 :       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    3425              :         {
    3426   3303680008 :           elt_list **l = &REG_VALUES (i);
    3427   3533721667 :           while (*l)
    3428              :             {
    3429    230041659 :               cselib_val *v = (*l)->elt;
    3430    230041659 :               if (v && cselib_invalidated_by_call_p (callee_abi, i, v))
    3431     73758811 :                 cselib_invalidate_regno_val (i, l);
    3432              :               else
    3433    156282848 :                 l = &(*l)->next;
    3434              :             }
    3435              :         }
    3436              : 
    3437              :       /* Since it is not clear how cselib is going to be used, be
    3438              :          conservative here and treat looping pure or const functions
    3439              :          as if they were regular functions.  */
    3440     35145532 :       if (RTL_LOOPING_CONST_OR_PURE_CALL_P (call)
    3441     35145532 :           || !(RTL_CONST_OR_PURE_CALL_P (call)))
    3442     32175898 :         cselib_invalidate_mem (callmem[0]);
    3443              :       else
    3444              :         {
    3445              :           /* For const/pure calls, invalidate any argument slots because
    3446              :              they are owned by the callee.  */
    3447      8797109 :           for (x = CALL_INSN_FUNCTION_USAGE (call); x; x = XEXP (x, 1))
    3448      5827475 :             if (GET_CODE (XEXP (x, 0)) == USE
    3449      5827475 :                 && MEM_P (XEXP (XEXP (x, 0), 0)))
    3450       143551 :               cselib_invalidate_mem (XEXP (XEXP (x, 0), 0));
    3451              :           /* And invalidate memory below the stack (or above for
    3452              :              !STACK_GROWS_DOWNWARD), as even const/pure call can invalidate
    3453              :              that.  Do this only if !ACCUMULATE_OUTGOING_ARGS or if
    3454              :              cfun->calls_alloca, otherwise the stack pointer shouldn't be
    3455              :              changing in the middle of the function and nothing should be
    3456              :              stored below the stack pointer.  */
    3457      2969634 :           if (!ACCUMULATE_OUTGOING_ARGS || cfun->calls_alloca)
    3458      2969167 :             cselib_invalidate_mem (callmem[1]);
    3459              :         }
    3460              :     }
    3461              : 
    3462    923852518 :   cselib_record_sets (insn);
    3463              : 
    3464              :   /* Look for any CLOBBERs in CALL_INSN_FUNCTION_USAGE, but only
    3465              :      after we have processed the insn.  */
    3466    923852518 :   if (auto call = dyn_cast<rtx_call_insn *> (insn))
    3467              :     {
    3468    104398569 :       for (x = CALL_INSN_FUNCTION_USAGE (call); x; x = XEXP (x, 1))
    3469     69253037 :         if (GET_CODE (XEXP (x, 0)) == CLOBBER)
    3470            0 :           cselib_invalidate_rtx (XEXP (XEXP (x, 0), 0));
    3471              : 
    3472              :       /* Flush everything on setjmp.  */
    3473     35145532 :       if (cselib_preserve_constants
    3474     35145532 :           && find_reg_note (insn, REG_SETJMP, NULL))
    3475              :         {
    3476          236 :           cselib_preserve_only_values ();
    3477          236 :           cselib_reset_table (next_uid);
    3478              :         }
    3479              :     }
    3480              : 
    3481              :   /* On setter of the hard frame pointer if frame_pointer_needed,
    3482              :      invalidate stack_pointer_rtx, so that sp and {,h}fp based
    3483              :      VALUEs are distinct.  */
    3484    923852518 :   if (reload_completed
    3485    422790709 :       && frame_pointer_needed
    3486    965013506 :       && fp_setter_insn (insn))
    3487        93414 :     cselib_invalidate_rtx (stack_pointer_rtx);
    3488              : 
    3489    923852518 :   cselib_current_insn = NULL;
    3490              : 
    3491    923852518 :   if (n_useless_values > MAX_USELESS_VALUES
    3492              :       /* remove_useless_values is linear in the hash table size.  Avoid
    3493              :          quadratic behavior for very large hashtables with very few
    3494              :          useless elements.  */
    3495    923852518 :       && ((unsigned int)n_useless_values
    3496      2524686 :           > (cselib_hash_table->elements () - n_debug_values) / 4))
    3497        28859 :     remove_useless_values ();
    3498              : }
    3499              : 
    3500              : /* Initialize cselib for one pass.  The caller must also call
    3501              :    init_alias_analysis.  */
    3502              : 
    3503              : void
    3504     10477525 : cselib_init (int record_what)
    3505              : {
    3506     10477525 :   cselib_record_memory = record_what & CSELIB_RECORD_MEMORY;
    3507     10477525 :   cselib_preserve_constants = record_what & CSELIB_PRESERVE_CONSTANTS;
    3508     10477525 :   cselib_any_perm_equivs = false;
    3509              : 
    3510              :   /* (mem:BLK (scratch)) is a special mechanism to conflict with everything,
    3511              :      see canon_true_dependence.  This is only created once.  */
    3512     10477525 :   if (! callmem[0])
    3513       150990 :     callmem[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
    3514              :   /* Similarly create a MEM representing roughly everything below
    3515              :      the stack for STACK_GROWS_DOWNWARD targets or everything above
    3516              :      it otherwise.  Do this only when !ACCUMULATE_OUTGOING_ARGS or
    3517              :      if cfun->calls_alloca, otherwise the stack pointer shouldn't be
    3518              :      changing in the middle of the function and nothing should be stored
    3519              :      below the stack pointer.  */
    3520     10477525 :   if (!callmem[1] && (!ACCUMULATE_OUTGOING_ARGS || cfun->calls_alloca))
    3521              :     {
    3522       150704 :       if (STACK_GROWS_DOWNWARD)
    3523              :         {
    3524       150704 :           unsigned HOST_WIDE_INT off = -(GET_MODE_MASK (Pmode) >> 1);
    3525              : #ifdef STACK_ADDRESS_OFFSET
    3526              :           /* On SPARC take stack pointer bias into account as well.  */
    3527              :           off += (STACK_ADDRESS_OFFSET
    3528              :                   - FIRST_PARM_OFFSET (current_function_decl));
    3529              : #endif
    3530       150704 :           callmem[1] = plus_constant (Pmode, stack_pointer_rtx, off);
    3531              :         }
    3532              :       else
    3533              :         callmem[1] = stack_pointer_rtx;
    3534       150704 :       callmem[1] = gen_rtx_MEM (BLKmode, callmem[1]);
    3535       156139 :       set_mem_size (callmem[1], GET_MODE_MASK (Pmode) >> 1);
    3536              :     }
    3537              : 
    3538     10477525 :   cselib_nregs = max_reg_num ();
    3539              : 
    3540              :   /* We preserve reg_values to allow expensive clearing of the whole thing.
    3541              :      Reallocate it however if it happens to be too large.  */
    3542     10477525 :   if (!reg_values || reg_values_size < cselib_nregs
    3543     10166852 :       || (reg_values_size > 10 && reg_values_size > cselib_nregs * 4))
    3544              :     {
    3545       326753 :       free (reg_values);
    3546              :       /* Some space for newly emit instructions so we don't end up
    3547              :          reallocating in between passes.  */
    3548       326753 :       reg_values_size = cselib_nregs + (63 + cselib_nregs) / 16;
    3549       326753 :       reg_values = XCNEWVEC (struct elt_list *, reg_values_size);
    3550              :     }
    3551     10477525 :   used_regs = XNEWVEC (unsigned int, cselib_nregs);
    3552     10477525 :   n_used_regs = 0;
    3553              :   /* FIXME: enable sanitization (PR87845) */
    3554     10477525 :   cselib_hash_table
    3555     10477525 :     = new hash_table<cselib_hasher> (31, /* ggc */ false,
    3556     10477525 :                                      /* sanitize_eq_and_hash */ false);
    3557     10477525 :   if (cselib_preserve_constants)
    3558       503306 :     cselib_preserved_hash_table
    3559       503306 :       = new hash_table<cselib_hasher> (31, /* ggc */ false,
    3560       503306 :                                        /* sanitize_eq_and_hash */ false);
    3561     10477525 :   next_uid = 1;
    3562     10477525 : }
    3563              : 
    3564              : /* Called when the current user is done with cselib.  */
    3565              : 
    3566              : void
    3567     10477525 : cselib_finish (void)
    3568              : {
    3569     10477525 :   bool preserved = cselib_preserve_constants;
    3570     10477525 :   cselib_discard_hook = NULL;
    3571     10477525 :   cselib_preserve_constants = false;
    3572     10477525 :   cselib_any_perm_equivs = false;
    3573     10477525 :   cfa_base_preserved_val = NULL;
    3574     10477525 :   cfa_base_preserved_regno = INVALID_REGNUM;
    3575     10477525 :   elt_list_pool.release ();
    3576     10477525 :   elt_loc_list_pool.release ();
    3577     10477525 :   cselib_val_pool.release ();
    3578     10477525 :   value_pool.release ();
    3579     10477525 :   cselib_clear_table ();
    3580     10477525 :   delete cselib_hash_table;
    3581     10477525 :   cselib_hash_table = NULL;
    3582     10477525 :   if (preserved)
    3583       503306 :     delete cselib_preserved_hash_table;
    3584     10477525 :   cselib_preserved_prune_list.release ();
    3585     10477525 :   cselib_preserved_hash_table = NULL;
    3586     10477525 :   free (used_regs);
    3587     10477525 :   used_regs = 0;
    3588     10477525 :   n_useless_values = 0;
    3589     10477525 :   n_useless_debug_values = 0;
    3590     10477525 :   n_debug_values = 0;
    3591     10477525 :   next_uid = 0;
    3592     10477525 : }
    3593              : 
    3594              : /* Dump the cselib_val V to FILE *OUT.  */
    3595              : 
    3596              : int
    3597           93 : dump_cselib_val (cselib_val *v, FILE *out)
    3598              : {
    3599           93 :   bool need_lf = true;
    3600              : 
    3601           93 :   print_inline_rtx (out, v->val_rtx, 0);
    3602              : 
    3603           93 :   if (v->locs)
    3604              :     {
    3605           86 :       struct elt_loc_list *l = v->locs;
    3606           86 :       if (need_lf)
    3607              :         {
    3608           86 :           fputc ('\n', out);
    3609           86 :           need_lf = false;
    3610              :         }
    3611           86 :       fputs (" locs:", out);
    3612          149 :       do
    3613              :         {
    3614          149 :           if (l->setting_insn)
    3615          149 :             fprintf (out, "\n  from insn %i ",
    3616          149 :                      INSN_UID (l->setting_insn));
    3617              :           else
    3618            0 :             fprintf (out, "\n   ");
    3619          149 :           print_inline_rtx (out, l->loc, 4);
    3620              :         }
    3621          149 :       while ((l = l->next));
    3622           86 :       fputc ('\n', out);
    3623              :     }
    3624              :   else
    3625              :     {
    3626            7 :       fputs (" no locs", out);
    3627            7 :       need_lf = true;
    3628              :     }
    3629              : 
    3630           93 :   if (v->addr_list)
    3631              :     {
    3632            6 :       struct elt_list *e = v->addr_list;
    3633            6 :       if (need_lf)
    3634              :         {
    3635            0 :           fputc ('\n', out);
    3636            0 :           need_lf = false;
    3637              :         }
    3638            6 :       fputs (" addr list:", out);
    3639            6 :       do
    3640              :         {
    3641            6 :           fputs ("\n  ", out);
    3642            6 :           print_inline_rtx (out, e->elt->val_rtx, 2);
    3643              :         }
    3644            6 :       while ((e = e->next));
    3645            6 :       fputc ('\n', out);
    3646              :     }
    3647              :   else
    3648              :     {
    3649           87 :       fputs (" no addrs", out);
    3650           87 :       need_lf = true;
    3651              :     }
    3652              : 
    3653           93 :   if (v->next_containing_mem == &dummy_val)
    3654            6 :     fputs (" last mem\n", out);
    3655           87 :   else if (v->next_containing_mem)
    3656              :     {
    3657            0 :       fputs (" next mem ", out);
    3658            0 :       print_inline_rtx (out, v->next_containing_mem->val_rtx, 2);
    3659            0 :       fputc ('\n', out);
    3660              :     }
    3661           87 :   else if (need_lf)
    3662           81 :     fputc ('\n', out);
    3663              : 
    3664           93 :   return 1;
    3665              : }
    3666              : 
    3667              : /* Dump the cselib_val *X to FILE *OUT.  */
    3668              : 
    3669              : static int
    3670           93 : dump_cselib_val_ptr (cselib_val **x, FILE *out)
    3671              : {
    3672           93 :   cselib_val *v = *x;
    3673           93 :   return dump_cselib_val (v, out);
    3674              : }
    3675              : 
    3676              : /* Dump to OUT everything in the CSELIB table.  */
    3677              : 
    3678              : void
    3679           11 : dump_cselib_table (FILE *out)
    3680              : {
    3681           11 :   fprintf (out, "cselib hash table:\n");
    3682          104 :   cselib_hash_table->traverse <FILE *, dump_cselib_val_ptr> (out);
    3683           11 :   if (cselib_preserved_hash_table)
    3684              :     {
    3685           11 :       fprintf (out, "cselib preserved hash table:\n");
    3686           11 :       cselib_preserved_hash_table->traverse <FILE *, dump_cselib_val_ptr> (out);
    3687              :     }
    3688           11 :   if (first_containing_mem != &dummy_val)
    3689              :     {
    3690            6 :       fputs ("first mem ", out);
    3691            6 :       print_inline_rtx (out, first_containing_mem->val_rtx, 2);
    3692            6 :       fputc ('\n', out);
    3693              :     }
    3694           11 :   fprintf (out, "next uid %i\n", next_uid);
    3695           11 : }
    3696              : 
    3697              : #include "gt-cselib.h"
        

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