efd4aca2e94be3f3d51e3ac01adc545ef7f9554c
[platform/upstream/gcc.git] / gcc / reload.c
1 /* Search an insn for pseudo regs that must be in hard regs and are not.
2    Copyright (C) 1987, 88, 89, 92-6, 1997 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21
22 /* This file contains subroutines used only from the file reload1.c.
23    It knows how to scan one insn for operands and values
24    that need to be copied into registers to make valid code.
25    It also finds other operands and values which are valid
26    but for which equivalent values in registers exist and
27    ought to be used instead.
28
29    Before processing the first insn of the function, call `init_reload'.
30
31    To scan an insn, call `find_reloads'.  This does two things:
32    1. sets up tables describing which values must be reloaded
33    for this insn, and what kind of hard regs they must be reloaded into;
34    2. optionally record the locations where those values appear in
35    the data, so they can be replaced properly later.
36    This is done only if the second arg to `find_reloads' is nonzero.
37
38    The third arg to `find_reloads' specifies the number of levels
39    of indirect addressing supported by the machine.  If it is zero,
40    indirect addressing is not valid.  If it is one, (MEM (REG n))
41    is valid even if (REG n) did not get a hard register; if it is two,
42    (MEM (MEM (REG n))) is also valid even if (REG n) did not get a
43    hard register, and similarly for higher values.
44
45    Then you must choose the hard regs to reload those pseudo regs into,
46    and generate appropriate load insns before this insn and perhaps
47    also store insns after this insn.  Set up the array `reload_reg_rtx'
48    to contain the REG rtx's for the registers you used.  In some
49    cases `find_reloads' will return a nonzero value in `reload_reg_rtx'
50    for certain reloads.  Then that tells you which register to use,
51    so you do not need to allocate one.  But you still do need to add extra
52    instructions to copy the value into and out of that register.
53
54    Finally you must call `subst_reloads' to substitute the reload reg rtx's
55    into the locations already recorded.
56
57 NOTE SIDE EFFECTS:
58
59    find_reloads can alter the operands of the instruction it is called on.
60
61    1. Two operands of any sort may be interchanged, if they are in a
62    commutative instruction.
63    This happens only if find_reloads thinks the instruction will compile
64    better that way.
65
66    2. Pseudo-registers that are equivalent to constants are replaced
67    with those constants if they are not in hard registers.
68
69 1 happens every time find_reloads is called.
70 2 happens only when REPLACE is 1, which is only when
71 actually doing the reloads, not when just counting them.
72
73
74 Using a reload register for several reloads in one insn:
75
76 When an insn has reloads, it is considered as having three parts:
77 the input reloads, the insn itself after reloading, and the output reloads.
78 Reloads of values used in memory addresses are often needed for only one part.
79
80 When this is so, reload_when_needed records which part needs the reload.
81 Two reloads for different parts of the insn can share the same reload
82 register.
83
84 When a reload is used for addresses in multiple parts, or when it is
85 an ordinary operand, it is classified as RELOAD_OTHER, and cannot share
86 a register with any other reload.  */
87
88 #define REG_OK_STRICT
89
90 #include <stdio.h>
91 #include "config.h"
92 #include "rtl.h"
93 #include "insn-config.h"
94 #include "insn-codes.h"
95 #include "recog.h"
96 #include "reload.h"
97 #include "regs.h"
98 #include "hard-reg-set.h"
99 #include "flags.h"
100 #include "real.h"
101 #include "output.h"
102 #include "expr.h"
103
104 #ifndef REGISTER_MOVE_COST
105 #define REGISTER_MOVE_COST(x, y) 2
106 #endif
107
108 #ifndef REGNO_MODE_OK_FOR_BASE_P
109 #define REGNO_MODE_OK_FOR_BASE_P(REGNO, MODE) REGNO_OK_FOR_BASE_P (REGNO)
110 #endif
111
112 #ifndef REG_MODE_OK_FOR_BASE_P
113 #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
114 #endif
115 \f
116 /* The variables set up by `find_reloads' are:
117
118    n_reloads              number of distinct reloads needed; max reload # + 1
119        tables indexed by reload number
120    reload_in              rtx for value to reload from
121    reload_out             rtx for where to store reload-reg afterward if nec
122                            (often the same as reload_in)
123    reload_reg_class       enum reg_class, saying what regs to reload into
124    reload_inmode          enum machine_mode; mode this operand should have
125                            when reloaded, on input.
126    reload_outmode         enum machine_mode; mode this operand should have
127                            when reloaded, on output.
128    reload_optional        char, nonzero for an optional reload.
129                            Optional reloads are ignored unless the
130                            value is already sitting in a register.
131    reload_inc             int, positive amount to increment or decrement by if
132                            reload_in is a PRE_DEC, PRE_INC, POST_DEC, POST_INC.
133                            Ignored otherwise (don't assume it is zero).
134    reload_in_reg          rtx.  A reg for which reload_in is the equivalent.
135                            If reload_in is a symbol_ref which came from
136                            reg_equiv_constant, then this is the pseudo
137                            which has that symbol_ref as equivalent.
138    reload_reg_rtx         rtx.  This is the register to reload into.
139                            If it is zero when `find_reloads' returns,
140                            you must find a suitable register in the class
141                            specified by reload_reg_class, and store here
142                            an rtx for that register with mode from
143                            reload_inmode or reload_outmode.
144    reload_nocombine       char, nonzero if this reload shouldn't be
145                            combined with another reload.
146    reload_opnum           int, operand number being reloaded.  This is
147                            used to group related reloads and need not always
148                            be equal to the actual operand number in the insn,
149                            though it current will be; for in-out operands, it
150                            is one of the two operand numbers.
151    reload_when_needed    enum, classifies reload as needed either for
152                            addressing an input reload, addressing an output,
153                            for addressing a non-reloaded mem ref,
154                            or for unspecified purposes (i.e., more than one
155                            of the above).
156    reload_secondary_p     int, 1 if this is a secondary register for one
157                            or more reloads.
158    reload_secondary_in_reload
159    reload_secondary_out_reload
160                           int, gives the reload number of a secondary
161                            reload, when needed; otherwise -1
162    reload_secondary_in_icode
163    reload_secondary_out_icode
164                           enum insn_code, if a secondary reload is required,
165                            gives the INSN_CODE that uses the secondary
166                            reload as a scratch register, or CODE_FOR_nothing
167                            if the secondary reload register is to be an
168                            intermediate register.  */
169 int n_reloads;
170
171 rtx reload_in[MAX_RELOADS];
172 rtx reload_out[MAX_RELOADS];
173 enum reg_class reload_reg_class[MAX_RELOADS];
174 enum machine_mode reload_inmode[MAX_RELOADS];
175 enum machine_mode reload_outmode[MAX_RELOADS];
176 rtx reload_reg_rtx[MAX_RELOADS];
177 char reload_optional[MAX_RELOADS];
178 int reload_inc[MAX_RELOADS];
179 rtx reload_in_reg[MAX_RELOADS];
180 char reload_nocombine[MAX_RELOADS];
181 int reload_opnum[MAX_RELOADS];
182 enum reload_type reload_when_needed[MAX_RELOADS];
183 int reload_secondary_p[MAX_RELOADS];
184 int reload_secondary_in_reload[MAX_RELOADS];
185 int reload_secondary_out_reload[MAX_RELOADS];
186 enum insn_code reload_secondary_in_icode[MAX_RELOADS];
187 enum insn_code reload_secondary_out_icode[MAX_RELOADS];
188
189 /* All the "earlyclobber" operands of the current insn
190    are recorded here.  */
191 int n_earlyclobbers;
192 rtx reload_earlyclobbers[MAX_RECOG_OPERANDS];
193
194 int reload_n_operands;
195
196 /* Replacing reloads.
197
198    If `replace_reloads' is nonzero, then as each reload is recorded
199    an entry is made for it in the table `replacements'.
200    Then later `subst_reloads' can look through that table and
201    perform all the replacements needed.  */
202
203 /* Nonzero means record the places to replace.  */
204 static int replace_reloads;
205
206 /* Each replacement is recorded with a structure like this.  */
207 struct replacement
208 {
209   rtx *where;                   /* Location to store in */
210   rtx *subreg_loc;              /* Location of SUBREG if WHERE is inside
211                                    a SUBREG; 0 otherwise.  */
212   int what;                     /* which reload this is for */
213   enum machine_mode mode;       /* mode it must have */
214 };
215
216 static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
217
218 /* Number of replacements currently recorded.  */
219 static int n_replacements;
220
221 /* Used to track what is modified by an operand.  */
222 struct decomposition
223 {
224   int reg_flag;         /* Nonzero if referencing a register.  */
225   int safe;             /* Nonzero if this can't conflict with anything.  */
226   rtx base;             /* Base address for MEM.  */
227   HOST_WIDE_INT start;  /* Starting offset or register number.  */
228   HOST_WIDE_INT end;    /* Ending offset or register number.  */
229 };
230
231 /* MEM-rtx's created for pseudo-regs in stack slots not directly addressable;
232    (see reg_equiv_address).  */
233 static rtx memlocs[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
234 static int n_memlocs;
235
236 #ifdef SECONDARY_MEMORY_NEEDED
237
238 /* Save MEMs needed to copy from one class of registers to another.  One MEM
239    is used per mode, but normally only one or two modes are ever used.  
240
241    We keep two versions, before and after register elimination.  The one 
242    after register elimination is record separately for each operand.  This
243    is done in case the address is not valid to be sure that we separately
244    reload each.  */
245
246 static rtx secondary_memlocs[NUM_MACHINE_MODES];
247 static rtx secondary_memlocs_elim[NUM_MACHINE_MODES][MAX_RECOG_OPERANDS];
248 #endif
249
250 /* The instruction we are doing reloads for;
251    so we can test whether a register dies in it.  */
252 static rtx this_insn;
253
254 /* Nonzero if this instruction is a user-specified asm with operands.  */
255 static int this_insn_is_asm;
256
257 /* If hard_regs_live_known is nonzero,
258    we can tell which hard regs are currently live,
259    at least enough to succeed in choosing dummy reloads.  */
260 static int hard_regs_live_known;
261
262 /* Indexed by hard reg number,
263    element is nonegative if hard reg has been spilled.
264    This vector is passed to `find_reloads' as an argument
265    and is not changed here.  */
266 static short *static_reload_reg_p;
267
268 /* Set to 1 in subst_reg_equivs if it changes anything.  */
269 static int subst_reg_equivs_changed;
270
271 /* On return from push_reload, holds the reload-number for the OUT
272    operand, which can be different for that from the input operand.  */
273 static int output_reloadnum;
274
275   /* Compare two RTX's.  */
276 #define MATCHES(x, y) \
277  (x == y || (x != 0 && (GET_CODE (x) == REG                             \
278                         ? GET_CODE (y) == REG && REGNO (x) == REGNO (y) \
279                         : rtx_equal_p (x, y) && ! side_effects_p (x))))
280
281   /* Indicates if two reloads purposes are for similar enough things that we
282      can merge their reloads.  */
283 #define MERGABLE_RELOADS(when1, when2, op1, op2) \
284   ((when1) == RELOAD_OTHER || (when2) == RELOAD_OTHER   \
285    || ((when1) == (when2) && (op1) == (op2))            \
286    || ((when1) == RELOAD_FOR_INPUT && (when2) == RELOAD_FOR_INPUT) \
287    || ((when1) == RELOAD_FOR_OPERAND_ADDRESS            \
288        && (when2) == RELOAD_FOR_OPERAND_ADDRESS)        \
289    || ((when1) == RELOAD_FOR_OTHER_ADDRESS              \
290        && (when2) == RELOAD_FOR_OTHER_ADDRESS))
291
292   /* Nonzero if these two reload purposes produce RELOAD_OTHER when merged.  */
293 #define MERGE_TO_OTHER(when1, when2, op1, op2) \
294   ((when1) != (when2)                                   \
295    || ! ((op1) == (op2)                                 \
296          || (when1) == RELOAD_FOR_INPUT                 \
297          || (when1) == RELOAD_FOR_OPERAND_ADDRESS       \
298          || (when1) == RELOAD_FOR_OTHER_ADDRESS))
299
300   /* If we are going to reload an address, compute the reload type to
301      use.  */
302 #define ADDR_TYPE(type)                                 \
303   ((type) == RELOAD_FOR_INPUT_ADDRESS                   \
304    ? RELOAD_FOR_INPADDR_ADDRESS                         \
305    : ((type) == RELOAD_FOR_OUTPUT_ADDRESS               \
306       ? RELOAD_FOR_OUTADDR_ADDRESS                      \
307       : (type)))
308
309 static int push_secondary_reload PROTO((int, rtx, int, int, enum reg_class,
310                                         enum machine_mode, enum reload_type,
311                                         enum insn_code *));
312 static enum reg_class find_valid_class PROTO((enum machine_mode, int));
313 static int push_reload          PROTO((rtx, rtx, rtx *, rtx *, enum reg_class,
314                                        enum machine_mode, enum machine_mode,
315                                        int, int, int, enum reload_type));
316 static void push_replacement    PROTO((rtx *, int, enum machine_mode));
317 static void combine_reloads     PROTO((void));
318 static rtx find_dummy_reload    PROTO((rtx, rtx, rtx *, rtx *,
319                                        enum machine_mode, enum machine_mode,
320                                        enum reg_class, int, int));
321 static int earlyclobber_operand_p PROTO((rtx));
322 static int hard_reg_set_here_p  PROTO((int, int, rtx));
323 static struct decomposition decompose PROTO((rtx));
324 static int immune_p             PROTO((rtx, rtx, struct decomposition));
325 static int alternative_allows_memconst PROTO((char *, int));
326 static rtx find_reloads_toplev  PROTO((rtx, int, enum reload_type, int, int));
327 static rtx make_memloc          PROTO((rtx, int));
328 static int find_reloads_address PROTO((enum machine_mode, rtx *, rtx, rtx *,
329                                        int, enum reload_type, int, rtx));
330 static rtx subst_reg_equivs     PROTO((rtx));
331 static rtx subst_indexed_address PROTO((rtx));
332 static int find_reloads_address_1 PROTO((enum machine_mode, rtx, int, rtx *,
333                                          int, enum reload_type,int, rtx));
334 static void find_reloads_address_part PROTO((rtx, rtx *, enum reg_class,
335                                              enum machine_mode, int,
336                                              enum reload_type, int));
337 static int find_inc_amount      PROTO((rtx, rtx));
338 \f
339 #ifdef HAVE_SECONDARY_RELOADS
340
341 /* Determine if any secondary reloads are needed for loading (if IN_P is
342    non-zero) or storing (if IN_P is zero) X to or from a reload register of
343    register class RELOAD_CLASS in mode RELOAD_MODE.  If secondary reloads
344    are needed, push them.
345
346    Return the reload number of the secondary reload we made, or -1 if
347    we didn't need one.  *PICODE is set to the insn_code to use if we do
348    need a secondary reload.  */
349
350 static int
351 push_secondary_reload (in_p, x, opnum, optional, reload_class, reload_mode,
352                        type, picode)
353      int in_p;
354      rtx x;
355      int opnum;
356      int optional;
357      enum reg_class reload_class;
358      enum machine_mode reload_mode;
359      enum reload_type type;
360      enum insn_code *picode;
361 {
362   enum reg_class class = NO_REGS;
363   enum machine_mode mode = reload_mode;
364   enum insn_code icode = CODE_FOR_nothing;
365   enum reg_class t_class = NO_REGS;
366   enum machine_mode t_mode = VOIDmode;
367   enum insn_code t_icode = CODE_FOR_nothing;
368   enum reload_type secondary_type;
369   int i;
370   int s_reload, t_reload = -1;
371
372   if (type == RELOAD_FOR_INPUT_ADDRESS
373       || type == RELOAD_FOR_OUTPUT_ADDRESS
374       || type == RELOAD_FOR_INPADDR_ADDRESS
375       || type == RELOAD_FOR_OUTADDR_ADDRESS)
376     secondary_type = type;
377   else
378     secondary_type = in_p ? RELOAD_FOR_INPUT_ADDRESS : RELOAD_FOR_OUTPUT_ADDRESS;
379
380   *picode = CODE_FOR_nothing;
381
382   /* If X is a paradoxical SUBREG, use the inner value to determine both the
383      mode and object being reloaded.  */
384   if (GET_CODE (x) == SUBREG
385       && (GET_MODE_SIZE (GET_MODE (x))
386           > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
387     {
388       x = SUBREG_REG (x);
389       reload_mode = GET_MODE (x);
390     }
391
392   /* If X is a pseudo-register that has an equivalent MEM (actually, if it
393      is still a pseudo-register by now, it *must* have an equivalent MEM
394      but we don't want to assume that), use that equivalent when seeing if
395      a secondary reload is needed since whether or not a reload is needed
396      might be sensitive to the form of the MEM.  */
397
398   if (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER
399       && reg_equiv_mem[REGNO (x)] != 0)
400     x = reg_equiv_mem[REGNO (x)];
401
402 #ifdef SECONDARY_INPUT_RELOAD_CLASS
403   if (in_p)
404     class = SECONDARY_INPUT_RELOAD_CLASS (reload_class, reload_mode, x);
405 #endif
406
407 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
408   if (! in_p)
409     class = SECONDARY_OUTPUT_RELOAD_CLASS (reload_class, reload_mode, x);
410 #endif
411
412   /* If we don't need any secondary registers, done.  */
413   if (class == NO_REGS)
414     return -1;
415
416   /* Get a possible insn to use.  If the predicate doesn't accept X, don't
417      use the insn.  */
418
419   icode = (in_p ? reload_in_optab[(int) reload_mode]
420            : reload_out_optab[(int) reload_mode]);
421
422   if (icode != CODE_FOR_nothing
423       && insn_operand_predicate[(int) icode][in_p]
424       && (! (insn_operand_predicate[(int) icode][in_p]) (x, reload_mode)))
425     icode = CODE_FOR_nothing;
426
427   /* If we will be using an insn, see if it can directly handle the reload
428      register we will be using.  If it can, the secondary reload is for a
429      scratch register.  If it can't, we will use the secondary reload for
430      an intermediate register and require a tertiary reload for the scratch
431      register.  */
432
433   if (icode != CODE_FOR_nothing)
434     {
435       /* If IN_P is non-zero, the reload register will be the output in 
436          operand 0.  If IN_P is zero, the reload register will be the input
437          in operand 1.  Outputs should have an initial "=", which we must
438          skip.  */
439
440       char insn_letter = insn_operand_constraint[(int) icode][!in_p][in_p];
441       enum reg_class insn_class
442         = (insn_letter == 'r' ? GENERAL_REGS
443            : REG_CLASS_FROM_LETTER (insn_letter));
444
445       if (insn_class == NO_REGS
446           || (in_p && insn_operand_constraint[(int) icode][!in_p][0] != '=')
447           /* The scratch register's constraint must start with "=&".  */
448           || insn_operand_constraint[(int) icode][2][0] != '='
449           || insn_operand_constraint[(int) icode][2][1] != '&')
450         abort ();
451
452       if (reg_class_subset_p (reload_class, insn_class))
453         mode = insn_operand_mode[(int) icode][2];
454       else
455         {
456           char t_letter = insn_operand_constraint[(int) icode][2][2];
457           class = insn_class;
458           t_mode = insn_operand_mode[(int) icode][2];
459           t_class = (t_letter == 'r' ? GENERAL_REGS
460                      : REG_CLASS_FROM_LETTER (t_letter));
461           t_icode = icode;
462           icode = CODE_FOR_nothing;
463         }
464     }
465
466   /* This case isn't valid, so fail.  Reload is allowed to use the same
467      register for RELOAD_FOR_INPUT_ADDRESS and RELOAD_FOR_INPUT reloads, but
468      in the case of a secondary register, we actually need two different
469      registers for correct code.  We fail here to prevent the possibility of
470      silently generating incorrect code later.
471
472      The convention is that secondary input reloads are valid only if the
473      secondary_class is different from class.  If you have such a case, you
474      can not use secondary reloads, you must work around the problem some
475      other way.
476
477      Allow this when MODE is not reload_mode and assume that the generated
478      code handles this case (it does on the Alpha, which is the only place
479      this currently happens).  */
480
481   if (in_p && class == reload_class && mode == reload_mode)
482     abort ();
483
484   /* If we need a tertiary reload, see if we have one we can reuse or else
485      make a new one.  */
486
487   if (t_class != NO_REGS)
488     {
489       for (t_reload = 0; t_reload < n_reloads; t_reload++)
490         if (reload_secondary_p[t_reload]
491             && (reg_class_subset_p (t_class, reload_reg_class[t_reload])
492                 || reg_class_subset_p (reload_reg_class[t_reload], t_class))
493             && ((in_p && reload_inmode[t_reload] == t_mode)
494                 || (! in_p && reload_outmode[t_reload] == t_mode))
495             && ((in_p && (reload_secondary_in_icode[t_reload]
496                           == CODE_FOR_nothing))
497                 || (! in_p &&(reload_secondary_out_icode[t_reload]
498                               == CODE_FOR_nothing)))
499             && (reg_class_size[(int) t_class] == 1
500 #ifdef SMALL_REGISTER_CLASSES
501                 || SMALL_REGISTER_CLASSES
502 #endif
503                 )
504             && MERGABLE_RELOADS (secondary_type,
505                                  reload_when_needed[t_reload],
506                                  opnum, reload_opnum[t_reload]))
507           {
508             if (in_p)
509               reload_inmode[t_reload] = t_mode;
510             if (! in_p)
511               reload_outmode[t_reload] = t_mode;
512
513             if (reg_class_subset_p (t_class, reload_reg_class[t_reload]))
514               reload_reg_class[t_reload] = t_class;
515
516             reload_opnum[t_reload] = MIN (reload_opnum[t_reload], opnum);
517             reload_optional[t_reload] &= optional;
518             reload_secondary_p[t_reload] = 1;
519             if (MERGE_TO_OTHER (secondary_type, reload_when_needed[t_reload],
520                                 opnum, reload_opnum[t_reload]))
521               reload_when_needed[t_reload] = RELOAD_OTHER;
522           }
523
524       if (t_reload == n_reloads)
525         {
526           /* We need to make a new tertiary reload for this register class.  */
527           reload_in[t_reload] = reload_out[t_reload] = 0;
528           reload_reg_class[t_reload] = t_class;
529           reload_inmode[t_reload] = in_p ? t_mode : VOIDmode;
530           reload_outmode[t_reload] = ! in_p ? t_mode : VOIDmode;
531           reload_reg_rtx[t_reload] = 0;
532           reload_optional[t_reload] = optional;
533           reload_inc[t_reload] = 0;
534           /* Maybe we could combine these, but it seems too tricky.  */
535           reload_nocombine[t_reload] = 1;
536           reload_in_reg[t_reload] = 0;
537           reload_opnum[t_reload] = opnum;
538           reload_when_needed[t_reload] = secondary_type;
539           reload_secondary_in_reload[t_reload] = -1;
540           reload_secondary_out_reload[t_reload] = -1;
541           reload_secondary_in_icode[t_reload] = CODE_FOR_nothing;
542           reload_secondary_out_icode[t_reload] = CODE_FOR_nothing;
543           reload_secondary_p[t_reload] = 1;
544
545           n_reloads++;
546         }
547     }
548
549   /* See if we can reuse an existing secondary reload.  */
550   for (s_reload = 0; s_reload < n_reloads; s_reload++)
551     if (reload_secondary_p[s_reload]
552         && (reg_class_subset_p (class, reload_reg_class[s_reload])
553             || reg_class_subset_p (reload_reg_class[s_reload], class))
554         && ((in_p && reload_inmode[s_reload] == mode)
555             || (! in_p && reload_outmode[s_reload] == mode))
556         && ((in_p && reload_secondary_in_reload[s_reload] == t_reload)
557             || (! in_p && reload_secondary_out_reload[s_reload] == t_reload))
558         && ((in_p && reload_secondary_in_icode[s_reload] == t_icode)
559             || (! in_p && reload_secondary_out_icode[s_reload] == t_icode))
560         && (reg_class_size[(int) class] == 1
561 #ifdef SMALL_REGISTER_CLASSES
562             || SMALL_REGISTER_CLASSES
563 #endif
564             )
565         && MERGABLE_RELOADS (secondary_type, reload_when_needed[s_reload],
566                              opnum, reload_opnum[s_reload]))
567       {
568         if (in_p)
569           reload_inmode[s_reload] = mode;
570         if (! in_p)
571           reload_outmode[s_reload] = mode;
572
573         if (reg_class_subset_p (class, reload_reg_class[s_reload]))
574           reload_reg_class[s_reload] = class;
575
576         reload_opnum[s_reload] = MIN (reload_opnum[s_reload], opnum);
577         reload_optional[s_reload] &= optional;
578         reload_secondary_p[s_reload] = 1;
579         if (MERGE_TO_OTHER (secondary_type, reload_when_needed[s_reload],
580                             opnum, reload_opnum[s_reload]))
581           reload_when_needed[s_reload] = RELOAD_OTHER;
582       }
583
584   if (s_reload == n_reloads)
585     {
586       /* We need to make a new secondary reload for this register class.  */
587       reload_in[s_reload] = reload_out[s_reload] = 0;
588       reload_reg_class[s_reload] = class;
589
590       reload_inmode[s_reload] = in_p ? mode : VOIDmode;
591       reload_outmode[s_reload] = ! in_p ? mode : VOIDmode;
592       reload_reg_rtx[s_reload] = 0;
593       reload_optional[s_reload] = optional;
594       reload_inc[s_reload] = 0;
595       /* Maybe we could combine these, but it seems too tricky.  */
596       reload_nocombine[s_reload] = 1;
597       reload_in_reg[s_reload] = 0;
598       reload_opnum[s_reload] = opnum;
599       reload_when_needed[s_reload] = secondary_type;
600       reload_secondary_in_reload[s_reload] = in_p ? t_reload : -1;
601       reload_secondary_out_reload[s_reload] = ! in_p ? t_reload : -1;
602       reload_secondary_in_icode[s_reload] = in_p ? t_icode : CODE_FOR_nothing; 
603       reload_secondary_out_icode[s_reload]
604         = ! in_p ? t_icode : CODE_FOR_nothing;
605       reload_secondary_p[s_reload] = 1;
606
607       n_reloads++;
608
609 #ifdef SECONDARY_MEMORY_NEEDED
610       /* If we need a memory location to copy between the two reload regs,
611          set it up now.  */
612
613       if (in_p && icode == CODE_FOR_nothing
614           && SECONDARY_MEMORY_NEEDED (class, reload_class, mode))
615         get_secondary_mem (x, mode, opnum, type);
616
617       if (! in_p && icode == CODE_FOR_nothing
618           && SECONDARY_MEMORY_NEEDED (reload_class, class, mode))
619         get_secondary_mem (x, mode, opnum, type);
620 #endif
621     }
622
623   *picode = icode;
624   return s_reload;
625 }
626 #endif /* HAVE_SECONDARY_RELOADS */
627 \f
628 #ifdef SECONDARY_MEMORY_NEEDED
629
630 /* Return a memory location that will be used to copy X in mode MODE.  
631    If we haven't already made a location for this mode in this insn,
632    call find_reloads_address on the location being returned.  */
633
634 rtx
635 get_secondary_mem (x, mode, opnum, type)
636      rtx x;
637      enum machine_mode mode;
638      int opnum;
639      enum reload_type type;
640 {
641   rtx loc;
642   int mem_valid;
643
644   /* By default, if MODE is narrower than a word, widen it to a word.
645      This is required because most machines that require these memory
646      locations do not support short load and stores from all registers
647      (e.g., FP registers).  */
648
649 #ifdef SECONDARY_MEMORY_NEEDED_MODE
650   mode = SECONDARY_MEMORY_NEEDED_MODE (mode);
651 #else
652   if (GET_MODE_BITSIZE (mode) < BITS_PER_WORD)
653     mode = mode_for_size (BITS_PER_WORD, GET_MODE_CLASS (mode), 0);
654 #endif
655
656   /* If we already have made a MEM for this operand in MODE, return it.  */
657   if (secondary_memlocs_elim[(int) mode][opnum] != 0)
658     return secondary_memlocs_elim[(int) mode][opnum];
659
660   /* If this is the first time we've tried to get a MEM for this mode, 
661      allocate a new one.  `something_changed' in reload will get set
662      by noticing that the frame size has changed.  */
663
664   if (secondary_memlocs[(int) mode] == 0)
665     {
666 #ifdef SECONDARY_MEMORY_NEEDED_RTX
667       secondary_memlocs[(int) mode] = SECONDARY_MEMORY_NEEDED_RTX (mode);
668 #else
669       secondary_memlocs[(int) mode]
670         = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
671 #endif
672     }
673
674   /* Get a version of the address doing any eliminations needed.  If that
675      didn't give us a new MEM, make a new one if it isn't valid.  */
676
677   loc = eliminate_regs (secondary_memlocs[(int) mode], VOIDmode, NULL_RTX, 0);
678   mem_valid = strict_memory_address_p (mode, XEXP (loc, 0));
679
680   if (! mem_valid && loc == secondary_memlocs[(int) mode])
681     loc = copy_rtx (loc);
682
683   /* The only time the call below will do anything is if the stack
684      offset is too large.  In that case IND_LEVELS doesn't matter, so we
685      can just pass a zero.  Adjust the type to be the address of the
686      corresponding object.  If the address was valid, save the eliminated
687      address.  If it wasn't valid, we need to make a reload each time, so
688      don't save it.  */
689
690   if (! mem_valid)
691     {
692       type =  (type == RELOAD_FOR_INPUT ? RELOAD_FOR_INPUT_ADDRESS
693                : type == RELOAD_FOR_OUTPUT ? RELOAD_FOR_OUTPUT_ADDRESS
694                : RELOAD_OTHER);
695
696       find_reloads_address (mode, NULL_PTR, XEXP (loc, 0), &XEXP (loc, 0),
697                             opnum, type, 0, 0);
698     }
699
700   secondary_memlocs_elim[(int) mode][opnum] = loc;
701   return loc;
702 }
703
704 /* Clear any secondary memory locations we've made.  */
705
706 void
707 clear_secondary_mem ()
708 {
709   bzero ((char *) secondary_memlocs, sizeof secondary_memlocs);
710 }
711 #endif /* SECONDARY_MEMORY_NEEDED */
712 \f
713 /* Find the largest class for which every register number plus N is valid in
714    M1 (if in range).  Abort if no such class exists.  */
715
716 static enum reg_class
717 find_valid_class (m1, n)
718      enum machine_mode  m1;
719      int n;
720 {
721   int class;
722   int regno;
723   enum reg_class best_class;
724   int best_size = 0;
725
726   for (class = 1; class < N_REG_CLASSES; class++)
727     {
728       int bad = 0;
729       for (regno = 0; regno < FIRST_PSEUDO_REGISTER && ! bad; regno++)
730         if (TEST_HARD_REG_BIT (reg_class_contents[class], regno)
731             && TEST_HARD_REG_BIT (reg_class_contents[class], regno + n)
732             && ! HARD_REGNO_MODE_OK (regno + n, m1))
733           bad = 1;
734
735       if (! bad && reg_class_size[class] > best_size)
736         best_class = class, best_size = reg_class_size[class];
737     }
738
739   if (best_size == 0)
740     abort ();
741
742   return best_class;
743 }
744 \f
745 /* Record one reload that needs to be performed.
746    IN is an rtx saying where the data are to be found before this instruction.
747    OUT says where they must be stored after the instruction.
748    (IN is zero for data not read, and OUT is zero for data not written.)
749    INLOC and OUTLOC point to the places in the instructions where
750    IN and OUT were found.
751    If IN and OUT are both non-zero, it means the same register must be used
752    to reload both IN and OUT.
753
754    CLASS is a register class required for the reloaded data.
755    INMODE is the machine mode that the instruction requires
756    for the reg that replaces IN and OUTMODE is likewise for OUT.
757
758    If IN is zero, then OUT's location and mode should be passed as
759    INLOC and INMODE.
760
761    STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx.
762
763    OPTIONAL nonzero means this reload does not need to be performed:
764    it can be discarded if that is more convenient.
765
766    OPNUM and TYPE say what the purpose of this reload is.
767
768    The return value is the reload-number for this reload.
769
770    If both IN and OUT are nonzero, in some rare cases we might
771    want to make two separate reloads.  (Actually we never do this now.)
772    Therefore, the reload-number for OUT is stored in
773    output_reloadnum when we return; the return value applies to IN.
774    Usually (presently always), when IN and OUT are nonzero,
775    the two reload-numbers are equal, but the caller should be careful to
776    distinguish them.  */
777
778 static int
779 push_reload (in, out, inloc, outloc, class,
780              inmode, outmode, strict_low, optional, opnum, type)
781      register rtx in, out;
782      rtx *inloc, *outloc;
783      enum reg_class class;
784      enum machine_mode inmode, outmode;
785      int strict_low;
786      int optional;
787      int opnum;
788      enum reload_type type;
789 {
790   register int i;
791   int dont_share = 0;
792   int dont_remove_subreg = 0;
793   rtx *in_subreg_loc = 0, *out_subreg_loc = 0;
794   int secondary_in_reload = -1, secondary_out_reload = -1;
795   enum insn_code secondary_in_icode = CODE_FOR_nothing;
796   enum insn_code secondary_out_icode = CODE_FOR_nothing;
797
798   /* INMODE and/or OUTMODE could be VOIDmode if no mode
799      has been specified for the operand.  In that case,
800      use the operand's mode as the mode to reload.  */
801   if (inmode == VOIDmode && in != 0)
802     inmode = GET_MODE (in);
803   if (outmode == VOIDmode && out != 0)
804     outmode = GET_MODE (out);
805
806   /* If IN is a pseudo register everywhere-equivalent to a constant, and 
807      it is not in a hard register, reload straight from the constant,
808      since we want to get rid of such pseudo registers.
809      Often this is done earlier, but not always in find_reloads_address.  */
810   if (in != 0 && GET_CODE (in) == REG)
811     {
812       register int regno = REGNO (in);
813
814       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
815           && reg_equiv_constant[regno] != 0)
816         in = reg_equiv_constant[regno];
817     }
818
819   /* Likewise for OUT.  Of course, OUT will never be equivalent to
820      an actual constant, but it might be equivalent to a memory location
821      (in the case of a parameter).  */
822   if (out != 0 && GET_CODE (out) == REG)
823     {
824       register int regno = REGNO (out);
825
826       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
827           && reg_equiv_constant[regno] != 0)
828         out = reg_equiv_constant[regno];
829     }
830
831   /* If we have a read-write operand with an address side-effect,
832      change either IN or OUT so the side-effect happens only once.  */
833   if (in != 0 && out != 0 && GET_CODE (in) == MEM && rtx_equal_p (in, out))
834     {
835       if (GET_CODE (XEXP (in, 0)) == POST_INC
836           || GET_CODE (XEXP (in, 0)) == POST_DEC)
837         in = gen_rtx (MEM, GET_MODE (in), XEXP (XEXP (in, 0), 0));
838       if (GET_CODE (XEXP (in, 0)) == PRE_INC
839           || GET_CODE (XEXP (in, 0)) == PRE_DEC)
840         out = gen_rtx (MEM, GET_MODE (out), XEXP (XEXP (out, 0), 0));
841     }
842
843   /* If we are reloading a (SUBREG constant ...), really reload just the
844      inside expression in its own mode.  Similarly for (SUBREG (PLUS ...)).
845      If we have (SUBREG:M1 (MEM:M2 ...) ...) (or an inner REG that is still
846      a pseudo and hence will become a MEM) with M1 wider than M2 and the
847      register is a pseudo, also reload the inside expression.
848      For machines that extend byte loads, do this for any SUBREG of a pseudo
849      where both M1 and M2 are a word or smaller, M1 is wider than M2, and
850      M2 is an integral mode that gets extended when loaded.
851      Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
852      either M1 is not valid for R or M2 is wider than a word but we only
853      need one word to store an M2-sized quantity in R.
854      (However, if OUT is nonzero, we need to reload the reg *and*
855      the subreg, so do nothing here, and let following statement handle it.)
856
857      Note that the case of (SUBREG (CONST_INT...)...) is handled elsewhere;
858      we can't handle it here because CONST_INT does not indicate a mode.
859
860      Similarly, we must reload the inside expression if we have a
861      STRICT_LOW_PART (presumably, in == out in the cas).
862
863      Also reload the inner expression if it does not require a secondary
864      reload but the SUBREG does.
865
866      Finally, reload the inner expression if it is a register that is in
867      the class whose registers cannot be referenced in a different size
868      and M1 is not the same size as M2.  If SUBREG_WORD is nonzero, we
869      cannot reload just the inside since we might end up with the wrong
870      register class.  */
871
872   if (in != 0 && GET_CODE (in) == SUBREG && SUBREG_WORD (in) == 0
873 #ifdef CLASS_CANNOT_CHANGE_SIZE
874       && class != CLASS_CANNOT_CHANGE_SIZE
875 #endif
876       && (CONSTANT_P (SUBREG_REG (in))
877           || GET_CODE (SUBREG_REG (in)) == PLUS
878           || strict_low
879           || (((GET_CODE (SUBREG_REG (in)) == REG
880                 && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER)
881                || GET_CODE (SUBREG_REG (in)) == MEM)
882               && ((GET_MODE_SIZE (inmode)
883                    > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
884 #ifdef LOAD_EXTEND_OP
885                   || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
886                       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
887                           <= UNITS_PER_WORD)
888                       && (GET_MODE_SIZE (inmode)
889                           > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
890                       && INTEGRAL_MODE_P (GET_MODE (SUBREG_REG (in)))
891                       && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (in))) != NIL)
892 #endif
893                   ))
894           || (GET_CODE (SUBREG_REG (in)) == REG
895               && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
896               /* The case where out is nonzero
897                  is handled differently in the following statement.  */
898               && (out == 0 || SUBREG_WORD (in) == 0)
899               && ((GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
900                    && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
901                        > UNITS_PER_WORD)
902                    && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
903                         / UNITS_PER_WORD)
904                        != HARD_REGNO_NREGS (REGNO (SUBREG_REG (in)),
905                                             GET_MODE (SUBREG_REG (in)))))
906                   || ! HARD_REGNO_MODE_OK ((REGNO (SUBREG_REG (in))
907                                             + SUBREG_WORD (in)),
908                                            inmode)))
909 #ifdef SECONDARY_INPUT_RELOAD_CLASS
910           || (SECONDARY_INPUT_RELOAD_CLASS (class, inmode, in) != NO_REGS
911               && (SECONDARY_INPUT_RELOAD_CLASS (class,
912                                                 GET_MODE (SUBREG_REG (in)),
913                                                 SUBREG_REG (in))
914                   == NO_REGS))
915 #endif
916 #ifdef CLASS_CANNOT_CHANGE_SIZE
917           || (GET_CODE (SUBREG_REG (in)) == REG
918               && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
919               && (TEST_HARD_REG_BIT
920                   (reg_class_contents[(int) CLASS_CANNOT_CHANGE_SIZE],
921                    REGNO (SUBREG_REG (in))))
922               && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
923                   != GET_MODE_SIZE (inmode)))
924 #endif
925           ))
926     {
927       in_subreg_loc = inloc;
928       inloc = &SUBREG_REG (in);
929       in = *inloc;
930 #ifndef LOAD_EXTEND_OP
931       if (GET_CODE (in) == MEM)
932         /* This is supposed to happen only for paradoxical subregs made by
933            combine.c.  (SUBREG (MEM)) isn't supposed to occur other ways.  */
934         if (GET_MODE_SIZE (GET_MODE (in)) > GET_MODE_SIZE (inmode))
935           abort ();
936 #endif
937       inmode = GET_MODE (in);
938     }
939
940   /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
941      either M1 is not valid for R or M2 is wider than a word but we only
942      need one word to store an M2-sized quantity in R.
943
944      However, we must reload the inner reg *as well as* the subreg in
945      that case.  */
946
947   /* Similar issue for (SUBREG constant ...) if it was not handled by the
948      code above.  This can happen if SUBREG_WORD != 0.  */
949
950   if (in != 0 && GET_CODE (in) == SUBREG
951       && (CONSTANT_P (SUBREG_REG (in))
952           || (GET_CODE (SUBREG_REG (in)) == REG
953               && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
954               && (! HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (in))
955                                         + SUBREG_WORD (in),
956                                         inmode)
957                   || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
958                       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
959                           > UNITS_PER_WORD)
960                       && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
961                            / UNITS_PER_WORD)
962                           != HARD_REGNO_NREGS (REGNO (SUBREG_REG (in)),
963                                                GET_MODE (SUBREG_REG (in)))))))))
964     {
965       /* This relies on the fact that emit_reload_insns outputs the
966          instructions for input reloads of type RELOAD_OTHER in the same
967          order as the reloads.  Thus if the outer reload is also of type
968          RELOAD_OTHER, we are guaranteed that this inner reload will be
969          output before the outer reload.  */
970       push_reload (SUBREG_REG (in), NULL_RTX, &SUBREG_REG (in), NULL_PTR,
971                    find_valid_class (inmode, SUBREG_WORD (in)),
972                    VOIDmode, VOIDmode, 0, 0, opnum, type);
973       dont_remove_subreg = 1;
974     }
975
976   /* Similarly for paradoxical and problematical SUBREGs on the output.
977      Note that there is no reason we need worry about the previous value
978      of SUBREG_REG (out); even if wider than out,
979      storing in a subreg is entitled to clobber it all
980      (except in the case of STRICT_LOW_PART,
981      and in that case the constraint should label it input-output.)  */
982   if (out != 0 && GET_CODE (out) == SUBREG && SUBREG_WORD (out) == 0
983 #ifdef CLASS_CANNOT_CHANGE_SIZE
984       && class != CLASS_CANNOT_CHANGE_SIZE
985 #endif
986       && (CONSTANT_P (SUBREG_REG (out))
987           || strict_low
988           || (((GET_CODE (SUBREG_REG (out)) == REG
989                 && REGNO (SUBREG_REG (out)) >= FIRST_PSEUDO_REGISTER)
990                || GET_CODE (SUBREG_REG (out)) == MEM)
991               && ((GET_MODE_SIZE (outmode)
992                    > GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))))
993           || (GET_CODE (SUBREG_REG (out)) == REG
994               && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
995               && ((GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
996                    && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
997                        > UNITS_PER_WORD)
998                    && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
999                         / UNITS_PER_WORD)
1000                        != HARD_REGNO_NREGS (REGNO (SUBREG_REG (out)),
1001                                             GET_MODE (SUBREG_REG (out)))))
1002                   || ! HARD_REGNO_MODE_OK ((REGNO (SUBREG_REG (out))
1003                                             + SUBREG_WORD (out)),
1004                                            outmode)))
1005 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1006           || (SECONDARY_OUTPUT_RELOAD_CLASS (class, outmode, out) != NO_REGS
1007               && (SECONDARY_OUTPUT_RELOAD_CLASS (class,
1008                                                  GET_MODE (SUBREG_REG (out)),
1009                                                  SUBREG_REG (out))
1010                   == NO_REGS))
1011 #endif
1012 #ifdef CLASS_CANNOT_CHANGE_SIZE
1013           || (GET_CODE (SUBREG_REG (out)) == REG
1014               && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1015               && (TEST_HARD_REG_BIT
1016                   (reg_class_contents[(int) CLASS_CANNOT_CHANGE_SIZE],
1017                    REGNO (SUBREG_REG (out))))
1018               && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1019                   != GET_MODE_SIZE (outmode)))
1020 #endif
1021           ))
1022     {
1023       out_subreg_loc = outloc;
1024       outloc = &SUBREG_REG (out);
1025       out = *outloc; 
1026 #ifndef LOAD_EXTEND_OP
1027      if (GET_CODE (out) == MEM
1028           && GET_MODE_SIZE (GET_MODE (out)) > GET_MODE_SIZE (outmode))
1029         abort ();
1030 #endif
1031       outmode = GET_MODE (out);
1032     }
1033
1034   /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
1035      either M1 is not valid for R or M2 is wider than a word but we only
1036      need one word to store an M2-sized quantity in R.
1037
1038      However, we must reload the inner reg *as well as* the subreg in
1039      that case.  In this case, the inner reg is an in-out reload.  */
1040
1041   if (out != 0 && GET_CODE (out) == SUBREG
1042       && GET_CODE (SUBREG_REG (out)) == REG
1043       && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1044       && (! HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (out)) + SUBREG_WORD (out),
1045                                 outmode)
1046           || (GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
1047               && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1048                   > UNITS_PER_WORD)
1049               && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1050                    / UNITS_PER_WORD)
1051                   != HARD_REGNO_NREGS (REGNO (SUBREG_REG (out)),
1052                                        GET_MODE (SUBREG_REG (out)))))))
1053     {
1054       /* This relies on the fact that emit_reload_insns outputs the
1055          instructions for output reloads of type RELOAD_OTHER in reverse
1056          order of the reloads.  Thus if the outer reload is also of type
1057          RELOAD_OTHER, we are guaranteed that this inner reload will be
1058          output after the outer reload.  */
1059       dont_remove_subreg = 1;
1060       push_reload (SUBREG_REG (out), SUBREG_REG (out), &SUBREG_REG (out),
1061                    &SUBREG_REG (out),
1062                    find_valid_class (outmode, SUBREG_WORD (out)),
1063                    VOIDmode, VOIDmode, 0, 0,
1064                    opnum, RELOAD_OTHER);
1065     }
1066
1067   /* If IN appears in OUT, we can't share any input-only reload for IN.  */
1068   if (in != 0 && out != 0 && GET_CODE (out) == MEM
1069       && (GET_CODE (in) == REG || GET_CODE (in) == MEM)
1070       && reg_overlap_mentioned_for_reload_p (in, XEXP (out, 0)))
1071     dont_share = 1;
1072
1073   /* If IN is a SUBREG of a hard register, make a new REG.  This
1074      simplifies some of the cases below.  */
1075
1076   if (in != 0 && GET_CODE (in) == SUBREG && GET_CODE (SUBREG_REG (in)) == REG
1077       && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1078       && ! dont_remove_subreg)
1079     in = gen_rtx (REG, GET_MODE (in),
1080                   REGNO (SUBREG_REG (in)) + SUBREG_WORD (in));
1081
1082   /* Similarly for OUT.  */
1083   if (out != 0 && GET_CODE (out) == SUBREG
1084       && GET_CODE (SUBREG_REG (out)) == REG
1085       && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1086       && ! dont_remove_subreg)
1087     out = gen_rtx (REG, GET_MODE (out),
1088                   REGNO (SUBREG_REG (out)) + SUBREG_WORD (out));
1089
1090   /* Narrow down the class of register wanted if that is
1091      desirable on this machine for efficiency.  */
1092   if (in != 0)
1093     class = PREFERRED_RELOAD_CLASS (in, class);
1094
1095   /* Output reloads may need analogous treatment, different in detail.  */
1096 #ifdef PREFERRED_OUTPUT_RELOAD_CLASS
1097   if (out != 0)
1098     class = PREFERRED_OUTPUT_RELOAD_CLASS (out, class);
1099 #endif
1100
1101   /* Make sure we use a class that can handle the actual pseudo
1102      inside any subreg.  For example, on the 386, QImode regs
1103      can appear within SImode subregs.  Although GENERAL_REGS
1104      can handle SImode, QImode needs a smaller class.  */
1105 #ifdef LIMIT_RELOAD_CLASS
1106   if (in_subreg_loc)
1107     class = LIMIT_RELOAD_CLASS (inmode, class);
1108   else if (in != 0 && GET_CODE (in) == SUBREG)
1109     class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (in)), class);
1110
1111   if (out_subreg_loc)
1112     class = LIMIT_RELOAD_CLASS (outmode, class);
1113   if (out != 0 && GET_CODE (out) == SUBREG)
1114     class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (out)), class);
1115 #endif
1116
1117   /* Verify that this class is at least possible for the mode that
1118      is specified.  */
1119   if (this_insn_is_asm)
1120     {
1121       enum machine_mode mode;
1122       if (GET_MODE_SIZE (inmode) > GET_MODE_SIZE (outmode))
1123         mode = inmode;
1124       else
1125         mode = outmode;
1126       if (mode == VOIDmode)
1127         {
1128           error_for_asm (this_insn, "cannot reload integer constant operand in `asm'");
1129           mode = word_mode;
1130           if (in != 0)
1131             inmode = word_mode;
1132           if (out != 0)
1133             outmode = word_mode;
1134         }
1135       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1136         if (HARD_REGNO_MODE_OK (i, mode)
1137             && TEST_HARD_REG_BIT (reg_class_contents[(int) class], i))
1138           {
1139             int nregs = HARD_REGNO_NREGS (i, mode);
1140
1141             int j;
1142             for (j = 1; j < nregs; j++)
1143               if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class], i + j))
1144                 break;
1145             if (j == nregs)
1146               break;
1147           }
1148       if (i == FIRST_PSEUDO_REGISTER)
1149         {
1150           error_for_asm (this_insn, "impossible register constraint in `asm'");
1151           class = ALL_REGS;
1152         }
1153     }
1154
1155   if (class == NO_REGS)
1156     abort ();
1157
1158   /* We can use an existing reload if the class is right
1159      and at least one of IN and OUT is a match
1160      and the other is at worst neutral.
1161      (A zero compared against anything is neutral.) 
1162
1163      If SMALL_REGISTER_CLASSES, don't use existing reloads unless they are
1164      for the same thing since that can cause us to need more reload registers
1165      than we otherwise would.  */
1166
1167   for (i = 0; i < n_reloads; i++)
1168     if ((reg_class_subset_p (class, reload_reg_class[i])
1169          || reg_class_subset_p (reload_reg_class[i], class))
1170         /* If the existing reload has a register, it must fit our class.  */
1171         && (reload_reg_rtx[i] == 0
1172             || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1173                                   true_regnum (reload_reg_rtx[i])))
1174         && ((in != 0 && MATCHES (reload_in[i], in) && ! dont_share
1175              && (out == 0 || reload_out[i] == 0 || MATCHES (reload_out[i], out)))
1176             ||
1177             (out != 0 && MATCHES (reload_out[i], out)
1178              && (in == 0 || reload_in[i] == 0 || MATCHES (reload_in[i], in))))
1179         && (reg_class_size[(int) class] == 1
1180 #ifdef SMALL_REGISTER_CLASSES
1181             || SMALL_REGISTER_CLASSES
1182 #endif
1183             )
1184         && MERGABLE_RELOADS (type, reload_when_needed[i],
1185                              opnum, reload_opnum[i]))
1186       break;
1187
1188   /* Reloading a plain reg for input can match a reload to postincrement
1189      that reg, since the postincrement's value is the right value.
1190      Likewise, it can match a preincrement reload, since we regard
1191      the preincrementation as happening before any ref in this insn
1192      to that register.  */
1193   if (i == n_reloads)
1194     for (i = 0; i < n_reloads; i++)
1195       if ((reg_class_subset_p (class, reload_reg_class[i])
1196            || reg_class_subset_p (reload_reg_class[i], class))
1197           /* If the existing reload has a register, it must fit our class.  */
1198           && (reload_reg_rtx[i] == 0
1199               || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1200                                     true_regnum (reload_reg_rtx[i])))
1201           && out == 0 && reload_out[i] == 0 && reload_in[i] != 0
1202           && ((GET_CODE (in) == REG
1203                && (GET_CODE (reload_in[i]) == POST_INC
1204                    || GET_CODE (reload_in[i]) == POST_DEC
1205                    || GET_CODE (reload_in[i]) == PRE_INC
1206                    || GET_CODE (reload_in[i]) == PRE_DEC)
1207                && MATCHES (XEXP (reload_in[i], 0), in))
1208               ||
1209               (GET_CODE (reload_in[i]) == REG
1210                && (GET_CODE (in) == POST_INC
1211                    || GET_CODE (in) == POST_DEC
1212                    || GET_CODE (in) == PRE_INC
1213                    || GET_CODE (in) == PRE_DEC)
1214                && MATCHES (XEXP (in, 0), reload_in[i])))
1215           && (reg_class_size[(int) class] == 1
1216 #ifdef SMALL_REGISTER_CLASSES
1217               || SMALL_REGISTER_CLASSES
1218 #endif
1219               )
1220           && MERGABLE_RELOADS (type, reload_when_needed[i],
1221                                opnum, reload_opnum[i]))
1222         {
1223           /* Make sure reload_in ultimately has the increment,
1224              not the plain register.  */
1225           if (GET_CODE (in) == REG)
1226             in = reload_in[i];
1227           break;
1228         }
1229
1230   if (i == n_reloads)
1231     {
1232       /* See if we need a secondary reload register to move between CLASS
1233          and IN or CLASS and OUT.  Get the icode and push any required reloads
1234          needed for each of them if so.  */
1235
1236 #ifdef SECONDARY_INPUT_RELOAD_CLASS
1237       if (in != 0)
1238         secondary_in_reload
1239           = push_secondary_reload (1, in, opnum, optional, class, inmode, type,
1240                                    &secondary_in_icode);
1241 #endif
1242
1243 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1244       if (out != 0 && GET_CODE (out) != SCRATCH)
1245         secondary_out_reload
1246           = push_secondary_reload (0, out, opnum, optional, class, outmode,
1247                                    type, &secondary_out_icode);
1248 #endif
1249
1250       /* We found no existing reload suitable for re-use.
1251          So add an additional reload.  */
1252
1253       i = n_reloads;
1254       reload_in[i] = in;
1255       reload_out[i] = out;
1256       reload_reg_class[i] = class;
1257       reload_inmode[i] = inmode;
1258       reload_outmode[i] = outmode;
1259       reload_reg_rtx[i] = 0;
1260       reload_optional[i] = optional;
1261       reload_inc[i] = 0;
1262       reload_nocombine[i] = 0;
1263       reload_in_reg[i] = inloc ? *inloc : 0;
1264       reload_opnum[i] = opnum;
1265       reload_when_needed[i] = type;
1266       reload_secondary_in_reload[i] = secondary_in_reload;
1267       reload_secondary_out_reload[i] = secondary_out_reload;
1268       reload_secondary_in_icode[i] = secondary_in_icode;
1269       reload_secondary_out_icode[i] = secondary_out_icode;
1270       reload_secondary_p[i] = 0;
1271
1272       n_reloads++;
1273
1274 #ifdef SECONDARY_MEMORY_NEEDED
1275       /* If a memory location is needed for the copy, make one.  */
1276       if (in != 0 && GET_CODE (in) == REG
1277           && REGNO (in) < FIRST_PSEUDO_REGISTER
1278           && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (REGNO (in)),
1279                                      class, inmode))
1280         get_secondary_mem (in, inmode, opnum, type);
1281
1282       if (out != 0 && GET_CODE (out) == REG
1283           && REGNO (out) < FIRST_PSEUDO_REGISTER
1284           && SECONDARY_MEMORY_NEEDED (class, REGNO_REG_CLASS (REGNO (out)),
1285                                       outmode))
1286         get_secondary_mem (out, outmode, opnum, type);
1287 #endif
1288     }
1289   else
1290     {
1291       /* We are reusing an existing reload,
1292          but we may have additional information for it.
1293          For example, we may now have both IN and OUT
1294          while the old one may have just one of them.  */
1295
1296       /* The modes can be different.  If they are, we want to reload in
1297          the larger mode, so that the value is valid for both modes.  */
1298       if (inmode != VOIDmode
1299           && GET_MODE_SIZE (inmode) > GET_MODE_SIZE (reload_inmode[i]))
1300         reload_inmode[i] = inmode;
1301       if (outmode != VOIDmode
1302           && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (reload_outmode[i]))
1303         reload_outmode[i] = outmode;
1304       if (in != 0)
1305         reload_in[i] = in;
1306       if (out != 0)
1307         reload_out[i] = out;
1308       if (reg_class_subset_p (class, reload_reg_class[i]))
1309         reload_reg_class[i] = class;
1310       reload_optional[i] &= optional;
1311       if (MERGE_TO_OTHER (type, reload_when_needed[i],
1312                           opnum, reload_opnum[i]))
1313         reload_when_needed[i] = RELOAD_OTHER;
1314       reload_opnum[i] = MIN (reload_opnum[i], opnum);
1315     }
1316
1317   /* If the ostensible rtx being reload differs from the rtx found
1318      in the location to substitute, this reload is not safe to combine
1319      because we cannot reliably tell whether it appears in the insn.  */
1320
1321   if (in != 0 && in != *inloc)
1322     reload_nocombine[i] = 1;
1323
1324 #if 0
1325   /* This was replaced by changes in find_reloads_address_1 and the new
1326      function inc_for_reload, which go with a new meaning of reload_inc.  */
1327
1328   /* If this is an IN/OUT reload in an insn that sets the CC,
1329      it must be for an autoincrement.  It doesn't work to store
1330      the incremented value after the insn because that would clobber the CC.
1331      So we must do the increment of the value reloaded from,
1332      increment it, store it back, then decrement again.  */
1333   if (out != 0 && sets_cc0_p (PATTERN (this_insn)))
1334     {
1335       out = 0;
1336       reload_out[i] = 0;
1337       reload_inc[i] = find_inc_amount (PATTERN (this_insn), in);
1338       /* If we did not find a nonzero amount-to-increment-by,
1339          that contradicts the belief that IN is being incremented
1340          in an address in this insn.  */
1341       if (reload_inc[i] == 0)
1342         abort ();
1343     }
1344 #endif
1345
1346   /* If we will replace IN and OUT with the reload-reg,
1347      record where they are located so that substitution need
1348      not do a tree walk.  */
1349
1350   if (replace_reloads)
1351     {
1352       if (inloc != 0)
1353         {
1354           register struct replacement *r = &replacements[n_replacements++];
1355           r->what = i;
1356           r->subreg_loc = in_subreg_loc;
1357           r->where = inloc;
1358           r->mode = inmode;
1359         }
1360       if (outloc != 0 && outloc != inloc)
1361         {
1362           register struct replacement *r = &replacements[n_replacements++];
1363           r->what = i;
1364           r->where = outloc;
1365           r->subreg_loc = out_subreg_loc;
1366           r->mode = outmode;
1367         }
1368     }
1369
1370   /* If this reload is just being introduced and it has both
1371      an incoming quantity and an outgoing quantity that are
1372      supposed to be made to match, see if either one of the two
1373      can serve as the place to reload into.
1374
1375      If one of them is acceptable, set reload_reg_rtx[i]
1376      to that one.  */
1377
1378   if (in != 0 && out != 0 && in != out && reload_reg_rtx[i] == 0)
1379     {
1380       reload_reg_rtx[i] = find_dummy_reload (in, out, inloc, outloc,
1381                                              inmode, outmode,
1382                                              reload_reg_class[i], i,
1383                                              earlyclobber_operand_p (out));
1384
1385       /* If the outgoing register already contains the same value
1386          as the incoming one, we can dispense with loading it.
1387          The easiest way to tell the caller that is to give a phony
1388          value for the incoming operand (same as outgoing one).  */
1389       if (reload_reg_rtx[i] == out
1390           && (GET_CODE (in) == REG || CONSTANT_P (in))
1391           && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
1392                                   static_reload_reg_p, i, inmode))
1393         reload_in[i] = out;
1394     }
1395
1396   /* If this is an input reload and the operand contains a register that
1397      dies in this insn and is used nowhere else, see if it is the right class
1398      to be used for this reload.  Use it if so.  (This occurs most commonly
1399      in the case of paradoxical SUBREGs and in-out reloads).  We cannot do
1400      this if it is also an output reload that mentions the register unless
1401      the output is a SUBREG that clobbers an entire register.
1402
1403      Note that the operand might be one of the spill regs, if it is a
1404      pseudo reg and we are in a block where spilling has not taken place.
1405      But if there is no spilling in this block, that is OK.
1406      An explicitly used hard reg cannot be a spill reg.  */
1407
1408   if (reload_reg_rtx[i] == 0 && in != 0)
1409     {
1410       rtx note;
1411       int regno;
1412
1413       for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1414         if (REG_NOTE_KIND (note) == REG_DEAD
1415             && GET_CODE (XEXP (note, 0)) == REG
1416             && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER
1417             && reg_mentioned_p (XEXP (note, 0), in)
1418             && ! refers_to_regno_for_reload_p (regno,
1419                                                (regno
1420                                                 + HARD_REGNO_NREGS (regno,
1421                                                                     inmode)),
1422                                                PATTERN (this_insn), inloc)
1423             /* If this is also an output reload, IN cannot be used as
1424                the reload register if it is set in this insn unless IN
1425                is also OUT.  */
1426             && (out == 0 || in == out
1427                 || ! hard_reg_set_here_p (regno,
1428                                           (regno
1429                                            + HARD_REGNO_NREGS (regno,
1430                                                                inmode)),
1431                                           PATTERN (this_insn)))
1432             /* ??? Why is this code so different from the previous?
1433                Is there any simple coherent way to describe the two together?
1434                What's going on here.  */
1435             && (in != out
1436                 || (GET_CODE (in) == SUBREG
1437                     && (((GET_MODE_SIZE (GET_MODE (in)) + (UNITS_PER_WORD - 1))
1438                          / UNITS_PER_WORD)
1439                         == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1440                              + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
1441             /* Make sure the operand fits in the reg that dies.  */
1442             && GET_MODE_SIZE (inmode) <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))
1443             && HARD_REGNO_MODE_OK (regno, inmode)
1444             && GET_MODE_SIZE (outmode) <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))
1445             && HARD_REGNO_MODE_OK (regno, outmode)
1446             && TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno)
1447             && !fixed_regs[regno])
1448           {
1449             reload_reg_rtx[i] = gen_rtx (REG, inmode, regno);
1450             break;
1451           }
1452     }
1453
1454   if (out)
1455     output_reloadnum = i;
1456
1457   return i;
1458 }
1459
1460 /* Record an additional place we must replace a value
1461    for which we have already recorded a reload.
1462    RELOADNUM is the value returned by push_reload
1463    when the reload was recorded.
1464    This is used in insn patterns that use match_dup.  */
1465
1466 static void
1467 push_replacement (loc, reloadnum, mode)
1468      rtx *loc;
1469      int reloadnum;
1470      enum machine_mode mode;
1471 {
1472   if (replace_reloads)
1473     {
1474       register struct replacement *r = &replacements[n_replacements++];
1475       r->what = reloadnum;
1476       r->where = loc;
1477       r->subreg_loc = 0;
1478       r->mode = mode;
1479     }
1480 }
1481 \f
1482 /* Transfer all replacements that used to be in reload FROM to be in
1483    reload TO.  */
1484
1485 void
1486 transfer_replacements (to, from)
1487      int to, from;
1488 {
1489   int i;
1490
1491   for (i = 0; i < n_replacements; i++)
1492     if (replacements[i].what == from)
1493       replacements[i].what = to;
1494 }
1495 \f
1496 /* If there is only one output reload, and it is not for an earlyclobber
1497    operand, try to combine it with a (logically unrelated) input reload
1498    to reduce the number of reload registers needed.
1499
1500    This is safe if the input reload does not appear in
1501    the value being output-reloaded, because this implies
1502    it is not needed any more once the original insn completes.
1503
1504    If that doesn't work, see we can use any of the registers that
1505    die in this insn as a reload register.  We can if it is of the right
1506    class and does not appear in the value being output-reloaded.  */
1507
1508 static void
1509 combine_reloads ()
1510 {
1511   int i;
1512   int output_reload = -1;
1513   int secondary_out = -1;
1514   rtx note;
1515
1516   /* Find the output reload; return unless there is exactly one
1517      and that one is mandatory.  */
1518
1519   for (i = 0; i < n_reloads; i++)
1520     if (reload_out[i] != 0)
1521       {
1522         if (output_reload >= 0)
1523           return;
1524         output_reload = i;
1525       }
1526
1527   if (output_reload < 0 || reload_optional[output_reload])
1528     return;
1529
1530   /* An input-output reload isn't combinable.  */
1531
1532   if (reload_in[output_reload] != 0)
1533     return;
1534
1535   /* If this reload is for an earlyclobber operand, we can't do anything.  */
1536   if (earlyclobber_operand_p (reload_out[output_reload]))
1537     return;
1538
1539   /* Check each input reload; can we combine it?  */
1540
1541   for (i = 0; i < n_reloads; i++)
1542     if (reload_in[i] && ! reload_optional[i] && ! reload_nocombine[i]
1543         /* Life span of this reload must not extend past main insn.  */
1544         && reload_when_needed[i] != RELOAD_FOR_OUTPUT_ADDRESS
1545         && reload_when_needed[i] != RELOAD_FOR_OUTADDR_ADDRESS
1546         && reload_when_needed[i] != RELOAD_OTHER
1547         && (CLASS_MAX_NREGS (reload_reg_class[i], reload_inmode[i])
1548             == CLASS_MAX_NREGS (reload_reg_class[output_reload],
1549                                 reload_outmode[output_reload]))
1550         && reload_inc[i] == 0
1551         && reload_reg_rtx[i] == 0
1552 #ifdef SECONDARY_MEMORY_NEEDED
1553         /* Don't combine two reloads with different secondary
1554            memory locations.  */
1555         && (secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[i]] == 0
1556             || secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[output_reload]] == 0
1557             || rtx_equal_p (secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[i]],
1558                             secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[output_reload]]))
1559 #endif
1560         && (
1561 #ifdef SMALL_REGISTER_CLASSES
1562             SMALL_REGISTER_CLASSES
1563 #else
1564             0
1565 #endif
1566               ? reload_reg_class[i] == reload_reg_class[output_reload]
1567               : (reg_class_subset_p (reload_reg_class[i],
1568                                      reload_reg_class[output_reload])
1569                  || reg_class_subset_p (reload_reg_class[output_reload],
1570                                         reload_reg_class[i])))
1571         && (MATCHES (reload_in[i], reload_out[output_reload])
1572             /* Args reversed because the first arg seems to be
1573                the one that we imagine being modified
1574                while the second is the one that might be affected.  */
1575             || (! reg_overlap_mentioned_for_reload_p (reload_out[output_reload],
1576                                                       reload_in[i])
1577                 /* However, if the input is a register that appears inside
1578                    the output, then we also can't share.
1579                    Imagine (set (mem (reg 69)) (plus (reg 69) ...)).
1580                    If the same reload reg is used for both reg 69 and the
1581                    result to be stored in memory, then that result
1582                    will clobber the address of the memory ref.  */
1583                 && ! (GET_CODE (reload_in[i]) == REG
1584                       && reg_overlap_mentioned_for_reload_p (reload_in[i],
1585                                                              reload_out[output_reload]))))
1586         && (reg_class_size[(int) reload_reg_class[i]]
1587 #ifdef SMALL_REGISTER_CLASSES
1588              || SMALL_REGISTER_CLASSES
1589 #endif
1590             )
1591         /* We will allow making things slightly worse by combining an
1592            input and an output, but no worse than that.  */
1593         && (reload_when_needed[i] == RELOAD_FOR_INPUT
1594             || reload_when_needed[i] == RELOAD_FOR_OUTPUT))
1595       {
1596         int j;
1597
1598         /* We have found a reload to combine with!  */
1599         reload_out[i] = reload_out[output_reload];
1600         reload_outmode[i] = reload_outmode[output_reload];
1601         /* Mark the old output reload as inoperative.  */
1602         reload_out[output_reload] = 0;
1603         /* The combined reload is needed for the entire insn.  */
1604         reload_when_needed[i] = RELOAD_OTHER;
1605         /* If the output reload had a secondary reload, copy it.  */
1606         if (reload_secondary_out_reload[output_reload] != -1)
1607           {
1608             reload_secondary_out_reload[i]
1609               = reload_secondary_out_reload[output_reload];
1610             reload_secondary_out_icode[i]
1611               = reload_secondary_out_icode[output_reload];
1612           }
1613
1614 #ifdef SECONDARY_MEMORY_NEEDED
1615         /* Copy any secondary MEM.  */
1616         if (secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[output_reload]] != 0)
1617           secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[i]]
1618             = secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[output_reload]];
1619 #endif
1620         /* If required, minimize the register class.  */
1621         if (reg_class_subset_p (reload_reg_class[output_reload],
1622                                 reload_reg_class[i]))
1623           reload_reg_class[i] = reload_reg_class[output_reload];
1624
1625         /* Transfer all replacements from the old reload to the combined.  */
1626         for (j = 0; j < n_replacements; j++)
1627           if (replacements[j].what == output_reload)
1628             replacements[j].what = i;
1629
1630         return;
1631       }
1632
1633   /* If this insn has only one operand that is modified or written (assumed
1634      to be the first),  it must be the one corresponding to this reload.  It
1635      is safe to use anything that dies in this insn for that output provided
1636      that it does not occur in the output (we already know it isn't an
1637      earlyclobber.  If this is an asm insn, give up.  */
1638
1639   if (INSN_CODE (this_insn) == -1)
1640     return;
1641
1642   for (i = 1; i < insn_n_operands[INSN_CODE (this_insn)]; i++)
1643     if (insn_operand_constraint[INSN_CODE (this_insn)][i][0] == '='
1644         || insn_operand_constraint[INSN_CODE (this_insn)][i][0] == '+')
1645       return;
1646
1647   /* See if some hard register that dies in this insn and is not used in
1648      the output is the right class.  Only works if the register we pick
1649      up can fully hold our output reload.  */
1650   for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1651     if (REG_NOTE_KIND (note) == REG_DEAD
1652         && GET_CODE (XEXP (note, 0)) == REG
1653         && ! reg_overlap_mentioned_for_reload_p (XEXP (note, 0),
1654                                                  reload_out[output_reload])
1655         && REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1656         && HARD_REGNO_MODE_OK (REGNO (XEXP (note, 0)), reload_outmode[output_reload])
1657         && TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[output_reload]],
1658                               REGNO (XEXP (note, 0)))
1659         && (HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), reload_outmode[output_reload])
1660             <= HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), GET_MODE (XEXP (note, 0))))
1661         /* Ensure that a secondary or tertiary reload for this output
1662            won't want this register.  */
1663         && ((secondary_out = reload_secondary_out_reload[output_reload]) == -1
1664             || (! (TEST_HARD_REG_BIT
1665                     (reg_class_contents[(int) reload_reg_class[secondary_out]],
1666                      REGNO (XEXP (note, 0))))
1667                 && ((secondary_out = reload_secondary_out_reload[secondary_out]) == -1
1668                     ||  ! (TEST_HARD_REG_BIT
1669                            (reg_class_contents[(int) reload_reg_class[secondary_out]],
1670                             REGNO (XEXP (note, 0)))))))
1671         && ! fixed_regs[REGNO (XEXP (note, 0))])
1672       {
1673         reload_reg_rtx[output_reload] = gen_rtx (REG,
1674                                                  reload_outmode[output_reload],
1675                                                  REGNO (XEXP (note, 0)));
1676         return;
1677       }
1678 }
1679 \f
1680 /* Try to find a reload register for an in-out reload (expressions IN and OUT).
1681    See if one of IN and OUT is a register that may be used;
1682    this is desirable since a spill-register won't be needed.
1683    If so, return the register rtx that proves acceptable.
1684
1685    INLOC and OUTLOC are locations where IN and OUT appear in the insn.
1686    CLASS is the register class required for the reload.
1687
1688    If FOR_REAL is >= 0, it is the number of the reload,
1689    and in some cases when it can be discovered that OUT doesn't need
1690    to be computed, clear out reload_out[FOR_REAL].
1691
1692    If FOR_REAL is -1, this should not be done, because this call
1693    is just to see if a register can be found, not to find and install it.
1694
1695    EARLYCLOBBER is non-zero if OUT is an earlyclobber operand.  This
1696    puts an additional constraint on being able to use IN for OUT since
1697    IN must not appear elsewhere in the insn (it is assumed that IN itself
1698    is safe from the earlyclobber).  */
1699
1700 static rtx
1701 find_dummy_reload (real_in, real_out, inloc, outloc,
1702                    inmode, outmode, class, for_real, earlyclobber)
1703      rtx real_in, real_out;
1704      rtx *inloc, *outloc;
1705      enum machine_mode inmode, outmode;
1706      enum reg_class class;
1707      int for_real;
1708      int earlyclobber;
1709 {
1710   rtx in = real_in;
1711   rtx out = real_out;
1712   int in_offset = 0;
1713   int out_offset = 0;
1714   rtx value = 0;
1715
1716   /* If operands exceed a word, we can't use either of them
1717      unless they have the same size.  */
1718   if (GET_MODE_SIZE (outmode) != GET_MODE_SIZE (inmode)
1719       && (GET_MODE_SIZE (outmode) > UNITS_PER_WORD
1720           || GET_MODE_SIZE (inmode) > UNITS_PER_WORD))
1721     return 0;
1722
1723   /* Find the inside of any subregs.  */
1724   while (GET_CODE (out) == SUBREG)
1725     {
1726       out_offset = SUBREG_WORD (out);
1727       out = SUBREG_REG (out);
1728     }
1729   while (GET_CODE (in) == SUBREG)
1730     {
1731       in_offset = SUBREG_WORD (in);
1732       in = SUBREG_REG (in);
1733     }
1734
1735   /* Narrow down the reg class, the same way push_reload will;
1736      otherwise we might find a dummy now, but push_reload won't.  */
1737   class = PREFERRED_RELOAD_CLASS (in, class);
1738
1739   /* See if OUT will do.  */
1740   if (GET_CODE (out) == REG
1741       && REGNO (out) < FIRST_PSEUDO_REGISTER)
1742     {
1743       register int regno = REGNO (out) + out_offset;
1744       int nwords = HARD_REGNO_NREGS (regno, outmode);
1745       rtx saved_rtx;
1746
1747       /* When we consider whether the insn uses OUT,
1748          ignore references within IN.  They don't prevent us
1749          from copying IN into OUT, because those refs would
1750          move into the insn that reloads IN.
1751
1752          However, we only ignore IN in its role as this reload.
1753          If the insn uses IN elsewhere and it contains OUT,
1754          that counts.  We can't be sure it's the "same" operand
1755          so it might not go through this reload.  */
1756       saved_rtx = *inloc;
1757       *inloc = const0_rtx;
1758
1759       if (regno < FIRST_PSEUDO_REGISTER
1760           /* A fixed reg that can overlap other regs better not be used
1761              for reloading in any way.  */
1762 #ifdef OVERLAPPING_REGNO_P
1763           && ! (fixed_regs[regno] && OVERLAPPING_REGNO_P (regno))
1764 #endif
1765           && ! refers_to_regno_for_reload_p (regno, regno + nwords,
1766                                              PATTERN (this_insn), outloc))
1767         {
1768           int i;
1769           for (i = 0; i < nwords; i++)
1770             if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1771                                      regno + i))
1772               break;
1773
1774           if (i == nwords)
1775             {
1776               if (GET_CODE (real_out) == REG)
1777                 value = real_out;
1778               else
1779                 value = gen_rtx (REG, outmode, regno);
1780             }
1781         }
1782
1783       *inloc = saved_rtx;
1784     }
1785
1786   /* Consider using IN if OUT was not acceptable
1787      or if OUT dies in this insn (like the quotient in a divmod insn).
1788      We can't use IN unless it is dies in this insn,
1789      which means we must know accurately which hard regs are live.
1790      Also, the result can't go in IN if IN is used within OUT,
1791      or if OUT is an earlyclobber and IN appears elsewhere in the insn.  */
1792   if (hard_regs_live_known
1793       && GET_CODE (in) == REG
1794       && REGNO (in) < FIRST_PSEUDO_REGISTER
1795       && (value == 0
1796           || find_reg_note (this_insn, REG_UNUSED, real_out))
1797       && find_reg_note (this_insn, REG_DEAD, real_in)
1798       && !fixed_regs[REGNO (in)]
1799       && HARD_REGNO_MODE_OK (REGNO (in),
1800                              /* The only case where out and real_out might
1801                                 have different modes is where real_out
1802                                 is a subreg, and in that case, out
1803                                 has a real mode.  */
1804                              (GET_MODE (out) != VOIDmode
1805                               ? GET_MODE (out) : outmode)))
1806     {
1807       register int regno = REGNO (in) + in_offset;
1808       int nwords = HARD_REGNO_NREGS (regno, inmode);
1809
1810       if (! refers_to_regno_for_reload_p (regno, regno + nwords, out, NULL_PTR)
1811           && ! hard_reg_set_here_p (regno, regno + nwords,
1812                                     PATTERN (this_insn))
1813           && (! earlyclobber
1814               || ! refers_to_regno_for_reload_p (regno, regno + nwords,
1815                                                  PATTERN (this_insn), inloc)))
1816         {
1817           int i;
1818           for (i = 0; i < nwords; i++)
1819             if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1820                                      regno + i))
1821               break;
1822
1823           if (i == nwords)
1824             {
1825               /* If we were going to use OUT as the reload reg
1826                  and changed our mind, it means OUT is a dummy that
1827                  dies here.  So don't bother copying value to it.  */
1828               if (for_real >= 0 && value == real_out)
1829                 reload_out[for_real] = 0;
1830               if (GET_CODE (real_in) == REG)
1831                 value = real_in;
1832               else
1833                 value = gen_rtx (REG, inmode, regno);
1834             }
1835         }
1836     }
1837
1838   return value;
1839 }
1840 \f
1841 /* This page contains subroutines used mainly for determining
1842    whether the IN or an OUT of a reload can serve as the
1843    reload register.  */
1844
1845 /* Return 1 if X is an operand of an insn that is being earlyclobbered.  */
1846
1847 static int
1848 earlyclobber_operand_p (x)
1849      rtx x;
1850 {
1851   int i;
1852
1853   for (i = 0; i < n_earlyclobbers; i++)
1854     if (reload_earlyclobbers[i] == x)
1855       return 1;
1856
1857   return 0;
1858 }
1859
1860 /* Return 1 if expression X alters a hard reg in the range
1861    from BEG_REGNO (inclusive) to END_REGNO (exclusive),
1862    either explicitly or in the guise of a pseudo-reg allocated to REGNO.
1863    X should be the body of an instruction.  */
1864
1865 static int
1866 hard_reg_set_here_p (beg_regno, end_regno, x)
1867      register int beg_regno, end_regno;
1868      rtx x;
1869 {
1870   if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
1871     {
1872       register rtx op0 = SET_DEST (x);
1873       while (GET_CODE (op0) == SUBREG)
1874         op0 = SUBREG_REG (op0);
1875       if (GET_CODE (op0) == REG)
1876         {
1877           register int r = REGNO (op0);
1878           /* See if this reg overlaps range under consideration.  */
1879           if (r < end_regno
1880               && r + HARD_REGNO_NREGS (r, GET_MODE (op0)) > beg_regno)
1881             return 1;
1882         }
1883     }
1884   else if (GET_CODE (x) == PARALLEL)
1885     {
1886       register int i = XVECLEN (x, 0) - 1;
1887       for (; i >= 0; i--)
1888         if (hard_reg_set_here_p (beg_regno, end_regno, XVECEXP (x, 0, i)))
1889           return 1;
1890     }
1891
1892   return 0;
1893 }
1894
1895 /* Return 1 if ADDR is a valid memory address for mode MODE,
1896    and check that each pseudo reg has the proper kind of
1897    hard reg.  */
1898
1899 int
1900 strict_memory_address_p (mode, addr)
1901      enum machine_mode mode;
1902      register rtx addr;
1903 {
1904   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1905   return 0;
1906
1907  win:
1908   return 1;
1909 }
1910 \f
1911 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
1912    if they are the same hard reg, and has special hacks for
1913    autoincrement and autodecrement.
1914    This is specifically intended for find_reloads to use
1915    in determining whether two operands match.
1916    X is the operand whose number is the lower of the two.
1917
1918    The value is 2 if Y contains a pre-increment that matches
1919    a non-incrementing address in X.  */
1920
1921 /* ??? To be completely correct, we should arrange to pass
1922    for X the output operand and for Y the input operand.
1923    For now, we assume that the output operand has the lower number
1924    because that is natural in (SET output (... input ...)).  */
1925
1926 int
1927 operands_match_p (x, y)
1928      register rtx x, y;
1929 {
1930   register int i;
1931   register RTX_CODE code = GET_CODE (x);
1932   register char *fmt;
1933   int success_2;
1934       
1935   if (x == y)
1936     return 1;
1937   if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
1938       && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
1939                                   && GET_CODE (SUBREG_REG (y)) == REG)))
1940     {
1941       register int j;
1942
1943       if (code == SUBREG)
1944         {
1945           i = REGNO (SUBREG_REG (x));
1946           if (i >= FIRST_PSEUDO_REGISTER)
1947             goto slow;
1948           i += SUBREG_WORD (x);
1949         }
1950       else
1951         i = REGNO (x);
1952
1953       if (GET_CODE (y) == SUBREG)
1954         {
1955           j = REGNO (SUBREG_REG (y));
1956           if (j >= FIRST_PSEUDO_REGISTER)
1957             goto slow;
1958           j += SUBREG_WORD (y);
1959         }
1960       else
1961         j = REGNO (y);
1962
1963       /* On a WORDS_BIG_ENDIAN machine, point to the last register of a
1964          multiple hard register group, so that for example (reg:DI 0) and
1965          (reg:SI 1) will be considered the same register.  */
1966       if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
1967           && i < FIRST_PSEUDO_REGISTER)
1968         i += (GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD) - 1;
1969       if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (y)) > UNITS_PER_WORD
1970           && j < FIRST_PSEUDO_REGISTER)
1971         j += (GET_MODE_SIZE (GET_MODE (y)) / UNITS_PER_WORD) - 1;
1972
1973       return i == j;
1974     }
1975   /* If two operands must match, because they are really a single
1976      operand of an assembler insn, then two postincrements are invalid
1977      because the assembler insn would increment only once.
1978      On the other hand, an postincrement matches ordinary indexing
1979      if the postincrement is the output operand.  */
1980   if (code == POST_DEC || code == POST_INC)
1981     return operands_match_p (XEXP (x, 0), y);
1982   /* Two preincrements are invalid
1983      because the assembler insn would increment only once.
1984      On the other hand, an preincrement matches ordinary indexing
1985      if the preincrement is the input operand.
1986      In this case, return 2, since some callers need to do special
1987      things when this happens.  */
1988   if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC)
1989     return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
1990
1991  slow:
1992
1993   /* Now we have disposed of all the cases 
1994      in which different rtx codes can match.  */
1995   if (code != GET_CODE (y))
1996     return 0;
1997   if (code == LABEL_REF)
1998     return XEXP (x, 0) == XEXP (y, 0);
1999   if (code == SYMBOL_REF)
2000     return XSTR (x, 0) == XSTR (y, 0);
2001
2002   /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.  */
2003
2004   if (GET_MODE (x) != GET_MODE (y))
2005     return 0;
2006
2007   /* Compare the elements.  If any pair of corresponding elements
2008      fail to match, return 0 for the whole things.  */
2009
2010   success_2 = 0;
2011   fmt = GET_RTX_FORMAT (code);
2012   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2013     {
2014       int val;
2015       switch (fmt[i])
2016         {
2017         case 'w':
2018           if (XWINT (x, i) != XWINT (y, i))
2019             return 0;
2020           break;
2021
2022         case 'i':
2023           if (XINT (x, i) != XINT (y, i))
2024             return 0;
2025           break;
2026
2027         case 'e':
2028           val = operands_match_p (XEXP (x, i), XEXP (y, i));
2029           if (val == 0)
2030             return 0;
2031           /* If any subexpression returns 2,
2032              we should return 2 if we are successful.  */
2033           if (val == 2)
2034             success_2 = 1;
2035           break;
2036
2037         case '0':
2038           break;
2039
2040           /* It is believed that rtx's at this level will never
2041              contain anything but integers and other rtx's,
2042              except for within LABEL_REFs and SYMBOL_REFs.  */
2043         default:
2044           abort ();
2045         }
2046     }
2047   return 1 + success_2;
2048 }
2049 \f
2050 /* Return the number of times character C occurs in string S.  */
2051
2052 int
2053 n_occurrences (c, s)
2054      int c;
2055      char *s;
2056 {
2057   int n = 0;
2058   while (*s)
2059     n += (*s++ == c);
2060   return n;
2061 }
2062 \f
2063 /* Describe the range of registers or memory referenced by X.
2064    If X is a register, set REG_FLAG and put the first register 
2065    number into START and the last plus one into END.
2066    If X is a memory reference, put a base address into BASE 
2067    and a range of integer offsets into START and END.
2068    If X is pushing on the stack, we can assume it causes no trouble, 
2069    so we set the SAFE field.  */
2070
2071 static struct decomposition
2072 decompose (x)
2073      rtx x;
2074 {
2075   struct decomposition val;
2076   int all_const = 0;
2077
2078   val.reg_flag = 0;
2079   val.safe = 0;
2080   if (GET_CODE (x) == MEM)
2081     {
2082       rtx base, offset = 0;
2083       rtx addr = XEXP (x, 0);
2084
2085       if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
2086           || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
2087         {
2088           val.base = XEXP (addr, 0);
2089           val.start = - GET_MODE_SIZE (GET_MODE (x));
2090           val.end = GET_MODE_SIZE (GET_MODE (x));
2091           val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2092           return val;
2093         }
2094
2095       if (GET_CODE (addr) == CONST)
2096         {
2097           addr = XEXP (addr, 0);
2098           all_const = 1;
2099         }
2100       if (GET_CODE (addr) == PLUS)
2101         {
2102           if (CONSTANT_P (XEXP (addr, 0)))
2103             {
2104               base = XEXP (addr, 1);
2105               offset = XEXP (addr, 0);
2106             }
2107           else if (CONSTANT_P (XEXP (addr, 1)))
2108             {
2109               base = XEXP (addr, 0);
2110               offset = XEXP (addr, 1);
2111             }
2112         }
2113
2114       if (offset == 0)
2115         {
2116           base = addr;
2117           offset = const0_rtx;
2118         } 
2119       if (GET_CODE (offset) == CONST)
2120         offset = XEXP (offset, 0);
2121       if (GET_CODE (offset) == PLUS)
2122         {
2123           if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
2124             {
2125               base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 1));
2126               offset = XEXP (offset, 0);
2127             }
2128           else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
2129             {
2130               base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 0));
2131               offset = XEXP (offset, 1);
2132             }
2133           else
2134             {
2135               base = gen_rtx (PLUS, GET_MODE (base), base, offset);
2136               offset = const0_rtx;
2137             }
2138         }
2139       else if (GET_CODE (offset) != CONST_INT)
2140         {
2141           base = gen_rtx (PLUS, GET_MODE (base), base, offset);
2142           offset = const0_rtx;
2143         }
2144
2145       if (all_const && GET_CODE (base) == PLUS)
2146         base = gen_rtx (CONST, GET_MODE (base), base);
2147
2148       if (GET_CODE (offset) != CONST_INT)
2149         abort ();
2150
2151       val.start = INTVAL (offset);
2152       val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
2153       val.base = base;
2154       return val;
2155     }
2156   else if (GET_CODE (x) == REG)
2157     {
2158       val.reg_flag = 1;
2159       val.start = true_regnum (x); 
2160       if (val.start < 0)
2161         {
2162           /* A pseudo with no hard reg.  */
2163           val.start = REGNO (x);
2164           val.end = val.start + 1;
2165         }
2166       else
2167         /* A hard reg.  */
2168         val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2169     }
2170   else if (GET_CODE (x) == SUBREG)
2171     {
2172       if (GET_CODE (SUBREG_REG (x)) != REG)
2173         /* This could be more precise, but it's good enough.  */
2174         return decompose (SUBREG_REG (x));
2175       val.reg_flag = 1;
2176       val.start = true_regnum (x); 
2177       if (val.start < 0)
2178         return decompose (SUBREG_REG (x));
2179       else
2180         /* A hard reg.  */
2181         val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2182     }
2183   else if (CONSTANT_P (x)
2184            /* This hasn't been assigned yet, so it can't conflict yet.  */
2185            || GET_CODE (x) == SCRATCH)
2186     val.safe = 1;
2187   else
2188     abort ();
2189   return val;
2190 }
2191
2192 /* Return 1 if altering Y will not modify the value of X.
2193    Y is also described by YDATA, which should be decompose (Y).  */
2194
2195 static int
2196 immune_p (x, y, ydata)
2197      rtx x, y;
2198      struct decomposition ydata;
2199 {
2200   struct decomposition xdata;
2201
2202   if (ydata.reg_flag)
2203     return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, NULL_PTR);
2204   if (ydata.safe)
2205     return 1;
2206
2207   if (GET_CODE (y) != MEM)
2208     abort ();
2209   /* If Y is memory and X is not, Y can't affect X.  */
2210   if (GET_CODE (x) != MEM)
2211     return 1;
2212
2213   xdata =  decompose (x);
2214
2215   if (! rtx_equal_p (xdata.base, ydata.base))
2216     {
2217       /* If bases are distinct symbolic constants, there is no overlap.  */
2218       if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
2219         return 1;
2220       /* Constants and stack slots never overlap.  */
2221       if (CONSTANT_P (xdata.base)
2222           && (ydata.base == frame_pointer_rtx
2223               || ydata.base == hard_frame_pointer_rtx
2224               || ydata.base == stack_pointer_rtx))
2225         return 1;
2226       if (CONSTANT_P (ydata.base)
2227           && (xdata.base == frame_pointer_rtx
2228               || xdata.base == hard_frame_pointer_rtx
2229               || xdata.base == stack_pointer_rtx))
2230         return 1;
2231       /* If either base is variable, we don't know anything.  */
2232       return 0;
2233     }
2234
2235
2236   return (xdata.start >= ydata.end || ydata.start >= xdata.end);
2237 }
2238
2239 /* Similar, but calls decompose.  */
2240
2241 int
2242 safe_from_earlyclobber (op, clobber)
2243      rtx op, clobber;
2244 {
2245   struct decomposition early_data;
2246
2247   early_data = decompose (clobber);
2248   return immune_p (op, clobber, early_data);
2249 }
2250 \f
2251 /* Main entry point of this file: search the body of INSN
2252    for values that need reloading and record them with push_reload.
2253    REPLACE nonzero means record also where the values occur
2254    so that subst_reloads can be used.
2255
2256    IND_LEVELS says how many levels of indirection are supported by this
2257    machine; a value of zero means that a memory reference is not a valid
2258    memory address.
2259
2260    LIVE_KNOWN says we have valid information about which hard
2261    regs are live at each point in the program; this is true when
2262    we are called from global_alloc but false when stupid register
2263    allocation has been done.
2264
2265    RELOAD_REG_P if nonzero is a vector indexed by hard reg number
2266    which is nonnegative if the reg has been commandeered for reloading into.
2267    It is copied into STATIC_RELOAD_REG_P and referenced from there
2268    by various subroutines.  */
2269
2270 void
2271 find_reloads (insn, replace, ind_levels, live_known, reload_reg_p)
2272      rtx insn;
2273      int replace, ind_levels;
2274      int live_known;
2275      short *reload_reg_p;
2276 {
2277 #ifdef REGISTER_CONSTRAINTS
2278
2279   register int insn_code_number;
2280   register int i, j;
2281   int noperands;
2282   /* These are the constraints for the insn.  We don't change them.  */
2283   char *constraints1[MAX_RECOG_OPERANDS];
2284   /* These start out as the constraints for the insn
2285      and they are chewed up as we consider alternatives.  */
2286   char *constraints[MAX_RECOG_OPERANDS];
2287   /* These are the preferred classes for an operand, or NO_REGS if it isn't
2288      a register.  */
2289   enum reg_class preferred_class[MAX_RECOG_OPERANDS];
2290   char pref_or_nothing[MAX_RECOG_OPERANDS];
2291   /* Nonzero for a MEM operand whose entire address needs a reload.  */
2292   int address_reloaded[MAX_RECOG_OPERANDS];
2293   /* Value of enum reload_type to use for operand.  */
2294   enum reload_type operand_type[MAX_RECOG_OPERANDS];
2295   /* Value of enum reload_type to use within address of operand.  */
2296   enum reload_type address_type[MAX_RECOG_OPERANDS];
2297   /* Save the usage of each operand.  */
2298   enum reload_usage { RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE } modified[MAX_RECOG_OPERANDS];
2299   int no_input_reloads = 0, no_output_reloads = 0;
2300   int n_alternatives;
2301   int this_alternative[MAX_RECOG_OPERANDS];
2302   char this_alternative_win[MAX_RECOG_OPERANDS];
2303   char this_alternative_offmemok[MAX_RECOG_OPERANDS];
2304   char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2305   int this_alternative_matches[MAX_RECOG_OPERANDS];
2306   int swapped;
2307   int goal_alternative[MAX_RECOG_OPERANDS];
2308   int this_alternative_number;
2309   int goal_alternative_number;
2310   int operand_reloadnum[MAX_RECOG_OPERANDS];
2311   int goal_alternative_matches[MAX_RECOG_OPERANDS];
2312   int goal_alternative_matched[MAX_RECOG_OPERANDS];
2313   char goal_alternative_win[MAX_RECOG_OPERANDS];
2314   char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
2315   char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2316   int goal_alternative_swapped;
2317   int best;
2318   int commutative;
2319   char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
2320   rtx substed_operand[MAX_RECOG_OPERANDS];
2321   rtx body = PATTERN (insn);
2322   rtx set = single_set (insn);
2323   int goal_earlyclobber, this_earlyclobber;
2324   enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
2325
2326   this_insn = insn;
2327   this_insn_is_asm = 0;         /* Tentative.  */
2328   n_reloads = 0;
2329   n_replacements = 0;
2330   n_memlocs = 0;
2331   n_earlyclobbers = 0;
2332   replace_reloads = replace;
2333   hard_regs_live_known = live_known;
2334   static_reload_reg_p = reload_reg_p;
2335
2336   /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads;
2337      neither are insns that SET cc0.  Insns that use CC0 are not allowed
2338      to have any input reloads.  */
2339   if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == CALL_INSN)
2340     no_output_reloads = 1;
2341
2342 #ifdef HAVE_cc0
2343   if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
2344     no_input_reloads = 1;
2345   if (reg_set_p (cc0_rtx, PATTERN (insn)))
2346     no_output_reloads = 1;
2347 #endif
2348      
2349 #ifdef SECONDARY_MEMORY_NEEDED
2350   /* The eliminated forms of any secondary memory locations are per-insn, so
2351      clear them out here.  */
2352
2353   bzero ((char *) secondary_memlocs_elim, sizeof secondary_memlocs_elim);
2354 #endif
2355
2356   /* Find what kind of insn this is.  NOPERANDS gets number of operands.
2357      Make OPERANDS point to a vector of operand values.
2358      Make OPERAND_LOCS point to a vector of pointers to
2359      where the operands were found.
2360      Fill CONSTRAINTS and CONSTRAINTS1 with pointers to the
2361      constraint-strings for this insn.
2362      Return if the insn needs no reload processing.  */
2363
2364   switch (GET_CODE (body))
2365     {
2366     case USE:
2367     case CLOBBER:
2368     case ASM_INPUT:
2369     case ADDR_VEC:
2370     case ADDR_DIFF_VEC:
2371       return;
2372
2373     case SET:
2374       /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it
2375          is cheap to move between them.  If it is not, there may not be an insn
2376          to do the copy, so we may need a reload.  */
2377       if (GET_CODE (SET_DEST (body)) == REG
2378           && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
2379           && GET_CODE (SET_SRC (body)) == REG
2380           && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER
2381           && REGISTER_MOVE_COST (REGNO_REG_CLASS (REGNO (SET_SRC (body))),
2382                                  REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2)
2383         return;
2384     case PARALLEL:
2385     case ASM_OPERANDS:
2386       reload_n_operands = noperands = asm_noperands (body);
2387       if (noperands >= 0)
2388         {
2389           /* This insn is an `asm' with operands.  */
2390
2391           insn_code_number = -1;
2392           this_insn_is_asm = 1;
2393
2394           /* expand_asm_operands makes sure there aren't too many operands.  */
2395           if (noperands > MAX_RECOG_OPERANDS)
2396             abort ();
2397
2398           /* Now get the operand values and constraints out of the insn.  */
2399
2400           decode_asm_operands (body, recog_operand, recog_operand_loc,
2401                                constraints, operand_mode);
2402           if (noperands > 0)
2403             {
2404               bcopy ((char *) constraints, (char *) constraints1,
2405                      noperands * sizeof (char *));
2406               n_alternatives = n_occurrences (',', constraints[0]) + 1;
2407               for (i = 1; i < noperands; i++)
2408                 if (n_alternatives != n_occurrences (',', constraints[i]) + 1)
2409                   {
2410                     error_for_asm (insn, "operand constraints differ in number of alternatives");
2411                     /* Avoid further trouble with this insn.  */
2412                     PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
2413                     n_reloads = 0;
2414                     return;
2415                   }
2416             }
2417           break;
2418         }
2419
2420     default:
2421       /* Ordinary insn: recognize it, get the operands via insn_extract
2422          and get the constraints.  */
2423
2424       insn_code_number = recog_memoized (insn);
2425       if (insn_code_number < 0)
2426         fatal_insn_not_found (insn);
2427
2428       reload_n_operands = noperands = insn_n_operands[insn_code_number];
2429       n_alternatives = insn_n_alternatives[insn_code_number];
2430       /* Just return "no reloads" if insn has no operands with constraints.  */
2431       if (n_alternatives == 0)
2432         return;
2433       insn_extract (insn);
2434       for (i = 0; i < noperands; i++)
2435         {
2436           constraints[i] = constraints1[i]
2437             = insn_operand_constraint[insn_code_number][i];
2438           operand_mode[i] = insn_operand_mode[insn_code_number][i];
2439         }
2440     }
2441
2442   if (noperands == 0)
2443     return;
2444
2445   commutative = -1;
2446
2447   /* If we will need to know, later, whether some pair of operands
2448      are the same, we must compare them now and save the result.
2449      Reloading the base and index registers will clobber them
2450      and afterward they will fail to match.  */
2451
2452   for (i = 0; i < noperands; i++)
2453     {
2454       register char *p;
2455       register int c;
2456
2457       substed_operand[i] = recog_operand[i];
2458       p = constraints[i];
2459
2460       modified[i] = RELOAD_READ;
2461
2462       /* Scan this operand's constraint to see if it is an output operand, 
2463          an in-out operand, is commutative, or should match another.  */
2464
2465       while (c = *p++)
2466         {
2467           if (c == '=')
2468             modified[i] = RELOAD_WRITE;
2469           else if (c == '+')
2470             modified[i] = RELOAD_READ_WRITE;
2471           else if (c == '%')
2472             {
2473               /* The last operand should not be marked commutative.  */
2474               if (i == noperands - 1)
2475                 {
2476                   if (this_insn_is_asm)
2477                     warning_for_asm (this_insn,
2478                                      "`%%' constraint used with last operand");
2479                   else
2480                     abort ();
2481                 }
2482               else
2483                 commutative = i;
2484             }
2485           else if (c >= '0' && c <= '9')
2486             {
2487               c -= '0';
2488               operands_match[c][i]
2489                 = operands_match_p (recog_operand[c], recog_operand[i]);
2490
2491               /* An operand may not match itself.  */
2492               if (c == i)
2493                 {
2494                   if (this_insn_is_asm)
2495                     warning_for_asm (this_insn,
2496                                      "operand %d has constraint %d", i, c);
2497                   else
2498                     abort ();
2499                 }
2500
2501               /* If C can be commuted with C+1, and C might need to match I,
2502                  then C+1 might also need to match I.  */
2503               if (commutative >= 0)
2504                 {
2505                   if (c == commutative || c == commutative + 1)
2506                     {
2507                       int other = c + (c == commutative ? 1 : -1);
2508                       operands_match[other][i]
2509                         = operands_match_p (recog_operand[other], recog_operand[i]);
2510                     }
2511                   if (i == commutative || i == commutative + 1)
2512                     {
2513                       int other = i + (i == commutative ? 1 : -1);
2514                       operands_match[c][other]
2515                         = operands_match_p (recog_operand[c], recog_operand[other]);
2516                     }
2517                   /* Note that C is supposed to be less than I.
2518                      No need to consider altering both C and I because in
2519                      that case we would alter one into the other.  */
2520                 }
2521             }
2522         }
2523     }
2524
2525   /* Examine each operand that is a memory reference or memory address
2526      and reload parts of the addresses into index registers.
2527      Also here any references to pseudo regs that didn't get hard regs
2528      but are equivalent to constants get replaced in the insn itself
2529      with those constants.  Nobody will ever see them again. 
2530
2531      Finally, set up the preferred classes of each operand.  */
2532
2533   for (i = 0; i < noperands; i++)
2534     {
2535       register RTX_CODE code = GET_CODE (recog_operand[i]);
2536
2537       address_reloaded[i] = 0;
2538       operand_type[i] = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT
2539                          : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT
2540                          : RELOAD_OTHER);
2541       address_type[i]
2542         = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT_ADDRESS
2543            : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT_ADDRESS
2544            : RELOAD_OTHER);
2545
2546       if (*constraints[i] == 0)
2547         /* Ignore things like match_operator operands.  */
2548         ;
2549       else if (constraints[i][0] == 'p')
2550         {
2551           find_reloads_address (VOIDmode, NULL_PTR,
2552                                 recog_operand[i], recog_operand_loc[i],
2553                                 i, operand_type[i], ind_levels, insn);
2554
2555           /* If we now have a simple operand where we used to have a 
2556              PLUS or MULT, re-recognize and try again.  */
2557           if ((GET_RTX_CLASS (GET_CODE (*recog_operand_loc[i])) == 'o'
2558                || GET_CODE (*recog_operand_loc[i]) == SUBREG)
2559               && (GET_CODE (recog_operand[i]) == MULT
2560                   || GET_CODE (recog_operand[i]) == PLUS))
2561             {
2562               INSN_CODE (insn) = -1;
2563               find_reloads (insn, replace, ind_levels, live_known,
2564                             reload_reg_p);
2565               return;
2566             }
2567
2568           substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2569         }
2570       else if (code == MEM)
2571         {
2572           if (find_reloads_address (GET_MODE (recog_operand[i]),
2573                                     recog_operand_loc[i],
2574                                     XEXP (recog_operand[i], 0),
2575                                     &XEXP (recog_operand[i], 0),
2576                                     i, address_type[i], ind_levels, insn))
2577             address_reloaded[i] = 1;
2578           substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2579         }
2580       else if (code == SUBREG)
2581         substed_operand[i] = recog_operand[i] = *recog_operand_loc[i]
2582           = find_reloads_toplev (recog_operand[i], i, address_type[i],
2583                                  ind_levels,
2584                                  set != 0
2585                                  && &SET_DEST (set) == recog_operand_loc[i]);
2586       else if (code == PLUS || GET_RTX_CLASS (code) == '1')
2587         /* We can get a PLUS as an "operand" as a result of register
2588            elimination.  See eliminate_regs and gen_reload.  We handle
2589            a unary operator by reloading the operand.  */
2590         substed_operand[i] = recog_operand[i] = *recog_operand_loc[i]
2591           = find_reloads_toplev (recog_operand[i], i, address_type[i],
2592                                  ind_levels, 0);
2593       else if (code == REG)
2594         {
2595           /* This is equivalent to calling find_reloads_toplev.
2596              The code is duplicated for speed.
2597              When we find a pseudo always equivalent to a constant,
2598              we replace it by the constant.  We must be sure, however,
2599              that we don't try to replace it in the insn in which it
2600              is being set.   */
2601           register int regno = REGNO (recog_operand[i]);
2602           if (reg_equiv_constant[regno] != 0
2603               && (set == 0 || &SET_DEST (set) != recog_operand_loc[i]))
2604             substed_operand[i] = recog_operand[i]
2605               = reg_equiv_constant[regno];
2606 #if 0 /* This might screw code in reload1.c to delete prior output-reload
2607          that feeds this insn.  */
2608           if (reg_equiv_mem[regno] != 0)
2609             substed_operand[i] = recog_operand[i]
2610               = reg_equiv_mem[regno];
2611 #endif
2612           if (reg_equiv_address[regno] != 0)
2613             {
2614               /* If reg_equiv_address is not a constant address, copy it,
2615                  since it may be shared.  */
2616               /* We must rerun eliminate_regs, in case the elimination
2617                  offsets have changed.  */
2618               rtx address = XEXP (eliminate_regs (reg_equiv_memory_loc[regno],
2619                                                   0, NULL_RTX, 0),
2620                                   0);
2621
2622               if (rtx_varies_p (address))
2623                 address = copy_rtx (address);
2624
2625               /* If this is an output operand, we must output a CLOBBER
2626                  after INSN so find_equiv_reg knows REGNO is being written. 
2627                  Mark this insn specially, do we can put our output reloads
2628                  after it.  */
2629
2630               if (modified[i] != RELOAD_READ)
2631                 PUT_MODE (emit_insn_after (gen_rtx (CLOBBER, VOIDmode,
2632                                                     recog_operand[i]),
2633                                            insn),
2634                           DImode);
2635
2636               *recog_operand_loc[i] = recog_operand[i]
2637                 = gen_rtx (MEM, GET_MODE (recog_operand[i]), address);
2638               RTX_UNCHANGING_P (recog_operand[i])
2639                 = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
2640               find_reloads_address (GET_MODE (recog_operand[i]),
2641                                     recog_operand_loc[i],
2642                                     XEXP (recog_operand[i], 0),
2643                                     &XEXP (recog_operand[i], 0),
2644                                     i, address_type[i], ind_levels, insn);
2645               substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2646             }
2647         }
2648       /* If the operand is still a register (we didn't replace it with an
2649          equivalent), get the preferred class to reload it into.  */
2650       code = GET_CODE (recog_operand[i]);
2651       preferred_class[i]
2652         = ((code == REG && REGNO (recog_operand[i]) >= FIRST_PSEUDO_REGISTER)
2653            ? reg_preferred_class (REGNO (recog_operand[i])) : NO_REGS);
2654       pref_or_nothing[i]
2655         = (code == REG && REGNO (recog_operand[i]) >= FIRST_PSEUDO_REGISTER
2656            && reg_alternate_class (REGNO (recog_operand[i])) == NO_REGS);
2657     }
2658
2659   /* If this is simply a copy from operand 1 to operand 0, merge the
2660      preferred classes for the operands.  */
2661   if (set != 0 && noperands >= 2 && recog_operand[0] == SET_DEST (set)
2662       && recog_operand[1] == SET_SRC (set))
2663     {
2664       preferred_class[0] = preferred_class[1]
2665         = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]];
2666       pref_or_nothing[0] |= pref_or_nothing[1];
2667       pref_or_nothing[1] |= pref_or_nothing[0];
2668     }
2669
2670   /* Now see what we need for pseudo-regs that didn't get hard regs
2671      or got the wrong kind of hard reg.  For this, we must consider
2672      all the operands together against the register constraints.  */
2673
2674   best = MAX_RECOG_OPERANDS + 300;
2675
2676   swapped = 0;
2677   goal_alternative_swapped = 0;
2678  try_swapped:
2679
2680   /* The constraints are made of several alternatives.
2681      Each operand's constraint looks like foo,bar,... with commas
2682      separating the alternatives.  The first alternatives for all
2683      operands go together, the second alternatives go together, etc.
2684
2685      First loop over alternatives.  */
2686
2687   for (this_alternative_number = 0;
2688        this_alternative_number < n_alternatives;
2689        this_alternative_number++)
2690     {
2691       /* Loop over operands for one constraint alternative.  */
2692       /* LOSERS counts those that don't fit this alternative
2693          and would require loading.  */
2694       int losers = 0;
2695       /* BAD is set to 1 if it some operand can't fit this alternative
2696          even after reloading.  */
2697       int bad = 0;
2698       /* REJECT is a count of how undesirable this alternative says it is
2699          if any reloading is required.  If the alternative matches exactly
2700          then REJECT is ignored, but otherwise it gets this much
2701          counted against it in addition to the reloading needed.  Each 
2702          ? counts three times here since we want the disparaging caused by
2703          a bad register class to only count 1/3 as much.  */
2704       int reject = 0;
2705
2706       this_earlyclobber = 0;
2707
2708       for (i = 0; i < noperands; i++)
2709         {
2710           register char *p = constraints[i];
2711           register int win = 0;
2712           /* 0 => this operand can be reloaded somehow for this alternative */
2713           int badop = 1;
2714           /* 0 => this operand can be reloaded if the alternative allows regs.  */
2715           int winreg = 0;
2716           int c;
2717           register rtx operand = recog_operand[i];
2718           int offset = 0;
2719           /* Nonzero means this is a MEM that must be reloaded into a reg
2720              regardless of what the constraint says.  */
2721           int force_reload = 0;
2722           int offmemok = 0;
2723           /* Nonzero if a constant forced into memory would be OK for this
2724              operand.  */
2725           int constmemok = 0;
2726           int earlyclobber = 0;
2727
2728           /* If the predicate accepts a unary operator, it means that
2729              we need to reload the operand.  */
2730           if (GET_RTX_CLASS (GET_CODE (operand)) == '1')
2731             operand = XEXP (operand, 0);
2732
2733           /* If the operand is a SUBREG, extract
2734              the REG or MEM (or maybe even a constant) within.
2735              (Constants can occur as a result of reg_equiv_constant.)  */
2736
2737           while (GET_CODE (operand) == SUBREG)
2738             {
2739               offset += SUBREG_WORD (operand);
2740               operand = SUBREG_REG (operand);
2741               /* Force reload if this is a constant or PLUS or if there may may
2742                  be a problem accessing OPERAND in the outer mode.  */
2743               if (CONSTANT_P (operand)
2744                   || GET_CODE (operand) == PLUS
2745                   /* We must force a reload of paradoxical SUBREGs
2746                      of a MEM because the alignment of the inner value
2747                      may not be enough to do the outer reference.  On
2748                      big-endian machines, it may also reference outside
2749                      the object.
2750
2751                      On machines that extend byte operations and we have a
2752                      SUBREG where both the inner and outer modes are no wider
2753                      than a word and the inner mode is narrower, is integral,
2754                      and gets extended when loaded from memory, combine.c has
2755                      made assumptions about the behavior of the machine in such
2756                      register access.  If the data is, in fact, in memory we
2757                      must always load using the size assumed to be in the
2758                      register and let the insn do the different-sized 
2759                      accesses.  */
2760                   || ((GET_CODE (operand) == MEM
2761                        || (GET_CODE (operand)== REG
2762                            && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
2763                       && (((GET_MODE_BITSIZE (GET_MODE (operand))
2764                             < BIGGEST_ALIGNMENT)
2765                            && (GET_MODE_SIZE (operand_mode[i])
2766                                > GET_MODE_SIZE (GET_MODE (operand))))
2767                           || (GET_CODE (operand) == MEM && BYTES_BIG_ENDIAN)
2768 #ifdef LOAD_EXTEND_OP
2769                           || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2770                               && (GET_MODE_SIZE (GET_MODE (operand))
2771                                   <= UNITS_PER_WORD)
2772                               && (GET_MODE_SIZE (operand_mode[i])
2773                                   > GET_MODE_SIZE (GET_MODE (operand)))
2774                               && INTEGRAL_MODE_P (GET_MODE (operand))
2775                               && LOAD_EXTEND_OP (GET_MODE (operand)) != NIL)
2776 #endif
2777                           ))
2778                   /* Subreg of a hard reg which can't handle the subreg's mode
2779                      or which would handle that mode in the wrong number of
2780                      registers for subregging to work.  */
2781                   || (GET_CODE (operand) == REG
2782                       && REGNO (operand) < FIRST_PSEUDO_REGISTER
2783                       && ((GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2784                            && (GET_MODE_SIZE (GET_MODE (operand))
2785                                > UNITS_PER_WORD)
2786                            && ((GET_MODE_SIZE (GET_MODE (operand))
2787                                 / UNITS_PER_WORD)
2788                                != HARD_REGNO_NREGS (REGNO (operand),
2789                                                     GET_MODE (operand))))
2790                           || ! HARD_REGNO_MODE_OK (REGNO (operand) + offset,
2791                                                    operand_mode[i]))))
2792                 force_reload = 1;
2793             }
2794
2795           this_alternative[i] = (int) NO_REGS;
2796           this_alternative_win[i] = 0;
2797           this_alternative_offmemok[i] = 0;
2798           this_alternative_earlyclobber[i] = 0;
2799           this_alternative_matches[i] = -1;
2800
2801           /* An empty constraint or empty alternative
2802              allows anything which matched the pattern.  */
2803           if (*p == 0 || *p == ',')
2804             win = 1, badop = 0;
2805
2806           /* Scan this alternative's specs for this operand;
2807              set WIN if the operand fits any letter in this alternative.
2808              Otherwise, clear BADOP if this operand could
2809              fit some letter after reloads,
2810              or set WINREG if this operand could fit after reloads
2811              provided the constraint allows some registers.  */
2812
2813           while (*p && (c = *p++) != ',')
2814             switch (c)
2815               {
2816               case '=':
2817               case '+':
2818               case '*':
2819                 break;
2820
2821               case '%':
2822                 /* The last operand should not be marked commutative.  */
2823                 if (i != noperands - 1)
2824                   commutative = i;
2825                 break;
2826
2827               case '?':
2828                 reject += 3;
2829                 break;
2830
2831               case '!':
2832                 reject = 300;
2833                 break;
2834
2835               case '#':
2836                 /* Ignore rest of this alternative as far as
2837                    reloading is concerned.  */
2838                 while (*p && *p != ',') p++;
2839                 break;
2840
2841               case '0':
2842               case '1':
2843               case '2':
2844               case '3':
2845               case '4':
2846                 c -= '0';
2847                 this_alternative_matches[i] = c;
2848                 /* We are supposed to match a previous operand.
2849                    If we do, we win if that one did.
2850                    If we do not, count both of the operands as losers.
2851                    (This is too conservative, since most of the time
2852                    only a single reload insn will be needed to make
2853                    the two operands win.  As a result, this alternative
2854                    may be rejected when it is actually desirable.)  */
2855                 if ((swapped && (c != commutative || i != commutative + 1))
2856                     /* If we are matching as if two operands were swapped,
2857                        also pretend that operands_match had been computed
2858                        with swapped.
2859                        But if I is the second of those and C is the first,
2860                        don't exchange them, because operands_match is valid
2861                        only on one side of its diagonal.  */
2862                     ? (operands_match
2863                         [(c == commutative || c == commutative + 1)
2864                          ? 2*commutative + 1 - c : c]
2865                         [(i == commutative || i == commutative + 1)
2866                          ? 2*commutative + 1 - i : i])
2867                     : operands_match[c][i])
2868                   win = this_alternative_win[c];
2869                 else
2870                   {
2871                     /* Operands don't match.  */
2872                     rtx value;
2873                     /* Retroactively mark the operand we had to match
2874                        as a loser, if it wasn't already.  */
2875                     if (this_alternative_win[c])
2876                       losers++;
2877                     this_alternative_win[c] = 0;
2878                     if (this_alternative[c] == (int) NO_REGS)
2879                       bad = 1;
2880                     /* But count the pair only once in the total badness of
2881                        this alternative, if the pair can be a dummy reload.  */
2882                     value
2883                       = find_dummy_reload (recog_operand[i], recog_operand[c],
2884                                            recog_operand_loc[i], recog_operand_loc[c],
2885                                            operand_mode[i], operand_mode[c],
2886                                            this_alternative[c], -1,
2887                                            this_alternative_earlyclobber[c]);
2888
2889                     if (value != 0)
2890                       losers--;
2891                   }
2892                 /* This can be fixed with reloads if the operand
2893                    we are supposed to match can be fixed with reloads.  */
2894                 badop = 0;
2895                 this_alternative[i] = this_alternative[c];
2896
2897                 /* If we have to reload this operand and some previous
2898                    operand also had to match the same thing as this
2899                    operand, we don't know how to do that.  So reject this
2900                    alternative.  */
2901                 if (! win || force_reload)
2902                   for (j = 0; j < i; j++)
2903                     if (this_alternative_matches[j]
2904                         == this_alternative_matches[i])
2905                       badop = 1;
2906
2907                 break;
2908
2909               case 'p':
2910                 /* All necessary reloads for an address_operand
2911                    were handled in find_reloads_address.  */
2912                 this_alternative[i] = (int) BASE_REG_CLASS;
2913                 win = 1;
2914                 break;
2915
2916               case 'm':
2917                 if (force_reload)
2918                   break;
2919                 if (GET_CODE (operand) == MEM
2920                     || (GET_CODE (operand) == REG
2921                         && REGNO (operand) >= FIRST_PSEUDO_REGISTER
2922                         && reg_renumber[REGNO (operand)] < 0))
2923                   win = 1;
2924                 if (CONSTANT_P (operand))
2925                   badop = 0;
2926                 constmemok = 1;
2927                 break;
2928
2929               case '<':
2930                 if (GET_CODE (operand) == MEM
2931                     && ! address_reloaded[i]
2932                     && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
2933                         || GET_CODE (XEXP (operand, 0)) == POST_DEC))
2934                   win = 1;
2935                 break;
2936
2937               case '>':
2938                 if (GET_CODE (operand) == MEM
2939                     && ! address_reloaded[i]
2940                     && (GET_CODE (XEXP (operand, 0)) == PRE_INC
2941                         || GET_CODE (XEXP (operand, 0)) == POST_INC))
2942                   win = 1;
2943                 break;
2944
2945                 /* Memory operand whose address is not offsettable.  */
2946               case 'V':
2947                 if (force_reload)
2948                   break;
2949                 if (GET_CODE (operand) == MEM
2950                     && ! (ind_levels ? offsettable_memref_p (operand)
2951                           : offsettable_nonstrict_memref_p (operand))
2952                     /* Certain mem addresses will become offsettable
2953                        after they themselves are reloaded.  This is important;
2954                        we don't want our own handling of unoffsettables
2955                        to override the handling of reg_equiv_address.  */
2956                     && !(GET_CODE (XEXP (operand, 0)) == REG
2957                          && (ind_levels == 0
2958                              || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0)))
2959                   win = 1;
2960                 break;
2961
2962                 /* Memory operand whose address is offsettable.  */
2963               case 'o':
2964                 if (force_reload)
2965                   break;
2966                 if ((GET_CODE (operand) == MEM
2967                      /* If IND_LEVELS, find_reloads_address won't reload a
2968                         pseudo that didn't get a hard reg, so we have to
2969                         reject that case.  */
2970                      && (ind_levels ? offsettable_memref_p (operand)
2971                          : offsettable_nonstrict_memref_p (operand)))
2972                     /* A reloaded auto-increment address is offsettable,
2973                        because it is now just a simple register indirect.  */
2974                     || (GET_CODE (operand) == MEM
2975                         && address_reloaded[i]
2976                         && (GET_CODE (XEXP (operand, 0)) == PRE_INC
2977                             || GET_CODE (XEXP (operand, 0)) == PRE_DEC
2978                             || GET_CODE (XEXP (operand, 0)) == POST_INC
2979                             || GET_CODE (XEXP (operand, 0)) == POST_DEC))
2980                     /* Certain mem addresses will become offsettable
2981                        after they themselves are reloaded.  This is important;
2982                        we don't want our own handling of unoffsettables
2983                        to override the handling of reg_equiv_address.  */
2984                     || (GET_CODE (operand) == MEM
2985                         && GET_CODE (XEXP (operand, 0)) == REG
2986                         && (ind_levels == 0
2987                             || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0))
2988                     || (GET_CODE (operand) == REG
2989                         && REGNO (operand) >= FIRST_PSEUDO_REGISTER
2990                         && reg_renumber[REGNO (operand)] < 0
2991                         /* If reg_equiv_address is nonzero, we will be
2992                            loading it into a register; hence it will be
2993                            offsettable, but we cannot say that reg_equiv_mem
2994                            is offsettable without checking.  */
2995                         && ((reg_equiv_mem[REGNO (operand)] != 0
2996                              && offsettable_memref_p (reg_equiv_mem[REGNO (operand)]))
2997                             || (reg_equiv_address[REGNO (operand)] != 0))))
2998                   win = 1;
2999                 if (CONSTANT_P (operand) || GET_CODE (operand) == MEM)
3000                   badop = 0;
3001                 constmemok = 1;
3002                 offmemok = 1;
3003                 break;
3004
3005               case '&':
3006                 /* Output operand that is stored before the need for the
3007                    input operands (and their index registers) is over.  */
3008                 earlyclobber = 1, this_earlyclobber = 1;
3009                 break;
3010
3011               case 'E':
3012 #ifndef REAL_ARITHMETIC
3013                 /* Match any floating double constant, but only if
3014                    we can examine the bits of it reliably.  */
3015                 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
3016                      || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
3017                     && GET_MODE (operand) != VOIDmode && ! flag_pretend_float)
3018                   break;
3019 #endif
3020                 if (GET_CODE (operand) == CONST_DOUBLE)
3021                   win = 1;
3022                 break;
3023
3024               case 'F':
3025                 if (GET_CODE (operand) == CONST_DOUBLE)
3026                   win = 1;
3027                 break;
3028
3029               case 'G':
3030               case 'H':
3031                 if (GET_CODE (operand) == CONST_DOUBLE
3032                     && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c))
3033                   win = 1;
3034                 break;
3035
3036               case 's':
3037                 if (GET_CODE (operand) == CONST_INT
3038                     || (GET_CODE (operand) == CONST_DOUBLE
3039                         && GET_MODE (operand) == VOIDmode))
3040                   break;
3041               case 'i':
3042                 if (CONSTANT_P (operand)
3043 #ifdef LEGITIMATE_PIC_OPERAND_P
3044                     && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand))
3045 #endif
3046                     )
3047                   win = 1;
3048                 break;
3049
3050               case 'n':
3051                 if (GET_CODE (operand) == CONST_INT
3052                     || (GET_CODE (operand) == CONST_DOUBLE
3053                         && GET_MODE (operand) == VOIDmode))
3054                   win = 1;
3055                 break;
3056
3057               case 'I':
3058               case 'J':
3059               case 'K':
3060               case 'L':
3061               case 'M':
3062               case 'N':
3063               case 'O':
3064               case 'P':
3065                 if (GET_CODE (operand) == CONST_INT
3066                     && CONST_OK_FOR_LETTER_P (INTVAL (operand), c))
3067                   win = 1;
3068                 break;
3069
3070               case 'X':
3071                 win = 1;
3072                 break;
3073
3074               case 'g':
3075                 if (! force_reload
3076                     /* A PLUS is never a valid operand, but reload can make
3077                        it from a register when eliminating registers.  */
3078                     && GET_CODE (operand) != PLUS
3079                     /* A SCRATCH is not a valid operand.  */
3080                     && GET_CODE (operand) != SCRATCH
3081 #ifdef LEGITIMATE_PIC_OPERAND_P
3082                     && (! CONSTANT_P (operand) 
3083                         || ! flag_pic 
3084                         || LEGITIMATE_PIC_OPERAND_P (operand))
3085 #endif
3086                     && (GENERAL_REGS == ALL_REGS
3087                         || GET_CODE (operand) != REG
3088                         || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
3089                             && reg_renumber[REGNO (operand)] < 0)))
3090                   win = 1;
3091                 /* Drop through into 'r' case */
3092
3093               case 'r':
3094                 this_alternative[i]
3095                   = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
3096                 goto reg;
3097
3098 #ifdef EXTRA_CONSTRAINT
3099               case 'Q':
3100               case 'R':
3101               case 'S':
3102               case 'T':
3103               case 'U':
3104                 if (EXTRA_CONSTRAINT (operand, c))
3105                   win = 1;
3106                 break;
3107 #endif
3108   
3109               default:
3110                 this_alternative[i]
3111                   = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)];
3112                 
3113               reg:
3114                 if (GET_MODE (operand) == BLKmode)
3115                   break;
3116                 winreg = 1;
3117                 if (GET_CODE (operand) == REG
3118                     && reg_fits_class_p (operand, this_alternative[i],
3119                                          offset, GET_MODE (recog_operand[i])))
3120                   win = 1;
3121                 break;
3122               }
3123
3124           constraints[i] = p;
3125
3126           /* If this operand could be handled with a reg,
3127              and some reg is allowed, then this operand can be handled.  */
3128           if (winreg && this_alternative[i] != (int) NO_REGS)
3129             badop = 0;
3130
3131           /* Record which operands fit this alternative.  */
3132           this_alternative_earlyclobber[i] = earlyclobber;
3133           if (win && ! force_reload)
3134             this_alternative_win[i] = 1;
3135           else
3136             {
3137               int const_to_mem = 0;
3138
3139               this_alternative_offmemok[i] = offmemok;
3140               losers++;
3141               if (badop)
3142                 bad = 1;
3143               /* Alternative loses if it has no regs for a reg operand.  */
3144               if (GET_CODE (operand) == REG
3145                   && this_alternative[i] == (int) NO_REGS
3146                   && this_alternative_matches[i] < 0)
3147                 bad = 1;
3148
3149               /* Alternative loses if it requires a type of reload not
3150                  permitted for this insn.  We can always reload SCRATCH
3151                  and objects with a REG_UNUSED note.  */
3152               if (GET_CODE (operand) != SCRATCH
3153                   && modified[i] != RELOAD_READ && no_output_reloads
3154                   && ! find_reg_note (insn, REG_UNUSED, operand))
3155                 bad = 1;
3156               else if (modified[i] != RELOAD_WRITE && no_input_reloads)
3157                 bad = 1;
3158
3159               /* If this is a constant that is reloaded into the desired
3160                  class by copying it to memory first, count that as another
3161                  reload.  This is consistent with other code and is
3162                  required to avoid choosing another alternative when
3163                  the constant is moved into memory by this function on
3164                  an early reload pass.  Note that the test here is 
3165                  precisely the same as in the code below that calls
3166                  force_const_mem.  */
3167               if (CONSTANT_P (operand)
3168                   /* force_const_mem does not accept HIGH.  */
3169                   && GET_CODE (operand) != HIGH
3170                   && (PREFERRED_RELOAD_CLASS (operand,
3171                                               (enum reg_class) this_alternative[i])
3172                       == NO_REGS)
3173                   && operand_mode[i] != VOIDmode)
3174                 {
3175                   const_to_mem = 1;
3176                   if (this_alternative[i] != (int) NO_REGS)
3177                     losers++;
3178                 }
3179
3180               /* If we can't reload this value at all, reject this
3181                  alternative.  Note that we could also lose due to
3182                  LIMIT_RELOAD_RELOAD_CLASS, but we don't check that
3183                  here.  */
3184
3185               if (! CONSTANT_P (operand)
3186                   && (enum reg_class) this_alternative[i] != NO_REGS
3187                   && (PREFERRED_RELOAD_CLASS (operand,
3188                                               (enum reg_class) this_alternative[i])
3189                       == NO_REGS))
3190                 bad = 1;
3191
3192               /* We prefer to reload pseudos over reloading other things,
3193                  since such reloads may be able to be eliminated later.
3194                  If we are reloading a SCRATCH, we won't be generating any
3195                  insns, just using a register, so it is also preferred. 
3196                  So bump REJECT in other cases.  Don't do this in the
3197                  case where we are forcing a constant into memory and
3198                  it will then win since we don't want to have a different
3199                  alternative match then.  */
3200               if (! (GET_CODE (operand) == REG
3201                      && REGNO (operand) >= FIRST_PSEUDO_REGISTER)
3202                   && GET_CODE (operand) != SCRATCH
3203                   && ! (const_to_mem && constmemok))
3204                 reject++;
3205             }
3206
3207           /* If this operand is a pseudo register that didn't get a hard 
3208              reg and this alternative accepts some register, see if the
3209              class that we want is a subset of the preferred class for this
3210              register.  If not, but it intersects that class, use the
3211              preferred class instead.  If it does not intersect the preferred
3212              class, show that usage of this alternative should be discouraged;
3213              it will be discouraged more still if the register is `preferred
3214              or nothing'.  We do this because it increases the chance of
3215              reusing our spill register in a later insn and avoiding a pair
3216              of memory stores and loads.
3217
3218              Don't bother with this if this alternative will accept this
3219              operand.
3220
3221              Don't do this for a multiword operand, since it is only a
3222              small win and has the risk of requiring more spill registers,
3223              which could cause a large loss.
3224
3225              Don't do this if the preferred class has only one register
3226              because we might otherwise exhaust the class.  */
3227
3228
3229           if (! win && this_alternative[i] != (int) NO_REGS
3230               && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3231               && reg_class_size[(int) preferred_class[i]] > 1)
3232             {
3233               if (! reg_class_subset_p (this_alternative[i],
3234                                         preferred_class[i]))
3235                 {
3236                   /* Since we don't have a way of forming the intersection,
3237                      we just do something special if the preferred class
3238                      is a subset of the class we have; that's the most 
3239                      common case anyway.  */
3240                   if (reg_class_subset_p (preferred_class[i],
3241                                           this_alternative[i]))
3242                     this_alternative[i] = (int) preferred_class[i];
3243                   else
3244                     reject += (1 + pref_or_nothing[i]);
3245                 }
3246             }
3247         }
3248
3249       /* Now see if any output operands that are marked "earlyclobber"
3250          in this alternative conflict with any input operands
3251          or any memory addresses.  */
3252
3253       for (i = 0; i < noperands; i++)
3254         if (this_alternative_earlyclobber[i]
3255             && this_alternative_win[i])
3256           {
3257             struct decomposition early_data; 
3258
3259             early_data = decompose (recog_operand[i]);
3260
3261             if (modified[i] == RELOAD_READ)
3262               {
3263                 if (this_insn_is_asm)
3264                   warning_for_asm (this_insn,
3265                                    "`&' constraint used with input operand");
3266                 else
3267                   abort ();
3268                 continue;
3269               }
3270             
3271             if (this_alternative[i] == NO_REGS)
3272               {
3273                 this_alternative_earlyclobber[i] = 0;
3274                 if (this_insn_is_asm)
3275                   error_for_asm (this_insn,
3276                                  "`&' constraint used with no register class");
3277                 else
3278                   abort ();
3279               }
3280
3281             for (j = 0; j < noperands; j++)
3282               /* Is this an input operand or a memory ref?  */
3283               if ((GET_CODE (recog_operand[j]) == MEM
3284                    || modified[j] != RELOAD_WRITE)
3285                   && j != i
3286                   /* Ignore things like match_operator operands.  */
3287                   && *constraints1[j] != 0
3288                   /* Don't count an input operand that is constrained to match
3289                      the early clobber operand.  */
3290                   && ! (this_alternative_matches[j] == i
3291                         && rtx_equal_p (recog_operand[i], recog_operand[j]))
3292                   /* Is it altered by storing the earlyclobber operand?  */
3293                   && !immune_p (recog_operand[j], recog_operand[i], early_data))
3294                 {
3295                   /* If the output is in a single-reg class,
3296                      it's costly to reload it, so reload the input instead.  */
3297                   if (reg_class_size[this_alternative[i]] == 1
3298                       && (GET_CODE (recog_operand[j]) == REG
3299                           || GET_CODE (recog_operand[j]) == SUBREG))
3300                     {
3301                       losers++;
3302                       this_alternative_win[j] = 0;
3303                     }
3304                   else
3305                     break;
3306                 }
3307             /* If an earlyclobber operand conflicts with something,
3308                it must be reloaded, so request this and count the cost.  */
3309             if (j != noperands)
3310               {
3311                 losers++;
3312                 this_alternative_win[i] = 0;
3313                 for (j = 0; j < noperands; j++)
3314                   if (this_alternative_matches[j] == i
3315                       && this_alternative_win[j])
3316                     {
3317                       this_alternative_win[j] = 0;
3318                       losers++;
3319                     }
3320               }
3321           }
3322
3323       /* If one alternative accepts all the operands, no reload required,
3324          choose that alternative; don't consider the remaining ones.  */
3325       if (losers == 0)
3326         {
3327           /* Unswap these so that they are never swapped at `finish'.  */
3328           if (commutative >= 0)
3329             {
3330               recog_operand[commutative] = substed_operand[commutative];
3331               recog_operand[commutative + 1]
3332                 = substed_operand[commutative + 1];
3333             }
3334           for (i = 0; i < noperands; i++)
3335             {
3336               goal_alternative_win[i] = 1;
3337               goal_alternative[i] = this_alternative[i];
3338               goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3339               goal_alternative_matches[i] = this_alternative_matches[i];
3340               goal_alternative_earlyclobber[i]
3341                 = this_alternative_earlyclobber[i];
3342             }
3343           goal_alternative_number = this_alternative_number;
3344           goal_alternative_swapped = swapped;
3345           goal_earlyclobber = this_earlyclobber;
3346           goto finish;
3347         }
3348
3349       /* REJECT, set by the ! and ? constraint characters and when a register
3350          would be reloaded into a non-preferred class, discourages the use of
3351          this alternative for a reload goal.  REJECT is incremented by three
3352          for each ? and one for each non-preferred class.  */
3353       losers = losers * 3 + reject;
3354
3355       /* If this alternative can be made to work by reloading,
3356          and it needs less reloading than the others checked so far,
3357          record it as the chosen goal for reloading.  */
3358       if (! bad && best > losers)
3359         {
3360           for (i = 0; i < noperands; i++)
3361             {
3362               goal_alternative[i] = this_alternative[i];
3363               goal_alternative_win[i] = this_alternative_win[i];
3364               goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3365               goal_alternative_matches[i] = this_alternative_matches[i];
3366               goal_alternative_earlyclobber[i]
3367                 = this_alternative_earlyclobber[i];
3368             }
3369           goal_alternative_swapped = swapped;
3370           best = losers;
3371           goal_alternative_number = this_alternative_number;
3372           goal_earlyclobber = this_earlyclobber;
3373         }
3374     }
3375
3376   /* If insn is commutative (it's safe to exchange a certain pair of operands)
3377      then we need to try each alternative twice,
3378      the second time matching those two operands
3379      as if we had exchanged them.
3380      To do this, really exchange them in operands.
3381
3382      If we have just tried the alternatives the second time,
3383      return operands to normal and drop through.  */
3384
3385   if (commutative >= 0)
3386     {
3387       swapped = !swapped;
3388       if (swapped)
3389         {
3390           register enum reg_class tclass;
3391           register int t;
3392
3393           recog_operand[commutative] = substed_operand[commutative + 1];
3394           recog_operand[commutative + 1] = substed_operand[commutative];
3395
3396           tclass = preferred_class[commutative];
3397           preferred_class[commutative] = preferred_class[commutative + 1];
3398           preferred_class[commutative + 1] = tclass;
3399
3400           t = pref_or_nothing[commutative];
3401           pref_or_nothing[commutative] = pref_or_nothing[commutative + 1];
3402           pref_or_nothing[commutative + 1] = t;
3403
3404           bcopy ((char *) constraints1, (char *) constraints,
3405                  noperands * sizeof (char *));
3406           goto try_swapped;
3407         }
3408       else
3409         {
3410           recog_operand[commutative] = substed_operand[commutative];
3411           recog_operand[commutative + 1] = substed_operand[commutative + 1];
3412         }
3413     }
3414
3415   /* The operands don't meet the constraints.
3416      goal_alternative describes the alternative
3417      that we could reach by reloading the fewest operands.
3418      Reload so as to fit it.  */
3419
3420   if (best == MAX_RECOG_OPERANDS + 300)
3421     {
3422       /* No alternative works with reloads??  */
3423       if (insn_code_number >= 0)
3424         abort ();
3425       error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3426       /* Avoid further trouble with this insn.  */
3427       PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
3428       n_reloads = 0;
3429       return;
3430     }
3431
3432   /* Jump to `finish' from above if all operands are valid already.
3433      In that case, goal_alternative_win is all 1.  */
3434  finish:
3435
3436   /* Right now, for any pair of operands I and J that are required to match,
3437      with I < J,
3438      goal_alternative_matches[J] is I.
3439      Set up goal_alternative_matched as the inverse function:
3440      goal_alternative_matched[I] = J.  */
3441
3442   for (i = 0; i < noperands; i++)
3443     goal_alternative_matched[i] = -1;
3444
3445   for (i = 0; i < noperands; i++)
3446     if (! goal_alternative_win[i]
3447         && goal_alternative_matches[i] >= 0)
3448       goal_alternative_matched[goal_alternative_matches[i]] = i;
3449
3450   /* If the best alternative is with operands 1 and 2 swapped,
3451      consider them swapped before reporting the reloads.  Update the
3452      operand numbers of any reloads already pushed.  */
3453
3454   if (goal_alternative_swapped)
3455     {
3456       register rtx tem;
3457
3458       tem = substed_operand[commutative];
3459       substed_operand[commutative] = substed_operand[commutative + 1];
3460       substed_operand[commutative + 1] = tem;
3461       tem = recog_operand[commutative];
3462       recog_operand[commutative] = recog_operand[commutative + 1];
3463       recog_operand[commutative + 1] = tem;
3464
3465       for (i = 0; i < n_reloads; i++)
3466         {
3467           if (reload_opnum[i] == commutative)
3468             reload_opnum[i] = commutative + 1;
3469           else if (reload_opnum[i] == commutative + 1)
3470             reload_opnum[i] = commutative;
3471         }
3472     }
3473
3474   /* Perform whatever substitutions on the operands we are supposed
3475      to make due to commutativity or replacement of registers
3476      with equivalent constants or memory slots.  */
3477
3478   for (i = 0; i < noperands; i++)
3479     {
3480       *recog_operand_loc[i] = substed_operand[i];
3481       /* While we are looping on operands, initialize this.  */
3482       operand_reloadnum[i] = -1;
3483
3484       /* If this is an earlyclobber operand, we need to widen the scope.
3485          The reload must remain valid from the start of the insn being
3486          reloaded until after the operand is stored into its destination.
3487          We approximate this with RELOAD_OTHER even though we know that we
3488          do not conflict with RELOAD_FOR_INPUT_ADDRESS reloads.
3489
3490          One special case that is worth checking is when we have an
3491          output that is earlyclobber but isn't used past the insn (typically
3492          a SCRATCH).  In this case, we only need have the reload live 
3493          through the insn itself, but not for any of our input or output
3494          reloads. 
3495
3496          In any case, anything needed to address this operand can remain
3497          however they were previously categorized.  */
3498
3499       if (goal_alternative_earlyclobber[i])
3500         operand_type[i]
3501           = (find_reg_note (insn, REG_UNUSED, recog_operand[i])
3502              ? RELOAD_FOR_INSN : RELOAD_OTHER);
3503     }
3504
3505   /* Any constants that aren't allowed and can't be reloaded
3506      into registers are here changed into memory references.  */
3507   for (i = 0; i < noperands; i++)
3508     if (! goal_alternative_win[i]
3509         && CONSTANT_P (recog_operand[i])
3510         /* force_const_mem does not accept HIGH.  */
3511         && GET_CODE (recog_operand[i]) != HIGH
3512         && (PREFERRED_RELOAD_CLASS (recog_operand[i],
3513                                     (enum reg_class) goal_alternative[i])
3514             == NO_REGS)
3515         && operand_mode[i] != VOIDmode)
3516       {
3517         *recog_operand_loc[i] = recog_operand[i]
3518           = find_reloads_toplev (force_const_mem (operand_mode[i],
3519                                                   recog_operand[i]),
3520                                  i, address_type[i], ind_levels, 0);
3521         if (alternative_allows_memconst (constraints1[i],
3522                                          goal_alternative_number))
3523           goal_alternative_win[i] = 1;
3524       }
3525
3526   /* Record the values of the earlyclobber operands for the caller.  */
3527   if (goal_earlyclobber)
3528     for (i = 0; i < noperands; i++)
3529       if (goal_alternative_earlyclobber[i])
3530         reload_earlyclobbers[n_earlyclobbers++] = recog_operand[i];
3531
3532   /* Now record reloads for all the operands that need them.  */
3533   for (i = 0; i < noperands; i++)
3534     if (! goal_alternative_win[i])
3535       {
3536         /* Operands that match previous ones have already been handled.  */
3537         if (goal_alternative_matches[i] >= 0)
3538           ;
3539         /* Handle an operand with a nonoffsettable address
3540            appearing where an offsettable address will do
3541            by reloading the address into a base register.
3542
3543            ??? We can also do this when the operand is a register and
3544            reg_equiv_mem is not offsettable, but this is a bit tricky,
3545            so we don't bother with it.  It may not be worth doing.  */
3546         else if (goal_alternative_matched[i] == -1
3547                  && goal_alternative_offmemok[i]
3548                  && GET_CODE (recog_operand[i]) == MEM)
3549           {
3550             operand_reloadnum[i]
3551               = push_reload (XEXP (recog_operand[i], 0), NULL_RTX,
3552                              &XEXP (recog_operand[i], 0), NULL_PTR,
3553                              BASE_REG_CLASS, GET_MODE (XEXP (recog_operand[i], 0)),
3554                              VOIDmode, 0, 0, i, RELOAD_FOR_INPUT);
3555             reload_inc[operand_reloadnum[i]]
3556               = GET_MODE_SIZE (GET_MODE (recog_operand[i]));
3557
3558             /* If this operand is an output, we will have made any
3559                reloads for its address as RELOAD_FOR_OUTPUT_ADDRESS, but
3560                now we are treating part of the operand as an input, so
3561                we must change these to RELOAD_FOR_INPUT_ADDRESS.  */
3562
3563             if (modified[i] == RELOAD_WRITE)
3564               {
3565                 for (j = 0; j < n_reloads; j++)
3566                   {
3567                     if (reload_opnum[j] == i)
3568                       {
3569                         if (reload_when_needed[j] == RELOAD_FOR_OUTPUT_ADDRESS)
3570                           reload_when_needed[j] = RELOAD_FOR_INPUT_ADDRESS;
3571                         else if (reload_when_needed[j]
3572                                  == RELOAD_FOR_OUTADDR_ADDRESS)
3573                           reload_when_needed[j] = RELOAD_FOR_INPADDR_ADDRESS;
3574                       }
3575                   }
3576               }
3577           }
3578         else if (goal_alternative_matched[i] == -1)
3579           operand_reloadnum[i]
3580             = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
3581                            modified[i] != RELOAD_READ ? recog_operand[i] : 0,
3582                            (modified[i] != RELOAD_WRITE
3583                             ? recog_operand_loc[i] : 0),
3584                            modified[i] != RELOAD_READ ? recog_operand_loc[i] : 0,
3585                            (enum reg_class) goal_alternative[i],
3586                            (modified[i] == RELOAD_WRITE
3587                             ? VOIDmode : operand_mode[i]),
3588                            (modified[i] == RELOAD_READ
3589                             ? VOIDmode : operand_mode[i]),
3590                            (insn_code_number < 0 ? 0
3591                             : insn_operand_strict_low[insn_code_number][i]),
3592                            0, i, operand_type[i]);
3593         /* In a matching pair of operands, one must be input only
3594            and the other must be output only.
3595            Pass the input operand as IN and the other as OUT.  */
3596         else if (modified[i] == RELOAD_READ
3597                  && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
3598           {
3599             operand_reloadnum[i]
3600               = push_reload (recog_operand[i],
3601                              recog_operand[goal_alternative_matched[i]],
3602                              recog_operand_loc[i],
3603                              recog_operand_loc[goal_alternative_matched[i]],
3604                              (enum reg_class) goal_alternative[i],
3605                              operand_mode[i],
3606                              operand_mode[goal_alternative_matched[i]],
3607                              0, 0, i, RELOAD_OTHER);
3608             operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
3609           }
3610         else if (modified[i] == RELOAD_WRITE
3611                  && modified[goal_alternative_matched[i]] == RELOAD_READ)
3612           {
3613             operand_reloadnum[goal_alternative_matched[i]]
3614               = push_reload (recog_operand[goal_alternative_matched[i]],
3615                              recog_operand[i],
3616                              recog_operand_loc[goal_alternative_matched[i]],
3617                              recog_operand_loc[i],
3618                              (enum reg_class) goal_alternative[i],
3619                              operand_mode[goal_alternative_matched[i]],
3620                              operand_mode[i],
3621                              0, 0, i, RELOAD_OTHER);
3622             operand_reloadnum[i] = output_reloadnum;
3623           }
3624         else if (insn_code_number >= 0)
3625           abort ();
3626         else
3627           {
3628             error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3629             /* Avoid further trouble with this insn.  */
3630             PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
3631             n_reloads = 0;
3632             return;
3633           }
3634       }
3635     else if (goal_alternative_matched[i] < 0
3636              && goal_alternative_matches[i] < 0
3637              && optimize)
3638       {
3639         /* For each non-matching operand that's a MEM or a pseudo-register 
3640            that didn't get a hard register, make an optional reload.
3641            This may get done even if the insn needs no reloads otherwise.  */
3642
3643         rtx operand = recog_operand[i];
3644
3645         while (GET_CODE (operand) == SUBREG)
3646           operand = XEXP (operand, 0);
3647         if ((GET_CODE (operand) == MEM
3648              || (GET_CODE (operand) == REG
3649                  && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3650             && (enum reg_class) goal_alternative[i] != NO_REGS
3651             && ! no_input_reloads
3652             /* Optional output reloads don't do anything and we mustn't
3653                make in-out reloads on insns that are not permitted output
3654                reloads.  */
3655             && (modified[i] == RELOAD_READ
3656                 || (modified[i] == RELOAD_READ_WRITE && ! no_output_reloads)))
3657           operand_reloadnum[i]
3658             = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
3659                            modified[i] != RELOAD_READ ? recog_operand[i] : 0,
3660                            (modified[i] != RELOAD_WRITE
3661                             ? recog_operand_loc[i] : 0),
3662                            (modified[i] != RELOAD_READ
3663                             ? recog_operand_loc[i] : 0),
3664                            (enum reg_class) goal_alternative[i],
3665                            (modified[i] == RELOAD_WRITE
3666                             ? VOIDmode : operand_mode[i]),
3667                            (modified[i] == RELOAD_READ
3668                             ? VOIDmode : operand_mode[i]),
3669                            (insn_code_number < 0 ? 0
3670                             : insn_operand_strict_low[insn_code_number][i]),
3671                            1, i, operand_type[i]);
3672       }
3673     else if (goal_alternative_matches[i] >= 0
3674              && goal_alternative_win[goal_alternative_matches[i]]
3675              && modified[i] == RELOAD_READ
3676              && modified[goal_alternative_matches[i]] == RELOAD_WRITE
3677              && ! no_input_reloads && ! no_output_reloads
3678              && optimize)
3679       {
3680         /* Similarly, make an optional reload for a pair of matching
3681            objects that are in MEM or a pseudo that didn't get a hard reg.  */
3682
3683         rtx operand = recog_operand[i];
3684
3685         while (GET_CODE (operand) == SUBREG)
3686           operand = XEXP (operand, 0);
3687         if ((GET_CODE (operand) == MEM
3688              || (GET_CODE (operand) == REG
3689                  && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3690             && ((enum reg_class) goal_alternative[goal_alternative_matches[i]]
3691                 != NO_REGS))
3692           operand_reloadnum[i] = operand_reloadnum[goal_alternative_matches[i]]
3693             = push_reload (recog_operand[goal_alternative_matches[i]],
3694                            recog_operand[i],
3695                            recog_operand_loc[goal_alternative_matches[i]],
3696                            recog_operand_loc[i],
3697                            (enum reg_class) goal_alternative[goal_alternative_matches[i]],
3698                            operand_mode[goal_alternative_matches[i]],
3699                            operand_mode[i],
3700                            0, 1, goal_alternative_matches[i], RELOAD_OTHER);
3701       }
3702   
3703   /* If this insn pattern contains any MATCH_DUP's, make sure that
3704      they will be substituted if the operands they match are substituted.
3705      Also do now any substitutions we already did on the operands.
3706
3707      Don't do this if we aren't making replacements because we might be
3708      propagating things allocated by frame pointer elimination into places
3709      it doesn't expect.  */
3710
3711   if (insn_code_number >= 0 && replace)
3712     for (i = insn_n_dups[insn_code_number] - 1; i >= 0; i--)
3713       {
3714         int opno = recog_dup_num[i];
3715         *recog_dup_loc[i] = *recog_operand_loc[opno];
3716         if (operand_reloadnum[opno] >= 0)
3717           push_replacement (recog_dup_loc[i], operand_reloadnum[opno],
3718                             insn_operand_mode[insn_code_number][opno]);
3719       }
3720
3721 #if 0
3722   /* This loses because reloading of prior insns can invalidate the equivalence
3723      (or at least find_equiv_reg isn't smart enough to find it any more),
3724      causing this insn to need more reload regs than it needed before.
3725      It may be too late to make the reload regs available.
3726      Now this optimization is done safely in choose_reload_regs.  */
3727
3728   /* For each reload of a reg into some other class of reg,
3729      search for an existing equivalent reg (same value now) in the right class.
3730      We can use it as long as we don't need to change its contents.  */
3731   for (i = 0; i < n_reloads; i++)
3732     if (reload_reg_rtx[i] == 0
3733         && reload_in[i] != 0
3734         && GET_CODE (reload_in[i]) == REG
3735         && reload_out[i] == 0)
3736       {
3737         reload_reg_rtx[i]
3738           = find_equiv_reg (reload_in[i], insn, reload_reg_class[i], -1,
3739                             static_reload_reg_p, 0, reload_inmode[i]);
3740         /* Prevent generation of insn to load the value
3741            because the one we found already has the value.  */
3742         if (reload_reg_rtx[i])
3743           reload_in[i] = reload_reg_rtx[i];
3744       }
3745 #endif
3746
3747   /* Perhaps an output reload can be combined with another
3748      to reduce needs by one.  */
3749   if (!goal_earlyclobber)
3750     combine_reloads ();
3751
3752   /* If we have a pair of reloads for parts of an address, they are reloading
3753      the same object, the operands themselves were not reloaded, and they
3754      are for two operands that are supposed to match, merge the reloads and
3755      change the type of the surviving reload to RELOAD_FOR_OPERAND_ADDRESS.  */
3756
3757   for (i = 0; i < n_reloads; i++)
3758     {
3759       int k;
3760
3761       for (j = i + 1; j < n_reloads; j++)
3762         if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3763              || reload_when_needed[i] == RELOAD_FOR_OUTPUT_ADDRESS
3764              || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3765              || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3766             && (reload_when_needed[j] == RELOAD_FOR_INPUT_ADDRESS
3767                 || reload_when_needed[j] == RELOAD_FOR_OUTPUT_ADDRESS
3768                 || reload_when_needed[j] == RELOAD_FOR_INPADDR_ADDRESS
3769                 || reload_when_needed[j] == RELOAD_FOR_OUTADDR_ADDRESS)
3770             && rtx_equal_p (reload_in[i], reload_in[j])
3771             && (operand_reloadnum[reload_opnum[i]] < 0
3772                 || reload_optional[operand_reloadnum[reload_opnum[i]]])
3773             && (operand_reloadnum[reload_opnum[j]] < 0
3774                 || reload_optional[operand_reloadnum[reload_opnum[j]]])
3775             && (goal_alternative_matches[reload_opnum[i]] == reload_opnum[j]
3776                 || (goal_alternative_matches[reload_opnum[j]]
3777                     == reload_opnum[i])))
3778           {
3779             for (k = 0; k < n_replacements; k++)
3780               if (replacements[k].what == j)
3781                 replacements[k].what = i;
3782
3783             if (reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3784                 || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3785               reload_when_needed[i] = RELOAD_FOR_OPADDR_ADDR;
3786             else
3787               reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
3788             reload_in[j] = 0;
3789           }
3790     }
3791
3792   /* Scan all the reloads and update their type. 
3793      If a reload is for the address of an operand and we didn't reload
3794      that operand, change the type.  Similarly, change the operand number
3795      of a reload when two operands match.  If a reload is optional, treat it
3796      as though the operand isn't reloaded.
3797
3798      ??? This latter case is somewhat odd because if we do the optional
3799      reload, it means the object is hanging around.  Thus we need only
3800      do the address reload if the optional reload was NOT done.
3801
3802      Change secondary reloads to be the address type of their operand, not
3803      the normal type.
3804
3805      If an operand's reload is now RELOAD_OTHER, change any
3806      RELOAD_FOR_INPUT_ADDRESS reloads of that operand to
3807      RELOAD_FOR_OTHER_ADDRESS.  */
3808
3809   for (i = 0; i < n_reloads; i++)
3810     {
3811       if (reload_secondary_p[i]
3812           && reload_when_needed[i] == operand_type[reload_opnum[i]])
3813         reload_when_needed[i] = address_type[reload_opnum[i]];
3814
3815       if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3816            || reload_when_needed[i] == RELOAD_FOR_OUTPUT_ADDRESS
3817            || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3818            || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3819           && (operand_reloadnum[reload_opnum[i]] < 0
3820               || reload_optional[operand_reloadnum[reload_opnum[i]]]))
3821         {
3822           /* If we have a secondary reload to go along with this reload,
3823              change its type to RELOAD_FOR_OPADDR_ADDR.  */
3824
3825           if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3826                || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS)
3827               && reload_secondary_in_reload[i] != -1)
3828             {
3829               int secondary_in_reload = reload_secondary_in_reload[i];
3830
3831               reload_when_needed[secondary_in_reload]
3832                 = RELOAD_FOR_OPADDR_ADDR;
3833
3834               /* If there's a tertiary reload we have to change it also.  */
3835               if (secondary_in_reload > 0
3836                   && reload_secondary_in_reload[secondary_in_reload] != -1)
3837                 reload_when_needed[reload_secondary_in_reload[secondary_in_reload]] 
3838                   = RELOAD_FOR_OPADDR_ADDR;
3839             }
3840
3841           if ((reload_when_needed[i] == RELOAD_FOR_OUTPUT_ADDRESS
3842                || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3843               && reload_secondary_out_reload[i] != -1)
3844             {
3845               int secondary_out_reload = reload_secondary_out_reload[i];
3846
3847               reload_when_needed[secondary_out_reload]
3848                 = RELOAD_FOR_OPADDR_ADDR;
3849
3850               /* If there's a tertiary reload we have to change it also.  */
3851               if (secondary_out_reload
3852                   && reload_secondary_out_reload[secondary_out_reload] != -1)
3853                 reload_when_needed[reload_secondary_out_reload[secondary_out_reload]] 
3854                   = RELOAD_FOR_OPADDR_ADDR;
3855             }
3856           if (reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3857               || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3858             reload_when_needed[i] = RELOAD_FOR_OPADDR_ADDR;
3859           else
3860             reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
3861         }
3862
3863       if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3864            || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS)
3865           && operand_reloadnum[reload_opnum[i]] >= 0
3866           && (reload_when_needed[operand_reloadnum[reload_opnum[i]]] 
3867               == RELOAD_OTHER))
3868         reload_when_needed[i] = RELOAD_FOR_OTHER_ADDRESS;
3869
3870       if (goal_alternative_matches[reload_opnum[i]] >= 0)
3871         reload_opnum[i] = goal_alternative_matches[reload_opnum[i]];
3872     }
3873
3874   /* Scan all the reloads, and check for RELOAD_FOR_OPERAND_ADDRESS reloads.
3875      If we have more than one, then convert all RELOAD_FOR_OPADDR_ADDR
3876      reloads to RELOAD_FOR_OPERAND_ADDRESS reloads.
3877
3878      choose_reload_regs assumes that RELOAD_FOR_OPADDR_ADDR reloads never
3879      conflict with RELOAD_FOR_OPERAND_ADDRESS reloads.  This is true for a
3880      single pair of RELOAD_FOR_OPADDR_ADDR/RELOAD_FOR_OPERAND_ADDRESS reloads.
3881      However, if there is more than one RELOAD_FOR_OPERAND_ADDRESS reload,
3882      then a RELOAD_FOR_OPADDR_ADDR reload conflicts with all
3883      RELOAD_FOR_OPERAND_ADDRESS reloads other than the one that uses it.
3884      This is complicated by the fact that a single operand can have more
3885      than one RELOAD_FOR_OPERAND_ADDRESS reload.  It is very difficult to fix
3886      choose_reload_regs without affecting code quality, and cases that
3887      actually fail are extremely rare, so it turns out to be better to fix
3888      the problem here by not generating cases that choose_reload_regs will
3889      fail for.  */
3890    
3891   {
3892     int op_addr_reloads = 0;
3893     for (i = 0; i < n_reloads; i++)
3894       if (reload_when_needed[i] == RELOAD_FOR_OPERAND_ADDRESS)
3895         op_addr_reloads++;
3896
3897     if (op_addr_reloads > 1)
3898       for (i = 0; i < n_reloads; i++)
3899         if (reload_when_needed[i] == RELOAD_FOR_OPADDR_ADDR)
3900           reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
3901   }
3902
3903   /* See if we have any reloads that are now allowed to be merged
3904      because we've changed when the reload is needed to
3905      RELOAD_FOR_OPERAND_ADDRESS or RELOAD_FOR_OTHER_ADDRESS.  Only
3906      check for the most common cases.  */
3907
3908   for (i = 0; i < n_reloads; i++)
3909     if (reload_in[i] != 0 && reload_out[i] == 0
3910         && (reload_when_needed[i] == RELOAD_FOR_OPERAND_ADDRESS
3911             || reload_when_needed[i] == RELOAD_FOR_OPADDR_ADDR
3912             || reload_when_needed[i] == RELOAD_FOR_OTHER_ADDRESS))
3913       for (j = 0; j < n_reloads; j++)
3914         if (i != j && reload_in[j] != 0 && reload_out[j] == 0
3915             && reload_when_needed[j] == reload_when_needed[i]
3916             && MATCHES (reload_in[i], reload_in[j])
3917             && reload_reg_class[i] == reload_reg_class[j]
3918             && !reload_nocombine[i] && !reload_nocombine[j]
3919             && reload_reg_rtx[i] == reload_reg_rtx[j])
3920           {
3921             reload_opnum[i] = MIN (reload_opnum[i], reload_opnum[j]);
3922             transfer_replacements (i, j);
3923             reload_in[j] = 0;
3924           }
3925
3926 #else /* no REGISTER_CONSTRAINTS */
3927   int noperands;
3928   int insn_code_number;
3929   int goal_earlyclobber = 0; /* Always 0, to make combine_reloads happen.  */
3930   register int i;
3931   rtx body = PATTERN (insn);
3932
3933   n_reloads = 0;
3934   n_replacements = 0;
3935   n_earlyclobbers = 0;
3936   replace_reloads = replace;
3937   this_insn = insn;
3938
3939   /* Find what kind of insn this is.  NOPERANDS gets number of operands.
3940      Store the operand values in RECOG_OPERAND and the locations
3941      of the words in the insn that point to them in RECOG_OPERAND_LOC.
3942      Return if the insn needs no reload processing.  */
3943
3944   switch (GET_CODE (body))
3945     {
3946     case USE:
3947     case CLOBBER:
3948     case ASM_INPUT:
3949     case ADDR_VEC:
3950     case ADDR_DIFF_VEC:
3951       return;
3952
3953     case PARALLEL:
3954     case SET:
3955       noperands = asm_noperands (body);
3956       if (noperands >= 0)
3957         {
3958           /* This insn is an `asm' with operands.
3959              First, find out how many operands, and allocate space.  */
3960
3961           insn_code_number = -1;
3962           /* ??? This is a bug! ???
3963              Give up and delete this insn if it has too many operands.  */
3964           if (noperands > MAX_RECOG_OPERANDS)
3965             abort ();
3966
3967           /* Now get the operand values out of the insn.  */
3968
3969           decode_asm_operands (body, recog_operand, recog_operand_loc,
3970                                NULL_PTR, NULL_PTR);
3971           break;
3972         }
3973
3974     default:
3975       /* Ordinary insn: recognize it, allocate space for operands and
3976          constraints, and get them out via insn_extract.  */
3977
3978       insn_code_number = recog_memoized (insn);
3979       noperands = insn_n_operands[insn_code_number];
3980       insn_extract (insn);
3981     }
3982
3983   if (noperands == 0)
3984     return;
3985
3986   for (i = 0; i < noperands; i++)
3987     {
3988       register RTX_CODE code = GET_CODE (recog_operand[i]);
3989       int is_set_dest = GET_CODE (body) == SET && (i == 0);
3990
3991       if (insn_code_number >= 0)
3992         if (insn_operand_address_p[insn_code_number][i])
3993           find_reloads_address (VOIDmode, NULL_PTR,
3994                                 recog_operand[i], recog_operand_loc[i],
3995                                 i, RELOAD_FOR_INPUT, ind_levels, insn);
3996
3997       /* In these cases, we can't tell if the operand is an input
3998          or an output, so be conservative.  In practice it won't be
3999          problem.  */
4000
4001       if (code == MEM)
4002         find_reloads_address (GET_MODE (recog_operand[i]),
4003                               recog_operand_loc[i],
4004                               XEXP (recog_operand[i], 0),
4005                               &XEXP (recog_operand[i], 0),
4006                               i, RELOAD_OTHER, ind_levels, insn);
4007       if (code == SUBREG)
4008         recog_operand[i] = *recog_operand_loc[i]
4009           = find_reloads_toplev (recog_operand[i], i, RELOAD_OTHER,
4010                                  ind_levels, is_set_dest);
4011       if (code == REG)
4012         {
4013           register int regno = REGNO (recog_operand[i]);
4014           if (reg_equiv_constant[regno] != 0 && !is_set_dest)
4015             recog_operand[i] = *recog_operand_loc[i]
4016               = reg_equiv_constant[regno];
4017 #if 0 /* This might screw code in reload1.c to delete prior output-reload
4018          that feeds this insn.  */
4019           if (reg_equiv_mem[regno] != 0)
4020             recog_operand[i] = *recog_operand_loc[i]
4021               = reg_equiv_mem[regno];
4022 #endif
4023         }
4024     }
4025
4026   /* Perhaps an output reload can be combined with another
4027      to reduce needs by one.  */
4028   if (!goal_earlyclobber)
4029     combine_reloads ();
4030 #endif /* no REGISTER_CONSTRAINTS */
4031 }
4032
4033 /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
4034    accepts a memory operand with constant address.  */
4035
4036 static int
4037 alternative_allows_memconst (constraint, altnum)
4038      char *constraint;
4039      int altnum;
4040 {
4041   register int c;
4042   /* Skip alternatives before the one requested.  */
4043   while (altnum > 0)
4044     {
4045       while (*constraint++ != ',');
4046       altnum--;
4047     }
4048   /* Scan the requested alternative for 'm' or 'o'.
4049      If one of them is present, this alternative accepts memory constants.  */
4050   while ((c = *constraint++) && c != ',' && c != '#')
4051     if (c == 'm' || c == 'o')
4052       return 1;
4053   return 0;
4054 }
4055 \f
4056 /* Scan X for memory references and scan the addresses for reloading.
4057    Also checks for references to "constant" regs that we want to eliminate
4058    and replaces them with the values they stand for.
4059    We may alter X destructively if it contains a reference to such.
4060    If X is just a constant reg, we return the equivalent value
4061    instead of X.
4062
4063    IND_LEVELS says how many levels of indirect addressing this machine
4064    supports.
4065
4066    OPNUM and TYPE identify the purpose of the reload.
4067
4068    IS_SET_DEST is true if X is the destination of a SET, which is not
4069    appropriate to be replaced by a constant.  */
4070
4071 static rtx
4072 find_reloads_toplev (x, opnum, type, ind_levels, is_set_dest)
4073      rtx x;
4074      int opnum;
4075      enum reload_type type;
4076      int ind_levels;
4077      int is_set_dest;
4078 {
4079   register RTX_CODE code = GET_CODE (x);
4080
4081   register char *fmt = GET_RTX_FORMAT (code);
4082   register int i;
4083
4084   if (code == REG)
4085     {
4086       /* This code is duplicated for speed in find_reloads.  */
4087       register int regno = REGNO (x);
4088       if (reg_equiv_constant[regno] != 0 && !is_set_dest)
4089         x = reg_equiv_constant[regno];
4090 #if 0
4091 /*  This creates (subreg (mem...)) which would cause an unnecessary
4092     reload of the mem.  */
4093       else if (reg_equiv_mem[regno] != 0)
4094         x = reg_equiv_mem[regno];
4095 #endif
4096       else if (reg_equiv_address[regno] != 0)
4097         {
4098           /* If reg_equiv_address varies, it may be shared, so copy it.  */
4099           /* We must rerun eliminate_regs, in case the elimination
4100              offsets have changed.  */
4101           rtx addr = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0,
4102                                            NULL_RTX, 0),
4103                            0);
4104
4105           if (rtx_varies_p (addr))
4106             addr = copy_rtx (addr);
4107
4108           x = gen_rtx (MEM, GET_MODE (x), addr);
4109           RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4110           find_reloads_address (GET_MODE (x), NULL_PTR,
4111                                 XEXP (x, 0),
4112                                 &XEXP (x, 0), opnum, type, ind_levels, 0);
4113         }
4114       return x;
4115     }
4116   if (code == MEM)
4117     {
4118       rtx tem = x;
4119       find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0),
4120                             opnum, type, ind_levels, 0);
4121       return tem;
4122     }
4123
4124   if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG)
4125     {
4126       /* Check for SUBREG containing a REG that's equivalent to a constant. 
4127          If the constant has a known value, truncate it right now.
4128          Similarly if we are extracting a single-word of a multi-word
4129          constant.  If the constant is symbolic, allow it to be substituted
4130          normally.  push_reload will strip the subreg later.  If the
4131          constant is VOIDmode, abort because we will lose the mode of
4132          the register (this should never happen because one of the cases
4133          above should handle it).  */
4134
4135       register int regno = REGNO (SUBREG_REG (x));
4136       rtx tem;
4137
4138       if (subreg_lowpart_p (x)
4139           && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4140           && reg_equiv_constant[regno] != 0
4141           && (tem = gen_lowpart_common (GET_MODE (x),
4142                                         reg_equiv_constant[regno])) != 0)
4143         return tem;
4144
4145       if (GET_MODE_BITSIZE (GET_MODE (x)) == BITS_PER_WORD
4146           && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4147           && reg_equiv_constant[regno] != 0
4148           && (tem = operand_subword (reg_equiv_constant[regno],
4149                                      SUBREG_WORD (x), 0,
4150                                      GET_MODE (SUBREG_REG (x)))) != 0)
4151         return tem;
4152
4153       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4154           && reg_equiv_constant[regno] != 0
4155           && GET_MODE (reg_equiv_constant[regno]) == VOIDmode)
4156         abort ();
4157
4158       /* If the subreg contains a reg that will be converted to a mem,
4159          convert the subreg to a narrower memref now.
4160          Otherwise, we would get (subreg (mem ...) ...),
4161          which would force reload of the mem.
4162
4163          We also need to do this if there is an equivalent MEM that is
4164          not offsettable.  In that case, alter_subreg would produce an
4165          invalid address on big-endian machines.
4166
4167          For machines that extend byte loads, we must not reload using
4168          a wider mode if we have a paradoxical SUBREG.  find_reloads will
4169          force a reload in that case.  So we should not do anything here.  */
4170
4171       else if (regno >= FIRST_PSEUDO_REGISTER
4172 #ifdef LOAD_EXTEND_OP
4173                && (GET_MODE_SIZE (GET_MODE (x))
4174                    <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
4175 #endif
4176                && (reg_equiv_address[regno] != 0
4177                    || (reg_equiv_mem[regno] != 0
4178                        && (! strict_memory_address_p (GET_MODE (x), 
4179                                                       XEXP (reg_equiv_mem[regno], 0))
4180                            || ! offsettable_memref_p (reg_equiv_mem[regno])))))
4181         {
4182           int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
4183           /* We must rerun eliminate_regs, in case the elimination
4184              offsets have changed.  */
4185           rtx addr = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0,
4186                                            NULL_RTX, 0),
4187                            0);
4188           if (BYTES_BIG_ENDIAN)
4189             {
4190               int size;
4191               size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
4192               offset += MIN (size, UNITS_PER_WORD);
4193               size = GET_MODE_SIZE (GET_MODE (x));
4194               offset -= MIN (size, UNITS_PER_WORD);
4195             }
4196           addr = plus_constant (addr, offset);
4197           x = gen_rtx (MEM, GET_MODE (x), addr);
4198           RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4199           find_reloads_address (GET_MODE (x), NULL_PTR,
4200                                 XEXP (x, 0),
4201                                 &XEXP (x, 0), opnum, type, ind_levels, 0);
4202         }
4203
4204     }
4205
4206   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4207     {
4208       if (fmt[i] == 'e')
4209         XEXP (x, i) = find_reloads_toplev (XEXP (x, i), opnum, type,
4210                                            ind_levels, is_set_dest);
4211     }
4212   return x;
4213 }
4214
4215 /* Return a mem ref for the memory equivalent of reg REGNO.
4216    This mem ref is not shared with anything.  */
4217
4218 static rtx
4219 make_memloc (ad, regno)
4220      rtx ad;
4221      int regno;
4222 {
4223   register int i;
4224   /* We must rerun eliminate_regs, in case the elimination
4225      offsets have changed.  */
4226   rtx tem = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0, NULL_RTX, 0),
4227                   0);
4228
4229 #if 0 /* We cannot safely reuse a memloc made here;
4230          if the pseudo appears twice, and its mem needs a reload,
4231          it gets two separate reloads assigned, but it only
4232          gets substituted with the second of them;
4233          then it can get used before that reload reg gets loaded up.  */
4234   for (i = 0; i < n_memlocs; i++)
4235     if (rtx_equal_p (tem, XEXP (memlocs[i], 0)))
4236       return memlocs[i];
4237 #endif
4238
4239   /* If TEM might contain a pseudo, we must copy it to avoid
4240      modifying it when we do the substitution for the reload.  */
4241   if (rtx_varies_p (tem))
4242     tem = copy_rtx (tem);
4243
4244   tem = gen_rtx (MEM, GET_MODE (ad), tem);
4245   RTX_UNCHANGING_P (tem) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4246   memlocs[n_memlocs++] = tem;
4247   return tem;
4248 }
4249
4250 /* Record all reloads needed for handling memory address AD
4251    which appears in *LOC in a memory reference to mode MODE
4252    which itself is found in location  *MEMREFLOC.
4253    Note that we take shortcuts assuming that no multi-reg machine mode
4254    occurs as part of an address.
4255
4256    OPNUM and TYPE specify the purpose of this reload.
4257
4258    IND_LEVELS says how many levels of indirect addressing this machine
4259    supports.
4260
4261    INSN, if nonzero, is the insn in which we do the reload.  It is used
4262    to determine if we may generate output reloads.
4263
4264    Value is nonzero if this address is reloaded or replaced as a whole.
4265    This is interesting to the caller if the address is an autoincrement.
4266
4267    Note that there is no verification that the address will be valid after
4268    this routine does its work.  Instead, we rely on the fact that the address
4269    was valid when reload started.  So we need only undo things that reload
4270    could have broken.  These are wrong register types, pseudos not allocated
4271    to a hard register, and frame pointer elimination.  */
4272
4273 static int
4274 find_reloads_address (mode, memrefloc, ad, loc, opnum, type, ind_levels, insn)
4275      enum machine_mode mode;
4276      rtx *memrefloc;
4277      rtx ad;
4278      rtx *loc;
4279      int opnum;
4280      enum reload_type type;
4281      int ind_levels;
4282      rtx insn;
4283 {
4284   register int regno;
4285   rtx tem;
4286
4287   /* If the address is a register, see if it is a legitimate address and
4288      reload if not.  We first handle the cases where we need not reload
4289      or where we must reload in a non-standard way.  */
4290
4291   if (GET_CODE (ad) == REG)
4292     {
4293       regno = REGNO (ad);
4294
4295       if (reg_equiv_constant[regno] != 0
4296           && strict_memory_address_p (mode, reg_equiv_constant[regno]))
4297         {
4298           *loc = ad = reg_equiv_constant[regno];
4299           return 1;
4300         }
4301
4302       else if (reg_equiv_address[regno] != 0)
4303         {
4304           tem = make_memloc (ad, regno);
4305           find_reloads_address (GET_MODE (tem), NULL_PTR, XEXP (tem, 0),
4306                                 &XEXP (tem, 0), opnum, ADDR_TYPE (type),
4307                                 ind_levels, insn);
4308           push_reload (tem, NULL_RTX, loc, NULL_PTR,
4309                        reload_address_base_reg_class,
4310                        GET_MODE (ad), VOIDmode, 0, 0,
4311                        opnum, type);
4312           return 1;
4313         }
4314
4315       /* We can avoid a reload if the register's equivalent memory expression
4316          is valid as an indirect memory address.
4317          But not all addresses are valid in a mem used as an indirect address:
4318          only reg or reg+constant.  */
4319
4320       else if (reg_equiv_mem[regno] != 0 && ind_levels > 0
4321                && strict_memory_address_p (mode, reg_equiv_mem[regno])
4322                && (GET_CODE (XEXP (reg_equiv_mem[regno], 0)) == REG
4323                    || (GET_CODE (XEXP (reg_equiv_mem[regno], 0)) == PLUS
4324                        && GET_CODE (XEXP (XEXP (reg_equiv_mem[regno], 0), 0)) == REG
4325                        && CONSTANT_P (XEXP (XEXP (reg_equiv_mem[regno], 0), 1)))))
4326         return 0;
4327
4328       /* The only remaining case where we can avoid a reload is if this is a
4329          hard register that is valid as a base register and which is not the
4330          subject of a CLOBBER in this insn.  */
4331
4332       else if (regno < FIRST_PSEUDO_REGISTER
4333                && REGNO_MODE_OK_FOR_BASE_P (regno, mode)
4334                && ! regno_clobbered_p (regno, this_insn))
4335         return 0;
4336
4337       /* If we do not have one of the cases above, we must do the reload.  */
4338       push_reload (ad, NULL_RTX, loc, NULL_PTR, reload_address_base_reg_class,
4339                    GET_MODE (ad), VOIDmode, 0, 0, opnum, type);
4340       return 1;
4341     }
4342
4343   if (strict_memory_address_p (mode, ad))
4344     {
4345       /* The address appears valid, so reloads are not needed.
4346          But the address may contain an eliminable register.
4347          This can happen because a machine with indirect addressing
4348          may consider a pseudo register by itself a valid address even when
4349          it has failed to get a hard reg.
4350          So do a tree-walk to find and eliminate all such regs.  */
4351
4352       /* But first quickly dispose of a common case.  */
4353       if (GET_CODE (ad) == PLUS
4354           && GET_CODE (XEXP (ad, 1)) == CONST_INT
4355           && GET_CODE (XEXP (ad, 0)) == REG
4356           && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
4357         return 0;
4358
4359       subst_reg_equivs_changed = 0;
4360       *loc = subst_reg_equivs (ad);
4361
4362       if (! subst_reg_equivs_changed)
4363         return 0;
4364
4365       /* Check result for validity after substitution.  */
4366       if (strict_memory_address_p (mode, ad))
4367         return 0;
4368     }
4369
4370   /* The address is not valid.  We have to figure out why.  One possibility
4371      is that it is itself a MEM.  This can happen when the frame pointer is
4372      being eliminated, a pseudo is not allocated to a hard register, and the
4373      offset between the frame and stack pointers is not its initial value.
4374      In that case the pseudo will have been replaced by a MEM referring to
4375      the stack pointer.  */
4376   if (GET_CODE (ad) == MEM)
4377     {
4378       /* First ensure that the address in this MEM is valid.  Then, unless
4379          indirect addresses are valid, reload the MEM into a register.  */
4380       tem = ad;
4381       find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0),
4382                             opnum, ADDR_TYPE (type),
4383                             ind_levels == 0 ? 0 : ind_levels - 1, insn);
4384
4385       /* If tem was changed, then we must create a new memory reference to
4386          hold it and store it back into memrefloc.  */
4387       if (tem != ad && memrefloc)
4388         {
4389           *memrefloc = copy_rtx (*memrefloc);
4390           copy_replacements (tem, XEXP (*memrefloc, 0));
4391           loc = &XEXP (*memrefloc, 0);
4392         }
4393
4394       /* Check similar cases as for indirect addresses as above except
4395          that we can allow pseudos and a MEM since they should have been
4396          taken care of above.  */
4397
4398       if (ind_levels == 0
4399           || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok)
4400           || GET_CODE (XEXP (tem, 0)) == MEM
4401           || ! (GET_CODE (XEXP (tem, 0)) == REG
4402                 || (GET_CODE (XEXP (tem, 0)) == PLUS
4403                     && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG
4404                     && GET_CODE (XEXP (XEXP (tem, 0), 1)) == CONST_INT)))
4405         {
4406           /* Must use TEM here, not AD, since it is the one that will
4407              have any subexpressions reloaded, if needed.  */
4408           push_reload (tem, NULL_RTX, loc, NULL_PTR,
4409                        reload_address_base_reg_class, GET_MODE (tem),
4410                        VOIDmode, 0,
4411                        0, opnum, type);
4412           return 1;
4413         }
4414       else
4415         return 0;
4416     }
4417
4418   /* If we have address of a stack slot but it's not valid because the
4419      displacement is too large, compute the sum in a register.
4420      Handle all base registers here, not just fp/ap/sp, because on some
4421      targets (namely SH) we can also get too large displacements from
4422      big-endian corrections.  */
4423   else if (GET_CODE (ad) == PLUS
4424            && GET_CODE (XEXP (ad, 0)) == REG
4425            && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER
4426            && REG_MODE_OK_FOR_BASE_P (XEXP (ad, 0), mode)
4427            && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4428     {
4429       /* Unshare the MEM rtx so we can safely alter it.  */
4430       if (memrefloc)
4431         {
4432           *memrefloc = copy_rtx (*memrefloc);
4433           loc = &XEXP (*memrefloc, 0);
4434         }
4435       if (double_reg_address_ok)
4436         {
4437           /* Unshare the sum as well.  */
4438           *loc = ad = copy_rtx (ad);
4439           /* Reload the displacement into an index reg.
4440              We assume the frame pointer or arg pointer is a base reg.  */
4441           find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4442                                      reload_address_index_reg_class,
4443                                      GET_MODE (ad), opnum, type, ind_levels);
4444         }
4445       else
4446         {
4447           /* If the sum of two regs is not necessarily valid,
4448              reload the sum into a base reg.
4449              That will at least work.  */
4450           find_reloads_address_part (ad, loc, reload_address_base_reg_class,
4451                                      Pmode, opnum, type, ind_levels);
4452         }
4453       return 1;
4454     }
4455
4456   /* If we have an indexed stack slot, there are three possible reasons why
4457      it might be invalid: The index might need to be reloaded, the address
4458      might have been made by frame pointer elimination and hence have a
4459      constant out of range, or both reasons might apply.  
4460
4461      We can easily check for an index needing reload, but even if that is the
4462      case, we might also have an invalid constant.  To avoid making the
4463      conservative assumption and requiring two reloads, we see if this address
4464      is valid when not interpreted strictly.  If it is, the only problem is
4465      that the index needs a reload and find_reloads_address_1 will take care
4466      of it.
4467
4468      There is still a case when we might generate an extra reload,
4469      however.  In certain cases eliminate_regs will return a MEM for a REG
4470      (see the code there for details).  In those cases, memory_address_p
4471      applied to our address will return 0 so we will think that our offset
4472      must be too large.  But it might indeed be valid and the only problem
4473      is that a MEM is present where a REG should be.  This case should be
4474      very rare and there doesn't seem to be any way to avoid it.
4475
4476      If we decide to do something here, it must be that
4477      `double_reg_address_ok' is true and that this address rtl was made by
4478      eliminate_regs.  We generate a reload of the fp/sp/ap + constant and
4479      rework the sum so that the reload register will be added to the index.
4480      This is safe because we know the address isn't shared.
4481
4482      We check for fp/ap/sp as both the first and second operand of the
4483      innermost PLUS.  */
4484
4485   else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4486            && GET_CODE (XEXP (ad, 0)) == PLUS
4487            && (XEXP (XEXP (ad, 0), 0) == frame_pointer_rtx
4488 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
4489                || XEXP (XEXP (ad, 0), 0) == hard_frame_pointer_rtx
4490 #endif
4491 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4492                || XEXP (XEXP (ad, 0), 0) == arg_pointer_rtx
4493 #endif
4494                || XEXP (XEXP (ad, 0), 0) == stack_pointer_rtx)
4495            && ! memory_address_p (mode, ad))
4496     {
4497       *loc = ad = gen_rtx (PLUS, GET_MODE (ad),
4498                            plus_constant (XEXP (XEXP (ad, 0), 0),
4499                                           INTVAL (XEXP (ad, 1))),
4500                            XEXP (XEXP (ad, 0), 1));
4501       find_reloads_address_part (XEXP (ad, 0), &XEXP (ad, 0),
4502                                  reload_address_base_reg_class,
4503                                  GET_MODE (ad), opnum, type, ind_levels);
4504       find_reloads_address_1 (mode, XEXP (ad, 1), 1, &XEXP (ad, 1), opnum,
4505                               type, 0, insn);
4506
4507       return 1;
4508     }
4509                            
4510   else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4511            && GET_CODE (XEXP (ad, 0)) == PLUS
4512            && (XEXP (XEXP (ad, 0), 1) == frame_pointer_rtx
4513 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4514                || XEXP (XEXP (ad, 0), 1) == hard_frame_pointer_rtx
4515 #endif
4516 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4517                || XEXP (XEXP (ad, 0), 1) == arg_pointer_rtx
4518 #endif
4519                || XEXP (XEXP (ad, 0), 1) == stack_pointer_rtx)
4520            && ! memory_address_p (mode, ad))
4521     {
4522       *loc = ad = gen_rtx (PLUS, GET_MODE (ad),
4523                            XEXP (XEXP (ad, 0), 0),
4524                            plus_constant (XEXP (XEXP (ad, 0), 1),
4525                                           INTVAL (XEXP (ad, 1))));
4526       find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4527                                  reload_address_base_reg_class,
4528                                  GET_MODE (ad), opnum, type, ind_levels);
4529       find_reloads_address_1 (mode, XEXP (ad, 0), 1, &XEXP (ad, 0), opnum,
4530                               type, 0, insn);
4531
4532       return 1;
4533     }
4534                            
4535   /* See if address becomes valid when an eliminable register
4536      in a sum is replaced.  */
4537
4538   tem = ad;
4539   if (GET_CODE (ad) == PLUS)
4540     tem = subst_indexed_address (ad);
4541   if (tem != ad && strict_memory_address_p (mode, tem))
4542     {
4543       /* Ok, we win that way.  Replace any additional eliminable
4544          registers.  */
4545
4546       subst_reg_equivs_changed = 0;
4547       tem = subst_reg_equivs (tem);
4548
4549       /* Make sure that didn't make the address invalid again.  */
4550
4551       if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
4552         {
4553           *loc = tem;
4554           return 0;
4555         }
4556     }
4557
4558   /* If constants aren't valid addresses, reload the constant address
4559      into a register.  */
4560   if (CONSTANT_P (ad) && ! strict_memory_address_p (mode, ad))
4561     {
4562       /* If AD is in address in the constant pool, the MEM rtx may be shared.
4563          Unshare it so we can safely alter it.  */
4564       if (memrefloc && GET_CODE (ad) == SYMBOL_REF
4565           && CONSTANT_POOL_ADDRESS_P (ad))
4566         {
4567           *memrefloc = copy_rtx (*memrefloc);
4568           loc = &XEXP (*memrefloc, 0);
4569         }
4570
4571       find_reloads_address_part (ad, loc, reload_address_base_reg_class,
4572                                  Pmode, opnum, type,
4573                                  ind_levels);
4574       return 1;
4575     }
4576
4577   return find_reloads_address_1 (mode, ad, 0, loc, opnum, type, ind_levels,
4578                                  insn);
4579 }
4580 \f
4581 /* Find all pseudo regs appearing in AD
4582    that are eliminable in favor of equivalent values
4583    and do not have hard regs; replace them by their equivalents.  */
4584
4585 static rtx
4586 subst_reg_equivs (ad)
4587      rtx ad;
4588 {
4589   register RTX_CODE code = GET_CODE (ad);
4590   register int i;
4591   register char *fmt;
4592
4593   switch (code)
4594     {
4595     case HIGH:
4596     case CONST_INT:
4597     case CONST:
4598     case CONST_DOUBLE:
4599     case SYMBOL_REF:
4600     case LABEL_REF:
4601     case PC:
4602     case CC0:
4603       return ad;
4604
4605     case REG:
4606       {
4607         register int regno = REGNO (ad);
4608
4609         if (reg_equiv_constant[regno] != 0)
4610           {
4611             subst_reg_equivs_changed = 1;
4612             return reg_equiv_constant[regno];
4613           }
4614       }
4615       return ad;
4616
4617     case PLUS:
4618       /* Quickly dispose of a common case.  */
4619       if (XEXP (ad, 0) == frame_pointer_rtx
4620           && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4621         return ad;
4622     }
4623
4624   fmt = GET_RTX_FORMAT (code);
4625   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4626     if (fmt[i] == 'e')
4627       XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i));
4628   return ad;
4629 }
4630 \f
4631 /* Compute the sum of X and Y, making canonicalizations assumed in an
4632    address, namely: sum constant integers, surround the sum of two
4633    constants with a CONST, put the constant as the second operand, and
4634    group the constant on the outermost sum.
4635
4636    This routine assumes both inputs are already in canonical form.  */
4637
4638 rtx
4639 form_sum (x, y)
4640      rtx x, y;
4641 {
4642   rtx tem;
4643   enum machine_mode mode = GET_MODE (x);
4644
4645   if (mode == VOIDmode)
4646     mode = GET_MODE (y);
4647
4648   if (mode == VOIDmode)
4649     mode = Pmode;
4650
4651   if (GET_CODE (x) == CONST_INT)
4652     return plus_constant (y, INTVAL (x));
4653   else if (GET_CODE (y) == CONST_INT)
4654     return plus_constant (x, INTVAL (y));
4655   else if (CONSTANT_P (x))
4656     tem = x, x = y, y = tem;
4657
4658   if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
4659     return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y));
4660
4661   /* Note that if the operands of Y are specified in the opposite
4662      order in the recursive calls below, infinite recursion will occur.  */
4663   if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
4664     return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1));
4665
4666   /* If both constant, encapsulate sum.  Otherwise, just form sum.  A
4667      constant will have been placed second.  */
4668   if (CONSTANT_P (x) && CONSTANT_P (y))
4669     {
4670       if (GET_CODE (x) == CONST)
4671         x = XEXP (x, 0);
4672       if (GET_CODE (y) == CONST)
4673         y = XEXP (y, 0);
4674
4675       return gen_rtx (CONST, VOIDmode, gen_rtx (PLUS, mode, x, y));
4676     }
4677
4678   return gen_rtx (PLUS, mode, x, y);
4679 }
4680 \f
4681 /* If ADDR is a sum containing a pseudo register that should be
4682    replaced with a constant (from reg_equiv_constant),
4683    return the result of doing so, and also apply the associative
4684    law so that the result is more likely to be a valid address.
4685    (But it is not guaranteed to be one.)
4686
4687    Note that at most one register is replaced, even if more are
4688    replaceable.  Also, we try to put the result into a canonical form
4689    so it is more likely to be a valid address.
4690
4691    In all other cases, return ADDR.  */
4692
4693 static rtx
4694 subst_indexed_address (addr)
4695      rtx addr;
4696 {
4697   rtx op0 = 0, op1 = 0, op2 = 0;
4698   rtx tem;
4699   int regno;
4700
4701   if (GET_CODE (addr) == PLUS)
4702     {
4703       /* Try to find a register to replace.  */
4704       op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0;
4705       if (GET_CODE (op0) == REG
4706           && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER
4707           && reg_renumber[regno] < 0
4708           && reg_equiv_constant[regno] != 0)
4709         op0 = reg_equiv_constant[regno];
4710       else if (GET_CODE (op1) == REG
4711           && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER
4712           && reg_renumber[regno] < 0
4713           && reg_equiv_constant[regno] != 0)
4714         op1 = reg_equiv_constant[regno];
4715       else if (GET_CODE (op0) == PLUS
4716                && (tem = subst_indexed_address (op0)) != op0)
4717         op0 = tem;
4718       else if (GET_CODE (op1) == PLUS
4719                && (tem = subst_indexed_address (op1)) != op1)
4720         op1 = tem;
4721       else
4722         return addr;
4723
4724       /* Pick out up to three things to add.  */
4725       if (GET_CODE (op1) == PLUS)
4726         op2 = XEXP (op1, 1), op1 = XEXP (op1, 0);
4727       else if (GET_CODE (op0) == PLUS)
4728         op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
4729
4730       /* Compute the sum.  */
4731       if (op2 != 0)
4732         op1 = form_sum (op1, op2);
4733       if (op1 != 0)
4734         op0 = form_sum (op0, op1);
4735
4736       return op0;
4737     }
4738   return addr;
4739 }
4740 \f
4741 /* Record the pseudo registers we must reload into hard registers in a
4742    subexpression of a would-be memory address, X referring to a value
4743    in mode MODE.  (This function is not called if the address we find
4744    is strictly valid.)
4745
4746    CONTEXT = 1 means we are considering regs as index regs,
4747    = 0 means we are considering them as base regs.
4748
4749    OPNUM and TYPE specify the purpose of any reloads made.
4750
4751    IND_LEVELS says how many levels of indirect addressing are
4752    supported at this point in the address.
4753
4754    INSN, if nonzero, is the insn in which we do the reload.  It is used
4755    to determine if we may generate output reloads.
4756
4757    We return nonzero if X, as a whole, is reloaded or replaced.  */
4758
4759 /* Note that we take shortcuts assuming that no multi-reg machine mode
4760    occurs as part of an address.
4761    Also, this is not fully machine-customizable; it works for machines
4762    such as vaxes and 68000's and 32000's, but other possible machines
4763    could have addressing modes that this does not handle right.  */
4764
4765 static int
4766 find_reloads_address_1 (mode, x, context, loc, opnum, type, ind_levels, insn)
4767      enum machine_mode mode;
4768      rtx x;
4769      int context;
4770      rtx *loc;
4771      int opnum;
4772      enum reload_type type;
4773      int ind_levels;
4774      rtx insn;
4775 {
4776   register RTX_CODE code = GET_CODE (x);
4777
4778   switch (code)
4779     {
4780     case PLUS:
4781       {
4782         register rtx orig_op0 = XEXP (x, 0);
4783         register rtx orig_op1 = XEXP (x, 1);
4784         register RTX_CODE code0 = GET_CODE (orig_op0);
4785         register RTX_CODE code1 = GET_CODE (orig_op1);
4786         register rtx op0 = orig_op0;
4787         register rtx op1 = orig_op1;
4788
4789         if (GET_CODE (op0) == SUBREG)
4790           {
4791             op0 = SUBREG_REG (op0);
4792             code0 = GET_CODE (op0);
4793             if (code0 == REG && REGNO (op0) < FIRST_PSEUDO_REGISTER)
4794               op0 = gen_rtx (REG, word_mode,
4795                              REGNO (op0) + SUBREG_WORD (orig_op0));
4796           }
4797
4798         if (GET_CODE (op1) == SUBREG)
4799           {
4800             op1 = SUBREG_REG (op1);
4801             code1 = GET_CODE (op1);
4802             if (code1 == REG && REGNO (op1) < FIRST_PSEUDO_REGISTER)
4803               op1 = gen_rtx (REG, GET_MODE (op1),
4804                              REGNO (op1) + SUBREG_WORD (orig_op1));
4805           }
4806
4807         if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE 
4808             || code0 == ZERO_EXTEND || code1 == MEM)
4809           {
4810             find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4811                                     type, ind_levels, insn);
4812             find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4813                                     type, ind_levels, insn);
4814           }
4815
4816         else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
4817                  || code1 == ZERO_EXTEND || code0 == MEM)
4818           {
4819             find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4820                                     type, ind_levels, insn);
4821             find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
4822                                     type, ind_levels, insn);
4823           }
4824
4825         else if (code0 == CONST_INT || code0 == CONST
4826                  || code0 == SYMBOL_REF || code0 == LABEL_REF)
4827           find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4828                                   type, ind_levels, insn);
4829
4830         else if (code1 == CONST_INT || code1 == CONST
4831                  || code1 == SYMBOL_REF || code1 == LABEL_REF)
4832           find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4833                                   type, ind_levels, insn);
4834
4835         else if (code0 == REG && code1 == REG)
4836           {
4837             if (REG_OK_FOR_INDEX_P (op0)
4838                 && REG_MODE_OK_FOR_BASE_P (op1, mode))
4839               return 0;
4840             else if (REG_OK_FOR_INDEX_P (op1)
4841                      && REG_MODE_OK_FOR_BASE_P (op0, mode))
4842               return 0;
4843             else if (REG_MODE_OK_FOR_BASE_P (op1, mode))
4844               find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4845                                       type, ind_levels, insn);
4846             else if (REG_MODE_OK_FOR_BASE_P (op0, mode))
4847               find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
4848                                       type, ind_levels, insn);
4849             else if (REG_OK_FOR_INDEX_P (op1))
4850               find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4851                                       type, ind_levels, insn);
4852             else if (REG_OK_FOR_INDEX_P (op0))
4853               find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4854                                       type, ind_levels, insn);
4855             else
4856               {
4857                 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4858                                         type, ind_levels, insn);
4859                 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4860                                         type, ind_levels, insn);
4861               }
4862           }
4863
4864         else if (code0 == REG)
4865           {
4866             find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4867                                     type, ind_levels, insn);
4868             find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4869                                     type, ind_levels, insn);
4870           }
4871
4872         else if (code1 == REG)
4873           {
4874             find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
4875                                     type, ind_levels, insn);
4876             find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4877                                     type, ind_levels, insn);
4878           }
4879       }
4880
4881       return 0;
4882
4883     case POST_INC:
4884     case POST_DEC:
4885     case PRE_INC:
4886     case PRE_DEC:
4887       if (GET_CODE (XEXP (x, 0)) == REG)
4888         {
4889           register int regno = REGNO (XEXP (x, 0));
4890           int value = 0;
4891           rtx x_orig = x;
4892
4893           /* A register that is incremented cannot be constant!  */
4894           if (regno >= FIRST_PSEUDO_REGISTER
4895               && reg_equiv_constant[regno] != 0)
4896             abort ();
4897
4898           /* Handle a register that is equivalent to a memory location
4899              which cannot be addressed directly.  */
4900           if (reg_equiv_address[regno] != 0)
4901             {
4902               rtx tem = make_memloc (XEXP (x, 0), regno);
4903               /* First reload the memory location's address.
4904                  We can't use ADDR_TYPE (type) here, because we need to
4905                  write back the value after reading it, hence we actually
4906                  need two registers.  */
4907               find_reloads_address (GET_MODE (tem), 0, XEXP (tem, 0),
4908                                     &XEXP (tem, 0), opnum, type,
4909                                     ind_levels, insn);
4910               /* Put this inside a new increment-expression.  */
4911               x = gen_rtx (GET_CODE (x), GET_MODE (x), tem);
4912               /* Proceed to reload that, as if it contained a register.  */
4913             }
4914
4915           /* If we have a hard register that is ok as an index,
4916              don't make a reload.  If an autoincrement of a nice register
4917              isn't "valid", it must be that no autoincrement is "valid".
4918              If that is true and something made an autoincrement anyway,
4919              this must be a special context where one is allowed.
4920              (For example, a "push" instruction.)
4921              We can't improve this address, so leave it alone.  */
4922
4923           /* Otherwise, reload the autoincrement into a suitable hard reg
4924              and record how much to increment by.  */
4925
4926           if (reg_renumber[regno] >= 0)
4927             regno = reg_renumber[regno];
4928           if ((regno >= FIRST_PSEUDO_REGISTER
4929                || !(context ? REGNO_OK_FOR_INDEX_P (regno)
4930                     : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
4931             {
4932               register rtx link;
4933               int reloadnum;
4934
4935               /* If we can output the register afterwards, do so, this
4936                  saves the extra update.
4937                  We can do so if we have an INSN - i.e. no JUMP_INSN nor
4938                  CALL_INSN - and it does not set CC0.
4939                  But don't do this if we cannot directly address the
4940                  memory location, since this will make it harder to
4941                  reuse address reloads, and increses register pressure.
4942                  Also don't do this if we can probably update x directly.  */
4943               rtx equiv = reg_equiv_mem[regno];
4944               int icode = (int) add_optab->handlers[(int) Pmode].insn_code;
4945               if (insn && GET_CODE (insn) == INSN && equiv
4946 #ifdef HAVE_cc0
4947                   && ! sets_cc0_p (PATTERN (insn))
4948 #endif
4949                   && ! (icode != CODE_FOR_nothing
4950                         && (*insn_operand_predicate[icode][0]) (equiv, Pmode)
4951                         && (*insn_operand_predicate[icode][1]) (equiv, Pmode)))
4952                 {
4953                   loc = &XEXP (x, 0);
4954                   x = XEXP (x, 0);
4955                   reloadnum
4956                     = push_reload (x, x, loc, loc,
4957                                    (context
4958                                     ? reload_address_index_reg_class
4959                                     : reload_address_base_reg_class),
4960                                     GET_MODE (x), GET_MODE (x), VOIDmode, 0,
4961                                     opnum, RELOAD_OTHER);
4962                 }
4963               else
4964                 {
4965                   reloadnum
4966                     = push_reload (x, NULL_RTX, loc, NULL_PTR,
4967                                    (context
4968                                     ? reload_address_index_reg_class
4969                                     : reload_address_base_reg_class),
4970                                    GET_MODE (x), GET_MODE (x), VOIDmode, 0,
4971                                    opnum, type);
4972                   reload_inc[reloadnum]
4973                     = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0));
4974     
4975                   value = 1;
4976                 }
4977
4978 #ifdef AUTO_INC_DEC
4979               /* Update the REG_INC notes.  */
4980
4981               for (link = REG_NOTES (this_insn);
4982                    link; link = XEXP (link, 1))
4983                 if (REG_NOTE_KIND (link) == REG_INC
4984                     && REGNO (XEXP (link, 0)) == REGNO (XEXP (x_orig, 0)))
4985                   push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
4986 #endif
4987             }
4988           return value;
4989         }
4990
4991       else if (GET_CODE (XEXP (x, 0)) == MEM)
4992         {
4993           /* This is probably the result of a substitution, by eliminate_regs,
4994              of an equivalent address for a pseudo that was not allocated to a
4995              hard register.  Verify that the specified address is valid and
4996              reload it into a register.  */
4997           rtx tem = XEXP (x, 0);
4998           register rtx link;
4999           int reloadnum;
5000
5001           /* Since we know we are going to reload this item, don't decrement
5002              for the indirection level.
5003
5004              Note that this is actually conservative:  it would be slightly
5005              more efficient to use the value of SPILL_INDIRECT_LEVELS from
5006              reload1.c here.  */
5007           /* We can't use ADDR_TYPE (type) here, because we need to
5008              write back the value after reading it, hence we actually
5009              need two registers.  */
5010           find_reloads_address (GET_MODE (x), &XEXP (x, 0),
5011                                 XEXP (XEXP (x, 0), 0), &XEXP (XEXP (x, 0), 0),
5012                                 opnum, type, ind_levels, insn);
5013
5014           reloadnum = push_reload (x, NULL_RTX, loc, NULL_PTR,
5015                                    (context
5016                                     ? reload_address_index_reg_class
5017                                     : reload_address_base_reg_class),
5018                                    GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5019           reload_inc[reloadnum]
5020             = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
5021
5022           link = FIND_REG_INC_NOTE (this_insn, tem);
5023           if (link != 0)
5024             push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5025
5026           return 1;
5027         }
5028       return 0;
5029
5030     case MEM:
5031       /* This is probably the result of a substitution, by eliminate_regs, of
5032          an equivalent address for a pseudo that was not allocated to a hard
5033          register.  Verify that the specified address is valid and reload it
5034          into a register.
5035
5036          Since we know we are going to reload this item, don't decrement for
5037          the indirection level.
5038
5039          Note that this is actually conservative:  it would be slightly more
5040          efficient to use the value of SPILL_INDIRECT_LEVELS from
5041          reload1.c here.  */
5042
5043       find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5044                             opnum, ADDR_TYPE (type), ind_levels, insn);
5045       push_reload (*loc, NULL_RTX, loc, NULL_PTR,
5046                    (context ? reload_address_index_reg_class
5047                     : reload_address_base_reg_class),
5048                    GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5049       return 1;
5050
5051     case REG:
5052       {
5053         register int regno = REGNO (x);
5054
5055         if (reg_equiv_constant[regno] != 0)
5056           {
5057             find_reloads_address_part (reg_equiv_constant[regno], loc, 
5058                                        (context
5059                                         ? reload_address_index_reg_class
5060                                         : reload_address_base_reg_class),
5061                                        GET_MODE (x), opnum, type, ind_levels);
5062             return 1;
5063           }
5064
5065 #if 0 /* This might screw code in reload1.c to delete prior output-reload
5066          that feeds this insn.  */
5067         if (reg_equiv_mem[regno] != 0)
5068           {
5069             push_reload (reg_equiv_mem[regno], NULL_RTX, loc, NULL_PTR,
5070                          (context
5071                           ? reload_address_index_reg_class
5072                           : reload_address_base_reg_class),
5073                          GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5074             return 1;
5075           }
5076 #endif
5077
5078         if (reg_equiv_address[regno] != 0)
5079           {
5080             x = make_memloc (x, regno);
5081             find_reloads_address (GET_MODE (x), 0, XEXP (x, 0), &XEXP (x, 0),
5082                                   opnum, ADDR_TYPE (type), ind_levels, insn);
5083           }
5084
5085         if (reg_renumber[regno] >= 0)
5086           regno = reg_renumber[regno];
5087
5088         if ((regno >= FIRST_PSEUDO_REGISTER
5089              || !(context ? REGNO_OK_FOR_INDEX_P (regno)
5090                   : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
5091           {
5092             push_reload (x, NULL_RTX, loc, NULL_PTR,
5093                          (context
5094                           ? reload_address_index_reg_class
5095                           : reload_address_base_reg_class),
5096                          GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5097             return 1;
5098           }
5099
5100         /* If a register appearing in an address is the subject of a CLOBBER
5101            in this insn, reload it into some other register to be safe.
5102            The CLOBBER is supposed to make the register unavailable
5103            from before this insn to after it.  */
5104         if (regno_clobbered_p (regno, this_insn))
5105           {
5106             push_reload (x, NULL_RTX, loc, NULL_PTR,
5107                          (context
5108                           ? reload_address_index_reg_class
5109                           : reload_address_base_reg_class),
5110                          GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5111             return 1;
5112           }
5113       }
5114       return 0;
5115
5116     case SUBREG:
5117       if (GET_CODE (SUBREG_REG (x)) == REG)
5118         {
5119           /* If this is a SUBREG of a hard register and the resulting register
5120              is of the wrong class, reload the whole SUBREG.  This avoids
5121              needless copies if SUBREG_REG is multi-word.  */
5122           if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5123             {
5124               int regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
5125
5126               if (! (context ? REGNO_OK_FOR_INDEX_P (regno)
5127                      : REGNO_MODE_OK_FOR_BASE_P (regno, mode)))
5128                 {
5129                   push_reload (x, NULL_RTX, loc, NULL_PTR,
5130                                (context
5131                                 ? reload_address_index_reg_class
5132                                 : reload_address_base_reg_class),
5133                                GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5134                   return 1;
5135                 }
5136             }
5137           /* If this is a SUBREG of a pseudo-register, and the pseudo-register
5138              is larger than the class size, then reload the whole SUBREG.  */
5139           else
5140             {
5141               enum reg_class class = (context
5142                                       ? reload_address_index_reg_class
5143                                       : reload_address_base_reg_class);
5144               if (CLASS_MAX_NREGS (class, GET_MODE (SUBREG_REG (x)))
5145                   > reg_class_size[class])
5146                 {
5147                   push_reload (x, NULL_RTX, loc, NULL_PTR, class,
5148                                GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5149                   return 1;
5150                 }
5151             }
5152         }
5153       break;
5154     }
5155
5156   {
5157     register char *fmt = GET_RTX_FORMAT (code);
5158     register int i;
5159
5160     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5161       {
5162         if (fmt[i] == 'e')
5163           find_reloads_address_1 (mode, XEXP (x, i), context, &XEXP (x, i),
5164                                   opnum, type, ind_levels, insn);
5165       }
5166   }
5167
5168   return 0;
5169 }
5170 \f
5171 /* X, which is found at *LOC, is a part of an address that needs to be
5172    reloaded into a register of class CLASS.  If X is a constant, or if
5173    X is a PLUS that contains a constant, check that the constant is a
5174    legitimate operand and that we are supposed to be able to load
5175    it into the register.
5176
5177    If not, force the constant into memory and reload the MEM instead.
5178
5179    MODE is the mode to use, in case X is an integer constant.
5180
5181    OPNUM and TYPE describe the purpose of any reloads made.
5182
5183    IND_LEVELS says how many levels of indirect addressing this machine
5184    supports.  */
5185
5186 static void
5187 find_reloads_address_part (x, loc, class, mode, opnum, type, ind_levels)
5188      rtx x;
5189      rtx *loc;
5190      enum reg_class class;
5191      enum machine_mode mode;
5192      int opnum;
5193      enum reload_type type;
5194      int ind_levels;
5195 {
5196   if (CONSTANT_P (x)
5197       && (! LEGITIMATE_CONSTANT_P (x)
5198           || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
5199     {
5200       rtx tem = x = force_const_mem (mode, x);
5201       find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5202                             opnum, type, ind_levels, 0);
5203     }
5204
5205   else if (GET_CODE (x) == PLUS
5206            && CONSTANT_P (XEXP (x, 1))
5207            && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
5208                || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
5209     {
5210       rtx tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
5211
5212       x = gen_rtx (PLUS, GET_MODE (x), XEXP (x, 0), tem);
5213       find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5214                             opnum, type, ind_levels, 0);
5215     }
5216
5217   push_reload (x, NULL_RTX, loc, NULL_PTR, class,
5218                mode, VOIDmode, 0, 0, opnum, type);
5219 }
5220 \f
5221 /* Substitute into the current INSN the registers into which we have reloaded
5222    the things that need reloading.  The array `replacements'
5223    says contains the locations of all pointers that must be changed
5224    and says what to replace them with.
5225
5226    Return the rtx that X translates into; usually X, but modified.  */
5227
5228 void
5229 subst_reloads ()
5230 {
5231   register int i;
5232
5233   for (i = 0; i < n_replacements; i++)
5234     {
5235       register struct replacement *r = &replacements[i];
5236       register rtx reloadreg = reload_reg_rtx[r->what];
5237       if (reloadreg)
5238         {
5239           /* Encapsulate RELOADREG so its machine mode matches what
5240              used to be there.  Note that gen_lowpart_common will
5241              do the wrong thing if RELOADREG is multi-word.  RELOADREG
5242              will always be a REG here.  */
5243           if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
5244             reloadreg = gen_rtx (REG, r->mode, REGNO (reloadreg));
5245
5246           /* If we are putting this into a SUBREG and RELOADREG is a
5247              SUBREG, we would be making nested SUBREGs, so we have to fix
5248              this up.  Note that r->where == &SUBREG_REG (*r->subreg_loc).  */
5249
5250           if (r->subreg_loc != 0 && GET_CODE (reloadreg) == SUBREG)
5251             {
5252               if (GET_MODE (*r->subreg_loc)
5253                   == GET_MODE (SUBREG_REG (reloadreg)))
5254                 *r->subreg_loc = SUBREG_REG (reloadreg);
5255               else
5256                 {
5257                   *r->where = SUBREG_REG (reloadreg);
5258                   SUBREG_WORD (*r->subreg_loc) += SUBREG_WORD (reloadreg);
5259                 }
5260             }
5261           else
5262             *r->where = reloadreg;
5263         }
5264       /* If reload got no reg and isn't optional, something's wrong.  */
5265       else if (! reload_optional[r->what])
5266         abort ();
5267     }
5268 }
5269 \f
5270 /* Make a copy of any replacements being done into X and move those copies
5271    to locations in Y, a copy of X.  We only look at the highest level of
5272    the RTL.  */
5273
5274 void
5275 copy_replacements (x, y)
5276      rtx x;
5277      rtx y;
5278 {
5279   int i, j;
5280   enum rtx_code code = GET_CODE (x);
5281   char *fmt = GET_RTX_FORMAT (code);
5282   struct replacement *r;
5283
5284   /* We can't support X being a SUBREG because we might then need to know its
5285      location if something inside it was replaced.  */
5286   if (code == SUBREG)
5287     abort ();
5288
5289   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5290     if (fmt[i] == 'e')
5291       for (j = 0; j < n_replacements; j++)
5292         {
5293           if (replacements[j].subreg_loc == &XEXP (x, i))
5294             {
5295               r = &replacements[n_replacements++];
5296               r->where = replacements[j].where;
5297               r->subreg_loc = &XEXP (y, i);
5298               r->what = replacements[j].what;
5299               r->mode = replacements[j].mode;
5300             }
5301           else if (replacements[j].where == &XEXP (x, i))
5302             {
5303               r = &replacements[n_replacements++];
5304               r->where = &XEXP (y, i);
5305               r->subreg_loc = 0;
5306               r->what = replacements[j].what;
5307               r->mode = replacements[j].mode;
5308             }
5309         }
5310 }
5311 \f
5312 /* If LOC was scheduled to be replaced by something, return the replacement.
5313    Otherwise, return *LOC.  */
5314
5315 rtx
5316 find_replacement (loc)
5317      rtx *loc;
5318 {
5319   struct replacement *r;
5320
5321   for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
5322     {
5323       rtx reloadreg = reload_reg_rtx[r->what];
5324
5325       if (reloadreg && r->where == loc)
5326         {
5327           if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
5328             reloadreg = gen_rtx (REG, r->mode, REGNO (reloadreg));
5329
5330           return reloadreg;
5331         }
5332       else if (reloadreg && r->subreg_loc == loc)
5333         {
5334           /* RELOADREG must be either a REG or a SUBREG.
5335
5336              ??? Is it actually still ever a SUBREG?  If so, why?  */
5337
5338           if (GET_CODE (reloadreg) == REG)
5339             return gen_rtx (REG, GET_MODE (*loc),
5340                             REGNO (reloadreg) + SUBREG_WORD (*loc));
5341           else if (GET_MODE (reloadreg) == GET_MODE (*loc))
5342             return reloadreg;
5343           else
5344             return gen_rtx (SUBREG, GET_MODE (*loc), SUBREG_REG (reloadreg),
5345                             SUBREG_WORD (reloadreg) + SUBREG_WORD (*loc));
5346         }
5347     }
5348
5349   return *loc;
5350 }
5351 \f
5352 /* Return nonzero if register in range [REGNO, ENDREGNO)
5353    appears either explicitly or implicitly in X
5354    other than being stored into (except for earlyclobber operands).
5355
5356    References contained within the substructure at LOC do not count.
5357    LOC may be zero, meaning don't ignore anything.
5358
5359    This is similar to refers_to_regno_p in rtlanal.c except that we
5360    look at equivalences for pseudos that didn't get hard registers.  */
5361
5362 int
5363 refers_to_regno_for_reload_p (regno, endregno, x, loc)
5364      int regno, endregno;
5365      rtx x;
5366      rtx *loc;
5367 {
5368   register int i;
5369   register RTX_CODE code;
5370   register char *fmt;
5371
5372   if (x == 0)
5373     return 0;
5374
5375  repeat:
5376   code = GET_CODE (x);
5377
5378   switch (code)
5379     {
5380     case REG:
5381       i = REGNO (x);
5382
5383       /* If this is a pseudo, a hard register must not have been allocated.
5384          X must therefore either be a constant or be in memory.  */
5385       if (i >= FIRST_PSEUDO_REGISTER)
5386         {
5387           if (reg_equiv_memory_loc[i])
5388             return refers_to_regno_for_reload_p (regno, endregno,
5389                                                  reg_equiv_memory_loc[i],
5390                                                  NULL_PTR);
5391
5392           if (reg_equiv_constant[i])
5393             return 0;
5394
5395           abort ();
5396         }
5397
5398       return (endregno > i
5399               && regno < i + (i < FIRST_PSEUDO_REGISTER 
5400                               ? HARD_REGNO_NREGS (i, GET_MODE (x))
5401                               : 1));
5402
5403     case SUBREG:
5404       /* If this is a SUBREG of a hard reg, we can see exactly which
5405          registers are being modified.  Otherwise, handle normally.  */
5406       if (GET_CODE (SUBREG_REG (x)) == REG
5407           && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5408         {
5409           int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
5410           int inner_endregno
5411             = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
5412                              ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
5413
5414           return endregno > inner_regno && regno < inner_endregno;
5415         }
5416       break;
5417
5418     case CLOBBER:
5419     case SET:
5420       if (&SET_DEST (x) != loc
5421           /* Note setting a SUBREG counts as referring to the REG it is in for
5422              a pseudo but not for hard registers since we can
5423              treat each word individually.  */
5424           && ((GET_CODE (SET_DEST (x)) == SUBREG
5425                && loc != &SUBREG_REG (SET_DEST (x))
5426                && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
5427                && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
5428                && refers_to_regno_for_reload_p (regno, endregno,
5429                                                 SUBREG_REG (SET_DEST (x)),
5430                                                 loc))
5431               /* If the output is an earlyclobber operand, this is
5432                  a conflict.  */
5433               || ((GET_CODE (SET_DEST (x)) != REG
5434                    || earlyclobber_operand_p (SET_DEST (x)))
5435                   && refers_to_regno_for_reload_p (regno, endregno,
5436                                                    SET_DEST (x), loc))))
5437         return 1;
5438
5439       if (code == CLOBBER || loc == &SET_SRC (x))
5440         return 0;
5441       x = SET_SRC (x);
5442       goto repeat;
5443     }
5444
5445   /* X does not match, so try its subexpressions.  */
5446
5447   fmt = GET_RTX_FORMAT (code);
5448   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5449     {
5450       if (fmt[i] == 'e' && loc != &XEXP (x, i))
5451         {
5452           if (i == 0)
5453             {
5454               x = XEXP (x, 0);
5455               goto repeat;
5456             }
5457           else
5458             if (refers_to_regno_for_reload_p (regno, endregno,
5459                                               XEXP (x, i), loc))
5460               return 1;
5461         }
5462       else if (fmt[i] == 'E')
5463         {
5464           register int j;
5465           for (j = XVECLEN (x, i) - 1; j >=0; j--)
5466             if (loc != &XVECEXP (x, i, j)
5467                 && refers_to_regno_for_reload_p (regno, endregno,
5468                                                  XVECEXP (x, i, j), loc))
5469               return 1;
5470         }
5471     }
5472   return 0;
5473 }
5474
5475 /* Nonzero if modifying X will affect IN.  If X is a register or a SUBREG,
5476    we check if any register number in X conflicts with the relevant register
5477    numbers.  If X is a constant, return 0.  If X is a MEM, return 1 iff IN
5478    contains a MEM (we don't bother checking for memory addresses that can't
5479    conflict because we expect this to be a rare case. 
5480
5481    This function is similar to reg_overlap_mention_p in rtlanal.c except
5482    that we look at equivalences for pseudos that didn't get hard registers.  */
5483
5484 int
5485 reg_overlap_mentioned_for_reload_p (x, in)
5486      rtx x, in;
5487 {
5488   int regno, endregno;
5489
5490   if (GET_CODE (x) == SUBREG)
5491     {
5492       regno = REGNO (SUBREG_REG (x));
5493       if (regno < FIRST_PSEUDO_REGISTER)
5494         regno += SUBREG_WORD (x);
5495     }
5496   else if (GET_CODE (x) == REG)
5497     {
5498       regno = REGNO (x);
5499
5500       /* If this is a pseudo, it must not have been assigned a hard register.
5501          Therefore, it must either be in memory or be a constant.  */
5502
5503       if (regno >= FIRST_PSEUDO_REGISTER)
5504         {
5505           if (reg_equiv_memory_loc[regno])
5506             return refers_to_mem_for_reload_p (in);
5507           else if (reg_equiv_constant[regno])
5508             return 0;
5509           abort ();
5510         }
5511     }
5512   else if (CONSTANT_P (x))
5513     return 0;
5514   else if (GET_CODE (x) == MEM)
5515     return refers_to_mem_for_reload_p (in);
5516   else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
5517            || GET_CODE (x) == CC0)
5518     return reg_mentioned_p (x, in);
5519   else
5520     abort ();
5521
5522   endregno = regno + (regno < FIRST_PSEUDO_REGISTER
5523                       ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
5524
5525   return refers_to_regno_for_reload_p (regno, endregno, in, NULL_PTR);
5526 }
5527
5528 /* Return nonzero if anything in X contains a MEM.  Look also for pseudo
5529    registers.  */
5530
5531 int
5532 refers_to_mem_for_reload_p (x)
5533      rtx x;
5534 {
5535   char *fmt;
5536   int i;
5537
5538   if (GET_CODE (x) == MEM)
5539     return 1;
5540
5541   if (GET_CODE (x) == REG)
5542     return (REGNO (x) >= FIRST_PSEUDO_REGISTER
5543             && reg_equiv_memory_loc[REGNO (x)]);
5544                         
5545   fmt = GET_RTX_FORMAT (GET_CODE (x));
5546   for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
5547     if (fmt[i] == 'e'
5548         && (GET_CODE (XEXP (x, i)) == MEM
5549             || refers_to_mem_for_reload_p (XEXP (x, i))))
5550       return 1;
5551   
5552   return 0;
5553 }
5554 \f
5555 /* Check the insns before INSN to see if there is a suitable register
5556    containing the same value as GOAL.
5557    If OTHER is -1, look for a register in class CLASS.
5558    Otherwise, just see if register number OTHER shares GOAL's value.
5559
5560    Return an rtx for the register found, or zero if none is found.
5561
5562    If RELOAD_REG_P is (short *)1,
5563    we reject any hard reg that appears in reload_reg_rtx
5564    because such a hard reg is also needed coming into this insn.
5565
5566    If RELOAD_REG_P is any other nonzero value,
5567    it is a vector indexed by hard reg number
5568    and we reject any hard reg whose element in the vector is nonnegative
5569    as well as any that appears in reload_reg_rtx.
5570
5571    If GOAL is zero, then GOALREG is a register number; we look
5572    for an equivalent for that register.
5573
5574    MODE is the machine mode of the value we want an equivalence for.
5575    If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
5576
5577    This function is used by jump.c as well as in the reload pass.
5578
5579    If GOAL is the sum of the stack pointer and a constant, we treat it
5580    as if it were a constant except that sp is required to be unchanging.  */
5581
5582 rtx
5583 find_equiv_reg (goal, insn, class, other, reload_reg_p, goalreg, mode)
5584      register rtx goal;
5585      rtx insn;
5586      enum reg_class class;
5587      register int other;
5588      short *reload_reg_p;
5589      int goalreg;
5590      enum machine_mode mode;
5591 {
5592   register rtx p = insn;
5593   rtx goaltry, valtry, value, where;
5594   register rtx pat;
5595   register int regno = -1;
5596   int valueno;
5597   int goal_mem = 0;
5598   int goal_const = 0;
5599   int goal_mem_addr_varies = 0;
5600   int need_stable_sp = 0;
5601   int nregs;
5602   int valuenregs;
5603
5604   if (goal == 0)
5605     regno = goalreg;
5606   else if (GET_CODE (goal) == REG)
5607     regno = REGNO (goal);
5608   else if (GET_CODE (goal) == MEM)
5609     {
5610       enum rtx_code code = GET_CODE (XEXP (goal, 0));
5611       if (MEM_VOLATILE_P (goal))
5612         return 0;
5613       if (flag_float_store && GET_MODE_CLASS (GET_MODE (goal)) == MODE_FLOAT)
5614         return 0;
5615       /* An address with side effects must be reexecuted.  */
5616       switch (code)
5617         {
5618         case POST_INC:
5619         case PRE_INC:
5620         case POST_DEC:
5621         case PRE_DEC:
5622           return 0;
5623         }
5624       goal_mem = 1;
5625     }
5626   else if (CONSTANT_P (goal))
5627     goal_const = 1;
5628   else if (GET_CODE (goal) == PLUS
5629            && XEXP (goal, 0) == stack_pointer_rtx
5630            && CONSTANT_P (XEXP (goal, 1)))
5631     goal_const = need_stable_sp = 1;
5632   else
5633     return 0;
5634
5635   /* On some machines, certain regs must always be rejected
5636      because they don't behave the way ordinary registers do.  */
5637   
5638 #ifdef OVERLAPPING_REGNO_P
5639    if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5640        && OVERLAPPING_REGNO_P (regno))
5641      return 0;
5642 #endif      
5643
5644   /* Scan insns back from INSN, looking for one that copies
5645      a value into or out of GOAL.
5646      Stop and give up if we reach a label.  */
5647
5648   while (1)
5649     {
5650       p = PREV_INSN (p);
5651       if (p == 0 || GET_CODE (p) == CODE_LABEL)
5652         return 0;
5653       if (GET_CODE (p) == INSN
5654           /* If we don't want spill regs ...  */
5655           && (! (reload_reg_p != 0
5656                  && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
5657           /* ... then ignore insns introduced by reload; they aren't useful
5658              and can cause results in reload_as_needed to be different
5659              from what they were when calculating the need for spills.
5660              If we notice an input-reload insn here, we will reject it below,
5661              but it might hide a usable equivalent.  That makes bad code.
5662              It may even abort: perhaps no reg was spilled for this insn
5663              because it was assumed we would find that equivalent.  */
5664               || INSN_UID (p) < reload_first_uid))
5665         {
5666           rtx tem;
5667           pat = single_set (p);
5668           /* First check for something that sets some reg equal to GOAL.  */
5669           if (pat != 0
5670               && ((regno >= 0
5671                    && true_regnum (SET_SRC (pat)) == regno
5672                    && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
5673                   ||
5674                   (regno >= 0
5675                    && true_regnum (SET_DEST (pat)) == regno
5676                    && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0)
5677                   ||
5678                   (goal_const && rtx_equal_p (SET_SRC (pat), goal)
5679                    && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
5680                   || (goal_mem
5681                       && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0
5682                       && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
5683                   || (goal_mem
5684                       && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0
5685                       && rtx_renumbered_equal_p (goal, SET_DEST (pat)))
5686                   /* If we are looking for a constant,
5687                      and something equivalent to that constant was copied
5688                      into a reg, we can use that reg.  */
5689                   || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
5690                                                           NULL_RTX))
5691                       && rtx_equal_p (XEXP (tem, 0), goal)
5692                       && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
5693                   || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
5694                                                           NULL_RTX))
5695                       && GET_CODE (SET_DEST (pat)) == REG
5696                       && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
5697                       && GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) == MODE_FLOAT
5698                       && GET_CODE (goal) == CONST_INT
5699                       && 0 != (goaltry = operand_subword (XEXP (tem, 0), 0, 0,
5700                                                           VOIDmode))
5701                       && rtx_equal_p (goal, goaltry)
5702                       && (valtry = operand_subword (SET_DEST (pat), 0, 0,
5703                                                     VOIDmode))
5704                       && (valueno = true_regnum (valtry)) >= 0)
5705                   || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
5706                                                           NULL_RTX))
5707                       && GET_CODE (SET_DEST (pat)) == REG
5708                       && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
5709                       && GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) == MODE_FLOAT
5710                       && GET_CODE (goal) == CONST_INT
5711                       && 0 != (goaltry = operand_subword (XEXP (tem, 0), 1, 0,
5712                                                           VOIDmode))
5713                       && rtx_equal_p (goal, goaltry)
5714                       && (valtry
5715                           = operand_subword (SET_DEST (pat), 1, 0, VOIDmode))
5716                       && (valueno = true_regnum (valtry)) >= 0)))
5717             if (other >= 0
5718                 ? valueno == other
5719                 : ((unsigned) valueno < FIRST_PSEUDO_REGISTER
5720                    && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
5721                                          valueno)))
5722               {
5723                 value = valtry;
5724                 where = p;
5725                 break;
5726               }
5727         }
5728     }
5729
5730   /* We found a previous insn copying GOAL into a suitable other reg VALUE
5731      (or copying VALUE into GOAL, if GOAL is also a register).
5732      Now verify that VALUE is really valid.  */
5733
5734   /* VALUENO is the register number of VALUE; a hard register.  */
5735
5736   /* Don't try to re-use something that is killed in this insn.  We want
5737      to be able to trust REG_UNUSED notes.  */
5738   if (find_reg_note (where, REG_UNUSED, value))
5739     return 0;
5740
5741   /* If we propose to get the value from the stack pointer or if GOAL is
5742      a MEM based on the stack pointer, we need a stable SP.  */
5743   if (valueno == STACK_POINTER_REGNUM || regno == STACK_POINTER_REGNUM
5744       || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx,
5745                                                           goal)))
5746     need_stable_sp = 1;
5747
5748   /* Reject VALUE if the copy-insn moved the wrong sort of datum.  */
5749   if (GET_MODE (value) != mode)
5750     return 0;
5751
5752   /* Reject VALUE if it was loaded from GOAL
5753      and is also a register that appears in the address of GOAL.  */
5754
5755   if (goal_mem && value == SET_DEST (single_set (where))
5756       && refers_to_regno_for_reload_p (valueno,
5757                                        (valueno
5758                                         + HARD_REGNO_NREGS (valueno, mode)),
5759                                        goal, NULL_PTR))
5760     return 0;
5761
5762   /* Reject registers that overlap GOAL.  */
5763
5764   if (!goal_mem && !goal_const
5765       && regno + HARD_REGNO_NREGS (regno, mode) > valueno
5766       && regno < valueno + HARD_REGNO_NREGS (valueno, mode))
5767     return 0;
5768
5769   /* Reject VALUE if it is one of the regs reserved for reloads.
5770      Reload1 knows how to reuse them anyway, and it would get
5771      confused if we allocated one without its knowledge.
5772      (Now that insns introduced by reload are ignored above,
5773      this case shouldn't happen, but I'm not positive.)  */
5774
5775   if (reload_reg_p != 0 && reload_reg_p != (short *) (HOST_WIDE_INT) 1
5776       && reload_reg_p[valueno] >= 0)
5777     return 0;
5778
5779   /* On some machines, certain regs must always be rejected
5780      because they don't behave the way ordinary registers do.  */
5781   
5782 #ifdef OVERLAPPING_REGNO_P
5783   if (OVERLAPPING_REGNO_P (valueno))
5784     return 0;
5785 #endif      
5786
5787   nregs = HARD_REGNO_NREGS (regno, mode);
5788   valuenregs = HARD_REGNO_NREGS (valueno, mode);
5789
5790   /* Reject VALUE if it is a register being used for an input reload
5791      even if it is not one of those reserved.  */
5792
5793   if (reload_reg_p != 0)
5794     {
5795       int i;
5796       for (i = 0; i < n_reloads; i++)
5797         if (reload_reg_rtx[i] != 0 && reload_in[i])
5798           {
5799             int regno1 = REGNO (reload_reg_rtx[i]);
5800             int nregs1 = HARD_REGNO_NREGS (regno1,
5801                                            GET_MODE (reload_reg_rtx[i]));
5802             if (regno1 < valueno + valuenregs
5803                 && regno1 + nregs1 > valueno)
5804               return 0;
5805           }
5806     }
5807
5808   if (goal_mem)
5809     /* We must treat frame pointer as varying here,
5810        since it can vary--in a nonlocal goto as generated by expand_goto.  */
5811     goal_mem_addr_varies = !CONSTANT_ADDRESS_P (XEXP (goal, 0));
5812
5813   /* Now verify that the values of GOAL and VALUE remain unaltered
5814      until INSN is reached.  */
5815
5816   p = insn;
5817   while (1)
5818     {
5819       p = PREV_INSN (p);
5820       if (p == where)
5821         return value;
5822
5823       /* Don't trust the conversion past a function call
5824          if either of the two is in a call-clobbered register, or memory.  */
5825       if (GET_CODE (p) == CALL_INSN
5826           && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5827                && call_used_regs[regno])
5828               ||
5829               (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
5830                && call_used_regs[valueno])
5831               ||
5832               goal_mem
5833               || need_stable_sp))
5834         return 0;
5835
5836 #ifdef NON_SAVING_SETJMP 
5837       if (NON_SAVING_SETJMP && GET_CODE (p) == NOTE
5838           && NOTE_LINE_NUMBER (p) == NOTE_INSN_SETJMP)
5839         return 0;
5840 #endif
5841
5842 #ifdef INSN_CLOBBERS_REGNO_P
5843       if ((valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
5844           && INSN_CLOBBERS_REGNO_P (p, valueno))
5845           || (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5846           && INSN_CLOBBERS_REGNO_P (p, regno)))
5847         return 0;
5848 #endif
5849
5850       if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
5851         {
5852           /* If this insn P stores in either GOAL or VALUE, return 0.
5853              If GOAL is a memory ref and this insn writes memory, return 0.
5854              If GOAL is a memory ref and its address is not constant,
5855              and this insn P changes a register used in GOAL, return 0.  */
5856
5857           pat = PATTERN (p);
5858           if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
5859             {
5860               register rtx dest = SET_DEST (pat);
5861               while (GET_CODE (dest) == SUBREG
5862                      || GET_CODE (dest) == ZERO_EXTRACT
5863                      || GET_CODE (dest) == SIGN_EXTRACT
5864                      || GET_CODE (dest) == STRICT_LOW_PART)
5865                 dest = XEXP (dest, 0);
5866               if (GET_CODE (dest) == REG)
5867                 {
5868                   register int xregno = REGNO (dest);
5869                   int xnregs;
5870                   if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5871                     xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5872                   else
5873                     xnregs = 1;
5874                   if (xregno < regno + nregs && xregno + xnregs > regno)
5875                     return 0;
5876                   if (xregno < valueno + valuenregs
5877                       && xregno + xnregs > valueno)
5878                     return 0;
5879                   if (goal_mem_addr_varies
5880                       && reg_overlap_mentioned_for_reload_p (dest, goal))
5881                     return 0;
5882                 }
5883               else if (goal_mem && GET_CODE (dest) == MEM
5884                        && ! push_operand (dest, GET_MODE (dest)))
5885                 return 0;
5886               else if (GET_CODE (dest) == MEM && regno >= FIRST_PSEUDO_REGISTER
5887                        && reg_equiv_memory_loc[regno] != 0)
5888                 return 0;
5889               else if (need_stable_sp && push_operand (dest, GET_MODE (dest)))
5890                 return 0;
5891             }
5892           else if (GET_CODE (pat) == PARALLEL)
5893             {
5894               register int i;
5895               for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
5896                 {
5897                   register rtx v1 = XVECEXP (pat, 0, i);
5898                   if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
5899                     {
5900                       register rtx dest = SET_DEST (v1);
5901                       while (GET_CODE (dest) == SUBREG
5902                              || GET_CODE (dest) == ZERO_EXTRACT
5903                              || GET_CODE (dest) == SIGN_EXTRACT
5904                              || GET_CODE (dest) == STRICT_LOW_PART)
5905                         dest = XEXP (dest, 0);
5906                       if (GET_CODE (dest) == REG)
5907                         {
5908                           register int xregno = REGNO (dest);
5909                           int xnregs;
5910                           if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5911                             xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5912                           else
5913                             xnregs = 1;
5914                           if (xregno < regno + nregs
5915                               && xregno + xnregs > regno)
5916                             return 0;
5917                           if (xregno < valueno + valuenregs
5918                               && xregno + xnregs > valueno)
5919                             return 0;
5920                           if (goal_mem_addr_varies
5921                               && reg_overlap_mentioned_for_reload_p (dest,
5922                                                                      goal))
5923                             return 0;
5924                         }
5925                       else if (goal_mem && GET_CODE (dest) == MEM
5926                                && ! push_operand (dest, GET_MODE (dest)))
5927                         return 0;
5928                       else if (need_stable_sp
5929                                && push_operand (dest, GET_MODE (dest)))
5930                         return 0;
5931                     }
5932                 }
5933             }
5934
5935           if (GET_CODE (p) == CALL_INSN && CALL_INSN_FUNCTION_USAGE (p))
5936             {
5937               rtx link;
5938
5939               for (link = CALL_INSN_FUNCTION_USAGE (p); XEXP (link, 1) != 0;
5940                    link = XEXP (link, 1))
5941                 {
5942                   pat = XEXP (link, 0);
5943                   if (GET_CODE (pat) == CLOBBER)
5944                     {
5945                       register rtx dest = SET_DEST (pat);
5946                       while (GET_CODE (dest) == SUBREG
5947                              || GET_CODE (dest) == ZERO_EXTRACT
5948                              || GET_CODE (dest) == SIGN_EXTRACT
5949                              || GET_CODE (dest) == STRICT_LOW_PART)
5950                         dest = XEXP (dest, 0);
5951                       if (GET_CODE (dest) == REG)
5952                         {
5953                           register int xregno = REGNO (dest);
5954                           int xnregs;
5955                           if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5956                             xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5957                           else
5958                             xnregs = 1;
5959                           if (xregno < regno + nregs
5960                               && xregno + xnregs > regno)
5961                             return 0;
5962                           if (xregno < valueno + valuenregs
5963                               && xregno + xnregs > valueno)
5964                             return 0;
5965                           if (goal_mem_addr_varies
5966                               && reg_overlap_mentioned_for_reload_p (dest,
5967                                                                      goal))
5968                             return 0;
5969                         }
5970                       else if (goal_mem && GET_CODE (dest) == MEM
5971                                && ! push_operand (dest, GET_MODE (dest)))
5972                         return 0;
5973                       else if (need_stable_sp
5974                                && push_operand (dest, GET_MODE (dest)))
5975                         return 0;
5976                     }
5977                 }
5978             }
5979
5980 #ifdef AUTO_INC_DEC
5981           /* If this insn auto-increments or auto-decrements
5982              either regno or valueno, return 0 now.
5983              If GOAL is a memory ref and its address is not constant,
5984              and this insn P increments a register used in GOAL, return 0.  */
5985           {
5986             register rtx link;
5987
5988             for (link = REG_NOTES (p); link; link = XEXP (link, 1))
5989               if (REG_NOTE_KIND (link) == REG_INC
5990                   && GET_CODE (XEXP (link, 0)) == REG)
5991                 {
5992                   register int incno = REGNO (XEXP (link, 0));
5993                   if (incno < regno + nregs && incno >= regno)
5994                     return 0;
5995                   if (incno < valueno + valuenregs && incno >= valueno)
5996                     return 0;
5997                   if (goal_mem_addr_varies
5998                       && reg_overlap_mentioned_for_reload_p (XEXP (link, 0),
5999                                                              goal))
6000                     return 0;
6001                 }
6002           }
6003 #endif
6004         }
6005     }
6006 }
6007 \f
6008 /* Find a place where INCED appears in an increment or decrement operator
6009    within X, and return the amount INCED is incremented or decremented by.
6010    The value is always positive.  */
6011
6012 static int
6013 find_inc_amount (x, inced)
6014      rtx x, inced;
6015 {
6016   register enum rtx_code code = GET_CODE (x);
6017   register char *fmt;
6018   register int i;
6019
6020   if (code == MEM)
6021     {
6022       register rtx addr = XEXP (x, 0);
6023       if ((GET_CODE (addr) == PRE_DEC
6024            || GET_CODE (addr) == POST_DEC
6025            || GET_CODE (addr) == PRE_INC
6026            || GET_CODE (addr) == POST_INC)
6027           && XEXP (addr, 0) == inced)
6028         return GET_MODE_SIZE (GET_MODE (x));
6029     }
6030
6031   fmt = GET_RTX_FORMAT (code);
6032   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6033     {
6034       if (fmt[i] == 'e')
6035         {
6036           register int tem = find_inc_amount (XEXP (x, i), inced);
6037           if (tem != 0)
6038             return tem;
6039         }
6040       if (fmt[i] == 'E')
6041         {
6042           register int j;
6043           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6044             {
6045               register int tem = find_inc_amount (XVECEXP (x, i, j), inced);
6046               if (tem != 0)
6047                 return tem;
6048             }
6049         }
6050     }
6051
6052   return 0;
6053 }
6054 \f
6055 /* Return 1 if register REGNO is the subject of a clobber in insn INSN.  */
6056
6057 int
6058 regno_clobbered_p (regno, insn)
6059      int regno;
6060      rtx insn;
6061 {
6062   if (GET_CODE (PATTERN (insn)) == CLOBBER
6063       && GET_CODE (XEXP (PATTERN (insn), 0)) == REG)
6064     return REGNO (XEXP (PATTERN (insn), 0)) == regno;
6065
6066   if (GET_CODE (PATTERN (insn)) == PARALLEL)
6067     {
6068       int i = XVECLEN (PATTERN (insn), 0) - 1;
6069
6070       for (; i >= 0; i--)
6071         {
6072           rtx elt = XVECEXP (PATTERN (insn), 0, i);
6073           if (GET_CODE (elt) == CLOBBER && GET_CODE (XEXP (elt, 0)) == REG
6074               && REGNO (XEXP (elt, 0)) == regno)
6075             return 1;
6076         }
6077     }
6078
6079   return 0;
6080 }
6081
6082 static char *reload_when_needed_name[] =
6083 {
6084   "RELOAD_FOR_INPUT", 
6085   "RELOAD_FOR_OUTPUT", 
6086   "RELOAD_FOR_INSN",
6087   "RELOAD_FOR_INPUT_ADDRESS",
6088   "RELOAD_FOR_INPADDR_ADDRESS",
6089   "RELOAD_FOR_OUTPUT_ADDRESS",
6090   "RELOAD_FOR_OUTADDR_ADDRESS",
6091   "RELOAD_FOR_OPERAND_ADDRESS", 
6092   "RELOAD_FOR_OPADDR_ADDR",
6093   "RELOAD_OTHER", 
6094   "RELOAD_FOR_OTHER_ADDRESS"
6095 };
6096
6097 static char *reg_class_names[] = REG_CLASS_NAMES;
6098
6099 /* This function is used to print the variables set by 'find_reloads' */
6100
6101 void
6102 debug_reload ()
6103 {
6104   int r;
6105   char *prefix;
6106
6107   for (r = 0; r < n_reloads; r++)
6108     {
6109       fprintf (stderr, "Reload %d: ", r);
6110
6111       if (reload_in[r] != 0)
6112         {
6113           fprintf (stderr, "reload_in (%s) = ",
6114                    GET_MODE_NAME (reload_inmode[r]));
6115           print_inline_rtx (stderr, reload_in[r], 24);
6116           fprintf (stderr, "\n\t");
6117         }
6118
6119       if (reload_out[r] != 0)
6120         {
6121           fprintf (stderr, "reload_out (%s) = ",
6122                    GET_MODE_NAME (reload_outmode[r]));
6123           print_inline_rtx (stderr, reload_out[r], 24);
6124           fprintf (stderr, "\n\t");
6125         }
6126
6127       fprintf (stderr, "%s, ", reg_class_names[(int) reload_reg_class[r]]);
6128
6129       fprintf (stderr, "%s (opnum = %d)",
6130                reload_when_needed_name[(int) reload_when_needed[r]],
6131                reload_opnum[r]);
6132
6133       if (reload_optional[r])
6134         fprintf (stderr, ", optional");
6135
6136       if (reload_inc[r] != 0)
6137         fprintf (stderr, ", inc by %d", reload_inc[r]);
6138
6139       if (reload_nocombine[r])
6140         fprintf (stderr, ", can't combine");
6141
6142       if (reload_secondary_p[r])
6143         fprintf (stderr, ", secondary_reload_p");
6144
6145       if (reload_in_reg[r] != 0)
6146         {
6147           fprintf (stderr, "\n\treload_in_reg: ");
6148           print_inline_rtx (stderr, reload_in_reg[r], 24);
6149         }
6150
6151       if (reload_reg_rtx[r] != 0)
6152         {
6153           fprintf (stderr, "\n\treload_reg_rtx: ");
6154           print_inline_rtx (stderr, reload_reg_rtx[r], 24);
6155         }
6156
6157       prefix = "\n\t";
6158       if (reload_secondary_in_reload[r] != -1)
6159         {
6160           fprintf (stderr, "%ssecondary_in_reload = %d",
6161                    prefix, reload_secondary_in_reload[r]);
6162           prefix = ", ";
6163         }
6164
6165       if (reload_secondary_out_reload[r] != -1)
6166         fprintf (stderr, "%ssecondary_out_reload = %d\n",
6167                  prefix, reload_secondary_out_reload[r]);
6168
6169       prefix = "\n\t";
6170       if (reload_secondary_in_icode[r] != CODE_FOR_nothing)
6171         {
6172           fprintf (stderr, "%ssecondary_in_icode = %s", prefix, insn_name[r]);
6173           prefix = ", ";
6174         }
6175
6176       if (reload_secondary_out_icode[r] != CODE_FOR_nothing)
6177         fprintf (stderr, "%ssecondary_out_icode = %s", prefix, insn_name[r]);
6178
6179       fprintf (stderr, "\n");
6180     }
6181 }