1 /* Move registers around to reduce number of move instructions needed.
2 Copyright (C) 1987, 88, 89, 92-97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This module looks for cases where matching constraints would force
22 an instruction to need a reload, and this reload would be a register
23 to register move. It then attempts to change the registers used by the
24 instruction to avoid the move instruction. */
33 /* stdio.h must precede rtl.h for FFS. */
37 #include "insn-config.h"
42 #include "hard-reg-set.h"
45 #include "insn-flags.h"
47 static int optimize_reg_copy_1 PROTO((rtx, rtx, rtx));
48 static void optimize_reg_copy_2 PROTO((rtx, rtx, rtx));
49 static void optimize_reg_copy_3 PROTO((rtx, rtx, rtx));
52 int with[MAX_RECOG_OPERANDS];
53 enum { READ, WRITE, READWRITE } use[MAX_RECOG_OPERANDS];
54 int commutative[MAX_RECOG_OPERANDS];
55 int early_clobber[MAX_RECOG_OPERANDS];
59 static int try_auto_increment PROTO((rtx, rtx, rtx, rtx, HOST_WIDE_INT, int));
61 static int find_matches PROTO((rtx, struct match *));
62 static int fixup_match_1 PROTO((rtx, rtx, rtx, rtx, rtx, int, int, int, FILE *))
64 static int reg_is_remote_constant_p PROTO((rtx, rtx, rtx));
65 static int stable_but_for_p PROTO((rtx, rtx, rtx));
66 static int loop_depth;
70 /* INC_INSN is an instruction that adds INCREMENT to REG.
71 Try to fold INC_INSN as a post/pre in/decrement into INSN.
72 Iff INC_INSN_SET is nonzero, inc_insn has a destination different from src.
73 Return nonzero for success. */
75 try_auto_increment (insn, inc_insn, inc_insn_set, reg, increment, pre)
76 rtx reg, insn, inc_insn ,inc_insn_set;
77 HOST_WIDE_INT increment;
80 enum rtx_code inc_code;
82 rtx pset = single_set (insn);
85 /* Can't use the size of SET_SRC, we might have something like
86 (sign_extend:SI (mem:QI ... */
87 rtx use = find_use_as_address (pset, reg, 0);
88 if (use != 0 && use != (rtx) 1)
90 int size = GET_MODE_SIZE (GET_MODE (use));
92 #ifdef HAVE_POST_INCREMENT
93 || (pre == 0 && (inc_code = POST_INC, increment == size))
95 #ifdef HAVE_PRE_INCREMENT
96 || (pre == 1 && (inc_code = PRE_INC, increment == size))
98 #ifdef HAVE_POST_DECREMENT
99 || (pre == 0 && (inc_code = POST_DEC, increment == -size))
101 #ifdef HAVE_PRE_DECREMENT
102 || (pre == 1 && (inc_code = PRE_DEC, increment == -size))
109 &SET_SRC (inc_insn_set),
110 XEXP (SET_SRC (inc_insn_set), 0), 1);
111 validate_change (insn, &XEXP (use, 0),
112 gen_rtx_fmt_e (inc_code, Pmode, reg), 1);
113 if (apply_change_group ())
116 = gen_rtx_EXPR_LIST (REG_INC,
117 reg, REG_NOTES (insn));
120 PUT_CODE (inc_insn, NOTE);
121 NOTE_LINE_NUMBER (inc_insn) = NOTE_INSN_DELETED;
122 NOTE_SOURCE_FILE (inc_insn) = 0;
131 #endif /* AUTO_INC_DEC */
133 static int *regno_src_regno;
135 /* Indicate how good a choice REG (which appears as a source) is to replace
136 a destination register with. The higher the returned value, the better
137 the choice. The main objective is to avoid using a register that is
138 a candidate for tying to a hard register, since the output might in
139 turn be a candidate to be tied to a different hard register. */
141 replacement_quality(reg)
146 /* Bad if this isn't a register at all. */
147 if (GET_CODE (reg) != REG)
150 /* If this register is not meant to get a hard register,
151 it is a poor choice. */
152 if (REG_LIVE_LENGTH (REGNO (reg)) < 0)
155 src_regno = regno_src_regno[REGNO (reg)];
157 /* If it was not copied from another register, it is fine. */
161 /* Copied from a hard register? */
162 if (src_regno < FIRST_PSEUDO_REGISTER)
165 /* Copied from a pseudo register - not as bad as from a hard register,
166 yet still cumbersome, since the register live length will be lengthened
167 when the registers get tied. */
171 /* INSN is a copy from SRC to DEST, both registers, and SRC does not die
174 Search forward to see if SRC dies before either it or DEST is modified,
175 but don't scan past the end of a basic block. If so, we can replace SRC
176 with DEST and let SRC die in INSN.
178 This will reduce the number of registers live in that range and may enable
179 DEST to be tied to SRC, thus often saving one register in addition to a
180 register-register copy. */
183 optimize_reg_copy_1 (insn, dest, src)
191 int sregno = REGNO (src);
192 int dregno = REGNO (dest);
194 /* We don't want to mess with hard regs if register classes are small. */
196 || (SMALL_REGISTER_CLASSES
197 && (sregno < FIRST_PSEUDO_REGISTER
198 || dregno < FIRST_PSEUDO_REGISTER))
199 /* We don't see all updates to SP if they are in an auto-inc memory
200 reference, so we must disallow this optimization on them. */
201 || sregno == STACK_POINTER_REGNUM || dregno == STACK_POINTER_REGNUM)
204 for (p = NEXT_INSN (insn); p; p = NEXT_INSN (p))
206 if (GET_CODE (p) == CODE_LABEL || GET_CODE (p) == JUMP_INSN
207 || (GET_CODE (p) == NOTE
208 && (NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_BEG
209 || NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_END)))
212 /* ??? We can't scan past the end of a basic block without updating
213 the register lifetime info (REG_DEAD/basic_block_live_at_start).
214 A CALL_INSN might be the last insn of a basic block, if it is inside
215 an EH region. There is no easy way to tell, so we just always break
216 when we see a CALL_INSN if flag_exceptions is nonzero. */
217 if (flag_exceptions && GET_CODE (p) == CALL_INSN)
220 if (GET_RTX_CLASS (GET_CODE (p)) != 'i')
223 if (reg_set_p (src, p) || reg_set_p (dest, p)
224 /* Don't change a USE of a register. */
225 || (GET_CODE (PATTERN (p)) == USE
226 && reg_overlap_mentioned_p (src, XEXP (PATTERN (p), 0))))
229 /* See if all of SRC dies in P. This test is slightly more
230 conservative than it needs to be. */
231 if ((note = find_regno_note (p, REG_DEAD, sregno)) != 0
232 && GET_MODE (XEXP (note, 0)) == GET_MODE (src))
240 /* We can do the optimization. Scan forward from INSN again,
241 replacing regs as we go. Set FAILED if a replacement can't
242 be done. In that case, we can't move the death note for SRC.
243 This should be rare. */
245 /* Set to stop at next insn. */
246 for (q = next_real_insn (insn);
247 q != next_real_insn (p);
248 q = next_real_insn (q))
250 if (reg_overlap_mentioned_p (src, PATTERN (q)))
252 /* If SRC is a hard register, we might miss some
253 overlapping registers with validate_replace_rtx,
254 so we would have to undo it. We can't if DEST is
255 present in the insn, so fail in that combination
257 if (sregno < FIRST_PSEUDO_REGISTER
258 && reg_mentioned_p (dest, PATTERN (q)))
261 /* Replace all uses and make sure that the register
262 isn't still present. */
263 else if (validate_replace_rtx (src, dest, q)
264 && (sregno >= FIRST_PSEUDO_REGISTER
265 || ! reg_overlap_mentioned_p (src,
268 /* We assume that a register is used exactly once per
269 insn in the updates below. If this is not correct,
270 no great harm is done. */
271 if (sregno >= FIRST_PSEUDO_REGISTER)
272 REG_N_REFS (sregno) -= loop_depth;
273 if (dregno >= FIRST_PSEUDO_REGISTER)
274 REG_N_REFS (dregno) += loop_depth;
278 validate_replace_rtx (dest, src, q);
283 /* Count the insns and CALL_INSNs passed. If we passed the
284 death note of DEST, show increased live length. */
289 /* If the insn in which SRC dies is a CALL_INSN, don't count it
290 as a call that has been crossed. Otherwise, count it. */
291 if (q != p && GET_CODE (q) == CALL_INSN)
298 /* If DEST dies here, remove the death note and save it for
299 later. Make sure ALL of DEST dies here; again, this is
300 overly conservative. */
302 && (dest_death = find_regno_note (q, REG_DEAD, dregno)) != 0)
304 if (GET_MODE (XEXP (dest_death, 0)) != GET_MODE (dest))
305 failed = 1, dest_death = 0;
307 remove_note (q, dest_death);
313 if (sregno >= FIRST_PSEUDO_REGISTER)
315 if (REG_LIVE_LENGTH (sregno) >= 0)
317 REG_LIVE_LENGTH (sregno) -= length;
318 /* REG_LIVE_LENGTH is only an approximation after
319 combine if sched is not run, so make sure that we
320 still have a reasonable value. */
321 if (REG_LIVE_LENGTH (sregno) < 2)
322 REG_LIVE_LENGTH (sregno) = 2;
325 REG_N_CALLS_CROSSED (sregno) -= n_calls;
328 if (dregno >= FIRST_PSEUDO_REGISTER)
330 if (REG_LIVE_LENGTH (dregno) >= 0)
331 REG_LIVE_LENGTH (dregno) += d_length;
333 REG_N_CALLS_CROSSED (dregno) += d_n_calls;
336 /* Move death note of SRC from P to INSN. */
337 remove_note (p, note);
338 XEXP (note, 1) = REG_NOTES (insn);
339 REG_NOTES (insn) = note;
342 /* Put death note of DEST on P if we saw it die. */
345 XEXP (dest_death, 1) = REG_NOTES (p);
346 REG_NOTES (p) = dest_death;
352 /* If SRC is a hard register which is set or killed in some other
353 way, we can't do this optimization. */
354 else if (sregno < FIRST_PSEUDO_REGISTER
355 && dead_or_set_p (p, src))
361 /* INSN is a copy of SRC to DEST, in which SRC dies. See if we now have
362 a sequence of insns that modify DEST followed by an insn that sets
363 SRC to DEST in which DEST dies, with no prior modification of DEST.
364 (There is no need to check if the insns in between actually modify
365 DEST. We should not have cases where DEST is not modified, but
366 the optimization is safe if no such modification is detected.)
367 In that case, we can replace all uses of DEST, starting with INSN and
368 ending with the set of SRC to DEST, with SRC. We do not do this
369 optimization if a CALL_INSN is crossed unless SRC already crosses a
370 call or if DEST dies before the copy back to SRC.
372 It is assumed that DEST and SRC are pseudos; it is too complicated to do
373 this for hard registers since the substitutions we may make might fail. */
376 optimize_reg_copy_2 (insn, dest, src)
383 int sregno = REGNO (src);
384 int dregno = REGNO (dest);
386 for (p = NEXT_INSN (insn); p; p = NEXT_INSN (p))
388 if (GET_CODE (p) == CODE_LABEL || GET_CODE (p) == JUMP_INSN
389 || (GET_CODE (p) == NOTE
390 && (NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_BEG
391 || NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_END)))
394 /* ??? We can't scan past the end of a basic block without updating
395 the register lifetime info (REG_DEAD/basic_block_live_at_start).
396 A CALL_INSN might be the last insn of a basic block, if it is inside
397 an EH region. There is no easy way to tell, so we just always break
398 when we see a CALL_INSN if flag_exceptions is nonzero. */
399 if (flag_exceptions && GET_CODE (p) == CALL_INSN)
402 if (GET_RTX_CLASS (GET_CODE (p)) != 'i')
405 set = single_set (p);
406 if (set && SET_SRC (set) == dest && SET_DEST (set) == src
407 && find_reg_note (p, REG_DEAD, dest))
409 /* We can do the optimization. Scan forward from INSN again,
410 replacing regs as we go. */
412 /* Set to stop at next insn. */
413 for (q = insn; q != NEXT_INSN (p); q = NEXT_INSN (q))
414 if (GET_RTX_CLASS (GET_CODE (q)) == 'i')
416 if (reg_mentioned_p (dest, PATTERN (q)))
418 PATTERN (q) = replace_rtx (PATTERN (q), dest, src);
420 /* We assume that a register is used exactly once per
421 insn in the updates below. If this is not correct,
422 no great harm is done. */
423 REG_N_REFS (dregno) -= loop_depth;
424 REG_N_REFS (sregno) += loop_depth;
428 if (GET_CODE (q) == CALL_INSN)
430 REG_N_CALLS_CROSSED (dregno)--;
431 REG_N_CALLS_CROSSED (sregno)++;
435 remove_note (p, find_reg_note (p, REG_DEAD, dest));
436 REG_N_DEATHS (dregno)--;
437 remove_note (insn, find_reg_note (insn, REG_DEAD, src));
438 REG_N_DEATHS (sregno)--;
442 if (reg_set_p (src, p)
443 || find_reg_note (p, REG_DEAD, dest)
444 || (GET_CODE (p) == CALL_INSN && REG_N_CALLS_CROSSED (sregno) == 0))
448 /* INSN is a ZERO_EXTEND or SIGN_EXTEND of SRC to DEST.
449 Look if SRC dies there, and if it is only set once, by loading
450 it from memory. If so, try to encorporate the zero/sign extension
451 into the memory read, change SRC to the mode of DEST, and alter
452 the remaining accesses to use the appropriate SUBREG. This allows
453 SRC and DEST to be tied later. */
455 optimize_reg_copy_3 (insn, dest, src)
460 rtx src_reg = XEXP (src, 0);
461 int src_no = REGNO (src_reg);
462 int dst_no = REGNO (dest);
464 enum machine_mode old_mode;
466 if (src_no < FIRST_PSEUDO_REGISTER
467 || dst_no < FIRST_PSEUDO_REGISTER
468 || ! find_reg_note (insn, REG_DEAD, src_reg)
469 || REG_N_SETS (src_no) != 1)
471 for (p = PREV_INSN (insn); ! reg_set_p (src_reg, p); p = PREV_INSN (p))
473 if (GET_CODE (p) == CODE_LABEL || GET_CODE (p) == JUMP_INSN
474 || (GET_CODE (p) == NOTE
475 && (NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_BEG
476 || NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_END)))
479 /* ??? We can't scan past the end of a basic block without updating
480 the register lifetime info (REG_DEAD/basic_block_live_at_start).
481 A CALL_INSN might be the last insn of a basic block, if it is inside
482 an EH region. There is no easy way to tell, so we just always break
483 when we see a CALL_INSN if flag_exceptions is nonzero. */
484 if (flag_exceptions && GET_CODE (p) == CALL_INSN)
487 if (GET_RTX_CLASS (GET_CODE (p)) != 'i')
490 if (! (set = single_set (p))
491 || GET_CODE (SET_SRC (set)) != MEM
492 || SET_DEST (set) != src_reg)
494 old_mode = GET_MODE (src_reg);
495 PUT_MODE (src_reg, GET_MODE (src));
496 XEXP (src, 0) = SET_SRC (set);
497 if (! validate_change (p, &SET_SRC (set), src, 0))
499 PUT_MODE (src_reg, old_mode);
500 XEXP (src, 0) = src_reg;
503 subreg = gen_rtx_SUBREG (old_mode, src_reg, 0);
504 while (p = NEXT_INSN (p), p != insn)
506 if (GET_RTX_CLASS (GET_CODE (p)) != 'i')
508 validate_replace_rtx (src_reg, subreg, p);
510 validate_replace_rtx (src, src_reg, insn);
513 /* Return whether REG is set in only one location, and is set to a
514 constant, but is set in a different basic block from INSN (an
515 instructions which uses REG). In this case REG is equivalent to a
516 constant, and we don't want to break that equivalence, because that
517 may increase register pressure and make reload harder. If REG is
518 set in the same basic block as INSN, we don't worry about it,
519 because we'll probably need a register anyhow (??? but what if REG
520 is used in a different basic block as well as this one?). FIRST is
521 the first insn in the function. */
524 reg_is_remote_constant_p (reg, insn, first)
531 if (REG_N_SETS (REGNO (reg)) != 1)
534 /* Look for the set. */
535 for (p = LOG_LINKS (insn); p; p = XEXP (p, 1))
539 if (REG_NOTE_KIND (p) != 0)
541 s = single_set (XEXP (p, 0));
543 && GET_CODE (SET_DEST (s)) == REG
544 && REGNO (SET_DEST (s)) == REGNO (reg))
546 /* The register is set in the same basic block. */
551 for (p = first; p && p != insn; p = NEXT_INSN (p))
555 if (GET_RTX_CLASS (GET_CODE (p)) != 'i')
559 && GET_CODE (SET_DEST (s)) == REG
560 && REGNO (SET_DEST (s)) == REGNO (reg))
562 /* This is the instruction which sets REG. If there is a
563 REG_EQUAL note, then REG is equivalent to a constant. */
564 if (find_reg_note (p, REG_EQUAL, NULL_RTX))
573 /* cse disrupts preincrement / postdecrement squences when it finds a
574 hard register as ultimate source, like the frame pointer. */
576 fixup_match_2 (insn, dst, src, offset, regmove_dump_file)
577 rtx insn, dst, src, offset;
578 FILE *regmove_dump_file;
580 rtx p, dst_death = 0;
581 int length, num_calls = 0;
583 /* If SRC dies in INSN, we'd have to move the death note. This is
584 considered to be very unlikely, so we just skip the optimization
586 if (find_regno_note (insn, REG_DEAD, REGNO (src)))
589 /* Scan backward to find the first instruction that sets DST. */
591 for (length = 0, p = PREV_INSN (insn); p; p = PREV_INSN (p))
595 if (GET_CODE (p) == CODE_LABEL
596 || GET_CODE (p) == JUMP_INSN
597 || (GET_CODE (p) == NOTE
598 && (NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_BEG
599 || NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_END)))
602 /* ??? We can't scan past the end of a basic block without updating
603 the register lifetime info (REG_DEAD/basic_block_live_at_start).
604 A CALL_INSN might be the last insn of a basic block, if it is inside
605 an EH region. There is no easy way to tell, so we just always break
606 when we see a CALL_INSN if flag_exceptions is nonzero. */
607 if (flag_exceptions && GET_CODE (p) == CALL_INSN)
610 if (GET_RTX_CLASS (GET_CODE (p)) != 'i')
613 if (find_regno_note (p, REG_DEAD, REGNO (dst)))
618 pset = single_set (p);
619 if (pset && SET_DEST (pset) == dst
620 && GET_CODE (SET_SRC (pset)) == PLUS
621 && XEXP (SET_SRC (pset), 0) == src
622 && GET_CODE (XEXP (SET_SRC (pset), 1)) == CONST_INT)
624 HOST_WIDE_INT newconst
625 = INTVAL (offset) - INTVAL (XEXP (SET_SRC (pset), 1));
626 if (validate_change (insn, &PATTERN (insn),
627 gen_addsi3 (dst, dst, GEN_INT (newconst)), 0))
629 /* Remove the death note for DST from DST_DEATH. */
632 remove_death (REGNO (dst), dst_death);
633 REG_LIVE_LENGTH (REGNO (dst)) += length;
634 REG_N_CALLS_CROSSED (REGNO (dst)) += num_calls;
637 REG_N_REFS (REGNO (dst)) += loop_depth;
638 REG_N_REFS (REGNO (src)) -= loop_depth;
640 if (regmove_dump_file)
641 fprintf (regmove_dump_file,
642 "Fixed operand of insn %d.\n",
646 for (p = PREV_INSN (insn); p; p = PREV_INSN (p))
648 if (GET_CODE (p) == CODE_LABEL
649 || GET_CODE (p) == JUMP_INSN
650 || (GET_CODE (p) == NOTE
651 && (NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_BEG
652 || NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_END)))
654 if (reg_overlap_mentioned_p (dst, PATTERN (p)))
656 if (try_auto_increment (p, insn, 0, dst, newconst, 0))
661 for (p = NEXT_INSN (insn); p; p = NEXT_INSN (p))
663 if (GET_CODE (p) == CODE_LABEL
664 || GET_CODE (p) == JUMP_INSN
665 || (GET_CODE (p) == NOTE
666 && (NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_BEG
667 || NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_END)))
669 if (reg_overlap_mentioned_p (dst, PATTERN (p)))
671 try_auto_increment (p, insn, 0, dst, newconst, 1);
680 if (reg_set_p (dst, PATTERN (p)))
683 /* If we have passed a call instruction, and the
684 pseudo-reg SRC is not already live across a call,
685 then don't perform the optimization. */
686 /* reg_set_p is overly conservative for CALL_INSNS, thinks that all
687 hard regs are clobbered. Thus, we only use it for src for
689 if (GET_CODE (p) == CALL_INSN)
694 if (REG_N_CALLS_CROSSED (REGNO (src)) == 0)
697 if (call_used_regs [REGNO (dst)]
698 || find_reg_fusage (p, CLOBBER, dst))
701 else if (reg_set_p (src, PATTERN (p)))
709 regmove_optimize (f, nregs, regmove_dump_file)
712 FILE *regmove_dump_file;
717 int maxregnum = max_reg_num (), i;
719 regno_src_regno = (int *)alloca (sizeof *regno_src_regno * maxregnum);
720 for (i = maxregnum; --i >= 0; ) regno_src_regno[i] = -1;
722 /* A forward/backward pass. Replace output operands with input operands. */
726 for (pass = 0; pass <= 2; pass++)
728 if (! flag_regmove && pass >= flag_expensive_optimizations)
731 if (regmove_dump_file)
732 fprintf (regmove_dump_file, "Starting %s pass...\n",
733 pass ? "backward" : "forward");
735 for (insn = pass ? get_last_insn () : f; insn;
736 insn = pass ? PREV_INSN (insn) : NEXT_INSN (insn))
739 int insn_code_number;
740 int operand_number, match_number;
742 if (GET_CODE (insn) == NOTE)
744 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
746 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
750 set = single_set (insn);
754 if (flag_expensive_optimizations && ! pass
755 && (GET_CODE (SET_SRC (set)) == SIGN_EXTEND
756 || GET_CODE (SET_SRC (set)) == ZERO_EXTEND)
757 && GET_CODE (XEXP (SET_SRC (set), 0)) == REG
758 && GET_CODE (SET_DEST(set)) == REG)
759 optimize_reg_copy_3 (insn, SET_DEST (set), SET_SRC (set));
761 if (flag_expensive_optimizations && ! pass
762 && GET_CODE (SET_SRC (set)) == REG
763 && GET_CODE (SET_DEST(set)) == REG)
765 /* If this is a register-register copy where SRC is not dead,
766 see if we can optimize it. If this optimization succeeds,
767 it will become a copy where SRC is dead. */
768 if ((find_reg_note (insn, REG_DEAD, SET_SRC (set))
769 || optimize_reg_copy_1 (insn, SET_DEST (set), SET_SRC (set)))
770 && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER)
772 /* Similarly for a pseudo-pseudo copy when SRC is dead. */
773 if (REGNO (SET_SRC (set)) >= FIRST_PSEUDO_REGISTER)
774 optimize_reg_copy_2 (insn, SET_DEST (set), SET_SRC (set));
775 if (regno_src_regno[REGNO (SET_DEST (set))] < 0
776 && SET_SRC (set) != SET_DEST (set))
778 int srcregno = REGNO (SET_SRC(set));
779 if (regno_src_regno[srcregno] >= 0)
780 srcregno = regno_src_regno[srcregno];
781 regno_src_regno[REGNO (SET_DEST (set))] = srcregno;
785 #ifdef REGISTER_CONSTRAINTS
787 = find_matches (insn, &match);
789 if (insn_code_number < 0)
792 /* Now scan through the operands looking for a source operand
793 which is supposed to match the destination operand.
794 Then scan forward for an instruction which uses the dest
796 If it dies there, then replace the dest in both operands with
797 the source operand. */
799 for (operand_number = 0;
800 operand_number < insn_n_operands[insn_code_number];
803 rtx src, dst, src_subreg;
804 enum reg_class src_class, dst_class;
806 match_number = match.with[operand_number];
808 /* Nothing to do if the two operands aren't supposed to match. */
809 if (match_number < 0)
812 src = recog_operand[operand_number];
813 dst = recog_operand[match_number];
815 if (GET_CODE (src) != REG)
819 if (GET_CODE (dst) == SUBREG
820 && GET_MODE_SIZE (GET_MODE (dst))
821 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (dst))))
824 = gen_rtx_SUBREG (GET_MODE (SUBREG_REG (dst)),
825 src, SUBREG_WORD (dst));
826 dst = SUBREG_REG (dst);
828 if (GET_CODE (dst) != REG
829 || REGNO (dst) < FIRST_PSEUDO_REGISTER)
832 if (REGNO (src) < FIRST_PSEUDO_REGISTER)
834 if (match.commutative[operand_number] < operand_number)
835 regno_src_regno[REGNO (dst)] = REGNO (src);
839 if (REG_LIVE_LENGTH (REGNO (src)) < 0)
842 /* operand_number/src must be a read-only operand, and
843 match_operand/dst must be a write-only operand. */
844 if (match.use[operand_number] != READ
845 || match.use[match_number] != WRITE)
848 if (match.early_clobber[match_number]
849 && count_occurrences (PATTERN (insn), src) > 1)
852 /* Make sure match_operand is the destination. */
853 if (recog_operand[match_number] != SET_DEST (set))
856 /* If the operands already match, then there is nothing to do. */
857 /* But in the commutative case, we might find a better match. */
858 if (operands_match_p (src, dst)
859 || (match.commutative[operand_number] >= 0
860 && operands_match_p (recog_operand[match.commutative
861 [operand_number]], dst)
862 && (replacement_quality (recog_operand[match.commutative
864 >= replacement_quality (src))))
867 src_class = reg_preferred_class (REGNO (src));
868 dst_class = reg_preferred_class (REGNO (dst));
869 if (src_class != dst_class
870 && (! reg_class_subset_p (src_class, dst_class)
871 || CLASS_LIKELY_SPILLED_P (src_class))
872 && (! reg_class_subset_p (dst_class, src_class)
873 || CLASS_LIKELY_SPILLED_P (dst_class)))
876 if (fixup_match_1 (insn, set, src, src_subreg, dst, pass,
877 operand_number, match_number,
884 /* A backward pass. Replace input operands with output operands. */
886 if (regmove_dump_file)
887 fprintf (regmove_dump_file, "Starting backward pass...\n");
891 for (insn = get_last_insn (); insn; insn = PREV_INSN (insn))
893 if (GET_CODE (insn) == NOTE)
895 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
897 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
900 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
902 int insn_code_number = find_matches (insn, &match);
903 int operand_number, match_number;
905 if (insn_code_number < 0)
908 /* Now scan through the operands looking for a destination operand
909 which is supposed to match a source operand.
910 Then scan backward for an instruction which sets the source
911 operand. If safe, then replace the source operand with the
912 dest operand in both instructions. */
914 for (operand_number = 0;
915 operand_number < insn_n_operands[insn_code_number];
918 rtx set, p, src, dst;
919 rtx src_note, dst_note;
922 enum reg_class src_class, dst_class;
925 match_number = match.with[operand_number];
927 /* Nothing to do if the two operands aren't supposed to match. */
928 if (match_number < 0)
931 dst = recog_operand[match_number];
932 src = recog_operand[operand_number];
934 if (GET_CODE (src) != REG)
937 if (GET_CODE (dst) != REG
938 || REGNO (dst) < FIRST_PSEUDO_REGISTER
939 || REG_LIVE_LENGTH (REGNO (dst)) < 0)
942 /* If the operands already match, then there is nothing to do. */
943 if (operands_match_p (src, dst)
944 || (match.commutative[operand_number] >= 0
945 && operands_match_p (recog_operand[match.commutative[operand_number]], dst)))
948 set = single_set (insn);
952 /* match_number/dst must be a write-only operand, and
953 operand_operand/src must be a read-only operand. */
954 if (match.use[operand_number] != READ
955 || match.use[match_number] != WRITE)
958 if (match.early_clobber[match_number]
959 && count_occurrences (PATTERN (insn), src) > 1)
962 /* Make sure match_number is the destination. */
963 if (recog_operand[match_number] != SET_DEST (set))
966 if (REGNO (src) < FIRST_PSEUDO_REGISTER)
968 if (GET_CODE (SET_SRC (set)) == PLUS
969 && GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT
970 && XEXP (SET_SRC (set), 0) == src
971 && fixup_match_2 (insn, dst, src,
972 XEXP (SET_SRC (set), 1),
977 src_class = reg_preferred_class (REGNO (src));
978 dst_class = reg_preferred_class (REGNO (dst));
979 if (src_class != dst_class
980 && (! reg_class_subset_p (src_class, dst_class)
981 || CLASS_LIKELY_SPILLED_P (src_class))
982 && (! reg_class_subset_p (dst_class, src_class)
983 || CLASS_LIKELY_SPILLED_P (dst_class)))
986 if (! (src_note = find_reg_note (insn, REG_DEAD, src)))
989 /* Can not modify an earlier insn to set dst if this insn
990 uses an old value in the source. */
991 if (reg_overlap_mentioned_p (dst, SET_SRC (set)))
994 if (regmove_dump_file)
995 fprintf (regmove_dump_file,
996 "Could fix operand %d of insn %d matching operand %d.\n",
997 operand_number, INSN_UID (insn), match_number);
999 /* If src is set once in a different basic block,
1000 and is set equal to a constant, then do not use
1001 it for this optimization, as this would make it
1002 no longer equivalent to a constant. */
1003 if (reg_is_remote_constant_p (src, insn, f))
1006 /* Scan backward to find the first instruction that uses
1007 the input operand. If the operand is set here, then
1008 replace it in both instructions with match_number. */
1010 for (length = 0, p = PREV_INSN (insn); p; p = PREV_INSN (p))
1014 if (GET_CODE (p) == CODE_LABEL
1015 || GET_CODE (p) == JUMP_INSN
1016 || (GET_CODE (p) == NOTE
1017 && (NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_BEG
1018 || NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_END)))
1021 /* ??? We can't scan past the end of a basic block without
1022 updating the register lifetime info
1023 (REG_DEAD/basic_block_live_at_start).
1024 A CALL_INSN might be the last insn of a basic block, if
1025 it is inside an EH region. There is no easy way to tell,
1026 so we just always break when we see a CALL_INSN if
1027 flag_exceptions is nonzero. */
1028 if (flag_exceptions && GET_CODE (p) == CALL_INSN)
1031 if (GET_RTX_CLASS (GET_CODE (p)) != 'i')
1036 /* ??? See if all of SRC is set in P. This test is much
1037 more conservative than it needs to be. */
1038 pset = single_set (p);
1039 if (pset && SET_DEST (pset) == src)
1041 /* We use validate_replace_rtx, in case there
1042 are multiple identical source operands. All of
1043 them have to be changed at the same time. */
1044 if (validate_replace_rtx (src, dst, insn))
1046 if (validate_change (p, &SET_DEST (pset),
1051 /* Change all source operands back.
1052 This modifies the dst as a side-effect. */
1053 validate_replace_rtx (dst, src, insn);
1054 /* Now make sure the dst is right. */
1055 validate_change (insn,
1056 recog_operand_loc[match_number],
1063 if (reg_overlap_mentioned_p (src, PATTERN (p))
1064 || reg_overlap_mentioned_p (dst, PATTERN (p)))
1067 /* If we have passed a call instruction, and the
1068 pseudo-reg DST is not already live across a call,
1069 then don't perform the optimization. */
1070 if (GET_CODE (p) == CALL_INSN)
1074 if (REG_N_CALLS_CROSSED (REGNO (dst)) == 0)
1083 /* Remove the death note for SRC from INSN. */
1084 remove_note (insn, src_note);
1085 /* Move the death note for SRC to P if it is used
1087 if (reg_overlap_mentioned_p (src, PATTERN (p)))
1089 XEXP (src_note, 1) = REG_NOTES (p);
1090 REG_NOTES (p) = src_note;
1092 /* If there is a REG_DEAD note for DST on P, then remove
1093 it, because DST is now set there. */
1094 if ((dst_note = find_reg_note (p, REG_DEAD, dst)))
1095 remove_note (p, dst_note);
1097 dstno = REGNO (dst);
1098 srcno = REGNO (src);
1100 REG_N_SETS (dstno)++;
1101 REG_N_SETS (srcno)--;
1103 REG_N_CALLS_CROSSED (dstno) += num_calls;
1104 REG_N_CALLS_CROSSED (srcno) -= num_calls;
1106 REG_LIVE_LENGTH (dstno) += length;
1107 if (REG_LIVE_LENGTH (srcno) >= 0)
1109 REG_LIVE_LENGTH (srcno) -= length;
1110 /* REG_LIVE_LENGTH is only an approximation after
1111 combine if sched is not run, so make sure that we
1112 still have a reasonable value. */
1113 if (REG_LIVE_LENGTH (srcno) < 2)
1114 REG_LIVE_LENGTH (srcno) = 2;
1117 /* We assume that a register is used exactly once per
1118 insn in the updates above. If this is not correct,
1119 no great harm is done. */
1121 REG_N_REFS (dstno) += 2 * loop_depth;
1122 REG_N_REFS (srcno) -= 2 * loop_depth;
1124 /* If that was the only time src was set,
1125 and src was not live at the start of the
1126 function, we know that we have no more
1127 references to src; clear REG_N_REFS so it
1128 won't make reload do any work. */
1129 if (REG_N_SETS (REGNO (src)) == 0
1130 && ! regno_uninitialized (REGNO (src)))
1131 REG_N_REFS (REGNO (src)) = 0;
1133 if (regmove_dump_file)
1134 fprintf (regmove_dump_file,
1135 "Fixed operand %d of insn %d matching operand %d.\n",
1136 operand_number, INSN_UID (insn), match_number);
1143 #endif /* REGISTER_CONSTRAINTS */
1148 find_matches (insn, matchp)
1150 struct match *matchp;
1152 int likely_spilled[MAX_RECOG_OPERANDS];
1154 int insn_code_number = recog_memoized (insn);
1155 int any_matches = 0;
1157 if (insn_code_number < 0)
1160 insn_extract (insn);
1161 if (! constrain_operands (insn_code_number, 0))
1164 /* Must initialize this before main loop, because the code for
1165 the commutative case may set matches for operands other than
1167 for (operand_number = insn_n_operands[insn_code_number];
1168 --operand_number >= 0; )
1169 matchp->with[operand_number] = matchp->commutative[operand_number] = -1;
1171 for (operand_number = 0; operand_number < insn_n_operands[insn_code_number];
1177 p = insn_operand_constraint[insn_code_number][operand_number];
1179 likely_spilled[operand_number] = 0;
1180 matchp->use[operand_number] = READ;
1181 matchp->early_clobber[operand_number] = 0;
1183 matchp->use[operand_number] = WRITE;
1185 matchp->use[operand_number] = READWRITE;
1187 for (;*p && i < which_alternative; p++)
1191 while ((c = *p++) != '\0' && c != ',')
1199 matchp->early_clobber[operand_number] = 1;
1202 matchp->commutative[operand_number] = operand_number + 1;
1203 matchp->commutative[operand_number + 1] = operand_number;
1205 case '0': case '1': case '2': case '3': case '4':
1206 case '5': case '6': case '7': case '8': case '9':
1208 if (c < operand_number && likely_spilled[(unsigned char) c])
1210 matchp->with[operand_number] = c;
1212 if (matchp->commutative[operand_number] >= 0)
1213 matchp->with[matchp->commutative[operand_number]] = c;
1215 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'h':
1216 case 'j': case 'k': case 'l': case 'p': case 'q': case 't': case 'u':
1217 case 'v': case 'w': case 'x': case 'y': case 'z': case 'A': case 'B':
1218 case 'C': case 'D': case 'W': case 'Y': case 'Z':
1219 if (CLASS_LIKELY_SPILLED_P (REG_CLASS_FROM_LETTER (c)))
1220 likely_spilled[operand_number] = 1;
1224 return any_matches ? insn_code_number : -1;
1227 /* Try to replace output operand DST in SET, with input operand SRC. SET is
1228 the only set in INSN. INSN has just been recgnized and constrained.
1229 SRC is operand number OPERAND_NUMBER in INSN.
1230 DST is operand number MATCH_NUMBER in INSN.
1231 If BACKWARD is nonzero, we have been called in a backward pass.
1232 Return nonzero for success. */
1234 fixup_match_1 (insn, set, src, src_subreg, dst, backward, operand_number,
1235 match_number, regmove_dump_file)
1236 rtx insn, set, src, src_subreg, dst;
1237 int backward, operand_number, match_number;
1238 FILE *regmove_dump_file;
1241 rtx post_inc = 0, post_inc_set = 0, search_end = 0;
1243 int num_calls = 0, s_num_calls = 0;
1244 enum rtx_code code = NOTE;
1245 HOST_WIDE_INT insn_const, newconst;
1246 rtx overlap = 0; /* need to move insn ? */
1247 rtx src_note = find_reg_note (insn, REG_DEAD, src), dst_note;
1248 int length, s_length, true_loop_depth;
1252 /* Look for (set (regX) (op regA constX))
1253 (set (regY) (op regA constY))
1255 (set (regA) (op regA constX)).
1256 (set (regY) (op regA constY-constX)).
1257 This works for add and shift operations, if
1258 regA is dead after or set by the second insn. */
1260 code = GET_CODE (SET_SRC (set));
1261 if ((code == PLUS || code == LSHIFTRT
1262 || code == ASHIFT || code == ASHIFTRT)
1263 && XEXP (SET_SRC (set), 0) == src
1264 && GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT)
1265 insn_const = INTVAL (XEXP (SET_SRC (set), 1));
1266 else if (! stable_but_for_p (SET_SRC (set), src, dst))
1269 /* We might find a src_note while scanning. */
1273 if (regmove_dump_file)
1274 fprintf (regmove_dump_file,
1275 "Could fix operand %d of insn %d matching operand %d.\n",
1276 operand_number, INSN_UID (insn), match_number);
1278 /* If SRC is equivalent to a constant set in a different basic block,
1279 then do not use it for this optimization. We want the equivalence
1280 so that if we have to reload this register, we can reload the
1281 constant, rather than extending the lifespan of the register. */
1282 if (reg_is_remote_constant_p (src, insn, get_insns ()))
1285 /* Scan forward to find the next instruction that
1286 uses the output operand. If the operand dies here,
1287 then replace it in both instructions with
1290 for (length = s_length = 0, p = NEXT_INSN (insn); p; p = NEXT_INSN (p))
1292 if (GET_CODE (p) == CODE_LABEL || GET_CODE (p) == JUMP_INSN
1293 || (GET_CODE (p) == NOTE
1294 && (NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_BEG
1295 || NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_END)))
1298 /* ??? We can't scan past the end of a basic block without updating
1299 the register lifetime info (REG_DEAD/basic_block_live_at_start).
1300 A CALL_INSN might be the last insn of a basic block, if it is
1301 inside an EH region. There is no easy way to tell, so we just
1302 always break when we see a CALL_INSN if flag_exceptions is nonzero. */
1303 if (flag_exceptions && GET_CODE (p) == CALL_INSN)
1306 if (GET_RTX_CLASS (GET_CODE (p)) != 'i')
1313 if (reg_set_p (src, p) || reg_set_p (dst, p)
1314 || (GET_CODE (PATTERN (p)) == USE
1315 && reg_overlap_mentioned_p (src, XEXP (PATTERN (p), 0))))
1318 /* See if all of DST dies in P. This test is
1319 slightly more conservative than it needs to be. */
1320 if ((dst_note = find_regno_note (p, REG_DEAD, REGNO (dst)))
1321 && (GET_MODE (XEXP (dst_note, 0)) == GET_MODE (dst)))
1328 /* If an optimization is done, the value of SRC while P
1329 is executed will be changed. Check that this is OK. */
1330 if (reg_overlap_mentioned_p (src, PATTERN (p)))
1332 for (q = p; q; q = NEXT_INSN (q))
1334 if (GET_CODE (q) == CODE_LABEL || GET_CODE (q) == JUMP_INSN
1335 || (GET_CODE (q) == NOTE
1336 && (NOTE_LINE_NUMBER (q) == NOTE_INSN_LOOP_BEG
1337 || NOTE_LINE_NUMBER (q) == NOTE_INSN_LOOP_END)))
1343 /* ??? We can't scan past the end of a basic block without
1344 updating the register lifetime info
1345 (REG_DEAD/basic_block_live_at_start).
1346 A CALL_INSN might be the last insn of a basic block, if
1347 it is inside an EH region. There is no easy way to tell,
1348 so we just always break when we see a CALL_INSN if
1349 flag_exceptions is nonzero. */
1350 if (flag_exceptions && GET_CODE (q) == CALL_INSN)
1356 if (GET_RTX_CLASS (GET_CODE (q)) != 'i')
1358 if (reg_overlap_mentioned_p (src, PATTERN (q))
1359 || reg_set_p (src, q))
1363 set2 = single_set (q);
1364 if (! q || ! set2 || GET_CODE (SET_SRC (set2)) != code
1365 || XEXP (SET_SRC (set2), 0) != src
1366 || GET_CODE (XEXP (SET_SRC (set2), 1)) != CONST_INT
1367 || (SET_DEST (set2) != src
1368 && ! find_reg_note (q, REG_DEAD, src)))
1370 /* If this is a PLUS, we can still save a register by doing
1373 src -= insn_const; .
1374 This also gives opportunities for subsequent
1375 optimizations in the backward pass, so do it there. */
1376 if (code == PLUS && backward
1378 /* We may not emit an insn directly
1379 after P if the latter sets CC0. */
1380 && ! sets_cc0_p (PATTERN (p))
1388 newconst = -insn_const;
1396 newconst = INTVAL (XEXP (SET_SRC (set2), 1)) - insn_const;
1397 /* Reject out of range shifts. */
1401 >= GET_MODE_BITSIZE (GET_MODE (SET_SRC (set2))))))
1406 if (SET_DEST (set2) != src)
1407 post_inc_set = set2;
1410 /* We use 1 as last argument to validate_change so that all
1411 changes are accepted or rejected together by apply_change_group
1412 when it is called by validate_replace_rtx . */
1413 validate_change (q, &XEXP (SET_SRC (set2), 1),
1414 GEN_INT (newconst), 1);
1416 validate_change (insn, recog_operand_loc[match_number], src, 1);
1417 if (validate_replace_rtx (dst, src_subreg, p))
1422 if (reg_overlap_mentioned_p (dst, PATTERN (p)))
1424 if (! src_note && reg_overlap_mentioned_p (src, PATTERN (p)))
1426 /* INSN was already checked to be movable when
1427 we found no REG_DEAD note for src on it. */
1429 src_note = find_reg_note (p, REG_DEAD, src);
1432 /* If we have passed a call instruction, and the pseudo-reg SRC is not
1433 already live across a call, then don't perform the optimization. */
1434 if (GET_CODE (p) == CALL_INSN)
1436 if (REG_N_CALLS_CROSSED (REGNO (src)) == 0)
1450 true_loop_depth = backward ? 2 - loop_depth : loop_depth;
1452 /* Remove the death note for DST from P. */
1453 remove_note (p, dst_note);
1456 post_inc = emit_insn_after (copy_rtx (PATTERN (insn)), p);
1457 #if defined (HAVE_PRE_INCREMENT) || defined (HAVE_PRE_DECREMENT)
1459 && try_auto_increment (search_end, post_inc, 0, src, newconst, 1))
1462 validate_change (insn, &XEXP (SET_SRC (set), 1), GEN_INT (insn_const), 0);
1463 REG_N_SETS (REGNO (src))++;
1464 REG_N_REFS (REGNO (src)) += true_loop_depth;
1465 REG_LIVE_LENGTH (REGNO (src))++;
1469 /* The lifetime of src and dest overlap,
1470 but we can change this by moving insn. */
1471 rtx pat = PATTERN (insn);
1473 remove_note (overlap, src_note);
1474 #if defined (HAVE_POST_INCREMENT) || defined (HAVE_POST_DECREMENT)
1476 && try_auto_increment (overlap, insn, 0, src, insn_const, 0))
1481 rtx notes = REG_NOTES (insn);
1483 emit_insn_after_with_line_notes (pat, PREV_INSN (p), insn);
1484 PUT_CODE (insn, NOTE);
1485 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1486 NOTE_SOURCE_FILE (insn) = 0;
1487 /* emit_insn_after_with_line_notes has no
1488 return value, so search for the new insn. */
1489 for (insn = p; PATTERN (insn) != pat; )
1490 insn = PREV_INSN (insn);
1492 REG_NOTES (insn) = notes;
1495 /* Sometimes we'd generate src = const; src += n;
1496 if so, replace the instruction that set src
1497 in the first place. */
1499 if (! overlap && (code == PLUS || code == MINUS))
1501 rtx note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
1503 int num_calls2 = 0, s_length2 = 0;
1505 if (note && CONSTANT_P (XEXP (note, 0)))
1507 for (q = PREV_INSN (insn); q; q = PREV_INSN(q))
1509 if (GET_CODE (q) == CODE_LABEL || GET_CODE (q) == JUMP_INSN
1510 || (GET_CODE (q) == NOTE
1511 && (NOTE_LINE_NUMBER (q) == NOTE_INSN_LOOP_BEG
1512 || NOTE_LINE_NUMBER (q) == NOTE_INSN_LOOP_END)))
1518 /* ??? We can't scan past the end of a basic block without
1519 updating the register lifetime info
1520 (REG_DEAD/basic_block_live_at_start).
1521 A CALL_INSN might be the last insn of a basic block, if
1522 it is inside an EH region. There is no easy way to tell,
1523 so we just always break when we see a CALL_INSN if
1524 flag_exceptions is nonzero. */
1525 if (flag_exceptions && GET_CODE (q) == CALL_INSN)
1531 if (GET_RTX_CLASS (GET_CODE (q)) != 'i')
1534 if (reg_set_p (src, q))
1536 set2 = single_set (q);
1539 if (reg_overlap_mentioned_p (src, PATTERN (q)))
1544 if (GET_CODE (p) == CALL_INSN)
1547 if (q && set2 && SET_DEST (set2) == src && CONSTANT_P (SET_SRC (set2))
1548 && validate_change (insn, &SET_SRC (set), XEXP (note, 0), 0))
1551 NOTE_LINE_NUMBER (q) = NOTE_INSN_DELETED;
1552 NOTE_SOURCE_FILE (q) = 0;
1553 REG_N_SETS (REGNO (src))--;
1554 REG_N_CALLS_CROSSED (REGNO (src)) -= num_calls2;
1555 REG_N_REFS (REGNO (src)) -= true_loop_depth;
1556 REG_LIVE_LENGTH (REGNO (src)) -= s_length2;
1562 /* Don't remove this seemingly useless if, it is needed to pair with the
1563 else in the next two conditionally included code blocks. */
1566 #if defined (HAVE_PRE_INCREMENT) || defined (HAVE_PRE_DECREMENT)
1567 else if ((code == PLUS || code == MINUS) && insn_const
1568 && try_auto_increment (p, insn, 0, src, insn_const, 1))
1571 #if defined (HAVE_POST_INCREMENT) || defined (HAVE_POST_DECREMENT)
1573 && try_auto_increment (p, post_inc, post_inc_set, src, newconst, 0))
1576 #if defined (HAVE_PRE_INCREMENT) || defined (HAVE_PRE_DECREMENT)
1577 /* If post_inc still prevails, try to find an
1578 insn where it can be used as a pre-in/decrement.
1579 If code is MINUS, this was already tried. */
1580 if (post_inc && code == PLUS
1581 /* Check that newconst is likely to be usable
1582 in a pre-in/decrement before starting the search. */
1584 #if defined (HAVE_PRE_INCREMENT)
1585 || (newconst > 0 && newconst <= MOVE_MAX)
1587 #if defined (HAVE_PRE_DECREMENT)
1588 || (newconst < 0 && newconst >= -MOVE_MAX)
1590 ) && exact_log2 (newconst))
1594 inc_dest = post_inc_set ? SET_DEST (post_inc_set) : src;
1595 for (q = post_inc; (q = NEXT_INSN (q)); )
1597 if (GET_CODE (q) == CODE_LABEL || GET_CODE (q) == JUMP_INSN
1598 || (GET_CODE (q) == NOTE
1599 && (NOTE_LINE_NUMBER (q) == NOTE_INSN_LOOP_BEG
1600 || NOTE_LINE_NUMBER (q) == NOTE_INSN_LOOP_END)))
1603 /* ??? We can't scan past the end of a basic block without updating
1604 the register lifetime info (REG_DEAD/basic_block_live_at_start).
1605 A CALL_INSN might be the last insn of a basic block, if it
1606 is inside an EH region. There is no easy way to tell so we
1607 just always break when we see a CALL_INSN if flag_exceptions
1609 if (flag_exceptions && GET_CODE (q) == CALL_INSN)
1612 if (GET_RTX_CLASS (GET_CODE (q)) != 'i')
1614 if (src != inc_dest && (reg_overlap_mentioned_p (src, PATTERN (q))
1615 || reg_set_p (src, q)))
1617 if (reg_set_p (inc_dest, q))
1619 if (reg_overlap_mentioned_p (inc_dest, PATTERN (q)))
1621 try_auto_increment (q, post_inc,
1622 post_inc_set, inc_dest, newconst, 1);
1627 #endif /* defined (HAVE_PRE_INCREMENT) || defined (HAVE_PRE_DECREMENT) */
1628 /* Move the death note for DST to INSN if it is used
1630 if (reg_overlap_mentioned_p (dst, PATTERN (insn)))
1632 XEXP (dst_note, 1) = REG_NOTES (insn);
1633 REG_NOTES (insn) = dst_note;
1638 /* Move the death note for SRC from INSN to P. */
1640 remove_note (insn, src_note);
1641 XEXP (src_note, 1) = REG_NOTES (p);
1642 REG_NOTES (p) = src_note;
1644 REG_N_CALLS_CROSSED (REGNO (src)) += s_num_calls;
1647 REG_N_SETS (REGNO (src))++;
1648 REG_N_SETS (REGNO (dst))--;
1650 REG_N_CALLS_CROSSED (REGNO (dst)) -= num_calls;
1652 REG_LIVE_LENGTH (REGNO (src)) += s_length;
1653 if (REG_LIVE_LENGTH (REGNO (dst)) >= 0)
1655 REG_LIVE_LENGTH (REGNO (dst)) -= length;
1656 /* REG_LIVE_LENGTH is only an approximation after
1657 combine if sched is not run, so make sure that we
1658 still have a reasonable value. */
1659 if (REG_LIVE_LENGTH (REGNO (dst)) < 2)
1660 REG_LIVE_LENGTH (REGNO (dst)) = 2;
1663 /* We assume that a register is used exactly once per
1664 insn in the updates above. If this is not correct,
1665 no great harm is done. */
1667 REG_N_REFS (REGNO (src)) += 2 * true_loop_depth;
1668 REG_N_REFS (REGNO (dst)) -= 2 * true_loop_depth;
1670 /* If that was the only time dst was set,
1671 and dst was not live at the start of the
1672 function, we know that we have no more
1673 references to dst; clear REG_N_REFS so it
1674 won't make reload do any work. */
1675 if (REG_N_SETS (REGNO (dst)) == 0
1676 && ! regno_uninitialized (REGNO (dst)))
1677 REG_N_REFS (REGNO (dst)) = 0;
1679 if (regmove_dump_file)
1680 fprintf (regmove_dump_file,
1681 "Fixed operand %d of insn %d matching operand %d.\n",
1682 operand_number, INSN_UID (insn), match_number);
1687 /* return nonzero if X is stable but for mentioning SRC or mentioning /
1688 changing DST . If in doubt, presume it is unstable. */
1690 stable_but_for_p (x, src, dst)
1693 RTX_CODE code = GET_CODE (x);
1694 switch (GET_RTX_CLASS (code))
1696 case '<': case '1': case 'c': case '2': case 'b': case '3':
1699 char *fmt = GET_RTX_FORMAT (code);
1700 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1701 if (fmt[i] == 'e' && ! stable_but_for_p (XEXP (x, i), src, dst))
1706 if (x == src || x == dst)
1710 return ! rtx_unstable_p (x);
1714 /* Test if regmove seems profitable for this target. */
1716 regmove_profitable_p ()
1718 #ifdef REGISTER_CONSTRAINTS
1720 enum machine_mode mode;
1721 optab tstoptab = add_optab;
1722 do /* check add_optab and ashl_optab */
1723 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1724 mode = GET_MODE_WIDER_MODE (mode))
1726 int icode = (int) tstoptab->handlers[(int) mode].insn_code;
1727 rtx reg0, reg1, reg2, pat;
1730 if (GET_MODE_BITSIZE (mode) < 32 || icode == CODE_FOR_nothing)
1732 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1733 if (TEST_HARD_REG_BIT (reg_class_contents[GENERAL_REGS], i))
1735 if (i + 2 >= FIRST_PSEUDO_REGISTER)
1737 reg0 = gen_rtx_REG (insn_operand_mode[icode][0], i);
1738 reg1 = gen_rtx_REG (insn_operand_mode[icode][1], i + 1);
1739 reg2 = gen_rtx_REG (insn_operand_mode[icode][2], i + 2);
1740 if (! (*insn_operand_predicate[icode][0]) (reg0, VOIDmode)
1741 || ! (*insn_operand_predicate[icode][1]) (reg1, VOIDmode)
1742 || ! (*insn_operand_predicate[icode][2]) (reg2, VOIDmode))
1744 pat = GEN_FCN (icode) (reg0, reg1, reg2);
1747 if (GET_CODE (pat) == SEQUENCE)
1748 pat = XVECEXP (pat, 0, XVECLEN (pat, 0) - 1);
1750 pat = make_insn_raw (pat);
1751 if (! single_set (pat)
1752 || GET_CODE (SET_SRC (single_set (pat))) != tstoptab->code)
1753 /* Unexpected complexity; don't need to handle this unless
1754 we find a machine where this occurs and regmove should
1757 if (find_matches (pat, &match) >= 0)
1761 while (tstoptab != ashl_optab && (tstoptab = ashl_optab, 1));
1762 #endif /* REGISTER_CONSTRAINTS */