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 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 delete_insn, 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"
57 /* Optimize jump y; x: ... y: jumpif... x?
58 Don't know if it is worth bothering with. */
59 /* Optimize two cases of conditional jump to conditional jump?
60 This can never delete any instruction or make anything dead,
61 or even change what is live at any point.
62 So perhaps let combiner do it. */
64 static rtx next_nonnote_insn_in_loop PARAMS ((rtx));
65 static void init_label_info PARAMS ((rtx));
66 static void mark_all_labels PARAMS ((rtx));
67 static int duplicate_loop_exit_test PARAMS ((rtx));
68 static void delete_computation PARAMS ((rtx));
69 static void redirect_exp_1 PARAMS ((rtx *, rtx, rtx, rtx));
70 static int redirect_exp PARAMS ((rtx, rtx, rtx));
71 static void invert_exp_1 PARAMS ((rtx));
72 static int invert_exp PARAMS ((rtx));
73 static int returnjump_p_1 PARAMS ((rtx *, void *));
74 static void delete_prior_computation PARAMS ((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 (f)
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))++;
97 /* Some old code expects exactly one BARRIER as the NEXT_INSN of a
98 non-fallthru insn. This is not generally true, as multiple barriers
99 may have crept in, or the BARRIER may be separated from the last
100 real insn by one or more NOTEs.
102 This simple pass moves barriers and removes duplicates so that the
108 rtx insn, next, prev;
109 for (insn = get_insns (); insn; insn = next)
111 next = NEXT_INSN (insn);
112 if (GET_CODE (insn) == BARRIER)
114 prev = prev_nonnote_insn (insn);
115 if (GET_CODE (prev) == BARRIER)
116 delete_barrier (insn);
117 else if (prev != PREV_INSN (insn))
118 reorder_insns (insn, insn, prev);
123 /* Return the next insn after INSN that is not a NOTE and is in the loop,
124 i.e. when there is no such INSN before NOTE_INSN_LOOP_END return NULL_RTX.
125 This routine does not look inside SEQUENCEs. */
128 next_nonnote_insn_in_loop (insn)
133 insn = NEXT_INSN (insn);
134 if (insn == 0 || GET_CODE (insn) != NOTE)
136 if (GET_CODE (insn) == NOTE
137 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
145 copy_loop_headers (f)
149 /* Now iterate optimizing jumps until nothing changes over one pass. */
150 for (insn = f; insn; insn = next)
154 next = NEXT_INSN (insn);
156 /* See if this is a NOTE_INSN_LOOP_BEG followed by an unconditional
157 jump. Try to optimize by duplicating the loop exit test if so.
158 This is only safe immediately after regscan, because it uses
159 the values of regno_first_uid and regno_last_uid. */
160 if (GET_CODE (insn) == NOTE
161 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
162 && (temp1 = next_nonnote_insn_in_loop (insn)) != 0
163 && any_uncondjump_p (temp1) && onlyjump_p (temp1))
165 temp = PREV_INSN (insn);
166 if (duplicate_loop_exit_test (insn))
168 next = NEXT_INSN (temp);
175 purge_line_number_notes (f)
180 /* Delete extraneous line number notes.
181 Note that two consecutive notes for different lines are not really
182 extraneous. There should be some indication where that line belonged,
183 even if it became empty. */
185 for (insn = f; insn; insn = NEXT_INSN (insn))
186 if (GET_CODE (insn) == NOTE)
188 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
189 /* Any previous line note was for the prologue; gdb wants a new
190 note after the prologue even if it is for the same line. */
191 last_note = NULL_RTX;
192 else if (NOTE_LINE_NUMBER (insn) >= 0)
194 /* Delete this note if it is identical to previous note. */
196 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last_note)
197 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last_note))
199 delete_related_insns (insn);
208 /* Initialize LABEL_NUSES and JUMP_LABEL fields. Delete any REG_LABEL
209 notes whose labels don't occur in the insn any more. Returns the
210 largest INSN_UID found. */
217 for (insn = f; insn; insn = NEXT_INSN (insn))
218 if (GET_CODE (insn) == CODE_LABEL)
219 LABEL_NUSES (insn) = (LABEL_PRESERVE_P (insn) != 0);
220 else if (GET_CODE (insn) == JUMP_INSN)
221 JUMP_LABEL (insn) = 0;
222 else if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN)
226 for (note = REG_NOTES (insn); note; note = next)
228 next = XEXP (note, 1);
229 if (REG_NOTE_KIND (note) == REG_LABEL
230 && ! reg_mentioned_p (XEXP (note, 0), PATTERN (insn)))
231 remove_note (insn, note);
236 /* Mark the label each jump jumps to.
237 Combine consecutive labels, and count uses of labels. */
245 for (insn = f; insn; insn = NEXT_INSN (insn))
248 if (GET_CODE (insn) == CALL_INSN
249 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
251 mark_all_labels (XEXP (PATTERN (insn), 0));
252 mark_all_labels (XEXP (PATTERN (insn), 1));
253 mark_all_labels (XEXP (PATTERN (insn), 2));
255 /* Canonicalize the tail recursion label attached to the
256 CALL_PLACEHOLDER insn. */
257 if (XEXP (PATTERN (insn), 3))
259 rtx label_ref = gen_rtx_LABEL_REF (VOIDmode,
260 XEXP (PATTERN (insn), 3));
261 mark_jump_label (label_ref, insn, 0);
262 XEXP (PATTERN (insn), 3) = XEXP (label_ref, 0);
268 mark_jump_label (PATTERN (insn), insn, 0);
269 if (! INSN_DELETED_P (insn) && GET_CODE (insn) == JUMP_INSN)
271 /* When we know the LABEL_REF contained in a REG used in
272 an indirect jump, we'll have a REG_LABEL note so that
273 flow can tell where it's going. */
274 if (JUMP_LABEL (insn) == 0)
276 rtx label_note = find_reg_note (insn, REG_LABEL, NULL_RTX);
279 /* But a LABEL_REF around the REG_LABEL note, so
280 that we can canonicalize it. */
281 rtx label_ref = gen_rtx_LABEL_REF (VOIDmode,
282 XEXP (label_note, 0));
284 mark_jump_label (label_ref, insn, 0);
285 XEXP (label_note, 0) = XEXP (label_ref, 0);
286 JUMP_LABEL (insn) = XEXP (label_note, 0);
293 /* LOOP_START is a NOTE_INSN_LOOP_BEG note that is followed by an unconditional
294 jump. Assume that this unconditional jump is to the exit test code. If
295 the code is sufficiently simple, make a copy of it before INSN,
296 followed by a jump to the exit of the loop. Then delete the unconditional
299 Return 1 if we made the change, else 0.
301 This is only safe immediately after a regscan pass because it uses the
302 values of regno_first_uid and regno_last_uid. */
305 duplicate_loop_exit_test (loop_start)
308 rtx insn, set, reg, p, link;
309 rtx copy = 0, first_copy = 0;
312 = NEXT_INSN (JUMP_LABEL (next_nonnote_insn_in_loop (loop_start)));
314 int max_reg = max_reg_num ();
316 rtx loop_pre_header_label;
318 /* Scan the exit code. We do not perform this optimization if any insn:
322 has a REG_RETVAL or REG_LIBCALL note (hard to adjust)
323 is a NOTE_INSN_LOOP_BEG because this means we have a nested loop
325 We also do not do this if we find an insn with ASM_OPERANDS. While
326 this restriction should not be necessary, copying an insn with
327 ASM_OPERANDS can confuse asm_noperands in some cases.
329 Also, don't do this if the exit code is more than 20 insns. */
331 for (insn = exitcode;
333 && ! (GET_CODE (insn) == NOTE
334 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END);
335 insn = NEXT_INSN (insn))
337 switch (GET_CODE (insn))
345 && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
346 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END))
347 /* If we were to duplicate this code, we would not move
348 the BLOCK notes, and so debugging the moved code would
349 be difficult. Thus, we only move the code with -O2 or
356 /* The code below would grossly mishandle REG_WAS_0 notes,
357 so get rid of them here. */
358 while ((p = find_reg_note (insn, REG_WAS_0, NULL_RTX)) != 0)
359 remove_note (insn, p);
361 || find_reg_note (insn, REG_RETVAL, NULL_RTX)
362 || find_reg_note (insn, REG_LIBCALL, NULL_RTX))
370 /* Unless INSN is zero, we can do the optimization. */
376 /* See if any insn sets a register only used in the loop exit code and
377 not a user variable. If so, replace it with a new register. */
378 for (insn = exitcode; insn != lastexit; insn = NEXT_INSN (insn))
379 if (GET_CODE (insn) == INSN
380 && (set = single_set (insn)) != 0
381 && ((reg = SET_DEST (set), GET_CODE (reg) == REG)
382 || (GET_CODE (reg) == SUBREG
383 && (reg = SUBREG_REG (reg), GET_CODE (reg) == REG)))
384 && REGNO (reg) >= FIRST_PSEUDO_REGISTER
385 && REGNO_FIRST_UID (REGNO (reg)) == INSN_UID (insn))
387 for (p = NEXT_INSN (insn); p != lastexit; p = NEXT_INSN (p))
388 if (REGNO_LAST_UID (REGNO (reg)) == INSN_UID (p))
393 /* We can do the replacement. Allocate reg_map if this is the
394 first replacement we found. */
396 reg_map = (rtx *) xcalloc (max_reg, sizeof (rtx));
398 REG_LOOP_TEST_P (reg) = 1;
400 reg_map[REGNO (reg)] = gen_reg_rtx (GET_MODE (reg));
403 loop_pre_header_label = gen_label_rtx ();
405 /* Now copy each insn. */
406 for (insn = exitcode; insn != lastexit; insn = NEXT_INSN (insn))
408 switch (GET_CODE (insn))
411 copy = emit_barrier_before (loop_start);
414 /* Only copy line-number notes. */
415 if (NOTE_LINE_NUMBER (insn) >= 0)
417 copy = emit_note_before (NOTE_LINE_NUMBER (insn), loop_start);
418 NOTE_SOURCE_FILE (copy) = NOTE_SOURCE_FILE (insn);
423 copy = emit_insn_before (copy_insn (PATTERN (insn)), loop_start);
425 replace_regs (PATTERN (copy), reg_map, max_reg, 1);
427 mark_jump_label (PATTERN (copy), copy, 0);
428 INSN_SCOPE (copy) = INSN_SCOPE (insn);
430 /* Copy all REG_NOTES except REG_LABEL since mark_jump_label will
432 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
433 if (REG_NOTE_KIND (link) != REG_LABEL)
435 if (GET_CODE (link) == EXPR_LIST)
437 = copy_insn_1 (gen_rtx_EXPR_LIST (REG_NOTE_KIND (link),
442 = copy_insn_1 (gen_rtx_INSN_LIST (REG_NOTE_KIND (link),
447 if (reg_map && REG_NOTES (copy))
448 replace_regs (REG_NOTES (copy), reg_map, max_reg, 1);
452 copy = emit_jump_insn_before (copy_insn (PATTERN (insn)),
454 INSN_SCOPE (copy) = INSN_SCOPE (insn);
456 replace_regs (PATTERN (copy), reg_map, max_reg, 1);
457 mark_jump_label (PATTERN (copy), copy, 0);
458 if (REG_NOTES (insn))
460 REG_NOTES (copy) = copy_insn_1 (REG_NOTES (insn));
462 replace_regs (REG_NOTES (copy), reg_map, max_reg, 1);
465 /* Predict conditional jump that do make loop looping as taken.
466 Other jumps are probably exit conditions, so predict
468 if (any_condjump_p (copy))
470 rtx label = JUMP_LABEL (copy);
473 /* The jump_insn after loop_start should be followed
474 by barrier and loopback label. */
475 if (prev_nonnote_insn (label)
476 && (prev_nonnote_insn (prev_nonnote_insn (label))
477 == next_nonnote_insn (loop_start)))
479 predict_insn_def (copy, PRED_LOOP_HEADER, TAKEN);
480 /* To keep pre-header, we need to redirect all loop
481 entrances before the LOOP_BEG note. */
482 redirect_jump (copy, loop_pre_header_label, 0);
485 predict_insn_def (copy, PRED_LOOP_HEADER, NOT_TAKEN);
494 /* Record the first insn we copied. We need it so that we can
495 scan the copied insns for new pseudo registers. */
500 /* Now clean up by emitting a jump to the end label and deleting the jump
501 at the start of the loop. */
502 if (! copy || GET_CODE (copy) != BARRIER)
504 copy = emit_jump_insn_before (gen_jump (get_label_after (insn)),
507 /* Record the first insn we copied. We need it so that we can
508 scan the copied insns for new pseudo registers. This may not
509 be strictly necessary since we should have copied at least one
510 insn above. But I am going to be safe. */
514 mark_jump_label (PATTERN (copy), copy, 0);
515 emit_barrier_before (loop_start);
518 emit_label_before (loop_pre_header_label, loop_start);
520 /* Now scan from the first insn we copied to the last insn we copied
521 (copy) for new pseudo registers. Do this after the code to jump to
522 the end label since that might create a new pseudo too. */
523 reg_scan_update (first_copy, copy, max_reg);
525 /* Mark the exit code as the virtual top of the converted loop. */
526 emit_note_before (NOTE_INSN_LOOP_VTOP, exitcode);
528 delete_related_insns (next_nonnote_insn (loop_start));
537 /* Move all block-beg, block-end, loop-beg, loop-cont, loop-vtop, loop-end,
538 notes between START and END out before START. START and END may be such
539 notes. Returns the values of the new starting and ending insns, which
540 may be different if the original ones were such notes.
541 Return true if there were only such notes and no real instructions. */
544 squeeze_notes (startp, endp)
554 rtx past_end = NEXT_INSN (end);
556 for (insn = start; insn != past_end; insn = next)
558 next = NEXT_INSN (insn);
559 if (GET_CODE (insn) == NOTE
560 && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
561 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
562 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
563 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END
564 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_CONT
565 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_VTOP))
571 rtx prev = PREV_INSN (insn);
572 PREV_INSN (insn) = PREV_INSN (start);
573 NEXT_INSN (insn) = start;
574 NEXT_INSN (PREV_INSN (insn)) = insn;
575 PREV_INSN (NEXT_INSN (insn)) = insn;
576 NEXT_INSN (prev) = next;
577 PREV_INSN (next) = prev;
584 /* There were no real instructions. */
585 if (start == past_end)
595 /* Return the label before INSN, or put a new label there. */
598 get_label_before (insn)
603 /* Find an existing label at this point
604 or make a new one if there is none. */
605 label = prev_nonnote_insn (insn);
607 if (label == 0 || GET_CODE (label) != CODE_LABEL)
609 rtx prev = PREV_INSN (insn);
611 label = gen_label_rtx ();
612 emit_label_after (label, prev);
613 LABEL_NUSES (label) = 0;
618 /* Return the label after INSN, or put a new label there. */
621 get_label_after (insn)
626 /* Find an existing label at this point
627 or make a new one if there is none. */
628 label = next_nonnote_insn (insn);
630 if (label == 0 || GET_CODE (label) != CODE_LABEL)
632 label = gen_label_rtx ();
633 emit_label_after (label, insn);
634 LABEL_NUSES (label) = 0;
639 /* Given a comparison (CODE ARG0 ARG1), inside an insn, INSN, return a code
640 of reversed comparison if it is possible to do so. Otherwise return UNKNOWN.
641 UNKNOWN may be returned in case we are having CC_MODE compare and we don't
642 know whether it's source is floating point or integer comparison. Machine
643 description should define REVERSIBLE_CC_MODE and REVERSE_CONDITION macros
644 to help this function avoid overhead in these cases. */
646 reversed_comparison_code_parts (code, arg0, arg1, insn)
647 rtx insn, arg0, arg1;
650 enum machine_mode mode;
652 /* If this is not actually a comparison, we can't reverse it. */
653 if (GET_RTX_CLASS (code) != '<')
656 mode = GET_MODE (arg0);
657 if (mode == VOIDmode)
658 mode = GET_MODE (arg1);
660 /* First see if machine description supply us way to reverse the comparison.
661 Give it priority over everything else to allow machine description to do
663 #ifdef REVERSIBLE_CC_MODE
664 if (GET_MODE_CLASS (mode) == MODE_CC
665 && REVERSIBLE_CC_MODE (mode))
667 #ifdef REVERSE_CONDITION
668 return REVERSE_CONDITION (code, mode);
670 return reverse_condition (code);
674 /* Try a few special cases based on the comparison code. */
683 /* It is always safe to reverse EQ and NE, even for the floating
684 point. Similary the unsigned comparisons are never used for
685 floating point so we can reverse them in the default way. */
686 return reverse_condition (code);
691 /* In case we already see unordered comparison, we can be sure to
692 be dealing with floating point so we don't need any more tests. */
693 return reverse_condition_maybe_unordered (code);
698 /* We don't have safe way to reverse these yet. */
704 if (GET_MODE_CLASS (mode) == MODE_CC || CC0_P (arg0))
707 /* Try to search for the comparison to determine the real mode.
708 This code is expensive, but with sane machine description it
709 will be never used, since REVERSIBLE_CC_MODE will return true
714 for (prev = prev_nonnote_insn (insn);
715 prev != 0 && GET_CODE (prev) != CODE_LABEL;
716 prev = prev_nonnote_insn (prev))
718 rtx set = set_of (arg0, prev);
719 if (set && GET_CODE (set) == SET
720 && rtx_equal_p (SET_DEST (set), arg0))
722 rtx src = SET_SRC (set);
724 if (GET_CODE (src) == COMPARE)
726 rtx comparison = src;
727 arg0 = XEXP (src, 0);
728 mode = GET_MODE (arg0);
729 if (mode == VOIDmode)
730 mode = GET_MODE (XEXP (comparison, 1));
733 /* We can get past reg-reg moves. This may be useful for model
734 of i387 comparisons that first move flag registers around. */
741 /* If register is clobbered in some ununderstandable way,
748 /* Test for an integer condition, or a floating-point comparison
749 in which NaNs can be ignored. */
750 if (GET_CODE (arg0) == CONST_INT
751 || (GET_MODE (arg0) != VOIDmode
752 && GET_MODE_CLASS (mode) != MODE_CC
753 && !HONOR_NANS (mode)))
754 return reverse_condition (code);
759 /* An wrapper around the previous function to take COMPARISON as rtx
760 expression. This simplifies many callers. */
762 reversed_comparison_code (comparison, insn)
763 rtx comparison, insn;
765 if (GET_RTX_CLASS (GET_CODE (comparison)) != '<')
767 return reversed_comparison_code_parts (GET_CODE (comparison),
768 XEXP (comparison, 0),
769 XEXP (comparison, 1), insn);
772 /* Given an rtx-code for a comparison, return the code for the negated
773 comparison. If no such code exists, return UNKNOWN.
775 WATCH OUT! reverse_condition is not safe to use on a jump that might
776 be acting on the results of an IEEE floating point comparison, because
777 of the special treatment of non-signaling nans in comparisons.
778 Use reversed_comparison_code instead. */
781 reverse_condition (code)
824 /* Similar, but we're allowed to generate unordered comparisons, which
825 makes it safe for IEEE floating-point. Of course, we have to recognize
826 that the target will support them too... */
829 reverse_condition_maybe_unordered (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 nonzero 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 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 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;
1232 return x && (GET_CODE (x) == RETURN
1233 || (GET_CODE (x) == SET && SET_IS_RETURN_P (x)));
1240 if (GET_CODE (insn) != JUMP_INSN)
1242 return for_each_rtx (&PATTERN (insn), returnjump_p_1, NULL);
1245 /* Return true if INSN is a jump that only transfers control and
1254 if (GET_CODE (insn) != JUMP_INSN)
1257 set = single_set (insn);
1260 if (GET_CODE (SET_DEST (set)) != PC)
1262 if (side_effects_p (SET_SRC (set)))
1270 /* Return nonzero if X is an RTX that only sets the condition codes
1271 and has no side effects. */
1284 return sets_cc0_p (x) == 1 && ! side_effects_p (x);
1287 /* Return 1 if X is an RTX that does nothing but set the condition codes
1288 and CLOBBER or USE registers.
1289 Return -1 if X does explicitly set the condition codes,
1290 but also does other things. */
1303 if (GET_CODE (x) == SET && SET_DEST (x) == cc0_rtx)
1305 if (GET_CODE (x) == PARALLEL)
1309 int other_things = 0;
1310 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1312 if (GET_CODE (XVECEXP (x, 0, i)) == SET
1313 && SET_DEST (XVECEXP (x, 0, i)) == cc0_rtx)
1315 else if (GET_CODE (XVECEXP (x, 0, i)) == SET)
1318 return ! sets_cc0 ? 0 : other_things ? -1 : 1;
1324 /* Follow any unconditional jump at LABEL;
1325 return the ultimate label reached by any such chain of jumps.
1326 If LABEL is not followed by a jump, return LABEL.
1327 If the chain loops or we can't find end, return LABEL,
1328 since that tells caller to avoid changing the insn.
1330 If RELOAD_COMPLETED is 0, we do not chain across a NOTE_INSN_LOOP_BEG or
1331 a USE or CLOBBER. */
1334 follow_jumps (label)
1344 && (insn = next_active_insn (value)) != 0
1345 && GET_CODE (insn) == JUMP_INSN
1346 && ((JUMP_LABEL (insn) != 0 && any_uncondjump_p (insn)
1347 && onlyjump_p (insn))
1348 || GET_CODE (PATTERN (insn)) == RETURN)
1349 && (next = NEXT_INSN (insn))
1350 && GET_CODE (next) == BARRIER);
1353 /* Don't chain through the insn that jumps into a loop
1354 from outside the loop,
1355 since that would create multiple loop entry jumps
1356 and prevent loop optimization. */
1358 if (!reload_completed)
1359 for (tem = value; tem != insn; tem = NEXT_INSN (tem))
1360 if (GET_CODE (tem) == NOTE
1361 && (NOTE_LINE_NUMBER (tem) == NOTE_INSN_LOOP_BEG
1362 /* ??? Optional. Disables some optimizations, but makes
1363 gcov output more accurate with -O. */
1364 || (flag_test_coverage && NOTE_LINE_NUMBER (tem) > 0)))
1367 /* If we have found a cycle, make the insn jump to itself. */
1368 if (JUMP_LABEL (insn) == label)
1371 tem = next_active_insn (JUMP_LABEL (insn));
1372 if (tem && (GET_CODE (PATTERN (tem)) == ADDR_VEC
1373 || GET_CODE (PATTERN (tem)) == ADDR_DIFF_VEC))
1376 value = JUMP_LABEL (insn);
1384 /* Find all CODE_LABELs referred to in X, and increment their use counts.
1385 If INSN is a JUMP_INSN and there is at least one CODE_LABEL referenced
1386 in INSN, then store one of them in JUMP_LABEL (INSN).
1387 If INSN is an INSN or a CALL_INSN and there is at least one CODE_LABEL
1388 referenced in INSN, add a REG_LABEL note containing that label to INSN.
1389 Also, when there are consecutive labels, canonicalize on the last of them.
1391 Note that two labels separated by a loop-beginning note
1392 must be kept distinct if we have not yet done loop-optimization,
1393 because the gap between them is where loop-optimize
1394 will want to move invariant code to. CROSS_JUMP tells us
1395 that loop-optimization is done with. */
1398 mark_jump_label (x, insn, in_mem)
1403 RTX_CODE code = GET_CODE (x);
1426 /* If this is a constant-pool reference, see if it is a label. */
1427 if (CONSTANT_POOL_ADDRESS_P (x))
1428 mark_jump_label (get_pool_constant (x), insn, in_mem);
1433 rtx label = XEXP (x, 0);
1435 /* Ignore remaining references to unreachable labels that
1436 have been deleted. */
1437 if (GET_CODE (label) == NOTE
1438 && NOTE_LINE_NUMBER (label) == NOTE_INSN_DELETED_LABEL)
1441 if (GET_CODE (label) != CODE_LABEL)
1444 /* Ignore references to labels of containing functions. */
1445 if (LABEL_REF_NONLOCAL_P (x))
1448 XEXP (x, 0) = label;
1449 if (! insn || ! INSN_DELETED_P (insn))
1450 ++LABEL_NUSES (label);
1454 if (GET_CODE (insn) == JUMP_INSN)
1455 JUMP_LABEL (insn) = label;
1458 /* Add a REG_LABEL note for LABEL unless there already
1459 is one. All uses of a label, except for labels
1460 that are the targets of jumps, must have a
1462 if (! find_reg_note (insn, REG_LABEL, label))
1463 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL, label,
1470 /* Do walk the labels in a vector, but not the first operand of an
1471 ADDR_DIFF_VEC. Don't set the JUMP_LABEL of a vector. */
1474 if (! INSN_DELETED_P (insn))
1476 int eltnum = code == ADDR_DIFF_VEC ? 1 : 0;
1478 for (i = 0; i < XVECLEN (x, eltnum); i++)
1479 mark_jump_label (XVECEXP (x, eltnum, i), NULL_RTX, in_mem);
1487 fmt = GET_RTX_FORMAT (code);
1488 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1491 mark_jump_label (XEXP (x, i), insn, in_mem);
1492 else if (fmt[i] == 'E')
1495 for (j = 0; j < XVECLEN (x, i); j++)
1496 mark_jump_label (XVECEXP (x, i, j), insn, in_mem);
1501 /* If all INSN does is set the pc, delete it,
1502 and delete the insn that set the condition codes for it
1503 if that's what the previous thing was. */
1509 rtx set = single_set (insn);
1511 if (set && GET_CODE (SET_DEST (set)) == PC)
1512 delete_computation (insn);
1515 /* Verify INSN is a BARRIER and delete it. */
1518 delete_barrier (insn)
1521 if (GET_CODE (insn) != BARRIER)
1527 /* Recursively delete prior insns that compute the value (used only by INSN
1528 which the caller is deleting) stored in the register mentioned by NOTE
1529 which is a REG_DEAD note associated with INSN. */
1532 delete_prior_computation (note, insn)
1537 rtx reg = XEXP (note, 0);
1539 for (our_prev = prev_nonnote_insn (insn);
1540 our_prev && (GET_CODE (our_prev) == INSN
1541 || GET_CODE (our_prev) == CALL_INSN);
1542 our_prev = prev_nonnote_insn (our_prev))
1544 rtx pat = PATTERN (our_prev);
1546 /* If we reach a CALL which is not calling a const function
1547 or the callee pops the arguments, then give up. */
1548 if (GET_CODE (our_prev) == CALL_INSN
1549 && (! CONST_OR_PURE_CALL_P (our_prev)
1550 || GET_CODE (pat) != SET || GET_CODE (SET_SRC (pat)) != CALL))
1553 /* If we reach a SEQUENCE, it is too complex to try to
1554 do anything with it, so give up. We can be run during
1555 and after reorg, so SEQUENCE rtl can legitimately show
1557 if (GET_CODE (pat) == SEQUENCE)
1560 if (GET_CODE (pat) == USE
1561 && GET_CODE (XEXP (pat, 0)) == INSN)
1562 /* reorg creates USEs that look like this. We leave them
1563 alone because reorg needs them for its own purposes. */
1566 if (reg_set_p (reg, pat))
1568 if (side_effects_p (pat) && GET_CODE (our_prev) != CALL_INSN)
1571 if (GET_CODE (pat) == PARALLEL)
1573 /* If we find a SET of something else, we can't
1578 for (i = 0; i < XVECLEN (pat, 0); i++)
1580 rtx part = XVECEXP (pat, 0, i);
1582 if (GET_CODE (part) == SET
1583 && SET_DEST (part) != reg)
1587 if (i == XVECLEN (pat, 0))
1588 delete_computation (our_prev);
1590 else if (GET_CODE (pat) == SET
1591 && GET_CODE (SET_DEST (pat)) == REG)
1593 int dest_regno = REGNO (SET_DEST (pat));
1596 + (dest_regno < FIRST_PSEUDO_REGISTER
1597 ? HARD_REGNO_NREGS (dest_regno,
1598 GET_MODE (SET_DEST (pat))) : 1));
1599 int regno = REGNO (reg);
1602 + (regno < FIRST_PSEUDO_REGISTER
1603 ? HARD_REGNO_NREGS (regno, GET_MODE (reg)) : 1));
1605 if (dest_regno >= regno
1606 && dest_endregno <= endregno)
1607 delete_computation (our_prev);
1609 /* We may have a multi-word hard register and some, but not
1610 all, of the words of the register are needed in subsequent
1611 insns. Write REG_UNUSED notes for those parts that were not
1613 else if (dest_regno <= regno
1614 && dest_endregno >= endregno)
1618 REG_NOTES (our_prev)
1619 = gen_rtx_EXPR_LIST (REG_UNUSED, reg,
1620 REG_NOTES (our_prev));
1622 for (i = dest_regno; i < dest_endregno; i++)
1623 if (! find_regno_note (our_prev, REG_UNUSED, i))
1626 if (i == dest_endregno)
1627 delete_computation (our_prev);
1634 /* If PAT references the register that dies here, it is an
1635 additional use. Hence any prior SET isn't dead. However, this
1636 insn becomes the new place for the REG_DEAD note. */
1637 if (reg_overlap_mentioned_p (reg, pat))
1639 XEXP (note, 1) = REG_NOTES (our_prev);
1640 REG_NOTES (our_prev) = note;
1646 /* Delete INSN and recursively delete insns that compute values used only
1647 by INSN. This uses the REG_DEAD notes computed during flow analysis.
1648 If we are running before flow.c, we need do nothing since flow.c will
1649 delete dead code. We also can't know if the registers being used are
1650 dead or not at this point.
1652 Otherwise, look at all our REG_DEAD notes. If a previous insn does
1653 nothing other than set a register that dies in this insn, we can delete
1656 On machines with CC0, if CC0 is used in this insn, we may be able to
1657 delete the insn that set it. */
1660 delete_computation (insn)
1666 if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
1668 rtx prev = prev_nonnote_insn (insn);
1669 /* We assume that at this stage
1670 CC's are always set explicitly
1671 and always immediately before the jump that
1672 will use them. So if the previous insn
1673 exists to set the CC's, delete it
1674 (unless it performs auto-increments, etc.). */
1675 if (prev && GET_CODE (prev) == INSN
1676 && sets_cc0_p (PATTERN (prev)))
1678 if (sets_cc0_p (PATTERN (prev)) > 0
1679 && ! side_effects_p (PATTERN (prev)))
1680 delete_computation (prev);
1682 /* Otherwise, show that cc0 won't be used. */
1683 REG_NOTES (prev) = gen_rtx_EXPR_LIST (REG_UNUSED,
1684 cc0_rtx, REG_NOTES (prev));
1689 for (note = REG_NOTES (insn); note; note = next)
1691 next = XEXP (note, 1);
1693 if (REG_NOTE_KIND (note) != REG_DEAD
1694 /* Verify that the REG_NOTE is legitimate. */
1695 || GET_CODE (XEXP (note, 0)) != REG)
1698 delete_prior_computation (note, insn);
1701 delete_related_insns (insn);
1704 /* Delete insn INSN from the chain of insns and update label ref counts
1705 and delete insns now unreachable.
1707 Returns the first insn after INSN that was not deleted.
1709 Usage of this instruction is deprecated. Use delete_insn instead and
1710 subsequent cfg_cleanup pass to delete unreachable code if needed. */
1713 delete_related_insns (insn)
1716 int was_code_label = (GET_CODE (insn) == CODE_LABEL);
1718 rtx next = NEXT_INSN (insn), prev = PREV_INSN (insn);
1720 while (next && INSN_DELETED_P (next))
1721 next = NEXT_INSN (next);
1723 /* This insn is already deleted => return first following nondeleted. */
1724 if (INSN_DELETED_P (insn))
1729 /* If instruction is followed by a barrier,
1730 delete the barrier too. */
1732 if (next != 0 && GET_CODE (next) == BARRIER)
1735 /* If deleting a jump, decrement the count of the label,
1736 and delete the label if it is now unused. */
1738 if (GET_CODE (insn) == JUMP_INSN && JUMP_LABEL (insn))
1740 rtx lab = JUMP_LABEL (insn), lab_next;
1742 if (LABEL_NUSES (lab) == 0)
1744 /* This can delete NEXT or PREV,
1745 either directly if NEXT is JUMP_LABEL (INSN),
1746 or indirectly through more levels of jumps. */
1747 delete_related_insns (lab);
1749 /* I feel a little doubtful about this loop,
1750 but I see no clean and sure alternative way
1751 to find the first insn after INSN that is not now deleted.
1752 I hope this works. */
1753 while (next && INSN_DELETED_P (next))
1754 next = NEXT_INSN (next);
1757 else if ((lab_next = next_nonnote_insn (lab)) != NULL
1758 && GET_CODE (lab_next) == JUMP_INSN
1759 && (GET_CODE (PATTERN (lab_next)) == ADDR_VEC
1760 || GET_CODE (PATTERN (lab_next)) == ADDR_DIFF_VEC))
1762 /* If we're deleting the tablejump, delete the dispatch table.
1763 We may not be able to kill the label immediately preceding
1764 just yet, as it might be referenced in code leading up to
1766 delete_related_insns (lab_next);
1770 /* Likewise if we're deleting a dispatch table. */
1772 if (GET_CODE (insn) == JUMP_INSN
1773 && (GET_CODE (PATTERN (insn)) == ADDR_VEC
1774 || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC))
1776 rtx pat = PATTERN (insn);
1777 int i, diff_vec_p = GET_CODE (pat) == ADDR_DIFF_VEC;
1778 int len = XVECLEN (pat, diff_vec_p);
1780 for (i = 0; i < len; i++)
1781 if (LABEL_NUSES (XEXP (XVECEXP (pat, diff_vec_p, i), 0)) == 0)
1782 delete_related_insns (XEXP (XVECEXP (pat, diff_vec_p, i), 0));
1783 while (next && INSN_DELETED_P (next))
1784 next = NEXT_INSN (next);
1788 /* Likewise for an ordinary INSN / CALL_INSN with a REG_LABEL note. */
1789 if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN)
1790 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1791 if (REG_NOTE_KIND (note) == REG_LABEL
1792 /* This could also be a NOTE_INSN_DELETED_LABEL note. */
1793 && GET_CODE (XEXP (note, 0)) == CODE_LABEL)
1794 if (LABEL_NUSES (XEXP (note, 0)) == 0)
1795 delete_related_insns (XEXP (note, 0));
1797 while (prev && (INSN_DELETED_P (prev) || GET_CODE (prev) == NOTE))
1798 prev = PREV_INSN (prev);
1800 /* If INSN was a label and a dispatch table follows it,
1801 delete the dispatch table. The tablejump must have gone already.
1802 It isn't useful to fall through into a table. */
1805 && NEXT_INSN (insn) != 0
1806 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN
1807 && (GET_CODE (PATTERN (NEXT_INSN (insn))) == ADDR_VEC
1808 || GET_CODE (PATTERN (NEXT_INSN (insn))) == ADDR_DIFF_VEC))
1809 next = delete_related_insns (NEXT_INSN (insn));
1811 /* If INSN was a label, delete insns following it if now unreachable. */
1813 if (was_code_label && prev && GET_CODE (prev) == BARRIER)
1817 && (GET_RTX_CLASS (code = GET_CODE (next)) == 'i'
1818 || code == NOTE || code == BARRIER
1819 || (code == CODE_LABEL && INSN_DELETED_P (next))))
1822 && NOTE_LINE_NUMBER (next) != NOTE_INSN_FUNCTION_END)
1823 next = NEXT_INSN (next);
1824 /* Keep going past other deleted labels to delete what follows. */
1825 else if (code == CODE_LABEL && INSN_DELETED_P (next))
1826 next = NEXT_INSN (next);
1828 /* Note: if this deletes a jump, it can cause more
1829 deletion of unreachable code, after a different label.
1830 As long as the value from this recursive call is correct,
1831 this invocation functions correctly. */
1832 next = delete_related_insns (next);
1839 /* Advance from INSN till reaching something not deleted
1840 then return that. May return INSN itself. */
1843 next_nondeleted_insn (insn)
1846 while (INSN_DELETED_P (insn))
1847 insn = NEXT_INSN (insn);
1851 /* Delete a range of insns from FROM to TO, inclusive.
1852 This is for the sake of peephole optimization, so assume
1853 that whatever these insns do will still be done by a new
1854 peephole insn that will replace them. */
1857 delete_for_peephole (from, to)
1864 rtx next = NEXT_INSN (insn);
1865 rtx prev = PREV_INSN (insn);
1867 if (GET_CODE (insn) != NOTE)
1869 INSN_DELETED_P (insn) = 1;
1871 /* Patch this insn out of the chain. */
1872 /* We don't do this all at once, because we
1873 must preserve all NOTEs. */
1875 NEXT_INSN (prev) = next;
1878 PREV_INSN (next) = prev;
1886 /* Note that if TO is an unconditional jump
1887 we *do not* delete the BARRIER that follows,
1888 since the peephole that replaces this sequence
1889 is also an unconditional jump in that case. */
1892 /* We have determined that AVOIDED_INSN is never reached, and are
1893 about to delete it. If the insn chain between AVOIDED_INSN and
1894 FINISH contains more than one line from the current function, and
1895 contains at least one operation, print a warning if the user asked
1896 for it. If FINISH is NULL, look between AVOIDED_INSN and a LABEL.
1898 CSE and inlining can duplicate insns, so it's possible to get
1899 spurious warnings from this. */
1902 never_reached_warning (avoided_insn, finish)
1903 rtx avoided_insn, finish;
1906 rtx a_line_note = NULL;
1907 int two_avoided_lines = 0, contains_insn = 0, reached_end = 0;
1909 if (!warn_notreached)
1912 /* Scan forwards, looking at LINE_NUMBER notes, until we hit a LABEL
1913 in case FINISH is NULL, otherwise until we run out of insns. */
1915 for (insn = avoided_insn; insn != NULL; insn = NEXT_INSN (insn))
1917 if ((finish == NULL && GET_CODE (insn) == CODE_LABEL)
1918 || GET_CODE (insn) == BARRIER)
1921 if (GET_CODE (insn) == NOTE /* A line number note? */
1922 && NOTE_LINE_NUMBER (insn) >= 0)
1924 if (a_line_note == NULL)
1927 two_avoided_lines |= (NOTE_LINE_NUMBER (a_line_note)
1928 != NOTE_LINE_NUMBER (insn));
1930 else if (INSN_P (insn))
1932 if (reached_end || a_line_note == NULL)
1940 if (two_avoided_lines && contains_insn)
1941 warning_with_file_and_line (NOTE_SOURCE_FILE (a_line_note),
1942 NOTE_LINE_NUMBER (a_line_note),
1943 "will never be executed");
1946 /* Throughout LOC, redirect OLABEL to NLABEL. Treat null OLABEL or
1947 NLABEL as a return. Accrue modifications into the change group. */
1950 redirect_exp_1 (loc, olabel, nlabel, insn)
1956 RTX_CODE code = GET_CODE (x);
1960 if (code == LABEL_REF)
1962 if (XEXP (x, 0) == olabel)
1966 n = gen_rtx_LABEL_REF (VOIDmode, nlabel);
1968 n = gen_rtx_RETURN (VOIDmode);
1970 validate_change (insn, loc, n, 1);
1974 else if (code == RETURN && olabel == 0)
1976 x = gen_rtx_LABEL_REF (VOIDmode, nlabel);
1977 if (loc == &PATTERN (insn))
1978 x = gen_rtx_SET (VOIDmode, pc_rtx, x);
1979 validate_change (insn, loc, x, 1);
1983 if (code == SET && nlabel == 0 && SET_DEST (x) == pc_rtx
1984 && GET_CODE (SET_SRC (x)) == LABEL_REF
1985 && XEXP (SET_SRC (x), 0) == olabel)
1987 validate_change (insn, loc, gen_rtx_RETURN (VOIDmode), 1);
1991 fmt = GET_RTX_FORMAT (code);
1992 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1995 redirect_exp_1 (&XEXP (x, i), olabel, nlabel, insn);
1996 else if (fmt[i] == 'E')
1999 for (j = 0; j < XVECLEN (x, i); j++)
2000 redirect_exp_1 (&XVECEXP (x, i, j), olabel, nlabel, insn);
2005 /* Similar, but apply the change group and report success or failure. */
2008 redirect_exp (olabel, nlabel, insn)
2014 if (GET_CODE (PATTERN (insn)) == PARALLEL)
2015 loc = &XVECEXP (PATTERN (insn), 0, 0);
2017 loc = &PATTERN (insn);
2019 redirect_exp_1 (loc, olabel, nlabel, insn);
2020 if (num_validated_changes () == 0)
2023 return apply_change_group ();
2026 /* Make JUMP go to NLABEL instead of where it jumps now. Accrue
2027 the modifications into the change group. Return false if we did
2028 not see how to do that. */
2031 redirect_jump_1 (jump, nlabel)
2034 int ochanges = num_validated_changes ();
2037 if (GET_CODE (PATTERN (jump)) == PARALLEL)
2038 loc = &XVECEXP (PATTERN (jump), 0, 0);
2040 loc = &PATTERN (jump);
2042 redirect_exp_1 (loc, JUMP_LABEL (jump), nlabel, jump);
2043 return num_validated_changes () > ochanges;
2046 /* Make JUMP go to NLABEL instead of where it jumps now. If the old
2047 jump target label is unused as a result, it and the code following
2050 If NLABEL is zero, we are to turn the jump into a (possibly conditional)
2053 The return value will be 1 if the change was made, 0 if it wasn't
2054 (this can only occur for NLABEL == 0). */
2057 redirect_jump (jump, nlabel, delete_unused)
2061 rtx olabel = JUMP_LABEL (jump);
2063 if (nlabel == olabel)
2066 if (! redirect_exp (olabel, nlabel, jump))
2069 JUMP_LABEL (jump) = nlabel;
2071 ++LABEL_NUSES (nlabel);
2073 /* If we're eliding the jump over exception cleanups at the end of a
2074 function, move the function end note so that -Wreturn-type works. */
2075 if (olabel && nlabel
2076 && NEXT_INSN (olabel)
2077 && GET_CODE (NEXT_INSN (olabel)) == NOTE
2078 && NOTE_LINE_NUMBER (NEXT_INSN (olabel)) == NOTE_INSN_FUNCTION_END)
2079 emit_note_after (NOTE_INSN_FUNCTION_END, nlabel);
2081 if (olabel && --LABEL_NUSES (olabel) == 0 && delete_unused
2082 /* Undefined labels will remain outside the insn stream. */
2083 && INSN_UID (olabel))
2084 delete_related_insns (olabel);
2089 /* Invert the jump condition of rtx X contained in jump insn, INSN.
2090 Accrue the modifications into the change group. */
2097 rtx x = pc_set (insn);
2103 code = GET_CODE (x);
2105 if (code == IF_THEN_ELSE)
2107 rtx comp = XEXP (x, 0);
2109 enum rtx_code reversed_code;
2111 /* We can do this in two ways: The preferable way, which can only
2112 be done if this is not an integer comparison, is to reverse
2113 the comparison code. Otherwise, swap the THEN-part and ELSE-part
2114 of the IF_THEN_ELSE. If we can't do either, fail. */
2116 reversed_code = reversed_comparison_code (comp, insn);
2118 if (reversed_code != UNKNOWN)
2120 validate_change (insn, &XEXP (x, 0),
2121 gen_rtx_fmt_ee (reversed_code,
2122 GET_MODE (comp), XEXP (comp, 0),
2129 validate_change (insn, &XEXP (x, 1), XEXP (x, 2), 1);
2130 validate_change (insn, &XEXP (x, 2), tem, 1);
2136 /* Invert the jump condition of conditional jump insn, INSN.
2138 Return 1 if we can do so, 0 if we cannot find a way to do so that
2139 matches a pattern. */
2145 invert_exp_1 (insn);
2146 if (num_validated_changes () == 0)
2149 return apply_change_group ();
2152 /* Invert the condition of the jump JUMP, and make it jump to label
2153 NLABEL instead of where it jumps now. Accrue changes into the
2154 change group. Return false if we didn't see how to perform the
2155 inversion and redirection. */
2158 invert_jump_1 (jump, nlabel)
2163 ochanges = num_validated_changes ();
2164 invert_exp_1 (jump);
2165 if (num_validated_changes () == ochanges)
2168 return redirect_jump_1 (jump, nlabel);
2171 /* Invert the condition of the jump JUMP, and make it jump to label
2172 NLABEL instead of where it jumps now. Return true if successful. */
2175 invert_jump (jump, nlabel, delete_unused)
2179 /* We have to either invert the condition and change the label or
2180 do neither. Either operation could fail. We first try to invert
2181 the jump. If that succeeds, we try changing the label. If that fails,
2182 we invert the jump back to what it was. */
2184 if (! invert_exp (jump))
2187 if (redirect_jump (jump, nlabel, delete_unused))
2189 invert_br_probabilities (jump);
2194 if (! invert_exp (jump))
2195 /* This should just be putting it back the way it was. */
2202 /* Like rtx_equal_p except that it considers two REGs as equal
2203 if they renumber to the same value and considers two commutative
2204 operations to be the same if the order of the operands has been
2207 ??? Addition is not commutative on the PA due to the weird implicit
2208 space register selection rules for memory addresses. Therefore, we
2209 don't consider a + b == b + a.
2211 We could/should make this test a little tighter. Possibly only
2212 disabling it on the PA via some backend macro or only disabling this
2213 case when the PLUS is inside a MEM. */
2216 rtx_renumbered_equal_p (x, y)
2220 RTX_CODE code = GET_CODE (x);
2226 if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
2227 && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
2228 && GET_CODE (SUBREG_REG (y)) == REG)))
2230 int reg_x = -1, reg_y = -1;
2231 int byte_x = 0, byte_y = 0;
2233 if (GET_MODE (x) != GET_MODE (y))
2236 /* If we haven't done any renumbering, don't
2237 make any assumptions. */
2238 if (reg_renumber == 0)
2239 return rtx_equal_p (x, y);
2243 reg_x = REGNO (SUBREG_REG (x));
2244 byte_x = SUBREG_BYTE (x);
2246 if (reg_renumber[reg_x] >= 0)
2248 reg_x = subreg_regno_offset (reg_renumber[reg_x],
2249 GET_MODE (SUBREG_REG (x)),
2258 if (reg_renumber[reg_x] >= 0)
2259 reg_x = reg_renumber[reg_x];
2262 if (GET_CODE (y) == SUBREG)
2264 reg_y = REGNO (SUBREG_REG (y));
2265 byte_y = SUBREG_BYTE (y);
2267 if (reg_renumber[reg_y] >= 0)
2269 reg_y = subreg_regno_offset (reg_renumber[reg_y],
2270 GET_MODE (SUBREG_REG (y)),
2279 if (reg_renumber[reg_y] >= 0)
2280 reg_y = reg_renumber[reg_y];
2283 return reg_x >= 0 && reg_x == reg_y && byte_x == byte_y;
2286 /* Now we have disposed of all the cases
2287 in which different rtx codes can match. */
2288 if (code != GET_CODE (y))
2300 return INTVAL (x) == INTVAL (y);
2303 /* We can't assume nonlocal labels have their following insns yet. */
2304 if (LABEL_REF_NONLOCAL_P (x) || LABEL_REF_NONLOCAL_P (y))
2305 return XEXP (x, 0) == XEXP (y, 0);
2307 /* Two label-refs are equivalent if they point at labels
2308 in the same position in the instruction stream. */
2309 return (next_real_insn (XEXP (x, 0))
2310 == next_real_insn (XEXP (y, 0)));
2313 return XSTR (x, 0) == XSTR (y, 0);
2316 /* If we didn't match EQ equality above, they aren't the same. */
2323 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
2325 if (GET_MODE (x) != GET_MODE (y))
2328 /* For commutative operations, the RTX match if the operand match in any
2329 order. Also handle the simple binary and unary cases without a loop.
2331 ??? Don't consider PLUS a commutative operator; see comments above. */
2332 if ((code == EQ || code == NE || GET_RTX_CLASS (code) == 'c')
2334 return ((rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 0))
2335 && rtx_renumbered_equal_p (XEXP (x, 1), XEXP (y, 1)))
2336 || (rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 1))
2337 && rtx_renumbered_equal_p (XEXP (x, 1), XEXP (y, 0))));
2338 else if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == '2')
2339 return (rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 0))
2340 && rtx_renumbered_equal_p (XEXP (x, 1), XEXP (y, 1)));
2341 else if (GET_RTX_CLASS (code) == '1')
2342 return rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 0));
2344 /* Compare the elements. If any pair of corresponding elements
2345 fail to match, return 0 for the whole things. */
2347 fmt = GET_RTX_FORMAT (code);
2348 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2354 if (XWINT (x, i) != XWINT (y, i))
2359 if (XINT (x, i) != XINT (y, i))
2364 if (XTREE (x, i) != XTREE (y, i))
2369 if (strcmp (XSTR (x, i), XSTR (y, i)))
2374 if (! rtx_renumbered_equal_p (XEXP (x, i), XEXP (y, i)))
2379 if (XEXP (x, i) != XEXP (y, i))
2386 if (XVECLEN (x, i) != XVECLEN (y, i))
2388 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2389 if (!rtx_renumbered_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j)))
2400 /* If X is a hard register or equivalent to one or a subregister of one,
2401 return the hard register number. If X is a pseudo register that was not
2402 assigned a hard register, return the pseudo register number. Otherwise,
2403 return -1. Any rtx is valid for X. */
2409 if (GET_CODE (x) == REG)
2411 if (REGNO (x) >= FIRST_PSEUDO_REGISTER && reg_renumber[REGNO (x)] >= 0)
2412 return reg_renumber[REGNO (x)];
2415 if (GET_CODE (x) == SUBREG)
2417 int base = true_regnum (SUBREG_REG (x));
2418 if (base >= 0 && base < FIRST_PSEUDO_REGISTER)
2419 return base + subreg_regno_offset (REGNO (SUBREG_REG (x)),
2420 GET_MODE (SUBREG_REG (x)),
2421 SUBREG_BYTE (x), GET_MODE (x));
2426 /* Return regno of the register REG and handle subregs too. */
2428 reg_or_subregno (reg)
2433 if (GET_CODE (reg) == SUBREG)
2434 return REGNO (SUBREG_REG (reg));