Line data Source code
1 : /* Optimize jump instructions, for GNU compiler.
2 : Copyright (C) 1987-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
6 : GCC is free software; you can redistribute it and/or modify it under
7 : the terms of the GNU General Public License as published by the Free
8 : Software Foundation; either version 3, or (at your option) any later
9 : version.
10 :
11 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with GCC; see the file COPYING3. If not see
18 : <http://www.gnu.org/licenses/>. */
19 :
20 : /* This is the pathetic reminder of old fame of the jump-optimization pass
21 : of the compiler. Now it contains basically a set of utility functions to
22 : operate with jumps.
23 :
24 : Each CODE_LABEL has a count of the times it is used
25 : stored in the LABEL_NUSES internal field, and each JUMP_INSN
26 : has one label that it refers to stored in the
27 : JUMP_LABEL internal field. With this we can detect labels that
28 : become unused because of the deletion of all the jumps that
29 : formerly used them. The JUMP_LABEL info is sometimes looked
30 : at by later passes. For return insns, it contains either a
31 : RETURN or a SIMPLE_RETURN rtx.
32 :
33 : The subroutines redirect_jump and invert_jump are used
34 : from other passes as well. */
35 :
36 : #include "config.h"
37 : #include "system.h"
38 : #include "coretypes.h"
39 : #include "backend.h"
40 : #include "target.h"
41 : #include "rtl.h"
42 : #include "tree.h"
43 : #include "cfghooks.h"
44 : #include "tree-pass.h"
45 : #include "memmodel.h"
46 : #include "tm_p.h"
47 : #include "insn-config.h"
48 : #include "regs.h"
49 : #include "emit-rtl.h"
50 : #include "recog.h"
51 : #include "cfgrtl.h"
52 : #include "rtl-iter.h"
53 :
54 : /* Optimize jump y; x: ... y: jumpif... x?
55 : Don't know if it is worth bothering with. */
56 : /* Optimize two cases of conditional jump to conditional jump?
57 : This can never delete any instruction or make anything dead,
58 : or even change what is live at any point.
59 : So perhaps let combiner do it. */
60 :
61 : static void init_label_info (rtx_insn *);
62 : static void mark_all_labels (rtx_insn *);
63 : static void mark_jump_label_1 (rtx, rtx_insn *, bool, bool);
64 : static void mark_jump_label_asm (rtx, rtx_insn *);
65 : static void redirect_exp_1 (rtx *, rtx, rtx, rtx_insn *);
66 : static bool invert_exp_1 (rtx, rtx_jump_insn *);
67 :
68 : /* Worker for rebuild_jump_labels and rebuild_jump_labels_chain. */
69 : static void
70 7459113 : rebuild_jump_labels_1 (rtx_insn *f, bool count_forced)
71 : {
72 7459113 : timevar_push (TV_REBUILD_JUMP);
73 7459113 : init_label_info (f);
74 7459113 : mark_all_labels (f);
75 :
76 : /* Keep track of labels used from static data; we don't track them
77 : closely enough to delete them here, so make sure their reference
78 : count doesn't drop to zero. */
79 :
80 7459113 : if (count_forced)
81 : {
82 : rtx_insn *insn;
83 : unsigned int i;
84 4653908 : FOR_EACH_VEC_SAFE_ELT (forced_labels, i, insn)
85 93608 : if (LABEL_P (insn))
86 68086 : LABEL_NUSES (insn)++;
87 : }
88 7459113 : timevar_pop (TV_REBUILD_JUMP);
89 7459113 : }
90 :
91 : /* This function rebuilds the JUMP_LABEL field and REG_LABEL_TARGET
92 : notes in jumping insns and REG_LABEL_OPERAND notes in non-jumping
93 : instructions and jumping insns that have labels as operands
94 : (e.g. cbranchsi4). */
95 : void
96 4560300 : rebuild_jump_labels (rtx_insn *f)
97 : {
98 4560300 : rebuild_jump_labels_1 (f, true);
99 4560300 : }
100 :
101 : /* This function is like rebuild_jump_labels, but doesn't run over
102 : forced_labels. It can be used on insn chains that aren't the
103 : main function chain. */
104 : void
105 2898813 : rebuild_jump_labels_chain (rtx_insn *chain)
106 : {
107 2898813 : rebuild_jump_labels_1 (chain, false);
108 2898813 : }
109 :
110 : /* Some old code expects exactly one BARRIER as the NEXT_INSN of a
111 : non-fallthru insn. This is not generally true, as multiple barriers
112 : may have crept in, or the BARRIER may be separated from the last
113 : real insn by one or more NOTEs.
114 :
115 : This simple pass moves barriers and removes duplicates so that the
116 : old code is happy.
117 : */
118 : static unsigned int
119 1517128 : cleanup_barriers (void)
120 : {
121 1517128 : rtx_insn *insn;
122 215295930 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
123 : {
124 213778802 : if (BARRIER_P (insn))
125 : {
126 4875482 : rtx_insn *prev = prev_nonnote_nondebug_insn (insn);
127 4875482 : if (!prev)
128 0 : continue;
129 :
130 4875482 : if (BARRIER_P (prev))
131 5744 : delete_insn (insn);
132 4869738 : else if (prev != PREV_INSN (insn))
133 : {
134 147387 : basic_block bb = BLOCK_FOR_INSN (prev);
135 147387 : rtx_insn *end = PREV_INSN (insn);
136 147387 : reorder_insns_nobb (insn, insn, prev);
137 147387 : if (bb)
138 : {
139 : /* If the backend called in machine reorg compute_bb_for_insn
140 : and didn't free_bb_for_insn again, preserve basic block
141 : boundaries. Move the end of basic block to PREV since
142 : it is followed by a barrier now, and clear BLOCK_FOR_INSN
143 : on the following notes.
144 : ??? Maybe the proper solution for the targets that have
145 : cfg around after machine reorg is not to run cleanup_barriers
146 : pass at all. */
147 147387 : BB_END (bb) = prev;
148 568653 : do
149 : {
150 568653 : prev = NEXT_INSN (prev);
151 568653 : if (prev != insn && BLOCK_FOR_INSN (prev) == bb)
152 1344 : BLOCK_FOR_INSN (prev) = NULL;
153 : }
154 568653 : while (prev != end);
155 : }
156 : }
157 : }
158 : }
159 1517128 : return 0;
160 : }
161 :
162 : namespace {
163 :
164 : const pass_data pass_data_cleanup_barriers =
165 : {
166 : RTL_PASS, /* type */
167 : "barriers", /* name */
168 : OPTGROUP_NONE, /* optinfo_flags */
169 : TV_NONE, /* tv_id */
170 : 0, /* properties_required */
171 : 0, /* properties_provided */
172 : 0, /* properties_destroyed */
173 : 0, /* todo_flags_start */
174 : 0, /* todo_flags_finish */
175 : };
176 :
177 : class pass_cleanup_barriers : public rtl_opt_pass
178 : {
179 : public:
180 297180 : pass_cleanup_barriers (gcc::context *ctxt)
181 594360 : : rtl_opt_pass (pass_data_cleanup_barriers, ctxt)
182 : {}
183 :
184 : /* opt_pass methods: */
185 1517128 : unsigned int execute (function *) final override
186 : {
187 1517128 : return cleanup_barriers ();
188 : }
189 :
190 : }; // class pass_cleanup_barriers
191 :
192 : } // anon namespace
193 :
194 : rtl_opt_pass *
195 297180 : make_pass_cleanup_barriers (gcc::context *ctxt)
196 : {
197 297180 : return new pass_cleanup_barriers (ctxt);
198 : }
199 :
200 :
201 : /* Initialize LABEL_NUSES and JUMP_LABEL fields, add REG_LABEL_TARGET
202 : for remaining targets for JUMP_P. Delete any REG_LABEL_OPERAND
203 : notes whose labels don't occur in the insn any more. */
204 :
205 : static void
206 7459113 : init_label_info (rtx_insn *f)
207 : {
208 7459113 : rtx_insn *insn;
209 :
210 690278074 : for (insn = f; insn; insn = NEXT_INSN (insn))
211 : {
212 682818961 : if (LABEL_P (insn))
213 28250570 : LABEL_NUSES (insn) = (LABEL_PRESERVE_P (insn) != 0);
214 :
215 : /* REG_LABEL_TARGET notes (including the JUMP_LABEL field) are
216 : sticky and not reset here; that way we won't lose association
217 : with a label when e.g. the source for a target register
218 : disappears out of reach for targets that may use jump-target
219 : registers. Jump transformations are supposed to transform
220 : any REG_LABEL_TARGET notes. The target label reference in a
221 : branch may disappear from the branch (and from the
222 : instruction before it) for other reasons, like register
223 : allocation. */
224 :
225 682818961 : if (INSN_P (insn))
226 : {
227 560739879 : rtx note, next;
228 :
229 775291321 : for (note = REG_NOTES (insn); note; note = next)
230 : {
231 214551442 : next = XEXP (note, 1);
232 214551442 : if (REG_NOTE_KIND (note) == REG_LABEL_OPERAND
233 214551442 : && ! reg_mentioned_p (XEXP (note, 0), PATTERN (insn)))
234 43 : remove_note (insn, note);
235 : }
236 : }
237 : }
238 7459113 : }
239 :
240 : /* A subroutine of mark_all_labels. Trivially propagate a simple label
241 : load into a jump_insn that uses it. */
242 :
243 : static void
244 3588 : maybe_propagate_label_ref (rtx_insn *jump_insn, rtx_insn *prev_nonjump_insn)
245 : {
246 3588 : rtx label_note, pc, pc_src;
247 :
248 3588 : pc = pc_set (jump_insn);
249 3588 : pc_src = pc != NULL ? SET_SRC (pc) : NULL;
250 3588 : label_note = find_reg_note (prev_nonjump_insn, REG_LABEL_OPERAND, NULL);
251 :
252 : /* If the previous non-jump insn sets something to a label,
253 : something that this jump insn uses, make that label the primary
254 : target of this insn if we don't yet have any. That previous
255 : insn must be a single_set and not refer to more than one label.
256 : The jump insn must not refer to other labels as jump targets
257 : and must be a plain (set (pc) ...), maybe in a parallel, and
258 : may refer to the item being set only directly or as one of the
259 : arms in an IF_THEN_ELSE. */
260 :
261 3588 : if (label_note != NULL && pc_src != NULL)
262 : {
263 59 : rtx label_set = single_set (prev_nonjump_insn);
264 59 : rtx label_dest = label_set != NULL ? SET_DEST (label_set) : NULL;
265 :
266 59 : if (label_set != NULL
267 : /* The source must be the direct LABEL_REF, not a
268 : PLUS, UNSPEC, IF_THEN_ELSE etc. */
269 59 : && GET_CODE (SET_SRC (label_set)) == LABEL_REF
270 2 : && (rtx_equal_p (label_dest, pc_src)
271 0 : || (GET_CODE (pc_src) == IF_THEN_ELSE
272 0 : && (rtx_equal_p (label_dest, XEXP (pc_src, 1))
273 0 : || rtx_equal_p (label_dest, XEXP (pc_src, 2))))))
274 : {
275 : /* The CODE_LABEL referred to in the note must be the
276 : CODE_LABEL in the LABEL_REF of the "set". We can
277 : conveniently use it for the marker function, which
278 : requires a LABEL_REF wrapping. */
279 2 : gcc_assert (XEXP (label_note, 0) == label_ref_label (SET_SRC (label_set)));
280 :
281 2 : mark_jump_label_1 (label_set, jump_insn, false, true);
282 :
283 2 : gcc_assert (JUMP_LABEL (jump_insn) == XEXP (label_note, 0));
284 : }
285 : }
286 3588 : }
287 :
288 : /* Mark the label each jump jumps to.
289 : Combine consecutive labels, and count uses of labels. */
290 :
291 : static void
292 7459113 : mark_all_labels (rtx_insn *f)
293 : {
294 7459113 : rtx_insn *insn;
295 :
296 7459113 : if (current_ir_type () == IR_RTL_CFGLAYOUT)
297 : {
298 308718 : basic_block bb;
299 9581611 : FOR_EACH_BB_FN (bb, cfun)
300 : {
301 : /* In cfglayout mode, we don't bother with trivial next-insn
302 : propagation of LABEL_REFs into JUMP_LABEL. This will be
303 : handled by other optimizers using better algorithms. */
304 120450022 : FOR_BB_INSNS (bb, insn)
305 : {
306 111177129 : gcc_assert (! insn->deleted ());
307 111177129 : if (NONDEBUG_INSN_P (insn))
308 46802335 : mark_jump_label (PATTERN (insn), insn, 0);
309 : }
310 :
311 : /* In cfglayout mode, there may be non-insns between the
312 : basic blocks. If those non-insns represent tablejump data,
313 : they contain label references that we must record. */
314 9283715 : for (insn = BB_HEADER (bb); insn; insn = NEXT_INSN (insn))
315 10822 : if (JUMP_TABLE_DATA_P (insn))
316 0 : mark_jump_label (PATTERN (insn), insn, 0);
317 9769963 : for (insn = BB_FOOTER (bb); insn; insn = NEXT_INSN (insn))
318 497070 : if (JUMP_TABLE_DATA_P (insn))
319 7644 : mark_jump_label (PATTERN (insn), insn, 0);
320 : }
321 : }
322 : else
323 : {
324 : rtx_insn *prev_nonjump_insn = NULL;
325 578792227 : for (insn = f; insn; insn = NEXT_INSN (insn))
326 : {
327 571641832 : if (insn->deleted ())
328 : ;
329 571641832 : else if (LABEL_P (insn))
330 : prev_nonjump_insn = NULL;
331 548260027 : else if (JUMP_TABLE_DATA_P (insn))
332 25447 : mark_jump_label (PATTERN (insn), insn, 0);
333 548234580 : else if (NONDEBUG_INSN_P (insn))
334 : {
335 275297252 : mark_jump_label (PATTERN (insn), insn, 0);
336 275297252 : if (JUMP_P (insn))
337 : {
338 31194124 : if (JUMP_LABEL (insn) == NULL && prev_nonjump_insn != NULL)
339 3588 : maybe_propagate_label_ref (insn, prev_nonjump_insn);
340 : }
341 : else
342 : prev_nonjump_insn = insn;
343 : }
344 : }
345 : }
346 7459113 : }
347 :
348 : /* Given a comparison (CODE ARG0 ARG1), inside an insn, INSN, return a code
349 : of reversed comparison if it is possible to do so. Otherwise return UNKNOWN.
350 : UNKNOWN may be returned in case we are having CC_MODE compare and we don't
351 : know whether it's source is floating point or integer comparison. Machine
352 : description should define REVERSIBLE_CC_MODE and REVERSE_CONDITION macros
353 : to help this function avoid overhead in these cases. */
354 : enum rtx_code
355 66486871 : reversed_comparison_code_parts (enum rtx_code code, const_rtx arg0,
356 : const_rtx arg1, const rtx_insn *insn)
357 : {
358 66486871 : machine_mode mode;
359 :
360 : /* If this is not actually a comparison, we can't reverse it. */
361 66486871 : if (GET_RTX_CLASS (code) != RTX_COMPARE
362 : && GET_RTX_CLASS (code) != RTX_COMM_COMPARE)
363 : return UNKNOWN;
364 :
365 66486871 : mode = GET_MODE (arg0);
366 66486871 : if (mode == VOIDmode)
367 36556 : mode = GET_MODE (arg1);
368 :
369 : /* First see if machine description supplies us way to reverse the
370 : comparison. Give it priority over everything else to allow
371 : machine description to do tricks. */
372 66486871 : if (GET_MODE_CLASS (mode) == MODE_CC
373 : && REVERSIBLE_CC_MODE (mode))
374 32664985 : return REVERSE_CONDITION (code, mode);
375 :
376 : /* Try a few special cases based on the comparison code. */
377 33821886 : switch (code)
378 : {
379 29413120 : case GEU:
380 29413120 : case GTU:
381 29413120 : case LEU:
382 29413120 : case LTU:
383 29413120 : case NE:
384 29413120 : case EQ:
385 : /* It is always safe to reverse EQ and NE, even for the floating
386 : point. Similarly the unsigned comparisons are never used for
387 : floating point so we can reverse them in the default way. */
388 29413120 : return reverse_condition (code);
389 1899 : case ORDERED:
390 1899 : case UNORDERED:
391 : /* In case we already see unordered comparison, we can be sure to
392 : be dealing with floating point so we don't need any more tests. */
393 1899 : return reverse_condition_maybe_unordered (code);
394 6593 : case LTGT:
395 6593 : case UNEQ:
396 : /* LTGT is signaling and UNEQ is quiet, so reversing one into the
397 : other changes whether a quiet NaN operand raises an exception.
398 : That only matters if FP traps are honored and the operands may
399 : be NaNs; a MODE_CC comparison does not tell us the latter. */
400 6593 : if (flag_trapping_math
401 6593 : && (GET_MODE_CLASS (mode) == MODE_CC || HONOR_NANS (mode)))
402 : return UNKNOWN;
403 5769 : return reverse_condition_maybe_unordered (code);
404 : case UNLT:
405 : case UNLE:
406 : case UNGT:
407 : case UNGE:
408 : /* We don't have safe way to reverse these yet. */
409 : return UNKNOWN;
410 4377119 : default:
411 4377119 : break;
412 : }
413 :
414 4377119 : if (GET_MODE_CLASS (mode) == MODE_CC)
415 : {
416 : /* Try to search for the comparison to determine the real mode.
417 : This code is expensive, but with sane machine description it
418 : will be never used, since REVERSIBLE_CC_MODE will return true
419 : in all cases. */
420 : if (! insn)
421 : return UNKNOWN;
422 :
423 : /* These CONST_CAST's are okay because prev_nonnote_insn just
424 : returns its argument and we assign it to a const_rtx
425 : variable. */
426 : for (rtx_insn *prev = prev_nonnote_insn (const_cast<rtx_insn *> (insn));
427 : prev != 0 && !LABEL_P (prev);
428 : prev = prev_nonnote_insn (prev))
429 : {
430 : const_rtx set = set_of (arg0, prev);
431 : if (set && GET_CODE (set) == SET
432 : && rtx_equal_p (SET_DEST (set), arg0))
433 : {
434 : rtx src = SET_SRC (set);
435 :
436 : if (GET_CODE (src) == COMPARE)
437 : {
438 : rtx comparison = src;
439 : arg0 = XEXP (src, 0);
440 : mode = GET_MODE (arg0);
441 : if (mode == VOIDmode)
442 : mode = GET_MODE (XEXP (comparison, 1));
443 : break;
444 : }
445 : /* We can get past reg-reg moves. This may be useful for model
446 : of i387 comparisons that first move flag registers around. */
447 : if (REG_P (src))
448 : {
449 : arg0 = src;
450 : continue;
451 : }
452 : }
453 : /* If register is clobbered in some ununderstandable way,
454 : give up. */
455 : if (set)
456 : return UNKNOWN;
457 : }
458 : }
459 :
460 : /* Test for an integer condition, or a floating-point comparison
461 : in which NaNs can be ignored. */
462 4377119 : if (CONST_INT_P (arg0)
463 4377119 : || (GET_MODE (arg0) != VOIDmode
464 : && GET_MODE_CLASS (mode) != MODE_CC
465 4350852 : && !HONOR_NANS (mode)))
466 3963850 : return reverse_condition (code);
467 :
468 : return UNKNOWN;
469 : }
470 :
471 : /* A wrapper around the previous function to take COMPARISON as rtx
472 : expression. This simplifies many callers. */
473 : enum rtx_code
474 56887458 : reversed_comparison_code (const_rtx comparison, const rtx_insn *insn)
475 : {
476 56887458 : if (!COMPARISON_P (comparison))
477 : return UNKNOWN;
478 56887458 : return reversed_comparison_code_parts (GET_CODE (comparison),
479 56887458 : XEXP (comparison, 0),
480 56887458 : XEXP (comparison, 1), insn);
481 : }
482 :
483 : /* Return comparison with reversed code of EXP.
484 : Return NULL_RTX in case we fail to do the reversal. */
485 : rtx
486 339190 : reversed_comparison (const_rtx exp, machine_mode mode)
487 : {
488 339190 : enum rtx_code reversed_code = reversed_comparison_code (exp, NULL);
489 339190 : if (reversed_code == UNKNOWN)
490 : return NULL_RTX;
491 : else
492 677608 : return simplify_gen_relational (reversed_code, mode, VOIDmode,
493 338804 : XEXP (exp, 0), XEXP (exp, 1));
494 : }
495 :
496 :
497 : /* Given an rtx-code for a comparison, return the code for the negated
498 : comparison. If no such code exists, return UNKNOWN.
499 :
500 : WATCH OUT! reverse_condition is not safe to use on a jump that might
501 : be acting on the results of an IEEE floating point comparison, because
502 : of the special treatment of non-signaling nans in comparisons.
503 : Use reversed_comparison_code instead. */
504 :
505 : enum rtx_code
506 81618597 : reverse_condition (enum rtx_code code)
507 : {
508 81618597 : switch (code)
509 : {
510 : case EQ:
511 : return NE;
512 : case NE:
513 : return EQ;
514 : case GT:
515 : return LE;
516 : case GE:
517 : return LT;
518 : case LT:
519 : return GE;
520 : case LE:
521 : return GT;
522 : case GTU:
523 : return LEU;
524 : case GEU:
525 : return LTU;
526 : case LTU:
527 : return GEU;
528 : case LEU:
529 : return GTU;
530 : case UNORDERED:
531 : return ORDERED;
532 : case ORDERED:
533 : return UNORDERED;
534 :
535 : case UNLT:
536 : case UNLE:
537 : case UNGT:
538 : case UNGE:
539 : case UNEQ:
540 : case LTGT:
541 : return UNKNOWN;
542 :
543 0 : default:
544 0 : gcc_unreachable ();
545 : }
546 : }
547 :
548 : /* Similar, but we're allowed to generate unordered comparisons, which
549 : makes it safe for IEEE floating-point. Of course, we have to recognize
550 : that the target will support them too... */
551 :
552 : enum rtx_code
553 4811181 : reverse_condition_maybe_unordered (enum rtx_code code)
554 : {
555 4811181 : switch (code)
556 : {
557 : case EQ:
558 : return NE;
559 275862 : case NE:
560 275862 : return EQ;
561 236931 : case GT:
562 236931 : return UNLE;
563 91414 : case GE:
564 91414 : return UNLT;
565 2546 : case LT:
566 2546 : return UNGE;
567 3682 : case LE:
568 3682 : return UNGT;
569 128520 : case LTGT:
570 128520 : return UNEQ;
571 1712060 : case UNORDERED:
572 1712060 : return ORDERED;
573 184915 : case ORDERED:
574 184915 : return UNORDERED;
575 100165 : case UNLT:
576 100165 : return GE;
577 215779 : case UNLE:
578 215779 : return GT;
579 83 : case UNGT:
580 83 : return LE;
581 944 : case UNGE:
582 944 : return LT;
583 1832159 : case UNEQ:
584 1832159 : return LTGT;
585 :
586 0 : default:
587 0 : gcc_unreachable ();
588 : }
589 : }
590 :
591 : /* Similar, but return the code when two operands of a comparison are swapped.
592 : This IS safe for IEEE floating-point. */
593 :
594 : enum rtx_code
595 8881416 : swap_condition (enum rtx_code code)
596 : {
597 8881416 : switch (code)
598 : {
599 : case EQ:
600 : case NE:
601 : case UNORDERED:
602 : case ORDERED:
603 : case UNEQ:
604 : case LTGT:
605 : return code;
606 :
607 734758 : case GT:
608 734758 : return LT;
609 378479 : case GE:
610 378479 : return LE;
611 213311 : case LT:
612 213311 : return GT;
613 241821 : case LE:
614 241821 : return GE;
615 183874 : case GTU:
616 183874 : return LTU;
617 1247614 : case GEU:
618 1247614 : return LEU;
619 1431631 : case LTU:
620 1431631 : return GTU;
621 114769 : case LEU:
622 114769 : return GEU;
623 14417 : case UNLT:
624 14417 : return UNGT;
625 49681 : case UNLE:
626 49681 : return UNGE;
627 15105 : case UNGT:
628 15105 : return UNLT;
629 20078 : case UNGE:
630 20078 : return UNLE;
631 :
632 0 : default:
633 0 : gcc_unreachable ();
634 : }
635 : }
636 :
637 : /* Given a comparison CODE, return the corresponding unsigned comparison.
638 : If CODE is an equality comparison or already an unsigned comparison,
639 : CODE is returned. */
640 :
641 : enum rtx_code
642 12693370 : unsigned_condition (enum rtx_code code)
643 : {
644 12693370 : switch (code)
645 : {
646 : case EQ:
647 : case NE:
648 : case GTU:
649 : case GEU:
650 : case LTU:
651 : case LEU:
652 : return code;
653 :
654 194411 : case GT:
655 194411 : return GTU;
656 103609 : case GE:
657 103609 : return GEU;
658 101172 : case LT:
659 101172 : return LTU;
660 168898 : case LE:
661 168898 : return LEU;
662 :
663 0 : default:
664 0 : gcc_unreachable ();
665 : }
666 : }
667 :
668 : /* Similarly, return the signed version of a comparison. */
669 :
670 : enum rtx_code
671 7119839 : signed_condition (enum rtx_code code)
672 : {
673 7119839 : switch (code)
674 : {
675 : case EQ:
676 : case NE:
677 : case GT:
678 : case GE:
679 : case LT:
680 : case LE:
681 : return code;
682 :
683 0 : case GTU:
684 0 : return GT;
685 0 : case GEU:
686 0 : return GE;
687 0 : case LTU:
688 0 : return LT;
689 0 : case LEU:
690 0 : return LE;
691 :
692 0 : default:
693 0 : gcc_unreachable ();
694 : }
695 : }
696 :
697 : /* Return true if CODE1 is more strict than CODE2, i.e., if the
698 : truth of CODE1 implies the truth of CODE2. */
699 :
700 : bool
701 47853293 : comparison_dominates_p (enum rtx_code code1, enum rtx_code code2)
702 : {
703 : /* UNKNOWN comparison codes can happen as a result of trying to revert
704 : comparison codes.
705 : They can't match anything, so we have to reject them here. */
706 47853293 : if (code1 == UNKNOWN || code2 == UNKNOWN)
707 : return false;
708 :
709 15311662 : if (code1 == code2)
710 : return true;
711 :
712 8780779 : switch (code1)
713 : {
714 790876 : case UNEQ:
715 790876 : if (code2 == UNLE || code2 == UNGE)
716 : return true;
717 : break;
718 :
719 2080982 : case EQ:
720 2080982 : if (code2 == LE || code2 == LEU || code2 == GE || code2 == GEU
721 : || code2 == ORDERED)
722 442772 : return true;
723 : break;
724 :
725 22001 : case UNLT:
726 22001 : if (code2 == UNLE || code2 == NE)
727 : return true;
728 : break;
729 :
730 172465 : case LT:
731 172465 : if (code2 == LE || code2 == NE || code2 == ORDERED || code2 == LTGT)
732 : return true;
733 : break;
734 :
735 0 : case UNGT:
736 0 : if (code2 == UNGE || code2 == NE)
737 : return true;
738 : break;
739 :
740 454831 : case GT:
741 454831 : if (code2 == GE || code2 == NE || code2 == ORDERED || code2 == LTGT)
742 : return true;
743 : break;
744 :
745 896596 : case GE:
746 896596 : case LE:
747 896596 : if (code2 == ORDERED)
748 1687 : return true;
749 : break;
750 :
751 18063 : case LTGT:
752 18063 : if (code2 == NE || code2 == ORDERED)
753 : return true;
754 : break;
755 :
756 329767 : case LTU:
757 329767 : if (code2 == LEU || code2 == NE)
758 : return true;
759 : break;
760 :
761 183140 : case GTU:
762 183140 : if (code2 == GEU || code2 == NE)
763 : return true;
764 : break;
765 :
766 18663 : case UNORDERED:
767 18663 : if (code2 == NE || code2 == UNEQ || code2 == UNLE || code2 == UNLT
768 8435 : || code2 == UNGE || code2 == UNGT)
769 10228 : return true;
770 : break;
771 :
772 : default:
773 : break;
774 : }
775 :
776 : return false;
777 : }
778 :
779 : /* Return true if INSN is an unconditional jump and nothing else. */
780 :
781 : bool
782 135008144 : simplejump_p (const rtx_insn *insn)
783 : {
784 135008144 : return (JUMP_P (insn)
785 133441893 : && GET_CODE (PATTERN (insn)) == SET
786 128759726 : && GET_CODE (SET_DEST (PATTERN (insn))) == PC
787 263767870 : && GET_CODE (SET_SRC (PATTERN (insn))) == LABEL_REF);
788 : }
789 :
790 : /* Return true if INSN is a (possibly) conditional jump
791 : and nothing more.
792 :
793 : Use of this function is deprecated, since we need to support combined
794 : branch and compare insns. Use any_condjump_p instead whenever possible. */
795 :
796 : bool
797 41095828 : condjump_p (const rtx_insn *insn)
798 : {
799 41095828 : const_rtx x = PATTERN (insn);
800 :
801 41095828 : if (GET_CODE (x) != SET
802 7932494 : || GET_CODE (SET_DEST (x)) != PC)
803 : return false;
804 :
805 7519497 : x = SET_SRC (x);
806 7519497 : if (GET_CODE (x) == LABEL_REF)
807 : return true;
808 : else
809 5190483 : return (GET_CODE (x) == IF_THEN_ELSE
810 5190483 : && ((GET_CODE (XEXP (x, 2)) == PC
811 5188174 : && (GET_CODE (XEXP (x, 1)) == LABEL_REF
812 0 : || ANY_RETURN_P (XEXP (x, 1))))
813 0 : || (GET_CODE (XEXP (x, 1)) == PC
814 0 : && (GET_CODE (XEXP (x, 2)) == LABEL_REF
815 0 : || ANY_RETURN_P (XEXP (x, 2))))));
816 : }
817 :
818 : /* Return true if INSN is a (possibly) conditional jump inside a
819 : PARALLEL.
820 :
821 : Use this function is deprecated, since we need to support combined
822 : branch and compare insns. Use any_condjump_p instead whenever possible. */
823 :
824 : bool
825 1449569 : condjump_in_parallel_p (const rtx_insn *insn)
826 : {
827 1449569 : const_rtx x = PATTERN (insn);
828 :
829 1449569 : if (GET_CODE (x) != PARALLEL)
830 : return false;
831 : else
832 25891 : x = XVECEXP (x, 0, 0);
833 :
834 25891 : if (GET_CODE (x) != SET)
835 : return false;
836 8169 : if (GET_CODE (SET_DEST (x)) != PC)
837 : return false;
838 7765 : if (GET_CODE (SET_SRC (x)) == LABEL_REF)
839 : return true;
840 7765 : if (GET_CODE (SET_SRC (x)) != IF_THEN_ELSE)
841 : return false;
842 74 : if (XEXP (SET_SRC (x), 2) == pc_rtx
843 74 : && (GET_CODE (XEXP (SET_SRC (x), 1)) == LABEL_REF
844 0 : || ANY_RETURN_P (XEXP (SET_SRC (x), 1))))
845 : return true;
846 0 : if (XEXP (SET_SRC (x), 1) == pc_rtx
847 0 : && (GET_CODE (XEXP (SET_SRC (x), 2)) == LABEL_REF
848 0 : || ANY_RETURN_P (XEXP (SET_SRC (x), 2))))
849 0 : return true;
850 : return false;
851 : }
852 :
853 : /* Return set of PC, otherwise NULL. */
854 :
855 : rtx
856 4614851944 : pc_set (const rtx_insn *insn)
857 : {
858 4614851944 : rtx pat;
859 4614851944 : if (!JUMP_P (insn))
860 : return NULL_RTX;
861 2562112376 : pat = PATTERN (insn);
862 :
863 : /* The set is allowed to appear either as the insn pattern or
864 : the first set in a PARALLEL, UNSPEC or UNSPEC_VOLATILE. */
865 2562112376 : switch (GET_CODE (pat))
866 : {
867 6529563 : case PARALLEL:
868 6529563 : case UNSPEC:
869 6529563 : case UNSPEC_VOLATILE:
870 6529563 : pat = XVECEXP (pat, 0, 0);
871 6529563 : break;
872 : default:
873 : break;
874 : }
875 2562112376 : if (GET_CODE (pat) == SET && GET_CODE (SET_DEST (pat)) == PC)
876 2470832910 : return pat;
877 :
878 : return NULL_RTX;
879 : }
880 :
881 : /* Return true when insn is an unconditional direct jump,
882 : possibly bundled inside a PARALLEL, UNSPEC or UNSPEC_VOLATILE.
883 : The instruction may have various other effects so before removing the jump
884 : you must verify onlyjump_p. */
885 :
886 : bool
887 1794620421 : any_uncondjump_p (const rtx_insn *insn)
888 : {
889 1794620421 : const_rtx x = pc_set (insn);
890 1794620421 : if (!x)
891 : return false;
892 898091254 : if (GET_CODE (SET_SRC (x)) != LABEL_REF)
893 : return false;
894 112702773 : if (find_reg_note (insn, REG_NON_LOCAL_GOTO, NULL_RTX))
895 0 : return false;
896 : return true;
897 : }
898 :
899 : /* Return true when insn is a conditional jump. This function works for
900 : instructions containing PC sets in PARALLELs, UNSPECs or UNSPEC_VOLATILEs.
901 : The instruction may have various other effects so before removing the jump
902 : you must verify onlyjump_p.
903 :
904 : Note that unlike condjump_p it returns false for unconditional jumps. */
905 :
906 : bool
907 2694227398 : any_condjump_p (const rtx_insn *insn)
908 : {
909 2694227398 : const_rtx x = pc_set (insn);
910 2694227398 : enum rtx_code a, b;
911 :
912 2694227398 : if (!x)
913 : return false;
914 1446738306 : if (GET_CODE (SET_SRC (x)) != IF_THEN_ELSE)
915 : return false;
916 :
917 1416699469 : a = GET_CODE (XEXP (SET_SRC (x), 1));
918 1416699469 : b = GET_CODE (XEXP (SET_SRC (x), 2));
919 :
920 1416699469 : return ((b == PC && (a == LABEL_REF || a == RETURN || a == SIMPLE_RETURN))
921 1416699469 : || (a == PC
922 0 : && (b == LABEL_REF || b == RETURN || b == SIMPLE_RETURN)));
923 : }
924 :
925 : /* Return the label of a conditional jump. */
926 :
927 : rtx
928 0 : condjump_label (const rtx_insn *insn)
929 : {
930 0 : rtx x = pc_set (insn);
931 :
932 0 : if (!x)
933 : return NULL_RTX;
934 0 : x = SET_SRC (x);
935 0 : if (GET_CODE (x) == LABEL_REF)
936 : return x;
937 0 : if (GET_CODE (x) != IF_THEN_ELSE)
938 : return NULL_RTX;
939 0 : if (XEXP (x, 2) == pc_rtx && GET_CODE (XEXP (x, 1)) == LABEL_REF)
940 : return XEXP (x, 1);
941 0 : if (XEXP (x, 1) == pc_rtx && GET_CODE (XEXP (x, 2)) == LABEL_REF)
942 0 : return XEXP (x, 2);
943 : return NULL_RTX;
944 : }
945 :
946 : /* Return TRUE if INSN is a return jump. */
947 :
948 : bool
949 566371157 : returnjump_p (const rtx_insn *insn)
950 : {
951 566371157 : if (JUMP_P (insn))
952 : {
953 552972158 : subrtx_iterator::array_type array;
954 3608627440 : FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
955 : {
956 3141423385 : const_rtx x = *iter;
957 3141423385 : switch (GET_CODE (x))
958 : {
959 : case RETURN:
960 : case SIMPLE_RETURN:
961 : case EH_RETURN:
962 85768103 : return true;
963 :
964 468023597 : case SET:
965 468023597 : if (SET_IS_RETURN_P (x))
966 : return true;
967 : break;
968 :
969 : default:
970 : break;
971 : }
972 : }
973 552972158 : }
974 : return false;
975 : }
976 :
977 : /* Return true if INSN is a (possibly conditional) return insn. */
978 :
979 : bool
980 184369 : eh_returnjump_p (rtx_insn *insn)
981 : {
982 184369 : if (JUMP_P (insn))
983 : {
984 54872 : subrtx_iterator::array_type array;
985 109713 : FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
986 54872 : if (GET_CODE (*iter) == EH_RETURN)
987 31 : return true;
988 54872 : }
989 : return false;
990 : }
991 :
992 : /* Return true if INSN is a jump that only transfers control and
993 : nothing more. */
994 :
995 : bool
996 460174504 : onlyjump_p (const rtx_insn *insn)
997 : {
998 460174504 : rtx set;
999 :
1000 460174504 : if (!JUMP_P (insn))
1001 : return false;
1002 :
1003 197057204 : set = single_set (insn);
1004 197057204 : if (set == NULL)
1005 : return false;
1006 188834928 : if (GET_CODE (SET_DEST (set)) != PC)
1007 : return false;
1008 188833538 : if (side_effects_p (SET_SRC (set)))
1009 90 : return false;
1010 :
1011 : return true;
1012 : }
1013 :
1014 : /* Return true iff INSN is a jump and its JUMP_LABEL is a label, not
1015 : NULL or a return. */
1016 : bool
1017 28715523 : jump_to_label_p (const rtx_insn *insn)
1018 : {
1019 28715523 : return (JUMP_P (insn)
1020 28715523 : && JUMP_LABEL (insn) != NULL && !ANY_RETURN_P (JUMP_LABEL (insn)));
1021 : }
1022 :
1023 : /* Find all CODE_LABELs referred to in X, and increment their use
1024 : counts. If INSN is a JUMP_INSN and there is at least one
1025 : CODE_LABEL referenced in INSN as a jump target, then store the last
1026 : one in JUMP_LABEL (INSN). For a tablejump, this must be the label
1027 : for the ADDR_VEC. Store any other jump targets as REG_LABEL_TARGET
1028 : notes. If INSN is an INSN or a CALL_INSN or non-target operands of
1029 : a JUMP_INSN, and there is at least one CODE_LABEL referenced in
1030 : INSN, add a REG_LABEL_OPERAND note containing that label to INSN.
1031 : For returnjumps, the JUMP_LABEL will also be set as appropriate.
1032 :
1033 : Note that two labels separated by a loop-beginning note
1034 : must be kept distinct if we have not yet done loop-optimization,
1035 : because the gap between them is where loop-optimize
1036 : will want to move invariant code to. CROSS_JUMP tells us
1037 : that loop-optimization is done with. */
1038 :
1039 : void
1040 324467535 : mark_jump_label (rtx x, rtx_insn *insn, int in_mem)
1041 : {
1042 324467535 : rtx asmop = extract_asm_operands (x);
1043 324467535 : if (asmop)
1044 305178 : mark_jump_label_asm (asmop, insn);
1045 : else
1046 648324714 : mark_jump_label_1 (x, insn, in_mem != 0,
1047 324162357 : (insn != NULL && x == PATTERN (insn) && JUMP_P (insn)));
1048 324467535 : }
1049 :
1050 : /* Worker function for mark_jump_label. IN_MEM is TRUE when X occurs
1051 : within a (MEM ...). IS_TARGET is TRUE when X is to be treated as a
1052 : jump-target; when the JUMP_LABEL field of INSN should be set or a
1053 : REG_LABEL_TARGET note should be added, not a REG_LABEL_OPERAND
1054 : note. */
1055 :
1056 : static void
1057 1627183379 : mark_jump_label_1 (rtx x, rtx_insn *insn, bool in_mem, bool is_target)
1058 : {
1059 1651771540 : RTX_CODE code = GET_CODE (x);
1060 1651771540 : int i;
1061 1651771540 : const char *fmt;
1062 :
1063 1651771540 : switch (code)
1064 : {
1065 : case PC:
1066 : case REG:
1067 : case CLOBBER:
1068 : case CALL:
1069 : return;
1070 :
1071 2772786 : case RETURN:
1072 2772786 : case SIMPLE_RETURN:
1073 2772786 : if (is_target)
1074 : {
1075 2772786 : gcc_assert (JUMP_LABEL (insn) == NULL || JUMP_LABEL (insn) == x);
1076 2772786 : JUMP_LABEL (insn) = x;
1077 : }
1078 : return;
1079 :
1080 : case MEM:
1081 124567751 : in_mem = true;
1082 : break;
1083 :
1084 0 : case SEQUENCE:
1085 0 : {
1086 0 : rtx_sequence *seq = as_a <rtx_sequence *> (x);
1087 0 : for (i = 0; i < seq->len (); i++)
1088 0 : mark_jump_label (PATTERN (seq->insn (i)),
1089 : seq->insn (i), 0);
1090 : }
1091 : return;
1092 :
1093 31727957 : case SYMBOL_REF:
1094 31727957 : if (!in_mem)
1095 : return;
1096 :
1097 : /* If this is a constant-pool reference, see if it is a label. */
1098 17240458 : if (CONSTANT_POOL_ADDRESS_P (x))
1099 3149104 : mark_jump_label_1 (get_pool_constant (x), insn, in_mem, is_target);
1100 : break;
1101 :
1102 : /* Handle operands in the condition of an if-then-else as for a
1103 : non-jump insn. */
1104 25388167 : case IF_THEN_ELSE:
1105 25388167 : if (!is_target)
1106 : break;
1107 24588161 : mark_jump_label_1 (XEXP (x, 0), insn, in_mem, false);
1108 24588161 : mark_jump_label_1 (XEXP (x, 1), insn, in_mem, true);
1109 24588161 : mark_jump_label_1 (XEXP (x, 2), insn, in_mem, true);
1110 24588161 : return;
1111 :
1112 34216852 : case LABEL_REF:
1113 34216852 : {
1114 34216852 : rtx_insn *label = label_ref_label (x);
1115 :
1116 : /* Ignore remaining references to unreachable labels that
1117 : have been deleted. */
1118 34216852 : if (NOTE_P (label)
1119 539 : && NOTE_KIND (label) == NOTE_INSN_DELETED_LABEL)
1120 : break;
1121 :
1122 34216313 : gcc_assert (LABEL_P (label));
1123 :
1124 : /* Ignore references to labels of containing functions. */
1125 34216313 : if (LABEL_REF_NONLOCAL_P (x))
1126 : break;
1127 :
1128 34214805 : set_label_ref_label (x, label);
1129 34214805 : if (! insn || ! insn->deleted ())
1130 34214805 : ++LABEL_NUSES (label);
1131 :
1132 34214805 : if (insn)
1133 : {
1134 33475073 : if (is_target
1135 : /* Do not change a previous setting of JUMP_LABEL. If the
1136 : JUMP_LABEL slot is occupied by a different label,
1137 : create a note for this label. */
1138 33421456 : && (JUMP_LABEL (insn) == NULL || JUMP_LABEL (insn) == label))
1139 33420739 : JUMP_LABEL (insn) = label;
1140 : else
1141 : {
1142 : enum reg_note kind
1143 : = is_target ? REG_LABEL_TARGET : REG_LABEL_OPERAND;
1144 :
1145 : /* Add a REG_LABEL_OPERAND or REG_LABEL_TARGET note
1146 : for LABEL unless there already is one. All uses of
1147 : a label, except for the primary target of a jump,
1148 : must have such a note. */
1149 54334 : if (! find_reg_note (insn, kind, label))
1150 27120 : add_reg_note (insn, kind, label);
1151 : }
1152 : }
1153 : return;
1154 : }
1155 :
1156 : /* Do walk the labels in a vector, but not the first operand of an
1157 : ADDR_DIFF_VEC. Don't set the JUMP_LABEL of a vector. */
1158 33091 : case ADDR_VEC:
1159 33091 : case ADDR_DIFF_VEC:
1160 33091 : if (! insn->deleted ())
1161 : {
1162 33091 : int eltnum = code == ADDR_DIFF_VEC ? 1 : 0;
1163 :
1164 772823 : for (i = 0; i < XVECLEN (x, eltnum); i++)
1165 739732 : mark_jump_label_1 (XVECEXP (x, eltnum, i), NULL, in_mem,
1166 : is_target);
1167 : }
1168 : return;
1169 :
1170 : default:
1171 : break;
1172 : }
1173 :
1174 913496158 : fmt = GET_RTX_FORMAT (code);
1175 :
1176 : /* The primary target of a tablejump is the label of the ADDR_VEC,
1177 : which is canonically mentioned *last* in the insn. To get it
1178 : marked as JUMP_LABEL, we iterate over items in reverse order. */
1179 2469945864 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1180 : {
1181 1556449706 : if (fmt[i] == 'e')
1182 1131358691 : mark_jump_label_1 (XEXP (x, i), insn, in_mem, is_target);
1183 425091015 : else if (fmt[i] == 'E')
1184 : {
1185 54910871 : int j;
1186 :
1187 173296854 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1188 118385983 : mark_jump_label_1 (XVECEXP (x, i, j), insn, in_mem,
1189 : is_target);
1190 : }
1191 : }
1192 : }
1193 :
1194 : /* Worker function for mark_jump_label. Handle asm insns specially.
1195 : In particular, output operands need not be considered so we can
1196 : avoid re-scanning the replicated asm_operand. Also, the asm_labels
1197 : need to be considered targets. */
1198 :
1199 : static void
1200 305178 : mark_jump_label_asm (rtx asmop, rtx_insn *insn)
1201 : {
1202 305178 : int i;
1203 :
1204 513379 : for (i = ASM_OPERANDS_INPUT_LENGTH (asmop) - 1; i >= 0; --i)
1205 208201 : mark_jump_label_1 (ASM_OPERANDS_INPUT (asmop, i), insn, false, false);
1206 :
1207 308165 : for (i = ASM_OPERANDS_LABEL_LENGTH (asmop) - 1; i >= 0; --i)
1208 2987 : mark_jump_label_1 (ASM_OPERANDS_LABEL (asmop, i), insn, false, true);
1209 305178 : }
1210 :
1211 : /* Delete insn INSN from the chain of insns and update label ref counts
1212 : and delete insns now unreachable.
1213 :
1214 : Returns the first insn after INSN that was not deleted.
1215 :
1216 : Usage of this instruction is deprecated. Use delete_insn instead and
1217 : subsequent cfg_cleanup pass to delete unreachable code if needed. */
1218 :
1219 : rtx_insn *
1220 0 : delete_related_insns (rtx uncast_insn)
1221 : {
1222 0 : rtx_insn *insn = as_a <rtx_insn *> (uncast_insn);
1223 0 : bool was_code_label = LABEL_P (insn);
1224 0 : rtx note;
1225 0 : rtx_insn *next = NEXT_INSN (insn), *prev = PREV_INSN (insn);
1226 :
1227 0 : while (next && next->deleted ())
1228 0 : next = NEXT_INSN (next);
1229 :
1230 : /* This insn is already deleted => return first following nondeleted. */
1231 0 : if (insn->deleted ())
1232 : return next;
1233 :
1234 0 : delete_insn (insn);
1235 :
1236 : /* If instruction is followed by a barrier,
1237 : delete the barrier too. */
1238 :
1239 0 : if (next != 0 && BARRIER_P (next))
1240 0 : delete_insn (next);
1241 :
1242 : /* If deleting a jump, decrement the count of the label,
1243 : and delete the label if it is now unused. */
1244 :
1245 0 : if (jump_to_label_p (insn))
1246 : {
1247 0 : rtx lab = JUMP_LABEL (insn);
1248 0 : rtx_jump_table_data *lab_next;
1249 :
1250 0 : if (LABEL_NUSES (lab) == 0)
1251 : /* This can delete NEXT or PREV,
1252 : either directly if NEXT is JUMP_LABEL (INSN),
1253 : or indirectly through more levels of jumps. */
1254 0 : delete_related_insns (lab);
1255 0 : else if (tablejump_p (insn, NULL, &lab_next)
1256 0 : && !JUMP_TABLE_SHARED_P (PATTERN (lab_next)))
1257 : {
1258 : /* If we're deleting the tablejump, delete the dispatch table.
1259 : We may not be able to kill the label immediately preceding
1260 : just yet, as it might be referenced in code leading up to
1261 : the tablejump. A table that other jumps dispatch through as
1262 : well outlives this one. */
1263 0 : delete_related_insns (lab_next);
1264 : }
1265 : }
1266 :
1267 : /* Likewise if we're deleting a dispatch table. */
1268 :
1269 0 : if (rtx_jump_table_data *table = dyn_cast <rtx_jump_table_data *> (insn))
1270 : {
1271 0 : rtvec labels = table->get_labels ();
1272 0 : int i;
1273 0 : int len = GET_NUM_ELEM (labels);
1274 :
1275 0 : for (i = 0; i < len; i++)
1276 0 : if (LABEL_NUSES (label_ref_label (RTVEC_ELT (labels, i))) == 0)
1277 0 : delete_related_insns (label_ref_label (RTVEC_ELT (labels, i)));
1278 0 : while (next && next->deleted ())
1279 0 : next = NEXT_INSN (next);
1280 : return next;
1281 : }
1282 :
1283 : /* Likewise for any JUMP_P / INSN / CALL_INSN with a
1284 : REG_LABEL_OPERAND or REG_LABEL_TARGET note. */
1285 0 : if (INSN_P (insn))
1286 0 : for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1287 0 : if ((REG_NOTE_KIND (note) == REG_LABEL_OPERAND
1288 0 : || REG_NOTE_KIND (note) == REG_LABEL_TARGET)
1289 : /* This could also be a NOTE_INSN_DELETED_LABEL note. */
1290 0 : && LABEL_P (XEXP (note, 0)))
1291 0 : if (LABEL_NUSES (XEXP (note, 0)) == 0)
1292 0 : delete_related_insns (XEXP (note, 0));
1293 :
1294 0 : while (prev && (prev->deleted () || NOTE_P (prev) || DEBUG_INSN_P (prev)))
1295 0 : prev = PREV_INSN (prev);
1296 :
1297 : /* If INSN was a label and a dispatch table follows it,
1298 : delete the dispatch table. The tablejump must have gone already.
1299 : It isn't useful to fall through into a table. */
1300 :
1301 0 : if (was_code_label
1302 0 : && NEXT_INSN (insn) != 0
1303 0 : && JUMP_TABLE_DATA_P (NEXT_INSN (insn)))
1304 0 : next = delete_related_insns (NEXT_INSN (insn));
1305 :
1306 : /* If INSN was a label, delete insns following it if now unreachable. */
1307 :
1308 0 : if (was_code_label && prev && BARRIER_P (prev))
1309 : {
1310 : enum rtx_code code;
1311 0 : while (next)
1312 : {
1313 0 : code = GET_CODE (next);
1314 0 : if (code == NOTE)
1315 0 : next = NEXT_INSN (next);
1316 : /* Keep going past other deleted labels to delete what follows. */
1317 0 : else if (code == CODE_LABEL && next->deleted ())
1318 0 : next = NEXT_INSN (next);
1319 : /* Keep the (use (insn))s created by dbr_schedule, which needs
1320 : them in order to track liveness relative to a previous
1321 : barrier. */
1322 0 : else if (INSN_P (next)
1323 0 : && GET_CODE (PATTERN (next)) == USE
1324 0 : && INSN_P (XEXP (PATTERN (next), 0)))
1325 0 : next = NEXT_INSN (next);
1326 0 : else if (code == BARRIER || INSN_P (next))
1327 : /* Note: if this deletes a jump, it can cause more
1328 : deletion of unreachable code, after a different label.
1329 : As long as the value from this recursive call is correct,
1330 : this invocation functions correctly. */
1331 0 : next = delete_related_insns (next);
1332 : else
1333 : break;
1334 : }
1335 : }
1336 :
1337 : /* I feel a little doubtful about this loop,
1338 : but I see no clean and sure alternative way
1339 : to find the first insn after INSN that is not now deleted.
1340 : I hope this works. */
1341 0 : while (next && next->deleted ())
1342 0 : next = NEXT_INSN (next);
1343 : return next;
1344 : }
1345 :
1346 : /* Delete a range of insns from FROM to TO, inclusive.
1347 : This is for the sake of peephole optimization, so assume
1348 : that whatever these insns do will still be done by a new
1349 : peephole insn that will replace them. */
1350 :
1351 : void
1352 0 : delete_for_peephole (rtx_insn *from, rtx_insn *to)
1353 : {
1354 0 : rtx_insn *insn = from;
1355 :
1356 0 : while (1)
1357 : {
1358 0 : rtx_insn *next = NEXT_INSN (insn);
1359 0 : rtx_insn *prev = PREV_INSN (insn);
1360 :
1361 0 : if (!NOTE_P (insn))
1362 : {
1363 0 : insn->set_deleted();
1364 :
1365 : /* Patch this insn out of the chain. */
1366 : /* We don't do this all at once, because we
1367 : must preserve all NOTEs. */
1368 0 : if (prev)
1369 0 : SET_NEXT_INSN (prev) = next;
1370 :
1371 0 : if (next)
1372 0 : SET_PREV_INSN (next) = prev;
1373 : }
1374 :
1375 0 : if (insn == to)
1376 : break;
1377 : insn = next;
1378 : }
1379 :
1380 : /* Note that if TO is an unconditional jump
1381 : we *do not* delete the BARRIER that follows,
1382 : since the peephole that replaces this sequence
1383 : is also an unconditional jump in that case. */
1384 0 : }
1385 :
1386 : /* A helper function for redirect_exp_1; examines its input X and returns
1387 : either a LABEL_REF around a label, or a RETURN if X was NULL. */
1388 : static rtx
1389 10760545 : redirect_target (rtx x)
1390 : {
1391 10760545 : if (x == NULL_RTX)
1392 0 : return ret_rtx;
1393 10760545 : if (!ANY_RETURN_P (x))
1394 11339469 : return gen_rtx_LABEL_REF (Pmode, x);
1395 : return x;
1396 : }
1397 :
1398 : /* Throughout LOC, redirect OLABEL to NLABEL. Treat null OLABEL or
1399 : NLABEL as a return. Accrue modifications into the change group. */
1400 :
1401 : static void
1402 42635879 : redirect_exp_1 (rtx *loc, rtx olabel, rtx nlabel, rtx_insn *insn)
1403 : {
1404 52952011 : rtx x = *loc;
1405 52952011 : RTX_CODE code = GET_CODE (x);
1406 52952011 : int i;
1407 52952011 : const char *fmt;
1408 :
1409 10760545 : if ((code == LABEL_REF && label_ref_label (x) == olabel)
1410 52952011 : || x == olabel)
1411 : {
1412 10760545 : x = redirect_target (nlabel);
1413 10760545 : if (GET_CODE (x) == LABEL_REF && loc == &PATTERN (insn))
1414 0 : x = gen_rtx_SET (pc_rtx, x);
1415 10760545 : validate_change (insn, loc, x, 1);
1416 10760545 : return;
1417 : }
1418 :
1419 10798657 : if (code == SET && SET_DEST (x) == pc_rtx
1420 10798657 : && ANY_RETURN_P (nlabel)
1421 904438 : && GET_CODE (SET_SRC (x)) == LABEL_REF
1422 42229578 : && label_ref_label (SET_SRC (x)) == olabel)
1423 : {
1424 38112 : validate_change (insn, loc, nlabel, 1);
1425 38112 : return;
1426 : }
1427 :
1428 42153354 : if (code == IF_THEN_ELSE)
1429 : {
1430 : /* Skip the condition of an IF_THEN_ELSE. We only want to
1431 : change jump destinations, not eventual label comparisons. */
1432 10316132 : redirect_exp_1 (&XEXP (x, 1), olabel, nlabel, insn);
1433 10316132 : redirect_exp_1 (&XEXP (x, 2), olabel, nlabel, insn);
1434 10316132 : return;
1435 : }
1436 :
1437 31837222 : fmt = GET_RTX_FORMAT (code);
1438 53358312 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1439 : {
1440 21521090 : if (fmt[i] == 'e')
1441 21521090 : redirect_exp_1 (&XEXP (x, i), olabel, nlabel, insn);
1442 0 : else if (fmt[i] == 'E')
1443 : {
1444 : int j;
1445 0 : for (j = 0; j < XVECLEN (x, i); j++)
1446 0 : redirect_exp_1 (&XVECEXP (x, i, j), olabel, nlabel, insn);
1447 : }
1448 : }
1449 : }
1450 :
1451 : /* Make JUMP go to NLABEL instead of where it jumps now. Accrue
1452 : the modifications into the change group. Return false if we did
1453 : not see how to do that. */
1454 :
1455 : bool
1456 10798657 : redirect_jump_1 (rtx_jump_insn *jump, rtx nlabel)
1457 : {
1458 10798657 : int ochanges = num_validated_changes ();
1459 10798657 : rtx *loc, asmop;
1460 :
1461 10798657 : gcc_assert (nlabel != NULL_RTX);
1462 10798657 : asmop = extract_asm_operands (PATTERN (jump));
1463 10798657 : if (asmop)
1464 : {
1465 0 : if (nlabel == NULL)
1466 : return false;
1467 0 : gcc_assert (ASM_OPERANDS_LABEL_LENGTH (asmop) == 1);
1468 0 : loc = &ASM_OPERANDS_LABEL (asmop, 0);
1469 : }
1470 10798657 : else if (GET_CODE (PATTERN (jump)) == PARALLEL)
1471 728 : loc = &XVECEXP (PATTERN (jump), 0, 0);
1472 : else
1473 10797929 : loc = &PATTERN (jump);
1474 :
1475 10798657 : redirect_exp_1 (loc, JUMP_LABEL (jump), nlabel, jump);
1476 10798657 : return num_validated_changes () > ochanges;
1477 : }
1478 :
1479 : /* Make JUMP go to NLABEL instead of where it jumps now. If the old
1480 : jump target label is unused as a result, it and the code following
1481 : it may be deleted.
1482 :
1483 : Normally, NLABEL will be a label, but it may also be a RETURN rtx;
1484 : in that case we are to turn the jump into a (possibly conditional)
1485 : return insn.
1486 :
1487 : The return value will be true if the change was made, false if it wasn't
1488 : (this can only occur when trying to produce return insns). */
1489 :
1490 : bool
1491 8147893 : redirect_jump (rtx_jump_insn *jump, rtx nlabel, int delete_unused)
1492 : {
1493 8147893 : rtx olabel = jump->jump_label ();
1494 :
1495 8147893 : if (!nlabel)
1496 : {
1497 : /* If there is no label, we are asked to redirect to the EXIT block.
1498 : When before the epilogue is emitted, return/simple_return cannot be
1499 : created so we return false immediately. After the epilogue
1500 : is emitted, we always expect a label, either a non-null label, or a
1501 : return/simple_return RTX. */
1502 :
1503 0 : if (!epilogue_completed)
1504 : return false;
1505 0 : gcc_unreachable ();
1506 : }
1507 :
1508 8147893 : if (nlabel == olabel)
1509 : return true;
1510 :
1511 8147893 : if (! redirect_jump_1 (jump, nlabel) || ! apply_change_group ())
1512 : return false;
1513 :
1514 7381641 : redirect_jump_2 (jump, olabel, nlabel, delete_unused, 0);
1515 7381641 : return true;
1516 : }
1517 :
1518 : /* Fix up JUMP_LABEL and label ref counts after OLABEL has been replaced with
1519 : NLABEL in JUMP.
1520 : If DELETE_UNUSED is positive, delete related insn to OLABEL if its ref
1521 : count has dropped to zero. */
1522 : void
1523 20461763 : redirect_jump_2 (rtx_jump_insn *jump, rtx olabel, rtx nlabel, int delete_unused,
1524 : int invert)
1525 : {
1526 20461763 : rtx note;
1527 :
1528 20461763 : gcc_assert (JUMP_LABEL (jump) == olabel);
1529 :
1530 : /* Negative DELETE_UNUSED used to be used to signalize behavior on
1531 : moving FUNCTION_END note. Just sanity check that no user still worry
1532 : about this. */
1533 20461763 : gcc_assert (delete_unused >= 0);
1534 20461763 : JUMP_LABEL (jump) = nlabel;
1535 20461763 : if (!ANY_RETURN_P (nlabel))
1536 20423651 : ++LABEL_NUSES (nlabel);
1537 :
1538 : /* Update labels in any REG_EQUAL note. */
1539 20461763 : if ((note = find_reg_note (jump, REG_EQUAL, NULL_RTX)) != NULL_RTX)
1540 : {
1541 0 : if (ANY_RETURN_P (nlabel)
1542 0 : || (invert && !invert_exp_1 (XEXP (note, 0), jump)))
1543 0 : remove_note (jump, note);
1544 : else
1545 : {
1546 0 : redirect_exp_1 (&XEXP (note, 0), olabel, nlabel, jump);
1547 0 : confirm_change_group ();
1548 : }
1549 : }
1550 :
1551 : /* Handle the case where we had a conditional crossing jump to a return
1552 : label and are now changing it into a direct conditional return.
1553 : The jump is no longer crossing in that case. */
1554 20461763 : if (ANY_RETURN_P (nlabel))
1555 38112 : set_crossing_jump (jump, false);
1556 :
1557 20461763 : if (!ANY_RETURN_P (olabel)
1558 20461763 : && --LABEL_NUSES (olabel) == 0 && delete_unused > 0
1559 : /* Undefined labels will remain outside the insn stream. */
1560 20461763 : && INSN_UID (olabel))
1561 0 : delete_related_insns (olabel);
1562 20461763 : if (invert)
1563 12956616 : invert_br_probabilities (jump);
1564 20461763 : }
1565 :
1566 : /* Invert the jump condition X contained in jump insn INSN. Accrue the
1567 : modifications into the change group. Return true for success. */
1568 : static bool
1569 12956616 : invert_exp_1 (rtx x, rtx_jump_insn *insn)
1570 : {
1571 12956616 : RTX_CODE code = GET_CODE (x);
1572 :
1573 12956616 : if (code == IF_THEN_ELSE)
1574 : {
1575 12956616 : rtx comp = XEXP (x, 0);
1576 12956616 : rtx tem;
1577 12956616 : enum rtx_code reversed_code;
1578 :
1579 : /* We can do this in two ways: The preferable way, which can only
1580 : be done if this is not an integer comparison, is to reverse
1581 : the comparison code. Otherwise, swap the THEN-part and ELSE-part
1582 : of the IF_THEN_ELSE. If we can't do either, fail. */
1583 :
1584 12956616 : reversed_code = reversed_comparison_code (comp, insn);
1585 :
1586 12956616 : if (reversed_code != UNKNOWN)
1587 : {
1588 25913232 : validate_change (insn, &XEXP (x, 0),
1589 12956616 : gen_rtx_fmt_ee (reversed_code,
1590 : GET_MODE (comp), XEXP (comp, 0),
1591 : XEXP (comp, 1)),
1592 : 1);
1593 12956616 : return true;
1594 : }
1595 :
1596 0 : tem = XEXP (x, 1);
1597 0 : validate_change (insn, &XEXP (x, 1), XEXP (x, 2), 1);
1598 0 : validate_change (insn, &XEXP (x, 2), tem, 1);
1599 0 : return true;
1600 : }
1601 : else
1602 : return false;
1603 : }
1604 :
1605 : /* Invert the condition of the jump JUMP, and make it jump to label
1606 : NLABEL instead of where it jumps now. Accrue changes into the
1607 : change group. Return false if we didn't see how to perform the
1608 : inversion and redirection. */
1609 :
1610 : bool
1611 12956626 : invert_jump_1 (rtx_jump_insn *jump, rtx nlabel)
1612 : {
1613 12956626 : rtx x = pc_set (jump);
1614 12956626 : int ochanges;
1615 12956626 : bool ok;
1616 :
1617 12956626 : ochanges = num_validated_changes ();
1618 12956626 : if (x == NULL)
1619 : return false;
1620 12956616 : ok = invert_exp_1 (SET_SRC (x), jump);
1621 12956616 : gcc_assert (ok);
1622 :
1623 12956616 : if (num_validated_changes () == ochanges)
1624 : return false;
1625 :
1626 : /* redirect_jump_1 will fail of nlabel == olabel, and the current use is
1627 : in Pmode, so checking this is not merely an optimization. */
1628 12956616 : return nlabel == JUMP_LABEL (jump) || redirect_jump_1 (jump, nlabel);
1629 : }
1630 :
1631 : /* Invert the condition of the jump JUMP, and make it jump to label
1632 : NLABEL instead of where it jumps now. Return true if successful. */
1633 :
1634 : bool
1635 12935877 : invert_jump (rtx_jump_insn *jump, rtx nlabel, int delete_unused)
1636 : {
1637 12935877 : rtx olabel = JUMP_LABEL (jump);
1638 :
1639 12935877 : if (invert_jump_1 (jump, nlabel) && apply_change_group ())
1640 : {
1641 12935867 : redirect_jump_2 (jump, olabel, nlabel, delete_unused, 1);
1642 12935867 : return true;
1643 : }
1644 10 : cancel_changes (0);
1645 10 : return false;
1646 : }
1647 :
1648 :
1649 : /* Like rtx_equal_p except that it considers two REGs as equal
1650 : if they renumber to the same value and considers two commutative
1651 : operations to be the same if the order of the operands has been
1652 : reversed. */
1653 :
1654 : bool
1655 104883702 : rtx_renumbered_equal_p (const_rtx x, const_rtx y)
1656 : {
1657 104953499 : int i;
1658 104953499 : const enum rtx_code code = GET_CODE (x);
1659 104953499 : const char *fmt;
1660 :
1661 104953499 : if (x == y)
1662 : return true;
1663 :
1664 78739187 : if ((code == REG || (code == SUBREG && REG_P (SUBREG_REG (x))))
1665 20035895 : && (REG_P (y) || (GET_CODE (y) == SUBREG
1666 194 : && REG_P (SUBREG_REG (y)))))
1667 : {
1668 17153996 : int reg_x = -1, reg_y = -1;
1669 17153996 : poly_int64 byte_x = 0, byte_y = 0;
1670 17153996 : struct subreg_info info;
1671 :
1672 17153996 : if (GET_MODE (x) != GET_MODE (y))
1673 : return false;
1674 :
1675 : /* If we haven't done any renumbering, don't
1676 : make any assumptions. */
1677 14934973 : if (reg_renumber == 0)
1678 0 : return rtx_equal_p (x, y);
1679 :
1680 14934973 : if (code == SUBREG)
1681 : {
1682 0 : reg_x = REGNO (SUBREG_REG (x));
1683 0 : byte_x = SUBREG_BYTE (x);
1684 :
1685 0 : if (reg_renumber[reg_x] >= 0)
1686 : {
1687 0 : subreg_get_info (reg_renumber[reg_x],
1688 0 : GET_MODE (SUBREG_REG (x)), byte_x,
1689 : GET_MODE (x), &info);
1690 0 : if (!info.representable_p)
1691 : return false;
1692 0 : reg_x = info.offset;
1693 0 : byte_x = 0;
1694 : }
1695 : }
1696 : else
1697 : {
1698 14934973 : reg_x = REGNO (x);
1699 14934973 : if (reg_renumber[reg_x] >= 0)
1700 0 : reg_x = reg_renumber[reg_x];
1701 : }
1702 :
1703 14934973 : if (GET_CODE (y) == SUBREG)
1704 : {
1705 0 : reg_y = REGNO (SUBREG_REG (y));
1706 0 : byte_y = SUBREG_BYTE (y);
1707 :
1708 0 : if (reg_renumber[reg_y] >= 0)
1709 : {
1710 0 : subreg_get_info (reg_renumber[reg_y],
1711 0 : GET_MODE (SUBREG_REG (y)), byte_y,
1712 0 : GET_MODE (y), &info);
1713 0 : if (!info.representable_p)
1714 : return false;
1715 0 : reg_y = info.offset;
1716 0 : byte_y = 0;
1717 : }
1718 : }
1719 : else
1720 : {
1721 14934973 : reg_y = REGNO (y);
1722 14934973 : if (reg_renumber[reg_y] >= 0)
1723 0 : reg_y = reg_renumber[reg_y];
1724 : }
1725 :
1726 14934973 : return reg_x >= 0 && reg_x == reg_y && known_eq (byte_x, byte_y);
1727 : }
1728 :
1729 : /* Now we have disposed of all the cases
1730 : in which different rtx codes can match. */
1731 61585191 : if (code != GET_CODE (y))
1732 : return false;
1733 :
1734 53727685 : switch (code)
1735 : {
1736 : case PC:
1737 : case ADDR_VEC:
1738 : case ADDR_DIFF_VEC:
1739 : CASE_CONST_UNIQUE:
1740 : return false;
1741 :
1742 : case CONST_VECTOR:
1743 : if (!same_vector_encodings_p (x, y))
1744 : return false;
1745 : break;
1746 :
1747 783 : case LABEL_REF:
1748 : /* We can't assume nonlocal labels have their following insns yet. */
1749 783 : if (LABEL_REF_NONLOCAL_P (x) || LABEL_REF_NONLOCAL_P (y))
1750 0 : return label_ref_label (x) == label_ref_label (y);
1751 :
1752 : /* Two label-refs are equivalent if they point at labels
1753 : in the same position in the instruction stream. */
1754 : else
1755 : {
1756 783 : rtx_insn *xi = next_nonnote_nondebug_insn (label_ref_label (x));
1757 783 : rtx_insn *yi = next_nonnote_nondebug_insn (label_ref_label (y));
1758 1566 : while (xi && LABEL_P (xi))
1759 0 : xi = next_nonnote_nondebug_insn (xi);
1760 783 : while (yi && LABEL_P (yi))
1761 0 : yi = next_nonnote_nondebug_insn (yi);
1762 783 : return xi == yi;
1763 : }
1764 :
1765 3624401 : case SYMBOL_REF:
1766 3624401 : return XSTR (x, 0) == XSTR (y, 0);
1767 :
1768 : case CODE_LABEL:
1769 : /* If we didn't match EQ equality above, they aren't the same. */
1770 : return false;
1771 :
1772 : default:
1773 : break;
1774 : }
1775 :
1776 : /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
1777 :
1778 46106676 : if (GET_MODE (x) != GET_MODE (y))
1779 : return false;
1780 :
1781 : /* MEMs referring to different address space are not equivalent. */
1782 57797021 : if (code == MEM && MEM_ADDR_SPACE (x) != MEM_ADDR_SPACE (y))
1783 : return false;
1784 :
1785 : /* For commutative operations, the RTX match if the operand match in any
1786 : order. Also handle the simple binary and unary cases without a loop. */
1787 45394991 : if (targetm.commutative_p (x, UNKNOWN))
1788 3700299 : return ((rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 0))
1789 3280819 : && rtx_renumbered_equal_p (XEXP (x, 1), XEXP (y, 1)))
1790 4642638 : || (rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 1))
1791 11466 : && rtx_renumbered_equal_p (XEXP (x, 1), XEXP (y, 0))));
1792 41694692 : else if (NON_COMMUTATIVE_P (x))
1793 602954 : return (rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 0))
1794 602954 : && rtx_renumbered_equal_p (XEXP (x, 1), XEXP (y, 1)));
1795 41091738 : else if (UNARY_P (x))
1796 69797 : return rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 0));
1797 :
1798 : /* Compare the elements. If any pair of corresponding elements
1799 : fail to match, return false for the whole things. */
1800 :
1801 41021941 : fmt = GET_RTX_FORMAT (code);
1802 89897576 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1803 : {
1804 67259341 : int j;
1805 67259341 : switch (fmt[i])
1806 : {
1807 0 : case 'w':
1808 0 : if (XWINT (x, i) != XWINT (y, i))
1809 : return false;
1810 : break;
1811 :
1812 82492 : case 'i':
1813 82492 : if (XINT (x, i) != XINT (y, i))
1814 : return false;
1815 : break;
1816 :
1817 6163 : case 'L':
1818 6163 : if (XLOC (x, i) != XLOC (y, i))
1819 : {
1820 6137 : if (((code == ASM_OPERANDS && i == 6)
1821 4049 : || (code == ASM_INPUT && i == 1)))
1822 : break;
1823 : return false;
1824 : }
1825 : break;
1826 :
1827 905 : case 'p':
1828 905 : if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y)))
1829 : return false;
1830 : break;
1831 :
1832 0 : case 't':
1833 0 : if (XTREE (x, i) != XTREE (y, i))
1834 : return false;
1835 : break;
1836 :
1837 6461 : case 's':
1838 6461 : if (strcmp (XSTR (x, i), XSTR (y, i)))
1839 : return false;
1840 : break;
1841 :
1842 54174213 : case 'e':
1843 54174213 : if (! rtx_renumbered_equal_p (XEXP (x, i), XEXP (y, i)))
1844 : return false;
1845 : break;
1846 :
1847 0 : case 'u':
1848 0 : if (XEXP (x, i) != XEXP (y, i))
1849 : return false;
1850 : /* Fall through. */
1851 : case '0':
1852 : break;
1853 :
1854 766399 : case 'E':
1855 766399 : if (XVECLEN (x, i) != XVECLEN (y, i))
1856 : return false;
1857 1869491 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1858 1459707 : if (!rtx_renumbered_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j)))
1859 : return false;
1860 : break;
1861 :
1862 0 : default:
1863 0 : gcc_unreachable ();
1864 : }
1865 : }
1866 : return true;
1867 : }
1868 :
1869 : /* If X is a hard register or equivalent to one or a subregister of one,
1870 : return the hard register number. If X is a pseudo register that was not
1871 : assigned a hard register, return the pseudo register number. Otherwise,
1872 : return -1. Any rtx is valid for X. */
1873 :
1874 : int
1875 413376817 : true_regnum (const_rtx x)
1876 : {
1877 413376817 : if (REG_P (x))
1878 : {
1879 230237034 : if (REGNO (x) >= FIRST_PSEUDO_REGISTER
1880 230237034 : && (lra_in_progress || reg_renumber[REGNO (x)] >= 0))
1881 6368 : return reg_renumber[REGNO (x)];
1882 230230666 : return REGNO (x);
1883 : }
1884 183139783 : if (GET_CODE (x) == SUBREG)
1885 : {
1886 5406 : int base = true_regnum (SUBREG_REG (x));
1887 5406 : if (base >= 0
1888 5406 : && base < FIRST_PSEUDO_REGISTER)
1889 : {
1890 4867 : struct subreg_info info;
1891 :
1892 4867 : subreg_get_info (lra_in_progress
1893 4860 : ? (unsigned) base : REGNO (SUBREG_REG (x)),
1894 4867 : GET_MODE (SUBREG_REG (x)),
1895 4867 : SUBREG_BYTE (x), GET_MODE (x), &info);
1896 :
1897 4867 : if (info.representable_p)
1898 4867 : return base + info.offset;
1899 : }
1900 : }
1901 : return -1;
1902 : }
1903 :
1904 : /* Return regno of the register REG and handle subregs too. */
1905 : unsigned int
1906 15305689 : reg_or_subregno (const_rtx reg)
1907 : {
1908 15305689 : if (GET_CODE (reg) == SUBREG)
1909 739592 : reg = SUBREG_REG (reg);
1910 15305689 : gcc_assert (REG_P (reg));
1911 15305689 : return REGNO (reg);
1912 : }
|