Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gcc4 / gcc / reload.c
blobeea9cc738a183155e2507ea764016f80f3bc811f
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) || GET_CODE (in) == PLUS)
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
1333 && (REG_P (in)
1334 || (GET_CODE (in) == SUBREG && REG_P (SUBREG_REG (in))))
1335 && reg_or_subregno (in) < FIRST_PSEUDO_REGISTER
1336 && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (reg_or_subregno (in)),
1337 class, inmode))
1338 get_secondary_mem (in, inmode, opnum, type);
1339 #endif
1341 i = n_reloads;
1342 rld[i].in = in;
1343 rld[i].out = out;
1344 rld[i].class = class;
1345 rld[i].inmode = inmode;
1346 rld[i].outmode = outmode;
1347 rld[i].reg_rtx = 0;
1348 rld[i].optional = optional;
1349 rld[i].inc = 0;
1350 rld[i].nocombine = 0;
1351 rld[i].in_reg = inloc ? *inloc : 0;
1352 rld[i].out_reg = outloc ? *outloc : 0;
1353 rld[i].opnum = opnum;
1354 rld[i].when_needed = type;
1355 rld[i].secondary_in_reload = secondary_in_reload;
1356 rld[i].secondary_out_reload = secondary_out_reload;
1357 rld[i].secondary_in_icode = secondary_in_icode;
1358 rld[i].secondary_out_icode = secondary_out_icode;
1359 rld[i].secondary_p = 0;
1361 n_reloads++;
1363 #ifdef SECONDARY_MEMORY_NEEDED
1364 if (out != 0
1365 && (REG_P (out)
1366 || (GET_CODE (out) == SUBREG && REG_P (SUBREG_REG (out))))
1367 && reg_or_subregno (out) < FIRST_PSEUDO_REGISTER
1368 && SECONDARY_MEMORY_NEEDED (class,
1369 REGNO_REG_CLASS (reg_or_subregno (out)),
1370 outmode))
1371 get_secondary_mem (out, outmode, opnum, type);
1372 #endif
1374 else
1376 /* We are reusing an existing reload,
1377 but we may have additional information for it.
1378 For example, we may now have both IN and OUT
1379 while the old one may have just one of them. */
1381 /* The modes can be different. If they are, we want to reload in
1382 the larger mode, so that the value is valid for both modes. */
1383 if (inmode != VOIDmode
1384 && GET_MODE_SIZE (inmode) > GET_MODE_SIZE (rld[i].inmode))
1385 rld[i].inmode = inmode;
1386 if (outmode != VOIDmode
1387 && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (rld[i].outmode))
1388 rld[i].outmode = outmode;
1389 if (in != 0)
1391 rtx in_reg = inloc ? *inloc : 0;
1392 /* If we merge reloads for two distinct rtl expressions that
1393 are identical in content, there might be duplicate address
1394 reloads. Remove the extra set now, so that if we later find
1395 that we can inherit this reload, we can get rid of the
1396 address reloads altogether.
1398 Do not do this if both reloads are optional since the result
1399 would be an optional reload which could potentially leave
1400 unresolved address replacements.
1402 It is not sufficient to call transfer_replacements since
1403 choose_reload_regs will remove the replacements for address
1404 reloads of inherited reloads which results in the same
1405 problem. */
1406 if (rld[i].in != in && rtx_equal_p (in, rld[i].in)
1407 && ! (rld[i].optional && optional))
1409 /* We must keep the address reload with the lower operand
1410 number alive. */
1411 if (opnum > rld[i].opnum)
1413 remove_address_replacements (in);
1414 in = rld[i].in;
1415 in_reg = rld[i].in_reg;
1417 else
1418 remove_address_replacements (rld[i].in);
1420 rld[i].in = in;
1421 rld[i].in_reg = in_reg;
1423 if (out != 0)
1425 rld[i].out = out;
1426 rld[i].out_reg = outloc ? *outloc : 0;
1428 if (reg_class_subset_p (class, rld[i].class))
1429 rld[i].class = class;
1430 rld[i].optional &= optional;
1431 if (MERGE_TO_OTHER (type, rld[i].when_needed,
1432 opnum, rld[i].opnum))
1433 rld[i].when_needed = RELOAD_OTHER;
1434 rld[i].opnum = MIN (rld[i].opnum, opnum);
1437 /* If the ostensible rtx being reloaded differs from the rtx found
1438 in the location to substitute, this reload is not safe to combine
1439 because we cannot reliably tell whether it appears in the insn. */
1441 if (in != 0 && in != *inloc)
1442 rld[i].nocombine = 1;
1444 #if 0
1445 /* This was replaced by changes in find_reloads_address_1 and the new
1446 function inc_for_reload, which go with a new meaning of reload_inc. */
1448 /* If this is an IN/OUT reload in an insn that sets the CC,
1449 it must be for an autoincrement. It doesn't work to store
1450 the incremented value after the insn because that would clobber the CC.
1451 So we must do the increment of the value reloaded from,
1452 increment it, store it back, then decrement again. */
1453 if (out != 0 && sets_cc0_p (PATTERN (this_insn)))
1455 out = 0;
1456 rld[i].out = 0;
1457 rld[i].inc = find_inc_amount (PATTERN (this_insn), in);
1458 /* If we did not find a nonzero amount-to-increment-by,
1459 that contradicts the belief that IN is being incremented
1460 in an address in this insn. */
1461 gcc_assert (rld[i].inc != 0);
1463 #endif
1465 /* If we will replace IN and OUT with the reload-reg,
1466 record where they are located so that substitution need
1467 not do a tree walk. */
1469 if (replace_reloads)
1471 if (inloc != 0)
1473 struct replacement *r = &replacements[n_replacements++];
1474 r->what = i;
1475 r->subreg_loc = in_subreg_loc;
1476 r->where = inloc;
1477 r->mode = inmode;
1479 if (outloc != 0 && outloc != inloc)
1481 struct replacement *r = &replacements[n_replacements++];
1482 r->what = i;
1483 r->where = outloc;
1484 r->subreg_loc = out_subreg_loc;
1485 r->mode = outmode;
1489 /* If this reload is just being introduced and it has both
1490 an incoming quantity and an outgoing quantity that are
1491 supposed to be made to match, see if either one of the two
1492 can serve as the place to reload into.
1494 If one of them is acceptable, set rld[i].reg_rtx
1495 to that one. */
1497 if (in != 0 && out != 0 && in != out && rld[i].reg_rtx == 0)
1499 rld[i].reg_rtx = find_dummy_reload (in, out, inloc, outloc,
1500 inmode, outmode,
1501 rld[i].class, i,
1502 earlyclobber_operand_p (out));
1504 /* If the outgoing register already contains the same value
1505 as the incoming one, we can dispense with loading it.
1506 The easiest way to tell the caller that is to give a phony
1507 value for the incoming operand (same as outgoing one). */
1508 if (rld[i].reg_rtx == out
1509 && (REG_P (in) || CONSTANT_P (in))
1510 && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
1511 static_reload_reg_p, i, inmode))
1512 rld[i].in = out;
1515 /* If this is an input reload and the operand contains a register that
1516 dies in this insn and is used nowhere else, see if it is the right class
1517 to be used for this reload. Use it if so. (This occurs most commonly
1518 in the case of paradoxical SUBREGs and in-out reloads). We cannot do
1519 this if it is also an output reload that mentions the register unless
1520 the output is a SUBREG that clobbers an entire register.
1522 Note that the operand might be one of the spill regs, if it is a
1523 pseudo reg and we are in a block where spilling has not taken place.
1524 But if there is no spilling in this block, that is OK.
1525 An explicitly used hard reg cannot be a spill reg. */
1527 if (rld[i].reg_rtx == 0 && in != 0 && hard_regs_live_known)
1529 rtx note;
1530 int regno;
1531 enum machine_mode rel_mode = inmode;
1533 if (out && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (inmode))
1534 rel_mode = outmode;
1536 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1537 if (REG_NOTE_KIND (note) == REG_DEAD
1538 && REG_P (XEXP (note, 0))
1539 && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER
1540 && reg_mentioned_p (XEXP (note, 0), in)
1541 /* Check that we don't use a hardreg for an uninitialized
1542 pseudo. See also find_dummy_reload(). */
1543 && (ORIGINAL_REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1544 || ! bitmap_bit_p (ENTRY_BLOCK_PTR->il.rtl->global_live_at_end,
1545 ORIGINAL_REGNO (XEXP (note, 0))))
1546 && ! refers_to_regno_for_reload_p (regno,
1547 (regno
1548 + hard_regno_nregs[regno]
1549 [rel_mode]),
1550 PATTERN (this_insn), inloc)
1551 /* If this is also an output reload, IN cannot be used as
1552 the reload register if it is set in this insn unless IN
1553 is also OUT. */
1554 && (out == 0 || in == out
1555 || ! hard_reg_set_here_p (regno,
1556 (regno
1557 + hard_regno_nregs[regno]
1558 [rel_mode]),
1559 PATTERN (this_insn)))
1560 /* ??? Why is this code so different from the previous?
1561 Is there any simple coherent way to describe the two together?
1562 What's going on here. */
1563 && (in != out
1564 || (GET_CODE (in) == SUBREG
1565 && (((GET_MODE_SIZE (GET_MODE (in)) + (UNITS_PER_WORD - 1))
1566 / UNITS_PER_WORD)
1567 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1568 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
1569 /* Make sure the operand fits in the reg that dies. */
1570 && (GET_MODE_SIZE (rel_mode)
1571 <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0))))
1572 && HARD_REGNO_MODE_OK (regno, inmode)
1573 && HARD_REGNO_MODE_OK (regno, outmode))
1575 unsigned int offs;
1576 unsigned int nregs = MAX (hard_regno_nregs[regno][inmode],
1577 hard_regno_nregs[regno][outmode]);
1579 for (offs = 0; offs < nregs; offs++)
1580 if (fixed_regs[regno + offs]
1581 || ! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1582 regno + offs))
1583 break;
1585 if (offs == nregs
1586 && (! (refers_to_regno_for_reload_p
1587 (regno, (regno + hard_regno_nregs[regno][inmode]),
1588 in, (rtx *)0))
1589 || can_reload_into (in, regno, inmode)))
1591 rld[i].reg_rtx = gen_rtx_REG (rel_mode, regno);
1592 break;
1597 if (out)
1598 output_reloadnum = i;
1600 return i;
1603 /* Record an additional place we must replace a value
1604 for which we have already recorded a reload.
1605 RELOADNUM is the value returned by push_reload
1606 when the reload was recorded.
1607 This is used in insn patterns that use match_dup. */
1609 static void
1610 push_replacement (rtx *loc, int reloadnum, enum machine_mode mode)
1612 if (replace_reloads)
1614 struct replacement *r = &replacements[n_replacements++];
1615 r->what = reloadnum;
1616 r->where = loc;
1617 r->subreg_loc = 0;
1618 r->mode = mode;
1622 /* Duplicate any replacement we have recorded to apply at
1623 location ORIG_LOC to also be performed at DUP_LOC.
1624 This is used in insn patterns that use match_dup. */
1626 static void
1627 dup_replacements (rtx *dup_loc, rtx *orig_loc)
1629 int i, n = n_replacements;
1631 for (i = 0; i < n; i++)
1633 struct replacement *r = &replacements[i];
1634 if (r->where == orig_loc)
1635 push_replacement (dup_loc, r->what, r->mode);
1639 /* Transfer all replacements that used to be in reload FROM to be in
1640 reload TO. */
1642 void
1643 transfer_replacements (int to, int from)
1645 int i;
1647 for (i = 0; i < n_replacements; i++)
1648 if (replacements[i].what == from)
1649 replacements[i].what = to;
1652 /* IN_RTX is the value loaded by a reload that we now decided to inherit,
1653 or a subpart of it. If we have any replacements registered for IN_RTX,
1654 cancel the reloads that were supposed to load them.
1655 Return nonzero if we canceled any reloads. */
1657 remove_address_replacements (rtx in_rtx)
1659 int i, j;
1660 char reload_flags[MAX_RELOADS];
1661 int something_changed = 0;
1663 memset (reload_flags, 0, sizeof reload_flags);
1664 for (i = 0, j = 0; i < n_replacements; i++)
1666 if (loc_mentioned_in_p (replacements[i].where, in_rtx))
1667 reload_flags[replacements[i].what] |= 1;
1668 else
1670 replacements[j++] = replacements[i];
1671 reload_flags[replacements[i].what] |= 2;
1674 /* Note that the following store must be done before the recursive calls. */
1675 n_replacements = j;
1677 for (i = n_reloads - 1; i >= 0; i--)
1679 if (reload_flags[i] == 1)
1681 deallocate_reload_reg (i);
1682 remove_address_replacements (rld[i].in);
1683 rld[i].in = 0;
1684 something_changed = 1;
1687 return something_changed;
1690 /* If there is only one output reload, and it is not for an earlyclobber
1691 operand, try to combine it with a (logically unrelated) input reload
1692 to reduce the number of reload registers needed.
1694 This is safe if the input reload does not appear in
1695 the value being output-reloaded, because this implies
1696 it is not needed any more once the original insn completes.
1698 If that doesn't work, see we can use any of the registers that
1699 die in this insn as a reload register. We can if it is of the right
1700 class and does not appear in the value being output-reloaded. */
1702 static void
1703 combine_reloads (void)
1705 int i;
1706 int output_reload = -1;
1707 int secondary_out = -1;
1708 rtx note;
1710 /* Find the output reload; return unless there is exactly one
1711 and that one is mandatory. */
1713 for (i = 0; i < n_reloads; i++)
1714 if (rld[i].out != 0)
1716 if (output_reload >= 0)
1717 return;
1718 output_reload = i;
1721 if (output_reload < 0 || rld[output_reload].optional)
1722 return;
1724 /* An input-output reload isn't combinable. */
1726 if (rld[output_reload].in != 0)
1727 return;
1729 /* If this reload is for an earlyclobber operand, we can't do anything. */
1730 if (earlyclobber_operand_p (rld[output_reload].out))
1731 return;
1733 /* If there is a reload for part of the address of this operand, we would
1734 need to chnage it to RELOAD_FOR_OTHER_ADDRESS. But that would extend
1735 its life to the point where doing this combine would not lower the
1736 number of spill registers needed. */
1737 for (i = 0; i < n_reloads; i++)
1738 if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
1739 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
1740 && rld[i].opnum == rld[output_reload].opnum)
1741 return;
1743 /* Check each input reload; can we combine it? */
1745 for (i = 0; i < n_reloads; i++)
1746 if (rld[i].in && ! rld[i].optional && ! rld[i].nocombine
1747 /* Life span of this reload must not extend past main insn. */
1748 && rld[i].when_needed != RELOAD_FOR_OUTPUT_ADDRESS
1749 && rld[i].when_needed != RELOAD_FOR_OUTADDR_ADDRESS
1750 && rld[i].when_needed != RELOAD_OTHER
1751 && (CLASS_MAX_NREGS (rld[i].class, rld[i].inmode)
1752 == CLASS_MAX_NREGS (rld[output_reload].class,
1753 rld[output_reload].outmode))
1754 && rld[i].inc == 0
1755 && rld[i].reg_rtx == 0
1756 #ifdef SECONDARY_MEMORY_NEEDED
1757 /* Don't combine two reloads with different secondary
1758 memory locations. */
1759 && (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum] == 0
1760 || secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] == 0
1761 || rtx_equal_p (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum],
1762 secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum]))
1763 #endif
1764 && (SMALL_REGISTER_CLASSES
1765 ? (rld[i].class == rld[output_reload].class)
1766 : (reg_class_subset_p (rld[i].class,
1767 rld[output_reload].class)
1768 || reg_class_subset_p (rld[output_reload].class,
1769 rld[i].class)))
1770 && (MATCHES (rld[i].in, rld[output_reload].out)
1771 /* Args reversed because the first arg seems to be
1772 the one that we imagine being modified
1773 while the second is the one that might be affected. */
1774 || (! reg_overlap_mentioned_for_reload_p (rld[output_reload].out,
1775 rld[i].in)
1776 /* However, if the input is a register that appears inside
1777 the output, then we also can't share.
1778 Imagine (set (mem (reg 69)) (plus (reg 69) ...)).
1779 If the same reload reg is used for both reg 69 and the
1780 result to be stored in memory, then that result
1781 will clobber the address of the memory ref. */
1782 && ! (REG_P (rld[i].in)
1783 && reg_overlap_mentioned_for_reload_p (rld[i].in,
1784 rld[output_reload].out))))
1785 && ! reload_inner_reg_of_subreg (rld[i].in, rld[i].inmode,
1786 rld[i].when_needed != RELOAD_FOR_INPUT)
1787 && (reg_class_size[(int) rld[i].class]
1788 || SMALL_REGISTER_CLASSES)
1789 /* We will allow making things slightly worse by combining an
1790 input and an output, but no worse than that. */
1791 && (rld[i].when_needed == RELOAD_FOR_INPUT
1792 || rld[i].when_needed == RELOAD_FOR_OUTPUT))
1794 int j;
1796 /* We have found a reload to combine with! */
1797 rld[i].out = rld[output_reload].out;
1798 rld[i].out_reg = rld[output_reload].out_reg;
1799 rld[i].outmode = rld[output_reload].outmode;
1800 /* Mark the old output reload as inoperative. */
1801 rld[output_reload].out = 0;
1802 /* The combined reload is needed for the entire insn. */
1803 rld[i].when_needed = RELOAD_OTHER;
1804 /* If the output reload had a secondary reload, copy it. */
1805 if (rld[output_reload].secondary_out_reload != -1)
1807 rld[i].secondary_out_reload
1808 = rld[output_reload].secondary_out_reload;
1809 rld[i].secondary_out_icode
1810 = rld[output_reload].secondary_out_icode;
1813 #ifdef SECONDARY_MEMORY_NEEDED
1814 /* Copy any secondary MEM. */
1815 if (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] != 0)
1816 secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum]
1817 = secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum];
1818 #endif
1819 /* If required, minimize the register class. */
1820 if (reg_class_subset_p (rld[output_reload].class,
1821 rld[i].class))
1822 rld[i].class = rld[output_reload].class;
1824 /* Transfer all replacements from the old reload to the combined. */
1825 for (j = 0; j < n_replacements; j++)
1826 if (replacements[j].what == output_reload)
1827 replacements[j].what = i;
1829 return;
1832 /* If this insn has only one operand that is modified or written (assumed
1833 to be the first), it must be the one corresponding to this reload. It
1834 is safe to use anything that dies in this insn for that output provided
1835 that it does not occur in the output (we already know it isn't an
1836 earlyclobber. If this is an asm insn, give up. */
1838 if (INSN_CODE (this_insn) == -1)
1839 return;
1841 for (i = 1; i < insn_data[INSN_CODE (this_insn)].n_operands; i++)
1842 if (insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '='
1843 || insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '+')
1844 return;
1846 /* See if some hard register that dies in this insn and is not used in
1847 the output is the right class. Only works if the register we pick
1848 up can fully hold our output reload. */
1849 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1850 if (REG_NOTE_KIND (note) == REG_DEAD
1851 && REG_P (XEXP (note, 0))
1852 && ! reg_overlap_mentioned_for_reload_p (XEXP (note, 0),
1853 rld[output_reload].out)
1854 && REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1855 && HARD_REGNO_MODE_OK (REGNO (XEXP (note, 0)), rld[output_reload].outmode)
1856 && TEST_HARD_REG_BIT (reg_class_contents[(int) rld[output_reload].class],
1857 REGNO (XEXP (note, 0)))
1858 && (hard_regno_nregs[REGNO (XEXP (note, 0))][rld[output_reload].outmode]
1859 <= hard_regno_nregs[REGNO (XEXP (note, 0))][GET_MODE (XEXP (note, 0))])
1860 /* Ensure that a secondary or tertiary reload for this output
1861 won't want this register. */
1862 && ((secondary_out = rld[output_reload].secondary_out_reload) == -1
1863 || (! (TEST_HARD_REG_BIT
1864 (reg_class_contents[(int) rld[secondary_out].class],
1865 REGNO (XEXP (note, 0))))
1866 && ((secondary_out = rld[secondary_out].secondary_out_reload) == -1
1867 || ! (TEST_HARD_REG_BIT
1868 (reg_class_contents[(int) rld[secondary_out].class],
1869 REGNO (XEXP (note, 0)))))))
1870 && ! fixed_regs[REGNO (XEXP (note, 0))]
1871 /* Check that we don't use a hardreg for an uninitialized
1872 pseudo. See also find_dummy_reload(). */
1873 && (ORIGINAL_REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1874 || ! bitmap_bit_p (ENTRY_BLOCK_PTR->il.rtl->global_live_at_end,
1875 ORIGINAL_REGNO (XEXP (note, 0)))))
1877 rld[output_reload].reg_rtx
1878 = gen_rtx_REG (rld[output_reload].outmode,
1879 REGNO (XEXP (note, 0)));
1880 return;
1884 /* Try to find a reload register for an in-out reload (expressions IN and OUT).
1885 See if one of IN and OUT is a register that may be used;
1886 this is desirable since a spill-register won't be needed.
1887 If so, return the register rtx that proves acceptable.
1889 INLOC and OUTLOC are locations where IN and OUT appear in the insn.
1890 CLASS is the register class required for the reload.
1892 If FOR_REAL is >= 0, it is the number of the reload,
1893 and in some cases when it can be discovered that OUT doesn't need
1894 to be computed, clear out rld[FOR_REAL].out.
1896 If FOR_REAL is -1, this should not be done, because this call
1897 is just to see if a register can be found, not to find and install it.
1899 EARLYCLOBBER is nonzero if OUT is an earlyclobber operand. This
1900 puts an additional constraint on being able to use IN for OUT since
1901 IN must not appear elsewhere in the insn (it is assumed that IN itself
1902 is safe from the earlyclobber). */
1904 static rtx
1905 find_dummy_reload (rtx real_in, rtx real_out, rtx *inloc, rtx *outloc,
1906 enum machine_mode inmode, enum machine_mode outmode,
1907 enum reg_class class, int for_real, int earlyclobber)
1909 rtx in = real_in;
1910 rtx out = real_out;
1911 int in_offset = 0;
1912 int out_offset = 0;
1913 rtx value = 0;
1915 /* If operands exceed a word, we can't use either of them
1916 unless they have the same size. */
1917 if (GET_MODE_SIZE (outmode) != GET_MODE_SIZE (inmode)
1918 && (GET_MODE_SIZE (outmode) > UNITS_PER_WORD
1919 || GET_MODE_SIZE (inmode) > UNITS_PER_WORD))
1920 return 0;
1922 /* Note that {in,out}_offset are needed only when 'in' or 'out'
1923 respectively refers to a hard register. */
1925 /* Find the inside of any subregs. */
1926 while (GET_CODE (out) == SUBREG)
1928 if (REG_P (SUBREG_REG (out))
1929 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER)
1930 out_offset += subreg_regno_offset (REGNO (SUBREG_REG (out)),
1931 GET_MODE (SUBREG_REG (out)),
1932 SUBREG_BYTE (out),
1933 GET_MODE (out));
1934 out = SUBREG_REG (out);
1936 while (GET_CODE (in) == SUBREG)
1938 if (REG_P (SUBREG_REG (in))
1939 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER)
1940 in_offset += subreg_regno_offset (REGNO (SUBREG_REG (in)),
1941 GET_MODE (SUBREG_REG (in)),
1942 SUBREG_BYTE (in),
1943 GET_MODE (in));
1944 in = SUBREG_REG (in);
1947 /* Narrow down the reg class, the same way push_reload will;
1948 otherwise we might find a dummy now, but push_reload won't. */
1949 class = PREFERRED_RELOAD_CLASS (in, class);
1951 /* See if OUT will do. */
1952 if (REG_P (out)
1953 && REGNO (out) < FIRST_PSEUDO_REGISTER)
1955 unsigned int regno = REGNO (out) + out_offset;
1956 unsigned int nwords = hard_regno_nregs[regno][outmode];
1957 rtx saved_rtx;
1959 /* When we consider whether the insn uses OUT,
1960 ignore references within IN. They don't prevent us
1961 from copying IN into OUT, because those refs would
1962 move into the insn that reloads IN.
1964 However, we only ignore IN in its role as this reload.
1965 If the insn uses IN elsewhere and it contains OUT,
1966 that counts. We can't be sure it's the "same" operand
1967 so it might not go through this reload. */
1968 saved_rtx = *inloc;
1969 *inloc = const0_rtx;
1971 if (regno < FIRST_PSEUDO_REGISTER
1972 && HARD_REGNO_MODE_OK (regno, outmode)
1973 && ! refers_to_regno_for_reload_p (regno, regno + nwords,
1974 PATTERN (this_insn), outloc))
1976 unsigned int i;
1978 for (i = 0; i < nwords; i++)
1979 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1980 regno + i))
1981 break;
1983 if (i == nwords)
1985 if (REG_P (real_out))
1986 value = real_out;
1987 else
1988 value = gen_rtx_REG (outmode, regno);
1992 *inloc = saved_rtx;
1995 /* Consider using IN if OUT was not acceptable
1996 or if OUT dies in this insn (like the quotient in a divmod insn).
1997 We can't use IN unless it is dies in this insn,
1998 which means we must know accurately which hard regs are live.
1999 Also, the result can't go in IN if IN is used within OUT,
2000 or if OUT is an earlyclobber and IN appears elsewhere in the insn. */
2001 if (hard_regs_live_known
2002 && REG_P (in)
2003 && REGNO (in) < FIRST_PSEUDO_REGISTER
2004 && (value == 0
2005 || find_reg_note (this_insn, REG_UNUSED, real_out))
2006 && find_reg_note (this_insn, REG_DEAD, real_in)
2007 && !fixed_regs[REGNO (in)]
2008 && HARD_REGNO_MODE_OK (REGNO (in),
2009 /* The only case where out and real_out might
2010 have different modes is where real_out
2011 is a subreg, and in that case, out
2012 has a real mode. */
2013 (GET_MODE (out) != VOIDmode
2014 ? GET_MODE (out) : outmode))
2015 /* But only do all this if we can be sure, that this input
2016 operand doesn't correspond with an uninitialized pseudoreg.
2017 global can assign some hardreg to it, which is the same as
2018 a different pseudo also currently live (as it can ignore the
2019 conflict). So we never must introduce writes to such hardregs,
2020 as they would clobber the other live pseudo using the same.
2021 See also PR20973. */
2022 && (ORIGINAL_REGNO (in) < FIRST_PSEUDO_REGISTER
2023 || ! bitmap_bit_p (ENTRY_BLOCK_PTR->il.rtl->global_live_at_end,
2024 ORIGINAL_REGNO (in))))
2026 unsigned int regno = REGNO (in) + in_offset;
2027 unsigned int nwords = hard_regno_nregs[regno][inmode];
2029 if (! refers_to_regno_for_reload_p (regno, regno + nwords, out, (rtx*) 0)
2030 && ! hard_reg_set_here_p (regno, regno + nwords,
2031 PATTERN (this_insn))
2032 && (! earlyclobber
2033 || ! refers_to_regno_for_reload_p (regno, regno + nwords,
2034 PATTERN (this_insn), inloc)))
2036 unsigned int i;
2038 for (i = 0; i < nwords; i++)
2039 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
2040 regno + i))
2041 break;
2043 if (i == nwords)
2045 /* If we were going to use OUT as the reload reg
2046 and changed our mind, it means OUT is a dummy that
2047 dies here. So don't bother copying value to it. */
2048 if (for_real >= 0 && value == real_out)
2049 rld[for_real].out = 0;
2050 if (REG_P (real_in))
2051 value = real_in;
2052 else
2053 value = gen_rtx_REG (inmode, regno);
2058 return value;
2061 /* This page contains subroutines used mainly for determining
2062 whether the IN or an OUT of a reload can serve as the
2063 reload register. */
2065 /* Return 1 if X is an operand of an insn that is being earlyclobbered. */
2068 earlyclobber_operand_p (rtx x)
2070 int i;
2072 for (i = 0; i < n_earlyclobbers; i++)
2073 if (reload_earlyclobbers[i] == x)
2074 return 1;
2076 return 0;
2079 /* Return 1 if expression X alters a hard reg in the range
2080 from BEG_REGNO (inclusive) to END_REGNO (exclusive),
2081 either explicitly or in the guise of a pseudo-reg allocated to REGNO.
2082 X should be the body of an instruction. */
2084 static int
2085 hard_reg_set_here_p (unsigned int beg_regno, unsigned int end_regno, rtx x)
2087 if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
2089 rtx op0 = SET_DEST (x);
2091 while (GET_CODE (op0) == SUBREG)
2092 op0 = SUBREG_REG (op0);
2093 if (REG_P (op0))
2095 unsigned int r = REGNO (op0);
2097 /* See if this reg overlaps range under consideration. */
2098 if (r < end_regno
2099 && r + hard_regno_nregs[r][GET_MODE (op0)] > beg_regno)
2100 return 1;
2103 else if (GET_CODE (x) == PARALLEL)
2105 int i = XVECLEN (x, 0) - 1;
2107 for (; i >= 0; i--)
2108 if (hard_reg_set_here_p (beg_regno, end_regno, XVECEXP (x, 0, i)))
2109 return 1;
2112 return 0;
2115 /* Return 1 if ADDR is a valid memory address for mode MODE,
2116 and check that each pseudo reg has the proper kind of
2117 hard reg. */
2120 strict_memory_address_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx addr)
2122 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
2123 return 0;
2125 win:
2126 return 1;
2129 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
2130 if they are the same hard reg, and has special hacks for
2131 autoincrement and autodecrement.
2132 This is specifically intended for find_reloads to use
2133 in determining whether two operands match.
2134 X is the operand whose number is the lower of the two.
2136 The value is 2 if Y contains a pre-increment that matches
2137 a non-incrementing address in X. */
2139 /* ??? To be completely correct, we should arrange to pass
2140 for X the output operand and for Y the input operand.
2141 For now, we assume that the output operand has the lower number
2142 because that is natural in (SET output (... input ...)). */
2145 operands_match_p (rtx x, rtx y)
2147 int i;
2148 RTX_CODE code = GET_CODE (x);
2149 const char *fmt;
2150 int success_2;
2152 if (x == y)
2153 return 1;
2154 if ((code == REG || (code == SUBREG && REG_P (SUBREG_REG (x))))
2155 && (REG_P (y) || (GET_CODE (y) == SUBREG
2156 && REG_P (SUBREG_REG (y)))))
2158 int j;
2160 if (code == SUBREG)
2162 i = REGNO (SUBREG_REG (x));
2163 if (i >= FIRST_PSEUDO_REGISTER)
2164 goto slow;
2165 i += subreg_regno_offset (REGNO (SUBREG_REG (x)),
2166 GET_MODE (SUBREG_REG (x)),
2167 SUBREG_BYTE (x),
2168 GET_MODE (x));
2170 else
2171 i = REGNO (x);
2173 if (GET_CODE (y) == SUBREG)
2175 j = REGNO (SUBREG_REG (y));
2176 if (j >= FIRST_PSEUDO_REGISTER)
2177 goto slow;
2178 j += subreg_regno_offset (REGNO (SUBREG_REG (y)),
2179 GET_MODE (SUBREG_REG (y)),
2180 SUBREG_BYTE (y),
2181 GET_MODE (y));
2183 else
2184 j = REGNO (y);
2186 /* On a WORDS_BIG_ENDIAN machine, point to the last register of a
2187 multiple hard register group of scalar integer registers, so that
2188 for example (reg:DI 0) and (reg:SI 1) will be considered the same
2189 register. */
2190 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
2191 && SCALAR_INT_MODE_P (GET_MODE (x))
2192 && i < FIRST_PSEUDO_REGISTER)
2193 i += hard_regno_nregs[i][GET_MODE (x)] - 1;
2194 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (y)) > UNITS_PER_WORD
2195 && SCALAR_INT_MODE_P (GET_MODE (y))
2196 && j < FIRST_PSEUDO_REGISTER)
2197 j += hard_regno_nregs[j][GET_MODE (y)] - 1;
2199 return i == j;
2201 /* If two operands must match, because they are really a single
2202 operand of an assembler insn, then two postincrements are invalid
2203 because the assembler insn would increment only once.
2204 On the other hand, a postincrement matches ordinary indexing
2205 if the postincrement is the output operand. */
2206 if (code == POST_DEC || code == POST_INC || code == POST_MODIFY)
2207 return operands_match_p (XEXP (x, 0), y);
2208 /* Two preincrements are invalid
2209 because the assembler insn would increment only once.
2210 On the other hand, a preincrement matches ordinary indexing
2211 if the preincrement is the input operand.
2212 In this case, return 2, since some callers need to do special
2213 things when this happens. */
2214 if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC
2215 || GET_CODE (y) == PRE_MODIFY)
2216 return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
2218 slow:
2220 /* Now we have disposed of all the cases in which different rtx codes
2221 can match. */
2222 if (code != GET_CODE (y))
2223 return 0;
2225 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
2226 if (GET_MODE (x) != GET_MODE (y))
2227 return 0;
2229 switch (code)
2231 case CONST_INT:
2232 case CONST_DOUBLE:
2233 return 0;
2235 case LABEL_REF:
2236 return XEXP (x, 0) == XEXP (y, 0);
2237 case SYMBOL_REF:
2238 return XSTR (x, 0) == XSTR (y, 0);
2240 default:
2241 break;
2244 /* Compare the elements. If any pair of corresponding elements
2245 fail to match, return 0 for the whole things. */
2247 success_2 = 0;
2248 fmt = GET_RTX_FORMAT (code);
2249 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2251 int val, j;
2252 switch (fmt[i])
2254 case 'w':
2255 if (XWINT (x, i) != XWINT (y, i))
2256 return 0;
2257 break;
2259 case 'i':
2260 if (XINT (x, i) != XINT (y, i))
2261 return 0;
2262 break;
2264 case 'e':
2265 val = operands_match_p (XEXP (x, i), XEXP (y, i));
2266 if (val == 0)
2267 return 0;
2268 /* If any subexpression returns 2,
2269 we should return 2 if we are successful. */
2270 if (val == 2)
2271 success_2 = 1;
2272 break;
2274 case '0':
2275 break;
2277 case 'E':
2278 if (XVECLEN (x, i) != XVECLEN (y, i))
2279 return 0;
2280 for (j = XVECLEN (x, i) - 1; j >= 0; --j)
2282 val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j));
2283 if (val == 0)
2284 return 0;
2285 if (val == 2)
2286 success_2 = 1;
2288 break;
2290 /* It is believed that rtx's at this level will never
2291 contain anything but integers and other rtx's,
2292 except for within LABEL_REFs and SYMBOL_REFs. */
2293 default:
2294 gcc_unreachable ();
2297 return 1 + success_2;
2300 /* Describe the range of registers or memory referenced by X.
2301 If X is a register, set REG_FLAG and put the first register
2302 number into START and the last plus one into END.
2303 If X is a memory reference, put a base address into BASE
2304 and a range of integer offsets into START and END.
2305 If X is pushing on the stack, we can assume it causes no trouble,
2306 so we set the SAFE field. */
2308 static struct decomposition
2309 decompose (rtx x)
2311 struct decomposition val;
2312 int all_const = 0;
2314 memset (&val, 0, sizeof (val));
2316 switch (GET_CODE (x))
2318 case MEM:
2320 rtx base = NULL_RTX, offset = 0;
2321 rtx addr = XEXP (x, 0);
2323 if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
2324 || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
2326 val.base = XEXP (addr, 0);
2327 val.start = -GET_MODE_SIZE (GET_MODE (x));
2328 val.end = GET_MODE_SIZE (GET_MODE (x));
2329 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2330 return val;
2333 if (GET_CODE (addr) == PRE_MODIFY || GET_CODE (addr) == POST_MODIFY)
2335 if (GET_CODE (XEXP (addr, 1)) == PLUS
2336 && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0)
2337 && CONSTANT_P (XEXP (XEXP (addr, 1), 1)))
2339 val.base = XEXP (addr, 0);
2340 val.start = -INTVAL (XEXP (XEXP (addr, 1), 1));
2341 val.end = INTVAL (XEXP (XEXP (addr, 1), 1));
2342 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2343 return val;
2347 if (GET_CODE (addr) == CONST)
2349 addr = XEXP (addr, 0);
2350 all_const = 1;
2352 if (GET_CODE (addr) == PLUS)
2354 if (CONSTANT_P (XEXP (addr, 0)))
2356 base = XEXP (addr, 1);
2357 offset = XEXP (addr, 0);
2359 else if (CONSTANT_P (XEXP (addr, 1)))
2361 base = XEXP (addr, 0);
2362 offset = XEXP (addr, 1);
2366 if (offset == 0)
2368 base = addr;
2369 offset = const0_rtx;
2371 if (GET_CODE (offset) == CONST)
2372 offset = XEXP (offset, 0);
2373 if (GET_CODE (offset) == PLUS)
2375 if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
2377 base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 1));
2378 offset = XEXP (offset, 0);
2380 else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
2382 base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 0));
2383 offset = XEXP (offset, 1);
2385 else
2387 base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2388 offset = const0_rtx;
2391 else if (GET_CODE (offset) != CONST_INT)
2393 base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2394 offset = const0_rtx;
2397 if (all_const && GET_CODE (base) == PLUS)
2398 base = gen_rtx_CONST (GET_MODE (base), base);
2400 gcc_assert (GET_CODE (offset) == CONST_INT);
2402 val.start = INTVAL (offset);
2403 val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
2404 val.base = base;
2406 break;
2408 case REG:
2409 val.reg_flag = 1;
2410 val.start = true_regnum (x);
2411 if (val.start < 0 || val.start >= FIRST_PSEUDO_REGISTER)
2413 /* A pseudo with no hard reg. */
2414 val.start = REGNO (x);
2415 val.end = val.start + 1;
2417 else
2418 /* A hard reg. */
2419 val.end = val.start + hard_regno_nregs[val.start][GET_MODE (x)];
2420 break;
2422 case SUBREG:
2423 if (!REG_P (SUBREG_REG (x)))
2424 /* This could be more precise, but it's good enough. */
2425 return decompose (SUBREG_REG (x));
2426 val.reg_flag = 1;
2427 val.start = true_regnum (x);
2428 if (val.start < 0 || val.start >= FIRST_PSEUDO_REGISTER)
2429 return decompose (SUBREG_REG (x));
2430 else
2431 /* A hard reg. */
2432 val.end = val.start + hard_regno_nregs[val.start][GET_MODE (x)];
2433 break;
2435 case SCRATCH:
2436 /* This hasn't been assigned yet, so it can't conflict yet. */
2437 val.safe = 1;
2438 break;
2440 default:
2441 gcc_assert (CONSTANT_P (x));
2442 val.safe = 1;
2443 break;
2445 return val;
2448 /* Return 1 if altering Y will not modify the value of X.
2449 Y is also described by YDATA, which should be decompose (Y). */
2451 static int
2452 immune_p (rtx x, rtx y, struct decomposition ydata)
2454 struct decomposition xdata;
2456 if (ydata.reg_flag)
2457 return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, (rtx*) 0);
2458 if (ydata.safe)
2459 return 1;
2461 gcc_assert (MEM_P (y));
2462 /* If Y is memory and X is not, Y can't affect X. */
2463 if (!MEM_P (x))
2464 return 1;
2466 xdata = decompose (x);
2468 if (! rtx_equal_p (xdata.base, ydata.base))
2470 /* If bases are distinct symbolic constants, there is no overlap. */
2471 if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
2472 return 1;
2473 /* Constants and stack slots never overlap. */
2474 if (CONSTANT_P (xdata.base)
2475 && (ydata.base == frame_pointer_rtx
2476 || ydata.base == hard_frame_pointer_rtx
2477 || ydata.base == stack_pointer_rtx))
2478 return 1;
2479 if (CONSTANT_P (ydata.base)
2480 && (xdata.base == frame_pointer_rtx
2481 || xdata.base == hard_frame_pointer_rtx
2482 || xdata.base == stack_pointer_rtx))
2483 return 1;
2484 /* If either base is variable, we don't know anything. */
2485 return 0;
2488 return (xdata.start >= ydata.end || ydata.start >= xdata.end);
2491 /* Similar, but calls decompose. */
2494 safe_from_earlyclobber (rtx op, rtx clobber)
2496 struct decomposition early_data;
2498 early_data = decompose (clobber);
2499 return immune_p (op, clobber, early_data);
2502 /* Main entry point of this file: search the body of INSN
2503 for values that need reloading and record them with push_reload.
2504 REPLACE nonzero means record also where the values occur
2505 so that subst_reloads can be used.
2507 IND_LEVELS says how many levels of indirection are supported by this
2508 machine; a value of zero means that a memory reference is not a valid
2509 memory address.
2511 LIVE_KNOWN says we have valid information about which hard
2512 regs are live at each point in the program; this is true when
2513 we are called from global_alloc but false when stupid register
2514 allocation has been done.
2516 RELOAD_REG_P if nonzero is a vector indexed by hard reg number
2517 which is nonnegative if the reg has been commandeered for reloading into.
2518 It is copied into STATIC_RELOAD_REG_P and referenced from there
2519 by various subroutines.
2521 Return TRUE if some operands need to be changed, because of swapping
2522 commutative operands, reg_equiv_address substitution, or whatever. */
2525 find_reloads (rtx insn, int replace, int ind_levels, int live_known,
2526 short *reload_reg_p)
2528 int insn_code_number;
2529 int i, j;
2530 int noperands;
2531 /* These start out as the constraints for the insn
2532 and they are chewed up as we consider alternatives. */
2533 char *constraints[MAX_RECOG_OPERANDS];
2534 /* These are the preferred classes for an operand, or NO_REGS if it isn't
2535 a register. */
2536 enum reg_class preferred_class[MAX_RECOG_OPERANDS];
2537 char pref_or_nothing[MAX_RECOG_OPERANDS];
2538 /* Nonzero for a MEM operand whose entire address needs a reload.
2539 May be -1 to indicate the entire address may or may not need a reload. */
2540 int address_reloaded[MAX_RECOG_OPERANDS];
2541 /* Nonzero for an address operand that needs to be completely reloaded.
2542 May be -1 to indicate the entire operand may or may not need a reload. */
2543 int address_operand_reloaded[MAX_RECOG_OPERANDS];
2544 /* Value of enum reload_type to use for operand. */
2545 enum reload_type operand_type[MAX_RECOG_OPERANDS];
2546 /* Value of enum reload_type to use within address of operand. */
2547 enum reload_type address_type[MAX_RECOG_OPERANDS];
2548 /* Save the usage of each operand. */
2549 enum reload_usage { RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE } modified[MAX_RECOG_OPERANDS];
2550 int no_input_reloads = 0, no_output_reloads = 0;
2551 int n_alternatives;
2552 int this_alternative[MAX_RECOG_OPERANDS];
2553 char this_alternative_match_win[MAX_RECOG_OPERANDS];
2554 char this_alternative_win[MAX_RECOG_OPERANDS];
2555 char this_alternative_offmemok[MAX_RECOG_OPERANDS];
2556 char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2557 int this_alternative_matches[MAX_RECOG_OPERANDS];
2558 int swapped;
2559 int goal_alternative[MAX_RECOG_OPERANDS];
2560 int this_alternative_number;
2561 int goal_alternative_number = 0;
2562 int operand_reloadnum[MAX_RECOG_OPERANDS];
2563 int goal_alternative_matches[MAX_RECOG_OPERANDS];
2564 int goal_alternative_matched[MAX_RECOG_OPERANDS];
2565 char goal_alternative_match_win[MAX_RECOG_OPERANDS];
2566 char goal_alternative_win[MAX_RECOG_OPERANDS];
2567 char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
2568 char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2569 int goal_alternative_swapped;
2570 int best;
2571 int commutative;
2572 char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
2573 rtx substed_operand[MAX_RECOG_OPERANDS];
2574 rtx body = PATTERN (insn);
2575 rtx set = single_set (insn);
2576 int goal_earlyclobber = 0, this_earlyclobber;
2577 enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
2578 int retval = 0;
2580 this_insn = insn;
2581 n_reloads = 0;
2582 n_replacements = 0;
2583 n_earlyclobbers = 0;
2584 replace_reloads = replace;
2585 hard_regs_live_known = live_known;
2586 static_reload_reg_p = reload_reg_p;
2588 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads;
2589 neither are insns that SET cc0. Insns that use CC0 are not allowed
2590 to have any input reloads. */
2591 if (JUMP_P (insn) || CALL_P (insn))
2592 no_output_reloads = 1;
2594 #ifdef HAVE_cc0
2595 if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
2596 no_input_reloads = 1;
2597 if (reg_set_p (cc0_rtx, PATTERN (insn)))
2598 no_output_reloads = 1;
2599 #endif
2601 #ifdef SECONDARY_MEMORY_NEEDED
2602 /* The eliminated forms of any secondary memory locations are per-insn, so
2603 clear them out here. */
2605 if (secondary_memlocs_elim_used)
2607 memset (secondary_memlocs_elim, 0,
2608 sizeof (secondary_memlocs_elim[0]) * secondary_memlocs_elim_used);
2609 secondary_memlocs_elim_used = 0;
2611 #endif
2613 /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it
2614 is cheap to move between them. If it is not, there may not be an insn
2615 to do the copy, so we may need a reload. */
2616 if (GET_CODE (body) == SET
2617 && REG_P (SET_DEST (body))
2618 && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
2619 && REG_P (SET_SRC (body))
2620 && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER
2621 && REGISTER_MOVE_COST (GET_MODE (SET_SRC (body)),
2622 REGNO_REG_CLASS (REGNO (SET_SRC (body))),
2623 REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2)
2624 return 0;
2626 extract_insn (insn);
2628 noperands = reload_n_operands = recog_data.n_operands;
2629 n_alternatives = recog_data.n_alternatives;
2631 /* Just return "no reloads" if insn has no operands with constraints. */
2632 if (noperands == 0 || n_alternatives == 0)
2633 return 0;
2635 insn_code_number = INSN_CODE (insn);
2636 this_insn_is_asm = insn_code_number < 0;
2638 memcpy (operand_mode, recog_data.operand_mode,
2639 noperands * sizeof (enum machine_mode));
2640 memcpy (constraints, recog_data.constraints, noperands * sizeof (char *));
2642 commutative = -1;
2644 /* If we will need to know, later, whether some pair of operands
2645 are the same, we must compare them now and save the result.
2646 Reloading the base and index registers will clobber them
2647 and afterward they will fail to match. */
2649 for (i = 0; i < noperands; i++)
2651 char *p;
2652 int c;
2654 substed_operand[i] = recog_data.operand[i];
2655 p = constraints[i];
2657 modified[i] = RELOAD_READ;
2659 /* Scan this operand's constraint to see if it is an output operand,
2660 an in-out operand, is commutative, or should match another. */
2662 while ((c = *p))
2664 p += CONSTRAINT_LEN (c, p);
2665 switch (c)
2667 case '=':
2668 modified[i] = RELOAD_WRITE;
2669 break;
2670 case '+':
2671 modified[i] = RELOAD_READ_WRITE;
2672 break;
2673 case '%':
2675 /* The last operand should not be marked commutative. */
2676 gcc_assert (i != noperands - 1);
2678 /* We currently only support one commutative pair of
2679 operands. Some existing asm code currently uses more
2680 than one pair. Previously, that would usually work,
2681 but sometimes it would crash the compiler. We
2682 continue supporting that case as well as we can by
2683 silently ignoring all but the first pair. In the
2684 future we may handle it correctly. */
2685 if (commutative < 0)
2686 commutative = i;
2687 else
2688 gcc_assert (this_insn_is_asm);
2690 break;
2691 /* Use of ISDIGIT is tempting here, but it may get expensive because
2692 of locale support we don't want. */
2693 case '0': case '1': case '2': case '3': case '4':
2694 case '5': case '6': case '7': case '8': case '9':
2696 c = strtoul (p - 1, &p, 10);
2698 operands_match[c][i]
2699 = operands_match_p (recog_data.operand[c],
2700 recog_data.operand[i]);
2702 /* An operand may not match itself. */
2703 gcc_assert (c != i);
2705 /* If C can be commuted with C+1, and C might need to match I,
2706 then C+1 might also need to match I. */
2707 if (commutative >= 0)
2709 if (c == commutative || c == commutative + 1)
2711 int other = c + (c == commutative ? 1 : -1);
2712 operands_match[other][i]
2713 = operands_match_p (recog_data.operand[other],
2714 recog_data.operand[i]);
2716 if (i == commutative || i == commutative + 1)
2718 int other = i + (i == commutative ? 1 : -1);
2719 operands_match[c][other]
2720 = operands_match_p (recog_data.operand[c],
2721 recog_data.operand[other]);
2723 /* Note that C is supposed to be less than I.
2724 No need to consider altering both C and I because in
2725 that case we would alter one into the other. */
2732 /* Examine each operand that is a memory reference or memory address
2733 and reload parts of the addresses into index registers.
2734 Also here any references to pseudo regs that didn't get hard regs
2735 but are equivalent to constants get replaced in the insn itself
2736 with those constants. Nobody will ever see them again.
2738 Finally, set up the preferred classes of each operand. */
2740 for (i = 0; i < noperands; i++)
2742 RTX_CODE code = GET_CODE (recog_data.operand[i]);
2744 address_reloaded[i] = 0;
2745 address_operand_reloaded[i] = 0;
2746 operand_type[i] = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT
2747 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT
2748 : RELOAD_OTHER);
2749 address_type[i]
2750 = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT_ADDRESS
2751 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT_ADDRESS
2752 : RELOAD_OTHER);
2754 if (*constraints[i] == 0)
2755 /* Ignore things like match_operator operands. */
2757 else if (constraints[i][0] == 'p'
2758 || EXTRA_ADDRESS_CONSTRAINT (constraints[i][0], constraints[i]))
2760 address_operand_reloaded[i]
2761 = find_reloads_address (recog_data.operand_mode[i], (rtx*) 0,
2762 recog_data.operand[i],
2763 recog_data.operand_loc[i],
2764 i, operand_type[i], ind_levels, insn);
2766 /* If we now have a simple operand where we used to have a
2767 PLUS or MULT, re-recognize and try again. */
2768 if ((OBJECT_P (*recog_data.operand_loc[i])
2769 || GET_CODE (*recog_data.operand_loc[i]) == SUBREG)
2770 && (GET_CODE (recog_data.operand[i]) == MULT
2771 || GET_CODE (recog_data.operand[i]) == PLUS))
2773 INSN_CODE (insn) = -1;
2774 retval = find_reloads (insn, replace, ind_levels, live_known,
2775 reload_reg_p);
2776 return retval;
2779 recog_data.operand[i] = *recog_data.operand_loc[i];
2780 substed_operand[i] = recog_data.operand[i];
2782 /* Address operands are reloaded in their existing mode,
2783 no matter what is specified in the machine description. */
2784 operand_mode[i] = GET_MODE (recog_data.operand[i]);
2786 else if (code == MEM)
2788 address_reloaded[i]
2789 = find_reloads_address (GET_MODE (recog_data.operand[i]),
2790 recog_data.operand_loc[i],
2791 XEXP (recog_data.operand[i], 0),
2792 &XEXP (recog_data.operand[i], 0),
2793 i, address_type[i], ind_levels, insn);
2794 recog_data.operand[i] = *recog_data.operand_loc[i];
2795 substed_operand[i] = recog_data.operand[i];
2797 else if (code == SUBREG)
2799 rtx reg = SUBREG_REG (recog_data.operand[i]);
2800 rtx op
2801 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2802 ind_levels,
2803 set != 0
2804 && &SET_DEST (set) == recog_data.operand_loc[i],
2805 insn,
2806 &address_reloaded[i]);
2808 /* If we made a MEM to load (a part of) the stackslot of a pseudo
2809 that didn't get a hard register, emit a USE with a REG_EQUAL
2810 note in front so that we might inherit a previous, possibly
2811 wider reload. */
2813 if (replace
2814 && MEM_P (op)
2815 && REG_P (reg)
2816 && (GET_MODE_SIZE (GET_MODE (reg))
2817 >= GET_MODE_SIZE (GET_MODE (op))))
2818 set_unique_reg_note (emit_insn_before (gen_rtx_USE (VOIDmode, reg),
2819 insn),
2820 REG_EQUAL, reg_equiv_memory_loc[REGNO (reg)]);
2822 substed_operand[i] = recog_data.operand[i] = op;
2824 else if (code == PLUS || GET_RTX_CLASS (code) == RTX_UNARY)
2825 /* We can get a PLUS as an "operand" as a result of register
2826 elimination. See eliminate_regs and gen_reload. We handle
2827 a unary operator by reloading the operand. */
2828 substed_operand[i] = recog_data.operand[i]
2829 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2830 ind_levels, 0, insn,
2831 &address_reloaded[i]);
2832 else if (code == REG)
2834 /* This is equivalent to calling find_reloads_toplev.
2835 The code is duplicated for speed.
2836 When we find a pseudo always equivalent to a constant,
2837 we replace it by the constant. We must be sure, however,
2838 that we don't try to replace it in the insn in which it
2839 is being set. */
2840 int regno = REGNO (recog_data.operand[i]);
2841 if (reg_equiv_constant[regno] != 0
2842 && (set == 0 || &SET_DEST (set) != recog_data.operand_loc[i]))
2844 /* Record the existing mode so that the check if constants are
2845 allowed will work when operand_mode isn't specified. */
2847 if (operand_mode[i] == VOIDmode)
2848 operand_mode[i] = GET_MODE (recog_data.operand[i]);
2850 substed_operand[i] = recog_data.operand[i]
2851 = reg_equiv_constant[regno];
2853 if (reg_equiv_memory_loc[regno] != 0
2854 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
2855 /* We need not give a valid is_set_dest argument since the case
2856 of a constant equivalence was checked above. */
2857 substed_operand[i] = recog_data.operand[i]
2858 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2859 ind_levels, 0, insn,
2860 &address_reloaded[i]);
2862 /* If the operand is still a register (we didn't replace it with an
2863 equivalent), get the preferred class to reload it into. */
2864 code = GET_CODE (recog_data.operand[i]);
2865 preferred_class[i]
2866 = ((code == REG && REGNO (recog_data.operand[i])
2867 >= FIRST_PSEUDO_REGISTER)
2868 ? reg_preferred_class (REGNO (recog_data.operand[i]))
2869 : NO_REGS);
2870 pref_or_nothing[i]
2871 = (code == REG
2872 && REGNO (recog_data.operand[i]) >= FIRST_PSEUDO_REGISTER
2873 && reg_alternate_class (REGNO (recog_data.operand[i])) == NO_REGS);
2876 /* If this is simply a copy from operand 1 to operand 0, merge the
2877 preferred classes for the operands. */
2878 if (set != 0 && noperands >= 2 && recog_data.operand[0] == SET_DEST (set)
2879 && recog_data.operand[1] == SET_SRC (set))
2881 preferred_class[0] = preferred_class[1]
2882 = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]];
2883 pref_or_nothing[0] |= pref_or_nothing[1];
2884 pref_or_nothing[1] |= pref_or_nothing[0];
2887 /* Now see what we need for pseudo-regs that didn't get hard regs
2888 or got the wrong kind of hard reg. For this, we must consider
2889 all the operands together against the register constraints. */
2891 best = MAX_RECOG_OPERANDS * 2 + 600;
2893 swapped = 0;
2894 goal_alternative_swapped = 0;
2895 try_swapped:
2897 /* The constraints are made of several alternatives.
2898 Each operand's constraint looks like foo,bar,... with commas
2899 separating the alternatives. The first alternatives for all
2900 operands go together, the second alternatives go together, etc.
2902 First loop over alternatives. */
2904 for (this_alternative_number = 0;
2905 this_alternative_number < n_alternatives;
2906 this_alternative_number++)
2908 /* Loop over operands for one constraint alternative. */
2909 /* LOSERS counts those that don't fit this alternative
2910 and would require loading. */
2911 int losers = 0;
2912 /* BAD is set to 1 if it some operand can't fit this alternative
2913 even after reloading. */
2914 int bad = 0;
2915 /* REJECT is a count of how undesirable this alternative says it is
2916 if any reloading is required. If the alternative matches exactly
2917 then REJECT is ignored, but otherwise it gets this much
2918 counted against it in addition to the reloading needed. Each
2919 ? counts three times here since we want the disparaging caused by
2920 a bad register class to only count 1/3 as much. */
2921 int reject = 0;
2923 this_earlyclobber = 0;
2925 for (i = 0; i < noperands; i++)
2927 char *p = constraints[i];
2928 char *end;
2929 int len;
2930 int win = 0;
2931 int did_match = 0;
2932 /* 0 => this operand can be reloaded somehow for this alternative. */
2933 int badop = 1;
2934 /* 0 => this operand can be reloaded if the alternative allows regs. */
2935 int winreg = 0;
2936 int c;
2937 int m;
2938 rtx operand = recog_data.operand[i];
2939 int offset = 0;
2940 /* Nonzero means this is a MEM that must be reloaded into a reg
2941 regardless of what the constraint says. */
2942 int force_reload = 0;
2943 int offmemok = 0;
2944 /* Nonzero if a constant forced into memory would be OK for this
2945 operand. */
2946 int constmemok = 0;
2947 int earlyclobber = 0;
2949 #ifndef KEEP_UNARY_OPERATORS_AT_CONSTRAINT_CHECKING
2950 /* See comment at similar #ifndef in recog.c. */
2952 /* If the predicate accepts a unary operator, it means that
2953 we need to reload the operand, but do not do this for
2954 match_operator and friends. */
2955 if (UNARY_P (operand) && *p != 0)
2956 operand = XEXP (operand, 0);
2957 #endif
2959 /* If the operand is a SUBREG, extract
2960 the REG or MEM (or maybe even a constant) within.
2961 (Constants can occur as a result of reg_equiv_constant.) */
2963 while (GET_CODE (operand) == SUBREG)
2965 /* Offset only matters when operand is a REG and
2966 it is a hard reg. This is because it is passed
2967 to reg_fits_class_p if it is a REG and all pseudos
2968 return 0 from that function. */
2969 if (REG_P (SUBREG_REG (operand))
2970 && REGNO (SUBREG_REG (operand)) < FIRST_PSEUDO_REGISTER)
2972 if (!subreg_offset_representable_p
2973 (REGNO (SUBREG_REG (operand)),
2974 GET_MODE (SUBREG_REG (operand)),
2975 SUBREG_BYTE (operand),
2976 GET_MODE (operand)))
2977 force_reload = 1;
2978 offset += subreg_regno_offset (REGNO (SUBREG_REG (operand)),
2979 GET_MODE (SUBREG_REG (operand)),
2980 SUBREG_BYTE (operand),
2981 GET_MODE (operand));
2983 operand = SUBREG_REG (operand);
2984 /* Force reload if this is a constant or PLUS or if there may
2985 be a problem accessing OPERAND in the outer mode. */
2986 if (CONSTANT_P (operand)
2987 || GET_CODE (operand) == PLUS
2988 /* We must force a reload of paradoxical SUBREGs
2989 of a MEM because the alignment of the inner value
2990 may not be enough to do the outer reference. On
2991 big-endian machines, it may also reference outside
2992 the object.
2994 On machines that extend byte operations and we have a
2995 SUBREG where both the inner and outer modes are no wider
2996 than a word and the inner mode is narrower, is integral,
2997 and gets extended when loaded from memory, combine.c has
2998 made assumptions about the behavior of the machine in such
2999 register access. If the data is, in fact, in memory we
3000 must always load using the size assumed to be in the
3001 register and let the insn do the different-sized
3002 accesses.
3004 This is doubly true if WORD_REGISTER_OPERATIONS. In
3005 this case eliminate_regs has left non-paradoxical
3006 subregs for push_reload to see. Make sure it does
3007 by forcing the reload.
3009 ??? When is it right at this stage to have a subreg
3010 of a mem that is _not_ to be handled specially? IMO
3011 those should have been reduced to just a mem. */
3012 || ((MEM_P (operand)
3013 || (REG_P (operand)
3014 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3015 #ifndef WORD_REGISTER_OPERATIONS
3016 && (((GET_MODE_BITSIZE (GET_MODE (operand))
3017 < BIGGEST_ALIGNMENT)
3018 && (GET_MODE_SIZE (operand_mode[i])
3019 > GET_MODE_SIZE (GET_MODE (operand))))
3020 || BYTES_BIG_ENDIAN
3021 #ifdef LOAD_EXTEND_OP
3022 || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3023 && (GET_MODE_SIZE (GET_MODE (operand))
3024 <= UNITS_PER_WORD)
3025 && (GET_MODE_SIZE (operand_mode[i])
3026 > GET_MODE_SIZE (GET_MODE (operand)))
3027 && INTEGRAL_MODE_P (GET_MODE (operand))
3028 && LOAD_EXTEND_OP (GET_MODE (operand)) != UNKNOWN)
3029 #endif
3031 #endif
3034 force_reload = 1;
3037 this_alternative[i] = (int) NO_REGS;
3038 this_alternative_win[i] = 0;
3039 this_alternative_match_win[i] = 0;
3040 this_alternative_offmemok[i] = 0;
3041 this_alternative_earlyclobber[i] = 0;
3042 this_alternative_matches[i] = -1;
3044 /* An empty constraint or empty alternative
3045 allows anything which matched the pattern. */
3046 if (*p == 0 || *p == ',')
3047 win = 1, badop = 0;
3049 /* Scan this alternative's specs for this operand;
3050 set WIN if the operand fits any letter in this alternative.
3051 Otherwise, clear BADOP if this operand could
3052 fit some letter after reloads,
3053 or set WINREG if this operand could fit after reloads
3054 provided the constraint allows some registers. */
3057 switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
3059 case '\0':
3060 len = 0;
3061 break;
3062 case ',':
3063 c = '\0';
3064 break;
3066 case '=': case '+': case '*':
3067 break;
3069 case '%':
3070 /* We only support one commutative marker, the first
3071 one. We already set commutative above. */
3072 break;
3074 case '?':
3075 reject += 6;
3076 break;
3078 case '!':
3079 reject = 600;
3080 break;
3082 case '#':
3083 /* Ignore rest of this alternative as far as
3084 reloading is concerned. */
3086 p++;
3087 while (*p && *p != ',');
3088 len = 0;
3089 break;
3091 case '0': case '1': case '2': case '3': case '4':
3092 case '5': case '6': case '7': case '8': case '9':
3093 m = strtoul (p, &end, 10);
3094 p = end;
3095 len = 0;
3097 this_alternative_matches[i] = m;
3098 /* We are supposed to match a previous operand.
3099 If we do, we win if that one did.
3100 If we do not, count both of the operands as losers.
3101 (This is too conservative, since most of the time
3102 only a single reload insn will be needed to make
3103 the two operands win. As a result, this alternative
3104 may be rejected when it is actually desirable.) */
3105 if ((swapped && (m != commutative || i != commutative + 1))
3106 /* If we are matching as if two operands were swapped,
3107 also pretend that operands_match had been computed
3108 with swapped.
3109 But if I is the second of those and C is the first,
3110 don't exchange them, because operands_match is valid
3111 only on one side of its diagonal. */
3112 ? (operands_match
3113 [(m == commutative || m == commutative + 1)
3114 ? 2 * commutative + 1 - m : m]
3115 [(i == commutative || i == commutative + 1)
3116 ? 2 * commutative + 1 - i : i])
3117 : operands_match[m][i])
3119 /* If we are matching a non-offsettable address where an
3120 offsettable address was expected, then we must reject
3121 this combination, because we can't reload it. */
3122 if (this_alternative_offmemok[m]
3123 && MEM_P (recog_data.operand[m])
3124 && this_alternative[m] == (int) NO_REGS
3125 && ! this_alternative_win[m])
3126 bad = 1;
3128 did_match = this_alternative_win[m];
3130 else
3132 /* Operands don't match. */
3133 rtx value;
3134 int loc1, loc2;
3135 /* Retroactively mark the operand we had to match
3136 as a loser, if it wasn't already. */
3137 if (this_alternative_win[m])
3138 losers++;
3139 this_alternative_win[m] = 0;
3140 if (this_alternative[m] == (int) NO_REGS)
3141 bad = 1;
3142 /* But count the pair only once in the total badness of
3143 this alternative, if the pair can be a dummy reload.
3144 The pointers in operand_loc are not swapped; swap
3145 them by hand if necessary. */
3146 if (swapped && i == commutative)
3147 loc1 = commutative + 1;
3148 else if (swapped && i == commutative + 1)
3149 loc1 = commutative;
3150 else
3151 loc1 = i;
3152 if (swapped && m == commutative)
3153 loc2 = commutative + 1;
3154 else if (swapped && m == commutative + 1)
3155 loc2 = commutative;
3156 else
3157 loc2 = m;
3158 value
3159 = find_dummy_reload (recog_data.operand[i],
3160 recog_data.operand[m],
3161 recog_data.operand_loc[loc1],
3162 recog_data.operand_loc[loc2],
3163 operand_mode[i], operand_mode[m],
3164 this_alternative[m], -1,
3165 this_alternative_earlyclobber[m]);
3167 if (value != 0)
3168 losers--;
3170 /* This can be fixed with reloads if the operand
3171 we are supposed to match can be fixed with reloads. */
3172 badop = 0;
3173 this_alternative[i] = this_alternative[m];
3175 /* If we have to reload this operand and some previous
3176 operand also had to match the same thing as this
3177 operand, we don't know how to do that. So reject this
3178 alternative. */
3179 if (! did_match || force_reload)
3180 for (j = 0; j < i; j++)
3181 if (this_alternative_matches[j]
3182 == this_alternative_matches[i])
3183 badop = 1;
3184 break;
3186 case 'p':
3187 /* All necessary reloads for an address_operand
3188 were handled in find_reloads_address. */
3189 this_alternative[i] = (int) MODE_BASE_REG_CLASS (VOIDmode);
3190 win = 1;
3191 badop = 0;
3192 break;
3194 case 'm':
3195 if (force_reload)
3196 break;
3197 if (MEM_P (operand)
3198 || (REG_P (operand)
3199 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3200 && reg_renumber[REGNO (operand)] < 0))
3201 win = 1;
3202 if (CONST_POOL_OK_P (operand))
3203 badop = 0;
3204 constmemok = 1;
3205 break;
3207 case '<':
3208 if (MEM_P (operand)
3209 && ! address_reloaded[i]
3210 && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
3211 || GET_CODE (XEXP (operand, 0)) == POST_DEC))
3212 win = 1;
3213 break;
3215 case '>':
3216 if (MEM_P (operand)
3217 && ! address_reloaded[i]
3218 && (GET_CODE (XEXP (operand, 0)) == PRE_INC
3219 || GET_CODE (XEXP (operand, 0)) == POST_INC))
3220 win = 1;
3221 break;
3223 /* Memory operand whose address is not offsettable. */
3224 case 'V':
3225 if (force_reload)
3226 break;
3227 if (MEM_P (operand)
3228 && ! (ind_levels ? offsettable_memref_p (operand)
3229 : offsettable_nonstrict_memref_p (operand))
3230 /* Certain mem addresses will become offsettable
3231 after they themselves are reloaded. This is important;
3232 we don't want our own handling of unoffsettables
3233 to override the handling of reg_equiv_address. */
3234 && !(REG_P (XEXP (operand, 0))
3235 && (ind_levels == 0
3236 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0)))
3237 win = 1;
3238 break;
3240 /* Memory operand whose address is offsettable. */
3241 case 'o':
3242 if (force_reload)
3243 break;
3244 if ((MEM_P (operand)
3245 /* If IND_LEVELS, find_reloads_address won't reload a
3246 pseudo that didn't get a hard reg, so we have to
3247 reject that case. */
3248 && ((ind_levels ? offsettable_memref_p (operand)
3249 : offsettable_nonstrict_memref_p (operand))
3250 /* A reloaded address is offsettable because it is now
3251 just a simple register indirect. */
3252 || address_reloaded[i] == 1))
3253 || (REG_P (operand)
3254 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3255 && reg_renumber[REGNO (operand)] < 0
3256 /* If reg_equiv_address is nonzero, we will be
3257 loading it into a register; hence it will be
3258 offsettable, but we cannot say that reg_equiv_mem
3259 is offsettable without checking. */
3260 && ((reg_equiv_mem[REGNO (operand)] != 0
3261 && offsettable_memref_p (reg_equiv_mem[REGNO (operand)]))
3262 || (reg_equiv_address[REGNO (operand)] != 0))))
3263 win = 1;
3264 if (CONST_POOL_OK_P (operand)
3265 || MEM_P (operand))
3266 badop = 0;
3267 constmemok = 1;
3268 offmemok = 1;
3269 break;
3271 case '&':
3272 /* Output operand that is stored before the need for the
3273 input operands (and their index registers) is over. */
3274 earlyclobber = 1, this_earlyclobber = 1;
3275 break;
3277 case 'E':
3278 case 'F':
3279 if (GET_CODE (operand) == CONST_DOUBLE
3280 || (GET_CODE (operand) == CONST_VECTOR
3281 && (GET_MODE_CLASS (GET_MODE (operand))
3282 == MODE_VECTOR_FLOAT)))
3283 win = 1;
3284 break;
3286 case 'G':
3287 case 'H':
3288 if (GET_CODE (operand) == CONST_DOUBLE
3289 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (operand, c, p))
3290 win = 1;
3291 break;
3293 case 's':
3294 if (GET_CODE (operand) == CONST_INT
3295 || (GET_CODE (operand) == CONST_DOUBLE
3296 && GET_MODE (operand) == VOIDmode))
3297 break;
3298 case 'i':
3299 if (CONSTANT_P (operand)
3300 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand)))
3301 win = 1;
3302 break;
3304 case 'n':
3305 if (GET_CODE (operand) == CONST_INT
3306 || (GET_CODE (operand) == CONST_DOUBLE
3307 && GET_MODE (operand) == VOIDmode))
3308 win = 1;
3309 break;
3311 case 'I':
3312 case 'J':
3313 case 'K':
3314 case 'L':
3315 case 'M':
3316 case 'N':
3317 case 'O':
3318 case 'P':
3319 if (GET_CODE (operand) == CONST_INT
3320 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (operand), c, p))
3321 win = 1;
3322 break;
3324 case 'X':
3325 win = 1;
3326 break;
3328 case 'g':
3329 if (! force_reload
3330 /* A PLUS is never a valid operand, but reload can make
3331 it from a register when eliminating registers. */
3332 && GET_CODE (operand) != PLUS
3333 /* A SCRATCH is not a valid operand. */
3334 && GET_CODE (operand) != SCRATCH
3335 && (! CONSTANT_P (operand)
3336 || ! flag_pic
3337 || LEGITIMATE_PIC_OPERAND_P (operand))
3338 && (GENERAL_REGS == ALL_REGS
3339 || !REG_P (operand)
3340 || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
3341 && reg_renumber[REGNO (operand)] < 0)))
3342 win = 1;
3343 /* Drop through into 'r' case. */
3345 case 'r':
3346 this_alternative[i]
3347 = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
3348 goto reg;
3350 default:
3351 if (REG_CLASS_FROM_CONSTRAINT (c, p) == NO_REGS)
3353 #ifdef EXTRA_CONSTRAINT_STR
3354 if (EXTRA_MEMORY_CONSTRAINT (c, p))
3356 if (force_reload)
3357 break;
3358 if (EXTRA_CONSTRAINT_STR (operand, c, p))
3359 win = 1;
3360 /* If the address was already reloaded,
3361 we win as well. */
3362 else if (MEM_P (operand)
3363 && address_reloaded[i] == 1)
3364 win = 1;
3365 /* Likewise if the address will be reloaded because
3366 reg_equiv_address is nonzero. For reg_equiv_mem
3367 we have to check. */
3368 else if (REG_P (operand)
3369 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3370 && reg_renumber[REGNO (operand)] < 0
3371 && ((reg_equiv_mem[REGNO (operand)] != 0
3372 && EXTRA_CONSTRAINT_STR (reg_equiv_mem[REGNO (operand)], c, p))
3373 || (reg_equiv_address[REGNO (operand)] != 0)))
3374 win = 1;
3376 /* If we didn't already win, we can reload
3377 constants via force_const_mem, and other
3378 MEMs by reloading the address like for 'o'. */
3379 if (CONST_POOL_OK_P (operand)
3380 || MEM_P (operand))
3381 badop = 0;
3382 constmemok = 1;
3383 offmemok = 1;
3384 break;
3386 if (EXTRA_ADDRESS_CONSTRAINT (c, p))
3388 if (EXTRA_CONSTRAINT_STR (operand, c, p))
3389 win = 1;
3391 /* If we didn't already win, we can reload
3392 the address into a base register. */
3393 this_alternative[i] = (int) MODE_BASE_REG_CLASS (VOIDmode);
3394 badop = 0;
3395 break;
3398 if (EXTRA_CONSTRAINT_STR (operand, c, p))
3399 win = 1;
3400 #endif
3401 break;
3404 this_alternative[i]
3405 = (int) (reg_class_subunion
3406 [this_alternative[i]]
3407 [(int) REG_CLASS_FROM_CONSTRAINT (c, p)]);
3408 reg:
3409 if (GET_MODE (operand) == BLKmode)
3410 break;
3411 winreg = 1;
3412 if (REG_P (operand)
3413 && reg_fits_class_p (operand, this_alternative[i],
3414 offset, GET_MODE (recog_data.operand[i])))
3415 win = 1;
3416 break;
3418 while ((p += len), c);
3420 constraints[i] = p;
3422 /* If this operand could be handled with a reg,
3423 and some reg is allowed, then this operand can be handled. */
3424 if (winreg && this_alternative[i] != (int) NO_REGS)
3425 badop = 0;
3427 /* Record which operands fit this alternative. */
3428 this_alternative_earlyclobber[i] = earlyclobber;
3429 if (win && ! force_reload)
3430 this_alternative_win[i] = 1;
3431 else if (did_match && ! force_reload)
3432 this_alternative_match_win[i] = 1;
3433 else
3435 int const_to_mem = 0;
3437 this_alternative_offmemok[i] = offmemok;
3438 losers++;
3439 if (badop)
3440 bad = 1;
3441 /* Alternative loses if it has no regs for a reg operand. */
3442 if (REG_P (operand)
3443 && this_alternative[i] == (int) NO_REGS
3444 && this_alternative_matches[i] < 0)
3445 bad = 1;
3447 /* If this is a constant that is reloaded into the desired
3448 class by copying it to memory first, count that as another
3449 reload. This is consistent with other code and is
3450 required to avoid choosing another alternative when
3451 the constant is moved into memory by this function on
3452 an early reload pass. Note that the test here is
3453 precisely the same as in the code below that calls
3454 force_const_mem. */
3455 if (CONST_POOL_OK_P (operand)
3456 && ((PREFERRED_RELOAD_CLASS (operand,
3457 (enum reg_class) this_alternative[i])
3458 == NO_REGS)
3459 || no_input_reloads)
3460 && operand_mode[i] != VOIDmode)
3462 const_to_mem = 1;
3463 if (this_alternative[i] != (int) NO_REGS)
3464 losers++;
3467 /* If we can't reload this value at all, reject this
3468 alternative. Note that we could also lose due to
3469 LIMIT_RELOAD_RELOAD_CLASS, but we don't check that
3470 here. */
3472 if (! CONSTANT_P (operand)
3473 && (enum reg_class) this_alternative[i] != NO_REGS
3474 && (PREFERRED_RELOAD_CLASS (operand,
3475 (enum reg_class) this_alternative[i])
3476 == NO_REGS))
3477 bad = 1;
3479 /* Alternative loses if it requires a type of reload not
3480 permitted for this insn. We can always reload SCRATCH
3481 and objects with a REG_UNUSED note. */
3482 else if (GET_CODE (operand) != SCRATCH
3483 && modified[i] != RELOAD_READ && no_output_reloads
3484 && ! find_reg_note (insn, REG_UNUSED, operand))
3485 bad = 1;
3486 else if (modified[i] != RELOAD_WRITE && no_input_reloads
3487 && ! const_to_mem)
3488 bad = 1;
3490 /* We prefer to reload pseudos over reloading other things,
3491 since such reloads may be able to be eliminated later.
3492 If we are reloading a SCRATCH, we won't be generating any
3493 insns, just using a register, so it is also preferred.
3494 So bump REJECT in other cases. Don't do this in the
3495 case where we are forcing a constant into memory and
3496 it will then win since we don't want to have a different
3497 alternative match then. */
3498 if (! (REG_P (operand)
3499 && REGNO (operand) >= FIRST_PSEUDO_REGISTER)
3500 && GET_CODE (operand) != SCRATCH
3501 && ! (const_to_mem && constmemok))
3502 reject += 2;
3504 /* Input reloads can be inherited more often than output
3505 reloads can be removed, so penalize output reloads. */
3506 if (operand_type[i] != RELOAD_FOR_INPUT
3507 && GET_CODE (operand) != SCRATCH)
3508 reject++;
3511 /* If this operand is a pseudo register that didn't get a hard
3512 reg and this alternative accepts some register, see if the
3513 class that we want is a subset of the preferred class for this
3514 register. If not, but it intersects that class, use the
3515 preferred class instead. If it does not intersect the preferred
3516 class, show that usage of this alternative should be discouraged;
3517 it will be discouraged more still if the register is `preferred
3518 or nothing'. We do this because it increases the chance of
3519 reusing our spill register in a later insn and avoiding a pair
3520 of memory stores and loads.
3522 Don't bother with this if this alternative will accept this
3523 operand.
3525 Don't do this for a multiword operand, since it is only a
3526 small win and has the risk of requiring more spill registers,
3527 which could cause a large loss.
3529 Don't do this if the preferred class has only one register
3530 because we might otherwise exhaust the class. */
3532 if (! win && ! did_match
3533 && this_alternative[i] != (int) NO_REGS
3534 && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3535 && reg_class_size [(int) preferred_class[i]] > 0
3536 && ! SMALL_REGISTER_CLASS_P (preferred_class[i]))
3538 if (! reg_class_subset_p (this_alternative[i],
3539 preferred_class[i]))
3541 /* Since we don't have a way of forming the intersection,
3542 we just do something special if the preferred class
3543 is a subset of the class we have; that's the most
3544 common case anyway. */
3545 if (reg_class_subset_p (preferred_class[i],
3546 this_alternative[i]))
3547 this_alternative[i] = (int) preferred_class[i];
3548 else
3549 reject += (2 + 2 * pref_or_nothing[i]);
3554 /* Now see if any output operands that are marked "earlyclobber"
3555 in this alternative conflict with any input operands
3556 or any memory addresses. */
3558 for (i = 0; i < noperands; i++)
3559 if (this_alternative_earlyclobber[i]
3560 && (this_alternative_win[i] || this_alternative_match_win[i]))
3562 struct decomposition early_data;
3564 early_data = decompose (recog_data.operand[i]);
3566 gcc_assert (modified[i] != RELOAD_READ);
3568 if (this_alternative[i] == NO_REGS)
3570 this_alternative_earlyclobber[i] = 0;
3571 gcc_assert (this_insn_is_asm);
3572 error_for_asm (this_insn,
3573 "%<&%> constraint used with no register class");
3576 for (j = 0; j < noperands; j++)
3577 /* Is this an input operand or a memory ref? */
3578 if ((MEM_P (recog_data.operand[j])
3579 || modified[j] != RELOAD_WRITE)
3580 && j != i
3581 /* Ignore things like match_operator operands. */
3582 && *recog_data.constraints[j] != 0
3583 /* Don't count an input operand that is constrained to match
3584 the early clobber operand. */
3585 && ! (this_alternative_matches[j] == i
3586 && rtx_equal_p (recog_data.operand[i],
3587 recog_data.operand[j]))
3588 /* Is it altered by storing the earlyclobber operand? */
3589 && !immune_p (recog_data.operand[j], recog_data.operand[i],
3590 early_data))
3592 /* If the output is in a non-empty few-regs class,
3593 it's costly to reload it, so reload the input instead. */
3594 if (SMALL_REGISTER_CLASS_P (this_alternative[i])
3595 && (REG_P (recog_data.operand[j])
3596 || GET_CODE (recog_data.operand[j]) == SUBREG))
3598 losers++;
3599 this_alternative_win[j] = 0;
3600 this_alternative_match_win[j] = 0;
3602 else
3603 break;
3605 /* If an earlyclobber operand conflicts with something,
3606 it must be reloaded, so request this and count the cost. */
3607 if (j != noperands)
3609 losers++;
3610 this_alternative_win[i] = 0;
3611 this_alternative_match_win[j] = 0;
3612 for (j = 0; j < noperands; j++)
3613 if (this_alternative_matches[j] == i
3614 && this_alternative_match_win[j])
3616 this_alternative_win[j] = 0;
3617 this_alternative_match_win[j] = 0;
3618 losers++;
3623 /* If one alternative accepts all the operands, no reload required,
3624 choose that alternative; don't consider the remaining ones. */
3625 if (losers == 0)
3627 /* Unswap these so that they are never swapped at `finish'. */
3628 if (commutative >= 0)
3630 recog_data.operand[commutative] = substed_operand[commutative];
3631 recog_data.operand[commutative + 1]
3632 = substed_operand[commutative + 1];
3634 for (i = 0; i < noperands; i++)
3636 goal_alternative_win[i] = this_alternative_win[i];
3637 goal_alternative_match_win[i] = this_alternative_match_win[i];
3638 goal_alternative[i] = this_alternative[i];
3639 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3640 goal_alternative_matches[i] = this_alternative_matches[i];
3641 goal_alternative_earlyclobber[i]
3642 = this_alternative_earlyclobber[i];
3644 goal_alternative_number = this_alternative_number;
3645 goal_alternative_swapped = swapped;
3646 goal_earlyclobber = this_earlyclobber;
3647 goto finish;
3650 /* REJECT, set by the ! and ? constraint characters and when a register
3651 would be reloaded into a non-preferred class, discourages the use of
3652 this alternative for a reload goal. REJECT is incremented by six
3653 for each ? and two for each non-preferred class. */
3654 losers = losers * 6 + reject;
3656 /* If this alternative can be made to work by reloading,
3657 and it needs less reloading than the others checked so far,
3658 record it as the chosen goal for reloading. */
3659 if (! bad && best > losers)
3661 for (i = 0; i < noperands; i++)
3663 goal_alternative[i] = this_alternative[i];
3664 goal_alternative_win[i] = this_alternative_win[i];
3665 goal_alternative_match_win[i] = this_alternative_match_win[i];
3666 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3667 goal_alternative_matches[i] = this_alternative_matches[i];
3668 goal_alternative_earlyclobber[i]
3669 = this_alternative_earlyclobber[i];
3671 goal_alternative_swapped = swapped;
3672 best = losers;
3673 goal_alternative_number = this_alternative_number;
3674 goal_earlyclobber = this_earlyclobber;
3678 /* If insn is commutative (it's safe to exchange a certain pair of operands)
3679 then we need to try each alternative twice,
3680 the second time matching those two operands
3681 as if we had exchanged them.
3682 To do this, really exchange them in operands.
3684 If we have just tried the alternatives the second time,
3685 return operands to normal and drop through. */
3687 if (commutative >= 0)
3689 swapped = !swapped;
3690 if (swapped)
3692 enum reg_class tclass;
3693 int t;
3695 recog_data.operand[commutative] = substed_operand[commutative + 1];
3696 recog_data.operand[commutative + 1] = substed_operand[commutative];
3697 /* Swap the duplicates too. */
3698 for (i = 0; i < recog_data.n_dups; i++)
3699 if (recog_data.dup_num[i] == commutative
3700 || recog_data.dup_num[i] == commutative + 1)
3701 *recog_data.dup_loc[i]
3702 = recog_data.operand[(int) recog_data.dup_num[i]];
3704 tclass = preferred_class[commutative];
3705 preferred_class[commutative] = preferred_class[commutative + 1];
3706 preferred_class[commutative + 1] = tclass;
3708 t = pref_or_nothing[commutative];
3709 pref_or_nothing[commutative] = pref_or_nothing[commutative + 1];
3710 pref_or_nothing[commutative + 1] = t;
3712 t = address_reloaded[commutative];
3713 address_reloaded[commutative] = address_reloaded[commutative + 1];
3714 address_reloaded[commutative + 1] = t;
3716 memcpy (constraints, recog_data.constraints,
3717 noperands * sizeof (char *));
3718 goto try_swapped;
3720 else
3722 recog_data.operand[commutative] = substed_operand[commutative];
3723 recog_data.operand[commutative + 1]
3724 = substed_operand[commutative + 1];
3725 /* Unswap the duplicates too. */
3726 for (i = 0; i < recog_data.n_dups; i++)
3727 if (recog_data.dup_num[i] == commutative
3728 || recog_data.dup_num[i] == commutative + 1)
3729 *recog_data.dup_loc[i]
3730 = recog_data.operand[(int) recog_data.dup_num[i]];
3734 /* The operands don't meet the constraints.
3735 goal_alternative describes the alternative
3736 that we could reach by reloading the fewest operands.
3737 Reload so as to fit it. */
3739 if (best == MAX_RECOG_OPERANDS * 2 + 600)
3741 /* No alternative works with reloads?? */
3742 if (insn_code_number >= 0)
3743 fatal_insn ("unable to generate reloads for:", insn);
3744 error_for_asm (insn, "inconsistent operand constraints in an %<asm%>");
3745 /* Avoid further trouble with this insn. */
3746 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3747 n_reloads = 0;
3748 return 0;
3751 /* Jump to `finish' from above if all operands are valid already.
3752 In that case, goal_alternative_win is all 1. */
3753 finish:
3755 /* Right now, for any pair of operands I and J that are required to match,
3756 with I < J,
3757 goal_alternative_matches[J] is I.
3758 Set up goal_alternative_matched as the inverse function:
3759 goal_alternative_matched[I] = J. */
3761 for (i = 0; i < noperands; i++)
3762 goal_alternative_matched[i] = -1;
3764 for (i = 0; i < noperands; i++)
3765 if (! goal_alternative_win[i]
3766 && goal_alternative_matches[i] >= 0)
3767 goal_alternative_matched[goal_alternative_matches[i]] = i;
3769 for (i = 0; i < noperands; i++)
3770 goal_alternative_win[i] |= goal_alternative_match_win[i];
3772 /* If the best alternative is with operands 1 and 2 swapped,
3773 consider them swapped before reporting the reloads. Update the
3774 operand numbers of any reloads already pushed. */
3776 if (goal_alternative_swapped)
3778 rtx tem;
3780 tem = substed_operand[commutative];
3781 substed_operand[commutative] = substed_operand[commutative + 1];
3782 substed_operand[commutative + 1] = tem;
3783 tem = recog_data.operand[commutative];
3784 recog_data.operand[commutative] = recog_data.operand[commutative + 1];
3785 recog_data.operand[commutative + 1] = tem;
3786 tem = *recog_data.operand_loc[commutative];
3787 *recog_data.operand_loc[commutative]
3788 = *recog_data.operand_loc[commutative + 1];
3789 *recog_data.operand_loc[commutative + 1] = tem;
3791 for (i = 0; i < n_reloads; i++)
3793 if (rld[i].opnum == commutative)
3794 rld[i].opnum = commutative + 1;
3795 else if (rld[i].opnum == commutative + 1)
3796 rld[i].opnum = commutative;
3800 for (i = 0; i < noperands; i++)
3802 operand_reloadnum[i] = -1;
3804 /* If this is an earlyclobber operand, we need to widen the scope.
3805 The reload must remain valid from the start of the insn being
3806 reloaded until after the operand is stored into its destination.
3807 We approximate this with RELOAD_OTHER even though we know that we
3808 do not conflict with RELOAD_FOR_INPUT_ADDRESS reloads.
3810 One special case that is worth checking is when we have an
3811 output that is earlyclobber but isn't used past the insn (typically
3812 a SCRATCH). In this case, we only need have the reload live
3813 through the insn itself, but not for any of our input or output
3814 reloads.
3815 But we must not accidentally narrow the scope of an existing
3816 RELOAD_OTHER reload - leave these alone.
3818 In any case, anything needed to address this operand can remain
3819 however they were previously categorized. */
3821 if (goal_alternative_earlyclobber[i] && operand_type[i] != RELOAD_OTHER)
3822 operand_type[i]
3823 = (find_reg_note (insn, REG_UNUSED, recog_data.operand[i])
3824 ? RELOAD_FOR_INSN : RELOAD_OTHER);
3827 /* Any constants that aren't allowed and can't be reloaded
3828 into registers are here changed into memory references. */
3829 for (i = 0; i < noperands; i++)
3830 if (! goal_alternative_win[i]
3831 && CONST_POOL_OK_P (recog_data.operand[i])
3832 && ((PREFERRED_RELOAD_CLASS (recog_data.operand[i],
3833 (enum reg_class) goal_alternative[i])
3834 == NO_REGS)
3835 || no_input_reloads)
3836 && operand_mode[i] != VOIDmode)
3838 substed_operand[i] = recog_data.operand[i]
3839 = find_reloads_toplev (force_const_mem (operand_mode[i],
3840 recog_data.operand[i]),
3841 i, address_type[i], ind_levels, 0, insn,
3842 NULL);
3843 if (alternative_allows_memconst (recog_data.constraints[i],
3844 goal_alternative_number))
3845 goal_alternative_win[i] = 1;
3848 /* Likewise any invalid constants appearing as operand of a PLUS
3849 that is to be reloaded. */
3850 for (i = 0; i < noperands; i++)
3851 if (! goal_alternative_win[i]
3852 && GET_CODE (recog_data.operand[i]) == PLUS
3853 && CONST_POOL_OK_P (XEXP (recog_data.operand[i], 1))
3854 && (PREFERRED_RELOAD_CLASS (XEXP (recog_data.operand[i], 1),
3855 (enum reg_class) goal_alternative[i])
3856 == NO_REGS)
3857 && operand_mode[i] != VOIDmode)
3859 rtx tem = force_const_mem (operand_mode[i],
3860 XEXP (recog_data.operand[i], 1));
3861 tem = gen_rtx_PLUS (operand_mode[i],
3862 XEXP (recog_data.operand[i], 0), tem);
3864 substed_operand[i] = recog_data.operand[i]
3865 = find_reloads_toplev (tem, i, address_type[i],
3866 ind_levels, 0, insn, NULL);
3869 /* Record the values of the earlyclobber operands for the caller. */
3870 if (goal_earlyclobber)
3871 for (i = 0; i < noperands; i++)
3872 if (goal_alternative_earlyclobber[i])
3873 reload_earlyclobbers[n_earlyclobbers++] = recog_data.operand[i];
3875 /* Now record reloads for all the operands that need them. */
3876 for (i = 0; i < noperands; i++)
3877 if (! goal_alternative_win[i])
3879 /* Operands that match previous ones have already been handled. */
3880 if (goal_alternative_matches[i] >= 0)
3882 /* Handle an operand with a nonoffsettable address
3883 appearing where an offsettable address will do
3884 by reloading the address into a base register.
3886 ??? We can also do this when the operand is a register and
3887 reg_equiv_mem is not offsettable, but this is a bit tricky,
3888 so we don't bother with it. It may not be worth doing. */
3889 else if (goal_alternative_matched[i] == -1
3890 && goal_alternative_offmemok[i]
3891 && MEM_P (recog_data.operand[i]))
3893 operand_reloadnum[i]
3894 = push_reload (XEXP (recog_data.operand[i], 0), NULL_RTX,
3895 &XEXP (recog_data.operand[i], 0), (rtx*) 0,
3896 MODE_BASE_REG_CLASS (VOIDmode),
3897 GET_MODE (XEXP (recog_data.operand[i], 0)),
3898 VOIDmode, 0, 0, i, RELOAD_FOR_INPUT);
3899 rld[operand_reloadnum[i]].inc
3900 = GET_MODE_SIZE (GET_MODE (recog_data.operand[i]));
3902 /* If this operand is an output, we will have made any
3903 reloads for its address as RELOAD_FOR_OUTPUT_ADDRESS, but
3904 now we are treating part of the operand as an input, so
3905 we must change these to RELOAD_FOR_INPUT_ADDRESS. */
3907 if (modified[i] == RELOAD_WRITE)
3909 for (j = 0; j < n_reloads; j++)
3911 if (rld[j].opnum == i)
3913 if (rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS)
3914 rld[j].when_needed = RELOAD_FOR_INPUT_ADDRESS;
3915 else if (rld[j].when_needed
3916 == RELOAD_FOR_OUTADDR_ADDRESS)
3917 rld[j].when_needed = RELOAD_FOR_INPADDR_ADDRESS;
3922 else if (goal_alternative_matched[i] == -1)
3924 operand_reloadnum[i]
3925 = push_reload ((modified[i] != RELOAD_WRITE
3926 ? recog_data.operand[i] : 0),
3927 (modified[i] != RELOAD_READ
3928 ? recog_data.operand[i] : 0),
3929 (modified[i] != RELOAD_WRITE
3930 ? recog_data.operand_loc[i] : 0),
3931 (modified[i] != RELOAD_READ
3932 ? recog_data.operand_loc[i] : 0),
3933 (enum reg_class) goal_alternative[i],
3934 (modified[i] == RELOAD_WRITE
3935 ? VOIDmode : operand_mode[i]),
3936 (modified[i] == RELOAD_READ
3937 ? VOIDmode : operand_mode[i]),
3938 (insn_code_number < 0 ? 0
3939 : insn_data[insn_code_number].operand[i].strict_low),
3940 0, i, operand_type[i]);
3942 /* In a matching pair of operands, one must be input only
3943 and the other must be output only.
3944 Pass the input operand as IN and the other as OUT. */
3945 else if (modified[i] == RELOAD_READ
3946 && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
3948 operand_reloadnum[i]
3949 = push_reload (recog_data.operand[i],
3950 recog_data.operand[goal_alternative_matched[i]],
3951 recog_data.operand_loc[i],
3952 recog_data.operand_loc[goal_alternative_matched[i]],
3953 (enum reg_class) goal_alternative[i],
3954 operand_mode[i],
3955 operand_mode[goal_alternative_matched[i]],
3956 0, 0, i, RELOAD_OTHER);
3957 operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
3959 else if (modified[i] == RELOAD_WRITE
3960 && modified[goal_alternative_matched[i]] == RELOAD_READ)
3962 operand_reloadnum[goal_alternative_matched[i]]
3963 = push_reload (recog_data.operand[goal_alternative_matched[i]],
3964 recog_data.operand[i],
3965 recog_data.operand_loc[goal_alternative_matched[i]],
3966 recog_data.operand_loc[i],
3967 (enum reg_class) goal_alternative[i],
3968 operand_mode[goal_alternative_matched[i]],
3969 operand_mode[i],
3970 0, 0, i, RELOAD_OTHER);
3971 operand_reloadnum[i] = output_reloadnum;
3973 else
3975 gcc_assert (insn_code_number < 0);
3976 error_for_asm (insn, "inconsistent operand constraints "
3977 "in an %<asm%>");
3978 /* Avoid further trouble with this insn. */
3979 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3980 n_reloads = 0;
3981 return 0;
3984 else if (goal_alternative_matched[i] < 0
3985 && goal_alternative_matches[i] < 0
3986 && address_operand_reloaded[i] != 1
3987 && optimize)
3989 /* For each non-matching operand that's a MEM or a pseudo-register
3990 that didn't get a hard register, make an optional reload.
3991 This may get done even if the insn needs no reloads otherwise. */
3993 rtx operand = recog_data.operand[i];
3995 while (GET_CODE (operand) == SUBREG)
3996 operand = SUBREG_REG (operand);
3997 if ((MEM_P (operand)
3998 || (REG_P (operand)
3999 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
4000 /* If this is only for an output, the optional reload would not
4001 actually cause us to use a register now, just note that
4002 something is stored here. */
4003 && ((enum reg_class) goal_alternative[i] != NO_REGS
4004 || modified[i] == RELOAD_WRITE)
4005 && ! no_input_reloads
4006 /* An optional output reload might allow to delete INSN later.
4007 We mustn't make in-out reloads on insns that are not permitted
4008 output reloads.
4009 If this is an asm, we can't delete it; we must not even call
4010 push_reload for an optional output reload in this case,
4011 because we can't be sure that the constraint allows a register,
4012 and push_reload verifies the constraints for asms. */
4013 && (modified[i] == RELOAD_READ
4014 || (! no_output_reloads && ! this_insn_is_asm)))
4015 operand_reloadnum[i]
4016 = push_reload ((modified[i] != RELOAD_WRITE
4017 ? recog_data.operand[i] : 0),
4018 (modified[i] != RELOAD_READ
4019 ? recog_data.operand[i] : 0),
4020 (modified[i] != RELOAD_WRITE
4021 ? recog_data.operand_loc[i] : 0),
4022 (modified[i] != RELOAD_READ
4023 ? recog_data.operand_loc[i] : 0),
4024 (enum reg_class) goal_alternative[i],
4025 (modified[i] == RELOAD_WRITE
4026 ? VOIDmode : operand_mode[i]),
4027 (modified[i] == RELOAD_READ
4028 ? VOIDmode : operand_mode[i]),
4029 (insn_code_number < 0 ? 0
4030 : insn_data[insn_code_number].operand[i].strict_low),
4031 1, i, operand_type[i]);
4032 /* If a memory reference remains (either as a MEM or a pseudo that
4033 did not get a hard register), yet we can't make an optional
4034 reload, check if this is actually a pseudo register reference;
4035 we then need to emit a USE and/or a CLOBBER so that reload
4036 inheritance will do the right thing. */
4037 else if (replace
4038 && (MEM_P (operand)
4039 || (REG_P (operand)
4040 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
4041 && reg_renumber [REGNO (operand)] < 0)))
4043 operand = *recog_data.operand_loc[i];
4045 while (GET_CODE (operand) == SUBREG)
4046 operand = SUBREG_REG (operand);
4047 if (REG_P (operand))
4049 if (modified[i] != RELOAD_WRITE)
4050 /* We mark the USE with QImode so that we recognize
4051 it as one that can be safely deleted at the end
4052 of reload. */
4053 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, operand),
4054 insn), QImode);
4055 if (modified[i] != RELOAD_READ)
4056 emit_insn_after (gen_rtx_CLOBBER (VOIDmode, operand), insn);
4060 else if (goal_alternative_matches[i] >= 0
4061 && goal_alternative_win[goal_alternative_matches[i]]
4062 && modified[i] == RELOAD_READ
4063 && modified[goal_alternative_matches[i]] == RELOAD_WRITE
4064 && ! no_input_reloads && ! no_output_reloads
4065 && optimize)
4067 /* Similarly, make an optional reload for a pair of matching
4068 objects that are in MEM or a pseudo that didn't get a hard reg. */
4070 rtx operand = recog_data.operand[i];
4072 while (GET_CODE (operand) == SUBREG)
4073 operand = SUBREG_REG (operand);
4074 if ((MEM_P (operand)
4075 || (REG_P (operand)
4076 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
4077 && ((enum reg_class) goal_alternative[goal_alternative_matches[i]]
4078 != NO_REGS))
4079 operand_reloadnum[i] = operand_reloadnum[goal_alternative_matches[i]]
4080 = push_reload (recog_data.operand[goal_alternative_matches[i]],
4081 recog_data.operand[i],
4082 recog_data.operand_loc[goal_alternative_matches[i]],
4083 recog_data.operand_loc[i],
4084 (enum reg_class) goal_alternative[goal_alternative_matches[i]],
4085 operand_mode[goal_alternative_matches[i]],
4086 operand_mode[i],
4087 0, 1, goal_alternative_matches[i], RELOAD_OTHER);
4090 /* Perform whatever substitutions on the operands we are supposed
4091 to make due to commutativity or replacement of registers
4092 with equivalent constants or memory slots. */
4094 for (i = 0; i < noperands; i++)
4096 /* We only do this on the last pass through reload, because it is
4097 possible for some data (like reg_equiv_address) to be changed during
4098 later passes. Moreover, we loose the opportunity to get a useful
4099 reload_{in,out}_reg when we do these replacements. */
4101 if (replace)
4103 rtx substitution = substed_operand[i];
4105 *recog_data.operand_loc[i] = substitution;
4107 /* If we're replacing an operand with a LABEL_REF, we need
4108 to make sure that there's a REG_LABEL note attached to
4109 this instruction. */
4110 if (!JUMP_P (insn)
4111 && GET_CODE (substitution) == LABEL_REF
4112 && !find_reg_note (insn, REG_LABEL, XEXP (substitution, 0)))
4113 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL,
4114 XEXP (substitution, 0),
4115 REG_NOTES (insn));
4117 else
4118 retval |= (substed_operand[i] != *recog_data.operand_loc[i]);
4121 /* If this insn pattern contains any MATCH_DUP's, make sure that
4122 they will be substituted if the operands they match are substituted.
4123 Also do now any substitutions we already did on the operands.
4125 Don't do this if we aren't making replacements because we might be
4126 propagating things allocated by frame pointer elimination into places
4127 it doesn't expect. */
4129 if (insn_code_number >= 0 && replace)
4130 for (i = insn_data[insn_code_number].n_dups - 1; i >= 0; i--)
4132 int opno = recog_data.dup_num[i];
4133 *recog_data.dup_loc[i] = *recog_data.operand_loc[opno];
4134 dup_replacements (recog_data.dup_loc[i], recog_data.operand_loc[opno]);
4137 #if 0
4138 /* This loses because reloading of prior insns can invalidate the equivalence
4139 (or at least find_equiv_reg isn't smart enough to find it any more),
4140 causing this insn to need more reload regs than it needed before.
4141 It may be too late to make the reload regs available.
4142 Now this optimization is done safely in choose_reload_regs. */
4144 /* For each reload of a reg into some other class of reg,
4145 search for an existing equivalent reg (same value now) in the right class.
4146 We can use it as long as we don't need to change its contents. */
4147 for (i = 0; i < n_reloads; i++)
4148 if (rld[i].reg_rtx == 0
4149 && rld[i].in != 0
4150 && REG_P (rld[i].in)
4151 && rld[i].out == 0)
4153 rld[i].reg_rtx
4154 = find_equiv_reg (rld[i].in, insn, rld[i].class, -1,
4155 static_reload_reg_p, 0, rld[i].inmode);
4156 /* Prevent generation of insn to load the value
4157 because the one we found already has the value. */
4158 if (rld[i].reg_rtx)
4159 rld[i].in = rld[i].reg_rtx;
4161 #endif
4163 /* Perhaps an output reload can be combined with another
4164 to reduce needs by one. */
4165 if (!goal_earlyclobber)
4166 combine_reloads ();
4168 /* If we have a pair of reloads for parts of an address, they are reloading
4169 the same object, the operands themselves were not reloaded, and they
4170 are for two operands that are supposed to match, merge the reloads and
4171 change the type of the surviving reload to RELOAD_FOR_OPERAND_ADDRESS. */
4173 for (i = 0; i < n_reloads; i++)
4175 int k;
4177 for (j = i + 1; j < n_reloads; j++)
4178 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4179 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4180 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4181 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4182 && (rld[j].when_needed == RELOAD_FOR_INPUT_ADDRESS
4183 || rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4184 || rld[j].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4185 || rld[j].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4186 && rtx_equal_p (rld[i].in, rld[j].in)
4187 && (operand_reloadnum[rld[i].opnum] < 0
4188 || rld[operand_reloadnum[rld[i].opnum]].optional)
4189 && (operand_reloadnum[rld[j].opnum] < 0
4190 || rld[operand_reloadnum[rld[j].opnum]].optional)
4191 && (goal_alternative_matches[rld[i].opnum] == rld[j].opnum
4192 || (goal_alternative_matches[rld[j].opnum]
4193 == rld[i].opnum)))
4195 for (k = 0; k < n_replacements; k++)
4196 if (replacements[k].what == j)
4197 replacements[k].what = i;
4199 if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4200 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4201 rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
4202 else
4203 rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
4204 rld[j].in = 0;
4208 /* Scan all the reloads and update their type.
4209 If a reload is for the address of an operand and we didn't reload
4210 that operand, change the type. Similarly, change the operand number
4211 of a reload when two operands match. If a reload is optional, treat it
4212 as though the operand isn't reloaded.
4214 ??? This latter case is somewhat odd because if we do the optional
4215 reload, it means the object is hanging around. Thus we need only
4216 do the address reload if the optional reload was NOT done.
4218 Change secondary reloads to be the address type of their operand, not
4219 the normal type.
4221 If an operand's reload is now RELOAD_OTHER, change any
4222 RELOAD_FOR_INPUT_ADDRESS reloads of that operand to
4223 RELOAD_FOR_OTHER_ADDRESS. */
4225 for (i = 0; i < n_reloads; i++)
4227 if (rld[i].secondary_p
4228 && rld[i].when_needed == operand_type[rld[i].opnum])
4229 rld[i].when_needed = address_type[rld[i].opnum];
4231 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4232 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4233 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4234 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4235 && (operand_reloadnum[rld[i].opnum] < 0
4236 || rld[operand_reloadnum[rld[i].opnum]].optional))
4238 /* If we have a secondary reload to go along with this reload,
4239 change its type to RELOAD_FOR_OPADDR_ADDR. */
4241 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4242 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
4243 && rld[i].secondary_in_reload != -1)
4245 int secondary_in_reload = rld[i].secondary_in_reload;
4247 rld[secondary_in_reload].when_needed = RELOAD_FOR_OPADDR_ADDR;
4249 /* If there's a tertiary reload we have to change it also. */
4250 if (secondary_in_reload > 0
4251 && rld[secondary_in_reload].secondary_in_reload != -1)
4252 rld[rld[secondary_in_reload].secondary_in_reload].when_needed
4253 = RELOAD_FOR_OPADDR_ADDR;
4256 if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4257 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4258 && rld[i].secondary_out_reload != -1)
4260 int secondary_out_reload = rld[i].secondary_out_reload;
4262 rld[secondary_out_reload].when_needed = RELOAD_FOR_OPADDR_ADDR;
4264 /* If there's a tertiary reload we have to change it also. */
4265 if (secondary_out_reload
4266 && rld[secondary_out_reload].secondary_out_reload != -1)
4267 rld[rld[secondary_out_reload].secondary_out_reload].when_needed
4268 = RELOAD_FOR_OPADDR_ADDR;
4271 if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4272 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4273 rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
4274 else
4275 rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
4278 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4279 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
4280 && operand_reloadnum[rld[i].opnum] >= 0
4281 && (rld[operand_reloadnum[rld[i].opnum]].when_needed
4282 == RELOAD_OTHER))
4283 rld[i].when_needed = RELOAD_FOR_OTHER_ADDRESS;
4285 if (goal_alternative_matches[rld[i].opnum] >= 0)
4286 rld[i].opnum = goal_alternative_matches[rld[i].opnum];
4289 /* Scan all the reloads, and check for RELOAD_FOR_OPERAND_ADDRESS reloads.
4290 If we have more than one, then convert all RELOAD_FOR_OPADDR_ADDR
4291 reloads to RELOAD_FOR_OPERAND_ADDRESS reloads.
4293 choose_reload_regs assumes that RELOAD_FOR_OPADDR_ADDR reloads never
4294 conflict with RELOAD_FOR_OPERAND_ADDRESS reloads. This is true for a
4295 single pair of RELOAD_FOR_OPADDR_ADDR/RELOAD_FOR_OPERAND_ADDRESS reloads.
4296 However, if there is more than one RELOAD_FOR_OPERAND_ADDRESS reload,
4297 then a RELOAD_FOR_OPADDR_ADDR reload conflicts with all
4298 RELOAD_FOR_OPERAND_ADDRESS reloads other than the one that uses it.
4299 This is complicated by the fact that a single operand can have more
4300 than one RELOAD_FOR_OPERAND_ADDRESS reload. It is very difficult to fix
4301 choose_reload_regs without affecting code quality, and cases that
4302 actually fail are extremely rare, so it turns out to be better to fix
4303 the problem here by not generating cases that choose_reload_regs will
4304 fail for. */
4305 /* There is a similar problem with RELOAD_FOR_INPUT_ADDRESS /
4306 RELOAD_FOR_OUTPUT_ADDRESS when there is more than one of a kind for
4307 a single operand.
4308 We can reduce the register pressure by exploiting that a
4309 RELOAD_FOR_X_ADDR_ADDR that precedes all RELOAD_FOR_X_ADDRESS reloads
4310 does not conflict with any of them, if it is only used for the first of
4311 the RELOAD_FOR_X_ADDRESS reloads. */
4313 int first_op_addr_num = -2;
4314 int first_inpaddr_num[MAX_RECOG_OPERANDS];
4315 int first_outpaddr_num[MAX_RECOG_OPERANDS];
4316 int need_change = 0;
4317 /* We use last_op_addr_reload and the contents of the above arrays
4318 first as flags - -2 means no instance encountered, -1 means exactly
4319 one instance encountered.
4320 If more than one instance has been encountered, we store the reload
4321 number of the first reload of the kind in question; reload numbers
4322 are known to be non-negative. */
4323 for (i = 0; i < noperands; i++)
4324 first_inpaddr_num[i] = first_outpaddr_num[i] = -2;
4325 for (i = n_reloads - 1; i >= 0; i--)
4327 switch (rld[i].when_needed)
4329 case RELOAD_FOR_OPERAND_ADDRESS:
4330 if (++first_op_addr_num >= 0)
4332 first_op_addr_num = i;
4333 need_change = 1;
4335 break;
4336 case RELOAD_FOR_INPUT_ADDRESS:
4337 if (++first_inpaddr_num[rld[i].opnum] >= 0)
4339 first_inpaddr_num[rld[i].opnum] = i;
4340 need_change = 1;
4342 break;
4343 case RELOAD_FOR_OUTPUT_ADDRESS:
4344 if (++first_outpaddr_num[rld[i].opnum] >= 0)
4346 first_outpaddr_num[rld[i].opnum] = i;
4347 need_change = 1;
4349 break;
4350 default:
4351 break;
4355 if (need_change)
4357 for (i = 0; i < n_reloads; i++)
4359 int first_num;
4360 enum reload_type type;
4362 switch (rld[i].when_needed)
4364 case RELOAD_FOR_OPADDR_ADDR:
4365 first_num = first_op_addr_num;
4366 type = RELOAD_FOR_OPERAND_ADDRESS;
4367 break;
4368 case RELOAD_FOR_INPADDR_ADDRESS:
4369 first_num = first_inpaddr_num[rld[i].opnum];
4370 type = RELOAD_FOR_INPUT_ADDRESS;
4371 break;
4372 case RELOAD_FOR_OUTADDR_ADDRESS:
4373 first_num = first_outpaddr_num[rld[i].opnum];
4374 type = RELOAD_FOR_OUTPUT_ADDRESS;
4375 break;
4376 default:
4377 continue;
4379 if (first_num < 0)
4380 continue;
4381 else if (i > first_num)
4382 rld[i].when_needed = type;
4383 else
4385 /* Check if the only TYPE reload that uses reload I is
4386 reload FIRST_NUM. */
4387 for (j = n_reloads - 1; j > first_num; j--)
4389 if (rld[j].when_needed == type
4390 && (rld[i].secondary_p
4391 ? rld[j].secondary_in_reload == i
4392 : reg_mentioned_p (rld[i].in, rld[j].in)))
4394 rld[i].when_needed = type;
4395 break;
4403 /* See if we have any reloads that are now allowed to be merged
4404 because we've changed when the reload is needed to
4405 RELOAD_FOR_OPERAND_ADDRESS or RELOAD_FOR_OTHER_ADDRESS. Only
4406 check for the most common cases. */
4408 for (i = 0; i < n_reloads; i++)
4409 if (rld[i].in != 0 && rld[i].out == 0
4410 && (rld[i].when_needed == RELOAD_FOR_OPERAND_ADDRESS
4411 || rld[i].when_needed == RELOAD_FOR_OPADDR_ADDR
4412 || rld[i].when_needed == RELOAD_FOR_OTHER_ADDRESS))
4413 for (j = 0; j < n_reloads; j++)
4414 if (i != j && rld[j].in != 0 && rld[j].out == 0
4415 && rld[j].when_needed == rld[i].when_needed
4416 && MATCHES (rld[i].in, rld[j].in)
4417 && rld[i].class == rld[j].class
4418 && !rld[i].nocombine && !rld[j].nocombine
4419 && rld[i].reg_rtx == rld[j].reg_rtx)
4421 rld[i].opnum = MIN (rld[i].opnum, rld[j].opnum);
4422 transfer_replacements (i, j);
4423 rld[j].in = 0;
4426 #ifdef HAVE_cc0
4427 /* If we made any reloads for addresses, see if they violate a
4428 "no input reloads" requirement for this insn. But loads that we
4429 do after the insn (such as for output addresses) are fine. */
4430 if (no_input_reloads)
4431 for (i = 0; i < n_reloads; i++)
4432 gcc_assert (rld[i].in == 0
4433 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS
4434 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS);
4435 #endif
4437 /* Compute reload_mode and reload_nregs. */
4438 for (i = 0; i < n_reloads; i++)
4440 rld[i].mode
4441 = (rld[i].inmode == VOIDmode
4442 || (GET_MODE_SIZE (rld[i].outmode)
4443 > GET_MODE_SIZE (rld[i].inmode)))
4444 ? rld[i].outmode : rld[i].inmode;
4446 rld[i].nregs = CLASS_MAX_NREGS (rld[i].class, rld[i].mode);
4449 /* Special case a simple move with an input reload and a
4450 destination of a hard reg, if the hard reg is ok, use it. */
4451 for (i = 0; i < n_reloads; i++)
4452 if (rld[i].when_needed == RELOAD_FOR_INPUT
4453 && GET_CODE (PATTERN (insn)) == SET
4454 && REG_P (SET_DEST (PATTERN (insn)))
4455 && SET_SRC (PATTERN (insn)) == rld[i].in)
4457 rtx dest = SET_DEST (PATTERN (insn));
4458 unsigned int regno = REGNO (dest);
4460 if (regno < FIRST_PSEUDO_REGISTER
4461 && TEST_HARD_REG_BIT (reg_class_contents[rld[i].class], regno)
4462 && HARD_REGNO_MODE_OK (regno, rld[i].mode))
4464 int nr = hard_regno_nregs[regno][rld[i].mode];
4465 int ok = 1, nri;
4467 for (nri = 1; nri < nr; nri ++)
4468 if (! TEST_HARD_REG_BIT (reg_class_contents[rld[i].class], regno + nri))
4469 ok = 0;
4471 if (ok)
4472 rld[i].reg_rtx = dest;
4476 return retval;
4479 /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
4480 accepts a memory operand with constant address. */
4482 static int
4483 alternative_allows_memconst (const char *constraint, int altnum)
4485 int c;
4486 /* Skip alternatives before the one requested. */
4487 while (altnum > 0)
4489 while (*constraint++ != ',');
4490 altnum--;
4492 /* Scan the requested alternative for 'm' or 'o'.
4493 If one of them is present, this alternative accepts memory constants. */
4494 for (; (c = *constraint) && c != ',' && c != '#';
4495 constraint += CONSTRAINT_LEN (c, constraint))
4496 if (c == 'm' || c == 'o' || EXTRA_MEMORY_CONSTRAINT (c, constraint))
4497 return 1;
4498 return 0;
4501 /* Scan X for memory references and scan the addresses for reloading.
4502 Also checks for references to "constant" regs that we want to eliminate
4503 and replaces them with the values they stand for.
4504 We may alter X destructively if it contains a reference to such.
4505 If X is just a constant reg, we return the equivalent value
4506 instead of X.
4508 IND_LEVELS says how many levels of indirect addressing this machine
4509 supports.
4511 OPNUM and TYPE identify the purpose of the reload.
4513 IS_SET_DEST is true if X is the destination of a SET, which is not
4514 appropriate to be replaced by a constant.
4516 INSN, if nonzero, is the insn in which we do the reload. It is used
4517 to determine if we may generate output reloads, and where to put USEs
4518 for pseudos that we have to replace with stack slots.
4520 ADDRESS_RELOADED. If nonzero, is a pointer to where we put the
4521 result of find_reloads_address. */
4523 static rtx
4524 find_reloads_toplev (rtx x, int opnum, enum reload_type type,
4525 int ind_levels, int is_set_dest, rtx insn,
4526 int *address_reloaded)
4528 RTX_CODE code = GET_CODE (x);
4530 const char *fmt = GET_RTX_FORMAT (code);
4531 int i;
4532 int copied;
4534 if (code == REG)
4536 /* This code is duplicated for speed in find_reloads. */
4537 int regno = REGNO (x);
4538 if (reg_equiv_constant[regno] != 0 && !is_set_dest)
4539 x = reg_equiv_constant[regno];
4540 #if 0
4541 /* This creates (subreg (mem...)) which would cause an unnecessary
4542 reload of the mem. */
4543 else if (reg_equiv_mem[regno] != 0)
4544 x = reg_equiv_mem[regno];
4545 #endif
4546 else if (reg_equiv_memory_loc[regno]
4547 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
4549 rtx mem = make_memloc (x, regno);
4550 if (reg_equiv_address[regno]
4551 || ! rtx_equal_p (mem, reg_equiv_mem[regno]))
4553 /* If this is not a toplevel operand, find_reloads doesn't see
4554 this substitution. We have to emit a USE of the pseudo so
4555 that delete_output_reload can see it. */
4556 if (replace_reloads && recog_data.operand[opnum] != x)
4557 /* We mark the USE with QImode so that we recognize it
4558 as one that can be safely deleted at the end of
4559 reload. */
4560 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, x), insn),
4561 QImode);
4562 x = mem;
4563 i = find_reloads_address (GET_MODE (x), &x, XEXP (x, 0), &XEXP (x, 0),
4564 opnum, type, ind_levels, insn);
4565 if (address_reloaded)
4566 *address_reloaded = i;
4569 return x;
4571 if (code == MEM)
4573 rtx tem = x;
4575 i = find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0),
4576 opnum, type, ind_levels, insn);
4577 if (address_reloaded)
4578 *address_reloaded = i;
4580 return tem;
4583 if (code == SUBREG && REG_P (SUBREG_REG (x)))
4585 /* Check for SUBREG containing a REG that's equivalent to a
4586 constant. If the constant has a known value, truncate it
4587 right now. Similarly if we are extracting a single-word of a
4588 multi-word constant. If the constant is symbolic, allow it
4589 to be substituted normally. push_reload will strip the
4590 subreg later. The constant must not be VOIDmode, because we
4591 will lose the mode of the register (this should never happen
4592 because one of the cases above should handle it). */
4594 int regno = REGNO (SUBREG_REG (x));
4595 rtx tem;
4597 if (subreg_lowpart_p (x)
4598 && regno >= FIRST_PSEUDO_REGISTER
4599 && reg_renumber[regno] < 0
4600 && reg_equiv_constant[regno] != 0
4601 && (tem = gen_lowpart_common (GET_MODE (x),
4602 reg_equiv_constant[regno])) != 0)
4603 return tem;
4605 if (regno >= FIRST_PSEUDO_REGISTER
4606 && reg_renumber[regno] < 0
4607 && reg_equiv_constant[regno] != 0)
4609 tem =
4610 simplify_gen_subreg (GET_MODE (x), reg_equiv_constant[regno],
4611 GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
4612 gcc_assert (tem);
4613 return tem;
4616 /* If the subreg contains a reg that will be converted to a mem,
4617 convert the subreg to a narrower memref now.
4618 Otherwise, we would get (subreg (mem ...) ...),
4619 which would force reload of the mem.
4621 We also need to do this if there is an equivalent MEM that is
4622 not offsettable. In that case, alter_subreg would produce an
4623 invalid address on big-endian machines.
4625 For machines that extend byte loads, we must not reload using
4626 a wider mode if we have a paradoxical SUBREG. find_reloads will
4627 force a reload in that case. So we should not do anything here. */
4629 if (regno >= FIRST_PSEUDO_REGISTER
4630 #ifdef LOAD_EXTEND_OP
4631 && (GET_MODE_SIZE (GET_MODE (x))
4632 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
4633 #endif
4634 && (reg_equiv_address[regno] != 0
4635 || (reg_equiv_mem[regno] != 0
4636 && (! strict_memory_address_p (GET_MODE (x),
4637 XEXP (reg_equiv_mem[regno], 0))
4638 || ! offsettable_memref_p (reg_equiv_mem[regno])
4639 || num_not_at_initial_offset))))
4640 x = find_reloads_subreg_address (x, 1, opnum, type, ind_levels,
4641 insn);
4644 for (copied = 0, i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4646 if (fmt[i] == 'e')
4648 rtx new_part = find_reloads_toplev (XEXP (x, i), opnum, type,
4649 ind_levels, is_set_dest, insn,
4650 address_reloaded);
4651 /* If we have replaced a reg with it's equivalent memory loc -
4652 that can still be handled here e.g. if it's in a paradoxical
4653 subreg - we must make the change in a copy, rather than using
4654 a destructive change. This way, find_reloads can still elect
4655 not to do the change. */
4656 if (new_part != XEXP (x, i) && ! CONSTANT_P (new_part) && ! copied)
4658 x = shallow_copy_rtx (x);
4659 copied = 1;
4661 XEXP (x, i) = new_part;
4664 return x;
4667 /* Return a mem ref for the memory equivalent of reg REGNO.
4668 This mem ref is not shared with anything. */
4670 static rtx
4671 make_memloc (rtx ad, int regno)
4673 /* We must rerun eliminate_regs, in case the elimination
4674 offsets have changed. */
4675 rtx tem
4676 = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0, NULL_RTX), 0);
4678 /* If TEM might contain a pseudo, we must copy it to avoid
4679 modifying it when we do the substitution for the reload. */
4680 if (rtx_varies_p (tem, 0))
4681 tem = copy_rtx (tem);
4683 tem = replace_equiv_address_nv (reg_equiv_memory_loc[regno], tem);
4684 tem = adjust_address_nv (tem, GET_MODE (ad), 0);
4686 /* Copy the result if it's still the same as the equivalence, to avoid
4687 modifying it when we do the substitution for the reload. */
4688 if (tem == reg_equiv_memory_loc[regno])
4689 tem = copy_rtx (tem);
4690 return tem;
4693 /* Returns true if AD could be turned into a valid memory reference
4694 to mode MODE by reloading the part pointed to by PART into a
4695 register. */
4697 static int
4698 maybe_memory_address_p (enum machine_mode mode, rtx ad, rtx *part)
4700 int retv;
4701 rtx tem = *part;
4702 rtx reg = gen_rtx_REG (GET_MODE (tem), max_reg_num ());
4704 *part = reg;
4705 retv = memory_address_p (mode, ad);
4706 *part = tem;
4708 return retv;
4711 /* Record all reloads needed for handling memory address AD
4712 which appears in *LOC in a memory reference to mode MODE
4713 which itself is found in location *MEMREFLOC.
4714 Note that we take shortcuts assuming that no multi-reg machine mode
4715 occurs as part of an address.
4717 OPNUM and TYPE specify the purpose of this reload.
4719 IND_LEVELS says how many levels of indirect addressing this machine
4720 supports.
4722 INSN, if nonzero, is the insn in which we do the reload. It is used
4723 to determine if we may generate output reloads, and where to put USEs
4724 for pseudos that we have to replace with stack slots.
4726 Value is one if this address is reloaded or replaced as a whole; it is
4727 zero if the top level of this address was not reloaded or replaced, and
4728 it is -1 if it may or may not have been reloaded or replaced.
4730 Note that there is no verification that the address will be valid after
4731 this routine does its work. Instead, we rely on the fact that the address
4732 was valid when reload started. So we need only undo things that reload
4733 could have broken. These are wrong register types, pseudos not allocated
4734 to a hard register, and frame pointer elimination. */
4736 static int
4737 find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
4738 rtx *loc, int opnum, enum reload_type type,
4739 int ind_levels, rtx insn)
4741 int regno;
4742 int removed_and = 0;
4743 int op_index;
4744 rtx tem;
4746 /* If the address is a register, see if it is a legitimate address and
4747 reload if not. We first handle the cases where we need not reload
4748 or where we must reload in a non-standard way. */
4750 if (REG_P (ad))
4752 regno = REGNO (ad);
4754 /* If the register is equivalent to an invariant expression, substitute
4755 the invariant, and eliminate any eliminable register references. */
4756 tem = reg_equiv_constant[regno];
4757 if (tem != 0
4758 && (tem = eliminate_regs (tem, mode, insn))
4759 && strict_memory_address_p (mode, tem))
4761 *loc = ad = tem;
4762 return 0;
4765 tem = reg_equiv_memory_loc[regno];
4766 if (tem != 0)
4768 if (reg_equiv_address[regno] != 0 || num_not_at_initial_offset)
4770 tem = make_memloc (ad, regno);
4771 if (! strict_memory_address_p (GET_MODE (tem), XEXP (tem, 0)))
4773 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
4774 &XEXP (tem, 0), opnum,
4775 ADDR_TYPE (type), ind_levels, insn);
4777 /* We can avoid a reload if the register's equivalent memory
4778 expression is valid as an indirect memory address.
4779 But not all addresses are valid in a mem used as an indirect
4780 address: only reg or reg+constant. */
4782 if (ind_levels > 0
4783 && strict_memory_address_p (mode, tem)
4784 && (REG_P (XEXP (tem, 0))
4785 || (GET_CODE (XEXP (tem, 0)) == PLUS
4786 && REG_P (XEXP (XEXP (tem, 0), 0))
4787 && CONSTANT_P (XEXP (XEXP (tem, 0), 1)))))
4789 /* TEM is not the same as what we'll be replacing the
4790 pseudo with after reload, put a USE in front of INSN
4791 in the final reload pass. */
4792 if (replace_reloads
4793 && num_not_at_initial_offset
4794 && ! rtx_equal_p (tem, reg_equiv_mem[regno]))
4796 *loc = tem;
4797 /* We mark the USE with QImode so that we
4798 recognize it as one that can be safely
4799 deleted at the end of reload. */
4800 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad),
4801 insn), QImode);
4803 /* This doesn't really count as replacing the address
4804 as a whole, since it is still a memory access. */
4806 return 0;
4808 ad = tem;
4812 /* The only remaining case where we can avoid a reload is if this is a
4813 hard register that is valid as a base register and which is not the
4814 subject of a CLOBBER in this insn. */
4816 else if (regno < FIRST_PSEUDO_REGISTER
4817 && REGNO_MODE_OK_FOR_BASE_P (regno, mode)
4818 && ! regno_clobbered_p (regno, this_insn, mode, 0))
4819 return 0;
4821 /* If we do not have one of the cases above, we must do the reload. */
4822 push_reload (ad, NULL_RTX, loc, (rtx*) 0, MODE_BASE_REG_CLASS (mode),
4823 GET_MODE (ad), VOIDmode, 0, 0, opnum, type);
4824 return 1;
4827 if (strict_memory_address_p (mode, ad))
4829 /* The address appears valid, so reloads are not needed.
4830 But the address may contain an eliminable register.
4831 This can happen because a machine with indirect addressing
4832 may consider a pseudo register by itself a valid address even when
4833 it has failed to get a hard reg.
4834 So do a tree-walk to find and eliminate all such regs. */
4836 /* But first quickly dispose of a common case. */
4837 if (GET_CODE (ad) == PLUS
4838 && GET_CODE (XEXP (ad, 1)) == CONST_INT
4839 && REG_P (XEXP (ad, 0))
4840 && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
4841 return 0;
4843 subst_reg_equivs_changed = 0;
4844 *loc = subst_reg_equivs (ad, insn);
4846 if (! subst_reg_equivs_changed)
4847 return 0;
4849 /* Check result for validity after substitution. */
4850 if (strict_memory_address_p (mode, ad))
4851 return 0;
4854 #ifdef LEGITIMIZE_RELOAD_ADDRESS
4857 if (memrefloc)
4859 LEGITIMIZE_RELOAD_ADDRESS (ad, GET_MODE (*memrefloc), opnum, type,
4860 ind_levels, win);
4862 break;
4863 win:
4864 *memrefloc = copy_rtx (*memrefloc);
4865 XEXP (*memrefloc, 0) = ad;
4866 move_replacements (&ad, &XEXP (*memrefloc, 0));
4867 return -1;
4869 while (0);
4870 #endif
4872 /* The address is not valid. We have to figure out why. First see if
4873 we have an outer AND and remove it if so. Then analyze what's inside. */
4875 if (GET_CODE (ad) == AND)
4877 removed_and = 1;
4878 loc = &XEXP (ad, 0);
4879 ad = *loc;
4882 /* One possibility for why the address is invalid is that it is itself
4883 a MEM. This can happen when the frame pointer is being eliminated, a
4884 pseudo is not allocated to a hard register, and the offset between the
4885 frame and stack pointers is not its initial value. In that case the
4886 pseudo will have been replaced by a MEM referring to the
4887 stack pointer. */
4888 if (MEM_P (ad))
4890 /* First ensure that the address in this MEM is valid. Then, unless
4891 indirect addresses are valid, reload the MEM into a register. */
4892 tem = ad;
4893 find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0),
4894 opnum, ADDR_TYPE (type),
4895 ind_levels == 0 ? 0 : ind_levels - 1, insn);
4897 /* If tem was changed, then we must create a new memory reference to
4898 hold it and store it back into memrefloc. */
4899 if (tem != ad && memrefloc)
4901 *memrefloc = copy_rtx (*memrefloc);
4902 copy_replacements (tem, XEXP (*memrefloc, 0));
4903 loc = &XEXP (*memrefloc, 0);
4904 if (removed_and)
4905 loc = &XEXP (*loc, 0);
4908 /* Check similar cases as for indirect addresses as above except
4909 that we can allow pseudos and a MEM since they should have been
4910 taken care of above. */
4912 if (ind_levels == 0
4913 || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok)
4914 || MEM_P (XEXP (tem, 0))
4915 || ! (REG_P (XEXP (tem, 0))
4916 || (GET_CODE (XEXP (tem, 0)) == PLUS
4917 && REG_P (XEXP (XEXP (tem, 0), 0))
4918 && GET_CODE (XEXP (XEXP (tem, 0), 1)) == CONST_INT)))
4920 /* Must use TEM here, not AD, since it is the one that will
4921 have any subexpressions reloaded, if needed. */
4922 push_reload (tem, NULL_RTX, loc, (rtx*) 0,
4923 MODE_BASE_REG_CLASS (mode), GET_MODE (tem),
4924 VOIDmode, 0,
4925 0, opnum, type);
4926 return ! removed_and;
4928 else
4929 return 0;
4932 /* If we have address of a stack slot but it's not valid because the
4933 displacement is too large, compute the sum in a register.
4934 Handle all base registers here, not just fp/ap/sp, because on some
4935 targets (namely SH) we can also get too large displacements from
4936 big-endian corrections. */
4937 else if (GET_CODE (ad) == PLUS
4938 && REG_P (XEXP (ad, 0))
4939 && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER
4940 && REG_MODE_OK_FOR_BASE_P (XEXP (ad, 0), mode)
4941 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4943 /* Unshare the MEM rtx so we can safely alter it. */
4944 if (memrefloc)
4946 *memrefloc = copy_rtx (*memrefloc);
4947 loc = &XEXP (*memrefloc, 0);
4948 if (removed_and)
4949 loc = &XEXP (*loc, 0);
4952 if (double_reg_address_ok)
4954 /* Unshare the sum as well. */
4955 *loc = ad = copy_rtx (ad);
4957 /* Reload the displacement into an index reg.
4958 We assume the frame pointer or arg pointer is a base reg. */
4959 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4960 INDEX_REG_CLASS, GET_MODE (ad), opnum,
4961 type, ind_levels);
4962 return 0;
4964 else
4966 /* If the sum of two regs is not necessarily valid,
4967 reload the sum into a base reg.
4968 That will at least work. */
4969 find_reloads_address_part (ad, loc, MODE_BASE_REG_CLASS (mode),
4970 Pmode, opnum, type, ind_levels);
4972 return ! removed_and;
4975 /* If we have an indexed stack slot, there are three possible reasons why
4976 it might be invalid: The index might need to be reloaded, the address
4977 might have been made by frame pointer elimination and hence have a
4978 constant out of range, or both reasons might apply.
4980 We can easily check for an index needing reload, but even if that is the
4981 case, we might also have an invalid constant. To avoid making the
4982 conservative assumption and requiring two reloads, we see if this address
4983 is valid when not interpreted strictly. If it is, the only problem is
4984 that the index needs a reload and find_reloads_address_1 will take care
4985 of it.
4987 Handle all base registers here, not just fp/ap/sp, because on some
4988 targets (namely SPARC) we can also get invalid addresses from preventive
4989 subreg big-endian corrections made by find_reloads_toplev. We
4990 can also get expressions involving LO_SUM (rather than PLUS) from
4991 find_reloads_subreg_address.
4993 If we decide to do something, it must be that `double_reg_address_ok'
4994 is true. We generate a reload of the base register + constant and
4995 rework the sum so that the reload register will be added to the index.
4996 This is safe because we know the address isn't shared.
4998 We check for the base register as both the first and second operand of
4999 the innermost PLUS and/or LO_SUM. */
5001 for (op_index = 0; op_index < 2; ++op_index)
5003 rtx operand;
5005 if (!(GET_CODE (ad) == PLUS
5006 && GET_CODE (XEXP (ad, 1)) == CONST_INT
5007 && (GET_CODE (XEXP (ad, 0)) == PLUS
5008 || GET_CODE (XEXP (ad, 0)) == LO_SUM)))
5009 continue;
5011 operand = XEXP (XEXP (ad, 0), op_index);
5012 if (!REG_P (operand) || REGNO (operand) >= FIRST_PSEUDO_REGISTER)
5013 continue;
5015 if ((REG_MODE_OK_FOR_BASE_P (operand, mode)
5016 || operand == frame_pointer_rtx
5017 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
5018 || operand == hard_frame_pointer_rtx
5019 #endif
5020 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
5021 || operand == arg_pointer_rtx
5022 #endif
5023 || operand == stack_pointer_rtx)
5024 && ! maybe_memory_address_p (mode, ad,
5025 &XEXP (XEXP (ad, 0), 1 - op_index)))
5027 rtx offset_reg;
5028 rtx addend;
5030 offset_reg = plus_constant (operand, INTVAL (XEXP (ad, 1)));
5031 addend = XEXP (XEXP (ad, 0), 1 - op_index);
5033 /* Form the adjusted address. */
5034 if (GET_CODE (XEXP (ad, 0)) == PLUS)
5035 ad = gen_rtx_PLUS (GET_MODE (ad),
5036 op_index == 0 ? offset_reg : addend,
5037 op_index == 0 ? addend : offset_reg);
5038 else
5039 ad = gen_rtx_LO_SUM (GET_MODE (ad),
5040 op_index == 0 ? offset_reg : addend,
5041 op_index == 0 ? addend : offset_reg);
5042 *loc = ad;
5044 find_reloads_address_part (XEXP (ad, op_index),
5045 &XEXP (ad, op_index),
5046 MODE_BASE_REG_CLASS (mode),
5047 GET_MODE (ad), opnum, type, ind_levels);
5048 find_reloads_address_1 (mode,
5049 XEXP (ad, 1 - op_index), 1,
5050 &XEXP (ad, 1 - op_index), opnum,
5051 type, 0, insn);
5053 return 0;
5057 /* See if address becomes valid when an eliminable register
5058 in a sum is replaced. */
5060 tem = ad;
5061 if (GET_CODE (ad) == PLUS)
5062 tem = subst_indexed_address (ad);
5063 if (tem != ad && strict_memory_address_p (mode, tem))
5065 /* Ok, we win that way. Replace any additional eliminable
5066 registers. */
5068 subst_reg_equivs_changed = 0;
5069 tem = subst_reg_equivs (tem, insn);
5071 /* Make sure that didn't make the address invalid again. */
5073 if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
5075 *loc = tem;
5076 return 0;
5080 /* If constants aren't valid addresses, reload the constant address
5081 into a register. */
5082 if (CONSTANT_P (ad) && ! strict_memory_address_p (mode, ad))
5084 /* If AD is an address in the constant pool, the MEM rtx may be shared.
5085 Unshare it so we can safely alter it. */
5086 if (memrefloc && GET_CODE (ad) == SYMBOL_REF
5087 && CONSTANT_POOL_ADDRESS_P (ad))
5089 *memrefloc = copy_rtx (*memrefloc);
5090 loc = &XEXP (*memrefloc, 0);
5091 if (removed_and)
5092 loc = &XEXP (*loc, 0);
5095 find_reloads_address_part (ad, loc, MODE_BASE_REG_CLASS (mode),
5096 Pmode, opnum, type, ind_levels);
5097 return ! removed_and;
5100 return find_reloads_address_1 (mode, ad, 0, loc, opnum, type, ind_levels,
5101 insn);
5104 /* Find all pseudo regs appearing in AD
5105 that are eliminable in favor of equivalent values
5106 and do not have hard regs; replace them by their equivalents.
5107 INSN, if nonzero, is the insn in which we do the reload. We put USEs in
5108 front of it for pseudos that we have to replace with stack slots. */
5110 static rtx
5111 subst_reg_equivs (rtx ad, rtx insn)
5113 RTX_CODE code = GET_CODE (ad);
5114 int i;
5115 const char *fmt;
5117 switch (code)
5119 case HIGH:
5120 case CONST_INT:
5121 case CONST:
5122 case CONST_DOUBLE:
5123 case CONST_VECTOR:
5124 case SYMBOL_REF:
5125 case LABEL_REF:
5126 case PC:
5127 case CC0:
5128 return ad;
5130 case REG:
5132 int regno = REGNO (ad);
5134 if (reg_equiv_constant[regno] != 0)
5136 subst_reg_equivs_changed = 1;
5137 return reg_equiv_constant[regno];
5139 if (reg_equiv_memory_loc[regno] && num_not_at_initial_offset)
5141 rtx mem = make_memloc (ad, regno);
5142 if (! rtx_equal_p (mem, reg_equiv_mem[regno]))
5144 subst_reg_equivs_changed = 1;
5145 /* We mark the USE with QImode so that we recognize it
5146 as one that can be safely deleted at the end of
5147 reload. */
5148 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad), insn),
5149 QImode);
5150 return mem;
5154 return ad;
5156 case PLUS:
5157 /* Quickly dispose of a common case. */
5158 if (XEXP (ad, 0) == frame_pointer_rtx
5159 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
5160 return ad;
5161 break;
5163 default:
5164 break;
5167 fmt = GET_RTX_FORMAT (code);
5168 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5169 if (fmt[i] == 'e')
5170 XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i), insn);
5171 return ad;
5174 /* Compute the sum of X and Y, making canonicalizations assumed in an
5175 address, namely: sum constant integers, surround the sum of two
5176 constants with a CONST, put the constant as the second operand, and
5177 group the constant on the outermost sum.
5179 This routine assumes both inputs are already in canonical form. */
5182 form_sum (rtx x, rtx y)
5184 rtx tem;
5185 enum machine_mode mode = GET_MODE (x);
5187 if (mode == VOIDmode)
5188 mode = GET_MODE (y);
5190 if (mode == VOIDmode)
5191 mode = Pmode;
5193 if (GET_CODE (x) == CONST_INT)
5194 return plus_constant (y, INTVAL (x));
5195 else if (GET_CODE (y) == CONST_INT)
5196 return plus_constant (x, INTVAL (y));
5197 else if (CONSTANT_P (x))
5198 tem = x, x = y, y = tem;
5200 if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
5201 return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y));
5203 /* Note that if the operands of Y are specified in the opposite
5204 order in the recursive calls below, infinite recursion will occur. */
5205 if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
5206 return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1));
5208 /* If both constant, encapsulate sum. Otherwise, just form sum. A
5209 constant will have been placed second. */
5210 if (CONSTANT_P (x) && CONSTANT_P (y))
5212 if (GET_CODE (x) == CONST)
5213 x = XEXP (x, 0);
5214 if (GET_CODE (y) == CONST)
5215 y = XEXP (y, 0);
5217 return gen_rtx_CONST (VOIDmode, gen_rtx_PLUS (mode, x, y));
5220 return gen_rtx_PLUS (mode, x, y);
5223 /* If ADDR is a sum containing a pseudo register that should be
5224 replaced with a constant (from reg_equiv_constant),
5225 return the result of doing so, and also apply the associative
5226 law so that the result is more likely to be a valid address.
5227 (But it is not guaranteed to be one.)
5229 Note that at most one register is replaced, even if more are
5230 replaceable. Also, we try to put the result into a canonical form
5231 so it is more likely to be a valid address.
5233 In all other cases, return ADDR. */
5235 static rtx
5236 subst_indexed_address (rtx addr)
5238 rtx op0 = 0, op1 = 0, op2 = 0;
5239 rtx tem;
5240 int regno;
5242 if (GET_CODE (addr) == PLUS)
5244 /* Try to find a register to replace. */
5245 op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0;
5246 if (REG_P (op0)
5247 && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER
5248 && reg_renumber[regno] < 0
5249 && reg_equiv_constant[regno] != 0)
5250 op0 = reg_equiv_constant[regno];
5251 else if (REG_P (op1)
5252 && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER
5253 && reg_renumber[regno] < 0
5254 && reg_equiv_constant[regno] != 0)
5255 op1 = reg_equiv_constant[regno];
5256 else if (GET_CODE (op0) == PLUS
5257 && (tem = subst_indexed_address (op0)) != op0)
5258 op0 = tem;
5259 else if (GET_CODE (op1) == PLUS
5260 && (tem = subst_indexed_address (op1)) != op1)
5261 op1 = tem;
5262 else
5263 return addr;
5265 /* Pick out up to three things to add. */
5266 if (GET_CODE (op1) == PLUS)
5267 op2 = XEXP (op1, 1), op1 = XEXP (op1, 0);
5268 else if (GET_CODE (op0) == PLUS)
5269 op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
5271 /* Compute the sum. */
5272 if (op2 != 0)
5273 op1 = form_sum (op1, op2);
5274 if (op1 != 0)
5275 op0 = form_sum (op0, op1);
5277 return op0;
5279 return addr;
5282 /* Update the REG_INC notes for an insn. It updates all REG_INC
5283 notes for the instruction which refer to REGNO the to refer
5284 to the reload number.
5286 INSN is the insn for which any REG_INC notes need updating.
5288 REGNO is the register number which has been reloaded.
5290 RELOADNUM is the reload number. */
5292 static void
5293 update_auto_inc_notes (rtx insn ATTRIBUTE_UNUSED, int regno ATTRIBUTE_UNUSED,
5294 int reloadnum ATTRIBUTE_UNUSED)
5296 #ifdef AUTO_INC_DEC
5297 rtx link;
5299 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
5300 if (REG_NOTE_KIND (link) == REG_INC
5301 && (int) REGNO (XEXP (link, 0)) == regno)
5302 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5303 #endif
5306 /* Record the pseudo registers we must reload into hard registers in a
5307 subexpression of a would-be memory address, X referring to a value
5308 in mode MODE. (This function is not called if the address we find
5309 is strictly valid.)
5311 CONTEXT = 1 means we are considering regs as index regs,
5312 = 0 means we are considering them as base regs, = 2 means we
5313 are considering them as base regs for REG + REG.
5315 OPNUM and TYPE specify the purpose of any reloads made.
5317 IND_LEVELS says how many levels of indirect addressing are
5318 supported at this point in the address.
5320 INSN, if nonzero, is the insn in which we do the reload. It is used
5321 to determine if we may generate output reloads.
5323 We return nonzero if X, as a whole, is reloaded or replaced. */
5325 /* Note that we take shortcuts assuming that no multi-reg machine mode
5326 occurs as part of an address.
5327 Also, this is not fully machine-customizable; it works for machines
5328 such as VAXen and 68000's and 32000's, but other possible machines
5329 could have addressing modes that this does not handle right.
5330 If you add push_reload calls here, you need to make sure gen_reload
5331 handles those cases gracefully. */
5333 static int
5334 find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
5335 rtx *loc, int opnum, enum reload_type type,
5336 int ind_levels, rtx insn)
5338 #define REG_OK_FOR_CONTEXT(CONTEXT, REGNO, MODE) \
5339 ((CONTEXT) == 2 \
5340 ? REGNO_MODE_OK_FOR_REG_BASE_P (REGNO, MODE) \
5341 : (CONTEXT) == 1 \
5342 ? REGNO_OK_FOR_INDEX_P (REGNO) \
5343 : REGNO_MODE_OK_FOR_BASE_P (REGNO, MODE))
5345 enum reg_class context_reg_class;
5346 RTX_CODE code = GET_CODE (x);
5348 if (context == 2)
5349 context_reg_class = MODE_BASE_REG_REG_CLASS (mode);
5350 else if (context == 1)
5351 context_reg_class = INDEX_REG_CLASS;
5352 else
5353 context_reg_class = MODE_BASE_REG_CLASS (mode);
5355 switch (code)
5357 case PLUS:
5359 rtx orig_op0 = XEXP (x, 0);
5360 rtx orig_op1 = XEXP (x, 1);
5361 RTX_CODE code0 = GET_CODE (orig_op0);
5362 RTX_CODE code1 = GET_CODE (orig_op1);
5363 rtx op0 = orig_op0;
5364 rtx op1 = orig_op1;
5366 if (GET_CODE (op0) == SUBREG)
5368 op0 = SUBREG_REG (op0);
5369 code0 = GET_CODE (op0);
5370 if (code0 == REG && REGNO (op0) < FIRST_PSEUDO_REGISTER)
5371 op0 = gen_rtx_REG (word_mode,
5372 (REGNO (op0) +
5373 subreg_regno_offset (REGNO (SUBREG_REG (orig_op0)),
5374 GET_MODE (SUBREG_REG (orig_op0)),
5375 SUBREG_BYTE (orig_op0),
5376 GET_MODE (orig_op0))));
5379 if (GET_CODE (op1) == SUBREG)
5381 op1 = SUBREG_REG (op1);
5382 code1 = GET_CODE (op1);
5383 if (code1 == REG && REGNO (op1) < FIRST_PSEUDO_REGISTER)
5384 /* ??? Why is this given op1's mode and above for
5385 ??? op0 SUBREGs we use word_mode? */
5386 op1 = gen_rtx_REG (GET_MODE (op1),
5387 (REGNO (op1) +
5388 subreg_regno_offset (REGNO (SUBREG_REG (orig_op1)),
5389 GET_MODE (SUBREG_REG (orig_op1)),
5390 SUBREG_BYTE (orig_op1),
5391 GET_MODE (orig_op1))));
5393 /* Plus in the index register may be created only as a result of
5394 register remateralization for expression like &localvar*4. Reload it.
5395 It may be possible to combine the displacement on the outer level,
5396 but it is probably not worthwhile to do so. */
5397 if (context == 1)
5399 find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5400 opnum, ADDR_TYPE (type), ind_levels, insn);
5401 push_reload (*loc, NULL_RTX, loc, (rtx*) 0,
5402 context_reg_class,
5403 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5404 return 1;
5407 if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
5408 || code0 == ZERO_EXTEND || code1 == MEM)
5410 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5411 type, ind_levels, insn);
5412 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5413 type, ind_levels, insn);
5416 else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
5417 || code1 == ZERO_EXTEND || code0 == MEM)
5419 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5420 type, ind_levels, insn);
5421 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5422 type, ind_levels, insn);
5425 else if (code0 == CONST_INT || code0 == CONST
5426 || code0 == SYMBOL_REF || code0 == LABEL_REF)
5427 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5428 type, ind_levels, insn);
5430 else if (code1 == CONST_INT || code1 == CONST
5431 || code1 == SYMBOL_REF || code1 == LABEL_REF)
5432 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5433 type, ind_levels, insn);
5435 else if (code0 == REG && code1 == REG)
5437 if (REG_OK_FOR_INDEX_P (op0)
5438 && REG_MODE_OK_FOR_REG_BASE_P (op1, mode))
5439 return 0;
5440 else if (REG_OK_FOR_INDEX_P (op1)
5441 && REG_MODE_OK_FOR_REG_BASE_P (op0, mode))
5442 return 0;
5443 else if (REG_MODE_OK_FOR_REG_BASE_P (op1, mode))
5444 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5445 type, ind_levels, insn);
5446 else if (REG_MODE_OK_FOR_REG_BASE_P (op0, mode))
5447 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5448 type, ind_levels, insn);
5449 else if (REG_OK_FOR_INDEX_P (op1))
5450 find_reloads_address_1 (mode, orig_op0, 2, &XEXP (x, 0), opnum,
5451 type, ind_levels, insn);
5452 else if (REG_OK_FOR_INDEX_P (op0))
5453 find_reloads_address_1 (mode, orig_op1, 2, &XEXP (x, 1), opnum,
5454 type, ind_levels, insn);
5455 else
5457 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5458 type, ind_levels, insn);
5459 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5460 type, ind_levels, insn);
5464 else if (code0 == REG)
5466 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5467 type, ind_levels, insn);
5468 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5469 type, ind_levels, insn);
5472 else if (code1 == REG)
5474 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5475 type, ind_levels, insn);
5476 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5477 type, ind_levels, insn);
5481 return 0;
5483 case POST_MODIFY:
5484 case PRE_MODIFY:
5486 rtx op0 = XEXP (x, 0);
5487 rtx op1 = XEXP (x, 1);
5488 int regno;
5489 int reloadnum;
5491 if (GET_CODE (op1) != PLUS && GET_CODE (op1) != MINUS)
5492 return 0;
5494 /* Currently, we only support {PRE,POST}_MODIFY constructs
5495 where a base register is {inc,dec}remented by the contents
5496 of another register or by a constant value. Thus, these
5497 operands must match. */
5498 gcc_assert (op0 == XEXP (op1, 0));
5500 /* Require index register (or constant). Let's just handle the
5501 register case in the meantime... If the target allows
5502 auto-modify by a constant then we could try replacing a pseudo
5503 register with its equivalent constant where applicable. */
5504 if (REG_P (XEXP (op1, 1)))
5505 if (!REGNO_OK_FOR_INDEX_P (REGNO (XEXP (op1, 1))))
5506 find_reloads_address_1 (mode, XEXP (op1, 1), 1, &XEXP (op1, 1),
5507 opnum, type, ind_levels, insn);
5509 gcc_assert (REG_P (XEXP (op1, 0)));
5511 regno = REGNO (XEXP (op1, 0));
5513 /* A register that is incremented cannot be constant! */
5514 gcc_assert (regno < FIRST_PSEUDO_REGISTER
5515 || reg_equiv_constant[regno] == 0);
5517 /* Handle a register that is equivalent to a memory location
5518 which cannot be addressed directly. */
5519 if (reg_equiv_memory_loc[regno] != 0
5520 && (reg_equiv_address[regno] != 0
5521 || num_not_at_initial_offset))
5523 rtx tem = make_memloc (XEXP (x, 0), regno);
5525 if (reg_equiv_address[regno]
5526 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5528 /* First reload the memory location's address.
5529 We can't use ADDR_TYPE (type) here, because we need to
5530 write back the value after reading it, hence we actually
5531 need two registers. */
5532 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5533 &XEXP (tem, 0), opnum,
5534 RELOAD_OTHER,
5535 ind_levels, insn);
5537 /* Then reload the memory location into a base
5538 register. */
5539 reloadnum = push_reload (tem, tem, &XEXP (x, 0),
5540 &XEXP (op1, 0),
5541 MODE_BASE_REG_CLASS (mode),
5542 GET_MODE (x), GET_MODE (x), 0,
5543 0, opnum, RELOAD_OTHER);
5545 update_auto_inc_notes (this_insn, regno, reloadnum);
5546 return 0;
5550 if (reg_renumber[regno] >= 0)
5551 regno = reg_renumber[regno];
5553 /* We require a base register here... */
5554 if (!REGNO_MODE_OK_FOR_BASE_P (regno, GET_MODE (x)))
5556 reloadnum = push_reload (XEXP (op1, 0), XEXP (x, 0),
5557 &XEXP (op1, 0), &XEXP (x, 0),
5558 MODE_BASE_REG_CLASS (mode),
5559 GET_MODE (x), GET_MODE (x), 0, 0,
5560 opnum, RELOAD_OTHER);
5562 update_auto_inc_notes (this_insn, regno, reloadnum);
5563 return 0;
5566 return 0;
5568 case POST_INC:
5569 case POST_DEC:
5570 case PRE_INC:
5571 case PRE_DEC:
5572 if (REG_P (XEXP (x, 0)))
5574 int regno = REGNO (XEXP (x, 0));
5575 int value = 0;
5576 rtx x_orig = x;
5578 /* A register that is incremented cannot be constant! */
5579 gcc_assert (regno < FIRST_PSEUDO_REGISTER
5580 || reg_equiv_constant[regno] == 0);
5582 /* Handle a register that is equivalent to a memory location
5583 which cannot be addressed directly. */
5584 if (reg_equiv_memory_loc[regno] != 0
5585 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
5587 rtx tem = make_memloc (XEXP (x, 0), regno);
5588 if (reg_equiv_address[regno]
5589 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5591 /* First reload the memory location's address.
5592 We can't use ADDR_TYPE (type) here, because we need to
5593 write back the value after reading it, hence we actually
5594 need two registers. */
5595 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5596 &XEXP (tem, 0), opnum, type,
5597 ind_levels, insn);
5598 /* Put this inside a new increment-expression. */
5599 x = gen_rtx_fmt_e (GET_CODE (x), GET_MODE (x), tem);
5600 /* Proceed to reload that, as if it contained a register. */
5604 /* If we have a hard register that is ok as an index,
5605 don't make a reload. If an autoincrement of a nice register
5606 isn't "valid", it must be that no autoincrement is "valid".
5607 If that is true and something made an autoincrement anyway,
5608 this must be a special context where one is allowed.
5609 (For example, a "push" instruction.)
5610 We can't improve this address, so leave it alone. */
5612 /* Otherwise, reload the autoincrement into a suitable hard reg
5613 and record how much to increment by. */
5615 if (reg_renumber[regno] >= 0)
5616 regno = reg_renumber[regno];
5617 if (regno >= FIRST_PSEUDO_REGISTER
5618 || !REG_OK_FOR_CONTEXT (context, regno, mode))
5620 int reloadnum;
5622 /* If we can output the register afterwards, do so, this
5623 saves the extra update.
5624 We can do so if we have an INSN - i.e. no JUMP_INSN nor
5625 CALL_INSN - and it does not set CC0.
5626 But don't do this if we cannot directly address the
5627 memory location, since this will make it harder to
5628 reuse address reloads, and increases register pressure.
5629 Also don't do this if we can probably update x directly. */
5630 rtx equiv = (MEM_P (XEXP (x, 0))
5631 ? XEXP (x, 0)
5632 : reg_equiv_mem[regno]);
5633 int icode = (int) add_optab->handlers[(int) Pmode].insn_code;
5634 if (insn && NONJUMP_INSN_P (insn) && equiv
5635 && memory_operand (equiv, GET_MODE (equiv))
5636 #ifdef HAVE_cc0
5637 && ! sets_cc0_p (PATTERN (insn))
5638 #endif
5639 && ! (icode != CODE_FOR_nothing
5640 && ((*insn_data[icode].operand[0].predicate)
5641 (equiv, Pmode))
5642 && ((*insn_data[icode].operand[1].predicate)
5643 (equiv, Pmode))))
5645 /* We use the original pseudo for loc, so that
5646 emit_reload_insns() knows which pseudo this
5647 reload refers to and updates the pseudo rtx, not
5648 its equivalent memory location, as well as the
5649 corresponding entry in reg_last_reload_reg. */
5650 loc = &XEXP (x_orig, 0);
5651 x = XEXP (x, 0);
5652 reloadnum
5653 = push_reload (x, x, loc, loc,
5654 context_reg_class,
5655 GET_MODE (x), GET_MODE (x), 0, 0,
5656 opnum, RELOAD_OTHER);
5658 else
5660 reloadnum
5661 = push_reload (x, NULL_RTX, loc, (rtx*) 0,
5662 context_reg_class,
5663 GET_MODE (x), GET_MODE (x), 0, 0,
5664 opnum, type);
5665 rld[reloadnum].inc
5666 = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0));
5668 value = 1;
5671 update_auto_inc_notes (this_insn, REGNO (XEXP (x_orig, 0)),
5672 reloadnum);
5674 return value;
5677 else if (MEM_P (XEXP (x, 0)))
5679 /* This is probably the result of a substitution, by eliminate_regs,
5680 of an equivalent address for a pseudo that was not allocated to a
5681 hard register. Verify that the specified address is valid and
5682 reload it into a register. */
5683 /* Variable `tem' might or might not be used in FIND_REG_INC_NOTE. */
5684 rtx tem ATTRIBUTE_UNUSED = XEXP (x, 0);
5685 rtx link;
5686 int reloadnum;
5688 /* Since we know we are going to reload this item, don't decrement
5689 for the indirection level.
5691 Note that this is actually conservative: it would be slightly
5692 more efficient to use the value of SPILL_INDIRECT_LEVELS from
5693 reload1.c here. */
5694 /* We can't use ADDR_TYPE (type) here, because we need to
5695 write back the value after reading it, hence we actually
5696 need two registers. */
5697 find_reloads_address (GET_MODE (x), &XEXP (x, 0),
5698 XEXP (XEXP (x, 0), 0), &XEXP (XEXP (x, 0), 0),
5699 opnum, type, ind_levels, insn);
5701 reloadnum = push_reload (x, NULL_RTX, loc, (rtx*) 0,
5702 context_reg_class,
5703 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5704 rld[reloadnum].inc
5705 = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
5707 link = FIND_REG_INC_NOTE (this_insn, tem);
5708 if (link != 0)
5709 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5711 return 1;
5713 return 0;
5715 case TRUNCATE:
5716 case SIGN_EXTEND:
5717 case ZERO_EXTEND:
5718 /* Look for parts to reload in the inner expression and reload them
5719 too, in addition to this operation. Reloading all inner parts in
5720 addition to this one shouldn't be necessary, but at this point,
5721 we don't know if we can possibly omit any part that *can* be
5722 reloaded. Targets that are better off reloading just either part
5723 (or perhaps even a different part of an outer expression), should
5724 define LEGITIMIZE_RELOAD_ADDRESS. */
5725 find_reloads_address_1 (GET_MODE (XEXP (x, 0)), XEXP (x, 0),
5726 context, &XEXP (x, 0), opnum,
5727 type, ind_levels, insn);
5728 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5729 context_reg_class,
5730 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5731 return 1;
5733 case MEM:
5734 /* This is probably the result of a substitution, by eliminate_regs, of
5735 an equivalent address for a pseudo that was not allocated to a hard
5736 register. Verify that the specified address is valid and reload it
5737 into a register.
5739 Since we know we are going to reload this item, don't decrement for
5740 the indirection level.
5742 Note that this is actually conservative: it would be slightly more
5743 efficient to use the value of SPILL_INDIRECT_LEVELS from
5744 reload1.c here. */
5746 find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5747 opnum, ADDR_TYPE (type), ind_levels, insn);
5748 push_reload (*loc, NULL_RTX, loc, (rtx*) 0,
5749 context_reg_class,
5750 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5751 return 1;
5753 case REG:
5755 int regno = REGNO (x);
5757 if (reg_equiv_constant[regno] != 0)
5759 find_reloads_address_part (reg_equiv_constant[regno], loc,
5760 context_reg_class,
5761 GET_MODE (x), opnum, type, ind_levels);
5762 return 1;
5765 #if 0 /* This might screw code in reload1.c to delete prior output-reload
5766 that feeds this insn. */
5767 if (reg_equiv_mem[regno] != 0)
5769 push_reload (reg_equiv_mem[regno], NULL_RTX, loc, (rtx*) 0,
5770 context_reg_class,
5771 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5772 return 1;
5774 #endif
5776 if (reg_equiv_memory_loc[regno]
5777 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
5779 rtx tem = make_memloc (x, regno);
5780 if (reg_equiv_address[regno] != 0
5781 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5783 x = tem;
5784 find_reloads_address (GET_MODE (x), &x, XEXP (x, 0),
5785 &XEXP (x, 0), opnum, ADDR_TYPE (type),
5786 ind_levels, insn);
5790 if (reg_renumber[regno] >= 0)
5791 regno = reg_renumber[regno];
5793 if (regno >= FIRST_PSEUDO_REGISTER
5794 || !REG_OK_FOR_CONTEXT (context, regno, mode))
5796 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5797 context_reg_class,
5798 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5799 return 1;
5802 /* If a register appearing in an address is the subject of a CLOBBER
5803 in this insn, reload it into some other register to be safe.
5804 The CLOBBER is supposed to make the register unavailable
5805 from before this insn to after it. */
5806 if (regno_clobbered_p (regno, this_insn, GET_MODE (x), 0))
5808 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5809 context_reg_class,
5810 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5811 return 1;
5814 return 0;
5816 case SUBREG:
5817 if (REG_P (SUBREG_REG (x)))
5819 /* If this is a SUBREG of a hard register and the resulting register
5820 is of the wrong class, reload the whole SUBREG. This avoids
5821 needless copies if SUBREG_REG is multi-word. */
5822 if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5824 int regno ATTRIBUTE_UNUSED = subreg_regno (x);
5826 if (! REG_OK_FOR_CONTEXT (context, regno, mode))
5828 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5829 context_reg_class,
5830 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5831 return 1;
5834 /* If this is a SUBREG of a pseudo-register, and the pseudo-register
5835 is larger than the class size, then reload the whole SUBREG. */
5836 else
5838 enum reg_class class = context_reg_class;
5839 if ((unsigned) CLASS_MAX_NREGS (class, GET_MODE (SUBREG_REG (x)))
5840 > reg_class_size[class])
5842 x = find_reloads_subreg_address (x, 0, opnum,
5843 ADDR_TYPE (type),
5844 ind_levels, insn);
5845 push_reload (x, NULL_RTX, loc, (rtx*) 0, class,
5846 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5847 return 1;
5851 break;
5853 default:
5854 break;
5858 const char *fmt = GET_RTX_FORMAT (code);
5859 int i;
5861 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5863 if (fmt[i] == 'e')
5864 find_reloads_address_1 (mode, XEXP (x, i), context, &XEXP (x, i),
5865 opnum, type, ind_levels, insn);
5869 #undef REG_OK_FOR_CONTEXT
5870 return 0;
5873 /* X, which is found at *LOC, is a part of an address that needs to be
5874 reloaded into a register of class CLASS. If X is a constant, or if
5875 X is a PLUS that contains a constant, check that the constant is a
5876 legitimate operand and that we are supposed to be able to load
5877 it into the register.
5879 If not, force the constant into memory and reload the MEM instead.
5881 MODE is the mode to use, in case X is an integer constant.
5883 OPNUM and TYPE describe the purpose of any reloads made.
5885 IND_LEVELS says how many levels of indirect addressing this machine
5886 supports. */
5888 static void
5889 find_reloads_address_part (rtx x, rtx *loc, enum reg_class class,
5890 enum machine_mode mode, int opnum,
5891 enum reload_type type, int ind_levels)
5893 if (CONSTANT_P (x)
5894 && (! LEGITIMATE_CONSTANT_P (x)
5895 || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
5897 rtx tem;
5899 tem = x = force_const_mem (mode, x);
5900 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5901 opnum, type, ind_levels, 0);
5904 else if (GET_CODE (x) == PLUS
5905 && CONSTANT_P (XEXP (x, 1))
5906 && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
5907 || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
5909 rtx tem;
5911 tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
5912 x = gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), tem);
5913 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5914 opnum, type, ind_levels, 0);
5917 push_reload (x, NULL_RTX, loc, (rtx*) 0, class,
5918 mode, VOIDmode, 0, 0, opnum, type);
5921 /* X, a subreg of a pseudo, is a part of an address that needs to be
5922 reloaded.
5924 If the pseudo is equivalent to a memory location that cannot be directly
5925 addressed, make the necessary address reloads.
5927 If address reloads have been necessary, or if the address is changed
5928 by register elimination, return the rtx of the memory location;
5929 otherwise, return X.
5931 If FORCE_REPLACE is nonzero, unconditionally replace the subreg with the
5932 memory location.
5934 OPNUM and TYPE identify the purpose of the reload.
5936 IND_LEVELS says how many levels of indirect addressing are
5937 supported at this point in the address.
5939 INSN, if nonzero, is the insn in which we do the reload. It is used
5940 to determine where to put USEs for pseudos that we have to replace with
5941 stack slots. */
5943 static rtx
5944 find_reloads_subreg_address (rtx x, int force_replace, int opnum,
5945 enum reload_type type, int ind_levels, rtx insn)
5947 int regno = REGNO (SUBREG_REG (x));
5949 if (reg_equiv_memory_loc[regno])
5951 /* If the address is not directly addressable, or if the address is not
5952 offsettable, then it must be replaced. */
5953 if (! force_replace
5954 && (reg_equiv_address[regno]
5955 || ! offsettable_memref_p (reg_equiv_mem[regno])))
5956 force_replace = 1;
5958 if (force_replace || num_not_at_initial_offset)
5960 rtx tem = make_memloc (SUBREG_REG (x), regno);
5962 /* If the address changes because of register elimination, then
5963 it must be replaced. */
5964 if (force_replace
5965 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5967 unsigned outer_size = GET_MODE_SIZE (GET_MODE (x));
5968 unsigned inner_size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
5969 int offset;
5970 enum machine_mode orig_mode = GET_MODE (tem);
5971 int reloaded;
5973 /* For big-endian paradoxical subregs, SUBREG_BYTE does not
5974 hold the correct (negative) byte offset. */
5975 if (BYTES_BIG_ENDIAN && outer_size > inner_size)
5976 offset = inner_size - outer_size;
5977 else
5978 offset = SUBREG_BYTE (x);
5980 XEXP (tem, 0) = plus_constant (XEXP (tem, 0), offset);
5981 PUT_MODE (tem, GET_MODE (x));
5983 /* If this was a paradoxical subreg that we replaced, the
5984 resulting memory must be sufficiently aligned to allow
5985 us to widen the mode of the memory. */
5986 if (outer_size > inner_size)
5988 rtx base;
5990 base = XEXP (tem, 0);
5991 if (GET_CODE (base) == PLUS)
5993 if (GET_CODE (XEXP (base, 1)) == CONST_INT
5994 && INTVAL (XEXP (base, 1)) % outer_size != 0)
5995 return x;
5996 base = XEXP (base, 0);
5998 if (!REG_P (base)
5999 || (REGNO_POINTER_ALIGN (REGNO (base))
6000 < outer_size * BITS_PER_UNIT))
6001 return x;
6004 reloaded = find_reloads_address (GET_MODE (tem), &tem,
6005 XEXP (tem, 0), &XEXP (tem, 0),
6006 opnum, type, ind_levels, insn);
6008 /* For some processors an address may be valid in the
6009 original mode but not in a smaller mode. For
6010 example, ARM accepts a scaled index register in
6011 SImode but not in HImode. find_reloads_address
6012 assumes that we pass it a valid address, and doesn't
6013 force a reload. This will probably be fine if
6014 find_reloads_address finds some reloads. But if it
6015 doesn't find any, then we may have just converted a
6016 valid address into an invalid one. Check for that
6017 here. */
6018 if (reloaded != 1
6019 && strict_memory_address_p (orig_mode, XEXP (tem, 0))
6020 && !strict_memory_address_p (GET_MODE (tem),
6021 XEXP (tem, 0)))
6022 push_reload (XEXP (tem, 0), NULL_RTX, &XEXP (tem, 0), (rtx*) 0,
6023 MODE_BASE_REG_CLASS (GET_MODE (tem)),
6024 GET_MODE (XEXP (tem, 0)), VOIDmode, 0, 0,
6025 opnum, type);
6027 /* If this is not a toplevel operand, find_reloads doesn't see
6028 this substitution. We have to emit a USE of the pseudo so
6029 that delete_output_reload can see it. */
6030 if (replace_reloads && recog_data.operand[opnum] != x)
6031 /* We mark the USE with QImode so that we recognize it
6032 as one that can be safely deleted at the end of
6033 reload. */
6034 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode,
6035 SUBREG_REG (x)),
6036 insn), QImode);
6037 x = tem;
6041 return x;
6044 /* Substitute into the current INSN the registers into which we have reloaded
6045 the things that need reloading. The array `replacements'
6046 contains the locations of all pointers that must be changed
6047 and says what to replace them with.
6049 Return the rtx that X translates into; usually X, but modified. */
6051 void
6052 subst_reloads (rtx insn)
6054 int i;
6056 for (i = 0; i < n_replacements; i++)
6058 struct replacement *r = &replacements[i];
6059 rtx reloadreg = rld[r->what].reg_rtx;
6060 if (reloadreg)
6062 #ifdef ENABLE_CHECKING
6063 /* Internal consistency test. Check that we don't modify
6064 anything in the equivalence arrays. Whenever something from
6065 those arrays needs to be reloaded, it must be unshared before
6066 being substituted into; the equivalence must not be modified.
6067 Otherwise, if the equivalence is used after that, it will
6068 have been modified, and the thing substituted (probably a
6069 register) is likely overwritten and not a usable equivalence. */
6070 int check_regno;
6072 for (check_regno = 0; check_regno < max_regno; check_regno++)
6074 #define CHECK_MODF(ARRAY) \
6075 gcc_assert (!ARRAY[check_regno] \
6076 || !loc_mentioned_in_p (r->where, \
6077 ARRAY[check_regno]))
6079 CHECK_MODF (reg_equiv_constant);
6080 CHECK_MODF (reg_equiv_memory_loc);
6081 CHECK_MODF (reg_equiv_address);
6082 CHECK_MODF (reg_equiv_mem);
6083 #undef CHECK_MODF
6085 #endif /* ENABLE_CHECKING */
6087 /* If we're replacing a LABEL_REF with a register, add a
6088 REG_LABEL note to indicate to flow which label this
6089 register refers to. */
6090 if (GET_CODE (*r->where) == LABEL_REF
6091 && JUMP_P (insn))
6093 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL,
6094 XEXP (*r->where, 0),
6095 REG_NOTES (insn));
6096 JUMP_LABEL (insn) = XEXP (*r->where, 0);
6099 /* Encapsulate RELOADREG so its machine mode matches what
6100 used to be there. Note that gen_lowpart_common will
6101 do the wrong thing if RELOADREG is multi-word. RELOADREG
6102 will always be a REG here. */
6103 if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
6104 reloadreg = reload_adjust_reg_for_mode (reloadreg, r->mode);
6106 /* If we are putting this into a SUBREG and RELOADREG is a
6107 SUBREG, we would be making nested SUBREGs, so we have to fix
6108 this up. Note that r->where == &SUBREG_REG (*r->subreg_loc). */
6110 if (r->subreg_loc != 0 && GET_CODE (reloadreg) == SUBREG)
6112 if (GET_MODE (*r->subreg_loc)
6113 == GET_MODE (SUBREG_REG (reloadreg)))
6114 *r->subreg_loc = SUBREG_REG (reloadreg);
6115 else
6117 int final_offset =
6118 SUBREG_BYTE (*r->subreg_loc) + SUBREG_BYTE (reloadreg);
6120 /* When working with SUBREGs the rule is that the byte
6121 offset must be a multiple of the SUBREG's mode. */
6122 final_offset = (final_offset /
6123 GET_MODE_SIZE (GET_MODE (*r->subreg_loc)));
6124 final_offset = (final_offset *
6125 GET_MODE_SIZE (GET_MODE (*r->subreg_loc)));
6127 *r->where = SUBREG_REG (reloadreg);
6128 SUBREG_BYTE (*r->subreg_loc) = final_offset;
6131 else
6132 *r->where = reloadreg;
6134 /* If reload got no reg and isn't optional, something's wrong. */
6135 else
6136 gcc_assert (rld[r->what].optional);
6140 /* Make a copy of any replacements being done into X and move those
6141 copies to locations in Y, a copy of X. */
6143 void
6144 copy_replacements (rtx x, rtx y)
6146 /* We can't support X being a SUBREG because we might then need to know its
6147 location if something inside it was replaced. */
6148 gcc_assert (GET_CODE (x) != SUBREG);
6150 copy_replacements_1 (&x, &y, n_replacements);
6153 static void
6154 copy_replacements_1 (rtx *px, rtx *py, int orig_replacements)
6156 int i, j;
6157 rtx x, y;
6158 struct replacement *r;
6159 enum rtx_code code;
6160 const char *fmt;
6162 for (j = 0; j < orig_replacements; j++)
6164 if (replacements[j].subreg_loc == px)
6166 r = &replacements[n_replacements++];
6167 r->where = replacements[j].where;
6168 r->subreg_loc = py;
6169 r->what = replacements[j].what;
6170 r->mode = replacements[j].mode;
6172 else if (replacements[j].where == px)
6174 r = &replacements[n_replacements++];
6175 r->where = py;
6176 r->subreg_loc = 0;
6177 r->what = replacements[j].what;
6178 r->mode = replacements[j].mode;
6182 x = *px;
6183 y = *py;
6184 code = GET_CODE (x);
6185 fmt = GET_RTX_FORMAT (code);
6187 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6189 if (fmt[i] == 'e')
6190 copy_replacements_1 (&XEXP (x, i), &XEXP (y, i), orig_replacements);
6191 else if (fmt[i] == 'E')
6192 for (j = XVECLEN (x, i); --j >= 0; )
6193 copy_replacements_1 (&XVECEXP (x, i, j), &XVECEXP (y, i, j),
6194 orig_replacements);
6198 /* Change any replacements being done to *X to be done to *Y. */
6200 void
6201 move_replacements (rtx *x, rtx *y)
6203 int i;
6205 for (i = 0; i < n_replacements; i++)
6206 if (replacements[i].subreg_loc == x)
6207 replacements[i].subreg_loc = y;
6208 else if (replacements[i].where == x)
6210 replacements[i].where = y;
6211 replacements[i].subreg_loc = 0;
6215 /* If LOC was scheduled to be replaced by something, return the replacement.
6216 Otherwise, return *LOC. */
6219 find_replacement (rtx *loc)
6221 struct replacement *r;
6223 for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
6225 rtx reloadreg = rld[r->what].reg_rtx;
6227 if (reloadreg && r->where == loc)
6229 if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
6230 reloadreg = gen_rtx_REG (r->mode, REGNO (reloadreg));
6232 return reloadreg;
6234 else if (reloadreg && r->subreg_loc == loc)
6236 /* RELOADREG must be either a REG or a SUBREG.
6238 ??? Is it actually still ever a SUBREG? If so, why? */
6240 if (REG_P (reloadreg))
6241 return gen_rtx_REG (GET_MODE (*loc),
6242 (REGNO (reloadreg) +
6243 subreg_regno_offset (REGNO (SUBREG_REG (*loc)),
6244 GET_MODE (SUBREG_REG (*loc)),
6245 SUBREG_BYTE (*loc),
6246 GET_MODE (*loc))));
6247 else if (GET_MODE (reloadreg) == GET_MODE (*loc))
6248 return reloadreg;
6249 else
6251 int final_offset = SUBREG_BYTE (reloadreg) + SUBREG_BYTE (*loc);
6253 /* When working with SUBREGs the rule is that the byte
6254 offset must be a multiple of the SUBREG's mode. */
6255 final_offset = (final_offset / GET_MODE_SIZE (GET_MODE (*loc)));
6256 final_offset = (final_offset * GET_MODE_SIZE (GET_MODE (*loc)));
6257 return gen_rtx_SUBREG (GET_MODE (*loc), SUBREG_REG (reloadreg),
6258 final_offset);
6263 /* If *LOC is a PLUS, MINUS, or MULT, see if a replacement is scheduled for
6264 what's inside and make a new rtl if so. */
6265 if (GET_CODE (*loc) == PLUS || GET_CODE (*loc) == MINUS
6266 || GET_CODE (*loc) == MULT)
6268 rtx x = find_replacement (&XEXP (*loc, 0));
6269 rtx y = find_replacement (&XEXP (*loc, 1));
6271 if (x != XEXP (*loc, 0) || y != XEXP (*loc, 1))
6272 return gen_rtx_fmt_ee (GET_CODE (*loc), GET_MODE (*loc), x, y);
6275 return *loc;
6278 /* Return nonzero if register in range [REGNO, ENDREGNO)
6279 appears either explicitly or implicitly in X
6280 other than being stored into (except for earlyclobber operands).
6282 References contained within the substructure at LOC do not count.
6283 LOC may be zero, meaning don't ignore anything.
6285 This is similar to refers_to_regno_p in rtlanal.c except that we
6286 look at equivalences for pseudos that didn't get hard registers. */
6288 static int
6289 refers_to_regno_for_reload_p (unsigned int regno, unsigned int endregno,
6290 rtx x, rtx *loc)
6292 int i;
6293 unsigned int r;
6294 RTX_CODE code;
6295 const char *fmt;
6297 if (x == 0)
6298 return 0;
6300 repeat:
6301 code = GET_CODE (x);
6303 switch (code)
6305 case REG:
6306 r = REGNO (x);
6308 /* If this is a pseudo, a hard register must not have been allocated.
6309 X must therefore either be a constant or be in memory. */
6310 if (r >= FIRST_PSEUDO_REGISTER)
6312 if (reg_equiv_memory_loc[r])
6313 return refers_to_regno_for_reload_p (regno, endregno,
6314 reg_equiv_memory_loc[r],
6315 (rtx*) 0);
6317 gcc_assert (reg_equiv_constant[r]
6318 || (reg_equiv_invariant[r] && reg_equiv_init[r]));
6319 return 0;
6322 return (endregno > r
6323 && regno < r + (r < FIRST_PSEUDO_REGISTER
6324 ? hard_regno_nregs[r][GET_MODE (x)]
6325 : 1));
6327 case SUBREG:
6328 /* If this is a SUBREG of a hard reg, we can see exactly which
6329 registers are being modified. Otherwise, handle normally. */
6330 if (REG_P (SUBREG_REG (x))
6331 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
6333 unsigned int inner_regno = subreg_regno (x);
6334 unsigned int inner_endregno
6335 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
6336 ? hard_regno_nregs[inner_regno][GET_MODE (x)] : 1);
6338 return endregno > inner_regno && regno < inner_endregno;
6340 break;
6342 case CLOBBER:
6343 case SET:
6344 if (&SET_DEST (x) != loc
6345 /* Note setting a SUBREG counts as referring to the REG it is in for
6346 a pseudo but not for hard registers since we can
6347 treat each word individually. */
6348 && ((GET_CODE (SET_DEST (x)) == SUBREG
6349 && loc != &SUBREG_REG (SET_DEST (x))
6350 && REG_P (SUBREG_REG (SET_DEST (x)))
6351 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
6352 && refers_to_regno_for_reload_p (regno, endregno,
6353 SUBREG_REG (SET_DEST (x)),
6354 loc))
6355 /* If the output is an earlyclobber operand, this is
6356 a conflict. */
6357 || ((!REG_P (SET_DEST (x))
6358 || earlyclobber_operand_p (SET_DEST (x)))
6359 && refers_to_regno_for_reload_p (regno, endregno,
6360 SET_DEST (x), loc))))
6361 return 1;
6363 if (code == CLOBBER || loc == &SET_SRC (x))
6364 return 0;
6365 x = SET_SRC (x);
6366 goto repeat;
6368 default:
6369 break;
6372 /* X does not match, so try its subexpressions. */
6374 fmt = GET_RTX_FORMAT (code);
6375 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6377 if (fmt[i] == 'e' && loc != &XEXP (x, i))
6379 if (i == 0)
6381 x = XEXP (x, 0);
6382 goto repeat;
6384 else
6385 if (refers_to_regno_for_reload_p (regno, endregno,
6386 XEXP (x, i), loc))
6387 return 1;
6389 else if (fmt[i] == 'E')
6391 int j;
6392 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6393 if (loc != &XVECEXP (x, i, j)
6394 && refers_to_regno_for_reload_p (regno, endregno,
6395 XVECEXP (x, i, j), loc))
6396 return 1;
6399 return 0;
6402 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
6403 we check if any register number in X conflicts with the relevant register
6404 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
6405 contains a MEM (we don't bother checking for memory addresses that can't
6406 conflict because we expect this to be a rare case.
6408 This function is similar to reg_overlap_mentioned_p in rtlanal.c except
6409 that we look at equivalences for pseudos that didn't get hard registers. */
6412 reg_overlap_mentioned_for_reload_p (rtx x, rtx in)
6414 int regno, endregno;
6416 /* Overly conservative. */
6417 if (GET_CODE (x) == STRICT_LOW_PART
6418 || GET_RTX_CLASS (GET_CODE (x)) == RTX_AUTOINC)
6419 x = XEXP (x, 0);
6421 /* If either argument is a constant, then modifying X can not affect IN. */
6422 if (CONSTANT_P (x) || CONSTANT_P (in))
6423 return 0;
6424 else if (GET_CODE (x) == SUBREG)
6426 regno = REGNO (SUBREG_REG (x));
6427 if (regno < FIRST_PSEUDO_REGISTER)
6428 regno += subreg_regno_offset (REGNO (SUBREG_REG (x)),
6429 GET_MODE (SUBREG_REG (x)),
6430 SUBREG_BYTE (x),
6431 GET_MODE (x));
6433 else if (REG_P (x))
6435 regno = REGNO (x);
6437 /* If this is a pseudo, it must not have been assigned a hard register.
6438 Therefore, it must either be in memory or be a constant. */
6440 if (regno >= FIRST_PSEUDO_REGISTER)
6442 if (reg_equiv_memory_loc[regno])
6443 return refers_to_mem_for_reload_p (in);
6444 gcc_assert (reg_equiv_constant[regno]);
6445 return 0;
6448 else if (MEM_P (x))
6449 return refers_to_mem_for_reload_p (in);
6450 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
6451 || GET_CODE (x) == CC0)
6452 return reg_mentioned_p (x, in);
6453 else
6455 gcc_assert (GET_CODE (x) == PLUS);
6457 /* We actually want to know if X is mentioned somewhere inside IN.
6458 We must not say that (plus (sp) (const_int 124)) is in
6459 (plus (sp) (const_int 64)), since that can lead to incorrect reload
6460 allocation when spuriously changing a RELOAD_FOR_OUTPUT_ADDRESS
6461 into a RELOAD_OTHER on behalf of another RELOAD_OTHER. */
6462 while (MEM_P (in))
6463 in = XEXP (in, 0);
6464 if (REG_P (in))
6465 return 0;
6466 else if (GET_CODE (in) == PLUS)
6467 return (rtx_equal_p (x, in)
6468 || reg_overlap_mentioned_for_reload_p (x, XEXP (in, 0))
6469 || reg_overlap_mentioned_for_reload_p (x, XEXP (in, 1)));
6470 else return (reg_overlap_mentioned_for_reload_p (XEXP (x, 0), in)
6471 || reg_overlap_mentioned_for_reload_p (XEXP (x, 1), in));
6474 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
6475 ? hard_regno_nregs[regno][GET_MODE (x)] : 1);
6477 return refers_to_regno_for_reload_p (regno, endregno, in, (rtx*) 0);
6480 /* Return nonzero if anything in X contains a MEM. Look also for pseudo
6481 registers. */
6483 static int
6484 refers_to_mem_for_reload_p (rtx x)
6486 const char *fmt;
6487 int i;
6489 if (MEM_P (x))
6490 return 1;
6492 if (REG_P (x))
6493 return (REGNO (x) >= FIRST_PSEUDO_REGISTER
6494 && reg_equiv_memory_loc[REGNO (x)]);
6496 fmt = GET_RTX_FORMAT (GET_CODE (x));
6497 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
6498 if (fmt[i] == 'e'
6499 && (MEM_P (XEXP (x, i))
6500 || refers_to_mem_for_reload_p (XEXP (x, i))))
6501 return 1;
6503 return 0;
6506 /* Check the insns before INSN to see if there is a suitable register
6507 containing the same value as GOAL.
6508 If OTHER is -1, look for a register in class CLASS.
6509 Otherwise, just see if register number OTHER shares GOAL's value.
6511 Return an rtx for the register found, or zero if none is found.
6513 If RELOAD_REG_P is (short *)1,
6514 we reject any hard reg that appears in reload_reg_rtx
6515 because such a hard reg is also needed coming into this insn.
6517 If RELOAD_REG_P is any other nonzero value,
6518 it is a vector indexed by hard reg number
6519 and we reject any hard reg whose element in the vector is nonnegative
6520 as well as any that appears in reload_reg_rtx.
6522 If GOAL is zero, then GOALREG is a register number; we look
6523 for an equivalent for that register.
6525 MODE is the machine mode of the value we want an equivalence for.
6526 If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
6528 This function is used by jump.c as well as in the reload pass.
6530 If GOAL is the sum of the stack pointer and a constant, we treat it
6531 as if it were a constant except that sp is required to be unchanging. */
6534 find_equiv_reg (rtx goal, rtx insn, enum reg_class class, int other,
6535 short *reload_reg_p, int goalreg, enum machine_mode mode)
6537 rtx p = insn;
6538 rtx goaltry, valtry, value, where;
6539 rtx pat;
6540 int regno = -1;
6541 int valueno;
6542 int goal_mem = 0;
6543 int goal_const = 0;
6544 int goal_mem_addr_varies = 0;
6545 int need_stable_sp = 0;
6546 int nregs;
6547 int valuenregs;
6548 int num = 0;
6550 if (goal == 0)
6551 regno = goalreg;
6552 else if (REG_P (goal))
6553 regno = REGNO (goal);
6554 else if (MEM_P (goal))
6556 enum rtx_code code = GET_CODE (XEXP (goal, 0));
6557 if (MEM_VOLATILE_P (goal))
6558 return 0;
6559 if (flag_float_store && GET_MODE_CLASS (GET_MODE (goal)) == MODE_FLOAT)
6560 return 0;
6561 /* An address with side effects must be reexecuted. */
6562 switch (code)
6564 case POST_INC:
6565 case PRE_INC:
6566 case POST_DEC:
6567 case PRE_DEC:
6568 case POST_MODIFY:
6569 case PRE_MODIFY:
6570 return 0;
6571 default:
6572 break;
6574 goal_mem = 1;
6576 else if (CONSTANT_P (goal))
6577 goal_const = 1;
6578 else if (GET_CODE (goal) == PLUS
6579 && XEXP (goal, 0) == stack_pointer_rtx
6580 && CONSTANT_P (XEXP (goal, 1)))
6581 goal_const = need_stable_sp = 1;
6582 else if (GET_CODE (goal) == PLUS
6583 && XEXP (goal, 0) == frame_pointer_rtx
6584 && CONSTANT_P (XEXP (goal, 1)))
6585 goal_const = 1;
6586 else
6587 return 0;
6589 num = 0;
6590 /* Scan insns back from INSN, looking for one that copies
6591 a value into or out of GOAL.
6592 Stop and give up if we reach a label. */
6594 while (1)
6596 p = PREV_INSN (p);
6597 num++;
6598 if (p == 0 || LABEL_P (p)
6599 || num > PARAM_VALUE (PARAM_MAX_RELOAD_SEARCH_INSNS))
6600 return 0;
6602 if (NONJUMP_INSN_P (p)
6603 /* If we don't want spill regs ... */
6604 && (! (reload_reg_p != 0
6605 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6606 /* ... then ignore insns introduced by reload; they aren't
6607 useful and can cause results in reload_as_needed to be
6608 different from what they were when calculating the need for
6609 spills. If we notice an input-reload insn here, we will
6610 reject it below, but it might hide a usable equivalent.
6611 That makes bad code. It may even fail: perhaps no reg was
6612 spilled for this insn because it was assumed we would find
6613 that equivalent. */
6614 || INSN_UID (p) < reload_first_uid))
6616 rtx tem;
6617 pat = single_set (p);
6619 /* First check for something that sets some reg equal to GOAL. */
6620 if (pat != 0
6621 && ((regno >= 0
6622 && true_regnum (SET_SRC (pat)) == regno
6623 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6625 (regno >= 0
6626 && true_regnum (SET_DEST (pat)) == regno
6627 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0)
6629 (goal_const && rtx_equal_p (SET_SRC (pat), goal)
6630 /* When looking for stack pointer + const,
6631 make sure we don't use a stack adjust. */
6632 && !reg_overlap_mentioned_for_reload_p (SET_DEST (pat), goal)
6633 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6634 || (goal_mem
6635 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0
6636 && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
6637 || (goal_mem
6638 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0
6639 && rtx_renumbered_equal_p (goal, SET_DEST (pat)))
6640 /* If we are looking for a constant,
6641 and something equivalent to that constant was copied
6642 into a reg, we can use that reg. */
6643 || (goal_const && REG_NOTES (p) != 0
6644 && (tem = find_reg_note (p, REG_EQUIV, NULL_RTX))
6645 && ((rtx_equal_p (XEXP (tem, 0), goal)
6646 && (valueno
6647 = true_regnum (valtry = SET_DEST (pat))) >= 0)
6648 || (REG_P (SET_DEST (pat))
6649 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6650 && (GET_MODE_CLASS (GET_MODE (XEXP (tem, 0)))
6651 == MODE_FLOAT)
6652 && GET_CODE (goal) == CONST_INT
6653 && 0 != (goaltry
6654 = operand_subword (XEXP (tem, 0), 0, 0,
6655 VOIDmode))
6656 && rtx_equal_p (goal, goaltry)
6657 && (valtry
6658 = operand_subword (SET_DEST (pat), 0, 0,
6659 VOIDmode))
6660 && (valueno = true_regnum (valtry)) >= 0)))
6661 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
6662 NULL_RTX))
6663 && REG_P (SET_DEST (pat))
6664 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6665 && (GET_MODE_CLASS (GET_MODE (XEXP (tem, 0)))
6666 == MODE_FLOAT)
6667 && GET_CODE (goal) == CONST_INT
6668 && 0 != (goaltry = operand_subword (XEXP (tem, 0), 1, 0,
6669 VOIDmode))
6670 && rtx_equal_p (goal, goaltry)
6671 && (valtry
6672 = operand_subword (SET_DEST (pat), 1, 0, VOIDmode))
6673 && (valueno = true_regnum (valtry)) >= 0)))
6675 if (other >= 0)
6677 if (valueno != other)
6678 continue;
6680 else if ((unsigned) valueno >= FIRST_PSEUDO_REGISTER)
6681 continue;
6682 else
6684 int i;
6686 for (i = hard_regno_nregs[valueno][mode] - 1; i >= 0; i--)
6687 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
6688 valueno + i))
6689 break;
6690 if (i >= 0)
6691 continue;
6693 value = valtry;
6694 where = p;
6695 break;
6700 /* We found a previous insn copying GOAL into a suitable other reg VALUE
6701 (or copying VALUE into GOAL, if GOAL is also a register).
6702 Now verify that VALUE is really valid. */
6704 /* VALUENO is the register number of VALUE; a hard register. */
6706 /* Don't try to re-use something that is killed in this insn. We want
6707 to be able to trust REG_UNUSED notes. */
6708 if (REG_NOTES (where) != 0 && find_reg_note (where, REG_UNUSED, value))
6709 return 0;
6711 /* If we propose to get the value from the stack pointer or if GOAL is
6712 a MEM based on the stack pointer, we need a stable SP. */
6713 if (valueno == STACK_POINTER_REGNUM || regno == STACK_POINTER_REGNUM
6714 || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx,
6715 goal)))
6716 need_stable_sp = 1;
6718 /* Reject VALUE if the copy-insn moved the wrong sort of datum. */
6719 if (GET_MODE (value) != mode)
6720 return 0;
6722 /* Reject VALUE if it was loaded from GOAL
6723 and is also a register that appears in the address of GOAL. */
6725 if (goal_mem && value == SET_DEST (single_set (where))
6726 && refers_to_regno_for_reload_p (valueno,
6727 (valueno
6728 + hard_regno_nregs[valueno][mode]),
6729 goal, (rtx*) 0))
6730 return 0;
6732 /* Reject registers that overlap GOAL. */
6734 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
6735 nregs = hard_regno_nregs[regno][mode];
6736 else
6737 nregs = 1;
6738 valuenregs = hard_regno_nregs[valueno][mode];
6740 if (!goal_mem && !goal_const
6741 && regno + nregs > valueno && regno < valueno + valuenregs)
6742 return 0;
6744 /* Reject VALUE if it is one of the regs reserved for reloads.
6745 Reload1 knows how to reuse them anyway, and it would get
6746 confused if we allocated one without its knowledge.
6747 (Now that insns introduced by reload are ignored above,
6748 this case shouldn't happen, but I'm not positive.) */
6750 if (reload_reg_p != 0 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6752 int i;
6753 for (i = 0; i < valuenregs; ++i)
6754 if (reload_reg_p[valueno + i] >= 0)
6755 return 0;
6758 /* Reject VALUE if it is a register being used for an input reload
6759 even if it is not one of those reserved. */
6761 if (reload_reg_p != 0)
6763 int i;
6764 for (i = 0; i < n_reloads; i++)
6765 if (rld[i].reg_rtx != 0 && rld[i].in)
6767 int regno1 = REGNO (rld[i].reg_rtx);
6768 int nregs1 = hard_regno_nregs[regno1]
6769 [GET_MODE (rld[i].reg_rtx)];
6770 if (regno1 < valueno + valuenregs
6771 && regno1 + nregs1 > valueno)
6772 return 0;
6776 if (goal_mem)
6777 /* We must treat frame pointer as varying here,
6778 since it can vary--in a nonlocal goto as generated by expand_goto. */
6779 goal_mem_addr_varies = !CONSTANT_ADDRESS_P (XEXP (goal, 0));
6781 /* Now verify that the values of GOAL and VALUE remain unaltered
6782 until INSN is reached. */
6784 p = insn;
6785 while (1)
6787 p = PREV_INSN (p);
6788 if (p == where)
6789 return value;
6791 /* Don't trust the conversion past a function call
6792 if either of the two is in a call-clobbered register, or memory. */
6793 if (CALL_P (p))
6795 int i;
6797 if (goal_mem || need_stable_sp)
6798 return 0;
6800 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
6801 for (i = 0; i < nregs; ++i)
6802 if (call_used_regs[regno + i]
6803 || HARD_REGNO_CALL_PART_CLOBBERED (regno + i, mode))
6804 return 0;
6806 if (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER)
6807 for (i = 0; i < valuenregs; ++i)
6808 if (call_used_regs[valueno + i]
6809 || HARD_REGNO_CALL_PART_CLOBBERED (valueno + i, mode))
6810 return 0;
6813 if (INSN_P (p))
6815 pat = PATTERN (p);
6817 /* Watch out for unspec_volatile, and volatile asms. */
6818 if (volatile_insn_p (pat))
6819 return 0;
6821 /* If this insn P stores in either GOAL or VALUE, return 0.
6822 If GOAL is a memory ref and this insn writes memory, return 0.
6823 If GOAL is a memory ref and its address is not constant,
6824 and this insn P changes a register used in GOAL, return 0. */
6826 if (GET_CODE (pat) == COND_EXEC)
6827 pat = COND_EXEC_CODE (pat);
6828 if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
6830 rtx dest = SET_DEST (pat);
6831 while (GET_CODE (dest) == SUBREG
6832 || GET_CODE (dest) == ZERO_EXTRACT
6833 || GET_CODE (dest) == STRICT_LOW_PART)
6834 dest = XEXP (dest, 0);
6835 if (REG_P (dest))
6837 int xregno = REGNO (dest);
6838 int xnregs;
6839 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6840 xnregs = hard_regno_nregs[xregno][GET_MODE (dest)];
6841 else
6842 xnregs = 1;
6843 if (xregno < regno + nregs && xregno + xnregs > regno)
6844 return 0;
6845 if (xregno < valueno + valuenregs
6846 && xregno + xnregs > valueno)
6847 return 0;
6848 if (goal_mem_addr_varies
6849 && reg_overlap_mentioned_for_reload_p (dest, goal))
6850 return 0;
6851 if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6852 return 0;
6854 else if (goal_mem && MEM_P (dest)
6855 && ! push_operand (dest, GET_MODE (dest)))
6856 return 0;
6857 else if (MEM_P (dest) && regno >= FIRST_PSEUDO_REGISTER
6858 && reg_equiv_memory_loc[regno] != 0)
6859 return 0;
6860 else if (need_stable_sp && push_operand (dest, GET_MODE (dest)))
6861 return 0;
6863 else if (GET_CODE (pat) == PARALLEL)
6865 int i;
6866 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
6868 rtx v1 = XVECEXP (pat, 0, i);
6869 if (GET_CODE (v1) == COND_EXEC)
6870 v1 = COND_EXEC_CODE (v1);
6871 if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
6873 rtx dest = SET_DEST (v1);
6874 while (GET_CODE (dest) == SUBREG
6875 || GET_CODE (dest) == ZERO_EXTRACT
6876 || GET_CODE (dest) == STRICT_LOW_PART)
6877 dest = XEXP (dest, 0);
6878 if (REG_P (dest))
6880 int xregno = REGNO (dest);
6881 int xnregs;
6882 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6883 xnregs = hard_regno_nregs[xregno][GET_MODE (dest)];
6884 else
6885 xnregs = 1;
6886 if (xregno < regno + nregs
6887 && xregno + xnregs > regno)
6888 return 0;
6889 if (xregno < valueno + valuenregs
6890 && xregno + xnregs > valueno)
6891 return 0;
6892 if (goal_mem_addr_varies
6893 && reg_overlap_mentioned_for_reload_p (dest,
6894 goal))
6895 return 0;
6896 if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6897 return 0;
6899 else if (goal_mem && MEM_P (dest)
6900 && ! push_operand (dest, GET_MODE (dest)))
6901 return 0;
6902 else if (MEM_P (dest) && regno >= FIRST_PSEUDO_REGISTER
6903 && reg_equiv_memory_loc[regno] != 0)
6904 return 0;
6905 else if (need_stable_sp
6906 && push_operand (dest, GET_MODE (dest)))
6907 return 0;
6912 if (CALL_P (p) && CALL_INSN_FUNCTION_USAGE (p))
6914 rtx link;
6916 for (link = CALL_INSN_FUNCTION_USAGE (p); XEXP (link, 1) != 0;
6917 link = XEXP (link, 1))
6919 pat = XEXP (link, 0);
6920 if (GET_CODE (pat) == CLOBBER)
6922 rtx dest = SET_DEST (pat);
6924 if (REG_P (dest))
6926 int xregno = REGNO (dest);
6927 int xnregs
6928 = hard_regno_nregs[xregno][GET_MODE (dest)];
6930 if (xregno < regno + nregs
6931 && xregno + xnregs > regno)
6932 return 0;
6933 else if (xregno < valueno + valuenregs
6934 && xregno + xnregs > valueno)
6935 return 0;
6936 else if (goal_mem_addr_varies
6937 && reg_overlap_mentioned_for_reload_p (dest,
6938 goal))
6939 return 0;
6942 else if (goal_mem && MEM_P (dest)
6943 && ! push_operand (dest, GET_MODE (dest)))
6944 return 0;
6945 else if (need_stable_sp
6946 && push_operand (dest, GET_MODE (dest)))
6947 return 0;
6952 #ifdef AUTO_INC_DEC
6953 /* If this insn auto-increments or auto-decrements
6954 either regno or valueno, return 0 now.
6955 If GOAL is a memory ref and its address is not constant,
6956 and this insn P increments a register used in GOAL, return 0. */
6958 rtx link;
6960 for (link = REG_NOTES (p); link; link = XEXP (link, 1))
6961 if (REG_NOTE_KIND (link) == REG_INC
6962 && REG_P (XEXP (link, 0)))
6964 int incno = REGNO (XEXP (link, 0));
6965 if (incno < regno + nregs && incno >= regno)
6966 return 0;
6967 if (incno < valueno + valuenregs && incno >= valueno)
6968 return 0;
6969 if (goal_mem_addr_varies
6970 && reg_overlap_mentioned_for_reload_p (XEXP (link, 0),
6971 goal))
6972 return 0;
6975 #endif
6980 /* Find a place where INCED appears in an increment or decrement operator
6981 within X, and return the amount INCED is incremented or decremented by.
6982 The value is always positive. */
6984 static int
6985 find_inc_amount (rtx x, rtx inced)
6987 enum rtx_code code = GET_CODE (x);
6988 const char *fmt;
6989 int i;
6991 if (code == MEM)
6993 rtx addr = XEXP (x, 0);
6994 if ((GET_CODE (addr) == PRE_DEC
6995 || GET_CODE (addr) == POST_DEC
6996 || GET_CODE (addr) == PRE_INC
6997 || GET_CODE (addr) == POST_INC)
6998 && XEXP (addr, 0) == inced)
6999 return GET_MODE_SIZE (GET_MODE (x));
7000 else if ((GET_CODE (addr) == PRE_MODIFY
7001 || GET_CODE (addr) == POST_MODIFY)
7002 && GET_CODE (XEXP (addr, 1)) == PLUS
7003 && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0)
7004 && XEXP (addr, 0) == inced
7005 && GET_CODE (XEXP (XEXP (addr, 1), 1)) == CONST_INT)
7007 i = INTVAL (XEXP (XEXP (addr, 1), 1));
7008 return i < 0 ? -i : i;
7012 fmt = GET_RTX_FORMAT (code);
7013 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
7015 if (fmt[i] == 'e')
7017 int tem = find_inc_amount (XEXP (x, i), inced);
7018 if (tem != 0)
7019 return tem;
7021 if (fmt[i] == 'E')
7023 int j;
7024 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
7026 int tem = find_inc_amount (XVECEXP (x, i, j), inced);
7027 if (tem != 0)
7028 return tem;
7033 return 0;
7036 /* Return 1 if registers from REGNO to ENDREGNO are the subjects of a
7037 REG_INC note in insn INSN. REGNO must refer to a hard register. */
7039 #ifdef AUTO_INC_DEC
7040 static int
7041 reg_inc_found_and_valid_p (unsigned int regno, unsigned int endregno,
7042 rtx insn)
7044 rtx link;
7046 gcc_assert (insn);
7048 if (! INSN_P (insn))
7049 return 0;
7051 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
7052 if (REG_NOTE_KIND (link) == REG_INC)
7054 unsigned int test = (int) REGNO (XEXP (link, 0));
7055 if (test >= regno && test < endregno)
7056 return 1;
7058 return 0;
7060 #else
7062 #define reg_inc_found_and_valid_p(regno,endregno,insn) 0
7064 #endif
7066 /* Return 1 if register REGNO is the subject of a clobber in insn INSN.
7067 If SETS is 1, also consider SETs. If SETS is 2, enable checking
7068 REG_INC. REGNO must refer to a hard register. */
7071 regno_clobbered_p (unsigned int regno, rtx insn, enum machine_mode mode,
7072 int sets)
7074 unsigned int nregs, endregno;
7076 /* regno must be a hard register. */
7077 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
7079 nregs = hard_regno_nregs[regno][mode];
7080 endregno = regno + nregs;
7082 if ((GET_CODE (PATTERN (insn)) == CLOBBER
7083 || (sets == 1 && GET_CODE (PATTERN (insn)) == SET))
7084 && REG_P (XEXP (PATTERN (insn), 0)))
7086 unsigned int test = REGNO (XEXP (PATTERN (insn), 0));
7088 return test >= regno && test < endregno;
7091 if (sets == 2 && reg_inc_found_and_valid_p (regno, endregno, insn))
7092 return 1;
7094 if (GET_CODE (PATTERN (insn)) == PARALLEL)
7096 int i = XVECLEN (PATTERN (insn), 0) - 1;
7098 for (; i >= 0; i--)
7100 rtx elt = XVECEXP (PATTERN (insn), 0, i);
7101 if ((GET_CODE (elt) == CLOBBER
7102 || (sets == 1 && GET_CODE (PATTERN (insn)) == SET))
7103 && REG_P (XEXP (elt, 0)))
7105 unsigned int test = REGNO (XEXP (elt, 0));
7107 if (test >= regno && test < endregno)
7108 return 1;
7110 if (sets == 2
7111 && reg_inc_found_and_valid_p (regno, endregno, elt))
7112 return 1;
7116 return 0;
7119 /* Find the low part, with mode MODE, of a hard regno RELOADREG. */
7121 reload_adjust_reg_for_mode (rtx reloadreg, enum machine_mode mode)
7123 int regno;
7125 if (GET_MODE (reloadreg) == mode)
7126 return reloadreg;
7128 regno = REGNO (reloadreg);
7130 if (WORDS_BIG_ENDIAN)
7131 regno += (int) hard_regno_nregs[regno][GET_MODE (reloadreg)]
7132 - (int) hard_regno_nregs[regno][mode];
7134 return gen_rtx_REG (mode, regno);
7137 static const char *const reload_when_needed_name[] =
7139 "RELOAD_FOR_INPUT",
7140 "RELOAD_FOR_OUTPUT",
7141 "RELOAD_FOR_INSN",
7142 "RELOAD_FOR_INPUT_ADDRESS",
7143 "RELOAD_FOR_INPADDR_ADDRESS",
7144 "RELOAD_FOR_OUTPUT_ADDRESS",
7145 "RELOAD_FOR_OUTADDR_ADDRESS",
7146 "RELOAD_FOR_OPERAND_ADDRESS",
7147 "RELOAD_FOR_OPADDR_ADDR",
7148 "RELOAD_OTHER",
7149 "RELOAD_FOR_OTHER_ADDRESS"
7152 /* These functions are used to print the variables set by 'find_reloads' */
7154 void
7155 debug_reload_to_stream (FILE *f)
7157 int r;
7158 const char *prefix;
7160 if (! f)
7161 f = stderr;
7162 for (r = 0; r < n_reloads; r++)
7164 fprintf (f, "Reload %d: ", r);
7166 if (rld[r].in != 0)
7168 fprintf (f, "reload_in (%s) = ",
7169 GET_MODE_NAME (rld[r].inmode));
7170 print_inline_rtx (f, rld[r].in, 24);
7171 fprintf (f, "\n\t");
7174 if (rld[r].out != 0)
7176 fprintf (f, "reload_out (%s) = ",
7177 GET_MODE_NAME (rld[r].outmode));
7178 print_inline_rtx (f, rld[r].out, 24);
7179 fprintf (f, "\n\t");
7182 fprintf (f, "%s, ", reg_class_names[(int) rld[r].class]);
7184 fprintf (f, "%s (opnum = %d)",
7185 reload_when_needed_name[(int) rld[r].when_needed],
7186 rld[r].opnum);
7188 if (rld[r].optional)
7189 fprintf (f, ", optional");
7191 if (rld[r].nongroup)
7192 fprintf (f, ", nongroup");
7194 if (rld[r].inc != 0)
7195 fprintf (f, ", inc by %d", rld[r].inc);
7197 if (rld[r].nocombine)
7198 fprintf (f, ", can't combine");
7200 if (rld[r].secondary_p)
7201 fprintf (f, ", secondary_reload_p");
7203 if (rld[r].in_reg != 0)
7205 fprintf (f, "\n\treload_in_reg: ");
7206 print_inline_rtx (f, rld[r].in_reg, 24);
7209 if (rld[r].out_reg != 0)
7211 fprintf (f, "\n\treload_out_reg: ");
7212 print_inline_rtx (f, rld[r].out_reg, 24);
7215 if (rld[r].reg_rtx != 0)
7217 fprintf (f, "\n\treload_reg_rtx: ");
7218 print_inline_rtx (f, rld[r].reg_rtx, 24);
7221 prefix = "\n\t";
7222 if (rld[r].secondary_in_reload != -1)
7224 fprintf (f, "%ssecondary_in_reload = %d",
7225 prefix, rld[r].secondary_in_reload);
7226 prefix = ", ";
7229 if (rld[r].secondary_out_reload != -1)
7230 fprintf (f, "%ssecondary_out_reload = %d\n",
7231 prefix, rld[r].secondary_out_reload);
7233 prefix = "\n\t";
7234 if (rld[r].secondary_in_icode != CODE_FOR_nothing)
7236 fprintf (f, "%ssecondary_in_icode = %s", prefix,
7237 insn_data[rld[r].secondary_in_icode].name);
7238 prefix = ", ";
7241 if (rld[r].secondary_out_icode != CODE_FOR_nothing)
7242 fprintf (f, "%ssecondary_out_icode = %s", prefix,
7243 insn_data[rld[r].secondary_out_icode].name);
7245 fprintf (f, "\n");
7249 void
7250 debug_reload (void)
7252 debug_reload_to_stream (stderr);