home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__src1 / combine.c < prev    next >
C/C++ Source or Header  |  1993-07-23  |  86KB  |  2,637 lines

  1. /* Optimize by combining instructions for GNU compiler.
  2.    Copyright (C) 1987, 1988 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 1, 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.
  39.  
  40.    We check (with use_crosses_set_p) to avoid combining in such a way
  41.    as to move a computation to a place where its value would be different.
  42.  
  43.    Combination is done by mathematically substituting the previous
  44.    insn(s) values for the regs they set into the expressions in
  45.    the later insns that refer to these regs.  If the result is a valid insn
  46.    for our target machine, according to the machine description,
  47.    we install it, delete the earlier insns, and update the data flow
  48.    information (LOG_LINKS and REG_NOTES) for what we did.
  49.  
  50.    To simplify substitution, we combine only when the earlier insn(s)
  51.    consist of only a single assignment.  To simplify updating afterward,
  52.    we never combine when a subroutine call appears in the middle.
  53.  
  54.    Since we do not represent assignments to CC0 explicitly except when that
  55.    is all an insn does, there is no LOG_LINKS entry in an insn that uses
  56.    the condition code for the insn that set the condition code.
  57.    Fortunately, these two insns must be consecutive.
  58.    Therefore, every JUMP_INSN is taken to have an implicit logical link
  59.    to the preceding insn.  This is not quite right, since non-jumps can
  60.    also use the condition code; but in practice such insns would not
  61.    combine anyway.  */
  62.  
  63. #include "config.h"
  64. #include "rtl.h"
  65. #include "flags.h"
  66. #include "regs.h"
  67. #include "basic-block.h"
  68. #include "insn-config.h"
  69. #include "recog.h"
  70.  
  71. #define max(A,B) ((A) > (B) ? (A) : (B))
  72. #define min(A,B) ((A) < (B) ? (A) : (B))
  73.  
  74. /* It is not safe to use ordinary gen_lowpart in combine.
  75.    Use gen_lowpart_for_combine instead.  See comments there.  */
  76. #define gen_lowpart dont_use_gen_lowpart_you_dummy
  77.  
  78. /* Number of attempts to combine instructions in this function.  */
  79.  
  80. static int combine_attempts;
  81. static int distrib_attempts;
  82.  
  83. /* Number of attempts that got as far as substitution in this function.  */
  84.  
  85. static int combine_merges;
  86. static int distrib_merges_1, distrib_merges_2;
  87.  
  88. /* Number of instructions combined with added SETs in this function.  */
  89.  
  90. static int combine_extras;
  91.  
  92. /* Number of instructions combined in this function.  */
  93.  
  94. static int combine_successes;
  95. static int distrib_successes;
  96.  
  97. /* Totals over entire compilation.  */
  98.  
  99. static int total_attempts, total_merges, total_extras, total_successes;
  100. static int total_distrib_attempts, total_distrib_merges_1, total_distrib_merges_2, total_distrib_successes;
  101.  
  102.  
  103. /* Vector mapping INSN_UIDs to cuids.
  104.    The cuids are like uids but increase monononically always.
  105.    Combine always uses cuids so that it can compare them.
  106.    But actually renumbering the uids, which we used to do,
  107.    proves to be a bad idea because it makes it hard to compare
  108.    the dumps produced by earlier passes with those from later passes.  */
  109.  
  110. static short *uid_cuid;
  111.  
  112. /* Get the cuid of an insn.  */
  113.  
  114. #define INSN_CUID(INSN) (uid_cuid[INSN_UID (INSN)])
  115.  
  116.  
  117. /* Record last point of death of (hard or pseudo) register n.  */
  118.  
  119. static rtx *reg_last_death;
  120.  
  121. /* Record last point of modification of (hard or pseudo) register n.  */
  122.  
  123. static rtx *reg_last_set;
  124.  
  125. /* Record the cuid of the last insn that invalidated memory
  126.    (anything that writes memory, and subroutine calls).  */
  127.  
  128. static int mem_last_set;
  129.  
  130. /* Record the cuid of the last CALL_INSN
  131.    so we can tell whether a potential combination crosses any calls.  */
  132.  
  133. static int last_call_cuid;
  134.  
  135. /* When `subst' is called, this is the insn that is being modified
  136.    (by combining in a previous insn).  The PATTERN of this insn
  137.    is still the old pattern partially modified and it should not be
  138.    looked at, but this may be used to examine the successors of the insn
  139.    to judge whether a simplification is valid.  */
  140.  
  141. static rtx subst_insn;
  142.  
  143. /* Record one modification to rtl structure
  144.    to be undone by storing old_contents into *where.
  145.    is_int is 1 if the contents are an int.  */
  146.  
  147. struct undo
  148. {
  149.   rtx *where;
  150.   rtx old_contents;
  151.   int is_int;
  152. };
  153.  
  154. struct undo_int
  155. {
  156.   int *where;
  157.   int old_contents;
  158.   int is_int;
  159. };
  160.  
  161. /* Record a bunch of changes to be undone, up to MAX_UNDO of them.
  162.    num_undo says how many are currently recorded.
  163.    storage is nonzero if we must undo the allocation of new storage.
  164.    The value of storage is what to pass to obfree.  */
  165.  
  166. #define MAX_UNDO 10
  167.  
  168. struct undobuf
  169. {
  170.   int num_undo;
  171.   char *storage;
  172.   struct undo undo[MAX_UNDO];
  173. };
  174.  
  175. static struct undobuf undobuf;
  176.  
  177. /* Number of times the pseudo being substituted for
  178.    was found and replaced.  */
  179.  
  180. static int n_occurrences;
  181.  
  182. static void move_deaths ();
  183. static void move_deaths_2 ();
  184. void remove_death ();
  185. static void record_dead_and_set_regs ();
  186. int regno_dead_p ();
  187. static int use_crosses_set_p ();
  188. static int try_combine ();
  189. static rtx try_distrib ();
  190. static rtx subst ();
  191. static void undo_all ();
  192. static void copy_substitutions ();
  193. static void add_links ();
  194. static void remove_links ();
  195. static void add_incs ();
  196. static int adjacent_insns_p ();
  197. static int check_asm_operands ();
  198. static rtx simplify_and_const_int ();
  199. static rtx gen_lowpart_for_combine ();
  200. static void simplify_set_cc0_and ();
  201.  
  202. /* Main entry point for combiner.  F is the first insn of the function.
  203.    NREGS is the first unused pseudo-reg number.  */
  204.  
  205. void
  206. combine_instructions (f, nregs)
  207.      rtx f;
  208.      int nregs;
  209. {
  210.   register rtx insn;
  211.   register int i;
  212.   register rtx links, nextlinks;
  213.   rtx prev;
  214.  
  215.   combine_attempts = 0;
  216.   combine_merges = 0;
  217.   combine_extras = 0;
  218.   combine_successes = 0;
  219.   distrib_attempts = 0;
  220.   distrib_merges_1 = 0;
  221.   distrib_merges_2 = 0;
  222.   distrib_successes = 0;
  223.  
  224.   reg_last_death = (rtx *) alloca (nregs * sizeof (rtx));
  225.   reg_last_set = (rtx *) alloca (nregs * sizeof (rtx));
  226.   bzero (reg_last_death, nregs * sizeof (rtx));
  227.   bzero (reg_last_set, nregs * sizeof (rtx));
  228.  
  229.   init_recog ();
  230.  
  231.   /* Compute maximum uid value so uid_cuid can be allocated.  */
  232.  
  233.   for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
  234.     if (INSN_UID (insn) > i)
  235.       i = INSN_UID (insn);
  236.  
  237.   uid_cuid = (short *) alloca ((i + 1) * sizeof (short));
  238.  
  239.   /* Compute the mapping from uids to cuids.
  240.      Cuids are numbers assigned to insns, like uids,
  241.      except that cuids increase monotonically through the code.  */
  242.  
  243.   for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
  244.     INSN_CUID (insn) = ++i;
  245.  
  246.   /* Now scan all the insns in forward order.  */
  247.  
  248.   last_call_cuid = 0;
  249.   mem_last_set = 0;
  250.   prev = 0;
  251.  
  252.   for (insn = f; insn; insn = NEXT_INSN (insn))
  253.     {
  254.       if (GET_CODE (insn) == INSN
  255.       || GET_CODE (insn) == CALL_INSN
  256.       || GET_CODE (insn) == JUMP_INSN)
  257.     {
  258.     retry:
  259.       /* Try this insn with each insn it links back to.  */
  260.  
  261.       for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
  262.         if (try_combine (insn, XEXP (links, 0), 0))
  263.           goto retry;
  264.  
  265.       /* Try each sequence of three linked insns ending with this one.  */
  266.  
  267.       for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
  268.         if (GET_CODE (XEXP (links, 0)) != NOTE)
  269.           for (nextlinks = LOG_LINKS (XEXP (links, 0)); nextlinks;
  270.            nextlinks = XEXP (nextlinks, 1))
  271.         if (try_combine (insn, XEXP (links, 0), XEXP (nextlinks, 0)))
  272.           goto retry;
  273.  
  274.       /* Try to combine a jump insn that uses CC0
  275.          with a preceding insn that sets CC0, and maybe with its
  276.          logical predecessor as well.
  277.          This is how we make decrement-and-branch insns.
  278.          We need this special code because data flow connections
  279.          via CC0 do not get entered in LOG_LINKS.  */
  280.  
  281.       if (GET_CODE (insn) == JUMP_INSN
  282.           && prev != 0
  283.           && GET_CODE (prev) == INSN
  284.           && GET_CODE (PATTERN (prev)) == SET
  285.           && GET_CODE (SET_DEST (PATTERN (prev))) == CC0)
  286.         {
  287.           if (try_combine (insn, prev, 0))
  288.         goto retry;
  289.  
  290.           if (GET_CODE (prev) != NOTE)
  291.         for (nextlinks = LOG_LINKS (prev); nextlinks;
  292.              nextlinks = XEXP (nextlinks, 1))
  293.           if (try_combine (insn, prev, XEXP (nextlinks, 0)))
  294.             goto retry;
  295.         }
  296.  
  297.       /* Try to apply the distributive law to this insn
  298.          and two insns that compute the operands of this one.  */
  299.       for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
  300.         if (GET_CODE (XEXP (links, 0)) != NOTE)
  301.           for (nextlinks = XEXP (links, 1); nextlinks; nextlinks = XEXP (nextlinks, 1))
  302.         if (GET_CODE (XEXP (nextlinks, 0)) != NOTE)
  303.           {
  304.             rtx try_from = 0;
  305.  
  306.             if (GET_CODE (PATTERN (XEXP (links, 0))) == SET
  307.             && find_reg_note (insn, REG_DEAD, SET_DEST (PATTERN (XEXP (links, 0))))
  308.             && GET_CODE (PATTERN (XEXP (nextlinks, 0))) == SET
  309.             && find_reg_note (insn, REG_DEAD, SET_DEST (PATTERN (XEXP (nextlinks, 0)))))
  310.               try_from = try_distrib (insn, XEXP (links, 0), XEXP (nextlinks, 0));
  311.             if (try_from != 0)
  312.               {
  313.             insn = try_from;
  314.             goto retry;
  315.               }
  316.           }
  317. #if 0
  318. /* Turned off because on 68020 it takes four insns to make
  319.    something like (a[b / 32] & (1 << (31 - (b % 32)))) != 0
  320.    that could actually be optimized, and that's an unlikely piece of code.  */
  321.       /* If an insn gets or sets a bit field, try combining it
  322.          with two different insns whose results it uses.  */
  323.       if (GET_CODE (insn) == INSN
  324.           && GET_CODE (PATTERN (insn)) == SET
  325.           && (GET_CODE (SET_DEST (PATTERN (insn))) == ZERO_EXTRACT
  326.           || GET_CODE (SET_DEST (PATTERN (insn))) == SIGN_EXTRACT
  327.           || GET_CODE (SET_SRC (PATTERN (insn))) == ZERO_EXTRACT
  328.           || GET_CODE (SET_SRC (PATTERN (insn))) == SIGN_EXTRACT))
  329.         {
  330.           for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
  331.         if (GET_CODE (XEXP (links, 0)) != NOTE)
  332.           for (nextlinks = XEXP (links, 1); nextlinks;
  333.                nextlinks = XEXP (nextlinks, 1))
  334.             if (try_combine (insn, XEXP (links, 0), XEXP (nextlinks, 0)))
  335.               goto retry;
  336.         }
  337. #endif
  338.       record_dead_and_set_regs (insn);
  339.       prev = insn;
  340.     }
  341.       else if (GET_CODE (insn) != NOTE)
  342.     prev = 0;
  343.     }
  344.   total_attempts += combine_attempts;
  345.   total_merges += combine_merges;
  346.   total_extras += combine_extras;
  347.   total_successes += combine_successes;
  348. }
  349.  
  350. /* Try to combine the insns I1 and I2 into I3.
  351.    Here I1 appears earlier than I2, which is earlier than I3.
  352.    I1 can be zero; then we combine just I2 into I3.
  353.  
  354.    Return 1 if successful; if that happens, I1 and I2 are pseudo-deleted
  355.    by turning them into NOTEs, and I3 is modified.
  356.    Return 0 if the combination does not work.  Then nothing is changed.  */
  357.  
  358. static int
  359. try_combine (i3, i2, i1)
  360.      register rtx i3, i2, i1;
  361. {
  362.   register rtx newpat;
  363.   int added_sets_1 = 0;
  364.   int added_sets_2 = 0;
  365.   int total_sets;
  366.   int i2_is_used;
  367.   register rtx link;
  368.   int insn_code_number;
  369.   rtx i2dest, i2src;
  370.   rtx i1dest, i1src;
  371.   int maxreg;
  372.   rtx temp;
  373.  
  374.   combine_attempts++;
  375.  
  376.   /* Don't combine with something already used up by combination.  */
  377.  
  378.   if (GET_CODE (i2) == NOTE
  379.       || (i1 && GET_CODE (i1) == NOTE))
  380.     return 0;
  381.  
  382.   /* Don't combine across a CALL_INSN, because that would possibly
  383.      change whether the life span of some REGs crosses calls or not,
  384.      and it is a pain to update that information.  */
  385.  
  386.   if (INSN_CUID (i2) < last_call_cuid
  387.       || (i1 && INSN_CUID (i1) < last_call_cuid))
  388.     return 0;
  389.  
  390.   /* Can combine only if previous insn is a SET of a REG, a SUBREG or CC0.
  391.      That REG must be either set or dead by the final instruction
  392.      (so that we can safely forget about setting it).
  393.      Also test use_crosses_set_p to make sure that the value
  394.      that is to be substituted for the register
  395.      does not use any registers whose values alter in between.
  396.      Do not try combining with moves from one register to another
  397.      since it is better to let them be tied by register allocation.
  398.      (There is a switch to permit such combination; except the insns
  399.      that copy a function value into another register are never combined
  400.      because moving that too far away from the function call could cause
  401.      something else to be stored in that register in the interim.)
  402.  
  403.      A set of a SUBREG is considered as if it were a set from
  404.      SUBREG.  Thus, (SET (SUBREG:X (REG:Y...)) (something:X...))
  405.      is handled by substituting (SUBREG:Y (something:X...)) for (REG:Y...).  */
  406.  
  407.   if (GET_CODE (PATTERN (i2)) != SET)
  408.     return 0;
  409.   i2dest = SET_DEST (PATTERN (i2));
  410.   i2src = SET_SRC (PATTERN (i2));
  411.   if (GET_CODE (i2dest) == SUBREG)
  412.     {
  413.       i2dest = SUBREG_REG (i2dest);
  414.       i2src = gen_rtx (SUBREG, GET_MODE (i2dest), i2src, 0);
  415.     }
  416.   /* Don't eliminate a store in the stack pointer.  */
  417.   if (i2dest == stack_pointer_rtx)
  418.     return 0;
  419.   if (GET_CODE (i2dest) != CC0
  420.       && (GET_CODE (i2dest) != REG
  421.       || (GET_CODE (i2src) == REG
  422.           && (!flag_combine_regs
  423.           /* Don't substitute a function value reg for any other.  */
  424.           || FUNCTION_VALUE_REGNO_P (REGNO (i2src))))
  425.       || GET_CODE (i2src) == CALL
  426.       /* Don't substitute into an incremented register.  */
  427.       || find_reg_note (i3, REG_INC, i2dest)
  428.       || use_crosses_set_p (i2src, INSN_CUID (i2))))
  429.     return 0;
  430.  
  431.   if (i1 != 0)
  432.     {
  433.       if (GET_CODE (PATTERN (i1)) != SET)
  434.     return 0;
  435.       i1dest = SET_DEST (PATTERN (i1));
  436.       i1src = SET_SRC (PATTERN (i1));
  437.       if (GET_CODE (i1dest) == SUBREG)
  438.     {
  439.       i1dest = SUBREG_REG (i1dest);
  440.       i1src = gen_rtx (SUBREG, GET_MODE (i1dest), i1src, 0);
  441.     }
  442.       if (i1dest == stack_pointer_rtx)
  443.     return 0;
  444.       if (GET_CODE (i1dest) != CC0
  445.       && (GET_CODE (i1dest) != REG
  446.           || (GET_CODE (i1src) == REG
  447.           && (!flag_combine_regs
  448.               || FUNCTION_VALUE_REGNO_P (REGNO (i1src))))
  449.           || GET_CODE (i1src) == CALL
  450.           || find_reg_note (i3, REG_INC, i1dest)
  451.           || find_reg_note (i2, REG_INC, i1dest)
  452.           || use_crosses_set_p (i1src, INSN_CUID (i1))))
  453.     return 0;
  454.     }
  455.  
  456.   /* If I2 contains anything volatile, reject, unless nothing
  457.      volatile comes between it and I3.  */
  458.   if (volatile_refs_p (PATTERN (i2)))
  459.     {
  460.       rtx insn;
  461.       for (insn = NEXT_INSN (i2); insn != i3; insn = NEXT_INSN (insn))
  462.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  463.         || GET_CODE (insn) == JUMP_INSN)
  464.       if (volatile_refs_p (PATTERN (insn)))
  465.         return 0;
  466.     }
  467.   /* Likewise for I1; nothing volatile can come between it and I3,
  468.      except optionally I2.  */
  469.   if (i1 && volatile_refs_p (PATTERN (i1)))
  470.     {
  471.       rtx insn;
  472.       rtx end = (volatile_refs_p (PATTERN (i2)) ? i2 : i3);
  473.       for (insn = NEXT_INSN (i1); insn != end; insn = NEXT_INSN (insn))
  474.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  475.         || GET_CODE (insn) == JUMP_INSN)
  476.       if (volatile_refs_p (PATTERN (insn)))
  477.         return 0;
  478.     }
  479.  
  480.   /* If I1 or I2 contains an autoincrement or autodecrement,
  481.      make sure that register is not used between there and I3,
  482.      and not already used in I3 either.
  483.      Also insist that I3 not be a jump; if it were one
  484.      and the incremented register were spilled, we would lose.  */
  485.   for (link = REG_NOTES (i2); link; link = XEXP (link, 1))
  486.     if (REG_NOTE_KIND (link) == REG_INC
  487.     && (GET_CODE (i3) == JUMP_INSN
  488.         || reg_used_between_p (XEXP (link, 0), i2, i3)
  489.         || reg_mentioned_p (XEXP (link, 0), PATTERN (i3))))
  490.       return 0;
  491.  
  492.   if (i1)
  493.     for (link = REG_NOTES (i1); link; link = XEXP (link, 1))
  494.       if (REG_NOTE_KIND (link) == REG_INC
  495.       && (GET_CODE (i3) == JUMP_INSN
  496.           || reg_used_between_p (XEXP (link, 0), i1, i3)
  497.           || reg_mentioned_p (XEXP (link, 0), PATTERN (i3))))
  498.     return 0;
  499.  
  500.   /* If I3 has an inc, then give up if I1 or I2 uses the reg that is inc'd,
  501.      EXCEPT in one case: I3 has a post-inc in an output operand.  */
  502.   if (!(GET_CODE (PATTERN (i3)) == SET
  503.     && GET_CODE (SET_SRC (PATTERN (i3))) == REG
  504.     && GET_CODE (SET_DEST (PATTERN (i3))) == MEM
  505.     && (GET_CODE (XEXP (SET_DEST (PATTERN (i3)), 0)) == POST_INC
  506.         || GET_CODE (XEXP (SET_DEST (PATTERN (i3)), 0)) == POST_DEC)))
  507.     /* It's not the exception.  */
  508.     for (link = REG_NOTES (i3); link; link = XEXP (link, 1))
  509.       if (REG_NOTE_KIND (link) == REG_INC
  510.       && (reg_mentioned_p (XEXP (link, 0), PATTERN (i2))
  511.           || (i1 != 0
  512.           && reg_mentioned_p (XEXP (link, 0), PATTERN (i1)))))
  513.     return 0;
  514.  
  515.   /* Don't combine an insn I1 or I2 that follows a CC0-setting insn.
  516.      An insn that uses CC0 must not be separated from the one that sets it.
  517.      It would be more logical to test whether CC0 occurs inside I1 or I2,
  518.      but that would be much slower, and this ought to be equivalent.  */
  519.   temp = PREV_INSN (i2);
  520.   while (temp && GET_CODE (temp) == NOTE)
  521.     temp = PREV_INSN (temp);
  522.   if (temp && GET_CODE (temp) == INSN && sets_cc0_p (PATTERN (temp)))
  523.     return 0;
  524.   if (i1)
  525.     {
  526.       temp = PREV_INSN (i2);
  527.       while (temp && GET_CODE (temp) == NOTE)
  528.     temp = PREV_INSN (temp);
  529.       if (temp && GET_CODE (temp) == INSN && sets_cc0_p (PATTERN (temp)))
  530.     return 0;
  531.     }
  532.  
  533.   /* See if the SETs in i1 or i2 need to be kept around in the merged
  534.      instruction: whenever the value set there is still needed past i3.  */
  535.   added_sets_2 = (GET_CODE (i2dest) != CC0
  536.           && ! dead_or_set_p (i3, i2dest));
  537.   if (i1)
  538.     added_sets_1 = ! (dead_or_set_p (i3, i1dest)
  539.               || dead_or_set_p (i2, i1dest));
  540.  
  541.   combine_merges++;
  542.  
  543.   undobuf.num_undo = 0;
  544.   undobuf.storage = 0;
  545.  
  546.   /* Substitute in the latest insn for the regs set by the earlier ones.  */
  547.  
  548.   maxreg = max_reg_num ();
  549.  
  550.   subst_insn = i3;
  551.   n_occurrences = 0;        /* `subst' counts here */
  552.  
  553.   newpat = subst (PATTERN (i3), i2dest, i2src);
  554.   /* Record whether i2's body now appears within i3's body.  */
  555.   i2_is_used = n_occurrences;
  556.  
  557.   if (i1)
  558.     {
  559.       n_occurrences = 0;
  560.       newpat = subst (newpat, i1dest, i1src);
  561.     }
  562.  
  563.   if (GET_CODE (PATTERN (i3)) == SET
  564.       && SET_DEST (PATTERN (i3)) == cc0_rtx
  565.       && (GET_CODE (SET_SRC (PATTERN (i3))) == AND
  566.       || GET_CODE (SET_SRC (PATTERN (i3))) == LSHIFTRT)
  567.       && next_insn_tests_no_inequality (i3))
  568.     simplify_set_cc0_and (i3);
  569.  
  570.   if (max_reg_num () != maxreg)
  571.     abort ();
  572.  
  573.   /* If the actions of the earler insns must be kept
  574.      in addition to substituting them into the latest one,
  575.      we must make a new PARALLEL for the latest insn
  576.      to hold additional the SETs.  */
  577.  
  578.   if (added_sets_1 || added_sets_2)
  579.     {
  580.       combine_extras++;
  581.  
  582.       /* Arrange to free later what we allocate now
  583.      if we don't accept this combination.  */
  584.       if (!undobuf.storage)
  585.     undobuf.storage = (char *) oballoc (0);
  586.  
  587.       if (GET_CODE (newpat) == PARALLEL)
  588.     {
  589.       rtvec old = XVEC (newpat, 0);
  590.       total_sets = XVECLEN (newpat, 0) + added_sets_1 + added_sets_2;
  591.       newpat = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (total_sets));
  592.       bcopy (&old->elem[0], &XVECEXP (newpat, 0, 0),
  593.          sizeof (old->elem[0]) * old->num_elem);
  594.     }
  595.       else
  596.     {
  597.       rtx old = newpat;
  598.       total_sets = 1 + added_sets_1 + added_sets_2;
  599.       newpat = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (total_sets));
  600.       XVECEXP (newpat, 0, 0) = old;
  601.     }
  602.      if (added_sets_1)
  603.     {
  604.       XVECEXP (newpat, 0, --total_sets) = PATTERN (i1);
  605.     }
  606.      if (added_sets_2)
  607.     {
  608.       /* If there is no I1, use I2's body as is.  */
  609.       if (i1 == 0
  610.       /* If I2 was stuck into I3, then anything within it has
  611.          already had I1 substituted into it when that was done to I3.  */
  612.           || i2_is_used)
  613.         {
  614.           XVECEXP (newpat, 0, --total_sets) = PATTERN (i2);
  615.         }
  616.       else
  617.         XVECEXP (newpat, 0, --total_sets)
  618.           = subst (PATTERN (i2), i1dest, i1src);
  619.     }
  620.     }
  621.  
  622.   /* Fail if an autoincrement side-effect has been duplicated.  */
  623.   if ((i2_is_used > 1 && find_reg_note (i2, REG_INC, 0) != 0)
  624.       || (i1 != 0 && n_occurrences > 1 && find_reg_note (i1, REG_INC, 0) != 0))
  625.     {
  626.       undo_all ();
  627.       return 0;
  628.     }
  629.  
  630.   /* Is the result of combination a valid instruction?  */
  631.   insn_code_number = recog (newpat, i3);
  632.  
  633.   if (insn_code_number >= 0
  634.       /* Is the result a reasonable ASM_OPERANDS?  */
  635.       || (check_asm_operands (newpat) && ! added_sets_1 && ! added_sets_2))
  636.     {
  637.       /* Yes.  Install it.  */
  638.       register int regno;
  639.       INSN_CODE (i3) = insn_code_number;
  640.       PATTERN (i3) = newpat;
  641.       /* If anything was substituted more than once,
  642.      copy it to avoid invalid shared rtl structure.  */
  643.       copy_substitutions ();
  644.       /* The data flowing into I2 now flows into I3.
  645.      But we cannot always move all of I2's LOG_LINKS into I3,
  646.      since they must go to a setting of a REG from the
  647.      first use following.  If I2 was the first use following a set,
  648.      I3 is now a use, but it is not the first use
  649.      if some instruction between I2 and I3 is also a use.
  650.      Here, for simplicity, we move all the links only if
  651.      there are no real insns between I2 and I3.
  652.      Otherwise, we move only links that correspond to regs
  653.      that used to die in I2.  They are always safe to move.  */
  654.       add_links (i3, i2, adjacent_insns_p (i2, i3));
  655.       /* Most REGs that previously died in I2 now die in I3.  */ 
  656.       move_deaths (i2src, INSN_CUID (i2), i3);
  657.       if (GET_CODE (i2dest) == REG)
  658.     {
  659.       /* If the reg formerly set in I2 died only once and that was in I3,
  660.          zero its use count so it won't make `reload' do any work.  */
  661.       regno = REGNO (i2dest);
  662.       if (! added_sets_2)
  663.         {
  664.           reg_n_sets[regno]--;
  665.           /* Used to check  && regno_dead_p (regno, i3)  also here.  */
  666.           if (reg_n_sets[regno] == 0
  667.           && ! (basic_block_live_at_start[0][regno / HOST_BITS_PER_INT]
  668.             & (1 << (regno % HOST_BITS_PER_INT))))
  669.         reg_n_refs[regno] = 0;
  670.         }
  671.       /* If a ref to REGNO was substituted into I3 from I2,
  672.          then it still dies there if it previously did.
  673.          Otherwise either REGNO never did die in I3 so remove_death is safe
  674.          or this entire life of REGNO is gone so remove its death.  */
  675.       if (!added_sets_2
  676.           && ! reg_mentioned_p (i2dest, PATTERN (i3)))
  677.         remove_death (regno, i3);
  678.     }
  679.       /* Any registers previously autoincremented in I2
  680.      are now incremented in I3.  */
  681.       add_incs (i3, REG_NOTES (i2));
  682.       if (i1)
  683.     {
  684.       /* Likewise, merge the info from I1 and get rid of it.  */
  685.       add_links (i3, i1,
  686.              adjacent_insns_p (i1, i2) && adjacent_insns_p (i2, i3));
  687.       move_deaths (i1src, INSN_CUID (i1), i3);
  688.       if (GET_CODE (i1dest) == REG)
  689.         {
  690.           regno = REGNO (i1dest);
  691.           if (! added_sets_1)
  692.         {
  693.           reg_n_sets[regno]--;
  694.           /* Used to also check  && regno_dead_p (regno, i3) here.  */
  695.  
  696.           if (reg_n_sets[regno] == 0
  697.               && ! (basic_block_live_at_start[0][regno / HOST_BITS_PER_INT]
  698.                 & (1 << (regno % HOST_BITS_PER_INT))))
  699.  
  700.             reg_n_refs[regno] = 0;
  701.         }
  702.           /* If a ref to REGNO was substituted into I3 from I1,
  703.          then it still dies there if it previously did.
  704.          Else either REGNO never did die in I3 so remove_death is safe
  705.          or this entire life of REGNO is gone so remove its death.  */
  706.           if (! added_sets_1
  707.           && ! reg_mentioned_p (i1dest, PATTERN (i3)))
  708.         remove_death (regno, i3);
  709.         }
  710.       add_incs (i3, REG_NOTES (i1));
  711.       LOG_LINKS (i1) = 0;
  712.       PUT_CODE (i1, NOTE);
  713.       NOTE_LINE_NUMBER (i1) = NOTE_INSN_DELETED;
  714.       NOTE_SOURCE_FILE (i1) = 0;
  715.     }
  716.       /* Get rid of I2.  */
  717.       LOG_LINKS (i2) = 0;
  718.       PUT_CODE (i2, NOTE);
  719.       NOTE_LINE_NUMBER (i2) = NOTE_INSN_DELETED;
  720.       NOTE_SOURCE_FILE (i2) = 0;
  721.  
  722.       combine_successes++;
  723.       return 1;
  724.     }
  725.  
  726.   /* Failure: change I3 back the way it was.  */
  727.   undo_all ();
  728.  
  729.   return 0;
  730. }
  731.  
  732. /* Undo all the modifications recorded in undobuf.  */
  733.  
  734. static void
  735. undo_all ()
  736. {
  737.   register int i;
  738.   if (undobuf.num_undo > MAX_UNDO)
  739.     undobuf.num_undo = MAX_UNDO;
  740.   for (i = undobuf.num_undo - 1; i >= 0; i--)
  741.     *undobuf.undo[i].where = undobuf.undo[i].old_contents;
  742.   if (undobuf.storage)
  743.     obfree (undobuf.storage);
  744.   undobuf.num_undo = 0;
  745.   undobuf.storage = 0;
  746. }
  747.  
  748. /* If this insn had more than one substitution,
  749.    copy all but one, so that no invalid shared substructure is introduced.  */
  750.  
  751. static void
  752. copy_substitutions ()
  753. {
  754.   register int i;
  755.   if (undobuf.num_undo > 1)
  756.     {
  757.       for (i = undobuf.num_undo - 1; i >= 1; i--)
  758.     if (! undobuf.undo[i].is_int)
  759.       *undobuf.undo[i].where = copy_rtx (*undobuf.undo[i].where);
  760.     }
  761. }
  762.  
  763. /* Throughout X, replace FROM with TO, and return the result.
  764.    The result is TO if X is FROM;
  765.    otherwise the result is X, but its contents may have been modified.
  766.    If they were modified, a record was made in undobuf so that
  767.    undo_all will (among other things) return X to its original state.
  768.  
  769.    If the number of changes necessary is too much to record to undo,
  770.    the excess changes are not made, so the result is invalid.
  771.    The changes already made can still be undone.
  772.    undobuf.num_undo is incremented for such changes, so by testing that
  773.    the caller can tell whether the result is valid.
  774.  
  775.    `n_occurrences' is incremented each time FROM is replaced.  */
  776.  
  777. static rtx
  778. subst (x, from, to)
  779.      register rtx x, from, to;
  780. {
  781.   register char *fmt;
  782.   register int len, i;
  783.   register enum rtx_code code;
  784. #if (defined(atarist) || defined(atariminix))
  785.   short was_replaced[2];    /* 'char' confuses GAS 1.14... */
  786. #else
  787.   char was_replaced[2];
  788. #endif
  789.  
  790. #define SUBST(INTO, NEWVAL)  \
  791.  do { if (undobuf.num_undo < MAX_UNDO)                    \
  792.     {                                \
  793.       undobuf.undo[undobuf.num_undo].where = &INTO;            \
  794.       undobuf.undo[undobuf.num_undo].old_contents = INTO;        \
  795.       undobuf.undo[undobuf.num_undo].is_int = 0;            \
  796.       INTO = NEWVAL;                        \
  797.     }                                \
  798.       undobuf.num_undo++; } while (0)
  799.  
  800. #define SUBST_INT(INTO, NEWVAL)  \
  801.  do { if (undobuf.num_undo < MAX_UNDO)                    \
  802.     {                                \
  803.       struct undo_int *u = (struct undo_int *)&undobuf.undo[undobuf.num_undo];\
  804.       u->where = &INTO;                        \
  805.       u->old_contents = INTO;                    \
  806.       u->is_int = 1;                        \
  807.       INTO = NEWVAL;                        \
  808.     }                                \
  809.       undobuf.num_undo++; } while (0)
  810.  
  811. /* FAKE_EXTEND_SAFE_P (MODE, FROM) is 1 if (subreg:MODE FROM 0) is a safe
  812.    replacement for (zero_extend:MODE FROM) or (sign_extend:MODE FROM).
  813.    If it is 0, that cannot be done.  We can now do this for any MEM
  814.    because (SUBREG (MEM...)) is guaranteed to cause the MEM to be reloaded.
  815.    If not for that, MEM's would very rarely be safe.  */
  816.  
  817. /* Reject MODEs bigger than a word, because we might not be able
  818.    to reference a two-register group starting with an arbitrary register
  819.    (and currently gen_lowpart might crash for a SUBREG).  */
  820.  
  821. #define FAKE_EXTEND_SAFE_P(MODE, FROM) \
  822.   (GET_MODE_SIZE (MODE) <= UNITS_PER_WORD            \
  823.    && (GET_CODE (FROM) == REG || GET_CODE (FROM) == SUBREG    \
  824.        || GET_CODE (FROM) == MEM))
  825.  
  826.   if (x == from)
  827.     return to;
  828.  
  829.   /* It is possible to have a subexpression appear twice in the insn.
  830.      Suppose that FROM is a register that appears within TO.
  831.      Then, after that subexpression has been scanned once by `subst',
  832.      the second time it is scanned, TO may be found.  If we were
  833.      to scan TO here, we would find FROM within it and create a
  834.      self-referent rtl structure which is completely wrong.  */
  835.   if (x == to)
  836.     return to;
  837.  
  838.   code = GET_CODE (x);
  839.  
  840.   /* A little bit of algebraic simplification here.  */
  841.   switch (code)
  842.     {
  843.       /* This case has no effect except to speed things up.  */
  844.     case REG:
  845.     case CONST_INT:
  846.     case CONST:
  847.     case SYMBOL_REF:
  848.     case LABEL_REF:
  849.     case PC:
  850.     case CC0:
  851.       return x;
  852.     }
  853.  
  854.   was_replaced[0] = 0;
  855.   was_replaced[1] = 0;
  856.  
  857.   len = GET_RTX_LENGTH (code);
  858.   fmt = GET_RTX_FORMAT (code);
  859.  
  860.   /* Don't replace FROM where it is being stored in rather than used.  */
  861.   if (code == SET && SET_DEST (x) == from)
  862.     fmt = "ie";
  863.   if (code == SET && GET_CODE (SET_DEST (x)) == SUBREG
  864.       && SUBREG_REG (SET_DEST (x)) == from)
  865.     fmt = "ie";
  866.  
  867.   for (i = 0; i < len; i++)
  868.     {
  869.       if (fmt[i] == 'E')
  870.     {
  871.       register int j;
  872.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  873.         {
  874.           register rtx new;
  875.           if (XVECEXP (x, i, j) == from)
  876.         new = to, n_occurrences++;
  877.           else
  878.         new = subst (XVECEXP (x, i, j), from, to);
  879.           if (new != XVECEXP (x, i, j))
  880.         SUBST (XVECEXP (x, i, j), new);
  881.         }
  882.     }
  883.       else if (fmt[i] == 'e')
  884.     {
  885.       register rtx new;
  886.  
  887.       if (XEXP (x, i) == from)
  888.         {
  889.           new = to;
  890.           n_occurrences++;
  891.           if (i < 2)
  892.         was_replaced[i] = 1;
  893.         }
  894.       else
  895.         new = subst (XEXP (x, i), from, to);
  896.  
  897.       if (new != XEXP (x, i))
  898.         SUBST (XEXP (x, i), new);
  899.     }
  900.     }
  901.  
  902.   /* A little bit of algebraic simplification here.  */
  903.   switch (code)
  904.     {
  905.     case SUBREG:
  906.       /* Changing mode twice with SUBREG => just change it once,
  907.      or not at all if changing back to starting mode.  */
  908.       if (SUBREG_REG (x) == to
  909.       && GET_CODE (to) == SUBREG)
  910.     {
  911.       if (GET_MODE (x) == GET_MODE (SUBREG_REG (to)))
  912.         if (SUBREG_WORD (x) == 0 && SUBREG_WORD (to) == 0)
  913.           return SUBREG_REG (to);
  914.       SUBST (SUBREG_REG (x), SUBREG_REG (to));
  915.       if (SUBREG_WORD (to) != 0)
  916.         SUBST_INT (SUBREG_WORD (x), SUBREG_WORD (x) + SUBREG_WORD (to));
  917.     }
  918.       if (SUBREG_REG (x) == to
  919.       && (GET_CODE (to) == SIGN_EXTEND || GET_CODE (to) == ZERO_EXTEND)
  920.       && subreg_lowpart_p (x))
  921.     {
  922.       /* (subreg (sign_extend X)) is X, if it has same mode as X.  */
  923.       if (GET_MODE (x) == GET_MODE (XEXP (to, 0)))
  924.         return XEXP (to, 0);
  925.       /* (subreg (sign_extend X)), if it has a mode wider than X,
  926.          can be done with (sign_extend X).  */
  927.       if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (XEXP (to, 0))))
  928.         {
  929.           if (!undobuf.storage)
  930.         undobuf.storage = (char *) oballoc (0);
  931.           return gen_rtx (GET_CODE (to), GET_MODE (x), XEXP (to, 0));
  932.         }
  933.       /* Extend and then truncate smaller than it was to start with:
  934.          no need to extend.  */
  935.       if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (GET_MODE (XEXP (to, 0))))
  936.         {
  937.           SUBST (XEXP (x, 0), XEXP (to, 0));
  938.         }
  939.     }
  940.       /* (subreg:A (mem:B X) N) becomes a modified MEM.
  941.      This avoids producing any (subreg (mem))s except in the special
  942.      paradoxical case where gen_lowpart_for_combine makes them.  */
  943.       if (SUBREG_REG (x) == to
  944.       && GET_CODE (to) == MEM)
  945.     {
  946.       int endian_offset = 0;
  947. #ifdef BYTES_BIG_ENDIAN
  948.       if (GET_MODE_SIZE (GET_MODE (x)) < UNITS_PER_WORD)
  949.         endian_offset += UNITS_PER_WORD - GET_MODE_SIZE (GET_MODE (x));
  950.       if (GET_MODE_SIZE (GET_MODE (to)) < UNITS_PER_WORD)
  951.         endian_offset -= UNITS_PER_WORD - GET_MODE_SIZE (GET_MODE (to));
  952. #endif
  953.       if (!undobuf.storage)
  954.         undobuf.storage = (char *) oballoc (0);
  955.       /* Note if the plus_constant doesn't make a valid address
  956.          then this combination won't be accepted.  */
  957.       return gen_rtx (MEM, GET_MODE (x),
  958.               plus_constant (XEXP (to, 0),
  959.                      (SUBREG_WORD (x) * UNITS_PER_WORD
  960.                       + endian_offset)));
  961.     }
  962.       break;
  963.  
  964.     case NOT:
  965.       /* (not (minus X 1)) can become (neg X).  */
  966.       if (was_replaced[0]
  967.       && ((GET_CODE (to) == PLUS && INTVAL (XEXP (to, 1)) == -1)
  968.           || (GET_CODE (to) == MINUS && XEXP (to, 1) == const1_rtx)))
  969.     {
  970.       if (!undobuf.storage)
  971.         undobuf.storage = (char *) oballoc (0);
  972.       return gen_rtx (NEG, GET_MODE (to), XEXP (to, 0));
  973.     }
  974.       /* Don't let substitution introduce double-negatives.  */
  975.       if (was_replaced[0]
  976.       && GET_CODE (to) == code)
  977.     return XEXP (to, 0);
  978.       break;
  979.  
  980.     case NEG:
  981.       /* (neg (minus X Y)) can become (minus Y X).  */
  982.       if (was_replaced[0] && GET_CODE (to) == MINUS)
  983.     {
  984.       if (!undobuf.storage)
  985.         undobuf.storage = (char *) oballoc (0);
  986.       return gen_rtx (MINUS, GET_MODE (to),
  987.               XEXP (to, 1), XEXP (to, 0));
  988.     }
  989.       /* Don't let substitution introduce double-negatives.  */
  990.       if (was_replaced[0]
  991.       && GET_CODE (to) == code)
  992.     return XEXP (to, 0);
  993.       break;
  994.  
  995.     case FLOAT_TRUNCATE:
  996.       /* (float_truncate:SF (float_extend:DF foo:SF)) = foo:SF.  */
  997.       if (was_replaced[0]
  998.       && GET_CODE (to) == FLOAT_EXTEND
  999.       && GET_MODE (XEXP (to, 0)) == GET_MODE (x))
  1000.     return XEXP (to, 0);
  1001.       break;
  1002.  
  1003.     case PLUS:
  1004.       /* In (plus <foo> (ashift <bar> <n>))
  1005.      change the shift to a multiply so we can recognize
  1006.      scaled indexed addresses.  */
  1007.       if ((was_replaced[0]
  1008.        || was_replaced[1])
  1009.       && GET_CODE (to) == ASHIFT
  1010.       && GET_CODE (XEXP (to, 1)) == CONST_INT
  1011.       && INTVAL (XEXP (to, 1)) < HOST_BITS_PER_INT)
  1012.     {
  1013.       rtx temp;
  1014.       if (!undobuf.storage)
  1015.         undobuf.storage = (char *) oballoc (0);
  1016.       temp = gen_rtx (MULT, GET_MODE (to),
  1017.               XEXP (to, 0),
  1018.               gen_rtx (CONST_INT, VOIDmode,
  1019.                    1 << INTVAL (XEXP (to, 1))));
  1020.       if (was_replaced[0])
  1021.         SUBST (XEXP (x, 0), temp);
  1022.       else
  1023.         SUBST (XEXP (x, 1), temp);
  1024.     }
  1025.       /* (plus X (neg Y)) becomes (minus X Y).  */
  1026.       if (GET_CODE (XEXP (x, 1)) == NEG)
  1027.     {
  1028.       if (!undobuf.storage)
  1029.         undobuf.storage = (char *) oballoc (0);
  1030.       return gen_rtx (MINUS, GET_MODE (x),
  1031.               XEXP (x, 0), XEXP (XEXP (x, 1), 0));
  1032.     }
  1033.       /* (plus (neg X) Y) becomes (minus Y X).  */
  1034.       if (GET_CODE (XEXP (x, 0)) == NEG)
  1035.     {
  1036.       if (!undobuf.storage)
  1037.         undobuf.storage = (char *) oballoc (0);
  1038.       return gen_rtx (MINUS, GET_MODE (x),
  1039.               XEXP (x, 1), XEXP (XEXP (x, 0), 0));
  1040.     }
  1041.       /* (plus (plus x c1) c2) => (plus x c1+c2) */
  1042.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  1043.       && GET_CODE (XEXP (x, 0)) == PLUS
  1044.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
  1045.     {
  1046.       int sum = (INTVAL (XEXP (x, 1))
  1047.              + INTVAL (XEXP (XEXP (x, 0), 1)));
  1048.       if (sum == 0)
  1049.         return XEXP (XEXP (x, 0), 0);
  1050.       if (!undobuf.storage)
  1051.         undobuf.storage = (char *) oballoc (0);
  1052.       SUBST (XEXP (x, 1), gen_rtx (CONST_INT, VOIDmode, sum));
  1053.       SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
  1054.       break;
  1055.     }
  1056.       /* If we have something (putative index) being added to a sum,
  1057.      associate it so that any constant term is outermost.
  1058.      That's because that's the way indexed addresses are
  1059.      now supposed to appear.  */
  1060.       if (((was_replaced[0] && GET_CODE (XEXP (x, 1)) == PLUS)
  1061.        || (was_replaced[1] && GET_CODE (XEXP (x, 0)) == PLUS))
  1062.       ||
  1063.       ((was_replaced[0] || was_replaced[1])
  1064.        && GET_CODE (to) == PLUS))
  1065.     {
  1066.       rtx offset = 0, base, index;
  1067.       if (GET_CODE (to) != PLUS)
  1068.         {
  1069.           index = to;
  1070.           base = was_replaced[0] ? XEXP (x, 1) : XEXP (x, 0);
  1071.         }
  1072.       else
  1073.         {
  1074.           index = was_replaced[0] ? XEXP (x, 1) : XEXP (x, 0);
  1075.           base = to;
  1076.         }
  1077.       if (CONSTANT_ADDRESS_P (XEXP (base, 0)))
  1078.         {
  1079.           offset = XEXP (base, 0);
  1080.           base = XEXP (base, 1);
  1081.         }
  1082.       else if (CONSTANT_ADDRESS_P (XEXP (base, 1)))
  1083.         {
  1084.           offset = XEXP (base, 1);
  1085.           base = XEXP (base, 0);
  1086.         }
  1087.       if (offset != 0)
  1088.         {
  1089.           if (!undobuf.storage)
  1090.         undobuf.storage = (char *) oballoc (0);
  1091.           if (GET_CODE (offset) == CONST_INT)
  1092.         return plus_constant (gen_rtx (PLUS, GET_MODE (index),
  1093.                            base, index),
  1094.                       INTVAL (offset));
  1095.           if (GET_CODE (index) == CONST_INT)
  1096.         return plus_constant (gen_rtx (PLUS, GET_MODE (offset),
  1097.                            base, offset),
  1098.                       INTVAL (index));
  1099.           return gen_rtx (PLUS, GET_MODE (index),
  1100.                   gen_rtx (PLUS, GET_MODE (index),
  1101.                        base, index),
  1102.                   offset);
  1103.         }
  1104.     }
  1105.       break;
  1106.  
  1107.     case EQ:
  1108.     case NE:
  1109.       /* If comparing a subreg against zero, discard the subreg.  */
  1110.       if (was_replaced[0]
  1111.       && GET_CODE (to) == SUBREG
  1112.       && SUBREG_WORD (to) == 0
  1113.       && XEXP (x, 1) == const0_rtx)
  1114.     SUBST (XEXP (x, 0), SUBREG_REG (to));
  1115.  
  1116.       /* If comparing a ZERO_EXTRACT against zero,
  1117.      canonicalize to a SIGN_EXTRACT,
  1118.      since the two are equivalent here.  */
  1119.       if (was_replaced[0]
  1120.       && GET_CODE (to) == ZERO_EXTRACT
  1121.       && XEXP (x, 1) == const0_rtx)
  1122.     {
  1123.       if (!undobuf.storage)
  1124.         undobuf.storage = (char *) oballoc (0);
  1125.       SUBST (XEXP (x, 0),
  1126.          gen_rtx (SIGN_EXTRACT, GET_MODE (to),
  1127.               XEXP (to, 0), XEXP (to, 1),
  1128.               XEXP (to, 2)));
  1129.     }
  1130.       /* If we are putting (ASHIFT 1 x) into (EQ (AND ... y) 0),
  1131.      arrange to return (EQ (SIGN_EXTRACT y 1 x) 0),
  1132.      which is what jump-on-bit instructions are written with.  */
  1133.       else if (XEXP (x, 1) == const0_rtx
  1134.            && GET_CODE (XEXP (x, 0)) == AND
  1135.            && (XEXP (XEXP (x, 0), 0) == to
  1136.            || XEXP (XEXP (x, 0), 1) == to)
  1137.            && GET_CODE (to) == ASHIFT
  1138.            && XEXP (to, 0) == const1_rtx)
  1139.     {
  1140.       register rtx y = XEXP (XEXP (x, 0),
  1141.                  XEXP (XEXP (x, 0), 0) == to);
  1142.       if (!undobuf.storage)
  1143.         undobuf.storage = (char *) oballoc (0);
  1144.       SUBST (XEXP (x, 0),
  1145.          gen_rtx (SIGN_EXTRACT, GET_MODE (to),
  1146.               y,
  1147.               const1_rtx, XEXP (to, 1)));
  1148.     }
  1149.  
  1150.       break;
  1151.  
  1152.     case ZERO_EXTEND:
  1153.       /* Nested zero-extends are equivalent to just one.  */
  1154.       if (was_replaced[0]
  1155.       && GET_CODE (to) == ZERO_EXTEND)
  1156.     SUBST (XEXP (x, 0), XEXP (to, 0));
  1157.       /* Zero extending a constant int can be replaced
  1158.      by a zero-extended constant.  */
  1159.       if (was_replaced[0]
  1160.       && HOST_BITS_PER_INT >= GET_MODE_BITSIZE (GET_MODE (from))
  1161.       && GET_CODE (to) == CONST_INT)
  1162.     {
  1163.       int intval = INTVAL (to) & GET_MODE_MASK (GET_MODE (from));
  1164.       if (!undobuf.storage)
  1165.         undobuf.storage = (char *) oballoc (0);
  1166.       return gen_rtx (CONST_INT, VOIDmode, intval);
  1167.     }
  1168.       /* Zero-extending the result of an and with a constant can be done
  1169.      with a wider and.  */
  1170.       if (was_replaced[0]
  1171.       && GET_CODE (to) == AND
  1172.       && GET_CODE (XEXP (to, 1)) == CONST_INT
  1173.       && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0))
  1174.       /* Avoid getting wrong result if the constant has high bits set
  1175.          that are irrelevant in the narrow mode where it is being used.  */
  1176.       && 0 == (INTVAL (XEXP (to, 1))
  1177.            & ~ GET_MODE_MASK (GET_MODE (to))))
  1178.     {
  1179.       if (!undobuf.storage)
  1180.         undobuf.storage = (char *) oballoc (0);
  1181.       return gen_rtx (AND, GET_MODE (x),
  1182.               gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
  1183.               XEXP (to, 1));
  1184.     } 
  1185.       /* Change (zero_extend:M (subreg:N (zero_extract:M ...) 0))
  1186.      to (zero_extract:M ...) if the field extracted fits in mode N.  */
  1187.       if (GET_CODE (XEXP (x, 0)) == SUBREG
  1188.       && GET_CODE (XEXP (XEXP (x, 0), 0)) == ZERO_EXTRACT
  1189.       && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
  1190.       && (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1))
  1191.           <= GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))))
  1192.     {
  1193.       return XEXP (XEXP (x, 0), 0);
  1194.     }
  1195.       /* Change (zero_extend:M (subreg:N (and:M ... <const>) 0))
  1196.      to (and:M ...) if the significant bits fit in mode N.  */
  1197.       if (GET_CODE (XEXP (x, 0)) == SUBREG
  1198.       && SUBREG_REG (XEXP (x, 0)) == to
  1199.       && SUBREG_WORD (XEXP (x, 0)) == 0
  1200.       && GET_CODE (to) == AND
  1201.       && GET_CODE (XEXP (to, 1)) == CONST_INT
  1202.       && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0))
  1203.       /* Avoid getting wrong result if the constant has high bits set
  1204.          that are irrelevant in the narrow mode where it is being used.  */
  1205.       && 0 == (INTVAL (XEXP (to, 1))
  1206.            & ~ GET_MODE_MASK (GET_MODE (to))))
  1207.     {
  1208.       if (!undobuf.storage)
  1209.         undobuf.storage = (char *) oballoc (0);
  1210.       return gen_rtx (AND, GET_MODE (x),
  1211.               gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
  1212.               XEXP (to, 1));
  1213.     }
  1214.       /* In (zero_extend:M (subreg:N (lshiftrt:M (zero_extend:M (any:N ...)))))
  1215.      remove the outer zero extension.  */
  1216.       if (GET_CODE (XEXP (x, 0)) == SUBREG
  1217.       && SUBREG_REG (XEXP (x, 0)) == to
  1218.       && SUBREG_WORD (XEXP (x, 0)) == 0
  1219.       && GET_CODE (to) == LSHIFTRT)
  1220.     {
  1221.       rtx tmp = XEXP (to, 0);
  1222.  
  1223.       if (GET_CODE (tmp) == REG)
  1224.         if (reg_n_sets[REGNO (tmp)] == 1)
  1225.           tmp = SET_SRC (PATTERN (reg_last_set[REGNO (tmp)]));
  1226.         else
  1227.           break;
  1228.  
  1229.       if (GET_CODE (tmp) == ZERO_EXTEND
  1230.           && GET_MODE (tmp) == GET_MODE (x)
  1231.           && GET_MODE (XEXP (tmp, 0)) == GET_MODE (XEXP (x, 0)))
  1232.         return SUBREG_REG (XEXP (x, 0));
  1233.     }
  1234.       break;
  1235.  
  1236.     case SIGN_EXTEND:
  1237.       /* Nested sign-extends are equivalent to just one.  */
  1238.       if (was_replaced[0]
  1239.       && GET_CODE (to) == SIGN_EXTEND)
  1240.     SUBST (XEXP (x, 0), XEXP (to, 0));
  1241.       /* Sign extending a constant int can be replaced
  1242.      by a sign-extended constant.  */
  1243.       if (was_replaced[0]
  1244.       && HOST_BITS_PER_INT >= GET_MODE_BITSIZE (GET_MODE (from))
  1245.       && GET_CODE (to) == CONST_INT)
  1246.     {
  1247.       int intval = INTVAL (to);
  1248.       if (!undobuf.storage)
  1249.         undobuf.storage = (char *) oballoc (0);
  1250.       if (intval > 0
  1251.           && (intval & (1 << (GET_MODE_BITSIZE (GET_MODE (from)) - 1))))
  1252.         intval |= ~ GET_MODE_MASK (GET_MODE (from));
  1253.       return gen_rtx (CONST_INT, VOIDmode, intval);
  1254.     }
  1255.       /* Sign-extending the result of an and with a constant can be done
  1256.      with a wider and, provided the high bit of the constant is 0.  */
  1257.       if (was_replaced[0]
  1258.       && GET_CODE (to) == AND
  1259.       && GET_CODE (XEXP (to, 1)) == CONST_INT
  1260.       && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0))
  1261.       && ((INTVAL (XEXP (to, 1))
  1262.            & (-1 << (GET_MODE_BITSIZE (GET_MODE (to)) - 1)))
  1263.           == 0))
  1264.     {
  1265.       if (!undobuf.storage)
  1266.         undobuf.storage = (char *) oballoc (0);
  1267.       return gen_rtx (AND, GET_MODE (x),
  1268.               gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
  1269.               XEXP (to, 1));
  1270.      } 
  1271.       /* hacks added by tiemann.  */
  1272.       /* Change (sign_extend:M (subreg:N (and:M ... <const>) 0))
  1273.      to (and:M ...), provided the result fits in mode N,
  1274.      and the high bit of the constant is 0.  */
  1275.       if (GET_CODE (XEXP (x, 0)) == SUBREG
  1276.       && SUBREG_REG (XEXP (x, 0)) == to
  1277.       && SUBREG_WORD (XEXP (x, 0)) == 0
  1278.       && GET_CODE (to) == AND
  1279.       && GET_CODE (XEXP (to, 1)) == CONST_INT
  1280.       && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0))
  1281.       && ((INTVAL (XEXP (to, 1))
  1282.            & (-1 << (GET_MODE_BITSIZE (GET_MODE (to)) - 1)))
  1283.           == 0))
  1284.     {
  1285.       if (!undobuf.storage)
  1286.         undobuf.storage = (char *) oballoc (0);
  1287.       return gen_rtx (AND, GET_MODE (x),
  1288.               gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
  1289.               XEXP (to, 1));
  1290.     } 
  1291.       /* In (sign_extend:M (subreg:N (ashiftrt:M (sign_extend:M (any:N ...)))))
  1292.      remove the outer sign extension.  */
  1293.       if (GET_CODE (XEXP (x, 0)) == SUBREG
  1294.       && SUBREG_REG (XEXP (x, 0)) == to
  1295.       && SUBREG_WORD (XEXP (x, 0)) == 0
  1296.       && GET_CODE (to) == ASHIFTRT)
  1297.     {
  1298.       rtx tmp = XEXP (to, 0);
  1299.  
  1300.       if (GET_CODE (tmp) == REG)
  1301.         if (reg_n_sets[REGNO (tmp)] == 1)
  1302.           tmp = SET_SRC (PATTERN (reg_last_set[REGNO (tmp)]));
  1303.         else
  1304.           break;
  1305.  
  1306.       if (GET_CODE (tmp) == SIGN_EXTEND
  1307.           && GET_MODE (tmp) == GET_MODE (x)
  1308.           && GET_MODE (XEXP (tmp, 0)) == GET_MODE (XEXP (x, 0)))
  1309.         return SUBREG_REG (XEXP (x, 0));
  1310.     }
  1311.       break;
  1312.  
  1313.     case SET:
  1314.       /* In (set (zero-extract <x> <n> <y>) (and <foo> <(2**n-1) | anything>))
  1315.      the `and' can be deleted.  This can happen when storing a bit
  1316.      that came from a set-flag insn followed by masking to one bit.  */
  1317.       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
  1318.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  1319.       && was_replaced[1]
  1320.       && GET_CODE (to) == AND
  1321.       && GET_CODE (XEXP (to, 1)) == CONST_INT
  1322.       && 0 == (((1 << INTVAL (XEXP (XEXP (x, 0), 1))) - 1)
  1323.            & ~ INTVAL (XEXP (to, 1))))
  1324.     {
  1325.       SUBST (XEXP (x, 1), XEXP (to, 0));
  1326.     } 
  1327.       /* In (set (zero-extract <x> <n> <y>)
  1328.          (subreg (and <foo> <(2**n-1) | anything>)))
  1329.      the `and' can be deleted.  */
  1330.       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
  1331.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  1332.       && GET_CODE (XEXP (x, 1)) == SUBREG
  1333.       && SUBREG_WORD (XEXP (x, 1)) == 0
  1334.       && GET_CODE (SUBREG_REG (XEXP (x, 1))) == AND
  1335.       && GET_CODE (XEXP (SUBREG_REG (XEXP (x, 1)), 1)) == CONST_INT
  1336.       && 0 == (((1 << INTVAL (XEXP (XEXP (x, 0), 1))) - 1)
  1337.            & ~ INTVAL (XEXP (SUBREG_REG (XEXP (x, 1)), 1))))
  1338.     {
  1339.       SUBST (SUBREG_REG (XEXP (x, 1)), XEXP (SUBREG_REG (XEXP (x, 1)), 0));
  1340.     } 
  1341.       /* (set (zero_extract ...) (and/or/xor (zero_extract ...) const)),
  1342.      if both zero_extracts have the same location, size and position,
  1343.      can be changed to avoid the byte extracts.  */
  1344.       if ((GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
  1345.        || GET_CODE (XEXP (x, 0)) == SIGN_EXTRACT)
  1346.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  1347.       && (GET_CODE (XEXP (x, 1)) == AND
  1348.           || GET_CODE (XEXP (x, 1)) == IOR
  1349.           || GET_CODE (XEXP (x, 1)) == XOR)
  1350.       && rtx_equal_p (XEXP (x, 0), XEXP (XEXP (x, 1), 0))
  1351.       && GET_CODE (XEXP (XEXP (x, 1), 0)) == GET_CODE (XEXP (x, 0))
  1352.       && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
  1353.       /* zero_extract can apply to a QImode even if the bits extracted
  1354.          don't fit inside that byte.  In such a case, we may not do this
  1355.          optimization, since the OR or AND insn really would need
  1356.          to fit in a byte.  */
  1357.       && (INTVAL (XEXP (XEXP (x, 0), 1)) + INTVAL (XEXP (XEXP (x, 0), 2))
  1358.           < GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (x, 0), 0)))))
  1359.     {
  1360.       int shiftcount;
  1361. #ifdef BITS_BIG_ENDIAN
  1362.       shiftcount
  1363.         = GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (x, 0), 0)))
  1364.           - INTVAL (XEXP (XEXP (x, 0), 1)) - INTVAL (XEXP (XEXP (x, 0), 2));
  1365. #else
  1366.       shiftcount
  1367.         = INTVAL (XEXP (XEXP (x, 0), 2));
  1368. #endif
  1369.       if (!undobuf.storage)
  1370.         undobuf.storage = (char *) oballoc (0);
  1371.       return
  1372.         gen_rtx (SET, VOIDmode,
  1373.              XEXP (XEXP (x, 0), 0),
  1374.              gen_rtx (GET_CODE (XEXP (x, 1)),
  1375.                   GET_MODE (XEXP (XEXP (x, 0), 0)),
  1376.                   XEXP (XEXP (XEXP (x, 1), 0), 0),
  1377.                   gen_rtx (CONST_INT, VOIDmode,
  1378.                        (INTVAL (XEXP (XEXP (x, 1), 1))
  1379.                     << shiftcount)
  1380.                        + (GET_CODE (XEXP (x, 1)) == AND
  1381.                       ? (1 << shiftcount) - 1
  1382.                       : 0))));
  1383.     }
  1384.       /* Can simplify (set (cc0) (compare (zero/sign_extend FOO) CONST))
  1385.      to (set (cc0) (compare FOO CONST)) if CONST fits in FOO's mode
  1386.      and we are only testing equality.
  1387.      In fact, this is valid for zero_extend if what follows is an
  1388.      unsigned comparison, and for sign_extend with a signed comparison.  */
  1389.       if (SET_DEST (x) == cc0_rtx
  1390.       && GET_CODE (SET_SRC (x)) == COMPARE
  1391.       && (GET_CODE (XEXP (SET_SRC (x), 0)) == ZERO_EXTEND
  1392.           || GET_CODE (XEXP (SET_SRC (x), 0)) == SIGN_EXTEND)
  1393.       && next_insn_tests_no_inequality (subst_insn)
  1394.       && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
  1395.       /* This is overly cautious by one bit, but saves worrying about
  1396.          whether it is zero-extension or sign extension.  */
  1397.       && ((unsigned) INTVAL (XEXP (SET_SRC (x), 1))
  1398.           < (1 << (GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (SET_SRC (x), 0), 0))) - 1))))
  1399.     SUBST (XEXP (SET_SRC (x), 0), XEXP (XEXP (SET_SRC (x), 0), 0));
  1400.       break;
  1401.  
  1402.     case AND:
  1403.       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  1404.     {
  1405.       rtx tem = simplify_and_const_int (x, to);
  1406.       if (tem)
  1407.         return tem;
  1408.     }
  1409.       break;
  1410.  
  1411.     case IOR:
  1412.     case XOR:
  1413.       /* (ior (ior x c1) c2) => (ior x c1|c2); likewise for xor.  */
  1414.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  1415.       && GET_CODE (XEXP (x, 0)) == code
  1416.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
  1417.     {
  1418.       int c0 = INTVAL (XEXP (x, 1));
  1419.       int c1 = INTVAL (XEXP (XEXP (x, 0), 1));
  1420.       int combined = (code == IOR ? c0 | c1 : c0 ^ c1);
  1421.  
  1422.       if (combined == 0)
  1423.         return XEXP (XEXP (x, 0), 0);
  1424.       if (!undobuf.storage)
  1425.         undobuf.storage = (char *) oballoc (0);
  1426.       SUBST (XEXP (x, 1), gen_rtx (CONST_INT, VOIDmode, combined));
  1427.       SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
  1428.       break;
  1429.     }
  1430.  
  1431.     case FLOAT:
  1432.       /* (float (sign_extend <X>)) = (float <X>).  */
  1433.       if (was_replaced[0]
  1434.       && GET_CODE (to) == SIGN_EXTEND)
  1435.     SUBST (XEXP (x, 0), XEXP (to, 0));
  1436.       break;
  1437.  
  1438.     case ZERO_EXTRACT:
  1439.       /* (ZERO_EXTRACT (TRUNCATE x)...)
  1440.      can become (ZERO_EXTRACT x ...).  */
  1441.       if (was_replaced[0]
  1442.       && GET_CODE (to) == TRUNCATE)
  1443.     {
  1444. #ifdef BITS_BIG_ENDIAN
  1445.       if (GET_CODE (XEXP (x, 2)) == CONST_INT)
  1446.         {
  1447.           if (!undobuf.storage)
  1448.         undobuf.storage = (char *) oballoc (0);
  1449.           /* On a big-endian machine, must increment the bit-number
  1450.          since sign bit is farther away in the pre-truncated value.  */
  1451.           return gen_rtx (ZERO_EXTRACT, GET_MODE (x),
  1452.                   XEXP (to, 0),
  1453.                   XEXP (x, 1),
  1454.                   gen_rtx (CONST_INT, VOIDmode,
  1455.                        (INTVAL (XEXP (x, 2))
  1456.                     + GET_MODE_BITSIZE (GET_MODE (XEXP (to, 0)))
  1457.                     - GET_MODE_BITSIZE (GET_MODE (to)))));
  1458.         }
  1459. #else
  1460.       SUBST (XEXP (x, 0), XEXP (to, 0));
  1461. #endif
  1462.     }
  1463.       /* Extracting a single bit from the result of a shift:
  1464.      see which bit it was before the shift and extract that directly.  */
  1465.       if (was_replaced[0]
  1466.       && (GET_CODE (to) == ASHIFTRT || GET_CODE (to) == LSHIFTRT
  1467.           || GET_CODE (to) == ASHIFT || GET_CODE (to) == LSHIFT)
  1468.       && GET_CODE (XEXP (to, 1)) == CONST_INT
  1469.       && XEXP (x, 1) == const1_rtx
  1470.       && GET_CODE (XEXP (x, 2)) == CONST_INT)
  1471.     {
  1472.       int shift = INTVAL (XEXP (to, 1));
  1473.       int newpos;
  1474.       if (GET_CODE (to) == ASHIFT || GET_CODE (to) == LSHIFT)
  1475.         shift = - shift;
  1476. #ifdef BITS_BIG_ENDIAN
  1477.       shift = - shift;
  1478. #endif
  1479.       newpos = INTVAL (XEXP (x, 2)) + shift;
  1480.       if (newpos >= 0 &&
  1481.           newpos < GET_MODE_BITSIZE (GET_MODE (to)))
  1482.         {
  1483.           if (!undobuf.storage)
  1484.         undobuf.storage = (char *) oballoc (0);
  1485.           return gen_rtx (ZERO_EXTRACT, GET_MODE (x),
  1486.                   XEXP (to, 0), const1_rtx,
  1487.                   gen_rtx (CONST_INT, VOIDmode, newpos));
  1488.         }
  1489.     }
  1490.       break;
  1491.  
  1492.     case LSHIFTRT:
  1493.     case ASHIFTRT:
  1494.     case ROTATE:
  1495.     case ROTATERT:
  1496. #ifdef SHIFT_COUNT_TRUNCATED
  1497.       /* (lshift <X> (sign_extend <Y>)) = (lshift <X> <Y>) (most machines).
  1498.      True for all kinds of shifts and also for zero_extend.  */
  1499.       if (was_replaced[1]
  1500.       && (GET_CODE (to) == SIGN_EXTEND
  1501.           || GET_CODE (to) == ZERO_EXTEND)
  1502.       && FAKE_EXTEND_SAFE_P (GET_MODE (to), XEXP (to, 0)))
  1503.     {
  1504.       if (!undobuf.storage)
  1505.         undobuf.storage = (char *) oballoc (0);
  1506.       SUBST (XEXP (x, 1),
  1507.          /* This is a perverse SUBREG, wider than its base.  */
  1508.          gen_lowpart_for_combine (GET_MODE (to), XEXP (to, 0)));
  1509.     }
  1510. #endif
  1511.       /* Two shifts in a row of same kind
  1512.      in same direction with constant counts
  1513.      may be combined.  */
  1514.       if (was_replaced[0]
  1515.       && GET_CODE (to) == GET_CODE (x)
  1516.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  1517.       && GET_CODE (XEXP (to, 1)) == CONST_INT
  1518.       && INTVAL (XEXP (to, 1)) > 0
  1519.       && INTVAL (XEXP (x, 1)) > 0
  1520.       && (INTVAL (XEXP (x, 1)) + INTVAL (XEXP (to, 1))
  1521.           < GET_MODE_BITSIZE (GET_MODE (x))))
  1522.     {
  1523.       if (!undobuf.storage)
  1524.         undobuf.storage = (char *) oballoc (0);
  1525.       return gen_rtx (GET_CODE (x), GET_MODE (x),
  1526.               XEXP (to, 0),
  1527.               gen_rtx (CONST_INT, VOIDmode,
  1528.                    INTVAL (XEXP (x, 1))
  1529.                    + INTVAL (XEXP (to, 1))));
  1530.     }
  1531.       break;
  1532.  
  1533.     case LSHIFT:
  1534.     case ASHIFT:
  1535. #ifdef SHIFT_COUNT_TRUNCATED
  1536.       /* (lshift <X> (sign_extend <Y>)) = (lshift <X> <Y>) (most machines).
  1537.      True for all kinds of shifts and also for zero_extend.  */
  1538.       if (was_replaced[1]
  1539.       && (GET_CODE (to) == SIGN_EXTEND
  1540.           || GET_CODE (to) == ZERO_EXTEND)
  1541.       && GET_CODE (to) == REG)
  1542.     {
  1543.       if (!undobuf.storage)
  1544.         undobuf.storage = (char *) oballoc (0);
  1545.       SUBST (XEXP (x, 1), gen_rtx (SUBREG, GET_MODE (to), XEXP (to, 0), 0));
  1546.     }
  1547. #endif
  1548.       /* (lshift (and (lshiftrt <foo> <X>) <Y>) <X>)
  1549.      happens copying between bit fields in similar structures.
  1550.      It can be replaced by one and instruction.
  1551.      It does not matter whether the shifts are logical or arithmetic.  */
  1552.       if (GET_CODE (XEXP (x, 0)) == AND
  1553.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  1554.       && INTVAL (XEXP (x, 1)) > 0
  1555.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  1556.       && XEXP (XEXP (x, 0), 0) == to
  1557.       && (GET_CODE (to) == LSHIFTRT
  1558.           || GET_CODE (to) == ASHIFTRT)
  1559. #if 0
  1560. /* I now believe this restriction is unnecessary.
  1561.    The outer shift will discard those bits in any case, right?  */
  1562.  
  1563.           /* If inner shift is arithmetic, either it shifts left or
  1564.          the bits it shifts the sign into are zeroed by the and.  */
  1565.           && (INTVAL (XEXP (x, 1)) < 0
  1566.               || ((unsigned) INTVAL (XEXP (XEXP (x, 0), 1))
  1567.               < 1 << (GET_MODE_BITSIZE (GET_MODE (x))
  1568.                   - INTVAL (XEXP (x, 0)))))
  1569. #endif
  1570.       && GET_CODE (XEXP (to, 1)) == CONST_INT
  1571.       && INTVAL (XEXP (x, 1)) == INTVAL (XEXP (to, 1)))
  1572.     {
  1573.       if (!undobuf.storage)
  1574.         undobuf.storage = (char *) oballoc (0);
  1575.       /* The constant in the new `and' is <Y> << <X>
  1576.          but clear out all bits that don't belong in our mode.  */
  1577.       return gen_rtx (AND, GET_MODE (x), XEXP (to, 0),
  1578.               gen_rtx (CONST_INT, VOIDmode,
  1579.                    (GET_MODE_MASK (GET_MODE (x))
  1580.                     & ((GET_MODE_MASK (GET_MODE (x))
  1581.                     & INTVAL (XEXP (XEXP (x, 0), 1)))
  1582.                        << INTVAL (XEXP (x, 1))))));
  1583.     } 
  1584.       /* Two shifts in a row in same direction with constant counts
  1585.      may be combined.  */
  1586.       if (was_replaced[0]
  1587.       && (GET_CODE (to) == ASHIFT || GET_CODE (to) == LSHIFT)
  1588.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  1589.       && GET_CODE (XEXP (to, 1)) == CONST_INT
  1590.       && INTVAL (XEXP (to, 1)) > 0
  1591.       && INTVAL (XEXP (x, 1)) > 0
  1592.       && (INTVAL (XEXP (x, 1)) + INTVAL (XEXP (to, 1))
  1593.           < GET_MODE_BITSIZE (GET_MODE (x))))
  1594.     {
  1595.       if (!undobuf.storage)
  1596.         undobuf.storage = (char *) oballoc (0);
  1597.       return gen_rtx (GET_CODE (x), GET_MODE (x),
  1598.               XEXP (to, 0),
  1599.               gen_rtx (CONST_INT, VOIDmode,
  1600.                    INTVAL (XEXP (x, 1))
  1601.                    + INTVAL (XEXP (to, 1))));
  1602.     }
  1603.       /* (ashift (ashiftrt <foo> <X>) <X>)
  1604.      (or, on some machines, (ashift (ashift <foo> <-X>) <X>) instead)
  1605.      happens if you divide by 2**N and then multiply by 2**N.
  1606.      It can be replaced by one `and' instruction.
  1607.      It does not matter whether the shifts are logical or arithmetic.  */
  1608.       if (GET_CODE (XEXP (x, 1)) == CONST_INT
  1609.       && INTVAL (XEXP (x, 1)) > 0
  1610.       && was_replaced[0]
  1611.       && (((GET_CODE (to) == LSHIFTRT || GET_CODE (to) == ASHIFTRT)
  1612.            && GET_CODE (XEXP (to, 1)) == CONST_INT
  1613.            && INTVAL (XEXP (x, 1)) == INTVAL (XEXP (to, 1)))
  1614.           ||
  1615.           ((GET_CODE (to) == LSHIFT || GET_CODE (to) == ASHIFT)
  1616.            && GET_CODE (XEXP (to, 1)) == CONST_INT
  1617.            && INTVAL (XEXP (x, 1)) == - INTVAL (XEXP (to, 1)))))
  1618.     {
  1619.       if (!undobuf.storage)
  1620.         undobuf.storage = (char *) oballoc (0);
  1621.       /* The constant in the new `and' is -1 << <X>
  1622.          but clear out all bits that don't belong in our mode.  */
  1623.       return gen_rtx (AND, GET_MODE (x), XEXP (to, 0),
  1624.               gen_rtx (CONST_INT, VOIDmode,
  1625.                    (GET_MODE_MASK (GET_MODE (x))
  1626.                     & (GET_MODE_MASK (GET_MODE (x))
  1627.                        << INTVAL (XEXP (x, 1))))));
  1628.     } 
  1629.  
  1630.     }
  1631.  
  1632.   return x;
  1633. }
  1634.  
  1635. /* This is the AND case of the function subst.  */
  1636.  
  1637. static rtx
  1638. simplify_and_const_int (x, to)
  1639.      rtx x, to;
  1640. {
  1641.   register rtx varop = XEXP (x, 0);
  1642.   register int constop = INTVAL (XEXP (x, 1));
  1643.  
  1644.   /* (and (subreg (and <foo> <constant>) 0) <constant>)
  1645.      results from an andsi followed by an andqi,
  1646.      which happens frequently when storing bit-fields
  1647.      on something whose result comes from an andsi.  */
  1648.   if (GET_CODE (varop) == SUBREG
  1649.       && XEXP (varop, 0) == to
  1650.       && subreg_lowpart_p (varop)
  1651.       && GET_CODE (to) == AND
  1652.       && GET_CODE (XEXP (to, 1)) == CONST_INT
  1653.       /* Verify that the result of the outer `and'
  1654.      is not affected by any bits not defined in the inner `and'.
  1655.      True if the outer mode is narrower, or if the outer constant
  1656.      masks to zero all the bits that the inner mode doesn't have.  */
  1657.       && (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (GET_MODE (to))
  1658.       || (constop & ~ GET_MODE_MASK (GET_MODE (to))) == 0))
  1659.     {
  1660.       if (!undobuf.storage)
  1661.     undobuf.storage = (char *) oballoc (0);
  1662.       return gen_rtx (AND, GET_MODE (x),
  1663.               gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
  1664.               gen_rtx (CONST_INT, VOIDmode,
  1665.                    constop
  1666.                    /* Remember that the bits outside that mode
  1667.                   are not being changed, so the effect
  1668.                   is as if they were all 1.  */
  1669.                    & INTVAL (XEXP (to, 1))));
  1670.     } 
  1671.   /* (and:SI (zero_extract:SI ...) <constant>)
  1672.      results from an andsi following a byte-fetch on risc machines.
  1673.      When the constant includes all bits extracted, eliminate the `and'.  */
  1674.   if (GET_CODE (varop) == ZERO_EXTRACT
  1675.       && GET_CODE (XEXP (varop, 1)) == CONST_INT
  1676.       /* The `and' must not clear any bits that the extract can give.  */
  1677.       && (~ constop & ((1 << INTVAL (XEXP (varop, 1))) - 1)) == 0)
  1678.     return varop;
  1679.   /* (and (zero_extend <foo>) <constant>)
  1680.      often results from storing in a bit-field something
  1681.      that was calculated as a short.  Replace with a single `and'
  1682.      in whose constant all bits not in <foo>'s mode are zero.  */
  1683.   if (varop == to
  1684.       && GET_CODE (to) == ZERO_EXTEND
  1685.       && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0)))
  1686.     {
  1687.       if (!undobuf.storage)
  1688.     undobuf.storage = (char *) oballoc (0);
  1689.       return gen_rtx (AND, GET_MODE (x),
  1690.               /* This is a perverse SUBREG, wider than its base.  */
  1691.               gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
  1692.               gen_rtx (CONST_INT, VOIDmode,
  1693.                    constop & GET_MODE_MASK (GET_MODE (XEXP (to, 0)))));
  1694.     }
  1695.   /* (and (sign_extend <foo>) <constant>)
  1696.      can be replaced with (and (subreg <foo>) <constant>)
  1697.      if <constant> is narrower than <foo>'s mode,
  1698.      or with (zero_extend <foo>) if <constant> is a mask for that mode.  */
  1699.   if (varop == to
  1700.       && GET_CODE (to) == SIGN_EXTEND
  1701.       && ((unsigned) constop <= GET_MODE_MASK (GET_MODE (XEXP (to, 0))))
  1702.       && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0)))
  1703.     {
  1704.       if (!undobuf.storage)
  1705.     undobuf.storage = (char *) oballoc (0);
  1706.       if (constop == GET_MODE_MASK (GET_MODE (XEXP (to, 0))))
  1707.     return gen_rtx (ZERO_EXTEND, GET_MODE (x), XEXP (to, 0));
  1708.       return gen_rtx (AND, GET_MODE (x),
  1709.               /* This is a perverse SUBREG, wider than its base.  */
  1710.               gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
  1711.               XEXP (x, 1));
  1712.     }
  1713.   /* (and (and <foo> <constant>) <constant>)
  1714.      comes from two and instructions in a row.  */
  1715.   if (varop == to
  1716.       && GET_CODE (to) == AND
  1717.       && GET_CODE (XEXP (to, 1)) == CONST_INT)
  1718.     {
  1719.       if (!undobuf.storage)
  1720.     undobuf.storage = (char *) oballoc (0);
  1721.       return gen_rtx (AND, GET_MODE (x),
  1722.               XEXP (to, 0),
  1723.               gen_rtx (CONST_INT, VOIDmode,
  1724.                    constop
  1725.                    & INTVAL (XEXP (to, 1))));
  1726.     }
  1727.   /* (and (ashiftrt (ashift FOO N) N) CONST)
  1728.      may be simplified to (and FOO CONST) if CONST masks off the bits
  1729.      changed by the two shifts.  */
  1730.   if (GET_CODE (varop) == ASHIFTRT
  1731.       && GET_CODE (XEXP (varop, 1)) == CONST_INT
  1732.       && XEXP (varop, 0) == to
  1733.       && GET_CODE (to) == ASHIFT
  1734.       && GET_CODE (XEXP (to, 1)) == CONST_INT
  1735.       && INTVAL (XEXP (varop, 1)) == INTVAL (XEXP (to, 1))
  1736.       && ((unsigned) constop >> INTVAL (XEXP (varop, 1))) == 0)
  1737.     {
  1738.       if (!undobuf.storage)
  1739.     undobuf.storage = (char *) oballoc (0);
  1740.       /* If CONST is a mask for the low byte,
  1741.      change this into a zero-extend instruction
  1742.      from just the low byte of FOO.  */
  1743.       if (constop == GET_MODE_MASK (QImode))
  1744.     {
  1745.       rtx temp = gen_lowpart_for_combine (QImode, XEXP (to, 0));
  1746.       if (GET_CODE (temp) != CLOBBER)
  1747.         return gen_rtx (ZERO_EXTEND, GET_MODE (x), temp);
  1748.     }
  1749.       return gen_rtx (AND, GET_MODE (x),
  1750.               XEXP (to, 0), XEXP (x, 1));
  1751.     }
  1752.   /* (and x const) may be converted to (zero_extend (subreg x 0)).  */
  1753.   if (constop == GET_MODE_MASK (QImode)
  1754.       && GET_CODE (varop) == REG)
  1755.     {
  1756.       if (!undobuf.storage)
  1757.     undobuf.storage = (char *) oballoc (0);
  1758.       return gen_rtx (ZERO_EXTEND, GET_MODE (x),
  1759.               gen_rtx (SUBREG, QImode, varop, 0));
  1760.     }
  1761.   if (constop == GET_MODE_MASK (HImode)
  1762.       && GET_CODE (varop) == REG)
  1763.     {
  1764.       if (!undobuf.storage)
  1765.     undobuf.storage = (char *) oballoc (0);
  1766.       return gen_rtx (ZERO_EXTEND, GET_MODE (x),
  1767.               gen_rtx (SUBREG, HImode, varop, 0));
  1768.     }
  1769.   /* No simplification applies.  */
  1770.   return 0;
  1771. }
  1772.  
  1773. /* Like gen_lowpart but for use by combine.  In combine it is not possible
  1774.    to create any new pseudoregs.  However, it is safe to create
  1775.    invalid memory addresses, because combine will try to recognize
  1776.    them and all they will do is make the combine attempt fail.
  1777.  
  1778.    If for some reason this cannot do its job, an rtx
  1779.    (clobber (const_int 0)) is returned.
  1780.    An insn containing that will not be recognized.  */
  1781.  
  1782. #undef gen_lowpart
  1783.  
  1784. static rtx
  1785. gen_lowpart_for_combine (mode, x)
  1786.      enum machine_mode mode;
  1787.      register rtx x;
  1788. {
  1789.   if (GET_CODE (x) == SUBREG || GET_CODE (x) == REG)
  1790.     return gen_lowpart (mode, x);
  1791.   if (GET_MODE (x) == mode)
  1792.     return gen_rtx (CLOBBER, VOIDmode, const0_rtx);
  1793.   if (GET_CODE (x) == MEM)
  1794.     {
  1795.       register int offset = 0;
  1796.  
  1797.       /* Refuse to work on a volatile memory ref.  */
  1798.       if (MEM_VOLATILE_P (x))
  1799.     return gen_rtx (CLOBBER, VOIDmode, const0_rtx);
  1800.  
  1801.       /* If we want to refer to something bigger than the original memref,
  1802.      generate a perverse subreg instead.  That will force a reload
  1803.      of the original memref X.  */
  1804.       if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode))
  1805.     return gen_rtx (SUBREG, mode, x, 0);
  1806.  
  1807. #ifdef WORDS_BIG_ENDIAN
  1808.       offset = (max (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
  1809.         - max (GET_MODE_SIZE (mode), UNITS_PER_WORD));
  1810. #endif
  1811. #ifdef BYTES_BIG_ENDIAN
  1812.       /* Adjust the address so that the address-after-the-data
  1813.      is unchanged.  */
  1814.       offset -= (min (UNITS_PER_WORD, GET_MODE_SIZE (mode))
  1815.          - min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
  1816. #endif
  1817.       return gen_rtx (MEM, mode, plus_constant (XEXP (x, 0),
  1818.                         offset));
  1819.     }
  1820.   else
  1821.     return gen_rtx (CLOBBER, VOIDmode, const0_rtx);
  1822. }
  1823.  
  1824. /* After substitution, if the resulting pattern looks like
  1825.    (set (cc0) (and ...)) or (set (cc0) (lshiftrt ...)),
  1826.    this function is called to simplify the
  1827.    pattern into a bit-field operation if possible.  */
  1828.  
  1829. static void
  1830. simplify_set_cc0_and (insn)
  1831.      rtx insn;
  1832. {
  1833.   register rtx value = XEXP (PATTERN (insn), 1);
  1834.   register rtx op0 = XEXP (value, 0);
  1835.   register rtx op1 = XEXP (value, 1);
  1836.   int offset = 0;
  1837.   rtx var = 0;
  1838.   rtx bitnum = 0;
  1839.   int temp;
  1840.   int unit;
  1841.   rtx newpat;
  1842.  
  1843.   if (GET_CODE (value) == AND)
  1844.     {
  1845.       op0 = XEXP (value, 0);
  1846.       op1 = XEXP (value, 1);
  1847.     }
  1848.   else if (GET_CODE (value) == LSHIFTRT)
  1849.     {
  1850.       /* If there is no AND, but there is a shift that discards
  1851.      all but the sign bit, we can pretend that the shift result
  1852.      is ANDed with 1.  Otherwise we cannot handle just a shift.  */
  1853.       if (GET_CODE (XEXP (value, 1)) == CONST_INT
  1854.       && (INTVAL (XEXP (value, 1))
  1855.           == GET_MODE_BITSIZE (GET_MODE (value)) - 1))
  1856.     {
  1857.       op0 = value;
  1858.       op1 = const1_rtx;
  1859.     }
  1860.       else
  1861.     return;
  1862.     }
  1863.   else
  1864.     abort ();
  1865.  
  1866.   /* Look for a constant power of 2 or a shifted 1
  1867.      on either side of the AND.  Set VAR to the other side.
  1868.      Set BITNUM to the shift count of the 1 (as an rtx).
  1869.      Or, if bit number is constant, set OFFSET to the bit number.  */
  1870.  
  1871.   switch (GET_CODE (op0))
  1872.     {
  1873.     case CONST_INT:
  1874.       temp = exact_log2 (INTVAL (op0));
  1875.       if (temp < 0)
  1876.     return;
  1877.       offset = temp;
  1878.       var = op1;
  1879.       break;
  1880.  
  1881.     case ASHIFT:
  1882.     case LSHIFT:
  1883.       if (XEXP (op0, 0) == const1_rtx)
  1884.     {
  1885.       bitnum = XEXP (op0, 1);
  1886.       var = op1;
  1887.     }
  1888.     }
  1889.   if (var == 0)
  1890.     switch (GET_CODE (op1))
  1891.       {
  1892.       case CONST_INT:
  1893.     temp = exact_log2 (INTVAL (op1));
  1894.     if (temp < 0)
  1895.       return;
  1896.     offset = temp;
  1897.     var = op0;
  1898.     break;
  1899.  
  1900.       case ASHIFT:
  1901.       case LSHIFT:
  1902.     if (XEXP (op1, 0) == const1_rtx)
  1903.       {
  1904.         bitnum = XEXP (op1, 1);
  1905.         var = op0;
  1906.       }
  1907.       }
  1908.  
  1909.   /* If VAR is 0, we didn't find something recognizable.  */
  1910.   if (var == 0)
  1911.     return;
  1912.  
  1913.   if (!undobuf.storage)
  1914.     undobuf.storage = (char *) oballoc (0);
  1915.  
  1916.   /* If the bit position is currently exactly 0,
  1917.      extract a right-shift from the variable portion.  */
  1918.   if (offset == 0
  1919.       && (GET_CODE (var) == ASHIFTRT || GET_CODE (var) == LSHIFTRT))
  1920.     {
  1921.       bitnum = XEXP (var, 1);
  1922.       var = XEXP (var, 0);
  1923.     }
  1924.  
  1925.   if (GET_CODE (var) == SUBREG && SUBREG_WORD (var) == 0)
  1926.     var = SUBREG_REG (var);
  1927.  
  1928.   /* Note that BITNUM and OFFSET are always little-endian thru here
  1929.      even on a big-endian machine.  */
  1930.  
  1931. #ifdef BITS_BIG_ENDIAN
  1932.   unit = GET_MODE_BITSIZE (GET_MODE (var)) - 1;
  1933.  
  1934.   if (bitnum != 0)
  1935.     bitnum = gen_rtx (MINUS, SImode,
  1936.               gen_rtx (CONST_INT, VOIDmode, unit), bitnum);
  1937.   else
  1938.     offset = unit - offset;
  1939. #endif
  1940.  
  1941.   if (bitnum == 0)
  1942.     bitnum = gen_rtx (CONST_INT, VOIDmode, offset);
  1943.  
  1944.   newpat = gen_rtx (SET, VOIDmode, cc0_rtx,
  1945.             gen_rtx (ZERO_EXTRACT, VOIDmode, var, const1_rtx, bitnum));
  1946.   if (recog (newpat, insn) >= 0)
  1947.     {
  1948.       if (undobuf.num_undo < MAX_UNDO)
  1949.     {
  1950.       undobuf.undo[undobuf.num_undo].where = &XEXP (PATTERN (insn), 1);
  1951.       undobuf.undo[undobuf.num_undo].old_contents = value;
  1952.       XEXP (PATTERN (insn), 1) = XEXP (newpat, 1);
  1953.     }
  1954.       undobuf.num_undo++;
  1955.     }
  1956. }
  1957.  
  1958. /* Update the records of when each REG was most recently set or killed
  1959.    for the things done by INSN.  This is the last thing done in processing
  1960.    INSN in the combiner loop.
  1961.  
  1962.    We update reg_last_set, reg_last_death, and also the similar information
  1963.    mem_last_set (which insn most recently modified memory)
  1964.    and last_call_cuid (which insn was the most recent subroutine call).  */
  1965.  
  1966. static void
  1967. record_dead_and_set_regs (insn)
  1968.      rtx insn;
  1969. {
  1970.   register rtx link;
  1971.   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  1972.     {
  1973.       if (REG_NOTE_KIND (link) == REG_DEAD)
  1974.     reg_last_death[REGNO (XEXP (link, 0))] = insn;
  1975.       else if (REG_NOTE_KIND (link) == REG_INC)
  1976.     reg_last_set[REGNO (XEXP (link, 0))] = insn;
  1977.     }
  1978.  
  1979.   if (GET_CODE (insn) == CALL_INSN)
  1980.     last_call_cuid = mem_last_set = INSN_CUID (insn);
  1981.  
  1982.   if (GET_CODE (PATTERN (insn)) == PARALLEL)
  1983.     {
  1984.       register int i;
  1985.       for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
  1986.     {
  1987.       register rtx elt = XVECEXP (PATTERN (insn), 0, i);
  1988.       register enum rtx_code code = GET_CODE (elt);
  1989.       if (code == SET || code == CLOBBER)
  1990.         {
  1991.           if (GET_CODE (XEXP (elt, 0)) == REG)
  1992.         reg_last_set[REGNO (XEXP (elt, 0))] = insn;
  1993.           if (GET_CODE (XEXP (elt, 0)) == SUBREG
  1994.           && GET_CODE (SUBREG_REG (XEXP (elt, 0))) == REG)
  1995.         reg_last_set[REGNO (SUBREG_REG (XEXP (elt, 0)))] = insn;
  1996.           else if (GET_CODE (XEXP (elt, 0)) == MEM)
  1997.         mem_last_set = INSN_CUID (insn);
  1998.         }
  1999.     }
  2000.     }
  2001.   else if (GET_CODE (PATTERN (insn)) == SET
  2002.        || GET_CODE (PATTERN (insn)) == CLOBBER)
  2003.     {
  2004.       register rtx x = XEXP (PATTERN (insn), 0);
  2005.       if (GET_CODE (x) == REG)
  2006.     reg_last_set[REGNO (x)] = insn;
  2007.       if (GET_CODE (x) == SUBREG
  2008.       && GET_CODE (SUBREG_REG (x)) == REG)
  2009.     reg_last_set[REGNO (SUBREG_REG (x))] = insn;
  2010.       else if (GET_CODE (x) == MEM)
  2011.     mem_last_set = INSN_CUID (insn);
  2012.     }
  2013. }
  2014.  
  2015. /* Return nonzero if expression X refers to a REG or to memory
  2016.    that is set in an instruction more recent than FROM_CUID.  */
  2017.  
  2018. static int
  2019. use_crosses_set_p (x, from_cuid)
  2020.      register rtx x;
  2021.      int from_cuid;
  2022. {
  2023.   register char *fmt;
  2024.   register int i;
  2025.   register enum rtx_code code = GET_CODE (x);
  2026.  
  2027.   if (code == REG)
  2028.     {
  2029.       register int regno = REGNO (x);
  2030. #ifdef PUSH_ROUNDING
  2031.       /* Don't allow uses of the stack pointer to be moved,
  2032.      because we don't know whether the move crosses a push insn.  */
  2033.       if (regno == STACK_POINTER_REGNUM)
  2034.     return 1;
  2035. #endif
  2036.       return (reg_last_set[regno]
  2037.           && INSN_CUID (reg_last_set[regno]) > from_cuid);
  2038.     }
  2039.  
  2040.   if (code == MEM && mem_last_set > from_cuid)
  2041.     return 1;
  2042.  
  2043.   fmt = GET_RTX_FORMAT (code);
  2044.  
  2045.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2046.     {
  2047.       if (fmt[i] == 'E')
  2048.     {
  2049.       register int j;
  2050.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2051.         if (use_crosses_set_p (XVECEXP (x, i, j), from_cuid))
  2052.           return 1;
  2053.     }
  2054.       else if (fmt[i] == 'e'
  2055.            && use_crosses_set_p (XEXP (x, i), from_cuid))
  2056.     return 1;
  2057.     }
  2058.   return 0;
  2059. }
  2060.  
  2061. /* Return nonzero if reg REGNO is marked as dying in INSN.  */
  2062.  
  2063. int
  2064. regno_dead_p (regno, insn)
  2065.      int regno;
  2066.      rtx insn;
  2067. {
  2068.   register rtx link;
  2069.  
  2070.   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  2071.     if ((REG_NOTE_KIND (link) == REG_DEAD
  2072.      || REG_NOTE_KIND (link) == REG_INC)
  2073.     && REGNO (XEXP (link, 0)) == regno)
  2074.       return 1;
  2075.  
  2076.   return 0;
  2077. }
  2078.  
  2079. /* Return nonzero if J is the first insn following I,
  2080.    not counting labels, line numbers, etc.
  2081.    We assume that J follows I.  */
  2082.  
  2083. static int
  2084. adjacent_insns_p (i, j)
  2085.      rtx i, j;
  2086. {
  2087.   register rtx insn;
  2088.   for (insn = NEXT_INSN (i); insn != j; insn = NEXT_INSN (insn))
  2089.     if (GET_CODE (insn) == INSN
  2090.     || GET_CODE (insn) == CALL_INSN
  2091.     || GET_CODE (insn) == JUMP_INSN)
  2092.       return 0;
  2093.   return 1;
  2094. }
  2095.  
  2096. /* Check that X is an insn-body for an `asm' with operands
  2097.    and that the operands mentioned in it are legitimate.  */
  2098.  
  2099. static int
  2100. check_asm_operands (x)
  2101.      rtx x;
  2102. {
  2103.   int noperands = asm_noperands (x);
  2104.   rtx *operands;
  2105.   int i;
  2106.  
  2107.   if (noperands < 0)
  2108.     return 0;
  2109.   if (noperands == 0)
  2110.     return 1;
  2111.  
  2112.   operands = (rtx *) alloca (noperands * sizeof (rtx));
  2113.   decode_asm_operands (x, operands, 0, 0, 0);
  2114.  
  2115.   for (i = 0; i < noperands; i++)
  2116.     if (!general_operand (operands[i], VOIDmode))
  2117.       return 0;
  2118.  
  2119.   return 1;
  2120. }
  2121.  
  2122. /* Concatenate the list of logical links of OINSN
  2123.    into INSN's list of logical links.
  2124.    Modifies OINSN destructively.
  2125.  
  2126.    If ALL_LINKS is nonzero, move all the links that OINSN has.
  2127.    Otherwise, move only those that point to insns that set regs
  2128.    that die in the insn OINSN.
  2129.    Other links are clobbered so that they are no longer effective.  */
  2130.  
  2131. static void
  2132. add_links (insn, oinsn, all_links)
  2133.      rtx insn, oinsn;
  2134.      int all_links;
  2135. {
  2136.   register rtx links = LOG_LINKS (oinsn);
  2137.   if (! all_links)
  2138.     {
  2139.       rtx tail;
  2140.       for (tail = links; tail; tail = XEXP (tail, 1))
  2141.     {
  2142.       rtx target = XEXP (tail, 0);
  2143.       if (GET_CODE (target) != INSN
  2144.           || GET_CODE (PATTERN (target)) != SET
  2145.           || GET_CODE (SET_DEST (PATTERN (target))) != REG
  2146.           || ! dead_or_set_p (oinsn, SET_DEST (PATTERN (target))))
  2147.         /* OINSN is going to become a NOTE 
  2148.            so a link pointing there will have no effect.  */
  2149.         XEXP (tail, 0) = oinsn;
  2150.     }
  2151.     }
  2152.   if (LOG_LINKS (insn) == 0)
  2153.     LOG_LINKS (insn) = links;
  2154.   else
  2155.     {
  2156.       register rtx next, prev = LOG_LINKS (insn);
  2157.       while (next = XEXP (prev, 1))
  2158.     prev = next;
  2159.       XEXP (prev, 1) = links;
  2160.     }
  2161. }
  2162.   
  2163. /* Delete any LOG_LINKS of INSN which point at OINSN.  */
  2164.  
  2165. static void
  2166. remove_links (insn, oinsn)
  2167.      rtx insn, oinsn;
  2168. {
  2169.   register rtx next = LOG_LINKS (insn), prev = 0;
  2170.   while (next)
  2171.     {
  2172.       if (XEXP (next, 0) == oinsn)
  2173.     {
  2174.       if (prev)
  2175.         XEXP (prev, 1) = XEXP (next, 1);
  2176.       else
  2177.         LOG_LINKS (insn) = XEXP (next, 1);
  2178.     }
  2179.       else
  2180.     prev = next;
  2181.       next = XEXP (next, 1);
  2182.     }
  2183. }
  2184.  
  2185. /* Concatenate the any elements of the list of reg-notes INCS
  2186.    which are of type REG_INC
  2187.    into INSN's list of reg-notes.  */
  2188.  
  2189. static void
  2190. add_incs (insn, incs)
  2191.      rtx insn, incs;
  2192. {
  2193.   register rtx tail;
  2194.  
  2195.   for (tail = incs; tail; tail = XEXP (tail, 1))
  2196.     if (REG_NOTE_KIND (tail) == REG_INC)
  2197.       REG_NOTES (insn)
  2198.     = gen_rtx (EXPR_LIST, REG_INC, XEXP (tail, 0), REG_NOTES (insn));
  2199. }
  2200.  
  2201. /* Remove register number REGNO from the dead registers list of INSN.  */
  2202.  
  2203. void
  2204. remove_death (regno, insn)
  2205.      int regno;
  2206.      rtx insn;
  2207. {
  2208.   register rtx link, next;
  2209.   while ((link = REG_NOTES (insn))
  2210.      && REG_NOTE_KIND (link) == REG_DEAD
  2211.      && REGNO (XEXP (link, 0)) == regno)
  2212.     REG_NOTES (insn) = XEXP (link, 1);
  2213.  
  2214.   if (link)
  2215.     while (next = XEXP (link, 1))
  2216.       {
  2217.     if (REG_NOTE_KIND (next) == REG_DEAD
  2218.         && REGNO (XEXP (next, 0)) == regno)
  2219.       XEXP (link, 1) = XEXP (next, 1);
  2220.     else
  2221.       link = next;
  2222.       }
  2223. }
  2224.  
  2225. /* For each register (hardware or pseudo) used within expression X,
  2226.    if its death is in an instruction with cuid
  2227.    between FROM_CUID (inclusive) and TO_INSN (exclusive),
  2228.    mark it as dead in TO_INSN instead.
  2229.  
  2230.    This is done when X is being merged by combination into TO_INSN.  */
  2231.  
  2232. static void
  2233. move_deaths (x, from_cuid, to_insn)
  2234.      rtx x;
  2235.      int from_cuid;
  2236.      rtx to_insn;
  2237. {
  2238.   register char *fmt;
  2239.   register int len, i;
  2240.   register enum rtx_code code = GET_CODE (x);
  2241.  
  2242.   if (code == REG)
  2243.     {
  2244.       register rtx where_dead = reg_last_death[REGNO (x)];
  2245.  
  2246.       if (where_dead && INSN_CUID (where_dead) >= from_cuid
  2247.       && INSN_CUID (where_dead) < INSN_CUID (to_insn))
  2248.     {
  2249.       remove_death (REGNO (x), reg_last_death[REGNO (x)]);
  2250.       if (! dead_or_set_p (to_insn, x))
  2251.         REG_NOTES (to_insn)
  2252.           = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (to_insn));
  2253.     }
  2254.       return;
  2255.     }
  2256.  
  2257.   len = GET_RTX_LENGTH (code);
  2258.   fmt = GET_RTX_FORMAT (code);
  2259.  
  2260.   for (i = 0; i < len; i++)
  2261.     {
  2262.       if (fmt[i] == 'E')
  2263.     {
  2264.       register int j;
  2265.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2266.         move_deaths (XVECEXP (x, i, j), from_cuid, to_insn);
  2267.     }
  2268.       else if (fmt[i] == 'e')
  2269.     move_deaths (XEXP (x, i), from_cuid, to_insn);
  2270.     }
  2271. }
  2272.  
  2273. /* Like move_deaths, but deaths are moving both forward
  2274.    (from FROM_CUID to TO_INSN), and backwards
  2275.    (from FROM_INSN to TO_INSN).  This is what happens
  2276.    when an insn is removed after applying the distributive law.  */
  2277.  
  2278. static void
  2279. move_deaths_2 (x, from_cuid, from_insn, to_insn)
  2280.      rtx x;
  2281.      int from_cuid;
  2282.      rtx from_insn, to_insn;
  2283. {
  2284.   register char *fmt;
  2285.   register int len, i;
  2286.   register enum rtx_code code = GET_CODE (x);
  2287.  
  2288.   if (code == REG)
  2289.     {
  2290.       register rtx where_dead = reg_last_death[REGNO (x)];
  2291.  
  2292.       if (where_dead && INSN_CUID (where_dead) >= from_cuid
  2293.       && INSN_CUID (where_dead) < INSN_CUID (to_insn))
  2294.     {
  2295.       remove_death (REGNO (x), reg_last_death[REGNO (x)]);
  2296.       if (! dead_or_set_p (to_insn, x))
  2297.         REG_NOTES (to_insn)
  2298.           = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (to_insn));
  2299.     }
  2300.       /* Can't use where_dead for from_insn because it has
  2301.      not been computed yet.  */
  2302.       else if (dead_or_set_p (from_insn, x))
  2303.     {
  2304.       remove_death (REGNO (x), from_insn);
  2305.       if (! dead_or_set_p (to_insn, x))
  2306.         REG_NOTES (to_insn)
  2307.           = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (to_insn));
  2308.     }
  2309.       return;
  2310.     }
  2311.  
  2312.   len = GET_RTX_LENGTH (code);
  2313.   fmt = GET_RTX_FORMAT (code);
  2314.  
  2315.   for (i = 0; i < len; i++)
  2316.     {
  2317.       if (fmt[i] == 'E')
  2318.     {
  2319.       register int j;
  2320.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2321.         move_deaths_2 (XVECEXP (x, i, j), from_cuid, from_insn, to_insn);
  2322.     }
  2323.       else if (fmt[i] == 'e')
  2324.     move_deaths_2 (XEXP (x, i), from_cuid, from_insn, to_insn);
  2325.     }
  2326. }
  2327.  
  2328. /* The distrib combiner rewrites groups of insns so that optimizations
  2329.    can be more easily recognized.  The front-end does not know how to
  2330.    group certain kinds of operations for efficient execution, and the
  2331.    resulting code can be quite poor.  For example, on a machine without
  2332.    bitfield instructions, bitfield references look like
  2333.  
  2334.     (and (lshiftrt ... n) m)
  2335.  
  2336.    When combining two bitfield operations, such as with ||, this can
  2337.    yield code like
  2338.  
  2339.     (set z
  2340.          (or (and (lshiftrt x n) 1)
  2341.          (and (lshiftrt y n) 1)))
  2342.  
  2343.    which can be more efficiently executed as
  2344.  
  2345.     (set z
  2346.          (lshiftrt (and (or x y)
  2347.                 (1 << m)) n))
  2348.  
  2349.    From there, the combiner attempts to rewrite the insns,
  2350.    keeping flow information accurate for later passes,
  2351.    and reducing the total number of insns executed.
  2352.  
  2353.    This function returns the point at which we should try
  2354.    looking for more simplifications.  This will be before
  2355.    INSN if the call succeeds.  We do not need to fear
  2356.    infinite loops, since this function is guaranteed to
  2357.    eliminate at least one (non-note) instruction if it returns
  2358.    successfully.  */
  2359.  
  2360. static rtx
  2361. try_distrib (insn, xprev1, xprev2)
  2362.      rtx insn, xprev1, xprev2;
  2363. {
  2364.   rtx pat = PATTERN (insn);
  2365.   rtx prev1, prev2, pat1, pat2, src1, src2;
  2366.   rtx to_prev, to_insn;
  2367.   enum rtx_code code;
  2368.   int insn_code_number, prev_code_number, regno;
  2369.   rtx new_insn_pat, new_prev_pat;
  2370.  
  2371.   distrib_attempts++;
  2372.  
  2373.   /* ??? Need to implement a test that PREV2 and PREV1
  2374.      are completely independent.  Right now their
  2375.      recognition ability is sufficiently limited that
  2376.      it should not be necessary, but better safe than sorry.  */
  2377.  
  2378.   /* Let PREV1 be the later of the two insns, and PREV2 the earlier.  */
  2379.   if (INSN_CUID (xprev1) > INSN_CUID (xprev2))
  2380.     {
  2381.       prev1 = xprev1;
  2382.       prev2 = xprev2;
  2383.     }
  2384.   else
  2385.     {
  2386.       prev1 = xprev2;
  2387.       prev2 = xprev1;
  2388.     }
  2389.  
  2390.   pat1 = PATTERN (prev1);
  2391.   pat2 = PATTERN (prev2);
  2392.  
  2393.   /* First, see if INSN, PREV1, and PREV2 have patterns we can expect
  2394.      to simplify.  */
  2395.  
  2396.   if (GET_CODE (pat) != SET
  2397.       || GET_CODE (pat1) != SET
  2398.       || GET_CODE (pat2) != SET)
  2399.     return 0;
  2400.  
  2401.   code = GET_CODE (SET_SRC (pat));
  2402.   src1 = SET_SRC (pat1);
  2403.   src2 = SET_SRC (pat2);
  2404.  
  2405.   if (GET_CODE (SET_DEST (pat1)) != REG
  2406.       || GET_CODE (SET_DEST (pat2)) != REG)
  2407.     return 0;
  2408.  
  2409.   switch (code)
  2410.     {
  2411.     default:
  2412.       return 0;
  2413.  
  2414.     case IOR:
  2415.     case AND:
  2416.     case XOR:
  2417.     case PLUS:
  2418.       ;
  2419.     }
  2420.  
  2421.   /* Insns PREV1 and PREV2 must provide the two operands of the arithmetic
  2422.      that is done in INSN.  */
  2423.   if (! ((XEXP (SET_SRC (pat), 0) == SET_DEST (pat1)
  2424.       && XEXP (SET_SRC (pat), 1) == SET_DEST (pat2))
  2425.      ||
  2426.      (XEXP (SET_SRC (pat), 0) == SET_DEST (pat2)
  2427.       && XEXP (SET_SRC (pat), 1) == SET_DEST (pat1))))
  2428.     return 0;
  2429.  
  2430.   /* They must not be used in any other way in INSN.
  2431.      In particular, they must not be used in a result memory address.  */
  2432.   if (reg_mentioned_p (SET_DEST (pat1), SET_DEST (pat))
  2433.       || reg_mentioned_p (SET_DEST (pat2), SET_DEST (pat)))
  2434.     return 0;
  2435.  
  2436.   /* Give up if the two operands' modes don't match.  */
  2437.   if (GET_MODE (src1) != GET_MODE (src2))
  2438.     return 0;
  2439.  
  2440.   /* PREV1 and PREV2 must compute the same operation.
  2441.      Actually, there are other cases that could be handled,
  2442.      but are not implemented.  For example:
  2443.  
  2444.      (set (reg:SI 94)
  2445.       (and:SI (reg:SI 73)
  2446.           (const_int 223)))
  2447.  
  2448.      (set (reg:SI 95)
  2449.       (zero_extend:SI (subreg:QI (reg:SI 91) 0)))
  2450.  
  2451.      (set (reg:SI 96)
  2452.       (ior:SI (reg:SI 94)
  2453.           (reg:SI 95)))
  2454.  
  2455.      In this case, we know that because (reg:SI 94) has
  2456.      been anded with 223, there is no need to zero_extend
  2457.      (reg:SI 91), and we could eliminate (reg:SI 95).  */
  2458.  
  2459.   if (GET_CODE (src1) != GET_CODE (src2))
  2460.     return 0;
  2461.  
  2462.   /* The SETs in PREV1 and PREV2 do not need to be kept around.  */
  2463.  
  2464.   undobuf.num_undo = 0;
  2465.   undobuf.storage = 0;
  2466.  
  2467.   /* Substitute in the latest insn for the regs set by the earlier ones.  */
  2468.   subst_insn = insn;
  2469.   n_occurrences = 0;    /* `subst' counts here */
  2470.  
  2471.   switch (GET_CODE (src1))
  2472.     {
  2473.     /* case XOR:  Does not distribute through anything!  */
  2474.     case LSHIFTRT:
  2475.     case ASHIFTRT:
  2476.       /* Right-shift can't distribute through addition
  2477.      since the round-off would happen differently.  */
  2478.     case AND:
  2479.     case IOR:
  2480.       /* Boolean ops don't distribute through addition.  */
  2481.       if (code == PLUS)
  2482.     return 0;
  2483.  
  2484.     case LSHIFT:
  2485.     case ASHIFT:
  2486.       /* Left shifts are multiplication; they distribute through
  2487.      addition.  Also, since they work bitwise, they
  2488.      distribute through boolean operations.  */
  2489.       goto do_distrib;
  2490.  
  2491.     case MULT:
  2492.       /* Multiplication distributes through addition only.  */
  2493.       if (code != PLUS)
  2494.     return 0;
  2495.  
  2496.     do_distrib:
  2497.       /* Try changing (+ (* x c) (* y c)) to (* (+ x y) c).  */
  2498.  
  2499.       if (GET_CODE (XEXP (src1, 1)) != CONST_INT
  2500.       || GET_CODE (XEXP (src2, 1)) != CONST_INT
  2501.       || INTVAL (XEXP (src1, 1)) != INTVAL (XEXP (src2, 1)))
  2502.     return 0;
  2503.       to_prev = gen_rtx (code, GET_MODE (src1),
  2504.              XEXP (src1, 0), XEXP (src2, 0));
  2505.       to_insn = gen_rtx (GET_CODE (src1), GET_MODE (src1), SET_DEST (pat1), XEXP (src1, 1));
  2506.       break;
  2507.  
  2508.     case ZERO_EXTEND:
  2509.     case SIGN_EXTEND:
  2510.       /* Extension can't distribute through addition;
  2511.      the carries could be changed.  */
  2512.       if (code == PLUS)
  2513.     return 0;
  2514.       {
  2515.     rtx inner1 = XEXP (src1, 0), inner2 = XEXP (src2, 0);
  2516.     int subreg_needed = 0;
  2517.  
  2518.     /* Try changing (+ (extend x) (extend y)) to (extend (+ x y)).  */
  2519.     /* But keep extend insns together with their subregs.  */
  2520.     if (GET_CODE (inner1) == SUBREG)
  2521.       if (SUBREG_WORD (inner1) != 0)
  2522.         return 0;
  2523.       else
  2524.         {
  2525.           subreg_needed = 1;
  2526.           inner1 = SUBREG_REG (inner1);
  2527.         }
  2528.  
  2529.     if (GET_CODE (inner2) == SUBREG)
  2530.       if (SUBREG_WORD (inner2) != 0)
  2531.         return 0;
  2532.       else
  2533.         {
  2534.           subreg_needed = 1;
  2535.           inner2 = SUBREG_REG (inner2);
  2536.         }
  2537.  
  2538.     to_prev = gen_rtx (code, GET_MODE (src1), inner1, inner2);
  2539.     to_insn = gen_rtx (GET_CODE (src1), GET_MODE (src1),
  2540.                subreg_needed
  2541.                ? gen_rtx (SUBREG, GET_MODE (XEXP (src1, 0)),
  2542.                       SET_DEST (pat1), 0)
  2543.                : SET_DEST (pat1));
  2544.       }
  2545.       break;
  2546.  
  2547.     default:
  2548.       return 0;
  2549.     }
  2550.  
  2551.   /* Are the results of this "substitution" a valid instruction?  */
  2552.  
  2553.   new_insn_pat = subst (PATTERN (insn), SET_SRC (PATTERN (insn)), to_insn);
  2554.   distrib_merges_1++;
  2555.  
  2556.   insn_code_number = recog (new_insn_pat, insn);
  2557.   if (insn_code_number < 0)
  2558.     {
  2559.       undo_all ();
  2560.       return 0;
  2561.     }
  2562.  
  2563.   subst_insn = prev1;
  2564.   new_prev_pat = subst (pat1, src1, to_prev);
  2565.   distrib_merges_2++;
  2566.  
  2567.   prev_code_number = recog (new_prev_pat, prev1);
  2568.   if (prev_code_number < 0)
  2569.     {
  2570.       undo_all ();
  2571.       return 0;
  2572.     }
  2573.  
  2574.   /* Everything worked; install the new patterns.  */
  2575.   INSN_CODE (insn) = insn_code_number;
  2576.   PATTERN (insn) = new_insn_pat;
  2577.  
  2578.   INSN_CODE (prev1) = prev_code_number;
  2579.   PATTERN (prev1) = new_prev_pat;
  2580.  
  2581.   /* Need to change LOG_LINKS around...PREV1 now gets
  2582.      whatever flowed into PREV2.  PREV2 is going to
  2583.      become a NOTE, so we clear out its LOG_LINKS.  */
  2584.   remove_links (insn, prev2);
  2585.   add_links (prev1, prev2, adjacent_insns_p (prev2, prev1));
  2586.  
  2587.   /* Registers which died in PREV2 now die in PREV1.
  2588.      Also, registers born in PREV2 dying in INSN now die in PREV1.  */
  2589.   move_deaths_2 (src2, INSN_CUID (prev2), insn, prev1);
  2590.  
  2591.   regno = REGNO (SET_DEST (pat2));
  2592.  
  2593.   reg_n_sets[regno]--;
  2594.   if (reg_n_sets[regno] == 0
  2595.       && ! (basic_block_live_at_start[0][regno / HOST_BITS_PER_INT]
  2596.         & (1 << (regno % HOST_BITS_PER_INT))))
  2597.     reg_n_refs[regno] = 0;
  2598.   remove_death (regno, insn);
  2599.  
  2600.   PUT_CODE (prev2, NOTE);
  2601.   NOTE_LINE_NUMBER (prev2) = NOTE_INSN_DELETED;
  2602.   NOTE_SOURCE_FILE (prev2) = 0;
  2603.  
  2604.   distrib_successes++;
  2605.   return prev1;
  2606. }
  2607.  
  2608. void
  2609. dump_combine_stats (file)
  2610.      char *file;
  2611. {
  2612.   fprintf
  2613.     (file,
  2614.      ";; Combiner statistics: %d attempts, %d substitutions (%d requiring new space),\n;; %d successes.\n\n",
  2615.      combine_attempts, combine_merges, combine_extras, combine_successes);
  2616.   fprintf
  2617.     (file,
  2618.      ";; Distributer statistics: %d attempts, %d:%d substitutions,\n;; %d successes.\n\n",
  2619.      distrib_attempts, distrib_merges_1,
  2620.      distrib_merges_2, distrib_successes);
  2621. }
  2622.  
  2623. void
  2624. dump_combine_total_stats (file)
  2625.      char *file;
  2626. {
  2627.   fprintf
  2628.     (file,
  2629.      "\n;; Combiner totals: %d attempts, %d substitutions (%d requiring new space),\n;; %d successes.\n",
  2630.      total_attempts, total_merges, total_extras, total_successes);
  2631.   fprintf
  2632.     (file,
  2633.      "\n;; Distributer totals: %d attempts, %d:%d substitutions,\n;; %d successes.\n",
  2634.      total_distrib_attempts, total_distrib_merges_1,
  2635.      total_distrib_merges_2, total_distrib_successes);
  2636. }
  2637.