* check-init.c, decl.c, expr.c, gcj.texi, java-tree.h,
[official-gcc.git] / gcc / reload.c
blobc8e8c07aebe9e84f8a42aa9b20b4d1d3b2453ad0
1 /* Search an insn for pseudo regs that must be in hard regs and are not.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA. */
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.
29 Before processing the first insn of the function, call `init_reload'.
30 init_reload actually has to be called earlier anyway.
32 To scan an insn, call `find_reloads'. This does two things:
33 1. sets up tables describing which values must be reloaded
34 for this insn, and what kind of hard regs they must be reloaded into;
35 2. optionally record the locations where those values appear in
36 the data, so they can be replaced properly later.
37 This is done only if the second arg to `find_reloads' is nonzero.
39 The third arg to `find_reloads' specifies the number of levels
40 of indirect addressing supported by the machine. If it is zero,
41 indirect addressing is not valid. If it is one, (MEM (REG n))
42 is valid even if (REG n) did not get a hard register; if it is two,
43 (MEM (MEM (REG n))) is also valid even if (REG n) did not get a
44 hard register, and similarly for higher values.
46 Then you must choose the hard regs to reload those pseudo regs into,
47 and generate appropriate load insns before this insn and perhaps
48 also store insns after this insn. Set up the array `reload_reg_rtx'
49 to contain the REG rtx's for the registers you used. In some
50 cases `find_reloads' will return a nonzero value in `reload_reg_rtx'
51 for certain reloads. Then that tells you which register to use,
52 so you do not need to allocate one. But you still do need to add extra
53 instructions to copy the value into and out of that register.
55 Finally you must call `subst_reloads' to substitute the reload reg rtx's
56 into the locations already recorded.
58 NOTE SIDE EFFECTS:
60 find_reloads can alter the operands of the instruction it is called on.
62 1. Two operands of any sort may be interchanged, if they are in a
63 commutative instruction.
64 This happens only if find_reloads thinks the instruction will compile
65 better that way.
67 2. Pseudo-registers that are equivalent to constants are replaced
68 with those constants if they are not in hard registers.
70 1 happens every time find_reloads is called.
71 2 happens only when REPLACE is 1, which is only when
72 actually doing the reloads, not when just counting them.
74 Using a reload register for several reloads in one insn:
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.
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.
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. */
88 #define REG_OK_STRICT
90 #include "config.h"
91 #include "system.h"
92 #include "coretypes.h"
93 #include "tm.h"
94 #include "rtl.h"
95 #include "tm_p.h"
96 #include "insn-config.h"
97 #include "expr.h"
98 #include "optabs.h"
99 #include "recog.h"
100 #include "reload.h"
101 #include "regs.h"
102 #include "hard-reg-set.h"
103 #include "flags.h"
104 #include "real.h"
105 #include "output.h"
106 #include "function.h"
107 #include "toplev.h"
108 #include "params.h"
109 #include "target.h"
111 /* True if X is a constant that can be forced into the constant pool. */
112 #define CONST_POOL_OK_P(X) \
113 (CONSTANT_P (X) \
114 && GET_CODE (X) != HIGH \
115 && !targetm.cannot_force_const_mem (X))
117 /* True if C is a non-empty register class that has too few registers
118 to be safely used as a reload target class. */
119 #define SMALL_REGISTER_CLASS_P(C) \
120 (reg_class_size [(C)] == 1 \
121 || (reg_class_size [(C)] >= 1 && CLASS_LIKELY_SPILLED_P (C)))
124 /* All reloads of the current insn are recorded here. See reload.h for
125 comments. */
126 int n_reloads;
127 struct reload rld[MAX_RELOADS];
129 /* All the "earlyclobber" operands of the current insn
130 are recorded here. */
131 int n_earlyclobbers;
132 rtx reload_earlyclobbers[MAX_RECOG_OPERANDS];
134 int reload_n_operands;
136 /* Replacing reloads.
138 If `replace_reloads' is nonzero, then as each reload is recorded
139 an entry is made for it in the table `replacements'.
140 Then later `subst_reloads' can look through that table and
141 perform all the replacements needed. */
143 /* Nonzero means record the places to replace. */
144 static int replace_reloads;
146 /* Each replacement is recorded with a structure like this. */
147 struct replacement
149 rtx *where; /* Location to store in */
150 rtx *subreg_loc; /* Location of SUBREG if WHERE is inside
151 a SUBREG; 0 otherwise. */
152 int what; /* which reload this is for */
153 enum machine_mode mode; /* mode it must have */
156 static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
158 /* Number of replacements currently recorded. */
159 static int n_replacements;
161 /* Used to track what is modified by an operand. */
162 struct decomposition
164 int reg_flag; /* Nonzero if referencing a register. */
165 int safe; /* Nonzero if this can't conflict with anything. */
166 rtx base; /* Base address for MEM. */
167 HOST_WIDE_INT start; /* Starting offset or register number. */
168 HOST_WIDE_INT end; /* Ending offset or register number. */
171 #ifdef SECONDARY_MEMORY_NEEDED
173 /* Save MEMs needed to copy from one class of registers to another. One MEM
174 is used per mode, but normally only one or two modes are ever used.
176 We keep two versions, before and after register elimination. The one
177 after register elimination is record separately for each operand. This
178 is done in case the address is not valid to be sure that we separately
179 reload each. */
181 static rtx secondary_memlocs[NUM_MACHINE_MODES];
182 static rtx secondary_memlocs_elim[NUM_MACHINE_MODES][MAX_RECOG_OPERANDS];
183 static int secondary_memlocs_elim_used = 0;
184 #endif
186 /* The instruction we are doing reloads for;
187 so we can test whether a register dies in it. */
188 static rtx this_insn;
190 /* Nonzero if this instruction is a user-specified asm with operands. */
191 static int this_insn_is_asm;
193 /* If hard_regs_live_known is nonzero,
194 we can tell which hard regs are currently live,
195 at least enough to succeed in choosing dummy reloads. */
196 static int hard_regs_live_known;
198 /* Indexed by hard reg number,
199 element is nonnegative if hard reg has been spilled.
200 This vector is passed to `find_reloads' as an argument
201 and is not changed here. */
202 static short *static_reload_reg_p;
204 /* Set to 1 in subst_reg_equivs if it changes anything. */
205 static int subst_reg_equivs_changed;
207 /* On return from push_reload, holds the reload-number for the OUT
208 operand, which can be different for that from the input operand. */
209 static int output_reloadnum;
211 /* Compare two RTX's. */
212 #define MATCHES(x, y) \
213 (x == y || (x != 0 && (REG_P (x) \
214 ? REG_P (y) && REGNO (x) == REGNO (y) \
215 : rtx_equal_p (x, y) && ! side_effects_p (x))))
217 /* Indicates if two reloads purposes are for similar enough things that we
218 can merge their reloads. */
219 #define MERGABLE_RELOADS(when1, when2, op1, op2) \
220 ((when1) == RELOAD_OTHER || (when2) == RELOAD_OTHER \
221 || ((when1) == (when2) && (op1) == (op2)) \
222 || ((when1) == RELOAD_FOR_INPUT && (when2) == RELOAD_FOR_INPUT) \
223 || ((when1) == RELOAD_FOR_OPERAND_ADDRESS \
224 && (when2) == RELOAD_FOR_OPERAND_ADDRESS) \
225 || ((when1) == RELOAD_FOR_OTHER_ADDRESS \
226 && (when2) == RELOAD_FOR_OTHER_ADDRESS))
228 /* Nonzero if these two reload purposes produce RELOAD_OTHER when merged. */
229 #define MERGE_TO_OTHER(when1, when2, op1, op2) \
230 ((when1) != (when2) \
231 || ! ((op1) == (op2) \
232 || (when1) == RELOAD_FOR_INPUT \
233 || (when1) == RELOAD_FOR_OPERAND_ADDRESS \
234 || (when1) == RELOAD_FOR_OTHER_ADDRESS))
236 /* If we are going to reload an address, compute the reload type to
237 use. */
238 #define ADDR_TYPE(type) \
239 ((type) == RELOAD_FOR_INPUT_ADDRESS \
240 ? RELOAD_FOR_INPADDR_ADDRESS \
241 : ((type) == RELOAD_FOR_OUTPUT_ADDRESS \
242 ? RELOAD_FOR_OUTADDR_ADDRESS \
243 : (type)))
245 #ifdef HAVE_SECONDARY_RELOADS
246 static int push_secondary_reload (int, rtx, int, int, enum reg_class,
247 enum machine_mode, enum reload_type,
248 enum insn_code *);
249 #endif
250 static enum reg_class find_valid_class (enum machine_mode, enum machine_mode,
251 int, unsigned int);
252 static int reload_inner_reg_of_subreg (rtx, enum machine_mode, int);
253 static void push_replacement (rtx *, int, enum machine_mode);
254 static void dup_replacements (rtx *, rtx *);
255 static void combine_reloads (void);
256 static int find_reusable_reload (rtx *, rtx, enum reg_class,
257 enum reload_type, int, int);
258 static rtx find_dummy_reload (rtx, rtx, rtx *, rtx *, enum machine_mode,
259 enum machine_mode, enum reg_class, int, int);
260 static int hard_reg_set_here_p (unsigned int, unsigned int, rtx);
261 static struct decomposition decompose (rtx);
262 static int immune_p (rtx, rtx, struct decomposition);
263 static int alternative_allows_memconst (const char *, int);
264 static rtx find_reloads_toplev (rtx, int, enum reload_type, int, int, rtx,
265 int *);
266 static rtx make_memloc (rtx, int);
267 static int maybe_memory_address_p (enum machine_mode, rtx, rtx *);
268 static int find_reloads_address (enum machine_mode, rtx *, rtx, rtx *,
269 int, enum reload_type, int, rtx);
270 static rtx subst_reg_equivs (rtx, rtx);
271 static rtx subst_indexed_address (rtx);
272 static void update_auto_inc_notes (rtx, int, int);
273 static int find_reloads_address_1 (enum machine_mode, rtx, int, rtx *,
274 int, enum reload_type,int, rtx);
275 static void find_reloads_address_part (rtx, rtx *, enum reg_class,
276 enum machine_mode, int,
277 enum reload_type, int);
278 static rtx find_reloads_subreg_address (rtx, int, int, enum reload_type,
279 int, rtx);
280 static void copy_replacements_1 (rtx *, rtx *, int);
281 static int find_inc_amount (rtx, rtx);
282 static int refers_to_mem_for_reload_p (rtx);
283 static int refers_to_regno_for_reload_p (unsigned int, unsigned int,
284 rtx, rtx *);
286 #ifdef HAVE_SECONDARY_RELOADS
288 /* Determine if any secondary reloads are needed for loading (if IN_P is
289 nonzero) or storing (if IN_P is zero) X to or from a reload register of
290 register class RELOAD_CLASS in mode RELOAD_MODE. If secondary reloads
291 are needed, push them.
293 Return the reload number of the secondary reload we made, or -1 if
294 we didn't need one. *PICODE is set to the insn_code to use if we do
295 need a secondary reload. */
297 static int
298 push_secondary_reload (int in_p, rtx x, int opnum, int optional,
299 enum reg_class reload_class,
300 enum machine_mode reload_mode, enum reload_type type,
301 enum insn_code *picode)
303 enum reg_class class = NO_REGS;
304 enum machine_mode mode = reload_mode;
305 enum insn_code icode = CODE_FOR_nothing;
306 enum reg_class t_class = NO_REGS;
307 enum machine_mode t_mode = VOIDmode;
308 enum insn_code t_icode = CODE_FOR_nothing;
309 enum reload_type secondary_type;
310 int s_reload, t_reload = -1;
312 if (type == RELOAD_FOR_INPUT_ADDRESS
313 || type == RELOAD_FOR_OUTPUT_ADDRESS
314 || type == RELOAD_FOR_INPADDR_ADDRESS
315 || type == RELOAD_FOR_OUTADDR_ADDRESS)
316 secondary_type = type;
317 else
318 secondary_type = in_p ? RELOAD_FOR_INPUT_ADDRESS : RELOAD_FOR_OUTPUT_ADDRESS;
320 *picode = CODE_FOR_nothing;
322 /* If X is a paradoxical SUBREG, use the inner value to determine both the
323 mode and object being reloaded. */
324 if (GET_CODE (x) == SUBREG
325 && (GET_MODE_SIZE (GET_MODE (x))
326 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
328 x = SUBREG_REG (x);
329 reload_mode = GET_MODE (x);
332 /* If X is a pseudo-register that has an equivalent MEM (actually, if it
333 is still a pseudo-register by now, it *must* have an equivalent MEM
334 but we don't want to assume that), use that equivalent when seeing if
335 a secondary reload is needed since whether or not a reload is needed
336 might be sensitive to the form of the MEM. */
338 if (REG_P (x) && REGNO (x) >= FIRST_PSEUDO_REGISTER
339 && reg_equiv_mem[REGNO (x)] != 0)
340 x = reg_equiv_mem[REGNO (x)];
342 #ifdef SECONDARY_INPUT_RELOAD_CLASS
343 if (in_p)
344 class = SECONDARY_INPUT_RELOAD_CLASS (reload_class, reload_mode, x);
345 #endif
347 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
348 if (! in_p)
349 class = SECONDARY_OUTPUT_RELOAD_CLASS (reload_class, reload_mode, x);
350 #endif
352 /* If we don't need any secondary registers, done. */
353 if (class == NO_REGS)
354 return -1;
356 /* Get a possible insn to use. If the predicate doesn't accept X, don't
357 use the insn. */
359 icode = (in_p ? reload_in_optab[(int) reload_mode]
360 : reload_out_optab[(int) reload_mode]);
362 if (icode != CODE_FOR_nothing
363 && insn_data[(int) icode].operand[in_p].predicate
364 && (! (insn_data[(int) icode].operand[in_p].predicate) (x, reload_mode)))
365 icode = CODE_FOR_nothing;
367 /* If we will be using an insn, see if it can directly handle the reload
368 register we will be using. If it can, the secondary reload is for a
369 scratch register. If it can't, we will use the secondary reload for
370 an intermediate register and require a tertiary reload for the scratch
371 register. */
373 if (icode != CODE_FOR_nothing)
375 /* If IN_P is nonzero, the reload register will be the output in
376 operand 0. If IN_P is zero, the reload register will be the input
377 in operand 1. Outputs should have an initial "=", which we must
378 skip. */
380 enum reg_class insn_class;
382 if (insn_data[(int) icode].operand[!in_p].constraint[0] == 0)
383 insn_class = ALL_REGS;
384 else
386 const char *insn_constraint
387 = &insn_data[(int) icode].operand[!in_p].constraint[in_p];
388 char insn_letter = *insn_constraint;
389 insn_class
390 = (insn_letter == 'r' ? GENERAL_REGS
391 : REG_CLASS_FROM_CONSTRAINT ((unsigned char) insn_letter,
392 insn_constraint));
394 gcc_assert (insn_class != NO_REGS);
395 gcc_assert (!in_p
396 || insn_data[(int) icode].operand[!in_p].constraint[0]
397 == '=');
400 /* The scratch register's constraint must start with "=&". */
401 gcc_assert (insn_data[(int) icode].operand[2].constraint[0] == '='
402 && insn_data[(int) icode].operand[2].constraint[1] == '&');
404 if (reg_class_subset_p (reload_class, insn_class))
405 mode = insn_data[(int) icode].operand[2].mode;
406 else
408 const char *t_constraint
409 = &insn_data[(int) icode].operand[2].constraint[2];
410 char t_letter = *t_constraint;
411 class = insn_class;
412 t_mode = insn_data[(int) icode].operand[2].mode;
413 t_class = (t_letter == 'r' ? GENERAL_REGS
414 : REG_CLASS_FROM_CONSTRAINT ((unsigned char) t_letter,
415 t_constraint));
416 t_icode = icode;
417 icode = CODE_FOR_nothing;
421 /* This case isn't valid, so fail. Reload is allowed to use the same
422 register for RELOAD_FOR_INPUT_ADDRESS and RELOAD_FOR_INPUT reloads, but
423 in the case of a secondary register, we actually need two different
424 registers for correct code. We fail here to prevent the possibility of
425 silently generating incorrect code later.
427 The convention is that secondary input reloads are valid only if the
428 secondary_class is different from class. If you have such a case, you
429 can not use secondary reloads, you must work around the problem some
430 other way.
432 Allow this when a reload_in/out pattern is being used. I.e. assume
433 that the generated code handles this case. */
435 gcc_assert (!in_p || class != reload_class || icode != CODE_FOR_nothing
436 || t_icode != CODE_FOR_nothing);
438 /* If we need a tertiary reload, see if we have one we can reuse or else
439 make a new one. */
441 if (t_class != NO_REGS)
443 for (t_reload = 0; t_reload < n_reloads; t_reload++)
444 if (rld[t_reload].secondary_p
445 && (reg_class_subset_p (t_class, rld[t_reload].class)
446 || reg_class_subset_p (rld[t_reload].class, t_class))
447 && ((in_p && rld[t_reload].inmode == t_mode)
448 || (! in_p && rld[t_reload].outmode == t_mode))
449 && ((in_p && (rld[t_reload].secondary_in_icode
450 == CODE_FOR_nothing))
451 || (! in_p &&(rld[t_reload].secondary_out_icode
452 == CODE_FOR_nothing)))
453 && (SMALL_REGISTER_CLASS_P (t_class) || SMALL_REGISTER_CLASSES)
454 && MERGABLE_RELOADS (secondary_type,
455 rld[t_reload].when_needed,
456 opnum, rld[t_reload].opnum))
458 if (in_p)
459 rld[t_reload].inmode = t_mode;
460 if (! in_p)
461 rld[t_reload].outmode = t_mode;
463 if (reg_class_subset_p (t_class, rld[t_reload].class))
464 rld[t_reload].class = t_class;
466 rld[t_reload].opnum = MIN (rld[t_reload].opnum, opnum);
467 rld[t_reload].optional &= optional;
468 rld[t_reload].secondary_p = 1;
469 if (MERGE_TO_OTHER (secondary_type, rld[t_reload].when_needed,
470 opnum, rld[t_reload].opnum))
471 rld[t_reload].when_needed = RELOAD_OTHER;
474 if (t_reload == n_reloads)
476 /* We need to make a new tertiary reload for this register class. */
477 rld[t_reload].in = rld[t_reload].out = 0;
478 rld[t_reload].class = t_class;
479 rld[t_reload].inmode = in_p ? t_mode : VOIDmode;
480 rld[t_reload].outmode = ! in_p ? t_mode : VOIDmode;
481 rld[t_reload].reg_rtx = 0;
482 rld[t_reload].optional = optional;
483 rld[t_reload].inc = 0;
484 /* Maybe we could combine these, but it seems too tricky. */
485 rld[t_reload].nocombine = 1;
486 rld[t_reload].in_reg = 0;
487 rld[t_reload].out_reg = 0;
488 rld[t_reload].opnum = opnum;
489 rld[t_reload].when_needed = secondary_type;
490 rld[t_reload].secondary_in_reload = -1;
491 rld[t_reload].secondary_out_reload = -1;
492 rld[t_reload].secondary_in_icode = CODE_FOR_nothing;
493 rld[t_reload].secondary_out_icode = CODE_FOR_nothing;
494 rld[t_reload].secondary_p = 1;
496 n_reloads++;
500 /* See if we can reuse an existing secondary reload. */
501 for (s_reload = 0; s_reload < n_reloads; s_reload++)
502 if (rld[s_reload].secondary_p
503 && (reg_class_subset_p (class, rld[s_reload].class)
504 || reg_class_subset_p (rld[s_reload].class, class))
505 && ((in_p && rld[s_reload].inmode == mode)
506 || (! in_p && rld[s_reload].outmode == mode))
507 && ((in_p && rld[s_reload].secondary_in_reload == t_reload)
508 || (! in_p && rld[s_reload].secondary_out_reload == t_reload))
509 && ((in_p && rld[s_reload].secondary_in_icode == t_icode)
510 || (! in_p && rld[s_reload].secondary_out_icode == t_icode))
511 && (SMALL_REGISTER_CLASS_P (class) || SMALL_REGISTER_CLASSES)
512 && MERGABLE_RELOADS (secondary_type, rld[s_reload].when_needed,
513 opnum, rld[s_reload].opnum))
515 if (in_p)
516 rld[s_reload].inmode = mode;
517 if (! in_p)
518 rld[s_reload].outmode = mode;
520 if (reg_class_subset_p (class, rld[s_reload].class))
521 rld[s_reload].class = class;
523 rld[s_reload].opnum = MIN (rld[s_reload].opnum, opnum);
524 rld[s_reload].optional &= optional;
525 rld[s_reload].secondary_p = 1;
526 if (MERGE_TO_OTHER (secondary_type, rld[s_reload].when_needed,
527 opnum, rld[s_reload].opnum))
528 rld[s_reload].when_needed = RELOAD_OTHER;
531 if (s_reload == n_reloads)
533 #ifdef SECONDARY_MEMORY_NEEDED
534 /* If we need a memory location to copy between the two reload regs,
535 set it up now. Note that we do the input case before making
536 the reload and the output case after. This is due to the
537 way reloads are output. */
539 if (in_p && icode == CODE_FOR_nothing
540 && SECONDARY_MEMORY_NEEDED (class, reload_class, mode))
542 get_secondary_mem (x, reload_mode, opnum, type);
544 /* We may have just added new reloads. Make sure we add
545 the new reload at the end. */
546 s_reload = n_reloads;
548 #endif
550 /* We need to make a new secondary reload for this register class. */
551 rld[s_reload].in = rld[s_reload].out = 0;
552 rld[s_reload].class = class;
554 rld[s_reload].inmode = in_p ? mode : VOIDmode;
555 rld[s_reload].outmode = ! in_p ? mode : VOIDmode;
556 rld[s_reload].reg_rtx = 0;
557 rld[s_reload].optional = optional;
558 rld[s_reload].inc = 0;
559 /* Maybe we could combine these, but it seems too tricky. */
560 rld[s_reload].nocombine = 1;
561 rld[s_reload].in_reg = 0;
562 rld[s_reload].out_reg = 0;
563 rld[s_reload].opnum = opnum;
564 rld[s_reload].when_needed = secondary_type;
565 rld[s_reload].secondary_in_reload = in_p ? t_reload : -1;
566 rld[s_reload].secondary_out_reload = ! in_p ? t_reload : -1;
567 rld[s_reload].secondary_in_icode = in_p ? t_icode : CODE_FOR_nothing;
568 rld[s_reload].secondary_out_icode
569 = ! in_p ? t_icode : CODE_FOR_nothing;
570 rld[s_reload].secondary_p = 1;
572 n_reloads++;
574 #ifdef SECONDARY_MEMORY_NEEDED
575 if (! in_p && icode == CODE_FOR_nothing
576 && SECONDARY_MEMORY_NEEDED (reload_class, class, mode))
577 get_secondary_mem (x, mode, opnum, type);
578 #endif
581 *picode = icode;
582 return s_reload;
584 #endif /* HAVE_SECONDARY_RELOADS */
586 #ifdef SECONDARY_MEMORY_NEEDED
588 /* Return a memory location that will be used to copy X in mode MODE.
589 If we haven't already made a location for this mode in this insn,
590 call find_reloads_address on the location being returned. */
593 get_secondary_mem (rtx x ATTRIBUTE_UNUSED, enum machine_mode mode,
594 int opnum, enum reload_type type)
596 rtx loc;
597 int mem_valid;
599 /* By default, if MODE is narrower than a word, widen it to a word.
600 This is required because most machines that require these memory
601 locations do not support short load and stores from all registers
602 (e.g., FP registers). */
604 #ifdef SECONDARY_MEMORY_NEEDED_MODE
605 mode = SECONDARY_MEMORY_NEEDED_MODE (mode);
606 #else
607 if (GET_MODE_BITSIZE (mode) < BITS_PER_WORD && INTEGRAL_MODE_P (mode))
608 mode = mode_for_size (BITS_PER_WORD, GET_MODE_CLASS (mode), 0);
609 #endif
611 /* If we already have made a MEM for this operand in MODE, return it. */
612 if (secondary_memlocs_elim[(int) mode][opnum] != 0)
613 return secondary_memlocs_elim[(int) mode][opnum];
615 /* If this is the first time we've tried to get a MEM for this mode,
616 allocate a new one. `something_changed' in reload will get set
617 by noticing that the frame size has changed. */
619 if (secondary_memlocs[(int) mode] == 0)
621 #ifdef SECONDARY_MEMORY_NEEDED_RTX
622 secondary_memlocs[(int) mode] = SECONDARY_MEMORY_NEEDED_RTX (mode);
623 #else
624 secondary_memlocs[(int) mode]
625 = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
626 #endif
629 /* Get a version of the address doing any eliminations needed. If that
630 didn't give us a new MEM, make a new one if it isn't valid. */
632 loc = eliminate_regs (secondary_memlocs[(int) mode], VOIDmode, NULL_RTX);
633 mem_valid = strict_memory_address_p (mode, XEXP (loc, 0));
635 if (! mem_valid && loc == secondary_memlocs[(int) mode])
636 loc = copy_rtx (loc);
638 /* The only time the call below will do anything is if the stack
639 offset is too large. In that case IND_LEVELS doesn't matter, so we
640 can just pass a zero. Adjust the type to be the address of the
641 corresponding object. If the address was valid, save the eliminated
642 address. If it wasn't valid, we need to make a reload each time, so
643 don't save it. */
645 if (! mem_valid)
647 type = (type == RELOAD_FOR_INPUT ? RELOAD_FOR_INPUT_ADDRESS
648 : type == RELOAD_FOR_OUTPUT ? RELOAD_FOR_OUTPUT_ADDRESS
649 : RELOAD_OTHER);
651 find_reloads_address (mode, &loc, XEXP (loc, 0), &XEXP (loc, 0),
652 opnum, type, 0, 0);
655 secondary_memlocs_elim[(int) mode][opnum] = loc;
656 if (secondary_memlocs_elim_used <= (int)mode)
657 secondary_memlocs_elim_used = (int)mode + 1;
658 return loc;
661 /* Clear any secondary memory locations we've made. */
663 void
664 clear_secondary_mem (void)
666 memset (secondary_memlocs, 0, sizeof secondary_memlocs);
668 #endif /* SECONDARY_MEMORY_NEEDED */
671 /* Find the largest class which has at least one register valid in
672 mode INNER, and which for every such register, that register number
673 plus N is also valid in OUTER (if in range) and is cheap to move
674 into REGNO. Such a class must exist. */
676 static enum reg_class
677 find_valid_class (enum machine_mode outer ATTRIBUTE_UNUSED,
678 enum machine_mode inner ATTRIBUTE_UNUSED, int n,
679 unsigned int dest_regno ATTRIBUTE_UNUSED)
681 int best_cost = -1;
682 int class;
683 int regno;
684 enum reg_class best_class = NO_REGS;
685 enum reg_class dest_class ATTRIBUTE_UNUSED = REGNO_REG_CLASS (dest_regno);
686 unsigned int best_size = 0;
687 int cost;
689 for (class = 1; class < N_REG_CLASSES; class++)
691 int bad = 0;
692 int good = 0;
693 for (regno = 0; regno < FIRST_PSEUDO_REGISTER - n && ! bad; regno++)
694 if (TEST_HARD_REG_BIT (reg_class_contents[class], regno))
696 if (HARD_REGNO_MODE_OK (regno, inner))
698 good = 1;
699 if (! TEST_HARD_REG_BIT (reg_class_contents[class], regno + n)
700 || ! HARD_REGNO_MODE_OK (regno + n, outer))
701 bad = 1;
705 if (bad || !good)
706 continue;
707 cost = REGISTER_MOVE_COST (outer, class, dest_class);
709 if ((reg_class_size[class] > best_size
710 && (best_cost < 0 || best_cost >= cost))
711 || best_cost > cost)
713 best_class = class;
714 best_size = reg_class_size[class];
715 best_cost = REGISTER_MOVE_COST (outer, class, dest_class);
719 gcc_assert (best_size != 0);
721 return best_class;
724 /* Return the number of a previously made reload that can be combined with
725 a new one, or n_reloads if none of the existing reloads can be used.
726 OUT, CLASS, TYPE and OPNUM are the same arguments as passed to
727 push_reload, they determine the kind of the new reload that we try to
728 combine. P_IN points to the corresponding value of IN, which can be
729 modified by this function.
730 DONT_SHARE is nonzero if we can't share any input-only reload for IN. */
732 static int
733 find_reusable_reload (rtx *p_in, rtx out, enum reg_class class,
734 enum reload_type type, int opnum, int dont_share)
736 rtx in = *p_in;
737 int i;
738 /* We can't merge two reloads if the output of either one is
739 earlyclobbered. */
741 if (earlyclobber_operand_p (out))
742 return n_reloads;
744 /* We can use an existing reload if the class is right
745 and at least one of IN and OUT is a match
746 and the other is at worst neutral.
747 (A zero compared against anything is neutral.)
749 If SMALL_REGISTER_CLASSES, don't use existing reloads unless they are
750 for the same thing since that can cause us to need more reload registers
751 than we otherwise would. */
753 for (i = 0; i < n_reloads; i++)
754 if ((reg_class_subset_p (class, rld[i].class)
755 || reg_class_subset_p (rld[i].class, class))
756 /* If the existing reload has a register, it must fit our class. */
757 && (rld[i].reg_rtx == 0
758 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
759 true_regnum (rld[i].reg_rtx)))
760 && ((in != 0 && MATCHES (rld[i].in, in) && ! dont_share
761 && (out == 0 || rld[i].out == 0 || MATCHES (rld[i].out, out)))
762 || (out != 0 && MATCHES (rld[i].out, out)
763 && (in == 0 || rld[i].in == 0 || MATCHES (rld[i].in, in))))
764 && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out))
765 && (SMALL_REGISTER_CLASS_P (class) || SMALL_REGISTER_CLASSES)
766 && MERGABLE_RELOADS (type, rld[i].when_needed, opnum, rld[i].opnum))
767 return i;
769 /* Reloading a plain reg for input can match a reload to postincrement
770 that reg, since the postincrement's value is the right value.
771 Likewise, it can match a preincrement reload, since we regard
772 the preincrementation as happening before any ref in this insn
773 to that register. */
774 for (i = 0; i < n_reloads; i++)
775 if ((reg_class_subset_p (class, rld[i].class)
776 || reg_class_subset_p (rld[i].class, class))
777 /* If the existing reload has a register, it must fit our
778 class. */
779 && (rld[i].reg_rtx == 0
780 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
781 true_regnum (rld[i].reg_rtx)))
782 && out == 0 && rld[i].out == 0 && rld[i].in != 0
783 && ((REG_P (in)
784 && GET_RTX_CLASS (GET_CODE (rld[i].in)) == RTX_AUTOINC
785 && MATCHES (XEXP (rld[i].in, 0), in))
786 || (REG_P (rld[i].in)
787 && GET_RTX_CLASS (GET_CODE (in)) == RTX_AUTOINC
788 && MATCHES (XEXP (in, 0), rld[i].in)))
789 && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out))
790 && (SMALL_REGISTER_CLASS_P (class) || SMALL_REGISTER_CLASSES)
791 && MERGABLE_RELOADS (type, rld[i].when_needed,
792 opnum, rld[i].opnum))
794 /* Make sure reload_in ultimately has the increment,
795 not the plain register. */
796 if (REG_P (in))
797 *p_in = rld[i].in;
798 return i;
800 return n_reloads;
803 /* Return nonzero if X is a SUBREG which will require reloading of its
804 SUBREG_REG expression. */
806 static int
807 reload_inner_reg_of_subreg (rtx x, enum machine_mode mode, int output)
809 rtx inner;
811 /* Only SUBREGs are problematical. */
812 if (GET_CODE (x) != SUBREG)
813 return 0;
815 inner = SUBREG_REG (x);
817 /* If INNER is a constant or PLUS, then INNER must be reloaded. */
818 if (CONSTANT_P (inner) || GET_CODE (inner) == PLUS)
819 return 1;
821 /* If INNER is not a hard register, then INNER will not need to
822 be reloaded. */
823 if (!REG_P (inner)
824 || REGNO (inner) >= FIRST_PSEUDO_REGISTER)
825 return 0;
827 /* If INNER is not ok for MODE, then INNER will need reloading. */
828 if (! HARD_REGNO_MODE_OK (subreg_regno (x), mode))
829 return 1;
831 /* If the outer part is a word or smaller, INNER larger than a
832 word and the number of regs for INNER is not the same as the
833 number of words in INNER, then INNER will need reloading. */
834 return (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
835 && output
836 && GET_MODE_SIZE (GET_MODE (inner)) > UNITS_PER_WORD
837 && ((GET_MODE_SIZE (GET_MODE (inner)) / UNITS_PER_WORD)
838 != (int) hard_regno_nregs[REGNO (inner)][GET_MODE (inner)]));
841 /* Return nonzero if IN can be reloaded into REGNO with mode MODE without
842 requiring an extra reload register. The caller has already found that
843 IN contains some reference to REGNO, so check that we can produce the
844 new value in a single step. E.g. if we have
845 (set (reg r13) (plus (reg r13) (const int 1))), and there is an
846 instruction that adds one to a register, this should succeed.
847 However, if we have something like
848 (set (reg r13) (plus (reg r13) (const int 999))), and the constant 999
849 needs to be loaded into a register first, we need a separate reload
850 register.
851 Such PLUS reloads are generated by find_reload_address_part.
852 The out-of-range PLUS expressions are usually introduced in the instruction
853 patterns by register elimination and substituting pseudos without a home
854 by their function-invariant equivalences. */
855 static int
856 can_reload_into (rtx in, int regno, enum machine_mode mode)
858 rtx dst, test_insn;
859 int r = 0;
860 struct recog_data save_recog_data;
862 /* For matching constraints, we often get notional input reloads where
863 we want to use the original register as the reload register. I.e.
864 technically this is a non-optional input-output reload, but IN is
865 already a valid register, and has been chosen as the reload register.
866 Speed this up, since it trivially works. */
867 if (REG_P (in))
868 return 1;
870 /* To test MEMs properly, we'd have to take into account all the reloads
871 that are already scheduled, which can become quite complicated.
872 And since we've already handled address reloads for this MEM, it
873 should always succeed anyway. */
874 if (MEM_P (in))
875 return 1;
877 /* If we can make a simple SET insn that does the job, everything should
878 be fine. */
879 dst = gen_rtx_REG (mode, regno);
880 test_insn = make_insn_raw (gen_rtx_SET (VOIDmode, dst, in));
881 save_recog_data = recog_data;
882 if (recog_memoized (test_insn) >= 0)
884 extract_insn (test_insn);
885 r = constrain_operands (1);
887 recog_data = save_recog_data;
888 return r;
891 /* Record one reload that needs to be performed.
892 IN is an rtx saying where the data are to be found before this instruction.
893 OUT says where they must be stored after the instruction.
894 (IN is zero for data not read, and OUT is zero for data not written.)
895 INLOC and OUTLOC point to the places in the instructions where
896 IN and OUT were found.
897 If IN and OUT are both nonzero, it means the same register must be used
898 to reload both IN and OUT.
900 CLASS is a register class required for the reloaded data.
901 INMODE is the machine mode that the instruction requires
902 for the reg that replaces IN and OUTMODE is likewise for OUT.
904 If IN is zero, then OUT's location and mode should be passed as
905 INLOC and INMODE.
907 STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx.
909 OPTIONAL nonzero means this reload does not need to be performed:
910 it can be discarded if that is more convenient.
912 OPNUM and TYPE say what the purpose of this reload is.
914 The return value is the reload-number for this reload.
916 If both IN and OUT are nonzero, in some rare cases we might
917 want to make two separate reloads. (Actually we never do this now.)
918 Therefore, the reload-number for OUT is stored in
919 output_reloadnum when we return; the return value applies to IN.
920 Usually (presently always), when IN and OUT are nonzero,
921 the two reload-numbers are equal, but the caller should be careful to
922 distinguish them. */
925 push_reload (rtx in, rtx out, rtx *inloc, rtx *outloc,
926 enum reg_class class, enum machine_mode inmode,
927 enum machine_mode outmode, int strict_low, int optional,
928 int opnum, enum reload_type type)
930 int i;
931 int dont_share = 0;
932 int dont_remove_subreg = 0;
933 rtx *in_subreg_loc = 0, *out_subreg_loc = 0;
934 int secondary_in_reload = -1, secondary_out_reload = -1;
935 enum insn_code secondary_in_icode = CODE_FOR_nothing;
936 enum insn_code secondary_out_icode = CODE_FOR_nothing;
938 /* INMODE and/or OUTMODE could be VOIDmode if no mode
939 has been specified for the operand. In that case,
940 use the operand's mode as the mode to reload. */
941 if (inmode == VOIDmode && in != 0)
942 inmode = GET_MODE (in);
943 if (outmode == VOIDmode && out != 0)
944 outmode = GET_MODE (out);
946 /* If IN is a pseudo register everywhere-equivalent to a constant, and
947 it is not in a hard register, reload straight from the constant,
948 since we want to get rid of such pseudo registers.
949 Often this is done earlier, but not always in find_reloads_address. */
950 if (in != 0 && REG_P (in))
952 int regno = REGNO (in);
954 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
955 && reg_equiv_constant[regno] != 0)
956 in = reg_equiv_constant[regno];
959 /* Likewise for OUT. Of course, OUT will never be equivalent to
960 an actual constant, but it might be equivalent to a memory location
961 (in the case of a parameter). */
962 if (out != 0 && REG_P (out))
964 int regno = REGNO (out);
966 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
967 && reg_equiv_constant[regno] != 0)
968 out = reg_equiv_constant[regno];
971 /* If we have a read-write operand with an address side-effect,
972 change either IN or OUT so the side-effect happens only once. */
973 if (in != 0 && out != 0 && MEM_P (in) && rtx_equal_p (in, out))
974 switch (GET_CODE (XEXP (in, 0)))
976 case POST_INC: case POST_DEC: case POST_MODIFY:
977 in = replace_equiv_address_nv (in, XEXP (XEXP (in, 0), 0));
978 break;
980 case PRE_INC: case PRE_DEC: case PRE_MODIFY:
981 out = replace_equiv_address_nv (out, XEXP (XEXP (out, 0), 0));
982 break;
984 default:
985 break;
988 /* If we are reloading a (SUBREG constant ...), really reload just the
989 inside expression in its own mode. Similarly for (SUBREG (PLUS ...)).
990 If we have (SUBREG:M1 (MEM:M2 ...) ...) (or an inner REG that is still
991 a pseudo and hence will become a MEM) with M1 wider than M2 and the
992 register is a pseudo, also reload the inside expression.
993 For machines that extend byte loads, do this for any SUBREG of a pseudo
994 where both M1 and M2 are a word or smaller, M1 is wider than M2, and
995 M2 is an integral mode that gets extended when loaded.
996 Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
997 either M1 is not valid for R or M2 is wider than a word but we only
998 need one word to store an M2-sized quantity in R.
999 (However, if OUT is nonzero, we need to reload the reg *and*
1000 the subreg, so do nothing here, and let following statement handle it.)
1002 Note that the case of (SUBREG (CONST_INT...)...) is handled elsewhere;
1003 we can't handle it here because CONST_INT does not indicate a mode.
1005 Similarly, we must reload the inside expression if we have a
1006 STRICT_LOW_PART (presumably, in == out in the cas).
1008 Also reload the inner expression if it does not require a secondary
1009 reload but the SUBREG does.
1011 Finally, reload the inner expression if it is a register that is in
1012 the class whose registers cannot be referenced in a different size
1013 and M1 is not the same size as M2. If subreg_lowpart_p is false, we
1014 cannot reload just the inside since we might end up with the wrong
1015 register class. But if it is inside a STRICT_LOW_PART, we have
1016 no choice, so we hope we do get the right register class there. */
1018 if (in != 0 && GET_CODE (in) == SUBREG
1019 && (subreg_lowpart_p (in) || strict_low)
1020 #ifdef CANNOT_CHANGE_MODE_CLASS
1021 && !CANNOT_CHANGE_MODE_CLASS (GET_MODE (SUBREG_REG (in)), inmode, class)
1022 #endif
1023 && (CONSTANT_P (SUBREG_REG (in))
1024 || GET_CODE (SUBREG_REG (in)) == PLUS
1025 || strict_low
1026 || (((REG_P (SUBREG_REG (in))
1027 && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER)
1028 || MEM_P (SUBREG_REG (in)))
1029 && ((GET_MODE_SIZE (inmode)
1030 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
1031 #ifdef LOAD_EXTEND_OP
1032 || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
1033 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1034 <= UNITS_PER_WORD)
1035 && (GET_MODE_SIZE (inmode)
1036 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
1037 && INTEGRAL_MODE_P (GET_MODE (SUBREG_REG (in)))
1038 && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (in))) != UNKNOWN)
1039 #endif
1040 #ifdef WORD_REGISTER_OPERATIONS
1041 || ((GET_MODE_SIZE (inmode)
1042 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
1043 && ((GET_MODE_SIZE (inmode) - 1) / UNITS_PER_WORD ==
1044 ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))) - 1)
1045 / UNITS_PER_WORD)))
1046 #endif
1048 || (REG_P (SUBREG_REG (in))
1049 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1050 /* The case where out is nonzero
1051 is handled differently in the following statement. */
1052 && (out == 0 || subreg_lowpart_p (in))
1053 && ((GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
1054 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1055 > UNITS_PER_WORD)
1056 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1057 / UNITS_PER_WORD)
1058 != (int) hard_regno_nregs[REGNO (SUBREG_REG (in))]
1059 [GET_MODE (SUBREG_REG (in))]))
1060 || ! HARD_REGNO_MODE_OK (subreg_regno (in), inmode)))
1061 #ifdef SECONDARY_INPUT_RELOAD_CLASS
1062 || (SECONDARY_INPUT_RELOAD_CLASS (class, inmode, in) != NO_REGS
1063 && (SECONDARY_INPUT_RELOAD_CLASS (class,
1064 GET_MODE (SUBREG_REG (in)),
1065 SUBREG_REG (in))
1066 == NO_REGS))
1067 #endif
1068 #ifdef CANNOT_CHANGE_MODE_CLASS
1069 || (REG_P (SUBREG_REG (in))
1070 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1071 && REG_CANNOT_CHANGE_MODE_P
1072 (REGNO (SUBREG_REG (in)), GET_MODE (SUBREG_REG (in)), inmode))
1073 #endif
1076 in_subreg_loc = inloc;
1077 inloc = &SUBREG_REG (in);
1078 in = *inloc;
1079 #if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS)
1080 if (MEM_P (in))
1081 /* This is supposed to happen only for paradoxical subregs made by
1082 combine.c. (SUBREG (MEM)) isn't supposed to occur other ways. */
1083 gcc_assert (GET_MODE_SIZE (GET_MODE (in)) <= GET_MODE_SIZE (inmode));
1084 #endif
1085 inmode = GET_MODE (in);
1088 /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
1089 either M1 is not valid for R or M2 is wider than a word but we only
1090 need one word to store an M2-sized quantity in R.
1092 However, we must reload the inner reg *as well as* the subreg in
1093 that case. */
1095 /* Similar issue for (SUBREG constant ...) if it was not handled by the
1096 code above. This can happen if SUBREG_BYTE != 0. */
1098 if (in != 0 && reload_inner_reg_of_subreg (in, inmode, 0))
1100 enum reg_class in_class = class;
1102 if (REG_P (SUBREG_REG (in)))
1103 in_class
1104 = find_valid_class (inmode, GET_MODE (SUBREG_REG (in)),
1105 subreg_regno_offset (REGNO (SUBREG_REG (in)),
1106 GET_MODE (SUBREG_REG (in)),
1107 SUBREG_BYTE (in),
1108 GET_MODE (in)),
1109 REGNO (SUBREG_REG (in)));
1111 /* This relies on the fact that emit_reload_insns outputs the
1112 instructions for input reloads of type RELOAD_OTHER in the same
1113 order as the reloads. Thus if the outer reload is also of type
1114 RELOAD_OTHER, we are guaranteed that this inner reload will be
1115 output before the outer reload. */
1116 push_reload (SUBREG_REG (in), NULL_RTX, &SUBREG_REG (in), (rtx *) 0,
1117 in_class, VOIDmode, VOIDmode, 0, 0, opnum, type);
1118 dont_remove_subreg = 1;
1121 /* Similarly for paradoxical and problematical SUBREGs on the output.
1122 Note that there is no reason we need worry about the previous value
1123 of SUBREG_REG (out); even if wider than out,
1124 storing in a subreg is entitled to clobber it all
1125 (except in the case of STRICT_LOW_PART,
1126 and in that case the constraint should label it input-output.) */
1127 if (out != 0 && GET_CODE (out) == SUBREG
1128 && (subreg_lowpart_p (out) || strict_low)
1129 #ifdef CANNOT_CHANGE_MODE_CLASS
1130 && !CANNOT_CHANGE_MODE_CLASS (GET_MODE (SUBREG_REG (out)), outmode, class)
1131 #endif
1132 && (CONSTANT_P (SUBREG_REG (out))
1133 || strict_low
1134 || (((REG_P (SUBREG_REG (out))
1135 && REGNO (SUBREG_REG (out)) >= FIRST_PSEUDO_REGISTER)
1136 || MEM_P (SUBREG_REG (out)))
1137 && ((GET_MODE_SIZE (outmode)
1138 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))
1139 #ifdef WORD_REGISTER_OPERATIONS
1140 || ((GET_MODE_SIZE (outmode)
1141 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))
1142 && ((GET_MODE_SIZE (outmode) - 1) / UNITS_PER_WORD ==
1143 ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))) - 1)
1144 / UNITS_PER_WORD)))
1145 #endif
1147 || (REG_P (SUBREG_REG (out))
1148 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1149 && ((GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
1150 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1151 > UNITS_PER_WORD)
1152 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1153 / UNITS_PER_WORD)
1154 != (int) hard_regno_nregs[REGNO (SUBREG_REG (out))]
1155 [GET_MODE (SUBREG_REG (out))]))
1156 || ! HARD_REGNO_MODE_OK (subreg_regno (out), outmode)))
1157 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1158 || (SECONDARY_OUTPUT_RELOAD_CLASS (class, outmode, out) != NO_REGS
1159 && (SECONDARY_OUTPUT_RELOAD_CLASS (class,
1160 GET_MODE (SUBREG_REG (out)),
1161 SUBREG_REG (out))
1162 == NO_REGS))
1163 #endif
1164 #ifdef CANNOT_CHANGE_MODE_CLASS
1165 || (REG_P (SUBREG_REG (out))
1166 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1167 && REG_CANNOT_CHANGE_MODE_P (REGNO (SUBREG_REG (out)),
1168 GET_MODE (SUBREG_REG (out)),
1169 outmode))
1170 #endif
1173 out_subreg_loc = outloc;
1174 outloc = &SUBREG_REG (out);
1175 out = *outloc;
1176 #if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS)
1177 gcc_assert (!MEM_P (out)
1178 || GET_MODE_SIZE (GET_MODE (out))
1179 <= GET_MODE_SIZE (outmode));
1180 #endif
1181 outmode = GET_MODE (out);
1184 /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
1185 either M1 is not valid for R or M2 is wider than a word but we only
1186 need one word to store an M2-sized quantity in R.
1188 However, we must reload the inner reg *as well as* the subreg in
1189 that case. In this case, the inner reg is an in-out reload. */
1191 if (out != 0 && reload_inner_reg_of_subreg (out, outmode, 1))
1193 /* This relies on the fact that emit_reload_insns outputs the
1194 instructions for output reloads of type RELOAD_OTHER in reverse
1195 order of the reloads. Thus if the outer reload is also of type
1196 RELOAD_OTHER, we are guaranteed that this inner reload will be
1197 output after the outer reload. */
1198 dont_remove_subreg = 1;
1199 push_reload (SUBREG_REG (out), SUBREG_REG (out), &SUBREG_REG (out),
1200 &SUBREG_REG (out),
1201 find_valid_class (outmode, GET_MODE (SUBREG_REG (out)),
1202 subreg_regno_offset (REGNO (SUBREG_REG (out)),
1203 GET_MODE (SUBREG_REG (out)),
1204 SUBREG_BYTE (out),
1205 GET_MODE (out)),
1206 REGNO (SUBREG_REG (out))),
1207 VOIDmode, VOIDmode, 0, 0,
1208 opnum, RELOAD_OTHER);
1211 /* If IN appears in OUT, we can't share any input-only reload for IN. */
1212 if (in != 0 && out != 0 && MEM_P (out)
1213 && (REG_P (in) || MEM_P (in))
1214 && reg_overlap_mentioned_for_reload_p (in, XEXP (out, 0)))
1215 dont_share = 1;
1217 /* If IN is a SUBREG of a hard register, make a new REG. This
1218 simplifies some of the cases below. */
1220 if (in != 0 && GET_CODE (in) == SUBREG && REG_P (SUBREG_REG (in))
1221 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1222 && ! dont_remove_subreg)
1223 in = gen_rtx_REG (GET_MODE (in), subreg_regno (in));
1225 /* Similarly for OUT. */
1226 if (out != 0 && GET_CODE (out) == SUBREG
1227 && REG_P (SUBREG_REG (out))
1228 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1229 && ! dont_remove_subreg)
1230 out = gen_rtx_REG (GET_MODE (out), subreg_regno (out));
1232 /* Narrow down the class of register wanted if that is
1233 desirable on this machine for efficiency. */
1234 if (in != 0)
1235 class = PREFERRED_RELOAD_CLASS (in, class);
1237 /* Output reloads may need analogous treatment, different in detail. */
1238 #ifdef PREFERRED_OUTPUT_RELOAD_CLASS
1239 if (out != 0)
1240 class = PREFERRED_OUTPUT_RELOAD_CLASS (out, class);
1241 #endif
1243 /* Make sure we use a class that can handle the actual pseudo
1244 inside any subreg. For example, on the 386, QImode regs
1245 can appear within SImode subregs. Although GENERAL_REGS
1246 can handle SImode, QImode needs a smaller class. */
1247 #ifdef LIMIT_RELOAD_CLASS
1248 if (in_subreg_loc)
1249 class = LIMIT_RELOAD_CLASS (inmode, class);
1250 else if (in != 0 && GET_CODE (in) == SUBREG)
1251 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (in)), class);
1253 if (out_subreg_loc)
1254 class = LIMIT_RELOAD_CLASS (outmode, class);
1255 if (out != 0 && GET_CODE (out) == SUBREG)
1256 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (out)), class);
1257 #endif
1259 /* Verify that this class is at least possible for the mode that
1260 is specified. */
1261 if (this_insn_is_asm)
1263 enum machine_mode mode;
1264 if (GET_MODE_SIZE (inmode) > GET_MODE_SIZE (outmode))
1265 mode = inmode;
1266 else
1267 mode = outmode;
1268 if (mode == VOIDmode)
1270 error_for_asm (this_insn, "cannot reload integer constant "
1271 "operand in %<asm%>");
1272 mode = word_mode;
1273 if (in != 0)
1274 inmode = word_mode;
1275 if (out != 0)
1276 outmode = word_mode;
1278 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1279 if (HARD_REGNO_MODE_OK (i, mode)
1280 && TEST_HARD_REG_BIT (reg_class_contents[(int) class], i))
1282 int nregs = hard_regno_nregs[i][mode];
1284 int j;
1285 for (j = 1; j < nregs; j++)
1286 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class], i + j))
1287 break;
1288 if (j == nregs)
1289 break;
1291 if (i == FIRST_PSEUDO_REGISTER)
1293 error_for_asm (this_insn, "impossible register constraint "
1294 "in %<asm%>");
1295 class = ALL_REGS;
1299 /* Optional output reloads are always OK even if we have no register class,
1300 since the function of these reloads is only to have spill_reg_store etc.
1301 set, so that the storing insn can be deleted later. */
1302 gcc_assert (class != NO_REGS
1303 || (optional != 0 && type == RELOAD_FOR_OUTPUT));
1305 i = find_reusable_reload (&in, out, class, type, opnum, dont_share);
1307 if (i == n_reloads)
1309 /* See if we need a secondary reload register to move between CLASS
1310 and IN or CLASS and OUT. Get the icode and push any required reloads
1311 needed for each of them if so. */
1313 #ifdef SECONDARY_INPUT_RELOAD_CLASS
1314 if (in != 0)
1315 secondary_in_reload
1316 = push_secondary_reload (1, in, opnum, optional, class, inmode, type,
1317 &secondary_in_icode);
1318 #endif
1320 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1321 if (out != 0 && GET_CODE (out) != SCRATCH)
1322 secondary_out_reload
1323 = push_secondary_reload (0, out, opnum, optional, class, outmode,
1324 type, &secondary_out_icode);
1325 #endif
1327 /* We found no existing reload suitable for re-use.
1328 So add an additional reload. */
1330 #ifdef SECONDARY_MEMORY_NEEDED
1331 /* If a memory location is needed for the copy, make one. */
1332 if (in != 0 && (REG_P (in) || GET_CODE (in) == SUBREG)
1333 && reg_or_subregno (in) < FIRST_PSEUDO_REGISTER
1334 && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (reg_or_subregno (in)),
1335 class, inmode))
1336 get_secondary_mem (in, inmode, opnum, type);
1337 #endif
1339 i = n_reloads;
1340 rld[i].in = in;
1341 rld[i].out = out;
1342 rld[i].class = class;
1343 rld[i].inmode = inmode;
1344 rld[i].outmode = outmode;
1345 rld[i].reg_rtx = 0;
1346 rld[i].optional = optional;
1347 rld[i].inc = 0;
1348 rld[i].nocombine = 0;
1349 rld[i].in_reg = inloc ? *inloc : 0;
1350 rld[i].out_reg = outloc ? *outloc : 0;
1351 rld[i].opnum = opnum;
1352 rld[i].when_needed = type;
1353 rld[i].secondary_in_reload = secondary_in_reload;
1354 rld[i].secondary_out_reload = secondary_out_reload;
1355 rld[i].secondary_in_icode = secondary_in_icode;
1356 rld[i].secondary_out_icode = secondary_out_icode;
1357 rld[i].secondary_p = 0;
1359 n_reloads++;
1361 #ifdef SECONDARY_MEMORY_NEEDED
1362 if (out != 0 && (REG_P (out) || GET_CODE (out) == SUBREG)
1363 && reg_or_subregno (out) < FIRST_PSEUDO_REGISTER
1364 && SECONDARY_MEMORY_NEEDED (class,
1365 REGNO_REG_CLASS (reg_or_subregno (out)),
1366 outmode))
1367 get_secondary_mem (out, outmode, opnum, type);
1368 #endif
1370 else
1372 /* We are reusing an existing reload,
1373 but we may have additional information for it.
1374 For example, we may now have both IN and OUT
1375 while the old one may have just one of them. */
1377 /* The modes can be different. If they are, we want to reload in
1378 the larger mode, so that the value is valid for both modes. */
1379 if (inmode != VOIDmode
1380 && GET_MODE_SIZE (inmode) > GET_MODE_SIZE (rld[i].inmode))
1381 rld[i].inmode = inmode;
1382 if (outmode != VOIDmode
1383 && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (rld[i].outmode))
1384 rld[i].outmode = outmode;
1385 if (in != 0)
1387 rtx in_reg = inloc ? *inloc : 0;
1388 /* If we merge reloads for two distinct rtl expressions that
1389 are identical in content, there might be duplicate address
1390 reloads. Remove the extra set now, so that if we later find
1391 that we can inherit this reload, we can get rid of the
1392 address reloads altogether.
1394 Do not do this if both reloads are optional since the result
1395 would be an optional reload which could potentially leave
1396 unresolved address replacements.
1398 It is not sufficient to call transfer_replacements since
1399 choose_reload_regs will remove the replacements for address
1400 reloads of inherited reloads which results in the same
1401 problem. */
1402 if (rld[i].in != in && rtx_equal_p (in, rld[i].in)
1403 && ! (rld[i].optional && optional))
1405 /* We must keep the address reload with the lower operand
1406 number alive. */
1407 if (opnum > rld[i].opnum)
1409 remove_address_replacements (in);
1410 in = rld[i].in;
1411 in_reg = rld[i].in_reg;
1413 else
1414 remove_address_replacements (rld[i].in);
1416 rld[i].in = in;
1417 rld[i].in_reg = in_reg;
1419 if (out != 0)
1421 rld[i].out = out;
1422 rld[i].out_reg = outloc ? *outloc : 0;
1424 if (reg_class_subset_p (class, rld[i].class))
1425 rld[i].class = class;
1426 rld[i].optional &= optional;
1427 if (MERGE_TO_OTHER (type, rld[i].when_needed,
1428 opnum, rld[i].opnum))
1429 rld[i].when_needed = RELOAD_OTHER;
1430 rld[i].opnum = MIN (rld[i].opnum, opnum);
1433 /* If the ostensible rtx being reloaded differs from the rtx found
1434 in the location to substitute, this reload is not safe to combine
1435 because we cannot reliably tell whether it appears in the insn. */
1437 if (in != 0 && in != *inloc)
1438 rld[i].nocombine = 1;
1440 #if 0
1441 /* This was replaced by changes in find_reloads_address_1 and the new
1442 function inc_for_reload, which go with a new meaning of reload_inc. */
1444 /* If this is an IN/OUT reload in an insn that sets the CC,
1445 it must be for an autoincrement. It doesn't work to store
1446 the incremented value after the insn because that would clobber the CC.
1447 So we must do the increment of the value reloaded from,
1448 increment it, store it back, then decrement again. */
1449 if (out != 0 && sets_cc0_p (PATTERN (this_insn)))
1451 out = 0;
1452 rld[i].out = 0;
1453 rld[i].inc = find_inc_amount (PATTERN (this_insn), in);
1454 /* If we did not find a nonzero amount-to-increment-by,
1455 that contradicts the belief that IN is being incremented
1456 in an address in this insn. */
1457 gcc_assert (rld[i].inc != 0);
1459 #endif
1461 /* If we will replace IN and OUT with the reload-reg,
1462 record where they are located so that substitution need
1463 not do a tree walk. */
1465 if (replace_reloads)
1467 if (inloc != 0)
1469 struct replacement *r = &replacements[n_replacements++];
1470 r->what = i;
1471 r->subreg_loc = in_subreg_loc;
1472 r->where = inloc;
1473 r->mode = inmode;
1475 if (outloc != 0 && outloc != inloc)
1477 struct replacement *r = &replacements[n_replacements++];
1478 r->what = i;
1479 r->where = outloc;
1480 r->subreg_loc = out_subreg_loc;
1481 r->mode = outmode;
1485 /* If this reload is just being introduced and it has both
1486 an incoming quantity and an outgoing quantity that are
1487 supposed to be made to match, see if either one of the two
1488 can serve as the place to reload into.
1490 If one of them is acceptable, set rld[i].reg_rtx
1491 to that one. */
1493 if (in != 0 && out != 0 && in != out && rld[i].reg_rtx == 0)
1495 rld[i].reg_rtx = find_dummy_reload (in, out, inloc, outloc,
1496 inmode, outmode,
1497 rld[i].class, i,
1498 earlyclobber_operand_p (out));
1500 /* If the outgoing register already contains the same value
1501 as the incoming one, we can dispense with loading it.
1502 The easiest way to tell the caller that is to give a phony
1503 value for the incoming operand (same as outgoing one). */
1504 if (rld[i].reg_rtx == out
1505 && (REG_P (in) || CONSTANT_P (in))
1506 && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
1507 static_reload_reg_p, i, inmode))
1508 rld[i].in = out;
1511 /* If this is an input reload and the operand contains a register that
1512 dies in this insn and is used nowhere else, see if it is the right class
1513 to be used for this reload. Use it if so. (This occurs most commonly
1514 in the case of paradoxical SUBREGs and in-out reloads). We cannot do
1515 this if it is also an output reload that mentions the register unless
1516 the output is a SUBREG that clobbers an entire register.
1518 Note that the operand might be one of the spill regs, if it is a
1519 pseudo reg and we are in a block where spilling has not taken place.
1520 But if there is no spilling in this block, that is OK.
1521 An explicitly used hard reg cannot be a spill reg. */
1523 if (rld[i].reg_rtx == 0 && in != 0 && hard_regs_live_known)
1525 rtx note;
1526 int regno;
1527 enum machine_mode rel_mode = inmode;
1529 if (out && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (inmode))
1530 rel_mode = outmode;
1532 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1533 if (REG_NOTE_KIND (note) == REG_DEAD
1534 && REG_P (XEXP (note, 0))
1535 && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER
1536 && reg_mentioned_p (XEXP (note, 0), in)
1537 /* Check that we don't use a hardreg for an uninitialized
1538 pseudo. See also find_dummy_reload(). */
1539 && (ORIGINAL_REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1540 || ! bitmap_bit_p (ENTRY_BLOCK_PTR->il.rtl->global_live_at_end,
1541 ORIGINAL_REGNO (XEXP (note, 0))))
1542 && ! refers_to_regno_for_reload_p (regno,
1543 (regno
1544 + hard_regno_nregs[regno]
1545 [rel_mode]),
1546 PATTERN (this_insn), inloc)
1547 /* If this is also an output reload, IN cannot be used as
1548 the reload register if it is set in this insn unless IN
1549 is also OUT. */
1550 && (out == 0 || in == out
1551 || ! hard_reg_set_here_p (regno,
1552 (regno
1553 + hard_regno_nregs[regno]
1554 [rel_mode]),
1555 PATTERN (this_insn)))
1556 /* ??? Why is this code so different from the previous?
1557 Is there any simple coherent way to describe the two together?
1558 What's going on here. */
1559 && (in != out
1560 || (GET_CODE (in) == SUBREG
1561 && (((GET_MODE_SIZE (GET_MODE (in)) + (UNITS_PER_WORD - 1))
1562 / UNITS_PER_WORD)
1563 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1564 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
1565 /* Make sure the operand fits in the reg that dies. */
1566 && (GET_MODE_SIZE (rel_mode)
1567 <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0))))
1568 && HARD_REGNO_MODE_OK (regno, inmode)
1569 && HARD_REGNO_MODE_OK (regno, outmode))
1571 unsigned int offs;
1572 unsigned int nregs = MAX (hard_regno_nregs[regno][inmode],
1573 hard_regno_nregs[regno][outmode]);
1575 for (offs = 0; offs < nregs; offs++)
1576 if (fixed_regs[regno + offs]
1577 || ! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1578 regno + offs))
1579 break;
1581 if (offs == nregs
1582 && (! (refers_to_regno_for_reload_p
1583 (regno, (regno + hard_regno_nregs[regno][inmode]),
1584 in, (rtx *)0))
1585 || can_reload_into (in, regno, inmode)))
1587 rld[i].reg_rtx = gen_rtx_REG (rel_mode, regno);
1588 break;
1593 if (out)
1594 output_reloadnum = i;
1596 return i;
1599 /* Record an additional place we must replace a value
1600 for which we have already recorded a reload.
1601 RELOADNUM is the value returned by push_reload
1602 when the reload was recorded.
1603 This is used in insn patterns that use match_dup. */
1605 static void
1606 push_replacement (rtx *loc, int reloadnum, enum machine_mode mode)
1608 if (replace_reloads)
1610 struct replacement *r = &replacements[n_replacements++];
1611 r->what = reloadnum;
1612 r->where = loc;
1613 r->subreg_loc = 0;
1614 r->mode = mode;
1618 /* Duplicate any replacement we have recorded to apply at
1619 location ORIG_LOC to also be performed at DUP_LOC.
1620 This is used in insn patterns that use match_dup. */
1622 static void
1623 dup_replacements (rtx *dup_loc, rtx *orig_loc)
1625 int i, n = n_replacements;
1627 for (i = 0; i < n; i++)
1629 struct replacement *r = &replacements[i];
1630 if (r->where == orig_loc)
1631 push_replacement (dup_loc, r->what, r->mode);
1635 /* Transfer all replacements that used to be in reload FROM to be in
1636 reload TO. */
1638 void
1639 transfer_replacements (int to, int from)
1641 int i;
1643 for (i = 0; i < n_replacements; i++)
1644 if (replacements[i].what == from)
1645 replacements[i].what = to;
1648 /* IN_RTX is the value loaded by a reload that we now decided to inherit,
1649 or a subpart of it. If we have any replacements registered for IN_RTX,
1650 cancel the reloads that were supposed to load them.
1651 Return nonzero if we canceled any reloads. */
1653 remove_address_replacements (rtx in_rtx)
1655 int i, j;
1656 char reload_flags[MAX_RELOADS];
1657 int something_changed = 0;
1659 memset (reload_flags, 0, sizeof reload_flags);
1660 for (i = 0, j = 0; i < n_replacements; i++)
1662 if (loc_mentioned_in_p (replacements[i].where, in_rtx))
1663 reload_flags[replacements[i].what] |= 1;
1664 else
1666 replacements[j++] = replacements[i];
1667 reload_flags[replacements[i].what] |= 2;
1670 /* Note that the following store must be done before the recursive calls. */
1671 n_replacements = j;
1673 for (i = n_reloads - 1; i >= 0; i--)
1675 if (reload_flags[i] == 1)
1677 deallocate_reload_reg (i);
1678 remove_address_replacements (rld[i].in);
1679 rld[i].in = 0;
1680 something_changed = 1;
1683 return something_changed;
1686 /* If there is only one output reload, and it is not for an earlyclobber
1687 operand, try to combine it with a (logically unrelated) input reload
1688 to reduce the number of reload registers needed.
1690 This is safe if the input reload does not appear in
1691 the value being output-reloaded, because this implies
1692 it is not needed any more once the original insn completes.
1694 If that doesn't work, see we can use any of the registers that
1695 die in this insn as a reload register. We can if it is of the right
1696 class and does not appear in the value being output-reloaded. */
1698 static void
1699 combine_reloads (void)
1701 int i;
1702 int output_reload = -1;
1703 int secondary_out = -1;
1704 rtx note;
1706 /* Find the output reload; return unless there is exactly one
1707 and that one is mandatory. */
1709 for (i = 0; i < n_reloads; i++)
1710 if (rld[i].out != 0)
1712 if (output_reload >= 0)
1713 return;
1714 output_reload = i;
1717 if (output_reload < 0 || rld[output_reload].optional)
1718 return;
1720 /* An input-output reload isn't combinable. */
1722 if (rld[output_reload].in != 0)
1723 return;
1725 /* If this reload is for an earlyclobber operand, we can't do anything. */
1726 if (earlyclobber_operand_p (rld[output_reload].out))
1727 return;
1729 /* If there is a reload for part of the address of this operand, we would
1730 need to chnage it to RELOAD_FOR_OTHER_ADDRESS. But that would extend
1731 its life to the point where doing this combine would not lower the
1732 number of spill registers needed. */
1733 for (i = 0; i < n_reloads; i++)
1734 if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
1735 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
1736 && rld[i].opnum == rld[output_reload].opnum)
1737 return;
1739 /* Check each input reload; can we combine it? */
1741 for (i = 0; i < n_reloads; i++)
1742 if (rld[i].in && ! rld[i].optional && ! rld[i].nocombine
1743 /* Life span of this reload must not extend past main insn. */
1744 && rld[i].when_needed != RELOAD_FOR_OUTPUT_ADDRESS
1745 && rld[i].when_needed != RELOAD_FOR_OUTADDR_ADDRESS
1746 && rld[i].when_needed != RELOAD_OTHER
1747 && (CLASS_MAX_NREGS (rld[i].class, rld[i].inmode)
1748 == CLASS_MAX_NREGS (rld[output_reload].class,
1749 rld[output_reload].outmode))
1750 && rld[i].inc == 0
1751 && rld[i].reg_rtx == 0
1752 #ifdef SECONDARY_MEMORY_NEEDED
1753 /* Don't combine two reloads with different secondary
1754 memory locations. */
1755 && (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum] == 0
1756 || secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] == 0
1757 || rtx_equal_p (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum],
1758 secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum]))
1759 #endif
1760 && (SMALL_REGISTER_CLASSES
1761 ? (rld[i].class == rld[output_reload].class)
1762 : (reg_class_subset_p (rld[i].class,
1763 rld[output_reload].class)
1764 || reg_class_subset_p (rld[output_reload].class,
1765 rld[i].class)))
1766 && (MATCHES (rld[i].in, rld[output_reload].out)
1767 /* Args reversed because the first arg seems to be
1768 the one that we imagine being modified
1769 while the second is the one that might be affected. */
1770 || (! reg_overlap_mentioned_for_reload_p (rld[output_reload].out,
1771 rld[i].in)
1772 /* However, if the input is a register that appears inside
1773 the output, then we also can't share.
1774 Imagine (set (mem (reg 69)) (plus (reg 69) ...)).
1775 If the same reload reg is used for both reg 69 and the
1776 result to be stored in memory, then that result
1777 will clobber the address of the memory ref. */
1778 && ! (REG_P (rld[i].in)
1779 && reg_overlap_mentioned_for_reload_p (rld[i].in,
1780 rld[output_reload].out))))
1781 && ! reload_inner_reg_of_subreg (rld[i].in, rld[i].inmode,
1782 rld[i].when_needed != RELOAD_FOR_INPUT)
1783 && (reg_class_size[(int) rld[i].class]
1784 || SMALL_REGISTER_CLASSES)
1785 /* We will allow making things slightly worse by combining an
1786 input and an output, but no worse than that. */
1787 && (rld[i].when_needed == RELOAD_FOR_INPUT
1788 || rld[i].when_needed == RELOAD_FOR_OUTPUT))
1790 int j;
1792 /* We have found a reload to combine with! */
1793 rld[i].out = rld[output_reload].out;
1794 rld[i].out_reg = rld[output_reload].out_reg;
1795 rld[i].outmode = rld[output_reload].outmode;
1796 /* Mark the old output reload as inoperative. */
1797 rld[output_reload].out = 0;
1798 /* The combined reload is needed for the entire insn. */
1799 rld[i].when_needed = RELOAD_OTHER;
1800 /* If the output reload had a secondary reload, copy it. */
1801 if (rld[output_reload].secondary_out_reload != -1)
1803 rld[i].secondary_out_reload
1804 = rld[output_reload].secondary_out_reload;
1805 rld[i].secondary_out_icode
1806 = rld[output_reload].secondary_out_icode;
1809 #ifdef SECONDARY_MEMORY_NEEDED
1810 /* Copy any secondary MEM. */
1811 if (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] != 0)
1812 secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum]
1813 = secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum];
1814 #endif
1815 /* If required, minimize the register class. */
1816 if (reg_class_subset_p (rld[output_reload].class,
1817 rld[i].class))
1818 rld[i].class = rld[output_reload].class;
1820 /* Transfer all replacements from the old reload to the combined. */
1821 for (j = 0; j < n_replacements; j++)
1822 if (replacements[j].what == output_reload)
1823 replacements[j].what = i;
1825 return;
1828 /* If this insn has only one operand that is modified or written (assumed
1829 to be the first), it must be the one corresponding to this reload. It
1830 is safe to use anything that dies in this insn for that output provided
1831 that it does not occur in the output (we already know it isn't an
1832 earlyclobber. If this is an asm insn, give up. */
1834 if (INSN_CODE (this_insn) == -1)
1835 return;
1837 for (i = 1; i < insn_data[INSN_CODE (this_insn)].n_operands; i++)
1838 if (insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '='
1839 || insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '+')
1840 return;
1842 /* See if some hard register that dies in this insn and is not used in
1843 the output is the right class. Only works if the register we pick
1844 up can fully hold our output reload. */
1845 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1846 if (REG_NOTE_KIND (note) == REG_DEAD
1847 && REG_P (XEXP (note, 0))
1848 && ! reg_overlap_mentioned_for_reload_p (XEXP (note, 0),
1849 rld[output_reload].out)
1850 && REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1851 && HARD_REGNO_MODE_OK (REGNO (XEXP (note, 0)), rld[output_reload].outmode)
1852 && TEST_HARD_REG_BIT (reg_class_contents[(int) rld[output_reload].class],
1853 REGNO (XEXP (note, 0)))
1854 && (hard_regno_nregs[REGNO (XEXP (note, 0))][rld[output_reload].outmode]
1855 <= hard_regno_nregs[REGNO (XEXP (note, 0))][GET_MODE (XEXP (note, 0))])
1856 /* Ensure that a secondary or tertiary reload for this output
1857 won't want this register. */
1858 && ((secondary_out = rld[output_reload].secondary_out_reload) == -1
1859 || (! (TEST_HARD_REG_BIT
1860 (reg_class_contents[(int) rld[secondary_out].class],
1861 REGNO (XEXP (note, 0))))
1862 && ((secondary_out = rld[secondary_out].secondary_out_reload) == -1
1863 || ! (TEST_HARD_REG_BIT
1864 (reg_class_contents[(int) rld[secondary_out].class],
1865 REGNO (XEXP (note, 0)))))))
1866 && ! fixed_regs[REGNO (XEXP (note, 0))])
1868 rld[output_reload].reg_rtx
1869 = gen_rtx_REG (rld[output_reload].outmode,
1870 REGNO (XEXP (note, 0)));
1871 return;
1875 /* Try to find a reload register for an in-out reload (expressions IN and OUT).
1876 See if one of IN and OUT is a register that may be used;
1877 this is desirable since a spill-register won't be needed.
1878 If so, return the register rtx that proves acceptable.
1880 INLOC and OUTLOC are locations where IN and OUT appear in the insn.
1881 CLASS is the register class required for the reload.
1883 If FOR_REAL is >= 0, it is the number of the reload,
1884 and in some cases when it can be discovered that OUT doesn't need
1885 to be computed, clear out rld[FOR_REAL].out.
1887 If FOR_REAL is -1, this should not be done, because this call
1888 is just to see if a register can be found, not to find and install it.
1890 EARLYCLOBBER is nonzero if OUT is an earlyclobber operand. This
1891 puts an additional constraint on being able to use IN for OUT since
1892 IN must not appear elsewhere in the insn (it is assumed that IN itself
1893 is safe from the earlyclobber). */
1895 static rtx
1896 find_dummy_reload (rtx real_in, rtx real_out, rtx *inloc, rtx *outloc,
1897 enum machine_mode inmode, enum machine_mode outmode,
1898 enum reg_class class, int for_real, int earlyclobber)
1900 rtx in = real_in;
1901 rtx out = real_out;
1902 int in_offset = 0;
1903 int out_offset = 0;
1904 rtx value = 0;
1906 /* If operands exceed a word, we can't use either of them
1907 unless they have the same size. */
1908 if (GET_MODE_SIZE (outmode) != GET_MODE_SIZE (inmode)
1909 && (GET_MODE_SIZE (outmode) > UNITS_PER_WORD
1910 || GET_MODE_SIZE (inmode) > UNITS_PER_WORD))
1911 return 0;
1913 /* Note that {in,out}_offset are needed only when 'in' or 'out'
1914 respectively refers to a hard register. */
1916 /* Find the inside of any subregs. */
1917 while (GET_CODE (out) == SUBREG)
1919 if (REG_P (SUBREG_REG (out))
1920 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER)
1921 out_offset += subreg_regno_offset (REGNO (SUBREG_REG (out)),
1922 GET_MODE (SUBREG_REG (out)),
1923 SUBREG_BYTE (out),
1924 GET_MODE (out));
1925 out = SUBREG_REG (out);
1927 while (GET_CODE (in) == SUBREG)
1929 if (REG_P (SUBREG_REG (in))
1930 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER)
1931 in_offset += subreg_regno_offset (REGNO (SUBREG_REG (in)),
1932 GET_MODE (SUBREG_REG (in)),
1933 SUBREG_BYTE (in),
1934 GET_MODE (in));
1935 in = SUBREG_REG (in);
1938 /* Narrow down the reg class, the same way push_reload will;
1939 otherwise we might find a dummy now, but push_reload won't. */
1940 class = PREFERRED_RELOAD_CLASS (in, class);
1942 /* See if OUT will do. */
1943 if (REG_P (out)
1944 && REGNO (out) < FIRST_PSEUDO_REGISTER)
1946 unsigned int regno = REGNO (out) + out_offset;
1947 unsigned int nwords = hard_regno_nregs[regno][outmode];
1948 rtx saved_rtx;
1950 /* When we consider whether the insn uses OUT,
1951 ignore references within IN. They don't prevent us
1952 from copying IN into OUT, because those refs would
1953 move into the insn that reloads IN.
1955 However, we only ignore IN in its role as this reload.
1956 If the insn uses IN elsewhere and it contains OUT,
1957 that counts. We can't be sure it's the "same" operand
1958 so it might not go through this reload. */
1959 saved_rtx = *inloc;
1960 *inloc = const0_rtx;
1962 if (regno < FIRST_PSEUDO_REGISTER
1963 && HARD_REGNO_MODE_OK (regno, outmode)
1964 && ! refers_to_regno_for_reload_p (regno, regno + nwords,
1965 PATTERN (this_insn), outloc))
1967 unsigned int i;
1969 for (i = 0; i < nwords; i++)
1970 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1971 regno + i))
1972 break;
1974 if (i == nwords)
1976 if (REG_P (real_out))
1977 value = real_out;
1978 else
1979 value = gen_rtx_REG (outmode, regno);
1983 *inloc = saved_rtx;
1986 /* Consider using IN if OUT was not acceptable
1987 or if OUT dies in this insn (like the quotient in a divmod insn).
1988 We can't use IN unless it is dies in this insn,
1989 which means we must know accurately which hard regs are live.
1990 Also, the result can't go in IN if IN is used within OUT,
1991 or if OUT is an earlyclobber and IN appears elsewhere in the insn. */
1992 if (hard_regs_live_known
1993 && REG_P (in)
1994 && REGNO (in) < FIRST_PSEUDO_REGISTER
1995 && (value == 0
1996 || find_reg_note (this_insn, REG_UNUSED, real_out))
1997 && find_reg_note (this_insn, REG_DEAD, real_in)
1998 && !fixed_regs[REGNO (in)]
1999 && HARD_REGNO_MODE_OK (REGNO (in),
2000 /* The only case where out and real_out might
2001 have different modes is where real_out
2002 is a subreg, and in that case, out
2003 has a real mode. */
2004 (GET_MODE (out) != VOIDmode
2005 ? GET_MODE (out) : outmode))
2006 /* But only do all this if we can be sure, that this input
2007 operand doesn't correspond with an uninitialized pseudoreg.
2008 global can assign some hardreg to it, which is the same as
2009 a different pseudo also currently live (as it can ignore the
2010 conflict). So we never must introduce writes to such hardregs,
2011 as they would clobber the other live pseudo using the same.
2012 See also PR20973. */
2013 && (ORIGINAL_REGNO (in) < FIRST_PSEUDO_REGISTER
2014 || ! bitmap_bit_p (ENTRY_BLOCK_PTR->il.rtl->global_live_at_end,
2015 ORIGINAL_REGNO (in))))
2017 unsigned int regno = REGNO (in) + in_offset;
2018 unsigned int nwords = hard_regno_nregs[regno][inmode];
2020 if (! refers_to_regno_for_reload_p (regno, regno + nwords, out, (rtx*) 0)
2021 && ! hard_reg_set_here_p (regno, regno + nwords,
2022 PATTERN (this_insn))
2023 && (! earlyclobber
2024 || ! refers_to_regno_for_reload_p (regno, regno + nwords,
2025 PATTERN (this_insn), inloc)))
2027 unsigned int i;
2029 for (i = 0; i < nwords; i++)
2030 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
2031 regno + i))
2032 break;
2034 if (i == nwords)
2036 /* If we were going to use OUT as the reload reg
2037 and changed our mind, it means OUT is a dummy that
2038 dies here. So don't bother copying value to it. */
2039 if (for_real >= 0 && value == real_out)
2040 rld[for_real].out = 0;
2041 if (REG_P (real_in))
2042 value = real_in;
2043 else
2044 value = gen_rtx_REG (inmode, regno);
2049 return value;
2052 /* This page contains subroutines used mainly for determining
2053 whether the IN or an OUT of a reload can serve as the
2054 reload register. */
2056 /* Return 1 if X is an operand of an insn that is being earlyclobbered. */
2059 earlyclobber_operand_p (rtx x)
2061 int i;
2063 for (i = 0; i < n_earlyclobbers; i++)
2064 if (reload_earlyclobbers[i] == x)
2065 return 1;
2067 return 0;
2070 /* Return 1 if expression X alters a hard reg in the range
2071 from BEG_REGNO (inclusive) to END_REGNO (exclusive),
2072 either explicitly or in the guise of a pseudo-reg allocated to REGNO.
2073 X should be the body of an instruction. */
2075 static int
2076 hard_reg_set_here_p (unsigned int beg_regno, unsigned int end_regno, rtx x)
2078 if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
2080 rtx op0 = SET_DEST (x);
2082 while (GET_CODE (op0) == SUBREG)
2083 op0 = SUBREG_REG (op0);
2084 if (REG_P (op0))
2086 unsigned int r = REGNO (op0);
2088 /* See if this reg overlaps range under consideration. */
2089 if (r < end_regno
2090 && r + hard_regno_nregs[r][GET_MODE (op0)] > beg_regno)
2091 return 1;
2094 else if (GET_CODE (x) == PARALLEL)
2096 int i = XVECLEN (x, 0) - 1;
2098 for (; i >= 0; i--)
2099 if (hard_reg_set_here_p (beg_regno, end_regno, XVECEXP (x, 0, i)))
2100 return 1;
2103 return 0;
2106 /* Return 1 if ADDR is a valid memory address for mode MODE,
2107 and check that each pseudo reg has the proper kind of
2108 hard reg. */
2111 strict_memory_address_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx addr)
2113 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
2114 return 0;
2116 win:
2117 return 1;
2120 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
2121 if they are the same hard reg, and has special hacks for
2122 autoincrement and autodecrement.
2123 This is specifically intended for find_reloads to use
2124 in determining whether two operands match.
2125 X is the operand whose number is the lower of the two.
2127 The value is 2 if Y contains a pre-increment that matches
2128 a non-incrementing address in X. */
2130 /* ??? To be completely correct, we should arrange to pass
2131 for X the output operand and for Y the input operand.
2132 For now, we assume that the output operand has the lower number
2133 because that is natural in (SET output (... input ...)). */
2136 operands_match_p (rtx x, rtx y)
2138 int i;
2139 RTX_CODE code = GET_CODE (x);
2140 const char *fmt;
2141 int success_2;
2143 if (x == y)
2144 return 1;
2145 if ((code == REG || (code == SUBREG && REG_P (SUBREG_REG (x))))
2146 && (REG_P (y) || (GET_CODE (y) == SUBREG
2147 && REG_P (SUBREG_REG (y)))))
2149 int j;
2151 if (code == SUBREG)
2153 i = REGNO (SUBREG_REG (x));
2154 if (i >= FIRST_PSEUDO_REGISTER)
2155 goto slow;
2156 i += subreg_regno_offset (REGNO (SUBREG_REG (x)),
2157 GET_MODE (SUBREG_REG (x)),
2158 SUBREG_BYTE (x),
2159 GET_MODE (x));
2161 else
2162 i = REGNO (x);
2164 if (GET_CODE (y) == SUBREG)
2166 j = REGNO (SUBREG_REG (y));
2167 if (j >= FIRST_PSEUDO_REGISTER)
2168 goto slow;
2169 j += subreg_regno_offset (REGNO (SUBREG_REG (y)),
2170 GET_MODE (SUBREG_REG (y)),
2171 SUBREG_BYTE (y),
2172 GET_MODE (y));
2174 else
2175 j = REGNO (y);
2177 /* On a WORDS_BIG_ENDIAN machine, point to the last register of a
2178 multiple hard register group of scalar integer registers, so that
2179 for example (reg:DI 0) and (reg:SI 1) will be considered the same
2180 register. */
2181 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
2182 && SCALAR_INT_MODE_P (GET_MODE (x))
2183 && i < FIRST_PSEUDO_REGISTER)
2184 i += hard_regno_nregs[i][GET_MODE (x)] - 1;
2185 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (y)) > UNITS_PER_WORD
2186 && SCALAR_INT_MODE_P (GET_MODE (y))
2187 && j < FIRST_PSEUDO_REGISTER)
2188 j += hard_regno_nregs[j][GET_MODE (y)] - 1;
2190 return i == j;
2192 /* If two operands must match, because they are really a single
2193 operand of an assembler insn, then two postincrements are invalid
2194 because the assembler insn would increment only once.
2195 On the other hand, a postincrement matches ordinary indexing
2196 if the postincrement is the output operand. */
2197 if (code == POST_DEC || code == POST_INC || code == POST_MODIFY)
2198 return operands_match_p (XEXP (x, 0), y);
2199 /* Two preincrements are invalid
2200 because the assembler insn would increment only once.
2201 On the other hand, a preincrement matches ordinary indexing
2202 if the preincrement is the input operand.
2203 In this case, return 2, since some callers need to do special
2204 things when this happens. */
2205 if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC
2206 || GET_CODE (y) == PRE_MODIFY)
2207 return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
2209 slow:
2211 /* Now we have disposed of all the cases in which different rtx codes
2212 can match. */
2213 if (code != GET_CODE (y))
2214 return 0;
2216 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
2217 if (GET_MODE (x) != GET_MODE (y))
2218 return 0;
2220 switch (code)
2222 case CONST_INT:
2223 case CONST_DOUBLE:
2224 return 0;
2226 case LABEL_REF:
2227 return XEXP (x, 0) == XEXP (y, 0);
2228 case SYMBOL_REF:
2229 return XSTR (x, 0) == XSTR (y, 0);
2231 default:
2232 break;
2235 /* Compare the elements. If any pair of corresponding elements
2236 fail to match, return 0 for the whole things. */
2238 success_2 = 0;
2239 fmt = GET_RTX_FORMAT (code);
2240 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2242 int val, j;
2243 switch (fmt[i])
2245 case 'w':
2246 if (XWINT (x, i) != XWINT (y, i))
2247 return 0;
2248 break;
2250 case 'i':
2251 if (XINT (x, i) != XINT (y, i))
2252 return 0;
2253 break;
2255 case 'e':
2256 val = operands_match_p (XEXP (x, i), XEXP (y, i));
2257 if (val == 0)
2258 return 0;
2259 /* If any subexpression returns 2,
2260 we should return 2 if we are successful. */
2261 if (val == 2)
2262 success_2 = 1;
2263 break;
2265 case '0':
2266 break;
2268 case 'E':
2269 if (XVECLEN (x, i) != XVECLEN (y, i))
2270 return 0;
2271 for (j = XVECLEN (x, i) - 1; j >= 0; --j)
2273 val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j));
2274 if (val == 0)
2275 return 0;
2276 if (val == 2)
2277 success_2 = 1;
2279 break;
2281 /* It is believed that rtx's at this level will never
2282 contain anything but integers and other rtx's,
2283 except for within LABEL_REFs and SYMBOL_REFs. */
2284 default:
2285 gcc_unreachable ();
2288 return 1 + success_2;
2291 /* Describe the range of registers or memory referenced by X.
2292 If X is a register, set REG_FLAG and put the first register
2293 number into START and the last plus one into END.
2294 If X is a memory reference, put a base address into BASE
2295 and a range of integer offsets into START and END.
2296 If X is pushing on the stack, we can assume it causes no trouble,
2297 so we set the SAFE field. */
2299 static struct decomposition
2300 decompose (rtx x)
2302 struct decomposition val;
2303 int all_const = 0;
2305 memset (&val, 0, sizeof (val));
2307 switch (GET_CODE (x))
2309 case MEM:
2311 rtx base = NULL_RTX, offset = 0;
2312 rtx addr = XEXP (x, 0);
2314 if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
2315 || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
2317 val.base = XEXP (addr, 0);
2318 val.start = -GET_MODE_SIZE (GET_MODE (x));
2319 val.end = GET_MODE_SIZE (GET_MODE (x));
2320 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2321 return val;
2324 if (GET_CODE (addr) == PRE_MODIFY || GET_CODE (addr) == POST_MODIFY)
2326 if (GET_CODE (XEXP (addr, 1)) == PLUS
2327 && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0)
2328 && CONSTANT_P (XEXP (XEXP (addr, 1), 1)))
2330 val.base = XEXP (addr, 0);
2331 val.start = -INTVAL (XEXP (XEXP (addr, 1), 1));
2332 val.end = INTVAL (XEXP (XEXP (addr, 1), 1));
2333 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2334 return val;
2338 if (GET_CODE (addr) == CONST)
2340 addr = XEXP (addr, 0);
2341 all_const = 1;
2343 if (GET_CODE (addr) == PLUS)
2345 if (CONSTANT_P (XEXP (addr, 0)))
2347 base = XEXP (addr, 1);
2348 offset = XEXP (addr, 0);
2350 else if (CONSTANT_P (XEXP (addr, 1)))
2352 base = XEXP (addr, 0);
2353 offset = XEXP (addr, 1);
2357 if (offset == 0)
2359 base = addr;
2360 offset = const0_rtx;
2362 if (GET_CODE (offset) == CONST)
2363 offset = XEXP (offset, 0);
2364 if (GET_CODE (offset) == PLUS)
2366 if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
2368 base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 1));
2369 offset = XEXP (offset, 0);
2371 else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
2373 base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 0));
2374 offset = XEXP (offset, 1);
2376 else
2378 base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2379 offset = const0_rtx;
2382 else if (GET_CODE (offset) != CONST_INT)
2384 base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2385 offset = const0_rtx;
2388 if (all_const && GET_CODE (base) == PLUS)
2389 base = gen_rtx_CONST (GET_MODE (base), base);
2391 gcc_assert (GET_CODE (offset) == CONST_INT);
2393 val.start = INTVAL (offset);
2394 val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
2395 val.base = base;
2397 break;
2399 case REG:
2400 val.reg_flag = 1;
2401 val.start = true_regnum (x);
2402 if (val.start < 0 || val.start >= FIRST_PSEUDO_REGISTER)
2404 /* A pseudo with no hard reg. */
2405 val.start = REGNO (x);
2406 val.end = val.start + 1;
2408 else
2409 /* A hard reg. */
2410 val.end = val.start + hard_regno_nregs[val.start][GET_MODE (x)];
2411 break;
2413 case SUBREG:
2414 if (!REG_P (SUBREG_REG (x)))
2415 /* This could be more precise, but it's good enough. */
2416 return decompose (SUBREG_REG (x));
2417 val.reg_flag = 1;
2418 val.start = true_regnum (x);
2419 if (val.start < 0 || val.start >= FIRST_PSEUDO_REGISTER)
2420 return decompose (SUBREG_REG (x));
2421 else
2422 /* A hard reg. */
2423 val.end = val.start + hard_regno_nregs[val.start][GET_MODE (x)];
2424 break;
2426 case SCRATCH:
2427 /* This hasn't been assigned yet, so it can't conflict yet. */
2428 val.safe = 1;
2429 break;
2431 default:
2432 gcc_assert (CONSTANT_P (x));
2433 val.safe = 1;
2434 break;
2436 return val;
2439 /* Return 1 if altering Y will not modify the value of X.
2440 Y is also described by YDATA, which should be decompose (Y). */
2442 static int
2443 immune_p (rtx x, rtx y, struct decomposition ydata)
2445 struct decomposition xdata;
2447 if (ydata.reg_flag)
2448 return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, (rtx*) 0);
2449 if (ydata.safe)
2450 return 1;
2452 gcc_assert (MEM_P (y));
2453 /* If Y is memory and X is not, Y can't affect X. */
2454 if (!MEM_P (x))
2455 return 1;
2457 xdata = decompose (x);
2459 if (! rtx_equal_p (xdata.base, ydata.base))
2461 /* If bases are distinct symbolic constants, there is no overlap. */
2462 if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
2463 return 1;
2464 /* Constants and stack slots never overlap. */
2465 if (CONSTANT_P (xdata.base)
2466 && (ydata.base == frame_pointer_rtx
2467 || ydata.base == hard_frame_pointer_rtx
2468 || ydata.base == stack_pointer_rtx))
2469 return 1;
2470 if (CONSTANT_P (ydata.base)
2471 && (xdata.base == frame_pointer_rtx
2472 || xdata.base == hard_frame_pointer_rtx
2473 || xdata.base == stack_pointer_rtx))
2474 return 1;
2475 /* If either base is variable, we don't know anything. */
2476 return 0;
2479 return (xdata.start >= ydata.end || ydata.start >= xdata.end);
2482 /* Similar, but calls decompose. */
2485 safe_from_earlyclobber (rtx op, rtx clobber)
2487 struct decomposition early_data;
2489 early_data = decompose (clobber);
2490 return immune_p (op, clobber, early_data);
2493 /* Main entry point of this file: search the body of INSN
2494 for values that need reloading and record them with push_reload.
2495 REPLACE nonzero means record also where the values occur
2496 so that subst_reloads can be used.
2498 IND_LEVELS says how many levels of indirection are supported by this
2499 machine; a value of zero means that a memory reference is not a valid
2500 memory address.
2502 LIVE_KNOWN says we have valid information about which hard
2503 regs are live at each point in the program; this is true when
2504 we are called from global_alloc but false when stupid register
2505 allocation has been done.
2507 RELOAD_REG_P if nonzero is a vector indexed by hard reg number
2508 which is nonnegative if the reg has been commandeered for reloading into.
2509 It is copied into STATIC_RELOAD_REG_P and referenced from there
2510 by various subroutines.
2512 Return TRUE if some operands need to be changed, because of swapping
2513 commutative operands, reg_equiv_address substitution, or whatever. */
2516 find_reloads (rtx insn, int replace, int ind_levels, int live_known,
2517 short *reload_reg_p)
2519 int insn_code_number;
2520 int i, j;
2521 int noperands;
2522 /* These start out as the constraints for the insn
2523 and they are chewed up as we consider alternatives. */
2524 char *constraints[MAX_RECOG_OPERANDS];
2525 /* These are the preferred classes for an operand, or NO_REGS if it isn't
2526 a register. */
2527 enum reg_class preferred_class[MAX_RECOG_OPERANDS];
2528 char pref_or_nothing[MAX_RECOG_OPERANDS];
2529 /* Nonzero for a MEM operand whose entire address needs a reload.
2530 May be -1 to indicate the entire address may or may not need a reload. */
2531 int address_reloaded[MAX_RECOG_OPERANDS];
2532 /* Nonzero for an address operand that needs to be completely reloaded.
2533 May be -1 to indicate the entire operand may or may not need a reload. */
2534 int address_operand_reloaded[MAX_RECOG_OPERANDS];
2535 /* Value of enum reload_type to use for operand. */
2536 enum reload_type operand_type[MAX_RECOG_OPERANDS];
2537 /* Value of enum reload_type to use within address of operand. */
2538 enum reload_type address_type[MAX_RECOG_OPERANDS];
2539 /* Save the usage of each operand. */
2540 enum reload_usage { RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE } modified[MAX_RECOG_OPERANDS];
2541 int no_input_reloads = 0, no_output_reloads = 0;
2542 int n_alternatives;
2543 int this_alternative[MAX_RECOG_OPERANDS];
2544 char this_alternative_match_win[MAX_RECOG_OPERANDS];
2545 char this_alternative_win[MAX_RECOG_OPERANDS];
2546 char this_alternative_offmemok[MAX_RECOG_OPERANDS];
2547 char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2548 int this_alternative_matches[MAX_RECOG_OPERANDS];
2549 int swapped;
2550 int goal_alternative[MAX_RECOG_OPERANDS];
2551 int this_alternative_number;
2552 int goal_alternative_number = 0;
2553 int operand_reloadnum[MAX_RECOG_OPERANDS];
2554 int goal_alternative_matches[MAX_RECOG_OPERANDS];
2555 int goal_alternative_matched[MAX_RECOG_OPERANDS];
2556 char goal_alternative_match_win[MAX_RECOG_OPERANDS];
2557 char goal_alternative_win[MAX_RECOG_OPERANDS];
2558 char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
2559 char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2560 int goal_alternative_swapped;
2561 int best;
2562 int commutative;
2563 char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
2564 rtx substed_operand[MAX_RECOG_OPERANDS];
2565 rtx body = PATTERN (insn);
2566 rtx set = single_set (insn);
2567 int goal_earlyclobber = 0, this_earlyclobber;
2568 enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
2569 int retval = 0;
2571 this_insn = insn;
2572 n_reloads = 0;
2573 n_replacements = 0;
2574 n_earlyclobbers = 0;
2575 replace_reloads = replace;
2576 hard_regs_live_known = live_known;
2577 static_reload_reg_p = reload_reg_p;
2579 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads;
2580 neither are insns that SET cc0. Insns that use CC0 are not allowed
2581 to have any input reloads. */
2582 if (JUMP_P (insn) || CALL_P (insn))
2583 no_output_reloads = 1;
2585 #ifdef HAVE_cc0
2586 if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
2587 no_input_reloads = 1;
2588 if (reg_set_p (cc0_rtx, PATTERN (insn)))
2589 no_output_reloads = 1;
2590 #endif
2592 #ifdef SECONDARY_MEMORY_NEEDED
2593 /* The eliminated forms of any secondary memory locations are per-insn, so
2594 clear them out here. */
2596 if (secondary_memlocs_elim_used)
2598 memset (secondary_memlocs_elim, 0,
2599 sizeof (secondary_memlocs_elim[0]) * secondary_memlocs_elim_used);
2600 secondary_memlocs_elim_used = 0;
2602 #endif
2604 /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it
2605 is cheap to move between them. If it is not, there may not be an insn
2606 to do the copy, so we may need a reload. */
2607 if (GET_CODE (body) == SET
2608 && REG_P (SET_DEST (body))
2609 && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
2610 && REG_P (SET_SRC (body))
2611 && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER
2612 && REGISTER_MOVE_COST (GET_MODE (SET_SRC (body)),
2613 REGNO_REG_CLASS (REGNO (SET_SRC (body))),
2614 REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2)
2615 return 0;
2617 extract_insn (insn);
2619 noperands = reload_n_operands = recog_data.n_operands;
2620 n_alternatives = recog_data.n_alternatives;
2622 /* Just return "no reloads" if insn has no operands with constraints. */
2623 if (noperands == 0 || n_alternatives == 0)
2624 return 0;
2626 insn_code_number = INSN_CODE (insn);
2627 this_insn_is_asm = insn_code_number < 0;
2629 memcpy (operand_mode, recog_data.operand_mode,
2630 noperands * sizeof (enum machine_mode));
2631 memcpy (constraints, recog_data.constraints, noperands * sizeof (char *));
2633 commutative = -1;
2635 /* If we will need to know, later, whether some pair of operands
2636 are the same, we must compare them now and save the result.
2637 Reloading the base and index registers will clobber them
2638 and afterward they will fail to match. */
2640 for (i = 0; i < noperands; i++)
2642 char *p;
2643 int c;
2645 substed_operand[i] = recog_data.operand[i];
2646 p = constraints[i];
2648 modified[i] = RELOAD_READ;
2650 /* Scan this operand's constraint to see if it is an output operand,
2651 an in-out operand, is commutative, or should match another. */
2653 while ((c = *p))
2655 p += CONSTRAINT_LEN (c, p);
2656 switch (c)
2658 case '=':
2659 modified[i] = RELOAD_WRITE;
2660 break;
2661 case '+':
2662 modified[i] = RELOAD_READ_WRITE;
2663 break;
2664 case '%':
2666 /* The last operand should not be marked commutative. */
2667 gcc_assert (i != noperands - 1);
2669 /* We currently only support one commutative pair of
2670 operands. Some existing asm code currently uses more
2671 than one pair. Previously, that would usually work,
2672 but sometimes it would crash the compiler. We
2673 continue supporting that case as well as we can by
2674 silently ignoring all but the first pair. In the
2675 future we may handle it correctly. */
2676 if (commutative < 0)
2677 commutative = i;
2678 else
2679 gcc_assert (this_insn_is_asm);
2681 break;
2682 /* Use of ISDIGIT is tempting here, but it may get expensive because
2683 of locale support we don't want. */
2684 case '0': case '1': case '2': case '3': case '4':
2685 case '5': case '6': case '7': case '8': case '9':
2687 c = strtoul (p - 1, &p, 10);
2689 operands_match[c][i]
2690 = operands_match_p (recog_data.operand[c],
2691 recog_data.operand[i]);
2693 /* An operand may not match itself. */
2694 gcc_assert (c != i);
2696 /* If C can be commuted with C+1, and C might need to match I,
2697 then C+1 might also need to match I. */
2698 if (commutative >= 0)
2700 if (c == commutative || c == commutative + 1)
2702 int other = c + (c == commutative ? 1 : -1);
2703 operands_match[other][i]
2704 = operands_match_p (recog_data.operand[other],
2705 recog_data.operand[i]);
2707 if (i == commutative || i == commutative + 1)
2709 int other = i + (i == commutative ? 1 : -1);
2710 operands_match[c][other]
2711 = operands_match_p (recog_data.operand[c],
2712 recog_data.operand[other]);
2714 /* Note that C is supposed to be less than I.
2715 No need to consider altering both C and I because in
2716 that case we would alter one into the other. */
2723 /* Examine each operand that is a memory reference or memory address
2724 and reload parts of the addresses into index registers.
2725 Also here any references to pseudo regs that didn't get hard regs
2726 but are equivalent to constants get replaced in the insn itself
2727 with those constants. Nobody will ever see them again.
2729 Finally, set up the preferred classes of each operand. */
2731 for (i = 0; i < noperands; i++)
2733 RTX_CODE code = GET_CODE (recog_data.operand[i]);
2735 address_reloaded[i] = 0;
2736 address_operand_reloaded[i] = 0;
2737 operand_type[i] = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT
2738 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT
2739 : RELOAD_OTHER);
2740 address_type[i]
2741 = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT_ADDRESS
2742 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT_ADDRESS
2743 : RELOAD_OTHER);
2745 if (*constraints[i] == 0)
2746 /* Ignore things like match_operator operands. */
2748 else if (constraints[i][0] == 'p'
2749 || EXTRA_ADDRESS_CONSTRAINT (constraints[i][0], constraints[i]))
2751 address_operand_reloaded[i]
2752 = find_reloads_address (recog_data.operand_mode[i], (rtx*) 0,
2753 recog_data.operand[i],
2754 recog_data.operand_loc[i],
2755 i, operand_type[i], ind_levels, insn);
2757 /* If we now have a simple operand where we used to have a
2758 PLUS or MULT, re-recognize and try again. */
2759 if ((OBJECT_P (*recog_data.operand_loc[i])
2760 || GET_CODE (*recog_data.operand_loc[i]) == SUBREG)
2761 && (GET_CODE (recog_data.operand[i]) == MULT
2762 || GET_CODE (recog_data.operand[i]) == PLUS))
2764 INSN_CODE (insn) = -1;
2765 retval = find_reloads (insn, replace, ind_levels, live_known,
2766 reload_reg_p);
2767 return retval;
2770 recog_data.operand[i] = *recog_data.operand_loc[i];
2771 substed_operand[i] = recog_data.operand[i];
2773 /* Address operands are reloaded in their existing mode,
2774 no matter what is specified in the machine description. */
2775 operand_mode[i] = GET_MODE (recog_data.operand[i]);
2777 else if (code == MEM)
2779 address_reloaded[i]
2780 = find_reloads_address (GET_MODE (recog_data.operand[i]),
2781 recog_data.operand_loc[i],
2782 XEXP (recog_data.operand[i], 0),
2783 &XEXP (recog_data.operand[i], 0),
2784 i, address_type[i], ind_levels, insn);
2785 recog_data.operand[i] = *recog_data.operand_loc[i];
2786 substed_operand[i] = recog_data.operand[i];
2788 else if (code == SUBREG)
2790 rtx reg = SUBREG_REG (recog_data.operand[i]);
2791 rtx op
2792 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2793 ind_levels,
2794 set != 0
2795 && &SET_DEST (set) == recog_data.operand_loc[i],
2796 insn,
2797 &address_reloaded[i]);
2799 /* If we made a MEM to load (a part of) the stackslot of a pseudo
2800 that didn't get a hard register, emit a USE with a REG_EQUAL
2801 note in front so that we might inherit a previous, possibly
2802 wider reload. */
2804 if (replace
2805 && MEM_P (op)
2806 && REG_P (reg)
2807 && (GET_MODE_SIZE (GET_MODE (reg))
2808 >= GET_MODE_SIZE (GET_MODE (op))))
2809 set_unique_reg_note (emit_insn_before (gen_rtx_USE (VOIDmode, reg),
2810 insn),
2811 REG_EQUAL, reg_equiv_memory_loc[REGNO (reg)]);
2813 substed_operand[i] = recog_data.operand[i] = op;
2815 else if (code == PLUS || GET_RTX_CLASS (code) == RTX_UNARY)
2816 /* We can get a PLUS as an "operand" as a result of register
2817 elimination. See eliminate_regs and gen_reload. We handle
2818 a unary operator by reloading the operand. */
2819 substed_operand[i] = recog_data.operand[i]
2820 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2821 ind_levels, 0, insn,
2822 &address_reloaded[i]);
2823 else if (code == REG)
2825 /* This is equivalent to calling find_reloads_toplev.
2826 The code is duplicated for speed.
2827 When we find a pseudo always equivalent to a constant,
2828 we replace it by the constant. We must be sure, however,
2829 that we don't try to replace it in the insn in which it
2830 is being set. */
2831 int regno = REGNO (recog_data.operand[i]);
2832 if (reg_equiv_constant[regno] != 0
2833 && (set == 0 || &SET_DEST (set) != recog_data.operand_loc[i]))
2835 /* Record the existing mode so that the check if constants are
2836 allowed will work when operand_mode isn't specified. */
2838 if (operand_mode[i] == VOIDmode)
2839 operand_mode[i] = GET_MODE (recog_data.operand[i]);
2841 substed_operand[i] = recog_data.operand[i]
2842 = reg_equiv_constant[regno];
2844 if (reg_equiv_memory_loc[regno] != 0
2845 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
2846 /* We need not give a valid is_set_dest argument since the case
2847 of a constant equivalence was checked above. */
2848 substed_operand[i] = recog_data.operand[i]
2849 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2850 ind_levels, 0, insn,
2851 &address_reloaded[i]);
2853 /* If the operand is still a register (we didn't replace it with an
2854 equivalent), get the preferred class to reload it into. */
2855 code = GET_CODE (recog_data.operand[i]);
2856 preferred_class[i]
2857 = ((code == REG && REGNO (recog_data.operand[i])
2858 >= FIRST_PSEUDO_REGISTER)
2859 ? reg_preferred_class (REGNO (recog_data.operand[i]))
2860 : NO_REGS);
2861 pref_or_nothing[i]
2862 = (code == REG
2863 && REGNO (recog_data.operand[i]) >= FIRST_PSEUDO_REGISTER
2864 && reg_alternate_class (REGNO (recog_data.operand[i])) == NO_REGS);
2867 /* If this is simply a copy from operand 1 to operand 0, merge the
2868 preferred classes for the operands. */
2869 if (set != 0 && noperands >= 2 && recog_data.operand[0] == SET_DEST (set)
2870 && recog_data.operand[1] == SET_SRC (set))
2872 preferred_class[0] = preferred_class[1]
2873 = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]];
2874 pref_or_nothing[0] |= pref_or_nothing[1];
2875 pref_or_nothing[1] |= pref_or_nothing[0];
2878 /* Now see what we need for pseudo-regs that didn't get hard regs
2879 or got the wrong kind of hard reg. For this, we must consider
2880 all the operands together against the register constraints. */
2882 best = MAX_RECOG_OPERANDS * 2 + 600;
2884 swapped = 0;
2885 goal_alternative_swapped = 0;
2886 try_swapped:
2888 /* The constraints are made of several alternatives.
2889 Each operand's constraint looks like foo,bar,... with commas
2890 separating the alternatives. The first alternatives for all
2891 operands go together, the second alternatives go together, etc.
2893 First loop over alternatives. */
2895 for (this_alternative_number = 0;
2896 this_alternative_number < n_alternatives;
2897 this_alternative_number++)
2899 /* Loop over operands for one constraint alternative. */
2900 /* LOSERS counts those that don't fit this alternative
2901 and would require loading. */
2902 int losers = 0;
2903 /* BAD is set to 1 if it some operand can't fit this alternative
2904 even after reloading. */
2905 int bad = 0;
2906 /* REJECT is a count of how undesirable this alternative says it is
2907 if any reloading is required. If the alternative matches exactly
2908 then REJECT is ignored, but otherwise it gets this much
2909 counted against it in addition to the reloading needed. Each
2910 ? counts three times here since we want the disparaging caused by
2911 a bad register class to only count 1/3 as much. */
2912 int reject = 0;
2914 this_earlyclobber = 0;
2916 for (i = 0; i < noperands; i++)
2918 char *p = constraints[i];
2919 char *end;
2920 int len;
2921 int win = 0;
2922 int did_match = 0;
2923 /* 0 => this operand can be reloaded somehow for this alternative. */
2924 int badop = 1;
2925 /* 0 => this operand can be reloaded if the alternative allows regs. */
2926 int winreg = 0;
2927 int c;
2928 int m;
2929 rtx operand = recog_data.operand[i];
2930 int offset = 0;
2931 /* Nonzero means this is a MEM that must be reloaded into a reg
2932 regardless of what the constraint says. */
2933 int force_reload = 0;
2934 int offmemok = 0;
2935 /* Nonzero if a constant forced into memory would be OK for this
2936 operand. */
2937 int constmemok = 0;
2938 int earlyclobber = 0;
2940 /* If the predicate accepts a unary operator, it means that
2941 we need to reload the operand, but do not do this for
2942 match_operator and friends. */
2943 if (UNARY_P (operand) && *p != 0)
2944 operand = XEXP (operand, 0);
2946 /* If the operand is a SUBREG, extract
2947 the REG or MEM (or maybe even a constant) within.
2948 (Constants can occur as a result of reg_equiv_constant.) */
2950 while (GET_CODE (operand) == SUBREG)
2952 /* Offset only matters when operand is a REG and
2953 it is a hard reg. This is because it is passed
2954 to reg_fits_class_p if it is a REG and all pseudos
2955 return 0 from that function. */
2956 if (REG_P (SUBREG_REG (operand))
2957 && REGNO (SUBREG_REG (operand)) < FIRST_PSEUDO_REGISTER)
2959 if (!subreg_offset_representable_p
2960 (REGNO (SUBREG_REG (operand)),
2961 GET_MODE (SUBREG_REG (operand)),
2962 SUBREG_BYTE (operand),
2963 GET_MODE (operand)))
2964 force_reload = 1;
2965 offset += subreg_regno_offset (REGNO (SUBREG_REG (operand)),
2966 GET_MODE (SUBREG_REG (operand)),
2967 SUBREG_BYTE (operand),
2968 GET_MODE (operand));
2970 operand = SUBREG_REG (operand);
2971 /* Force reload if this is a constant or PLUS or if there may
2972 be a problem accessing OPERAND in the outer mode. */
2973 if (CONSTANT_P (operand)
2974 || GET_CODE (operand) == PLUS
2975 /* We must force a reload of paradoxical SUBREGs
2976 of a MEM because the alignment of the inner value
2977 may not be enough to do the outer reference. On
2978 big-endian machines, it may also reference outside
2979 the object.
2981 On machines that extend byte operations and we have a
2982 SUBREG where both the inner and outer modes are no wider
2983 than a word and the inner mode is narrower, is integral,
2984 and gets extended when loaded from memory, combine.c has
2985 made assumptions about the behavior of the machine in such
2986 register access. If the data is, in fact, in memory we
2987 must always load using the size assumed to be in the
2988 register and let the insn do the different-sized
2989 accesses.
2991 This is doubly true if WORD_REGISTER_OPERATIONS. In
2992 this case eliminate_regs has left non-paradoxical
2993 subregs for push_reload to see. Make sure it does
2994 by forcing the reload.
2996 ??? When is it right at this stage to have a subreg
2997 of a mem that is _not_ to be handled specially? IMO
2998 those should have been reduced to just a mem. */
2999 || ((MEM_P (operand)
3000 || (REG_P (operand)
3001 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3002 #ifndef WORD_REGISTER_OPERATIONS
3003 && (((GET_MODE_BITSIZE (GET_MODE (operand))
3004 < BIGGEST_ALIGNMENT)
3005 && (GET_MODE_SIZE (operand_mode[i])
3006 > GET_MODE_SIZE (GET_MODE (operand))))
3007 || BYTES_BIG_ENDIAN
3008 #ifdef LOAD_EXTEND_OP
3009 || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3010 && (GET_MODE_SIZE (GET_MODE (operand))
3011 <= UNITS_PER_WORD)
3012 && (GET_MODE_SIZE (operand_mode[i])
3013 > GET_MODE_SIZE (GET_MODE (operand)))
3014 && INTEGRAL_MODE_P (GET_MODE (operand))
3015 && LOAD_EXTEND_OP (GET_MODE (operand)) != UNKNOWN)
3016 #endif
3018 #endif
3021 force_reload = 1;
3024 this_alternative[i] = (int) NO_REGS;
3025 this_alternative_win[i] = 0;
3026 this_alternative_match_win[i] = 0;
3027 this_alternative_offmemok[i] = 0;
3028 this_alternative_earlyclobber[i] = 0;
3029 this_alternative_matches[i] = -1;
3031 /* An empty constraint or empty alternative
3032 allows anything which matched the pattern. */
3033 if (*p == 0 || *p == ',')
3034 win = 1, badop = 0;
3036 /* Scan this alternative's specs for this operand;
3037 set WIN if the operand fits any letter in this alternative.
3038 Otherwise, clear BADOP if this operand could
3039 fit some letter after reloads,
3040 or set WINREG if this operand could fit after reloads
3041 provided the constraint allows some registers. */
3044 switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
3046 case '\0':
3047 len = 0;
3048 break;
3049 case ',':
3050 c = '\0';
3051 break;
3053 case '=': case '+': case '*':
3054 break;
3056 case '%':
3057 /* We only support one commutative marker, the first
3058 one. We already set commutative above. */
3059 break;
3061 case '?':
3062 reject += 6;
3063 break;
3065 case '!':
3066 reject = 600;
3067 break;
3069 case '#':
3070 /* Ignore rest of this alternative as far as
3071 reloading is concerned. */
3073 p++;
3074 while (*p && *p != ',');
3075 len = 0;
3076 break;
3078 case '0': case '1': case '2': case '3': case '4':
3079 case '5': case '6': case '7': case '8': case '9':
3080 m = strtoul (p, &end, 10);
3081 p = end;
3082 len = 0;
3084 this_alternative_matches[i] = m;
3085 /* We are supposed to match a previous operand.
3086 If we do, we win if that one did.
3087 If we do not, count both of the operands as losers.
3088 (This is too conservative, since most of the time
3089 only a single reload insn will be needed to make
3090 the two operands win. As a result, this alternative
3091 may be rejected when it is actually desirable.) */
3092 if ((swapped && (m != commutative || i != commutative + 1))
3093 /* If we are matching as if two operands were swapped,
3094 also pretend that operands_match had been computed
3095 with swapped.
3096 But if I is the second of those and C is the first,
3097 don't exchange them, because operands_match is valid
3098 only on one side of its diagonal. */
3099 ? (operands_match
3100 [(m == commutative || m == commutative + 1)
3101 ? 2 * commutative + 1 - m : m]
3102 [(i == commutative || i == commutative + 1)
3103 ? 2 * commutative + 1 - i : i])
3104 : operands_match[m][i])
3106 /* If we are matching a non-offsettable address where an
3107 offsettable address was expected, then we must reject
3108 this combination, because we can't reload it. */
3109 if (this_alternative_offmemok[m]
3110 && MEM_P (recog_data.operand[m])
3111 && this_alternative[m] == (int) NO_REGS
3112 && ! this_alternative_win[m])
3113 bad = 1;
3115 did_match = this_alternative_win[m];
3117 else
3119 /* Operands don't match. */
3120 rtx value;
3121 int loc1, loc2;
3122 /* Retroactively mark the operand we had to match
3123 as a loser, if it wasn't already. */
3124 if (this_alternative_win[m])
3125 losers++;
3126 this_alternative_win[m] = 0;
3127 if (this_alternative[m] == (int) NO_REGS)
3128 bad = 1;
3129 /* But count the pair only once in the total badness of
3130 this alternative, if the pair can be a dummy reload.
3131 The pointers in operand_loc are not swapped; swap
3132 them by hand if necessary. */
3133 if (swapped && i == commutative)
3134 loc1 = commutative + 1;
3135 else if (swapped && i == commutative + 1)
3136 loc1 = commutative;
3137 else
3138 loc1 = i;
3139 if (swapped && m == commutative)
3140 loc2 = commutative + 1;
3141 else if (swapped && m == commutative + 1)
3142 loc2 = commutative;
3143 else
3144 loc2 = m;
3145 value
3146 = find_dummy_reload (recog_data.operand[i],
3147 recog_data.operand[m],
3148 recog_data.operand_loc[loc1],
3149 recog_data.operand_loc[loc2],
3150 operand_mode[i], operand_mode[m],
3151 this_alternative[m], -1,
3152 this_alternative_earlyclobber[m]);
3154 if (value != 0)
3155 losers--;
3157 /* This can be fixed with reloads if the operand
3158 we are supposed to match can be fixed with reloads. */
3159 badop = 0;
3160 this_alternative[i] = this_alternative[m];
3162 /* If we have to reload this operand and some previous
3163 operand also had to match the same thing as this
3164 operand, we don't know how to do that. So reject this
3165 alternative. */
3166 if (! did_match || force_reload)
3167 for (j = 0; j < i; j++)
3168 if (this_alternative_matches[j]
3169 == this_alternative_matches[i])
3170 badop = 1;
3171 break;
3173 case 'p':
3174 /* All necessary reloads for an address_operand
3175 were handled in find_reloads_address. */
3176 this_alternative[i] = (int) MODE_BASE_REG_CLASS (VOIDmode);
3177 win = 1;
3178 badop = 0;
3179 break;
3181 case 'm':
3182 if (force_reload)
3183 break;
3184 if (MEM_P (operand)
3185 || (REG_P (operand)
3186 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3187 && reg_renumber[REGNO (operand)] < 0))
3188 win = 1;
3189 if (CONST_POOL_OK_P (operand))
3190 badop = 0;
3191 constmemok = 1;
3192 break;
3194 case '<':
3195 if (MEM_P (operand)
3196 && ! address_reloaded[i]
3197 && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
3198 || GET_CODE (XEXP (operand, 0)) == POST_DEC))
3199 win = 1;
3200 break;
3202 case '>':
3203 if (MEM_P (operand)
3204 && ! address_reloaded[i]
3205 && (GET_CODE (XEXP (operand, 0)) == PRE_INC
3206 || GET_CODE (XEXP (operand, 0)) == POST_INC))
3207 win = 1;
3208 break;
3210 /* Memory operand whose address is not offsettable. */
3211 case 'V':
3212 if (force_reload)
3213 break;
3214 if (MEM_P (operand)
3215 && ! (ind_levels ? offsettable_memref_p (operand)
3216 : offsettable_nonstrict_memref_p (operand))
3217 /* Certain mem addresses will become offsettable
3218 after they themselves are reloaded. This is important;
3219 we don't want our own handling of unoffsettables
3220 to override the handling of reg_equiv_address. */
3221 && !(REG_P (XEXP (operand, 0))
3222 && (ind_levels == 0
3223 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0)))
3224 win = 1;
3225 break;
3227 /* Memory operand whose address is offsettable. */
3228 case 'o':
3229 if (force_reload)
3230 break;
3231 if ((MEM_P (operand)
3232 /* If IND_LEVELS, find_reloads_address won't reload a
3233 pseudo that didn't get a hard reg, so we have to
3234 reject that case. */
3235 && ((ind_levels ? offsettable_memref_p (operand)
3236 : offsettable_nonstrict_memref_p (operand))
3237 /* A reloaded address is offsettable because it is now
3238 just a simple register indirect. */
3239 || address_reloaded[i] == 1))
3240 || (REG_P (operand)
3241 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3242 && reg_renumber[REGNO (operand)] < 0
3243 /* If reg_equiv_address is nonzero, we will be
3244 loading it into a register; hence it will be
3245 offsettable, but we cannot say that reg_equiv_mem
3246 is offsettable without checking. */
3247 && ((reg_equiv_mem[REGNO (operand)] != 0
3248 && offsettable_memref_p (reg_equiv_mem[REGNO (operand)]))
3249 || (reg_equiv_address[REGNO (operand)] != 0))))
3250 win = 1;
3251 if (CONST_POOL_OK_P (operand)
3252 || MEM_P (operand))
3253 badop = 0;
3254 constmemok = 1;
3255 offmemok = 1;
3256 break;
3258 case '&':
3259 /* Output operand that is stored before the need for the
3260 input operands (and their index registers) is over. */
3261 earlyclobber = 1, this_earlyclobber = 1;
3262 break;
3264 case 'E':
3265 case 'F':
3266 if (GET_CODE (operand) == CONST_DOUBLE
3267 || (GET_CODE (operand) == CONST_VECTOR
3268 && (GET_MODE_CLASS (GET_MODE (operand))
3269 == MODE_VECTOR_FLOAT)))
3270 win = 1;
3271 break;
3273 case 'G':
3274 case 'H':
3275 if (GET_CODE (operand) == CONST_DOUBLE
3276 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (operand, c, p))
3277 win = 1;
3278 break;
3280 case 's':
3281 if (GET_CODE (operand) == CONST_INT
3282 || (GET_CODE (operand) == CONST_DOUBLE
3283 && GET_MODE (operand) == VOIDmode))
3284 break;
3285 case 'i':
3286 if (CONSTANT_P (operand)
3287 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand)))
3288 win = 1;
3289 break;
3291 case 'n':
3292 if (GET_CODE (operand) == CONST_INT
3293 || (GET_CODE (operand) == CONST_DOUBLE
3294 && GET_MODE (operand) == VOIDmode))
3295 win = 1;
3296 break;
3298 case 'I':
3299 case 'J':
3300 case 'K':
3301 case 'L':
3302 case 'M':
3303 case 'N':
3304 case 'O':
3305 case 'P':
3306 if (GET_CODE (operand) == CONST_INT
3307 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (operand), c, p))
3308 win = 1;
3309 break;
3311 case 'X':
3312 win = 1;
3313 break;
3315 case 'g':
3316 if (! force_reload
3317 /* A PLUS is never a valid operand, but reload can make
3318 it from a register when eliminating registers. */
3319 && GET_CODE (operand) != PLUS
3320 /* A SCRATCH is not a valid operand. */
3321 && GET_CODE (operand) != SCRATCH
3322 && (! CONSTANT_P (operand)
3323 || ! flag_pic
3324 || LEGITIMATE_PIC_OPERAND_P (operand))
3325 && (GENERAL_REGS == ALL_REGS
3326 || !REG_P (operand)
3327 || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
3328 && reg_renumber[REGNO (operand)] < 0)))
3329 win = 1;
3330 /* Drop through into 'r' case. */
3332 case 'r':
3333 this_alternative[i]
3334 = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
3335 goto reg;
3337 default:
3338 if (REG_CLASS_FROM_CONSTRAINT (c, p) == NO_REGS)
3340 #ifdef EXTRA_CONSTRAINT_STR
3341 if (EXTRA_MEMORY_CONSTRAINT (c, p))
3343 if (force_reload)
3344 break;
3345 if (EXTRA_CONSTRAINT_STR (operand, c, p))
3346 win = 1;
3347 /* If the address was already reloaded,
3348 we win as well. */
3349 else if (MEM_P (operand)
3350 && address_reloaded[i] == 1)
3351 win = 1;
3352 /* Likewise if the address will be reloaded because
3353 reg_equiv_address is nonzero. For reg_equiv_mem
3354 we have to check. */
3355 else if (REG_P (operand)
3356 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3357 && reg_renumber[REGNO (operand)] < 0
3358 && ((reg_equiv_mem[REGNO (operand)] != 0
3359 && EXTRA_CONSTRAINT_STR (reg_equiv_mem[REGNO (operand)], c, p))
3360 || (reg_equiv_address[REGNO (operand)] != 0)))
3361 win = 1;
3363 /* If we didn't already win, we can reload
3364 constants via force_const_mem, and other
3365 MEMs by reloading the address like for 'o'. */
3366 if (CONST_POOL_OK_P (operand)
3367 || MEM_P (operand))
3368 badop = 0;
3369 constmemok = 1;
3370 offmemok = 1;
3371 break;
3373 if (EXTRA_ADDRESS_CONSTRAINT (c, p))
3375 if (EXTRA_CONSTRAINT_STR (operand, c, p))
3376 win = 1;
3378 /* If we didn't already win, we can reload
3379 the address into a base register. */
3380 this_alternative[i] = (int) MODE_BASE_REG_CLASS (VOIDmode);
3381 badop = 0;
3382 break;
3385 if (EXTRA_CONSTRAINT_STR (operand, c, p))
3386 win = 1;
3387 #endif
3388 break;
3391 this_alternative[i]
3392 = (int) (reg_class_subunion
3393 [this_alternative[i]]
3394 [(int) REG_CLASS_FROM_CONSTRAINT (c, p)]);
3395 reg:
3396 if (GET_MODE (operand) == BLKmode)
3397 break;
3398 winreg = 1;
3399 if (REG_P (operand)
3400 && reg_fits_class_p (operand, this_alternative[i],
3401 offset, GET_MODE (recog_data.operand[i])))
3402 win = 1;
3403 break;
3405 while ((p += len), c);
3407 constraints[i] = p;
3409 /* If this operand could be handled with a reg,
3410 and some reg is allowed, then this operand can be handled. */
3411 if (winreg && this_alternative[i] != (int) NO_REGS)
3412 badop = 0;
3414 /* Record which operands fit this alternative. */
3415 this_alternative_earlyclobber[i] = earlyclobber;
3416 if (win && ! force_reload)
3417 this_alternative_win[i] = 1;
3418 else if (did_match && ! force_reload)
3419 this_alternative_match_win[i] = 1;
3420 else
3422 int const_to_mem = 0;
3424 this_alternative_offmemok[i] = offmemok;
3425 losers++;
3426 if (badop)
3427 bad = 1;
3428 /* Alternative loses if it has no regs for a reg operand. */
3429 if (REG_P (operand)
3430 && this_alternative[i] == (int) NO_REGS
3431 && this_alternative_matches[i] < 0)
3432 bad = 1;
3434 /* If this is a constant that is reloaded into the desired
3435 class by copying it to memory first, count that as another
3436 reload. This is consistent with other code and is
3437 required to avoid choosing another alternative when
3438 the constant is moved into memory by this function on
3439 an early reload pass. Note that the test here is
3440 precisely the same as in the code below that calls
3441 force_const_mem. */
3442 if (CONST_POOL_OK_P (operand)
3443 && ((PREFERRED_RELOAD_CLASS (operand,
3444 (enum reg_class) this_alternative[i])
3445 == NO_REGS)
3446 || no_input_reloads)
3447 && operand_mode[i] != VOIDmode)
3449 const_to_mem = 1;
3450 if (this_alternative[i] != (int) NO_REGS)
3451 losers++;
3454 /* If we can't reload this value at all, reject this
3455 alternative. Note that we could also lose due to
3456 LIMIT_RELOAD_RELOAD_CLASS, but we don't check that
3457 here. */
3459 if (! CONSTANT_P (operand)
3460 && (enum reg_class) this_alternative[i] != NO_REGS
3461 && (PREFERRED_RELOAD_CLASS (operand,
3462 (enum reg_class) this_alternative[i])
3463 == NO_REGS))
3464 bad = 1;
3466 /* Alternative loses if it requires a type of reload not
3467 permitted for this insn. We can always reload SCRATCH
3468 and objects with a REG_UNUSED note. */
3469 else if (GET_CODE (operand) != SCRATCH
3470 && modified[i] != RELOAD_READ && no_output_reloads
3471 && ! find_reg_note (insn, REG_UNUSED, operand))
3472 bad = 1;
3473 else if (modified[i] != RELOAD_WRITE && no_input_reloads
3474 && ! const_to_mem)
3475 bad = 1;
3477 /* We prefer to reload pseudos over reloading other things,
3478 since such reloads may be able to be eliminated later.
3479 If we are reloading a SCRATCH, we won't be generating any
3480 insns, just using a register, so it is also preferred.
3481 So bump REJECT in other cases. Don't do this in the
3482 case where we are forcing a constant into memory and
3483 it will then win since we don't want to have a different
3484 alternative match then. */
3485 if (! (REG_P (operand)
3486 && REGNO (operand) >= FIRST_PSEUDO_REGISTER)
3487 && GET_CODE (operand) != SCRATCH
3488 && ! (const_to_mem && constmemok))
3489 reject += 2;
3491 /* Input reloads can be inherited more often than output
3492 reloads can be removed, so penalize output reloads. */
3493 if (operand_type[i] != RELOAD_FOR_INPUT
3494 && GET_CODE (operand) != SCRATCH)
3495 reject++;
3498 /* If this operand is a pseudo register that didn't get a hard
3499 reg and this alternative accepts some register, see if the
3500 class that we want is a subset of the preferred class for this
3501 register. If not, but it intersects that class, use the
3502 preferred class instead. If it does not intersect the preferred
3503 class, show that usage of this alternative should be discouraged;
3504 it will be discouraged more still if the register is `preferred
3505 or nothing'. We do this because it increases the chance of
3506 reusing our spill register in a later insn and avoiding a pair
3507 of memory stores and loads.
3509 Don't bother with this if this alternative will accept this
3510 operand.
3512 Don't do this for a multiword operand, since it is only a
3513 small win and has the risk of requiring more spill registers,
3514 which could cause a large loss.
3516 Don't do this if the preferred class has only one register
3517 because we might otherwise exhaust the class. */
3519 if (! win && ! did_match
3520 && this_alternative[i] != (int) NO_REGS
3521 && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3522 && reg_class_size [(int) preferred_class[i]] > 0
3523 && ! SMALL_REGISTER_CLASS_P (preferred_class[i]))
3525 if (! reg_class_subset_p (this_alternative[i],
3526 preferred_class[i]))
3528 /* Since we don't have a way of forming the intersection,
3529 we just do something special if the preferred class
3530 is a subset of the class we have; that's the most
3531 common case anyway. */
3532 if (reg_class_subset_p (preferred_class[i],
3533 this_alternative[i]))
3534 this_alternative[i] = (int) preferred_class[i];
3535 else
3536 reject += (2 + 2 * pref_or_nothing[i]);
3541 /* Now see if any output operands that are marked "earlyclobber"
3542 in this alternative conflict with any input operands
3543 or any memory addresses. */
3545 for (i = 0; i < noperands; i++)
3546 if (this_alternative_earlyclobber[i]
3547 && (this_alternative_win[i] || this_alternative_match_win[i]))
3549 struct decomposition early_data;
3551 early_data = decompose (recog_data.operand[i]);
3553 gcc_assert (modified[i] != RELOAD_READ);
3555 if (this_alternative[i] == NO_REGS)
3557 this_alternative_earlyclobber[i] = 0;
3558 gcc_assert (this_insn_is_asm);
3559 error_for_asm (this_insn,
3560 "%<&%> constraint used with no register class");
3563 for (j = 0; j < noperands; j++)
3564 /* Is this an input operand or a memory ref? */
3565 if ((MEM_P (recog_data.operand[j])
3566 || modified[j] != RELOAD_WRITE)
3567 && j != i
3568 /* Ignore things like match_operator operands. */
3569 && *recog_data.constraints[j] != 0
3570 /* Don't count an input operand that is constrained to match
3571 the early clobber operand. */
3572 && ! (this_alternative_matches[j] == i
3573 && rtx_equal_p (recog_data.operand[i],
3574 recog_data.operand[j]))
3575 /* Is it altered by storing the earlyclobber operand? */
3576 && !immune_p (recog_data.operand[j], recog_data.operand[i],
3577 early_data))
3579 /* If the output is in a non-empty few-regs class,
3580 it's costly to reload it, so reload the input instead. */
3581 if (SMALL_REGISTER_CLASS_P (this_alternative[i])
3582 && (REG_P (recog_data.operand[j])
3583 || GET_CODE (recog_data.operand[j]) == SUBREG))
3585 losers++;
3586 this_alternative_win[j] = 0;
3587 this_alternative_match_win[j] = 0;
3589 else
3590 break;
3592 /* If an earlyclobber operand conflicts with something,
3593 it must be reloaded, so request this and count the cost. */
3594 if (j != noperands)
3596 losers++;
3597 this_alternative_win[i] = 0;
3598 this_alternative_match_win[j] = 0;
3599 for (j = 0; j < noperands; j++)
3600 if (this_alternative_matches[j] == i
3601 && this_alternative_match_win[j])
3603 this_alternative_win[j] = 0;
3604 this_alternative_match_win[j] = 0;
3605 losers++;
3610 /* If one alternative accepts all the operands, no reload required,
3611 choose that alternative; don't consider the remaining ones. */
3612 if (losers == 0)
3614 /* Unswap these so that they are never swapped at `finish'. */
3615 if (commutative >= 0)
3617 recog_data.operand[commutative] = substed_operand[commutative];
3618 recog_data.operand[commutative + 1]
3619 = substed_operand[commutative + 1];
3621 for (i = 0; i < noperands; i++)
3623 goal_alternative_win[i] = this_alternative_win[i];
3624 goal_alternative_match_win[i] = this_alternative_match_win[i];
3625 goal_alternative[i] = this_alternative[i];
3626 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3627 goal_alternative_matches[i] = this_alternative_matches[i];
3628 goal_alternative_earlyclobber[i]
3629 = this_alternative_earlyclobber[i];
3631 goal_alternative_number = this_alternative_number;
3632 goal_alternative_swapped = swapped;
3633 goal_earlyclobber = this_earlyclobber;
3634 goto finish;
3637 /* REJECT, set by the ! and ? constraint characters and when a register
3638 would be reloaded into a non-preferred class, discourages the use of
3639 this alternative for a reload goal. REJECT is incremented by six
3640 for each ? and two for each non-preferred class. */
3641 losers = losers * 6 + reject;
3643 /* If this alternative can be made to work by reloading,
3644 and it needs less reloading than the others checked so far,
3645 record it as the chosen goal for reloading. */
3646 if (! bad && best > losers)
3648 for (i = 0; i < noperands; i++)
3650 goal_alternative[i] = this_alternative[i];
3651 goal_alternative_win[i] = this_alternative_win[i];
3652 goal_alternative_match_win[i] = this_alternative_match_win[i];
3653 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3654 goal_alternative_matches[i] = this_alternative_matches[i];
3655 goal_alternative_earlyclobber[i]
3656 = this_alternative_earlyclobber[i];
3658 goal_alternative_swapped = swapped;
3659 best = losers;
3660 goal_alternative_number = this_alternative_number;
3661 goal_earlyclobber = this_earlyclobber;
3665 /* If insn is commutative (it's safe to exchange a certain pair of operands)
3666 then we need to try each alternative twice,
3667 the second time matching those two operands
3668 as if we had exchanged them.
3669 To do this, really exchange them in operands.
3671 If we have just tried the alternatives the second time,
3672 return operands to normal and drop through. */
3674 if (commutative >= 0)
3676 swapped = !swapped;
3677 if (swapped)
3679 enum reg_class tclass;
3680 int t;
3682 recog_data.operand[commutative] = substed_operand[commutative + 1];
3683 recog_data.operand[commutative + 1] = substed_operand[commutative];
3684 /* Swap the duplicates too. */
3685 for (i = 0; i < recog_data.n_dups; i++)
3686 if (recog_data.dup_num[i] == commutative
3687 || recog_data.dup_num[i] == commutative + 1)
3688 *recog_data.dup_loc[i]
3689 = recog_data.operand[(int) recog_data.dup_num[i]];
3691 tclass = preferred_class[commutative];
3692 preferred_class[commutative] = preferred_class[commutative + 1];
3693 preferred_class[commutative + 1] = tclass;
3695 t = pref_or_nothing[commutative];
3696 pref_or_nothing[commutative] = pref_or_nothing[commutative + 1];
3697 pref_or_nothing[commutative + 1] = t;
3699 t = address_reloaded[commutative];
3700 address_reloaded[commutative] = address_reloaded[commutative + 1];
3701 address_reloaded[commutative + 1] = t;
3703 memcpy (constraints, recog_data.constraints,
3704 noperands * sizeof (char *));
3705 goto try_swapped;
3707 else
3709 recog_data.operand[commutative] = substed_operand[commutative];
3710 recog_data.operand[commutative + 1]
3711 = substed_operand[commutative + 1];
3712 /* Unswap the duplicates too. */
3713 for (i = 0; i < recog_data.n_dups; i++)
3714 if (recog_data.dup_num[i] == commutative
3715 || recog_data.dup_num[i] == commutative + 1)
3716 *recog_data.dup_loc[i]
3717 = recog_data.operand[(int) recog_data.dup_num[i]];
3721 /* The operands don't meet the constraints.
3722 goal_alternative describes the alternative
3723 that we could reach by reloading the fewest operands.
3724 Reload so as to fit it. */
3726 if (best == MAX_RECOG_OPERANDS * 2 + 600)
3728 /* No alternative works with reloads?? */
3729 if (insn_code_number >= 0)
3730 fatal_insn ("unable to generate reloads for:", insn);
3731 error_for_asm (insn, "inconsistent operand constraints in an %<asm%>");
3732 /* Avoid further trouble with this insn. */
3733 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3734 n_reloads = 0;
3735 return 0;
3738 /* Jump to `finish' from above if all operands are valid already.
3739 In that case, goal_alternative_win is all 1. */
3740 finish:
3742 /* Right now, for any pair of operands I and J that are required to match,
3743 with I < J,
3744 goal_alternative_matches[J] is I.
3745 Set up goal_alternative_matched as the inverse function:
3746 goal_alternative_matched[I] = J. */
3748 for (i = 0; i < noperands; i++)
3749 goal_alternative_matched[i] = -1;
3751 for (i = 0; i < noperands; i++)
3752 if (! goal_alternative_win[i]
3753 && goal_alternative_matches[i] >= 0)
3754 goal_alternative_matched[goal_alternative_matches[i]] = i;
3756 for (i = 0; i < noperands; i++)
3757 goal_alternative_win[i] |= goal_alternative_match_win[i];
3759 /* If the best alternative is with operands 1 and 2 swapped,
3760 consider them swapped before reporting the reloads. Update the
3761 operand numbers of any reloads already pushed. */
3763 if (goal_alternative_swapped)
3765 rtx tem;
3767 tem = substed_operand[commutative];
3768 substed_operand[commutative] = substed_operand[commutative + 1];
3769 substed_operand[commutative + 1] = tem;
3770 tem = recog_data.operand[commutative];
3771 recog_data.operand[commutative] = recog_data.operand[commutative + 1];
3772 recog_data.operand[commutative + 1] = tem;
3773 tem = *recog_data.operand_loc[commutative];
3774 *recog_data.operand_loc[commutative]
3775 = *recog_data.operand_loc[commutative + 1];
3776 *recog_data.operand_loc[commutative + 1] = tem;
3778 for (i = 0; i < n_reloads; i++)
3780 if (rld[i].opnum == commutative)
3781 rld[i].opnum = commutative + 1;
3782 else if (rld[i].opnum == commutative + 1)
3783 rld[i].opnum = commutative;
3787 for (i = 0; i < noperands; i++)
3789 operand_reloadnum[i] = -1;
3791 /* If this is an earlyclobber operand, we need to widen the scope.
3792 The reload must remain valid from the start of the insn being
3793 reloaded until after the operand is stored into its destination.
3794 We approximate this with RELOAD_OTHER even though we know that we
3795 do not conflict with RELOAD_FOR_INPUT_ADDRESS reloads.
3797 One special case that is worth checking is when we have an
3798 output that is earlyclobber but isn't used past the insn (typically
3799 a SCRATCH). In this case, we only need have the reload live
3800 through the insn itself, but not for any of our input or output
3801 reloads.
3802 But we must not accidentally narrow the scope of an existing
3803 RELOAD_OTHER reload - leave these alone.
3805 In any case, anything needed to address this operand can remain
3806 however they were previously categorized. */
3808 if (goal_alternative_earlyclobber[i] && operand_type[i] != RELOAD_OTHER)
3809 operand_type[i]
3810 = (find_reg_note (insn, REG_UNUSED, recog_data.operand[i])
3811 ? RELOAD_FOR_INSN : RELOAD_OTHER);
3814 /* Any constants that aren't allowed and can't be reloaded
3815 into registers are here changed into memory references. */
3816 for (i = 0; i < noperands; i++)
3817 if (! goal_alternative_win[i]
3818 && CONST_POOL_OK_P (recog_data.operand[i])
3819 && ((PREFERRED_RELOAD_CLASS (recog_data.operand[i],
3820 (enum reg_class) goal_alternative[i])
3821 == NO_REGS)
3822 || no_input_reloads)
3823 && operand_mode[i] != VOIDmode)
3825 substed_operand[i] = recog_data.operand[i]
3826 = find_reloads_toplev (force_const_mem (operand_mode[i],
3827 recog_data.operand[i]),
3828 i, address_type[i], ind_levels, 0, insn,
3829 NULL);
3830 if (alternative_allows_memconst (recog_data.constraints[i],
3831 goal_alternative_number))
3832 goal_alternative_win[i] = 1;
3835 /* Likewise any invalid constants appearing as operand of a PLUS
3836 that is to be reloaded. */
3837 for (i = 0; i < noperands; i++)
3838 if (! goal_alternative_win[i]
3839 && GET_CODE (recog_data.operand[i]) == PLUS
3840 && CONST_POOL_OK_P (XEXP (recog_data.operand[i], 1))
3841 && (PREFERRED_RELOAD_CLASS (XEXP (recog_data.operand[i], 1),
3842 (enum reg_class) goal_alternative[i])
3843 == NO_REGS)
3844 && operand_mode[i] != VOIDmode)
3846 rtx tem = force_const_mem (operand_mode[i],
3847 XEXP (recog_data.operand[i], 1));
3848 tem = gen_rtx_PLUS (operand_mode[i],
3849 XEXP (recog_data.operand[i], 0), tem);
3851 substed_operand[i] = recog_data.operand[i]
3852 = find_reloads_toplev (tem, i, address_type[i],
3853 ind_levels, 0, insn, NULL);
3856 /* Record the values of the earlyclobber operands for the caller. */
3857 if (goal_earlyclobber)
3858 for (i = 0; i < noperands; i++)
3859 if (goal_alternative_earlyclobber[i])
3860 reload_earlyclobbers[n_earlyclobbers++] = recog_data.operand[i];
3862 /* Now record reloads for all the operands that need them. */
3863 for (i = 0; i < noperands; i++)
3864 if (! goal_alternative_win[i])
3866 /* Operands that match previous ones have already been handled. */
3867 if (goal_alternative_matches[i] >= 0)
3869 /* Handle an operand with a nonoffsettable address
3870 appearing where an offsettable address will do
3871 by reloading the address into a base register.
3873 ??? We can also do this when the operand is a register and
3874 reg_equiv_mem is not offsettable, but this is a bit tricky,
3875 so we don't bother with it. It may not be worth doing. */
3876 else if (goal_alternative_matched[i] == -1
3877 && goal_alternative_offmemok[i]
3878 && MEM_P (recog_data.operand[i]))
3880 operand_reloadnum[i]
3881 = push_reload (XEXP (recog_data.operand[i], 0), NULL_RTX,
3882 &XEXP (recog_data.operand[i], 0), (rtx*) 0,
3883 MODE_BASE_REG_CLASS (VOIDmode),
3884 GET_MODE (XEXP (recog_data.operand[i], 0)),
3885 VOIDmode, 0, 0, i, RELOAD_FOR_INPUT);
3886 rld[operand_reloadnum[i]].inc
3887 = GET_MODE_SIZE (GET_MODE (recog_data.operand[i]));
3889 /* If this operand is an output, we will have made any
3890 reloads for its address as RELOAD_FOR_OUTPUT_ADDRESS, but
3891 now we are treating part of the operand as an input, so
3892 we must change these to RELOAD_FOR_INPUT_ADDRESS. */
3894 if (modified[i] == RELOAD_WRITE)
3896 for (j = 0; j < n_reloads; j++)
3898 if (rld[j].opnum == i)
3900 if (rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS)
3901 rld[j].when_needed = RELOAD_FOR_INPUT_ADDRESS;
3902 else if (rld[j].when_needed
3903 == RELOAD_FOR_OUTADDR_ADDRESS)
3904 rld[j].when_needed = RELOAD_FOR_INPADDR_ADDRESS;
3909 else if (goal_alternative_matched[i] == -1)
3911 operand_reloadnum[i]
3912 = push_reload ((modified[i] != RELOAD_WRITE
3913 ? recog_data.operand[i] : 0),
3914 (modified[i] != RELOAD_READ
3915 ? recog_data.operand[i] : 0),
3916 (modified[i] != RELOAD_WRITE
3917 ? recog_data.operand_loc[i] : 0),
3918 (modified[i] != RELOAD_READ
3919 ? recog_data.operand_loc[i] : 0),
3920 (enum reg_class) goal_alternative[i],
3921 (modified[i] == RELOAD_WRITE
3922 ? VOIDmode : operand_mode[i]),
3923 (modified[i] == RELOAD_READ
3924 ? VOIDmode : operand_mode[i]),
3925 (insn_code_number < 0 ? 0
3926 : insn_data[insn_code_number].operand[i].strict_low),
3927 0, i, operand_type[i]);
3929 /* In a matching pair of operands, one must be input only
3930 and the other must be output only.
3931 Pass the input operand as IN and the other as OUT. */
3932 else if (modified[i] == RELOAD_READ
3933 && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
3935 operand_reloadnum[i]
3936 = push_reload (recog_data.operand[i],
3937 recog_data.operand[goal_alternative_matched[i]],
3938 recog_data.operand_loc[i],
3939 recog_data.operand_loc[goal_alternative_matched[i]],
3940 (enum reg_class) goal_alternative[i],
3941 operand_mode[i],
3942 operand_mode[goal_alternative_matched[i]],
3943 0, 0, i, RELOAD_OTHER);
3944 operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
3946 else if (modified[i] == RELOAD_WRITE
3947 && modified[goal_alternative_matched[i]] == RELOAD_READ)
3949 operand_reloadnum[goal_alternative_matched[i]]
3950 = push_reload (recog_data.operand[goal_alternative_matched[i]],
3951 recog_data.operand[i],
3952 recog_data.operand_loc[goal_alternative_matched[i]],
3953 recog_data.operand_loc[i],
3954 (enum reg_class) goal_alternative[i],
3955 operand_mode[goal_alternative_matched[i]],
3956 operand_mode[i],
3957 0, 0, i, RELOAD_OTHER);
3958 operand_reloadnum[i] = output_reloadnum;
3960 else
3962 gcc_assert (insn_code_number < 0);
3963 error_for_asm (insn, "inconsistent operand constraints "
3964 "in an %<asm%>");
3965 /* Avoid further trouble with this insn. */
3966 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3967 n_reloads = 0;
3968 return 0;
3971 else if (goal_alternative_matched[i] < 0
3972 && goal_alternative_matches[i] < 0
3973 && address_operand_reloaded[i] != 1
3974 && optimize)
3976 /* For each non-matching operand that's a MEM or a pseudo-register
3977 that didn't get a hard register, make an optional reload.
3978 This may get done even if the insn needs no reloads otherwise. */
3980 rtx operand = recog_data.operand[i];
3982 while (GET_CODE (operand) == SUBREG)
3983 operand = SUBREG_REG (operand);
3984 if ((MEM_P (operand)
3985 || (REG_P (operand)
3986 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3987 /* If this is only for an output, the optional reload would not
3988 actually cause us to use a register now, just note that
3989 something is stored here. */
3990 && ((enum reg_class) goal_alternative[i] != NO_REGS
3991 || modified[i] == RELOAD_WRITE)
3992 && ! no_input_reloads
3993 /* An optional output reload might allow to delete INSN later.
3994 We mustn't make in-out reloads on insns that are not permitted
3995 output reloads.
3996 If this is an asm, we can't delete it; we must not even call
3997 push_reload for an optional output reload in this case,
3998 because we can't be sure that the constraint allows a register,
3999 and push_reload verifies the constraints for asms. */
4000 && (modified[i] == RELOAD_READ
4001 || (! no_output_reloads && ! this_insn_is_asm)))
4002 operand_reloadnum[i]
4003 = push_reload ((modified[i] != RELOAD_WRITE
4004 ? recog_data.operand[i] : 0),
4005 (modified[i] != RELOAD_READ
4006 ? recog_data.operand[i] : 0),
4007 (modified[i] != RELOAD_WRITE
4008 ? recog_data.operand_loc[i] : 0),
4009 (modified[i] != RELOAD_READ
4010 ? recog_data.operand_loc[i] : 0),
4011 (enum reg_class) goal_alternative[i],
4012 (modified[i] == RELOAD_WRITE
4013 ? VOIDmode : operand_mode[i]),
4014 (modified[i] == RELOAD_READ
4015 ? VOIDmode : operand_mode[i]),
4016 (insn_code_number < 0 ? 0
4017 : insn_data[insn_code_number].operand[i].strict_low),
4018 1, i, operand_type[i]);
4019 /* If a memory reference remains (either as a MEM or a pseudo that
4020 did not get a hard register), yet we can't make an optional
4021 reload, check if this is actually a pseudo register reference;
4022 we then need to emit a USE and/or a CLOBBER so that reload
4023 inheritance will do the right thing. */
4024 else if (replace
4025 && (MEM_P (operand)
4026 || (REG_P (operand)
4027 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
4028 && reg_renumber [REGNO (operand)] < 0)))
4030 operand = *recog_data.operand_loc[i];
4032 while (GET_CODE (operand) == SUBREG)
4033 operand = SUBREG_REG (operand);
4034 if (REG_P (operand))
4036 if (modified[i] != RELOAD_WRITE)
4037 /* We mark the USE with QImode so that we recognize
4038 it as one that can be safely deleted at the end
4039 of reload. */
4040 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, operand),
4041 insn), QImode);
4042 if (modified[i] != RELOAD_READ)
4043 emit_insn_after (gen_rtx_CLOBBER (VOIDmode, operand), insn);
4047 else if (goal_alternative_matches[i] >= 0
4048 && goal_alternative_win[goal_alternative_matches[i]]
4049 && modified[i] == RELOAD_READ
4050 && modified[goal_alternative_matches[i]] == RELOAD_WRITE
4051 && ! no_input_reloads && ! no_output_reloads
4052 && optimize)
4054 /* Similarly, make an optional reload for a pair of matching
4055 objects that are in MEM or a pseudo that didn't get a hard reg. */
4057 rtx operand = recog_data.operand[i];
4059 while (GET_CODE (operand) == SUBREG)
4060 operand = SUBREG_REG (operand);
4061 if ((MEM_P (operand)
4062 || (REG_P (operand)
4063 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
4064 && ((enum reg_class) goal_alternative[goal_alternative_matches[i]]
4065 != NO_REGS))
4066 operand_reloadnum[i] = operand_reloadnum[goal_alternative_matches[i]]
4067 = push_reload (recog_data.operand[goal_alternative_matches[i]],
4068 recog_data.operand[i],
4069 recog_data.operand_loc[goal_alternative_matches[i]],
4070 recog_data.operand_loc[i],
4071 (enum reg_class) goal_alternative[goal_alternative_matches[i]],
4072 operand_mode[goal_alternative_matches[i]],
4073 operand_mode[i],
4074 0, 1, goal_alternative_matches[i], RELOAD_OTHER);
4077 /* Perform whatever substitutions on the operands we are supposed
4078 to make due to commutativity or replacement of registers
4079 with equivalent constants or memory slots. */
4081 for (i = 0; i < noperands; i++)
4083 /* We only do this on the last pass through reload, because it is
4084 possible for some data (like reg_equiv_address) to be changed during
4085 later passes. Moreover, we loose the opportunity to get a useful
4086 reload_{in,out}_reg when we do these replacements. */
4088 if (replace)
4090 rtx substitution = substed_operand[i];
4092 *recog_data.operand_loc[i] = substitution;
4094 /* If we're replacing an operand with a LABEL_REF, we need
4095 to make sure that there's a REG_LABEL note attached to
4096 this instruction. */
4097 if (!JUMP_P (insn)
4098 && GET_CODE (substitution) == LABEL_REF
4099 && !find_reg_note (insn, REG_LABEL, XEXP (substitution, 0)))
4100 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL,
4101 XEXP (substitution, 0),
4102 REG_NOTES (insn));
4104 else
4105 retval |= (substed_operand[i] != *recog_data.operand_loc[i]);
4108 /* If this insn pattern contains any MATCH_DUP's, make sure that
4109 they will be substituted if the operands they match are substituted.
4110 Also do now any substitutions we already did on the operands.
4112 Don't do this if we aren't making replacements because we might be
4113 propagating things allocated by frame pointer elimination into places
4114 it doesn't expect. */
4116 if (insn_code_number >= 0 && replace)
4117 for (i = insn_data[insn_code_number].n_dups - 1; i >= 0; i--)
4119 int opno = recog_data.dup_num[i];
4120 *recog_data.dup_loc[i] = *recog_data.operand_loc[opno];
4121 dup_replacements (recog_data.dup_loc[i], recog_data.operand_loc[opno]);
4124 #if 0
4125 /* This loses because reloading of prior insns can invalidate the equivalence
4126 (or at least find_equiv_reg isn't smart enough to find it any more),
4127 causing this insn to need more reload regs than it needed before.
4128 It may be too late to make the reload regs available.
4129 Now this optimization is done safely in choose_reload_regs. */
4131 /* For each reload of a reg into some other class of reg,
4132 search for an existing equivalent reg (same value now) in the right class.
4133 We can use it as long as we don't need to change its contents. */
4134 for (i = 0; i < n_reloads; i++)
4135 if (rld[i].reg_rtx == 0
4136 && rld[i].in != 0
4137 && REG_P (rld[i].in)
4138 && rld[i].out == 0)
4140 rld[i].reg_rtx
4141 = find_equiv_reg (rld[i].in, insn, rld[i].class, -1,
4142 static_reload_reg_p, 0, rld[i].inmode);
4143 /* Prevent generation of insn to load the value
4144 because the one we found already has the value. */
4145 if (rld[i].reg_rtx)
4146 rld[i].in = rld[i].reg_rtx;
4148 #endif
4150 /* Perhaps an output reload can be combined with another
4151 to reduce needs by one. */
4152 if (!goal_earlyclobber)
4153 combine_reloads ();
4155 /* If we have a pair of reloads for parts of an address, they are reloading
4156 the same object, the operands themselves were not reloaded, and they
4157 are for two operands that are supposed to match, merge the reloads and
4158 change the type of the surviving reload to RELOAD_FOR_OPERAND_ADDRESS. */
4160 for (i = 0; i < n_reloads; i++)
4162 int k;
4164 for (j = i + 1; j < n_reloads; j++)
4165 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4166 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4167 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4168 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4169 && (rld[j].when_needed == RELOAD_FOR_INPUT_ADDRESS
4170 || rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4171 || rld[j].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4172 || rld[j].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4173 && rtx_equal_p (rld[i].in, rld[j].in)
4174 && (operand_reloadnum[rld[i].opnum] < 0
4175 || rld[operand_reloadnum[rld[i].opnum]].optional)
4176 && (operand_reloadnum[rld[j].opnum] < 0
4177 || rld[operand_reloadnum[rld[j].opnum]].optional)
4178 && (goal_alternative_matches[rld[i].opnum] == rld[j].opnum
4179 || (goal_alternative_matches[rld[j].opnum]
4180 == rld[i].opnum)))
4182 for (k = 0; k < n_replacements; k++)
4183 if (replacements[k].what == j)
4184 replacements[k].what = i;
4186 if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4187 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4188 rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
4189 else
4190 rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
4191 rld[j].in = 0;
4195 /* Scan all the reloads and update their type.
4196 If a reload is for the address of an operand and we didn't reload
4197 that operand, change the type. Similarly, change the operand number
4198 of a reload when two operands match. If a reload is optional, treat it
4199 as though the operand isn't reloaded.
4201 ??? This latter case is somewhat odd because if we do the optional
4202 reload, it means the object is hanging around. Thus we need only
4203 do the address reload if the optional reload was NOT done.
4205 Change secondary reloads to be the address type of their operand, not
4206 the normal type.
4208 If an operand's reload is now RELOAD_OTHER, change any
4209 RELOAD_FOR_INPUT_ADDRESS reloads of that operand to
4210 RELOAD_FOR_OTHER_ADDRESS. */
4212 for (i = 0; i < n_reloads; i++)
4214 if (rld[i].secondary_p
4215 && rld[i].when_needed == operand_type[rld[i].opnum])
4216 rld[i].when_needed = address_type[rld[i].opnum];
4218 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4219 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4220 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4221 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4222 && (operand_reloadnum[rld[i].opnum] < 0
4223 || rld[operand_reloadnum[rld[i].opnum]].optional))
4225 /* If we have a secondary reload to go along with this reload,
4226 change its type to RELOAD_FOR_OPADDR_ADDR. */
4228 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4229 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
4230 && rld[i].secondary_in_reload != -1)
4232 int secondary_in_reload = rld[i].secondary_in_reload;
4234 rld[secondary_in_reload].when_needed = RELOAD_FOR_OPADDR_ADDR;
4236 /* If there's a tertiary reload we have to change it also. */
4237 if (secondary_in_reload > 0
4238 && rld[secondary_in_reload].secondary_in_reload != -1)
4239 rld[rld[secondary_in_reload].secondary_in_reload].when_needed
4240 = RELOAD_FOR_OPADDR_ADDR;
4243 if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4244 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4245 && rld[i].secondary_out_reload != -1)
4247 int secondary_out_reload = rld[i].secondary_out_reload;
4249 rld[secondary_out_reload].when_needed = RELOAD_FOR_OPADDR_ADDR;
4251 /* If there's a tertiary reload we have to change it also. */
4252 if (secondary_out_reload
4253 && rld[secondary_out_reload].secondary_out_reload != -1)
4254 rld[rld[secondary_out_reload].secondary_out_reload].when_needed
4255 = RELOAD_FOR_OPADDR_ADDR;
4258 if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4259 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4260 rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
4261 else
4262 rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
4265 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4266 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
4267 && operand_reloadnum[rld[i].opnum] >= 0
4268 && (rld[operand_reloadnum[rld[i].opnum]].when_needed
4269 == RELOAD_OTHER))
4270 rld[i].when_needed = RELOAD_FOR_OTHER_ADDRESS;
4272 if (goal_alternative_matches[rld[i].opnum] >= 0)
4273 rld[i].opnum = goal_alternative_matches[rld[i].opnum];
4276 /* Scan all the reloads, and check for RELOAD_FOR_OPERAND_ADDRESS reloads.
4277 If we have more than one, then convert all RELOAD_FOR_OPADDR_ADDR
4278 reloads to RELOAD_FOR_OPERAND_ADDRESS reloads.
4280 choose_reload_regs assumes that RELOAD_FOR_OPADDR_ADDR reloads never
4281 conflict with RELOAD_FOR_OPERAND_ADDRESS reloads. This is true for a
4282 single pair of RELOAD_FOR_OPADDR_ADDR/RELOAD_FOR_OPERAND_ADDRESS reloads.
4283 However, if there is more than one RELOAD_FOR_OPERAND_ADDRESS reload,
4284 then a RELOAD_FOR_OPADDR_ADDR reload conflicts with all
4285 RELOAD_FOR_OPERAND_ADDRESS reloads other than the one that uses it.
4286 This is complicated by the fact that a single operand can have more
4287 than one RELOAD_FOR_OPERAND_ADDRESS reload. It is very difficult to fix
4288 choose_reload_regs without affecting code quality, and cases that
4289 actually fail are extremely rare, so it turns out to be better to fix
4290 the problem here by not generating cases that choose_reload_regs will
4291 fail for. */
4292 /* There is a similar problem with RELOAD_FOR_INPUT_ADDRESS /
4293 RELOAD_FOR_OUTPUT_ADDRESS when there is more than one of a kind for
4294 a single operand.
4295 We can reduce the register pressure by exploiting that a
4296 RELOAD_FOR_X_ADDR_ADDR that precedes all RELOAD_FOR_X_ADDRESS reloads
4297 does not conflict with any of them, if it is only used for the first of
4298 the RELOAD_FOR_X_ADDRESS reloads. */
4300 int first_op_addr_num = -2;
4301 int first_inpaddr_num[MAX_RECOG_OPERANDS];
4302 int first_outpaddr_num[MAX_RECOG_OPERANDS];
4303 int need_change = 0;
4304 /* We use last_op_addr_reload and the contents of the above arrays
4305 first as flags - -2 means no instance encountered, -1 means exactly
4306 one instance encountered.
4307 If more than one instance has been encountered, we store the reload
4308 number of the first reload of the kind in question; reload numbers
4309 are known to be non-negative. */
4310 for (i = 0; i < noperands; i++)
4311 first_inpaddr_num[i] = first_outpaddr_num[i] = -2;
4312 for (i = n_reloads - 1; i >= 0; i--)
4314 switch (rld[i].when_needed)
4316 case RELOAD_FOR_OPERAND_ADDRESS:
4317 if (++first_op_addr_num >= 0)
4319 first_op_addr_num = i;
4320 need_change = 1;
4322 break;
4323 case RELOAD_FOR_INPUT_ADDRESS:
4324 if (++first_inpaddr_num[rld[i].opnum] >= 0)
4326 first_inpaddr_num[rld[i].opnum] = i;
4327 need_change = 1;
4329 break;
4330 case RELOAD_FOR_OUTPUT_ADDRESS:
4331 if (++first_outpaddr_num[rld[i].opnum] >= 0)
4333 first_outpaddr_num[rld[i].opnum] = i;
4334 need_change = 1;
4336 break;
4337 default:
4338 break;
4342 if (need_change)
4344 for (i = 0; i < n_reloads; i++)
4346 int first_num;
4347 enum reload_type type;
4349 switch (rld[i].when_needed)
4351 case RELOAD_FOR_OPADDR_ADDR:
4352 first_num = first_op_addr_num;
4353 type = RELOAD_FOR_OPERAND_ADDRESS;
4354 break;
4355 case RELOAD_FOR_INPADDR_ADDRESS:
4356 first_num = first_inpaddr_num[rld[i].opnum];
4357 type = RELOAD_FOR_INPUT_ADDRESS;
4358 break;
4359 case RELOAD_FOR_OUTADDR_ADDRESS:
4360 first_num = first_outpaddr_num[rld[i].opnum];
4361 type = RELOAD_FOR_OUTPUT_ADDRESS;
4362 break;
4363 default:
4364 continue;
4366 if (first_num < 0)
4367 continue;
4368 else if (i > first_num)
4369 rld[i].when_needed = type;
4370 else
4372 /* Check if the only TYPE reload that uses reload I is
4373 reload FIRST_NUM. */
4374 for (j = n_reloads - 1; j > first_num; j--)
4376 if (rld[j].when_needed == type
4377 && (rld[i].secondary_p
4378 ? rld[j].secondary_in_reload == i
4379 : reg_mentioned_p (rld[i].in, rld[j].in)))
4381 rld[i].when_needed = type;
4382 break;
4390 /* See if we have any reloads that are now allowed to be merged
4391 because we've changed when the reload is needed to
4392 RELOAD_FOR_OPERAND_ADDRESS or RELOAD_FOR_OTHER_ADDRESS. Only
4393 check for the most common cases. */
4395 for (i = 0; i < n_reloads; i++)
4396 if (rld[i].in != 0 && rld[i].out == 0
4397 && (rld[i].when_needed == RELOAD_FOR_OPERAND_ADDRESS
4398 || rld[i].when_needed == RELOAD_FOR_OPADDR_ADDR
4399 || rld[i].when_needed == RELOAD_FOR_OTHER_ADDRESS))
4400 for (j = 0; j < n_reloads; j++)
4401 if (i != j && rld[j].in != 0 && rld[j].out == 0
4402 && rld[j].when_needed == rld[i].when_needed
4403 && MATCHES (rld[i].in, rld[j].in)
4404 && rld[i].class == rld[j].class
4405 && !rld[i].nocombine && !rld[j].nocombine
4406 && rld[i].reg_rtx == rld[j].reg_rtx)
4408 rld[i].opnum = MIN (rld[i].opnum, rld[j].opnum);
4409 transfer_replacements (i, j);
4410 rld[j].in = 0;
4413 #ifdef HAVE_cc0
4414 /* If we made any reloads for addresses, see if they violate a
4415 "no input reloads" requirement for this insn. But loads that we
4416 do after the insn (such as for output addresses) are fine. */
4417 if (no_input_reloads)
4418 for (i = 0; i < n_reloads; i++)
4419 gcc_assert (rld[i].in == 0
4420 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS
4421 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS);
4422 #endif
4424 /* Compute reload_mode and reload_nregs. */
4425 for (i = 0; i < n_reloads; i++)
4427 rld[i].mode
4428 = (rld[i].inmode == VOIDmode
4429 || (GET_MODE_SIZE (rld[i].outmode)
4430 > GET_MODE_SIZE (rld[i].inmode)))
4431 ? rld[i].outmode : rld[i].inmode;
4433 rld[i].nregs = CLASS_MAX_NREGS (rld[i].class, rld[i].mode);
4436 /* Special case a simple move with an input reload and a
4437 destination of a hard reg, if the hard reg is ok, use it. */
4438 for (i = 0; i < n_reloads; i++)
4439 if (rld[i].when_needed == RELOAD_FOR_INPUT
4440 && GET_CODE (PATTERN (insn)) == SET
4441 && REG_P (SET_DEST (PATTERN (insn)))
4442 && SET_SRC (PATTERN (insn)) == rld[i].in)
4444 rtx dest = SET_DEST (PATTERN (insn));
4445 unsigned int regno = REGNO (dest);
4447 if (regno < FIRST_PSEUDO_REGISTER
4448 && TEST_HARD_REG_BIT (reg_class_contents[rld[i].class], regno)
4449 && HARD_REGNO_MODE_OK (regno, rld[i].mode))
4451 int nr = hard_regno_nregs[regno][rld[i].mode];
4452 int ok = 1, nri;
4454 for (nri = 1; nri < nr; nri ++)
4455 if (! TEST_HARD_REG_BIT (reg_class_contents[rld[i].class], regno + nri))
4456 ok = 0;
4458 if (ok)
4459 rld[i].reg_rtx = dest;
4463 return retval;
4466 /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
4467 accepts a memory operand with constant address. */
4469 static int
4470 alternative_allows_memconst (const char *constraint, int altnum)
4472 int c;
4473 /* Skip alternatives before the one requested. */
4474 while (altnum > 0)
4476 while (*constraint++ != ',');
4477 altnum--;
4479 /* Scan the requested alternative for 'm' or 'o'.
4480 If one of them is present, this alternative accepts memory constants. */
4481 for (; (c = *constraint) && c != ',' && c != '#';
4482 constraint += CONSTRAINT_LEN (c, constraint))
4483 if (c == 'm' || c == 'o' || EXTRA_MEMORY_CONSTRAINT (c, constraint))
4484 return 1;
4485 return 0;
4488 /* Scan X for memory references and scan the addresses for reloading.
4489 Also checks for references to "constant" regs that we want to eliminate
4490 and replaces them with the values they stand for.
4491 We may alter X destructively if it contains a reference to such.
4492 If X is just a constant reg, we return the equivalent value
4493 instead of X.
4495 IND_LEVELS says how many levels of indirect addressing this machine
4496 supports.
4498 OPNUM and TYPE identify the purpose of the reload.
4500 IS_SET_DEST is true if X is the destination of a SET, which is not
4501 appropriate to be replaced by a constant.
4503 INSN, if nonzero, is the insn in which we do the reload. It is used
4504 to determine if we may generate output reloads, and where to put USEs
4505 for pseudos that we have to replace with stack slots.
4507 ADDRESS_RELOADED. If nonzero, is a pointer to where we put the
4508 result of find_reloads_address. */
4510 static rtx
4511 find_reloads_toplev (rtx x, int opnum, enum reload_type type,
4512 int ind_levels, int is_set_dest, rtx insn,
4513 int *address_reloaded)
4515 RTX_CODE code = GET_CODE (x);
4517 const char *fmt = GET_RTX_FORMAT (code);
4518 int i;
4519 int copied;
4521 if (code == REG)
4523 /* This code is duplicated for speed in find_reloads. */
4524 int regno = REGNO (x);
4525 if (reg_equiv_constant[regno] != 0 && !is_set_dest)
4526 x = reg_equiv_constant[regno];
4527 #if 0
4528 /* This creates (subreg (mem...)) which would cause an unnecessary
4529 reload of the mem. */
4530 else if (reg_equiv_mem[regno] != 0)
4531 x = reg_equiv_mem[regno];
4532 #endif
4533 else if (reg_equiv_memory_loc[regno]
4534 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
4536 rtx mem = make_memloc (x, regno);
4537 if (reg_equiv_address[regno]
4538 || ! rtx_equal_p (mem, reg_equiv_mem[regno]))
4540 /* If this is not a toplevel operand, find_reloads doesn't see
4541 this substitution. We have to emit a USE of the pseudo so
4542 that delete_output_reload can see it. */
4543 if (replace_reloads && recog_data.operand[opnum] != x)
4544 /* We mark the USE with QImode so that we recognize it
4545 as one that can be safely deleted at the end of
4546 reload. */
4547 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, x), insn),
4548 QImode);
4549 x = mem;
4550 i = find_reloads_address (GET_MODE (x), &x, XEXP (x, 0), &XEXP (x, 0),
4551 opnum, type, ind_levels, insn);
4552 if (address_reloaded)
4553 *address_reloaded = i;
4556 return x;
4558 if (code == MEM)
4560 rtx tem = x;
4562 i = find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0),
4563 opnum, type, ind_levels, insn);
4564 if (address_reloaded)
4565 *address_reloaded = i;
4567 return tem;
4570 if (code == SUBREG && REG_P (SUBREG_REG (x)))
4572 /* Check for SUBREG containing a REG that's equivalent to a
4573 constant. If the constant has a known value, truncate it
4574 right now. Similarly if we are extracting a single-word of a
4575 multi-word constant. If the constant is symbolic, allow it
4576 to be substituted normally. push_reload will strip the
4577 subreg later. The constant must not be VOIDmode, because we
4578 will lose the mode of the register (this should never happen
4579 because one of the cases above should handle it). */
4581 int regno = REGNO (SUBREG_REG (x));
4582 rtx tem;
4584 if (subreg_lowpart_p (x)
4585 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4586 && reg_equiv_constant[regno] != 0
4587 && (tem = gen_lowpart_common (GET_MODE (x),
4588 reg_equiv_constant[regno])) != 0)
4589 return tem;
4591 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4592 && reg_equiv_constant[regno] != 0)
4594 tem =
4595 simplify_gen_subreg (GET_MODE (x), reg_equiv_constant[regno],
4596 GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
4597 gcc_assert (tem);
4598 return tem;
4601 /* If the subreg contains a reg that will be converted to a mem,
4602 convert the subreg to a narrower memref now.
4603 Otherwise, we would get (subreg (mem ...) ...),
4604 which would force reload of the mem.
4606 We also need to do this if there is an equivalent MEM that is
4607 not offsettable. In that case, alter_subreg would produce an
4608 invalid address on big-endian machines.
4610 For machines that extend byte loads, we must not reload using
4611 a wider mode if we have a paradoxical SUBREG. find_reloads will
4612 force a reload in that case. So we should not do anything here. */
4614 else if (regno >= FIRST_PSEUDO_REGISTER
4615 #ifdef LOAD_EXTEND_OP
4616 && (GET_MODE_SIZE (GET_MODE (x))
4617 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
4618 #endif
4619 && (reg_equiv_address[regno] != 0
4620 || (reg_equiv_mem[regno] != 0
4621 && (! strict_memory_address_p (GET_MODE (x),
4622 XEXP (reg_equiv_mem[regno], 0))
4623 || ! offsettable_memref_p (reg_equiv_mem[regno])
4624 || num_not_at_initial_offset))))
4625 x = find_reloads_subreg_address (x, 1, opnum, type, ind_levels,
4626 insn);
4629 for (copied = 0, i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4631 if (fmt[i] == 'e')
4633 rtx new_part = find_reloads_toplev (XEXP (x, i), opnum, type,
4634 ind_levels, is_set_dest, insn,
4635 address_reloaded);
4636 /* If we have replaced a reg with it's equivalent memory loc -
4637 that can still be handled here e.g. if it's in a paradoxical
4638 subreg - we must make the change in a copy, rather than using
4639 a destructive change. This way, find_reloads can still elect
4640 not to do the change. */
4641 if (new_part != XEXP (x, i) && ! CONSTANT_P (new_part) && ! copied)
4643 x = shallow_copy_rtx (x);
4644 copied = 1;
4646 XEXP (x, i) = new_part;
4649 return x;
4652 /* Return a mem ref for the memory equivalent of reg REGNO.
4653 This mem ref is not shared with anything. */
4655 static rtx
4656 make_memloc (rtx ad, int regno)
4658 /* We must rerun eliminate_regs, in case the elimination
4659 offsets have changed. */
4660 rtx tem
4661 = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0, NULL_RTX), 0);
4663 /* If TEM might contain a pseudo, we must copy it to avoid
4664 modifying it when we do the substitution for the reload. */
4665 if (rtx_varies_p (tem, 0))
4666 tem = copy_rtx (tem);
4668 tem = replace_equiv_address_nv (reg_equiv_memory_loc[regno], tem);
4669 tem = adjust_address_nv (tem, GET_MODE (ad), 0);
4671 /* Copy the result if it's still the same as the equivalence, to avoid
4672 modifying it when we do the substitution for the reload. */
4673 if (tem == reg_equiv_memory_loc[regno])
4674 tem = copy_rtx (tem);
4675 return tem;
4678 /* Returns true if AD could be turned into a valid memory reference
4679 to mode MODE by reloading the part pointed to by PART into a
4680 register. */
4682 static int
4683 maybe_memory_address_p (enum machine_mode mode, rtx ad, rtx *part)
4685 int retv;
4686 rtx tem = *part;
4687 rtx reg = gen_rtx_REG (GET_MODE (tem), max_reg_num ());
4689 *part = reg;
4690 retv = memory_address_p (mode, ad);
4691 *part = tem;
4693 return retv;
4696 /* Record all reloads needed for handling memory address AD
4697 which appears in *LOC in a memory reference to mode MODE
4698 which itself is found in location *MEMREFLOC.
4699 Note that we take shortcuts assuming that no multi-reg machine mode
4700 occurs as part of an address.
4702 OPNUM and TYPE specify the purpose of this reload.
4704 IND_LEVELS says how many levels of indirect addressing this machine
4705 supports.
4707 INSN, if nonzero, is the insn in which we do the reload. It is used
4708 to determine if we may generate output reloads, and where to put USEs
4709 for pseudos that we have to replace with stack slots.
4711 Value is one if this address is reloaded or replaced as a whole; it is
4712 zero if the top level of this address was not reloaded or replaced, and
4713 it is -1 if it may or may not have been reloaded or replaced.
4715 Note that there is no verification that the address will be valid after
4716 this routine does its work. Instead, we rely on the fact that the address
4717 was valid when reload started. So we need only undo things that reload
4718 could have broken. These are wrong register types, pseudos not allocated
4719 to a hard register, and frame pointer elimination. */
4721 static int
4722 find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
4723 rtx *loc, int opnum, enum reload_type type,
4724 int ind_levels, rtx insn)
4726 int regno;
4727 int removed_and = 0;
4728 int op_index;
4729 rtx tem;
4731 /* If the address is a register, see if it is a legitimate address and
4732 reload if not. We first handle the cases where we need not reload
4733 or where we must reload in a non-standard way. */
4735 if (REG_P (ad))
4737 regno = REGNO (ad);
4739 /* If the register is equivalent to an invariant expression, substitute
4740 the invariant, and eliminate any eliminable register references. */
4741 tem = reg_equiv_constant[regno];
4742 if (tem != 0
4743 && (tem = eliminate_regs (tem, mode, insn))
4744 && strict_memory_address_p (mode, tem))
4746 *loc = ad = tem;
4747 return 0;
4750 tem = reg_equiv_memory_loc[regno];
4751 if (tem != 0)
4753 if (reg_equiv_address[regno] != 0 || num_not_at_initial_offset)
4755 tem = make_memloc (ad, regno);
4756 if (! strict_memory_address_p (GET_MODE (tem), XEXP (tem, 0)))
4758 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
4759 &XEXP (tem, 0), opnum,
4760 ADDR_TYPE (type), ind_levels, insn);
4762 /* We can avoid a reload if the register's equivalent memory
4763 expression is valid as an indirect memory address.
4764 But not all addresses are valid in a mem used as an indirect
4765 address: only reg or reg+constant. */
4767 if (ind_levels > 0
4768 && strict_memory_address_p (mode, tem)
4769 && (REG_P (XEXP (tem, 0))
4770 || (GET_CODE (XEXP (tem, 0)) == PLUS
4771 && REG_P (XEXP (XEXP (tem, 0), 0))
4772 && CONSTANT_P (XEXP (XEXP (tem, 0), 1)))))
4774 /* TEM is not the same as what we'll be replacing the
4775 pseudo with after reload, put a USE in front of INSN
4776 in the final reload pass. */
4777 if (replace_reloads
4778 && num_not_at_initial_offset
4779 && ! rtx_equal_p (tem, reg_equiv_mem[regno]))
4781 *loc = tem;
4782 /* We mark the USE with QImode so that we
4783 recognize it as one that can be safely
4784 deleted at the end of reload. */
4785 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad),
4786 insn), QImode);
4788 /* This doesn't really count as replacing the address
4789 as a whole, since it is still a memory access. */
4791 return 0;
4793 ad = tem;
4797 /* The only remaining case where we can avoid a reload is if this is a
4798 hard register that is valid as a base register and which is not the
4799 subject of a CLOBBER in this insn. */
4801 else if (regno < FIRST_PSEUDO_REGISTER
4802 && REGNO_MODE_OK_FOR_BASE_P (regno, mode)
4803 && ! regno_clobbered_p (regno, this_insn, mode, 0))
4804 return 0;
4806 /* If we do not have one of the cases above, we must do the reload. */
4807 push_reload (ad, NULL_RTX, loc, (rtx*) 0, MODE_BASE_REG_CLASS (mode),
4808 GET_MODE (ad), VOIDmode, 0, 0, opnum, type);
4809 return 1;
4812 if (strict_memory_address_p (mode, ad))
4814 /* The address appears valid, so reloads are not needed.
4815 But the address may contain an eliminable register.
4816 This can happen because a machine with indirect addressing
4817 may consider a pseudo register by itself a valid address even when
4818 it has failed to get a hard reg.
4819 So do a tree-walk to find and eliminate all such regs. */
4821 /* But first quickly dispose of a common case. */
4822 if (GET_CODE (ad) == PLUS
4823 && GET_CODE (XEXP (ad, 1)) == CONST_INT
4824 && REG_P (XEXP (ad, 0))
4825 && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
4826 return 0;
4828 subst_reg_equivs_changed = 0;
4829 *loc = subst_reg_equivs (ad, insn);
4831 if (! subst_reg_equivs_changed)
4832 return 0;
4834 /* Check result for validity after substitution. */
4835 if (strict_memory_address_p (mode, ad))
4836 return 0;
4839 #ifdef LEGITIMIZE_RELOAD_ADDRESS
4842 if (memrefloc)
4844 LEGITIMIZE_RELOAD_ADDRESS (ad, GET_MODE (*memrefloc), opnum, type,
4845 ind_levels, win);
4847 break;
4848 win:
4849 *memrefloc = copy_rtx (*memrefloc);
4850 XEXP (*memrefloc, 0) = ad;
4851 move_replacements (&ad, &XEXP (*memrefloc, 0));
4852 return -1;
4854 while (0);
4855 #endif
4857 /* The address is not valid. We have to figure out why. First see if
4858 we have an outer AND and remove it if so. Then analyze what's inside. */
4860 if (GET_CODE (ad) == AND)
4862 removed_and = 1;
4863 loc = &XEXP (ad, 0);
4864 ad = *loc;
4867 /* One possibility for why the address is invalid is that it is itself
4868 a MEM. This can happen when the frame pointer is being eliminated, a
4869 pseudo is not allocated to a hard register, and the offset between the
4870 frame and stack pointers is not its initial value. In that case the
4871 pseudo will have been replaced by a MEM referring to the
4872 stack pointer. */
4873 if (MEM_P (ad))
4875 /* First ensure that the address in this MEM is valid. Then, unless
4876 indirect addresses are valid, reload the MEM into a register. */
4877 tem = ad;
4878 find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0),
4879 opnum, ADDR_TYPE (type),
4880 ind_levels == 0 ? 0 : ind_levels - 1, insn);
4882 /* If tem was changed, then we must create a new memory reference to
4883 hold it and store it back into memrefloc. */
4884 if (tem != ad && memrefloc)
4886 *memrefloc = copy_rtx (*memrefloc);
4887 copy_replacements (tem, XEXP (*memrefloc, 0));
4888 loc = &XEXP (*memrefloc, 0);
4889 if (removed_and)
4890 loc = &XEXP (*loc, 0);
4893 /* Check similar cases as for indirect addresses as above except
4894 that we can allow pseudos and a MEM since they should have been
4895 taken care of above. */
4897 if (ind_levels == 0
4898 || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok)
4899 || MEM_P (XEXP (tem, 0))
4900 || ! (REG_P (XEXP (tem, 0))
4901 || (GET_CODE (XEXP (tem, 0)) == PLUS
4902 && REG_P (XEXP (XEXP (tem, 0), 0))
4903 && GET_CODE (XEXP (XEXP (tem, 0), 1)) == CONST_INT)))
4905 /* Must use TEM here, not AD, since it is the one that will
4906 have any subexpressions reloaded, if needed. */
4907 push_reload (tem, NULL_RTX, loc, (rtx*) 0,
4908 MODE_BASE_REG_CLASS (mode), GET_MODE (tem),
4909 VOIDmode, 0,
4910 0, opnum, type);
4911 return ! removed_and;
4913 else
4914 return 0;
4917 /* If we have address of a stack slot but it's not valid because the
4918 displacement is too large, compute the sum in a register.
4919 Handle all base registers here, not just fp/ap/sp, because on some
4920 targets (namely SH) we can also get too large displacements from
4921 big-endian corrections. */
4922 else if (GET_CODE (ad) == PLUS
4923 && REG_P (XEXP (ad, 0))
4924 && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER
4925 && REG_MODE_OK_FOR_BASE_P (XEXP (ad, 0), mode)
4926 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4928 /* Unshare the MEM rtx so we can safely alter it. */
4929 if (memrefloc)
4931 *memrefloc = copy_rtx (*memrefloc);
4932 loc = &XEXP (*memrefloc, 0);
4933 if (removed_and)
4934 loc = &XEXP (*loc, 0);
4937 if (double_reg_address_ok)
4939 /* Unshare the sum as well. */
4940 *loc = ad = copy_rtx (ad);
4942 /* Reload the displacement into an index reg.
4943 We assume the frame pointer or arg pointer is a base reg. */
4944 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4945 INDEX_REG_CLASS, GET_MODE (ad), opnum,
4946 type, ind_levels);
4947 return 0;
4949 else
4951 /* If the sum of two regs is not necessarily valid,
4952 reload the sum into a base reg.
4953 That will at least work. */
4954 find_reloads_address_part (ad, loc, MODE_BASE_REG_CLASS (mode),
4955 Pmode, opnum, type, ind_levels);
4957 return ! removed_and;
4960 /* If we have an indexed stack slot, there are three possible reasons why
4961 it might be invalid: The index might need to be reloaded, the address
4962 might have been made by frame pointer elimination and hence have a
4963 constant out of range, or both reasons might apply.
4965 We can easily check for an index needing reload, but even if that is the
4966 case, we might also have an invalid constant. To avoid making the
4967 conservative assumption and requiring two reloads, we see if this address
4968 is valid when not interpreted strictly. If it is, the only problem is
4969 that the index needs a reload and find_reloads_address_1 will take care
4970 of it.
4972 Handle all base registers here, not just fp/ap/sp, because on some
4973 targets (namely SPARC) we can also get invalid addresses from preventive
4974 subreg big-endian corrections made by find_reloads_toplev. We
4975 can also get expressions involving LO_SUM (rather than PLUS) from
4976 find_reloads_subreg_address.
4978 If we decide to do something, it must be that `double_reg_address_ok'
4979 is true. We generate a reload of the base register + constant and
4980 rework the sum so that the reload register will be added to the index.
4981 This is safe because we know the address isn't shared.
4983 We check for the base register as both the first and second operand of
4984 the innermost PLUS and/or LO_SUM. */
4986 for (op_index = 0; op_index < 2; ++op_index)
4988 rtx operand;
4990 if (!(GET_CODE (ad) == PLUS
4991 && GET_CODE (XEXP (ad, 1)) == CONST_INT
4992 && (GET_CODE (XEXP (ad, 0)) == PLUS
4993 || GET_CODE (XEXP (ad, 0)) == LO_SUM)))
4994 continue;
4996 operand = XEXP (XEXP (ad, 0), op_index);
4997 if (!REG_P (operand) || REGNO (operand) >= FIRST_PSEUDO_REGISTER)
4998 continue;
5000 if ((REG_MODE_OK_FOR_BASE_P (operand, mode)
5001 || operand == frame_pointer_rtx
5002 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
5003 || operand == hard_frame_pointer_rtx
5004 #endif
5005 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
5006 || operand == arg_pointer_rtx
5007 #endif
5008 || operand == stack_pointer_rtx)
5009 && ! maybe_memory_address_p (mode, ad,
5010 &XEXP (XEXP (ad, 0), 1 - op_index)))
5012 rtx offset_reg;
5013 rtx addend;
5015 offset_reg = plus_constant (operand, INTVAL (XEXP (ad, 1)));
5016 addend = XEXP (XEXP (ad, 0), 1 - op_index);
5018 /* Form the adjusted address. */
5019 if (GET_CODE (XEXP (ad, 0)) == PLUS)
5020 ad = gen_rtx_PLUS (GET_MODE (ad),
5021 op_index == 0 ? offset_reg : addend,
5022 op_index == 0 ? addend : offset_reg);
5023 else
5024 ad = gen_rtx_LO_SUM (GET_MODE (ad),
5025 op_index == 0 ? offset_reg : addend,
5026 op_index == 0 ? addend : offset_reg);
5027 *loc = ad;
5029 find_reloads_address_part (XEXP (ad, op_index),
5030 &XEXP (ad, op_index),
5031 MODE_BASE_REG_CLASS (mode),
5032 GET_MODE (ad), opnum, type, ind_levels);
5033 find_reloads_address_1 (mode,
5034 XEXP (ad, 1 - op_index), 1,
5035 &XEXP (ad, 1 - op_index), opnum,
5036 type, 0, insn);
5038 return 0;
5042 /* See if address becomes valid when an eliminable register
5043 in a sum is replaced. */
5045 tem = ad;
5046 if (GET_CODE (ad) == PLUS)
5047 tem = subst_indexed_address (ad);
5048 if (tem != ad && strict_memory_address_p (mode, tem))
5050 /* Ok, we win that way. Replace any additional eliminable
5051 registers. */
5053 subst_reg_equivs_changed = 0;
5054 tem = subst_reg_equivs (tem, insn);
5056 /* Make sure that didn't make the address invalid again. */
5058 if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
5060 *loc = tem;
5061 return 0;
5065 /* If constants aren't valid addresses, reload the constant address
5066 into a register. */
5067 if (CONSTANT_P (ad) && ! strict_memory_address_p (mode, ad))
5069 /* If AD is an address in the constant pool, the MEM rtx may be shared.
5070 Unshare it so we can safely alter it. */
5071 if (memrefloc && GET_CODE (ad) == SYMBOL_REF
5072 && CONSTANT_POOL_ADDRESS_P (ad))
5074 *memrefloc = copy_rtx (*memrefloc);
5075 loc = &XEXP (*memrefloc, 0);
5076 if (removed_and)
5077 loc = &XEXP (*loc, 0);
5080 find_reloads_address_part (ad, loc, MODE_BASE_REG_CLASS (mode),
5081 Pmode, opnum, type, ind_levels);
5082 return ! removed_and;
5085 return find_reloads_address_1 (mode, ad, 0, loc, opnum, type, ind_levels,
5086 insn);
5089 /* Find all pseudo regs appearing in AD
5090 that are eliminable in favor of equivalent values
5091 and do not have hard regs; replace them by their equivalents.
5092 INSN, if nonzero, is the insn in which we do the reload. We put USEs in
5093 front of it for pseudos that we have to replace with stack slots. */
5095 static rtx
5096 subst_reg_equivs (rtx ad, rtx insn)
5098 RTX_CODE code = GET_CODE (ad);
5099 int i;
5100 const char *fmt;
5102 switch (code)
5104 case HIGH:
5105 case CONST_INT:
5106 case CONST:
5107 case CONST_DOUBLE:
5108 case CONST_VECTOR:
5109 case SYMBOL_REF:
5110 case LABEL_REF:
5111 case PC:
5112 case CC0:
5113 return ad;
5115 case REG:
5117 int regno = REGNO (ad);
5119 if (reg_equiv_constant[regno] != 0)
5121 subst_reg_equivs_changed = 1;
5122 return reg_equiv_constant[regno];
5124 if (reg_equiv_memory_loc[regno] && num_not_at_initial_offset)
5126 rtx mem = make_memloc (ad, regno);
5127 if (! rtx_equal_p (mem, reg_equiv_mem[regno]))
5129 subst_reg_equivs_changed = 1;
5130 /* We mark the USE with QImode so that we recognize it
5131 as one that can be safely deleted at the end of
5132 reload. */
5133 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad), insn),
5134 QImode);
5135 return mem;
5139 return ad;
5141 case PLUS:
5142 /* Quickly dispose of a common case. */
5143 if (XEXP (ad, 0) == frame_pointer_rtx
5144 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
5145 return ad;
5146 break;
5148 default:
5149 break;
5152 fmt = GET_RTX_FORMAT (code);
5153 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5154 if (fmt[i] == 'e')
5155 XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i), insn);
5156 return ad;
5159 /* Compute the sum of X and Y, making canonicalizations assumed in an
5160 address, namely: sum constant integers, surround the sum of two
5161 constants with a CONST, put the constant as the second operand, and
5162 group the constant on the outermost sum.
5164 This routine assumes both inputs are already in canonical form. */
5167 form_sum (rtx x, rtx y)
5169 rtx tem;
5170 enum machine_mode mode = GET_MODE (x);
5172 if (mode == VOIDmode)
5173 mode = GET_MODE (y);
5175 if (mode == VOIDmode)
5176 mode = Pmode;
5178 if (GET_CODE (x) == CONST_INT)
5179 return plus_constant (y, INTVAL (x));
5180 else if (GET_CODE (y) == CONST_INT)
5181 return plus_constant (x, INTVAL (y));
5182 else if (CONSTANT_P (x))
5183 tem = x, x = y, y = tem;
5185 if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
5186 return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y));
5188 /* Note that if the operands of Y are specified in the opposite
5189 order in the recursive calls below, infinite recursion will occur. */
5190 if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
5191 return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1));
5193 /* If both constant, encapsulate sum. Otherwise, just form sum. A
5194 constant will have been placed second. */
5195 if (CONSTANT_P (x) && CONSTANT_P (y))
5197 if (GET_CODE (x) == CONST)
5198 x = XEXP (x, 0);
5199 if (GET_CODE (y) == CONST)
5200 y = XEXP (y, 0);
5202 return gen_rtx_CONST (VOIDmode, gen_rtx_PLUS (mode, x, y));
5205 return gen_rtx_PLUS (mode, x, y);
5208 /* If ADDR is a sum containing a pseudo register that should be
5209 replaced with a constant (from reg_equiv_constant),
5210 return the result of doing so, and also apply the associative
5211 law so that the result is more likely to be a valid address.
5212 (But it is not guaranteed to be one.)
5214 Note that at most one register is replaced, even if more are
5215 replaceable. Also, we try to put the result into a canonical form
5216 so it is more likely to be a valid address.
5218 In all other cases, return ADDR. */
5220 static rtx
5221 subst_indexed_address (rtx addr)
5223 rtx op0 = 0, op1 = 0, op2 = 0;
5224 rtx tem;
5225 int regno;
5227 if (GET_CODE (addr) == PLUS)
5229 /* Try to find a register to replace. */
5230 op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0;
5231 if (REG_P (op0)
5232 && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER
5233 && reg_renumber[regno] < 0
5234 && reg_equiv_constant[regno] != 0)
5235 op0 = reg_equiv_constant[regno];
5236 else if (REG_P (op1)
5237 && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER
5238 && reg_renumber[regno] < 0
5239 && reg_equiv_constant[regno] != 0)
5240 op1 = reg_equiv_constant[regno];
5241 else if (GET_CODE (op0) == PLUS
5242 && (tem = subst_indexed_address (op0)) != op0)
5243 op0 = tem;
5244 else if (GET_CODE (op1) == PLUS
5245 && (tem = subst_indexed_address (op1)) != op1)
5246 op1 = tem;
5247 else
5248 return addr;
5250 /* Pick out up to three things to add. */
5251 if (GET_CODE (op1) == PLUS)
5252 op2 = XEXP (op1, 1), op1 = XEXP (op1, 0);
5253 else if (GET_CODE (op0) == PLUS)
5254 op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
5256 /* Compute the sum. */
5257 if (op2 != 0)
5258 op1 = form_sum (op1, op2);
5259 if (op1 != 0)
5260 op0 = form_sum (op0, op1);
5262 return op0;
5264 return addr;
5267 /* Update the REG_INC notes for an insn. It updates all REG_INC
5268 notes for the instruction which refer to REGNO the to refer
5269 to the reload number.
5271 INSN is the insn for which any REG_INC notes need updating.
5273 REGNO is the register number which has been reloaded.
5275 RELOADNUM is the reload number. */
5277 static void
5278 update_auto_inc_notes (rtx insn ATTRIBUTE_UNUSED, int regno ATTRIBUTE_UNUSED,
5279 int reloadnum ATTRIBUTE_UNUSED)
5281 #ifdef AUTO_INC_DEC
5282 rtx link;
5284 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
5285 if (REG_NOTE_KIND (link) == REG_INC
5286 && (int) REGNO (XEXP (link, 0)) == regno)
5287 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5288 #endif
5291 /* Record the pseudo registers we must reload into hard registers in a
5292 subexpression of a would-be memory address, X referring to a value
5293 in mode MODE. (This function is not called if the address we find
5294 is strictly valid.)
5296 CONTEXT = 1 means we are considering regs as index regs,
5297 = 0 means we are considering them as base regs, = 2 means we
5298 are considering them as base regs for REG + REG.
5300 OPNUM and TYPE specify the purpose of any reloads made.
5302 IND_LEVELS says how many levels of indirect addressing are
5303 supported at this point in the address.
5305 INSN, if nonzero, is the insn in which we do the reload. It is used
5306 to determine if we may generate output reloads.
5308 We return nonzero if X, as a whole, is reloaded or replaced. */
5310 /* Note that we take shortcuts assuming that no multi-reg machine mode
5311 occurs as part of an address.
5312 Also, this is not fully machine-customizable; it works for machines
5313 such as VAXen and 68000's and 32000's, but other possible machines
5314 could have addressing modes that this does not handle right. */
5316 static int
5317 find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
5318 rtx *loc, int opnum, enum reload_type type,
5319 int ind_levels, rtx insn)
5321 #define REG_OK_FOR_CONTEXT(CONTEXT, REGNO, MODE) \
5322 ((CONTEXT) == 2 \
5323 ? REGNO_MODE_OK_FOR_REG_BASE_P (REGNO, MODE) \
5324 : (CONTEXT) == 1 \
5325 ? REGNO_OK_FOR_INDEX_P (REGNO) \
5326 : REGNO_MODE_OK_FOR_BASE_P (REGNO, MODE))
5328 enum reg_class context_reg_class;
5329 RTX_CODE code = GET_CODE (x);
5331 if (context == 2)
5332 context_reg_class = MODE_BASE_REG_REG_CLASS (mode);
5333 else if (context == 1)
5334 context_reg_class = INDEX_REG_CLASS;
5335 else
5336 context_reg_class = MODE_BASE_REG_CLASS (mode);
5338 switch (code)
5340 case PLUS:
5342 rtx orig_op0 = XEXP (x, 0);
5343 rtx orig_op1 = XEXP (x, 1);
5344 RTX_CODE code0 = GET_CODE (orig_op0);
5345 RTX_CODE code1 = GET_CODE (orig_op1);
5346 rtx op0 = orig_op0;
5347 rtx op1 = orig_op1;
5349 if (GET_CODE (op0) == SUBREG)
5351 op0 = SUBREG_REG (op0);
5352 code0 = GET_CODE (op0);
5353 if (code0 == REG && REGNO (op0) < FIRST_PSEUDO_REGISTER)
5354 op0 = gen_rtx_REG (word_mode,
5355 (REGNO (op0) +
5356 subreg_regno_offset (REGNO (SUBREG_REG (orig_op0)),
5357 GET_MODE (SUBREG_REG (orig_op0)),
5358 SUBREG_BYTE (orig_op0),
5359 GET_MODE (orig_op0))));
5362 if (GET_CODE (op1) == SUBREG)
5364 op1 = SUBREG_REG (op1);
5365 code1 = GET_CODE (op1);
5366 if (code1 == REG && REGNO (op1) < FIRST_PSEUDO_REGISTER)
5367 /* ??? Why is this given op1's mode and above for
5368 ??? op0 SUBREGs we use word_mode? */
5369 op1 = gen_rtx_REG (GET_MODE (op1),
5370 (REGNO (op1) +
5371 subreg_regno_offset (REGNO (SUBREG_REG (orig_op1)),
5372 GET_MODE (SUBREG_REG (orig_op1)),
5373 SUBREG_BYTE (orig_op1),
5374 GET_MODE (orig_op1))));
5376 /* Plus in the index register may be created only as a result of
5377 register remateralization for expression like &localvar*4. Reload it.
5378 It may be possible to combine the displacement on the outer level,
5379 but it is probably not worthwhile to do so. */
5380 if (context == 1)
5382 find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5383 opnum, ADDR_TYPE (type), ind_levels, insn);
5384 push_reload (*loc, NULL_RTX, loc, (rtx*) 0,
5385 context_reg_class,
5386 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5387 return 1;
5390 if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
5391 || code0 == ZERO_EXTEND || code1 == MEM)
5393 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5394 type, ind_levels, insn);
5395 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5396 type, ind_levels, insn);
5399 else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
5400 || code1 == ZERO_EXTEND || code0 == MEM)
5402 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5403 type, ind_levels, insn);
5404 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5405 type, ind_levels, insn);
5408 else if (code0 == CONST_INT || code0 == CONST
5409 || code0 == SYMBOL_REF || code0 == LABEL_REF)
5410 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5411 type, ind_levels, insn);
5413 else if (code1 == CONST_INT || code1 == CONST
5414 || code1 == SYMBOL_REF || code1 == LABEL_REF)
5415 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5416 type, ind_levels, insn);
5418 else if (code0 == REG && code1 == REG)
5420 if (REG_OK_FOR_INDEX_P (op0)
5421 && REG_MODE_OK_FOR_REG_BASE_P (op1, mode))
5422 return 0;
5423 else if (REG_OK_FOR_INDEX_P (op1)
5424 && REG_MODE_OK_FOR_REG_BASE_P (op0, mode))
5425 return 0;
5426 else if (REG_MODE_OK_FOR_REG_BASE_P (op1, mode))
5427 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5428 type, ind_levels, insn);
5429 else if (REG_MODE_OK_FOR_REG_BASE_P (op0, mode))
5430 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5431 type, ind_levels, insn);
5432 else if (REG_OK_FOR_INDEX_P (op1))
5433 find_reloads_address_1 (mode, orig_op0, 2, &XEXP (x, 0), opnum,
5434 type, ind_levels, insn);
5435 else if (REG_OK_FOR_INDEX_P (op0))
5436 find_reloads_address_1 (mode, orig_op1, 2, &XEXP (x, 1), opnum,
5437 type, ind_levels, insn);
5438 else
5440 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5441 type, ind_levels, insn);
5442 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5443 type, ind_levels, insn);
5447 else if (code0 == REG)
5449 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5450 type, ind_levels, insn);
5451 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5452 type, ind_levels, insn);
5455 else if (code1 == REG)
5457 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5458 type, ind_levels, insn);
5459 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5460 type, ind_levels, insn);
5464 return 0;
5466 case POST_MODIFY:
5467 case PRE_MODIFY:
5469 rtx op0 = XEXP (x, 0);
5470 rtx op1 = XEXP (x, 1);
5471 int regno;
5472 int reloadnum;
5474 if (GET_CODE (op1) != PLUS && GET_CODE (op1) != MINUS)
5475 return 0;
5477 /* Currently, we only support {PRE,POST}_MODIFY constructs
5478 where a base register is {inc,dec}remented by the contents
5479 of another register or by a constant value. Thus, these
5480 operands must match. */
5481 gcc_assert (op0 == XEXP (op1, 0));
5483 /* Require index register (or constant). Let's just handle the
5484 register case in the meantime... If the target allows
5485 auto-modify by a constant then we could try replacing a pseudo
5486 register with its equivalent constant where applicable. */
5487 if (REG_P (XEXP (op1, 1)))
5488 if (!REGNO_OK_FOR_INDEX_P (REGNO (XEXP (op1, 1))))
5489 find_reloads_address_1 (mode, XEXP (op1, 1), 1, &XEXP (op1, 1),
5490 opnum, type, ind_levels, insn);
5492 gcc_assert (REG_P (XEXP (op1, 0)));
5494 regno = REGNO (XEXP (op1, 0));
5496 /* A register that is incremented cannot be constant! */
5497 gcc_assert (regno < FIRST_PSEUDO_REGISTER
5498 || reg_equiv_constant[regno] == 0);
5500 /* Handle a register that is equivalent to a memory location
5501 which cannot be addressed directly. */
5502 if (reg_equiv_memory_loc[regno] != 0
5503 && (reg_equiv_address[regno] != 0
5504 || num_not_at_initial_offset))
5506 rtx tem = make_memloc (XEXP (x, 0), regno);
5508 if (reg_equiv_address[regno]
5509 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5511 /* First reload the memory location's address.
5512 We can't use ADDR_TYPE (type) here, because we need to
5513 write back the value after reading it, hence we actually
5514 need two registers. */
5515 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5516 &XEXP (tem, 0), opnum,
5517 RELOAD_OTHER,
5518 ind_levels, insn);
5520 /* Then reload the memory location into a base
5521 register. */
5522 reloadnum = push_reload (tem, tem, &XEXP (x, 0),
5523 &XEXP (op1, 0),
5524 MODE_BASE_REG_CLASS (mode),
5525 GET_MODE (x), GET_MODE (x), 0,
5526 0, opnum, RELOAD_OTHER);
5528 update_auto_inc_notes (this_insn, regno, reloadnum);
5529 return 0;
5533 if (reg_renumber[regno] >= 0)
5534 regno = reg_renumber[regno];
5536 /* We require a base register here... */
5537 if (!REGNO_MODE_OK_FOR_BASE_P (regno, GET_MODE (x)))
5539 reloadnum = push_reload (XEXP (op1, 0), XEXP (x, 0),
5540 &XEXP (op1, 0), &XEXP (x, 0),
5541 MODE_BASE_REG_CLASS (mode),
5542 GET_MODE (x), GET_MODE (x), 0, 0,
5543 opnum, RELOAD_OTHER);
5545 update_auto_inc_notes (this_insn, regno, reloadnum);
5546 return 0;
5549 return 0;
5551 case POST_INC:
5552 case POST_DEC:
5553 case PRE_INC:
5554 case PRE_DEC:
5555 if (REG_P (XEXP (x, 0)))
5557 int regno = REGNO (XEXP (x, 0));
5558 int value = 0;
5559 rtx x_orig = x;
5561 /* A register that is incremented cannot be constant! */
5562 gcc_assert (regno < FIRST_PSEUDO_REGISTER
5563 || reg_equiv_constant[regno] == 0);
5565 /* Handle a register that is equivalent to a memory location
5566 which cannot be addressed directly. */
5567 if (reg_equiv_memory_loc[regno] != 0
5568 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
5570 rtx tem = make_memloc (XEXP (x, 0), regno);
5571 if (reg_equiv_address[regno]
5572 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5574 /* First reload the memory location's address.
5575 We can't use ADDR_TYPE (type) here, because we need to
5576 write back the value after reading it, hence we actually
5577 need two registers. */
5578 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5579 &XEXP (tem, 0), opnum, type,
5580 ind_levels, insn);
5581 /* Put this inside a new increment-expression. */
5582 x = gen_rtx_fmt_e (GET_CODE (x), GET_MODE (x), tem);
5583 /* Proceed to reload that, as if it contained a register. */
5587 /* If we have a hard register that is ok as an index,
5588 don't make a reload. If an autoincrement of a nice register
5589 isn't "valid", it must be that no autoincrement is "valid".
5590 If that is true and something made an autoincrement anyway,
5591 this must be a special context where one is allowed.
5592 (For example, a "push" instruction.)
5593 We can't improve this address, so leave it alone. */
5595 /* Otherwise, reload the autoincrement into a suitable hard reg
5596 and record how much to increment by. */
5598 if (reg_renumber[regno] >= 0)
5599 regno = reg_renumber[regno];
5600 if (regno >= FIRST_PSEUDO_REGISTER
5601 || !REG_OK_FOR_CONTEXT (context, regno, mode))
5603 int reloadnum;
5605 /* If we can output the register afterwards, do so, this
5606 saves the extra update.
5607 We can do so if we have an INSN - i.e. no JUMP_INSN nor
5608 CALL_INSN - and it does not set CC0.
5609 But don't do this if we cannot directly address the
5610 memory location, since this will make it harder to
5611 reuse address reloads, and increases register pressure.
5612 Also don't do this if we can probably update x directly. */
5613 rtx equiv = (MEM_P (XEXP (x, 0))
5614 ? XEXP (x, 0)
5615 : reg_equiv_mem[regno]);
5616 int icode = (int) add_optab->handlers[(int) Pmode].insn_code;
5617 if (insn && NONJUMP_INSN_P (insn) && equiv
5618 && memory_operand (equiv, GET_MODE (equiv))
5619 #ifdef HAVE_cc0
5620 && ! sets_cc0_p (PATTERN (insn))
5621 #endif
5622 && ! (icode != CODE_FOR_nothing
5623 && ((*insn_data[icode].operand[0].predicate)
5624 (equiv, Pmode))
5625 && ((*insn_data[icode].operand[1].predicate)
5626 (equiv, Pmode))))
5628 /* We use the original pseudo for loc, so that
5629 emit_reload_insns() knows which pseudo this
5630 reload refers to and updates the pseudo rtx, not
5631 its equivalent memory location, as well as the
5632 corresponding entry in reg_last_reload_reg. */
5633 loc = &XEXP (x_orig, 0);
5634 x = XEXP (x, 0);
5635 reloadnum
5636 = push_reload (x, x, loc, loc,
5637 context_reg_class,
5638 GET_MODE (x), GET_MODE (x), 0, 0,
5639 opnum, RELOAD_OTHER);
5641 else
5643 reloadnum
5644 = push_reload (x, NULL_RTX, loc, (rtx*) 0,
5645 context_reg_class,
5646 GET_MODE (x), GET_MODE (x), 0, 0,
5647 opnum, type);
5648 rld[reloadnum].inc
5649 = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0));
5651 value = 1;
5654 update_auto_inc_notes (this_insn, REGNO (XEXP (x_orig, 0)),
5655 reloadnum);
5657 return value;
5660 else if (MEM_P (XEXP (x, 0)))
5662 /* This is probably the result of a substitution, by eliminate_regs,
5663 of an equivalent address for a pseudo that was not allocated to a
5664 hard register. Verify that the specified address is valid and
5665 reload it into a register. */
5666 /* Variable `tem' might or might not be used in FIND_REG_INC_NOTE. */
5667 rtx tem ATTRIBUTE_UNUSED = XEXP (x, 0);
5668 rtx link;
5669 int reloadnum;
5671 /* Since we know we are going to reload this item, don't decrement
5672 for the indirection level.
5674 Note that this is actually conservative: it would be slightly
5675 more efficient to use the value of SPILL_INDIRECT_LEVELS from
5676 reload1.c here. */
5677 /* We can't use ADDR_TYPE (type) here, because we need to
5678 write back the value after reading it, hence we actually
5679 need two registers. */
5680 find_reloads_address (GET_MODE (x), &XEXP (x, 0),
5681 XEXP (XEXP (x, 0), 0), &XEXP (XEXP (x, 0), 0),
5682 opnum, type, ind_levels, insn);
5684 reloadnum = push_reload (x, NULL_RTX, loc, (rtx*) 0,
5685 context_reg_class,
5686 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5687 rld[reloadnum].inc
5688 = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
5690 link = FIND_REG_INC_NOTE (this_insn, tem);
5691 if (link != 0)
5692 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5694 return 1;
5696 return 0;
5698 case MEM:
5699 /* This is probably the result of a substitution, by eliminate_regs, of
5700 an equivalent address for a pseudo that was not allocated to a hard
5701 register. Verify that the specified address is valid and reload it
5702 into a register.
5704 Since we know we are going to reload this item, don't decrement for
5705 the indirection level.
5707 Note that this is actually conservative: it would be slightly more
5708 efficient to use the value of SPILL_INDIRECT_LEVELS from
5709 reload1.c here. */
5711 find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5712 opnum, ADDR_TYPE (type), ind_levels, insn);
5713 push_reload (*loc, NULL_RTX, loc, (rtx*) 0,
5714 context_reg_class,
5715 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5716 return 1;
5718 case REG:
5720 int regno = REGNO (x);
5722 if (reg_equiv_constant[regno] != 0)
5724 find_reloads_address_part (reg_equiv_constant[regno], loc,
5725 context_reg_class,
5726 GET_MODE (x), opnum, type, ind_levels);
5727 return 1;
5730 #if 0 /* This might screw code in reload1.c to delete prior output-reload
5731 that feeds this insn. */
5732 if (reg_equiv_mem[regno] != 0)
5734 push_reload (reg_equiv_mem[regno], NULL_RTX, loc, (rtx*) 0,
5735 context_reg_class,
5736 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5737 return 1;
5739 #endif
5741 if (reg_equiv_memory_loc[regno]
5742 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
5744 rtx tem = make_memloc (x, regno);
5745 if (reg_equiv_address[regno] != 0
5746 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5748 x = tem;
5749 find_reloads_address (GET_MODE (x), &x, XEXP (x, 0),
5750 &XEXP (x, 0), opnum, ADDR_TYPE (type),
5751 ind_levels, insn);
5755 if (reg_renumber[regno] >= 0)
5756 regno = reg_renumber[regno];
5758 if (regno >= FIRST_PSEUDO_REGISTER
5759 || !REG_OK_FOR_CONTEXT (context, regno, mode))
5761 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5762 context_reg_class,
5763 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5764 return 1;
5767 /* If a register appearing in an address is the subject of a CLOBBER
5768 in this insn, reload it into some other register to be safe.
5769 The CLOBBER is supposed to make the register unavailable
5770 from before this insn to after it. */
5771 if (regno_clobbered_p (regno, this_insn, GET_MODE (x), 0))
5773 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5774 context_reg_class,
5775 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5776 return 1;
5779 return 0;
5781 case SUBREG:
5782 if (REG_P (SUBREG_REG (x)))
5784 /* If this is a SUBREG of a hard register and the resulting register
5785 is of the wrong class, reload the whole SUBREG. This avoids
5786 needless copies if SUBREG_REG is multi-word. */
5787 if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5789 int regno ATTRIBUTE_UNUSED = subreg_regno (x);
5791 if (! REG_OK_FOR_CONTEXT (context, regno, mode))
5793 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5794 context_reg_class,
5795 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5796 return 1;
5799 /* If this is a SUBREG of a pseudo-register, and the pseudo-register
5800 is larger than the class size, then reload the whole SUBREG. */
5801 else
5803 enum reg_class class = context_reg_class;
5804 if ((unsigned) CLASS_MAX_NREGS (class, GET_MODE (SUBREG_REG (x)))
5805 > reg_class_size[class])
5807 x = find_reloads_subreg_address (x, 0, opnum,
5808 ADDR_TYPE (type),
5809 ind_levels, insn);
5810 push_reload (x, NULL_RTX, loc, (rtx*) 0, class,
5811 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5812 return 1;
5816 break;
5818 default:
5819 break;
5823 const char *fmt = GET_RTX_FORMAT (code);
5824 int i;
5826 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5828 if (fmt[i] == 'e')
5829 find_reloads_address_1 (mode, XEXP (x, i), context, &XEXP (x, i),
5830 opnum, type, ind_levels, insn);
5834 #undef REG_OK_FOR_CONTEXT
5835 return 0;
5838 /* X, which is found at *LOC, is a part of an address that needs to be
5839 reloaded into a register of class CLASS. If X is a constant, or if
5840 X is a PLUS that contains a constant, check that the constant is a
5841 legitimate operand and that we are supposed to be able to load
5842 it into the register.
5844 If not, force the constant into memory and reload the MEM instead.
5846 MODE is the mode to use, in case X is an integer constant.
5848 OPNUM and TYPE describe the purpose of any reloads made.
5850 IND_LEVELS says how many levels of indirect addressing this machine
5851 supports. */
5853 static void
5854 find_reloads_address_part (rtx x, rtx *loc, enum reg_class class,
5855 enum machine_mode mode, int opnum,
5856 enum reload_type type, int ind_levels)
5858 if (CONSTANT_P (x)
5859 && (! LEGITIMATE_CONSTANT_P (x)
5860 || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
5862 rtx tem;
5864 tem = x = force_const_mem (mode, x);
5865 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5866 opnum, type, ind_levels, 0);
5869 else if (GET_CODE (x) == PLUS
5870 && CONSTANT_P (XEXP (x, 1))
5871 && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
5872 || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
5874 rtx tem;
5876 tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
5877 x = gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), tem);
5878 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5879 opnum, type, ind_levels, 0);
5882 push_reload (x, NULL_RTX, loc, (rtx*) 0, class,
5883 mode, VOIDmode, 0, 0, opnum, type);
5886 /* X, a subreg of a pseudo, is a part of an address that needs to be
5887 reloaded.
5889 If the pseudo is equivalent to a memory location that cannot be directly
5890 addressed, make the necessary address reloads.
5892 If address reloads have been necessary, or if the address is changed
5893 by register elimination, return the rtx of the memory location;
5894 otherwise, return X.
5896 If FORCE_REPLACE is nonzero, unconditionally replace the subreg with the
5897 memory location.
5899 OPNUM and TYPE identify the purpose of the reload.
5901 IND_LEVELS says how many levels of indirect addressing are
5902 supported at this point in the address.
5904 INSN, if nonzero, is the insn in which we do the reload. It is used
5905 to determine where to put USEs for pseudos that we have to replace with
5906 stack slots. */
5908 static rtx
5909 find_reloads_subreg_address (rtx x, int force_replace, int opnum,
5910 enum reload_type type, int ind_levels, rtx insn)
5912 int regno = REGNO (SUBREG_REG (x));
5914 if (reg_equiv_memory_loc[regno])
5916 /* If the address is not directly addressable, or if the address is not
5917 offsettable, then it must be replaced. */
5918 if (! force_replace
5919 && (reg_equiv_address[regno]
5920 || ! offsettable_memref_p (reg_equiv_mem[regno])))
5921 force_replace = 1;
5923 if (force_replace || num_not_at_initial_offset)
5925 rtx tem = make_memloc (SUBREG_REG (x), regno);
5927 /* If the address changes because of register elimination, then
5928 it must be replaced. */
5929 if (force_replace
5930 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5932 unsigned outer_size = GET_MODE_SIZE (GET_MODE (x));
5933 unsigned inner_size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
5934 int offset;
5936 /* For big-endian paradoxical subregs, SUBREG_BYTE does not
5937 hold the correct (negative) byte offset. */
5938 if (BYTES_BIG_ENDIAN && outer_size > inner_size)
5939 offset = inner_size - outer_size;
5940 else
5941 offset = SUBREG_BYTE (x);
5943 XEXP (tem, 0) = plus_constant (XEXP (tem, 0), offset);
5944 PUT_MODE (tem, GET_MODE (x));
5946 /* If this was a paradoxical subreg that we replaced, the
5947 resulting memory must be sufficiently aligned to allow
5948 us to widen the mode of the memory. */
5949 if (outer_size > inner_size && STRICT_ALIGNMENT)
5951 rtx base;
5953 base = XEXP (tem, 0);
5954 if (GET_CODE (base) == PLUS)
5956 if (GET_CODE (XEXP (base, 1)) == CONST_INT
5957 && INTVAL (XEXP (base, 1)) % outer_size != 0)
5958 return x;
5959 base = XEXP (base, 0);
5961 if (!REG_P (base)
5962 || (REGNO_POINTER_ALIGN (REGNO (base))
5963 < outer_size * BITS_PER_UNIT))
5964 return x;
5967 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5968 &XEXP (tem, 0), opnum, type,
5969 ind_levels, insn);
5971 /* If this is not a toplevel operand, find_reloads doesn't see
5972 this substitution. We have to emit a USE of the pseudo so
5973 that delete_output_reload can see it. */
5974 if (replace_reloads && recog_data.operand[opnum] != x)
5975 /* We mark the USE with QImode so that we recognize it
5976 as one that can be safely deleted at the end of
5977 reload. */
5978 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode,
5979 SUBREG_REG (x)),
5980 insn), QImode);
5981 x = tem;
5985 return x;
5988 /* Substitute into the current INSN the registers into which we have reloaded
5989 the things that need reloading. The array `replacements'
5990 contains the locations of all pointers that must be changed
5991 and says what to replace them with.
5993 Return the rtx that X translates into; usually X, but modified. */
5995 void
5996 subst_reloads (rtx insn)
5998 int i;
6000 for (i = 0; i < n_replacements; i++)
6002 struct replacement *r = &replacements[i];
6003 rtx reloadreg = rld[r->what].reg_rtx;
6004 if (reloadreg)
6006 #ifdef ENABLE_CHECKING
6007 /* Internal consistency test. Check that we don't modify
6008 anything in the equivalence arrays. Whenever something from
6009 those arrays needs to be reloaded, it must be unshared before
6010 being substituted into; the equivalence must not be modified.
6011 Otherwise, if the equivalence is used after that, it will
6012 have been modified, and the thing substituted (probably a
6013 register) is likely overwritten and not a usable equivalence. */
6014 int check_regno;
6016 for (check_regno = 0; check_regno < max_regno; check_regno++)
6018 #define CHECK_MODF(ARRAY) \
6019 gcc_assert (!ARRAY[check_regno] \
6020 || !loc_mentioned_in_p (r->where, \
6021 ARRAY[check_regno]))
6023 CHECK_MODF (reg_equiv_constant);
6024 CHECK_MODF (reg_equiv_memory_loc);
6025 CHECK_MODF (reg_equiv_address);
6026 CHECK_MODF (reg_equiv_mem);
6027 #undef CHECK_MODF
6029 #endif /* ENABLE_CHECKING */
6031 /* If we're replacing a LABEL_REF with a register, add a
6032 REG_LABEL note to indicate to flow which label this
6033 register refers to. */
6034 if (GET_CODE (*r->where) == LABEL_REF
6035 && JUMP_P (insn))
6036 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL,
6037 XEXP (*r->where, 0),
6038 REG_NOTES (insn));
6040 /* Encapsulate RELOADREG so its machine mode matches what
6041 used to be there. Note that gen_lowpart_common will
6042 do the wrong thing if RELOADREG is multi-word. RELOADREG
6043 will always be a REG here. */
6044 if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
6045 reloadreg = reload_adjust_reg_for_mode (reloadreg, r->mode);
6047 /* If we are putting this into a SUBREG and RELOADREG is a
6048 SUBREG, we would be making nested SUBREGs, so we have to fix
6049 this up. Note that r->where == &SUBREG_REG (*r->subreg_loc). */
6051 if (r->subreg_loc != 0 && GET_CODE (reloadreg) == SUBREG)
6053 if (GET_MODE (*r->subreg_loc)
6054 == GET_MODE (SUBREG_REG (reloadreg)))
6055 *r->subreg_loc = SUBREG_REG (reloadreg);
6056 else
6058 int final_offset =
6059 SUBREG_BYTE (*r->subreg_loc) + SUBREG_BYTE (reloadreg);
6061 /* When working with SUBREGs the rule is that the byte
6062 offset must be a multiple of the SUBREG's mode. */
6063 final_offset = (final_offset /
6064 GET_MODE_SIZE (GET_MODE (*r->subreg_loc)));
6065 final_offset = (final_offset *
6066 GET_MODE_SIZE (GET_MODE (*r->subreg_loc)));
6068 *r->where = SUBREG_REG (reloadreg);
6069 SUBREG_BYTE (*r->subreg_loc) = final_offset;
6072 else
6073 *r->where = reloadreg;
6075 /* If reload got no reg and isn't optional, something's wrong. */
6076 else
6077 gcc_assert (rld[r->what].optional);
6081 /* Make a copy of any replacements being done into X and move those
6082 copies to locations in Y, a copy of X. */
6084 void
6085 copy_replacements (rtx x, rtx y)
6087 /* We can't support X being a SUBREG because we might then need to know its
6088 location if something inside it was replaced. */
6089 gcc_assert (GET_CODE (x) != SUBREG);
6091 copy_replacements_1 (&x, &y, n_replacements);
6094 static void
6095 copy_replacements_1 (rtx *px, rtx *py, int orig_replacements)
6097 int i, j;
6098 rtx x, y;
6099 struct replacement *r;
6100 enum rtx_code code;
6101 const char *fmt;
6103 for (j = 0; j < orig_replacements; j++)
6105 if (replacements[j].subreg_loc == px)
6107 r = &replacements[n_replacements++];
6108 r->where = replacements[j].where;
6109 r->subreg_loc = py;
6110 r->what = replacements[j].what;
6111 r->mode = replacements[j].mode;
6113 else if (replacements[j].where == px)
6115 r = &replacements[n_replacements++];
6116 r->where = py;
6117 r->subreg_loc = 0;
6118 r->what = replacements[j].what;
6119 r->mode = replacements[j].mode;
6123 x = *px;
6124 y = *py;
6125 code = GET_CODE (x);
6126 fmt = GET_RTX_FORMAT (code);
6128 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6130 if (fmt[i] == 'e')
6131 copy_replacements_1 (&XEXP (x, i), &XEXP (y, i), orig_replacements);
6132 else if (fmt[i] == 'E')
6133 for (j = XVECLEN (x, i); --j >= 0; )
6134 copy_replacements_1 (&XVECEXP (x, i, j), &XVECEXP (y, i, j),
6135 orig_replacements);
6139 /* Change any replacements being done to *X to be done to *Y. */
6141 void
6142 move_replacements (rtx *x, rtx *y)
6144 int i;
6146 for (i = 0; i < n_replacements; i++)
6147 if (replacements[i].subreg_loc == x)
6148 replacements[i].subreg_loc = y;
6149 else if (replacements[i].where == x)
6151 replacements[i].where = y;
6152 replacements[i].subreg_loc = 0;
6156 /* If LOC was scheduled to be replaced by something, return the replacement.
6157 Otherwise, return *LOC. */
6160 find_replacement (rtx *loc)
6162 struct replacement *r;
6164 for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
6166 rtx reloadreg = rld[r->what].reg_rtx;
6168 if (reloadreg && r->where == loc)
6170 if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
6171 reloadreg = gen_rtx_REG (r->mode, REGNO (reloadreg));
6173 return reloadreg;
6175 else if (reloadreg && r->subreg_loc == loc)
6177 /* RELOADREG must be either a REG or a SUBREG.
6179 ??? Is it actually still ever a SUBREG? If so, why? */
6181 if (REG_P (reloadreg))
6182 return gen_rtx_REG (GET_MODE (*loc),
6183 (REGNO (reloadreg) +
6184 subreg_regno_offset (REGNO (SUBREG_REG (*loc)),
6185 GET_MODE (SUBREG_REG (*loc)),
6186 SUBREG_BYTE (*loc),
6187 GET_MODE (*loc))));
6188 else if (GET_MODE (reloadreg) == GET_MODE (*loc))
6189 return reloadreg;
6190 else
6192 int final_offset = SUBREG_BYTE (reloadreg) + SUBREG_BYTE (*loc);
6194 /* When working with SUBREGs the rule is that the byte
6195 offset must be a multiple of the SUBREG's mode. */
6196 final_offset = (final_offset / GET_MODE_SIZE (GET_MODE (*loc)));
6197 final_offset = (final_offset * GET_MODE_SIZE (GET_MODE (*loc)));
6198 return gen_rtx_SUBREG (GET_MODE (*loc), SUBREG_REG (reloadreg),
6199 final_offset);
6204 /* If *LOC is a PLUS, MINUS, or MULT, see if a replacement is scheduled for
6205 what's inside and make a new rtl if so. */
6206 if (GET_CODE (*loc) == PLUS || GET_CODE (*loc) == MINUS
6207 || GET_CODE (*loc) == MULT)
6209 rtx x = find_replacement (&XEXP (*loc, 0));
6210 rtx y = find_replacement (&XEXP (*loc, 1));
6212 if (x != XEXP (*loc, 0) || y != XEXP (*loc, 1))
6213 return gen_rtx_fmt_ee (GET_CODE (*loc), GET_MODE (*loc), x, y);
6216 return *loc;
6219 /* Return nonzero if register in range [REGNO, ENDREGNO)
6220 appears either explicitly or implicitly in X
6221 other than being stored into (except for earlyclobber operands).
6223 References contained within the substructure at LOC do not count.
6224 LOC may be zero, meaning don't ignore anything.
6226 This is similar to refers_to_regno_p in rtlanal.c except that we
6227 look at equivalences for pseudos that didn't get hard registers. */
6229 static int
6230 refers_to_regno_for_reload_p (unsigned int regno, unsigned int endregno,
6231 rtx x, rtx *loc)
6233 int i;
6234 unsigned int r;
6235 RTX_CODE code;
6236 const char *fmt;
6238 if (x == 0)
6239 return 0;
6241 repeat:
6242 code = GET_CODE (x);
6244 switch (code)
6246 case REG:
6247 r = REGNO (x);
6249 /* If this is a pseudo, a hard register must not have been allocated.
6250 X must therefore either be a constant or be in memory. */
6251 if (r >= FIRST_PSEUDO_REGISTER)
6253 if (reg_equiv_memory_loc[r])
6254 return refers_to_regno_for_reload_p (regno, endregno,
6255 reg_equiv_memory_loc[r],
6256 (rtx*) 0);
6258 gcc_assert (reg_equiv_constant[r]);
6259 return 0;
6262 return (endregno > r
6263 && regno < r + (r < FIRST_PSEUDO_REGISTER
6264 ? hard_regno_nregs[r][GET_MODE (x)]
6265 : 1));
6267 case SUBREG:
6268 /* If this is a SUBREG of a hard reg, we can see exactly which
6269 registers are being modified. Otherwise, handle normally. */
6270 if (REG_P (SUBREG_REG (x))
6271 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
6273 unsigned int inner_regno = subreg_regno (x);
6274 unsigned int inner_endregno
6275 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
6276 ? hard_regno_nregs[inner_regno][GET_MODE (x)] : 1);
6278 return endregno > inner_regno && regno < inner_endregno;
6280 break;
6282 case CLOBBER:
6283 case SET:
6284 if (&SET_DEST (x) != loc
6285 /* Note setting a SUBREG counts as referring to the REG it is in for
6286 a pseudo but not for hard registers since we can
6287 treat each word individually. */
6288 && ((GET_CODE (SET_DEST (x)) == SUBREG
6289 && loc != &SUBREG_REG (SET_DEST (x))
6290 && REG_P (SUBREG_REG (SET_DEST (x)))
6291 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
6292 && refers_to_regno_for_reload_p (regno, endregno,
6293 SUBREG_REG (SET_DEST (x)),
6294 loc))
6295 /* If the output is an earlyclobber operand, this is
6296 a conflict. */
6297 || ((!REG_P (SET_DEST (x))
6298 || earlyclobber_operand_p (SET_DEST (x)))
6299 && refers_to_regno_for_reload_p (regno, endregno,
6300 SET_DEST (x), loc))))
6301 return 1;
6303 if (code == CLOBBER || loc == &SET_SRC (x))
6304 return 0;
6305 x = SET_SRC (x);
6306 goto repeat;
6308 default:
6309 break;
6312 /* X does not match, so try its subexpressions. */
6314 fmt = GET_RTX_FORMAT (code);
6315 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6317 if (fmt[i] == 'e' && loc != &XEXP (x, i))
6319 if (i == 0)
6321 x = XEXP (x, 0);
6322 goto repeat;
6324 else
6325 if (refers_to_regno_for_reload_p (regno, endregno,
6326 XEXP (x, i), loc))
6327 return 1;
6329 else if (fmt[i] == 'E')
6331 int j;
6332 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6333 if (loc != &XVECEXP (x, i, j)
6334 && refers_to_regno_for_reload_p (regno, endregno,
6335 XVECEXP (x, i, j), loc))
6336 return 1;
6339 return 0;
6342 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
6343 we check if any register number in X conflicts with the relevant register
6344 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
6345 contains a MEM (we don't bother checking for memory addresses that can't
6346 conflict because we expect this to be a rare case.
6348 This function is similar to reg_overlap_mentioned_p in rtlanal.c except
6349 that we look at equivalences for pseudos that didn't get hard registers. */
6352 reg_overlap_mentioned_for_reload_p (rtx x, rtx in)
6354 int regno, endregno;
6356 /* Overly conservative. */
6357 if (GET_CODE (x) == STRICT_LOW_PART
6358 || GET_RTX_CLASS (GET_CODE (x)) == RTX_AUTOINC)
6359 x = XEXP (x, 0);
6361 /* If either argument is a constant, then modifying X can not affect IN. */
6362 if (CONSTANT_P (x) || CONSTANT_P (in))
6363 return 0;
6364 else if (GET_CODE (x) == SUBREG)
6366 regno = REGNO (SUBREG_REG (x));
6367 if (regno < FIRST_PSEUDO_REGISTER)
6368 regno += subreg_regno_offset (REGNO (SUBREG_REG (x)),
6369 GET_MODE (SUBREG_REG (x)),
6370 SUBREG_BYTE (x),
6371 GET_MODE (x));
6373 else if (REG_P (x))
6375 regno = REGNO (x);
6377 /* If this is a pseudo, it must not have been assigned a hard register.
6378 Therefore, it must either be in memory or be a constant. */
6380 if (regno >= FIRST_PSEUDO_REGISTER)
6382 if (reg_equiv_memory_loc[regno])
6383 return refers_to_mem_for_reload_p (in);
6384 gcc_assert (reg_equiv_constant[regno]);
6385 return 0;
6388 else if (MEM_P (x))
6389 return refers_to_mem_for_reload_p (in);
6390 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
6391 || GET_CODE (x) == CC0)
6392 return reg_mentioned_p (x, in);
6393 else
6395 gcc_assert (GET_CODE (x) == PLUS);
6397 /* We actually want to know if X is mentioned somewhere inside IN.
6398 We must not say that (plus (sp) (const_int 124)) is in
6399 (plus (sp) (const_int 64)), since that can lead to incorrect reload
6400 allocation when spuriously changing a RELOAD_FOR_OUTPUT_ADDRESS
6401 into a RELOAD_OTHER on behalf of another RELOAD_OTHER. */
6402 while (MEM_P (in))
6403 in = XEXP (in, 0);
6404 if (REG_P (in))
6405 return 0;
6406 else if (GET_CODE (in) == PLUS)
6407 return (reg_overlap_mentioned_for_reload_p (x, XEXP (in, 0))
6408 || reg_overlap_mentioned_for_reload_p (x, XEXP (in, 1)));
6409 else return (reg_overlap_mentioned_for_reload_p (XEXP (x, 0), in)
6410 || reg_overlap_mentioned_for_reload_p (XEXP (x, 1), in));
6413 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
6414 ? hard_regno_nregs[regno][GET_MODE (x)] : 1);
6416 return refers_to_regno_for_reload_p (regno, endregno, in, (rtx*) 0);
6419 /* Return nonzero if anything in X contains a MEM. Look also for pseudo
6420 registers. */
6422 static int
6423 refers_to_mem_for_reload_p (rtx x)
6425 const char *fmt;
6426 int i;
6428 if (MEM_P (x))
6429 return 1;
6431 if (REG_P (x))
6432 return (REGNO (x) >= FIRST_PSEUDO_REGISTER
6433 && reg_equiv_memory_loc[REGNO (x)]);
6435 fmt = GET_RTX_FORMAT (GET_CODE (x));
6436 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
6437 if (fmt[i] == 'e'
6438 && (MEM_P (XEXP (x, i))
6439 || refers_to_mem_for_reload_p (XEXP (x, i))))
6440 return 1;
6442 return 0;
6445 /* Check the insns before INSN to see if there is a suitable register
6446 containing the same value as GOAL.
6447 If OTHER is -1, look for a register in class CLASS.
6448 Otherwise, just see if register number OTHER shares GOAL's value.
6450 Return an rtx for the register found, or zero if none is found.
6452 If RELOAD_REG_P is (short *)1,
6453 we reject any hard reg that appears in reload_reg_rtx
6454 because such a hard reg is also needed coming into this insn.
6456 If RELOAD_REG_P is any other nonzero value,
6457 it is a vector indexed by hard reg number
6458 and we reject any hard reg whose element in the vector is nonnegative
6459 as well as any that appears in reload_reg_rtx.
6461 If GOAL is zero, then GOALREG is a register number; we look
6462 for an equivalent for that register.
6464 MODE is the machine mode of the value we want an equivalence for.
6465 If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
6467 This function is used by jump.c as well as in the reload pass.
6469 If GOAL is the sum of the stack pointer and a constant, we treat it
6470 as if it were a constant except that sp is required to be unchanging. */
6473 find_equiv_reg (rtx goal, rtx insn, enum reg_class class, int other,
6474 short *reload_reg_p, int goalreg, enum machine_mode mode)
6476 rtx p = insn;
6477 rtx goaltry, valtry, value, where;
6478 rtx pat;
6479 int regno = -1;
6480 int valueno;
6481 int goal_mem = 0;
6482 int goal_const = 0;
6483 int goal_mem_addr_varies = 0;
6484 int need_stable_sp = 0;
6485 int nregs;
6486 int valuenregs;
6487 int num = 0;
6489 if (goal == 0)
6490 regno = goalreg;
6491 else if (REG_P (goal))
6492 regno = REGNO (goal);
6493 else if (MEM_P (goal))
6495 enum rtx_code code = GET_CODE (XEXP (goal, 0));
6496 if (MEM_VOLATILE_P (goal))
6497 return 0;
6498 if (flag_float_store && GET_MODE_CLASS (GET_MODE (goal)) == MODE_FLOAT)
6499 return 0;
6500 /* An address with side effects must be reexecuted. */
6501 switch (code)
6503 case POST_INC:
6504 case PRE_INC:
6505 case POST_DEC:
6506 case PRE_DEC:
6507 case POST_MODIFY:
6508 case PRE_MODIFY:
6509 return 0;
6510 default:
6511 break;
6513 goal_mem = 1;
6515 else if (CONSTANT_P (goal))
6516 goal_const = 1;
6517 else if (GET_CODE (goal) == PLUS
6518 && XEXP (goal, 0) == stack_pointer_rtx
6519 && CONSTANT_P (XEXP (goal, 1)))
6520 goal_const = need_stable_sp = 1;
6521 else if (GET_CODE (goal) == PLUS
6522 && XEXP (goal, 0) == frame_pointer_rtx
6523 && CONSTANT_P (XEXP (goal, 1)))
6524 goal_const = 1;
6525 else
6526 return 0;
6528 num = 0;
6529 /* Scan insns back from INSN, looking for one that copies
6530 a value into or out of GOAL.
6531 Stop and give up if we reach a label. */
6533 while (1)
6535 p = PREV_INSN (p);
6536 num++;
6537 if (p == 0 || LABEL_P (p)
6538 || num > PARAM_VALUE (PARAM_MAX_RELOAD_SEARCH_INSNS))
6539 return 0;
6541 if (NONJUMP_INSN_P (p)
6542 /* If we don't want spill regs ... */
6543 && (! (reload_reg_p != 0
6544 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6545 /* ... then ignore insns introduced by reload; they aren't
6546 useful and can cause results in reload_as_needed to be
6547 different from what they were when calculating the need for
6548 spills. If we notice an input-reload insn here, we will
6549 reject it below, but it might hide a usable equivalent.
6550 That makes bad code. It may even fail: perhaps no reg was
6551 spilled for this insn because it was assumed we would find
6552 that equivalent. */
6553 || INSN_UID (p) < reload_first_uid))
6555 rtx tem;
6556 pat = single_set (p);
6558 /* First check for something that sets some reg equal to GOAL. */
6559 if (pat != 0
6560 && ((regno >= 0
6561 && true_regnum (SET_SRC (pat)) == regno
6562 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6564 (regno >= 0
6565 && true_regnum (SET_DEST (pat)) == regno
6566 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0)
6568 (goal_const && rtx_equal_p (SET_SRC (pat), goal)
6569 /* When looking for stack pointer + const,
6570 make sure we don't use a stack adjust. */
6571 && !reg_overlap_mentioned_for_reload_p (SET_DEST (pat), goal)
6572 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6573 || (goal_mem
6574 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0
6575 && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
6576 || (goal_mem
6577 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0
6578 && rtx_renumbered_equal_p (goal, SET_DEST (pat)))
6579 /* If we are looking for a constant,
6580 and something equivalent to that constant was copied
6581 into a reg, we can use that reg. */
6582 || (goal_const && REG_NOTES (p) != 0
6583 && (tem = find_reg_note (p, REG_EQUIV, NULL_RTX))
6584 && ((rtx_equal_p (XEXP (tem, 0), goal)
6585 && (valueno
6586 = true_regnum (valtry = SET_DEST (pat))) >= 0)
6587 || (REG_P (SET_DEST (pat))
6588 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6589 && (GET_MODE_CLASS (GET_MODE (XEXP (tem, 0)))
6590 == MODE_FLOAT)
6591 && GET_CODE (goal) == CONST_INT
6592 && 0 != (goaltry
6593 = operand_subword (XEXP (tem, 0), 0, 0,
6594 VOIDmode))
6595 && rtx_equal_p (goal, goaltry)
6596 && (valtry
6597 = operand_subword (SET_DEST (pat), 0, 0,
6598 VOIDmode))
6599 && (valueno = true_regnum (valtry)) >= 0)))
6600 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
6601 NULL_RTX))
6602 && REG_P (SET_DEST (pat))
6603 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6604 && (GET_MODE_CLASS (GET_MODE (XEXP (tem, 0)))
6605 == MODE_FLOAT)
6606 && GET_CODE (goal) == CONST_INT
6607 && 0 != (goaltry = operand_subword (XEXP (tem, 0), 1, 0,
6608 VOIDmode))
6609 && rtx_equal_p (goal, goaltry)
6610 && (valtry
6611 = operand_subword (SET_DEST (pat), 1, 0, VOIDmode))
6612 && (valueno = true_regnum (valtry)) >= 0)))
6614 if (other >= 0)
6616 if (valueno != other)
6617 continue;
6619 else if ((unsigned) valueno >= FIRST_PSEUDO_REGISTER)
6620 continue;
6621 else
6623 int i;
6625 for (i = hard_regno_nregs[valueno][mode] - 1; i >= 0; i--)
6626 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
6627 valueno + i))
6628 break;
6629 if (i >= 0)
6630 continue;
6632 value = valtry;
6633 where = p;
6634 break;
6639 /* We found a previous insn copying GOAL into a suitable other reg VALUE
6640 (or copying VALUE into GOAL, if GOAL is also a register).
6641 Now verify that VALUE is really valid. */
6643 /* VALUENO is the register number of VALUE; a hard register. */
6645 /* Don't try to re-use something that is killed in this insn. We want
6646 to be able to trust REG_UNUSED notes. */
6647 if (REG_NOTES (where) != 0 && find_reg_note (where, REG_UNUSED, value))
6648 return 0;
6650 /* If we propose to get the value from the stack pointer or if GOAL is
6651 a MEM based on the stack pointer, we need a stable SP. */
6652 if (valueno == STACK_POINTER_REGNUM || regno == STACK_POINTER_REGNUM
6653 || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx,
6654 goal)))
6655 need_stable_sp = 1;
6657 /* Reject VALUE if the copy-insn moved the wrong sort of datum. */
6658 if (GET_MODE (value) != mode)
6659 return 0;
6661 /* Reject VALUE if it was loaded from GOAL
6662 and is also a register that appears in the address of GOAL. */
6664 if (goal_mem && value == SET_DEST (single_set (where))
6665 && refers_to_regno_for_reload_p (valueno,
6666 (valueno
6667 + hard_regno_nregs[valueno][mode]),
6668 goal, (rtx*) 0))
6669 return 0;
6671 /* Reject registers that overlap GOAL. */
6673 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
6674 nregs = hard_regno_nregs[regno][mode];
6675 else
6676 nregs = 1;
6677 valuenregs = hard_regno_nregs[valueno][mode];
6679 if (!goal_mem && !goal_const
6680 && regno + nregs > valueno && regno < valueno + valuenregs)
6681 return 0;
6683 /* Reject VALUE if it is one of the regs reserved for reloads.
6684 Reload1 knows how to reuse them anyway, and it would get
6685 confused if we allocated one without its knowledge.
6686 (Now that insns introduced by reload are ignored above,
6687 this case shouldn't happen, but I'm not positive.) */
6689 if (reload_reg_p != 0 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6691 int i;
6692 for (i = 0; i < valuenregs; ++i)
6693 if (reload_reg_p[valueno + i] >= 0)
6694 return 0;
6697 /* Reject VALUE if it is a register being used for an input reload
6698 even if it is not one of those reserved. */
6700 if (reload_reg_p != 0)
6702 int i;
6703 for (i = 0; i < n_reloads; i++)
6704 if (rld[i].reg_rtx != 0 && rld[i].in)
6706 int regno1 = REGNO (rld[i].reg_rtx);
6707 int nregs1 = hard_regno_nregs[regno1]
6708 [GET_MODE (rld[i].reg_rtx)];
6709 if (regno1 < valueno + valuenregs
6710 && regno1 + nregs1 > valueno)
6711 return 0;
6715 if (goal_mem)
6716 /* We must treat frame pointer as varying here,
6717 since it can vary--in a nonlocal goto as generated by expand_goto. */
6718 goal_mem_addr_varies = !CONSTANT_ADDRESS_P (XEXP (goal, 0));
6720 /* Now verify that the values of GOAL and VALUE remain unaltered
6721 until INSN is reached. */
6723 p = insn;
6724 while (1)
6726 p = PREV_INSN (p);
6727 if (p == where)
6728 return value;
6730 /* Don't trust the conversion past a function call
6731 if either of the two is in a call-clobbered register, or memory. */
6732 if (CALL_P (p))
6734 int i;
6736 if (goal_mem || need_stable_sp)
6737 return 0;
6739 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
6740 for (i = 0; i < nregs; ++i)
6741 if (call_used_regs[regno + i]
6742 || HARD_REGNO_CALL_PART_CLOBBERED (regno + i, mode))
6743 return 0;
6745 if (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER)
6746 for (i = 0; i < valuenregs; ++i)
6747 if (call_used_regs[valueno + i]
6748 || HARD_REGNO_CALL_PART_CLOBBERED (valueno + i, mode))
6749 return 0;
6752 if (INSN_P (p))
6754 pat = PATTERN (p);
6756 /* Watch out for unspec_volatile, and volatile asms. */
6757 if (volatile_insn_p (pat))
6758 return 0;
6760 /* If this insn P stores in either GOAL or VALUE, return 0.
6761 If GOAL is a memory ref and this insn writes memory, return 0.
6762 If GOAL is a memory ref and its address is not constant,
6763 and this insn P changes a register used in GOAL, return 0. */
6765 if (GET_CODE (pat) == COND_EXEC)
6766 pat = COND_EXEC_CODE (pat);
6767 if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
6769 rtx dest = SET_DEST (pat);
6770 while (GET_CODE (dest) == SUBREG
6771 || GET_CODE (dest) == ZERO_EXTRACT
6772 || GET_CODE (dest) == STRICT_LOW_PART)
6773 dest = XEXP (dest, 0);
6774 if (REG_P (dest))
6776 int xregno = REGNO (dest);
6777 int xnregs;
6778 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6779 xnregs = hard_regno_nregs[xregno][GET_MODE (dest)];
6780 else
6781 xnregs = 1;
6782 if (xregno < regno + nregs && xregno + xnregs > regno)
6783 return 0;
6784 if (xregno < valueno + valuenregs
6785 && xregno + xnregs > valueno)
6786 return 0;
6787 if (goal_mem_addr_varies
6788 && reg_overlap_mentioned_for_reload_p (dest, goal))
6789 return 0;
6790 if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6791 return 0;
6793 else if (goal_mem && MEM_P (dest)
6794 && ! push_operand (dest, GET_MODE (dest)))
6795 return 0;
6796 else if (MEM_P (dest) && regno >= FIRST_PSEUDO_REGISTER
6797 && reg_equiv_memory_loc[regno] != 0)
6798 return 0;
6799 else if (need_stable_sp && push_operand (dest, GET_MODE (dest)))
6800 return 0;
6802 else if (GET_CODE (pat) == PARALLEL)
6804 int i;
6805 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
6807 rtx v1 = XVECEXP (pat, 0, i);
6808 if (GET_CODE (v1) == COND_EXEC)
6809 v1 = COND_EXEC_CODE (v1);
6810 if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
6812 rtx dest = SET_DEST (v1);
6813 while (GET_CODE (dest) == SUBREG
6814 || GET_CODE (dest) == ZERO_EXTRACT
6815 || GET_CODE (dest) == STRICT_LOW_PART)
6816 dest = XEXP (dest, 0);
6817 if (REG_P (dest))
6819 int xregno = REGNO (dest);
6820 int xnregs;
6821 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6822 xnregs = hard_regno_nregs[xregno][GET_MODE (dest)];
6823 else
6824 xnregs = 1;
6825 if (xregno < regno + nregs
6826 && xregno + xnregs > regno)
6827 return 0;
6828 if (xregno < valueno + valuenregs
6829 && xregno + xnregs > valueno)
6830 return 0;
6831 if (goal_mem_addr_varies
6832 && reg_overlap_mentioned_for_reload_p (dest,
6833 goal))
6834 return 0;
6835 if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6836 return 0;
6838 else if (goal_mem && MEM_P (dest)
6839 && ! push_operand (dest, GET_MODE (dest)))
6840 return 0;
6841 else if (MEM_P (dest) && regno >= FIRST_PSEUDO_REGISTER
6842 && reg_equiv_memory_loc[regno] != 0)
6843 return 0;
6844 else if (need_stable_sp
6845 && push_operand (dest, GET_MODE (dest)))
6846 return 0;
6851 if (CALL_P (p) && CALL_INSN_FUNCTION_USAGE (p))
6853 rtx link;
6855 for (link = CALL_INSN_FUNCTION_USAGE (p); XEXP (link, 1) != 0;
6856 link = XEXP (link, 1))
6858 pat = XEXP (link, 0);
6859 if (GET_CODE (pat) == CLOBBER)
6861 rtx dest = SET_DEST (pat);
6863 if (REG_P (dest))
6865 int xregno = REGNO (dest);
6866 int xnregs
6867 = hard_regno_nregs[xregno][GET_MODE (dest)];
6869 if (xregno < regno + nregs
6870 && xregno + xnregs > regno)
6871 return 0;
6872 else if (xregno < valueno + valuenregs
6873 && xregno + xnregs > valueno)
6874 return 0;
6875 else if (goal_mem_addr_varies
6876 && reg_overlap_mentioned_for_reload_p (dest,
6877 goal))
6878 return 0;
6881 else if (goal_mem && MEM_P (dest)
6882 && ! push_operand (dest, GET_MODE (dest)))
6883 return 0;
6884 else if (need_stable_sp
6885 && push_operand (dest, GET_MODE (dest)))
6886 return 0;
6891 #ifdef AUTO_INC_DEC
6892 /* If this insn auto-increments or auto-decrements
6893 either regno or valueno, return 0 now.
6894 If GOAL is a memory ref and its address is not constant,
6895 and this insn P increments a register used in GOAL, return 0. */
6897 rtx link;
6899 for (link = REG_NOTES (p); link; link = XEXP (link, 1))
6900 if (REG_NOTE_KIND (link) == REG_INC
6901 && REG_P (XEXP (link, 0)))
6903 int incno = REGNO (XEXP (link, 0));
6904 if (incno < regno + nregs && incno >= regno)
6905 return 0;
6906 if (incno < valueno + valuenregs && incno >= valueno)
6907 return 0;
6908 if (goal_mem_addr_varies
6909 && reg_overlap_mentioned_for_reload_p (XEXP (link, 0),
6910 goal))
6911 return 0;
6914 #endif
6919 /* Find a place where INCED appears in an increment or decrement operator
6920 within X, and return the amount INCED is incremented or decremented by.
6921 The value is always positive. */
6923 static int
6924 find_inc_amount (rtx x, rtx inced)
6926 enum rtx_code code = GET_CODE (x);
6927 const char *fmt;
6928 int i;
6930 if (code == MEM)
6932 rtx addr = XEXP (x, 0);
6933 if ((GET_CODE (addr) == PRE_DEC
6934 || GET_CODE (addr) == POST_DEC
6935 || GET_CODE (addr) == PRE_INC
6936 || GET_CODE (addr) == POST_INC)
6937 && XEXP (addr, 0) == inced)
6938 return GET_MODE_SIZE (GET_MODE (x));
6939 else if ((GET_CODE (addr) == PRE_MODIFY
6940 || GET_CODE (addr) == POST_MODIFY)
6941 && GET_CODE (XEXP (addr, 1)) == PLUS
6942 && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0)
6943 && XEXP (addr, 0) == inced
6944 && GET_CODE (XEXP (XEXP (addr, 1), 1)) == CONST_INT)
6946 i = INTVAL (XEXP (XEXP (addr, 1), 1));
6947 return i < 0 ? -i : i;
6951 fmt = GET_RTX_FORMAT (code);
6952 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6954 if (fmt[i] == 'e')
6956 int tem = find_inc_amount (XEXP (x, i), inced);
6957 if (tem != 0)
6958 return tem;
6960 if (fmt[i] == 'E')
6962 int j;
6963 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6965 int tem = find_inc_amount (XVECEXP (x, i, j), inced);
6966 if (tem != 0)
6967 return tem;
6972 return 0;
6975 /* Return 1 if register REGNO is the subject of a clobber in insn INSN.
6976 If SETS is nonzero, also consider SETs. REGNO must refer to a hard
6977 register. */
6980 regno_clobbered_p (unsigned int regno, rtx insn, enum machine_mode mode,
6981 int sets)
6983 unsigned int nregs, endregno;
6985 /* regno must be a hard register. */
6986 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
6988 nregs = hard_regno_nregs[regno][mode];
6989 endregno = regno + nregs;
6991 if ((GET_CODE (PATTERN (insn)) == CLOBBER
6992 || (sets && GET_CODE (PATTERN (insn)) == SET))
6993 && REG_P (XEXP (PATTERN (insn), 0)))
6995 unsigned int test = REGNO (XEXP (PATTERN (insn), 0));
6997 return test >= regno && test < endregno;
7000 if (GET_CODE (PATTERN (insn)) == PARALLEL)
7002 int i = XVECLEN (PATTERN (insn), 0) - 1;
7004 for (; i >= 0; i--)
7006 rtx elt = XVECEXP (PATTERN (insn), 0, i);
7007 if ((GET_CODE (elt) == CLOBBER
7008 || (sets && GET_CODE (PATTERN (insn)) == SET))
7009 && REG_P (XEXP (elt, 0)))
7011 unsigned int test = REGNO (XEXP (elt, 0));
7013 if (test >= regno && test < endregno)
7014 return 1;
7019 return 0;
7022 /* Find the low part, with mode MODE, of a hard regno RELOADREG. */
7024 reload_adjust_reg_for_mode (rtx reloadreg, enum machine_mode mode)
7026 int regno;
7028 if (GET_MODE (reloadreg) == mode)
7029 return reloadreg;
7031 regno = REGNO (reloadreg);
7033 if (WORDS_BIG_ENDIAN)
7034 regno += (int) hard_regno_nregs[regno][GET_MODE (reloadreg)]
7035 - (int) hard_regno_nregs[regno][mode];
7037 return gen_rtx_REG (mode, regno);
7040 static const char *const reload_when_needed_name[] =
7042 "RELOAD_FOR_INPUT",
7043 "RELOAD_FOR_OUTPUT",
7044 "RELOAD_FOR_INSN",
7045 "RELOAD_FOR_INPUT_ADDRESS",
7046 "RELOAD_FOR_INPADDR_ADDRESS",
7047 "RELOAD_FOR_OUTPUT_ADDRESS",
7048 "RELOAD_FOR_OUTADDR_ADDRESS",
7049 "RELOAD_FOR_OPERAND_ADDRESS",
7050 "RELOAD_FOR_OPADDR_ADDR",
7051 "RELOAD_OTHER",
7052 "RELOAD_FOR_OTHER_ADDRESS"
7055 /* These functions are used to print the variables set by 'find_reloads' */
7057 void
7058 debug_reload_to_stream (FILE *f)
7060 int r;
7061 const char *prefix;
7063 if (! f)
7064 f = stderr;
7065 for (r = 0; r < n_reloads; r++)
7067 fprintf (f, "Reload %d: ", r);
7069 if (rld[r].in != 0)
7071 fprintf (f, "reload_in (%s) = ",
7072 GET_MODE_NAME (rld[r].inmode));
7073 print_inline_rtx (f, rld[r].in, 24);
7074 fprintf (f, "\n\t");
7077 if (rld[r].out != 0)
7079 fprintf (f, "reload_out (%s) = ",
7080 GET_MODE_NAME (rld[r].outmode));
7081 print_inline_rtx (f, rld[r].out, 24);
7082 fprintf (f, "\n\t");
7085 fprintf (f, "%s, ", reg_class_names[(int) rld[r].class]);
7087 fprintf (f, "%s (opnum = %d)",
7088 reload_when_needed_name[(int) rld[r].when_needed],
7089 rld[r].opnum);
7091 if (rld[r].optional)
7092 fprintf (f, ", optional");
7094 if (rld[r].nongroup)
7095 fprintf (f, ", nongroup");
7097 if (rld[r].inc != 0)
7098 fprintf (f, ", inc by %d", rld[r].inc);
7100 if (rld[r].nocombine)
7101 fprintf (f, ", can't combine");
7103 if (rld[r].secondary_p)
7104 fprintf (f, ", secondary_reload_p");
7106 if (rld[r].in_reg != 0)
7108 fprintf (f, "\n\treload_in_reg: ");
7109 print_inline_rtx (f, rld[r].in_reg, 24);
7112 if (rld[r].out_reg != 0)
7114 fprintf (f, "\n\treload_out_reg: ");
7115 print_inline_rtx (f, rld[r].out_reg, 24);
7118 if (rld[r].reg_rtx != 0)
7120 fprintf (f, "\n\treload_reg_rtx: ");
7121 print_inline_rtx (f, rld[r].reg_rtx, 24);
7124 prefix = "\n\t";
7125 if (rld[r].secondary_in_reload != -1)
7127 fprintf (f, "%ssecondary_in_reload = %d",
7128 prefix, rld[r].secondary_in_reload);
7129 prefix = ", ";
7132 if (rld[r].secondary_out_reload != -1)
7133 fprintf (f, "%ssecondary_out_reload = %d\n",
7134 prefix, rld[r].secondary_out_reload);
7136 prefix = "\n\t";
7137 if (rld[r].secondary_in_icode != CODE_FOR_nothing)
7139 fprintf (f, "%ssecondary_in_icode = %s", prefix,
7140 insn_data[rld[r].secondary_in_icode].name);
7141 prefix = ", ";
7144 if (rld[r].secondary_out_icode != CODE_FOR_nothing)
7145 fprintf (f, "%ssecondary_out_icode = %s", prefix,
7146 insn_data[rld[r].secondary_out_icode].name);
7148 fprintf (f, "\n");
7152 void
7153 debug_reload (void)
7155 debug_reload_to_stream (stderr);