1 /* Move registers around to reduce number of move instructions needed.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This module looks for cases where matching constraints would force
24 an instruction to need a reload, and this reload would be a register
25 to register move. It then attempts to change the registers used by the
26 instruction to avoid the move instruction. */
30 #include "rtl.h" /* stdio.h must precede rtl.h for FFS. */
32 #include "insn-config.h"
36 #include "hard-reg-set.h"
40 #include "insn-flags.h"
41 #include "basic-block.h"
44 static int perhaps_ends_bb_p
PARAMS ((rtx
));
45 static int optimize_reg_copy_1
PARAMS ((rtx
, rtx
, rtx
));
46 static void optimize_reg_copy_2
PARAMS ((rtx
, rtx
, rtx
));
47 static void optimize_reg_copy_3
PARAMS ((rtx
, rtx
, rtx
));
48 static rtx gen_add3_insn
PARAMS ((rtx
, rtx
, rtx
));
49 static void copy_src_to_dest
PARAMS ((rtx
, rtx
, rtx
, int));
50 static int *regmove_bb_head
;
53 int with
[MAX_RECOG_OPERANDS
];
54 enum { READ
, WRITE
, READWRITE
} use
[MAX_RECOG_OPERANDS
];
55 int commutative
[MAX_RECOG_OPERANDS
];
56 int early_clobber
[MAX_RECOG_OPERANDS
];
59 static rtx discover_flags_reg
PARAMS ((void));
60 static void mark_flags_life_zones
PARAMS ((rtx
));
61 static void flags_set_1
PARAMS ((rtx
, rtx
, void *));
63 static int try_auto_increment
PARAMS ((rtx
, rtx
, rtx
, rtx
, HOST_WIDE_INT
, int));
64 static int find_matches
PARAMS ((rtx
, struct match
*));
65 static void replace_in_call_usage
PARAMS ((rtx
*, int, rtx
, rtx
));
66 static int fixup_match_1
PARAMS ((rtx
, rtx
, rtx
, rtx
, rtx
, int, int, int, FILE *))
68 static int reg_is_remote_constant_p
PARAMS ((rtx
, rtx
, rtx
));
69 static int stable_and_no_regs_but_for_p
PARAMS ((rtx
, rtx
, rtx
));
70 static int regclass_compatible_p
PARAMS ((int, int));
71 static int replacement_quality
PARAMS ((rtx
));
72 static int fixup_match_2
PARAMS ((rtx
, rtx
, rtx
, rtx
, FILE *));
74 /* Return non-zero if registers with CLASS1 and CLASS2 can be merged without
75 causing too much register allocation problems. */
77 regclass_compatible_p (class0
, class1
)
80 return (class0
== class1
81 || (reg_class_subset_p (class0
, class1
)
82 && ! CLASS_LIKELY_SPILLED_P (class0
))
83 || (reg_class_subset_p (class1
, class0
)
84 && ! CLASS_LIKELY_SPILLED_P (class1
)));
87 /* Generate and return an insn body to add r1 and c,
88 storing the result in r0. */
90 gen_add3_insn (r0
, r1
, c
)
93 int icode
= (int) add_optab
->handlers
[(int) GET_MODE (r0
)].insn_code
;
95 if (icode
== CODE_FOR_nothing
96 || ! ((*insn_data
[icode
].operand
[0].predicate
)
97 (r0
, insn_data
[icode
].operand
[0].mode
))
98 || ! ((*insn_data
[icode
].operand
[1].predicate
)
99 (r1
, insn_data
[icode
].operand
[1].mode
))
100 || ! ((*insn_data
[icode
].operand
[2].predicate
)
101 (c
, insn_data
[icode
].operand
[2].mode
)))
104 return (GEN_FCN (icode
) (r0
, r1
, c
));
108 /* INC_INSN is an instruction that adds INCREMENT to REG.
109 Try to fold INC_INSN as a post/pre in/decrement into INSN.
110 Iff INC_INSN_SET is nonzero, inc_insn has a destination different from src.
111 Return nonzero for success. */
113 try_auto_increment (insn
, inc_insn
, inc_insn_set
, reg
, increment
, pre
)
114 rtx reg
, insn
, inc_insn
,inc_insn_set
;
115 HOST_WIDE_INT increment
;
118 enum rtx_code inc_code
;
120 rtx pset
= single_set (insn
);
123 /* Can't use the size of SET_SRC, we might have something like
124 (sign_extend:SI (mem:QI ... */
125 rtx use
= find_use_as_address (pset
, reg
, 0);
126 if (use
!= 0 && use
!= (rtx
) 1)
128 int size
= GET_MODE_SIZE (GET_MODE (use
));
130 || (HAVE_POST_INCREMENT
131 && pre
== 0 && (inc_code
= POST_INC
, increment
== size
))
132 || (HAVE_PRE_INCREMENT
133 && pre
== 1 && (inc_code
= PRE_INC
, increment
== size
))
134 || (HAVE_POST_DECREMENT
135 && pre
== 0 && (inc_code
= POST_DEC
, increment
== -size
))
136 || (HAVE_PRE_DECREMENT
137 && pre
== 1 && (inc_code
= PRE_DEC
, increment
== -size
))
143 &SET_SRC (inc_insn_set
),
144 XEXP (SET_SRC (inc_insn_set
), 0), 1);
145 validate_change (insn
, &XEXP (use
, 0),
146 gen_rtx_fmt_e (inc_code
, Pmode
, reg
), 1);
147 if (apply_change_group ())
149 /* If there is a REG_DEAD note on this insn, we must
150 change this not to REG_UNUSED meaning that the register
151 is set, but the value is dead. Failure to do so will
152 result in a sched1 abort -- when it recomputes lifetime
153 information, the number of REG_DEAD notes will have
155 rtx note
= find_reg_note (insn
, REG_DEAD
, reg
);
157 PUT_MODE (note
, REG_UNUSED
);
160 = gen_rtx_EXPR_LIST (REG_INC
,
161 reg
, REG_NOTES (insn
));
164 PUT_CODE (inc_insn
, NOTE
);
165 NOTE_LINE_NUMBER (inc_insn
) = NOTE_INSN_DELETED
;
166 NOTE_SOURCE_FILE (inc_insn
) = 0;
176 /* Determine if the pattern generated by add_optab has a clobber,
177 such as might be issued for a flags hard register. To make the
178 code elsewhere simpler, we handle cc0 in this same framework.
180 Return the register if one was discovered. Return NULL_RTX if
181 if no flags were found. Return pc_rtx if we got confused. */
184 discover_flags_reg ()
187 tmp
= gen_rtx_REG (word_mode
, 10000);
188 tmp
= gen_add3_insn (tmp
, tmp
, GEN_INT (2));
190 /* If we get something that isn't a simple set, or a
191 [(set ..) (clobber ..)], this whole function will go wrong. */
192 if (GET_CODE (tmp
) == SET
)
194 else if (GET_CODE (tmp
) == PARALLEL
)
198 if (XVECLEN (tmp
, 0) != 2)
200 tmp
= XVECEXP (tmp
, 0, 1);
201 if (GET_CODE (tmp
) != CLOBBER
)
205 /* Don't do anything foolish if the md wanted to clobber a
206 scratch or something. We only care about hard regs.
207 Moreover we don't like the notion of subregs of hard regs. */
208 if (GET_CODE (tmp
) == SUBREG
209 && GET_CODE (SUBREG_REG (tmp
)) == REG
210 && REGNO (SUBREG_REG (tmp
)) < FIRST_PSEUDO_REGISTER
)
212 found
= (GET_CODE (tmp
) == REG
&& REGNO (tmp
) < FIRST_PSEUDO_REGISTER
);
214 return (found
? tmp
: NULL_RTX
);
220 /* It is a tedious task identifying when the flags register is live and
221 when it is safe to optimize. Since we process the instruction stream
222 multiple times, locate and record these live zones by marking the
223 mode of the instructions --
225 QImode is used on the instruction at which the flags becomes live.
227 HImode is used within the range (exclusive) that the flags are
228 live. Thus the user of the flags is not marked.
230 All other instructions are cleared to VOIDmode. */
232 /* Used to communicate with flags_set_1. */
233 static rtx flags_set_1_rtx
;
234 static int flags_set_1_set
;
237 mark_flags_life_zones (flags
)
245 /* If we found a flags register on a cc0 host, bail. */
246 if (flags
== NULL_RTX
)
248 else if (flags
!= cc0_rtx
)
252 /* Simple cases first: if no flags, clear all modes. If confusing,
253 mark the entire function as being in a flags shadow. */
254 if (flags
== NULL_RTX
|| flags
== pc_rtx
)
256 enum machine_mode mode
= (flags
? HImode
: VOIDmode
);
258 for (insn
= get_insns(); insn
; insn
= NEXT_INSN (insn
))
259 PUT_MODE (insn
, mode
);
267 flags_regno
= REGNO (flags
);
268 flags_nregs
= HARD_REGNO_NREGS (flags_regno
, GET_MODE (flags
));
270 flags_set_1_rtx
= flags
;
272 /* Process each basic block. */
273 for (block
= n_basic_blocks
- 1; block
>= 0; block
--)
278 insn
= BLOCK_HEAD (block
);
279 end
= BLOCK_END (block
);
281 /* Look out for the (unlikely) case of flags being live across
282 basic block boundaries. */
287 for (i
= 0; i
< flags_nregs
; ++i
)
288 live
|= REGNO_REG_SET_P (BASIC_BLOCK (block
)->global_live_at_start
,
295 /* Process liveness in reverse order of importance --
296 alive, death, birth. This lets more important info
297 overwrite the mode of lesser info. */
302 /* In the cc0 case, death is not marked in reg notes,
303 but is instead the mere use of cc0 when it is alive. */
304 if (live
&& reg_mentioned_p (cc0_rtx
, PATTERN (insn
)))
307 /* In the hard reg case, we watch death notes. */
308 if (live
&& find_regno_note (insn
, REG_DEAD
, flags_regno
))
311 PUT_MODE (insn
, (live
? HImode
: VOIDmode
));
313 /* In either case, birth is denoted simply by it's presence
314 as the destination of a set. */
316 note_stores (PATTERN (insn
), flags_set_1
, NULL
);
320 PUT_MODE (insn
, QImode
);
324 PUT_MODE (insn
, (live
? HImode
: VOIDmode
));
328 insn
= NEXT_INSN (insn
);
333 /* A subroutine of mark_flags_life_zones, called through note_stores. */
336 flags_set_1 (x
, pat
, data
)
338 void *data ATTRIBUTE_UNUSED
;
340 if (GET_CODE (pat
) == SET
341 && reg_overlap_mentioned_p (x
, flags_set_1_rtx
))
345 static int *regno_src_regno
;
347 /* Indicate how good a choice REG (which appears as a source) is to replace
348 a destination register with. The higher the returned value, the better
349 the choice. The main objective is to avoid using a register that is
350 a candidate for tying to a hard register, since the output might in
351 turn be a candidate to be tied to a different hard register. */
353 replacement_quality(reg
)
358 /* Bad if this isn't a register at all. */
359 if (GET_CODE (reg
) != REG
)
362 /* If this register is not meant to get a hard register,
363 it is a poor choice. */
364 if (REG_LIVE_LENGTH (REGNO (reg
)) < 0)
367 src_regno
= regno_src_regno
[REGNO (reg
)];
369 /* If it was not copied from another register, it is fine. */
373 /* Copied from a hard register? */
374 if (src_regno
< FIRST_PSEUDO_REGISTER
)
377 /* Copied from a pseudo register - not as bad as from a hard register,
378 yet still cumbersome, since the register live length will be lengthened
379 when the registers get tied. */
383 /* Return 1 if INSN might end a basic block. */
385 static int perhaps_ends_bb_p (insn
)
388 switch (GET_CODE (insn
))
392 /* These always end a basic block. */
396 /* A CALL_INSN might be the last insn of a basic block, if it is inside
397 an EH region or if there are nonlocal gotos. Note that this test is
398 very conservative. */
399 return flag_exceptions
|| nonlocal_goto_handler_labels
;
402 /* All others never end a basic block. */
407 /* INSN is a copy from SRC to DEST, both registers, and SRC does not die
410 Search forward to see if SRC dies before either it or DEST is modified,
411 but don't scan past the end of a basic block. If so, we can replace SRC
412 with DEST and let SRC die in INSN.
414 This will reduce the number of registers live in that range and may enable
415 DEST to be tied to SRC, thus often saving one register in addition to a
416 register-register copy. */
419 optimize_reg_copy_1 (insn
, dest
, src
)
427 int sregno
= REGNO (src
);
428 int dregno
= REGNO (dest
);
430 /* We don't want to mess with hard regs if register classes are small. */
432 || (SMALL_REGISTER_CLASSES
433 && (sregno
< FIRST_PSEUDO_REGISTER
434 || dregno
< FIRST_PSEUDO_REGISTER
))
435 /* We don't see all updates to SP if they are in an auto-inc memory
436 reference, so we must disallow this optimization on them. */
437 || sregno
== STACK_POINTER_REGNUM
|| dregno
== STACK_POINTER_REGNUM
)
440 for (p
= NEXT_INSN (insn
); p
; p
= NEXT_INSN (p
))
442 /* ??? We can't scan past the end of a basic block without updating
443 the register lifetime info (REG_DEAD/basic_block_live_at_start). */
444 if (perhaps_ends_bb_p (p
))
446 else if (! INSN_P (p
))
449 if (reg_set_p (src
, p
) || reg_set_p (dest
, p
)
450 /* Don't change a USE of a register. */
451 || (GET_CODE (PATTERN (p
)) == USE
452 && reg_overlap_mentioned_p (src
, XEXP (PATTERN (p
), 0))))
455 /* See if all of SRC dies in P. This test is slightly more
456 conservative than it needs to be. */
457 if ((note
= find_regno_note (p
, REG_DEAD
, sregno
)) != 0
458 && GET_MODE (XEXP (note
, 0)) == GET_MODE (src
))
466 /* We can do the optimization. Scan forward from INSN again,
467 replacing regs as we go. Set FAILED if a replacement can't
468 be done. In that case, we can't move the death note for SRC.
469 This should be rare. */
471 /* Set to stop at next insn. */
472 for (q
= next_real_insn (insn
);
473 q
!= next_real_insn (p
);
474 q
= next_real_insn (q
))
476 if (reg_overlap_mentioned_p (src
, PATTERN (q
)))
478 /* If SRC is a hard register, we might miss some
479 overlapping registers with validate_replace_rtx,
480 so we would have to undo it. We can't if DEST is
481 present in the insn, so fail in that combination
483 if (sregno
< FIRST_PSEUDO_REGISTER
484 && reg_mentioned_p (dest
, PATTERN (q
)))
487 /* Replace all uses and make sure that the register
488 isn't still present. */
489 else if (validate_replace_rtx (src
, dest
, q
)
490 && (sregno
>= FIRST_PSEUDO_REGISTER
491 || ! reg_overlap_mentioned_p (src
,
496 validate_replace_rtx (dest
, src
, q
);
501 /* For SREGNO, count the total number of insns scanned.
502 For DREGNO, count the total number of insns scanned after
503 passing the death note for DREGNO. */
508 /* If the insn in which SRC dies is a CALL_INSN, don't count it
509 as a call that has been crossed. Otherwise, count it. */
510 if (q
!= p
&& GET_CODE (q
) == CALL_INSN
)
512 /* Similarly, total calls for SREGNO, total calls beyond
513 the death note for DREGNO. */
519 /* If DEST dies here, remove the death note and save it for
520 later. Make sure ALL of DEST dies here; again, this is
521 overly conservative. */
523 && (dest_death
= find_regno_note (q
, REG_DEAD
, dregno
)) != 0)
525 if (GET_MODE (XEXP (dest_death
, 0)) != GET_MODE (dest
))
526 failed
= 1, dest_death
= 0;
528 remove_note (q
, dest_death
);
534 /* These counters need to be updated if and only if we are
535 going to move the REG_DEAD note. */
536 if (sregno
>= FIRST_PSEUDO_REGISTER
)
538 if (REG_LIVE_LENGTH (sregno
) >= 0)
540 REG_LIVE_LENGTH (sregno
) -= s_length
;
541 /* REG_LIVE_LENGTH is only an approximation after
542 combine if sched is not run, so make sure that we
543 still have a reasonable value. */
544 if (REG_LIVE_LENGTH (sregno
) < 2)
545 REG_LIVE_LENGTH (sregno
) = 2;
548 REG_N_CALLS_CROSSED (sregno
) -= s_n_calls
;
551 /* Move death note of SRC from P to INSN. */
552 remove_note (p
, note
);
553 XEXP (note
, 1) = REG_NOTES (insn
);
554 REG_NOTES (insn
) = note
;
557 /* DEST is also dead if INSN has a REG_UNUSED note for DEST. */
559 && (dest_death
= find_regno_note (insn
, REG_UNUSED
, dregno
)))
561 PUT_REG_NOTE_KIND (dest_death
, REG_DEAD
);
562 remove_note (insn
, dest_death
);
565 /* Put death note of DEST on P if we saw it die. */
568 XEXP (dest_death
, 1) = REG_NOTES (p
);
569 REG_NOTES (p
) = dest_death
;
571 if (dregno
>= FIRST_PSEUDO_REGISTER
)
573 /* If and only if we are moving the death note for DREGNO,
574 then we need to update its counters. */
575 if (REG_LIVE_LENGTH (dregno
) >= 0)
576 REG_LIVE_LENGTH (dregno
) += d_length
;
577 REG_N_CALLS_CROSSED (dregno
) += d_n_calls
;
584 /* If SRC is a hard register which is set or killed in some other
585 way, we can't do this optimization. */
586 else if (sregno
< FIRST_PSEUDO_REGISTER
587 && dead_or_set_p (p
, src
))
593 /* INSN is a copy of SRC to DEST, in which SRC dies. See if we now have
594 a sequence of insns that modify DEST followed by an insn that sets
595 SRC to DEST in which DEST dies, with no prior modification of DEST.
596 (There is no need to check if the insns in between actually modify
597 DEST. We should not have cases where DEST is not modified, but
598 the optimization is safe if no such modification is detected.)
599 In that case, we can replace all uses of DEST, starting with INSN and
600 ending with the set of SRC to DEST, with SRC. We do not do this
601 optimization if a CALL_INSN is crossed unless SRC already crosses a
602 call or if DEST dies before the copy back to SRC.
604 It is assumed that DEST and SRC are pseudos; it is too complicated to do
605 this for hard registers since the substitutions we may make might fail. */
608 optimize_reg_copy_2 (insn
, dest
, src
)
615 int sregno
= REGNO (src
);
616 int dregno
= REGNO (dest
);
618 for (p
= NEXT_INSN (insn
); p
; p
= NEXT_INSN (p
))
620 /* ??? We can't scan past the end of a basic block without updating
621 the register lifetime info (REG_DEAD/basic_block_live_at_start). */
622 if (perhaps_ends_bb_p (p
))
624 else if (! INSN_P (p
))
627 set
= single_set (p
);
628 if (set
&& SET_SRC (set
) == dest
&& SET_DEST (set
) == src
629 && find_reg_note (p
, REG_DEAD
, dest
))
631 /* We can do the optimization. Scan forward from INSN again,
632 replacing regs as we go. */
634 /* Set to stop at next insn. */
635 for (q
= insn
; q
!= NEXT_INSN (p
); q
= NEXT_INSN (q
))
638 if (reg_mentioned_p (dest
, PATTERN (q
)))
639 PATTERN (q
) = replace_rtx (PATTERN (q
), dest
, src
);
642 if (GET_CODE (q
) == CALL_INSN
)
644 REG_N_CALLS_CROSSED (dregno
)--;
645 REG_N_CALLS_CROSSED (sregno
)++;
649 remove_note (p
, find_reg_note (p
, REG_DEAD
, dest
));
650 REG_N_DEATHS (dregno
)--;
651 remove_note (insn
, find_reg_note (insn
, REG_DEAD
, src
));
652 REG_N_DEATHS (sregno
)--;
656 if (reg_set_p (src
, p
)
657 || find_reg_note (p
, REG_DEAD
, dest
)
658 || (GET_CODE (p
) == CALL_INSN
&& REG_N_CALLS_CROSSED (sregno
) == 0))
662 /* INSN is a ZERO_EXTEND or SIGN_EXTEND of SRC to DEST.
663 Look if SRC dies there, and if it is only set once, by loading
664 it from memory. If so, try to encorporate the zero/sign extension
665 into the memory read, change SRC to the mode of DEST, and alter
666 the remaining accesses to use the appropriate SUBREG. This allows
667 SRC and DEST to be tied later. */
669 optimize_reg_copy_3 (insn
, dest
, src
)
674 rtx src_reg
= XEXP (src
, 0);
675 int src_no
= REGNO (src_reg
);
676 int dst_no
= REGNO (dest
);
678 enum machine_mode old_mode
;
680 if (src_no
< FIRST_PSEUDO_REGISTER
681 || dst_no
< FIRST_PSEUDO_REGISTER
682 || ! find_reg_note (insn
, REG_DEAD
, src_reg
)
683 || REG_N_SETS (src_no
) != 1)
685 for (p
= PREV_INSN (insn
); p
&& ! reg_set_p (src_reg
, p
); p
= PREV_INSN (p
))
686 /* ??? We can't scan past the end of a basic block without updating
687 the register lifetime info (REG_DEAD/basic_block_live_at_start). */
688 if (perhaps_ends_bb_p (p
))
694 if (! (set
= single_set (p
))
695 || GET_CODE (SET_SRC (set
)) != MEM
696 || SET_DEST (set
) != src_reg
)
699 /* Be conserative: although this optimization is also valid for
700 volatile memory references, that could cause trouble in later passes. */
701 if (MEM_VOLATILE_P (SET_SRC (set
)))
704 /* Do not use a SUBREG to truncate from one mode to another if truncation
706 if (GET_MODE_BITSIZE (GET_MODE (src_reg
)) <= GET_MODE_BITSIZE (GET_MODE (src
))
707 && !TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (GET_MODE (src
)),
708 GET_MODE_BITSIZE (GET_MODE (src_reg
))))
711 old_mode
= GET_MODE (src_reg
);
712 PUT_MODE (src_reg
, GET_MODE (src
));
713 XEXP (src
, 0) = SET_SRC (set
);
715 /* Include this change in the group so that it's easily undone if
716 one of the changes in the group is invalid. */
717 validate_change (p
, &SET_SRC (set
), src
, 1);
719 /* Now walk forward making additional replacements. We want to be able
720 to undo all the changes if a later substitution fails. */
721 subreg
= gen_rtx_SUBREG (old_mode
, src_reg
, 0);
722 while (p
= NEXT_INSN (p
), p
!= insn
)
727 /* Make a tenative change. */
728 validate_replace_rtx_group (src_reg
, subreg
, p
);
731 validate_replace_rtx_group (src
, src_reg
, insn
);
733 /* Now see if all the changes are valid. */
734 if (! apply_change_group ())
736 /* One or more changes were no good. Back out everything. */
737 PUT_MODE (src_reg
, old_mode
);
738 XEXP (src
, 0) = src_reg
;
743 /* If we were not able to update the users of src to use dest directly, try
744 instead moving the value to dest directly before the operation. */
747 copy_src_to_dest (insn
, src
, dest
, old_max_uid
)
766 /* A REG_LIVE_LENGTH of -1 indicates the register is equivalent to a constant
767 or memory location and is used infrequently; a REG_LIVE_LENGTH of -2 is
768 parameter when there is no frame pointer that is not allocated a register.
769 For now, we just reject them, rather than incrementing the live length. */
771 if (GET_CODE (src
) == REG
772 && REG_LIVE_LENGTH (REGNO (src
)) > 0
773 && GET_CODE (dest
) == REG
774 && !RTX_UNCHANGING_P (dest
)
775 && REG_LIVE_LENGTH (REGNO (dest
)) > 0
776 && (set
= single_set (insn
)) != NULL_RTX
777 && !reg_mentioned_p (dest
, SET_SRC (set
))
778 && GET_MODE (src
) == GET_MODE (dest
))
780 int old_num_regs
= reg_rtx_no
;
782 /* Generate the src->dest move. */
784 emit_move_insn (dest
, src
);
785 seq
= gen_sequence ();
787 /* If this sequence uses new registers, we may not use it. */
788 if (old_num_regs
!= reg_rtx_no
789 || ! validate_replace_rtx (src
, dest
, insn
))
791 /* We have to restore reg_rtx_no to its old value, lest
792 recompute_reg_usage will try to compute the usage of the
793 new regs, yet reg_n_info is not valid for them. */
794 reg_rtx_no
= old_num_regs
;
797 emit_insn_before (seq
, insn
);
798 move_insn
= PREV_INSN (insn
);
799 p_move_notes
= ®_NOTES (move_insn
);
800 p_insn_notes
= ®_NOTES (insn
);
802 /* Move any notes mentioning src to the move instruction */
803 for (link
= REG_NOTES (insn
); link
!= NULL_RTX
; link
= next
)
805 next
= XEXP (link
, 1);
806 if (XEXP (link
, 0) == src
)
808 *p_move_notes
= link
;
809 p_move_notes
= &XEXP (link
, 1);
813 *p_insn_notes
= link
;
814 p_insn_notes
= &XEXP (link
, 1);
818 *p_move_notes
= NULL_RTX
;
819 *p_insn_notes
= NULL_RTX
;
821 /* Is the insn the head of a basic block? If so extend it */
822 insn_uid
= INSN_UID (insn
);
823 move_uid
= INSN_UID (move_insn
);
824 if (insn_uid
< old_max_uid
)
826 bb
= regmove_bb_head
[insn_uid
];
829 BLOCK_HEAD (bb
) = move_insn
;
830 regmove_bb_head
[insn_uid
] = -1;
834 /* Update the various register tables. */
835 dest_regno
= REGNO (dest
);
836 REG_N_SETS (dest_regno
) ++;
837 REG_LIVE_LENGTH (dest_regno
)++;
838 if (REGNO_FIRST_UID (dest_regno
) == insn_uid
)
839 REGNO_FIRST_UID (dest_regno
) = move_uid
;
841 src_regno
= REGNO (src
);
842 if (! find_reg_note (move_insn
, REG_DEAD
, src
))
843 REG_LIVE_LENGTH (src_regno
)++;
845 if (REGNO_FIRST_UID (src_regno
) == insn_uid
)
846 REGNO_FIRST_UID (src_regno
) = move_uid
;
848 if (REGNO_LAST_UID (src_regno
) == insn_uid
)
849 REGNO_LAST_UID (src_regno
) = move_uid
;
851 if (REGNO_LAST_NOTE_UID (src_regno
) == insn_uid
)
852 REGNO_LAST_NOTE_UID (src_regno
) = move_uid
;
857 /* Return whether REG is set in only one location, and is set to a
858 constant, but is set in a different basic block from INSN (an
859 instructions which uses REG). In this case REG is equivalent to a
860 constant, and we don't want to break that equivalence, because that
861 may increase register pressure and make reload harder. If REG is
862 set in the same basic block as INSN, we don't worry about it,
863 because we'll probably need a register anyhow (??? but what if REG
864 is used in a different basic block as well as this one?). FIRST is
865 the first insn in the function. */
868 reg_is_remote_constant_p (reg
, insn
, first
)
875 if (REG_N_SETS (REGNO (reg
)) != 1)
878 /* Look for the set. */
879 for (p
= LOG_LINKS (insn
); p
; p
= XEXP (p
, 1))
883 if (REG_NOTE_KIND (p
) != 0)
885 s
= single_set (XEXP (p
, 0));
887 && GET_CODE (SET_DEST (s
)) == REG
888 && REGNO (SET_DEST (s
)) == REGNO (reg
))
890 /* The register is set in the same basic block. */
895 for (p
= first
; p
&& p
!= insn
; p
= NEXT_INSN (p
))
903 && GET_CODE (SET_DEST (s
)) == REG
904 && REGNO (SET_DEST (s
)) == REGNO (reg
))
906 /* This is the instruction which sets REG. If there is a
907 REG_EQUAL note, then REG is equivalent to a constant. */
908 if (find_reg_note (p
, REG_EQUAL
, NULL_RTX
))
917 /* INSN is adding a CONST_INT to a REG. We search backwards looking for
918 another add immediate instruction with the same source and dest registers,
919 and if we find one, we change INSN to an increment, and return 1. If
920 no changes are made, we return 0.
923 (set (reg100) (plus reg1 offset1))
925 (set (reg100) (plus reg1 offset2))
927 (set (reg100) (plus reg1 offset1))
929 (set (reg100) (plus reg100 offset2-offset1)) */
931 /* ??? What does this comment mean? */
932 /* cse disrupts preincrement / postdecrement squences when it finds a
933 hard register as ultimate source, like the frame pointer. */
936 fixup_match_2 (insn
, dst
, src
, offset
, regmove_dump_file
)
937 rtx insn
, dst
, src
, offset
;
938 FILE *regmove_dump_file
;
940 rtx p
, dst_death
= 0;
941 int length
, num_calls
= 0;
943 /* If SRC dies in INSN, we'd have to move the death note. This is
944 considered to be very unlikely, so we just skip the optimization
946 if (find_regno_note (insn
, REG_DEAD
, REGNO (src
)))
949 /* Scan backward to find the first instruction that sets DST. */
951 for (length
= 0, p
= PREV_INSN (insn
); p
; p
= PREV_INSN (p
))
955 /* ??? We can't scan past the end of a basic block without updating
956 the register lifetime info (REG_DEAD/basic_block_live_at_start). */
957 if (perhaps_ends_bb_p (p
))
959 else if (! INSN_P (p
))
962 if (find_regno_note (p
, REG_DEAD
, REGNO (dst
)))
967 pset
= single_set (p
);
968 if (pset
&& SET_DEST (pset
) == dst
969 && GET_CODE (SET_SRC (pset
)) == PLUS
970 && XEXP (SET_SRC (pset
), 0) == src
971 && GET_CODE (XEXP (SET_SRC (pset
), 1)) == CONST_INT
)
973 HOST_WIDE_INT newconst
974 = INTVAL (offset
) - INTVAL (XEXP (SET_SRC (pset
), 1));
975 rtx add
= gen_add3_insn (dst
, dst
, GEN_INT (newconst
));
977 if (add
&& validate_change (insn
, &PATTERN (insn
), add
, 0))
979 /* Remove the death note for DST from DST_DEATH. */
982 remove_death (REGNO (dst
), dst_death
);
983 REG_LIVE_LENGTH (REGNO (dst
)) += length
;
984 REG_N_CALLS_CROSSED (REGNO (dst
)) += num_calls
;
987 if (regmove_dump_file
)
988 fprintf (regmove_dump_file
,
989 "Fixed operand of insn %d.\n",
993 for (p
= PREV_INSN (insn
); p
; p
= PREV_INSN (p
))
995 if (GET_CODE (p
) == CODE_LABEL
996 || GET_CODE (p
) == JUMP_INSN
)
1000 if (reg_overlap_mentioned_p (dst
, PATTERN (p
)))
1002 if (try_auto_increment (p
, insn
, 0, dst
, newconst
, 0))
1007 for (p
= NEXT_INSN (insn
); p
; p
= NEXT_INSN (p
))
1009 if (GET_CODE (p
) == CODE_LABEL
1010 || GET_CODE (p
) == JUMP_INSN
)
1014 if (reg_overlap_mentioned_p (dst
, PATTERN (p
)))
1016 try_auto_increment (p
, insn
, 0, dst
, newconst
, 1);
1025 if (reg_set_p (dst
, PATTERN (p
)))
1028 /* If we have passed a call instruction, and the
1029 pseudo-reg SRC is not already live across a call,
1030 then don't perform the optimization. */
1031 /* reg_set_p is overly conservative for CALL_INSNS, thinks that all
1032 hard regs are clobbered. Thus, we only use it for src for
1034 if (GET_CODE (p
) == CALL_INSN
)
1039 if (REG_N_CALLS_CROSSED (REGNO (src
)) == 0)
1042 if (call_used_regs
[REGNO (dst
)]
1043 || find_reg_fusage (p
, CLOBBER
, dst
))
1046 else if (reg_set_p (src
, PATTERN (p
)))
1054 regmove_optimize (f
, nregs
, regmove_dump_file
)
1057 FILE *regmove_dump_file
;
1059 int old_max_uid
= get_max_uid ();
1064 rtx copy_src
, copy_dst
;
1066 /* Find out where a potential flags register is live, and so that we
1067 can supress some optimizations in those zones. */
1068 mark_flags_life_zones (discover_flags_reg ());
1070 regno_src_regno
= (int *) xmalloc (sizeof *regno_src_regno
* nregs
);
1071 for (i
= nregs
; --i
>= 0; ) regno_src_regno
[i
] = -1;
1073 regmove_bb_head
= (int *) xmalloc (sizeof (int) * (old_max_uid
+ 1));
1074 for (i
= old_max_uid
; i
>= 0; i
--) regmove_bb_head
[i
] = -1;
1075 for (i
= 0; i
< n_basic_blocks
; i
++)
1076 regmove_bb_head
[INSN_UID (BLOCK_HEAD (i
))] = i
;
1078 /* A forward/backward pass. Replace output operands with input operands. */
1080 for (pass
= 0; pass
<= 2; pass
++)
1082 if (! flag_regmove
&& pass
>= flag_expensive_optimizations
)
1085 if (regmove_dump_file
)
1086 fprintf (regmove_dump_file
, "Starting %s pass...\n",
1087 pass
? "backward" : "forward");
1089 for (insn
= pass
? get_last_insn () : f
; insn
;
1090 insn
= pass
? PREV_INSN (insn
) : NEXT_INSN (insn
))
1093 int op_no
, match_no
;
1095 set
= single_set (insn
);
1099 if (flag_expensive_optimizations
&& ! pass
1100 && (GET_CODE (SET_SRC (set
)) == SIGN_EXTEND
1101 || GET_CODE (SET_SRC (set
)) == ZERO_EXTEND
)
1102 && GET_CODE (XEXP (SET_SRC (set
), 0)) == REG
1103 && GET_CODE (SET_DEST(set
)) == REG
)
1104 optimize_reg_copy_3 (insn
, SET_DEST (set
), SET_SRC (set
));
1106 if (flag_expensive_optimizations
&& ! pass
1107 && GET_CODE (SET_SRC (set
)) == REG
1108 && GET_CODE (SET_DEST(set
)) == REG
)
1110 /* If this is a register-register copy where SRC is not dead,
1111 see if we can optimize it. If this optimization succeeds,
1112 it will become a copy where SRC is dead. */
1113 if ((find_reg_note (insn
, REG_DEAD
, SET_SRC (set
))
1114 || optimize_reg_copy_1 (insn
, SET_DEST (set
), SET_SRC (set
)))
1115 && REGNO (SET_DEST (set
)) >= FIRST_PSEUDO_REGISTER
)
1117 /* Similarly for a pseudo-pseudo copy when SRC is dead. */
1118 if (REGNO (SET_SRC (set
)) >= FIRST_PSEUDO_REGISTER
)
1119 optimize_reg_copy_2 (insn
, SET_DEST (set
), SET_SRC (set
));
1120 if (regno_src_regno
[REGNO (SET_DEST (set
))] < 0
1121 && SET_SRC (set
) != SET_DEST (set
))
1123 int srcregno
= REGNO (SET_SRC(set
));
1124 if (regno_src_regno
[srcregno
] >= 0)
1125 srcregno
= regno_src_regno
[srcregno
];
1126 regno_src_regno
[REGNO (SET_DEST (set
))] = srcregno
;
1133 if (! find_matches (insn
, &match
))
1136 /* Now scan through the operands looking for a source operand
1137 which is supposed to match the destination operand.
1138 Then scan forward for an instruction which uses the dest
1140 If it dies there, then replace the dest in both operands with
1141 the source operand. */
1143 for (op_no
= 0; op_no
< recog_data
.n_operands
; op_no
++)
1145 rtx src
, dst
, src_subreg
;
1146 enum reg_class src_class
, dst_class
;
1148 match_no
= match
.with
[op_no
];
1150 /* Nothing to do if the two operands aren't supposed to match. */
1154 src
= recog_data
.operand
[op_no
];
1155 dst
= recog_data
.operand
[match_no
];
1157 if (GET_CODE (src
) != REG
)
1161 if (GET_CODE (dst
) == SUBREG
1162 && GET_MODE_SIZE (GET_MODE (dst
))
1163 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (dst
))))
1166 = gen_rtx_SUBREG (GET_MODE (SUBREG_REG (dst
)),
1167 src
, SUBREG_WORD (dst
));
1168 dst
= SUBREG_REG (dst
);
1170 if (GET_CODE (dst
) != REG
1171 || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
1174 if (REGNO (src
) < FIRST_PSEUDO_REGISTER
)
1176 if (match
.commutative
[op_no
] < op_no
)
1177 regno_src_regno
[REGNO (dst
)] = REGNO (src
);
1181 if (REG_LIVE_LENGTH (REGNO (src
)) < 0)
1184 /* op_no/src must be a read-only operand, and
1185 match_operand/dst must be a write-only operand. */
1186 if (match
.use
[op_no
] != READ
1187 || match
.use
[match_no
] != WRITE
)
1190 if (match
.early_clobber
[match_no
]
1191 && count_occurrences (PATTERN (insn
), src
, 0) > 1)
1194 /* Make sure match_operand is the destination. */
1195 if (recog_data
.operand
[match_no
] != SET_DEST (set
))
1198 /* If the operands already match, then there is nothing to do. */
1199 if (operands_match_p (src
, dst
))
1202 /* But in the commutative case, we might find a better match. */
1203 if (match
.commutative
[op_no
] >= 0)
1205 rtx comm
= recog_data
.operand
[match
.commutative
[op_no
]];
1206 if (operands_match_p (comm
, dst
)
1207 && (replacement_quality (comm
)
1208 >= replacement_quality (src
)))
1212 src_class
= reg_preferred_class (REGNO (src
));
1213 dst_class
= reg_preferred_class (REGNO (dst
));
1214 if (! regclass_compatible_p (src_class
, dst_class
))
1217 if (fixup_match_1 (insn
, set
, src
, src_subreg
, dst
, pass
,
1225 /* A backward pass. Replace input operands with output operands. */
1227 if (regmove_dump_file
)
1228 fprintf (regmove_dump_file
, "Starting backward pass...\n");
1230 for (insn
= get_last_insn (); insn
; insn
= PREV_INSN (insn
))
1234 int op_no
, match_no
;
1237 if (! find_matches (insn
, &match
))
1240 /* Now scan through the operands looking for a destination operand
1241 which is supposed to match a source operand.
1242 Then scan backward for an instruction which sets the source
1243 operand. If safe, then replace the source operand with the
1244 dest operand in both instructions. */
1246 copy_src
= NULL_RTX
;
1247 copy_dst
= NULL_RTX
;
1248 for (op_no
= 0; op_no
< recog_data
.n_operands
; op_no
++)
1250 rtx set
, p
, src
, dst
;
1251 rtx src_note
, dst_note
;
1253 enum reg_class src_class
, dst_class
;
1256 match_no
= match
.with
[op_no
];
1258 /* Nothing to do if the two operands aren't supposed to match. */
1262 dst
= recog_data
.operand
[match_no
];
1263 src
= recog_data
.operand
[op_no
];
1265 if (GET_CODE (src
) != REG
)
1268 if (GET_CODE (dst
) != REG
1269 || REGNO (dst
) < FIRST_PSEUDO_REGISTER
1270 || REG_LIVE_LENGTH (REGNO (dst
)) < 0)
1273 /* If the operands already match, then there is nothing to do. */
1274 if (operands_match_p (src
, dst
))
1277 if (match
.commutative
[op_no
] >= 0)
1279 rtx comm
= recog_data
.operand
[match
.commutative
[op_no
]];
1280 if (operands_match_p (comm
, dst
))
1284 set
= single_set (insn
);
1288 /* match_no/dst must be a write-only operand, and
1289 operand_operand/src must be a read-only operand. */
1290 if (match
.use
[op_no
] != READ
1291 || match
.use
[match_no
] != WRITE
)
1294 if (match
.early_clobber
[match_no
]
1295 && count_occurrences (PATTERN (insn
), src
, 0) > 1)
1298 /* Make sure match_no is the destination. */
1299 if (recog_data
.operand
[match_no
] != SET_DEST (set
))
1302 if (REGNO (src
) < FIRST_PSEUDO_REGISTER
)
1304 if (GET_CODE (SET_SRC (set
)) == PLUS
1305 && GET_CODE (XEXP (SET_SRC (set
), 1)) == CONST_INT
1306 && XEXP (SET_SRC (set
), 0) == src
1307 && fixup_match_2 (insn
, dst
, src
,
1308 XEXP (SET_SRC (set
), 1),
1313 src_class
= reg_preferred_class (REGNO (src
));
1314 dst_class
= reg_preferred_class (REGNO (dst
));
1315 if (! regclass_compatible_p (src_class
, dst_class
))
1325 /* Can not modify an earlier insn to set dst if this insn
1326 uses an old value in the source. */
1327 if (reg_overlap_mentioned_p (dst
, SET_SRC (set
)))
1337 if (! (src_note
= find_reg_note (insn
, REG_DEAD
, src
)))
1348 /* If src is set once in a different basic block,
1349 and is set equal to a constant, then do not use
1350 it for this optimization, as this would make it
1351 no longer equivalent to a constant. */
1353 if (reg_is_remote_constant_p (src
, insn
, f
))
1364 if (regmove_dump_file
)
1365 fprintf (regmove_dump_file
,
1366 "Could fix operand %d of insn %d matching operand %d.\n",
1367 op_no
, INSN_UID (insn
), match_no
);
1369 /* Scan backward to find the first instruction that uses
1370 the input operand. If the operand is set here, then
1371 replace it in both instructions with match_no. */
1373 for (length
= 0, p
= PREV_INSN (insn
); p
; p
= PREV_INSN (p
))
1377 /* ??? We can't scan past the end of a basic block without
1378 updating the register lifetime info
1379 (REG_DEAD/basic_block_live_at_start). */
1380 if (perhaps_ends_bb_p (p
))
1382 else if (! INSN_P (p
))
1387 /* ??? See if all of SRC is set in P. This test is much
1388 more conservative than it needs to be. */
1389 pset
= single_set (p
);
1390 if (pset
&& SET_DEST (pset
) == src
)
1392 /* We use validate_replace_rtx, in case there
1393 are multiple identical source operands. All of
1394 them have to be changed at the same time. */
1395 if (validate_replace_rtx (src
, dst
, insn
))
1397 if (validate_change (p
, &SET_DEST (pset
),
1402 /* Change all source operands back.
1403 This modifies the dst as a side-effect. */
1404 validate_replace_rtx (dst
, src
, insn
);
1405 /* Now make sure the dst is right. */
1406 validate_change (insn
,
1407 recog_data
.operand_loc
[match_no
],
1414 if (reg_overlap_mentioned_p (src
, PATTERN (p
))
1415 || reg_overlap_mentioned_p (dst
, PATTERN (p
)))
1418 /* If we have passed a call instruction, and the
1419 pseudo-reg DST is not already live across a call,
1420 then don't perform the optimization. */
1421 if (GET_CODE (p
) == CALL_INSN
)
1425 if (REG_N_CALLS_CROSSED (REGNO (dst
)) == 0)
1434 /* Remove the death note for SRC from INSN. */
1435 remove_note (insn
, src_note
);
1436 /* Move the death note for SRC to P if it is used
1438 if (reg_overlap_mentioned_p (src
, PATTERN (p
)))
1440 XEXP (src_note
, 1) = REG_NOTES (p
);
1441 REG_NOTES (p
) = src_note
;
1443 /* If there is a REG_DEAD note for DST on P, then remove
1444 it, because DST is now set there. */
1445 if ((dst_note
= find_reg_note (p
, REG_DEAD
, dst
)))
1446 remove_note (p
, dst_note
);
1448 dstno
= REGNO (dst
);
1449 srcno
= REGNO (src
);
1451 REG_N_SETS (dstno
)++;
1452 REG_N_SETS (srcno
)--;
1454 REG_N_CALLS_CROSSED (dstno
) += num_calls
;
1455 REG_N_CALLS_CROSSED (srcno
) -= num_calls
;
1457 REG_LIVE_LENGTH (dstno
) += length
;
1458 if (REG_LIVE_LENGTH (srcno
) >= 0)
1460 REG_LIVE_LENGTH (srcno
) -= length
;
1461 /* REG_LIVE_LENGTH is only an approximation after
1462 combine if sched is not run, so make sure that we
1463 still have a reasonable value. */
1464 if (REG_LIVE_LENGTH (srcno
) < 2)
1465 REG_LIVE_LENGTH (srcno
) = 2;
1468 if (regmove_dump_file
)
1469 fprintf (regmove_dump_file
,
1470 "Fixed operand %d of insn %d matching operand %d.\n",
1471 op_no
, INSN_UID (insn
), match_no
);
1477 /* If we weren't able to replace any of the alternatives, try an
1478 alternative appoach of copying the source to the destination. */
1479 if (!success
&& copy_src
!= NULL_RTX
)
1480 copy_src_to_dest (insn
, copy_src
, copy_dst
, old_max_uid
);
1485 /* In fixup_match_1, some insns may have been inserted after basic block
1486 ends. Fix that here. */
1487 for (i
= 0; i
< n_basic_blocks
; i
++)
1489 rtx end
= BLOCK_END (i
);
1491 rtx next
= NEXT_INSN (new);
1492 while (next
!= 0 && INSN_UID (next
) >= old_max_uid
1493 && (i
== n_basic_blocks
- 1 || BLOCK_HEAD (i
+ 1) != next
))
1494 new = next
, next
= NEXT_INSN (new);
1495 BLOCK_END (i
) = new;
1500 free (regno_src_regno
);
1501 free (regmove_bb_head
);
1504 /* Returns nonzero if INSN's pattern has matching constraints for any operand.
1505 Returns 0 if INSN can't be recognized, or if the alternative can't be
1508 Initialize the info in MATCHP based on the constraints. */
1511 find_matches (insn
, matchp
)
1513 struct match
*matchp
;
1515 int likely_spilled
[MAX_RECOG_OPERANDS
];
1517 int any_matches
= 0;
1519 extract_insn (insn
);
1520 if (! constrain_operands (0))
1523 /* Must initialize this before main loop, because the code for
1524 the commutative case may set matches for operands other than
1526 for (op_no
= recog_data
.n_operands
; --op_no
>= 0; )
1527 matchp
->with
[op_no
] = matchp
->commutative
[op_no
] = -1;
1529 for (op_no
= 0; op_no
< recog_data
.n_operands
; op_no
++)
1535 p
= recog_data
.constraints
[op_no
];
1537 likely_spilled
[op_no
] = 0;
1538 matchp
->use
[op_no
] = READ
;
1539 matchp
->early_clobber
[op_no
] = 0;
1541 matchp
->use
[op_no
] = WRITE
;
1543 matchp
->use
[op_no
] = READWRITE
;
1545 for (;*p
&& i
< which_alternative
; p
++)
1549 while ((c
= *p
++) != '\0' && c
!= ',')
1557 matchp
->early_clobber
[op_no
] = 1;
1560 matchp
->commutative
[op_no
] = op_no
+ 1;
1561 matchp
->commutative
[op_no
+ 1] = op_no
;
1563 case '0': case '1': case '2': case '3': case '4':
1564 case '5': case '6': case '7': case '8': case '9':
1566 if (c
< op_no
&& likely_spilled
[(unsigned char) c
])
1568 matchp
->with
[op_no
] = c
;
1570 if (matchp
->commutative
[op_no
] >= 0)
1571 matchp
->with
[matchp
->commutative
[op_no
]] = c
;
1573 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'h':
1574 case 'j': case 'k': case 'l': case 'p': case 'q': case 't': case 'u':
1575 case 'v': case 'w': case 'x': case 'y': case 'z': case 'A': case 'B':
1576 case 'C': case 'D': case 'W': case 'Y': case 'Z':
1577 if (CLASS_LIKELY_SPILLED_P (REG_CLASS_FROM_LETTER ((unsigned char)c
)))
1578 likely_spilled
[op_no
] = 1;
1585 /* Try to replace all occurrences of DST_REG with SRC in LOC, that is
1586 assumed to be in INSN. */
1589 replace_in_call_usage (loc
, dst_reg
, src
, insn
)
1603 code
= GET_CODE (x
);
1606 if (REGNO (x
) != dst_reg
)
1609 validate_change (insn
, loc
, src
, 1);
1614 /* Process each of our operands recursively. */
1615 fmt
= GET_RTX_FORMAT (code
);
1616 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
1618 replace_in_call_usage (&XEXP (x
, i
), dst_reg
, src
, insn
);
1619 else if (*fmt
== 'E')
1620 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1621 replace_in_call_usage (& XVECEXP (x
, i
, j
), dst_reg
, src
, insn
);
1624 /* Try to replace output operand DST in SET, with input operand SRC. SET is
1625 the only set in INSN. INSN has just been recognized and constrained.
1626 SRC is operand number OPERAND_NUMBER in INSN.
1627 DST is operand number MATCH_NUMBER in INSN.
1628 If BACKWARD is nonzero, we have been called in a backward pass.
1629 Return nonzero for success. */
1632 fixup_match_1 (insn
, set
, src
, src_subreg
, dst
, backward
, operand_number
,
1633 match_number
, regmove_dump_file
)
1634 rtx insn
, set
, src
, src_subreg
, dst
;
1635 int backward
, operand_number
, match_number
;
1636 FILE *regmove_dump_file
;
1639 rtx post_inc
= 0, post_inc_set
= 0, search_end
= 0;
1641 int num_calls
= 0, s_num_calls
= 0;
1642 enum rtx_code code
= NOTE
;
1643 HOST_WIDE_INT insn_const
= 0, newconst
;
1644 rtx overlap
= 0; /* need to move insn ? */
1645 rtx src_note
= find_reg_note (insn
, REG_DEAD
, src
), dst_note
= NULL_RTX
;
1646 int length
, s_length
;
1648 /* If SRC is marked as unchanging, we may not change it.
1649 ??? Maybe we could get better code by removing the unchanging bit
1650 instead, and changing it back if we don't succeed? */
1651 if (RTX_UNCHANGING_P (src
))
1656 /* Look for (set (regX) (op regA constX))
1657 (set (regY) (op regA constY))
1659 (set (regA) (op regA constX)).
1660 (set (regY) (op regA constY-constX)).
1661 This works for add and shift operations, if
1662 regA is dead after or set by the second insn. */
1664 code
= GET_CODE (SET_SRC (set
));
1665 if ((code
== PLUS
|| code
== LSHIFTRT
1666 || code
== ASHIFT
|| code
== ASHIFTRT
)
1667 && XEXP (SET_SRC (set
), 0) == src
1668 && GET_CODE (XEXP (SET_SRC (set
), 1)) == CONST_INT
)
1669 insn_const
= INTVAL (XEXP (SET_SRC (set
), 1));
1670 else if (! stable_and_no_regs_but_for_p (SET_SRC (set
), src
, dst
))
1673 /* We might find a src_note while scanning. */
1677 if (regmove_dump_file
)
1678 fprintf (regmove_dump_file
,
1679 "Could fix operand %d of insn %d matching operand %d.\n",
1680 operand_number
, INSN_UID (insn
), match_number
);
1682 /* If SRC is equivalent to a constant set in a different basic block,
1683 then do not use it for this optimization. We want the equivalence
1684 so that if we have to reload this register, we can reload the
1685 constant, rather than extending the lifespan of the register. */
1686 if (reg_is_remote_constant_p (src
, insn
, get_insns ()))
1689 /* Scan forward to find the next instruction that
1690 uses the output operand. If the operand dies here,
1691 then replace it in both instructions with
1694 for (length
= s_length
= 0, p
= NEXT_INSN (insn
); p
; p
= NEXT_INSN (p
))
1696 if (GET_CODE (p
) == CALL_INSN
)
1697 replace_in_call_usage (& CALL_INSN_FUNCTION_USAGE (p
),
1698 REGNO (dst
), src
, p
);
1700 /* ??? We can't scan past the end of a basic block without updating
1701 the register lifetime info (REG_DEAD/basic_block_live_at_start). */
1702 if (perhaps_ends_bb_p (p
))
1704 else if (! INSN_P (p
))
1711 if (reg_set_p (src
, p
) || reg_set_p (dst
, p
)
1712 || (GET_CODE (PATTERN (p
)) == USE
1713 && reg_overlap_mentioned_p (src
, XEXP (PATTERN (p
), 0))))
1716 /* See if all of DST dies in P. This test is
1717 slightly more conservative than it needs to be. */
1718 if ((dst_note
= find_regno_note (p
, REG_DEAD
, REGNO (dst
)))
1719 && (GET_MODE (XEXP (dst_note
, 0)) == GET_MODE (dst
)))
1721 /* If we would be moving INSN, check that we won't move it
1722 into the shadow of a live a live flags register. */
1723 /* ??? We only try to move it in front of P, although
1724 we could move it anywhere between OVERLAP and P. */
1725 if (overlap
&& GET_MODE (PREV_INSN (p
)) != VOIDmode
)
1731 rtx set2
= NULL_RTX
;
1733 /* If an optimization is done, the value of SRC while P
1734 is executed will be changed. Check that this is OK. */
1735 if (reg_overlap_mentioned_p (src
, PATTERN (p
)))
1737 for (q
= p
; q
; q
= NEXT_INSN (q
))
1739 /* ??? We can't scan past the end of a basic block without
1740 updating the register lifetime info
1741 (REG_DEAD/basic_block_live_at_start). */
1742 if (perhaps_ends_bb_p (q
))
1747 else if (! INSN_P (q
))
1749 else if (reg_overlap_mentioned_p (src
, PATTERN (q
))
1750 || reg_set_p (src
, q
))
1754 set2
= single_set (q
);
1755 if (! q
|| ! set2
|| GET_CODE (SET_SRC (set2
)) != code
1756 || XEXP (SET_SRC (set2
), 0) != src
1757 || GET_CODE (XEXP (SET_SRC (set2
), 1)) != CONST_INT
1758 || (SET_DEST (set2
) != src
1759 && ! find_reg_note (q
, REG_DEAD
, src
)))
1761 /* If this is a PLUS, we can still save a register by doing
1764 src -= insn_const; .
1765 This also gives opportunities for subsequent
1766 optimizations in the backward pass, so do it there. */
1767 if (code
== PLUS
&& backward
1768 /* Don't do this if we can likely tie DST to SET_DEST
1769 of P later; we can't do this tying here if we got a
1771 && ! (dst_note
&& ! REG_N_CALLS_CROSSED (REGNO (dst
))
1773 && GET_CODE (SET_DEST (single_set (p
))) == REG
1774 && (REGNO (SET_DEST (single_set (p
)))
1775 < FIRST_PSEUDO_REGISTER
))
1776 /* We may only emit an insn directly after P if we
1777 are not in the shadow of a live flags register. */
1778 && GET_MODE (p
) == VOIDmode
)
1783 newconst
= -insn_const
;
1791 newconst
= INTVAL (XEXP (SET_SRC (set2
), 1)) - insn_const
;
1792 /* Reject out of range shifts. */
1795 || ((unsigned HOST_WIDE_INT
) newconst
1796 >= (GET_MODE_BITSIZE (GET_MODE
1797 (SET_SRC (set2
)))))))
1802 if (SET_DEST (set2
) != src
)
1803 post_inc_set
= set2
;
1806 /* We use 1 as last argument to validate_change so that all
1807 changes are accepted or rejected together by apply_change_group
1808 when it is called by validate_replace_rtx . */
1809 validate_change (q
, &XEXP (SET_SRC (set2
), 1),
1810 GEN_INT (newconst
), 1);
1812 validate_change (insn
, recog_data
.operand_loc
[match_number
], src
, 1);
1813 if (validate_replace_rtx (dst
, src_subreg
, p
))
1818 if (reg_overlap_mentioned_p (dst
, PATTERN (p
)))
1820 if (! src_note
&& reg_overlap_mentioned_p (src
, PATTERN (p
)))
1822 /* INSN was already checked to be movable wrt. the registers that it
1823 sets / uses when we found no REG_DEAD note for src on it, but it
1824 still might clobber the flags register. We'll have to check that
1825 we won't insert it into the shadow of a live flags register when
1826 we finally know where we are to move it. */
1828 src_note
= find_reg_note (p
, REG_DEAD
, src
);
1831 /* If we have passed a call instruction, and the pseudo-reg SRC is not
1832 already live across a call, then don't perform the optimization. */
1833 if (GET_CODE (p
) == CALL_INSN
)
1835 if (REG_N_CALLS_CROSSED (REGNO (src
)) == 0)
1849 /* Remove the death note for DST from P. */
1850 remove_note (p
, dst_note
);
1853 post_inc
= emit_insn_after (copy_rtx (PATTERN (insn
)), p
);
1854 if ((HAVE_PRE_INCREMENT
|| HAVE_PRE_DECREMENT
)
1856 && try_auto_increment (search_end
, post_inc
, 0, src
, newconst
, 1))
1858 validate_change (insn
, &XEXP (SET_SRC (set
), 1), GEN_INT (insn_const
), 0);
1859 REG_N_SETS (REGNO (src
))++;
1860 REG_LIVE_LENGTH (REGNO (src
))++;
1864 /* The lifetime of src and dest overlap,
1865 but we can change this by moving insn. */
1866 rtx pat
= PATTERN (insn
);
1868 remove_note (overlap
, src_note
);
1869 if ((HAVE_POST_INCREMENT
|| HAVE_POST_DECREMENT
)
1871 && try_auto_increment (overlap
, insn
, 0, src
, insn_const
, 0))
1875 rtx notes
= REG_NOTES (insn
);
1877 emit_insn_after_with_line_notes (pat
, PREV_INSN (p
), insn
);
1878 PUT_CODE (insn
, NOTE
);
1879 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1880 NOTE_SOURCE_FILE (insn
) = 0;
1881 /* emit_insn_after_with_line_notes has no
1882 return value, so search for the new insn. */
1884 while (! INSN_P (insn
) || PATTERN (insn
) != pat
)
1885 insn
= PREV_INSN (insn
);
1887 REG_NOTES (insn
) = notes
;
1890 /* Sometimes we'd generate src = const; src += n;
1891 if so, replace the instruction that set src
1892 in the first place. */
1894 if (! overlap
&& (code
== PLUS
|| code
== MINUS
))
1896 rtx note
= find_reg_note (insn
, REG_EQUAL
, NULL_RTX
);
1897 rtx q
, set2
= NULL_RTX
;
1898 int num_calls2
= 0, s_length2
= 0;
1900 if (note
&& CONSTANT_P (XEXP (note
, 0)))
1902 for (q
= PREV_INSN (insn
); q
; q
= PREV_INSN(q
))
1904 /* ??? We can't scan past the end of a basic block without
1905 updating the register lifetime info
1906 (REG_DEAD/basic_block_live_at_start). */
1907 if (perhaps_ends_bb_p (q
))
1912 else if (! INSN_P (q
))
1916 if (reg_set_p (src
, q
))
1918 set2
= single_set (q
);
1921 if (reg_overlap_mentioned_p (src
, PATTERN (q
)))
1926 if (GET_CODE (p
) == CALL_INSN
)
1929 if (q
&& set2
&& SET_DEST (set2
) == src
&& CONSTANT_P (SET_SRC (set2
))
1930 && validate_change (insn
, &SET_SRC (set
), XEXP (note
, 0), 0))
1933 NOTE_LINE_NUMBER (q
) = NOTE_INSN_DELETED
;
1934 NOTE_SOURCE_FILE (q
) = 0;
1935 REG_N_SETS (REGNO (src
))--;
1936 REG_N_CALLS_CROSSED (REGNO (src
)) -= num_calls2
;
1937 REG_LIVE_LENGTH (REGNO (src
)) -= s_length2
;
1943 if ((HAVE_PRE_INCREMENT
|| HAVE_PRE_DECREMENT
)
1944 && (code
== PLUS
|| code
== MINUS
) && insn_const
1945 && try_auto_increment (p
, insn
, 0, src
, insn_const
, 1))
1947 else if ((HAVE_POST_INCREMENT
|| HAVE_POST_DECREMENT
)
1949 && try_auto_increment (p
, post_inc
, post_inc_set
, src
, newconst
, 0))
1951 /* If post_inc still prevails, try to find an
1952 insn where it can be used as a pre-in/decrement.
1953 If code is MINUS, this was already tried. */
1954 if (post_inc
&& code
== PLUS
1955 /* Check that newconst is likely to be usable
1956 in a pre-in/decrement before starting the search. */
1957 && ((HAVE_PRE_INCREMENT
&& newconst
> 0 && newconst
<= MOVE_MAX
)
1958 || (HAVE_PRE_DECREMENT
&& newconst
< 0 && newconst
>= -MOVE_MAX
))
1959 && exact_log2 (newconst
))
1963 inc_dest
= post_inc_set
? SET_DEST (post_inc_set
) : src
;
1964 for (q
= post_inc
; (q
= NEXT_INSN (q
)); )
1966 /* ??? We can't scan past the end of a basic block without updating
1967 the register lifetime info
1968 (REG_DEAD/basic_block_live_at_start). */
1969 if (perhaps_ends_bb_p (q
))
1971 else if (! INSN_P (q
))
1973 else if (src
!= inc_dest
1974 && (reg_overlap_mentioned_p (src
, PATTERN (q
))
1975 || reg_set_p (src
, q
)))
1977 else if (reg_set_p (inc_dest
, q
))
1979 else if (reg_overlap_mentioned_p (inc_dest
, PATTERN (q
)))
1981 try_auto_increment (q
, post_inc
,
1982 post_inc_set
, inc_dest
, newconst
, 1);
1988 /* Move the death note for DST to INSN if it is used
1990 if (reg_overlap_mentioned_p (dst
, PATTERN (insn
)))
1992 XEXP (dst_note
, 1) = REG_NOTES (insn
);
1993 REG_NOTES (insn
) = dst_note
;
1998 /* Move the death note for SRC from INSN to P. */
2000 remove_note (insn
, src_note
);
2001 XEXP (src_note
, 1) = REG_NOTES (p
);
2002 REG_NOTES (p
) = src_note
;
2004 REG_N_CALLS_CROSSED (REGNO (src
)) += s_num_calls
;
2007 REG_N_SETS (REGNO (src
))++;
2008 REG_N_SETS (REGNO (dst
))--;
2010 REG_N_CALLS_CROSSED (REGNO (dst
)) -= num_calls
;
2012 REG_LIVE_LENGTH (REGNO (src
)) += s_length
;
2013 if (REG_LIVE_LENGTH (REGNO (dst
)) >= 0)
2015 REG_LIVE_LENGTH (REGNO (dst
)) -= length
;
2016 /* REG_LIVE_LENGTH is only an approximation after
2017 combine if sched is not run, so make sure that we
2018 still have a reasonable value. */
2019 if (REG_LIVE_LENGTH (REGNO (dst
)) < 2)
2020 REG_LIVE_LENGTH (REGNO (dst
)) = 2;
2022 if (regmove_dump_file
)
2023 fprintf (regmove_dump_file
,
2024 "Fixed operand %d of insn %d matching operand %d.\n",
2025 operand_number
, INSN_UID (insn
), match_number
);
2030 /* return nonzero if X is stable and mentions no regsiters but for
2031 mentioning SRC or mentioning / changing DST . If in doubt, presume
2033 The rationale is that we want to check if we can move an insn easily
2034 while just paying attention to SRC and DST. A register is considered
2035 stable if it has the RTX_UNCHANGING_P bit set, but that would still
2036 leave the burden to update REG_DEAD / REG_UNUSED notes, so we don't
2037 want any registers but SRC and DST. */
2039 stable_and_no_regs_but_for_p (x
, src
, dst
)
2042 RTX_CODE code
= GET_CODE (x
);
2043 switch (GET_RTX_CLASS (code
))
2045 case '<': case '1': case 'c': case '2': case 'b': case '3':
2048 const char *fmt
= GET_RTX_FORMAT (code
);
2049 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2051 && ! stable_and_no_regs_but_for_p (XEXP (x
, i
), src
, dst
))
2057 return x
== src
|| x
== dst
;
2058 /* If this is a MEM, look inside - there might be a register hidden in
2059 the address of an unchanging MEM. */
2061 && ! stable_and_no_regs_but_for_p (XEXP (x
, 0), src
, dst
))
2065 return ! rtx_unstable_p (x
);
2069 /* Track stack adjustments and stack memory references. Attempt to
2070 reduce the number of stack adjustments by back-propogating across
2071 the memory references.
2073 This is intended primarily for use with targets that do not define
2074 ACCUMULATE_OUTGOING_ARGS. It is of significantly more value to
2075 targets that define PREFERRED_STACK_BOUNDARY more aligned than
2076 STACK_BOUNDARY (e.g. x86), or if not all registers can be pushed
2077 (e.g. x86 fp regs) which would ordinarily have to be implemented
2078 as a sub/mov pair due to restrictions in calls.c.
2080 Propogation stops when any of the insns that need adjusting are
2081 (a) no longer valid because we've exceeded their range, (b) a
2082 non-trivial push instruction, or (c) a call instruction.
2084 Restriction B is based on the assumption that push instructions
2085 are smaller or faster. If a port really wants to remove all
2086 pushes, it should have defined ACCUMULATE_OUTGOING_ARGS. The
2087 one exception that is made is for an add immediately followed
2090 /* This structure records stack memory references between stack adjusting
2095 HOST_WIDE_INT sp_offset
;
2097 struct csa_memlist
*next
;
2100 static int stack_memref_p
PARAMS ((rtx
));
2101 static rtx single_set_for_csa
PARAMS ((rtx
));
2102 static void free_csa_memlist
PARAMS ((struct csa_memlist
*));
2103 static struct csa_memlist
*record_one_stack_memref
2104 PARAMS ((rtx
, rtx
*, struct csa_memlist
*));
2105 static int try_apply_stack_adjustment
2106 PARAMS ((rtx
, struct csa_memlist
*, HOST_WIDE_INT
, HOST_WIDE_INT
));
2107 static void combine_stack_adjustments_for_block
PARAMS ((basic_block
));
2108 static int record_stack_memrefs
PARAMS ((rtx
*, void *));
2111 /* Main entry point for stack adjustment combination. */
2114 combine_stack_adjustments ()
2118 for (i
= 0; i
< n_basic_blocks
; ++i
)
2119 combine_stack_adjustments_for_block (BASIC_BLOCK (i
));
2122 /* Recognize a MEM of the form (sp) or (plus sp const). */
2128 if (GET_CODE (x
) != MEM
)
2132 if (x
== stack_pointer_rtx
)
2134 if (GET_CODE (x
) == PLUS
2135 && XEXP (x
, 0) == stack_pointer_rtx
2136 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
2142 /* Recognize either normal single_set or the hack in i386.md for
2143 tying fp and sp adjustments. */
2146 single_set_for_csa (insn
)
2150 rtx tmp
= single_set (insn
);
2154 if (GET_CODE (insn
) != INSN
2155 || GET_CODE (PATTERN (insn
)) != PARALLEL
)
2158 tmp
= PATTERN (insn
);
2159 if (GET_CODE (XVECEXP (tmp
, 0, 0)) != SET
)
2162 for (i
= 1; i
< XVECLEN (tmp
, 0); ++i
)
2164 rtx
this = XVECEXP (tmp
, 0, i
);
2166 /* The special case is allowing a no-op set. */
2167 if (GET_CODE (this) == SET
2168 && SET_SRC (this) == SET_DEST (this))
2170 else if (GET_CODE (this) != CLOBBER
2171 && GET_CODE (this) != USE
)
2175 return XVECEXP (tmp
, 0, 0);
2178 /* Free the list of csa_memlist nodes. */
2181 free_csa_memlist (memlist
)
2182 struct csa_memlist
*memlist
;
2184 struct csa_memlist
*next
;
2185 for (; memlist
; memlist
= next
)
2187 next
= memlist
->next
;
2192 /* Create a new csa_memlist node from the given memory reference.
2193 It is already known that the memory is stack_memref_p. */
2195 static struct csa_memlist
*
2196 record_one_stack_memref (insn
, mem
, next_memlist
)
2198 struct csa_memlist
*next_memlist
;
2200 struct csa_memlist
*ml
;
2202 ml
= (struct csa_memlist
*) xmalloc (sizeof (*ml
));
2204 if (XEXP (*mem
, 0) == stack_pointer_rtx
)
2207 ml
->sp_offset
= INTVAL (XEXP (XEXP (*mem
, 0), 1));
2211 ml
->next
= next_memlist
;
2216 /* Attempt to apply ADJUST to the stack adjusting insn INSN, as well
2217 as each of the memories in MEMLIST. Return true on success. */
2220 try_apply_stack_adjustment (insn
, memlist
, new_adjust
, delta
)
2222 struct csa_memlist
*memlist
;
2223 HOST_WIDE_INT new_adjust
, delta
;
2225 struct csa_memlist
*ml
;
2228 /* We know INSN matches single_set_for_csa, because that's what we
2229 recognized earlier. However, if INSN is not single_set, it is
2230 doing double duty as a barrier for frame pointer memory accesses,
2231 which we are not recording. Therefore, an adjust insn that is not
2232 single_set may not have a positive delta applied. */
2234 if (delta
> 0 && ! single_set (insn
))
2236 set
= single_set_for_csa (insn
);
2237 validate_change (insn
, &XEXP (SET_SRC (set
), 1), GEN_INT (new_adjust
), 1);
2239 for (ml
= memlist
; ml
; ml
= ml
->next
)
2241 HOST_WIDE_INT c
= ml
->sp_offset
- delta
;
2242 rtx
new = gen_rtx_MEM (GET_MODE (*ml
->mem
),
2243 plus_constant (stack_pointer_rtx
, c
));
2245 /* Don't reference memory below the stack pointer. */
2252 MEM_COPY_ATTRIBUTES (new, *ml
->mem
);
2253 validate_change (ml
->insn
, ml
->mem
, new, 1);
2256 if (apply_change_group ())
2258 /* Succeeded. Update our knowledge of the memory references. */
2259 for (ml
= memlist
; ml
; ml
= ml
->next
)
2260 ml
->sp_offset
-= delta
;
2268 /* Called via for_each_rtx and used to record all stack memory references in
2269 the insn and discard all other stack pointer references. */
2270 struct record_stack_memrefs_data
2273 struct csa_memlist
*memlist
;
2277 record_stack_memrefs (xp
, data
)
2282 struct record_stack_memrefs_data
*d
=
2283 (struct record_stack_memrefs_data
*) data
;
2286 switch (GET_CODE (x
))
2289 if (!reg_mentioned_p (stack_pointer_rtx
, x
))
2291 /* We are not able to handle correctly all possible memrefs containing
2292 stack pointer, so this check is neccesary. */
2293 if (stack_memref_p (x
))
2295 d
->memlist
= record_one_stack_memref (d
->insn
, xp
, d
->memlist
);
2300 /* ??? We want be able to handle non-memory stack pointer references
2301 later. For now just discard all insns refering to stack pointer
2302 outside mem expressions. We would probably want to teach
2303 validate_replace to simplify expressions first. */
2304 if (x
== stack_pointer_rtx
)
2313 /* Subroutine of combine_stack_adjustments, called for each basic block. */
2316 combine_stack_adjustments_for_block (bb
)
2319 HOST_WIDE_INT last_sp_adjust
= 0;
2320 rtx last_sp_set
= NULL_RTX
;
2321 struct csa_memlist
*memlist
= NULL
;
2324 struct record_stack_memrefs_data data
;
2326 for (insn
= bb
->head
; ; insn
= next
)
2330 pending_delete
= NULL_RTX
;
2331 next
= NEXT_INSN (insn
);
2333 if (! INSN_P (insn
))
2336 set
= single_set_for_csa (insn
);
2339 rtx dest
= SET_DEST (set
);
2340 rtx src
= SET_SRC (set
);
2342 /* Find constant additions to the stack pointer. */
2343 if (dest
== stack_pointer_rtx
2344 && GET_CODE (src
) == PLUS
2345 && XEXP (src
, 0) == stack_pointer_rtx
2346 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
2348 HOST_WIDE_INT this_adjust
= INTVAL (XEXP (src
, 1));
2350 /* If we've not seen an adjustment previously, record
2351 it now and continue. */
2355 last_sp_adjust
= this_adjust
;
2359 /* If not all recorded memrefs can be adjusted, or the
2360 adjustment is now too large for a constant addition,
2361 we cannot merge the two stack adjustments. */
2362 if (! try_apply_stack_adjustment (last_sp_set
, memlist
,
2363 last_sp_adjust
+ this_adjust
,
2366 free_csa_memlist (memlist
);
2369 last_sp_adjust
= this_adjust
;
2374 pending_delete
= insn
;
2375 last_sp_adjust
+= this_adjust
;
2377 /* If, by some accident, the adjustments cancel out,
2378 delete both insns and start from scratch. */
2379 if (last_sp_adjust
== 0)
2381 if (last_sp_set
== bb
->head
)
2382 bb
->head
= NEXT_INSN (last_sp_set
);
2383 flow_delete_insn (last_sp_set
);
2385 free_csa_memlist (memlist
);
2387 last_sp_set
= NULL_RTX
;
2393 /* Find a predecrement of exactly the previous adjustment and
2394 turn it into a direct store. Obviously we can't do this if
2395 there were any intervening uses of the stack pointer. */
2397 && GET_CODE (dest
) == MEM
2398 && ((GET_CODE (XEXP (dest
, 0)) == PRE_DEC
2400 == (HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (dest
))))
2401 || (GET_CODE (XEXP (dest
, 0)) == PRE_MODIFY
2402 && GET_CODE (XEXP (XEXP (dest
, 0), 1)) == PLUS
2403 && XEXP (XEXP (XEXP (dest
, 0), 1), 0) == stack_pointer_rtx
2404 && (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
2406 && (INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
2407 == -last_sp_adjust
)))
2408 && XEXP (XEXP (dest
, 0), 0) == stack_pointer_rtx
2409 && ! reg_mentioned_p (stack_pointer_rtx
, src
)
2410 && memory_address_p (GET_MODE (dest
), stack_pointer_rtx
)
2411 && validate_change (insn
, &SET_DEST (set
),
2412 change_address (dest
, VOIDmode
,
2413 stack_pointer_rtx
), 0))
2415 if (last_sp_set
== bb
->head
)
2416 bb
->head
= NEXT_INSN (last_sp_set
);
2417 flow_delete_insn (last_sp_set
);
2419 free_csa_memlist (memlist
);
2421 last_sp_set
= NULL_RTX
;
2428 data
.memlist
= memlist
;
2429 if (GET_CODE (insn
) != CALL_INSN
&& last_sp_set
2430 && !for_each_rtx (&PATTERN (insn
), record_stack_memrefs
, &data
))
2432 memlist
= data
.memlist
;
2435 memlist
= data
.memlist
;
2437 /* Otherwise, we were not able to process the instruction.
2438 Do not continue collecting data across such a one. */
2440 && (GET_CODE (insn
) == CALL_INSN
2441 || reg_mentioned_p (stack_pointer_rtx
, PATTERN (insn
))))
2443 free_csa_memlist (memlist
);
2445 last_sp_set
= NULL_RTX
;
2450 if (insn
== bb
->end
)
2454 flow_delete_insn (pending_delete
);
2459 bb
->end
= PREV_INSN (pending_delete
);
2460 flow_delete_insn (pending_delete
);