LCOV - code coverage report
Current view: top level - gcc - cse.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 91.5 % 3149 2881
Test Date: 2026-12-05 16:10:02 Functions: 92.6 % 95 88
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Common subexpression elimination 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 "stmt.h"
      27              : #include "tree.h"
      28              : #include "cfghooks.h"
      29              : #include "df.h"
      30              : #include "memmodel.h"
      31              : #include "tm_p.h"
      32              : #include "insn-config.h"
      33              : #include "regs.h"
      34              : #include "emit-rtl.h"
      35              : #include "recog.h"
      36              : #include "cfgrtl.h"
      37              : #include "cfganal.h"
      38              : #include "cfgcleanup.h"
      39              : #include "alias.h"
      40              : #include "toplev.h"
      41              : #include "rtlhooks-def.h"
      42              : #include "tree-pass.h"
      43              : #include "dbgcnt.h"
      44              : #include "rtl-iter.h"
      45              : #include "function-abi.h"
      46              : #include "rtlanal.h"
      47              : #include "expr.h"
      48              : 
      49              : /* The basic idea of common subexpression elimination is to go
      50              :    through the code, keeping a record of expressions that would
      51              :    have the same value at the current scan point, and replacing
      52              :    expressions encountered with the cheapest equivalent expression.
      53              : 
      54              :    It is too complicated to keep track of the different possibilities
      55              :    when control paths merge in this code; so, at each label, we forget all
      56              :    that is known and start fresh.  This can be described as processing each
      57              :    extended basic block separately.  We have a separate pass to perform
      58              :    global CSE.
      59              : 
      60              :    Note CSE can turn a conditional or computed jump into a nop or
      61              :    an unconditional jump.  When this occurs we arrange to run the jump
      62              :    optimizer after CSE to delete the unreachable code.
      63              : 
      64              :    We use two data structures to record the equivalent expressions:
      65              :    a hash table for most expressions, and a vector of "quantity
      66              :    numbers" to record equivalent (pseudo) registers.
      67              : 
      68              :    The use of the special data structure for registers is desirable
      69              :    because it is faster.  It is possible because registers references
      70              :    contain a fairly small number, the register number, taken from
      71              :    a contiguously allocated series, and two register references are
      72              :    identical if they have the same number.  General expressions
      73              :    do not have any such thing, so the only way to retrieve the
      74              :    information recorded on an expression other than a register
      75              :    is to keep it in a hash table.
      76              : 
      77              : Registers and "quantity numbers":
      78              : 
      79              :    At the start of each basic block, all of the (hardware and pseudo)
      80              :    registers used in the function are given distinct quantity
      81              :    numbers to indicate their contents.  During scan, when the code
      82              :    copies one register into another, we copy the quantity number.
      83              :    When a register is loaded in any other way, we allocate a new
      84              :    quantity number to describe the value generated by this operation.
      85              :    `REG_QTY (N)' records what quantity register N is currently thought
      86              :    of as containing.
      87              : 
      88              :    All real quantity numbers are greater than or equal to zero.
      89              :    If register N has not been assigned a quantity, `REG_QTY (N)' will
      90              :    equal -N - 1, which is always negative.
      91              : 
      92              :    Quantity numbers below zero do not exist and none of the `qty_table'
      93              :    entries should be referenced with a negative index.
      94              : 
      95              :    We also maintain a bidirectional chain of registers for each
      96              :    quantity number.  The `qty_table` members `first_reg' and `last_reg',
      97              :    and `reg_eqv_table' members `next' and `prev' hold these chains.
      98              : 
      99              :    The first register in a chain is the one whose lifespan is least local.
     100              :    Among equals, it is the one that was seen first.
     101              :    We replace any equivalent register with that one.
     102              : 
     103              :    If two registers have the same quantity number, it must be true that
     104              :    REG expressions with qty_table `mode' must be in the hash table for both
     105              :    registers and must be in the same class.
     106              : 
     107              :    The converse is not true.  Since hard registers may be referenced in
     108              :    any mode, two REG expressions might be equivalent in the hash table
     109              :    but not have the same quantity number if the quantity number of one
     110              :    of the registers is not the same mode as those expressions.
     111              : 
     112              : Constants and quantity numbers
     113              : 
     114              :    When a quantity has a known constant value, that value is stored
     115              :    in the appropriate qty_table `const_rtx'.  This is in addition to
     116              :    putting the constant in the hash table as is usual for non-regs.
     117              : 
     118              :    Whether a reg or a constant is preferred is determined by the configuration
     119              :    macro CONST_COSTS and will often depend on the constant value.  In any
     120              :    event, expressions containing constants can be simplified, by fold_rtx.
     121              : 
     122              :    When a quantity has a known nearly constant value (such as an address
     123              :    of a stack slot), that value is stored in the appropriate qty_table
     124              :    `const_rtx'.
     125              : 
     126              :    Integer constants don't have a machine mode.  However, cse
     127              :    determines the intended machine mode from the destination
     128              :    of the instruction that moves the constant.  The machine mode
     129              :    is recorded in the hash table along with the actual RTL
     130              :    constant expression so that different modes are kept separate.
     131              : 
     132              : Other expressions:
     133              : 
     134              :    To record known equivalences among expressions in general
     135              :    we use a hash table called `table'.  It has a fixed number of buckets
     136              :    that contain chains of `struct table_elt' elements for expressions.
     137              :    These chains connect the elements whose expressions have the same
     138              :    hash codes.
     139              : 
     140              :    Other chains through the same elements connect the elements which
     141              :    currently have equivalent values.
     142              : 
     143              :    Register references in an expression are canonicalized before hashing
     144              :    the expression.  This is done using `reg_qty' and qty_table `first_reg'.
     145              :    The hash code of a register reference is computed using the quantity
     146              :    number, not the register number.
     147              : 
     148              :    When the value of an expression changes, it is necessary to remove from the
     149              :    hash table not just that expression but all expressions whose values
     150              :    could be different as a result.
     151              : 
     152              :      1. If the value changing is in memory, except in special cases
     153              :      ANYTHING referring to memory could be changed.  That is because
     154              :      nobody knows where a pointer does not point.
     155              :      The function `invalidate_memory' removes what is necessary.
     156              : 
     157              :      The special cases are when the address is constant or is
     158              :      a constant plus a fixed register such as the frame pointer
     159              :      or a static chain pointer.  When such addresses are stored in,
     160              :      we can tell exactly which other such addresses must be invalidated
     161              :      due to overlap.  `invalidate' does this.
     162              :      All expressions that refer to non-constant
     163              :      memory addresses are also invalidated.  `invalidate_memory' does this.
     164              : 
     165              :      2. If the value changing is a register, all expressions
     166              :      containing references to that register, and only those,
     167              :      must be removed.
     168              : 
     169              :    Because searching the entire hash table for expressions that contain
     170              :    a register is very slow, we try to figure out when it isn't necessary.
     171              :    Precisely, this is necessary only when expressions have been
     172              :    entered in the hash table using this register, and then the value has
     173              :    changed, and then another expression wants to be added to refer to
     174              :    the register's new value.  This sequence of circumstances is rare
     175              :    within any one basic block.
     176              : 
     177              :    `REG_TICK' and `REG_IN_TABLE', accessors for members of
     178              :    cse_reg_info, are used to detect this case.  REG_TICK (i) is
     179              :    incremented whenever a value is stored in register i.
     180              :    REG_IN_TABLE (i) holds -1 if no references to register i have been
     181              :    entered in the table; otherwise, it contains the value REG_TICK (i)
     182              :    had when the references were entered.  If we want to enter a
     183              :    reference and REG_IN_TABLE (i) != REG_TICK (i), we must scan and
     184              :    remove old references.  Until we want to enter a new entry, the
     185              :    mere fact that the two vectors don't match makes the entries be
     186              :    ignored if anyone tries to match them.
     187              : 
     188              :    Registers themselves are entered in the hash table as well as in
     189              :    the equivalent-register chains.  However, `REG_TICK' and
     190              :    `REG_IN_TABLE' do not apply to expressions which are simple
     191              :    register references.  These expressions are removed from the table
     192              :    immediately when they become invalid, and this can be done even if
     193              :    we do not immediately search for all the expressions that refer to
     194              :    the register.
     195              : 
     196              :    A CLOBBER rtx in an instruction invalidates its operand for further
     197              :    reuse.  A CLOBBER or SET rtx whose operand is a MEM:BLK
     198              :    invalidates everything that resides in memory.
     199              : 
     200              : Related expressions:
     201              : 
     202              :    Constant expressions that differ only by an additive integer
     203              :    are called related.  When a constant expression is put in
     204              :    the table, the related expression with no constant term
     205              :    is also entered.  These are made to point at each other
     206              :    so that it is possible to find out if there exists any
     207              :    register equivalent to an expression related to a given expression.  */
     208              : 
     209              : /* Length of qty_table vector.  We know in advance we will not need
     210              :    a quantity number this big.  */
     211              : 
     212              : static int max_qty;
     213              : 
     214              : /* Next quantity number to be allocated.
     215              :    This is 1 + the largest number needed so far.  */
     216              : 
     217              : static int next_qty;
     218              : 
     219              : /* Per-qty information tracking.
     220              : 
     221              :    `first_reg' and `last_reg' track the head and tail of the
     222              :    chain of registers which currently contain this quantity.
     223              : 
     224              :    `mode' contains the machine mode of this quantity.
     225              : 
     226              :    `const_rtx' holds the rtx of the constant value of this
     227              :    quantity, if known.  A summations of the frame/arg pointer
     228              :    and a constant can also be entered here.  When this holds
     229              :    a known value, `const_insn' is the insn which stored the
     230              :    constant value.
     231              : 
     232              :    `comparison_{code,const,qty}' are used to track when a
     233              :    comparison between a quantity and some constant or register has
     234              :    been passed.  In such a case, we know the results of the comparison
     235              :    in case we see it again.  These members record a comparison that
     236              :    is known to be true.  `comparison_code' holds the rtx code of such
     237              :    a comparison, else it is set to UNKNOWN and the other two
     238              :    comparison members are undefined.  `comparison_const' holds
     239              :    the constant being compared against, or zero if the comparison
     240              :    is not against a constant.  `comparison_qty' holds the quantity
     241              :    being compared against when the result is known.  If the comparison
     242              :    is not with a register, `comparison_qty' is INT_MIN.  */
     243              : 
     244              : struct qty_table_elem
     245              : {
     246              :   rtx const_rtx;
     247              :   rtx_insn *const_insn;
     248              :   rtx comparison_const;
     249              :   int comparison_qty;
     250              :   unsigned int first_reg, last_reg;
     251              :   machine_mode mode : MACHINE_MODE_BITSIZE;
     252              :   enum rtx_code comparison_code : RTX_CODE_BITSIZE;
     253              : };
     254              : 
     255              : /* The table of all qtys, indexed by qty number.  */
     256              : static struct qty_table_elem *qty_table;
     257              : 
     258              : /* Insn being scanned.  */
     259              : 
     260              : static rtx_insn *this_insn;
     261              : static bool optimize_this_for_speed_p;
     262              : 
     263              : /* Index by register number, gives the number of the next (or
     264              :    previous) register in the chain of registers sharing the same
     265              :    value.
     266              : 
     267              :    Or -1 if this register is at the end of the chain.
     268              : 
     269              :    If REG_QTY (N) == -N - 1, reg_eqv_table[N].next is undefined.  */
     270              : 
     271              : /* Per-register equivalence chain.  */
     272              : struct reg_eqv_elem
     273              : {
     274              :   int next, prev;
     275              : };
     276              : 
     277              : /* The table of all register equivalence chains.  */
     278              : static struct reg_eqv_elem *reg_eqv_table;
     279              : 
     280              : struct cse_reg_info
     281              : {
     282              :   /* The timestamp at which this register is initialized.  */
     283              :   unsigned int timestamp;
     284              : 
     285              :   /* The quantity number of the register's current contents.  */
     286              :   int reg_qty;
     287              : 
     288              :   /* The number of times the register has been altered in the current
     289              :      basic block.  */
     290              :   int reg_tick;
     291              : 
     292              :   /* The REG_TICK value at which rtx's containing this register are
     293              :      valid in the hash table.  If this does not equal the current
     294              :      reg_tick value, such expressions existing in the hash table are
     295              :      invalid.  */
     296              :   int reg_in_table;
     297              : 
     298              :   /* The SUBREG that was set when REG_TICK was last incremented.  Set
     299              :      to -1 if the last store was to the whole register, not a subreg.  */
     300              :   unsigned int subreg_ticked;
     301              : };
     302              : 
     303              : /* A table of cse_reg_info indexed by register numbers.  */
     304              : static struct cse_reg_info *cse_reg_info_table;
     305              : 
     306              : /* The size of the above table.  */
     307              : static unsigned int cse_reg_info_table_size;
     308              : 
     309              : /* The index of the first entry that has not been initialized.  */
     310              : static unsigned int cse_reg_info_table_first_uninitialized;
     311              : 
     312              : /* The timestamp at the beginning of the current run of
     313              :    cse_extended_basic_block.  We increment this variable at the beginning of
     314              :    the current run of cse_extended_basic_block.  The timestamp field of a
     315              :    cse_reg_info entry matches the value of this variable if and only
     316              :    if the entry has been initialized during the current run of
     317              :    cse_extended_basic_block.  */
     318              : static unsigned int cse_reg_info_timestamp;
     319              : 
     320              : /* A HARD_REG_SET containing all the hard registers for which there is
     321              :    currently a REG expression in the hash table.  Note the difference
     322              :    from the above variables, which indicate if the REG is mentioned in some
     323              :    expression in the table.  */
     324              : 
     325              : static HARD_REG_SET hard_regs_in_table;
     326              : 
     327              : /* True if CSE has altered the CFG.  */
     328              : static bool cse_cfg_altered;
     329              : 
     330              : /* True if CSE has altered conditional jump insns in such a way
     331              :    that jump optimization should be redone.  */
     332              : static bool cse_jumps_altered;
     333              : 
     334              : /* True if we put a LABEL_REF into the hash table for an INSN
     335              :    without a REG_LABEL_OPERAND, we have to rerun jump after CSE
     336              :    to put in the note.  */
     337              : static bool recorded_label_ref;
     338              : 
     339              : /* canon_hash stores 1 in do_not_record if it notices a reference to PC or
     340              :    some other volatile subexpression.  */
     341              : 
     342              : static int do_not_record;
     343              : 
     344              : /* canon_hash stores 1 in hash_arg_in_memory
     345              :    if it notices a reference to memory within the expression being hashed.  */
     346              : 
     347              : static int hash_arg_in_memory;
     348              : 
     349              : /* The hash table contains buckets which are chains of `struct table_elt's,
     350              :    each recording one expression's information.
     351              :    That expression is in the `exp' field.
     352              : 
     353              :    The canon_exp field contains a canonical (from the point of view of
     354              :    alias analysis) version of the `exp' field.
     355              : 
     356              :    Those elements with the same hash code are chained in both directions
     357              :    through the `next_same_hash' and `prev_same_hash' fields.
     358              : 
     359              :    Each set of expressions with equivalent values
     360              :    are on a two-way chain through the `next_same_value'
     361              :    and `prev_same_value' fields, and all point with
     362              :    the `first_same_value' field at the first element in
     363              :    that chain.  The chain is in order of increasing cost.
     364              :    Each element's cost value is in its `cost' field.
     365              : 
     366              :    The `in_memory' field is nonzero for elements that
     367              :    involve any reference to memory.  These elements are removed
     368              :    whenever a write is done to an unidentified location in memory.
     369              :    To be safe, we assume that a memory address is unidentified unless
     370              :    the address is either a symbol constant or a constant plus
     371              :    the frame pointer or argument pointer.
     372              : 
     373              :    The `related_value' field is used to connect related expressions
     374              :    (that differ by adding an integer).
     375              :    The related expressions are chained in a circular fashion.
     376              :    `related_value' is zero for expressions for which this
     377              :    chain is not useful.
     378              : 
     379              :    The `cost' field stores the cost of this element's expression.
     380              :    The `regcost' field stores the value returned by approx_reg_cost for
     381              :    this element's expression.
     382              : 
     383              :    The `is_const' flag is set if the element is a constant (including
     384              :    a fixed address).
     385              : 
     386              :    The `flag' field is used as a temporary during some search routines.
     387              : 
     388              :    The `mode' field is usually the same as GET_MODE (`exp'), but
     389              :    if `exp' is a CONST_INT and has no machine mode then the `mode'
     390              :    field is the mode it was being used as.  Each constant is
     391              :    recorded separately for each mode it is used with.  */
     392              : 
     393              : struct table_elt
     394              : {
     395              :   rtx exp;
     396              :   rtx canon_exp;
     397              :   struct table_elt *next_same_hash;
     398              :   struct table_elt *prev_same_hash;
     399              :   struct table_elt *next_same_value;
     400              :   struct table_elt *prev_same_value;
     401              :   struct table_elt *first_same_value;
     402              :   struct table_elt *related_value;
     403              :   int cost;
     404              :   int regcost;
     405              :   machine_mode mode : MACHINE_MODE_BITSIZE;
     406              :   char in_memory;
     407              :   char is_const;
     408              :   char flag;
     409              : };
     410              : 
     411              : /* We don't want a lot of buckets, because we rarely have very many
     412              :    things stored in the hash table, and a lot of buckets slows
     413              :    down a lot of loops that happen frequently.  */
     414              : #define HASH_SHIFT      5
     415              : #define HASH_SIZE       (1 << HASH_SHIFT)
     416              : #define HASH_MASK       (HASH_SIZE - 1)
     417              : 
     418              : /* Determine whether register number N is considered a fixed register for the
     419              :    purpose of approximating register costs.
     420              :    It is desirable to replace other regs with fixed regs, to reduce need for
     421              :    non-fixed hard regs.
     422              :    A reg wins if it is either the frame pointer or designated as fixed.  */
     423              : #define FIXED_REGNO_P(N)  \
     424              :   ((N) == FRAME_POINTER_REGNUM || (N) == HARD_FRAME_POINTER_REGNUM \
     425              :    || fixed_regs[N] || global_regs[N])
     426              : 
     427              : /* Compute cost of X, as stored in the `cost' field of a table_elt.  Fixed
     428              :    hard registers and pointers into the frame are the cheapest with a cost
     429              :    of 0.  Next come pseudos with a cost of one and other hard registers with
     430              :    a cost of 2.  Aside from these special cases, call `rtx_cost'.  */
     431              : 
     432              : #define CHEAP_REGNO(N)                                                  \
     433              :   (REGNO_PTR_FRAME_P (N)                                                \
     434              :    || (HARD_REGISTER_NUM_P (N)                                          \
     435              :        && FIXED_REGNO_P (N) && REGNO_REG_CLASS (N) != NO_REGS))
     436              : 
     437              : #define COST(X, MODE)                                                   \
     438              :   (REG_P (X) ? 0 : notreg_cost (X, MODE, SET, 1))
     439              : #define COST_IN(X, MODE, OUTER, OPNO)                                   \
     440              :   (REG_P (X) ? 0 : notreg_cost (X, MODE, OUTER, OPNO))
     441              : 
     442              : /* Get the number of times this register has been updated in this
     443              :    basic block.  */
     444              : 
     445              : #define REG_TICK(N) (get_cse_reg_info (N)->reg_tick)
     446              : 
     447              : /* Get the point at which REG was recorded in the table.  */
     448              : 
     449              : #define REG_IN_TABLE(N) (get_cse_reg_info (N)->reg_in_table)
     450              : 
     451              : /* Get the SUBREG set at the last increment to REG_TICK (-1 if not a
     452              :    SUBREG).  */
     453              : 
     454              : #define SUBREG_TICKED(N) (get_cse_reg_info (N)->subreg_ticked)
     455              : 
     456              : /* Get the quantity number for REG.  */
     457              : 
     458              : #define REG_QTY(N) (get_cse_reg_info (N)->reg_qty)
     459              : 
     460              : /* Determine if the quantity number for register X represents a valid index
     461              :    into the qty_table.  */
     462              : 
     463              : #define REGNO_QTY_VALID_P(N) (REG_QTY (N) >= 0)
     464              : 
     465              : /* Compare table_elt X and Y and return true iff X is cheaper than Y.  */
     466              : 
     467              : #define CHEAPER(X, Y) \
     468              :  (preferable ((X)->cost, (X)->regcost, (Y)->cost, (Y)->regcost) < 0)
     469              : 
     470              : static struct table_elt *table[HASH_SIZE];
     471              : 
     472              : /* Chain of `struct table_elt's made so far for this function
     473              :    but currently removed from the table.  */
     474              : 
     475              : static struct table_elt *free_element_chain;
     476              : 
     477              : /* Trace a patch through the CFG.  */
     478              : 
     479              : struct branch_path
     480              : {
     481              :   /* The basic block for this path entry.  */
     482              :   basic_block bb;
     483              : };
     484              : 
     485              : /* This data describes a pair of vec_duplicates in the same BB, which duplicate
     486              :    the same pseudo to different vector lengths.  The same structure is also
     487              :    used while prescanning a basic block as a temporary cache entry.  */
     488              : 
     489       350893 : struct cse_vec_duplicate_match
     490              : {
     491              :   basic_block bb;
     492              :   machine_mode widest_mode;
     493              :   rtx scalar;
     494              :   rtx_insn *first_insn;
     495              :   rtx_insn *widest_insn;
     496              :   rtx_insn *last_checked_insn;
     497              :   auto_vec<rtx_insn *> related_dups;
     498              : 
     499       350827 :   cse_vec_duplicate_match (basic_block bb_, machine_mode widest_mode_,
     500              :                            rtx scalar_, rtx_insn *first_insn_,
     501              :                            rtx_insn *widest_insn_,
     502              :                            rtx_insn *last_checked_insn_)
     503       350827 :     : bb (bb_), widest_mode (widest_mode_), scalar (scalar_),
     504       350827 :       first_insn (first_insn_), widest_insn (widest_insn_),
     505       350827 :       last_checked_insn (last_checked_insn_)
     506              :   {}
     507              : 
     508       354901 :   cse_vec_duplicate_match (const cse_vec_duplicate_match &other)
     509       354901 :     : bb (other.bb), widest_mode (other.widest_mode), scalar (other.scalar),
     510       354901 :       first_insn (other.first_insn), widest_insn (other.widest_insn),
     511       354901 :       last_checked_insn (other.last_checked_insn)
     512              :   {
     513       709802 :     related_dups.reserve (other.related_dups.length ());
     514       354901 :     related_dups.splice (other.related_dups);
     515       354901 :   }
     516              : };
     517              : 
     518              : /* This data describes a block that will be processed by
     519              :    cse_extended_basic_block.  */
     520              : 
     521      2358258 : struct cse_basic_block_data
     522              : {
     523              :   /* Total number of SETs in block.  */
     524              :   int nsets;
     525              :   /* Size of current branch path, if any.  */
     526              :   int path_size;
     527              :   /* Current path, indicating which basic_blocks will be processed.  */
     528              :   struct branch_path *path;
     529              :   /* vec_duplicate sources seen in the current BB while prescanning.  */
     530              :   auto_vec<cse_vec_duplicate_match, 8> vec_duplicate_cache;
     531              :   /* Syntactic vec_duplicate matches found in the same BB while prescanning.  */
     532              :   auto_vec<cse_vec_duplicate_match, 8> vec_duplicate_matches;
     533              : };
     534              : 
     535              : 
     536              : /* Pointers to the live in/live out bitmaps for the boundaries of the
     537              :    current EBB.  */
     538              : static bitmap cse_ebb_live_in, cse_ebb_live_out;
     539              : 
     540              : /* A simple bitmap to track which basic blocks have been visited
     541              :    already as part of an already processed extended basic block.  */
     542              : static sbitmap cse_visited_basic_blocks;
     543              : 
     544              : static bool fixed_base_plus_p (rtx x);
     545              : static int notreg_cost (rtx, machine_mode, enum rtx_code, int);
     546              : static int preferable (int, int, int, int);
     547              : static void new_basic_block (void);
     548              : static void make_new_qty (unsigned int, machine_mode);
     549              : static void make_regs_eqv (unsigned int, unsigned int);
     550              : static void delete_reg_equiv (unsigned int);
     551              : static bool mention_regs (rtx);
     552              : static bool insert_regs (rtx, struct table_elt *, bool);
     553              : static void remove_from_table (struct table_elt *, unsigned);
     554              : static void remove_pseudo_from_table (rtx, unsigned);
     555              : static struct table_elt *lookup (rtx, unsigned, machine_mode);
     556              : static struct table_elt *lookup_for_remove (rtx, unsigned, machine_mode);
     557              : static rtx lookup_as_function (rtx, enum rtx_code);
     558              : static struct table_elt *insert_with_costs (rtx, struct table_elt *, unsigned,
     559              :                                             machine_mode, int, int);
     560              : static struct table_elt *insert (rtx, struct table_elt *, unsigned,
     561              :                                  machine_mode);
     562              : static void merge_equiv_classes (struct table_elt *, struct table_elt *);
     563              : static void invalidate (rtx, machine_mode);
     564              : static void remove_invalid_refs (unsigned int);
     565              : static void remove_invalid_subreg_refs (unsigned int, poly_uint64,
     566              :                                         machine_mode);
     567              : static void rehash_using_reg (rtx);
     568              : static void invalidate_memory (void);
     569              : static rtx use_related_value (rtx, struct table_elt *);
     570              : 
     571              : static inline unsigned canon_hash (rtx, machine_mode);
     572              : static inline unsigned safe_hash (rtx, machine_mode);
     573              : static inline unsigned hash_rtx_string (const char *);
     574              : 
     575              : static rtx canon_reg (rtx, rtx_insn *);
     576              : static enum rtx_code find_comparison_args (enum rtx_code, rtx *, rtx *,
     577              :                                            machine_mode *,
     578              :                                            machine_mode *);
     579              : static rtx fold_rtx (rtx, rtx_insn *);
     580              : static rtx equiv_constant (rtx);
     581              : static void record_jump_equiv (rtx_insn *, bool);
     582              : static void record_jump_cond (enum rtx_code, machine_mode, rtx, rtx);
     583              : static void cse_insn (rtx_insn *);
     584              : static void cse_prescan_cache_vec_dup (struct cse_basic_block_data *,
     585              :                                        basic_block, rtx_insn *, rtx);
     586              : static void cse_prescan_path (struct cse_basic_block_data *);
     587              : static void invalidate_from_clobbers (rtx_insn *);
     588              : static void invalidate_from_sets_and_clobbers (rtx_insn *);
     589              : static void cse_extended_basic_block (struct cse_basic_block_data *);
     590              : extern void dump_class (struct table_elt*);
     591              : static void get_cse_reg_info_1 (unsigned int regno);
     592              : static struct cse_reg_info * get_cse_reg_info (unsigned int regno);
     593              : 
     594              : static void flush_hash_table (void);
     595              : static bool insn_live_p (rtx_insn *, int *);
     596              : static bool set_live_p (rtx, int *);
     597              : static void cse_change_cc_mode_insn (rtx_insn *, rtx);
     598              : static void cse_change_cc_mode_insns (rtx_insn *, rtx_insn *, rtx);
     599              : static machine_mode cse_cc_succs (basic_block, basic_block, rtx, rtx,
     600              :                                        bool);
     601              : 
     602              : 
     603              : #undef RTL_HOOKS_GEN_LOWPART
     604              : #define RTL_HOOKS_GEN_LOWPART           gen_lowpart_if_possible
     605              : 
     606              : static const struct rtl_hooks cse_rtl_hooks = RTL_HOOKS_INITIALIZER;
     607              : 
     608              : /* Compute hash code of X in mode M.  Special-case case where X is a pseudo
     609              :    register (hard registers may require `do_not_record' to be set).  */
     610              : 
     611              : static inline unsigned
     612    864444000 : HASH (rtx x, machine_mode mode)
     613              : {
     614    561239363 :   unsigned h = (REG_P (x) && REGNO (x) >= FIRST_PSEUDO_REGISTER
     615   1199212792 :                 ? (((unsigned) REG << 7) + (unsigned) REG_QTY (REGNO (x)))
     616    864444000 :                 : canon_hash (x, mode));
     617    864444000 :   return (h ^ (h >> HASH_SHIFT)) & HASH_MASK;
     618              : }
     619              : 
     620              : /* Like HASH, but without side-effects.  */
     621              : 
     622              : static inline unsigned
     623    238351027 : SAFE_HASH (rtx x, machine_mode mode)
     624              : {
     625    119433795 :   unsigned h = (REG_P (x) && REGNO (x) >= FIRST_PSEUDO_REGISTER
     626    305810390 :                 ? (((unsigned) REG << 7) + (unsigned) REG_QTY (REGNO (x)))
     627    238351027 :                 : safe_hash (x, mode));
     628    238351027 :   return (h ^ (h >> HASH_SHIFT)) & HASH_MASK;
     629              : }
     630              : 
     631              : /* Nonzero if X has the form (PLUS frame-pointer integer).  */
     632              : 
     633              : static bool
     634    245201806 : fixed_base_plus_p (rtx x)
     635              : {
     636    278090179 :   switch (GET_CODE (x))
     637              :     {
     638    144954920 :     case REG:
     639    144954920 :       if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx)
     640              :         return true;
     641    130312488 :       if (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM])
     642       118197 :         return true;
     643              :       return false;
     644              : 
     645     39408909 :     case PLUS:
     646     39408909 :       if (!CONST_INT_P (XEXP (x, 1)))
     647              :         return false;
     648     32888373 :       return fixed_base_plus_p (XEXP (x, 0));
     649              : 
     650              :     default:
     651              :       return false;
     652              :     }
     653              : }
     654              : 
     655              : /* Dump the expressions in the equivalence class indicated by CLASSP.
     656              :    This function is used only for debugging.  */
     657              : DEBUG_FUNCTION void
     658            0 : dump_class (struct table_elt *classp)
     659              : {
     660            0 :   struct table_elt *elt;
     661              : 
     662            0 :   fprintf (stderr, "Equivalence chain for ");
     663            0 :   print_rtl (stderr, classp->exp);
     664            0 :   fprintf (stderr, ": \n");
     665              : 
     666            0 :   for (elt = classp->first_same_value; elt; elt = elt->next_same_value)
     667              :     {
     668            0 :       print_rtl (stderr, elt->exp);
     669            0 :       fprintf (stderr, "\n");
     670              :     }
     671            0 : }
     672              : 
     673              : /* Return an estimate of the cost of the registers used in an rtx.
     674              :    This is mostly the number of different REG expressions in the rtx;
     675              :    however for some exceptions like fixed registers we use a cost of
     676              :    0.  If any other hard register reference occurs, return MAX_COST.  */
     677              : 
     678              : static int
     679    447950150 : approx_reg_cost (const_rtx x)
     680              : {
     681    447950150 :   int cost = 0;
     682    447950150 :   subrtx_iterator::array_type array;
     683   1413396630 :   FOR_EACH_SUBRTX (iter, array, x, NONCONST)
     684              :     {
     685   1023205644 :       const_rtx x = *iter;
     686   1023205644 :       if (REG_P (x))
     687              :         {
     688    424114885 :           unsigned int regno = REGNO (x);
     689    424114885 :           if (!CHEAP_REGNO (regno))
     690              :             {
     691     57759164 :               if (regno < FIRST_PSEUDO_REGISTER)
     692              :                 {
     693     57759164 :                   if (targetm.small_register_classes_for_mode_p (GET_MODE (x)))
     694     57759164 :                     return MAX_COST;
     695            0 :                   cost += 2;
     696              :                 }
     697              :               else
     698    302060344 :                 cost += 1;
     699              :             }
     700              :         }
     701              :     }
     702    390190986 :   return cost;
     703    447950150 : }
     704              : 
     705              : /* Return a negative value if an rtx A, whose costs are given by COST_A
     706              :    and REGCOST_A, is more desirable than an rtx B.
     707              :    Return a positive value if A is less desirable, or 0 if the two are
     708              :    equally good.  */
     709              : static int
     710    680543985 : preferable (int cost_a, int regcost_a, int cost_b, int regcost_b)
     711              : {
     712              :   /* First, get rid of cases involving expressions that are entirely
     713              :      unwanted.  */
     714    680543985 :   if (cost_a != cost_b)
     715              :     {
     716    636322487 :       if (cost_a == MAX_COST)
     717              :         return 1;
     718    634904224 :       if (cost_b == MAX_COST)
     719              :         return -1;
     720              :     }
     721              : 
     722              :   /* Avoid extending lifetimes of hardregs.  */
     723    179016397 :   if (regcost_a != regcost_b)
     724              :     {
     725     97774304 :       if (regcost_a == MAX_COST)
     726              :         return 1;
     727     75943682 :       if (regcost_b == MAX_COST)
     728              :         return -1;
     729              :     }
     730              : 
     731              :   /* Normal operation costs take precedence.  */
     732    155074806 :   if (cost_a != cost_b)
     733    110982253 :     return cost_a - cost_b;
     734              :   /* Only if these are identical consider effects on register pressure.  */
     735     44092553 :   if (regcost_a != regcost_b)
     736     44092553 :     return regcost_a - regcost_b;
     737              :   return 0;
     738              : }
     739              : 
     740              : /* Internal function, to compute cost when X is not a register; called
     741              :    from COST macro to keep it simple.  */
     742              : 
     743              : static int
     744    315717880 : notreg_cost (rtx x, machine_mode mode, enum rtx_code outer, int opno)
     745              : {
     746    315717880 :   scalar_int_mode int_mode, inner_mode;
     747    315717880 :   return ((GET_CODE (x) == SUBREG
     748      5602390 :            && REG_P (SUBREG_REG (x))
     749    317912473 :            && is_int_mode (mode, &int_mode)
     750    317014841 :            && is_int_mode (GET_MODE (SUBREG_REG (x)), &inner_mode)
     751      7876416 :            && GET_MODE_SIZE (int_mode) < GET_MODE_SIZE (inner_mode)
     752      3886998 :            && subreg_lowpart_p (x)
     753      2641247 :            && TRULY_NOOP_TRUNCATION_MODES_P (int_mode, inner_mode))
     754    315717880 :           ? 0
     755    313076633 :           : rtx_cost (x, mode, outer, opno, optimize_this_for_speed_p) * 2);
     756              : }
     757              : 
     758              : 
     759              : /* Initialize CSE_REG_INFO_TABLE.  */
     760              : 
     761              : static void
     762      2358258 : init_cse_reg_info (unsigned int nregs)
     763              : {
     764              :   /* Do we need to grow the table?  */
     765      2358258 :   if (nregs > cse_reg_info_table_size)
     766              :     {
     767       184044 :       unsigned int new_size;
     768              : 
     769       184044 :       if (cse_reg_info_table_size < 2048)
     770              :         {
     771              :           /* Compute a new size that is a power of 2 and no smaller
     772              :              than the large of NREGS and 64.  */
     773       183702 :           new_size = (cse_reg_info_table_size
     774       183702 :                       ? cse_reg_info_table_size : 64);
     775              : 
     776       409640 :           while (new_size < nregs)
     777       225938 :             new_size *= 2;
     778              :         }
     779              :       else
     780              :         {
     781              :           /* If we need a big table, allocate just enough to hold
     782              :              NREGS registers.  */
     783              :           new_size = nregs;
     784              :         }
     785              : 
     786              :       /* Reallocate the table with NEW_SIZE entries.  */
     787       184044 :       free (cse_reg_info_table);
     788       184044 :       cse_reg_info_table = XNEWVEC (struct cse_reg_info, new_size);
     789       184044 :       cse_reg_info_table_size = new_size;
     790       184044 :       cse_reg_info_table_first_uninitialized = 0;
     791              :     }
     792              : 
     793              :   /* Do we have all of the first NREGS entries initialized?  */
     794      2358258 :   if (cse_reg_info_table_first_uninitialized < nregs)
     795              :     {
     796       336378 :       unsigned int old_timestamp = cse_reg_info_timestamp - 1;
     797       336378 :       unsigned int i;
     798              : 
     799              :       /* Put the old timestamp on newly allocated entries so that they
     800              :          will all be considered out of date.  We do not touch those
     801              :          entries beyond the first NREGS entries to be nice to the
     802              :          virtual memory.  */
     803     34935581 :       for (i = cse_reg_info_table_first_uninitialized; i < nregs; i++)
     804     34599203 :         cse_reg_info_table[i].timestamp = old_timestamp;
     805              : 
     806       336378 :       cse_reg_info_table_first_uninitialized = nregs;
     807              :     }
     808      2358258 : }
     809              : 
     810              : /* Given REGNO, initialize the cse_reg_info entry for REGNO.  */
     811              : 
     812              : static void
     813    899363817 : get_cse_reg_info_1 (unsigned int regno)
     814              : {
     815              :   /* Set TIMESTAMP field to CSE_REG_INFO_TIMESTAMP so that this
     816              :      entry will be considered to have been initialized.  */
     817    899363817 :   cse_reg_info_table[regno].timestamp = cse_reg_info_timestamp;
     818              : 
     819              :   /* Initialize the rest of the entry.  */
     820    899363817 :   cse_reg_info_table[regno].reg_tick = 1;
     821    899363817 :   cse_reg_info_table[regno].reg_in_table = -1;
     822    899363817 :   cse_reg_info_table[regno].subreg_ticked = -1;
     823    899363817 :   cse_reg_info_table[regno].reg_qty = -regno - 1;
     824    899363817 : }
     825              : 
     826              : /* Find a cse_reg_info entry for REGNO.  */
     827              : 
     828              : static inline struct cse_reg_info *
     829  11655210661 : get_cse_reg_info (unsigned int regno)
     830              : {
     831  11655210661 :   struct cse_reg_info *p = &cse_reg_info_table[regno];
     832              : 
     833              :   /* If this entry has not been initialized, go ahead and initialize
     834              :      it.  */
     835  11655210661 :   if (p->timestamp != cse_reg_info_timestamp)
     836    899363817 :     get_cse_reg_info_1 (regno);
     837              : 
     838  11655210661 :   return p;
     839              : }
     840              : 
     841              : /* Clear the hash table and initialize each register with its own quantity,
     842              :    for a new basic block.  */
     843              : 
     844              : static void
     845     21286386 : new_basic_block (void)
     846              : {
     847     21286386 :   int i;
     848              : 
     849     21286386 :   next_qty = 0;
     850              : 
     851              :   /* Invalidate cse_reg_info_table.  */
     852     21286386 :   cse_reg_info_timestamp++;
     853              : 
     854              :   /* Clear out hash table state for this pass.  */
     855     21286386 :   CLEAR_HARD_REG_SET (hard_regs_in_table);
     856              : 
     857              :   /* The per-quantity values used to be initialized here, but it is
     858              :      much faster to initialize each as it is made in `make_new_qty'.  */
     859              : 
     860    702450738 :   for (i = 0; i < HASH_SIZE; i++)
     861              :     {
     862    681164352 :       struct table_elt *first;
     863              : 
     864    681164352 :       first = table[i];
     865    681164352 :       if (first != NULL)
     866              :         {
     867    140432160 :           struct table_elt *last = first;
     868              : 
     869    140432160 :           table[i] = NULL;
     870              : 
     871    199728710 :           while (last->next_same_hash != NULL)
     872              :             last = last->next_same_hash;
     873              : 
     874              :           /* Now relink this hash entire chain into
     875              :              the free element list.  */
     876              : 
     877    140432160 :           last->next_same_hash = free_element_chain;
     878    140432160 :           free_element_chain = first;
     879              :         }
     880              :     }
     881     21286386 : }
     882              : 
     883              : /* Say that register REG contains a quantity in mode MODE not in any
     884              :    register before and initialize that quantity.  */
     885              : 
     886              : static void
     887    107607829 : make_new_qty (unsigned int reg, machine_mode mode)
     888              : {
     889    107607829 :   int q;
     890    107607829 :   struct qty_table_elem *ent;
     891    107607829 :   struct reg_eqv_elem *eqv;
     892              : 
     893    107607829 :   gcc_assert (next_qty < max_qty);
     894              : 
     895    107607829 :   q = REG_QTY (reg) = next_qty++;
     896    107607829 :   ent = &qty_table[q];
     897    107607829 :   ent->first_reg = reg;
     898    107607829 :   ent->last_reg = reg;
     899    107607829 :   ent->mode = mode;
     900    107607829 :   ent->const_rtx = ent->const_insn = NULL;
     901    107607829 :   ent->comparison_code = UNKNOWN;
     902              : 
     903    107607829 :   eqv = &reg_eqv_table[reg];
     904    107607829 :   eqv->next = eqv->prev = -1;
     905    107607829 : }
     906              : 
     907              : /* Make reg NEW equivalent to reg OLD.
     908              :    OLD is not changing; NEW is.  */
     909              : 
     910              : static void
     911     12003565 : make_regs_eqv (unsigned int new_reg, unsigned int old_reg)
     912              : {
     913     12003565 :   unsigned int lastr, firstr;
     914     12003565 :   int q = REG_QTY (old_reg);
     915     12003565 :   struct qty_table_elem *ent;
     916              : 
     917     12003565 :   ent = &qty_table[q];
     918              : 
     919              :   /* Nothing should become eqv until it has a "non-invalid" qty number.  */
     920     12003565 :   gcc_assert (REGNO_QTY_VALID_P (old_reg));
     921              : 
     922     12003565 :   REG_QTY (new_reg) = q;
     923     12003565 :   firstr = ent->first_reg;
     924     12003565 :   lastr = ent->last_reg;
     925              : 
     926              :   /* Prefer fixed hard registers to anything.  Prefer pseudo regs to other
     927              :      hard regs.  Among pseudos, if NEW will live longer than any other reg
     928              :      of the same qty, and that is beyond the current basic block,
     929              :      make it the new canonical replacement for this qty.  */
     930       317939 :   if (! (firstr < FIRST_PSEUDO_REGISTER && FIXED_REGNO_P (firstr))
     931              :       /* Certain fixed registers might be of the class NO_REGS.  This means
     932              :          that not only can they not be allocated by the compiler, but
     933              :          they cannot be used in substitutions or canonicalizations
     934              :          either.  */
     935     11685626 :       && (new_reg >= FIRST_PSEUDO_REGISTER || REGNO_REG_CLASS (new_reg) != NO_REGS)
     936     12008675 :       && ((new_reg < FIRST_PSEUDO_REGISTER && FIXED_REGNO_P (new_reg))
     937     11680516 :           || (new_reg >= FIRST_PSEUDO_REGISTER
     938     11680516 :               && (firstr < FIRST_PSEUDO_REGISTER
     939     11680516 :                   || (bitmap_bit_p (cse_ebb_live_out, new_reg)
     940      3759807 :                       && !bitmap_bit_p (cse_ebb_live_out, firstr))
     941      9585526 :                   || (bitmap_bit_p (cse_ebb_live_in, new_reg)
     942       522587 :                       && !bitmap_bit_p (cse_ebb_live_in, firstr))))))
     943              :     {
     944      2203121 :       reg_eqv_table[firstr].prev = new_reg;
     945      2203121 :       reg_eqv_table[new_reg].next = firstr;
     946      2203121 :       reg_eqv_table[new_reg].prev = -1;
     947      2203121 :       ent->first_reg = new_reg;
     948              :     }
     949              :   else
     950              :     {
     951              :       /* If NEW is a hard reg (known to be non-fixed), insert at end.
     952              :          Otherwise, insert before any non-fixed hard regs that are at the
     953              :          end.  Registers of class NO_REGS cannot be used as an
     954              :          equivalent for anything.  */
     955       299034 :       while (lastr < FIRST_PSEUDO_REGISTER && reg_eqv_table[lastr].prev >= 0
     956            0 :              && (REGNO_REG_CLASS (lastr) == NO_REGS || ! FIXED_REGNO_P (lastr))
     957      9800444 :              && new_reg >= FIRST_PSEUDO_REGISTER)
     958            0 :         lastr = reg_eqv_table[lastr].prev;
     959      9800444 :       reg_eqv_table[new_reg].next = reg_eqv_table[lastr].next;
     960      9800444 :       if (reg_eqv_table[lastr].next >= 0)
     961            0 :         reg_eqv_table[reg_eqv_table[lastr].next].prev = new_reg;
     962              :       else
     963      9800444 :         qty_table[q].last_reg = new_reg;
     964      9800444 :       reg_eqv_table[lastr].next = new_reg;
     965      9800444 :       reg_eqv_table[new_reg].prev = lastr;
     966              :     }
     967     12003565 : }
     968              : 
     969              : /* Remove REG from its equivalence class.  */
     970              : 
     971              : static void
     972   1560235196 : delete_reg_equiv (unsigned int reg)
     973              : {
     974   1560235196 :   struct qty_table_elem *ent;
     975   1560235196 :   int q = REG_QTY (reg);
     976   1560235196 :   int p, n;
     977              : 
     978              :   /* If invalid, do nothing.  */
     979   1560235196 :   if (! REGNO_QTY_VALID_P (reg))
     980              :     return;
     981              : 
     982     19282633 :   ent = &qty_table[q];
     983              : 
     984     19282633 :   p = reg_eqv_table[reg].prev;
     985     19282633 :   n = reg_eqv_table[reg].next;
     986              : 
     987     19282633 :   if (n != -1)
     988       687981 :     reg_eqv_table[n].prev = p;
     989              :   else
     990     18594652 :     ent->last_reg = p;
     991     19282633 :   if (p != -1)
     992       697968 :     reg_eqv_table[p].next = n;
     993              :   else
     994     18584665 :     ent->first_reg = n;
     995              : 
     996     19282633 :   REG_QTY (reg) = -reg - 1;
     997              : }
     998              : 
     999              : /* Remove any invalid expressions from the hash table
    1000              :    that refer to any of the registers contained in expression X.
    1001              : 
    1002              :    Make sure that newly inserted references to those registers
    1003              :    as subexpressions will be considered valid.
    1004              : 
    1005              :    mention_regs is not called when a register itself
    1006              :    is being stored in the table.
    1007              : 
    1008              :    Return true if we have done something that may have changed
    1009              :    the hash code of X.  */
    1010              : 
    1011              : static bool
    1012    481417972 : mention_regs (rtx x)
    1013              : {
    1014    481417972 :   enum rtx_code code;
    1015    481417972 :   int i, j;
    1016    481417972 :   const char *fmt;
    1017    481417972 :   bool changed = false;
    1018              : 
    1019    481417972 :   if (x == 0)
    1020              :     return false;
    1021              : 
    1022    481417972 :   code = GET_CODE (x);
    1023    481417972 :   if (code == REG)
    1024              :     {
    1025    144983906 :       unsigned int regno = REGNO (x);
    1026    144983906 :       unsigned int endregno = END_REGNO (x);
    1027    144983906 :       unsigned int i;
    1028              : 
    1029    289967812 :       for (i = regno; i < endregno; i++)
    1030              :         {
    1031    144983906 :           if (REG_IN_TABLE (i) >= 0 && REG_IN_TABLE (i) != REG_TICK (i))
    1032       169304 :             remove_invalid_refs (i);
    1033              : 
    1034    144983906 :           REG_IN_TABLE (i) = REG_TICK (i);
    1035    144983906 :           SUBREG_TICKED (i) = -1;
    1036              :         }
    1037              : 
    1038              :       return false;
    1039              :     }
    1040              : 
    1041              :   /* If this is a SUBREG, we don't want to discard other SUBREGs of the same
    1042              :      pseudo if they don't use overlapping words.  We handle only pseudos
    1043              :      here for simplicity.  */
    1044      8103304 :   if (code == SUBREG && REG_P (SUBREG_REG (x))
    1045    344518983 :       && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER)
    1046              :     {
    1047      8084804 :       unsigned int i = REGNO (SUBREG_REG (x));
    1048              : 
    1049      8084804 :       if (REG_IN_TABLE (i) >= 0 && REG_IN_TABLE (i) != REG_TICK (i))
    1050              :         {
    1051              :           /* If REG_IN_TABLE (i) differs from REG_TICK (i) by one, and
    1052              :              the last store to this register really stored into this
    1053              :              subreg, then remove the memory of this subreg.
    1054              :              Otherwise, remove any memory of the entire register and
    1055              :              all its subregs from the table.  */
    1056       343198 :           if (REG_TICK (i) - REG_IN_TABLE (i) > 1
    1057       343198 :               || SUBREG_TICKED (i) != REGNO (SUBREG_REG (x)))
    1058       343198 :             remove_invalid_refs (i);
    1059              :           else
    1060            0 :             remove_invalid_subreg_refs (i, SUBREG_BYTE (x), GET_MODE (x));
    1061              :         }
    1062              : 
    1063      8084804 :       REG_IN_TABLE (i) = REG_TICK (i);
    1064      8084804 :       SUBREG_TICKED (i) = REGNO (SUBREG_REG (x));
    1065      8084804 :       return false;
    1066              :     }
    1067              : 
    1068              :   /* If X is a comparison or a COMPARE and either operand is a register
    1069              :      that does not have a quantity, give it one.  This is so that a later
    1070              :      call to record_jump_equiv won't cause X to be assigned a different
    1071              :      hash code and not found in the table after that call.
    1072              : 
    1073              :      It is not necessary to do this here, since rehash_using_reg can
    1074              :      fix up the table later, but doing this here eliminates the need to
    1075              :      call that expensive function in the most common case where the only
    1076              :      use of the register is in the comparison.  */
    1077              : 
    1078    328349262 :   if (code == COMPARE || COMPARISON_P (x))
    1079              :     {
    1080     24181127 :       if (REG_P (XEXP (x, 0))
    1081     24181127 :           && ! REGNO_QTY_VALID_P (REGNO (XEXP (x, 0))))
    1082      9102668 :         if (insert_regs (XEXP (x, 0), NULL, false))
    1083              :           {
    1084      9102668 :             rehash_using_reg (XEXP (x, 0));
    1085      9102668 :             changed = true;
    1086              :           }
    1087              : 
    1088     24181127 :       if (REG_P (XEXP (x, 1))
    1089     24181127 :           && ! REGNO_QTY_VALID_P (REGNO (XEXP (x, 1))))
    1090      2496780 :         if (insert_regs (XEXP (x, 1), NULL, false))
    1091              :           {
    1092      2496780 :             rehash_using_reg (XEXP (x, 1));
    1093      2496780 :             changed = true;
    1094              :           }
    1095              :     }
    1096              : 
    1097    328349262 :   fmt = GET_RTX_FORMAT (code);
    1098    852952624 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1099    524603362 :     if (fmt[i] == 'e')
    1100              :       {
    1101    309400454 :         if (mention_regs (XEXP (x, i)))
    1102    524603362 :           changed = true;
    1103              :       }
    1104    215202908 :     else if (fmt[i] == 'E')
    1105     19205192 :       for (j = 0; j < XVECLEN (x, i); j++)
    1106     14581139 :         if (mention_regs (XVECEXP (x, i, j)))
    1107       360461 :           changed = true;
    1108              : 
    1109              :   return changed;
    1110              : }
    1111              : 
    1112              : /* Update the register quantities for inserting X into the hash table
    1113              :    with a value equivalent to CLASSP.
    1114              :    (If the class does not contain a REG, it is irrelevant.)
    1115              :    If MODIFIED is true, X is a destination; it is being modified.
    1116              :    Note that delete_reg_equiv should be called on a register
    1117              :    before insert_regs is done on that register with MODIFIED != 0.
    1118              : 
    1119              :    True value means that elements of reg_qty have changed
    1120              :    so X's hash code may be different.  */
    1121              : 
    1122              : static bool
    1123    259416209 : insert_regs (rtx x, struct table_elt *classp, bool modified)
    1124              : {
    1125    259416209 :   if (REG_P (x))
    1126              :     {
    1127    126237324 :       unsigned int regno = REGNO (x);
    1128    126237324 :       int qty_valid;
    1129              : 
    1130              :       /* If REGNO is in the equivalence table already but is of the
    1131              :          wrong mode for that equivalence, don't do anything here.  */
    1132              : 
    1133    126237324 :       qty_valid = REGNO_QTY_VALID_P (regno);
    1134    126237324 :       if (qty_valid)
    1135              :         {
    1136      6625930 :           struct qty_table_elem *ent = &qty_table[REG_QTY (regno)];
    1137              : 
    1138      6625930 :           if (ent->mode != GET_MODE (x))
    1139              :             return false;
    1140              :         }
    1141              : 
    1142    126237324 :       if (modified || ! qty_valid)
    1143              :         {
    1144    119611394 :           if (classp)
    1145     96751265 :             for (classp = classp->first_same_value;
    1146    190866927 :                  classp != 0;
    1147     94115662 :                  classp = classp->next_same_value)
    1148    106119227 :               if (REG_P (classp->exp)
    1149     12003565 :                   && GET_MODE (classp->exp) == GET_MODE (x))
    1150              :                 {
    1151     12003565 :                   unsigned c_regno = REGNO (classp->exp);
    1152              : 
    1153     12003565 :                   gcc_assert (REGNO_QTY_VALID_P (c_regno));
    1154              : 
    1155              :                   /* Suppose that 5 is hard reg and 100 and 101 are
    1156              :                      pseudos.  Consider
    1157              : 
    1158              :                      (set (reg:si 100) (reg:si 5))
    1159              :                      (set (reg:si 5) (reg:si 100))
    1160              :                      (set (reg:di 101) (reg:di 5))
    1161              : 
    1162              :                      We would now set REG_QTY (101) = REG_QTY (5), but the
    1163              :                      entry for 5 is in SImode.  When we use this later in
    1164              :                      copy propagation, we get the register in wrong mode.  */
    1165     12003565 :                   if (qty_table[REG_QTY (c_regno)].mode != GET_MODE (x))
    1166            0 :                     continue;
    1167              : 
    1168     12003565 :                   make_regs_eqv (regno, c_regno);
    1169     12003565 :                   return true;
    1170              :                 }
    1171              : 
    1172              :           /* Mention_regs for a SUBREG checks if REG_TICK is exactly one larger
    1173              :              than REG_IN_TABLE to find out if there was only a single preceding
    1174              :              invalidation - for the SUBREG - or another one, which would be
    1175              :              for the full register.  However, if we find here that REG_TICK
    1176              :              indicates that the register is invalid, it means that it has
    1177              :              been invalidated in a separate operation.  The SUBREG might be used
    1178              :              now (then this is a recursive call), or we might use the full REG
    1179              :              now and a SUBREG of it later.  So bump up REG_TICK so that
    1180              :              mention_regs will do the right thing.  */
    1181    107607829 :           if (! modified
    1182     23077465 :               && REG_IN_TABLE (regno) >= 0
    1183    109772214 :               && REG_TICK (regno) == REG_IN_TABLE (regno) + 1)
    1184          498 :             REG_TICK (regno)++;
    1185    107607829 :           make_new_qty (regno, GET_MODE (x));
    1186    107607829 :           return true;
    1187              :         }
    1188              : 
    1189              :       return false;
    1190              :     }
    1191              : 
    1192              :   /* If X is a SUBREG, we will likely be inserting the inner register in the
    1193              :      table.  If that register doesn't have an assigned quantity number at
    1194              :      this point but does later, the insertion that we will be doing now will
    1195              :      not be accessible because its hash code will have changed.  So assign
    1196              :      a quantity number now.  */
    1197              : 
    1198      3535132 :   else if (GET_CODE (x) == SUBREG && REG_P (SUBREG_REG (x))
    1199    136698489 :            && ! REGNO_QTY_VALID_P (REGNO (SUBREG_REG (x))))
    1200              :     {
    1201      1694320 :       insert_regs (SUBREG_REG (x), NULL, false);
    1202      1694320 :       mention_regs (x);
    1203      1694320 :       return true;
    1204              :     }
    1205              :   else
    1206    131484565 :     return mention_regs (x);
    1207              : }
    1208              : 
    1209              : 
    1210              : /* Compute upper and lower anchors for CST.  Also compute the offset of CST
    1211              :    from these anchors/bases such that *_BASE + *_OFFS = CST.  Return false iff
    1212              :    CST is equal to an anchor.  */
    1213              : 
    1214              : static bool
    1215            0 : compute_const_anchors (rtx cst,
    1216              :                        HOST_WIDE_INT *lower_base, HOST_WIDE_INT *lower_offs,
    1217              :                        HOST_WIDE_INT *upper_base, HOST_WIDE_INT *upper_offs)
    1218              : {
    1219            0 :   unsigned HOST_WIDE_INT n = UINTVAL (cst);
    1220              : 
    1221            0 :   *lower_base = n & ~(targetm.const_anchor - 1);
    1222            0 :   if ((unsigned HOST_WIDE_INT) *lower_base == n)
    1223              :     return false;
    1224              : 
    1225            0 :   *upper_base = ((n + (targetm.const_anchor - 1))
    1226            0 :                  & ~(targetm.const_anchor - 1));
    1227            0 :   *upper_offs = n - *upper_base;
    1228            0 :   *lower_offs = n - *lower_base;
    1229            0 :   return true;
    1230              : }
    1231              : 
    1232              : /* Insert the equivalence between ANCHOR and (REG + OFF) in mode MODE.  */
    1233              : 
    1234              : static void
    1235            0 : insert_const_anchor (HOST_WIDE_INT anchor, rtx reg, HOST_WIDE_INT offs,
    1236              :                      machine_mode mode)
    1237              : {
    1238            0 :   struct table_elt *elt;
    1239            0 :   unsigned hash;
    1240            0 :   rtx anchor_exp;
    1241            0 :   rtx exp;
    1242              : 
    1243            0 :   anchor_exp = gen_int_mode (anchor, mode);
    1244            0 :   hash = HASH (anchor_exp, mode);
    1245            0 :   elt = lookup (anchor_exp, hash, mode);
    1246            0 :   if (!elt)
    1247            0 :     elt = insert (anchor_exp, NULL, hash, mode);
    1248              : 
    1249            0 :   exp = plus_constant (mode, reg, offs);
    1250              :   /* REG has just been inserted and the hash codes recomputed.  */
    1251            0 :   mention_regs (exp);
    1252            0 :   hash = HASH (exp, mode);
    1253              : 
    1254              :   /* Use the cost of the register rather than the whole expression.  When
    1255              :      looking up constant anchors we will further offset the corresponding
    1256              :      expression therefore it does not make sense to prefer REGs over
    1257              :      reg-immediate additions.  Prefer instead the oldest expression.  Also
    1258              :      don't prefer pseudos over hard regs so that we derive constants in
    1259              :      argument registers from other argument registers rather than from the
    1260              :      original pseudo that was used to synthesize the constant.  */
    1261            0 :   insert_with_costs (exp, elt, hash, mode, COST (reg, mode), 1);
    1262            0 : }
    1263              : 
    1264              : /* The constant CST is equivalent to the register REG.  Create
    1265              :    equivalences between the two anchors of CST and the corresponding
    1266              :    register-offset expressions using REG.  */
    1267              : 
    1268              : static void
    1269            0 : insert_const_anchors (rtx reg, rtx cst, machine_mode mode)
    1270              : {
    1271            0 :   HOST_WIDE_INT lower_base, lower_offs, upper_base, upper_offs;
    1272              : 
    1273            0 :   if (!compute_const_anchors (cst, &lower_base, &lower_offs,
    1274              :                               &upper_base, &upper_offs))
    1275            0 :       return;
    1276              : 
    1277              :   /* Ignore anchors of value 0.  Constants accessible from zero are
    1278              :      simple.  */
    1279            0 :   if (lower_base != 0)
    1280            0 :     insert_const_anchor (lower_base, reg, -lower_offs, mode);
    1281              : 
    1282            0 :   if (upper_base != 0)
    1283            0 :     insert_const_anchor (upper_base, reg, -upper_offs, mode);
    1284              : }
    1285              : 
    1286              : /* We need to express ANCHOR_ELT->exp + OFFS.  Walk the equivalence list of
    1287              :    ANCHOR_ELT and see if offsetting any of the entries by OFFS would create a
    1288              :    valid expression.  Return the cheapest and oldest of such expressions.  In
    1289              :    *OLD, return how old the resulting expression is compared to the other
    1290              :    equivalent expressions.  */
    1291              : 
    1292              : static rtx
    1293            0 : find_reg_offset_for_const (struct table_elt *anchor_elt, HOST_WIDE_INT offs,
    1294              :                            unsigned *old)
    1295              : {
    1296            0 :   struct table_elt *elt;
    1297            0 :   unsigned idx;
    1298            0 :   struct table_elt *match_elt;
    1299            0 :   rtx match;
    1300              : 
    1301              :   /* Find the cheapest and *oldest* expression to maximize the chance of
    1302              :      reusing the same pseudo.  */
    1303              : 
    1304            0 :   match_elt = NULL;
    1305            0 :   match = NULL_RTX;
    1306            0 :   for (elt = anchor_elt->first_same_value, idx = 0;
    1307            0 :        elt;
    1308            0 :        elt = elt->next_same_value, idx++)
    1309              :     {
    1310            0 :       if (match_elt && CHEAPER (match_elt, elt))
    1311              :         return match;
    1312              : 
    1313            0 :       if (REG_P (elt->exp)
    1314            0 :           || (GET_CODE (elt->exp) == PLUS
    1315            0 :               && REG_P (XEXP (elt->exp, 0))
    1316            0 :               && GET_CODE (XEXP (elt->exp, 1)) == CONST_INT))
    1317              :         {
    1318            0 :           rtx x;
    1319              : 
    1320              :           /* Ignore expressions that are no longer valid.  */
    1321            0 :           if (!REG_P (elt->exp) && !exp_equiv_p (elt->exp, elt->exp, 1, false))
    1322            0 :             continue;
    1323              : 
    1324            0 :           x = plus_constant (GET_MODE (elt->exp), elt->exp, offs);
    1325            0 :           if (REG_P (x)
    1326            0 :               || (GET_CODE (x) == PLUS
    1327            0 :                   && IN_RANGE (INTVAL (XEXP (x, 1)),
    1328              :                                -targetm.const_anchor,
    1329              :                                targetm.const_anchor - 1)))
    1330              :             {
    1331            0 :               match = x;
    1332            0 :               match_elt = elt;
    1333            0 :               *old = idx;
    1334              :             }
    1335              :         }
    1336              :     }
    1337              : 
    1338              :   return match;
    1339              : }
    1340              : 
    1341              : /* Try to express the constant SRC_CONST using a register+offset expression
    1342              :    derived from a constant anchor.  Return it if successful or NULL_RTX,
    1343              :    otherwise.  */
    1344              : 
    1345              : static rtx
    1346            0 : try_const_anchors (rtx src_const, machine_mode mode)
    1347              : {
    1348            0 :   struct table_elt *lower_elt, *upper_elt;
    1349            0 :   HOST_WIDE_INT lower_base, lower_offs, upper_base, upper_offs;
    1350            0 :   rtx lower_anchor_rtx, upper_anchor_rtx;
    1351            0 :   rtx lower_exp = NULL_RTX, upper_exp = NULL_RTX;
    1352            0 :   unsigned lower_old, upper_old;
    1353              : 
    1354              :   /* CONST_INT may be in various modes, avoid non-scalar-int mode. */
    1355            0 :   if (!SCALAR_INT_MODE_P (mode))
    1356              :     return NULL_RTX;
    1357              : 
    1358            0 :   if (!compute_const_anchors (src_const, &lower_base, &lower_offs,
    1359              :                               &upper_base, &upper_offs))
    1360              :     return NULL_RTX;
    1361              : 
    1362            0 :   lower_anchor_rtx = GEN_INT (lower_base);
    1363            0 :   upper_anchor_rtx = GEN_INT (upper_base);
    1364            0 :   lower_elt = lookup (lower_anchor_rtx, HASH (lower_anchor_rtx, mode), mode);
    1365            0 :   upper_elt = lookup (upper_anchor_rtx, HASH (upper_anchor_rtx, mode), mode);
    1366              : 
    1367            0 :   if (lower_elt)
    1368            0 :     lower_exp = find_reg_offset_for_const (lower_elt, lower_offs, &lower_old);
    1369            0 :   if (upper_elt)
    1370            0 :     upper_exp = find_reg_offset_for_const (upper_elt, upper_offs, &upper_old);
    1371              : 
    1372            0 :   if (!lower_exp)
    1373              :     return upper_exp;
    1374            0 :   if (!upper_exp)
    1375              :     return lower_exp;
    1376              : 
    1377              :   /* Return the older expression.  */
    1378            0 :   return (upper_old > lower_old ? upper_exp : lower_exp);
    1379              : }
    1380              : 
    1381              : /* Look in or update the hash table.  */
    1382              : 
    1383              : /* Remove table element ELT from use in the table.
    1384              :    HASH is its hash code, made using the HASH macro.
    1385              :    It's an argument because often that is known in advance
    1386              :    and we save much time not recomputing it.  */
    1387              : 
    1388              : static void
    1389     70604313 : remove_from_table (struct table_elt *elt, unsigned int hash)
    1390              : {
    1391     70604313 :   if (elt == 0)
    1392              :     return;
    1393              : 
    1394              :   /* Mark this element as removed.  See cse_insn.  */
    1395     70604313 :   elt->first_same_value = 0;
    1396              : 
    1397              :   /* Remove the table element from its equivalence class.  */
    1398              : 
    1399     70604313 :   {
    1400     70604313 :     struct table_elt *prev = elt->prev_same_value;
    1401     70604313 :     struct table_elt *next = elt->next_same_value;
    1402              : 
    1403     70604313 :     if (next)
    1404      8035964 :       next->prev_same_value = prev;
    1405              : 
    1406     70604313 :     if (prev)
    1407     45392726 :       prev->next_same_value = next;
    1408              :     else
    1409              :       {
    1410              :         struct table_elt *newfirst = next;
    1411     40822747 :         while (next)
    1412              :           {
    1413     15611160 :             next->first_same_value = newfirst;
    1414     15611160 :             next = next->next_same_value;
    1415              :           }
    1416              :       }
    1417              :   }
    1418              : 
    1419              :   /* Remove the table element from its hash bucket.  */
    1420              : 
    1421     70604313 :   {
    1422     70604313 :     struct table_elt *prev = elt->prev_same_hash;
    1423     70604313 :     struct table_elt *next = elt->next_same_hash;
    1424              : 
    1425     70604313 :     if (next)
    1426     20886511 :       next->prev_same_hash = prev;
    1427              : 
    1428     70604313 :     if (prev)
    1429      9002735 :       prev->next_same_hash = next;
    1430     61601578 :     else if (table[hash] == elt)
    1431     61601572 :       table[hash] = next;
    1432              :     else
    1433              :       {
    1434              :         /* This entry is not in the proper hash bucket.  This can happen
    1435              :            when two classes were merged by `merge_equiv_classes'.  Search
    1436              :            for the hash bucket that it heads.  This happens only very
    1437              :            rarely, so the cost is acceptable.  */
    1438          198 :         for (hash = 0; hash < HASH_SIZE; hash++)
    1439          192 :           if (table[hash] == elt)
    1440            6 :             table[hash] = next;
    1441              :       }
    1442              :   }
    1443              : 
    1444              :   /* Remove the table element from its related-value circular chain.  */
    1445              : 
    1446     70604313 :   if (elt->related_value != 0 && elt->related_value != elt)
    1447              :     {
    1448              :       struct table_elt *p = elt->related_value;
    1449              : 
    1450       264319 :       while (p->related_value != elt)
    1451              :         p = p->related_value;
    1452        33271 :       p->related_value = elt->related_value;
    1453        33271 :       if (p->related_value == p)
    1454        25890 :         p->related_value = 0;
    1455              :     }
    1456              : 
    1457              :   /* Now add it to the free element chain.  */
    1458     70604313 :   elt->next_same_hash = free_element_chain;
    1459     70604313 :   free_element_chain = elt;
    1460              : }
    1461              : 
    1462              : /* Same as above, but X is a pseudo-register.  */
    1463              : 
    1464              : static void
    1465     94942633 : remove_pseudo_from_table (rtx x, unsigned int hash)
    1466              : {
    1467     94942633 :   struct table_elt *elt;
    1468              : 
    1469              :   /* Because a pseudo-register can be referenced in more than one
    1470              :      mode, we might have to remove more than one table entry.  */
    1471     99527331 :   while ((elt = lookup_for_remove (x, hash, VOIDmode)))
    1472      4584698 :     remove_from_table (elt, hash);
    1473     94942633 : }
    1474              : 
    1475              : /* Look up X in the hash table and return its table element,
    1476              :    or 0 if X is not in the table.
    1477              : 
    1478              :    MODE is the machine-mode of X, or if X is an integer constant
    1479              :    with VOIDmode then MODE is the mode with which X will be used.
    1480              : 
    1481              :    Here we are satisfied to find an expression whose tree structure
    1482              :    looks like X.  */
    1483              : 
    1484              : static struct table_elt *
    1485    509266094 : lookup (rtx x, unsigned int hash, machine_mode mode)
    1486              : {
    1487    509266094 :   struct table_elt *p;
    1488              : 
    1489    762225525 :   for (p = table[hash]; p; p = p->next_same_hash)
    1490    386724729 :     if (mode == p->mode && ((x == p->exp && REG_P (x))
    1491    152005950 :                             || exp_equiv_p (x, p->exp, !REG_P (x), false)))
    1492              :       return p;
    1493              : 
    1494              :   return 0;
    1495              : }
    1496              : 
    1497              : /* Like `lookup' but don't care whether the table element uses invalid regs.
    1498              :    Also ignore discrepancies in the machine mode of a register.  */
    1499              : 
    1500              : static struct table_elt *
    1501     99527331 : lookup_for_remove (rtx x, unsigned int hash, machine_mode mode)
    1502              : {
    1503     99527331 :   struct table_elt *p;
    1504              : 
    1505     99527331 :   if (REG_P (x))
    1506              :     {
    1507     99527331 :       unsigned int regno = REGNO (x);
    1508              : 
    1509              :       /* Don't check the machine mode when comparing registers;
    1510              :          invalidating (REG:SI 0) also invalidates (REG:DF 0).  */
    1511    196375555 :       for (p = table[hash]; p; p = p->next_same_hash)
    1512    101432922 :         if (REG_P (p->exp)
    1513    101432922 :             && REGNO (p->exp) == regno)
    1514              :           return p;
    1515              :     }
    1516              :   else
    1517              :     {
    1518            0 :       for (p = table[hash]; p; p = p->next_same_hash)
    1519            0 :         if (mode == p->mode
    1520            0 :             && (x == p->exp || exp_equiv_p (x, p->exp, 0, false)))
    1521              :           return p;
    1522              :     }
    1523              : 
    1524              :   return 0;
    1525              : }
    1526              : 
    1527              : /* Look for an expression equivalent to X and with code CODE.
    1528              :    If one is found, return that expression.  */
    1529              : 
    1530              : static rtx
    1531     63226322 : lookup_as_function (rtx x, enum rtx_code code)
    1532              : {
    1533     63226322 :   struct table_elt *p
    1534     63226322 :     = lookup (x, SAFE_HASH (x, VOIDmode), GET_MODE (x));
    1535              : 
    1536     63226322 :   if (p == 0)
    1537              :     return 0;
    1538              : 
    1539     39978421 :   for (p = p->first_same_value; p; p = p->next_same_value)
    1540     27765515 :     if (GET_CODE (p->exp) == code
    1541              :         /* Make sure this is a valid entry in the table.  */
    1542     27765515 :         && exp_equiv_p (p->exp, p->exp, 1, false))
    1543       831096 :       return p->exp;
    1544              : 
    1545              :   return 0;
    1546              : }
    1547              : 
    1548              : /* Insert X in the hash table, assuming HASH is its hash code and
    1549              :    CLASSP is an element of the class it should go in (or 0 if a new
    1550              :    class should be made).  COST is the code of X and reg_cost is the
    1551              :    cost of registers in X.  It is inserted at the proper position to
    1552              :    keep the class in the order cheapest first.
    1553              : 
    1554              :    MODE is the machine-mode of X, or if X is an integer constant
    1555              :    with VOIDmode then MODE is the mode with which X will be used.
    1556              : 
    1557              :    For elements of equal cheapness, the most recent one
    1558              :    goes in front, except that the first element in the list
    1559              :    remains first unless a cheaper element is added.  The order of
    1560              :    pseudo-registers does not matter, as canon_reg will be called to
    1561              :    find the cheapest when a register is retrieved from the table.
    1562              : 
    1563              :    The in_memory field in the hash table element is set to 0.
    1564              :    The caller must set it nonzero if appropriate.
    1565              : 
    1566              :    You should call insert_regs (X, CLASSP, MODIFY) before calling here,
    1567              :    and if insert_regs returns a nonzero value
    1568              :    you must then recompute its hash code before calling here.
    1569              : 
    1570              :    If necessary, update table showing constant values of quantities.  */
    1571              : 
    1572              : static struct table_elt *
    1573    270919771 : insert_with_costs (rtx x, struct table_elt *classp, unsigned int hash,
    1574              :                    machine_mode mode, int cost, int reg_cost)
    1575              : {
    1576    270919771 :   struct table_elt *elt;
    1577              : 
    1578              :   /* If X is a register and we haven't made a quantity for it,
    1579              :      something is wrong.  */
    1580    270919771 :   gcc_assert (!REG_P (x) || REGNO_QTY_VALID_P (REGNO (x)));
    1581              : 
    1582              :   /* If X is a hard register, show it is being put in the table.  */
    1583    270919771 :   if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
    1584     22416683 :     add_to_hard_reg_set (&hard_regs_in_table, GET_MODE (x), REGNO (x));
    1585              : 
    1586              :   /* Put an element for X into the right hash bucket.  */
    1587              : 
    1588    270919771 :   elt = free_element_chain;
    1589    270919771 :   if (elt)
    1590    265563800 :     free_element_chain = elt->next_same_hash;
    1591              :   else
    1592      5355971 :     elt = XNEW (struct table_elt);
    1593              : 
    1594    270919771 :   elt->exp = x;
    1595    270919771 :   elt->canon_exp = NULL_RTX;
    1596    270919771 :   elt->cost = cost;
    1597    270919771 :   elt->regcost = reg_cost;
    1598    270919771 :   elt->next_same_value = 0;
    1599    270919771 :   elt->prev_same_value = 0;
    1600    270919771 :   elt->next_same_hash = table[hash];
    1601    270919771 :   elt->prev_same_hash = 0;
    1602    270919771 :   elt->related_value = 0;
    1603    270919771 :   elt->in_memory = 0;
    1604    270919771 :   elt->mode = mode;
    1605    270919771 :   elt->is_const = (CONSTANT_P (x) || fixed_base_plus_p (x));
    1606              : 
    1607    270919771 :   if (table[hash])
    1608     86003630 :     table[hash]->prev_same_hash = elt;
    1609    270919771 :   table[hash] = elt;
    1610              : 
    1611              :   /* Put it into the proper value-class.  */
    1612    270919771 :   if (classp)
    1613              :     {
    1614    132491550 :       classp = classp->first_same_value;
    1615    132491550 :       if (CHEAPER (elt, classp))
    1616              :         /* Insert at the head of the class.  */
    1617              :         {
    1618     62184016 :           struct table_elt *p;
    1619     62184016 :           elt->next_same_value = classp;
    1620     62184016 :           classp->prev_same_value = elt;
    1621     62184016 :           elt->first_same_value = elt;
    1622              : 
    1623    131372883 :           for (p = classp; p; p = p->next_same_value)
    1624     69188867 :             p->first_same_value = elt;
    1625              :         }
    1626              :       else
    1627              :         {
    1628              :           /* Insert not at head of the class.  */
    1629              :           /* Put it after the last element cheaper than X.  */
    1630              :           struct table_elt *p, *next;
    1631              : 
    1632              :           for (p = classp;
    1633    153685406 :                (next = p->next_same_value) && CHEAPER (next, elt);
    1634              :                p = next)
    1635              :             ;
    1636              : 
    1637              :           /* Put it after P and before NEXT.  */
    1638     70307534 :           elt->next_same_value = next;
    1639     70307534 :           if (next)
    1640     17249645 :             next->prev_same_value = elt;
    1641              : 
    1642     70307534 :           elt->prev_same_value = p;
    1643     70307534 :           p->next_same_value = elt;
    1644     70307534 :           elt->first_same_value = classp;
    1645              :         }
    1646              :     }
    1647              :   else
    1648    138428221 :     elt->first_same_value = elt;
    1649              : 
    1650              :   /* If this is a constant being set equivalent to a register or a register
    1651              :      being set equivalent to a constant, note the constant equivalence.
    1652              : 
    1653              :      If this is a constant, it cannot be equivalent to a different constant,
    1654              :      and a constant is the only thing that can be cheaper than a register.  So
    1655              :      we know the register is the head of the class (before the constant was
    1656              :      inserted).
    1657              : 
    1658              :      If this is a register that is not already known equivalent to a
    1659              :      constant, we must check the entire class.
    1660              : 
    1661              :      If this is a register that is already known equivalent to an insn,
    1662              :      update the qtys `const_insn' to show that `this_insn' is the latest
    1663              :      insn making that quantity equivalent to the constant.  */
    1664              : 
    1665    270919771 :   if (elt->is_const && classp && REG_P (classp->exp)
    1666      3374199 :       && !REG_P (x))
    1667              :     {
    1668      3371374 :       int exp_q = REG_QTY (REGNO (classp->exp));
    1669      3371374 :       struct qty_table_elem *exp_ent = &qty_table[exp_q];
    1670              : 
    1671      3371374 :       exp_ent->const_rtx = gen_lowpart (exp_ent->mode, x);
    1672      3371374 :       exp_ent->const_insn = this_insn;
    1673      3371374 :     }
    1674              : 
    1675    267548397 :   else if (REG_P (x)
    1676    112943556 :            && classp
    1677     96760674 :            && ! qty_table[REG_QTY (REGNO (x))].const_rtx
    1678    359591522 :            && ! elt->is_const)
    1679              :     {
    1680              :       struct table_elt *p;
    1681              : 
    1682    213733174 :       for (p = classp; p != 0; p = p->next_same_value)
    1683              :         {
    1684    136387437 :           if (p->is_const && !REG_P (p->exp))
    1685              :             {
    1686     14694502 :               int x_q = REG_QTY (REGNO (x));
    1687     14694502 :               struct qty_table_elem *x_ent = &qty_table[x_q];
    1688              : 
    1689     14694502 :               x_ent->const_rtx
    1690     14694502 :                 = gen_lowpart (GET_MODE (x), p->exp);
    1691     14694502 :               x_ent->const_insn = this_insn;
    1692     14694502 :               break;
    1693              :             }
    1694              :         }
    1695              :     }
    1696              : 
    1697    175508158 :   else if (REG_P (x)
    1698     20903317 :            && qty_table[REG_QTY (REGNO (x))].const_rtx
    1699    180225708 :            && GET_MODE (x) == qty_table[REG_QTY (REGNO (x))].mode)
    1700      4717550 :     qty_table[REG_QTY (REGNO (x))].const_insn = this_insn;
    1701              : 
    1702              :   /* If this is a constant with symbolic value,
    1703              :      and it has a term with an explicit integer value,
    1704              :      link it up with related expressions.  */
    1705    270919771 :   if (GET_CODE (x) == CONST)
    1706              :     {
    1707       878076 :       rtx subexp = get_related_value (x);
    1708       878076 :       unsigned subhash;
    1709       878076 :       struct table_elt *subelt, *subelt_prev;
    1710              : 
    1711       878076 :       if (subexp != 0)
    1712              :         {
    1713              :           /* Get the integer-free subexpression in the hash table.  */
    1714       864251 :           subhash = SAFE_HASH (subexp, mode);
    1715       864251 :           subelt = lookup (subexp, subhash, mode);
    1716       864251 :           if (subelt == 0)
    1717       387917 :             subelt = insert (subexp, NULL, subhash, mode);
    1718              :           /* Initialize SUBELT's circular chain if it has none.  */
    1719       864251 :           if (subelt->related_value == 0)
    1720       564185 :             subelt->related_value = subelt;
    1721              :           /* Find the element in the circular chain that precedes SUBELT.  */
    1722       864251 :           subelt_prev = subelt;
    1723      3572981 :           while (subelt_prev->related_value != subelt)
    1724              :             subelt_prev = subelt_prev->related_value;
    1725              :           /* Put new ELT into SUBELT's circular chain just before SUBELT.
    1726              :              This way the element that follows SUBELT is the oldest one.  */
    1727       864251 :           elt->related_value = subelt_prev->related_value;
    1728       864251 :           subelt_prev->related_value = elt;
    1729              :         }
    1730              :     }
    1731              : 
    1732    270919771 :   return elt;
    1733              : }
    1734              : 
    1735              : /* Wrap insert_with_costs by passing the default costs.  */
    1736              : 
    1737              : static struct table_elt *
    1738    270919771 : insert (rtx x, struct table_elt *classp, unsigned int hash,
    1739              :         machine_mode mode)
    1740              : {
    1741    541839542 :   return insert_with_costs (x, classp, hash, mode,
    1742    270919771 :                             COST (x, mode), approx_reg_cost (x));
    1743              : }
    1744              : 
    1745              : 
    1746              : /* Given two equivalence classes, CLASS1 and CLASS2, put all the entries from
    1747              :    CLASS2 into CLASS1.  This is done when we have reached an insn which makes
    1748              :    the two classes equivalent.
    1749              : 
    1750              :    CLASS1 will be the surviving class; CLASS2 should not be used after this
    1751              :    call.
    1752              : 
    1753              :    Any invalid entries in CLASS2 will not be copied.  */
    1754              : 
    1755              : static void
    1756      5377208 : merge_equiv_classes (struct table_elt *class1, struct table_elt *class2)
    1757              : {
    1758      5377208 :   struct table_elt *elt, *next, *new_elt;
    1759              : 
    1760              :   /* Ensure we start with the head of the classes.  */
    1761      5377208 :   class1 = class1->first_same_value;
    1762      5377208 :   class2 = class2->first_same_value;
    1763              : 
    1764              :   /* If they were already equal, forget it.  */
    1765      5377208 :   if (class1 == class2)
    1766              :     return;
    1767              : 
    1768     12815119 :   for (elt = class2; elt; elt = next)
    1769              :     {
    1770      7437911 :       unsigned int hash;
    1771      7437911 :       rtx exp = elt->exp;
    1772      7437911 :       machine_mode mode = elt->mode;
    1773              : 
    1774      7437911 :       next = elt->next_same_value;
    1775              : 
    1776              :       /* Remove old entry, make a new one in CLASS1's class.
    1777              :          Don't do this for invalid entries as we cannot find their
    1778              :          hash code (it also isn't necessary).  */
    1779      7437911 :       if (REG_P (exp) || exp_equiv_p (exp, exp, 1, false))
    1780              :         {
    1781      7437887 :           bool need_rehash = false;
    1782              : 
    1783      7437887 :           hash_arg_in_memory = 0;
    1784      7437887 :           hash = HASH (exp, mode);
    1785              : 
    1786      7437887 :           if (REG_P (exp))
    1787              :             {
    1788      2020999 :               need_rehash = REGNO_QTY_VALID_P (REGNO (exp));
    1789      2020999 :               delete_reg_equiv (REGNO (exp));
    1790              :             }
    1791              : 
    1792      7437887 :           if (REG_P (exp) && REGNO (exp) >= FIRST_PSEUDO_REGISTER)
    1793      2019827 :             remove_pseudo_from_table (exp, hash);
    1794              :           else
    1795      5418060 :             remove_from_table (elt, hash);
    1796              : 
    1797      7437887 :           if (insert_regs (exp, class1, false) || need_rehash)
    1798              :             {
    1799      2020999 :               rehash_using_reg (exp);
    1800      2020999 :               hash = HASH (exp, mode);
    1801              :             }
    1802      7437887 :           new_elt = insert (exp, class1, hash, mode);
    1803      7437887 :           new_elt->in_memory = hash_arg_in_memory;
    1804      7437887 :           if (GET_CODE (exp) == ASM_OPERANDS && elt->cost == MAX_COST)
    1805            0 :             new_elt->cost = MAX_COST;
    1806              :         }
    1807              :     }
    1808              : }
    1809              : 
    1810              : /* Flush the entire hash table.  */
    1811              : 
    1812              : static void
    1813         8322 : flush_hash_table (void)
    1814              : {
    1815         8322 :   int i;
    1816         8322 :   struct table_elt *p;
    1817              : 
    1818       274626 :   for (i = 0; i < HASH_SIZE; i++)
    1819      1131040 :     for (p = table[i]; p; p = table[i])
    1820              :       {
    1821              :         /* Note that invalidate can remove elements
    1822              :            after P in the current hash chain.  */
    1823       864736 :         if (REG_P (p->exp))
    1824       410997 :           invalidate (p->exp, VOIDmode);
    1825              :         else
    1826       453739 :           remove_from_table (p, i);
    1827              :       }
    1828         8322 : }
    1829              : 
    1830              : /* Check whether an anti dependence exists between X and EXP.  MODE and
    1831              :    ADDR are as for canon_anti_dependence.  */
    1832              : 
    1833              : static bool
    1834    192168300 : check_dependence (const_rtx x, rtx exp, machine_mode mode, rtx addr)
    1835              : {
    1836    192168300 :   subrtx_iterator::array_type array;
    1837    903828475 :   FOR_EACH_SUBRTX (iter, array, x, NONCONST)
    1838              :     {
    1839    720102174 :       const_rtx x = *iter;
    1840    720102174 :       if (MEM_P (x) && canon_anti_dependence (x, true, exp, mode, addr))
    1841      8441999 :         return true;
    1842              :     }
    1843    183726301 :   return false;
    1844    192168300 : }
    1845              : 
    1846              : /* Remove from the hash table, or mark as invalid, all expressions whose
    1847              :    values could be altered by storing in register X.  */
    1848              : 
    1849              : static void
    1850    226308377 : invalidate_reg (rtx x)
    1851              : {
    1852    226308377 :   gcc_assert (GET_CODE (x) == REG);
    1853              : 
    1854              :   /* If X is a register, dependencies on its contents are recorded
    1855              :      through the qty number mechanism.  Just change the qty number of
    1856              :      the register, mark it as invalid for expressions that refer to it,
    1857              :      and remove it itself.  */
    1858    226308377 :   unsigned int regno = REGNO (x);
    1859    226308377 :   unsigned int hash = HASH (x, GET_MODE (x));
    1860              : 
    1861              :   /* Remove REGNO from any quantity list it might be on and indicate
    1862              :      that its value might have changed.  If it is a pseudo, remove its
    1863              :      entry from the hash table.
    1864              : 
    1865              :      For a hard register, we do the first two actions above for any
    1866              :      additional hard registers corresponding to X.  Then, if any of these
    1867              :      registers are in the table, we must remove any REG entries that
    1868              :      overlap these registers.  */
    1869              : 
    1870    226308377 :   delete_reg_equiv (regno);
    1871    226308377 :   REG_TICK (regno)++;
    1872    226308377 :   SUBREG_TICKED (regno) = -1;
    1873              : 
    1874    226308377 :   if (regno >= FIRST_PSEUDO_REGISTER)
    1875     92922806 :     remove_pseudo_from_table (x, hash);
    1876              :   else
    1877              :     {
    1878    133385571 :       HOST_WIDE_INT in_table = TEST_HARD_REG_BIT (hard_regs_in_table, regno);
    1879    133385571 :       unsigned int endregno = END_REGNO (x);
    1880    133385571 :       unsigned int rn;
    1881    133385571 :       struct table_elt *p, *next;
    1882              : 
    1883    133385571 :       CLEAR_HARD_REG_BIT (hard_regs_in_table, regno);
    1884              : 
    1885    133988095 :       for (rn = regno + 1; rn < endregno; rn++)
    1886              :         {
    1887       602524 :           in_table |= TEST_HARD_REG_BIT (hard_regs_in_table, rn);
    1888       602524 :           CLEAR_HARD_REG_BIT (hard_regs_in_table, rn);
    1889       602524 :           delete_reg_equiv (rn);
    1890       602524 :           REG_TICK (rn)++;
    1891       602524 :           SUBREG_TICKED (rn) = -1;
    1892              :         }
    1893              : 
    1894    133385571 :       if (in_table)
    1895    416115546 :         for (hash = 0; hash < HASH_SIZE; hash++)
    1896    649360392 :           for (p = table[hash]; p; p = next)
    1897              :             {
    1898    245854408 :               next = p->next_same_hash;
    1899              : 
    1900    245854408 :               if (!REG_P (p->exp) || REGNO (p->exp) >= FIRST_PSEUDO_REGISTER)
    1901    234883469 :                 continue;
    1902              : 
    1903     10970939 :               unsigned int tregno = REGNO (p->exp);
    1904     10970939 :               unsigned int tendregno = END_REGNO (p->exp);
    1905     10970939 :               if (tendregno > regno && tregno < endregno)
    1906     10898151 :                 remove_from_table (p, hash);
    1907              :             }
    1908              :     }
    1909    226308377 : }
    1910              : 
    1911              : /* Remove from the hash table, or mark as invalid, all expressions whose
    1912              :    values could be altered by storing in X.  X is a register, a subreg, or
    1913              :    a memory reference with nonvarying address (because, when a memory
    1914              :    reference with a varying address is stored in, all memory references are
    1915              :    removed by invalidate_memory so specific invalidation is superfluous).
    1916              :    FULL_MODE, if not VOIDmode, indicates that this much should be
    1917              :    invalidated instead of just the amount indicated by the mode of X.  This
    1918              :    is only used for bitfield stores into memory.
    1919              : 
    1920              :    A nonvarying address may be just a register or just a symbol reference,
    1921              :    or it may be either of those plus a numeric offset.  */
    1922              : 
    1923              : static void
    1924    255887780 : invalidate (rtx x, machine_mode full_mode)
    1925              : {
    1926    257597357 :   int i;
    1927    257597357 :   struct table_elt *p;
    1928    257597357 :   rtx addr;
    1929              : 
    1930    257597357 :   switch (GET_CODE (x))
    1931              :     {
    1932    226308187 :     case REG:
    1933    226308187 :       invalidate_reg (x);
    1934    226308187 :       return;
    1935              : 
    1936      1663837 :     case SUBREG:
    1937      1663837 :       invalidate (SUBREG_REG (x), VOIDmode);
    1938      1663837 :       return;
    1939              : 
    1940        26415 :     case PARALLEL:
    1941        72155 :       for (i = XVECLEN (x, 0) - 1; i >= 0; --i)
    1942        45740 :         invalidate (XVECEXP (x, 0, i), VOIDmode);
    1943              :       return;
    1944              : 
    1945        45740 :     case EXPR_LIST:
    1946              :       /* This is part of a disjoint return value; extract the location in
    1947              :          question ignoring the offset.  */
    1948        45740 :       invalidate (XEXP (x, 0), VOIDmode);
    1949        45740 :       return;
    1950              : 
    1951     29553178 :     case MEM:
    1952     29553178 :       addr = canon_rtx (get_addr (XEXP (x, 0)));
    1953              :       /* Calculate the canonical version of X here so that
    1954              :          true_dependence doesn't generate new RTL for X on each call.  */
    1955     29553178 :       x = canon_rtx (x);
    1956              : 
    1957              :       /* Remove all hash table elements that refer to overlapping pieces of
    1958              :          memory.  */
    1959     29553178 :       if (full_mode == VOIDmode)
    1960     29552210 :         full_mode = GET_MODE (x);
    1961              : 
    1962    975254874 :       for (i = 0; i < HASH_SIZE; i++)
    1963              :         {
    1964    945701696 :           struct table_elt *next;
    1965              : 
    1966   1939885443 :           for (p = table[i]; p; p = next)
    1967              :             {
    1968    994183747 :               next = p->next_same_hash;
    1969    994183747 :               if (p->in_memory)
    1970              :                 {
    1971              :                   /* Just canonicalize the expression once;
    1972              :                      otherwise each time we call invalidate
    1973              :                      true_dependence will canonicalize the
    1974              :                      expression again.  */
    1975    192168300 :                   if (!p->canon_exp)
    1976     27723219 :                     p->canon_exp = canon_rtx (p->exp);
    1977    192168300 :                   if (check_dependence (p->canon_exp, x, full_mode, addr))
    1978      8441999 :                     remove_from_table (p, i);
    1979              :                 }
    1980              :             }
    1981              :         }
    1982              :       return;
    1983              : 
    1984            0 :     default:
    1985            0 :       gcc_unreachable ();
    1986              :     }
    1987              : }
    1988              : 
    1989              : /* Invalidate DEST.  Used when DEST is not going to be added
    1990              :    into the hash table for some reason, e.g. do_not_record
    1991              :    flagged on it.  */
    1992              : 
    1993              : static void
    1994     56638470 : invalidate_dest (rtx dest)
    1995              : {
    1996     56638470 :   if (REG_P (dest)
    1997     27273435 :       || GET_CODE (dest) == SUBREG
    1998     27273435 :       || MEM_P (dest))
    1999     36176557 :     invalidate (dest, VOIDmode);
    2000     20461913 :   else if (GET_CODE (dest) == STRICT_LOW_PART
    2001     20461913 :            || GET_CODE (dest) == ZERO_EXTRACT)
    2002          976 :     invalidate (XEXP (dest, 0), GET_MODE (dest));
    2003     56638470 : }
    2004              : 
    2005              : /* Remove all expressions that refer to register REGNO,
    2006              :    since they are already invalid, and we are about to
    2007              :    mark that register valid again and don't want the old
    2008              :    expressions to reappear as valid.  */
    2009              : 
    2010              : static void
    2011     13636545 : remove_invalid_refs (unsigned int regno)
    2012              : {
    2013     13636545 :   unsigned int i;
    2014     13636545 :   struct table_elt *p, *next;
    2015              : 
    2016    450005985 :   for (i = 0; i < HASH_SIZE; i++)
    2017    693767504 :     for (p = table[i]; p; p = next)
    2018              :       {
    2019    257398064 :         next = p->next_same_hash;
    2020    257398064 :         if (!REG_P (p->exp) && refers_to_regno_p (regno, p->exp))
    2021     17727690 :           remove_from_table (p, i);
    2022              :       }
    2023     13636545 : }
    2024              : 
    2025              : /* Likewise for a subreg with subreg_reg REGNO, subreg_byte OFFSET,
    2026              :    and mode MODE.  */
    2027              : static void
    2028            0 : remove_invalid_subreg_refs (unsigned int regno, poly_uint64 offset,
    2029              :                             machine_mode mode)
    2030              : {
    2031            0 :   unsigned int i;
    2032            0 :   struct table_elt *p, *next;
    2033              : 
    2034            0 :   for (i = 0; i < HASH_SIZE; i++)
    2035            0 :     for (p = table[i]; p; p = next)
    2036              :       {
    2037            0 :         rtx exp = p->exp;
    2038            0 :         next = p->next_same_hash;
    2039              : 
    2040            0 :         if (!REG_P (exp)
    2041            0 :             && (GET_CODE (exp) != SUBREG
    2042            0 :                 || !REG_P (SUBREG_REG (exp))
    2043            0 :                 || REGNO (SUBREG_REG (exp)) != regno
    2044            0 :                 || ranges_maybe_overlap_p (SUBREG_BYTE (exp),
    2045            0 :                                            GET_MODE_SIZE (GET_MODE (exp)),
    2046            0 :                                            offset, GET_MODE_SIZE (mode)))
    2047            0 :             && refers_to_regno_p (regno, p->exp))
    2048            0 :           remove_from_table (p, i);
    2049              :       }
    2050            0 : }
    2051              : 
    2052              : /* Recompute the hash codes of any valid entries in the hash table that
    2053              :    reference X, if X is a register, or SUBREG_REG (X) if X is a SUBREG.
    2054              : 
    2055              :    This is called when we make a jump equivalence.  */
    2056              : 
    2057              : static void
    2058    129496213 : rehash_using_reg (rtx x)
    2059              : {
    2060    129496213 :   unsigned int i;
    2061    129496213 :   struct table_elt *p, *next;
    2062    129496213 :   unsigned hash;
    2063              : 
    2064    129496213 :   if (GET_CODE (x) == SUBREG)
    2065      1694320 :     x = SUBREG_REG (x);
    2066              : 
    2067              :   /* If X is not a register or if the register is known not to be in any
    2068              :      valid entries in the table, we have no work to do.  */
    2069              : 
    2070    129496213 :   if (!REG_P (x)
    2071    119611394 :       || REG_IN_TABLE (REGNO (x)) < 0
    2072    134612184 :       || REG_IN_TABLE (REGNO (x)) != REG_TICK (REGNO (x)))
    2073              :     return;
    2074              : 
    2075              :   /* Scan all hash chains looking for valid entries that mention X.
    2076              :      If we find one and it is in the wrong hash chain, move it.  */
    2077              : 
    2078    168808266 :   for (i = 0; i < HASH_SIZE; i++)
    2079    278955906 :     for (p = table[i]; p; p = next)
    2080              :       {
    2081    115263042 :         next = p->next_same_hash;
    2082    115263042 :         if (reg_mentioned_p (x, p->exp)
    2083      4943722 :             && exp_equiv_p (p->exp, p->exp, 1, false)
    2084    120206584 :             && i != (hash = SAFE_HASH (p->exp, p->mode)))
    2085              :           {
    2086      3506685 :             if (p->next_same_hash)
    2087      1120566 :               p->next_same_hash->prev_same_hash = p->prev_same_hash;
    2088              : 
    2089      3506685 :             if (p->prev_same_hash)
    2090       646159 :               p->prev_same_hash->next_same_hash = p->next_same_hash;
    2091              :             else
    2092      2860526 :               table[i] = p->next_same_hash;
    2093              : 
    2094      3506685 :             p->next_same_hash = table[hash];
    2095      3506685 :             p->prev_same_hash = 0;
    2096      3506685 :             if (table[hash])
    2097      1689234 :               table[hash]->prev_same_hash = p;
    2098      3506685 :             table[hash] = p;
    2099              :           }
    2100              :       }
    2101              : }
    2102              : 
    2103              : /* Remove from the hash table any expression that is a call-clobbered
    2104              :    register in INSN.  Also update their TICK values.  */
    2105              : 
    2106              : static void
    2107     15887571 : invalidate_for_call (rtx_call_insn *insn)
    2108              : {
    2109     15887571 :   unsigned int regno;
    2110     15887571 :   unsigned hash;
    2111     15887571 :   struct table_elt *p, *next;
    2112     15887571 :   int in_table = 0;
    2113     15887571 :   hard_reg_set_iterator hrsi;
    2114              : 
    2115              :   /* Go through all the hard registers.  For each that might be clobbered
    2116              :      in call insn INSN, remove the register from quantity chains and update
    2117              :      reg_tick if defined.  Also see if any of these registers is currently
    2118              :      in the table.
    2119              : 
    2120              :      ??? We could be more precise for partially-clobbered registers,
    2121              :      and only invalidate values that actually occupy the clobbered part
    2122              :      of the registers.  It doesn't seem worth the effort though, since
    2123              :      we shouldn't see this situation much before RA.  Whatever choice
    2124              :      we make here has to be consistent with the table walk below,
    2125              :      so any change to this test will require a change there too.  */
    2126     15887571 :   HARD_REG_SET callee_clobbers
    2127     15887571 :     = insn_callee_abi (insn).full_and_partial_reg_clobbers ();
    2128   1347190867 :   EXECUTE_IF_SET_IN_HARD_REG_SET (callee_clobbers, 0, regno, hrsi)
    2129              :     {
    2130   1331303296 :       delete_reg_equiv (regno);
    2131   1331303296 :       if (REG_TICK (regno) >= 0)
    2132              :         {
    2133   1331303296 :           REG_TICK (regno)++;
    2134   1331303296 :           SUBREG_TICKED (regno) = -1;
    2135              :         }
    2136   1331303296 :       in_table |= (TEST_HARD_REG_BIT (hard_regs_in_table, regno) != 0);
    2137              :     }
    2138              : 
    2139              :   /* In the case where we have no call-clobbered hard registers in the
    2140              :      table, we are done.  Otherwise, scan the table and remove any
    2141              :      entry that overlaps a call-clobbered register.  */
    2142              : 
    2143     15887571 :   if (in_table)
    2144    121226985 :     for (hash = 0; hash < HASH_SIZE; hash++)
    2145    175967280 :       for (p = table[hash]; p; p = next)
    2146              :         {
    2147     58413840 :           next = p->next_same_hash;
    2148              : 
    2149    113691990 :           if (!REG_P (p->exp)
    2150     58413840 :               || REGNO (p->exp) >= FIRST_PSEUDO_REGISTER)
    2151     55278150 :             continue;
    2152              : 
    2153              :           /* This must use the same test as above rather than the
    2154              :              more accurate clobbers_reg_p.  */
    2155      3135690 :           if (overlaps_hard_reg_set_p (callee_clobbers, GET_MODE (p->exp),
    2156      3135690 :                                        REGNO (p->exp)))
    2157      3114932 :             remove_from_table (p, hash);
    2158              :         }
    2159     15887571 : }
    2160              : 
    2161              : /* Given an expression X of type CONST,
    2162              :    and ELT which is its table entry (or 0 if it
    2163              :    is not in the hash table),
    2164              :    return an alternate expression for X as a register plus integer.
    2165              :    If none can be found, return 0.  */
    2166              : 
    2167              : static rtx
    2168       756853 : use_related_value (rtx x, struct table_elt *elt)
    2169              : {
    2170       756853 :   struct table_elt *relt = 0;
    2171       756853 :   struct table_elt *p, *q;
    2172       756853 :   HOST_WIDE_INT offset;
    2173              : 
    2174              :   /* First, is there anything related known?
    2175              :      If we have a table element, we can tell from that.
    2176              :      Otherwise, must look it up.  */
    2177              : 
    2178       756853 :   if (elt != 0 && elt->related_value != 0)
    2179              :     relt = elt;
    2180       579236 :   else if (elt == 0 && GET_CODE (x) == CONST)
    2181              :     {
    2182       579236 :       rtx subexp = get_related_value (x);
    2183       579236 :       if (subexp != 0)
    2184       565411 :         relt = lookup (subexp,
    2185              :                        SAFE_HASH (subexp, GET_MODE (subexp)),
    2186       565411 :                        GET_MODE (subexp));
    2187              :     }
    2188              : 
    2189       697653 :   if (relt == 0)
    2190              :     return 0;
    2191              : 
    2192              :   /* Search all related table entries for one that has an
    2193              :      equivalent register.  */
    2194              : 
    2195              :   p = relt;
    2196       900876 :   while (1)
    2197              :     {
    2198              :       /* This loop is strange in that it is executed in two different cases.
    2199              :          The first is when X is already in the table.  Then it is searching
    2200              :          the RELATED_VALUE list of X's class (RELT).  The second case is when
    2201              :          X is not in the table.  Then RELT points to a class for the related
    2202              :          value.
    2203              : 
    2204              :          Ensure that, whatever case we are in, that we ignore classes that have
    2205              :          the same value as X.  */
    2206              : 
    2207       900876 :       if (rtx_equal_p (x, p->exp))
    2208              :         q = 0;
    2209              :       else
    2210      1763286 :         for (q = p->first_same_value; q; q = q->next_same_value)
    2211      1224682 :           if (REG_P (q->exp))
    2212              :             break;
    2213              : 
    2214       768634 :       if (q)
    2215              :         break;
    2216              : 
    2217       670846 :       p = p->related_value;
    2218              : 
    2219              :       /* We went all the way around, so there is nothing to be found.
    2220              :          Alternatively, perhaps RELT was in the table for some other reason
    2221              :          and it has no related values recorded.  */
    2222       670846 :       if (p == relt || p == 0)
    2223              :         break;
    2224              :     }
    2225              : 
    2226       340112 :   if (q == 0)
    2227              :     return 0;
    2228              : 
    2229       230030 :   offset = (get_integer_term (x) - get_integer_term (p->exp));
    2230              :   /* Note: OFFSET may be 0 if P->xexp and X are related by commutativity.  */
    2231       230030 :   return plus_constant (q->mode, q->exp, offset);
    2232              : }
    2233              : 
    2234              : 
    2235              : /* Hash a string.  Just add its bytes up.  */
    2236              : static inline unsigned
    2237       133693 : hash_rtx_string (const char *ps)
    2238              : {
    2239       133693 :   unsigned hash = 0;
    2240       133693 :   const unsigned char *p = (const unsigned char *) ps;
    2241              : 
    2242       133693 :   if (p)
    2243       766342 :     while (*p)
    2244       632649 :       hash += *p++;
    2245              : 
    2246       133693 :   return hash;
    2247              : }
    2248              : 
    2249              : /* Hash an rtx.  We are careful to make sure the value is never negative.
    2250              :    Equivalent registers hash identically.
    2251              :    MODE is used in hashing for CONST_INTs only;
    2252              :    otherwise the mode of X is used.
    2253              : 
    2254              :    Store 1 in DO_NOT_RECORD_P if any subexpression is volatile.
    2255              : 
    2256              :    If HASH_ARG_IN_MEMORY_P is not NULL, store 1 in it if X contains
    2257              :    a MEM rtx which does not have the MEM_READONLY_P flag set.
    2258              : 
    2259              :    Note that cse_insn knows that the hash code of a MEM expression
    2260              :    is just (int) MEM plus the hash code of the address.
    2261              : 
    2262              :    Call CB on each rtx if CB is not NULL.
    2263              :    When the callback returns true, we continue with the new rtx.  */
    2264              : 
    2265              : unsigned
    2266   1318064986 : hash_rtx (const_rtx x, machine_mode mode,
    2267              :           int *do_not_record_p, int *hash_arg_in_memory_p,
    2268              :           bool have_reg_qty, hash_rtx_callback_function cb)
    2269              : {
    2270   1318064986 :   int i, j;
    2271   1318064986 :   unsigned hash = 0;
    2272   1944666285 :   enum rtx_code code;
    2273   1944666285 :   const char *fmt;
    2274   1944666285 :   machine_mode newmode;
    2275   1944666285 :   rtx newx;
    2276              : 
    2277              :   /* Used to turn recursion into iteration.  We can't rely on GCC's
    2278              :      tail-recursion elimination since we need to keep accumulating values
    2279              :      in HASH.  */
    2280    626601299 :  repeat:
    2281   1944666285 :   if (x == 0)
    2282              :     return hash;
    2283              : 
    2284              :   /* Invoke the callback first.  */
    2285   1944666285 :   if (cb != NULL
    2286   1944666285 :       && ((*cb) (x, mode, &newx, &newmode)))
    2287              :     {
    2288            0 :       hash += hash_rtx (newx, newmode, do_not_record_p,
    2289              :                         hash_arg_in_memory_p, have_reg_qty, cb);
    2290            0 :       return hash;
    2291              :     }
    2292              : 
    2293   1944666285 :   code = GET_CODE (x);
    2294   1944666285 :   switch (code)
    2295              :     {
    2296    675704217 :     case REG:
    2297    675704217 :       {
    2298    675704217 :         unsigned int regno = REGNO (x);
    2299              : 
    2300    675704217 :         if (do_not_record_p && !reload_completed)
    2301              :           {
    2302              :             /* On some machines, we can't record any non-fixed hard register,
    2303              :                because extending its life will cause reload problems.  We
    2304              :                consider ap, fp, sp, gp to be fixed for this purpose.
    2305              : 
    2306              :                We also consider CCmode registers to be fixed for this purpose;
    2307              :                failure to do so leads to failure to simplify 0<100 type of
    2308              :                conditionals.
    2309              : 
    2310              :                On all machines, we can't record any global registers.
    2311              :                Nor should we record any register that is in a small
    2312              :                class, as defined by TARGET_CLASS_LIKELY_SPILLED_P.  */
    2313    672060225 :             bool record;
    2314              : 
    2315    672060225 :             if (regno >= FIRST_PSEUDO_REGISTER)
    2316              :               record = true;
    2317    446047214 :             else if (x == frame_pointer_rtx
    2318    310595194 :                      || x == hard_frame_pointer_rtx
    2319    310478008 :                      || x == arg_pointer_rtx
    2320    302694013 :                      || x == stack_pointer_rtx
    2321    267134695 :                      || x == pic_offset_table_rtx)
    2322              :               record = true;
    2323    267134695 :             else if (global_regs[regno])
    2324              :               record = false;
    2325    267134318 :             else if (fixed_regs[regno])
    2326              :               record = true;
    2327     79134226 :             else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_CC)
    2328              :               record = true;
    2329     79134226 :             else if (targetm.small_register_classes_for_mode_p (GET_MODE (x)))
    2330              :               record = false;
    2331            0 :             else if (targetm.class_likely_spilled_p (REGNO_REG_CLASS (regno)))
    2332              :               record = false;
    2333              :             else
    2334              :               record = true;
    2335              : 
    2336              :             if (!record)
    2337              :               {
    2338     79134603 :                 *do_not_record_p = 1;
    2339     79134603 :                 return 0;
    2340              :               }
    2341              :           }
    2342              : 
    2343    596569614 :         hash += ((unsigned int) REG << 7);
    2344    596569614 :         hash += (have_reg_qty ? (unsigned) REG_QTY (regno) : regno);
    2345    596569614 :         return hash;
    2346              :       }
    2347              : 
    2348              :     /* We handle SUBREG of a REG specially because the underlying
    2349              :        reg changes its hash value with every value change; we don't
    2350              :        want to have to forget unrelated subregs when one subreg changes.  */
    2351     38112011 :     case SUBREG:
    2352     38112011 :       {
    2353     38112011 :         if (REG_P (SUBREG_REG (x)))
    2354              :           {
    2355     76092198 :             hash += (((unsigned int) SUBREG << 7)
    2356     38046099 :                      + REGNO (SUBREG_REG (x))
    2357     38046099 :                      + (constant_lower_bound (SUBREG_BYTE (x))
    2358     38046099 :                         / UNITS_PER_WORD));
    2359     38046099 :             return hash;
    2360              :           }
    2361              :         break;
    2362              :       }
    2363              : 
    2364    351910950 :     case CONST_INT:
    2365    351910950 :       hash += (((unsigned int) CONST_INT << 7) + (unsigned int) mode
    2366    351910950 :                + (unsigned int) INTVAL (x));
    2367    351910950 :       return hash;
    2368              : 
    2369              :     case CONST_WIDE_INT:
    2370      3082110 :       for (i = 0; i < CONST_WIDE_INT_NUNITS (x); i++)
    2371      2054904 :         hash += CONST_WIDE_INT_ELT (x, i);
    2372              :       return hash;
    2373              : 
    2374            0 :     case CONST_POLY_INT:
    2375            0 :       {
    2376            0 :         inchash::hash h;
    2377            0 :         h.add_int (hash);
    2378            0 :         for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
    2379            0 :           h.add_wide_int (CONST_POLY_INT_COEFFS (x)[i]);
    2380            0 :         return h.end ();
    2381              :       }
    2382              : 
    2383      4452653 :     case CONST_DOUBLE:
    2384              :       /* This is like the general case, except that it only counts
    2385              :          the integers representing the constant.  */
    2386      4452653 :       hash += (unsigned int) code + (unsigned int) GET_MODE (x);
    2387      4452653 :       if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (x) == VOIDmode)
    2388              :         hash += ((unsigned int) CONST_DOUBLE_LOW (x)
    2389              :                  + (unsigned int) CONST_DOUBLE_HIGH (x));
    2390              :       else
    2391      4452653 :         hash += real_hash (CONST_DOUBLE_REAL_VALUE (x));
    2392      4452653 :       return hash;
    2393              : 
    2394            0 :     case CONST_FIXED:
    2395            0 :       hash += (unsigned int) code + (unsigned int) GET_MODE (x);
    2396            0 :       hash += fixed_hash (CONST_FIXED_VALUE (x));
    2397            0 :       return hash;
    2398              : 
    2399      3980339 :     case CONST_VECTOR:
    2400      3980339 :       {
    2401      3980339 :         int units;
    2402      3980339 :         rtx elt;
    2403              : 
    2404      3980339 :         units = const_vector_encoded_nelts (x);
    2405              : 
    2406     10751698 :         for (i = 0; i < units; ++i)
    2407              :           {
    2408      6771359 :             elt = CONST_VECTOR_ENCODED_ELT (x, i);
    2409      6771359 :             hash += hash_rtx (elt, GET_MODE (elt),
    2410              :                               do_not_record_p, hash_arg_in_memory_p,
    2411              :                               have_reg_qty, cb);
    2412              :           }
    2413              : 
    2414              :         return hash;
    2415              :       }
    2416              : 
    2417              :       /* Assume there is only one rtx object for any given label.  */
    2418     20700928 :     case LABEL_REF:
    2419              :       /* We don't hash on the address of the CODE_LABEL to avoid bootstrap
    2420              :          differences and differences between each stage's debugging dumps.  */
    2421     20700928 :          hash += (((unsigned int) LABEL_REF << 7)
    2422     20700928 :                   + CODE_LABEL_NUMBER (label_ref_label (x)));
    2423     20700928 :       return hash;
    2424              : 
    2425    157272586 :     case SYMBOL_REF:
    2426    157272586 :       {
    2427              :         /* Don't hash on the symbol's address to avoid bootstrap differences.
    2428              :            Different hash values may cause expressions to be recorded in
    2429              :            different orders and thus different registers to be used in the
    2430              :            final assembler.  This also avoids differences in the dump files
    2431              :            between various stages.  */
    2432    157272586 :         unsigned int h = 0;
    2433    157272586 :         const unsigned char *p = (const unsigned char *) XSTR (x, 0);
    2434              : 
    2435   3547853639 :         while (*p)
    2436   3390581053 :           h += (h << 7) + *p++; /* ??? revisit */
    2437              : 
    2438    157272586 :         hash += ((unsigned int) SYMBOL_REF << 7) + h;
    2439    157272586 :         return hash;
    2440              :       }
    2441              : 
    2442    273580309 :     case MEM:
    2443              :       /* We don't record if marked volatile or if BLKmode since we don't
    2444              :          know the size of the move.  */
    2445    273580309 :       if (do_not_record_p && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode))
    2446              :         {
    2447      5583795 :           *do_not_record_p = 1;
    2448      5583795 :           return 0;
    2449              :         }
    2450    267996514 :       if (hash_arg_in_memory_p && !MEM_READONLY_P (x))
    2451     61079651 :         *hash_arg_in_memory_p = 1;
    2452              : 
    2453              :       /* Now that we have already found this special case,
    2454              :          might as well speed it up as much as possible.  */
    2455    267996514 :       hash += (unsigned) MEM;
    2456    267996514 :       x = XEXP (x, 0);
    2457    267996514 :       goto repeat;
    2458              : 
    2459           73 :     case USE:
    2460              :       /* A USE that mentions non-volatile memory needs special
    2461              :          handling since the MEM may be BLKmode which normally
    2462              :          prevents an entry from being made.  Pure calls are
    2463              :          marked by a USE which mentions BLKmode memory.
    2464              :          See calls.cc:emit_call_1.  */
    2465           73 :       if (MEM_P (XEXP (x, 0))
    2466           73 :           && ! MEM_VOLATILE_P (XEXP (x, 0)))
    2467              :         {
    2468            0 :           hash += (unsigned) USE;
    2469            0 :           x = XEXP (x, 0);
    2470              : 
    2471            0 :           if (hash_arg_in_memory_p && !MEM_READONLY_P (x))
    2472            0 :             *hash_arg_in_memory_p = 1;
    2473              : 
    2474              :           /* Now that we have already found this special case,
    2475              :              might as well speed it up as much as possible.  */
    2476            0 :           hash += (unsigned) MEM;
    2477            0 :           x = XEXP (x, 0);
    2478            0 :           goto repeat;
    2479              :         }
    2480              :       break;
    2481              : 
    2482     52657292 :     case PRE_DEC:
    2483     52657292 :     case PRE_INC:
    2484     52657292 :     case POST_DEC:
    2485     52657292 :     case POST_INC:
    2486     52657292 :     case PRE_MODIFY:
    2487     52657292 :     case POST_MODIFY:
    2488     52657292 :     case PC:
    2489     52657292 :     case CALL:
    2490     52657292 :     case UNSPEC_VOLATILE:
    2491     52657292 :       if (do_not_record_p) {
    2492     52655911 :         *do_not_record_p = 1;
    2493     52655911 :         return 0;
    2494              :       }
    2495              :       else
    2496              :         return hash;
    2497       214446 :       break;
    2498              : 
    2499       214446 :     case ASM_OPERANDS:
    2500       214446 :       if (do_not_record_p && MEM_VOLATILE_P (x))
    2501              :         {
    2502       176788 :           *do_not_record_p = 1;
    2503       176788 :           return 0;
    2504              :         }
    2505              :       else
    2506              :         {
    2507              :           /* We don't want to take the filename and line into account.  */
    2508        75316 :           hash += (unsigned) code + (unsigned) GET_MODE (x)
    2509        37658 :             + hash_rtx_string (ASM_OPERANDS_TEMPLATE (x))
    2510        37658 :             + hash_rtx_string (ASM_OPERANDS_OUTPUT_CONSTRAINT (x))
    2511        37658 :             + (unsigned) ASM_OPERANDS_OUTPUT_IDX (x);
    2512              : 
    2513        37658 :           if (ASM_OPERANDS_INPUT_LENGTH (x))
    2514              :             {
    2515        58377 :               for (i = 1; i < ASM_OPERANDS_INPUT_LENGTH (x); i++)
    2516              :                 {
    2517        51064 :                   hash += (hash_rtx (ASM_OPERANDS_INPUT (x, i),
    2518        25532 :                                      GET_MODE (ASM_OPERANDS_INPUT (x, i)),
    2519              :                                      do_not_record_p, hash_arg_in_memory_p,
    2520              :                                      have_reg_qty, cb)
    2521        25532 :                            + hash_rtx_string
    2522        51064 :                            (ASM_OPERANDS_INPUT_CONSTRAINT (x, i)));
    2523              :                 }
    2524              : 
    2525        32845 :               hash += hash_rtx_string (ASM_OPERANDS_INPUT_CONSTRAINT (x, 0));
    2526        32845 :               x = ASM_OPERANDS_INPUT (x, 0);
    2527        32845 :               mode = GET_MODE (x);
    2528        32845 :               goto repeat;
    2529              :             }
    2530              : 
    2531              :           return hash;
    2532              :         }
    2533              :       break;
    2534              : 
    2535              :     default:
    2536              :       break;
    2537              :     }
    2538              : 
    2539    365119260 :   i = GET_RTX_LENGTH (code) - 1;
    2540    365119260 :   hash += (unsigned) code + (unsigned) GET_MODE (x);
    2541    365119260 :   fmt = GET_RTX_FORMAT (code);
    2542    738575914 :   for (; i >= 0; i--)
    2543              :     {
    2544    732028594 :       switch (fmt[i])
    2545              :         {
    2546    720070571 :         case 'e':
    2547              :           /* If we are about to do the last recursive call
    2548              :              needed at this level, change it into iteration.
    2549              :              This function  is called enough to be worth it.  */
    2550    720070571 :           if (i == 0)
    2551              :             {
    2552    358571940 :               x = XEXP (x, i);
    2553    358571940 :               goto repeat;
    2554              :             }
    2555              : 
    2556    361498631 :           hash += hash_rtx (XEXP (x, i), VOIDmode, do_not_record_p,
    2557              :                             hash_arg_in_memory_p,
    2558              :                             have_reg_qty, cb);
    2559    361498631 :           break;
    2560              : 
    2561              :         case 'E':
    2562     16828935 :           for (j = 0; j < XVECLEN (x, i); j++)
    2563     10281863 :             hash += hash_rtx (XVECEXP (x, i, j), VOIDmode, do_not_record_p,
    2564              :                               hash_arg_in_memory_p,
    2565              :                               have_reg_qty, cb);
    2566              :           break;
    2567              : 
    2568            0 :         case 's':
    2569            0 :           hash += hash_rtx_string (XSTR (x, i));
    2570            0 :           break;
    2571              : 
    2572      5344987 :         case 'i':
    2573      5344987 :           hash += (unsigned int) XINT (x, i);
    2574      5344987 :           break;
    2575              : 
    2576            0 :         case 'L':
    2577            0 :           hash += (unsigned int) XLOC (x, i);
    2578            0 :           break;
    2579              : 
    2580        65912 :         case 'p':
    2581        65912 :           hash += constant_lower_bound (SUBREG_BYTE (x));
    2582        65912 :           break;
    2583              : 
    2584              :         case '0': case 't':
    2585              :           /* Unused.  */
    2586              :           break;
    2587              : 
    2588            0 :         default:
    2589            0 :           gcc_unreachable ();
    2590              :         }
    2591              :     }
    2592              : 
    2593              :   return hash;
    2594              : }
    2595              : 
    2596              : /* Hash an rtx X for cse via hash_rtx.
    2597              :    Stores 1 in do_not_record if any subexpression is volatile.
    2598              :    Stores 1 in hash_arg_in_memory if X contains a mem rtx which
    2599              :    does not have the MEM_READONLY_P flag set.  */
    2600              : 
    2601              : static inline unsigned
    2602    529675208 : canon_hash (rtx x, machine_mode mode)
    2603              : {
    2604    529675208 :   return hash_rtx (x, mode, &do_not_record, &hash_arg_in_memory, true);
    2605              : }
    2606              : 
    2607              : /* Like canon_hash but with no side effects, i.e. do_not_record
    2608              :    and hash_arg_in_memory are not changed.  */
    2609              : 
    2610              : static inline unsigned
    2611    170891664 : safe_hash (rtx x, machine_mode mode)
    2612              : {
    2613    170891664 :   int dummy_do_not_record;
    2614    170891664 :   return hash_rtx (x, mode, &dummy_do_not_record, NULL, true);
    2615              : }
    2616              : 
    2617              : /* Return true iff X and Y would canonicalize into the same thing,
    2618              :    without actually constructing the canonicalization of either one.
    2619              :    If VALIDATE is nonzero,
    2620              :    we assume X is an expression being processed from the rtl
    2621              :    and Y was found in the hash table.  We check register refs
    2622              :    in Y for being marked as valid.
    2623              : 
    2624              :    If FOR_GCSE is true, we compare X and Y for equivalence for GCSE.  */
    2625              : 
    2626              : bool
    2627    801153770 : exp_equiv_p (const_rtx x, const_rtx y, int validate, bool for_gcse)
    2628              : {
    2629    801153770 :   int i, j;
    2630    801153770 :   enum rtx_code code;
    2631    801153770 :   const char *fmt;
    2632              : 
    2633              :   /* Note: it is incorrect to assume an expression is equivalent to itself
    2634              :      if VALIDATE is nonzero.  */
    2635    801153770 :   if (x == y && !validate)
    2636              :     return true;
    2637              : 
    2638    777562294 :   if (x == 0 || y == 0)
    2639              :     return x == y;
    2640              : 
    2641    777562294 :   code = GET_CODE (x);
    2642    777562294 :   if (code != GET_CODE (y))
    2643              :     return false;
    2644              : 
    2645              :   /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.  */
    2646    665504426 :   if (GET_MODE (x) != GET_MODE (y))
    2647              :     return false;
    2648              : 
    2649              :   /* MEMs referring to different address space are not equivalent.  */
    2650    696541138 :   if (code == MEM && MEM_ADDR_SPACE (x) != MEM_ADDR_SPACE (y))
    2651              :     return false;
    2652              : 
    2653    587466687 :   switch (code)
    2654              :     {
    2655              :     case PC:
    2656              :     CASE_CONST_UNIQUE:
    2657              :       return x == y;
    2658              : 
    2659              :     case CONST_VECTOR:
    2660              :       if (!same_vector_encodings_p (x, y))
    2661              :         return false;
    2662              :       break;
    2663              : 
    2664        24175 :     case LABEL_REF:
    2665        24175 :       return label_ref_label (x) == label_ref_label (y);
    2666              : 
    2667     18752664 :     case SYMBOL_REF:
    2668     18752664 :       return XSTR (x, 0) == XSTR (y, 0);
    2669              : 
    2670    170879452 :     case REG:
    2671    170879452 :       if (for_gcse)
    2672      1306481 :         return REGNO (x) == REGNO (y);
    2673              :       else
    2674              :         {
    2675    169572971 :           unsigned int regno = REGNO (y);
    2676    169572971 :           unsigned int i;
    2677    169572971 :           unsigned int endregno = END_REGNO (y);
    2678              : 
    2679              :           /* If the quantities are not the same, the expressions are not
    2680              :              equivalent.  If there are and we are not to validate, they
    2681              :              are equivalent.  Otherwise, ensure all regs are up-to-date.  */
    2682              : 
    2683    169572971 :           if (REG_QTY (REGNO (x)) != REG_QTY (regno))
    2684              :             return false;
    2685              : 
    2686    155580448 :           if (! validate)
    2687              :             return true;
    2688              : 
    2689    287494615 :           for (i = regno; i < endregno; i++)
    2690    144933970 :             if (REG_IN_TABLE (i) != REG_TICK (i))
    2691              :               return false;
    2692              : 
    2693              :           return true;
    2694              :         }
    2695              : 
    2696    107635553 :     case MEM:
    2697    107635553 :       if (for_gcse)
    2698              :         {
    2699              :           /* A volatile mem should not be considered equivalent to any
    2700              :              other.  */
    2701     59469808 :           if (MEM_VOLATILE_P (x) || MEM_VOLATILE_P (y))
    2702              :             return false;
    2703              : 
    2704              :           /* Can't merge two expressions in different alias sets, since we
    2705              :              can decide that the expression is transparent in a block when
    2706              :              it isn't, due to it being set with the different alias set.
    2707              : 
    2708              :              Also, can't merge two expressions with different MEM_ATTRS.
    2709              :              They could e.g. be two different entities allocated into the
    2710              :              same space on the stack (see e.g. PR25130).  In that case, the
    2711              :              MEM addresses can be the same, even though the two MEMs are
    2712              :              absolutely not equivalent.
    2713              : 
    2714              :              But because really all MEM attributes should be the same for
    2715              :              equivalent MEMs, we just use the invariant that MEMs that have
    2716              :              the same attributes share the same mem_attrs data structure.  */
    2717     59357912 :           if (!mem_attrs_eq_p (MEM_ATTRS (x), MEM_ATTRS (y)))
    2718              :             return false;
    2719              : 
    2720              :           /* If we are handling exceptions, we cannot consider two expressions
    2721              :              with different trapping status as equivalent, because simple_mem
    2722              :              might accept one and reject the other.  */
    2723      9220182 :           if (cfun->can_throw_non_call_exceptions
    2724      9220182 :               && (MEM_NOTRAP_P (x) != MEM_NOTRAP_P (y)))
    2725              :             return false;
    2726              :         }
    2727              :       break;
    2728              : 
    2729      8595652 :     case SUBREG:
    2730              :       /* Two SUBREGs of the same REG are not interchangeable if they differ
    2731              :          in their promotion state.  */
    2732      8595652 :       if (SUBREG_PROMOTED_VAR_P (x) != SUBREG_PROMOTED_VAR_P (y)
    2733      8595652 :           || (SUBREG_PROMOTED_VAR_P (x)
    2734        58301 :               && SUBREG_PROMOTED_GET (x) != SUBREG_PROMOTED_GET (y)))
    2735              :         return false;
    2736              :       break;
    2737              : 
    2738              :     /*  For commutative operations, check both orders.  */
    2739     74390120 :     case PLUS:
    2740     74390120 :     case MULT:
    2741     74390120 :     case AND:
    2742     74390120 :     case IOR:
    2743     74390120 :     case XOR:
    2744     74390120 :     case NE:
    2745     74390120 :     case EQ:
    2746     74390120 :       return ((exp_equiv_p (XEXP (x, 0), XEXP (y, 0),
    2747              :                              validate, for_gcse)
    2748     68589709 :                && exp_equiv_p (XEXP (x, 1), XEXP (y, 1),
    2749              :                                 validate, for_gcse))
    2750     81485960 :               || (exp_equiv_p (XEXP (x, 0), XEXP (y, 1),
    2751              :                                 validate, for_gcse)
    2752        19478 :                   && exp_equiv_p (XEXP (x, 1), XEXP (y, 0),
    2753              :                                    validate, for_gcse)));
    2754              : 
    2755        13120 :     case ASM_OPERANDS:
    2756              :       /* We don't use the generic code below because we want to
    2757              :          disregard filename and line numbers.  */
    2758              : 
    2759              :       /* A volatile asm isn't equivalent to any other.  */
    2760        13120 :       if (MEM_VOLATILE_P (x) || MEM_VOLATILE_P (y))
    2761              :         return false;
    2762              : 
    2763        13120 :       if (GET_MODE (x) != GET_MODE (y)
    2764        13120 :           || strcmp (ASM_OPERANDS_TEMPLATE (x), ASM_OPERANDS_TEMPLATE (y))
    2765        13120 :           || strcmp (ASM_OPERANDS_OUTPUT_CONSTRAINT (x),
    2766        13120 :                      ASM_OPERANDS_OUTPUT_CONSTRAINT (y))
    2767        13110 :           || ASM_OPERANDS_OUTPUT_IDX (x) != ASM_OPERANDS_OUTPUT_IDX (y)
    2768        13110 :           || ASM_OPERANDS_INPUT_LENGTH (x) != ASM_OPERANDS_INPUT_LENGTH (y))
    2769              :         return false;
    2770              : 
    2771        13110 :       if (ASM_OPERANDS_INPUT_LENGTH (x))
    2772              :         {
    2773        17811 :           for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
    2774         9021 :             if (! exp_equiv_p (ASM_OPERANDS_INPUT (x, i),
    2775         9021 :                                ASM_OPERANDS_INPUT (y, i),
    2776              :                                validate, for_gcse)
    2777         9021 :                 || strcmp (ASM_OPERANDS_INPUT_CONSTRAINT (x, i),
    2778         8908 :                            ASM_OPERANDS_INPUT_CONSTRAINT (y, i)))
    2779              :               return false;
    2780              :         }
    2781              : 
    2782              :       return true;
    2783              : 
    2784              :     default:
    2785              :       break;
    2786              :     }
    2787              : 
    2788              :   /* Compare the elements.  If any pair of corresponding elements
    2789              :      fail to match, return 0 for the whole thing.  */
    2790              : 
    2791    128328404 :   fmt = GET_RTX_FORMAT (code);
    2792    358156250 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    2793              :     {
    2794    242567212 :       switch (fmt[i])
    2795              :         {
    2796    163090240 :         case 'e':
    2797    163090240 :           if (! exp_equiv_p (XEXP (x, i), XEXP (y, i),
    2798              :                               validate, for_gcse))
    2799              :             return false;
    2800              :           break;
    2801              : 
    2802      9874135 :         case 'E':
    2803      9874135 :           if (XVECLEN (x, i) != XVECLEN (y, i))
    2804              :             return 0;
    2805     47554987 :           for (j = 0; j < XVECLEN (x, i); j++)
    2806     38589891 :             if (! exp_equiv_p (XVECEXP (x, i, j), XVECEXP (y, i, j),
    2807              :                                 validate, for_gcse))
    2808              :               return false;
    2809              :           break;
    2810              : 
    2811            0 :         case 's':
    2812            0 :           if (strcmp (XSTR (x, i), XSTR (y, i)))
    2813              :             return false;
    2814              :           break;
    2815              : 
    2816      3636014 :         case 'i':
    2817      3636014 :           if (XINT (x, i) != XINT (y, i))
    2818              :             return false;
    2819              :           break;
    2820              : 
    2821            0 :         case 'L':
    2822            0 :           if (XLOC (x, i) != XLOC (y, i))
    2823              :             return false;
    2824              :           break;
    2825              : 
    2826            0 :         case 'w':
    2827            0 :           if (XWINT (x, i) != XWINT (y, i))
    2828              :             return false;
    2829              :           break;
    2830              : 
    2831      8590538 :         case 'p':
    2832      8590538 :           if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y)))
    2833              :             return false;
    2834              :           break;
    2835              : 
    2836              :         case '0':
    2837              :         case 't':
    2838              :           break;
    2839              : 
    2840            0 :         default:
    2841            0 :           gcc_unreachable ();
    2842              :         }
    2843              :     }
    2844              : 
    2845              :   return true;
    2846              : }
    2847              : 
    2848              : /* Subroutine of canon_reg.  Pass *XLOC through canon_reg, and validate
    2849              :    the result if necessary.  INSN is as for canon_reg.  */
    2850              : 
    2851              : static void
    2852   1060206380 : validate_canon_reg (rtx *xloc, rtx_insn *insn)
    2853              : {
    2854   1060206380 :   if (*xloc)
    2855              :     {
    2856   1060206380 :       rtx new_rtx = canon_reg (*xloc, insn);
    2857              : 
    2858              :       /* If replacing pseudo with hard reg or vice versa, ensure the
    2859              :          insn remains valid.  Likewise if the insn has MATCH_DUPs.  */
    2860   1060206380 :       gcc_assert (insn && new_rtx);
    2861   1060206380 :       validate_change (insn, xloc, new_rtx, 1);
    2862              :     }
    2863   1060206380 : }
    2864              : 
    2865              : /* Canonicalize an expression:
    2866              :    replace each register reference inside it
    2867              :    with the "oldest" equivalent register.
    2868              : 
    2869              :    If INSN is nonzero validate_change is used to ensure that INSN remains valid
    2870              :    after we make our substitution.  The calls are made with IN_GROUP nonzero
    2871              :    so apply_change_group must be called upon the outermost return from this
    2872              :    function (unless INSN is zero).  The result of apply_change_group can
    2873              :    generally be discarded since the changes we are making are optional.  */
    2874              : 
    2875              : static rtx
    2876   1756733483 : canon_reg (rtx x, rtx_insn *insn)
    2877              : {
    2878   1756733483 :   int i;
    2879   1756733483 :   enum rtx_code code;
    2880   1756733483 :   const char *fmt;
    2881              : 
    2882   1756733483 :   if (x == 0)
    2883              :     return x;
    2884              : 
    2885   1756733483 :   code = GET_CODE (x);
    2886   1756733483 :   switch (code)
    2887              :     {
    2888              :     case PC:
    2889              :     case CONST:
    2890              :     CASE_CONST_ANY:
    2891              :     case SYMBOL_REF:
    2892              :     case LABEL_REF:
    2893              :     case ADDR_VEC:
    2894              :     case ADDR_DIFF_VEC:
    2895              :       return x;
    2896              : 
    2897     10418219 :     case SUBREG:
    2898     10418219 :       {
    2899     10418219 :         rtx inner = canon_reg (SUBREG_REG (x), insn);
    2900     10418219 :         if (inner != SUBREG_REG (x))
    2901              :           {
    2902       268310 :             rtx newx = simplify_subreg (GET_MODE (x), inner,
    2903       134155 :                                         GET_MODE (SUBREG_REG (x)),
    2904       134155 :                                         SUBREG_BYTE (x));
    2905       134155 :             if (newx)
    2906              :               return newx;
    2907              : 
    2908       134155 :             if (validate_subreg (GET_MODE (x), GET_MODE (inner),
    2909       134155 :                                  inner, SUBREG_BYTE (x)))
    2910              :               {
    2911              :                 /* This is going to re-use the existing SUBREG
    2912              :                    expression, but the substitution may make the
    2913              :                    previously known promotion state invalid.  */
    2914       134155 :                 validate_change (insn, &SUBREG_REG (x), inner, 1);
    2915       134155 :                 if (GET_CODE (x) == SUBREG)
    2916       134155 :                   SUBREG_PROMOTED_VAR_P (x) = 0;
    2917              :               }
    2918              :           }
    2919              :         return x;
    2920              :       }
    2921              : 
    2922    485861451 :     case REG:
    2923    485861451 :       {
    2924    485861451 :         int first;
    2925    485861451 :         int q;
    2926    485861451 :         struct qty_table_elem *ent;
    2927              : 
    2928              :         /* Never replace a hard reg, because hard regs can appear
    2929              :            in more than one machine mode, and we must preserve the mode
    2930              :            of each occurrence.  Also, some hard regs appear in
    2931              :            MEMs that are shared and mustn't be altered.  Don't try to
    2932              :            replace any reg that maps to a reg of class NO_REGS.  */
    2933    485861451 :         if (REGNO (x) < FIRST_PSEUDO_REGISTER
    2934    485861451 :             || ! REGNO_QTY_VALID_P (REGNO (x)))
    2935              :           return x;
    2936              : 
    2937    172118848 :         q = REG_QTY (REGNO (x));
    2938    172118848 :         ent = &qty_table[q];
    2939    172118848 :         first = ent->first_reg;
    2940    172118848 :         return (first >= FIRST_PSEUDO_REGISTER ? regno_reg_rtx[first]
    2941       408350 :                 : REGNO_REG_CLASS (first) == NO_REGS ? x
    2942    172118848 :                 : gen_rtx_REG (ent->mode, first));
    2943              :       }
    2944              : 
    2945    776023902 :     default:
    2946    776023902 :       break;
    2947              :     }
    2948              : 
    2949    776023902 :   fmt = GET_RTX_FORMAT (code);
    2950   2133813017 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    2951              :     {
    2952   1357789115 :       int j;
    2953              : 
    2954   1357789115 :       if (fmt[i] == 'e')
    2955   1046560658 :         validate_canon_reg (&XEXP (x, i), insn);
    2956    311228457 :       else if (fmt[i] == 'E')
    2957     20582703 :         for (j = 0; j < XVECLEN (x, i); j++)
    2958     13645722 :           validate_canon_reg (&XVECEXP (x, i, j), insn);
    2959              :     }
    2960              : 
    2961              :   return x;
    2962              : }
    2963              : 
    2964              : /* Given an operation (CODE, *PARG1, *PARG2), where code is a comparison
    2965              :    operation (EQ, NE, GT, etc.), follow it back through the hash table and
    2966              :    what values are being compared.
    2967              : 
    2968              :    *PARG1 and *PARG2 are updated to contain the rtx representing the values
    2969              :    actually being compared.  For example, if *PARG1 was (reg:CC CC_REG) and
    2970              :    *PARG2 was (const_int 0), *PARG1 and *PARG2 will be set to the objects that
    2971              :    were compared to produce (reg:CC CC_REG).
    2972              : 
    2973              :    The return value is the comparison operator and is either the code of
    2974              :    A or the code corresponding to the inverse of the comparison.  */
    2975              : 
    2976              : static enum rtx_code
    2977     37557320 : find_comparison_args (enum rtx_code code, rtx *parg1, rtx *parg2,
    2978              :                       machine_mode *pmode1, machine_mode *pmode2)
    2979              : {
    2980     37557320 :   rtx arg1, arg2;
    2981     37557320 :   hash_set<rtx> *visited = NULL;
    2982              :   /* Set nonzero when we find something of interest.  */
    2983     37557320 :   rtx x = NULL;
    2984              : 
    2985     37557320 :   arg1 = *parg1, arg2 = *parg2;
    2986              : 
    2987              :   /* If ARG2 is const0_rtx, see what ARG1 is equivalent to.  */
    2988              : 
    2989     73184720 :   while (arg2 == CONST0_RTX (GET_MODE (arg1)))
    2990              :     {
    2991     54667270 :       int reverse_code = 0;
    2992     54667270 :       struct table_elt *p = 0;
    2993              : 
    2994              :       /* Remember state from previous iteration.  */
    2995     54667270 :       if (x)
    2996              :         {
    2997     17186777 :           if (!visited)
    2998     17182243 :             visited = new hash_set<rtx>;
    2999     17186777 :           visited->add (x);
    3000     17186777 :           x = 0;
    3001              :         }
    3002              : 
    3003              :       /* If arg1 is a COMPARE, extract the comparison arguments from it.  */
    3004              : 
    3005     54667270 :       if (GET_CODE (arg1) == COMPARE && arg2 == const0_rtx)
    3006            0 :         x = arg1;
    3007              : 
    3008              :       /* If ARG1 is a comparison operator and CODE is testing for
    3009              :          STORE_FLAG_VALUE, get the inner arguments.  */
    3010              : 
    3011     54667270 :       else if (COMPARISON_P (arg1))
    3012              :         {
    3013              : #ifdef FLOAT_STORE_FLAG_VALUE
    3014              :           REAL_VALUE_TYPE fsfv;
    3015              : #endif
    3016              : 
    3017            0 :           if (code == NE
    3018              :               || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_INT
    3019              :                   && code == LT && STORE_FLAG_VALUE == -1)
    3020              : #ifdef FLOAT_STORE_FLAG_VALUE
    3021              :               || (SCALAR_FLOAT_MODE_P (GET_MODE (arg1))
    3022              :                   && (fsfv = FLOAT_STORE_FLAG_VALUE (GET_MODE (arg1)),
    3023              :                       REAL_VALUE_NEGATIVE (fsfv)))
    3024              : #endif
    3025              :               )
    3026            0 :             x = arg1;
    3027            0 :           else if (code == EQ
    3028              :                    || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_INT
    3029              :                        && code == GE && STORE_FLAG_VALUE == -1)
    3030              : #ifdef FLOAT_STORE_FLAG_VALUE
    3031              :                    || (SCALAR_FLOAT_MODE_P (GET_MODE (arg1))
    3032              :                        && (fsfv = FLOAT_STORE_FLAG_VALUE (GET_MODE (arg1)),
    3033              :                            REAL_VALUE_NEGATIVE (fsfv)))
    3034              : #endif
    3035              :                    )
    3036            0 :             x = arg1, reverse_code = 1;
    3037              :         }
    3038              : 
    3039              :       /* ??? We could also check for
    3040              : 
    3041              :          (ne (and (eq (...) (const_int 1))) (const_int 0))
    3042              : 
    3043              :          and related forms, but let's wait until we see them occurring.  */
    3044              : 
    3045     54667270 :       if (x == 0)
    3046              :         /* Look up ARG1 in the hash table and see if it has an equivalence
    3047              :            that lets us see what is being compared.  */
    3048     54667270 :         p = lookup (arg1, SAFE_HASH (arg1, GET_MODE (arg1)), GET_MODE (arg1));
    3049     54667270 :       if (p)
    3050              :         {
    3051     43650995 :           p = p->first_same_value;
    3052              : 
    3053              :           /* If what we compare is already known to be constant, that is as
    3054              :              good as it gets.
    3055              :              We need to break the loop in this case, because otherwise we
    3056              :              can have an infinite loop when looking at a reg that is known
    3057              :              to be a constant which is the same as a comparison of a reg
    3058              :              against zero which appears later in the insn stream, which in
    3059              :              turn is constant and the same as the comparison of the first reg
    3060              :              against zero...  */
    3061     43650995 :           if (p->is_const)
    3062              :             break;
    3063              :         }
    3064              : 
    3065     70016846 :       for (; p; p = p->next_same_value)
    3066              :         {
    3067     50982604 :           machine_mode inner_mode = GET_MODE (p->exp);
    3068              : #ifdef FLOAT_STORE_FLAG_VALUE
    3069              :           REAL_VALUE_TYPE fsfv;
    3070              : #endif
    3071              : 
    3072              :           /* If the entry isn't valid, skip it.  */
    3073     50982604 :           if (! exp_equiv_p (p->exp, p->exp, 1, false))
    3074      1850240 :             continue;
    3075              : 
    3076              :           /* If it's a comparison we've used before, skip it.  */
    3077     49132364 :           if (visited && visited->contains (p->exp))
    3078            0 :             continue;
    3079              : 
    3080     49132364 :           if (GET_CODE (p->exp) == COMPARE
    3081              :               /* Another possibility is that this machine has a compare insn
    3082              :                  that includes the comparison code.  In that case, ARG1 would
    3083              :                  be equivalent to a comparison operation that would set ARG1 to
    3084              :                  either STORE_FLAG_VALUE or zero.  If this is an NE operation,
    3085              :                  ORIG_CODE is the actual comparison being done; if it is an EQ,
    3086              :                  we must reverse ORIG_CODE.  On machine with a negative value
    3087              :                  for STORE_FLAG_VALUE, also look at LT and GE operations.  */
    3088     49132364 :               || ((code == NE
    3089      9194139 :                    || (code == LT
    3090       262487 :                        && val_signbit_known_set_p (inner_mode,
    3091              :                                                    STORE_FLAG_VALUE))
    3092              : #ifdef FLOAT_STORE_FLAG_VALUE
    3093              :                    || (code == LT
    3094              :                        && SCALAR_FLOAT_MODE_P (inner_mode)
    3095              :                        && (fsfv = FLOAT_STORE_FLAG_VALUE (GET_MODE (arg1)),
    3096              :                            REAL_VALUE_NEGATIVE (fsfv)))
    3097              : #endif
    3098              :                    )
    3099      4418774 :                   && COMPARISON_P (p->exp)))
    3100              :             {
    3101     35522820 :               x = p->exp;
    3102     35522820 :               break;
    3103              :             }
    3104     13609544 :           else if ((code == EQ
    3105      7629231 :                     || (code == GE
    3106       228943 :                         && val_signbit_known_set_p (inner_mode,
    3107              :                                                     STORE_FLAG_VALUE))
    3108              : #ifdef FLOAT_STORE_FLAG_VALUE
    3109              :                     || (code == GE
    3110              :                         && SCALAR_FLOAT_MODE_P (inner_mode)
    3111              :                         && (fsfv = FLOAT_STORE_FLAG_VALUE (GET_MODE (arg1)),
    3112              :                             REAL_VALUE_NEGATIVE (fsfv)))
    3113              : #endif
    3114              :                     )
    3115     13609544 :                    && COMPARISON_P (p->exp))
    3116              :             {
    3117       104580 :               reverse_code = 1;
    3118       104580 :               x = p->exp;
    3119       104580 :               break;
    3120              :             }
    3121              : 
    3122              :           /* If this non-trapping address, e.g. fp + constant, the
    3123              :              equivalent is a better operand since it may let us predict
    3124              :              the value of the comparison.  */
    3125     13504964 :           else if (!rtx_addr_can_trap_p (p->exp))
    3126              :             {
    3127            0 :               arg1 = p->exp;
    3128            0 :               continue;
    3129              :             }
    3130              :         }
    3131              : 
    3132              :       /* If we didn't find a useful equivalence for ARG1, we are done.
    3133              :          Otherwise, set up for the next iteration.  */
    3134     54661642 :       if (x == 0)
    3135              :         break;
    3136              : 
    3137              :       /* If we need to reverse the comparison, make sure that is
    3138              :          possible -- we can't necessarily infer the value of GE from LT
    3139              :          with floating-point operands.  */
    3140     35627400 :       if (reverse_code)
    3141              :         {
    3142       104580 :           enum rtx_code reversed = reversed_comparison_code (x, NULL);
    3143       104580 :           if (reversed == UNKNOWN)
    3144              :             break;
    3145              :           else
    3146              :             code = reversed;
    3147              :         }
    3148     35522820 :       else if (COMPARISON_P (x))
    3149         3369 :         code = GET_CODE (x);
    3150     35627400 :       arg1 = XEXP (x, 0), arg2 = XEXP (x, 1);
    3151              :     }
    3152              : 
    3153              :   /* Return our results.  Return the modes from before fold_rtx
    3154              :      because fold_rtx might produce const_int, and then it's too late.  */
    3155     37557320 :   *pmode1 = GET_MODE (arg1), *pmode2 = GET_MODE (arg2);
    3156     37557320 :   *parg1 = fold_rtx (arg1, 0), *parg2 = fold_rtx (arg2, 0);
    3157              : 
    3158     37557320 :   if (visited)
    3159     17182243 :     delete visited;
    3160     37557320 :   return code;
    3161              : }
    3162              : 
    3163              : /* If X is a nontrivial arithmetic operation on an argument for which
    3164              :    a constant value can be determined, return the result of operating
    3165              :    on that value, as a constant.  Otherwise, return X, possibly with
    3166              :    one or more operands changed to a forward-propagated constant.
    3167              : 
    3168              :    If X is a register whose contents are known, we do NOT return
    3169              :    those contents here; equiv_constant is called to perform that task.
    3170              :    For SUBREGs and MEMs, we do that both here and in equiv_constant.
    3171              : 
    3172              :    INSN is the insn that we may be modifying.  If it is 0, make a copy
    3173              :    of X before modifying it.  */
    3174              : 
    3175              : static rtx
    3176    407057294 : fold_rtx (rtx x, rtx_insn *insn)
    3177              : {
    3178    407059125 :   enum rtx_code code;
    3179    407059125 :   machine_mode mode;
    3180    407059125 :   const char *fmt;
    3181    407059125 :   int i;
    3182    407059125 :   rtx new_rtx = 0;
    3183    407059125 :   bool changed = false;
    3184    407059125 :   poly_int64 xval;
    3185              : 
    3186              :   /* Operands of X.  */
    3187              :   /* Workaround -Wmaybe-uninitialized false positive during
    3188              :      profiledbootstrap by initializing them.  */
    3189    407059125 :   rtx folded_arg0 = NULL_RTX;
    3190    407059125 :   rtx folded_arg1 = NULL_RTX;
    3191              : 
    3192              :   /* Constant equivalents of first three operands of X;
    3193              :      0 when no such equivalent is known.  */
    3194    407059125 :   rtx const_arg0;
    3195    407059125 :   rtx const_arg1;
    3196    407059125 :   rtx const_arg2;
    3197              : 
    3198              :   /* The mode of the first operand of X.  We need this for sign and zero
    3199              :      extends.  */
    3200    407059125 :   machine_mode mode_arg0;
    3201              : 
    3202    407059125 :   if (x == 0)
    3203              :     return x;
    3204              : 
    3205              :   /* Try to perform some initial simplifications on X.  */
    3206    407059125 :   code = GET_CODE (x);
    3207    407059125 :   switch (code)
    3208              :     {
    3209     63673979 :     case MEM:
    3210     63673979 :     case SUBREG:
    3211              :     /* The first operand of a SIGN/ZERO_EXTRACT has a different meaning
    3212              :        than it would in other contexts.  Basically its mode does not
    3213              :        signify the size of the object read.  That information is carried
    3214              :        by size operand.    If we happen to have a MEM of the appropriate
    3215              :        mode in our tables with a constant value we could simplify the
    3216              :        extraction incorrectly if we allowed substitution of that value
    3217              :        for the MEM.   */
    3218     63673979 :     case ZERO_EXTRACT:
    3219     63673979 :     case SIGN_EXTRACT:
    3220     63673979 :       if ((new_rtx = equiv_constant (x)) != NULL_RTX)
    3221      2367051 :         return new_rtx;
    3222              :       return x;
    3223              : 
    3224              :     case CONST:
    3225              :     CASE_CONST_ANY:
    3226              :     case SYMBOL_REF:
    3227              :     case LABEL_REF:
    3228              :     case REG:
    3229              :     case PC:
    3230              :       /* No use simplifying an EXPR_LIST
    3231              :          since they are used only for lists of args
    3232              :          in a function call's REG_EQUAL note.  */
    3233              :     case EXPR_LIST:
    3234              :       return x;
    3235              : 
    3236       213512 :     case ASM_OPERANDS:
    3237       213512 :       if (insn)
    3238              :         {
    3239            0 :           for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
    3240            0 :             validate_change (insn, &ASM_OPERANDS_INPUT (x, i),
    3241            0 :                              fold_rtx (ASM_OPERANDS_INPUT (x, i), insn), 0);
    3242              :         }
    3243              :       return x;
    3244              : 
    3245     15887571 :     case CALL:
    3246     15887571 :       if (NO_FUNCTION_CSE && CONSTANT_P (XEXP (XEXP (x, 0), 0)))
    3247              :         return x;
    3248              :       break;
    3249       959539 :     case VEC_SELECT:
    3250       959539 :       {
    3251       959539 :         rtx trueop0 = XEXP (x, 0);
    3252       959539 :         mode = GET_MODE (trueop0);
    3253       959539 :         rtx trueop1 = XEXP (x, 1);
    3254              :         /* If we select a low-part subreg, return that.  */
    3255       959539 :         if (vec_series_lowpart_p (GET_MODE (x), mode, trueop1))
    3256              :           {
    3257          219 :             rtx new_rtx = lowpart_subreg (GET_MODE (x), trueop0, mode);
    3258          219 :             if (new_rtx != NULL_RTX)
    3259              :               return new_rtx;
    3260              :           }
    3261              :       }
    3262              : 
    3263              :     /* Anything else goes through the loop below.  */
    3264              :     default:
    3265              :       break;
    3266              :     }
    3267              : 
    3268    119154088 :   mode = GET_MODE (x);
    3269    119154088 :   const_arg0 = 0;
    3270    119154088 :   const_arg1 = 0;
    3271    119154088 :   const_arg2 = 0;
    3272    119154088 :   mode_arg0 = VOIDmode;
    3273              : 
    3274              :   /* Try folding our operands.
    3275              :      Then see which ones have constant values known.  */
    3276              : 
    3277    119154088 :   fmt = GET_RTX_FORMAT (code);
    3278    371580673 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    3279    252426585 :     if (fmt[i] == 'e')
    3280              :       {
    3281    247798201 :         rtx folded_arg = XEXP (x, i), const_arg;
    3282    247798201 :         machine_mode mode_arg = GET_MODE (folded_arg);
    3283              : 
    3284    247798201 :         switch (GET_CODE (folded_arg))
    3285              :           {
    3286    111202484 :           case MEM:
    3287    111202484 :           case REG:
    3288    111202484 :           case SUBREG:
    3289    111202484 :             const_arg = equiv_constant (folded_arg);
    3290    111202484 :             break;
    3291              : 
    3292              :           case CONST:
    3293              :           CASE_CONST_ANY:
    3294              :           case SYMBOL_REF:
    3295              :           case LABEL_REF:
    3296              :             const_arg = folded_arg;
    3297              :             break;
    3298              : 
    3299     46500922 :           default:
    3300     46500922 :             folded_arg = fold_rtx (folded_arg, insn);
    3301     46500922 :             const_arg = equiv_constant (folded_arg);
    3302     46500922 :             break;
    3303              :           }
    3304              : 
    3305              :         /* For the first three operands, see if the operand
    3306              :            is constant or equivalent to a constant.  */
    3307    247798201 :         switch (i)
    3308              :           {
    3309    116360236 :           case 0:
    3310    116360236 :             folded_arg0 = folded_arg;
    3311    116360236 :             const_arg0 = const_arg;
    3312    116360236 :             mode_arg0 = mode_arg;
    3313    116360236 :             break;
    3314    110128537 :           case 1:
    3315    110128537 :             folded_arg1 = folded_arg;
    3316    110128537 :             const_arg1 = const_arg;
    3317    110128537 :             break;
    3318     21309428 :           case 2:
    3319     21309428 :             const_arg2 = const_arg;
    3320     21309428 :             break;
    3321              :           }
    3322              : 
    3323              :         /* Pick the least expensive of the argument and an equivalent constant
    3324              :            argument.  */
    3325    247798201 :         if (const_arg != 0
    3326    247798201 :             && const_arg != folded_arg
    3327      6158122 :             && (COST_IN (const_arg, mode_arg, code, i)
    3328      3079061 :                 <= COST_IN (folded_arg, mode_arg, code, i))
    3329              : 
    3330              :             /* It's not safe to substitute the operand of a conversion
    3331              :                operator with a constant, as the conversion's identity
    3332              :                depends upon the mode of its operand.  This optimization
    3333              :                is handled by the call to simplify_unary_operation.  */
    3334    249420280 :             && (GET_RTX_CLASS (code) != RTX_UNARY
    3335       407053 :                 || GET_MODE (const_arg) == mode_arg0
    3336       344329 :                 || (code != ZERO_EXTEND
    3337              :                     && code != SIGN_EXTEND
    3338       344329 :                     && code != TRUNCATE
    3339       344329 :                     && code != FLOAT_TRUNCATE
    3340       270249 :                     && code != FLOAT_EXTEND
    3341       270249 :                     && code != FLOAT
    3342              :                     && code != FIX
    3343       270056 :                     && code != UNSIGNED_FLOAT
    3344       270056 :                     && code != UNSIGNED_FIX)))
    3345              :           folded_arg = const_arg;
    3346              : 
    3347    247798201 :         if (folded_arg == XEXP (x, i))
    3348    245684286 :           continue;
    3349              : 
    3350      2113915 :         if (insn == NULL_RTX && !changed)
    3351      1916275 :           x = copy_rtx (x);
    3352      2113915 :         changed = true;
    3353      2113915 :         validate_unshare_change (insn, &XEXP (x, i), folded_arg, 1);
    3354              :       }
    3355              : 
    3356    119154088 :   if (changed)
    3357              :     {
    3358              :       /* Canonicalize X if necessary, and keep const_argN and folded_argN
    3359              :          consistent with the order in X.  */
    3360      1916774 :       if (canonicalize_change_group (insn, x))
    3361              :         {
    3362       106929 :           std::swap (const_arg0, const_arg1);
    3363       106929 :           std::swap (folded_arg0, folded_arg1);
    3364              :         }
    3365              : 
    3366      1916774 :       apply_change_group ();
    3367              :     }
    3368              : 
    3369              :   /* If X is an arithmetic operation, see if we can simplify it.  */
    3370              : 
    3371    119154088 :   switch (GET_RTX_CLASS (code))
    3372              :     {
    3373      6231699 :     case RTX_UNARY:
    3374      6231699 :       {
    3375              :         /* We can't simplify extension ops unless we know the
    3376              :            original mode.  */
    3377      6231699 :         if ((code == ZERO_EXTEND || code == SIGN_EXTEND)
    3378      4380473 :             && mode_arg0 == VOIDmode)
    3379              :           break;
    3380              : 
    3381      6231699 :         new_rtx = simplify_unary_operation (code, mode,
    3382              :                                             const_arg0 ? const_arg0 : folded_arg0,
    3383              :                                             mode_arg0);
    3384              :       }
    3385      6231699 :       break;
    3386              : 
    3387     22737103 :     case RTX_COMPARE:
    3388     22737103 :     case RTX_COMM_COMPARE:
    3389              :       /* See what items are actually being compared and set FOLDED_ARG[01]
    3390              :          to those values and CODE to the actual comparison code.  If any are
    3391              :          constant, set CONST_ARG0 and CONST_ARG1 appropriately.  We needn't
    3392              :          do anything if both operands are already known to be constant.  */
    3393              : 
    3394              :       /* ??? Vector mode comparisons are not supported yet.  */
    3395     22737103 :       if (VECTOR_MODE_P (mode))
    3396              :         break;
    3397              : 
    3398     22593582 :       if (const_arg0 == 0 || const_arg1 == 0)
    3399              :         {
    3400     22592449 :           struct table_elt *p0, *p1;
    3401     22592449 :           rtx true_rtx, false_rtx;
    3402     22592449 :           machine_mode mode_arg1;
    3403              : 
    3404     22592449 :           if (SCALAR_FLOAT_MODE_P (mode))
    3405              :             {
    3406              : #ifdef FLOAT_STORE_FLAG_VALUE
    3407              :               true_rtx = (const_double_from_real_value
    3408              :                           (FLOAT_STORE_FLAG_VALUE (mode), mode));
    3409              : #else
    3410         2551 :               true_rtx = NULL_RTX;
    3411              : #endif
    3412         2551 :               false_rtx = CONST0_RTX (mode);
    3413              :             }
    3414              :           else
    3415              :             {
    3416     22589898 :               true_rtx = const_true_rtx;
    3417     22589898 :               false_rtx = const0_rtx;
    3418              :             }
    3419              : 
    3420     22592449 :           code = find_comparison_args (code, &folded_arg0, &folded_arg1,
    3421              :                                        &mode_arg0, &mode_arg1);
    3422              : 
    3423              :           /* If the mode is VOIDmode or a MODE_CC mode, we don't know
    3424              :              what kinds of things are being compared, so we can't do
    3425              :              anything with this comparison.  */
    3426              : 
    3427     22592449 :           if (mode_arg0 == VOIDmode || GET_MODE_CLASS (mode_arg0) == MODE_CC)
    3428              :             break;
    3429              : 
    3430     21233636 :           const_arg0 = equiv_constant (folded_arg0);
    3431     21233636 :           const_arg1 = equiv_constant (folded_arg1);
    3432              : 
    3433              :           /* If we do not now have two constants being compared, see
    3434              :              if we can nevertheless deduce some things about the
    3435              :              comparison.  */
    3436     21233636 :           if (const_arg0 == 0 || const_arg1 == 0)
    3437              :             {
    3438     21028588 :               if (const_arg1 != NULL)
    3439              :                 {
    3440     15704825 :                   rtx cheapest_simplification;
    3441     15704825 :                   int cheapest_cost;
    3442     15704825 :                   rtx simp_result;
    3443     15704825 :                   struct table_elt *p;
    3444              : 
    3445              :                   /* See if we can find an equivalent of folded_arg0
    3446              :                      that gets us a cheaper expression, possibly a
    3447              :                      constant through simplifications.  */
    3448     15704825 :                   p = lookup (folded_arg0, SAFE_HASH (folded_arg0, mode_arg0),
    3449              :                               mode_arg0);
    3450              : 
    3451     15704825 :                   if (p != NULL)
    3452              :                     {
    3453      6454617 :                       cheapest_simplification = x;
    3454      6454617 :                       cheapest_cost = COST (x, mode);
    3455              : 
    3456     18670820 :                       for (p = p->first_same_value; p != NULL; p = p->next_same_value)
    3457              :                         {
    3458     12216203 :                           int cost;
    3459              : 
    3460              :                           /* If the entry isn't valid, skip it.  */
    3461     12216203 :                           if (! exp_equiv_p (p->exp, p->exp, 1, false))
    3462       516663 :                             continue;
    3463              : 
    3464              :                           /* Try to simplify using this equivalence.  */
    3465     11699540 :                           simp_result
    3466     11699540 :                             = simplify_relational_operation (code, mode,
    3467              :                                                              mode_arg0,
    3468              :                                                              p->exp,
    3469              :                                                              const_arg1);
    3470              : 
    3471     11699540 :                           if (simp_result == NULL)
    3472     11552244 :                             continue;
    3473              : 
    3474       147296 :                           cost = COST (simp_result, mode);
    3475       147296 :                           if (cost < cheapest_cost)
    3476              :                             {
    3477     12216203 :                               cheapest_cost = cost;
    3478     12216203 :                               cheapest_simplification = simp_result;
    3479              :                             }
    3480              :                         }
    3481              : 
    3482              :                       /* If we have a cheaper expression now, use that
    3483              :                          and try folding it further, from the top.  */
    3484      6454617 :                       if (cheapest_simplification != x)
    3485         1796 :                         return fold_rtx (copy_rtx (cheapest_simplification),
    3486        11153 :                                          insn);
    3487              :                     }
    3488              :                 }
    3489              : 
    3490              :               /* See if the two operands are the same.  */
    3491              : 
    3492     21220571 :               if ((REG_P (folded_arg0)
    3493     17732311 :                    && REG_P (folded_arg1)
    3494      4631401 :                    && (REG_QTY (REGNO (folded_arg0))
    3495      4631401 :                        == REG_QTY (REGNO (folded_arg1))))
    3496     38940942 :                   || ((p0 = lookup (folded_arg0,
    3497              :                                     SAFE_HASH (folded_arg0, mode_arg0),
    3498              :                                     mode_arg0))
    3499      8994578 :                       && (p1 = lookup (folded_arg1,
    3500              :                                        SAFE_HASH (folded_arg1, mode_arg0),
    3501              :                                        mode_arg0))
    3502      2494263 :                       && p0->first_same_value == p1->first_same_value))
    3503        12951 :                 folded_arg1 = folded_arg0;
    3504              : 
    3505              :               /* If FOLDED_ARG0 is a register, see if the comparison we are
    3506              :                  doing now is either the same as we did before or the reverse
    3507              :                  (we only check the reverse if not floating-point).  */
    3508     21207620 :               else if (REG_P (folded_arg0))
    3509              :                 {
    3510     17719980 :                   int qty = REG_QTY (REGNO (folded_arg0));
    3511              : 
    3512     17719980 :                   if (REGNO_QTY_VALID_P (REGNO (folded_arg0)))
    3513              :                     {
    3514     17709212 :                       struct qty_table_elem *ent = &qty_table[qty];
    3515              : 
    3516     17709212 :                       if ((comparison_dominates_p (ent->comparison_code, code)
    3517     17233884 :                            || (! FLOAT_MODE_P (mode_arg0)
    3518     16999795 :                                && comparison_dominates_p (ent->comparison_code,
    3519              :                                                           reverse_condition (code))))
    3520     18171684 :                           && (rtx_equal_p (ent->comparison_const, folded_arg1)
    3521       930238 :                               || (const_arg1
    3522       792944 :                                   && rtx_equal_p (ent->comparison_const,
    3523              :                                                   const_arg1))
    3524       930238 :                               || (REG_P (folded_arg1)
    3525       128564 :                                   && (REG_QTY (REGNO (folded_arg1)) == ent->comparison_qty))))
    3526              :                         {
    3527         9357 :                           if (comparison_dominates_p (ent->comparison_code, code))
    3528              :                             {
    3529         6782 :                               if (true_rtx)
    3530              :                                 return true_rtx;
    3531              :                               else
    3532              :                                 break;
    3533              :                             }
    3534              :                           else
    3535              :                             return false_rtx;
    3536              :                         }
    3537              :                     }
    3538              :                 }
    3539              :             }
    3540              :         }
    3541              : 
    3542              :       /* If we are comparing against zero, see if the first operand is
    3543              :          equivalent to an IOR with a constant.  If so, we may be able to
    3544              :          determine the result of this comparison.  */
    3545     21223616 :       if (const_arg1 == const0_rtx && !const_arg0)
    3546              :         {
    3547      9997846 :           rtx y = lookup_as_function (folded_arg0, IOR);
    3548      9997846 :           rtx inner_const;
    3549              : 
    3550      9997846 :           if (y != 0
    3551        78660 :               && (inner_const = equiv_constant (XEXP (y, 1))) != 0
    3552           53 :               && CONST_INT_P (inner_const)
    3553      9997899 :               && INTVAL (inner_const) != 0)
    3554           53 :             folded_arg0 = gen_rtx_IOR (mode_arg0, XEXP (y, 0), inner_const);
    3555              :         }
    3556              : 
    3557     21216013 :       {
    3558     21216013 :         rtx op0 = const_arg0 ? const_arg0 : copy_rtx (folded_arg0);
    3559     21223616 :         rtx op1 = const_arg1 ? const_arg1 : copy_rtx (folded_arg1);
    3560     21223616 :         new_rtx = simplify_relational_operation (code, mode, mode_arg0,
    3561              :                                                  op0, op1);
    3562              :       }
    3563     21223616 :       break;
    3564              : 
    3565     65563343 :     case RTX_BIN_ARITH:
    3566     65563343 :     case RTX_COMM_ARITH:
    3567     65563343 :       switch (code)
    3568              :         {
    3569     27968909 :         case PLUS:
    3570              :           /* If the second operand is a LABEL_REF, see if the first is a MINUS
    3571              :              with that LABEL_REF as its second operand.  If so, the result is
    3572              :              the first operand of that MINUS.  This handles switches with an
    3573              :              ADDR_DIFF_VEC table.  */
    3574     27968909 :           if (const_arg1 && GET_CODE (const_arg1) == LABEL_REF)
    3575              :             {
    3576         3042 :               rtx y
    3577         3042 :                 = GET_CODE (folded_arg0) == MINUS ? folded_arg0
    3578         3042 :                 : lookup_as_function (folded_arg0, MINUS);
    3579              : 
    3580            0 :               if (y != 0 && GET_CODE (XEXP (y, 1)) == LABEL_REF
    3581         3042 :                   && label_ref_label (XEXP (y, 1)) == label_ref_label (const_arg1))
    3582            0 :                 return XEXP (y, 0);
    3583              : 
    3584              :               /* Now try for a CONST of a MINUS like the above.  */
    3585         3042 :               if ((y = (GET_CODE (folded_arg0) == CONST ? folded_arg0
    3586         3042 :                         : lookup_as_function (folded_arg0, CONST))) != 0
    3587            0 :                   && GET_CODE (XEXP (y, 0)) == MINUS
    3588            0 :                   && GET_CODE (XEXP (XEXP (y, 0), 1)) == LABEL_REF
    3589         3042 :                   && label_ref_label (XEXP (XEXP (y, 0), 1)) == label_ref_label (const_arg1))
    3590            0 :                 return XEXP (XEXP (y, 0), 0);
    3591              :             }
    3592              : 
    3593              :           /* Likewise if the operands are in the other order.  */
    3594     27968909 :           if (const_arg0 && GET_CODE (const_arg0) == LABEL_REF)
    3595              :             {
    3596           20 :               rtx y
    3597           20 :                 = GET_CODE (folded_arg1) == MINUS ? folded_arg1
    3598           20 :                 : lookup_as_function (folded_arg1, MINUS);
    3599              : 
    3600            0 :               if (y != 0 && GET_CODE (XEXP (y, 1)) == LABEL_REF
    3601           20 :                   && label_ref_label (XEXP (y, 1)) == label_ref_label (const_arg0))
    3602            0 :                 return XEXP (y, 0);
    3603              : 
    3604              :               /* Now try for a CONST of a MINUS like the above.  */
    3605           20 :               if ((y = (GET_CODE (folded_arg1) == CONST ? folded_arg1
    3606           20 :                         : lookup_as_function (folded_arg1, CONST))) != 0
    3607            0 :                   && GET_CODE (XEXP (y, 0)) == MINUS
    3608            0 :                   && GET_CODE (XEXP (XEXP (y, 0), 1)) == LABEL_REF
    3609           20 :                   && label_ref_label (XEXP (XEXP (y, 0), 1)) == label_ref_label (const_arg0))
    3610            0 :                 return XEXP (XEXP (y, 0), 0);
    3611              :             }
    3612              : 
    3613              :           /* If second operand is a register equivalent to a negative
    3614              :              CONST_INT, see if we can find a register equivalent to the
    3615              :              positive constant.  Make a MINUS if so.  Don't do this for
    3616              :              a non-negative constant since we might then alternate between
    3617              :              choosing positive and negative constants.  Having the positive
    3618              :              constant previously-used is the more common case.  Be sure
    3619              :              the resulting constant is non-negative; if const_arg1 were
    3620              :              the smallest negative number this would overflow: depending
    3621              :              on the mode, this would either just be the same value (and
    3622              :              hence not save anything) or be incorrect.  */
    3623     27968909 :           if (const_arg1 != 0 && CONST_INT_P (const_arg1)
    3624     22244422 :               && INTVAL (const_arg1) < 0
    3625              :               /* This used to test
    3626              : 
    3627              :                  -INTVAL (const_arg1) >= 0
    3628              : 
    3629              :                  But The Sun V5.0 compilers mis-compiled that test.  So
    3630              :                  instead we test for the problematic value in a more direct
    3631              :                  manner and hope the Sun compilers get it correct.  */
    3632     12597526 :               && INTVAL (const_arg1) !=
    3633              :                 (HOST_WIDE_INT_1 << (HOST_BITS_PER_WIDE_INT - 1))
    3634     12578325 :               && REG_P (folded_arg1))
    3635              :             {
    3636        33008 :               rtx new_const = GEN_INT (-INTVAL (const_arg1));
    3637        33008 :               struct table_elt *p
    3638        33008 :                 = lookup (new_const, SAFE_HASH (new_const, mode), mode);
    3639              : 
    3640        33008 :               if (p)
    3641         5137 :                 for (p = p->first_same_value; p; p = p->next_same_value)
    3642         5133 :                   if (REG_P (p->exp))
    3643         2690 :                     return simplify_gen_binary (MINUS, mode, folded_arg0,
    3644         2690 :                                                 canon_reg (p->exp, NULL));
    3645              :             }
    3646     27966219 :           goto from_plus;
    3647              : 
    3648      2340474 :         case MINUS:
    3649              :           /* If we have (MINUS Y C), see if Y is known to be (PLUS Z C2).
    3650              :              If so, produce (PLUS Z C2-C).  */
    3651      2340474 :           if (const_arg1 != 0 && poly_int_rtx_p (const_arg1, &xval))
    3652              :             {
    3653        43370 :               rtx y = lookup_as_function (XEXP (x, 0), PLUS);
    3654        43370 :               if (y && poly_int_rtx_p (XEXP (y, 1)))
    3655           35 :                 return fold_rtx (plus_constant (mode, copy_rtx (y), -xval),
    3656           35 :                                  NULL);
    3657              :             }
    3658              : 
    3659              :           /* Fall through.  */
    3660              : 
    3661     41044351 :         from_plus:
    3662     41044351 :         case SMIN:    case SMAX:      case UMIN:    case UMAX:
    3663     41044351 :         case IOR:     case AND:       case XOR:
    3664     41044351 :         case MULT:
    3665     41044351 :         case ASHIFT:  case LSHIFTRT:  case ASHIFTRT:
    3666              :           /* If we have (<op> <reg> <const_int>) for an associative OP and REG
    3667              :              is known to be of similar form, we may be able to replace the
    3668              :              operation with a combined operation.  This may eliminate the
    3669              :              intermediate operation if every use is simplified in this way.
    3670              :              Note that the similar optimization done by combine.cc only works
    3671              :              if the intermediate operation's result has only one reference.  */
    3672              : 
    3673     41044351 :           if (REG_P (folded_arg0)
    3674     37650412 :               && const_arg1 && CONST_INT_P (const_arg1))
    3675              :             {
    3676     27305869 :               int is_shift
    3677     27305869 :                 = (code == ASHIFT || code == ASHIFTRT || code == LSHIFTRT);
    3678              :               rtx y, inner_const, new_const;
    3679              :               rtx canon_const_arg1 = const_arg1;
    3680              :               enum rtx_code associate_code;
    3681              : 
    3682              :               if (is_shift
    3683      6873844 :                   && (INTVAL (const_arg1) >= GET_MODE_UNIT_PRECISION (mode)
    3684      3436755 :                       || INTVAL (const_arg1) < 0))
    3685              :                 {
    3686              :                   if (SHIFT_COUNT_TRUNCATED)
    3687              :                     canon_const_arg1 = gen_int_shift_amount
    3688              :                       (mode, (INTVAL (const_arg1)
    3689              :                               & (GET_MODE_UNIT_BITSIZE (mode) - 1)));
    3690              :                   else
    3691              :                     break;
    3692              :                 }
    3693              : 
    3694     27305700 :               y = lookup_as_function (folded_arg0, code);
    3695     27305700 :               if (y == 0)
    3696              :                 break;
    3697              : 
    3698              :               /* If we have compiled a statement like
    3699              :                  "if (x == (x & mask1))", and now are looking at
    3700              :                  "x & mask2", we will have a case where the first operand
    3701              :                  of Y is the same as our first operand.  Unless we detect
    3702              :                  this case, an infinite loop will result.  */
    3703       735090 :               if (XEXP (y, 0) == folded_arg0)
    3704              :                 break;
    3705              : 
    3706       734779 :               inner_const = equiv_constant (fold_rtx (XEXP (y, 1), 0));
    3707       734779 :               if (!inner_const || !CONST_INT_P (inner_const))
    3708              :                 break;
    3709              : 
    3710              :               /* Don't associate these operations if they are a PLUS with the
    3711              :                  same constant and it is a power of two.  These might be doable
    3712              :                  with a pre- or post-increment.  Similarly for two subtracts of
    3713              :                  identical powers of two with post decrement.  */
    3714              : 
    3715       533498 :               if (code == PLUS && const_arg1 == inner_const
    3716              :                   && ((HAVE_PRE_INCREMENT
    3717              :                           && pow2p_hwi (INTVAL (const_arg1)))
    3718              :                       || (HAVE_POST_INCREMENT
    3719              :                           && pow2p_hwi (INTVAL (const_arg1)))
    3720              :                       || (HAVE_PRE_DECREMENT
    3721              :                           && pow2p_hwi (- INTVAL (const_arg1)))
    3722              :                       || (HAVE_POST_DECREMENT
    3723              :                           && pow2p_hwi (- INTVAL (const_arg1)))))
    3724              :                 break;
    3725              : 
    3726              :               /* ??? Vector mode shifts by scalar
    3727              :                  shift operand are not supported yet.  */
    3728       533498 :               if (is_shift && VECTOR_MODE_P (mode))
    3729              :                 break;
    3730              : 
    3731         4298 :               if (is_shift
    3732         8596 :                   && (INTVAL (inner_const) >= GET_MODE_UNIT_PRECISION (mode)
    3733         4298 :                       || INTVAL (inner_const) < 0))
    3734              :                 {
    3735              :                   if (SHIFT_COUNT_TRUNCATED)
    3736              :                     inner_const = gen_int_shift_amount
    3737              :                       (mode, (INTVAL (inner_const)
    3738              :                               & (GET_MODE_UNIT_BITSIZE (mode) - 1)));
    3739              :                   else
    3740              :                     break;
    3741              :                 }
    3742              : 
    3743              :               /* Compute the code used to compose the constants.  For example,
    3744              :                  A-C1-C2 is A-(C1 + C2), so if CODE == MINUS, we want PLUS.  */
    3745              : 
    3746       533233 :               associate_code = (is_shift || code == MINUS ? PLUS : code);
    3747              : 
    3748       533233 :               new_const = simplify_binary_operation (associate_code, mode,
    3749              :                                                      canon_const_arg1,
    3750              :                                                      inner_const);
    3751              : 
    3752       533233 :               if (new_const == 0)
    3753              :                 break;
    3754              : 
    3755              :               /* If we are associating shift operations, don't let this
    3756              :                  produce a shift of the size of the object or larger.
    3757              :                  This could occur when we follow a sign-extend by a right
    3758              :                  shift on a machine that does a sign-extend as a pair
    3759              :                  of shifts.  */
    3760              : 
    3761       533233 :               if (is_shift
    3762         4298 :                   && CONST_INT_P (new_const)
    3763       541829 :                   && INTVAL (new_const) >= GET_MODE_UNIT_PRECISION (mode))
    3764              :                 {
    3765              :                   /* As an exception, we can turn an ASHIFTRT of this
    3766              :                      form into a shift of the number of bits - 1.  */
    3767         1557 :                   if (code == ASHIFTRT)
    3768         1534 :                     new_const = gen_int_shift_amount
    3769         1534 :                       (mode, GET_MODE_UNIT_BITSIZE (mode) - 1);
    3770           23 :                   else if (!side_effects_p (XEXP (y, 0)))
    3771           23 :                     return CONST0_RTX (mode);
    3772              :                   else
    3773              :                     break;
    3774              :                 }
    3775              : 
    3776       533210 :               y = copy_rtx (XEXP (y, 0));
    3777              : 
    3778              :               /* If Y contains our first operand (the most common way this
    3779              :                  can happen is if Y is a MEM), we would do into an infinite
    3780              :                  loop if we tried to fold it.  So don't in that case.  */
    3781              : 
    3782       533210 :               if (! reg_mentioned_p (folded_arg0, y))
    3783       533210 :                 y = fold_rtx (y, insn);
    3784              : 
    3785       533210 :               return simplify_gen_binary (code, mode, y, new_const);
    3786              :             }
    3787              :           break;
    3788              : 
    3789              :         case DIV:       case UDIV:
    3790              :           /* ??? The associative optimization performed immediately above is
    3791              :              also possible for DIV and UDIV using associate_code of MULT.
    3792              :              However, we would need extra code to verify that the
    3793              :              multiplication does not overflow, that is, there is no overflow
    3794              :              in the calculation of new_const.  */
    3795              :           break;
    3796              : 
    3797              :         default:
    3798              :           break;
    3799              :         }
    3800              : 
    3801     65027385 :       new_rtx = simplify_binary_operation (code, mode,
    3802              :                                        const_arg0 ? const_arg0 : folded_arg0,
    3803              :                                        const_arg1 ? const_arg1 : folded_arg1);
    3804     65027385 :       break;
    3805              : 
    3806            0 :     case RTX_OBJ:
    3807              :       /* (lo_sum (high X) X) is simply X.  */
    3808            0 :       if (code == LO_SUM && const_arg0 != 0
    3809            0 :           && GET_CODE (const_arg0) == HIGH
    3810            0 :           && rtx_equal_p (XEXP (const_arg0, 0), const_arg1))
    3811              :         return const_arg1;
    3812              :       break;
    3813              : 
    3814     21309428 :     case RTX_TERNARY:
    3815     21309428 :     case RTX_BITFIELD_OPS:
    3816     21309428 :       new_rtx = simplify_ternary_operation (code, mode, mode_arg0,
    3817              :                                         const_arg0 ? const_arg0 : folded_arg0,
    3818              :                                         const_arg1 ? const_arg1 : folded_arg1,
    3819              :                                         const_arg2 ? const_arg2 : XEXP (x, 2));
    3820     21309428 :       break;
    3821              : 
    3822              :     default:
    3823              :       break;
    3824              :     }
    3825              : 
    3826    115150941 :   return new_rtx ? new_rtx : x;
    3827              : }
    3828              : 
    3829              : /* Return a constant value currently equivalent to X.
    3830              :    Return 0 if we don't know one.  */
    3831              : 
    3832              : static rtx
    3833    278536455 : equiv_constant (rtx x)
    3834              : {
    3835    278536455 :   if (REG_P (x)
    3836    278536455 :       && REGNO_QTY_VALID_P (REGNO (x)))
    3837              :     {
    3838     88766829 :       int x_q = REG_QTY (REGNO (x));
    3839     88766829 :       struct qty_table_elem *x_ent = &qty_table[x_q];
    3840              : 
    3841     88766829 :       if (x_ent->const_rtx)
    3842      4549222 :         x = gen_lowpart (GET_MODE (x), x_ent->const_rtx);
    3843              :     }
    3844              : 
    3845    278536455 :   if (x == 0 || CONSTANT_P (x))
    3846              :     return x;
    3847              : 
    3848    251312741 :   if (GET_CODE (x) == SUBREG)
    3849              :     {
    3850      6470642 :       machine_mode mode = GET_MODE (x);
    3851      6470642 :       machine_mode imode = GET_MODE (SUBREG_REG (x));
    3852      6470642 :       rtx new_rtx;
    3853              : 
    3854              :       /* See if we previously assigned a constant value to this SUBREG.  */
    3855      6470642 :       if ((new_rtx = lookup_as_function (x, CONST_INT)) != 0
    3856      6460087 :           || (new_rtx = lookup_as_function (x, CONST_WIDE_INT)) != 0
    3857      6460087 :           || (NUM_POLY_INT_COEFFS > 1
    3858              :               && (new_rtx = lookup_as_function (x, CONST_POLY_INT)) != 0)
    3859      6454171 :           || (new_rtx = lookup_as_function (x, CONST_DOUBLE)) != 0
    3860     12924619 :           || (new_rtx = lookup_as_function (x, CONST_FIXED)) != 0)
    3861              :         return new_rtx;
    3862              : 
    3863              :       /* If we didn't and if doing so makes sense, see if we previously
    3864              :          assigned a constant value to the enclosing word mode SUBREG.  */
    3865     13786791 :       if (known_lt (GET_MODE_SIZE (mode), UNITS_PER_WORD)
    3866     10136080 :           && known_lt (UNITS_PER_WORD, GET_MODE_SIZE (imode)))
    3867              :         {
    3868        34405 :           poly_int64 byte = (SUBREG_BYTE (x)
    3869        34405 :                              - subreg_lowpart_offset (mode, word_mode));
    3870        68810 :           if (known_ge (byte, 0) && multiple_p (byte, UNITS_PER_WORD))
    3871              :             {
    3872        34405 :               rtx y = gen_rtx_SUBREG (word_mode, SUBREG_REG (x), byte);
    3873        34405 :               new_rtx = lookup_as_function (y, CONST_INT);
    3874        34405 :               if (new_rtx)
    3875            0 :                 return gen_lowpart (mode, new_rtx);
    3876              :             }
    3877              :         }
    3878              : 
    3879              :       /* Otherwise see if we already have a constant for the inner REG,
    3880              :          and if that is enough to calculate an equivalent constant for
    3881              :          the subreg.  Note that the upper bits of paradoxical subregs
    3882              :          are undefined, so they cannot be said to equal anything.  */
    3883      6453977 :       if (REG_P (SUBREG_REG (x))
    3884      6444331 :           && !paradoxical_subreg_p (x)
    3885     12707619 :           && (new_rtx = equiv_constant (SUBREG_REG (x))) != 0)
    3886       106903 :         return simplify_subreg (mode, new_rtx, imode, SUBREG_BYTE (x));
    3887              : 
    3888              :       return 0;
    3889              :     }
    3890              : 
    3891              :   /* If X is a MEM, see if it is a constant-pool reference, or look it up in
    3892              :      the hash table in case its value was seen before.  */
    3893              : 
    3894    244842099 :   if (MEM_P (x))
    3895              :     {
    3896     70333841 :       struct table_elt *elt;
    3897              : 
    3898     70333841 :       x = avoid_constant_pool_reference (x);
    3899     70333841 :       if (CONSTANT_P (x))
    3900              :         return x;
    3901              : 
    3902     68143189 :       elt = lookup (x, SAFE_HASH (x, GET_MODE (x)), GET_MODE (x));
    3903     68143189 :       if (elt == 0)
    3904              :         return 0;
    3905              : 
    3906     11950416 :       for (elt = elt->first_same_value; elt; elt = elt->next_same_value)
    3907     10208644 :         if (elt->is_const && CONSTANT_P (elt->exp))
    3908              :           return elt->exp;
    3909              :     }
    3910              : 
    3911              :   return 0;
    3912              : }
    3913              : 
    3914              : /* Given INSN, a jump insn, TAKEN indicates if we are following the
    3915              :    "taken" branch.
    3916              : 
    3917              :    In certain cases, this can cause us to add an equivalence.  For example,
    3918              :    if we are following the taken case of
    3919              :         if (i == 2)
    3920              :    we can add the fact that `i' and '2' are now equivalent.
    3921              : 
    3922              :    In any case, we can record that this comparison was passed.  If the same
    3923              :    comparison is seen later, we will know its value.  */
    3924              : 
    3925              : static void
    3926     14964871 : record_jump_equiv (rtx_insn *insn, bool taken)
    3927              : {
    3928     14964871 :   int cond_known_true;
    3929     14964871 :   rtx op0, op1;
    3930     14964871 :   rtx set;
    3931     14964871 :   machine_mode mode, mode0, mode1;
    3932     14964871 :   enum rtx_code code;
    3933              : 
    3934              :   /* Ensure this is the right kind of insn.  */
    3935     14964871 :   gcc_assert (any_condjump_p (insn));
    3936              : 
    3937     14964871 :   set = pc_set (insn);
    3938              : 
    3939              :   /* See if this jump condition is known true or false.  */
    3940     14964871 :   if (taken)
    3941      5951201 :     cond_known_true = (XEXP (SET_SRC (set), 2) == pc_rtx);
    3942              :   else
    3943      9013670 :     cond_known_true = (XEXP (SET_SRC (set), 1) == pc_rtx);
    3944              : 
    3945              :   /* Get the type of comparison being done and the operands being compared.
    3946              :      If we had to reverse a non-equality condition, record that fact so we
    3947              :      know that it isn't valid for floating-point.  */
    3948     14964871 :   code = GET_CODE (XEXP (SET_SRC (set), 0));
    3949     14964871 :   op0 = fold_rtx (XEXP (XEXP (SET_SRC (set), 0), 0), insn);
    3950     14964871 :   op1 = fold_rtx (XEXP (XEXP (SET_SRC (set), 0), 1), insn);
    3951              : 
    3952              :   /* If fold_rtx returns NULL_RTX, there's nothing to record.  */
    3953     14964871 :   if (op0 == NULL_RTX || op1 == NULL_RTX)
    3954        92365 :     return;
    3955              : 
    3956     14964871 :   code = find_comparison_args (code, &op0, &op1, &mode0, &mode1);
    3957     14964871 :   if (! cond_known_true)
    3958              :     {
    3959      9013670 :       code = reversed_comparison_code_parts (code, op0, op1, insn);
    3960              : 
    3961              :       /* Don't remember if we can't find the inverse.  */
    3962      9013670 :       if (code == UNKNOWN)
    3963              :         return;
    3964              :     }
    3965              : 
    3966              :   /* The mode is the mode of the non-constant.  */
    3967     14872506 :   mode = mode0;
    3968     14872506 :   if (mode1 != VOIDmode)
    3969      3745298 :     mode = mode1;
    3970              : 
    3971     14872506 :   record_jump_cond (code, mode, op0, op1);
    3972              : }
    3973              : 
    3974              : /* Yet another form of subreg creation.  In this case, we want something in
    3975              :    MODE, and we should assume OP has MODE iff it is naturally modeless.  */
    3976              : 
    3977              : static rtx
    3978        58425 : record_jump_cond_subreg (machine_mode mode, rtx op)
    3979              : {
    3980        58425 :   machine_mode op_mode = GET_MODE (op);
    3981        58425 :   if (op_mode == mode || op_mode == VOIDmode)
    3982              :     return op;
    3983         6216 :   return lowpart_subreg (mode, op, op_mode);
    3984              : }
    3985              : 
    3986              : /* We know that comparison CODE applied to OP0 and OP1 in MODE is true.
    3987              :    Make any useful entries we can with that information.  Called from
    3988              :    above function and called recursively.  */
    3989              : 
    3990              : static void
    3991     14930929 : record_jump_cond (enum rtx_code code, machine_mode mode, rtx op0, rtx op1)
    3992              : {
    3993     14930929 :   unsigned op0_hash, op1_hash;
    3994     14930929 :   int op0_in_memory, op1_in_memory;
    3995     14930929 :   struct table_elt *op0_elt, *op1_elt;
    3996              : 
    3997              :   /* If OP0 and OP1 are known equal, and either is a paradoxical SUBREG,
    3998              :      we know that they are also equal in the smaller mode (this is also
    3999              :      true for all smaller modes whether or not there is a SUBREG, but
    4000              :      is not worth testing for with no SUBREG).  */
    4001              : 
    4002              :   /* Note that GET_MODE (op0) may not equal MODE.  */
    4003     14979453 :   if (code == EQ && paradoxical_subreg_p (op0))
    4004              :     {
    4005            0 :       machine_mode inner_mode = GET_MODE (SUBREG_REG (op0));
    4006            0 :       rtx tem = record_jump_cond_subreg (inner_mode, op1);
    4007            0 :       if (tem)
    4008            0 :         record_jump_cond (code, mode, SUBREG_REG (op0), tem);
    4009              :     }
    4010              : 
    4011     14946128 :   if (code == EQ && paradoxical_subreg_p (op1))
    4012              :     {
    4013            0 :       machine_mode inner_mode = GET_MODE (SUBREG_REG (op1));
    4014            0 :       rtx tem = record_jump_cond_subreg (inner_mode, op0);
    4015            0 :       if (tem)
    4016            0 :         record_jump_cond (code, mode, SUBREG_REG (op1), tem);
    4017              :     }
    4018              : 
    4019              :   /* Similarly, if this is an NE comparison, and either is a SUBREG
    4020              :      making a smaller mode, we know the whole thing is also NE.  */
    4021              : 
    4022              :   /* Note that GET_MODE (op0) may not equal MODE;
    4023              :      if we test MODE instead, we can get an infinite recursion
    4024              :      alternating between two modes each wider than MODE.  */
    4025              : 
    4026     14930929 :   if (code == NE
    4027        53426 :       && partial_subreg_p (op0)
    4028     14984107 :       && subreg_lowpart_p (op0))
    4029              :     {
    4030        52814 :       machine_mode inner_mode = GET_MODE (SUBREG_REG (op0));
    4031        52814 :       rtx tem = record_jump_cond_subreg (inner_mode, op1);
    4032        52814 :       if (tem)
    4033        52814 :         record_jump_cond (code, mode, SUBREG_REG (op0), tem);
    4034              :     }
    4035              : 
    4036     14930929 :   if (code == NE
    4037        11923 :       && partial_subreg_p (op1)
    4038     14936596 :       && subreg_lowpart_p (op1))
    4039              :     {
    4040         5611 :       machine_mode inner_mode = GET_MODE (SUBREG_REG (op1));
    4041         5611 :       rtx tem = record_jump_cond_subreg (inner_mode, op0);
    4042         5611 :       if (tem)
    4043         5609 :         record_jump_cond (code, mode, SUBREG_REG (op1), tem);
    4044              :     }
    4045              : 
    4046              :   /* Hash both operands.  */
    4047              : 
    4048     14930929 :   do_not_record = 0;
    4049     14930929 :   hash_arg_in_memory = 0;
    4050     14930929 :   op0_hash = HASH (op0, mode);
    4051     14930929 :   op0_in_memory = hash_arg_in_memory;
    4052              : 
    4053     14930929 :   if (do_not_record)
    4054              :     return;
    4055              : 
    4056     14930929 :   do_not_record = 0;
    4057     14930929 :   hash_arg_in_memory = 0;
    4058     14930929 :   op1_hash = HASH (op1, mode);
    4059     14930929 :   op1_in_memory = hash_arg_in_memory;
    4060              : 
    4061     14930929 :   if (do_not_record)
    4062              :     return;
    4063              : 
    4064              :   /* Look up both operands.  */
    4065     14930929 :   op0_elt = lookup (op0, op0_hash, mode);
    4066     14930929 :   op1_elt = lookup (op1, op1_hash, mode);
    4067              : 
    4068              :   /* If both operands are already equivalent or if they are not in the
    4069              :      table but are identical, do nothing.  */
    4070     14930929 :   if ((op0_elt != 0 && op1_elt != 0
    4071      1863226 :        && op0_elt->first_same_value == op1_elt->first_same_value)
    4072     16794070 :       || op0 == op1 || rtx_equal_p (op0, op1))
    4073              :     return;
    4074              : 
    4075              :   /* If we aren't setting two things equal all we can do is save this
    4076              :      comparison.   Similarly if this is floating-point.  In the latter
    4077              :      case, OP1 might be zero and both -0.0 and 0.0 are equal to it.
    4078              :      If we record the equality, we might inadvertently delete code
    4079              :      whose intent was to change -0 to +0.  */
    4080              : 
    4081     14930073 :   if (code != EQ || FLOAT_MODE_P (GET_MODE (op0)))
    4082              :     {
    4083      9563768 :       struct qty_table_elem *ent;
    4084      9563768 :       int qty;
    4085              : 
    4086              :       /* If OP0 is not a register, or if OP1 is neither a register
    4087              :          or constant, we can't do anything.  */
    4088              : 
    4089      9563768 :       if (!REG_P (op1))
    4090      7624717 :         op1 = equiv_constant (op1);
    4091              : 
    4092      9563768 :       if (!REG_P (op0) || op1 == 0)
    4093              :         return;
    4094              : 
    4095              :       /* Put OP0 in the hash table if it isn't already.  This gives it a
    4096              :          new quantity number.  */
    4097      8148859 :       if (op0_elt == 0)
    4098              :         {
    4099      3355467 :           if (insert_regs (op0, NULL, false))
    4100              :             {
    4101        58387 :               rehash_using_reg (op0);
    4102        58387 :               op0_hash = HASH (op0, mode);
    4103              : 
    4104              :               /* If OP0 is contained in OP1, this changes its hash code
    4105              :                  as well.  Faster to rehash than to check, except
    4106              :                  for the simple case of a constant.  */
    4107        58387 :               if (! CONSTANT_P (op1))
    4108          230 :                 op1_hash = HASH (op1,mode);
    4109              :             }
    4110              : 
    4111      3355467 :           op0_elt = insert (op0, NULL, op0_hash, mode);
    4112      3355467 :           op0_elt->in_memory = op0_in_memory;
    4113              :         }
    4114              : 
    4115      8148859 :       qty = REG_QTY (REGNO (op0));
    4116      8148859 :       ent = &qty_table[qty];
    4117              : 
    4118      8148859 :       ent->comparison_code = code;
    4119      8148859 :       if (REG_P (op1))
    4120              :         {
    4121              :           /* Look it up again--in case op0 and op1 are the same.  */
    4122      1844523 :           op1_elt = lookup (op1, op1_hash, mode);
    4123              : 
    4124              :           /* Put OP1 in the hash table so it gets a new quantity number.  */
    4125      1844523 :           if (op1_elt == 0)
    4126              :             {
    4127       687875 :               if (insert_regs (op1, NULL, false))
    4128              :                 {
    4129          218 :                   rehash_using_reg (op1);
    4130          218 :                   op1_hash = HASH (op1, mode);
    4131              :                 }
    4132              : 
    4133       687875 :               op1_elt = insert (op1, NULL, op1_hash, mode);
    4134       687875 :               op1_elt->in_memory = op1_in_memory;
    4135              :             }
    4136              : 
    4137      1844523 :           ent->comparison_const = NULL_RTX;
    4138      1844523 :           ent->comparison_qty = REG_QTY (REGNO (op1));
    4139              :         }
    4140              :       else
    4141              :         {
    4142      6304336 :           ent->comparison_const = op1;
    4143      6304336 :           ent->comparison_qty = INT_MIN;
    4144              :         }
    4145              : 
    4146              :       return;
    4147              :     }
    4148              : 
    4149              :   /* If either side is still missing an equivalence, make it now,
    4150              :      then merge the equivalences.  */
    4151              : 
    4152      5366305 :   if (op0_elt == 0)
    4153              :     {
    4154      3348582 :       if (insert_regs (op0, NULL, false))
    4155              :         {
    4156        20001 :           rehash_using_reg (op0);
    4157        20001 :           op0_hash = HASH (op0, mode);
    4158              :         }
    4159              : 
    4160      3348582 :       op0_elt = insert (op0, NULL, op0_hash, mode);
    4161      3348582 :       op0_elt->in_memory = op0_in_memory;
    4162              :     }
    4163              : 
    4164      5366305 :   if (op1_elt == 0)
    4165              :     {
    4166      4046879 :       if (insert_regs (op1, NULL, false))
    4167              :         {
    4168         8875 :           rehash_using_reg (op1);
    4169         8875 :           op1_hash = HASH (op1, mode);
    4170              :         }
    4171              : 
    4172      4046879 :       op1_elt = insert (op1, NULL, op1_hash, mode);
    4173      4046879 :       op1_elt->in_memory = op1_in_memory;
    4174              :     }
    4175              : 
    4176      5366305 :   merge_equiv_classes (op0_elt, op1_elt);
    4177              : }
    4178              : 
    4179              : /* CSE processing for one instruction.
    4180              : 
    4181              :    Most "true" common subexpressions are mostly optimized away in GIMPLE,
    4182              :    but the few that "leak through" are cleaned up by cse_insn, and complex
    4183              :    addressing modes are often formed here.
    4184              : 
    4185              :    The main function is cse_insn, and between here and that function
    4186              :    a couple of helper functions is defined to keep the size of cse_insn
    4187              :    within reasonable proportions.
    4188              : 
    4189              :    Data is shared between the main and helper functions via STRUCT SET,
    4190              :    that contains all data related for every set in the instruction that
    4191              :    is being processed.
    4192              : 
    4193              :    Note that cse_main processes all sets in the instruction.  Most
    4194              :    passes in GCC only process simple SET insns or single_set insns, but
    4195              :    CSE processes insns with multiple sets as well.  */
    4196              : 
    4197              : /* Data on one SET contained in the instruction.  */
    4198              : 
    4199              : struct set
    4200              : {
    4201              :   /* The SET rtx itself.  */
    4202              :   rtx rtl;
    4203              :   /* The SET_SRC of the rtx (the original value, if it is changing).  */
    4204              :   rtx src;
    4205              :   /* The hash-table element for the SET_SRC of the SET.  */
    4206              :   struct table_elt *src_elt;
    4207              :   /* Hash value for the SET_SRC.  */
    4208              :   unsigned src_hash;
    4209              :   /* Hash value for the SET_DEST.  */
    4210              :   unsigned dest_hash;
    4211              :   /* The SET_DEST, with SUBREG, etc., stripped.  */
    4212              :   rtx inner_dest;
    4213              :   /* Original machine mode, in case it becomes a CONST_INT.  */
    4214              :   machine_mode mode : MACHINE_MODE_BITSIZE;
    4215              :   /* Nonzero if the SET_SRC is in memory.  */
    4216              :   unsigned int src_in_memory : 1;
    4217              :   /* Nonzero if the SET_SRC contains something
    4218              :      whose value cannot be predicted and understood.  */
    4219              :   unsigned int src_volatile : 1;
    4220              :   /* Nonzero if RTL is an artificial set that has been created to describe
    4221              :      part of an insn's effect.  Zero means that RTL appears directly in
    4222              :      the insn pattern.  */
    4223              :   unsigned int is_fake_set : 1;
    4224              :   /* Hash value of constant equivalent for SET_SRC.  */
    4225              :   unsigned src_const_hash;
    4226              :   /* A constant equivalent for SET_SRC, if any.  */
    4227              :   rtx src_const;
    4228              :   /* Table entry for constant equivalent for SET_SRC, if any.  */
    4229              :   struct table_elt *src_const_elt;
    4230              :   /* Table entry for the destination address.  */
    4231              :   struct table_elt *dest_addr_elt;
    4232              : };
    4233              : 
    4234              : /* Special handling for (set REG0 REG1) where REG0 is the
    4235              :    "cheapest", cheaper than REG1.  After cse, REG1 will probably not
    4236              :    be used in the sequel, so (if easily done) change this insn to
    4237              :    (set REG1 REG0) and replace REG1 with REG0 in the previous insn
    4238              :    that computed their value.  Then REG1 will become a dead store
    4239              :    and won't cloud the situation for later optimizations.
    4240              : 
    4241              :    Do not make this change if REG1 is a hard register, because it will
    4242              :    then be used in the sequel and we may be changing a two-operand insn
    4243              :    into a three-operand insn.
    4244              : 
    4245              :    This is the last transformation that cse_insn will try to do.  */
    4246              : 
    4247              : static void
    4248    140078598 : try_back_substitute_reg (rtx set, rtx_insn *insn)
    4249              : {
    4250    140078598 :   rtx dest = SET_DEST (set);
    4251    140078598 :   rtx src = SET_SRC (set);
    4252              : 
    4253    140078598 :   if (REG_P (dest)
    4254    116589107 :       && REG_P (src) && ! HARD_REGISTER_P (src)
    4255    147676463 :       && REGNO_QTY_VALID_P (REGNO (src)))
    4256              :     {
    4257      7597832 :       int src_q = REG_QTY (REGNO (src));
    4258      7597832 :       struct qty_table_elem *src_ent = &qty_table[src_q];
    4259              : 
    4260      7597832 :       if (src_ent->first_reg == REGNO (dest))
    4261              :         {
    4262              :           /* Scan for the previous nonnote insn, but stop at a basic
    4263              :              block boundary.  */
    4264      1859365 :           rtx_insn *prev = insn;
    4265      1859365 :           rtx_insn *bb_head = BB_HEAD (BLOCK_FOR_INSN (insn));
    4266      4525794 :           do
    4267              :             {
    4268      4525794 :               prev = PREV_INSN (prev);
    4269              :             }
    4270      4525794 :           while (prev != bb_head && (NOTE_P (prev) || DEBUG_INSN_P (prev)));
    4271              : 
    4272              :           /* Do not swap the registers around if the previous instruction
    4273              :              attaches a REG_EQUIV note to REG1.
    4274              : 
    4275              :              ??? It's not entirely clear whether we can transfer a REG_EQUIV
    4276              :              from the pseudo that originally shadowed an incoming argument
    4277              :              to another register.  Some uses of REG_EQUIV might rely on it
    4278              :              being attached to REG1 rather than REG2.
    4279              : 
    4280              :              This section previously turned the REG_EQUIV into a REG_EQUAL
    4281              :              note.  We cannot do that because REG_EQUIV may provide an
    4282              :              uninitialized stack slot when REG_PARM_STACK_SPACE is used.  */
    4283      1859365 :           if (NONJUMP_INSN_P (prev)
    4284      1117719 :               && GET_CODE (PATTERN (prev)) == SET
    4285       813348 :               && SET_DEST (PATTERN (prev)) == src
    4286      2103337 :               && ! find_reg_note (prev, REG_EQUIV, NULL_RTX))
    4287              :             {
    4288       243876 :               rtx note;
    4289              : 
    4290       243876 :               validate_change (prev, &SET_DEST (PATTERN (prev)), dest, 1);
    4291       243876 :               validate_change (insn, &SET_DEST (set), src, 1);
    4292       243876 :               validate_change (insn, &SET_SRC (set), dest, 1);
    4293       243876 :               apply_change_group ();
    4294              : 
    4295              :               /* If INSN has a REG_EQUAL note, and this note mentions
    4296              :                  REG0, then we must delete it, because the value in
    4297              :                  REG0 has changed.  If the note's value is REG1, we must
    4298              :                  also delete it because that is now this insn's dest.  */
    4299       243876 :               note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
    4300       243876 :               if (note != 0
    4301       243876 :                   && (reg_mentioned_p (dest, XEXP (note, 0))
    4302         1485 :                       || rtx_equal_p (src, XEXP (note, 0))))
    4303           10 :                 remove_note (insn, note);
    4304              : 
    4305              :               /* If INSN has a REG_ARGS_SIZE note, move it to PREV.  */
    4306       243876 :               note = find_reg_note (insn, REG_ARGS_SIZE, NULL_RTX);
    4307       243876 :               if (note != 0)
    4308              :                 {
    4309            0 :                   remove_note (insn, note);
    4310            0 :                   gcc_assert (!find_reg_note (prev, REG_ARGS_SIZE, NULL_RTX));
    4311            0 :                   set_unique_reg_note (prev, REG_ARGS_SIZE, XEXP (note, 0));
    4312              :                 }
    4313              :             }
    4314              :         }
    4315              :     }
    4316    140078598 : }
    4317              : 
    4318              : /* Add an entry containing RTL X into SETS.  IS_FAKE_SET is true if X is
    4319              :    an artificial set that has been created to describe part of an insn's
    4320              :    effect.  */
    4321              : static inline void
    4322    199993680 : add_to_set (vec<struct set> *sets, rtx x, bool is_fake_set)
    4323              : {
    4324    199993680 :   struct set entry = {};
    4325    199993680 :   entry.rtl = x;
    4326    199993680 :   entry.is_fake_set = is_fake_set;
    4327    199993680 :   sets->safe_push (entry);
    4328    199993680 : }
    4329              : 
    4330              : /* Record all the SETs in this instruction into SETS_PTR,
    4331              :    and return the number of recorded sets.  */
    4332              : static int
    4333    410923483 : find_sets_in_insn (rtx_insn *insn, vec<struct set> *psets)
    4334              : {
    4335    410923483 :   rtx x = PATTERN (insn);
    4336              : 
    4337    410923483 :   if (GET_CODE (x) == SET)
    4338              :     {
    4339              :       /* Ignore SETs that are unconditional jumps.
    4340              :          They never need cse processing, so this does not hurt.
    4341              :          The reason is not efficiency but rather
    4342              :          so that we can test at the end for instructions
    4343              :          that have been simplified to unconditional jumps
    4344              :          and not be misled by unchanged instructions
    4345              :          that were unconditional jumps to begin with.  */
    4346    173672620 :       if (SET_DEST (x) == pc_rtx
    4347     20461430 :           && GET_CODE (SET_SRC (x)) == LABEL_REF)
    4348              :         ;
    4349              :       /* Don't count call-insns, (set (reg 0) (call ...)), as a set.
    4350              :          The hard function value register is used only once, to copy to
    4351              :          someplace else, so it isn't worth cse'ing.  */
    4352    173672439 :       else if (GET_CODE (SET_SRC (x)) == CALL)
    4353              :         ;
    4354    166344153 :       else if (GET_CODE (SET_SRC (x)) == CONST_VECTOR
    4355       683634 :                && GET_MODE_CLASS (GET_MODE (SET_SRC (x))) != MODE_VECTOR_BOOL
    4356              :                /* Prevent duplicates from being generated if the type is a V1
    4357              :                   type and a subreg.  Folding this will result in the same
    4358              :                   element as folding x itself.  */
    4359    167027787 :                && !(SUBREG_P (SET_DEST (x))
    4360           70 :                     && known_eq (GET_MODE_NUNITS (GET_MODE (SET_SRC (x))), 1)))
    4361              :         {
    4362              :           /* First register the vector itself.  */
    4363       683633 :           add_to_set (psets, x, false);
    4364       683633 :           rtx src = SET_SRC (x);
    4365              :           /* Go over the constants of the CONST_VECTOR in forward order, to
    4366              :              put them in the same order in the SETS array.  */
    4367      1367416 :           for (unsigned i = 0; i < const_vector_encoded_nelts (src) ; i++)
    4368              :             {
    4369              :               /* These are templates and don't actually get emitted but are
    4370              :                  used to tell CSE how to get to a particular constant.  */
    4371       683783 :               rtx y = simplify_gen_vec_select (SET_DEST (x), i);
    4372       683783 :               gcc_assert (y);
    4373       683783 :               if (!REG_P (y))
    4374              :                 {
    4375       682076 :                   rtx set = gen_rtx_SET (y, CONST_VECTOR_ELT (src, i));
    4376       682076 :                   add_to_set (psets, set, true);
    4377              :                 }
    4378              :             }
    4379              :         }
    4380              :       else
    4381    165660520 :         add_to_set (psets, x, false);
    4382              :     }
    4383    237250863 :   else if (GET_CODE (x) == PARALLEL)
    4384              :     {
    4385     31984178 :       int i, lim = XVECLEN (x, 0);
    4386              : 
    4387              :       /* Go over the expressions of the PARALLEL in forward order, to
    4388              :          put them in the same order in the SETS array.  */
    4389     97388853 :       for (i = 0; i < lim; i++)
    4390              :         {
    4391     65404675 :           rtx y = XVECEXP (x, 0, i);
    4392     65404675 :           if (GET_CODE (y) == SET)
    4393              :             {
    4394              :               /* As above, we ignore unconditional jumps and call-insns and
    4395              :                  ignore the result of apply_change_group.  */
    4396     32977616 :               if (SET_DEST (y) == pc_rtx
    4397        21185 :                   && GET_CODE (SET_SRC (y)) == LABEL_REF)
    4398              :                 ;
    4399     32977616 :               else if (GET_CODE (SET_SRC (y)) == CALL)
    4400              :                 ;
    4401              :               else
    4402     32967451 :                 add_to_set (psets, y, false);
    4403              :             }
    4404              :         }
    4405              :     }
    4406              : 
    4407    410923483 :   return psets->length ();
    4408              : }
    4409              : 
    4410              : /* Subroutine of canonicalize_insn.  X is an ASM_OPERANDS in INSN.  */
    4411              : 
    4412              : static void
    4413        85638 : canon_asm_operands (rtx x, rtx_insn *insn)
    4414              : {
    4415       115284 :   for (int i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
    4416              :     {
    4417        29646 :       rtx input = ASM_OPERANDS_INPUT (x, i);
    4418        29646 :       if (!(REG_P (input) && HARD_REGISTER_P (input)))
    4419              :         {
    4420        29260 :           input = canon_reg (input, insn);
    4421        29260 :           validate_change (insn, &ASM_OPERANDS_INPUT (x, i), input, 1);
    4422              :         }
    4423              :     }
    4424        85638 : }
    4425              : 
    4426              : /* Where possible, substitute every register reference in the N_SETS
    4427              :    number of SETS in INSN with the canonical register.
    4428              : 
    4429              :    Register canonicalization propagatest the earliest register (i.e.
    4430              :    one that is set before INSN) with the same value.  This is a very
    4431              :    useful, simple form of CSE, to clean up warts from expanding GIMPLE
    4432              :    to RTL.  For instance, a CONST for an address is usually expanded
    4433              :    multiple times to loads into different registers, thus creating many
    4434              :    subexpressions of the form:
    4435              : 
    4436              :    (set (reg1) (some_const))
    4437              :    (set (mem (... reg1 ...) (thing)))
    4438              :    (set (reg2) (some_const))
    4439              :    (set (mem (... reg2 ...) (thing)))
    4440              : 
    4441              :    After canonicalizing, the code takes the following form:
    4442              : 
    4443              :    (set (reg1) (some_const))
    4444              :    (set (mem (... reg1 ...) (thing)))
    4445              :    (set (reg2) (some_const))
    4446              :    (set (mem (... reg1 ...) (thing)))
    4447              : 
    4448              :    The set to reg2 is now trivially dead, and the memory reference (or
    4449              :    address, or whatever) may be a candidate for further CSEing.
    4450              : 
    4451              :    In this function, the result of apply_change_group can be ignored;
    4452              :    see canon_reg.  */
    4453              : 
    4454              : static void
    4455    410923483 : canonicalize_insn (rtx_insn *insn, vec<struct set> *psets)
    4456              : {
    4457    410923483 :   vec<struct set> sets = *psets;
    4458    410923483 :   int n_sets = sets.length ();
    4459    410923483 :   rtx tem;
    4460    410923483 :   rtx x = PATTERN (insn);
    4461    410923483 :   int i;
    4462              : 
    4463    410923483 :   if (auto call = dyn_cast<rtx_call_insn *> (insn))
    4464              :     {
    4465     47077946 :       for (tem = CALL_INSN_FUNCTION_USAGE (call); tem; tem = XEXP (tem, 1))
    4466     31190375 :         if (GET_CODE (XEXP (tem, 0)) != SET)
    4467     30973686 :           XEXP (tem, 0) = canon_reg (XEXP (tem, 0), call);
    4468              :     }
    4469              : 
    4470    410923483 :   if (GET_CODE (x) == SET && GET_CODE (SET_SRC (x)) == CALL)
    4471              :     {
    4472      7328286 :       canon_reg (SET_SRC (x), insn);
    4473      7328286 :       apply_change_group ();
    4474      7328286 :       fold_rtx (SET_SRC (x), insn);
    4475              :     }
    4476    403595197 :   else if (GET_CODE (x) == CLOBBER)
    4477              :     {
    4478              :       /* If we clobber memory, canon the address.
    4479              :          This does nothing when a register is clobbered
    4480              :          because we have already invalidated the reg.  */
    4481        69808 :       if (MEM_P (XEXP (x, 0)))
    4482        13208 :         canon_reg (XEXP (x, 0), insn);
    4483              :     }
    4484    403525389 :   else if (GET_CODE (x) == USE
    4485    403525389 :            && ! (REG_P (XEXP (x, 0))
    4486      1300750 :                  && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER))
    4487              :     /* Canonicalize a USE of a pseudo register or memory location.  */
    4488            0 :     canon_reg (x, insn);
    4489    403525389 :   else if (GET_CODE (x) == ASM_OPERANDS)
    4490           18 :     canon_asm_operands (x, insn);
    4491    403525371 :   else if (GET_CODE (x) == CALL)
    4492              :     {
    4493      8058977 :       canon_reg (x, insn);
    4494      8058977 :       apply_change_group ();
    4495      8058977 :       fold_rtx (x, insn);
    4496              :     }
    4497    395466394 :   else if (DEBUG_INSN_P (insn))
    4498    195128521 :     canon_reg (PATTERN (insn), insn);
    4499    200337873 :   else if (GET_CODE (x) == PARALLEL)
    4500              :     {
    4501     97388853 :       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
    4502              :         {
    4503     65404675 :           rtx y = XVECEXP (x, 0, i);
    4504     65404675 :           if (GET_CODE (y) == SET && GET_CODE (SET_SRC (y)) == CALL)
    4505              :             {
    4506        10165 :               canon_reg (SET_SRC (y), insn);
    4507        10165 :               apply_change_group ();
    4508        10165 :               fold_rtx (SET_SRC (y), insn);
    4509              :             }
    4510     65394510 :           else if (GET_CODE (y) == CLOBBER)
    4511              :             {
    4512     31577070 :               if (MEM_P (XEXP (y, 0)))
    4513        63972 :                 canon_reg (XEXP (y, 0), insn);
    4514              :             }
    4515     33817440 :           else if (GET_CODE (y) == USE
    4516     33817440 :                    && ! (REG_P (XEXP (y, 0))
    4517        99993 :                          && REGNO (XEXP (y, 0)) < FIRST_PSEUDO_REGISTER))
    4518       235921 :             canon_reg (y, insn);
    4519     33581519 :           else if (GET_CODE (y) == ASM_OPERANDS)
    4520        85620 :             canon_asm_operands (y, insn);
    4521     33495899 :           else if (GET_CODE (y) == CALL)
    4522              :             {
    4523       490143 :               canon_reg (y, insn);
    4524       490143 :               apply_change_group ();
    4525       490143 :               fold_rtx (y, insn);
    4526              :             }
    4527              :         }
    4528              :     }
    4529              : 
    4530    196701915 :   if (n_sets == 1 && REG_NOTES (insn) != 0
    4531    537688747 :       && (tem = find_reg_note (insn, REG_EQUAL, NULL_RTX)) != 0)
    4532              :     {
    4533              :       /* We potentially will process this insn many times.  Therefore,
    4534              :          drop the REG_EQUAL note if it is equal to the SET_SRC of the
    4535              :          unique set in INSN.
    4536              : 
    4537              :          Do not do so if the REG_EQUAL note is for a STRICT_LOW_PART,
    4538              :          because cse_insn handles those specially.  */
    4539      9127727 :       if (GET_CODE (SET_DEST (sets[0].rtl)) != STRICT_LOW_PART
    4540      9127727 :           && rtx_equal_p (XEXP (tem, 0), SET_SRC (sets[0].rtl)))
    4541       183387 :         remove_note (insn, tem);
    4542              :       else
    4543              :         {
    4544      8944340 :           canon_reg (XEXP (tem, 0), insn);
    4545      8944340 :           apply_change_group ();
    4546      8944340 :           XEXP (tem, 0) = fold_rtx (XEXP (tem, 0), insn);
    4547      8944340 :           df_notes_rescan (insn);
    4548              :         }
    4549              :     }
    4550              : 
    4551              :   /* Canonicalize sources and addresses of destinations.
    4552              :      We do this in a separate pass to avoid problems when a MATCH_DUP is
    4553              :      present in the insn pattern.  In that case, we want to ensure that
    4554              :      we don't break the duplicate nature of the pattern.  So we will replace
    4555              :      both operands at the same time.  Otherwise, we would fail to find an
    4556              :      equivalent substitution in the loop calling validate_change below.
    4557              : 
    4558              :      We used to suppress canonicalization of DEST if it appears in SRC,
    4559              :      but we don't do this any more.  */
    4560              : 
    4561    610917163 :   for (i = 0; i < n_sets; i++)
    4562              :     {
    4563    199993680 :       rtx dest = SET_DEST (sets[i].rtl);
    4564    199993680 :       rtx src = SET_SRC (sets[i].rtl);
    4565    199993680 :       rtx new_rtx = canon_reg (src, insn);
    4566              : 
    4567    199993680 :       validate_change (insn, &SET_SRC (sets[i].rtl), new_rtx, 1);
    4568              : 
    4569    199993680 :       if (GET_CODE (dest) == ZERO_EXTRACT)
    4570              :         {
    4571         4078 :           validate_change (insn, &XEXP (dest, 1),
    4572              :                            canon_reg (XEXP (dest, 1), insn), 1);
    4573         4078 :           validate_change (insn, &XEXP (dest, 2),
    4574              :                            canon_reg (XEXP (dest, 2), insn), 1);
    4575              :         }
    4576              : 
    4577    201675593 :       while (GET_CODE (dest) == SUBREG
    4578    200011662 :              || GET_CODE (dest) == ZERO_EXTRACT
    4579    401683177 :              || GET_CODE (dest) == STRICT_LOW_PART)
    4580      1681913 :         dest = XEXP (dest, 0);
    4581              : 
    4582    199993680 :       if (MEM_P (dest))
    4583     29418402 :         canon_reg (dest, insn);
    4584              :     }
    4585              : 
    4586              :   /* Now that we have done all the replacements, we can apply the change
    4587              :      group and see if they all work.  Note that this will cause some
    4588              :      canonicalizations that would have worked individually not to be applied
    4589              :      because some other canonicalization didn't work, but this should not
    4590              :      occur often.
    4591              : 
    4592              :      The result of apply_change_group can be ignored; see canon_reg.  */
    4593              : 
    4594    410923483 :   apply_change_group ();
    4595    410923483 : }
    4596              : 
    4597              : /* Main function of CSE.
    4598              :    First simplify sources and addresses of all assignments
    4599              :    in the instruction, using previously-computed equivalents values.
    4600              :    Then install the new sources and destinations in the table
    4601              :    of available values.  */
    4602              : 
    4603              : static void
    4604    410923483 : cse_insn (rtx_insn *insn)
    4605              : {
    4606    410923483 :   rtx x = PATTERN (insn);
    4607    410923483 :   int i;
    4608    410923483 :   rtx tem;
    4609    410923483 :   int n_sets = 0;
    4610              : 
    4611    410923483 :   rtx src_eqv = 0;
    4612    410923483 :   struct table_elt *src_eqv_elt = 0;
    4613    410923483 :   int src_eqv_volatile = 0;
    4614    410923483 :   int src_eqv_in_memory = 0;
    4615    410923483 :   unsigned src_eqv_hash = 0;
    4616              : 
    4617    410923483 :   this_insn = insn;
    4618              : 
    4619              :   /* Find all regs explicitly clobbered in this insn,
    4620              :      to ensure they are not replaced with any other regs
    4621              :      elsewhere in this insn.  */
    4622    410923483 :   invalidate_from_sets_and_clobbers (insn);
    4623              : 
    4624              :   /* Record all the SETs in this instruction.  */
    4625    410923483 :   auto_vec<struct set, 8> sets;
    4626    410923483 :   n_sets = find_sets_in_insn (insn, (vec<struct set>*)&sets);
    4627              : 
    4628              :   /* Substitute the canonical register where possible.  */
    4629    410923483 :   canonicalize_insn (insn, (vec<struct set>*)&sets);
    4630              : 
    4631              :   /* If this insn has a REG_EQUAL note, store the equivalent value in SRC_EQV,
    4632              :      if different, or if the DEST is a STRICT_LOW_PART/ZERO_EXTRACT.  The
    4633              :      latter condition is necessary because SRC_EQV is handled specially for
    4634              :      this case, and if it isn't set, then there will be no equivalence
    4635              :      for the destination.  */
    4636    196701915 :   if (n_sets == 1 && REG_NOTES (insn) != 0
    4637    537544702 :       && (tem = find_reg_note (insn, REG_EQUAL, NULL_RTX)) != 0)
    4638              :     {
    4639              : 
    4640      8944340 :       if (GET_CODE (SET_DEST (sets[0].rtl)) != ZERO_EXTRACT
    4641      8944340 :           && (! rtx_equal_p (XEXP (tem, 0), SET_SRC (sets[0].rtl))
    4642        16381 :               || GET_CODE (SET_DEST (sets[0].rtl)) == STRICT_LOW_PART))
    4643      8927959 :         src_eqv = copy_rtx (XEXP (tem, 0));
    4644              :       /* If DEST is of the form ZERO_EXTACT, as in:
    4645              :          (set (zero_extract:SI (reg:SI 119)
    4646              :                   (const_int 16 [0x10])
    4647              :                   (const_int 16 [0x10]))
    4648              :               (const_int 51154 [0xc7d2]))
    4649              :          REG_EQUAL note will specify the value of register (reg:SI 119) at this
    4650              :          point.  Note that this is different from SRC_EQV. We can however
    4651              :          calculate SRC_EQV with the position and width of ZERO_EXTRACT.  */
    4652        16381 :       else if (GET_CODE (SET_DEST (sets[0].rtl)) == ZERO_EXTRACT
    4653            0 :                && CONST_INT_P (XEXP (tem, 0))
    4654            0 :                && CONST_INT_P (XEXP (SET_DEST (sets[0].rtl), 1))
    4655        16381 :                && CONST_INT_P (XEXP (SET_DEST (sets[0].rtl), 2)))
    4656              :         {
    4657            0 :           rtx dest_reg = XEXP (SET_DEST (sets[0].rtl), 0);
    4658              :           /* This is the mode of XEXP (tem, 0) as well.  */
    4659            0 :           scalar_int_mode dest_mode
    4660            0 :             = as_a <scalar_int_mode> (GET_MODE (dest_reg));
    4661            0 :           rtx width = XEXP (SET_DEST (sets[0].rtl), 1);
    4662            0 :           rtx pos = XEXP (SET_DEST (sets[0].rtl), 2);
    4663            0 :           HOST_WIDE_INT val = INTVAL (XEXP (tem, 0));
    4664            0 :           HOST_WIDE_INT mask;
    4665            0 :           unsigned int shift;
    4666            0 :           if (BITS_BIG_ENDIAN)
    4667              :             shift = (GET_MODE_PRECISION (dest_mode)
    4668              :                      - INTVAL (pos) - INTVAL (width));
    4669              :           else
    4670            0 :             shift = INTVAL (pos);
    4671            0 :           if (INTVAL (width) == HOST_BITS_PER_WIDE_INT)
    4672              :             mask = HOST_WIDE_INT_M1;
    4673              :           else
    4674            0 :             mask = (HOST_WIDE_INT_1 << INTVAL (width)) - 1;
    4675            0 :           val = (val >> shift) & mask;
    4676            0 :           src_eqv = GEN_INT (val);
    4677              :         }
    4678              :     }
    4679              : 
    4680              :   /* Set sets[i].src_elt to the class each source belongs to.
    4681              :      Detect assignments from or to volatile things
    4682              :      and set set[i] to zero so they will be ignored
    4683              :      in the rest of this function.
    4684              : 
    4685              :      Nothing in this loop changes the hash table or the register chains.  */
    4686              : 
    4687    610917171 :   for (i = 0; i < n_sets; i++)
    4688              :     {
    4689    199993688 :       bool repeat = false;
    4690    199993688 :       bool noop_insn = false;
    4691    199993688 :       rtx src, dest;
    4692    199993688 :       rtx src_folded;
    4693    199993688 :       struct table_elt *elt = 0, *p;
    4694    199993688 :       machine_mode mode;
    4695    199993688 :       rtx src_eqv_here;
    4696    199993688 :       rtx src_const = 0;
    4697    199993688 :       rtx src_related = 0;
    4698    199993688 :       rtx dest_related = 0;
    4699    199993688 :       bool src_related_is_const_anchor = false;
    4700    199993688 :       struct table_elt *src_const_elt = 0;
    4701    199993688 :       int src_cost = MAX_COST;
    4702    199993688 :       int src_eqv_cost = MAX_COST;
    4703    199993688 :       int src_folded_cost = MAX_COST;
    4704    199993688 :       int src_related_cost = MAX_COST;
    4705    199993688 :       int src_elt_cost = MAX_COST;
    4706    199993688 :       int src_regcost = MAX_COST;
    4707    199993688 :       int src_eqv_regcost = MAX_COST;
    4708    199993688 :       int src_folded_regcost = MAX_COST;
    4709    199993688 :       int src_related_regcost = MAX_COST;
    4710    199993688 :       int src_elt_regcost = MAX_COST;
    4711    199993688 :       scalar_int_mode int_mode;
    4712    199993688 :       bool is_fake_set = sets[i].is_fake_set;
    4713              : 
    4714    199993688 :       dest = SET_DEST (sets[i].rtl);
    4715    199993688 :       src = SET_SRC (sets[i].rtl);
    4716              : 
    4717              :       /* If SRC is a constant that has no machine mode,
    4718              :          hash it with the destination's machine mode.
    4719              :          This way we can keep different modes separate.  */
    4720              : 
    4721    199993688 :       mode = GET_MODE (src) == VOIDmode ? GET_MODE (dest) : GET_MODE (src);
    4722    199993688 :       sets[i].mode = mode;
    4723              : 
    4724    199993688 :       if (!is_fake_set && src_eqv)
    4725              :         {
    4726      8927959 :           machine_mode eqvmode = mode;
    4727      8927959 :           if (GET_CODE (dest) == STRICT_LOW_PART)
    4728            0 :             eqvmode = GET_MODE (SUBREG_REG (XEXP (dest, 0)));
    4729      8927959 :           do_not_record = 0;
    4730      8927959 :           hash_arg_in_memory = 0;
    4731      8927959 :           src_eqv_hash = HASH (src_eqv, eqvmode);
    4732              : 
    4733              :           /* Find the equivalence class for the equivalent expression.  */
    4734              : 
    4735      8927959 :           if (!do_not_record)
    4736      8925775 :             src_eqv_elt = lookup (src_eqv, src_eqv_hash, eqvmode);
    4737              : 
    4738      8927959 :           src_eqv_volatile = do_not_record;
    4739      8927959 :           src_eqv_in_memory = hash_arg_in_memory;
    4740              :         }
    4741              : 
    4742              :       /* If this is a STRICT_LOW_PART assignment, src_eqv corresponds to the
    4743              :          value of the INNER register, not the destination.  So it is not
    4744              :          a valid substitution for the source.  But save it for later.  */
    4745    199993688 :       if (is_fake_set || GET_CODE (dest) == STRICT_LOW_PART)
    4746              :         src_eqv_here = 0;
    4747              :       else
    4748    199993688 :         src_eqv_here = src_eqv;
    4749              : 
    4750              :       /* Simplify and foldable subexpressions in SRC.  Then get the fully-
    4751              :          simplified result, which may not necessarily be valid.  */
    4752    199993688 :       src_folded = fold_rtx (src, NULL);
    4753              : 
    4754              : #if 0
    4755              :       /* ??? This caused bad code to be generated for the m68k port with -O2.
    4756              :          Suppose src is (CONST_INT -1), and that after truncation src_folded
    4757              :          is (CONST_INT 3).  Suppose src_folded is then used for src_const.
    4758              :          At the end we will add src and src_const to the same equivalence
    4759              :          class.  We now have 3 and -1 on the same equivalence class.  This
    4760              :          causes later instructions to be mis-optimized.  */
    4761              :       /* If storing a constant in a bitfield, pre-truncate the constant
    4762              :          so we will be able to record it later.  */
    4763              :       if (GET_CODE (SET_DEST (sets[i].rtl)) == ZERO_EXTRACT)
    4764              :         {
    4765              :           rtx width = XEXP (SET_DEST (sets[i].rtl), 1);
    4766              : 
    4767              :           if (CONST_INT_P (src)
    4768              :               && CONST_INT_P (width)
    4769              :               && INTVAL (width) < HOST_BITS_PER_WIDE_INT
    4770              :               && (INTVAL (src) & ((HOST_WIDE_INT) (-1) << INTVAL (width))))
    4771              :             src_folded
    4772              :               = GEN_INT (INTVAL (src) & ((HOST_WIDE_INT_1
    4773              :                                           << INTVAL (width)) - 1));
    4774              :         }
    4775              : #endif
    4776              : 
    4777              :       /* Compute SRC's hash code, and also notice if it
    4778              :          should not be recorded at all.  In that case,
    4779              :          prevent any further processing of this assignment.
    4780              : 
    4781              :          We set DO_NOT_RECORD if the destination has a REG_UNUSED note.
    4782              :          This avoids getting the source register into the tables, where it
    4783              :          may be invalidated later (via REG_QTY), then trigger an ICE upon
    4784              :          re-insertion.
    4785              : 
    4786              :          This is only a problem in multi-set insns.  If it were a single
    4787              :          set the dead copy would have been removed.  If the RHS were anything
    4788              :          but a simple REG, then we won't call insert_regs and thus there's
    4789              :          no potential for triggering the ICE.  */
    4790    399987376 :       do_not_record = (REG_P (dest)
    4791    148426693 :                        && REG_P (src)
    4792    235282440 :                        && find_reg_note (insn, REG_UNUSED, dest));
    4793    199993688 :       hash_arg_in_memory = 0;
    4794              : 
    4795    199993688 :       sets[i].src = src;
    4796    199993688 :       sets[i].src_hash = HASH (src, mode);
    4797    199993688 :       sets[i].src_volatile = do_not_record;
    4798    199993688 :       sets[i].src_in_memory = hash_arg_in_memory;
    4799              : 
    4800              :       /* If SRC is a MEM, there is a REG_EQUIV note for SRC, and DEST is
    4801              :          a pseudo, do not record SRC.  Using SRC as a replacement for
    4802              :          anything else will be incorrect in that situation.  Note that
    4803              :          this usually occurs only for stack slots, in which case all the
    4804              :          RTL would be referring to SRC, so we don't lose any optimization
    4805              :          opportunities by not having SRC in the hash table.  */
    4806              : 
    4807    199993688 :       if (MEM_P (src)
    4808     25495413 :           && find_reg_note (insn, REG_EQUIV, NULL_RTX) != 0
    4809       925196 :           && REG_P (dest)
    4810    200918884 :           && REGNO (dest) >= FIRST_PSEUDO_REGISTER)
    4811       925196 :         sets[i].src_volatile = 1;
    4812              : 
    4813    199068492 :       else if (GET_CODE (src) == ASM_OPERANDS
    4814       213512 :                && GET_CODE (x) == PARALLEL)
    4815              :         {
    4816              :           /* Do not record result of a non-volatile inline asm with
    4817              :              more than one result.  */
    4818       213488 :           if (n_sets > 1)
    4819       169858 :             sets[i].src_volatile = 1;
    4820              : 
    4821       213488 :           int j, lim = XVECLEN (x, 0);
    4822      1091742 :           for (j = 0; j < lim; j++)
    4823              :             {
    4824       880702 :               rtx y = XVECEXP (x, 0, j);
    4825              :               /* And do not record result of a non-volatile inline asm
    4826              :                  with "memory" clobber.  */
    4827       880702 :               if (GET_CODE (y) == CLOBBER && MEM_P (XEXP (y, 0)))
    4828              :                 {
    4829         2448 :                   sets[i].src_volatile = 1;
    4830         2448 :                   break;
    4831              :                 }
    4832              :             }
    4833              :         }
    4834              : 
    4835              : #if 0
    4836              :       /* It is no longer clear why we used to do this, but it doesn't
    4837              :          appear to still be needed.  So let's try without it since this
    4838              :          code hurts cse'ing widened ops.  */
    4839              :       /* If source is a paradoxical subreg (such as QI treated as an SI),
    4840              :          treat it as volatile.  It may do the work of an SI in one context
    4841              :          where the extra bits are not being used, but cannot replace an SI
    4842              :          in general.  */
    4843              :       if (paradoxical_subreg_p (src))
    4844              :         sets[i].src_volatile = 1;
    4845              : #endif
    4846              : 
    4847              :       /* Locate all possible equivalent forms for SRC.  Try to replace
    4848              :          SRC in the insn with each cheaper equivalent.
    4849              : 
    4850              :          We have the following types of equivalents: SRC itself, a folded
    4851              :          version, a value given in a REG_EQUAL note, or a value related
    4852              :          to a constant.
    4853              : 
    4854              :          Each of these equivalents may be part of an additional class
    4855              :          of equivalents (if more than one is in the table, they must be in
    4856              :          the same class; we check for this).
    4857              : 
    4858              :          If the source is volatile, we don't do any table lookups.
    4859              : 
    4860              :          We note any constant equivalent for possible later use in a
    4861              :          REG_NOTE.  */
    4862              : 
    4863    199993688 :       if (!sets[i].src_volatile)
    4864    165212334 :         elt = lookup (src, sets[i].src_hash, mode);
    4865              : 
    4866    199993688 :       sets[i].src_elt = elt;
    4867              : 
    4868    199993688 :       if (elt && src_eqv_here && src_eqv_elt)
    4869              :         {
    4870      3024917 :           if (elt->first_same_value != src_eqv_elt->first_same_value)
    4871              :             {
    4872              :               /* The REG_EQUAL is indicating that two formerly distinct
    4873              :                  classes are now equivalent.  So merge them.  */
    4874         9827 :               merge_equiv_classes (elt, src_eqv_elt);
    4875         9827 :               src_eqv_hash = HASH (src_eqv, elt->mode);
    4876         9827 :               src_eqv_elt = lookup (src_eqv, src_eqv_hash, elt->mode);
    4877              :             }
    4878              : 
    4879              :           src_eqv_here = 0;
    4880              :         }
    4881              : 
    4882    196769921 :       else if (src_eqv_elt)
    4883              :         elt = src_eqv_elt;
    4884              : 
    4885              :       /* Try to find a constant somewhere and record it in `src_const'.
    4886              :          Record its table element, if any, in `src_const_elt'.  Look in
    4887              :          any known equivalences first.  (If the constant is not in the
    4888              :          table, also set `sets[i].src_const_hash').  */
    4889    196593180 :       if (elt)
    4890    103635499 :         for (p = elt->first_same_value; p; p = p->next_same_value)
    4891     85007728 :           if (p->is_const)
    4892              :             {
    4893     16729800 :               src_const = p->exp;
    4894     16729800 :               src_const_elt = elt;
    4895     16729800 :               break;
    4896              :             }
    4897              : 
    4898     35357571 :       if (src_const == 0
    4899    183263888 :           && (CONSTANT_P (src_folded)
    4900              :               /* Consider (minus (label_ref L1) (label_ref L2)) as
    4901              :                  "constant" here so we will record it. This allows us
    4902              :                  to fold switch statements when an ADDR_DIFF_VEC is used.  */
    4903    155976949 :               || (GET_CODE (src_folded) == MINUS
    4904      1912175 :                   && GET_CODE (XEXP (src_folded, 0)) == LABEL_REF
    4905           95 :                   && GET_CODE (XEXP (src_folded, 1)) == LABEL_REF)))
    4906              :         src_const = src_folded, src_const_elt = elt;
    4907    172706663 :       else if (src_const == 0 && src_eqv_here && CONSTANT_P (src_eqv_here))
    4908       423354 :         src_const = src_eqv_here, src_const_elt = src_eqv_elt;
    4909              : 
    4910              :       /* If we don't know if the constant is in the table, get its
    4911              :          hash code and look it up.  */
    4912    199993688 :       if (src_const && src_const_elt == 0)
    4913              :         {
    4914     27709335 :           sets[i].src_const_hash = HASH (src_const, mode);
    4915     27709335 :           src_const_elt = lookup (src_const, sets[i].src_const_hash, mode);
    4916              :         }
    4917              : 
    4918    199993688 :       sets[i].src_const = src_const;
    4919    199993688 :       sets[i].src_const_elt = src_const_elt;
    4920              : 
    4921              :       /* If the constant and our source are both in the table, mark them as
    4922              :          equivalent.  Otherwise, if a constant is in the table but the source
    4923              :          isn't, set ELT to it.  */
    4924    199993688 :       if (src_const_elt && elt
    4925     16730844 :           && src_const_elt->first_same_value != elt->first_same_value)
    4926            0 :         merge_equiv_classes (elt, src_const_elt);
    4927    199993688 :       else if (src_const_elt && elt == 0)
    4928    199993688 :         elt = src_const_elt;
    4929              : 
    4930              :       /* See if there is a register linearly related to a constant
    4931              :          equivalent of SRC.  */
    4932    199993688 :       if (src_const
    4933     44440179 :           && (GET_CODE (src_const) == CONST
    4934     43776699 :               || (src_const_elt && src_const_elt->related_value != 0)))
    4935              :         {
    4936       756853 :           src_related = use_related_value (src_const, src_const_elt);
    4937       756853 :           if (src_related)
    4938              :             {
    4939       230030 :               struct table_elt *src_related_elt
    4940       230030 :                 = lookup (src_related, HASH (src_related, mode), mode);
    4941       230030 :               if (src_related_elt && elt)
    4942              :                 {
    4943         1921 :                   if (elt->first_same_value
    4944         1921 :                       != src_related_elt->first_same_value)
    4945              :                     /* This can occur when we previously saw a CONST
    4946              :                        involving a SYMBOL_REF and then see the SYMBOL_REF
    4947              :                        twice.  Merge the involved classes.  */
    4948          915 :                     merge_equiv_classes (elt, src_related_elt);
    4949              : 
    4950              :                   src_related = 0;
    4951    199993688 :                   src_related_elt = 0;
    4952              :                 }
    4953       228109 :               else if (src_related_elt && elt == 0)
    4954         6923 :                 elt = src_related_elt;
    4955              :             }
    4956              :         }
    4957              : 
    4958              :       /* See if we have a CONST_INT that is already in a register in a
    4959              :          wider mode.  */
    4960              : 
    4961     44212070 :       if (src_const && src_related == 0 && CONST_INT_P (src_const)
    4962     19279242 :           && is_int_mode (mode, &int_mode)
    4963    221305719 :           && GET_MODE_PRECISION (int_mode) < BITS_PER_WORD)
    4964              :         {
    4965      8393000 :           opt_scalar_int_mode wider_mode_iter;
    4966     21442317 :           FOR_EACH_WIDER_MODE (wider_mode_iter, int_mode)
    4967              :             {
    4968     21442317 :               scalar_int_mode wider_mode = wider_mode_iter.require ();
    4969     22194294 :               if (GET_MODE_PRECISION (wider_mode) > BITS_PER_WORD)
    4970              :                 break;
    4971              : 
    4972     13292003 :               struct table_elt *const_elt
    4973     13292003 :                 = lookup (src_const, HASH (src_const, wider_mode), wider_mode);
    4974              : 
    4975     13292003 :               if (const_elt == 0)
    4976     12609323 :                 continue;
    4977              : 
    4978       682680 :               for (const_elt = const_elt->first_same_value;
    4979      2072660 :                    const_elt; const_elt = const_elt->next_same_value)
    4980      1632666 :                 if (REG_P (const_elt->exp))
    4981              :                   {
    4982       242686 :                     src_related = gen_lowpart (int_mode, const_elt->exp);
    4983       242686 :                     break;
    4984              :                   }
    4985              : 
    4986       682680 :               if (src_related != 0)
    4987              :                 break;
    4988              :             }
    4989              :         }
    4990              : 
    4991              :       /* Another possibility is that we have an AND with a constant in
    4992              :          a mode narrower than a word.  If so, it might have been generated
    4993              :          as part of an "if" which would narrow the AND.  If we already
    4994              :          have done the AND in a wider mode, we can use a SUBREG of that
    4995              :          value.  */
    4996              : 
    4997    195594941 :       if (flag_expensive_optimizations && ! src_related
    4998    334530360 :           && is_a <scalar_int_mode> (mode, &int_mode)
    4999    134536672 :           && GET_CODE (src) == AND && CONST_INT_P (XEXP (src, 1))
    5000    201306854 :           && GET_MODE_SIZE (int_mode) < UNITS_PER_WORD)
    5001              :         {
    5002       784553 :           opt_scalar_int_mode tmode_iter;
    5003       784553 :           rtx new_and = gen_rtx_AND (VOIDmode, NULL_RTX, XEXP (src, 1));
    5004              : 
    5005      2303874 :           FOR_EACH_WIDER_MODE (tmode_iter, int_mode)
    5006              :             {
    5007      2303874 :               scalar_int_mode tmode = tmode_iter.require ();
    5008      4760053 :               if (GET_MODE_SIZE (tmode) > UNITS_PER_WORD)
    5009              :                 break;
    5010              : 
    5011      1519390 :               rtx inner = gen_lowpart (tmode, XEXP (src, 0));
    5012      1519390 :               struct table_elt *larger_elt;
    5013              : 
    5014      1519390 :               if (inner)
    5015              :                 {
    5016      1509696 :                   PUT_MODE (new_and, tmode);
    5017      1509696 :                   XEXP (new_and, 0) = inner;
    5018      1509696 :                   larger_elt = lookup (new_and, HASH (new_and, tmode), tmode);
    5019      1509696 :                   if (larger_elt == 0)
    5020      1509627 :                     continue;
    5021              : 
    5022           69 :                   for (larger_elt = larger_elt->first_same_value;
    5023           69 :                        larger_elt; larger_elt = larger_elt->next_same_value)
    5024           69 :                     if (REG_P (larger_elt->exp))
    5025              :                       {
    5026           69 :                         src_related
    5027           69 :                           = gen_lowpart (int_mode, larger_elt->exp);
    5028           69 :                         break;
    5029              :                       }
    5030              : 
    5031           69 :                   if (src_related)
    5032              :                     break;
    5033              :                 }
    5034              :             }
    5035              :         }
    5036              : 
    5037              :       /* If SRC_EQV is a CONST_INT, try looking up some related
    5038              :          constants (logical and arithmetic negation).  Those may
    5039              :          ultimately be cheaper to re-use.  */
    5040    199993688 :       if (GET_CODE (src) != CONST_INT
    5041              :           && GET_CODE (src) != REG
    5042              :           && GET_CODE (src) != SUBREG
    5043    123940504 :           && src_const
    5044     16526434 :           && GET_CODE (src_const) == CONST_INT)
    5045              :         {
    5046        68501 :           rtx trial_rtx = GEN_INT (~UINTVAL (src_const));
    5047        68501 :           struct table_elt *tmp = lookup (trial_rtx, HASH (trial_rtx, mode), mode);
    5048        68501 :           rtx_code code = NOT;
    5049        68501 :           if (!tmp)
    5050              :             {
    5051        67345 :               trial_rtx = GEN_INT (-UINTVAL (src_const));
    5052        67345 :               tmp = lookup (trial_rtx, HASH (trial_rtx, mode), mode);
    5053        67345 :               code = NEG;
    5054              :             }
    5055              : 
    5056        67345 :           if (tmp)
    5057              :             {
    5058        10912 :               src_related = gen_rtx_fmt_e (code, mode, tmp->first_same_value->exp);
    5059        10912 :               src_eqv_here = src_related;
    5060        10912 :               src_related_is_const_anchor = true;
    5061              :             }
    5062              : 
    5063              :         }
    5064              : 
    5065              :       /* See if a MEM has already been loaded with a widening operation;
    5066              :          if it has, we can use a subreg of that.  Many CISC machines
    5067              :          also have such operations, but this is only likely to be
    5068              :          beneficial on these machines.  */
    5069              : 
    5070    199993688 :       rtx_code extend_op;
    5071    199993688 :       if (flag_expensive_optimizations && src_related == 0
    5072              :           && MEM_P (src) && ! do_not_record
    5073              :           && is_a <scalar_int_mode> (mode, &int_mode)
    5074              :           && (extend_op = load_extend_op (int_mode)) != UNKNOWN)
    5075              :         {
    5076              : #if GCC_VERSION >= 5000
    5077              :           struct rtx_def memory_extend_buf;
    5078              :           rtx memory_extend_rtx = &memory_extend_buf;
    5079              : #else
    5080              :           /* Workaround GCC < 5 bug, fixed in r5-3834 as part of PR63362
    5081              :              fix.  */
    5082              :           alignas (rtx_def) unsigned char memory_extended_buf[sizeof (rtx_def)];
    5083              :           rtx memory_extend_rtx = (rtx) &memory_extended_buf[0];
    5084              : #endif
    5085              : 
    5086              :           /* Set what we are trying to extend and the operation it might
    5087              :              have been extended with.  */
    5088              :           memset (memory_extend_rtx, 0, sizeof (*memory_extend_rtx));
    5089              :           PUT_CODE (memory_extend_rtx, extend_op);
    5090              :           XEXP (memory_extend_rtx, 0) = src;
    5091              : 
    5092              :           opt_scalar_int_mode tmode_iter;
    5093              :           FOR_EACH_WIDER_MODE (tmode_iter, int_mode)
    5094              :             {
    5095              :               struct table_elt *larger_elt;
    5096              : 
    5097              :               scalar_int_mode tmode = tmode_iter.require ();
    5098              :               if (GET_MODE_SIZE (tmode) > UNITS_PER_WORD)
    5099              :                 break;
    5100              : 
    5101              :               PUT_MODE (memory_extend_rtx, tmode);
    5102              :               larger_elt = lookup (memory_extend_rtx,
    5103              :                                    HASH (memory_extend_rtx, tmode), tmode);
    5104              :               if (larger_elt == 0)
    5105              :                 continue;
    5106              : 
    5107              :               for (larger_elt = larger_elt->first_same_value;
    5108              :                    larger_elt; larger_elt = larger_elt->next_same_value)
    5109              :                 if (REG_P (larger_elt->exp))
    5110              :                   {
    5111              :                     src_related = gen_lowpart (int_mode, larger_elt->exp);
    5112              :                     break;
    5113              :                   }
    5114              : 
    5115              :               if (src_related)
    5116              :                 break;
    5117              :             }
    5118              :         }
    5119              : 
    5120              :       /* Try to express the constant using a register+offset expression
    5121              :          derived from a constant anchor.  */
    5122              : 
    5123    199993688 :       if (targetm.const_anchor
    5124            0 :           && !src_related
    5125            0 :           && src_const
    5126            0 :           && GET_CODE (src_const) == CONST_INT)
    5127              :         {
    5128            0 :           src_related = try_const_anchors (src_const, mode);
    5129            0 :           src_related_is_const_anchor = src_related != NULL_RTX;
    5130              :         }
    5131              : 
    5132              :       /* Try to re-materialize a vec_dup with an existing constant.   */
    5133    199993688 :       rtx src_elt;
    5134      5913917 :       if ((!src_eqv_here || CONSTANT_P (src_eqv_here))
    5135    199993688 :           && const_vec_duplicate_p (src, &src_elt))
    5136              :         {
    5137       687298 :            machine_mode const_mode = GET_MODE_INNER (GET_MODE (src));
    5138       687298 :            struct table_elt *related_elt
    5139       687298 :                 = lookup (src_elt, HASH (src_elt, const_mode), const_mode);
    5140       687298 :            if (related_elt)
    5141              :             {
    5142       273179 :               for (related_elt = related_elt->first_same_value;
    5143      2096451 :                    related_elt; related_elt = related_elt->next_same_value)
    5144      1854991 :                 if (REG_P (related_elt->exp))
    5145              :                   {
    5146              :                    /* We don't need to compare costs with an existing (constant)
    5147              :                       src_eqv_here, since any such src_eqv_here should already be
    5148              :                       available in src_const.  */
    5149        31719 :                     src_eqv_here
    5150        31719 :                         = gen_rtx_VEC_DUPLICATE (GET_MODE (src),
    5151              :                                                  related_elt->exp);
    5152        31719 :                     break;
    5153              :                   }
    5154              :             }
    5155              :         }
    5156              : 
    5157    199993688 :       if (src == src_folded)
    5158    195520140 :         src_folded = 0;
    5159              : 
    5160              :       /* At this point, ELT, if nonzero, points to a class of expressions
    5161              :          equivalent to the source of this SET and SRC, SRC_EQV, SRC_FOLDED,
    5162              :          and SRC_RELATED, if nonzero, each contain additional equivalent
    5163              :          expressions.  Prune these latter expressions by deleting expressions
    5164              :          already in the equivalence class.
    5165              : 
    5166              :          Check for an equivalent identical to the destination.  If found,
    5167              :          this is the preferred equivalent since it will likely lead to
    5168              :          elimination of the insn.  Indicate this by placing it in
    5169              :          `src_related'.  */
    5170              : 
    5171    199993688 :       if (elt)
    5172     35427997 :         elt = elt->first_same_value;
    5173    321151569 :       for (p = elt; p; p = p->next_same_value)
    5174              :         {
    5175    121157881 :           enum rtx_code code = GET_CODE (p->exp);
    5176              : 
    5177              :           /* If the expression is not valid, ignore it.  Then we do not
    5178              :              have to check for validity below.  In most cases, we can use
    5179              :              `rtx_equal_p', since canonicalization has already been done.  */
    5180    121157881 :           if (code != REG && ! exp_equiv_p (p->exp, p->exp, 1, false))
    5181         4480 :             continue;
    5182              : 
    5183              :           /* Also skip paradoxical subregs, unless that's what we're
    5184              :              looking for.  */
    5185    121153401 :           if (paradoxical_subreg_p (p->exp)
    5186      2822322 :               && ! (src != 0
    5187         3378 :                     && GET_CODE (src) == SUBREG
    5188         3378 :                     && GET_MODE (src) == GET_MODE (p->exp)
    5189         3378 :                     && partial_subreg_p (GET_MODE (SUBREG_REG (src)),
    5190              :                                          GET_MODE (SUBREG_REG (p->exp)))))
    5191         3633 :             continue;
    5192              : 
    5193    121149768 :           if (src && GET_CODE (src) == code && rtx_equal_p (src, p->exp))
    5194              :             src = 0;
    5195      2257293 :           else if (src_folded && GET_CODE (src_folded) == code
    5196     86760002 :                    && rtx_equal_p (src_folded, p->exp))
    5197              :             src_folded = 0;
    5198       781854 :           else if (src_eqv_here && GET_CODE (src_eqv_here) == code
    5199     85932075 :                    && rtx_equal_p (src_eqv_here, p->exp))
    5200              :             src_eqv_here = 0;
    5201       741505 :           else if (src_related && GET_CODE (src_related) == code
    5202     85369577 :                    && rtx_equal_p (src_related, p->exp))
    5203              :             src_related = 0;
    5204              : 
    5205              :           /* This is the same as the destination of the insns, we want
    5206              :              to prefer it.  The code below will then give it a negative
    5207              :              cost.  */
    5208    121149768 :           if (!dest_related
    5209    121149768 :               && GET_CODE (dest) == code && rtx_equal_p (p->exp, dest))
    5210       225422 :             dest_related = p->exp;
    5211              :         }
    5212              : 
    5213              :       /* Find the cheapest valid equivalent, trying all the available
    5214              :          possibilities.  Prefer items not in the hash table to ones
    5215              :          that are when they are equal cost.  Note that we can never
    5216              :          worsen an insn as the current contents will also succeed.
    5217              :          If we find an equivalent identical to the destination, use it as best,
    5218              :          since this insn will probably be eliminated in that case.  */
    5219    199993688 :       if (src)
    5220              :         {
    5221    165035462 :           if (rtx_equal_p (src, dest))
    5222              :             src_cost = src_regcost = -1;
    5223              :           else
    5224              :             {
    5225    165035456 :               src_cost = COST (src, mode);
    5226    165035456 :               src_regcost = approx_reg_cost (src);
    5227              :             }
    5228              :         }
    5229              : 
    5230    199993688 :       if (src_eqv_here)
    5231              :         {
    5232      5637629 :           if (rtx_equal_p (src_eqv_here, dest))
    5233              :             src_eqv_cost = src_eqv_regcost = -1;
    5234              :           else
    5235              :             {
    5236      5637629 :               src_eqv_cost = COST (src_eqv_here, mode);
    5237      5637629 :               src_eqv_regcost = approx_reg_cost (src_eqv_here);
    5238              :             }
    5239              :         }
    5240              : 
    5241    199993688 :       if (src_folded)
    5242              :         {
    5243      3905738 :           if (rtx_equal_p (src_folded, dest))
    5244              :             src_folded_cost = src_folded_regcost = -1;
    5245              :           else
    5246              :             {
    5247      3893098 :               src_folded_cost = COST (src_folded, mode);
    5248      3893098 :               src_folded_regcost = approx_reg_cost (src_folded);
    5249              :             }
    5250              :         }
    5251              : 
    5252    199993688 :       if (dest_related)
    5253              :         {
    5254              :           src_related_cost = src_related_regcost = -1;
    5255              :           /* Handle it as src_related.  */
    5256              :           src_related = dest_related;
    5257              :         }
    5258    199768266 :       else if (src_related)
    5259              :         {
    5260       476662 :           src_related_cost = COST (src_related, mode);
    5261       476662 :           src_related_regcost = approx_reg_cost (src_related);
    5262              : 
    5263              :           /* If a const-anchor is used to synthesize a constant that
    5264              :              normally requires multiple instructions then slightly prefer
    5265              :              it over the original sequence.  These instructions are likely
    5266              :              to become redundant now.  We can't compare against the cost
    5267              :              of src_eqv_here because, on MIPS for example, multi-insn
    5268              :              constants have zero cost; they are assumed to be hoisted from
    5269              :              loops.  */
    5270       476662 :           if (src_related_is_const_anchor
    5271       476662 :               && src_related_cost == src_cost
    5272         6007 :               && src_eqv_here)
    5273         6005 :             src_related_cost--;
    5274              :         }
    5275              : 
    5276              :       /* If this was an indirect jump insn, a known label will really be
    5277              :          cheaper even though it looks more expensive.  */
    5278    199993688 :       if (dest == pc_rtx && src_const && GET_CODE (src_const) == LABEL_REF)
    5279    199993688 :         src_folded = src_const, src_folded_cost = src_folded_regcost = -1;
    5280              : 
    5281              :       /* Terminate loop when replacement made.  This must terminate since
    5282              :          the current contents will be tested and will always be valid.  */
    5283    205413411 :       while (!is_fake_set)
    5284              :         {
    5285              :           rtx trial;
    5286              : 
    5287              :           /* Skip invalid entries.  */
    5288     36457210 :           while (elt && !REG_P (elt->exp)
    5289    213796040 :                  && ! exp_equiv_p (elt->exp, elt->exp, 1, false))
    5290           12 :             elt = elt->next_same_value;
    5291              : 
    5292              :           /* A paradoxical subreg would be bad here: it'll be the right
    5293              :              size, but later may be adjusted so that the upper bits aren't
    5294              :              what we want.  So reject it.  */
    5295    204732509 :           if (elt != 0
    5296     36457198 :               && paradoxical_subreg_p (elt->exp)
    5297              :               /* It is okay, though, if the rtx we're trying to match
    5298              :                  will ignore any of the bits we can't predict.  */
    5299    204733683 :               && ! (src != 0
    5300         1174 :                     && GET_CODE (src) == SUBREG
    5301         1174 :                     && GET_MODE (src) == GET_MODE (elt->exp)
    5302         1174 :                     && partial_subreg_p (GET_MODE (SUBREG_REG (src)),
    5303              :                                          GET_MODE (SUBREG_REG (elt->exp)))))
    5304              :             {
    5305         1174 :               elt = elt->next_same_value;
    5306         1174 :               continue;
    5307              :             }
    5308              : 
    5309    204730161 :           if (elt)
    5310              :             {
    5311     36456024 :               src_elt_cost = elt->cost;
    5312     36456024 :               src_elt_regcost = elt->regcost;
    5313              :             }
    5314              : 
    5315              :           /* Find cheapest and skip it for the next time.   For items
    5316              :              of equal cost, use this order:
    5317              :              src_folded, src, src_eqv, src_related and hash table entry.  */
    5318    204730161 :           if (src_folded
    5319      8206206 :               && preferable (src_folded_cost, src_folded_regcost,
    5320              :                              src_cost, src_regcost) <= 0
    5321      6307256 :               && preferable (src_folded_cost, src_folded_regcost,
    5322              :                              src_eqv_cost, src_eqv_regcost) <= 0
    5323      5413616 :               && preferable (src_folded_cost, src_folded_regcost,
    5324              :                              src_related_cost, src_related_regcost) <= 0
    5325    210139807 :               && preferable (src_folded_cost, src_folded_regcost,
    5326              :                              src_elt_cost, src_elt_regcost) <= 0)
    5327              :             trial = src_folded, src_folded_cost = MAX_COST;
    5328    199821257 :           else if (src
    5329    163872576 :                    && preferable (src_cost, src_regcost,
    5330              :                                   src_eqv_cost, src_eqv_regcost) <= 0
    5331    162309579 :                    && preferable (src_cost, src_regcost,
    5332              :                                   src_related_cost, src_related_regcost) <= 0
    5333    362104085 :                    && preferable (src_cost, src_regcost,
    5334              :                                   src_elt_cost, src_elt_regcost) <= 0)
    5335              :             trial = src, src_cost = MAX_COST;
    5336     37611093 :           else if (src_eqv_here
    5337      1772426 :                    && preferable (src_eqv_cost, src_eqv_regcost,
    5338              :                                   src_related_cost, src_related_regcost) <= 0
    5339     39378099 :                    && preferable (src_eqv_cost, src_eqv_regcost,
    5340              :                                   src_elt_cost, src_elt_regcost) <= 0)
    5341              :             trial = src_eqv_here, src_eqv_cost = MAX_COST;
    5342     36057550 :           else if (src_related
    5343     36057550 :                    && preferable (src_related_cost, src_related_regcost,
    5344              :                                   src_elt_cost, src_elt_regcost) <= 0)
    5345              :             trial = src_related, src_related_cost = MAX_COST;
    5346              :           else
    5347              :             {
    5348     35811977 :               trial = elt->exp;
    5349     35811977 :               elt = elt->next_same_value;
    5350     35811977 :               src_elt_cost = MAX_COST;
    5351              :             }
    5352              : 
    5353              :           /* Try to optimize
    5354              :              (set (reg:M N) (const_int A))
    5355              :              (set (reg:M2 O) (const_int B))
    5356              :              (set (zero_extract:M2 (reg:M N) (const_int C) (const_int D))
    5357              :                   (reg:M2 O)).  */
    5358    204730161 :           if (GET_CODE (SET_DEST (sets[i].rtl)) == ZERO_EXTRACT
    5359         4078 :               && CONST_INT_P (trial)
    5360          737 :               && CONST_INT_P (XEXP (SET_DEST (sets[i].rtl), 1))
    5361          737 :               && CONST_INT_P (XEXP (SET_DEST (sets[i].rtl), 2))
    5362          586 :               && REG_P (XEXP (SET_DEST (sets[i].rtl), 0))
    5363          106 :               && (known_ge
    5364              :                   (GET_MODE_PRECISION (GET_MODE (SET_DEST (sets[i].rtl))),
    5365              :                    INTVAL (XEXP (SET_DEST (sets[i].rtl), 1))))
    5366    204730267 :               && ((unsigned) INTVAL (XEXP (SET_DEST (sets[i].rtl), 1))
    5367          106 :                   + (unsigned) INTVAL (XEXP (SET_DEST (sets[i].rtl), 2))
    5368              :                   <= HOST_BITS_PER_WIDE_INT))
    5369              :             {
    5370          106 :               rtx dest_reg = XEXP (SET_DEST (sets[i].rtl), 0);
    5371          106 :               rtx width = XEXP (SET_DEST (sets[i].rtl), 1);
    5372          106 :               rtx pos = XEXP (SET_DEST (sets[i].rtl), 2);
    5373          106 :               unsigned int dest_hash = HASH (dest_reg, GET_MODE (dest_reg));
    5374          106 :               struct table_elt *dest_elt
    5375          106 :                 = lookup (dest_reg, dest_hash, GET_MODE (dest_reg));
    5376          106 :               rtx dest_cst = NULL;
    5377              : 
    5378          106 :               if (dest_elt)
    5379          153 :                 for (p = dest_elt->first_same_value; p; p = p->next_same_value)
    5380          104 :                   if (p->is_const && CONST_INT_P (p->exp))
    5381              :                     {
    5382              :                       dest_cst = p->exp;
    5383              :                       break;
    5384              :                     }
    5385           57 :               if (dest_cst)
    5386              :                 {
    5387            8 :                   HOST_WIDE_INT val = INTVAL (dest_cst);
    5388            8 :                   HOST_WIDE_INT mask;
    5389            8 :                   unsigned int shift;
    5390              :                   /* This is the mode of DEST_CST as well.  */
    5391            8 :                   scalar_int_mode dest_mode
    5392            8 :                     = as_a <scalar_int_mode> (GET_MODE (dest_reg));
    5393            8 :                   if (BITS_BIG_ENDIAN)
    5394              :                     shift = GET_MODE_PRECISION (dest_mode)
    5395              :                             - INTVAL (pos) - INTVAL (width);
    5396              :                   else
    5397            8 :                     shift = INTVAL (pos);
    5398            8 :                   if (INTVAL (width) == HOST_BITS_PER_WIDE_INT)
    5399              :                     mask = HOST_WIDE_INT_M1;
    5400              :                   else
    5401            8 :                     mask = (HOST_WIDE_INT_1 << INTVAL (width)) - 1;
    5402            8 :                   val &= ~(mask << shift);
    5403            8 :                   val |= (INTVAL (trial) & mask) << shift;
    5404            8 :                   val = trunc_int_for_mode (val, dest_mode);
    5405            8 :                   validate_unshare_change (insn, &SET_DEST (sets[i].rtl),
    5406              :                                            dest_reg, 1);
    5407            8 :                   validate_unshare_change (insn, &SET_SRC (sets[i].rtl),
    5408              :                                            GEN_INT (val), 1);
    5409            8 :                   if (apply_change_group ())
    5410              :                     {
    5411            8 :                       rtx note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
    5412            8 :                       if (note)
    5413              :                         {
    5414            0 :                           remove_note (insn, note);
    5415            0 :                           df_notes_rescan (insn);
    5416              :                         }
    5417            8 :                       src_eqv = NULL_RTX;
    5418            8 :                       src_eqv_elt = NULL;
    5419            8 :                       src_eqv_volatile = 0;
    5420            8 :                       src_eqv_in_memory = 0;
    5421            8 :                       src_eqv_hash = 0;
    5422            8 :                       repeat = true;
    5423            8 :                       break;
    5424              :                     }
    5425              :                 }
    5426              :             }
    5427              : 
    5428              :           /* We don't normally have an insn matching (set (pc) (pc)), so
    5429              :              check for this separately here.  We will delete such an
    5430              :              insn below.
    5431              : 
    5432              :              For other cases such as a table jump or conditional jump
    5433              :              where we know the ultimate target, go ahead and replace the
    5434              :              operand.  While that may not make a valid insn, we will
    5435              :              reemit the jump below (and also insert any necessary
    5436              :              barriers).  */
    5437    201677847 :           if (n_sets == 1 && dest == pc_rtx
    5438    225226361 :               && (trial == pc_rtx
    5439     20483795 :                   || (GET_CODE (trial) == LABEL_REF
    5440        11012 :                       && ! condjump_p (insn))))
    5441              :             {
    5442              :               /* Don't substitute non-local labels, this confuses CFG.  */
    5443        15150 :               if (GET_CODE (trial) == LABEL_REF
    5444        13782 :                   && LABEL_REF_NONLOCAL_P (trial))
    5445         1368 :                 continue;
    5446              : 
    5447        12414 :               SET_SRC (sets[i].rtl) = trial;
    5448        12414 :               cse_jumps_altered = true;
    5449        12414 :               break;
    5450              :             }
    5451              : 
    5452              :           /* Similarly, lots of targets don't allow no-op
    5453              :              (set (mem x) (mem x)) moves.  Even (set (reg x) (reg x))
    5454              :              might be impossible for certain registers (like CC registers).  */
    5455    204716371 :           else if (n_sets == 1
    5456    201664065 :                    && !CALL_P (insn)
    5457    201173986 :                    && (MEM_P (trial) || REG_P (trial))
    5458     81310587 :                    && rtx_equal_p (trial, dest)
    5459       215154 :                    && !side_effects_p (dest)
    5460       215150 :                    && (cfun->can_delete_dead_exceptions
    5461        49577 :                        || insn_nothrow_p (insn))
    5462              :                    /* We can only remove the later store if the earlier aliases
    5463              :                       at least all accesses the later one.  */
    5464    204921099 :                    && (!MEM_P (trial)
    5465        25272 :                        || ((MEM_ALIAS_SET (dest) == MEM_ALIAS_SET (trial)
    5466         8619 :                             || alias_set_subset_of (MEM_ALIAS_SET (dest),
    5467         8619 :                                                     MEM_ALIAS_SET (trial)))
    5468        17125 :                             && (!MEM_EXPR (trial)
    5469        16144 :                                 || refs_same_for_tbaa_p (MEM_EXPR (trial),
    5470        16144 :                                                          MEM_EXPR (dest))))))
    5471              :             {
    5472       193606 :               SET_SRC (sets[i].rtl) = trial;
    5473       193606 :               noop_insn = true;
    5474       193606 :               break;
    5475              :             }
    5476              : 
    5477              :           /* Reject certain invalid forms of CONST that we create.  */
    5478    204522765 :           else if (CONSTANT_P (trial)
    5479     33797368 :                    && GET_CODE (trial) == CONST
    5480              :                    /* Reject cases that will cause decode_rtx_const to
    5481              :                       die.  On the alpha when simplifying a switch, we
    5482              :                       get (const (truncate (minus (label_ref)
    5483              :                       (label_ref)))).  */
    5484       590975 :                    && (GET_CODE (XEXP (trial, 0)) == TRUNCATE
    5485              :                        /* Likewise on IA-64, except without the
    5486              :                           truncate.  */
    5487       590975 :                        || (GET_CODE (XEXP (trial, 0)) == MINUS
    5488            0 :                            && GET_CODE (XEXP (XEXP (trial, 0), 0)) == LABEL_REF
    5489            0 :                            && GET_CODE (XEXP (XEXP (trial, 0), 1)) == LABEL_REF)))
    5490              :             /* Do nothing for this case.  */
    5491              :             ;
    5492              : 
    5493              :           /* Do not replace anything with a MEM, except the replacement
    5494              :              is a no-op.  This allows this loop to terminate.  */
    5495    204522765 :           else if (MEM_P (trial) && !rtx_equal_p (trial, SET_SRC(sets[i].rtl)))
    5496              :             /* Do nothing for this case.  */
    5497              :             ;
    5498              : 
    5499              :           /* Look for a substitution that makes a valid insn.  */
    5500    204438606 :           else if (validate_unshare_change (insn, &SET_SRC (sets[i].rtl),
    5501              :                                             trial, 0))
    5502              :             {
    5503    199105584 :               rtx new_rtx = canon_reg (SET_SRC (sets[i].rtl), insn);
    5504              : 
    5505              :               /* The result of apply_change_group can be ignored; see
    5506              :                  canon_reg.  */
    5507              : 
    5508    199105584 :               validate_change (insn, &SET_SRC (sets[i].rtl), new_rtx, 1);
    5509    199105584 :               apply_change_group ();
    5510              : 
    5511    199105584 :               break;
    5512              :             }
    5513              : 
    5514              :           /* If the current function uses a constant pool and this is a
    5515              :              constant, try making a pool entry. Put it in src_folded
    5516              :              unless we already have done this since that is where it
    5517              :              likely came from.  */
    5518              : 
    5519      5333022 :           else if (crtl->uses_const_pool
    5520      3905277 :                    && CONSTANT_P (trial)
    5521      2887820 :                    && !CONST_INT_P (trial)
    5522      2869227 :                    && (src_folded == 0 || !MEM_P (src_folded))
    5523      1988123 :                    && GET_MODE_CLASS (mode) != MODE_CC
    5524      1988123 :                    && mode != VOIDmode)
    5525              :             {
    5526      1988123 :               src_folded = force_const_mem (mode, trial);
    5527      1988123 :               if (src_folded)
    5528              :                 {
    5529      1987534 :                   src_folded_cost = COST (src_folded, mode);
    5530      1987534 :                   src_folded_regcost = approx_reg_cost (src_folded);
    5531              :                 }
    5532              :             }
    5533              :         }
    5534              : 
    5535              :       /* If we changed the insn too much, handle this set from scratch.  */
    5536    199311604 :       if (repeat)
    5537              :         {
    5538            8 :           i--;
    5539            8 :           continue;
    5540              :         }
    5541              : 
    5542    199993680 :       src = SET_SRC (sets[i].rtl);
    5543              : 
    5544              :       /* In general, it is good to have a SET with SET_SRC == SET_DEST.
    5545              :          However, there is an important exception:  If both are registers
    5546              :          that are not the head of their equivalence class, replace SET_SRC
    5547              :          with the head of the class.  If we do not do this, we will have
    5548              :          both registers live over a portion of the basic block.  This way,
    5549              :          their lifetimes will likely abut instead of overlapping.  */
    5550    199993680 :       if (!is_fake_set
    5551    199311604 :           && REG_P (dest)
    5552    348420373 :           && REGNO_QTY_VALID_P (REGNO (dest)))
    5553              :         {
    5554      8415552 :           int dest_q = REG_QTY (REGNO (dest));
    5555      8415552 :           struct qty_table_elem *dest_ent = &qty_table[dest_q];
    5556              : 
    5557      8415552 :           if (dest_ent->mode == GET_MODE (dest)
    5558      6571002 :               && dest_ent->first_reg != REGNO (dest)
    5559       121602 :               && REG_P (src) && REGNO (src) == REGNO (dest)
    5560              :               /* Don't do this if the original insn had a hard reg as
    5561              :                  SET_SRC or SET_DEST.  */
    5562         4257 :               && (!REG_P (sets[i].src)
    5563         3181 :                   || REGNO (sets[i].src) >= FIRST_PSEUDO_REGISTER)
    5564      8419795 :               && (!REG_P (dest) || REGNO (dest) >= FIRST_PSEUDO_REGISTER))
    5565              :             /* We can't call canon_reg here because it won't do anything if
    5566              :                SRC is a hard register.  */
    5567              :             {
    5568         4243 :               int src_q = REG_QTY (REGNO (src));
    5569         4243 :               struct qty_table_elem *src_ent = &qty_table[src_q];
    5570         4243 :               int first = src_ent->first_reg;
    5571         4243 :               rtx new_src
    5572              :                 = (first >= FIRST_PSEUDO_REGISTER
    5573         4243 :                    ? regno_reg_rtx[first] : gen_rtx_REG (GET_MODE (src), first));
    5574              : 
    5575              :               /* We must use validate-change even for this, because this
    5576              :                  might be a special no-op instruction, suitable only to
    5577              :                  tag notes onto.  */
    5578         4243 :               if (validate_change (insn, &SET_SRC (sets[i].rtl), new_src, 0))
    5579              :                 {
    5580         4243 :                   src = new_src;
    5581              :                   /* If we had a constant that is cheaper than what we are now
    5582              :                      setting SRC to, use that constant.  We ignored it when we
    5583              :                      thought we could make this into a no-op.  */
    5584         1605 :                   if (src_const && COST (src_const, mode) < COST (src, mode)
    5585         4243 :                       && validate_change (insn, &SET_SRC (sets[i].rtl),
    5586              :                                           src_const, 0))
    5587              :                     src = src_const;
    5588              :                 }
    5589              :             }
    5590              :         }
    5591              : 
    5592              :       /* If we made a change, recompute SRC values.  */
    5593    199993680 :       if (src != sets[i].src)
    5594              :         {
    5595      3418767 :           do_not_record = 0;
    5596      3418767 :           hash_arg_in_memory = 0;
    5597      3418767 :           sets[i].src = src;
    5598      3418767 :           sets[i].src_hash = HASH (src, mode);
    5599      3418767 :           sets[i].src_volatile = do_not_record;
    5600      3418767 :           sets[i].src_in_memory = hash_arg_in_memory;
    5601      3418767 :           sets[i].src_elt = lookup (src, sets[i].src_hash, mode);
    5602              :         }
    5603              : 
    5604              :       /* If this is a single SET, we are setting a register, and we have an
    5605              :          equivalent constant, we want to add a REG_EQUAL note if the constant
    5606              :          is different from the source.  We don't want to do it for a constant
    5607              :          pseudo since verifying that this pseudo hasn't been eliminated is a
    5608              :          pain; moreover such a note won't help anything.
    5609              : 
    5610              :          Avoid a REG_EQUAL note for (CONST (MINUS (LABEL_REF) (LABEL_REF)))
    5611              :          which can be created for a reference to a compile time computable
    5612              :          entry in a jump table.  */
    5613    199993680 :       if (n_sets == 1
    5614    196701915 :           && REG_P (dest)
    5615    146128280 :           && src_const
    5616     30130672 :           && !REG_P (src_const)
    5617     30103900 :           && !(GET_CODE (src_const) == SUBREG
    5618            0 :                && REG_P (SUBREG_REG (src_const)))
    5619     30103900 :           && !(GET_CODE (src_const) == CONST
    5620       391475 :                && GET_CODE (XEXP (src_const, 0)) == MINUS
    5621            0 :                && GET_CODE (XEXP (XEXP (src_const, 0), 0)) == LABEL_REF
    5622            0 :                && GET_CODE (XEXP (XEXP (src_const, 0), 1)) == LABEL_REF)
    5623    230097580 :           && !rtx_equal_p (src, src_const))
    5624              :         {
    5625              :           /* Make sure that the rtx is not shared.  */
    5626      7918161 :           src_const = copy_rtx (src_const);
    5627              : 
    5628              :           /* Record the actual constant value in a REG_EQUAL note,
    5629              :              making a new one if one does not already exist.  */
    5630      7918161 :           set_unique_reg_note (insn, REG_EQUAL, src_const);
    5631      7918161 :           df_notes_rescan (insn);
    5632              :         }
    5633              : 
    5634              :       /* Now deal with the destination.  */
    5635    199993680 :       do_not_record = 0;
    5636              : 
    5637              :       /* Look within any ZERO_EXTRACT to the MEM or REG within it.  */
    5638    199993680 :       while (GET_CODE (dest) == SUBREG
    5639    200011654 :              || GET_CODE (dest) == ZERO_EXTRACT
    5640    401683169 :              || GET_CODE (dest) == STRICT_LOW_PART)
    5641      1681905 :         dest = XEXP (dest, 0);
    5642              : 
    5643    199993680 :       sets[i].inner_dest = dest;
    5644              : 
    5645    199993680 :       if (MEM_P (dest))
    5646              :         {
    5647              : #ifdef PUSH_ROUNDING
    5648              :           /* Stack pushes invalidate the stack pointer.  */
    5649     29418402 :           rtx addr = XEXP (dest, 0);
    5650     29418402 :           if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC
    5651      5565729 :               && XEXP (addr, 0) == stack_pointer_rtx)
    5652      5565729 :             invalidate (stack_pointer_rtx, VOIDmode);
    5653              : #endif
    5654     29418402 :           dest = fold_rtx (dest, insn);
    5655              :         }
    5656              : 
    5657              :       /* Compute the hash code of the destination now,
    5658              :          before the effects of this instruction are recorded,
    5659              :          since the register values used in the address computation
    5660              :          are those before this instruction.  */
    5661    199993680 :       sets[i].dest_hash = HASH (dest, mode);
    5662              : 
    5663              :       /* Don't enter a bit-field in the hash table
    5664              :          because the value in it after the store
    5665              :          may not equal what was stored, due to truncation.  */
    5666              : 
    5667    199993680 :       if (GET_CODE (SET_DEST (sets[i].rtl)) == ZERO_EXTRACT)
    5668              :         {
    5669         4070 :           rtx width = XEXP (SET_DEST (sets[i].rtl), 1);
    5670              : 
    5671         4070 :           if (src_const != 0 && CONST_INT_P (src_const)
    5672          729 :               && CONST_INT_P (width)
    5673          729 :               && INTVAL (width) < HOST_BITS_PER_WIDE_INT
    5674          729 :               && ! (INTVAL (src_const)
    5675          729 :                     & (HOST_WIDE_INT_M1U << INTVAL (width))))
    5676              :             /* Exception: if the value is constant,
    5677              :                and it won't be truncated, record it.  */
    5678              :             ;
    5679              :           else
    5680              :             {
    5681              :               /* This is chosen so that the destination will be invalidated
    5682              :                  but no new value will be recorded.
    5683              :                  We must invalidate because sometimes constant
    5684              :                  values can be recorded for bitfields.  */
    5685         3342 :               sets[i].src_elt = 0;
    5686         3342 :               sets[i].src_volatile = 1;
    5687         3342 :               src_eqv = 0;
    5688         3342 :               src_eqv_elt = 0;
    5689              :             }
    5690              :         }
    5691              : 
    5692              :       /* If only one set in a JUMP_INSN and it is now a no-op, we can delete
    5693              :          the insn.  */
    5694    199989610 :       else if (n_sets == 1 && dest == pc_rtx && src == pc_rtx)
    5695              :         {
    5696              :           /* One less use of the label this insn used to jump to.  */
    5697        12413 :           cse_cfg_altered |= delete_insn_and_edges (insn);
    5698        12413 :           cse_jumps_altered = true;
    5699              :           /* No more processing for this set.  */
    5700        12413 :           sets[i].rtl = 0;
    5701              :         }
    5702              : 
    5703              :       /* Similarly for no-op moves.  */
    5704    199977197 :       else if (noop_insn)
    5705              :         {
    5706       193606 :           if (cfun->can_throw_non_call_exceptions && can_throw_internal (insn))
    5707            0 :             cse_cfg_altered = true;
    5708       193606 :           cse_cfg_altered |= delete_insn_and_edges (insn);
    5709              :           /* No more processing for this set.  */
    5710       193606 :           sets[i].rtl = 0;
    5711              :         }
    5712              : 
    5713              :       /* If this SET is now setting PC to a label, we know it used to
    5714              :          be a conditional or computed branch.  */
    5715     20470021 :       else if (dest == pc_rtx && GET_CODE (src) == LABEL_REF
    5716    199793235 :                && !LABEL_REF_NONLOCAL_P (src))
    5717              :         {
    5718              :           /* We reemit the jump in as many cases as possible just in
    5719              :              case the form of an unconditional jump is significantly
    5720              :              different than a computed jump or conditional jump.
    5721              : 
    5722              :              If this insn has multiple sets, then reemitting the
    5723              :              jump is nontrivial.  So instead we just force rerecognition
    5724              :              and hope for the best.  */
    5725         9644 :           if (n_sets == 1)
    5726              :             {
    5727         9644 :               rtx_jump_insn *new_rtx;
    5728         9644 :               rtx note;
    5729              : 
    5730         9644 :               rtx_insn *seq = targetm.gen_jump (XEXP (src, 0));
    5731         9644 :               new_rtx = emit_jump_insn_before (seq, insn);
    5732         9644 :               JUMP_LABEL (new_rtx) = XEXP (src, 0);
    5733         9644 :               LABEL_NUSES (label_ref_label (src))++;
    5734              : 
    5735              :               /* Make sure to copy over REG_NON_LOCAL_GOTO.  */
    5736         9644 :               note = find_reg_note (insn, REG_NON_LOCAL_GOTO, 0);
    5737         9644 :               if (note)
    5738              :                 {
    5739            0 :                   XEXP (note, 1) = NULL_RTX;
    5740            0 :                   REG_NOTES (new_rtx) = note;
    5741              :                 }
    5742              : 
    5743         9644 :               cse_cfg_altered |= delete_insn_and_edges (insn);
    5744         9644 :               insn = new_rtx;
    5745              :             }
    5746              :           else
    5747            0 :             INSN_CODE (insn) = -1;
    5748              : 
    5749              :           /* Do not bother deleting any unreachable code, let jump do it.  */
    5750         9644 :           cse_jumps_altered = true;
    5751         9644 :           sets[i].rtl = 0;
    5752              :         }
    5753              : 
    5754              :       /* If destination is volatile, invalidate it and then do no further
    5755              :          processing for this assignment.  */
    5756              : 
    5757    199773947 :       else if (do_not_record)
    5758              :         {
    5759     56637476 :           invalidate_dest (dest);
    5760     56637476 :           sets[i].rtl = 0;
    5761              :         }
    5762              : 
    5763    199993680 :       if (sets[i].rtl != 0 && dest != SET_DEST (sets[i].rtl))
    5764              :         {
    5765      1751853 :           do_not_record = 0;
    5766      1751853 :           sets[i].dest_hash = HASH (SET_DEST (sets[i].rtl), mode);
    5767      1751853 :           if (do_not_record)
    5768              :             {
    5769          994 :               invalidate_dest (SET_DEST (sets[i].rtl));
    5770          994 :               sets[i].rtl = 0;
    5771              :             }
    5772              :         }
    5773              :     }
    5774              : 
    5775              :   /* Now enter all non-volatile source expressions in the hash table
    5776              :      if they are not already present.
    5777              :      Record their equivalence classes in src_elt.
    5778              :      This way we can insert the corresponding destinations into
    5779              :      the same classes even if the actual sources are no longer in them
    5780              :      (having been invalidated).  */
    5781              : 
    5782      5517624 :   if (src_eqv && src_eqv_elt == 0 && sets[0].rtl != 0 && ! src_eqv_volatile
    5783    415448080 :       && ! rtx_equal_p (src_eqv, SET_DEST (sets[0].rtl)))
    5784              :     {
    5785      4524597 :       struct table_elt *elt;
    5786      4524597 :       struct table_elt *classp = sets[0].src_elt;
    5787      4524597 :       rtx dest = SET_DEST (sets[0].rtl);
    5788      4524597 :       machine_mode eqvmode = GET_MODE (dest);
    5789              : 
    5790      4524597 :       if (GET_CODE (dest) == STRICT_LOW_PART)
    5791              :         {
    5792            0 :           eqvmode = GET_MODE (SUBREG_REG (XEXP (dest, 0)));
    5793            0 :           classp = 0;
    5794              :         }
    5795      4524597 :       if (insert_regs (src_eqv, classp, false))
    5796              :         {
    5797       156041 :           rehash_using_reg (src_eqv);
    5798       156041 :           src_eqv_hash = HASH (src_eqv, eqvmode);
    5799              :         }
    5800      4524597 :       elt = insert (src_eqv, classp, src_eqv_hash, eqvmode);
    5801      4524597 :       elt->in_memory = src_eqv_in_memory;
    5802      4524597 :       src_eqv_elt = elt;
    5803              : 
    5804              :       /* Check to see if src_eqv_elt is the same as a set source which
    5805              :          does not yet have an elt, and if so set the elt of the set source
    5806              :          to src_eqv_elt.  */
    5807      9049194 :       for (i = 0; i < n_sets; i++)
    5808      9049194 :         if (sets[i].rtl && sets[i].src_elt == 0
    5809      8916842 :             && rtx_equal_p (SET_SRC (sets[i].rtl), src_eqv))
    5810        99278 :           sets[i].src_elt = src_eqv_elt;
    5811              :     }
    5812              : 
    5813    610917163 :   for (i = 0; i < n_sets; i++)
    5814    343133227 :     if (sets[i].rtl && ! sets[i].src_volatile
    5815    329318026 :         && ! rtx_equal_p (SET_SRC (sets[i].rtl), SET_DEST (sets[i].rtl)))
    5816              :       {
    5817    129319313 :         if (GET_CODE (SET_DEST (sets[i].rtl)) == STRICT_LOW_PART)
    5818              :           {
    5819              :             /* REG_EQUAL in setting a STRICT_LOW_PART
    5820              :                gives an equivalent for the entire destination register,
    5821              :                not just for the subreg being stored in now.
    5822              :                This is a more interesting equivalence, so we arrange later
    5823              :                to treat the entire reg as the destination.  */
    5824        13904 :             sets[i].src_elt = src_eqv_elt;
    5825        13904 :             sets[i].src_hash = src_eqv_hash;
    5826              :           }
    5827              :         else
    5828              :           {
    5829              :             /* Insert source and constant equivalent into hash table, if not
    5830              :                already present.  */
    5831    129305409 :             struct table_elt *classp = src_eqv_elt;
    5832    129305409 :             rtx src = sets[i].src;
    5833    129305409 :             rtx dest = SET_DEST (sets[i].rtl);
    5834    270127420 :             machine_mode mode
    5835    129305409 :               = GET_MODE (src) == VOIDmode ? GET_MODE (dest) : GET_MODE (src);
    5836              : 
    5837              :             /* It's possible that we have a source value known to be
    5838              :                constant but don't have a REG_EQUAL note on the insn.
    5839              :                Lack of a note will mean src_eqv_elt will be NULL.  This
    5840              :                can happen where we've generated a SUBREG to access a
    5841              :                CONST_INT that is already in a register in a wider mode.
    5842              :                Ensure that the source expression is put in the proper
    5843              :                constant class.  */
    5844    129305409 :             if (!classp)
    5845    123820337 :               classp = sets[i].src_const_elt;
    5846              : 
    5847    129305409 :             if (sets[i].src_elt == 0)
    5848              :               {
    5849    106738588 :                 struct table_elt *elt;
    5850              : 
    5851              :                 /* Note that these insert_regs calls cannot remove
    5852              :                    any of the src_elt's, because they would have failed to
    5853              :                    match if not still valid.  */
    5854    106738588 :                 if (insert_regs (src, classp, false))
    5855              :                   {
    5856     17748135 :                     rehash_using_reg (src);
    5857     17748135 :                     sets[i].src_hash = HASH (src, mode);
    5858              :                   }
    5859    106738588 :                 elt = insert (src, classp, sets[i].src_hash, mode);
    5860    106738588 :                 elt->in_memory = sets[i].src_in_memory;
    5861              :                 /* If inline asm has any clobbers, ensure we only reuse
    5862              :                    existing inline asms and never try to put the ASM_OPERANDS
    5863              :                    into an insn that isn't inline asm.  */
    5864    106738588 :                 if (GET_CODE (src) == ASM_OPERANDS
    5865        20722 :                     && GET_CODE (x) == PARALLEL)
    5866        20704 :                   elt->cost = MAX_COST;
    5867    106738588 :                 sets[i].src_elt = classp = elt;
    5868              :               }
    5869    154765851 :             if (sets[i].src_const && sets[i].src_const_elt == 0
    5870     15102243 :                 && src != sets[i].src_const
    5871    131561870 :                 && ! rtx_equal_p (sets[i].src_const, src))
    5872      2256461 :               sets[i].src_elt = insert (sets[i].src_const, classp,
    5873      2256461 :                                         sets[i].src_const_hash, mode);
    5874              :           }
    5875              :       }
    5876     70674367 :     else if (sets[i].src_elt == 0)
    5877              :       /* If we did not insert the source into the hash table (e.g., it was
    5878              :          volatile), note the equivalence class for the REG_EQUAL value, if any,
    5879              :          so that the destination goes into that class.  */
    5880     57947641 :       sets[i].src_elt = src_eqv_elt;
    5881              : 
    5882              :   /* Record destination addresses in the hash table.  This allows us to
    5883              :      check if they are invalidated by other sets.  */
    5884    610917163 :   for (i = 0; i < n_sets; i++)
    5885              :     {
    5886    199993680 :       if (sets[i].rtl)
    5887              :         {
    5888    143139547 :           rtx x = sets[i].inner_dest;
    5889    143139547 :           struct table_elt *elt;
    5890    143139547 :           machine_mode mode;
    5891    143139547 :           unsigned hash;
    5892              : 
    5893    143139547 :           if (MEM_P (x))
    5894              :             {
    5895     22591911 :               x = XEXP (x, 0);
    5896     22591911 :               mode = GET_MODE (x);
    5897     22591911 :               hash = HASH (x, mode);
    5898     22591911 :               elt = lookup (x, hash, mode);
    5899     22591911 :               if (!elt)
    5900              :                 {
    5901     19698632 :                   if (insert_regs (x, NULL, false))
    5902              :                     {
    5903      2257584 :                       rtx dest = SET_DEST (sets[i].rtl);
    5904              : 
    5905      2257584 :                       rehash_using_reg (x);
    5906      2257584 :                       hash = HASH (x, mode);
    5907      2257584 :                       sets[i].dest_hash = HASH (dest, GET_MODE (dest));
    5908              :                     }
    5909     19698632 :                   elt = insert (x, NULL, hash, mode);
    5910              :                 }
    5911              : 
    5912     22591911 :               sets[i].dest_addr_elt = elt;
    5913              :             }
    5914              :           else
    5915    120547636 :             sets[i].dest_addr_elt = NULL;
    5916              :         }
    5917              :     }
    5918              : 
    5919    410923483 :   invalidate_from_clobbers (insn);
    5920              : 
    5921              :   /* Some registers are invalidated by subroutine calls.  Memory is
    5922              :      invalidated by non-constant calls.  */
    5923              : 
    5924    410923483 :   if (auto call = dyn_cast<rtx_call_insn *> (insn))
    5925              :     {
    5926     15887571 :       if (!(RTL_CONST_OR_PURE_CALL_P (call)))
    5927     13749374 :         invalidate_memory ();
    5928              :       else
    5929              :         /* For const/pure calls, invalidate any argument slots, because
    5930              :            those are owned by the callee.  */
    5931      6354059 :         for (tem = CALL_INSN_FUNCTION_USAGE (call); tem; tem = XEXP (tem, 1))
    5932      4215862 :           if (GET_CODE (XEXP (tem, 0)) == USE
    5933      4215861 :               && MEM_P (XEXP (XEXP (tem, 0), 0)))
    5934        71597 :             invalidate (XEXP (XEXP (tem, 0), 0), VOIDmode);
    5935     15887571 :       invalidate_for_call (call);
    5936              :     }
    5937              : 
    5938              :   /* Now invalidate everything set by this instruction.
    5939              :      If a SUBREG or other funny destination is being set,
    5940              :      sets[i].rtl is still nonzero, so here we invalidate the reg
    5941              :      a part of which is being set.  */
    5942              : 
    5943    610917163 :   for (i = 0; i < n_sets; i++)
    5944    199993680 :     if (sets[i].rtl)
    5945              :       {
    5946              :         /* We can't use the inner dest, because the mode associated with
    5947              :            a ZERO_EXTRACT is significant.  */
    5948    143139547 :         rtx dest = SET_DEST (sets[i].rtl);
    5949              : 
    5950              :         /* Needed for registers to remove the register from its
    5951              :            previous quantity's chain.
    5952              :            Needed for memory if this is a nonvarying address, unless
    5953              :            we have just done an invalidate_memory that covers even those.  */
    5954    143139547 :         if (REG_P (dest) || GET_CODE (dest) == SUBREG)
    5955    120530516 :           invalidate (dest, VOIDmode);
    5956     22609031 :         else if (MEM_P (dest))
    5957     22591911 :           invalidate (dest, VOIDmode);
    5958        17120 :         else if (GET_CODE (dest) == STRICT_LOW_PART
    5959         3216 :                  || GET_CODE (dest) == ZERO_EXTRACT)
    5960        16998 :           invalidate (XEXP (dest, 0), GET_MODE (dest));
    5961              :       }
    5962              : 
    5963              :   /* Don't cse over a call to setjmp; on some machines (eg VAX)
    5964              :      the regs restored by the longjmp come from a later time
    5965              :      than the setjmp.  */
    5966    410923483 :   if (CALL_P (insn) && find_reg_note (insn, REG_SETJMP, NULL))
    5967              :     {
    5968         2292 :       flush_hash_table ();
    5969         2292 :       goto done;
    5970              :     }
    5971              : 
    5972              :   /* Make sure registers mentioned in destinations
    5973              :      are safe for use in an expression to be inserted.
    5974              :      This removes from the hash table
    5975              :      any invalid entry that refers to one of these registers.
    5976              : 
    5977              :      We don't care about the return value from mention_regs because
    5978              :      we are going to hash the SET_DEST values unconditionally.  */
    5979              : 
    5980    610914871 :   for (i = 0; i < n_sets; i++)
    5981              :     {
    5982    199993680 :       if (sets[i].rtl)
    5983              :         {
    5984    143139547 :           rtx x = SET_DEST (sets[i].rtl);
    5985              : 
    5986    143139547 :           if (!REG_P (x))
    5987     24257494 :             mention_regs (x);
    5988              :           else
    5989              :             {
    5990              :               /* We used to rely on all references to a register becoming
    5991              :                  inaccessible when a register changes to a new quantity,
    5992              :                  since that changes the hash code.  However, that is not
    5993              :                  safe, since after HASH_SIZE new quantities we get a
    5994              :                  hash 'collision' of a register with its own invalid
    5995              :                  entries.  And since SUBREGs have been changed not to
    5996              :                  change their hash code with the hash code of the register,
    5997              :                  it wouldn't work any longer at all.  So we have to check
    5998              :                  for any invalid references lying around now.
    5999              :                  This code is similar to the REG case in mention_regs,
    6000              :                  but it knows that reg_tick has been incremented, and
    6001              :                  it leaves reg_in_table as -1 .  */
    6002    118882053 :               unsigned int regno = REGNO (x);
    6003    118882053 :               unsigned int endregno = END_REGNO (x);
    6004    118882053 :               unsigned int i;
    6005              : 
    6006    237764106 :               for (i = regno; i < endregno; i++)
    6007              :                 {
    6008    118882053 :                   if (REG_IN_TABLE (i) >= 0)
    6009              :                     {
    6010     13124043 :                       remove_invalid_refs (i);
    6011     13124043 :                       REG_IN_TABLE (i) = -1;
    6012              :                     }
    6013              :                 }
    6014              :             }
    6015              :         }
    6016              :     }
    6017              : 
    6018              :   /* We may have just removed some of the src_elt's from the hash table.
    6019              :      So replace each one with the current head of the same class.
    6020              :      Also check if destination addresses have been removed.  */
    6021              : 
    6022    610914871 :   for (i = 0; i < n_sets; i++)
    6023    199993680 :     if (sets[i].rtl)
    6024              :       {
    6025    143139547 :         if (sets[i].dest_addr_elt
    6026    143139547 :             && sets[i].dest_addr_elt->first_same_value == 0)
    6027              :           {
    6028              :             /* The elt was removed, which means this destination is not
    6029              :                valid after this instruction.  */
    6030            0 :             sets[i].rtl = NULL_RTX;
    6031              :           }
    6032    143139547 :         else if (sets[i].src_elt && sets[i].src_elt->first_same_value == 0)
    6033              :           /* If elt was removed, find current head of same class,
    6034              :              or 0 if nothing remains of that class.  */
    6035              :           {
    6036     10957839 :             struct table_elt *elt = sets[i].src_elt;
    6037              : 
    6038     10957839 :             while (elt && elt->prev_same_value)
    6039              :               elt = elt->prev_same_value;
    6040              : 
    6041     21844218 :             while (elt && elt->first_same_value == 0)
    6042     10922481 :               elt = elt->next_same_value;
    6043     10921737 :             sets[i].src_elt = elt ? elt->first_same_value : 0;
    6044              :           }
    6045              :       }
    6046              : 
    6047              :   /* Now insert the destinations into their equivalence classes.  */
    6048              : 
    6049    610914871 :   for (i = 0; i < n_sets; i++)
    6050    199993680 :     if (sets[i].rtl)
    6051              :       {
    6052    143139547 :         rtx dest = SET_DEST (sets[i].rtl);
    6053    143139547 :         struct table_elt *elt;
    6054              : 
    6055              :         /* Don't record value if we are not supposed to risk allocating
    6056              :            floating-point values in registers that might be wider than
    6057              :            memory.  */
    6058    167831290 :         if ((flag_float_store
    6059        12898 :              && MEM_P (dest)
    6060         4396 :              && FLOAT_MODE_P (GET_MODE (dest)))
    6061              :             /* Don't record BLKmode values, because we don't know the
    6062              :                size of it, and can't be sure that other BLKmode values
    6063              :                have the same or smaller size.  */
    6064    143136851 :             || GET_MODE (dest) == BLKmode
    6065              :             /* If we didn't put a REG_EQUAL value or a source into the hash
    6066              :                table, there is no point is recording DEST.  */
    6067    286276398 :             || sets[i].src_elt == 0)
    6068     24691743 :           continue;
    6069              : 
    6070              :         /* STRICT_LOW_PART isn't part of the value BEING set,
    6071              :            and neither is the SUBREG inside it.
    6072              :            Note that in this case SETS[I].SRC_ELT is really SRC_EQV_ELT.  */
    6073    118447804 :         if (GET_CODE (dest) == STRICT_LOW_PART)
    6074            0 :           dest = SUBREG_REG (XEXP (dest, 0));
    6075              : 
    6076    118447804 :         if (REG_P (dest) || GET_CODE (dest) == SUBREG)
    6077              :           /* Registers must also be inserted into chains for quantities.  */
    6078     96228757 :           if (insert_regs (dest, sets[i].src_elt, true))
    6079              :             {
    6080              :               /* If `insert_regs' changes something, the hash code must be
    6081              :                  recalculated.  */
    6082     95626525 :               rehash_using_reg (dest);
    6083     95626525 :               sets[i].dest_hash = HASH (dest, GET_MODE (dest));
    6084              :             }
    6085              : 
    6086              :         /* If DEST is a paradoxical SUBREG, don't record DEST since the bits
    6087              :            outside the mode of GET_MODE (SUBREG_REG (dest)) are undefined.  */
    6088    118447804 :         if (paradoxical_subreg_p (dest))
    6089        66095 :           continue;
    6090              : 
    6091    355145127 :         elt = insert (dest, sets[i].src_elt,
    6092    118381709 :                       sets[i].dest_hash, GET_MODE (dest));
    6093              : 
    6094              :         /* If this is a constant, insert the constant anchors with the
    6095              :            equivalent register-offset expressions using register DEST.  */
    6096    118381709 :         if (targetm.const_anchor
    6097            0 :             && REG_P (dest)
    6098            0 :             && SCALAR_INT_MODE_P (GET_MODE (dest))
    6099    118381709 :             && GET_CODE (sets[i].src_elt->exp) == CONST_INT)
    6100            0 :           insert_const_anchors (dest, sets[i].src_elt->exp, GET_MODE (dest));
    6101              : 
    6102    118381709 :         elt->in_memory = (MEM_P (sets[i].inner_dest)
    6103    118381709 :                           && !MEM_READONLY_P (sets[i].inner_dest));
    6104              : 
    6105              :         /* If we have (set (subreg:m1 (reg:m2 foo) 0) (bar:m1)), M1 is no
    6106              :            narrower than M2, and both M1 and M2 are the same number of words,
    6107              :            we are also doing (set (reg:m2 foo) (subreg:m2 (bar:m1) 0)) so
    6108              :            make that equivalence as well.
    6109              : 
    6110              :            However, BAR may have equivalences for which gen_lowpart
    6111              :            will produce a simpler value than gen_lowpart applied to
    6112              :            BAR (e.g., if BAR was ZERO_EXTENDed from M2), so we will scan all
    6113              :            BAR's equivalences.  If we don't get a simplified form, make
    6114              :            the SUBREG.  It will not be used in an equivalence, but will
    6115              :            cause two similar assignments to be detected.
    6116              : 
    6117              :            Note the loop below will find SUBREG_REG (DEST) since we have
    6118              :            already entered SRC and DEST of the SET in the table.  */
    6119              : 
    6120    118381709 :         if (GET_CODE (dest) == SUBREG
    6121              :             && (known_equal_after_align_down
    6122    201547546 :                 (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) - 1,
    6123      3022220 :                  GET_MODE_SIZE (GET_MODE (dest)) - 1,
    6124      1511110 :                  UNITS_PER_WORD))
    6125        95023 :             && !partial_subreg_p (dest)
    6126    118424465 :             && sets[i].src_elt != 0)
    6127              :           {
    6128        42756 :             machine_mode new_mode = GET_MODE (SUBREG_REG (dest));
    6129        42756 :             struct table_elt *elt, *classp = 0;
    6130              : 
    6131       472062 :             for (elt = sets[i].src_elt->first_same_value; elt;
    6132       429306 :                  elt = elt->next_same_value)
    6133              :               {
    6134       429306 :                 rtx new_src = 0;
    6135       429306 :                 unsigned src_hash;
    6136       429306 :                 struct table_elt *src_elt;
    6137              : 
    6138              :                 /* Ignore invalid entries.  */
    6139       429306 :                 if (!REG_P (elt->exp)
    6140       429306 :                     && ! exp_equiv_p (elt->exp, elt->exp, 1, false))
    6141            0 :                   continue;
    6142              : 
    6143              :                 /* We may have already been playing subreg games.  If the
    6144              :                    mode is already correct for the destination, use it.  */
    6145       429306 :                 if (GET_MODE (elt->exp) == new_mode)
    6146              :                   new_src = elt->exp;
    6147              :                 else
    6148              :                   {
    6149       429306 :                     poly_uint64 byte
    6150       429306 :                       = subreg_lowpart_offset (new_mode, GET_MODE (dest));
    6151       429306 :                     new_src = simplify_gen_subreg (new_mode, elt->exp,
    6152       429306 :                                                    GET_MODE (dest), byte);
    6153              :                   }
    6154              : 
    6155              :                 /* The call to simplify_gen_subreg fails if the value
    6156              :                    is VOIDmode, yet we can't do any simplification, e.g.
    6157              :                    for EXPR_LISTs denoting function call results.
    6158              :                    It is invalid to construct a SUBREG with a VOIDmode
    6159              :                    SUBREG_REG, hence a zero new_src means we can't do
    6160              :                    this substitution.  */
    6161       429306 :                 if (! new_src)
    6162            6 :                   continue;
    6163              : 
    6164       429300 :                 src_hash = HASH (new_src, new_mode);
    6165       429300 :                 src_elt = lookup (new_src, src_hash, new_mode);
    6166              : 
    6167              :                 /* Put the new source in the hash table is if isn't
    6168              :                    already.  */
    6169       429300 :                 if (src_elt == 0)
    6170              :                   {
    6171        55177 :                     if (insert_regs (new_src, classp, false))
    6172              :                       {
    6173            0 :                         rehash_using_reg (new_src);
    6174            0 :                         src_hash = HASH (new_src, new_mode);
    6175              :                       }
    6176        55177 :                     src_elt = insert (new_src, classp, src_hash, new_mode);
    6177        55177 :                     src_elt->in_memory = elt->in_memory;
    6178        55177 :                     if (GET_CODE (new_src) == ASM_OPERANDS
    6179            0 :                         && elt->cost == MAX_COST)
    6180            0 :                       src_elt->cost = MAX_COST;
    6181              :                   }
    6182       374123 :                 else if (classp && classp != src_elt->first_same_value)
    6183              :                   /* Show that two things that we've seen before are
    6184              :                      actually the same.  */
    6185          161 :                   merge_equiv_classes (src_elt, classp);
    6186              : 
    6187       429300 :                 classp = src_elt->first_same_value;
    6188              :                 /* Ignore invalid entries.  */
    6189       429300 :                 while (classp
    6190       429300 :                        && !REG_P (classp->exp)
    6191       807550 :                        && ! exp_equiv_p (classp->exp, classp->exp, 1, false))
    6192            0 :                   classp = classp->next_same_value;
    6193              :               }
    6194              :           }
    6195              :       }
    6196              : 
    6197              :   /* Special handling for (set REG0 REG1) where REG0 is the
    6198              :      "cheapest", cheaper than REG1.  After cse, REG1 will probably not
    6199              :      be used in the sequel, so (if easily done) change this insn to
    6200              :      (set REG1 REG0) and replace REG1 with REG0 in the previous insn
    6201              :      that computed their value.  Then REG1 will become a dead store
    6202              :      and won't cloud the situation for later optimizations.
    6203              : 
    6204              :      Do not make this change if REG1 is a hard register, because it will
    6205              :      then be used in the sequel and we may be changing a two-operand insn
    6206              :      into a three-operand insn.
    6207              : 
    6208              :      Also do not do this if we are operating on a copy of INSN.  */
    6209              : 
    6210    607623106 :   if (n_sets == 1 && sets[0].rtl)
    6211    140078598 :     try_back_substitute_reg (sets[0].rtl, insn);
    6212              : 
    6213    410923483 : done:;
    6214    410923483 : }
    6215              : 
    6216              : /* Remove from the hash table all expressions that reference memory.  */
    6217              : 
    6218              : static void
    6219     13749374 : invalidate_memory (void)
    6220              : {
    6221     13749374 :   int i;
    6222     13749374 :   struct table_elt *p, *next;
    6223              : 
    6224    453729342 :   for (i = 0; i < HASH_SIZE; i++)
    6225    634903447 :     for (p = table[i]; p; p = next)
    6226              :       {
    6227    194923479 :         next = p->next_same_hash;
    6228    194923479 :         if (p->in_memory)
    6229     19965044 :           remove_from_table (p, i);
    6230              :       }
    6231     13749374 : }
    6232              : 
    6233              : /* Perform invalidation on the basis of everything about INSN,
    6234              :    except for invalidating the actual places that are SET in it.
    6235              :    This includes the places CLOBBERed, and anything that might
    6236              :    alias with something that is SET or CLOBBERed.  */
    6237              : 
    6238              : static void
    6239    410923483 : invalidate_from_clobbers (rtx_insn *insn)
    6240              : {
    6241    410923483 :   rtx x = PATTERN (insn);
    6242              : 
    6243    410923483 :   if (GET_CODE (x) == CLOBBER)
    6244              :     {
    6245        69808 :       rtx ref = XEXP (x, 0);
    6246        69808 :       if (ref)
    6247              :         {
    6248        69808 :           if (REG_P (ref) || GET_CODE (ref) == SUBREG
    6249        13208 :               || MEM_P (ref))
    6250        69808 :             invalidate (ref, VOIDmode);
    6251            0 :           else if (GET_CODE (ref) == STRICT_LOW_PART
    6252            0 :                    || GET_CODE (ref) == ZERO_EXTRACT)
    6253            0 :             invalidate (XEXP (ref, 0), GET_MODE (ref));
    6254              :         }
    6255              :     }
    6256    410853675 :   else if (GET_CODE (x) == PARALLEL)
    6257              :     {
    6258     31266514 :       int i;
    6259     95230787 :       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
    6260              :         {
    6261     63964273 :           rtx y = XVECEXP (x, 0, i);
    6262     63964273 :           if (GET_CODE (y) == CLOBBER)
    6263              :             {
    6264     30854332 :               rtx ref = XEXP (y, 0);
    6265     30854332 :               if (REG_P (ref) || GET_CODE (ref) == SUBREG
    6266       263019 :                   || MEM_P (ref))
    6267     30655285 :                 invalidate (ref, VOIDmode);
    6268       199047 :               else if (GET_CODE (ref) == STRICT_LOW_PART
    6269       199047 :                        || GET_CODE (ref) == ZERO_EXTRACT)
    6270            0 :                 invalidate (XEXP (ref, 0), GET_MODE (ref));
    6271              :             }
    6272              :         }
    6273              :     }
    6274    410923483 : }
    6275              : 
    6276              : /* Perform invalidation on the basis of everything about INSN.
    6277              :    This includes the places CLOBBERed, and anything that might
    6278              :    alias with something that is SET or CLOBBERed.  */
    6279              : 
    6280              : static void
    6281    410923483 : invalidate_from_sets_and_clobbers (rtx_insn *insn)
    6282              : {
    6283    410923483 :   rtx tem;
    6284    410923483 :   rtx x = PATTERN (insn);
    6285              : 
    6286    410923483 :   if (CALL_P (insn))
    6287              :     {
    6288     47077946 :       for (tem = CALL_INSN_FUNCTION_USAGE (insn); tem; tem = XEXP (tem, 1))
    6289              :         {
    6290     31190375 :           rtx temx = XEXP (tem, 0);
    6291     31190375 :           if (GET_CODE (temx) == CLOBBER)
    6292            0 :             invalidate (SET_DEST (temx), VOIDmode);
    6293              :         }
    6294              :     }
    6295              : 
    6296              :   /* Ensure we invalidate the destination register of a CALL insn.
    6297              :      This is necessary for machines where this register is a fixed_reg,
    6298              :      because no other code would invalidate it.  */
    6299    410923483 :   if (GET_CODE (x) == SET && GET_CODE (SET_SRC (x)) == CALL)
    6300      7328286 :     invalidate (SET_DEST (x), VOIDmode);
    6301              : 
    6302    403595197 :   else if (GET_CODE (x) == PARALLEL)
    6303              :     {
    6304     31984178 :       int i;
    6305              : 
    6306     97388853 :       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
    6307              :         {
    6308     65404675 :           rtx y = XVECEXP (x, 0, i);
    6309     65404675 :           if (GET_CODE (y) == CLOBBER)
    6310              :             {
    6311     31577070 :               rtx clobbered = XEXP (y, 0);
    6312              : 
    6313     31577070 :               if (REG_P (clobbered)
    6314       268089 :                   || GET_CODE (clobbered) == SUBREG)
    6315     31308981 :                 invalidate (clobbered, VOIDmode);
    6316       268089 :               else if (GET_CODE (clobbered) == STRICT_LOW_PART
    6317       268089 :                        || GET_CODE (clobbered) == ZERO_EXTRACT)
    6318            0 :                 invalidate (XEXP (clobbered, 0), GET_MODE (clobbered));
    6319              :             }
    6320     33827605 :           else if (GET_CODE (y) == SET && GET_CODE (SET_SRC (y)) == CALL)
    6321        10165 :             invalidate (SET_DEST (y), VOIDmode);
    6322              :         }
    6323              :     }
    6324              : 
    6325              :   /* Any single register constraint may introduce a conflict, if the associated
    6326              :      hard register is live.  For example:
    6327              : 
    6328              :      r100=%1
    6329              :      r101=42
    6330              :      r102=exp(r101)
    6331              : 
    6332              :      If the first operand r101 of exp is constrained to hard register %1, then
    6333              :      r100 cannot be trivially substituted by %1 in the following since %1 got
    6334              :      clobbered.  Such conflicts may stem from single register classes as well
    6335              :      as hard register constraints.  Since prior RA we do not know which
    6336              :      alternative will be chosen, be conservative and consider any such hard
    6337              :      register from any alternative as a potential clobber.  */
    6338    410923483 :   extract_insn (insn);
    6339    886332562 :   for (int nop = recog_data.n_operands - 1; nop >= 0; --nop)
    6340              :     {
    6341    475409079 :       int c;
    6342    475409079 :       const char *p = recog_data.constraints[nop];
    6343  15884628292 :       for (; (c = *p); p += CONSTRAINT_LEN (c, p))
    6344  15409219213 :         if (c == ',')
    6345              :           ;
    6346  10070283406 :         else if (c == '{')
    6347              :           {
    6348          190 :             int regno = decode_hard_reg_constraint (p);
    6349          190 :             machine_mode mode = recog_data.operand_mode[nop];
    6350          190 :             invalidate_reg (gen_rtx_REG (mode, regno));
    6351              :           }
    6352              :     }
    6353    410923483 : }
    6354              : 
    6355              : static rtx cse_process_note (rtx);
    6356              : 
    6357              : /* A simplify_replace_fn_rtx callback for cse_process_note.  Process X,
    6358              :    part of the REG_NOTES of an insn.  Replace any registers with either
    6359              :    an equivalent constant or the canonical form of the register.
    6360              :    Only replace addresses if the containing MEM remains valid.
    6361              : 
    6362              :    Return the replacement for X, or null if it should be simplified
    6363              :    recursively.  */
    6364              : 
    6365              : static rtx
    6366     29976090 : cse_process_note_1 (rtx x, const_rtx, void *)
    6367              : {
    6368     29976090 :   if (MEM_P (x))
    6369              :     {
    6370      2072080 :       validate_change (x, &XEXP (x, 0), cse_process_note (XEXP (x, 0)), false);
    6371      1036040 :       return x;
    6372              :     }
    6373              : 
    6374     28940050 :   if (REG_P (x))
    6375              :     {
    6376      6309666 :       int i = REG_QTY (REGNO (x));
    6377              : 
    6378              :       /* Return a constant or a constant register.  */
    6379      6309666 :       if (REGNO_QTY_VALID_P (REGNO (x)))
    6380              :         {
    6381      1685302 :           struct qty_table_elem *ent = &qty_table[i];
    6382              : 
    6383      1685302 :           if (ent->const_rtx != NULL_RTX
    6384        21591 :               && (CONSTANT_P (ent->const_rtx)
    6385        15818 :                   || REG_P (ent->const_rtx)))
    6386              :             {
    6387         5773 :               rtx new_rtx = gen_lowpart (GET_MODE (x), ent->const_rtx);
    6388         5773 :               if (new_rtx)
    6389         5773 :                 return copy_rtx (new_rtx);
    6390              :             }
    6391              :         }
    6392              : 
    6393              :       /* Otherwise, canonicalize this register.  */
    6394      6303893 :       return canon_reg (x, NULL);
    6395              :     }
    6396              : 
    6397              :   return NULL_RTX;
    6398              : }
    6399              : 
    6400              : /* Process X, part of the REG_NOTES of an insn.  Replace any registers in it
    6401              :    with either an equivalent constant or the canonical form of the register.
    6402              :    Only replace addresses if the containing MEM remains valid.  */
    6403              : 
    6404              : static rtx
    6405     10163908 : cse_process_note (rtx x)
    6406              : {
    6407      1036040 :   return simplify_replace_fn_rtx (x, NULL_RTX, cse_process_note_1, NULL);
    6408              : }
    6409              : 
    6410              : 
    6411              : /* Find a path in the CFG, starting with FIRST_BB to perform CSE on.
    6412              : 
    6413              :    DATA is a pointer to a struct cse_basic_block_data, that is used to
    6414              :    describe the path.
    6415              :    It is filled with a queue of basic blocks, starting with FIRST_BB
    6416              :    and following a trace through the CFG.
    6417              : 
    6418              :    If all paths starting at FIRST_BB have been followed, or no new path
    6419              :    starting at FIRST_BB can be constructed, this function returns FALSE.
    6420              :    Otherwise, DATA->path is filled and the function returns TRUE indicating
    6421              :    that a path to follow was found.
    6422              : 
    6423              :    If FOLLOW_JUMPS is false, the maximum path length is 1 and the only
    6424              :    block in the path will be FIRST_BB.  */
    6425              : 
    6426              : static bool
    6427     40550368 : cse_find_path (basic_block first_bb, struct cse_basic_block_data *data,
    6428              :                bool follow_jumps)
    6429              : {
    6430     40550368 :   basic_block bb;
    6431     40550368 :   edge e;
    6432     40550368 :   int path_size;
    6433              : 
    6434     40550368 :   bitmap_set_bit (cse_visited_basic_blocks, first_bb->index);
    6435              : 
    6436              :   /* See if there is a previous path.  */
    6437     40550368 :   path_size = data->path_size;
    6438              : 
    6439              :   /* There is a previous path.  Make sure it started with FIRST_BB.  */
    6440     40550368 :   if (path_size)
    6441     21797704 :     gcc_assert (data->path[0].bb == first_bb);
    6442              : 
    6443              :   /* There was only one basic block in the last path.  Clear the path and
    6444              :      return, so that paths starting at another basic block can be tried.  */
    6445     21797704 :   if (path_size == 1)
    6446              :     {
    6447     14621237 :       path_size = 0;
    6448     14621237 :       goto done;
    6449              :     }
    6450              : 
    6451              :   /* If the path was empty from the beginning, construct a new path.  */
    6452     25929131 :   if (path_size == 0)
    6453     18752664 :     data->path[path_size++].bb = first_bb;
    6454              :   else
    6455              :     {
    6456              :       /* Otherwise, path_size must be equal to or greater than 2, because
    6457              :          a previous path exists that is at least two basic blocks long.
    6458              : 
    6459              :          Update the previous branch path, if any.  If the last branch was
    6460              :          previously along the branch edge, take the fallthrough edge now.  */
    6461     15876572 :       while (path_size >= 2)
    6462              :         {
    6463     11745145 :           basic_block last_bb_in_path, previous_bb_in_path;
    6464     11745145 :           edge e;
    6465              : 
    6466     11745145 :           --path_size;
    6467     11745145 :           last_bb_in_path = data->path[path_size].bb;
    6468     11745145 :           previous_bb_in_path = data->path[path_size - 1].bb;
    6469              : 
    6470              :           /* If we previously followed a path along the branch edge, try
    6471              :              the fallthru edge now.  */
    6472     20445250 :           if (EDGE_COUNT (previous_bb_in_path->succs) == 2
    6473     11407995 :               && any_condjump_p (BB_END (previous_bb_in_path))
    6474     11407995 :               && (e = find_edge (previous_bb_in_path, last_bb_in_path))
    6475     23153140 :               && e == BRANCH_EDGE (previous_bb_in_path))
    6476              :             {
    6477      4066194 :               bb = FALLTHRU_EDGE (previous_bb_in_path)->dest;
    6478      4066194 :               if (bb != EXIT_BLOCK_PTR_FOR_FN (cfun)
    6479      4066194 :                   && single_pred_p (bb)
    6480              :                   /* We used to assert here that we would only see blocks
    6481              :                      that we have not visited yet.  But we may end up
    6482              :                      visiting basic blocks twice if the CFG has changed
    6483              :                      in this run of cse_main, because when the CFG changes
    6484              :                      the topological sort of the CFG also changes.  A basic
    6485              :                      blocks that previously had more than two predecessors
    6486              :                      may now have a single predecessor, and become part of
    6487              :                      a path that starts at another basic block.
    6488              : 
    6489              :                      We still want to visit each basic block only once, so
    6490              :                      halt the path here if we have already visited BB.  */
    6491      7111234 :                   && !bitmap_bit_p (cse_visited_basic_blocks, bb->index))
    6492              :                 {
    6493      3045040 :                   bitmap_set_bit (cse_visited_basic_blocks, bb->index);
    6494      3045040 :                   data->path[path_size++].bb = bb;
    6495      3045040 :                   break;
    6496              :                 }
    6497              :             }
    6498              : 
    6499      8700105 :           data->path[path_size].bb = NULL;
    6500              :         }
    6501              : 
    6502              :       /* If only one block remains in the path, bail.  */
    6503      7176467 :       if (path_size == 1)
    6504              :         {
    6505      4131427 :           path_size = 0;
    6506      4131427 :           goto done;
    6507              :         }
    6508              :     }
    6509              : 
    6510              :   /* Extend the path if possible.  */
    6511     21797704 :   if (follow_jumps)
    6512              :     {
    6513     12441768 :       bb = data->path[path_size - 1].bb;
    6514     21145552 :       while (bb && path_size < param_max_cse_path_length)
    6515              :         {
    6516     20986753 :           if (single_succ_p (bb))
    6517      9180579 :             e = single_succ_edge (bb);
    6518     11806174 :           else if (EDGE_COUNT (bb->succs) == 2
    6519     11785206 :                    && any_condjump_p (BB_END (bb)))
    6520              :             {
    6521              :               /* First try to follow the branch.  If that doesn't lead
    6522              :                  to a useful path, follow the fallthru edge.  */
    6523      9316984 :               e = BRANCH_EDGE (bb);
    6524      9316984 :               if (!single_pred_p (e->dest))
    6525      5240442 :                 e = FALLTHRU_EDGE (bb);
    6526              :             }
    6527              :           else
    6528              :             e = NULL;
    6529              : 
    6530     18497563 :           if (e
    6531     18497563 :               && !((e->flags & EDGE_ABNORMAL_CALL) && cfun->has_nonlocal_label)
    6532     18496518 :               && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)
    6533     16300011 :               && single_pred_p (e->dest)
    6534              :               /* Avoid visiting basic blocks twice.  The large comment
    6535              :                  above explains why this can happen.  */
    6536     27201360 :               && !bitmap_bit_p (cse_visited_basic_blocks, e->dest->index))
    6537              :             {
    6538      8703784 :               basic_block bb2 = e->dest;
    6539      8703784 :               bitmap_set_bit (cse_visited_basic_blocks, bb2->index);
    6540      8703784 :               data->path[path_size++].bb = bb2;
    6541      8703784 :               bb = bb2;
    6542              :             }
    6543              :           else
    6544              :             bb = NULL;
    6545              :         }
    6546              :     }
    6547              : 
    6548      9355936 : done:
    6549     40550368 :   data->path_size = path_size;
    6550     40550368 :   return path_size != 0;
    6551              : }
    6552              : 
    6553              : /* Dump the path in DATA to file F.  NSETS is the number of sets
    6554              :    in the path.  */
    6555              : 
    6556              : static void
    6557          317 : cse_dump_path (struct cse_basic_block_data *data, int nsets, FILE *f)
    6558              : {
    6559          317 :   int path_entry;
    6560              : 
    6561          317 :   fprintf (f, ";; Following path with %d sets: ", nsets);
    6562         1119 :   for (path_entry = 0; path_entry < data->path_size; path_entry++)
    6563          485 :     fprintf (f, "%d ", (data->path[path_entry].bb)->index);
    6564          317 :   fputc ('\n', f);
    6565          317 :   fflush (f);
    6566          317 : }
    6567              : 
    6568              : 
    6569              : /* Return true if BB has exception handling successor edges.  */
    6570              : 
    6571              : static bool
    6572      9067364 : have_eh_succ_edges (basic_block bb)
    6573              : {
    6574      9067364 :   edge e;
    6575      9067364 :   edge_iterator ei;
    6576              : 
    6577     21347179 :   FOR_EACH_EDGE (e, ei, bb->succs)
    6578     13279253 :     if (e->flags & EDGE_EH)
    6579              :       return true;
    6580              : 
    6581              :   return false;
    6582              : }
    6583              : 
    6584              : /* Record vec_duplicate match for SET in the same basic block, if any.  */
    6585              : static void
    6586    206663280 : cse_prescan_cache_vec_dup (struct cse_basic_block_data *data, basic_block bb,
    6587              :                            rtx_insn *insn, rtx set)
    6588              : {
    6589    206663280 :   rtx src = SET_SRC (set);
    6590    206663280 :   rtx dest = SET_DEST (set);
    6591    206663280 :   machine_mode mode = GET_MODE (src);
    6592    206663280 :   rtx scalar;
    6593              : 
    6594              :   /* Limit matching to duplicates of the same pseudo register, or an exact
    6595              :      SUBREG of such a pseudo.  */
    6596    206663280 :   if (!vec_duplicate_p (src, &scalar))
    6597    206312453 :     return;
    6598      1047458 :   if (REG_P (scalar))
    6599              :     {
    6600       350350 :       if (HARD_REGISTER_P (scalar))
    6601              :         return;
    6602              :     }
    6603       697108 :   else if (SUBREG_P (scalar))
    6604              :     {
    6605         1022 :       if (!REG_P (SUBREG_REG (scalar))
    6606         1022 :           || HARD_REGISTER_P (SUBREG_REG (scalar)))
    6607              :         return;
    6608              :     }
    6609              :   else
    6610              :     return;
    6611              : 
    6612              :   /* Check for matching cached vec_duplicates and save the match if found.  */
    6613      1278921 :   for (auto &entry : data->vec_duplicate_cache)
    6614              :     /* Create a match with existing cache entry if both scalar register
    6615              :        pseudos are matching and the new vec_duplicate mode is wider.  */
    6616       450700 :     if (GET_MODE_INNER (mode) == GET_MODE_INNER (entry.widest_mode)
    6617       216279 :         && rtx_equal_p (entry.scalar, scalar)
    6618       225897 :         && entry.last_checked_insn)
    6619              :       {
    6620          547 :         if (REG_P (dest)
    6621         1641 :             && known_gt (GET_MODE_SIZE (mode),
    6622              :                          GET_MODE_SIZE (entry.widest_mode)))
    6623              :           {
    6624           75 :             if (reg_set_between_p (scalar, entry.last_checked_insn, insn))
    6625              :               {
    6626            2 :                 entry.last_checked_insn = NULL;
    6627            2 :                 continue;
    6628              :               }
    6629           73 :             entry.widest_mode = mode;
    6630           73 :             entry.widest_insn = insn;
    6631           73 :             entry.last_checked_insn = insn;
    6632           73 :             entry.related_dups.safe_push (insn);
    6633           73 :             return;
    6634              :           }
    6635         1416 :         else if (known_le (GET_MODE_SIZE (mode),
    6636              :                            GET_MODE_SIZE (entry.widest_mode)))
    6637              :           {
    6638          472 :             if (reg_set_between_p (scalar, entry.last_checked_insn, insn))
    6639              :               {
    6640            0 :                 entry.last_checked_insn = NULL;
    6641            0 :                 continue;
    6642              :               }
    6643          472 :             entry.last_checked_insn = insn;
    6644          472 :             entry.related_dups.safe_push (insn);
    6645          472 :             return;
    6646              :           }
    6647              :       }
    6648              : 
    6649              :   /* Cache vec_duplicate as a new entry if no match was found.  */
    6650       350827 :   cse_vec_duplicate_match new_entry (bb, mode, scalar, insn, NULL, insn);
    6651       350827 :   new_entry.related_dups.safe_push (insn);
    6652       350827 :   data->vec_duplicate_cache.safe_push (new_entry);
    6653       350827 : }
    6654              : 
    6655              : 
    6656              : /* Scan to the end of the path described by DATA.  Return an estimate of
    6657              :    the total number of SETs of all insns in the path.  Also record any
    6658              :    matching vec_duplicate SETs of the same scalar value for different modes.  */
    6659              : 
    6660              : static void
    6661     21797704 : cse_prescan_path (struct cse_basic_block_data *data)
    6662              : {
    6663     21797704 :   int nsets = 0;
    6664     21797704 :   int path_size = data->path_size;
    6665     21797704 :   int path_entry;
    6666              : 
    6667     21797704 :   data->vec_duplicate_matches.truncate (0);
    6668              : 
    6669              :   /* Scan to end of each basic block in the path.  */
    6670     80717160 :   for (path_entry = 0; path_entry < path_size; path_entry++)
    6671              :     {
    6672     37121752 :       basic_block bb;
    6673     37121752 :       rtx_insn *insn;
    6674              : 
    6675     37121752 :       bb = data->path[path_entry].bb;
    6676     37121752 :       data->vec_duplicate_cache.truncate (0);
    6677              : 
    6678    507353341 :       FOR_BB_INSNS (bb, insn)
    6679              :         {
    6680    470231589 :           if (!INSN_P (insn))
    6681     59292161 :             continue;
    6682              : 
    6683    410939428 :           rtx pattern = PATTERN (insn);
    6684              : 
    6685              :           /* A PARALLEL can have lots of SETs in it,
    6686              :              especially if it is really an ASM_OPERANDS.  */
    6687    410939428 :           if (GET_CODE (pattern) == PARALLEL)
    6688              :             {
    6689     31988964 :               int len = XVECLEN (pattern, 0);
    6690              : 
    6691     31988964 :               nsets += len;
    6692     97403217 :               for (int i = 0; i < len; i++)
    6693              :                 {
    6694     65414253 :                   rtx elt = XVECEXP (pattern, 0, i);
    6695     65414253 :                   if (GET_CODE (elt) == SET)
    6696     32982408 :                     cse_prescan_cache_vec_dup (data, bb, insn, elt);
    6697              :                 }
    6698              :             }
    6699              :           else
    6700              :             {
    6701    378950464 :               if (GET_CODE (pattern) == SET)
    6702    173680872 :                 cse_prescan_cache_vec_dup (data, bb, insn, pattern);
    6703    378950464 :               nsets += 1;
    6704              :             }
    6705              :         }
    6706              : 
    6707              :       /* Record any vec_duplicate matches from this basic block.  */
    6708    111716083 :       for (auto &entry : data->vec_duplicate_cache)
    6709              :         {
    6710              :           /* If we recorded no wider vec_duplicate match then skip.  */
    6711       350827 :           if (entry.widest_insn == NULL_RTX)
    6712       350761 :             continue;
    6713              : 
    6714           66 :           data->vec_duplicate_matches.safe_push (entry);
    6715              :         }
    6716              :     }
    6717              : 
    6718     21797704 :   data->nsets = nsets;
    6719     21797704 : }
    6720              : 
    6721              : /* Return true if the pattern of INSN uses a LABEL_REF for which
    6722              :    there isn't a REG_LABEL_OPERAND note.  */
    6723              : 
    6724              : static bool
    6725    410755594 : check_for_label_ref (rtx_insn *insn)
    6726              : {
    6727              :   /* If this insn uses a LABEL_REF and there isn't a REG_LABEL_OPERAND
    6728              :      note for it, we must rerun jump since it needs to place the note.  If
    6729              :      this is a LABEL_REF for a CODE_LABEL that isn't in the insn chain,
    6730              :      don't do this since no REG_LABEL_OPERAND will be added.  */
    6731    410755594 :   subrtx_iterator::array_type array;
    6732   2047650536 :   FOR_EACH_SUBRTX (iter, array, PATTERN (insn), ALL)
    6733              :     {
    6734   1636896247 :       const_rtx x = *iter;
    6735   1636896247 :       if (GET_CODE (x) == LABEL_REF
    6736     20507161 :           && !LABEL_REF_NONLOCAL_P (x)
    6737     20506304 :           && (!JUMP_P (insn)
    6738     20464122 :               || !label_is_jump_target_p (label_ref_label (x), insn))
    6739        42183 :           && LABEL_P (label_ref_label (x))
    6740        41818 :           && INSN_UID (label_ref_label (x)) != 0
    6741   1636938065 :           && !find_reg_note (insn, REG_LABEL_OPERAND, label_ref_label (x)))
    6742         1305 :         return true;
    6743              :     }
    6744    410754289 :   return false;
    6745    410755594 : }
    6746              : 
    6747              : /* Process a single extended basic block described by EBB_DATA.  */
    6748              : 
    6749              : static void
    6750     21286386 : cse_extended_basic_block (struct cse_basic_block_data *ebb_data)
    6751              : {
    6752     21286386 :   int path_size = ebb_data->path_size;
    6753     21286386 :   int path_entry;
    6754     21286386 :   int num_insns = 0;
    6755              : 
    6756              :   /* Allocate the space needed by qty_table.  */
    6757     21286386 :   qty_table = XNEWVEC (struct qty_table_elem, max_qty);
    6758              : 
    6759     21286386 :   new_basic_block ();
    6760     21286386 :   cse_ebb_live_in = df_get_live_in (ebb_data->path[0].bb);
    6761     21286386 :   cse_ebb_live_out = df_get_live_out (ebb_data->path[path_size - 1].bb);
    6762     57893032 :   for (path_entry = 0; path_entry < path_size; path_entry++)
    6763              :     {
    6764     36606646 :       basic_block bb;
    6765     36606646 :       rtx_insn *insn;
    6766              : 
    6767     36606646 :       bb = ebb_data->path[path_entry].bb;
    6768              : 
    6769              :       /* Invalidate recorded information for eh regs if there is an EH
    6770              :          edge pointing to that bb.  */
    6771     36606646 :       if (bb_has_eh_pred (bb))
    6772              :         {
    6773       552117 :           df_ref def;
    6774              : 
    6775      2208468 :           FOR_EACH_ARTIFICIAL_DEF (def, bb->index)
    6776      1104234 :             if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
    6777      1104234 :               invalidate (DF_REF_REG (def), GET_MODE (DF_REF_REG (def)));
    6778              :         }
    6779              : 
    6780     36606646 :       optimize_this_for_speed_p = optimize_bb_for_speed_p (bb);
    6781    505907747 :       FOR_BB_INSNS (bb, insn)
    6782              :         {
    6783              :           /* If we have processed 1,000 insns, flush the hash table to
    6784              :              avoid extreme quadratic behavior.  We must not include NOTEs
    6785              :              in the count since there may be more of them when generating
    6786              :              debugging information.  If we clear the table at different
    6787              :              times, code generated with -g -O might be different than code
    6788              :              generated with -O but not -g.
    6789              : 
    6790              :              FIXME: This is a real kludge and needs to be done some other
    6791              :                     way.  */
    6792    469301101 :           if (NONDEBUG_INSN_P (insn)
    6793    469301101 :               && num_insns++ > param_max_cse_insns)
    6794              :             {
    6795         6030 :               flush_hash_table ();
    6796         6030 :               num_insns = 0;
    6797              :             }
    6798              : 
    6799    469301101 :           if (INSN_P (insn))
    6800              :             {
    6801              :               /* Process notes first so we have all notes in canonical forms
    6802              :                  when looking for duplicate operations.  */
    6803    410923483 :               bool changed = false;
    6804    651634353 :               for (rtx note = REG_NOTES (insn); note; note = XEXP (note, 1))
    6805    240710870 :                 if (REG_NOTE_KIND (note) == REG_EQUAL)
    6806              :                   {
    6807      9127868 :                     rtx newval = cse_process_note (XEXP (note, 0));
    6808      9127868 :                     if (newval != XEXP (note, 0))
    6809              :                       {
    6810        44214 :                         XEXP (note, 0) = newval;
    6811        44214 :                         changed = true;
    6812              :                       }
    6813              :                   }
    6814    410923483 :               if (changed)
    6815        44214 :                 df_notes_rescan (insn);
    6816              : 
    6817    410923483 :               cse_insn (insn);
    6818              : 
    6819              :               /* If we haven't already found an insn where we added a LABEL_REF,
    6820              :                  check this one.  */
    6821    410923483 :               if (INSN_P (insn) && !recorded_label_ref
    6822    821679077 :                   && check_for_label_ref (insn))
    6823         1305 :                 recorded_label_ref = true;
    6824              :             }
    6825              :         }
    6826              : 
    6827              :       /* With non-call exceptions, we are not always able to update
    6828              :          the CFG properly inside cse_insn.  So clean up possibly
    6829              :          redundant EH edges here.  */
    6830     36606646 :       if (cfun->can_throw_non_call_exceptions && have_eh_succ_edges (bb))
    6831       999438 :         cse_cfg_altered |= purge_dead_edges (bb);
    6832              : 
    6833              :       /* If we changed a conditional jump, we may have terminated
    6834              :          the path we are following.  Check that by verifying that
    6835              :          the edge we would take still exists.  If the edge does
    6836              :          not exist anymore, purge the remainder of the path.
    6837              :          Note that this will cause us to return to the caller.  */
    6838     36606646 :       if (path_entry < path_size - 1)
    6839              :         {
    6840     15323147 :           basic_block next_bb = ebb_data->path[path_entry + 1].bb;
    6841     15323147 :           if (!find_edge (bb, next_bb))
    6842              :             {
    6843         3679 :               do
    6844              :                 {
    6845         3679 :                   path_size--;
    6846              : 
    6847              :                   /* If we truncate the path, we must also reset the
    6848              :                      visited bit on the remaining blocks in the path,
    6849              :                      or we will never visit them at all.  */
    6850         3679 :                   bitmap_clear_bit (cse_visited_basic_blocks,
    6851         3679 :                              ebb_data->path[path_size].bb->index);
    6852         3679 :                   ebb_data->path[path_size].bb = NULL;
    6853              :                 }
    6854         3679 :               while (path_size - 1 != path_entry);
    6855         2887 :               ebb_data->path_size = path_size;
    6856              :             }
    6857              :         }
    6858              : 
    6859              :       /* If this is a conditional jump insn, record any known
    6860              :          equivalences due to the condition being tested.  */
    6861     36606646 :       insn = BB_END (bb);
    6862     36606646 :       if (path_entry < path_size - 1
    6863     51571517 :           && EDGE_COUNT (bb->succs) == 2
    6864     14964871 :           && JUMP_P (insn)
    6865     14964871 :           && single_set (insn)
    6866     14964871 :           && any_condjump_p (insn)
    6867              :           /* single_set may return non-NULL even for multiple sets
    6868              :              if there are REG_UNUSED notes.  record_jump_equiv only
    6869              :              looks at pc_set and doesn't consider other sets that
    6870              :              could affect the value, and the recorded equivalence
    6871              :              can extend the lifetime of the compared REG, so use
    6872              :              also !multiple_sets check to verify it is exactly one
    6873              :              set.  */
    6874     51571517 :           && !multiple_sets (insn))
    6875              :         {
    6876     14964871 :           basic_block next_bb = ebb_data->path[path_entry + 1].bb;
    6877     14964871 :           bool taken = (next_bb == BRANCH_EDGE (bb)->dest);
    6878     14964871 :           record_jump_equiv (insn, taken);
    6879              :         }
    6880              :     }
    6881              : 
    6882     21286386 :   gcc_assert (next_qty <= max_qty);
    6883              : 
    6884     21286386 :   free (qty_table);
    6885     21286386 : }
    6886              : 
    6887              : 
    6888              : /* Perform cse on the instructions of a function.
    6889              :    F is the first instruction.
    6890              :    NREGS is one plus the highest pseudo-reg number used in the instruction.
    6891              : 
    6892              :    Return 2 if jump optimizations should be redone due to simplifications
    6893              :    in conditional jump instructions.
    6894              :    Return 1 if the CFG should be cleaned up because it has been modified.
    6895              :    Return 0 otherwise.  */
    6896              : 
    6897              : static int
    6898      2358258 : cse_main (rtx_insn *f ATTRIBUTE_UNUSED, int nregs)
    6899              : {
    6900      2358258 :   struct cse_basic_block_data ebb_data;
    6901      2358258 :   basic_block bb;
    6902      2358258 :   int *rc_order = XNEWVEC (int, last_basic_block_for_fn (cfun));
    6903      2358258 :   int i, n_blocks;
    6904              : 
    6905              :   /* CSE doesn't use dominane info but can invalidate it in different ways.
    6906              :      For simplicity free dominance info here.  */
    6907      2358258 :   free_dominance_info (CDI_DOMINATORS);
    6908              : 
    6909      2358258 :   df_set_flags (DF_LR_RUN_DCE);
    6910      2358258 :   df_note_add_problem ();
    6911      2358258 :   df_analyze ();
    6912      2358258 :   df_set_flags (DF_DEFER_INSN_RESCAN);
    6913              : 
    6914      2358258 :   reg_scan (get_insns (), max_reg_num ());
    6915      2358258 :   init_cse_reg_info (nregs);
    6916              : 
    6917      2358258 :   ebb_data.path = XNEWVEC (struct branch_path,
    6918              :                            param_max_cse_path_length);
    6919              : 
    6920      2358258 :   cse_cfg_altered = false;
    6921      2358258 :   cse_jumps_altered = false;
    6922      2358258 :   recorded_label_ref = false;
    6923      2358258 :   ebb_data.path_size = 0;
    6924      2358258 :   ebb_data.nsets = 0;
    6925      2358258 :   rtl_hooks = cse_rtl_hooks;
    6926              : 
    6927      2358258 :   init_recog ();
    6928      2358258 :   init_alias_analysis ();
    6929              : 
    6930      2358258 :   reg_eqv_table = XNEWVEC (struct reg_eqv_elem, nregs);
    6931              : 
    6932              :   /* Set up the table of already visited basic blocks.  */
    6933      2358258 :   cse_visited_basic_blocks = sbitmap_alloc (last_basic_block_for_fn (cfun));
    6934      2358258 :   bitmap_clear (cse_visited_basic_blocks);
    6935              : 
    6936              :   /* Loop over basic blocks in reverse completion order (RPO),
    6937              :      excluding the ENTRY and EXIT blocks.  */
    6938      2358258 :   n_blocks = pre_and_rev_post_order_compute (NULL, rc_order, false);
    6939      2358258 :   i = 0;
    6940     23469180 :   while (i < n_blocks)
    6941              :     {
    6942              :       /* Find the first block in the RPO queue that we have not yet
    6943              :          processed before.  */
    6944     30077349 :       do
    6945              :         {
    6946     30077349 :           bb = BASIC_BLOCK_FOR_FN (cfun, rc_order[i++]);
    6947              :         }
    6948     30077349 :       while (bitmap_bit_p (cse_visited_basic_blocks, bb->index)
    6949     48830013 :              && i < n_blocks);
    6950              : 
    6951              :       /* Find all paths starting with BB, and process them.  */
    6952     40550368 :       while (cse_find_path (bb, &ebb_data, flag_cse_follow_jumps))
    6953              :         {
    6954              :           /* Pre-scan the path.  */
    6955     21797704 :           cse_prescan_path (&ebb_data);
    6956              : 
    6957              :           /* If this basic block has no sets, skip it.  */
    6958     21797704 :           if (ebb_data.nsets == 0)
    6959       511318 :             continue;
    6960              : 
    6961              :           /* If prescan discovers any vec_duplicate pairs where a wider
    6962              :              duplicate appears after a narrow duplicate of the same scalar,
    6963              :              move the widest duplicate before the first vec_duplicate of this
    6964              :              scalar and rewrite all related duplicates to reuse it.  */
    6965     63859224 :           for (auto &match : ebb_data.vec_duplicate_matches)
    6966              :             {
    6967           66 :               rtx wide_set = single_set (match.widest_insn);
    6968           66 :               if (!wide_set)
    6969            0 :                 continue;
    6970           66 :               rtx wide_reg = SET_DEST (wide_set);
    6971           66 :               rtx_insn *insert_after = PREV_INSN (match.first_insn);
    6972           66 :               if (!REG_P (wide_reg) || !insert_after)
    6973            0 :                 continue;
    6974              : 
    6975              :               /* Safety check that WIDE_REG is not otherwise used or redefined
    6976              :                  before its original defining insn.  */
    6977           66 :               if (reg_used_between_p (wide_reg, match.first_insn,
    6978           66 :                                       match.widest_insn)
    6979          132 :                   || reg_set_between_p (wide_reg, match.first_insn,
    6980           66 :                                         match.widest_insn))
    6981            0 :                 continue;
    6982              : 
    6983              :               /* Rewrite all related duplicates as a group so we either keep
    6984              :                  the whole transformation or none of it.  */
    6985           66 :               int prev_changes = num_changes_pending ();
    6986           66 :               bool abort_changes = false;
    6987              : 
    6988          339 :               for (auto &dup_insn : match.related_dups)
    6989              :                 {
    6990          141 :                   rtx dup_set;
    6991          141 :                   rtx dup_src;
    6992          141 :                   machine_mode dup_mode;
    6993              : 
    6994          141 :                   if (dup_insn == match.widest_insn)
    6995           66 :                     continue;
    6996              : 
    6997              :                   /* The earlier safety check already covered the range from
    6998              :                      FIRST_INSN up to WIDEST_INSN.  Only check the remaining
    6999              :                      suffix for duplicates that come later in the block.  This
    7000              :                      also covers call-clobbered hard registers via
    7001              :                      reg_set_between_p.  */
    7002           75 :                   bool reg_set = false;
    7003           75 :                   bool reg_set_with_widest_after = false;
    7004          761 :                   for (rtx_insn *scan = NEXT_INSN (match.widest_insn);
    7005         1522 :                        scan != NEXT_INSN (BB_END (match.bb))
    7006          761 :                        && scan != NULL_RTX;
    7007          686 :                        scan = NEXT_INSN (scan))
    7008              :                     {
    7009          688 :                       if (scan == dup_insn)
    7010              :                         {
    7011              :                           reg_set_with_widest_after = reg_set;
    7012              :                           break;
    7013              :                         }
    7014          686 :                       if (!reg_set
    7015          686 :                           && INSN_P (scan)
    7016         1372 :                           && reg_set_p (wide_reg, scan))
    7017              :                         reg_set = true;
    7018              :                     }
    7019              : 
    7020           75 :                   if (reg_set_with_widest_after)
    7021            0 :                     continue;
    7022              : 
    7023           75 :                   dup_set = single_set (dup_insn);
    7024           75 :                   if (!dup_set)
    7025              :                     {
    7026              :                       abort_changes = true;
    7027              :                       break;
    7028              :                     }
    7029              : 
    7030           75 :                   dup_mode = GET_MODE (SET_DEST (dup_set));
    7031           75 :                   if (dup_mode == GET_MODE (wide_reg))
    7032              :                     dup_src = wide_reg;
    7033              :                   else
    7034              :                     {
    7035           75 :                       dup_src = gen_lowpart (dup_mode, wide_reg);
    7036           75 :                       if (!dup_src)
    7037              :                         {
    7038              :                           abort_changes = true;
    7039              :                           break;
    7040              :                         }
    7041              :                     }
    7042              : 
    7043           75 :                   if (rtx_equal_p (dup_src, SET_DEST (dup_set)))
    7044            0 :                     continue;
    7045              : 
    7046           75 :                   if (!validate_change (dup_insn, &SET_SRC (dup_set),
    7047              :                                         dup_src, 1))
    7048              :                     {
    7049              :                       abort_changes = true;
    7050              :                       break;
    7051              :                     }
    7052              :                 }
    7053              : 
    7054           66 :               if (abort_changes)
    7055              :                 {
    7056            0 :                   cancel_changes (prev_changes);
    7057            0 :                   continue;
    7058              :                 }
    7059              : 
    7060           66 :               if (num_changes_pending () == prev_changes)
    7061            0 :                 continue;
    7062              : 
    7063           66 :               if (!apply_change_group ())
    7064            0 :                 continue;
    7065              : 
    7066           66 :               reorder_insns (match.widest_insn, match.widest_insn,
    7067              :                              insert_after);
    7068              : 
    7069           66 :               if (match.related_dups.contains (match.widest_insn))
    7070           66 :                 df_insn_rescan (match.widest_insn);
    7071              :             }
    7072              : 
    7073              :           /* Get a reasonable estimate for the maximum number of qty's
    7074              :              needed for this path.  For this, we take the number of sets
    7075              :              and multiply that by MAX_RECOG_OPERANDS.  */
    7076     21286386 :           max_qty = ebb_data.nsets * MAX_RECOG_OPERANDS;
    7077              : 
    7078              :           /* Dump the path we're about to process.  */
    7079     21286386 :           if (dump_file)
    7080          317 :             cse_dump_path (&ebb_data, ebb_data.nsets, dump_file);
    7081              : 
    7082     21286386 :           cse_extended_basic_block (&ebb_data);
    7083              :         }
    7084              :     }
    7085              : 
    7086              :   /* Clean up.  */
    7087      2358258 :   end_alias_analysis ();
    7088      2358258 :   free (reg_eqv_table);
    7089      2358258 :   free (ebb_data.path);
    7090      2358258 :   sbitmap_free (cse_visited_basic_blocks);
    7091      2358258 :   free (rc_order);
    7092      2358258 :   rtl_hooks = general_rtl_hooks;
    7093              : 
    7094      2358258 :   if (cse_jumps_altered || recorded_label_ref)
    7095              :     return 2;
    7096      2350324 :   else if (cse_cfg_altered)
    7097              :     return 1;
    7098              :   else
    7099      2340644 :     return 0;
    7100      2358258 : }
    7101              : 
    7102              : /* Count the number of times registers are used (not set) in X.
    7103              :    COUNTS is an array in which we accumulate the count, INCR is how much
    7104              :    we count each register usage.
    7105              : 
    7106              :    Don't count a usage of DEST, which is the SET_DEST of a SET which
    7107              :    contains X in its SET_SRC.  This is because such a SET does not
    7108              :    modify the liveness of DEST.
    7109              :    DEST is set to pc_rtx for a trapping insn, or for an insn with side effects.
    7110              :    We must then count uses of a SET_DEST regardless, because the insn can't be
    7111              :    deleted here.
    7112              :    Also count uses of a SET_DEST if it has been used by an earlier insn,
    7113              :    but in that case only when incrementing and not when decrementing, effectively
    7114              :    making setters of such a pseudo non-eliminable.  This is for cases like
    7115              :    (set (reg x) (expr))
    7116              :    ...
    7117              :    (set (reg y) (expr (reg (x))))
    7118              :    ...
    7119              :    (set (reg x) (expr (reg (x))))
    7120              :    where we can't eliminate the last insn because x is is still used, if y
    7121              :    is unused we can eliminate the middle insn and when considering the first insn
    7122              :    we used to eliminate it despite it being used in the last insn.  */
    7123              : 
    7124              : static void
    7125   2506584928 : count_reg_usage (rtx x, int *counts, rtx dest, int incr)
    7126              : {
    7127   2997128409 :   enum rtx_code code;
    7128   2997128409 :   rtx note;
    7129   2997128409 :   const char *fmt;
    7130   2997128409 :   int i, j;
    7131              : 
    7132   2997128409 :   if (x == 0)
    7133              :     return;
    7134              : 
    7135   2966723270 :   switch (code = GET_CODE (x))
    7136              :     {
    7137    563090695 :     case REG:
    7138    563090695 :       if (x != dest || (incr > 0 && counts[REGNO (x)]))
    7139    559167251 :         counts[REGNO (x)] += incr;
    7140              :       return;
    7141              : 
    7142              :     case PC:
    7143              :     case CONST:
    7144              :     CASE_CONST_ANY:
    7145              :     case SYMBOL_REF:
    7146              :     case LABEL_REF:
    7147              :       return;
    7148              : 
    7149    171321762 :     case CLOBBER:
    7150              :       /* If we are clobbering a MEM, mark any registers inside the address
    7151              :          as being used.  */
    7152    171321762 :       if (MEM_P (XEXP (x, 0)))
    7153       219471 :         count_reg_usage (XEXP (XEXP (x, 0), 0), counts, NULL_RTX, incr);
    7154              :       return;
    7155              : 
    7156    405761629 :     case SET:
    7157              :       /* Unless we are setting a REG, count everything in SET_DEST.  */
    7158    405761629 :       if (!REG_P (SET_DEST (x)))
    7159     98618195 :         count_reg_usage (SET_DEST (x), counts, NULL_RTX, incr);
    7160    405761629 :       count_reg_usage (SET_SRC (x), counts,
    7161              :                        dest ? dest : SET_DEST (x),
    7162              :                        incr);
    7163    405761629 :       return;
    7164              : 
    7165              :     case DEBUG_INSN:
    7166              :       return;
    7167              : 
    7168    426716951 :     case CALL_INSN:
    7169    426716951 :     case INSN:
    7170    426716951 :     case JUMP_INSN:
    7171              :       /* We expect dest to be NULL_RTX here.  If the insn may throw,
    7172              :          or if it cannot be deleted due to side-effects, mark this fact
    7173              :          by setting DEST to pc_rtx.  */
    7174    426716951 :       if ((!cfun->can_delete_dead_exceptions
    7175    165732530 :            && !insn_nothrow_p (as_a <rtx_insn *> (x)))
    7176    574251448 :           || side_effects_p (PATTERN (x)))
    7177     55842671 :         dest = pc_rtx;
    7178    426716951 :       if (auto call = dyn_cast<rtx_call_insn *> (x))
    7179     30405139 :         count_reg_usage (CALL_INSN_FUNCTION_USAGE (call), counts, dest, incr);
    7180    426716951 :       count_reg_usage (PATTERN (x), counts, dest, incr);
    7181              : 
    7182              :       /* Things used in a REG_EQUAL note aren't dead since loop may try to
    7183              :          use them.  */
    7184              : 
    7185    426716951 :       note = find_reg_equal_equiv_note (as_a <rtx_insn *> (x));
    7186    426716951 :       if (note)
    7187              :         {
    7188     23149180 :           rtx eqv = XEXP (note, 0);
    7189              : 
    7190     23149180 :           if (GET_CODE (eqv) == EXPR_LIST)
    7191              :           /* This REG_EQUAL note describes the result of a function call.
    7192              :              Process all the arguments.  */
    7193            0 :             do
    7194              :               {
    7195            0 :                 count_reg_usage (XEXP (eqv, 0), counts, dest, incr);
    7196            0 :                 eqv = XEXP (eqv, 1);
    7197              :               }
    7198            0 :             while (eqv && GET_CODE (eqv) == EXPR_LIST);
    7199              :           else
    7200              :             count_reg_usage (eqv, counts, dest, incr);
    7201              :         }
    7202              :       return;
    7203              : 
    7204     61413201 :     case EXPR_LIST:
    7205     61413201 :       if (REG_NOTE_KIND (x) == REG_EQUAL
    7206     61413201 :           || (REG_NOTE_KIND (x) != REG_NONNEG && GET_CODE (XEXP (x,0)) == USE)
    7207              :           /* FUNCTION_USAGE expression lists may include (CLOBBER (mem /u)),
    7208              :              involving registers in the address.  */
    7209       691238 :           || GET_CODE (XEXP (x, 0)) == CLOBBER)
    7210     60721963 :         count_reg_usage (XEXP (x, 0), counts, NULL_RTX, incr);
    7211              : 
    7212     61413201 :       count_reg_usage (XEXP (x, 1), counts, NULL_RTX, incr);
    7213     61413201 :       return;
    7214              : 
    7215       681327 :     case ASM_OPERANDS:
    7216              :       /* Iterate over just the inputs, not the constraints as well.  */
    7217      1376533 :       for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
    7218       695206 :         count_reg_usage (ASM_OPERANDS_INPUT (x, i), counts, dest, incr);
    7219              :       return;
    7220              : 
    7221            0 :     case INSN_LIST:
    7222            0 :     case INT_LIST:
    7223            0 :       gcc_unreachable ();
    7224              : 
    7225    746077915 :     default:
    7226    746077915 :       break;
    7227              :     }
    7228              : 
    7229    746077915 :   fmt = GET_RTX_FORMAT (code);
    7230   2066854165 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    7231              :     {
    7232   1320776250 :       if (fmt[i] == 'e')
    7233   1005170132 :         count_reg_usage (XEXP (x, i), counts, dest, incr);
    7234    315606118 :       else if (fmt[i] == 'E')
    7235    212271348 :         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    7236    142177286 :           count_reg_usage (XVECEXP (x, i, j), counts, dest, incr);
    7237              :     }
    7238              : }
    7239              : 
    7240              : /* Return true if X is a dead register.  */
    7241              : 
    7242              : static inline bool
    7243    817501528 : is_dead_reg (const_rtx x, int *counts)
    7244              : {
    7245    817501528 :   return (REG_P (x)
    7246    357313374 :           && REGNO (x) >= FIRST_PSEUDO_REGISTER
    7247    223043627 :           && counts[REGNO (x)] == 0);
    7248              : }
    7249              : 
    7250              : /* Return true if set is live.  */
    7251              : static bool
    7252    383165299 : set_live_p (rtx set, int *counts)
    7253              : {
    7254    383165299 :   if (set_noop_p (set))
    7255              :     return false;
    7256              : 
    7257    383142572 :   if (!is_dead_reg (SET_DEST (set), counts)
    7258      9062161 :       || side_effects_p (SET_SRC (set)))
    7259    374147431 :     return true;
    7260              : 
    7261              :   return false;
    7262              : }
    7263              : 
    7264              : /* Return true if insn is live.  */
    7265              : 
    7266              : static bool
    7267    732904375 : insn_live_p (rtx_insn *insn, int *counts)
    7268              : {
    7269    732904375 :   int i;
    7270    732904375 :   if (!cfun->can_delete_dead_exceptions && !insn_nothrow_p (insn))
    7271              :     return true;
    7272    714492185 :   else if (GET_CODE (PATTERN (insn)) == SET)
    7273    322683440 :     return set_live_p (PATTERN (insn), counts);
    7274    391808745 :   else if (GET_CODE (PATTERN (insn)) == PARALLEL)
    7275              :     {
    7276    122317878 :       for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
    7277              :         {
    7278    121812500 :           rtx elt = XVECEXP (PATTERN (insn), 0, i);
    7279              : 
    7280    121812500 :           if (GET_CODE (elt) == SET)
    7281              :             {
    7282     60481859 :               if (set_live_p (elt, counts))
    7283              :                 return true;
    7284              :             }
    7285     61330641 :           else if (GET_CODE (elt) != CLOBBER && GET_CODE (elt) != USE)
    7286              :             return true;
    7287              :         }
    7288              :       return false;
    7289              :     }
    7290    331304885 :   else if (DEBUG_INSN_P (insn))
    7291              :     {
    7292    314676466 :       if (DEBUG_MARKER_INSN_P (insn))
    7293              :         return true;
    7294              : 
    7295    243596247 :       if (DEBUG_BIND_INSN_P (insn)
    7296    243596247 :           && TREE_VISITED (INSN_VAR_LOCATION_DECL (insn)))
    7297       455371 :         return false;
    7298              : 
    7299              :       return true;
    7300              :     }
    7301              :   else
    7302              :     return true;
    7303              : }
    7304              : 
    7305              : /* Count the number of stores into pseudo.  Callback for note_stores.  */
    7306              : 
    7307              : static void
    7308    260939812 : count_stores (rtx x, const_rtx set ATTRIBUTE_UNUSED, void *data)
    7309              : {
    7310    260939812 :   int *counts = (int *) data;
    7311    260939812 :   if (REG_P (x) && REGNO (x) >= FIRST_PSEUDO_REGISTER)
    7312     97636641 :     counts[REGNO (x)]++;
    7313    260939812 : }
    7314              : 
    7315              : /* Return if DEBUG_INSN pattern PAT needs to be reset because some dead
    7316              :    pseudo doesn't have a replacement.  COUNTS[X] is zero if register X
    7317              :    is dead and REPLACEMENTS[X] is null if it has no replacement.
    7318              :    Set *SEEN_REPL to true if we see a dead register that does have
    7319              :    a replacement.  */
    7320              : 
    7321              : static bool
    7322    243372144 : is_dead_debug_insn (const_rtx pat, int *counts, rtx *replacements,
    7323              :                     bool *seen_repl)
    7324              : {
    7325    243372144 :   subrtx_iterator::array_type array;
    7326    673496778 :   FOR_EACH_SUBRTX (iter, array, pat, NONCONST)
    7327              :     {
    7328    430149572 :       const_rtx x = *iter;
    7329    496336383 :       if (is_dead_reg (x, counts))
    7330              :         {
    7331        50212 :           if (replacements && replacements[REGNO (x)] != NULL_RTX)
    7332        25274 :             *seen_repl = true;
    7333              :           else
    7334        24938 :             return true;
    7335              :         }
    7336              :     }
    7337    243347206 :   return false;
    7338    243372144 : }
    7339              : 
    7340              : /* Replace a dead pseudo in a DEBUG_INSN with replacement DEBUG_EXPR.
    7341              :    Callback for simplify_replace_fn_rtx.  */
    7342              : 
    7343              : static rtx
    7344        40470 : replace_dead_reg (rtx x, const_rtx old_rtx ATTRIBUTE_UNUSED, void *data)
    7345              : {
    7346        40470 :   rtx *replacements = (rtx *) data;
    7347              : 
    7348        40470 :   if (REG_P (x)
    7349        26337 :       && REGNO (x) >= FIRST_PSEUDO_REGISTER
    7350        66763 :       && replacements[REGNO (x)] != NULL_RTX)
    7351              :     {
    7352        25274 :       if (GET_MODE (x) == GET_MODE (replacements[REGNO (x)]))
    7353              :         return replacements[REGNO (x)];
    7354            0 :       return lowpart_subreg (GET_MODE (x), replacements[REGNO (x)],
    7355            0 :                              GET_MODE (replacements[REGNO (x)]));
    7356              :     }
    7357              :   return NULL_RTX;
    7358              : }
    7359              : 
    7360              : /* Scan all the insns and delete any that are dead; i.e., they store a register
    7361              :    that is never used or they copy a register to itself.
    7362              : 
    7363              :    This is used to remove insns made obviously dead by cse, loop or other
    7364              :    optimizations.  It improves the heuristics in loop since it won't try to
    7365              :    move dead invariants out of loops or make givs for dead quantities.  The
    7366              :    remaining passes of the compilation are also sped up.  */
    7367              : 
    7368              : int
    7369      6538252 : delete_trivially_dead_insns (rtx_insn *insns, int nreg)
    7370              : {
    7371      6538252 :   int *counts;
    7372      6538252 :   rtx_insn *insn, *prev;
    7373      6538252 :   rtx *replacements = NULL;
    7374      6538252 :   int ndead = 0;
    7375              : 
    7376      6538252 :   timevar_push (TV_DELETE_TRIVIALLY_DEAD);
    7377              :   /* First count the number of times each register is used.  */
    7378      6538252 :   if (MAY_HAVE_DEBUG_BIND_INSNS)
    7379              :     {
    7380      2688760 :       counts = XCNEWVEC (int, nreg * 3);
    7381    631681402 :       for (insn = insns; insn; insn = NEXT_INSN (insn))
    7382    626303882 :         if (DEBUG_BIND_INSN_P (insn))
    7383              :           {
    7384    243810404 :             count_reg_usage (INSN_VAR_LOCATION_LOC (insn), counts + nreg,
    7385              :                              NULL_RTX, 1);
    7386    243810404 :             TREE_VISITED (INSN_VAR_LOCATION_DECL (insn)) = 0;
    7387              :           }
    7388    382493478 :         else if (INSN_P (insn))
    7389              :           {
    7390    308490414 :             count_reg_usage (insn, counts, NULL_RTX, 1);
    7391    308490414 :             note_stores (insn, count_stores, counts + nreg * 2);
    7392              :           }
    7393              :       /* If there can be debug insns, COUNTS are 3 consecutive arrays.
    7394              :          First one counts how many times each pseudo is used outside
    7395              :          of debug insns, second counts how many times each pseudo is
    7396              :          used in debug insns and third counts how many times a pseudo
    7397              :          is stored.  */
    7398              :     }
    7399              :   else
    7400              :     {
    7401      3849492 :       counts = XCNEWVEC (int, nreg);
    7402    237329021 :       for (insn = insns; insn; insn = NEXT_INSN (insn))
    7403    229630037 :         if (INSN_P (insn))
    7404    180603557 :           count_reg_usage (insn, counts, NULL_RTX, 1);
    7405              :       /* If no debug insns can be present, COUNTS is just an array
    7406              :          which counts how many times each pseudo is used.  */
    7407              :     }
    7408              :   /* Pseudo PIC register should be considered as used due to possible
    7409              :      new usages generated.  */
    7410      6538252 :   if (!reload_completed
    7411      6538252 :       && pic_offset_table_rtx
    7412      6757214 :       && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
    7413       218962 :     counts[REGNO (pic_offset_table_rtx)]++;
    7414              :   /* Go from the last insn to the first and delete insns that only set unused
    7415              :      registers or copy a register to itself.  As we delete an insn, remove
    7416              :      usage counts for registers it uses.
    7417              : 
    7418              :      The first jump optimization pass may leave a real insn as the last
    7419              :      insn in the function.   We must not skip that insn or we may end
    7420              :      up deleting code that is not really dead.
    7421              : 
    7422              :      If some otherwise unused register is only used in DEBUG_INSNs,
    7423              :      try to create a DEBUG_EXPR temporary and emit a DEBUG_INSN before
    7424              :      the setter.  Then go through DEBUG_INSNs and if a DEBUG_EXPR
    7425              :      has been created for the unused register, replace it with
    7426              :      the DEBUG_EXPR, otherwise reset the DEBUG_INSN.  */
    7427      6538252 :   auto_vec<tree, 32> later_debug_set_vars;
    7428    862472171 :   for (insn = get_last_insn (); insn; insn = prev)
    7429              :     {
    7430    855933919 :       int live_insn = 0;
    7431              : 
    7432    855933919 :       prev = PREV_INSN (insn);
    7433    855933919 :       if (!INSN_P (insn))
    7434    123029544 :         continue;
    7435              : 
    7436    732904375 :       live_insn = insn_live_p (insn, counts);
    7437              : 
    7438              :       /* If this is a dead insn, delete it and show registers in it aren't
    7439              :          being used.  */
    7440              : 
    7441    732904375 :       if (! live_insn && dbg_cnt (delete_trivial_dead))
    7442              :         {
    7443      9158570 :           if (DEBUG_INSN_P (insn))
    7444              :             {
    7445       455371 :               if (DEBUG_BIND_INSN_P (insn))
    7446       455371 :                 count_reg_usage (INSN_VAR_LOCATION_LOC (insn), counts + nreg,
    7447              :                                  NULL_RTX, -1);
    7448              :             }
    7449              :           else
    7450              :             {
    7451      8703199 :               rtx set;
    7452      8703199 :               if (MAY_HAVE_DEBUG_BIND_INSNS
    7453      4209384 :                   && (set = single_set (insn)) != NULL_RTX
    7454      4209384 :                   && is_dead_reg (SET_DEST (set), counts)
    7455              :                   /* Used at least once in some DEBUG_INSN.  */
    7456      4203455 :                   && counts[REGNO (SET_DEST (set)) + nreg] > 0
    7457              :                   /* And set exactly once.  */
    7458        17930 :                   && counts[REGNO (SET_DEST (set)) + nreg * 2] == 1
    7459        17112 :                   && !side_effects_p (SET_SRC (set))
    7460      8720311 :                   && asm_noperands (PATTERN (insn)) < 0)
    7461              :                 {
    7462        17111 :                   rtx dval, bind_var_loc;
    7463        17111 :                   rtx_insn *bind;
    7464              : 
    7465              :                   /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL).  */
    7466        17111 :                   dval = make_debug_expr_from_rtl (SET_DEST (set));
    7467              : 
    7468              :                   /* Emit a debug bind insn before the insn in which
    7469              :                      reg dies.  */
    7470        17111 :                   bind_var_loc =
    7471        17111 :                     gen_rtx_VAR_LOCATION (GET_MODE (SET_DEST (set)),
    7472              :                                           DEBUG_EXPR_TREE_DECL (dval),
    7473              :                                           SET_SRC (set),
    7474              :                                           VAR_INIT_STATUS_INITIALIZED);
    7475        17111 :                   count_reg_usage (bind_var_loc, counts + nreg, NULL_RTX, 1);
    7476              : 
    7477        17111 :                   bind = emit_debug_insn_before (bind_var_loc, insn);
    7478        17111 :                   df_insn_rescan (bind);
    7479              : 
    7480        17111 :                   if (replacements == NULL)
    7481         9193 :                     replacements = XCNEWVEC (rtx, nreg);
    7482        17111 :                   replacements[REGNO (SET_DEST (set))] = dval;
    7483              :                 }
    7484              : 
    7485      8703199 :               count_reg_usage (insn, counts, NULL_RTX, -1);
    7486      8703199 :               ndead++;
    7487              :             }
    7488      9158570 :           cse_cfg_altered |= delete_insn_and_edges (insn);
    7489              :         }
    7490              :       else
    7491              :         {
    7492    723745805 :           if (!DEBUG_INSN_P (insn) || DEBUG_MARKER_INSN_P (insn))
    7493              :             {
    7494   1684225904 :               for (tree var : later_debug_set_vars)
    7495    243053588 :                 TREE_VISITED (var) = 0;
    7496    480390772 :               later_debug_set_vars.truncate (0);
    7497              :             }
    7498   1099288952 :           else if (DEBUG_BIND_INSN_P (insn)
    7499    243355033 :                    && !TREE_VISITED (INSN_VAR_LOCATION_DECL (insn)))
    7500              :             {
    7501    243349164 :               later_debug_set_vars.safe_push (INSN_VAR_LOCATION_DECL (insn));
    7502    243349164 :               TREE_VISITED (INSN_VAR_LOCATION_DECL (insn)) = 1;
    7503              :             }
    7504              :         }
    7505              :     }
    7506              : 
    7507      6538252 :   if (MAY_HAVE_DEBUG_BIND_INSNS)
    7508              :     {
    7509    624344998 :       for (insn = get_last_insn (); insn; insn = PREV_INSN (insn))
    7510    936107911 :         if (DEBUG_BIND_INSN_P (insn))
    7511              :           {
    7512              :             /* If this debug insn references a dead register that wasn't replaced
    7513              :                with an DEBUG_EXPR, reset the DEBUG_INSN.  */
    7514    243372144 :             bool seen_repl = false;
    7515    243372144 :             if (is_dead_debug_insn (INSN_VAR_LOCATION_LOC (insn),
    7516              :                                     counts, replacements, &seen_repl))
    7517              :               {
    7518        24938 :                 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
    7519        24938 :                 df_insn_rescan (insn);
    7520              :               }
    7521    243347206 :             else if (seen_repl)
    7522              :               {
    7523        25255 :                 INSN_VAR_LOCATION_LOC (insn)
    7524        25255 :                   = simplify_replace_fn_rtx (INSN_VAR_LOCATION_LOC (insn),
    7525              :                                              NULL_RTX, replace_dead_reg,
    7526              :                                              replacements);
    7527        25255 :                 df_insn_rescan (insn);
    7528              :               }
    7529              :           }
    7530      2688760 :       free (replacements);
    7531              :     }
    7532              : 
    7533      6538252 :   if (dump_file && ndead)
    7534           26 :     fprintf (dump_file, "Deleted %i trivially dead insns\n",
    7535              :              ndead);
    7536              :   /* Clean up.  */
    7537      6538252 :   free (counts);
    7538      6538252 :   timevar_pop (TV_DELETE_TRIVIALLY_DEAD);
    7539      6538252 :   return ndead;
    7540      6538252 : }
    7541              : 
    7542              : /* If LOC contains references to NEWREG in a different mode, change them
    7543              :    to use NEWREG instead.  */
    7544              : 
    7545              : static void
    7546        59540 : cse_change_cc_mode (subrtx_ptr_iterator::array_type &array,
    7547              :                     rtx *loc, rtx_insn *insn, rtx newreg)
    7548              : {
    7549       367892 :   FOR_EACH_SUBRTX_PTR (iter, array, loc, NONCONST)
    7550              :     {
    7551       308352 :       rtx *loc = *iter;
    7552       308352 :       rtx x = *loc;
    7553       308352 :       if (x
    7554       278582 :           && REG_P (x)
    7555        68971 :           && REGNO (x) == REGNO (newreg)
    7556       359069 :           && GET_MODE (x) != GET_MODE (newreg))
    7557              :         {
    7558        50717 :           validate_change (insn, loc, newreg, 1);
    7559        50717 :           iter.skip_subrtxes ();
    7560              :         }
    7561              :     }
    7562        59540 : }
    7563              : 
    7564              : /* Change the mode of any reference to the register REGNO (NEWREG) to
    7565              :    GET_MODE (NEWREG) in INSN.  */
    7566              : 
    7567              : static void
    7568        29770 : cse_change_cc_mode_insn (rtx_insn *insn, rtx newreg)
    7569              : {
    7570        29770 :   int success;
    7571              : 
    7572        29770 :   if (!INSN_P (insn))
    7573            0 :     return;
    7574              : 
    7575        29770 :   subrtx_ptr_iterator::array_type array;
    7576        29770 :   cse_change_cc_mode (array, &PATTERN (insn), insn, newreg);
    7577        29770 :   cse_change_cc_mode (array, &REG_NOTES (insn), insn, newreg);
    7578              : 
    7579              :   /* If the following assertion was triggered, there is most probably
    7580              :      something wrong with the cc_modes_compatible back end function.
    7581              :      CC modes only can be considered compatible if the insn - with the mode
    7582              :      replaced by any of the compatible modes - can still be recognized.  */
    7583        29770 :   success = apply_change_group ();
    7584        29770 :   gcc_assert (success);
    7585        29770 : }
    7586              : 
    7587              : /* Change the mode of any reference to the register REGNO (NEWREG) to
    7588              :    GET_MODE (NEWREG), starting at START.  Stop before END.  Stop at
    7589              :    any instruction which modifies NEWREG.  */
    7590              : 
    7591              : static void
    7592        20075 : cse_change_cc_mode_insns (rtx_insn *start, rtx_insn *end, rtx newreg)
    7593              : {
    7594        20075 :   rtx_insn *insn;
    7595              : 
    7596        40520 :   for (insn = start; insn != end; insn = NEXT_INSN (insn))
    7597              :     {
    7598        21951 :       if (! INSN_P (insn))
    7599            0 :         continue;
    7600              : 
    7601        21951 :       if (reg_set_p (newreg, insn))
    7602              :         return;
    7603              : 
    7604        20445 :       cse_change_cc_mode_insn (insn, newreg);
    7605              :     }
    7606              : }
    7607              : 
    7608              : /* BB is a basic block which finishes with CC_REG as a condition code
    7609              :    register which is set to CC_SRC.  Look through the successors of BB
    7610              :    to find blocks which have a single predecessor (i.e., this one),
    7611              :    and look through those blocks for an assignment to CC_REG which is
    7612              :    equivalent to CC_SRC.  CAN_CHANGE_MODE indicates whether we are
    7613              :    permitted to change the mode of CC_SRC to a compatible mode.  This
    7614              :    returns VOIDmode if no equivalent assignments were found.
    7615              :    Otherwise it returns the mode which CC_SRC should wind up with.
    7616              :    ORIG_BB should be the same as BB in the outermost cse_cc_succs call,
    7617              :    but is passed unmodified down to recursive calls in order to prevent
    7618              :    endless recursion.
    7619              : 
    7620              :    The main complexity in this function is handling the mode issues.
    7621              :    We may have more than one duplicate which we can eliminate, and we
    7622              :    try to find a mode which will work for multiple duplicates.  */
    7623              : 
    7624              : static machine_mode
    7625      5687367 : cse_cc_succs (basic_block bb, basic_block orig_bb, rtx cc_reg, rtx cc_src,
    7626              :               bool can_change_mode)
    7627              : {
    7628      5687367 :   bool found_equiv;
    7629      5687367 :   machine_mode mode;
    7630      5687367 :   unsigned int insn_count;
    7631      5687367 :   edge e;
    7632      5687367 :   rtx_insn *insns[2];
    7633      5687367 :   machine_mode modes[2];
    7634      5687367 :   rtx_insn *last_insns[2];
    7635      5687367 :   unsigned int i;
    7636      5687367 :   rtx newreg;
    7637      5687367 :   edge_iterator ei;
    7638              : 
    7639              :   /* We expect to have two successors.  Look at both before picking
    7640              :      the final mode for the comparison.  If we have more successors
    7641              :      (i.e., some sort of table jump, although that seems unlikely),
    7642              :      then we require all beyond the first two to use the same
    7643              :      mode.  */
    7644              : 
    7645      5687367 :   found_equiv = false;
    7646      5687367 :   mode = GET_MODE (cc_src);
    7647      5687367 :   insn_count = 0;
    7648     16111707 :   FOR_EACH_EDGE (e, ei, bb->succs)
    7649              :     {
    7650     10424340 :       rtx_insn *insn;
    7651     10424340 :       rtx_insn *end;
    7652              : 
    7653     10424340 :       if (e->flags & EDGE_COMPLEX)
    7654        32716 :         continue;
    7655              : 
    7656     10391624 :       if (EDGE_COUNT (e->dest->preds) != 1
    7657      5803192 :           || e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun)
    7658              :           /* Avoid endless recursion on unreachable blocks.  */
    7659     16094311 :           || e->dest == orig_bb)
    7660      4688938 :         continue;
    7661              : 
    7662      5702686 :       end = NEXT_INSN (BB_END (e->dest));
    7663     36237322 :       for (insn = BB_HEAD (e->dest); insn != end; insn = NEXT_INSN (insn))
    7664              :         {
    7665     35079973 :           rtx set;
    7666              : 
    7667     35079973 :           if (! INSN_P (insn))
    7668      7729836 :             continue;
    7669              : 
    7670              :           /* If CC_SRC is modified, we have to stop looking for
    7671              :              something which uses it.  */
    7672     27350137 :           if (modified_in_p (cc_src, insn))
    7673              :             break;
    7674              : 
    7675              :           /* Check whether INSN sets CC_REG to CC_SRC.  */
    7676     26850001 :           set = single_set (insn);
    7677     26850001 :           if (set
    7678     11585541 :               && REG_P (SET_DEST (set))
    7679     36936700 :               && REGNO (SET_DEST (set)) == REGNO (cc_reg))
    7680              :             {
    7681      1416511 :               bool found;
    7682      1416511 :               machine_mode set_mode;
    7683      1416511 :               machine_mode comp_mode;
    7684              : 
    7685      1416511 :               found = false;
    7686      1416511 :               set_mode = GET_MODE (SET_SRC (set));
    7687      1416511 :               comp_mode = set_mode;
    7688      1416511 :               if (rtx_equal_p (cc_src, SET_SRC (set)))
    7689              :                 found = true;
    7690      1410395 :               else if (GET_CODE (cc_src) == COMPARE
    7691      1341377 :                        && GET_CODE (SET_SRC (set)) == COMPARE
    7692      1290563 :                        && mode != set_mode
    7693       352841 :                        && rtx_equal_p (XEXP (cc_src, 0),
    7694       352841 :                                        XEXP (SET_SRC (set), 0))
    7695      1472617 :                        && rtx_equal_p (XEXP (cc_src, 1),
    7696        62222 :                                        XEXP (SET_SRC (set), 1)))
    7697              : 
    7698              :                 {
    7699        20079 :                   comp_mode = targetm.cc_modes_compatible (mode, set_mode);
    7700        20079 :                   if (comp_mode != VOIDmode
    7701        20079 :                       && (can_change_mode || comp_mode == mode))
    7702              :                     found = true;
    7703              :                 }
    7704              : 
    7705        26191 :               if (found)
    7706              :                 {
    7707        26191 :                   found_equiv = true;
    7708        26191 :                   if (insn_count < ARRAY_SIZE (insns))
    7709              :                     {
    7710        26191 :                       insns[insn_count] = insn;
    7711        26191 :                       modes[insn_count] = set_mode;
    7712        26191 :                       last_insns[insn_count] = end;
    7713        26191 :                       ++insn_count;
    7714              : 
    7715        26191 :                       if (mode != comp_mode)
    7716              :                         {
    7717         9325 :                           gcc_assert (can_change_mode);
    7718         9325 :                           mode = comp_mode;
    7719              : 
    7720              :                           /* The modified insn will be re-recognized later.  */
    7721         9325 :                           PUT_MODE (cc_src, mode);
    7722              :                         }
    7723              :                     }
    7724              :                   else
    7725              :                     {
    7726            0 :                       if (set_mode != mode)
    7727              :                         {
    7728              :                           /* We found a matching expression in the
    7729              :                              wrong mode, but we don't have room to
    7730              :                              store it in the array.  Punt.  This case
    7731              :                              should be rare.  */
    7732              :                           break;
    7733              :                         }
    7734              :                       /* INSN sets CC_REG to a value equal to CC_SRC
    7735              :                          with the right mode.  We can simply delete
    7736              :                          it.  */
    7737            0 :                       delete_insn (insn);
    7738              :                     }
    7739              : 
    7740              :                   /* We found an instruction to delete.  Keep looking,
    7741              :                      in the hopes of finding a three-way jump.  */
    7742        26191 :                   continue;
    7743              :                 }
    7744              : 
    7745              :               /* We found an instruction which sets the condition
    7746              :                  code, so don't look any farther.  */
    7747              :               break;
    7748              :             }
    7749              : 
    7750              :           /* If INSN sets CC_REG in some other way, don't look any
    7751              :              farther.  */
    7752     25433490 :           if (reg_set_p (cc_reg, insn))
    7753              :             break;
    7754              :         }
    7755              : 
    7756              :       /* If we fell off the bottom of the block, we can keep looking
    7757              :          through successors.  We pass CAN_CHANGE_MODE as false because
    7758              :          we aren't prepared to handle compatibility between the
    7759              :          further blocks and this block.  */
    7760      5702686 :       if (insn == end)
    7761              :         {
    7762      1157349 :           machine_mode submode;
    7763              : 
    7764      1157349 :           submode = cse_cc_succs (e->dest, orig_bb, cc_reg, cc_src, false);
    7765      1157349 :           if (submode != VOIDmode)
    7766              :             {
    7767           54 :               gcc_assert (submode == mode);
    7768              :               found_equiv = true;
    7769              :               can_change_mode = false;
    7770              :             }
    7771              :         }
    7772              :     }
    7773              : 
    7774      5687367 :   if (! found_equiv)
    7775              :     return VOIDmode;
    7776              : 
    7777              :   /* Now INSN_COUNT is the number of instructions we found which set
    7778              :      CC_REG to a value equivalent to CC_SRC.  The instructions are in
    7779              :      INSNS.  The modes used by those instructions are in MODES.  */
    7780              : 
    7781              :   newreg = NULL_RTX;
    7782        52427 :   for (i = 0; i < insn_count; ++i)
    7783              :     {
    7784        26191 :       if (modes[i] != mode)
    7785              :         {
    7786              :           /* We need to change the mode of CC_REG in INSNS[i] and
    7787              :              subsequent instructions.  */
    7788        10750 :           if (! newreg)
    7789              :             {
    7790        10750 :               if (GET_MODE (cc_reg) == mode)
    7791              :                 newreg = cc_reg;
    7792              :               else
    7793         7848 :                 newreg = gen_rtx_REG (mode, REGNO (cc_reg));
    7794              :             }
    7795        10750 :           cse_change_cc_mode_insns (NEXT_INSN (insns[i]), last_insns[i],
    7796              :                                     newreg);
    7797              :         }
    7798              : 
    7799        26191 :       cse_cfg_altered |= delete_insn_and_edges (insns[i]);
    7800              :     }
    7801              : 
    7802              :   return mode;
    7803              : }
    7804              : 
    7805              : /* If we have a fixed condition code register (or two), walk through
    7806              :    the instructions and try to eliminate duplicate assignments.  */
    7807              : 
    7808              : static void
    7809       987476 : cse_condition_code_reg (void)
    7810              : {
    7811       987476 :   unsigned int cc_regno_1;
    7812       987476 :   unsigned int cc_regno_2;
    7813       987476 :   rtx cc_reg_1;
    7814       987476 :   rtx cc_reg_2;
    7815       987476 :   basic_block bb;
    7816              : 
    7817       987476 :   if (! targetm.fixed_condition_code_regs (&cc_regno_1, &cc_regno_2))
    7818            0 :     return;
    7819              : 
    7820       987476 :   cc_reg_1 = gen_rtx_REG (CCmode, cc_regno_1);
    7821       987476 :   if (cc_regno_2 != INVALID_REGNUM)
    7822            0 :     cc_reg_2 = gen_rtx_REG (CCmode, cc_regno_2);
    7823              :   else
    7824              :     cc_reg_2 = NULL_RTX;
    7825              : 
    7826     11081630 :   FOR_EACH_BB_FN (bb, cfun)
    7827              :     {
    7828     10094154 :       rtx_insn *last_insn;
    7829     10094154 :       rtx cc_reg;
    7830     10094154 :       rtx_insn *insn;
    7831     10094154 :       rtx_insn *cc_src_insn;
    7832     10094154 :       rtx cc_src;
    7833     10094154 :       machine_mode mode;
    7834     10094154 :       machine_mode orig_mode;
    7835              : 
    7836              :       /* Look for blocks which end with a conditional jump based on a
    7837              :          condition code register.  Then look for the instruction which
    7838              :          sets the condition code register.  Then look through the
    7839              :          successor blocks for instructions which set the condition
    7840              :          code register to the same value.  There are other possible
    7841              :          uses of the condition code register, but these are by far the
    7842              :          most common and the ones which we are most likely to be able
    7843              :          to optimize.  */
    7844              : 
    7845     10094154 :       last_insn = BB_END (bb);
    7846     10094154 :       if (!JUMP_P (last_insn))
    7847      5412204 :         continue;
    7848              : 
    7849      4681950 :       if (reg_referenced_p (cc_reg_1, PATTERN (last_insn)))
    7850              :         cc_reg = cc_reg_1;
    7851        14874 :       else if (cc_reg_2 && reg_referenced_p (cc_reg_2, PATTERN (last_insn)))
    7852              :         cc_reg = cc_reg_2;
    7853              :       else
    7854        14874 :         continue;
    7855              : 
    7856      4667076 :       cc_src_insn = NULL;
    7857      4667076 :       cc_src = NULL_RTX;
    7858      4842623 :       for (insn = PREV_INSN (last_insn);
    7859      4842623 :            insn && insn != PREV_INSN (BB_HEAD (bb));
    7860       175547 :            insn = PREV_INSN (insn))
    7861              :         {
    7862      4722661 :           rtx set;
    7863              : 
    7864      4722661 :           if (! INSN_P (insn))
    7865       128693 :             continue;
    7866      4593968 :           set = single_set (insn);
    7867      4593968 :           if (set
    7868      4538119 :               && REG_P (SET_DEST (set))
    7869      9131160 :               && REGNO (SET_DEST (set)) == REGNO (cc_reg))
    7870              :             {
    7871      4530032 :               cc_src_insn = insn;
    7872      4530032 :               cc_src = SET_SRC (set);
    7873      4530032 :               break;
    7874              :             }
    7875        63936 :           else if (reg_set_p (cc_reg, insn))
    7876              :             break;
    7877              :         }
    7878              : 
    7879      4667076 :       if (! cc_src_insn)
    7880       137044 :         continue;
    7881              : 
    7882      4530032 :       if (modified_between_p (cc_src, cc_src_insn, NEXT_INSN (last_insn)))
    7883           14 :         continue;
    7884              : 
    7885              :       /* Now CC_REG is a condition code register used for a
    7886              :          conditional jump at the end of the block, and CC_SRC, in
    7887              :          CC_SRC_INSN, is the value to which that condition code
    7888              :          register is set, and CC_SRC is still meaningful at the end of
    7889              :          the basic block.  */
    7890              : 
    7891      4530018 :       orig_mode = GET_MODE (cc_src);
    7892      4530018 :       mode = cse_cc_succs (bb, bb, cc_reg, cc_src, true);
    7893      4530018 :       if (mode != VOIDmode)
    7894              :         {
    7895        26182 :           gcc_assert (mode == GET_MODE (cc_src));
    7896        26182 :           if (mode != orig_mode)
    7897              :             {
    7898         9325 :               rtx newreg = gen_rtx_REG (mode, REGNO (cc_reg));
    7899              : 
    7900         9325 :               cse_change_cc_mode_insn (cc_src_insn, newreg);
    7901              : 
    7902              :               /* Do the same in the following insns that use the
    7903              :                  current value of CC_REG within BB.  */
    7904         9325 :               cse_change_cc_mode_insns (NEXT_INSN (cc_src_insn),
    7905              :                                         NEXT_INSN (last_insn),
    7906              :                                         newreg);
    7907              :             }
    7908              :         }
    7909              :     }
    7910              : }
    7911              : 
    7912              : 
    7913              : /* Perform common subexpression elimination.  Nonzero value from
    7914              :    `cse_main' means that jumps were simplified and some code may now
    7915              :    be unreachable, so do jump optimization again.  */
    7916              : static unsigned int
    7917      1070213 : rest_of_handle_cse (void)
    7918              : {
    7919      1070213 :   int tem;
    7920              : 
    7921      1070213 :   if (dump_file)
    7922           32 :     dump_flow_info (dump_file, dump_flags);
    7923              : 
    7924      1070213 :   tem = cse_main (get_insns (), max_reg_num ());
    7925              : 
    7926              :   /* If we are not running more CSE passes, then we are no longer
    7927              :      expecting CSE to be run.  But always rerun it in a cheap mode.  */
    7928      1070213 :   cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
    7929              : 
    7930      1070213 :   if (tem == 2)
    7931              :     {
    7932         5444 :       timevar_push (TV_JUMP);
    7933         5444 :       rebuild_jump_labels (get_insns ());
    7934         5444 :       cse_cfg_altered |= cleanup_cfg (CLEANUP_CFG_CHANGED);
    7935         5444 :       timevar_pop (TV_JUMP);
    7936              :     }
    7937      1064769 :   else if (tem == 1 || optimize > 1)
    7938       982382 :     cse_cfg_altered |= cleanup_cfg (0);
    7939              : 
    7940      1070213 :   return 0;
    7941              : }
    7942              : 
    7943              : namespace {
    7944              : 
    7945              : const pass_data pass_data_cse =
    7946              : {
    7947              :   RTL_PASS, /* type */
    7948              :   "cse1", /* name */
    7949              :   OPTGROUP_NONE, /* optinfo_flags */
    7950              :   TV_CSE, /* tv_id */
    7951              :   0, /* properties_required */
    7952              :   0, /* properties_provided */
    7953              :   0, /* properties_destroyed */
    7954              :   0, /* todo_flags_start */
    7955              :   TODO_df_finish, /* todo_flags_finish */
    7956              : };
    7957              : 
    7958              : class pass_cse : public rtl_opt_pass
    7959              : {
    7960              : public:
    7961       302985 :   pass_cse (gcc::context *ctxt)
    7962       605970 :     : rtl_opt_pass (pass_data_cse, ctxt)
    7963              :   {}
    7964              : 
    7965              :   /* opt_pass methods: */
    7966      1531131 :   bool gate (function *) final override { return optimize > 0; }
    7967      1070213 :   unsigned int execute (function *) final override
    7968              :   {
    7969      1070213 :     return rest_of_handle_cse ();
    7970              :   }
    7971              : 
    7972              : }; // class pass_cse
    7973              : 
    7974              : } // anon namespace
    7975              : 
    7976              : rtl_opt_pass *
    7977       302985 : make_pass_cse (gcc::context *ctxt)
    7978              : {
    7979       302985 :   return new pass_cse (ctxt);
    7980              : }
    7981              : 
    7982              : 
    7983              : /* Run second CSE pass after loop optimizations.  */
    7984              : static unsigned int
    7985       987476 : rest_of_handle_cse2 (void)
    7986              : {
    7987       987476 :   int tem;
    7988              : 
    7989       987476 :   if (dump_file)
    7990           22 :     dump_flow_info (dump_file, dump_flags);
    7991              : 
    7992       987476 :   tem = cse_main (get_insns (), max_reg_num ());
    7993              : 
    7994              :   /* Run a pass to eliminate duplicated assignments to condition code
    7995              :      registers.  We have to run this after bypass_jumps, because it
    7996              :      makes it harder for that pass to determine whether a jump can be
    7997              :      bypassed safely.  */
    7998       987476 :   cse_condition_code_reg ();
    7999              : 
    8000       987476 :   delete_trivially_dead_insns (get_insns (), max_reg_num ());
    8001              : 
    8002       987476 :   if (tem == 2)
    8003              :     {
    8004         2232 :       timevar_push (TV_JUMP);
    8005         2232 :       rebuild_jump_labels (get_insns ());
    8006         2232 :       cse_cfg_altered |= cleanup_cfg (CLEANUP_CFG_CHANGED);
    8007         2232 :       timevar_pop (TV_JUMP);
    8008              :     }
    8009       985244 :   else if (tem == 1 || cse_cfg_altered)
    8010          108 :     cse_cfg_altered |= cleanup_cfg (0);
    8011              : 
    8012       987476 :   cse_not_expected = 1;
    8013       987476 :   return 0;
    8014              : }
    8015              : 
    8016              : 
    8017              : namespace {
    8018              : 
    8019              : const pass_data pass_data_cse2 =
    8020              : {
    8021              :   RTL_PASS, /* type */
    8022              :   "cse2", /* name */
    8023              :   OPTGROUP_NONE, /* optinfo_flags */
    8024              :   TV_CSE2, /* tv_id */
    8025              :   0, /* properties_required */
    8026              :   0, /* properties_provided */
    8027              :   0, /* properties_destroyed */
    8028              :   0, /* todo_flags_start */
    8029              :   TODO_df_finish, /* todo_flags_finish */
    8030              : };
    8031              : 
    8032              : class pass_cse2 : public rtl_opt_pass
    8033              : {
    8034              : public:
    8035       302985 :   pass_cse2 (gcc::context *ctxt)
    8036       605970 :     : rtl_opt_pass (pass_data_cse2, ctxt)
    8037              :   {}
    8038              : 
    8039              :   /* opt_pass methods: */
    8040      1531131 :   bool gate (function *) final override
    8041              :     {
    8042      1531131 :       return optimize > 0 && flag_rerun_cse_after_loop;
    8043              :     }
    8044              : 
    8045       987476 :   unsigned int execute (function *) final override
    8046              :   {
    8047       987476 :     return rest_of_handle_cse2 ();
    8048              :   }
    8049              : 
    8050              : }; // class pass_cse2
    8051              : 
    8052              : } // anon namespace
    8053              : 
    8054              : rtl_opt_pass *
    8055       302985 : make_pass_cse2 (gcc::context *ctxt)
    8056              : {
    8057       302985 :   return new pass_cse2 (ctxt);
    8058              : }
    8059              : 
    8060              : /* Run second CSE pass after loop optimizations.  */
    8061              : static unsigned int
    8062       300569 : rest_of_handle_cse_after_global_opts (void)
    8063              : {
    8064       300569 :   int save_cfj;
    8065       300569 :   int tem;
    8066              : 
    8067              :   /* We only want to do local CSE, so don't follow jumps.  */
    8068       300569 :   save_cfj = flag_cse_follow_jumps;
    8069       300569 :   flag_cse_follow_jumps = 0;
    8070              : 
    8071       300569 :   rebuild_jump_labels (get_insns ());
    8072       300569 :   tem = cse_main (get_insns (), max_reg_num ());
    8073       300569 :   cse_cfg_altered |= purge_all_dead_edges ();
    8074       300569 :   delete_trivially_dead_insns (get_insns (), max_reg_num ());
    8075              : 
    8076       300569 :   cse_not_expected = !flag_rerun_cse_after_loop;
    8077              : 
    8078              :   /* If cse altered any jumps, rerun jump opts to clean things up.  */
    8079       300569 :   if (tem == 2)
    8080              :     {
    8081          258 :       timevar_push (TV_JUMP);
    8082          258 :       rebuild_jump_labels (get_insns ());
    8083          258 :       cse_cfg_altered |= cleanup_cfg (CLEANUP_CFG_CHANGED);
    8084          258 :       timevar_pop (TV_JUMP);
    8085              :     }
    8086       300311 :   else if (tem == 1 || cse_cfg_altered)
    8087         4786 :     cse_cfg_altered |= cleanup_cfg (0);
    8088              : 
    8089       300569 :   flag_cse_follow_jumps = save_cfj;
    8090       300569 :   return 0;
    8091              : }
    8092              : 
    8093              : namespace {
    8094              : 
    8095              : const pass_data pass_data_cse_after_global_opts =
    8096              : {
    8097              :   RTL_PASS, /* type */
    8098              :   "cse_local", /* name */
    8099              :   OPTGROUP_NONE, /* optinfo_flags */
    8100              :   TV_CSE, /* tv_id */
    8101              :   0, /* properties_required */
    8102              :   0, /* properties_provided */
    8103              :   0, /* properties_destroyed */
    8104              :   0, /* todo_flags_start */
    8105              :   TODO_df_finish, /* todo_flags_finish */
    8106              : };
    8107              : 
    8108              : class pass_cse_after_global_opts : public rtl_opt_pass
    8109              : {
    8110              : public:
    8111       302985 :   pass_cse_after_global_opts (gcc::context *ctxt)
    8112       605970 :     : rtl_opt_pass (pass_data_cse_after_global_opts, ctxt)
    8113              :   {}
    8114              : 
    8115              :   /* opt_pass methods: */
    8116      1531131 :   bool gate (function *) final override
    8117              :     {
    8118      1531131 :       return optimize > 0 && flag_rerun_cse_after_global_opts;
    8119              :     }
    8120              : 
    8121       300569 :   unsigned int execute (function *) final override
    8122              :     {
    8123       300569 :       return rest_of_handle_cse_after_global_opts ();
    8124              :     }
    8125              : 
    8126              : }; // class pass_cse_after_global_opts
    8127              : 
    8128              : } // anon namespace
    8129              : 
    8130              : rtl_opt_pass *
    8131       302985 : make_pass_cse_after_global_opts (gcc::context *ctxt)
    8132              : {
    8133       302985 :   return new pass_cse_after_global_opts (ctxt);
    8134              : }
        

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.