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 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 void init_label_info
PARAMS ((rtx
));
65 static void mark_all_labels
PARAMS ((rtx
));
66 static int duplicate_loop_exit_test
PARAMS ((rtx
));
67 static void delete_computation
PARAMS ((rtx
));
68 static void redirect_exp_1
PARAMS ((rtx
*, rtx
, rtx
, rtx
));
69 static int redirect_exp
PARAMS ((rtx
, rtx
, rtx
));
70 static void invert_exp_1
PARAMS ((rtx
));
71 static int invert_exp
PARAMS ((rtx
));
72 static int returnjump_p_1
PARAMS ((rtx
*, void *));
73 static void delete_prior_computation
PARAMS ((rtx
, rtx
));
75 /* Alternate entry into the jump optimizer. This entry point only rebuilds
76 the JUMP_LABEL field in jumping insns and REG_LABEL notes in non-jumping
79 rebuild_jump_labels (f
)
87 /* Keep track of labels used from static data; we don't track them
88 closely enough to delete them here, so make sure their reference
89 count doesn't drop to zero. */
91 for (insn
= forced_labels
; insn
; insn
= XEXP (insn
, 1))
92 if (GET_CODE (XEXP (insn
, 0)) == CODE_LABEL
)
93 LABEL_NUSES (XEXP (insn
, 0))++;
96 /* Some old code expects exactly one BARRIER as the NEXT_INSN of a
97 non-fallthru insn. This is not generally true, as multiple barriers
98 may have crept in, or the BARRIER may be separated from the last
99 real insn by one or more NOTEs.
101 This simple pass moves barriers and removes duplicates so that the
107 rtx insn
, next
, prev
;
108 for (insn
= get_insns (); insn
; insn
= next
)
110 next
= NEXT_INSN (insn
);
111 if (GET_CODE (insn
) == BARRIER
)
113 prev
= prev_nonnote_insn (insn
);
114 if (GET_CODE (prev
) == BARRIER
)
115 delete_barrier (insn
);
116 else if (prev
!= PREV_INSN (insn
))
117 reorder_insns (insn
, insn
, prev
);
123 copy_loop_headers (f
)
127 /* Now iterate optimizing jumps until nothing changes over one pass. */
128 for (insn
= f
; insn
; insn
= next
)
132 next
= NEXT_INSN (insn
);
134 /* See if this is a NOTE_INSN_LOOP_BEG followed by an unconditional
135 jump. Try to optimize by duplicating the loop exit test if so.
136 This is only safe immediately after regscan, because it uses
137 the values of regno_first_uid and regno_last_uid. */
138 if (GET_CODE (insn
) == NOTE
139 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
140 && (temp1
= next_nonnote_insn (insn
)) != 0
141 && any_uncondjump_p (temp1
) && onlyjump_p (temp1
))
143 temp
= PREV_INSN (insn
);
144 if (duplicate_loop_exit_test (insn
))
146 next
= NEXT_INSN (temp
);
153 purge_line_number_notes (f
)
158 /* Delete extraneous line number notes.
159 Note that two consecutive notes for different lines are not really
160 extraneous. There should be some indication where that line belonged,
161 even if it became empty. */
163 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
164 if (GET_CODE (insn
) == NOTE
)
166 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_FUNCTION_BEG
)
167 /* Any previous line note was for the prologue; gdb wants a new
168 note after the prologue even if it is for the same line. */
169 last_note
= NULL_RTX
;
170 else if (NOTE_LINE_NUMBER (insn
) >= 0)
172 /* Delete this note if it is identical to previous note. */
174 && NOTE_SOURCE_FILE (insn
) == NOTE_SOURCE_FILE (last_note
)
175 && NOTE_LINE_NUMBER (insn
) == NOTE_LINE_NUMBER (last_note
))
177 delete_related_insns (insn
);
186 /* Initialize LABEL_NUSES and JUMP_LABEL fields. Delete any REG_LABEL
187 notes whose labels don't occur in the insn any more. Returns the
188 largest INSN_UID found. */
195 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
196 if (GET_CODE (insn
) == CODE_LABEL
)
197 LABEL_NUSES (insn
) = (LABEL_PRESERVE_P (insn
) != 0);
198 else if (GET_CODE (insn
) == JUMP_INSN
)
199 JUMP_LABEL (insn
) = 0;
200 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
204 for (note
= REG_NOTES (insn
); note
; note
= next
)
206 next
= XEXP (note
, 1);
207 if (REG_NOTE_KIND (note
) == REG_LABEL
208 && ! reg_mentioned_p (XEXP (note
, 0), PATTERN (insn
)))
209 remove_note (insn
, note
);
214 /* Mark the label each jump jumps to.
215 Combine consecutive labels, and count uses of labels. */
223 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
226 if (GET_CODE (insn
) == CALL_INSN
227 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
229 mark_all_labels (XEXP (PATTERN (insn
), 0));
230 mark_all_labels (XEXP (PATTERN (insn
), 1));
231 mark_all_labels (XEXP (PATTERN (insn
), 2));
233 /* Canonicalize the tail recursion label attached to the
234 CALL_PLACEHOLDER insn. */
235 if (XEXP (PATTERN (insn
), 3))
237 rtx label_ref
= gen_rtx_LABEL_REF (VOIDmode
,
238 XEXP (PATTERN (insn
), 3));
239 mark_jump_label (label_ref
, insn
, 0);
240 XEXP (PATTERN (insn
), 3) = XEXP (label_ref
, 0);
246 mark_jump_label (PATTERN (insn
), insn
, 0);
247 if (! INSN_DELETED_P (insn
) && GET_CODE (insn
) == JUMP_INSN
)
249 /* When we know the LABEL_REF contained in a REG used in
250 an indirect jump, we'll have a REG_LABEL note so that
251 flow can tell where it's going. */
252 if (JUMP_LABEL (insn
) == 0)
254 rtx label_note
= find_reg_note (insn
, REG_LABEL
, NULL_RTX
);
257 /* But a LABEL_REF around the REG_LABEL note, so
258 that we can canonicalize it. */
259 rtx label_ref
= gen_rtx_LABEL_REF (VOIDmode
,
260 XEXP (label_note
, 0));
262 mark_jump_label (label_ref
, insn
, 0);
263 XEXP (label_note
, 0) = XEXP (label_ref
, 0);
264 JUMP_LABEL (insn
) = XEXP (label_note
, 0);
271 /* LOOP_START is a NOTE_INSN_LOOP_BEG note that is followed by an unconditional
272 jump. Assume that this unconditional jump is to the exit test code. If
273 the code is sufficiently simple, make a copy of it before INSN,
274 followed by a jump to the exit of the loop. Then delete the unconditional
277 Return 1 if we made the change, else 0.
279 This is only safe immediately after a regscan pass because it uses the
280 values of regno_first_uid and regno_last_uid. */
283 duplicate_loop_exit_test (loop_start
)
286 rtx insn
, set
, reg
, p
, link
;
287 rtx copy
= 0, first_copy
= 0;
289 rtx exitcode
= NEXT_INSN (JUMP_LABEL (next_nonnote_insn (loop_start
)));
291 int max_reg
= max_reg_num ();
293 rtx loop_pre_header_label
;
295 /* Scan the exit code. We do not perform this optimization if any insn:
299 has a REG_RETVAL or REG_LIBCALL note (hard to adjust)
300 is a NOTE_INSN_LOOP_BEG because this means we have a nested loop
302 We also do not do this if we find an insn with ASM_OPERANDS. While
303 this restriction should not be necessary, copying an insn with
304 ASM_OPERANDS can confuse asm_noperands in some cases.
306 Also, don't do this if the exit code is more than 20 insns. */
308 for (insn
= exitcode
;
310 && ! (GET_CODE (insn
) == NOTE
311 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
);
312 insn
= NEXT_INSN (insn
))
314 switch (GET_CODE (insn
))
322 && (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
323 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
))
324 /* If we were to duplicate this code, we would not move
325 the BLOCK notes, and so debugging the moved code would
326 be difficult. Thus, we only move the code with -O2 or
333 /* The code below would grossly mishandle REG_WAS_0 notes,
334 so get rid of them here. */
335 while ((p
= find_reg_note (insn
, REG_WAS_0
, NULL_RTX
)) != 0)
336 remove_note (insn
, p
);
338 || find_reg_note (insn
, REG_RETVAL
, NULL_RTX
)
339 || find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
))
347 /* Unless INSN is zero, we can do the optimization. */
353 /* See if any insn sets a register only used in the loop exit code and
354 not a user variable. If so, replace it with a new register. */
355 for (insn
= exitcode
; insn
!= lastexit
; insn
= NEXT_INSN (insn
))
356 if (GET_CODE (insn
) == INSN
357 && (set
= single_set (insn
)) != 0
358 && ((reg
= SET_DEST (set
), GET_CODE (reg
) == REG
)
359 || (GET_CODE (reg
) == SUBREG
360 && (reg
= SUBREG_REG (reg
), GET_CODE (reg
) == REG
)))
361 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
362 && REGNO_FIRST_UID (REGNO (reg
)) == INSN_UID (insn
))
364 for (p
= NEXT_INSN (insn
); p
!= lastexit
; p
= NEXT_INSN (p
))
365 if (REGNO_LAST_UID (REGNO (reg
)) == INSN_UID (p
))
370 /* We can do the replacement. Allocate reg_map if this is the
371 first replacement we found. */
373 reg_map
= (rtx
*) xcalloc (max_reg
, sizeof (rtx
));
375 REG_LOOP_TEST_P (reg
) = 1;
377 reg_map
[REGNO (reg
)] = gen_reg_rtx (GET_MODE (reg
));
380 loop_pre_header_label
= gen_label_rtx ();
382 /* Now copy each insn. */
383 for (insn
= exitcode
; insn
!= lastexit
; insn
= NEXT_INSN (insn
))
385 switch (GET_CODE (insn
))
388 copy
= emit_barrier_before (loop_start
);
391 /* Only copy line-number notes. */
392 if (NOTE_LINE_NUMBER (insn
) >= 0)
394 copy
= emit_note_before (NOTE_LINE_NUMBER (insn
), loop_start
);
395 NOTE_SOURCE_FILE (copy
) = NOTE_SOURCE_FILE (insn
);
400 copy
= emit_insn_before (copy_insn (PATTERN (insn
)), loop_start
);
402 replace_regs (PATTERN (copy
), reg_map
, max_reg
, 1);
404 mark_jump_label (PATTERN (copy
), copy
, 0);
405 INSN_SCOPE (copy
) = INSN_SCOPE (insn
);
407 /* Copy all REG_NOTES except REG_LABEL since mark_jump_label will
409 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
410 if (REG_NOTE_KIND (link
) != REG_LABEL
)
412 if (GET_CODE (link
) == EXPR_LIST
)
414 = copy_insn_1 (gen_rtx_EXPR_LIST (REG_NOTE_KIND (link
),
419 = copy_insn_1 (gen_rtx_INSN_LIST (REG_NOTE_KIND (link
),
424 if (reg_map
&& REG_NOTES (copy
))
425 replace_regs (REG_NOTES (copy
), reg_map
, max_reg
, 1);
429 copy
= emit_jump_insn_before (copy_insn (PATTERN (insn
)),
431 INSN_SCOPE (copy
) = INSN_SCOPE (insn
);
433 replace_regs (PATTERN (copy
), reg_map
, max_reg
, 1);
434 mark_jump_label (PATTERN (copy
), copy
, 0);
435 if (REG_NOTES (insn
))
437 REG_NOTES (copy
) = copy_insn_1 (REG_NOTES (insn
));
439 replace_regs (REG_NOTES (copy
), reg_map
, max_reg
, 1);
442 /* Predict conditional jump that do make loop looping as taken.
443 Other jumps are probably exit conditions, so predict
445 if (any_condjump_p (copy
))
447 rtx label
= JUMP_LABEL (copy
);
450 /* The jump_insn after loop_start should be followed
451 by barrier and loopback label. */
452 if (prev_nonnote_insn (label
)
453 && (prev_nonnote_insn (prev_nonnote_insn (label
))
454 == next_nonnote_insn (loop_start
)))
456 predict_insn_def (copy
, PRED_LOOP_HEADER
, TAKEN
);
457 /* To keep pre-header, we need to redirect all loop
458 entrances before the LOOP_BEG note. */
459 redirect_jump (copy
, loop_pre_header_label
, 0);
462 predict_insn_def (copy
, PRED_LOOP_HEADER
, NOT_TAKEN
);
471 /* Record the first insn we copied. We need it so that we can
472 scan the copied insns for new pseudo registers. */
477 /* Now clean up by emitting a jump to the end label and deleting the jump
478 at the start of the loop. */
479 if (! copy
|| GET_CODE (copy
) != BARRIER
)
481 copy
= emit_jump_insn_before (gen_jump (get_label_after (insn
)),
484 /* Record the first insn we copied. We need it so that we can
485 scan the copied insns for new pseudo registers. This may not
486 be strictly necessary since we should have copied at least one
487 insn above. But I am going to be safe. */
491 mark_jump_label (PATTERN (copy
), copy
, 0);
492 emit_barrier_before (loop_start
);
495 emit_label_before (loop_pre_header_label
, loop_start
);
497 /* Now scan from the first insn we copied to the last insn we copied
498 (copy) for new pseudo registers. Do this after the code to jump to
499 the end label since that might create a new pseudo too. */
500 reg_scan_update (first_copy
, copy
, max_reg
);
502 /* Mark the exit code as the virtual top of the converted loop. */
503 emit_note_before (NOTE_INSN_LOOP_VTOP
, exitcode
);
505 delete_related_insns (next_nonnote_insn (loop_start
));
514 /* Move all block-beg, block-end, loop-beg, loop-cont, loop-vtop, loop-end,
515 notes between START and END out before START. START and END may be such
516 notes. Returns the values of the new starting and ending insns, which
517 may be different if the original ones were such notes.
518 Return true if there were only such notes and no real instructions. */
521 squeeze_notes (startp
, endp
)
531 rtx past_end
= NEXT_INSN (end
);
533 for (insn
= start
; insn
!= past_end
; insn
= next
)
535 next
= NEXT_INSN (insn
);
536 if (GET_CODE (insn
) == NOTE
537 && (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
538 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
539 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
540 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
541 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_CONT
542 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_VTOP
))
548 rtx prev
= PREV_INSN (insn
);
549 PREV_INSN (insn
) = PREV_INSN (start
);
550 NEXT_INSN (insn
) = start
;
551 NEXT_INSN (PREV_INSN (insn
)) = insn
;
552 PREV_INSN (NEXT_INSN (insn
)) = insn
;
553 NEXT_INSN (prev
) = next
;
554 PREV_INSN (next
) = prev
;
561 /* There were no real instructions. */
562 if (start
== past_end
)
572 /* Return the label before INSN, or put a new label there. */
575 get_label_before (insn
)
580 /* Find an existing label at this point
581 or make a new one if there is none. */
582 label
= prev_nonnote_insn (insn
);
584 if (label
== 0 || GET_CODE (label
) != CODE_LABEL
)
586 rtx prev
= PREV_INSN (insn
);
588 label
= gen_label_rtx ();
589 emit_label_after (label
, prev
);
590 LABEL_NUSES (label
) = 0;
595 /* Return the label after INSN, or put a new label there. */
598 get_label_after (insn
)
603 /* Find an existing label at this point
604 or make a new one if there is none. */
605 label
= next_nonnote_insn (insn
);
607 if (label
== 0 || GET_CODE (label
) != CODE_LABEL
)
609 label
= gen_label_rtx ();
610 emit_label_after (label
, insn
);
611 LABEL_NUSES (label
) = 0;
616 /* Given a comparison (CODE ARG0 ARG1), inside an insn, INSN, return a code
617 of reversed comparison if it is possible to do so. Otherwise return UNKNOWN.
618 UNKNOWN may be returned in case we are having CC_MODE compare and we don't
619 know whether it's source is floating point or integer comparison. Machine
620 description should define REVERSIBLE_CC_MODE and REVERSE_CONDITION macros
621 to help this function avoid overhead in these cases. */
623 reversed_comparison_code_parts (code
, arg0
, arg1
, insn
)
624 rtx insn
, arg0
, arg1
;
627 enum machine_mode mode
;
629 /* If this is not actually a comparison, we can't reverse it. */
630 if (GET_RTX_CLASS (code
) != '<')
633 mode
= GET_MODE (arg0
);
634 if (mode
== VOIDmode
)
635 mode
= GET_MODE (arg1
);
637 /* First see if machine description supply us way to reverse the comparison.
638 Give it priority over everything else to allow machine description to do
640 #ifdef REVERSIBLE_CC_MODE
641 if (GET_MODE_CLASS (mode
) == MODE_CC
642 && REVERSIBLE_CC_MODE (mode
))
644 #ifdef REVERSE_CONDITION
645 return REVERSE_CONDITION (code
, mode
);
647 return reverse_condition (code
);
651 /* Try a few special cases based on the comparison code. */
660 /* It is always safe to reverse EQ and NE, even for the floating
661 point. Similary the unsigned comparisons are never used for
662 floating point so we can reverse them in the default way. */
663 return reverse_condition (code
);
668 /* In case we already see unordered comparison, we can be sure to
669 be dealing with floating point so we don't need any more tests. */
670 return reverse_condition_maybe_unordered (code
);
675 /* We don't have safe way to reverse these yet. */
681 if (GET_MODE_CLASS (mode
) == MODE_CC
688 /* Try to search for the comparison to determine the real mode.
689 This code is expensive, but with sane machine description it
690 will be never used, since REVERSIBLE_CC_MODE will return true
695 for (prev
= prev_nonnote_insn (insn
);
696 prev
!= 0 && GET_CODE (prev
) != CODE_LABEL
;
697 prev
= prev_nonnote_insn (prev
))
699 rtx set
= set_of (arg0
, prev
);
700 if (set
&& GET_CODE (set
) == SET
701 && rtx_equal_p (SET_DEST (set
), arg0
))
703 rtx src
= SET_SRC (set
);
705 if (GET_CODE (src
) == COMPARE
)
707 rtx comparison
= src
;
708 arg0
= XEXP (src
, 0);
709 mode
= GET_MODE (arg0
);
710 if (mode
== VOIDmode
)
711 mode
= GET_MODE (XEXP (comparison
, 1));
714 /* We can get past reg-reg moves. This may be useful for model
715 of i387 comparisons that first move flag registers around. */
722 /* If register is clobbered in some ununderstandable way,
729 /* Test for an integer condition, or a floating-point comparison
730 in which NaNs can be ignored. */
731 if (GET_CODE (arg0
) == CONST_INT
732 || (GET_MODE (arg0
) != VOIDmode
733 && GET_MODE_CLASS (mode
) != MODE_CC
734 && !HONOR_NANS (mode
)))
735 return reverse_condition (code
);
740 /* An wrapper around the previous function to take COMPARISON as rtx
741 expression. This simplifies many callers. */
743 reversed_comparison_code (comparison
, insn
)
744 rtx comparison
, insn
;
746 if (GET_RTX_CLASS (GET_CODE (comparison
)) != '<')
748 return reversed_comparison_code_parts (GET_CODE (comparison
),
749 XEXP (comparison
, 0),
750 XEXP (comparison
, 1), insn
);
753 /* Given an rtx-code for a comparison, return the code for the negated
754 comparison. If no such code exists, return UNKNOWN.
756 WATCH OUT! reverse_condition is not safe to use on a jump that might
757 be acting on the results of an IEEE floating point comparison, because
758 of the special treatment of non-signaling nans in comparisons.
759 Use reversed_comparison_code instead. */
762 reverse_condition (code
)
805 /* Similar, but we're allowed to generate unordered comparisons, which
806 makes it safe for IEEE floating-point. Of course, we have to recognize
807 that the target will support them too... */
810 reverse_condition_maybe_unordered (code
)
849 /* Similar, but return the code when two operands of a comparison are swapped.
850 This IS safe for IEEE floating-point. */
853 swap_condition (code
)
896 /* Given a comparison CODE, return the corresponding unsigned comparison.
897 If CODE is an equality comparison or already an unsigned comparison,
901 unsigned_condition (code
)
928 /* Similarly, return the signed version of a comparison. */
931 signed_condition (code
)
958 /* Return nonzero if CODE1 is more strict than CODE2, i.e., if the
959 truth of CODE1 implies the truth of CODE2. */
962 comparison_dominates_p (code1
, code2
)
963 enum rtx_code code1
, code2
;
965 /* UNKNOWN comparison codes can happen as a result of trying to revert
967 They can't match anything, so we have to reject them here. */
968 if (code1
== UNKNOWN
|| code2
== UNKNOWN
)
977 if (code2
== UNLE
|| code2
== UNGE
)
982 if (code2
== LE
|| code2
== LEU
|| code2
== GE
|| code2
== GEU
988 if (code2
== UNLE
|| code2
== NE
)
993 if (code2
== LE
|| code2
== NE
|| code2
== ORDERED
|| code2
== LTGT
)
998 if (code2
== UNGE
|| code2
== NE
)
1003 if (code2
== GE
|| code2
== NE
|| code2
== ORDERED
|| code2
== LTGT
)
1009 if (code2
== ORDERED
)
1014 if (code2
== NE
|| code2
== ORDERED
)
1019 if (code2
== LEU
|| code2
== NE
)
1024 if (code2
== GEU
|| code2
== NE
)
1029 if (code2
== NE
|| code2
== UNEQ
|| code2
== UNLE
|| code2
== UNLT
1030 || code2
== UNGE
|| code2
== UNGT
)
1041 /* Return 1 if INSN is an unconditional jump and nothing else. */
1047 return (GET_CODE (insn
) == JUMP_INSN
1048 && GET_CODE (PATTERN (insn
)) == SET
1049 && GET_CODE (SET_DEST (PATTERN (insn
))) == PC
1050 && GET_CODE (SET_SRC (PATTERN (insn
))) == LABEL_REF
);
1053 /* Return nonzero if INSN is a (possibly) conditional jump
1056 Use this function is deprecated, since we need to support combined
1057 branch and compare insns. Use any_condjump_p instead whenever possible. */
1063 rtx x
= PATTERN (insn
);
1065 if (GET_CODE (x
) != SET
1066 || GET_CODE (SET_DEST (x
)) != PC
)
1070 if (GET_CODE (x
) == LABEL_REF
)
1073 return (GET_CODE (x
) == IF_THEN_ELSE
1074 && ((GET_CODE (XEXP (x
, 2)) == PC
1075 && (GET_CODE (XEXP (x
, 1)) == LABEL_REF
1076 || GET_CODE (XEXP (x
, 1)) == RETURN
))
1077 || (GET_CODE (XEXP (x
, 1)) == PC
1078 && (GET_CODE (XEXP (x
, 2)) == LABEL_REF
1079 || GET_CODE (XEXP (x
, 2)) == RETURN
))));
1084 /* Return nonzero if INSN is a (possibly) conditional jump inside a
1087 Use this function is deprecated, since we need to support combined
1088 branch and compare insns. Use any_condjump_p instead whenever possible. */
1091 condjump_in_parallel_p (insn
)
1094 rtx x
= PATTERN (insn
);
1096 if (GET_CODE (x
) != PARALLEL
)
1099 x
= XVECEXP (x
, 0, 0);
1101 if (GET_CODE (x
) != SET
)
1103 if (GET_CODE (SET_DEST (x
)) != PC
)
1105 if (GET_CODE (SET_SRC (x
)) == LABEL_REF
)
1107 if (GET_CODE (SET_SRC (x
)) != IF_THEN_ELSE
)
1109 if (XEXP (SET_SRC (x
), 2) == pc_rtx
1110 && (GET_CODE (XEXP (SET_SRC (x
), 1)) == LABEL_REF
1111 || GET_CODE (XEXP (SET_SRC (x
), 1)) == RETURN
))
1113 if (XEXP (SET_SRC (x
), 1) == pc_rtx
1114 && (GET_CODE (XEXP (SET_SRC (x
), 2)) == LABEL_REF
1115 || GET_CODE (XEXP (SET_SRC (x
), 2)) == RETURN
))
1120 /* Return set of PC, otherwise NULL. */
1127 if (GET_CODE (insn
) != JUMP_INSN
)
1129 pat
= PATTERN (insn
);
1131 /* The set is allowed to appear either as the insn pattern or
1132 the first set in a PARALLEL. */
1133 if (GET_CODE (pat
) == PARALLEL
)
1134 pat
= XVECEXP (pat
, 0, 0);
1135 if (GET_CODE (pat
) == SET
&& GET_CODE (SET_DEST (pat
)) == PC
)
1141 /* Return true when insn is an unconditional direct jump,
1142 possibly bundled inside a PARALLEL. */
1145 any_uncondjump_p (insn
)
1148 rtx x
= pc_set (insn
);
1151 if (GET_CODE (SET_SRC (x
)) != LABEL_REF
)
1156 /* Return true when insn is a conditional jump. This function works for
1157 instructions containing PC sets in PARALLELs. The instruction may have
1158 various other effects so before removing the jump you must verify
1161 Note that unlike condjump_p it returns false for unconditional jumps. */
1164 any_condjump_p (insn
)
1167 rtx x
= pc_set (insn
);
1172 if (GET_CODE (SET_SRC (x
)) != IF_THEN_ELSE
)
1175 a
= GET_CODE (XEXP (SET_SRC (x
), 1));
1176 b
= GET_CODE (XEXP (SET_SRC (x
), 2));
1178 return ((b
== PC
&& (a
== LABEL_REF
|| a
== RETURN
))
1179 || (a
== PC
&& (b
== LABEL_REF
|| b
== RETURN
)));
1182 /* Return the label of a conditional jump. */
1185 condjump_label (insn
)
1188 rtx x
= pc_set (insn
);
1193 if (GET_CODE (x
) == LABEL_REF
)
1195 if (GET_CODE (x
) != IF_THEN_ELSE
)
1197 if (XEXP (x
, 2) == pc_rtx
&& GET_CODE (XEXP (x
, 1)) == LABEL_REF
)
1199 if (XEXP (x
, 1) == pc_rtx
&& GET_CODE (XEXP (x
, 2)) == LABEL_REF
)
1204 /* Return true if INSN is a (possibly conditional) return insn. */
1207 returnjump_p_1 (loc
, data
)
1209 void *data ATTRIBUTE_UNUSED
;
1213 return x
&& (GET_CODE (x
) == RETURN
1214 || (GET_CODE (x
) == SET
&& SET_IS_RETURN_P (x
)));
1221 if (GET_CODE (insn
) != JUMP_INSN
)
1223 return for_each_rtx (&PATTERN (insn
), returnjump_p_1
, NULL
);
1226 /* Return true if INSN is a jump that only transfers control and
1235 if (GET_CODE (insn
) != JUMP_INSN
)
1238 set
= single_set (insn
);
1241 if (GET_CODE (SET_DEST (set
)) != PC
)
1243 if (side_effects_p (SET_SRC (set
)))
1251 /* Return nonzero if X is an RTX that only sets the condition codes
1252 and has no side effects. */
1265 return sets_cc0_p (x
) == 1 && ! side_effects_p (x
);
1268 /* Return 1 if X is an RTX that does nothing but set the condition codes
1269 and CLOBBER or USE registers.
1270 Return -1 if X does explicitly set the condition codes,
1271 but also does other things. */
1284 if (GET_CODE (x
) == SET
&& SET_DEST (x
) == cc0_rtx
)
1286 if (GET_CODE (x
) == PARALLEL
)
1290 int other_things
= 0;
1291 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1293 if (GET_CODE (XVECEXP (x
, 0, i
)) == SET
1294 && SET_DEST (XVECEXP (x
, 0, i
)) == cc0_rtx
)
1296 else if (GET_CODE (XVECEXP (x
, 0, i
)) == SET
)
1299 return ! sets_cc0
? 0 : other_things
? -1 : 1;
1305 /* Follow any unconditional jump at LABEL;
1306 return the ultimate label reached by any such chain of jumps.
1307 If LABEL is not followed by a jump, return LABEL.
1308 If the chain loops or we can't find end, return LABEL,
1309 since that tells caller to avoid changing the insn.
1311 If RELOAD_COMPLETED is 0, we do not chain across a NOTE_INSN_LOOP_BEG or
1312 a USE or CLOBBER. */
1315 follow_jumps (label
)
1325 && (insn
= next_active_insn (value
)) != 0
1326 && GET_CODE (insn
) == JUMP_INSN
1327 && ((JUMP_LABEL (insn
) != 0 && any_uncondjump_p (insn
)
1328 && onlyjump_p (insn
))
1329 || GET_CODE (PATTERN (insn
)) == RETURN
)
1330 && (next
= NEXT_INSN (insn
))
1331 && GET_CODE (next
) == BARRIER
);
1334 /* Don't chain through the insn that jumps into a loop
1335 from outside the loop,
1336 since that would create multiple loop entry jumps
1337 and prevent loop optimization. */
1339 if (!reload_completed
)
1340 for (tem
= value
; tem
!= insn
; tem
= NEXT_INSN (tem
))
1341 if (GET_CODE (tem
) == NOTE
1342 && (NOTE_LINE_NUMBER (tem
) == NOTE_INSN_LOOP_BEG
1343 /* ??? Optional. Disables some optimizations, but makes
1344 gcov output more accurate with -O. */
1345 || (flag_test_coverage
&& NOTE_LINE_NUMBER (tem
) > 0)))
1348 /* If we have found a cycle, make the insn jump to itself. */
1349 if (JUMP_LABEL (insn
) == label
)
1352 tem
= next_active_insn (JUMP_LABEL (insn
));
1353 if (tem
&& (GET_CODE (PATTERN (tem
)) == ADDR_VEC
1354 || GET_CODE (PATTERN (tem
)) == ADDR_DIFF_VEC
))
1357 value
= JUMP_LABEL (insn
);
1365 /* Find all CODE_LABELs referred to in X, and increment their use counts.
1366 If INSN is a JUMP_INSN and there is at least one CODE_LABEL referenced
1367 in INSN, then store one of them in JUMP_LABEL (INSN).
1368 If INSN is an INSN or a CALL_INSN and there is at least one CODE_LABEL
1369 referenced in INSN, add a REG_LABEL note containing that label to INSN.
1370 Also, when there are consecutive labels, canonicalize on the last of them.
1372 Note that two labels separated by a loop-beginning note
1373 must be kept distinct if we have not yet done loop-optimization,
1374 because the gap between them is where loop-optimize
1375 will want to move invariant code to. CROSS_JUMP tells us
1376 that loop-optimization is done with. */
1379 mark_jump_label (x
, insn
, in_mem
)
1384 RTX_CODE code
= GET_CODE (x
);
1407 /* If this is a constant-pool reference, see if it is a label. */
1408 if (CONSTANT_POOL_ADDRESS_P (x
))
1409 mark_jump_label (get_pool_constant (x
), insn
, in_mem
);
1414 rtx label
= XEXP (x
, 0);
1416 /* Ignore remaining references to unreachable labels that
1417 have been deleted. */
1418 if (GET_CODE (label
) == NOTE
1419 && NOTE_LINE_NUMBER (label
) == NOTE_INSN_DELETED_LABEL
)
1422 if (GET_CODE (label
) != CODE_LABEL
)
1425 /* Ignore references to labels of containing functions. */
1426 if (LABEL_REF_NONLOCAL_P (x
))
1429 XEXP (x
, 0) = label
;
1430 if (! insn
|| ! INSN_DELETED_P (insn
))
1431 ++LABEL_NUSES (label
);
1435 if (GET_CODE (insn
) == JUMP_INSN
)
1436 JUMP_LABEL (insn
) = label
;
1439 /* Add a REG_LABEL note for LABEL unless there already
1440 is one. All uses of a label, except for labels
1441 that are the targets of jumps, must have a
1443 if (! find_reg_note (insn
, REG_LABEL
, label
))
1444 REG_NOTES (insn
) = gen_rtx_INSN_LIST (REG_LABEL
, label
,
1451 /* Do walk the labels in a vector, but not the first operand of an
1452 ADDR_DIFF_VEC. Don't set the JUMP_LABEL of a vector. */
1455 if (! INSN_DELETED_P (insn
))
1457 int eltnum
= code
== ADDR_DIFF_VEC
? 1 : 0;
1459 for (i
= 0; i
< XVECLEN (x
, eltnum
); i
++)
1460 mark_jump_label (XVECEXP (x
, eltnum
, i
), NULL_RTX
, in_mem
);
1468 fmt
= GET_RTX_FORMAT (code
);
1469 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1472 mark_jump_label (XEXP (x
, i
), insn
, in_mem
);
1473 else if (fmt
[i
] == 'E')
1476 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1477 mark_jump_label (XVECEXP (x
, i
, j
), insn
, in_mem
);
1482 /* If all INSN does is set the pc, delete it,
1483 and delete the insn that set the condition codes for it
1484 if that's what the previous thing was. */
1490 rtx set
= single_set (insn
);
1492 if (set
&& GET_CODE (SET_DEST (set
)) == PC
)
1493 delete_computation (insn
);
1496 /* Verify INSN is a BARRIER and delete it. */
1499 delete_barrier (insn
)
1502 if (GET_CODE (insn
) != BARRIER
)
1508 /* Recursively delete prior insns that compute the value (used only by INSN
1509 which the caller is deleting) stored in the register mentioned by NOTE
1510 which is a REG_DEAD note associated with INSN. */
1513 delete_prior_computation (note
, insn
)
1518 rtx reg
= XEXP (note
, 0);
1520 for (our_prev
= prev_nonnote_insn (insn
);
1521 our_prev
&& (GET_CODE (our_prev
) == INSN
1522 || GET_CODE (our_prev
) == CALL_INSN
);
1523 our_prev
= prev_nonnote_insn (our_prev
))
1525 rtx pat
= PATTERN (our_prev
);
1527 /* If we reach a CALL which is not calling a const function
1528 or the callee pops the arguments, then give up. */
1529 if (GET_CODE (our_prev
) == CALL_INSN
1530 && (! CONST_OR_PURE_CALL_P (our_prev
)
1531 || GET_CODE (pat
) != SET
|| GET_CODE (SET_SRC (pat
)) != CALL
))
1534 /* If we reach a SEQUENCE, it is too complex to try to
1535 do anything with it, so give up. We can be run during
1536 and after reorg, so SEQUENCE rtl can legitimately show
1538 if (GET_CODE (pat
) == SEQUENCE
)
1541 if (GET_CODE (pat
) == USE
1542 && GET_CODE (XEXP (pat
, 0)) == INSN
)
1543 /* reorg creates USEs that look like this. We leave them
1544 alone because reorg needs them for its own purposes. */
1547 if (reg_set_p (reg
, pat
))
1549 if (side_effects_p (pat
) && GET_CODE (our_prev
) != CALL_INSN
)
1552 if (GET_CODE (pat
) == PARALLEL
)
1554 /* If we find a SET of something else, we can't
1559 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
1561 rtx part
= XVECEXP (pat
, 0, i
);
1563 if (GET_CODE (part
) == SET
1564 && SET_DEST (part
) != reg
)
1568 if (i
== XVECLEN (pat
, 0))
1569 delete_computation (our_prev
);
1571 else if (GET_CODE (pat
) == SET
1572 && GET_CODE (SET_DEST (pat
)) == REG
)
1574 int dest_regno
= REGNO (SET_DEST (pat
));
1577 + (dest_regno
< FIRST_PSEUDO_REGISTER
1578 ? HARD_REGNO_NREGS (dest_regno
,
1579 GET_MODE (SET_DEST (pat
))) : 1));
1580 int regno
= REGNO (reg
);
1583 + (regno
< FIRST_PSEUDO_REGISTER
1584 ? HARD_REGNO_NREGS (regno
, GET_MODE (reg
)) : 1));
1586 if (dest_regno
>= regno
1587 && dest_endregno
<= endregno
)
1588 delete_computation (our_prev
);
1590 /* We may have a multi-word hard register and some, but not
1591 all, of the words of the register are needed in subsequent
1592 insns. Write REG_UNUSED notes for those parts that were not
1594 else if (dest_regno
<= regno
1595 && dest_endregno
>= endregno
)
1599 REG_NOTES (our_prev
)
1600 = gen_rtx_EXPR_LIST (REG_UNUSED
, reg
,
1601 REG_NOTES (our_prev
));
1603 for (i
= dest_regno
; i
< dest_endregno
; i
++)
1604 if (! find_regno_note (our_prev
, REG_UNUSED
, i
))
1607 if (i
== dest_endregno
)
1608 delete_computation (our_prev
);
1615 /* If PAT references the register that dies here, it is an
1616 additional use. Hence any prior SET isn't dead. However, this
1617 insn becomes the new place for the REG_DEAD note. */
1618 if (reg_overlap_mentioned_p (reg
, pat
))
1620 XEXP (note
, 1) = REG_NOTES (our_prev
);
1621 REG_NOTES (our_prev
) = note
;
1627 /* Delete INSN and recursively delete insns that compute values used only
1628 by INSN. This uses the REG_DEAD notes computed during flow analysis.
1629 If we are running before flow.c, we need do nothing since flow.c will
1630 delete dead code. We also can't know if the registers being used are
1631 dead or not at this point.
1633 Otherwise, look at all our REG_DEAD notes. If a previous insn does
1634 nothing other than set a register that dies in this insn, we can delete
1637 On machines with CC0, if CC0 is used in this insn, we may be able to
1638 delete the insn that set it. */
1641 delete_computation (insn
)
1647 if (reg_referenced_p (cc0_rtx
, PATTERN (insn
)))
1649 rtx prev
= prev_nonnote_insn (insn
);
1650 /* We assume that at this stage
1651 CC's are always set explicitly
1652 and always immediately before the jump that
1653 will use them. So if the previous insn
1654 exists to set the CC's, delete it
1655 (unless it performs auto-increments, etc.). */
1656 if (prev
&& GET_CODE (prev
) == INSN
1657 && sets_cc0_p (PATTERN (prev
)))
1659 if (sets_cc0_p (PATTERN (prev
)) > 0
1660 && ! side_effects_p (PATTERN (prev
)))
1661 delete_computation (prev
);
1663 /* Otherwise, show that cc0 won't be used. */
1664 REG_NOTES (prev
) = gen_rtx_EXPR_LIST (REG_UNUSED
,
1665 cc0_rtx
, REG_NOTES (prev
));
1670 for (note
= REG_NOTES (insn
); note
; note
= next
)
1672 next
= XEXP (note
, 1);
1674 if (REG_NOTE_KIND (note
) != REG_DEAD
1675 /* Verify that the REG_NOTE is legitimate. */
1676 || GET_CODE (XEXP (note
, 0)) != REG
)
1679 delete_prior_computation (note
, insn
);
1682 delete_related_insns (insn
);
1685 /* Delete insn INSN from the chain of insns and update label ref counts
1686 and delete insns now unreachable.
1688 Returns the first insn after INSN that was not deleted.
1690 Usage of this instruction is deprecated. Use delete_insn instead and
1691 subsequent cfg_cleanup pass to delete unreachable code if needed. */
1694 delete_related_insns (insn
)
1697 int was_code_label
= (GET_CODE (insn
) == CODE_LABEL
);
1699 rtx next
= NEXT_INSN (insn
), prev
= PREV_INSN (insn
);
1701 while (next
&& INSN_DELETED_P (next
))
1702 next
= NEXT_INSN (next
);
1704 /* This insn is already deleted => return first following nondeleted. */
1705 if (INSN_DELETED_P (insn
))
1710 /* If instruction is followed by a barrier,
1711 delete the barrier too. */
1713 if (next
!= 0 && GET_CODE (next
) == BARRIER
)
1716 /* If deleting a jump, decrement the count of the label,
1717 and delete the label if it is now unused. */
1719 if (GET_CODE (insn
) == JUMP_INSN
&& JUMP_LABEL (insn
))
1721 rtx lab
= JUMP_LABEL (insn
), lab_next
;
1723 if (LABEL_NUSES (lab
) == 0)
1725 /* This can delete NEXT or PREV,
1726 either directly if NEXT is JUMP_LABEL (INSN),
1727 or indirectly through more levels of jumps. */
1728 delete_related_insns (lab
);
1730 /* I feel a little doubtful about this loop,
1731 but I see no clean and sure alternative way
1732 to find the first insn after INSN that is not now deleted.
1733 I hope this works. */
1734 while (next
&& INSN_DELETED_P (next
))
1735 next
= NEXT_INSN (next
);
1738 else if ((lab_next
= next_nonnote_insn (lab
)) != NULL
1739 && GET_CODE (lab_next
) == JUMP_INSN
1740 && (GET_CODE (PATTERN (lab_next
)) == ADDR_VEC
1741 || GET_CODE (PATTERN (lab_next
)) == ADDR_DIFF_VEC
))
1743 /* If we're deleting the tablejump, delete the dispatch table.
1744 We may not be able to kill the label immediately preceding
1745 just yet, as it might be referenced in code leading up to
1747 delete_related_insns (lab_next
);
1751 /* Likewise if we're deleting a dispatch table. */
1753 if (GET_CODE (insn
) == JUMP_INSN
1754 && (GET_CODE (PATTERN (insn
)) == ADDR_VEC
1755 || GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
))
1757 rtx pat
= PATTERN (insn
);
1758 int i
, diff_vec_p
= GET_CODE (pat
) == ADDR_DIFF_VEC
;
1759 int len
= XVECLEN (pat
, diff_vec_p
);
1761 for (i
= 0; i
< len
; i
++)
1762 if (LABEL_NUSES (XEXP (XVECEXP (pat
, diff_vec_p
, i
), 0)) == 0)
1763 delete_related_insns (XEXP (XVECEXP (pat
, diff_vec_p
, i
), 0));
1764 while (next
&& INSN_DELETED_P (next
))
1765 next
= NEXT_INSN (next
);
1769 /* Likewise for an ordinary INSN / CALL_INSN with a REG_LABEL note. */
1770 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
1771 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
1772 if (REG_NOTE_KIND (note
) == REG_LABEL
1773 /* This could also be a NOTE_INSN_DELETED_LABEL note. */
1774 && GET_CODE (XEXP (note
, 0)) == CODE_LABEL
)
1775 if (LABEL_NUSES (XEXP (note
, 0)) == 0)
1776 delete_related_insns (XEXP (note
, 0));
1778 while (prev
&& (INSN_DELETED_P (prev
) || GET_CODE (prev
) == NOTE
))
1779 prev
= PREV_INSN (prev
);
1781 /* If INSN was a label and a dispatch table follows it,
1782 delete the dispatch table. The tablejump must have gone already.
1783 It isn't useful to fall through into a table. */
1786 && NEXT_INSN (insn
) != 0
1787 && GET_CODE (NEXT_INSN (insn
)) == JUMP_INSN
1788 && (GET_CODE (PATTERN (NEXT_INSN (insn
))) == ADDR_VEC
1789 || GET_CODE (PATTERN (NEXT_INSN (insn
))) == ADDR_DIFF_VEC
))
1790 next
= delete_related_insns (NEXT_INSN (insn
));
1792 /* If INSN was a label, delete insns following it if now unreachable. */
1794 if (was_code_label
&& prev
&& GET_CODE (prev
) == BARRIER
)
1798 && (GET_RTX_CLASS (code
= GET_CODE (next
)) == 'i'
1799 || code
== NOTE
|| code
== BARRIER
1800 || (code
== CODE_LABEL
&& INSN_DELETED_P (next
))))
1803 && NOTE_LINE_NUMBER (next
) != NOTE_INSN_FUNCTION_END
)
1804 next
= NEXT_INSN (next
);
1805 /* Keep going past other deleted labels to delete what follows. */
1806 else if (code
== CODE_LABEL
&& INSN_DELETED_P (next
))
1807 next
= NEXT_INSN (next
);
1809 /* Note: if this deletes a jump, it can cause more
1810 deletion of unreachable code, after a different label.
1811 As long as the value from this recursive call is correct,
1812 this invocation functions correctly. */
1813 next
= delete_related_insns (next
);
1820 /* Advance from INSN till reaching something not deleted
1821 then return that. May return INSN itself. */
1824 next_nondeleted_insn (insn
)
1827 while (INSN_DELETED_P (insn
))
1828 insn
= NEXT_INSN (insn
);
1832 /* Delete a range of insns from FROM to TO, inclusive.
1833 This is for the sake of peephole optimization, so assume
1834 that whatever these insns do will still be done by a new
1835 peephole insn that will replace them. */
1838 delete_for_peephole (from
, to
)
1845 rtx next
= NEXT_INSN (insn
);
1846 rtx prev
= PREV_INSN (insn
);
1848 if (GET_CODE (insn
) != NOTE
)
1850 INSN_DELETED_P (insn
) = 1;
1852 /* Patch this insn out of the chain. */
1853 /* We don't do this all at once, because we
1854 must preserve all NOTEs. */
1856 NEXT_INSN (prev
) = next
;
1859 PREV_INSN (next
) = prev
;
1867 /* Note that if TO is an unconditional jump
1868 we *do not* delete the BARRIER that follows,
1869 since the peephole that replaces this sequence
1870 is also an unconditional jump in that case. */
1873 /* We have determined that INSN is never reached, and are about to
1874 delete it. Print a warning if the user asked for one.
1876 To try to make this warning more useful, this should only be called
1877 once per basic block not reached, and it only warns when the basic
1878 block contains more than one line from the current function, and
1879 contains at least one operation. CSE and inlining can duplicate insns,
1880 so it's possible to get spurious warnings from this. */
1883 never_reached_warning (avoided_insn
, finish
)
1884 rtx avoided_insn
, finish
;
1887 rtx a_line_note
= NULL
;
1888 int two_avoided_lines
= 0, contains_insn
= 0, reached_end
= 0;
1890 if (! warn_notreached
)
1893 /* Scan forwards, looking at LINE_NUMBER notes, until
1894 we hit a LABEL or we run out of insns. */
1896 for (insn
= avoided_insn
; insn
!= NULL
; insn
= NEXT_INSN (insn
))
1898 if (finish
== NULL
&& GET_CODE (insn
) == CODE_LABEL
)
1901 if (GET_CODE (insn
) == NOTE
/* A line number note? */
1902 && NOTE_LINE_NUMBER (insn
) >= 0)
1904 if (a_line_note
== NULL
)
1907 two_avoided_lines
|= (NOTE_LINE_NUMBER (a_line_note
)
1908 != NOTE_LINE_NUMBER (insn
));
1910 else if (INSN_P (insn
))
1912 if (reached_end
|| a_line_note
== NULL
)
1920 if (two_avoided_lines
&& contains_insn
)
1921 warning_with_file_and_line (NOTE_SOURCE_FILE (a_line_note
),
1922 NOTE_LINE_NUMBER (a_line_note
),
1923 "will never be executed");
1926 /* Throughout LOC, redirect OLABEL to NLABEL. Treat null OLABEL or
1927 NLABEL as a return. Accrue modifications into the change group. */
1930 redirect_exp_1 (loc
, olabel
, nlabel
, insn
)
1936 RTX_CODE code
= GET_CODE (x
);
1940 if (code
== LABEL_REF
)
1942 if (XEXP (x
, 0) == olabel
)
1946 n
= gen_rtx_LABEL_REF (VOIDmode
, nlabel
);
1948 n
= gen_rtx_RETURN (VOIDmode
);
1950 validate_change (insn
, loc
, n
, 1);
1954 else if (code
== RETURN
&& olabel
== 0)
1956 x
= gen_rtx_LABEL_REF (VOIDmode
, nlabel
);
1957 if (loc
== &PATTERN (insn
))
1958 x
= gen_rtx_SET (VOIDmode
, pc_rtx
, x
);
1959 validate_change (insn
, loc
, x
, 1);
1963 if (code
== SET
&& nlabel
== 0 && SET_DEST (x
) == pc_rtx
1964 && GET_CODE (SET_SRC (x
)) == LABEL_REF
1965 && XEXP (SET_SRC (x
), 0) == olabel
)
1967 validate_change (insn
, loc
, gen_rtx_RETURN (VOIDmode
), 1);
1971 fmt
= GET_RTX_FORMAT (code
);
1972 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1975 redirect_exp_1 (&XEXP (x
, i
), olabel
, nlabel
, insn
);
1976 else if (fmt
[i
] == 'E')
1979 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1980 redirect_exp_1 (&XVECEXP (x
, i
, j
), olabel
, nlabel
, insn
);
1985 /* Similar, but apply the change group and report success or failure. */
1988 redirect_exp (olabel
, nlabel
, insn
)
1994 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
1995 loc
= &XVECEXP (PATTERN (insn
), 0, 0);
1997 loc
= &PATTERN (insn
);
1999 redirect_exp_1 (loc
, olabel
, nlabel
, insn
);
2000 if (num_validated_changes () == 0)
2003 return apply_change_group ();
2006 /* Make JUMP go to NLABEL instead of where it jumps now. Accrue
2007 the modifications into the change group. Return false if we did
2008 not see how to do that. */
2011 redirect_jump_1 (jump
, nlabel
)
2014 int ochanges
= num_validated_changes ();
2017 if (GET_CODE (PATTERN (jump
)) == PARALLEL
)
2018 loc
= &XVECEXP (PATTERN (jump
), 0, 0);
2020 loc
= &PATTERN (jump
);
2022 redirect_exp_1 (loc
, JUMP_LABEL (jump
), nlabel
, jump
);
2023 return num_validated_changes () > ochanges
;
2026 /* Make JUMP go to NLABEL instead of where it jumps now. If the old
2027 jump target label is unused as a result, it and the code following
2030 If NLABEL is zero, we are to turn the jump into a (possibly conditional)
2033 The return value will be 1 if the change was made, 0 if it wasn't
2034 (this can only occur for NLABEL == 0). */
2037 redirect_jump (jump
, nlabel
, delete_unused
)
2041 rtx olabel
= JUMP_LABEL (jump
);
2043 if (nlabel
== olabel
)
2046 if (! redirect_exp (olabel
, nlabel
, jump
))
2049 JUMP_LABEL (jump
) = nlabel
;
2051 ++LABEL_NUSES (nlabel
);
2053 /* If we're eliding the jump over exception cleanups at the end of a
2054 function, move the function end note so that -Wreturn-type works. */
2055 if (olabel
&& nlabel
2056 && NEXT_INSN (olabel
)
2057 && GET_CODE (NEXT_INSN (olabel
)) == NOTE
2058 && NOTE_LINE_NUMBER (NEXT_INSN (olabel
)) == NOTE_INSN_FUNCTION_END
)
2059 emit_note_after (NOTE_INSN_FUNCTION_END
, nlabel
);
2061 if (olabel
&& --LABEL_NUSES (olabel
) == 0 && delete_unused
2062 /* Undefined labels will remain outside the insn stream. */
2063 && INSN_UID (olabel
))
2064 delete_related_insns (olabel
);
2069 /* Invert the jump condition of rtx X contained in jump insn, INSN.
2070 Accrue the modifications into the change group. */
2077 rtx x
= pc_set (insn
);
2083 code
= GET_CODE (x
);
2085 if (code
== IF_THEN_ELSE
)
2087 rtx comp
= XEXP (x
, 0);
2089 enum rtx_code reversed_code
;
2091 /* We can do this in two ways: The preferable way, which can only
2092 be done if this is not an integer comparison, is to reverse
2093 the comparison code. Otherwise, swap the THEN-part and ELSE-part
2094 of the IF_THEN_ELSE. If we can't do either, fail. */
2096 reversed_code
= reversed_comparison_code (comp
, insn
);
2098 if (reversed_code
!= UNKNOWN
)
2100 validate_change (insn
, &XEXP (x
, 0),
2101 gen_rtx_fmt_ee (reversed_code
,
2102 GET_MODE (comp
), XEXP (comp
, 0),
2109 validate_change (insn
, &XEXP (x
, 1), XEXP (x
, 2), 1);
2110 validate_change (insn
, &XEXP (x
, 2), tem
, 1);
2116 /* Invert the jump condition of conditional jump insn, INSN.
2118 Return 1 if we can do so, 0 if we cannot find a way to do so that
2119 matches a pattern. */
2125 invert_exp_1 (insn
);
2126 if (num_validated_changes () == 0)
2129 return apply_change_group ();
2132 /* Invert the condition of the jump JUMP, and make it jump to label
2133 NLABEL instead of where it jumps now. Accrue changes into the
2134 change group. Return false if we didn't see how to perform the
2135 inversion and redirection. */
2138 invert_jump_1 (jump
, nlabel
)
2143 ochanges
= num_validated_changes ();
2144 invert_exp_1 (jump
);
2145 if (num_validated_changes () == ochanges
)
2148 return redirect_jump_1 (jump
, nlabel
);
2151 /* Invert the condition of the jump JUMP, and make it jump to label
2152 NLABEL instead of where it jumps now. Return true if successful. */
2155 invert_jump (jump
, nlabel
, delete_unused
)
2159 /* We have to either invert the condition and change the label or
2160 do neither. Either operation could fail. We first try to invert
2161 the jump. If that succeeds, we try changing the label. If that fails,
2162 we invert the jump back to what it was. */
2164 if (! invert_exp (jump
))
2167 if (redirect_jump (jump
, nlabel
, delete_unused
))
2169 invert_br_probabilities (jump
);
2174 if (! invert_exp (jump
))
2175 /* This should just be putting it back the way it was. */
2182 /* Like rtx_equal_p except that it considers two REGs as equal
2183 if they renumber to the same value and considers two commutative
2184 operations to be the same if the order of the operands has been
2187 ??? Addition is not commutative on the PA due to the weird implicit
2188 space register selection rules for memory addresses. Therefore, we
2189 don't consider a + b == b + a.
2191 We could/should make this test a little tighter. Possibly only
2192 disabling it on the PA via some backend macro or only disabling this
2193 case when the PLUS is inside a MEM. */
2196 rtx_renumbered_equal_p (x
, y
)
2200 RTX_CODE code
= GET_CODE (x
);
2206 if ((code
== REG
|| (code
== SUBREG
&& GET_CODE (SUBREG_REG (x
)) == REG
))
2207 && (GET_CODE (y
) == REG
|| (GET_CODE (y
) == SUBREG
2208 && GET_CODE (SUBREG_REG (y
)) == REG
)))
2210 int reg_x
= -1, reg_y
= -1;
2211 int byte_x
= 0, byte_y
= 0;
2213 if (GET_MODE (x
) != GET_MODE (y
))
2216 /* If we haven't done any renumbering, don't
2217 make any assumptions. */
2218 if (reg_renumber
== 0)
2219 return rtx_equal_p (x
, y
);
2223 reg_x
= REGNO (SUBREG_REG (x
));
2224 byte_x
= SUBREG_BYTE (x
);
2226 if (reg_renumber
[reg_x
] >= 0)
2228 reg_x
= subreg_regno_offset (reg_renumber
[reg_x
],
2229 GET_MODE (SUBREG_REG (x
)),
2238 if (reg_renumber
[reg_x
] >= 0)
2239 reg_x
= reg_renumber
[reg_x
];
2242 if (GET_CODE (y
) == SUBREG
)
2244 reg_y
= REGNO (SUBREG_REG (y
));
2245 byte_y
= SUBREG_BYTE (y
);
2247 if (reg_renumber
[reg_y
] >= 0)
2249 reg_y
= subreg_regno_offset (reg_renumber
[reg_y
],
2250 GET_MODE (SUBREG_REG (y
)),
2259 if (reg_renumber
[reg_y
] >= 0)
2260 reg_y
= reg_renumber
[reg_y
];
2263 return reg_x
>= 0 && reg_x
== reg_y
&& byte_x
== byte_y
;
2266 /* Now we have disposed of all the cases
2267 in which different rtx codes can match. */
2268 if (code
!= GET_CODE (y
))
2280 return INTVAL (x
) == INTVAL (y
);
2283 /* We can't assume nonlocal labels have their following insns yet. */
2284 if (LABEL_REF_NONLOCAL_P (x
) || LABEL_REF_NONLOCAL_P (y
))
2285 return XEXP (x
, 0) == XEXP (y
, 0);
2287 /* Two label-refs are equivalent if they point at labels
2288 in the same position in the instruction stream. */
2289 return (next_real_insn (XEXP (x
, 0))
2290 == next_real_insn (XEXP (y
, 0)));
2293 return XSTR (x
, 0) == XSTR (y
, 0);
2296 /* If we didn't match EQ equality above, they aren't the same. */
2303 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
2305 if (GET_MODE (x
) != GET_MODE (y
))
2308 /* For commutative operations, the RTX match if the operand match in any
2309 order. Also handle the simple binary and unary cases without a loop.
2311 ??? Don't consider PLUS a commutative operator; see comments above. */
2312 if ((code
== EQ
|| code
== NE
|| GET_RTX_CLASS (code
) == 'c')
2314 return ((rtx_renumbered_equal_p (XEXP (x
, 0), XEXP (y
, 0))
2315 && rtx_renumbered_equal_p (XEXP (x
, 1), XEXP (y
, 1)))
2316 || (rtx_renumbered_equal_p (XEXP (x
, 0), XEXP (y
, 1))
2317 && rtx_renumbered_equal_p (XEXP (x
, 1), XEXP (y
, 0))));
2318 else if (GET_RTX_CLASS (code
) == '<' || GET_RTX_CLASS (code
) == '2')
2319 return (rtx_renumbered_equal_p (XEXP (x
, 0), XEXP (y
, 0))
2320 && rtx_renumbered_equal_p (XEXP (x
, 1), XEXP (y
, 1)));
2321 else if (GET_RTX_CLASS (code
) == '1')
2322 return rtx_renumbered_equal_p (XEXP (x
, 0), XEXP (y
, 0));
2324 /* Compare the elements. If any pair of corresponding elements
2325 fail to match, return 0 for the whole things. */
2327 fmt
= GET_RTX_FORMAT (code
);
2328 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2334 if (XWINT (x
, i
) != XWINT (y
, i
))
2339 if (XINT (x
, i
) != XINT (y
, i
))
2344 if (XTREE (x
, i
) != XTREE (y
, i
))
2349 if (strcmp (XSTR (x
, i
), XSTR (y
, i
)))
2354 if (! rtx_renumbered_equal_p (XEXP (x
, i
), XEXP (y
, i
)))
2359 if (XEXP (x
, i
) != XEXP (y
, i
))
2366 if (XVECLEN (x
, i
) != XVECLEN (y
, i
))
2368 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2369 if (!rtx_renumbered_equal_p (XVECEXP (x
, i
, j
), XVECEXP (y
, i
, j
)))
2380 /* If X is a hard register or equivalent to one or a subregister of one,
2381 return the hard register number. If X is a pseudo register that was not
2382 assigned a hard register, return the pseudo register number. Otherwise,
2383 return -1. Any rtx is valid for X. */
2389 if (GET_CODE (x
) == REG
)
2391 if (REGNO (x
) >= FIRST_PSEUDO_REGISTER
&& reg_renumber
[REGNO (x
)] >= 0)
2392 return reg_renumber
[REGNO (x
)];
2395 if (GET_CODE (x
) == SUBREG
)
2397 int base
= true_regnum (SUBREG_REG (x
));
2398 if (base
>= 0 && base
< FIRST_PSEUDO_REGISTER
)
2399 return base
+ subreg_regno_offset (REGNO (SUBREG_REG (x
)),
2400 GET_MODE (SUBREG_REG (x
)),
2401 SUBREG_BYTE (x
), GET_MODE (x
));
2406 /* Return regno of the register REG and handle subregs too. */
2408 reg_or_subregno (reg
)
2413 if (GET_CODE (reg
) == SUBREG
)
2414 return REGNO (SUBREG_REG (reg
));