Include expr.h.
[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));
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
1384       /* If the outgoing register already contains the same value
1385          as the incoming one, we can dispense with loading it.
1386          The easiest way to tell the caller that is to give a phony
1387          value for the incoming operand (same as outgoing one).  */
1388       if (reload_reg_rtx[i] == out
1389           && (GET_CODE (in) == REG || CONSTANT_P (in))
1390           && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
1391                                   static_reload_reg_p, i, inmode))
1392         reload_in[i] = out;
1393     }
1394
1395   /* If this is an input reload and the operand contains a register that
1396      dies in this insn and is used nowhere else, see if it is the right class
1397      to be used for this reload.  Use it if so.  (This occurs most commonly
1398      in the case of paradoxical SUBREGs and in-out reloads).  We cannot do
1399      this if it is also an output reload that mentions the register unless
1400      the output is a SUBREG that clobbers an entire register.
1401
1402      Note that the operand might be one of the spill regs, if it is a
1403      pseudo reg and we are in a block where spilling has not taken place.
1404      But if there is no spilling in this block, that is OK.
1405      An explicitly used hard reg cannot be a spill reg.  */
1406
1407   if (reload_reg_rtx[i] == 0 && in != 0)
1408     {
1409       rtx note;
1410       int regno;
1411
1412       for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1413         if (REG_NOTE_KIND (note) == REG_DEAD
1414             && GET_CODE (XEXP (note, 0)) == REG
1415             && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER
1416             && reg_mentioned_p (XEXP (note, 0), in)
1417             && ! refers_to_regno_for_reload_p (regno,
1418                                                (regno
1419                                                 + HARD_REGNO_NREGS (regno,
1420                                                                     inmode)),
1421                                                PATTERN (this_insn), inloc)
1422             /* If this is also an output reload, IN cannot be used as
1423                the reload register if it is set in this insn unless IN
1424                is also OUT.  */
1425             && (out == 0 || in == out
1426                 || ! hard_reg_set_here_p (regno,
1427                                           (regno
1428                                            + HARD_REGNO_NREGS (regno,
1429                                                                inmode)),
1430                                           PATTERN (this_insn)))
1431             /* ??? Why is this code so different from the previous?
1432                Is there any simple coherent way to describe the two together?
1433                What's going on here.  */
1434             && (in != out
1435                 || (GET_CODE (in) == SUBREG
1436                     && (((GET_MODE_SIZE (GET_MODE (in)) + (UNITS_PER_WORD - 1))
1437                          / UNITS_PER_WORD)
1438                         == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1439                              + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
1440             /* Make sure the operand fits in the reg that dies.  */
1441             && GET_MODE_SIZE (inmode) <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))
1442             && HARD_REGNO_MODE_OK (regno, inmode)
1443             && GET_MODE_SIZE (outmode) <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))
1444             && HARD_REGNO_MODE_OK (regno, outmode)
1445             && TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno)
1446             && !fixed_regs[regno])
1447           {
1448             reload_reg_rtx[i] = gen_rtx (REG, inmode, regno);
1449             break;
1450           }
1451     }
1452
1453   if (out)
1454     output_reloadnum = i;
1455
1456   return i;
1457 }
1458
1459 /* Record an additional place we must replace a value
1460    for which we have already recorded a reload.
1461    RELOADNUM is the value returned by push_reload
1462    when the reload was recorded.
1463    This is used in insn patterns that use match_dup.  */
1464
1465 static void
1466 push_replacement (loc, reloadnum, mode)
1467      rtx *loc;
1468      int reloadnum;
1469      enum machine_mode mode;
1470 {
1471   if (replace_reloads)
1472     {
1473       register struct replacement *r = &replacements[n_replacements++];
1474       r->what = reloadnum;
1475       r->where = loc;
1476       r->subreg_loc = 0;
1477       r->mode = mode;
1478     }
1479 }
1480 \f
1481 /* Transfer all replacements that used to be in reload FROM to be in
1482    reload TO.  */
1483
1484 void
1485 transfer_replacements (to, from)
1486      int to, from;
1487 {
1488   int i;
1489
1490   for (i = 0; i < n_replacements; i++)
1491     if (replacements[i].what == from)
1492       replacements[i].what = to;
1493 }
1494 \f
1495 /* If there is only one output reload, and it is not for an earlyclobber
1496    operand, try to combine it with a (logically unrelated) input reload
1497    to reduce the number of reload registers needed.
1498
1499    This is safe if the input reload does not appear in
1500    the value being output-reloaded, because this implies
1501    it is not needed any more once the original insn completes.
1502
1503    If that doesn't work, see we can use any of the registers that
1504    die in this insn as a reload register.  We can if it is of the right
1505    class and does not appear in the value being output-reloaded.  */
1506
1507 static void
1508 combine_reloads ()
1509 {
1510   int i;
1511   int output_reload = -1;
1512   int secondary_out = -1;
1513   rtx note;
1514
1515   /* Find the output reload; return unless there is exactly one
1516      and that one is mandatory.  */
1517
1518   for (i = 0; i < n_reloads; i++)
1519     if (reload_out[i] != 0)
1520       {
1521         if (output_reload >= 0)
1522           return;
1523         output_reload = i;
1524       }
1525
1526   if (output_reload < 0 || reload_optional[output_reload])
1527     return;
1528
1529   /* An input-output reload isn't combinable.  */
1530
1531   if (reload_in[output_reload] != 0)
1532     return;
1533
1534   /* If this reload is for an earlyclobber operand, we can't do anything.  */
1535   if (earlyclobber_operand_p (reload_out[output_reload]))
1536     return;
1537
1538   /* Check each input reload; can we combine it?  */
1539
1540   for (i = 0; i < n_reloads; i++)
1541     if (reload_in[i] && ! reload_optional[i] && ! reload_nocombine[i]
1542         /* Life span of this reload must not extend past main insn.  */
1543         && reload_when_needed[i] != RELOAD_FOR_OUTPUT_ADDRESS
1544         && reload_when_needed[i] != RELOAD_FOR_OUTADDR_ADDRESS
1545         && reload_when_needed[i] != RELOAD_OTHER
1546         && (CLASS_MAX_NREGS (reload_reg_class[i], reload_inmode[i])
1547             == CLASS_MAX_NREGS (reload_reg_class[output_reload],
1548                                 reload_outmode[output_reload]))
1549         && reload_inc[i] == 0
1550         && reload_reg_rtx[i] == 0
1551 #ifdef SECONDARY_MEMORY_NEEDED
1552         /* Don't combine two reloads with different secondary
1553            memory locations.  */
1554         && (secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[i]] == 0
1555             || secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[output_reload]] == 0
1556             || rtx_equal_p (secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[i]],
1557                             secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[output_reload]]))
1558 #endif
1559         && (
1560 #ifdef SMALL_REGISTER_CLASSES
1561             SMALL_REGISTER_CLASSES
1562 #else
1563             0
1564 #endif
1565               ? reload_reg_class[i] == reload_reg_class[output_reload]
1566               : (reg_class_subset_p (reload_reg_class[i],
1567                                      reload_reg_class[output_reload])
1568                  || reg_class_subset_p (reload_reg_class[output_reload],
1569                                         reload_reg_class[i])))
1570         && (MATCHES (reload_in[i], reload_out[output_reload])
1571             /* Args reversed because the first arg seems to be
1572                the one that we imagine being modified
1573                while the second is the one that might be affected.  */
1574             || (! reg_overlap_mentioned_for_reload_p (reload_out[output_reload],
1575                                                       reload_in[i])
1576                 /* However, if the input is a register that appears inside
1577                    the output, then we also can't share.
1578                    Imagine (set (mem (reg 69)) (plus (reg 69) ...)).
1579                    If the same reload reg is used for both reg 69 and the
1580                    result to be stored in memory, then that result
1581                    will clobber the address of the memory ref.  */
1582                 && ! (GET_CODE (reload_in[i]) == REG
1583                       && reg_overlap_mentioned_for_reload_p (reload_in[i],
1584                                                              reload_out[output_reload]))))
1585         && (reg_class_size[(int) reload_reg_class[i]]
1586 #ifdef SMALL_REGISTER_CLASSES
1587              || SMALL_REGISTER_CLASSES
1588 #endif
1589             )
1590         /* We will allow making things slightly worse by combining an
1591            input and an output, but no worse than that.  */
1592         && (reload_when_needed[i] == RELOAD_FOR_INPUT
1593             || reload_when_needed[i] == RELOAD_FOR_OUTPUT))
1594       {
1595         int j;
1596
1597         /* We have found a reload to combine with!  */
1598         reload_out[i] = reload_out[output_reload];
1599         reload_outmode[i] = reload_outmode[output_reload];
1600         /* Mark the old output reload as inoperative.  */
1601         reload_out[output_reload] = 0;
1602         /* The combined reload is needed for the entire insn.  */
1603         reload_when_needed[i] = RELOAD_OTHER;
1604         /* If the output reload had a secondary reload, copy it.  */
1605         if (reload_secondary_out_reload[output_reload] != -1)
1606           {
1607             reload_secondary_out_reload[i]
1608               = reload_secondary_out_reload[output_reload];
1609             reload_secondary_out_icode[i]
1610               = reload_secondary_out_icode[output_reload];
1611           }
1612
1613 #ifdef SECONDARY_MEMORY_NEEDED
1614         /* Copy any secondary MEM.  */
1615         if (secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[output_reload]] != 0)
1616           secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[i]]
1617             = secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[output_reload]];
1618 #endif
1619         /* If required, minimize the register class.  */
1620         if (reg_class_subset_p (reload_reg_class[output_reload],
1621                                 reload_reg_class[i]))
1622           reload_reg_class[i] = reload_reg_class[output_reload];
1623
1624         /* Transfer all replacements from the old reload to the combined.  */
1625         for (j = 0; j < n_replacements; j++)
1626           if (replacements[j].what == output_reload)
1627             replacements[j].what = i;
1628
1629         return;
1630       }
1631
1632   /* If this insn has only one operand that is modified or written (assumed
1633      to be the first),  it must be the one corresponding to this reload.  It
1634      is safe to use anything that dies in this insn for that output provided
1635      that it does not occur in the output (we already know it isn't an
1636      earlyclobber.  If this is an asm insn, give up.  */
1637
1638   if (INSN_CODE (this_insn) == -1)
1639     return;
1640
1641   for (i = 1; i < insn_n_operands[INSN_CODE (this_insn)]; i++)
1642     if (insn_operand_constraint[INSN_CODE (this_insn)][i][0] == '='
1643         || insn_operand_constraint[INSN_CODE (this_insn)][i][0] == '+')
1644       return;
1645
1646   /* See if some hard register that dies in this insn and is not used in
1647      the output is the right class.  Only works if the register we pick
1648      up can fully hold our output reload.  */
1649   for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1650     if (REG_NOTE_KIND (note) == REG_DEAD
1651         && GET_CODE (XEXP (note, 0)) == REG
1652         && ! reg_overlap_mentioned_for_reload_p (XEXP (note, 0),
1653                                                  reload_out[output_reload])
1654         && REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1655         && HARD_REGNO_MODE_OK (REGNO (XEXP (note, 0)), reload_outmode[output_reload])
1656         && TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[output_reload]],
1657                               REGNO (XEXP (note, 0)))
1658         && (HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), reload_outmode[output_reload])
1659             <= HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), GET_MODE (XEXP (note, 0))))
1660         /* Ensure that a secondary or tertiary reload for this output
1661            won't want this register.  */
1662         && ((secondary_out = reload_secondary_out_reload[output_reload]) == -1
1663             || (! (TEST_HARD_REG_BIT
1664                     (reg_class_contents[(int) reload_reg_class[secondary_out]],
1665                      REGNO (XEXP (note, 0))))
1666                 && ((secondary_out = reload_secondary_out_reload[secondary_out]) == -1
1667                     ||  ! (TEST_HARD_REG_BIT
1668                            (reg_class_contents[(int) reload_reg_class[secondary_out]],
1669                             REGNO (XEXP (note, 0)))))))
1670         && ! fixed_regs[REGNO (XEXP (note, 0))])
1671       {
1672         reload_reg_rtx[output_reload] = gen_rtx (REG,
1673                                                  reload_outmode[output_reload],
1674                                                  REGNO (XEXP (note, 0)));
1675         return;
1676       }
1677 }
1678 \f
1679 /* Try to find a reload register for an in-out reload (expressions IN and OUT).
1680    See if one of IN and OUT is a register that may be used;
1681    this is desirable since a spill-register won't be needed.
1682    If so, return the register rtx that proves acceptable.
1683
1684    INLOC and OUTLOC are locations where IN and OUT appear in the insn.
1685    CLASS is the register class required for the reload.
1686
1687    If FOR_REAL is >= 0, it is the number of the reload,
1688    and in some cases when it can be discovered that OUT doesn't need
1689    to be computed, clear out reload_out[FOR_REAL].
1690
1691    If FOR_REAL is -1, this should not be done, because this call
1692    is just to see if a register can be found, not to find and install it.  */
1693
1694 static rtx
1695 find_dummy_reload (real_in, real_out, inloc, outloc,
1696                    inmode, outmode, class, for_real)
1697      rtx real_in, real_out;
1698      rtx *inloc, *outloc;
1699      enum machine_mode inmode, outmode;
1700      enum reg_class class;
1701      int for_real;
1702 {
1703   rtx in = real_in;
1704   rtx out = real_out;
1705   int in_offset = 0;
1706   int out_offset = 0;
1707   rtx value = 0;
1708
1709   /* If operands exceed a word, we can't use either of them
1710      unless they have the same size.  */
1711   if (GET_MODE_SIZE (outmode) != GET_MODE_SIZE (inmode)
1712       && (GET_MODE_SIZE (outmode) > UNITS_PER_WORD
1713           || GET_MODE_SIZE (inmode) > UNITS_PER_WORD))
1714     return 0;
1715
1716   /* Find the inside of any subregs.  */
1717   while (GET_CODE (out) == SUBREG)
1718     {
1719       out_offset = SUBREG_WORD (out);
1720       out = SUBREG_REG (out);
1721     }
1722   while (GET_CODE (in) == SUBREG)
1723     {
1724       in_offset = SUBREG_WORD (in);
1725       in = SUBREG_REG (in);
1726     }
1727
1728   /* Narrow down the reg class, the same way push_reload will;
1729      otherwise we might find a dummy now, but push_reload won't.  */
1730   class = PREFERRED_RELOAD_CLASS (in, class);
1731
1732   /* See if OUT will do.  */
1733   if (GET_CODE (out) == REG
1734       && REGNO (out) < FIRST_PSEUDO_REGISTER)
1735     {
1736       register int regno = REGNO (out) + out_offset;
1737       int nwords = HARD_REGNO_NREGS (regno, outmode);
1738       rtx saved_rtx;
1739
1740       /* When we consider whether the insn uses OUT,
1741          ignore references within IN.  They don't prevent us
1742          from copying IN into OUT, because those refs would
1743          move into the insn that reloads IN.
1744
1745          However, we only ignore IN in its role as this reload.
1746          If the insn uses IN elsewhere and it contains OUT,
1747          that counts.  We can't be sure it's the "same" operand
1748          so it might not go through this reload.  */
1749       saved_rtx = *inloc;
1750       *inloc = const0_rtx;
1751
1752       if (regno < FIRST_PSEUDO_REGISTER
1753           /* A fixed reg that can overlap other regs better not be used
1754              for reloading in any way.  */
1755 #ifdef OVERLAPPING_REGNO_P
1756           && ! (fixed_regs[regno] && OVERLAPPING_REGNO_P (regno))
1757 #endif
1758           && ! refers_to_regno_for_reload_p (regno, regno + nwords,
1759                                              PATTERN (this_insn), outloc))
1760         {
1761           int i;
1762           for (i = 0; i < nwords; i++)
1763             if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1764                                      regno + i))
1765               break;
1766
1767           if (i == nwords)
1768             {
1769               if (GET_CODE (real_out) == REG)
1770                 value = real_out;
1771               else
1772                 value = gen_rtx (REG, outmode, regno);
1773             }
1774         }
1775
1776       *inloc = saved_rtx;
1777     }
1778
1779   /* Consider using IN if OUT was not acceptable
1780      or if OUT dies in this insn (like the quotient in a divmod insn).
1781      We can't use IN unless it is dies in this insn,
1782      which means we must know accurately which hard regs are live.
1783      Also, the result can't go in IN if IN is used within OUT.  */
1784   if (hard_regs_live_known
1785       && GET_CODE (in) == REG
1786       && REGNO (in) < FIRST_PSEUDO_REGISTER
1787       && (value == 0
1788           || find_reg_note (this_insn, REG_UNUSED, real_out))
1789       && find_reg_note (this_insn, REG_DEAD, real_in)
1790       && !fixed_regs[REGNO (in)]
1791       && HARD_REGNO_MODE_OK (REGNO (in),
1792                              /* The only case where out and real_out might
1793                                 have different modes is where real_out
1794                                 is a subreg, and in that case, out
1795                                 has a real mode.  */
1796                              (GET_MODE (out) != VOIDmode
1797                               ? GET_MODE (out) : outmode)))
1798     {
1799       register int regno = REGNO (in) + in_offset;
1800       int nwords = HARD_REGNO_NREGS (regno, inmode);
1801
1802       if (! refers_to_regno_for_reload_p (regno, regno + nwords, out, NULL_PTR)
1803           && ! hard_reg_set_here_p (regno, regno + nwords,
1804                                     PATTERN (this_insn)))
1805         {
1806           int i;
1807           for (i = 0; i < nwords; i++)
1808             if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1809                                      regno + i))
1810               break;
1811
1812           if (i == nwords)
1813             {
1814               /* If we were going to use OUT as the reload reg
1815                  and changed our mind, it means OUT is a dummy that
1816                  dies here.  So don't bother copying value to it.  */
1817               if (for_real >= 0 && value == real_out)
1818                 reload_out[for_real] = 0;
1819               if (GET_CODE (real_in) == REG)
1820                 value = real_in;
1821               else
1822                 value = gen_rtx (REG, inmode, regno);
1823             }
1824         }
1825     }
1826
1827   return value;
1828 }
1829 \f
1830 /* This page contains subroutines used mainly for determining
1831    whether the IN or an OUT of a reload can serve as the
1832    reload register.  */
1833
1834 /* Return 1 if X is an operand of an insn that is being earlyclobbered.  */
1835
1836 static int
1837 earlyclobber_operand_p (x)
1838      rtx x;
1839 {
1840   int i;
1841
1842   for (i = 0; i < n_earlyclobbers; i++)
1843     if (reload_earlyclobbers[i] == x)
1844       return 1;
1845
1846   return 0;
1847 }
1848
1849 /* Return 1 if expression X alters a hard reg in the range
1850    from BEG_REGNO (inclusive) to END_REGNO (exclusive),
1851    either explicitly or in the guise of a pseudo-reg allocated to REGNO.
1852    X should be the body of an instruction.  */
1853
1854 static int
1855 hard_reg_set_here_p (beg_regno, end_regno, x)
1856      register int beg_regno, end_regno;
1857      rtx x;
1858 {
1859   if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
1860     {
1861       register rtx op0 = SET_DEST (x);
1862       while (GET_CODE (op0) == SUBREG)
1863         op0 = SUBREG_REG (op0);
1864       if (GET_CODE (op0) == REG)
1865         {
1866           register int r = REGNO (op0);
1867           /* See if this reg overlaps range under consideration.  */
1868           if (r < end_regno
1869               && r + HARD_REGNO_NREGS (r, GET_MODE (op0)) > beg_regno)
1870             return 1;
1871         }
1872     }
1873   else if (GET_CODE (x) == PARALLEL)
1874     {
1875       register int i = XVECLEN (x, 0) - 1;
1876       for (; i >= 0; i--)
1877         if (hard_reg_set_here_p (beg_regno, end_regno, XVECEXP (x, 0, i)))
1878           return 1;
1879     }
1880
1881   return 0;
1882 }
1883
1884 /* Return 1 if ADDR is a valid memory address for mode MODE,
1885    and check that each pseudo reg has the proper kind of
1886    hard reg.  */
1887
1888 int
1889 strict_memory_address_p (mode, addr)
1890      enum machine_mode mode;
1891      register rtx addr;
1892 {
1893   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1894   return 0;
1895
1896  win:
1897   return 1;
1898 }
1899 \f
1900 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
1901    if they are the same hard reg, and has special hacks for
1902    autoincrement and autodecrement.
1903    This is specifically intended for find_reloads to use
1904    in determining whether two operands match.
1905    X is the operand whose number is the lower of the two.
1906
1907    The value is 2 if Y contains a pre-increment that matches
1908    a non-incrementing address in X.  */
1909
1910 /* ??? To be completely correct, we should arrange to pass
1911    for X the output operand and for Y the input operand.
1912    For now, we assume that the output operand has the lower number
1913    because that is natural in (SET output (... input ...)).  */
1914
1915 int
1916 operands_match_p (x, y)
1917      register rtx x, y;
1918 {
1919   register int i;
1920   register RTX_CODE code = GET_CODE (x);
1921   register char *fmt;
1922   int success_2;
1923       
1924   if (x == y)
1925     return 1;
1926   if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
1927       && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
1928                                   && GET_CODE (SUBREG_REG (y)) == REG)))
1929     {
1930       register int j;
1931
1932       if (code == SUBREG)
1933         {
1934           i = REGNO (SUBREG_REG (x));
1935           if (i >= FIRST_PSEUDO_REGISTER)
1936             goto slow;
1937           i += SUBREG_WORD (x);
1938         }
1939       else
1940         i = REGNO (x);
1941
1942       if (GET_CODE (y) == SUBREG)
1943         {
1944           j = REGNO (SUBREG_REG (y));
1945           if (j >= FIRST_PSEUDO_REGISTER)
1946             goto slow;
1947           j += SUBREG_WORD (y);
1948         }
1949       else
1950         j = REGNO (y);
1951
1952       /* On a WORDS_BIG_ENDIAN machine, point to the last register of a
1953          multiple hard register group, so that for example (reg:DI 0) and
1954          (reg:SI 1) will be considered the same register.  */
1955       if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
1956           && i < FIRST_PSEUDO_REGISTER)
1957         i += (GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD) - 1;
1958       if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (y)) > UNITS_PER_WORD
1959           && j < FIRST_PSEUDO_REGISTER)
1960         j += (GET_MODE_SIZE (GET_MODE (y)) / UNITS_PER_WORD) - 1;
1961
1962       return i == j;
1963     }
1964   /* If two operands must match, because they are really a single
1965      operand of an assembler insn, then two postincrements are invalid
1966      because the assembler insn would increment only once.
1967      On the other hand, an postincrement matches ordinary indexing
1968      if the postincrement is the output operand.  */
1969   if (code == POST_DEC || code == POST_INC)
1970     return operands_match_p (XEXP (x, 0), y);
1971   /* Two preincrements are invalid
1972      because the assembler insn would increment only once.
1973      On the other hand, an preincrement matches ordinary indexing
1974      if the preincrement is the input operand.
1975      In this case, return 2, since some callers need to do special
1976      things when this happens.  */
1977   if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC)
1978     return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
1979
1980  slow:
1981
1982   /* Now we have disposed of all the cases 
1983      in which different rtx codes can match.  */
1984   if (code != GET_CODE (y))
1985     return 0;
1986   if (code == LABEL_REF)
1987     return XEXP (x, 0) == XEXP (y, 0);
1988   if (code == SYMBOL_REF)
1989     return XSTR (x, 0) == XSTR (y, 0);
1990
1991   /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.  */
1992
1993   if (GET_MODE (x) != GET_MODE (y))
1994     return 0;
1995
1996   /* Compare the elements.  If any pair of corresponding elements
1997      fail to match, return 0 for the whole things.  */
1998
1999   success_2 = 0;
2000   fmt = GET_RTX_FORMAT (code);
2001   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2002     {
2003       int val;
2004       switch (fmt[i])
2005         {
2006         case 'w':
2007           if (XWINT (x, i) != XWINT (y, i))
2008             return 0;
2009           break;
2010
2011         case 'i':
2012           if (XINT (x, i) != XINT (y, i))
2013             return 0;
2014           break;
2015
2016         case 'e':
2017           val = operands_match_p (XEXP (x, i), XEXP (y, i));
2018           if (val == 0)
2019             return 0;
2020           /* If any subexpression returns 2,
2021              we should return 2 if we are successful.  */
2022           if (val == 2)
2023             success_2 = 1;
2024           break;
2025
2026         case '0':
2027           break;
2028
2029           /* It is believed that rtx's at this level will never
2030              contain anything but integers and other rtx's,
2031              except for within LABEL_REFs and SYMBOL_REFs.  */
2032         default:
2033           abort ();
2034         }
2035     }
2036   return 1 + success_2;
2037 }
2038 \f
2039 /* Return the number of times character C occurs in string S.  */
2040
2041 int
2042 n_occurrences (c, s)
2043      int c;
2044      char *s;
2045 {
2046   int n = 0;
2047   while (*s)
2048     n += (*s++ == c);
2049   return n;
2050 }
2051 \f
2052 /* Describe the range of registers or memory referenced by X.
2053    If X is a register, set REG_FLAG and put the first register 
2054    number into START and the last plus one into END.
2055    If X is a memory reference, put a base address into BASE 
2056    and a range of integer offsets into START and END.
2057    If X is pushing on the stack, we can assume it causes no trouble, 
2058    so we set the SAFE field.  */
2059
2060 static struct decomposition
2061 decompose (x)
2062      rtx x;
2063 {
2064   struct decomposition val;
2065   int all_const = 0;
2066
2067   val.reg_flag = 0;
2068   val.safe = 0;
2069   if (GET_CODE (x) == MEM)
2070     {
2071       rtx base, offset = 0;
2072       rtx addr = XEXP (x, 0);
2073
2074       if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
2075           || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
2076         {
2077           val.base = XEXP (addr, 0);
2078           val.start = - GET_MODE_SIZE (GET_MODE (x));
2079           val.end = GET_MODE_SIZE (GET_MODE (x));
2080           val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2081           return val;
2082         }
2083
2084       if (GET_CODE (addr) == CONST)
2085         {
2086           addr = XEXP (addr, 0);
2087           all_const = 1;
2088         }
2089       if (GET_CODE (addr) == PLUS)
2090         {
2091           if (CONSTANT_P (XEXP (addr, 0)))
2092             {
2093               base = XEXP (addr, 1);
2094               offset = XEXP (addr, 0);
2095             }
2096           else if (CONSTANT_P (XEXP (addr, 1)))
2097             {
2098               base = XEXP (addr, 0);
2099               offset = XEXP (addr, 1);
2100             }
2101         }
2102
2103       if (offset == 0)
2104         {
2105           base = addr;
2106           offset = const0_rtx;
2107         } 
2108       if (GET_CODE (offset) == CONST)
2109         offset = XEXP (offset, 0);
2110       if (GET_CODE (offset) == PLUS)
2111         {
2112           if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
2113             {
2114               base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 1));
2115               offset = XEXP (offset, 0);
2116             }
2117           else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
2118             {
2119               base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 0));
2120               offset = XEXP (offset, 1);
2121             }
2122           else
2123             {
2124               base = gen_rtx (PLUS, GET_MODE (base), base, offset);
2125               offset = const0_rtx;
2126             }
2127         }
2128       else if (GET_CODE (offset) != CONST_INT)
2129         {
2130           base = gen_rtx (PLUS, GET_MODE (base), base, offset);
2131           offset = const0_rtx;
2132         }
2133
2134       if (all_const && GET_CODE (base) == PLUS)
2135         base = gen_rtx (CONST, GET_MODE (base), base);
2136
2137       if (GET_CODE (offset) != CONST_INT)
2138         abort ();
2139
2140       val.start = INTVAL (offset);
2141       val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
2142       val.base = base;
2143       return val;
2144     }
2145   else if (GET_CODE (x) == REG)
2146     {
2147       val.reg_flag = 1;
2148       val.start = true_regnum (x); 
2149       if (val.start < 0)
2150         {
2151           /* A pseudo with no hard reg.  */
2152           val.start = REGNO (x);
2153           val.end = val.start + 1;
2154         }
2155       else
2156         /* A hard reg.  */
2157         val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2158     }
2159   else if (GET_CODE (x) == SUBREG)
2160     {
2161       if (GET_CODE (SUBREG_REG (x)) != REG)
2162         /* This could be more precise, but it's good enough.  */
2163         return decompose (SUBREG_REG (x));
2164       val.reg_flag = 1;
2165       val.start = true_regnum (x); 
2166       if (val.start < 0)
2167         return decompose (SUBREG_REG (x));
2168       else
2169         /* A hard reg.  */
2170         val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2171     }
2172   else if (CONSTANT_P (x)
2173            /* This hasn't been assigned yet, so it can't conflict yet.  */
2174            || GET_CODE (x) == SCRATCH)
2175     val.safe = 1;
2176   else
2177     abort ();
2178   return val;
2179 }
2180
2181 /* Return 1 if altering Y will not modify the value of X.
2182    Y is also described by YDATA, which should be decompose (Y).  */
2183
2184 static int
2185 immune_p (x, y, ydata)
2186      rtx x, y;
2187      struct decomposition ydata;
2188 {
2189   struct decomposition xdata;
2190
2191   if (ydata.reg_flag)
2192     return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, NULL_PTR);
2193   if (ydata.safe)
2194     return 1;
2195
2196   if (GET_CODE (y) != MEM)
2197     abort ();
2198   /* If Y is memory and X is not, Y can't affect X.  */
2199   if (GET_CODE (x) != MEM)
2200     return 1;
2201
2202   xdata =  decompose (x);
2203
2204   if (! rtx_equal_p (xdata.base, ydata.base))
2205     {
2206       /* If bases are distinct symbolic constants, there is no overlap.  */
2207       if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
2208         return 1;
2209       /* Constants and stack slots never overlap.  */
2210       if (CONSTANT_P (xdata.base)
2211           && (ydata.base == frame_pointer_rtx
2212               || ydata.base == hard_frame_pointer_rtx
2213               || ydata.base == stack_pointer_rtx))
2214         return 1;
2215       if (CONSTANT_P (ydata.base)
2216           && (xdata.base == frame_pointer_rtx
2217               || xdata.base == hard_frame_pointer_rtx
2218               || xdata.base == stack_pointer_rtx))
2219         return 1;
2220       /* If either base is variable, we don't know anything.  */
2221       return 0;
2222     }
2223
2224
2225   return (xdata.start >= ydata.end || ydata.start >= xdata.end);
2226 }
2227
2228 /* Similar, but calls decompose.  */
2229
2230 int
2231 safe_from_earlyclobber (op, clobber)
2232      rtx op, clobber;
2233 {
2234   struct decomposition early_data;
2235
2236   early_data = decompose (clobber);
2237   return immune_p (op, clobber, early_data);
2238 }
2239 \f
2240 /* Main entry point of this file: search the body of INSN
2241    for values that need reloading and record them with push_reload.
2242    REPLACE nonzero means record also where the values occur
2243    so that subst_reloads can be used.
2244
2245    IND_LEVELS says how many levels of indirection are supported by this
2246    machine; a value of zero means that a memory reference is not a valid
2247    memory address.
2248
2249    LIVE_KNOWN says we have valid information about which hard
2250    regs are live at each point in the program; this is true when
2251    we are called from global_alloc but false when stupid register
2252    allocation has been done.
2253
2254    RELOAD_REG_P if nonzero is a vector indexed by hard reg number
2255    which is nonnegative if the reg has been commandeered for reloading into.
2256    It is copied into STATIC_RELOAD_REG_P and referenced from there
2257    by various subroutines.  */
2258
2259 void
2260 find_reloads (insn, replace, ind_levels, live_known, reload_reg_p)
2261      rtx insn;
2262      int replace, ind_levels;
2263      int live_known;
2264      short *reload_reg_p;
2265 {
2266 #ifdef REGISTER_CONSTRAINTS
2267
2268   register int insn_code_number;
2269   register int i, j;
2270   int noperands;
2271   /* These are the constraints for the insn.  We don't change them.  */
2272   char *constraints1[MAX_RECOG_OPERANDS];
2273   /* These start out as the constraints for the insn
2274      and they are chewed up as we consider alternatives.  */
2275   char *constraints[MAX_RECOG_OPERANDS];
2276   /* These are the preferred classes for an operand, or NO_REGS if it isn't
2277      a register.  */
2278   enum reg_class preferred_class[MAX_RECOG_OPERANDS];
2279   char pref_or_nothing[MAX_RECOG_OPERANDS];
2280   /* Nonzero for a MEM operand whose entire address needs a reload.  */
2281   int address_reloaded[MAX_RECOG_OPERANDS];
2282   /* Value of enum reload_type to use for operand.  */
2283   enum reload_type operand_type[MAX_RECOG_OPERANDS];
2284   /* Value of enum reload_type to use within address of operand.  */
2285   enum reload_type address_type[MAX_RECOG_OPERANDS];
2286   /* Save the usage of each operand.  */
2287   enum reload_usage { RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE } modified[MAX_RECOG_OPERANDS];
2288   int no_input_reloads = 0, no_output_reloads = 0;
2289   int n_alternatives;
2290   int this_alternative[MAX_RECOG_OPERANDS];
2291   char this_alternative_win[MAX_RECOG_OPERANDS];
2292   char this_alternative_offmemok[MAX_RECOG_OPERANDS];
2293   char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2294   int this_alternative_matches[MAX_RECOG_OPERANDS];
2295   int swapped;
2296   int goal_alternative[MAX_RECOG_OPERANDS];
2297   int this_alternative_number;
2298   int goal_alternative_number;
2299   int operand_reloadnum[MAX_RECOG_OPERANDS];
2300   int goal_alternative_matches[MAX_RECOG_OPERANDS];
2301   int goal_alternative_matched[MAX_RECOG_OPERANDS];
2302   char goal_alternative_win[MAX_RECOG_OPERANDS];
2303   char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
2304   char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2305   int goal_alternative_swapped;
2306   int best;
2307   int commutative;
2308   char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
2309   rtx substed_operand[MAX_RECOG_OPERANDS];
2310   rtx body = PATTERN (insn);
2311   rtx set = single_set (insn);
2312   int goal_earlyclobber, this_earlyclobber;
2313   enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
2314
2315   this_insn = insn;
2316   this_insn_is_asm = 0;         /* Tentative.  */
2317   n_reloads = 0;
2318   n_replacements = 0;
2319   n_memlocs = 0;
2320   n_earlyclobbers = 0;
2321   replace_reloads = replace;
2322   hard_regs_live_known = live_known;
2323   static_reload_reg_p = reload_reg_p;
2324
2325   /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads;
2326      neither are insns that SET cc0.  Insns that use CC0 are not allowed
2327      to have any input reloads.  */
2328   if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == CALL_INSN)
2329     no_output_reloads = 1;
2330
2331 #ifdef HAVE_cc0
2332   if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
2333     no_input_reloads = 1;
2334   if (reg_set_p (cc0_rtx, PATTERN (insn)))
2335     no_output_reloads = 1;
2336 #endif
2337      
2338 #ifdef SECONDARY_MEMORY_NEEDED
2339   /* The eliminated forms of any secondary memory locations are per-insn, so
2340      clear them out here.  */
2341
2342   bzero ((char *) secondary_memlocs_elim, sizeof secondary_memlocs_elim);
2343 #endif
2344
2345   /* Find what kind of insn this is.  NOPERANDS gets number of operands.
2346      Make OPERANDS point to a vector of operand values.
2347      Make OPERAND_LOCS point to a vector of pointers to
2348      where the operands were found.
2349      Fill CONSTRAINTS and CONSTRAINTS1 with pointers to the
2350      constraint-strings for this insn.
2351      Return if the insn needs no reload processing.  */
2352
2353   switch (GET_CODE (body))
2354     {
2355     case USE:
2356     case CLOBBER:
2357     case ASM_INPUT:
2358     case ADDR_VEC:
2359     case ADDR_DIFF_VEC:
2360       return;
2361
2362     case SET:
2363       /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it
2364          is cheap to move between them.  If it is not, there may not be an insn
2365          to do the copy, so we may need a reload.  */
2366       if (GET_CODE (SET_DEST (body)) == REG
2367           && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
2368           && GET_CODE (SET_SRC (body)) == REG
2369           && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER
2370           && REGISTER_MOVE_COST (REGNO_REG_CLASS (REGNO (SET_SRC (body))),
2371                                  REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2)
2372         return;
2373     case PARALLEL:
2374     case ASM_OPERANDS:
2375       reload_n_operands = noperands = asm_noperands (body);
2376       if (noperands >= 0)
2377         {
2378           /* This insn is an `asm' with operands.  */
2379
2380           insn_code_number = -1;
2381           this_insn_is_asm = 1;
2382
2383           /* expand_asm_operands makes sure there aren't too many operands.  */
2384           if (noperands > MAX_RECOG_OPERANDS)
2385             abort ();
2386
2387           /* Now get the operand values and constraints out of the insn.  */
2388
2389           decode_asm_operands (body, recog_operand, recog_operand_loc,
2390                                constraints, operand_mode);
2391           if (noperands > 0)
2392             {
2393               bcopy ((char *) constraints, (char *) constraints1,
2394                      noperands * sizeof (char *));
2395               n_alternatives = n_occurrences (',', constraints[0]) + 1;
2396               for (i = 1; i < noperands; i++)
2397                 if (n_alternatives != n_occurrences (',', constraints[i]) + 1)
2398                   {
2399                     error_for_asm (insn, "operand constraints differ in number of alternatives");
2400                     /* Avoid further trouble with this insn.  */
2401                     PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
2402                     n_reloads = 0;
2403                     return;
2404                   }
2405             }
2406           break;
2407         }
2408
2409     default:
2410       /* Ordinary insn: recognize it, get the operands via insn_extract
2411          and get the constraints.  */
2412
2413       insn_code_number = recog_memoized (insn);
2414       if (insn_code_number < 0)
2415         fatal_insn_not_found (insn);
2416
2417       reload_n_operands = noperands = insn_n_operands[insn_code_number];
2418       n_alternatives = insn_n_alternatives[insn_code_number];
2419       /* Just return "no reloads" if insn has no operands with constraints.  */
2420       if (n_alternatives == 0)
2421         return;
2422       insn_extract (insn);
2423       for (i = 0; i < noperands; i++)
2424         {
2425           constraints[i] = constraints1[i]
2426             = insn_operand_constraint[insn_code_number][i];
2427           operand_mode[i] = insn_operand_mode[insn_code_number][i];
2428         }
2429     }
2430
2431   if (noperands == 0)
2432     return;
2433
2434   commutative = -1;
2435
2436   /* If we will need to know, later, whether some pair of operands
2437      are the same, we must compare them now and save the result.
2438      Reloading the base and index registers will clobber them
2439      and afterward they will fail to match.  */
2440
2441   for (i = 0; i < noperands; i++)
2442     {
2443       register char *p;
2444       register int c;
2445
2446       substed_operand[i] = recog_operand[i];
2447       p = constraints[i];
2448
2449       modified[i] = RELOAD_READ;
2450
2451       /* Scan this operand's constraint to see if it is an output operand, 
2452          an in-out operand, is commutative, or should match another.  */
2453
2454       while (c = *p++)
2455         {
2456           if (c == '=')
2457             modified[i] = RELOAD_WRITE;
2458           else if (c == '+')
2459             modified[i] = RELOAD_READ_WRITE;
2460           else if (c == '%')
2461             {
2462               /* The last operand should not be marked commutative.  */
2463               if (i == noperands - 1)
2464                 {
2465                   if (this_insn_is_asm)
2466                     warning_for_asm (this_insn,
2467                                      "`%%' constraint used with last operand");
2468                   else
2469                     abort ();
2470                 }
2471               else
2472                 commutative = i;
2473             }
2474           else if (c >= '0' && c <= '9')
2475             {
2476               c -= '0';
2477               operands_match[c][i]
2478                 = operands_match_p (recog_operand[c], recog_operand[i]);
2479
2480               /* An operand may not match itself.  */
2481               if (c == i)
2482                 {
2483                   if (this_insn_is_asm)
2484                     warning_for_asm (this_insn,
2485                                      "operand %d has constraint %d", i, c);
2486                   else
2487                     abort ();
2488                 }
2489
2490               /* If C can be commuted with C+1, and C might need to match I,
2491                  then C+1 might also need to match I.  */
2492               if (commutative >= 0)
2493                 {
2494                   if (c == commutative || c == commutative + 1)
2495                     {
2496                       int other = c + (c == commutative ? 1 : -1);
2497                       operands_match[other][i]
2498                         = operands_match_p (recog_operand[other], recog_operand[i]);
2499                     }
2500                   if (i == commutative || i == commutative + 1)
2501                     {
2502                       int other = i + (i == commutative ? 1 : -1);
2503                       operands_match[c][other]
2504                         = operands_match_p (recog_operand[c], recog_operand[other]);
2505                     }
2506                   /* Note that C is supposed to be less than I.
2507                      No need to consider altering both C and I because in
2508                      that case we would alter one into the other.  */
2509                 }
2510             }
2511         }
2512     }
2513
2514   /* Examine each operand that is a memory reference or memory address
2515      and reload parts of the addresses into index registers.
2516      Also here any references to pseudo regs that didn't get hard regs
2517      but are equivalent to constants get replaced in the insn itself
2518      with those constants.  Nobody will ever see them again. 
2519
2520      Finally, set up the preferred classes of each operand.  */
2521
2522   for (i = 0; i < noperands; i++)
2523     {
2524       register RTX_CODE code = GET_CODE (recog_operand[i]);
2525
2526       address_reloaded[i] = 0;
2527       operand_type[i] = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT
2528                          : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT
2529                          : RELOAD_OTHER);
2530       address_type[i]
2531         = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT_ADDRESS
2532            : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT_ADDRESS
2533            : RELOAD_OTHER);
2534
2535       if (*constraints[i] == 0)
2536         /* Ignore things like match_operator operands.  */
2537         ;
2538       else if (constraints[i][0] == 'p')
2539         {
2540           find_reloads_address (VOIDmode, NULL_PTR,
2541                                 recog_operand[i], recog_operand_loc[i],
2542                                 i, operand_type[i], ind_levels, insn);
2543
2544           /* If we now have a simple operand where we used to have a 
2545              PLUS or MULT, re-recognize and try again.  */
2546           if ((GET_RTX_CLASS (GET_CODE (*recog_operand_loc[i])) == 'o'
2547                || GET_CODE (*recog_operand_loc[i]) == SUBREG)
2548               && (GET_CODE (recog_operand[i]) == MULT
2549                   || GET_CODE (recog_operand[i]) == PLUS))
2550             {
2551               INSN_CODE (insn) = -1;
2552               find_reloads (insn, replace, ind_levels, live_known,
2553                             reload_reg_p);
2554               return;
2555             }
2556
2557           substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2558         }
2559       else if (code == MEM)
2560         {
2561           if (find_reloads_address (GET_MODE (recog_operand[i]),
2562                                     recog_operand_loc[i],
2563                                     XEXP (recog_operand[i], 0),
2564                                     &XEXP (recog_operand[i], 0),
2565                                     i, address_type[i], ind_levels, insn))
2566             address_reloaded[i] = 1;
2567           substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2568         }
2569       else if (code == SUBREG)
2570         substed_operand[i] = recog_operand[i] = *recog_operand_loc[i]
2571           = find_reloads_toplev (recog_operand[i], i, address_type[i],
2572                                  ind_levels,
2573                                  set != 0
2574                                  && &SET_DEST (set) == recog_operand_loc[i]);
2575       else if (code == PLUS || GET_RTX_CLASS (code) == '1')
2576         /* We can get a PLUS as an "operand" as a result of register
2577            elimination.  See eliminate_regs and gen_reload.  We handle
2578            a unary operator by reloading the operand.  */
2579         substed_operand[i] = recog_operand[i] = *recog_operand_loc[i]
2580           = find_reloads_toplev (recog_operand[i], i, address_type[i],
2581                                  ind_levels, 0);
2582       else if (code == REG)
2583         {
2584           /* This is equivalent to calling find_reloads_toplev.
2585              The code is duplicated for speed.
2586              When we find a pseudo always equivalent to a constant,
2587              we replace it by the constant.  We must be sure, however,
2588              that we don't try to replace it in the insn in which it
2589              is being set.   */
2590           register int regno = REGNO (recog_operand[i]);
2591           if (reg_equiv_constant[regno] != 0
2592               && (set == 0 || &SET_DEST (set) != recog_operand_loc[i]))
2593             substed_operand[i] = recog_operand[i]
2594               = reg_equiv_constant[regno];
2595 #if 0 /* This might screw code in reload1.c to delete prior output-reload
2596          that feeds this insn.  */
2597           if (reg_equiv_mem[regno] != 0)
2598             substed_operand[i] = recog_operand[i]
2599               = reg_equiv_mem[regno];
2600 #endif
2601           if (reg_equiv_address[regno] != 0)
2602             {
2603               /* If reg_equiv_address is not a constant address, copy it,
2604                  since it may be shared.  */
2605               /* We must rerun eliminate_regs, in case the elimination
2606                  offsets have changed.  */
2607               rtx address = XEXP (eliminate_regs (reg_equiv_memory_loc[regno],
2608                                                   0, NULL_RTX, 0),
2609                                   0);
2610
2611               if (rtx_varies_p (address))
2612                 address = copy_rtx (address);
2613
2614               /* If this is an output operand, we must output a CLOBBER
2615                  after INSN so find_equiv_reg knows REGNO is being written. 
2616                  Mark this insn specially, do we can put our output reloads
2617                  after it.  */
2618
2619               if (modified[i] != RELOAD_READ)
2620                 PUT_MODE (emit_insn_after (gen_rtx (CLOBBER, VOIDmode,
2621                                                     recog_operand[i]),
2622                                            insn),
2623                           DImode);
2624
2625               *recog_operand_loc[i] = recog_operand[i]
2626                 = gen_rtx (MEM, GET_MODE (recog_operand[i]), address);
2627               RTX_UNCHANGING_P (recog_operand[i])
2628                 = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
2629               find_reloads_address (GET_MODE (recog_operand[i]),
2630                                     recog_operand_loc[i],
2631                                     XEXP (recog_operand[i], 0),
2632                                     &XEXP (recog_operand[i], 0),
2633                                     i, address_type[i], ind_levels, insn);
2634               substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2635             }
2636         }
2637       /* If the operand is still a register (we didn't replace it with an
2638          equivalent), get the preferred class to reload it into.  */
2639       code = GET_CODE (recog_operand[i]);
2640       preferred_class[i]
2641         = ((code == REG && REGNO (recog_operand[i]) >= FIRST_PSEUDO_REGISTER)
2642            ? reg_preferred_class (REGNO (recog_operand[i])) : NO_REGS);
2643       pref_or_nothing[i]
2644         = (code == REG && REGNO (recog_operand[i]) >= FIRST_PSEUDO_REGISTER
2645            && reg_alternate_class (REGNO (recog_operand[i])) == NO_REGS);
2646     }
2647
2648   /* If this is simply a copy from operand 1 to operand 0, merge the
2649      preferred classes for the operands.  */
2650   if (set != 0 && noperands >= 2 && recog_operand[0] == SET_DEST (set)
2651       && recog_operand[1] == SET_SRC (set))
2652     {
2653       preferred_class[0] = preferred_class[1]
2654         = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]];
2655       pref_or_nothing[0] |= pref_or_nothing[1];
2656       pref_or_nothing[1] |= pref_or_nothing[0];
2657     }
2658
2659   /* Now see what we need for pseudo-regs that didn't get hard regs
2660      or got the wrong kind of hard reg.  For this, we must consider
2661      all the operands together against the register constraints.  */
2662
2663   best = MAX_RECOG_OPERANDS + 300;
2664
2665   swapped = 0;
2666   goal_alternative_swapped = 0;
2667  try_swapped:
2668
2669   /* The constraints are made of several alternatives.
2670      Each operand's constraint looks like foo,bar,... with commas
2671      separating the alternatives.  The first alternatives for all
2672      operands go together, the second alternatives go together, etc.
2673
2674      First loop over alternatives.  */
2675
2676   for (this_alternative_number = 0;
2677        this_alternative_number < n_alternatives;
2678        this_alternative_number++)
2679     {
2680       /* Loop over operands for one constraint alternative.  */
2681       /* LOSERS counts those that don't fit this alternative
2682          and would require loading.  */
2683       int losers = 0;
2684       /* BAD is set to 1 if it some operand can't fit this alternative
2685          even after reloading.  */
2686       int bad = 0;
2687       /* REJECT is a count of how undesirable this alternative says it is
2688          if any reloading is required.  If the alternative matches exactly
2689          then REJECT is ignored, but otherwise it gets this much
2690          counted against it in addition to the reloading needed.  Each 
2691          ? counts three times here since we want the disparaging caused by
2692          a bad register class to only count 1/3 as much.  */
2693       int reject = 0;
2694
2695       this_earlyclobber = 0;
2696
2697       for (i = 0; i < noperands; i++)
2698         {
2699           register char *p = constraints[i];
2700           register int win = 0;
2701           /* 0 => this operand can be reloaded somehow for this alternative */
2702           int badop = 1;
2703           /* 0 => this operand can be reloaded if the alternative allows regs.  */
2704           int winreg = 0;
2705           int c;
2706           register rtx operand = recog_operand[i];
2707           int offset = 0;
2708           /* Nonzero means this is a MEM that must be reloaded into a reg
2709              regardless of what the constraint says.  */
2710           int force_reload = 0;
2711           int offmemok = 0;
2712           /* Nonzero if a constant forced into memory would be OK for this
2713              operand.  */
2714           int constmemok = 0;
2715           int earlyclobber = 0;
2716
2717           /* If the predicate accepts a unary operator, it means that
2718              we need to reload the operand.  */
2719           if (GET_RTX_CLASS (GET_CODE (operand)) == '1')
2720             operand = XEXP (operand, 0);
2721
2722           /* If the operand is a SUBREG, extract
2723              the REG or MEM (or maybe even a constant) within.
2724              (Constants can occur as a result of reg_equiv_constant.)  */
2725
2726           while (GET_CODE (operand) == SUBREG)
2727             {
2728               offset += SUBREG_WORD (operand);
2729               operand = SUBREG_REG (operand);
2730               /* Force reload if this is a constant or PLUS or if there may may
2731                  be a problem accessing OPERAND in the outer mode.  */
2732               if (CONSTANT_P (operand)
2733                   || GET_CODE (operand) == PLUS
2734                   /* We must force a reload of paradoxical SUBREGs
2735                      of a MEM because the alignment of the inner value
2736                      may not be enough to do the outer reference.  On
2737                      big-endian machines, it may also reference outside
2738                      the object.
2739
2740                      On machines that extend byte operations and we have a
2741                      SUBREG where both the inner and outer modes are no wider
2742                      than a word and the inner mode is narrower, is integral,
2743                      and gets extended when loaded from memory, combine.c has
2744                      made assumptions about the behavior of the machine in such
2745                      register access.  If the data is, in fact, in memory we
2746                      must always load using the size assumed to be in the
2747                      register and let the insn do the different-sized 
2748                      accesses.  */
2749                   || ((GET_CODE (operand) == MEM
2750                        || (GET_CODE (operand)== REG
2751                            && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
2752                       && (((GET_MODE_BITSIZE (GET_MODE (operand))
2753                             < BIGGEST_ALIGNMENT)
2754                            && (GET_MODE_SIZE (operand_mode[i])
2755                                > GET_MODE_SIZE (GET_MODE (operand))))
2756                           || (GET_CODE (operand) == MEM && BYTES_BIG_ENDIAN)
2757 #ifdef LOAD_EXTEND_OP
2758                           || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2759                               && (GET_MODE_SIZE (GET_MODE (operand))
2760                                   <= UNITS_PER_WORD)
2761                               && (GET_MODE_SIZE (operand_mode[i])
2762                                   > GET_MODE_SIZE (GET_MODE (operand)))
2763                               && INTEGRAL_MODE_P (GET_MODE (operand))
2764                               && LOAD_EXTEND_OP (GET_MODE (operand)) != NIL)
2765 #endif
2766                           ))
2767                   /* Subreg of a hard reg which can't handle the subreg's mode
2768                      or which would handle that mode in the wrong number of
2769                      registers for subregging to work.  */
2770                   || (GET_CODE (operand) == REG
2771                       && REGNO (operand) < FIRST_PSEUDO_REGISTER
2772                       && ((GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2773                            && (GET_MODE_SIZE (GET_MODE (operand))
2774                                > UNITS_PER_WORD)
2775                            && ((GET_MODE_SIZE (GET_MODE (operand))
2776                                 / UNITS_PER_WORD)
2777                                != HARD_REGNO_NREGS (REGNO (operand),
2778                                                     GET_MODE (operand))))
2779                           || ! HARD_REGNO_MODE_OK (REGNO (operand) + offset,
2780                                                    operand_mode[i]))))
2781                 force_reload = 1;
2782             }
2783
2784           this_alternative[i] = (int) NO_REGS;
2785           this_alternative_win[i] = 0;
2786           this_alternative_offmemok[i] = 0;
2787           this_alternative_earlyclobber[i] = 0;
2788           this_alternative_matches[i] = -1;
2789
2790           /* An empty constraint or empty alternative
2791              allows anything which matched the pattern.  */
2792           if (*p == 0 || *p == ',')
2793             win = 1, badop = 0;
2794
2795           /* Scan this alternative's specs for this operand;
2796              set WIN if the operand fits any letter in this alternative.
2797              Otherwise, clear BADOP if this operand could
2798              fit some letter after reloads,
2799              or set WINREG if this operand could fit after reloads
2800              provided the constraint allows some registers.  */
2801
2802           while (*p && (c = *p++) != ',')
2803             switch (c)
2804               {
2805               case '=':
2806               case '+':
2807               case '*':
2808                 break;
2809
2810               case '%':
2811                 /* The last operand should not be marked commutative.  */
2812                 if (i != noperands - 1)
2813                   commutative = i;
2814                 break;
2815
2816               case '?':
2817                 reject += 3;
2818                 break;
2819
2820               case '!':
2821                 reject = 300;
2822                 break;
2823
2824               case '#':
2825                 /* Ignore rest of this alternative as far as
2826                    reloading is concerned.  */
2827                 while (*p && *p != ',') p++;
2828                 break;
2829
2830               case '0':
2831               case '1':
2832               case '2':
2833               case '3':
2834               case '4':
2835                 c -= '0';
2836                 this_alternative_matches[i] = c;
2837                 /* We are supposed to match a previous operand.
2838                    If we do, we win if that one did.
2839                    If we do not, count both of the operands as losers.
2840                    (This is too conservative, since most of the time
2841                    only a single reload insn will be needed to make
2842                    the two operands win.  As a result, this alternative
2843                    may be rejected when it is actually desirable.)  */
2844                 if ((swapped && (c != commutative || i != commutative + 1))
2845                     /* If we are matching as if two operands were swapped,
2846                        also pretend that operands_match had been computed
2847                        with swapped.
2848                        But if I is the second of those and C is the first,
2849                        don't exchange them, because operands_match is valid
2850                        only on one side of its diagonal.  */
2851                     ? (operands_match
2852                         [(c == commutative || c == commutative + 1)
2853                          ? 2*commutative + 1 - c : c]
2854                         [(i == commutative || i == commutative + 1)
2855                          ? 2*commutative + 1 - i : i])
2856                     : operands_match[c][i])
2857                   win = this_alternative_win[c];
2858                 else
2859                   {
2860                     /* Operands don't match.  */
2861                     rtx value;
2862                     /* Retroactively mark the operand we had to match
2863                        as a loser, if it wasn't already.  */
2864                     if (this_alternative_win[c])
2865                       losers++;
2866                     this_alternative_win[c] = 0;
2867                     if (this_alternative[c] == (int) NO_REGS)
2868                       bad = 1;
2869                     /* But count the pair only once in the total badness of
2870                        this alternative, if the pair can be a dummy reload.  */
2871                     value
2872                       = find_dummy_reload (recog_operand[i], recog_operand[c],
2873                                            recog_operand_loc[i], recog_operand_loc[c],
2874                                            operand_mode[i], operand_mode[c],
2875                                            this_alternative[c], -1);
2876
2877                     if (value != 0)
2878                       losers--;
2879                   }
2880                 /* This can be fixed with reloads if the operand
2881                    we are supposed to match can be fixed with reloads.  */
2882                 badop = 0;
2883                 this_alternative[i] = this_alternative[c];
2884
2885                 /* If we have to reload this operand and some previous
2886                    operand also had to match the same thing as this
2887                    operand, we don't know how to do that.  So reject this
2888                    alternative.  */
2889                 if (! win || force_reload)
2890                   for (j = 0; j < i; j++)
2891                     if (this_alternative_matches[j]
2892                         == this_alternative_matches[i])
2893                       badop = 1;
2894
2895                 break;
2896
2897               case 'p':
2898                 /* All necessary reloads for an address_operand
2899                    were handled in find_reloads_address.  */
2900                 this_alternative[i] = (int) BASE_REG_CLASS;
2901                 win = 1;
2902                 break;
2903
2904               case 'm':
2905                 if (force_reload)
2906                   break;
2907                 if (GET_CODE (operand) == MEM
2908                     || (GET_CODE (operand) == REG
2909                         && REGNO (operand) >= FIRST_PSEUDO_REGISTER
2910                         && reg_renumber[REGNO (operand)] < 0))
2911                   win = 1;
2912                 if (CONSTANT_P (operand))
2913                   badop = 0;
2914                 constmemok = 1;
2915                 break;
2916
2917               case '<':
2918                 if (GET_CODE (operand) == MEM
2919                     && ! address_reloaded[i]
2920                     && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
2921                         || GET_CODE (XEXP (operand, 0)) == POST_DEC))
2922                   win = 1;
2923                 break;
2924
2925               case '>':
2926                 if (GET_CODE (operand) == MEM
2927                     && ! address_reloaded[i]
2928                     && (GET_CODE (XEXP (operand, 0)) == PRE_INC
2929                         || GET_CODE (XEXP (operand, 0)) == POST_INC))
2930                   win = 1;
2931                 break;
2932
2933                 /* Memory operand whose address is not offsettable.  */
2934               case 'V':
2935                 if (force_reload)
2936                   break;
2937                 if (GET_CODE (operand) == MEM
2938                     && ! (ind_levels ? offsettable_memref_p (operand)
2939                           : offsettable_nonstrict_memref_p (operand))
2940                     /* Certain mem addresses will become offsettable
2941                        after they themselves are reloaded.  This is important;
2942                        we don't want our own handling of unoffsettables
2943                        to override the handling of reg_equiv_address.  */
2944                     && !(GET_CODE (XEXP (operand, 0)) == REG
2945                          && (ind_levels == 0
2946                              || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0)))
2947                   win = 1;
2948                 break;
2949
2950                 /* Memory operand whose address is offsettable.  */
2951               case 'o':
2952                 if (force_reload)
2953                   break;
2954                 if ((GET_CODE (operand) == MEM
2955                      /* If IND_LEVELS, find_reloads_address won't reload a
2956                         pseudo that didn't get a hard reg, so we have to
2957                         reject that case.  */
2958                      && (ind_levels ? offsettable_memref_p (operand)
2959                          : offsettable_nonstrict_memref_p (operand)))
2960                     /* A reloaded auto-increment address is offsettable,
2961                        because it is now just a simple register indirect.  */
2962                     || (GET_CODE (operand) == MEM
2963                         && address_reloaded[i]
2964                         && (GET_CODE (XEXP (operand, 0)) == PRE_INC
2965                             || GET_CODE (XEXP (operand, 0)) == PRE_DEC
2966                             || GET_CODE (XEXP (operand, 0)) == POST_INC
2967                             || GET_CODE (XEXP (operand, 0)) == POST_DEC))
2968                     /* Certain mem addresses will become offsettable
2969                        after they themselves are reloaded.  This is important;
2970                        we don't want our own handling of unoffsettables
2971                        to override the handling of reg_equiv_address.  */
2972                     || (GET_CODE (operand) == MEM
2973                         && GET_CODE (XEXP (operand, 0)) == REG
2974                         && (ind_levels == 0
2975                             || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0))
2976                     || (GET_CODE (operand) == REG
2977                         && REGNO (operand) >= FIRST_PSEUDO_REGISTER
2978                         && reg_renumber[REGNO (operand)] < 0
2979                         /* If reg_equiv_address is nonzero, we will be
2980                            loading it into a register; hence it will be
2981                            offsettable, but we cannot say that reg_equiv_mem
2982                            is offsettable without checking.  */
2983                         && ((reg_equiv_mem[REGNO (operand)] != 0
2984                              && offsettable_memref_p (reg_equiv_mem[REGNO (operand)]))
2985                             || (reg_equiv_address[REGNO (operand)] != 0))))
2986                   win = 1;
2987                 if (CONSTANT_P (operand) || GET_CODE (operand) == MEM)
2988                   badop = 0;
2989                 constmemok = 1;
2990                 offmemok = 1;
2991                 break;
2992
2993               case '&':
2994                 /* Output operand that is stored before the need for the
2995                    input operands (and their index registers) is over.  */
2996                 earlyclobber = 1, this_earlyclobber = 1;
2997                 break;
2998
2999               case 'E':
3000 #ifndef REAL_ARITHMETIC
3001                 /* Match any floating double constant, but only if
3002                    we can examine the bits of it reliably.  */
3003                 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
3004                      || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
3005                     && GET_MODE (operand) != VOIDmode && ! flag_pretend_float)
3006                   break;
3007 #endif
3008                 if (GET_CODE (operand) == CONST_DOUBLE)
3009                   win = 1;
3010                 break;
3011
3012               case 'F':
3013                 if (GET_CODE (operand) == CONST_DOUBLE)
3014                   win = 1;
3015                 break;
3016
3017               case 'G':
3018               case 'H':
3019                 if (GET_CODE (operand) == CONST_DOUBLE
3020                     && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c))
3021                   win = 1;
3022                 break;
3023
3024               case 's':
3025                 if (GET_CODE (operand) == CONST_INT
3026                     || (GET_CODE (operand) == CONST_DOUBLE
3027                         && GET_MODE (operand) == VOIDmode))
3028                   break;
3029               case 'i':
3030                 if (CONSTANT_P (operand)
3031 #ifdef LEGITIMATE_PIC_OPERAND_P
3032                     && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand))
3033 #endif
3034                     )
3035                   win = 1;
3036                 break;
3037
3038               case 'n':
3039                 if (GET_CODE (operand) == CONST_INT
3040                     || (GET_CODE (operand) == CONST_DOUBLE
3041                         && GET_MODE (operand) == VOIDmode))
3042                   win = 1;
3043                 break;
3044
3045               case 'I':
3046               case 'J':
3047               case 'K':
3048               case 'L':
3049               case 'M':
3050               case 'N':
3051               case 'O':
3052               case 'P':
3053                 if (GET_CODE (operand) == CONST_INT
3054                     && CONST_OK_FOR_LETTER_P (INTVAL (operand), c))
3055                   win = 1;
3056                 break;
3057
3058               case 'X':
3059                 win = 1;
3060                 break;
3061
3062               case 'g':
3063                 if (! force_reload
3064                     /* A PLUS is never a valid operand, but reload can make
3065                        it from a register when eliminating registers.  */
3066                     && GET_CODE (operand) != PLUS
3067                     /* A SCRATCH is not a valid operand.  */
3068                     && GET_CODE (operand) != SCRATCH
3069 #ifdef LEGITIMATE_PIC_OPERAND_P
3070                     && (! CONSTANT_P (operand) 
3071                         || ! flag_pic 
3072                         || LEGITIMATE_PIC_OPERAND_P (operand))
3073 #endif
3074                     && (GENERAL_REGS == ALL_REGS
3075                         || GET_CODE (operand) != REG
3076                         || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
3077                             && reg_renumber[REGNO (operand)] < 0)))
3078                   win = 1;
3079                 /* Drop through into 'r' case */
3080
3081               case 'r':
3082                 this_alternative[i]
3083                   = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
3084                 goto reg;
3085
3086 #ifdef EXTRA_CONSTRAINT
3087               case 'Q':
3088               case 'R':
3089               case 'S':
3090               case 'T':
3091               case 'U':
3092                 if (EXTRA_CONSTRAINT (operand, c))
3093                   win = 1;
3094                 break;
3095 #endif
3096   
3097               default:
3098                 this_alternative[i]
3099                   = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)];
3100                 
3101               reg:
3102                 if (GET_MODE (operand) == BLKmode)
3103                   break;
3104                 winreg = 1;
3105                 if (GET_CODE (operand) == REG
3106                     && reg_fits_class_p (operand, this_alternative[i],
3107                                          offset, GET_MODE (recog_operand[i])))
3108                   win = 1;
3109                 break;
3110               }
3111
3112           constraints[i] = p;
3113
3114           /* If this operand could be handled with a reg,
3115              and some reg is allowed, then this operand can be handled.  */
3116           if (winreg && this_alternative[i] != (int) NO_REGS)
3117             badop = 0;
3118
3119           /* Record which operands fit this alternative.  */
3120           this_alternative_earlyclobber[i] = earlyclobber;
3121           if (win && ! force_reload)
3122             this_alternative_win[i] = 1;
3123           else
3124             {
3125               int const_to_mem = 0;
3126
3127               this_alternative_offmemok[i] = offmemok;
3128               losers++;
3129               if (badop)
3130                 bad = 1;
3131               /* Alternative loses if it has no regs for a reg operand.  */
3132               if (GET_CODE (operand) == REG
3133                   && this_alternative[i] == (int) NO_REGS
3134                   && this_alternative_matches[i] < 0)
3135                 bad = 1;
3136
3137               /* Alternative loses if it requires a type of reload not
3138                  permitted for this insn.  We can always reload SCRATCH
3139                  and objects with a REG_UNUSED note.  */
3140               if (GET_CODE (operand) != SCRATCH
3141                   && modified[i] != RELOAD_READ && no_output_reloads
3142                   && ! find_reg_note (insn, REG_UNUSED, operand))
3143                 bad = 1;
3144               else if (modified[i] != RELOAD_WRITE && no_input_reloads)
3145                 bad = 1;
3146
3147               /* If this is a constant that is reloaded into the desired
3148                  class by copying it to memory first, count that as another
3149                  reload.  This is consistent with other code and is
3150                  required to avoid choosing another alternative when
3151                  the constant is moved into memory by this function on
3152                  an early reload pass.  Note that the test here is 
3153                  precisely the same as in the code below that calls
3154                  force_const_mem.  */
3155               if (CONSTANT_P (operand)
3156                   /* force_const_mem does not accept HIGH.  */
3157                   && GET_CODE (operand) != HIGH
3158                   && (PREFERRED_RELOAD_CLASS (operand,
3159                                               (enum reg_class) this_alternative[i])
3160                       == NO_REGS)
3161                   && operand_mode[i] != VOIDmode)
3162                 {
3163                   const_to_mem = 1;
3164                   if (this_alternative[i] != (int) NO_REGS)
3165                     losers++;
3166                 }
3167
3168               /* If we can't reload this value at all, reject this
3169                  alternative.  Note that we could also lose due to
3170                  LIMIT_RELOAD_RELOAD_CLASS, but we don't check that
3171                  here.  */
3172
3173               if (! CONSTANT_P (operand)
3174                   && (enum reg_class) this_alternative[i] != NO_REGS
3175                   && (PREFERRED_RELOAD_CLASS (operand,
3176                                               (enum reg_class) this_alternative[i])
3177                       == NO_REGS))
3178                 bad = 1;
3179
3180               /* We prefer to reload pseudos over reloading other things,
3181                  since such reloads may be able to be eliminated later.
3182                  If we are reloading a SCRATCH, we won't be generating any
3183                  insns, just using a register, so it is also preferred. 
3184                  So bump REJECT in other cases.  Don't do this in the
3185                  case where we are forcing a constant into memory and
3186                  it will then win since we don't want to have a different
3187                  alternative match then.  */
3188               if (! (GET_CODE (operand) == REG
3189                      && REGNO (operand) >= FIRST_PSEUDO_REGISTER)
3190                   && GET_CODE (operand) != SCRATCH
3191                   && ! (const_to_mem && constmemok))
3192                 reject++;
3193             }
3194
3195           /* If this operand is a pseudo register that didn't get a hard 
3196              reg and this alternative accepts some register, see if the
3197              class that we want is a subset of the preferred class for this
3198              register.  If not, but it intersects that class, use the
3199              preferred class instead.  If it does not intersect the preferred
3200              class, show that usage of this alternative should be discouraged;
3201              it will be discouraged more still if the register is `preferred
3202              or nothing'.  We do this because it increases the chance of
3203              reusing our spill register in a later insn and avoiding a pair
3204              of memory stores and loads.
3205
3206              Don't bother with this if this alternative will accept this
3207              operand.
3208
3209              Don't do this for a multiword operand, since it is only a
3210              small win and has the risk of requiring more spill registers,
3211              which could cause a large loss.
3212
3213              Don't do this if the preferred class has only one register
3214              because we might otherwise exhaust the class.  */
3215
3216
3217           if (! win && this_alternative[i] != (int) NO_REGS
3218               && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3219               && reg_class_size[(int) preferred_class[i]] > 1)
3220             {
3221               if (! reg_class_subset_p (this_alternative[i],
3222                                         preferred_class[i]))
3223                 {
3224                   /* Since we don't have a way of forming the intersection,
3225                      we just do something special if the preferred class
3226                      is a subset of the class we have; that's the most 
3227                      common case anyway.  */
3228                   if (reg_class_subset_p (preferred_class[i],
3229                                           this_alternative[i]))
3230                     this_alternative[i] = (int) preferred_class[i];
3231                   else
3232                     reject += (1 + pref_or_nothing[i]);
3233                 }
3234             }
3235         }
3236
3237       /* Now see if any output operands that are marked "earlyclobber"
3238          in this alternative conflict with any input operands
3239          or any memory addresses.  */
3240
3241       for (i = 0; i < noperands; i++)
3242         if (this_alternative_earlyclobber[i]
3243             && this_alternative_win[i])
3244           {
3245             struct decomposition early_data; 
3246
3247             early_data = decompose (recog_operand[i]);
3248
3249             if (modified[i] == RELOAD_READ)
3250               {
3251                 if (this_insn_is_asm)
3252                   warning_for_asm (this_insn,
3253                                    "`&' constraint used with input operand");
3254                 else
3255                   abort ();
3256                 continue;
3257               }
3258             
3259             if (this_alternative[i] == NO_REGS)
3260               {
3261                 this_alternative_earlyclobber[i] = 0;
3262                 if (this_insn_is_asm)
3263                   error_for_asm (this_insn,
3264                                  "`&' constraint used with no register class");
3265                 else
3266                   abort ();
3267               }
3268
3269             for (j = 0; j < noperands; j++)
3270               /* Is this an input operand or a memory ref?  */
3271               if ((GET_CODE (recog_operand[j]) == MEM
3272                    || modified[j] != RELOAD_WRITE)
3273                   && j != i
3274                   /* Ignore things like match_operator operands.  */
3275                   && *constraints1[j] != 0
3276                   /* Don't count an input operand that is constrained to match
3277                      the early clobber operand.  */
3278                   && ! (this_alternative_matches[j] == i
3279                         && rtx_equal_p (recog_operand[i], recog_operand[j]))
3280                   /* Is it altered by storing the earlyclobber operand?  */
3281                   && !immune_p (recog_operand[j], recog_operand[i], early_data))
3282                 {
3283                   /* If the output is in a single-reg class,
3284                      it's costly to reload it, so reload the input instead.  */
3285                   if (reg_class_size[this_alternative[i]] == 1
3286                       && (GET_CODE (recog_operand[j]) == REG
3287                           || GET_CODE (recog_operand[j]) == SUBREG))
3288                     {
3289                       losers++;
3290                       this_alternative_win[j] = 0;
3291                     }
3292                   else
3293                     break;
3294                 }
3295             /* If an earlyclobber operand conflicts with something,
3296                it must be reloaded, so request this and count the cost.  */
3297             if (j != noperands)
3298               {
3299                 losers++;
3300                 this_alternative_win[i] = 0;
3301                 for (j = 0; j < noperands; j++)
3302                   if (this_alternative_matches[j] == i
3303                       && this_alternative_win[j])
3304                     {
3305                       this_alternative_win[j] = 0;
3306                       losers++;
3307                     }
3308               }
3309           }
3310
3311       /* If one alternative accepts all the operands, no reload required,
3312          choose that alternative; don't consider the remaining ones.  */
3313       if (losers == 0)
3314         {
3315           /* Unswap these so that they are never swapped at `finish'.  */
3316           if (commutative >= 0)
3317             {
3318               recog_operand[commutative] = substed_operand[commutative];
3319               recog_operand[commutative + 1]
3320                 = substed_operand[commutative + 1];
3321             }
3322           for (i = 0; i < noperands; i++)
3323             {
3324               goal_alternative_win[i] = 1;
3325               goal_alternative[i] = this_alternative[i];
3326               goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3327               goal_alternative_matches[i] = this_alternative_matches[i];
3328               goal_alternative_earlyclobber[i]
3329                 = this_alternative_earlyclobber[i];
3330             }
3331           goal_alternative_number = this_alternative_number;
3332           goal_alternative_swapped = swapped;
3333           goal_earlyclobber = this_earlyclobber;
3334           goto finish;
3335         }
3336
3337       /* REJECT, set by the ! and ? constraint characters and when a register
3338          would be reloaded into a non-preferred class, discourages the use of
3339          this alternative for a reload goal.  REJECT is incremented by three
3340          for each ? and one for each non-preferred class.  */
3341       losers = losers * 3 + reject;
3342
3343       /* If this alternative can be made to work by reloading,
3344          and it needs less reloading than the others checked so far,
3345          record it as the chosen goal for reloading.  */
3346       if (! bad && best > losers)
3347         {
3348           for (i = 0; i < noperands; i++)
3349             {
3350               goal_alternative[i] = this_alternative[i];
3351               goal_alternative_win[i] = this_alternative_win[i];
3352               goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3353               goal_alternative_matches[i] = this_alternative_matches[i];
3354               goal_alternative_earlyclobber[i]
3355                 = this_alternative_earlyclobber[i];
3356             }
3357           goal_alternative_swapped = swapped;
3358           best = losers;
3359           goal_alternative_number = this_alternative_number;
3360           goal_earlyclobber = this_earlyclobber;
3361         }
3362     }
3363
3364   /* If insn is commutative (it's safe to exchange a certain pair of operands)
3365      then we need to try each alternative twice,
3366      the second time matching those two operands
3367      as if we had exchanged them.
3368      To do this, really exchange them in operands.
3369
3370      If we have just tried the alternatives the second time,
3371      return operands to normal and drop through.  */
3372
3373   if (commutative >= 0)
3374     {
3375       swapped = !swapped;
3376       if (swapped)
3377         {
3378           register enum reg_class tclass;
3379           register int t;
3380
3381           recog_operand[commutative] = substed_operand[commutative + 1];
3382           recog_operand[commutative + 1] = substed_operand[commutative];
3383
3384           tclass = preferred_class[commutative];
3385           preferred_class[commutative] = preferred_class[commutative + 1];
3386           preferred_class[commutative + 1] = tclass;
3387
3388           t = pref_or_nothing[commutative];
3389           pref_or_nothing[commutative] = pref_or_nothing[commutative + 1];
3390           pref_or_nothing[commutative + 1] = t;
3391
3392           bcopy ((char *) constraints1, (char *) constraints,
3393                  noperands * sizeof (char *));
3394           goto try_swapped;
3395         }
3396       else
3397         {
3398           recog_operand[commutative] = substed_operand[commutative];
3399           recog_operand[commutative + 1] = substed_operand[commutative + 1];
3400         }
3401     }
3402
3403   /* The operands don't meet the constraints.
3404      goal_alternative describes the alternative
3405      that we could reach by reloading the fewest operands.
3406      Reload so as to fit it.  */
3407
3408   if (best == MAX_RECOG_OPERANDS + 300)
3409     {
3410       /* No alternative works with reloads??  */
3411       if (insn_code_number >= 0)
3412         abort ();
3413       error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3414       /* Avoid further trouble with this insn.  */
3415       PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
3416       n_reloads = 0;
3417       return;
3418     }
3419
3420   /* Jump to `finish' from above if all operands are valid already.
3421      In that case, goal_alternative_win is all 1.  */
3422  finish:
3423
3424   /* Right now, for any pair of operands I and J that are required to match,
3425      with I < J,
3426      goal_alternative_matches[J] is I.
3427      Set up goal_alternative_matched as the inverse function:
3428      goal_alternative_matched[I] = J.  */
3429
3430   for (i = 0; i < noperands; i++)
3431     goal_alternative_matched[i] = -1;
3432
3433   for (i = 0; i < noperands; i++)
3434     if (! goal_alternative_win[i]
3435         && goal_alternative_matches[i] >= 0)
3436       goal_alternative_matched[goal_alternative_matches[i]] = i;
3437
3438   /* If the best alternative is with operands 1 and 2 swapped,
3439      consider them swapped before reporting the reloads.  Update the
3440      operand numbers of any reloads already pushed.  */
3441
3442   if (goal_alternative_swapped)
3443     {
3444       register rtx tem;
3445
3446       tem = substed_operand[commutative];
3447       substed_operand[commutative] = substed_operand[commutative + 1];
3448       substed_operand[commutative + 1] = tem;
3449       tem = recog_operand[commutative];
3450       recog_operand[commutative] = recog_operand[commutative + 1];
3451       recog_operand[commutative + 1] = tem;
3452
3453       for (i = 0; i < n_reloads; i++)
3454         {
3455           if (reload_opnum[i] == commutative)
3456             reload_opnum[i] = commutative + 1;
3457           else if (reload_opnum[i] == commutative + 1)
3458             reload_opnum[i] = commutative;
3459         }
3460     }
3461
3462   /* Perform whatever substitutions on the operands we are supposed
3463      to make due to commutativity or replacement of registers
3464      with equivalent constants or memory slots.  */
3465
3466   for (i = 0; i < noperands; i++)
3467     {
3468       *recog_operand_loc[i] = substed_operand[i];
3469       /* While we are looping on operands, initialize this.  */
3470       operand_reloadnum[i] = -1;
3471
3472       /* If this is an earlyclobber operand, we need to widen the scope.
3473          The reload must remain valid from the start of the insn being
3474          reloaded until after the operand is stored into its destination.
3475          We approximate this with RELOAD_OTHER even though we know that we
3476          do not conflict with RELOAD_FOR_INPUT_ADDRESS reloads.
3477
3478          One special case that is worth checking is when we have an
3479          output that is earlyclobber but isn't used past the insn (typically
3480          a SCRATCH).  In this case, we only need have the reload live 
3481          through the insn itself, but not for any of our input or output
3482          reloads. 
3483
3484          In any case, anything needed to address this operand can remain
3485          however they were previously categorized.  */
3486
3487       if (goal_alternative_earlyclobber[i])
3488         operand_type[i]
3489           = (find_reg_note (insn, REG_UNUSED, recog_operand[i])
3490              ? RELOAD_FOR_INSN : RELOAD_OTHER);
3491     }
3492
3493   /* Any constants that aren't allowed and can't be reloaded
3494      into registers are here changed into memory references.  */
3495   for (i = 0; i < noperands; i++)
3496     if (! goal_alternative_win[i]
3497         && CONSTANT_P (recog_operand[i])
3498         /* force_const_mem does not accept HIGH.  */
3499         && GET_CODE (recog_operand[i]) != HIGH
3500         && (PREFERRED_RELOAD_CLASS (recog_operand[i],
3501                                     (enum reg_class) goal_alternative[i])
3502             == NO_REGS)
3503         && operand_mode[i] != VOIDmode)
3504       {
3505         *recog_operand_loc[i] = recog_operand[i]
3506           = find_reloads_toplev (force_const_mem (operand_mode[i],
3507                                                   recog_operand[i]),
3508                                  i, address_type[i], ind_levels, 0);
3509         if (alternative_allows_memconst (constraints1[i],
3510                                          goal_alternative_number))
3511           goal_alternative_win[i] = 1;
3512       }
3513
3514   /* Record the values of the earlyclobber operands for the caller.  */
3515   if (goal_earlyclobber)
3516     for (i = 0; i < noperands; i++)
3517       if (goal_alternative_earlyclobber[i])
3518         reload_earlyclobbers[n_earlyclobbers++] = recog_operand[i];
3519
3520   /* Now record reloads for all the operands that need them.  */
3521   for (i = 0; i < noperands; i++)
3522     if (! goal_alternative_win[i])
3523       {
3524         /* Operands that match previous ones have already been handled.  */
3525         if (goal_alternative_matches[i] >= 0)
3526           ;
3527         /* Handle an operand with a nonoffsettable address
3528            appearing where an offsettable address will do
3529            by reloading the address into a base register.
3530
3531            ??? We can also do this when the operand is a register and
3532            reg_equiv_mem is not offsettable, but this is a bit tricky,
3533            so we don't bother with it.  It may not be worth doing.  */
3534         else if (goal_alternative_matched[i] == -1
3535                  && goal_alternative_offmemok[i]
3536                  && GET_CODE (recog_operand[i]) == MEM)
3537           {
3538             operand_reloadnum[i]
3539               = push_reload (XEXP (recog_operand[i], 0), NULL_RTX,
3540                              &XEXP (recog_operand[i], 0), NULL_PTR,
3541                              BASE_REG_CLASS, GET_MODE (XEXP (recog_operand[i], 0)),
3542                              VOIDmode, 0, 0, i, RELOAD_FOR_INPUT);
3543             reload_inc[operand_reloadnum[i]]
3544               = GET_MODE_SIZE (GET_MODE (recog_operand[i]));
3545
3546             /* If this operand is an output, we will have made any
3547                reloads for its address as RELOAD_FOR_OUTPUT_ADDRESS, but
3548                now we are treating part of the operand as an input, so
3549                we must change these to RELOAD_FOR_INPUT_ADDRESS.  */
3550
3551             if (modified[i] == RELOAD_WRITE)
3552               {
3553                 for (j = 0; j < n_reloads; j++)
3554                   {
3555                     if (reload_opnum[j] == i)
3556                       {
3557                         if (reload_when_needed[j] == RELOAD_FOR_OUTPUT_ADDRESS)
3558                           reload_when_needed[j] = RELOAD_FOR_INPUT_ADDRESS;
3559                         else if (reload_when_needed[j]
3560                                  == RELOAD_FOR_OUTADDR_ADDRESS)
3561                           reload_when_needed[j] = RELOAD_FOR_INPADDR_ADDRESS;
3562                       }
3563                   }
3564               }
3565           }
3566         else if (goal_alternative_matched[i] == -1)
3567           operand_reloadnum[i] =
3568             push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
3569                          modified[i] != RELOAD_READ ? recog_operand[i] : 0,
3570                          (modified[i] != RELOAD_WRITE ?
3571                           recog_operand_loc[i] : 0),
3572                          modified[i] != RELOAD_READ ? recog_operand_loc[i] : 0,
3573                          (enum reg_class) goal_alternative[i],
3574                          (modified[i] == RELOAD_WRITE
3575                           ? VOIDmode : operand_mode[i]),
3576                          (modified[i] == RELOAD_READ
3577                           ? VOIDmode : operand_mode[i]),
3578                          (insn_code_number < 0 ? 0
3579                           : insn_operand_strict_low[insn_code_number][i]),
3580                          0, i, operand_type[i]);
3581         /* In a matching pair of operands, one must be input only
3582            and the other must be output only.
3583            Pass the input operand as IN and the other as OUT.  */
3584         else if (modified[i] == RELOAD_READ
3585                  && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
3586           {
3587             operand_reloadnum[i]
3588               = push_reload (recog_operand[i],
3589                              recog_operand[goal_alternative_matched[i]],
3590                              recog_operand_loc[i],
3591                              recog_operand_loc[goal_alternative_matched[i]],
3592                              (enum reg_class) goal_alternative[i],
3593                              operand_mode[i],
3594                              operand_mode[goal_alternative_matched[i]],
3595                              0, 0, i, RELOAD_OTHER);
3596             operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
3597           }
3598         else if (modified[i] == RELOAD_WRITE
3599                  && modified[goal_alternative_matched[i]] == RELOAD_READ)
3600           {
3601             operand_reloadnum[goal_alternative_matched[i]]
3602               = push_reload (recog_operand[goal_alternative_matched[i]],
3603                              recog_operand[i],
3604                              recog_operand_loc[goal_alternative_matched[i]],
3605                              recog_operand_loc[i],
3606                              (enum reg_class) goal_alternative[i],
3607                              operand_mode[goal_alternative_matched[i]],
3608                              operand_mode[i],
3609                              0, 0, i, RELOAD_OTHER);
3610             operand_reloadnum[i] = output_reloadnum;
3611           }
3612         else if (insn_code_number >= 0)
3613           abort ();
3614         else
3615           {
3616             error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3617             /* Avoid further trouble with this insn.  */
3618             PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
3619             n_reloads = 0;
3620             return;
3621           }
3622       }
3623     else if (goal_alternative_matched[i] < 0
3624              && goal_alternative_matches[i] < 0
3625              && optimize)
3626       {
3627         /* For each non-matching operand that's a MEM or a pseudo-register 
3628            that didn't get a hard register, make an optional reload.
3629            This may get done even if the insn needs no reloads otherwise.  */
3630
3631         rtx operand = recog_operand[i];
3632
3633         while (GET_CODE (operand) == SUBREG)
3634           operand = XEXP (operand, 0);
3635         if ((GET_CODE (operand) == MEM
3636              || (GET_CODE (operand) == REG
3637                  && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3638             && (enum reg_class) goal_alternative[i] != NO_REGS
3639             && ! no_input_reloads
3640             /* Optional output reloads don't do anything and we mustn't
3641                make in-out reloads on insns that are not permitted output
3642                reloads.  */
3643             && (modified[i] == RELOAD_READ
3644                 || (modified[i] == RELOAD_READ_WRITE && ! no_output_reloads)))
3645           operand_reloadnum[i]
3646             = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
3647                            modified[i] != RELOAD_READ ? recog_operand[i] : 0,
3648                            (modified[i] != RELOAD_WRITE
3649                             ? recog_operand_loc[i] : 0),
3650                            (modified[i] != RELOAD_READ
3651                             ? recog_operand_loc[i] : 0),
3652                            (enum reg_class) goal_alternative[i],
3653                            (modified[i] == RELOAD_WRITE
3654                             ? VOIDmode : operand_mode[i]),
3655                            (modified[i] == RELOAD_READ
3656                             ? VOIDmode : operand_mode[i]),
3657                            (insn_code_number < 0 ? 0
3658                             : insn_operand_strict_low[insn_code_number][i]),
3659                            1, i, operand_type[i]);
3660       }
3661     else if (goal_alternative_matches[i] >= 0
3662              && goal_alternative_win[goal_alternative_matches[i]]
3663              && modified[i] == RELOAD_READ
3664              && modified[goal_alternative_matches[i]] == RELOAD_WRITE
3665              && ! no_input_reloads && ! no_output_reloads
3666              && optimize)
3667       {
3668         /* Similarly, make an optional reload for a pair of matching
3669            objects that are in MEM or a pseudo that didn't get a hard reg.  */
3670
3671         rtx operand = recog_operand[i];
3672
3673         while (GET_CODE (operand) == SUBREG)
3674           operand = XEXP (operand, 0);
3675         if ((GET_CODE (operand) == MEM
3676              || (GET_CODE (operand) == REG
3677                  && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3678             && ((enum reg_class) goal_alternative[goal_alternative_matches[i]]
3679                 != NO_REGS))
3680           operand_reloadnum[i] = operand_reloadnum[goal_alternative_matches[i]]
3681             = push_reload (recog_operand[goal_alternative_matches[i]],
3682                            recog_operand[i],
3683                            recog_operand_loc[goal_alternative_matches[i]],
3684                            recog_operand_loc[i],
3685                            (enum reg_class) goal_alternative[goal_alternative_matches[i]],
3686                            operand_mode[goal_alternative_matches[i]],
3687                            operand_mode[i],
3688                            0, 1, goal_alternative_matches[i], RELOAD_OTHER);
3689       }
3690   
3691   /* If this insn pattern contains any MATCH_DUP's, make sure that
3692      they will be substituted if the operands they match are substituted.
3693      Also do now any substitutions we already did on the operands.
3694
3695      Don't do this if we aren't making replacements because we might be
3696      propagating things allocated by frame pointer elimination into places
3697      it doesn't expect.  */
3698
3699   if (insn_code_number >= 0 && replace)
3700     for (i = insn_n_dups[insn_code_number] - 1; i >= 0; i--)
3701       {
3702         int opno = recog_dup_num[i];
3703         *recog_dup_loc[i] = *recog_operand_loc[opno];
3704         if (operand_reloadnum[opno] >= 0)
3705           push_replacement (recog_dup_loc[i], operand_reloadnum[opno],
3706                             insn_operand_mode[insn_code_number][opno]);
3707       }
3708
3709 #if 0
3710   /* This loses because reloading of prior insns can invalidate the equivalence
3711      (or at least find_equiv_reg isn't smart enough to find it any more),
3712      causing this insn to need more reload regs than it needed before.
3713      It may be too late to make the reload regs available.
3714      Now this optimization is done safely in choose_reload_regs.  */
3715
3716   /* For each reload of a reg into some other class of reg,
3717      search for an existing equivalent reg (same value now) in the right class.
3718      We can use it as long as we don't need to change its contents.  */
3719   for (i = 0; i < n_reloads; i++)
3720     if (reload_reg_rtx[i] == 0
3721         && reload_in[i] != 0
3722         && GET_CODE (reload_in[i]) == REG
3723         && reload_out[i] == 0)
3724       {
3725         reload_reg_rtx[i]
3726           = find_equiv_reg (reload_in[i], insn, reload_reg_class[i], -1,
3727                             static_reload_reg_p, 0, reload_inmode[i]);
3728         /* Prevent generation of insn to load the value
3729            because the one we found already has the value.  */
3730         if (reload_reg_rtx[i])
3731           reload_in[i] = reload_reg_rtx[i];
3732       }
3733 #endif
3734
3735   /* Perhaps an output reload can be combined with another
3736      to reduce needs by one.  */
3737   if (!goal_earlyclobber)
3738     combine_reloads ();
3739
3740   /* If we have a pair of reloads for parts of an address, they are reloading
3741      the same object, the operands themselves were not reloaded, and they
3742      are for two operands that are supposed to match, merge the reloads and
3743      change the type of the surviving reload to RELOAD_FOR_OPERAND_ADDRESS.  */
3744
3745   for (i = 0; i < n_reloads; i++)
3746     {
3747       int k;
3748
3749       for (j = i + 1; j < n_reloads; j++)
3750         if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3751              || reload_when_needed[i] == RELOAD_FOR_OUTPUT_ADDRESS
3752              || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3753              || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3754             && (reload_when_needed[j] == RELOAD_FOR_INPUT_ADDRESS
3755                 || reload_when_needed[j] == RELOAD_FOR_OUTPUT_ADDRESS
3756                 || reload_when_needed[j] == RELOAD_FOR_INPADDR_ADDRESS
3757                 || reload_when_needed[j] == RELOAD_FOR_OUTADDR_ADDRESS)
3758             && rtx_equal_p (reload_in[i], reload_in[j])
3759             && (operand_reloadnum[reload_opnum[i]] < 0
3760                 || reload_optional[operand_reloadnum[reload_opnum[i]]])
3761             && (operand_reloadnum[reload_opnum[j]] < 0
3762                 || reload_optional[operand_reloadnum[reload_opnum[j]]])
3763             && (goal_alternative_matches[reload_opnum[i]] == reload_opnum[j]
3764                 || (goal_alternative_matches[reload_opnum[j]]
3765                     == reload_opnum[i])))
3766           {
3767             for (k = 0; k < n_replacements; k++)
3768               if (replacements[k].what == j)
3769                 replacements[k].what = i;
3770
3771             if (reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3772                 || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3773               reload_when_needed[i] = RELOAD_FOR_OPADDR_ADDR;
3774             else
3775               reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
3776             reload_in[j] = 0;
3777           }
3778     }
3779
3780   /* Scan all the reloads and update their type. 
3781      If a reload is for the address of an operand and we didn't reload
3782      that operand, change the type.  Similarly, change the operand number
3783      of a reload when two operands match.  If a reload is optional, treat it
3784      as though the operand isn't reloaded.
3785
3786      ??? This latter case is somewhat odd because if we do the optional
3787      reload, it means the object is hanging around.  Thus we need only
3788      do the address reload if the optional reload was NOT done.
3789
3790      Change secondary reloads to be the address type of their operand, not
3791      the normal type.
3792
3793      If an operand's reload is now RELOAD_OTHER, change any
3794      RELOAD_FOR_INPUT_ADDRESS reloads of that operand to
3795      RELOAD_FOR_OTHER_ADDRESS.  */
3796
3797   for (i = 0; i < n_reloads; i++)
3798     {
3799       if (reload_secondary_p[i]
3800           && reload_when_needed[i] == operand_type[reload_opnum[i]])
3801         reload_when_needed[i] = address_type[reload_opnum[i]];
3802
3803       if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3804            || reload_when_needed[i] == RELOAD_FOR_OUTPUT_ADDRESS
3805            || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3806            || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3807           && (operand_reloadnum[reload_opnum[i]] < 0
3808               || reload_optional[operand_reloadnum[reload_opnum[i]]]))
3809         {
3810           /* If we have a secondary reload to go along with this reload,
3811              change its type to RELOAD_FOR_OPADDR_ADDR.  */
3812
3813           if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3814                || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS)
3815               && reload_secondary_in_reload[i] != -1)
3816             {
3817               int secondary_in_reload = reload_secondary_in_reload[i];
3818
3819               reload_when_needed[secondary_in_reload] = 
3820                 RELOAD_FOR_OPADDR_ADDR;
3821
3822               /* If there's a tertiary reload we have to change it also.  */
3823               if (secondary_in_reload > 0
3824                   && reload_secondary_in_reload[secondary_in_reload] != -1)
3825                 reload_when_needed[reload_secondary_in_reload[secondary_in_reload]] 
3826                   = RELOAD_FOR_OPADDR_ADDR;
3827             }
3828
3829           if ((reload_when_needed[i] == RELOAD_FOR_OUTPUT_ADDRESS
3830                || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3831               && reload_secondary_out_reload[i] != -1)
3832             {
3833               int secondary_out_reload = reload_secondary_out_reload[i];
3834
3835               reload_when_needed[secondary_out_reload] = 
3836                 RELOAD_FOR_OPADDR_ADDR;
3837
3838               /* If there's a tertiary reload we have to change it also.  */
3839               if (secondary_out_reload
3840                   && reload_secondary_out_reload[secondary_out_reload] != -1)
3841                 reload_when_needed[reload_secondary_out_reload[secondary_out_reload]] 
3842                   = RELOAD_FOR_OPADDR_ADDR;
3843             }
3844           if (reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3845               || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3846             reload_when_needed[i] = RELOAD_FOR_OPADDR_ADDR;
3847           else
3848             reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
3849         }
3850
3851       if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3852            || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS)
3853           && operand_reloadnum[reload_opnum[i]] >= 0
3854           && (reload_when_needed[operand_reloadnum[reload_opnum[i]]] 
3855               == RELOAD_OTHER))
3856         reload_when_needed[i] = RELOAD_FOR_OTHER_ADDRESS;
3857
3858       if (goal_alternative_matches[reload_opnum[i]] >= 0)
3859         reload_opnum[i] = goal_alternative_matches[reload_opnum[i]];
3860     }
3861
3862   /* See if we have any reloads that are now allowed to be merged
3863      because we've changed when the reload is needed to
3864      RELOAD_FOR_OPERAND_ADDRESS or RELOAD_FOR_OTHER_ADDRESS.  Only
3865      check for the most common cases.  */
3866
3867   for (i = 0; i < n_reloads; i++)
3868     if (reload_in[i] != 0 && reload_out[i] == 0
3869         && (reload_when_needed[i] == RELOAD_FOR_OPERAND_ADDRESS
3870             || reload_when_needed[i] == RELOAD_FOR_OPADDR_ADDR
3871             || reload_when_needed[i] == RELOAD_FOR_OTHER_ADDRESS))
3872       for (j = 0; j < n_reloads; j++)
3873         if (i != j && reload_in[j] != 0 && reload_out[j] == 0
3874             && reload_when_needed[j] == reload_when_needed[i]
3875             && MATCHES (reload_in[i], reload_in[j])
3876             && reload_reg_class[i] == reload_reg_class[j]
3877             && !reload_nocombine[i] && !reload_nocombine[j]
3878             && reload_reg_rtx[i] == reload_reg_rtx[j])
3879           {
3880             reload_opnum[i] = MIN (reload_opnum[i], reload_opnum[j]);
3881             transfer_replacements (i, j);
3882             reload_in[j] = 0;
3883           }
3884
3885 #else /* no REGISTER_CONSTRAINTS */
3886   int noperands;
3887   int insn_code_number;
3888   int goal_earlyclobber = 0; /* Always 0, to make combine_reloads happen.  */
3889   register int i;
3890   rtx body = PATTERN (insn);
3891
3892   n_reloads = 0;
3893   n_replacements = 0;
3894   n_earlyclobbers = 0;
3895   replace_reloads = replace;
3896   this_insn = insn;
3897
3898   /* Find what kind of insn this is.  NOPERANDS gets number of operands.
3899      Store the operand values in RECOG_OPERAND and the locations
3900      of the words in the insn that point to them in RECOG_OPERAND_LOC.
3901      Return if the insn needs no reload processing.  */
3902
3903   switch (GET_CODE (body))
3904     {
3905     case USE:
3906     case CLOBBER:
3907     case ASM_INPUT:
3908     case ADDR_VEC:
3909     case ADDR_DIFF_VEC:
3910       return;
3911
3912     case PARALLEL:
3913     case SET:
3914       noperands = asm_noperands (body);
3915       if (noperands >= 0)
3916         {
3917           /* This insn is an `asm' with operands.
3918              First, find out how many operands, and allocate space.  */
3919
3920           insn_code_number = -1;
3921           /* ??? This is a bug! ???
3922              Give up and delete this insn if it has too many operands.  */
3923           if (noperands > MAX_RECOG_OPERANDS)
3924             abort ();
3925
3926           /* Now get the operand values out of the insn.  */
3927
3928           decode_asm_operands (body, recog_operand, recog_operand_loc,
3929                                NULL_PTR, NULL_PTR);
3930           break;
3931         }
3932
3933     default:
3934       /* Ordinary insn: recognize it, allocate space for operands and
3935          constraints, and get them out via insn_extract.  */
3936
3937       insn_code_number = recog_memoized (insn);
3938       noperands = insn_n_operands[insn_code_number];
3939       insn_extract (insn);
3940     }
3941
3942   if (noperands == 0)
3943     return;
3944
3945   for (i = 0; i < noperands; i++)
3946     {
3947       register RTX_CODE code = GET_CODE (recog_operand[i]);
3948       int is_set_dest = GET_CODE (body) == SET && (i == 0);
3949
3950       if (insn_code_number >= 0)
3951         if (insn_operand_address_p[insn_code_number][i])
3952           find_reloads_address (VOIDmode, NULL_PTR,
3953                                 recog_operand[i], recog_operand_loc[i],
3954                                 i, RELOAD_FOR_INPUT, ind_levels, insn);
3955
3956       /* In these cases, we can't tell if the operand is an input
3957          or an output, so be conservative.  In practice it won't be
3958          problem.  */
3959
3960       if (code == MEM)
3961         find_reloads_address (GET_MODE (recog_operand[i]),
3962                               recog_operand_loc[i],
3963                               XEXP (recog_operand[i], 0),
3964                               &XEXP (recog_operand[i], 0),
3965                               i, RELOAD_OTHER, ind_levels, insn);
3966       if (code == SUBREG)
3967         recog_operand[i] = *recog_operand_loc[i]
3968           = find_reloads_toplev (recog_operand[i], i, RELOAD_OTHER,
3969                                  ind_levels, is_set_dest);
3970       if (code == REG)
3971         {
3972           register int regno = REGNO (recog_operand[i]);
3973           if (reg_equiv_constant[regno] != 0 && !is_set_dest)
3974             recog_operand[i] = *recog_operand_loc[i]
3975               = reg_equiv_constant[regno];
3976 #if 0 /* This might screw code in reload1.c to delete prior output-reload
3977          that feeds this insn.  */
3978           if (reg_equiv_mem[regno] != 0)
3979             recog_operand[i] = *recog_operand_loc[i]
3980               = reg_equiv_mem[regno];
3981 #endif
3982         }
3983     }
3984
3985   /* Perhaps an output reload can be combined with another
3986      to reduce needs by one.  */
3987   if (!goal_earlyclobber)
3988     combine_reloads ();
3989 #endif /* no REGISTER_CONSTRAINTS */
3990 }
3991
3992 /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
3993    accepts a memory operand with constant address.  */
3994
3995 static int
3996 alternative_allows_memconst (constraint, altnum)
3997      char *constraint;
3998      int altnum;
3999 {
4000   register int c;
4001   /* Skip alternatives before the one requested.  */
4002   while (altnum > 0)
4003     {
4004       while (*constraint++ != ',');
4005       altnum--;
4006     }
4007   /* Scan the requested alternative for 'm' or 'o'.
4008      If one of them is present, this alternative accepts memory constants.  */
4009   while ((c = *constraint++) && c != ',' && c != '#')
4010     if (c == 'm' || c == 'o')
4011       return 1;
4012   return 0;
4013 }
4014 \f
4015 /* Scan X for memory references and scan the addresses for reloading.
4016    Also checks for references to "constant" regs that we want to eliminate
4017    and replaces them with the values they stand for.
4018    We may alter X destructively if it contains a reference to such.
4019    If X is just a constant reg, we return the equivalent value
4020    instead of X.
4021
4022    IND_LEVELS says how many levels of indirect addressing this machine
4023    supports.
4024
4025    OPNUM and TYPE identify the purpose of the reload.
4026
4027    IS_SET_DEST is true if X is the destination of a SET, which is not
4028    appropriate to be replaced by a constant.  */
4029
4030 static rtx
4031 find_reloads_toplev (x, opnum, type, ind_levels, is_set_dest)
4032      rtx x;
4033      int opnum;
4034      enum reload_type type;
4035      int ind_levels;
4036      int is_set_dest;
4037 {
4038   register RTX_CODE code = GET_CODE (x);
4039
4040   register char *fmt = GET_RTX_FORMAT (code);
4041   register int i;
4042
4043   if (code == REG)
4044     {
4045       /* This code is duplicated for speed in find_reloads.  */
4046       register int regno = REGNO (x);
4047       if (reg_equiv_constant[regno] != 0 && !is_set_dest)
4048         x = reg_equiv_constant[regno];
4049 #if 0
4050 /*  This creates (subreg (mem...)) which would cause an unnecessary
4051     reload of the mem.  */
4052       else if (reg_equiv_mem[regno] != 0)
4053         x = reg_equiv_mem[regno];
4054 #endif
4055       else if (reg_equiv_address[regno] != 0)
4056         {
4057           /* If reg_equiv_address varies, it may be shared, so copy it.  */
4058           /* We must rerun eliminate_regs, in case the elimination
4059              offsets have changed.  */
4060           rtx addr = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0,
4061                                            NULL_RTX, 0),
4062                            0);
4063
4064           if (rtx_varies_p (addr))
4065             addr = copy_rtx (addr);
4066
4067           x = gen_rtx (MEM, GET_MODE (x), addr);
4068           RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4069           find_reloads_address (GET_MODE (x), NULL_PTR,
4070                                 XEXP (x, 0),
4071                                 &XEXP (x, 0), opnum, type, ind_levels, 0);
4072         }
4073       return x;
4074     }
4075   if (code == MEM)
4076     {
4077       rtx tem = x;
4078       find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0),
4079                             opnum, type, ind_levels, 0);
4080       return tem;
4081     }
4082
4083   if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG)
4084     {
4085       /* Check for SUBREG containing a REG that's equivalent to a constant. 
4086          If the constant has a known value, truncate it right now.
4087          Similarly if we are extracting a single-word of a multi-word
4088          constant.  If the constant is symbolic, allow it to be substituted
4089          normally.  push_reload will strip the subreg later.  If the
4090          constant is VOIDmode, abort because we will lose the mode of
4091          the register (this should never happen because one of the cases
4092          above should handle it).  */
4093
4094       register int regno = REGNO (SUBREG_REG (x));
4095       rtx tem;
4096
4097       if (subreg_lowpart_p (x)
4098           && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4099           && reg_equiv_constant[regno] != 0
4100           && (tem = gen_lowpart_common (GET_MODE (x),
4101                                         reg_equiv_constant[regno])) != 0)
4102         return tem;
4103
4104       if (GET_MODE_BITSIZE (GET_MODE (x)) == BITS_PER_WORD
4105           && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4106           && reg_equiv_constant[regno] != 0
4107           && (tem = operand_subword (reg_equiv_constant[regno],
4108                                      SUBREG_WORD (x), 0,
4109                                      GET_MODE (SUBREG_REG (x)))) != 0)
4110         return tem;
4111
4112       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4113           && reg_equiv_constant[regno] != 0
4114           && GET_MODE (reg_equiv_constant[regno]) == VOIDmode)
4115         abort ();
4116
4117       /* If the subreg contains a reg that will be converted to a mem,
4118          convert the subreg to a narrower memref now.
4119          Otherwise, we would get (subreg (mem ...) ...),
4120          which would force reload of the mem.
4121
4122          We also need to do this if there is an equivalent MEM that is
4123          not offsettable.  In that case, alter_subreg would produce an
4124          invalid address on big-endian machines.
4125
4126          For machines that extend byte loads, we must not reload using
4127          a wider mode if we have a paradoxical SUBREG.  find_reloads will
4128          force a reload in that case.  So we should not do anything here.  */
4129
4130       else if (regno >= FIRST_PSEUDO_REGISTER
4131 #ifdef LOAD_EXTEND_OP
4132                && (GET_MODE_SIZE (GET_MODE (x))
4133                    <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
4134 #endif
4135                && (reg_equiv_address[regno] != 0
4136                    || (reg_equiv_mem[regno] != 0
4137                        && (! strict_memory_address_p (GET_MODE (x), 
4138                                                       XEXP (reg_equiv_mem[regno], 0))
4139                            || ! offsettable_memref_p (reg_equiv_mem[regno])))))
4140         {
4141           int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
4142           /* We must rerun eliminate_regs, in case the elimination
4143              offsets have changed.  */
4144           rtx addr = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0,
4145                                            NULL_RTX, 0),
4146                            0);
4147           if (BYTES_BIG_ENDIAN)
4148             {
4149               int size;
4150               size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
4151               offset += MIN (size, UNITS_PER_WORD);
4152               size = GET_MODE_SIZE (GET_MODE (x));
4153               offset -= MIN (size, UNITS_PER_WORD);
4154             }
4155           addr = plus_constant (addr, offset);
4156           x = gen_rtx (MEM, GET_MODE (x), addr);
4157           RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4158           find_reloads_address (GET_MODE (x), NULL_PTR,
4159                                 XEXP (x, 0),
4160                                 &XEXP (x, 0), opnum, type, ind_levels, 0);
4161         }
4162
4163     }
4164
4165   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4166     {
4167       if (fmt[i] == 'e')
4168         XEXP (x, i) = find_reloads_toplev (XEXP (x, i), opnum, type,
4169                                            ind_levels, is_set_dest);
4170     }
4171   return x;
4172 }
4173
4174 /* Return a mem ref for the memory equivalent of reg REGNO.
4175    This mem ref is not shared with anything.  */
4176
4177 static rtx
4178 make_memloc (ad, regno)
4179      rtx ad;
4180      int regno;
4181 {
4182   register int i;
4183   /* We must rerun eliminate_regs, in case the elimination
4184      offsets have changed.  */
4185   rtx tem = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0, NULL_RTX, 0),
4186                   0);
4187
4188 #if 0 /* We cannot safely reuse a memloc made here;
4189          if the pseudo appears twice, and its mem needs a reload,
4190          it gets two separate reloads assigned, but it only
4191          gets substituted with the second of them;
4192          then it can get used before that reload reg gets loaded up.  */
4193   for (i = 0; i < n_memlocs; i++)
4194     if (rtx_equal_p (tem, XEXP (memlocs[i], 0)))
4195       return memlocs[i];
4196 #endif
4197
4198   /* If TEM might contain a pseudo, we must copy it to avoid
4199      modifying it when we do the substitution for the reload.  */
4200   if (rtx_varies_p (tem))
4201     tem = copy_rtx (tem);
4202
4203   tem = gen_rtx (MEM, GET_MODE (ad), tem);
4204   RTX_UNCHANGING_P (tem) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4205   memlocs[n_memlocs++] = tem;
4206   return tem;
4207 }
4208
4209 /* Record all reloads needed for handling memory address AD
4210    which appears in *LOC in a memory reference to mode MODE
4211    which itself is found in location  *MEMREFLOC.
4212    Note that we take shortcuts assuming that no multi-reg machine mode
4213    occurs as part of an address.
4214
4215    OPNUM and TYPE specify the purpose of this reload.
4216
4217    IND_LEVELS says how many levels of indirect addressing this machine
4218    supports.
4219
4220    INSN, if nonzero, is the insn in which we do the reload.  It is used
4221    to determine if we may generate output reloads.
4222
4223    Value is nonzero if this address is reloaded or replaced as a whole.
4224    This is interesting to the caller if the address is an autoincrement.
4225
4226    Note that there is no verification that the address will be valid after
4227    this routine does its work.  Instead, we rely on the fact that the address
4228    was valid when reload started.  So we need only undo things that reload
4229    could have broken.  These are wrong register types, pseudos not allocated
4230    to a hard register, and frame pointer elimination.  */
4231
4232 static int
4233 find_reloads_address (mode, memrefloc, ad, loc, opnum, type, ind_levels, insn)
4234      enum machine_mode mode;
4235      rtx *memrefloc;
4236      rtx ad;
4237      rtx *loc;
4238      int opnum;
4239      enum reload_type type;
4240      int ind_levels;
4241      rtx insn;
4242 {
4243   register int regno;
4244   rtx tem;
4245
4246   /* If the address is a register, see if it is a legitimate address and
4247      reload if not.  We first handle the cases where we need not reload
4248      or where we must reload in a non-standard way.  */
4249
4250   if (GET_CODE (ad) == REG)
4251     {
4252       regno = REGNO (ad);
4253
4254       if (reg_equiv_constant[regno] != 0
4255           && strict_memory_address_p (mode, reg_equiv_constant[regno]))
4256         {
4257           *loc = ad = reg_equiv_constant[regno];
4258           return 1;
4259         }
4260
4261       else if (reg_equiv_address[regno] != 0)
4262         {
4263           tem = make_memloc (ad, regno);
4264           find_reloads_address (GET_MODE (tem), NULL_PTR, XEXP (tem, 0),
4265                                 &XEXP (tem, 0), opnum, ADDR_TYPE (type),
4266                                 ind_levels, insn);
4267           push_reload (tem, NULL_RTX, loc, NULL_PTR,
4268                        reload_address_base_reg_class,
4269                        GET_MODE (ad), VOIDmode, 0, 0,
4270                        opnum, type);
4271           return 1;
4272         }
4273
4274       /* We can avoid a reload if the register's equivalent memory expression
4275          is valid as an indirect memory address.
4276          But not all addresses are valid in a mem used as an indirect address:
4277          only reg or reg+constant.  */
4278
4279       else if (reg_equiv_mem[regno] != 0 && ind_levels > 0
4280                && strict_memory_address_p (mode, reg_equiv_mem[regno])
4281                && (GET_CODE (XEXP (reg_equiv_mem[regno], 0)) == REG
4282                    || (GET_CODE (XEXP (reg_equiv_mem[regno], 0)) == PLUS
4283                        && GET_CODE (XEXP (XEXP (reg_equiv_mem[regno], 0), 0)) == REG
4284                        && CONSTANT_P (XEXP (XEXP (reg_equiv_mem[regno], 0), 1)))))
4285         return 0;
4286
4287       /* The only remaining case where we can avoid a reload is if this is a
4288          hard register that is valid as a base register and which is not the
4289          subject of a CLOBBER in this insn.  */
4290
4291       else if (regno < FIRST_PSEUDO_REGISTER
4292                && REGNO_MODE_OK_FOR_BASE_P (regno, mode)
4293                && ! regno_clobbered_p (regno, this_insn))
4294         return 0;
4295
4296       /* If we do not have one of the cases above, we must do the reload.  */
4297       push_reload (ad, NULL_RTX, loc, NULL_PTR, reload_address_base_reg_class,
4298                    GET_MODE (ad), VOIDmode, 0, 0, opnum, type);
4299       return 1;
4300     }
4301
4302   if (strict_memory_address_p (mode, ad))
4303     {
4304       /* The address appears valid, so reloads are not needed.
4305          But the address may contain an eliminable register.
4306          This can happen because a machine with indirect addressing
4307          may consider a pseudo register by itself a valid address even when
4308          it has failed to get a hard reg.
4309          So do a tree-walk to find and eliminate all such regs.  */
4310
4311       /* But first quickly dispose of a common case.  */
4312       if (GET_CODE (ad) == PLUS
4313           && GET_CODE (XEXP (ad, 1)) == CONST_INT
4314           && GET_CODE (XEXP (ad, 0)) == REG
4315           && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
4316         return 0;
4317
4318       subst_reg_equivs_changed = 0;
4319       *loc = subst_reg_equivs (ad);
4320
4321       if (! subst_reg_equivs_changed)
4322         return 0;
4323
4324       /* Check result for validity after substitution.  */
4325       if (strict_memory_address_p (mode, ad))
4326         return 0;
4327     }
4328
4329   /* The address is not valid.  We have to figure out why.  One possibility
4330      is that it is itself a MEM.  This can happen when the frame pointer is
4331      being eliminated, a pseudo is not allocated to a hard register, and the
4332      offset between the frame and stack pointers is not its initial value.
4333      In that case the pseudo will have been replaced by a MEM referring to
4334      the stack pointer.  */
4335   if (GET_CODE (ad) == MEM)
4336     {
4337       /* First ensure that the address in this MEM is valid.  Then, unless
4338          indirect addresses are valid, reload the MEM into a register.  */
4339       tem = ad;
4340       find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0),
4341                             opnum, ADDR_TYPE (type),
4342                             ind_levels == 0 ? 0 : ind_levels - 1, insn);
4343
4344       /* If tem was changed, then we must create a new memory reference to
4345          hold it and store it back into memrefloc.  */
4346       if (tem != ad && memrefloc)
4347         {
4348           *memrefloc = copy_rtx (*memrefloc);
4349           copy_replacements (tem, XEXP (*memrefloc, 0));
4350           loc = &XEXP (*memrefloc, 0);
4351         }
4352
4353       /* Check similar cases as for indirect addresses as above except
4354          that we can allow pseudos and a MEM since they should have been
4355          taken care of above.  */
4356
4357       if (ind_levels == 0
4358           || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok)
4359           || GET_CODE (XEXP (tem, 0)) == MEM
4360           || ! (GET_CODE (XEXP (tem, 0)) == REG
4361                 || (GET_CODE (XEXP (tem, 0)) == PLUS
4362                     && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG
4363                     && GET_CODE (XEXP (XEXP (tem, 0), 1)) == CONST_INT)))
4364         {
4365           /* Must use TEM here, not AD, since it is the one that will
4366              have any subexpressions reloaded, if needed.  */
4367           push_reload (tem, NULL_RTX, loc, NULL_PTR,
4368                        reload_address_base_reg_class, GET_MODE (tem),
4369                        VOIDmode, 0,
4370                        0, opnum, type);
4371           return 1;
4372         }
4373       else
4374         return 0;
4375     }
4376
4377   /* If we have address of a stack slot but it's not valid because the
4378      displacement is too large, compute the sum in a register.
4379      Handle all base registers here, not just fp/ap/sp, because on some
4380      targets (namely SH) we can also get too large displacements from
4381      big-endian corrections.  */
4382   else if (GET_CODE (ad) == PLUS
4383            && GET_CODE (XEXP (ad, 0)) == REG
4384            && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER
4385            && REG_MODE_OK_FOR_BASE_P (XEXP (ad, 0), mode)
4386            && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4387     {
4388       /* Unshare the MEM rtx so we can safely alter it.  */
4389       if (memrefloc)
4390         {
4391           *memrefloc = copy_rtx (*memrefloc);
4392           loc = &XEXP (*memrefloc, 0);
4393         }
4394       if (double_reg_address_ok)
4395         {
4396           /* Unshare the sum as well.  */
4397           *loc = ad = copy_rtx (ad);
4398           /* Reload the displacement into an index reg.
4399              We assume the frame pointer or arg pointer is a base reg.  */
4400           find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4401                                      reload_address_index_reg_class,
4402                                      GET_MODE (ad), opnum, type, ind_levels);
4403         }
4404       else
4405         {
4406           /* If the sum of two regs is not necessarily valid,
4407              reload the sum into a base reg.
4408              That will at least work.  */
4409           find_reloads_address_part (ad, loc, reload_address_base_reg_class,
4410                                      Pmode, opnum, type, ind_levels);
4411         }
4412       return 1;
4413     }
4414
4415   /* If we have an indexed stack slot, there are three possible reasons why
4416      it might be invalid: The index might need to be reloaded, the address
4417      might have been made by frame pointer elimination and hence have a
4418      constant out of range, or both reasons might apply.  
4419
4420      We can easily check for an index needing reload, but even if that is the
4421      case, we might also have an invalid constant.  To avoid making the
4422      conservative assumption and requiring two reloads, we see if this address
4423      is valid when not interpreted strictly.  If it is, the only problem is
4424      that the index needs a reload and find_reloads_address_1 will take care
4425      of it.
4426
4427      There is still a case when we might generate an extra reload,
4428      however.  In certain cases eliminate_regs will return a MEM for a REG
4429      (see the code there for details).  In those cases, memory_address_p
4430      applied to our address will return 0 so we will think that our offset
4431      must be too large.  But it might indeed be valid and the only problem
4432      is that a MEM is present where a REG should be.  This case should be
4433      very rare and there doesn't seem to be any way to avoid it.
4434
4435      If we decide to do something here, it must be that
4436      `double_reg_address_ok' is true and that this address rtl was made by
4437      eliminate_regs.  We generate a reload of the fp/sp/ap + constant and
4438      rework the sum so that the reload register will be added to the index.
4439      This is safe because we know the address isn't shared.
4440
4441      We check for fp/ap/sp as both the first and second operand of the
4442      innermost PLUS.  */
4443
4444   else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4445            && GET_CODE (XEXP (ad, 0)) == PLUS
4446            && (XEXP (XEXP (ad, 0), 0) == frame_pointer_rtx
4447 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
4448                || XEXP (XEXP (ad, 0), 0) == hard_frame_pointer_rtx
4449 #endif
4450 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4451                || XEXP (XEXP (ad, 0), 0) == arg_pointer_rtx
4452 #endif
4453                || XEXP (XEXP (ad, 0), 0) == stack_pointer_rtx)
4454            && ! memory_address_p (mode, ad))
4455     {
4456       *loc = ad = gen_rtx (PLUS, GET_MODE (ad),
4457                            plus_constant (XEXP (XEXP (ad, 0), 0),
4458                                           INTVAL (XEXP (ad, 1))),
4459                            XEXP (XEXP (ad, 0), 1));
4460       find_reloads_address_part (XEXP (ad, 0), &XEXP (ad, 0),
4461                                  reload_address_base_reg_class,
4462                                  GET_MODE (ad), opnum, type, ind_levels);
4463       find_reloads_address_1 (mode, XEXP (ad, 1), 1, &XEXP (ad, 1), opnum,
4464                               type, 0, insn);
4465
4466       return 1;
4467     }
4468                            
4469   else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4470            && GET_CODE (XEXP (ad, 0)) == PLUS
4471            && (XEXP (XEXP (ad, 0), 1) == frame_pointer_rtx
4472 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4473                || XEXP (XEXP (ad, 0), 1) == hard_frame_pointer_rtx
4474 #endif
4475 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4476                || XEXP (XEXP (ad, 0), 1) == arg_pointer_rtx
4477 #endif
4478                || XEXP (XEXP (ad, 0), 1) == stack_pointer_rtx)
4479            && ! memory_address_p (mode, ad))
4480     {
4481       *loc = ad = gen_rtx (PLUS, GET_MODE (ad),
4482                            XEXP (XEXP (ad, 0), 0),
4483                            plus_constant (XEXP (XEXP (ad, 0), 1),
4484                                           INTVAL (XEXP (ad, 1))));
4485       find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4486                                  reload_address_base_reg_class,
4487                                  GET_MODE (ad), opnum, type, ind_levels);
4488       find_reloads_address_1 (mode, XEXP (ad, 0), 1, &XEXP (ad, 0), opnum,
4489                               type, 0, insn);
4490
4491       return 1;
4492     }
4493                            
4494   /* See if address becomes valid when an eliminable register
4495      in a sum is replaced.  */
4496
4497   tem = ad;
4498   if (GET_CODE (ad) == PLUS)
4499     tem = subst_indexed_address (ad);
4500   if (tem != ad && strict_memory_address_p (mode, tem))
4501     {
4502       /* Ok, we win that way.  Replace any additional eliminable
4503          registers.  */
4504
4505       subst_reg_equivs_changed = 0;
4506       tem = subst_reg_equivs (tem);
4507
4508       /* Make sure that didn't make the address invalid again.  */
4509
4510       if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
4511         {
4512           *loc = tem;
4513           return 0;
4514         }
4515     }
4516
4517   /* If constants aren't valid addresses, reload the constant address
4518      into a register.  */
4519   if (CONSTANT_P (ad) && ! strict_memory_address_p (mode, ad))
4520     {
4521       /* If AD is in address in the constant pool, the MEM rtx may be shared.
4522          Unshare it so we can safely alter it.  */
4523       if (memrefloc && GET_CODE (ad) == SYMBOL_REF
4524           && CONSTANT_POOL_ADDRESS_P (ad))
4525         {
4526           *memrefloc = copy_rtx (*memrefloc);
4527           loc = &XEXP (*memrefloc, 0);
4528         }
4529
4530       find_reloads_address_part (ad, loc, reload_address_base_reg_class,
4531                                  Pmode, opnum, type,
4532                                  ind_levels);
4533       return 1;
4534     }
4535
4536   return find_reloads_address_1 (mode, ad, 0, loc, opnum, type, ind_levels,
4537                                  insn);
4538 }
4539 \f
4540 /* Find all pseudo regs appearing in AD
4541    that are eliminable in favor of equivalent values
4542    and do not have hard regs; replace them by their equivalents.  */
4543
4544 static rtx
4545 subst_reg_equivs (ad)
4546      rtx ad;
4547 {
4548   register RTX_CODE code = GET_CODE (ad);
4549   register int i;
4550   register char *fmt;
4551
4552   switch (code)
4553     {
4554     case HIGH:
4555     case CONST_INT:
4556     case CONST:
4557     case CONST_DOUBLE:
4558     case SYMBOL_REF:
4559     case LABEL_REF:
4560     case PC:
4561     case CC0:
4562       return ad;
4563
4564     case REG:
4565       {
4566         register int regno = REGNO (ad);
4567
4568         if (reg_equiv_constant[regno] != 0)
4569           {
4570             subst_reg_equivs_changed = 1;
4571             return reg_equiv_constant[regno];
4572           }
4573       }
4574       return ad;
4575
4576     case PLUS:
4577       /* Quickly dispose of a common case.  */
4578       if (XEXP (ad, 0) == frame_pointer_rtx
4579           && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4580         return ad;
4581     }
4582
4583   fmt = GET_RTX_FORMAT (code);
4584   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4585     if (fmt[i] == 'e')
4586       XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i));
4587   return ad;
4588 }
4589 \f
4590 /* Compute the sum of X and Y, making canonicalizations assumed in an
4591    address, namely: sum constant integers, surround the sum of two
4592    constants with a CONST, put the constant as the second operand, and
4593    group the constant on the outermost sum.
4594
4595    This routine assumes both inputs are already in canonical form.  */
4596
4597 rtx
4598 form_sum (x, y)
4599      rtx x, y;
4600 {
4601   rtx tem;
4602   enum machine_mode mode = GET_MODE (x);
4603
4604   if (mode == VOIDmode)
4605     mode = GET_MODE (y);
4606
4607   if (mode == VOIDmode)
4608     mode = Pmode;
4609
4610   if (GET_CODE (x) == CONST_INT)
4611     return plus_constant (y, INTVAL (x));
4612   else if (GET_CODE (y) == CONST_INT)
4613     return plus_constant (x, INTVAL (y));
4614   else if (CONSTANT_P (x))
4615     tem = x, x = y, y = tem;
4616
4617   if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
4618     return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y));
4619
4620   /* Note that if the operands of Y are specified in the opposite
4621      order in the recursive calls below, infinite recursion will occur.  */
4622   if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
4623     return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1));
4624
4625   /* If both constant, encapsulate sum.  Otherwise, just form sum.  A
4626      constant will have been placed second.  */
4627   if (CONSTANT_P (x) && CONSTANT_P (y))
4628     {
4629       if (GET_CODE (x) == CONST)
4630         x = XEXP (x, 0);
4631       if (GET_CODE (y) == CONST)
4632         y = XEXP (y, 0);
4633
4634       return gen_rtx (CONST, VOIDmode, gen_rtx (PLUS, mode, x, y));
4635     }
4636
4637   return gen_rtx (PLUS, mode, x, y);
4638 }
4639 \f
4640 /* If ADDR is a sum containing a pseudo register that should be
4641    replaced with a constant (from reg_equiv_constant),
4642    return the result of doing so, and also apply the associative
4643    law so that the result is more likely to be a valid address.
4644    (But it is not guaranteed to be one.)
4645
4646    Note that at most one register is replaced, even if more are
4647    replaceable.  Also, we try to put the result into a canonical form
4648    so it is more likely to be a valid address.
4649
4650    In all other cases, return ADDR.  */
4651
4652 static rtx
4653 subst_indexed_address (addr)
4654      rtx addr;
4655 {
4656   rtx op0 = 0, op1 = 0, op2 = 0;
4657   rtx tem;
4658   int regno;
4659
4660   if (GET_CODE (addr) == PLUS)
4661     {
4662       /* Try to find a register to replace.  */
4663       op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0;
4664       if (GET_CODE (op0) == REG
4665           && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER
4666           && reg_renumber[regno] < 0
4667           && reg_equiv_constant[regno] != 0)
4668         op0 = reg_equiv_constant[regno];
4669       else if (GET_CODE (op1) == REG
4670           && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER
4671           && reg_renumber[regno] < 0
4672           && reg_equiv_constant[regno] != 0)
4673         op1 = reg_equiv_constant[regno];
4674       else if (GET_CODE (op0) == PLUS
4675                && (tem = subst_indexed_address (op0)) != op0)
4676         op0 = tem;
4677       else if (GET_CODE (op1) == PLUS
4678                && (tem = subst_indexed_address (op1)) != op1)
4679         op1 = tem;
4680       else
4681         return addr;
4682
4683       /* Pick out up to three things to add.  */
4684       if (GET_CODE (op1) == PLUS)
4685         op2 = XEXP (op1, 1), op1 = XEXP (op1, 0);
4686       else if (GET_CODE (op0) == PLUS)
4687         op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
4688
4689       /* Compute the sum.  */
4690       if (op2 != 0)
4691         op1 = form_sum (op1, op2);
4692       if (op1 != 0)
4693         op0 = form_sum (op0, op1);
4694
4695       return op0;
4696     }
4697   return addr;
4698 }
4699 \f
4700 /* Record the pseudo registers we must reload into hard registers in a
4701    subexpression of a would-be memory address, X referring to a value
4702    in mode MODE.  (This function is not called if the address we find
4703    is strictly valid.)
4704
4705    CONTEXT = 1 means we are considering regs as index regs,
4706    = 0 means we are considering them as base regs.
4707
4708    OPNUM and TYPE specify the purpose of any reloads made.
4709
4710    IND_LEVELS says how many levels of indirect addressing are
4711    supported at this point in the address.
4712
4713    INSN, if nonzero, is the insn in which we do the reload.  It is used
4714    to determine if we may generate output reloads.
4715
4716    We return nonzero if X, as a whole, is reloaded or replaced.  */
4717
4718 /* Note that we take shortcuts assuming that no multi-reg machine mode
4719    occurs as part of an address.
4720    Also, this is not fully machine-customizable; it works for machines
4721    such as vaxes and 68000's and 32000's, but other possible machines
4722    could have addressing modes that this does not handle right.  */
4723
4724 static int
4725 find_reloads_address_1 (mode, x, context, loc, opnum, type, ind_levels, insn)
4726      enum machine_mode mode;
4727      rtx x;
4728      int context;
4729      rtx *loc;
4730      int opnum;
4731      enum reload_type type;
4732      int ind_levels;
4733      rtx insn;
4734 {
4735   register RTX_CODE code = GET_CODE (x);
4736
4737   switch (code)
4738     {
4739     case PLUS:
4740       {
4741         register rtx orig_op0 = XEXP (x, 0);
4742         register rtx orig_op1 = XEXP (x, 1);
4743         register RTX_CODE code0 = GET_CODE (orig_op0);
4744         register RTX_CODE code1 = GET_CODE (orig_op1);
4745         register rtx op0 = orig_op0;
4746         register rtx op1 = orig_op1;
4747
4748         if (GET_CODE (op0) == SUBREG)
4749           {
4750             op0 = SUBREG_REG (op0);
4751             code0 = GET_CODE (op0);
4752             if (code0 == REG && REGNO (op0) < FIRST_PSEUDO_REGISTER)
4753               op0 = gen_rtx (REG, word_mode,
4754                              REGNO (op0) + SUBREG_WORD (orig_op0));
4755           }
4756
4757         if (GET_CODE (op1) == SUBREG)
4758           {
4759             op1 = SUBREG_REG (op1);
4760             code1 = GET_CODE (op1);
4761             if (code1 == REG && REGNO (op1) < FIRST_PSEUDO_REGISTER)
4762               op1 = gen_rtx (REG, GET_MODE (op1),
4763                              REGNO (op1) + SUBREG_WORD (orig_op1));
4764           }
4765
4766         if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE 
4767             || code0 == ZERO_EXTEND || code1 == MEM)
4768           {
4769             find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4770                                     type, ind_levels, insn);
4771             find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4772                                     type, ind_levels, insn);
4773           }
4774
4775         else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
4776                  || code1 == ZERO_EXTEND || code0 == MEM)
4777           {
4778             find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4779                                     type, ind_levels, insn);
4780             find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
4781                                     type, ind_levels, insn);
4782           }
4783
4784         else if (code0 == CONST_INT || code0 == CONST
4785                  || code0 == SYMBOL_REF || code0 == LABEL_REF)
4786           find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4787                                   type, ind_levels, insn);
4788
4789         else if (code1 == CONST_INT || code1 == CONST
4790                  || code1 == SYMBOL_REF || code1 == LABEL_REF)
4791           find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4792                                   type, ind_levels, insn);
4793
4794         else if (code0 == REG && code1 == REG)
4795           {
4796             if (REG_OK_FOR_INDEX_P (op0)
4797                 && REG_MODE_OK_FOR_BASE_P (op1, mode))
4798               return 0;
4799             else if (REG_OK_FOR_INDEX_P (op1)
4800                      && REG_MODE_OK_FOR_BASE_P (op0, mode))
4801               return 0;
4802             else if (REG_MODE_OK_FOR_BASE_P (op1, mode))
4803               find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4804                                       type, ind_levels, insn);
4805             else if (REG_MODE_OK_FOR_BASE_P (op0, mode))
4806               find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
4807                                       type, ind_levels, insn);
4808             else if (REG_OK_FOR_INDEX_P (op1))
4809               find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4810                                       type, ind_levels, insn);
4811             else if (REG_OK_FOR_INDEX_P (op0))
4812               find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4813                                       type, ind_levels, insn);
4814             else
4815               {
4816                 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4817                                         type, ind_levels, insn);
4818                 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4819                                         type, ind_levels, insn);
4820               }
4821           }
4822
4823         else if (code0 == REG)
4824           {
4825             find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4826                                     type, ind_levels, insn);
4827             find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4828                                     type, ind_levels, insn);
4829           }
4830
4831         else if (code1 == REG)
4832           {
4833             find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
4834                                     type, ind_levels, insn);
4835             find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4836                                     type, ind_levels, insn);
4837           }
4838       }
4839
4840       return 0;
4841
4842     case POST_INC:
4843     case POST_DEC:
4844     case PRE_INC:
4845     case PRE_DEC:
4846       if (GET_CODE (XEXP (x, 0)) == REG)
4847         {
4848           register int regno = REGNO (XEXP (x, 0));
4849           int value = 0;
4850           rtx x_orig = x;
4851
4852           /* A register that is incremented cannot be constant!  */
4853           if (regno >= FIRST_PSEUDO_REGISTER
4854               && reg_equiv_constant[regno] != 0)
4855             abort ();
4856
4857           /* Handle a register that is equivalent to a memory location
4858              which cannot be addressed directly.  */
4859           if (reg_equiv_address[regno] != 0)
4860             {
4861               rtx tem = make_memloc (XEXP (x, 0), regno);
4862               /* First reload the memory location's address.
4863                  We can't use ADDR_TYPE (type) here, because we need to
4864                  write back the value after reading it, hence we actually
4865                  need two registers.  */
4866               find_reloads_address (GET_MODE (tem), 0, XEXP (tem, 0),
4867                                     &XEXP (tem, 0), opnum, type,
4868                                     ind_levels, insn);
4869               /* Put this inside a new increment-expression.  */
4870               x = gen_rtx (GET_CODE (x), GET_MODE (x), tem);
4871               /* Proceed to reload that, as if it contained a register.  */
4872             }
4873
4874           /* If we have a hard register that is ok as an index,
4875              don't make a reload.  If an autoincrement of a nice register
4876              isn't "valid", it must be that no autoincrement is "valid".
4877              If that is true and something made an autoincrement anyway,
4878              this must be a special context where one is allowed.
4879              (For example, a "push" instruction.)
4880              We can't improve this address, so leave it alone.  */
4881
4882           /* Otherwise, reload the autoincrement into a suitable hard reg
4883              and record how much to increment by.  */
4884
4885           if (reg_renumber[regno] >= 0)
4886             regno = reg_renumber[regno];
4887           if ((regno >= FIRST_PSEUDO_REGISTER
4888                || !(context ? REGNO_OK_FOR_INDEX_P (regno)
4889                     : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
4890             {
4891               register rtx link;
4892               int reloadnum;
4893
4894               /* If we can output the register afterwards, do so, this
4895                  saves the extra update.
4896                  We can do so if we have an INSN - i.e. no JUMP_INSN nor
4897                  CALL_INSN - and it does not set CC0.
4898                  But don't do this if we cannot directly address the
4899                  memory location, since this will make it harder to
4900                  reuse address reloads, and increses register pressure.
4901                  Also don't do this if we can probably update x directly.  */
4902               rtx equiv = reg_equiv_mem[regno];
4903               int icode = (int) add_optab->handlers[(int) Pmode].insn_code;
4904               if (insn && GET_CODE (insn) == INSN && equiv
4905 #ifdef HAVE_cc0
4906                   && ! sets_cc0_p (PATTERN (insn))
4907 #endif
4908                   && ! (icode != CODE_FOR_nothing
4909                         && (*insn_operand_predicate[icode][0]) (equiv, Pmode)
4910                         && (*insn_operand_predicate[icode][1]) (equiv, Pmode)))
4911                 {
4912                   loc = &XEXP (x, 0);
4913                   x = XEXP (x, 0);
4914                   reloadnum
4915                     = push_reload (x, x, loc, loc,
4916                                    (context
4917                                     ? reload_address_index_reg_class
4918                                     : reload_address_base_reg_class),
4919                                     GET_MODE (x), GET_MODE (x), VOIDmode, 0,
4920                                     opnum, RELOAD_OTHER);
4921                 }
4922               else
4923                 {
4924                   reloadnum
4925                     = push_reload (x, NULL_RTX, loc, NULL_PTR,
4926                                    (context
4927                                     ? reload_address_index_reg_class
4928                                     : reload_address_base_reg_class),
4929                                    GET_MODE (x), GET_MODE (x), VOIDmode, 0,
4930                                    opnum, type);
4931                   reload_inc[reloadnum]
4932                     = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0));
4933     
4934                   value = 1;
4935                 }
4936
4937 #ifdef AUTO_INC_DEC
4938               /* Update the REG_INC notes.  */
4939
4940               for (link = REG_NOTES (this_insn);
4941                    link; link = XEXP (link, 1))
4942                 if (REG_NOTE_KIND (link) == REG_INC
4943                     && REGNO (XEXP (link, 0)) == REGNO (XEXP (x_orig, 0)))
4944                   push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
4945 #endif
4946             }
4947           return value;
4948         }
4949
4950       else if (GET_CODE (XEXP (x, 0)) == MEM)
4951         {
4952           /* This is probably the result of a substitution, by eliminate_regs,
4953              of an equivalent address for a pseudo that was not allocated to a
4954              hard register.  Verify that the specified address is valid and
4955              reload it into a register.  */
4956           rtx tem = XEXP (x, 0);
4957           register rtx link;
4958           int reloadnum;
4959
4960           /* Since we know we are going to reload this item, don't decrement
4961              for the indirection level.
4962
4963              Note that this is actually conservative:  it would be slightly
4964              more efficient to use the value of SPILL_INDIRECT_LEVELS from
4965              reload1.c here.  */
4966           /* We can't use ADDR_TYPE (type) here, because we need to
4967              write back the value after reading it, hence we actually
4968              need two registers.  */
4969           find_reloads_address (GET_MODE (x), &XEXP (x, 0),
4970                                 XEXP (XEXP (x, 0), 0), &XEXP (XEXP (x, 0), 0),
4971                                 opnum, type, ind_levels, insn);
4972
4973           reloadnum = push_reload (x, NULL_RTX, loc, NULL_PTR,
4974                                    (context
4975                                     ? reload_address_index_reg_class
4976                                     : reload_address_base_reg_class),
4977                                    GET_MODE (x), VOIDmode, 0, 0, opnum, type);
4978           reload_inc[reloadnum]
4979             = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
4980
4981           link = FIND_REG_INC_NOTE (this_insn, tem);
4982           if (link != 0)
4983             push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
4984
4985           return 1;
4986         }
4987       return 0;
4988
4989     case MEM:
4990       /* This is probably the result of a substitution, by eliminate_regs, of
4991          an equivalent address for a pseudo that was not allocated to a hard
4992          register.  Verify that the specified address is valid and reload it
4993          into a register.
4994
4995          Since we know we are going to reload this item, don't decrement for
4996          the indirection level.
4997
4998          Note that this is actually conservative:  it would be slightly more
4999          efficient to use the value of SPILL_INDIRECT_LEVELS from
5000          reload1.c here.  */
5001
5002       find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5003                             opnum, ADDR_TYPE (type), ind_levels, insn);
5004       push_reload (*loc, NULL_RTX, loc, NULL_PTR,
5005                    (context ? reload_address_index_reg_class
5006                     : reload_address_base_reg_class),
5007                    GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5008       return 1;
5009
5010     case REG:
5011       {
5012         register int regno = REGNO (x);
5013
5014         if (reg_equiv_constant[regno] != 0)
5015           {
5016             find_reloads_address_part (reg_equiv_constant[regno], loc, 
5017                                        (context
5018                                         ? reload_address_index_reg_class
5019                                         : reload_address_base_reg_class),
5020                                        GET_MODE (x), opnum, type, ind_levels);
5021             return 1;
5022           }
5023
5024 #if 0 /* This might screw code in reload1.c to delete prior output-reload
5025          that feeds this insn.  */
5026         if (reg_equiv_mem[regno] != 0)
5027           {
5028             push_reload (reg_equiv_mem[regno], NULL_RTX, loc, NULL_PTR,
5029                          (context
5030                           ? reload_address_index_reg_class
5031                           : reload_address_base_reg_class),
5032                          GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5033             return 1;
5034           }
5035 #endif
5036
5037         if (reg_equiv_address[regno] != 0)
5038           {
5039             x = make_memloc (x, regno);
5040             find_reloads_address (GET_MODE (x), 0, XEXP (x, 0), &XEXP (x, 0),
5041                                   opnum, ADDR_TYPE (type), ind_levels, insn);
5042           }
5043
5044         if (reg_renumber[regno] >= 0)
5045           regno = reg_renumber[regno];
5046
5047         if ((regno >= FIRST_PSEUDO_REGISTER
5048              || !(context ? REGNO_OK_FOR_INDEX_P (regno)
5049                   : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
5050           {
5051             push_reload (x, NULL_RTX, loc, NULL_PTR,
5052                          (context
5053                           ? reload_address_index_reg_class
5054                           : reload_address_base_reg_class),
5055                          GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5056             return 1;
5057           }
5058
5059         /* If a register appearing in an address is the subject of a CLOBBER
5060            in this insn, reload it into some other register to be safe.
5061            The CLOBBER is supposed to make the register unavailable
5062            from before this insn to after it.  */
5063         if (regno_clobbered_p (regno, this_insn))
5064           {
5065             push_reload (x, NULL_RTX, loc, NULL_PTR,
5066                          (context
5067                           ? reload_address_index_reg_class
5068                           : reload_address_base_reg_class),
5069                          GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5070             return 1;
5071           }
5072       }
5073       return 0;
5074
5075     case SUBREG:
5076       if (GET_CODE (SUBREG_REG (x)) == REG)
5077         {
5078           /* If this is a SUBREG of a hard register and the resulting register
5079              is of the wrong class, reload the whole SUBREG.  This avoids
5080              needless copies if SUBREG_REG is multi-word.  */
5081           if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5082             {
5083               int regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
5084
5085               if (! (context ? REGNO_OK_FOR_INDEX_P (regno)
5086                      : REGNO_MODE_OK_FOR_BASE_P (regno, mode)))
5087                 {
5088                   push_reload (x, NULL_RTX, loc, NULL_PTR,
5089                                (context
5090                                 ? reload_address_index_reg_class
5091                                 : reload_address_base_reg_class),
5092                                GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5093                   return 1;
5094                 }
5095             }
5096           /* If this is a SUBREG of a pseudo-register, and the pseudo-register
5097              is larger than the class size, then reload the whole SUBREG.  */
5098           else
5099             {
5100               enum reg_class class = (context
5101                                       ? reload_address_index_reg_class
5102                                       : reload_address_base_reg_class);
5103               if (CLASS_MAX_NREGS (class, GET_MODE (SUBREG_REG (x)))
5104                   > reg_class_size[class])
5105                 {
5106                   push_reload (x, NULL_RTX, loc, NULL_PTR, class,
5107                                GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5108                   return 1;
5109                 }
5110             }
5111         }
5112       break;
5113     }
5114
5115   {
5116     register char *fmt = GET_RTX_FORMAT (code);
5117     register int i;
5118
5119     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5120       {
5121         if (fmt[i] == 'e')
5122           find_reloads_address_1 (mode, XEXP (x, i), context, &XEXP (x, i),
5123                                   opnum, type, ind_levels, insn);
5124       }
5125   }
5126
5127   return 0;
5128 }
5129 \f
5130 /* X, which is found at *LOC, is a part of an address that needs to be
5131    reloaded into a register of class CLASS.  If X is a constant, or if
5132    X is a PLUS that contains a constant, check that the constant is a
5133    legitimate operand and that we are supposed to be able to load
5134    it into the register.
5135
5136    If not, force the constant into memory and reload the MEM instead.
5137
5138    MODE is the mode to use, in case X is an integer constant.
5139
5140    OPNUM and TYPE describe the purpose of any reloads made.
5141
5142    IND_LEVELS says how many levels of indirect addressing this machine
5143    supports.  */
5144
5145 static void
5146 find_reloads_address_part (x, loc, class, mode, opnum, type, ind_levels)
5147      rtx x;
5148      rtx *loc;
5149      enum reg_class class;
5150      enum machine_mode mode;
5151      int opnum;
5152      enum reload_type type;
5153      int ind_levels;
5154 {
5155   if (CONSTANT_P (x)
5156       && (! LEGITIMATE_CONSTANT_P (x)
5157           || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
5158     {
5159       rtx tem = x = force_const_mem (mode, x);
5160       find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5161                             opnum, type, ind_levels, 0);
5162     }
5163
5164   else if (GET_CODE (x) == PLUS
5165            && CONSTANT_P (XEXP (x, 1))
5166            && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
5167                || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
5168     {
5169       rtx tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
5170
5171       x = gen_rtx (PLUS, GET_MODE (x), XEXP (x, 0), tem);
5172       find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5173                             opnum, type, ind_levels, 0);
5174     }
5175
5176   push_reload (x, NULL_RTX, loc, NULL_PTR, class,
5177                mode, VOIDmode, 0, 0, opnum, type);
5178 }
5179 \f
5180 /* Substitute into the current INSN the registers into which we have reloaded
5181    the things that need reloading.  The array `replacements'
5182    says contains the locations of all pointers that must be changed
5183    and says what to replace them with.
5184
5185    Return the rtx that X translates into; usually X, but modified.  */
5186
5187 void
5188 subst_reloads ()
5189 {
5190   register int i;
5191
5192   for (i = 0; i < n_replacements; i++)
5193     {
5194       register struct replacement *r = &replacements[i];
5195       register rtx reloadreg = reload_reg_rtx[r->what];
5196       if (reloadreg)
5197         {
5198           /* Encapsulate RELOADREG so its machine mode matches what
5199              used to be there.  Note that gen_lowpart_common will
5200              do the wrong thing if RELOADREG is multi-word.  RELOADREG
5201              will always be a REG here.  */
5202           if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
5203             reloadreg = gen_rtx (REG, r->mode, REGNO (reloadreg));
5204
5205           /* If we are putting this into a SUBREG and RELOADREG is a
5206              SUBREG, we would be making nested SUBREGs, so we have to fix
5207              this up.  Note that r->where == &SUBREG_REG (*r->subreg_loc).  */
5208
5209           if (r->subreg_loc != 0 && GET_CODE (reloadreg) == SUBREG)
5210             {
5211               if (GET_MODE (*r->subreg_loc)
5212                   == GET_MODE (SUBREG_REG (reloadreg)))
5213                 *r->subreg_loc = SUBREG_REG (reloadreg);
5214               else
5215                 {
5216                   *r->where = SUBREG_REG (reloadreg);
5217                   SUBREG_WORD (*r->subreg_loc) += SUBREG_WORD (reloadreg);
5218                 }
5219             }
5220           else
5221             *r->where = reloadreg;
5222         }
5223       /* If reload got no reg and isn't optional, something's wrong.  */
5224       else if (! reload_optional[r->what])
5225         abort ();
5226     }
5227 }
5228 \f
5229 /* Make a copy of any replacements being done into X and move those copies
5230    to locations in Y, a copy of X.  We only look at the highest level of
5231    the RTL.  */
5232
5233 void
5234 copy_replacements (x, y)
5235      rtx x;
5236      rtx y;
5237 {
5238   int i, j;
5239   enum rtx_code code = GET_CODE (x);
5240   char *fmt = GET_RTX_FORMAT (code);
5241   struct replacement *r;
5242
5243   /* We can't support X being a SUBREG because we might then need to know its
5244      location if something inside it was replaced.  */
5245   if (code == SUBREG)
5246     abort ();
5247
5248   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5249     if (fmt[i] == 'e')
5250       for (j = 0; j < n_replacements; j++)
5251         {
5252           if (replacements[j].subreg_loc == &XEXP (x, i))
5253             {
5254               r = &replacements[n_replacements++];
5255               r->where = replacements[j].where;
5256               r->subreg_loc = &XEXP (y, i);
5257               r->what = replacements[j].what;
5258               r->mode = replacements[j].mode;
5259             }
5260           else if (replacements[j].where == &XEXP (x, i))
5261             {
5262               r = &replacements[n_replacements++];
5263               r->where = &XEXP (y, i);
5264               r->subreg_loc = 0;
5265               r->what = replacements[j].what;
5266               r->mode = replacements[j].mode;
5267             }
5268         }
5269 }
5270 \f
5271 /* If LOC was scheduled to be replaced by something, return the replacement.
5272    Otherwise, return *LOC.  */
5273
5274 rtx
5275 find_replacement (loc)
5276      rtx *loc;
5277 {
5278   struct replacement *r;
5279
5280   for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
5281     {
5282       rtx reloadreg = reload_reg_rtx[r->what];
5283
5284       if (reloadreg && r->where == loc)
5285         {
5286           if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
5287             reloadreg = gen_rtx (REG, r->mode, REGNO (reloadreg));
5288
5289           return reloadreg;
5290         }
5291       else if (reloadreg && r->subreg_loc == loc)
5292         {
5293           /* RELOADREG must be either a REG or a SUBREG.
5294
5295              ??? Is it actually still ever a SUBREG?  If so, why?  */
5296
5297           if (GET_CODE (reloadreg) == REG)
5298             return gen_rtx (REG, GET_MODE (*loc),
5299                             REGNO (reloadreg) + SUBREG_WORD (*loc));
5300           else if (GET_MODE (reloadreg) == GET_MODE (*loc))
5301             return reloadreg;
5302           else
5303             return gen_rtx (SUBREG, GET_MODE (*loc), SUBREG_REG (reloadreg),
5304                             SUBREG_WORD (reloadreg) + SUBREG_WORD (*loc));
5305         }
5306     }
5307
5308   return *loc;
5309 }
5310 \f
5311 /* Return nonzero if register in range [REGNO, ENDREGNO)
5312    appears either explicitly or implicitly in X
5313    other than being stored into (except for earlyclobber operands).
5314
5315    References contained within the substructure at LOC do not count.
5316    LOC may be zero, meaning don't ignore anything.
5317
5318    This is similar to refers_to_regno_p in rtlanal.c except that we
5319    look at equivalences for pseudos that didn't get hard registers.  */
5320
5321 int
5322 refers_to_regno_for_reload_p (regno, endregno, x, loc)
5323      int regno, endregno;
5324      rtx x;
5325      rtx *loc;
5326 {
5327   register int i;
5328   register RTX_CODE code;
5329   register char *fmt;
5330
5331   if (x == 0)
5332     return 0;
5333
5334  repeat:
5335   code = GET_CODE (x);
5336
5337   switch (code)
5338     {
5339     case REG:
5340       i = REGNO (x);
5341
5342       /* If this is a pseudo, a hard register must not have been allocated.
5343          X must therefore either be a constant or be in memory.  */
5344       if (i >= FIRST_PSEUDO_REGISTER)
5345         {
5346           if (reg_equiv_memory_loc[i])
5347             return refers_to_regno_for_reload_p (regno, endregno,
5348                                                  reg_equiv_memory_loc[i],
5349                                                  NULL_PTR);
5350
5351           if (reg_equiv_constant[i])
5352             return 0;
5353
5354           abort ();
5355         }
5356
5357       return (endregno > i
5358               && regno < i + (i < FIRST_PSEUDO_REGISTER 
5359                               ? HARD_REGNO_NREGS (i, GET_MODE (x))
5360                               : 1));
5361
5362     case SUBREG:
5363       /* If this is a SUBREG of a hard reg, we can see exactly which
5364          registers are being modified.  Otherwise, handle normally.  */
5365       if (GET_CODE (SUBREG_REG (x)) == REG
5366           && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5367         {
5368           int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
5369           int inner_endregno
5370             = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
5371                              ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
5372
5373           return endregno > inner_regno && regno < inner_endregno;
5374         }
5375       break;
5376
5377     case CLOBBER:
5378     case SET:
5379       if (&SET_DEST (x) != loc
5380           /* Note setting a SUBREG counts as referring to the REG it is in for
5381              a pseudo but not for hard registers since we can
5382              treat each word individually.  */
5383           && ((GET_CODE (SET_DEST (x)) == SUBREG
5384                && loc != &SUBREG_REG (SET_DEST (x))
5385                && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
5386                && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
5387                && refers_to_regno_for_reload_p (regno, endregno,
5388                                                 SUBREG_REG (SET_DEST (x)),
5389                                                 loc))
5390               /* If the output is an earlyclobber operand, this is
5391                  a conflict.  */
5392               || ((GET_CODE (SET_DEST (x)) != REG
5393                    || earlyclobber_operand_p (SET_DEST (x)))
5394                   && refers_to_regno_for_reload_p (regno, endregno,
5395                                                    SET_DEST (x), loc))))
5396         return 1;
5397
5398       if (code == CLOBBER || loc == &SET_SRC (x))
5399         return 0;
5400       x = SET_SRC (x);
5401       goto repeat;
5402     }
5403
5404   /* X does not match, so try its subexpressions.  */
5405
5406   fmt = GET_RTX_FORMAT (code);
5407   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5408     {
5409       if (fmt[i] == 'e' && loc != &XEXP (x, i))
5410         {
5411           if (i == 0)
5412             {
5413               x = XEXP (x, 0);
5414               goto repeat;
5415             }
5416           else
5417             if (refers_to_regno_for_reload_p (regno, endregno,
5418                                               XEXP (x, i), loc))
5419               return 1;
5420         }
5421       else if (fmt[i] == 'E')
5422         {
5423           register int j;
5424           for (j = XVECLEN (x, i) - 1; j >=0; j--)
5425             if (loc != &XVECEXP (x, i, j)
5426                 && refers_to_regno_for_reload_p (regno, endregno,
5427                                                  XVECEXP (x, i, j), loc))
5428               return 1;
5429         }
5430     }
5431   return 0;
5432 }
5433
5434 /* Nonzero if modifying X will affect IN.  If X is a register or a SUBREG,
5435    we check if any register number in X conflicts with the relevant register
5436    numbers.  If X is a constant, return 0.  If X is a MEM, return 1 iff IN
5437    contains a MEM (we don't bother checking for memory addresses that can't
5438    conflict because we expect this to be a rare case. 
5439
5440    This function is similar to reg_overlap_mention_p in rtlanal.c except
5441    that we look at equivalences for pseudos that didn't get hard registers.  */
5442
5443 int
5444 reg_overlap_mentioned_for_reload_p (x, in)
5445      rtx x, in;
5446 {
5447   int regno, endregno;
5448
5449   if (GET_CODE (x) == SUBREG)
5450     {
5451       regno = REGNO (SUBREG_REG (x));
5452       if (regno < FIRST_PSEUDO_REGISTER)
5453         regno += SUBREG_WORD (x);
5454     }
5455   else if (GET_CODE (x) == REG)
5456     {
5457       regno = REGNO (x);
5458
5459       /* If this is a pseudo, it must not have been assigned a hard register.
5460          Therefore, it must either be in memory or be a constant.  */
5461
5462       if (regno >= FIRST_PSEUDO_REGISTER)
5463         {
5464           if (reg_equiv_memory_loc[regno])
5465             return refers_to_mem_for_reload_p (in);
5466           else if (reg_equiv_constant[regno])
5467             return 0;
5468           abort ();
5469         }
5470     }
5471   else if (CONSTANT_P (x))
5472     return 0;
5473   else if (GET_CODE (x) == MEM)
5474     return refers_to_mem_for_reload_p (in);
5475   else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
5476            || GET_CODE (x) == CC0)
5477     return reg_mentioned_p (x, in);
5478   else
5479     abort ();
5480
5481   endregno = regno + (regno < FIRST_PSEUDO_REGISTER
5482                       ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
5483
5484   return refers_to_regno_for_reload_p (regno, endregno, in, NULL_PTR);
5485 }
5486
5487 /* Return nonzero if anything in X contains a MEM.  Look also for pseudo
5488    registers.  */
5489
5490 int
5491 refers_to_mem_for_reload_p (x)
5492      rtx x;
5493 {
5494   char *fmt;
5495   int i;
5496
5497   if (GET_CODE (x) == MEM)
5498     return 1;
5499
5500   if (GET_CODE (x) == REG)
5501     return (REGNO (x) >= FIRST_PSEUDO_REGISTER
5502             && reg_equiv_memory_loc[REGNO (x)]);
5503                         
5504   fmt = GET_RTX_FORMAT (GET_CODE (x));
5505   for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
5506     if (fmt[i] == 'e'
5507         && (GET_CODE (XEXP (x, i)) == MEM
5508             || refers_to_mem_for_reload_p (XEXP (x, i))))
5509       return 1;
5510   
5511   return 0;
5512 }
5513 \f
5514 /* Check the insns before INSN to see if there is a suitable register
5515    containing the same value as GOAL.
5516    If OTHER is -1, look for a register in class CLASS.
5517    Otherwise, just see if register number OTHER shares GOAL's value.
5518
5519    Return an rtx for the register found, or zero if none is found.
5520
5521    If RELOAD_REG_P is (short *)1,
5522    we reject any hard reg that appears in reload_reg_rtx
5523    because such a hard reg is also needed coming into this insn.
5524
5525    If RELOAD_REG_P is any other nonzero value,
5526    it is a vector indexed by hard reg number
5527    and we reject any hard reg whose element in the vector is nonnegative
5528    as well as any that appears in reload_reg_rtx.
5529
5530    If GOAL is zero, then GOALREG is a register number; we look
5531    for an equivalent for that register.
5532
5533    MODE is the machine mode of the value we want an equivalence for.
5534    If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
5535
5536    This function is used by jump.c as well as in the reload pass.
5537
5538    If GOAL is the sum of the stack pointer and a constant, we treat it
5539    as if it were a constant except that sp is required to be unchanging.  */
5540
5541 rtx
5542 find_equiv_reg (goal, insn, class, other, reload_reg_p, goalreg, mode)
5543      register rtx goal;
5544      rtx insn;
5545      enum reg_class class;
5546      register int other;
5547      short *reload_reg_p;
5548      int goalreg;
5549      enum machine_mode mode;
5550 {
5551   register rtx p = insn;
5552   rtx goaltry, valtry, value, where;
5553   register rtx pat;
5554   register int regno = -1;
5555   int valueno;
5556   int goal_mem = 0;
5557   int goal_const = 0;
5558   int goal_mem_addr_varies = 0;
5559   int need_stable_sp = 0;
5560   int nregs;
5561   int valuenregs;
5562
5563   if (goal == 0)
5564     regno = goalreg;
5565   else if (GET_CODE (goal) == REG)
5566     regno = REGNO (goal);
5567   else if (GET_CODE (goal) == MEM)
5568     {
5569       enum rtx_code code = GET_CODE (XEXP (goal, 0));
5570       if (MEM_VOLATILE_P (goal))
5571         return 0;
5572       if (flag_float_store && GET_MODE_CLASS (GET_MODE (goal)) == MODE_FLOAT)
5573         return 0;
5574       /* An address with side effects must be reexecuted.  */
5575       switch (code)
5576         {
5577         case POST_INC:
5578         case PRE_INC:
5579         case POST_DEC:
5580         case PRE_DEC:
5581           return 0;
5582         }
5583       goal_mem = 1;
5584     }
5585   else if (CONSTANT_P (goal))
5586     goal_const = 1;
5587   else if (GET_CODE (goal) == PLUS
5588            && XEXP (goal, 0) == stack_pointer_rtx
5589            && CONSTANT_P (XEXP (goal, 1)))
5590     goal_const = need_stable_sp = 1;
5591   else
5592     return 0;
5593
5594   /* On some machines, certain regs must always be rejected
5595      because they don't behave the way ordinary registers do.  */
5596   
5597 #ifdef OVERLAPPING_REGNO_P
5598    if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5599        && OVERLAPPING_REGNO_P (regno))
5600      return 0;
5601 #endif      
5602
5603   /* Scan insns back from INSN, looking for one that copies
5604      a value into or out of GOAL.
5605      Stop and give up if we reach a label.  */
5606
5607   while (1)
5608     {
5609       p = PREV_INSN (p);
5610       if (p == 0 || GET_CODE (p) == CODE_LABEL)
5611         return 0;
5612       if (GET_CODE (p) == INSN
5613           /* If we don't want spill regs ...  */
5614           && (! (reload_reg_p != 0
5615                  && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
5616           /* ... then ignore insns introduced by reload; they aren't useful
5617              and can cause results in reload_as_needed to be different
5618              from what they were when calculating the need for spills.
5619              If we notice an input-reload insn here, we will reject it below,
5620              but it might hide a usable equivalent.  That makes bad code.
5621              It may even abort: perhaps no reg was spilled for this insn
5622              because it was assumed we would find that equivalent.  */
5623               || INSN_UID (p) < reload_first_uid))
5624         {
5625           rtx tem;
5626           pat = single_set (p);
5627           /* First check for something that sets some reg equal to GOAL.  */
5628           if (pat != 0
5629               && ((regno >= 0
5630                    && true_regnum (SET_SRC (pat)) == regno
5631                    && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
5632                   ||
5633                   (regno >= 0
5634                    && true_regnum (SET_DEST (pat)) == regno
5635                    && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0)
5636                   ||
5637                   (goal_const && rtx_equal_p (SET_SRC (pat), goal)
5638                    && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
5639                   || (goal_mem
5640                       && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0
5641                       && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
5642                   || (goal_mem
5643                       && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0
5644                       && rtx_renumbered_equal_p (goal, SET_DEST (pat)))
5645                   /* If we are looking for a constant,
5646                      and something equivalent to that constant was copied
5647                      into a reg, we can use that reg.  */
5648                   || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
5649                                                           NULL_RTX))
5650                       && rtx_equal_p (XEXP (tem, 0), goal)
5651                       && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
5652                   || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
5653                                                           NULL_RTX))
5654                       && GET_CODE (SET_DEST (pat)) == REG
5655                       && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
5656                       && GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) == MODE_FLOAT
5657                       && GET_CODE (goal) == CONST_INT
5658                       && 0 != (goaltry = operand_subword (XEXP (tem, 0), 0, 0,
5659                                                           VOIDmode))
5660                       && rtx_equal_p (goal, goaltry)
5661                       && (valtry = operand_subword (SET_DEST (pat), 0, 0,
5662                                                     VOIDmode))
5663                       && (valueno = true_regnum (valtry)) >= 0)
5664                   || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
5665                                                           NULL_RTX))
5666                       && GET_CODE (SET_DEST (pat)) == REG
5667                       && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
5668                       && GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) == MODE_FLOAT
5669                       && GET_CODE (goal) == CONST_INT
5670                       && 0 != (goaltry = operand_subword (XEXP (tem, 0), 1, 0,
5671                                                           VOIDmode))
5672                       && rtx_equal_p (goal, goaltry)
5673                       && (valtry
5674                           = operand_subword (SET_DEST (pat), 1, 0, VOIDmode))
5675                       && (valueno = true_regnum (valtry)) >= 0)))
5676             if (other >= 0
5677                 ? valueno == other
5678                 : ((unsigned) valueno < FIRST_PSEUDO_REGISTER
5679                    && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
5680                                          valueno)))
5681               {
5682                 value = valtry;
5683                 where = p;
5684                 break;
5685               }
5686         }
5687     }
5688
5689   /* We found a previous insn copying GOAL into a suitable other reg VALUE
5690      (or copying VALUE into GOAL, if GOAL is also a register).
5691      Now verify that VALUE is really valid.  */
5692
5693   /* VALUENO is the register number of VALUE; a hard register.  */
5694
5695   /* Don't try to re-use something that is killed in this insn.  We want
5696      to be able to trust REG_UNUSED notes.  */
5697   if (find_reg_note (where, REG_UNUSED, value))
5698     return 0;
5699
5700   /* If we propose to get the value from the stack pointer or if GOAL is
5701      a MEM based on the stack pointer, we need a stable SP.  */
5702   if (valueno == STACK_POINTER_REGNUM || regno == STACK_POINTER_REGNUM
5703       || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx,
5704                                                           goal)))
5705     need_stable_sp = 1;
5706
5707   /* Reject VALUE if the copy-insn moved the wrong sort of datum.  */
5708   if (GET_MODE (value) != mode)
5709     return 0;
5710
5711   /* Reject VALUE if it was loaded from GOAL
5712      and is also a register that appears in the address of GOAL.  */
5713
5714   if (goal_mem && value == SET_DEST (single_set (where))
5715       && refers_to_regno_for_reload_p (valueno,
5716                                        (valueno
5717                                         + HARD_REGNO_NREGS (valueno, mode)),
5718                                        goal, NULL_PTR))
5719     return 0;
5720
5721   /* Reject registers that overlap GOAL.  */
5722
5723   if (!goal_mem && !goal_const
5724       && regno + HARD_REGNO_NREGS (regno, mode) > valueno
5725       && regno < valueno + HARD_REGNO_NREGS (valueno, mode))
5726     return 0;
5727
5728   /* Reject VALUE if it is one of the regs reserved for reloads.
5729      Reload1 knows how to reuse them anyway, and it would get
5730      confused if we allocated one without its knowledge.
5731      (Now that insns introduced by reload are ignored above,
5732      this case shouldn't happen, but I'm not positive.)  */
5733
5734   if (reload_reg_p != 0 && reload_reg_p != (short *) (HOST_WIDE_INT) 1
5735       && reload_reg_p[valueno] >= 0)
5736     return 0;
5737
5738   /* On some machines, certain regs must always be rejected
5739      because they don't behave the way ordinary registers do.  */
5740   
5741 #ifdef OVERLAPPING_REGNO_P
5742   if (OVERLAPPING_REGNO_P (valueno))
5743     return 0;
5744 #endif      
5745
5746   nregs = HARD_REGNO_NREGS (regno, mode);
5747   valuenregs = HARD_REGNO_NREGS (valueno, mode);
5748
5749   /* Reject VALUE if it is a register being used for an input reload
5750      even if it is not one of those reserved.  */
5751
5752   if (reload_reg_p != 0)
5753     {
5754       int i;
5755       for (i = 0; i < n_reloads; i++)
5756         if (reload_reg_rtx[i] != 0 && reload_in[i])
5757           {
5758             int regno1 = REGNO (reload_reg_rtx[i]);
5759             int nregs1 = HARD_REGNO_NREGS (regno1,
5760                                            GET_MODE (reload_reg_rtx[i]));
5761             if (regno1 < valueno + valuenregs
5762                 && regno1 + nregs1 > valueno)
5763               return 0;
5764           }
5765     }
5766
5767   if (goal_mem)
5768     /* We must treat frame pointer as varying here,
5769        since it can vary--in a nonlocal goto as generated by expand_goto.  */
5770     goal_mem_addr_varies = !CONSTANT_ADDRESS_P (XEXP (goal, 0));
5771
5772   /* Now verify that the values of GOAL and VALUE remain unaltered
5773      until INSN is reached.  */
5774
5775   p = insn;
5776   while (1)
5777     {
5778       p = PREV_INSN (p);
5779       if (p == where)
5780         return value;
5781
5782       /* Don't trust the conversion past a function call
5783          if either of the two is in a call-clobbered register, or memory.  */
5784       if (GET_CODE (p) == CALL_INSN
5785           && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5786                && call_used_regs[regno])
5787               ||
5788               (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
5789                && call_used_regs[valueno])
5790               ||
5791               goal_mem
5792               || need_stable_sp))
5793         return 0;
5794
5795 #ifdef NON_SAVING_SETJMP 
5796       if (NON_SAVING_SETJMP && GET_CODE (p) == NOTE
5797           && NOTE_LINE_NUMBER (p) == NOTE_INSN_SETJMP)
5798         return 0;
5799 #endif
5800
5801 #ifdef INSN_CLOBBERS_REGNO_P
5802       if ((valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
5803           && INSN_CLOBBERS_REGNO_P (p, valueno))
5804           || (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5805           && INSN_CLOBBERS_REGNO_P (p, regno)))
5806         return 0;
5807 #endif
5808
5809       if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
5810         {
5811           /* If this insn P stores in either GOAL or VALUE, return 0.
5812              If GOAL is a memory ref and this insn writes memory, return 0.
5813              If GOAL is a memory ref and its address is not constant,
5814              and this insn P changes a register used in GOAL, return 0.  */
5815
5816           pat = PATTERN (p);
5817           if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
5818             {
5819               register rtx dest = SET_DEST (pat);
5820               while (GET_CODE (dest) == SUBREG
5821                      || GET_CODE (dest) == ZERO_EXTRACT
5822                      || GET_CODE (dest) == SIGN_EXTRACT
5823                      || GET_CODE (dest) == STRICT_LOW_PART)
5824                 dest = XEXP (dest, 0);
5825               if (GET_CODE (dest) == REG)
5826                 {
5827                   register int xregno = REGNO (dest);
5828                   int xnregs;
5829                   if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5830                     xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5831                   else
5832                     xnregs = 1;
5833                   if (xregno < regno + nregs && xregno + xnregs > regno)
5834                     return 0;
5835                   if (xregno < valueno + valuenregs
5836                       && xregno + xnregs > valueno)
5837                     return 0;
5838                   if (goal_mem_addr_varies
5839                       && reg_overlap_mentioned_for_reload_p (dest, goal))
5840                     return 0;
5841                 }
5842               else if (goal_mem && GET_CODE (dest) == MEM
5843                        && ! push_operand (dest, GET_MODE (dest)))
5844                 return 0;
5845               else if (GET_CODE (dest) == MEM && regno >= FIRST_PSEUDO_REGISTER
5846                        && reg_equiv_memory_loc[regno] != 0)
5847                 return 0;
5848               else if (need_stable_sp && push_operand (dest, GET_MODE (dest)))
5849                 return 0;
5850             }
5851           else if (GET_CODE (pat) == PARALLEL)
5852             {
5853               register int i;
5854               for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
5855                 {
5856                   register rtx v1 = XVECEXP (pat, 0, i);
5857                   if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
5858                     {
5859                       register rtx dest = SET_DEST (v1);
5860                       while (GET_CODE (dest) == SUBREG
5861                              || GET_CODE (dest) == ZERO_EXTRACT
5862                              || GET_CODE (dest) == SIGN_EXTRACT
5863                              || GET_CODE (dest) == STRICT_LOW_PART)
5864                         dest = XEXP (dest, 0);
5865                       if (GET_CODE (dest) == REG)
5866                         {
5867                           register int xregno = REGNO (dest);
5868                           int xnregs;
5869                           if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5870                             xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5871                           else
5872                             xnregs = 1;
5873                           if (xregno < regno + nregs
5874                               && 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,
5881                                                                      goal))
5882                             return 0;
5883                         }
5884                       else if (goal_mem && GET_CODE (dest) == MEM
5885                                && ! push_operand (dest, GET_MODE (dest)))
5886                         return 0;
5887                       else if (need_stable_sp
5888                                && push_operand (dest, GET_MODE (dest)))
5889                         return 0;
5890                     }
5891                 }
5892             }
5893
5894           if (GET_CODE (p) == CALL_INSN && CALL_INSN_FUNCTION_USAGE (p))
5895             {
5896               rtx link;
5897
5898               for (link = CALL_INSN_FUNCTION_USAGE (p); XEXP (link, 1) != 0;
5899                    link = XEXP (link, 1))
5900                 {
5901                   pat = XEXP (link, 0);
5902                   if (GET_CODE (pat) == CLOBBER)
5903                     {
5904                       register rtx dest = SET_DEST (pat);
5905                       while (GET_CODE (dest) == SUBREG
5906                              || GET_CODE (dest) == ZERO_EXTRACT
5907                              || GET_CODE (dest) == SIGN_EXTRACT
5908                              || GET_CODE (dest) == STRICT_LOW_PART)
5909                         dest = XEXP (dest, 0);
5910                       if (GET_CODE (dest) == REG)
5911                         {
5912                           register int xregno = REGNO (dest);
5913                           int xnregs;
5914                           if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5915                             xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5916                           else
5917                             xnregs = 1;
5918                           if (xregno < regno + nregs
5919                               && xregno + xnregs > regno)
5920                             return 0;
5921                           if (xregno < valueno + valuenregs
5922                               && xregno + xnregs > valueno)
5923                             return 0;
5924                           if (goal_mem_addr_varies
5925                               && reg_overlap_mentioned_for_reload_p (dest,
5926                                                                      goal))
5927                             return 0;
5928                         }
5929                       else if (goal_mem && GET_CODE (dest) == MEM
5930                                && ! push_operand (dest, GET_MODE (dest)))
5931                         return 0;
5932                       else if (need_stable_sp
5933                                && push_operand (dest, GET_MODE (dest)))
5934                         return 0;
5935                     }
5936                 }
5937             }
5938
5939 #ifdef AUTO_INC_DEC
5940           /* If this insn auto-increments or auto-decrements
5941              either regno or valueno, return 0 now.
5942              If GOAL is a memory ref and its address is not constant,
5943              and this insn P increments a register used in GOAL, return 0.  */
5944           {
5945             register rtx link;
5946
5947             for (link = REG_NOTES (p); link; link = XEXP (link, 1))
5948               if (REG_NOTE_KIND (link) == REG_INC
5949                   && GET_CODE (XEXP (link, 0)) == REG)
5950                 {
5951                   register int incno = REGNO (XEXP (link, 0));
5952                   if (incno < regno + nregs && incno >= regno)
5953                     return 0;
5954                   if (incno < valueno + valuenregs && incno >= valueno)
5955                     return 0;
5956                   if (goal_mem_addr_varies
5957                       && reg_overlap_mentioned_for_reload_p (XEXP (link, 0),
5958                                                              goal))
5959                     return 0;
5960                 }
5961           }
5962 #endif
5963         }
5964     }
5965 }
5966 \f
5967 /* Find a place where INCED appears in an increment or decrement operator
5968    within X, and return the amount INCED is incremented or decremented by.
5969    The value is always positive.  */
5970
5971 static int
5972 find_inc_amount (x, inced)
5973      rtx x, inced;
5974 {
5975   register enum rtx_code code = GET_CODE (x);
5976   register char *fmt;
5977   register int i;
5978
5979   if (code == MEM)
5980     {
5981       register rtx addr = XEXP (x, 0);
5982       if ((GET_CODE (addr) == PRE_DEC
5983            || GET_CODE (addr) == POST_DEC
5984            || GET_CODE (addr) == PRE_INC
5985            || GET_CODE (addr) == POST_INC)
5986           && XEXP (addr, 0) == inced)
5987         return GET_MODE_SIZE (GET_MODE (x));
5988     }
5989
5990   fmt = GET_RTX_FORMAT (code);
5991   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5992     {
5993       if (fmt[i] == 'e')
5994         {
5995           register int tem = find_inc_amount (XEXP (x, i), inced);
5996           if (tem != 0)
5997             return tem;
5998         }
5999       if (fmt[i] == 'E')
6000         {
6001           register int j;
6002           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6003             {
6004               register int tem = find_inc_amount (XVECEXP (x, i, j), inced);
6005               if (tem != 0)
6006                 return tem;
6007             }
6008         }
6009     }
6010
6011   return 0;
6012 }
6013 \f
6014 /* Return 1 if register REGNO is the subject of a clobber in insn INSN.  */
6015
6016 int
6017 regno_clobbered_p (regno, insn)
6018      int regno;
6019      rtx insn;
6020 {
6021   if (GET_CODE (PATTERN (insn)) == CLOBBER
6022       && GET_CODE (XEXP (PATTERN (insn), 0)) == REG)
6023     return REGNO (XEXP (PATTERN (insn), 0)) == regno;
6024
6025   if (GET_CODE (PATTERN (insn)) == PARALLEL)
6026     {
6027       int i = XVECLEN (PATTERN (insn), 0) - 1;
6028
6029       for (; i >= 0; i--)
6030         {
6031           rtx elt = XVECEXP (PATTERN (insn), 0, i);
6032           if (GET_CODE (elt) == CLOBBER && GET_CODE (XEXP (elt, 0)) == REG
6033               && REGNO (XEXP (elt, 0)) == regno)
6034             return 1;
6035         }
6036     }
6037
6038   return 0;
6039 }
6040
6041 static char *reload_when_needed_name[] =
6042 {
6043   "RELOAD_FOR_INPUT", 
6044   "RELOAD_FOR_OUTPUT", 
6045   "RELOAD_FOR_INSN",
6046   "RELOAD_FOR_INPUT_ADDRESS",
6047   "RELOAD_FOR_INPADDR_ADDRESS",
6048   "RELOAD_FOR_OUTPUT_ADDRESS",
6049   "RELOAD_FOR_OUTADDR_ADDRESS",
6050   "RELOAD_FOR_OPERAND_ADDRESS", 
6051   "RELOAD_FOR_OPADDR_ADDR",
6052   "RELOAD_OTHER", 
6053   "RELOAD_FOR_OTHER_ADDRESS"
6054 };
6055
6056 static char *reg_class_names[] = REG_CLASS_NAMES;
6057
6058 /* This function is used to print the variables set by 'find_reloads' */
6059
6060 void
6061 debug_reload()
6062 {
6063   int r;
6064
6065   fprintf (stderr, "\nn_reloads = %d\n", n_reloads);
6066
6067   for (r = 0; r < n_reloads; r++)
6068     {
6069       fprintf (stderr, "\nRELOAD %d\n", r);
6070
6071       if (reload_in[r])
6072         {
6073           fprintf (stderr, "\nreload_in (%s) = ",
6074                    GET_MODE_NAME (reload_inmode[r]));
6075           debug_rtx (reload_in[r]);
6076         }
6077
6078       if (reload_out[r])
6079         {
6080           fprintf (stderr, "\nreload_out (%s) = ",
6081                    GET_MODE_NAME (reload_outmode[r]));
6082           debug_rtx (reload_out[r]);
6083         }
6084
6085       fprintf (stderr, "%s, ", reg_class_names[(int) reload_reg_class[r]]);
6086
6087       fprintf (stderr, "%s (opnum = %d)",
6088                reload_when_needed_name[(int)reload_when_needed[r]],
6089                reload_opnum[r]);
6090
6091       if (reload_optional[r])
6092         fprintf (stderr, ", optional");
6093
6094       if (reload_in[r])
6095         fprintf (stderr, ", inc by %d\n", reload_inc[r]);
6096
6097       if (reload_nocombine[r])
6098         fprintf (stderr, ", can't combine");
6099
6100       if (reload_secondary_p[r])
6101         fprintf (stderr, ", secondary_reload_p");
6102
6103       if (reload_in_reg[r])
6104         {
6105           fprintf (stderr, "\nreload_in_reg:\t\t\t");
6106           debug_rtx (reload_in_reg[r]);
6107         }
6108
6109       if (reload_reg_rtx[r])
6110         {
6111           fprintf (stderr, "\nreload_reg_rtx:\t\t\t");
6112           debug_rtx (reload_reg_rtx[r]);
6113         }
6114
6115       if (reload_secondary_in_reload[r] != -1)
6116         {
6117           fprintf (stderr, "\nsecondary_in_reload = ");
6118           fprintf (stderr, "%d ", reload_secondary_in_reload[r]);
6119         }
6120
6121       if (reload_secondary_out_reload[r] != -1)
6122         {
6123           if (reload_secondary_in_reload[r] != -1)
6124             fprintf (stderr, ", secondary_out_reload = ");
6125           else
6126             fprintf (stderr, "\nsecondary_out_reload = ");
6127
6128           fprintf (stderr, "%d", reload_secondary_out_reload[r]);
6129         }
6130
6131
6132       if (reload_secondary_in_icode[r] != CODE_FOR_nothing)
6133         {
6134           fprintf (stderr, "\nsecondary_in_icode = ");
6135           fprintf (stderr, "%s", insn_name[r]);
6136         }
6137
6138       if (reload_secondary_out_icode[r] != CODE_FOR_nothing)
6139         {
6140           if (reload_secondary_in_icode[r] != CODE_FOR_nothing)
6141             fprintf (stderr, ", secondary_out_icode = ");
6142           else
6143             fprintf (stderr, "\nsecondary_out_icode = ");
6144
6145           fprintf (stderr, "%s ", insn_name[r]);
6146         }
6147       fprintf (stderr, "\n");
6148     }
6149
6150   fprintf (stderr, "\n");
6151 }