1 /* Optimize jump instructions, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 91-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This is the jump-optimization pass of the compiler.
23 It is run two or three times: once before cse, sometimes once after cse,
24 and once after reload (before final).
26 jump_optimize deletes unreachable code and labels that are not used.
27 It also deletes jumps that jump to the following insn,
28 and simplifies jumps around unconditional jumps and jumps
29 to unconditional jumps.
31 Each CODE_LABEL has a count of the times it is used
32 stored in the LABEL_NUSES internal field, and each JUMP_INSN
33 has one label that it refers to stored in the
34 JUMP_LABEL internal field. With this we can detect labels that
35 become unused because of the deletion of all the jumps that
36 formerly used them. The JUMP_LABEL info is sometimes looked
39 Optionally, cross-jumping can be done. Currently it is done
40 only the last time (when after reload and before final).
41 In fact, the code for cross-jumping now assumes that register
42 allocation has been done, since it uses `rtx_renumbered_equal_p'.
44 Jump optimization is done after cse when cse's constant-propagation
45 causes jumps to become unconditional or to be deleted.
47 Unreachable loops are not detected here, because the labels
48 have references and the insns appear reachable from the labels.
49 find_basic_blocks in flow.c finds and deletes such loops.
51 The subroutines delete_insn, redirect_jump, and invert_jump are used
52 from other passes as well. */
58 #include "hard-reg-set.h"
60 #include "insn-config.h"
61 #include "insn-flags.h"
62 #include "insn-attr.h"
70 /* ??? Eventually must record somehow the labels used by jumps
71 from nested functions. */
72 /* Pre-record the next or previous real insn for each label?
73 No, this pass is very fast anyway. */
74 /* Condense consecutive labels?
75 This would make life analysis faster, maybe. */
76 /* Optimize jump y; x: ... y: jumpif... x?
77 Don't know if it is worth bothering with. */
78 /* Optimize two cases of conditional jump to conditional jump?
79 This can never delete any instruction or make anything dead,
80 or even change what is live at any point.
81 So perhaps let combiner do it. */
83 /* Vector indexed by uid.
84 For each CODE_LABEL, index by its uid to get first unconditional jump
85 that jumps to the label.
86 For each JUMP_INSN, index by its uid to get the next unconditional jump
87 that jumps to the same label.
88 Element 0 is the start of a chain of all return insns.
89 (It is safe to use element 0 because insn uid 0 is not used. */
91 static rtx
*jump_chain
;
93 /* Maximum index in jump_chain. */
95 static int max_jump_chain
;
97 /* Set nonzero by jump_optimize if control can fall through
98 to the end of the function. */
101 /* Indicates whether death notes are significant in cross jump analysis.
102 Normally they are not significant, because of A and B jump to C,
103 and R dies in A, it must die in B. But this might not be true after
104 stack register conversion, and we must compare death notes in that
107 static int cross_jump_death_matters
= 0;
109 static int init_label_info
PROTO((rtx
));
110 static void delete_barrier_successors
PROTO((rtx
));
111 static void mark_all_labels
PROTO((rtx
, int));
112 static rtx delete_unreferenced_labels
PROTO((rtx
));
113 static void delete_noop_moves
PROTO((rtx
));
114 static int calculate_can_reach_end
PROTO((rtx
, int, int));
115 static int duplicate_loop_exit_test
PROTO((rtx
));
116 static void find_cross_jump
PROTO((rtx
, rtx
, int, rtx
*, rtx
*));
117 static void do_cross_jump
PROTO((rtx
, rtx
, rtx
));
118 static int jump_back_p
PROTO((rtx
, rtx
));
119 static int tension_vector_labels
PROTO((rtx
, int));
120 static void mark_jump_label
PROTO((rtx
, rtx
, int));
121 static void delete_computation
PROTO((rtx
));
122 static void delete_from_jump_chain
PROTO((rtx
));
123 static int delete_labelref_insn
PROTO((rtx
, rtx
, int));
124 static void mark_modified_reg
PROTO((rtx
, rtx
));
125 static void redirect_tablejump
PROTO((rtx
, rtx
));
126 static void jump_optimize_1
PROTO ((rtx
, int, int, int, int));
128 static rtx find_insert_position
PROTO((rtx
, rtx
));
131 /* Main external entry point into the jump optimizer. See comments before
132 jump_optimize_1 for descriptions of the arguments. */
134 jump_optimize (f
, cross_jump
, noop_moves
, after_regscan
)
140 jump_optimize_1 (f
, cross_jump
, noop_moves
, after_regscan
, 0);
143 /* Alternate entry into the jump optimizer. This entry point only rebuilds
144 the JUMP_LABEL field in jumping insns and REG_LABEL notes in non-jumping
147 rebuild_jump_labels (f
)
150 jump_optimize_1 (f
, 0, 0, 0, 1);
154 /* Delete no-op jumps and optimize jumps to jumps
155 and jumps around jumps.
156 Delete unused labels and unreachable code.
158 If CROSS_JUMP is 1, detect matching code
159 before a jump and its destination and unify them.
160 If CROSS_JUMP is 2, do cross-jumping, but pay attention to death notes.
162 If NOOP_MOVES is nonzero, delete no-op move insns.
164 If AFTER_REGSCAN is nonzero, then this jump pass is being run immediately
165 after regscan, and it is safe to use regno_first_uid and regno_last_uid.
167 If MARK_LABELS_ONLY is nonzero, then we only rebuild the jump chain
168 and JUMP_LABEL field for jumping insns.
170 If `optimize' is zero, don't change any code,
171 just determine whether control drops off the end of the function.
172 This case occurs when we have -W and not -O.
173 It works because `delete_insn' checks the value of `optimize'
174 and refrains from actually deleting when that is 0. */
177 jump_optimize_1 (f
, cross_jump
, noop_moves
, after_regscan
, mark_labels_only
)
182 int mark_labels_only
;
184 register rtx insn
, next
;
191 cross_jump_death_matters
= (cross_jump
== 2);
192 max_uid
= init_label_info (f
) + 1;
194 /* If we are performing cross jump optimizations, then initialize
195 tables mapping UIDs to EH regions to avoid incorrect movement
196 of insns from one EH region to another. */
197 if (flag_exceptions
&& cross_jump
)
198 init_insn_eh_region (f
, max_uid
);
200 delete_barrier_successors (f
);
202 /* Leave some extra room for labels and duplicate exit test insns
204 max_jump_chain
= max_uid
* 14 / 10;
205 jump_chain
= (rtx
*) alloca (max_jump_chain
* sizeof (rtx
));
206 bzero ((char *) jump_chain
, max_jump_chain
* sizeof (rtx
));
208 mark_all_labels (f
, cross_jump
);
210 /* Keep track of labels used from static data;
211 they cannot ever be deleted. */
213 for (insn
= forced_labels
; insn
; insn
= XEXP (insn
, 1))
214 LABEL_NUSES (XEXP (insn
, 0))++;
216 check_exception_handler_labels ();
218 /* Keep track of labels used for marking handlers for exception
219 regions; they cannot usually be deleted. */
221 for (insn
= exception_handler_labels
; insn
; insn
= XEXP (insn
, 1))
222 LABEL_NUSES (XEXP (insn
, 0))++;
224 /* Quit now if we just wanted to rebuild the JUMP_LABEL and REG_LABEL
225 notes and recompute LABEL_NUSES. */
226 if (mark_labels_only
)
229 exception_optimize ();
231 last_insn
= delete_unreferenced_labels (f
);
235 /* CAN_REACH_END is persistent for each function. Once set it should
236 not be cleared. This is especially true for the case where we
237 delete the NOTE_FUNCTION_END note. CAN_REACH_END is cleared by
238 the front-end before compiling each function. */
239 if (calculate_can_reach_end (last_insn
, 1, 0))
242 /* Zero the "deleted" flag of all the "deleted" insns. */
243 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
244 INSN_DELETED_P (insn
) = 0;
246 /* Show that the jump chain is not valid. */
254 /* If we fall through to the epilogue, see if we can insert a RETURN insn
255 in front of it. If the machine allows it at this point (we might be
256 after reload for a leaf routine), it will improve optimization for it
258 insn
= get_last_insn ();
259 while (insn
&& GET_CODE (insn
) == NOTE
)
260 insn
= PREV_INSN (insn
);
262 if (insn
&& GET_CODE (insn
) != BARRIER
)
264 emit_jump_insn (gen_return ());
271 delete_noop_moves (f
);
273 /* If we haven't yet gotten to reload and we have just run regscan,
274 delete any insn that sets a register that isn't used elsewhere.
275 This helps some of the optimizations below by having less insns
276 being jumped around. */
278 if (! reload_completed
&& after_regscan
)
279 for (insn
= f
; insn
; insn
= next
)
281 rtx set
= single_set (insn
);
283 next
= NEXT_INSN (insn
);
285 if (set
&& GET_CODE (SET_DEST (set
)) == REG
286 && REGNO (SET_DEST (set
)) >= FIRST_PSEUDO_REGISTER
287 && REGNO_FIRST_UID (REGNO (SET_DEST (set
))) == INSN_UID (insn
)
288 /* We use regno_last_note_uid so as not to delete the setting
289 of a reg that's used in notes. A subsequent optimization
290 might arrange to use that reg for real. */
291 && REGNO_LAST_NOTE_UID (REGNO (SET_DEST (set
))) == INSN_UID (insn
)
292 && ! side_effects_p (SET_SRC (set
))
293 && ! find_reg_note (insn
, REG_RETVAL
, 0)
294 /* An ADDRESSOF expression can turn into a use of the internal arg
295 pointer, so do not delete the initialization of the internal
296 arg pointer yet. If it is truly dead, flow will delete the
297 initializing insn. */
298 && SET_DEST (set
) != current_function_internal_arg_pointer
)
302 /* Now iterate optimizing jumps until nothing changes over one pass. */
304 old_max_reg
= max_reg_num ();
309 for (insn
= f
; insn
; insn
= next
)
312 rtx temp
, temp1
, temp2
, temp3
, temp4
, temp5
, temp6
;
314 int this_is_simplejump
, this_is_condjump
, reversep
= 0;
315 int this_is_condjump_in_parallel
;
318 /* If NOT the first iteration, if this is the last jump pass
319 (just before final), do the special peephole optimizations.
320 Avoiding the first iteration gives ordinary jump opts
321 a chance to work before peephole opts. */
323 if (reload_completed
&& !first
&& !flag_no_peephole
)
324 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == JUMP_INSN
)
328 /* That could have deleted some insns after INSN, so check now
329 what the following insn is. */
331 next
= NEXT_INSN (insn
);
333 /* See if this is a NOTE_INSN_LOOP_BEG followed by an unconditional
334 jump. Try to optimize by duplicating the loop exit test if so.
335 This is only safe immediately after regscan, because it uses
336 the values of regno_first_uid and regno_last_uid. */
337 if (after_regscan
&& GET_CODE (insn
) == NOTE
338 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
339 && (temp1
= next_nonnote_insn (insn
)) != 0
340 && simplejump_p (temp1
))
342 temp
= PREV_INSN (insn
);
343 if (duplicate_loop_exit_test (insn
))
346 next
= NEXT_INSN (temp
);
351 if (GET_CODE (insn
) != JUMP_INSN
)
354 this_is_simplejump
= simplejump_p (insn
);
355 this_is_condjump
= condjump_p (insn
);
356 this_is_condjump_in_parallel
= condjump_in_parallel_p (insn
);
358 /* Tension the labels in dispatch tables. */
360 if (GET_CODE (PATTERN (insn
)) == ADDR_VEC
)
361 changed
|= tension_vector_labels (PATTERN (insn
), 0);
362 if (GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
)
363 changed
|= tension_vector_labels (PATTERN (insn
), 1);
365 /* If a dispatch table always goes to the same place,
366 get rid of it and replace the insn that uses it. */
368 if (GET_CODE (PATTERN (insn
)) == ADDR_VEC
369 || GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
)
372 rtx pat
= PATTERN (insn
);
373 int diff_vec_p
= GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
;
374 int len
= XVECLEN (pat
, diff_vec_p
);
375 rtx dispatch
= prev_real_insn (insn
);
377 for (i
= 0; i
< len
; i
++)
378 if (XEXP (XVECEXP (pat
, diff_vec_p
, i
), 0)
379 != XEXP (XVECEXP (pat
, diff_vec_p
, 0), 0))
383 && GET_CODE (dispatch
) == JUMP_INSN
384 && JUMP_LABEL (dispatch
) != 0
385 /* Don't mess with a casesi insn. */
386 && !(GET_CODE (PATTERN (dispatch
)) == SET
387 && (GET_CODE (SET_SRC (PATTERN (dispatch
)))
389 && next_real_insn (JUMP_LABEL (dispatch
)) == insn
)
391 redirect_tablejump (dispatch
,
392 XEXP (XVECEXP (pat
, diff_vec_p
, 0), 0));
397 reallabelprev
= prev_active_insn (JUMP_LABEL (insn
));
399 /* If a jump references the end of the function, try to turn
400 it into a RETURN insn, possibly a conditional one. */
401 if (JUMP_LABEL (insn
)
402 && (next_active_insn (JUMP_LABEL (insn
)) == 0
403 || GET_CODE (PATTERN (next_active_insn (JUMP_LABEL (insn
))))
405 changed
|= redirect_jump (insn
, NULL_RTX
);
407 /* Detect jump to following insn. */
408 if (reallabelprev
== insn
&& condjump_p (insn
))
410 next
= next_real_insn (JUMP_LABEL (insn
));
416 /* If we have an unconditional jump preceded by a USE, try to put
417 the USE before the target and jump there. This simplifies many
418 of the optimizations below since we don't have to worry about
419 dealing with these USE insns. We only do this if the label
420 being branch to already has the identical USE or if code
421 never falls through to that label. */
423 if (this_is_simplejump
424 && (temp
= prev_nonnote_insn (insn
)) != 0
425 && GET_CODE (temp
) == INSN
&& GET_CODE (PATTERN (temp
)) == USE
426 && (temp1
= prev_nonnote_insn (JUMP_LABEL (insn
))) != 0
427 && (GET_CODE (temp1
) == BARRIER
428 || (GET_CODE (temp1
) == INSN
429 && rtx_equal_p (PATTERN (temp
), PATTERN (temp1
))))
430 /* Don't do this optimization if we have a loop containing only
431 the USE instruction, and the loop start label has a usage
432 count of 1. This is because we will redo this optimization
433 everytime through the outer loop, and jump opt will never
435 && ! ((temp2
= prev_nonnote_insn (temp
)) != 0
436 && temp2
== JUMP_LABEL (insn
)
437 && LABEL_NUSES (temp2
) == 1))
439 if (GET_CODE (temp1
) == BARRIER
)
441 emit_insn_after (PATTERN (temp
), temp1
);
442 temp1
= NEXT_INSN (temp1
);
446 redirect_jump (insn
, get_label_before (temp1
));
447 reallabelprev
= prev_real_insn (temp1
);
451 /* Simplify if (...) x = a; else x = b; by converting it
452 to x = b; if (...) x = a;
453 if B is sufficiently simple, the test doesn't involve X,
454 and nothing in the test modifies B or X.
456 If we have small register classes, we also can't do this if X
459 If the "x = b;" insn has any REG_NOTES, we don't do this because
460 of the possibility that we are running after CSE and there is a
461 REG_EQUAL note that is only valid if the branch has already been
462 taken. If we move the insn with the REG_EQUAL note, we may
463 fold the comparison to always be false in a later CSE pass.
464 (We could also delete the REG_NOTES when moving the insn, but it
465 seems simpler to not move it.) An exception is that we can move
466 the insn if the only note is a REG_EQUAL or REG_EQUIV whose
467 value is the same as "b".
469 INSN is the branch over the `else' part.
473 TEMP to the jump insn preceding "x = a;"
475 TEMP2 to the insn that sets "x = b;"
476 TEMP3 to the insn that sets "x = a;"
477 TEMP4 to the set of "x = b"; */
479 if (this_is_simplejump
480 && (temp3
= prev_active_insn (insn
)) != 0
481 && GET_CODE (temp3
) == INSN
482 && (temp4
= single_set (temp3
)) != 0
483 && GET_CODE (temp1
= SET_DEST (temp4
)) == REG
484 && (! SMALL_REGISTER_CLASSES
485 || REGNO (temp1
) >= FIRST_PSEUDO_REGISTER
)
486 && (temp2
= next_active_insn (insn
)) != 0
487 && GET_CODE (temp2
) == INSN
488 && (temp4
= single_set (temp2
)) != 0
489 && rtx_equal_p (SET_DEST (temp4
), temp1
)
490 && ! side_effects_p (SET_SRC (temp4
))
491 && ! may_trap_p (SET_SRC (temp4
))
492 && (REG_NOTES (temp2
) == 0
493 || ((REG_NOTE_KIND (REG_NOTES (temp2
)) == REG_EQUAL
494 || REG_NOTE_KIND (REG_NOTES (temp2
)) == REG_EQUIV
)
495 && XEXP (REG_NOTES (temp2
), 1) == 0
496 && rtx_equal_p (XEXP (REG_NOTES (temp2
), 0),
498 && (temp
= prev_active_insn (temp3
)) != 0
499 && condjump_p (temp
) && ! simplejump_p (temp
)
500 /* TEMP must skip over the "x = a;" insn */
501 && prev_real_insn (JUMP_LABEL (temp
)) == insn
502 && no_labels_between_p (insn
, JUMP_LABEL (temp
))
503 /* There must be no other entries to the "x = b;" insn. */
504 && no_labels_between_p (JUMP_LABEL (temp
), temp2
)
505 /* INSN must either branch to the insn after TEMP2 or the insn
506 after TEMP2 must branch to the same place as INSN. */
507 && (reallabelprev
== temp2
508 || ((temp5
= next_active_insn (temp2
)) != 0
509 && simplejump_p (temp5
)
510 && JUMP_LABEL (temp5
) == JUMP_LABEL (insn
))))
512 /* The test expression, X, may be a complicated test with
513 multiple branches. See if we can find all the uses of
514 the label that TEMP branches to without hitting a CALL_INSN
515 or a jump to somewhere else. */
516 rtx target
= JUMP_LABEL (temp
);
517 int nuses
= LABEL_NUSES (target
);
523 /* Set P to the first jump insn that goes around "x = a;". */
524 for (p
= temp
; nuses
&& p
; p
= prev_nonnote_insn (p
))
526 if (GET_CODE (p
) == JUMP_INSN
)
528 if (condjump_p (p
) && ! simplejump_p (p
)
529 && JUMP_LABEL (p
) == target
)
538 else if (GET_CODE (p
) == CALL_INSN
)
543 /* We cannot insert anything between a set of cc and its use
544 so if P uses cc0, we must back up to the previous insn. */
545 q
= prev_nonnote_insn (p
);
546 if (q
&& GET_RTX_CLASS (GET_CODE (q
)) == 'i'
547 && sets_cc0_p (PATTERN (q
)))
554 /* If we found all the uses and there was no data conflict, we
555 can move the assignment unless we can branch into the middle
558 && no_labels_between_p (p
, insn
)
559 && ! reg_referenced_between_p (temp1
, p
, NEXT_INSN (temp3
))
560 && ! reg_set_between_p (temp1
, p
, temp3
)
561 && (GET_CODE (SET_SRC (temp4
)) == CONST_INT
562 || ! modified_between_p (SET_SRC (temp4
), p
, temp2
))
563 /* Verify that registers used by the jump are not clobbered
564 by the instruction being moved. */
565 && ! regs_set_between_p (PATTERN (temp
),
569 emit_insn_after_with_line_notes (PATTERN (temp2
), p
, temp2
);
572 /* Set NEXT to an insn that we know won't go away. */
573 next
= next_active_insn (insn
);
575 /* Delete the jump around the set. Note that we must do
576 this before we redirect the test jumps so that it won't
577 delete the code immediately following the assignment
578 we moved (which might be a jump). */
582 /* We either have two consecutive labels or a jump to
583 a jump, so adjust all the JUMP_INSNs to branch to where
585 for (p
= NEXT_INSN (p
); p
!= next
; p
= NEXT_INSN (p
))
586 if (GET_CODE (p
) == JUMP_INSN
)
587 redirect_jump (p
, target
);
594 /* Simplify if (...) { x = a; goto l; } x = b; by converting it
595 to x = a; if (...) goto l; x = b;
596 if A is sufficiently simple, the test doesn't involve X,
597 and nothing in the test modifies A or X.
599 If we have small register classes, we also can't do this if X
602 If the "x = a;" insn has any REG_NOTES, we don't do this because
603 of the possibility that we are running after CSE and there is a
604 REG_EQUAL note that is only valid if the branch has already been
605 taken. If we move the insn with the REG_EQUAL note, we may
606 fold the comparison to always be false in a later CSE pass.
607 (We could also delete the REG_NOTES when moving the insn, but it
608 seems simpler to not move it.) An exception is that we can move
609 the insn if the only note is a REG_EQUAL or REG_EQUIV whose
610 value is the same as "a".
616 TEMP to the jump insn preceding "x = a;"
618 TEMP2 to the insn that sets "x = b;"
619 TEMP3 to the insn that sets "x = a;"
620 TEMP4 to the set of "x = a"; */
622 if (this_is_simplejump
623 && (temp2
= next_active_insn (insn
)) != 0
624 && GET_CODE (temp2
) == INSN
625 && (temp4
= single_set (temp2
)) != 0
626 && GET_CODE (temp1
= SET_DEST (temp4
)) == REG
627 && (! SMALL_REGISTER_CLASSES
628 || REGNO (temp1
) >= FIRST_PSEUDO_REGISTER
)
629 && (temp3
= prev_active_insn (insn
)) != 0
630 && GET_CODE (temp3
) == INSN
631 && (temp4
= single_set (temp3
)) != 0
632 && rtx_equal_p (SET_DEST (temp4
), temp1
)
633 && ! side_effects_p (SET_SRC (temp4
))
634 && ! may_trap_p (SET_SRC (temp4
))
635 && (REG_NOTES (temp3
) == 0
636 || ((REG_NOTE_KIND (REG_NOTES (temp3
)) == REG_EQUAL
637 || REG_NOTE_KIND (REG_NOTES (temp3
)) == REG_EQUIV
)
638 && XEXP (REG_NOTES (temp3
), 1) == 0
639 && rtx_equal_p (XEXP (REG_NOTES (temp3
), 0),
641 && (temp
= prev_active_insn (temp3
)) != 0
642 && condjump_p (temp
) && ! simplejump_p (temp
)
643 /* TEMP must skip over the "x = a;" insn */
644 && prev_real_insn (JUMP_LABEL (temp
)) == insn
645 && no_labels_between_p (temp
, insn
))
647 rtx prev_label
= JUMP_LABEL (temp
);
648 rtx insert_after
= prev_nonnote_insn (temp
);
651 /* We cannot insert anything between a set of cc and its use. */
652 if (insert_after
&& GET_RTX_CLASS (GET_CODE (insert_after
)) == 'i'
653 && sets_cc0_p (PATTERN (insert_after
)))
654 insert_after
= prev_nonnote_insn (insert_after
);
656 ++LABEL_NUSES (prev_label
);
659 && no_labels_between_p (insert_after
, temp
)
660 && ! reg_referenced_between_p (temp1
, insert_after
, temp3
)
661 && ! reg_referenced_between_p (temp1
, temp3
,
663 && ! reg_set_between_p (temp1
, insert_after
, temp
)
664 && ! modified_between_p (SET_SRC (temp4
), insert_after
, temp
)
665 /* Verify that registers used by the jump are not clobbered
666 by the instruction being moved. */
667 && ! regs_set_between_p (PATTERN (temp
),
670 && invert_jump (temp
, JUMP_LABEL (insn
)))
672 emit_insn_after_with_line_notes (PATTERN (temp3
),
673 insert_after
, temp3
);
676 /* Set NEXT to an insn that we know won't go away. */
680 if (prev_label
&& --LABEL_NUSES (prev_label
) == 0)
681 delete_insn (prev_label
);
687 /* If we have if (...) x = exp; and branches are expensive,
688 EXP is a single insn, does not have any side effects, cannot
689 trap, and is not too costly, convert this to
690 t = exp; if (...) x = t;
692 Don't do this when we have CC0 because it is unlikely to help
693 and we'd need to worry about where to place the new insn and
694 the potential for conflicts. We also can't do this when we have
695 notes on the insn for the same reason as above.
699 TEMP to the "x = exp;" insn.
700 TEMP1 to the single set in the "x = exp;" insn.
703 if (! reload_completed
704 && this_is_condjump
&& ! this_is_simplejump
706 && (temp
= next_nonnote_insn (insn
)) != 0
707 && GET_CODE (temp
) == INSN
708 && REG_NOTES (temp
) == 0
709 && (reallabelprev
== temp
710 || ((temp2
= next_active_insn (temp
)) != 0
711 && simplejump_p (temp2
)
712 && JUMP_LABEL (temp2
) == JUMP_LABEL (insn
)))
713 && (temp1
= single_set (temp
)) != 0
714 && (temp2
= SET_DEST (temp1
), GET_CODE (temp2
) == REG
)
715 && (! SMALL_REGISTER_CLASSES
716 || REGNO (temp2
) >= FIRST_PSEUDO_REGISTER
)
717 && GET_CODE (SET_SRC (temp1
)) != REG
718 && GET_CODE (SET_SRC (temp1
)) != SUBREG
719 && GET_CODE (SET_SRC (temp1
)) != CONST_INT
720 && ! side_effects_p (SET_SRC (temp1
))
721 && ! may_trap_p (SET_SRC (temp1
))
722 && rtx_cost (SET_SRC (temp1
), SET
) < 10)
724 rtx
new = gen_reg_rtx (GET_MODE (temp2
));
726 if ((temp3
= find_insert_position (insn
, temp
))
727 && validate_change (temp
, &SET_DEST (temp1
), new, 0))
729 next
= emit_insn_after (gen_move_insn (temp2
, new), insn
);
730 emit_insn_after_with_line_notes (PATTERN (temp
),
731 PREV_INSN (temp3
), temp
);
733 reallabelprev
= prev_active_insn (JUMP_LABEL (insn
));
737 reg_scan_update (temp3
, NEXT_INSN (next
), old_max_reg
);
738 old_max_reg
= max_reg_num ();
743 /* Similarly, if it takes two insns to compute EXP but they
744 have the same destination. Here TEMP3 will be the second
745 insn and TEMP4 the SET from that insn. */
747 if (! reload_completed
748 && this_is_condjump
&& ! this_is_simplejump
750 && (temp
= next_nonnote_insn (insn
)) != 0
751 && GET_CODE (temp
) == INSN
752 && REG_NOTES (temp
) == 0
753 && (temp3
= next_nonnote_insn (temp
)) != 0
754 && GET_CODE (temp3
) == INSN
755 && REG_NOTES (temp3
) == 0
756 && (reallabelprev
== temp3
757 || ((temp2
= next_active_insn (temp3
)) != 0
758 && simplejump_p (temp2
)
759 && JUMP_LABEL (temp2
) == JUMP_LABEL (insn
)))
760 && (temp1
= single_set (temp
)) != 0
761 && (temp2
= SET_DEST (temp1
), GET_CODE (temp2
) == REG
)
762 && GET_MODE_CLASS (GET_MODE (temp2
)) == MODE_INT
763 && (! SMALL_REGISTER_CLASSES
764 || REGNO (temp2
) >= FIRST_PSEUDO_REGISTER
)
765 && ! side_effects_p (SET_SRC (temp1
))
766 && ! may_trap_p (SET_SRC (temp1
))
767 && rtx_cost (SET_SRC (temp1
), SET
) < 10
768 && (temp4
= single_set (temp3
)) != 0
769 && rtx_equal_p (SET_DEST (temp4
), temp2
)
770 && ! side_effects_p (SET_SRC (temp4
))
771 && ! may_trap_p (SET_SRC (temp4
))
772 && rtx_cost (SET_SRC (temp4
), SET
) < 10)
774 rtx
new = gen_reg_rtx (GET_MODE (temp2
));
776 if ((temp5
= find_insert_position (insn
, temp
))
777 && (temp6
= find_insert_position (insn
, temp3
))
778 && validate_change (temp
, &SET_DEST (temp1
), new, 0))
780 /* Use the earliest of temp5 and temp6. */
783 next
= emit_insn_after (gen_move_insn (temp2
, new), insn
);
784 emit_insn_after_with_line_notes (PATTERN (temp
),
785 PREV_INSN (temp6
), temp
);
786 emit_insn_after_with_line_notes
787 (replace_rtx (PATTERN (temp3
), temp2
, new),
788 PREV_INSN (temp6
), temp3
);
791 reallabelprev
= prev_active_insn (JUMP_LABEL (insn
));
795 reg_scan_update (temp6
, NEXT_INSN (next
), old_max_reg
);
796 old_max_reg
= max_reg_num ();
801 /* Finally, handle the case where two insns are used to
802 compute EXP but a temporary register is used. Here we must
803 ensure that the temporary register is not used anywhere else. */
805 if (! reload_completed
807 && this_is_condjump
&& ! this_is_simplejump
809 && (temp
= next_nonnote_insn (insn
)) != 0
810 && GET_CODE (temp
) == INSN
811 && REG_NOTES (temp
) == 0
812 && (temp3
= next_nonnote_insn (temp
)) != 0
813 && GET_CODE (temp3
) == INSN
814 && REG_NOTES (temp3
) == 0
815 && (reallabelprev
== temp3
816 || ((temp2
= next_active_insn (temp3
)) != 0
817 && simplejump_p (temp2
)
818 && JUMP_LABEL (temp2
) == JUMP_LABEL (insn
)))
819 && (temp1
= single_set (temp
)) != 0
820 && (temp5
= SET_DEST (temp1
),
821 (GET_CODE (temp5
) == REG
822 || (GET_CODE (temp5
) == SUBREG
823 && (temp5
= SUBREG_REG (temp5
),
824 GET_CODE (temp5
) == REG
))))
825 && REGNO (temp5
) >= FIRST_PSEUDO_REGISTER
826 && REGNO_FIRST_UID (REGNO (temp5
)) == INSN_UID (temp
)
827 && REGNO_LAST_UID (REGNO (temp5
)) == INSN_UID (temp3
)
828 && ! side_effects_p (SET_SRC (temp1
))
829 && ! may_trap_p (SET_SRC (temp1
))
830 && rtx_cost (SET_SRC (temp1
), SET
) < 10
831 && (temp4
= single_set (temp3
)) != 0
832 && (temp2
= SET_DEST (temp4
), GET_CODE (temp2
) == REG
)
833 && GET_MODE_CLASS (GET_MODE (temp2
)) == MODE_INT
834 && (! SMALL_REGISTER_CLASSES
835 || REGNO (temp2
) >= FIRST_PSEUDO_REGISTER
)
836 && rtx_equal_p (SET_DEST (temp4
), temp2
)
837 && ! side_effects_p (SET_SRC (temp4
))
838 && ! may_trap_p (SET_SRC (temp4
))
839 && rtx_cost (SET_SRC (temp4
), SET
) < 10)
841 rtx
new = gen_reg_rtx (GET_MODE (temp2
));
843 if ((temp5
= find_insert_position (insn
, temp
))
844 && (temp6
= find_insert_position (insn
, temp3
))
845 && validate_change (temp3
, &SET_DEST (temp4
), new, 0))
847 /* Use the earliest of temp5 and temp6. */
850 next
= emit_insn_after (gen_move_insn (temp2
, new), insn
);
851 emit_insn_after_with_line_notes (PATTERN (temp
),
852 PREV_INSN (temp6
), temp
);
853 emit_insn_after_with_line_notes (PATTERN (temp3
),
854 PREV_INSN (temp6
), temp3
);
857 reallabelprev
= prev_active_insn (JUMP_LABEL (insn
));
861 reg_scan_update (temp6
, NEXT_INSN (next
), old_max_reg
);
862 old_max_reg
= max_reg_num ();
866 #endif /* HAVE_cc0 */
868 /* Try to use a conditional move (if the target has them), or a
869 store-flag insn. The general case is:
871 1) x = a; if (...) x = b; and
874 If the jump would be faster, the machine should not have defined
875 the movcc or scc insns!. These cases are often made by the
876 previous optimization.
878 The second case is treated as x = x; if (...) x = b;.
880 INSN here is the jump around the store. We set:
882 TEMP to the "x op= b;" insn.
885 TEMP3 to A (X in the second case).
886 TEMP4 to the condition being tested.
887 TEMP5 to the earliest insn used to find the condition.
888 TEMP6 to the SET of TEMP. */
890 if (/* We can't do this after reload has completed. */
892 && this_is_condjump
&& ! this_is_simplejump
893 /* Set TEMP to the "x = b;" insn. */
894 && (temp
= next_nonnote_insn (insn
)) != 0
895 && GET_CODE (temp
) == INSN
896 && (temp6
= single_set (temp
)) != NULL_RTX
897 && GET_CODE (temp1
= SET_DEST (temp6
)) == REG
898 && (! SMALL_REGISTER_CLASSES
899 || REGNO (temp1
) >= FIRST_PSEUDO_REGISTER
)
900 && ! side_effects_p (temp2
= SET_SRC (temp6
))
901 && ! may_trap_p (temp2
)
902 /* Allow either form, but prefer the former if both apply.
903 There is no point in using the old value of TEMP1 if
904 it is a register, since cse will alias them. It can
905 lose if the old value were a hard register since CSE
906 won't replace hard registers. Avoid using TEMP3 if
907 small register classes and it is a hard register. */
908 && (((temp3
= reg_set_last (temp1
, insn
)) != 0
909 && ! (SMALL_REGISTER_CLASSES
&& GET_CODE (temp3
) == REG
910 && REGNO (temp3
) < FIRST_PSEUDO_REGISTER
))
911 /* Make the latter case look like x = x; if (...) x = b; */
912 || (temp3
= temp1
, 1))
913 /* INSN must either branch to the insn after TEMP or the insn
914 after TEMP must branch to the same place as INSN. */
915 && (reallabelprev
== temp
916 || ((temp4
= next_active_insn (temp
)) != 0
917 && simplejump_p (temp4
)
918 && JUMP_LABEL (temp4
) == JUMP_LABEL (insn
)))
919 && (temp4
= get_condition (insn
, &temp5
)) != 0
920 /* We must be comparing objects whose modes imply the size.
921 We could handle BLKmode if (1) emit_store_flag could
922 and (2) we could find the size reliably. */
923 && GET_MODE (XEXP (temp4
, 0)) != BLKmode
924 /* Even if branches are cheap, the store_flag optimization
925 can win when the operation to be performed can be
926 expressed directly. */
928 /* If the previous insn sets CC0 and something else, we can't
929 do this since we are going to delete that insn. */
931 && ! ((temp6
= prev_nonnote_insn (insn
)) != 0
932 && GET_CODE (temp6
) == INSN
933 && (sets_cc0_p (PATTERN (temp6
)) == -1
934 || (sets_cc0_p (PATTERN (temp6
)) == 1
935 && FIND_REG_INC_NOTE (temp6
, NULL_RTX
))))
939 #ifdef HAVE_conditional_move
940 /* First try a conditional move. */
942 enum rtx_code code
= GET_CODE (temp4
);
944 rtx cond0
, cond1
, aval
, bval
;
945 rtx target
, new_insn
;
947 /* Copy the compared variables into cond0 and cond1, so that
948 any side effects performed in or after the old comparison,
949 will not affect our compare which will come later. */
950 /* ??? Is it possible to just use the comparison in the jump
951 insn? After all, we're going to delete it. We'd have
952 to modify emit_conditional_move to take a comparison rtx
953 instead or write a new function. */
954 cond0
= gen_reg_rtx (GET_MODE (XEXP (temp4
, 0)));
955 /* We want the target to be able to simplify comparisons with
956 zero (and maybe other constants as well), so don't create
957 pseudos for them. There's no need to either. */
958 if (GET_CODE (XEXP (temp4
, 1)) == CONST_INT
959 || GET_CODE (XEXP (temp4
, 1)) == CONST_DOUBLE
)
960 cond1
= XEXP (temp4
, 1);
962 cond1
= gen_reg_rtx (GET_MODE (XEXP (temp4
, 1)));
964 /* Careful about copying these values -- an IOR or what may
965 need to do other things, like clobber flags. */
966 /* ??? Assume for the moment that AVAL is ok. */
971 /* If we're not dealing with a register or the insn is more
972 complex than a simple SET, duplicate the computation and
973 replace the destination with a new temporary. */
974 if (register_operand (temp2
, GET_MODE (var
))
975 && GET_CODE (PATTERN (temp
)) == SET
)
979 bval
= gen_reg_rtx (GET_MODE (var
));
980 new_insn
= copy_rtx (temp
);
981 temp6
= single_set (new_insn
);
982 SET_DEST (temp6
) = bval
;
983 emit_insn (PATTERN (new_insn
));
986 target
= emit_conditional_move (var
, code
,
987 cond0
, cond1
, VOIDmode
,
988 aval
, bval
, GET_MODE (var
),
989 (code
== LTU
|| code
== GEU
990 || code
== LEU
|| code
== GTU
));
994 rtx seq1
, seq2
, last
;
997 /* Save the conditional move sequence but don't emit it
998 yet. On some machines, like the alpha, it is possible
999 that temp5 == insn, so next generate the sequence that
1000 saves the compared values and then emit both
1001 sequences ensuring seq1 occurs before seq2. */
1002 seq2
= get_insns ();
1005 /* "Now that we can't fail..." Famous last words.
1006 Generate the copy insns that preserve the compared
1009 emit_move_insn (cond0
, XEXP (temp4
, 0));
1010 if (cond1
!= XEXP (temp4
, 1))
1011 emit_move_insn (cond1
, XEXP (temp4
, 1));
1012 seq1
= get_insns ();
1015 /* Validate the sequence -- this may be some weird
1016 bit-extract-and-test instruction for which there
1017 exists no complimentary bit-extract insn. */
1019 for (last
= seq1
; last
; last
= NEXT_INSN (last
))
1020 if (recog_memoized (last
) < 0)
1028 emit_insns_before (seq1
, temp5
);
1030 /* Insert conditional move after insn, to be sure
1031 that the jump and a possible compare won't be
1033 last
= emit_insns_after (seq2
, insn
);
1035 /* ??? We can also delete the insn that sets X to A.
1036 Flow will do it too though. */
1038 next
= NEXT_INSN (insn
);
1043 reg_scan_update (seq1
, NEXT_INSN (last
),
1045 old_max_reg
= max_reg_num ();
1057 /* That didn't work, try a store-flag insn.
1059 We further divide the cases into:
1061 1) x = a; if (...) x = b; and either A or B is zero,
1062 2) if (...) x = 0; and jumps are expensive,
1063 3) x = a; if (...) x = b; and A and B are constants where all
1064 the set bits in A are also set in B and jumps are expensive,
1065 4) x = a; if (...) x = b; and A and B non-zero, and jumps are
1067 5) if (...) x = b; if jumps are even more expensive. */
1069 if (GET_MODE_CLASS (GET_MODE (temp1
)) == MODE_INT
1070 && ((GET_CODE (temp3
) == CONST_INT
)
1071 /* Make the latter case look like
1072 x = x; if (...) x = 0; */
1075 && temp2
== const0_rtx
)
1076 || BRANCH_COST
>= 3)))
1077 /* If B is zero, OK; if A is zero, can only do (1) if we
1078 can reverse the condition. See if (3) applies possibly
1079 by reversing the condition. Prefer reversing to (4) when
1080 branches are very expensive. */
1081 && (((BRANCH_COST
>= 2
1082 || STORE_FLAG_VALUE
== -1
1083 || (STORE_FLAG_VALUE
== 1
1084 /* Check that the mask is a power of two,
1085 so that it can probably be generated
1087 && GET_CODE (temp3
) == CONST_INT
1088 && exact_log2 (INTVAL (temp3
)) >= 0))
1089 && (reversep
= 0, temp2
== const0_rtx
))
1090 || ((BRANCH_COST
>= 2
1091 || STORE_FLAG_VALUE
== -1
1092 || (STORE_FLAG_VALUE
== 1
1093 && GET_CODE (temp2
) == CONST_INT
1094 && exact_log2 (INTVAL (temp2
)) >= 0))
1095 && temp3
== const0_rtx
1096 && (reversep
= can_reverse_comparison_p (temp4
, insn
)))
1097 || (BRANCH_COST
>= 2
1098 && GET_CODE (temp2
) == CONST_INT
1099 && GET_CODE (temp3
) == CONST_INT
1100 && ((INTVAL (temp2
) & INTVAL (temp3
)) == INTVAL (temp2
)
1101 || ((INTVAL (temp2
) & INTVAL (temp3
)) == INTVAL (temp3
)
1102 && (reversep
= can_reverse_comparison_p (temp4
,
1104 || BRANCH_COST
>= 3)
1107 enum rtx_code code
= GET_CODE (temp4
);
1108 rtx uval
, cval
, var
= temp1
;
1112 /* If necessary, reverse the condition. */
1114 code
= reverse_condition (code
), uval
= temp2
, cval
= temp3
;
1116 uval
= temp3
, cval
= temp2
;
1118 /* If CVAL is non-zero, normalize to -1. Otherwise, if UVAL
1119 is the constant 1, it is best to just compute the result
1120 directly. If UVAL is constant and STORE_FLAG_VALUE
1121 includes all of its bits, it is best to compute the flag
1122 value unnormalized and `and' it with UVAL. Otherwise,
1123 normalize to -1 and `and' with UVAL. */
1124 normalizep
= (cval
!= const0_rtx
? -1
1125 : (uval
== const1_rtx
? 1
1126 : (GET_CODE (uval
) == CONST_INT
1127 && (INTVAL (uval
) & ~STORE_FLAG_VALUE
) == 0)
1130 /* We will be putting the store-flag insn immediately in
1131 front of the comparison that was originally being done,
1132 so we know all the variables in TEMP4 will be valid.
1133 However, this might be in front of the assignment of
1134 A to VAR. If it is, it would clobber the store-flag
1135 we will be emitting.
1137 Therefore, emit into a temporary which will be copied to
1138 VAR immediately after TEMP. */
1141 target
= emit_store_flag (gen_reg_rtx (GET_MODE (var
)), code
,
1142 XEXP (temp4
, 0), XEXP (temp4
, 1),
1144 (code
== LTU
|| code
== LEU
1145 || code
== GEU
|| code
== GTU
),
1155 /* Put the store-flag insns in front of the first insn
1156 used to compute the condition to ensure that we
1157 use the same values of them as the current
1158 comparison. However, the remainder of the insns we
1159 generate will be placed directly in front of the
1160 jump insn, in case any of the pseudos we use
1161 are modified earlier. */
1163 emit_insns_before (seq
, temp5
);
1167 /* Both CVAL and UVAL are non-zero. */
1168 if (cval
!= const0_rtx
&& uval
!= const0_rtx
)
1172 tem1
= expand_and (uval
, target
, NULL_RTX
);
1173 if (GET_CODE (cval
) == CONST_INT
1174 && GET_CODE (uval
) == CONST_INT
1175 && (INTVAL (cval
) & INTVAL (uval
)) == INTVAL (cval
))
1179 tem2
= expand_unop (GET_MODE (var
), one_cmpl_optab
,
1180 target
, NULL_RTX
, 0);
1181 tem2
= expand_and (cval
, tem2
,
1182 (GET_CODE (tem2
) == REG
1186 /* If we usually make new pseudos, do so here. This
1187 turns out to help machines that have conditional
1189 /* ??? Conditional moves have already been handled.
1190 This may be obsolete. */
1192 if (flag_expensive_optimizations
)
1195 target
= expand_binop (GET_MODE (var
), ior_optab
,
1199 else if (normalizep
!= 1)
1201 /* We know that either CVAL or UVAL is zero. If
1202 UVAL is zero, negate TARGET and `and' with CVAL.
1203 Otherwise, `and' with UVAL. */
1204 if (uval
== const0_rtx
)
1206 target
= expand_unop (GET_MODE (var
), one_cmpl_optab
,
1207 target
, NULL_RTX
, 0);
1211 target
= expand_and (uval
, target
,
1212 (GET_CODE (target
) == REG
1213 && ! preserve_subexpressions_p ()
1214 ? target
: NULL_RTX
));
1217 emit_move_insn (var
, target
);
1221 /* If INSN uses CC0, we must not separate it from the
1222 insn that sets cc0. */
1223 if (reg_mentioned_p (cc0_rtx
, PATTERN (before
)))
1224 before
= prev_nonnote_insn (before
);
1226 emit_insns_before (seq
, before
);
1229 next
= NEXT_INSN (insn
);
1234 reg_scan_update (seq
, NEXT_INSN (next
), old_max_reg
);
1235 old_max_reg
= max_reg_num ();
1246 /* If branches are expensive, convert
1247 if (foo) bar++; to bar += (foo != 0);
1248 and similarly for "bar--;"
1250 INSN is the conditional branch around the arithmetic. We set:
1252 TEMP is the arithmetic insn.
1253 TEMP1 is the SET doing the arithmetic.
1254 TEMP2 is the operand being incremented or decremented.
1255 TEMP3 to the condition being tested.
1256 TEMP4 to the earliest insn used to find the condition. */
1258 if ((BRANCH_COST
>= 2
1266 && ! reload_completed
1267 && this_is_condjump
&& ! this_is_simplejump
1268 && (temp
= next_nonnote_insn (insn
)) != 0
1269 && (temp1
= single_set (temp
)) != 0
1270 && (temp2
= SET_DEST (temp1
),
1271 GET_MODE_CLASS (GET_MODE (temp2
)) == MODE_INT
)
1272 && GET_CODE (SET_SRC (temp1
)) == PLUS
1273 && (XEXP (SET_SRC (temp1
), 1) == const1_rtx
1274 || XEXP (SET_SRC (temp1
), 1) == constm1_rtx
)
1275 && rtx_equal_p (temp2
, XEXP (SET_SRC (temp1
), 0))
1276 && ! side_effects_p (temp2
)
1277 && ! may_trap_p (temp2
)
1278 /* INSN must either branch to the insn after TEMP or the insn
1279 after TEMP must branch to the same place as INSN. */
1280 && (reallabelprev
== temp
1281 || ((temp3
= next_active_insn (temp
)) != 0
1282 && simplejump_p (temp3
)
1283 && JUMP_LABEL (temp3
) == JUMP_LABEL (insn
)))
1284 && (temp3
= get_condition (insn
, &temp4
)) != 0
1285 /* We must be comparing objects whose modes imply the size.
1286 We could handle BLKmode if (1) emit_store_flag could
1287 and (2) we could find the size reliably. */
1288 && GET_MODE (XEXP (temp3
, 0)) != BLKmode
1289 && can_reverse_comparison_p (temp3
, insn
))
1291 rtx temp6
, target
= 0, seq
, init_insn
= 0, init
= temp2
;
1292 enum rtx_code code
= reverse_condition (GET_CODE (temp3
));
1296 /* It must be the case that TEMP2 is not modified in the range
1297 [TEMP4, INSN). The one exception we make is if the insn
1298 before INSN sets TEMP2 to something which is also unchanged
1299 in that range. In that case, we can move the initialization
1300 into our sequence. */
1302 if ((temp5
= prev_active_insn (insn
)) != 0
1303 && no_labels_between_p (temp5
, insn
)
1304 && GET_CODE (temp5
) == INSN
1305 && (temp6
= single_set (temp5
)) != 0
1306 && rtx_equal_p (temp2
, SET_DEST (temp6
))
1307 && (CONSTANT_P (SET_SRC (temp6
))
1308 || GET_CODE (SET_SRC (temp6
)) == REG
1309 || GET_CODE (SET_SRC (temp6
)) == SUBREG
))
1311 emit_insn (PATTERN (temp5
));
1313 init
= SET_SRC (temp6
);
1316 if (CONSTANT_P (init
)
1317 || ! reg_set_between_p (init
, PREV_INSN (temp4
), insn
))
1318 target
= emit_store_flag (gen_reg_rtx (GET_MODE (temp2
)), code
,
1319 XEXP (temp3
, 0), XEXP (temp3
, 1),
1321 (code
== LTU
|| code
== LEU
1322 || code
== GTU
|| code
== GEU
), 1);
1324 /* If we can do the store-flag, do the addition or
1328 target
= expand_binop (GET_MODE (temp2
),
1329 (XEXP (SET_SRC (temp1
), 1) == const1_rtx
1330 ? add_optab
: sub_optab
),
1331 temp2
, target
, temp2
, 0, OPTAB_WIDEN
);
1335 /* Put the result back in temp2 in case it isn't already.
1336 Then replace the jump, possible a CC0-setting insn in
1337 front of the jump, and TEMP, with the sequence we have
1340 if (target
!= temp2
)
1341 emit_move_insn (temp2
, target
);
1346 emit_insns_before (seq
, temp4
);
1350 delete_insn (init_insn
);
1352 next
= NEXT_INSN (insn
);
1354 delete_insn (prev_nonnote_insn (insn
));
1360 reg_scan_update (seq
, NEXT_INSN (next
), old_max_reg
);
1361 old_max_reg
= max_reg_num ();
1371 /* Simplify if (...) x = 1; else {...} if (x) ...
1372 We recognize this case scanning backwards as well.
1374 TEMP is the assignment to x;
1375 TEMP1 is the label at the head of the second if. */
1376 /* ?? This should call get_condition to find the values being
1377 compared, instead of looking for a COMPARE insn when HAVE_cc0
1378 is not defined. This would allow it to work on the m88k. */
1379 /* ?? This optimization is only safe before cse is run if HAVE_cc0
1380 is not defined and the condition is tested by a separate compare
1381 insn. This is because the code below assumes that the result
1382 of the compare dies in the following branch.
1384 Not only that, but there might be other insns between the
1385 compare and branch whose results are live. Those insns need
1388 A way to fix this is to move the insns at JUMP_LABEL (insn)
1389 to before INSN. If we are running before flow, they will
1390 be deleted if they aren't needed. But this doesn't work
1393 This is really a special-case of jump threading, anyway. The
1394 right thing to do is to replace this and jump threading with
1395 much simpler code in cse.
1397 This code has been turned off in the non-cc0 case in the
1401 else if (this_is_simplejump
1402 /* Safe to skip USE and CLOBBER insns here
1403 since they will not be deleted. */
1404 && (temp
= prev_active_insn (insn
))
1405 && no_labels_between_p (temp
, insn
)
1406 && GET_CODE (temp
) == INSN
1407 && GET_CODE (PATTERN (temp
)) == SET
1408 && GET_CODE (SET_DEST (PATTERN (temp
))) == REG
1409 && CONSTANT_P (SET_SRC (PATTERN (temp
)))
1410 && (temp1
= next_active_insn (JUMP_LABEL (insn
)))
1411 /* If we find that the next value tested is `x'
1412 (TEMP1 is the insn where this happens), win. */
1413 && GET_CODE (temp1
) == INSN
1414 && GET_CODE (PATTERN (temp1
)) == SET
1416 /* Does temp1 `tst' the value of x? */
1417 && SET_SRC (PATTERN (temp1
)) == SET_DEST (PATTERN (temp
))
1418 && SET_DEST (PATTERN (temp1
)) == cc0_rtx
1419 && (temp1
= next_nonnote_insn (temp1
))
1421 /* Does temp1 compare the value of x against zero? */
1422 && GET_CODE (SET_SRC (PATTERN (temp1
))) == COMPARE
1423 && XEXP (SET_SRC (PATTERN (temp1
)), 1) == const0_rtx
1424 && (XEXP (SET_SRC (PATTERN (temp1
)), 0)
1425 == SET_DEST (PATTERN (temp
)))
1426 && GET_CODE (SET_DEST (PATTERN (temp1
))) == REG
1427 && (temp1
= find_next_ref (SET_DEST (PATTERN (temp1
)), temp1
))
1429 && condjump_p (temp1
))
1431 /* Get the if_then_else from the condjump. */
1432 rtx choice
= SET_SRC (PATTERN (temp1
));
1433 if (GET_CODE (choice
) == IF_THEN_ELSE
)
1435 enum rtx_code code
= GET_CODE (XEXP (choice
, 0));
1436 rtx val
= SET_SRC (PATTERN (temp
));
1438 = simplify_relational_operation (code
, GET_MODE (SET_DEST (PATTERN (temp
))),
1442 if (cond
== const_true_rtx
)
1443 ultimate
= XEXP (choice
, 1);
1444 else if (cond
== const0_rtx
)
1445 ultimate
= XEXP (choice
, 2);
1449 if (ultimate
== pc_rtx
)
1450 ultimate
= get_label_after (temp1
);
1451 else if (ultimate
&& GET_CODE (ultimate
) != RETURN
)
1452 ultimate
= XEXP (ultimate
, 0);
1454 if (ultimate
&& JUMP_LABEL(insn
) != ultimate
)
1455 changed
|= redirect_jump (insn
, ultimate
);
1461 /* @@ This needs a bit of work before it will be right.
1463 Any type of comparison can be accepted for the first and
1464 second compare. When rewriting the first jump, we must
1465 compute the what conditions can reach label3, and use the
1466 appropriate code. We can not simply reverse/swap the code
1467 of the first jump. In some cases, the second jump must be
1471 < == converts to > ==
1472 < != converts to == >
1475 If the code is written to only accept an '==' test for the second
1476 compare, then all that needs to be done is to swap the condition
1477 of the first branch.
1479 It is questionable whether we want this optimization anyways,
1480 since if the user wrote code like this because he/she knew that
1481 the jump to label1 is taken most of the time, then rewriting
1482 this gives slower code. */
1483 /* @@ This should call get_condition to find the values being
1484 compared, instead of looking for a COMPARE insn when HAVE_cc0
1485 is not defined. This would allow it to work on the m88k. */
1486 /* @@ This optimization is only safe before cse is run if HAVE_cc0
1487 is not defined and the condition is tested by a separate compare
1488 insn. This is because the code below assumes that the result
1489 of the compare dies in the following branch. */
1491 /* Simplify test a ~= b
1505 where ~= is an inequality, e.g. >, and ~~= is the swapped
1508 We recognize this case scanning backwards.
1510 TEMP is the conditional jump to `label2';
1511 TEMP1 is the test for `a == b';
1512 TEMP2 is the conditional jump to `label1';
1513 TEMP3 is the test for `a ~= b'. */
1514 else if (this_is_simplejump
1515 && (temp
= prev_active_insn (insn
))
1516 && no_labels_between_p (temp
, insn
)
1517 && condjump_p (temp
)
1518 && (temp1
= prev_active_insn (temp
))
1519 && no_labels_between_p (temp1
, temp
)
1520 && GET_CODE (temp1
) == INSN
1521 && GET_CODE (PATTERN (temp1
)) == SET
1523 && sets_cc0_p (PATTERN (temp1
)) == 1
1525 && GET_CODE (SET_SRC (PATTERN (temp1
))) == COMPARE
1526 && GET_CODE (SET_DEST (PATTERN (temp1
))) == REG
1527 && (temp
== find_next_ref (SET_DEST (PATTERN (temp1
)), temp1
))
1529 && (temp2
= prev_active_insn (temp1
))
1530 && no_labels_between_p (temp2
, temp1
)
1531 && condjump_p (temp2
)
1532 && JUMP_LABEL (temp2
) == next_nonnote_insn (NEXT_INSN (insn
))
1533 && (temp3
= prev_active_insn (temp2
))
1534 && no_labels_between_p (temp3
, temp2
)
1535 && GET_CODE (PATTERN (temp3
)) == SET
1536 && rtx_equal_p (SET_DEST (PATTERN (temp3
)),
1537 SET_DEST (PATTERN (temp1
)))
1538 && rtx_equal_p (SET_SRC (PATTERN (temp1
)),
1539 SET_SRC (PATTERN (temp3
)))
1540 && ! inequality_comparisons_p (PATTERN (temp
))
1541 && inequality_comparisons_p (PATTERN (temp2
)))
1543 rtx fallthrough_label
= JUMP_LABEL (temp2
);
1545 ++LABEL_NUSES (fallthrough_label
);
1546 if (swap_jump (temp2
, JUMP_LABEL (insn
)))
1552 if (--LABEL_NUSES (fallthrough_label
) == 0)
1553 delete_insn (fallthrough_label
);
1556 /* Simplify if (...) {... x = 1;} if (x) ...
1558 We recognize this case backwards.
1560 TEMP is the test of `x';
1561 TEMP1 is the assignment to `x' at the end of the
1562 previous statement. */
1563 /* @@ This should call get_condition to find the values being
1564 compared, instead of looking for a COMPARE insn when HAVE_cc0
1565 is not defined. This would allow it to work on the m88k. */
1566 /* @@ This optimization is only safe before cse is run if HAVE_cc0
1567 is not defined and the condition is tested by a separate compare
1568 insn. This is because the code below assumes that the result
1569 of the compare dies in the following branch. */
1571 /* ??? This has to be turned off. The problem is that the
1572 unconditional jump might indirectly end up branching to the
1573 label between TEMP1 and TEMP. We can't detect this, in general,
1574 since it may become a jump to there after further optimizations.
1575 If that jump is done, it will be deleted, so we will retry
1576 this optimization in the next pass, thus an infinite loop.
1578 The present code prevents this by putting the jump after the
1579 label, but this is not logically correct. */
1581 else if (this_is_condjump
1582 /* Safe to skip USE and CLOBBER insns here
1583 since they will not be deleted. */
1584 && (temp
= prev_active_insn (insn
))
1585 && no_labels_between_p (temp
, insn
)
1586 && GET_CODE (temp
) == INSN
1587 && GET_CODE (PATTERN (temp
)) == SET
1589 && sets_cc0_p (PATTERN (temp
)) == 1
1590 && GET_CODE (SET_SRC (PATTERN (temp
))) == REG
1592 /* Temp must be a compare insn, we can not accept a register
1593 to register move here, since it may not be simply a
1595 && GET_CODE (SET_SRC (PATTERN (temp
))) == COMPARE
1596 && XEXP (SET_SRC (PATTERN (temp
)), 1) == const0_rtx
1597 && GET_CODE (XEXP (SET_SRC (PATTERN (temp
)), 0)) == REG
1598 && GET_CODE (SET_DEST (PATTERN (temp
))) == REG
1599 && insn
== find_next_ref (SET_DEST (PATTERN (temp
)), temp
)
1601 /* May skip USE or CLOBBER insns here
1602 for checking for opportunity, since we
1603 take care of them later. */
1604 && (temp1
= prev_active_insn (temp
))
1605 && GET_CODE (temp1
) == INSN
1606 && GET_CODE (PATTERN (temp1
)) == SET
1608 && SET_SRC (PATTERN (temp
)) == SET_DEST (PATTERN (temp1
))
1610 && (XEXP (SET_SRC (PATTERN (temp
)), 0)
1611 == SET_DEST (PATTERN (temp1
)))
1613 && CONSTANT_P (SET_SRC (PATTERN (temp1
)))
1614 /* If this isn't true, cse will do the job. */
1615 && ! no_labels_between_p (temp1
, temp
))
1617 /* Get the if_then_else from the condjump. */
1618 rtx choice
= SET_SRC (PATTERN (insn
));
1619 if (GET_CODE (choice
) == IF_THEN_ELSE
1620 && (GET_CODE (XEXP (choice
, 0)) == EQ
1621 || GET_CODE (XEXP (choice
, 0)) == NE
))
1623 int want_nonzero
= (GET_CODE (XEXP (choice
, 0)) == NE
);
1628 /* Get the place that condjump will jump to
1629 if it is reached from here. */
1630 if ((SET_SRC (PATTERN (temp1
)) != const0_rtx
)
1632 ultimate
= XEXP (choice
, 1);
1634 ultimate
= XEXP (choice
, 2);
1635 /* Get it as a CODE_LABEL. */
1636 if (ultimate
== pc_rtx
)
1637 ultimate
= get_label_after (insn
);
1639 /* Get the label out of the LABEL_REF. */
1640 ultimate
= XEXP (ultimate
, 0);
1642 /* Insert the jump immediately before TEMP, specifically
1643 after the label that is between TEMP1 and TEMP. */
1644 last_insn
= PREV_INSN (temp
);
1646 /* If we would be branching to the next insn, the jump
1647 would immediately be deleted and the re-inserted in
1648 a subsequent pass over the code. So don't do anything
1650 if (next_active_insn (last_insn
)
1651 != next_active_insn (ultimate
))
1653 emit_barrier_after (last_insn
);
1654 p
= emit_jump_insn_after (gen_jump (ultimate
),
1656 JUMP_LABEL (p
) = ultimate
;
1657 ++LABEL_NUSES (ultimate
);
1658 if (INSN_UID (ultimate
) < max_jump_chain
1659 && INSN_CODE (p
) < max_jump_chain
)
1661 jump_chain
[INSN_UID (p
)]
1662 = jump_chain
[INSN_UID (ultimate
)];
1663 jump_chain
[INSN_UID (ultimate
)] = p
;
1671 /* Detect a conditional jump going to the same place
1672 as an immediately following unconditional jump. */
1673 else if (this_is_condjump
1674 && (temp
= next_active_insn (insn
)) != 0
1675 && simplejump_p (temp
)
1676 && (next_active_insn (JUMP_LABEL (insn
))
1677 == next_active_insn (JUMP_LABEL (temp
))))
1681 /* ??? Optional. Disables some optimizations, but makes
1682 gcov output more accurate with -O. */
1683 if (flag_test_coverage
&& !reload_completed
)
1684 for (tem
= insn
; tem
!= temp
; tem
= NEXT_INSN (tem
))
1685 if (GET_CODE (tem
) == NOTE
&& NOTE_LINE_NUMBER (tem
) > 0)
1696 /* Detect a conditional jump jumping over an unconditional trap. */
1698 && this_is_condjump
&& ! this_is_simplejump
1699 && reallabelprev
!= 0
1700 && GET_CODE (reallabelprev
) == INSN
1701 && GET_CODE (PATTERN (reallabelprev
)) == TRAP_IF
1702 && TRAP_CONDITION (PATTERN (reallabelprev
)) == const_true_rtx
1703 && prev_active_insn (reallabelprev
) == insn
1704 && no_labels_between_p (insn
, reallabelprev
)
1705 && (temp2
= get_condition (insn
, &temp4
))
1706 && can_reverse_comparison_p (temp2
, insn
))
1708 rtx
new = gen_cond_trap (reverse_condition (GET_CODE (temp2
)),
1709 XEXP (temp2
, 0), XEXP (temp2
, 1),
1710 TRAP_CODE (PATTERN (reallabelprev
)));
1714 emit_insn_before (new, temp4
);
1715 delete_insn (reallabelprev
);
1721 /* Detect a jump jumping to an unconditional trap. */
1722 else if (HAVE_trap
&& this_is_condjump
1723 && (temp
= next_active_insn (JUMP_LABEL (insn
)))
1724 && GET_CODE (temp
) == INSN
1725 && GET_CODE (PATTERN (temp
)) == TRAP_IF
1726 && (this_is_simplejump
1727 || (temp2
= get_condition (insn
, &temp4
))))
1729 rtx tc
= TRAP_CONDITION (PATTERN (temp
));
1731 if (tc
== const_true_rtx
1732 || (! this_is_simplejump
&& rtx_equal_p (temp2
, tc
)))
1735 /* Replace an unconditional jump to a trap with a trap. */
1736 if (this_is_simplejump
)
1738 emit_barrier_after (emit_insn_before (gen_trap (), insn
));
1743 new = gen_cond_trap (GET_CODE (temp2
), XEXP (temp2
, 0),
1745 TRAP_CODE (PATTERN (temp
)));
1748 emit_insn_before (new, temp4
);
1754 /* If the trap condition and jump condition are mutually
1755 exclusive, redirect the jump to the following insn. */
1756 else if (GET_RTX_CLASS (GET_CODE (tc
)) == '<'
1757 && ! this_is_simplejump
1758 && swap_condition (GET_CODE (temp2
)) == GET_CODE (tc
)
1759 && rtx_equal_p (XEXP (tc
, 0), XEXP (temp2
, 0))
1760 && rtx_equal_p (XEXP (tc
, 1), XEXP (temp2
, 1))
1761 && redirect_jump (insn
, get_label_after (temp
)))
1769 /* Detect a conditional jump jumping over an unconditional jump. */
1771 else if ((this_is_condjump
|| this_is_condjump_in_parallel
)
1772 && ! this_is_simplejump
1773 && reallabelprev
!= 0
1774 && GET_CODE (reallabelprev
) == JUMP_INSN
1775 && prev_active_insn (reallabelprev
) == insn
1776 && no_labels_between_p (insn
, reallabelprev
)
1777 && simplejump_p (reallabelprev
))
1779 /* When we invert the unconditional jump, we will be
1780 decrementing the usage count of its old label.
1781 Make sure that we don't delete it now because that
1782 might cause the following code to be deleted. */
1783 rtx prev_uses
= prev_nonnote_insn (reallabelprev
);
1784 rtx prev_label
= JUMP_LABEL (insn
);
1787 ++LABEL_NUSES (prev_label
);
1789 if (invert_jump (insn
, JUMP_LABEL (reallabelprev
)))
1791 /* It is very likely that if there are USE insns before
1792 this jump, they hold REG_DEAD notes. These REG_DEAD
1793 notes are no longer valid due to this optimization,
1794 and will cause the life-analysis that following passes
1795 (notably delayed-branch scheduling) to think that
1796 these registers are dead when they are not.
1798 To prevent this trouble, we just remove the USE insns
1799 from the insn chain. */
1801 while (prev_uses
&& GET_CODE (prev_uses
) == INSN
1802 && GET_CODE (PATTERN (prev_uses
)) == USE
)
1804 rtx useless
= prev_uses
;
1805 prev_uses
= prev_nonnote_insn (prev_uses
);
1806 delete_insn (useless
);
1809 delete_insn (reallabelprev
);
1814 /* We can now safely delete the label if it is unreferenced
1815 since the delete_insn above has deleted the BARRIER. */
1816 if (prev_label
&& --LABEL_NUSES (prev_label
) == 0)
1817 delete_insn (prev_label
);
1822 /* Detect a jump to a jump. */
1824 nlabel
= follow_jumps (JUMP_LABEL (insn
));
1825 if (nlabel
!= JUMP_LABEL (insn
)
1826 && redirect_jump (insn
, nlabel
))
1832 /* Look for if (foo) bar; else break; */
1833 /* The insns look like this:
1834 insn = condjump label1;
1835 ...range1 (some insns)...
1838 ...range2 (some insns)...
1839 jump somewhere unconditionally
1842 rtx label1
= next_label (insn
);
1843 rtx range1end
= label1
? prev_active_insn (label1
) : 0;
1844 /* Don't do this optimization on the first round, so that
1845 jump-around-a-jump gets simplified before we ask here
1846 whether a jump is unconditional.
1848 Also don't do it when we are called after reload since
1849 it will confuse reorg. */
1851 && (reload_completed
? ! flag_delayed_branch
: 1)
1852 /* Make sure INSN is something we can invert. */
1853 && condjump_p (insn
)
1855 && JUMP_LABEL (insn
) == label1
1856 && LABEL_NUSES (label1
) == 1
1857 && GET_CODE (range1end
) == JUMP_INSN
1858 && simplejump_p (range1end
))
1860 rtx label2
= next_label (label1
);
1861 rtx range2end
= label2
? prev_active_insn (label2
) : 0;
1862 if (range1end
!= range2end
1863 && JUMP_LABEL (range1end
) == label2
1864 && GET_CODE (range2end
) == JUMP_INSN
1865 && GET_CODE (NEXT_INSN (range2end
)) == BARRIER
1866 /* Invert the jump condition, so we
1867 still execute the same insns in each case. */
1868 && invert_jump (insn
, label1
))
1870 rtx range1beg
= next_active_insn (insn
);
1871 rtx range2beg
= next_active_insn (label1
);
1872 rtx range1after
, range2after
;
1873 rtx range1before
, range2before
;
1876 /* Include in each range any notes before it, to be
1877 sure that we get the line number note if any, even
1878 if there are other notes here. */
1879 while (PREV_INSN (range1beg
)
1880 && GET_CODE (PREV_INSN (range1beg
)) == NOTE
)
1881 range1beg
= PREV_INSN (range1beg
);
1883 while (PREV_INSN (range2beg
)
1884 && GET_CODE (PREV_INSN (range2beg
)) == NOTE
)
1885 range2beg
= PREV_INSN (range2beg
);
1887 /* Don't move NOTEs for blocks or loops; shift them
1888 outside the ranges, where they'll stay put. */
1889 range1beg
= squeeze_notes (range1beg
, range1end
);
1890 range2beg
= squeeze_notes (range2beg
, range2end
);
1892 /* Get current surrounds of the 2 ranges. */
1893 range1before
= PREV_INSN (range1beg
);
1894 range2before
= PREV_INSN (range2beg
);
1895 range1after
= NEXT_INSN (range1end
);
1896 range2after
= NEXT_INSN (range2end
);
1898 /* Splice range2 where range1 was. */
1899 NEXT_INSN (range1before
) = range2beg
;
1900 PREV_INSN (range2beg
) = range1before
;
1901 NEXT_INSN (range2end
) = range1after
;
1902 PREV_INSN (range1after
) = range2end
;
1903 /* Splice range1 where range2 was. */
1904 NEXT_INSN (range2before
) = range1beg
;
1905 PREV_INSN (range1beg
) = range2before
;
1906 NEXT_INSN (range1end
) = range2after
;
1907 PREV_INSN (range2after
) = range1end
;
1909 /* Check for a loop end note between the end of
1910 range2, and the next code label. If there is one,
1911 then what we have really seen is
1912 if (foo) break; end_of_loop;
1913 and moved the break sequence outside the loop.
1914 We must move the LOOP_END note to where the
1915 loop really ends now, or we will confuse loop
1916 optimization. Stop if we find a LOOP_BEG note
1917 first, since we don't want to move the LOOP_END
1918 note in that case. */
1919 for (;range2after
!= label2
; range2after
= rangenext
)
1921 rangenext
= NEXT_INSN (range2after
);
1922 if (GET_CODE (range2after
) == NOTE
)
1924 if (NOTE_LINE_NUMBER (range2after
)
1925 == NOTE_INSN_LOOP_END
)
1927 NEXT_INSN (PREV_INSN (range2after
))
1929 PREV_INSN (rangenext
)
1930 = PREV_INSN (range2after
);
1931 PREV_INSN (range2after
)
1932 = PREV_INSN (range1beg
);
1933 NEXT_INSN (range2after
) = range1beg
;
1934 NEXT_INSN (PREV_INSN (range1beg
))
1936 PREV_INSN (range1beg
) = range2after
;
1938 else if (NOTE_LINE_NUMBER (range2after
)
1939 == NOTE_INSN_LOOP_BEG
)
1949 /* Now that the jump has been tensioned,
1950 try cross jumping: check for identical code
1951 before the jump and before its target label. */
1953 /* First, cross jumping of conditional jumps: */
1955 if (cross_jump
&& condjump_p (insn
))
1957 rtx newjpos
, newlpos
;
1958 rtx x
= prev_real_insn (JUMP_LABEL (insn
));
1960 /* A conditional jump may be crossjumped
1961 only if the place it jumps to follows
1962 an opposing jump that comes back here. */
1964 if (x
!= 0 && ! jump_back_p (x
, insn
))
1965 /* We have no opposing jump;
1966 cannot cross jump this insn. */
1970 /* TARGET is nonzero if it is ok to cross jump
1971 to code before TARGET. If so, see if matches. */
1973 find_cross_jump (insn
, x
, 2,
1974 &newjpos
, &newlpos
);
1978 do_cross_jump (insn
, newjpos
, newlpos
);
1979 /* Make the old conditional jump
1980 into an unconditional one. */
1981 SET_SRC (PATTERN (insn
))
1982 = gen_rtx_LABEL_REF (VOIDmode
, JUMP_LABEL (insn
));
1983 INSN_CODE (insn
) = -1;
1984 emit_barrier_after (insn
);
1985 /* Add to jump_chain unless this is a new label
1986 whose UID is too large. */
1987 if (INSN_UID (JUMP_LABEL (insn
)) < max_jump_chain
)
1989 jump_chain
[INSN_UID (insn
)]
1990 = jump_chain
[INSN_UID (JUMP_LABEL (insn
))];
1991 jump_chain
[INSN_UID (JUMP_LABEL (insn
))] = insn
;
1998 /* Cross jumping of unconditional jumps:
1999 a few differences. */
2001 if (cross_jump
&& simplejump_p (insn
))
2003 rtx newjpos
, newlpos
;
2008 /* TARGET is nonzero if it is ok to cross jump
2009 to code before TARGET. If so, see if matches. */
2010 find_cross_jump (insn
, JUMP_LABEL (insn
), 1,
2011 &newjpos
, &newlpos
);
2013 /* If cannot cross jump to code before the label,
2014 see if we can cross jump to another jump to
2016 /* Try each other jump to this label. */
2017 if (INSN_UID (JUMP_LABEL (insn
)) < max_uid
)
2018 for (target
= jump_chain
[INSN_UID (JUMP_LABEL (insn
))];
2019 target
!= 0 && newjpos
== 0;
2020 target
= jump_chain
[INSN_UID (target
)])
2022 && JUMP_LABEL (target
) == JUMP_LABEL (insn
)
2023 /* Ignore TARGET if it's deleted. */
2024 && ! INSN_DELETED_P (target
))
2025 find_cross_jump (insn
, target
, 2,
2026 &newjpos
, &newlpos
);
2030 do_cross_jump (insn
, newjpos
, newlpos
);
2036 /* This code was dead in the previous jump.c! */
2037 if (cross_jump
&& GET_CODE (PATTERN (insn
)) == RETURN
)
2039 /* Return insns all "jump to the same place"
2040 so we can cross-jump between any two of them. */
2042 rtx newjpos
, newlpos
, target
;
2046 /* If cannot cross jump to code before the label,
2047 see if we can cross jump to another jump to
2049 /* Try each other jump to this label. */
2050 for (target
= jump_chain
[0];
2051 target
!= 0 && newjpos
== 0;
2052 target
= jump_chain
[INSN_UID (target
)])
2054 && ! INSN_DELETED_P (target
)
2055 && GET_CODE (PATTERN (target
)) == RETURN
)
2056 find_cross_jump (insn
, target
, 2,
2057 &newjpos
, &newlpos
);
2061 do_cross_jump (insn
, newjpos
, newlpos
);
2072 /* Delete extraneous line number notes.
2073 Note that two consecutive notes for different lines are not really
2074 extraneous. There should be some indication where that line belonged,
2075 even if it became empty. */
2080 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
2081 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) >= 0)
2083 /* Delete this note if it is identical to previous note. */
2085 && NOTE_SOURCE_FILE (insn
) == NOTE_SOURCE_FILE (last_note
)
2086 && NOTE_LINE_NUMBER (insn
) == NOTE_LINE_NUMBER (last_note
))
2099 /* If we fall through to the epilogue, see if we can insert a RETURN insn
2100 in front of it. If the machine allows it at this point (we might be
2101 after reload for a leaf routine), it will improve optimization for it
2102 to be there. We do this both here and at the start of this pass since
2103 the RETURN might have been deleted by some of our optimizations. */
2104 insn
= get_last_insn ();
2105 while (insn
&& GET_CODE (insn
) == NOTE
)
2106 insn
= PREV_INSN (insn
);
2108 if (insn
&& GET_CODE (insn
) != BARRIER
)
2110 emit_jump_insn (gen_return ());
2116 /* CAN_REACH_END is persistent for each function. Once set it should
2117 not be cleared. This is especially true for the case where we
2118 delete the NOTE_FUNCTION_END note. CAN_REACH_END is cleared by
2119 the front-end before compiling each function. */
2120 if (calculate_can_reach_end (last_insn
, 0, 1))
2123 /* Show JUMP_CHAIN no longer valid. */
2127 /* Initialize LABEL_NUSES and JUMP_LABEL fields. Delete any REG_LABEL
2128 notes whose labels don't occur in the insn any more. Returns the
2129 largest INSN_UID found. */
2134 int largest_uid
= 0;
2137 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
2139 if (GET_CODE (insn
) == CODE_LABEL
)
2140 LABEL_NUSES (insn
) = (LABEL_PRESERVE_P (insn
) != 0);
2141 else if (GET_CODE (insn
) == JUMP_INSN
)
2142 JUMP_LABEL (insn
) = 0;
2143 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
2147 for (note
= REG_NOTES (insn
); note
; note
= next
)
2149 next
= XEXP (note
, 1);
2150 if (REG_NOTE_KIND (note
) == REG_LABEL
2151 && ! reg_mentioned_p (XEXP (note
, 0), PATTERN (insn
)))
2152 remove_note (insn
, note
);
2155 if (INSN_UID (insn
) > largest_uid
)
2156 largest_uid
= INSN_UID (insn
);
2162 /* Delete insns following barriers, up to next label.
2164 Also delete no-op jumps created by gcse. */
2166 delete_barrier_successors (f
)
2171 for (insn
= f
; insn
;)
2173 if (GET_CODE (insn
) == BARRIER
)
2175 insn
= NEXT_INSN (insn
);
2177 never_reached_warning (insn
);
2179 while (insn
!= 0 && GET_CODE (insn
) != CODE_LABEL
)
2181 if (GET_CODE (insn
) == NOTE
2182 && NOTE_LINE_NUMBER (insn
) != NOTE_INSN_FUNCTION_END
)
2183 insn
= NEXT_INSN (insn
);
2185 insn
= delete_insn (insn
);
2187 /* INSN is now the code_label. */
2189 /* Also remove (set (pc) (pc)) insns which can be created by
2190 gcse. We eliminate such insns now to avoid having them
2191 cause problems later. */
2192 else if (GET_CODE (insn
) == JUMP_INSN
2193 && GET_CODE (PATTERN (insn
)) == SET
2194 && SET_SRC (PATTERN (insn
)) == pc_rtx
2195 && SET_DEST (PATTERN (insn
)) == pc_rtx
)
2196 insn
= delete_insn (insn
);
2199 insn
= NEXT_INSN (insn
);
2203 /* Mark the label each jump jumps to.
2204 Combine consecutive labels, and count uses of labels.
2206 For each label, make a chain (using `jump_chain')
2207 of all the *unconditional* jumps that jump to it;
2208 also make a chain of all returns.
2210 CROSS_JUMP indicates whether we are doing cross jumping
2211 and if we are whether we will be paying attention to
2212 death notes or not. */
2215 mark_all_labels (f
, cross_jump
)
2221 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
2222 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
2224 mark_jump_label (PATTERN (insn
), insn
, cross_jump
);
2225 if (! INSN_DELETED_P (insn
) && GET_CODE (insn
) == JUMP_INSN
)
2227 if (JUMP_LABEL (insn
) != 0 && simplejump_p (insn
))
2229 jump_chain
[INSN_UID (insn
)]
2230 = jump_chain
[INSN_UID (JUMP_LABEL (insn
))];
2231 jump_chain
[INSN_UID (JUMP_LABEL (insn
))] = insn
;
2233 if (GET_CODE (PATTERN (insn
)) == RETURN
)
2235 jump_chain
[INSN_UID (insn
)] = jump_chain
[0];
2236 jump_chain
[0] = insn
;
2242 /* Delete all labels already not referenced.
2243 Also find and return the last insn. */
2246 delete_unreferenced_labels (f
)
2249 rtx final
= NULL_RTX
;
2252 for (insn
= f
; insn
; )
2254 if (GET_CODE (insn
) == CODE_LABEL
&& LABEL_NUSES (insn
) == 0)
2255 insn
= delete_insn (insn
);
2259 insn
= NEXT_INSN (insn
);
2266 /* Delete various simple forms of moves which have no necessary
2270 delete_noop_moves (f
)
2275 for (insn
= f
; insn
; )
2277 next
= NEXT_INSN (insn
);
2279 if (GET_CODE (insn
) == INSN
)
2281 register rtx body
= PATTERN (insn
);
2283 /* Combine stack_adjusts with following push_insns. */
2284 #ifdef PUSH_ROUNDING
2285 if (GET_CODE (body
) == SET
2286 && SET_DEST (body
) == stack_pointer_rtx
2287 && GET_CODE (SET_SRC (body
)) == PLUS
2288 && XEXP (SET_SRC (body
), 0) == stack_pointer_rtx
2289 && GET_CODE (XEXP (SET_SRC (body
), 1)) == CONST_INT
2290 && INTVAL (XEXP (SET_SRC (body
), 1)) > 0)
2293 rtx stack_adjust_insn
= insn
;
2294 int stack_adjust_amount
= INTVAL (XEXP (SET_SRC (body
), 1));
2295 int total_pushed
= 0;
2298 /* Find all successive push insns. */
2300 /* Don't convert more than three pushes;
2301 that starts adding too many displaced addresses
2302 and the whole thing starts becoming a losing
2307 p
= next_nonnote_insn (p
);
2308 if (p
== 0 || GET_CODE (p
) != INSN
)
2310 pbody
= PATTERN (p
);
2311 if (GET_CODE (pbody
) != SET
)
2313 dest
= SET_DEST (pbody
);
2314 /* Allow a no-op move between the adjust and the push. */
2315 if (GET_CODE (dest
) == REG
2316 && GET_CODE (SET_SRC (pbody
)) == REG
2317 && REGNO (dest
) == REGNO (SET_SRC (pbody
)))
2319 if (! (GET_CODE (dest
) == MEM
2320 && GET_CODE (XEXP (dest
, 0)) == POST_INC
2321 && XEXP (XEXP (dest
, 0), 0) == stack_pointer_rtx
))
2324 if (total_pushed
+ GET_MODE_SIZE (GET_MODE (SET_DEST (pbody
)))
2325 > stack_adjust_amount
)
2327 total_pushed
+= GET_MODE_SIZE (GET_MODE (SET_DEST (pbody
)));
2330 /* Discard the amount pushed from the stack adjust;
2331 maybe eliminate it entirely. */
2332 if (total_pushed
>= stack_adjust_amount
)
2334 delete_computation (stack_adjust_insn
);
2335 total_pushed
= stack_adjust_amount
;
2338 XEXP (SET_SRC (PATTERN (stack_adjust_insn
)), 1)
2339 = GEN_INT (stack_adjust_amount
- total_pushed
);
2341 /* Change the appropriate push insns to ordinary stores. */
2343 while (total_pushed
> 0)
2346 p
= next_nonnote_insn (p
);
2347 if (GET_CODE (p
) != INSN
)
2349 pbody
= PATTERN (p
);
2350 if (GET_CODE (pbody
) != SET
)
2352 dest
= SET_DEST (pbody
);
2353 /* Allow a no-op move between the adjust and the push. */
2354 if (GET_CODE (dest
) == REG
2355 && GET_CODE (SET_SRC (pbody
)) == REG
2356 && REGNO (dest
) == REGNO (SET_SRC (pbody
)))
2358 if (! (GET_CODE (dest
) == MEM
2359 && GET_CODE (XEXP (dest
, 0)) == POST_INC
2360 && XEXP (XEXP (dest
, 0), 0) == stack_pointer_rtx
))
2362 total_pushed
-= GET_MODE_SIZE (GET_MODE (SET_DEST (pbody
)));
2363 /* If this push doesn't fully fit in the space
2364 of the stack adjust that we deleted,
2365 make another stack adjust here for what we
2366 didn't use up. There should be peepholes
2367 to recognize the resulting sequence of insns. */
2368 if (total_pushed
< 0)
2370 emit_insn_before (gen_add2_insn (stack_pointer_rtx
,
2371 GEN_INT (- total_pushed
)),
2376 = plus_constant (stack_pointer_rtx
, total_pushed
);
2381 /* Detect and delete no-op move instructions
2382 resulting from not allocating a parameter in a register. */
2384 if (GET_CODE (body
) == SET
2385 && (SET_DEST (body
) == SET_SRC (body
)
2386 || (GET_CODE (SET_DEST (body
)) == MEM
2387 && GET_CODE (SET_SRC (body
)) == MEM
2388 && rtx_equal_p (SET_SRC (body
), SET_DEST (body
))))
2389 && ! (GET_CODE (SET_DEST (body
)) == MEM
2390 && MEM_VOLATILE_P (SET_DEST (body
)))
2391 && ! (GET_CODE (SET_SRC (body
)) == MEM
2392 && MEM_VOLATILE_P (SET_SRC (body
))))
2393 delete_computation (insn
);
2395 /* Detect and ignore no-op move instructions
2396 resulting from smart or fortuitous register allocation. */
2398 else if (GET_CODE (body
) == SET
)
2400 int sreg
= true_regnum (SET_SRC (body
));
2401 int dreg
= true_regnum (SET_DEST (body
));
2403 if (sreg
== dreg
&& sreg
>= 0)
2405 else if (sreg
>= 0 && dreg
>= 0)
2408 rtx tem
= find_equiv_reg (NULL_RTX
, insn
, 0,
2409 sreg
, NULL_PTR
, dreg
,
2410 GET_MODE (SET_SRC (body
)));
2413 && GET_MODE (tem
) == GET_MODE (SET_DEST (body
)))
2415 /* DREG may have been the target of a REG_DEAD note in
2416 the insn which makes INSN redundant. If so, reorg
2417 would still think it is dead. So search for such a
2418 note and delete it if we find it. */
2419 if (! find_regno_note (insn
, REG_UNUSED
, dreg
))
2420 for (trial
= prev_nonnote_insn (insn
);
2421 trial
&& GET_CODE (trial
) != CODE_LABEL
;
2422 trial
= prev_nonnote_insn (trial
))
2423 if (find_regno_note (trial
, REG_DEAD
, dreg
))
2425 remove_death (dreg
, trial
);
2429 /* Deleting insn could lose a death-note for SREG. */
2430 if ((trial
= find_regno_note (insn
, REG_DEAD
, sreg
)))
2432 /* Change this into a USE so that we won't emit
2433 code for it, but still can keep the note. */
2435 = gen_rtx_USE (VOIDmode
, XEXP (trial
, 0));
2436 INSN_CODE (insn
) = -1;
2437 /* Remove all reg notes but the REG_DEAD one. */
2438 REG_NOTES (insn
) = trial
;
2439 XEXP (trial
, 1) = NULL_RTX
;
2445 else if (dreg
>= 0 && CONSTANT_P (SET_SRC (body
))
2446 && find_equiv_reg (SET_SRC (body
), insn
, 0, dreg
,
2448 GET_MODE (SET_DEST (body
))))
2450 /* This handles the case where we have two consecutive
2451 assignments of the same constant to pseudos that didn't
2452 get a hard reg. Each SET from the constant will be
2453 converted into a SET of the spill register and an
2454 output reload will be made following it. This produces
2455 two loads of the same constant into the same spill
2460 /* Look back for a death note for the first reg.
2461 If there is one, it is no longer accurate. */
2462 while (in_insn
&& GET_CODE (in_insn
) != CODE_LABEL
)
2464 if ((GET_CODE (in_insn
) == INSN
2465 || GET_CODE (in_insn
) == JUMP_INSN
)
2466 && find_regno_note (in_insn
, REG_DEAD
, dreg
))
2468 remove_death (dreg
, in_insn
);
2471 in_insn
= PREV_INSN (in_insn
);
2474 /* Delete the second load of the value. */
2478 else if (GET_CODE (body
) == PARALLEL
)
2480 /* If each part is a set between two identical registers or
2481 a USE or CLOBBER, delete the insn. */
2485 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
2487 tem
= XVECEXP (body
, 0, i
);
2488 if (GET_CODE (tem
) == USE
|| GET_CODE (tem
) == CLOBBER
)
2491 if (GET_CODE (tem
) != SET
2492 || (sreg
= true_regnum (SET_SRC (tem
))) < 0
2493 || (dreg
= true_regnum (SET_DEST (tem
))) < 0
2501 /* Also delete insns to store bit fields if they are no-ops. */
2502 /* Not worth the hair to detect this in the big-endian case. */
2503 else if (! BYTES_BIG_ENDIAN
2504 && GET_CODE (body
) == SET
2505 && GET_CODE (SET_DEST (body
)) == ZERO_EXTRACT
2506 && XEXP (SET_DEST (body
), 2) == const0_rtx
2507 && XEXP (SET_DEST (body
), 0) == SET_SRC (body
)
2508 && ! (GET_CODE (SET_SRC (body
)) == MEM
2509 && MEM_VOLATILE_P (SET_SRC (body
))))
2516 /* See if there is still a NOTE_INSN_FUNCTION_END in this function.
2517 If so indicate that this function can drop off the end by returning
2520 CHECK_DELETED indicates whether we must check if the note being
2521 searched for has the deleted flag set.
2523 DELETE_FINAL_NOTE indicates whether we should delete the note
2527 calculate_can_reach_end (last
, check_deleted
, delete_final_note
)
2530 int delete_final_note
;
2535 while (insn
!= NULL_RTX
)
2539 /* One label can follow the end-note: the return label. */
2540 if (GET_CODE (insn
) == CODE_LABEL
&& n_labels
-- > 0)
2542 /* Ordinary insns can follow it if returning a structure. */
2543 else if (GET_CODE (insn
) == INSN
)
2545 /* If machine uses explicit RETURN insns, no epilogue,
2546 then one of them follows the note. */
2547 else if (GET_CODE (insn
) == JUMP_INSN
2548 && GET_CODE (PATTERN (insn
)) == RETURN
)
2550 /* A barrier can follow the return insn. */
2551 else if (GET_CODE (insn
) == BARRIER
)
2553 /* Other kinds of notes can follow also. */
2554 else if (GET_CODE (insn
) == NOTE
2555 && NOTE_LINE_NUMBER (insn
) != NOTE_INSN_FUNCTION_END
)
2561 insn
= PREV_INSN (insn
);
2564 /* See if we backed up to the appropriate type of note. */
2565 if (insn
!= NULL_RTX
2566 && GET_CODE (insn
) == NOTE
2567 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_FUNCTION_END
2568 && (check_deleted
== 0
2569 || ! INSN_DELETED_P (insn
)))
2571 if (delete_final_note
)
2579 /* LOOP_START is a NOTE_INSN_LOOP_BEG note that is followed by an unconditional
2580 jump. Assume that this unconditional jump is to the exit test code. If
2581 the code is sufficiently simple, make a copy of it before INSN,
2582 followed by a jump to the exit of the loop. Then delete the unconditional
2585 Return 1 if we made the change, else 0.
2587 This is only safe immediately after a regscan pass because it uses the
2588 values of regno_first_uid and regno_last_uid. */
2591 duplicate_loop_exit_test (loop_start
)
2594 rtx insn
, set
, reg
, p
, link
;
2595 rtx copy
= 0, first_copy
= 0;
2597 rtx exitcode
= NEXT_INSN (JUMP_LABEL (next_nonnote_insn (loop_start
)));
2599 int max_reg
= max_reg_num ();
2602 /* Scan the exit code. We do not perform this optimization if any insn:
2606 has a REG_RETVAL or REG_LIBCALL note (hard to adjust)
2607 is a NOTE_INSN_LOOP_BEG because this means we have a nested loop
2608 is a NOTE_INSN_BLOCK_{BEG,END} because duplicating these notes
2611 We also do not do this if we find an insn with ASM_OPERANDS. While
2612 this restriction should not be necessary, copying an insn with
2613 ASM_OPERANDS can confuse asm_noperands in some cases.
2615 Also, don't do this if the exit code is more than 20 insns. */
2617 for (insn
= exitcode
;
2619 && ! (GET_CODE (insn
) == NOTE
2620 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
);
2621 insn
= NEXT_INSN (insn
))
2623 switch (GET_CODE (insn
))
2629 /* We could be in front of the wrong NOTE_INSN_LOOP_END if there is
2630 a jump immediately after the loop start that branches outside
2631 the loop but within an outer loop, near the exit test.
2632 If we copied this exit test and created a phony
2633 NOTE_INSN_LOOP_VTOP, this could make instructions immediately
2634 before the exit test look like these could be safely moved
2635 out of the loop even if they actually may be never executed.
2636 This can be avoided by checking here for NOTE_INSN_LOOP_CONT. */
2638 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
2639 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_CONT
)
2643 && (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
2644 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
))
2645 /* If we were to duplicate this code, we would not move
2646 the BLOCK notes, and so debugging the moved code would
2647 be difficult. Thus, we only move the code with -O2 or
2654 /* The code below would grossly mishandle REG_WAS_0 notes,
2655 so get rid of them here. */
2656 while ((p
= find_reg_note (insn
, REG_WAS_0
, NULL_RTX
)) != 0)
2657 remove_note (insn
, p
);
2658 if (++num_insns
> 20
2659 || find_reg_note (insn
, REG_RETVAL
, NULL_RTX
)
2660 || find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
)
2661 || asm_noperands (PATTERN (insn
)) > 0)
2669 /* Unless INSN is zero, we can do the optimization. */
2675 /* See if any insn sets a register only used in the loop exit code and
2676 not a user variable. If so, replace it with a new register. */
2677 for (insn
= exitcode
; insn
!= lastexit
; insn
= NEXT_INSN (insn
))
2678 if (GET_CODE (insn
) == INSN
2679 && (set
= single_set (insn
)) != 0
2680 && ((reg
= SET_DEST (set
), GET_CODE (reg
) == REG
)
2681 || (GET_CODE (reg
) == SUBREG
2682 && (reg
= SUBREG_REG (reg
), GET_CODE (reg
) == REG
)))
2683 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
2684 && REGNO_FIRST_UID (REGNO (reg
)) == INSN_UID (insn
))
2686 for (p
= NEXT_INSN (insn
); p
!= lastexit
; p
= NEXT_INSN (p
))
2687 if (REGNO_LAST_UID (REGNO (reg
)) == INSN_UID (p
))
2692 /* We can do the replacement. Allocate reg_map if this is the
2693 first replacement we found. */
2696 reg_map
= (rtx
*) alloca (max_reg
* sizeof (rtx
));
2697 bzero ((char *) reg_map
, max_reg
* sizeof (rtx
));
2700 REG_LOOP_TEST_P (reg
) = 1;
2702 reg_map
[REGNO (reg
)] = gen_reg_rtx (GET_MODE (reg
));
2706 /* Now copy each insn. */
2707 for (insn
= exitcode
; insn
!= lastexit
; insn
= NEXT_INSN (insn
))
2709 switch (GET_CODE (insn
))
2712 copy
= emit_barrier_before (loop_start
);
2715 /* Only copy line-number notes. */
2716 if (NOTE_LINE_NUMBER (insn
) >= 0)
2718 copy
= emit_note_before (NOTE_LINE_NUMBER (insn
), loop_start
);
2719 NOTE_SOURCE_FILE (copy
) = NOTE_SOURCE_FILE (insn
);
2724 copy
= emit_insn_before (copy_rtx (PATTERN (insn
)), loop_start
);
2726 replace_regs (PATTERN (copy
), reg_map
, max_reg
, 1);
2728 mark_jump_label (PATTERN (copy
), copy
, 0);
2730 /* Copy all REG_NOTES except REG_LABEL since mark_jump_label will
2732 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2733 if (REG_NOTE_KIND (link
) != REG_LABEL
)
2735 = copy_rtx (gen_rtx_EXPR_LIST (REG_NOTE_KIND (link
),
2738 if (reg_map
&& REG_NOTES (copy
))
2739 replace_regs (REG_NOTES (copy
), reg_map
, max_reg
, 1);
2743 copy
= emit_jump_insn_before (copy_rtx (PATTERN (insn
)), loop_start
);
2745 replace_regs (PATTERN (copy
), reg_map
, max_reg
, 1);
2746 mark_jump_label (PATTERN (copy
), copy
, 0);
2747 if (REG_NOTES (insn
))
2749 REG_NOTES (copy
) = copy_rtx (REG_NOTES (insn
));
2751 replace_regs (REG_NOTES (copy
), reg_map
, max_reg
, 1);
2754 /* If this is a simple jump, add it to the jump chain. */
2756 if (INSN_UID (copy
) < max_jump_chain
&& JUMP_LABEL (copy
)
2757 && simplejump_p (copy
))
2759 jump_chain
[INSN_UID (copy
)]
2760 = jump_chain
[INSN_UID (JUMP_LABEL (copy
))];
2761 jump_chain
[INSN_UID (JUMP_LABEL (copy
))] = copy
;
2769 /* Record the first insn we copied. We need it so that we can
2770 scan the copied insns for new pseudo registers. */
2775 /* Now clean up by emitting a jump to the end label and deleting the jump
2776 at the start of the loop. */
2777 if (! copy
|| GET_CODE (copy
) != BARRIER
)
2779 copy
= emit_jump_insn_before (gen_jump (get_label_after (insn
)),
2782 /* Record the first insn we copied. We need it so that we can
2783 scan the copied insns for new pseudo registers. This may not
2784 be strictly necessary since we should have copied at least one
2785 insn above. But I am going to be safe. */
2789 mark_jump_label (PATTERN (copy
), copy
, 0);
2790 if (INSN_UID (copy
) < max_jump_chain
2791 && INSN_UID (JUMP_LABEL (copy
)) < max_jump_chain
)
2793 jump_chain
[INSN_UID (copy
)]
2794 = jump_chain
[INSN_UID (JUMP_LABEL (copy
))];
2795 jump_chain
[INSN_UID (JUMP_LABEL (copy
))] = copy
;
2797 emit_barrier_before (loop_start
);
2800 /* Now scan from the first insn we copied to the last insn we copied
2801 (copy) for new pseudo registers. Do this after the code to jump to
2802 the end label since that might create a new pseudo too. */
2803 reg_scan_update (first_copy
, copy
, max_reg
);
2805 /* Mark the exit code as the virtual top of the converted loop. */
2806 emit_note_before (NOTE_INSN_LOOP_VTOP
, exitcode
);
2808 delete_insn (next_nonnote_insn (loop_start
));
2813 /* Move all block-beg, block-end, loop-beg, loop-cont, loop-vtop, and
2814 loop-end notes between START and END out before START. Assume that
2815 END is not such a note. START may be such a note. Returns the value
2816 of the new starting insn, which may be different if the original start
2820 squeeze_notes (start
, end
)
2826 for (insn
= start
; insn
!= end
; insn
= next
)
2828 next
= NEXT_INSN (insn
);
2829 if (GET_CODE (insn
) == NOTE
2830 && (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
2831 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
2832 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
2833 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
2834 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_CONT
2835 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_VTOP
))
2841 rtx prev
= PREV_INSN (insn
);
2842 PREV_INSN (insn
) = PREV_INSN (start
);
2843 NEXT_INSN (insn
) = start
;
2844 NEXT_INSN (PREV_INSN (insn
)) = insn
;
2845 PREV_INSN (NEXT_INSN (insn
)) = insn
;
2846 NEXT_INSN (prev
) = next
;
2847 PREV_INSN (next
) = prev
;
2855 /* Compare the instructions before insn E1 with those before E2
2856 to find an opportunity for cross jumping.
2857 (This means detecting identical sequences of insns followed by
2858 jumps to the same place, or followed by a label and a jump
2859 to that label, and replacing one with a jump to the other.)
2861 Assume E1 is a jump that jumps to label E2
2862 (that is not always true but it might as well be).
2863 Find the longest possible equivalent sequences
2864 and store the first insns of those sequences into *F1 and *F2.
2865 Store zero there if no equivalent preceding instructions are found.
2867 We give up if we find a label in stream 1.
2868 Actually we could transfer that label into stream 2. */
2871 find_cross_jump (e1
, e2
, minimum
, f1
, f2
)
2876 register rtx i1
= e1
, i2
= e2
;
2877 register rtx p1
, p2
;
2880 rtx last1
= 0, last2
= 0;
2881 rtx afterlast1
= 0, afterlast2
= 0;
2888 i1
= prev_nonnote_insn (i1
);
2890 i2
= PREV_INSN (i2
);
2891 while (i2
&& (GET_CODE (i2
) == NOTE
|| GET_CODE (i2
) == CODE_LABEL
))
2892 i2
= PREV_INSN (i2
);
2897 /* Don't allow the range of insns preceding E1 or E2
2898 to include the other (E2 or E1). */
2899 if (i2
== e1
|| i1
== e2
)
2902 /* If we will get to this code by jumping, those jumps will be
2903 tensioned to go directly to the new label (before I2),
2904 so this cross-jumping won't cost extra. So reduce the minimum. */
2905 if (GET_CODE (i1
) == CODE_LABEL
)
2911 if (i2
== 0 || GET_CODE (i1
) != GET_CODE (i2
))
2914 /* Avoid moving insns across EH regions if either of the insns
2917 && (asynchronous_exceptions
|| GET_CODE (i1
) == CALL_INSN
)
2918 && !in_same_eh_region (i1
, i2
))
2924 /* If this is a CALL_INSN, compare register usage information.
2925 If we don't check this on stack register machines, the two
2926 CALL_INSNs might be merged leaving reg-stack.c with mismatching
2927 numbers of stack registers in the same basic block.
2928 If we don't check this on machines with delay slots, a delay slot may
2929 be filled that clobbers a parameter expected by the subroutine.
2931 ??? We take the simple route for now and assume that if they're
2932 equal, they were constructed identically. */
2934 if (GET_CODE (i1
) == CALL_INSN
2935 && ! rtx_equal_p (CALL_INSN_FUNCTION_USAGE (i1
),
2936 CALL_INSN_FUNCTION_USAGE (i2
)))
2940 /* If cross_jump_death_matters is not 0, the insn's mode
2941 indicates whether or not the insn contains any stack-like
2944 if (!lose
&& cross_jump_death_matters
&& stack_regs_mentioned (i1
))
2946 /* If register stack conversion has already been done, then
2947 death notes must also be compared before it is certain that
2948 the two instruction streams match. */
2951 HARD_REG_SET i1_regset
, i2_regset
;
2953 CLEAR_HARD_REG_SET (i1_regset
);
2954 CLEAR_HARD_REG_SET (i2_regset
);
2956 for (note
= REG_NOTES (i1
); note
; note
= XEXP (note
, 1))
2957 if (REG_NOTE_KIND (note
) == REG_DEAD
2958 && STACK_REG_P (XEXP (note
, 0)))
2959 SET_HARD_REG_BIT (i1_regset
, REGNO (XEXP (note
, 0)));
2961 for (note
= REG_NOTES (i2
); note
; note
= XEXP (note
, 1))
2962 if (REG_NOTE_KIND (note
) == REG_DEAD
2963 && STACK_REG_P (XEXP (note
, 0)))
2964 SET_HARD_REG_BIT (i2_regset
, REGNO (XEXP (note
, 0)));
2966 GO_IF_HARD_REG_EQUAL (i1_regset
, i2_regset
, done
);
2975 /* Don't allow old-style asm or volatile extended asms to be accepted
2976 for cross jumping purposes. It is conceptually correct to allow
2977 them, since cross-jumping preserves the dynamic instruction order
2978 even though it is changing the static instruction order. However,
2979 if an asm is being used to emit an assembler pseudo-op, such as
2980 the MIPS `.set reorder' pseudo-op, then the static instruction order
2981 matters and it must be preserved. */
2982 if (GET_CODE (p1
) == ASM_INPUT
|| GET_CODE (p2
) == ASM_INPUT
2983 || (GET_CODE (p1
) == ASM_OPERANDS
&& MEM_VOLATILE_P (p1
))
2984 || (GET_CODE (p2
) == ASM_OPERANDS
&& MEM_VOLATILE_P (p2
)))
2987 if (lose
|| GET_CODE (p1
) != GET_CODE (p2
)
2988 || ! rtx_renumbered_equal_p (p1
, p2
))
2990 /* The following code helps take care of G++ cleanups. */
2994 if (!lose
&& GET_CODE (p1
) == GET_CODE (p2
)
2995 && ((equiv1
= find_reg_note (i1
, REG_EQUAL
, NULL_RTX
)) != 0
2996 || (equiv1
= find_reg_note (i1
, REG_EQUIV
, NULL_RTX
)) != 0)
2997 && ((equiv2
= find_reg_note (i2
, REG_EQUAL
, NULL_RTX
)) != 0
2998 || (equiv2
= find_reg_note (i2
, REG_EQUIV
, NULL_RTX
)) != 0)
2999 /* If the equivalences are not to a constant, they may
3000 reference pseudos that no longer exist, so we can't
3002 && CONSTANT_P (XEXP (equiv1
, 0))
3003 && rtx_equal_p (XEXP (equiv1
, 0), XEXP (equiv2
, 0)))
3005 rtx s1
= single_set (i1
);
3006 rtx s2
= single_set (i2
);
3007 if (s1
!= 0 && s2
!= 0
3008 && rtx_renumbered_equal_p (SET_DEST (s1
), SET_DEST (s2
)))
3010 validate_change (i1
, &SET_SRC (s1
), XEXP (equiv1
, 0), 1);
3011 validate_change (i2
, &SET_SRC (s2
), XEXP (equiv2
, 0), 1);
3012 if (! rtx_renumbered_equal_p (p1
, p2
))
3014 else if (apply_change_group ())
3019 /* Insns fail to match; cross jumping is limited to the following
3023 /* Don't allow the insn after a compare to be shared by
3024 cross-jumping unless the compare is also shared.
3025 Here, if either of these non-matching insns is a compare,
3026 exclude the following insn from possible cross-jumping. */
3027 if (sets_cc0_p (p1
) || sets_cc0_p (p2
))
3028 last1
= afterlast1
, last2
= afterlast2
, ++minimum
;
3031 /* If cross-jumping here will feed a jump-around-jump
3032 optimization, this jump won't cost extra, so reduce
3034 if (GET_CODE (i1
) == JUMP_INSN
3036 && prev_real_insn (JUMP_LABEL (i1
)) == e1
)
3042 if (GET_CODE (p1
) != USE
&& GET_CODE (p1
) != CLOBBER
)
3044 /* Ok, this insn is potentially includable in a cross-jump here. */
3045 afterlast1
= last1
, afterlast2
= last2
;
3046 last1
= i1
, last2
= i2
, --minimum
;
3050 if (minimum
<= 0 && last1
!= 0 && last1
!= e1
)
3051 *f1
= last1
, *f2
= last2
;
3055 do_cross_jump (insn
, newjpos
, newlpos
)
3056 rtx insn
, newjpos
, newlpos
;
3058 /* Find an existing label at this point
3059 or make a new one if there is none. */
3060 register rtx label
= get_label_before (newlpos
);
3062 /* Make the same jump insn jump to the new point. */
3063 if (GET_CODE (PATTERN (insn
)) == RETURN
)
3065 /* Remove from jump chain of returns. */
3066 delete_from_jump_chain (insn
);
3067 /* Change the insn. */
3068 PATTERN (insn
) = gen_jump (label
);
3069 INSN_CODE (insn
) = -1;
3070 JUMP_LABEL (insn
) = label
;
3071 LABEL_NUSES (label
)++;
3072 /* Add to new the jump chain. */
3073 if (INSN_UID (label
) < max_jump_chain
3074 && INSN_UID (insn
) < max_jump_chain
)
3076 jump_chain
[INSN_UID (insn
)] = jump_chain
[INSN_UID (label
)];
3077 jump_chain
[INSN_UID (label
)] = insn
;
3081 redirect_jump (insn
, label
);
3083 /* Delete the matching insns before the jump. Also, remove any REG_EQUAL
3084 or REG_EQUIV note in the NEWLPOS stream that isn't also present in
3085 the NEWJPOS stream. */
3087 while (newjpos
!= insn
)
3091 for (lnote
= REG_NOTES (newlpos
); lnote
; lnote
= XEXP (lnote
, 1))
3092 if ((REG_NOTE_KIND (lnote
) == REG_EQUAL
3093 || REG_NOTE_KIND (lnote
) == REG_EQUIV
)
3094 && ! find_reg_note (newjpos
, REG_EQUAL
, XEXP (lnote
, 0))
3095 && ! find_reg_note (newjpos
, REG_EQUIV
, XEXP (lnote
, 0)))
3096 remove_note (newlpos
, lnote
);
3098 delete_insn (newjpos
);
3099 newjpos
= next_real_insn (newjpos
);
3100 newlpos
= next_real_insn (newlpos
);
3104 /* Return the label before INSN, or put a new label there. */
3107 get_label_before (insn
)
3112 /* Find an existing label at this point
3113 or make a new one if there is none. */
3114 label
= prev_nonnote_insn (insn
);
3116 if (label
== 0 || GET_CODE (label
) != CODE_LABEL
)
3118 rtx prev
= PREV_INSN (insn
);
3120 label
= gen_label_rtx ();
3121 emit_label_after (label
, prev
);
3122 LABEL_NUSES (label
) = 0;
3127 /* Return the label after INSN, or put a new label there. */
3130 get_label_after (insn
)
3135 /* Find an existing label at this point
3136 or make a new one if there is none. */
3137 label
= next_nonnote_insn (insn
);
3139 if (label
== 0 || GET_CODE (label
) != CODE_LABEL
)
3141 label
= gen_label_rtx ();
3142 emit_label_after (label
, insn
);
3143 LABEL_NUSES (label
) = 0;
3148 /* Return 1 if INSN is a jump that jumps to right after TARGET
3149 only on the condition that TARGET itself would drop through.
3150 Assumes that TARGET is a conditional jump. */
3153 jump_back_p (insn
, target
)
3157 enum rtx_code codei
, codet
;
3159 if (simplejump_p (insn
) || ! condjump_p (insn
)
3160 || simplejump_p (target
)
3161 || target
!= prev_real_insn (JUMP_LABEL (insn
)))
3164 cinsn
= XEXP (SET_SRC (PATTERN (insn
)), 0);
3165 ctarget
= XEXP (SET_SRC (PATTERN (target
)), 0);
3167 codei
= GET_CODE (cinsn
);
3168 codet
= GET_CODE (ctarget
);
3170 if (XEXP (SET_SRC (PATTERN (insn
)), 1) == pc_rtx
)
3172 if (! can_reverse_comparison_p (cinsn
, insn
))
3174 codei
= reverse_condition (codei
);
3177 if (XEXP (SET_SRC (PATTERN (target
)), 2) == pc_rtx
)
3179 if (! can_reverse_comparison_p (ctarget
, target
))
3181 codet
= reverse_condition (codet
);
3184 return (codei
== codet
3185 && rtx_renumbered_equal_p (XEXP (cinsn
, 0), XEXP (ctarget
, 0))
3186 && rtx_renumbered_equal_p (XEXP (cinsn
, 1), XEXP (ctarget
, 1)));
3189 /* Given a comparison, COMPARISON, inside a conditional jump insn, INSN,
3190 return non-zero if it is safe to reverse this comparison. It is if our
3191 floating-point is not IEEE, if this is an NE or EQ comparison, or if
3192 this is known to be an integer comparison. */
3195 can_reverse_comparison_p (comparison
, insn
)
3201 /* If this is not actually a comparison, we can't reverse it. */
3202 if (GET_RTX_CLASS (GET_CODE (comparison
)) != '<')
3205 if (TARGET_FLOAT_FORMAT
!= IEEE_FLOAT_FORMAT
3206 /* If this is an NE comparison, it is safe to reverse it to an EQ
3207 comparison and vice versa, even for floating point. If no operands
3208 are NaNs, the reversal is valid. If some operand is a NaN, EQ is
3209 always false and NE is always true, so the reversal is also valid. */
3211 || GET_CODE (comparison
) == NE
3212 || GET_CODE (comparison
) == EQ
)
3215 arg0
= XEXP (comparison
, 0);
3217 /* Make sure ARG0 is one of the actual objects being compared. If we
3218 can't do this, we can't be sure the comparison can be reversed.
3220 Handle cc0 and a MODE_CC register. */
3221 if ((GET_CODE (arg0
) == REG
&& GET_MODE_CLASS (GET_MODE (arg0
)) == MODE_CC
)
3227 rtx prev
= prev_nonnote_insn (insn
);
3230 /* If the comparison itself was a loop invariant, it could have been
3231 hoisted out of the loop. If we proceed to unroll such a loop, then
3232 we may not be able to find the comparison when copying the loop.
3234 Returning zero in that case is the safe thing to do. */
3238 set
= single_set (prev
);
3239 if (set
== 0 || SET_DEST (set
) != arg0
)
3242 arg0
= SET_SRC (set
);
3244 if (GET_CODE (arg0
) == COMPARE
)
3245 arg0
= XEXP (arg0
, 0);
3248 /* We can reverse this if ARG0 is a CONST_INT or if its mode is
3249 not VOIDmode and neither a MODE_CC nor MODE_FLOAT type. */
3250 return (GET_CODE (arg0
) == CONST_INT
3251 || (GET_MODE (arg0
) != VOIDmode
3252 && GET_MODE_CLASS (GET_MODE (arg0
)) != MODE_CC
3253 && GET_MODE_CLASS (GET_MODE (arg0
)) != MODE_FLOAT
));
3256 /* Given an rtx-code for a comparison, return the code
3257 for the negated comparison.
3258 WATCH OUT! reverse_condition is not safe to use on a jump
3259 that might be acting on the results of an IEEE floating point comparison,
3260 because of the special treatment of non-signaling nans in comparisons.
3261 Use can_reverse_comparison_p to be sure. */
3264 reverse_condition (code
)
3305 /* Similar, but return the code when two operands of a comparison are swapped.
3306 This IS safe for IEEE floating-point. */
3309 swap_condition (code
)
3348 /* Given a comparison CODE, return the corresponding unsigned comparison.
3349 If CODE is an equality comparison or already an unsigned comparison,
3350 CODE is returned. */
3353 unsigned_condition (code
)
3383 /* Similarly, return the signed version of a comparison. */
3386 signed_condition (code
)
3416 /* Return non-zero if CODE1 is more strict than CODE2, i.e., if the
3417 truth of CODE1 implies the truth of CODE2. */
3420 comparison_dominates_p (code1
, code2
)
3421 enum rtx_code code1
, code2
;
3429 if (code2
== LE
|| code2
== LEU
|| code2
== GE
|| code2
== GEU
)
3434 if (code2
== LE
|| code2
== NE
)
3439 if (code2
== GE
|| code2
== NE
)
3444 if (code2
== LEU
|| code2
== NE
)
3449 if (code2
== GEU
|| code2
== NE
)
3460 /* Return 1 if INSN is an unconditional jump and nothing else. */
3466 return (GET_CODE (insn
) == JUMP_INSN
3467 && GET_CODE (PATTERN (insn
)) == SET
3468 && GET_CODE (SET_DEST (PATTERN (insn
))) == PC
3469 && GET_CODE (SET_SRC (PATTERN (insn
))) == LABEL_REF
);
3472 /* Return nonzero if INSN is a (possibly) conditional jump
3473 and nothing more. */
3479 register rtx x
= PATTERN (insn
);
3480 if (GET_CODE (x
) != SET
)
3482 if (GET_CODE (SET_DEST (x
)) != PC
)
3484 if (GET_CODE (SET_SRC (x
)) == LABEL_REF
)
3486 if (GET_CODE (SET_SRC (x
)) != IF_THEN_ELSE
)
3488 if (XEXP (SET_SRC (x
), 2) == pc_rtx
3489 && (GET_CODE (XEXP (SET_SRC (x
), 1)) == LABEL_REF
3490 || GET_CODE (XEXP (SET_SRC (x
), 1)) == RETURN
))
3492 if (XEXP (SET_SRC (x
), 1) == pc_rtx
3493 && (GET_CODE (XEXP (SET_SRC (x
), 2)) == LABEL_REF
3494 || GET_CODE (XEXP (SET_SRC (x
), 2)) == RETURN
))
3499 /* Return nonzero if INSN is a (possibly) conditional jump
3500 and nothing more. */
3503 condjump_in_parallel_p (insn
)
3506 register rtx x
= PATTERN (insn
);
3508 if (GET_CODE (x
) != PARALLEL
)
3511 x
= XVECEXP (x
, 0, 0);
3513 if (GET_CODE (x
) != SET
)
3515 if (GET_CODE (SET_DEST (x
)) != PC
)
3517 if (GET_CODE (SET_SRC (x
)) == LABEL_REF
)
3519 if (GET_CODE (SET_SRC (x
)) != IF_THEN_ELSE
)
3521 if (XEXP (SET_SRC (x
), 2) == pc_rtx
3522 && (GET_CODE (XEXP (SET_SRC (x
), 1)) == LABEL_REF
3523 || GET_CODE (XEXP (SET_SRC (x
), 1)) == RETURN
))
3525 if (XEXP (SET_SRC (x
), 1) == pc_rtx
3526 && (GET_CODE (XEXP (SET_SRC (x
), 2)) == LABEL_REF
3527 || GET_CODE (XEXP (SET_SRC (x
), 2)) == RETURN
))
3532 /* Return the label of a conditional jump. */
3535 condjump_label (insn
)
3538 register rtx x
= PATTERN (insn
);
3540 if (GET_CODE (x
) == PARALLEL
)
3541 x
= XVECEXP (x
, 0, 0);
3542 if (GET_CODE (x
) != SET
)
3544 if (GET_CODE (SET_DEST (x
)) != PC
)
3547 if (GET_CODE (x
) == LABEL_REF
)
3549 if (GET_CODE (x
) != IF_THEN_ELSE
)
3551 if (XEXP (x
, 2) == pc_rtx
&& GET_CODE (XEXP (x
, 1)) == LABEL_REF
)
3553 if (XEXP (x
, 1) == pc_rtx
&& GET_CODE (XEXP (x
, 2)) == LABEL_REF
)
3558 /* Return true if INSN is a (possibly conditional) return insn. */
3561 returnjump_p_1 (loc
, data
)
3563 void *data ATTRIBUTE_UNUSED
;
3566 return GET_CODE (x
) == RETURN
;
3573 return for_each_rtx (&PATTERN (insn
), returnjump_p_1
, NULL
);
3576 /* Return true if INSN is a jump that only transfers control and
3585 if (GET_CODE (insn
) != JUMP_INSN
)
3588 set
= single_set (insn
);
3591 if (GET_CODE (SET_DEST (set
)) != PC
)
3593 if (side_effects_p (SET_SRC (set
)))
3601 /* Return 1 if X is an RTX that does nothing but set the condition codes
3602 and CLOBBER or USE registers.
3603 Return -1 if X does explicitly set the condition codes,
3604 but also does other things. */
3608 rtx x ATTRIBUTE_UNUSED
;
3610 if (GET_CODE (x
) == SET
&& SET_DEST (x
) == cc0_rtx
)
3612 if (GET_CODE (x
) == PARALLEL
)
3616 int other_things
= 0;
3617 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
3619 if (GET_CODE (XVECEXP (x
, 0, i
)) == SET
3620 && SET_DEST (XVECEXP (x
, 0, i
)) == cc0_rtx
)
3622 else if (GET_CODE (XVECEXP (x
, 0, i
)) == SET
)
3625 return ! sets_cc0
? 0 : other_things
? -1 : 1;
3631 /* Follow any unconditional jump at LABEL;
3632 return the ultimate label reached by any such chain of jumps.
3633 If LABEL is not followed by a jump, return LABEL.
3634 If the chain loops or we can't find end, return LABEL,
3635 since that tells caller to avoid changing the insn.
3637 If RELOAD_COMPLETED is 0, we do not chain across a NOTE_INSN_LOOP_BEG or
3638 a USE or CLOBBER. */
3641 follow_jumps (label
)
3646 register rtx value
= label
;
3651 && (insn
= next_active_insn (value
)) != 0
3652 && GET_CODE (insn
) == JUMP_INSN
3653 && ((JUMP_LABEL (insn
) != 0 && simplejump_p (insn
))
3654 || GET_CODE (PATTERN (insn
)) == RETURN
)
3655 && (next
= NEXT_INSN (insn
))
3656 && GET_CODE (next
) == BARRIER
);
3659 /* Don't chain through the insn that jumps into a loop
3660 from outside the loop,
3661 since that would create multiple loop entry jumps
3662 and prevent loop optimization. */
3664 if (!reload_completed
)
3665 for (tem
= value
; tem
!= insn
; tem
= NEXT_INSN (tem
))
3666 if (GET_CODE (tem
) == NOTE
3667 && (NOTE_LINE_NUMBER (tem
) == NOTE_INSN_LOOP_BEG
3668 /* ??? Optional. Disables some optimizations, but makes
3669 gcov output more accurate with -O. */
3670 || (flag_test_coverage
&& NOTE_LINE_NUMBER (tem
) > 0)))
3673 /* If we have found a cycle, make the insn jump to itself. */
3674 if (JUMP_LABEL (insn
) == label
)
3677 tem
= next_active_insn (JUMP_LABEL (insn
));
3678 if (tem
&& (GET_CODE (PATTERN (tem
)) == ADDR_VEC
3679 || GET_CODE (PATTERN (tem
)) == ADDR_DIFF_VEC
))
3682 value
= JUMP_LABEL (insn
);
3689 /* Assuming that field IDX of X is a vector of label_refs,
3690 replace each of them by the ultimate label reached by it.
3691 Return nonzero if a change is made.
3692 If IGNORE_LOOPS is 0, we do not chain across a NOTE_INSN_LOOP_BEG. */
3695 tension_vector_labels (x
, idx
)
3701 for (i
= XVECLEN (x
, idx
) - 1; i
>= 0; i
--)
3703 register rtx olabel
= XEXP (XVECEXP (x
, idx
, i
), 0);
3704 register rtx nlabel
= follow_jumps (olabel
);
3705 if (nlabel
&& nlabel
!= olabel
)
3707 XEXP (XVECEXP (x
, idx
, i
), 0) = nlabel
;
3708 ++LABEL_NUSES (nlabel
);
3709 if (--LABEL_NUSES (olabel
) == 0)
3710 delete_insn (olabel
);
3717 /* Find all CODE_LABELs referred to in X, and increment their use counts.
3718 If INSN is a JUMP_INSN and there is at least one CODE_LABEL referenced
3719 in INSN, then store one of them in JUMP_LABEL (INSN).
3720 If INSN is an INSN or a CALL_INSN and there is at least one CODE_LABEL
3721 referenced in INSN, add a REG_LABEL note containing that label to INSN.
3722 Also, when there are consecutive labels, canonicalize on the last of them.
3724 Note that two labels separated by a loop-beginning note
3725 must be kept distinct if we have not yet done loop-optimization,
3726 because the gap between them is where loop-optimize
3727 will want to move invariant code to. CROSS_JUMP tells us
3728 that loop-optimization is done with.
3730 Once reload has completed (CROSS_JUMP non-zero), we need not consider
3731 two labels distinct if they are separated by only USE or CLOBBER insns. */
3734 mark_jump_label (x
, insn
, cross_jump
)
3739 register RTX_CODE code
= GET_CODE (x
);
3741 register const char *fmt
;
3757 /* If this is a constant-pool reference, see if it is a label. */
3758 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
3759 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)))
3760 mark_jump_label (get_pool_constant (XEXP (x
, 0)), insn
, cross_jump
);
3765 rtx label
= XEXP (x
, 0);
3770 if (GET_CODE (label
) != CODE_LABEL
)
3773 /* Ignore references to labels of containing functions. */
3774 if (LABEL_REF_NONLOCAL_P (x
))
3777 /* If there are other labels following this one,
3778 replace it with the last of the consecutive labels. */
3779 for (next
= NEXT_INSN (label
); next
; next
= NEXT_INSN (next
))
3781 if (GET_CODE (next
) == CODE_LABEL
)
3783 else if (cross_jump
&& GET_CODE (next
) == INSN
3784 && (GET_CODE (PATTERN (next
)) == USE
3785 || GET_CODE (PATTERN (next
)) == CLOBBER
))
3787 else if (GET_CODE (next
) != NOTE
)
3789 else if (! cross_jump
3790 && (NOTE_LINE_NUMBER (next
) == NOTE_INSN_LOOP_BEG
3791 || NOTE_LINE_NUMBER (next
) == NOTE_INSN_FUNCTION_END
3792 /* ??? Optional. Disables some optimizations, but
3793 makes gcov output more accurate with -O. */
3794 || (flag_test_coverage
&& NOTE_LINE_NUMBER (next
) > 0)))
3798 XEXP (x
, 0) = label
;
3799 if (! insn
|| ! INSN_DELETED_P (insn
))
3800 ++LABEL_NUSES (label
);
3804 if (GET_CODE (insn
) == JUMP_INSN
)
3805 JUMP_LABEL (insn
) = label
;
3807 /* If we've changed OLABEL and we had a REG_LABEL note
3808 for it, update it as well. */
3809 else if (label
!= olabel
3810 && (note
= find_reg_note (insn
, REG_LABEL
, olabel
)) != 0)
3811 XEXP (note
, 0) = label
;
3813 /* Otherwise, add a REG_LABEL note for LABEL unless there already
3815 else if (! find_reg_note (insn
, REG_LABEL
, label
))
3817 /* This code used to ignore labels which refered to dispatch
3818 tables to avoid flow.c generating worse code.
3820 However, in the presense of global optimizations like
3821 gcse which call find_basic_blocks without calling
3822 life_analysis, not recording such labels will lead
3823 to compiler aborts because of inconsistencies in the
3824 flow graph. So we go ahead and record the label.
3826 It may also be the case that the optimization argument
3827 is no longer valid because of the more accurate cfg
3828 we build in find_basic_blocks -- it no longer pessimizes
3829 code when it finds a REG_LABEL note. */
3830 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_LABEL
, label
,
3837 /* Do walk the labels in a vector, but not the first operand of an
3838 ADDR_DIFF_VEC. Don't set the JUMP_LABEL of a vector. */
3841 if (! INSN_DELETED_P (insn
))
3843 int eltnum
= code
== ADDR_DIFF_VEC
? 1 : 0;
3845 for (i
= 0; i
< XVECLEN (x
, eltnum
); i
++)
3846 mark_jump_label (XVECEXP (x
, eltnum
, i
), NULL_RTX
, cross_jump
);
3854 fmt
= GET_RTX_FORMAT (code
);
3855 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3858 mark_jump_label (XEXP (x
, i
), insn
, cross_jump
);
3859 else if (fmt
[i
] == 'E')
3862 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3863 mark_jump_label (XVECEXP (x
, i
, j
), insn
, cross_jump
);
3868 /* If all INSN does is set the pc, delete it,
3869 and delete the insn that set the condition codes for it
3870 if that's what the previous thing was. */
3876 register rtx set
= single_set (insn
);
3878 if (set
&& GET_CODE (SET_DEST (set
)) == PC
)
3879 delete_computation (insn
);
3882 /* Recursively delete prior insns that compute the value (used only by INSN
3883 which the caller is deleting) stored in the register mentioned by NOTE
3884 which is a REG_DEAD note associated with INSN. */
3887 delete_prior_computation (note
, insn
)
3892 rtx reg
= XEXP (note
, 0);
3894 for (our_prev
= prev_nonnote_insn (insn
);
3895 our_prev
&& GET_CODE (our_prev
) == INSN
;
3896 our_prev
= prev_nonnote_insn (our_prev
))
3898 rtx pat
= PATTERN (our_prev
);
3900 /* If we reach a SEQUENCE, it is too complex to try to
3901 do anything with it, so give up. */
3902 if (GET_CODE (pat
) == SEQUENCE
)
3905 if (GET_CODE (pat
) == USE
3906 && GET_CODE (XEXP (pat
, 0)) == INSN
)
3907 /* reorg creates USEs that look like this. We leave them
3908 alone because reorg needs them for its own purposes. */
3911 if (reg_set_p (reg
, pat
))
3913 if (side_effects_p (pat
))
3916 if (GET_CODE (pat
) == PARALLEL
)
3918 /* If we find a SET of something else, we can't
3923 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
3925 rtx part
= XVECEXP (pat
, 0, i
);
3927 if (GET_CODE (part
) == SET
3928 && SET_DEST (part
) != reg
)
3932 if (i
== XVECLEN (pat
, 0))
3933 delete_computation (our_prev
);
3935 else if (GET_CODE (pat
) == SET
3936 && GET_CODE (SET_DEST (pat
)) == REG
)
3938 int dest_regno
= REGNO (SET_DEST (pat
));
3940 = dest_regno
+ (dest_regno
< FIRST_PSEUDO_REGISTER
3941 ? HARD_REGNO_NREGS (dest_regno
,
3942 GET_MODE (SET_DEST (pat
))) : 1);
3943 int regno
= REGNO (reg
);
3944 int endregno
= regno
+ (regno
< FIRST_PSEUDO_REGISTER
3945 ? HARD_REGNO_NREGS (regno
, GET_MODE (reg
)) : 1);
3947 if (dest_regno
>= regno
3948 && dest_endregno
<= endregno
)
3949 delete_computation (our_prev
);
3951 /* We may have a multi-word hard register and some, but not
3952 all, of the words of the register are needed in subsequent
3953 insns. Write REG_UNUSED notes for those parts that were not
3955 else if (dest_regno
<= regno
3956 && dest_endregno
>= endregno
3957 && ! find_regno_note (our_prev
, REG_UNUSED
, REGNO(reg
)))
3961 REG_NOTES (our_prev
)
3962 = gen_rtx_EXPR_LIST (REG_UNUSED
, reg
, REG_NOTES (our_prev
));
3964 for (i
= dest_regno
; i
< dest_endregno
; i
++)
3965 if (! find_regno_note (our_prev
, REG_UNUSED
, i
))
3968 if (i
== dest_endregno
)
3969 delete_computation (our_prev
);
3976 /* If PAT references the register that dies here, it is an
3977 additional use. Hence any prior SET isn't dead. However, this
3978 insn becomes the new place for the REG_DEAD note. */
3979 if (reg_overlap_mentioned_p (reg
, pat
))
3981 XEXP (note
, 1) = REG_NOTES (our_prev
);
3982 REG_NOTES (our_prev
) = note
;
3988 /* Delete INSN and recursively delete insns that compute values used only
3989 by INSN. This uses the REG_DEAD notes computed during flow analysis.
3990 If we are running before flow.c, we need do nothing since flow.c will
3991 delete dead code. We also can't know if the registers being used are
3992 dead or not at this point.
3994 Otherwise, look at all our REG_DEAD notes. If a previous insn does
3995 nothing other than set a register that dies in this insn, we can delete
3998 On machines with CC0, if CC0 is used in this insn, we may be able to
3999 delete the insn that set it. */
4002 delete_computation (insn
)
4009 if (reg_referenced_p (cc0_rtx
, PATTERN (insn
)))
4011 rtx prev
= prev_nonnote_insn (insn
);
4012 /* We assume that at this stage
4013 CC's are always set explicitly
4014 and always immediately before the jump that
4015 will use them. So if the previous insn
4016 exists to set the CC's, delete it
4017 (unless it performs auto-increments, etc.). */
4018 if (prev
&& GET_CODE (prev
) == INSN
4019 && sets_cc0_p (PATTERN (prev
)))
4021 if (sets_cc0_p (PATTERN (prev
)) > 0
4022 && ! side_effects_p (PATTERN (prev
)))
4023 delete_computation (prev
);
4025 /* Otherwise, show that cc0 won't be used. */
4026 REG_NOTES (prev
) = gen_rtx_EXPR_LIST (REG_UNUSED
,
4027 cc0_rtx
, REG_NOTES (prev
));
4032 #ifdef INSN_SCHEDULING
4033 /* ?!? The schedulers do not keep REG_DEAD notes accurate after
4034 reload has completed. The schedulers need to be fixed. Until
4035 they are, we must not rely on the death notes here. */
4036 if (reload_completed
&& flag_schedule_insns_after_reload
)
4043 set
= single_set (insn
);
4045 for (note
= REG_NOTES (insn
); note
; note
= next
)
4047 next
= XEXP (note
, 1);
4049 if (REG_NOTE_KIND (note
) != REG_DEAD
4050 /* Verify that the REG_NOTE is legitimate. */
4051 || GET_CODE (XEXP (note
, 0)) != REG
)
4054 if (set
&& reg_overlap_mentioned_p (SET_DEST (set
), XEXP (note
, 0)))
4057 delete_prior_computation (note
, insn
);
4060 /* The REG_DEAD note may have been omitted for a register
4061 which is both set and used by the insn. */
4063 && GET_CODE (SET_DEST (set
)) == REG
4064 && reg_mentioned_p (SET_DEST (set
), SET_SRC (set
)))
4066 note
= gen_rtx_EXPR_LIST (REG_DEAD
, SET_DEST (set
), NULL_RTX
);
4067 delete_prior_computation (note
, insn
);
4073 /* Delete insn INSN from the chain of insns and update label ref counts.
4074 May delete some following insns as a consequence; may even delete
4075 a label elsewhere and insns that follow it.
4077 Returns the first insn after INSN that was not deleted. */
4083 register rtx next
= NEXT_INSN (insn
);
4084 register rtx prev
= PREV_INSN (insn
);
4085 register int was_code_label
= (GET_CODE (insn
) == CODE_LABEL
);
4086 register int dont_really_delete
= 0;
4088 while (next
&& INSN_DELETED_P (next
))
4089 next
= NEXT_INSN (next
);
4091 /* This insn is already deleted => return first following nondeleted. */
4092 if (INSN_DELETED_P (insn
))
4096 remove_node_from_expr_list (insn
, &nonlocal_goto_handler_labels
);
4098 /* Don't delete user-declared labels. Convert them to special NOTEs
4100 if (was_code_label
&& LABEL_NAME (insn
) != 0
4101 && optimize
&& ! dont_really_delete
)
4103 PUT_CODE (insn
, NOTE
);
4104 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED_LABEL
;
4105 NOTE_SOURCE_FILE (insn
) = 0;
4106 dont_really_delete
= 1;
4109 /* Mark this insn as deleted. */
4110 INSN_DELETED_P (insn
) = 1;
4112 /* If this is an unconditional jump, delete it from the jump chain. */
4113 if (simplejump_p (insn
))
4114 delete_from_jump_chain (insn
);
4116 /* If instruction is followed by a barrier,
4117 delete the barrier too. */
4119 if (next
!= 0 && GET_CODE (next
) == BARRIER
)
4121 INSN_DELETED_P (next
) = 1;
4122 next
= NEXT_INSN (next
);
4125 /* Patch out INSN (and the barrier if any) */
4127 if (optimize
&& ! dont_really_delete
)
4131 NEXT_INSN (prev
) = next
;
4132 if (GET_CODE (prev
) == INSN
&& GET_CODE (PATTERN (prev
)) == SEQUENCE
)
4133 NEXT_INSN (XVECEXP (PATTERN (prev
), 0,
4134 XVECLEN (PATTERN (prev
), 0) - 1)) = next
;
4139 PREV_INSN (next
) = prev
;
4140 if (GET_CODE (next
) == INSN
&& GET_CODE (PATTERN (next
)) == SEQUENCE
)
4141 PREV_INSN (XVECEXP (PATTERN (next
), 0, 0)) = prev
;
4144 if (prev
&& NEXT_INSN (prev
) == 0)
4145 set_last_insn (prev
);
4148 /* If deleting a jump, decrement the count of the label,
4149 and delete the label if it is now unused. */
4151 if (GET_CODE (insn
) == JUMP_INSN
&& JUMP_LABEL (insn
))
4153 rtx lab
= JUMP_LABEL (insn
), lab_next
;
4155 if (--LABEL_NUSES (lab
) == 0)
4157 /* This can delete NEXT or PREV,
4158 either directly if NEXT is JUMP_LABEL (INSN),
4159 or indirectly through more levels of jumps. */
4162 /* I feel a little doubtful about this loop,
4163 but I see no clean and sure alternative way
4164 to find the first insn after INSN that is not now deleted.
4165 I hope this works. */
4166 while (next
&& INSN_DELETED_P (next
))
4167 next
= NEXT_INSN (next
);
4170 else if ((lab_next
= next_nonnote_insn (lab
)) != NULL
4171 && GET_CODE (lab_next
) == JUMP_INSN
4172 && (GET_CODE (PATTERN (lab_next
)) == ADDR_VEC
4173 || GET_CODE (PATTERN (lab_next
)) == ADDR_DIFF_VEC
))
4175 /* If we're deleting the tablejump, delete the dispatch table.
4176 We may not be able to kill the label immediately preceeding
4177 just yet, as it might be referenced in code leading up to
4179 delete_insn (lab_next
);
4183 /* Likewise if we're deleting a dispatch table. */
4185 if (GET_CODE (insn
) == JUMP_INSN
4186 && (GET_CODE (PATTERN (insn
)) == ADDR_VEC
4187 || GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
))
4189 rtx pat
= PATTERN (insn
);
4190 int i
, diff_vec_p
= GET_CODE (pat
) == ADDR_DIFF_VEC
;
4191 int len
= XVECLEN (pat
, diff_vec_p
);
4193 for (i
= 0; i
< len
; i
++)
4194 if (--LABEL_NUSES (XEXP (XVECEXP (pat
, diff_vec_p
, i
), 0)) == 0)
4195 delete_insn (XEXP (XVECEXP (pat
, diff_vec_p
, i
), 0));
4196 while (next
&& INSN_DELETED_P (next
))
4197 next
= NEXT_INSN (next
);
4201 while (prev
&& (INSN_DELETED_P (prev
) || GET_CODE (prev
) == NOTE
))
4202 prev
= PREV_INSN (prev
);
4204 /* If INSN was a label and a dispatch table follows it,
4205 delete the dispatch table. The tablejump must have gone already.
4206 It isn't useful to fall through into a table. */
4209 && NEXT_INSN (insn
) != 0
4210 && GET_CODE (NEXT_INSN (insn
)) == JUMP_INSN
4211 && (GET_CODE (PATTERN (NEXT_INSN (insn
))) == ADDR_VEC
4212 || GET_CODE (PATTERN (NEXT_INSN (insn
))) == ADDR_DIFF_VEC
))
4213 next
= delete_insn (NEXT_INSN (insn
));
4215 /* If INSN was a label, delete insns following it if now unreachable. */
4217 if (was_code_label
&& prev
&& GET_CODE (prev
) == BARRIER
)
4219 register RTX_CODE code
;
4221 && (GET_RTX_CLASS (code
= GET_CODE (next
)) == 'i'
4222 || code
== NOTE
|| code
== BARRIER
4223 || (code
== CODE_LABEL
&& INSN_DELETED_P (next
))))
4226 && NOTE_LINE_NUMBER (next
) != NOTE_INSN_FUNCTION_END
)
4227 next
= NEXT_INSN (next
);
4228 /* Keep going past other deleted labels to delete what follows. */
4229 else if (code
== CODE_LABEL
&& INSN_DELETED_P (next
))
4230 next
= NEXT_INSN (next
);
4232 /* Note: if this deletes a jump, it can cause more
4233 deletion of unreachable code, after a different label.
4234 As long as the value from this recursive call is correct,
4235 this invocation functions correctly. */
4236 next
= delete_insn (next
);
4243 /* Advance from INSN till reaching something not deleted
4244 then return that. May return INSN itself. */
4247 next_nondeleted_insn (insn
)
4250 while (INSN_DELETED_P (insn
))
4251 insn
= NEXT_INSN (insn
);
4255 /* Delete a range of insns from FROM to TO, inclusive.
4256 This is for the sake of peephole optimization, so assume
4257 that whatever these insns do will still be done by a new
4258 peephole insn that will replace them. */
4261 delete_for_peephole (from
, to
)
4262 register rtx from
, to
;
4264 register rtx insn
= from
;
4268 register rtx next
= NEXT_INSN (insn
);
4269 register rtx prev
= PREV_INSN (insn
);
4271 if (GET_CODE (insn
) != NOTE
)
4273 INSN_DELETED_P (insn
) = 1;
4275 /* Patch this insn out of the chain. */
4276 /* We don't do this all at once, because we
4277 must preserve all NOTEs. */
4279 NEXT_INSN (prev
) = next
;
4282 PREV_INSN (next
) = prev
;
4290 /* Note that if TO is an unconditional jump
4291 we *do not* delete the BARRIER that follows,
4292 since the peephole that replaces this sequence
4293 is also an unconditional jump in that case. */
4296 /* We have determined that INSN is never reached, and are about to
4297 delete it. Print a warning if the user asked for one.
4299 To try to make this warning more useful, this should only be called
4300 once per basic block not reached, and it only warns when the basic
4301 block contains more than one line from the current function, and
4302 contains at least one operation. CSE and inlining can duplicate insns,
4303 so it's possible to get spurious warnings from this. */
4306 never_reached_warning (avoided_insn
)
4310 rtx a_line_note
= NULL
;
4311 int two_avoided_lines
= 0;
4312 int contains_insn
= 0;
4314 if (! warn_notreached
)
4317 /* Scan forwards, looking at LINE_NUMBER notes, until
4318 we hit a LABEL or we run out of insns. */
4320 for (insn
= avoided_insn
; insn
!= NULL
; insn
= NEXT_INSN (insn
))
4322 if (GET_CODE (insn
) == CODE_LABEL
)
4324 else if (GET_CODE (insn
) == NOTE
/* A line number note? */
4325 && NOTE_LINE_NUMBER (insn
) >= 0)
4327 if (a_line_note
== NULL
)
4330 two_avoided_lines
|= (NOTE_LINE_NUMBER (a_line_note
)
4331 != NOTE_LINE_NUMBER (insn
));
4333 else if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
4336 if (two_avoided_lines
&& contains_insn
)
4337 warning_with_file_and_line (NOTE_SOURCE_FILE (a_line_note
),
4338 NOTE_LINE_NUMBER (a_line_note
),
4339 "will never be executed");
4342 /* Invert the condition of the jump JUMP, and make it jump
4343 to label NLABEL instead of where it jumps now. */
4346 invert_jump (jump
, nlabel
)
4349 /* We have to either invert the condition and change the label or
4350 do neither. Either operation could fail. We first try to invert
4351 the jump. If that succeeds, we try changing the label. If that fails,
4352 we invert the jump back to what it was. */
4354 if (! invert_exp (PATTERN (jump
), jump
))
4357 if (redirect_jump (jump
, nlabel
))
4359 if (flag_branch_probabilities
)
4361 rtx note
= find_reg_note (jump
, REG_BR_PROB
, 0);
4363 /* An inverted jump means that a probability taken becomes a
4364 probability not taken. Subtract the branch probability from the
4365 probability base to convert it back to a taken probability.
4366 (We don't flip the probability on a branch that's never taken. */
4367 if (note
&& XINT (XEXP (note
, 0), 0) >= 0)
4368 XINT (XEXP (note
, 0), 0) = REG_BR_PROB_BASE
- XINT (XEXP (note
, 0), 0);
4374 if (! invert_exp (PATTERN (jump
), jump
))
4375 /* This should just be putting it back the way it was. */
4381 /* Invert the jump condition of rtx X contained in jump insn, INSN.
4383 Return 1 if we can do so, 0 if we cannot find a way to do so that
4384 matches a pattern. */
4387 invert_exp (x
, insn
)
4391 register RTX_CODE code
;
4393 register const char *fmt
;
4395 code
= GET_CODE (x
);
4397 if (code
== IF_THEN_ELSE
)
4399 register rtx comp
= XEXP (x
, 0);
4402 /* We can do this in two ways: The preferable way, which can only
4403 be done if this is not an integer comparison, is to reverse
4404 the comparison code. Otherwise, swap the THEN-part and ELSE-part
4405 of the IF_THEN_ELSE. If we can't do either, fail. */
4407 if (can_reverse_comparison_p (comp
, insn
)
4408 && validate_change (insn
, &XEXP (x
, 0),
4409 gen_rtx_fmt_ee (reverse_condition (GET_CODE (comp
)),
4410 GET_MODE (comp
), XEXP (comp
, 0),
4411 XEXP (comp
, 1)), 0))
4415 validate_change (insn
, &XEXP (x
, 1), XEXP (x
, 2), 1);
4416 validate_change (insn
, &XEXP (x
, 2), tem
, 1);
4417 return apply_change_group ();
4420 fmt
= GET_RTX_FORMAT (code
);
4421 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4424 if (! invert_exp (XEXP (x
, i
), insn
))
4429 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4430 if (!invert_exp (XVECEXP (x
, i
, j
), insn
))
4438 /* Make jump JUMP jump to label NLABEL instead of where it jumps now.
4439 If the old jump target label is unused as a result,
4440 it and the code following it may be deleted.
4442 If NLABEL is zero, we are to turn the jump into a (possibly conditional)
4445 The return value will be 1 if the change was made, 0 if it wasn't (this
4446 can only occur for NLABEL == 0). */
4449 redirect_jump (jump
, nlabel
)
4452 register rtx olabel
= JUMP_LABEL (jump
);
4454 if (nlabel
== olabel
)
4457 if (! redirect_exp (&PATTERN (jump
), olabel
, nlabel
, jump
))
4460 /* If this is an unconditional branch, delete it from the jump_chain of
4461 OLABEL and add it to the jump_chain of NLABEL (assuming both labels
4462 have UID's in range and JUMP_CHAIN is valid). */
4463 if (jump_chain
&& (simplejump_p (jump
)
4464 || GET_CODE (PATTERN (jump
)) == RETURN
))
4466 int label_index
= nlabel
? INSN_UID (nlabel
) : 0;
4468 delete_from_jump_chain (jump
);
4469 if (label_index
< max_jump_chain
4470 && INSN_UID (jump
) < max_jump_chain
)
4472 jump_chain
[INSN_UID (jump
)] = jump_chain
[label_index
];
4473 jump_chain
[label_index
] = jump
;
4477 JUMP_LABEL (jump
) = nlabel
;
4479 ++LABEL_NUSES (nlabel
);
4481 if (olabel
&& --LABEL_NUSES (olabel
) == 0)
4482 delete_insn (olabel
);
4487 /* Delete the instruction JUMP from any jump chain it might be on. */
4490 delete_from_jump_chain (jump
)
4494 rtx olabel
= JUMP_LABEL (jump
);
4496 /* Handle unconditional jumps. */
4497 if (jump_chain
&& olabel
!= 0
4498 && INSN_UID (olabel
) < max_jump_chain
4499 && simplejump_p (jump
))
4500 index
= INSN_UID (olabel
);
4501 /* Handle return insns. */
4502 else if (jump_chain
&& GET_CODE (PATTERN (jump
)) == RETURN
)
4506 if (jump_chain
[index
] == jump
)
4507 jump_chain
[index
] = jump_chain
[INSN_UID (jump
)];
4512 for (insn
= jump_chain
[index
];
4514 insn
= jump_chain
[INSN_UID (insn
)])
4515 if (jump_chain
[INSN_UID (insn
)] == jump
)
4517 jump_chain
[INSN_UID (insn
)] = jump_chain
[INSN_UID (jump
)];
4523 /* If NLABEL is nonzero, throughout the rtx at LOC,
4524 alter (LABEL_REF OLABEL) to (LABEL_REF NLABEL). If OLABEL is
4525 zero, alter (RETURN) to (LABEL_REF NLABEL).
4527 If NLABEL is zero, alter (LABEL_REF OLABEL) to (RETURN) and check
4528 validity with validate_change. Convert (set (pc) (label_ref olabel))
4531 Return 0 if we found a change we would like to make but it is invalid.
4532 Otherwise, return 1. */
4535 redirect_exp (loc
, olabel
, nlabel
, insn
)
4540 register rtx x
= *loc
;
4541 register RTX_CODE code
= GET_CODE (x
);
4543 register const char *fmt
;
4545 if (code
== LABEL_REF
)
4547 if (XEXP (x
, 0) == olabel
)
4550 XEXP (x
, 0) = nlabel
;
4552 return validate_change (insn
, loc
, gen_rtx_RETURN (VOIDmode
), 0);
4556 else if (code
== RETURN
&& olabel
== 0)
4558 x
= gen_rtx_LABEL_REF (VOIDmode
, nlabel
);
4559 if (loc
== &PATTERN (insn
))
4560 x
= gen_rtx_SET (VOIDmode
, pc_rtx
, x
);
4561 return validate_change (insn
, loc
, x
, 0);
4564 if (code
== SET
&& nlabel
== 0 && SET_DEST (x
) == pc_rtx
4565 && GET_CODE (SET_SRC (x
)) == LABEL_REF
4566 && XEXP (SET_SRC (x
), 0) == olabel
)
4567 return validate_change (insn
, loc
, gen_rtx_RETURN (VOIDmode
), 0);
4569 fmt
= GET_RTX_FORMAT (code
);
4570 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4573 if (! redirect_exp (&XEXP (x
, i
), olabel
, nlabel
, insn
))
4578 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4579 if (! redirect_exp (&XVECEXP (x
, i
, j
), olabel
, nlabel
, insn
))
4587 /* Make jump JUMP jump to label NLABEL, assuming it used to be a tablejump.
4589 If the old jump target label (before the dispatch table) becomes unused,
4590 it and the dispatch table may be deleted. In that case, find the insn
4591 before the jump references that label and delete it and logical successors
4595 redirect_tablejump (jump
, nlabel
)
4598 register rtx olabel
= JUMP_LABEL (jump
);
4600 /* Add this jump to the jump_chain of NLABEL. */
4601 if (jump_chain
&& INSN_UID (nlabel
) < max_jump_chain
4602 && INSN_UID (jump
) < max_jump_chain
)
4604 jump_chain
[INSN_UID (jump
)] = jump_chain
[INSN_UID (nlabel
)];
4605 jump_chain
[INSN_UID (nlabel
)] = jump
;
4608 PATTERN (jump
) = gen_jump (nlabel
);
4609 JUMP_LABEL (jump
) = nlabel
;
4610 ++LABEL_NUSES (nlabel
);
4611 INSN_CODE (jump
) = -1;
4613 if (--LABEL_NUSES (olabel
) == 0)
4615 delete_labelref_insn (jump
, olabel
, 0);
4616 delete_insn (olabel
);
4620 /* Find the insn referencing LABEL that is a logical predecessor of INSN.
4621 If we found one, delete it and then delete this insn if DELETE_THIS is
4622 non-zero. Return non-zero if INSN or a predecessor references LABEL. */
4625 delete_labelref_insn (insn
, label
, delete_this
)
4632 if (GET_CODE (insn
) != NOTE
4633 && reg_mentioned_p (label
, PATTERN (insn
)))
4644 for (link
= LOG_LINKS (insn
); link
; link
= XEXP (link
, 1))
4645 if (delete_labelref_insn (XEXP (link
, 0), label
, 1))
4659 /* Like rtx_equal_p except that it considers two REGs as equal
4660 if they renumber to the same value and considers two commutative
4661 operations to be the same if the order of the operands has been
4664 ??? Addition is not commutative on the PA due to the weird implicit
4665 space register selection rules for memory addresses. Therefore, we
4666 don't consider a + b == b + a.
4668 We could/should make this test a little tighter. Possibly only
4669 disabling it on the PA via some backend macro or only disabling this
4670 case when the PLUS is inside a MEM. */
4673 rtx_renumbered_equal_p (x
, y
)
4677 register RTX_CODE code
= GET_CODE (x
);
4678 register const char *fmt
;
4683 if ((code
== REG
|| (code
== SUBREG
&& GET_CODE (SUBREG_REG (x
)) == REG
))
4684 && (GET_CODE (y
) == REG
|| (GET_CODE (y
) == SUBREG
4685 && GET_CODE (SUBREG_REG (y
)) == REG
)))
4687 int reg_x
= -1, reg_y
= -1;
4688 int word_x
= 0, word_y
= 0;
4690 if (GET_MODE (x
) != GET_MODE (y
))
4693 /* If we haven't done any renumbering, don't
4694 make any assumptions. */
4695 if (reg_renumber
== 0)
4696 return rtx_equal_p (x
, y
);
4700 reg_x
= REGNO (SUBREG_REG (x
));
4701 word_x
= SUBREG_WORD (x
);
4703 if (reg_renumber
[reg_x
] >= 0)
4705 reg_x
= reg_renumber
[reg_x
] + word_x
;
4713 if (reg_renumber
[reg_x
] >= 0)
4714 reg_x
= reg_renumber
[reg_x
];
4717 if (GET_CODE (y
) == SUBREG
)
4719 reg_y
= REGNO (SUBREG_REG (y
));
4720 word_y
= SUBREG_WORD (y
);
4722 if (reg_renumber
[reg_y
] >= 0)
4724 reg_y
= reg_renumber
[reg_y
];
4732 if (reg_renumber
[reg_y
] >= 0)
4733 reg_y
= reg_renumber
[reg_y
];
4736 return reg_x
>= 0 && reg_x
== reg_y
&& word_x
== word_y
;
4739 /* Now we have disposed of all the cases
4740 in which different rtx codes can match. */
4741 if (code
!= GET_CODE (y
))
4753 return INTVAL (x
) == INTVAL (y
);
4756 /* We can't assume nonlocal labels have their following insns yet. */
4757 if (LABEL_REF_NONLOCAL_P (x
) || LABEL_REF_NONLOCAL_P (y
))
4758 return XEXP (x
, 0) == XEXP (y
, 0);
4760 /* Two label-refs are equivalent if they point at labels
4761 in the same position in the instruction stream. */
4762 return (next_real_insn (XEXP (x
, 0))
4763 == next_real_insn (XEXP (y
, 0)));
4766 return XSTR (x
, 0) == XSTR (y
, 0);
4769 /* If we didn't match EQ equality above, they aren't the same. */
4776 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
4778 if (GET_MODE (x
) != GET_MODE (y
))
4781 /* For commutative operations, the RTX match if the operand match in any
4782 order. Also handle the simple binary and unary cases without a loop.
4784 ??? Don't consider PLUS a commutative operator; see comments above. */
4785 if ((code
== EQ
|| code
== NE
|| GET_RTX_CLASS (code
) == 'c')
4787 return ((rtx_renumbered_equal_p (XEXP (x
, 0), XEXP (y
, 0))
4788 && rtx_renumbered_equal_p (XEXP (x
, 1), XEXP (y
, 1)))
4789 || (rtx_renumbered_equal_p (XEXP (x
, 0), XEXP (y
, 1))
4790 && rtx_renumbered_equal_p (XEXP (x
, 1), XEXP (y
, 0))));
4791 else if (GET_RTX_CLASS (code
) == '<' || GET_RTX_CLASS (code
) == '2')
4792 return (rtx_renumbered_equal_p (XEXP (x
, 0), XEXP (y
, 0))
4793 && rtx_renumbered_equal_p (XEXP (x
, 1), XEXP (y
, 1)));
4794 else if (GET_RTX_CLASS (code
) == '1')
4795 return rtx_renumbered_equal_p (XEXP (x
, 0), XEXP (y
, 0));
4797 /* Compare the elements. If any pair of corresponding elements
4798 fail to match, return 0 for the whole things. */
4800 fmt
= GET_RTX_FORMAT (code
);
4801 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4807 if (XWINT (x
, i
) != XWINT (y
, i
))
4812 if (XINT (x
, i
) != XINT (y
, i
))
4817 if (strcmp (XSTR (x
, i
), XSTR (y
, i
)))
4822 if (! rtx_renumbered_equal_p (XEXP (x
, i
), XEXP (y
, i
)))
4827 if (XEXP (x
, i
) != XEXP (y
, i
))
4834 if (XVECLEN (x
, i
) != XVECLEN (y
, i
))
4836 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4837 if (!rtx_renumbered_equal_p (XVECEXP (x
, i
, j
), XVECEXP (y
, i
, j
)))
4848 /* If X is a hard register or equivalent to one or a subregister of one,
4849 return the hard register number. If X is a pseudo register that was not
4850 assigned a hard register, return the pseudo register number. Otherwise,
4851 return -1. Any rtx is valid for X. */
4857 if (GET_CODE (x
) == REG
)
4859 if (REGNO (x
) >= FIRST_PSEUDO_REGISTER
&& reg_renumber
[REGNO (x
)] >= 0)
4860 return reg_renumber
[REGNO (x
)];
4863 if (GET_CODE (x
) == SUBREG
)
4865 int base
= true_regnum (SUBREG_REG (x
));
4866 if (base
>= 0 && base
< FIRST_PSEUDO_REGISTER
)
4867 return SUBREG_WORD (x
) + base
;
4872 /* Optimize code of the form:
4874 for (x = a[i]; x; ...)
4876 for (x = a[i]; x; ...)
4880 Loop optimize will change the above code into
4884 { ...; if (! (x = ...)) break; }
4887 { ...; if (! (x = ...)) break; }
4890 In general, if the first test fails, the program can branch
4891 directly to `foo' and skip the second try which is doomed to fail.
4892 We run this after loop optimization and before flow analysis. */
4894 /* When comparing the insn patterns, we track the fact that different
4895 pseudo-register numbers may have been used in each computation.
4896 The following array stores an equivalence -- same_regs[I] == J means
4897 that pseudo register I was used in the first set of tests in a context
4898 where J was used in the second set. We also count the number of such
4899 pending equivalences. If nonzero, the expressions really aren't the
4902 static int *same_regs
;
4904 static int num_same_regs
;
4906 /* Track any registers modified between the target of the first jump and
4907 the second jump. They never compare equal. */
4909 static char *modified_regs
;
4911 /* Record if memory was modified. */
4913 static int modified_mem
;
4915 /* Called via note_stores on each insn between the target of the first
4916 branch and the second branch. It marks any changed registers. */
4919 mark_modified_reg (dest
, x
)
4921 rtx x ATTRIBUTE_UNUSED
;
4925 if (GET_CODE (dest
) == SUBREG
)
4926 dest
= SUBREG_REG (dest
);
4928 if (GET_CODE (dest
) == MEM
)
4931 if (GET_CODE (dest
) != REG
)
4934 regno
= REGNO (dest
);
4935 if (regno
>= FIRST_PSEUDO_REGISTER
)
4936 modified_regs
[regno
] = 1;
4938 for (i
= 0; i
< HARD_REGNO_NREGS (regno
, GET_MODE (dest
)); i
++)
4939 modified_regs
[regno
+ i
] = 1;
4942 /* F is the first insn in the chain of insns. */
4945 thread_jumps (f
, max_reg
, flag_before_loop
)
4948 int flag_before_loop
;
4950 /* Basic algorithm is to find a conditional branch,
4951 the label it may branch to, and the branch after
4952 that label. If the two branches test the same condition,
4953 walk back from both branch paths until the insn patterns
4954 differ, or code labels are hit. If we make it back to
4955 the target of the first branch, then we know that the first branch
4956 will either always succeed or always fail depending on the relative
4957 senses of the two branches. So adjust the first branch accordingly
4960 rtx label
, b1
, b2
, t1
, t2
;
4961 enum rtx_code code1
, code2
;
4962 rtx b1op0
, b1op1
, b2op0
, b2op1
;
4967 /* Allocate register tables and quick-reset table. */
4968 modified_regs
= (char *) alloca (max_reg
* sizeof (char));
4969 same_regs
= (int *) alloca (max_reg
* sizeof (int));
4970 all_reset
= (int *) alloca (max_reg
* sizeof (int));
4971 for (i
= 0; i
< max_reg
; i
++)
4978 for (b1
= f
; b1
; b1
= NEXT_INSN (b1
))
4980 /* Get to a candidate branch insn. */
4981 if (GET_CODE (b1
) != JUMP_INSN
4982 || ! condjump_p (b1
) || simplejump_p (b1
)
4983 || JUMP_LABEL (b1
) == 0)
4986 bzero (modified_regs
, max_reg
* sizeof (char));
4989 bcopy ((char *) all_reset
, (char *) same_regs
,
4990 max_reg
* sizeof (int));
4993 label
= JUMP_LABEL (b1
);
4995 /* Look for a branch after the target. Record any registers and
4996 memory modified between the target and the branch. Stop when we
4997 get to a label since we can't know what was changed there. */
4998 for (b2
= NEXT_INSN (label
); b2
; b2
= NEXT_INSN (b2
))
5000 if (GET_CODE (b2
) == CODE_LABEL
)
5003 else if (GET_CODE (b2
) == JUMP_INSN
)
5005 /* If this is an unconditional jump and is the only use of
5006 its target label, we can follow it. */
5007 if (simplejump_p (b2
)
5008 && JUMP_LABEL (b2
) != 0
5009 && LABEL_NUSES (JUMP_LABEL (b2
)) == 1)
5011 b2
= JUMP_LABEL (b2
);
5018 if (GET_CODE (b2
) != CALL_INSN
&& GET_CODE (b2
) != INSN
)
5021 if (GET_CODE (b2
) == CALL_INSN
)
5024 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
5025 if (call_used_regs
[i
] && ! fixed_regs
[i
]
5026 && i
!= STACK_POINTER_REGNUM
5027 && i
!= FRAME_POINTER_REGNUM
5028 && i
!= HARD_FRAME_POINTER_REGNUM
5029 && i
!= ARG_POINTER_REGNUM
)
5030 modified_regs
[i
] = 1;
5033 note_stores (PATTERN (b2
), mark_modified_reg
);
5036 /* Check the next candidate branch insn from the label
5039 || GET_CODE (b2
) != JUMP_INSN
5041 || ! condjump_p (b2
)
5042 || simplejump_p (b2
))
5045 /* Get the comparison codes and operands, reversing the
5046 codes if appropriate. If we don't have comparison codes,
5047 we can't do anything. */
5048 b1op0
= XEXP (XEXP (SET_SRC (PATTERN (b1
)), 0), 0);
5049 b1op1
= XEXP (XEXP (SET_SRC (PATTERN (b1
)), 0), 1);
5050 code1
= GET_CODE (XEXP (SET_SRC (PATTERN (b1
)), 0));
5051 if (XEXP (SET_SRC (PATTERN (b1
)), 1) == pc_rtx
)
5052 code1
= reverse_condition (code1
);
5054 b2op0
= XEXP (XEXP (SET_SRC (PATTERN (b2
)), 0), 0);
5055 b2op1
= XEXP (XEXP (SET_SRC (PATTERN (b2
)), 0), 1);
5056 code2
= GET_CODE (XEXP (SET_SRC (PATTERN (b2
)), 0));
5057 if (XEXP (SET_SRC (PATTERN (b2
)), 1) == pc_rtx
)
5058 code2
= reverse_condition (code2
);
5060 /* If they test the same things and knowing that B1 branches
5061 tells us whether or not B2 branches, check if we
5062 can thread the branch. */
5063 if (rtx_equal_for_thread_p (b1op0
, b2op0
, b2
)
5064 && rtx_equal_for_thread_p (b1op1
, b2op1
, b2
)
5065 && (comparison_dominates_p (code1
, code2
)
5066 || (comparison_dominates_p (code1
, reverse_condition (code2
))
5067 && can_reverse_comparison_p (XEXP (SET_SRC (PATTERN (b1
)),
5071 t1
= prev_nonnote_insn (b1
);
5072 t2
= prev_nonnote_insn (b2
);
5074 while (t1
!= 0 && t2
!= 0)
5078 /* We have reached the target of the first branch.
5079 If there are no pending register equivalents,
5080 we know that this branch will either always
5081 succeed (if the senses of the two branches are
5082 the same) or always fail (if not). */
5085 if (num_same_regs
!= 0)
5088 if (comparison_dominates_p (code1
, code2
))
5089 new_label
= JUMP_LABEL (b2
);
5091 new_label
= get_label_after (b2
);
5093 if (JUMP_LABEL (b1
) != new_label
)
5095 rtx prev
= PREV_INSN (new_label
);
5097 if (flag_before_loop
5098 && GET_CODE (prev
) == NOTE
5099 && NOTE_LINE_NUMBER (prev
) == NOTE_INSN_LOOP_BEG
)
5101 /* Don't thread to the loop label. If a loop
5102 label is reused, loop optimization will
5103 be disabled for that loop. */
5104 new_label
= gen_label_rtx ();
5105 emit_label_after (new_label
, PREV_INSN (prev
));
5107 changed
|= redirect_jump (b1
, new_label
);
5112 /* If either of these is not a normal insn (it might be
5113 a JUMP_INSN, CALL_INSN, or CODE_LABEL) we fail. (NOTEs
5114 have already been skipped above.) Similarly, fail
5115 if the insns are different. */
5116 if (GET_CODE (t1
) != INSN
|| GET_CODE (t2
) != INSN
5117 || recog_memoized (t1
) != recog_memoized (t2
)
5118 || ! rtx_equal_for_thread_p (PATTERN (t1
),
5122 t1
= prev_nonnote_insn (t1
);
5123 t2
= prev_nonnote_insn (t2
);
5130 /* This is like RTX_EQUAL_P except that it knows about our handling of
5131 possibly equivalent registers and knows to consider volatile and
5132 modified objects as not equal.
5134 YINSN is the insn containing Y. */
5137 rtx_equal_for_thread_p (x
, y
, yinsn
)
5143 register enum rtx_code code
;
5144 register const char *fmt
;
5146 code
= GET_CODE (x
);
5147 /* Rtx's of different codes cannot be equal. */
5148 if (code
!= GET_CODE (y
))
5151 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
5152 (REG:SI x) and (REG:HI x) are NOT equivalent. */
5154 if (GET_MODE (x
) != GET_MODE (y
))
5157 /* For floating-point, consider everything unequal. This is a bit
5158 pessimistic, but this pass would only rarely do anything for FP
5160 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
5161 && FLOAT_MODE_P (GET_MODE (x
)) && ! flag_fast_math
)
5164 /* For commutative operations, the RTX match if the operand match in any
5165 order. Also handle the simple binary and unary cases without a loop. */
5166 if (code
== EQ
|| code
== NE
|| GET_RTX_CLASS (code
) == 'c')
5167 return ((rtx_equal_for_thread_p (XEXP (x
, 0), XEXP (y
, 0), yinsn
)
5168 && rtx_equal_for_thread_p (XEXP (x
, 1), XEXP (y
, 1), yinsn
))
5169 || (rtx_equal_for_thread_p (XEXP (x
, 0), XEXP (y
, 1), yinsn
)
5170 && rtx_equal_for_thread_p (XEXP (x
, 1), XEXP (y
, 0), yinsn
)));
5171 else if (GET_RTX_CLASS (code
) == '<' || GET_RTX_CLASS (code
) == '2')
5172 return (rtx_equal_for_thread_p (XEXP (x
, 0), XEXP (y
, 0), yinsn
)
5173 && rtx_equal_for_thread_p (XEXP (x
, 1), XEXP (y
, 1), yinsn
));
5174 else if (GET_RTX_CLASS (code
) == '1')
5175 return rtx_equal_for_thread_p (XEXP (x
, 0), XEXP (y
, 0), yinsn
);
5177 /* Handle special-cases first. */
5181 if (REGNO (x
) == REGNO (y
) && ! modified_regs
[REGNO (x
)])
5184 /* If neither is user variable or hard register, check for possible
5186 if (REG_USERVAR_P (x
) || REG_USERVAR_P (y
)
5187 || REGNO (x
) < FIRST_PSEUDO_REGISTER
5188 || REGNO (y
) < FIRST_PSEUDO_REGISTER
)
5191 if (same_regs
[REGNO (x
)] == -1)
5193 same_regs
[REGNO (x
)] = REGNO (y
);
5196 /* If this is the first time we are seeing a register on the `Y'
5197 side, see if it is the last use. If not, we can't thread the
5198 jump, so mark it as not equivalent. */
5199 if (REGNO_LAST_UID (REGNO (y
)) != INSN_UID (yinsn
))
5205 return (same_regs
[REGNO (x
)] == REGNO (y
));
5210 /* If memory modified or either volatile, not equivalent.
5211 Else, check address. */
5212 if (modified_mem
|| MEM_VOLATILE_P (x
) || MEM_VOLATILE_P (y
))
5215 return rtx_equal_for_thread_p (XEXP (x
, 0), XEXP (y
, 0), yinsn
);
5218 if (MEM_VOLATILE_P (x
) || MEM_VOLATILE_P (y
))
5224 /* Cancel a pending `same_regs' if setting equivalenced registers.
5225 Then process source. */
5226 if (GET_CODE (SET_DEST (x
)) == REG
5227 && GET_CODE (SET_DEST (y
)) == REG
)
5229 if (same_regs
[REGNO (SET_DEST (x
))] == REGNO (SET_DEST (y
)))
5231 same_regs
[REGNO (SET_DEST (x
))] = -1;
5234 else if (REGNO (SET_DEST (x
)) != REGNO (SET_DEST (y
)))
5238 if (rtx_equal_for_thread_p (SET_DEST (x
), SET_DEST (y
), yinsn
) == 0)
5241 return rtx_equal_for_thread_p (SET_SRC (x
), SET_SRC (y
), yinsn
);
5244 return XEXP (x
, 0) == XEXP (y
, 0);
5247 return XSTR (x
, 0) == XSTR (y
, 0);
5256 fmt
= GET_RTX_FORMAT (code
);
5257 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
5262 if (XWINT (x
, i
) != XWINT (y
, i
))
5268 if (XINT (x
, i
) != XINT (y
, i
))
5274 /* Two vectors must have the same length. */
5275 if (XVECLEN (x
, i
) != XVECLEN (y
, i
))
5278 /* And the corresponding elements must match. */
5279 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5280 if (rtx_equal_for_thread_p (XVECEXP (x
, i
, j
),
5281 XVECEXP (y
, i
, j
), yinsn
) == 0)
5286 if (rtx_equal_for_thread_p (XEXP (x
, i
), XEXP (y
, i
), yinsn
) == 0)
5292 if (strcmp (XSTR (x
, i
), XSTR (y
, i
)))
5297 /* These are just backpointers, so they don't matter. */
5304 /* It is believed that rtx's at this level will never
5305 contain anything but integers and other rtx's,
5306 except for within LABEL_REFs and SYMBOL_REFs. */
5316 /* Return the insn that NEW can be safely inserted in front of starting at
5317 the jump insn INSN. Return 0 if it is not safe to do this jump
5318 optimization. Note that NEW must contain a single set. */
5321 find_insert_position (insn
, new)
5328 /* If NEW does not clobber, it is safe to insert NEW before INSN. */
5329 if (GET_CODE (PATTERN (new)) != PARALLEL
)
5332 for (i
= XVECLEN (PATTERN (new), 0) - 1; i
>= 0; i
--)
5333 if (GET_CODE (XVECEXP (PATTERN (new), 0, i
)) == CLOBBER
5334 && reg_overlap_mentioned_p (XEXP (XVECEXP (PATTERN (new), 0, i
), 0),
5341 /* There is a good chance that the previous insn PREV sets the thing
5342 being clobbered (often the CC in a hard reg). If PREV does not
5343 use what NEW sets, we can insert NEW before PREV. */
5345 prev
= prev_active_insn (insn
);
5346 for (i
= XVECLEN (PATTERN (new), 0) - 1; i
>= 0; i
--)
5347 if (GET_CODE (XVECEXP (PATTERN (new), 0, i
)) == CLOBBER
5348 && reg_overlap_mentioned_p (XEXP (XVECEXP (PATTERN (new), 0, i
), 0),
5350 && ! modified_in_p (XEXP (XVECEXP (PATTERN (new), 0, i
), 0),
5354 return reg_mentioned_p (SET_DEST (single_set (new)), prev
) ? 0 : prev
;
5356 #endif /* !HAVE_cc0 */