home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / bbs / gnu / gcc-2.6.0-src.lha / GNU / src / amiga / gcc-2.6.0 / combine.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-12  |  359.4 KB  |  10,791 lines

  1. /* Optimize by combining instructions for GNU compiler.
  2.    Copyright (C) 1987, 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This module is essentially the "combiner" phase of the U. of Arizona
  22.    Portable Optimizer, but redone to work on our list-structured
  23.    representation for RTL instead of their string representation.
  24.  
  25.    The LOG_LINKS of each insn identify the most recent assignment
  26.    to each REG used in the insn.  It is a list of previous insns,
  27.    each of which contains a SET for a REG that is used in this insn
  28.    and not used or set in between.  LOG_LINKs never cross basic blocks.
  29.    They were set up by the preceding pass (lifetime analysis).
  30.  
  31.    We try to combine each pair of insns joined by a logical link.
  32.    We also try to combine triples of insns A, B and C when
  33.    C has a link back to B and B has a link back to A.
  34.  
  35.    LOG_LINKS does not have links for use of the CC0.  They don't
  36.    need to, because the insn that sets the CC0 is always immediately
  37.    before the insn that tests it.  So we always regard a branch
  38.    insn as having a logical link to the preceding insn.  The same is true
  39.    for an insn explicitly using CC0.
  40.  
  41.    We check (with use_crosses_set_p) to avoid combining in such a way
  42.    as to move a computation to a place where its value would be different.
  43.  
  44.    Combination is done by mathematically substituting the previous
  45.    insn(s) values for the regs they set into the expressions in
  46.    the later insns that refer to these regs.  If the result is a valid insn
  47.    for our target machine, according to the machine description,
  48.    we install it, delete the earlier insns, and update the data flow
  49.    information (LOG_LINKS and REG_NOTES) for what we did.
  50.  
  51.    There are a few exceptions where the dataflow information created by
  52.    flow.c aren't completely updated:
  53.  
  54.    - reg_live_length is not updated
  55.    - reg_n_refs is not adjusted in the rare case when a register is
  56.      no longer required in a computation
  57.    - there are extremely rare cases (see distribute_regnotes) when a
  58.      REG_DEAD note is lost
  59.    - a LOG_LINKS entry that refers to an insn with multiple SETs may be
  60.      removed because there is no way to know which register it was 
  61.      linking
  62.  
  63.    To simplify substitution, we combine only when the earlier insn(s)
  64.    consist of only a single assignment.  To simplify updating afterward,
  65.    we never combine when a subroutine call appears in the middle.
  66.  
  67.    Since we do not represent assignments to CC0 explicitly except when that
  68.    is all an insn does, there is no LOG_LINKS entry in an insn that uses
  69.    the condition code for the insn that set the condition code.
  70.    Fortunately, these two insns must be consecutive.
  71.    Therefore, every JUMP_INSN is taken to have an implicit logical link
  72.    to the preceding insn.  This is not quite right, since non-jumps can
  73.    also use the condition code; but in practice such insns would not
  74.    combine anyway.  */
  75.  
  76. #include "config.h"
  77. #ifdef __STDC__
  78. #include <stdarg.h>
  79. #else
  80. #include <varargs.h>
  81. #endif
  82.  
  83. /* Must precede rtl.h for FFS.  */
  84. #include <stdio.h>
  85.  
  86. #include "rtl.h"
  87. #include "flags.h"
  88. #include "regs.h"
  89. #include "hard-reg-set.h"
  90. #include "expr.h"
  91. #include "basic-block.h"
  92. #include "insn-config.h"
  93. #include "insn-flags.h"
  94. #include "insn-codes.h"
  95. #include "insn-attr.h"
  96. #include "recog.h"
  97. #include "real.h"
  98.  
  99. /* It is not safe to use ordinary gen_lowpart in combine.
  100.    Use gen_lowpart_for_combine instead.  See comments there.  */
  101. #define gen_lowpart dont_use_gen_lowpart_you_dummy
  102.  
  103. /* Number of attempts to combine instructions in this function.  */
  104.  
  105. static int combine_attempts;
  106.  
  107. /* Number of attempts that got as far as substitution in this function.  */
  108.  
  109. static int combine_merges;
  110.  
  111. /* Number of instructions combined with added SETs in this function.  */
  112.  
  113. static int combine_extras;
  114.  
  115. /* Number of instructions combined in this function.  */
  116.  
  117. static int combine_successes;
  118.  
  119. /* Totals over entire compilation.  */
  120.  
  121. static int total_attempts, total_merges, total_extras, total_successes;
  122.  
  123. /* Define a defulat value for REVERSIBLE_CC_MODE.
  124.    We can never assume that a condition code mode is safe to reverse unless
  125.    the md tells us so.  */
  126. #ifndef REVERSIBLE_CC_MODE
  127. #define REVERSIBLE_CC_MODE(MODE) 0
  128. #endif
  129.  
  130. /* Vector mapping INSN_UIDs to cuids.
  131.    The cuids are like uids but increase monotonically always.
  132.    Combine always uses cuids so that it can compare them.
  133.    But actually renumbering the uids, which we used to do,
  134.    proves to be a bad idea because it makes it hard to compare
  135.    the dumps produced by earlier passes with those from later passes.  */
  136.  
  137. static int *uid_cuid;
  138.  
  139. /* Get the cuid of an insn.  */
  140.  
  141. #define INSN_CUID(INSN) (uid_cuid[INSN_UID (INSN)])
  142.  
  143. /* Maximum register number, which is the size of the tables below.  */
  144.  
  145. static int combine_max_regno;
  146.  
  147. /* Record last point of death of (hard or pseudo) register n.  */
  148.  
  149. static rtx *reg_last_death;
  150.  
  151. /* Record last point of modification of (hard or pseudo) register n.  */
  152.  
  153. static rtx *reg_last_set;
  154.  
  155. /* Record the cuid of the last insn that invalidated memory
  156.    (anything that writes memory, and subroutine calls, but not pushes).  */
  157.  
  158. static int mem_last_set;
  159.  
  160. /* Record the cuid of the last CALL_INSN
  161.    so we can tell whether a potential combination crosses any calls.  */
  162.  
  163. static int last_call_cuid;
  164.  
  165. /* When `subst' is called, this is the insn that is being modified
  166.    (by combining in a previous insn).  The PATTERN of this insn
  167.    is still the old pattern partially modified and it should not be
  168.    looked at, but this may be used to examine the successors of the insn
  169.    to judge whether a simplification is valid.  */
  170.  
  171. static rtx subst_insn;
  172.  
  173. /* If nonzero, this is the insn that should be presumed to be
  174.    immediately in front of `subst_insn'.  */
  175.  
  176. static rtx subst_prev_insn;
  177.  
  178. /* This is the lowest CUID that `subst' is currently dealing with.
  179.    get_last_value will not return a value if the register was set at or
  180.    after this CUID.  If not for this mechanism, we could get confused if
  181.    I2 or I1 in try_combine were an insn that used the old value of a register
  182.    to obtain a new value.  In that case, we might erroneously get the
  183.    new value of the register when we wanted the old one.  */
  184.  
  185. static int subst_low_cuid;
  186.  
  187. /* This contains any hard registers that are used in newpat; reg_dead_at_p
  188.    must consider all these registers to be always live.  */
  189.  
  190. static HARD_REG_SET newpat_used_regs;
  191.  
  192. /* This is an insn to which a LOG_LINKS entry has been added.  If this
  193.    insn is the earlier than I2 or I3, combine should rescan starting at
  194.    that location.  */
  195.  
  196. static rtx added_links_insn;
  197.  
  198. /* This is the value of undobuf.num_undo when we started processing this 
  199.    substitution.  This will prevent gen_rtx_combine from re-used a piece
  200.    from the previous expression.  Doing so can produce circular rtl
  201.    structures.  */
  202.  
  203. static int previous_num_undos;
  204.  
  205. /* Basic block number of the block in which we are performing combines.  */
  206. static int this_basic_block;
  207.  
  208. /* The next group of arrays allows the recording of the last value assigned
  209.    to (hard or pseudo) register n.  We use this information to see if a
  210.    operation being processed is redundant given a prior operation performed
  211.    on the register.  For example, an `and' with a constant is redundant if
  212.    all the zero bits are already known to be turned off.
  213.  
  214.    We use an approach similar to that used by cse, but change it in the
  215.    following ways:
  216.  
  217.    (1) We do not want to reinitialize at each label.
  218.    (2) It is useful, but not critical, to know the actual value assigned
  219.        to a register.  Often just its form is helpful.
  220.  
  221.    Therefore, we maintain the following arrays:
  222.  
  223.    reg_last_set_value        the last value assigned
  224.    reg_last_set_label        records the value of label_tick when the
  225.                 register was assigned
  226.    reg_last_set_table_tick    records the value of label_tick when a
  227.                 value using the register is assigned
  228.    reg_last_set_invalid        set to non-zero when it is not valid
  229.                 to use the value of this register in some
  230.                 register's value
  231.  
  232.    To understand the usage of these tables, it is important to understand
  233.    the distinction between the value in reg_last_set_value being valid
  234.    and the register being validly contained in some other expression in the
  235.    table.
  236.  
  237.    Entry I in reg_last_set_value is valid if it is non-zero, and either
  238.    reg_n_sets[i] is 1 or reg_last_set_label[i] == label_tick.
  239.  
  240.    Register I may validly appear in any expression returned for the value
  241.    of another register if reg_n_sets[i] is 1.  It may also appear in the
  242.    value for register J if reg_last_set_label[i] < reg_last_set_label[j] or
  243.    reg_last_set_invalid[j] is zero.
  244.  
  245.    If an expression is found in the table containing a register which may
  246.    not validly appear in an expression, the register is replaced by
  247.    something that won't match, (clobber (const_int 0)).
  248.  
  249.    reg_last_set_invalid[i] is set non-zero when register I is being assigned
  250.    to and reg_last_set_table_tick[i] == label_tick.  */
  251.  
  252. /* Record last value assigned to (hard or pseudo) register n. */
  253.  
  254. static rtx *reg_last_set_value;
  255.  
  256. /* Record the value of label_tick when the value for register n is placed in
  257.    reg_last_set_value[n].  */
  258.  
  259. static int *reg_last_set_label;
  260.  
  261. /* Record the value of label_tick when an expression involving register n
  262.    is placed in reg_last_set_value. */
  263.  
  264. static int *reg_last_set_table_tick;
  265.  
  266. /* Set non-zero if references to register n in expressions should not be
  267.    used.  */
  268.  
  269. static char *reg_last_set_invalid;
  270.  
  271. /* Incremented for each label. */
  272.  
  273. static int label_tick;
  274.  
  275. /* Some registers that are set more than once and used in more than one
  276.    basic block are nevertheless always set in similar ways.  For example,
  277.    a QImode register may be loaded from memory in two places on a machine
  278.    where byte loads zero extend.
  279.  
  280.    We record in the following array what we know about the nonzero
  281.    bits of a register, specifically which bits are known to be zero.
  282.  
  283.    If an entry is zero, it means that we don't know anything special.  */
  284.  
  285. static unsigned HOST_WIDE_INT *reg_nonzero_bits;
  286.  
  287. /* Mode used to compute significance in reg_nonzero_bits.  It is the largest
  288.    integer mode that can fit in HOST_BITS_PER_WIDE_INT.  */
  289.  
  290. static enum machine_mode nonzero_bits_mode;
  291.  
  292. /* Nonzero if we know that a register has some leading bits that are always
  293.    equal to the sign bit.  */
  294.  
  295. static char *reg_sign_bit_copies;
  296.  
  297. /* Nonzero when reg_nonzero_bits and reg_sign_bit_copies can be safely used.
  298.    It is zero while computing them and after combine has completed.  This
  299.    former test prevents propagating values based on previously set values,
  300.    which can be incorrect if a variable is modified in a loop.  */
  301.  
  302. static int nonzero_sign_valid;
  303.  
  304. /* These arrays are maintained in parallel with reg_last_set_value
  305.    and are used to store the mode in which the register was last set,
  306.    the bits that were known to be zero when it was last set, and the
  307.    number of sign bits copies it was known to have when it was last set.  */
  308.  
  309. static enum machine_mode *reg_last_set_mode;
  310. static unsigned HOST_WIDE_INT *reg_last_set_nonzero_bits;
  311. static char *reg_last_set_sign_bit_copies;
  312.  
  313. /* Record one modification to rtl structure
  314.    to be undone by storing old_contents into *where.
  315.    is_int is 1 if the contents are an int.  */
  316.  
  317. struct undo
  318. {
  319.   int is_int;
  320.   union {rtx r; int i;} old_contents;
  321.   union {rtx *r; int *i;} where;
  322. };
  323.  
  324. /* Record a bunch of changes to be undone, up to MAX_UNDO of them.
  325.    num_undo says how many are currently recorded.
  326.  
  327.    storage is nonzero if we must undo the allocation of new storage.
  328.    The value of storage is what to pass to obfree.
  329.  
  330.    other_insn is nonzero if we have modified some other insn in the process
  331.    of working on subst_insn.  It must be verified too.  */
  332.  
  333. #define MAX_UNDO 50
  334.  
  335. struct undobuf
  336. {
  337.   int num_undo;
  338.   char *storage;
  339.   struct undo undo[MAX_UNDO];
  340.   rtx other_insn;
  341. };
  342.  
  343. static struct undobuf undobuf;
  344.  
  345. /* Substitute NEWVAL, an rtx expression, into INTO, a place in some
  346.    insn.  The substitution can be undone by undo_all.  If INTO is already
  347.    set to NEWVAL, do not record this change.  Because computing NEWVAL might
  348.    also call SUBST, we have to compute it before we put anything into
  349.    the undo table.  */
  350.  
  351. #define SUBST(INTO, NEWVAL)  \
  352.  do { rtx _new = (NEWVAL);                        \
  353.       if (undobuf.num_undo < MAX_UNDO)                    \
  354.     {                                \
  355.       undobuf.undo[undobuf.num_undo].is_int = 0;            \
  356.       undobuf.undo[undobuf.num_undo].where.r = &INTO;        \
  357.       undobuf.undo[undobuf.num_undo].old_contents.r = INTO;    \
  358.       INTO = _new;                            \
  359.       if (undobuf.undo[undobuf.num_undo].old_contents.r != INTO)    \
  360.         undobuf.num_undo++;                     \
  361.     }                                \
  362.     } while (0)
  363.  
  364. /* Similar to SUBST, but NEWVAL is an int.  INTO will normally be an XINT
  365.    expression.
  366.    Note that substitution for the value of a CONST_INT is not safe.  */
  367.  
  368. #define SUBST_INT(INTO, NEWVAL)  \
  369.  do { if (undobuf.num_undo < MAX_UNDO)                    \
  370. {                                    \
  371.       undobuf.undo[undobuf.num_undo].is_int = 1;            \
  372.       undobuf.undo[undobuf.num_undo].where.i = (int *) &INTO;    \
  373.       undobuf.undo[undobuf.num_undo].old_contents.i = INTO;        \
  374.       INTO = NEWVAL;                        \
  375.       if (undobuf.undo[undobuf.num_undo].old_contents.i != INTO)    \
  376.         undobuf.num_undo++;                        \
  377.     }                                \
  378.      } while (0)
  379.  
  380. /* Number of times the pseudo being substituted for
  381.    was found and replaced.  */
  382.  
  383. static int n_occurrences;
  384.  
  385. static void init_reg_last_arrays    PROTO(());
  386. static void setup_incoming_promotions   PROTO(());
  387. static void set_nonzero_bits_and_sign_copies  PROTO((rtx, rtx));
  388. static int can_combine_p    PROTO((rtx, rtx, rtx, rtx, rtx *, rtx *));
  389. static int combinable_i3pat    PROTO((rtx, rtx *, rtx, rtx, int, rtx *));
  390. static rtx try_combine        PROTO((rtx, rtx, rtx));
  391. static void undo_all        PROTO((void));
  392. static rtx *find_split_point    PROTO((rtx *, rtx));
  393. static rtx subst        PROTO((rtx, rtx, rtx, int, int));
  394. static rtx simplify_rtx        PROTO((rtx, enum machine_mode, int, int));
  395. static rtx simplify_if_then_else  PROTO((rtx));
  396. static rtx simplify_set        PROTO((rtx));
  397. static rtx simplify_logical    PROTO((rtx, int));
  398. static rtx expand_compound_operation  PROTO((rtx));
  399. static rtx expand_field_assignment  PROTO((rtx));
  400. static rtx make_extraction    PROTO((enum machine_mode, rtx, int, rtx, int,
  401.                        int, int, int));
  402. static rtx extract_left_shift    PROTO((rtx, int));
  403. static rtx make_compound_operation  PROTO((rtx, enum rtx_code));
  404. static int get_pos_from_mask    PROTO((unsigned HOST_WIDE_INT, int *));
  405. static rtx force_to_mode    PROTO((rtx, enum machine_mode,
  406.                        unsigned HOST_WIDE_INT, rtx, int));
  407. static rtx if_then_else_cond    PROTO((rtx, rtx *, rtx *));
  408. static rtx known_cond        PROTO((rtx, enum rtx_code, rtx, rtx));
  409. static rtx make_field_assignment  PROTO((rtx));
  410. static rtx apply_distributive_law  PROTO((rtx));
  411. static rtx simplify_and_const_int  PROTO((rtx, enum machine_mode, rtx,
  412.                       unsigned HOST_WIDE_INT));
  413. static unsigned HOST_WIDE_INT nonzero_bits  PROTO((rtx, enum machine_mode));
  414. static int num_sign_bit_copies  PROTO((rtx, enum machine_mode));
  415. static int merge_outer_ops    PROTO((enum rtx_code *, HOST_WIDE_INT *,
  416.                        enum rtx_code, HOST_WIDE_INT,
  417.                        enum machine_mode, int *));
  418. static rtx simplify_shift_const    PROTO((rtx, enum rtx_code, enum machine_mode,
  419.                        rtx, int));
  420. static int recog_for_combine    PROTO((rtx *, rtx, rtx *));
  421. static rtx gen_lowpart_for_combine  PROTO((enum machine_mode, rtx));
  422. static rtx gen_rtx_combine PVPROTO((enum rtx_code code, enum machine_mode mode,
  423.                   ...));
  424. static rtx gen_binary        PROTO((enum rtx_code, enum machine_mode,
  425.                        rtx, rtx));
  426. static rtx gen_unary        PROTO((enum rtx_code, enum machine_mode,
  427.                        enum machine_mode, rtx));
  428. static enum rtx_code simplify_comparison  PROTO((enum rtx_code, rtx *, rtx *));
  429. static int reversible_comparison_p  PROTO((rtx));
  430. static void update_table_tick    PROTO((rtx));
  431. static void record_value_for_reg  PROTO((rtx, rtx, rtx));
  432. static void record_dead_and_set_regs_1  PROTO((rtx, rtx));
  433. static void record_dead_and_set_regs  PROTO((rtx));
  434. static int get_last_value_validate  PROTO((rtx *, int, int));
  435. static rtx get_last_value    PROTO((rtx));
  436. static int use_crosses_set_p    PROTO((rtx, int));
  437. static void reg_dead_at_p_1    PROTO((rtx, rtx));
  438. static int reg_dead_at_p    PROTO((rtx, rtx));
  439. static void move_deaths        PROTO((rtx, int, rtx, rtx *));
  440. static int reg_bitfield_target_p  PROTO((rtx, rtx));
  441. static void distribute_notes    PROTO((rtx, rtx, rtx, rtx, rtx, rtx));
  442. static void distribute_links    PROTO((rtx));
  443. static void mark_used_regs_combine PROTO((rtx));
  444.  
  445. /* Main entry point for combiner.  F is the first insn of the function.
  446.    NREGS is the first unused pseudo-reg number.  */
  447.  
  448. void
  449. combine_instructions (f, nregs)
  450.      rtx f;
  451.      int nregs;
  452. {
  453.   register rtx insn, next, prev;
  454.   register int i;
  455.   register rtx links, nextlinks;
  456.  
  457.   combine_attempts = 0;
  458.   combine_merges = 0;
  459.   combine_extras = 0;
  460.   combine_successes = 0;
  461.   undobuf.num_undo = previous_num_undos = 0;
  462.  
  463.   combine_max_regno = nregs;
  464.  
  465.   reg_nonzero_bits
  466.     = (unsigned HOST_WIDE_INT *) alloca (nregs * sizeof (HOST_WIDE_INT));
  467.   reg_sign_bit_copies = (char *) alloca (nregs * sizeof (char));
  468.  
  469.   bzero ((char *) reg_nonzero_bits, nregs * sizeof (HOST_WIDE_INT));
  470.   bzero (reg_sign_bit_copies, nregs * sizeof (char));
  471.  
  472.   reg_last_death = (rtx *) alloca (nregs * sizeof (rtx));
  473.   reg_last_set = (rtx *) alloca (nregs * sizeof (rtx));
  474.   reg_last_set_value = (rtx *) alloca (nregs * sizeof (rtx));
  475.   reg_last_set_table_tick = (int *) alloca (nregs * sizeof (int));
  476.   reg_last_set_label = (int *) alloca (nregs * sizeof (int));
  477.   reg_last_set_invalid = (char *) alloca (nregs * sizeof (char));
  478.   reg_last_set_mode
  479.     = (enum machine_mode *) alloca (nregs * sizeof (enum machine_mode));
  480.   reg_last_set_nonzero_bits
  481.     = (unsigned HOST_WIDE_INT *) alloca (nregs * sizeof (HOST_WIDE_INT));
  482.   reg_last_set_sign_bit_copies
  483.     = (char *) alloca (nregs * sizeof (char));
  484.  
  485.   init_reg_last_arrays ();
  486.  
  487.   init_recog_no_volatile ();
  488.  
  489.   /* Compute maximum uid value so uid_cuid can be allocated.  */
  490.  
  491.   for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
  492.     if (INSN_UID (insn) > i)
  493.       i = INSN_UID (insn);
  494.  
  495.   uid_cuid = (int *) alloca ((i + 1) * sizeof (int));
  496.  
  497.   nonzero_bits_mode = mode_for_size (HOST_BITS_PER_WIDE_INT, MODE_INT, 0);
  498.  
  499.   /* Don't use reg_nonzero_bits when computing it.  This can cause problems
  500.      when, for example, we have j <<= 1 in a loop.  */
  501.  
  502.   nonzero_sign_valid = 0;
  503.  
  504.   /* Compute the mapping from uids to cuids.
  505.      Cuids are numbers assigned to insns, like uids,
  506.      except that cuids increase monotonically through the code. 
  507.  
  508.      Scan all SETs and see if we can deduce anything about what
  509.      bits are known to be zero for some registers and how many copies
  510.      of the sign bit are known to exist for those registers.
  511.  
  512.      Also set any known values so that we can use it while searching
  513.      for what bits are known to be set.  */
  514.  
  515.   label_tick = 1;
  516.  
  517.   setup_incoming_promotions ();
  518.  
  519.   for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
  520.     {
  521.       INSN_CUID (insn) = ++i;
  522.       subst_low_cuid = i;
  523.       subst_insn = insn;
  524.  
  525.       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  526.     {
  527.       note_stores (PATTERN (insn), set_nonzero_bits_and_sign_copies);
  528.       record_dead_and_set_regs (insn);
  529.     }
  530.  
  531.       if (GET_CODE (insn) == CODE_LABEL)
  532.     label_tick++;
  533.     }
  534.  
  535.   nonzero_sign_valid = 1;
  536.  
  537.   /* Now scan all the insns in forward order.  */
  538.  
  539.   this_basic_block = -1;
  540.   label_tick = 1;
  541.   last_call_cuid = 0;
  542.   mem_last_set = 0;
  543.   init_reg_last_arrays ();
  544.   setup_incoming_promotions ();
  545.  
  546.   for (insn = f; insn; insn = next ? next : NEXT_INSN (insn))
  547.     {
  548.       next = 0;
  549.  
  550.       /* If INSN starts a new basic block, update our basic block number.  */
  551.       if (this_basic_block + 1 < n_basic_blocks
  552.       && basic_block_head[this_basic_block + 1] == insn)
  553.     this_basic_block++;
  554.  
  555.       if (GET_CODE (insn) == CODE_LABEL)
  556.     label_tick++;
  557.  
  558.       else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  559.     {
  560.       /* Try this insn with each insn it links back to.  */
  561.  
  562.       for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
  563.         if ((next = try_combine (insn, XEXP (links, 0), NULL_RTX)) != 0)
  564.           goto retry;
  565.  
  566.       /* Try each sequence of three linked insns ending with this one.  */
  567.  
  568.       for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
  569.         for (nextlinks = LOG_LINKS (XEXP (links, 0)); nextlinks;
  570.          nextlinks = XEXP (nextlinks, 1))
  571.           if ((next = try_combine (insn, XEXP (links, 0),
  572.                        XEXP (nextlinks, 0))) != 0)
  573.         goto retry;
  574.  
  575. #ifdef HAVE_cc0
  576.       /* Try to combine a jump insn that uses CC0
  577.          with a preceding insn that sets CC0, and maybe with its
  578.          logical predecessor as well.
  579.          This is how we make decrement-and-branch insns.
  580.          We need this special code because data flow connections
  581.          via CC0 do not get entered in LOG_LINKS.  */
  582.  
  583.       if (GET_CODE (insn) == JUMP_INSN
  584.           && (prev = prev_nonnote_insn (insn)) != 0
  585.           && GET_CODE (prev) == INSN
  586.           && sets_cc0_p (PATTERN (prev)))
  587.         {
  588.           if ((next = try_combine (insn, prev, NULL_RTX)) != 0)
  589.         goto retry;
  590.  
  591.           for (nextlinks = LOG_LINKS (prev); nextlinks;
  592.            nextlinks = XEXP (nextlinks, 1))
  593.         if ((next = try_combine (insn, prev,
  594.                      XEXP (nextlinks, 0))) != 0)
  595.           goto retry;
  596.         }
  597.  
  598.       /* Do the same for an insn that explicitly references CC0.  */
  599.       if (GET_CODE (insn) == INSN
  600.           && (prev = prev_nonnote_insn (insn)) != 0
  601.           && GET_CODE (prev) == INSN
  602.           && sets_cc0_p (PATTERN (prev))
  603.           && GET_CODE (PATTERN (insn)) == SET
  604.           && reg_mentioned_p (cc0_rtx, SET_SRC (PATTERN (insn))))
  605.         {
  606.           if ((next = try_combine (insn, prev, NULL_RTX)) != 0)
  607.         goto retry;
  608.  
  609.           for (nextlinks = LOG_LINKS (prev); nextlinks;
  610.            nextlinks = XEXP (nextlinks, 1))
  611.         if ((next = try_combine (insn, prev,
  612.                      XEXP (nextlinks, 0))) != 0)
  613.           goto retry;
  614.         }
  615.  
  616.       /* Finally, see if any of the insns that this insn links to
  617.          explicitly references CC0.  If so, try this insn, that insn,
  618.          and its predecessor if it sets CC0.  */
  619.       for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
  620.         if (GET_CODE (XEXP (links, 0)) == INSN
  621.         && GET_CODE (PATTERN (XEXP (links, 0))) == SET
  622.         && reg_mentioned_p (cc0_rtx, SET_SRC (PATTERN (XEXP (links, 0))))
  623.         && (prev = prev_nonnote_insn (XEXP (links, 0))) != 0
  624.         && GET_CODE (prev) == INSN
  625.         && sets_cc0_p (PATTERN (prev))
  626.         && (next = try_combine (insn, XEXP (links, 0), prev)) != 0)
  627.           goto retry;
  628. #endif
  629.  
  630.       /* Try combining an insn with two different insns whose results it
  631.          uses.  */
  632.       for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
  633.         for (nextlinks = XEXP (links, 1); nextlinks;
  634.          nextlinks = XEXP (nextlinks, 1))
  635.           if ((next = try_combine (insn, XEXP (links, 0),
  636.                        XEXP (nextlinks, 0))) != 0)
  637.         goto retry;
  638.  
  639.       if (GET_CODE (insn) != NOTE)
  640.         record_dead_and_set_regs (insn);
  641.  
  642.     retry:
  643.       ;
  644.     }
  645.     }
  646.  
  647.   total_attempts += combine_attempts;
  648.   total_merges += combine_merges;
  649.   total_extras += combine_extras;
  650.   total_successes += combine_successes;
  651.  
  652.   nonzero_sign_valid = 0;
  653. }
  654.  
  655. /* Wipe the reg_last_xxx arrays in preparation for another pass.  */
  656.  
  657. static void
  658. init_reg_last_arrays ()
  659. {
  660.   int nregs = combine_max_regno;
  661.  
  662.   bzero ((char *) reg_last_death, nregs * sizeof (rtx));
  663.   bzero ((char *) reg_last_set, nregs * sizeof (rtx));
  664.   bzero ((char *) reg_last_set_value, nregs * sizeof (rtx));
  665.   bzero ((char *) reg_last_set_table_tick, nregs * sizeof (int));
  666.   bzero ((char *) reg_last_set_label, nregs * sizeof (int));
  667.   bzero (reg_last_set_invalid, nregs * sizeof (char));
  668.   bzero ((char *) reg_last_set_mode, nregs * sizeof (enum machine_mode));
  669.   bzero ((char *) reg_last_set_nonzero_bits, nregs * sizeof (HOST_WIDE_INT));
  670.   bzero (reg_last_set_sign_bit_copies, nregs * sizeof (char));
  671. }
  672.  
  673. /* Set up any promoted values for incoming argument registers.  */
  674.  
  675. static void
  676. setup_incoming_promotions ()
  677. {
  678. #ifdef PROMOTE_FUNCTION_ARGS
  679.   int regno;
  680.   rtx reg;
  681.   enum machine_mode mode;
  682.   int unsignedp;
  683.   rtx first = get_insns ();
  684.  
  685.   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
  686.     if (FUNCTION_ARG_REGNO_P (regno)
  687.     && (reg = promoted_input_arg (regno, &mode, &unsignedp)) != 0)
  688.       record_value_for_reg (reg, first,
  689.                 gen_rtx (unsignedp ? ZERO_EXTEND : SIGN_EXTEND,
  690.                      GET_MODE (reg),
  691.                      gen_rtx (CLOBBER, mode, const0_rtx)));
  692. #endif
  693. }
  694.  
  695. /* Called via note_stores.  If X is a pseudo that is used in more than
  696.    one basic block, is narrower that HOST_BITS_PER_WIDE_INT, and is being
  697.    set, record what bits are known zero.  If we are clobbering X,
  698.    ignore this "set" because the clobbered value won't be used. 
  699.  
  700.    If we are setting only a portion of X and we can't figure out what
  701.    portion, assume all bits will be used since we don't know what will
  702.    be happening.
  703.  
  704.    Similarly, set how many bits of X are known to be copies of the sign bit
  705.    at all locations in the function.  This is the smallest number implied 
  706.    by any set of X.  */
  707.  
  708. static void
  709. set_nonzero_bits_and_sign_copies (x, set)
  710.      rtx x;
  711.      rtx set;
  712. {
  713.   int num;
  714.  
  715.   if (GET_CODE (x) == REG
  716.       && REGNO (x) >= FIRST_PSEUDO_REGISTER
  717.       && reg_n_sets[REGNO (x)] > 1
  718.       && reg_basic_block[REGNO (x)] < 0
  719.       /* If this register is undefined at the start of the file, we can't
  720.      say what its contents were.  */
  721.       && ! (basic_block_live_at_start[0][REGNO (x) / REGSET_ELT_BITS]
  722.         & ((REGSET_ELT_TYPE) 1 << (REGNO (x) % REGSET_ELT_BITS)))
  723.       && GET_MODE_BITSIZE (GET_MODE (x)) <= HOST_BITS_PER_WIDE_INT)
  724.     {
  725.       if (GET_CODE (set) == CLOBBER)
  726.     {
  727.       reg_nonzero_bits[REGNO (x)] = GET_MODE_MASK (GET_MODE (x));
  728.       reg_sign_bit_copies[REGNO (x)] = 0;
  729.       return;
  730.     }
  731.  
  732.       /* If this is a complex assignment, see if we can convert it into a
  733.      simple assignment.  */
  734.       set = expand_field_assignment (set);
  735.  
  736.       /* If this is a simple assignment, or we have a paradoxical SUBREG,
  737.      set what we know about X.  */
  738.  
  739.       if (SET_DEST (set) == x
  740.       || (GET_CODE (SET_DEST (set)) == SUBREG
  741.           && (GET_MODE_SIZE (GET_MODE (SET_DEST (set)))
  742.           > GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (set)))))
  743.           && SUBREG_REG (SET_DEST (set)) == x))
  744.     {
  745.       rtx src = SET_SRC (set);
  746.  
  747. #ifdef SHORT_IMMEDIATES_SIGN_EXTEND
  748.       /* If X is narrower than a word and SRC is a non-negative
  749.          constant that would appear negative in the mode of X,
  750.          sign-extend it for use in reg_nonzero_bits because some
  751.          machines (maybe most) will actually do the sign-extension
  752.          and this is the conservative approach. 
  753.  
  754.          ??? For 2.5, try to tighten up the MD files in this regard
  755.          instead of this kludge.  */
  756.  
  757.       if (GET_MODE_BITSIZE (GET_MODE (x)) < BITS_PER_WORD
  758.           && GET_CODE (src) == CONST_INT
  759.           && INTVAL (src) > 0
  760.           && 0 != (INTVAL (src)
  761.                & ((HOST_WIDE_INT) 1
  762.               << (GET_MODE_BITSIZE (GET_MODE (x)) - 1))))
  763.         src = GEN_INT (INTVAL (src)
  764.                | ((HOST_WIDE_INT) (-1)
  765.                   << GET_MODE_BITSIZE (GET_MODE (x))));
  766. #endif
  767.  
  768.       reg_nonzero_bits[REGNO (x)]
  769.         |= nonzero_bits (src, nonzero_bits_mode);
  770.       num = num_sign_bit_copies (SET_SRC (set), GET_MODE (x));
  771.       if (reg_sign_bit_copies[REGNO (x)] == 0
  772.           || reg_sign_bit_copies[REGNO (x)] > num)
  773.         reg_sign_bit_copies[REGNO (x)] = num;
  774.     }
  775.       else
  776.     {
  777.       reg_nonzero_bits[REGNO (x)] = GET_MODE_MASK (GET_MODE (x));
  778.       reg_sign_bit_copies[REGNO (x)] = 0;
  779.     }
  780.     }
  781. }
  782.  
  783. /* See if INSN can be combined into I3.  PRED and SUCC are optionally
  784.    insns that were previously combined into I3 or that will be combined
  785.    into the merger of INSN and I3.
  786.  
  787.    Return 0 if the combination is not allowed for any reason.
  788.  
  789.    If the combination is allowed, *PDEST will be set to the single 
  790.    destination of INSN and *PSRC to the single source, and this function
  791.    will return 1.  */
  792.  
  793. static int
  794. can_combine_p (insn, i3, pred, succ, pdest, psrc)
  795.      rtx insn;
  796.      rtx i3;
  797.      rtx pred, succ;
  798.      rtx *pdest, *psrc;
  799. {
  800.   int i;
  801.   rtx set = 0, src, dest;
  802.   rtx p, link;
  803.   int all_adjacent = (succ ? (next_active_insn (insn) == succ
  804.                   && next_active_insn (succ) == i3)
  805.               : next_active_insn (insn) == i3);
  806.  
  807.   /* Can combine only if previous insn is a SET of a REG, a SUBREG or CC0.
  808.      or a PARALLEL consisting of such a SET and CLOBBERs. 
  809.  
  810.      If INSN has CLOBBER parallel parts, ignore them for our processing.
  811.      By definition, these happen during the execution of the insn.  When it
  812.      is merged with another insn, all bets are off.  If they are, in fact,
  813.      needed and aren't also supplied in I3, they may be added by
  814.      recog_for_combine.  Otherwise, it won't match. 
  815.  
  816.      We can also ignore a SET whose SET_DEST is mentioned in a REG_UNUSED
  817.      note.
  818.  
  819.      Get the source and destination of INSN.  If more than one, can't 
  820.      combine.  */
  821.      
  822.   if (GET_CODE (PATTERN (insn)) == SET)
  823.     set = PATTERN (insn);
  824.   else if (GET_CODE (PATTERN (insn)) == PARALLEL
  825.        && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
  826.     {
  827.       for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
  828.     {
  829.       rtx elt = XVECEXP (PATTERN (insn), 0, i);
  830.  
  831.       switch (GET_CODE (elt))
  832.         {
  833.           /* We can ignore CLOBBERs.  */
  834.         case CLOBBER:
  835.           break;
  836.  
  837.         case SET:
  838.           /* Ignore SETs whose result isn't used but not those that
  839.          have side-effects.  */
  840.           if (find_reg_note (insn, REG_UNUSED, SET_DEST (elt))
  841.           && ! side_effects_p (elt))
  842.         break;
  843.  
  844.           /* If we have already found a SET, this is a second one and
  845.          so we cannot combine with this insn.  */
  846.           if (set)
  847.         return 0;
  848.  
  849.           set = elt;
  850.           break;
  851.  
  852.         default:
  853.           /* Anything else means we can't combine.  */
  854.           return 0;
  855.         }
  856.     }
  857.  
  858.       if (set == 0
  859.       /* If SET_SRC is an ASM_OPERANDS we can't throw away these CLOBBERs,
  860.          so don't do anything with it.  */
  861.       || GET_CODE (SET_SRC (set)) == ASM_OPERANDS)
  862.     return 0;
  863.     }
  864.   else
  865.     return 0;
  866.  
  867.   if (set == 0)
  868.     return 0;
  869.  
  870.   set = expand_field_assignment (set);
  871.   src = SET_SRC (set), dest = SET_DEST (set);
  872.  
  873.   /* Don't eliminate a store in the stack pointer.  */
  874.   if (dest == stack_pointer_rtx
  875.       /* If we couldn't eliminate a field assignment, we can't combine.  */
  876.       || GET_CODE (dest) == ZERO_EXTRACT || GET_CODE (dest) == STRICT_LOW_PART
  877.       /* Don't combine with an insn that sets a register to itself if it has
  878.      a REG_EQUAL note.  This may be part of a REG_NO_CONFLICT sequence.  */
  879.       || (rtx_equal_p (src, dest) && find_reg_note (insn, REG_EQUAL, NULL_RTX))
  880.       /* Can't merge a function call.  */
  881.       || GET_CODE (src) == CALL
  882.       /* Don't eliminate a function call argument.  */
  883.       || (GET_CODE (i3) == CALL_INSN && find_reg_fusage (i3, USE, dest))
  884.       /* Don't substitute into an incremented register.  */
  885.       || FIND_REG_INC_NOTE (i3, dest)
  886.       || (succ && FIND_REG_INC_NOTE (succ, dest))
  887.       /* Don't combine the end of a libcall into anything.  */
  888.       || find_reg_note (insn, REG_RETVAL, NULL_RTX)
  889.       /* Make sure that DEST is not used after SUCC but before I3.  */
  890.       || (succ && ! all_adjacent
  891.       && reg_used_between_p (dest, succ, i3))
  892.       /* Make sure that the value that is to be substituted for the register
  893.      does not use any registers whose values alter in between.  However,
  894.      If the insns are adjacent, a use can't cross a set even though we
  895.      think it might (this can happen for a sequence of insns each setting
  896.      the same destination; reg_last_set of that register might point to
  897.      a NOTE).  If INSN has a REG_EQUIV note, the register is always
  898.      equivalent to the memory so the substitution is valid even if there
  899.      are intervening stores.  Also, don't move a volatile asm or
  900.      UNSPEC_VOLATILE across any other insns.  */
  901.       || (! all_adjacent
  902.       && (((GET_CODE (src) != MEM
  903.         || ! find_reg_note (insn, REG_EQUIV, src))
  904.            && use_crosses_set_p (src, INSN_CUID (insn)))
  905.           || (GET_CODE (src) == ASM_OPERANDS && MEM_VOLATILE_P (src))
  906.           || GET_CODE (src) == UNSPEC_VOLATILE))
  907.       /* If there is a REG_NO_CONFLICT note for DEST in I3 or SUCC, we get
  908.      better register allocation by not doing the combine.  */
  909.       || find_reg_note (i3, REG_NO_CONFLICT, dest)
  910.       || (succ && find_reg_note (succ, REG_NO_CONFLICT, dest))
  911.       /* Don't combine across a CALL_INSN, because that would possibly
  912.      change whether the life span of some REGs crosses calls or not,
  913.      and it is a pain to update that information.
  914.      Exception: if source is a constant, moving it later can't hurt.
  915.      Accept that special case, because it helps -fforce-addr a lot.  */
  916.       || (INSN_CUID (insn) < last_call_cuid && ! CONSTANT_P (src)))
  917.     return 0;
  918.  
  919.   /* DEST must either be a REG or CC0.  */
  920.   if (GET_CODE (dest) == REG)
  921.     {
  922.       /* If register alignment is being enforced for multi-word items in all
  923.      cases except for parameters, it is possible to have a register copy
  924.      insn referencing a hard register that is not allowed to contain the
  925.      mode being copied and which would not be valid as an operand of most
  926.      insns.  Eliminate this problem by not combining with such an insn.
  927.  
  928.      Also, on some machines we don't want to extend the life of a hard
  929.      register.  */
  930.  
  931.       if (GET_CODE (src) == REG
  932.       && ((REGNO (dest) < FIRST_PSEUDO_REGISTER
  933.            && ! HARD_REGNO_MODE_OK (REGNO (dest), GET_MODE (dest)))
  934.           /* Don't extend the life of a hard register unless it is
  935.          user variable (if we have few registers) or it can't
  936.          fit into the desired register (meaning something special
  937.          is going on).  */
  938.           || (REGNO (src) < FIRST_PSEUDO_REGISTER
  939.           && (! HARD_REGNO_MODE_OK (REGNO (src), GET_MODE (src))
  940. #ifdef SMALL_REGISTER_CLASSES
  941.               || ! REG_USERVAR_P (src)
  942. #endif
  943.               ))))
  944.     return 0;
  945.     }
  946.   else if (GET_CODE (dest) != CC0)
  947.     return 0;
  948.  
  949.   /* Don't substitute for a register intended as a clobberable operand.
  950.      Similarly, don't substitute an expression containing a register that
  951.      will be clobbered in I3.  */
  952.   if (GET_CODE (PATTERN (i3)) == PARALLEL)
  953.     for (i = XVECLEN (PATTERN (i3), 0) - 1; i >= 0; i--)
  954.       if (GET_CODE (XVECEXP (PATTERN (i3), 0, i)) == CLOBBER
  955.       && (reg_overlap_mentioned_p (XEXP (XVECEXP (PATTERN (i3), 0, i), 0),
  956.                        src)
  957.           || rtx_equal_p (XEXP (XVECEXP (PATTERN (i3), 0, i), 0), dest)))
  958.     return 0;
  959.  
  960.   /* If INSN contains anything volatile, or is an `asm' (whether volatile
  961.      or not), reject, unless nothing volatile comes between it and I3,
  962.      with the exception of SUCC.  */
  963.  
  964.   if (GET_CODE (src) == ASM_OPERANDS || volatile_refs_p (src))
  965.     for (p = NEXT_INSN (insn); p != i3; p = NEXT_INSN (p))
  966.       if (GET_RTX_CLASS (GET_CODE (p)) == 'i'
  967.       && p != succ && volatile_refs_p (PATTERN (p)))
  968.     return 0;
  969.  
  970.   /* If there are any volatile insns between INSN and I3, reject, because
  971.      they might affect machine state.  */
  972.  
  973.   for (p = NEXT_INSN (insn); p != i3; p = NEXT_INSN (p))
  974.     if (GET_RTX_CLASS (GET_CODE (p)) == 'i'
  975.     && p != succ && volatile_insn_p (PATTERN (p)))
  976.       return 0;
  977.  
  978.   /* If INSN or I2 contains an autoincrement or autodecrement,
  979.      make sure that register is not used between there and I3,
  980.      and not already used in I3 either.
  981.      Also insist that I3 not be a jump; if it were one
  982.      and the incremented register were spilled, we would lose.  */
  983.  
  984. #ifdef AUTO_INC_DEC
  985.   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  986.     if (REG_NOTE_KIND (link) == REG_INC
  987.     && (GET_CODE (i3) == JUMP_INSN
  988.         || reg_used_between_p (XEXP (link, 0), insn, i3)
  989.         || reg_overlap_mentioned_p (XEXP (link, 0), PATTERN (i3))))
  990.       return 0;
  991. #endif
  992.  
  993. #ifdef HAVE_cc0
  994.   /* Don't combine an insn that follows a CC0-setting insn.
  995.      An insn that uses CC0 must not be separated from the one that sets it.
  996.      We do, however, allow I2 to follow a CC0-setting insn if that insn
  997.      is passed as I1; in that case it will be deleted also.
  998.      We also allow combining in this case if all the insns are adjacent
  999.      because that would leave the two CC0 insns adjacent as well.
  1000.      It would be more logical to test whether CC0 occurs inside I1 or I2,
  1001.      but that would be much slower, and this ought to be equivalent.  */
  1002.  
  1003.   p = prev_nonnote_insn (insn);
  1004.   if (p && p != pred && GET_CODE (p) == INSN && sets_cc0_p (PATTERN (p))
  1005.       && ! all_adjacent)
  1006.     return 0;
  1007. #endif
  1008.  
  1009.   /* If we get here, we have passed all the tests and the combination is
  1010.      to be allowed.  */
  1011.  
  1012.   *pdest = dest;
  1013.   *psrc = src;
  1014.  
  1015.   return 1;
  1016. }
  1017.  
  1018. /* LOC is the location within I3 that contains its pattern or the component
  1019.    of a PARALLEL of the pattern.  We validate that it is valid for combining.
  1020.  
  1021.    One problem is if I3 modifies its output, as opposed to replacing it
  1022.    entirely, we can't allow the output to contain I2DEST or I1DEST as doing
  1023.    so would produce an insn that is not equivalent to the original insns.
  1024.  
  1025.    Consider:
  1026.  
  1027.          (set (reg:DI 101) (reg:DI 100))
  1028.      (set (subreg:SI (reg:DI 101) 0) <foo>)
  1029.  
  1030.    This is NOT equivalent to:
  1031.  
  1032.          (parallel [(set (subreg:SI (reg:DI 100) 0) <foo>)
  1033.              (set (reg:DI 101) (reg:DI 100))])
  1034.  
  1035.    Not only does this modify 100 (in which case it might still be valid
  1036.    if 100 were dead in I2), it sets 101 to the ORIGINAL value of 100. 
  1037.  
  1038.    We can also run into a problem if I2 sets a register that I1
  1039.    uses and I1 gets directly substituted into I3 (not via I2).  In that
  1040.    case, we would be getting the wrong value of I2DEST into I3, so we
  1041.    must reject the combination.  This case occurs when I2 and I1 both
  1042.    feed into I3, rather than when I1 feeds into I2, which feeds into I3.
  1043.    If I1_NOT_IN_SRC is non-zero, it means that finding I1 in the source
  1044.    of a SET must prevent combination from occurring.
  1045.  
  1046.    On machines where SMALL_REGISTER_CLASSES is defined, we don't combine
  1047.    if the destination of a SET is a hard register that isn't a user
  1048.    variable.
  1049.  
  1050.    Before doing the above check, we first try to expand a field assignment
  1051.    into a set of logical operations.
  1052.  
  1053.    If PI3_DEST_KILLED is non-zero, it is a pointer to a location in which
  1054.    we place a register that is both set and used within I3.  If more than one
  1055.    such register is detected, we fail.
  1056.  
  1057.    Return 1 if the combination is valid, zero otherwise.  */
  1058.  
  1059. static int
  1060. combinable_i3pat (i3, loc, i2dest, i1dest, i1_not_in_src, pi3dest_killed)
  1061.      rtx i3;
  1062.      rtx *loc;
  1063.      rtx i2dest;
  1064.      rtx i1dest;
  1065.      int i1_not_in_src;
  1066.      rtx *pi3dest_killed;
  1067. {
  1068.   rtx x = *loc;
  1069.  
  1070.   if (GET_CODE (x) == SET)
  1071.     {
  1072.       rtx set = expand_field_assignment (x);
  1073.       rtx dest = SET_DEST (set);
  1074.       rtx src = SET_SRC (set);
  1075.       rtx inner_dest = dest, inner_src = src;
  1076.  
  1077.       SUBST (*loc, set);
  1078.  
  1079.       while (GET_CODE (inner_dest) == STRICT_LOW_PART
  1080.          || GET_CODE (inner_dest) == SUBREG
  1081.          || GET_CODE (inner_dest) == ZERO_EXTRACT)
  1082.     inner_dest = XEXP (inner_dest, 0);
  1083.  
  1084.   /* We probably don't need this any more now that LIMIT_RELOAD_CLASS
  1085.      was added.  */
  1086. #if 0
  1087.       while (GET_CODE (inner_src) == STRICT_LOW_PART
  1088.          || GET_CODE (inner_src) == SUBREG
  1089.          || GET_CODE (inner_src) == ZERO_EXTRACT)
  1090.     inner_src = XEXP (inner_src, 0);
  1091.  
  1092.       /* If it is better that two different modes keep two different pseudos,
  1093.      avoid combining them.  This avoids producing the following pattern
  1094.      on a 386:
  1095.       (set (subreg:SI (reg/v:QI 21) 0)
  1096.            (lshiftrt:SI (reg/v:SI 20)
  1097.                (const_int 24)))
  1098.      If that were made, reload could not handle the pair of
  1099.      reg 20/21, since it would try to get any GENERAL_REGS
  1100.      but some of them don't handle QImode.  */
  1101.  
  1102.       if (rtx_equal_p (inner_src, i2dest)
  1103.       && GET_CODE (inner_dest) == REG
  1104.       && ! MODES_TIEABLE_P (GET_MODE (i2dest), GET_MODE (inner_dest)))
  1105.     return 0;
  1106. #endif
  1107.  
  1108.       /* Check for the case where I3 modifies its output, as
  1109.      discussed above.  */
  1110.       if ((inner_dest != dest
  1111.        && (reg_overlap_mentioned_p (i2dest, inner_dest)
  1112.            || (i1dest && reg_overlap_mentioned_p (i1dest, inner_dest))))
  1113.       /* This is the same test done in can_combine_p except that we
  1114.          allow a hard register with SMALL_REGISTER_CLASSES if SRC is a
  1115.          CALL operation.  */
  1116.       || (GET_CODE (inner_dest) == REG
  1117.           && REGNO (inner_dest) < FIRST_PSEUDO_REGISTER
  1118.           && (! HARD_REGNO_MODE_OK (REGNO (inner_dest),
  1119.                     GET_MODE (inner_dest))
  1120. #ifdef SMALL_REGISTER_CLASSES
  1121.          || (GET_CODE (src) != CALL && ! REG_USERVAR_P (inner_dest))
  1122. #endif
  1123.           ))
  1124.       || (i1_not_in_src && reg_overlap_mentioned_p (i1dest, src)))
  1125.     return 0;
  1126.  
  1127.       /* If DEST is used in I3, it is being killed in this insn,
  1128.      so record that for later. 
  1129.      Never add REG_DEAD notes for the FRAME_POINTER_REGNUM or the
  1130.      STACK_POINTER_REGNUM, since these are always considered to be
  1131.      live.  Similarly for ARG_POINTER_REGNUM if it is fixed.  */
  1132.       if (pi3dest_killed && GET_CODE (dest) == REG
  1133.       && reg_referenced_p (dest, PATTERN (i3))
  1134.       && REGNO (dest) != FRAME_POINTER_REGNUM
  1135. #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
  1136.       && REGNO (dest) != HARD_FRAME_POINTER_REGNUM
  1137. #endif
  1138. #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  1139.       && (REGNO (dest) != ARG_POINTER_REGNUM
  1140.           || ! fixed_regs [REGNO (dest)])
  1141. #endif
  1142.       && REGNO (dest) != STACK_POINTER_REGNUM)
  1143.     {
  1144.       if (*pi3dest_killed)
  1145.         return 0;
  1146.  
  1147.       *pi3dest_killed = dest;
  1148.     }
  1149.     }
  1150.  
  1151.   else if (GET_CODE (x) == PARALLEL)
  1152.     {
  1153.       int i;
  1154.  
  1155.       for (i = 0; i < XVECLEN (x, 0); i++)
  1156.     if (! combinable_i3pat (i3, &XVECEXP (x, 0, i), i2dest, i1dest,
  1157.                 i1_not_in_src, pi3dest_killed))
  1158.       return 0;
  1159.     }
  1160.  
  1161.   return 1;
  1162. }
  1163.  
  1164. /* Try to combine the insns I1 and I2 into I3.
  1165.    Here I1 and I2 appear earlier than I3.
  1166.    I1 can be zero; then we combine just I2 into I3.
  1167.  
  1168.    It we are combining three insns and the resulting insn is not recognized,
  1169.    try splitting it into two insns.  If that happens, I2 and I3 are retained
  1170.    and I1 is pseudo-deleted by turning it into a NOTE.  Otherwise, I1 and I2
  1171.    are pseudo-deleted.
  1172.  
  1173.    Return 0 if the combination does not work.  Then nothing is changed. 
  1174.    If we did the combination, return the insn at which combine should
  1175.    resume scanning.  */
  1176.  
  1177. static rtx
  1178. try_combine (i3, i2, i1)
  1179.      register rtx i3, i2, i1;
  1180. {
  1181.   /* New patterns for I3 and I3, respectively.  */
  1182.   rtx newpat, newi2pat = 0;
  1183.   /* Indicates need to preserve SET in I1 or I2 in I3 if it is not dead.  */
  1184.   int added_sets_1, added_sets_2;
  1185.   /* Total number of SETs to put into I3.  */
  1186.   int total_sets;
  1187.   /* Nonzero is I2's body now appears in I3.  */
  1188.   int i2_is_used;
  1189.   /* INSN_CODEs for new I3, new I2, and user of condition code.  */
  1190.   int insn_code_number, i2_code_number, other_code_number;
  1191.   /* Contains I3 if the destination of I3 is used in its source, which means
  1192.      that the old life of I3 is being killed.  If that usage is placed into
  1193.      I2 and not in I3, a REG_DEAD note must be made.  */
  1194.   rtx i3dest_killed = 0;
  1195.   /* SET_DEST and SET_SRC of I2 and I1.  */
  1196.   rtx i2dest, i2src, i1dest = 0, i1src = 0;
  1197.   /* PATTERN (I2), or a copy of it in certain cases.  */
  1198.   rtx i2pat;
  1199.   /* Indicates if I2DEST or I1DEST is in I2SRC or I1_SRC.  */
  1200.   int i2dest_in_i2src = 0, i1dest_in_i1src = 0, i2dest_in_i1src = 0;
  1201.   int i1_feeds_i3 = 0;
  1202.   /* Notes that must be added to REG_NOTES in I3 and I2.  */
  1203.   rtx new_i3_notes, new_i2_notes;
  1204.   /* Notes that we substituted I3 into I2 instead of the normal case.  */
  1205.   int i3_subst_into_i2 = 0;
  1206.  
  1207.   int maxreg;
  1208.   rtx temp;
  1209.   register rtx link;
  1210.   int i;
  1211.  
  1212.   /* If any of I1, I2, and I3 isn't really an insn, we can't do anything.
  1213.      This can occur when flow deletes an insn that it has merged into an
  1214.      auto-increment address.  We also can't do anything if I3 has a
  1215.      REG_LIBCALL note since we don't want to disrupt the contiguity of a
  1216.      libcall.  */
  1217.  
  1218.   if (GET_RTX_CLASS (GET_CODE (i3)) != 'i'
  1219.       || GET_RTX_CLASS (GET_CODE (i2)) != 'i'
  1220.       || (i1 && GET_RTX_CLASS (GET_CODE (i1)) != 'i')
  1221.       || find_reg_note (i3, REG_LIBCALL, NULL_RTX))
  1222.     return 0;
  1223.  
  1224.   combine_attempts++;
  1225.  
  1226.   undobuf.num_undo = previous_num_undos = 0;
  1227.   undobuf.other_insn = 0;
  1228.  
  1229.   /* Save the current high-water-mark so we can free storage if we didn't
  1230.      accept this combination.  */
  1231.   undobuf.storage = (char *) oballoc (0);
  1232.  
  1233.   /* Reset the hard register usage information.  */
  1234.   CLEAR_HARD_REG_SET (newpat_used_regs);
  1235.  
  1236.   /* If I1 and I2 both feed I3, they can be in any order.  To simplify the
  1237.      code below, set I1 to be the earlier of the two insns.  */
  1238.   if (i1 && INSN_CUID (i1) > INSN_CUID (i2))
  1239.     temp = i1, i1 = i2, i2 = temp;
  1240.  
  1241.   subst_prev_insn = 0;
  1242.   added_links_insn = 0;
  1243.  
  1244.   /* First check for one important special-case that the code below will
  1245.      not handle.  Namely, the case where I1 is zero, I2 has multiple sets,
  1246.      and I3 is a SET whose SET_SRC is a SET_DEST in I2.  In that case,
  1247.      we may be able to replace that destination with the destination of I3.
  1248.      This occurs in the common code where we compute both a quotient and
  1249.      remainder into a structure, in which case we want to do the computation
  1250.      directly into the structure to avoid register-register copies.
  1251.  
  1252.      We make very conservative checks below and only try to handle the
  1253.      most common cases of this.  For example, we only handle the case
  1254.      where I2 and I3 are adjacent to avoid making difficult register
  1255.      usage tests.  */
  1256.  
  1257.   if (i1 == 0 && GET_CODE (i3) == INSN && GET_CODE (PATTERN (i3)) == SET
  1258.       && GET_CODE (SET_SRC (PATTERN (i3))) == REG
  1259.       && REGNO (SET_SRC (PATTERN (i3))) >= FIRST_PSEUDO_REGISTER
  1260. #ifdef SMALL_REGISTER_CLASSES
  1261.       && (GET_CODE (SET_DEST (PATTERN (i3))) != REG
  1262.       || REGNO (SET_DEST (PATTERN (i3))) >= FIRST_PSEUDO_REGISTER
  1263.       || REG_USERVAR_P (SET_DEST (PATTERN (i3))))
  1264. #endif
  1265.       && find_reg_note (i3, REG_DEAD, SET_SRC (PATTERN (i3)))
  1266.       && GET_CODE (PATTERN (i2)) == PARALLEL
  1267.       && ! side_effects_p (SET_DEST (PATTERN (i3)))
  1268.       /* If the dest of I3 is a ZERO_EXTRACT or STRICT_LOW_PART, the code
  1269.      below would need to check what is inside (and reg_overlap_mentioned_p
  1270.      doesn't support those codes anyway).  Don't allow those destinations;
  1271.      the resulting insn isn't likely to be recognized anyway.  */
  1272.       && GET_CODE (SET_DEST (PATTERN (i3))) != ZERO_EXTRACT
  1273.       && GET_CODE (SET_DEST (PATTERN (i3))) != STRICT_LOW_PART
  1274.       && ! reg_overlap_mentioned_p (SET_SRC (PATTERN (i3)),
  1275.                     SET_DEST (PATTERN (i3)))
  1276.       && next_real_insn (i2) == i3)
  1277.     {
  1278.       rtx p2 = PATTERN (i2);
  1279.  
  1280.       /* Make sure that the destination of I3,
  1281.      which we are going to substitute into one output of I2,
  1282.      is not used within another output of I2.  We must avoid making this:
  1283.      (parallel [(set (mem (reg 69)) ...)
  1284.             (set (reg 69) ...)])
  1285.      which is not well-defined as to order of actions.
  1286.      (Besides, reload can't handle output reloads for this.)
  1287.  
  1288.      The problem can also happen if the dest of I3 is a memory ref,
  1289.      if another dest in I2 is an indirect memory ref.  */
  1290.       for (i = 0; i < XVECLEN (p2, 0); i++)
  1291.     if (GET_CODE (XVECEXP (p2, 0, i)) == SET
  1292.         && reg_overlap_mentioned_p (SET_DEST (PATTERN (i3)),
  1293.                     SET_DEST (XVECEXP (p2, 0, i))))
  1294.       break;
  1295.  
  1296.       if (i == XVECLEN (p2, 0))
  1297.     for (i = 0; i < XVECLEN (p2, 0); i++)
  1298.       if (SET_DEST (XVECEXP (p2, 0, i)) == SET_SRC (PATTERN (i3)))
  1299.         {
  1300.           combine_merges++;
  1301.  
  1302.           subst_insn = i3;
  1303.           subst_low_cuid = INSN_CUID (i2);
  1304.  
  1305.           added_sets_2 = added_sets_1 = 0;
  1306.           i2dest = SET_SRC (PATTERN (i3));
  1307.  
  1308.           /* Replace the dest in I2 with our dest and make the resulting
  1309.          insn the new pattern for I3.  Then skip to where we
  1310.          validate the pattern.  Everything was set up above.  */
  1311.           SUBST (SET_DEST (XVECEXP (p2, 0, i)), 
  1312.              SET_DEST (PATTERN (i3)));
  1313.  
  1314.           newpat = p2;
  1315.           i3_subst_into_i2 = 1;
  1316.           goto validate_replacement;
  1317.         }
  1318.     }
  1319.  
  1320. #ifndef HAVE_cc0
  1321.   /* If we have no I1 and I2 looks like:
  1322.     (parallel [(set (reg:CC X) (compare:CC OP (const_int 0)))
  1323.            (set Y OP)])
  1324.      make up a dummy I1 that is
  1325.     (set Y OP)
  1326.      and change I2 to be
  1327.         (set (reg:CC X) (compare:CC Y (const_int 0)))
  1328.  
  1329.      (We can ignore any trailing CLOBBERs.)
  1330.  
  1331.      This undoes a previous combination and allows us to match a branch-and-
  1332.      decrement insn.  */
  1333.  
  1334.   if (i1 == 0 && GET_CODE (PATTERN (i2)) == PARALLEL
  1335.       && XVECLEN (PATTERN (i2), 0) >= 2
  1336.       && GET_CODE (XVECEXP (PATTERN (i2), 0, 0)) == SET
  1337.       && (GET_MODE_CLASS (GET_MODE (SET_DEST (XVECEXP (PATTERN (i2), 0, 0))))
  1338.       == MODE_CC)
  1339.       && GET_CODE (SET_SRC (XVECEXP (PATTERN (i2), 0, 0))) == COMPARE
  1340.       && XEXP (SET_SRC (XVECEXP (PATTERN (i2), 0, 0)), 1) == const0_rtx
  1341.       && GET_CODE (XVECEXP (PATTERN (i2), 0, 1)) == SET
  1342.       && GET_CODE (SET_DEST (XVECEXP (PATTERN (i2), 0, 1))) == REG
  1343.       && rtx_equal_p (XEXP (SET_SRC (XVECEXP (PATTERN (i2), 0, 0)), 0),
  1344.               SET_SRC (XVECEXP (PATTERN (i2), 0, 1))))
  1345.     {
  1346.       for (i =  XVECLEN (PATTERN (i2), 0) - 1; i >= 2; i--)
  1347.     if (GET_CODE (XVECEXP (PATTERN (i2), 0, i)) != CLOBBER)
  1348.       break;
  1349.  
  1350.       if (i == 1)
  1351.     {
  1352.       /* We make I1 with the same INSN_UID as I2.  This gives it
  1353.          the same INSN_CUID for value tracking.  Our fake I1 will
  1354.          never appear in the insn stream so giving it the same INSN_UID
  1355.          as I2 will not cause a problem.  */
  1356.  
  1357.       subst_prev_insn = i1
  1358.         = gen_rtx (INSN, VOIDmode, INSN_UID (i2), 0, i2,
  1359.                XVECEXP (PATTERN (i2), 0, 1), -1, 0, 0);
  1360.  
  1361.       SUBST (PATTERN (i2), XVECEXP (PATTERN (i2), 0, 0));
  1362.       SUBST (XEXP (SET_SRC (PATTERN (i2)), 0),
  1363.          SET_DEST (PATTERN (i1)));
  1364.     }
  1365.     }
  1366. #endif
  1367.  
  1368.   /* Verify that I2 and I1 are valid for combining.  */
  1369.   if (! can_combine_p (i2, i3, i1, NULL_RTX, &i2dest, &i2src)
  1370.       || (i1 && ! can_combine_p (i1, i3, NULL_RTX, i2, &i1dest, &i1src)))
  1371.     {
  1372.       undo_all ();
  1373.       return 0;
  1374.     }
  1375.  
  1376.   /* Record whether I2DEST is used in I2SRC and similarly for the other
  1377.      cases.  Knowing this will help in register status updating below.  */
  1378.   i2dest_in_i2src = reg_overlap_mentioned_p (i2dest, i2src);
  1379.   i1dest_in_i1src = i1 && reg_overlap_mentioned_p (i1dest, i1src);
  1380.   i2dest_in_i1src = i1 && reg_overlap_mentioned_p (i2dest, i1src);
  1381.  
  1382.   /* See if I1 directly feeds into I3.  It does if I1DEST is not used
  1383.      in I2SRC.  */
  1384.   i1_feeds_i3 = i1 && ! reg_overlap_mentioned_p (i1dest, i2src);
  1385.  
  1386.   /* Ensure that I3's pattern can be the destination of combines.  */
  1387.   if (! combinable_i3pat (i3, &PATTERN (i3), i2dest, i1dest,
  1388.               i1 && i2dest_in_i1src && i1_feeds_i3,
  1389.               &i3dest_killed))
  1390.     {
  1391.       undo_all ();
  1392.       return 0;
  1393.     }
  1394.  
  1395.   /* If I3 has an inc, then give up if I1 or I2 uses the reg that is inc'd.
  1396.      We used to do this EXCEPT in one case: I3 has a post-inc in an
  1397.      output operand.  However, that exception can give rise to insns like
  1398.          mov r3,(r3)+
  1399.      which is a famous insn on the PDP-11 where the value of r3 used as the
  1400.      source was model-dependent.  Avoid this sort of thing.  */
  1401.  
  1402. #if 0
  1403.   if (!(GET_CODE (PATTERN (i3)) == SET
  1404.     && GET_CODE (SET_SRC (PATTERN (i3))) == REG
  1405.     && GET_CODE (SET_DEST (PATTERN (i3))) == MEM
  1406.     && (GET_CODE (XEXP (SET_DEST (PATTERN (i3)), 0)) == POST_INC
  1407.         || GET_CODE (XEXP (SET_DEST (PATTERN (i3)), 0)) == POST_DEC)))
  1408.     /* It's not the exception.  */
  1409. #endif
  1410. #ifdef AUTO_INC_DEC
  1411.     for (link = REG_NOTES (i3); link; link = XEXP (link, 1))
  1412.       if (REG_NOTE_KIND (link) == REG_INC
  1413.       && (reg_overlap_mentioned_p (XEXP (link, 0), PATTERN (i2))
  1414.           || (i1 != 0
  1415.           && reg_overlap_mentioned_p (XEXP (link, 0), PATTERN (i1)))))
  1416.     {
  1417.       undo_all ();
  1418.       return 0;
  1419.     }
  1420. #endif
  1421.  
  1422.   /* See if the SETs in I1 or I2 need to be kept around in the merged
  1423.      instruction: whenever the value set there is still needed past I3.
  1424.      For the SETs in I2, this is easy: we see if I2DEST dies or is set in I3.
  1425.  
  1426.      For the SET in I1, we have two cases:  If I1 and I2 independently
  1427.      feed into I3, the set in I1 needs to be kept around if I1DEST dies
  1428.      or is set in I3.  Otherwise (if I1 feeds I2 which feeds I3), the set
  1429.      in I1 needs to be kept around unless I1DEST dies or is set in either
  1430.      I2 or I3.  We can distinguish these cases by seeing if I2SRC mentions
  1431.      I1DEST.  If so, we know I1 feeds into I2.  */
  1432.  
  1433.   added_sets_2 = ! dead_or_set_p (i3, i2dest);
  1434.  
  1435.   added_sets_1
  1436.     = i1 && ! (i1_feeds_i3 ? dead_or_set_p (i3, i1dest)
  1437.            : (dead_or_set_p (i3, i1dest) || dead_or_set_p (i2, i1dest)));
  1438.  
  1439.   /* If the set in I2 needs to be kept around, we must make a copy of
  1440.      PATTERN (I2), so that when we substitute I1SRC for I1DEST in
  1441.      PATTERN (I2), we are only substituting for the original I1DEST, not into
  1442.      an already-substituted copy.  This also prevents making self-referential
  1443.      rtx.  If I2 is a PARALLEL, we just need the piece that assigns I2SRC to
  1444.      I2DEST.  */
  1445.  
  1446.   i2pat = (GET_CODE (PATTERN (i2)) == PARALLEL
  1447.        ? gen_rtx (SET, VOIDmode, i2dest, i2src)
  1448.        : PATTERN (i2));
  1449.  
  1450.   if (added_sets_2)
  1451.     i2pat = copy_rtx (i2pat);
  1452.  
  1453.   combine_merges++;
  1454.  
  1455.   /* Substitute in the latest insn for the regs set by the earlier ones.  */
  1456.  
  1457.   maxreg = max_reg_num ();
  1458.  
  1459.   subst_insn = i3;
  1460.  
  1461.   /* It is possible that the source of I2 or I1 may be performing an
  1462.      unneeded operation, such as a ZERO_EXTEND of something that is known
  1463.      to have the high part zero.  Handle that case by letting subst look at
  1464.      the innermost one of them.
  1465.  
  1466.      Another way to do this would be to have a function that tries to
  1467.      simplify a single insn instead of merging two or more insns.  We don't
  1468.      do this because of the potential of infinite loops and because
  1469.      of the potential extra memory required.  However, doing it the way
  1470.      we are is a bit of a kludge and doesn't catch all cases.
  1471.  
  1472.      But only do this if -fexpensive-optimizations since it slows things down
  1473.      and doesn't usually win.  */
  1474.  
  1475.   if (flag_expensive_optimizations)
  1476.     {
  1477.       /* Pass pc_rtx so no substitutions are done, just simplifications.
  1478.      The cases that we are interested in here do not involve the few
  1479.      cases were is_replaced is checked.  */
  1480.       if (i1)
  1481.     {
  1482.       subst_low_cuid = INSN_CUID (i1);
  1483.       i1src = subst (i1src, pc_rtx, pc_rtx, 0, 0);
  1484.     }
  1485.       else
  1486.     {
  1487.       subst_low_cuid = INSN_CUID (i2);
  1488.       i2src = subst (i2src, pc_rtx, pc_rtx, 0, 0);
  1489.     }
  1490.  
  1491.       previous_num_undos = undobuf.num_undo;
  1492.     }
  1493.  
  1494. #ifndef HAVE_cc0
  1495.   /* Many machines that don't use CC0 have insns that can both perform an
  1496.      arithmetic operation and set the condition code.  These operations will
  1497.      be represented as a PARALLEL with the first element of the vector
  1498.      being a COMPARE of an arithmetic operation with the constant zero.
  1499.      The second element of the vector will set some pseudo to the result
  1500.      of the same arithmetic operation.  If we simplify the COMPARE, we won't
  1501.      match such a pattern and so will generate an extra insn.   Here we test
  1502.      for this case, where both the comparison and the operation result are
  1503.      needed, and make the PARALLEL by just replacing I2DEST in I3SRC with
  1504.      I2SRC.  Later we will make the PARALLEL that contains I2.  */
  1505.  
  1506.   if (i1 == 0 && added_sets_2 && GET_CODE (PATTERN (i3)) == SET
  1507.       && GET_CODE (SET_SRC (PATTERN (i3))) == COMPARE
  1508.       && XEXP (SET_SRC (PATTERN (i3)), 1) == const0_rtx
  1509.       && rtx_equal_p (XEXP (SET_SRC (PATTERN (i3)), 0), i2dest))
  1510.     {
  1511.       rtx *cc_use;
  1512.       enum machine_mode compare_mode;
  1513.  
  1514.       newpat = PATTERN (i3);
  1515.       SUBST (XEXP (SET_SRC (newpat), 0), i2src);
  1516.  
  1517.       i2_is_used = 1;
  1518.  
  1519. #ifdef EXTRA_CC_MODES
  1520.       /* See if a COMPARE with the operand we substituted in should be done
  1521.      with the mode that is currently being used.  If not, do the same
  1522.      processing we do in `subst' for a SET; namely, if the destination
  1523.      is used only once, try to replace it with a register of the proper
  1524.      mode and also replace the COMPARE.  */
  1525.       if (undobuf.other_insn == 0
  1526.       && (cc_use = find_single_use (SET_DEST (newpat), i3,
  1527.                     &undobuf.other_insn))
  1528.       && ((compare_mode = SELECT_CC_MODE (GET_CODE (*cc_use),
  1529.                           i2src, const0_rtx))
  1530.           != GET_MODE (SET_DEST (newpat))))
  1531.     {
  1532.       int regno = REGNO (SET_DEST (newpat));
  1533.       rtx new_dest = gen_rtx (REG, compare_mode, regno);
  1534.  
  1535.       if (regno < FIRST_PSEUDO_REGISTER
  1536.           || (reg_n_sets[regno] == 1 && ! added_sets_2
  1537.           && ! REG_USERVAR_P (SET_DEST (newpat))))
  1538.         {
  1539.           if (regno >= FIRST_PSEUDO_REGISTER)
  1540.         SUBST (regno_reg_rtx[regno], new_dest);
  1541.  
  1542.           SUBST (SET_DEST (newpat), new_dest);
  1543.           SUBST (XEXP (*cc_use, 0), new_dest);
  1544.           SUBST (SET_SRC (newpat),
  1545.              gen_rtx_combine (COMPARE, compare_mode,
  1546.                       i2src, const0_rtx));
  1547.         }
  1548.       else
  1549.         undobuf.other_insn = 0;
  1550.     }
  1551. #endif      
  1552.     }
  1553.   else
  1554. #endif
  1555.     {
  1556.       n_occurrences = 0;        /* `subst' counts here */
  1557.  
  1558.       /* If I1 feeds into I2 (not into I3) and I1DEST is in I1SRC, we
  1559.      need to make a unique copy of I2SRC each time we substitute it
  1560.      to avoid self-referential rtl.  */
  1561.  
  1562.       subst_low_cuid = INSN_CUID (i2);
  1563.       newpat = subst (PATTERN (i3), i2dest, i2src, 0,
  1564.               ! i1_feeds_i3 && i1dest_in_i1src);
  1565.       previous_num_undos = undobuf.num_undo;
  1566.  
  1567.       /* Record whether i2's body now appears within i3's body.  */
  1568.       i2_is_used = n_occurrences;
  1569.     }
  1570.  
  1571.   /* If we already got a failure, don't try to do more.  Otherwise,
  1572.      try to substitute in I1 if we have it.  */
  1573.  
  1574.   if (i1 && GET_CODE (newpat) != CLOBBER)
  1575.     {
  1576.       /* Before we can do this substitution, we must redo the test done
  1577.      above (see detailed comments there) that ensures  that I1DEST
  1578.      isn't mentioned in any SETs in NEWPAT that are field assignments. */
  1579.  
  1580.       if (! combinable_i3pat (NULL_RTX, &newpat, i1dest, NULL_RTX,
  1581.                   0, NULL_PTR))
  1582.     {
  1583.       undo_all ();
  1584.       return 0;
  1585.     }
  1586.  
  1587.       n_occurrences = 0;
  1588.       subst_low_cuid = INSN_CUID (i1);
  1589.       newpat = subst (newpat, i1dest, i1src, 0, 0);
  1590.       previous_num_undos = undobuf.num_undo;
  1591.     }
  1592.  
  1593.   /* Fail if an autoincrement side-effect has been duplicated.  Be careful
  1594.      to count all the ways that I2SRC and I1SRC can be used.  */
  1595.   if ((FIND_REG_INC_NOTE (i2, NULL_RTX) != 0
  1596.        && i2_is_used + added_sets_2 > 1)
  1597.       || (i1 != 0 && FIND_REG_INC_NOTE (i1, NULL_RTX) != 0
  1598.       && (n_occurrences + added_sets_1 + (added_sets_2 && ! i1_feeds_i3)
  1599.           > 1))
  1600.       /* Fail if we tried to make a new register (we used to abort, but there's
  1601.      really no reason to).  */
  1602.       || max_reg_num () != maxreg
  1603.       /* Fail if we couldn't do something and have a CLOBBER.  */
  1604.       || GET_CODE (newpat) == CLOBBER)
  1605.     {
  1606.       undo_all ();
  1607.       return 0;
  1608.     }
  1609.  
  1610.   /* If the actions of the earlier insns must be kept
  1611.      in addition to substituting them into the latest one,
  1612.      we must make a new PARALLEL for the latest insn
  1613.      to hold additional the SETs.  */
  1614.  
  1615.   if (added_sets_1 || added_sets_2)
  1616.     {
  1617.       combine_extras++;
  1618.  
  1619.       if (GET_CODE (newpat) == PARALLEL)
  1620.     {
  1621.       rtvec old = XVEC (newpat, 0);
  1622.       total_sets = XVECLEN (newpat, 0) + added_sets_1 + added_sets_2;
  1623.       newpat = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (total_sets));
  1624.       bcopy ((char *) &old->elem[0], (char *) &XVECEXP (newpat, 0, 0),
  1625.          sizeof (old->elem[0]) * old->num_elem);
  1626.     }
  1627.       else
  1628.     {
  1629.       rtx old = newpat;
  1630.       total_sets = 1 + added_sets_1 + added_sets_2;
  1631.       newpat = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (total_sets));
  1632.       XVECEXP (newpat, 0, 0) = old;
  1633.     }
  1634.  
  1635.      if (added_sets_1)
  1636.        XVECEXP (newpat, 0, --total_sets)
  1637.      = (GET_CODE (PATTERN (i1)) == PARALLEL
  1638.         ? gen_rtx (SET, VOIDmode, i1dest, i1src) : PATTERN (i1));
  1639.  
  1640.      if (added_sets_2)
  1641.     {
  1642.       /* If there is no I1, use I2's body as is.  We used to also not do
  1643.          the subst call below if I2 was substituted into I3,
  1644.          but that could lose a simplification.  */
  1645.       if (i1 == 0)
  1646.         XVECEXP (newpat, 0, --total_sets) = i2pat;
  1647.       else
  1648.         /* See comment where i2pat is assigned.  */
  1649.         XVECEXP (newpat, 0, --total_sets)
  1650.           = subst (i2pat, i1dest, i1src, 0, 0);
  1651.     }
  1652.     }
  1653.  
  1654.   /* We come here when we are replacing a destination in I2 with the
  1655.      destination of I3.  */
  1656.  validate_replacement:
  1657.  
  1658.   /* Note which hard regs this insn has as inputs.  */
  1659.   mark_used_regs_combine (newpat);
  1660.  
  1661.   /* Is the result of combination a valid instruction?  */
  1662.   insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
  1663.  
  1664.   /* If the result isn't valid, see if it is a PARALLEL of two SETs where
  1665.      the second SET's destination is a register that is unused.  In that case,
  1666.      we just need the first SET.   This can occur when simplifying a divmod
  1667.      insn.  We *must* test for this case here because the code below that
  1668.      splits two independent SETs doesn't handle this case correctly when it
  1669.      updates the register status.  Also check the case where the first
  1670.      SET's destination is unused.  That would not cause incorrect code, but
  1671.      does cause an unneeded insn to remain.  */
  1672.  
  1673.   if (insn_code_number < 0 && GET_CODE (newpat) == PARALLEL
  1674.       && XVECLEN (newpat, 0) == 2
  1675.       && GET_CODE (XVECEXP (newpat, 0, 0)) == SET
  1676.       && GET_CODE (XVECEXP (newpat, 0, 1)) == SET
  1677.       && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) == REG
  1678.       && find_reg_note (i3, REG_UNUSED, SET_DEST (XVECEXP (newpat, 0, 1)))
  1679.       && ! side_effects_p (SET_SRC (XVECEXP (newpat, 0, 1)))
  1680.       && asm_noperands (newpat) < 0)
  1681.     {
  1682.       newpat = XVECEXP (newpat, 0, 0);
  1683.       insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
  1684.     }
  1685.  
  1686.   else if (insn_code_number < 0 && GET_CODE (newpat) == PARALLEL
  1687.        && XVECLEN (newpat, 0) == 2
  1688.        && GET_CODE (XVECEXP (newpat, 0, 0)) == SET
  1689.        && GET_CODE (XVECEXP (newpat, 0, 1)) == SET
  1690.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) == REG
  1691.        && find_reg_note (i3, REG_UNUSED, SET_DEST (XVECEXP (newpat, 0, 0)))
  1692.        && ! side_effects_p (SET_SRC (XVECEXP (newpat, 0, 0)))
  1693.        && asm_noperands (newpat) < 0)
  1694.     {
  1695.       newpat = XVECEXP (newpat, 0, 1);
  1696.       insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
  1697.     }
  1698.  
  1699.   /* If we were combining three insns and the result is a simple SET
  1700.      with no ASM_OPERANDS that wasn't recognized, try to split it into two
  1701.      insns.  There are two ways to do this.  It can be split using a 
  1702.      machine-specific method (like when you have an addition of a large
  1703.      constant) or by combine in the function find_split_point.  */
  1704.  
  1705.   if (i1 && insn_code_number < 0 && GET_CODE (newpat) == SET
  1706.       && asm_noperands (newpat) < 0)
  1707.     {
  1708.       rtx m_split, *split;
  1709.       rtx ni2dest = i2dest;
  1710.  
  1711.       /* See if the MD file can split NEWPAT.  If it can't, see if letting it
  1712.      use I2DEST as a scratch register will help.  In the latter case,
  1713.      convert I2DEST to the mode of the source of NEWPAT if we can.  */
  1714.  
  1715.       m_split = split_insns (newpat, i3);
  1716.  
  1717.       /* We can only use I2DEST as a scratch reg if it doesn't overlap any
  1718.      inputs of NEWPAT.  */
  1719.  
  1720.       /* ??? If I2DEST is not safe, and I1DEST exists, then it would be
  1721.      possible to try that as a scratch reg.  This would require adding
  1722.      more code to make it work though.  */
  1723.  
  1724.       if (m_split == 0 && ! reg_overlap_mentioned_p (ni2dest, newpat))
  1725.     {
  1726.       /* If I2DEST is a hard register or the only use of a pseudo,
  1727.          we can change its mode.  */
  1728.       if (GET_MODE (SET_DEST (newpat)) != GET_MODE (i2dest)
  1729.           && GET_MODE (SET_DEST (newpat)) != VOIDmode
  1730.           && GET_CODE (i2dest) == REG
  1731.           && (REGNO (i2dest) < FIRST_PSEUDO_REGISTER
  1732.           || (reg_n_sets[REGNO (i2dest)] == 1 && ! added_sets_2
  1733.               && ! REG_USERVAR_P (i2dest))))
  1734.         ni2dest = gen_rtx (REG, GET_MODE (SET_DEST (newpat)),
  1735.                    REGNO (i2dest));
  1736.  
  1737.       m_split = split_insns (gen_rtx (PARALLEL, VOIDmode,
  1738.                       gen_rtvec (2, newpat,
  1739.                              gen_rtx (CLOBBER,
  1740.                                   VOIDmode,
  1741.                                   ni2dest))),
  1742.                  i3);
  1743.     }
  1744.  
  1745.       if (m_split && GET_CODE (m_split) == SEQUENCE
  1746.       && XVECLEN (m_split, 0) == 2
  1747.       && (next_real_insn (i2) == i3
  1748.           || ! use_crosses_set_p (PATTERN (XVECEXP (m_split, 0, 0)),
  1749.                       INSN_CUID (i2))))
  1750.     {
  1751.       rtx i2set, i3set;
  1752.       rtx newi3pat = PATTERN (XVECEXP (m_split, 0, 1));
  1753.       newi2pat = PATTERN (XVECEXP (m_split, 0, 0));
  1754.  
  1755.       i3set = single_set (XVECEXP (m_split, 0, 1));
  1756.       i2set = single_set (XVECEXP (m_split, 0, 0));
  1757.  
  1758.       /* In case we changed the mode of I2DEST, replace it in the
  1759.          pseudo-register table here.  We can't do it above in case this
  1760.          code doesn't get executed and we do a split the other way.  */
  1761.  
  1762.       if (REGNO (i2dest) >= FIRST_PSEUDO_REGISTER)
  1763.         SUBST (regno_reg_rtx[REGNO (i2dest)], ni2dest);
  1764.  
  1765.       i2_code_number = recog_for_combine (&newi2pat, i2, &new_i2_notes);
  1766.  
  1767.       /* If I2 or I3 has multiple SETs, we won't know how to track
  1768.          register status, so don't use these insns.  */
  1769.  
  1770.       if (i2_code_number >= 0 && i2set && i3set)
  1771.         insn_code_number = recog_for_combine (&newi3pat, i3,
  1772.                           &new_i3_notes);
  1773.  
  1774.       if (insn_code_number >= 0)
  1775.         newpat = newi3pat;
  1776.  
  1777.       /* It is possible that both insns now set the destination of I3.
  1778.          If so, we must show an extra use of it.  */
  1779.  
  1780.       if (insn_code_number >= 0 && GET_CODE (SET_DEST (i3set)) == REG
  1781.           && GET_CODE (SET_DEST (i2set)) == REG
  1782.           && REGNO (SET_DEST (i3set)) == REGNO (SET_DEST (i2set)))
  1783.         reg_n_sets[REGNO (SET_DEST (i2set))]++;
  1784.     }
  1785.  
  1786.       /* If we can split it and use I2DEST, go ahead and see if that
  1787.      helps things be recognized.  Verify that none of the registers
  1788.      are set between I2 and I3.  */
  1789.       if (insn_code_number < 0 && (split = find_split_point (&newpat, i3)) != 0
  1790. #ifdef HAVE_cc0
  1791.       && GET_CODE (i2dest) == REG
  1792. #endif
  1793.       /* We need I2DEST in the proper mode.  If it is a hard register
  1794.          or the only use of a pseudo, we can change its mode.  */
  1795.       && (GET_MODE (*split) == GET_MODE (i2dest)
  1796.           || GET_MODE (*split) == VOIDmode
  1797.           || REGNO (i2dest) < FIRST_PSEUDO_REGISTER
  1798.           || (reg_n_sets[REGNO (i2dest)] == 1 && ! added_sets_2
  1799.           && ! REG_USERVAR_P (i2dest)))
  1800.       && (next_real_insn (i2) == i3
  1801.           || ! use_crosses_set_p (*split, INSN_CUID (i2)))
  1802.       /* We can't overwrite I2DEST if its value is still used by
  1803.          NEWPAT.  */
  1804.       && ! reg_referenced_p (i2dest, newpat))
  1805.     {
  1806.       rtx newdest = i2dest;
  1807.  
  1808.       /* Get NEWDEST as a register in the proper mode.  We have already
  1809.          validated that we can do this.  */
  1810.       if (GET_MODE (i2dest) != GET_MODE (*split)
  1811.           && GET_MODE (*split) != VOIDmode)
  1812.         {
  1813.           newdest = gen_rtx (REG, GET_MODE (*split), REGNO (i2dest));
  1814.  
  1815.           if (REGNO (i2dest) >= FIRST_PSEUDO_REGISTER)
  1816.         SUBST (regno_reg_rtx[REGNO (i2dest)], newdest);
  1817.         }
  1818.  
  1819.       /* If *SPLIT is a (mult FOO (const_int pow2)), convert it to
  1820.          an ASHIFT.  This can occur if it was inside a PLUS and hence
  1821.          appeared to be a memory address.  This is a kludge.  */
  1822.       if (GET_CODE (*split) == MULT
  1823.           && GET_CODE (XEXP (*split, 1)) == CONST_INT
  1824.           && (i = exact_log2 (INTVAL (XEXP (*split, 1)))) >= 0)
  1825.         SUBST (*split, gen_rtx_combine (ASHIFT, GET_MODE (*split),
  1826.                         XEXP (*split, 0), GEN_INT (i)));
  1827.  
  1828. #ifdef INSN_SCHEDULING
  1829.       /* If *SPLIT is a paradoxical SUBREG, when we split it, it should
  1830.          be written as a ZERO_EXTEND.  */
  1831.       if (GET_CODE (*split) == SUBREG
  1832.           && GET_CODE (SUBREG_REG (*split)) == MEM)
  1833.         SUBST (*split, gen_rtx_combine (ZERO_EXTEND, GET_MODE (*split),
  1834.                         XEXP (*split, 0)));
  1835. #endif
  1836.  
  1837.       newi2pat = gen_rtx_combine (SET, VOIDmode, newdest, *split);
  1838.       SUBST (*split, newdest);
  1839.       i2_code_number = recog_for_combine (&newi2pat, i2, &new_i2_notes);
  1840.       if (i2_code_number >= 0)
  1841.         insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
  1842.     }
  1843.     }
  1844.  
  1845.   /* Check for a case where we loaded from memory in a narrow mode and
  1846.      then sign extended it, but we need both registers.  In that case,
  1847.      we have a PARALLEL with both loads from the same memory location.
  1848.      We can split this into a load from memory followed by a register-register
  1849.      copy.  This saves at least one insn, more if register allocation can
  1850.      eliminate the copy.
  1851.  
  1852.      We cannot do this if the destination of the second assignment is
  1853.      a register that we have already assumed is zero-extended.  Similarly
  1854.      for a SUBREG of such a register.  */
  1855.  
  1856.   else if (i1 && insn_code_number < 0 && asm_noperands (newpat) < 0
  1857.        && GET_CODE (newpat) == PARALLEL
  1858.        && XVECLEN (newpat, 0) == 2
  1859.        && GET_CODE (XVECEXP (newpat, 0, 0)) == SET
  1860.        && GET_CODE (SET_SRC (XVECEXP (newpat, 0, 0))) == SIGN_EXTEND
  1861.        && GET_CODE (XVECEXP (newpat, 0, 1)) == SET
  1862.        && rtx_equal_p (SET_SRC (XVECEXP (newpat, 0, 1)),
  1863.                XEXP (SET_SRC (XVECEXP (newpat, 0, 0)), 0))
  1864.        && ! use_crosses_set_p (SET_SRC (XVECEXP (newpat, 0, 1)),
  1865.                    INSN_CUID (i2))
  1866.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != ZERO_EXTRACT
  1867.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != STRICT_LOW_PART
  1868.        && ! (temp = SET_DEST (XVECEXP (newpat, 0, 1)),
  1869.          (GET_CODE (temp) == REG
  1870.           && reg_nonzero_bits[REGNO (temp)] != 0
  1871.           && GET_MODE_BITSIZE (GET_MODE (temp)) < BITS_PER_WORD
  1872.           && GET_MODE_BITSIZE (GET_MODE (temp)) < HOST_BITS_PER_INT
  1873.           && (reg_nonzero_bits[REGNO (temp)]
  1874.               != GET_MODE_MASK (word_mode))))
  1875.        && ! (GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) == SUBREG
  1876.          && (temp = SUBREG_REG (SET_DEST (XVECEXP (newpat, 0, 1))),
  1877.              (GET_CODE (temp) == REG
  1878.               && reg_nonzero_bits[REGNO (temp)] != 0
  1879.               && GET_MODE_BITSIZE (GET_MODE (temp)) < BITS_PER_WORD
  1880.               && GET_MODE_BITSIZE (GET_MODE (temp)) < HOST_BITS_PER_INT
  1881.               && (reg_nonzero_bits[REGNO (temp)]
  1882.               != GET_MODE_MASK (word_mode)))))
  1883.        && ! reg_overlap_mentioned_p (SET_DEST (XVECEXP (newpat, 0, 1)),
  1884.                      SET_SRC (XVECEXP (newpat, 0, 1)))
  1885.        && ! find_reg_note (i3, REG_UNUSED,
  1886.                    SET_DEST (XVECEXP (newpat, 0, 0))))
  1887.     {
  1888.       rtx ni2dest;
  1889.  
  1890.       newi2pat = XVECEXP (newpat, 0, 0);
  1891.       ni2dest = SET_DEST (XVECEXP (newpat, 0, 0));
  1892.       newpat = XVECEXP (newpat, 0, 1);
  1893.       SUBST (SET_SRC (newpat),
  1894.          gen_lowpart_for_combine (GET_MODE (SET_SRC (newpat)), ni2dest));
  1895.       i2_code_number = recog_for_combine (&newi2pat, i2, &new_i2_notes);
  1896.       if (i2_code_number >= 0)
  1897.     insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
  1898.  
  1899.       if (insn_code_number >= 0)
  1900.     {
  1901.       rtx insn;
  1902.       rtx link;
  1903.  
  1904.       /* If we will be able to accept this, we have made a change to the
  1905.          destination of I3.  This can invalidate a LOG_LINKS pointing
  1906.          to I3.  No other part of combine.c makes such a transformation.
  1907.  
  1908.          The new I3 will have a destination that was previously the
  1909.          destination of I1 or I2 and which was used in i2 or I3.  Call
  1910.          distribute_links to make a LOG_LINK from the next use of
  1911.          that destination.  */
  1912.  
  1913.       PATTERN (i3) = newpat;
  1914.       distribute_links (gen_rtx (INSN_LIST, VOIDmode, i3, NULL_RTX));
  1915.  
  1916.       /* I3 now uses what used to be its destination and which is
  1917.          now I2's destination.  That means we need a LOG_LINK from
  1918.          I3 to I2.  But we used to have one, so we still will.
  1919.  
  1920.          However, some later insn might be using I2's dest and have
  1921.          a LOG_LINK pointing at I3.  We must remove this link.
  1922.          The simplest way to remove the link is to point it at I1,
  1923.          which we know will be a NOTE.  */
  1924.  
  1925.       for (insn = NEXT_INSN (i3);
  1926.            insn && (this_basic_block == n_basic_blocks - 1
  1927.             || insn != basic_block_head[this_basic_block + 1]);
  1928.            insn = NEXT_INSN (insn))
  1929.         {
  1930.           if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  1931.           && reg_referenced_p (ni2dest, PATTERN (insn)))
  1932.         {
  1933.           for (link = LOG_LINKS (insn); link;
  1934.                link = XEXP (link, 1))
  1935.             if (XEXP (link, 0) == i3)
  1936.               XEXP (link, 0) = i1;
  1937.  
  1938.           break;
  1939.         }
  1940.         }
  1941.     }
  1942.     }
  1943.         
  1944.   /* Similarly, check for a case where we have a PARALLEL of two independent
  1945.      SETs but we started with three insns.  In this case, we can do the sets
  1946.      as two separate insns.  This case occurs when some SET allows two
  1947.      other insns to combine, but the destination of that SET is still live.  */
  1948.  
  1949.   else if (i1 && insn_code_number < 0 && asm_noperands (newpat) < 0
  1950.        && GET_CODE (newpat) == PARALLEL
  1951.        && XVECLEN (newpat, 0) == 2
  1952.        && GET_CODE (XVECEXP (newpat, 0, 0)) == SET
  1953.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) != ZERO_EXTRACT
  1954.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) != STRICT_LOW_PART
  1955.        && GET_CODE (XVECEXP (newpat, 0, 1)) == SET
  1956.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != ZERO_EXTRACT
  1957.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != STRICT_LOW_PART
  1958.        && ! use_crosses_set_p (SET_SRC (XVECEXP (newpat, 0, 1)),
  1959.                    INSN_CUID (i2))
  1960.        /* Don't pass sets with (USE (MEM ...)) dests to the following.  */
  1961.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != USE
  1962.        && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) != USE
  1963.        && ! reg_referenced_p (SET_DEST (XVECEXP (newpat, 0, 1)),
  1964.                   XVECEXP (newpat, 0, 0))
  1965.        && ! reg_referenced_p (SET_DEST (XVECEXP (newpat, 0, 0)),
  1966.                   XVECEXP (newpat, 0, 1)))
  1967.     {
  1968.       newi2pat = XVECEXP (newpat, 0, 1);
  1969.       newpat = XVECEXP (newpat, 0, 0);
  1970.  
  1971.       i2_code_number = recog_for_combine (&newi2pat, i2, &new_i2_notes);
  1972.       if (i2_code_number >= 0)
  1973.     insn_code_number = recog_for_combine (&newpat, i3, &new_i3_notes);
  1974.     }
  1975.  
  1976.   /* If it still isn't recognized, fail and change things back the way they
  1977.      were.  */
  1978.   if ((insn_code_number < 0
  1979.        /* Is the result a reasonable ASM_OPERANDS?  */
  1980.        && (! check_asm_operands (newpat) || added_sets_1 || added_sets_2)))
  1981.     {
  1982.       undo_all ();
  1983.       return 0;
  1984.     }
  1985.  
  1986.   /* If we had to change another insn, make sure it is valid also.  */
  1987.   if (undobuf.other_insn)
  1988.     {
  1989.       rtx other_pat = PATTERN (undobuf.other_insn);
  1990.       rtx new_other_notes;
  1991.       rtx note, next;
  1992.  
  1993.       CLEAR_HARD_REG_SET (newpat_used_regs);
  1994.  
  1995.       other_code_number = recog_for_combine (&other_pat, undobuf.other_insn,
  1996.                          &new_other_notes);
  1997.  
  1998.       if (other_code_number < 0 && ! check_asm_operands (other_pat))
  1999.     {
  2000.       undo_all ();
  2001.       return 0;
  2002.     }
  2003.  
  2004.       PATTERN (undobuf.other_insn) = other_pat;
  2005.  
  2006.       /* If any of the notes in OTHER_INSN were REG_UNUSED, ensure that they
  2007.      are still valid.  Then add any non-duplicate notes added by
  2008.      recog_for_combine.  */
  2009.       for (note = REG_NOTES (undobuf.other_insn); note; note = next)
  2010.     {
  2011.       next = XEXP (note, 1);
  2012.  
  2013.       if (REG_NOTE_KIND (note) == REG_UNUSED
  2014.           && ! reg_set_p (XEXP (note, 0), PATTERN (undobuf.other_insn)))
  2015.         {
  2016.           if (GET_CODE (XEXP (note, 0)) == REG)
  2017.         reg_n_deaths[REGNO (XEXP (note, 0))]--;
  2018.  
  2019.           remove_note (undobuf.other_insn, note);
  2020.         }
  2021.     }
  2022.  
  2023.       for (note = new_other_notes; note; note = XEXP (note, 1))
  2024.     if (GET_CODE (XEXP (note, 0)) == REG)
  2025.       reg_n_deaths[REGNO (XEXP (note, 0))]++;
  2026.  
  2027.       distribute_notes (new_other_notes, undobuf.other_insn,
  2028.             undobuf.other_insn, NULL_RTX, NULL_RTX, NULL_RTX);
  2029.     }
  2030.  
  2031.   /* We now know that we can do this combination.  Merge the insns and 
  2032.      update the status of registers and LOG_LINKS.  */
  2033.  
  2034.   {
  2035.     rtx i3notes, i2notes, i1notes = 0;
  2036.     rtx i3links, i2links, i1links = 0;
  2037.     rtx midnotes = 0;
  2038.     register int regno;
  2039.     /* Compute which registers we expect to eliminate.  */
  2040.     rtx elim_i2 = (newi2pat || i2dest_in_i2src || i2dest_in_i1src
  2041.            ? 0 : i2dest);
  2042.     rtx elim_i1 = i1 == 0 || i1dest_in_i1src ? 0 : i1dest;
  2043.  
  2044.     /* Get the old REG_NOTES and LOG_LINKS from all our insns and
  2045.        clear them.  */
  2046.     i3notes = REG_NOTES (i3), i3links = LOG_LINKS (i3);
  2047.     i2notes = REG_NOTES (i2), i2links = LOG_LINKS (i2);
  2048.     if (i1)
  2049.       i1notes = REG_NOTES (i1), i1links = LOG_LINKS (i1);
  2050.  
  2051.     /* Ensure that we do not have something that should not be shared but
  2052.        occurs multiple times in the new insns.  Check this by first
  2053.        resetting all the `used' flags and then copying anything is shared.  */
  2054.  
  2055.     reset_used_flags (i3notes);
  2056.     reset_used_flags (i2notes);
  2057.     reset_used_flags (i1notes);
  2058.     reset_used_flags (newpat);
  2059.     reset_used_flags (newi2pat);
  2060.     if (undobuf.other_insn)
  2061.       reset_used_flags (PATTERN (undobuf.other_insn));
  2062.  
  2063.     i3notes = copy_rtx_if_shared (i3notes);
  2064.     i2notes = copy_rtx_if_shared (i2notes);
  2065.     i1notes = copy_rtx_if_shared (i1notes);
  2066.     newpat = copy_rtx_if_shared (newpat);
  2067.     newi2pat = copy_rtx_if_shared (newi2pat);
  2068.     if (undobuf.other_insn)
  2069.       reset_used_flags (PATTERN (undobuf.other_insn));
  2070.  
  2071.     INSN_CODE (i3) = insn_code_number;
  2072.     PATTERN (i3) = newpat;
  2073.     if (undobuf.other_insn)
  2074.       INSN_CODE (undobuf.other_insn) = other_code_number;
  2075.  
  2076.     /* We had one special case above where I2 had more than one set and
  2077.        we replaced a destination of one of those sets with the destination
  2078.        of I3.  In that case, we have to update LOG_LINKS of insns later
  2079.        in this basic block.  Note that this (expensive) case is rare.
  2080.  
  2081.        Also, in this case, we must pretend that all REG_NOTEs for I2
  2082.        actually came from I3, so that REG_UNUSED notes from I2 will be
  2083.        properly handled.  */
  2084.  
  2085.     if (i3_subst_into_i2)
  2086.       {
  2087.     for (i = 0; i < XVECLEN (PATTERN (i2), 0); i++)
  2088.       if (GET_CODE (SET_DEST (XVECEXP (PATTERN (i2), 0, i))) == REG
  2089.           && SET_DEST (XVECEXP (PATTERN (i2), 0, i)) != i2dest
  2090.           && ! find_reg_note (i2, REG_UNUSED,
  2091.                   SET_DEST (XVECEXP (PATTERN (i2), 0, i))))
  2092.         for (temp = NEXT_INSN (i2);
  2093.          temp && (this_basic_block == n_basic_blocks - 1
  2094.               || basic_block_head[this_basic_block] != temp);
  2095.          temp = NEXT_INSN (temp))
  2096.           if (temp != i3 && GET_RTX_CLASS (GET_CODE (temp)) == 'i')
  2097.         for (link = LOG_LINKS (temp); link; link = XEXP (link, 1))
  2098.           if (XEXP (link, 0) == i2)
  2099.             XEXP (link, 0) = i3;
  2100.  
  2101.     if (i3notes)
  2102.       {
  2103.         rtx link = i3notes;
  2104.         while (XEXP (link, 1))
  2105.           link = XEXP (link, 1);
  2106.         XEXP (link, 1) = i2notes;
  2107.       }
  2108.     else
  2109.       i3notes = i2notes;
  2110.     i2notes = 0;
  2111.       }
  2112.  
  2113.     LOG_LINKS (i3) = 0;
  2114.     REG_NOTES (i3) = 0;
  2115.     LOG_LINKS (i2) = 0;
  2116.     REG_NOTES (i2) = 0;
  2117.  
  2118.     if (newi2pat)
  2119.       {
  2120.     INSN_CODE (i2) = i2_code_number;
  2121.     PATTERN (i2) = newi2pat;
  2122.       }
  2123.     else
  2124.       {
  2125.     PUT_CODE (i2, NOTE);
  2126.     NOTE_LINE_NUMBER (i2) = NOTE_INSN_DELETED;
  2127.     NOTE_SOURCE_FILE (i2) = 0;
  2128.       }
  2129.  
  2130.     if (i1)
  2131.       {
  2132.     LOG_LINKS (i1) = 0;
  2133.     REG_NOTES (i1) = 0;
  2134.     PUT_CODE (i1, NOTE);
  2135.     NOTE_LINE_NUMBER (i1) = NOTE_INSN_DELETED;
  2136.     NOTE_SOURCE_FILE (i1) = 0;
  2137.       }
  2138.  
  2139.     /* Get death notes for everything that is now used in either I3 or
  2140.        I2 and used to die in a previous insn.  */
  2141.  
  2142.     move_deaths (newpat, i1 ? INSN_CUID (i1) : INSN_CUID (i2), i3, &midnotes);
  2143.     if (newi2pat)
  2144.       move_deaths (newi2pat, INSN_CUID (i1), i2, &midnotes);
  2145.  
  2146.     /* Distribute all the LOG_LINKS and REG_NOTES from I1, I2, and I3.  */
  2147.     if (i3notes)
  2148.       distribute_notes (i3notes, i3, i3, newi2pat ? i2 : NULL_RTX,
  2149.             elim_i2, elim_i1);
  2150.     if (i2notes)
  2151.       distribute_notes (i2notes, i2, i3, newi2pat ? i2 : NULL_RTX,
  2152.             elim_i2, elim_i1);
  2153.     if (i1notes)
  2154.       distribute_notes (i1notes, i1, i3, newi2pat ? i2 : NULL_RTX,
  2155.             elim_i2, elim_i1);
  2156.     if (midnotes)
  2157.       distribute_notes (midnotes, NULL_RTX, i3, newi2pat ? i2 : NULL_RTX,
  2158.             elim_i2, elim_i1);
  2159.  
  2160.     /* Distribute any notes added to I2 or I3 by recog_for_combine.  We
  2161.        know these are REG_UNUSED and want them to go to the desired insn,
  2162.        so we always pass it as i3.  We have not counted the notes in 
  2163.        reg_n_deaths yet, so we need to do so now.  */
  2164.  
  2165.     if (newi2pat && new_i2_notes)
  2166.       {
  2167.     for (temp = new_i2_notes; temp; temp = XEXP (temp, 1))
  2168.       if (GET_CODE (XEXP (temp, 0)) == REG)
  2169.         reg_n_deaths[REGNO (XEXP (temp, 0))]++;
  2170.     
  2171.     distribute_notes (new_i2_notes, i2, i2, NULL_RTX, NULL_RTX, NULL_RTX);
  2172.       }
  2173.  
  2174.     if (new_i3_notes)
  2175.       {
  2176.     for (temp = new_i3_notes; temp; temp = XEXP (temp, 1))
  2177.       if (GET_CODE (XEXP (temp, 0)) == REG)
  2178.         reg_n_deaths[REGNO (XEXP (temp, 0))]++;
  2179.     
  2180.     distribute_notes (new_i3_notes, i3, i3, NULL_RTX, NULL_RTX, NULL_RTX);
  2181.       }
  2182.  
  2183.     /* If I3DEST was used in I3SRC, it really died in I3.  We may need to
  2184.        put a REG_DEAD note for it somewhere.  Similarly for I2 and I1.
  2185.        Show an additional death due to the REG_DEAD note we make here.  If
  2186.        we discard it in distribute_notes, we will decrement it again.  */
  2187.  
  2188.     if (i3dest_killed)
  2189.       {
  2190.     if (GET_CODE (i3dest_killed) == REG)
  2191.       reg_n_deaths[REGNO (i3dest_killed)]++;
  2192.  
  2193.     distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i3dest_killed,
  2194.                    NULL_RTX),
  2195.               NULL_RTX, i3, newi2pat ? i2 : NULL_RTX,
  2196.               NULL_RTX, NULL_RTX);
  2197.       }
  2198.  
  2199.     /* For I2 and I1, we have to be careful.  If NEWI2PAT exists and sets
  2200.        I2DEST or I1DEST, the death must be somewhere before I2, not I3.  If
  2201.        we passed I3 in that case, it might delete I2.  */
  2202.  
  2203.     if (i2dest_in_i2src)
  2204.       {
  2205.     if (GET_CODE (i2dest) == REG)
  2206.       reg_n_deaths[REGNO (i2dest)]++;
  2207.  
  2208.     if (newi2pat && reg_set_p (i2dest, newi2pat))
  2209.       distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i2dest, NULL_RTX),
  2210.                 NULL_RTX, i2, NULL_RTX, NULL_RTX, NULL_RTX);
  2211.     else
  2212.       distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i2dest, NULL_RTX),
  2213.                 NULL_RTX, i3, newi2pat ? i2 : NULL_RTX,
  2214.                 NULL_RTX, NULL_RTX);
  2215.       }
  2216.  
  2217.     if (i1dest_in_i1src)
  2218.       {
  2219.     if (GET_CODE (i1dest) == REG)
  2220.       reg_n_deaths[REGNO (i1dest)]++;
  2221.  
  2222.     if (newi2pat && reg_set_p (i1dest, newi2pat))
  2223.       distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i1dest, NULL_RTX),
  2224.                 NULL_RTX, i2, NULL_RTX, NULL_RTX, NULL_RTX);
  2225.     else
  2226.       distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i1dest, NULL_RTX),
  2227.                 NULL_RTX, i3, newi2pat ? i2 : NULL_RTX,
  2228.                 NULL_RTX, NULL_RTX);
  2229.       }
  2230.  
  2231.     distribute_links (i3links);
  2232.     distribute_links (i2links);
  2233.     distribute_links (i1links);
  2234.  
  2235.     if (GET_CODE (i2dest) == REG)
  2236.       {
  2237.     rtx link;
  2238.     rtx i2_insn = 0, i2_val = 0, set;
  2239.  
  2240.     /* The insn that used to set this register doesn't exist, and
  2241.        this life of the register may not exist either.  See if one of
  2242.        I3's links points to an insn that sets I2DEST.  If it does, 
  2243.        that is now the last known value for I2DEST. If we don't update
  2244.        this and I2 set the register to a value that depended on its old
  2245.        contents, we will get confused.  If this insn is used, thing
  2246.        will be set correctly in combine_instructions.  */
  2247.  
  2248.     for (link = LOG_LINKS (i3); link; link = XEXP (link, 1))
  2249.       if ((set = single_set (XEXP (link, 0))) != 0
  2250.           && rtx_equal_p (i2dest, SET_DEST (set)))
  2251.         i2_insn = XEXP (link, 0), i2_val = SET_SRC (set);
  2252.  
  2253.     record_value_for_reg (i2dest, i2_insn, i2_val);
  2254.  
  2255.     /* If the reg formerly set in I2 died only once and that was in I3,
  2256.        zero its use count so it won't make `reload' do any work.  */
  2257.     if (! added_sets_2 && newi2pat == 0 && ! i2dest_in_i2src)
  2258.       {
  2259.         regno = REGNO (i2dest);
  2260.         reg_n_sets[regno]--;
  2261.         if (reg_n_sets[regno] == 0
  2262.         && ! (basic_block_live_at_start[0][regno / REGSET_ELT_BITS]
  2263.               & ((REGSET_ELT_TYPE) 1 << (regno % REGSET_ELT_BITS))))
  2264.           reg_n_refs[regno] = 0;
  2265.       }
  2266.       }
  2267.  
  2268.     if (i1 && GET_CODE (i1dest) == REG)
  2269.       {
  2270.     rtx link;
  2271.     rtx i1_insn = 0, i1_val = 0, set;
  2272.  
  2273.     for (link = LOG_LINKS (i3); link; link = XEXP (link, 1))
  2274.       if ((set = single_set (XEXP (link, 0))) != 0
  2275.           && rtx_equal_p (i1dest, SET_DEST (set)))
  2276.         i1_insn = XEXP (link, 0), i1_val = SET_SRC (set);
  2277.  
  2278.     record_value_for_reg (i1dest, i1_insn, i1_val);
  2279.  
  2280.     regno = REGNO (i1dest);
  2281.     if (! added_sets_1 && ! i1dest_in_i1src)
  2282.       {
  2283.         reg_n_sets[regno]--;
  2284.         if (reg_n_sets[regno] == 0
  2285.         && ! (basic_block_live_at_start[0][regno / REGSET_ELT_BITS]
  2286.               & ((REGSET_ELT_TYPE) 1 << (regno % REGSET_ELT_BITS))))
  2287.           reg_n_refs[regno] = 0;
  2288.       }
  2289.       }
  2290.  
  2291.     /* Update reg_nonzero_bits et al for any changes that may have been made
  2292.        to this insn.  */
  2293.  
  2294.     note_stores (newpat, set_nonzero_bits_and_sign_copies);
  2295.     if (newi2pat)
  2296.       note_stores (newi2pat, set_nonzero_bits_and_sign_copies);
  2297.  
  2298.     /* If I3 is now an unconditional jump, ensure that it has a 
  2299.        BARRIER following it since it may have initially been a
  2300.        conditional jump.  It may also be the last nonnote insn.  */
  2301.  
  2302.     if ((GET_CODE (newpat) == RETURN || simplejump_p (i3))
  2303.     && ((temp = next_nonnote_insn (i3)) == NULL_RTX
  2304.         || GET_CODE (temp) != BARRIER))
  2305.       emit_barrier_after (i3);
  2306.   }
  2307.  
  2308.   combine_successes++;
  2309.  
  2310.   if (added_links_insn
  2311.       && (newi2pat == 0 || INSN_CUID (added_links_insn) < INSN_CUID (i2))
  2312.       && INSN_CUID (added_links_insn) < INSN_CUID (i3))
  2313.     return added_links_insn;
  2314.   else
  2315.     return newi2pat ? i2 : i3;
  2316. }
  2317.  
  2318. /* Undo all the modifications recorded in undobuf.  */
  2319.  
  2320. static void
  2321. undo_all ()
  2322. {
  2323.   register int i;
  2324.   if (undobuf.num_undo > MAX_UNDO)
  2325.     undobuf.num_undo = MAX_UNDO;
  2326.   for (i = undobuf.num_undo - 1; i >= 0; i--)
  2327.     {
  2328.       if (undobuf.undo[i].is_int)
  2329.     *undobuf.undo[i].where.i = undobuf.undo[i].old_contents.i;
  2330.       else
  2331.     *undobuf.undo[i].where.r = undobuf.undo[i].old_contents.r;
  2332.       
  2333.     }
  2334.  
  2335.   obfree (undobuf.storage);
  2336.   undobuf.num_undo = 0;
  2337. }
  2338.  
  2339. /* Find the innermost point within the rtx at LOC, possibly LOC itself,
  2340.    where we have an arithmetic expression and return that point.  LOC will
  2341.    be inside INSN.
  2342.  
  2343.    try_combine will call this function to see if an insn can be split into
  2344.    two insns.  */
  2345.  
  2346. static rtx *
  2347. find_split_point (loc, insn)
  2348.      rtx *loc;
  2349.      rtx insn;
  2350. {
  2351.   rtx x = *loc;
  2352.   enum rtx_code code = GET_CODE (x);
  2353.   rtx *split;
  2354.   int len = 0, pos, unsignedp;
  2355.   rtx inner;
  2356.  
  2357.   /* First special-case some codes.  */
  2358.   switch (code)
  2359.     {
  2360.     case SUBREG:
  2361. #ifdef INSN_SCHEDULING
  2362.       /* If we are making a paradoxical SUBREG invalid, it becomes a split
  2363.      point.  */
  2364.       if (GET_CODE (SUBREG_REG (x)) == MEM)
  2365.     return loc;
  2366. #endif
  2367.       return find_split_point (&SUBREG_REG (x), insn);
  2368.  
  2369.     case MEM:
  2370. #ifdef HAVE_lo_sum
  2371.       /* If we have (mem (const ..)) or (mem (symbol_ref ...)), split it
  2372.      using LO_SUM and HIGH.  */
  2373.       if (GET_CODE (XEXP (x, 0)) == CONST
  2374.       || GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
  2375.     {
  2376.       SUBST (XEXP (x, 0),
  2377.          gen_rtx_combine (LO_SUM, Pmode,
  2378.                   gen_rtx_combine (HIGH, Pmode, XEXP (x, 0)),
  2379.                   XEXP (x, 0)));
  2380.       return &XEXP (XEXP (x, 0), 0);
  2381.     }
  2382. #endif
  2383.  
  2384.       /* If we have a PLUS whose second operand is a constant and the
  2385.      address is not valid, perhaps will can split it up using
  2386.      the machine-specific way to split large constants.  We use
  2387.      the first psuedo-reg (one of the virtual regs) as a placeholder;
  2388.      it will not remain in the result.  */
  2389.       if (GET_CODE (XEXP (x, 0)) == PLUS
  2390.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  2391.       && ! memory_address_p (GET_MODE (x), XEXP (x, 0)))
  2392.     {
  2393.       rtx reg = regno_reg_rtx[FIRST_PSEUDO_REGISTER];
  2394.       rtx seq = split_insns (gen_rtx (SET, VOIDmode, reg, XEXP (x, 0)),
  2395.                  subst_insn);
  2396.  
  2397.       /* This should have produced two insns, each of which sets our
  2398.          placeholder.  If the source of the second is a valid address,
  2399.          we can make put both sources together and make a split point
  2400.          in the middle.  */
  2401.  
  2402.       if (seq && XVECLEN (seq, 0) == 2
  2403.           && GET_CODE (XVECEXP (seq, 0, 0)) == INSN
  2404.           && GET_CODE (PATTERN (XVECEXP (seq, 0, 0))) == SET
  2405.           && SET_DEST (PATTERN (XVECEXP (seq, 0, 0))) == reg
  2406.           && ! reg_mentioned_p (reg,
  2407.                     SET_SRC (PATTERN (XVECEXP (seq, 0, 0))))
  2408.           && GET_CODE (XVECEXP (seq, 0, 1)) == INSN
  2409.           && GET_CODE (PATTERN (XVECEXP (seq, 0, 1))) == SET
  2410.           && SET_DEST (PATTERN (XVECEXP (seq, 0, 1))) == reg
  2411.           && memory_address_p (GET_MODE (x),
  2412.                    SET_SRC (PATTERN (XVECEXP (seq, 0, 1)))))
  2413.         {
  2414.           rtx src1 = SET_SRC (PATTERN (XVECEXP (seq, 0, 0)));
  2415.           rtx src2 = SET_SRC (PATTERN (XVECEXP (seq, 0, 1)));
  2416.  
  2417.           /* Replace the placeholder in SRC2 with SRC1.  If we can
  2418.          find where in SRC2 it was placed, that can become our
  2419.          split point and we can replace this address with SRC2.
  2420.          Just try two obvious places.  */
  2421.  
  2422.           src2 = replace_rtx (src2, reg, src1);
  2423.           split = 0;
  2424.           if (XEXP (src2, 0) == src1)
  2425.         split = &XEXP (src2, 0);
  2426.           else if (GET_RTX_FORMAT (GET_CODE (XEXP (src2, 0)))[0] == 'e'
  2427.                && XEXP (XEXP (src2, 0), 0) == src1)
  2428.         split = &XEXP (XEXP (src2, 0), 0);
  2429.  
  2430.           if (split)
  2431.         {
  2432.           SUBST (XEXP (x, 0), src2);
  2433.           return split;
  2434.         }
  2435.         }
  2436.       
  2437.       /* If that didn't work, perhaps the first operand is complex and
  2438.          needs to be computed separately, so make a split point there.
  2439.          This will occur on machines that just support REG + CONST
  2440.          and have a constant moved through some previous computation.  */
  2441.  
  2442.       else if (GET_RTX_CLASS (GET_CODE (XEXP (XEXP (x, 0), 0))) != 'o'
  2443.            && ! (GET_CODE (XEXP (XEXP (x, 0), 0)) == SUBREG
  2444.              && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (XEXP (x, 0), 0))))
  2445.                  == 'o')))
  2446.         return &XEXP (XEXP (x, 0), 0);
  2447.     }
  2448.       break;
  2449.  
  2450.     case SET:
  2451. #ifdef HAVE_cc0
  2452.       /* If SET_DEST is CC0 and SET_SRC is not an operand, a COMPARE, or a
  2453.      ZERO_EXTRACT, the most likely reason why this doesn't match is that
  2454.      we need to put the operand into a register.  So split at that
  2455.      point.  */
  2456.  
  2457.       if (SET_DEST (x) == cc0_rtx
  2458.       && GET_CODE (SET_SRC (x)) != COMPARE
  2459.       && GET_CODE (SET_SRC (x)) != ZERO_EXTRACT
  2460.       && GET_RTX_CLASS (GET_CODE (SET_SRC (x))) != 'o'
  2461.       && ! (GET_CODE (SET_SRC (x)) == SUBREG
  2462.         && GET_RTX_CLASS (GET_CODE (SUBREG_REG (SET_SRC (x)))) == 'o'))
  2463.     return &SET_SRC (x);
  2464. #endif
  2465.  
  2466.       /* See if we can split SET_SRC as it stands.  */
  2467.       split = find_split_point (&SET_SRC (x), insn);
  2468.       if (split && split != &SET_SRC (x))
  2469.     return split;
  2470.  
  2471.       /* See if this is a bitfield assignment with everything constant.  If
  2472.      so, this is an IOR of an AND, so split it into that.  */
  2473.       if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
  2474.       && (GET_MODE_BITSIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
  2475.           <= HOST_BITS_PER_WIDE_INT)
  2476.       && GET_CODE (XEXP (SET_DEST (x), 1)) == CONST_INT
  2477.       && GET_CODE (XEXP (SET_DEST (x), 2)) == CONST_INT
  2478.       && GET_CODE (SET_SRC (x)) == CONST_INT
  2479.       && ((INTVAL (XEXP (SET_DEST (x), 1))
  2480.           + INTVAL (XEXP (SET_DEST (x), 2)))
  2481.           <= GET_MODE_BITSIZE (GET_MODE (XEXP (SET_DEST (x), 0))))
  2482.       && ! side_effects_p (XEXP (SET_DEST (x), 0)))
  2483.     {
  2484.       int pos = INTVAL (XEXP (SET_DEST (x), 2));
  2485.       int len = INTVAL (XEXP (SET_DEST (x), 1));
  2486.       int src = INTVAL (SET_SRC (x));
  2487.       rtx dest = XEXP (SET_DEST (x), 0);
  2488.       enum machine_mode mode = GET_MODE (dest);
  2489.       unsigned HOST_WIDE_INT mask = ((HOST_WIDE_INT) 1 << len) - 1;
  2490.  
  2491. #if BITS_BIG_ENDIAN
  2492.       pos = GET_MODE_BITSIZE (mode) - len - pos;
  2493. #endif
  2494.  
  2495.       if (src == mask)
  2496.         SUBST (SET_SRC (x),
  2497.            gen_binary (IOR, mode, dest, GEN_INT (src << pos)));
  2498.       else
  2499.         SUBST (SET_SRC (x),
  2500.            gen_binary (IOR, mode,
  2501.                    gen_binary (AND, mode, dest, 
  2502.                        GEN_INT (~ (mask << pos)
  2503.                             & GET_MODE_MASK (mode))),
  2504.                    GEN_INT (src << pos)));
  2505.  
  2506.       SUBST (SET_DEST (x), dest);
  2507.  
  2508.       split = find_split_point (&SET_SRC (x), insn);
  2509.       if (split && split != &SET_SRC (x))
  2510.         return split;
  2511.     }
  2512.  
  2513.       /* Otherwise, see if this is an operation that we can split into two.
  2514.      If so, try to split that.  */
  2515.       code = GET_CODE (SET_SRC (x));
  2516.  
  2517.       switch (code)
  2518.     {
  2519.     case AND:
  2520.       /* If we are AND'ing with a large constant that is only a single
  2521.          bit and the result is only being used in a context where we
  2522.          need to know if it is zero or non-zero, replace it with a bit
  2523.          extraction.  This will avoid the large constant, which might
  2524.          have taken more than one insn to make.  If the constant were
  2525.          not a valid argument to the AND but took only one insn to make,
  2526.          this is no worse, but if it took more than one insn, it will
  2527.          be better.  */
  2528.  
  2529.       if (GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
  2530.           && GET_CODE (XEXP (SET_SRC (x), 0)) == REG
  2531.           && (pos = exact_log2 (INTVAL (XEXP (SET_SRC (x), 1)))) >= 7
  2532.           && GET_CODE (SET_DEST (x)) == REG
  2533.           && (split = find_single_use (SET_DEST (x), insn, NULL_PTR)) != 0
  2534.           && (GET_CODE (*split) == EQ || GET_CODE (*split) == NE)
  2535.           && XEXP (*split, 0) == SET_DEST (x)
  2536.           && XEXP (*split, 1) == const0_rtx)
  2537.         {
  2538.           SUBST (SET_SRC (x),
  2539.              make_extraction (GET_MODE (SET_DEST (x)),
  2540.                       XEXP (SET_SRC (x), 0),
  2541.                       pos, NULL_RTX, 1, 1, 0, 0));
  2542.           return find_split_point (loc, insn);
  2543.         }
  2544.       break;
  2545.  
  2546.     case SIGN_EXTEND:
  2547.       inner = XEXP (SET_SRC (x), 0);
  2548.       pos = 0;
  2549.       len = GET_MODE_BITSIZE (GET_MODE (inner));
  2550.       unsignedp = 0;
  2551.       break;
  2552.  
  2553.     case SIGN_EXTRACT:
  2554.     case ZERO_EXTRACT:
  2555.       if (GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
  2556.           && GET_CODE (XEXP (SET_SRC (x), 2)) == CONST_INT)
  2557.         {
  2558.           inner = XEXP (SET_SRC (x), 0);
  2559.           len = INTVAL (XEXP (SET_SRC (x), 1));
  2560.           pos = INTVAL (XEXP (SET_SRC (x), 2));
  2561.  
  2562. #if BITS_BIG_ENDIAN
  2563.           pos = GET_MODE_BITSIZE (GET_MODE (inner)) - len - pos;
  2564. #endif
  2565.           unsignedp = (code == ZERO_EXTRACT);
  2566.         }
  2567.       break;
  2568.     }
  2569.  
  2570.       if (len && pos >= 0 && pos + len <= GET_MODE_BITSIZE (GET_MODE (inner)))
  2571.     {
  2572.       enum machine_mode mode = GET_MODE (SET_SRC (x));
  2573.  
  2574.       /* For unsigned, we have a choice of a shift followed by an
  2575.          AND or two shifts.  Use two shifts for field sizes where the
  2576.          constant might be too large.  We assume here that we can
  2577.          always at least get 8-bit constants in an AND insn, which is
  2578.          true for every current RISC.  */
  2579.  
  2580.       if (unsignedp && len <= 8)
  2581.         {
  2582.           SUBST (SET_SRC (x),
  2583.              gen_rtx_combine
  2584.              (AND, mode,
  2585.               gen_rtx_combine (LSHIFTRT, mode,
  2586.                        gen_lowpart_for_combine (mode, inner),
  2587.                        GEN_INT (pos)),
  2588.               GEN_INT (((HOST_WIDE_INT) 1 << len) - 1)));
  2589.  
  2590.           split = find_split_point (&SET_SRC (x), insn);
  2591.           if (split && split != &SET_SRC (x))
  2592.         return split;
  2593.         }
  2594.       else
  2595.         {
  2596.           SUBST (SET_SRC (x),
  2597.              gen_rtx_combine
  2598.              (unsignedp ? LSHIFTRT : ASHIFTRT, mode,
  2599.               gen_rtx_combine (ASHIFT, mode,
  2600.                        gen_lowpart_for_combine (mode, inner),
  2601.                        GEN_INT (GET_MODE_BITSIZE (mode)
  2602.                         - len - pos)),
  2603.               GEN_INT (GET_MODE_BITSIZE (mode) - len)));
  2604.  
  2605.           split = find_split_point (&SET_SRC (x), insn);
  2606.           if (split && split != &SET_SRC (x))
  2607.         return split;
  2608.         }
  2609.     }
  2610.  
  2611.       /* See if this is a simple operation with a constant as the second
  2612.      operand.  It might be that this constant is out of range and hence
  2613.      could be used as a split point.  */
  2614.       if ((GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '2'
  2615.        || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == 'c'
  2616.        || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '<')
  2617.       && CONSTANT_P (XEXP (SET_SRC (x), 1))
  2618.       && (GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (x), 0))) == 'o'
  2619.           || (GET_CODE (XEXP (SET_SRC (x), 0)) == SUBREG
  2620.           && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (SET_SRC (x), 0))))
  2621.               == 'o'))))
  2622.     return &XEXP (SET_SRC (x), 1);
  2623.  
  2624.       /* Finally, see if this is a simple operation with its first operand
  2625.      not in a register.  The operation might require this operand in a
  2626.      register, so return it as a split point.  We can always do this
  2627.      because if the first operand were another operation, we would have
  2628.      already found it as a split point.  */
  2629.       if ((GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '2'
  2630.        || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == 'c'
  2631.        || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '<'
  2632.        || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '1')
  2633.       && ! register_operand (XEXP (SET_SRC (x), 0), VOIDmode))
  2634.     return &XEXP (SET_SRC (x), 0);
  2635.  
  2636.       return 0;
  2637.  
  2638.     case AND:
  2639.     case IOR:
  2640.       /* We write NOR as (and (not A) (not B)), but if we don't have a NOR,
  2641.      it is better to write this as (not (ior A B)) so we can split it.
  2642.      Similarly for IOR.  */
  2643.       if (GET_CODE (XEXP (x, 0)) == NOT && GET_CODE (XEXP (x, 1)) == NOT)
  2644.     {
  2645.       SUBST (*loc,
  2646.          gen_rtx_combine (NOT, GET_MODE (x),
  2647.                   gen_rtx_combine (code == IOR ? AND : IOR,
  2648.                            GET_MODE (x),
  2649.                            XEXP (XEXP (x, 0), 0),
  2650.                            XEXP (XEXP (x, 1), 0))));
  2651.       return find_split_point (loc, insn);
  2652.     }
  2653.  
  2654.       /* Many RISC machines have a large set of logical insns.  If the
  2655.      second operand is a NOT, put it first so we will try to split the
  2656.      other operand first.  */
  2657.       if (GET_CODE (XEXP (x, 1)) == NOT)
  2658.     {
  2659.       rtx tem = XEXP (x, 0);
  2660.       SUBST (XEXP (x, 0), XEXP (x, 1));
  2661.       SUBST (XEXP (x, 1), tem);
  2662.     }
  2663.       break;
  2664.     }
  2665.  
  2666.   /* Otherwise, select our actions depending on our rtx class.  */
  2667.   switch (GET_RTX_CLASS (code))
  2668.     {
  2669.     case 'b':            /* This is ZERO_EXTRACT and SIGN_EXTRACT.  */
  2670.     case '3':
  2671.       split = find_split_point (&XEXP (x, 2), insn);
  2672.       if (split)
  2673.     return split;
  2674.       /* ... fall through ... */
  2675.     case '2':
  2676.     case 'c':
  2677.     case '<':
  2678.       split = find_split_point (&XEXP (x, 1), insn);
  2679.       if (split)
  2680.     return split;
  2681.       /* ... fall through ... */
  2682.     case '1':
  2683.       /* Some machines have (and (shift ...) ...) insns.  If X is not
  2684.      an AND, but XEXP (X, 0) is, use it as our split point.  */
  2685.       if (GET_CODE (x) != AND && GET_CODE (XEXP (x, 0)) == AND)
  2686.     return &XEXP (x, 0);
  2687.  
  2688.       split = find_split_point (&XEXP (x, 0), insn);
  2689.       if (split)
  2690.     return split;
  2691.       return loc;
  2692.     }
  2693.  
  2694.   /* Otherwise, we don't have a split point.  */
  2695.   return 0;
  2696. }
  2697.  
  2698. /* Throughout X, replace FROM with TO, and return the result.
  2699.    The result is TO if X is FROM;
  2700.    otherwise the result is X, but its contents may have been modified.
  2701.    If they were modified, a record was made in undobuf so that
  2702.    undo_all will (among other things) return X to its original state.
  2703.  
  2704.    If the number of changes necessary is too much to record to undo,
  2705.    the excess changes are not made, so the result is invalid.
  2706.    The changes already made can still be undone.
  2707.    undobuf.num_undo is incremented for such changes, so by testing that
  2708.    the caller can tell whether the result is valid.
  2709.  
  2710.    `n_occurrences' is incremented each time FROM is replaced.
  2711.    
  2712.    IN_DEST is non-zero if we are processing the SET_DEST of a SET.
  2713.  
  2714.    UNIQUE_COPY is non-zero if each substitution must be unique.  We do this
  2715.    by copying if `n_occurrences' is non-zero.  */
  2716.  
  2717. static rtx
  2718. subst (x, from, to, in_dest, unique_copy)
  2719.      register rtx x, from, to;
  2720.      int in_dest;
  2721.      int unique_copy;
  2722. {
  2723.   register enum rtx_code code = GET_CODE (x);
  2724.   enum machine_mode op0_mode = VOIDmode;
  2725.   register char *fmt;
  2726.   register int len, i;
  2727.   rtx new;
  2728.  
  2729. /* Two expressions are equal if they are identical copies of a shared
  2730.    RTX or if they are both registers with the same register number
  2731.    and mode.  */
  2732.  
  2733. #define COMBINE_RTX_EQUAL_P(X,Y)            \
  2734.   ((X) == (Y)                        \
  2735.    || (GET_CODE (X) == REG && GET_CODE (Y) == REG    \
  2736.        && REGNO (X) == REGNO (Y) && GET_MODE (X) == GET_MODE (Y)))
  2737.  
  2738.   if (! in_dest && COMBINE_RTX_EQUAL_P (x, from))
  2739.     {
  2740.       n_occurrences++;
  2741.       return (unique_copy && n_occurrences > 1 ? copy_rtx (to) : to);
  2742.     }
  2743.  
  2744.   /* If X and FROM are the same register but different modes, they will
  2745.      not have been seen as equal above.  However, flow.c will make a 
  2746.      LOG_LINKS entry for that case.  If we do nothing, we will try to
  2747.      rerecognize our original insn and, when it succeeds, we will
  2748.      delete the feeding insn, which is incorrect.
  2749.  
  2750.      So force this insn not to match in this (rare) case.  */
  2751.   if (! in_dest && code == REG && GET_CODE (from) == REG
  2752.       && REGNO (x) == REGNO (from))
  2753.     return gen_rtx (CLOBBER, GET_MODE (x), const0_rtx);
  2754.  
  2755.   /* If this is an object, we are done unless it is a MEM or LO_SUM, both
  2756.      of which may contain things that can be combined.  */
  2757.   if (code != MEM && code != LO_SUM && GET_RTX_CLASS (code) == 'o')
  2758.     return x;
  2759.  
  2760.   /* It is possible to have a subexpression appear twice in the insn.
  2761.      Suppose that FROM is a register that appears within TO.
  2762.      Then, after that subexpression has been scanned once by `subst',
  2763.      the second time it is scanned, TO may be found.  If we were
  2764.      to scan TO here, we would find FROM within it and create a
  2765.      self-referent rtl structure which is completely wrong.  */
  2766.   if (COMBINE_RTX_EQUAL_P (x, to))
  2767.     return to;
  2768.  
  2769.   len = GET_RTX_LENGTH (code);
  2770.   fmt = GET_RTX_FORMAT (code);
  2771.  
  2772.   /* We don't need to process a SET_DEST that is a register, CC0, or PC, so
  2773.      set up to skip this common case.  All other cases where we want to
  2774.      suppress replacing something inside a SET_SRC are handled via the
  2775.      IN_DEST operand.  */
  2776.   if (code == SET
  2777.       && (GET_CODE (SET_DEST (x)) == REG
  2778.         || GET_CODE (SET_DEST (x)) == CC0
  2779.         || GET_CODE (SET_DEST (x)) == PC))
  2780.     fmt = "ie";
  2781.  
  2782.   /* Get the mode of operand 0 in case X is now a SIGN_EXTEND of a constant. */
  2783.   if (fmt[0] == 'e')
  2784.     op0_mode = GET_MODE (XEXP (x, 0));
  2785.  
  2786.   for (i = 0; i < len; i++)
  2787.     {
  2788.       if (fmt[i] == 'E')
  2789.     {
  2790.       register int j;
  2791.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2792.         {
  2793.           if (COMBINE_RTX_EQUAL_P (XVECEXP (x, i, j), from))
  2794.         {
  2795.           new = (unique_copy && n_occurrences ? copy_rtx (to) : to);
  2796.           n_occurrences++;
  2797.         }
  2798.           else
  2799.         {
  2800.           new = subst (XVECEXP (x, i, j), from, to, 0, unique_copy);
  2801.  
  2802.           /* If this substitution failed, this whole thing fails.  */
  2803.           if (GET_CODE (new) == CLOBBER && XEXP (new, 0) == const0_rtx)
  2804.             return new;
  2805.         }
  2806.  
  2807.           SUBST (XVECEXP (x, i, j), new);
  2808.         }
  2809.     }
  2810.       else if (fmt[i] == 'e')
  2811.     {
  2812.       if (COMBINE_RTX_EQUAL_P (XEXP (x, i), from))
  2813.         {
  2814.           /* In general, don't install a subreg involving two modes not
  2815.          tieable.  It can worsen register allocation, and can even
  2816.          make invalid reload insns, since the reg inside may need to
  2817.          be copied from in the outside mode, and that may be invalid
  2818.          if it is an fp reg copied in integer mode.
  2819.  
  2820.          We allow two exceptions to this: It is valid if it is inside
  2821.          another SUBREG and the mode of that SUBREG and the mode of
  2822.          the inside of TO is tieable and it is valid if X is a SET
  2823.          that copies FROM to CC0.  */
  2824.           if (GET_CODE (to) == SUBREG
  2825.           && ! MODES_TIEABLE_P (GET_MODE (to),
  2826.                     GET_MODE (SUBREG_REG (to)))
  2827.           && ! (code == SUBREG
  2828.             && MODES_TIEABLE_P (GET_MODE (x),
  2829.                         GET_MODE (SUBREG_REG (to))))
  2830. #ifdef HAVE_cc0
  2831.           && ! (code == SET && i == 1 && XEXP (x, 0) == cc0_rtx)
  2832. #endif
  2833.           )
  2834.         return gen_rtx (CLOBBER, VOIDmode, const0_rtx);
  2835.  
  2836.           new = (unique_copy && n_occurrences ? copy_rtx (to) : to);
  2837.           n_occurrences++;
  2838.         }
  2839.       else
  2840.         /* If we are in a SET_DEST, suppress most cases unless we
  2841.            have gone inside a MEM, in which case we want to
  2842.            simplify the address.  We assume here that things that
  2843.            are actually part of the destination have their inner
  2844.            parts in the first expression.  This is true for SUBREG, 
  2845.            STRICT_LOW_PART, and ZERO_EXTRACT, which are the only
  2846.            things aside from REG and MEM that should appear in a
  2847.            SET_DEST.  */
  2848.         new = subst (XEXP (x, i), from, to,
  2849.              (((in_dest
  2850.                 && (code == SUBREG || code == STRICT_LOW_PART
  2851.                 || code == ZERO_EXTRACT))
  2852.                || code == SET)
  2853.               && i == 0), unique_copy);
  2854.  
  2855.       /* If we found that we will have to reject this combination,
  2856.          indicate that by returning the CLOBBER ourselves, rather than
  2857.          an expression containing it.  This will speed things up as
  2858.          well as prevent accidents where two CLOBBERs are considered
  2859.          to be equal, thus producing an incorrect simplification.  */
  2860.  
  2861.       if (GET_CODE (new) == CLOBBER && XEXP (new, 0) == const0_rtx)
  2862.         return new;
  2863.  
  2864.       SUBST (XEXP (x, i), new);
  2865.     }
  2866.     }
  2867.  
  2868.   /* Try to simplify X.  If the simplification changed the code, it is likely
  2869.      that further simplification will help, so loop, but limit the number
  2870.      of repetitions that will be performed.  */
  2871.  
  2872.   for (i = 0; i < 4; i++)
  2873.     {
  2874.       /* If X is sufficiently simple, don't bother trying to do anything
  2875.      with it.  */
  2876.       if (code != CONST_INT && code != REG && code != CLOBBER)
  2877.     x = simplify_rtx (x, op0_mode, i == 3, in_dest);
  2878.  
  2879.       if (GET_CODE (x) == code)
  2880.     break;
  2881.  
  2882.       code = GET_CODE (x);
  2883.  
  2884.       /* We no longer know the original mode of operand 0 since we
  2885.      have changed the form of X)  */
  2886.       op0_mode = VOIDmode;
  2887.     }
  2888.  
  2889.   return x;
  2890. }
  2891.  
  2892. /* Simplify X, a piece of RTL.  We just operate on the expression at the
  2893.    outer level; call `subst' to simplify recursively.  Return the new
  2894.    expression.
  2895.  
  2896.    OP0_MODE is the original mode of XEXP (x, 0); LAST is nonzero if this
  2897.    will be the iteration even if an expression with a code different from
  2898.    X is returned; IN_DEST is nonzero if we are inside a SET_DEST.  */
  2899.  
  2900. static rtx
  2901. simplify_rtx (x, op0_mode, last, in_dest)
  2902.      rtx x;
  2903.      enum machine_mode op0_mode;
  2904.      int last;
  2905.      int in_dest;
  2906. {
  2907.   enum rtx_code code = GET_CODE (x);
  2908.   enum machine_mode mode = GET_MODE (x);
  2909.   rtx temp;
  2910.   int i;
  2911.  
  2912.   /* If this is a commutative operation, put a constant last and a complex
  2913.      expression first.  We don't need to do this for comparisons here.  */
  2914.   if (GET_RTX_CLASS (code) == 'c'
  2915.       && ((CONSTANT_P (XEXP (x, 0)) && GET_CODE (XEXP (x, 1)) != CONST_INT)
  2916.       || (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == 'o'
  2917.           && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) != 'o')
  2918.       || (GET_CODE (XEXP (x, 0)) == SUBREG
  2919.           && GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 0)))) == 'o'
  2920.           && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) != 'o')))
  2921.     {
  2922.       temp = XEXP (x, 0);
  2923.       SUBST (XEXP (x, 0), XEXP (x, 1));
  2924.       SUBST (XEXP (x, 1), temp);
  2925.     }
  2926.  
  2927.   /* If this is a PLUS, MINUS, or MULT, and the first operand is the
  2928.      sign extension of a PLUS with a constant, reverse the order of the sign
  2929.      extension and the addition. Note that this not the same as the original
  2930.      code, but overflow is undefined for signed values.  Also note that the
  2931.      PLUS will have been partially moved "inside" the sign-extension, so that
  2932.      the first operand of X will really look like:
  2933.          (ashiftrt (plus (ashift A C4) C5) C4).
  2934.      We convert this to
  2935.          (plus (ashiftrt (ashift A C4) C2) C4)
  2936.      and replace the first operand of X with that expression.  Later parts
  2937.      of this function may simplify the expression further.
  2938.  
  2939.      For example, if we start with (mult (sign_extend (plus A C1)) C2),
  2940.      we swap the SIGN_EXTEND and PLUS.  Later code will apply the
  2941.      distributive law to produce (plus (mult (sign_extend X) C1) C3).
  2942.  
  2943.      We do this to simplify address expressions.  */
  2944.  
  2945.   if ((code == PLUS || code == MINUS || code == MULT)
  2946.       && GET_CODE (XEXP (x, 0)) == ASHIFTRT
  2947.       && GET_CODE (XEXP (XEXP (x, 0), 0)) == PLUS
  2948.       && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ASHIFT
  2949.       && GET_CODE (XEXP (XEXP (XEXP (XEXP (x, 0), 0), 0), 1)) == CONST_INT
  2950.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  2951.       && XEXP (XEXP (XEXP (XEXP (x, 0), 0), 0), 1) == XEXP (XEXP (x, 0), 1)
  2952.       && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
  2953.       && (temp = simplify_binary_operation (ASHIFTRT, mode,
  2954.                         XEXP (XEXP (XEXP (x, 0), 0), 1),
  2955.                         XEXP (XEXP (x, 0), 1))) != 0)
  2956.     {
  2957.       rtx new
  2958.     = simplify_shift_const (NULL_RTX, ASHIFT, mode,
  2959.                 XEXP (XEXP (XEXP (XEXP (x, 0), 0), 0), 0),
  2960.                 INTVAL (XEXP (XEXP (x, 0), 1)));
  2961.  
  2962.       new = simplify_shift_const (NULL_RTX, ASHIFTRT, mode, new,
  2963.                   INTVAL (XEXP (XEXP (x, 0), 1)));
  2964.  
  2965.       SUBST (XEXP (x, 0), gen_binary (PLUS, mode, new, temp));
  2966.     }
  2967.  
  2968.   /* If this is a simple operation applied to an IF_THEN_ELSE, try 
  2969.      applying it to the arms of the IF_THEN_ELSE.  This often simplifies
  2970.      things.  Check for cases where both arms are testing the same
  2971.      condition.
  2972.  
  2973.      Don't do anything if all operands are very simple.  */
  2974.  
  2975.   if (((GET_RTX_CLASS (code) == '2' || GET_RTX_CLASS (code) == 'c'
  2976.     || GET_RTX_CLASS (code) == '<')
  2977.        && ((GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) != 'o'
  2978.         && ! (GET_CODE (XEXP (x, 0)) == SUBREG
  2979.           && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 0))))
  2980.               == 'o')))
  2981.        || (GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) != 'o'
  2982.            && ! (GET_CODE (XEXP (x, 1)) == SUBREG
  2983.              && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 1))))
  2984.              == 'o')))))
  2985.       || (GET_RTX_CLASS (code) == '1'
  2986.       && ((GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) != 'o'
  2987.            && ! (GET_CODE (XEXP (x, 0)) == SUBREG
  2988.              && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 0))))
  2989.              == 'o'))))))
  2990.     {
  2991.       rtx cond, true, false;
  2992.  
  2993.       cond = if_then_else_cond (x, &true, &false);
  2994.       if (cond != 0)
  2995.     {
  2996.       rtx cop1 = const0_rtx;
  2997.       enum rtx_code cond_code = simplify_comparison (NE, &cond, &cop1);
  2998.  
  2999.       /* Simplify the alternative arms; this may collapse the true and 
  3000.          false arms to store-flag values.  */
  3001.       true = subst (true, pc_rtx, pc_rtx, 0, 0);
  3002.       false = subst (false, pc_rtx, pc_rtx, 0, 0);
  3003.  
  3004.       /* Restarting if we generate a store-flag expression will cause
  3005.          us to loop.  Just drop through in this case.  */
  3006.  
  3007.       /* If the result values are STORE_FLAG_VALUE and zero, we can
  3008.          just make the comparison operation.  */
  3009.       if (true == const_true_rtx && false == const0_rtx)
  3010.         x = gen_binary (cond_code, mode, cond, cop1);
  3011.       else if (true == const0_rtx && false == const_true_rtx)
  3012.         x = gen_binary (reverse_condition (cond_code), mode, cond, cop1);
  3013.  
  3014.       /* Likewise, we can make the negate of a comparison operation
  3015.          if the result values are - STORE_FLAG_VALUE and zero.  */
  3016.       else if (GET_CODE (true) == CONST_INT
  3017.            && INTVAL (true) == - STORE_FLAG_VALUE
  3018.            && false == const0_rtx)
  3019.         x = gen_unary (NEG, mode, mode,
  3020.                gen_binary (cond_code, mode, cond, cop1));
  3021.       else if (GET_CODE (false) == CONST_INT
  3022.            && INTVAL (false) == - STORE_FLAG_VALUE
  3023.            && true == const0_rtx)
  3024.         x = gen_unary (NEG, mode, mode,
  3025.                gen_binary (reverse_condition (cond_code), 
  3026.                        mode, cond, cop1));
  3027.       else
  3028.         return gen_rtx (IF_THEN_ELSE, mode,
  3029.                 gen_binary (cond_code, VOIDmode, cond, cop1),
  3030.                 true, false);
  3031.  
  3032.       code = GET_CODE (x);
  3033.       op0_mode = VOIDmode;
  3034.     }
  3035.     }
  3036.  
  3037.   /* Try to fold this expression in case we have constants that weren't
  3038.      present before.  */
  3039.   temp = 0;
  3040.   switch (GET_RTX_CLASS (code))
  3041.     {
  3042.     case '1':
  3043.       temp = simplify_unary_operation (code, mode, XEXP (x, 0), op0_mode);
  3044.       break;
  3045.     case '<':
  3046.       temp = simplify_relational_operation (code, op0_mode,
  3047.                         XEXP (x, 0), XEXP (x, 1));
  3048. #ifdef FLOAT_STORE_FLAG_VALUE
  3049.       if (temp != 0 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
  3050.     temp = ((temp == const0_rtx) ? CONST0_RTX (GET_MODE (x))
  3051.         : immed_real_const_1 (FLOAT_STORE_FLAG_VALUE, GET_MODE (x)));
  3052. #endif
  3053.       break;
  3054.     case 'c':
  3055.     case '2':
  3056.       temp = simplify_binary_operation (code, mode, XEXP (x, 0), XEXP (x, 1));
  3057.       break;
  3058.     case 'b':
  3059.     case '3':
  3060.       temp = simplify_ternary_operation (code, mode, op0_mode, XEXP (x, 0),
  3061.                      XEXP (x, 1), XEXP (x, 2));
  3062.       break;
  3063.     }
  3064.  
  3065.   if (temp)
  3066.     x = temp, code = GET_CODE (temp);
  3067.  
  3068.   /* First see if we can apply the inverse distributive law.  */
  3069.   if (code == PLUS || code == MINUS
  3070.       || code == AND || code == IOR || code == XOR)
  3071.     {
  3072.       x = apply_distributive_law (x);
  3073.       code = GET_CODE (x);
  3074.     }
  3075.  
  3076.   /* If CODE is an associative operation not otherwise handled, see if we
  3077.      can associate some operands.  This can win if they are constants or
  3078.      if they are logically related (i.e. (a & b) & a.  */
  3079.   if ((code == PLUS || code == MINUS
  3080.        || code == MULT || code == AND || code == IOR || code == XOR
  3081.        || code == DIV || code == UDIV
  3082.        || code == SMAX || code == SMIN || code == UMAX || code == UMIN)
  3083.       && INTEGRAL_MODE_P (mode))
  3084.     {
  3085.       if (GET_CODE (XEXP (x, 0)) == code)
  3086.     {
  3087.       rtx other = XEXP (XEXP (x, 0), 0);
  3088.       rtx inner_op0 = XEXP (XEXP (x, 0), 1);
  3089.       rtx inner_op1 = XEXP (x, 1);
  3090.       rtx inner;
  3091.       
  3092.       /* Make sure we pass the constant operand if any as the second
  3093.          one if this is a commutative operation.  */
  3094.       if (CONSTANT_P (inner_op0) && GET_RTX_CLASS (code) == 'c')
  3095.         {
  3096.           rtx tem = inner_op0;
  3097.           inner_op0 = inner_op1;
  3098.           inner_op1 = tem;
  3099.         }
  3100.       inner = simplify_binary_operation (code == MINUS ? PLUS
  3101.                          : code == DIV ? MULT
  3102.                          : code == UDIV ? MULT
  3103.                          : code,
  3104.                          mode, inner_op0, inner_op1);
  3105.  
  3106.       /* For commutative operations, try the other pair if that one
  3107.          didn't simplify.  */
  3108.       if (inner == 0 && GET_RTX_CLASS (code) == 'c')
  3109.         {
  3110.           other = XEXP (XEXP (x, 0), 1);
  3111.           inner = simplify_binary_operation (code, mode,
  3112.                          XEXP (XEXP (x, 0), 0),
  3113.                          XEXP (x, 1));
  3114.         }
  3115.  
  3116.       if (inner)
  3117.         return gen_binary (code, mode, other, inner);
  3118.     }
  3119.     }
  3120.  
  3121.   /* A little bit of algebraic simplification here.  */
  3122.   switch (code)
  3123.     {
  3124.     case MEM:
  3125.       /* Ensure that our address has any ASHIFTs converted to MULT in case
  3126.      address-recognizing predicates are called later.  */
  3127.       temp = make_compound_operation (XEXP (x, 0), MEM);
  3128.       SUBST (XEXP (x, 0), temp);
  3129.       break;
  3130.  
  3131.     case SUBREG:
  3132.       /* (subreg:A (mem:B X) N) becomes a modified MEM unless the SUBREG
  3133.      is paradoxical.  If we can't do that safely, then it becomes
  3134.      something nonsensical so that this combination won't take place.  */
  3135.  
  3136.       if (GET_CODE (SUBREG_REG (x)) == MEM
  3137.       && (GET_MODE_SIZE (mode)
  3138.           <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
  3139.     {
  3140.       rtx inner = SUBREG_REG (x);
  3141.       int endian_offset = 0;
  3142.       /* Don't change the mode of the MEM
  3143.          if that would change the meaning of the address.  */
  3144.       if (MEM_VOLATILE_P (SUBREG_REG (x))
  3145.           || mode_dependent_address_p (XEXP (inner, 0)))
  3146.         return gen_rtx (CLOBBER, mode, const0_rtx);
  3147.  
  3148. #if BYTES_BIG_ENDIAN
  3149.       if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
  3150.         endian_offset += UNITS_PER_WORD - GET_MODE_SIZE (mode);
  3151.       if (GET_MODE_SIZE (GET_MODE (inner)) < UNITS_PER_WORD)
  3152.         endian_offset -= UNITS_PER_WORD - GET_MODE_SIZE (GET_MODE (inner));
  3153. #endif
  3154.       /* Note if the plus_constant doesn't make a valid address
  3155.          then this combination won't be accepted.  */
  3156.       x = gen_rtx (MEM, mode,
  3157.                plus_constant (XEXP (inner, 0),
  3158.                       (SUBREG_WORD (x) * UNITS_PER_WORD
  3159.                        + endian_offset)));
  3160.       MEM_VOLATILE_P (x) = MEM_VOLATILE_P (inner);
  3161.       RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (inner);
  3162.       MEM_IN_STRUCT_P (x) = MEM_IN_STRUCT_P (inner);
  3163.       return x;
  3164.     }
  3165.  
  3166.       /* If we are in a SET_DEST, these other cases can't apply.  */
  3167.       if (in_dest)
  3168.     return x;
  3169.  
  3170.       /* Changing mode twice with SUBREG => just change it once,
  3171.      or not at all if changing back to starting mode.  */
  3172.       if (GET_CODE (SUBREG_REG (x)) == SUBREG)
  3173.     {
  3174.       if (mode == GET_MODE (SUBREG_REG (SUBREG_REG (x)))
  3175.           && SUBREG_WORD (x) == 0 && SUBREG_WORD (SUBREG_REG (x)) == 0)
  3176.         return SUBREG_REG (SUBREG_REG (x));
  3177.  
  3178.       SUBST_INT (SUBREG_WORD (x),
  3179.              SUBREG_WORD (x) + SUBREG_WORD (SUBREG_REG (x)));
  3180.       SUBST (SUBREG_REG (x), SUBREG_REG (SUBREG_REG (x)));
  3181.     }
  3182.  
  3183.       /* SUBREG of a hard register => just change the register number
  3184.      and/or mode.  If the hard register is not valid in that mode,
  3185.      suppress this combination.  If the hard register is the stack,
  3186.      frame, or argument pointer, leave this as a SUBREG.  */
  3187.  
  3188.       if (GET_CODE (SUBREG_REG (x)) == REG
  3189.       && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER
  3190.       && REGNO (SUBREG_REG (x)) != FRAME_POINTER_REGNUM
  3191. #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
  3192.       && REGNO (SUBREG_REG (x)) != HARD_FRAME_POINTER_REGNUM
  3193. #endif
  3194. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  3195.       && REGNO (SUBREG_REG (x)) != ARG_POINTER_REGNUM
  3196. #endif
  3197.       && REGNO (SUBREG_REG (x)) != STACK_POINTER_REGNUM)
  3198.     {
  3199.       if (HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (x)) + SUBREG_WORD (x),
  3200.                   mode))
  3201.         return gen_rtx (REG, mode,
  3202.                 REGNO (SUBREG_REG (x)) + SUBREG_WORD (x));
  3203.       else
  3204.         return gen_rtx (CLOBBER, mode, const0_rtx);
  3205.     }
  3206.  
  3207.       /* For a constant, try to pick up the part we want.  Handle a full
  3208.      word and low-order part.  Only do this if we are narrowing
  3209.      the constant; if it is being widened, we have no idea what
  3210.      the extra bits will have been set to.  */
  3211.  
  3212.       if (CONSTANT_P (SUBREG_REG (x)) && op0_mode != VOIDmode
  3213.       && GET_MODE_SIZE (mode) == UNITS_PER_WORD
  3214.       && GET_MODE_SIZE (op0_mode) < UNITS_PER_WORD
  3215.       && GET_MODE_CLASS (mode) == MODE_INT)
  3216.     {
  3217.       temp = operand_subword (SUBREG_REG (x), SUBREG_WORD (x),
  3218.                   0, op0_mode);
  3219.       if (temp)
  3220.         return temp;
  3221.     }
  3222.     
  3223.       /* If we want a subreg of a constant, at offset 0,
  3224.      take the low bits.  On a little-endian machine, that's
  3225.      always valid.  On a big-endian machine, it's valid
  3226.      only if the constant's mode fits in one word.  */
  3227.       if (CONSTANT_P (SUBREG_REG (x)) && subreg_lowpart_p (x)
  3228.       && GET_MODE_SIZE (mode) < GET_MODE_SIZE (op0_mode)
  3229. #if WORDS_BIG_ENDIAN
  3230.       && GET_MODE_BITSIZE (op0_mode) <= BITS_PER_WORD
  3231. #endif
  3232.       )
  3233.     return gen_lowpart_for_combine (mode, SUBREG_REG (x));
  3234.  
  3235.       /* A paradoxical SUBREG of a VOIDmode constant is the same constant,
  3236.      since we are saying that the high bits don't matter.  */
  3237.       if (CONSTANT_P (SUBREG_REG (x)) && GET_MODE (SUBREG_REG (x)) == VOIDmode
  3238.       && GET_MODE_SIZE (mode) > GET_MODE_SIZE (op0_mode))
  3239.     return SUBREG_REG (x);
  3240.  
  3241.       /* Note that we cannot do any narrowing for non-constants since
  3242.      we might have been counting on using the fact that some bits were
  3243.      zero.  We now do this in the SET.  */
  3244.  
  3245.       break;
  3246.  
  3247.     case NOT:
  3248.       /* (not (plus X -1)) can become (neg X).  */
  3249.       if (GET_CODE (XEXP (x, 0)) == PLUS
  3250.       && XEXP (XEXP (x, 0), 1) == constm1_rtx)
  3251.     return gen_rtx_combine (NEG, mode, XEXP (XEXP (x, 0), 0));
  3252.  
  3253.       /* Similarly, (not (neg X)) is (plus X -1).  */
  3254.       if (GET_CODE (XEXP (x, 0)) == NEG)
  3255.     return gen_rtx_combine (PLUS, mode, XEXP (XEXP (x, 0), 0),
  3256.                 constm1_rtx);
  3257.  
  3258.       /* (not (xor X C)) for C constant is (xor X D) with D = ~ C.  */
  3259.       if (GET_CODE (XEXP (x, 0)) == XOR
  3260.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  3261.       && (temp = simplify_unary_operation (NOT, mode,
  3262.                            XEXP (XEXP (x, 0), 1),
  3263.                            mode)) != 0)
  3264.     {
  3265.       SUBST (XEXP (XEXP (x, 0), 1), temp);
  3266.       return XEXP (x, 0);
  3267.     }
  3268.           
  3269.       /* (not (ashift 1 X)) is (rotate ~1 X).  We used to do this for operands
  3270.      other than 1, but that is not valid.  We could do a similar
  3271.      simplification for (not (lshiftrt C X)) where C is just the sign bit,
  3272.      but this doesn't seem common enough to bother with.  */
  3273.       if (GET_CODE (XEXP (x, 0)) == ASHIFT
  3274.       && XEXP (XEXP (x, 0), 0) == const1_rtx)
  3275.     return gen_rtx (ROTATE, mode, gen_unary (NOT, mode, mode, const1_rtx),
  3276.             XEXP (XEXP (x, 0), 1));
  3277.                         
  3278.       if (GET_CODE (XEXP (x, 0)) == SUBREG
  3279.       && subreg_lowpart_p (XEXP (x, 0))
  3280.       && (GET_MODE_SIZE (GET_MODE (XEXP (x, 0)))
  3281.           < GET_MODE_SIZE (GET_MODE (SUBREG_REG (XEXP (x, 0)))))
  3282.       && GET_CODE (SUBREG_REG (XEXP (x, 0))) == ASHIFT
  3283.       && XEXP (SUBREG_REG (XEXP (x, 0)), 0) == const1_rtx)
  3284.     {
  3285.       enum machine_mode inner_mode = GET_MODE (SUBREG_REG (XEXP (x, 0)));
  3286.  
  3287.       x = gen_rtx (ROTATE, inner_mode,
  3288.                gen_unary (NOT, inner_mode, inner_mode, const1_rtx),
  3289.                XEXP (SUBREG_REG (XEXP (x, 0)), 1));
  3290.       return gen_lowpart_for_combine (mode, x);
  3291.     }
  3292.                         
  3293. #if STORE_FLAG_VALUE == -1
  3294.       /* (not (comparison foo bar)) can be done by reversing the comparison
  3295.      code if valid.  */
  3296.       if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
  3297.       && reversible_comparison_p (XEXP (x, 0)))
  3298.     return gen_rtx_combine (reverse_condition (GET_CODE (XEXP (x, 0))),
  3299.                 mode, XEXP (XEXP (x, 0), 0),
  3300.                 XEXP (XEXP (x, 0), 1));
  3301.  
  3302.       /* (ashiftrt foo C) where C is the number of bits in FOO minus 1
  3303.      is (lt foo (const_int 0)), so we can perform the above
  3304.      simplification.  */
  3305.  
  3306.       if (XEXP (x, 1) == const1_rtx
  3307.       && GET_CODE (XEXP (x, 0)) == ASHIFTRT
  3308.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  3309.       && INTVAL (XEXP (XEXP (x, 0), 1)) == GET_MODE_BITSIZE (mode) - 1)
  3310.     return gen_rtx_combine (GE, mode, XEXP (XEXP (x, 0), 0), const0_rtx);
  3311. #endif
  3312.  
  3313.       /* Apply De Morgan's laws to reduce number of patterns for machines
  3314.       with negating logical insns (and-not, nand, etc.).  If result has
  3315.       only one NOT, put it first, since that is how the patterns are
  3316.       coded.  */
  3317.  
  3318.       if (GET_CODE (XEXP (x, 0)) == IOR || GET_CODE (XEXP (x, 0)) == AND)
  3319.      {
  3320.       rtx in1 = XEXP (XEXP (x, 0), 0), in2 = XEXP (XEXP (x, 0), 1);
  3321.  
  3322.      if (GET_CODE (in1) == NOT)
  3323.        in1 = XEXP (in1, 0);
  3324.       else
  3325.        in1 = gen_rtx_combine (NOT, GET_MODE (in1), in1);
  3326.  
  3327.      if (GET_CODE (in2) == NOT)
  3328.        in2 = XEXP (in2, 0);
  3329.       else if (GET_CODE (in2) == CONST_INT
  3330.           && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
  3331.        in2 = GEN_INT (GET_MODE_MASK (mode) & ~ INTVAL (in2));
  3332.      else
  3333.        in2 = gen_rtx_combine (NOT, GET_MODE (in2), in2);
  3334.  
  3335.      if (GET_CODE (in2) == NOT)
  3336.        {
  3337.          rtx tem = in2;
  3338.          in2 = in1; in1 = tem;
  3339.        }
  3340.  
  3341.      return gen_rtx_combine (GET_CODE (XEXP (x, 0)) == IOR ? AND : IOR,
  3342.                  mode, in1, in2);
  3343.        } 
  3344.       break;
  3345.  
  3346.     case NEG:
  3347.       /* (neg (plus X 1)) can become (not X).  */
  3348.       if (GET_CODE (XEXP (x, 0)) == PLUS
  3349.       && XEXP (XEXP (x, 0), 1) == const1_rtx)
  3350.     return gen_rtx_combine (NOT, mode, XEXP (XEXP (x, 0), 0));
  3351.  
  3352.       /* Similarly, (neg (not X)) is (plus X 1).  */
  3353.       if (GET_CODE (XEXP (x, 0)) == NOT)
  3354.     return plus_constant (XEXP (XEXP (x, 0), 0), 1);
  3355.  
  3356.       /* (neg (minus X Y)) can become (minus Y X).  */
  3357.       if (GET_CODE (XEXP (x, 0)) == MINUS
  3358.       && (! FLOAT_MODE_P (mode)
  3359.           /* x-y != -(y-x) with IEEE floating point. */
  3360.           || TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
  3361.           || flag_fast_math))
  3362.     return gen_binary (MINUS, mode, XEXP (XEXP (x, 0), 1),
  3363.                XEXP (XEXP (x, 0), 0));
  3364.  
  3365.       /* (neg (xor A 1)) is (plus A -1) if A is known to be either 0 or 1. */
  3366.       if (GET_CODE (XEXP (x, 0)) == XOR && XEXP (XEXP (x, 0), 1) == const1_rtx
  3367.       && nonzero_bits (XEXP (XEXP (x, 0), 0), mode) == 1)
  3368.     return gen_binary (PLUS, mode, XEXP (XEXP (x, 0), 0), constm1_rtx);
  3369.  
  3370.       /* NEG commutes with ASHIFT since it is multiplication.  Only do this
  3371.      if we can then eliminate the NEG (e.g.,
  3372.      if the operand is a constant).  */
  3373.  
  3374.       if (GET_CODE (XEXP (x, 0)) == ASHIFT)
  3375.     {
  3376.       temp = simplify_unary_operation (NEG, mode,
  3377.                        XEXP (XEXP (x, 0), 0), mode);
  3378.       if (temp)
  3379.         {
  3380.           SUBST (XEXP (XEXP (x, 0), 0), temp);
  3381.           return XEXP (x, 0);
  3382.         }
  3383.     }
  3384.  
  3385.       temp = expand_compound_operation (XEXP (x, 0));
  3386.  
  3387.       /* For C equal to the width of MODE minus 1, (neg (ashiftrt X C)) can be
  3388.       replaced by (lshiftrt X C).  This will convert
  3389.      (neg (sign_extract X 1 Y)) to (zero_extract X 1 Y).  */
  3390.  
  3391.       if (GET_CODE (temp) == ASHIFTRT
  3392.       && GET_CODE (XEXP (temp, 1)) == CONST_INT
  3393.       && INTVAL (XEXP (temp, 1)) == GET_MODE_BITSIZE (mode) - 1)
  3394.     return simplify_shift_const (temp, LSHIFTRT, mode, XEXP (temp, 0),
  3395.                      INTVAL (XEXP (temp, 1)));
  3396.  
  3397.       /* If X has only a single bit that might be nonzero, say, bit I, convert
  3398.      (neg X) to (ashiftrt (ashift X C-I) C-I) where C is the bitsize of
  3399.      MODE minus 1.  This will convert (neg (zero_extract X 1 Y)) to
  3400.      (sign_extract X 1 Y).  But only do this if TEMP isn't a register
  3401.      or a SUBREG of one since we'd be making the expression more
  3402.      complex if it was just a register.  */
  3403.  
  3404.       if (GET_CODE (temp) != REG
  3405.       && ! (GET_CODE (temp) == SUBREG
  3406.         && GET_CODE (SUBREG_REG (temp)) == REG)
  3407.       && (i = exact_log2 (nonzero_bits (temp, mode))) >= 0)
  3408.     {
  3409.       rtx temp1 = simplify_shift_const
  3410.         (NULL_RTX, ASHIFTRT, mode,
  3411.          simplify_shift_const (NULL_RTX, ASHIFT, mode, temp,
  3412.                    GET_MODE_BITSIZE (mode) - 1 - i),
  3413.          GET_MODE_BITSIZE (mode) - 1 - i);
  3414.  
  3415.       /* If all we did was surround TEMP with the two shifts, we
  3416.          haven't improved anything, so don't use it.  Otherwise,
  3417.          we are better off with TEMP1.  */
  3418.       if (GET_CODE (temp1) != ASHIFTRT
  3419.           || GET_CODE (XEXP (temp1, 0)) != ASHIFT
  3420.           || XEXP (XEXP (temp1, 0), 0) != temp)
  3421.         return temp1;
  3422.     }
  3423.       break;
  3424.  
  3425.     case FLOAT_TRUNCATE:
  3426.       /* (float_truncate:SF (float_extend:DF foo:SF)) = foo:SF.  */
  3427.       if (GET_CODE (XEXP (x, 0)) == FLOAT_EXTEND
  3428.       && GET_MODE (XEXP (XEXP (x, 0), 0)) == mode)
  3429.      return XEXP (XEXP (x, 0), 0);
  3430.  
  3431.       /* (float_truncate:SF (OP:DF (float_extend:DF foo:sf))) is
  3432.      (OP:SF foo:SF) if OP is NEG or ABS.  */
  3433.       if ((GET_CODE (XEXP (x, 0)) == ABS
  3434.        || GET_CODE (XEXP (x, 0)) == NEG)
  3435.       && GET_CODE (XEXP (XEXP (x, 0), 0)) == FLOAT_EXTEND
  3436.       && GET_MODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == mode)
  3437.     return gen_unary (GET_CODE (XEXP (x, 0)), mode, mode,
  3438.               XEXP (XEXP (XEXP (x, 0), 0), 0));
  3439.       break;  
  3440.  
  3441. #ifdef HAVE_cc0
  3442.     case COMPARE:
  3443.       /* Convert (compare FOO (const_int 0)) to FOO unless we aren't
  3444.      using cc0, in which case we want to leave it as a COMPARE
  3445.      so we can distinguish it from a register-register-copy.  */
  3446.       if (XEXP (x, 1) == const0_rtx)
  3447.     return XEXP (x, 0);
  3448.  
  3449.       /* In IEEE floating point, x-0 is not the same as x.  */
  3450.       if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
  3451.        || ! FLOAT_MODE_P (GET_MODE (XEXP (x, 0)))
  3452.        || flag_fast_math)
  3453.       && XEXP (x, 1) == CONST0_RTX (GET_MODE (XEXP (x, 0))))
  3454.     return XEXP (x, 0);
  3455.       break;
  3456. #endif
  3457.  
  3458.     case CONST:
  3459.       /* (const (const X)) can become (const X).  Do it this way rather than
  3460.      returning the inner CONST since CONST can be shared with a
  3461.      REG_EQUAL note.  */
  3462.       if (GET_CODE (XEXP (x, 0)) == CONST)
  3463.     SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
  3464.       break;
  3465.  
  3466. #ifdef HAVE_lo_sum
  3467.     case LO_SUM:
  3468.       /* Convert (lo_sum (high FOO) FOO) to FOO.  This is necessary so we
  3469.      can add in an offset.  find_split_point will split this address up
  3470.      again if it doesn't match.  */
  3471.       if (GET_CODE (XEXP (x, 0)) == HIGH
  3472.       && rtx_equal_p (XEXP (XEXP (x, 0), 0), XEXP (x, 1)))
  3473.     return XEXP (x, 1);
  3474.       break;
  3475. #endif
  3476.  
  3477.     case PLUS:
  3478.       /* If we have (plus (plus (A const) B)), associate it so that CONST is
  3479.      outermost.  That's because that's the way indexed addresses are
  3480.      supposed to appear.  This code used to check many more cases, but
  3481.      they are now checked elsewhere.  */
  3482.       if (GET_CODE (XEXP (x, 0)) == PLUS
  3483.       && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
  3484.     return gen_binary (PLUS, mode,
  3485.                gen_binary (PLUS, mode, XEXP (XEXP (x, 0), 0),
  3486.                        XEXP (x, 1)),
  3487.                XEXP (XEXP (x, 0), 1));
  3488.  
  3489.       /* (plus (xor (and <foo> (const_int pow2 - 1)) <c>) <-c>)
  3490.      when c is (const_int (pow2 + 1) / 2) is a sign extension of a
  3491.      bit-field and can be replaced by either a sign_extend or a
  3492.      sign_extract.  The `and' may be a zero_extend.  */
  3493.       if (GET_CODE (XEXP (x, 0)) == XOR
  3494.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  3495.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  3496.       && INTVAL (XEXP (x, 1)) == - INTVAL (XEXP (XEXP (x, 0), 1))
  3497.       && (i = exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)))) >= 0
  3498.       && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  3499.       && ((GET_CODE (XEXP (XEXP (x, 0), 0)) == AND
  3500.            && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
  3501.            && (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1))
  3502.            == ((HOST_WIDE_INT) 1 << (i + 1)) - 1))
  3503.           || (GET_CODE (XEXP (XEXP (x, 0), 0)) == ZERO_EXTEND
  3504.           && (GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (XEXP (x, 0), 0), 0)))
  3505.               == i + 1))))
  3506.     return simplify_shift_const
  3507.       (NULL_RTX, ASHIFTRT, mode,
  3508.        simplify_shift_const (NULL_RTX, ASHIFT, mode,
  3509.                  XEXP (XEXP (XEXP (x, 0), 0), 0),
  3510.                  GET_MODE_BITSIZE (mode) - (i + 1)),
  3511.        GET_MODE_BITSIZE (mode) - (i + 1));
  3512.  
  3513.       /* (plus (comparison A B) C) can become (neg (rev-comp A B)) if
  3514.      C is 1 and STORE_FLAG_VALUE is -1 or if C is -1 and STORE_FLAG_VALUE
  3515.      is 1.  This produces better code than the alternative immediately
  3516.      below.  */
  3517.       if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
  3518.       && reversible_comparison_p (XEXP (x, 0))
  3519.       && ((STORE_FLAG_VALUE == -1 && XEXP (x, 1) == const1_rtx)
  3520.           || (STORE_FLAG_VALUE == 1 && XEXP (x, 1) == constm1_rtx)))
  3521.     return
  3522.       gen_unary (NEG, mode, mode,
  3523.              gen_binary (reverse_condition (GET_CODE (XEXP (x, 0))),
  3524.                  mode, XEXP (XEXP (x, 0), 0),
  3525.                  XEXP (XEXP (x, 0), 1)));
  3526.  
  3527.       /* If only the low-order bit of X is possibly nonzero, (plus x -1)
  3528.      can become (ashiftrt (ashift (xor x 1) C) C) where C is
  3529.      the bitsize of the mode - 1.  This allows simplification of
  3530.      "a = (b & 8) == 0;"  */
  3531.       if (XEXP (x, 1) == constm1_rtx
  3532.       && GET_CODE (XEXP (x, 0)) != REG
  3533.       && ! (GET_CODE (XEXP (x,0)) == SUBREG
  3534.         && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG)
  3535.       && nonzero_bits (XEXP (x, 0), mode) == 1)
  3536.     return simplify_shift_const (NULL_RTX, ASHIFTRT, mode,
  3537.        simplify_shift_const (NULL_RTX, ASHIFT, mode,
  3538.                  gen_rtx_combine (XOR, mode,
  3539.                           XEXP (x, 0), const1_rtx),
  3540.                  GET_MODE_BITSIZE (mode) - 1),
  3541.        GET_MODE_BITSIZE (mode) - 1);
  3542.  
  3543.       /* If we are adding two things that have no bits in common, convert
  3544.      the addition into an IOR.  This will often be further simplified,
  3545.      for example in cases like ((a & 1) + (a & 2)), which can
  3546.      become a & 3.  */
  3547.  
  3548.       if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  3549.       && (nonzero_bits (XEXP (x, 0), mode)
  3550.           & nonzero_bits (XEXP (x, 1), mode)) == 0)
  3551.     return gen_binary (IOR, mode, XEXP (x, 0), XEXP (x, 1));
  3552.       break;
  3553.  
  3554.     case MINUS:
  3555. #if STORE_FLAG_VALUE == 1
  3556.       /* (minus 1 (comparison foo bar)) can be done by reversing the comparison
  3557.      code if valid.  */
  3558.       if (XEXP (x, 0) == const1_rtx
  3559.       && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == '<'
  3560.       && reversible_comparison_p (XEXP (x, 1)))
  3561.     return gen_binary (reverse_condition (GET_CODE (XEXP (x, 1))),
  3562.                mode, XEXP (XEXP (x, 1), 0),
  3563.                 XEXP (XEXP (x, 1), 1));
  3564. #endif
  3565.  
  3566.       /* (minus <foo> (and <foo> (const_int -pow2))) becomes
  3567.      (and <foo> (const_int pow2-1))  */
  3568.       if (GET_CODE (XEXP (x, 1)) == AND
  3569.       && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
  3570.       && exact_log2 (- INTVAL (XEXP (XEXP (x, 1), 1))) >= 0
  3571.       && rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0)))
  3572.     return simplify_and_const_int (NULL_RTX, mode, XEXP (x, 0),
  3573.                        - INTVAL (XEXP (XEXP (x, 1), 1)) - 1);
  3574.  
  3575.       /* Canonicalize (minus A (plus B C)) to (minus (minus A B) C) for
  3576.      integers.  */
  3577.       if (GET_CODE (XEXP (x, 1)) == PLUS && INTEGRAL_MODE_P (mode))
  3578.     return gen_binary (MINUS, mode,
  3579.                gen_binary (MINUS, mode, XEXP (x, 0),
  3580.                        XEXP (XEXP (x, 1), 0)),
  3581.                XEXP (XEXP (x, 1), 1));
  3582.       break;
  3583.  
  3584.     case MULT:
  3585.       /* If we have (mult (plus A B) C), apply the distributive law and then
  3586.      the inverse distributive law to see if things simplify.  This
  3587.      occurs mostly in addresses, often when unrolling loops.  */
  3588.  
  3589.       if (GET_CODE (XEXP (x, 0)) == PLUS)
  3590.     {
  3591.       x = apply_distributive_law
  3592.         (gen_binary (PLUS, mode,
  3593.              gen_binary (MULT, mode,
  3594.                      XEXP (XEXP (x, 0), 0), XEXP (x, 1)),
  3595.              gen_binary (MULT, mode,
  3596.                      XEXP (XEXP (x, 0), 1), XEXP (x, 1))));
  3597.  
  3598.       if (GET_CODE (x) != MULT)
  3599.         return x;
  3600.     }
  3601.       break;
  3602.  
  3603.     case UDIV:
  3604.       /* If this is a divide by a power of two, treat it as a shift if
  3605.      its first operand is a shift.  */
  3606.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  3607.       && (i = exact_log2 (INTVAL (XEXP (x, 1)))) >= 0
  3608.       && (GET_CODE (XEXP (x, 0)) == ASHIFT
  3609.           || GET_CODE (XEXP (x, 0)) == LSHIFTRT
  3610.           || GET_CODE (XEXP (x, 0)) == ASHIFTRT
  3611.           || GET_CODE (XEXP (x, 0)) == ROTATE
  3612.           || GET_CODE (XEXP (x, 0)) == ROTATERT))
  3613.     return simplify_shift_const (NULL_RTX, LSHIFTRT, mode, XEXP (x, 0), i);
  3614.       break;
  3615.  
  3616.     case EQ:  case NE:
  3617.     case GT:  case GTU:  case GE:  case GEU:
  3618.     case LT:  case LTU:  case LE:  case LEU:
  3619.       /* If the first operand is a condition code, we can't do anything
  3620.      with it.  */
  3621.       if (GET_CODE (XEXP (x, 0)) == COMPARE
  3622.       || (GET_MODE_CLASS (GET_MODE (XEXP (x, 0))) != MODE_CC
  3623. #ifdef HAVE_cc0
  3624.           && XEXP (x, 0) != cc0_rtx
  3625. #endif
  3626.            ))
  3627.     {
  3628.       rtx op0 = XEXP (x, 0);
  3629.       rtx op1 = XEXP (x, 1);
  3630.       enum rtx_code new_code;
  3631.  
  3632.       if (GET_CODE (op0) == COMPARE)
  3633.         op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
  3634.  
  3635.       /* Simplify our comparison, if possible.  */
  3636.       new_code = simplify_comparison (code, &op0, &op1);
  3637.  
  3638. #if STORE_FLAG_VALUE == 1
  3639.       /* If STORE_FLAG_VALUE is 1, we can convert (ne x 0) to simply X
  3640.          if only the low-order bit is possibly nonzero in X (such as when
  3641.          X is a ZERO_EXTRACT of one bit).  Similarly, we can convert EQ to
  3642.          (xor X 1) or (minus 1 X); we use the former.  Finally, if X is
  3643.          known to be either 0 or -1, NE becomes a NEG and EQ becomes
  3644.          (plus X 1).
  3645.  
  3646.          Remove any ZERO_EXTRACT we made when thinking this was a
  3647.          comparison.  It may now be simpler to use, e.g., an AND.  If a
  3648.          ZERO_EXTRACT is indeed appropriate, it will be placed back by
  3649.          the call to make_compound_operation in the SET case.  */
  3650.  
  3651.       if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT
  3652.           && op1 == const0_rtx
  3653.           && nonzero_bits (op0, mode) == 1)
  3654.         return gen_lowpart_for_combine (mode,
  3655.                         expand_compound_operation (op0));
  3656.  
  3657.       else if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT
  3658.            && op1 == const0_rtx
  3659.            && (num_sign_bit_copies (op0, mode)
  3660.                == GET_MODE_BITSIZE (mode)))
  3661.         {
  3662.           op0 = expand_compound_operation (op0);
  3663.           return gen_unary (NEG, mode, mode,
  3664.                 gen_lowpart_for_combine (mode, op0));
  3665.         }
  3666.  
  3667.       else if (new_code == EQ && GET_MODE_CLASS (mode) == MODE_INT
  3668.            && op1 == const0_rtx
  3669.            && nonzero_bits (op0, mode) == 1)
  3670.         {
  3671.           op0 = expand_compound_operation (op0);
  3672.           return gen_binary (XOR, mode,
  3673.                  gen_lowpart_for_combine (mode, op0),
  3674.                  const1_rtx);
  3675.         }
  3676.  
  3677.       else if (new_code == EQ && GET_MODE_CLASS (mode) == MODE_INT
  3678.            && op1 == const0_rtx
  3679.            && (num_sign_bit_copies (op0, mode)
  3680.                == GET_MODE_BITSIZE (mode)))
  3681.         {
  3682.           op0 = expand_compound_operation (op0);
  3683.           return plus_constant (gen_lowpart_for_combine (mode, op0), 1);
  3684.         }
  3685. #endif
  3686.  
  3687. #if STORE_FLAG_VALUE == -1
  3688.       /* If STORE_FLAG_VALUE is -1, we have cases similar to
  3689.          those above.  */
  3690.       if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT
  3691.           && op1 == const0_rtx
  3692.           && (num_sign_bit_copies (op0, mode)
  3693.           == GET_MODE_BITSIZE (mode)))
  3694.         return gen_lowpart_for_combine (mode,
  3695.                         expand_compound_operation (op0));
  3696.  
  3697.       else if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT
  3698.            && op1 == const0_rtx
  3699.            && nonzero_bits (op0, mode) == 1)
  3700.         {
  3701.           op0 = expand_compound_operation (op0);
  3702.           return gen_unary (NEG, mode, mode,
  3703.                 gen_lowpart_for_combine (mode, op0));
  3704.         }
  3705.  
  3706.       else if (new_code == EQ && GET_MODE_CLASS (mode) == MODE_INT
  3707.            && op1 == const0_rtx
  3708.            && (num_sign_bit_copies (op0, mode)
  3709.                == GET_MODE_BITSIZE (mode)))
  3710.         {
  3711.           op0 = expand_compound_operation (op0);
  3712.           return gen_unary (NOT, mode, mode,
  3713.                 gen_lowpart_for_combine (mode, op0));
  3714.         }
  3715.  
  3716.       /* If X is 0/1, (eq X 0) is X-1.  */
  3717.       else if (new_code == EQ && GET_MODE_CLASS (mode) == MODE_INT
  3718.            && op1 == const0_rtx
  3719.            && nonzero_bits (op0, mode) == 1)
  3720.         {
  3721.           op0 = expand_compound_operation (op0);
  3722.           return plus_constant (gen_lowpart_for_combine (mode, op0), -1);
  3723.         }
  3724. #endif
  3725.  
  3726.       /* If STORE_FLAG_VALUE says to just test the sign bit and X has just
  3727.          one bit that might be nonzero, we can convert (ne x 0) to
  3728.          (ashift x c) where C puts the bit in the sign bit.  Remove any
  3729.          AND with STORE_FLAG_VALUE when we are done, since we are only
  3730.          going to test the sign bit.  */
  3731.       if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT
  3732.           && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  3733.           && (STORE_FLAG_VALUE
  3734.           == (HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (mode) - 1))
  3735.           && op1 == const0_rtx
  3736.           && mode == GET_MODE (op0)
  3737.           && (i = exact_log2 (nonzero_bits (op0, mode))) >= 0)
  3738.         {
  3739.           x = simplify_shift_const (NULL_RTX, ASHIFT, mode,
  3740.                     expand_compound_operation (op0),
  3741.                     GET_MODE_BITSIZE (mode) - 1 - i);
  3742.           if (GET_CODE (x) == AND && XEXP (x, 1) == const_true_rtx)
  3743.         return XEXP (x, 0);
  3744.           else
  3745.         return x;
  3746.         }
  3747.  
  3748.       /* If the code changed, return a whole new comparison.  */
  3749.       if (new_code != code)
  3750.         return gen_rtx_combine (new_code, mode, op0, op1);
  3751.  
  3752.       /* Otherwise, keep this operation, but maybe change its operands.  
  3753.          This also converts (ne (compare FOO BAR) 0) to (ne FOO BAR).  */
  3754.       SUBST (XEXP (x, 0), op0);
  3755.       SUBST (XEXP (x, 1), op1);
  3756.     }
  3757.       break;
  3758.       
  3759.     case IF_THEN_ELSE:
  3760.       return simplify_if_then_else (x);
  3761.  
  3762.     case ZERO_EXTRACT:
  3763.     case SIGN_EXTRACT:
  3764.     case ZERO_EXTEND:
  3765.     case SIGN_EXTEND:
  3766.       /* If we are processing SET_DEST, we are done. */
  3767.       if (in_dest)
  3768.     return x;
  3769.  
  3770.       return expand_compound_operation (x);
  3771.  
  3772.     case SET:
  3773.       return simplify_set (x);
  3774.  
  3775.     case AND:
  3776.     case IOR:
  3777.     case XOR:
  3778.       return simplify_logical (x, last);
  3779.  
  3780.     case ABS:
  3781.       /* (abs (neg <foo>)) -> (abs <foo>) */
  3782.       if (GET_CODE (XEXP (x, 0)) == NEG)
  3783.     SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
  3784.  
  3785.       /* If operand is something known to be positive, ignore the ABS.  */
  3786.       if (GET_CODE (XEXP (x, 0)) == FFS || GET_CODE (XEXP (x, 0)) == ABS
  3787.       || ((GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))
  3788.            <= HOST_BITS_PER_WIDE_INT)
  3789.           && ((nonzero_bits (XEXP (x, 0), GET_MODE (XEXP (x, 0)))
  3790.            & ((HOST_WIDE_INT) 1
  3791.               << (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) - 1)))
  3792.           == 0)))
  3793.     return XEXP (x, 0);
  3794.  
  3795.  
  3796.       /* If operand is known to be only -1 or 0, convert ABS to NEG.  */
  3797.       if (num_sign_bit_copies (XEXP (x, 0), mode) == GET_MODE_BITSIZE (mode))
  3798.     return gen_rtx_combine (NEG, mode, XEXP (x, 0));
  3799.  
  3800.       break;
  3801.  
  3802.     case FFS:
  3803.       /* (ffs (*_extend <X>)) = (ffs <X>) */
  3804.       if (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND
  3805.       || GET_CODE (XEXP (x, 0)) == ZERO_EXTEND)
  3806.     SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
  3807.       break;
  3808.  
  3809.     case FLOAT:
  3810.       /* (float (sign_extend <X>)) = (float <X>).  */
  3811.       if (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)
  3812.     SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
  3813.       break;
  3814.  
  3815.     case ASHIFT:
  3816.     case LSHIFTRT:
  3817.     case ASHIFTRT:
  3818.     case ROTATE:
  3819.     case ROTATERT:
  3820.       /* If this is a shift by a constant amount, simplify it.  */
  3821.       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  3822.     return simplify_shift_const (x, code, mode, XEXP (x, 0), 
  3823.                      INTVAL (XEXP (x, 1)));
  3824.  
  3825. #ifdef SHIFT_COUNT_TRUNCATED
  3826.       else if (SHIFT_COUNT_TRUNCATED && GET_CODE (XEXP (x, 1)) != REG)
  3827.     SUBST (XEXP (x, 1),
  3828.            force_to_mode (XEXP (x, 1), GET_MODE (x),
  3829.                   ((HOST_WIDE_INT) 1 
  3830.                    << exact_log2 (GET_MODE_BITSIZE (GET_MODE (x))))
  3831.                   - 1,
  3832.                   NULL_RTX, 0));
  3833. #endif
  3834.  
  3835.       break;
  3836.     }
  3837.  
  3838.   return x;
  3839. }
  3840.  
  3841. /* Simplify X, an IF_THEN_ELSE expression.  Return the new expression.  */
  3842.  
  3843. static rtx
  3844. simplify_if_then_else (x)
  3845.      rtx x;
  3846. {
  3847.   enum machine_mode mode = GET_MODE (x);
  3848.   rtx cond = XEXP (x, 0);
  3849.   rtx true = XEXP (x, 1);
  3850.   rtx false = XEXP (x, 2);
  3851.   enum rtx_code true_code = GET_CODE (cond);
  3852.   int comparison_p = GET_RTX_CLASS (true_code) == '<';
  3853.   rtx temp;
  3854.   int i;
  3855.  
  3856.   /* Simplify storing of the truth value. */
  3857.   if (comparison_p && true == const_true_rtx && false == const0_rtx)
  3858.     return gen_binary (true_code, mode, XEXP (cond, 0), XEXP (cond, 1));
  3859.       
  3860.   /* Also when the truth value has to be reversed. */
  3861.   if (comparison_p && reversible_comparison_p (cond)
  3862.       && true == const0_rtx && false == const_true_rtx)
  3863.     return gen_binary (reverse_condition (true_code),
  3864.                mode, XEXP (cond, 0), XEXP (cond, 1));
  3865.  
  3866.   /* Sometimes we can simplify the arm of an IF_THEN_ELSE if a register used
  3867.      in it is being compared against certain values.  Get the true and false
  3868.      comparisons and see if that says anything about the value of each arm.  */
  3869.  
  3870.   if (comparison_p && reversible_comparison_p (cond)
  3871.       && GET_CODE (XEXP (cond, 0)) == REG)
  3872.     {
  3873.       HOST_WIDE_INT nzb;
  3874.       rtx from = XEXP (cond, 0);
  3875.       enum rtx_code false_code = reverse_condition (true_code);
  3876.       rtx true_val = XEXP (cond, 1);
  3877.       rtx false_val = true_val;
  3878.       int swapped = 0;
  3879.  
  3880.       /* If FALSE_CODE is EQ, swap the codes and arms.  */
  3881.  
  3882.       if (false_code == EQ)
  3883.     {
  3884.       swapped = 1, true_code = EQ, false_code = NE;
  3885.       temp = true, true = false, false = temp;
  3886.     }
  3887.  
  3888.       /* If we are comparing against zero and the expression being tested has
  3889.      only a single bit that might be nonzero, that is its value when it is
  3890.      not equal to zero.  Similarly if it is known to be -1 or 0.  */
  3891.  
  3892.       if (true_code == EQ && true_val == const0_rtx
  3893.       && exact_log2 (nzb = nonzero_bits (from, GET_MODE (from))) >= 0)
  3894.     false_code = EQ, false_val = GEN_INT (nzb);
  3895.       else if (true_code == EQ && true_val == const0_rtx
  3896.            && (num_sign_bit_copies (from, GET_MODE (from))
  3897.            == GET_MODE_BITSIZE (GET_MODE (from))))
  3898.     false_code = EQ, false_val = constm1_rtx;
  3899.  
  3900.       /* Now simplify an arm if we know the value of the register in the
  3901.      branch and it is used in the arm.  Be careful due to the potential
  3902.      of locally-shared RTL.  */
  3903.  
  3904.       if (reg_mentioned_p (from, true))
  3905.     true = subst (known_cond (copy_rtx (true), true_code, from, true_val),
  3906.               pc_rtx, pc_rtx, 0, 0);
  3907.       if (reg_mentioned_p (from, false))
  3908.     false = subst (known_cond (copy_rtx (false), false_code,
  3909.                    from, false_val),
  3910.                pc_rtx, pc_rtx, 0, 0);
  3911.  
  3912.       SUBST (XEXP (x, 1), swapped ? false : true);
  3913.       SUBST (XEXP (x, 2), swapped ? true : false);
  3914.  
  3915.       true = XEXP (x, 1), false = XEXP (x, 2), true_code = GET_CODE (cond);
  3916.     }
  3917.  
  3918.   /* If we have (if_then_else FOO (pc) (label_ref BAR)) and FOO can be
  3919.      reversed, do so to avoid needing two sets of patterns for
  3920.      subtract-and-branch insns.  Similarly if we have a constant in the true
  3921.      arm, the false arm is the same as the first operand of the comparison, or
  3922.      the false arm is more complicated than the true arm.  */
  3923.  
  3924.   if (comparison_p && reversible_comparison_p (cond)
  3925.       && (true == pc_rtx 
  3926.       || (CONSTANT_P (true)
  3927.           && GET_CODE (false) != CONST_INT && false != pc_rtx)
  3928.       || true == const0_rtx
  3929.       || (GET_RTX_CLASS (GET_CODE (true)) == 'o'
  3930.           && GET_RTX_CLASS (GET_CODE (false)) != 'o')
  3931.       || (GET_CODE (true) == SUBREG
  3932.           && GET_RTX_CLASS (GET_CODE (SUBREG_REG (true))) == 'o'
  3933.           && GET_RTX_CLASS (GET_CODE (false)) != 'o')
  3934.       || reg_mentioned_p (true, false)
  3935.       || rtx_equal_p (false, XEXP (cond, 0))))
  3936.     {
  3937.       true_code = reverse_condition (true_code);
  3938.       SUBST (XEXP (x, 0),
  3939.          gen_binary (true_code, GET_MODE (cond), XEXP (cond, 0),
  3940.              XEXP (cond, 1)));
  3941.  
  3942.       SUBST (XEXP (x, 1), false);
  3943.       SUBST (XEXP (x, 2), true);
  3944.  
  3945.       temp = true, true = false, false = temp, cond = XEXP (x, 0);
  3946.     }
  3947.  
  3948.   /* If the two arms are identical, we don't need the comparison.  */
  3949.  
  3950.   if (rtx_equal_p (true, false) && ! side_effects_p (cond))
  3951.     return true;
  3952.  
  3953.   /* Look for cases where we have (abs x) or (neg (abs X)).  */
  3954.  
  3955.   if (GET_MODE_CLASS (mode) == MODE_INT
  3956.       && GET_CODE (false) == NEG
  3957.       && rtx_equal_p (true, XEXP (false, 0))
  3958.       && comparison_p
  3959.       && rtx_equal_p (true, XEXP (cond, 0))
  3960.       && ! side_effects_p (true))
  3961.     switch (true_code)
  3962.       {
  3963.       case GT:
  3964.       case GE:
  3965.     return gen_unary (ABS, mode, mode, true);
  3966.       case LT:
  3967.       case LE:
  3968.     return gen_unary (NEG, mode, mode, gen_unary (ABS, mode, mode, true));
  3969.       }
  3970.  
  3971.   /* Look for MIN or MAX.  */
  3972.  
  3973.   if ((! FLOAT_MODE_P (mode) | flag_fast_math)
  3974.       && comparison_p
  3975.       && rtx_equal_p (XEXP (cond, 0), true)
  3976.       && rtx_equal_p (XEXP (cond, 1), false)
  3977.       && ! side_effects_p (cond))
  3978.     switch (true_code)
  3979.       {
  3980.       case GE:
  3981.       case GT:
  3982.     return gen_binary (SMAX, mode, true, false);
  3983.       case LE:
  3984.       case LT:
  3985.     return gen_binary (SMIN, mode, true, false);
  3986.       case GEU:
  3987.       case GTU:
  3988.     return gen_binary (UMAX, mode, true, false);
  3989.       case LEU:
  3990.       case LTU:
  3991.     return gen_binary (UMIN, mode, true, false);
  3992.       }
  3993.   
  3994. #if STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1
  3995.  
  3996.   /* If we have (if_then_else COND (OP Z C1) Z) and OP is an identity when its
  3997.      second operand is zero, this can be done as (OP Z (mult COND C2)) where
  3998.      C2 = C1 * STORE_FLAG_VALUE. Similarly if OP has an outer ZERO_EXTEND or
  3999.      SIGN_EXTEND as long as Z is already extended (so we don't destroy it).
  4000.      We can do this kind of thing in some cases when STORE_FLAG_VALUE is
  4001.      neither of the above, but it isn't worth checking for.  */
  4002.  
  4003.   if (comparison_p && mode != VOIDmode && ! side_effects_p (x))
  4004.     {
  4005.       rtx t = make_compound_operation (true, SET);
  4006.       rtx f = make_compound_operation (false, SET);
  4007.       rtx cond_op0 = XEXP (cond, 0);
  4008.       rtx cond_op1 = XEXP (cond, 1);
  4009.       enum rtx_code op, extend_op = NIL;
  4010.       enum machine_mode m = mode;
  4011.       rtx z = 0, c1;
  4012.  
  4013.       if ((GET_CODE (t) == PLUS || GET_CODE (t) == MINUS
  4014.        || GET_CODE (t) == IOR || GET_CODE (t) == XOR
  4015.        || GET_CODE (t) == ASHIFT
  4016.        || GET_CODE (t) == LSHIFTRT || GET_CODE (t) == ASHIFTRT)
  4017.       && rtx_equal_p (XEXP (t, 0), f))
  4018.     c1 = XEXP (t, 1), op = GET_CODE (t), z = f;
  4019.  
  4020.       /* If an identity-zero op is commutative, check whether there
  4021.      would be a match if we swapped the operands. */
  4022.       else if ((GET_CODE (t) == PLUS || GET_CODE (t) == IOR
  4023.         || GET_CODE (t) == XOR)
  4024.            && rtx_equal_p (XEXP (t, 1), f))
  4025.     c1 = XEXP (t, 0), op = GET_CODE (t), z = f;
  4026.       else if (GET_CODE (t) == SIGN_EXTEND
  4027.            && (GET_CODE (XEXP (t, 0)) == PLUS
  4028.            || GET_CODE (XEXP (t, 0)) == MINUS
  4029.            || GET_CODE (XEXP (t, 0)) == IOR
  4030.            || GET_CODE (XEXP (t, 0)) == XOR
  4031.            || GET_CODE (XEXP (t, 0)) == ASHIFT
  4032.            || GET_CODE (XEXP (t, 0)) == LSHIFTRT
  4033.            || GET_CODE (XEXP (t, 0)) == ASHIFTRT)
  4034.            && GET_CODE (XEXP (XEXP (t, 0), 0)) == SUBREG
  4035.            && subreg_lowpart_p (XEXP (XEXP (t, 0), 0))
  4036.            && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 0)), f)
  4037.            && (num_sign_bit_copies (f, GET_MODE (f))
  4038.            > (GET_MODE_BITSIZE (mode)
  4039.               - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (t, 0), 0))))))
  4040.     {
  4041.       c1 = XEXP (XEXP (t, 0), 1); z = f; op = GET_CODE (XEXP (t, 0));
  4042.       extend_op = SIGN_EXTEND;
  4043.       m = GET_MODE (XEXP (t, 0));
  4044.     }
  4045.       else if (GET_CODE (t) == SIGN_EXTEND
  4046.            && (GET_CODE (XEXP (t, 0)) == PLUS
  4047.            || GET_CODE (XEXP (t, 0)) == IOR
  4048.            || GET_CODE (XEXP (t, 0)) == XOR)
  4049.            && GET_CODE (XEXP (XEXP (t, 0), 1)) == SUBREG
  4050.            && subreg_lowpart_p (XEXP (XEXP (t, 0), 1))
  4051.            && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 1)), f)
  4052.            && (num_sign_bit_copies (f, GET_MODE (f))
  4053.            > (GET_MODE_BITSIZE (mode)
  4054.               - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (t, 0), 1))))))
  4055.     {
  4056.       c1 = XEXP (XEXP (t, 0), 0); z = f; op = GET_CODE (XEXP (t, 0));
  4057.       extend_op = SIGN_EXTEND;
  4058.       m = GET_MODE (XEXP (t, 0));
  4059.     }
  4060.       else if (GET_CODE (t) == ZERO_EXTEND
  4061.            && (GET_CODE (XEXP (t, 0)) == PLUS
  4062.            || GET_CODE (XEXP (t, 0)) == MINUS
  4063.            || GET_CODE (XEXP (t, 0)) == IOR
  4064.            || GET_CODE (XEXP (t, 0)) == XOR
  4065.            || GET_CODE (XEXP (t, 0)) == ASHIFT
  4066.            || GET_CODE (XEXP (t, 0)) == LSHIFTRT
  4067.            || GET_CODE (XEXP (t, 0)) == ASHIFTRT)
  4068.            && GET_CODE (XEXP (XEXP (t, 0), 0)) == SUBREG
  4069.            && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  4070.            && subreg_lowpart_p (XEXP (XEXP (t, 0), 0))
  4071.            && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 0)), f)
  4072.            && ((nonzero_bits (f, GET_MODE (f))
  4073.             & ~ GET_MODE_MASK (GET_MODE (XEXP (XEXP (t, 0), 0))))
  4074.            == 0))
  4075.     {
  4076.       c1 = XEXP (XEXP (t, 0), 1); z = f; op = GET_CODE (XEXP (t, 0));
  4077.       extend_op = ZERO_EXTEND;
  4078.       m = GET_MODE (XEXP (t, 0));
  4079.     }
  4080.       else if (GET_CODE (t) == ZERO_EXTEND
  4081.            && (GET_CODE (XEXP (t, 0)) == PLUS
  4082.            || GET_CODE (XEXP (t, 0)) == IOR
  4083.            || GET_CODE (XEXP (t, 0)) == XOR)
  4084.            && GET_CODE (XEXP (XEXP (t, 0), 1)) == SUBREG
  4085.            && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  4086.            && subreg_lowpart_p (XEXP (XEXP (t, 0), 1))
  4087.            && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 1)), f)
  4088.            && ((nonzero_bits (f, GET_MODE (f))
  4089.             & ~ GET_MODE_MASK (GET_MODE (XEXP (XEXP (t, 0), 1))))
  4090.            == 0))
  4091.     {
  4092.       c1 = XEXP (XEXP (t, 0), 0); z = f; op = GET_CODE (XEXP (t, 0));
  4093.       extend_op = ZERO_EXTEND;
  4094.       m = GET_MODE (XEXP (t, 0));
  4095.     }
  4096.       
  4097.       if (z)
  4098.     {
  4099.       temp = subst (gen_binary (true_code, m, cond_op0, cond_op1),
  4100.             pc_rtx, pc_rtx, 0, 0);
  4101.       temp = gen_binary (MULT, m, temp,
  4102.                  gen_binary (MULT, m, c1, const_true_rtx));
  4103.       temp = subst (temp, pc_rtx, pc_rtx, 0, 0);
  4104.       temp = gen_binary (op, m, gen_lowpart_for_combine (m, z), temp);
  4105.  
  4106.       if (extend_op != NIL)
  4107.         temp = gen_unary (extend_op, mode, m, temp);
  4108.  
  4109.       return temp;
  4110.     }
  4111.     }
  4112. #endif
  4113.  
  4114.   /* If we have (if_then_else (ne A 0) C1 0) and either A is known to be 0 or
  4115.      1 and C1 is a single bit or A is known to be 0 or -1 and C1 is the
  4116.      negation of a single bit, we can convert this operation to a shift.  We
  4117.      can actually do this more generally, but it doesn't seem worth it.  */
  4118.  
  4119.   if (true_code == NE && XEXP (cond, 1) == const0_rtx
  4120.       && false == const0_rtx && GET_CODE (true) == CONST_INT
  4121.       && ((1 == nonzero_bits (XEXP (cond, 0), mode)
  4122.        && (i = exact_log2 (INTVAL (true))) >= 0)
  4123.       || ((num_sign_bit_copies (XEXP (cond, 0), mode)
  4124.            == GET_MODE_BITSIZE (mode))
  4125.           && (i = exact_log2 (- INTVAL (true))) >= 0)))
  4126.     return
  4127.       simplify_shift_const (NULL_RTX, ASHIFT, mode,
  4128.                 gen_lowpart_for_combine (mode, XEXP (cond, 0)), i);
  4129.  
  4130.   return x;
  4131. }
  4132.  
  4133. /* Simplify X, a SET expression.  Return the new expression.  */
  4134.  
  4135. static rtx
  4136. simplify_set (x)
  4137.      rtx x;
  4138. {
  4139.   rtx src = SET_SRC (x);
  4140.   rtx dest = SET_DEST (x);
  4141.   enum machine_mode mode
  4142.     = GET_MODE (src) != VOIDmode ? GET_MODE (src) : GET_MODE (dest);
  4143.   rtx other_insn;
  4144.   rtx *cc_use;
  4145.  
  4146.   /* (set (pc) (return)) gets written as (return).  */
  4147.   if (GET_CODE (dest) == PC && GET_CODE (src) == RETURN)
  4148.     return src;
  4149.  
  4150.   /* Now that we know for sure which bits of SRC we are using, see if we can
  4151.      simplify the expression for the object knowing that we only need the
  4152.      low-order bits.  */
  4153.  
  4154.   if (GET_MODE_CLASS (mode) == MODE_INT)
  4155.     src = force_to_mode (src, mode, GET_MODE_MASK (mode), NULL_RTX, 0);
  4156.  
  4157.   /* If we are setting CC0 or if the source is a COMPARE, look for the use of
  4158.      the comparison result and try to simplify it unless we already have used
  4159.      undobuf.other_insn.  */
  4160.   if ((GET_CODE (src) == COMPARE
  4161. #ifdef HAVE_cc0
  4162.        || dest == cc0_rtx
  4163. #endif
  4164.        )
  4165.       && (cc_use = find_single_use (dest, subst_insn, &other_insn)) != 0
  4166.       && (undobuf.other_insn == 0 || other_insn == undobuf.other_insn)
  4167.       && GET_RTX_CLASS (GET_CODE (*cc_use)) == '<'
  4168.       && rtx_equal_p (XEXP (*cc_use, 0), dest))
  4169.     {
  4170.       enum rtx_code old_code = GET_CODE (*cc_use);
  4171.       enum rtx_code new_code;
  4172.       rtx op0, op1;
  4173.       int other_changed = 0;
  4174.       enum machine_mode compare_mode = GET_MODE (dest);
  4175.  
  4176.       if (GET_CODE (src) == COMPARE)
  4177.     op0 = XEXP (src, 0), op1 = XEXP (src, 1);
  4178.       else
  4179.     op0 = src, op1 = const0_rtx;
  4180.  
  4181.       /* Simplify our comparison, if possible.  */
  4182.       new_code = simplify_comparison (old_code, &op0, &op1);
  4183.  
  4184. #ifdef EXTRA_CC_MODES
  4185.       /* If this machine has CC modes other than CCmode, check to see if we
  4186.      need to use a different CC mode here.  */
  4187.       compare_mode = SELECT_CC_MODE (new_code, op0, op1);
  4188. #endif /* EXTRA_CC_MODES */
  4189.  
  4190. #if !defined (HAVE_cc0) && defined (EXTRA_CC_MODES)
  4191.       /* If the mode changed, we have to change SET_DEST, the mode in the
  4192.      compare, and the mode in the place SET_DEST is used.  If SET_DEST is
  4193.      a hard register, just build new versions with the proper mode.  If it
  4194.      is a pseudo, we lose unless it is only time we set the pseudo, in
  4195.      which case we can safely change its mode.  */
  4196.       if (compare_mode != GET_MODE (dest))
  4197.     {
  4198.       int regno = REGNO (dest);
  4199.       rtx new_dest = gen_rtx (REG, compare_mode, regno);
  4200.  
  4201.       if (regno < FIRST_PSEUDO_REGISTER
  4202.           || (reg_n_sets[regno] == 1 && ! REG_USERVAR_P (dest)))
  4203.         {
  4204.           if (regno >= FIRST_PSEUDO_REGISTER)
  4205.         SUBST (regno_reg_rtx[regno], new_dest);
  4206.  
  4207.           SUBST (SET_DEST (x), new_dest);
  4208.           SUBST (XEXP (*cc_use, 0), new_dest);
  4209.           other_changed = 1;
  4210.  
  4211.           dest = new_dest;
  4212.         }
  4213.     }
  4214. #endif
  4215.  
  4216.       /* If the code changed, we have to build a new comparison in
  4217.      undobuf.other_insn.  */
  4218.       if (new_code != old_code)
  4219.     {
  4220.       unsigned HOST_WIDE_INT mask;
  4221.  
  4222.       SUBST (*cc_use, gen_rtx_combine (new_code, GET_MODE (*cc_use),
  4223.                        dest, const0_rtx));
  4224.  
  4225.       /* If the only change we made was to change an EQ into an NE or
  4226.          vice versa, OP0 has only one bit that might be nonzero, and OP1
  4227.          is zero, check if changing the user of the condition code will
  4228.          produce a valid insn.  If it won't, we can keep the original code
  4229.          in that insn by surrounding our operation with an XOR.  */
  4230.  
  4231.       if (((old_code == NE && new_code == EQ)
  4232.            || (old_code == EQ && new_code == NE))
  4233.           && ! other_changed && op1 == const0_rtx
  4234.           && GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT
  4235.           && exact_log2 (mask = nonzero_bits (op0, GET_MODE (op0))) >= 0)
  4236.         {
  4237.           rtx pat = PATTERN (other_insn), note = 0;
  4238.  
  4239.           if ((recog_for_combine (&pat, other_insn, ¬e) < 0
  4240.            && ! check_asm_operands (pat)))
  4241.         {
  4242.           PUT_CODE (*cc_use, old_code);
  4243.           other_insn = 0;
  4244.  
  4245.           op0 = gen_binary (XOR, GET_MODE (op0), op0, GEN_INT (mask));
  4246.         }
  4247.         }
  4248.  
  4249.       other_changed = 1;
  4250.     }
  4251.  
  4252.       if (other_changed)
  4253.     undobuf.other_insn = other_insn;
  4254.  
  4255. #ifdef HAVE_cc0
  4256.       /* If we are now comparing against zero, change our source if
  4257.      needed.  If we do not use cc0, we always have a COMPARE.  */
  4258.       if (op1 == const0_rtx && dest == cc0_rtx)
  4259.     {
  4260.       SUBST (SET_SRC (x), op0);
  4261.       src = op0;
  4262.     }
  4263.       else
  4264. #endif
  4265.  
  4266.       /* Otherwise, if we didn't previously have a COMPARE in the
  4267.      correct mode, we need one.  */
  4268.       if (GET_CODE (src) != COMPARE || GET_MODE (src) != compare_mode)
  4269.     {
  4270.       SUBST (SET_SRC (x),
  4271.          gen_rtx_combine (COMPARE, compare_mode, op0, op1));
  4272.       src = SET_SRC (x);
  4273.     }
  4274.       else
  4275.     {
  4276.       /* Otherwise, update the COMPARE if needed.  */
  4277.       SUBST (XEXP (src, 0), op0);
  4278.       SUBST (XEXP (src, 1), op1);
  4279.     }
  4280.     }
  4281.   else
  4282.     {
  4283.       /* Get SET_SRC in a form where we have placed back any
  4284.      compound expressions.  Then do the checks below.  */
  4285.       src = make_compound_operation (src, SET);
  4286.       SUBST (SET_SRC (x), src);
  4287.     }
  4288.  
  4289.   /* If we have (set x (subreg:m1 (op:m2 ...) 0)) with OP being some operation,
  4290.      and X being a REG or (subreg (reg)), we may be able to convert this to
  4291.      (set (subreg:m2 x) (op)). 
  4292.  
  4293.      We can always do this if M1 is narrower than M2 because that means that
  4294.      we only care about the low bits of the result.
  4295.  
  4296.      However, on machines without WORD_REGISTER_OPERATIONS defined, we cannot
  4297.      perform a narrower operation that requested since the high-order bits will
  4298.      be undefined.  On machine where it is defined, this transformation is safe
  4299.      as long as M1 and M2 have the same number of words.  */
  4300.  
  4301.   if (GET_CODE (src) == SUBREG && subreg_lowpart_p (src)
  4302.       && GET_RTX_CLASS (GET_CODE (SUBREG_REG (src))) != 'o'
  4303.       && (((GET_MODE_SIZE (GET_MODE (src)) + (UNITS_PER_WORD - 1))
  4304.        / UNITS_PER_WORD)
  4305.       == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (src)))
  4306.            + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))
  4307. #ifndef WORD_REGISTER_OPERATIONS
  4308.       && (GET_MODE_SIZE (GET_MODE (src))
  4309.       < GET_MODE_SIZE (GET_MODE (SUBREG_REG (src))))
  4310. #endif
  4311.       && (GET_CODE (dest) == REG
  4312.       || (GET_CODE (dest) == SUBREG
  4313.           && GET_CODE (SUBREG_REG (dest)) == REG)))
  4314.     {
  4315.       SUBST (SET_DEST (x),
  4316.          gen_lowpart_for_combine (GET_MODE (SUBREG_REG (src)),
  4317.                       dest));
  4318.       SUBST (SET_SRC (x), SUBREG_REG (src));
  4319.  
  4320.       src = SET_SRC (x), dest = SET_DEST (x);
  4321.     }
  4322.  
  4323. #ifdef LOAD_EXTEND_OP
  4324.   /* If we have (set FOO (subreg:M (mem:N BAR) 0)) with M wider than N, this
  4325.      would require a paradoxical subreg.  Replace the subreg with a
  4326.      zero_extend to avoid the reload that would otherwise be required. */
  4327.  
  4328.   if (GET_CODE (src) == SUBREG && subreg_lowpart_p (src)
  4329.       && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (src))) != NIL
  4330.       && SUBREG_WORD (src) == 0
  4331.       && (GET_MODE_SIZE (GET_MODE (src))
  4332.       > GET_MODE_SIZE (GET_MODE (SUBREG_REG (src))))
  4333.       && GET_CODE (SUBREG_REG (src)) == MEM)
  4334.     {
  4335.       SUBST (SET_SRC (x),
  4336.          gen_rtx_combine (LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (src))),
  4337.                   GET_MODE (src), XEXP (src, 0)));
  4338.  
  4339.       src = SET_SRC (x);
  4340.     }
  4341. #endif
  4342.  
  4343.   /* If we don't have a conditional move, SET_SRC is an IF_THEN_ELSE, and we
  4344.      are comparing an item known to be 0 or -1 against 0, use a logical
  4345.      operation instead. Check for one of the arms being an IOR of the other
  4346.      arm with some value.  We compute three terms to be IOR'ed together.  In
  4347.      practice, at most two will be nonzero.  Then we do the IOR's.  */
  4348.  
  4349.   if (GET_CODE (dest) != PC
  4350.       && GET_CODE (src) == IF_THEN_ELSE
  4351. #ifdef HAVE_conditional_move
  4352.       && ! HAVE_conditional_move
  4353. #endif
  4354.       && GET_MODE_CLASS (GET_MODE (src)) == MODE_INT
  4355.       && (GET_CODE (XEXP (src, 0)) == EQ || GET_CODE (XEXP (src, 0)) == NE)
  4356.       && XEXP (XEXP (src, 0), 1) == const0_rtx
  4357.       && (num_sign_bit_copies (XEXP (XEXP (src, 0), 0),
  4358.                    GET_MODE (XEXP (XEXP (src, 0), 0)))
  4359.       == GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (src, 0), 0))))
  4360.       && ! side_effects_p (src))
  4361.     {
  4362.       rtx true = (GET_CODE (XEXP (src, 0)) == NE
  4363.               ? XEXP (src, 1) : XEXP (src, 2));
  4364.       rtx false = (GET_CODE (XEXP (src, 0)) == NE
  4365.            ? XEXP (src, 2) : XEXP (src, 1));
  4366.       rtx term1 = const0_rtx, term2, term3;
  4367.  
  4368.       if (GET_CODE (true) == IOR && rtx_equal_p (XEXP (true, 0), false))
  4369.     term1 = false, true = XEXP (true, 1), false = const0_rtx;
  4370.       else if (GET_CODE (true) == IOR
  4371.            && rtx_equal_p (XEXP (true, 1), false))
  4372.     term1 = false, true = XEXP (true, 0), false = const0_rtx;
  4373.       else if (GET_CODE (false) == IOR
  4374.            && rtx_equal_p (XEXP (false, 0), true))
  4375.     term1 = true, false = XEXP (false, 1), true = const0_rtx;
  4376.       else if (GET_CODE (false) == IOR
  4377.            && rtx_equal_p (XEXP (false, 1), true))
  4378.     term1 = true, false = XEXP (false, 0), true = const0_rtx;
  4379.  
  4380.       term2 = gen_binary (AND, GET_MODE (src), XEXP (XEXP (src, 0), 0), true);
  4381.       term3 = gen_binary (AND, GET_MODE (src),
  4382.               gen_unary (NOT, GET_MODE (src), GET_MODE (src),
  4383.                      XEXP (XEXP (src, 0), 0)),
  4384.               false);
  4385.  
  4386.       SUBST (SET_SRC (x),
  4387.          gen_binary (IOR, GET_MODE (src),
  4388.              gen_binary (IOR, GET_MODE (src), term1, term2),
  4389.              term3));
  4390.  
  4391.       src = SET_SRC (x);
  4392.     }
  4393.  
  4394.   /* If either SRC or DEST is a CLOBBER of (const_int 0), make this
  4395.      whole thing fail.  */
  4396.   if (GET_CODE (src) == CLOBBER && XEXP (src, 0) == const0_rtx)
  4397.     return src;
  4398.   else if (GET_CODE (dest) == CLOBBER && XEXP (dest, 0) == const0_rtx)
  4399.     return dest;
  4400.   else
  4401.     /* Convert this into a field assignment operation, if possible.  */
  4402.     return make_field_assignment (x);
  4403. }
  4404.  
  4405. /* Simplify, X, and AND, IOR, or XOR operation, and return the simplified
  4406.    result.  LAST is nonzero if this is the last retry.  */
  4407.  
  4408. static rtx
  4409. simplify_logical (x, last)
  4410.      rtx x;
  4411.      int last;
  4412. {
  4413.   enum machine_mode mode = GET_MODE (x);
  4414.   rtx op0 = XEXP (x, 0);
  4415.   rtx op1 = XEXP (x, 1);
  4416.  
  4417.   switch (GET_CODE (x))
  4418.     {
  4419.     case AND:
  4420.       /* Convert (A ^ B) & A to A & (~ B) since the latter is often a single
  4421.      insn (and may simplify more).  */
  4422.       if (GET_CODE (op0) == XOR
  4423.       && rtx_equal_p (XEXP (op0, 0), op1)
  4424.       && ! side_effects_p (op1))
  4425.     x = gen_binary (AND, mode,
  4426.             gen_unary (NOT, mode, mode, XEXP (op0, 1)), op1);
  4427.  
  4428.       if (GET_CODE (op0) == XOR
  4429.       && rtx_equal_p (XEXP (op0, 1), op1)
  4430.       && ! side_effects_p (op1))
  4431.     x = gen_binary (AND, mode,
  4432.             gen_unary (NOT, mode, mode, XEXP (op0, 0)), op1);
  4433.  
  4434.       /* Similarly for (~ (A ^ B)) & A.  */
  4435.       if (GET_CODE (op0) == NOT
  4436.       && GET_CODE (XEXP (op0, 0)) == XOR
  4437.       && rtx_equal_p (XEXP (XEXP (op0, 0), 0), op1)
  4438.       && ! side_effects_p (op1))
  4439.     x = gen_binary (AND, mode, XEXP (XEXP (op0, 0), 1), op1);
  4440.  
  4441.       if (GET_CODE (op0) == NOT
  4442.       && GET_CODE (XEXP (op0, 0)) == XOR
  4443.       && rtx_equal_p (XEXP (XEXP (op0, 0), 1), op1)
  4444.       && ! side_effects_p (op1))
  4445.     x = gen_binary (AND, mode, XEXP (XEXP (op0, 0), 0), op1);
  4446.  
  4447.       if (GET_CODE (op1) == CONST_INT)
  4448.     {
  4449.       x = simplify_and_const_int (x, mode, op0, INTVAL (op1));
  4450.  
  4451.       /* If we have (ior (and (X C1) C2)) and the next restart would be
  4452.          the last, simplify this by making C1 as small as possible
  4453.          and then exit. */
  4454.       if (last
  4455.           && GET_CODE (x) == IOR && GET_CODE (op0) == AND
  4456.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  4457.           && GET_CODE (op1) == CONST_INT)
  4458.         return gen_binary (IOR, mode,
  4459.                    gen_binary (AND, mode, XEXP (op0, 0),
  4460.                        GEN_INT (INTVAL (XEXP (op0, 1))
  4461.                             & ~ INTVAL (op1))), op1);
  4462.  
  4463.       if (GET_CODE (x) != AND)
  4464.         return x;
  4465.     }
  4466.  
  4467.       /* Convert (A | B) & A to A.  */
  4468.       if (GET_CODE (op0) == IOR
  4469.       && (rtx_equal_p (XEXP (op0, 0), op1)
  4470.           || rtx_equal_p (XEXP (op0, 1), op1))
  4471.       && ! side_effects_p (XEXP (op0, 0))
  4472.       && ! side_effects_p (XEXP (op0, 1)))
  4473.     return op1;
  4474.  
  4475.       /* In the following group of tests (and those in case IOR below),
  4476.      we start with some combination of logical operations and apply
  4477.      the distributive law followed by the inverse distributive law.
  4478.      Most of the time, this results in no change.  However, if some of
  4479.      the operands are the same or inverses of each other, simplifications
  4480.      will result.
  4481.  
  4482.      For example, (and (ior A B) (not B)) can occur as the result of
  4483.      expanding a bit field assignment.  When we apply the distributive
  4484.      law to this, we get (ior (and (A (not B))) (and (B (not B)))),
  4485.      which then simplifies to (and (A (not B))). 
  4486.  
  4487.      If we have (and (ior A B) C), apply the distributive law and then
  4488.      the inverse distributive law to see if things simplify.  */
  4489.  
  4490.       if (GET_CODE (op0) == IOR || GET_CODE (op0) == XOR)
  4491.     {
  4492.       x = apply_distributive_law
  4493.         (gen_binary (GET_CODE (op0), mode,
  4494.              gen_binary (AND, mode, XEXP (op0, 0), op1),
  4495.              gen_binary (AND, mode, XEXP (op0, 1), op1)));
  4496.       if (GET_CODE (x) != AND)
  4497.         return x;
  4498.     }
  4499.  
  4500.       if (GET_CODE (op1) == IOR || GET_CODE (op1) == XOR)
  4501.     return apply_distributive_law
  4502.       (gen_binary (GET_CODE (op1), mode,
  4503.                gen_binary (AND, mode, XEXP (op1, 0), op0),
  4504.                gen_binary (AND, mode, XEXP (op1, 1), op0)));
  4505.  
  4506.       /* Similarly, taking advantage of the fact that
  4507.      (and (not A) (xor B C)) == (xor (ior A B) (ior A C))  */
  4508.  
  4509.       if (GET_CODE (op0) == NOT && GET_CODE (op1) == XOR)
  4510.     return apply_distributive_law
  4511.       (gen_binary (XOR, mode,
  4512.                gen_binary (IOR, mode, XEXP (op0, 0), XEXP (op1, 0)),
  4513.                gen_binary (IOR, mode, XEXP (op0, 0), XEXP (op1, 1))));
  4514.                                 
  4515.       else if (GET_CODE (op1) == NOT && GET_CODE (op0) == XOR)
  4516.     return apply_distributive_law
  4517.       (gen_binary (XOR, mode,
  4518.                gen_binary (IOR, mode, XEXP (op1, 0), XEXP (op0, 0)),
  4519.                gen_binary (IOR, mode, XEXP (op1, 0), XEXP (op0, 1))));
  4520.       break;
  4521.  
  4522.     case IOR:
  4523.       /* (ior A C) is C if all bits of A that might be nonzero are on in C.  */
  4524.       if (GET_CODE (op1) == CONST_INT
  4525.       && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  4526.       && (nonzero_bits (op0, mode) & ~ INTVAL (op1)) == 0)
  4527.     return op1;
  4528.  
  4529.       /* Convert (A & B) | A to A.  */
  4530.       if (GET_CODE (op0) == AND
  4531.       && (rtx_equal_p (XEXP (op0, 0), op1)
  4532.           || rtx_equal_p (XEXP (op0, 1), op1))
  4533.       && ! side_effects_p (XEXP (op0, 0))
  4534.       && ! side_effects_p (XEXP (op0, 1)))
  4535.     return op1;
  4536.  
  4537.       /* If we have (ior (and A B) C), apply the distributive law and then
  4538.      the inverse distributive law to see if things simplify.  */
  4539.  
  4540.       if (GET_CODE (op0) == AND)
  4541.     {
  4542.       x = apply_distributive_law
  4543.         (gen_binary (AND, mode,
  4544.              gen_binary (IOR, mode, XEXP (op0, 0), op1),
  4545.              gen_binary (IOR, mode, XEXP (op0, 1), op1)));
  4546.  
  4547.       if (GET_CODE (x) != IOR)
  4548.         return x;
  4549.     }
  4550.  
  4551.       if (GET_CODE (op1) == AND)
  4552.     {
  4553.       x = apply_distributive_law
  4554.         (gen_binary (AND, mode,
  4555.              gen_binary (IOR, mode, XEXP (op1, 0), op0),
  4556.              gen_binary (IOR, mode, XEXP (op1, 1), op0)));
  4557.  
  4558.       if (GET_CODE (x) != IOR)
  4559.         return x;
  4560.     }
  4561.  
  4562.       /* Convert (ior (ashift A CX) (lshiftrt A CY)) where CX+CY equals the
  4563.      mode size to (rotate A CX).  */
  4564.  
  4565.       if (((GET_CODE (op0) == ASHIFT && GET_CODE (op1) == LSHIFTRT)
  4566.        || (GET_CODE (op1) == ASHIFT && GET_CODE (op0) == LSHIFTRT))
  4567.       && rtx_equal_p (XEXP (op0, 0), XEXP (op1, 0))
  4568.       && GET_CODE (XEXP (op0, 1)) == CONST_INT
  4569.       && GET_CODE (XEXP (op1, 1)) == CONST_INT
  4570.       && (INTVAL (XEXP (op0, 1)) + INTVAL (XEXP (op1, 1))
  4571.           == GET_MODE_BITSIZE (mode)))
  4572.     return gen_rtx (ROTATE, mode, XEXP (op0, 0),
  4573.             (GET_CODE (op0) == ASHIFT
  4574.              ? XEXP (op0, 1) : XEXP (op1, 1)));
  4575.  
  4576.       /* If OP0 is (ashiftrt (plus ...) C), it might actually be
  4577.      a (sign_extend (plus ...)).  If so, OP1 is a CONST_INT, and the PLUS
  4578.      does not affect any of the bits in OP1, it can really be done
  4579.      as a PLUS and we can associate.  We do this by seeing if OP1
  4580.      can be safely shifted left C bits.  */
  4581.       if (GET_CODE (op1) == CONST_INT && GET_CODE (op0) == ASHIFTRT
  4582.       && GET_CODE (XEXP (op0, 0)) == PLUS
  4583.       && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT
  4584.       && GET_CODE (XEXP (op0, 1)) == CONST_INT
  4585.       && INTVAL (XEXP (op0, 1)) < HOST_BITS_PER_WIDE_INT)
  4586.     {
  4587.       int count = INTVAL (XEXP (op0, 1));
  4588.       HOST_WIDE_INT mask = INTVAL (op1) << count;
  4589.  
  4590.       if (mask >> count == INTVAL (op1)
  4591.           && (mask & nonzero_bits (XEXP (op0, 0), mode)) == 0)
  4592.         {
  4593.           SUBST (XEXP (XEXP (op0, 0), 1),
  4594.              GEN_INT (INTVAL (XEXP (XEXP (op0, 0), 1)) | mask));
  4595.           return op0;
  4596.         }
  4597.     }
  4598.       break;
  4599.  
  4600.     case XOR:
  4601.       /* Convert (XOR (NOT x) (NOT y)) to (XOR x y).
  4602.      Also convert (XOR (NOT x) y) to (NOT (XOR x y)), similarly for
  4603.      (NOT y).  */
  4604.       {
  4605.     int num_negated = 0;
  4606.  
  4607.     if (GET_CODE (op0) == NOT)
  4608.       num_negated++, op0 = XEXP (op0, 0);
  4609.     if (GET_CODE (op1) == NOT)
  4610.       num_negated++, op1 = XEXP (op1, 0);
  4611.  
  4612.     if (num_negated == 2)
  4613.       {
  4614.         SUBST (XEXP (x, 0), op0);
  4615.         SUBST (XEXP (x, 1), op1);
  4616.       }
  4617.     else if (num_negated == 1)
  4618.       return gen_unary (NOT, mode, mode, gen_binary (XOR, mode, op0, op1));
  4619.       }
  4620.  
  4621.       /* Convert (xor (and A B) B) to (and (not A) B).  The latter may
  4622.      correspond to a machine insn or result in further simplifications
  4623.      if B is a constant.  */
  4624.  
  4625.       if (GET_CODE (op0) == AND
  4626.       && rtx_equal_p (XEXP (op0, 1), op1)
  4627.       && ! side_effects_p (op1))
  4628.     return gen_binary (AND, mode,
  4629.                gen_unary (NOT, mode, mode, XEXP (op0, 0)),
  4630.                op1);
  4631.  
  4632.       else if (GET_CODE (op0) == AND
  4633.            && rtx_equal_p (XEXP (op0, 0), op1)
  4634.            && ! side_effects_p (op1))
  4635.     return gen_binary (AND, mode,
  4636.                gen_unary (NOT, mode, mode, XEXP (op0, 1)),
  4637.                op1);
  4638.  
  4639. #if STORE_FLAG_VALUE == 1
  4640.       /* (xor (comparison foo bar) (const_int 1)) can become the reversed
  4641.      comparison.  */
  4642.       if (op1 == const1_rtx
  4643.       && GET_RTX_CLASS (GET_CODE (op0)) == '<'
  4644.       && reversible_comparison_p (op0))
  4645.     return gen_rtx_combine (reverse_condition (GET_CODE (op0)),
  4646.                 mode, XEXP (op0, 0), XEXP (op0, 1));
  4647.  
  4648.       /* (lshiftrt foo C) where C is the number of bits in FOO minus 1
  4649.      is (lt foo (const_int 0)), so we can perform the above
  4650.      simplification.  */
  4651.  
  4652.       if (op1 == const1_rtx
  4653.       && GET_CODE (op0) == LSHIFTRT
  4654.       && GET_CODE (XEXP (op0, 1)) == CONST_INT
  4655.       && INTVAL (XEXP (op0, 1)) == GET_MODE_BITSIZE (mode) - 1)
  4656.     return gen_rtx_combine (GE, mode, XEXP (op0, 0), const0_rtx);
  4657. #endif
  4658.  
  4659.       /* (xor (comparison foo bar) (const_int sign-bit))
  4660.      when STORE_FLAG_VALUE is the sign bit.  */
  4661.       if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  4662.       && (STORE_FLAG_VALUE
  4663.           == (HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (mode) - 1))
  4664.       && op1 == const_true_rtx
  4665.       && GET_RTX_CLASS (GET_CODE (op0)) == '<'
  4666.       && reversible_comparison_p (op0))
  4667.     return gen_rtx_combine (reverse_condition (GET_CODE (op0)),
  4668.                 mode, XEXP (op0, 0), XEXP (op0, 1));
  4669.       break;
  4670.     }
  4671.  
  4672.   return x;
  4673. }
  4674.  
  4675. /* We consider ZERO_EXTRACT, SIGN_EXTRACT, and SIGN_EXTEND as "compound
  4676.    operations" because they can be replaced with two more basic operations.
  4677.    ZERO_EXTEND is also considered "compound" because it can be replaced with
  4678.    an AND operation, which is simpler, though only one operation.
  4679.  
  4680.    The function expand_compound_operation is called with an rtx expression
  4681.    and will convert it to the appropriate shifts and AND operations, 
  4682.    simplifying at each stage.
  4683.  
  4684.    The function make_compound_operation is called to convert an expression
  4685.    consisting of shifts and ANDs into the equivalent compound expression.
  4686.    It is the inverse of this function, loosely speaking.  */
  4687.  
  4688. static rtx
  4689. expand_compound_operation (x)
  4690.      rtx x;
  4691. {
  4692.   int pos = 0, len;
  4693.   int unsignedp = 0;
  4694.   int modewidth;
  4695.   rtx tem;
  4696.  
  4697.   switch (GET_CODE (x))
  4698.     {
  4699.     case ZERO_EXTEND:
  4700.       unsignedp = 1;
  4701.     case SIGN_EXTEND:
  4702.       /* We can't necessarily use a const_int for a multiword mode;
  4703.      it depends on implicitly extending the value.
  4704.      Since we don't know the right way to extend it,
  4705.      we can't tell whether the implicit way is right.
  4706.  
  4707.      Even for a mode that is no wider than a const_int,
  4708.      we can't win, because we need to sign extend one of its bits through
  4709.      the rest of it, and we don't know which bit.  */
  4710.       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
  4711.     return x;
  4712.  
  4713.       /* Return if (subreg:MODE FROM 0) is not a safe replacement for
  4714.      (zero_extend:MODE FROM) or (sign_extend:MODE FROM).  It is for any MEM
  4715.      because (SUBREG (MEM...)) is guaranteed to cause the MEM to be
  4716.      reloaded. If not for that, MEM's would very rarely be safe.
  4717.  
  4718.      Reject MODEs bigger than a word, because we might not be able
  4719.      to reference a two-register group starting with an arbitrary register
  4720.      (and currently gen_lowpart might crash for a SUBREG).  */
  4721.   
  4722.       if (GET_MODE_SIZE (GET_MODE (XEXP (x, 0))) > UNITS_PER_WORD)
  4723.     return x;
  4724.  
  4725.       len = GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)));
  4726.       /* If the inner object has VOIDmode (the only way this can happen
  4727.      is if it is a ASM_OPERANDS), we can't do anything since we don't
  4728.      know how much masking to do.  */
  4729.       if (len == 0)
  4730.     return x;
  4731.  
  4732.       break;
  4733.  
  4734.     case ZERO_EXTRACT:
  4735.       unsignedp = 1;
  4736.     case SIGN_EXTRACT:
  4737.       /* If the operand is a CLOBBER, just return it.  */
  4738.       if (GET_CODE (XEXP (x, 0)) == CLOBBER)
  4739.     return XEXP (x, 0);
  4740.  
  4741.       if (GET_CODE (XEXP (x, 1)) != CONST_INT
  4742.       || GET_CODE (XEXP (x, 2)) != CONST_INT
  4743.       || GET_MODE (XEXP (x, 0)) == VOIDmode)
  4744.     return x;
  4745.  
  4746.       len = INTVAL (XEXP (x, 1));
  4747.       pos = INTVAL (XEXP (x, 2));
  4748.  
  4749.       /* If this goes outside the object being extracted, replace the object
  4750.      with a (use (mem ...)) construct that only combine understands
  4751.      and is used only for this purpose.  */
  4752.       if (len + pos > GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))))
  4753.     SUBST (XEXP (x, 0), gen_rtx (USE, GET_MODE (x), XEXP (x, 0)));
  4754.  
  4755. #if BITS_BIG_ENDIAN
  4756.       pos = GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) - len - pos;
  4757. #endif
  4758.       break;
  4759.  
  4760.     default:
  4761.       return x;
  4762.     }
  4763.  
  4764.   /* If we reach here, we want to return a pair of shifts.  The inner
  4765.      shift is a left shift of BITSIZE - POS - LEN bits.  The outer
  4766.      shift is a right shift of BITSIZE - LEN bits.  It is arithmetic or
  4767.      logical depending on the value of UNSIGNEDP.
  4768.  
  4769.      If this was a ZERO_EXTEND or ZERO_EXTRACT, this pair of shifts will be
  4770.      converted into an AND of a shift.
  4771.  
  4772.      We must check for the case where the left shift would have a negative
  4773.      count.  This can happen in a case like (x >> 31) & 255 on machines
  4774.      that can't shift by a constant.  On those machines, we would first
  4775.      combine the shift with the AND to produce a variable-position 
  4776.      extraction.  Then the constant of 31 would be substituted in to produce
  4777.      a such a position.  */
  4778.  
  4779.   modewidth = GET_MODE_BITSIZE (GET_MODE (x));
  4780.   if (modewidth >= pos - len)
  4781.     tem = simplify_shift_const (NULL_RTX, unsignedp ? LSHIFTRT : ASHIFTRT,
  4782.                 GET_MODE (x),
  4783.                 simplify_shift_const (NULL_RTX, ASHIFT,
  4784.                               GET_MODE (x),
  4785.                               XEXP (x, 0),
  4786.                               modewidth - pos - len),
  4787.                 modewidth - len);
  4788.  
  4789.   else if (unsignedp && len < HOST_BITS_PER_WIDE_INT)
  4790.     tem = simplify_and_const_int (NULL_RTX, GET_MODE (x),
  4791.                   simplify_shift_const (NULL_RTX, LSHIFTRT,
  4792.                             GET_MODE (x),
  4793.                             XEXP (x, 0), pos),
  4794.                   ((HOST_WIDE_INT) 1 << len) - 1);
  4795.   else
  4796.     /* Any other cases we can't handle.  */
  4797.     return x;
  4798.     
  4799.  
  4800.   /* If we couldn't do this for some reason, return the original
  4801.      expression.  */
  4802.   if (GET_CODE (tem) == CLOBBER)
  4803.     return x;
  4804.  
  4805.   return tem;
  4806. }
  4807.  
  4808. /* X is a SET which contains an assignment of one object into
  4809.    a part of another (such as a bit-field assignment, STRICT_LOW_PART,
  4810.    or certain SUBREGS). If possible, convert it into a series of
  4811.    logical operations.
  4812.  
  4813.    We half-heartedly support variable positions, but do not at all
  4814.    support variable lengths.  */
  4815.  
  4816. static rtx
  4817. expand_field_assignment (x)
  4818.      rtx x;
  4819. {
  4820.   rtx inner;
  4821.   rtx pos;            /* Always counts from low bit. */
  4822.   int len;
  4823.   rtx mask;
  4824.   enum machine_mode compute_mode;
  4825.  
  4826.   /* Loop until we find something we can't simplify.  */
  4827.   while (1)
  4828.     {
  4829.       if (GET_CODE (SET_DEST (x)) == STRICT_LOW_PART
  4830.       && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG)
  4831.     {
  4832.       inner = SUBREG_REG (XEXP (SET_DEST (x), 0));
  4833.       len = GET_MODE_BITSIZE (GET_MODE (XEXP (SET_DEST (x), 0)));
  4834.       pos = const0_rtx;
  4835.     }
  4836.       else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
  4837.            && GET_CODE (XEXP (SET_DEST (x), 1)) == CONST_INT)
  4838.     {
  4839.       inner = XEXP (SET_DEST (x), 0);
  4840.       len = INTVAL (XEXP (SET_DEST (x), 1));
  4841.       pos = XEXP (SET_DEST (x), 2);
  4842.  
  4843.       /* If the position is constant and spans the width of INNER,
  4844.          surround INNER  with a USE to indicate this.  */
  4845.       if (GET_CODE (pos) == CONST_INT
  4846.           && INTVAL (pos) + len > GET_MODE_BITSIZE (GET_MODE (inner)))
  4847.         inner = gen_rtx (USE, GET_MODE (SET_DEST (x)), inner);
  4848.  
  4849. #if BITS_BIG_ENDIAN
  4850.       if (GET_CODE (pos) == CONST_INT)
  4851.         pos = GEN_INT (GET_MODE_BITSIZE (GET_MODE (inner)) - len
  4852.                - INTVAL (pos));
  4853.       else if (GET_CODE (pos) == MINUS
  4854.            && GET_CODE (XEXP (pos, 1)) == CONST_INT
  4855.            && (INTVAL (XEXP (pos, 1))
  4856.                == GET_MODE_BITSIZE (GET_MODE (inner)) - len))
  4857.         /* If position is ADJUST - X, new position is X.  */
  4858.         pos = XEXP (pos, 0);
  4859.       else
  4860.         pos = gen_binary (MINUS, GET_MODE (pos),
  4861.                   GEN_INT (GET_MODE_BITSIZE (GET_MODE (inner))
  4862.                        - len),
  4863.                   pos);
  4864. #endif
  4865.     }
  4866.  
  4867.       /* A SUBREG between two modes that occupy the same numbers of words
  4868.      can be done by moving the SUBREG to the source.  */
  4869.       else if (GET_CODE (SET_DEST (x)) == SUBREG
  4870.            && (((GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
  4871.              + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
  4872.            == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (x))))
  4873.             + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
  4874.     {
  4875.       x = gen_rtx (SET, VOIDmode, SUBREG_REG (SET_DEST (x)),
  4876.                gen_lowpart_for_combine (GET_MODE (SUBREG_REG (SET_DEST (x))),
  4877.                         SET_SRC (x)));
  4878.       continue;
  4879.     }
  4880.       else
  4881.     break;
  4882.  
  4883.       while (GET_CODE (inner) == SUBREG && subreg_lowpart_p (inner))
  4884.     inner = SUBREG_REG (inner);
  4885.  
  4886.       compute_mode = GET_MODE (inner);
  4887.  
  4888.       /* Compute a mask of LEN bits, if we can do this on the host machine.  */
  4889.       if (len < HOST_BITS_PER_WIDE_INT)
  4890.     mask = GEN_INT (((HOST_WIDE_INT) 1 << len) - 1);
  4891.       else
  4892.     break;
  4893.  
  4894.       /* Now compute the equivalent expression.  Make a copy of INNER
  4895.      for the SET_DEST in case it is a MEM into which we will substitute;
  4896.      we don't want shared RTL in that case.  */
  4897.       x = gen_rtx (SET, VOIDmode, copy_rtx (inner),
  4898.            gen_binary (IOR, compute_mode,
  4899.                    gen_binary (AND, compute_mode,
  4900.                        gen_unary (NOT, compute_mode,
  4901.                               compute_mode,
  4902.                               gen_binary (ASHIFT,
  4903.                                   compute_mode,
  4904.                                   mask, pos)),
  4905.                        inner),
  4906.                    gen_binary (ASHIFT, compute_mode,
  4907.                        gen_binary (AND, compute_mode,
  4908.                                gen_lowpart_for_combine
  4909.                                (compute_mode,
  4910.                             SET_SRC (x)),
  4911.                                mask),
  4912.                        pos)));
  4913.     }
  4914.  
  4915.   return x;
  4916. }
  4917.  
  4918. /* Return an RTX for a reference to LEN bits of INNER.  If POS_RTX is nonzero,
  4919.    it is an RTX that represents a variable starting position; otherwise,
  4920.    POS is the (constant) starting bit position (counted from the LSB).
  4921.  
  4922.    INNER may be a USE.  This will occur when we started with a bitfield
  4923.    that went outside the boundary of the object in memory, which is
  4924.    allowed on most machines.  To isolate this case, we produce a USE
  4925.    whose mode is wide enough and surround the MEM with it.  The only
  4926.    code that understands the USE is this routine.  If it is not removed,
  4927.    it will cause the resulting insn not to match.
  4928.  
  4929.    UNSIGNEDP is non-zero for an unsigned reference and zero for a 
  4930.    signed reference.
  4931.  
  4932.    IN_DEST is non-zero if this is a reference in the destination of a
  4933.    SET.  This is used when a ZERO_ or SIGN_EXTRACT isn't needed.  If non-zero,
  4934.    a STRICT_LOW_PART will be used, if zero, ZERO_EXTEND or SIGN_EXTEND will
  4935.    be used.
  4936.  
  4937.    IN_COMPARE is non-zero if we are in a COMPARE.  This means that a
  4938.    ZERO_EXTRACT should be built even for bits starting at bit 0.
  4939.  
  4940.    MODE is the desired mode of the result (if IN_DEST == 0).  */
  4941.  
  4942. static rtx
  4943. make_extraction (mode, inner, pos, pos_rtx, len,
  4944.          unsignedp, in_dest, in_compare)
  4945.      enum machine_mode mode;
  4946.      rtx inner;
  4947.      int pos;
  4948.      rtx pos_rtx;
  4949.      int len;
  4950.      int unsignedp;
  4951.      int in_dest, in_compare;
  4952. {
  4953.   /* This mode describes the size of the storage area
  4954.      to fetch the overall value from.  Within that, we
  4955.      ignore the POS lowest bits, etc.  */
  4956.   enum machine_mode is_mode = GET_MODE (inner);
  4957.   enum machine_mode inner_mode;
  4958.   enum machine_mode wanted_mem_mode = byte_mode;
  4959.   enum machine_mode pos_mode = word_mode;
  4960.   enum machine_mode extraction_mode = word_mode;
  4961.   enum machine_mode tmode = mode_for_size (len, MODE_INT, 1);
  4962.   int spans_byte = 0;
  4963.   rtx new = 0;
  4964.   rtx orig_pos_rtx = pos_rtx;
  4965.   int orig_pos;
  4966.  
  4967.   /* Get some information about INNER and get the innermost object.  */
  4968.   if (GET_CODE (inner) == USE)
  4969.     /* (use:SI (mem:QI foo)) stands for (mem:SI foo).  */
  4970.     /* We don't need to adjust the position because we set up the USE
  4971.        to pretend that it was a full-word object.  */
  4972.     spans_byte = 1, inner = XEXP (inner, 0);
  4973.   else if (GET_CODE (inner) == SUBREG && subreg_lowpart_p (inner))
  4974.     {
  4975.       /* If going from (subreg:SI (mem:QI ...)) to (mem:QI ...),
  4976.      consider just the QI as the memory to extract from.
  4977.      The subreg adds or removes high bits; its mode is
  4978.      irrelevant to the meaning of this extraction,
  4979.      since POS and LEN count from the lsb.  */
  4980.       if (GET_CODE (SUBREG_REG (inner)) == MEM)
  4981.     is_mode = GET_MODE (SUBREG_REG (inner));
  4982.       inner = SUBREG_REG (inner);
  4983.     }
  4984.  
  4985.   inner_mode = GET_MODE (inner);
  4986.  
  4987.   if (pos_rtx && GET_CODE (pos_rtx) == CONST_INT)
  4988.     pos = INTVAL (pos_rtx), pos_rtx = 0;
  4989.  
  4990.   /* See if this can be done without an extraction.  We never can if the
  4991.      width of the field is not the same as that of some integer mode. For
  4992.      registers, we can only avoid the extraction if the position is at the
  4993.      low-order bit and this is either not in the destination or we have the
  4994.      appropriate STRICT_LOW_PART operation available.
  4995.  
  4996.      For MEM, we can avoid an extract if the field starts on an appropriate
  4997.      boundary and we can change the mode of the memory reference.  However,
  4998.      we cannot directly access the MEM if we have a USE and the underlying
  4999.      MEM is not TMODE.  This combination means that MEM was being used in a
  5000.      context where bits outside its mode were being referenced; that is only
  5001.      valid in bit-field insns.  */
  5002.  
  5003.   if (tmode != BLKmode
  5004.       && ! (spans_byte && inner_mode != tmode)
  5005.       && ((pos_rtx == 0 && pos == 0 && GET_CODE (inner) != MEM
  5006.        && (! in_dest
  5007.            || (GET_CODE (inner) == REG
  5008.            && (movstrict_optab->handlers[(int) tmode].insn_code
  5009.                != CODE_FOR_nothing))))
  5010.       || (GET_CODE (inner) == MEM && pos_rtx == 0
  5011.           && (pos
  5012.           % (STRICT_ALIGNMENT ? GET_MODE_ALIGNMENT (tmode)
  5013.              : BITS_PER_UNIT)) == 0
  5014.           /* We can't do this if we are widening INNER_MODE (it
  5015.          may not be aligned, for one thing).  */
  5016.           && GET_MODE_BITSIZE (inner_mode) >= GET_MODE_BITSIZE (tmode)
  5017.           && (inner_mode == tmode
  5018.           || (! mode_dependent_address_p (XEXP (inner, 0))
  5019.               && ! MEM_VOLATILE_P (inner))))))
  5020.     {
  5021.       /* If INNER is a MEM, make a new MEM that encompasses just the desired
  5022.      field.  If the original and current mode are the same, we need not
  5023.      adjust the offset.  Otherwise, we do if bytes big endian.  
  5024.  
  5025.      If INNER is not a MEM, get a piece consisting of the just the field
  5026.      of interest (in this case POS must be 0).  */
  5027.  
  5028.       if (GET_CODE (inner) == MEM)
  5029.     {
  5030.       int offset;
  5031.       /* POS counts from lsb, but make OFFSET count in memory order.  */
  5032.       if (BYTES_BIG_ENDIAN)
  5033.         offset = (GET_MODE_BITSIZE (is_mode) - len - pos) / BITS_PER_UNIT;
  5034.       else
  5035.         offset = pos / BITS_PER_UNIT;
  5036.  
  5037.       new = gen_rtx (MEM, tmode, plus_constant (XEXP (inner, 0), offset));
  5038.       RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (inner);
  5039.       MEM_VOLATILE_P (new) = MEM_VOLATILE_P (inner);
  5040.       MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (inner);
  5041.     }
  5042.       else if (GET_CODE (inner) == REG)
  5043.     {
  5044.       /* We can't call gen_lowpart_for_combine here since we always want
  5045.          a SUBREG and it would sometimes return a new hard register.  */
  5046.       if (tmode != inner_mode)
  5047.         new = gen_rtx (SUBREG, tmode, inner,
  5048.                (WORDS_BIG_ENDIAN
  5049.                 && GET_MODE_SIZE (inner_mode) > UNITS_PER_WORD
  5050.                 ? ((GET_MODE_SIZE (inner_mode)
  5051.                 - GET_MODE_SIZE (tmode))
  5052.                    / UNITS_PER_WORD)
  5053.                 : 0));
  5054.       else
  5055.         new = inner;
  5056.     }
  5057.       else
  5058.     new = force_to_mode (inner, tmode,
  5059.                  len >= HOST_BITS_PER_WIDE_INT
  5060.                  ? GET_MODE_MASK (tmode)
  5061.                  : ((HOST_WIDE_INT) 1 << len) - 1,
  5062.                  NULL_RTX, 0);
  5063.  
  5064.       /* If this extraction is going into the destination of a SET, 
  5065.      make a STRICT_LOW_PART unless we made a MEM.  */
  5066.  
  5067.       if (in_dest)
  5068.     return (GET_CODE (new) == MEM ? new
  5069.         : (GET_CODE (new) != SUBREG
  5070.            ? gen_rtx (CLOBBER, tmode, const0_rtx)
  5071.            : gen_rtx_combine (STRICT_LOW_PART, VOIDmode, new)));
  5072.  
  5073.       /* Otherwise, sign- or zero-extend unless we already are in the
  5074.      proper mode.  */
  5075.  
  5076.       return (mode == tmode ? new
  5077.           : gen_rtx_combine (unsignedp ? ZERO_EXTEND : SIGN_EXTEND,
  5078.                  mode, new));
  5079.     }
  5080.  
  5081.   /* Unless this is a COMPARE or we have a funny memory reference,
  5082.      don't do anything with zero-extending field extracts starting at
  5083.      the low-order bit since they are simple AND operations.  */
  5084.   if (pos_rtx == 0 && pos == 0 && ! in_dest
  5085.       && ! in_compare && ! spans_byte && unsignedp)
  5086.     return 0;
  5087.  
  5088.   /* Unless we are allowed to span bytes, reject this if we would be
  5089.      spanning bytes or if the position is not a constant and the length
  5090.      is not 1.  In all other cases, we would only be going outside
  5091.      out object in cases when an original shift would have been
  5092.      undefined.  */
  5093.   if (! spans_byte
  5094.       && ((pos_rtx == 0 && pos + len > GET_MODE_BITSIZE (is_mode))
  5095.       || (pos_rtx != 0 && len != 1)))
  5096.     return 0;
  5097.  
  5098.   /* Get the mode to use should INNER be a MEM, the mode for the position,
  5099.      and the mode for the result.  */
  5100. #ifdef HAVE_insv
  5101.   if (in_dest)
  5102.     {
  5103.       wanted_mem_mode = insn_operand_mode[(int) CODE_FOR_insv][0];
  5104.       pos_mode = insn_operand_mode[(int) CODE_FOR_insv][2];
  5105.       extraction_mode = insn_operand_mode[(int) CODE_FOR_insv][3];
  5106.     }
  5107. #endif
  5108.  
  5109. #ifdef HAVE_extzv
  5110.   if (! in_dest && unsignedp)
  5111.     {
  5112.       wanted_mem_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
  5113.       pos_mode = insn_operand_mode[(int) CODE_FOR_extzv][3];
  5114.       extraction_mode = insn_operand_mode[(int) CODE_FOR_extzv][0];
  5115.     }
  5116. #endif
  5117.  
  5118. #ifdef HAVE_extv
  5119.   if (! in_dest && ! unsignedp)
  5120.     {
  5121.       wanted_mem_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
  5122.       pos_mode = insn_operand_mode[(int) CODE_FOR_extv][3];
  5123.       extraction_mode = insn_operand_mode[(int) CODE_FOR_extv][0];
  5124.     }
  5125. #endif
  5126.  
  5127.   /* Never narrow an object, since that might not be safe.  */
  5128.  
  5129.   if (mode != VOIDmode
  5130.       && GET_MODE_SIZE (extraction_mode) < GET_MODE_SIZE (mode))
  5131.     extraction_mode = mode;
  5132.  
  5133.   if (pos_rtx && GET_MODE (pos_rtx) != VOIDmode
  5134.       && GET_MODE_SIZE (pos_mode) < GET_MODE_SIZE (GET_MODE (pos_rtx)))
  5135.     pos_mode = GET_MODE (pos_rtx);
  5136.  
  5137.   /* If this is not from memory or we have to change the mode of memory and
  5138.      cannot, the desired mode is EXTRACTION_MODE.  */
  5139.   if (GET_CODE (inner) != MEM
  5140.       || (inner_mode != wanted_mem_mode
  5141.       && (mode_dependent_address_p (XEXP (inner, 0))
  5142.           || MEM_VOLATILE_P (inner))))
  5143.     wanted_mem_mode = extraction_mode;
  5144.  
  5145.   orig_pos = pos;
  5146.  
  5147. #if BITS_BIG_ENDIAN
  5148.   /* If position is constant, compute new position.  Otherwise, build
  5149.      subtraction.  */
  5150.   if (pos_rtx == 0)
  5151.     pos = (MAX (GET_MODE_BITSIZE (is_mode), GET_MODE_BITSIZE (wanted_mem_mode))
  5152.        - len - pos);
  5153.   else
  5154.     pos_rtx
  5155.       = gen_rtx_combine (MINUS, GET_MODE (pos_rtx),
  5156.              GEN_INT (MAX (GET_MODE_BITSIZE (is_mode),
  5157.                        GET_MODE_BITSIZE (wanted_mem_mode))
  5158.                   - len),
  5159.              pos_rtx);
  5160. #endif
  5161.  
  5162.   /* If INNER has a wider mode, make it smaller.  If this is a constant
  5163.      extract, try to adjust the byte to point to the byte containing
  5164.      the value.  */
  5165.   if (wanted_mem_mode != VOIDmode
  5166.       && GET_MODE_SIZE (wanted_mem_mode) < GET_MODE_SIZE (is_mode)
  5167.       && ((GET_CODE (inner) == MEM
  5168.        && (inner_mode == wanted_mem_mode
  5169.            || (! mode_dependent_address_p (XEXP (inner, 0))
  5170.            && ! MEM_VOLATILE_P (inner))))))
  5171.     {
  5172.       int offset = 0;
  5173.  
  5174.       /* The computations below will be correct if the machine is big
  5175.      endian in both bits and bytes or little endian in bits and bytes.
  5176.      If it is mixed, we must adjust.  */
  5177.          
  5178.       /* If bytes are big endian and we had a paradoxical SUBREG, we must
  5179.      adjust OFFSET to compensate. */
  5180. #if BYTES_BIG_ENDIAN
  5181.       if (! spans_byte
  5182.       && GET_MODE_SIZE (inner_mode) < GET_MODE_SIZE (is_mode))
  5183.     offset -= GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (inner_mode);
  5184. #endif
  5185.  
  5186.       /* If this is a constant position, we can move to the desired byte.  */
  5187.       if (pos_rtx == 0)
  5188.     {
  5189.       offset += pos / BITS_PER_UNIT;
  5190.       pos %= GET_MODE_BITSIZE (wanted_mem_mode);
  5191.     }
  5192.  
  5193. #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
  5194.       if (! spans_byte && is_mode != wanted_mem_mode)
  5195.     offset = (GET_MODE_SIZE (is_mode)
  5196.           - GET_MODE_SIZE (wanted_mem_mode) - offset);
  5197. #endif
  5198.  
  5199.       if (offset != 0 || inner_mode != wanted_mem_mode)
  5200.     {
  5201.       rtx newmem = gen_rtx (MEM, wanted_mem_mode,
  5202.                 plus_constant (XEXP (inner, 0), offset));
  5203.       RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (inner);
  5204.       MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (inner);
  5205.       MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (inner);
  5206.       inner = newmem;
  5207.     }
  5208.     }
  5209.  
  5210.   /* If INNER is not memory, we can always get it into the proper mode. */
  5211.   else if (GET_CODE (inner) != MEM)
  5212.     inner = force_to_mode (inner, extraction_mode,
  5213.                pos_rtx || len + orig_pos >= HOST_BITS_PER_WIDE_INT
  5214.                ? GET_MODE_MASK (extraction_mode)
  5215.                : (((HOST_WIDE_INT) 1 << len) - 1) << orig_pos,
  5216.                NULL_RTX, 0);
  5217.  
  5218.   /* Adjust mode of POS_RTX, if needed.  If we want a wider mode, we
  5219.      have to zero extend.  Otherwise, we can just use a SUBREG.  */
  5220.   if (pos_rtx != 0
  5221.       && GET_MODE_SIZE (pos_mode) > GET_MODE_SIZE (GET_MODE (pos_rtx)))
  5222.     pos_rtx = gen_rtx_combine (ZERO_EXTEND, pos_mode, pos_rtx);
  5223.   else if (pos_rtx != 0
  5224.        && GET_MODE_SIZE (pos_mode) < GET_MODE_SIZE (GET_MODE (pos_rtx)))
  5225.     pos_rtx = gen_lowpart_for_combine (pos_mode, pos_rtx);
  5226.  
  5227.   /* Make POS_RTX unless we already have it and it is correct.  If we don't
  5228.      have a POS_RTX but we do have an ORIG_POS_RTX, the latter must
  5229.      be a CONST_INT. */
  5230.   if (pos_rtx == 0 && orig_pos_rtx != 0 && INTVAL (orig_pos_rtx) == pos)
  5231.     pos_rtx = orig_pos_rtx;
  5232.  
  5233.   else if (pos_rtx == 0)
  5234.     pos_rtx = GEN_INT (pos);
  5235.  
  5236.   /* Make the required operation.  See if we can use existing rtx.  */
  5237.   new = gen_rtx_combine (unsignedp ? ZERO_EXTRACT : SIGN_EXTRACT,
  5238.              extraction_mode, inner, GEN_INT (len), pos_rtx);
  5239.   if (! in_dest)
  5240.     new = gen_lowpart_for_combine (mode, new);
  5241.  
  5242.   return new;
  5243. }
  5244.  
  5245. /* See if X contains an ASHIFT of COUNT or more bits that can be commuted
  5246.    with any other operations in X.  Return X without that shift if so.  */
  5247.  
  5248. static rtx
  5249. extract_left_shift (x, count)
  5250.      rtx x;
  5251.      int count;
  5252. {
  5253.   enum rtx_code code = GET_CODE (x);
  5254.   enum machine_mode mode = GET_MODE (x);
  5255.   rtx tem;
  5256.  
  5257.   switch (code)
  5258.     {
  5259.     case ASHIFT:
  5260.       /* This is the shift itself.  If it is wide enough, we will return
  5261.      either the value being shifted if the shift count is equal to
  5262.      COUNT or a shift for the difference.  */
  5263.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  5264.       && INTVAL (XEXP (x, 1)) >= count)
  5265.     return simplify_shift_const (NULL_RTX, ASHIFT, mode, XEXP (x, 0),
  5266.                      INTVAL (XEXP (x, 1)) - count);
  5267.       break;
  5268.  
  5269.     case NEG:  case NOT:
  5270.       if ((tem = extract_left_shift (XEXP (x, 0), count)) != 0)
  5271.     return gen_unary (code, mode, mode, tem);
  5272.  
  5273.       break;
  5274.  
  5275.     case PLUS:  case IOR:  case XOR:  case AND:
  5276.       /* If we can safely shift this constant and we find the inner shift,
  5277.      make a new operation.  */
  5278.       if (GET_CODE (XEXP (x,1)) == CONST_INT
  5279.       && (INTVAL (XEXP (x, 1)) & (((HOST_WIDE_INT) 1 << count)) - 1) == 0
  5280.       && (tem = extract_left_shift (XEXP (x, 0), count)) != 0)
  5281.     return gen_binary (code, mode, tem, 
  5282.                GEN_INT (INTVAL (XEXP (x, 1)) >> count));
  5283.  
  5284.       break;
  5285.     }
  5286.  
  5287.   return 0;
  5288. }
  5289.  
  5290. /* Look at the expression rooted at X.  Look for expressions
  5291.    equivalent to ZERO_EXTRACT, SIGN_EXTRACT, ZERO_EXTEND, SIGN_EXTEND.
  5292.    Form these expressions.
  5293.  
  5294.    Return the new rtx, usually just X.
  5295.  
  5296.    Also, for machines like the Vax that don't have logical shift insns,
  5297.    try to convert logical to arithmetic shift operations in cases where
  5298.    they are equivalent.  This undoes the canonicalizations to logical
  5299.    shifts done elsewhere.
  5300.  
  5301.    We try, as much as possible, to re-use rtl expressions to save memory.
  5302.  
  5303.    IN_CODE says what kind of expression we are processing.  Normally, it is
  5304.    SET.  In a memory address (inside a MEM, PLUS or minus, the latter two
  5305.    being kludges), it is MEM.  When processing the arguments of a comparison
  5306.    or a COMPARE against zero, it is COMPARE.  */
  5307.  
  5308. static rtx
  5309. make_compound_operation (x, in_code)
  5310.      rtx x;
  5311.      enum rtx_code in_code;
  5312. {
  5313.   enum rtx_code code = GET_CODE (x);
  5314.   enum machine_mode mode = GET_MODE (x);
  5315.   int mode_width = GET_MODE_BITSIZE (mode);
  5316.   rtx rhs, lhs;
  5317.   enum rtx_code next_code;
  5318.   int i;
  5319.   rtx new = 0;
  5320.   rtx tem;
  5321.   char *fmt;
  5322.  
  5323.   /* Select the code to be used in recursive calls.  Once we are inside an
  5324.      address, we stay there.  If we have a comparison, set to COMPARE,
  5325.      but once inside, go back to our default of SET.  */
  5326.  
  5327.   next_code = (code == MEM || code == PLUS || code == MINUS ? MEM
  5328.            : ((code == COMPARE || GET_RTX_CLASS (code) == '<')
  5329.           && XEXP (x, 1) == const0_rtx) ? COMPARE
  5330.            : in_code == COMPARE ? SET : in_code);
  5331.  
  5332.   /* Process depending on the code of this operation.  If NEW is set
  5333.      non-zero, it will be returned.  */
  5334.  
  5335.   switch (code)
  5336.     {
  5337.     case ASHIFT:
  5338.       /* Convert shifts by constants into multiplications if inside
  5339.      an address.  */
  5340.       if (in_code == MEM && GET_CODE (XEXP (x, 1)) == CONST_INT
  5341.       && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT
  5342.       && INTVAL (XEXP (x, 1)) >= 0)
  5343.     {
  5344.       new = make_compound_operation (XEXP (x, 0), next_code);
  5345.       new = gen_rtx_combine (MULT, mode, new,
  5346.                  GEN_INT ((HOST_WIDE_INT) 1
  5347.                       << INTVAL (XEXP (x, 1))));
  5348.     }
  5349.       break;
  5350.  
  5351.     case AND:
  5352.       /* If the second operand is not a constant, we can't do anything
  5353.      with it.  */
  5354.       if (GET_CODE (XEXP (x, 1)) != CONST_INT)
  5355.     break;
  5356.  
  5357.       /* If the constant is a power of two minus one and the first operand
  5358.      is a logical right shift, make an extraction.  */
  5359.       if (GET_CODE (XEXP (x, 0)) == LSHIFTRT
  5360.       && (i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0)
  5361.     {
  5362.       new = make_compound_operation (XEXP (XEXP (x, 0), 0), next_code);
  5363.       new = make_extraction (mode, new, 0, XEXP (XEXP (x, 0), 1), i, 1,
  5364.                  0, in_code == COMPARE);
  5365.     }
  5366.  
  5367.       /* Same as previous, but for (subreg (lshiftrt ...)) in first op.  */
  5368.       else if (GET_CODE (XEXP (x, 0)) == SUBREG
  5369.            && subreg_lowpart_p (XEXP (x, 0))
  5370.            && GET_CODE (SUBREG_REG (XEXP (x, 0))) == LSHIFTRT
  5371.            && (i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0)
  5372.     {
  5373.       new = make_compound_operation (XEXP (SUBREG_REG (XEXP (x, 0)), 0),
  5374.                      next_code);
  5375.       new = make_extraction (mode, new, 0,
  5376.                  XEXP (SUBREG_REG (XEXP (x, 0)), 1), i, 1,
  5377.                  0, in_code == COMPARE);
  5378.     }
  5379.       /* Same as previous, but for (xor/ior (lshiftrt...) (lshiftrt...)).  */
  5380.       else if ((GET_CODE (XEXP (x, 0)) == XOR
  5381.         || GET_CODE (XEXP (x, 0)) == IOR)
  5382.            && GET_CODE (XEXP (XEXP (x, 0), 0)) == LSHIFTRT
  5383.            && GET_CODE (XEXP (XEXP (x, 0), 1)) == LSHIFTRT
  5384.            && (i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0)
  5385.     {
  5386.       /* Apply the distributive law, and then try to make extractions.  */
  5387.       new = gen_rtx_combine (GET_CODE (XEXP (x, 0)), mode,
  5388.                  gen_rtx (AND, mode, XEXP (XEXP (x, 0), 0),
  5389.                       XEXP (x, 1)),
  5390.                  gen_rtx (AND, mode, XEXP (XEXP (x, 0), 1),
  5391.                       XEXP (x, 1)));
  5392.       new = make_compound_operation (new, in_code);
  5393.     }
  5394.  
  5395.       /* If we are have (and (rotate X C) M) and C is larger than the number
  5396.      of bits in M, this is an extraction.  */
  5397.  
  5398.       else if (GET_CODE (XEXP (x, 0)) == ROTATE
  5399.            && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  5400.            && (i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0
  5401.            && i <= INTVAL (XEXP (XEXP (x, 0), 1)))
  5402.     {
  5403.       new = make_compound_operation (XEXP (XEXP (x, 0), 0), next_code);
  5404.       new = make_extraction (mode, new,
  5405.                  (GET_MODE_BITSIZE (mode)
  5406.                   - INTVAL (XEXP (XEXP (x, 0), 1))),
  5407.                  NULL_RTX, i, 1, 0, in_code == COMPARE);
  5408.     }
  5409.  
  5410.       /* On machines without logical shifts, if the operand of the AND is
  5411.      a logical shift and our mask turns off all the propagated sign
  5412.      bits, we can replace the logical shift with an arithmetic shift.  */
  5413.       else if (ashr_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing
  5414.            && (lshr_optab->handlers[(int) mode].insn_code
  5415.            == CODE_FOR_nothing)
  5416.            && GET_CODE (XEXP (x, 0)) == LSHIFTRT
  5417.            && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  5418.            && INTVAL (XEXP (XEXP (x, 0), 1)) >= 0
  5419.            && INTVAL (XEXP (XEXP (x, 0), 1)) < HOST_BITS_PER_WIDE_INT
  5420.            && mode_width <= HOST_BITS_PER_WIDE_INT)
  5421.     {
  5422.       unsigned HOST_WIDE_INT mask = GET_MODE_MASK (mode);
  5423.  
  5424.       mask >>= INTVAL (XEXP (XEXP (x, 0), 1));
  5425.       if ((INTVAL (XEXP (x, 1)) & ~mask) == 0)
  5426.         SUBST (XEXP (x, 0),
  5427.            gen_rtx_combine (ASHIFTRT, mode,
  5428.                     make_compound_operation (XEXP (XEXP (x, 0), 0),
  5429.                                  next_code),
  5430.                     XEXP (XEXP (x, 0), 1)));
  5431.     }
  5432.  
  5433.       /* If the constant is one less than a power of two, this might be
  5434.      representable by an extraction even if no shift is present.
  5435.      If it doesn't end up being a ZERO_EXTEND, we will ignore it unless
  5436.      we are in a COMPARE.  */
  5437.       else if ((i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0)
  5438.     new = make_extraction (mode,
  5439.                    make_compound_operation (XEXP (x, 0),
  5440.                             next_code),
  5441.                    0, NULL_RTX, i, 1, 0, in_code == COMPARE);
  5442.  
  5443.       /* If we are in a comparison and this is an AND with a power of two,
  5444.      convert this into the appropriate bit extract.  */
  5445.       else if (in_code == COMPARE
  5446.            && (i = exact_log2 (INTVAL (XEXP (x, 1)))) >= 0)
  5447.     new = make_extraction (mode,
  5448.                    make_compound_operation (XEXP (x, 0),
  5449.                             next_code),
  5450.                    i, NULL_RTX, 1, 1, 0, 1);
  5451.  
  5452.       break;
  5453.  
  5454.     case LSHIFTRT:
  5455.       /* If the sign bit is known to be zero, replace this with an
  5456.      arithmetic shift.  */
  5457.       if (ashr_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing
  5458.       && lshr_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing
  5459.       && mode_width <= HOST_BITS_PER_WIDE_INT
  5460.       && (nonzero_bits (XEXP (x, 0), mode) & (1 << (mode_width - 1))) == 0)
  5461.     {
  5462.       new = gen_rtx_combine (ASHIFTRT, mode,
  5463.                  make_compound_operation (XEXP (x, 0),
  5464.                               next_code),
  5465.                  XEXP (x, 1));
  5466.       break;
  5467.     }
  5468.  
  5469.       /* ... fall through ... */
  5470.  
  5471.     case ASHIFTRT:
  5472.       lhs = XEXP (x, 0);
  5473.       rhs = XEXP (x, 1);
  5474.  
  5475.       /* If we have (ashiftrt (ashift foo C1) C2) with C2 >= C1,
  5476.      this is a SIGN_EXTRACT.  */
  5477.       if (GET_CODE (rhs) == CONST_INT
  5478.       && GET_CODE (lhs) == ASHIFT
  5479.       && GET_CODE (XEXP (lhs, 1)) == CONST_INT
  5480.       && INTVAL (rhs) >= INTVAL (XEXP (lhs, 1)))
  5481.     {
  5482.       new = make_compound_operation (XEXP (lhs, 0), next_code);
  5483.       new = make_extraction (mode, new,
  5484.                  INTVAL (rhs) - INTVAL (XEXP (lhs, 1)),
  5485.                  NULL_RTX, mode_width - INTVAL (rhs),
  5486.                  code == LSHIFTRT, 0, in_code == COMPARE);
  5487.     }
  5488.  
  5489.       /* See if we have operations between an ASHIFTRT and an ASHIFT.
  5490.      If so, try to merge the shifts into a SIGN_EXTEND.  We could
  5491.      also do this for some cases of SIGN_EXTRACT, but it doesn't
  5492.      seem worth the effort; the case checked for occurs on Alpha.  */
  5493.       
  5494.       if (GET_RTX_CLASS (GET_CODE (lhs)) != 'o'
  5495.       && ! (GET_CODE (lhs) == SUBREG
  5496.         && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (lhs))) == 'o'))
  5497.       && GET_CODE (rhs) == CONST_INT
  5498.       && INTVAL (rhs) < HOST_BITS_PER_WIDE_INT
  5499.       && (new = extract_left_shift (lhs, INTVAL (rhs))) != 0)
  5500.     new = make_extraction (mode, make_compound_operation (new, next_code),
  5501.                    0, NULL_RTX, mode_width - INTVAL (rhs),
  5502.                    code == LSHIFTRT, 0, in_code == COMPARE);
  5503.     
  5504.       break;
  5505.  
  5506.     case SUBREG:
  5507.       /* Call ourselves recursively on the inner expression.  If we are
  5508.      narrowing the object and it has a different RTL code from
  5509.      what it originally did, do this SUBREG as a force_to_mode.  */
  5510.  
  5511.       tem = make_compound_operation (SUBREG_REG (x), in_code);
  5512.       if (GET_CODE (tem) != GET_CODE (SUBREG_REG (x))
  5513.       && GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (tem))
  5514.       && subreg_lowpart_p (x))
  5515.     {
  5516.       rtx newer = force_to_mode (tem, mode,
  5517.                      GET_MODE_MASK (mode), NULL_RTX, 0);
  5518.  
  5519.       /* If we have something other than a SUBREG, we might have
  5520.          done an expansion, so rerun outselves.  */
  5521.       if (GET_CODE (newer) != SUBREG)
  5522.         newer = make_compound_operation (newer, in_code);
  5523.  
  5524.       return newer;
  5525.     }
  5526.     }
  5527.  
  5528.   if (new)
  5529.     {
  5530.       x = gen_lowpart_for_combine (mode, new);
  5531.       code = GET_CODE (x);
  5532.     }
  5533.  
  5534.   /* Now recursively process each operand of this operation.  */
  5535.   fmt = GET_RTX_FORMAT (code);
  5536.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  5537.     if (fmt[i] == 'e')
  5538.       {
  5539.     new = make_compound_operation (XEXP (x, i), next_code);
  5540.     SUBST (XEXP (x, i), new);
  5541.       }
  5542.  
  5543.   return x;
  5544. }
  5545.  
  5546. /* Given M see if it is a value that would select a field of bits
  5547.     within an item, but not the entire word.  Return -1 if not.
  5548.     Otherwise, return the starting position of the field, where 0 is the
  5549.     low-order bit.
  5550.  
  5551.    *PLEN is set to the length of the field.  */
  5552.  
  5553. static int
  5554. get_pos_from_mask (m, plen)
  5555.      unsigned HOST_WIDE_INT m;
  5556.      int *plen;
  5557. {
  5558.   /* Get the bit number of the first 1 bit from the right, -1 if none.  */
  5559.   int pos = exact_log2 (m & - m);
  5560.  
  5561.   if (pos < 0)
  5562.     return -1;
  5563.  
  5564.   /* Now shift off the low-order zero bits and see if we have a power of
  5565.      two minus 1.  */
  5566.   *plen = exact_log2 ((m >> pos) + 1);
  5567.  
  5568.   if (*plen <= 0)
  5569.     return -1;
  5570.  
  5571.   return pos;
  5572. }
  5573.  
  5574. /* See if X can be simplified knowing that we will only refer to it in
  5575.    MODE and will only refer to those bits that are nonzero in MASK.
  5576.    If other bits are being computed or if masking operations are done
  5577.    that select a superset of the bits in MASK, they can sometimes be
  5578.    ignored.
  5579.  
  5580.    Return a possibly simplified expression, but always convert X to
  5581.    MODE.  If X is a CONST_INT, AND the CONST_INT with MASK.
  5582.  
  5583.    Also, if REG is non-zero and X is a register equal in value to REG, 
  5584.    replace X with REG.
  5585.  
  5586.    If JUST_SELECT is nonzero, don't optimize by noticing that bits in MASK
  5587.    are all off in X.  This is used when X will be complemented, by either
  5588.    NOT, NEG, or XOR.  */
  5589.  
  5590. static rtx
  5591. force_to_mode (x, mode, mask, reg, just_select)
  5592.      rtx x;
  5593.      enum machine_mode mode;
  5594.      unsigned HOST_WIDE_INT mask;
  5595.      rtx reg;
  5596.      int just_select;
  5597. {
  5598.   enum rtx_code code = GET_CODE (x);
  5599.   int next_select = just_select || code == XOR || code == NOT || code == NEG;
  5600.   enum machine_mode op_mode;
  5601.   unsigned HOST_WIDE_INT fuller_mask, nonzero;
  5602.   rtx op0, op1, temp;
  5603.  
  5604.   /* If this is a CALL, don't do anything.  Some of the code below
  5605.      will do the wrong thing since the mode of a CALL is VOIDmode.  */
  5606.   if (code == CALL)
  5607.     return x;
  5608.  
  5609.   /* We want to perform the operation is its present mode unless we know
  5610.      that the operation is valid in MODE, in which case we do the operation
  5611.      in MODE.  */
  5612.   op_mode = ((GET_MODE_CLASS (mode) == GET_MODE_CLASS (GET_MODE (x))
  5613.           && code_to_optab[(int) code] != 0
  5614.           && (code_to_optab[(int) code]->handlers[(int) mode].insn_code
  5615.           != CODE_FOR_nothing))
  5616.          ? mode : GET_MODE (x));
  5617.  
  5618.   /* It is not valid to do a right-shift in a narrower mode
  5619.      than the one it came in with.  */
  5620.   if ((code == LSHIFTRT || code == ASHIFTRT)
  5621.       && GET_MODE_BITSIZE (mode) < GET_MODE_BITSIZE (GET_MODE (x)))
  5622.     op_mode = GET_MODE (x);
  5623.  
  5624.   /* Truncate MASK to fit OP_MODE.  */
  5625.   if (op_mode)
  5626.     mask &= GET_MODE_MASK (op_mode);
  5627.  
  5628.   /* When we have an arithmetic operation, or a shift whose count we
  5629.      do not know, we need to assume that all bit the up to the highest-order
  5630.      bit in MASK will be needed.  This is how we form such a mask.  */
  5631.   if (op_mode)
  5632.     fuller_mask = (GET_MODE_BITSIZE (op_mode) >= HOST_BITS_PER_WIDE_INT
  5633.            ? GET_MODE_MASK (op_mode)
  5634.            : ((HOST_WIDE_INT) 1 << (floor_log2 (mask) + 1)) - 1);
  5635.   else
  5636.     fuller_mask = ~ (HOST_WIDE_INT) 0;
  5637.  
  5638.   /* Determine what bits of X are guaranteed to be (non)zero.  */
  5639.   nonzero = nonzero_bits (x, mode);
  5640.  
  5641.   /* If none of the bits in X are needed, return a zero.  */
  5642.   if (! just_select && (nonzero & mask) == 0)
  5643.     return const0_rtx;
  5644.  
  5645.   /* If X is a CONST_INT, return a new one.  Do this here since the
  5646.      test below will fail.  */
  5647.   if (GET_CODE (x) == CONST_INT)
  5648.     {
  5649.       HOST_WIDE_INT cval = INTVAL (x) & mask;
  5650.       int width = GET_MODE_BITSIZE (mode);
  5651.  
  5652.       /* If MODE is narrower that HOST_WIDE_INT and CVAL is a negative
  5653.      number, sign extend it.  */
  5654.       if (width > 0 && width < HOST_BITS_PER_WIDE_INT
  5655.       && (cval & ((HOST_WIDE_INT) 1 << (width - 1))) != 0)
  5656.     cval |= (HOST_WIDE_INT) -1 << width;
  5657.     
  5658.       return GEN_INT (cval);
  5659.     }
  5660.  
  5661.   /* If X is narrower than MODE and we want all the bits in X's mode, just
  5662.      get X in the proper mode.  */
  5663.   if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode)
  5664.       && (GET_MODE_MASK (GET_MODE (x)) & ~ mask) == 0)
  5665.     return gen_lowpart_for_combine (mode, x);
  5666.  
  5667.   /* If we aren't changing the mode, X is not a SUBREG, and all zero bits in
  5668.      MASK are already known to be zero in X, we need not do anything.  */
  5669.   if (GET_MODE (x) == mode && code != SUBREG && (~ mask & nonzero) == 0)
  5670.     return x;
  5671.  
  5672.   switch (code)
  5673.     {
  5674.     case CLOBBER:
  5675.       /* If X is a (clobber (const_int)), return it since we know we are
  5676.      generating something that won't match. */
  5677.       return x;
  5678.  
  5679. #if ! BITS_BIG_ENDIAN
  5680.     case USE:
  5681.       /* X is a (use (mem ..)) that was made from a bit-field extraction that
  5682.      spanned the boundary of the MEM.  If we are now masking so it is
  5683.      within that boundary, we don't need the USE any more.  */
  5684.       if ((mask & ~ GET_MODE_MASK (GET_MODE (XEXP (x, 0)))) == 0)
  5685.     return force_to_mode (XEXP (x, 0), mode, mask, reg, next_select);
  5686. #endif
  5687.  
  5688.     case SIGN_EXTEND:
  5689.     case ZERO_EXTEND:
  5690.     case ZERO_EXTRACT:
  5691.     case SIGN_EXTRACT:
  5692.       x = expand_compound_operation (x);
  5693.       if (GET_CODE (x) != code)
  5694.     return force_to_mode (x, mode, mask, reg, next_select);
  5695.       break;
  5696.  
  5697.     case REG:
  5698.       if (reg != 0 && (rtx_equal_p (get_last_value (reg), x)
  5699.                || rtx_equal_p (reg, get_last_value (x))))
  5700.     x = reg;
  5701.       break;
  5702.  
  5703.     case SUBREG:
  5704.       if (subreg_lowpart_p (x)
  5705.       /* We can ignore the effect of this SUBREG if it narrows the mode or
  5706.          if the constant masks to zero all the bits the mode doesn't
  5707.          have.  */
  5708.       && ((GET_MODE_SIZE (GET_MODE (x))
  5709.            < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  5710.           || (0 == (mask
  5711.             & GET_MODE_MASK (GET_MODE (x))
  5712.             & ~ GET_MODE_MASK (GET_MODE (SUBREG_REG (x)))))))
  5713.     return force_to_mode (SUBREG_REG (x), mode, mask, reg, next_select);
  5714.       break;
  5715.  
  5716.     case AND:
  5717.       /* If this is an AND with a constant, convert it into an AND
  5718.      whose constant is the AND of that constant with MASK.  If it
  5719.      remains an AND of MASK, delete it since it is redundant.  */
  5720.  
  5721.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  5722.       && GET_MODE_BITSIZE (GET_MODE (x)) <= HOST_BITS_PER_WIDE_INT)
  5723.     {
  5724.       x = simplify_and_const_int (x, op_mode, XEXP (x, 0),
  5725.                       mask & INTVAL (XEXP (x, 1)));
  5726.  
  5727.       /* If X is still an AND, see if it is an AND with a mask that
  5728.          is just some low-order bits.  If so, and it is MASK, we don't
  5729.          need it.  */
  5730.  
  5731.       if (GET_CODE (x) == AND && GET_CODE (XEXP (x, 1)) == CONST_INT
  5732.           && INTVAL (XEXP (x, 1)) == mask)
  5733.         x = XEXP (x, 0);
  5734.  
  5735.       /* If it remains an AND, try making another AND with the bits
  5736.          in the mode mask that aren't in MASK turned on.  If the
  5737.          constant in the AND is wide enough, this might make a
  5738.          cheaper constant.  */
  5739.  
  5740.       if (GET_CODE (x) == AND && GET_CODE (XEXP (x, 1)) == CONST_INT
  5741.           && GET_MODE_MASK (GET_MODE (x)) != mask)
  5742.         {
  5743.           HOST_WIDE_INT cval = (INTVAL (XEXP (x, 1))
  5744.                     | (GET_MODE_MASK (GET_MODE (x)) & ~ mask));
  5745.           int width = GET_MODE_BITSIZE (GET_MODE (x));
  5746.           rtx y;
  5747.  
  5748.           /* If MODE is narrower that HOST_WIDE_INT and CVAL is a negative
  5749.          number, sign extend it.  */
  5750.           if (width > 0 && width < HOST_BITS_PER_WIDE_INT
  5751.           && (cval & ((HOST_WIDE_INT) 1 << (width - 1))) != 0)
  5752.         cval |= (HOST_WIDE_INT) -1 << width;
  5753.  
  5754.           y = gen_binary (AND, GET_MODE (x), XEXP (x, 0), GEN_INT (cval));
  5755.           if (rtx_cost (y, SET) < rtx_cost (x, SET))
  5756.         x = y;
  5757.         }
  5758.  
  5759.       break;
  5760.     }
  5761.  
  5762.       goto binop;
  5763.  
  5764.     case PLUS:
  5765.       /* In (and (plus FOO C1) M), if M is a mask that just turns off
  5766.      low-order bits (as in an alignment operation) and FOO is already
  5767.      aligned to that boundary, mask C1 to that boundary as well.
  5768.      This may eliminate that PLUS and, later, the AND.  */
  5769.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  5770.       && exact_log2 (- mask) >= 0
  5771.       && (nonzero_bits (XEXP (x, 0), mode) & ~ mask) == 0
  5772.       && (INTVAL (XEXP (x, 1)) & ~ mask) != 0)
  5773.     return force_to_mode (plus_constant (XEXP (x, 0),
  5774.                          INTVAL (XEXP (x, 1)) & mask),
  5775.                   mode, mask, reg, next_select);
  5776.  
  5777.       /* ... fall through ... */
  5778.  
  5779.     case MINUS:
  5780.     case MULT:
  5781.       /* For PLUS, MINUS and MULT, we need any bits less significant than the
  5782.      most significant bit in MASK since carries from those bits will
  5783.      affect the bits we are interested in.  */
  5784.       mask = fuller_mask;
  5785.       goto binop;
  5786.  
  5787.     case IOR:
  5788.     case XOR:
  5789.       /* If X is (ior (lshiftrt FOO C1) C2), try to commute the IOR and
  5790.      LSHIFTRT so we end up with an (and (lshiftrt (ior ...) ...) ...)
  5791.      operation which may be a bitfield extraction.  Ensure that the
  5792.      constant we form is not wider than the mode of X.  */
  5793.  
  5794.       if (GET_CODE (XEXP (x, 0)) == LSHIFTRT
  5795.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  5796.       && INTVAL (XEXP (XEXP (x, 0), 1)) >= 0
  5797.       && INTVAL (XEXP (XEXP (x, 0), 1)) < HOST_BITS_PER_WIDE_INT
  5798.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  5799.       && ((INTVAL (XEXP (XEXP (x, 0), 1))
  5800.            + floor_log2 (INTVAL (XEXP (x, 1))))
  5801.           < GET_MODE_BITSIZE (GET_MODE (x)))
  5802.       && (INTVAL (XEXP (x, 1))
  5803.           & ~ nonzero_bits (XEXP (x, 0), GET_MODE (x)) == 0))
  5804.     {
  5805.       temp = GEN_INT ((INTVAL (XEXP (x, 1)) & mask)
  5806.                   << INTVAL (XEXP (XEXP (x, 0), 1)));
  5807.       temp = gen_binary (GET_CODE (x), GET_MODE (x),
  5808.                  XEXP (XEXP (x, 0), 0), temp);
  5809.       x = gen_binary (LSHIFTRT, GET_MODE (x), temp, XEXP (x, 1));
  5810.       return force_to_mode (x, mode, mask, reg, next_select);
  5811.     }
  5812.  
  5813.     binop:
  5814.       /* For most binary operations, just propagate into the operation and
  5815.      change the mode if we have an operation of that mode.   */
  5816.  
  5817.       op0 = gen_lowpart_for_combine (op_mode,
  5818.                      force_to_mode (XEXP (x, 0), mode, mask,
  5819.                             reg, next_select));
  5820.       op1 = gen_lowpart_for_combine (op_mode,
  5821.                      force_to_mode (XEXP (x, 1), mode, mask,
  5822.                             reg, next_select));
  5823.  
  5824.       /* If OP1 is a CONST_INT and X is an IOR or XOR, clear bits outside
  5825.      MASK since OP1 might have been sign-extended but we never want
  5826.      to turn on extra bits, since combine might have previously relied
  5827.      on them being off.  */
  5828.       if (GET_CODE (op1) == CONST_INT && (code == IOR || code == XOR)
  5829.       && (INTVAL (op1) & mask) != 0)
  5830.     op1 = GEN_INT (INTVAL (op1) & mask);
  5831.      
  5832.       if (op_mode != GET_MODE (x) || op0 != XEXP (x, 0) || op1 != XEXP (x, 1))
  5833.     x = gen_binary (code, op_mode, op0, op1);
  5834.       break;
  5835.  
  5836.     case ASHIFT:
  5837.       /* For left shifts, do the same, but just for the first operand.
  5838.      However, we cannot do anything with shifts where we cannot
  5839.      guarantee that the counts are smaller than the size of the mode
  5840.      because such a count will have a different meaning in a
  5841.      wider mode.  */
  5842.  
  5843.       if (! (GET_CODE (XEXP (x, 1)) == CONST_INT
  5844.          && INTVAL (XEXP (x, 1)) >= 0
  5845.          && INTVAL (XEXP (x, 1)) < GET_MODE_BITSIZE (mode))
  5846.       && ! (GET_MODE (XEXP (x, 1)) != VOIDmode
  5847.         && (nonzero_bits (XEXP (x, 1), GET_MODE (XEXP (x, 1)))
  5848.             < (unsigned HOST_WIDE_INT) GET_MODE_BITSIZE (mode))))
  5849.     break;
  5850.     
  5851.       /* If the shift count is a constant and we can do arithmetic in
  5852.      the mode of the shift, refine which bits we need.  Otherwise, use the
  5853.      conservative form of the mask.  */
  5854.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  5855.       && INTVAL (XEXP (x, 1)) >= 0
  5856.       && INTVAL (XEXP (x, 1)) < GET_MODE_BITSIZE (op_mode)
  5857.       && GET_MODE_BITSIZE (op_mode) <= HOST_BITS_PER_WIDE_INT)
  5858.     mask >>= INTVAL (XEXP (x, 1));
  5859.       else
  5860.     mask = fuller_mask;
  5861.  
  5862.       op0 = gen_lowpart_for_combine (op_mode,
  5863.                      force_to_mode (XEXP (x, 0), op_mode,
  5864.                             mask, reg, next_select));
  5865.  
  5866.       if (op_mode != GET_MODE (x) || op0 != XEXP (x, 0))
  5867.     x =  gen_binary (code, op_mode, op0, XEXP (x, 1));
  5868.       break;
  5869.  
  5870.     case LSHIFTRT:
  5871.       /* Here we can only do something if the shift count is a constant,
  5872.      this shift constant is valid for the host, and we can do arithmetic
  5873.      in OP_MODE.  */
  5874.  
  5875.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  5876.       && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT
  5877.       && GET_MODE_BITSIZE (op_mode) <= HOST_BITS_PER_WIDE_INT)
  5878.     {
  5879.       rtx inner = XEXP (x, 0);
  5880.  
  5881.       /* Select the mask of the bits we need for the shift operand.  */
  5882.       mask <<= INTVAL (XEXP (x, 1));
  5883.  
  5884.       /* We can only change the mode of the shift if we can do arithmetic
  5885.          in the mode of the shift and MASK is no wider than the width of
  5886.          OP_MODE.  */
  5887.       if (GET_MODE_BITSIZE (op_mode) > HOST_BITS_PER_WIDE_INT
  5888.           || (mask & ~ GET_MODE_MASK (op_mode)) != 0)
  5889.         op_mode = GET_MODE (x);
  5890.  
  5891.       inner = force_to_mode (inner, op_mode, mask, reg, next_select);
  5892.  
  5893.       if (GET_MODE (x) != op_mode || inner != XEXP (x, 0))
  5894.         x = gen_binary (LSHIFTRT, op_mode, inner, XEXP (x, 1));
  5895.     }
  5896.  
  5897.       /* If we have (and (lshiftrt FOO C1) C2) where the combination of the
  5898.      shift and AND produces only copies of the sign bit (C2 is one less
  5899.      than a power of two), we can do this with just a shift.  */
  5900.  
  5901.       if (GET_CODE (x) == LSHIFTRT
  5902.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  5903.       && ((INTVAL (XEXP (x, 1))
  5904.            + num_sign_bit_copies (XEXP (x, 0), GET_MODE (XEXP (x, 0))))
  5905.           >= GET_MODE_BITSIZE (GET_MODE (x)))
  5906.       && exact_log2 (mask + 1) >= 0
  5907.       && (num_sign_bit_copies (XEXP (x, 0), GET_MODE (XEXP (x, 0)))
  5908.           >= exact_log2 (mask + 1)))
  5909.     x = gen_binary (LSHIFTRT, GET_MODE (x), XEXP (x, 0),
  5910.             GEN_INT (GET_MODE_BITSIZE (GET_MODE (x))
  5911.                  - exact_log2 (mask + 1)));
  5912.       break;
  5913.  
  5914.     case ASHIFTRT:
  5915.       /* If we are just looking for the sign bit, we don't need this shift at
  5916.      all, even if it has a variable count.  */
  5917.       if (mask == ((HOST_WIDE_INT) 1
  5918.            << (GET_MODE_BITSIZE (GET_MODE (x)) - 1)))
  5919.     return force_to_mode (XEXP (x, 0), mode, mask, reg, next_select);
  5920.  
  5921.       /* If this is a shift by a constant, get a mask that contains those bits
  5922.      that are not copies of the sign bit.  We then have two cases:  If
  5923.      MASK only includes those bits, this can be a logical shift, which may
  5924.      allow simplifications.  If MASK is a single-bit field not within
  5925.      those bits, we are requesting a copy of the sign bit and hence can
  5926.      shift the sign bit to the appropriate location.  */
  5927.  
  5928.       if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) >= 0
  5929.       && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT)
  5930.     {
  5931.       int i = -1;
  5932.  
  5933.       nonzero = GET_MODE_MASK (GET_MODE (x));
  5934.       nonzero >>= INTVAL (XEXP (x, 1));
  5935.  
  5936.       if ((mask & ~ nonzero) == 0
  5937.           || (i = exact_log2 (mask)) >= 0)
  5938.         {
  5939.           x = simplify_shift_const
  5940.         (x, LSHIFTRT, GET_MODE (x), XEXP (x, 0),
  5941.          i < 0 ? INTVAL (XEXP (x, 1))
  5942.          : GET_MODE_BITSIZE (GET_MODE (x)) - 1 - i);
  5943.  
  5944.           if (GET_CODE (x) != ASHIFTRT)
  5945.         return force_to_mode (x, mode, mask, reg, next_select);
  5946.         }
  5947.     }
  5948.  
  5949.       /* If MASK is 1, convert this to a LSHIFTRT.  This can be done
  5950.      even if the shift count isn't a constant.  */
  5951.       if (mask == 1)
  5952.     x = gen_binary (LSHIFTRT, GET_MODE (x), XEXP (x, 0), XEXP (x, 1));
  5953.  
  5954.       /* If this is a sign-extension operation that just affects bits
  5955.      we don't care about, remove it.  Be sure the call above returned
  5956.      something that is still a shift.  */
  5957.  
  5958.       if ((GET_CODE (x) == LSHIFTRT || GET_CODE (x) == ASHIFTRT)
  5959.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  5960.       && INTVAL (XEXP (x, 1)) >= 0
  5961.       && (INTVAL (XEXP (x, 1))
  5962.           <= GET_MODE_BITSIZE (GET_MODE (x)) - (floor_log2 (mask) + 1))
  5963.       && GET_CODE (XEXP (x, 0)) == ASHIFT
  5964.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  5965.       && INTVAL (XEXP (XEXP (x, 0), 1)) == INTVAL (XEXP (x, 1)))
  5966.     return force_to_mode (XEXP (XEXP (x, 0), 0), mode, mask,
  5967.                   reg, next_select);
  5968.  
  5969.       break;
  5970.  
  5971.     case ROTATE:
  5972.     case ROTATERT:
  5973.       /* If the shift count is constant and we can do computations
  5974.      in the mode of X, compute where the bits we care about are.
  5975.      Otherwise, we can't do anything.  Don't change the mode of
  5976.      the shift or propagate MODE into the shift, though.  */
  5977.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  5978.       && INTVAL (XEXP (x, 1)) >= 0)
  5979.     {
  5980.       temp = simplify_binary_operation (code == ROTATE ? ROTATERT : ROTATE,
  5981.                         GET_MODE (x), GEN_INT (mask),
  5982.                         XEXP (x, 1));
  5983.       if (temp && GET_CODE(temp) == CONST_INT)
  5984.         SUBST (XEXP (x, 0),
  5985.            force_to_mode (XEXP (x, 0), GET_MODE (x),
  5986.                   INTVAL (temp), reg, next_select));
  5987.     }
  5988.       break;
  5989.     
  5990.     case NEG:
  5991.       /* If we just want the low-order bit, the NEG isn't needed since it
  5992.      won't change the low-order bit.    */
  5993.       if (mask == 1)
  5994.     return force_to_mode (XEXP (x, 0), mode, mask, reg, just_select);
  5995.  
  5996.       /* We need any bits less significant than the most significant bit in
  5997.      MASK since carries from those bits will affect the bits we are
  5998.      interested in.  */
  5999.       mask = fuller_mask;
  6000.       goto unop;
  6001.  
  6002.     case NOT:
  6003.       /* (not FOO) is (xor FOO CONST), so if FOO is an LSHIFTRT, we can do the
  6004.      same as the XOR case above.  Ensure that the constant we form is not
  6005.      wider than the mode of X.  */
  6006.  
  6007.       if (GET_CODE (XEXP (x, 0)) == LSHIFTRT
  6008.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  6009.       && INTVAL (XEXP (XEXP (x, 0), 1)) >= 0
  6010.       && (INTVAL (XEXP (XEXP (x, 0), 1)) + floor_log2 (mask)
  6011.           < GET_MODE_BITSIZE (GET_MODE (x)))
  6012.       && INTVAL (XEXP (XEXP (x, 0), 1)) < HOST_BITS_PER_WIDE_INT)
  6013.     {
  6014.       temp = GEN_INT (mask << INTVAL (XEXP (XEXP (x, 0), 1)));
  6015.       temp = gen_binary (XOR, GET_MODE (x), XEXP (XEXP (x, 0), 0), temp);
  6016.       x = gen_binary (LSHIFTRT, GET_MODE (x), temp, XEXP (XEXP (x, 0), 1));
  6017.  
  6018.       return force_to_mode (x, mode, mask, reg, next_select);
  6019.     }
  6020.  
  6021.     unop:
  6022.       op0 = gen_lowpart_for_combine (op_mode,
  6023.                      force_to_mode (XEXP (x, 0), mode, mask,
  6024.                             reg, next_select));
  6025.       if (op_mode != GET_MODE (x) || op0 != XEXP (x, 0))
  6026.     x = gen_unary (code, op_mode, op_mode, op0);
  6027.       break;
  6028.  
  6029.     case NE:
  6030.       /* (and (ne FOO 0) CONST) can be (and FOO CONST) if CONST is included
  6031.      in STORE_FLAG_VALUE and FOO has no bits that might be nonzero not
  6032.      in CONST.  */
  6033.       if ((mask & ~ STORE_FLAG_VALUE) == 0 && XEXP (x, 0) == const0_rtx
  6034.       && (nonzero_bits (XEXP (x, 0), mode) & ~ mask) == 0)
  6035.     return force_to_mode (XEXP (x, 0), mode, mask, reg, next_select);
  6036.  
  6037.       break;
  6038.  
  6039.     case IF_THEN_ELSE:
  6040.       /* We have no way of knowing if the IF_THEN_ELSE can itself be
  6041.      written in a narrower mode.  We play it safe and do not do so.  */
  6042.  
  6043.       SUBST (XEXP (x, 1),
  6044.          gen_lowpart_for_combine (GET_MODE (x),
  6045.                       force_to_mode (XEXP (x, 1), mode,
  6046.                              mask, reg, next_select)));
  6047.       SUBST (XEXP (x, 2),
  6048.          gen_lowpart_for_combine (GET_MODE (x),
  6049.                       force_to_mode (XEXP (x, 2), mode,
  6050.                              mask, reg,next_select)));
  6051.       break;
  6052.     }
  6053.  
  6054.   /* Ensure we return a value of the proper mode.  */
  6055.   return gen_lowpart_for_combine (mode, x);
  6056. }
  6057.  
  6058. /* Return nonzero if X is an expression that has one of two values depending on
  6059.    whether some other value is zero or nonzero.  In that case, we return the
  6060.    value that is being tested, *PTRUE is set to the value if the rtx being
  6061.    returned has a nonzero value, and *PFALSE is set to the other alternative.
  6062.  
  6063.    If we return zero, we set *PTRUE and *PFALSE to X.  */
  6064.  
  6065. static rtx
  6066. if_then_else_cond (x, ptrue, pfalse)
  6067.      rtx x;
  6068.      rtx *ptrue, *pfalse;
  6069. {
  6070.   enum machine_mode mode = GET_MODE (x);
  6071.   enum rtx_code code = GET_CODE (x);
  6072.   int size = GET_MODE_BITSIZE (mode);
  6073.   rtx cond0, cond1, true0, true1, false0, false1;
  6074.   unsigned HOST_WIDE_INT nz;
  6075.  
  6076.   /* If this is a unary operation whose operand has one of two values, apply
  6077.      our opcode to compute those values.  */
  6078.   if (GET_RTX_CLASS (code) == '1'
  6079.       && (cond0 = if_then_else_cond (XEXP (x, 0), &true0, &false0)) != 0)
  6080.     {
  6081.       *ptrue = gen_unary (code, mode, GET_MODE (XEXP (x, 0)), true0);
  6082.       *pfalse = gen_unary (code, mode, GET_MODE (XEXP (x, 0)), false0);
  6083.       return cond0;
  6084.     }
  6085.  
  6086.   /* If this is a COMPARE, do nothing, since the IF_THEN_ELSE we would
  6087.      make can't possibly match and would supress other optimizations.  */
  6088.   else if (code == COMPARE)
  6089.     ;
  6090.  
  6091.   /* If this is a binary operation, see if either side has only one of two
  6092.      values.  If either one does or if both do and they are conditional on
  6093.      the same value, compute the new true and false values.  */
  6094.   else if (GET_RTX_CLASS (code) == 'c' || GET_RTX_CLASS (code) == '2'
  6095.        || GET_RTX_CLASS (code) == '<')
  6096.     {
  6097.       cond0 = if_then_else_cond (XEXP (x, 0), &true0, &false0);
  6098.       cond1 = if_then_else_cond (XEXP (x, 1), &true1, &false1);
  6099.  
  6100.       if ((cond0 != 0 || cond1 != 0)
  6101.       && ! (cond0 != 0 && cond1 != 0 && ! rtx_equal_p (cond0, cond1)))
  6102.     {
  6103.       *ptrue = gen_binary (code, mode, true0, true1);
  6104.       *pfalse = gen_binary (code, mode, false0, false1);
  6105.       return cond0 ? cond0 : cond1;
  6106.     }
  6107.  
  6108. #if STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1
  6109.  
  6110.       /* See if we have PLUS, IOR, XOR, MINUS or UMAX, where one of the
  6111.      operands is zero when the other is non-zero, and vice-versa.  */
  6112.  
  6113.       if ((code == PLUS || code == IOR || code == XOR || code == MINUS
  6114.        || code == UMAX)
  6115.       && GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == MULT)
  6116.     {
  6117.       rtx op0 = XEXP (XEXP (x, 0), 1);
  6118.       rtx op1 = XEXP (XEXP (x, 1), 1);
  6119.  
  6120.       cond0 = XEXP (XEXP (x, 0), 0);
  6121.       cond1 = XEXP (XEXP (x, 1), 0);
  6122.  
  6123.       if (GET_RTX_CLASS (GET_CODE (cond0)) == '<'
  6124.           && GET_RTX_CLASS (GET_CODE (cond1)) == '<'
  6125.           && reversible_comparison_p (cond1)
  6126.           && ((GET_CODE (cond0) == reverse_condition (GET_CODE (cond1))
  6127.            && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 0))
  6128.            && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 1)))
  6129.           || ((swap_condition (GET_CODE (cond0))
  6130.                == reverse_condition (GET_CODE (cond1)))
  6131.               && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 1))
  6132.               && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 0))))
  6133.           && ! side_effects_p (x))
  6134.         {
  6135.           *ptrue = gen_binary (MULT, mode, op0, const_true_rtx);
  6136.           *pfalse = gen_binary (MULT, mode, 
  6137.                     (code == MINUS 
  6138.                      ? gen_unary (NEG, mode, mode, op1) : op1),
  6139.                     const_true_rtx);
  6140.           return cond0;
  6141.         }
  6142.     }
  6143.  
  6144.       /* Similarly for MULT, AND and UMIN, execpt that for these the result
  6145.      is always zero.  */
  6146.       if ((code == MULT || code == AND || code == UMIN)
  6147.       && GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == MULT)
  6148.     {
  6149.       cond0 = XEXP (XEXP (x, 0), 0);
  6150.       cond1 = XEXP (XEXP (x, 1), 0);
  6151.  
  6152.       if (GET_RTX_CLASS (GET_CODE (cond0)) == '<'
  6153.           && GET_RTX_CLASS (GET_CODE (cond1)) == '<'
  6154.           && reversible_comparison_p (cond1)
  6155.           && ((GET_CODE (cond0) == reverse_condition (GET_CODE (cond1))
  6156.            && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 0))
  6157.            && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 1)))
  6158.           || ((swap_condition (GET_CODE (cond0))
  6159.                == reverse_condition (GET_CODE (cond1)))
  6160.               && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 1))
  6161.               && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 0))))
  6162.           && ! side_effects_p (x))
  6163.         {
  6164.           *ptrue = *pfalse = const0_rtx;
  6165.           return cond0;
  6166.         }
  6167.     }
  6168. #endif
  6169.     }
  6170.  
  6171.   else if (code == IF_THEN_ELSE)
  6172.     {
  6173.       /* If we have IF_THEN_ELSE already, extract the condition and
  6174.      canonicalize it if it is NE or EQ.  */
  6175.       cond0 = XEXP (x, 0);
  6176.       *ptrue = XEXP (x, 1), *pfalse = XEXP (x, 2);
  6177.       if (GET_CODE (cond0) == NE && XEXP (cond0, 1) == const0_rtx)
  6178.     return XEXP (cond0, 0);
  6179.       else if (GET_CODE (cond0) == EQ && XEXP (cond0, 1) == const0_rtx)
  6180.     {
  6181.       *ptrue = XEXP (x, 2), *pfalse = XEXP (x, 1);
  6182.       return XEXP (cond0, 0);
  6183.     }
  6184.       else
  6185.     return cond0;
  6186.     }
  6187.  
  6188.   /* If X is a normal SUBREG with both inner and outer modes integral,
  6189.      we can narrow both the true and false values of the inner expression,
  6190.      if there is a condition.  */
  6191.   else if (code == SUBREG && GET_MODE_CLASS (mode) == MODE_INT
  6192.        && GET_MODE_CLASS (GET_MODE (SUBREG_REG (x))) == MODE_INT
  6193.        && GET_MODE_SIZE (mode) <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
  6194.        && 0 != (cond0 = if_then_else_cond (SUBREG_REG (x),
  6195.                            &true0, &false0)))
  6196.     {
  6197.       *ptrue = force_to_mode (true0, mode, GET_MODE_MASK (mode), NULL_RTX, 0);
  6198.       *pfalse
  6199.     = force_to_mode (false0, mode, GET_MODE_MASK (mode), NULL_RTX, 0);
  6200.  
  6201.       return cond0;
  6202.     }
  6203.  
  6204.   /* If X is a constant, this isn't special and will cause confusions
  6205.      if we treat it as such.  Likewise if it is equivalent to a constant.  */
  6206.   else if (CONSTANT_P (x)
  6207.        || ((cond0 = get_last_value (x)) != 0 && CONSTANT_P (cond0)))
  6208.     ;
  6209.  
  6210.   /* If X is known to be either 0 or -1, those are the true and 
  6211.      false values when testing X.  */
  6212.   else if (num_sign_bit_copies (x, mode) == size)
  6213.     {
  6214.       *ptrue = constm1_rtx, *pfalse = const0_rtx;
  6215.       return x;
  6216.     }
  6217.  
  6218.   /* Likewise for 0 or a single bit.  */
  6219.   else if (exact_log2 (nz = nonzero_bits (x, mode)) >= 0)
  6220.     {
  6221.       *ptrue = GEN_INT (nz), *pfalse = const0_rtx;
  6222.       return x;
  6223.     }
  6224.  
  6225.   /* Otherwise fail; show no condition with true and false values the same.  */
  6226.   *ptrue = *pfalse = x;
  6227.   return 0;
  6228. }
  6229.  
  6230. /* Return the value of expression X given the fact that condition COND
  6231.    is known to be true when applied to REG as its first operand and VAL
  6232.    as its second.  X is known to not be shared and so can be modified in
  6233.    place.
  6234.  
  6235.    We only handle the simplest cases, and specifically those cases that
  6236.    arise with IF_THEN_ELSE expressions.  */
  6237.  
  6238. static rtx
  6239. known_cond (x, cond, reg, val)
  6240.      rtx x;
  6241.      enum rtx_code cond;
  6242.      rtx reg, val;
  6243. {
  6244.   enum rtx_code code = GET_CODE (x);
  6245.   rtx temp;
  6246.   char *fmt;
  6247.   int i, j;
  6248.  
  6249.   if (side_effects_p (x))
  6250.     return x;
  6251.  
  6252.   if (cond == EQ && rtx_equal_p (x, reg))
  6253.     return val;
  6254.  
  6255.   /* If X is (abs REG) and we know something about REG's relationship
  6256.      with zero, we may be able to simplify this.  */
  6257.  
  6258.   if (code == ABS && rtx_equal_p (XEXP (x, 0), reg) && val == const0_rtx)
  6259.     switch (cond)
  6260.       {
  6261.       case GE:  case GT:  case EQ:
  6262.     return XEXP (x, 0);
  6263.       case LT:  case LE:
  6264.     return gen_unary (NEG, GET_MODE (XEXP (x, 0)), GET_MODE (XEXP (x, 0)),
  6265.               XEXP (x, 0));
  6266.       }
  6267.  
  6268.   /* The only other cases we handle are MIN, MAX, and comparisons if the
  6269.      operands are the same as REG and VAL.  */
  6270.  
  6271.   else if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == 'c')
  6272.     {
  6273.       if (rtx_equal_p (XEXP (x, 0), val))
  6274.     cond = swap_condition (cond), temp = val, val = reg, reg = temp;
  6275.  
  6276.       if (rtx_equal_p (XEXP (x, 0), reg) && rtx_equal_p (XEXP (x, 1), val))
  6277.     {
  6278.       if (GET_RTX_CLASS (code) == '<')
  6279.         return (comparison_dominates_p (cond, code) ? const_true_rtx
  6280.             : (comparison_dominates_p (cond,
  6281.                            reverse_condition (code))
  6282.                ? const0_rtx : x));
  6283.  
  6284.       else if (code == SMAX || code == SMIN
  6285.            || code == UMIN || code == UMAX)
  6286.         {
  6287.           int unsignedp = (code == UMIN || code == UMAX);
  6288.  
  6289.           if (code == SMAX || code == UMAX)
  6290.         cond = reverse_condition (cond);
  6291.  
  6292.           switch (cond)
  6293.         {
  6294.         case GE:   case GT:
  6295.           return unsignedp ? x : XEXP (x, 1);
  6296.         case LE:   case LT:
  6297.           return unsignedp ? x : XEXP (x, 0);
  6298.         case GEU:  case GTU:
  6299.           return unsignedp ? XEXP (x, 1) : x;
  6300.         case LEU:  case LTU:
  6301.           return unsignedp ? XEXP (x, 0) : x;
  6302.         }
  6303.         }
  6304.     }
  6305.     }
  6306.  
  6307.   fmt = GET_RTX_FORMAT (code);
  6308.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  6309.     {
  6310.       if (fmt[i] == 'e')
  6311.     SUBST (XEXP (x, i), known_cond (XEXP (x, i), cond, reg, val));
  6312.       else if (fmt[i] == 'E')
  6313.     for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  6314.       SUBST (XVECEXP (x, i, j), known_cond (XVECEXP (x, i, j),
  6315.                         cond, reg, val));
  6316.     }
  6317.  
  6318.   return x;
  6319. }
  6320.  
  6321. /* See if X, a SET operation, can be rewritten as a bit-field assignment.
  6322.    Return that assignment if so.
  6323.  
  6324.    We only handle the most common cases.  */
  6325.  
  6326. static rtx
  6327. make_field_assignment (x)
  6328.      rtx x;
  6329. {
  6330.   rtx dest = SET_DEST (x);
  6331.   rtx src = SET_SRC (x);
  6332.   rtx assign;
  6333.   HOST_WIDE_INT c1;
  6334.   int pos, len;
  6335.   rtx other;
  6336.   enum machine_mode mode;
  6337.  
  6338.   /* If SRC was (and (not (ashift (const_int 1) POS)) DEST), this is
  6339.      a clear of a one-bit field.  We will have changed it to
  6340.      (and (rotate (const_int -2) POS) DEST), so check for that.  Also check
  6341.      for a SUBREG.  */
  6342.  
  6343.   if (GET_CODE (src) == AND && GET_CODE (XEXP (src, 0)) == ROTATE
  6344.       && GET_CODE (XEXP (XEXP (src, 0), 0)) == CONST_INT
  6345.       && INTVAL (XEXP (XEXP (src, 0), 0)) == -2
  6346.       && (rtx_equal_p (dest, XEXP (src, 1))
  6347.       || rtx_equal_p (dest, get_last_value (XEXP (src, 1)))
  6348.       || rtx_equal_p (get_last_value (dest), XEXP (src, 1))))
  6349.     {
  6350.       assign = make_extraction (VOIDmode, dest, 0, XEXP (XEXP (src, 0), 1),
  6351.                 1, 1, 1, 0);
  6352.       return gen_rtx (SET, VOIDmode, assign, const0_rtx);
  6353.     }
  6354.  
  6355.   else if (GET_CODE (src) == AND && GET_CODE (XEXP (src, 0)) == SUBREG
  6356.        && subreg_lowpart_p (XEXP (src, 0))
  6357.        && (GET_MODE_SIZE (GET_MODE (XEXP (src, 0))) 
  6358.            < GET_MODE_SIZE (GET_MODE (SUBREG_REG (XEXP (src, 0)))))
  6359.        && GET_CODE (SUBREG_REG (XEXP (src, 0))) == ROTATE
  6360.        && INTVAL (XEXP (SUBREG_REG (XEXP (src, 0)), 0)) == -2
  6361.        && (rtx_equal_p (dest, XEXP (src, 1))
  6362.            || rtx_equal_p (dest, get_last_value (XEXP (src, 1)))
  6363.            || rtx_equal_p (get_last_value (dest), XEXP (src, 1))))
  6364.     {
  6365.       assign = make_extraction (VOIDmode, dest, 0,
  6366.                 XEXP (SUBREG_REG (XEXP (src, 0)), 1),
  6367.                 1, 1, 1, 0);
  6368.       return gen_rtx (SET, VOIDmode, assign, const0_rtx);
  6369.     }
  6370.  
  6371.   /* If SRC is (ior (ashift (const_int 1) POS DEST)), this is a set of a
  6372.      one-bit field.  */
  6373.   else if (GET_CODE (src) == IOR && GET_CODE (XEXP (src, 0)) == ASHIFT
  6374.        && XEXP (XEXP (src, 0), 0) == const1_rtx
  6375.        && (rtx_equal_p (dest, XEXP (src, 1))
  6376.            || rtx_equal_p (dest, get_last_value (XEXP (src, 1)))
  6377.            || rtx_equal_p (get_last_value (dest), XEXP (src, 1))))
  6378.     {
  6379.       assign = make_extraction (VOIDmode, dest, 0, XEXP (XEXP (src, 0), 1),
  6380.                 1, 1, 1, 0);
  6381.       return gen_rtx (SET, VOIDmode, assign, const1_rtx);
  6382.     }
  6383.  
  6384.   /* The other case we handle is assignments into a constant-position
  6385.      field.  They look like (ior (and DEST C1) OTHER).  If C1 represents
  6386.      a mask that has all one bits except for a group of zero bits and
  6387.      OTHER is known to have zeros where C1 has ones, this is such an
  6388.      assignment.  Compute the position and length from C1.  Shift OTHER
  6389.      to the appropriate position, force it to the required mode, and
  6390.      make the extraction.  Check for the AND in both operands.  */
  6391.  
  6392.   if (GET_CODE (src) == IOR && GET_CODE (XEXP (src, 0)) == AND
  6393.       && GET_CODE (XEXP (XEXP (src, 0), 1)) == CONST_INT
  6394.       && (rtx_equal_p (XEXP (XEXP (src, 0), 0), dest)
  6395.       || rtx_equal_p (XEXP (XEXP (src, 0), 0), get_last_value (dest))
  6396.       || rtx_equal_p (get_last_value (XEXP (XEXP (src, 0), 1)), dest)))
  6397.     c1 = INTVAL (XEXP (XEXP (src, 0), 1)), other = XEXP (src, 1);
  6398.   else if (GET_CODE (src) == IOR && GET_CODE (XEXP (src, 1)) == AND
  6399.        && GET_CODE (XEXP (XEXP (src, 1), 1)) == CONST_INT
  6400.        && (rtx_equal_p (XEXP (XEXP (src, 1), 0), dest)
  6401.            || rtx_equal_p (XEXP (XEXP (src, 1), 0), get_last_value (dest))
  6402.            || rtx_equal_p (get_last_value (XEXP (XEXP (src, 1), 0)),
  6403.                    dest)))
  6404.     c1 = INTVAL (XEXP (XEXP (src, 1), 1)), other = XEXP (src, 0);
  6405.   else
  6406.     return x;
  6407.  
  6408.   pos = get_pos_from_mask (c1 ^ GET_MODE_MASK (GET_MODE (dest)), &len);
  6409.   if (pos < 0 || pos + len > GET_MODE_BITSIZE (GET_MODE (dest))
  6410.       || (GET_MODE_BITSIZE (GET_MODE (other)) <= HOST_BITS_PER_WIDE_INT
  6411.       && (c1 & nonzero_bits (other, GET_MODE (other))) != 0))
  6412.     return x;
  6413.  
  6414.   assign = make_extraction (VOIDmode, dest, pos, NULL_RTX, len, 1, 1, 0);
  6415.  
  6416.   /* The mode to use for the source is the mode of the assignment, or of
  6417.      what is inside a possible STRICT_LOW_PART.  */
  6418.   mode = (GET_CODE (assign) == STRICT_LOW_PART 
  6419.       ? GET_MODE (XEXP (assign, 0)) : GET_MODE (assign));
  6420.  
  6421.   /* Shift OTHER right POS places and make it the source, restricting it
  6422.      to the proper length and mode.  */
  6423.  
  6424.   src = force_to_mode (simplify_shift_const (NULL_RTX, LSHIFTRT,
  6425.                          GET_MODE (src), other, pos),
  6426.                mode,
  6427.                GET_MODE_BITSIZE (mode) >= HOST_BITS_PER_WIDE_INT
  6428.                ? GET_MODE_MASK (mode)
  6429.                : ((HOST_WIDE_INT) 1 << len) - 1,
  6430.                dest, 0);
  6431.  
  6432.   return gen_rtx_combine (SET, VOIDmode, assign, src);
  6433. }
  6434.  
  6435. /* See if X is of the form (+ (* a c) (* b c)) and convert to (* (+ a b) c)
  6436.    if so.  */
  6437.  
  6438. static rtx
  6439. apply_distributive_law (x)
  6440.      rtx x;
  6441. {
  6442.   enum rtx_code code = GET_CODE (x);
  6443.   rtx lhs, rhs, other;
  6444.   rtx tem;
  6445.   enum rtx_code inner_code;
  6446.  
  6447.   /* Distributivity is not true for floating point.
  6448.      It can change the value.  So don't do it.
  6449.      -- rms and moshier@world.std.com.  */
  6450.   if (FLOAT_MODE_P (GET_MODE (x)))
  6451.     return x;
  6452.  
  6453.   /* The outer operation can only be one of the following:  */
  6454.   if (code != IOR && code != AND && code != XOR
  6455.       && code != PLUS && code != MINUS)
  6456.     return x;
  6457.  
  6458.   lhs = XEXP (x, 0), rhs = XEXP (x, 1);
  6459.  
  6460.   /* If either operand is a primitive we can't do anything, so get out fast. */
  6461.   if (GET_RTX_CLASS (GET_CODE (lhs)) == 'o'
  6462.       || GET_RTX_CLASS (GET_CODE (rhs)) == 'o')
  6463.     return x;
  6464.  
  6465.   lhs = expand_compound_operation (lhs);
  6466.   rhs = expand_compound_operation (rhs);
  6467.   inner_code = GET_CODE (lhs);
  6468.   if (inner_code != GET_CODE (rhs))
  6469.     return x;
  6470.  
  6471.   /* See if the inner and outer operations distribute.  */
  6472.   switch (inner_code)
  6473.     {
  6474.     case LSHIFTRT:
  6475.     case ASHIFTRT:
  6476.     case AND:
  6477.     case IOR:
  6478.       /* These all distribute except over PLUS.  */
  6479.       if (code == PLUS || code == MINUS)
  6480.     return x;
  6481.       break;
  6482.  
  6483.     case MULT:
  6484.       if (code != PLUS && code != MINUS)
  6485.     return x;
  6486.       break;
  6487.  
  6488.     case ASHIFT:
  6489.       /* This is also a multiply, so it distributes over everything.  */
  6490.       break;
  6491.  
  6492.     case SUBREG:
  6493.       /* Non-paradoxical SUBREGs distributes over all operations, provided
  6494.      the inner modes and word numbers are the same, this is an extraction
  6495.      of a low-order part, we don't convert an fp operation to int or
  6496.      vice versa, and we would not be converting a single-word
  6497.      operation into a multi-word operation.  The latter test is not
  6498.      required, but it prevents generating unneeded multi-word operations.
  6499.      Some of the previous tests are redundant given the latter test, but
  6500.      are retained because they are required for correctness.
  6501.  
  6502.      We produce the result slightly differently in this case.  */
  6503.  
  6504.       if (GET_MODE (SUBREG_REG (lhs)) != GET_MODE (SUBREG_REG (rhs))
  6505.       || SUBREG_WORD (lhs) != SUBREG_WORD (rhs)
  6506.       || ! subreg_lowpart_p (lhs)
  6507.       || (GET_MODE_CLASS (GET_MODE (lhs))
  6508.           != GET_MODE_CLASS (GET_MODE (SUBREG_REG (lhs))))
  6509.       || (GET_MODE_SIZE (GET_MODE (lhs))
  6510.           < GET_MODE_SIZE (GET_MODE (SUBREG_REG (lhs))))
  6511.       || GET_MODE_SIZE (GET_MODE (SUBREG_REG (lhs))) > UNITS_PER_WORD)
  6512.     return x;
  6513.  
  6514.       tem = gen_binary (code, GET_MODE (SUBREG_REG (lhs)),
  6515.             SUBREG_REG (lhs), SUBREG_REG (rhs));
  6516.       return gen_lowpart_for_combine (GET_MODE (x), tem);
  6517.  
  6518.     default:
  6519.       return x;
  6520.     }
  6521.  
  6522.   /* Set LHS and RHS to the inner operands (A and B in the example
  6523.      above) and set OTHER to the common operand (C in the example).
  6524.      These is only one way to do this unless the inner operation is
  6525.      commutative.  */
  6526.   if (GET_RTX_CLASS (inner_code) == 'c'
  6527.       && rtx_equal_p (XEXP (lhs, 0), XEXP (rhs, 0)))
  6528.     other = XEXP (lhs, 0), lhs = XEXP (lhs, 1), rhs = XEXP (rhs, 1);
  6529.   else if (GET_RTX_CLASS (inner_code) == 'c'
  6530.        && rtx_equal_p (XEXP (lhs, 0), XEXP (rhs, 1)))
  6531.     other = XEXP (lhs, 0), lhs = XEXP (lhs, 1), rhs = XEXP (rhs, 0);
  6532.   else if (GET_RTX_CLASS (inner_code) == 'c'
  6533.        && rtx_equal_p (XEXP (lhs, 1), XEXP (rhs, 0)))
  6534.     other = XEXP (lhs, 1), lhs = XEXP (lhs, 0), rhs = XEXP (rhs, 1);
  6535.   else if (rtx_equal_p (XEXP (lhs, 1), XEXP (rhs, 1)))
  6536.     other = XEXP (lhs, 1), lhs = XEXP (lhs, 0), rhs = XEXP (rhs, 0);
  6537.   else
  6538.     return x;
  6539.  
  6540.   /* Form the new inner operation, seeing if it simplifies first.  */
  6541.   tem = gen_binary (code, GET_MODE (x), lhs, rhs);
  6542.  
  6543.   /* There is one exception to the general way of distributing:
  6544.      (a ^ b) | (a ^ c) -> (~a) & (b ^ c)  */
  6545.   if (code == XOR && inner_code == IOR)
  6546.     {
  6547.       inner_code = AND;
  6548.       other = gen_unary (NOT, GET_MODE (x), GET_MODE (x), other);
  6549.     }
  6550.  
  6551.   /* We may be able to continuing distributing the result, so call
  6552.      ourselves recursively on the inner operation before forming the
  6553.      outer operation, which we return.  */
  6554.   return gen_binary (inner_code, GET_MODE (x),
  6555.              apply_distributive_law (tem), other);
  6556. }
  6557.  
  6558. /* We have X, a logical `and' of VAROP with the constant CONSTOP, to be done
  6559.    in MODE.
  6560.  
  6561.    Return an equivalent form, if different from X.  Otherwise, return X.  If
  6562.    X is zero, we are to always construct the equivalent form.  */
  6563.  
  6564. static rtx
  6565. simplify_and_const_int (x, mode, varop, constop)
  6566.      rtx x;
  6567.      enum machine_mode mode;
  6568.      rtx varop;
  6569.      unsigned HOST_WIDE_INT constop;
  6570. {
  6571.   unsigned HOST_WIDE_INT nonzero;
  6572.   int i;
  6573.  
  6574.   /* Simplify VAROP knowing that we will be only looking at some of the
  6575.      bits in it.  */
  6576.   varop = force_to_mode (varop, mode, constop, NULL_RTX, 0);
  6577.  
  6578.   /* If VAROP is a CLOBBER, we will fail so return it; if it is a
  6579.      CONST_INT, we are done.  */
  6580.   if (GET_CODE (varop) == CLOBBER || GET_CODE (varop) == CONST_INT)
  6581.     return varop;
  6582.  
  6583.   /* See what bits may be nonzero in VAROP.  Unlike the general case of
  6584.      a call to nonzero_bits, here we don't care about bits outside
  6585.      MODE.  */
  6586.  
  6587.   nonzero = nonzero_bits (varop, mode) & GET_MODE_MASK (mode);
  6588.  
  6589.   /* Turn off all bits in the constant that are known to already be zero.
  6590.      Thus, if the AND isn't needed at all, we will have CONSTOP == NONZERO_BITS
  6591.      which is tested below.  */
  6592.  
  6593.   constop &= nonzero;
  6594.  
  6595.   /* If we don't have any bits left, return zero.  */
  6596.   if (constop == 0)
  6597.     return const0_rtx;
  6598.  
  6599.   /* If VAROP is a NEG of something known to be zero or 1 and CONSTOP is
  6600.      a power of two, we can replace this with a ASHIFT.  */
  6601.   if (GET_CODE (varop) == NEG && nonzero_bits (XEXP (varop, 0), mode) == 1
  6602.       && (i = exact_log2 (constop)) >= 0)
  6603.     return simplify_shift_const (NULL_RTX, ASHIFT, mode, XEXP (varop, 0), i);
  6604.                  
  6605.   /* If VAROP is an IOR or XOR, apply the AND to both branches of the IOR
  6606.      or XOR, then try to apply the distributive law.  This may eliminate
  6607.      operations if either branch can be simplified because of the AND.
  6608.      It may also make some cases more complex, but those cases probably
  6609.      won't match a pattern either with or without this.  */
  6610.  
  6611.   if (GET_CODE (varop) == IOR || GET_CODE (varop) == XOR)
  6612.     return
  6613.       gen_lowpart_for_combine
  6614.     (mode,
  6615.      apply_distributive_law
  6616.      (gen_binary (GET_CODE (varop), GET_MODE (varop),
  6617.               simplify_and_const_int (NULL_RTX, GET_MODE (varop),
  6618.                           XEXP (varop, 0), constop),
  6619.               simplify_and_const_int (NULL_RTX, GET_MODE (varop),
  6620.                           XEXP (varop, 1), constop))));
  6621.  
  6622.   /* Get VAROP in MODE.  Try to get a SUBREG if not.  Don't make a new SUBREG
  6623.      if we already had one (just check for the simplest cases).  */
  6624.   if (x && GET_CODE (XEXP (x, 0)) == SUBREG
  6625.       && GET_MODE (XEXP (x, 0)) == mode
  6626.       && SUBREG_REG (XEXP (x, 0)) == varop)
  6627.     varop = XEXP (x, 0);
  6628.   else
  6629.     varop = gen_lowpart_for_combine (mode, varop);
  6630.  
  6631.   /* If we can't make the SUBREG, try to return what we were given. */
  6632.   if (GET_CODE (varop) == CLOBBER)
  6633.     return x ? x : varop;
  6634.  
  6635.   /* If we are only masking insignificant bits, return VAROP.  */
  6636.   if (constop == nonzero)
  6637.     x = varop;
  6638.  
  6639.   /* Otherwise, return an AND.  See how much, if any, of X we can use.  */
  6640.   else if (x == 0 || GET_CODE (x) != AND || GET_MODE (x) != mode)
  6641.     x = gen_binary (AND, mode, varop, GEN_INT (constop));
  6642.  
  6643.   else
  6644.     {
  6645.       if (GET_CODE (XEXP (x, 1)) != CONST_INT
  6646.       || INTVAL (XEXP (x, 1)) != constop)
  6647.     SUBST (XEXP (x, 1), GEN_INT (constop));
  6648.  
  6649.       SUBST (XEXP (x, 0), varop);
  6650.     }
  6651.  
  6652.   return x;
  6653. }
  6654.  
  6655. /* Given an expression, X, compute which bits in X can be non-zero.
  6656.    We don't care about bits outside of those defined in MODE.
  6657.  
  6658.    For most X this is simply GET_MODE_MASK (GET_MODE (MODE)), but if X is
  6659.    a shift, AND, or zero_extract, we can do better.  */
  6660.  
  6661. static unsigned HOST_WIDE_INT
  6662. nonzero_bits (x, mode)
  6663.      rtx x;
  6664.      enum machine_mode mode;
  6665. {
  6666.   unsigned HOST_WIDE_INT nonzero = GET_MODE_MASK (mode);
  6667.   unsigned HOST_WIDE_INT inner_nz;
  6668.   enum rtx_code code;
  6669.   int mode_width = GET_MODE_BITSIZE (mode);
  6670.   rtx tem;
  6671.  
  6672.   /* For floating-point values, assume all bits are needed.  */
  6673.   if (FLOAT_MODE_P (GET_MODE (x)) || FLOAT_MODE_P (mode))
  6674.     return nonzero;
  6675.  
  6676.   /* If X is wider than MODE, use its mode instead.  */
  6677.   if (GET_MODE_BITSIZE (GET_MODE (x)) > mode_width)
  6678.     {
  6679.       mode = GET_MODE (x);
  6680.       nonzero = GET_MODE_MASK (mode);
  6681.       mode_width = GET_MODE_BITSIZE (mode);
  6682.     }
  6683.  
  6684.   if (mode_width > HOST_BITS_PER_WIDE_INT)
  6685.     /* Our only callers in this case look for single bit values.  So
  6686.        just return the mode mask.  Those tests will then be false.  */
  6687.     return nonzero;
  6688.  
  6689. #ifndef WORD_REGISTER_OPERATIONS
  6690.   /* If MODE is wider than X, but both are a single word for both the host
  6691.      and target machines, we can compute this from which bits of the 
  6692.      object might be nonzero in its own mode, taking into account the fact
  6693.      that on many CISC machines, accessing an object in a wider mode
  6694.      causes the high-order bits to become undefined.  So they are
  6695.      not known to be zero.  */
  6696.  
  6697.   if (GET_MODE (x) != VOIDmode && GET_MODE (x) != mode
  6698.       && GET_MODE_BITSIZE (GET_MODE (x)) <= BITS_PER_WORD
  6699.       && GET_MODE_BITSIZE (GET_MODE (x)) <= HOST_BITS_PER_WIDE_INT
  6700.       && GET_MODE_BITSIZE (mode) > GET_MODE_BITSIZE (GET_MODE (x)))
  6701.     {
  6702.       nonzero &= nonzero_bits (x, GET_MODE (x));
  6703.       nonzero |= GET_MODE_MASK (mode) & ~ GET_MODE_MASK (GET_MODE (x));
  6704.       return nonzero;
  6705.     }
  6706. #endif
  6707.  
  6708.   code = GET_CODE (x);
  6709.   switch (code)
  6710.     {
  6711.     case REG:
  6712. #ifdef STACK_BOUNDARY
  6713.       /* If this is the stack pointer, we may know something about its
  6714.      alignment.  If PUSH_ROUNDING is defined, it is possible for the
  6715.      stack to be momentarily aligned only to that amount, so we pick
  6716.      the least alignment.  */
  6717.  
  6718.       if (x == stack_pointer_rtx)
  6719.     {
  6720.       int sp_alignment = STACK_BOUNDARY / BITS_PER_UNIT;
  6721.  
  6722. #ifdef PUSH_ROUNDING
  6723.       sp_alignment = MIN (PUSH_ROUNDING (1), sp_alignment);
  6724. #endif
  6725.  
  6726.       return nonzero & ~ (sp_alignment - 1);
  6727.     }
  6728. #endif
  6729.  
  6730.       /* If X is a register whose nonzero bits value is current, use it.
  6731.      Otherwise, if X is a register whose value we can find, use that
  6732.      value.  Otherwise, use the previously-computed global nonzero bits
  6733.      for this register.  */
  6734.  
  6735.       if (reg_last_set_value[REGNO (x)] != 0
  6736.       && reg_last_set_mode[REGNO (x)] == mode
  6737.       && (reg_n_sets[REGNO (x)] == 1
  6738.           || reg_last_set_label[REGNO (x)] == label_tick)
  6739.       && INSN_CUID (reg_last_set[REGNO (x)]) < subst_low_cuid)
  6740.     return reg_last_set_nonzero_bits[REGNO (x)];
  6741.  
  6742.       tem = get_last_value (x);
  6743.  
  6744.       if (tem)
  6745.     {
  6746. #ifdef SHORT_IMMEDIATES_SIGN_EXTEND
  6747.       /* If X is narrower than MODE and TEM is a non-negative
  6748.          constant that would appear negative in the mode of X,
  6749.          sign-extend it for use in reg_nonzero_bits because some
  6750.          machines (maybe most) will actually do the sign-extension
  6751.          and this is the conservative approach. 
  6752.  
  6753.          ??? For 2.5, try to tighten up the MD files in this regard
  6754.          instead of this kludge.  */
  6755.  
  6756.       if (GET_MODE_BITSIZE (GET_MODE (x)) < mode_width
  6757.           && GET_CODE (tem) == CONST_INT
  6758.           && INTVAL (tem) > 0
  6759.           && 0 != (INTVAL (tem)
  6760.                & ((HOST_WIDE_INT) 1
  6761.               << (GET_MODE_BITSIZE (GET_MODE (x)) - 1))))
  6762.         tem = GEN_INT (INTVAL (tem)
  6763.                | ((HOST_WIDE_INT) (-1)
  6764.                   << GET_MODE_BITSIZE (GET_MODE (x))));
  6765. #endif
  6766.       return nonzero_bits (tem, mode);
  6767.     }
  6768.       else if (nonzero_sign_valid && reg_nonzero_bits[REGNO (x)])
  6769.     return reg_nonzero_bits[REGNO (x)] & nonzero;
  6770.       else
  6771.     return nonzero;
  6772.  
  6773.     case CONST_INT:
  6774. #ifdef SHORT_IMMEDIATES_SIGN_EXTEND
  6775.       /* If X is negative in MODE, sign-extend the value.  */
  6776.       if (INTVAL (x) > 0 && mode_width < BITS_PER_WORD
  6777.       && 0 != (INTVAL (x) & ((HOST_WIDE_INT) 1 << (mode_width - 1))))
  6778.     return (INTVAL (x) | ((HOST_WIDE_INT) (-1) << mode_width));
  6779. #endif
  6780.  
  6781.       return INTVAL (x);
  6782.  
  6783.     case MEM:
  6784. #ifdef LOAD_EXTEND_OP
  6785.       /* In many, if not most, RISC machines, reading a byte from memory
  6786.      zeros the rest of the register.  Noticing that fact saves a lot
  6787.      of extra zero-extends.  */
  6788.       if (LOAD_EXTEND_OP (GET_MODE (x)) == ZERO_EXTEND)
  6789.     nonzero &= GET_MODE_MASK (GET_MODE (x));
  6790. #endif
  6791.       break;
  6792.  
  6793.     case EQ:  case NE:
  6794.     case GT:  case GTU:
  6795.     case LT:  case LTU:
  6796.     case GE:  case GEU:
  6797.     case LE:  case LEU:
  6798.  
  6799.       /* If this produces an integer result, we know which bits are set.
  6800.      Code here used to clear bits outside the mode of X, but that is
  6801.      now done above.  */
  6802.  
  6803.       if (GET_MODE_CLASS (mode) == MODE_INT
  6804.       && mode_width <= HOST_BITS_PER_WIDE_INT)
  6805.     nonzero = STORE_FLAG_VALUE;
  6806.       break;
  6807.  
  6808.     case NEG:
  6809.       if (num_sign_bit_copies (XEXP (x, 0), GET_MODE (x))
  6810.       == GET_MODE_BITSIZE (GET_MODE (x)))
  6811.     nonzero = 1;
  6812.  
  6813.       if (GET_MODE_SIZE (GET_MODE (x)) < mode_width)
  6814.     nonzero |= (GET_MODE_MASK (mode) & ~ GET_MODE_MASK (GET_MODE (x)));
  6815.       break;
  6816.  
  6817.     case ABS:
  6818.       if (num_sign_bit_copies (XEXP (x, 0), GET_MODE (x))
  6819.       == GET_MODE_BITSIZE (GET_MODE (x)))
  6820.     nonzero = 1;
  6821.       break;
  6822.  
  6823.     case TRUNCATE:
  6824.       nonzero &= (nonzero_bits (XEXP (x, 0), mode) & GET_MODE_MASK (mode));
  6825.       break;
  6826.  
  6827.     case ZERO_EXTEND:
  6828.       nonzero &= nonzero_bits (XEXP (x, 0), mode);
  6829.       if (GET_MODE (XEXP (x, 0)) != VOIDmode)
  6830.     nonzero &= GET_MODE_MASK (GET_MODE (XEXP (x, 0)));
  6831.       break;
  6832.  
  6833.     case SIGN_EXTEND:
  6834.       /* If the sign bit is known clear, this is the same as ZERO_EXTEND.
  6835.      Otherwise, show all the bits in the outer mode but not the inner
  6836.      may be non-zero.  */
  6837.       inner_nz = nonzero_bits (XEXP (x, 0), mode);
  6838.       if (GET_MODE (XEXP (x, 0)) != VOIDmode)
  6839.     {
  6840.       inner_nz &= GET_MODE_MASK (GET_MODE (XEXP (x, 0)));
  6841.       if (inner_nz &
  6842.           (((HOST_WIDE_INT) 1
  6843.         << (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) - 1))))
  6844.         inner_nz |= (GET_MODE_MASK (mode)
  6845.               & ~ GET_MODE_MASK (GET_MODE (XEXP (x, 0))));
  6846.     }
  6847.  
  6848.       nonzero &= inner_nz;
  6849.       break;
  6850.  
  6851.     case AND:
  6852.       nonzero &= (nonzero_bits (XEXP (x, 0), mode)
  6853.           & nonzero_bits (XEXP (x, 1), mode));
  6854.       break;
  6855.  
  6856.     case XOR:   case IOR:
  6857.     case UMIN:  case UMAX:  case SMIN:  case SMAX:
  6858.       nonzero &= (nonzero_bits (XEXP (x, 0), mode)
  6859.           | nonzero_bits (XEXP (x, 1), mode));
  6860.       break;
  6861.  
  6862.     case PLUS:  case MINUS:
  6863.     case MULT:
  6864.     case DIV:   case UDIV:
  6865.     case MOD:   case UMOD:
  6866.       /* We can apply the rules of arithmetic to compute the number of
  6867.      high- and low-order zero bits of these operations.  We start by
  6868.      computing the width (position of the highest-order non-zero bit)
  6869.      and the number of low-order zero bits for each value.  */
  6870.       {
  6871.     unsigned HOST_WIDE_INT nz0 = nonzero_bits (XEXP (x, 0), mode);
  6872.     unsigned HOST_WIDE_INT nz1 = nonzero_bits (XEXP (x, 1), mode);
  6873.     int width0 = floor_log2 (nz0) + 1;
  6874.     int width1 = floor_log2 (nz1) + 1;
  6875.     int low0 = floor_log2 (nz0 & -nz0);
  6876.     int low1 = floor_log2 (nz1 & -nz1);
  6877.     int op0_maybe_minusp = (nz0 & ((HOST_WIDE_INT) 1 << (mode_width - 1)));
  6878.     int op1_maybe_minusp = (nz1 & ((HOST_WIDE_INT) 1 << (mode_width - 1)));
  6879.     int result_width = mode_width;
  6880.     int result_low = 0;
  6881.  
  6882.     switch (code)
  6883.       {
  6884.       case PLUS:
  6885.         result_width = MAX (width0, width1) + 1;
  6886.         result_low = MIN (low0, low1);
  6887.         break;
  6888.       case MINUS:
  6889.         result_low = MIN (low0, low1);
  6890.         break;
  6891.       case MULT:
  6892.         result_width = width0 + width1;
  6893.         result_low = low0 + low1;
  6894.         break;
  6895.       case DIV:
  6896.         if (! op0_maybe_minusp && ! op1_maybe_minusp)
  6897.           result_width = width0;
  6898.         break;
  6899.       case UDIV:
  6900.         result_width = width0;
  6901.         break;
  6902.       case MOD:
  6903.         if (! op0_maybe_minusp && ! op1_maybe_minusp)
  6904.           result_width = MIN (width0, width1);
  6905.         result_low = MIN (low0, low1);
  6906.         break;
  6907.       case UMOD:
  6908.         result_width = MIN (width0, width1);
  6909.         result_low = MIN (low0, low1);
  6910.         break;
  6911.       }
  6912.  
  6913.     if (result_width < mode_width)
  6914.       nonzero &= ((HOST_WIDE_INT) 1 << result_width) - 1;
  6915.  
  6916.     if (result_low > 0)
  6917.       nonzero &= ~ (((HOST_WIDE_INT) 1 << result_low) - 1);
  6918.       }
  6919.       break;
  6920.  
  6921.     case ZERO_EXTRACT:
  6922.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  6923.       && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT)
  6924.     nonzero &= ((HOST_WIDE_INT) 1 << INTVAL (XEXP (x, 1))) - 1;
  6925.       break;
  6926.  
  6927.     case SUBREG:
  6928.       /* If this is a SUBREG formed for a promoted variable that has
  6929.      been zero-extended, we know that at least the high-order bits
  6930.      are zero, though others might be too.  */
  6931.  
  6932.       if (SUBREG_PROMOTED_VAR_P (x) && SUBREG_PROMOTED_UNSIGNED_P (x))
  6933.     nonzero = (GET_MODE_MASK (GET_MODE (x))
  6934.            & nonzero_bits (SUBREG_REG (x), GET_MODE (x)));
  6935.  
  6936.       /* If the inner mode is a single word for both the host and target
  6937.      machines, we can compute this from which bits of the inner
  6938.      object might be nonzero.  */
  6939.       if (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))) <= BITS_PER_WORD
  6940.       && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x)))
  6941.           <= HOST_BITS_PER_WIDE_INT))
  6942.     {
  6943.       nonzero &= nonzero_bits (SUBREG_REG (x), mode);
  6944.  
  6945. #ifndef WORD_REGISTER_OPERATIONS
  6946.       /* On many CISC machines, accessing an object in a wider mode
  6947.          causes the high-order bits to become undefined.  So they are
  6948.          not known to be zero.  */
  6949.       if (GET_MODE_SIZE (GET_MODE (x))
  6950.           > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  6951.         nonzero |= (GET_MODE_MASK (GET_MODE (x))
  6952.             & ~ GET_MODE_MASK (GET_MODE (SUBREG_REG (x))));
  6953. #endif
  6954.     }
  6955.       break;
  6956.  
  6957.     case ASHIFTRT:
  6958.     case LSHIFTRT:
  6959.     case ASHIFT:
  6960.     case ROTATE:
  6961.       /* The nonzero bits are in two classes: any bits within MODE
  6962.      that aren't in GET_MODE (x) are always significant.  The rest of the
  6963.      nonzero bits are those that are significant in the operand of
  6964.      the shift when shifted the appropriate number of bits.  This
  6965.      shows that high-order bits are cleared by the right shift and
  6966.      low-order bits by left shifts.  */
  6967.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  6968.       && INTVAL (XEXP (x, 1)) >= 0
  6969.       && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT)
  6970.     {
  6971.       enum machine_mode inner_mode = GET_MODE (x);
  6972.       int width = GET_MODE_BITSIZE (inner_mode);
  6973.       int count = INTVAL (XEXP (x, 1));
  6974.       unsigned HOST_WIDE_INT mode_mask = GET_MODE_MASK (inner_mode);
  6975.       unsigned HOST_WIDE_INT op_nonzero = nonzero_bits (XEXP (x, 0), mode);
  6976.       unsigned HOST_WIDE_INT inner = op_nonzero & mode_mask;
  6977.       unsigned HOST_WIDE_INT outer = 0;
  6978.  
  6979.       if (mode_width > width)
  6980.         outer = (op_nonzero & nonzero & ~ mode_mask);
  6981.  
  6982.       if (code == LSHIFTRT)
  6983.         inner >>= count;
  6984.       else if (code == ASHIFTRT)
  6985.         {
  6986.           inner >>= count;
  6987.  
  6988.           /* If the sign bit may have been nonzero before the shift, we
  6989.          need to mark all the places it could have been copied to
  6990.          by the shift as possibly nonzero.  */
  6991.           if (inner & ((HOST_WIDE_INT) 1 << (width - 1 - count)))
  6992.         inner |= (((HOST_WIDE_INT) 1 << count) - 1) << (width - count);
  6993.         }
  6994.       else if (code == ASHIFT)
  6995.         inner <<= count;
  6996.       else
  6997.         inner = ((inner << (count % width)
  6998.               | (inner >> (width - (count % width)))) & mode_mask);
  6999.  
  7000.       nonzero &= (outer | inner);
  7001.     }
  7002.       break;
  7003.  
  7004.     case FFS:
  7005.       /* This is at most the number of bits in the mode.  */
  7006.       nonzero = ((HOST_WIDE_INT) 1 << (floor_log2 (mode_width) + 1)) - 1;
  7007.       break;
  7008.  
  7009.     case IF_THEN_ELSE:
  7010.       nonzero &= (nonzero_bits (XEXP (x, 1), mode)
  7011.           | nonzero_bits (XEXP (x, 2), mode));
  7012.       break;
  7013.     }
  7014.  
  7015.   return nonzero;
  7016. }
  7017.  
  7018. /* Return the number of bits at the high-order end of X that are known to
  7019.    be equal to the sign bit.  X will be used in mode MODE; if MODE is
  7020.    VOIDmode, X will be used in its own mode.  The returned value  will always
  7021.    be between 1 and the number of bits in MODE.  */
  7022.  
  7023. static int
  7024. num_sign_bit_copies (x, mode)
  7025.      rtx x;
  7026.      enum machine_mode mode;
  7027. {
  7028.   enum rtx_code code = GET_CODE (x);
  7029.   int bitwidth;
  7030.   int num0, num1, result;
  7031.   unsigned HOST_WIDE_INT nonzero;
  7032.   rtx tem;
  7033.  
  7034.   /* If we weren't given a mode, use the mode of X.  If the mode is still
  7035.      VOIDmode, we don't know anything.  Likewise if one of the modes is
  7036.      floating-point.  */
  7037.  
  7038.   if (mode == VOIDmode)
  7039.     mode = GET_MODE (x);
  7040.  
  7041.   if (mode == VOIDmode || FLOAT_MODE_P (mode) || FLOAT_MODE_P (GET_MODE (x)))
  7042.     return 1;
  7043.  
  7044.   bitwidth = GET_MODE_BITSIZE (mode);
  7045.  
  7046.   /* For a smaller object, just ignore the high bits. */
  7047.   if (bitwidth < GET_MODE_BITSIZE (GET_MODE (x)))
  7048.     return MAX (1, (num_sign_bit_copies (x, GET_MODE (x))
  7049.             - (GET_MODE_BITSIZE (GET_MODE (x)) - bitwidth)));
  7050.      
  7051. #ifndef WORD_REGISTER_OPERATIONS
  7052.   /* If this machine does not do all register operations on the entire
  7053.      register and MODE is wider than the mode of X, we can say nothing
  7054.      at all about the high-order bits.  */
  7055.   if (GET_MODE (x) != VOIDmode && bitwidth > GET_MODE_BITSIZE (GET_MODE (x)))
  7056.     return 1;
  7057. #endif
  7058.  
  7059.   switch (code)
  7060.     {
  7061.     case REG:
  7062.  
  7063.       if (reg_last_set_value[REGNO (x)] != 0
  7064.       && reg_last_set_mode[REGNO (x)] == mode
  7065.       && (reg_n_sets[REGNO (x)] == 1
  7066.           || reg_last_set_label[REGNO (x)] == label_tick)
  7067.       && INSN_CUID (reg_last_set[REGNO (x)]) < subst_low_cuid)
  7068.     return reg_last_set_sign_bit_copies[REGNO (x)];
  7069.  
  7070.       tem =  get_last_value (x);
  7071.       if (tem != 0)
  7072.     return num_sign_bit_copies (tem, mode);
  7073.  
  7074.       if (nonzero_sign_valid && reg_sign_bit_copies[REGNO (x)] != 0)
  7075.     return reg_sign_bit_copies[REGNO (x)];
  7076.       break;
  7077.  
  7078.     case MEM:
  7079. #ifdef LOAD_EXTEND_OP
  7080.       /* Some RISC machines sign-extend all loads of smaller than a word.  */
  7081.       if (LOAD_EXTEND_OP (GET_MODE (x)) == SIGN_EXTEND)
  7082.     return MAX (1, bitwidth - GET_MODE_BITSIZE (GET_MODE (x)) + 1);
  7083. #endif
  7084.       break;
  7085.  
  7086.     case CONST_INT:
  7087.       /* If the constant is negative, take its 1's complement and remask.
  7088.      Then see how many zero bits we have.  */
  7089.       nonzero = INTVAL (x) & GET_MODE_MASK (mode);
  7090.       if (bitwidth <= HOST_BITS_PER_WIDE_INT
  7091.       && (nonzero & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  7092.     nonzero = (~ nonzero) & GET_MODE_MASK (mode);
  7093.  
  7094.       return (nonzero == 0 ? bitwidth : bitwidth - floor_log2 (nonzero) - 1);
  7095.  
  7096.     case SUBREG:
  7097.       /* If this is a SUBREG for a promoted object that is sign-extended
  7098.      and we are looking at it in a wider mode, we know that at least the
  7099.      high-order bits are known to be sign bit copies.  */
  7100.  
  7101.       if (SUBREG_PROMOTED_VAR_P (x) && ! SUBREG_PROMOTED_UNSIGNED_P (x))
  7102.     return MAX (bitwidth - GET_MODE_BITSIZE (GET_MODE (x)) + 1,
  7103.             num_sign_bit_copies (SUBREG_REG (x), mode));
  7104.  
  7105.       /* For a smaller object, just ignore the high bits. */
  7106.       if (bitwidth <= GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))))
  7107.     {
  7108.       num0 = num_sign_bit_copies (SUBREG_REG (x), VOIDmode);
  7109.       return MAX (1, (num0
  7110.               - (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x)))
  7111.                  - bitwidth)));
  7112.     }
  7113.  
  7114. #ifdef WORD_REGISTER_OPERATIONS
  7115.       /* For paradoxical SUBREGs on machines where all register operations
  7116.      affect the entire register, just look inside.  Note that we are
  7117.      passing MODE to the recursive call, so the number of sign bit copies
  7118.      will remain relative to that mode, not the inner mode.  */
  7119.  
  7120.       if (GET_MODE_SIZE (GET_MODE (x))
  7121.       > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  7122.     return num_sign_bit_copies (SUBREG_REG (x), mode);
  7123. #endif
  7124.       break;
  7125.  
  7126.     case SIGN_EXTRACT:
  7127.       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  7128.     return MAX (1, bitwidth - INTVAL (XEXP (x, 1)));
  7129.       break;
  7130.  
  7131.     case SIGN_EXTEND: 
  7132.       return (bitwidth - GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))
  7133.           + num_sign_bit_copies (XEXP (x, 0), VOIDmode));
  7134.  
  7135.     case TRUNCATE:
  7136.       /* For a smaller object, just ignore the high bits. */
  7137.       num0 = num_sign_bit_copies (XEXP (x, 0), VOIDmode);
  7138.       return MAX (1, (num0 - (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))
  7139.                   - bitwidth)));
  7140.  
  7141.     case NOT:
  7142.       return num_sign_bit_copies (XEXP (x, 0), mode);
  7143.  
  7144.     case ROTATE:       case ROTATERT:
  7145.       /* If we are rotating left by a number of bits less than the number
  7146.      of sign bit copies, we can just subtract that amount from the
  7147.      number.  */
  7148.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  7149.       && INTVAL (XEXP (x, 1)) >= 0 && INTVAL (XEXP (x, 1)) < bitwidth)
  7150.     {
  7151.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  7152.       return MAX (1, num0 - (code == ROTATE ? INTVAL (XEXP (x, 1))
  7153.                  : bitwidth - INTVAL (XEXP (x, 1))));
  7154.     }
  7155.       break;
  7156.  
  7157.     case NEG:
  7158.       /* In general, this subtracts one sign bit copy.  But if the value
  7159.      is known to be positive, the number of sign bit copies is the
  7160.      same as that of the input.  Finally, if the input has just one bit
  7161.      that might be nonzero, all the bits are copies of the sign bit.  */
  7162.       nonzero = nonzero_bits (XEXP (x, 0), mode);
  7163.       if (nonzero == 1)
  7164.     return bitwidth;
  7165.  
  7166.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  7167.       if (num0 > 1
  7168.       && bitwidth <= HOST_BITS_PER_WIDE_INT
  7169.       && (((HOST_WIDE_INT) 1 << (bitwidth - 1)) & nonzero))
  7170.     num0--;
  7171.  
  7172.       return num0;
  7173.  
  7174.     case IOR:   case AND:   case XOR:
  7175.     case SMIN:  case SMAX:  case UMIN:  case UMAX:
  7176.       /* Logical operations will preserve the number of sign-bit copies.
  7177.      MIN and MAX operations always return one of the operands.  */
  7178.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  7179.       num1 = num_sign_bit_copies (XEXP (x, 1), mode);
  7180.       return MIN (num0, num1);
  7181.  
  7182.     case PLUS:  case MINUS:
  7183.       /* For addition and subtraction, we can have a 1-bit carry.  However,
  7184.      if we are subtracting 1 from a positive number, there will not
  7185.      be such a carry.  Furthermore, if the positive number is known to
  7186.      be 0 or 1, we know the result is either -1 or 0.  */
  7187.  
  7188.       if (code == PLUS && XEXP (x, 1) == constm1_rtx
  7189.       && bitwidth <= HOST_BITS_PER_WIDE_INT)
  7190.     {
  7191.       nonzero = nonzero_bits (XEXP (x, 0), mode);
  7192.       if ((((HOST_WIDE_INT) 1 << (bitwidth - 1)) & nonzero) == 0)
  7193.         return (nonzero == 1 || nonzero == 0 ? bitwidth
  7194.             : bitwidth - floor_log2 (nonzero) - 1);
  7195.     }
  7196.  
  7197.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  7198.       num1 = num_sign_bit_copies (XEXP (x, 1), mode);
  7199.       return MAX (1, MIN (num0, num1) - 1);
  7200.       
  7201.     case MULT:
  7202.       /* The number of bits of the product is the sum of the number of
  7203.      bits of both terms.  However, unless one of the terms if known
  7204.      to be positive, we must allow for an additional bit since negating
  7205.      a negative number can remove one sign bit copy.  */
  7206.  
  7207.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  7208.       num1 = num_sign_bit_copies (XEXP (x, 1), mode);
  7209.  
  7210.       result = bitwidth - (bitwidth - num0) - (bitwidth - num1);
  7211.       if (result > 0
  7212.       && bitwidth <= HOST_BITS_PER_WIDE_INT
  7213.       && ((nonzero_bits (XEXP (x, 0), mode)
  7214.            & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  7215.       && (nonzero_bits (XEXP (x, 1), mode)
  7216.           & ((HOST_WIDE_INT) 1 << (bitwidth - 1)) != 0))
  7217.     result--;
  7218.  
  7219.       return MAX (1, result);
  7220.  
  7221.     case UDIV:
  7222.       /* The result must be <= the first operand.  */
  7223.       return num_sign_bit_copies (XEXP (x, 0), mode);
  7224.  
  7225.     case UMOD:
  7226.       /* The result must be <= the scond operand.  */
  7227.       return num_sign_bit_copies (XEXP (x, 1), mode);
  7228.  
  7229.     case DIV:
  7230.       /* Similar to unsigned division, except that we have to worry about
  7231.      the case where the divisor is negative, in which case we have
  7232.      to add 1.  */
  7233.       result = num_sign_bit_copies (XEXP (x, 0), mode);
  7234.       if (result > 1
  7235.       && bitwidth <= HOST_BITS_PER_WIDE_INT
  7236.       && (nonzero_bits (XEXP (x, 1), mode)
  7237.           & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  7238.     result --;
  7239.  
  7240.       return result;
  7241.  
  7242.     case MOD:
  7243.       result = num_sign_bit_copies (XEXP (x, 1), mode);
  7244.       if (result > 1
  7245.       && bitwidth <= HOST_BITS_PER_WIDE_INT
  7246.       && (nonzero_bits (XEXP (x, 1), mode)
  7247.           & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  7248.     result --;
  7249.  
  7250.       return result;
  7251.  
  7252.     case ASHIFTRT:
  7253.       /* Shifts by a constant add to the number of bits equal to the
  7254.      sign bit.  */
  7255.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  7256.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  7257.       && INTVAL (XEXP (x, 1)) > 0)
  7258.     num0 = MIN (bitwidth, num0 + INTVAL (XEXP (x, 1)));
  7259.  
  7260.       return num0;
  7261.  
  7262.     case ASHIFT:
  7263.       /* Left shifts destroy copies.  */
  7264.       if (GET_CODE (XEXP (x, 1)) != CONST_INT
  7265.       || INTVAL (XEXP (x, 1)) < 0
  7266.       || INTVAL (XEXP (x, 1)) >= bitwidth)
  7267.     return 1;
  7268.  
  7269.       num0 = num_sign_bit_copies (XEXP (x, 0), mode);
  7270.       return MAX (1, num0 - INTVAL (XEXP (x, 1)));
  7271.  
  7272.     case IF_THEN_ELSE:
  7273.       num0 = num_sign_bit_copies (XEXP (x, 1), mode);
  7274.       num1 = num_sign_bit_copies (XEXP (x, 2), mode);
  7275.       return MIN (num0, num1);
  7276.  
  7277. #if STORE_FLAG_VALUE == -1
  7278.     case EQ:  case NE:  case GE:  case GT:  case LE:  case LT:
  7279.     case GEU: case GTU: case LEU: case LTU:
  7280.       return bitwidth;
  7281. #endif
  7282.     }
  7283.  
  7284.   /* If we haven't been able to figure it out by one of the above rules,
  7285.      see if some of the high-order bits are known to be zero.  If so,
  7286.      count those bits and return one less than that amount.  If we can't
  7287.      safely compute the mask for this mode, always return BITWIDTH.  */
  7288.  
  7289.   if (bitwidth > HOST_BITS_PER_WIDE_INT)
  7290.     return 1;
  7291.  
  7292.   nonzero = nonzero_bits (x, mode);
  7293.   return (nonzero & ((HOST_WIDE_INT) 1 << (bitwidth - 1))
  7294.       ? 1 : bitwidth - floor_log2 (nonzero) - 1);
  7295. }
  7296.  
  7297. /* Return the number of "extended" bits there are in X, when interpreted
  7298.    as a quantity in MODE whose signedness is indicated by UNSIGNEDP.  For
  7299.    unsigned quantities, this is the number of high-order zero bits.
  7300.    For signed quantities, this is the number of copies of the sign bit
  7301.    minus 1.  In both case, this function returns the number of "spare"
  7302.    bits.  For example, if two quantities for which this function returns
  7303.    at least 1 are added, the addition is known not to overflow.
  7304.  
  7305.    This function will always return 0 unless called during combine, which
  7306.    implies that it must be called from a define_split.  */
  7307.  
  7308. int
  7309. extended_count (x, mode, unsignedp)
  7310.      rtx x;
  7311.      enum machine_mode mode;
  7312.      int unsignedp;
  7313. {
  7314.   if (nonzero_sign_valid == 0)
  7315.     return 0;
  7316.  
  7317.   return (unsignedp
  7318.       ? (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
  7319.          && (GET_MODE_BITSIZE (mode) - 1
  7320.          - floor_log2 (nonzero_bits (x, mode))))
  7321.       : num_sign_bit_copies (x, mode) - 1);
  7322. }
  7323.  
  7324. /* This function is called from `simplify_shift_const' to merge two
  7325.    outer operations.  Specifically, we have already found that we need
  7326.    to perform operation *POP0 with constant *PCONST0 at the outermost
  7327.    position.  We would now like to also perform OP1 with constant CONST1
  7328.    (with *POP0 being done last).
  7329.  
  7330.    Return 1 if we can do the operation and update *POP0 and *PCONST0 with
  7331.    the resulting operation.  *PCOMP_P is set to 1 if we would need to 
  7332.    complement the innermost operand, otherwise it is unchanged.
  7333.  
  7334.    MODE is the mode in which the operation will be done.  No bits outside
  7335.    the width of this mode matter.  It is assumed that the width of this mode
  7336.    is smaller than or equal to HOST_BITS_PER_WIDE_INT.
  7337.  
  7338.    If *POP0 or OP1 are NIL, it means no operation is required.  Only NEG, PLUS,
  7339.    IOR, XOR, and AND are supported.  We may set *POP0 to SET if the proper
  7340.    result is simply *PCONST0.
  7341.  
  7342.    If the resulting operation cannot be expressed as one operation, we
  7343.    return 0 and do not change *POP0, *PCONST0, and *PCOMP_P.  */
  7344.  
  7345. static int
  7346. merge_outer_ops (pop0, pconst0, op1, const1, mode, pcomp_p)
  7347.      enum rtx_code *pop0;
  7348.      HOST_WIDE_INT *pconst0;
  7349.      enum rtx_code op1;
  7350.      HOST_WIDE_INT const1;
  7351.      enum machine_mode mode;
  7352.      int *pcomp_p;
  7353. {
  7354.   enum rtx_code op0 = *pop0;
  7355.   HOST_WIDE_INT const0 = *pconst0;
  7356.  
  7357.   const0 &= GET_MODE_MASK (mode);
  7358.   const1 &= GET_MODE_MASK (mode);
  7359.  
  7360.   /* If OP0 is an AND, clear unimportant bits in CONST1.  */
  7361.   if (op0 == AND)
  7362.     const1 &= const0;
  7363.  
  7364.   /* If OP0 or OP1 is NIL, this is easy.  Similarly if they are the same or
  7365.      if OP0 is SET.  */
  7366.  
  7367.   if (op1 == NIL || op0 == SET)
  7368.     return 1;
  7369.  
  7370.   else if (op0 == NIL)
  7371.     op0 = op1, const0 = const1;
  7372.  
  7373.   else if (op0 == op1)
  7374.     {
  7375.       switch (op0)
  7376.     {
  7377.     case AND:
  7378.       const0 &= const1;
  7379.       break;
  7380.     case IOR:
  7381.       const0 |= const1;
  7382.       break;
  7383.     case XOR:
  7384.       const0 ^= const1;
  7385.       break;
  7386.     case PLUS:
  7387.       const0 += const1;
  7388.       break;
  7389.     case NEG:
  7390.       op0 = NIL;
  7391.       break;
  7392.     }
  7393.     }
  7394.  
  7395.   /* Otherwise, if either is a PLUS or NEG, we can't do anything.  */
  7396.   else if (op0 == PLUS || op1 == PLUS || op0 == NEG || op1 == NEG)
  7397.     return 0;
  7398.  
  7399.   /* If the two constants aren't the same, we can't do anything.  The
  7400.      remaining six cases can all be done.  */
  7401.   else if (const0 != const1)
  7402.     return 0;
  7403.  
  7404.   else
  7405.     switch (op0)
  7406.       {
  7407.       case IOR:
  7408.     if (op1 == AND)
  7409.       /* (a & b) | b == b */
  7410.       op0 = SET;
  7411.     else /* op1 == XOR */
  7412.       /* (a ^ b) | b == a | b */
  7413.       ;
  7414.     break;
  7415.  
  7416.       case XOR:
  7417.     if (op1 == AND)
  7418.       /* (a & b) ^ b == (~a) & b */
  7419.       op0 = AND, *pcomp_p = 1;
  7420.     else /* op1 == IOR */
  7421.       /* (a | b) ^ b == a & ~b */
  7422.       op0 = AND, *pconst0 = ~ const0;
  7423.     break;
  7424.  
  7425.       case AND:
  7426.     if (op1 == IOR)
  7427.       /* (a | b) & b == b */
  7428.     op0 = SET;
  7429.     else /* op1 == XOR */
  7430.       /* (a ^ b) & b) == (~a) & b */
  7431.       *pcomp_p = 1;
  7432.     break;
  7433.       }
  7434.  
  7435.   /* Check for NO-OP cases.  */
  7436.   const0 &= GET_MODE_MASK (mode);
  7437.   if (const0 == 0
  7438.       && (op0 == IOR || op0 == XOR || op0 == PLUS))
  7439.     op0 = NIL;
  7440.   else if (const0 == 0 && op0 == AND)
  7441.     op0 = SET;
  7442.   else if (const0 == GET_MODE_MASK (mode) && op0 == AND)
  7443.     op0 = NIL;
  7444.  
  7445.   *pop0 = op0;
  7446.   *pconst0 = const0;
  7447.  
  7448.   return 1;
  7449. }
  7450.  
  7451. /* Simplify a shift of VAROP by COUNT bits.  CODE says what kind of shift.
  7452.    The result of the shift is RESULT_MODE.  X, if non-zero, is an expression
  7453.    that we started with.
  7454.  
  7455.    The shift is normally computed in the widest mode we find in VAROP, as
  7456.    long as it isn't a different number of words than RESULT_MODE.  Exceptions
  7457.    are ASHIFTRT and ROTATE, which are always done in their original mode,  */
  7458.  
  7459. static rtx
  7460. simplify_shift_const (x, code, result_mode, varop, count)
  7461.      rtx x;
  7462.      enum rtx_code code;
  7463.      enum machine_mode result_mode;
  7464.      rtx varop;
  7465.      int count;
  7466. {
  7467.   enum rtx_code orig_code = code;
  7468.   int orig_count = count;
  7469.   enum machine_mode mode = result_mode;
  7470.   enum machine_mode shift_mode, tmode;
  7471.   int mode_words
  7472.     = (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
  7473.   /* We form (outer_op (code varop count) (outer_const)).  */
  7474.   enum rtx_code outer_op = NIL;
  7475.   HOST_WIDE_INT outer_const = 0;
  7476.   rtx const_rtx;
  7477.   int complement_p = 0;
  7478.   rtx new;
  7479.  
  7480.   /* If we were given an invalid count, don't do anything except exactly
  7481.      what was requested.  */
  7482.  
  7483.   if (count < 0 || count > GET_MODE_BITSIZE (mode))
  7484.     {
  7485.       if (x)
  7486.     return x;
  7487.  
  7488.       return gen_rtx (code, mode, varop, GEN_INT (count));
  7489.     }
  7490.  
  7491.   /* Unless one of the branches of the `if' in this loop does a `continue',
  7492.      we will `break' the loop after the `if'.  */
  7493.  
  7494.   while (count != 0)
  7495.     {
  7496.       /* If we have an operand of (clobber (const_int 0)), just return that
  7497.      value.  */
  7498.       if (GET_CODE (varop) == CLOBBER)
  7499.     return varop;
  7500.  
  7501.       /* If we discovered we had to complement VAROP, leave.  Making a NOT
  7502.      here would cause an infinite loop.  */
  7503.       if (complement_p)
  7504.     break;
  7505.  
  7506.       /* Convert ROTATETRT to ROTATE.  */
  7507.       if (code == ROTATERT)
  7508.     code = ROTATE, count = GET_MODE_BITSIZE (result_mode) - count;
  7509.  
  7510.       /* We need to determine what mode we will do the shift in.  If the
  7511.      shift is a ASHIFTRT or ROTATE, we must always do it in the mode it
  7512.      was originally done in.  Otherwise, we can do it in MODE, the widest
  7513.      mode encountered. */
  7514.       shift_mode = (code == ASHIFTRT || code == ROTATE ? result_mode : mode);
  7515.  
  7516.       /* Handle cases where the count is greater than the size of the mode
  7517.      minus 1.  For ASHIFT, use the size minus one as the count (this can
  7518.      occur when simplifying (lshiftrt (ashiftrt ..))).  For rotates,
  7519.      take the count modulo the size.  For other shifts, the result is
  7520.      zero.
  7521.  
  7522.      Since these shifts are being produced by the compiler by combining
  7523.      multiple operations, each of which are defined, we know what the
  7524.      result is supposed to be.  */
  7525.      
  7526.       if (count > GET_MODE_BITSIZE (shift_mode) - 1)
  7527.     {
  7528.       if (code == ASHIFTRT)
  7529.         count = GET_MODE_BITSIZE (shift_mode) - 1;
  7530.       else if (code == ROTATE || code == ROTATERT)
  7531.         count %= GET_MODE_BITSIZE (shift_mode);
  7532.       else
  7533.         {
  7534.           /* We can't simply return zero because there may be an
  7535.          outer op.  */
  7536.           varop = const0_rtx;
  7537.           count = 0;
  7538.           break;
  7539.         }
  7540.     }
  7541.  
  7542.       /* Negative counts are invalid and should not have been made (a
  7543.      programmer-specified negative count should have been handled
  7544.      above). */
  7545.       else if (count < 0)
  7546.     abort ();
  7547.  
  7548.       /* An arithmetic right shift of a quantity known to be -1 or 0
  7549.      is a no-op.  */
  7550.       if (code == ASHIFTRT
  7551.       && (num_sign_bit_copies (varop, shift_mode)
  7552.           == GET_MODE_BITSIZE (shift_mode)))
  7553.     {
  7554.       count = 0;
  7555.       break;
  7556.     }
  7557.  
  7558.       /* If we are doing an arithmetic right shift and discarding all but
  7559.      the sign bit copies, this is equivalent to doing a shift by the
  7560.      bitsize minus one.  Convert it into that shift because it will often
  7561.      allow other simplifications.  */
  7562.  
  7563.       if (code == ASHIFTRT
  7564.       && (count + num_sign_bit_copies (varop, shift_mode)
  7565.           >= GET_MODE_BITSIZE (shift_mode)))
  7566.     count = GET_MODE_BITSIZE (shift_mode) - 1;
  7567.  
  7568.       /* We simplify the tests below and elsewhere by converting
  7569.      ASHIFTRT to LSHIFTRT if we know the sign bit is clear.
  7570.      `make_compound_operation' will convert it to a ASHIFTRT for
  7571.      those machines (such as Vax) that don't have a LSHIFTRT.  */
  7572.       if (GET_MODE_BITSIZE (shift_mode) <= HOST_BITS_PER_WIDE_INT
  7573.       && code == ASHIFTRT
  7574.       && ((nonzero_bits (varop, shift_mode)
  7575.            & ((HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (shift_mode) - 1)))
  7576.           == 0))
  7577.     code = LSHIFTRT;
  7578.  
  7579.       switch (GET_CODE (varop))
  7580.     {
  7581.     case SIGN_EXTEND:
  7582.     case ZERO_EXTEND:
  7583.     case SIGN_EXTRACT:
  7584.     case ZERO_EXTRACT:
  7585.       new = expand_compound_operation (varop);
  7586.       if (new != varop)
  7587.         {
  7588.           varop = new;
  7589.           continue;
  7590.         }
  7591.       break;
  7592.  
  7593.     case MEM:
  7594.       /* If we have (xshiftrt (mem ...) C) and C is MODE_WIDTH
  7595.          minus the width of a smaller mode, we can do this with a
  7596.          SIGN_EXTEND or ZERO_EXTEND from the narrower memory location.  */
  7597.       if ((code == ASHIFTRT || code == LSHIFTRT)
  7598.           && ! mode_dependent_address_p (XEXP (varop, 0))
  7599.           && ! MEM_VOLATILE_P (varop)
  7600.           && (tmode = mode_for_size (GET_MODE_BITSIZE (mode) - count,
  7601.                      MODE_INT, 1)) != BLKmode)
  7602.         {
  7603. #if BYTES_BIG_ENDIAN
  7604.           new = gen_rtx (MEM, tmode, XEXP (varop, 0));
  7605. #else
  7606.           new = gen_rtx (MEM, tmode,
  7607.                  plus_constant (XEXP (varop, 0),
  7608.                         count / BITS_PER_UNIT));
  7609.           RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (varop);
  7610.           MEM_VOLATILE_P (new) = MEM_VOLATILE_P (varop);
  7611.           MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (varop);
  7612. #endif
  7613.           varop = gen_rtx_combine (code == ASHIFTRT ? SIGN_EXTEND
  7614.                        : ZERO_EXTEND, mode, new);
  7615.           count = 0;
  7616.           continue;
  7617.         }
  7618.       break;
  7619.  
  7620.     case USE:
  7621.       /* Similar to the case above, except that we can only do this if
  7622.          the resulting mode is the same as that of the underlying
  7623.          MEM and adjust the address depending on the *bits* endianness
  7624.          because of the way that bit-field extract insns are defined.  */
  7625.       if ((code == ASHIFTRT || code == LSHIFTRT)
  7626.           && (tmode = mode_for_size (GET_MODE_BITSIZE (mode) - count,
  7627.                      MODE_INT, 1)) != BLKmode
  7628.           && tmode == GET_MODE (XEXP (varop, 0)))
  7629.         {
  7630. #if BITS_BIG_ENDIAN
  7631.           new = XEXP (varop, 0);
  7632. #else
  7633.           new = copy_rtx (XEXP (varop, 0));
  7634.           SUBST (XEXP (new, 0), 
  7635.              plus_constant (XEXP (new, 0),
  7636.                     count / BITS_PER_UNIT));
  7637. #endif
  7638.  
  7639.           varop = gen_rtx_combine (code == ASHIFTRT ? SIGN_EXTEND
  7640.                        : ZERO_EXTEND, mode, new);
  7641.           count = 0;
  7642.           continue;
  7643.         }
  7644.       break;
  7645.  
  7646.     case SUBREG:
  7647.       /* If VAROP is a SUBREG, strip it as long as the inner operand has
  7648.          the same number of words as what we've seen so far.  Then store
  7649.          the widest mode in MODE.  */
  7650.       if (subreg_lowpart_p (varop)
  7651.           && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop)))
  7652.           > GET_MODE_SIZE (GET_MODE (varop)))
  7653.           && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop)))
  7654.             + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
  7655.           == mode_words))
  7656.         {
  7657.           varop = SUBREG_REG (varop);
  7658.           if (GET_MODE_SIZE (GET_MODE (varop)) > GET_MODE_SIZE (mode))
  7659.         mode = GET_MODE (varop);
  7660.           continue;
  7661.         }
  7662.       break;
  7663.  
  7664.     case MULT:
  7665.       /* Some machines use MULT instead of ASHIFT because MULT
  7666.          is cheaper.  But it is still better on those machines to
  7667.          merge two shifts into one.  */
  7668.       if (GET_CODE (XEXP (varop, 1)) == CONST_INT
  7669.           && exact_log2 (INTVAL (XEXP (varop, 1))) >= 0)
  7670.         {
  7671.           varop = gen_binary (ASHIFT, GET_MODE (varop), XEXP (varop, 0),
  7672.                   GEN_INT (exact_log2 (INTVAL (XEXP (varop, 1)))));;
  7673.           continue;
  7674.         }
  7675.       break;
  7676.  
  7677.     case UDIV:
  7678.       /* Similar, for when divides are cheaper.  */
  7679.       if (GET_CODE (XEXP (varop, 1)) == CONST_INT
  7680.           && exact_log2 (INTVAL (XEXP (varop, 1))) >= 0)
  7681.         {
  7682.           varop = gen_binary (LSHIFTRT, GET_MODE (varop), XEXP (varop, 0),
  7683.                   GEN_INT (exact_log2 (INTVAL (XEXP (varop, 1)))));
  7684.           continue;
  7685.         }
  7686.       break;
  7687.  
  7688.     case ASHIFTRT:
  7689.       /* If we are extracting just the sign bit of an arithmetic right 
  7690.          shift, that shift is not needed.  */
  7691.       if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1)
  7692.         {
  7693.           varop = XEXP (varop, 0);
  7694.           continue;
  7695.         }
  7696.  
  7697.       /* ... fall through ... */
  7698.  
  7699.     case LSHIFTRT:
  7700.     case ASHIFT:
  7701.     case ROTATE:
  7702.       /* Here we have two nested shifts.  The result is usually the
  7703.          AND of a new shift with a mask.  We compute the result below.  */
  7704.       if (GET_CODE (XEXP (varop, 1)) == CONST_INT
  7705.           && INTVAL (XEXP (varop, 1)) >= 0
  7706.           && INTVAL (XEXP (varop, 1)) < GET_MODE_BITSIZE (GET_MODE (varop))
  7707.           && GET_MODE_BITSIZE (result_mode) <= HOST_BITS_PER_WIDE_INT
  7708.           && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
  7709.         {
  7710.           enum rtx_code first_code = GET_CODE (varop);
  7711.           int first_count = INTVAL (XEXP (varop, 1));
  7712.           unsigned HOST_WIDE_INT mask;
  7713.           rtx mask_rtx;
  7714.  
  7715.           /* We have one common special case.  We can't do any merging if
  7716.          the inner code is an ASHIFTRT of a smaller mode.  However, if
  7717.          we have (ashift:M1 (subreg:M1 (ashiftrt:M2 FOO C1) 0) C2)
  7718.          with C2 == GET_MODE_BITSIZE (M1) - GET_MODE_BITSIZE (M2),
  7719.          we can convert it to
  7720.          (ashiftrt:M1 (ashift:M1 (and:M1 (subreg:M1 FOO 0 C2) C3) C1).
  7721.          This simplifies certain SIGN_EXTEND operations.  */
  7722.           if (code == ASHIFT && first_code == ASHIFTRT
  7723.           && (GET_MODE_BITSIZE (result_mode)
  7724.               - GET_MODE_BITSIZE (GET_MODE (varop))) == count)
  7725.         {
  7726.           /* C3 has the low-order C1 bits zero.  */
  7727.           
  7728.           mask = (GET_MODE_MASK (mode)
  7729.               & ~ (((HOST_WIDE_INT) 1 << first_count) - 1));
  7730.  
  7731.           varop = simplify_and_const_int (NULL_RTX, result_mode,
  7732.                           XEXP (varop, 0), mask);
  7733.           varop = simplify_shift_const (NULL_RTX, ASHIFT, result_mode,
  7734.                         varop, count);
  7735.           count = first_count;
  7736.           code = ASHIFTRT;
  7737.           continue;
  7738.         }
  7739.           
  7740.           /* If this was (ashiftrt (ashift foo C1) C2) and FOO has more
  7741.          than C1 high-order bits equal to the sign bit, we can convert
  7742.          this to either an ASHIFT or a ASHIFTRT depending on the
  7743.          two counts. 
  7744.  
  7745.          We cannot do this if VAROP's mode is not SHIFT_MODE.  */
  7746.  
  7747.           if (code == ASHIFTRT && first_code == ASHIFT
  7748.           && GET_MODE (varop) == shift_mode
  7749.           && (num_sign_bit_copies (XEXP (varop, 0), shift_mode)
  7750.               > first_count))
  7751.         {
  7752.           count -= first_count;
  7753.           if (count < 0)
  7754.             count = - count, code = ASHIFT;
  7755.           varop = XEXP (varop, 0);
  7756.           continue;
  7757.         }
  7758.  
  7759.           /* There are some cases we can't do.  If CODE is ASHIFTRT,
  7760.          we can only do this if FIRST_CODE is also ASHIFTRT.
  7761.  
  7762.          We can't do the case when CODE is ROTATE and FIRST_CODE is
  7763.          ASHIFTRT.
  7764.  
  7765.          If the mode of this shift is not the mode of the outer shift,
  7766.          we can't do this if either shift is ASHIFTRT or ROTATE.
  7767.  
  7768.          Finally, we can't do any of these if the mode is too wide
  7769.          unless the codes are the same.
  7770.  
  7771.          Handle the case where the shift codes are the same
  7772.          first.  */
  7773.  
  7774.           if (code == first_code)
  7775.         {
  7776.           if (GET_MODE (varop) != result_mode
  7777.               && (code == ASHIFTRT || code == ROTATE))
  7778.             break;
  7779.  
  7780.           count += first_count;
  7781.           varop = XEXP (varop, 0);
  7782.           continue;
  7783.         }
  7784.  
  7785.           if (code == ASHIFTRT
  7786.           || (code == ROTATE && first_code == ASHIFTRT)
  7787.           || GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
  7788.           || (GET_MODE (varop) != result_mode
  7789.               && (first_code == ASHIFTRT || first_code == ROTATE
  7790.               || code == ROTATE)))
  7791.         break;
  7792.  
  7793.           /* To compute the mask to apply after the shift, shift the
  7794.          nonzero bits of the inner shift the same way the 
  7795.          outer shift will.  */
  7796.  
  7797.           mask_rtx = GEN_INT (nonzero_bits (varop, GET_MODE (varop)));
  7798.  
  7799.           mask_rtx
  7800.         = simplify_binary_operation (code, result_mode, mask_rtx,
  7801.                          GEN_INT (count));
  7802.                   
  7803.           /* Give up if we can't compute an outer operation to use.  */
  7804.           if (mask_rtx == 0
  7805.           || GET_CODE (mask_rtx) != CONST_INT
  7806.           || ! merge_outer_ops (&outer_op, &outer_const, AND,
  7807.                     INTVAL (mask_rtx),
  7808.                     result_mode, &complement_p))
  7809.         break;
  7810.  
  7811.           /* If the shifts are in the same direction, we add the
  7812.          counts.  Otherwise, we subtract them.  */
  7813.           if ((code == ASHIFTRT || code == LSHIFTRT)
  7814.           == (first_code == ASHIFTRT || first_code == LSHIFTRT))
  7815.         count += first_count;
  7816.           else
  7817.         count -= first_count;
  7818.  
  7819.           /* If COUNT is positive, the new shift is usually CODE, 
  7820.          except for the two exceptions below, in which case it is
  7821.          FIRST_CODE.  If the count is negative, FIRST_CODE should
  7822.          always be used  */
  7823.           if (count > 0
  7824.           && ((first_code == ROTATE && code == ASHIFT)
  7825.               || (first_code == ASHIFTRT && code == LSHIFTRT)))
  7826.         code = first_code;
  7827.           else if (count < 0)
  7828.         code = first_code, count = - count;
  7829.  
  7830.           varop = XEXP (varop, 0);
  7831.           continue;
  7832.         }
  7833.  
  7834.       /* If we have (A << B << C) for any shift, we can convert this to
  7835.          (A << C << B).  This wins if A is a constant.  Only try this if
  7836.          B is not a constant.  */
  7837.  
  7838.       else if (GET_CODE (varop) == code
  7839.            && GET_CODE (XEXP (varop, 1)) != CONST_INT
  7840.            && 0 != (new
  7841.                 = simplify_binary_operation (code, mode,
  7842.                              XEXP (varop, 0),
  7843.                              GEN_INT (count))))
  7844.         {
  7845.           varop = gen_rtx_combine (code, mode, new, XEXP (varop, 1));
  7846.           count = 0;
  7847.           continue;
  7848.         }
  7849.       break;
  7850.  
  7851.     case NOT:
  7852.       /* Make this fit the case below.  */
  7853.       varop = gen_rtx_combine (XOR, mode, XEXP (varop, 0),
  7854.                    GEN_INT (GET_MODE_MASK (mode)));
  7855.       continue;
  7856.  
  7857.     case IOR:
  7858.     case AND:
  7859.     case XOR:
  7860.       /* If we have (xshiftrt (ior (plus X (const_int -1)) X) C)
  7861.          with C the size of VAROP - 1 and the shift is logical if
  7862.          STORE_FLAG_VALUE is 1 and arithmetic if STORE_FLAG_VALUE is -1,
  7863.          we have an (le X 0) operation.   If we have an arithmetic shift
  7864.          and STORE_FLAG_VALUE is 1 or we have a logical shift with
  7865.          STORE_FLAG_VALUE of -1, we have a (neg (le X 0)) operation.  */
  7866.  
  7867.       if (GET_CODE (varop) == IOR && GET_CODE (XEXP (varop, 0)) == PLUS
  7868.           && XEXP (XEXP (varop, 0), 1) == constm1_rtx
  7869.           && (STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1)
  7870.           && (code == LSHIFTRT || code == ASHIFTRT)
  7871.           && count == GET_MODE_BITSIZE (GET_MODE (varop)) - 1
  7872.           && rtx_equal_p (XEXP (XEXP (varop, 0), 0), XEXP (varop, 1)))
  7873.         {
  7874.           count = 0;
  7875.           varop = gen_rtx_combine (LE, GET_MODE (varop), XEXP (varop, 1),
  7876.                        const0_rtx);
  7877.  
  7878.           if (STORE_FLAG_VALUE == 1 ? code == ASHIFTRT : code == LSHIFTRT)
  7879.         varop = gen_rtx_combine (NEG, GET_MODE (varop), varop);
  7880.  
  7881.           continue;
  7882.         }
  7883.  
  7884.       /* If we have (shift (logical)), move the logical to the outside
  7885.          to allow it to possibly combine with another logical and the
  7886.          shift to combine with another shift.  This also canonicalizes to
  7887.          what a ZERO_EXTRACT looks like.  Also, some machines have
  7888.          (and (shift)) insns.  */
  7889.  
  7890.       if (GET_CODE (XEXP (varop, 1)) == CONST_INT
  7891.           && (new = simplify_binary_operation (code, result_mode,
  7892.                            XEXP (varop, 1),
  7893.                            GEN_INT (count))) != 0
  7894.           && GET_CODE(new) == CONST_INT
  7895.           && merge_outer_ops (&outer_op, &outer_const, GET_CODE (varop),
  7896.                   INTVAL (new), result_mode, &complement_p))
  7897.         {
  7898.           varop = XEXP (varop, 0);
  7899.           continue;
  7900.         }
  7901.  
  7902.       /* If we can't do that, try to simplify the shift in each arm of the
  7903.          logical expression, make a new logical expression, and apply
  7904.          the inverse distributive law.  */
  7905.       {
  7906.         rtx lhs = simplify_shift_const (NULL_RTX, code, shift_mode,
  7907.                         XEXP (varop, 0), count);
  7908.         rtx rhs = simplify_shift_const (NULL_RTX, code, shift_mode,
  7909.                         XEXP (varop, 1), count);
  7910.  
  7911.         varop = gen_binary (GET_CODE (varop), shift_mode, lhs, rhs);
  7912.         varop = apply_distributive_law (varop);
  7913.  
  7914.         count = 0;
  7915.       }
  7916.       break;
  7917.  
  7918.     case EQ:
  7919.       /* convert (lshiftrt (eq FOO 0) C) to (xor FOO 1) if STORE_FLAG_VALUE
  7920.          says that the sign bit can be tested, FOO has mode MODE, C is
  7921.          GET_MODE_BITSIZE (MODE) - 1, and FOO has only its low-order bit
  7922.          that may be nonzero.  */
  7923.       if (code == LSHIFTRT
  7924.           && XEXP (varop, 1) == const0_rtx
  7925.           && GET_MODE (XEXP (varop, 0)) == result_mode
  7926.           && count == GET_MODE_BITSIZE (result_mode) - 1
  7927.           && GET_MODE_BITSIZE (result_mode) <= HOST_BITS_PER_WIDE_INT
  7928.           && ((STORE_FLAG_VALUE
  7929.            & ((HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (result_mode) - 1))))
  7930.           && nonzero_bits (XEXP (varop, 0), result_mode) == 1
  7931.           && merge_outer_ops (&outer_op, &outer_const, XOR,
  7932.                   (HOST_WIDE_INT) 1, result_mode,
  7933.                   &complement_p))
  7934.         {
  7935.           varop = XEXP (varop, 0);
  7936.           count = 0;
  7937.           continue;
  7938.         }
  7939.       break;
  7940.  
  7941.     case NEG:
  7942.       /* (lshiftrt (neg A) C) where A is either 0 or 1 and C is one less
  7943.          than the number of bits in the mode is equivalent to A.  */
  7944.       if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1
  7945.           && nonzero_bits (XEXP (varop, 0), result_mode) == 1)
  7946.         {
  7947.           varop = XEXP (varop, 0);
  7948.           count = 0;
  7949.           continue;
  7950.         }
  7951.  
  7952.       /* NEG commutes with ASHIFT since it is multiplication.  Move the
  7953.          NEG outside to allow shifts to combine.  */
  7954.       if (code == ASHIFT
  7955.           && merge_outer_ops (&outer_op, &outer_const, NEG,
  7956.                   (HOST_WIDE_INT) 0, result_mode,
  7957.                   &complement_p))
  7958.         {
  7959.           varop = XEXP (varop, 0);
  7960.           continue;
  7961.         }
  7962.       break;
  7963.  
  7964.     case PLUS:
  7965.       /* (lshiftrt (plus A -1) C) where A is either 0 or 1 and C
  7966.          is one less than the number of bits in the mode is
  7967.          equivalent to (xor A 1).  */
  7968.       if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1
  7969.           && XEXP (varop, 1) == constm1_rtx
  7970.           && nonzero_bits (XEXP (varop, 0), result_mode) == 1
  7971.           && merge_outer_ops (&outer_op, &outer_const, XOR,
  7972.                   (HOST_WIDE_INT) 1, result_mode,
  7973.                   &complement_p))
  7974.         {
  7975.           count = 0;
  7976.           varop = XEXP (varop, 0);
  7977.           continue;
  7978.         }
  7979.  
  7980.       /* If we have (xshiftrt (plus FOO BAR) C), and the only bits
  7981.          that might be nonzero in BAR are those being shifted out and those
  7982.          bits are known zero in FOO, we can replace the PLUS with FOO.
  7983.          Similarly in the other operand order.  This code occurs when
  7984.          we are computing the size of a variable-size array.  */
  7985.  
  7986.       if ((code == ASHIFTRT || code == LSHIFTRT)
  7987.           && count < HOST_BITS_PER_WIDE_INT
  7988.           && nonzero_bits (XEXP (varop, 1), result_mode) >> count == 0
  7989.           && (nonzero_bits (XEXP (varop, 1), result_mode)
  7990.           & nonzero_bits (XEXP (varop, 0), result_mode)) == 0)
  7991.         {
  7992.           varop = XEXP (varop, 0);
  7993.           continue;
  7994.         }
  7995.       else if ((code == ASHIFTRT || code == LSHIFTRT)
  7996.            && count < HOST_BITS_PER_WIDE_INT
  7997.            && GET_MODE_BITSIZE (result_mode) <= HOST_BITS_PER_WIDE_INT
  7998.            && 0 == (nonzero_bits (XEXP (varop, 0), result_mode)
  7999.                 >> count)
  8000.            && 0 == (nonzero_bits (XEXP (varop, 0), result_mode)
  8001.                 & nonzero_bits (XEXP (varop, 1),
  8002.                          result_mode)))
  8003.         {
  8004.           varop = XEXP (varop, 1);
  8005.           continue;
  8006.         }
  8007.  
  8008.       /* (ashift (plus foo C) N) is (plus (ashift foo N) C').  */
  8009.       if (code == ASHIFT
  8010.           && GET_CODE (XEXP (varop, 1)) == CONST_INT
  8011.           && (new = simplify_binary_operation (ASHIFT, result_mode,
  8012.                            XEXP (varop, 1),
  8013.                            GEN_INT (count))) != 0
  8014.           && GET_CODE(new) == CONST_INT
  8015.           && merge_outer_ops (&outer_op, &outer_const, PLUS,
  8016.                   INTVAL (new), result_mode, &complement_p))
  8017.         {
  8018.           varop = XEXP (varop, 0);
  8019.           continue;
  8020.         }
  8021.       break;
  8022.  
  8023.     case MINUS:
  8024.       /* If we have (xshiftrt (minus (ashiftrt X C)) X) C)
  8025.          with C the size of VAROP - 1 and the shift is logical if
  8026.          STORE_FLAG_VALUE is 1 and arithmetic if STORE_FLAG_VALUE is -1,
  8027.          we have a (gt X 0) operation.  If the shift is arithmetic with
  8028.          STORE_FLAG_VALUE of 1 or logical with STORE_FLAG_VALUE == -1,
  8029.          we have a (neg (gt X 0)) operation.  */
  8030.  
  8031.       if (GET_CODE (XEXP (varop, 0)) == ASHIFTRT
  8032.           && count == GET_MODE_BITSIZE (GET_MODE (varop)) - 1
  8033.           && (STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1)
  8034.           && (code == LSHIFTRT || code == ASHIFTRT)
  8035.           && GET_CODE (XEXP (XEXP (varop, 0), 1)) == CONST_INT
  8036.           && INTVAL (XEXP (XEXP (varop, 0), 1)) == count
  8037.           && rtx_equal_p (XEXP (XEXP (varop, 0), 0), XEXP (varop, 1)))
  8038.         {
  8039.           count = 0;
  8040.           varop = gen_rtx_combine (GT, GET_MODE (varop), XEXP (varop, 1),
  8041.                        const0_rtx);
  8042.  
  8043.           if (STORE_FLAG_VALUE == 1 ? code == ASHIFTRT : code == LSHIFTRT)
  8044.         varop = gen_rtx_combine (NEG, GET_MODE (varop), varop);
  8045.  
  8046.           continue;
  8047.         }
  8048.       break;
  8049.     }
  8050.  
  8051.       break;
  8052.     }
  8053.  
  8054.   /* We need to determine what mode to do the shift in.  If the shift is
  8055.      a ASHIFTRT or ROTATE, we must always do it in the mode it was originally
  8056.      done in.  Otherwise, we can do it in MODE, the widest mode encountered.
  8057.      The code we care about is that of the shift that will actually be done,
  8058.      not the shift that was originally requested.  */
  8059.   shift_mode = (code == ASHIFTRT || code == ROTATE ? result_mode : mode);
  8060.  
  8061.   /* We have now finished analyzing the shift.  The result should be
  8062.      a shift of type CODE with SHIFT_MODE shifting VAROP COUNT places.  If
  8063.      OUTER_OP is non-NIL, it is an operation that needs to be applied
  8064.      to the result of the shift.  OUTER_CONST is the relevant constant,
  8065.      but we must turn off all bits turned off in the shift.
  8066.  
  8067.      If we were passed a value for X, see if we can use any pieces of
  8068.      it.  If not, make new rtx.  */
  8069.  
  8070.   if (x && GET_RTX_CLASS (GET_CODE (x)) == '2'
  8071.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  8072.       && INTVAL (XEXP (x, 1)) == count)
  8073.     const_rtx = XEXP (x, 1);
  8074.   else
  8075.     const_rtx = GEN_INT (count);
  8076.  
  8077.   if (x && GET_CODE (XEXP (x, 0)) == SUBREG
  8078.       && GET_MODE (XEXP (x, 0)) == shift_mode
  8079.       && SUBREG_REG (XEXP (x, 0)) == varop)
  8080.     varop = XEXP (x, 0);
  8081.   else if (GET_MODE (varop) != shift_mode)
  8082.     varop = gen_lowpart_for_combine (shift_mode, varop);
  8083.  
  8084.   /* If we can't make the SUBREG, try to return what we were given. */
  8085.   if (GET_CODE (varop) == CLOBBER)
  8086.     return x ? x : varop;
  8087.  
  8088.   new = simplify_binary_operation (code, shift_mode, varop, const_rtx);
  8089.   if (new != 0)
  8090.     x = new;
  8091.   else
  8092.     {
  8093.       if (x == 0 || GET_CODE (x) != code || GET_MODE (x) != shift_mode)
  8094.     x = gen_rtx_combine (code, shift_mode, varop, const_rtx);
  8095.  
  8096.       SUBST (XEXP (x, 0), varop);
  8097.       SUBST (XEXP (x, 1), const_rtx);
  8098.     }
  8099.  
  8100.   /* If we have an outer operation and we just made a shift, it is
  8101.      possible that we could have simplified the shift were it not
  8102.      for the outer operation.  So try to do the simplification
  8103.      recursively.  */
  8104.  
  8105.   if (outer_op != NIL && GET_CODE (x) == code
  8106.       && GET_CODE (XEXP (x, 1)) == CONST_INT)
  8107.     x = simplify_shift_const (x, code, shift_mode, XEXP (x, 0),
  8108.                   INTVAL (XEXP (x, 1)));
  8109.  
  8110.   /* If we were doing a LSHIFTRT in a wider mode than it was originally,
  8111.      turn off all the bits that the shift would have turned off.  */
  8112.   if (orig_code == LSHIFTRT && result_mode != shift_mode)
  8113.     x = simplify_and_const_int (NULL_RTX, shift_mode, x,
  8114.                 GET_MODE_MASK (result_mode) >> orig_count);
  8115.       
  8116.   /* Do the remainder of the processing in RESULT_MODE.  */
  8117.   x = gen_lowpart_for_combine (result_mode, x);
  8118.  
  8119.   /* If COMPLEMENT_P is set, we have to complement X before doing the outer
  8120.      operation.  */
  8121.   if (complement_p)
  8122.     x = gen_unary (NOT, result_mode, result_mode, x);
  8123.  
  8124.   if (outer_op != NIL)
  8125.     {
  8126.       if (GET_MODE_BITSIZE (result_mode) < HOST_BITS_PER_WIDE_INT)
  8127.     outer_const &= GET_MODE_MASK (result_mode);
  8128.  
  8129.       if (outer_op == AND)
  8130.     x = simplify_and_const_int (NULL_RTX, result_mode, x, outer_const);
  8131.       else if (outer_op == SET)
  8132.     /* This means that we have determined that the result is
  8133.        equivalent to a constant.  This should be rare.  */
  8134.     x = GEN_INT (outer_const);
  8135.       else if (GET_RTX_CLASS (outer_op) == '1')
  8136.     x = gen_unary (outer_op, result_mode, result_mode, x);
  8137.       else
  8138.     x = gen_binary (outer_op, result_mode, x, GEN_INT (outer_const));
  8139.     }
  8140.  
  8141.   return x;
  8142. }  
  8143.  
  8144. /* Like recog, but we receive the address of a pointer to a new pattern.
  8145.    We try to match the rtx that the pointer points to.
  8146.    If that fails, we may try to modify or replace the pattern,
  8147.    storing the replacement into the same pointer object.
  8148.  
  8149.    Modifications include deletion or addition of CLOBBERs.
  8150.  
  8151.    PNOTES is a pointer to a location where any REG_UNUSED notes added for
  8152.    the CLOBBERs are placed.
  8153.  
  8154.    The value is the final insn code from the pattern ultimately matched,
  8155.    or -1.  */
  8156.  
  8157. static int
  8158. recog_for_combine (pnewpat, insn, pnotes)
  8159.      rtx *pnewpat;
  8160.      rtx insn;
  8161.      rtx *pnotes;
  8162. {
  8163.   register rtx pat = *pnewpat;
  8164.   int insn_code_number;
  8165.   int num_clobbers_to_add = 0;
  8166.   int i;
  8167.   rtx notes = 0;
  8168.  
  8169.   /* If PAT is a PARALLEL, check to see if it contains the CLOBBER
  8170.      we use to indicate that something didn't match.  If we find such a
  8171.      thing, force rejection.  */
  8172.   if (GET_CODE (pat) == PARALLEL)
  8173.     for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
  8174.       if (GET_CODE (XVECEXP (pat, 0, i)) == CLOBBER
  8175.       && XEXP (XVECEXP (pat, 0, i), 0) == const0_rtx)
  8176.     return -1;
  8177.  
  8178.   /* Is the result of combination a valid instruction?  */
  8179.   insn_code_number = recog (pat, insn, &num_clobbers_to_add);
  8180.  
  8181.   /* If it isn't, there is the possibility that we previously had an insn
  8182.      that clobbered some register as a side effect, but the combined
  8183.      insn doesn't need to do that.  So try once more without the clobbers
  8184.      unless this represents an ASM insn.  */
  8185.  
  8186.   if (insn_code_number < 0 && ! check_asm_operands (pat)
  8187.       && GET_CODE (pat) == PARALLEL)
  8188.     {
  8189.       int pos;
  8190.  
  8191.       for (pos = 0, i = 0; i < XVECLEN (pat, 0); i++)
  8192.     if (GET_CODE (XVECEXP (pat, 0, i)) != CLOBBER)
  8193.       {
  8194.         if (i != pos)
  8195.           SUBST (XVECEXP (pat, 0, pos), XVECEXP (pat, 0, i));
  8196.         pos++;
  8197.       }
  8198.  
  8199.       SUBST_INT (XVECLEN (pat, 0), pos);
  8200.  
  8201.       if (pos == 1)
  8202.     pat = XVECEXP (pat, 0, 0);
  8203.  
  8204.       insn_code_number = recog (pat, insn, &num_clobbers_to_add);
  8205.     }
  8206.  
  8207.   /* If we had any clobbers to add, make a new pattern than contains
  8208.      them.  Then check to make sure that all of them are dead.  */
  8209.   if (num_clobbers_to_add)
  8210.     {
  8211.       rtx newpat = gen_rtx (PARALLEL, VOIDmode,
  8212.                 gen_rtvec (GET_CODE (pat) == PARALLEL
  8213.                        ? XVECLEN (pat, 0) + num_clobbers_to_add
  8214.                        : num_clobbers_to_add + 1));
  8215.  
  8216.       if (GET_CODE (pat) == PARALLEL)
  8217.     for (i = 0; i < XVECLEN (pat, 0); i++)
  8218.       XVECEXP (newpat, 0, i) = XVECEXP (pat, 0, i);
  8219.       else
  8220.     XVECEXP (newpat, 0, 0) = pat;
  8221.  
  8222.       add_clobbers (newpat, insn_code_number);
  8223.  
  8224.       for (i = XVECLEN (newpat, 0) - num_clobbers_to_add;
  8225.        i < XVECLEN (newpat, 0); i++)
  8226.     {
  8227.       if (GET_CODE (XEXP (XVECEXP (newpat, 0, i), 0)) == REG
  8228.           && ! reg_dead_at_p (XEXP (XVECEXP (newpat, 0, i), 0), insn))
  8229.         return -1;
  8230.       notes = gen_rtx (EXPR_LIST, REG_UNUSED,
  8231.                XEXP (XVECEXP (newpat, 0, i), 0), notes);
  8232.     }
  8233.       pat = newpat;
  8234.     }
  8235.  
  8236.   *pnewpat = pat;
  8237.   *pnotes = notes;
  8238.  
  8239.   return insn_code_number;
  8240. }
  8241.  
  8242. /* Like gen_lowpart but for use by combine.  In combine it is not possible
  8243.    to create any new pseudoregs.  However, it is safe to create
  8244.    invalid memory addresses, because combine will try to recognize
  8245.    them and all they will do is make the combine attempt fail.
  8246.  
  8247.    If for some reason this cannot do its job, an rtx
  8248.    (clobber (const_int 0)) is returned.
  8249.    An insn containing that will not be recognized.  */
  8250.  
  8251. #undef gen_lowpart
  8252.  
  8253. static rtx
  8254. gen_lowpart_for_combine (mode, x)
  8255.      enum machine_mode mode;
  8256.      register rtx x;
  8257. {
  8258.   rtx result;
  8259.  
  8260.   if (GET_MODE (x) == mode)
  8261.     return x;
  8262.  
  8263.   /* We can only support MODE being wider than a word if X is a
  8264.      constant integer or has a mode the same size.  */
  8265.  
  8266.   if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
  8267.       && ! ((GET_MODE (x) == VOIDmode
  8268.          && (GET_CODE (x) == CONST_INT
  8269.          || GET_CODE (x) == CONST_DOUBLE))
  8270.         || GET_MODE_SIZE (GET_MODE (x)) == GET_MODE_SIZE (mode)))
  8271.     return gen_rtx (CLOBBER, GET_MODE (x), const0_rtx);
  8272.  
  8273.   /* X might be a paradoxical (subreg (mem)).  In that case, gen_lowpart
  8274.      won't know what to do.  So we will strip off the SUBREG here and
  8275.      process normally.  */
  8276.   if (GET_CODE (x) == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
  8277.     {
  8278.       x = SUBREG_REG (x);
  8279.       if (GET_MODE (x) == mode)
  8280.     return x;
  8281.     }
  8282.  
  8283.   result = gen_lowpart_common (mode, x);
  8284.   if (result)
  8285.     return result;
  8286.  
  8287.   if (GET_CODE (x) == MEM)
  8288.     {
  8289.       register int offset = 0;
  8290.       rtx new;
  8291.  
  8292.       /* Refuse to work on a volatile memory ref or one with a mode-dependent
  8293.      address.  */
  8294.       if (MEM_VOLATILE_P (x) || mode_dependent_address_p (XEXP (x, 0)))
  8295.     return gen_rtx (CLOBBER, GET_MODE (x), const0_rtx);
  8296.  
  8297.       /* If we want to refer to something bigger than the original memref,
  8298.      generate a perverse subreg instead.  That will force a reload
  8299.      of the original memref X.  */
  8300.       if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode))
  8301.     return gen_rtx (SUBREG, mode, x, 0);
  8302.  
  8303. #if WORDS_BIG_ENDIAN
  8304.       offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
  8305.         - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
  8306. #endif
  8307. #if BYTES_BIG_ENDIAN
  8308.       /* Adjust the address so that the address-after-the-data
  8309.      is unchanged.  */
  8310.       offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
  8311.          - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
  8312. #endif
  8313.       new = gen_rtx (MEM, mode, plus_constant (XEXP (x, 0), offset));
  8314.       RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (x);
  8315.       MEM_VOLATILE_P (new) = MEM_VOLATILE_P (x);
  8316.       MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (x);
  8317.       return new;
  8318.     }
  8319.  
  8320.   /* If X is a comparison operator, rewrite it in a new mode.  This
  8321.      probably won't match, but may allow further simplifications.  */
  8322.   else if (GET_RTX_CLASS (GET_CODE (x)) == '<')
  8323.     return gen_rtx_combine (GET_CODE (x), mode, XEXP (x, 0), XEXP (x, 1));
  8324.  
  8325.   /* If we couldn't simplify X any other way, just enclose it in a
  8326.      SUBREG.  Normally, this SUBREG won't match, but some patterns may
  8327.      include an explicit SUBREG or we may simplify it further in combine.  */
  8328.   else
  8329.     {
  8330.       int word = 0;
  8331.  
  8332.       if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
  8333.     word = ((GET_MODE_SIZE (GET_MODE (x))
  8334.          - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
  8335.         / UNITS_PER_WORD);
  8336.       return gen_rtx (SUBREG, mode, x, word);
  8337.     }
  8338. }
  8339.  
  8340. /* Make an rtx expression.  This is a subset of gen_rtx and only supports
  8341.    expressions of 1, 2, or 3 operands, each of which are rtx expressions.
  8342.  
  8343.    If the identical expression was previously in the insn (in the undobuf),
  8344.    it will be returned.  Only if it is not found will a new expression
  8345.    be made.  */
  8346.  
  8347. /*VARARGS2*/
  8348. static rtx
  8349. gen_rtx_combine VPROTO((enum rtx_code code, enum machine_mode mode, ...))
  8350. {
  8351. #ifndef __STDC__
  8352.   enum rtx_code code;
  8353.   enum machine_mode mode;
  8354. #endif
  8355.   va_list p;
  8356.   int n_args;
  8357.   rtx args[3];
  8358.   int i, j;
  8359.   char *fmt;
  8360.   rtx rt;
  8361.  
  8362.   VA_START (p, mode);
  8363.  
  8364. #ifndef __STDC__
  8365.   code = va_arg (p, enum rtx_code);
  8366.   mode = va_arg (p, enum machine_mode);
  8367. #endif
  8368.  
  8369.   n_args = GET_RTX_LENGTH (code);
  8370.   fmt = GET_RTX_FORMAT (code);
  8371.  
  8372.   if (n_args == 0 || n_args > 3)
  8373.     abort ();
  8374.  
  8375.   /* Get each arg and verify that it is supposed to be an expression.  */
  8376.   for (j = 0; j < n_args; j++)
  8377.     {
  8378.       if (*fmt++ != 'e')
  8379.     abort ();
  8380.  
  8381.       args[j] = va_arg (p, rtx);
  8382.     }
  8383.  
  8384.   /* See if this is in undobuf.  Be sure we don't use objects that came
  8385.      from another insn; this could produce circular rtl structures.  */
  8386.  
  8387.   for (i = previous_num_undos; i < undobuf.num_undo; i++)
  8388.     if (!undobuf.undo[i].is_int
  8389.     && GET_CODE (undobuf.undo[i].old_contents.r) == code
  8390.     && GET_MODE (undobuf.undo[i].old_contents.r) == mode)
  8391.       {
  8392.     for (j = 0; j < n_args; j++)
  8393.       if (XEXP (undobuf.undo[i].old_contents.r, j) != args[j])
  8394.         break;
  8395.  
  8396.     if (j == n_args)
  8397.       return undobuf.undo[i].old_contents.r;
  8398.       }
  8399.  
  8400.   /* Otherwise make a new rtx.  We know we have 1, 2, or 3 args.
  8401.      Use rtx_alloc instead of gen_rtx because it's faster on RISC.  */
  8402.   rt = rtx_alloc (code);
  8403.   PUT_MODE (rt, mode);
  8404.   XEXP (rt, 0) = args[0];
  8405.   if (n_args > 1)
  8406.     {
  8407.       XEXP (rt, 1) = args[1];
  8408.       if (n_args > 2)
  8409.     XEXP (rt, 2) = args[2];
  8410.     }
  8411.   return rt;
  8412. }
  8413.  
  8414. /* These routines make binary and unary operations by first seeing if they
  8415.    fold; if not, a new expression is allocated.  */
  8416.  
  8417. static rtx
  8418. gen_binary (code, mode, op0, op1)
  8419.      enum rtx_code code;
  8420.      enum machine_mode mode;
  8421.      rtx op0, op1;
  8422. {
  8423.   rtx result;
  8424.   rtx tem;
  8425.  
  8426.   if (GET_RTX_CLASS (code) == 'c'
  8427.       && (GET_CODE (op0) == CONST_INT
  8428.       || (CONSTANT_P (op0) && GET_CODE (op1) != CONST_INT)))
  8429.     tem = op0, op0 = op1, op1 = tem;
  8430.  
  8431.   if (GET_RTX_CLASS (code) == '<') 
  8432.     {
  8433.       enum machine_mode op_mode = GET_MODE (op0);
  8434.  
  8435.       /* Strip the COMPARE from (REL_OP (compare X Y) 0) to get 
  8436.      just (REL_OP X Y). */
  8437.       if (GET_CODE (op0) == COMPARE && op1 == const0_rtx)
  8438.     {
  8439.       op1 = XEXP (op0, 1);
  8440.       op0 = XEXP (op0, 0);
  8441.       op_mode = GET_MODE (op0);
  8442.     }
  8443.  
  8444.       if (op_mode == VOIDmode)
  8445.     op_mode = GET_MODE (op1);
  8446.       result = simplify_relational_operation (code, op_mode, op0, op1);
  8447.     }
  8448.   else
  8449.     result = simplify_binary_operation (code, mode, op0, op1);
  8450.  
  8451.   if (result)
  8452.     return result;
  8453.  
  8454.   /* Put complex operands first and constants second.  */
  8455.   if (GET_RTX_CLASS (code) == 'c'
  8456.       && ((CONSTANT_P (op0) && GET_CODE (op1) != CONST_INT)
  8457.       || (GET_RTX_CLASS (GET_CODE (op0)) == 'o'
  8458.           && GET_RTX_CLASS (GET_CODE (op1)) != 'o')
  8459.       || (GET_CODE (op0) == SUBREG
  8460.           && GET_RTX_CLASS (GET_CODE (SUBREG_REG (op0))) == 'o'
  8461.           && GET_RTX_CLASS (GET_CODE (op1)) != 'o')))
  8462.     return gen_rtx_combine (code, mode, op1, op0);
  8463.  
  8464.   return gen_rtx_combine (code, mode, op0, op1);
  8465. }
  8466.  
  8467. static rtx
  8468. gen_unary (code, mode, op0_mode, op0)
  8469.      enum rtx_code code;
  8470.      enum machine_mode mode, op0_mode;
  8471.      rtx op0;
  8472. {
  8473.   rtx result = simplify_unary_operation (code, mode, op0, op0_mode);
  8474.  
  8475.   if (result)
  8476.     return result;
  8477.  
  8478.   return gen_rtx_combine (code, mode, op0);
  8479. }
  8480.  
  8481. /* Simplify a comparison between *POP0 and *POP1 where CODE is the
  8482.    comparison code that will be tested.
  8483.  
  8484.    The result is a possibly different comparison code to use.  *POP0 and
  8485.    *POP1 may be updated.
  8486.  
  8487.    It is possible that we might detect that a comparison is either always
  8488.    true or always false.  However, we do not perform general constant
  8489.    folding in combine, so this knowledge isn't useful.  Such tautologies
  8490.    should have been detected earlier.  Hence we ignore all such cases.  */
  8491.  
  8492. static enum rtx_code
  8493. simplify_comparison (code, pop0, pop1)
  8494.      enum rtx_code code;
  8495.      rtx *pop0;
  8496.      rtx *pop1;
  8497. {
  8498.   rtx op0 = *pop0;
  8499.   rtx op1 = *pop1;
  8500.   rtx tem, tem1;
  8501.   int i;
  8502.   enum machine_mode mode, tmode;
  8503.  
  8504.   /* Try a few ways of applying the same transformation to both operands.  */
  8505.   while (1)
  8506.     {
  8507. #ifndef WORD_REGISTER_OPERATIONS
  8508.       /* The test below this one won't handle SIGN_EXTENDs on these machines,
  8509.      so check specially.  */
  8510.       if (code != GTU && code != GEU && code != LTU && code != LEU
  8511.       && GET_CODE (op0) == ASHIFTRT && GET_CODE (op1) == ASHIFTRT
  8512.       && GET_CODE (XEXP (op0, 0)) == ASHIFT
  8513.       && GET_CODE (XEXP (op1, 0)) == ASHIFT
  8514.       && GET_CODE (XEXP (XEXP (op0, 0), 0)) == SUBREG
  8515.       && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SUBREG
  8516.       && (GET_MODE (SUBREG_REG (XEXP (XEXP (op0, 0), 0)))
  8517.           == GET_MODE (SUBREG_REG (XEXP (XEXP (op1, 0), 0))))
  8518.       && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8519.       && GET_CODE (XEXP (op1, 1)) == CONST_INT
  8520.       && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT
  8521.       && GET_CODE (XEXP (XEXP (op1, 0), 1)) == CONST_INT
  8522.       && INTVAL (XEXP (op0, 1)) == INTVAL (XEXP (op1, 1))
  8523.       && INTVAL (XEXP (op0, 1)) == INTVAL (XEXP (XEXP (op0, 0), 1))
  8524.       && INTVAL (XEXP (op0, 1)) == INTVAL (XEXP (XEXP (op1, 0), 1))
  8525.       && (INTVAL (XEXP (op0, 1))
  8526.           == (GET_MODE_BITSIZE (GET_MODE (op0))
  8527.           - (GET_MODE_BITSIZE
  8528.              (GET_MODE (SUBREG_REG (XEXP (XEXP (op0, 0), 0))))))))
  8529.     {
  8530.       op0 = SUBREG_REG (XEXP (XEXP (op0, 0), 0));
  8531.       op1 = SUBREG_REG (XEXP (XEXP (op1, 0), 0));
  8532.     }
  8533. #endif
  8534.  
  8535.       /* If both operands are the same constant shift, see if we can ignore the
  8536.      shift.  We can if the shift is a rotate or if the bits shifted out of
  8537.      this shift are known to be zero for both inputs and if the type of
  8538.      comparison is compatible with the shift.  */
  8539.       if (GET_CODE (op0) == GET_CODE (op1)
  8540.       && GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT
  8541.       && ((GET_CODE (op0) == ROTATE && (code == NE || code == EQ))
  8542.           || ((GET_CODE (op0) == LSHIFTRT || GET_CODE (op0) == ASHIFT)
  8543.           && (code != GT && code != LT && code != GE && code != LE))
  8544.           || (GET_CODE (op0) == ASHIFTRT
  8545.           && (code != GTU && code != LTU
  8546.               && code != GEU && code != GEU)))
  8547.       && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8548.       && INTVAL (XEXP (op0, 1)) >= 0
  8549.       && INTVAL (XEXP (op0, 1)) < HOST_BITS_PER_WIDE_INT
  8550.       && XEXP (op0, 1) == XEXP (op1, 1))
  8551.     {
  8552.       enum machine_mode mode = GET_MODE (op0);
  8553.       unsigned HOST_WIDE_INT mask = GET_MODE_MASK (mode);
  8554.       int shift_count = INTVAL (XEXP (op0, 1));
  8555.  
  8556.       if (GET_CODE (op0) == LSHIFTRT || GET_CODE (op0) == ASHIFTRT)
  8557.         mask &= (mask >> shift_count) << shift_count;
  8558.       else if (GET_CODE (op0) == ASHIFT)
  8559.         mask = (mask & (mask << shift_count)) >> shift_count;
  8560.  
  8561.       if ((nonzero_bits (XEXP (op0, 0), mode) & ~ mask) == 0
  8562.           && (nonzero_bits (XEXP (op1, 0), mode) & ~ mask) == 0)
  8563.         op0 = XEXP (op0, 0), op1 = XEXP (op1, 0);
  8564.       else
  8565.         break;
  8566.     }
  8567.  
  8568.       /* If both operands are AND's of a paradoxical SUBREG by constant, the
  8569.      SUBREGs are of the same mode, and, in both cases, the AND would
  8570.      be redundant if the comparison was done in the narrower mode,
  8571.      do the comparison in the narrower mode (e.g., we are AND'ing with 1
  8572.      and the operand's possibly nonzero bits are 0xffffff01; in that case
  8573.      if we only care about QImode, we don't need the AND).  This case
  8574.      occurs if the output mode of an scc insn is not SImode and
  8575.      STORE_FLAG_VALUE == 1 (e.g., the 386).
  8576.  
  8577.      Similarly, check for a case where the AND's are ZERO_EXTEND
  8578.      operations from some narrower mode even though a SUBREG is not
  8579.      present.  */
  8580.  
  8581.       else if  (GET_CODE (op0) == AND && GET_CODE (op1) == AND
  8582.         && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8583.         && GET_CODE (XEXP (op1, 1)) == CONST_INT)
  8584.     {
  8585.       rtx inner_op0 = XEXP (op0, 0);
  8586.       rtx inner_op1 = XEXP (op1, 0);
  8587.       HOST_WIDE_INT c0 = INTVAL (XEXP (op0, 1));
  8588.       HOST_WIDE_INT c1 = INTVAL (XEXP (op1, 1));
  8589.       int changed = 0;
  8590.         
  8591.       if (GET_CODE (inner_op0) == SUBREG && GET_CODE (inner_op1) == SUBREG
  8592.           && (GET_MODE_SIZE (GET_MODE (inner_op0))
  8593.           > GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner_op0))))
  8594.           && (GET_MODE (SUBREG_REG (inner_op0))
  8595.           == GET_MODE (SUBREG_REG (inner_op1)))
  8596.           && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
  8597.           <= HOST_BITS_PER_WIDE_INT)
  8598.           && (0 == (~c0) & nonzero_bits (SUBREG_REG (inner_op0),
  8599.                          GET_MODE (SUBREG_REG (op0))))
  8600.           && (0 == (~c1) & nonzero_bits (SUBREG_REG (inner_op1),
  8601.                          GET_MODE (SUBREG_REG (inner_op1)))))
  8602.         {
  8603.           op0 = SUBREG_REG (inner_op0);
  8604.           op1 = SUBREG_REG (inner_op1);
  8605.  
  8606.           /* The resulting comparison is always unsigned since we masked
  8607.          off the original sign bit. */
  8608.           code = unsigned_condition (code);
  8609.  
  8610.           changed = 1;
  8611.         }
  8612.  
  8613.       else if (c0 == c1)
  8614.         for (tmode = GET_CLASS_NARROWEST_MODE
  8615.          (GET_MODE_CLASS (GET_MODE (op0)));
  8616.          tmode != GET_MODE (op0); tmode = GET_MODE_WIDER_MODE (tmode))
  8617.           if (c0 == GET_MODE_MASK (tmode))
  8618.         {
  8619.           op0 = gen_lowpart_for_combine (tmode, inner_op0);
  8620.           op1 = gen_lowpart_for_combine (tmode, inner_op1);
  8621.           changed = 1;
  8622.           break;
  8623.         }
  8624.  
  8625.       if (! changed)
  8626.         break;
  8627.     }
  8628.  
  8629.       /* If both operands are NOT, we can strip off the outer operation
  8630.      and adjust the comparison code for swapped operands; similarly for
  8631.      NEG, except that this must be an equality comparison.  */
  8632.       else if ((GET_CODE (op0) == NOT && GET_CODE (op1) == NOT)
  8633.            || (GET_CODE (op0) == NEG && GET_CODE (op1) == NEG
  8634.            && (code == EQ || code == NE)))
  8635.     op0 = XEXP (op0, 0), op1 = XEXP (op1, 0), code = swap_condition (code);
  8636.  
  8637.       else
  8638.     break;
  8639.     }
  8640.      
  8641.   /* If the first operand is a constant, swap the operands and adjust the
  8642.      comparison code appropriately.  */
  8643.   if (CONSTANT_P (op0))
  8644.     {
  8645.       tem = op0, op0 = op1, op1 = tem;
  8646.       code = swap_condition (code);
  8647.     }
  8648.  
  8649.   /* We now enter a loop during which we will try to simplify the comparison.
  8650.      For the most part, we only are concerned with comparisons with zero,
  8651.      but some things may really be comparisons with zero but not start
  8652.      out looking that way.  */
  8653.  
  8654.   while (GET_CODE (op1) == CONST_INT)
  8655.     {
  8656.       enum machine_mode mode = GET_MODE (op0);
  8657.       int mode_width = GET_MODE_BITSIZE (mode);
  8658.       unsigned HOST_WIDE_INT mask = GET_MODE_MASK (mode);
  8659.       int equality_comparison_p;
  8660.       int sign_bit_comparison_p;
  8661.       int unsigned_comparison_p;
  8662.       HOST_WIDE_INT const_op;
  8663.  
  8664.       /* We only want to handle integral modes.  This catches VOIDmode,
  8665.      CCmode, and the floating-point modes.  An exception is that we
  8666.      can handle VOIDmode if OP0 is a COMPARE or a comparison
  8667.      operation.  */
  8668.  
  8669.       if (GET_MODE_CLASS (mode) != MODE_INT
  8670.       && ! (mode == VOIDmode
  8671.         && (GET_CODE (op0) == COMPARE
  8672.             || GET_RTX_CLASS (GET_CODE (op0)) == '<')))
  8673.     break;
  8674.  
  8675.       /* Get the constant we are comparing against and turn off all bits
  8676.      not on in our mode.  */
  8677.       const_op = INTVAL (op1);
  8678.       if (mode_width <= HOST_BITS_PER_WIDE_INT)
  8679.     const_op &= mask;
  8680.  
  8681.       /* If we are comparing against a constant power of two and the value
  8682.      being compared can only have that single bit nonzero (e.g., it was
  8683.      `and'ed with that bit), we can replace this with a comparison
  8684.      with zero.  */
  8685.       if (const_op
  8686.       && (code == EQ || code == NE || code == GE || code == GEU
  8687.           || code == LT || code == LTU)
  8688.       && mode_width <= HOST_BITS_PER_WIDE_INT
  8689.       && exact_log2 (const_op) >= 0
  8690.       && nonzero_bits (op0, mode) == const_op)
  8691.     {
  8692.       code = (code == EQ || code == GE || code == GEU ? NE : EQ);
  8693.       op1 = const0_rtx, const_op = 0;
  8694.     }
  8695.  
  8696.       /* Similarly, if we are comparing a value known to be either -1 or
  8697.      0 with -1, change it to the opposite comparison against zero.  */
  8698.  
  8699.       if (const_op == -1
  8700.       && (code == EQ || code == NE || code == GT || code == LE
  8701.           || code == GEU || code == LTU)
  8702.       && num_sign_bit_copies (op0, mode) == mode_width)
  8703.     {
  8704.       code = (code == EQ || code == LE || code == GEU ? NE : EQ);
  8705.       op1 = const0_rtx, const_op = 0;
  8706.     }
  8707.  
  8708.       /* Do some canonicalizations based on the comparison code.  We prefer
  8709.      comparisons against zero and then prefer equality comparisons.  
  8710.      If we can reduce the size of a constant, we will do that too.  */
  8711.  
  8712.       switch (code)
  8713.     {
  8714.     case LT:
  8715.       /* < C is equivalent to <= (C - 1) */
  8716.       if (const_op > 0)
  8717.         {
  8718.           const_op -= 1;
  8719.           op1 = GEN_INT (const_op);
  8720.           code = LE;
  8721.           /* ... fall through to LE case below.  */
  8722.         }
  8723.       else
  8724.         break;
  8725.  
  8726.     case LE:
  8727.       /* <= C is equivalent to < (C + 1); we do this for C < 0  */
  8728.       if (const_op < 0)
  8729.         {
  8730.           const_op += 1;
  8731.           op1 = GEN_INT (const_op);
  8732.           code = LT;
  8733.         }
  8734.  
  8735.       /* If we are doing a <= 0 comparison on a value known to have
  8736.          a zero sign bit, we can replace this with == 0.  */
  8737.       else if (const_op == 0
  8738.            && mode_width <= HOST_BITS_PER_WIDE_INT
  8739.            && (nonzero_bits (op0, mode)
  8740.                & ((HOST_WIDE_INT) 1 << (mode_width - 1))) == 0)
  8741.         code = EQ;
  8742.       break;
  8743.  
  8744.     case GE:
  8745.       /* >= C is equivalent to > (C - 1). */
  8746.       if (const_op > 0)
  8747.         {
  8748.           const_op -= 1;
  8749.           op1 = GEN_INT (const_op);
  8750.           code = GT;
  8751.           /* ... fall through to GT below.  */
  8752.         }
  8753.       else
  8754.         break;
  8755.  
  8756.     case GT:
  8757.       /* > C is equivalent to >= (C + 1); we do this for C < 0*/
  8758.       if (const_op < 0)
  8759.         {
  8760.           const_op += 1;
  8761.           op1 = GEN_INT (const_op);
  8762.           code = GE;
  8763.         }
  8764.  
  8765.       /* If we are doing a > 0 comparison on a value known to have
  8766.          a zero sign bit, we can replace this with != 0.  */
  8767.       else if (const_op == 0
  8768.            && mode_width <= HOST_BITS_PER_WIDE_INT
  8769.            && (nonzero_bits (op0, mode)
  8770.                & ((HOST_WIDE_INT) 1 << (mode_width - 1))) == 0)
  8771.         code = NE;
  8772.       break;
  8773.  
  8774.     case LTU:
  8775.       /* < C is equivalent to <= (C - 1).  */
  8776.       if (const_op > 0)
  8777.         {
  8778.           const_op -= 1;
  8779.           op1 = GEN_INT (const_op);
  8780.           code = LEU;
  8781.           /* ... fall through ... */
  8782.         }
  8783.  
  8784.       /* (unsigned) < 0x80000000 is equivalent to >= 0.  */
  8785.       else if (const_op == (HOST_WIDE_INT) 1 << (mode_width - 1))
  8786.         {
  8787.           const_op = 0, op1 = const0_rtx;
  8788.           code = GE;
  8789.           break;
  8790.         }
  8791.       else
  8792.         break;
  8793.  
  8794.     case LEU:
  8795.       /* unsigned <= 0 is equivalent to == 0 */
  8796.       if (const_op == 0)
  8797.         code = EQ;
  8798.  
  8799.       /* (unsigned) <= 0x7fffffff is equivalent to >= 0. */
  8800.       else if (const_op == ((HOST_WIDE_INT) 1 << (mode_width - 1)) - 1)
  8801.         {
  8802.           const_op = 0, op1 = const0_rtx;
  8803.           code = GE;
  8804.         }
  8805.       break;
  8806.  
  8807.     case GEU:
  8808.       /* >= C is equivalent to < (C - 1).  */
  8809.       if (const_op > 1)
  8810.         {
  8811.           const_op -= 1;
  8812.           op1 = GEN_INT (const_op);
  8813.           code = GTU;
  8814.           /* ... fall through ... */
  8815.         }
  8816.  
  8817.       /* (unsigned) >= 0x80000000 is equivalent to < 0.  */
  8818.       else if (const_op == (HOST_WIDE_INT) 1 << (mode_width - 1))
  8819.         {
  8820.           const_op = 0, op1 = const0_rtx;
  8821.           code = LT;
  8822.         }
  8823.       else
  8824.         break;
  8825.  
  8826.     case GTU:
  8827.       /* unsigned > 0 is equivalent to != 0 */
  8828.       if (const_op == 0)
  8829.         code = NE;
  8830.  
  8831.       /* (unsigned) > 0x7fffffff is equivalent to < 0.  */
  8832.       else if (const_op == ((HOST_WIDE_INT) 1 << (mode_width - 1)) - 1)
  8833.         {
  8834.           const_op = 0, op1 = const0_rtx;
  8835.           code = LT;
  8836.         }
  8837.       break;
  8838.     }
  8839.  
  8840.       /* Compute some predicates to simplify code below.  */
  8841.  
  8842.       equality_comparison_p = (code == EQ || code == NE);
  8843.       sign_bit_comparison_p = ((code == LT || code == GE) && const_op == 0);
  8844.       unsigned_comparison_p = (code == LTU || code == LEU || code == GTU
  8845.                    || code == LEU);
  8846.  
  8847.       /* If this is a sign bit comparison and we can do arithmetic in
  8848.      MODE, say that we will only be needing the sign bit of OP0.  */
  8849.       if (sign_bit_comparison_p
  8850.       && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
  8851.     op0 = force_to_mode (op0, mode,
  8852.                  ((HOST_WIDE_INT) 1
  8853.                   << (GET_MODE_BITSIZE (mode) - 1)),
  8854.                  NULL_RTX, 0);
  8855.  
  8856.       /* Now try cases based on the opcode of OP0.  If none of the cases
  8857.      does a "continue", we exit this loop immediately after the
  8858.      switch.  */
  8859.  
  8860.       switch (GET_CODE (op0))
  8861.     {
  8862.     case ZERO_EXTRACT:
  8863.       /* If we are extracting a single bit from a variable position in
  8864.          a constant that has only a single bit set and are comparing it
  8865.          with zero, we can convert this into an equality comparison 
  8866.          between the position and the location of the single bit.  We can't
  8867.          do this if bit endian and we don't have an extzv since we then
  8868.          can't know what mode to use for the endianness adjustment.  */
  8869.  
  8870. #if ! BITS_BIG_ENDIAN || defined (HAVE_extzv)
  8871.       if (GET_CODE (XEXP (op0, 0)) == CONST_INT
  8872.           && XEXP (op0, 1) == const1_rtx
  8873.           && equality_comparison_p && const_op == 0
  8874.           && (i = exact_log2 (INTVAL (XEXP (op0, 0)))) >= 0)
  8875.         {
  8876. #if BITS_BIG_ENDIAN
  8877.           i = (GET_MODE_BITSIZE
  8878.            (insn_operand_mode[(int) CODE_FOR_extzv][1]) - 1 - i);
  8879. #endif
  8880.  
  8881.           op0 = XEXP (op0, 2);
  8882.           op1 = GEN_INT (i);
  8883.           const_op = i;
  8884.  
  8885.           /* Result is nonzero iff shift count is equal to I.  */
  8886.           code = reverse_condition (code);
  8887.           continue;
  8888.         }
  8889. #endif
  8890.  
  8891.       /* ... fall through ... */
  8892.  
  8893.     case SIGN_EXTRACT:
  8894.       tem = expand_compound_operation (op0);
  8895.       if (tem != op0)
  8896.         {
  8897.           op0 = tem;
  8898.           continue;
  8899.         }
  8900.       break;
  8901.  
  8902.     case NOT:
  8903.       /* If testing for equality, we can take the NOT of the constant.  */
  8904.       if (equality_comparison_p
  8905.           && (tem = simplify_unary_operation (NOT, mode, op1, mode)) != 0)
  8906.         {
  8907.           op0 = XEXP (op0, 0);
  8908.           op1 = tem;
  8909.           continue;
  8910.         }
  8911.  
  8912.       /* If just looking at the sign bit, reverse the sense of the
  8913.          comparison.  */
  8914.       if (sign_bit_comparison_p)
  8915.         {
  8916.           op0 = XEXP (op0, 0);
  8917.           code = (code == GE ? LT : GE);
  8918.           continue;
  8919.         }
  8920.       break;
  8921.  
  8922.     case NEG:
  8923.       /* If testing for equality, we can take the NEG of the constant.  */
  8924.       if (equality_comparison_p
  8925.           && (tem = simplify_unary_operation (NEG, mode, op1, mode)) != 0)
  8926.         {
  8927.           op0 = XEXP (op0, 0);
  8928.           op1 = tem;
  8929.           continue;
  8930.         }
  8931.  
  8932.       /* The remaining cases only apply to comparisons with zero.  */
  8933.       if (const_op != 0)
  8934.         break;
  8935.  
  8936.       /* When X is ABS or is known positive,
  8937.          (neg X) is < 0 if and only if X != 0.  */
  8938.  
  8939.       if (sign_bit_comparison_p
  8940.           && (GET_CODE (XEXP (op0, 0)) == ABS
  8941.           || (mode_width <= HOST_BITS_PER_WIDE_INT
  8942.               && (nonzero_bits (XEXP (op0, 0), mode)
  8943.               & ((HOST_WIDE_INT) 1 << (mode_width - 1))) == 0)))
  8944.         {
  8945.           op0 = XEXP (op0, 0);
  8946.           code = (code == LT ? NE : EQ);
  8947.           continue;
  8948.         }
  8949.  
  8950.       /* If we have NEG of something whose two high-order bits are the
  8951.          same, we know that "(-a) < 0" is equivalent to "a > 0". */
  8952.       if (num_sign_bit_copies (op0, mode) >= 2)
  8953.         {
  8954.           op0 = XEXP (op0, 0);
  8955.           code = swap_condition (code);
  8956.           continue;
  8957.         }
  8958.       break;
  8959.  
  8960.     case ROTATE:
  8961.       /* If we are testing equality and our count is a constant, we
  8962.          can perform the inverse operation on our RHS.  */
  8963.       if (equality_comparison_p && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8964.           && (tem = simplify_binary_operation (ROTATERT, mode,
  8965.                            op1, XEXP (op0, 1))) != 0)
  8966.         {
  8967.           op0 = XEXP (op0, 0);
  8968.           op1 = tem;
  8969.           continue;
  8970.         }
  8971.  
  8972.       /* If we are doing a < 0 or >= 0 comparison, it means we are testing
  8973.          a particular bit.  Convert it to an AND of a constant of that
  8974.          bit.  This will be converted into a ZERO_EXTRACT.  */
  8975.       if (const_op == 0 && sign_bit_comparison_p
  8976.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  8977.           && mode_width <= HOST_BITS_PER_WIDE_INT)
  8978.         {
  8979.           op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0),
  8980.                         ((HOST_WIDE_INT) 1
  8981.                          << (mode_width - 1
  8982.                          - INTVAL (XEXP (op0, 1)))));
  8983.           code = (code == LT ? NE : EQ);
  8984.           continue;
  8985.         }
  8986.  
  8987.       /* ... fall through ... */
  8988.  
  8989.     case ABS:
  8990.       /* ABS is ignorable inside an equality comparison with zero.  */
  8991.       if (const_op == 0 && equality_comparison_p)
  8992.         {
  8993.           op0 = XEXP (op0, 0);
  8994.           continue;
  8995.         }
  8996.       break;
  8997.       
  8998.  
  8999.     case SIGN_EXTEND:
  9000.       /* Can simplify (compare (zero/sign_extend FOO) CONST)
  9001.          to (compare FOO CONST) if CONST fits in FOO's mode and we 
  9002.          are either testing inequality or have an unsigned comparison
  9003.          with ZERO_EXTEND or a signed comparison with SIGN_EXTEND.  */
  9004.       if (! unsigned_comparison_p
  9005.           && (GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
  9006.           <= HOST_BITS_PER_WIDE_INT)
  9007.           && ((unsigned HOST_WIDE_INT) const_op
  9008.           < (((HOST_WIDE_INT) 1
  9009.               << (GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))) - 1)))))
  9010.         {
  9011.           op0 = XEXP (op0, 0);
  9012.           continue;
  9013.         }
  9014.       break;
  9015.  
  9016.     case SUBREG:
  9017.       /* Check for the case where we are comparing A - C1 with C2,
  9018.          both constants are smaller than 1/2 the maxium positive
  9019.          value in MODE, and the comparison is equality or unsigned.
  9020.          In that case, if A is either zero-extended to MODE or has
  9021.          sufficient sign bits so that the high-order bit in MODE
  9022.          is a copy of the sign in the inner mode, we can prove that it is
  9023.          safe to do the operation in the wider mode.  This simplifies
  9024.          many range checks.  */
  9025.  
  9026.       if (mode_width <= HOST_BITS_PER_WIDE_INT
  9027.           && subreg_lowpart_p (op0)
  9028.           && GET_CODE (SUBREG_REG (op0)) == PLUS
  9029.           && GET_CODE (XEXP (SUBREG_REG (op0), 1)) == CONST_INT
  9030.           && INTVAL (XEXP (SUBREG_REG (op0), 1)) < 0
  9031.           && (- INTVAL (XEXP (SUBREG_REG (op0), 1))
  9032.           < GET_MODE_MASK (mode) / 2)
  9033.           && (unsigned HOST_WIDE_INT) const_op < GET_MODE_MASK (mode) / 2
  9034.           && (0 == (nonzero_bits (XEXP (SUBREG_REG (op0), 0),
  9035.                       GET_MODE (SUBREG_REG (op0)))
  9036.             & ~ GET_MODE_MASK (mode))
  9037.           || (num_sign_bit_copies (XEXP (SUBREG_REG (op0), 0),
  9038.                        GET_MODE (SUBREG_REG (op0)))
  9039.               > (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
  9040.              - GET_MODE_BITSIZE (mode)))))
  9041.         {
  9042.           op0 = SUBREG_REG (op0);
  9043.           continue;
  9044.         }
  9045.  
  9046.       /* If the inner mode is narrower and we are extracting the low part,
  9047.          we can treat the SUBREG as if it were a ZERO_EXTEND.  */
  9048.       if (subreg_lowpart_p (op0)
  9049.           && GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0))) < mode_width)
  9050.         /* Fall through */ ;
  9051.       else
  9052.         break;
  9053.  
  9054.       /* ... fall through ... */
  9055.  
  9056.     case ZERO_EXTEND:
  9057.       if ((unsigned_comparison_p || equality_comparison_p)
  9058.           && (GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
  9059.           <= HOST_BITS_PER_WIDE_INT)
  9060.           && ((unsigned HOST_WIDE_INT) const_op
  9061.           < GET_MODE_MASK (GET_MODE (XEXP (op0, 0)))))
  9062.         {
  9063.           op0 = XEXP (op0, 0);
  9064.           continue;
  9065.         }
  9066.       break;
  9067.  
  9068.     case PLUS:
  9069.       /* (eq (plus X A) B) -> (eq X (minus B A)).  We can only do
  9070.          this for equality comparisons due to pathological cases involving
  9071.          overflows.  */
  9072.       if (equality_comparison_p
  9073.           && 0 != (tem = simplify_binary_operation (MINUS, mode,
  9074.                             op1, XEXP (op0, 1))))
  9075.         {
  9076.           op0 = XEXP (op0, 0);
  9077.           op1 = tem;
  9078.           continue;
  9079.         }
  9080.  
  9081.       /* (plus (abs X) (const_int -1)) is < 0 if and only if X == 0.  */
  9082.       if (const_op == 0 && XEXP (op0, 1) == constm1_rtx
  9083.           && GET_CODE (XEXP (op0, 0)) == ABS && sign_bit_comparison_p)
  9084.         {
  9085.           op0 = XEXP (XEXP (op0, 0), 0);
  9086.           code = (code == LT ? EQ : NE);
  9087.           continue;
  9088.         }
  9089.       break;
  9090.  
  9091.     case MINUS:
  9092.       /* (eq (minus A B) C) -> (eq A (plus B C)) or
  9093.          (eq B (minus A C)), whichever simplifies.  We can only do
  9094.          this for equality comparisons due to pathological cases involving
  9095.          overflows.  */
  9096.       if (equality_comparison_p
  9097.           && 0 != (tem = simplify_binary_operation (PLUS, mode,
  9098.                             XEXP (op0, 1), op1)))
  9099.         {
  9100.           op0 = XEXP (op0, 0);
  9101.           op1 = tem;
  9102.           continue;
  9103.         }
  9104.  
  9105.       if (equality_comparison_p
  9106.           && 0 != (tem = simplify_binary_operation (MINUS, mode,
  9107.                             XEXP (op0, 0), op1)))
  9108.         {
  9109.           op0 = XEXP (op0, 1);
  9110.           op1 = tem;
  9111.           continue;
  9112.         }
  9113.  
  9114.       /* The sign bit of (minus (ashiftrt X C) X), where C is the number
  9115.          of bits in X minus 1, is one iff X > 0.  */
  9116.       if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 0)) == ASHIFTRT
  9117.           && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT
  9118.           && INTVAL (XEXP (XEXP (op0, 0), 1)) == mode_width - 1
  9119.           && rtx_equal_p (XEXP (XEXP (op0, 0), 0), XEXP (op0, 1)))
  9120.         {
  9121.           op0 = XEXP (op0, 1);
  9122.           code = (code == GE ? LE : GT);
  9123.           continue;
  9124.         }
  9125.       break;
  9126.  
  9127.     case XOR:
  9128.       /* (eq (xor A B) C) -> (eq A (xor B C)).  This is a simplification
  9129.          if C is zero or B is a constant.  */
  9130.       if (equality_comparison_p
  9131.           && 0 != (tem = simplify_binary_operation (XOR, mode,
  9132.                             XEXP (op0, 1), op1)))
  9133.         {
  9134.           op0 = XEXP (op0, 0);
  9135.           op1 = tem;
  9136.           continue;
  9137.         }
  9138.       break;
  9139.  
  9140.     case EQ:  case NE:
  9141.     case LT:  case LTU:  case LE:  case LEU:
  9142.     case GT:  case GTU:  case GE:  case GEU:
  9143.       /* We can't do anything if OP0 is a condition code value, rather
  9144.          than an actual data value.  */
  9145.       if (const_op != 0
  9146. #ifdef HAVE_cc0
  9147.           || XEXP (op0, 0) == cc0_rtx
  9148. #endif
  9149.           || GET_MODE_CLASS (GET_MODE (XEXP (op0, 0))) == MODE_CC)
  9150.         break;
  9151.  
  9152.       /* Get the two operands being compared.  */
  9153.       if (GET_CODE (XEXP (op0, 0)) == COMPARE)
  9154.         tem = XEXP (XEXP (op0, 0), 0), tem1 = XEXP (XEXP (op0, 0), 1);
  9155.       else
  9156.         tem = XEXP (op0, 0), tem1 = XEXP (op0, 1);
  9157.  
  9158.       /* Check for the cases where we simply want the result of the
  9159.          earlier test or the opposite of that result.  */
  9160.       if (code == NE
  9161.           || (code == EQ && reversible_comparison_p (op0))
  9162.           || (GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT
  9163.           && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
  9164.           && (STORE_FLAG_VALUE
  9165.               & (((HOST_WIDE_INT) 1
  9166.               << (GET_MODE_BITSIZE (GET_MODE (op0)) - 1))))
  9167.           && (code == LT
  9168.               || (code == GE && reversible_comparison_p (op0)))))
  9169.         {
  9170.           code = (code == LT || code == NE
  9171.               ? GET_CODE (op0) : reverse_condition (GET_CODE (op0)));
  9172.           op0 = tem, op1 = tem1;
  9173.           continue;
  9174.         }
  9175.       break;
  9176.  
  9177.     case IOR:
  9178.       /* The sign bit of (ior (plus X (const_int -1)) X) is non-zero
  9179.          iff X <= 0.  */
  9180.       if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 0)) == PLUS
  9181.           && XEXP (XEXP (op0, 0), 1) == constm1_rtx
  9182.           && rtx_equal_p (XEXP (XEXP (op0, 0), 0), XEXP (op0, 1)))
  9183.         {
  9184.           op0 = XEXP (op0, 1);
  9185.           code = (code == GE ? GT : LE);
  9186.           continue;
  9187.         }
  9188.       break;
  9189.  
  9190.     case AND:
  9191.       /* Convert (and (xshift 1 X) Y) to (and (lshiftrt Y X) 1).  This
  9192.          will be converted to a ZERO_EXTRACT later.  */
  9193.       if (const_op == 0 && equality_comparison_p
  9194.           && GET_CODE (XEXP (op0, 0)) == ASHIFT
  9195.           && XEXP (XEXP (op0, 0), 0) == const1_rtx)
  9196.         {
  9197.           op0 = simplify_and_const_int
  9198.         (op0, mode, gen_rtx_combine (LSHIFTRT, mode,
  9199.                          XEXP (op0, 1),
  9200.                          XEXP (XEXP (op0, 0), 1)),
  9201.          (HOST_WIDE_INT) 1);
  9202.           continue;
  9203.         }
  9204.  
  9205.       /* If we are comparing (and (lshiftrt X C1) C2) for equality with
  9206.          zero and X is a comparison and C1 and C2 describe only bits set
  9207.          in STORE_FLAG_VALUE, we can compare with X.  */
  9208.       if (const_op == 0 && equality_comparison_p
  9209.           && mode_width <= HOST_BITS_PER_WIDE_INT
  9210.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  9211.           && GET_CODE (XEXP (op0, 0)) == LSHIFTRT
  9212.           && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT
  9213.           && INTVAL (XEXP (XEXP (op0, 0), 1)) >= 0
  9214.           && INTVAL (XEXP (XEXP (op0, 0), 1)) < HOST_BITS_PER_WIDE_INT)
  9215.         {
  9216.           mask = ((INTVAL (XEXP (op0, 1)) & GET_MODE_MASK (mode))
  9217.               << INTVAL (XEXP (XEXP (op0, 0), 1)));
  9218.           if ((~ STORE_FLAG_VALUE & mask) == 0
  9219.           && (GET_RTX_CLASS (GET_CODE (XEXP (XEXP (op0, 0), 0))) == '<'
  9220.               || ((tem = get_last_value (XEXP (XEXP (op0, 0), 0))) != 0
  9221.               && GET_RTX_CLASS (GET_CODE (tem)) == '<')))
  9222.         {
  9223.           op0 = XEXP (XEXP (op0, 0), 0);
  9224.           continue;
  9225.         }
  9226.         }
  9227.  
  9228.       /* If we are doing an equality comparison of an AND of a bit equal
  9229.          to the sign bit, replace this with a LT or GE comparison of
  9230.          the underlying value.  */
  9231.       if (equality_comparison_p
  9232.           && const_op == 0
  9233.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  9234.           && mode_width <= HOST_BITS_PER_WIDE_INT
  9235.           && ((INTVAL (XEXP (op0, 1)) & GET_MODE_MASK (mode))
  9236.           == (HOST_WIDE_INT) 1 << (mode_width - 1)))
  9237.         {
  9238.           op0 = XEXP (op0, 0);
  9239.           code = (code == EQ ? GE : LT);
  9240.           continue;
  9241.         }
  9242.  
  9243.       /* If this AND operation is really a ZERO_EXTEND from a narrower
  9244.          mode, the constant fits within that mode, and this is either an
  9245.          equality or unsigned comparison, try to do this comparison in
  9246.          the narrower mode.  */
  9247.       if ((equality_comparison_p || unsigned_comparison_p)
  9248.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  9249.           && (i = exact_log2 ((INTVAL (XEXP (op0, 1))
  9250.                    & GET_MODE_MASK (mode))
  9251.                   + 1)) >= 0
  9252.           && const_op >> i == 0
  9253.           && (tmode = mode_for_size (i, MODE_INT, 1)) != BLKmode)
  9254.         {
  9255.           op0 = gen_lowpart_for_combine (tmode, XEXP (op0, 0));
  9256.           continue;
  9257.         }
  9258.       break;
  9259.  
  9260.     case ASHIFT:
  9261.       /* If we have (compare (ashift FOO N) (const_int C)) and
  9262.          the high order N bits of FOO (N+1 if an inequality comparison)
  9263.          are known to be zero, we can do this by comparing FOO with C
  9264.          shifted right N bits so long as the low-order N bits of C are
  9265.          zero.  */
  9266.       if (GET_CODE (XEXP (op0, 1)) == CONST_INT
  9267.           && INTVAL (XEXP (op0, 1)) >= 0
  9268.           && ((INTVAL (XEXP (op0, 1)) + ! equality_comparison_p)
  9269.           < HOST_BITS_PER_WIDE_INT)
  9270.           && ((const_op
  9271.            & (((HOST_WIDE_INT) 1 << INTVAL (XEXP (op0, 1))) - 1)) == 0)
  9272.           && mode_width <= HOST_BITS_PER_WIDE_INT
  9273.           && (nonzero_bits (XEXP (op0, 0), mode)
  9274.           & ~ (mask >> (INTVAL (XEXP (op0, 1))
  9275.                 + ! equality_comparison_p))) == 0)
  9276.         {
  9277.           const_op >>= INTVAL (XEXP (op0, 1));
  9278.           op1 = GEN_INT (const_op);
  9279.           op0 = XEXP (op0, 0);
  9280.           continue;
  9281.         }
  9282.  
  9283.       /* If we are doing a sign bit comparison, it means we are testing
  9284.          a particular bit.  Convert it to the appropriate AND.  */
  9285.       if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 1)) == CONST_INT
  9286.           && mode_width <= HOST_BITS_PER_WIDE_INT)
  9287.         {
  9288.           op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0),
  9289.                         ((HOST_WIDE_INT) 1
  9290.                          << (mode_width - 1
  9291.                          - INTVAL (XEXP (op0, 1)))));
  9292.           code = (code == LT ? NE : EQ);
  9293.           continue;
  9294.         }
  9295.  
  9296.       /* If this an equality comparison with zero and we are shifting
  9297.          the low bit to the sign bit, we can convert this to an AND of the
  9298.          low-order bit.  */
  9299.       if (const_op == 0 && equality_comparison_p
  9300.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  9301.           && INTVAL (XEXP (op0, 1)) == mode_width - 1)
  9302.         {
  9303.           op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0),
  9304.                         (HOST_WIDE_INT) 1);
  9305.           continue;
  9306.         }
  9307.       break;
  9308.  
  9309.     case ASHIFTRT:
  9310.       /* If this is an equality comparison with zero, we can do this
  9311.          as a logical shift, which might be much simpler.  */
  9312.       if (equality_comparison_p && const_op == 0
  9313.           && GET_CODE (XEXP (op0, 1)) == CONST_INT)
  9314.         {
  9315.           op0 = simplify_shift_const (NULL_RTX, LSHIFTRT, mode,
  9316.                       XEXP (op0, 0),
  9317.                       INTVAL (XEXP (op0, 1)));
  9318.           continue;
  9319.         }
  9320.  
  9321.       /* If OP0 is a sign extension and CODE is not an unsigned comparison,
  9322.          do the comparison in a narrower mode.  */
  9323.       if (! unsigned_comparison_p
  9324.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  9325.           && GET_CODE (XEXP (op0, 0)) == ASHIFT
  9326.           && XEXP (op0, 1) == XEXP (XEXP (op0, 0), 1)
  9327.           && (tmode = mode_for_size (mode_width - INTVAL (XEXP (op0, 1)),
  9328.                      MODE_INT, 1)) != BLKmode
  9329.           && ((unsigned HOST_WIDE_INT) const_op <= GET_MODE_MASK (tmode)
  9330.           || ((unsigned HOST_WIDE_INT) - const_op
  9331.               <= GET_MODE_MASK (tmode))))
  9332.         {
  9333.           op0 = gen_lowpart_for_combine (tmode, XEXP (XEXP (op0, 0), 0));
  9334.           continue;
  9335.         }
  9336.  
  9337.       /* ... fall through ... */
  9338.     case LSHIFTRT:
  9339.       /* If we have (compare (xshiftrt FOO N) (const_int C)) and
  9340.          the low order N bits of FOO are known to be zero, we can do this
  9341.          by comparing FOO with C shifted left N bits so long as no
  9342.          overflow occurs.  */
  9343.       if (GET_CODE (XEXP (op0, 1)) == CONST_INT
  9344.           && INTVAL (XEXP (op0, 1)) >= 0
  9345.           && INTVAL (XEXP (op0, 1)) < HOST_BITS_PER_WIDE_INT
  9346.           && mode_width <= HOST_BITS_PER_WIDE_INT
  9347.           && (nonzero_bits (XEXP (op0, 0), mode)
  9348.           & (((HOST_WIDE_INT) 1 << INTVAL (XEXP (op0, 1))) - 1)) == 0
  9349.           && (const_op == 0
  9350.           || (floor_log2 (const_op) + INTVAL (XEXP (op0, 1))
  9351.               < mode_width)))
  9352.         {
  9353.           const_op <<= INTVAL (XEXP (op0, 1));
  9354.           op1 = GEN_INT (const_op);
  9355.           op0 = XEXP (op0, 0);
  9356.           continue;
  9357.         }
  9358.  
  9359.       /* If we are using this shift to extract just the sign bit, we
  9360.          can replace this with an LT or GE comparison.  */
  9361.       if (const_op == 0
  9362.           && (equality_comparison_p || sign_bit_comparison_p)
  9363.           && GET_CODE (XEXP (op0, 1)) == CONST_INT
  9364.           && INTVAL (XEXP (op0, 1)) == mode_width - 1)
  9365.         {
  9366.           op0 = XEXP (op0, 0);
  9367.           code = (code == NE || code == GT ? LT : GE);
  9368.           continue;
  9369.         }
  9370.       break;
  9371.     }
  9372.  
  9373.       break;
  9374.     }
  9375.  
  9376.   /* Now make any compound operations involved in this comparison.  Then,
  9377.      check for an outmost SUBREG on OP0 that isn't doing anything or is
  9378.      paradoxical.  The latter case can only occur when it is known that the
  9379.      "extra" bits will be zero.  Therefore, it is safe to remove the SUBREG.
  9380.      We can never remove a SUBREG for a non-equality comparison because the
  9381.      sign bit is in a different place in the underlying object.  */
  9382.  
  9383.   op0 = make_compound_operation (op0, op1 == const0_rtx ? COMPARE : SET);
  9384.   op1 = make_compound_operation (op1, SET);
  9385.  
  9386.   if (GET_CODE (op0) == SUBREG && subreg_lowpart_p (op0)
  9387.       && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
  9388.       && (code == NE || code == EQ)
  9389.       && ((GET_MODE_SIZE (GET_MODE (op0))
  9390.        > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0))))))
  9391.     {
  9392.       op0 = SUBREG_REG (op0);
  9393.       op1 = gen_lowpart_for_combine (GET_MODE (op0), op1);
  9394.     }
  9395.  
  9396.   else if (GET_CODE (op0) == SUBREG && subreg_lowpart_p (op0)
  9397.        && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
  9398.        && (code == NE || code == EQ)
  9399.        && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0)))
  9400.            <= HOST_BITS_PER_WIDE_INT)
  9401.        && (nonzero_bits (SUBREG_REG (op0), GET_MODE (SUBREG_REG (op0)))
  9402.            & ~ GET_MODE_MASK (GET_MODE (op0))) == 0
  9403.        && (tem = gen_lowpart_for_combine (GET_MODE (SUBREG_REG (op0)),
  9404.                           op1),
  9405.            (nonzero_bits (tem, GET_MODE (SUBREG_REG (op0)))
  9406.         & ~ GET_MODE_MASK (GET_MODE (op0))) == 0))
  9407.     op0 = SUBREG_REG (op0), op1 = tem;
  9408.  
  9409.   /* We now do the opposite procedure: Some machines don't have compare
  9410.      insns in all modes.  If OP0's mode is an integer mode smaller than a
  9411.      word and we can't do a compare in that mode, see if there is a larger
  9412.      mode for which we can do the compare.  There are a number of cases in
  9413.      which we can use the wider mode.  */
  9414.  
  9415.   mode = GET_MODE (op0);
  9416.   if (mode != VOIDmode && GET_MODE_CLASS (mode) == MODE_INT
  9417.       && GET_MODE_SIZE (mode) < UNITS_PER_WORD
  9418.       && cmp_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
  9419.     for (tmode = GET_MODE_WIDER_MODE (mode);
  9420.      (tmode != VOIDmode
  9421.       && GET_MODE_BITSIZE (tmode) <= HOST_BITS_PER_WIDE_INT);
  9422.      tmode = GET_MODE_WIDER_MODE (tmode))
  9423.       if (cmp_optab->handlers[(int) tmode].insn_code != CODE_FOR_nothing)
  9424.     {
  9425.       /* If the only nonzero bits in OP0 and OP1 are those in the
  9426.          narrower mode and this is an equality or unsigned comparison,
  9427.          we can use the wider mode.  Similarly for sign-extended
  9428.          values, in which case it is true for all comparisons.  */
  9429.       if (((code == EQ || code == NE
  9430.         || code == GEU || code == GTU || code == LEU || code == LTU)
  9431.            && (nonzero_bits (op0, tmode) & ~ GET_MODE_MASK (mode)) == 0
  9432.            && (nonzero_bits (op1, tmode) & ~ GET_MODE_MASK (mode)) == 0)
  9433.           || ((num_sign_bit_copies (op0, tmode)
  9434.            > GET_MODE_BITSIZE (tmode) - GET_MODE_BITSIZE (mode))
  9435.           && (num_sign_bit_copies (op1, tmode)
  9436.               > GET_MODE_BITSIZE (tmode) - GET_MODE_BITSIZE (mode))))
  9437.         {
  9438.           op0 = gen_lowpart_for_combine (tmode, op0);
  9439.           op1 = gen_lowpart_for_combine (tmode, op1);
  9440.           break;
  9441.         }
  9442.  
  9443.       /* If this is a test for negative, we can make an explicit
  9444.          test of the sign bit.  */
  9445.  
  9446.       if (op1 == const0_rtx && (code == LT || code == GE)
  9447.           && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
  9448.         {
  9449.           op0 = gen_binary (AND, tmode,
  9450.                 gen_lowpart_for_combine (tmode, op0),
  9451.                 GEN_INT ((HOST_WIDE_INT) 1
  9452.                      << (GET_MODE_BITSIZE (mode) - 1)));
  9453.           code = (code == LT) ? NE : EQ;
  9454.           break;
  9455.         }
  9456.     }
  9457.  
  9458. #ifdef CANONICALIZE_COMPARISON
  9459.   /* If this machine only supports a subset of valid comparisons, see if we
  9460.      can convert an unsupported one into a supported one.  */
  9461.   CANONICALIZE_COMPARISON (code, op0, op1);
  9462. #endif
  9463.  
  9464.   *pop0 = op0;
  9465.   *pop1 = op1;
  9466.  
  9467.   return code;
  9468. }
  9469.  
  9470. /* Return 1 if we know that X, a comparison operation, is not operating
  9471.    on a floating-point value or is EQ or NE, meaning that we can safely
  9472.    reverse it.  */
  9473.  
  9474. static int
  9475. reversible_comparison_p (x)
  9476.      rtx x;
  9477. {
  9478.   if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
  9479.       || flag_fast_math
  9480.       || GET_CODE (x) == NE || GET_CODE (x) == EQ)
  9481.     return 1;
  9482.  
  9483.   switch (GET_MODE_CLASS (GET_MODE (XEXP (x, 0))))
  9484.     {
  9485.     case MODE_INT:
  9486.     case MODE_PARTIAL_INT:
  9487.     case MODE_COMPLEX_INT:
  9488.       return 1;
  9489.  
  9490.     case MODE_CC:
  9491.       /* If the mode of the condition codes tells us that this is safe,
  9492.      we need look no further.  */
  9493.       if (REVERSIBLE_CC_MODE (GET_MODE (XEXP (x, 0))))
  9494.     return 1;
  9495.  
  9496.       /* Otherwise try and find where the condition codes were last set and
  9497.      use that.  */
  9498.       x = get_last_value (XEXP (x, 0));
  9499.       return (x && GET_CODE (x) == COMPARE
  9500.           && ! FLOAT_MODE_P (GET_MODE (XEXP (x, 0))));
  9501.     }
  9502.  
  9503.   return 0;
  9504. }
  9505.  
  9506. /* Utility function for following routine.  Called when X is part of a value
  9507.    being stored into reg_last_set_value.  Sets reg_last_set_table_tick
  9508.    for each register mentioned.  Similar to mention_regs in cse.c  */
  9509.  
  9510. static void
  9511. update_table_tick (x)
  9512.      rtx x;
  9513. {
  9514.   register enum rtx_code code = GET_CODE (x);
  9515.   register char *fmt = GET_RTX_FORMAT (code);
  9516.   register int i;
  9517.  
  9518.   if (code == REG)
  9519.     {
  9520.       int regno = REGNO (x);
  9521.       int endregno = regno + (regno < FIRST_PSEUDO_REGISTER
  9522.                   ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
  9523.  
  9524.       for (i = regno; i < endregno; i++)
  9525.     reg_last_set_table_tick[i] = label_tick;
  9526.  
  9527.       return;
  9528.     }
  9529.   
  9530.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  9531.     /* Note that we can't have an "E" in values stored; see
  9532.        get_last_value_validate.  */
  9533.     if (fmt[i] == 'e')
  9534.       update_table_tick (XEXP (x, i));
  9535. }
  9536.  
  9537. /* Record that REG is set to VALUE in insn INSN.  If VALUE is zero, we
  9538.    are saying that the register is clobbered and we no longer know its
  9539.    value.  If INSN is zero, don't update reg_last_set; this is only permitted
  9540.    with VALUE also zero and is used to invalidate the register.  */
  9541.  
  9542. static void
  9543. record_value_for_reg (reg, insn, value)
  9544.      rtx reg;
  9545.      rtx insn;
  9546.      rtx value;
  9547. {
  9548.   int regno = REGNO (reg);
  9549.   int endregno = regno + (regno < FIRST_PSEUDO_REGISTER
  9550.               ? HARD_REGNO_NREGS (regno, GET_MODE (reg)) : 1);
  9551.   int i;
  9552.  
  9553.   /* If VALUE contains REG and we have a previous value for REG, substitute
  9554.      the previous value.  */
  9555.   if (value && insn && reg_overlap_mentioned_p (reg, value))
  9556.     {
  9557.       rtx tem;
  9558.  
  9559.       /* Set things up so get_last_value is allowed to see anything set up to
  9560.      our insn.  */
  9561.       subst_low_cuid = INSN_CUID (insn);
  9562.       tem = get_last_value (reg);      
  9563.  
  9564.       if (tem)
  9565.     value = replace_rtx (copy_rtx (value), reg, tem);
  9566.     }
  9567.  
  9568.   /* For each register modified, show we don't know its value, that
  9569.      we don't know about its bitwise content, that its value has been
  9570.      updated, and that we don't know the location of the death of the
  9571.      register.  */
  9572.   for (i = regno; i < endregno; i ++)
  9573.     {
  9574.       if (insn)
  9575.     reg_last_set[i] = insn;
  9576.       reg_last_set_value[i] = 0;
  9577.       reg_last_set_mode[i] = 0;
  9578.       reg_last_set_nonzero_bits[i] = 0;
  9579.       reg_last_set_sign_bit_copies[i] = 0;
  9580.       reg_last_death[i] = 0;
  9581.     }
  9582.  
  9583.   /* Mark registers that are being referenced in this value.  */
  9584.   if (value)
  9585.     update_table_tick (value);
  9586.  
  9587.   /* Now update the status of each register being set.
  9588.      If someone is using this register in this block, set this register
  9589.      to invalid since we will get confused between the two lives in this
  9590.      basic block.  This makes using this register always invalid.  In cse, we
  9591.      scan the table to invalidate all entries using this register, but this
  9592.      is too much work for us.  */
  9593.  
  9594.   for (i = regno; i < endregno; i++)
  9595.     {
  9596.       reg_last_set_label[i] = label_tick;
  9597.       if (value && reg_last_set_table_tick[i] == label_tick)
  9598.     reg_last_set_invalid[i] = 1;
  9599.       else
  9600.     reg_last_set_invalid[i] = 0;
  9601.     }
  9602.  
  9603.   /* The value being assigned might refer to X (like in "x++;").  In that
  9604.      case, we must replace it with (clobber (const_int 0)) to prevent
  9605.      infinite loops.  */
  9606.   if (value && ! get_last_value_validate (&value,
  9607.                       reg_last_set_label[regno], 0))
  9608.     {
  9609.       value = copy_rtx (value);
  9610.       if (! get_last_value_validate (&value, reg_last_set_label[regno], 1))
  9611.     value = 0;
  9612.     }
  9613.  
  9614.   /* For the main register being modified, update the value, the mode, the
  9615.      nonzero bits, and the number of sign bit copies.  */
  9616.  
  9617.   reg_last_set_value[regno] = value;
  9618.  
  9619.   if (value)
  9620.     {
  9621.       subst_low_cuid = INSN_CUID (insn);
  9622.       reg_last_set_mode[regno] = GET_MODE (reg);
  9623.       reg_last_set_nonzero_bits[regno] = nonzero_bits (value, GET_MODE (reg));
  9624.       reg_last_set_sign_bit_copies[regno]
  9625.     = num_sign_bit_copies (value, GET_MODE (reg));
  9626.     }
  9627. }
  9628.  
  9629. /* Used for communication between the following two routines.  */
  9630. static rtx record_dead_insn;
  9631.  
  9632. /* Called via note_stores from record_dead_and_set_regs to handle one
  9633.    SET or CLOBBER in an insn.  */
  9634.  
  9635. static void
  9636. record_dead_and_set_regs_1 (dest, setter)
  9637.      rtx dest, setter;
  9638. {
  9639.   if (GET_CODE (dest) == REG)
  9640.     {
  9641.       /* If we are setting the whole register, we know its value.  Otherwise
  9642.      show that we don't know the value.  We can handle SUBREG in
  9643.      some cases.  */
  9644.       if (GET_CODE (setter) == SET && dest == SET_DEST (setter))
  9645.     record_value_for_reg (dest, record_dead_insn, SET_SRC (setter));
  9646.       else if (GET_CODE (setter) == SET
  9647.            && GET_CODE (SET_DEST (setter)) == SUBREG
  9648.            && SUBREG_REG (SET_DEST (setter)) == dest
  9649.            && GET_MODE_BITSIZE (GET_MODE (dest)) <= BITS_PER_WORD
  9650.            && subreg_lowpart_p (SET_DEST (setter)))
  9651.     record_value_for_reg (dest, record_dead_insn,
  9652.                   gen_lowpart_for_combine (GET_MODE (dest),
  9653.                                SET_SRC (setter)));
  9654.       else
  9655.     record_value_for_reg (dest, record_dead_insn, NULL_RTX);
  9656.     }
  9657.   else if (GET_CODE (dest) == MEM
  9658.        /* Ignore pushes, they clobber nothing.  */
  9659.        && ! push_operand (dest, GET_MODE (dest)))
  9660.     mem_last_set = INSN_CUID (record_dead_insn);
  9661. }
  9662.  
  9663. /* Update the records of when each REG was most recently set or killed
  9664.    for the things done by INSN.  This is the last thing done in processing
  9665.    INSN in the combiner loop.
  9666.  
  9667.    We update reg_last_set, reg_last_set_value, reg_last_set_mode,
  9668.    reg_last_set_nonzero_bits, reg_last_set_sign_bit_copies, reg_last_death,
  9669.    and also the similar information mem_last_set (which insn most recently
  9670.    modified memory) and last_call_cuid (which insn was the most recent
  9671.    subroutine call).  */
  9672.  
  9673. static void
  9674. record_dead_and_set_regs (insn)
  9675.      rtx insn;
  9676. {
  9677.   register rtx link;
  9678.   int i;
  9679.  
  9680.   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  9681.     {
  9682.       if (REG_NOTE_KIND (link) == REG_DEAD
  9683.       && GET_CODE (XEXP (link, 0)) == REG)
  9684.     {
  9685.       int regno = REGNO (XEXP (link, 0));
  9686.       int endregno
  9687.         = regno + (regno < FIRST_PSEUDO_REGISTER
  9688.                ? HARD_REGNO_NREGS (regno, GET_MODE (XEXP (link, 0)))
  9689.                : 1);
  9690.  
  9691.       for (i = regno; i < endregno; i++)
  9692.         reg_last_death[i] = insn;
  9693.     }
  9694.       else if (REG_NOTE_KIND (link) == REG_INC)
  9695.     record_value_for_reg (XEXP (link, 0), insn, NULL_RTX);
  9696.     }
  9697.  
  9698.   if (GET_CODE (insn) == CALL_INSN)
  9699.     {
  9700.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  9701.     if (call_used_regs[i])
  9702.       {
  9703.         reg_last_set_value[i] = 0;
  9704.         reg_last_set_mode[i] = 0;
  9705.         reg_last_set_nonzero_bits[i] = 0;
  9706.         reg_last_set_sign_bit_copies[i] = 0;
  9707.         reg_last_death[i] = 0;
  9708.       }
  9709.  
  9710.       last_call_cuid = mem_last_set = INSN_CUID (insn);
  9711.     }
  9712.  
  9713.   record_dead_insn = insn;
  9714.   note_stores (PATTERN (insn), record_dead_and_set_regs_1);
  9715. }
  9716.  
  9717. /* Utility routine for the following function.  Verify that all the registers
  9718.    mentioned in *LOC are valid when *LOC was part of a value set when
  9719.    label_tick == TICK.  Return 0 if some are not.
  9720.  
  9721.    If REPLACE is non-zero, replace the invalid reference with
  9722.    (clobber (const_int 0)) and return 1.  This replacement is useful because
  9723.    we often can get useful information about the form of a value (e.g., if
  9724.    it was produced by a shift that always produces -1 or 0) even though
  9725.    we don't know exactly what registers it was produced from.  */
  9726.  
  9727. static int
  9728. get_last_value_validate (loc, tick, replace)
  9729.      rtx *loc;
  9730.      int tick;
  9731.      int replace;
  9732. {
  9733.   rtx x = *loc;
  9734.   char *fmt = GET_RTX_FORMAT (GET_CODE (x));
  9735.   int len = GET_RTX_LENGTH (GET_CODE (x));
  9736.   int i;
  9737.  
  9738.   if (GET_CODE (x) == REG)
  9739.     {
  9740.       int regno = REGNO (x);
  9741.       int endregno = regno + (regno < FIRST_PSEUDO_REGISTER
  9742.                   ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
  9743.       int j;
  9744.  
  9745.       for (j = regno; j < endregno; j++)
  9746.     if (reg_last_set_invalid[j]
  9747.         /* If this is a pseudo-register that was only set once, it is
  9748.            always valid.  */
  9749.         || (! (regno >= FIRST_PSEUDO_REGISTER && reg_n_sets[regno] == 1)
  9750.         && reg_last_set_label[j] > tick))
  9751.       {
  9752.         if (replace)
  9753.           *loc = gen_rtx (CLOBBER, GET_MODE (x), const0_rtx);
  9754.         return replace;
  9755.       }
  9756.  
  9757.       return 1;
  9758.     }
  9759.  
  9760.   for (i = 0; i < len; i++)
  9761.     if ((fmt[i] == 'e'
  9762.      && get_last_value_validate (&XEXP (x, i), tick, replace) == 0)
  9763.     /* Don't bother with these.  They shouldn't occur anyway.  */
  9764.     || fmt[i] == 'E')
  9765.       return 0;
  9766.  
  9767.   /* If we haven't found a reason for it to be invalid, it is valid.  */
  9768.   return 1;
  9769. }
  9770.  
  9771. /* Get the last value assigned to X, if known.  Some registers
  9772.    in the value may be replaced with (clobber (const_int 0)) if their value
  9773.    is known longer known reliably.  */
  9774.  
  9775. static rtx
  9776. get_last_value (x)
  9777.      rtx x;
  9778. {
  9779.   int regno;
  9780.   rtx value;
  9781.  
  9782.   /* If this is a non-paradoxical SUBREG, get the value of its operand and
  9783.      then convert it to the desired mode.  If this is a paradoxical SUBREG,
  9784.      we cannot predict what values the "extra" bits might have. */
  9785.   if (GET_CODE (x) == SUBREG
  9786.       && subreg_lowpart_p (x)
  9787.       && (GET_MODE_SIZE (GET_MODE (x))
  9788.       <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  9789.       && (value = get_last_value (SUBREG_REG (x))) != 0)
  9790.     return gen_lowpart_for_combine (GET_MODE (x), value);
  9791.  
  9792.   if (GET_CODE (x) != REG)
  9793.     return 0;
  9794.  
  9795.   regno = REGNO (x);
  9796.   value = reg_last_set_value[regno];
  9797.  
  9798.   /* If we don't have a value or if it isn't for this basic block, return 0. */
  9799.  
  9800.   if (value == 0
  9801.       || (reg_n_sets[regno] != 1
  9802.       && reg_last_set_label[regno] != label_tick))
  9803.     return 0;
  9804.  
  9805.   /* If the value was set in a later insn that the ones we are processing,
  9806.      we can't use it even if the register was only set once, but make a quick
  9807.      check to see if the previous insn set it to something.  This is commonly
  9808.      the case when the same pseudo is used by repeated insns.  */
  9809.  
  9810.   if (INSN_CUID (reg_last_set[regno]) >= subst_low_cuid)
  9811.     {
  9812.       rtx insn, set;
  9813.  
  9814.       /* If there is an insn that is supposed to be immediately
  9815.      in front of subst_insn, use it.  */
  9816.       if (subst_prev_insn != 0)
  9817.     insn = subst_prev_insn;
  9818.       else
  9819.     for (insn = prev_nonnote_insn (subst_insn);
  9820.          insn && INSN_CUID (insn) >= subst_low_cuid;
  9821.          insn = prev_nonnote_insn (insn))
  9822.       ;
  9823.  
  9824.       if (insn
  9825.       && (set = single_set (insn)) != 0
  9826.       && rtx_equal_p (SET_DEST (set), x))
  9827.     {
  9828.       value = SET_SRC (set);
  9829.  
  9830.       /* Make sure that VALUE doesn't reference X.  Replace any
  9831.          expliit references with a CLOBBER.  If there are any remaining
  9832.          references (rare), don't use the value.  */
  9833.  
  9834.       if (reg_mentioned_p (x, value))
  9835.         value = replace_rtx (copy_rtx (value), x,
  9836.                  gen_rtx (CLOBBER, GET_MODE (x), const0_rtx));
  9837.  
  9838.       if (reg_overlap_mentioned_p (x, value))
  9839.         return 0;
  9840.     }
  9841.       else
  9842.     return 0;
  9843.     }
  9844.  
  9845.   /* If the value has all its registers valid, return it.  */
  9846.   if (get_last_value_validate (&value, reg_last_set_label[regno], 0))
  9847.     return value;
  9848.  
  9849.   /* Otherwise, make a copy and replace any invalid register with
  9850.      (clobber (const_int 0)).  If that fails for some reason, return 0.  */
  9851.  
  9852.   value = copy_rtx (value);
  9853.   if (get_last_value_validate (&value, reg_last_set_label[regno], 1))
  9854.     return value;
  9855.  
  9856.   return 0;
  9857. }
  9858.  
  9859. /* Return nonzero if expression X refers to a REG or to memory
  9860.    that is set in an instruction more recent than FROM_CUID.  */
  9861.  
  9862. static int
  9863. use_crosses_set_p (x, from_cuid)
  9864.      register rtx x;
  9865.      int from_cuid;
  9866. {
  9867.   register char *fmt;
  9868.   register int i;
  9869.   register enum rtx_code code = GET_CODE (x);
  9870.  
  9871.   if (code == REG)
  9872.     {
  9873.       register int regno = REGNO (x);
  9874.       int endreg = regno + (regno < FIRST_PSEUDO_REGISTER
  9875.                 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
  9876.       
  9877. #ifdef PUSH_ROUNDING
  9878.       /* Don't allow uses of the stack pointer to be moved,
  9879.      because we don't know whether the move crosses a push insn.  */
  9880.       if (regno == STACK_POINTER_REGNUM)
  9881.     return 1;
  9882. #endif
  9883.       for (;regno < endreg; regno++)
  9884.     if (reg_last_set[regno]
  9885.         && INSN_CUID (reg_last_set[regno]) > from_cuid)
  9886.       return 1;
  9887.       return 0;
  9888.     }
  9889.  
  9890.   if (code == MEM && mem_last_set > from_cuid)
  9891.     return 1;
  9892.  
  9893.   fmt = GET_RTX_FORMAT (code);
  9894.  
  9895.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  9896.     {
  9897.       if (fmt[i] == 'E')
  9898.     {
  9899.       register int j;
  9900.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  9901.         if (use_crosses_set_p (XVECEXP (x, i, j), from_cuid))
  9902.           return 1;
  9903.     }
  9904.       else if (fmt[i] == 'e'
  9905.            && use_crosses_set_p (XEXP (x, i), from_cuid))
  9906.     return 1;
  9907.     }
  9908.   return 0;
  9909. }
  9910.  
  9911. /* Define three variables used for communication between the following
  9912.    routines.  */
  9913.  
  9914. static int reg_dead_regno, reg_dead_endregno;
  9915. static int reg_dead_flag;
  9916.  
  9917. /* Function called via note_stores from reg_dead_at_p.
  9918.  
  9919.    If DEST is within [reg_dead_rengno, reg_dead_endregno), set 
  9920.    reg_dead_flag to 1 if X is a CLOBBER and to -1 it is a SET.  */
  9921.  
  9922. static void
  9923. reg_dead_at_p_1 (dest, x)
  9924.      rtx dest;
  9925.      rtx x;
  9926. {
  9927.   int regno, endregno;
  9928.  
  9929.   if (GET_CODE (dest) != REG)
  9930.     return;
  9931.  
  9932.   regno = REGNO (dest);
  9933.   endregno = regno + (regno < FIRST_PSEUDO_REGISTER 
  9934.               ? HARD_REGNO_NREGS (regno, GET_MODE (dest)) : 1);
  9935.  
  9936.   if (reg_dead_endregno > regno && reg_dead_regno < endregno)
  9937.     reg_dead_flag = (GET_CODE (x) == CLOBBER) ? 1 : -1;
  9938. }
  9939.  
  9940. /* Return non-zero if REG is known to be dead at INSN.
  9941.  
  9942.    We scan backwards from INSN.  If we hit a REG_DEAD note or a CLOBBER
  9943.    referencing REG, it is dead.  If we hit a SET referencing REG, it is
  9944.    live.  Otherwise, see if it is live or dead at the start of the basic
  9945.    block we are in.  Hard regs marked as being live in NEWPAT_USED_REGS
  9946.    must be assumed to be always live.  */
  9947.  
  9948. static int
  9949. reg_dead_at_p (reg, insn)
  9950.      rtx reg;
  9951.      rtx insn;
  9952. {
  9953.   int block, i;
  9954.  
  9955.   /* Set variables for reg_dead_at_p_1.  */
  9956.   reg_dead_regno = REGNO (reg);
  9957.   reg_dead_endregno = reg_dead_regno + (reg_dead_regno < FIRST_PSEUDO_REGISTER
  9958.                     ? HARD_REGNO_NREGS (reg_dead_regno,
  9959.                                 GET_MODE (reg))
  9960.                     : 1);
  9961.  
  9962.   reg_dead_flag = 0;
  9963.  
  9964.   /* Check that reg isn't mentioned in NEWPAT_USED_REGS.  */
  9965.   if (reg_dead_regno < FIRST_PSEUDO_REGISTER)
  9966.     {
  9967.       for (i = reg_dead_regno; i < reg_dead_endregno; i++)
  9968.     if (TEST_HARD_REG_BIT (newpat_used_regs, i))
  9969.       return 0;
  9970.     }
  9971.  
  9972.   /* Scan backwards until we find a REG_DEAD note, SET, CLOBBER, label, or
  9973.      beginning of function.  */
  9974.   for (; insn && GET_CODE (insn) != CODE_LABEL;
  9975.        insn = prev_nonnote_insn (insn))
  9976.     {
  9977.       note_stores (PATTERN (insn), reg_dead_at_p_1);
  9978.       if (reg_dead_flag)
  9979.     return reg_dead_flag == 1 ? 1 : 0;
  9980.  
  9981.       if (find_regno_note (insn, REG_DEAD, reg_dead_regno))
  9982.     return 1;
  9983.     }
  9984.  
  9985.   /* Get the basic block number that we were in.  */
  9986.   if (insn == 0)
  9987.     block = 0;
  9988.   else
  9989.     {
  9990.       for (block = 0; block < n_basic_blocks; block++)
  9991.     if (insn == basic_block_head[block])
  9992.       break;
  9993.  
  9994.       if (block == n_basic_blocks)
  9995.     return 0;
  9996.     }
  9997.  
  9998.   for (i = reg_dead_regno; i < reg_dead_endregno; i++)
  9999.     if (basic_block_live_at_start[block][i / REGSET_ELT_BITS]
  10000.     & ((REGSET_ELT_TYPE) 1 << (i % REGSET_ELT_BITS)))
  10001.       return 0;
  10002.  
  10003.   return 1;
  10004. }
  10005.  
  10006. /* Note hard registers in X that are used.  This code is similar to
  10007.    that in flow.c, but much simpler since we don't care about pseudos.  */
  10008.  
  10009. static void
  10010. mark_used_regs_combine (x)
  10011.      rtx x;
  10012. {
  10013.   register RTX_CODE code = GET_CODE (x);
  10014.   register int regno;
  10015.   int i;
  10016.  
  10017.   switch (code)
  10018.     {
  10019.     case LABEL_REF:
  10020.     case SYMBOL_REF:
  10021.     case CONST_INT:
  10022.     case CONST:
  10023.     case CONST_DOUBLE:
  10024.     case PC:
  10025.     case ADDR_VEC:
  10026.     case ADDR_DIFF_VEC:
  10027.     case ASM_INPUT:
  10028. #ifdef HAVE_cc0
  10029.     /* CC0 must die in the insn after it is set, so we don't need to take
  10030.        special note of it here.  */
  10031.     case CC0:
  10032. #endif
  10033.       return;
  10034.  
  10035.     case CLOBBER:
  10036.       /* If we are clobbering a MEM, mark any hard registers inside the
  10037.      address as used.  */
  10038.       if (GET_CODE (XEXP (x, 0)) == MEM)
  10039.     mark_used_regs_combine (XEXP (XEXP (x, 0), 0));
  10040.       return;
  10041.  
  10042.     case REG:
  10043.       regno = REGNO (x);
  10044.       /* A hard reg in a wide mode may really be multiple registers.
  10045.      If so, mark all of them just like the first.  */
  10046.       if (regno < FIRST_PSEUDO_REGISTER)
  10047.     {
  10048.       /* None of this applies to the stack, frame or arg pointers */
  10049.       if (regno == STACK_POINTER_REGNUM
  10050. #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
  10051.           || regno == HARD_FRAME_POINTER_REGNUM
  10052. #endif
  10053. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  10054.           || (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
  10055. #endif
  10056.           || regno == FRAME_POINTER_REGNUM)
  10057.         return;
  10058.  
  10059.       i = HARD_REGNO_NREGS (regno, GET_MODE (x));
  10060.       while (i-- > 0)
  10061.         SET_HARD_REG_BIT (newpat_used_regs, regno + i);
  10062.     }
  10063.       return;
  10064.  
  10065.     case SET:
  10066.       {
  10067.     /* If setting a MEM, or a SUBREG of a MEM, then note any hard regs in
  10068.        the address.  */
  10069.     register rtx testreg = SET_DEST (x);
  10070.  
  10071.     while (GET_CODE (testreg) == SUBREG
  10072.            || GET_CODE (testreg) == ZERO_EXTRACT
  10073.            || GET_CODE (testreg) == SIGN_EXTRACT
  10074.            || GET_CODE (testreg) == STRICT_LOW_PART)
  10075.       testreg = XEXP (testreg, 0);
  10076.  
  10077.     if (GET_CODE (testreg) == MEM)
  10078.       mark_used_regs_combine (XEXP (testreg, 0));
  10079.  
  10080.     mark_used_regs_combine (SET_SRC (x));
  10081.     return;
  10082.       }
  10083.     }
  10084.  
  10085.   /* Recursively scan the operands of this expression.  */
  10086.  
  10087.   {
  10088.     register char *fmt = GET_RTX_FORMAT (code);
  10089.  
  10090.     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  10091.       {
  10092.         if (fmt[i] == 'e')
  10093.       mark_used_regs_combine (XEXP (x, i));
  10094.         else if (fmt[i] == 'E')
  10095.           {
  10096.             register int j;
  10097.  
  10098.             for (j = 0; j < XVECLEN (x, i); j++)
  10099.               mark_used_regs_combine (XVECEXP (x, i, j));
  10100.           }
  10101.       }
  10102.   }
  10103. }
  10104.  
  10105.  
  10106. /* Remove register number REGNO from the dead registers list of INSN.
  10107.  
  10108.    Return the note used to record the death, if there was one.  */
  10109.  
  10110. rtx
  10111. remove_death (regno, insn)
  10112.      int regno;
  10113.      rtx insn;
  10114. {
  10115.   register rtx note = find_regno_note (insn, REG_DEAD, regno);
  10116.  
  10117.   if (note)
  10118.     {
  10119.       reg_n_deaths[regno]--;
  10120.       remove_note (insn, note);
  10121.     }
  10122.  
  10123.   return note;
  10124. }
  10125.  
  10126. /* For each register (hardware or pseudo) used within expression X, if its
  10127.    death is in an instruction with cuid between FROM_CUID (inclusive) and
  10128.    TO_INSN (exclusive), put a REG_DEAD note for that register in the
  10129.    list headed by PNOTES. 
  10130.  
  10131.    This is done when X is being merged by combination into TO_INSN.  These
  10132.    notes will then be distributed as needed.  */
  10133.  
  10134. static void
  10135. move_deaths (x, from_cuid, to_insn, pnotes)
  10136.      rtx x;
  10137.      int from_cuid;
  10138.      rtx to_insn;
  10139.      rtx *pnotes;
  10140. {
  10141.   register char *fmt;
  10142.   register int len, i;
  10143.   register enum rtx_code code = GET_CODE (x);
  10144.  
  10145.   if (code == REG)
  10146.     {
  10147.       register int regno = REGNO (x);
  10148.       register rtx where_dead = reg_last_death[regno];
  10149.  
  10150.       if (where_dead && INSN_CUID (where_dead) >= from_cuid
  10151.       && INSN_CUID (where_dead) < INSN_CUID (to_insn))
  10152.     {
  10153.       rtx note = remove_death (regno, where_dead);
  10154.  
  10155.       /* It is possible for the call above to return 0.  This can occur
  10156.          when reg_last_death points to I2 or I1 that we combined with.
  10157.          In that case make a new note.
  10158.  
  10159.          We must also check for the case where X is a hard register
  10160.          and NOTE is a death note for a range of hard registers
  10161.          including X.  In that case, we must put REG_DEAD notes for
  10162.          the remaining registers in place of NOTE.  */
  10163.  
  10164.       if (note != 0 && regno < FIRST_PSEUDO_REGISTER
  10165.           && (GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))
  10166.           != GET_MODE_SIZE (GET_MODE (x))))
  10167.         {
  10168.           int deadregno = REGNO (XEXP (note, 0));
  10169.           int deadend
  10170.         = (deadregno + HARD_REGNO_NREGS (deadregno,
  10171.                          GET_MODE (XEXP (note, 0))));
  10172.           int ourend = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
  10173.           int i;
  10174.  
  10175.           for (i = deadregno; i < deadend; i++)
  10176.         if (i < regno || i >= ourend)
  10177.           REG_NOTES (where_dead)
  10178.             = gen_rtx (EXPR_LIST, REG_DEAD,
  10179.                    gen_rtx (REG, reg_raw_mode[i], i),
  10180.                    REG_NOTES (where_dead));
  10181.         }
  10182.  
  10183.       if (note != 0 && GET_MODE (XEXP (note, 0)) == GET_MODE (x))
  10184.         {
  10185.           XEXP (note, 1) = *pnotes;
  10186.           *pnotes = note;
  10187.         }
  10188.       else
  10189.         *pnotes = gen_rtx (EXPR_LIST, REG_DEAD, x, *pnotes);
  10190.  
  10191.       reg_n_deaths[regno]++;
  10192.     }
  10193.  
  10194.       return;
  10195.     }
  10196.  
  10197.   else if (GET_CODE (x) == SET)
  10198.     {
  10199.       rtx dest = SET_DEST (x);
  10200.  
  10201.       move_deaths (SET_SRC (x), from_cuid, to_insn, pnotes);
  10202.  
  10203.       /* In the case of a ZERO_EXTRACT, a STRICT_LOW_PART, or a SUBREG
  10204.      that accesses one word of a multi-word item, some
  10205.      piece of everything register in the expression is used by
  10206.      this insn, so remove any old death.  */
  10207.  
  10208.       if (GET_CODE (dest) == ZERO_EXTRACT
  10209.       || GET_CODE (dest) == STRICT_LOW_PART
  10210.       || (GET_CODE (dest) == SUBREG
  10211.           && (((GET_MODE_SIZE (GET_MODE (dest))
  10212.             + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
  10213.           == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
  10214.                + UNITS_PER_WORD - 1) / UNITS_PER_WORD))))
  10215.     {
  10216.       move_deaths (dest, from_cuid, to_insn, pnotes);
  10217.       return;
  10218.     }
  10219.  
  10220.       /* If this is some other SUBREG, we know it replaces the entire
  10221.      value, so use that as the destination.  */
  10222.       if (GET_CODE (dest) == SUBREG)
  10223.     dest = SUBREG_REG (dest);
  10224.  
  10225.       /* If this is a MEM, adjust deaths of anything used in the address.
  10226.      For a REG (the only other possibility), the entire value is
  10227.      being replaced so the old value is not used in this insn.  */
  10228.  
  10229.       if (GET_CODE (dest) == MEM)
  10230.     move_deaths (XEXP (dest, 0), from_cuid, to_insn, pnotes);
  10231.       return;
  10232.     }
  10233.  
  10234.   else if (GET_CODE (x) == CLOBBER)
  10235.     return;
  10236.  
  10237.   len = GET_RTX_LENGTH (code);
  10238.   fmt = GET_RTX_FORMAT (code);
  10239.  
  10240.   for (i = 0; i < len; i++)
  10241.     {
  10242.       if (fmt[i] == 'E')
  10243.     {
  10244.       register int j;
  10245.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  10246.         move_deaths (XVECEXP (x, i, j), from_cuid, to_insn, pnotes);
  10247.     }
  10248.       else if (fmt[i] == 'e')
  10249.     move_deaths (XEXP (x, i), from_cuid, to_insn, pnotes);
  10250.     }
  10251. }
  10252.  
  10253. /* Return 1 if X is the target of a bit-field assignment in BODY, the
  10254.    pattern of an insn.  X must be a REG.  */
  10255.  
  10256. static int
  10257. reg_bitfield_target_p (x, body)
  10258.      rtx x;
  10259.      rtx body;
  10260. {
  10261.   int i;
  10262.  
  10263.   if (GET_CODE (body) == SET)
  10264.     {
  10265.       rtx dest = SET_DEST (body);
  10266.       rtx target;
  10267.       int regno, tregno, endregno, endtregno;
  10268.  
  10269.       if (GET_CODE (dest) == ZERO_EXTRACT)
  10270.     target = XEXP (dest, 0);
  10271.       else if (GET_CODE (dest) == STRICT_LOW_PART)
  10272.     target = SUBREG_REG (XEXP (dest, 0));
  10273.       else
  10274.     return 0;
  10275.  
  10276.       if (GET_CODE (target) == SUBREG)
  10277.     target = SUBREG_REG (target);
  10278.  
  10279.       if (GET_CODE (target) != REG)
  10280.     return 0;
  10281.  
  10282.       tregno = REGNO (target), regno = REGNO (x);
  10283.       if (tregno >= FIRST_PSEUDO_REGISTER || regno >= FIRST_PSEUDO_REGISTER)
  10284.     return target == x;
  10285.  
  10286.       endtregno = tregno + HARD_REGNO_NREGS (tregno, GET_MODE (target));
  10287.       endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
  10288.  
  10289.       return endregno > tregno && regno < endtregno;
  10290.     }
  10291.  
  10292.   else if (GET_CODE (body) == PARALLEL)
  10293.     for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
  10294.       if (reg_bitfield_target_p (x, XVECEXP (body, 0, i)))
  10295.     return 1;
  10296.  
  10297.   return 0;
  10298. }      
  10299.  
  10300. /* Given a chain of REG_NOTES originally from FROM_INSN, try to place them
  10301.    as appropriate.  I3 and I2 are the insns resulting from the combination
  10302.    insns including FROM (I2 may be zero).
  10303.  
  10304.    ELIM_I2 and ELIM_I1 are either zero or registers that we know will
  10305.    not need REG_DEAD notes because they are being substituted for.  This
  10306.    saves searching in the most common cases.
  10307.  
  10308.    Each note in the list is either ignored or placed on some insns, depending
  10309.    on the type of note.  */
  10310.  
  10311. static void
  10312. distribute_notes (notes, from_insn, i3, i2, elim_i2, elim_i1)
  10313.      rtx notes;
  10314.      rtx from_insn;
  10315.      rtx i3, i2;
  10316.      rtx elim_i2, elim_i1;
  10317. {
  10318.   rtx note, next_note;
  10319.   rtx tem;
  10320.  
  10321.   for (note = notes; note; note = next_note)
  10322.     {
  10323.       rtx place = 0, place2 = 0;
  10324.  
  10325.       /* If this NOTE references a pseudo register, ensure it references
  10326.      the latest copy of that register.  */
  10327.       if (XEXP (note, 0) && GET_CODE (XEXP (note, 0)) == REG
  10328.       && REGNO (XEXP (note, 0)) >= FIRST_PSEUDO_REGISTER)
  10329.     XEXP (note, 0) = regno_reg_rtx[REGNO (XEXP (note, 0))];
  10330.  
  10331.       next_note = XEXP (note, 1);
  10332.       switch (REG_NOTE_KIND (note))
  10333.     {
  10334.     case REG_UNUSED:
  10335.       /* If this note is from any insn other than i3, then we have no
  10336.          use for it, and must ignore it.
  10337.  
  10338.          Any clobbers for i3 may still exist, and so we must process
  10339.          REG_UNUSED notes from that insn.
  10340.  
  10341.          Any clobbers from i2 or i1 can only exist if they were added by
  10342.          recog_for_combine.  In that case, recog_for_combine created the
  10343.          necessary REG_UNUSED notes.  Trying to keep any original
  10344.          REG_UNUSED notes from these insns can cause incorrect output
  10345.          if it is for the same register as the original i3 dest.
  10346.          In that case, we will notice that the register is set in i3,
  10347.          and then add a REG_UNUSED note for the destination of i3, which
  10348.          is wrong.  */
  10349.       if (from_insn != i3)
  10350.         break;
  10351.  
  10352.       /* If this register is set or clobbered in I3, put the note there
  10353.          unless there is one already.  */
  10354.       else if (reg_set_p (XEXP (note, 0), PATTERN (i3)))
  10355.         {
  10356.           if (! (GET_CODE (XEXP (note, 0)) == REG
  10357.              ? find_regno_note (i3, REG_UNUSED, REGNO (XEXP (note, 0)))
  10358.              : find_reg_note (i3, REG_UNUSED, XEXP (note, 0))))
  10359.         place = i3;
  10360.         }
  10361.       /* Otherwise, if this register is used by I3, then this register
  10362.          now dies here, so we must put a REG_DEAD note here unless there
  10363.          is one already.  */
  10364.       else if (reg_referenced_p (XEXP (note, 0), PATTERN (i3))
  10365.            && ! (GET_CODE (XEXP (note, 0)) == REG
  10366.              ? find_regno_note (i3, REG_DEAD, REGNO (XEXP (note, 0)))
  10367.              : find_reg_note (i3, REG_DEAD, XEXP (note, 0))))
  10368.         {
  10369.           PUT_REG_NOTE_KIND (note, REG_DEAD);
  10370.           place = i3;
  10371.         }
  10372.       break;
  10373.  
  10374.     case REG_EQUAL:
  10375.     case REG_EQUIV:
  10376.     case REG_NONNEG:
  10377.       /* These notes say something about results of an insn.  We can
  10378.          only support them if they used to be on I3 in which case they
  10379.          remain on I3.  Otherwise they are ignored.
  10380.  
  10381.          If the note refers to an expression that is not a constant, we
  10382.          must also ignore the note since we cannot tell whether the
  10383.          equivalence is still true.  It might be possible to do
  10384.          slightly better than this (we only have a problem if I2DEST
  10385.          or I1DEST is present in the expression), but it doesn't
  10386.          seem worth the trouble.  */
  10387.  
  10388.       if (from_insn == i3
  10389.           && (XEXP (note, 0) == 0 || CONSTANT_P (XEXP (note, 0))))
  10390.         place = i3;
  10391.       break;
  10392.  
  10393.     case REG_INC:
  10394.     case REG_NO_CONFLICT:
  10395.     case REG_LABEL:
  10396.       /* These notes say something about how a register is used.  They must
  10397.          be present on any use of the register in I2 or I3.  */
  10398.       if (reg_mentioned_p (XEXP (note, 0), PATTERN (i3)))
  10399.         place = i3;
  10400.  
  10401.       if (i2 && reg_mentioned_p (XEXP (note, 0), PATTERN (i2)))
  10402.         {
  10403.           if (place)
  10404.         place2 = i2;
  10405.           else
  10406.         place = i2;
  10407.         }
  10408.       break;
  10409.  
  10410.     case REG_WAS_0:
  10411.       /* It is too much trouble to try to see if this note is still
  10412.          correct in all situations.  It is better to simply delete it.  */
  10413.       break;
  10414.  
  10415.     case REG_RETVAL:
  10416.       /* If the insn previously containing this note still exists,
  10417.          put it back where it was.  Otherwise move it to the previous
  10418.          insn.  Adjust the corresponding REG_LIBCALL note.  */
  10419.       if (GET_CODE (from_insn) != NOTE)
  10420.         place = from_insn;
  10421.       else
  10422.         {
  10423.           tem = find_reg_note (XEXP (note, 0), REG_LIBCALL, NULL_RTX);
  10424.           place = prev_real_insn (from_insn);
  10425.           if (tem && place)
  10426.         XEXP (tem, 0) = place;
  10427.         }
  10428.       break;
  10429.  
  10430.     case REG_LIBCALL:
  10431.       /* This is handled similarly to REG_RETVAL.  */
  10432.       if (GET_CODE (from_insn) != NOTE)
  10433.         place = from_insn;
  10434.       else
  10435.         {
  10436.           tem = find_reg_note (XEXP (note, 0), REG_RETVAL, NULL_RTX);
  10437.           place = next_real_insn (from_insn);
  10438.           if (tem && place)
  10439.         XEXP (tem, 0) = place;
  10440.         }
  10441.       break;
  10442.  
  10443.     case REG_DEAD:
  10444.       /* If the register is used as an input in I3, it dies there.
  10445.          Similarly for I2, if it is non-zero and adjacent to I3.
  10446.  
  10447.          If the register is not used as an input in either I3 or I2
  10448.          and it is not one of the registers we were supposed to eliminate,
  10449.          there are two possibilities.  We might have a non-adjacent I2
  10450.          or we might have somehow eliminated an additional register
  10451.          from a computation.  For example, we might have had A & B where
  10452.          we discover that B will always be zero.  In this case we will
  10453.          eliminate the reference to A.
  10454.  
  10455.          In both cases, we must search to see if we can find a previous
  10456.          use of A and put the death note there.  */
  10457.  
  10458.       if (from_insn
  10459.           && GET_CODE (from_insn) == CALL_INSN
  10460.               && find_reg_fusage (from_insn, USE, XEXP (note, 0)))
  10461.         place = from_insn;
  10462.       else if (reg_referenced_p (XEXP (note, 0), PATTERN (i3)))
  10463.         place = i3;
  10464.       else if (i2 != 0 && next_nonnote_insn (i2) == i3
  10465.            && reg_referenced_p (XEXP (note, 0), PATTERN (i2)))
  10466.         place = i2;
  10467.  
  10468.       if (XEXP (note, 0) == elim_i2 || XEXP (note, 0) == elim_i1)
  10469.         break;
  10470.  
  10471.       /* If the register is used in both I2 and I3 and it dies in I3, 
  10472.          we might have added another reference to it.  If reg_n_refs
  10473.          was 2, bump it to 3.  This has to be correct since the 
  10474.          register must have been set somewhere.  The reason this is
  10475.          done is because local-alloc.c treats 2 references as a 
  10476.          special case.  */
  10477.  
  10478.       if (place == i3 && i2 != 0 && GET_CODE (XEXP (note, 0)) == REG
  10479.           && reg_n_refs[REGNO (XEXP (note, 0))]== 2
  10480.           && reg_referenced_p (XEXP (note, 0), PATTERN (i2)))
  10481.         reg_n_refs[REGNO (XEXP (note, 0))] = 3;
  10482.  
  10483.       if (place == 0)
  10484.         for (tem = prev_nonnote_insn (i3);
  10485.          tem && (GET_CODE (tem) == INSN
  10486.              || GET_CODE (tem) == CALL_INSN);
  10487.          tem = prev_nonnote_insn (tem))
  10488.           {
  10489.         /* If the register is being set at TEM, see if that is all
  10490.            TEM is doing.  If so, delete TEM.  Otherwise, make this
  10491.            into a REG_UNUSED note instead.  */
  10492.         if (reg_set_p (XEXP (note, 0), PATTERN (tem)))
  10493.           {
  10494.             rtx set = single_set (tem);
  10495.  
  10496.             /* Verify that it was the set, and not a clobber that
  10497.                modified the register.  */
  10498.  
  10499.             if (set != 0 && ! side_effects_p (SET_SRC (set))
  10500.             && rtx_equal_p (XEXP (note, 0), SET_DEST (set)))
  10501.               {
  10502.             /* Move the notes and links of TEM elsewhere.
  10503.                This might delete other dead insns recursively. 
  10504.                First set the pattern to something that won't use
  10505.                any register.  */
  10506.  
  10507.             PATTERN (tem) = pc_rtx;
  10508.  
  10509.             distribute_notes (REG_NOTES (tem), tem, tem,
  10510.                       NULL_RTX, NULL_RTX, NULL_RTX);
  10511.             distribute_links (LOG_LINKS (tem));
  10512.  
  10513.             PUT_CODE (tem, NOTE);
  10514.             NOTE_LINE_NUMBER (tem) = NOTE_INSN_DELETED;
  10515.             NOTE_SOURCE_FILE (tem) = 0;
  10516.               }
  10517.             else
  10518.               {
  10519.             PUT_REG_NOTE_KIND (note, REG_UNUSED);
  10520.  
  10521.             /*  If there isn't already a REG_UNUSED note, put one
  10522.                 here.  */
  10523.             if (! find_regno_note (tem, REG_UNUSED,
  10524.                            REGNO (XEXP (note, 0))))
  10525.               place = tem;
  10526.             break;
  10527.               }
  10528.           }
  10529.         else if (reg_referenced_p (XEXP (note, 0), PATTERN (tem))
  10530.              || (GET_CODE (tem) == CALL_INSN
  10531.                  && find_reg_fusage (tem, USE, XEXP (note, 0))))
  10532.           {
  10533.             place = tem;
  10534.             break;
  10535.           }
  10536.           }
  10537.  
  10538.       /* If the register is set or already dead at PLACE, we needn't do
  10539.          anything with this note if it is still a REG_DEAD note.  
  10540.  
  10541.          Note that we cannot use just `dead_or_set_p' here since we can
  10542.          convert an assignment to a register into a bit-field assignment.
  10543.          Therefore, we must also omit the note if the register is the 
  10544.          target of a bitfield assignment.  */
  10545.          
  10546.       if (place && REG_NOTE_KIND (note) == REG_DEAD)
  10547.         {
  10548.           int regno = REGNO (XEXP (note, 0));
  10549.  
  10550.           if (dead_or_set_p (place, XEXP (note, 0))
  10551.           || reg_bitfield_target_p (XEXP (note, 0), PATTERN (place)))
  10552.         {
  10553.           /* Unless the register previously died in PLACE, clear
  10554.              reg_last_death.  [I no longer understand why this is
  10555.              being done.] */
  10556.           if (reg_last_death[regno] != place)
  10557.             reg_last_death[regno] = 0;
  10558.           place = 0;
  10559.         }
  10560.           else
  10561.         reg_last_death[regno] = place;
  10562.  
  10563.           /* If this is a death note for a hard reg that is occupying
  10564.          multiple registers, ensure that we are still using all
  10565.          parts of the object.  If we find a piece of the object
  10566.          that is unused, we must add a USE for that piece before
  10567.          PLACE and put the appropriate REG_DEAD note on it.
  10568.  
  10569.          An alternative would be to put a REG_UNUSED for the pieces
  10570.          on the insn that set the register, but that can't be done if
  10571.          it is not in the same block.  It is simpler, though less
  10572.          efficient, to add the USE insns.  */
  10573.  
  10574.           if (place && regno < FIRST_PSEUDO_REGISTER
  10575.           && HARD_REGNO_NREGS (regno, GET_MODE (XEXP (note, 0))) > 1)
  10576.         {
  10577.           int endregno
  10578.             = regno + HARD_REGNO_NREGS (regno,
  10579.                         GET_MODE (XEXP (note, 0)));
  10580.           int all_used = 1;
  10581.           int i;
  10582.  
  10583.           for (i = regno; i < endregno; i++)
  10584.             if (! refers_to_regno_p (i, i + 1, PATTERN (place), 0)
  10585.             && ! find_regno_fusage (place, USE, i))
  10586.               {
  10587.             rtx piece = gen_rtx (REG, reg_raw_mode[i], i);
  10588.             rtx p;
  10589.  
  10590.             /* See if we already placed a USE note for this
  10591.                register in front of PLACE.  */
  10592.             for (p = place;
  10593.                  GET_CODE (PREV_INSN (p)) == INSN
  10594.                  && GET_CODE (PATTERN (PREV_INSN (p))) == USE;
  10595.                  p = PREV_INSN (p))
  10596.               if (rtx_equal_p (piece,
  10597.                        XEXP (PATTERN (PREV_INSN (p)), 0)))
  10598.                 {
  10599.                   p = 0;
  10600.                   break;
  10601.                 }
  10602.  
  10603.             if (p)
  10604.               {
  10605.                 rtx use_insn
  10606.                   = emit_insn_before (gen_rtx (USE, VOIDmode,
  10607.                                piece),
  10608.                           p);
  10609.                 REG_NOTES (use_insn)
  10610.                   = gen_rtx (EXPR_LIST, REG_DEAD, piece,
  10611.                      REG_NOTES (use_insn));
  10612.               }
  10613.  
  10614.             all_used = 0;
  10615.               }
  10616.  
  10617.           /* Check for the case where the register dying partially
  10618.              overlaps the register set by this insn.  */
  10619.           if (all_used)
  10620.             for (i = regno; i < endregno; i++)
  10621.               if (dead_or_set_regno_p (place, i))
  10622.               {
  10623.                 all_used = 0;
  10624.                 break;
  10625.               }
  10626.  
  10627.           if (! all_used)
  10628.             {
  10629.               /* Put only REG_DEAD notes for pieces that are
  10630.              still used and that are not already dead or set.  */
  10631.  
  10632.               for (i = regno; i < endregno; i++)
  10633.             {
  10634.               rtx piece = gen_rtx (REG, reg_raw_mode[i], i);
  10635.  
  10636.               if (reg_referenced_p (piece, PATTERN (place))
  10637.                   && ! dead_or_set_p (place, piece)
  10638.                   && ! reg_bitfield_target_p (piece,
  10639.                               PATTERN (place)))
  10640.                 REG_NOTES (place) = gen_rtx (EXPR_LIST, REG_DEAD,
  10641.                              piece,
  10642.                              REG_NOTES (place));
  10643.             }
  10644.  
  10645.               place = 0;
  10646.             }
  10647.         }
  10648.         }
  10649.       break;
  10650.  
  10651.     default:
  10652.       /* Any other notes should not be present at this point in the
  10653.          compilation.  */
  10654.       abort ();
  10655.     }
  10656.  
  10657.       if (place)
  10658.     {
  10659.       XEXP (note, 1) = REG_NOTES (place);
  10660.       REG_NOTES (place) = note;
  10661.     }
  10662.       else if ((REG_NOTE_KIND (note) == REG_DEAD
  10663.         || REG_NOTE_KIND (note) == REG_UNUSED)
  10664.            && GET_CODE (XEXP (note, 0)) == REG)
  10665.     reg_n_deaths[REGNO (XEXP (note, 0))]--;
  10666.  
  10667.       if (place2)
  10668.     {
  10669.       if ((REG_NOTE_KIND (note) == REG_DEAD
  10670.            || REG_NOTE_KIND (note) == REG_UNUSED)
  10671.           && GET_CODE (XEXP (note, 0)) == REG)
  10672.         reg_n_deaths[REGNO (XEXP (note, 0))]++;
  10673.  
  10674.       REG_NOTES (place2) = gen_rtx (GET_CODE (note), REG_NOTE_KIND (note),
  10675.                     XEXP (note, 0), REG_NOTES (place2));
  10676.     }
  10677.     }
  10678. }
  10679.  
  10680. /* Similarly to above, distribute the LOG_LINKS that used to be present on
  10681.    I3, I2, and I1 to new locations.  This is also called in one case to
  10682.    add a link pointing at I3 when I3's destination is changed.  */
  10683.  
  10684. static void
  10685. distribute_links (links)
  10686.      rtx links;
  10687. {
  10688.   rtx link, next_link;
  10689.  
  10690.   for (link = links; link; link = next_link)
  10691.     {
  10692.       rtx place = 0;
  10693.       rtx insn;
  10694.       rtx set, reg;
  10695.  
  10696.       next_link = XEXP (link, 1);
  10697.  
  10698.       /* If the insn that this link points to is a NOTE or isn't a single
  10699.      set, ignore it.  In the latter case, it isn't clear what we
  10700.      can do other than ignore the link, since we can't tell which 
  10701.      register it was for.  Such links wouldn't be used by combine
  10702.      anyway.
  10703.  
  10704.      It is not possible for the destination of the target of the link to
  10705.      have been changed by combine.  The only potential of this is if we
  10706.      replace I3, I2, and I1 by I3 and I2.  But in that case the
  10707.      destination of I2 also remains unchanged.  */
  10708.  
  10709.       if (GET_CODE (XEXP (link, 0)) == NOTE
  10710.       || (set = single_set (XEXP (link, 0))) == 0)
  10711.     continue;
  10712.  
  10713.       reg = SET_DEST (set);
  10714.       while (GET_CODE (reg) == SUBREG || GET_CODE (reg) == ZERO_EXTRACT
  10715.          || GET_CODE (reg) == SIGN_EXTRACT
  10716.          || GET_CODE (reg) == STRICT_LOW_PART)
  10717.     reg = XEXP (reg, 0);
  10718.  
  10719.       /* A LOG_LINK is defined as being placed on the first insn that uses
  10720.      a register and points to the insn that sets the register.  Start
  10721.      searching at the next insn after the target of the link and stop
  10722.      when we reach a set of the register or the end of the basic block.
  10723.  
  10724.      Note that this correctly handles the link that used to point from
  10725.      I3 to I2.  Also note that not much searching is typically done here
  10726.      since most links don't point very far away.  */
  10727.  
  10728.       for (insn = NEXT_INSN (XEXP (link, 0));
  10729.        (insn && (this_basic_block == n_basic_blocks - 1
  10730.              || basic_block_head[this_basic_block + 1] != insn));
  10731.        insn = NEXT_INSN (insn))
  10732.     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  10733.         && reg_overlap_mentioned_p (reg, PATTERN (insn)))
  10734.       {
  10735.         if (reg_referenced_p (reg, PATTERN (insn)))
  10736.           place = insn;
  10737.         break;
  10738.       }
  10739.     else if (GET_CODE (insn) == CALL_INSN
  10740.           && find_reg_fusage (insn, USE, reg))
  10741.       {
  10742.         place = insn;
  10743.         break;
  10744.       }
  10745.  
  10746.       /* If we found a place to put the link, place it there unless there
  10747.      is already a link to the same insn as LINK at that point.  */
  10748.  
  10749.       if (place)
  10750.     {
  10751.       rtx link2;
  10752.  
  10753.       for (link2 = LOG_LINKS (place); link2; link2 = XEXP (link2, 1))
  10754.         if (XEXP (link2, 0) == XEXP (link, 0))
  10755.           break;
  10756.  
  10757.       if (link2 == 0)
  10758.         {
  10759.           XEXP (link, 1) = LOG_LINKS (place);
  10760.           LOG_LINKS (place) = link;
  10761.  
  10762.           /* Set added_links_insn to the earliest insn we added a
  10763.          link to.  */
  10764.           if (added_links_insn == 0 
  10765.           || INSN_CUID (added_links_insn) > INSN_CUID (place))
  10766.         added_links_insn = place;
  10767.         }
  10768.     }
  10769.     }
  10770. }
  10771.  
  10772. void
  10773. dump_combine_stats (file)
  10774.      FILE *file;
  10775. {
  10776.   fprintf
  10777.     (file,
  10778.      ";; Combiner statistics: %d attempts, %d substitutions (%d requiring new space),\n;; %d successes.\n\n",
  10779.      combine_attempts, combine_merges, combine_extras, combine_successes);
  10780. }
  10781.  
  10782. void
  10783. dump_combine_total_stats (file)
  10784.      FILE *file;
  10785. {
  10786.   fprintf
  10787.     (file,
  10788.      "\n;; Combiner totals: %d attempts, %d substitutions (%d requiring new space),\n;; %d successes.\n",
  10789.      total_attempts, total_merges, total_extras, total_successes);
  10790. }
  10791.