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 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. */
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 delete_insn, redirect_jump, and invert_jump are used
35 from other passes as well. */
42 #include "hard-reg-set.h"
44 #include "insn-config.h"
45 #include "insn-attr.h"
55 /* Optimize jump y; x: ... y: jumpif... x?
56 Don't know if it is worth bothering with. */
57 /* Optimize two cases of conditional jump to conditional jump?
58 This can never delete any instruction or make anything dead,
59 or even change what is live at any point.
60 So perhaps let combiner do it. */
62 static int init_label_info PARAMS ((rtx));
63 static void mark_all_labels PARAMS ((rtx));
64 static int duplicate_loop_exit_test PARAMS ((rtx));
65 static void delete_computation PARAMS ((rtx));
66 static void redirect_exp_1 PARAMS ((rtx *, rtx, rtx, rtx));
67 static int redirect_exp PARAMS ((rtx, rtx, rtx));
68 static void invert_exp_1 PARAMS ((rtx));
69 static int invert_exp PARAMS ((rtx));
70 static int returnjump_p_1 PARAMS ((rtx *, void *));
71 static void delete_prior_computation PARAMS ((rtx, rtx));
72 static void mark_modified_reg PARAMS ((rtx, rtx, void *));
74 /* Alternate entry into the jump optimizer. This entry point only rebuilds
75 the JUMP_LABEL field in jumping insns and REG_LABEL notes in non-jumping
78 rebuild_jump_labels (f)
84 max_uid = init_label_info (f) + 1;
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))++;
96 /* Keep track of labels used for marking handlers for exception
97 regions; they cannot usually be deleted. */
99 for (insn = exception_handler_labels; insn; insn = XEXP (insn, 1))
100 if (GET_CODE (XEXP (insn, 0)) == CODE_LABEL)
101 LABEL_NUSES (XEXP (insn, 0))++;
104 /* Some old code expects exactly one BARRIER as the NEXT_INSN of a
105 non-fallthru insn. This is not generally true, as multiple barriers
106 may have crept in, or the BARRIER may be separated from the last
107 real insn by one or more NOTEs.
109 This simple pass moves barriers and removes duplicates so that the
115 rtx insn, next, prev;
116 for (insn = get_insns (); insn; insn = next)
118 next = NEXT_INSN (insn);
119 if (GET_CODE (insn) == BARRIER)
121 prev = prev_nonnote_insn (insn);
122 if (GET_CODE (prev) == BARRIER)
123 delete_barrier (insn);
124 else if (prev != PREV_INSN (insn))
125 reorder_insns (insn, insn, prev);
131 copy_loop_headers (f)
134 register rtx insn, next;
135 /* Now iterate optimizing jumps until nothing changes over one pass. */
136 for (insn = f; insn; insn = next)
140 next = NEXT_INSN (insn);
142 /* See if this is a NOTE_INSN_LOOP_BEG followed by an unconditional
143 jump. Try to optimize by duplicating the loop exit test if so.
144 This is only safe immediately after regscan, because it uses
145 the values of regno_first_uid and regno_last_uid. */
146 if (GET_CODE (insn) == NOTE
147 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
148 && (temp1 = next_nonnote_insn (insn)) != 0
149 && any_uncondjump_p (temp1) && onlyjump_p (temp1))
151 temp = PREV_INSN (insn);
152 if (duplicate_loop_exit_test (insn))
154 next = NEXT_INSN (temp);
161 purge_line_number_notes (f)
166 /* Delete extraneous line number notes.
167 Note that two consecutive notes for different lines are not really
168 extraneous. There should be some indication where that line belonged,
169 even if it became empty. */
171 for (insn = f; insn; insn = NEXT_INSN (insn))
172 if (GET_CODE (insn) == NOTE)
174 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
175 /* Any previous line note was for the prologue; gdb wants a new
176 note after the prologue even if it is for the same line. */
177 last_note = NULL_RTX;
178 else if (NOTE_LINE_NUMBER (insn) >= 0)
180 /* Delete this note if it is identical to previous note. */
182 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last_note)
183 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last_note))
194 /* Initialize LABEL_NUSES and JUMP_LABEL fields. Delete any REG_LABEL
195 notes whose labels don't occur in the insn any more. Returns the
196 largest INSN_UID found. */
204 for (insn = f; insn; insn = NEXT_INSN (insn))
206 if (GET_CODE (insn) == CODE_LABEL)
207 LABEL_NUSES (insn) = (LABEL_PRESERVE_P (insn) != 0);
208 else if (GET_CODE (insn) == JUMP_INSN)
209 JUMP_LABEL (insn) = 0;
210 else if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN)
214 for (note = REG_NOTES (insn); note; note = next)
216 next = XEXP (note, 1);
217 if (REG_NOTE_KIND (note) == REG_LABEL
218 && ! reg_mentioned_p (XEXP (note, 0), PATTERN (insn)))
219 remove_note (insn, note);
222 if (INSN_UID (insn) > largest_uid)
223 largest_uid = INSN_UID (insn);
229 /* Mark the label each jump jumps to.
230 Combine consecutive labels, and count uses of labels. */
238 for (insn = f; insn; insn = NEXT_INSN (insn))
241 if (GET_CODE (insn) == CALL_INSN
242 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
244 mark_all_labels (XEXP (PATTERN (insn), 0));
245 mark_all_labels (XEXP (PATTERN (insn), 1));
246 mark_all_labels (XEXP (PATTERN (insn), 2));
248 /* Canonicalize the tail recursion label attached to the
249 CALL_PLACEHOLDER insn. */
250 if (XEXP (PATTERN (insn), 3))
252 rtx label_ref = gen_rtx_LABEL_REF (VOIDmode,
253 XEXP (PATTERN (insn), 3));
254 mark_jump_label (label_ref, insn, 0);
255 XEXP (PATTERN (insn), 3) = XEXP (label_ref, 0);
261 mark_jump_label (PATTERN (insn), insn, 0);
262 if (! INSN_DELETED_P (insn) && GET_CODE (insn) == JUMP_INSN)
264 /* When we know the LABEL_REF contained in a REG used in
265 an indirect jump, we'll have a REG_LABEL note so that
266 flow can tell where it's going. */
267 if (JUMP_LABEL (insn) == 0)
269 rtx label_note = find_reg_note (insn, REG_LABEL, NULL_RTX);
272 /* But a LABEL_REF around the REG_LABEL note, so
273 that we can canonicalize it. */
274 rtx label_ref = gen_rtx_LABEL_REF (VOIDmode,
275 XEXP (label_note, 0));
277 mark_jump_label (label_ref, insn, 0);
278 XEXP (label_note, 0) = XEXP (label_ref, 0);
279 JUMP_LABEL (insn) = XEXP (label_note, 0);
286 /* LOOP_START is a NOTE_INSN_LOOP_BEG note that is followed by an unconditional
287 jump. Assume that this unconditional jump is to the exit test code. If
288 the code is sufficiently simple, make a copy of it before INSN,
289 followed by a jump to the exit of the loop. Then delete the unconditional
292 Return 1 if we made the change, else 0.
294 This is only safe immediately after a regscan pass because it uses the
295 values of regno_first_uid and regno_last_uid. */
298 duplicate_loop_exit_test (loop_start)
301 rtx insn, set, reg, p, link;
302 rtx copy = 0, first_copy = 0;
304 rtx exitcode = NEXT_INSN (JUMP_LABEL (next_nonnote_insn (loop_start)));
306 int max_reg = max_reg_num ();
308 rtx loop_pre_header_label;
310 /* Scan the exit code. We do not perform this optimization if any insn:
314 has a REG_RETVAL or REG_LIBCALL note (hard to adjust)
315 is a NOTE_INSN_LOOP_BEG because this means we have a nested loop
316 is a NOTE_INSN_BLOCK_{BEG,END} because duplicating these notes
319 We also do not do this if we find an insn with ASM_OPERANDS. While
320 this restriction should not be necessary, copying an insn with
321 ASM_OPERANDS can confuse asm_noperands in some cases.
323 Also, don't do this if the exit code is more than 20 insns. */
325 for (insn = exitcode;
327 && ! (GET_CODE (insn) == NOTE
328 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END);
329 insn = NEXT_INSN (insn))
331 switch (GET_CODE (insn))
337 /* We could be in front of the wrong NOTE_INSN_LOOP_END if there is
338 a jump immediately after the loop start that branches outside
339 the loop but within an outer loop, near the exit test.
340 If we copied this exit test and created a phony
341 NOTE_INSN_LOOP_VTOP, this could make instructions immediately
342 before the exit test look like these could be safely moved
343 out of the loop even if they actually may be never executed.
344 This can be avoided by checking here for NOTE_INSN_LOOP_CONT. */
346 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
347 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_CONT)
351 && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
352 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END))
353 /* If we were to duplicate this code, we would not move
354 the BLOCK notes, and so debugging the moved code would
355 be difficult. Thus, we only move the code with -O2 or
362 /* The code below would grossly mishandle REG_WAS_0 notes,
363 so get rid of them here. */
364 while ((p = find_reg_note (insn, REG_WAS_0, NULL_RTX)) != 0)
365 remove_note (insn, p);
367 || find_reg_note (insn, REG_RETVAL, NULL_RTX)
368 || find_reg_note (insn, REG_LIBCALL, NULL_RTX))
376 /* Unless INSN is zero, we can do the optimization. */
382 /* See if any insn sets a register only used in the loop exit code and
383 not a user variable. If so, replace it with a new register. */
384 for (insn = exitcode; insn != lastexit; insn = NEXT_INSN (insn))
385 if (GET_CODE (insn) == INSN
386 && (set = single_set (insn)) != 0
387 && ((reg = SET_DEST (set), GET_CODE (reg) == REG)
388 || (GET_CODE (reg) == SUBREG
389 && (reg = SUBREG_REG (reg), GET_CODE (reg) == REG)))
390 && REGNO (reg) >= FIRST_PSEUDO_REGISTER
391 && REGNO_FIRST_UID (REGNO (reg)) == INSN_UID (insn))
393 for (p = NEXT_INSN (insn); p != lastexit; p = NEXT_INSN (p))
394 if (REGNO_LAST_UID (REGNO (reg)) == INSN_UID (p))
399 /* We can do the replacement. Allocate reg_map if this is the
400 first replacement we found. */
402 reg_map = (rtx *) xcalloc (max_reg, sizeof (rtx));
404 REG_LOOP_TEST_P (reg) = 1;
406 reg_map[REGNO (reg)] = gen_reg_rtx (GET_MODE (reg));
409 loop_pre_header_label = gen_label_rtx ();
411 /* Now copy each insn. */
412 for (insn = exitcode; insn != lastexit; insn = NEXT_INSN (insn))
414 switch (GET_CODE (insn))
417 copy = emit_barrier_before (loop_start);
420 /* Only copy line-number notes. */
421 if (NOTE_LINE_NUMBER (insn) >= 0)
423 copy = emit_note_before (NOTE_LINE_NUMBER (insn), loop_start);
424 NOTE_SOURCE_FILE (copy) = NOTE_SOURCE_FILE (insn);
429 copy = emit_insn_before (copy_insn (PATTERN (insn)), loop_start);
431 replace_regs (PATTERN (copy), reg_map, max_reg, 1);
433 mark_jump_label (PATTERN (copy), copy, 0);
435 /* Copy all REG_NOTES except REG_LABEL since mark_jump_label will
437 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
438 if (REG_NOTE_KIND (link) != REG_LABEL)
440 if (GET_CODE (link) == EXPR_LIST)
442 = copy_insn_1 (gen_rtx_EXPR_LIST (REG_NOTE_KIND (link),
447 = copy_insn_1 (gen_rtx_INSN_LIST (REG_NOTE_KIND (link),
452 if (reg_map && REG_NOTES (copy))
453 replace_regs (REG_NOTES (copy), reg_map, max_reg, 1);
457 copy = emit_jump_insn_before (copy_insn (PATTERN (insn)),
460 replace_regs (PATTERN (copy), reg_map, max_reg, 1);
461 mark_jump_label (PATTERN (copy), copy, 0);
462 if (REG_NOTES (insn))
464 REG_NOTES (copy) = copy_insn_1 (REG_NOTES (insn));
466 replace_regs (REG_NOTES (copy), reg_map, max_reg, 1);
469 /* Predict conditional jump that do make loop looping as taken.
470 Other jumps are probably exit conditions, so predict
472 if (any_condjump_p (copy))
474 rtx label = JUMP_LABEL (copy);
477 /* The jump_insn after loop_start should be followed
478 by barrier and loopback label. */
479 if (prev_nonnote_insn (label)
480 && (prev_nonnote_insn (prev_nonnote_insn (label))
481 == next_nonnote_insn (loop_start)))
483 predict_insn_def (copy, PRED_LOOP_HEADER, TAKEN);
484 /* To keep pre-header, we need to redirect all loop
485 entrances before the LOOP_BEG note. */
486 redirect_jump (copy, loop_pre_header_label, 0);
489 predict_insn_def (copy, PRED_LOOP_HEADER, NOT_TAKEN);
498 /* Record the first insn we copied. We need it so that we can
499 scan the copied insns for new pseudo registers. */
504 /* Now clean up by emitting a jump to the end label and deleting the jump
505 at the start of the loop. */
506 if (! copy || GET_CODE (copy) != BARRIER)
508 copy = emit_jump_insn_before (gen_jump (get_label_after (insn)),
511 /* Record the first insn we copied. We need it so that we can
512 scan the copied insns for new pseudo registers. This may not
513 be strictly necessary since we should have copied at least one
514 insn above. But I am going to be safe. */
518 mark_jump_label (PATTERN (copy), copy, 0);
519 emit_barrier_before (loop_start);
522 emit_label_before (loop_pre_header_label, loop_start);
524 /* Now scan from the first insn we copied to the last insn we copied
525 (copy) for new pseudo registers. Do this after the code to jump to
526 the end label since that might create a new pseudo too. */
527 reg_scan_update (first_copy, copy, max_reg);
529 /* Mark the exit code as the virtual top of the converted loop. */
530 emit_note_before (NOTE_INSN_LOOP_VTOP, exitcode);
532 delete_insn (next_nonnote_insn (loop_start));
541 /* Move all block-beg, block-end, loop-beg, loop-cont, loop-vtop, loop-end,
542 notes between START and END out before START. Assume that END is not
543 such a note. START may be such a note. Returns the value of the new
544 starting insn, which may be different if the original start was such a
548 squeeze_notes (start, end)
554 for (insn = start; insn != end; insn = next)
556 next = NEXT_INSN (insn);
557 if (GET_CODE (insn) == NOTE
558 && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
559 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
560 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
561 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END
562 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_CONT
563 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_VTOP))
569 rtx prev = PREV_INSN (insn);
570 PREV_INSN (insn) = PREV_INSN (start);
571 NEXT_INSN (insn) = start;
572 NEXT_INSN (PREV_INSN (insn)) = insn;
573 PREV_INSN (NEXT_INSN (insn)) = insn;
574 NEXT_INSN (prev) = next;
575 PREV_INSN (next) = prev;
583 /* Return the label before INSN, or put a new label there. */
586 get_label_before (insn)
591 /* Find an existing label at this point
592 or make a new one if there is none. */
593 label = prev_nonnote_insn (insn);
595 if (label == 0 || GET_CODE (label) != CODE_LABEL)
597 rtx prev = PREV_INSN (insn);
599 label = gen_label_rtx ();
600 emit_label_after (label, prev);
601 LABEL_NUSES (label) = 0;
606 /* Return the label after INSN, or put a new label there. */
609 get_label_after (insn)
614 /* Find an existing label at this point
615 or make a new one if there is none. */
616 label = next_nonnote_insn (insn);
618 if (label == 0 || GET_CODE (label) != CODE_LABEL)
620 label = gen_label_rtx ();
621 emit_label_after (label, insn);
622 LABEL_NUSES (label) = 0;
627 /* Given a comparison (CODE ARG0 ARG1), inside an insn, INSN, return a code
628 of reversed comparison if it is possible to do so. Otherwise return UNKNOWN.
629 UNKNOWN may be returned in case we are having CC_MODE compare and we don't
630 know whether it's source is floating point or integer comparison. Machine
631 description should define REVERSIBLE_CC_MODE and REVERSE_CONDITION macros
632 to help this function avoid overhead in these cases. */
634 reversed_comparison_code_parts (code, arg0, arg1, insn)
635 rtx insn, arg0, arg1;
638 enum machine_mode mode;
640 /* If this is not actually a comparison, we can't reverse it. */
641 if (GET_RTX_CLASS (code) != '<')
644 mode = GET_MODE (arg0);
645 if (mode == VOIDmode)
646 mode = GET_MODE (arg1);
648 /* First see if machine description supply us way to reverse the comparison.
649 Give it priority over everything else to allow machine description to do
651 #ifdef REVERSIBLE_CC_MODE
652 if (GET_MODE_CLASS (mode) == MODE_CC
653 && REVERSIBLE_CC_MODE (mode))
655 #ifdef REVERSE_CONDITION
656 return REVERSE_CONDITION (code, mode);
658 return reverse_condition (code);
662 /* Try a few special cases based on the comparison code. */
671 /* It is always safe to reverse EQ and NE, even for the floating
672 point. Similary the unsigned comparisons are never used for
673 floating point so we can reverse them in the default way. */
674 return reverse_condition (code);
679 /* In case we already see unordered comparison, we can be sure to
680 be dealing with floating point so we don't need any more tests. */
681 return reverse_condition_maybe_unordered (code);
686 /* We don't have safe way to reverse these yet. */
692 /* In case we give up IEEE compatibility, all comparisons are reversible. */
693 if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
694 || flag_unsafe_math_optimizations)
695 return reverse_condition (code);
697 if (GET_MODE_CLASS (mode) == MODE_CC
704 /* Try to search for the comparison to determine the real mode.
705 This code is expensive, but with sane machine description it
706 will be never used, since REVERSIBLE_CC_MODE will return true
711 for (prev = prev_nonnote_insn (insn);
712 prev != 0 && GET_CODE (prev) != CODE_LABEL;
713 prev = prev_nonnote_insn (prev))
715 rtx set = set_of (arg0, prev);
716 if (set && GET_CODE (set) == SET
717 && rtx_equal_p (SET_DEST (set), arg0))
719 rtx src = SET_SRC (set);
721 if (GET_CODE (src) == COMPARE)
723 rtx comparison = src;
724 arg0 = XEXP (src, 0);
725 mode = GET_MODE (arg0);
726 if (mode == VOIDmode)
727 mode = GET_MODE (XEXP (comparison, 1));
730 /* We can get past reg-reg moves. This may be usefull for model
731 of i387 comparisons that first move flag registers around. */
738 /* If register is clobbered in some ununderstandable way,
745 /* An integer condition. */
746 if (GET_CODE (arg0) == CONST_INT
747 || (GET_MODE (arg0) != VOIDmode
748 && GET_MODE_CLASS (mode) != MODE_CC
749 && ! FLOAT_MODE_P (mode)))
750 return reverse_condition (code);
755 /* An wrapper around the previous function to take COMPARISON as rtx
756 expression. This simplifies many callers. */
758 reversed_comparison_code (comparison, insn)
759 rtx comparison, insn;
761 if (GET_RTX_CLASS (GET_CODE (comparison)) != '<')
763 return reversed_comparison_code_parts (GET_CODE (comparison),
764 XEXP (comparison, 0),
765 XEXP (comparison, 1), insn);
768 /* Given an rtx-code for a comparison, return the code for the negated
769 comparison. If no such code exists, return UNKNOWN.
771 WATCH OUT! reverse_condition is not safe to use on a jump that might
772 be acting on the results of an IEEE floating point comparison, because
773 of the special treatment of non-signaling nans in comparisons.
774 Use reversed_comparison_code instead. */
777 reverse_condition (code)
820 /* Similar, but we're allowed to generate unordered comparisons, which
821 makes it safe for IEEE floating-point. Of course, we have to recognize
822 that the target will support them too... */
825 reverse_condition_maybe_unordered (code)
828 /* Non-IEEE formats don't have unordered conditions. */
829 if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT)
830 return reverse_condition (code);
868 /* Similar, but return the code when two operands of a comparison are swapped.
869 This IS safe for IEEE floating-point. */
872 swap_condition (code)
915 /* Given a comparison CODE, return the corresponding unsigned comparison.
916 If CODE is an equality comparison or already an unsigned comparison,
920 unsigned_condition (code)
947 /* Similarly, return the signed version of a comparison. */
950 signed_condition (code)
977 /* Return non-zero if CODE1 is more strict than CODE2, i.e., if the
978 truth of CODE1 implies the truth of CODE2. */
981 comparison_dominates_p (code1, code2)
982 enum rtx_code code1, code2;
984 /* UNKNOWN comparison codes can happen as a result of trying to revert
986 They can't match anything, so we have to reject them here. */
987 if (code1 == UNKNOWN || code2 == UNKNOWN)
996 if (code2 == UNLE || code2 == UNGE)
1001 if (code2 == LE || code2 == LEU || code2 == GE || code2 == GEU
1002 || code2 == ORDERED)
1007 if (code2 == UNLE || code2 == NE)
1012 if (code2 == LE || code2 == NE || code2 == ORDERED || code2 == LTGT)
1017 if (code2 == UNGE || code2 == NE)
1022 if (code2 == GE || code2 == NE || code2 == ORDERED || code2 == LTGT)
1028 if (code2 == ORDERED)
1033 if (code2 == NE || code2 == ORDERED)
1038 if (code2 == LEU || code2 == NE)
1043 if (code2 == GEU || code2 == NE)
1048 if (code2 == NE || code2 == UNEQ || code2 == UNLE || code2 == UNLT
1049 || code2 == UNGE || code2 == UNGT)
1060 /* Return 1 if INSN is an unconditional jump and nothing else. */
1066 return (GET_CODE (insn) == JUMP_INSN
1067 && GET_CODE (PATTERN (insn)) == SET
1068 && GET_CODE (SET_DEST (PATTERN (insn))) == PC
1069 && GET_CODE (SET_SRC (PATTERN (insn))) == LABEL_REF);
1072 /* Return nonzero if INSN is a (possibly) conditional jump
1075 Use this function is deprecated, since we need to support combined
1076 branch and compare insns. Use any_condjump_p instead whenever possible. */
1082 register rtx x = PATTERN (insn);
1084 if (GET_CODE (x) != SET
1085 || GET_CODE (SET_DEST (x)) != PC)
1089 if (GET_CODE (x) == LABEL_REF)
1092 return (GET_CODE (x) == IF_THEN_ELSE
1093 && ((GET_CODE (XEXP (x, 2)) == PC
1094 && (GET_CODE (XEXP (x, 1)) == LABEL_REF
1095 || GET_CODE (XEXP (x, 1)) == RETURN))
1096 || (GET_CODE (XEXP (x, 1)) == PC
1097 && (GET_CODE (XEXP (x, 2)) == LABEL_REF
1098 || GET_CODE (XEXP (x, 2)) == RETURN))));
1103 /* Return nonzero if INSN is a (possibly) conditional jump inside a
1106 Use this function is deprecated, since we need to support combined
1107 branch and compare insns. Use any_condjump_p instead whenever possible. */
1110 condjump_in_parallel_p (insn)
1113 register rtx x = PATTERN (insn);
1115 if (GET_CODE (x) != PARALLEL)
1118 x = XVECEXP (x, 0, 0);
1120 if (GET_CODE (x) != SET)
1122 if (GET_CODE (SET_DEST (x)) != PC)
1124 if (GET_CODE (SET_SRC (x)) == LABEL_REF)
1126 if (GET_CODE (SET_SRC (x)) != IF_THEN_ELSE)
1128 if (XEXP (SET_SRC (x), 2) == pc_rtx
1129 && (GET_CODE (XEXP (SET_SRC (x), 1)) == LABEL_REF
1130 || GET_CODE (XEXP (SET_SRC (x), 1)) == RETURN))
1132 if (XEXP (SET_SRC (x), 1) == pc_rtx
1133 && (GET_CODE (XEXP (SET_SRC (x), 2)) == LABEL_REF
1134 || GET_CODE (XEXP (SET_SRC (x), 2)) == RETURN))
1139 /* Return set of PC, otherwise NULL. */
1146 if (GET_CODE (insn) != JUMP_INSN)
1148 pat = PATTERN (insn);
1150 /* The set is allowed to appear either as the insn pattern or
1151 the first set in a PARALLEL. */
1152 if (GET_CODE (pat) == PARALLEL)
1153 pat = XVECEXP (pat, 0, 0);
1154 if (GET_CODE (pat) == SET && GET_CODE (SET_DEST (pat)) == PC)
1160 /* Return true when insn is an unconditional direct jump,
1161 possibly bundled inside a PARALLEL. */
1164 any_uncondjump_p (insn)
1167 rtx x = pc_set (insn);
1170 if (GET_CODE (SET_SRC (x)) != LABEL_REF)
1175 /* Return true when insn is a conditional jump. This function works for
1176 instructions containing PC sets in PARALLELs. The instruction may have
1177 various other effects so before removing the jump you must verify
1180 Note that unlike condjump_p it returns false for unconditional jumps. */
1183 any_condjump_p (insn)
1186 rtx x = pc_set (insn);
1191 if (GET_CODE (SET_SRC (x)) != IF_THEN_ELSE)
1194 a = GET_CODE (XEXP (SET_SRC (x), 1));
1195 b = GET_CODE (XEXP (SET_SRC (x), 2));
1197 return ((b == PC && (a == LABEL_REF || a == RETURN))
1198 || (a == PC && (b == LABEL_REF || b == RETURN)));
1201 /* Return the label of a conditional jump. */
1204 condjump_label (insn)
1207 rtx x = pc_set (insn);
1212 if (GET_CODE (x) == LABEL_REF)
1214 if (GET_CODE (x) != IF_THEN_ELSE)
1216 if (XEXP (x, 2) == pc_rtx && GET_CODE (XEXP (x, 1)) == LABEL_REF)
1218 if (XEXP (x, 1) == pc_rtx && GET_CODE (XEXP (x, 2)) == LABEL_REF)
1223 /* Return true if INSN is a (possibly conditional) return insn. */
1226 returnjump_p_1 (loc, data)
1228 void *data ATTRIBUTE_UNUSED;
1231 return x && GET_CODE (x) == RETURN;
1238 if (GET_CODE (insn) != JUMP_INSN)
1240 return for_each_rtx (&PATTERN (insn), returnjump_p_1, NULL);
1243 /* Return true if INSN is a jump that only transfers control and
1252 if (GET_CODE (insn) != JUMP_INSN)
1255 set = single_set (insn);
1258 if (GET_CODE (SET_DEST (set)) != PC)
1260 if (side_effects_p (SET_SRC (set)))
1268 /* Return non-zero if X is an RTX that only sets the condition codes
1269 and has no side effects. */
1282 return sets_cc0_p (x) == 1 && ! side_effects_p (x);
1285 /* Return 1 if X is an RTX that does nothing but set the condition codes
1286 and CLOBBER or USE registers.
1287 Return -1 if X does explicitly set the condition codes,
1288 but also does other things. */
1301 if (GET_CODE (x) == SET && SET_DEST (x) == cc0_rtx)
1303 if (GET_CODE (x) == PARALLEL)
1307 int other_things = 0;
1308 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1310 if (GET_CODE (XVECEXP (x, 0, i)) == SET
1311 && SET_DEST (XVECEXP (x, 0, i)) == cc0_rtx)
1313 else if (GET_CODE (XVECEXP (x, 0, i)) == SET)
1316 return ! sets_cc0 ? 0 : other_things ? -1 : 1;
1322 /* Follow any unconditional jump at LABEL;
1323 return the ultimate label reached by any such chain of jumps.
1324 If LABEL is not followed by a jump, return LABEL.
1325 If the chain loops or we can't find end, return LABEL,
1326 since that tells caller to avoid changing the insn.
1328 If RELOAD_COMPLETED is 0, we do not chain across a NOTE_INSN_LOOP_BEG or
1329 a USE or CLOBBER. */
1332 follow_jumps (label)
1337 register rtx value = label;
1342 && (insn = next_active_insn (value)) != 0
1343 && GET_CODE (insn) == JUMP_INSN
1344 && ((JUMP_LABEL (insn) != 0 && any_uncondjump_p (insn)
1345 && onlyjump_p (insn))
1346 || GET_CODE (PATTERN (insn)) == RETURN)
1347 && (next = NEXT_INSN (insn))
1348 && GET_CODE (next) == BARRIER);
1351 /* Don't chain through the insn that jumps into a loop
1352 from outside the loop,
1353 since that would create multiple loop entry jumps
1354 and prevent loop optimization. */
1356 if (!reload_completed)
1357 for (tem = value; tem != insn; tem = NEXT_INSN (tem))
1358 if (GET_CODE (tem) == NOTE
1359 && (NOTE_LINE_NUMBER (tem) == NOTE_INSN_LOOP_BEG
1360 /* ??? Optional. Disables some optimizations, but makes
1361 gcov output more accurate with -O. */
1362 || (flag_test_coverage && NOTE_LINE_NUMBER (tem) > 0)))
1365 /* If we have found a cycle, make the insn jump to itself. */
1366 if (JUMP_LABEL (insn) == label)
1369 tem = next_active_insn (JUMP_LABEL (insn));
1370 if (tem && (GET_CODE (PATTERN (tem)) == ADDR_VEC
1371 || GET_CODE (PATTERN (tem)) == ADDR_DIFF_VEC))
1374 value = JUMP_LABEL (insn);
1382 /* Find all CODE_LABELs referred to in X, and increment their use counts.
1383 If INSN is a JUMP_INSN and there is at least one CODE_LABEL referenced
1384 in INSN, then store one of them in JUMP_LABEL (INSN).
1385 If INSN is an INSN or a CALL_INSN and there is at least one CODE_LABEL
1386 referenced in INSN, add a REG_LABEL note containing that label to INSN.
1387 Also, when there are consecutive labels, canonicalize on the last of them.
1389 Note that two labels separated by a loop-beginning note
1390 must be kept distinct if we have not yet done loop-optimization,
1391 because the gap between them is where loop-optimize
1392 will want to move invariant code to. CROSS_JUMP tells us
1393 that loop-optimization is done with. */
1396 mark_jump_label (x, insn, in_mem)
1401 register RTX_CODE code = GET_CODE (x);
1403 register const char *fmt;
1425 /* If this is a constant-pool reference, see if it is a label. */
1426 if (CONSTANT_POOL_ADDRESS_P (x))
1427 mark_jump_label (get_pool_constant (x), insn, in_mem);
1432 rtx label = XEXP (x, 0);
1434 /* Ignore remaining references to unreachable labels that
1435 have been deleted. */
1436 if (GET_CODE (label) == NOTE
1437 && NOTE_LINE_NUMBER (label) == NOTE_INSN_DELETED_LABEL)
1440 if (GET_CODE (label) != CODE_LABEL)
1443 /* Ignore references to labels of containing functions. */
1444 if (LABEL_REF_NONLOCAL_P (x))
1447 XEXP (x, 0) = label;
1448 if (! insn || ! INSN_DELETED_P (insn))
1449 ++LABEL_NUSES (label);
1453 if (GET_CODE (insn) == JUMP_INSN)
1454 JUMP_LABEL (insn) = label;
1457 /* Add a REG_LABEL note for LABEL unless there already
1458 is one. All uses of a label, except for labels
1459 that are the targets of jumps, must have a
1461 if (! find_reg_note (insn, REG_LABEL, label))
1462 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL, label,
1469 /* Do walk the labels in a vector, but not the first operand of an
1470 ADDR_DIFF_VEC. Don't set the JUMP_LABEL of a vector. */
1473 if (! INSN_DELETED_P (insn))
1475 int eltnum = code == ADDR_DIFF_VEC ? 1 : 0;
1477 for (i = 0; i < XVECLEN (x, eltnum); i++)
1478 mark_jump_label (XVECEXP (x, eltnum, i), NULL_RTX, in_mem);
1486 fmt = GET_RTX_FORMAT (code);
1487 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1490 mark_jump_label (XEXP (x, i), insn, in_mem);
1491 else if (fmt[i] == 'E')
1494 for (j = 0; j < XVECLEN (x, i); j++)
1495 mark_jump_label (XVECEXP (x, i, j), insn, in_mem);
1500 /* If all INSN does is set the pc, delete it,
1501 and delete the insn that set the condition codes for it
1502 if that's what the previous thing was. */
1508 register rtx set = single_set (insn);
1510 if (set && GET_CODE (SET_DEST (set)) == PC)
1511 delete_computation (insn);
1514 /* Verify INSN is a BARRIER and delete it. */
1517 delete_barrier (insn)
1520 if (GET_CODE (insn) != BARRIER)
1526 /* Recursively delete prior insns that compute the value (used only by INSN
1527 which the caller is deleting) stored in the register mentioned by NOTE
1528 which is a REG_DEAD note associated with INSN. */
1531 delete_prior_computation (note, insn)
1536 rtx reg = XEXP (note, 0);
1538 for (our_prev = prev_nonnote_insn (insn);
1539 our_prev && (GET_CODE (our_prev) == INSN
1540 || GET_CODE (our_prev) == CALL_INSN);
1541 our_prev = prev_nonnote_insn (our_prev))
1543 rtx pat = PATTERN (our_prev);
1545 /* If we reach a CALL which is not calling a const function
1546 or the callee pops the arguments, then give up. */
1547 if (GET_CODE (our_prev) == CALL_INSN
1548 && (! CONST_OR_PURE_CALL_P (our_prev)
1549 || GET_CODE (pat) != SET || GET_CODE (SET_SRC (pat)) != CALL))
1552 /* If we reach a SEQUENCE, it is too complex to try to
1553 do anything with it, so give up. */
1554 if (GET_CODE (pat) == SEQUENCE)
1557 if (GET_CODE (pat) == USE
1558 && GET_CODE (XEXP (pat, 0)) == INSN)
1559 /* reorg creates USEs that look like this. We leave them
1560 alone because reorg needs them for its own purposes. */
1563 if (reg_set_p (reg, pat))
1565 if (side_effects_p (pat) && GET_CODE (our_prev) != CALL_INSN)
1568 if (GET_CODE (pat) == PARALLEL)
1570 /* If we find a SET of something else, we can't
1575 for (i = 0; i < XVECLEN (pat, 0); i++)
1577 rtx part = XVECEXP (pat, 0, i);
1579 if (GET_CODE (part) == SET
1580 && SET_DEST (part) != reg)
1584 if (i == XVECLEN (pat, 0))
1585 delete_computation (our_prev);
1587 else if (GET_CODE (pat) == SET
1588 && GET_CODE (SET_DEST (pat)) == REG)
1590 int dest_regno = REGNO (SET_DEST (pat));
1593 + (dest_regno < FIRST_PSEUDO_REGISTER
1594 ? HARD_REGNO_NREGS (dest_regno,
1595 GET_MODE (SET_DEST (pat))) : 1));
1596 int regno = REGNO (reg);
1599 + (regno < FIRST_PSEUDO_REGISTER
1600 ? HARD_REGNO_NREGS (regno, GET_MODE (reg)) : 1));
1602 if (dest_regno >= regno
1603 && dest_endregno <= endregno)
1604 delete_computation (our_prev);
1606 /* We may have a multi-word hard register and some, but not
1607 all, of the words of the register are needed in subsequent
1608 insns. Write REG_UNUSED notes for those parts that were not
1610 else if (dest_regno <= regno
1611 && dest_endregno >= endregno)
1615 REG_NOTES (our_prev)
1616 = gen_rtx_EXPR_LIST (REG_UNUSED, reg,
1617 REG_NOTES (our_prev));
1619 for (i = dest_regno; i < dest_endregno; i++)
1620 if (! find_regno_note (our_prev, REG_UNUSED, i))
1623 if (i == dest_endregno)
1624 delete_computation (our_prev);
1631 /* If PAT references the register that dies here, it is an
1632 additional use. Hence any prior SET isn't dead. However, this
1633 insn becomes the new place for the REG_DEAD note. */
1634 if (reg_overlap_mentioned_p (reg, pat))
1636 XEXP (note, 1) = REG_NOTES (our_prev);
1637 REG_NOTES (our_prev) = note;
1643 /* Delete INSN and recursively delete insns that compute values used only
1644 by INSN. This uses the REG_DEAD notes computed during flow analysis.
1645 If we are running before flow.c, we need do nothing since flow.c will
1646 delete dead code. We also can't know if the registers being used are
1647 dead or not at this point.
1649 Otherwise, look at all our REG_DEAD notes. If a previous insn does
1650 nothing other than set a register that dies in this insn, we can delete
1653 On machines with CC0, if CC0 is used in this insn, we may be able to
1654 delete the insn that set it. */
1657 delete_computation (insn)
1663 if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
1665 rtx prev = prev_nonnote_insn (insn);
1666 /* We assume that at this stage
1667 CC's are always set explicitly
1668 and always immediately before the jump that
1669 will use them. So if the previous insn
1670 exists to set the CC's, delete it
1671 (unless it performs auto-increments, etc.). */
1672 if (prev && GET_CODE (prev) == INSN
1673 && sets_cc0_p (PATTERN (prev)))
1675 if (sets_cc0_p (PATTERN (prev)) > 0
1676 && ! side_effects_p (PATTERN (prev)))
1677 delete_computation (prev);
1679 /* Otherwise, show that cc0 won't be used. */
1680 REG_NOTES (prev) = gen_rtx_EXPR_LIST (REG_UNUSED,
1681 cc0_rtx, REG_NOTES (prev));
1686 for (note = REG_NOTES (insn); note; note = next)
1688 next = XEXP (note, 1);
1690 if (REG_NOTE_KIND (note) != REG_DEAD
1691 /* Verify that the REG_NOTE is legitimate. */
1692 || GET_CODE (XEXP (note, 0)) != REG)
1695 delete_prior_computation (note, insn);
1701 /* Delete insn INSN from the chain of insns and update label ref counts.
1702 May delete some following insns as a consequence; may even delete
1703 a label elsewhere and insns that follow it.
1705 Returns the first insn after INSN that was not deleted. */
1711 register rtx next = NEXT_INSN (insn);
1712 register rtx prev = PREV_INSN (insn);
1713 register int was_code_label = (GET_CODE (insn) == CODE_LABEL);
1714 register int dont_really_delete = 0;
1717 while (next && INSN_DELETED_P (next))
1718 next = NEXT_INSN (next);
1720 /* This insn is already deleted => return first following nondeleted. */
1721 if (INSN_DELETED_P (insn))
1725 remove_node_from_expr_list (insn, &nonlocal_goto_handler_labels);
1727 /* Don't delete user-declared labels. When optimizing, convert them
1728 to special NOTEs instead. When not optimizing, leave them alone. */
1729 if (was_code_label && LABEL_NAME (insn) != 0)
1733 const char *name = LABEL_NAME (insn);
1734 PUT_CODE (insn, NOTE);
1735 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED_LABEL;
1736 NOTE_SOURCE_FILE (insn) = name;
1739 dont_really_delete = 1;
1742 /* Mark this insn as deleted. */
1743 INSN_DELETED_P (insn) = 1;
1745 /* If instruction is followed by a barrier,
1746 delete the barrier too. */
1748 if (next != 0 && GET_CODE (next) == BARRIER)
1750 INSN_DELETED_P (next) = 1;
1751 next = NEXT_INSN (next);
1754 /* Patch out INSN (and the barrier if any) */
1756 if (! dont_really_delete)
1760 NEXT_INSN (prev) = next;
1761 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
1762 NEXT_INSN (XVECEXP (PATTERN (prev), 0,
1763 XVECLEN (PATTERN (prev), 0) - 1)) = next;
1768 PREV_INSN (next) = prev;
1769 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
1770 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = prev;
1773 if (prev && NEXT_INSN (prev) == 0)
1774 set_last_insn (prev);
1777 /* If deleting a jump, decrement the count of the label,
1778 and delete the label if it is now unused. */
1780 if (GET_CODE (insn) == JUMP_INSN && JUMP_LABEL (insn))
1782 rtx lab = JUMP_LABEL (insn), lab_next;
1784 if (--LABEL_NUSES (lab) == 0)
1786 /* This can delete NEXT or PREV,
1787 either directly if NEXT is JUMP_LABEL (INSN),
1788 or indirectly through more levels of jumps. */
1791 /* I feel a little doubtful about this loop,
1792 but I see no clean and sure alternative way
1793 to find the first insn after INSN that is not now deleted.
1794 I hope this works. */
1795 while (next && INSN_DELETED_P (next))
1796 next = NEXT_INSN (next);
1799 else if ((lab_next = next_nonnote_insn (lab)) != NULL
1800 && GET_CODE (lab_next) == JUMP_INSN
1801 && (GET_CODE (PATTERN (lab_next)) == ADDR_VEC
1802 || GET_CODE (PATTERN (lab_next)) == ADDR_DIFF_VEC))
1804 /* If we're deleting the tablejump, delete the dispatch table.
1805 We may not be able to kill the label immediately preceeding
1806 just yet, as it might be referenced in code leading up to
1808 delete_insn (lab_next);
1812 /* Likewise if we're deleting a dispatch table. */
1814 if (GET_CODE (insn) == JUMP_INSN
1815 && (GET_CODE (PATTERN (insn)) == ADDR_VEC
1816 || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC))
1818 rtx pat = PATTERN (insn);
1819 int i, diff_vec_p = GET_CODE (pat) == ADDR_DIFF_VEC;
1820 int len = XVECLEN (pat, diff_vec_p);
1822 for (i = 0; i < len; i++)
1823 if (--LABEL_NUSES (XEXP (XVECEXP (pat, diff_vec_p, i), 0)) == 0)
1824 delete_insn (XEXP (XVECEXP (pat, diff_vec_p, i), 0));
1825 while (next && INSN_DELETED_P (next))
1826 next = NEXT_INSN (next);
1830 /* Likewise for an ordinary INSN / CALL_INSN with a REG_LABEL note. */
1831 if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN)
1832 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1833 if (REG_NOTE_KIND (note) == REG_LABEL
1834 /* This could also be a NOTE_INSN_DELETED_LABEL note. */
1835 && GET_CODE (XEXP (note, 0)) == CODE_LABEL)
1836 if (--LABEL_NUSES (XEXP (note, 0)) == 0)
1837 delete_insn (XEXP (note, 0));
1839 while (prev && (INSN_DELETED_P (prev) || GET_CODE (prev) == NOTE))
1840 prev = PREV_INSN (prev);
1842 /* If INSN was a label and a dispatch table follows it,
1843 delete the dispatch table. The tablejump must have gone already.
1844 It isn't useful to fall through into a table. */
1847 && NEXT_INSN (insn) != 0
1848 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN
1849 && (GET_CODE (PATTERN (NEXT_INSN (insn))) == ADDR_VEC
1850 || GET_CODE (PATTERN (NEXT_INSN (insn))) == ADDR_DIFF_VEC))
1851 next = delete_insn (NEXT_INSN (insn));
1853 /* If INSN was a label, delete insns following it if now unreachable. */
1855 if (was_code_label && prev && GET_CODE (prev) == BARRIER)
1857 register RTX_CODE code;
1859 && (GET_RTX_CLASS (code = GET_CODE (next)) == 'i'
1860 || code == NOTE || code == BARRIER
1861 || (code == CODE_LABEL && INSN_DELETED_P (next))))
1864 && NOTE_LINE_NUMBER (next) != NOTE_INSN_FUNCTION_END)
1865 next = NEXT_INSN (next);
1866 /* Keep going past other deleted labels to delete what follows. */
1867 else if (code == CODE_LABEL && INSN_DELETED_P (next))
1868 next = NEXT_INSN (next);
1870 /* Note: if this deletes a jump, it can cause more
1871 deletion of unreachable code, after a different label.
1872 As long as the value from this recursive call is correct,
1873 this invocation functions correctly. */
1874 next = delete_insn (next);
1881 /* Advance from INSN till reaching something not deleted
1882 then return that. May return INSN itself. */
1885 next_nondeleted_insn (insn)
1888 while (INSN_DELETED_P (insn))
1889 insn = NEXT_INSN (insn);
1893 /* Delete a range of insns from FROM to TO, inclusive.
1894 This is for the sake of peephole optimization, so assume
1895 that whatever these insns do will still be done by a new
1896 peephole insn that will replace them. */
1899 delete_for_peephole (from, to)
1900 register rtx from, to;
1902 register rtx insn = from;
1906 register rtx next = NEXT_INSN (insn);
1907 register rtx prev = PREV_INSN (insn);
1909 if (GET_CODE (insn) != NOTE)
1911 INSN_DELETED_P (insn) = 1;
1913 /* Patch this insn out of the chain. */
1914 /* We don't do this all at once, because we
1915 must preserve all NOTEs. */
1917 NEXT_INSN (prev) = next;
1920 PREV_INSN (next) = prev;
1928 /* Note that if TO is an unconditional jump
1929 we *do not* delete the BARRIER that follows,
1930 since the peephole that replaces this sequence
1931 is also an unconditional jump in that case. */
1934 /* We have determined that INSN is never reached, and are about to
1935 delete it. Print a warning if the user asked for one.
1937 To try to make this warning more useful, this should only be called
1938 once per basic block not reached, and it only warns when the basic
1939 block contains more than one line from the current function, and
1940 contains at least one operation. CSE and inlining can duplicate insns,
1941 so it's possible to get spurious warnings from this. */
1944 never_reached_warning (avoided_insn)
1948 rtx a_line_note = NULL;
1949 int two_avoided_lines = 0;
1950 int contains_insn = 0;
1952 if (! warn_notreached)
1955 /* Scan forwards, looking at LINE_NUMBER notes, until
1956 we hit a LABEL or we run out of insns. */
1958 for (insn = avoided_insn; insn != NULL; insn = NEXT_INSN (insn))
1960 if (GET_CODE (insn) == CODE_LABEL)
1962 else if (GET_CODE (insn) == NOTE /* A line number note? */
1963 && NOTE_LINE_NUMBER (insn) >= 0)
1965 if (a_line_note == NULL)
1968 two_avoided_lines |= (NOTE_LINE_NUMBER (a_line_note)
1969 != NOTE_LINE_NUMBER (insn));
1971 else if (INSN_P (insn))
1974 if (two_avoided_lines && contains_insn)
1975 warning_with_file_and_line (NOTE_SOURCE_FILE (a_line_note),
1976 NOTE_LINE_NUMBER (a_line_note),
1977 "will never be executed");
1980 /* Throughout LOC, redirect OLABEL to NLABEL. Treat null OLABEL or
1981 NLABEL as a return. Accrue modifications into the change group. */
1984 redirect_exp_1 (loc, olabel, nlabel, insn)
1989 register rtx x = *loc;
1990 register RTX_CODE code = GET_CODE (x);
1992 register const char *fmt;
1994 if (code == LABEL_REF)
1996 if (XEXP (x, 0) == olabel)
2000 n = gen_rtx_LABEL_REF (VOIDmode, nlabel);
2002 n = gen_rtx_RETURN (VOIDmode);
2004 validate_change (insn, loc, n, 1);
2008 else if (code == RETURN && olabel == 0)
2010 x = gen_rtx_LABEL_REF (VOIDmode, nlabel);
2011 if (loc == &PATTERN (insn))
2012 x = gen_rtx_SET (VOIDmode, pc_rtx, x);
2013 validate_change (insn, loc, x, 1);
2017 if (code == SET && nlabel == 0 && SET_DEST (x) == pc_rtx
2018 && GET_CODE (SET_SRC (x)) == LABEL_REF
2019 && XEXP (SET_SRC (x), 0) == olabel)
2021 validate_change (insn, loc, gen_rtx_RETURN (VOIDmode), 1);
2025 fmt = GET_RTX_FORMAT (code);
2026 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2029 redirect_exp_1 (&XEXP (x, i), olabel, nlabel, insn);
2030 else if (fmt[i] == 'E')
2033 for (j = 0; j < XVECLEN (x, i); j++)
2034 redirect_exp_1 (&XVECEXP (x, i, j), olabel, nlabel, insn);
2039 /* Similar, but apply the change group and report success or failure. */
2042 redirect_exp (olabel, nlabel, insn)
2048 if (GET_CODE (PATTERN (insn)) == PARALLEL)
2049 loc = &XVECEXP (PATTERN (insn), 0, 0);
2051 loc = &PATTERN (insn);
2053 redirect_exp_1 (loc, olabel, nlabel, insn);
2054 if (num_validated_changes () == 0)
2057 return apply_change_group ();
2060 /* Make JUMP go to NLABEL instead of where it jumps now. Accrue
2061 the modifications into the change group. Return false if we did
2062 not see how to do that. */
2065 redirect_jump_1 (jump, nlabel)
2068 int ochanges = num_validated_changes ();
2071 if (GET_CODE (PATTERN (jump)) == PARALLEL)
2072 loc = &XVECEXP (PATTERN (jump), 0, 0);
2074 loc = &PATTERN (jump);
2076 redirect_exp_1 (loc, JUMP_LABEL (jump), nlabel, jump);
2077 return num_validated_changes () > ochanges;
2080 /* Make JUMP go to NLABEL instead of where it jumps now. If the old
2081 jump target label is unused as a result, it and the code following
2084 If NLABEL is zero, we are to turn the jump into a (possibly conditional)
2087 The return value will be 1 if the change was made, 0 if it wasn't
2088 (this can only occur for NLABEL == 0). */
2091 redirect_jump (jump, nlabel, delete_unused)
2095 register rtx olabel = JUMP_LABEL (jump);
2097 if (nlabel == olabel)
2100 if (! redirect_exp (olabel, nlabel, jump))
2103 JUMP_LABEL (jump) = nlabel;
2105 ++LABEL_NUSES (nlabel);
2107 /* If we're eliding the jump over exception cleanups at the end of a
2108 function, move the function end note so that -Wreturn-type works. */
2109 if (olabel && nlabel
2110 && NEXT_INSN (olabel)
2111 && GET_CODE (NEXT_INSN (olabel)) == NOTE
2112 && NOTE_LINE_NUMBER (NEXT_INSN (olabel)) == NOTE_INSN_FUNCTION_END)
2113 emit_note_after (NOTE_INSN_FUNCTION_END, nlabel);
2115 if (olabel && --LABEL_NUSES (olabel) == 0 && delete_unused)
2116 delete_insn (olabel);
2121 /* Invert the jump condition of rtx X contained in jump insn, INSN.
2122 Accrue the modifications into the change group. */
2128 register RTX_CODE code;
2129 rtx x = pc_set (insn);
2135 code = GET_CODE (x);
2137 if (code == IF_THEN_ELSE)
2139 register rtx comp = XEXP (x, 0);
2141 enum rtx_code reversed_code;
2143 /* We can do this in two ways: The preferable way, which can only
2144 be done if this is not an integer comparison, is to reverse
2145 the comparison code. Otherwise, swap the THEN-part and ELSE-part
2146 of the IF_THEN_ELSE. If we can't do either, fail. */
2148 reversed_code = reversed_comparison_code (comp, insn);
2150 if (reversed_code != UNKNOWN)
2152 validate_change (insn, &XEXP (x, 0),
2153 gen_rtx_fmt_ee (reversed_code,
2154 GET_MODE (comp), XEXP (comp, 0),
2161 validate_change (insn, &XEXP (x, 1), XEXP (x, 2), 1);
2162 validate_change (insn, &XEXP (x, 2), tem, 1);
2168 /* Invert the jump condition of conditional jump insn, INSN.
2170 Return 1 if we can do so, 0 if we cannot find a way to do so that
2171 matches a pattern. */
2177 invert_exp_1 (insn);
2178 if (num_validated_changes () == 0)
2181 return apply_change_group ();
2184 /* Invert the condition of the jump JUMP, and make it jump to label
2185 NLABEL instead of where it jumps now. Accrue changes into the
2186 change group. Return false if we didn't see how to perform the
2187 inversion and redirection. */
2190 invert_jump_1 (jump, nlabel)
2195 ochanges = num_validated_changes ();
2196 invert_exp_1 (jump);
2197 if (num_validated_changes () == ochanges)
2200 return redirect_jump_1 (jump, nlabel);
2203 /* Invert the condition of the jump JUMP, and make it jump to label
2204 NLABEL instead of where it jumps now. Return true if successful. */
2207 invert_jump (jump, nlabel, delete_unused)
2211 /* We have to either invert the condition and change the label or
2212 do neither. Either operation could fail. We first try to invert
2213 the jump. If that succeeds, we try changing the label. If that fails,
2214 we invert the jump back to what it was. */
2216 if (! invert_exp (jump))
2219 if (redirect_jump (jump, nlabel, delete_unused))
2221 invert_br_probabilities (jump);
2226 if (! invert_exp (jump))
2227 /* This should just be putting it back the way it was. */
2234 /* Like rtx_equal_p except that it considers two REGs as equal
2235 if they renumber to the same value and considers two commutative
2236 operations to be the same if the order of the operands has been
2239 ??? Addition is not commutative on the PA due to the weird implicit
2240 space register selection rules for memory addresses. Therefore, we
2241 don't consider a + b == b + a.
2243 We could/should make this test a little tighter. Possibly only
2244 disabling it on the PA via some backend macro or only disabling this
2245 case when the PLUS is inside a MEM. */
2248 rtx_renumbered_equal_p (x, y)
2252 register RTX_CODE code = GET_CODE (x);
2253 register const char *fmt;
2258 if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
2259 && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
2260 && GET_CODE (SUBREG_REG (y)) == REG)))
2262 int reg_x = -1, reg_y = -1;
2263 int byte_x = 0, byte_y = 0;
2265 if (GET_MODE (x) != GET_MODE (y))
2268 /* If we haven't done any renumbering, don't
2269 make any assumptions. */
2270 if (reg_renumber == 0)
2271 return rtx_equal_p (x, y);
2275 reg_x = REGNO (SUBREG_REG (x));
2276 byte_x = SUBREG_BYTE (x);
2278 if (reg_renumber[reg_x] >= 0)
2280 reg_x = subreg_regno_offset (reg_renumber[reg_x],
2281 GET_MODE (SUBREG_REG (x)),
2290 if (reg_renumber[reg_x] >= 0)
2291 reg_x = reg_renumber[reg_x];
2294 if (GET_CODE (y) == SUBREG)
2296 reg_y = REGNO (SUBREG_REG (y));
2297 byte_y = SUBREG_BYTE (y);
2299 if (reg_renumber[reg_y] >= 0)
2301 reg_y = subreg_regno_offset (reg_renumber[reg_y],
2302 GET_MODE (SUBREG_REG (y)),
2311 if (reg_renumber[reg_y] >= 0)
2312 reg_y = reg_renumber[reg_y];
2315 return reg_x >= 0 && reg_x == reg_y && byte_x == byte_y;
2318 /* Now we have disposed of all the cases
2319 in which different rtx codes can match. */
2320 if (code != GET_CODE (y))
2332 return INTVAL (x) == INTVAL (y);
2335 /* We can't assume nonlocal labels have their following insns yet. */
2336 if (LABEL_REF_NONLOCAL_P (x) || LABEL_REF_NONLOCAL_P (y))
2337 return XEXP (x, 0) == XEXP (y, 0);
2339 /* Two label-refs are equivalent if they point at labels
2340 in the same position in the instruction stream. */
2341 return (next_real_insn (XEXP (x, 0))
2342 == next_real_insn (XEXP (y, 0)));
2345 return XSTR (x, 0) == XSTR (y, 0);
2348 /* If we didn't match EQ equality above, they aren't the same. */
2355 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
2357 if (GET_MODE (x) != GET_MODE (y))
2360 /* For commutative operations, the RTX match if the operand match in any
2361 order. Also handle the simple binary and unary cases without a loop.
2363 ??? Don't consider PLUS a commutative operator; see comments above. */
2364 if ((code == EQ || code == NE || GET_RTX_CLASS (code) == 'c')
2366 return ((rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 0))
2367 && rtx_renumbered_equal_p (XEXP (x, 1), XEXP (y, 1)))
2368 || (rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 1))
2369 && rtx_renumbered_equal_p (XEXP (x, 1), XEXP (y, 0))));
2370 else if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == '2')
2371 return (rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 0))
2372 && rtx_renumbered_equal_p (XEXP (x, 1), XEXP (y, 1)));
2373 else if (GET_RTX_CLASS (code) == '1')
2374 return rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 0));
2376 /* Compare the elements. If any pair of corresponding elements
2377 fail to match, return 0 for the whole things. */
2379 fmt = GET_RTX_FORMAT (code);
2380 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2386 if (XWINT (x, i) != XWINT (y, i))
2391 if (XINT (x, i) != XINT (y, i))
2396 if (XTREE (x, i) != XTREE (y, i))
2401 if (strcmp (XSTR (x, i), XSTR (y, i)))
2406 if (! rtx_renumbered_equal_p (XEXP (x, i), XEXP (y, i)))
2411 if (XEXP (x, i) != XEXP (y, i))
2418 if (XVECLEN (x, i) != XVECLEN (y, i))
2420 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2421 if (!rtx_renumbered_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j)))
2432 /* If X is a hard register or equivalent to one or a subregister of one,
2433 return the hard register number. If X is a pseudo register that was not
2434 assigned a hard register, return the pseudo register number. Otherwise,
2435 return -1. Any rtx is valid for X. */
2441 if (GET_CODE (x) == REG)
2443 if (REGNO (x) >= FIRST_PSEUDO_REGISTER && reg_renumber[REGNO (x)] >= 0)
2444 return reg_renumber[REGNO (x)];
2447 if (GET_CODE (x) == SUBREG)
2449 int base = true_regnum (SUBREG_REG (x));
2450 if (base >= 0 && base < FIRST_PSEUDO_REGISTER)
2451 return base + subreg_regno_offset (REGNO (SUBREG_REG (x)),
2452 GET_MODE (SUBREG_REG (x)),
2453 SUBREG_BYTE (x), GET_MODE (x));
2458 /* Optimize code of the form:
2460 for (x = a[i]; x; ...)
2462 for (x = a[i]; x; ...)
2466 Loop optimize will change the above code into
2470 { ...; if (! (x = ...)) break; }
2473 { ...; if (! (x = ...)) break; }
2476 In general, if the first test fails, the program can branch
2477 directly to `foo' and skip the second try which is doomed to fail.
2478 We run this after loop optimization and before flow analysis. */
2480 /* When comparing the insn patterns, we track the fact that different
2481 pseudo-register numbers may have been used in each computation.
2482 The following array stores an equivalence -- same_regs[I] == J means
2483 that pseudo register I was used in the first set of tests in a context
2484 where J was used in the second set. We also count the number of such
2485 pending equivalences. If nonzero, the expressions really aren't the
2488 static int *same_regs;
2490 static int num_same_regs;
2492 /* Track any registers modified between the target of the first jump and
2493 the second jump. They never compare equal. */
2495 static char *modified_regs;
2497 /* Record if memory was modified. */
2499 static int modified_mem;
2501 /* Called via note_stores on each insn between the target of the first
2502 branch and the second branch. It marks any changed registers. */
2505 mark_modified_reg (dest, x, data)
2508 void *data ATTRIBUTE_UNUSED;
2513 if (GET_CODE (dest) == SUBREG)
2514 dest = SUBREG_REG (dest);
2516 if (GET_CODE (dest) == MEM)
2519 if (GET_CODE (dest) != REG)
2522 regno = REGNO (dest);
2523 if (regno >= FIRST_PSEUDO_REGISTER)
2524 modified_regs[regno] = 1;
2525 /* Don't consider a hard condition code register as modified,
2526 if it is only being set. thread_jumps will check if it is set
2527 to the same value. */
2528 else if (GET_MODE_CLASS (GET_MODE (dest)) != MODE_CC
2529 || GET_CODE (x) != SET
2530 || ! rtx_equal_p (dest, SET_DEST (x))
2531 || HARD_REGNO_NREGS (regno, GET_MODE (dest)) != 1)
2532 for (i = 0; i < HARD_REGNO_NREGS (regno, GET_MODE (dest)); i++)
2533 modified_regs[regno + i] = 1;
2536 /* F is the first insn in the chain of insns. */
2539 thread_jumps (f, max_reg, flag_before_loop)
2542 int flag_before_loop;
2544 /* Basic algorithm is to find a conditional branch,
2545 the label it may branch to, and the branch after
2546 that label. If the two branches test the same condition,
2547 walk back from both branch paths until the insn patterns
2548 differ, or code labels are hit. If we make it back to
2549 the target of the first branch, then we know that the first branch
2550 will either always succeed or always fail depending on the relative
2551 senses of the two branches. So adjust the first branch accordingly
2554 rtx label, b1, b2, t1, t2;
2555 enum rtx_code code1, code2;
2556 rtx b1op0, b1op1, b2op0, b2op1;
2560 enum rtx_code reversed_code1, reversed_code2;
2562 /* Allocate register tables and quick-reset table. */
2563 modified_regs = (char *) xmalloc (max_reg * sizeof (char));
2564 same_regs = (int *) xmalloc (max_reg * sizeof (int));
2565 all_reset = (int *) xmalloc (max_reg * sizeof (int));
2566 for (i = 0; i < max_reg; i++)
2573 for (b1 = f; b1; b1 = NEXT_INSN (b1))
2578 /* Get to a candidate branch insn. */
2579 if (GET_CODE (b1) != JUMP_INSN
2580 || ! any_condjump_p (b1) || JUMP_LABEL (b1) == 0)
2583 memset (modified_regs, 0, max_reg * sizeof (char));
2586 memcpy (same_regs, all_reset, max_reg * sizeof (int));
2589 label = JUMP_LABEL (b1);
2591 /* Look for a branch after the target. Record any registers and
2592 memory modified between the target and the branch. Stop when we
2593 get to a label since we can't know what was changed there. */
2594 for (b2 = NEXT_INSN (label); b2; b2 = NEXT_INSN (b2))
2596 if (GET_CODE (b2) == CODE_LABEL)
2599 else if (GET_CODE (b2) == JUMP_INSN)
2601 /* If this is an unconditional jump and is the only use of
2602 its target label, we can follow it. */
2603 if (any_uncondjump_p (b2)
2605 && JUMP_LABEL (b2) != 0
2606 && LABEL_NUSES (JUMP_LABEL (b2)) == 1)
2608 b2 = JUMP_LABEL (b2);
2615 if (GET_CODE (b2) != CALL_INSN && GET_CODE (b2) != INSN)
2618 if (GET_CODE (b2) == CALL_INSN)
2621 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2622 if (call_used_regs[i] && ! fixed_regs[i]
2623 && i != STACK_POINTER_REGNUM
2624 && i != FRAME_POINTER_REGNUM
2625 && i != HARD_FRAME_POINTER_REGNUM
2626 && i != ARG_POINTER_REGNUM)
2627 modified_regs[i] = 1;
2630 note_stores (PATTERN (b2), mark_modified_reg, NULL);
2633 /* Check the next candidate branch insn from the label
2636 || GET_CODE (b2) != JUMP_INSN
2638 || !any_condjump_p (b2)
2639 || !onlyjump_p (b2))
2644 /* Get the comparison codes and operands, reversing the
2645 codes if appropriate. If we don't have comparison codes,
2646 we can't do anything. */
2647 b1op0 = XEXP (XEXP (SET_SRC (set), 0), 0);
2648 b1op1 = XEXP (XEXP (SET_SRC (set), 0), 1);
2649 code1 = GET_CODE (XEXP (SET_SRC (set), 0));
2650 reversed_code1 = code1;
2651 if (XEXP (SET_SRC (set), 1) == pc_rtx)
2652 code1 = reversed_comparison_code (XEXP (SET_SRC (set), 0), b1);
2654 reversed_code1 = reversed_comparison_code (XEXP (SET_SRC (set), 0), b1);
2656 b2op0 = XEXP (XEXP (SET_SRC (set2), 0), 0);
2657 b2op1 = XEXP (XEXP (SET_SRC (set2), 0), 1);
2658 code2 = GET_CODE (XEXP (SET_SRC (set2), 0));
2659 reversed_code2 = code2;
2660 if (XEXP (SET_SRC (set2), 1) == pc_rtx)
2661 code2 = reversed_comparison_code (XEXP (SET_SRC (set2), 0), b2);
2663 reversed_code2 = reversed_comparison_code (XEXP (SET_SRC (set2), 0), b2);
2665 /* If they test the same things and knowing that B1 branches
2666 tells us whether or not B2 branches, check if we
2667 can thread the branch. */
2668 if (rtx_equal_for_thread_p (b1op0, b2op0, b2)
2669 && rtx_equal_for_thread_p (b1op1, b2op1, b2)
2670 && (comparison_dominates_p (code1, code2)
2671 || comparison_dominates_p (code1, reversed_code2)))
2674 t1 = prev_nonnote_insn (b1);
2675 t2 = prev_nonnote_insn (b2);
2677 while (t1 != 0 && t2 != 0)
2681 /* We have reached the target of the first branch.
2682 If there are no pending register equivalents,
2683 we know that this branch will either always
2684 succeed (if the senses of the two branches are
2685 the same) or always fail (if not). */
2688 if (num_same_regs != 0)
2691 if (comparison_dominates_p (code1, code2))
2692 new_label = JUMP_LABEL (b2);
2694 new_label = get_label_after (b2);
2696 if (JUMP_LABEL (b1) != new_label)
2698 rtx prev = PREV_INSN (new_label);
2700 if (flag_before_loop
2701 && GET_CODE (prev) == NOTE
2702 && NOTE_LINE_NUMBER (prev) == NOTE_INSN_LOOP_BEG)
2704 /* Don't thread to the loop label. If a loop
2705 label is reused, loop optimization will
2706 be disabled for that loop. */
2707 new_label = gen_label_rtx ();
2708 emit_label_after (new_label, PREV_INSN (prev));
2710 changed |= redirect_jump (b1, new_label, 1);
2715 /* If either of these is not a normal insn (it might be
2716 a JUMP_INSN, CALL_INSN, or CODE_LABEL) we fail. (NOTEs
2717 have already been skipped above.) Similarly, fail
2718 if the insns are different. */
2719 if (GET_CODE (t1) != INSN || GET_CODE (t2) != INSN
2720 || recog_memoized (t1) != recog_memoized (t2)
2721 || ! rtx_equal_for_thread_p (PATTERN (t1),
2725 t1 = prev_nonnote_insn (t1);
2726 t2 = prev_nonnote_insn (t2);
2733 free (modified_regs);
2738 /* This is like RTX_EQUAL_P except that it knows about our handling of
2739 possibly equivalent registers and knows to consider volatile and
2740 modified objects as not equal.
2742 YINSN is the insn containing Y. */
2745 rtx_equal_for_thread_p (x, y, yinsn)
2751 register enum rtx_code code;
2752 register const char *fmt;
2754 code = GET_CODE (x);
2755 /* Rtx's of different codes cannot be equal. */
2756 if (code != GET_CODE (y))
2759 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
2760 (REG:SI x) and (REG:HI x) are NOT equivalent. */
2762 if (GET_MODE (x) != GET_MODE (y))
2765 /* For floating-point, consider everything unequal. This is a bit
2766 pessimistic, but this pass would only rarely do anything for FP
2768 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
2769 && FLOAT_MODE_P (GET_MODE (x)) && ! flag_unsafe_math_optimizations)
2772 /* For commutative operations, the RTX match if the operand match in any
2773 order. Also handle the simple binary and unary cases without a loop. */
2774 if (code == EQ || code == NE || GET_RTX_CLASS (code) == 'c')
2775 return ((rtx_equal_for_thread_p (XEXP (x, 0), XEXP (y, 0), yinsn)
2776 && rtx_equal_for_thread_p (XEXP (x, 1), XEXP (y, 1), yinsn))
2777 || (rtx_equal_for_thread_p (XEXP (x, 0), XEXP (y, 1), yinsn)
2778 && rtx_equal_for_thread_p (XEXP (x, 1), XEXP (y, 0), yinsn)));
2779 else if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == '2')
2780 return (rtx_equal_for_thread_p (XEXP (x, 0), XEXP (y, 0), yinsn)
2781 && rtx_equal_for_thread_p (XEXP (x, 1), XEXP (y, 1), yinsn));
2782 else if (GET_RTX_CLASS (code) == '1')
2783 return rtx_equal_for_thread_p (XEXP (x, 0), XEXP (y, 0), yinsn);
2785 /* Handle special-cases first. */
2789 if (REGNO (x) == REGNO (y) && ! modified_regs[REGNO (x)])
2792 /* If neither is user variable or hard register, check for possible
2794 if (REG_USERVAR_P (x) || REG_USERVAR_P (y)
2795 || REGNO (x) < FIRST_PSEUDO_REGISTER
2796 || REGNO (y) < FIRST_PSEUDO_REGISTER)
2799 if (same_regs[REGNO (x)] == -1)
2801 same_regs[REGNO (x)] = REGNO (y);
2804 /* If this is the first time we are seeing a register on the `Y'
2805 side, see if it is the last use. If not, we can't thread the
2806 jump, so mark it as not equivalent. */
2807 if (REGNO_LAST_UID (REGNO (y)) != INSN_UID (yinsn))
2813 return (same_regs[REGNO (x)] == (int) REGNO (y));
2818 /* If memory modified or either volatile, not equivalent.
2819 Else, check address. */
2820 if (modified_mem || MEM_VOLATILE_P (x) || MEM_VOLATILE_P (y))
2823 return rtx_equal_for_thread_p (XEXP (x, 0), XEXP (y, 0), yinsn);
2826 if (MEM_VOLATILE_P (x) || MEM_VOLATILE_P (y))
2832 /* Cancel a pending `same_regs' if setting equivalenced registers.
2833 Then process source. */
2834 if (GET_CODE (SET_DEST (x)) == REG
2835 && GET_CODE (SET_DEST (y)) == REG)
2837 if (same_regs[REGNO (SET_DEST (x))] == (int) REGNO (SET_DEST (y)))
2839 same_regs[REGNO (SET_DEST (x))] = -1;
2842 else if (REGNO (SET_DEST (x)) != REGNO (SET_DEST (y)))
2847 if (rtx_equal_for_thread_p (SET_DEST (x), SET_DEST (y), yinsn) == 0)
2851 return rtx_equal_for_thread_p (SET_SRC (x), SET_SRC (y), yinsn);
2854 return XEXP (x, 0) == XEXP (y, 0);
2857 return XSTR (x, 0) == XSTR (y, 0);
2866 fmt = GET_RTX_FORMAT (code);
2867 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2872 if (XWINT (x, i) != XWINT (y, i))
2878 if (XINT (x, i) != XINT (y, i))
2884 /* Two vectors must have the same length. */
2885 if (XVECLEN (x, i) != XVECLEN (y, i))
2888 /* And the corresponding elements must match. */
2889 for (j = 0; j < XVECLEN (x, i); j++)
2890 if (rtx_equal_for_thread_p (XVECEXP (x, i, j),
2891 XVECEXP (y, i, j), yinsn) == 0)
2896 if (rtx_equal_for_thread_p (XEXP (x, i), XEXP (y, i), yinsn) == 0)
2902 if (strcmp (XSTR (x, i), XSTR (y, i)))
2907 /* These are just backpointers, so they don't matter. */
2914 /* It is believed that rtx's at this level will never
2915 contain anything but integers and other rtx's,
2916 except for within LABEL_REFs and SYMBOL_REFs. */