• Main Page
  • Modules
  • Data Types
  • Files

osprey/kg++fe/gnu/cse.c

Go to the documentation of this file.
00001 /* Common subexpression elimination for GNU compiler.
00002    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998
00003    1999, 2000, 2001, 2002 Free Software Foundation, Inc.
00004 
00005 This file is part of GCC.
00006 
00007 GCC is free software; you can redistribute it and/or modify it under
00008 the terms of the GNU General Public License as published by the Free
00009 Software Foundation; either version 2, or (at your option) any later
00010 version.
00011 
00012 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
00013 WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with GCC; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
00020 02111-1307, USA.  */
00021 
00022 #include "config.h"
00023 /* stdio.h must precede rtl.h for FFS.  */
00024 #include "system.h"
00025 
00026 #include "rtl.h"
00027 #include "tm_p.h"
00028 #include "regs.h"
00029 #include "hard-reg-set.h"
00030 #include "basic-block.h"
00031 #include "flags.h"
00032 #include "real.h"
00033 #include "insn-config.h"
00034 #include "recog.h"
00035 #include "function.h"
00036 #include "expr.h"
00037 #include "toplev.h"
00038 #include "output.h"
00039 #include "ggc.h"
00040 #include "timevar.h"
00041 
00042 /* The basic idea of common subexpression elimination is to go
00043    through the code, keeping a record of expressions that would
00044    have the same value at the current scan point, and replacing
00045    expressions encountered with the cheapest equivalent expression.
00046 
00047    It is too complicated to keep track of the different possibilities
00048    when control paths merge in this code; so, at each label, we forget all
00049    that is known and start fresh.  This can be described as processing each
00050    extended basic block separately.  We have a separate pass to perform
00051    global CSE.
00052 
00053    Note CSE can turn a conditional or computed jump into a nop or
00054    an unconditional jump.  When this occurs we arrange to run the jump
00055    optimizer after CSE to delete the unreachable code.
00056 
00057    We use two data structures to record the equivalent expressions:
00058    a hash table for most expressions, and a vector of "quantity
00059    numbers" to record equivalent (pseudo) registers.
00060 
00061    The use of the special data structure for registers is desirable
00062    because it is faster.  It is possible because registers references
00063    contain a fairly small number, the register number, taken from
00064    a contiguously allocated series, and two register references are
00065    identical if they have the same number.  General expressions
00066    do not have any such thing, so the only way to retrieve the
00067    information recorded on an expression other than a register
00068    is to keep it in a hash table.
00069 
00070 Registers and "quantity numbers":
00071 
00072    At the start of each basic block, all of the (hardware and pseudo)
00073    registers used in the function are given distinct quantity
00074    numbers to indicate their contents.  During scan, when the code
00075    copies one register into another, we copy the quantity number.
00076    When a register is loaded in any other way, we allocate a new
00077    quantity number to describe the value generated by this operation.
00078    `reg_qty' records what quantity a register is currently thought
00079    of as containing.
00080 
00081    All real quantity numbers are greater than or equal to `max_reg'.
00082    If register N has not been assigned a quantity, reg_qty[N] will equal N.
00083 
00084    Quantity numbers below `max_reg' do not exist and none of the `qty_table'
00085    entries should be referenced with an index below `max_reg'.
00086 
00087    We also maintain a bidirectional chain of registers for each
00088    quantity number.  The `qty_table` members `first_reg' and `last_reg',
00089    and `reg_eqv_table' members `next' and `prev' hold these chains.
00090 
00091    The first register in a chain is the one whose lifespan is least local.
00092    Among equals, it is the one that was seen first.
00093    We replace any equivalent register with that one.
00094 
00095    If two registers have the same quantity number, it must be true that
00096    REG expressions with qty_table `mode' must be in the hash table for both
00097    registers and must be in the same class.
00098 
00099    The converse is not true.  Since hard registers may be referenced in
00100    any mode, two REG expressions might be equivalent in the hash table
00101    but not have the same quantity number if the quantity number of one
00102    of the registers is not the same mode as those expressions.
00103 
00104 Constants and quantity numbers
00105 
00106    When a quantity has a known constant value, that value is stored
00107    in the appropriate qty_table `const_rtx'.  This is in addition to
00108    putting the constant in the hash table as is usual for non-regs.
00109 
00110    Whether a reg or a constant is preferred is determined by the configuration
00111    macro CONST_COSTS and will often depend on the constant value.  In any
00112    event, expressions containing constants can be simplified, by fold_rtx.
00113 
00114    When a quantity has a known nearly constant value (such as an address
00115    of a stack slot), that value is stored in the appropriate qty_table
00116    `const_rtx'.
00117 
00118    Integer constants don't have a machine mode.  However, cse
00119    determines the intended machine mode from the destination
00120    of the instruction that moves the constant.  The machine mode
00121    is recorded in the hash table along with the actual RTL
00122    constant expression so that different modes are kept separate.
00123 
00124 Other expressions:
00125 
00126    To record known equivalences among expressions in general
00127    we use a hash table called `table'.  It has a fixed number of buckets
00128    that contain chains of `struct table_elt' elements for expressions.
00129    These chains connect the elements whose expressions have the same
00130    hash codes.
00131 
00132    Other chains through the same elements connect the elements which
00133    currently have equivalent values.
00134 
00135    Register references in an expression are canonicalized before hashing
00136    the expression.  This is done using `reg_qty' and qty_table `first_reg'.
00137    The hash code of a register reference is computed using the quantity
00138    number, not the register number.
00139 
00140    When the value of an expression changes, it is necessary to remove from the
00141    hash table not just that expression but all expressions whose values
00142    could be different as a result.
00143 
00144      1. If the value changing is in memory, except in special cases
00145      ANYTHING referring to memory could be changed.  That is because
00146      nobody knows where a pointer does not point.
00147      The function `invalidate_memory' removes what is necessary.
00148 
00149      The special cases are when the address is constant or is
00150      a constant plus a fixed register such as the frame pointer
00151      or a static chain pointer.  When such addresses are stored in,
00152      we can tell exactly which other such addresses must be invalidated
00153      due to overlap.  `invalidate' does this.
00154      All expressions that refer to non-constant
00155      memory addresses are also invalidated.  `invalidate_memory' does this.
00156 
00157      2. If the value changing is a register, all expressions
00158      containing references to that register, and only those,
00159      must be removed.
00160 
00161    Because searching the entire hash table for expressions that contain
00162    a register is very slow, we try to figure out when it isn't necessary.
00163    Precisely, this is necessary only when expressions have been
00164    entered in the hash table using this register, and then the value has
00165    changed, and then another expression wants to be added to refer to
00166    the register's new value.  This sequence of circumstances is rare
00167    within any one basic block.
00168 
00169    The vectors `reg_tick' and `reg_in_table' are used to detect this case.
00170    reg_tick[i] is incremented whenever a value is stored in register i.
00171    reg_in_table[i] holds -1 if no references to register i have been
00172    entered in the table; otherwise, it contains the value reg_tick[i] had
00173    when the references were entered.  If we want to enter a reference
00174    and reg_in_table[i] != reg_tick[i], we must scan and remove old references.
00175    Until we want to enter a new entry, the mere fact that the two vectors
00176    don't match makes the entries be ignored if anyone tries to match them.
00177 
00178    Registers themselves are entered in the hash table as well as in
00179    the equivalent-register chains.  However, the vectors `reg_tick'
00180    and `reg_in_table' do not apply to expressions which are simple
00181    register references.  These expressions are removed from the table
00182    immediately when they become invalid, and this can be done even if
00183    we do not immediately search for all the expressions that refer to
00184    the register.
00185 
00186    A CLOBBER rtx in an instruction invalidates its operand for further
00187    reuse.  A CLOBBER or SET rtx whose operand is a MEM:BLK
00188    invalidates everything that resides in memory.
00189 
00190 Related expressions:
00191 
00192    Constant expressions that differ only by an additive integer
00193    are called related.  When a constant expression is put in
00194    the table, the related expression with no constant term
00195    is also entered.  These are made to point at each other
00196    so that it is possible to find out if there exists any
00197    register equivalent to an expression related to a given expression.  */
00198 
00199 /* One plus largest register number used in this function.  */
00200 
00201 static int max_reg;
00202 
00203 /* One plus largest instruction UID used in this function at time of
00204    cse_main call.  */
00205 
00206 static int max_insn_uid;
00207 
00208 /* Length of qty_table vector.  We know in advance we will not need
00209    a quantity number this big.  */
00210 
00211 static int max_qty;
00212 
00213 /* Next quantity number to be allocated.
00214    This is 1 + the largest number needed so far.  */
00215 
00216 static int next_qty;
00217 
00218 /* Per-qty information tracking.
00219 
00220    `first_reg' and `last_reg' track the head and tail of the
00221    chain of registers which currently contain this quantity.
00222 
00223    `mode' contains the machine mode of this quantity.
00224 
00225    `const_rtx' holds the rtx of the constant value of this
00226    quantity, if known.  A summations of the frame/arg pointer
00227    and a constant can also be entered here.  When this holds
00228    a known value, `const_insn' is the insn which stored the
00229    constant value.
00230 
00231    `comparison_{code,const,qty}' are used to track when a
00232    comparison between a quantity and some constant or register has
00233    been passed.  In such a case, we know the results of the comparison
00234    in case we see it again.  These members record a comparison that
00235    is known to be true.  `comparison_code' holds the rtx code of such
00236    a comparison, else it is set to UNKNOWN and the other two
00237    comparison members are undefined.  `comparison_const' holds
00238    the constant being compared against, or zero if the comparison
00239    is not against a constant.  `comparison_qty' holds the quantity
00240    being compared against when the result is known.  If the comparison
00241    is not with a register, `comparison_qty' is -1.  */
00242 
00243 struct qty_table_elem
00244 {
00245   rtx const_rtx;
00246   rtx const_insn;
00247   rtx comparison_const;
00248   int comparison_qty;
00249   unsigned int first_reg, last_reg;
00250   enum machine_mode mode;
00251   enum rtx_code comparison_code;
00252 };
00253 
00254 /* The table of all qtys, indexed by qty number.  */
00255 static struct qty_table_elem *qty_table;
00256 
00257 #ifdef HAVE_cc0
00258 /* For machines that have a CC0, we do not record its value in the hash
00259    table since its use is guaranteed to be the insn immediately following
00260    its definition and any other insn is presumed to invalidate it.
00261 
00262    Instead, we store below the value last assigned to CC0.  If it should
00263    happen to be a constant, it is stored in preference to the actual
00264    assigned value.  In case it is a constant, we store the mode in which
00265    the constant should be interpreted.  */
00266 
00267 static rtx prev_insn_cc0;
00268 static enum machine_mode prev_insn_cc0_mode;
00269 #endif
00270 
00271 /* Previous actual insn.  0 if at first insn of basic block.  */
00272 
00273 static rtx prev_insn;
00274 
00275 /* Insn being scanned.  */
00276 
00277 static rtx this_insn;
00278 
00279 /* Index by register number, gives the number of the next (or
00280    previous) register in the chain of registers sharing the same
00281    value.
00282 
00283    Or -1 if this register is at the end of the chain.
00284 
00285    If reg_qty[N] == N, reg_eqv_table[N].next is undefined.  */
00286 
00287 /* Per-register equivalence chain.  */
00288 struct reg_eqv_elem
00289 {
00290   int next, prev;
00291 };
00292 
00293 /* The table of all register equivalence chains.  */
00294 static struct reg_eqv_elem *reg_eqv_table;
00295 
00296 struct cse_reg_info
00297 {
00298   /* Next in hash chain.  */
00299   struct cse_reg_info *hash_next;
00300 
00301   /* The next cse_reg_info structure in the free or used list.  */
00302   struct cse_reg_info *next;
00303 
00304   /* Search key */
00305   unsigned int regno;
00306 
00307   /* The quantity number of the register's current contents.  */
00308   int reg_qty;
00309 
00310   /* The number of times the register has been altered in the current
00311      basic block.  */
00312   int reg_tick;
00313 
00314   /* The REG_TICK value at which rtx's containing this register are
00315      valid in the hash table.  If this does not equal the current
00316      reg_tick value, such expressions existing in the hash table are
00317      invalid.  */
00318   int reg_in_table;
00319 
00320   /* The SUBREG that was set when REG_TICK was last incremented.  Set
00321      to -1 if the last store was to the whole register, not a subreg.  */
00322   unsigned int subreg_ticked;
00323 };
00324 
00325 /* A free list of cse_reg_info entries.  */
00326 static struct cse_reg_info *cse_reg_info_free_list;
00327 
00328 /* A used list of cse_reg_info entries.  */
00329 static struct cse_reg_info *cse_reg_info_used_list;
00330 static struct cse_reg_info *cse_reg_info_used_list_end;
00331 
00332 /* A mapping from registers to cse_reg_info data structures.  */
00333 #define REGHASH_SHIFT 7
00334 #define REGHASH_SIZE  (1 << REGHASH_SHIFT)
00335 #define REGHASH_MASK  (REGHASH_SIZE - 1)
00336 static struct cse_reg_info *reg_hash[REGHASH_SIZE];
00337 
00338 #define REGHASH_FN(REGNO) \
00339   (((REGNO) ^ ((REGNO) >> REGHASH_SHIFT)) & REGHASH_MASK)
00340 
00341 /* The last lookup we did into the cse_reg_info_tree.  This allows us
00342    to cache repeated lookups.  */
00343 static unsigned int cached_regno;
00344 static struct cse_reg_info *cached_cse_reg_info;
00345 
00346 /* A HARD_REG_SET containing all the hard registers for which there is
00347    currently a REG expression in the hash table.  Note the difference
00348    from the above variables, which indicate if the REG is mentioned in some
00349    expression in the table.  */
00350 
00351 static HARD_REG_SET hard_regs_in_table;
00352 
00353 /* CUID of insn that starts the basic block currently being cse-processed.  */
00354 
00355 static int cse_basic_block_start;
00356 
00357 /* CUID of insn that ends the basic block currently being cse-processed.  */
00358 
00359 static int cse_basic_block_end;
00360 
00361 /* Vector mapping INSN_UIDs to cuids.
00362    The cuids are like uids but increase monotonically always.
00363    We use them to see whether a reg is used outside a given basic block.  */
00364 
00365 static int *uid_cuid;
00366 
00367 /* Highest UID in UID_CUID.  */
00368 static int max_uid;
00369 
00370 /* Get the cuid of an insn.  */
00371 
00372 #define INSN_CUID(INSN) (uid_cuid[INSN_UID (INSN)])
00373 
00374 /* Nonzero if this pass has made changes, and therefore it's
00375    worthwhile to run the garbage collector.  */
00376 
00377 static int cse_altered;
00378 
00379 /* Nonzero if cse has altered conditional jump insns
00380    in such a way that jump optimization should be redone.  */
00381 
00382 static int cse_jumps_altered;
00383 
00384 /* Nonzero if we put a LABEL_REF into the hash table for an INSN without a
00385    REG_LABEL, we have to rerun jump after CSE to put in the note.  */
00386 static int recorded_label_ref;
00387 
00388 /* canon_hash stores 1 in do_not_record
00389    if it notices a reference to CC0, PC, or some other volatile
00390    subexpression.  */
00391 
00392 static int do_not_record;
00393 
00394 #ifdef LOAD_EXTEND_OP
00395 
00396 /* Scratch rtl used when looking for load-extended copy of a MEM.  */
00397 static rtx memory_extend_rtx;
00398 #endif
00399 
00400 /* canon_hash stores 1 in hash_arg_in_memory
00401    if it notices a reference to memory within the expression being hashed.  */
00402 
00403 static int hash_arg_in_memory;
00404 
00405 /* The hash table contains buckets which are chains of `struct table_elt's,
00406    each recording one expression's information.
00407    That expression is in the `exp' field.
00408 
00409    The canon_exp field contains a canonical (from the point of view of
00410    alias analysis) version of the `exp' field.
00411 
00412    Those elements with the same hash code are chained in both directions
00413    through the `next_same_hash' and `prev_same_hash' fields.
00414 
00415    Each set of expressions with equivalent values
00416    are on a two-way chain through the `next_same_value'
00417    and `prev_same_value' fields, and all point with
00418    the `first_same_value' field at the first element in
00419    that chain.  The chain is in order of increasing cost.
00420    Each element's cost value is in its `cost' field.
00421 
00422    The `in_memory' field is nonzero for elements that
00423    involve any reference to memory.  These elements are removed
00424    whenever a write is done to an unidentified location in memory.
00425    To be safe, we assume that a memory address is unidentified unless
00426    the address is either a symbol constant or a constant plus
00427    the frame pointer or argument pointer.
00428 
00429    The `related_value' field is used to connect related expressions
00430    (that differ by adding an integer).
00431    The related expressions are chained in a circular fashion.
00432    `related_value' is zero for expressions for which this
00433    chain is not useful.
00434 
00435    The `cost' field stores the cost of this element's expression.
00436    The `regcost' field stores the value returned by approx_reg_cost for
00437    this element's expression.
00438 
00439    The `is_const' flag is set if the element is a constant (including
00440    a fixed address).
00441 
00442    The `flag' field is used as a temporary during some search routines.
00443 
00444    The `mode' field is usually the same as GET_MODE (`exp'), but
00445    if `exp' is a CONST_INT and has no machine mode then the `mode'
00446    field is the mode it was being used as.  Each constant is
00447    recorded separately for each mode it is used with.  */
00448 
00449 struct table_elt
00450 {
00451   rtx exp;
00452   rtx canon_exp;
00453   struct table_elt *next_same_hash;
00454   struct table_elt *prev_same_hash;
00455   struct table_elt *next_same_value;
00456   struct table_elt *prev_same_value;
00457   struct table_elt *first_same_value;
00458   struct table_elt *related_value;
00459   int cost;
00460   int regcost;
00461   enum machine_mode mode;
00462   char in_memory;
00463   char is_const;
00464   char flag;
00465 };
00466 
00467 /* We don't want a lot of buckets, because we rarely have very many
00468    things stored in the hash table, and a lot of buckets slows
00469    down a lot of loops that happen frequently.  */
00470 #define HASH_SHIFT  5
00471 #define HASH_SIZE (1 << HASH_SHIFT)
00472 #define HASH_MASK (HASH_SIZE - 1)
00473 
00474 /* Compute hash code of X in mode M.  Special-case case where X is a pseudo
00475    register (hard registers may require `do_not_record' to be set).  */
00476 
00477 #define HASH(X, M)  \
00478  ((GET_CODE (X) == REG && REGNO (X) >= FIRST_PSEUDO_REGISTER  \
00479   ? (((unsigned) REG << 7) + (unsigned) REG_QTY (REGNO (X)))  \
00480   : canon_hash (X, M)) & HASH_MASK)
00481 
00482 /* Determine whether register number N is considered a fixed register for the
00483    purpose of approximating register costs.
00484    It is desirable to replace other regs with fixed regs, to reduce need for
00485    non-fixed hard regs.
00486    A reg wins if it is either the frame pointer or designated as fixed.  */
00487 #define FIXED_REGNO_P(N)  \
00488   ((N) == FRAME_POINTER_REGNUM || (N) == HARD_FRAME_POINTER_REGNUM \
00489    || fixed_regs[N] || global_regs[N])
00490 
00491 /* Compute cost of X, as stored in the `cost' field of a table_elt.  Fixed
00492    hard registers and pointers into the frame are the cheapest with a cost
00493    of 0.  Next come pseudos with a cost of one and other hard registers with
00494    a cost of 2.  Aside from these special cases, call `rtx_cost'.  */
00495 
00496 #define CHEAP_REGNO(N) \
00497   ((N) == FRAME_POINTER_REGNUM || (N) == HARD_FRAME_POINTER_REGNUM  \
00498    || (N) == STACK_POINTER_REGNUM || (N) == ARG_POINTER_REGNUM        \
00499    || ((N) >= FIRST_VIRTUAL_REGISTER && (N) <= LAST_VIRTUAL_REGISTER)   \
00500    || ((N) < FIRST_PSEUDO_REGISTER          \
00501        && FIXED_REGNO_P (N) && REGNO_REG_CLASS (N) != NO_REGS))
00502 
00503 #define COST(X) (GET_CODE (X) == REG ? 0 : notreg_cost (X, SET))
00504 #define COST_IN(X,OUTER) (GET_CODE (X) == REG ? 0 : notreg_cost (X, OUTER))
00505 
00506 /* Get the info associated with register N.  */
00507 
00508 #define GET_CSE_REG_INFO(N)       \
00509   (((N) == cached_regno && cached_cse_reg_info) \
00510    ? cached_cse_reg_info : get_cse_reg_info ((N)))
00511 
00512 /* Get the number of times this register has been updated in this
00513    basic block.  */
00514 
00515 #define REG_TICK(N) ((GET_CSE_REG_INFO (N))->reg_tick)
00516 
00517 /* Get the point at which REG was recorded in the table.  */
00518 
00519 #define REG_IN_TABLE(N) ((GET_CSE_REG_INFO (N))->reg_in_table)
00520 
00521 /* Get the SUBREG set at the last increment to REG_TICK (-1 if not a
00522    SUBREG).  */
00523 
00524 #define SUBREG_TICKED(N) ((GET_CSE_REG_INFO (N))->subreg_ticked)
00525 
00526 /* Get the quantity number for REG.  */
00527 
00528 #define REG_QTY(N) ((GET_CSE_REG_INFO (N))->reg_qty)
00529 
00530 /* Determine if the quantity number for register X represents a valid index
00531    into the qty_table.  */
00532 
00533 #define REGNO_QTY_VALID_P(N) (REG_QTY (N) != (int) (N))
00534 
00535 static struct table_elt *table[HASH_SIZE];
00536 
00537 /* Chain of `struct table_elt's made so far for this function
00538    but currently removed from the table.  */
00539 
00540 static struct table_elt *free_element_chain;
00541 
00542 /* Number of `struct table_elt' structures made so far for this function.  */
00543 
00544 static int n_elements_made;
00545 
00546 /* Maximum value `n_elements_made' has had so far in this compilation
00547    for functions previously processed.  */
00548 
00549 static int max_elements_made;
00550 
00551 /* Surviving equivalence class when two equivalence classes are merged
00552    by recording the effects of a jump in the last insn.  Zero if the
00553    last insn was not a conditional jump.  */
00554 
00555 static struct table_elt *last_jump_equiv_class;
00556 
00557 /* Set to the cost of a constant pool reference if one was found for a
00558    symbolic constant.  If this was found, it means we should try to
00559    convert constants into constant pool entries if they don't fit in
00560    the insn.  */
00561 
00562 static int constant_pool_entries_cost;
00563 
00564 /* Define maximum length of a branch path.  */
00565 
00566 #define PATHLENGTH  10
00567 
00568 /* This data describes a block that will be processed by cse_basic_block.  */
00569 
00570 struct cse_basic_block_data
00571 {
00572   /* Lowest CUID value of insns in block.  */
00573   int low_cuid;
00574   /* Highest CUID value of insns in block.  */
00575   int high_cuid;
00576   /* Total number of SETs in block.  */
00577   int nsets;
00578   /* Last insn in the block.  */
00579   rtx last;
00580   /* Size of current branch path, if any.  */
00581   int path_size;
00582   /* Current branch path, indicating which branches will be taken.  */
00583   struct branch_path
00584     {
00585       /* The branch insn.  */
00586       rtx branch;
00587       /* Whether it should be taken or not.  AROUND is the same as taken
00588    except that it is used when the destination label is not preceded
00589        by a BARRIER.  */
00590       enum taken {TAKEN, NOT_TAKEN, AROUND} status;
00591     } path[PATHLENGTH];
00592 };
00593 
00594 /* Nonzero if X has the form (PLUS frame-pointer integer).  We check for
00595    virtual regs here because the simplify_*_operation routines are called
00596    by integrate.c, which is called before virtual register instantiation.
00597 
00598    ?!? FIXED_BASE_PLUS_P and NONZERO_BASE_PLUS_P need to move into
00599    a header file so that their definitions can be shared with the
00600    simplification routines in simplify-rtx.c.  Until then, do not
00601    change these macros without also changing the copy in simplify-rtx.c.  */
00602 
00603 #define FIXED_BASE_PLUS_P(X)          \
00604   ((X) == frame_pointer_rtx || (X) == hard_frame_pointer_rtx  \
00605    || ((X) == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM])\
00606    || (X) == virtual_stack_vars_rtx       \
00607    || (X) == virtual_incoming_args_rtx        \
00608    || (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \
00609        && (XEXP (X, 0) == frame_pointer_rtx     \
00610      || XEXP (X, 0) == hard_frame_pointer_rtx   \
00611      || ((X) == arg_pointer_rtx       \
00612          && fixed_regs[ARG_POINTER_REGNUM])   \
00613      || XEXP (X, 0) == virtual_stack_vars_rtx   \
00614      || XEXP (X, 0) == virtual_incoming_args_rtx))  \
00615    || GET_CODE (X) == ADDRESSOF)
00616 
00617 /* Similar, but also allows reference to the stack pointer.
00618 
00619    This used to include FIXED_BASE_PLUS_P, however, we can't assume that
00620    arg_pointer_rtx by itself is nonzero, because on at least one machine,
00621    the i960, the arg pointer is zero when it is unused.  */
00622 
00623 #define NONZERO_BASE_PLUS_P(X)          \
00624   ((X) == frame_pointer_rtx || (X) == hard_frame_pointer_rtx  \
00625    || (X) == virtual_stack_vars_rtx       \
00626    || (X) == virtual_incoming_args_rtx        \
00627    || (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \
00628        && (XEXP (X, 0) == frame_pointer_rtx     \
00629      || XEXP (X, 0) == hard_frame_pointer_rtx   \
00630      || ((X) == arg_pointer_rtx       \
00631          && fixed_regs[ARG_POINTER_REGNUM])   \
00632      || XEXP (X, 0) == virtual_stack_vars_rtx   \
00633      || XEXP (X, 0) == virtual_incoming_args_rtx))  \
00634    || (X) == stack_pointer_rtx          \
00635    || (X) == virtual_stack_dynamic_rtx        \
00636    || (X) == virtual_outgoing_args_rtx        \
00637    || (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \
00638        && (XEXP (X, 0) == stack_pointer_rtx     \
00639      || XEXP (X, 0) == virtual_stack_dynamic_rtx    \
00640      || XEXP (X, 0) == virtual_outgoing_args_rtx))  \
00641    || GET_CODE (X) == ADDRESSOF)
00642 
00643 static int notreg_cost    PARAMS ((rtx, enum rtx_code));
00644 static int approx_reg_cost_1  PARAMS ((rtx *, void *));
00645 static int approx_reg_cost  PARAMS ((rtx));
00646 static int preferrable    PARAMS ((int, int, int, int));
00647 static void new_basic_block PARAMS ((void));
00648 static void make_new_qty  PARAMS ((unsigned int, enum machine_mode));
00649 static void make_regs_eqv PARAMS ((unsigned int, unsigned int));
00650 static void delete_reg_equiv  PARAMS ((unsigned int));
00651 static int mention_regs   PARAMS ((rtx));
00652 static int insert_regs    PARAMS ((rtx, struct table_elt *, int));
00653 static void remove_from_table PARAMS ((struct table_elt *, unsigned));
00654 static struct table_elt *lookup PARAMS ((rtx, unsigned, enum machine_mode)),
00655        *lookup_for_remove PARAMS ((rtx, unsigned, enum machine_mode));
00656 static rtx lookup_as_function PARAMS ((rtx, enum rtx_code));
00657 static struct table_elt *insert PARAMS ((rtx, struct table_elt *, unsigned,
00658            enum machine_mode));
00659 static void merge_equiv_classes PARAMS ((struct table_elt *,
00660            struct table_elt *));
00661 static void invalidate    PARAMS ((rtx, enum machine_mode));
00662 static int cse_rtx_varies_p PARAMS ((rtx, int));
00663 static void remove_invalid_refs PARAMS ((unsigned int));
00664 static void remove_invalid_subreg_refs  PARAMS ((unsigned int, unsigned int,
00665              enum machine_mode));
00666 static void rehash_using_reg  PARAMS ((rtx));
00667 static void invalidate_memory PARAMS ((void));
00668 static void invalidate_for_call PARAMS ((void));
00669 static rtx use_related_value  PARAMS ((rtx, struct table_elt *));
00670 static unsigned canon_hash  PARAMS ((rtx, enum machine_mode));
00671 static unsigned canon_hash_string PARAMS ((const char *));
00672 static unsigned safe_hash PARAMS ((rtx, enum machine_mode));
00673 static int exp_equiv_p    PARAMS ((rtx, rtx, int, int));
00674 static rtx canon_reg    PARAMS ((rtx, rtx));
00675 static void find_best_addr  PARAMS ((rtx, rtx *, enum machine_mode));
00676 static enum rtx_code find_comparison_args PARAMS ((enum rtx_code, rtx *, rtx *,
00677                enum machine_mode *,
00678                enum machine_mode *));
00679 static rtx fold_rtx   PARAMS ((rtx, rtx));
00680 static rtx equiv_constant PARAMS ((rtx));
00681 static void record_jump_equiv PARAMS ((rtx, int));
00682 static void record_jump_cond  PARAMS ((enum rtx_code, enum machine_mode,
00683            rtx, rtx, int));
00684 static void cse_insn    PARAMS ((rtx, rtx));
00685 static int addr_affects_sp_p  PARAMS ((rtx));
00686 static void invalidate_from_clobbers PARAMS ((rtx));
00687 static rtx cse_process_notes  PARAMS ((rtx, rtx));
00688 static void cse_around_loop PARAMS ((rtx));
00689 static void invalidate_skipped_set PARAMS ((rtx, rtx, void *));
00690 static void invalidate_skipped_block PARAMS ((rtx));
00691 static void cse_check_loop_start PARAMS ((rtx, rtx, void *));
00692 static void cse_set_around_loop PARAMS ((rtx, rtx, rtx));
00693 static rtx cse_basic_block  PARAMS ((rtx, rtx, struct branch_path *, int));
00694 static void count_reg_usage PARAMS ((rtx, int *, rtx, int));
00695 static int check_for_label_ref  PARAMS ((rtx *, void *));
00696 extern void dump_class          PARAMS ((struct table_elt*));
00697 static struct cse_reg_info * get_cse_reg_info PARAMS ((unsigned int));
00698 static int check_dependence PARAMS ((rtx *, void *));
00699 
00700 static void flush_hash_table  PARAMS ((void));
00701 static bool insn_live_p   PARAMS ((rtx, int *));
00702 static bool set_live_p    PARAMS ((rtx, rtx, int *));
00703 static bool dead_libcall_p  PARAMS ((rtx, int *));
00704 
00705 /* Dump the expressions in the equivalence class indicated by CLASSP.
00706    This function is used only for debugging.  */
00707 void
00708 dump_class (classp)
00709      struct table_elt *classp;
00710 {
00711   struct table_elt *elt;
00712 
00713   fprintf (stderr, "Equivalence chain for ");
00714   print_rtl (stderr, classp->exp);
00715   fprintf (stderr, ": \n");
00716 
00717   for (elt = classp->first_same_value; elt; elt = elt->next_same_value)
00718     {
00719       print_rtl (stderr, elt->exp);
00720       fprintf (stderr, "\n");
00721     }
00722 }
00723 
00724 /* Subroutine of approx_reg_cost; called through for_each_rtx.  */
00725 
00726 static int
00727 approx_reg_cost_1 (xp, data)
00728      rtx *xp;
00729      void *data;
00730 {
00731   rtx x = *xp;
00732   int *cost_p = data;
00733 
00734   if (x && GET_CODE (x) == REG)
00735     {
00736       unsigned int regno = REGNO (x);
00737 
00738       if (! CHEAP_REGNO (regno))
00739   {
00740     if (regno < FIRST_PSEUDO_REGISTER)
00741       {
00742         if (SMALL_REGISTER_CLASSES)
00743     return 1;
00744         *cost_p += 2;
00745       }
00746     else
00747       *cost_p += 1;
00748   }
00749     }
00750 
00751   return 0;
00752 }
00753 
00754 /* Return an estimate of the cost of the registers used in an rtx.
00755    This is mostly the number of different REG expressions in the rtx;
00756    however for some exceptions like fixed registers we use a cost of
00757    0.  If any other hard register reference occurs, return MAX_COST.  */
00758 
00759 static int
00760 approx_reg_cost (x)
00761      rtx x;
00762 {
00763   int cost = 0;
00764 
00765   if (for_each_rtx (&x, approx_reg_cost_1, (void *) &cost))
00766     return MAX_COST;
00767 
00768   return cost;
00769 }
00770 
00771 /* Return a negative value if an rtx A, whose costs are given by COST_A
00772    and REGCOST_A, is more desirable than an rtx B.
00773    Return a positive value if A is less desirable, or 0 if the two are
00774    equally good.  */
00775 static int
00776 preferrable (cost_a, regcost_a, cost_b, regcost_b)
00777      int cost_a, regcost_a, cost_b, regcost_b;
00778 {
00779   /* First, get rid of cases involving expressions that are entirely
00780      unwanted.  */
00781   if (cost_a != cost_b)
00782     {
00783       if (cost_a == MAX_COST)
00784   return 1;
00785       if (cost_b == MAX_COST)
00786   return -1;
00787     }
00788 
00789   /* Avoid extending lifetimes of hardregs.  */
00790   if (regcost_a != regcost_b)
00791     {
00792       if (regcost_a == MAX_COST)
00793   return 1;
00794       if (regcost_b == MAX_COST)
00795   return -1;
00796     }
00797 
00798   /* Normal operation costs take precedence.  */
00799   if (cost_a != cost_b)
00800     return cost_a - cost_b;
00801   /* Only if these are identical consider effects on register pressure.  */
00802   if (regcost_a != regcost_b)
00803     return regcost_a - regcost_b;
00804   return 0;
00805 }
00806 
00807 /* Internal function, to compute cost when X is not a register; called
00808    from COST macro to keep it simple.  */
00809 
00810 static int
00811 notreg_cost (x, outer)
00812      rtx x;
00813      enum rtx_code outer;
00814 {
00815   return ((GET_CODE (x) == SUBREG
00816      && GET_CODE (SUBREG_REG (x)) == REG
00817      && GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
00818      && GET_MODE_CLASS (GET_MODE (SUBREG_REG (x))) == MODE_INT
00819      && (GET_MODE_SIZE (GET_MODE (x))
00820          < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
00821      && subreg_lowpart_p (x)
00822      && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (GET_MODE (x)),
00823              GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x)))))
00824     ? 0
00825     : rtx_cost (x, outer) * 2);
00826 }
00827 
00828 /* Return an estimate of the cost of computing rtx X.
00829    One use is in cse, to decide which expression to keep in the hash table.
00830    Another is in rtl generation, to pick the cheapest way to multiply.
00831    Other uses like the latter are expected in the future.  */
00832 
00833 int
00834 rtx_cost (x, outer_code)
00835      rtx x;
00836      enum rtx_code outer_code ATTRIBUTE_UNUSED;
00837 {
00838   int i, j;
00839   enum rtx_code code;
00840   const char *fmt;
00841   int total;
00842 
00843   if (x == 0)
00844     return 0;
00845 
00846   /* Compute the default costs of certain things.
00847      Note that RTX_COSTS can override the defaults.  */
00848 
00849   code = GET_CODE (x);
00850   switch (code)
00851     {
00852     case MULT:
00853       total = COSTS_N_INSNS (5);
00854       break;
00855     case DIV:
00856     case UDIV:
00857     case MOD:
00858     case UMOD:
00859       total = COSTS_N_INSNS (7);
00860       break;
00861     case USE:
00862       /* Used in loop.c and combine.c as a marker.  */
00863       total = 0;
00864       break;
00865     default:
00866       total = COSTS_N_INSNS (1);
00867     }
00868 
00869   switch (code)
00870     {
00871     case REG:
00872       return 0;
00873 
00874     case SUBREG:
00875       /* If we can't tie these modes, make this expensive.  The larger
00876    the mode, the more expensive it is.  */
00877       if (! MODES_TIEABLE_P (GET_MODE (x), GET_MODE (SUBREG_REG (x))))
00878   return COSTS_N_INSNS (2
00879             + GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD);
00880       break;
00881 
00882 #ifdef RTX_COSTS
00883       RTX_COSTS (x, code, outer_code);
00884 #endif
00885 #ifdef CONST_COSTS
00886       CONST_COSTS (x, code, outer_code);
00887 #endif
00888 
00889     default:
00890 #ifdef DEFAULT_RTX_COSTS
00891       DEFAULT_RTX_COSTS (x, code, outer_code);
00892 #endif
00893       break;
00894     }
00895 
00896   /* Sum the costs of the sub-rtx's, plus cost of this operation,
00897      which is already in total.  */
00898 
00899   fmt = GET_RTX_FORMAT (code);
00900   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
00901     if (fmt[i] == 'e')
00902       total += rtx_cost (XEXP (x, i), code);
00903     else if (fmt[i] == 'E')
00904       for (j = 0; j < XVECLEN (x, i); j++)
00905   total += rtx_cost (XVECEXP (x, i, j), code);
00906 
00907   return total;
00908 }
00909 
00910 /* Return cost of address expression X.
00911    Expect that X is properly formed address reference.  */
00912 
00913 int
00914 address_cost (x, mode)
00915      rtx x;
00916      enum machine_mode mode;
00917 {
00918   /* The ADDRESS_COST macro does not deal with ADDRESSOF nodes.  But,
00919      during CSE, such nodes are present.  Using an ADDRESSOF node which
00920      refers to the address of a REG is a good thing because we can then
00921      turn (MEM (ADDRESSSOF (REG))) into just plain REG.  */
00922 
00923   if (GET_CODE (x) == ADDRESSOF && REG_P (XEXP ((x), 0)))
00924     return -1;
00925 
00926   /* We may be asked for cost of various unusual addresses, such as operands
00927      of push instruction.  It is not worthwhile to complicate writing
00928      of ADDRESS_COST macro by such cases.  */
00929 
00930   if (!memory_address_p (mode, x))
00931     return 1000;
00932 #ifdef ADDRESS_COST
00933   return ADDRESS_COST (x);
00934 #else
00935   return rtx_cost (x, MEM);
00936 #endif
00937 }
00938 
00939 
00940 static struct cse_reg_info *
00941 get_cse_reg_info (regno)
00942      unsigned int regno;
00943 {
00944   struct cse_reg_info **hash_head = &reg_hash[REGHASH_FN (regno)];
00945   struct cse_reg_info *p;
00946 
00947   for (p = *hash_head; p != NULL; p = p->hash_next)
00948     if (p->regno == regno)
00949       break;
00950 
00951   if (p == NULL)
00952     {
00953       /* Get a new cse_reg_info structure.  */
00954       if (cse_reg_info_free_list)
00955   {
00956     p = cse_reg_info_free_list;
00957     cse_reg_info_free_list = p->next;
00958   }
00959       else
00960   p = (struct cse_reg_info *) xmalloc (sizeof (struct cse_reg_info));
00961 
00962       /* Insert into hash table.  */
00963       p->hash_next = *hash_head;
00964       *hash_head = p;
00965 
00966       /* Initialize it.  */
00967       p->reg_tick = 1;
00968       p->reg_in_table = -1;
00969       p->subreg_ticked = -1;
00970       p->reg_qty = regno;
00971       p->regno = regno;
00972       p->next = cse_reg_info_used_list;
00973       cse_reg_info_used_list = p;
00974       if (!cse_reg_info_used_list_end)
00975   cse_reg_info_used_list_end = p;
00976     }
00977 
00978   /* Cache this lookup; we tend to be looking up information about the
00979      same register several times in a row.  */
00980   cached_regno = regno;
00981   cached_cse_reg_info = p;
00982 
00983   return p;
00984 }
00985 
00986 /* Clear the hash table and initialize each register with its own quantity,
00987    for a new basic block.  */
00988 
00989 static void
00990 new_basic_block ()
00991 {
00992   int i;
00993 
00994   next_qty = max_reg;
00995 
00996   /* Clear out hash table state for this pass.  */
00997 
00998   memset ((char *) reg_hash, 0, sizeof reg_hash);
00999 
01000   if (cse_reg_info_used_list)
01001     {
01002       cse_reg_info_used_list_end->next = cse_reg_info_free_list;
01003       cse_reg_info_free_list = cse_reg_info_used_list;
01004       cse_reg_info_used_list = cse_reg_info_used_list_end = 0;
01005     }
01006   cached_cse_reg_info = 0;
01007 
01008   CLEAR_HARD_REG_SET (hard_regs_in_table);
01009 
01010   /* The per-quantity values used to be initialized here, but it is
01011      much faster to initialize each as it is made in `make_new_qty'.  */
01012 
01013   for (i = 0; i < HASH_SIZE; i++)
01014     {
01015       struct table_elt *first;
01016 
01017       first = table[i];
01018       if (first != NULL)
01019   {
01020     struct table_elt *last = first;
01021 
01022     table[i] = NULL;
01023 
01024     while (last->next_same_hash != NULL)
01025       last = last->next_same_hash;
01026 
01027     /* Now relink this hash entire chain into
01028        the free element list.  */
01029 
01030     last->next_same_hash = free_element_chain;
01031     free_element_chain = first;
01032   }
01033     }
01034 
01035   prev_insn = 0;
01036 
01037 #ifdef HAVE_cc0
01038   prev_insn_cc0 = 0;
01039 #endif
01040 }
01041 
01042 /* Say that register REG contains a quantity in mode MODE not in any
01043    register before and initialize that quantity.  */
01044 
01045 static void
01046 make_new_qty (reg, mode)
01047      unsigned int reg;
01048      enum machine_mode mode;
01049 {
01050   int q;
01051   struct qty_table_elem *ent;
01052   struct reg_eqv_elem *eqv;
01053 
01054   if (next_qty >= max_qty)
01055     abort ();
01056 
01057   q = REG_QTY (reg) = next_qty++;
01058   ent = &qty_table[q];
01059   ent->first_reg = reg;
01060   ent->last_reg = reg;
01061   ent->mode = mode;
01062   ent->const_rtx = ent->const_insn = NULL_RTX;
01063   ent->comparison_code = UNKNOWN;
01064 
01065   eqv = &reg_eqv_table[reg];
01066   eqv->next = eqv->prev = -1;
01067 }
01068 
01069 /* Make reg NEW equivalent to reg OLD.
01070    OLD is not changing; NEW is.  */
01071 
01072 static void
01073 make_regs_eqv (new, old)
01074      unsigned int new, old;
01075 {
01076   unsigned int lastr, firstr;
01077   int q = REG_QTY (old);
01078   struct qty_table_elem *ent;
01079 
01080   ent = &qty_table[q];
01081 
01082   /* Nothing should become eqv until it has a "non-invalid" qty number.  */
01083   if (! REGNO_QTY_VALID_P (old))
01084     abort ();
01085 
01086   REG_QTY (new) = q;
01087   firstr = ent->first_reg;
01088   lastr = ent->last_reg;
01089 
01090   /* Prefer fixed hard registers to anything.  Prefer pseudo regs to other
01091      hard regs.  Among pseudos, if NEW will live longer than any other reg
01092      of the same qty, and that is beyond the current basic block,
01093      make it the new canonical replacement for this qty.  */
01094   if (! (firstr < FIRST_PSEUDO_REGISTER && FIXED_REGNO_P (firstr))
01095       /* Certain fixed registers might be of the class NO_REGS.  This means
01096    that not only can they not be allocated by the compiler, but
01097    they cannot be used in substitutions or canonicalizations
01098    either.  */
01099       && (new >= FIRST_PSEUDO_REGISTER || REGNO_REG_CLASS (new) != NO_REGS)
01100       && ((new < FIRST_PSEUDO_REGISTER && FIXED_REGNO_P (new))
01101     || (new >= FIRST_PSEUDO_REGISTER
01102         && (firstr < FIRST_PSEUDO_REGISTER
01103       || ((uid_cuid[REGNO_LAST_UID (new)] > cse_basic_block_end
01104            || (uid_cuid[REGNO_FIRST_UID (new)]
01105          < cse_basic_block_start))
01106           && (uid_cuid[REGNO_LAST_UID (new)]
01107         > uid_cuid[REGNO_LAST_UID (firstr)]))))))
01108     {
01109       reg_eqv_table[firstr].prev = new;
01110       reg_eqv_table[new].next = firstr;
01111       reg_eqv_table[new].prev = -1;
01112       ent->first_reg = new;
01113     }
01114   else
01115     {
01116       /* If NEW is a hard reg (known to be non-fixed), insert at end.
01117    Otherwise, insert before any non-fixed hard regs that are at the
01118    end.  Registers of class NO_REGS cannot be used as an
01119    equivalent for anything.  */
01120       while (lastr < FIRST_PSEUDO_REGISTER && reg_eqv_table[lastr].prev >= 0
01121        && (REGNO_REG_CLASS (lastr) == NO_REGS || ! FIXED_REGNO_P (lastr))
01122        && new >= FIRST_PSEUDO_REGISTER)
01123   lastr = reg_eqv_table[lastr].prev;
01124       reg_eqv_table[new].next = reg_eqv_table[lastr].next;
01125       if (reg_eqv_table[lastr].next >= 0)
01126   reg_eqv_table[reg_eqv_table[lastr].next].prev = new;
01127       else
01128   qty_table[q].last_reg = new;
01129       reg_eqv_table[lastr].next = new;
01130       reg_eqv_table[new].prev = lastr;
01131     }
01132 }
01133 
01134 /* Remove REG from its equivalence class.  */
01135 
01136 static void
01137 delete_reg_equiv (reg)
01138      unsigned int reg;
01139 {
01140   struct qty_table_elem *ent;
01141   int q = REG_QTY (reg);
01142   int p, n;
01143 
01144   /* If invalid, do nothing.  */
01145   if (q == (int) reg)
01146     return;
01147 
01148   ent = &qty_table[q];
01149 
01150   p = reg_eqv_table[reg].prev;
01151   n = reg_eqv_table[reg].next;
01152 
01153   if (n != -1)
01154     reg_eqv_table[n].prev = p;
01155   else
01156     ent->last_reg = p;
01157   if (p != -1)
01158     reg_eqv_table[p].next = n;
01159   else
01160     ent->first_reg = n;
01161 
01162   REG_QTY (reg) = reg;
01163 }
01164 
01165 /* Remove any invalid expressions from the hash table
01166    that refer to any of the registers contained in expression X.
01167 
01168    Make sure that newly inserted references to those registers
01169    as subexpressions will be considered valid.
01170 
01171    mention_regs is not called when a register itself
01172    is being stored in the table.
01173 
01174    Return 1 if we have done something that may have changed the hash code
01175    of X.  */
01176 
01177 static int
01178 mention_regs (x)
01179      rtx x;
01180 {
01181   enum rtx_code code;
01182   int i, j;
01183   const char *fmt;
01184   int changed = 0;
01185 
01186   if (x == 0)
01187     return 0;
01188 
01189   code = GET_CODE (x);
01190   if (code == REG)
01191     {
01192       unsigned int regno = REGNO (x);
01193       unsigned int endregno
01194   = regno + (regno >= FIRST_PSEUDO_REGISTER ? 1
01195        : HARD_REGNO_NREGS (regno, GET_MODE (x)));
01196       unsigned int i;
01197 
01198       for (i = regno; i < endregno; i++)
01199   {
01200     if (REG_IN_TABLE (i) >= 0 && REG_IN_TABLE (i) != REG_TICK (i))
01201       remove_invalid_refs (i);
01202 
01203     REG_IN_TABLE (i) = REG_TICK (i);
01204     SUBREG_TICKED (i) = -1;
01205   }
01206 
01207       return 0;
01208     }
01209 
01210   /* If this is a SUBREG, we don't want to discard other SUBREGs of the same
01211      pseudo if they don't use overlapping words.  We handle only pseudos
01212      here for simplicity.  */
01213   if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG
01214       && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER)
01215     {
01216       unsigned int i = REGNO (SUBREG_REG (x));
01217 
01218       if (REG_IN_TABLE (i) >= 0 && REG_IN_TABLE (i) != REG_TICK (i))
01219   {
01220     /* If REG_IN_TABLE (i) differs from REG_TICK (i) by one, and
01221        the last store to this register really stored into this
01222        subreg, then remove the memory of this subreg.
01223        Otherwise, remove any memory of the entire register and
01224        all its subregs from the table.  */
01225     if (REG_TICK (i) - REG_IN_TABLE (i) > 1
01226         || SUBREG_TICKED (i) != REGNO (SUBREG_REG (x)))
01227       remove_invalid_refs (i);
01228     else
01229       remove_invalid_subreg_refs (i, SUBREG_BYTE (x), GET_MODE (x));
01230   }
01231 
01232       REG_IN_TABLE (i) = REG_TICK (i);
01233       SUBREG_TICKED (i) = REGNO (SUBREG_REG (x));
01234       return 0;
01235     }
01236 
01237   /* If X is a comparison or a COMPARE and either operand is a register
01238      that does not have a quantity, give it one.  This is so that a later
01239      call to record_jump_equiv won't cause X to be assigned a different
01240      hash code and not found in the table after that call.
01241 
01242      It is not necessary to do this here, since rehash_using_reg can
01243      fix up the table later, but doing this here eliminates the need to
01244      call that expensive function in the most common case where the only
01245      use of the register is in the comparison.  */
01246 
01247   if (code == COMPARE || GET_RTX_CLASS (code) == '<')
01248     {
01249       if (GET_CODE (XEXP (x, 0)) == REG
01250     && ! REGNO_QTY_VALID_P (REGNO (XEXP (x, 0))))
01251   if (insert_regs (XEXP (x, 0), NULL, 0))
01252     {
01253       rehash_using_reg (XEXP (x, 0));
01254       changed = 1;
01255     }
01256 
01257       if (GET_CODE (XEXP (x, 1)) == REG
01258     && ! REGNO_QTY_VALID_P (REGNO (XEXP (x, 1))))
01259   if (insert_regs (XEXP (x, 1), NULL, 0))
01260     {
01261       rehash_using_reg (XEXP (x, 1));
01262       changed = 1;
01263     }
01264     }
01265 
01266   fmt = GET_RTX_FORMAT (code);
01267   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
01268     if (fmt[i] == 'e')
01269       changed |= mention_regs (XEXP (x, i));
01270     else if (fmt[i] == 'E')
01271       for (j = 0; j < XVECLEN (x, i); j++)
01272   changed |= mention_regs (XVECEXP (x, i, j));
01273 
01274   return changed;
01275 }
01276 
01277 /* Update the register quantities for inserting X into the hash table
01278    with a value equivalent to CLASSP.
01279    (If the class does not contain a REG, it is irrelevant.)
01280    If MODIFIED is nonzero, X is a destination; it is being modified.
01281    Note that delete_reg_equiv should be called on a register
01282    before insert_regs is done on that register with MODIFIED != 0.
01283 
01284    Nonzero value means that elements of reg_qty have changed
01285    so X's hash code may be different.  */
01286 
01287 static int
01288 insert_regs (x, classp, modified)
01289      rtx x;
01290      struct table_elt *classp;
01291      int modified;
01292 {
01293   if (GET_CODE (x) == REG)
01294     {
01295       unsigned int regno = REGNO (x);
01296       int qty_valid;
01297 
01298       /* If REGNO is in the equivalence table already but is of the
01299    wrong mode for that equivalence, don't do anything here.  */
01300 
01301       qty_valid = REGNO_QTY_VALID_P (regno);
01302       if (qty_valid)
01303   {
01304     struct qty_table_elem *ent = &qty_table[REG_QTY (regno)];
01305 
01306     if (ent->mode != GET_MODE (x))
01307       return 0;
01308   }
01309 
01310       if (modified || ! qty_valid)
01311   {
01312     if (classp)
01313       for (classp = classp->first_same_value;
01314      classp != 0;
01315      classp = classp->next_same_value)
01316         if (GET_CODE (classp->exp) == REG
01317       && GET_MODE (classp->exp) == GET_MODE (x))
01318     {
01319       make_regs_eqv (regno, REGNO (classp->exp));
01320       return 1;
01321     }
01322 
01323     /* Mention_regs for a SUBREG checks if REG_TICK is exactly one larger
01324        than REG_IN_TABLE to find out if there was only a single preceding
01325        invalidation - for the SUBREG - or another one, which would be
01326        for the full register.  However, if we find here that REG_TICK
01327        indicates that the register is invalid, it means that it has
01328        been invalidated in a separate operation.  The SUBREG might be used
01329        now (then this is a recursive call), or we might use the full REG
01330        now and a SUBREG of it later.  So bump up REG_TICK so that
01331        mention_regs will do the right thing.  */
01332     if (! modified
01333         && REG_IN_TABLE (regno) >= 0
01334         && REG_TICK (regno) == REG_IN_TABLE (regno) + 1)
01335       REG_TICK (regno)++;
01336     make_new_qty (regno, GET_MODE (x));
01337     return 1;
01338   }
01339 
01340       return 0;
01341     }
01342 
01343   /* If X is a SUBREG, we will likely be inserting the inner register in the
01344      table.  If that register doesn't have an assigned quantity number at
01345      this point but does later, the insertion that we will be doing now will
01346      not be accessible because its hash code will have changed.  So assign
01347      a quantity number now.  */
01348 
01349   else if (GET_CODE (x) == SUBREG && GET_CODE (SUBREG_REG (x)) == REG
01350      && ! REGNO_QTY_VALID_P (REGNO (SUBREG_REG (x))))
01351     {
01352       insert_regs (SUBREG_REG (x), NULL, 0);
01353       mention_regs (x);
01354       return 1;
01355     }
01356   else
01357     return mention_regs (x);
01358 }
01359 
01360 /* Look in or update the hash table.  */
01361 
01362 /* Remove table element ELT from use in the table.
01363    HASH is its hash code, made using the HASH macro.
01364    It's an argument because often that is known in advance
01365    and we save much time not recomputing it.  */
01366 
01367 static void
01368 remove_from_table (elt, hash)
01369      struct table_elt *elt;
01370      unsigned hash;
01371 {
01372   if (elt == 0)
01373     return;
01374 
01375   /* Mark this element as removed.  See cse_insn.  */
01376   elt->first_same_value = 0;
01377 
01378   /* Remove the table element from its equivalence class.  */
01379 
01380   {
01381     struct table_elt *prev = elt->prev_same_value;
01382     struct table_elt *next = elt->next_same_value;
01383 
01384     if (next)
01385       next->prev_same_value = prev;
01386 
01387     if (prev)
01388       prev->next_same_value = next;
01389     else
01390       {
01391   struct table_elt *newfirst = next;
01392   while (next)
01393     {
01394       next->first_same_value = newfirst;
01395       next = next->next_same_value;
01396     }
01397       }
01398   }
01399 
01400   /* Remove the table element from its hash bucket.  */
01401 
01402   {
01403     struct table_elt *prev = elt->prev_same_hash;
01404     struct table_elt *next = elt->next_same_hash;
01405 
01406     if (next)
01407       next->prev_same_hash = prev;
01408 
01409     if (prev)
01410       prev->next_same_hash = next;
01411     else if (table[hash] == elt)
01412       table[hash] = next;
01413     else
01414       {
01415   /* This entry is not in the proper hash bucket.  This can happen
01416      when two classes were merged by `merge_equiv_classes'.  Search
01417      for the hash bucket that it heads.  This happens only very
01418      rarely, so the cost is acceptable.  */
01419   for (hash = 0; hash < HASH_SIZE; hash++)
01420     if (table[hash] == elt)
01421       table[hash] = next;
01422       }
01423   }
01424 
01425   /* Remove the table element from its related-value circular chain.  */
01426 
01427   if (elt->related_value != 0 && elt->related_value != elt)
01428     {
01429       struct table_elt *p = elt->related_value;
01430 
01431       while (p->related_value != elt)
01432   p = p->related_value;
01433       p->related_value = elt->related_value;
01434       if (p->related_value == p)
01435   p->related_value = 0;
01436     }
01437 
01438   /* Now add it to the free element chain.  */
01439   elt->next_same_hash = free_element_chain;
01440   free_element_chain = elt;
01441 }
01442 
01443 /* Look up X in the hash table and return its table element,
01444    or 0 if X is not in the table.
01445 
01446    MODE is the machine-mode of X, or if X is an integer constant
01447    with VOIDmode then MODE is the mode with which X will be used.
01448 
01449    Here we are satisfied to find an expression whose tree structure
01450    looks like X.  */
01451 
01452 static struct table_elt *
01453 lookup (x, hash, mode)
01454      rtx x;
01455      unsigned hash;
01456      enum machine_mode mode;
01457 {
01458   struct table_elt *p;
01459 
01460   for (p = table[hash]; p; p = p->next_same_hash)
01461     if (mode == p->mode && ((x == p->exp && GET_CODE (x) == REG)
01462           || exp_equiv_p (x, p->exp, GET_CODE (x) != REG, 0)))
01463       return p;
01464 
01465   return 0;
01466 }
01467 
01468 /* Like `lookup' but don't care whether the table element uses invalid regs.
01469    Also ignore discrepancies in the machine mode of a register.  */
01470 
01471 static struct table_elt *
01472 lookup_for_remove (x, hash, mode)
01473      rtx x;
01474      unsigned hash;
01475      enum machine_mode mode;
01476 {
01477   struct table_elt *p;
01478 
01479   if (GET_CODE (x) == REG)
01480     {
01481       unsigned int regno = REGNO (x);
01482 
01483       /* Don't check the machine mode when comparing registers;
01484    invalidating (REG:SI 0) also invalidates (REG:DF 0).  */
01485       for (p = table[hash]; p; p = p->next_same_hash)
01486   if (GET_CODE (p->exp) == REG
01487       && REGNO (p->exp) == regno)
01488     return p;
01489     }
01490   else
01491     {
01492       for (p = table[hash]; p; p = p->next_same_hash)
01493   if (mode == p->mode && (x == p->exp || exp_equiv_p (x, p->exp, 0, 0)))
01494     return p;
01495     }
01496 
01497   return 0;
01498 }
01499 
01500 /* Look for an expression equivalent to X and with code CODE.
01501    If one is found, return that expression.  */
01502 
01503 static rtx
01504 lookup_as_function (x, code)
01505      rtx x;
01506      enum rtx_code code;
01507 {
01508   struct table_elt *p
01509     = lookup (x, safe_hash (x, VOIDmode) & HASH_MASK, GET_MODE (x));
01510 
01511   /* If we are looking for a CONST_INT, the mode doesn't really matter, as
01512      long as we are narrowing.  So if we looked in vain for a mode narrower
01513      than word_mode before, look for word_mode now.  */
01514   if (p == 0 && code == CONST_INT
01515       && GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (word_mode))
01516     {
01517       x = copy_rtx (x);
01518       PUT_MODE (x, word_mode);
01519       p = lookup (x, safe_hash (x, VOIDmode) & HASH_MASK, word_mode);
01520     }
01521 
01522   if (p == 0)
01523     return 0;
01524 
01525   for (p = p->first_same_value; p; p = p->next_same_value)
01526     if (GET_CODE (p->exp) == code
01527   /* Make sure this is a valid entry in the table.  */
01528   && exp_equiv_p (p->exp, p->exp, 1, 0))
01529       return p->exp;
01530 
01531   return 0;
01532 }
01533 
01534 /* Insert X in the hash table, assuming HASH is its hash code
01535    and CLASSP is an element of the class it should go in
01536    (or 0 if a new class should be made).
01537    It is inserted at the proper position to keep the class in
01538    the order cheapest first.
01539 
01540    MODE is the machine-mode of X, or if X is an integer constant
01541    with VOIDmode then MODE is the mode with which X will be used.
01542 
01543    For elements of equal cheapness, the most recent one
01544    goes in front, except that the first element in the list
01545    remains first unless a cheaper element is added.  The order of
01546    pseudo-registers does not matter, as canon_reg will be called to
01547    find the cheapest when a register is retrieved from the table.
01548 
01549    The in_memory field in the hash table element is set to 0.
01550    The caller must set it nonzero if appropriate.
01551 
01552    You should call insert_regs (X, CLASSP, MODIFY) before calling here,
01553    and if insert_regs returns a nonzero value
01554    you must then recompute its hash code before calling here.
01555 
01556    If necessary, update table showing constant values of quantities.  */
01557 
01558 #define CHEAPER(X, Y) \
01559  (preferrable ((X)->cost, (X)->regcost, (Y)->cost, (Y)->regcost) < 0)
01560 
01561 static struct table_elt *
01562 insert (x, classp, hash, mode)
01563      rtx x;
01564      struct table_elt *classp;
01565      unsigned hash;
01566      enum machine_mode mode;
01567 {
01568   struct table_elt *elt;
01569 
01570   /* If X is a register and we haven't made a quantity for it,
01571      something is wrong.  */
01572   if (GET_CODE (x) == REG && ! REGNO_QTY_VALID_P (REGNO (x)))
01573     abort ();
01574 
01575   /* If X is a hard register, show it is being put in the table.  */
01576   if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
01577     {
01578       unsigned int regno = REGNO (x);
01579       unsigned int endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
01580       unsigned int i;
01581 
01582       for (i = regno; i < endregno; i++)
01583   SET_HARD_REG_BIT (hard_regs_in_table, i);
01584     }
01585 
01586   /* Put an element for X into the right hash bucket.  */
01587 
01588   elt = free_element_chain;
01589   if (elt)
01590     free_element_chain = elt->next_same_hash;
01591   else
01592     {
01593       n_elements_made++;
01594       elt = (struct table_elt *) xmalloc (sizeof (struct table_elt));
01595     }
01596 
01597   elt->exp = x;
01598   elt->canon_exp = NULL_RTX;
01599   elt->cost = COST (x);
01600   elt->regcost = approx_reg_cost (x);
01601   elt->next_same_value = 0;
01602   elt->prev_same_value = 0;
01603   elt->next_same_hash = table[hash];
01604   elt->prev_same_hash = 0;
01605   elt->related_value = 0;
01606   elt->in_memory = 0;
01607   elt->mode = mode;
01608   elt->is_const = (CONSTANT_P (x)
01609        /* GNU C++ takes advantage of this for `this'
01610           (and other const values).  */
01611        || (GET_CODE (x) == REG
01612            && RTX_UNCHANGING_P (x)
01613            && REGNO (x) >= FIRST_PSEUDO_REGISTER)
01614        || FIXED_BASE_PLUS_P (x));
01615 
01616   if (table[hash])
01617     table[hash]->prev_same_hash = elt;
01618   table[hash] = elt;
01619 
01620   /* Put it into the proper value-class.  */
01621   if (classp)
01622     {
01623       classp = classp->first_same_value;
01624       if (CHEAPER (elt, classp))
01625   /* Insert at the head of the class */
01626   {
01627     struct table_elt *p;
01628     elt->next_same_value = classp;
01629     classp->prev_same_value = elt;
01630     elt->first_same_value = elt;
01631 
01632     for (p = classp; p; p = p->next_same_value)
01633       p->first_same_value = elt;
01634   }
01635       else
01636   {
01637     /* Insert not at head of the class.  */
01638     /* Put it after the last element cheaper than X.  */
01639     struct table_elt *p, *next;
01640 
01641     for (p = classp; (next = p->next_same_value) && CHEAPER (next, elt);
01642          p = next);
01643 
01644     /* Put it after P and before NEXT.  */
01645     elt->next_same_value = next;
01646     if (next)
01647       next->prev_same_value = elt;
01648 
01649     elt->prev_same_value = p;
01650     p->next_same_value = elt;
01651     elt->first_same_value = classp;
01652   }
01653     }
01654   else
01655     elt->first_same_value = elt;
01656 
01657   /* If this is a constant being set equivalent to a register or a register
01658      being set equivalent to a constant, note the constant equivalence.
01659 
01660      If this is a constant, it cannot be equivalent to a different constant,
01661      and a constant is the only thing that can be cheaper than a register.  So
01662      we know the register is the head of the class (before the constant was
01663      inserted).
01664 
01665      If this is a register that is not already known equivalent to a
01666      constant, we must check the entire class.
01667 
01668      If this is a register that is already known equivalent to an insn,
01669      update the qtys `const_insn' to show that `this_insn' is the latest
01670      insn making that quantity equivalent to the constant.  */
01671 
01672   if (elt->is_const && classp && GET_CODE (classp->exp) == REG
01673       && GET_CODE (x) != REG)
01674     {
01675       int exp_q = REG_QTY (REGNO (classp->exp));
01676       struct qty_table_elem *exp_ent = &qty_table[exp_q];
01677 
01678       exp_ent->const_rtx = gen_lowpart_if_possible (exp_ent->mode, x);
01679       exp_ent->const_insn = this_insn;
01680     }
01681 
01682   else if (GET_CODE (x) == REG
01683      && classp
01684      && ! qty_table[REG_QTY (REGNO (x))].const_rtx
01685      && ! elt->is_const)
01686     {
01687       struct table_elt *p;
01688 
01689       for (p = classp; p != 0; p = p->next_same_value)
01690   {
01691     if (p->is_const && GET_CODE (p->exp) != REG)
01692       {
01693         int x_q = REG_QTY (REGNO (x));
01694         struct qty_table_elem *x_ent = &qty_table[x_q];
01695 
01696         x_ent->const_rtx
01697     = gen_lowpart_if_possible (GET_MODE (x), p->exp);
01698         x_ent->const_insn = this_insn;
01699         break;
01700       }
01701   }
01702     }
01703 
01704   else if (GET_CODE (x) == REG
01705      && qty_table[REG_QTY (REGNO (x))].const_rtx
01706      && GET_MODE (x) == qty_table[REG_QTY (REGNO (x))].mode)
01707     qty_table[REG_QTY (REGNO (x))].const_insn = this_insn;
01708 
01709   /* If this is a constant with symbolic value,
01710      and it has a term with an explicit integer value,
01711      link it up with related expressions.  */
01712   if (GET_CODE (x) == CONST)
01713     {
01714       rtx subexp = get_related_value (x);
01715       unsigned subhash;
01716       struct table_elt *subelt, *subelt_prev;
01717 
01718       if (subexp != 0)
01719   {
01720     /* Get the integer-free subexpression in the hash table.  */
01721     subhash = safe_hash (subexp, mode) & HASH_MASK;
01722     subelt = lookup (subexp, subhash, mode);
01723     if (subelt == 0)
01724       subelt = insert (subexp, NULL, subhash, mode);
01725     /* Initialize SUBELT's circular chain if it has none.  */
01726     if (subelt->related_value == 0)
01727       subelt->related_value = subelt;
01728     /* Find the element in the circular chain that precedes SUBELT.  */
01729     subelt_prev = subelt;
01730     while (subelt_prev->related_value != subelt)
01731       subelt_prev = subelt_prev->related_value;
01732     /* Put new ELT into SUBELT's circular chain just before SUBELT.
01733        This way the element that follows SUBELT is the oldest one.  */
01734     elt->related_value = subelt_prev->related_value;
01735     subelt_prev->related_value = elt;
01736   }
01737     }
01738 
01739   return elt;
01740 }
01741 
01742 /* Given two equivalence classes, CLASS1 and CLASS2, put all the entries from
01743    CLASS2 into CLASS1.  This is done when we have reached an insn which makes
01744    the two classes equivalent.
01745 
01746    CLASS1 will be the surviving class; CLASS2 should not be used after this
01747    call.
01748 
01749    Any invalid entries in CLASS2 will not be copied.  */
01750 
01751 static void
01752 merge_equiv_classes (class1, class2)
01753      struct table_elt *class1, *class2;
01754 {
01755   struct table_elt *elt, *next, *new;
01756 
01757   /* Ensure we start with the head of the classes.  */
01758   class1 = class1->first_same_value;
01759   class2 = class2->first_same_value;
01760 
01761   /* If they were already equal, forget it.  */
01762   if (class1 == class2)
01763     return;
01764 
01765   for (elt = class2; elt; elt = next)
01766     {
01767       unsigned int hash;
01768       rtx exp = elt->exp;
01769       enum machine_mode mode = elt->mode;
01770 
01771       next = elt->next_same_value;
01772 
01773       /* Remove old entry, make a new one in CLASS1's class.
01774    Don't do this for invalid entries as we cannot find their
01775    hash code (it also isn't necessary).  */
01776       if (GET_CODE (exp) == REG || exp_equiv_p (exp, exp, 1, 0))
01777   {
01778     hash_arg_in_memory = 0;
01779     hash = HASH (exp, mode);
01780 
01781     if (GET_CODE (exp) == REG)
01782       delete_reg_equiv (REGNO (exp));
01783 
01784     remove_from_table (elt, hash);
01785 
01786     if (insert_regs (exp, class1, 0))
01787       {
01788         rehash_using_reg (exp);
01789         hash = HASH (exp, mode);
01790       }
01791     new = insert (exp, class1, hash, mode);
01792     new->in_memory = hash_arg_in_memory;
01793   }
01794     }
01795 }
01796 
01797 /* Flush the entire hash table.  */
01798 
01799 static void
01800 flush_hash_table ()
01801 {
01802   int i;
01803   struct table_elt *p;
01804 
01805   for (i = 0; i < HASH_SIZE; i++)
01806     for (p = table[i]; p; p = table[i])
01807       {
01808   /* Note that invalidate can remove elements
01809      after P in the current hash chain.  */
01810   if (GET_CODE (p->exp) == REG)
01811     invalidate (p->exp, p->mode);
01812   else
01813     remove_from_table (p, i);
01814       }
01815 }
01816 
01817 /* Function called for each rtx to check whether true dependence exist.  */
01818 struct check_dependence_data
01819 {
01820   enum machine_mode mode;
01821   rtx exp;
01822 };
01823 
01824 static int
01825 check_dependence (x, data)
01826      rtx *x;
01827      void *data;
01828 {
01829   struct check_dependence_data *d = (struct check_dependence_data *) data;
01830   if (*x && GET_CODE (*x) == MEM)
01831     return true_dependence (d->exp, d->mode, *x, cse_rtx_varies_p);
01832   else
01833     return 0;
01834 }
01835 
01836 /* Remove from the hash table, or mark as invalid, all expressions whose
01837    values could be altered by storing in X.  X is a register, a subreg, or
01838    a memory reference with nonvarying address (because, when a memory
01839    reference with a varying address is stored in, all memory references are
01840    removed by invalidate_memory so specific invalidation is superfluous).
01841    FULL_MODE, if not VOIDmode, indicates that this much should be
01842    invalidated instead of just the amount indicated by the mode of X.  This
01843    is only used for bitfield stores into memory.
01844 
01845    A nonvarying address may be just a register or just a symbol reference,
01846    or it may be either of those plus a numeric offset.  */
01847 
01848 static void
01849 invalidate (x, full_mode)
01850      rtx x;
01851      enum machine_mode full_mode;
01852 {
01853   int i;
01854   struct table_elt *p;
01855 
01856   switch (GET_CODE (x))
01857     {
01858     case REG:
01859       {
01860   /* If X is a register, dependencies on its contents are recorded
01861      through the qty number mechanism.  Just change the qty number of
01862      the register, mark it as invalid for expressions that refer to it,
01863      and remove it itself.  */
01864   unsigned int regno = REGNO (x);
01865   unsigned int hash = HASH (x, GET_MODE (x));
01866 
01867   /* Remove REGNO from any quantity list it might be on and indicate
01868      that its value might have changed.  If it is a pseudo, remove its
01869      entry from the hash table.
01870 
01871      For a hard register, we do the first two actions above for any
01872      additional hard registers corresponding to X.  Then, if any of these
01873      registers are in the table, we must remove any REG entries that
01874      overlap these registers.  */
01875 
01876   delete_reg_equiv (regno);
01877   REG_TICK (regno)++;
01878   SUBREG_TICKED (regno) = -1;
01879 
01880   if (regno >= FIRST_PSEUDO_REGISTER)
01881     {
01882       /* Because a register can be referenced in more than one mode,
01883          we might have to remove more than one table entry.  */
01884       struct table_elt *elt;
01885 
01886       while ((elt = lookup_for_remove (x, hash, GET_MODE (x))))
01887         remove_from_table (elt, hash);
01888     }
01889   else
01890     {
01891       HOST_WIDE_INT in_table
01892         = TEST_HARD_REG_BIT (hard_regs_in_table, regno);
01893       unsigned int endregno
01894         = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
01895       unsigned int tregno, tendregno, rn;
01896       struct table_elt *p, *next;
01897 
01898       CLEAR_HARD_REG_BIT (hard_regs_in_table, regno);
01899 
01900       for (rn = regno + 1; rn < endregno; rn++)
01901         {
01902     in_table |= TEST_HARD_REG_BIT (hard_regs_in_table, rn);
01903     CLEAR_HARD_REG_BIT (hard_regs_in_table, rn);
01904     delete_reg_equiv (rn);
01905     REG_TICK (rn)++;
01906     SUBREG_TICKED (rn) = -1;
01907         }
01908 
01909       if (in_table)
01910         for (hash = 0; hash < HASH_SIZE; hash++)
01911     for (p = table[hash]; p; p = next)
01912       {
01913         next = p->next_same_hash;
01914 
01915         if (GET_CODE (p->exp) != REG
01916       || REGNO (p->exp) >= FIRST_PSEUDO_REGISTER)
01917           continue;
01918 
01919         tregno = REGNO (p->exp);
01920         tendregno
01921           = tregno + HARD_REGNO_NREGS (tregno, GET_MODE (p->exp));
01922         if (tendregno > regno && tregno < endregno)
01923           remove_from_table (p, hash);
01924       }
01925     }
01926       }
01927       return;
01928 
01929     case SUBREG:
01930       invalidate (SUBREG_REG (x), VOIDmode);
01931       return;
01932 
01933     case PARALLEL:
01934       for (i = XVECLEN (x, 0) - 1; i >= 0; --i)
01935   invalidate (XVECEXP (x, 0, i), VOIDmode);
01936       return;
01937 
01938     case EXPR_LIST:
01939       /* This is part of a disjoint return value; extract the location in
01940    question ignoring the offset.  */
01941       invalidate (XEXP (x, 0), VOIDmode);
01942       return;
01943 
01944     case MEM:
01945       /* Calculate the canonical version of X here so that
01946    true_dependence doesn't generate new RTL for X on each call.  */
01947       x = canon_rtx (x);
01948 
01949       /* Remove all hash table elements that refer to overlapping pieces of
01950    memory.  */
01951       if (full_mode == VOIDmode)
01952   full_mode = GET_MODE (x);
01953 
01954       for (i = 0; i < HASH_SIZE; i++)
01955   {
01956     struct table_elt *next;
01957 
01958     for (p = table[i]; p; p = next)
01959       {
01960         next = p->next_same_hash;
01961         if (p->in_memory)
01962     {
01963       struct check_dependence_data d;
01964 
01965       /* Just canonicalize the expression once;
01966          otherwise each time we call invalidate
01967          true_dependence will canonicalize the
01968          expression again.  */
01969       if (!p->canon_exp)
01970         p->canon_exp = canon_rtx (p->exp);
01971       d.exp = x;
01972       d.mode = full_mode;
01973       if (for_each_rtx (&p->canon_exp, check_dependence, &d))
01974         remove_from_table (p, i);
01975     }
01976       }
01977   }
01978       return;
01979 
01980     default:
01981       abort ();
01982     }
01983 }
01984 
01985 /* Remove all expressions that refer to register REGNO,
01986    since they are already invalid, and we are about to
01987    mark that register valid again and don't want the old
01988    expressions to reappear as valid.  */
01989 
01990 static void
01991 remove_invalid_refs (regno)
01992      unsigned int regno;
01993 {
01994   unsigned int i;
01995   struct table_elt *p, *next;
01996 
01997   for (i = 0; i < HASH_SIZE; i++)
01998     for (p = table[i]; p; p = next)
01999       {
02000   next = p->next_same_hash;
02001   if (GET_CODE (p->exp) != REG
02002       && refers_to_regno_p (regno, regno + 1, p->exp, (rtx *) 0))
02003     remove_from_table (p, i);
02004       }
02005 }
02006 
02007 /* Likewise for a subreg with subreg_reg REGNO, subreg_byte OFFSET,
02008    and mode MODE.  */
02009 static void
02010 remove_invalid_subreg_refs (regno, offset, mode)
02011      unsigned int regno;
02012      unsigned int offset;
02013      enum machine_mode mode;
02014 {
02015   unsigned int i;
02016   struct table_elt *p, *next;
02017   unsigned int end = offset + (GET_MODE_SIZE (mode) - 1);
02018 
02019   for (i = 0; i < HASH_SIZE; i++)
02020     for (p = table[i]; p; p = next)
02021       {
02022   rtx exp = p->exp;
02023   next = p->next_same_hash;
02024 
02025   if (GET_CODE (exp) != REG
02026       && (GET_CODE (exp) != SUBREG
02027     || GET_CODE (SUBREG_REG (exp)) != REG
02028     || REGNO (SUBREG_REG (exp)) != regno
02029     || (((SUBREG_BYTE (exp)
02030           + (GET_MODE_SIZE (GET_MODE (exp)) - 1)) >= offset)
02031         && SUBREG_BYTE (exp) <= end))
02032       && refers_to_regno_p (regno, regno + 1, p->exp, (rtx *) 0))
02033     remove_from_table (p, i);
02034       }
02035 }
02036 
02037 /* Recompute the hash codes of any valid entries in the hash table that
02038    reference X, if X is a register, or SUBREG_REG (X) if X is a SUBREG.
02039 
02040    This is called when we make a jump equivalence.  */
02041 
02042 static void
02043 rehash_using_reg (x)
02044      rtx x;
02045 {
02046   unsigned int i;
02047   struct table_elt *p, *next;
02048   unsigned hash;
02049 
02050   if (GET_CODE (x) == SUBREG)
02051     x = SUBREG_REG (x);
02052 
02053   /* If X is not a register or if the register is known not to be in any
02054      valid entries in the table, we have no work to do.  */
02055 
02056   if (GET_CODE (x) != REG
02057       || REG_IN_TABLE (REGNO (x)) < 0
02058       || REG_IN_TABLE (REGNO (x)) != REG_TICK (REGNO (x)))
02059     return;
02060 
02061   /* Scan all hash chains looking for valid entries that mention X.
02062      If we find one and it is in the wrong hash chain, move it.  We can skip
02063      objects that are registers, since they are handled specially.  */
02064 
02065   for (i = 0; i < HASH_SIZE; i++)
02066     for (p = table[i]; p; p = next)
02067       {
02068   next = p->next_same_hash;
02069   if (GET_CODE (p->exp) != REG && reg_mentioned_p (x, p->exp)
02070       && exp_equiv_p (p->exp, p->exp, 1, 0)
02071       && i != (hash = safe_hash (p->exp, p->mode) & HASH_MASK))
02072     {
02073       if (p->next_same_hash)
02074         p->next_same_hash->prev_same_hash = p->prev_same_hash;
02075 
02076       if (p->prev_same_hash)
02077         p->prev_same_hash->next_same_hash = p->next_same_hash;
02078       else
02079         table[i] = p->next_same_hash;
02080 
02081       p->next_same_hash = table[hash];
02082       p->prev_same_hash = 0;
02083       if (table[hash])
02084         table[hash]->prev_same_hash = p;
02085       table[hash] = p;
02086     }
02087       }
02088 }
02089 
02090 /* Remove from the hash table any expression that is a call-clobbered
02091    register.  Also update their TICK values.  */
02092 
02093 static void
02094 invalidate_for_call ()
02095 {
02096   unsigned int regno, endregno;
02097   unsigned int i;
02098   unsigned hash;
02099   struct table_elt *p, *next;
02100   int in_table = 0;
02101 
02102   /* Go through all the hard registers.  For each that is clobbered in
02103      a CALL_INSN, remove the register from quantity chains and update
02104      reg_tick if defined.  Also see if any of these registers is currently
02105      in the table.  */
02106 
02107   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
02108     if (TEST_HARD_REG_BIT (regs_invalidated_by_call, regno))
02109       {
02110   delete_reg_equiv (regno);
02111   if (REG_TICK (regno) >= 0)
02112     {
02113       REG_TICK (regno)++;
02114       SUBREG_TICKED (regno) = -1;
02115     }
02116 
02117   in_table |= (TEST_HARD_REG_BIT (hard_regs_in_table, regno) != 0);
02118       }
02119 
02120   /* In the case where we have no call-clobbered hard registers in the
02121      table, we are done.  Otherwise, scan the table and remove any
02122      entry that overlaps a call-clobbered register.  */
02123 
02124   if (in_table)
02125     for (hash = 0; hash < HASH_SIZE; hash++)
02126       for (p = table[hash]; p; p = next)
02127   {
02128     next = p->next_same_hash;
02129 
02130     if (GET_CODE (p->exp) != REG
02131         || REGNO (p->exp) >= FIRST_PSEUDO_REGISTER)
02132       continue;
02133 
02134     regno = REGNO (p->exp);
02135     endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (p->exp));
02136 
02137     for (i = regno; i < endregno; i++)
02138       if (TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
02139         {
02140     remove_from_table (p, hash);
02141     break;
02142         }
02143   }
02144 }
02145 
02146 /* Given an expression X of type CONST,
02147    and ELT which is its table entry (or 0 if it
02148    is not in the hash table),
02149    return an alternate expression for X as a register plus integer.
02150    If none can be found, return 0.  */
02151 
02152 static rtx
02153 use_related_value (x, elt)
02154      rtx x;
02155      struct table_elt *elt;
02156 {
02157   struct table_elt *relt = 0;
02158   struct table_elt *p, *q;
02159   HOST_WIDE_INT offset;
02160 
02161   /* First, is there anything related known?
02162      If we have a table element, we can tell from that.
02163      Otherwise, must look it up.  */
02164 
02165   if (elt != 0 && elt->related_value != 0)
02166     relt = elt;
02167   else if (elt == 0 && GET_CODE (x) == CONST)
02168     {
02169       rtx subexp = get_related_value (x);
02170       if (subexp != 0)
02171   relt = lookup (subexp,
02172            safe_hash (subexp, GET_MODE (subexp)) & HASH_MASK,
02173            GET_MODE (subexp));
02174     }
02175 
02176   if (relt == 0)
02177     return 0;
02178 
02179   /* Search all related table entries for one that has an
02180      equivalent register.  */
02181 
02182   p = relt;
02183   while (1)
02184     {
02185       /* This loop is strange in that it is executed in two different cases.
02186    The first is when X is already in the table.  Then it is searching
02187    the RELATED_VALUE list of X's class (RELT).  The second case is when
02188    X is not in the table.  Then RELT points to a class for the related
02189    value.
02190 
02191    Ensure that, whatever case we are in, that we ignore classes that have
02192    the same value as X.  */
02193 
02194       if (rtx_equal_p (x, p->exp))
02195   q = 0;
02196       else
02197   for (q = p->first_same_value; q; q = q->next_same_value)
02198     if (GET_CODE (q->exp) == REG)
02199       break;
02200 
02201       if (q)
02202   break;
02203 
02204       p = p->related_value;
02205 
02206       /* We went all the way around, so there is nothing to be found.
02207    Alternatively, perhaps RELT was in the table for some other reason
02208    and it has no related values recorded.  */
02209       if (p == relt || p == 0)
02210   break;
02211     }
02212 
02213   if (q == 0)
02214     return 0;
02215 
02216   offset = (get_integer_term (x) - get_integer_term (p->exp));
02217   /* Note: OFFSET may be 0 if P->xexp and X are related by commutativity.  */
02218   return plus_constant (q->exp, offset);
02219 }
02220 
02221 /* Hash a string.  Just add its bytes up.  */
02222 static inline unsigned
02223 canon_hash_string (ps)
02224      const char *ps;
02225 {
02226   unsigned hash = 0;
02227   const unsigned char *p = (const unsigned char *) ps;
02228 
02229   if (p)
02230     while (*p)
02231       hash += *p++;
02232 
02233   return hash;
02234 }
02235 
02236 /* Hash an rtx.  We are careful to make sure the value is never negative.
02237    Equivalent registers hash identically.
02238    MODE is used in hashing for CONST_INTs only;
02239    otherwise the mode of X is used.
02240 
02241    Store 1 in do_not_record if any subexpression is volatile.
02242 
02243    Store 1 in hash_arg_in_memory if X contains a MEM rtx
02244    which does not have the RTX_UNCHANGING_P bit set.
02245 
02246    Note that cse_insn knows that the hash code of a MEM expression
02247    is just (int) MEM plus the hash code of the address.  */
02248 
02249 static unsigned
02250 canon_hash (x, mode)
02251      rtx x;
02252      enum machine_mode mode;
02253 {
02254   int i, j;
02255   unsigned hash = 0;
02256   enum rtx_code code;
02257   const char *fmt;
02258 
02259   /* repeat is used to turn tail-recursion into iteration.  */
02260  repeat:
02261   if (x == 0)
02262     return hash;
02263 
02264   code = GET_CODE (x);
02265   switch (code)
02266     {
02267     case REG:
02268       {
02269   unsigned int regno = REGNO (x);
02270   bool record;
02271 
02272   /* On some machines, we can't record any non-fixed hard register,
02273      because extending its life will cause reload problems.  We
02274      consider ap, fp, sp, gp to be fixed for this purpose.
02275 
02276      We also consider CCmode registers to be fixed for this purpose;
02277      failure to do so leads to failure to simplify 0<100 type of
02278      conditionals.
02279 
02280      On all machines, we can't record any global registers.
02281      Nor should we record any register that is in a small
02282      class, as defined by CLASS_LIKELY_SPILLED_P.  */
02283 
02284   if (regno >= FIRST_PSEUDO_REGISTER)
02285     record = true;
02286   else if (x == frame_pointer_rtx
02287      || x == hard_frame_pointer_rtx
02288      || x == arg_pointer_rtx
02289      || x == stack_pointer_rtx
02290      || x == pic_offset_table_rtx)
02291     record = true;
02292   else if (global_regs[regno])
02293     record = false;
02294   else if (fixed_regs[regno])
02295     record = true;
02296   else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_CC)
02297     record = true;
02298   else if (SMALL_REGISTER_CLASSES)
02299     record = false;
02300   else if (CLASS_LIKELY_SPILLED_P (REGNO_REG_CLASS (regno)))
02301     record = false;
02302   else
02303     record = true;
02304       
02305   if (!record)
02306     {
02307       do_not_record = 1;
02308       return 0;
02309     }
02310 
02311   hash += ((unsigned) REG << 7) + (unsigned) REG_QTY (regno);
02312   return hash;
02313       }
02314 
02315     /* We handle SUBREG of a REG specially because the underlying
02316        reg changes its hash value with every value change; we don't
02317        want to have to forget unrelated subregs when one subreg changes.  */
02318     case SUBREG:
02319       {
02320   if (GET_CODE (SUBREG_REG (x)) == REG)
02321     {
02322       hash += (((unsigned) SUBREG << 7)
02323          + REGNO (SUBREG_REG (x))
02324          + (SUBREG_BYTE (x) / UNITS_PER_WORD));
02325       return hash;
02326     }
02327   break;
02328       }
02329 
02330     case CONST_INT:
02331       {
02332   unsigned HOST_WIDE_INT tem = INTVAL (x);
02333   hash += ((unsigned) CONST_INT << 7) + (unsigned) mode + tem;
02334   return hash;
02335       }
02336 
02337     case CONST_DOUBLE:
02338       /* This is like the general case, except that it only counts
02339    the integers representing the constant.  */
02340       hash += (unsigned) code + (unsigned) GET_MODE (x);
02341       if (GET_MODE (x) != VOIDmode)
02342   hash += real_hash (CONST_DOUBLE_REAL_VALUE (x));
02343       else
02344   hash += ((unsigned) CONST_DOUBLE_LOW (x)
02345      + (unsigned) CONST_DOUBLE_HIGH (x));
02346       return hash;
02347 
02348     case CONST_VECTOR:
02349       {
02350   int units;
02351   rtx elt;
02352 
02353   units = CONST_VECTOR_NUNITS (x);
02354 
02355   for (i = 0; i < units; ++i)
02356     {
02357       elt = CONST_VECTOR_ELT (x, i);
02358       hash += canon_hash (elt, GET_MODE (elt));
02359     }
02360 
02361   return hash;
02362       }
02363 
02364       /* Assume there is only one rtx object for any given label.  */
02365     case LABEL_REF:
02366       hash += ((unsigned) LABEL_REF << 7) + (unsigned long) XEXP (x, 0);
02367       return hash;
02368 
02369     case SYMBOL_REF:
02370       hash += ((unsigned) SYMBOL_REF << 7) + (unsigned long) XSTR (x, 0);
02371       return hash;
02372 
02373     case MEM:
02374       /* We don't record if marked volatile or if BLKmode since we don't
02375    know the size of the move.  */
02376       if (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode)
02377   {
02378     do_not_record = 1;
02379     return 0;
02380   }
02381       if (! RTX_UNCHANGING_P (x) || FIXED_BASE_PLUS_P (XEXP (x, 0)))
02382   {
02383     hash_arg_in_memory = 1;
02384   }
02385       /* Now that we have already found this special case,
02386    might as well speed it up as much as possible.  */
02387       hash += (unsigned) MEM;
02388       x = XEXP (x, 0);
02389       goto repeat;
02390 
02391     case USE:
02392       /* A USE that mentions non-volatile memory needs special
02393    handling since the MEM may be BLKmode which normally
02394    prevents an entry from being made.  Pure calls are
02395    marked by a USE which mentions BLKmode memory.  */
02396       if (GET_CODE (XEXP (x, 0)) == MEM
02397     && ! MEM_VOLATILE_P (XEXP (x, 0)))
02398   {
02399     hash += (unsigned) USE;
02400     x = XEXP (x, 0);
02401 
02402     if (! RTX_UNCHANGING_P (x) || FIXED_BASE_PLUS_P (XEXP (x, 0)))
02403       hash_arg_in_memory = 1;
02404 
02405     /* Now that we have already found this special case,
02406        might as well speed it up as much as possible.  */
02407     hash += (unsigned) MEM;
02408     x = XEXP (x, 0);
02409     goto repeat;
02410   }
02411       break;
02412 
02413     case PRE_DEC:
02414     case PRE_INC:
02415     case POST_DEC:
02416     case POST_INC:
02417     case PRE_MODIFY:
02418     case POST_MODIFY:
02419     case PC:
02420     case CC0:
02421     case CALL:
02422     case UNSPEC_VOLATILE:
02423       do_not_record = 1;
02424       return 0;
02425 
02426     case ASM_OPERANDS:
02427       if (MEM_VOLATILE_P (x))
02428   {
02429     do_not_record = 1;
02430     return 0;
02431   }
02432       else
02433   {
02434     /* We don't want to take the filename and line into account.  */
02435     hash += (unsigned) code + (unsigned) GET_MODE (x)
02436       + canon_hash_string (ASM_OPERANDS_TEMPLATE (x))
02437       + canon_hash_string (ASM_OPERANDS_OUTPUT_CONSTRAINT (x))
02438       + (unsigned) ASM_OPERANDS_OUTPUT_IDX (x);
02439 
02440     if (ASM_OPERANDS_INPUT_LENGTH (x))
02441       {
02442         for (i = 1; i < ASM_OPERANDS_INPUT_LENGTH (x); i++)
02443     {
02444       hash += (canon_hash (ASM_OPERANDS_INPUT (x, i),
02445                GET_MODE (ASM_OPERANDS_INPUT (x, i)))
02446          + canon_hash_string (ASM_OPERANDS_INPUT_CONSTRAINT
02447             (x, i)));
02448     }
02449 
02450         hash += canon_hash_string (ASM_OPERANDS_INPUT_CONSTRAINT (x, 0));
02451         x = ASM_OPERANDS_INPUT (x, 0);
02452         mode = GET_MODE (x);
02453         goto repeat;
02454       }
02455 
02456     return hash;
02457   }
02458       break;
02459 
02460     default:
02461       break;
02462     }
02463 
02464   i = GET_RTX_LENGTH (code) - 1;
02465   hash += (unsigned) code + (unsigned) GET_MODE (x);
02466   fmt = GET_RTX_FORMAT (code);
02467   for (; i >= 0; i--)
02468     {
02469       if (fmt[i] == 'e')
02470   {
02471     rtx tem = XEXP (x, i);
02472 
02473     /* If we are about to do the last recursive call
02474        needed at this level, change it into iteration.
02475        This function  is called enough to be worth it.  */
02476     if (i == 0)
02477       {
02478         x = tem;
02479         goto repeat;
02480       }
02481     hash += canon_hash (tem, 0);
02482   }
02483       else if (fmt[i] == 'E')
02484   for (j = 0; j < XVECLEN (x, i); j++)
02485     hash += canon_hash (XVECEXP (x, i, j), 0);
02486       else if (fmt[i] == 's')
02487   hash += canon_hash_string (XSTR (x, i));
02488       else if (fmt[i] == 'i')
02489   {
02490     unsigned tem = XINT (x, i);
02491     hash += tem;
02492   }
02493       else if (fmt[i] == '0' || fmt[i] == 't')
02494   /* Unused.  */
02495   ;
02496       else
02497   abort ();
02498     }
02499   return hash;
02500 }
02501 
02502 /* Like canon_hash but with no side effects.  */
02503 
02504 static unsigned
02505 safe_hash (x, mode)
02506      rtx x;
02507      enum machine_mode mode;
02508 {
02509   int save_do_not_record = do_not_record;
02510   int save_hash_arg_in_memory = hash_arg_in_memory;
02511   unsigned hash = canon_hash (x, mode);
02512   hash_arg_in_memory = save_hash_arg_in_memory;
02513   do_not_record = save_do_not_record;
02514   return hash;
02515 }
02516 
02517 /* Return 1 iff X and Y would canonicalize into the same thing,
02518    without actually constructing the canonicalization of either one.
02519    If VALIDATE is nonzero,
02520    we assume X is an expression being processed from the rtl
02521    and Y was found in the hash table.  We check register refs
02522    in Y for being marked as valid.
02523 
02524    If EQUAL_VALUES is nonzero, we allow a register to match a constant value
02525    that is known to be in the register.  Ordinarily, we don't allow them
02526    to match, because letting them match would cause unpredictable results
02527    in all the places that search a hash table chain for an equivalent
02528    for a given value.  A possible equivalent that has different structure
02529    has its hash code computed from different data.  Whether the hash code
02530    is the same as that of the given value is pure luck.  */
02531 
02532 static int
02533 exp_equiv_p (x, y, validate, equal_values)
02534      rtx x, y;
02535      int validate;
02536      int equal_values;
02537 {
02538   int i, j;
02539   enum rtx_code code;
02540   const char *fmt;
02541 
02542   /* Note: it is incorrect to assume an expression is equivalent to itself
02543      if VALIDATE is nonzero.  */
02544   if (x == y && !validate)
02545     return 1;
02546   if (x == 0 || y == 0)
02547     return x == y;
02548 
02549   code = GET_CODE (x);
02550   if (code != GET_CODE (y))
02551     {
02552       if (!equal_values)
02553   return 0;
02554 
02555       /* If X is a constant and Y is a register or vice versa, they may be
02556    equivalent.  We only have to validate if Y is a register.  */
02557       if (CONSTANT_P (x) && GET_CODE (y) == REG
02558     && REGNO_QTY_VALID_P (REGNO (y)))
02559   {
02560     int y_q = REG_QTY (REGNO (y));
02561     struct qty_table_elem *y_ent = &qty_table[y_q];
02562 
02563     if (GET_MODE (y) == y_ent->mode
02564         && rtx_equal_p (x, y_ent->const_rtx)
02565         && (! validate || REG_IN_TABLE (REGNO (y)) == REG_TICK (REGNO (y))))
02566       return 1;
02567   }
02568 
02569       if (CONSTANT_P (y) && code == REG
02570     && REGNO_QTY_VALID_P (REGNO (x)))
02571   {
02572     int x_q = REG_QTY (REGNO (x));
02573     struct qty_table_elem *x_ent = &qty_table[x_q];
02574 
02575     if (GET_MODE (x) == x_ent->mode
02576         && rtx_equal_p (y, x_ent->const_rtx))
02577       return 1;
02578   }
02579 
02580       return 0;
02581     }
02582 
02583   /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.  */
02584   if (GET_MODE (x) != GET_MODE (y))
02585     return 0;
02586 
02587   switch (code)
02588     {
02589     case PC:
02590     case CC0:
02591     case CONST_INT:
02592       return x == y;
02593 
02594     case LABEL_REF:
02595       return XEXP (x, 0) == XEXP (y, 0);
02596 
02597     case SYMBOL_REF:
02598       return XSTR (x, 0) == XSTR (y, 0);
02599 
02600     case REG:
02601       {
02602   unsigned int regno = REGNO (y);
02603   unsigned int endregno
02604     = regno + (regno >= FIRST_PSEUDO_REGISTER ? 1
02605          : HARD_REGNO_NREGS (regno, GET_MODE (y)));
02606   unsigned int i;
02607 
02608   /* If the quantities are not the same, the expressions are not
02609      equivalent.  If there are and we are not to validate, they
02610      are equivalent.  Otherwise, ensure all regs are up-to-date.  */
02611 
02612   if (REG_QTY (REGNO (x)) != REG_QTY (regno))
02613     return 0;
02614 
02615   if (! validate)
02616     return 1;
02617 
02618   for (i = regno; i < endregno; i++)
02619     if (REG_IN_TABLE (i) != REG_TICK (i))
02620       return 0;
02621 
02622   return 1;
02623       }
02624 
02625     /*  For commutative operations, check both orders.  */
02626     case PLUS:
02627     case MULT:
02628     case AND:
02629     case IOR:
02630     case XOR:
02631     case NE:
02632     case EQ:
02633       return ((exp_equiv_p (XEXP (x, 0), XEXP (y, 0), validate, equal_values)
02634          && exp_equiv_p (XEXP (x, 1), XEXP (y, 1),
02635              validate, equal_values))
02636         || (exp_equiv_p (XEXP (x, 0), XEXP (y, 1),
02637              validate, equal_values)
02638       && exp_equiv_p (XEXP (x, 1), XEXP (y, 0),
02639           validate, equal_values)));
02640 
02641     case ASM_OPERANDS:
02642       /* We don't use the generic code below because we want to
02643    disregard filename and line numbers.  */
02644 
02645       /* A volatile asm isn't equivalent to any other.  */
02646       if (MEM_VOLATILE_P (x) || MEM_VOLATILE_P (y))
02647   return 0;
02648 
02649       if (GET_MODE (x) != GET_MODE (y)
02650     || strcmp (ASM_OPERANDS_TEMPLATE (x), ASM_OPERANDS_TEMPLATE (y))
02651     || strcmp (ASM_OPERANDS_OUTPUT_CONSTRAINT (x),
02652          ASM_OPERANDS_OUTPUT_CONSTRAINT (y))
02653     || ASM_OPERANDS_OUTPUT_IDX (x) != ASM_OPERANDS_OUTPUT_IDX (y)
02654     || ASM_OPERANDS_INPUT_LENGTH (x) != ASM_OPERANDS_INPUT_LENGTH (y))
02655   return 0;
02656 
02657       if (ASM_OPERANDS_INPUT_LENGTH (x))
02658   {
02659     for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
02660       if (! exp_equiv_p (ASM_OPERANDS_INPUT (x, i),
02661              ASM_OPERANDS_INPUT (y, i),
02662              validate, equal_values)
02663     || strcmp (ASM_OPERANDS_INPUT_CONSTRAINT (x, i),
02664          ASM_OPERANDS_INPUT_CONSTRAINT (y, i)))
02665         return 0;
02666   }
02667 
02668       return 1;
02669 
02670     default:
02671       break;
02672     }
02673 
02674   /* Compare the elements.  If any pair of corresponding elements
02675      fail to match, return 0 for the whole things.  */
02676 
02677   fmt = GET_RTX_FORMAT (code);
02678   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
02679     {
02680       switch (fmt[i])
02681   {
02682   case 'e':
02683     if (! exp_equiv_p (XEXP (x, i), XEXP (y, i), validate, equal_values))
02684       return 0;
02685     break;
02686 
02687   case 'E':
02688     if (XVECLEN (x, i) != XVECLEN (y, i))
02689       return 0;
02690     for (j = 0; j < XVECLEN (x, i); j++)
02691       if (! exp_equiv_p (XVECEXP (x, i, j), XVECEXP (y, i, j),
02692              validate, equal_values))
02693         return 0;
02694     break;
02695 
02696   case 's':
02697     if (strcmp (XSTR (x, i), XSTR (y, i)))
02698       return 0;
02699     break;
02700 
02701   case 'i':
02702     if (XINT (x, i) != XINT (y, i))
02703       return 0;
02704     break;
02705 
02706   case 'w':
02707     if (XWINT (x, i) != XWINT (y, i))
02708       return 0;
02709     break;
02710 
02711   case '0':
02712   case 't':
02713     break;
02714 
02715   default:
02716     abort ();
02717   }
02718     }
02719 
02720   return 1;
02721 }
02722 
02723 /* Return 1 if X has a value that can vary even between two
02724    executions of the program.  0 means X can be compared reliably
02725    against certain constants or near-constants.  */
02726 
02727 static int
02728 cse_rtx_varies_p (x, from_alias)
02729      rtx x;
02730      int from_alias;
02731 {
02732   /* We need not check for X and the equivalence class being of the same
02733      mode because if X is equivalent to a constant in some mode, it
02734      doesn't vary in any mode.  */
02735 
02736   if (GET_CODE (x) == REG
02737       && REGNO_QTY_VALID_P (REGNO (x)))
02738     {
02739       int x_q = REG_QTY (REGNO (x));
02740       struct qty_table_elem *x_ent = &qty_table[x_q];
02741 
02742       if (GET_MODE (x) == x_ent->mode
02743     && x_ent->const_rtx != NULL_RTX)
02744   return 0;
02745     }
02746 
02747   if (GET_CODE (x) == PLUS
02748       && GET_CODE (XEXP (x, 1)) == CONST_INT
02749       && GET_CODE (XEXP (x, 0)) == REG
02750       && REGNO_QTY_VALID_P (REGNO (XEXP (x, 0))))
02751     {
02752       int x0_q = REG_QTY (REGNO (XEXP (x, 0)));
02753       struct qty_table_elem *x0_ent = &qty_table[x0_q];
02754 
02755       if ((GET_MODE (XEXP (x, 0)) == x0_ent->mode)
02756     && x0_ent->const_rtx != NULL_RTX)
02757   return 0;
02758     }
02759 
02760   /* This can happen as the result of virtual register instantiation, if
02761      the initial constant is too large to be a valid address.  This gives
02762      us a three instruction sequence, load large offset into a register,
02763      load fp minus a constant into a register, then a MEM which is the
02764      sum of the two `constant' registers.  */
02765   if (GET_CODE (x) == PLUS
02766       && GET_CODE (XEXP (x, 0)) == REG
02767       && GET_CODE (XEXP (x, 1)) == REG
02768       && REGNO_QTY_VALID_P (REGNO (XEXP (x, 0)))
02769       && REGNO_QTY_VALID_P (REGNO (XEXP (x, 1))))
02770     {
02771       int x0_q = REG_QTY (REGNO (XEXP (x, 0)));
02772       int x1_q = REG_QTY (REGNO (XEXP (x, 1)));
02773       struct qty_table_elem *x0_ent = &qty_table[x0_q];
02774       struct qty_table_elem *x1_ent = &qty_table[x1_q];
02775 
02776       if ((GET_MODE (XEXP (x, 0)) == x0_ent->mode)
02777     && x0_ent->const_rtx != NULL_RTX
02778     && (GET_MODE (XEXP (x, 1)) == x1_ent->mode)
02779     && x1_ent->const_rtx != NULL_RTX)
02780   return 0;
02781     }
02782 
02783   return rtx_varies_p (x, from_alias);
02784 }
02785 
02786 /* Canonicalize an expression:
02787    replace each register reference inside it
02788    with the "oldest" equivalent register.
02789 
02790    If INSN is nonzero and we are replacing a pseudo with a hard register
02791    or vice versa, validate_change is used to ensure that INSN remains valid
02792    after we make our substitution.  The calls are made with IN_GROUP nonzero
02793    so apply_change_group must be called upon the outermost return from this
02794    function (unless INSN is zero).  The result of apply_change_group can
02795    generally be discarded since the changes we are making are optional.  */
02796 
02797 static rtx
02798 canon_reg (x, insn)
02799      rtx x;
02800      rtx insn;
02801 {
02802   int i;
02803   enum rtx_code code;
02804   const char *fmt;
02805 
02806   if (x == 0)
02807     return x;
02808 
02809   code = GET_CODE (x);
02810   switch (code)
02811     {
02812     case PC:
02813     case CC0:
02814     case CONST:
02815     case CONST_INT:
02816     case CONST_DOUBLE:
02817     case CONST_VECTOR:
02818     case SYMBOL_REF:
02819     case LABEL_REF:
02820     case ADDR_VEC:
02821     case ADDR_DIFF_VEC:
02822       return x;
02823 
02824     case REG:
02825       {
02826   int first;
02827   int q;
02828   struct qty_table_elem *ent;
02829 
02830   /* Never replace a hard reg, because hard regs can appear
02831      in more than one machine mode, and we must preserve the mode
02832      of each occurrence.  Also, some hard regs appear in
02833      MEMs that are shared and mustn't be altered.  Don't try to
02834      replace any reg that maps to a reg of class NO_REGS.  */
02835   if (REGNO (x) < FIRST_PSEUDO_REGISTER
02836       || ! REGNO_QTY_VALID_P (REGNO (x)))
02837     return x;
02838 
02839   q = REG_QTY (REGNO (x));
02840   ent = &qty_table[q];
02841   first = ent->first_reg;
02842   return (first >= FIRST_PSEUDO_REGISTER ? regno_reg_rtx[first]
02843     : REGNO_REG_CLASS (first) == NO_REGS ? x
02844     : gen_rtx_REG (ent->mode, first));
02845       }
02846 
02847     default:
02848       break;
02849     }
02850 
02851   fmt = GET_RTX_FORMAT (code);
02852   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
02853     {
02854       int j;
02855 
02856       if (fmt[i] == 'e')
02857   {
02858     rtx new = canon_reg (XEXP (x, i), insn);
02859     int insn_code;
02860 
02861     /* If replacing pseudo with hard reg or vice versa, ensure the
02862        insn remains valid.  Likewise if the insn has MATCH_DUPs.  */
02863     if (insn != 0 && new != 0
02864         && GET_CODE (new) == REG && GET_CODE (XEXP (x, i)) == REG
02865         && (((REGNO (new) < FIRST_PSEUDO_REGISTER)
02866        != (REGNO (XEXP (x, i)) < FIRST_PSEUDO_REGISTER))
02867       || (insn_code = recog_memoized (insn)) < 0
02868       || insn_data[insn_code].n_dups > 0))
02869       validate_change (insn, &XEXP (x, i), new, 1);
02870     else
02871       XEXP (x, i) = new;
02872   }
02873       else if (fmt[i] == 'E')
02874   for (j = 0; j < XVECLEN (x, i); j++)
02875     XVECEXP (x, i, j) = canon_reg (XVECEXP (x, i, j), insn);
02876     }
02877 
02878   return x;
02879 }
02880 
02881 /* LOC is a location within INSN that is an operand address (the contents of
02882    a MEM).  Find the best equivalent address to use that is valid for this
02883    insn.
02884 
02885    On most CISC machines, complicated address modes are costly, and rtx_cost
02886    is a good approximation for that cost.  However, most RISC machines have
02887    only a few (usually only one) memory reference formats.  If an address is
02888    valid at all, it is often just as cheap as any other address.  Hence, for
02889    RISC machines, we use the configuration macro `ADDRESS_COST' to compare the
02890    costs of various addresses.  For two addresses of equal cost, choose the one
02891    with the highest `rtx_cost' value as that has the potential of eliminating
02892    the most insns.  For equal costs, we choose the first in the equivalence
02893    class.  Note that we ignore the fact that pseudo registers are cheaper
02894    than hard registers here because we would also prefer the pseudo registers.
02895   */
02896 
02897 static void
02898 find_best_addr (insn, loc, mode)
02899      rtx insn;
02900      rtx *loc;
02901      enum machine_mode mode;
02902 {
02903   struct table_elt *elt;
02904   rtx addr = *loc;
02905 #ifdef ADDRESS_COST
02906   struct table_elt *p;
02907   int found_better = 1;
02908 #endif
02909   int save_do_not_record = do_not_record;
02910   int save_hash_arg_in_memory = hash_arg_in_memory;
02911   int addr_volatile;
02912   int regno;
02913   unsigned hash;
02914 
02915   /* Do not try to replace constant addresses or addresses of local and
02916      argument slots.  These MEM expressions are made only once and inserted
02917      in many instructions, as well as being used to control symbol table
02918      output.  It is not safe to clobber them.
02919 
02920      There are some uncommon cases where the address is already in a register
02921      for some reason, but we cannot take advantage of that because we have
02922      no easy way to unshare the MEM.  In addition, looking up all stack
02923      addresses is costly.  */
02924   if ((GET_CODE (addr) == PLUS
02925        && GET_CODE (XEXP (addr, 0)) == REG
02926        && GET_CODE (XEXP (addr, 1)) == CONST_INT
02927        && (regno = REGNO (XEXP (addr, 0)),
02928      regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM
02929      || regno == ARG_POINTER_REGNUM))
02930       || (GET_CODE (addr) == REG
02931     && (regno = REGNO (addr), regno == FRAME_POINTER_REGNUM
02932         || regno == HARD_FRAME_POINTER_REGNUM
02933         || regno == ARG_POINTER_REGNUM))
02934       || GET_CODE (addr) == ADDRESSOF
02935       || CONSTANT_ADDRESS_P (addr))
02936     return;
02937 
02938   /* If this address is not simply a register, try to fold it.  This will
02939      sometimes simplify the expression.  Many simplifications
02940      will not be valid, but some, usually applying the associative rule, will
02941      be valid and produce better code.  */
02942   if (GET_CODE (addr) != REG)
02943     {
02944       rtx folded = fold_rtx (copy_rtx (addr), NULL_RTX);
02945       int addr_folded_cost = address_cost (folded, mode);
02946       int addr_cost = address_cost (addr, mode);
02947 
02948       if ((addr_folded_cost < addr_cost
02949      || (addr_folded_cost == addr_cost
02950          /* ??? The rtx_cost comparison is left over from an older
02951       version of this code.  It is probably no longer helpful.  */
02952          && (rtx_cost (folded, MEM) > rtx_cost (addr, MEM)
02953        || approx_reg_cost (folded) < approx_reg_cost (addr))))
02954     && validate_change (insn, loc, folded, 0))
02955   addr = folded;
02956     }
02957 
02958   /* If this address is not in the hash table, we can't look for equivalences
02959      of the whole address.  Also, ignore if volatile.  */
02960 
02961   do_not_record = 0;
02962   hash = HASH (addr, Pmode);
02963   addr_volatile = do_not_record;
02964   do_not_record = save_do_not_record;
02965   hash_arg_in_memory = save_hash_arg_in_memory;
02966 
02967   if (addr_volatile)
02968     return;
02969 
02970   elt = lookup (addr, hash, Pmode);
02971 
02972 #ifndef ADDRESS_COST
02973   if (elt)
02974     {
02975       int our_cost = elt->cost;
02976 
02977       /* Find the lowest cost below ours that works.  */
02978       for (elt = elt->first_same_value; elt; elt = elt->next_same_value)
02979   if (elt->cost < our_cost
02980       && (GET_CODE (elt->exp) == REG
02981     || exp_equiv_p (elt->exp, elt->exp, 1, 0))
02982       && validate_change (insn, loc,
02983         canon_reg (copy_rtx (elt->exp), NULL_RTX), 0))
02984     return;
02985     }
02986 #else
02987 
02988   if (elt)
02989     {
02990       /* We need to find the best (under the criteria documented above) entry
02991    in the class that is valid.  We use the `flag' field to indicate
02992    choices that were invalid and iterate until we can't find a better
02993    one that hasn't already been tried.  */
02994 
02995       for (p = elt->first_same_value; p; p = p->next_same_value)
02996   p->flag = 0;
02997 
02998       while (found_better)
02999   {
03000     int best_addr_cost = address_cost (*loc, mode);
03001     int best_rtx_cost = (elt->cost + 1) >> 1;
03002     int exp_cost;
03003     struct table_elt *best_elt = elt;
03004 
03005     found_better = 0;
03006     for (p = elt->first_same_value; p; p = p->next_same_value)
03007       if (! p->flag)
03008         {
03009     if ((GET_CODE (p->exp) == REG
03010          || exp_equiv_p (p->exp, p->exp, 1, 0))
03011         && ((exp_cost = address_cost (p->exp, mode)) < best_addr_cost
03012       || (exp_cost == best_addr_cost
03013           && ((p->cost + 1) >> 1) > best_rtx_cost)))
03014       {
03015         found_better = 1;
03016         best_addr_cost = exp_cost;
03017         best_rtx_cost = (p->cost + 1) >> 1;
03018         best_elt = p;
03019       }
03020         }
03021 
03022     if (found_better)
03023       {
03024         if (validate_change (insn, loc,
03025            canon_reg (copy_rtx (best_elt->exp),
03026                 NULL_RTX), 0))
03027     return;
03028         else
03029     best_elt->flag = 1;
03030       }
03031   }
03032     }
03033 
03034   /* If the address is a binary operation with the first operand a register
03035      and the second a constant, do the same as above, but looking for
03036      equivalences of the register.  Then try to simplify before checking for
03037      the best address to use.  This catches a few cases:  First is when we
03038      have REG+const and the register is another REG+const.  We can often merge
03039      the constants and eliminate one insn and one register.  It may also be
03040      that a machine has a cheap REG+REG+const.  Finally, this improves the
03041      code on the Alpha for unaligned byte stores.  */
03042 
03043   if (flag_expensive_optimizations
03044       && (GET_RTX_CLASS (GET_CODE (*loc)) == '2'
03045     || GET_RTX_CLASS (GET_CODE (*loc)) == 'c')
03046       && GET_CODE (XEXP (*loc, 0)) == REG)
03047     {
03048       rtx op1 = XEXP (*loc, 1);
03049 
03050       do_not_record = 0;
03051       hash = HASH (XEXP (*loc, 0), Pmode);
03052       do_not_record = save_do_not_record;
03053       hash_arg_in_memory = save_hash_arg_in_memory;
03054 
03055       elt = lookup (XEXP (*loc, 0), hash, Pmode);
03056       if (elt == 0)
03057   return;
03058 
03059       /* We need to find the best (under the criteria documented above) entry
03060    in the class that is valid.  We use the `flag' field to indicate
03061    choices that were invalid and iterate until we can't find a better
03062    one that hasn't already been tried.  */
03063 
03064       for (p = elt->first_same_value; p; p = p->next_same_value)
03065   p->flag = 0;
03066 
03067       while (found_better)
03068   {
03069     int best_addr_cost = address_cost (*loc, mode);
03070     int best_rtx_cost = (COST (*loc) + 1) >> 1;
03071     struct table_elt *best_elt = elt;
03072     rtx best_rtx = *loc;
03073     int count;
03074 
03075     /* This is at worst case an O(n^2) algorithm, so limit our search
03076        to the first 32 elements on the list.  This avoids trouble
03077        compiling code with very long basic blocks that can easily
03078        call simplify_gen_binary so many times that we run out of
03079        memory.  */
03080 
03081     found_better = 0;
03082     for (p = elt->first_same_value, count = 0;
03083          p && count < 32;
03084          p = p->next_same_value, count++)
03085       if (! p->flag
03086     && (GET_CODE (p->exp) == REG
03087         || exp_equiv_p (p->exp, p->exp, 1, 0)))
03088         {
03089     rtx new = simplify_gen_binary (GET_CODE (*loc), Pmode,
03090                  p->exp, op1);
03091     int new_cost;
03092     new_cost = address_cost (new, mode);
03093 
03094     if (new_cost < best_addr_cost
03095         || (new_cost == best_addr_cost
03096       && (COST (new) + 1) >> 1 > best_rtx_cost))
03097       {
03098         found_better = 1;
03099         best_addr_cost = new_cost;
03100         best_rtx_cost = (COST (new) + 1) >> 1;
03101         best_elt = p;
03102         best_rtx = new;
03103       }
03104         }
03105 
03106     if (found_better)
03107       {
03108         if (validate_change (insn, loc,
03109            canon_reg (copy_rtx (best_rtx),
03110                 NULL_RTX), 0))
03111     return;
03112         else
03113     best_elt->flag = 1;
03114       }
03115   }
03116     }
03117 #endif
03118 }
03119 
03120 /* Given an operation (CODE, *PARG1, *PARG2), where code is a comparison
03121    operation (EQ, NE, GT, etc.), follow it back through the hash table and
03122    what values are being compared.
03123 
03124    *PARG1 and *PARG2 are updated to contain the rtx representing the values
03125    actually being compared.  For example, if *PARG1 was (cc0) and *PARG2
03126    was (const_int 0), *PARG1 and *PARG2 will be set to the objects that were
03127    compared to produce cc0.
03128 
03129    The return value is the comparison operator and is either the code of
03130    A or the code corresponding to the inverse of the comparison.  */
03131 
03132 static enum rtx_code
03133 find_comparison_args (code, parg1, parg2, pmode1, pmode2)
03134      enum rtx_code code;
03135      rtx *parg1, *parg2;
03136      enum machine_mode *pmode1, *pmode2;
03137 {
03138   rtx arg1, arg2;
03139 
03140   arg1 = *parg1, arg2 = *parg2;
03141 
03142   /* If ARG2 is const0_rtx, see what ARG1 is equivalent to.  */
03143 
03144   while (arg2 == CONST0_RTX (GET_MODE (arg1)))
03145     {
03146       /* Set nonzero when we find something of interest.  */
03147       rtx x = 0;
03148       int reverse_code = 0;
03149       struct table_elt *p = 0;
03150 
03151       /* If arg1 is a COMPARE, extract the comparison arguments from it.
03152    On machines with CC0, this is the only case that can occur, since
03153    fold_rtx will return the COMPARE or item being compared with zero
03154    when given CC0.  */
03155 
03156       if (GET_CODE (arg1) == COMPARE && arg2 == const0_rtx)
03157   x = arg1;
03158 
03159       /* If ARG1 is a comparison operator and CODE is testing for
03160    STORE_FLAG_VALUE, get the inner arguments.  */
03161 
03162       else if (GET_RTX_CLASS (GET_CODE (arg1)) == '<')
03163   {
03164 #ifdef FLOAT_STORE_FLAG_VALUE
03165     REAL_VALUE_TYPE fsfv;
03166 #endif
03167 
03168     if (code == NE
03169         || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_INT
03170       && code == LT && STORE_FLAG_VALUE == -1)
03171 #ifdef FLOAT_STORE_FLAG_VALUE
03172         || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_FLOAT
03173       && (fsfv = FLOAT_STORE_FLAG_VALUE (GET_MODE (arg1)),
03174           REAL_VALUE_NEGATIVE (fsfv)))
03175 #endif
03176         )
03177       x = arg1;
03178     else if (code == EQ
03179        || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_INT
03180            && code == GE && STORE_FLAG_VALUE == -1)
03181 #ifdef FLOAT_STORE_FLAG_VALUE
03182        || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_FLOAT
03183            && (fsfv = FLOAT_STORE_FLAG_VALUE (GET_MODE (arg1)),
03184          REAL_VALUE_NEGATIVE (fsfv)))
03185 #endif
03186        )
03187       x = arg1, reverse_code = 1;
03188   }
03189 
03190       /* ??? We could also check for
03191 
03192    (ne (and (eq (...) (const_int 1))) (const_int 0))
03193 
03194    and related forms, but let's wait until we see them occurring.  */
03195 
03196       if (x == 0)
03197   /* Look up ARG1 in the hash table and see if it has an equivalence
03198      that lets us see what is being compared.  */
03199   p = lookup (arg1, safe_hash (arg1, GET_MODE (arg1)) & HASH_MASK,
03200         GET_MODE (arg1));
03201       if (p)
03202   {
03203     p = p->first_same_value;
03204 
03205     /* If what we compare is already known to be constant, that is as
03206        good as it gets.
03207        We need to break the loop in this case, because otherwise we
03208        can have an infinite loop when looking at a reg that is known
03209        to be a constant which is the same as a comparison of a reg
03210        against zero which appears later in the insn stream, which in
03211        turn is constant and the same as the comparison of the first reg
03212        against zero...  */
03213     if (p->is_const)
03214       break;
03215   }
03216 
03217       for (; p; p = p->next_same_value)
03218   {
03219     enum machine_mode inner_mode = GET_MODE (p->exp);
03220 #ifdef FLOAT_STORE_FLAG_VALUE
03221     REAL_VALUE_TYPE fsfv;
03222 #endif
03223 
03224     /* If the entry isn't valid, skip it.  */
03225     if (! exp_equiv_p (p->exp, p->exp, 1, 0))
03226       continue;
03227 
03228     if (GET_CODE (p->exp) == COMPARE
03229         /* Another possibility is that this machine has a compare insn
03230      that includes the comparison code.  In that case, ARG1 would
03231      be equivalent to a comparison operation that would set ARG1 to
03232      either STORE_FLAG_VALUE or zero.  If this is an NE operation,
03233      ORIG_CODE is the actual comparison being done; if it is an EQ,
03234      we must reverse ORIG_CODE.  On machine with a negative value
03235      for STORE_FLAG_VALUE, also look at LT and GE operations.  */
03236         || ((code == NE
03237        || (code == LT
03238            && GET_MODE_CLASS (inner_mode) == MODE_INT
03239            && (GET_MODE_BITSIZE (inner_mode)
03240          <= HOST_BITS_PER_WIDE_INT)
03241            && (STORE_FLAG_VALUE
03242          & ((HOST_WIDE_INT) 1
03243             << (GET_MODE_BITSIZE (inner_mode) - 1))))
03244 #ifdef FLOAT_STORE_FLAG_VALUE
03245        || (code == LT
03246            && GET_MODE_CLASS (inner_mode) == MODE_FLOAT
03247            && (fsfv = FLOAT_STORE_FLAG_VALUE (GET_MODE (arg1)),
03248          REAL_VALUE_NEGATIVE (fsfv)))
03249 #endif
03250        )
03251       && GET_RTX_CLASS (GET_CODE (p->exp)) == '<'))
03252       {
03253         x = p->exp;
03254         break;
03255       }
03256     else if ((code == EQ
03257         || (code == GE
03258       && GET_MODE_CLASS (inner_mode) == MODE_INT
03259       && (GET_MODE_BITSIZE (inner_mode)
03260           <= HOST_BITS_PER_WIDE_INT)
03261       && (STORE_FLAG_VALUE
03262           & ((HOST_WIDE_INT) 1
03263              << (GET_MODE_BITSIZE (inner_mode) - 1))))
03264 #ifdef FLOAT_STORE_FLAG_VALUE
03265         || (code == GE
03266       && GET_MODE_CLASS (inner_mode) == MODE_FLOAT
03267       && (fsfv = FLOAT_STORE_FLAG_VALUE (GET_MODE (arg1)),
03268           REAL_VALUE_NEGATIVE (fsfv)))
03269 #endif
03270         )
03271        && GET_RTX_CLASS (GET_CODE (p->exp)) == '<')
03272       {
03273         reverse_code = 1;
03274         x = p->exp;
03275         break;
03276       }
03277 
03278     /* If this is fp + constant, the equivalent is a better operand since
03279        it may let us predict the value of the comparison.  */
03280     else if (NONZERO_BASE_PLUS_P (p->exp))
03281       {
03282         arg1 = p->exp;
03283         continue;
03284       }
03285   }
03286 
03287       /* If we didn't find a useful equivalence for ARG1, we are done.
03288    Otherwise, set up for the next iteration.  */
03289       if (x == 0)
03290   break;
03291 
03292       /* If we need to reverse the comparison, make sure that that is
03293    possible -- we can't necessarily infer the value of GE from LT
03294    with floating-point operands.  */
03295       if (reverse_code)
03296   {
03297     enum rtx_code reversed = reversed_comparison_code (x, NULL_RTX);
03298     if (reversed == UNKNOWN)
03299       break;
03300     else
03301       code = reversed;
03302   }
03303       else if (GET_RTX_CLASS (GET_CODE (x)) == '<')
03304   code = GET_CODE (x);
03305       arg1 = XEXP (x, 0), arg2 = XEXP (x, 1);
03306     }
03307 
03308   /* Return our results.  Return the modes from before fold_rtx
03309      because fold_rtx might produce const_int, and then it's too late.  */
03310   *pmode1 = GET_MODE (arg1), *pmode2 = GET_MODE (arg2);
03311   *parg1 = fold_rtx (arg1, 0), *parg2 = fold_rtx (arg2, 0);
03312 
03313   return code;
03314 }
03315 
03316 /* If X is a nontrivial arithmetic operation on an argument
03317    for which a constant value can be determined, return
03318    the result of operating on that value, as a constant.
03319    Otherwise, return X, possibly with one or more operands
03320    modified by recursive calls to this function.
03321 
03322    If X is a register whose contents are known, we do NOT
03323    return those contents here.  equiv_constant is called to
03324    perform that task.
03325 
03326    INSN is the insn that we may be modifying.  If it is 0, make a copy
03327    of X before modifying it.  */
03328 
03329 static rtx
03330 fold_rtx (x, insn)
03331      rtx x;
03332      rtx insn;
03333 {
03334   enum rtx_code code;
03335   enum machine_mode mode;
03336   const char *fmt;
03337   int i;
03338   rtx new = 0;
03339   int copied = 0;
03340   int must_swap = 0;
03341 
03342   /* Folded equivalents of first two operands of X.  */
03343   rtx folded_arg0;
03344   rtx folded_arg1;
03345 
03346   /* Constant equivalents of first three operands of X;
03347      0 when no such equivalent is known.  */
03348   rtx const_arg0;
03349   rtx const_arg1;
03350   rtx const_arg2;
03351 
03352   /* The mode of the first operand of X.  We need this for sign and zero
03353      extends.  */
03354   enum machine_mode mode_arg0;
03355 
03356   if (x == 0)
03357     return x;
03358 
03359   mode = GET_MODE (x);
03360   code = GET_CODE (x);
03361   switch (code)
03362     {
03363     case CONST:
03364     case CONST_INT:
03365     case CONST_DOUBLE:
03366     case CONST_VECTOR:
03367     case SYMBOL_REF:
03368     case LABEL_REF:
03369     case REG:
03370       /* No use simplifying an EXPR_LIST
03371    since they are used only for lists of args
03372    in a function call's REG_EQUAL note.  */
03373     case EXPR_LIST:
03374       /* Changing anything inside an ADDRESSOF is incorrect; we don't
03375    want to (e.g.,) make (addressof (const_int 0)) just because
03376    the location is known to be zero.  */
03377     case ADDRESSOF:
03378       return x;
03379 
03380 #ifdef HAVE_cc0
03381     case CC0:
03382       return prev_insn_cc0;
03383 #endif
03384 
03385     case PC:
03386       /* If the next insn is a CODE_LABEL followed by a jump table,
03387    PC's value is a LABEL_REF pointing to that label.  That
03388    lets us fold switch statements on the VAX.  */
03389       if (insn && GET_CODE (insn) == JUMP_INSN)
03390   {
03391     rtx next = next_nonnote_insn (insn);
03392 
03393     if (next && GET_CODE (next) == CODE_LABEL
03394         && NEXT_INSN (next) != 0
03395         && GET_CODE (NEXT_INSN (next)) == JUMP_INSN
03396         && (GET_CODE (PATTERN (NEXT_INSN (next))) == ADDR_VEC
03397       || GET_CODE (PATTERN (NEXT_INSN (next))) == ADDR_DIFF_VEC))
03398       return gen_rtx_LABEL_REF (Pmode, next);
03399   }
03400       break;
03401 
03402     case SUBREG:
03403       /* See if we previously assigned a constant value to this SUBREG.  */
03404       if ((new = lookup_as_function (x, CONST_INT)) != 0
03405     || (new = lookup_as_function (x, CONST_DOUBLE)) != 0)
03406   return new;
03407 
03408       /* If this is a paradoxical SUBREG, we have no idea what value the
03409    extra bits would have.  However, if the operand is equivalent
03410    to a SUBREG whose operand is the same as our mode, and all the
03411    modes are within a word, we can just use the inner operand
03412    because these SUBREGs just say how to treat the register.
03413 
03414    Similarly if we find an integer constant.  */
03415 
03416       if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
03417   {
03418     enum machine_mode imode = GET_MODE (SUBREG_REG (x));
03419     struct table_elt *elt;
03420 
03421     if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
03422         && GET_MODE_SIZE (imode) <= UNITS_PER_WORD
03423         && (elt = lookup (SUBREG_REG (x), HASH (SUBREG_REG (x), imode),
03424         imode)) != 0)
03425       for (elt = elt->first_same_value; elt; elt = elt->next_same_value)
03426         {
03427     if (CONSTANT_P (elt->exp)
03428         && GET_MODE (elt->exp) == VOIDmode)
03429       return elt->exp;
03430 
03431     if (GET_CODE (elt->exp) == SUBREG
03432         && GET_MODE (SUBREG_REG (elt->exp)) == mode
03433         && exp_equiv_p (elt->exp, elt->exp, 1, 0))
03434       return copy_rtx (SUBREG_REG (elt->exp));
03435         }
03436 
03437     return x;
03438   }
03439 
03440       /* Fold SUBREG_REG.  If it changed, see if we can simplify the SUBREG.
03441    We might be able to if the SUBREG is extracting a single word in an
03442    integral mode or extracting the low part.  */
03443 
03444       folded_arg0 = fold_rtx (SUBREG_REG (x), insn);
03445       const_arg0 = equiv_constant (folded_arg0);
03446       if (const_arg0)
03447   folded_arg0 = const_arg0;
03448 
03449       if (folded_arg0 != SUBREG_REG (x))
03450   {
03451     new = simplify_subreg (mode, folded_arg0,
03452          GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
03453     if (new)
03454       return new;
03455   }
03456 
03457       /* If this is a narrowing SUBREG and our operand is a REG, see if
03458    we can find an equivalence for REG that is an arithmetic operation
03459    in a wider mode where both operands are paradoxical SUBREGs
03460    from objects of our result mode.  In that case, we couldn't report
03461    an equivalent value for that operation, since we don't know what the
03462    extra bits will be.  But we can find an equivalence for this SUBREG
03463    by folding that operation is the narrow mode.  This allows us to
03464    fold arithmetic in narrow modes when the machine only supports
03465    word-sized arithmetic.
03466 
03467    Also look for a case where we have a SUBREG whose operand is the
03468    same as our result.  If both modes are smaller than a word, we
03469    are simply interpreting a register in different modes and we
03470    can use the inner value.  */
03471 
03472       if (GET_CODE (folded_arg0) == REG
03473     && GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (folded_arg0))
03474     && subreg_lowpart_p (x))
03475   {
03476     struct table_elt *elt;
03477 
03478     /* We can use HASH here since we know that canon_hash won't be
03479        called.  */
03480     elt = lookup (folded_arg0,
03481       HASH (folded_arg0, GET_MODE (folded_arg0)),
03482       GET_MODE (folded_arg0));
03483 
03484     if (elt)
03485       elt = elt->first_same_value;
03486 
03487     for (; elt; elt = elt->next_same_value)
03488       {
03489         enum rtx_code eltcode = GET_CODE (elt->exp);
03490 
03491         /* Just check for unary and binary operations.  */
03492         if (GET_RTX_CLASS (GET_CODE (elt->exp)) == '1'
03493       && GET_CODE (elt->exp) != SIGN_EXTEND
03494       && GET_CODE (elt->exp) != ZERO_EXTEND
03495       && GET_CODE (XEXP (elt->exp, 0)) == SUBREG
03496       && GET_MODE (SUBREG_REG (XEXP (elt->exp, 0))) == mode
03497       && (GET_MODE_CLASS (mode)
03498           == GET_MODE_CLASS (GET_MODE (XEXP (elt->exp, 0)))))
03499     {
03500       rtx op0 = SUBREG_REG (XEXP (elt->exp, 0));
03501 
03502       if (GET_CODE (op0) != REG && ! CONSTANT_P (op0))
03503         op0 = fold_rtx (op0, NULL_RTX);
03504 
03505       op0 = equiv_constant (op0);
03506       if (op0)
03507         new = simplify_unary_operation (GET_CODE (elt->exp), mode,
03508                 op0, mode);
03509     }
03510         else if ((GET_RTX_CLASS (GET_CODE (elt->exp)) == '2'
03511       || GET_RTX_CLASS (GET_CODE (elt->exp)) == 'c')
03512            && eltcode != DIV && eltcode != MOD
03513            && eltcode != UDIV && eltcode != UMOD
03514            && eltcode != ASHIFTRT && eltcode != LSHIFTRT
03515            && eltcode != ROTATE && eltcode != ROTATERT
03516            && ((GET_CODE (XEXP (elt->exp, 0)) == SUBREG
03517           && (GET_MODE (SUBREG_REG (XEXP (elt->exp, 0)))
03518         == mode))
03519          || CONSTANT_P (XEXP (elt->exp, 0)))
03520            && ((GET_CODE (XEXP (elt->exp, 1)) == SUBREG
03521           && (GET_MODE (SUBREG_REG (XEXP (elt->exp, 1)))
03522         == mode))
03523          || CONSTANT_P (XEXP (elt->exp, 1))))
03524     {
03525       rtx op0 = gen_lowpart_common (mode, XEXP (elt->exp, 0));
03526       rtx op1 = gen_lowpart_common (mode, XEXP (elt->exp, 1));
03527 
03528       if (op0 && GET_CODE (op0) != REG && ! CONSTANT_P (op0))
03529         op0 = fold_rtx (op0, NULL_RTX);
03530 
03531       if (op0)
03532         op0 = equiv_constant (op0);
03533 
03534       if (op1 && GET_CODE (op1) != REG && ! CONSTANT_P (op1))
03535         op1 = fold_rtx (op1, NULL_RTX);
03536 
03537       if (op1)
03538         op1 = equiv_constant (op1);
03539 
03540       /* If we are looking for the low SImode part of
03541          (ashift:DI c (const_int 32)), it doesn't work
03542          to compute that in SImode, because a 32-bit shift
03543          in SImode is unpredictable.  We know the value is 0.  */
03544       if (op0 && op1
03545           && GET_CODE (elt->exp) == ASHIFT
03546           && GET_CODE (op1) == CONST_INT
03547           && INTVAL (op1) >= GET_MODE_BITSIZE (mode))
03548         {
03549           if (INTVAL (op1) < GET_MODE_BITSIZE (GET_MODE (elt->exp)))
03550 
03551       /* If the count fits in the inner mode's width,
03552          but exceeds the outer mode's width,
03553          the value will get truncated to 0
03554          by the subreg.  */
03555       new = const0_rtx;
03556           else
03557       /* If the count exceeds even the inner mode's width,
03558          don't fold this expression.  */
03559       new = 0;
03560         }
03561       else if (op0 && op1)
03562         new = simplify_binary_operation (GET_CODE (elt->exp), mode,
03563                  op0, op1);
03564     }
03565 
03566         else if (GET_CODE (elt->exp) == SUBREG
03567            && GET_MODE (SUBREG_REG (elt->exp)) == mode
03568            && (GET_MODE_SIZE (GET_MODE (folded_arg0))
03569          <= UNITS_PER_WORD)
03570            && exp_equiv_p (elt->exp, elt->exp, 1, 0))
03571     new = copy_rtx (SUBREG_REG (elt->exp));
03572 
03573         if (new)
03574     return new;
03575       }
03576   }
03577 
03578       return x;
03579 
03580     case NOT:
03581     case NEG:
03582       /* If we have (NOT Y), see if Y is known to be (NOT Z).
03583    If so, (NOT Y) simplifies to Z.  Similarly for NEG.  */
03584       new = lookup_as_function (XEXP (x, 0), code);
03585       if (new)
03586   return fold_rtx (copy_rtx (XEXP (new, 0)), insn);
03587       break;
03588 
03589     case MEM:
03590       /* If we are not actually processing an insn, don't try to find the
03591    best address.  Not only don't we care, but we could modify the
03592    MEM in an invalid way since we have no insn to validate against.  */
03593       if (insn != 0)
03594   find_best_addr (insn, &XEXP (x, 0), GET_MODE (x));
03595 
03596       {
03597   /* Even if we don't fold in the insn itself,
03598      we can safely do so here, in hopes of getting a constant.  */
03599   rtx addr = fold_rtx (XEXP (x, 0), NULL_RTX);
03600   rtx base = 0;
03601   HOST_WIDE_INT offset = 0;
03602 
03603   if (GET_CODE (addr) == REG
03604       && REGNO_QTY_VALID_P (REGNO (addr)))
03605     {
03606       int addr_q = REG_QTY (REGNO (addr));
03607       struct qty_table_elem *addr_ent = &qty_table[addr_q];
03608 
03609       if (GET_MODE (addr) == addr_ent->mode
03610     && addr_ent->const_rtx != NULL_RTX)
03611         addr = addr_ent->const_rtx;
03612     }
03613 
03614   /* If address is constant, split it into a base and integer offset.  */
03615   if (GET_CODE (addr) == SYMBOL_REF || GET_CODE (addr) == LABEL_REF)
03616     base = addr;
03617   else if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS
03618      && GET_CODE (XEXP (XEXP (addr, 0), 1)) == CONST_INT)
03619     {
03620       base = XEXP (XEXP (addr, 0), 0);
03621       offset = INTVAL (XEXP (XEXP (addr, 0), 1));
03622     }
03623   else if (GET_CODE (addr) == LO_SUM
03624      && GET_CODE (XEXP (addr, 1)) == SYMBOL_REF)
03625     base = XEXP (addr, 1);
03626   else if (GET_CODE (addr) == ADDRESSOF)
03627     return change_address (x, VOIDmode, addr);
03628 
03629   /* If this is a constant pool reference, we can fold it into its
03630      constant to allow better value tracking.  */
03631   if (base && GET_CODE (base) == SYMBOL_REF
03632       && CONSTANT_POOL_ADDRESS_P (base))
03633     {
03634       rtx constant = get_pool_constant (base);
03635       enum machine_mode const_mode = get_pool_mode (base);
03636       rtx new;
03637 
03638       if (CONSTANT_P (constant) && GET_CODE (constant) != CONST_INT)
03639         constant_pool_entries_cost = COST (constant);
03640 
03641       /* If we are loading the full constant, we have an equivalence.  */
03642       if (offset == 0 && mode == const_mode)
03643         return constant;
03644 
03645       /* If this actually isn't a constant (weird!), we can't do
03646          anything.  Otherwise, handle the two most common cases:
03647          extracting a word from a multi-word constant, and extracting
03648          the low-order bits.  Other cases don't seem common enough to
03649          worry about.  */
03650       if (! CONSTANT_P (constant))
03651         return x;
03652 
03653       if (GET_MODE_CLASS (mode) == MODE_INT
03654     && GET_MODE_SIZE (mode) == UNITS_PER_WORD
03655     && offset % UNITS_PER_WORD == 0
03656     && (new = operand_subword (constant,
03657              offset / UNITS_PER_WORD,
03658              0, const_mode)) != 0)
03659         return new;
03660 
03661       if (((BYTES_BIG_ENDIAN
03662       && offset == GET_MODE_SIZE (GET_MODE (constant)) - 1)
03663      || (! BYTES_BIG_ENDIAN && offset == 0))
03664     && (new = gen_lowpart_if_possible (mode, constant)) != 0)
03665         return new;
03666     }
03667 
03668   /* If this is a reference to a label at a known position in a jump
03669      table, we also know its value.  */
03670   if (base && GET_CODE (base) == LABEL_REF)
03671     {
03672       rtx label = XEXP (base, 0);
03673       rtx table_insn = NEXT_INSN (label);
03674 
03675       if (table_insn && GET_CODE (table_insn) == JUMP_INSN
03676     && GET_CODE (PATTERN (table_insn)) == ADDR_VEC)
03677         {
03678     rtx table = PATTERN (table_insn);
03679 
03680     if (offset >= 0
03681         && (offset / GET_MODE_SIZE (GET_MODE (table))
03682       < XVECLEN (table, 0)))
03683       return XVECEXP (table, 0,
03684           offset / GET_MODE_SIZE (GET_MODE (table)));
03685         }
03686       if (table_insn && GET_CODE (table_insn) == JUMP_INSN
03687     && GET_CODE (PATTERN (table_insn)) == ADDR_DIFF_VEC)
03688         {
03689     rtx table = PATTERN (table_insn);
03690 
03691     if (offset >= 0
03692         && (offset / GET_MODE_SIZE (GET_MODE (table))
03693       < XVECLEN (table, 1)))
03694       {
03695         offset /= GET_MODE_SIZE (GET_MODE (table));
03696         new = gen_rtx_MINUS (Pmode, XVECEXP (table, 1, offset),
03697            XEXP (table, 0));
03698 
03699         if (GET_MODE (table) != Pmode)
03700           new = gen_rtx_TRUNCATE (GET_MODE (table), new);
03701 
03702         /* Indicate this is a constant.  This isn't a
03703            valid form of CONST, but it will only be used
03704            to fold the next insns and then discarded, so
03705            it should be safe.
03706 
03707            Note this expression must be explicitly discarded,
03708            by cse_insn, else it may end up in a REG_EQUAL note
03709            and "escape" to cause problems elsewhere.  */
03710         return gen_rtx_CONST (GET_MODE (new), new);
03711       }
03712         }
03713     }
03714 
03715   return x;
03716       }
03717 
03718 #ifdef NO_FUNCTION_CSE
03719     case CALL:
03720       if (CONSTANT_P (XEXP (XEXP (x, 0), 0)))
03721   return x;
03722       break;
03723 #endif
03724 
03725     case ASM_OPERANDS:
03726       for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
03727   validate_change (insn, &ASM_OPERANDS_INPUT (x, i),
03728        fold_rtx (ASM_OPERANDS_INPUT (x, i), insn), 0);
03729       break;
03730 
03731     default:
03732       break;
03733     }
03734 
03735   const_arg0 = 0;
03736   const_arg1 = 0;
03737   const_arg2 = 0;
03738   mode_arg0 = VOIDmode;
03739 
03740   /* Try folding our operands.
03741      Then see which ones have constant values known.  */
03742 
03743   fmt = GET_RTX_FORMAT (code);
03744   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
03745     if (fmt[i] == 'e')
03746       {
03747   rtx arg = XEXP (x, i);
03748   rtx folded_arg = arg, const_arg = 0;
03749   enum machine_mode mode_arg = GET_MODE (arg);
03750   rtx cheap_arg, expensive_arg;
03751   rtx replacements[2];
03752   int j;
03753   int old_cost = COST_IN (XEXP (x, i), code);
03754 
03755   /* Most arguments are cheap, so handle them specially.  */
03756   switch (GET_CODE (arg))
03757     {
03758     case REG:
03759       /* This is the same as calling equiv_constant; it is duplicated
03760          here for speed.  */
03761       if (REGNO_QTY_VALID_P (REGNO (arg)))
03762         {
03763     int arg_q = REG_QTY (REGNO (arg));
03764     struct qty_table_elem *arg_ent = &qty_table[arg_q];
03765 
03766     if (arg_ent->const_rtx != NULL_RTX
03767         && GET_CODE (arg_ent->const_rtx) != REG
03768         && GET_CODE (arg_ent->const_rtx) != PLUS)
03769       const_arg
03770         = gen_lowpart_if_possible (GET_MODE (arg),
03771                  arg_ent->const_rtx);
03772         }
03773       break;
03774 
03775     case CONST:
03776     case CONST_INT:
03777     case SYMBOL_REF:
03778     case LABEL_REF:
03779     case CONST_DOUBLE:
03780     case CONST_VECTOR:
03781       const_arg = arg;
03782       break;
03783 
03784 #ifdef HAVE_cc0
03785     case CC0:
03786       folded_arg = prev_insn_cc0;
03787       mode_arg = prev_insn_cc0_mode;
03788       const_arg = equiv_constant (folded_arg);
03789       break;
03790 #endif
03791 
03792     default:
03793       folded_arg = fold_rtx (arg, insn);
03794       const_arg = equiv_constant (folded_arg);
03795     }
03796 
03797   /* For the first three operands, see if the operand
03798      is constant or equivalent to a constant.  */
03799   switch (i)
03800     {
03801     case 0:
03802       folded_arg0 = folded_arg;
03803       const_arg0 = const_arg;
03804       mode_arg0 = mode_arg;
03805       break;
03806     case 1:
03807       folded_arg1 = folded_arg;
03808       const_arg1 = const_arg;
03809       break;
03810     case 2:
03811       const_arg2 = const_arg;
03812       break;
03813     }
03814 
03815   /* Pick the least expensive of the folded argument and an
03816      equivalent constant argument.  */
03817   if (const_arg == 0 || const_arg == folded_arg
03818       || COST_IN (const_arg, code) > COST_IN (folded_arg, code))
03819     cheap_arg = folded_arg, expensive_arg = const_arg;
03820   else
03821     cheap_arg = const_arg, expensive_arg = folded_arg;
03822 
03823   /* Try to replace the operand with the cheapest of the two
03824      possibilities.  If it doesn't work and this is either of the first
03825      two operands of a commutative operation, try swapping them.
03826      If THAT fails, try the more expensive, provided it is cheaper
03827      than what is already there.  */
03828 
03829   if (cheap_arg == XEXP (x, i))
03830     continue;
03831 
03832   if (insn == 0 && ! copied)
03833     {
03834       x = copy_rtx (x);
03835       copied = 1;
03836     }
03837 
03838   /* Order the replacements from cheapest to most expensive.  */
03839   replacements[0] = cheap_arg;
03840   replacements[1] = expensive_arg;
03841 
03842   for (j = 0; j < 2 && replacements[j]; j++)
03843     {
03844       int new_cost = COST_IN (replacements[j], code);
03845 
03846       /* Stop if what existed before was cheaper.  Prefer constants
03847          in the case of a tie.  */
03848       if (new_cost > old_cost
03849     || (new_cost == old_cost && CONSTANT_P (XEXP (x, i))))
03850         break;
03851 
03852       if (validate_change (insn, &XEXP (x, i), replacements[j], 0))
03853         break;
03854 
03855       if (code == NE || code == EQ || GET_RTX_CLASS (code) == 'c'
03856     || code == LTGT || code == UNEQ || code == ORDERED
03857     || code == UNORDERED)
03858         {
03859     validate_change (insn, &XEXP (x, i), XEXP (x, 1 - i), 1);
03860     validate_change (insn, &XEXP (x, 1 - i), replacements[j], 1);
03861 
03862     if (apply_change_group ())
03863       {
03864         /* Swap them back to be invalid so that this loop can
03865            continue and flag them to be swapped back later.  */
03866         rtx tem;
03867 
03868         tem = XEXP (x, 0); XEXP (x, 0) = XEXP (x, 1);
03869                XEXP (x, 1) = tem;
03870         must_swap = 1;
03871         break;
03872       }
03873         }
03874     }
03875       }
03876 
03877     else
03878       {
03879   if (fmt[i] == 'E')
03880     /* Don't try to fold inside of a vector of expressions.
03881        Doing nothing is harmless.  */
03882     {;}
03883       }
03884 
03885   /* If a commutative operation, place a constant integer as the second
03886      operand unless the first operand is also a constant integer.  Otherwise,
03887      place any constant second unless the first operand is also a constant.  */
03888 
03889   if (code == EQ || code == NE || GET_RTX_CLASS (code) == 'c'
03890       || code == LTGT || code == UNEQ || code == ORDERED
03891       || code == UNORDERED)
03892     {
03893       if (must_swap || (const_arg0
03894         && (const_arg1 == 0
03895                 || (GET_CODE (const_arg0) == CONST_INT
03896               && GET_CODE (const_arg1) != CONST_INT))))
03897   {
03898     rtx tem = XEXP (x, 0);
03899 
03900     if (insn == 0 && ! copied)
03901       {
03902         x = copy_rtx (x);
03903         copied = 1;
03904       }
03905 
03906     validate_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
03907     validate_change (insn, &XEXP (x, 1), tem, 1);
03908     if (apply_change_group ())
03909       {
03910         tem = const_arg0, const_arg0 = const_arg1, const_arg1 = tem;
03911         tem = folded_arg0, folded_arg0 = folded_arg1, folded_arg1 = tem;
03912       }
03913   }
03914     }
03915 
03916   /* If X is an arithmetic operation, see if we can simplify it.  */
03917 
03918   switch (GET_RTX_CLASS (code))
03919     {
03920     case '1':
03921       {
03922   int is_const = 0;
03923 
03924   /* We can't simplify extension ops unless we know the
03925      original mode.  */
03926   if ((code == ZERO_EXTEND || code == SIGN_EXTEND)
03927       && mode_arg0 == VOIDmode)
03928     break;
03929 
03930   /* If we had a CONST, strip it off and put it back later if we
03931      fold.  */
03932   if (const_arg0 != 0 && GET_CODE (const_arg0) == CONST)
03933     is_const = 1, const_arg0 = XEXP (const_arg0, 0);
03934 
03935   new = simplify_unary_operation (code, mode,
03936           const_arg0 ? const_arg0 : folded_arg0,
03937           mode_arg0);
03938   if (new != 0 && is_const)
03939     new = gen_rtx_CONST (mode, new);
03940       }
03941       break;
03942 
03943     case '<':
03944       /* See what items are actually being compared and set FOLDED_ARG[01]
03945    to those values and CODE to the actual comparison code.  If any are
03946    constant, set CONST_ARG0 and CONST_ARG1 appropriately.  We needn't
03947    do anything if both operands are already known to be constant.  */
03948 
03949       if (const_arg0 == 0 || const_arg1 == 0)
03950   {
03951     struct table_elt *p0, *p1;
03952     rtx true_rtx = const_true_rtx, false_rtx = const0_rtx;
03953     enum machine_mode mode_arg1;
03954 
03955 #ifdef FLOAT_STORE_FLAG_VALUE
03956     if (GET_MODE_CLASS (mode) == MODE_FLOAT)
03957       {
03958         true_rtx = (CONST_DOUBLE_FROM_REAL_VALUE
03959         (FLOAT_STORE_FLAG_VALUE (mode), mode));
03960         false_rtx = CONST0_RTX (mode);
03961       }
03962 #endif
03963 
03964     code = find_comparison_args (code, &folded_arg0, &folded_arg1,
03965                &mode_arg0, &mode_arg1);
03966     const_arg0 = equiv_constant (folded_arg0);
03967     const_arg1 = equiv_constant (folded_arg1);
03968 
03969     /* If the mode is VOIDmode or a MODE_CC mode, we don't know
03970        what kinds of things are being compared, so we can't do
03971        anything with this comparison.  */
03972 
03973     if (mode_arg0 == VOIDmode || GET_MODE_CLASS (mode_arg0) == MODE_CC)
03974       break;
03975 
03976     /* If we do not now have two constants being compared, see
03977        if we can nevertheless deduce some things about the
03978        comparison.  */
03979     if (const_arg0 == 0 || const_arg1 == 0)
03980       {
03981         /* Is FOLDED_ARG0 frame-pointer plus a constant?  Or
03982      non-explicit constant?  These aren't zero, but we
03983      don't know their sign.  */
03984         if (const_arg1 == const0_rtx
03985       && (NONZERO_BASE_PLUS_P (folded_arg0)
03986 #if 0  /* Sad to say, on sysvr4, #pragma weak can make a symbol address
03987     come out as 0.  */
03988           || GET_CODE (folded_arg0) == SYMBOL_REF
03989 #endif
03990           || GET_CODE (folded_arg0) == LABEL_REF
03991           || GET_CODE (folded_arg0) == CONST))
03992     {
03993       if (code == EQ)
03994         return false_rtx;
03995       else if (code == NE)
03996         return true_rtx;
03997     }
03998 
03999         /* See if the two operands are the same.  */
04000 
04001         if (folded_arg0 == folded_arg1
04002       || (GET_CODE (folded_arg0) == REG
04003           && GET_CODE (folded_arg1) == REG
04004           && (REG_QTY (REGNO (folded_arg0))
04005         == REG_QTY (REGNO (folded_arg1))))
04006       || ((p0 = lookup (folded_arg0,
04007             (safe_hash (folded_arg0, mode_arg0)
04008              & HASH_MASK), mode_arg0))
04009           && (p1 = lookup (folded_arg1,
04010                (safe_hash (folded_arg1, mode_arg0)
04011           & HASH_MASK), mode_arg0))
04012           && p0->first_same_value == p1->first_same_value))
04013     {
04014       /* Sadly two equal NaNs are not equivalent.  */
04015       if (!HONOR_NANS (mode_arg0))
04016         return ((code == EQ || code == LE || code == GE
04017            || code == LEU || code == GEU || code == UNEQ
04018            || code == UNLE || code == UNGE
04019            || code == ORDERED)
04020           ? true_rtx : false_rtx);
04021       /* Take care for the FP compares we can resolve.  */
04022       if (code == UNEQ || code == UNLE || code == UNGE)
04023         return true_rtx;
04024       if (code == LTGT || code == LT || code == GT)
04025         return false_rtx;
04026     }
04027 
04028         /* If FOLDED_ARG0 is a register, see if the comparison we are
04029      doing now is either the same as we did before or the reverse
04030      (we only check the reverse if not floating-point).  */
04031         else if (GET_CODE (folded_arg0) == REG)
04032     {
04033       int qty = REG_QTY (REGNO (folded_arg0));
04034 
04035       if (REGNO_QTY_VALID_P (REGNO (folded_arg0)))
04036         {
04037           struct qty_table_elem *ent = &qty_table[qty];
04038 
04039           if ((comparison_dominates_p (ent->comparison_code, code)
04040          || (! FLOAT_MODE_P (mode_arg0)
04041              && comparison_dominates_p (ent->comparison_code,
04042                       reverse_condition (code))))
04043         && (rtx_equal_p (ent->comparison_const, folded_arg1)
04044             || (const_arg1
04045           && rtx_equal_p (ent->comparison_const,
04046               const_arg1))
04047             || (GET_CODE (folded_arg1) == REG
04048           && (REG_QTY (REGNO (folded_arg1)) == ent->comparison_qty))))
04049       return (comparison_dominates_p (ent->comparison_code, code)
04050         ? true_rtx : false_rtx);
04051         }
04052     }
04053       }
04054   }
04055 
04056       /* If we are comparing against zero, see if the first operand is
04057    equivalent to an IOR with a constant.  If so, we may be able to
04058    determine the result of this comparison.  */
04059 
04060       if (const_arg1 == const0_rtx)
04061   {
04062     rtx y = lookup_as_function (folded_arg0, IOR);
04063     rtx inner_const;
04064 
04065     if (y != 0
04066         && (inner_const = equiv_constant (XEXP (y, 1))) != 0
04067         && GET_CODE (inner_const) == CONST_INT
04068         && INTVAL (inner_const) != 0)
04069       {
04070         int sign_bitnum = GET_MODE_BITSIZE (mode_arg0) - 1;
04071         int has_sign = (HOST_BITS_PER_WIDE_INT >= sign_bitnum
04072             && (INTVAL (inner_const)
04073           & ((HOST_WIDE_INT) 1 << sign_bitnum)));
04074         rtx true_rtx = const_true_rtx, false_rtx = const0_rtx;
04075 
04076 #ifdef FLOAT_STORE_FLAG_VALUE
04077         if (GET_MODE_CLASS (mode) == MODE_FLOAT)
04078     {
04079       true_rtx = (CONST_DOUBLE_FROM_REAL_VALUE
04080         (FLOAT_STORE_FLAG_VALUE (mode), mode));
04081       false_rtx = CONST0_RTX (mode);
04082     }
04083 #endif
04084 
04085         switch (code)
04086     {
04087     case EQ:
04088       return false_rtx;
04089     case NE:
04090       return true_rtx;
04091     case LT:  case LE:
04092       if (has_sign)
04093         return true_rtx;
04094       break;
04095     case GT:  case GE:
04096       if (has_sign)
04097         return false_rtx;
04098       break;
04099     default:
04100       break;
04101     }
04102       }
04103   }
04104 
04105       new = simplify_relational_operation (code,
04106              (mode_arg0 != VOIDmode
04107               ? mode_arg0
04108               : (GET_MODE (const_arg0
04109                ? const_arg0
04110                : folded_arg0)
04111                  != VOIDmode)
04112               ? GET_MODE (const_arg0
04113               ? const_arg0
04114               : folded_arg0)
04115               : GET_MODE (const_arg1
04116               ? const_arg1
04117               : folded_arg1)),
04118              const_arg0 ? const_arg0 : folded_arg0,
04119              const_arg1 ? const_arg1 : folded_arg1);
04120 #ifdef FLOAT_STORE_FLAG_VALUE
04121       if (new != 0 && GET_MODE_CLASS (mode) == MODE_FLOAT)
04122   {
04123     if (new == const0_rtx)
04124       new = CONST0_RTX (mode);
04125     else
04126       new = (CONST_DOUBLE_FROM_REAL_VALUE
04127        (FLOAT_STORE_FLAG_VALUE (mode), mode));
04128   }
04129 #endif
04130       break;
04131 
04132     case '2':
04133     case 'c':
04134       switch (code)
04135   {
04136   case PLUS:
04137     /* If the second operand is a LABEL_REF, see if the first is a MINUS
04138        with that LABEL_REF as its second operand.  If so, the result is
04139        the first operand of that MINUS.  This handles switches with an
04140        ADDR_DIFF_VEC table.  */
04141     if (const_arg1 && GET_CODE (const_arg1) == LABEL_REF)
04142       {
04143         rtx y
04144     = GET_CODE (folded_arg0) == MINUS ? folded_arg0
04145     : lookup_as_function (folded_arg0, MINUS);
04146 
04147         if (y != 0 && GET_CODE (XEXP (y, 1)) == LABEL_REF
04148       && XEXP (XEXP (y, 1), 0) == XEXP (const_arg1, 0))
04149     return XEXP (y, 0);
04150 
04151         /* Now try for a CONST of a MINUS like the above.  */
04152         if ((y = (GET_CODE (folded_arg0) == CONST ? folded_arg0
04153       : lookup_as_function (folded_arg0, CONST))) != 0
04154       && GET_CODE (XEXP (y, 0)) == MINUS
04155       && GET_CODE (XEXP (XEXP (y, 0), 1)) == LABEL_REF
04156       && XEXP (XEXP (XEXP (y, 0), 1), 0) == XEXP (const_arg1, 0))
04157     return XEXP (XEXP (y, 0), 0);
04158       }
04159 
04160     /* Likewise if the operands are in the other order.  */
04161     if (const_arg0 && GET_CODE (const_arg0) == LABEL_REF)
04162       {
04163         rtx y
04164     = GET_CODE (folded_arg1) == MINUS ? folded_arg1
04165     : lookup_as_function (folded_arg1, MINUS);
04166 
04167         if (y != 0 && GET_CODE (XEXP (y, 1)) == LABEL_REF
04168       && XEXP (XEXP (y, 1), 0) == XEXP (const_arg0, 0))
04169     return XEXP (y, 0);
04170 
04171         /* Now try for a CONST of a MINUS like the above.  */
04172         if ((y = (GET_CODE (folded_arg1) == CONST ? folded_arg1
04173       : lookup_as_function (folded_arg1, CONST))) != 0
04174       && GET_CODE (XEXP (y, 0)) == MINUS
04175       && GET_CODE (XEXP (XEXP (y, 0), 1)) == LABEL_REF
04176       && XEXP (XEXP (XEXP (y, 0), 1), 0) == XEXP (const_arg0, 0))
04177     return XEXP (XEXP (y, 0), 0);
04178       }
04179 
04180     /* If second operand is a register equivalent to a negative
04181        CONST_INT, see if we can find a register equivalent to the
04182        positive constant.  Make a MINUS if so.  Don't do this for
04183        a non-negative constant since we might then alternate between
04184        choosing positive and negative constants.  Having the positive
04185        constant previously-used is the more common case.  Be sure
04186        the resulting constant is non-negative; if const_arg1 were
04187        the smallest negative number this would overflow: depending
04188        on the mode, this would either just be the same value (and
04189        hence not save anything) or be incorrect.  */
04190     if (const_arg1 != 0 && GET_CODE (const_arg1) == CONST_INT
04191         && INTVAL (const_arg1) < 0
04192         /* This used to test
04193 
04194            -INTVAL (const_arg1) >= 0
04195 
04196      But The Sun V5.0 compilers mis-compiled that test.  So
04197      instead we test for the problematic value in a more direct
04198      manner and hope the Sun compilers get it correct.  */
04199         && INTVAL (const_arg1) !=
04200           ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1))
04201         && GET_CODE (folded_arg1) == REG)
04202       {
04203         rtx new_const = GEN_INT (-INTVAL (const_arg1));
04204         struct table_elt *p
04205     = lookup (new_const, safe_hash (new_const, mode) & HASH_MASK,
04206         mode);
04207 
04208         if (p)
04209     for (p = p->first_same_value; p; p = p->next_same_value)
04210       if (GET_CODE (p->exp) == REG)
04211         return simplify_gen_binary (MINUS, mode, folded_arg0,
04212             canon_reg (p->exp, NULL_RTX));
04213       }
04214     goto from_plus;
04215 
04216   case MINUS:
04217     /* If we have (MINUS Y C), see if Y is known to be (PLUS Z C2).
04218        If so, produce (PLUS Z C2-C).  */
04219     if (const_arg1 != 0 && GET_CODE (const_arg1) == CONST_INT)
04220       {
04221         rtx y = lookup_as_function (XEXP (x, 0), PLUS);
04222         if (y && GET_CODE (XEXP (y, 1)) == CONST_INT)
04223     return fold_rtx (plus_constant (copy_rtx (y),
04224             -INTVAL (const_arg1)),
04225          NULL_RTX);
04226       }
04227 
04228     /* Fall through.  */
04229 
04230   from_plus:
04231   case SMIN:    case SMAX:      case UMIN:    case UMAX:
04232   case IOR:     case AND:       case XOR:
04233   case MULT:
04234   case ASHIFT:  case LSHIFTRT:  case ASHIFTRT:
04235     /* If we have (<op> <reg> <const_int>) for an associative OP and REG
04236        is known to be of similar form, we may be able to replace the
04237        operation with a combined operation.  This may eliminate the
04238        intermediate operation if every use is simplified in this way.
04239        Note that the similar optimization done by combine.c only works
04240        if the intermediate operation's result has only one reference.  */
04241 
04242     if (GET_CODE (folded_arg0) == REG
04243         && const_arg1 && GET_CODE (const_arg1) == CONST_INT)
04244       {
04245         int is_shift
04246     = (code == ASHIFT || code == ASHIFTRT || code == LSHIFTRT);
04247         rtx y = lookup_as_function (folded_arg0, code);
04248         rtx inner_const;
04249         enum rtx_code associate_code;
04250         rtx new_const;
04251 
04252         if (y == 0
04253       || 0 == (inner_const
04254          = equiv_constant (fold_rtx (XEXP (y, 1), 0)))
04255       || GET_CODE (inner_const) != CONST_INT
04256       /* If we have compiled a statement like
04257          "if (x == (x & mask1))", and now are looking at
04258          "x & mask2", we will have a case where the first operand
04259          of Y is the same as our first operand.  Unless we detect
04260          this case, an infinite loop will result.  */
04261       || XEXP (y, 0) == folded_arg0)
04262     break;
04263 
04264         /* Don't associate these operations if they are a PLUS with the
04265      same constant and it is a power of two.  These might be doable
04266      with a pre- or post-increment.  Similarly for two subtracts of
04267      identical powers of two with post decrement.  */
04268 
04269         if (code == PLUS && INTVAL (const_arg1) == INTVAL (inner_const)
04270       && ((HAVE_PRE_INCREMENT
04271         && exact_log2 (INTVAL (const_arg1)) >= 0)
04272           || (HAVE_POST_INCREMENT
04273         && exact_log2 (INTVAL (const_arg1)) >= 0)
04274           || (HAVE_PRE_DECREMENT
04275         && exact_log2 (- INTVAL (const_arg1)) >= 0)
04276           || (HAVE_POST_DECREMENT
04277         && exact_log2 (- INTVAL (const_arg1)) >= 0)))
04278     break;
04279 
04280         /* Compute the code used to compose the constants.  For example,
04281      A-C1-C2 is A-(C1 + C2), so if CODE == MINUS, we want PLUS.  */
04282 
04283         associate_code = (is_shift || code == MINUS ? PLUS : code);
04284 
04285         new_const = simplify_binary_operation (associate_code, mode,
04286                  const_arg1, inner_const);
04287 
04288         if (new_const == 0)
04289     break;
04290 
04291         /* If we are associating shift operations, don't let this
04292      produce a shift of the size of the object or larger.
04293      This could occur when we follow a sign-extend by a right
04294      shift on a machine that does a sign-extend as a pair
04295      of shifts.  */
04296 
04297         if (is_shift && GET_CODE (new_const) == CONST_INT
04298       && INTVAL (new_const) >= GET_MODE_BITSIZE (mode))
04299     {
04300       /* As an exception, we can turn an ASHIFTRT of this
04301          form into a shift of the number of bits - 1.  */
04302       if (code == ASHIFTRT)
04303         new_const = GEN_INT (GET_MODE_BITSIZE (mode) - 1);
04304       else
04305         break;
04306     }
04307 
04308         y = copy_rtx (XEXP (y, 0));
04309 
04310         /* If Y contains our first operand (the most common way this
04311      can happen is if Y is a MEM), we would do into an infinite
04312      loop if we tried to fold it.  So don't in that case.  */
04313 
04314         if (! reg_mentioned_p (folded_arg0, y))
04315     y = fold_rtx (y, insn);
04316 
04317         return simplify_gen_binary (code, mode, y, new_const);
04318       }
04319     break;
04320 
04321   case DIV:       case UDIV:
04322     /* ??? The associative optimization performed immediately above is
04323        also possible for DIV and UDIV using associate_code of MULT.
04324        However, we would need extra code to verify that the
04325        multiplication does not overflow, that is, there is no overflow
04326        in the calculation of new_const.  */
04327     break;
04328 
04329   default:
04330     break;
04331   }
04332 
04333       new = simplify_binary_operation (code, mode,
04334                const_arg0 ? const_arg0 : folded_arg0,
04335                const_arg1 ? const_arg1 : folded_arg1);
04336       break;
04337 
04338     case 'o':
04339       /* (lo_sum (high X) X) is simply X.  */
04340       if (code == LO_SUM && const_arg0 != 0
04341     && GET_CODE (const_arg0) == HIGH
04342     && rtx_equal_p (XEXP (const_arg0, 0), const_arg1))
04343   return const_arg1;
04344       break;
04345 
04346     case '3':
04347     case 'b':
04348       new = simplify_ternary_operation (code, mode, mode_arg0,
04349           const_arg0 ? const_arg0 : folded_arg0,
04350           const_arg1 ? const_arg1 : folded_arg1,
04351           const_arg2 ? const_arg2 : XEXP (x, 2));
04352       break;
04353 
04354     case 'x':
04355       /* Always eliminate CONSTANT_P_RTX at this stage.  */
04356       if (code == CONSTANT_P_RTX)
04357   return (const_arg0 ? const1_rtx : const0_rtx);
04358       break;
04359     }
04360 
04361   return new ? new : x;
04362 }
04363 
04364 /* Return a constant value currently equivalent to X.
04365    Return 0 if we don't know one.  */
04366 
04367 static rtx
04368 equiv_constant (x)
04369      rtx x;
04370 {
04371   if (GET_CODE (x) == REG
04372       && REGNO_QTY_VALID_P (REGNO (x)))
04373     {
04374       int x_q = REG_QTY (REGNO (x));
04375       struct qty_table_elem *x_ent = &qty_table[x_q];
04376 
04377       if (x_ent->const_rtx)
04378   x = gen_lowpart_if_possible (GET_MODE (x), x_ent->const_rtx);
04379     }
04380 
04381   if (x == 0 || CONSTANT_P (x))
04382     return x;
04383 
04384   /* If X is a MEM, try to fold it outside the context of any insn to see if
04385      it might be equivalent to a constant.  That handles the case where it
04386      is a constant-pool reference.  Then try to look it up in the hash table
04387      in case it is something whose value we have seen before.  */
04388 
04389   if (GET_CODE (x) == MEM)
04390     {
04391       struct table_elt *elt;
04392 
04393       x = fold_rtx (x, NULL_RTX);
04394       if (CONSTANT_P (x))
04395   return x;
04396 
04397       elt = lookup (x, safe_hash (x, GET_MODE (x)) & HASH_MASK, GET_MODE (x));
04398       if (elt == 0)
04399   return 0;
04400 
04401       for (elt = elt->first_same_value; elt; elt = elt->next_same_value)
04402   if (elt->is_const && CONSTANT_P (elt->exp))
04403     return elt->exp;
04404     }
04405 
04406   return 0;
04407 }
04408 
04409 /* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a fixed-point
04410    number, return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
04411    least-significant part of X.
04412    MODE specifies how big a part of X to return.
04413 
04414    If the requested operation cannot be done, 0 is returned.
04415 
04416    This is similar to gen_lowpart in emit-rtl.c.  */
04417 
04418 rtx
04419 gen_lowpart_if_possible (mode, x)
04420      enum machine_mode mode;
04421      rtx x;
04422 {
04423   rtx result = gen_lowpart_common (mode, x);
04424 
04425   if (result)
04426     return result;
04427   else if (GET_CODE (x) == MEM)
04428     {
04429       /* This is the only other case we handle.  */
04430       int offset = 0;
04431       rtx new;
04432 
04433       if (WORDS_BIG_ENDIAN)
04434   offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
04435       - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
04436       if (BYTES_BIG_ENDIAN)
04437   /* Adjust the address so that the address-after-the-data is
04438      unchanged.  */
04439   offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
04440        - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
04441 
04442       new = adjust_address_nv (x, mode, offset);
04443       if (! memory_address_p (mode, XEXP (new, 0)))
04444   return 0;
04445 
04446       return new;
04447     }
04448   else
04449     return 0;
04450 }
04451 
04452 /* Given INSN, a jump insn, TAKEN indicates if we are following the "taken"
04453    branch.  It will be zero if not.
04454 
04455    In certain cases, this can cause us to add an equivalence.  For example,
04456    if we are following the taken case of
04457     if (i == 2)
04458    we can add the fact that `i' and '2' are now equivalent.
04459 
04460    In any case, we can record that this comparison was passed.  If the same
04461    comparison is seen later, we will know its value.  */
04462 
04463 static void
04464 record_jump_equiv (insn, taken)
04465      rtx insn;
04466      int taken;
04467 {
04468   int cond_known_true;
04469   rtx op0, op1;
04470   rtx set;
04471   enum machine_mode mode, mode0, mode1;
04472   int reversed_nonequality = 0;
04473   enum rtx_code code;
04474 
04475   /* Ensure this is the right kind of insn.  */
04476   if (! any_condjump_p (insn))
04477     return;
04478   set = pc_set (insn);
04479 
04480   /* See if this jump condition is known true or false.  */
04481   if (taken)
04482     cond_known_true = (XEXP (SET_SRC (set), 2) == pc_rtx);
04483   else
04484     cond_known_true = (XEXP (SET_SRC (set), 1) == pc_rtx);
04485 
04486   /* Get the type of comparison being done and the operands being compared.
04487      If we had to reverse a non-equality condition, record that fact so we
04488      know that it isn't valid for floating-point.  */
04489   code = GET_CODE (XEXP (SET_SRC (set), 0));
04490   op0 = fold_rtx (XEXP (XEXP (SET_SRC (set), 0), 0), insn);
04491   op1 = fold_rtx (XEXP (XEXP (SET_SRC (set), 0), 1), insn);
04492 
04493   code = find_comparison_args (code, &op0, &op1, &mode0, &mode1);
04494   if (! cond_known_true)
04495     {
04496       code = reversed_comparison_code_parts (code, op0, op1, insn);
04497 
04498       /* Don't remember if we can't find the inverse.  */
04499       if (code == UNKNOWN)
04500   return;
04501     }
04502 
04503   /* The mode is the mode of the non-constant.  */
04504   mode = mode0;
04505   if (mode1 != VOIDmode)
04506     mode = mode1;
04507 
04508   record_jump_cond (code, mode, op0, op1, reversed_nonequality);
04509 }
04510 
04511 /* We know that comparison CODE applied to OP0 and OP1 in MODE is true.
04512    REVERSED_NONEQUALITY is nonzero if CODE had to be swapped.
04513    Make any useful entries we can with that information.  Called from
04514    above function and called recursively.  */
04515 
04516 static void
04517 record_jump_cond (code, mode, op0, op1, reversed_nonequality)
04518      enum rtx_code code;
04519      enum machine_mode mode;
04520      rtx op0, op1;
04521      int reversed_nonequality;
04522 {
04523   unsigned op0_hash, op1_hash;
04524   int op0_in_memory, op1_in_memory;
04525   struct table_elt *op0_elt, *op1_elt;
04526 
04527   /* If OP0 and OP1 are known equal, and either is a paradoxical SUBREG,
04528      we know that they are also equal in the smaller mode (this is also
04529      true for all smaller modes whether or not there is a SUBREG, but
04530      is not worth testing for with no SUBREG).  */
04531 
04532   /* Note that GET_MODE (op0) may not equal MODE.  */
04533   if (code == EQ && GET_CODE (op0) == SUBREG
04534       && (GET_MODE_SIZE (GET_MODE (op0))
04535     > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0)))))
04536     {
04537       enum machine_mode inner_mode = GET_MODE (SUBREG_REG (op0));
04538       rtx tem = gen_lowpart_if_possible (inner_mode, op1);
04539 
04540       record_jump_cond (code, mode, SUBREG_REG (op0),
04541       tem ? tem : gen_rtx_SUBREG (inner_mode, op1, 0),
04542       reversed_nonequality);
04543     }
04544 
04545   if (code == EQ && GET_CODE (op1) == SUBREG
04546       && (GET_MODE_SIZE (GET_MODE (op1))
04547     > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op1)))))
04548     {
04549       enum machine_mode inner_mode = GET_MODE (SUBREG_REG (op1));
04550       rtx tem = gen_lowpart_if_possible (inner_mode, op0);
04551 
04552       record_jump_cond (code, mode, SUBREG_REG (op1),
04553       tem ? tem : gen_rtx_SUBREG (inner_mode, op0, 0),
04554       reversed_nonequality);
04555     }
04556 
04557   /* Similarly, if this is an NE comparison, and either is a SUBREG
04558      making a smaller mode, we know the whole thing is also NE.  */
04559 
04560   /* Note that GET_MODE (op0) may not equal MODE;
04561      if we test MODE instead, we can get an infinite recursion
04562      alternating between two modes each wider than MODE.  */
04563 
04564   if (code == NE && GET_CODE (op0) == SUBREG
04565       && subreg_lowpart_p (op0)
04566       && (GET_MODE_SIZE (GET_MODE (op0))
04567     < GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0)))))
04568     {
04569       enum machine_mode inner_mode = GET_MODE (SUBREG_REG (op0));
04570       rtx tem = gen_lowpart_if_possible (inner_mode, op1);
04571 
04572       record_jump_cond (code, mode, SUBREG_REG (op0),
04573       tem ? tem : gen_rtx_SUBREG (inner_mode, op1, 0),
04574       reversed_nonequality);
04575     }
04576 
04577   if (code == NE && GET_CODE (op1) == SUBREG
04578       && subreg_lowpart_p (op1)
04579       && (GET_MODE_SIZE (GET_MODE (op1))
04580     < GET_MODE_SIZE (GET_MODE (SUBREG_REG (op1)))))
04581     {
04582       enum machine_mode inner_mode = GET_MODE (SUBREG_REG (op1));
04583       rtx tem = gen_lowpart_if_possible (inner_mode, op0);
04584 
04585       record_jump_cond (code, mode, SUBREG_REG (op1),
04586       tem ? tem : gen_rtx_SUBREG (inner_mode, op0, 0),
04587       reversed_nonequality);
04588     }
04589 
04590   /* Hash both operands.  */
04591 
04592   do_not_record = 0;
04593   hash_arg_in_memory = 0;
04594   op0_hash = HASH (op0, mode);
04595   op0_in_memory = hash_arg_in_memory;
04596 
04597   if (do_not_record)
04598     return;
04599 
04600   do_not_record = 0;
04601   hash_arg_in_memory = 0;
04602   op1_hash = HASH (op1, mode);
04603   op1_in_memory = hash_arg_in_memory;
04604 
04605   if (do_not_record)
04606     return;
04607 
04608   /* Look up both operands.  */
04609   op0_elt = lookup (op0, op0_hash, mode);
04610   op1_elt = lookup (op1, op1_hash, mode);
04611 
04612   /* If both operands are already equivalent or if they are not in the
04613      table but are identical, do nothing.  */
04614   if ((op0_elt != 0 && op1_elt != 0
04615        && op0_elt->first_same_value == op1_elt->first_same_value)
04616       || op0 == op1 || rtx_equal_p (op0, op1))
04617     return;
04618 
04619   /* If we aren't setting two things equal all we can do is save this
04620      comparison.   Similarly if this is floating-point.  In the latter
04621      case, OP1 might be zero and both -0.0 and 0.0 are equal to it.
04622      If we record the equality, we might inadvertently delete code
04623      whose intent was to change -0 to +0.  */
04624 
04625   if (code != EQ || FLOAT_MODE_P (GET_MODE (op0)))
04626     {
04627       struct qty_table_elem *ent;
04628       int qty;
04629 
04630       /* If we reversed a floating-point comparison, if OP0 is not a
04631    register, or if OP1 is neither a register or constant, we can't
04632    do anything.  */
04633 
04634       if (GET_CODE (op1) != REG)
04635   op1 = equiv_constant (op1);
04636 
04637       if ((reversed_nonequality && FLOAT_MODE_P (mode))
04638     || GET_CODE (op0) != REG || op1 == 0)
04639   return;
04640 
04641       /* Put OP0 in the hash table if it isn't already.  This gives it a
04642    new quantity number.  */
04643       if (op0_elt == 0)
04644   {
04645     if (insert_regs (op0, NULL, 0))
04646       {
04647         rehash_using_reg (op0);
04648         op0_hash = HASH (op0, mode);
04649 
04650         /* If OP0 is contained in OP1, this changes its hash code
04651      as well.  Faster to rehash than to check, except
04652      for the simple case of a constant.  */
04653         if (! CONSTANT_P (op1))
04654     op1_hash = HASH (op1,mode);
04655       }
04656 
04657     op0_elt = insert (op0, NULL, op0_hash, mode);
04658     op0_elt->in_memory = op0_in_memory;
04659   }
04660 
04661       qty = REG_QTY (REGNO (op0));
04662       ent = &qty_table[qty];
04663 
04664       ent->comparison_code = code;
04665       if (GET_CODE (op1) == REG)
04666   {
04667     /* Look it up again--in case op0 and op1 are the same.  */
04668     op1_elt = lookup (op1, op1_hash, mode);
04669 
04670     /* Put OP1 in the hash table so it gets a new quantity number.  */
04671     if (op1_elt == 0)
04672       {
04673         if (insert_regs (op1, NULL, 0))
04674     {
04675       rehash_using_reg (op1);
04676       op1_hash = HASH (op1, mode);
04677     }
04678 
04679         op1_elt = insert (op1, NULL, op1_hash, mode);
04680         op1_elt->in_memory = op1_in_memory;
04681       }
04682 
04683     ent->comparison_const = NULL_RTX;
04684     ent->comparison_qty = REG_QTY (REGNO (op1));
04685   }
04686       else
04687   {
04688     ent->comparison_const = op1;
04689     ent->comparison_qty = -1;
04690   }
04691 
04692       return;
04693     }
04694 
04695   /* If either side is still missing an equivalence, make it now,
04696      then merge the equivalences.  */
04697 
04698   if (op0_elt == 0)
04699     {
04700       if (insert_regs (op0, NULL, 0))
04701   {
04702     rehash_using_reg (op0);
04703     op0_hash = HASH (op0, mode);
04704   }
04705 
04706       op0_elt = insert (op0, NULL, op0_hash, mode);
04707       op0_elt->in_memory = op0_in_memory;
04708     }
04709 
04710   if (op1_elt == 0)
04711     {
04712       if (insert_regs (op1, NULL, 0))
04713   {
04714     rehash_using_reg (op1);
04715     op1_hash = HASH (op1, mode);
04716   }
04717 
04718       op1_elt = insert (op1, NULL, op1_hash, mode);
04719       op1_elt->in_memory = op1_in_memory;
04720     }
04721 
04722   merge_equiv_classes (op0_elt, op1_elt);
04723   last_jump_equiv_class = op0_elt;
04724 }
04725 
04726 /* CSE processing for one instruction.
04727    First simplify sources and addresses of all assignments
04728    in the instruction, using previously-computed equivalents values.
04729    Then install the new sources and destinations in the table
04730    of available values.
04731 
04732    If LIBCALL_INSN is nonzero, don't record any equivalence made in
04733    the insn.  It means that INSN is inside libcall block.  In this
04734    case LIBCALL_INSN is the corresponding insn with REG_LIBCALL.  */
04735 
04736 /* Data on one SET contained in the instruction.  */
04737 
04738 struct set
04739 {
04740   /* The SET rtx itself.  */
04741   rtx rtl;
04742   /* The SET_SRC of the rtx (the original value, if it is changing).  */
04743   rtx src;
04744   /* The hash-table element for the SET_SRC of the SET.  */
04745   struct table_elt *src_elt;
04746   /* Hash value for the SET_SRC.  */
04747   unsigned src_hash;
04748   /* Hash value for the SET_DEST.  */
04749   unsigned dest_hash;
04750   /* The SET_DEST, with SUBREG, etc., stripped.  */
04751   rtx inner_dest;
04752   /* Nonzero if the SET_SRC is in memory.  */
04753   char src_in_memory;
04754   /* Nonzero if the SET_SRC contains something
04755      whose value cannot be predicted and understood.  */
04756   char src_volatile;
04757   /* Original machine mode, in case it becomes a CONST_INT.  */
04758   enum machine_mode mode;
04759   /* A constant equivalent for SET_SRC, if any.  */
04760   rtx src_const;
04761   /* Original SET_SRC value used for libcall notes.  */
04762   rtx orig_src;
04763   /* Hash value of constant equivalent for SET_SRC.  */
04764   unsigned src_const_hash;
04765   /* Table entry for constant equivalent for SET_SRC, if any.  */
04766   struct table_elt *src_const_elt;
04767 };
04768 
04769 static void
04770 cse_insn (insn, libcall_insn)
04771      rtx insn;
04772      rtx libcall_insn;
04773 {
04774   rtx x = PATTERN (insn);
04775   int i;
04776   rtx tem;
04777   int n_sets = 0;
04778 
04779 #ifdef HAVE_cc0
04780   /* Records what this insn does to set CC0.  */
04781   rtx this_insn_cc0 = 0;
04782   enum machine_mode this_insn_cc0_mode = VOIDmode;
04783 #endif
04784 
04785   rtx src_eqv = 0;
04786   struct table_elt *src_eqv_elt = 0;
04787   int src_eqv_volatile = 0;
04788   int src_eqv_in_memory = 0;
04789   unsigned src_eqv_hash = 0;
04790 
04791   struct set *sets = (struct set *) 0;
04792 
04793   this_insn = insn;
04794 
04795   /* Find all the SETs and CLOBBERs in this instruction.
04796      Record all the SETs in the array `set' and count them.
04797      Also determine whether there is a CLOBBER that invalidates
04798      all memory references, or all references at varying addresses.  */
04799 
04800   if (GET_CODE (insn) == CALL_INSN)
04801     {
04802       for (tem = CALL_INSN_FUNCTION_USAGE (insn); tem; tem = XEXP (tem, 1))
04803   {
04804     if (GET_CODE (XEXP (tem, 0)) == CLOBBER)
04805       invalidate (SET_DEST (XEXP (tem, 0)), VOIDmode);
04806     XEXP (tem, 0) = canon_reg (XEXP (tem, 0), insn);
04807   }
04808     }
04809 
04810   if (GET_CODE (x) == SET)
04811     {
04812       sets = (struct set *) alloca (sizeof (struct set));
04813       sets[0].rtl = x;
04814 
04815       /* Ignore SETs that are unconditional jumps.
04816    They never need cse processing, so this does not hurt.
04817    The reason is not efficiency but rather
04818    so that we can test at the end for instructions
04819    that have been simplified to unconditional jumps
04820    and not be misled by unchanged instructions
04821    that were unconditional jumps to begin with.  */
04822       if (SET_DEST (x) == pc_rtx
04823     && GET_CODE (SET_SRC (x)) == LABEL_REF)
04824   ;
04825 
04826       /* Don't count call-insns, (set (reg 0) (call ...)), as a set.
04827    The hard function value register is used only once, to copy to
04828    someplace else, so it isn't worth cse'ing (and on 80386 is unsafe)!
04829    Ensure we invalidate the destination register.  On the 80386 no
04830    other code would invalidate it since it is a fixed_reg.
04831    We need not check the return of apply_change_group; see canon_reg.  */
04832 
04833       else if (GET_CODE (SET_SRC (x)) == CALL)
04834   {
04835     canon_reg (SET_SRC (x), insn);
04836     apply_change_group ();
04837     fold_rtx (SET_SRC (x), insn);
04838     invalidate (SET_DEST (x), VOIDmode);
04839   }
04840       else
04841   n_sets = 1;
04842     }
04843   else if (GET_CODE (x) == PARALLEL)
04844     {
04845       int lim = XVECLEN (x, 0);
04846 
04847       sets = (struct set *) alloca (lim * sizeof (struct set));
04848 
04849       /* Find all regs explicitly clobbered in this insn,
04850    and ensure they are not replaced with any other regs
04851    elsewhere in this insn.
04852    When a reg that is clobbered is also used for input,
04853    we should presume that that is for a reason,
04854    and we should not substitute some other register
04855    which is not supposed to be clobbered.
04856    Therefore, this loop cannot be merged into the one below
04857    because a CALL may precede a CLOBBER and refer to the
04858    value clobbered.  We must not let a canonicalization do
04859    anything in that case.  */
04860       for (i = 0; i < lim; i++)
04861   {
04862     rtx y = XVECEXP (x, 0, i);
04863     if (GET_CODE (y) == CLOBBER)
04864       {
04865         rtx clobbered = XEXP (y, 0);
04866 
04867         if (GET_CODE (clobbered) == REG
04868       || GET_CODE (clobbered) == SUBREG)
04869     invalidate (clobbered, VOIDmode);
04870         else if (GET_CODE (clobbered) == STRICT_LOW_PART
04871            || GET_CODE (clobbered) == ZERO_EXTRACT)
04872     invalidate (XEXP (clobbered, 0), GET_MODE (clobbered));
04873       }
04874   }
04875 
04876       for (i = 0; i < lim; i++)
04877   {
04878     rtx y = XVECEXP (x, 0, i);
04879     if (GET_CODE (y) == SET)
04880       {
04881         /* As above, we ignore unconditional jumps and call-insns and
04882      ignore the result of apply_change_group.  */
04883         if (GET_CODE (SET_SRC (y)) == CALL)
04884     {
04885       canon_reg (SET_SRC (y), insn);
04886       apply_change_group ();
04887       fold_rtx (SET_SRC (y), insn);
04888       invalidate (SET_DEST (y), VOIDmode);
04889     }
04890         else if (SET_DEST (y) == pc_rtx
04891            && GET_CODE (SET_SRC (y)) == LABEL_REF)
04892     ;
04893         else
04894     sets[n_sets++].rtl = y;
04895       }
04896     else if (GET_CODE (y) == CLOBBER)
04897       {
04898         /* If we clobber memory, canon the address.
04899      This does nothing when a register is clobbered
04900      because we have already invalidated the reg.  */
04901         if (GET_CODE (XEXP (y, 0)) == MEM)
04902     canon_reg (XEXP (y, 0), NULL_RTX);
04903       }
04904     else if (GET_CODE (y) == USE
04905        && ! (GET_CODE (XEXP (y, 0)) == REG
04906        && REGNO (XEXP (y, 0)) < FIRST_PSEUDO_REGISTER))
04907       canon_reg (y, NULL_RTX);
04908     else if (GET_CODE (y) == CALL)
04909       {
04910         /* The result of apply_change_group can be ignored; see
04911      canon_reg.  */
04912         canon_reg (y, insn);
04913         apply_change_group ();
04914         fold_rtx (y, insn);
04915       }
04916   }
04917     }
04918   else if (GET_CODE (x) == CLOBBER)
04919     {
04920       if (GET_CODE (XEXP (x, 0)) == MEM)
04921   canon_reg (XEXP (x, 0), NULL_RTX);
04922     }
04923 
04924   /* Canonicalize a USE of a pseudo register or memory location.  */
04925   else if (GET_CODE (x) == USE
04926      && ! (GET_CODE (XEXP (x, 0)) == REG
04927      && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER))
04928     canon_reg (XEXP (x, 0), NULL_RTX);
04929   else if (GET_CODE (x) == CALL)
04930     {
04931       /* The result of apply_change_group can be ignored; see canon_reg.  */
04932       canon_reg (x, insn);
04933       apply_change_group ();
04934       fold_rtx (x, insn);
04935     }
04936 
04937   /* Store the equivalent value in SRC_EQV, if different, or if the DEST
04938      is a STRICT_LOW_PART.  The latter condition is necessary because SRC_EQV
04939      is handled specially for this case, and if it isn't set, then there will
04940      be no equivalence for the destination.  */
04941   if (n_sets == 1 && REG_NOTES (insn) != 0
04942       && (tem = find_reg_note (insn, REG_EQUAL, NULL_RTX)) != 0
04943       && (! rtx_equal_p (XEXP (tem, 0), SET_SRC (sets[0].rtl))
04944     || GET_CODE (SET_DEST (sets[0].rtl)) == STRICT_LOW_PART))
04945     {
04946       src_eqv = fold_rtx (canon_reg (XEXP (tem, 0), NULL_RTX), insn);
04947       XEXP (tem, 0) = src_eqv;
04948     }
04949 
04950   /* Canonicalize sources and addresses of destinations.
04951      We do this in a separate pass to avoid problems when a MATCH_DUP is
04952      present in the insn pattern.  In that case, we want to ensure that
04953      we don't break the duplicate nature of the pattern.  So we will replace
04954      both operands at the same time.  Otherwise, we would fail to find an
04955      equivalent substitution in the loop calling validate_change below.
04956 
04957      We used to suppress canonicalization of DEST if it appears in SRC,
04958      but we don't do this any more.  */
04959 
04960   for (i = 0; i < n_sets; i++)
04961     {
04962       rtx dest = SET_DEST (sets[i].rtl);
04963       rtx src = SET_SRC (sets[i].rtl);
04964       rtx new = canon_reg (src, insn);
04965       int insn_code;
04966 
04967       sets[i].orig_src = src;
04968       if ((GET_CODE (new) == REG && GET_CODE (src) == REG
04969      && ((REGNO (new) < FIRST_PSEUDO_REGISTER)
04970          != (REGNO (src) < FIRST_PSEUDO_REGISTER)))
04971     || (insn_code = recog_memoized (insn)) < 0
04972     || insn_data[insn_code].n_dups > 0)
04973   validate_change (insn, &SET_SRC (sets[i].rtl), new, 1);
04974       else
04975   SET_SRC (sets[i].rtl) = new;
04976 
04977       if (GET_CODE (dest) == ZERO_EXTRACT || GET_CODE (dest) == SIGN_EXTRACT)
04978   {
04979     validate_change (insn, &XEXP (dest, 1),
04980          canon_reg (XEXP (dest, 1), insn), 1);
04981     validate_change (insn, &XEXP (dest, 2),
04982          canon_reg (XEXP (dest, 2), insn), 1);
04983   }
04984 
04985       while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
04986        || GET_CODE (dest) == ZERO_EXTRACT
04987        || GET_CODE (dest) == SIGN_EXTRACT)
04988   dest = XEXP (dest, 0);
04989 
04990       if (GET_CODE (dest) == MEM)
04991   canon_reg (dest, insn);
04992     }
04993 
04994   /* Now that we have done all the replacements, we can apply the change
04995      group and see if they all work.  Note that this will cause some
04996      canonicalizations that would have worked individually not to be applied
04997      because some other canonicalization didn't work, but this should not
04998      occur often.
04999 
05000      The result of apply_change_group can be ignored; see canon_reg.  */
05001 
05002   apply_change_group ();
05003 
05004   /* Set sets[i].src_elt to the class each source belongs to.
05005      Detect assignments from or to volatile things
05006      and set set[i] to zero so they will be ignored
05007      in the rest of this function.
05008 
05009      Nothing in this loop changes the hash table or the register chains.  */
05010 
05011   for (i = 0; i < n_sets; i++)
05012     {
05013       rtx src, dest;
05014       rtx src_folded;
05015       struct table_elt *elt = 0, *p;
05016       enum machine_mode mode;
05017       rtx src_eqv_here;
05018       rtx src_const = 0;
05019       rtx src_related = 0;
05020       struct table_elt *src_const_elt = 0;
05021       int src_cost = MAX_COST;
05022       int src_eqv_cost = MAX_COST;
05023       int src_folded_cost = MAX_COST;
05024       int src_related_cost = MAX_COST;
05025       int src_elt_cost = MAX_COST;
05026       int src_regcost = MAX_COST;
05027       int src_eqv_regcost = MAX_COST;
05028       int src_folded_regcost = MAX_COST;
05029       int src_related_regcost = MAX_COST;
05030       int src_elt_regcost = MAX_COST;
05031       /* Set nonzero if we need to call force_const_mem on with the
05032    contents of src_folded before using it.  */
05033       int src_folded_force_flag = 0;
05034 
05035       dest = SET_DEST (sets[i].rtl);
05036       src = SET_SRC (sets[i].rtl);
05037 
05038       /* If SRC is a constant that has no machine mode,
05039    hash it with the destination's machine mode.
05040    This way we can keep different modes separate.  */
05041 
05042       mode = GET_MODE (src) == VOIDmode ? GET_MODE (dest) : GET_MODE (src);
05043       sets[i].mode = mode;
05044 
05045       if (src_eqv)
05046   {
05047     enum machine_mode eqvmode = mode;
05048     if (GET_CODE (dest) == STRICT_LOW_PART)
05049       eqvmode = GET_MODE (SUBREG_REG (XEXP (dest, 0)));
05050     do_not_record = 0;
05051     hash_arg_in_memory = 0;
05052     src_eqv_hash = HASH (src_eqv, eqvmode);
05053 
05054     /* Find the equivalence class for the equivalent expression.  */
05055 
05056     if (!do_not_record)
05057       src_eqv_elt = lookup (src_eqv, src_eqv_hash, eqvmode);
05058 
05059     src_eqv_volatile = do_not_record;
05060     src_eqv_in_memory = hash_arg_in_memory;
05061   }
05062 
05063       /* If this is a STRICT_LOW_PART assignment, src_eqv corresponds to the
05064    value of the INNER register, not the destination.  So it is not
05065    a valid substitution for the source.  But save it for later.  */
05066       if (GET_CODE (dest) == STRICT_LOW_PART)
05067   src_eqv_here = 0;
05068       else
05069   src_eqv_here = src_eqv;
05070 
05071       /* Simplify and foldable subexpressions in SRC.  Then get the fully-
05072    simplified result, which may not necessarily be valid.  */
05073       src_folded = fold_rtx (src, insn);
05074 
05075 #if 0
05076       /* ??? This caused bad code to be generated for the m68k port with -O2.
05077    Suppose src is (CONST_INT -1), and that after truncation src_folded
05078    is (CONST_INT 3).  Suppose src_folded is then used for src_const.
05079    At the end we will add src and src_const to the same equivalence
05080    class.  We now have 3 and -1 on the same equivalence class.  This
05081    causes later instructions to be mis-optimized.  */
05082       /* If storing a constant in a bitfield, pre-truncate the constant
05083    so we will be able to record it later.  */
05084       if (GET_CODE (SET_DEST (sets[i].rtl)) == ZERO_EXTRACT
05085     || GET_CODE (SET_DEST (sets[i].rtl)) == SIGN_EXTRACT)
05086   {
05087     rtx width = XEXP (SET_DEST (sets[i].rtl), 1);
05088 
05089     if (GET_CODE (src) == CONST_INT
05090         && GET_CODE (width) == CONST_INT
05091         && INTVAL (width) < HOST_BITS_PER_WIDE_INT
05092         && (INTVAL (src) & ((HOST_WIDE_INT) (-1) << INTVAL (width))))
05093       src_folded
05094         = GEN_INT (INTVAL (src) & (((HOST_WIDE_INT) 1
05095             << INTVAL (width)) - 1));
05096   }
05097 #endif
05098 
05099       /* Compute SRC's hash code, and also notice if it
05100    should not be recorded at all.  In that case,
05101    prevent any further processing of this assignment.  */
05102       do_not_record = 0;
05103       hash_arg_in_memory = 0;
05104 
05105       sets[i].src = src;
05106       sets[i].src_hash = HASH (src, mode);
05107       sets[i].src_volatile = do_not_record;
05108       sets[i].src_in_memory = hash_arg_in_memory;
05109 
05110       /* If SRC is a MEM, there is a REG_EQUIV note for SRC, and DEST is
05111    a pseudo, do not record SRC.  Using SRC as a replacement for
05112    anything else will be incorrect in that situation.  Note that
05113    this usually occurs only for stack slots, in which case all the
05114    RTL would be referring to SRC, so we don't lose any optimization
05115    opportunities by not having SRC in the hash table.  */
05116 
05117       if (GET_CODE (src) == MEM
05118     && find_reg_note (insn, REG_EQUIV, NULL_RTX) != 0
05119     && GET_CODE (dest) == REG
05120     && REGNO (dest) >= FIRST_PSEUDO_REGISTER)
05121   sets[i].src_volatile = 1;
05122 
05123 #if 0
05124       /* It is no longer clear why we used to do this, but it doesn't
05125    appear to still be needed.  So let's try without it since this
05126    code hurts cse'ing widened ops.  */
05127       /* If source is a perverse subreg (such as QI treated as an SI),
05128    treat it as volatile.  It may do the work of an SI in one context
05129    where the extra bits are not being used, but cannot replace an SI
05130    in general.  */
05131       if (GET_CODE (src) == SUBREG
05132     && (GET_MODE_SIZE (GET_MODE (src))
05133         > GET_MODE_SIZE (GET_MODE (SUBREG_REG (src)))))
05134   sets[i].src_volatile = 1;
05135 #endif
05136 
05137       /* Locate all possible equivalent forms for SRC.  Try to replace
05138          SRC in the insn with each cheaper equivalent.
05139 
05140          We have the following types of equivalents: SRC itself, a folded
05141          version, a value given in a REG_EQUAL note, or a value related
05142    to a constant.
05143 
05144          Each of these equivalents may be part of an additional class
05145          of equivalents (if more than one is in the table, they must be in
05146          the same class; we check for this).
05147 
05148    If the source is volatile, we don't do any table lookups.
05149 
05150          We note any constant equivalent for possible later use in a
05151          REG_NOTE.  */
05152 
05153       if (!sets[i].src_volatile)
05154   elt = lookup (src, sets[i].src_hash, mode);
05155 
05156       sets[i].src_elt = elt;
05157 
05158       if (elt && src_eqv_here && src_eqv_elt)
05159   {
05160     if (elt->first_same_value != src_eqv_elt->first_same_value)
05161       {
05162         /* The REG_EQUAL is indicating that two formerly distinct
05163      classes are now equivalent.  So merge them.  */
05164         merge_equiv_classes (elt, src_eqv_elt);
05165         src_eqv_hash = HASH (src_eqv, elt->mode);
05166         src_eqv_elt = lookup (src_eqv, src_eqv_hash, elt->mode);
05167       }
05168 
05169     src_eqv_here = 0;
05170   }
05171 
05172       else if (src_eqv_elt)
05173   elt = src_eqv_elt;
05174 
05175       /* Try to find a constant somewhere and record it in `src_const'.
05176    Record its table element, if any, in `src_const_elt'.  Look in
05177    any known equivalences first.  (If the constant is not in the
05178    table, also set `sets[i].src_const_hash').  */
05179       if (elt)
05180   for (p = elt->first_same_value; p; p = p->next_same_value)
05181     if (p->is_const)
05182       {
05183         src_const = p->exp;
05184         src_const_elt = elt;
05185         break;
05186       }
05187 
05188       if (src_const == 0
05189     && (CONSTANT_P (src_folded)
05190         /* Consider (minus (label_ref L1) (label_ref L2)) as
05191      "constant" here so we will record it. This allows us
05192      to fold switch statements when an ADDR_DIFF_VEC is used.  */
05193         || (GET_CODE (src_folded) == MINUS
05194       && GET_CODE (XEXP (src_folded, 0)) == LABEL_REF
05195       && GET_CODE (XEXP (src_folded, 1)) == LABEL_REF)))
05196   src_const = src_folded, src_const_elt = elt;
05197       else if (src_const == 0 && src_eqv_here && CONSTANT_P (src_eqv_here))
05198   src_const = src_eqv_here, src_const_elt = src_eqv_elt;
05199 
05200       /* If we don't know if the constant is in the table, get its
05201    hash code and look it up.  */
05202       if (src_const && src_const_elt == 0)
05203   {
05204     sets[i].src_const_hash = HASH (src_const, mode);
05205     src_const_elt = lookup (src_const, sets[i].src_const_hash, mode);
05206   }
05207 
05208       sets[i].src_const = src_const;
05209       sets[i].src_const_elt = src_const_elt;
05210 
05211       /* If the constant and our source are both in the table, mark them as
05212    equivalent.  Otherwise, if a constant is in the table but the source
05213    isn't, set ELT to it.  */
05214       if (src_const_elt && elt
05215     && src_const_elt->first_same_value != elt->first_same_value)
05216   merge_equiv_classes (elt, src_const_elt);
05217       else if (src_const_elt && elt == 0)
05218   elt = src_const_elt;
05219 
05220       /* See if there is a register linearly related to a constant
05221          equivalent of SRC.  */
05222       if (src_const
05223     && (GET_CODE (src_const) == CONST
05224         || (src_const_elt && src_const_elt->related_value != 0)))
05225   {
05226     src_related = use_related_value (src_const, src_const_elt);
05227     if (src_related)
05228       {
05229         struct table_elt *src_related_elt
05230     = lookup (src_related, HASH (src_related, mode), mode);
05231         if (src_related_elt && elt)
05232     {
05233       if (elt->first_same_value
05234           != src_related_elt->first_same_value)
05235         /* This can occur when we previously saw a CONST
05236            involving a SYMBOL_REF and then see the SYMBOL_REF
05237            twice.  Merge the involved classes.  */
05238         merge_equiv_classes (elt, src_related_elt);
05239 
05240       src_related = 0;
05241       src_related_elt = 0;
05242     }
05243         else if (src_related_elt && elt == 0)
05244     elt = src_related_elt;
05245       }
05246   }
05247 
05248       /* See if we have a CONST_INT that is already in a register in a
05249    wider mode.  */
05250 
05251       if (src_const && src_related == 0 && GET_CODE (src_const) == CONST_INT
05252     && GET_MODE_CLASS (mode) == MODE_INT
05253     && GET_MODE_BITSIZE (mode) < BITS_PER_WORD)
05254   {
05255     enum machine_mode wider_mode;
05256 
05257     for (wider_mode = GET_MODE_WIDER_MODE (mode);
05258          GET_MODE_BITSIZE (wider_mode) <= BITS_PER_WORD
05259          && src_related == 0;
05260          wider_mode = GET_MODE_WIDER_MODE (wider_mode))
05261       {
05262         struct table_elt *const_elt
05263     = lookup (src_const, HASH (src_const, wider_mode), wider_mode);
05264 
05265         if (const_elt == 0)
05266     continue;
05267 
05268         for (const_elt = const_elt->first_same_value;
05269        const_elt; const_elt = const_elt->next_same_value)
05270     if (GET_CODE (const_elt->exp) == REG)
05271       {
05272         src_related = gen_lowpart_if_possible (mode,
05273                  const_elt->exp);
05274         break;
05275       }
05276       }
05277   }
05278 
05279       /* Another possibility is that we have an AND with a constant in
05280    a mode narrower than a word.  If so, it might have been generated
05281    as part of an "if" which would narrow the AND.  If we already
05282    have done the AND in a wider mode, we can use a SUBREG of that
05283    value.  */
05284 
05285       if (flag_expensive_optimizations && ! src_related
05286     && GET_CODE (src) == AND && GET_CODE (XEXP (src, 1)) == CONST_INT
05287     && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
05288   {
05289     enum machine_mode tmode;
05290     rtx new_and = gen_rtx_AND (VOIDmode, NULL_RTX, XEXP (src, 1));
05291 
05292     for (tmode = GET_MODE_WIDER_MODE (mode);
05293          GET_MODE_SIZE (tmode) <= UNITS_PER_WORD;
05294          tmode = GET_MODE_WIDER_MODE (tmode))
05295       {
05296         rtx inner = gen_lowpart_if_possible (tmode, XEXP (src, 0));
05297         struct table_elt *larger_elt;
05298 
05299         if (inner)
05300     {
05301       PUT_MODE (new_and, tmode);
05302       XEXP (new_and, 0) = inner;
05303       larger_elt = lookup (new_and, HASH (new_and, tmode), tmode);
05304       if (larger_elt == 0)
05305         continue;
05306 
05307       for (larger_elt = larger_elt->first_same_value;
05308            larger_elt; larger_elt = larger_elt->next_same_value)
05309         if (GET_CODE (larger_elt->exp) == REG)
05310           {
05311       src_related
05312         = gen_lowpart_if_possible (mode, larger_elt->exp);
05313       break;
05314           }
05315 
05316       if (src_related)
05317         break;
05318     }
05319       }
05320   }
05321 
05322 #ifdef LOAD_EXTEND_OP
05323       /* See if a MEM has already been loaded with a widening operation;
05324    if it has, we can use a subreg of that.  Many CISC machines
05325    also have such operations, but this is only likely to be
05326    beneficial these machines.  */
05327 
05328       if (flag_expensive_optimizations && src_related == 0
05329     && (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
05330     && GET_MODE_CLASS (mode) == MODE_INT
05331     && GET_CODE (src) == MEM && ! do_not_record
05332     && LOAD_EXTEND_OP (mode) != NIL)
05333   {
05334     enum machine_mode tmode;
05335 
05336     /* Set what we are trying to extend and the operation it might
05337        have been extended with.  */
05338     PUT_CODE (memory_extend_rtx, LOAD_EXTEND_OP (mode));
05339     XEXP (memory_extend_rtx, 0) = src;
05340 
05341     for (tmode = GET_MODE_WIDER_MODE (mode);
05342          GET_MODE_SIZE (tmode) <= UNITS_PER_WORD;
05343          tmode = GET_MODE_WIDER_MODE (tmode))
05344       {
05345         struct table_elt *larger_elt;
05346 
05347         PUT_MODE (memory_extend_rtx, tmode);
05348         larger_elt = lookup (memory_extend_rtx,
05349            HASH (memory_extend_rtx, tmode), tmode);
05350         if (larger_elt == 0)
05351     continue;
05352 
05353         for (larger_elt = larger_elt->first_same_value;
05354        larger_elt; larger_elt = larger_elt->next_same_value)
05355     if (GET_CODE (larger_elt->exp) == REG)
05356       {
05357         src_related = gen_lowpart_if_possible (mode,
05358                  larger_elt->exp);
05359         break;
05360       }
05361 
05362         if (src_related)
05363     break;
05364       }
05365   }
05366 #endif /* LOAD_EXTEND_OP */
05367 
05368       if (src == src_folded)
05369   src_folded = 0;
05370 
05371       /* At this point, ELT, if nonzero, points to a class of expressions
05372          equivalent to the source of this SET and SRC, SRC_EQV, SRC_FOLDED,
05373    and SRC_RELATED, if nonzero, each contain additional equivalent
05374    expressions.  Prune these latter expressions by deleting expressions
05375    already in the equivalence class.
05376 
05377    Check for an equivalent identical to the destination.  If found,
05378    this is the preferred equivalent since it will likely lead to
05379    elimination of the insn.  Indicate this by placing it in
05380    `src_related'.  */
05381 
05382       if (elt)
05383   elt = elt->first_same_value;
05384       for (p = elt; p; p = p->next_same_value)
05385   {
05386     enum rtx_code code = GET_CODE (p->exp);
05387 
05388     /* If the expression is not valid, ignore it.  Then we do not
05389        have to check for validity below.  In most cases, we can use
05390        `rtx_equal_p', since canonicalization has already been done.  */
05391     if (code != REG && ! exp_equiv_p (p->exp, p->exp, 1, 0))
05392       continue;
05393 
05394     /* Also skip paradoxical subregs, unless that's what we're
05395        looking for.  */
05396     if (code == SUBREG
05397         && (GET_MODE_SIZE (GET_MODE (p->exp))
05398       > GET_MODE_SIZE (GET_MODE (SUBREG_REG (p->exp))))
05399         && ! (src != 0
05400         && GET_CODE (src) == SUBREG
05401         && GET_MODE (src) == GET_MODE (p->exp)
05402         && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (src)))
05403       < GET_MODE_SIZE (GET_MODE (SUBREG_REG (p->exp))))))
05404       continue;
05405 
05406     if (src && GET_CODE (src) == code && rtx_equal_p (src, p->exp))
05407       src = 0;
05408     else if (src_folded && GET_CODE (src_folded) == code
05409        && rtx_equal_p (src_folded, p->exp))
05410       src_folded = 0;
05411     else if (src_eqv_here && GET_CODE (src_eqv_here) == code
05412        && rtx_equal_p (src_eqv_here, p->exp))
05413       src_eqv_here = 0;
05414     else if (src_related && GET_CODE (src_related) == code
05415        && rtx_equal_p (src_related, p->exp))
05416       src_related = 0;
05417 
05418     /* This is the same as the destination of the insns, we want
05419        to prefer it.  Copy it to src_related.  The code below will
05420        then give it a negative cost.  */
05421     if (GET_CODE (dest) == code && rtx_equal_p (p->exp, dest))
05422       src_related = dest;
05423   }
05424 
05425       /* Find the cheapest valid equivalent, trying all the available
05426          possibilities.  Prefer items not in the hash table to ones
05427          that are when they are equal cost.  Note that we can never
05428          worsen an insn as the current contents will also succeed.
05429    If we find an equivalent identical to the destination, use it as best,
05430    since this insn will probably be eliminated in that case.  */
05431       if (src)
05432   {
05433     if (rtx_equal_p (src, dest))
05434       src_cost = src_regcost = -1;
05435     else
05436       {
05437         src_cost = COST (src);
05438         src_regcost = approx_reg_cost (src);
05439       }
05440   }
05441 
05442       if (src_eqv_here)
05443   {
05444     if (rtx_equal_p (src_eqv_here, dest))
05445       src_eqv_cost = src_eqv_regcost = -1;
05446     else
05447       {
05448         src_eqv_cost = COST (src_eqv_here);
05449         src_eqv_regcost = approx_reg_cost (src_eqv_here);
05450       }
05451   }
05452 
05453       if (src_folded)
05454   {
05455     if (rtx_equal_p (src_folded, dest))
05456       src_folded_cost = src_folded_regcost = -1;
05457     else
05458       {
05459         src_folded_cost = COST (src_folded);
05460         src_folded_regcost = approx_reg_cost (src_folded);
05461       }
05462   }
05463 
05464       if (src_related)
05465   {
05466     if (rtx_equal_p (src_related, dest))
05467       src_related_cost = src_related_regcost = -1;
05468     else
05469       {
05470         src_related_cost = COST (src_related);
05471         src_related_regcost = approx_reg_cost (src_related);
05472       }
05473   }
05474 
05475       /* If this was an indirect jump insn, a known label will really be
05476    cheaper even though it looks more expensive.  */
05477       if (dest == pc_rtx && src_const && GET_CODE (src_const) == LABEL_REF)
05478   src_folded = src_const, src_folded_cost = src_folded_regcost = -1;
05479 
05480       /* Terminate loop when replacement made.  This must terminate since
05481          the current contents will be tested and will always be valid.  */
05482       while (1)
05483   {
05484     rtx trial;
05485 
05486     /* Skip invalid entries.  */
05487     while (elt && GET_CODE (elt->exp) != REG
05488      && ! exp_equiv_p (elt->exp, elt->exp, 1, 0))
05489       elt = elt->next_same_value;
05490 
05491     /* A paradoxical subreg would be bad here: it'll be the right
05492        size, but later may be adjusted so that the upper bits aren't
05493        what we want.  So reject it.  */
05494     if (elt != 0
05495         && GET_CODE (elt->exp) == SUBREG
05496         && (GET_MODE_SIZE (GET_MODE (elt->exp))
05497       > GET_MODE_SIZE (GET_MODE (SUBREG_REG (elt->exp))))
05498         /* It is okay, though, if the rtx we're trying to match
05499      will ignore any of the bits we can't predict.  */
05500         && ! (src != 0
05501         && GET_CODE (src) == SUBREG
05502         && GET_MODE (src) == GET_MODE (elt->exp)
05503         && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (src)))
05504       < GET_MODE_SIZE (GET_MODE (SUBREG_REG (elt->exp))))))
05505       {
05506         elt = elt->next_same_value;
05507         continue;
05508       }
05509 
05510     if (elt)
05511       {
05512         src_elt_cost = elt->cost;
05513         src_elt_regcost = elt->regcost;
05514       }
05515 
05516     /* Find cheapest and skip it for the next time.   For items
05517        of equal cost, use this order:
05518        src_folded, src, src_eqv, src_related and hash table entry.  */
05519     if (src_folded
05520         && preferrable (src_folded_cost, src_folded_regcost,
05521             src_cost, src_regcost) <= 0
05522         && preferrable (src_folded_cost, src_folded_regcost,
05523             src_eqv_cost, src_eqv_regcost) <= 0
05524         && preferrable (src_folded_cost, src_folded_regcost,
05525             src_related_cost, src_related_regcost) <= 0
05526         && preferrable (src_folded_cost, src_folded_regcost,
05527             src_elt_cost, src_elt_regcost) <= 0)
05528       {
05529         trial = src_folded, src_folded_cost = MAX_COST;
05530         if (src_folded_force_flag)
05531     trial = force_const_mem (mode, trial);
05532       }
05533     else if (src
05534        && preferrable (src_cost, src_regcost,
05535            src_eqv_cost, src_eqv_regcost) <= 0
05536        && preferrable (src_cost, src_regcost,
05537            src_related_cost, src_related_regcost) <= 0
05538        && preferrable (src_cost, src_regcost,
05539            src_elt_cost, src_elt_regcost) <= 0)
05540       trial = src, src_cost = MAX_COST;
05541     else if (src_eqv_here
05542        && preferrable (src_eqv_cost, src_eqv_regcost,
05543            src_related_cost, src_related_regcost) <= 0
05544        && preferrable (src_eqv_cost, src_eqv_regcost,
05545            src_elt_cost, src_elt_regcost) <= 0)
05546       trial = copy_rtx (src_eqv_here), src_eqv_cost = MAX_COST;
05547     else if (src_related
05548        && preferrable (src_related_cost, src_related_regcost,
05549            src_elt_cost, src_elt_regcost) <= 0)
05550       trial = copy_rtx (src_related), src_related_cost = MAX_COST;
05551     else
05552       {
05553         trial = copy_rtx (elt->exp);
05554         elt = elt->next_same_value;
05555         src_elt_cost = MAX_COST;
05556       }
05557 
05558     /* We don't normally have an insn matching (set (pc) (pc)), so
05559        check for this separately here.  We will delete such an
05560        insn below.
05561 
05562        For other cases such as a table jump or conditional jump
05563        where we know the ultimate target, go ahead and replace the
05564        operand.  While that may not make a valid insn, we will
05565        reemit the jump below (and also insert any necessary
05566        barriers).  */
05567     if (n_sets == 1 && dest == pc_rtx
05568         && (trial == pc_rtx
05569       || (GET_CODE (trial) == LABEL_REF
05570           && ! condjump_p (insn))))
05571       {
05572         SET_SRC (sets[i].rtl) = trial;
05573         cse_jumps_altered = 1;
05574         break;
05575       }
05576 
05577     /* Look for a substitution that makes a valid insn.  */
05578     else if (validate_change (insn, &SET_SRC (sets[i].rtl), trial, 0))
05579       {
05580         /* If we just made a substitution inside a libcall, then we
05581      need to make the same substitution in any notes attached
05582      to the RETVAL insn.  */
05583         if (libcall_insn
05584       && (GET_CODE (sets[i].orig_src) == REG
05585           || GET_CODE (sets[i].orig_src) == SUBREG
05586           || GET_CODE (sets[i].orig_src) == MEM))
05587     replace_rtx (REG_NOTES (libcall_insn), sets[i].orig_src,
05588            canon_reg (SET_SRC (sets[i].rtl), insn));
05589 
05590         /* The result of apply_change_group can be ignored; see
05591      canon_reg.  */
05592 
05593         validate_change (insn, &SET_SRC (sets[i].rtl),
05594              canon_reg (SET_SRC (sets[i].rtl), insn),
05595              1);
05596         apply_change_group ();
05597         break;
05598       }
05599 
05600     /* If we previously found constant pool entries for
05601        constants and this is a constant, try making a
05602        pool entry.  Put it in src_folded unless we already have done
05603        this since that is where it likely came from.  */
05604 
05605     else if (constant_pool_entries_cost
05606        && CONSTANT_P (trial)
05607        /* Reject cases that will abort in decode_rtx_const.
05608           On the alpha when simplifying a switch, we get
05609           (const (truncate (minus (label_ref) (label_ref)))).  */
05610        && ! (GET_CODE (trial) == CONST
05611        && GET_CODE (XEXP (trial, 0)) == TRUNCATE)
05612        /* Likewise on IA-64, except without the truncate.  */
05613        && ! (GET_CODE (trial) == CONST
05614        && GET_CODE (XEXP (trial, 0)) == MINUS
05615        && GET_CODE (XEXP (XEXP (trial, 0), 0)) == LABEL_REF
05616        && GET_CODE (XEXP (XEXP (trial, 0), 1)) == LABEL_REF)
05617        && (src_folded == 0
05618            || (GET_CODE (src_folded) != MEM
05619          && ! src_folded_force_flag))
05620        && GET_MODE_CLASS (mode) != MODE_CC
05621        && mode != VOIDmode)
05622       {
05623         src_folded_force_flag = 1;
05624         src_folded = trial;
05625         src_folded_cost = constant_pool_entries_cost;
05626       }
05627   }
05628 
05629       src = SET_SRC (sets[i].rtl);
05630 
05631       /* In general, it is good to have a SET with SET_SRC == SET_DEST.
05632    However, there is an important exception:  If both are registers
05633    that are not the head of their equivalence class, replace SET_SRC
05634    with the head of the class.  If we do not do this, we will have
05635    both registers live over a portion of the basic block.  This way,
05636    their lifetimes will likely abut instead of overlapping.  */
05637       if (GET_CODE (dest) == REG
05638     && REGNO_QTY_VALID_P (REGNO (dest)))
05639   {
05640     int dest_q = REG_QTY (REGNO (dest));
05641     struct qty_table_elem *dest_ent = &qty_table[dest_q];
05642 
05643     if (dest_ent->mode == GET_MODE (dest)
05644         && dest_ent->first_reg != REGNO (dest)
05645         && GET_CODE (src) == REG && REGNO (src) == REGNO (dest)
05646         /* Don't do this if the original insn had a hard reg as
05647      SET_SRC or SET_DEST.  */
05648         && (GET_CODE (sets[i].src) != REG
05649       || REGNO (sets[i].src) >= FIRST_PSEUDO_REGISTER)
05650         && (GET_CODE (dest) != REG || REGNO (dest) >= FIRST_PSEUDO_REGISTER))
05651       /* We can't call canon_reg here because it won't do anything if
05652          SRC is a hard register.  */
05653       {
05654         int src_q = REG_QTY (REGNO (src));
05655         struct qty_table_elem *src_ent = &qty_table[src_q];
05656         int first = src_ent->first_reg;
05657         rtx new_src
05658     = (first >= FIRST_PSEUDO_REGISTER
05659        ? regno_reg_rtx[first] : gen_rtx_REG (GET_MODE (src), first));
05660 
05661         /* We must use validate-change even for this, because this
05662      might be a special no-op instruction, suitable only to
05663      tag notes onto.  */
05664         if (validate_change (insn, &SET_SRC (sets[i].rtl), new_src, 0))
05665     {
05666       src = new_src;
05667       /* If we had a constant that is cheaper than what we are now
05668          setting SRC to, use that constant.  We ignored it when we
05669          thought we could make this into a no-op.  */
05670       if (src_const && COST (src_const) < COST (src)
05671           && validate_change (insn, &SET_SRC (sets[i].rtl),
05672             src_const, 0))
05673         src = src_const;
05674     }
05675       }
05676   }
05677 
05678       /* If we made a change, recompute SRC values.  */
05679       if (src != sets[i].src)
05680   {
05681     cse_altered = 1;
05682     do_not_record = 0;
05683     hash_arg_in_memory = 0;
05684     sets[i].src = src;
05685     sets[i].src_hash = HASH (src, mode);
05686     sets[i].src_volatile = do_not_record;
05687     sets[i].src_in_memory = hash_arg_in_memory;
05688     sets[i].src_elt = lookup (src, sets[i].src_hash, mode);
05689   }
05690 
05691       /* If this is a single SET, we are setting a register, and we have an
05692    equivalent constant, we want to add a REG_NOTE.   We don't want
05693    to write a REG_EQUAL note for a constant pseudo since verifying that
05694    that pseudo hasn't been eliminated is a pain.  Such a note also
05695    won't help anything.
05696 
05697    Avoid a REG_EQUAL note for (CONST (MINUS (LABEL_REF) (LABEL_REF)))
05698    which can be created for a reference to a compile time computable
05699    entry in a jump table.  */
05700 
05701       if (n_sets == 1 && src_const && GET_CODE (dest) == REG
05702     && GET_CODE (src_const) != REG
05703     && ! (GET_CODE (src_const) == CONST
05704     && GET_CODE (XEXP (src_const, 0)) == MINUS
05705     && GET_CODE (XEXP (XEXP (src_const, 0), 0)) == LABEL_REF
05706     && GET_CODE (XEXP (XEXP (src_const, 0), 1)) == LABEL_REF))
05707   {
05708     /* Make sure that the rtx is not shared with any other insn.  */
05709     src_const = copy_rtx (src_const);
05710 
05711     /* Record the actual constant value in a REG_EQUAL note, making
05712        a new one if one does not already exist.  */
05713     set_unique_reg_note (insn, REG_EQUAL, src_const);
05714 
05715     /* If storing a constant value in a register that
05716        previously held the constant value 0,
05717        record this fact with a REG_WAS_0 note on this insn.
05718 
05719        Note that the *register* is required to have previously held 0,
05720        not just any register in the quantity and we must point to the
05721        insn that set that register to zero.
05722 
05723        Rather than track each register individually, we just see if
05724        the last set for this quantity was for this register.  */
05725 
05726     if (REGNO_QTY_VALID_P (REGNO (dest)))
05727       {
05728         int dest_q = REG_QTY (REGNO (dest));
05729         struct qty_table_elem *dest_ent = &qty_table[dest_q];
05730 
05731         if (dest_ent->const_rtx == const0_rtx)
05732     {
05733       /* See if we previously had a REG_WAS_0 note.  */
05734       rtx note = find_reg_note (insn, REG_WAS_0, NULL_RTX);
05735       rtx const_insn = dest_ent->const_insn;
05736 
05737       if ((tem = single_set (const_insn)) != 0
05738           && rtx_equal_p (SET_DEST (tem), dest))
05739         {
05740           if (note)
05741       XEXP (note, 0) = const_insn;
05742           else
05743       REG_NOTES (insn)
05744         = gen_rtx_INSN_LIST (REG_WAS_0, const_insn,
05745                  REG_NOTES (insn));
05746         }
05747     }
05748       }
05749   }
05750 
05751       /* Now deal with the destination.  */
05752       do_not_record = 0;
05753 
05754       /* Look within any SIGN_EXTRACT or ZERO_EXTRACT
05755    to the MEM or REG within it.  */
05756       while (GET_CODE (dest) == SIGN_EXTRACT
05757        || GET_CODE (dest) == ZERO_EXTRACT
05758        || GET_CODE (dest) == SUBREG
05759        || GET_CODE (dest) == STRICT_LOW_PART)
05760   dest = XEXP (dest, 0);
05761 
05762       sets[i].inner_dest = dest;
05763 
05764       if (GET_CODE (dest) == MEM)
05765   {
05766 #ifdef PUSH_ROUNDING
05767     /* Stack pushes invalidate the stack pointer.  */
05768     rtx addr = XEXP (dest, 0);
05769     if (GET_RTX_CLASS (GET_CODE (addr)) == 'a'
05770         && XEXP (addr, 0) == stack_pointer_rtx)
05771       invalidate (stack_pointer_rtx, Pmode);
05772 #endif
05773     dest = fold_rtx (dest, insn);
05774   }
05775 
05776       /* Compute the hash code of the destination now,
05777    before the effects of this instruction are recorded,
05778    since the register values used in the address computation
05779    are those before this instruction.  */
05780       sets[i].dest_hash = HASH (dest, mode);
05781 
05782       /* Don't enter a bit-field in the hash table
05783    because the value in it after the store
05784    may not equal what was stored, due to truncation.  */
05785 
05786       if (GET_CODE (SET_DEST (sets[i].rtl)) == ZERO_EXTRACT
05787     || GET_CODE (SET_DEST (sets[i].rtl)) == SIGN_EXTRACT)
05788   {
05789     rtx width = XEXP (SET_DEST (sets[i].rtl), 1);
05790 
05791     if (src_const != 0 && GET_CODE (src_const) == CONST_INT
05792         && GET_CODE (width) == CONST_INT
05793         && INTVAL (width) < HOST_BITS_PER_WIDE_INT
05794         && ! (INTVAL (src_const)
05795         & ((HOST_WIDE_INT) (-1) << INTVAL (width))))
05796       /* Exception: if the value is constant,
05797          and it won't be truncated, record it.  */
05798       ;
05799     else
05800       {
05801         /* This is chosen so that the destination will be invalidated
05802      but no new value will be recorded.
05803      We must invalidate because sometimes constant
05804      values can be recorded for bitfields.  */
05805         sets[i].src_elt = 0;
05806         sets[i].src_volatile = 1;
05807         src_eqv = 0;
05808         src_eqv_elt = 0;
05809       }
05810   }
05811 
05812       /* If only one set in a JUMP_INSN and it is now a no-op, we can delete
05813    the insn.  */
05814       else if (n_sets == 1 && dest == pc_rtx && src == pc_rtx)
05815   {
05816     /* One less use of the label this insn used to jump to.  */
05817     delete_insn (insn);
05818     cse_jumps_altered = 1;
05819     /* No more processing for this set.  */
05820     sets[i].rtl = 0;
05821   }
05822 
05823       /* If this SET is now setting PC to a label, we know it used to
05824    be a conditional or computed branch.  */
05825       else if (dest == pc_rtx && GET_CODE (src) == LABEL_REF)
05826   {
05827     /* Now emit a BARRIER after the unconditional jump.  */
05828     if (NEXT_INSN (insn) == 0
05829         || GET_CODE (NEXT_INSN (insn)) != BARRIER)
05830       emit_barrier_after (insn);
05831 
05832     /* We reemit the jump in as many cases as possible just in
05833        case the form of an unconditional jump is significantly
05834        different than a computed jump or conditional jump.
05835 
05836        If this insn has multiple sets, then reemitting the
05837        jump is nontrivial.  So instead we just force rerecognition
05838        and hope for the best.  */
05839     if (n_sets == 1)
05840       {
05841         rtx new = emit_jump_insn_after (gen_jump (XEXP (src, 0)), insn);
05842 
05843         JUMP_LABEL (new) = XEXP (src, 0);
05844         LABEL_NUSES (XEXP (src, 0))++;
05845         delete_insn (insn);
05846         insn = new;
05847 
05848         /* Now emit a BARRIER after the unconditional jump.  */
05849         if (NEXT_INSN (insn) == 0
05850       || GET_CODE (NEXT_INSN (insn)) != BARRIER)
05851     emit_barrier_after (insn);
05852       }
05853     else
05854       INSN_CODE (insn) = -1;
05855 
05856     never_reached_warning (insn, NULL);
05857 
05858     /* Do not bother deleting any unreachable code,
05859        let jump/flow do that.  */
05860 
05861     cse_jumps_altered = 1;
05862     sets[i].rtl = 0;
05863   }
05864 
05865       /* If destination is volatile, invalidate it and then do no further
05866    processing for this assignment.  */
05867 
05868       else if (do_not_record)
05869   {
05870     if (GET_CODE (dest) == REG || GET_CODE (dest) == SUBREG)
05871       invalidate (dest, VOIDmode);
05872     else if (GET_CODE (dest) == MEM)
05873       {
05874         /* Outgoing arguments for a libcall don't
05875      affect any recorded expressions.  */
05876         if (! libcall_insn || insn == libcall_insn)
05877     invalidate (dest, VOIDmode);
05878       }
05879     else if (GET_CODE (dest) == STRICT_LOW_PART
05880        || GET_CODE (dest) == ZERO_EXTRACT)
05881       invalidate (XEXP (dest, 0), GET_MODE (dest));
05882     sets[i].rtl = 0;
05883   }
05884 
05885       if (sets[i].rtl != 0 && dest != SET_DEST (sets[i].rtl))
05886   sets[i].dest_hash = HASH (SET_DEST (sets[i].rtl), mode);
05887 
05888 #ifdef HAVE_cc0
05889       /* If setting CC0, record what it was set to, or a constant, if it
05890    is equivalent to a constant.  If it is being set to a floating-point
05891    value, make a COMPARE with the appropriate constant of 0.  If we
05892    don't do this, later code can interpret this as a test against
05893    const0_rtx, which can cause problems if we try to put it into an
05894    insn as a floating-point operand.  */
05895       if (dest == cc0_rtx)
05896   {
05897     this_insn_cc0 = src_const && mode != VOIDmode ? src_const : src;
05898     this_insn_cc0_mode = mode;
05899     if (FLOAT_MODE_P (mode))
05900       this_insn_cc0 = gen_rtx_COMPARE (VOIDmode, this_insn_cc0,
05901                CONST0_RTX (mode));
05902   }
05903 #endif
05904     }
05905 
05906   /* Now enter all non-volatile source expressions in the hash table
05907      if they are not already present.
05908      Record their equivalence classes in src_elt.
05909      This way we can insert the corresponding destinations into
05910      the same classes even if the actual sources are no longer in them
05911      (having been invalidated).  */
05912 
05913   if (src_eqv && src_eqv_elt == 0 && sets[0].rtl != 0 && ! src_eqv_volatile
05914       && ! rtx_equal_p (src_eqv, SET_DEST (sets[0].rtl)))
05915     {
05916       struct table_elt *elt;
05917       struct table_elt *classp = sets[0].src_elt;
05918       rtx dest = SET_DEST (sets[0].rtl);
05919       enum machine_mode eqvmode = GET_MODE (dest);
05920 
05921       if (GET_CODE (dest) == STRICT_LOW_PART)
05922   {
05923     eqvmode = GET_MODE (SUBREG_REG (XEXP (dest, 0)));
05924     classp = 0;
05925   }
05926       if (insert_regs (src_eqv, classp, 0))
05927   {
05928     rehash_using_reg (src_eqv);
05929     src_eqv_hash = HASH (src_eqv, eqvmode);
05930   }
05931       elt = insert (src_eqv, classp, src_eqv_hash, eqvmode);
05932       elt->in_memory = src_eqv_in_memory;
05933       src_eqv_elt = elt;
05934 
05935       /* Check to see if src_eqv_elt is the same as a set source which
05936    does not yet have an elt, and if so set the elt of the set source
05937    to src_eqv_elt.  */
05938       for (i = 0; i < n_sets; i++)
05939   if (sets[i].rtl && sets[i].src_elt == 0
05940       && rtx_equal_p (SET_SRC (sets[i].rtl), src_eqv))
05941     sets[i].src_elt = src_eqv_elt;
05942     }
05943 
05944   for (i = 0; i < n_sets; i++)
05945     if (sets[i].rtl && ! sets[i].src_volatile
05946   && ! rtx_equal_p (SET_SRC (sets[i].rtl), SET_DEST (sets[i].rtl)))
05947       {
05948   if (GET_CODE (SET_DEST (sets[i].rtl)) == STRICT_LOW_PART)
05949     {
05950       /* REG_EQUAL in setting a STRICT_LOW_PART
05951          gives an equivalent for the entire destination register,
05952          not just for the subreg being stored in now.
05953          This is a more interesting equivalence, so we arrange later
05954          to treat the entire reg as the destination.  */
05955       sets[i].src_elt = src_eqv_elt;
05956       sets[i].src_hash = src_eqv_hash;
05957     }
05958   else
05959     {
05960       /* Insert source and constant equivalent into hash table, if not
05961          already present.  */
05962       struct table_elt *classp = src_eqv_elt;
05963       rtx src = sets[i].src;
05964       rtx dest = SET_DEST (sets[i].rtl);
05965       enum machine_mode mode
05966         = GET_MODE (src) == VOIDmode ? GET_MODE (dest) : GET_MODE (src);
05967 
05968       if (sets[i].src_elt == 0)
05969         {
05970     /* Don't put a hard register source into the table if this is
05971        the last insn of a libcall.  In this case, we only need
05972        to put src_eqv_elt in src_elt.  */
05973     if (! find_reg_note (insn, REG_RETVAL, NULL_RTX))
05974       {
05975         struct table_elt *elt;
05976 
05977         /* Note that these insert_regs calls cannot remove
05978            any of the src_elt's, because they would have failed to
05979            match if not still valid.  */
05980         if (insert_regs (src, classp, 0))
05981           {
05982       rehash_using_reg (src);
05983       sets[i].src_hash = HASH (src, mode);
05984           }
05985         elt = insert (src, classp, sets[i].src_hash, mode);
05986         elt->in_memory = sets[i].src_in_memory;
05987         sets[i].src_elt = classp = elt;
05988       }
05989     else
05990       sets[i].src_elt = classp;
05991         }
05992       if (sets[i].src_const && sets[i].src_const_elt == 0
05993     && src != sets[i].src_const
05994     && ! rtx_equal_p (sets[i].src_const, src))
05995         sets[i].src_elt = insert (sets[i].src_const, classp,
05996           sets[i].src_const_hash, mode);
05997     }
05998       }
05999     else if (sets[i].src_elt == 0)
06000       /* If we did not insert the source into the hash table (e.g., it was
06001    volatile), note the equivalence class for the REG_EQUAL value, if any,
06002    so that the destination goes into that class.  */
06003       sets[i].src_elt = src_eqv_elt;
06004 
06005   invalidate_from_clobbers (x);
06006 
06007   /* Some registers are invalidated by subroutine calls.  Memory is
06008      invalidated by non-constant calls.  */
06009 
06010   if (GET_CODE (insn) == CALL_INSN)
06011     {
06012       if (! CONST_OR_PURE_CALL_P (insn))
06013   invalidate_memory ();
06014       invalidate_for_call ();
06015     }
06016 
06017   /* Now invalidate everything set by this instruction.
06018      If a SUBREG or other funny destination is being set,
06019      sets[i].rtl is still nonzero, so here we invalidate the reg
06020      a part of which is being set.  */
06021 
06022   for (i = 0; i < n_sets; i++)
06023     if (sets[i].rtl)
06024       {
06025   /* We can't use the inner dest, because the mode associated with
06026      a ZERO_EXTRACT is significant.  */
06027   rtx dest = SET_DEST (sets[i].rtl);
06028 
06029   /* Needed for registers to remove the register from its
06030      previous quantity's chain.
06031      Needed for memory if this is a nonvarying address, unless
06032      we have just done an invalidate_memory that covers even those.  */
06033   if (GET_CODE (dest) == REG || GET_CODE (dest) == SUBREG)
06034     invalidate (dest, VOIDmode);
06035   else if (GET_CODE (dest) == MEM)
06036     {
06037       /* Outgoing arguments for a libcall don't
06038          affect any recorded expressions.  */
06039       if (! libcall_insn || insn == libcall_insn)
06040         invalidate (dest, VOIDmode);
06041     }
06042   else if (GET_CODE (dest) == STRICT_LOW_PART
06043      || GET_CODE (dest) == ZERO_EXTRACT)
06044     invalidate (XEXP (dest, 0), GET_MODE (dest));
06045       }
06046 
06047   /* A volatile ASM invalidates everything.  */
06048   if (GET_CODE (insn) == INSN
06049       && GET_CODE (PATTERN (insn)) == ASM_OPERANDS
06050       && MEM_VOLATILE_P (PATTERN (insn)))
06051     flush_hash_table ();
06052 
06053   /* Make sure registers mentioned in destinations
06054      are safe for use in an expression to be inserted.
06055      This removes from the hash table
06056      any invalid entry that refers to one of these registers.
06057 
06058      We don't care about the return value from mention_regs because
06059      we are going to hash the SET_DEST values unconditionally.  */
06060 
06061   for (i = 0; i < n_sets; i++)
06062     {
06063       if (sets[i].rtl)
06064   {
06065     rtx x = SET_DEST (sets[i].rtl);
06066 
06067     if (GET_CODE (x) != REG)
06068       mention_regs (x);
06069     else
06070       {
06071         /* We used to rely on all references to a register becoming
06072      inaccessible when a register changes to a new quantity,
06073      since that changes the hash code.  However, that is not
06074      safe, since after HASH_SIZE new quantities we get a
06075      hash 'collision' of a register with its own invalid
06076      entries.  And since SUBREGs have been changed not to
06077      change their hash code with the hash code of the register,
06078      it wouldn't work any longer at all.  So we have to check
06079      for any invalid references lying around now.
06080      This code is similar to the REG case in mention_regs,
06081      but it knows that reg_tick has been incremented, and
06082      it leaves reg_in_table as -1 .  */
06083         unsigned int regno = REGNO (x);
06084         unsigned int endregno
06085     = regno + (regno >= FIRST_PSEUDO_REGISTER ? 1
06086          : HARD_REGNO_NREGS (regno, GET_MODE (x)));
06087         unsigned int i;
06088 
06089         for (i = regno; i < endregno; i++)
06090     {
06091       if (REG_IN_TABLE (i) >= 0)
06092         {
06093           remove_invalid_refs (i);
06094           REG_IN_TABLE (i) = -1;
06095         }
06096     }
06097       }
06098   }
06099     }
06100 
06101   /* We may have just removed some of the src_elt's from the hash table.
06102      So replace each one with the current head of the same class.  */
06103 
06104   for (i = 0; i < n_sets; i++)
06105     if (sets[i].rtl)
06106       {
06107   if (sets[i].src_elt && sets[i].src_elt->first_same_value == 0)
06108     /* If elt was removed, find current head of same class,
06109        or 0 if nothing remains of that class.  */
06110     {
06111       struct table_elt *elt = sets[i].src_elt;
06112 
06113       while (elt && elt->prev_same_value)
06114         elt = elt->prev_same_value;
06115 
06116       while (elt && elt->first_same_value == 0)
06117         elt = elt->next_same_value;
06118       sets[i].src_elt = elt ? elt->first_same_value : 0;
06119     }
06120       }
06121 
06122   /* Now insert the destinations into their equivalence classes.  */
06123 
06124   for (i = 0; i < n_sets; i++)
06125     if (sets[i].rtl)
06126       {
06127   rtx dest = SET_DEST (sets[i].rtl);
06128   rtx inner_dest = sets[i].inner_dest;
06129   struct table_elt *elt;
06130 
06131   /* Don't record value if we are not supposed to risk allocating
06132      floating-point values in registers that might be wider than
06133      memory.  */
06134   if ((flag_float_store
06135        && GET_CODE (dest) == MEM
06136        && FLOAT_MODE_P (GET_MODE (dest)))
06137       /* Don't record BLKmode values, because we don't know the
06138          size of it, and can't be sure that other BLKmode values
06139          have the same or smaller size.  */
06140       || GET_MODE (dest) == BLKmode
06141       /* Don't record values of destinations set inside a libcall block
06142          since we might delete the libcall.  Things should have been set
06143          up so we won't want to reuse such a value, but we play it safe
06144          here.  */
06145       || libcall_insn
06146       /* If we didn't put a REG_EQUAL value or a source into the hash
06147          table, there is no point is recording DEST.  */
06148       || sets[i].src_elt == 0
06149       /* If DEST is a paradoxical SUBREG and SRC is a ZERO_EXTEND
06150          or SIGN_EXTEND, don't record DEST since it can cause
06151          some tracking to be wrong.
06152 
06153          ??? Think about this more later.  */
06154       || (GET_CODE (dest) == SUBREG
06155     && (GET_MODE_SIZE (GET_MODE (dest))
06156         > GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))))
06157     && (GET_CODE (sets[i].src) == SIGN_EXTEND
06158         || GET_CODE (sets[i].src) == ZERO_EXTEND)))
06159     continue;
06160 
06161   /* STRICT_LOW_PART isn't part of the value BEING set,
06162      and neither is the SUBREG inside it.
06163      Note that in this case SETS[I].SRC_ELT is really SRC_EQV_ELT.  */
06164   if (GET_CODE (dest) == STRICT_LOW_PART)
06165     dest = SUBREG_REG (XEXP (dest, 0));
06166 
06167   if (GET_CODE (dest) == REG || GET_CODE (dest) == SUBREG)
06168     /* Registers must also be inserted into chains for quantities.  */
06169     if (insert_regs (dest, sets[i].src_elt, 1))
06170       {
06171         /* If `insert_regs' changes something, the hash code must be
06172      recalculated.  */
06173         rehash_using_reg (dest);
06174         sets[i].dest_hash = HASH (dest, GET_MODE (dest));
06175       }
06176 
06177   if (GET_CODE (inner_dest) == MEM
06178       && GET_CODE (XEXP (inner_dest, 0)) == ADDRESSOF)
06179     /* Given (SET (MEM (ADDRESSOF (X))) Y) we don't want to say
06180        that (MEM (ADDRESSOF (X))) is equivalent to Y.
06181        Consider the case in which the address of the MEM is
06182        passed to a function, which alters the MEM.  Then, if we
06183        later use Y instead of the MEM we'll miss the update.  */
06184     elt = insert (dest, 0, sets[i].dest_hash, GET_MODE (dest));
06185   else
06186     elt = insert (dest, sets[i].src_elt,
06187       sets[i].dest_hash, GET_MODE (dest));
06188 
06189   elt->in_memory = (GET_CODE (sets[i].inner_dest) == MEM
06190         && (! RTX_UNCHANGING_P (sets[i].inner_dest)
06191             || FIXED_BASE_PLUS_P (XEXP (sets[i].inner_dest,
06192                 0))));
06193 
06194   /* If we have (set (subreg:m1 (reg:m2 foo) 0) (bar:m1)), M1 is no
06195      narrower than M2, and both M1 and M2 are the same number of words,
06196      we are also doing (set (reg:m2 foo) (subreg:m2 (bar:m1) 0)) so
06197      make that equivalence as well.
06198 
06199      However, BAR may have equivalences for which gen_lowpart_if_possible
06200      will produce a simpler value than gen_lowpart_if_possible applied to
06201      BAR (e.g., if BAR was ZERO_EXTENDed from M2), so we will scan all
06202      BAR's equivalences.  If we don't get a simplified form, make
06203      the SUBREG.  It will not be used in an equivalence, but will
06204      cause two similar assignments to be detected.
06205 
06206      Note the loop below will find SUBREG_REG (DEST) since we have
06207      already entered SRC and DEST of the SET in the table.  */
06208 
06209   if (GET_CODE (dest) == SUBREG
06210       && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) - 1)
06211      / UNITS_PER_WORD)
06212     == (GET_MODE_SIZE (GET_MODE (dest)) - 1) / UNITS_PER_WORD)
06213       && (GET_MODE_SIZE (GET_MODE (dest))
06214     >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))))
06215       && sets[i].src_elt != 0)
06216     {
06217       enum machine_mode new_mode = GET_MODE (SUBREG_REG (dest));
06218       struct table_elt *elt, *classp = 0;
06219 
06220       for (elt = sets[i].src_elt->first_same_value; elt;
06221      elt = elt->next_same_value)
06222         {
06223     rtx new_src = 0;
06224     unsigned src_hash;
06225     struct table_elt *src_elt;
06226     int byte = 0;
06227 
06228     /* Ignore invalid entries.  */
06229     if (GET_CODE (elt->exp) != REG
06230         && ! exp_equiv_p (elt->exp, elt->exp, 1, 0))
06231       continue;
06232 
06233     /* We may have already been playing subreg games.  If the
06234        mode is already correct for the destination, use it.  */
06235     if (GET_MODE (elt->exp) == new_mode)
06236       new_src = elt->exp;
06237     else
06238       {
06239         /* Calculate big endian correction for the SUBREG_BYTE.
06240            We have already checked that M1 (GET_MODE (dest))
06241            is not narrower than M2 (new_mode).  */
06242         if (BYTES_BIG_ENDIAN)
06243           byte = (GET_MODE_SIZE (GET_MODE (dest))
06244             - GET_MODE_SIZE (new_mode));
06245 
06246         new_src = simplify_gen_subreg (new_mode, elt->exp,
06247                      GET_MODE (dest), byte);
06248       }
06249 
06250     /* The call to simplify_gen_subreg fails if the value
06251        is VOIDmode, yet we can't do any simplification, e.g.
06252        for EXPR_LISTs denoting function call results.
06253        It is invalid to construct a SUBREG with a VOIDmode
06254        SUBREG_REG, hence a zero new_src means we can't do
06255        this substitution.  */
06256     if (! new_src)
06257       continue;
06258 
06259     src_hash = HASH (new_src, new_mode);
06260     src_elt = lookup (new_src, src_hash, new_mode);
06261 
06262     /* Put the new source in the hash table is if isn't
06263        already.  */
06264     if (src_elt == 0)
06265       {
06266         if (insert_regs (new_src, classp, 0))
06267           {
06268       rehash_using_reg (new_src);
06269       src_hash = HASH (new_src, new_mode);
06270           }
06271         src_elt = insert (new_src, classp, src_hash, new_mode);
06272         src_elt->in_memory = elt->in_memory;
06273       }
06274     else if (classp && classp != src_elt->first_same_value)
06275       /* Show that two things that we've seen before are
06276          actually the same.  */
06277       merge_equiv_classes (src_elt, classp);
06278 
06279     classp = src_elt->first_same_value;
06280     /* Ignore invalid entries.  */
06281     while (classp
06282            && GET_CODE (classp->exp) != REG
06283            && ! exp_equiv_p (classp->exp, classp->exp, 1, 0))
06284       classp = classp->next_same_value;
06285         }
06286     }
06287       }
06288 
06289   /* Special handling for (set REG0 REG1) where REG0 is the
06290      "cheapest", cheaper than REG1.  After cse, REG1 will probably not
06291      be used in the sequel, so (if easily done) change this insn to
06292      (set REG1 REG0) and replace REG1 with REG0 in the previous insn
06293      that computed their value.  Then REG1 will become a dead store
06294      and won't cloud the situation for later optimizations.
06295 
06296      Do not make this change if REG1 is a hard register, because it will
06297      then be used in the sequel and we may be changing a two-operand insn
06298      into a three-operand insn.
06299 
06300      Also do not do this if we are operating on a copy of INSN.
06301 
06302      Also don't do this if INSN ends a libcall; this would cause an unrelated
06303      register to be set in the middle of a libcall, and we then get bad code
06304      if the libcall is deleted.  */
06305 
06306   if (n_sets == 1 && sets[0].rtl && GET_CODE (SET_DEST (sets[0].rtl)) == REG
06307       && NEXT_INSN (PREV_INSN (insn)) == insn
06308       && GET_CODE (SET_SRC (sets[0].rtl)) == REG
06309       && REGNO (SET_SRC (sets[0].rtl)) >= FIRST_PSEUDO_REGISTER
06310       && REGNO_QTY_VALID_P (REGNO (SET_SRC (sets[0].rtl))))
06311     {
06312       int src_q = REG_QTY (REGNO (SET_SRC (sets[0].rtl)));
06313       struct qty_table_elem *src_ent = &qty_table[src_q];
06314 
06315       if ((src_ent->first_reg == REGNO (SET_DEST (sets[0].rtl)))
06316     && ! find_reg_note (insn, REG_RETVAL, NULL_RTX))
06317   {
06318     rtx prev = insn;
06319     /* Scan for the previous nonnote insn, but stop at a basic
06320        block boundary.  */
06321     do
06322       {
06323         prev = PREV_INSN (prev);
06324       }
06325     while (prev && GET_CODE (prev) == NOTE
06326      && NOTE_LINE_NUMBER (prev) != NOTE_INSN_BASIC_BLOCK);
06327       
06328     /* Do not swap the registers around if the previous instruction
06329        attaches a REG_EQUIV note to REG1.
06330 
06331        ??? It's not entirely clear whether we can transfer a REG_EQUIV
06332        from the pseudo that originally shadowed an incoming argument
06333        to another register.  Some uses of REG_EQUIV might rely on it
06334        being attached to REG1 rather than REG2.
06335 
06336        This section previously turned the REG_EQUIV into a REG_EQUAL
06337        note.  We cannot do that because REG_EQUIV may provide an
06338        uninitialized stack slot when REG_PARM_STACK_SPACE is used.  */
06339 
06340     if (prev != 0 && GET_CODE (prev) == INSN
06341         && GET_CODE (PATTERN (prev)) == SET
06342         && SET_DEST (PATTERN (prev)) == SET_SRC (sets[0].rtl)
06343         && ! find_reg_note (prev, REG_EQUIV, NULL_RTX))
06344       {
06345         rtx dest = SET_DEST (sets[0].rtl);
06346         rtx src = SET_SRC (sets[0].rtl);
06347         rtx note;
06348 
06349         validate_change (prev, &SET_DEST (PATTERN (prev)), dest, 1);
06350         validate_change (insn, &SET_DEST (sets[0].rtl), src, 1);
06351         validate_change (insn, &SET_SRC (sets[0].rtl), dest, 1);
06352         apply_change_group ();
06353 
06354         /* If there was a REG_WAS_0 note on PREV, remove it.  Move
06355      any REG_WAS_0 note on INSN to PREV.  */
06356         note = find_reg_note (prev, REG_WAS_0, NULL_RTX);
06357         if (note)
06358     remove_note (prev, note);
06359 
06360         note = find_reg_note (insn, REG_WAS_0, NULL_RTX);
06361         if (note)
06362     {
06363       remove_note (insn, note);
06364       XEXP (note, 1) = REG_NOTES (prev);
06365       REG_NOTES (prev) = note;
06366     }
06367 
06368         /* If INSN has a REG_EQUAL note, and this note mentions
06369      REG0, then we must delete it, because the value in
06370      REG0 has changed.  If the note's value is REG1, we must
06371      also delete it because that is now this insn's dest.  */
06372         note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
06373         if (note != 0
06374       && (reg_mentioned_p (dest, XEXP (note, 0))
06375           || rtx_equal_p (src, XEXP (note, 0))))
06376     remove_note (insn, note);
06377       }
06378   }
06379     }
06380 
06381   /* If this is a conditional jump insn, record any known equivalences due to
06382      the condition being tested.  */
06383 
06384   last_jump_equiv_class = 0;
06385   if (GET_CODE (insn) == JUMP_INSN
06386       && n_sets == 1 && GET_CODE (x) == SET
06387       && GET_CODE (SET_SRC (x)) == IF_THEN_ELSE)
06388     record_jump_equiv (insn, 0);
06389 
06390 #ifdef HAVE_cc0
06391   /* If the previous insn set CC0 and this insn no longer references CC0,
06392      delete the previous insn.  Here we use the fact that nothing expects CC0
06393      to be valid over an insn, which is true until the final pass.  */
06394   if (prev_insn && GET_CODE (prev_insn) == INSN
06395       && (tem = single_set (prev_insn)) != 0
06396       && SET_DEST (tem) == cc0_rtx
06397       && ! reg_mentioned_p (cc0_rtx, x))
06398     delete_insn (prev_insn);
06399 
06400   prev_insn_cc0 = this_insn_cc0;
06401   prev_insn_cc0_mode = this_insn_cc0_mode;
06402 #endif
06403 
06404   prev_insn = insn;
06405 }
06406 
06407 /* Remove from the hash table all expressions that reference memory.  */
06408 
06409 static void
06410 invalidate_memory ()
06411 {
06412   int i;
06413   struct table_elt *p, *next;
06414 
06415   for (i = 0; i < HASH_SIZE; i++)
06416     for (p = table[i]; p; p = next)
06417       {
06418   next = p->next_same_hash;
06419   if (p->in_memory)
06420     remove_from_table (p, i);
06421       }
06422 }
06423 
06424 /* If ADDR is an address that implicitly affects the stack pointer, return
06425    1 and update the register tables to show the effect.  Else, return 0.  */
06426 
06427 static int
06428 addr_affects_sp_p (addr)
06429      rtx addr;
06430 {
06431   if (GET_RTX_CLASS (GET_CODE (addr)) == 'a'
06432       && GET_CODE (XEXP (addr, 0)) == REG
06433       && REGNO (XEXP (addr, 0)) == STACK_POINTER_REGNUM)
06434     {
06435       if (REG_TICK (STACK_POINTER_REGNUM) >= 0)
06436   {
06437     REG_TICK (STACK_POINTER_REGNUM)++;
06438     /* Is it possible to use a subreg of SP?  */
06439     SUBREG_TICKED (STACK_POINTER_REGNUM) = -1;
06440   }
06441 
06442       /* This should be *very* rare.  */
06443       if (TEST_HARD_REG_BIT (hard_regs_in_table, STACK_POINTER_REGNUM))
06444   invalidate (stack_pointer_rtx, VOIDmode);
06445 
06446       return 1;
06447     }
06448 
06449   return 0;
06450 }
06451 
06452 /* Perform invalidation on the basis of everything about an insn
06453    except for invalidating the actual places that are SET in it.
06454    This includes the places CLOBBERed, and anything that might
06455    alias with something that is SET or CLOBBERed.
06456 
06457    X is the pattern of the insn.  */
06458 
06459 static void
06460 invalidate_from_clobbers (x)
06461      rtx x;
06462 {
06463   if (GET_CODE (x) == CLOBBER)
06464     {
06465       rtx ref = XEXP (x, 0);
06466       if (ref)
06467   {
06468     if (GET_CODE (ref) == REG || GET_CODE (ref) == SUBREG
06469         || GET_CODE (ref) == MEM)
06470       invalidate (ref, VOIDmode);
06471     else if (GET_CODE (ref) == STRICT_LOW_PART
06472        || GET_CODE (ref) == ZERO_EXTRACT)
06473       invalidate (XEXP (ref, 0), GET_MODE (ref));
06474   }
06475     }
06476   else if (GET_CODE (x) == PARALLEL)
06477     {
06478       int i;
06479       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
06480   {
06481     rtx y = XVECEXP (x, 0, i);
06482     if (GET_CODE (y) == CLOBBER)
06483       {
06484         rtx ref = XEXP (y, 0);
06485         if (GET_CODE (ref) == REG || GET_CODE (ref) == SUBREG
06486       || GET_CODE (ref) == MEM)
06487     invalidate (ref, VOIDmode);
06488         else if (GET_CODE (ref) == STRICT_LOW_PART
06489            || GET_CODE (ref) == ZERO_EXTRACT)
06490     invalidate (XEXP (ref, 0), GET_MODE (ref));
06491       }
06492   }
06493     }
06494 }
06495 
06496 /* Process X, part of the REG_NOTES of an insn.  Look at any REG_EQUAL notes
06497    and replace any registers in them with either an equivalent constant
06498    or the canonical form of the register.  If we are inside an address,
06499    only do this if the address remains valid.
06500 
06501    OBJECT is 0 except when within a MEM in which case it is the MEM.
06502 
06503    Return the replacement for X.  */
06504 
06505 static rtx
06506 cse_process_notes (x, object)
06507      rtx x;
06508      rtx object;
06509 {
06510   enum rtx_code code = GET_CODE (x);
06511   const char *fmt = GET_RTX_FORMAT (code);
06512   int i;
06513 
06514   switch (code)
06515     {
06516     case CONST_INT:
06517     case CONST:
06518     case SYMBOL_REF:
06519     case LABEL_REF:
06520     case CONST_DOUBLE:
06521     case CONST_VECTOR:
06522     case PC:
06523     case CC0:
06524     case LO_SUM:
06525       return x;
06526 
06527     case MEM:
06528       validate_change (x, &XEXP (x, 0),
06529            cse_process_notes (XEXP (x, 0), x), 0);
06530       return x;
06531 
06532     case EXPR_LIST:
06533     case INSN_LIST:
06534       if (REG_NOTE_KIND (x) == REG_EQUAL)
06535   XEXP (x, 0) = cse_process_notes (XEXP (x, 0), NULL_RTX);
06536       if (XEXP (x, 1))
06537   XEXP (x, 1) = cse_process_notes (XEXP (x, 1), NULL_RTX);
06538       return x;
06539 
06540     case SIGN_EXTEND:
06541     case ZERO_EXTEND:
06542     case SUBREG:
06543       {
06544   rtx new = cse_process_notes (XEXP (x, 0), object);
06545   /* We don't substitute VOIDmode constants into these rtx,
06546      since they would impede folding.  */
06547   if (GET_MODE (new) != VOIDmode)
06548     validate_change (object, &XEXP (x, 0), new, 0);
06549   return x;
06550       }
06551 
06552     case REG:
06553       i = REG_QTY (REGNO (x));
06554 
06555       /* Return a constant or a constant register.  */
06556       if (REGNO_QTY_VALID_P (REGNO (x)))
06557   {
06558     struct qty_table_elem *ent = &qty_table[i];
06559 
06560     if (ent->const_rtx != NULL_RTX
06561         && (CONSTANT_P (ent->const_rtx)
06562       || GET_CODE (ent->const_rtx) == REG))
06563       {
06564         rtx new = gen_lowpart_if_possible (GET_MODE (x), ent->const_rtx);
06565         if (new)
06566     return new;
06567       }
06568   }
06569 
06570       /* Otherwise, canonicalize this register.  */
06571       return canon_reg (x, NULL_RTX);
06572 
06573     default:
06574       break;
06575     }
06576 
06577   for (i = 0; i < GET_RTX_LENGTH (code); i++)
06578     if (fmt[i] == 'e')
06579       validate_change (object, &XEXP (x, i),
06580            cse_process_notes (XEXP (x, i), object), 0);
06581 
06582   return x;
06583 }
06584 
06585 /* Find common subexpressions between the end test of a loop and the beginning
06586    of the loop.  LOOP_START is the CODE_LABEL at the start of a loop.
06587 
06588    Often we have a loop where an expression in the exit test is used
06589    in the body of the loop.  For example "while (*p) *q++ = *p++;".
06590    Because of the way we duplicate the loop exit test in front of the loop,
06591    however, we don't detect that common subexpression.  This will be caught
06592    when global cse is implemented, but this is a quite common case.
06593 
06594    This function handles the most common cases of these common expressions.
06595    It is called after we have processed the basic block ending with the
06596    NOTE_INSN_LOOP_END note that ends a loop and the previous JUMP_INSN
06597    jumps to a label used only once.  */
06598 
06599 static void
06600 cse_around_loop (loop_start)
06601      rtx loop_start;
06602 {
06603   rtx insn;
06604   int i;
06605   struct table_elt *p;
06606 
06607   /* If the jump at the end of the loop doesn't go to the start, we don't
06608      do anything.  */
06609   for (insn = PREV_INSN (loop_start);
06610        insn && (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) >= 0);
06611        insn = PREV_INSN (insn))
06612     ;
06613 
06614   if (insn == 0
06615       || GET_CODE (insn) != NOTE
06616       || NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_BEG)
06617     return;
06618 
06619   /* If the last insn of the loop (the end test) was an NE comparison,
06620      we will interpret it as an EQ comparison, since we fell through
06621      the loop.  Any equivalences resulting from that comparison are
06622      therefore not valid and must be invalidated.  */
06623   if (last_jump_equiv_class)
06624     for (p = last_jump_equiv_class->first_same_value; p;
06625    p = p->next_same_value)
06626       {
06627   if (GET_CODE (p->exp) == MEM || GET_CODE (p->exp) == REG
06628       || (GET_CODE (p->exp) == SUBREG
06629     && GET_CODE (SUBREG_REG (p->exp)) == REG))
06630     invalidate (p->exp, VOIDmode);
06631   else if (GET_CODE (p->exp) == STRICT_LOW_PART
06632      || GET_CODE (p->exp) == ZERO_EXTRACT)
06633     invalidate (XEXP (p->exp, 0), GET_MODE (p->exp));
06634       }
06635 
06636   /* Process insns starting after LOOP_START until we hit a CALL_INSN or
06637      a CODE_LABEL (we could handle a CALL_INSN, but it isn't worth it).
06638 
06639      The only thing we do with SET_DEST is invalidate entries, so we
06640      can safely process each SET in order.  It is slightly less efficient
06641      to do so, but we only want to handle the most common cases.
06642 
06643      The gen_move_insn call in cse_set_around_loop may create new pseudos.
06644      These pseudos won't have valid entries in any of the tables indexed
06645      by register number, such as reg_qty.  We avoid out-of-range array
06646      accesses by not processing any instructions created after cse started.  */
06647 
06648   for (insn = NEXT_INSN (loop_start);
06649        GET_CODE (insn) != CALL_INSN && GET_CODE (insn) != CODE_LABEL
06650        && INSN_UID (insn) < max_insn_uid
06651        && ! (GET_CODE (insn) == NOTE
06652        && NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END);
06653        insn = NEXT_INSN (insn))
06654     {
06655       if (INSN_P (insn)
06656     && (GET_CODE (PATTERN (insn)) == SET
06657         || GET_CODE (PATTERN (insn)) == CLOBBER))
06658   cse_set_around_loop (PATTERN (insn), insn, loop_start);
06659       else if (INSN_P (insn) && GET_CODE (PATTERN (insn)) == PARALLEL)
06660   for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
06661     if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET
06662         || GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == CLOBBER)
06663       cse_set_around_loop (XVECEXP (PATTERN (insn), 0, i), insn,
06664          loop_start);
06665     }
06666 }
06667 
06668 /* Process one SET of an insn that was skipped.  We ignore CLOBBERs
06669    since they are done elsewhere.  This function is called via note_stores.  */
06670 
06671 static void
06672 invalidate_skipped_set (dest, set, data)
06673      rtx set;
06674      rtx dest;
06675      void *data ATTRIBUTE_UNUSED;
06676 {
06677   enum rtx_code code = GET_CODE (dest);
06678 
06679   if (code == MEM
06680       && ! addr_affects_sp_p (dest) /* If this is not a stack push ...  */
06681       /* There are times when an address can appear varying and be a PLUS
06682    during this scan when it would be a fixed address were we to know
06683    the proper equivalences.  So invalidate all memory if there is
06684    a BLKmode or nonscalar memory reference or a reference to a
06685    variable address.  */
06686       && (MEM_IN_STRUCT_P (dest) || GET_MODE (dest) == BLKmode
06687     || cse_rtx_varies_p (XEXP (dest, 0), 0)))
06688     {
06689       invalidate_memory ();
06690       return;
06691     }
06692 
06693   if (GET_CODE (set) == CLOBBER
06694 #ifdef HAVE_cc0
06695       || dest == cc0_rtx
06696 #endif
06697       || dest == pc_rtx)
06698     return;
06699 
06700   if (code == STRICT_LOW_PART || code == ZERO_EXTRACT)
06701     invalidate (XEXP (dest, 0), GET_MODE (dest));
06702   else if (code == REG || code == SUBREG || code == MEM)
06703     invalidate (dest, VOIDmode);
06704 }
06705 
06706 /* Invalidate all insns from START up to the end of the function or the
06707    next label.  This called when we wish to CSE around a block that is
06708    conditionally executed.  */
06709 
06710 static void
06711 invalidate_skipped_block (start)
06712      rtx start;
06713 {
06714   rtx insn;
06715 
06716   for (insn = start; insn && GET_CODE (insn) != CODE_LABEL;
06717        insn = NEXT_INSN (insn))
06718     {
06719       if (! INSN_P (insn))
06720   continue;
06721 
06722       if (GET_CODE (insn) == CALL_INSN)
06723   {
06724     if (! CONST_OR_PURE_CALL_P (insn))
06725       invalidate_memory ();
06726     invalidate_for_call ();
06727   }
06728 
06729       invalidate_from_clobbers (PATTERN (insn));
06730       note_stores (PATTERN (insn), invalidate_skipped_set, NULL);
06731     }
06732 }
06733 
06734 /* If modifying X will modify the value in *DATA (which is really an
06735    `rtx *'), indicate that fact by setting the pointed to value to
06736    NULL_RTX.  */
06737 
06738 static void
06739 cse_check_loop_start (x, set, data)
06740      rtx x;
06741      rtx set ATTRIBUTE_UNUSED;
06742      void *data;
06743 {
06744   rtx *cse_check_loop_start_value = (rtx *) data;
06745 
06746   if (*cse_check_loop_start_value == NULL_RTX
06747       || GET_CODE (x) == CC0 || GET_CODE (x) == PC)
06748     return;
06749 
06750   if ((GET_CODE (x) == MEM && GET_CODE (*cse_check_loop_start_value) == MEM)
06751       || reg_overlap_mentioned_p (x, *cse_check_loop_start_value))
06752     *cse_check_loop_start_value = NULL_RTX;
06753 }
06754 
06755 /* X is a SET or CLOBBER contained in INSN that was found near the start of
06756    a loop that starts with the label at LOOP_START.
06757 
06758    If X is a SET, we see if its SET_SRC is currently in our hash table.
06759    If so, we see if it has a value equal to some register used only in the
06760    loop exit code (as marked by jump.c).
06761 
06762    If those two conditions are true, we search backwards from the start of
06763    the loop to see if that same value was loaded into a register that still
06764    retains its value at the start of the loop.
06765 
06766    If so, we insert an insn after the load to copy the destination of that
06767    load into the equivalent register and (try to) replace our SET_SRC with that
06768    register.
06769 
06770    In any event, we invalidate whatever this SET or CLOBBER modifies.  */
06771 
06772 static void
06773 cse_set_around_loop (x, insn, loop_start)
06774      rtx x;
06775      rtx insn;
06776      rtx loop_start;
06777 {
06778   struct table_elt *src_elt;
06779 
06780   /* If this is a SET, see if we can replace SET_SRC, but ignore SETs that
06781      are setting PC or CC0 or whose SET_SRC is already a register.  */
06782   if (GET_CODE (x) == SET
06783       && GET_CODE (SET_DEST (x)) != PC && GET_CODE (SET_DEST (x)) != CC0
06784       && GET_CODE (SET_SRC (x)) != REG)
06785     {
06786       src_elt = lookup (SET_SRC (x),
06787       HASH (SET_SRC (x), GET_MODE (SET_DEST (x))),
06788       GET_MODE (SET_DEST (x)));
06789 
06790       if (src_elt)
06791   for (src_elt = src_elt->first_same_value; src_elt;
06792        src_elt = src_elt->next_same_value)
06793     if (GET_CODE (src_elt->exp) == REG && REG_LOOP_TEST_P (src_elt->exp)
06794         && COST (src_elt->exp) < COST (SET_SRC (x)))
06795       {
06796         rtx p, set;
06797 
06798         /* Look for an insn in front of LOOP_START that sets
06799      something in the desired mode to SET_SRC (x) before we hit
06800      a label or CALL_INSN.  */
06801 
06802         for (p = prev_nonnote_insn (loop_start);
06803        p && GET_CODE (p) != CALL_INSN
06804        && GET_CODE (p) != CODE_LABEL;
06805        p = prev_nonnote_insn  (p))
06806     if ((set = single_set (p)) != 0
06807         && GET_CODE (SET_DEST (set)) == REG
06808         && GET_MODE (SET_DEST (set)) == src_elt->mode
06809         && rtx_equal_p (SET_SRC (set), SET_SRC (x)))
06810       {
06811         /* We now have to ensure that nothing between P
06812            and LOOP_START modified anything referenced in
06813            SET_SRC (x).  We know that nothing within the loop
06814            can modify it, or we would have invalidated it in
06815            the hash table.  */
06816         rtx q;
06817         rtx cse_check_loop_start_value = SET_SRC (x);
06818         for (q = p; q != loop_start; q = NEXT_INSN (q))
06819           if (INSN_P (q))
06820       note_stores (PATTERN (q),
06821              cse_check_loop_start,
06822              &cse_check_loop_start_value);
06823 
06824         /* If nothing was changed and we can replace our
06825            SET_SRC, add an insn after P to copy its destination
06826            to what we will be replacing SET_SRC with.  */
06827         if (cse_check_loop_start_value
06828       && validate_change (insn, &SET_SRC (x),
06829               src_elt->exp, 0))
06830           {
06831       /* If this creates new pseudos, this is unsafe,
06832          because the regno of new pseudo is unsuitable
06833          to index into reg_qty when cse_insn processes
06834          the new insn.  Therefore, if a new pseudo was
06835          created, discard this optimization.  */
06836       int nregs = max_reg_num ();
06837       rtx move
06838         = gen_move_insn (src_elt->exp, SET_DEST (set));
06839       if (nregs != max_reg_num ())
06840         {
06841           if (! validate_change (insn, &SET_SRC (x),
06842                SET_SRC (set), 0))
06843             abort ();
06844         }
06845       else
06846         emit_insn_after (move, p);
06847           }
06848         break;
06849       }
06850       }
06851     }
06852 
06853   /* Deal with the destination of X affecting the stack pointer.  */
06854   addr_affects_sp_p (SET_DEST (x));
06855 
06856   /* See comment on similar code in cse_insn for explanation of these
06857      tests.  */
06858   if (GET_CODE (SET_DEST (x)) == REG || GET_CODE (SET_DEST (x)) == SUBREG
06859       || GET_CODE (SET_DEST (x)) == MEM)
06860     invalidate (SET_DEST (x), VOIDmode);
06861   else if (GET_CODE (SET_DEST (x)) == STRICT_LOW_PART
06862      || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
06863     invalidate (XEXP (SET_DEST (x), 0), GET_MODE (SET_DEST (x)));
06864 }
06865 
06866 /* Find the end of INSN's basic block and return its range,
06867    the total number of SETs in all the insns of the block, the last insn of the
06868    block, and the branch path.
06869 
06870    The branch path indicates which branches should be followed.  If a nonzero
06871    path size is specified, the block should be rescanned and a different set
06872    of branches will be taken.  The branch path is only used if
06873    FLAG_CSE_FOLLOW_JUMPS or FLAG_CSE_SKIP_BLOCKS is nonzero.
06874 
06875    DATA is a pointer to a struct cse_basic_block_data, defined below, that is
06876    used to describe the block.  It is filled in with the information about
06877    the current block.  The incoming structure's branch path, if any, is used
06878    to construct the output branch path.  */
06879 
06880 void
06881 cse_end_of_basic_block (insn, data, follow_jumps, after_loop, skip_blocks)
06882      rtx insn;
06883      struct cse_basic_block_data *data;
06884      int follow_jumps;
06885      int after_loop;
06886      int skip_blocks;
06887 {
06888   rtx p = insn, q;
06889   int nsets = 0;
06890   int low_cuid = INSN_CUID (insn), high_cuid = INSN_CUID (insn);
06891   rtx next = INSN_P (insn) ? insn : next_real_insn (insn);
06892   int path_size = data->path_size;
06893   int path_entry = 0;
06894   int i;
06895 
06896   /* Update the previous branch path, if any.  If the last branch was
06897      previously TAKEN, mark it NOT_TAKEN.  If it was previously NOT_TAKEN,
06898      shorten the path by one and look at the previous branch.  We know that
06899      at least one branch must have been taken if PATH_SIZE is nonzero.  */
06900   while (path_size > 0)
06901     {
06902       if (data->path[path_size - 1].status != NOT_TAKEN)
06903   {
06904     data->path[path_size - 1].status = NOT_TAKEN;
06905     break;
06906   }
06907       else
06908   path_size--;
06909     }
06910 
06911   /* If the first instruction is marked with QImode, that means we've
06912      already processed this block.  Our caller will look at DATA->LAST
06913      to figure out where to go next.  We want to return the next block
06914      in the instruction stream, not some branched-to block somewhere
06915      else.  We accomplish this by pretending our called forbid us to
06916      follow jumps, or skip blocks.  */
06917   if (GET_MODE (insn) == QImode)
06918     follow_jumps = skip_blocks = 0;
06919 
06920   /* Scan to end of this basic block.  */
06921   while (p && GET_CODE (p) != CODE_LABEL)
06922     {
06923       /* Don't cse out the end of a loop.  This makes a difference
06924    only for the unusual loops that always execute at least once;
06925    all other loops have labels there so we will stop in any case.
06926    Cse'ing out the end of the loop is dangerous because it
06927    might cause an invariant expression inside the loop
06928    to be reused after the end of the loop.  This would make it
06929    hard to move the expression out of the loop in loop.c,
06930    especially if it is one of several equivalent expressions
06931    and loop.c would like to eliminate it.
06932 
06933    If we are running after loop.c has finished, we can ignore
06934    the NOTE_INSN_LOOP_END.  */
06935 
06936       if (! after_loop && GET_CODE (p) == NOTE
06937     && NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_END)
06938   break;
06939 
06940       /* Don't cse over a call to setjmp; on some machines (eg VAX)
06941    the regs restored by the longjmp come from
06942    a later time than the setjmp.  */
06943       if (PREV_INSN (p) && GET_CODE (PREV_INSN (p)) == CALL_INSN
06944     && find_reg_note (PREV_INSN (p), REG_SETJMP, NULL))
06945   break;
06946 
06947       /* A PARALLEL can have lots of SETs in it,
06948    especially if it is really an ASM_OPERANDS.  */
06949       if (INSN_P (p) && GET_CODE (PATTERN (p)) == PARALLEL)
06950   nsets += XVECLEN (PATTERN (p), 0);
06951       else if (GET_CODE (p) != NOTE)
06952   nsets += 1;
06953 
06954       /* Ignore insns made by CSE; they cannot affect the boundaries of
06955    the basic block.  */
06956 
06957       if (INSN_UID (p) <= max_uid && INSN_CUID (p) > high_cuid)
06958   high_cuid = INSN_CUID (p);
06959       if (INSN_UID (p) <= max_uid && INSN_CUID (p) < low_cuid)
06960   low_cuid = INSN_CUID (p);
06961 
06962       /* See if this insn is in our branch path.  If it is and we are to
06963    take it, do so.  */
06964       if (path_entry < path_size && data->path[path_entry].branch == p)
06965   {
06966     if (data->path[path_entry].status != NOT_TAKEN)
06967       p = JUMP_LABEL (p);
06968 
06969     /* Point to next entry in path, if any.  */
06970     path_entry++;
06971   }
06972 
06973       /* If this is a conditional jump, we can follow it if -fcse-follow-jumps
06974    was specified, we haven't reached our maximum path length, there are
06975    insns following the target of the jump, this is the only use of the
06976    jump label, and the target label is preceded by a BARRIER.
06977 
06978    Alternatively, we can follow the jump if it branches around a
06979    block of code and there are no other branches into the block.
06980    In this case invalidate_skipped_block will be called to invalidate any
06981    registers set in the block when following the jump.  */
06982 
06983       else if ((follow_jumps || skip_blocks) && path_size < PATHLENGTH - 1
06984          && GET_CODE (p) == JUMP_INSN
06985          && GET_CODE (PATTERN (p)) == SET
06986          && GET_CODE (SET_SRC (PATTERN (p))) == IF_THEN_ELSE
06987          && JUMP_LABEL (p) != 0
06988          && LABEL_NUSES (JUMP_LABEL (p)) == 1
06989          && NEXT_INSN (JUMP_LABEL (p)) != 0)
06990   {
06991     for (q = PREV_INSN (JUMP_LABEL (p)); q; q = PREV_INSN (q))
06992       if ((GET_CODE (q) != NOTE
06993      || NOTE_LINE_NUMBER (q) == NOTE_INSN_LOOP_END
06994      || (PREV_INSN (q) && GET_CODE (PREV_INSN (q)) == CALL_INSN
06995          && find_reg_note (PREV_INSN (q), REG_SETJMP, NULL)))
06996     && (GET_CODE (q) != CODE_LABEL || LABEL_NUSES (q) != 0))
06997         break;
06998 
06999     /* If we ran into a BARRIER, this code is an extension of the
07000        basic block when the branch is taken.  */
07001     if (follow_jumps && q != 0 && GET_CODE (q) == BARRIER)
07002       {
07003         /* Don't allow ourself to keep walking around an
07004      always-executed loop.  */
07005         if (next_real_insn (q) == next)
07006     {
07007       p = NEXT_INSN (p);
07008       continue;
07009     }
07010 
07011         /* Similarly, don't put a branch in our path more than once.  */
07012         for (i = 0; i < path_entry; i++)
07013     if (data->path[i].branch == p)
07014       break;
07015 
07016         if (i != path_entry)
07017     break;
07018 
07019         data->path[path_entry].branch = p;
07020         data->path[path_entry++].status = TAKEN;
07021 
07022         /* This branch now ends our path.  It was possible that we
07023      didn't see this branch the last time around (when the
07024      insn in front of the target was a JUMP_INSN that was
07025      turned into a no-op).  */
07026         path_size = path_entry;
07027 
07028         p = JUMP_LABEL (p);
07029         /* Mark block so we won't scan it again later.  */
07030         PUT_MODE (NEXT_INSN (p), QImode);
07031       }
07032     /* Detect a branch around a block of code.  */
07033     else if (skip_blocks && q != 0 && GET_CODE (q) != CODE_LABEL)
07034       {
07035         rtx tmp;
07036 
07037         if (next_real_insn (q) == next)
07038     {
07039       p = NEXT_INSN (p);
07040       continue;
07041     }
07042 
07043         for (i = 0; i < path_entry; i++)
07044     if (data->path[i].branch == p)
07045       break;
07046 
07047         if (i != path_entry)
07048     break;
07049 
07050         /* This is no_labels_between_p (p, q) with an added check for
07051      reaching the end of a function (in case Q precedes P).  */
07052         for (tmp = NEXT_INSN (p); tmp && tmp != q; tmp = NEXT_INSN (tmp))
07053     if (GET_CODE (tmp) == CODE_LABEL)
07054       break;
07055 
07056         if (tmp == q)
07057     {
07058       data->path[path_entry].branch = p;
07059       data->path[path_entry++].status = AROUND;
07060 
07061       path_size = path_entry;
07062 
07063       p = JUMP_LABEL (p);
07064       /* Mark block so we won't scan it again later.  */
07065       PUT_MODE (NEXT_INSN (p), QImode);
07066     }
07067       }
07068   }
07069       p = NEXT_INSN (p);
07070     }
07071 
07072   data->low_cuid = low_cuid;
07073   data->high_cuid = high_cuid;
07074   data->nsets = nsets;
07075   data->last = p;
07076 
07077   /* If all jumps in the path are not taken, set our path length to zero
07078      so a rescan won't be done.  */
07079   for (i = path_size - 1; i >= 0; i--)
07080     if (data->path[i].status != NOT_TAKEN)
07081       break;
07082 
07083   if (i == -1)
07084     data->path_size = 0;
07085   else
07086     data->path_size = path_size;
07087 
07088   /* End the current branch path.  */
07089   data->path[path_size].branch = 0;
07090 }
07091 
07092 /* Perform cse on the instructions of a function.
07093    F is the first instruction.
07094    NREGS is one plus the highest pseudo-reg number used in the instruction.
07095 
07096    AFTER_LOOP is 1 if this is the cse call done after loop optimization
07097    (only if -frerun-cse-after-loop).
07098 
07099    Returns 1 if jump_optimize should be redone due to simplifications
07100    in conditional jump instructions.  */
07101 
07102 int
07103 cse_main (f, nregs, after_loop, file)
07104      rtx f;
07105      int nregs;
07106      int after_loop;
07107      FILE *file;
07108 {
07109   struct cse_basic_block_data val;
07110   rtx insn = f;
07111   int i;
07112 
07113   cse_jumps_altered = 0;
07114   recorded_label_ref = 0;
07115   constant_pool_entries_cost = 0;
07116   val.path_size = 0;
07117 
07118   init_recog ();
07119   init_alias_analysis ();
07120 
07121   max_reg = nregs;
07122 
07123   max_insn_uid = get_max_uid ();
07124 
07125   reg_eqv_table = (struct reg_eqv_elem *)
07126     xmalloc (nregs * sizeof (struct reg_eqv_elem));
07127 
07128 #ifdef LOAD_EXTEND_OP
07129 
07130   /* Allocate scratch rtl here.  cse_insn will fill in the memory reference
07131      and change the code and mode as appropriate.  */
07132   memory_extend_rtx = gen_rtx_ZERO_EXTEND (VOIDmode, NULL_RTX);
07133 #endif
07134 
07135   /* Reset the counter indicating how many elements have been made
07136      thus far.  */
07137   n_elements_made = 0;
07138 
07139   /* Find the largest uid.  */
07140 
07141   max_uid = get_max_uid ();
07142   uid_cuid = (int *) xcalloc (max_uid + 1, sizeof (int));
07143 
07144   /* Compute the mapping from uids to cuids.
07145      CUIDs are numbers assigned to insns, like uids,
07146      except that cuids increase monotonically through the code.
07147      Don't assign cuids to line-number NOTEs, so that the distance in cuids
07148      between two insns is not affected by -g.  */
07149 
07150   for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
07151     {
07152       if (GET_CODE (insn) != NOTE
07153     || NOTE_LINE_NUMBER (insn) < 0)
07154   INSN_CUID (insn) = ++i;
07155       else
07156   /* Give a line number note the same cuid as preceding insn.  */
07157   INSN_CUID (insn) = i;
07158     }
07159 
07160   ggc_push_context ();
07161 
07162   /* Loop over basic blocks.
07163      Compute the maximum number of qty's needed for each basic block
07164      (which is 2 for each SET).  */
07165   insn = f;
07166   while (insn)
07167     {
07168       cse_altered = 0;
07169       cse_end_of_basic_block (insn, &val, flag_cse_follow_jumps, after_loop,
07170             flag_cse_skip_blocks);
07171 
07172       /* If this basic block was already processed or has no sets, skip it.  */
07173       if (val.nsets == 0 || GET_MODE (insn) == QImode)
07174   {
07175     PUT_MODE (insn, VOIDmode);
07176     insn = (val.last ? NEXT_INSN (val.last) : 0);
07177     val.path_size = 0;
07178     continue;
07179   }
07180 
07181       cse_basic_block_start = val.low_cuid;
07182       cse_basic_block_end = val.high_cuid;
07183       max_qty = val.nsets * 2;
07184 
07185       if (file)
07186   fnotice (file, ";; Processing block from %d to %d, %d sets.\n",
07187      INSN_UID (insn), val.last ? INSN_UID (val.last) : 0,
07188      val.nsets);
07189 
07190       /* Make MAX_QTY bigger to give us room to optimize
07191    past the end of this basic block, if that should prove useful.  */
07192       if (max_qty < 500)
07193   max_qty = 500;
07194 
07195       max_qty += max_reg;
07196 
07197       /* If this basic block is being extended by following certain jumps,
07198          (see `cse_end_of_basic_block'), we reprocess the code from the start.
07199          Otherwise, we start after this basic block.  */
07200       if (val.path_size > 0)
07201   cse_basic_block (insn, val.last, val.path, 0);
07202       else
07203   {
07204     int old_cse_jumps_altered = cse_jumps_altered;
07205     rtx temp;
07206 
07207     /* When cse changes a conditional jump to an unconditional
07208        jump, we want to reprocess the block, since it will give
07209        us a new branch path to investigate.  */
07210     cse_jumps_altered = 0;
07211     temp = cse_basic_block (insn, val.last, val.path, ! after_loop);
07212     if (cse_jumps_altered == 0
07213         || (flag_cse_follow_jumps == 0 && flag_cse_skip_blocks == 0))
07214       insn = temp;
07215 
07216     cse_jumps_altered |= old_cse_jumps_altered;
07217   }
07218 
07219       if (cse_altered)
07220   ggc_collect ();
07221 
07222 #ifdef USE_C_ALLOCA
07223       alloca (0);
07224 #endif
07225     }
07226 
07227   ggc_pop_context ();
07228 
07229   if (max_elements_made < n_elements_made)
07230     max_elements_made = n_elements_made;
07231 
07232   /* Clean up.  */
07233   end_alias_analysis ();
07234   free (uid_cuid);
07235   free (reg_eqv_table);
07236 
07237   return cse_jumps_altered || recorded_label_ref;
07238 }
07239 
07240 /* Process a single basic block.  FROM and TO and the limits of the basic
07241    block.  NEXT_BRANCH points to the branch path when following jumps or
07242    a null path when not following jumps.
07243 
07244    AROUND_LOOP is nonzero if we are to try to cse around to the start of a
07245    loop.  This is true when we are being called for the last time on a
07246    block and this CSE pass is before loop.c.  */
07247 
07248 static rtx
07249 cse_basic_block (from, to, next_branch, around_loop)
07250      rtx from, to;
07251      struct branch_path *next_branch;
07252      int around_loop;
07253 {
07254   rtx insn;
07255   int to_usage = 0;
07256   rtx libcall_insn = NULL_RTX;
07257   int num_insns = 0;
07258 
07259   /* This array is undefined before max_reg, so only allocate
07260      the space actually needed and adjust the start.  */
07261 
07262   qty_table
07263     = (struct qty_table_elem *) xmalloc ((max_qty - max_reg)
07264            * sizeof (struct qty_table_elem));
07265   qty_table -= max_reg;
07266 
07267   new_basic_block ();
07268 
07269   /* TO might be a label.  If so, protect it from being deleted.  */
07270   if (to != 0 && GET_CODE (to) == CODE_LABEL)
07271     ++LABEL_NUSES (to);
07272 
07273   for (insn = from; insn != to; insn = NEXT_INSN (insn))
07274     {
07275       enum rtx_code code = GET_CODE (insn);
07276 
07277       /* If we have processed 1,000 insns, flush the hash table to
07278    avoid extreme quadratic behavior.  We must not include NOTEs
07279    in the count since there may be more of them when generating
07280    debugging information.  If we clear the table at different
07281    times, code generated with -g -O might be different than code
07282    generated with -O but not -g.
07283 
07284    ??? This is a real kludge and needs to be done some other way.
07285    Perhaps for 2.9.  */
07286       if (code != NOTE && num_insns++ > 1000)
07287   {
07288     flush_hash_table ();
07289     num_insns = 0;
07290   }
07291 
07292       /* See if this is a branch that is part of the path.  If so, and it is
07293    to be taken, do so.  */
07294       if (next_branch->branch == insn)
07295   {
07296     enum taken status = next_branch++->status;
07297     if (status != NOT_TAKEN)
07298       {
07299         if (status == TAKEN)
07300     record_jump_equiv (insn, 1);
07301         else
07302     invalidate_skipped_block (NEXT_INSN (insn));
07303 
07304         /* Set the last insn as the jump insn; it doesn't affect cc0.
07305      Then follow this branch.  */
07306 #ifdef HAVE_cc0
07307         prev_insn_cc0 = 0;
07308 #endif
07309         prev_insn = insn;
07310         insn = JUMP_LABEL (insn);
07311         continue;
07312       }
07313   }
07314 
07315       if (GET_MODE (insn) == QImode)
07316   PUT_MODE (insn, VOIDmode);
07317 
07318       if (GET_RTX_CLASS (code) == 'i')
07319   {
07320     rtx p;
07321 
07322     /* Process notes first so we have all notes in canonical forms when
07323        looking for duplicate operations.  */
07324 
07325     if (REG_NOTES (insn))
07326       REG_NOTES (insn) = cse_process_notes (REG_NOTES (insn), NULL_RTX);
07327 
07328     /* Track when we are inside in LIBCALL block.  Inside such a block,
07329        we do not want to record destinations.  The last insn of a
07330        LIBCALL block is not considered to be part of the block, since
07331        its destination is the result of the block and hence should be
07332        recorded.  */
07333 
07334     if (REG_NOTES (insn) != 0)
07335       {
07336         if ((p = find_reg_note (insn, REG_LIBCALL, NULL_RTX)))
07337     libcall_insn = XEXP (p, 0);
07338         else if (find_reg_note (insn, REG_RETVAL, NULL_RTX))
07339     libcall_insn = 0;
07340       }
07341 
07342     cse_insn (insn, libcall_insn);
07343 
07344     /* If we haven't already found an insn where we added a LABEL_REF,
07345        check this one.  */
07346     if (GET_CODE (insn) == INSN && ! recorded_label_ref
07347         && for_each_rtx (&PATTERN (insn), check_for_label_ref,
07348              (void *) insn))
07349       recorded_label_ref = 1;
07350   }
07351 
07352       /* If INSN is now an unconditional jump, skip to the end of our
07353    basic block by pretending that we just did the last insn in the
07354    basic block.  If we are jumping to the end of our block, show
07355    that we can have one usage of TO.  */
07356 
07357       if (any_uncondjump_p (insn))
07358   {
07359     if (to == 0)
07360       {
07361         free (qty_table + max_reg);
07362         return 0;
07363       }
07364 
07365     if (JUMP_LABEL (insn) == to)
07366       to_usage = 1;
07367 
07368     /* Maybe TO was deleted because the jump is unconditional.
07369        If so, there is nothing left in this basic block.  */
07370     /* ??? Perhaps it would be smarter to set TO
07371        to whatever follows this insn,
07372        and pretend the basic block had always ended here.  */
07373     if (INSN_DELETED_P (to))
07374       break;
07375 
07376     insn = PREV_INSN (to);
07377   }
07378 
07379       /* See if it is ok to keep on going past the label
07380    which used to end our basic block.  Remember that we incremented
07381    the count of that label, so we decrement it here.  If we made
07382    a jump unconditional, TO_USAGE will be one; in that case, we don't
07383    want to count the use in that jump.  */
07384 
07385       if (to != 0 && NEXT_INSN (insn) == to
07386     && GET_CODE (to) == CODE_LABEL && --LABEL_NUSES (to) == to_usage)
07387   {
07388     struct cse_basic_block_data val;
07389     rtx prev;
07390 
07391     insn = NEXT_INSN (to);
07392 
07393     /* If TO was the last insn in the function, we are done.  */
07394     if (insn == 0)
07395       {
07396         free (qty_table + max_reg);
07397         return 0;
07398       }
07399 
07400     /* If TO was preceded by a BARRIER we are done with this block
07401        because it has no continuation.  */
07402     prev = prev_nonnote_insn (to);
07403     if (prev && GET_CODE (prev) == BARRIER)
07404       {
07405         free (qty_table + max_reg);
07406         return insn;
07407       }
07408 
07409     /* Find the end of the following block.  Note that we won't be
07410        following branches in this case.  */
07411     to_usage = 0;
07412     val.path_size = 0;
07413     cse_end_of_basic_block (insn, &val, 0, 0, 0);
07414 
07415     /* If the tables we allocated have enough space left
07416        to handle all the SETs in the next basic block,
07417        continue through it.  Otherwise, return,
07418        and that block will be scanned individually.  */
07419     if (val.nsets * 2 + next_qty > max_qty)
07420       break;
07421 
07422     cse_basic_block_start = val.low_cuid;
07423     cse_basic_block_end = val.high_cuid;
07424     to = val.last;
07425 
07426     /* Prevent TO from being deleted if it is a label.  */
07427     if (to != 0 && GET_CODE (to) == CODE_LABEL)
07428       ++LABEL_NUSES (to);
07429 
07430     /* Back up so we process the first insn in the extension.  */
07431     insn = PREV_INSN (insn);
07432   }
07433     }
07434 
07435   if (next_qty > max_qty)
07436     abort ();
07437 
07438   /* If we are running before loop.c, we stopped on a NOTE_INSN_LOOP_END, and
07439      the previous insn is the only insn that branches to the head of a loop,
07440