1 /* Optimize jump instructions, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This is the pathetic reminder of old fame of the jump-optimization pass
23 of the compiler. Now it contains basically set of utility function to
26 Each CODE_LABEL has a count of the times it is used
27 stored in the LABEL_NUSES internal field, and each JUMP_INSN
28 has one label that it refers to stored in the
29 JUMP_LABEL internal field. With this we can detect labels that
30 become unused because of the deletion of all the jumps that
31 formerly used them. The JUMP_LABEL info is sometimes looked
34 The subroutines redirect_jump and invert_jump are used
35 from other passes as well. */
39 #include "coretypes.h"
44 #include "hard-reg-set.h"
46 #include "insn-config.h"
47 #include "insn-attr.h"
53 #include "diagnostic.h"
59 /* Optimize jump y; x: ... y: jumpif... x?
60 Don't know if it is worth bothering with. */
61 /* Optimize two cases of conditional jump to conditional jump?
62 This can never delete any instruction or make anything dead,
63 or even change what is live at any point.
64 So perhaps let combiner do it. */
66 static void init_label_info (rtx
);
67 static void mark_all_labels (rtx
);
68 static void delete_computation (rtx
);
69 static void redirect_exp_1 (rtx
*, rtx
, rtx
, rtx
);
70 static int redirect_exp (rtx
, rtx
, rtx
);
71 static void invert_exp_1 (rtx
);
72 static int invert_exp (rtx
);
73 static int returnjump_p_1 (rtx
*, void *);
74 static void delete_prior_computation (rtx
, rtx
);
76 /* Alternate entry into the jump optimizer. This entry point only rebuilds
77 the JUMP_LABEL field in jumping insns and REG_LABEL notes in non-jumping
80 rebuild_jump_labels (rtx f
)
84 timevar_push (TV_REBUILD_JUMP
);
88 /* Keep track of labels used from static data; we don't track them
89 closely enough to delete them here, so make sure their reference
90 count doesn't drop to zero. */
92 for (insn
= forced_labels
; insn
; insn
= XEXP (insn
, 1))
93 if (GET_CODE (XEXP (insn
, 0)) == CODE_LABEL
)
94 LABEL_NUSES (XEXP (insn
, 0))++;
95 timevar_pop (TV_REBUILD_JUMP
);
98 /* Some old code expects exactly one BARRIER as the NEXT_INSN of a
99 non-fallthru insn. This is not generally true, as multiple barriers
100 may have crept in, or the BARRIER may be separated from the last
101 real insn by one or more NOTEs.
103 This simple pass moves barriers and removes duplicates so that the
107 cleanup_barriers (void)
109 rtx insn
, next
, prev
;
110 for (insn
= get_insns (); insn
; insn
= next
)
112 next
= NEXT_INSN (insn
);
113 if (GET_CODE (insn
) == BARRIER
)
115 prev
= prev_nonnote_insn (insn
);
116 if (GET_CODE (prev
) == BARRIER
)
117 delete_barrier (insn
);
118 else if (prev
!= PREV_INSN (insn
))
119 reorder_insns (insn
, insn
, prev
);
125 purge_line_number_notes (rtx f
)
129 /* Delete extraneous line number notes.
130 Note that two consecutive notes for different lines are not really
131 extraneous. There should be some indication where that line belonged,
132 even if it became empty. */
134 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
135 if (GET_CODE (insn
) == NOTE
)
137 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_FUNCTION_BEG
)
138 /* Any previous line note was for the prologue; gdb wants a new
139 note after the prologue even if it is for the same line. */
140 last_note
= NULL_RTX
;
141 else if (NOTE_LINE_NUMBER (insn
) >= 0)
143 /* Delete this note if it is identical to previous note. */
145 && NOTE_SOURCE_FILE (insn
) == NOTE_SOURCE_FILE (last_note
)
146 && NOTE_LINE_NUMBER (insn
) == NOTE_LINE_NUMBER (last_note
))
148 delete_related_insns (insn
);
157 /* Initialize LABEL_NUSES and JUMP_LABEL fields. Delete any REG_LABEL
158 notes whose labels don't occur in the insn any more. Returns the
159 largest INSN_UID found. */
161 init_label_info (rtx f
)
165 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
166 if (GET_CODE (insn
) == CODE_LABEL
)
167 LABEL_NUSES (insn
) = (LABEL_PRESERVE_P (insn
) != 0);
168 else if (GET_CODE (insn
) == JUMP_INSN
)
169 JUMP_LABEL (insn
) = 0;
170 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
174 for (note
= REG_NOTES (insn
); note
; note
= next
)
176 next
= XEXP (note
, 1);
177 if (REG_NOTE_KIND (note
) == REG_LABEL
178 && ! reg_mentioned_p (XEXP (note
, 0), PATTERN (insn
)))
179 remove_note (insn
, note
);
184 /* Mark the label each jump jumps to.
185 Combine consecutive labels, and count uses of labels. */
188 mark_all_labels (rtx f
)
192 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
195 if (GET_CODE (insn
) == CALL_INSN
196 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
198 mark_all_labels (XEXP (PATTERN (insn
), 0));
199 mark_all_labels (XEXP (PATTERN (insn
), 1));
200 mark_all_labels (XEXP (PATTERN (insn
), 2));
202 /* Canonicalize the tail recursion label attached to the
203 CALL_PLACEHOLDER insn. */
204 if (XEXP (PATTERN (insn
), 3))
206 rtx label_ref
= gen_rtx_LABEL_REF (VOIDmode
,
207 XEXP (PATTERN (insn
), 3));
208 mark_jump_label (label_ref
, insn
, 0);
209 XEXP (PATTERN (insn
), 3) = XEXP (label_ref
, 0);
215 mark_jump_label (PATTERN (insn
), insn
, 0);
216 if (! INSN_DELETED_P (insn
) && GET_CODE (insn
) == JUMP_INSN
)
218 /* When we know the LABEL_REF contained in a REG used in
219 an indirect jump, we'll have a REG_LABEL note so that
220 flow can tell where it's going. */
221 if (JUMP_LABEL (insn
) == 0)
223 rtx label_note
= find_reg_note (insn
, REG_LABEL
, NULL_RTX
);
226 /* But a LABEL_REF around the REG_LABEL note, so
227 that we can canonicalize it. */
228 rtx label_ref
= gen_rtx_LABEL_REF (VOIDmode
,
229 XEXP (label_note
, 0));
231 mark_jump_label (label_ref
, insn
, 0);
232 XEXP (label_note
, 0) = XEXP (label_ref
, 0);
233 JUMP_LABEL (insn
) = XEXP (label_note
, 0);
240 /* Move all block-beg, block-end, loop-beg, loop-cont, loop-vtop, loop-end,
241 notes between START and END out before START. START and END may be such
242 notes. Returns the values of the new starting and ending insns, which
243 may be different if the original ones were such notes.
244 Return true if there were only such notes and no real instructions. */
247 squeeze_notes (rtx
* startp
, rtx
* endp
)
255 rtx past_end
= NEXT_INSN (end
);
257 for (insn
= start
; insn
!= past_end
; insn
= next
)
259 next
= NEXT_INSN (insn
);
260 if (GET_CODE (insn
) == NOTE
261 && (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
262 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
263 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
264 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
265 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_CONT
266 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_VTOP
))
272 rtx prev
= PREV_INSN (insn
);
273 PREV_INSN (insn
) = PREV_INSN (start
);
274 NEXT_INSN (insn
) = start
;
275 NEXT_INSN (PREV_INSN (insn
)) = insn
;
276 PREV_INSN (NEXT_INSN (insn
)) = insn
;
277 NEXT_INSN (prev
) = next
;
278 PREV_INSN (next
) = prev
;
285 /* There were no real instructions. */
286 if (start
== past_end
)
296 /* Return the label before INSN, or put a new label there. */
299 get_label_before (rtx insn
)
303 /* Find an existing label at this point
304 or make a new one if there is none. */
305 label
= prev_nonnote_insn (insn
);
307 if (label
== 0 || GET_CODE (label
) != CODE_LABEL
)
309 rtx prev
= PREV_INSN (insn
);
311 label
= gen_label_rtx ();
312 emit_label_after (label
, prev
);
313 LABEL_NUSES (label
) = 0;
318 /* Return the label after INSN, or put a new label there. */
321 get_label_after (rtx insn
)
325 /* Find an existing label at this point
326 or make a new one if there is none. */
327 label
= next_nonnote_insn (insn
);
329 if (label
== 0 || GET_CODE (label
) != CODE_LABEL
)
331 label
= gen_label_rtx ();
332 emit_label_after (label
, insn
);
333 LABEL_NUSES (label
) = 0;
338 /* Given a comparison (CODE ARG0 ARG1), inside an insn, INSN, return a code
339 of reversed comparison if it is possible to do so. Otherwise return UNKNOWN.
340 UNKNOWN may be returned in case we are having CC_MODE compare and we don't
341 know whether it's source is floating point or integer comparison. Machine
342 description should define REVERSIBLE_CC_MODE and REVERSE_CONDITION macros
343 to help this function avoid overhead in these cases. */
345 reversed_comparison_code_parts (enum rtx_code code
, rtx arg0
, rtx arg1
, rtx insn
)
347 enum machine_mode mode
;
349 /* If this is not actually a comparison, we can't reverse it. */
350 if (GET_RTX_CLASS (code
) != RTX_COMPARE
351 && GET_RTX_CLASS (code
) != RTX_COMM_COMPARE
)
354 mode
= GET_MODE (arg0
);
355 if (mode
== VOIDmode
)
356 mode
= GET_MODE (arg1
);
358 /* First see if machine description supplies us way to reverse the
359 comparison. Give it priority over everything else to allow
360 machine description to do tricks. */
361 if (GET_MODE_CLASS (mode
) == MODE_CC
362 && REVERSIBLE_CC_MODE (mode
))
364 #ifdef REVERSE_CONDITION
365 return REVERSE_CONDITION (code
, mode
);
367 return reverse_condition (code
);
370 /* Try a few special cases based on the comparison code. */
379 /* It is always safe to reverse EQ and NE, even for the floating
380 point. Similarly the unsigned comparisons are never used for
381 floating point so we can reverse them in the default way. */
382 return reverse_condition (code
);
387 /* In case we already see unordered comparison, we can be sure to
388 be dealing with floating point so we don't need any more tests. */
389 return reverse_condition_maybe_unordered (code
);
394 /* We don't have safe way to reverse these yet. */
400 if (GET_MODE_CLASS (mode
) == MODE_CC
|| CC0_P (arg0
))
403 /* Try to search for the comparison to determine the real mode.
404 This code is expensive, but with sane machine description it
405 will be never used, since REVERSIBLE_CC_MODE will return true
410 for (prev
= prev_nonnote_insn (insn
);
411 prev
!= 0 && GET_CODE (prev
) != CODE_LABEL
;
412 prev
= prev_nonnote_insn (prev
))
414 rtx set
= set_of (arg0
, prev
);
415 if (set
&& GET_CODE (set
) == SET
416 && rtx_equal_p (SET_DEST (set
), arg0
))
418 rtx src
= SET_SRC (set
);
420 if (GET_CODE (src
) == COMPARE
)
422 rtx comparison
= src
;
423 arg0
= XEXP (src
, 0);
424 mode
= GET_MODE (arg0
);
425 if (mode
== VOIDmode
)
426 mode
= GET_MODE (XEXP (comparison
, 1));
429 /* We can get past reg-reg moves. This may be useful for model
430 of i387 comparisons that first move flag registers around. */
437 /* If register is clobbered in some ununderstandable way,
444 /* Test for an integer condition, or a floating-point comparison
445 in which NaNs can be ignored. */
446 if (GET_CODE (arg0
) == CONST_INT
447 || (GET_MODE (arg0
) != VOIDmode
448 && GET_MODE_CLASS (mode
) != MODE_CC
449 && !HONOR_NANS (mode
)))
450 return reverse_condition (code
);
455 /* A wrapper around the previous function to take COMPARISON as rtx
456 expression. This simplifies many callers. */
458 reversed_comparison_code (rtx comparison
, rtx insn
)
460 if (!COMPARISON_P (comparison
))
462 return reversed_comparison_code_parts (GET_CODE (comparison
),
463 XEXP (comparison
, 0),
464 XEXP (comparison
, 1), insn
);
467 /* Given an rtx-code for a comparison, return the code for the negated
468 comparison. If no such code exists, return UNKNOWN.
470 WATCH OUT! reverse_condition is not safe to use on a jump that might
471 be acting on the results of an IEEE floating point comparison, because
472 of the special treatment of non-signaling nans in comparisons.
473 Use reversed_comparison_code instead. */
476 reverse_condition (enum rtx_code code
)
518 /* Similar, but we're allowed to generate unordered comparisons, which
519 makes it safe for IEEE floating-point. Of course, we have to recognize
520 that the target will support them too... */
523 reverse_condition_maybe_unordered (enum rtx_code code
)
561 /* Similar, but return the code when two operands of a comparison are swapped.
562 This IS safe for IEEE floating-point. */
565 swap_condition (enum rtx_code code
)
607 /* Given a comparison CODE, return the corresponding unsigned comparison.
608 If CODE is an equality comparison or already an unsigned comparison,
612 unsigned_condition (enum rtx_code code
)
638 /* Similarly, return the signed version of a comparison. */
641 signed_condition (enum rtx_code code
)
667 /* Return nonzero if CODE1 is more strict than CODE2, i.e., if the
668 truth of CODE1 implies the truth of CODE2. */
671 comparison_dominates_p (enum rtx_code code1
, enum rtx_code code2
)
673 /* UNKNOWN comparison codes can happen as a result of trying to revert
675 They can't match anything, so we have to reject them here. */
676 if (code1
== UNKNOWN
|| code2
== UNKNOWN
)
685 if (code2
== UNLE
|| code2
== UNGE
)
690 if (code2
== LE
|| code2
== LEU
|| code2
== GE
|| code2
== GEU
696 if (code2
== UNLE
|| code2
== NE
)
701 if (code2
== LE
|| code2
== NE
|| code2
== ORDERED
|| code2
== LTGT
)
706 if (code2
== UNGE
|| code2
== NE
)
711 if (code2
== GE
|| code2
== NE
|| code2
== ORDERED
|| code2
== LTGT
)
717 if (code2
== ORDERED
)
722 if (code2
== NE
|| code2
== ORDERED
)
727 if (code2
== LEU
|| code2
== NE
)
732 if (code2
== GEU
|| code2
== NE
)
737 if (code2
== NE
|| code2
== UNEQ
|| code2
== UNLE
|| code2
== UNLT
738 || code2
== UNGE
|| code2
== UNGT
)
749 /* Return 1 if INSN is an unconditional jump and nothing else. */
752 simplejump_p (rtx insn
)
754 return (GET_CODE (insn
) == JUMP_INSN
755 && GET_CODE (PATTERN (insn
)) == SET
756 && GET_CODE (SET_DEST (PATTERN (insn
))) == PC
757 && GET_CODE (SET_SRC (PATTERN (insn
))) == LABEL_REF
);
760 /* Return nonzero if INSN is a (possibly) conditional jump
763 Use of this function is deprecated, since we need to support combined
764 branch and compare insns. Use any_condjump_p instead whenever possible. */
767 condjump_p (rtx insn
)
769 rtx x
= PATTERN (insn
);
771 if (GET_CODE (x
) != SET
772 || GET_CODE (SET_DEST (x
)) != PC
)
776 if (GET_CODE (x
) == LABEL_REF
)
779 return (GET_CODE (x
) == IF_THEN_ELSE
780 && ((GET_CODE (XEXP (x
, 2)) == PC
781 && (GET_CODE (XEXP (x
, 1)) == LABEL_REF
782 || GET_CODE (XEXP (x
, 1)) == RETURN
))
783 || (GET_CODE (XEXP (x
, 1)) == PC
784 && (GET_CODE (XEXP (x
, 2)) == LABEL_REF
785 || GET_CODE (XEXP (x
, 2)) == RETURN
))));
790 /* Return nonzero if INSN is a (possibly) conditional jump inside a
793 Use this function is deprecated, since we need to support combined
794 branch and compare insns. Use any_condjump_p instead whenever possible. */
797 condjump_in_parallel_p (rtx insn
)
799 rtx x
= PATTERN (insn
);
801 if (GET_CODE (x
) != PARALLEL
)
804 x
= XVECEXP (x
, 0, 0);
806 if (GET_CODE (x
) != SET
)
808 if (GET_CODE (SET_DEST (x
)) != PC
)
810 if (GET_CODE (SET_SRC (x
)) == LABEL_REF
)
812 if (GET_CODE (SET_SRC (x
)) != IF_THEN_ELSE
)
814 if (XEXP (SET_SRC (x
), 2) == pc_rtx
815 && (GET_CODE (XEXP (SET_SRC (x
), 1)) == LABEL_REF
816 || GET_CODE (XEXP (SET_SRC (x
), 1)) == RETURN
))
818 if (XEXP (SET_SRC (x
), 1) == pc_rtx
819 && (GET_CODE (XEXP (SET_SRC (x
), 2)) == LABEL_REF
820 || GET_CODE (XEXP (SET_SRC (x
), 2)) == RETURN
))
825 /* Return set of PC, otherwise NULL. */
831 if (GET_CODE (insn
) != JUMP_INSN
)
833 pat
= PATTERN (insn
);
835 /* The set is allowed to appear either as the insn pattern or
836 the first set in a PARALLEL. */
837 if (GET_CODE (pat
) == PARALLEL
)
838 pat
= XVECEXP (pat
, 0, 0);
839 if (GET_CODE (pat
) == SET
&& GET_CODE (SET_DEST (pat
)) == PC
)
845 /* Return true when insn is an unconditional direct jump,
846 possibly bundled inside a PARALLEL. */
849 any_uncondjump_p (rtx insn
)
851 rtx x
= pc_set (insn
);
854 if (GET_CODE (SET_SRC (x
)) != LABEL_REF
)
856 if (find_reg_note (insn
, REG_NON_LOCAL_GOTO
, NULL_RTX
))
861 /* Return true when insn is a conditional jump. This function works for
862 instructions containing PC sets in PARALLELs. The instruction may have
863 various other effects so before removing the jump you must verify
866 Note that unlike condjump_p it returns false for unconditional jumps. */
869 any_condjump_p (rtx insn
)
871 rtx x
= pc_set (insn
);
876 if (GET_CODE (SET_SRC (x
)) != IF_THEN_ELSE
)
879 a
= GET_CODE (XEXP (SET_SRC (x
), 1));
880 b
= GET_CODE (XEXP (SET_SRC (x
), 2));
882 return ((b
== PC
&& (a
== LABEL_REF
|| a
== RETURN
))
883 || (a
== PC
&& (b
== LABEL_REF
|| b
== RETURN
)));
886 /* Return the label of a conditional jump. */
889 condjump_label (rtx insn
)
891 rtx x
= pc_set (insn
);
896 if (GET_CODE (x
) == LABEL_REF
)
898 if (GET_CODE (x
) != IF_THEN_ELSE
)
900 if (XEXP (x
, 2) == pc_rtx
&& GET_CODE (XEXP (x
, 1)) == LABEL_REF
)
902 if (XEXP (x
, 1) == pc_rtx
&& GET_CODE (XEXP (x
, 2)) == LABEL_REF
)
907 /* Return true if INSN is a (possibly conditional) return insn. */
910 returnjump_p_1 (rtx
*loc
, void *data ATTRIBUTE_UNUSED
)
914 return x
&& (GET_CODE (x
) == RETURN
915 || (GET_CODE (x
) == SET
&& SET_IS_RETURN_P (x
)));
919 returnjump_p (rtx insn
)
921 if (GET_CODE (insn
) != JUMP_INSN
)
923 return for_each_rtx (&PATTERN (insn
), returnjump_p_1
, NULL
);
926 /* Return true if INSN is a jump that only transfers control and
930 onlyjump_p (rtx insn
)
934 if (GET_CODE (insn
) != JUMP_INSN
)
937 set
= single_set (insn
);
940 if (GET_CODE (SET_DEST (set
)) != PC
)
942 if (side_effects_p (SET_SRC (set
)))
950 /* Return nonzero if X is an RTX that only sets the condition codes
951 and has no side effects. */
954 only_sets_cc0_p (rtx x
)
962 return sets_cc0_p (x
) == 1 && ! side_effects_p (x
);
965 /* Return 1 if X is an RTX that does nothing but set the condition codes
966 and CLOBBER or USE registers.
967 Return -1 if X does explicitly set the condition codes,
968 but also does other things. */
979 if (GET_CODE (x
) == SET
&& SET_DEST (x
) == cc0_rtx
)
981 if (GET_CODE (x
) == PARALLEL
)
985 int other_things
= 0;
986 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
988 if (GET_CODE (XVECEXP (x
, 0, i
)) == SET
989 && SET_DEST (XVECEXP (x
, 0, i
)) == cc0_rtx
)
991 else if (GET_CODE (XVECEXP (x
, 0, i
)) == SET
)
994 return ! sets_cc0
? 0 : other_things
? -1 : 1;
1000 /* Follow any unconditional jump at LABEL;
1001 return the ultimate label reached by any such chain of jumps.
1002 If LABEL is not followed by a jump, return LABEL.
1003 If the chain loops or we can't find end, return LABEL,
1004 since that tells caller to avoid changing the insn.
1006 If RELOAD_COMPLETED is 0, we do not chain across a NOTE_INSN_LOOP_BEG or
1007 a USE or CLOBBER. */
1010 follow_jumps (rtx label
)
1019 && (insn
= next_active_insn (value
)) != 0
1020 && GET_CODE (insn
) == JUMP_INSN
1021 && ((JUMP_LABEL (insn
) != 0 && any_uncondjump_p (insn
)
1022 && onlyjump_p (insn
))
1023 || GET_CODE (PATTERN (insn
)) == RETURN
)
1024 && (next
= NEXT_INSN (insn
))
1025 && GET_CODE (next
) == BARRIER
);
1028 /* Don't chain through the insn that jumps into a loop
1029 from outside the loop,
1030 since that would create multiple loop entry jumps
1031 and prevent loop optimization. */
1033 if (!reload_completed
)
1034 for (tem
= value
; tem
!= insn
; tem
= NEXT_INSN (tem
))
1035 if (GET_CODE (tem
) == NOTE
1036 && (NOTE_LINE_NUMBER (tem
) == NOTE_INSN_LOOP_BEG
1037 /* ??? Optional. Disables some optimizations, but makes
1038 gcov output more accurate with -O. */
1039 || (flag_test_coverage
&& NOTE_LINE_NUMBER (tem
) > 0)))
1042 /* If we have found a cycle, make the insn jump to itself. */
1043 if (JUMP_LABEL (insn
) == label
)
1046 tem
= next_active_insn (JUMP_LABEL (insn
));
1047 if (tem
&& (GET_CODE (PATTERN (tem
)) == ADDR_VEC
1048 || GET_CODE (PATTERN (tem
)) == ADDR_DIFF_VEC
))
1051 value
= JUMP_LABEL (insn
);
1059 /* Find all CODE_LABELs referred to in X, and increment their use counts.
1060 If INSN is a JUMP_INSN and there is at least one CODE_LABEL referenced
1061 in INSN, then store one of them in JUMP_LABEL (INSN).
1062 If INSN is an INSN or a CALL_INSN and there is at least one CODE_LABEL
1063 referenced in INSN, add a REG_LABEL note containing that label to INSN.
1064 Also, when there are consecutive labels, canonicalize on the last of them.
1066 Note that two labels separated by a loop-beginning note
1067 must be kept distinct if we have not yet done loop-optimization,
1068 because the gap between them is where loop-optimize
1069 will want to move invariant code to. CROSS_JUMP tells us
1070 that loop-optimization is done with. */
1073 mark_jump_label (rtx x
, rtx insn
, int in_mem
)
1075 RTX_CODE code
= GET_CODE (x
);
1098 /* If this is a constant-pool reference, see if it is a label. */
1099 if (CONSTANT_POOL_ADDRESS_P (x
))
1100 mark_jump_label (get_pool_constant (x
), insn
, in_mem
);
1105 rtx label
= XEXP (x
, 0);
1107 /* Ignore remaining references to unreachable labels that
1108 have been deleted. */
1109 if (GET_CODE (label
) == NOTE
1110 && NOTE_LINE_NUMBER (label
) == NOTE_INSN_DELETED_LABEL
)
1113 if (GET_CODE (label
) != CODE_LABEL
)
1116 /* Ignore references to labels of containing functions. */
1117 if (LABEL_REF_NONLOCAL_P (x
))
1120 XEXP (x
, 0) = label
;
1121 if (! insn
|| ! INSN_DELETED_P (insn
))
1122 ++LABEL_NUSES (label
);
1126 if (GET_CODE (insn
) == JUMP_INSN
)
1127 JUMP_LABEL (insn
) = label
;
1130 /* Add a REG_LABEL note for LABEL unless there already
1131 is one. All uses of a label, except for labels
1132 that are the targets of jumps, must have a
1134 if (! find_reg_note (insn
, REG_LABEL
, label
))
1135 REG_NOTES (insn
) = gen_rtx_INSN_LIST (REG_LABEL
, label
,
1142 /* Do walk the labels in a vector, but not the first operand of an
1143 ADDR_DIFF_VEC. Don't set the JUMP_LABEL of a vector. */
1146 if (! INSN_DELETED_P (insn
))
1148 int eltnum
= code
== ADDR_DIFF_VEC
? 1 : 0;
1150 for (i
= 0; i
< XVECLEN (x
, eltnum
); i
++)
1151 mark_jump_label (XVECEXP (x
, eltnum
, i
), NULL_RTX
, in_mem
);
1159 fmt
= GET_RTX_FORMAT (code
);
1160 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1163 mark_jump_label (XEXP (x
, i
), insn
, in_mem
);
1164 else if (fmt
[i
] == 'E')
1167 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1168 mark_jump_label (XVECEXP (x
, i
, j
), insn
, in_mem
);
1173 /* If all INSN does is set the pc, delete it,
1174 and delete the insn that set the condition codes for it
1175 if that's what the previous thing was. */
1178 delete_jump (rtx insn
)
1180 rtx set
= single_set (insn
);
1182 if (set
&& GET_CODE (SET_DEST (set
)) == PC
)
1183 delete_computation (insn
);
1186 /* Verify INSN is a BARRIER and delete it. */
1189 delete_barrier (rtx insn
)
1191 if (GET_CODE (insn
) != BARRIER
)
1197 /* Recursively delete prior insns that compute the value (used only by INSN
1198 which the caller is deleting) stored in the register mentioned by NOTE
1199 which is a REG_DEAD note associated with INSN. */
1202 delete_prior_computation (rtx note
, rtx insn
)
1205 rtx reg
= XEXP (note
, 0);
1207 for (our_prev
= prev_nonnote_insn (insn
);
1208 our_prev
&& (GET_CODE (our_prev
) == INSN
1209 || GET_CODE (our_prev
) == CALL_INSN
);
1210 our_prev
= prev_nonnote_insn (our_prev
))
1212 rtx pat
= PATTERN (our_prev
);
1214 /* If we reach a CALL which is not calling a const function
1215 or the callee pops the arguments, then give up. */
1216 if (GET_CODE (our_prev
) == CALL_INSN
1217 && (! CONST_OR_PURE_CALL_P (our_prev
)
1218 || GET_CODE (pat
) != SET
|| GET_CODE (SET_SRC (pat
)) != CALL
))
1221 /* If we reach a SEQUENCE, it is too complex to try to
1222 do anything with it, so give up. We can be run during
1223 and after reorg, so SEQUENCE rtl can legitimately show
1225 if (GET_CODE (pat
) == SEQUENCE
)
1228 if (GET_CODE (pat
) == USE
1229 && GET_CODE (XEXP (pat
, 0)) == INSN
)
1230 /* reorg creates USEs that look like this. We leave them
1231 alone because reorg needs them for its own purposes. */
1234 if (reg_set_p (reg
, pat
))
1236 if (side_effects_p (pat
) && GET_CODE (our_prev
) != CALL_INSN
)
1239 if (GET_CODE (pat
) == PARALLEL
)
1241 /* If we find a SET of something else, we can't
1246 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
1248 rtx part
= XVECEXP (pat
, 0, i
);
1250 if (GET_CODE (part
) == SET
1251 && SET_DEST (part
) != reg
)
1255 if (i
== XVECLEN (pat
, 0))
1256 delete_computation (our_prev
);
1258 else if (GET_CODE (pat
) == SET
1259 && GET_CODE (SET_DEST (pat
)) == REG
)
1261 int dest_regno
= REGNO (SET_DEST (pat
));
1264 + (dest_regno
< FIRST_PSEUDO_REGISTER
1265 ? hard_regno_nregs
[dest_regno
]
1266 [GET_MODE (SET_DEST (pat
))] : 1));
1267 int regno
= REGNO (reg
);
1270 + (regno
< FIRST_PSEUDO_REGISTER
1271 ? hard_regno_nregs
[regno
][GET_MODE (reg
)] : 1));
1273 if (dest_regno
>= regno
1274 && dest_endregno
<= endregno
)
1275 delete_computation (our_prev
);
1277 /* We may have a multi-word hard register and some, but not
1278 all, of the words of the register are needed in subsequent
1279 insns. Write REG_UNUSED notes for those parts that were not
1281 else if (dest_regno
<= regno
1282 && dest_endregno
>= endregno
)
1286 REG_NOTES (our_prev
)
1287 = gen_rtx_EXPR_LIST (REG_UNUSED
, reg
,
1288 REG_NOTES (our_prev
));
1290 for (i
= dest_regno
; i
< dest_endregno
; i
++)
1291 if (! find_regno_note (our_prev
, REG_UNUSED
, i
))
1294 if (i
== dest_endregno
)
1295 delete_computation (our_prev
);
1302 /* If PAT references the register that dies here, it is an
1303 additional use. Hence any prior SET isn't dead. However, this
1304 insn becomes the new place for the REG_DEAD note. */
1305 if (reg_overlap_mentioned_p (reg
, pat
))
1307 XEXP (note
, 1) = REG_NOTES (our_prev
);
1308 REG_NOTES (our_prev
) = note
;
1314 /* Delete INSN and recursively delete insns that compute values used only
1315 by INSN. This uses the REG_DEAD notes computed during flow analysis.
1316 If we are running before flow.c, we need do nothing since flow.c will
1317 delete dead code. We also can't know if the registers being used are
1318 dead or not at this point.
1320 Otherwise, look at all our REG_DEAD notes. If a previous insn does
1321 nothing other than set a register that dies in this insn, we can delete
1324 On machines with CC0, if CC0 is used in this insn, we may be able to
1325 delete the insn that set it. */
1328 delete_computation (rtx insn
)
1333 if (reg_referenced_p (cc0_rtx
, PATTERN (insn
)))
1335 rtx prev
= prev_nonnote_insn (insn
);
1336 /* We assume that at this stage
1337 CC's are always set explicitly
1338 and always immediately before the jump that
1339 will use them. So if the previous insn
1340 exists to set the CC's, delete it
1341 (unless it performs auto-increments, etc.). */
1342 if (prev
&& GET_CODE (prev
) == INSN
1343 && sets_cc0_p (PATTERN (prev
)))
1345 if (sets_cc0_p (PATTERN (prev
)) > 0
1346 && ! side_effects_p (PATTERN (prev
)))
1347 delete_computation (prev
);
1349 /* Otherwise, show that cc0 won't be used. */
1350 REG_NOTES (prev
) = gen_rtx_EXPR_LIST (REG_UNUSED
,
1351 cc0_rtx
, REG_NOTES (prev
));
1356 for (note
= REG_NOTES (insn
); note
; note
= next
)
1358 next
= XEXP (note
, 1);
1360 if (REG_NOTE_KIND (note
) != REG_DEAD
1361 /* Verify that the REG_NOTE is legitimate. */
1362 || GET_CODE (XEXP (note
, 0)) != REG
)
1365 delete_prior_computation (note
, insn
);
1368 delete_related_insns (insn
);
1371 /* Delete insn INSN from the chain of insns and update label ref counts
1372 and delete insns now unreachable.
1374 Returns the first insn after INSN that was not deleted.
1376 Usage of this instruction is deprecated. Use delete_insn instead and
1377 subsequent cfg_cleanup pass to delete unreachable code if needed. */
1380 delete_related_insns (rtx insn
)
1382 int was_code_label
= (GET_CODE (insn
) == CODE_LABEL
);
1384 rtx next
= NEXT_INSN (insn
), prev
= PREV_INSN (insn
);
1386 while (next
&& INSN_DELETED_P (next
))
1387 next
= NEXT_INSN (next
);
1389 /* This insn is already deleted => return first following nondeleted. */
1390 if (INSN_DELETED_P (insn
))
1395 /* If instruction is followed by a barrier,
1396 delete the barrier too. */
1398 if (next
!= 0 && GET_CODE (next
) == BARRIER
)
1401 /* If deleting a jump, decrement the count of the label,
1402 and delete the label if it is now unused. */
1404 if (GET_CODE (insn
) == JUMP_INSN
&& JUMP_LABEL (insn
))
1406 rtx lab
= JUMP_LABEL (insn
), lab_next
;
1408 if (LABEL_NUSES (lab
) == 0)
1410 /* This can delete NEXT or PREV,
1411 either directly if NEXT is JUMP_LABEL (INSN),
1412 or indirectly through more levels of jumps. */
1413 delete_related_insns (lab
);
1415 /* I feel a little doubtful about this loop,
1416 but I see no clean and sure alternative way
1417 to find the first insn after INSN that is not now deleted.
1418 I hope this works. */
1419 while (next
&& INSN_DELETED_P (next
))
1420 next
= NEXT_INSN (next
);
1423 else if (tablejump_p (insn
, NULL
, &lab_next
))
1425 /* If we're deleting the tablejump, delete the dispatch table.
1426 We may not be able to kill the label immediately preceding
1427 just yet, as it might be referenced in code leading up to
1429 delete_related_insns (lab_next
);
1433 /* Likewise if we're deleting a dispatch table. */
1435 if (GET_CODE (insn
) == JUMP_INSN
1436 && (GET_CODE (PATTERN (insn
)) == ADDR_VEC
1437 || GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
))
1439 rtx pat
= PATTERN (insn
);
1440 int i
, diff_vec_p
= GET_CODE (pat
) == ADDR_DIFF_VEC
;
1441 int len
= XVECLEN (pat
, diff_vec_p
);
1443 for (i
= 0; i
< len
; i
++)
1444 if (LABEL_NUSES (XEXP (XVECEXP (pat
, diff_vec_p
, i
), 0)) == 0)
1445 delete_related_insns (XEXP (XVECEXP (pat
, diff_vec_p
, i
), 0));
1446 while (next
&& INSN_DELETED_P (next
))
1447 next
= NEXT_INSN (next
);
1451 /* Likewise for an ordinary INSN / CALL_INSN with a REG_LABEL note. */
1452 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
1453 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
1454 if (REG_NOTE_KIND (note
) == REG_LABEL
1455 /* This could also be a NOTE_INSN_DELETED_LABEL note. */
1456 && GET_CODE (XEXP (note
, 0)) == CODE_LABEL
)
1457 if (LABEL_NUSES (XEXP (note
, 0)) == 0)
1458 delete_related_insns (XEXP (note
, 0));
1460 while (prev
&& (INSN_DELETED_P (prev
) || GET_CODE (prev
) == NOTE
))
1461 prev
= PREV_INSN (prev
);
1463 /* If INSN was a label and a dispatch table follows it,
1464 delete the dispatch table. The tablejump must have gone already.
1465 It isn't useful to fall through into a table. */
1468 && NEXT_INSN (insn
) != 0
1469 && GET_CODE (NEXT_INSN (insn
)) == JUMP_INSN
1470 && (GET_CODE (PATTERN (NEXT_INSN (insn
))) == ADDR_VEC
1471 || GET_CODE (PATTERN (NEXT_INSN (insn
))) == ADDR_DIFF_VEC
))
1472 next
= delete_related_insns (NEXT_INSN (insn
));
1474 /* If INSN was a label, delete insns following it if now unreachable. */
1476 if (was_code_label
&& prev
&& GET_CODE (prev
) == BARRIER
)
1481 code
= GET_CODE (next
);
1483 && NOTE_LINE_NUMBER (next
) != NOTE_INSN_FUNCTION_END
)
1484 next
= NEXT_INSN (next
);
1485 /* Keep going past other deleted labels to delete what follows. */
1486 else if (code
== CODE_LABEL
&& INSN_DELETED_P (next
))
1487 next
= NEXT_INSN (next
);
1488 else if (code
== BARRIER
|| INSN_P (next
))
1489 /* Note: if this deletes a jump, it can cause more
1490 deletion of unreachable code, after a different label.
1491 As long as the value from this recursive call is correct,
1492 this invocation functions correctly. */
1493 next
= delete_related_insns (next
);
1502 /* Delete a range of insns from FROM to TO, inclusive.
1503 This is for the sake of peephole optimization, so assume
1504 that whatever these insns do will still be done by a new
1505 peephole insn that will replace them. */
1508 delete_for_peephole (rtx from
, rtx to
)
1514 rtx next
= NEXT_INSN (insn
);
1515 rtx prev
= PREV_INSN (insn
);
1517 if (GET_CODE (insn
) != NOTE
)
1519 INSN_DELETED_P (insn
) = 1;
1521 /* Patch this insn out of the chain. */
1522 /* We don't do this all at once, because we
1523 must preserve all NOTEs. */
1525 NEXT_INSN (prev
) = next
;
1528 PREV_INSN (next
) = prev
;
1536 /* Note that if TO is an unconditional jump
1537 we *do not* delete the BARRIER that follows,
1538 since the peephole that replaces this sequence
1539 is also an unconditional jump in that case. */
1542 /* Throughout LOC, redirect OLABEL to NLABEL. Treat null OLABEL or
1543 NLABEL as a return. Accrue modifications into the change group. */
1546 redirect_exp_1 (rtx
*loc
, rtx olabel
, rtx nlabel
, rtx insn
)
1549 RTX_CODE code
= GET_CODE (x
);
1553 if (code
== LABEL_REF
)
1555 if (XEXP (x
, 0) == olabel
)
1559 n
= gen_rtx_LABEL_REF (VOIDmode
, nlabel
);
1561 n
= gen_rtx_RETURN (VOIDmode
);
1563 validate_change (insn
, loc
, n
, 1);
1567 else if (code
== RETURN
&& olabel
== 0)
1569 x
= gen_rtx_LABEL_REF (VOIDmode
, nlabel
);
1570 if (loc
== &PATTERN (insn
))
1571 x
= gen_rtx_SET (VOIDmode
, pc_rtx
, x
);
1572 validate_change (insn
, loc
, x
, 1);
1576 if (code
== SET
&& nlabel
== 0 && SET_DEST (x
) == pc_rtx
1577 && GET_CODE (SET_SRC (x
)) == LABEL_REF
1578 && XEXP (SET_SRC (x
), 0) == olabel
)
1580 validate_change (insn
, loc
, gen_rtx_RETURN (VOIDmode
), 1);
1584 fmt
= GET_RTX_FORMAT (code
);
1585 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1588 redirect_exp_1 (&XEXP (x
, i
), olabel
, nlabel
, insn
);
1589 else if (fmt
[i
] == 'E')
1592 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1593 redirect_exp_1 (&XVECEXP (x
, i
, j
), olabel
, nlabel
, insn
);
1598 /* Similar, but apply the change group and report success or failure. */
1601 redirect_exp (rtx olabel
, rtx nlabel
, rtx insn
)
1605 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
1606 loc
= &XVECEXP (PATTERN (insn
), 0, 0);
1608 loc
= &PATTERN (insn
);
1610 redirect_exp_1 (loc
, olabel
, nlabel
, insn
);
1611 if (num_validated_changes () == 0)
1614 return apply_change_group ();
1617 /* Make JUMP go to NLABEL instead of where it jumps now. Accrue
1618 the modifications into the change group. Return false if we did
1619 not see how to do that. */
1622 redirect_jump_1 (rtx jump
, rtx nlabel
)
1624 int ochanges
= num_validated_changes ();
1627 if (GET_CODE (PATTERN (jump
)) == PARALLEL
)
1628 loc
= &XVECEXP (PATTERN (jump
), 0, 0);
1630 loc
= &PATTERN (jump
);
1632 redirect_exp_1 (loc
, JUMP_LABEL (jump
), nlabel
, jump
);
1633 return num_validated_changes () > ochanges
;
1636 /* Make JUMP go to NLABEL instead of where it jumps now. If the old
1637 jump target label is unused as a result, it and the code following
1640 If NLABEL is zero, we are to turn the jump into a (possibly conditional)
1643 The return value will be 1 if the change was made, 0 if it wasn't
1644 (this can only occur for NLABEL == 0). */
1647 redirect_jump (rtx jump
, rtx nlabel
, int delete_unused
)
1649 rtx olabel
= JUMP_LABEL (jump
);
1652 if (nlabel
== olabel
)
1655 if (! redirect_exp (olabel
, nlabel
, jump
))
1658 JUMP_LABEL (jump
) = nlabel
;
1660 ++LABEL_NUSES (nlabel
);
1662 /* Update labels in any REG_EQUAL note. */
1663 if ((note
= find_reg_note (jump
, REG_EQUAL
, NULL_RTX
)) != NULL_RTX
)
1665 if (nlabel
&& olabel
)
1667 rtx dest
= XEXP (note
, 0);
1669 if (GET_CODE (dest
) == IF_THEN_ELSE
)
1671 if (GET_CODE (XEXP (dest
, 1)) == LABEL_REF
1672 && XEXP (XEXP (dest
, 1), 0) == olabel
)
1673 XEXP (XEXP (dest
, 1), 0) = nlabel
;
1674 if (GET_CODE (XEXP (dest
, 2)) == LABEL_REF
1675 && XEXP (XEXP (dest
, 2), 0) == olabel
)
1676 XEXP (XEXP (dest
, 2), 0) = nlabel
;
1679 remove_note (jump
, note
);
1682 remove_note (jump
, note
);
1685 /* If we're eliding the jump over exception cleanups at the end of a
1686 function, move the function end note so that -Wreturn-type works. */
1687 if (olabel
&& nlabel
1688 && NEXT_INSN (olabel
)
1689 && GET_CODE (NEXT_INSN (olabel
)) == NOTE
1690 && NOTE_LINE_NUMBER (NEXT_INSN (olabel
)) == NOTE_INSN_FUNCTION_END
)
1691 emit_note_after (NOTE_INSN_FUNCTION_END
, nlabel
);
1693 if (olabel
&& --LABEL_NUSES (olabel
) == 0 && delete_unused
1694 /* Undefined labels will remain outside the insn stream. */
1695 && INSN_UID (olabel
))
1696 delete_related_insns (olabel
);
1701 /* Invert the jump condition of rtx X contained in jump insn, INSN.
1702 Accrue the modifications into the change group. */
1705 invert_exp_1 (rtx insn
)
1708 rtx x
= pc_set (insn
);
1714 code
= GET_CODE (x
);
1716 if (code
== IF_THEN_ELSE
)
1718 rtx comp
= XEXP (x
, 0);
1720 enum rtx_code reversed_code
;
1722 /* We can do this in two ways: The preferable way, which can only
1723 be done if this is not an integer comparison, is to reverse
1724 the comparison code. Otherwise, swap the THEN-part and ELSE-part
1725 of the IF_THEN_ELSE. If we can't do either, fail. */
1727 reversed_code
= reversed_comparison_code (comp
, insn
);
1729 if (reversed_code
!= UNKNOWN
)
1731 validate_change (insn
, &XEXP (x
, 0),
1732 gen_rtx_fmt_ee (reversed_code
,
1733 GET_MODE (comp
), XEXP (comp
, 0),
1740 validate_change (insn
, &XEXP (x
, 1), XEXP (x
, 2), 1);
1741 validate_change (insn
, &XEXP (x
, 2), tem
, 1);
1747 /* Invert the jump condition of conditional jump insn, INSN.
1749 Return 1 if we can do so, 0 if we cannot find a way to do so that
1750 matches a pattern. */
1753 invert_exp (rtx insn
)
1755 invert_exp_1 (insn
);
1756 if (num_validated_changes () == 0)
1759 return apply_change_group ();
1762 /* Invert the condition of the jump JUMP, and make it jump to label
1763 NLABEL instead of where it jumps now. Accrue changes into the
1764 change group. Return false if we didn't see how to perform the
1765 inversion and redirection. */
1768 invert_jump_1 (rtx jump
, rtx nlabel
)
1772 ochanges
= num_validated_changes ();
1773 invert_exp_1 (jump
);
1774 if (num_validated_changes () == ochanges
)
1777 return redirect_jump_1 (jump
, nlabel
);
1780 /* Invert the condition of the jump JUMP, and make it jump to label
1781 NLABEL instead of where it jumps now. Return true if successful. */
1784 invert_jump (rtx jump
, rtx nlabel
, int delete_unused
)
1786 /* We have to either invert the condition and change the label or
1787 do neither. Either operation could fail. We first try to invert
1788 the jump. If that succeeds, we try changing the label. If that fails,
1789 we invert the jump back to what it was. */
1791 if (! invert_exp (jump
))
1794 if (redirect_jump (jump
, nlabel
, delete_unused
))
1796 /* Remove REG_EQUAL note if we have one. */
1797 rtx note
= find_reg_note (jump
, REG_EQUAL
, NULL_RTX
);
1799 remove_note (jump
, note
);
1801 invert_br_probabilities (jump
);
1806 if (! invert_exp (jump
))
1807 /* This should just be putting it back the way it was. */
1814 /* Like rtx_equal_p except that it considers two REGs as equal
1815 if they renumber to the same value and considers two commutative
1816 operations to be the same if the order of the operands has been
1819 ??? Addition is not commutative on the PA due to the weird implicit
1820 space register selection rules for memory addresses. Therefore, we
1821 don't consider a + b == b + a.
1823 We could/should make this test a little tighter. Possibly only
1824 disabling it on the PA via some backend macro or only disabling this
1825 case when the PLUS is inside a MEM. */
1828 rtx_renumbered_equal_p (rtx x
, rtx y
)
1831 enum rtx_code code
= GET_CODE (x
);
1837 if ((code
== REG
|| (code
== SUBREG
&& GET_CODE (SUBREG_REG (x
)) == REG
))
1838 && (GET_CODE (y
) == REG
|| (GET_CODE (y
) == SUBREG
1839 && GET_CODE (SUBREG_REG (y
)) == REG
)))
1841 int reg_x
= -1, reg_y
= -1;
1842 int byte_x
= 0, byte_y
= 0;
1844 if (GET_MODE (x
) != GET_MODE (y
))
1847 /* If we haven't done any renumbering, don't
1848 make any assumptions. */
1849 if (reg_renumber
== 0)
1850 return rtx_equal_p (x
, y
);
1854 reg_x
= REGNO (SUBREG_REG (x
));
1855 byte_x
= SUBREG_BYTE (x
);
1857 if (reg_renumber
[reg_x
] >= 0)
1859 reg_x
= subreg_regno_offset (reg_renumber
[reg_x
],
1860 GET_MODE (SUBREG_REG (x
)),
1869 if (reg_renumber
[reg_x
] >= 0)
1870 reg_x
= reg_renumber
[reg_x
];
1873 if (GET_CODE (y
) == SUBREG
)
1875 reg_y
= REGNO (SUBREG_REG (y
));
1876 byte_y
= SUBREG_BYTE (y
);
1878 if (reg_renumber
[reg_y
] >= 0)
1880 reg_y
= subreg_regno_offset (reg_renumber
[reg_y
],
1881 GET_MODE (SUBREG_REG (y
)),
1890 if (reg_renumber
[reg_y
] >= 0)
1891 reg_y
= reg_renumber
[reg_y
];
1894 return reg_x
>= 0 && reg_x
== reg_y
&& byte_x
== byte_y
;
1897 /* Now we have disposed of all the cases
1898 in which different rtx codes can match. */
1899 if (code
!= GET_CODE (y
))
1912 /* We can't assume nonlocal labels have their following insns yet. */
1913 if (LABEL_REF_NONLOCAL_P (x
) || LABEL_REF_NONLOCAL_P (y
))
1914 return XEXP (x
, 0) == XEXP (y
, 0);
1916 /* Two label-refs are equivalent if they point at labels
1917 in the same position in the instruction stream. */
1918 return (next_real_insn (XEXP (x
, 0))
1919 == next_real_insn (XEXP (y
, 0)));
1922 return XSTR (x
, 0) == XSTR (y
, 0);
1925 /* If we didn't match EQ equality above, they aren't the same. */
1932 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
1934 if (GET_MODE (x
) != GET_MODE (y
))
1937 /* For commutative operations, the RTX match if the operand match in any
1938 order. Also handle the simple binary and unary cases without a loop.
1940 ??? Don't consider PLUS a commutative operator; see comments above. */
1941 if (COMMUTATIVE_P (x
) && code
!= PLUS
)
1942 return ((rtx_renumbered_equal_p (XEXP (x
, 0), XEXP (y
, 0))
1943 && rtx_renumbered_equal_p (XEXP (x
, 1), XEXP (y
, 1)))
1944 || (rtx_renumbered_equal_p (XEXP (x
, 0), XEXP (y
, 1))
1945 && rtx_renumbered_equal_p (XEXP (x
, 1), XEXP (y
, 0))));
1946 else if (NON_COMMUTATIVE_P (x
))
1947 return (rtx_renumbered_equal_p (XEXP (x
, 0), XEXP (y
, 0))
1948 && rtx_renumbered_equal_p (XEXP (x
, 1), XEXP (y
, 1)));
1949 else if (UNARY_P (x
))
1950 return rtx_renumbered_equal_p (XEXP (x
, 0), XEXP (y
, 0));
1952 /* Compare the elements. If any pair of corresponding elements
1953 fail to match, return 0 for the whole things. */
1955 fmt
= GET_RTX_FORMAT (code
);
1956 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1962 if (XWINT (x
, i
) != XWINT (y
, i
))
1967 if (XINT (x
, i
) != XINT (y
, i
))
1972 if (XTREE (x
, i
) != XTREE (y
, i
))
1977 if (strcmp (XSTR (x
, i
), XSTR (y
, i
)))
1982 if (! rtx_renumbered_equal_p (XEXP (x
, i
), XEXP (y
, i
)))
1987 if (XEXP (x
, i
) != XEXP (y
, i
))
1994 if (XVECLEN (x
, i
) != XVECLEN (y
, i
))
1996 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1997 if (!rtx_renumbered_equal_p (XVECEXP (x
, i
, j
), XVECEXP (y
, i
, j
)))
2008 /* If X is a hard register or equivalent to one or a subregister of one,
2009 return the hard register number. If X is a pseudo register that was not
2010 assigned a hard register, return the pseudo register number. Otherwise,
2011 return -1. Any rtx is valid for X. */
2016 if (GET_CODE (x
) == REG
)
2018 if (REGNO (x
) >= FIRST_PSEUDO_REGISTER
&& reg_renumber
[REGNO (x
)] >= 0)
2019 return reg_renumber
[REGNO (x
)];
2022 if (GET_CODE (x
) == SUBREG
)
2024 int base
= true_regnum (SUBREG_REG (x
));
2025 if (base
>= 0 && base
< FIRST_PSEUDO_REGISTER
)
2026 return base
+ subreg_regno_offset (REGNO (SUBREG_REG (x
)),
2027 GET_MODE (SUBREG_REG (x
)),
2028 SUBREG_BYTE (x
), GET_MODE (x
));
2033 /* Return regno of the register REG and handle subregs too. */
2035 reg_or_subregno (rtx reg
)
2039 if (GET_CODE (reg
) == SUBREG
)
2040 return REGNO (SUBREG_REG (reg
));