]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cfgcleanup.c
Remove global call sets: cfgcleanup.c
[thirdparty/gcc.git] / gcc / cfgcleanup.c
CommitLineData
402209ff 1/* Control flow optimization code for GNU compiler.
a5544970 2 Copyright (C) 1987-2019 Free Software Foundation, Inc.
402209ff
JH
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
9dcd6f09 8Software Foundation; either version 3, or (at your option) any later
402209ff
JH
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
402209ff 19
1ea7e6ad 20/* This file contains optimizer of the control flow. The main entry point is
402209ff
JH
21 cleanup_cfg. Following optimizations are performed:
22
23 - Unreachable blocks removal
d1a6adeb 24 - Edge forwarding (edge to the forwarder block is forwarded to its
eaec9b3d 25 successor. Simplification of the branch instruction is performed by
402209ff 26 underlying infrastructure so branch can be converted to simplejump or
f5143c46 27 eliminated).
402209ff
JH
28 - Cross jumping (tail merging)
29 - Conditional jump-around-simplejump simplification
30 - Basic block merging. */
31
32#include "config.h"
33#include "system.h"
4977bab6 34#include "coretypes.h"
c7131fb2 35#include "backend.h"
957060b5 36#include "target.h"
402209ff 37#include "rtl.h"
957060b5
AM
38#include "tree.h"
39#include "cfghooks.h"
c7131fb2 40#include "df.h"
4d0cdd0c 41#include "memmodel.h"
957060b5 42#include "tm_p.h"
402209ff 43#include "insn-config.h"
957060b5 44#include "emit-rtl.h"
8ecba28a 45#include "cselib.h"
5f24e0dc 46#include "params.h"
ef330312
PB
47#include "tree-pass.h"
48#include "cfgloop.h"
60393bbc
AM
49#include "cfgrtl.h"
50#include "cfganal.h"
51#include "cfgbuild.h"
52#include "cfgcleanup.h"
c1e3e2d9 53#include "dce.h"
7d817ebc 54#include "dbgcnt.h"
a2250fe9 55#include "rtl-iter.h"
4b1a1d98 56#include "regs.h"
5a5a3bc5 57#include "function-abi.h"
402209ff 58
2dd2d53e 59#define FORWARDER_BLOCK_P(BB) ((BB)->flags & BB_FORWARDER_BLOCK)
c22cacf3 60
7cf240d5
JH
61/* Set to true when we are running first pass of try_optimize_cfg loop. */
62static bool first_pass;
c1e3e2d9 63
073a8998 64/* Set to true if crossjumps occurred in the latest run of try_optimize_cfg. */
bd2c6270 65static bool crossjumps_occurred;
c1e3e2d9 66
4ec5d4f5
BS
67/* Set to true if we couldn't run an optimization due to stale liveness
68 information; we should run df_analyze to enable more opportunities. */
69static bool block_was_dirty;
70
bf22920b 71static bool try_crossjump_to_edge (int, edge, edge, enum replace_direction);
d329e058 72static bool try_crossjump_bb (int, basic_block);
c2fc5456 73static bool outgoing_edges_match (int, basic_block, basic_block);
da5477a9 74static enum replace_direction old_insns_match_p (int, rtx_insn *, rtx_insn *);
d329e058 75
d329e058
AJ
76static void merge_blocks_move_predecessor_nojumps (basic_block, basic_block);
77static void merge_blocks_move_successor_nojumps (basic_block, basic_block);
d329e058
AJ
78static bool try_optimize_cfg (int);
79static bool try_simplify_condjump (basic_block);
80static bool try_forward_edges (int, basic_block);
6fb5fa3c 81static edge thread_jump (edge, basic_block);
d329e058
AJ
82static bool mark_effect (rtx, bitmap);
83static void notice_new_block (basic_block);
84static void update_forwarder_flag (basic_block);
c2fc5456 85static void merge_memattrs (rtx, rtx);
635559ab
JH
86\f
87/* Set flags for newly created block. */
88
89static void
d329e058 90notice_new_block (basic_block bb)
635559ab
JH
91{
92 if (!bb)
93 return;
5f0d2358 94
635559ab 95 if (forwarder_block_p (bb))
2dd2d53e 96 bb->flags |= BB_FORWARDER_BLOCK;
635559ab
JH
97}
98
99/* Recompute forwarder flag after block has been modified. */
100
101static void
d329e058 102update_forwarder_flag (basic_block bb)
635559ab
JH
103{
104 if (forwarder_block_p (bb))
2dd2d53e 105 bb->flags |= BB_FORWARDER_BLOCK;
635559ab 106 else
2dd2d53e 107 bb->flags &= ~BB_FORWARDER_BLOCK;
635559ab 108}
402209ff
JH
109\f
110/* Simplify a conditional jump around an unconditional jump.
111 Return true if something changed. */
112
113static bool
d329e058 114try_simplify_condjump (basic_block cbranch_block)
402209ff
JH
115{
116 basic_block jump_block, jump_dest_block, cbranch_dest_block;
117 edge cbranch_jump_edge, cbranch_fallthru_edge;
da5477a9 118 rtx_insn *cbranch_insn;
402209ff
JH
119
120 /* Verify that there are exactly two successors. */
628f6a4e 121 if (EDGE_COUNT (cbranch_block->succs) != 2)
402209ff
JH
122 return false;
123
124 /* Verify that we've got a normal conditional branch at the end
125 of the block. */
a813c111 126 cbranch_insn = BB_END (cbranch_block);
402209ff
JH
127 if (!any_condjump_p (cbranch_insn))
128 return false;
129
130 cbranch_fallthru_edge = FALLTHRU_EDGE (cbranch_block);
131 cbranch_jump_edge = BRANCH_EDGE (cbranch_block);
132
133 /* The next block must not have multiple predecessors, must not
134 be the last block in the function, and must contain just the
135 unconditional jump. */
136 jump_block = cbranch_fallthru_edge->dest;
c5cbcccf 137 if (!single_pred_p (jump_block)
fefa31b5 138 || jump_block->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
635559ab 139 || !FORWARDER_BLOCK_P (jump_block))
402209ff 140 return false;
c5cbcccf 141 jump_dest_block = single_succ (jump_block);
402209ff 142
750054a2
CT
143 /* If we are partitioning hot/cold basic blocks, we don't want to
144 mess up unconditional or indirect jumps that cross between hot
c22cacf3 145 and cold sections.
8e8d5162
CT
146
147 Basic block partitioning may result in some jumps that appear to
c22cacf3
MS
148 be optimizable (or blocks that appear to be mergeable), but which really
149 must be left untouched (they are required to make it safely across
150 partition boundaries). See the comments at the top of
8e8d5162 151 bb-reorder.c:partition_hot_cold_basic_blocks for complete details. */
750054a2 152
87c8b4be
CT
153 if (BB_PARTITION (jump_block) != BB_PARTITION (jump_dest_block)
154 || (cbranch_jump_edge->flags & EDGE_CROSSING))
750054a2
CT
155 return false;
156
402209ff
JH
157 /* The conditional branch must target the block after the
158 unconditional branch. */
159 cbranch_dest_block = cbranch_jump_edge->dest;
160
fefa31b5 161 if (cbranch_dest_block == EXIT_BLOCK_PTR_FOR_FN (cfun)
1a8fb012 162 || jump_dest_block == EXIT_BLOCK_PTR_FOR_FN (cfun)
2f52c531 163 || !can_fallthru (jump_block, cbranch_dest_block))
402209ff
JH
164 return false;
165
ca6c03ca 166 /* Invert the conditional branch. */
1476d1bd
MM
167 if (!invert_jump (as_a <rtx_jump_insn *> (cbranch_insn),
168 block_label (jump_dest_block), 0))
ca6c03ca 169 return false;
402209ff 170
c263766c
RH
171 if (dump_file)
172 fprintf (dump_file, "Simplifying condjump %i around jump %i\n",
a813c111 173 INSN_UID (cbranch_insn), INSN_UID (BB_END (jump_block)));
402209ff
JH
174
175 /* Success. Update the CFG to match. Note that after this point
176 the edge variable names appear backwards; the redirection is done
177 this way to preserve edge profile data. */
178 cbranch_jump_edge = redirect_edge_succ_nodup (cbranch_jump_edge,
179 cbranch_dest_block);
180 cbranch_fallthru_edge = redirect_edge_succ_nodup (cbranch_fallthru_edge,
181 jump_dest_block);
182 cbranch_jump_edge->flags |= EDGE_FALLTHRU;
183 cbranch_fallthru_edge->flags &= ~EDGE_FALLTHRU;
b446e5a2 184 update_br_prob_note (cbranch_block);
402209ff
JH
185
186 /* Delete the block with the unconditional jump, and clean up the mess. */
f470c378
ZD
187 delete_basic_block (jump_block);
188 tidy_fallthru_edge (cbranch_jump_edge);
261139ce 189 update_forwarder_flag (cbranch_block);
402209ff
JH
190
191 return true;
192}
193\f
8ecba28a
JH
194/* Attempt to prove that operation is NOOP using CSElib or mark the effect
195 on register. Used by jump threading. */
5f0d2358 196
8ecba28a 197static bool
d329e058 198mark_effect (rtx exp, regset nonequal)
8ecba28a 199{
9f16e871 200 rtx dest;
8ecba28a
JH
201 switch (GET_CODE (exp))
202 {
203 /* In case we do clobber the register, mark it as equal, as we know the
c22cacf3 204 value is dead so it don't have to match. */
f87c27b4 205 case CLOBBER:
07a737f3
RS
206 dest = XEXP (exp, 0);
207 if (REG_P (dest))
208 bitmap_clear_range (nonequal, REGNO (dest), REG_NREGS (dest));
f87c27b4 209 return false;
5f0d2358 210
f87c27b4
KH
211 case SET:
212 if (rtx_equal_for_cselib_p (SET_DEST (exp), SET_SRC (exp)))
8ecba28a 213 return false;
f87c27b4
KH
214 dest = SET_DEST (exp);
215 if (dest == pc_rtx)
8ecba28a 216 return false;
f87c27b4
KH
217 if (!REG_P (dest))
218 return true;
07a737f3 219 bitmap_set_range (nonequal, REGNO (dest), REG_NREGS (dest));
f87c27b4
KH
220 return false;
221
222 default:
223 return false;
8ecba28a
JH
224 }
225}
fe477d8b 226
a2250fe9
RS
227/* Return true if X contains a register in NONEQUAL. */
228static bool
229mentions_nonequal_regs (const_rtx x, regset nonequal)
fe477d8b 230{
a2250fe9
RS
231 subrtx_iterator::array_type array;
232 FOR_EACH_SUBRTX (iter, array, x, NONCONST)
fe477d8b 233 {
a2250fe9
RS
234 const_rtx x = *iter;
235 if (REG_P (x))
fe477d8b 236 {
53d1bae9
RS
237 unsigned int end_regno = END_REGNO (x);
238 for (unsigned int regno = REGNO (x); regno < end_regno; ++regno)
239 if (REGNO_REG_SET_P (nonequal, regno))
240 return true;
fe477d8b
JH
241 }
242 }
a2250fe9 243 return false;
fe477d8b 244}
a2250fe9 245
8ecba28a 246/* Attempt to prove that the basic block B will have no side effects and
95bd1dd7 247 always continues in the same edge if reached via E. Return the edge
8ecba28a
JH
248 if exist, NULL otherwise. */
249
250static edge
6fb5fa3c 251thread_jump (edge e, basic_block b)
8ecba28a 252{
da5477a9
DM
253 rtx set1, set2, cond1, cond2;
254 rtx_insn *insn;
8ecba28a
JH
255 enum rtx_code code1, code2, reversed_code2;
256 bool reverse1 = false;
3cd8c58a 257 unsigned i;
8ecba28a
JH
258 regset nonequal;
259 bool failed = false;
a2041967 260 reg_set_iterator rsi;
8ecba28a 261
2dd2d53e 262 if (b->flags & BB_NONTHREADABLE_BLOCK)
1540f9eb
JH
263 return NULL;
264
8ecba28a
JH
265 /* At the moment, we do handle only conditional jumps, but later we may
266 want to extend this code to tablejumps and others. */
628f6a4e 267 if (EDGE_COUNT (e->src->succs) != 2)
8ecba28a 268 return NULL;
628f6a4e 269 if (EDGE_COUNT (b->succs) != 2)
1540f9eb 270 {
2dd2d53e 271 b->flags |= BB_NONTHREADABLE_BLOCK;
1540f9eb
JH
272 return NULL;
273 }
8ecba28a
JH
274
275 /* Second branch must end with onlyjump, as we will eliminate the jump. */
a813c111 276 if (!any_condjump_p (BB_END (e->src)))
8ecba28a 277 return NULL;
f87c27b4 278
a813c111 279 if (!any_condjump_p (BB_END (b)) || !onlyjump_p (BB_END (b)))
1540f9eb 280 {
2dd2d53e 281 b->flags |= BB_NONTHREADABLE_BLOCK;
1540f9eb
JH
282 return NULL;
283 }
8ecba28a 284
a813c111
SB
285 set1 = pc_set (BB_END (e->src));
286 set2 = pc_set (BB_END (b));
8ecba28a 287 if (((e->flags & EDGE_FALLTHRU) != 0)
68f3f6f1 288 != (XEXP (SET_SRC (set1), 1) == pc_rtx))
8ecba28a
JH
289 reverse1 = true;
290
291 cond1 = XEXP (SET_SRC (set1), 0);
292 cond2 = XEXP (SET_SRC (set2), 0);
293 if (reverse1)
a813c111 294 code1 = reversed_comparison_code (cond1, BB_END (e->src));
8ecba28a
JH
295 else
296 code1 = GET_CODE (cond1);
297
298 code2 = GET_CODE (cond2);
a813c111 299 reversed_code2 = reversed_comparison_code (cond2, BB_END (b));
8ecba28a
JH
300
301 if (!comparison_dominates_p (code1, code2)
302 && !comparison_dominates_p (code1, reversed_code2))
303 return NULL;
304
305 /* Ensure that the comparison operators are equivalent.
95bd1dd7 306 ??? This is far too pessimistic. We should allow swapped operands,
8ecba28a
JH
307 different CCmodes, or for example comparisons for interval, that
308 dominate even when operands are not equivalent. */
309 if (!rtx_equal_p (XEXP (cond1, 0), XEXP (cond2, 0))
310 || !rtx_equal_p (XEXP (cond1, 1), XEXP (cond2, 1)))
311 return NULL;
312
23c64481
JJ
313 /* Punt if BB_END (e->src) is doloop-like conditional jump that modifies
314 the registers used in cond1. */
315 if (modified_in_p (cond1, BB_END (e->src)))
316 return NULL;
317
8ecba28a
JH
318 /* Short circuit cases where block B contains some side effects, as we can't
319 safely bypass it. */
a813c111 320 for (insn = NEXT_INSN (BB_HEAD (b)); insn != NEXT_INSN (BB_END (b));
8ecba28a
JH
321 insn = NEXT_INSN (insn))
322 if (INSN_P (insn) && side_effects_p (PATTERN (insn)))
1540f9eb 323 {
2dd2d53e 324 b->flags |= BB_NONTHREADABLE_BLOCK;
1540f9eb
JH
325 return NULL;
326 }
8ecba28a 327
457eeaae 328 cselib_init (0);
8ecba28a
JH
329
330 /* First process all values computed in the source basic block. */
3cd8c58a
NS
331 for (insn = NEXT_INSN (BB_HEAD (e->src));
332 insn != NEXT_INSN (BB_END (e->src));
8ecba28a
JH
333 insn = NEXT_INSN (insn))
334 if (INSN_P (insn))
335 cselib_process_insn (insn);
336
8bdbfff5 337 nonequal = BITMAP_ALLOC (NULL);
8ecba28a 338 CLEAR_REG_SET (nonequal);
5f0d2358 339
8ecba28a
JH
340 /* Now assume that we've continued by the edge E to B and continue
341 processing as if it were same basic block.
8ecba28a 342 Our goal is to prove that whole block is an NOOP. */
5f0d2358 343
3cd8c58a
NS
344 for (insn = NEXT_INSN (BB_HEAD (b));
345 insn != NEXT_INSN (BB_END (b)) && !failed;
8ecba28a 346 insn = NEXT_INSN (insn))
f87c27b4 347 {
becba8a7
JJ
348 /* cond2 must not mention any register that is not equal to the
349 former block. Check this before processing that instruction,
350 as BB_END (b) could contain also clobbers. */
351 if (insn == BB_END (b)
352 && mentions_nonequal_regs (cond2, nonequal))
353 goto failed_exit;
354
f87c27b4
KH
355 if (INSN_P (insn))
356 {
357 rtx pat = PATTERN (insn);
358
359 if (GET_CODE (pat) == PARALLEL)
360 {
3cd8c58a 361 for (i = 0; i < (unsigned)XVECLEN (pat, 0); i++)
f87c27b4
KH
362 failed |= mark_effect (XVECEXP (pat, 0, i), nonequal);
363 }
364 else
365 failed |= mark_effect (pat, nonequal);
366 }
5f0d2358 367
f87c27b4
KH
368 cselib_process_insn (insn);
369 }
8ecba28a
JH
370
371 /* Later we should clear nonequal of dead registers. So far we don't
372 have life information in cfg_cleanup. */
373 if (failed)
1540f9eb 374 {
2dd2d53e 375 b->flags |= BB_NONTHREADABLE_BLOCK;
1540f9eb
JH
376 goto failed_exit;
377 }
8ecba28a 378
a2041967
KH
379 EXECUTE_IF_SET_IN_REG_SET (nonequal, 0, i, rsi)
380 goto failed_exit;
8ecba28a 381
8bdbfff5 382 BITMAP_FREE (nonequal);
8ecba28a
JH
383 cselib_finish ();
384 if ((comparison_dominates_p (code1, code2) != 0)
4deaa2f8 385 != (XEXP (SET_SRC (set2), 1) == pc_rtx))
8ecba28a
JH
386 return BRANCH_EDGE (b);
387 else
388 return FALLTHRU_EDGE (b);
389
390failed_exit:
8bdbfff5 391 BITMAP_FREE (nonequal);
8ecba28a
JH
392 cselib_finish ();
393 return NULL;
394}
395\f
402209ff 396/* Attempt to forward edges leaving basic block B.
eaec9b3d 397 Return true if successful. */
402209ff
JH
398
399static bool
d329e058 400try_forward_edges (int mode, basic_block b)
402209ff
JH
401{
402 bool changed = false;
628f6a4e
BE
403 edge_iterator ei;
404 edge e, *threaded_edges = NULL;
402209ff 405
628f6a4e 406 for (ei = ei_start (b->succs); (e = ei_safe_edge (ei)); )
402209ff
JH
407 {
408 basic_block target, first;
8a829274
EB
409 location_t goto_locus;
410 int counter;
8ecba28a 411 bool threaded = false;
bcb3bc6d 412 int nthreaded_edges = 0;
4ec5d4f5 413 bool may_thread = first_pass || (b->flags & BB_MODIFIED) != 0;
687d5dfe 414 bool new_target_threaded = false;
402209ff 415
402209ff
JH
416 /* Skip complex edges because we don't know how to update them.
417
c22cacf3
MS
418 Still handle fallthru edges, as we can succeed to forward fallthru
419 edge to the same place as the branch edge of conditional branch
420 and turn conditional branch to an unconditional branch. */
402209ff 421 if (e->flags & EDGE_COMPLEX)
628f6a4e
BE
422 {
423 ei_next (&ei);
424 continue;
425 }
402209ff
JH
426
427 target = first = e->dest;
24bd1a0b 428 counter = NUM_FIXED_BLOCKS;
7241571e 429 goto_locus = e->goto_locus;
402209ff 430
0cae8d31 431 while (counter < n_basic_blocks_for_fn (cfun))
402209ff 432 {
8ecba28a 433 basic_block new_target = NULL;
4ec5d4f5 434 may_thread |= (target->flags & BB_MODIFIED) != 0;
8ecba28a
JH
435
436 if (FORWARDER_BLOCK_P (target)
fefa31b5 437 && single_succ (target) != EXIT_BLOCK_PTR_FOR_FN (cfun))
8ecba28a
JH
438 {
439 /* Bypass trivial infinite loops. */
c5cbcccf
ZD
440 new_target = single_succ (target);
441 if (target == new_target)
0cae8d31 442 counter = n_basic_blocks_for_fn (cfun);
7241571e
JJ
443 else if (!optimize)
444 {
445 /* When not optimizing, ensure that edges or forwarder
446 blocks with different locus are not optimized out. */
8a829274
EB
447 location_t new_locus = single_succ_edge (target)->goto_locus;
448 location_t locus = goto_locus;
7241571e 449
ffa4602f
EB
450 if (LOCATION_LOCUS (new_locus) != UNKNOWN_LOCATION
451 && LOCATION_LOCUS (locus) != UNKNOWN_LOCATION
5368224f 452 && new_locus != locus)
50a36e42
EB
453 new_target = NULL;
454 else
7241571e 455 {
ffa4602f 456 if (LOCATION_LOCUS (new_locus) != UNKNOWN_LOCATION)
50a36e42 457 locus = new_locus;
7241571e 458
da5477a9 459 rtx_insn *last = BB_END (target);
11321111
AO
460 if (DEBUG_INSN_P (last))
461 last = prev_nondebug_insn (last);
ffa4602f
EB
462 if (last && INSN_P (last))
463 new_locus = INSN_LOCATION (last);
464 else
465 new_locus = UNKNOWN_LOCATION;
11321111 466
ffa4602f
EB
467 if (LOCATION_LOCUS (new_locus) != UNKNOWN_LOCATION
468 && LOCATION_LOCUS (locus) != UNKNOWN_LOCATION
5368224f 469 && new_locus != locus)
50a36e42
EB
470 new_target = NULL;
471 else
472 {
ffa4602f 473 if (LOCATION_LOCUS (new_locus) != UNKNOWN_LOCATION)
50a36e42
EB
474 locus = new_locus;
475
476 goto_locus = locus;
477 }
7241571e
JJ
478 }
479 }
8ecba28a 480 }
5f0d2358 481
8ecba28a
JH
482 /* Allow to thread only over one edge at time to simplify updating
483 of probabilities. */
7cf240d5 484 else if ((mode & CLEANUP_THREADING) && may_thread)
8ecba28a 485 {
6fb5fa3c 486 edge t = thread_jump (e, target);
1c570418 487 if (t)
8ecba28a 488 {
bcb3bc6d 489 if (!threaded_edges)
0cae8d31
DM
490 threaded_edges = XNEWVEC (edge,
491 n_basic_blocks_for_fn (cfun));
3b3b1e32
RH
492 else
493 {
494 int i;
495
496 /* Detect an infinite loop across blocks not
497 including the start block. */
498 for (i = 0; i < nthreaded_edges; ++i)
499 if (threaded_edges[i] == t)
500 break;
501 if (i < nthreaded_edges)
b90e45ae 502 {
0cae8d31 503 counter = n_basic_blocks_for_fn (cfun);
b90e45ae
JH
504 break;
505 }
3b3b1e32
RH
506 }
507
508 /* Detect an infinite loop across the start block. */
509 if (t->dest == b)
510 break;
511
0cae8d31
DM
512 gcc_assert (nthreaded_edges
513 < (n_basic_blocks_for_fn (cfun)
514 - NUM_FIXED_BLOCKS));
1c570418 515 threaded_edges[nthreaded_edges++] = t;
3b3b1e32
RH
516
517 new_target = t->dest;
518 new_target_threaded = true;
8ecba28a
JH
519 }
520 }
5f0d2358 521
8ecba28a
JH
522 if (!new_target)
523 break;
402209ff 524
8ecba28a 525 counter++;
687d5dfe
JH
526 /* Do not turn non-crossing jump to crossing. Depending on target
527 it may require different instruction pattern. */
528 if ((e->flags & EDGE_CROSSING)
529 || BB_PARTITION (first) == BB_PARTITION (new_target))
530 {
531 target = new_target;
532 threaded |= new_target_threaded;
533 }
f87c27b4 534 }
402209ff 535
0cae8d31 536 if (counter >= n_basic_blocks_for_fn (cfun))
402209ff 537 {
c263766c
RH
538 if (dump_file)
539 fprintf (dump_file, "Infinite loop in BB %i.\n",
0b17ab2f 540 target->index);
402209ff
JH
541 }
542 else if (target == first)
543 ; /* We didn't do anything. */
544 else
545 {
546 /* Save the values now, as the edge may get removed. */
ef30ab83 547 profile_count edge_count = e->count ();
1c570418 548 int n = 0;
402209ff 549
7241571e
JJ
550 e->goto_locus = goto_locus;
551
6ee3c8e4 552 /* Don't force if target is exit block. */
fefa31b5 553 if (threaded && target != EXIT_BLOCK_PTR_FOR_FN (cfun))
402209ff 554 {
8ecba28a 555 notice_new_block (redirect_edge_and_branch_force (e, target));
c263766c
RH
556 if (dump_file)
557 fprintf (dump_file, "Conditionals threaded.\n");
402209ff 558 }
8ecba28a 559 else if (!redirect_edge_and_branch (e, target))
402209ff 560 {
c263766c
RH
561 if (dump_file)
562 fprintf (dump_file,
5f0d2358 563 "Forwarding edge %i->%i to %i failed.\n",
0b17ab2f 564 b->index, e->dest->index, target->index);
628f6a4e 565 ei_next (&ei);
8ecba28a 566 continue;
402209ff 567 }
5f0d2358 568
8ecba28a
JH
569 /* We successfully forwarded the edge. Now update profile
570 data: for each edge we traversed in the chain, remove
571 the original edge's execution count. */
8ecba28a
JH
572 do
573 {
574 edge t;
5f0d2358 575
c5cbcccf 576 if (!single_succ_p (first))
3b3b1e32 577 {
341c100f 578 gcc_assert (n < nthreaded_edges);
3b3b1e32 579 t = threaded_edges [n++];
341c100f 580 gcc_assert (t->src == first);
e7a74006 581 update_bb_profile_for_threading (first, edge_count, t);
b446e5a2 582 update_br_prob_note (first);
3b3b1e32 583 }
8ecba28a 584 else
bcb3bc6d 585 {
15db5571 586 first->count -= edge_count;
bcb3bc6d
JH
587 /* It is possible that as the result of
588 threading we've removed edge as it is
589 threaded to the fallthru edge. Avoid
590 getting out of sync. */
591 if (n < nthreaded_edges
592 && first == threaded_edges [n]->src)
593 n++;
c5cbcccf 594 t = single_succ_edge (first);
f87c27b4 595 }
5f0d2358 596
8ecba28a
JH
597 first = t->dest;
598 }
599 while (first != target);
600
601 changed = true;
628f6a4e 602 continue;
402209ff 603 }
628f6a4e 604 ei_next (&ei);
402209ff
JH
605 }
606
04695783 607 free (threaded_edges);
402209ff
JH
608 return changed;
609}
610\f
402209ff
JH
611
612/* Blocks A and B are to be merged into a single block. A has no incoming
613 fallthru edge, so it can be moved before B without adding or modifying
614 any jumps (aside from the jump from A to B). */
615
4262e623 616static void
d329e058 617merge_blocks_move_predecessor_nojumps (basic_block a, basic_block b)
402209ff 618{
da5477a9 619 rtx_insn *barrier;
402209ff 620
750054a2
CT
621 /* If we are partitioning hot/cold basic blocks, we don't want to
622 mess up unconditional or indirect jumps that cross between hot
8e8d5162 623 and cold sections.
c22cacf3 624
8e8d5162 625 Basic block partitioning may result in some jumps that appear to
c22cacf3
MS
626 be optimizable (or blocks that appear to be mergeable), but which really
627 must be left untouched (they are required to make it safely across
628 partition boundaries). See the comments at the top of
8e8d5162
CT
629 bb-reorder.c:partition_hot_cold_basic_blocks for complete details. */
630
87c8b4be 631 if (BB_PARTITION (a) != BB_PARTITION (b))
750054a2
CT
632 return;
633
a813c111 634 barrier = next_nonnote_insn (BB_END (a));
341c100f 635 gcc_assert (BARRIER_P (barrier));
53c17031 636 delete_insn (barrier);
402209ff 637
402209ff 638 /* Scramble the insn chain. */
a813c111
SB
639 if (BB_END (a) != PREV_INSN (BB_HEAD (b)))
640 reorder_insns_nobb (BB_HEAD (a), BB_END (a), PREV_INSN (BB_HEAD (b)));
6fb5fa3c 641 df_set_bb_dirty (a);
402209ff 642
c263766c
RH
643 if (dump_file)
644 fprintf (dump_file, "Moved block %d before %d and merged.\n",
0b17ab2f 645 a->index, b->index);
402209ff 646
bf77398c 647 /* Swap the records for the two blocks around. */
402209ff 648
918ed612
ZD
649 unlink_block (a);
650 link_block (a, b->prev_bb);
651
402209ff 652 /* Now blocks A and B are contiguous. Merge them. */
bc35512f 653 merge_blocks (a, b);
402209ff
JH
654}
655
656/* Blocks A and B are to be merged into a single block. B has no outgoing
657 fallthru edge, so it can be moved after A without adding or modifying
658 any jumps (aside from the jump from A to B). */
659
4262e623 660static void
d329e058 661merge_blocks_move_successor_nojumps (basic_block a, basic_block b)
402209ff 662{
da5477a9 663 rtx_insn *barrier, *real_b_end;
dfe08bc4 664 rtx_insn *label;
8942ee0f 665 rtx_jump_table_data *table;
402209ff 666
750054a2
CT
667 /* If we are partitioning hot/cold basic blocks, we don't want to
668 mess up unconditional or indirect jumps that cross between hot
c22cacf3
MS
669 and cold sections.
670
8e8d5162 671 Basic block partitioning may result in some jumps that appear to
c22cacf3
MS
672 be optimizable (or blocks that appear to be mergeable), but which really
673 must be left untouched (they are required to make it safely across
674 partition boundaries). See the comments at the top of
8e8d5162
CT
675 bb-reorder.c:partition_hot_cold_basic_blocks for complete details. */
676
87c8b4be 677 if (BB_PARTITION (a) != BB_PARTITION (b))
750054a2
CT
678 return;
679
a813c111 680 real_b_end = BB_END (b);
402209ff 681
ee735eef
JZ
682 /* If there is a jump table following block B temporarily add the jump table
683 to block B so that it will also be moved to the correct location. */
a813c111 684 if (tablejump_p (BB_END (b), &label, &table)
dfe08bc4 685 && prev_active_insn (label) == BB_END (b))
402209ff 686 {
1130d5e3 687 BB_END (b) = table;
402209ff
JH
688 }
689
690 /* There had better have been a barrier there. Delete it. */
a813c111 691 barrier = NEXT_INSN (BB_END (b));
4b4bf941 692 if (barrier && BARRIER_P (barrier))
53c17031 693 delete_insn (barrier);
402209ff 694
402209ff
JH
695
696 /* Scramble the insn chain. */
a813c111 697 reorder_insns_nobb (BB_HEAD (b), BB_END (b), BB_END (a));
402209ff 698
f62ce55b 699 /* Restore the real end of b. */
1130d5e3 700 BB_END (b) = real_b_end;
f62ce55b 701
c263766c
RH
702 if (dump_file)
703 fprintf (dump_file, "Moved block %d after %d and merged.\n",
0b17ab2f 704 b->index, a->index);
2150ad33
RH
705
706 /* Now blocks A and B are contiguous. Merge them. */
bc35512f 707 merge_blocks (a, b);
402209ff
JH
708}
709
710/* Attempt to merge basic blocks that are potentially non-adjacent.
ec3ae3da
JH
711 Return NULL iff the attempt failed, otherwise return basic block
712 where cleanup_cfg should continue. Because the merging commonly
713 moves basic block away or introduces another optimization
e0bb17a8 714 possibility, return basic block just before B so cleanup_cfg don't
ec3ae3da
JH
715 need to iterate.
716
717 It may be good idea to return basic block before C in the case
718 C has been moved after B and originally appeared earlier in the
4d6922ee 719 insn sequence, but we have no information available about the
ec3ae3da
JH
720 relative ordering of these two. Hopefully it is not too common. */
721
722static basic_block
bc35512f 723merge_blocks_move (edge e, basic_block b, basic_block c, int mode)
402209ff 724{
ec3ae3da 725 basic_block next;
402209ff 726
750054a2
CT
727 /* If we are partitioning hot/cold basic blocks, we don't want to
728 mess up unconditional or indirect jumps that cross between hot
c22cacf3
MS
729 and cold sections.
730
8e8d5162 731 Basic block partitioning may result in some jumps that appear to
c22cacf3
MS
732 be optimizable (or blocks that appear to be mergeable), but which really
733 must be left untouched (they are required to make it safely across
734 partition boundaries). See the comments at the top of
8e8d5162
CT
735 bb-reorder.c:partition_hot_cold_basic_blocks for complete details. */
736
87c8b4be 737 if (BB_PARTITION (b) != BB_PARTITION (c))
750054a2 738 return NULL;
c22cacf3 739
402209ff
JH
740 /* If B has a fallthru edge to C, no need to move anything. */
741 if (e->flags & EDGE_FALLTHRU)
742 {
0b17ab2f 743 int b_index = b->index, c_index = c->index;
7d776ee2
RG
744
745 /* Protect the loop latches. */
746 if (current_loops && c->loop_father->latch == c)
747 return NULL;
748
bc35512f 749 merge_blocks (b, c);
635559ab 750 update_forwarder_flag (b);
402209ff 751
c263766c
RH
752 if (dump_file)
753 fprintf (dump_file, "Merged %d and %d without moving.\n",
f87c27b4 754 b_index, c_index);
402209ff 755
fefa31b5 756 return b->prev_bb == ENTRY_BLOCK_PTR_FOR_FN (cfun) ? b : b->prev_bb;
402209ff 757 }
5f0d2358 758
402209ff
JH
759 /* Otherwise we will need to move code around. Do that only if expensive
760 transformations are allowed. */
761 else if (mode & CLEANUP_EXPENSIVE)
762 {
4262e623
JH
763 edge tmp_edge, b_fallthru_edge;
764 bool c_has_outgoing_fallthru;
765 bool b_has_incoming_fallthru;
402209ff
JH
766
767 /* Avoid overactive code motion, as the forwarder blocks should be
c22cacf3 768 eliminated by edge redirection instead. One exception might have
402209ff
JH
769 been if B is a forwarder block and C has no fallthru edge, but
770 that should be cleaned up by bb-reorder instead. */
635559ab 771 if (FORWARDER_BLOCK_P (b) || FORWARDER_BLOCK_P (c))
ec3ae3da 772 return NULL;
402209ff
JH
773
774 /* We must make sure to not munge nesting of lexical blocks,
775 and loop notes. This is done by squeezing out all the notes
776 and leaving them there to lie. Not ideal, but functional. */
777
0fd4b31d 778 tmp_edge = find_fallthru_edge (c->succs);
402209ff 779 c_has_outgoing_fallthru = (tmp_edge != NULL);
402209ff 780
0fd4b31d 781 tmp_edge = find_fallthru_edge (b->preds);
402209ff 782 b_has_incoming_fallthru = (tmp_edge != NULL);
4262e623 783 b_fallthru_edge = tmp_edge;
ec3ae3da 784 next = b->prev_bb;
912b79e7
JH
785 if (next == c)
786 next = next->prev_bb;
4262e623
JH
787
788 /* Otherwise, we're going to try to move C after B. If C does
789 not have an outgoing fallthru, then it can be moved
790 immediately after B without introducing or modifying jumps. */
791 if (! c_has_outgoing_fallthru)
792 {
793 merge_blocks_move_successor_nojumps (b, c);
fefa31b5 794 return next == ENTRY_BLOCK_PTR_FOR_FN (cfun) ? next->next_bb : next;
4262e623 795 }
402209ff
JH
796
797 /* If B does not have an incoming fallthru, then it can be moved
798 immediately before C without introducing or modifying jumps.
799 C cannot be the first block, so we do not have to worry about
800 accessing a non-existent block. */
402209ff 801
4262e623
JH
802 if (b_has_incoming_fallthru)
803 {
473fb060 804 basic_block bb;
5f0d2358 805
fefa31b5 806 if (b_fallthru_edge->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
ec3ae3da 807 return NULL;
7dddfb65
JH
808 bb = force_nonfallthru (b_fallthru_edge);
809 if (bb)
810 notice_new_block (bb);
4262e623 811 }
5f0d2358 812
4262e623 813 merge_blocks_move_predecessor_nojumps (b, c);
fefa31b5 814 return next == ENTRY_BLOCK_PTR_FOR_FN (cfun) ? next->next_bb : next;
402209ff 815 }
5f0d2358 816
10d6c0d0 817 return NULL;
402209ff
JH
818}
819\f
c2fc5456
R
820
821/* Removes the memory attributes of MEM expression
822 if they are not equal. */
823
893479de 824static void
c2fc5456
R
825merge_memattrs (rtx x, rtx y)
826{
827 int i;
828 int j;
829 enum rtx_code code;
830 const char *fmt;
831
832 if (x == y)
833 return;
834 if (x == 0 || y == 0)
835 return;
836
837 code = GET_CODE (x);
838
839 if (code != GET_CODE (y))
840 return;
841
842 if (GET_MODE (x) != GET_MODE (y))
843 return;
844
96b3c03f 845 if (code == MEM && !mem_attrs_eq_p (MEM_ATTRS (x), MEM_ATTRS (y)))
c2fc5456
R
846 {
847 if (! MEM_ATTRS (x))
848 MEM_ATTRS (y) = 0;
849 else if (! MEM_ATTRS (y))
850 MEM_ATTRS (x) = 0;
c22cacf3 851 else
c2fc5456 852 {
c2fc5456
R
853 if (MEM_ALIAS_SET (x) != MEM_ALIAS_SET (y))
854 {
855 set_mem_alias_set (x, 0);
856 set_mem_alias_set (y, 0);
857 }
c22cacf3 858
c2fc5456
R
859 if (! mem_expr_equal_p (MEM_EXPR (x), MEM_EXPR (y)))
860 {
861 set_mem_expr (x, 0);
862 set_mem_expr (y, 0);
527210c4
RS
863 clear_mem_offset (x);
864 clear_mem_offset (y);
c2fc5456 865 }
527210c4
RS
866 else if (MEM_OFFSET_KNOWN_P (x) != MEM_OFFSET_KNOWN_P (y)
867 || (MEM_OFFSET_KNOWN_P (x)
d05d7551 868 && maybe_ne (MEM_OFFSET (x), MEM_OFFSET (y))))
c2fc5456 869 {
527210c4
RS
870 clear_mem_offset (x);
871 clear_mem_offset (y);
c2fc5456 872 }
c22cacf3 873
d05d7551
RS
874 if (!MEM_SIZE_KNOWN_P (x))
875 clear_mem_size (y);
876 else if (!MEM_SIZE_KNOWN_P (y))
877 clear_mem_size (x);
878 else if (known_le (MEM_SIZE (x), MEM_SIZE (y)))
879 set_mem_size (x, MEM_SIZE (y));
880 else if (known_le (MEM_SIZE (y), MEM_SIZE (x)))
881 set_mem_size (y, MEM_SIZE (x));
c2fc5456 882 else
f5541398 883 {
d05d7551 884 /* The sizes aren't ordered, so we can't merge them. */
f5541398
RS
885 clear_mem_size (x);
886 clear_mem_size (y);
887 }
c2fc5456
R
888
889 set_mem_align (x, MIN (MEM_ALIGN (x), MEM_ALIGN (y)));
890 set_mem_align (y, MEM_ALIGN (x));
891 }
892 }
84cf4ab6
JJ
893 if (code == MEM)
894 {
895 if (MEM_READONLY_P (x) != MEM_READONLY_P (y))
896 {
897 MEM_READONLY_P (x) = 0;
898 MEM_READONLY_P (y) = 0;
899 }
900 if (MEM_NOTRAP_P (x) != MEM_NOTRAP_P (y))
901 {
902 MEM_NOTRAP_P (x) = 0;
903 MEM_NOTRAP_P (y) = 0;
904 }
905 if (MEM_VOLATILE_P (x) != MEM_VOLATILE_P (y))
906 {
907 MEM_VOLATILE_P (x) = 1;
908 MEM_VOLATILE_P (y) = 1;
909 }
910 }
c22cacf3 911
c2fc5456
R
912 fmt = GET_RTX_FORMAT (code);
913 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
914 {
915 switch (fmt[i])
916 {
917 case 'E':
918 /* Two vectors must have the same length. */
919 if (XVECLEN (x, i) != XVECLEN (y, i))
920 return;
921
922 for (j = 0; j < XVECLEN (x, i); j++)
923 merge_memattrs (XVECEXP (x, i, j), XVECEXP (y, i, j));
924
925 break;
926
927 case 'e':
928 merge_memattrs (XEXP (x, i), XEXP (y, i));
929 }
930 }
931 return;
932}
933
934
472c95f5
TV
935 /* Checks if patterns P1 and P2 are equivalent, apart from the possibly
936 different single sets S1 and S2. */
c2fc5456
R
937
938static bool
472c95f5
TV
939equal_different_set_p (rtx p1, rtx s1, rtx p2, rtx s2)
940{
941 int i;
942 rtx e1, e2;
943
944 if (p1 == s1 && p2 == s2)
945 return true;
946
947 if (GET_CODE (p1) != PARALLEL || GET_CODE (p2) != PARALLEL)
948 return false;
949
950 if (XVECLEN (p1, 0) != XVECLEN (p2, 0))
951 return false;
952
953 for (i = 0; i < XVECLEN (p1, 0); i++)
954 {
955 e1 = XVECEXP (p1, 0, i);
956 e2 = XVECEXP (p2, 0, i);
957 if (e1 == s1 && e2 == s2)
958 continue;
959 if (reload_completed
960 ? rtx_renumbered_equal_p (e1, e2) : rtx_equal_p (e1, e2))
961 continue;
962
21c0a521 963 return false;
472c95f5
TV
964 }
965
966 return true;
967}
968
3e87f2d6
SC
969
970/* NOTE1 is the REG_EQUAL note, if any, attached to an insn
971 that is a single_set with a SET_SRC of SRC1. Similarly
972 for NOTE2/SRC2.
973
974 So effectively NOTE1/NOTE2 are an alternate form of
975 SRC1/SRC2 respectively.
976
977 Return nonzero if SRC1 or NOTE1 has the same constant
978 integer value as SRC2 or NOTE2. Else return zero. */
979static int
980values_equal_p (rtx note1, rtx note2, rtx src1, rtx src2)
981{
982 if (note1
983 && note2
984 && CONST_INT_P (XEXP (note1, 0))
985 && rtx_equal_p (XEXP (note1, 0), XEXP (note2, 0)))
986 return 1;
987
988 if (!note1
989 && !note2
990 && CONST_INT_P (src1)
991 && CONST_INT_P (src2)
992 && rtx_equal_p (src1, src2))
993 return 1;
994
995 if (note1
996 && CONST_INT_P (src2)
997 && rtx_equal_p (XEXP (note1, 0), src2))
998 return 1;
999
1000 if (note2
1001 && CONST_INT_P (src1)
1002 && rtx_equal_p (XEXP (note2, 0), src1))
1003 return 1;
1004
1005 return 0;
1006}
1007
472c95f5
TV
1008/* Examine register notes on I1 and I2 and return:
1009 - dir_forward if I1 can be replaced by I2, or
1010 - dir_backward if I2 can be replaced by I1, or
1011 - dir_both if both are the case. */
1012
1013static enum replace_direction
da5477a9 1014can_replace_by (rtx_insn *i1, rtx_insn *i2)
472c95f5
TV
1015{
1016 rtx s1, s2, d1, d2, src1, src2, note1, note2;
1017 bool c1, c2;
1018
1019 /* Check for 2 sets. */
1020 s1 = single_set (i1);
1021 s2 = single_set (i2);
1022 if (s1 == NULL_RTX || s2 == NULL_RTX)
1023 return dir_none;
1024
1025 /* Check that the 2 sets set the same dest. */
1026 d1 = SET_DEST (s1);
1027 d2 = SET_DEST (s2);
1028 if (!(reload_completed
1029 ? rtx_renumbered_equal_p (d1, d2) : rtx_equal_p (d1, d2)))
1030 return dir_none;
1031
1032 /* Find identical req_equiv or reg_equal note, which implies that the 2 sets
1033 set dest to the same value. */
1034 note1 = find_reg_equal_equiv_note (i1);
1035 note2 = find_reg_equal_equiv_note (i2);
3e87f2d6
SC
1036
1037 src1 = SET_SRC (s1);
1038 src2 = SET_SRC (s2);
1039
1040 if (!values_equal_p (note1, note2, src1, src2))
472c95f5
TV
1041 return dir_none;
1042
1043 if (!equal_different_set_p (PATTERN (i1), s1, PATTERN (i2), s2))
1044 return dir_none;
1045
1046 /* Although the 2 sets set dest to the same value, we cannot replace
1047 (set (dest) (const_int))
1048 by
1049 (set (dest) (reg))
1050 because we don't know if the reg is live and has the same value at the
1051 location of replacement. */
472c95f5
TV
1052 c1 = CONST_INT_P (src1);
1053 c2 = CONST_INT_P (src2);
1054 if (c1 && c2)
1055 return dir_both;
1056 else if (c2)
1057 return dir_forward;
1058 else if (c1)
1059 return dir_backward;
1060
1061 return dir_none;
1062}
1063
1064/* Merges directions A and B. */
1065
1066static enum replace_direction
1067merge_dir (enum replace_direction a, enum replace_direction b)
1068{
1069 /* Implements the following table:
1070 |bo fw bw no
1071 ---+-----------
1072 bo |bo fw bw no
1073 fw |-- fw no no
1074 bw |-- -- bw no
1075 no |-- -- -- no. */
1076
1077 if (a == b)
1078 return a;
1079
1080 if (a == dir_both)
1081 return b;
1082 if (b == dir_both)
1083 return a;
1084
1085 return dir_none;
1086}
1087
aade772d
JJ
1088/* Array of flags indexed by reg note kind, true if the given
1089 reg note is CFA related. */
1090static const bool reg_note_cfa_p[] = {
1091#undef REG_CFA_NOTE
1092#define DEF_REG_NOTE(NAME) false,
1093#define REG_CFA_NOTE(NAME) true,
1094#include "reg-notes.def"
1095#undef REG_CFA_NOTE
1096#undef DEF_REG_NOTE
1097 false
1098};
1099
1100/* Return true if I1 and I2 have identical CFA notes (the same order
1101 and equivalent content). */
1102
1103static bool
1104insns_have_identical_cfa_notes (rtx_insn *i1, rtx_insn *i2)
1105{
1106 rtx n1, n2;
1107 for (n1 = REG_NOTES (i1), n2 = REG_NOTES (i2); ;
1108 n1 = XEXP (n1, 1), n2 = XEXP (n2, 1))
1109 {
1110 /* Skip over reg notes not related to CFI information. */
1111 while (n1 && !reg_note_cfa_p[REG_NOTE_KIND (n1)])
1112 n1 = XEXP (n1, 1);
1113 while (n2 && !reg_note_cfa_p[REG_NOTE_KIND (n2)])
1114 n2 = XEXP (n2, 1);
1115 if (n1 == NULL_RTX && n2 == NULL_RTX)
1116 return true;
1117 if (n1 == NULL_RTX || n2 == NULL_RTX)
1118 return false;
1119 if (XEXP (n1, 0) == XEXP (n2, 0))
1120 ;
1121 else if (XEXP (n1, 0) == NULL_RTX || XEXP (n2, 0) == NULL_RTX)
1122 return false;
1123 else if (!(reload_completed
1124 ? rtx_renumbered_equal_p (XEXP (n1, 0), XEXP (n2, 0))
1125 : rtx_equal_p (XEXP (n1, 0), XEXP (n2, 0))))
1126 return false;
1127 }
1128}
1129
472c95f5
TV
1130/* Examine I1 and I2 and return:
1131 - dir_forward if I1 can be replaced by I2, or
1132 - dir_backward if I2 can be replaced by I1, or
1133 - dir_both if both are the case. */
1134
1135static enum replace_direction
da5477a9 1136old_insns_match_p (int mode ATTRIBUTE_UNUSED, rtx_insn *i1, rtx_insn *i2)
c2fc5456
R
1137{
1138 rtx p1, p2;
1139
1140 /* Verify that I1 and I2 are equivalent. */
1141 if (GET_CODE (i1) != GET_CODE (i2))
472c95f5 1142 return dir_none;
c2fc5456 1143
ba21aba3
DD
1144 /* __builtin_unreachable() may lead to empty blocks (ending with
1145 NOTE_INSN_BASIC_BLOCK). They may be crossjumped. */
1146 if (NOTE_INSN_BASIC_BLOCK_P (i1) && NOTE_INSN_BASIC_BLOCK_P (i2))
472c95f5 1147 return dir_both;
ba21aba3 1148
9a08d230
RH
1149 /* ??? Do not allow cross-jumping between different stack levels. */
1150 p1 = find_reg_note (i1, REG_ARGS_SIZE, NULL);
1151 p2 = find_reg_note (i2, REG_ARGS_SIZE, NULL);
42aa5124
RH
1152 if (p1 && p2)
1153 {
1154 p1 = XEXP (p1, 0);
1155 p2 = XEXP (p2, 0);
1156 if (!rtx_equal_p (p1, p2))
1157 return dir_none;
1158
1159 /* ??? Worse, this adjustment had better be constant lest we
1160 have differing incoming stack levels. */
1161 if (!frame_pointer_needed
68184180 1162 && known_eq (find_args_size_adjust (i1), HOST_WIDE_INT_MIN))
42aa5124
RH
1163 return dir_none;
1164 }
1165 else if (p1 || p2)
9a08d230
RH
1166 return dir_none;
1167
aade772d
JJ
1168 /* Do not allow cross-jumping between frame related insns and other
1169 insns. */
1170 if (RTX_FRAME_RELATED_P (i1) != RTX_FRAME_RELATED_P (i2))
1171 return dir_none;
1172
7752e522 1173 p1 = PATTERN (i1);
c2fc5456
R
1174 p2 = PATTERN (i2);
1175
1176 if (GET_CODE (p1) != GET_CODE (p2))
472c95f5 1177 return dir_none;
c2fc5456
R
1178
1179 /* If this is a CALL_INSN, compare register usage information.
1180 If we don't check this on stack register machines, the two
1181 CALL_INSNs might be merged leaving reg-stack.c with mismatching
1182 numbers of stack registers in the same basic block.
1183 If we don't check this on machines with delay slots, a delay slot may
1184 be filled that clobbers a parameter expected by the subroutine.
1185
1186 ??? We take the simple route for now and assume that if they're
31ce8a53 1187 equal, they were constructed identically.
c2fc5456 1188
31ce8a53
BS
1189 Also check for identical exception regions. */
1190
1191 if (CALL_P (i1))
1192 {
1193 /* Ensure the same EH region. */
1194 rtx n1 = find_reg_note (i1, REG_EH_REGION, 0);
1195 rtx n2 = find_reg_note (i2, REG_EH_REGION, 0);
1196
1197 if (!n1 && n2)
472c95f5 1198 return dir_none;
31ce8a53
BS
1199
1200 if (n1 && (!n2 || XEXP (n1, 0) != XEXP (n2, 0)))
472c95f5 1201 return dir_none;
31ce8a53
BS
1202
1203 if (!rtx_equal_p (CALL_INSN_FUNCTION_USAGE (i1),
c22cacf3 1204 CALL_INSN_FUNCTION_USAGE (i2))
31ce8a53 1205 || SIBLING_CALL_P (i1) != SIBLING_CALL_P (i2))
472c95f5 1206 return dir_none;
68a9738a
JJ
1207
1208 /* For address sanitizer, never crossjump __asan_report_* builtins,
1209 otherwise errors might be reported on incorrect lines. */
de5a5fa1 1210 if (flag_sanitize & SANITIZE_ADDRESS)
68a9738a
JJ
1211 {
1212 rtx call = get_call_rtx_from (i1);
1213 if (call && GET_CODE (XEXP (XEXP (call, 0), 0)) == SYMBOL_REF)
1214 {
1215 rtx symbol = XEXP (XEXP (call, 0), 0);
1216 if (SYMBOL_REF_DECL (symbol)
1217 && TREE_CODE (SYMBOL_REF_DECL (symbol)) == FUNCTION_DECL)
1218 {
1219 if ((DECL_BUILT_IN_CLASS (SYMBOL_REF_DECL (symbol))
1220 == BUILT_IN_NORMAL)
1221 && DECL_FUNCTION_CODE (SYMBOL_REF_DECL (symbol))
1222 >= BUILT_IN_ASAN_REPORT_LOAD1
1223 && DECL_FUNCTION_CODE (SYMBOL_REF_DECL (symbol))
8946c29e 1224 <= BUILT_IN_ASAN_STOREN)
68a9738a
JJ
1225 return dir_none;
1226 }
1227 }
1228 }
4b1a1d98 1229
01699686 1230 if (insn_callee_abi (i1) != insn_callee_abi (i2))
4b1a1d98 1231 return dir_none;
31ce8a53 1232 }
c2fc5456 1233
aade772d
JJ
1234 /* If both i1 and i2 are frame related, verify all the CFA notes
1235 in the same order and with the same content. */
1236 if (RTX_FRAME_RELATED_P (i1) && !insns_have_identical_cfa_notes (i1, i2))
1237 return dir_none;
1238
c2fc5456
R
1239#ifdef STACK_REGS
1240 /* If cross_jump_death_matters is not 0, the insn's mode
1241 indicates whether or not the insn contains any stack-like
1242 regs. */
1243
1244 if ((mode & CLEANUP_POST_REGSTACK) && stack_regs_mentioned (i1))
1245 {
1246 /* If register stack conversion has already been done, then
c22cacf3
MS
1247 death notes must also be compared before it is certain that
1248 the two instruction streams match. */
c2fc5456
R
1249
1250 rtx note;
1251 HARD_REG_SET i1_regset, i2_regset;
1252
1253 CLEAR_HARD_REG_SET (i1_regset);
1254 CLEAR_HARD_REG_SET (i2_regset);
1255
1256 for (note = REG_NOTES (i1); note; note = XEXP (note, 1))
1257 if (REG_NOTE_KIND (note) == REG_DEAD && STACK_REG_P (XEXP (note, 0)))
1258 SET_HARD_REG_BIT (i1_regset, REGNO (XEXP (note, 0)));
1259
1260 for (note = REG_NOTES (i2); note; note = XEXP (note, 1))
1261 if (REG_NOTE_KIND (note) == REG_DEAD && STACK_REG_P (XEXP (note, 0)))
1262 SET_HARD_REG_BIT (i2_regset, REGNO (XEXP (note, 0)));
1263
a8579651 1264 if (i1_regset != i2_regset)
472c95f5 1265 return dir_none;
c2fc5456
R
1266 }
1267#endif
1268
1269 if (reload_completed
1270 ? rtx_renumbered_equal_p (p1, p2) : rtx_equal_p (p1, p2))
472c95f5 1271 return dir_both;
c2fc5456 1272
472c95f5 1273 return can_replace_by (i1, i2);
c2fc5456
R
1274}
1275\f
31ce8a53
BS
1276/* When comparing insns I1 and I2 in flow_find_cross_jump or
1277 flow_find_head_matching_sequence, ensure the notes match. */
1278
1279static void
da5477a9 1280merge_notes (rtx_insn *i1, rtx_insn *i2)
31ce8a53
BS
1281{
1282 /* If the merged insns have different REG_EQUAL notes, then
1283 remove them. */
1284 rtx equiv1 = find_reg_equal_equiv_note (i1);
1285 rtx equiv2 = find_reg_equal_equiv_note (i2);
1286
1287 if (equiv1 && !equiv2)
1288 remove_note (i1, equiv1);
1289 else if (!equiv1 && equiv2)
1290 remove_note (i2, equiv2);
1291 else if (equiv1 && equiv2
1292 && !rtx_equal_p (XEXP (equiv1, 0), XEXP (equiv2, 0)))
1293 {
1294 remove_note (i1, equiv1);
1295 remove_note (i2, equiv2);
1296 }
1297}
1298
823918ae
TV
1299 /* Walks from I1 in BB1 backward till the next non-debug insn, and returns the
1300 resulting insn in I1, and the corresponding bb in BB1. At the head of a
1301 bb, if there is a predecessor bb that reaches this bb via fallthru, and
1302 FOLLOW_FALLTHRU, walks further in the predecessor bb and registers this in
1303 DID_FALLTHRU. Otherwise, stops at the head of the bb. */
1304
1305static void
da5477a9 1306walk_to_nondebug_insn (rtx_insn **i1, basic_block *bb1, bool follow_fallthru,
823918ae
TV
1307 bool *did_fallthru)
1308{
1309 edge fallthru;
1310
1311 *did_fallthru = false;
1312
1313 /* Ignore notes. */
1314 while (!NONDEBUG_INSN_P (*i1))
1315 {
1316 if (*i1 != BB_HEAD (*bb1))
1317 {
1318 *i1 = PREV_INSN (*i1);
1319 continue;
1320 }
1321
1322 if (!follow_fallthru)
1323 return;
1324
1325 fallthru = find_fallthru_edge ((*bb1)->preds);
fefa31b5 1326 if (!fallthru || fallthru->src == ENTRY_BLOCK_PTR_FOR_FN (cfun)
823918ae
TV
1327 || !single_succ_p (fallthru->src))
1328 return;
1329
1330 *bb1 = fallthru->src;
1331 *i1 = BB_END (*bb1);
1332 *did_fallthru = true;
1333 }
1334}
1335
c2fc5456 1336/* Look through the insns at the end of BB1 and BB2 and find the longest
472c95f5
TV
1337 sequence that are either equivalent, or allow forward or backward
1338 replacement. Store the first insns for that sequence in *F1 and *F2 and
1339 return the sequence length.
1340
1341 DIR_P indicates the allowed replacement direction on function entry, and
1342 the actual replacement direction on function exit. If NULL, only equivalent
1343 sequences are allowed.
c2fc5456
R
1344
1345 To simplify callers of this function, if the blocks match exactly,
1346 store the head of the blocks in *F1 and *F2. */
1347
31ce8a53 1348int
da5477a9
DM
1349flow_find_cross_jump (basic_block bb1, basic_block bb2, rtx_insn **f1,
1350 rtx_insn **f2, enum replace_direction *dir_p)
c2fc5456 1351{
da5477a9 1352 rtx_insn *i1, *i2, *last1, *last2, *afterlast1, *afterlast2;
c2fc5456 1353 int ninsns = 0;
472c95f5 1354 enum replace_direction dir, last_dir, afterlast_dir;
823918ae 1355 bool follow_fallthru, did_fallthru;
472c95f5
TV
1356
1357 if (dir_p)
1358 dir = *dir_p;
1359 else
1360 dir = dir_both;
1361 afterlast_dir = dir;
1362 last_dir = afterlast_dir;
c2fc5456
R
1363
1364 /* Skip simple jumps at the end of the blocks. Complex jumps still
1365 need to be compared for equivalence, which we'll do below. */
1366
1367 i1 = BB_END (bb1);
da5477a9 1368 last1 = afterlast1 = last2 = afterlast2 = NULL;
c2fc5456
R
1369 if (onlyjump_p (i1)
1370 || (returnjump_p (i1) && !side_effects_p (PATTERN (i1))))
1371 {
1372 last1 = i1;
1373 i1 = PREV_INSN (i1);
1374 }
1375
1376 i2 = BB_END (bb2);
1377 if (onlyjump_p (i2)
1378 || (returnjump_p (i2) && !side_effects_p (PATTERN (i2))))
1379 {
1380 last2 = i2;
a0cbe71e
JJ
1381 /* Count everything except for unconditional jump as insn.
1382 Don't count any jumps if dir_p is NULL. */
1383 if (!simplejump_p (i2) && !returnjump_p (i2) && last1 && dir_p)
c2fc5456
R
1384 ninsns++;
1385 i2 = PREV_INSN (i2);
1386 }
1387
1388 while (true)
1389 {
823918ae
TV
1390 /* In the following example, we can replace all jumps to C by jumps to A.
1391
1392 This removes 4 duplicate insns.
1393 [bb A] insn1 [bb C] insn1
1394 insn2 insn2
1395 [bb B] insn3 insn3
1396 insn4 insn4
1397 jump_insn jump_insn
1398
1399 We could also replace all jumps to A by jumps to C, but that leaves B
1400 alive, and removes only 2 duplicate insns. In a subsequent crossjump
1401 step, all jumps to B would be replaced with jumps to the middle of C,
1402 achieving the same result with more effort.
1403 So we allow only the first possibility, which means that we don't allow
1404 fallthru in the block that's being replaced. */
1405
1406 follow_fallthru = dir_p && dir != dir_forward;
1407 walk_to_nondebug_insn (&i1, &bb1, follow_fallthru, &did_fallthru);
1408 if (did_fallthru)
1409 dir = dir_backward;
1410
1411 follow_fallthru = dir_p && dir != dir_backward;
1412 walk_to_nondebug_insn (&i2, &bb2, follow_fallthru, &did_fallthru);
1413 if (did_fallthru)
1414 dir = dir_forward;
c2fc5456
R
1415
1416 if (i1 == BB_HEAD (bb1) || i2 == BB_HEAD (bb2))
1417 break;
1418
ba61fc53
JH
1419 /* Do not turn corssing edge to non-crossing or vice versa after
1420 reload. */
1421 if (BB_PARTITION (BLOCK_FOR_INSN (i1))
1422 != BB_PARTITION (BLOCK_FOR_INSN (i2))
1423 && reload_completed)
1424 break;
1425
472c95f5
TV
1426 dir = merge_dir (dir, old_insns_match_p (0, i1, i2));
1427 if (dir == dir_none || (!dir_p && dir != dir_both))
c2fc5456
R
1428 break;
1429
1430 merge_memattrs (i1, i2);
1431
1432 /* Don't begin a cross-jump with a NOTE insn. */
1433 if (INSN_P (i1))
1434 {
31ce8a53 1435 merge_notes (i1, i2);
c2fc5456
R
1436
1437 afterlast1 = last1, afterlast2 = last2;
1438 last1 = i1, last2 = i2;
472c95f5
TV
1439 afterlast_dir = last_dir;
1440 last_dir = dir;
a0cbe71e 1441 if (active_insn_p (i1))
2a562b0a 1442 ninsns++;
c2fc5456
R
1443 }
1444
1445 i1 = PREV_INSN (i1);
1446 i2 = PREV_INSN (i2);
1447 }
1448
c2fc5456
R
1449 /* Don't allow the insn after a compare to be shared by
1450 cross-jumping unless the compare is also shared. */
618f4073
TS
1451 if (HAVE_cc0 && ninsns && reg_mentioned_p (cc0_rtx, last1)
1452 && ! sets_cc0_p (last1))
472c95f5 1453 last1 = afterlast1, last2 = afterlast2, last_dir = afterlast_dir, ninsns--;
c2fc5456
R
1454
1455 /* Include preceding notes and labels in the cross-jump. One,
1456 this may bring us to the head of the blocks as requested above.
1457 Two, it keeps line number notes as matched as may be. */
1458 if (ninsns)
1459 {
823918ae 1460 bb1 = BLOCK_FOR_INSN (last1);
b5b8b0ac 1461 while (last1 != BB_HEAD (bb1) && !NONDEBUG_INSN_P (PREV_INSN (last1)))
c2fc5456
R
1462 last1 = PREV_INSN (last1);
1463
1464 if (last1 != BB_HEAD (bb1) && LABEL_P (PREV_INSN (last1)))
1465 last1 = PREV_INSN (last1);
1466
823918ae 1467 bb2 = BLOCK_FOR_INSN (last2);
b5b8b0ac 1468 while (last2 != BB_HEAD (bb2) && !NONDEBUG_INSN_P (PREV_INSN (last2)))
c2fc5456
R
1469 last2 = PREV_INSN (last2);
1470
1471 if (last2 != BB_HEAD (bb2) && LABEL_P (PREV_INSN (last2)))
1472 last2 = PREV_INSN (last2);
1473
1474 *f1 = last1;
1475 *f2 = last2;
1476 }
1477
472c95f5
TV
1478 if (dir_p)
1479 *dir_p = last_dir;
c2fc5456
R
1480 return ninsns;
1481}
1482
31ce8a53
BS
1483/* Like flow_find_cross_jump, except start looking for a matching sequence from
1484 the head of the two blocks. Do not include jumps at the end.
1485 If STOP_AFTER is nonzero, stop after finding that many matching
b59e0455
JJ
1486 instructions. If STOP_AFTER is zero, count all INSN_P insns, if it is
1487 non-zero, only count active insns. */
31ce8a53
BS
1488
1489int
da5477a9
DM
1490flow_find_head_matching_sequence (basic_block bb1, basic_block bb2, rtx_insn **f1,
1491 rtx_insn **f2, int stop_after)
31ce8a53 1492{
da5477a9 1493 rtx_insn *i1, *i2, *last1, *last2, *beforelast1, *beforelast2;
31ce8a53
BS
1494 int ninsns = 0;
1495 edge e;
1496 edge_iterator ei;
1497 int nehedges1 = 0, nehedges2 = 0;
1498
1499 FOR_EACH_EDGE (e, ei, bb1->succs)
1500 if (e->flags & EDGE_EH)
1501 nehedges1++;
1502 FOR_EACH_EDGE (e, ei, bb2->succs)
1503 if (e->flags & EDGE_EH)
1504 nehedges2++;
1505
1506 i1 = BB_HEAD (bb1);
1507 i2 = BB_HEAD (bb2);
da5477a9 1508 last1 = beforelast1 = last2 = beforelast2 = NULL;
31ce8a53
BS
1509
1510 while (true)
1511 {
4ec5d4f5 1512 /* Ignore notes, except NOTE_INSN_EPILOGUE_BEG. */
31ce8a53 1513 while (!NONDEBUG_INSN_P (i1) && i1 != BB_END (bb1))
4ec5d4f5
BS
1514 {
1515 if (NOTE_P (i1) && NOTE_KIND (i1) == NOTE_INSN_EPILOGUE_BEG)
1516 break;
1517 i1 = NEXT_INSN (i1);
1518 }
31ce8a53
BS
1519
1520 while (!NONDEBUG_INSN_P (i2) && i2 != BB_END (bb2))
4ec5d4f5
BS
1521 {
1522 if (NOTE_P (i2) && NOTE_KIND (i2) == NOTE_INSN_EPILOGUE_BEG)
1523 break;
1524 i2 = NEXT_INSN (i2);
1525 }
31ce8a53 1526
662592e1
BS
1527 if ((i1 == BB_END (bb1) && !NONDEBUG_INSN_P (i1))
1528 || (i2 == BB_END (bb2) && !NONDEBUG_INSN_P (i2)))
1529 break;
1530
31ce8a53
BS
1531 if (NOTE_P (i1) || NOTE_P (i2)
1532 || JUMP_P (i1) || JUMP_P (i2))
1533 break;
1534
1535 /* A sanity check to make sure we're not merging insns with different
1536 effects on EH. If only one of them ends a basic block, it shouldn't
1537 have an EH edge; if both end a basic block, there should be the same
1538 number of EH edges. */
1539 if ((i1 == BB_END (bb1) && i2 != BB_END (bb2)
1540 && nehedges1 > 0)
1541 || (i2 == BB_END (bb2) && i1 != BB_END (bb1)
1542 && nehedges2 > 0)
1543 || (i1 == BB_END (bb1) && i2 == BB_END (bb2)
1544 && nehedges1 != nehedges2))
1545 break;
1546
472c95f5 1547 if (old_insns_match_p (0, i1, i2) != dir_both)
31ce8a53
BS
1548 break;
1549
1550 merge_memattrs (i1, i2);
1551
1552 /* Don't begin a cross-jump with a NOTE insn. */
1553 if (INSN_P (i1))
1554 {
1555 merge_notes (i1, i2);
1556
1557 beforelast1 = last1, beforelast2 = last2;
1558 last1 = i1, last2 = i2;
b59e0455 1559 if (!stop_after || active_insn_p (i1))
a0cbe71e 1560 ninsns++;
31ce8a53
BS
1561 }
1562
1563 if (i1 == BB_END (bb1) || i2 == BB_END (bb2)
1564 || (stop_after > 0 && ninsns == stop_after))
1565 break;
1566
1567 i1 = NEXT_INSN (i1);
1568 i2 = NEXT_INSN (i2);
1569 }
1570
31ce8a53
BS
1571 /* Don't allow a compare to be shared by cross-jumping unless the insn
1572 after the compare is also shared. */
618f4073
TS
1573 if (HAVE_cc0 && ninsns && reg_mentioned_p (cc0_rtx, last1)
1574 && sets_cc0_p (last1))
31ce8a53 1575 last1 = beforelast1, last2 = beforelast2, ninsns--;
31ce8a53
BS
1576
1577 if (ninsns)
1578 {
1579 *f1 = last1;
1580 *f2 = last2;
1581 }
1582
1583 return ninsns;
1584}
1585
c2fc5456
R
1586/* Return true iff outgoing edges of BB1 and BB2 match, together with
1587 the branch instruction. This means that if we commonize the control
1588 flow before end of the basic block, the semantic remains unchanged.
402209ff
JH
1589
1590 We may assume that there exists one edge with a common destination. */
1591
1592static bool
c2fc5456 1593outgoing_edges_match (int mode, basic_block bb1, basic_block bb2)
402209ff 1594{
0dd0e980
JH
1595 int nehedges1 = 0, nehedges2 = 0;
1596 edge fallthru1 = 0, fallthru2 = 0;
1597 edge e1, e2;
628f6a4e 1598 edge_iterator ei;
0dd0e980 1599
6626665f 1600 /* If we performed shrink-wrapping, edges to the exit block can
484db665
BS
1601 only be distinguished for JUMP_INSNs. The two paths may differ in
1602 whether they went through the prologue. Sibcalls are fine, we know
1603 that we either didn't need or inserted an epilogue before them. */
1604 if (crtl->shrink_wrapped
fefa31b5
DM
1605 && single_succ_p (bb1)
1606 && single_succ (bb1) == EXIT_BLOCK_PTR_FOR_FN (cfun)
b532a785
JJ
1607 && (!JUMP_P (BB_END (bb1))
1608 /* Punt if the only successor is a fake edge to exit, the jump
1609 must be some weird one. */
1610 || (single_succ_edge (bb1)->flags & EDGE_FAKE) != 0)
484db665
BS
1611 && !(CALL_P (BB_END (bb1)) && SIBLING_CALL_P (BB_END (bb1))))
1612 return false;
b532a785 1613
c04cf67b
RH
1614 /* If BB1 has only one successor, we may be looking at either an
1615 unconditional jump, or a fake edge to exit. */
c5cbcccf
ZD
1616 if (single_succ_p (bb1)
1617 && (single_succ_edge (bb1)->flags & (EDGE_COMPLEX | EDGE_FAKE)) == 0
4b4bf941 1618 && (!JUMP_P (BB_END (bb1)) || simplejump_p (BB_END (bb1))))
c5cbcccf
ZD
1619 return (single_succ_p (bb2)
1620 && (single_succ_edge (bb2)->flags
1621 & (EDGE_COMPLEX | EDGE_FAKE)) == 0
4b4bf941 1622 && (!JUMP_P (BB_END (bb2)) || simplejump_p (BB_END (bb2))));
402209ff
JH
1623
1624 /* Match conditional jumps - this may get tricky when fallthru and branch
1625 edges are crossed. */
628f6a4e 1626 if (EDGE_COUNT (bb1->succs) == 2
a813c111
SB
1627 && any_condjump_p (BB_END (bb1))
1628 && onlyjump_p (BB_END (bb1)))
402209ff 1629 {
c2fc5456
R
1630 edge b1, f1, b2, f2;
1631 bool reverse, match;
1632 rtx set1, set2, cond1, cond2;
1633 enum rtx_code code1, code2;
1634
628f6a4e 1635 if (EDGE_COUNT (bb2->succs) != 2
a813c111
SB
1636 || !any_condjump_p (BB_END (bb2))
1637 || !onlyjump_p (BB_END (bb2)))
0a2ed1f1 1638 return false;
c2fc5456
R
1639
1640 b1 = BRANCH_EDGE (bb1);
1641 b2 = BRANCH_EDGE (bb2);
1642 f1 = FALLTHRU_EDGE (bb1);
1643 f2 = FALLTHRU_EDGE (bb2);
1644
1645 /* Get around possible forwarders on fallthru edges. Other cases
c22cacf3 1646 should be optimized out already. */
c2fc5456
R
1647 if (FORWARDER_BLOCK_P (f1->dest))
1648 f1 = single_succ_edge (f1->dest);
1649
1650 if (FORWARDER_BLOCK_P (f2->dest))
1651 f2 = single_succ_edge (f2->dest);
1652
1653 /* To simplify use of this function, return false if there are
1654 unneeded forwarder blocks. These will get eliminated later
1655 during cleanup_cfg. */
1656 if (FORWARDER_BLOCK_P (f1->dest)
1657 || FORWARDER_BLOCK_P (f2->dest)
1658 || FORWARDER_BLOCK_P (b1->dest)
1659 || FORWARDER_BLOCK_P (b2->dest))
1660 return false;
1661
1662 if (f1->dest == f2->dest && b1->dest == b2->dest)
1663 reverse = false;
1664 else if (f1->dest == b2->dest && b1->dest == f2->dest)
1665 reverse = true;
1666 else
1667 return false;
1668
1669 set1 = pc_set (BB_END (bb1));
1670 set2 = pc_set (BB_END (bb2));
1671 if ((XEXP (SET_SRC (set1), 1) == pc_rtx)
1672 != (XEXP (SET_SRC (set2), 1) == pc_rtx))
1673 reverse = !reverse;
1674
1675 cond1 = XEXP (SET_SRC (set1), 0);
1676 cond2 = XEXP (SET_SRC (set2), 0);
1677 code1 = GET_CODE (cond1);
1678 if (reverse)
1679 code2 = reversed_comparison_code (cond2, BB_END (bb2));
1680 else
1681 code2 = GET_CODE (cond2);
1682
1683 if (code2 == UNKNOWN)
1684 return false;
1685
1686 /* Verify codes and operands match. */
1687 match = ((code1 == code2
1688 && rtx_renumbered_equal_p (XEXP (cond1, 0), XEXP (cond2, 0))
1689 && rtx_renumbered_equal_p (XEXP (cond1, 1), XEXP (cond2, 1)))
1690 || (code1 == swap_condition (code2)
1691 && rtx_renumbered_equal_p (XEXP (cond1, 1),
1692 XEXP (cond2, 0))
1693 && rtx_renumbered_equal_p (XEXP (cond1, 0),
1694 XEXP (cond2, 1))));
1695
1696 /* If we return true, we will join the blocks. Which means that
1697 we will only have one branch prediction bit to work with. Thus
1698 we require the existing branches to have probabilities that are
1699 roughly similar. */
1700 if (match
efd8f750
JH
1701 && optimize_bb_for_speed_p (bb1)
1702 && optimize_bb_for_speed_p (bb2))
c2fc5456 1703 {
357067f2 1704 profile_probability prob2;
c2fc5456
R
1705
1706 if (b1->dest == b2->dest)
1707 prob2 = b2->probability;
1708 else
1709 /* Do not use f2 probability as f2 may be forwarded. */
357067f2 1710 prob2 = b2->probability.invert ();
c2fc5456
R
1711
1712 /* Fail if the difference in probabilities is greater than 50%.
1713 This rules out two well-predicted branches with opposite
1714 outcomes. */
357067f2 1715 if (b1->probability.differs_lot_from_p (prob2))
c2fc5456
R
1716 {
1717 if (dump_file)
357067f2
JH
1718 {
1719 fprintf (dump_file,
1720 "Outcomes of branch in bb %i and %i differ too"
1721 " much (", bb1->index, bb2->index);
1722 b1->probability.dump (dump_file);
1723 prob2.dump (dump_file);
1724 fprintf (dump_file, ")\n");
1725 }
c2fc5456
R
1726 return false;
1727 }
1728 }
1729
1730 if (dump_file && match)
1731 fprintf (dump_file, "Conditionals in bb %i and %i match.\n",
1732 bb1->index, bb2->index);
1733
1734 return match;
402209ff
JH
1735 }
1736
09da1532 1737 /* Generic case - we are seeing a computed jump, table jump or trapping
0dd0e980
JH
1738 instruction. */
1739
39811184
JZ
1740 /* Check whether there are tablejumps in the end of BB1 and BB2.
1741 Return true if they are identical. */
1742 {
dfe08bc4 1743 rtx_insn *label1, *label2;
8942ee0f 1744 rtx_jump_table_data *table1, *table2;
39811184 1745
a813c111
SB
1746 if (tablejump_p (BB_END (bb1), &label1, &table1)
1747 && tablejump_p (BB_END (bb2), &label2, &table2)
39811184
JZ
1748 && GET_CODE (PATTERN (table1)) == GET_CODE (PATTERN (table2)))
1749 {
1750 /* The labels should never be the same rtx. If they really are same
1751 the jump tables are same too. So disable crossjumping of blocks BB1
1752 and BB2 because when deleting the common insns in the end of BB1
6de9cd9a 1753 by delete_basic_block () the jump table would be deleted too. */
4af16369 1754 /* If LABEL2 is referenced in BB1->END do not do anything
39811184
JZ
1755 because we would loose information when replacing
1756 LABEL1 by LABEL2 and then LABEL2 by LABEL1 in BB1->END. */
a813c111 1757 if (label1 != label2 && !rtx_referenced_p (label2, BB_END (bb1)))
39811184
JZ
1758 {
1759 /* Set IDENTICAL to true when the tables are identical. */
1760 bool identical = false;
1761 rtx p1, p2;
1762
1763 p1 = PATTERN (table1);
1764 p2 = PATTERN (table2);
1765 if (GET_CODE (p1) == ADDR_VEC && rtx_equal_p (p1, p2))
1766 {
1767 identical = true;
1768 }
1769 else if (GET_CODE (p1) == ADDR_DIFF_VEC
1770 && (XVECLEN (p1, 1) == XVECLEN (p2, 1))
1771 && rtx_equal_p (XEXP (p1, 2), XEXP (p2, 2))
1772 && rtx_equal_p (XEXP (p1, 3), XEXP (p2, 3)))
1773 {
1774 int i;
1775
1776 identical = true;
1777 for (i = XVECLEN (p1, 1) - 1; i >= 0 && identical; i--)
1778 if (!rtx_equal_p (XVECEXP (p1, 1, i), XVECEXP (p2, 1, i)))
1779 identical = false;
1780 }
1781
c2fc5456 1782 if (identical)
39811184 1783 {
39811184
JZ
1784 bool match;
1785
c2fc5456 1786 /* Temporarily replace references to LABEL1 with LABEL2
39811184 1787 in BB1->END so that we could compare the instructions. */
a2b7026c 1788 replace_label_in_insn (BB_END (bb1), label1, label2, false);
39811184 1789
472c95f5
TV
1790 match = (old_insns_match_p (mode, BB_END (bb1), BB_END (bb2))
1791 == dir_both);
c263766c
RH
1792 if (dump_file && match)
1793 fprintf (dump_file,
39811184
JZ
1794 "Tablejumps in bb %i and %i match.\n",
1795 bb1->index, bb2->index);
1796
c2fc5456
R
1797 /* Set the original label in BB1->END because when deleting
1798 a block whose end is a tablejump, the tablejump referenced
1799 from the instruction is deleted too. */
a2b7026c 1800 replace_label_in_insn (BB_END (bb1), label2, label1, false);
c2fc5456 1801
39811184
JZ
1802 return match;
1803 }
1804 }
1805 return false;
1806 }
1807 }
39811184 1808
d41d6122
TJ
1809 /* Find the last non-debug non-note instruction in each bb, except
1810 stop when we see the NOTE_INSN_BASIC_BLOCK, as old_insns_match_p
1811 handles that case specially. old_insns_match_p does not handle
1812 other types of instruction notes. */
da5477a9
DM
1813 rtx_insn *last1 = BB_END (bb1);
1814 rtx_insn *last2 = BB_END (bb2);
d41d6122
TJ
1815 while (!NOTE_INSN_BASIC_BLOCK_P (last1) &&
1816 (DEBUG_INSN_P (last1) || NOTE_P (last1)))
1817 last1 = PREV_INSN (last1);
1818 while (!NOTE_INSN_BASIC_BLOCK_P (last2) &&
1819 (DEBUG_INSN_P (last2) || NOTE_P (last2)))
1820 last2 = PREV_INSN (last2);
1821 gcc_assert (last1 && last2);
1822
0dd0e980 1823 /* First ensure that the instructions match. There may be many outgoing
39811184 1824 edges so this test is generally cheaper. */
206604dc 1825 if (old_insns_match_p (mode, last1, last2) != dir_both)
0dd0e980
JH
1826 return false;
1827
1828 /* Search the outgoing edges, ensure that the counts do match, find possible
1829 fallthru and exception handling edges since these needs more
1830 validation. */
628f6a4e
BE
1831 if (EDGE_COUNT (bb1->succs) != EDGE_COUNT (bb2->succs))
1832 return false;
1833
206604dc 1834 bool nonfakeedges = false;
628f6a4e 1835 FOR_EACH_EDGE (e1, ei, bb1->succs)
0dd0e980 1836 {
628f6a4e 1837 e2 = EDGE_SUCC (bb2, ei.index);
c22cacf3 1838
206604dc
JJ
1839 if ((e1->flags & EDGE_FAKE) == 0)
1840 nonfakeedges = true;
1841
0dd0e980
JH
1842 if (e1->flags & EDGE_EH)
1843 nehedges1++;
5f0d2358 1844
0dd0e980
JH
1845 if (e2->flags & EDGE_EH)
1846 nehedges2++;
5f0d2358 1847
0dd0e980
JH
1848 if (e1->flags & EDGE_FALLTHRU)
1849 fallthru1 = e1;
1850 if (e2->flags & EDGE_FALLTHRU)
1851 fallthru2 = e2;
1852 }
5f0d2358 1853
0dd0e980 1854 /* If number of edges of various types does not match, fail. */
628f6a4e 1855 if (nehedges1 != nehedges2
5f0d2358 1856 || (fallthru1 != 0) != (fallthru2 != 0))
0dd0e980
JH
1857 return false;
1858
206604dc
JJ
1859 /* If !ACCUMULATE_OUTGOING_ARGS, bb1 (and bb2) have no successors
1860 and the last real insn doesn't have REG_ARGS_SIZE note, don't
1861 attempt to optimize, as the two basic blocks might have different
1862 REG_ARGS_SIZE depths. For noreturn calls and unconditional
1863 traps there should be REG_ARG_SIZE notes, they could be missing
1864 for __builtin_unreachable () uses though. */
1865 if (!nonfakeedges
1866 && !ACCUMULATE_OUTGOING_ARGS
1867 && (!INSN_P (last1)
1868 || !find_reg_note (last1, REG_ARGS_SIZE, NULL)))
1869 return false;
1870
0dd0e980
JH
1871 /* fallthru edges must be forwarded to the same destination. */
1872 if (fallthru1)
1873 {
1874 basic_block d1 = (forwarder_block_p (fallthru1->dest)
c5cbcccf 1875 ? single_succ (fallthru1->dest): fallthru1->dest);
0dd0e980 1876 basic_block d2 = (forwarder_block_p (fallthru2->dest)
c5cbcccf 1877 ? single_succ (fallthru2->dest): fallthru2->dest);
5f0d2358 1878
0dd0e980
JH
1879 if (d1 != d2)
1880 return false;
1881 }
5f0d2358 1882
5f77fbd4
JJ
1883 /* Ensure the same EH region. */
1884 {
a813c111
SB
1885 rtx n1 = find_reg_note (BB_END (bb1), REG_EH_REGION, 0);
1886 rtx n2 = find_reg_note (BB_END (bb2), REG_EH_REGION, 0);
5f0d2358 1887
5f77fbd4
JJ
1888 if (!n1 && n2)
1889 return false;
1890
1891 if (n1 && (!n2 || XEXP (n1, 0) != XEXP (n2, 0)))
1892 return false;
1893 }
5f0d2358 1894
38109dab
GL
1895 /* The same checks as in try_crossjump_to_edge. It is required for RTL
1896 version of sequence abstraction. */
1897 FOR_EACH_EDGE (e1, ei, bb2->succs)
1898 {
1899 edge e2;
1900 edge_iterator ei;
1901 basic_block d1 = e1->dest;
1902
1903 if (FORWARDER_BLOCK_P (d1))
1904 d1 = EDGE_SUCC (d1, 0)->dest;
1905
1906 FOR_EACH_EDGE (e2, ei, bb1->succs)
1907 {
1908 basic_block d2 = e2->dest;
1909 if (FORWARDER_BLOCK_P (d2))
1910 d2 = EDGE_SUCC (d2, 0)->dest;
1911 if (d1 == d2)
1912 break;
1913 }
1914
1915 if (!e2)
1916 return false;
1917 }
1918
0dd0e980 1919 return true;
402209ff
JH
1920}
1921
38109dab
GL
1922/* Returns true if BB basic block has a preserve label. */
1923
1924static bool
1925block_has_preserve_label (basic_block bb)
1926{
1927 return (bb
1928 && block_label (bb)
1929 && LABEL_PRESERVE_P (block_label (bb)));
1930}
1931
402209ff
JH
1932/* E1 and E2 are edges with the same destination block. Search their
1933 predecessors for common code. If found, redirect control flow from
bf22920b
TV
1934 (maybe the middle of) E1->SRC to (maybe the middle of) E2->SRC (dir_forward),
1935 or the other way around (dir_backward). DIR specifies the allowed
1936 replacement direction. */
402209ff
JH
1937
1938static bool
bf22920b
TV
1939try_crossjump_to_edge (int mode, edge e1, edge e2,
1940 enum replace_direction dir)
402209ff 1941{
c2fc5456 1942 int nmatch;
402209ff 1943 basic_block src1 = e1->src, src2 = e2->src;
39587bb9 1944 basic_block redirect_to, redirect_from, to_remove;
823918ae 1945 basic_block osrc1, osrc2, redirect_edges_to, tmp;
da5477a9 1946 rtx_insn *newpos1, *newpos2;
402209ff 1947 edge s;
628f6a4e 1948 edge_iterator ei;
c2fc5456 1949
da5477a9 1950 newpos1 = newpos2 = NULL;
6de9cd9a 1951
402209ff
JH
1952 /* Search backward through forwarder blocks. We don't need to worry
1953 about multiple entry or chained forwarders, as they will be optimized
1954 away. We do this to look past the unconditional jump following a
1955 conditional jump that is required due to the current CFG shape. */
c5cbcccf 1956 if (single_pred_p (src1)
635559ab 1957 && FORWARDER_BLOCK_P (src1))
c5cbcccf 1958 e1 = single_pred_edge (src1), src1 = e1->src;
5f0d2358 1959
c5cbcccf 1960 if (single_pred_p (src2)
635559ab 1961 && FORWARDER_BLOCK_P (src2))
c5cbcccf 1962 e2 = single_pred_edge (src2), src2 = e2->src;
402209ff
JH
1963
1964 /* Nothing to do if we reach ENTRY, or a common source block. */
fefa31b5
DM
1965 if (src1 == ENTRY_BLOCK_PTR_FOR_FN (cfun) || src2
1966 == ENTRY_BLOCK_PTR_FOR_FN (cfun))
402209ff
JH
1967 return false;
1968 if (src1 == src2)
1969 return false;
1970
1971 /* Seeing more than 1 forwarder blocks would confuse us later... */
635559ab 1972 if (FORWARDER_BLOCK_P (e1->dest)
c5cbcccf 1973 && FORWARDER_BLOCK_P (single_succ (e1->dest)))
402209ff 1974 return false;
5f0d2358 1975
635559ab 1976 if (FORWARDER_BLOCK_P (e2->dest)
c5cbcccf 1977 && FORWARDER_BLOCK_P (single_succ (e2->dest)))
402209ff
JH
1978 return false;
1979
1980 /* Likewise with dead code (possibly newly created by the other optimizations
1981 of cfg_cleanup). */
628f6a4e 1982 if (EDGE_COUNT (src1->preds) == 0 || EDGE_COUNT (src2->preds) == 0)
402209ff
JH
1983 return false;
1984
ba61fc53
JH
1985 /* Do not turn corssing edge to non-crossing or vice versa after reload. */
1986 if (BB_PARTITION (src1) != BB_PARTITION (src2)
1987 && reload_completed)
1988 return false;
1989
402209ff 1990 /* Look for the common insn sequence, part the first ... */
c2fc5456 1991 if (!outgoing_edges_match (mode, src1, src2))
402209ff
JH
1992 return false;
1993
1994 /* ... and part the second. */
472c95f5 1995 nmatch = flow_find_cross_jump (src1, src2, &newpos1, &newpos2, &dir);
12183e0f 1996
823918ae
TV
1997 osrc1 = src1;
1998 osrc2 = src2;
1999 if (newpos1 != NULL_RTX)
2000 src1 = BLOCK_FOR_INSN (newpos1);
2001 if (newpos2 != NULL_RTX)
2002 src2 = BLOCK_FOR_INSN (newpos2);
2003
dd68669b
JL
2004 /* Check that SRC1 and SRC2 have preds again. They may have changed
2005 above due to the call to flow_find_cross_jump. */
2006 if (EDGE_COUNT (src1->preds) == 0 || EDGE_COUNT (src2->preds) == 0)
2007 return false;
2008
bf22920b
TV
2009 if (dir == dir_backward)
2010 {
ba61fc53
JH
2011 std::swap (osrc1, osrc2);
2012 std::swap (src1, src2);
2013 std::swap (e1, e2);
2014 std::swap (newpos1, newpos2);
bf22920b
TV
2015 }
2016
12183e0f
PH
2017 /* Don't proceed with the crossjump unless we found a sufficient number
2018 of matching instructions or the 'from' block was totally matched
2019 (such that its predecessors will hopefully be redirected and the
2020 block removed). */
c2fc5456
R
2021 if ((nmatch < PARAM_VALUE (PARAM_MIN_CROSSJUMP_INSNS))
2022 && (newpos1 != BB_HEAD (src1)))
7d22e898 2023 return false;
402209ff 2024
75c40d56 2025 /* Avoid deleting preserve label when redirecting ABNORMAL edges. */
38109dab
GL
2026 if (block_has_preserve_label (e1->dest)
2027 && (e1->flags & EDGE_ABNORMAL))
2028 return false;
2029
39811184
JZ
2030 /* Here we know that the insns in the end of SRC1 which are common with SRC2
2031 will be deleted.
2032 If we have tablejumps in the end of SRC1 and SRC2
2033 they have been already compared for equivalence in outgoing_edges_match ()
2034 so replace the references to TABLE1 by references to TABLE2. */
21c0a521 2035 {
dfe08bc4 2036 rtx_insn *label1, *label2;
8942ee0f 2037 rtx_jump_table_data *table1, *table2;
39811184 2038
823918ae
TV
2039 if (tablejump_p (BB_END (osrc1), &label1, &table1)
2040 && tablejump_p (BB_END (osrc2), &label2, &table2)
39811184
JZ
2041 && label1 != label2)
2042 {
da5477a9 2043 rtx_insn *insn;
39811184
JZ
2044
2045 /* Replace references to LABEL1 with LABEL2. */
39811184
JZ
2046 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2047 {
2048 /* Do not replace the label in SRC1->END because when deleting
2049 a block whose end is a tablejump, the tablejump referenced
2050 from the instruction is deleted too. */
823918ae 2051 if (insn != BB_END (osrc1))
a2b7026c 2052 replace_label_in_insn (insn, label1, label2, true);
39811184
JZ
2053 }
2054 }
21c0a521 2055 }
10d6c0d0 2056
b604fe9b
SB
2057 /* Avoid splitting if possible. We must always split when SRC2 has
2058 EH predecessor edges, or we may end up with basic blocks with both
2059 normal and EH predecessor edges. */
c2fc5456 2060 if (newpos2 == BB_HEAD (src2)
b604fe9b 2061 && !(EDGE_PRED (src2, 0)->flags & EDGE_EH))
402209ff
JH
2062 redirect_to = src2;
2063 else
2064 {
c2fc5456 2065 if (newpos2 == BB_HEAD (src2))
b604fe9b
SB
2066 {
2067 /* Skip possible basic block header. */
c2fc5456
R
2068 if (LABEL_P (newpos2))
2069 newpos2 = NEXT_INSN (newpos2);
b5b8b0ac
AO
2070 while (DEBUG_INSN_P (newpos2))
2071 newpos2 = NEXT_INSN (newpos2);
c2fc5456
R
2072 if (NOTE_P (newpos2))
2073 newpos2 = NEXT_INSN (newpos2);
b5b8b0ac
AO
2074 while (DEBUG_INSN_P (newpos2))
2075 newpos2 = NEXT_INSN (newpos2);
b604fe9b
SB
2076 }
2077
c263766c
RH
2078 if (dump_file)
2079 fprintf (dump_file, "Splitting bb %i before %i insns\n",
0b17ab2f 2080 src2->index, nmatch);
c2fc5456 2081 redirect_to = split_block (src2, PREV_INSN (newpos2))->dest;
402209ff
JH
2082 }
2083
c263766c 2084 if (dump_file)
c2fc5456
R
2085 fprintf (dump_file,
2086 "Cross jumping from bb %i to bb %i; %i common insns\n",
2087 src1->index, src2->index, nmatch);
402209ff 2088
6fc0bb99 2089 /* We may have some registers visible through the block. */
6fb5fa3c 2090 df_set_bb_dirty (redirect_to);
402209ff 2091
823918ae
TV
2092 if (osrc2 == src2)
2093 redirect_edges_to = redirect_to;
2094 else
2095 redirect_edges_to = osrc2;
2096
e7a74006 2097 /* Recompute the counts of destinations of outgoing edges. */
823918ae 2098 FOR_EACH_EDGE (s, ei, redirect_edges_to->succs)
402209ff
JH
2099 {
2100 edge s2;
628f6a4e 2101 edge_iterator ei;
402209ff
JH
2102 basic_block d = s->dest;
2103
635559ab 2104 if (FORWARDER_BLOCK_P (d))
c5cbcccf 2105 d = single_succ (d);
5f0d2358 2106
628f6a4e 2107 FOR_EACH_EDGE (s2, ei, src1->succs)
402209ff
JH
2108 {
2109 basic_block d2 = s2->dest;
635559ab 2110 if (FORWARDER_BLOCK_P (d2))
c5cbcccf 2111 d2 = single_succ (d2);
402209ff
JH
2112 if (d == d2)
2113 break;
2114 }
5f0d2358 2115
402209ff 2116 /* Take care to update possible forwarder blocks. We verified
c22cacf3
MS
2117 that there is no more than one in the chain, so we can't run
2118 into infinite loop. */
635559ab 2119 if (FORWARDER_BLOCK_P (s->dest))
e7a74006 2120 s->dest->count += s->count ();
5f0d2358 2121
635559ab 2122 if (FORWARDER_BLOCK_P (s2->dest))
e7a74006 2123 s2->dest->count -= s->count ();
5f0d2358 2124
97c07987
JH
2125 s->probability = s->probability.combine_with_count
2126 (redirect_edges_to->count,
2127 s2->probability, src1->count);
402209ff
JH
2128 }
2129
e7a74006 2130 /* Adjust count for the block. An earlier jump
52982a97
EB
2131 threading pass may have left the profile in an inconsistent
2132 state (see update_bb_profile_for_threading) so we must be
2133 prepared for overflows. */
823918ae
TV
2134 tmp = redirect_to;
2135 do
2136 {
2137 tmp->count += src1->count;
823918ae
TV
2138 if (tmp == redirect_edges_to)
2139 break;
2140 tmp = find_fallthru_edge (tmp->succs)->dest;
2141 }
2142 while (true);
2143 update_br_prob_note (redirect_edges_to);
402209ff
JH
2144
2145 /* Edit SRC1 to go to REDIRECT_TO at NEWPOS1. */
2146
c2fc5456
R
2147 /* Skip possible basic block header. */
2148 if (LABEL_P (newpos1))
2149 newpos1 = NEXT_INSN (newpos1);
b5b8b0ac
AO
2150
2151 while (DEBUG_INSN_P (newpos1))
2152 newpos1 = NEXT_INSN (newpos1);
2153
cd9c1ca8 2154 if (NOTE_INSN_BASIC_BLOCK_P (newpos1))
c2fc5456
R
2155 newpos1 = NEXT_INSN (newpos1);
2156
b5b8b0ac
AO
2157 while (DEBUG_INSN_P (newpos1))
2158 newpos1 = NEXT_INSN (newpos1);
2159
c2fc5456 2160 redirect_from = split_block (src1, PREV_INSN (newpos1))->src;
c5cbcccf 2161 to_remove = single_succ (redirect_from);
402209ff 2162
c5cbcccf 2163 redirect_edge_and_branch_force (single_succ_edge (redirect_from), redirect_to);
f470c378 2164 delete_basic_block (to_remove);
402209ff 2165
39587bb9 2166 update_forwarder_flag (redirect_from);
7cbd12b8
JJ
2167 if (redirect_to != src2)
2168 update_forwarder_flag (src2);
635559ab 2169
402209ff
JH
2170 return true;
2171}
2172
2173/* Search the predecessors of BB for common insn sequences. When found,
2174 share code between them by redirecting control flow. Return true if
2175 any changes made. */
2176
2177static bool
d329e058 2178try_crossjump_bb (int mode, basic_block bb)
402209ff 2179{
628f6a4e 2180 edge e, e2, fallthru;
402209ff 2181 bool changed;
628f6a4e 2182 unsigned max, ix, ix2;
402209ff 2183
f63d1bf7 2184 /* Nothing to do if there is not at least two incoming edges. */
628f6a4e 2185 if (EDGE_COUNT (bb->preds) < 2)
402209ff
JH
2186 return false;
2187
bbcb0c05
SB
2188 /* Don't crossjump if this block ends in a computed jump,
2189 unless we are optimizing for size. */
efd8f750 2190 if (optimize_bb_for_size_p (bb)
fefa31b5 2191 && bb != EXIT_BLOCK_PTR_FOR_FN (cfun)
bbcb0c05
SB
2192 && computed_jump_p (BB_END (bb)))
2193 return false;
2194
750054a2
CT
2195 /* If we are partitioning hot/cold basic blocks, we don't want to
2196 mess up unconditional or indirect jumps that cross between hot
c22cacf3
MS
2197 and cold sections.
2198
8e8d5162 2199 Basic block partitioning may result in some jumps that appear to
c22cacf3
MS
2200 be optimizable (or blocks that appear to be mergeable), but which really
2201 must be left untouched (they are required to make it safely across
2202 partition boundaries). See the comments at the top of
8e8d5162
CT
2203 bb-reorder.c:partition_hot_cold_basic_blocks for complete details. */
2204
c22cacf3
MS
2205 if (BB_PARTITION (EDGE_PRED (bb, 0)->src) !=
2206 BB_PARTITION (EDGE_PRED (bb, 1)->src)
87c8b4be 2207 || (EDGE_PRED (bb, 0)->flags & EDGE_CROSSING))
750054a2
CT
2208 return false;
2209
402209ff
JH
2210 /* It is always cheapest to redirect a block that ends in a branch to
2211 a block that falls through into BB, as that adds no branches to the
2212 program. We'll try that combination first. */
5f24e0dc
RH
2213 fallthru = NULL;
2214 max = PARAM_VALUE (PARAM_MAX_CROSSJUMP_EDGES);
628f6a4e
BE
2215
2216 if (EDGE_COUNT (bb->preds) > max)
2217 return false;
2218
0fd4b31d 2219 fallthru = find_fallthru_edge (bb->preds);
402209ff
JH
2220
2221 changed = false;
0248bceb 2222 for (ix = 0; ix < EDGE_COUNT (bb->preds);)
402209ff 2223 {
0248bceb 2224 e = EDGE_PRED (bb, ix);
628f6a4e 2225 ix++;
402209ff 2226
c1e3e2d9
SB
2227 /* As noted above, first try with the fallthru predecessor (or, a
2228 fallthru predecessor if we are in cfglayout mode). */
402209ff
JH
2229 if (fallthru)
2230 {
2231 /* Don't combine the fallthru edge into anything else.
2232 If there is a match, we'll do it the other way around. */
2233 if (e == fallthru)
2234 continue;
7cf240d5
JH
2235 /* If nothing changed since the last attempt, there is nothing
2236 we can do. */
2237 if (!first_pass
4ec5d4f5
BS
2238 && !((e->src->flags & BB_MODIFIED)
2239 || (fallthru->src->flags & BB_MODIFIED)))
7cf240d5 2240 continue;
402209ff 2241
bf22920b 2242 if (try_crossjump_to_edge (mode, e, fallthru, dir_forward))
402209ff
JH
2243 {
2244 changed = true;
628f6a4e 2245 ix = 0;
402209ff
JH
2246 continue;
2247 }
2248 }
2249
2250 /* Non-obvious work limiting check: Recognize that we're going
2251 to call try_crossjump_bb on every basic block. So if we have
2252 two blocks with lots of outgoing edges (a switch) and they
2253 share lots of common destinations, then we would do the
2254 cross-jump check once for each common destination.
2255
2256 Now, if the blocks actually are cross-jump candidates, then
2257 all of their destinations will be shared. Which means that
2258 we only need check them for cross-jump candidacy once. We
2259 can eliminate redundant checks of crossjump(A,B) by arbitrarily
2260 choosing to do the check from the block for which the edge
2261 in question is the first successor of A. */
628f6a4e 2262 if (EDGE_SUCC (e->src, 0) != e)
402209ff
JH
2263 continue;
2264
0248bceb 2265 for (ix2 = 0; ix2 < EDGE_COUNT (bb->preds); ix2++)
402209ff 2266 {
0248bceb 2267 e2 = EDGE_PRED (bb, ix2);
402209ff
JH
2268
2269 if (e2 == e)
2270 continue;
2271
2272 /* We've already checked the fallthru edge above. */
2273 if (e2 == fallthru)
2274 continue;
2275
402209ff
JH
2276 /* The "first successor" check above only prevents multiple
2277 checks of crossjump(A,B). In order to prevent redundant
2278 checks of crossjump(B,A), require that A be the block
2279 with the lowest index. */
0b17ab2f 2280 if (e->src->index > e2->src->index)
402209ff
JH
2281 continue;
2282
7cf240d5
JH
2283 /* If nothing changed since the last attempt, there is nothing
2284 we can do. */
2285 if (!first_pass
4ec5d4f5
BS
2286 && !((e->src->flags & BB_MODIFIED)
2287 || (e2->src->flags & BB_MODIFIED)))
7cf240d5
JH
2288 continue;
2289
bf22920b
TV
2290 /* Both e and e2 are not fallthru edges, so we can crossjump in either
2291 direction. */
2292 if (try_crossjump_to_edge (mode, e, e2, dir_both))
402209ff
JH
2293 {
2294 changed = true;
628f6a4e 2295 ix = 0;
402209ff
JH
2296 break;
2297 }
2298 }
2299 }
2300
c1e3e2d9 2301 if (changed)
bd2c6270 2302 crossjumps_occurred = true;
c1e3e2d9 2303
402209ff
JH
2304 return changed;
2305}
2306
4ec5d4f5
BS
2307/* Search the successors of BB for common insn sequences. When found,
2308 share code between them by moving it across the basic block
2309 boundary. Return true if any changes made. */
2310
2311static bool
2312try_head_merge_bb (basic_block bb)
2313{
2314 basic_block final_dest_bb = NULL;
2315 int max_match = INT_MAX;
2316 edge e0;
da5477a9 2317 rtx_insn **headptr, **currptr, **nextptr;
4ec5d4f5
BS
2318 bool changed, moveall;
2319 unsigned ix;
da5477a9 2320 rtx_insn *e0_last_head;
61aa0978
DM
2321 rtx cond;
2322 rtx_insn *move_before;
4ec5d4f5 2323 unsigned nedges = EDGE_COUNT (bb->succs);
da5477a9 2324 rtx_insn *jump = BB_END (bb);
4ec5d4f5
BS
2325 regset live, live_union;
2326
2327 /* Nothing to do if there is not at least two outgoing edges. */
2328 if (nedges < 2)
2329 return false;
2330
2331 /* Don't crossjump if this block ends in a computed jump,
2332 unless we are optimizing for size. */
2333 if (optimize_bb_for_size_p (bb)
fefa31b5 2334 && bb != EXIT_BLOCK_PTR_FOR_FN (cfun)
4ec5d4f5
BS
2335 && computed_jump_p (BB_END (bb)))
2336 return false;
2337
2338 cond = get_condition (jump, &move_before, true, false);
2339 if (cond == NULL_RTX)
43052d45 2340 {
618f4073 2341 if (HAVE_cc0 && reg_mentioned_p (cc0_rtx, jump))
43052d45
BS
2342 move_before = prev_nonnote_nondebug_insn (jump);
2343 else
43052d45
BS
2344 move_before = jump;
2345 }
4ec5d4f5
BS
2346
2347 for (ix = 0; ix < nedges; ix++)
fefa31b5 2348 if (EDGE_SUCC (bb, ix)->dest == EXIT_BLOCK_PTR_FOR_FN (cfun))
4ec5d4f5
BS
2349 return false;
2350
2351 for (ix = 0; ix < nedges; ix++)
2352 {
2353 edge e = EDGE_SUCC (bb, ix);
2354 basic_block other_bb = e->dest;
2355
2356 if (df_get_bb_dirty (other_bb))
2357 {
2358 block_was_dirty = true;
2359 return false;
2360 }
2361
2362 if (e->flags & EDGE_ABNORMAL)
2363 return false;
2364
2365 /* Normally, all destination blocks must only be reachable from this
2366 block, i.e. they must have one incoming edge.
2367
2368 There is one special case we can handle, that of multiple consecutive
2369 jumps where the first jumps to one of the targets of the second jump.
2370 This happens frequently in switch statements for default labels.
2371 The structure is as follows:
2372 FINAL_DEST_BB
2373 ....
2374 if (cond) jump A;
2375 fall through
2376 BB
2377 jump with targets A, B, C, D...
2378 A
2379 has two incoming edges, from FINAL_DEST_BB and BB
2380
2381 In this case, we can try to move the insns through BB and into
2382 FINAL_DEST_BB. */
2383 if (EDGE_COUNT (other_bb->preds) != 1)
2384 {
2385 edge incoming_edge, incoming_bb_other_edge;
2386 edge_iterator ei;
2387
2388 if (final_dest_bb != NULL
2389 || EDGE_COUNT (other_bb->preds) != 2)
2390 return false;
2391
2392 /* We must be able to move the insns across the whole block. */
2393 move_before = BB_HEAD (bb);
2394 while (!NONDEBUG_INSN_P (move_before))
2395 move_before = NEXT_INSN (move_before);
2396
2397 if (EDGE_COUNT (bb->preds) != 1)
2398 return false;
2399 incoming_edge = EDGE_PRED (bb, 0);
2400 final_dest_bb = incoming_edge->src;
2401 if (EDGE_COUNT (final_dest_bb->succs) != 2)
2402 return false;
2403 FOR_EACH_EDGE (incoming_bb_other_edge, ei, final_dest_bb->succs)
2404 if (incoming_bb_other_edge != incoming_edge)
2405 break;
2406 if (incoming_bb_other_edge->dest != other_bb)
2407 return false;
2408 }
2409 }
2410
2411 e0 = EDGE_SUCC (bb, 0);
da5477a9 2412 e0_last_head = NULL;
4ec5d4f5
BS
2413 changed = false;
2414
2415 for (ix = 1; ix < nedges; ix++)
2416 {
2417 edge e = EDGE_SUCC (bb, ix);
da5477a9 2418 rtx_insn *e0_last, *e_last;
4ec5d4f5
BS
2419 int nmatch;
2420
2421 nmatch = flow_find_head_matching_sequence (e0->dest, e->dest,
2422 &e0_last, &e_last, 0);
2423 if (nmatch == 0)
2424 return false;
2425
2426 if (nmatch < max_match)
2427 {
2428 max_match = nmatch;
2429 e0_last_head = e0_last;
2430 }
2431 }
2432
2433 /* If we matched an entire block, we probably have to avoid moving the
2434 last insn. */
2435 if (max_match > 0
2436 && e0_last_head == BB_END (e0->dest)
2437 && (find_reg_note (e0_last_head, REG_EH_REGION, 0)
2438 || control_flow_insn_p (e0_last_head)))
2439 {
2440 max_match--;
2441 if (max_match == 0)
2442 return false;
ec2d7121 2443 e0_last_head = prev_real_nondebug_insn (e0_last_head);
4ec5d4f5
BS
2444 }
2445
2446 if (max_match == 0)
2447 return false;
2448
2449 /* We must find a union of the live registers at each of the end points. */
2450 live = BITMAP_ALLOC (NULL);
2451 live_union = BITMAP_ALLOC (NULL);
2452
da5477a9
DM
2453 currptr = XNEWVEC (rtx_insn *, nedges);
2454 headptr = XNEWVEC (rtx_insn *, nedges);
2455 nextptr = XNEWVEC (rtx_insn *, nedges);
4ec5d4f5
BS
2456
2457 for (ix = 0; ix < nedges; ix++)
2458 {
2459 int j;
2460 basic_block merge_bb = EDGE_SUCC (bb, ix)->dest;
da5477a9 2461 rtx_insn *head = BB_HEAD (merge_bb);
4ec5d4f5 2462
b59e0455
JJ
2463 while (!NONDEBUG_INSN_P (head))
2464 head = NEXT_INSN (head);
4ec5d4f5
BS
2465 headptr[ix] = head;
2466 currptr[ix] = head;
2467
2468 /* Compute the end point and live information */
2469 for (j = 1; j < max_match; j++)
b59e0455
JJ
2470 do
2471 head = NEXT_INSN (head);
2472 while (!NONDEBUG_INSN_P (head));
4ec5d4f5
BS
2473 simulate_backwards_to_point (merge_bb, live, head);
2474 IOR_REG_SET (live_union, live);
2475 }
2476
2477 /* If we're moving across two blocks, verify the validity of the
2478 first move, then adjust the target and let the loop below deal
2479 with the final move. */
2480 if (final_dest_bb != NULL)
2481 {
61aa0978 2482 rtx_insn *move_upto;
4ec5d4f5
BS
2483
2484 moveall = can_move_insns_across (currptr[0], e0_last_head, move_before,
2485 jump, e0->dest, live_union,
2486 NULL, &move_upto);
2487 if (!moveall)
2488 {
2489 if (move_upto == NULL_RTX)
2490 goto out;
2491
2492 while (e0_last_head != move_upto)
2493 {
2494 df_simulate_one_insn_backwards (e0->dest, e0_last_head,
2495 live_union);
2496 e0_last_head = PREV_INSN (e0_last_head);
2497 }
2498 }
2499 if (e0_last_head == NULL_RTX)
2500 goto out;
2501
2502 jump = BB_END (final_dest_bb);
2503 cond = get_condition (jump, &move_before, true, false);
2504 if (cond == NULL_RTX)
43052d45 2505 {
618f4073 2506 if (HAVE_cc0 && reg_mentioned_p (cc0_rtx, jump))
43052d45
BS
2507 move_before = prev_nonnote_nondebug_insn (jump);
2508 else
43052d45
BS
2509 move_before = jump;
2510 }
4ec5d4f5
BS
2511 }
2512
2513 do
2514 {
61aa0978 2515 rtx_insn *move_upto;
4ec5d4f5
BS
2516 moveall = can_move_insns_across (currptr[0], e0_last_head,
2517 move_before, jump, e0->dest, live_union,
2518 NULL, &move_upto);
2519 if (!moveall && move_upto == NULL_RTX)
2520 {
2521 if (jump == move_before)
2522 break;
2523
2524 /* Try again, using a different insertion point. */
2525 move_before = jump;
2526
4ec5d4f5
BS
2527 /* Don't try moving before a cc0 user, as that may invalidate
2528 the cc0. */
618f4073 2529 if (HAVE_cc0 && reg_mentioned_p (cc0_rtx, jump))
4ec5d4f5 2530 break;
4ec5d4f5
BS
2531
2532 continue;
2533 }
2534
2535 if (final_dest_bb && !moveall)
2536 /* We haven't checked whether a partial move would be OK for the first
2537 move, so we have to fail this case. */
2538 break;
2539
2540 changed = true;
2541 for (;;)
2542 {
2543 if (currptr[0] == move_upto)
2544 break;
2545 for (ix = 0; ix < nedges; ix++)
2546 {
da5477a9 2547 rtx_insn *curr = currptr[ix];
4ec5d4f5
BS
2548 do
2549 curr = NEXT_INSN (curr);
2550 while (!NONDEBUG_INSN_P (curr));
2551 currptr[ix] = curr;
2552 }
2553 }
2554
2555 /* If we can't currently move all of the identical insns, remember
2556 each insn after the range that we'll merge. */
2557 if (!moveall)
2558 for (ix = 0; ix < nedges; ix++)
2559 {
da5477a9 2560 rtx_insn *curr = currptr[ix];
4ec5d4f5
BS
2561 do
2562 curr = NEXT_INSN (curr);
2563 while (!NONDEBUG_INSN_P (curr));
2564 nextptr[ix] = curr;
2565 }
2566
2567 reorder_insns (headptr[0], currptr[0], PREV_INSN (move_before));
2568 df_set_bb_dirty (EDGE_SUCC (bb, 0)->dest);
2569 if (final_dest_bb != NULL)
2570 df_set_bb_dirty (final_dest_bb);
2571 df_set_bb_dirty (bb);
2572 for (ix = 1; ix < nedges; ix++)
2573 {
2574 df_set_bb_dirty (EDGE_SUCC (bb, ix)->dest);
2575 delete_insn_chain (headptr[ix], currptr[ix], false);
2576 }
2577 if (!moveall)
2578 {
2579 if (jump == move_before)
2580 break;
2581
2582 /* For the unmerged insns, try a different insertion point. */
2583 move_before = jump;
2584
4ec5d4f5
BS
2585 /* Don't try moving before a cc0 user, as that may invalidate
2586 the cc0. */
618f4073 2587 if (HAVE_cc0 && reg_mentioned_p (cc0_rtx, jump))
4ec5d4f5 2588 break;
4ec5d4f5
BS
2589
2590 for (ix = 0; ix < nedges; ix++)
2591 currptr[ix] = headptr[ix] = nextptr[ix];
2592 }
2593 }
2594 while (!moveall);
2595
2596 out:
2597 free (currptr);
2598 free (headptr);
2599 free (nextptr);
2600
bd2c6270 2601 crossjumps_occurred |= changed;
4ec5d4f5
BS
2602
2603 return changed;
2604}
2605
7752e522
JJ
2606/* Return true if BB contains just bb note, or bb note followed
2607 by only DEBUG_INSNs. */
2608
2609static bool
2610trivially_empty_bb_p (basic_block bb)
2611{
da5477a9 2612 rtx_insn *insn = BB_END (bb);
7752e522
JJ
2613
2614 while (1)
2615 {
2616 if (insn == BB_HEAD (bb))
2617 return true;
2618 if (!DEBUG_INSN_P (insn))
2619 return false;
2620 insn = PREV_INSN (insn);
2621 }
2622}
2623
45676a7c
SB
2624/* Return true if BB contains just a return and possibly a USE of the
2625 return value. Fill in *RET and *USE with the return and use insns
2ea0d750 2626 if any found, otherwise NULL. All CLOBBERs are ignored. */
45676a7c
SB
2627
2628static bool
2629bb_is_just_return (basic_block bb, rtx_insn **ret, rtx_insn **use)
2630{
2631 *ret = *use = NULL;
2632 rtx_insn *insn;
2633
2634 if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun))
2635 return false;
2636
2637 FOR_BB_INSNS (bb, insn)
2638 if (NONDEBUG_INSN_P (insn))
2639 {
2ea0d750
SB
2640 rtx pat = PATTERN (insn);
2641
2642 if (!*ret && ANY_RETURN_P (pat))
45676a7c 2643 *ret = insn;
2ea0d750
SB
2644 else if (!*ret && !*use && GET_CODE (pat) == USE
2645 && REG_P (XEXP (pat, 0))
2646 && REG_FUNCTION_VALUE_P (XEXP (pat, 0)))
45676a7c 2647 *use = insn;
2ea0d750 2648 else if (GET_CODE (pat) != CLOBBER)
45676a7c
SB
2649 return false;
2650 }
2651
2652 return !!*ret;
2653}
2654
402209ff
JH
2655/* Do simple CFG optimizations - basic block merging, simplifying of jump
2656 instructions etc. Return nonzero if changes were made. */
2657
2658static bool
d329e058 2659try_optimize_cfg (int mode)
402209ff 2660{
402209ff
JH
2661 bool changed_overall = false;
2662 bool changed;
2663 int iterations = 0;
ec3ae3da 2664 basic_block bb, b, next;
402209ff 2665
6fb5fa3c 2666 if (mode & (CLEANUP_CROSSJUMP | CLEANUP_THREADING))
38c1593d
JH
2667 clear_bb_flags ();
2668
bd2c6270 2669 crossjumps_occurred = false;
c1e3e2d9 2670
11cd3bed 2671 FOR_EACH_BB_FN (bb, cfun)
2dd2d53e
SB
2672 update_forwarder_flag (bb);
2673
245f1bfa 2674 if (! targetm.cannot_modify_jumps_p ())
402209ff 2675 {
7cf240d5 2676 first_pass = true;
e4ec2cac
AO
2677 /* Attempt to merge blocks as made possible by edge removal. If
2678 a block has only one successor, and the successor has only
2679 one predecessor, they may be combined. */
2680 do
402209ff 2681 {
4ec5d4f5 2682 block_was_dirty = false;
e4ec2cac
AO
2683 changed = false;
2684 iterations++;
2685
c263766c
RH
2686 if (dump_file)
2687 fprintf (dump_file,
e4ec2cac
AO
2688 "\n\ntry_optimize_cfg iteration %i\n\n",
2689 iterations);
402209ff 2690
fefa31b5
DM
2691 for (b = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb; b
2692 != EXIT_BLOCK_PTR_FOR_FN (cfun);)
402209ff 2693 {
e0082a72 2694 basic_block c;
e4ec2cac
AO
2695 edge s;
2696 bool changed_here = false;
5f0d2358 2697
468059bc
DD
2698 /* Delete trivially dead basic blocks. This is either
2699 blocks with no predecessors, or empty blocks with no
1e211590
DD
2700 successors. However if the empty block with no
2701 successors is the successor of the ENTRY_BLOCK, it is
2702 kept. This ensures that the ENTRY_BLOCK will have a
2703 successor which is a precondition for many RTL
2704 passes. Empty blocks may result from expanding
468059bc
DD
2705 __builtin_unreachable (). */
2706 if (EDGE_COUNT (b->preds) == 0
1e211590 2707 || (EDGE_COUNT (b->succs) == 0
7752e522 2708 && trivially_empty_bb_p (b)
fefa31b5
DM
2709 && single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun))->dest
2710 != b))
e4ec2cac 2711 {
f6366fc7 2712 c = b->prev_bb;
f1de5107 2713 if (EDGE_COUNT (b->preds) > 0)
3b5fda81
JJ
2714 {
2715 edge e;
2716 edge_iterator ei;
2717
f1de5107
JJ
2718 if (current_ir_type () == IR_RTL_CFGLAYOUT)
2719 {
c758576a
JJ
2720 rtx_insn *insn;
2721 for (insn = BB_FOOTER (b);
2722 insn; insn = NEXT_INSN (insn))
2723 if (BARRIER_P (insn))
2724 break;
2725 if (insn)
f1de5107 2726 FOR_EACH_EDGE (e, ei, b->preds)
c758576a 2727 if ((e->flags & EDGE_FALLTHRU))
f1de5107 2728 {
c758576a
JJ
2729 if (BB_FOOTER (b)
2730 && BB_FOOTER (e->src) == NULL)
f1de5107 2731 {
d8ce2eae
DM
2732 BB_FOOTER (e->src) = BB_FOOTER (b);
2733 BB_FOOTER (b) = NULL;
f1de5107
JJ
2734 }
2735 else
c758576a 2736 emit_barrier_after_bb (e->src);
f1de5107
JJ
2737 }
2738 }
2739 else
2740 {
da5477a9 2741 rtx_insn *last = get_last_bb_insn (b);
f1de5107
JJ
2742 if (last && BARRIER_P (last))
2743 FOR_EACH_EDGE (e, ei, b->preds)
2744 if ((e->flags & EDGE_FALLTHRU))
2745 emit_barrier_after (BB_END (e->src));
2746 }
3b5fda81 2747 }
f470c378 2748 delete_basic_block (b);
bef16e87 2749 changed = true;
6626665f 2750 /* Avoid trying to remove the exit block. */
fefa31b5 2751 b = (c == ENTRY_BLOCK_PTR_FOR_FN (cfun) ? c->next_bb : c);
83bd032b 2752 continue;
e4ec2cac 2753 }
402209ff 2754
6ce2bcb7 2755 /* Remove code labels no longer used. */
c5cbcccf
ZD
2756 if (single_pred_p (b)
2757 && (single_pred_edge (b)->flags & EDGE_FALLTHRU)
2758 && !(single_pred_edge (b)->flags & EDGE_COMPLEX)
4b4bf941 2759 && LABEL_P (BB_HEAD (b))
6c979aa1 2760 && !LABEL_PRESERVE_P (BB_HEAD (b))
e4ec2cac
AO
2761 /* If the previous block ends with a branch to this
2762 block, we can't delete the label. Normally this
2763 is a condjump that is yet to be simplified, but
2764 if CASE_DROPS_THRU, this can be a tablejump with
2765 some element going to the same place as the
2766 default (fallthru). */
fefa31b5 2767 && (single_pred (b) == ENTRY_BLOCK_PTR_FOR_FN (cfun)
c5cbcccf 2768 || !JUMP_P (BB_END (single_pred (b)))
a813c111 2769 || ! label_is_jump_target_p (BB_HEAD (b),
c5cbcccf 2770 BB_END (single_pred (b)))))
e4ec2cac 2771 {
03fbe718 2772 delete_insn (BB_HEAD (b));
c263766c
RH
2773 if (dump_file)
2774 fprintf (dump_file, "Deleted label in block %i.\n",
0b17ab2f 2775 b->index);
e4ec2cac 2776 }
402209ff 2777
e4ec2cac 2778 /* If we fall through an empty block, we can remove it. */
9be94227 2779 if (!(mode & (CLEANUP_CFGLAYOUT | CLEANUP_NO_INSN_DEL))
c5cbcccf
ZD
2780 && single_pred_p (b)
2781 && (single_pred_edge (b)->flags & EDGE_FALLTHRU)
4b4bf941 2782 && !LABEL_P (BB_HEAD (b))
e4ec2cac
AO
2783 && FORWARDER_BLOCK_P (b)
2784 /* Note that forwarder_block_p true ensures that
2785 there is a successor for this block. */
c5cbcccf 2786 && (single_succ_edge (b)->flags & EDGE_FALLTHRU)
0cae8d31 2787 && n_basic_blocks_for_fn (cfun) > NUM_FIXED_BLOCKS + 1)
e4ec2cac 2788 {
c263766c
RH
2789 if (dump_file)
2790 fprintf (dump_file,
e4ec2cac 2791 "Deleting fallthru block %i.\n",
0b17ab2f 2792 b->index);
e4ec2cac 2793
fefa31b5
DM
2794 c = ((b->prev_bb == ENTRY_BLOCK_PTR_FOR_FN (cfun))
2795 ? b->next_bb : b->prev_bb);
c5cbcccf
ZD
2796 redirect_edge_succ_nodup (single_pred_edge (b),
2797 single_succ (b));
f470c378 2798 delete_basic_block (b);
e4ec2cac
AO
2799 changed = true;
2800 b = c;
1e211590 2801 continue;
e4ec2cac 2802 }
5f0d2358 2803
50a36e42 2804 /* Merge B with its single successor, if any. */
c5cbcccf
ZD
2805 if (single_succ_p (b)
2806 && (s = single_succ_edge (b))
ec3ae3da 2807 && !(s->flags & EDGE_COMPLEX)
fefa31b5 2808 && (c = s->dest) != EXIT_BLOCK_PTR_FOR_FN (cfun)
c5cbcccf 2809 && single_pred_p (c)
bc35512f
JH
2810 && b != c)
2811 {
2812 /* When not in cfg_layout mode use code aware of reordering
2813 INSN. This code possibly creates new basic blocks so it
2814 does not fit merge_blocks interface and is kept here in
2815 hope that it will become useless once more of compiler
2816 is transformed to use cfg_layout mode. */
c22cacf3 2817
bc35512f
JH
2818 if ((mode & CLEANUP_CFGLAYOUT)
2819 && can_merge_blocks_p (b, c))
2820 {
2821 merge_blocks (b, c);
2822 update_forwarder_flag (b);
2823 changed_here = true;
2824 }
2825 else if (!(mode & CLEANUP_CFGLAYOUT)
2826 /* If the jump insn has side effects,
2827 we can't kill the edge. */
4b4bf941 2828 && (!JUMP_P (BB_END (b))
e24e7211 2829 || (reload_completed
a813c111 2830 ? simplejump_p (BB_END (b))
e4efa971
JH
2831 : (onlyjump_p (BB_END (b))
2832 && !tablejump_p (BB_END (b),
2833 NULL, NULL))))
bc35512f
JH
2834 && (next = merge_blocks_move (s, b, c, mode)))
2835 {
2836 b = next;
2837 changed_here = true;
2838 }
ec3ae3da 2839 }
e4ec2cac 2840
45676a7c
SB
2841 /* Try to change a branch to a return to just that return. */
2842 rtx_insn *ret, *use;
2843 if (single_succ_p (b)
2844 && onlyjump_p (BB_END (b))
2845 && bb_is_just_return (single_succ (b), &ret, &use))
2846 {
2847 if (redirect_jump (as_a <rtx_jump_insn *> (BB_END (b)),
2848 PATTERN (ret), 0))
2849 {
2850 if (use)
2851 emit_insn_before (copy_insn (PATTERN (use)),
2852 BB_END (b));
2853 if (dump_file)
2854 fprintf (dump_file, "Changed jump %d->%d to return.\n",
2855 b->index, single_succ (b)->index);
2856 redirect_edge_succ (single_succ_edge (b),
2857 EXIT_BLOCK_PTR_FOR_FN (cfun));
2858 single_succ_edge (b)->flags &= ~EDGE_CROSSING;
2859 changed_here = true;
2860 }
2861 }
2862
2863 /* Try to change a conditional branch to a return to the
2864 respective conditional return. */
2865 if (EDGE_COUNT (b->succs) == 2
2866 && any_condjump_p (BB_END (b))
2867 && bb_is_just_return (BRANCH_EDGE (b)->dest, &ret, &use))
2868 {
2869 if (redirect_jump (as_a <rtx_jump_insn *> (BB_END (b)),
2870 PATTERN (ret), 0))
2871 {
2872 if (use)
2873 emit_insn_before (copy_insn (PATTERN (use)),
2874 BB_END (b));
2875 if (dump_file)
2876 fprintf (dump_file, "Changed conditional jump %d->%d "
2877 "to conditional return.\n",
2878 b->index, BRANCH_EDGE (b)->dest->index);
2879 redirect_edge_succ (BRANCH_EDGE (b),
2880 EXIT_BLOCK_PTR_FOR_FN (cfun));
2881 BRANCH_EDGE (b)->flags &= ~EDGE_CROSSING;
2882 changed_here = true;
2883 }
2884 }
2885
2886 /* Try to flip a conditional branch that falls through to
2887 a return so that it becomes a conditional return and a
2888 new jump to the original branch target. */
2889 if (EDGE_COUNT (b->succs) == 2
ac2a4c0d 2890 && BRANCH_EDGE (b)->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)
45676a7c
SB
2891 && any_condjump_p (BB_END (b))
2892 && bb_is_just_return (FALLTHRU_EDGE (b)->dest, &ret, &use))
2893 {
2894 if (invert_jump (as_a <rtx_jump_insn *> (BB_END (b)),
2895 JUMP_LABEL (BB_END (b)), 0))
2896 {
2897 basic_block new_ft = BRANCH_EDGE (b)->dest;
2898 if (redirect_jump (as_a <rtx_jump_insn *> (BB_END (b)),
2899 PATTERN (ret), 0))
2900 {
2901 if (use)
2902 emit_insn_before (copy_insn (PATTERN (use)),
2903 BB_END (b));
2904 if (dump_file)
2905 fprintf (dump_file, "Changed conditional jump "
2906 "%d->%d to conditional return, adding "
2907 "fall-through jump.\n",
2908 b->index, BRANCH_EDGE (b)->dest->index);
2909 redirect_edge_succ (BRANCH_EDGE (b),
2910 EXIT_BLOCK_PTR_FOR_FN (cfun));
2911 BRANCH_EDGE (b)->flags &= ~EDGE_CROSSING;
2912 std::swap (BRANCH_EDGE (b)->probability,
2913 FALLTHRU_EDGE (b)->probability);
2914 update_br_prob_note (b);
2915 basic_block jb = force_nonfallthru (FALLTHRU_EDGE (b));
2916 notice_new_block (jb);
2917 if (!redirect_jump (as_a <rtx_jump_insn *> (BB_END (jb)),
2918 block_label (new_ft), 0))
2919 gcc_unreachable ();
2920 redirect_edge_succ (single_succ_edge (jb), new_ft);
2921 changed_here = true;
2922 }
2923 else
2924 {
2925 /* Invert the jump back to what it was. This should
2926 never fail. */
2927 if (!invert_jump (as_a <rtx_jump_insn *> (BB_END (b)),
2928 JUMP_LABEL (BB_END (b)), 0))
2929 gcc_unreachable ();
2930 }
2931 }
2932 }
2933
e4ec2cac 2934 /* Simplify branch over branch. */
bc35512f
JH
2935 if ((mode & CLEANUP_EXPENSIVE)
2936 && !(mode & CLEANUP_CFGLAYOUT)
2937 && try_simplify_condjump (b))
38c1593d 2938 changed_here = true;
402209ff 2939
e4ec2cac
AO
2940 /* If B has a single outgoing edge, but uses a
2941 non-trivial jump instruction without side-effects, we
2942 can either delete the jump entirely, or replace it
3348b696 2943 with a simple unconditional jump. */
c5cbcccf 2944 if (single_succ_p (b)
fefa31b5 2945 && single_succ (b) != EXIT_BLOCK_PTR_FOR_FN (cfun)
a813c111 2946 && onlyjump_p (BB_END (b))
339ba33b 2947 && !CROSSING_JUMP_P (BB_END (b))
c5cbcccf
ZD
2948 && try_redirect_by_replacing_jump (single_succ_edge (b),
2949 single_succ (b),
20b4e8ae 2950 (mode & CLEANUP_CFGLAYOUT) != 0))
e4ec2cac 2951 {
e4ec2cac
AO
2952 update_forwarder_flag (b);
2953 changed_here = true;
2954 }
402209ff 2955
e4ec2cac
AO
2956 /* Simplify branch to branch. */
2957 if (try_forward_edges (mode, b))
afe8b6ec
EB
2958 {
2959 update_forwarder_flag (b);
2960 changed_here = true;
2961 }
402209ff 2962
e4ec2cac
AO
2963 /* Look for shared code between blocks. */
2964 if ((mode & CLEANUP_CROSSJUMP)
2965 && try_crossjump_bb (mode, b))
2966 changed_here = true;
402209ff 2967
4ec5d4f5
BS
2968 if ((mode & CLEANUP_CROSSJUMP)
2969 /* This can lengthen register lifetimes. Do it only after
2970 reload. */
2971 && reload_completed
2972 && try_head_merge_bb (b))
2973 changed_here = true;
2974
e4ec2cac
AO
2975 /* Don't get confused by the index shift caused by
2976 deleting blocks. */
2977 if (!changed_here)
e0082a72 2978 b = b->next_bb;
e4ec2cac
AO
2979 else
2980 changed = true;
2981 }
402209ff 2982
e4ec2cac 2983 if ((mode & CLEANUP_CROSSJUMP)
fefa31b5 2984 && try_crossjump_bb (mode, EXIT_BLOCK_PTR_FOR_FN (cfun)))
402209ff 2985 changed = true;
402209ff 2986
4ec5d4f5
BS
2987 if (block_was_dirty)
2988 {
2989 /* This should only be set by head-merging. */
2990 gcc_assert (mode & CLEANUP_CROSSJUMP);
2991 df_analyze ();
2992 }
2993
e4ec2cac 2994 if (changed)
600b5b1d
TJ
2995 {
2996 /* Edge forwarding in particular can cause hot blocks previously
2997 reached by both hot and cold blocks to become dominated only
2998 by cold blocks. This will cause the verification below to fail,
2999 and lead to now cold code in the hot section. This is not easy
3000 to detect and fix during edge forwarding, and in some cases
3001 is only visible after newly unreachable blocks are deleted,
3002 which will be done in fixup_partitions. */
3ff0dc17 3003 if ((mode & CLEANUP_NO_PARTITIONING) == 0)
3211aea2
JH
3004 {
3005 fixup_partitions ();
3006 checking_verify_flow_info ();
3007 }
600b5b1d 3008 }
402209ff 3009
e4ec2cac 3010 changed_overall |= changed;
7cf240d5 3011 first_pass = false;
e4ec2cac
AO
3012 }
3013 while (changed);
402209ff 3014 }
ca6c03ca 3015
04a90bec 3016 FOR_ALL_BB_FN (b, cfun)
2dd2d53e 3017 b->flags &= ~(BB_FORWARDER_BLOCK | BB_NONTHREADABLE_BLOCK);
635559ab 3018
402209ff
JH
3019 return changed_overall;
3020}
3021\f
6d2f8887 3022/* Delete all unreachable basic blocks. */
4262e623 3023
969d70ca 3024bool
d329e058 3025delete_unreachable_blocks (void)
402209ff 3026{
402209ff 3027 bool changed = false;
b5b8b0ac 3028 basic_block b, prev_bb;
402209ff
JH
3029
3030 find_unreachable_blocks ();
3031
65f4b875
AO
3032 /* When we're in GIMPLE mode and there may be debug bind insns, we
3033 should delete blocks in reverse dominator order, so as to get a
3034 chance to substitute all released DEFs into debug bind stmts. If
3035 we don't have dominators information, walking blocks backward
3036 gets us a better chance of retaining most debug information than
b5b8b0ac 3037 otherwise. */
65f4b875 3038 if (MAY_HAVE_DEBUG_BIND_INSNS && current_ir_type () == IR_GIMPLE
b5b8b0ac 3039 && dom_info_available_p (CDI_DOMINATORS))
402209ff 3040 {
fefa31b5
DM
3041 for (b = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb;
3042 b != ENTRY_BLOCK_PTR_FOR_FN (cfun); b = prev_bb)
b5b8b0ac
AO
3043 {
3044 prev_bb = b->prev_bb;
3045
3046 if (!(b->flags & BB_REACHABLE))
3047 {
3048 /* Speed up the removal of blocks that don't dominate
3049 others. Walking backwards, this should be the common
3050 case. */
3051 if (!first_dom_son (CDI_DOMINATORS, b))
3052 delete_basic_block (b);
3053 else
3054 {
9771b263 3055 vec<basic_block> h
b5b8b0ac
AO
3056 = get_all_dominated_blocks (CDI_DOMINATORS, b);
3057
9771b263 3058 while (h.length ())
b5b8b0ac 3059 {
9771b263 3060 b = h.pop ();
b5b8b0ac
AO
3061
3062 prev_bb = b->prev_bb;
0b17ab2f 3063
b5b8b0ac
AO
3064 gcc_assert (!(b->flags & BB_REACHABLE));
3065
3066 delete_basic_block (b);
3067 }
3068
9771b263 3069 h.release ();
b5b8b0ac
AO
3070 }
3071
3072 changed = true;
3073 }
3074 }
3075 }
3076 else
3077 {
fefa31b5
DM
3078 for (b = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb;
3079 b != ENTRY_BLOCK_PTR_FOR_FN (cfun); b = prev_bb)
6a58eee9 3080 {
b5b8b0ac
AO
3081 prev_bb = b->prev_bb;
3082
3083 if (!(b->flags & BB_REACHABLE))
3084 {
3085 delete_basic_block (b);
3086 changed = true;
3087 }
6a58eee9 3088 }
402209ff
JH
3089 }
3090
3091 if (changed)
3092 tidy_fallthru_edges ();
3093 return changed;
3094}
6fb5fa3c
DB
3095
3096/* Delete any jump tables never referenced. We can't delete them at the
29f3fd5b
SB
3097 time of removing tablejump insn as they are referenced by the preceding
3098 insns computing the destination, so we delay deleting and garbagecollect
3099 them once life information is computed. */
6fb5fa3c
DB
3100void
3101delete_dead_jumptables (void)
3102{
3103 basic_block bb;
3104
29f3fd5b
SB
3105 /* A dead jump table does not belong to any basic block. Scan insns
3106 between two adjacent basic blocks. */
11cd3bed 3107 FOR_EACH_BB_FN (bb, cfun)
6fb5fa3c 3108 {
da5477a9 3109 rtx_insn *insn, *next;
29f3fd5b
SB
3110
3111 for (insn = NEXT_INSN (BB_END (bb));
3112 insn && !NOTE_INSN_BASIC_BLOCK_P (insn);
3113 insn = next)
57d6c446 3114 {
29f3fd5b
SB
3115 next = NEXT_INSN (insn);
3116 if (LABEL_P (insn)
3117 && LABEL_NUSES (insn) == LABEL_PRESERVE_P (insn)
3118 && JUMP_TABLE_DATA_P (next))
3119 {
da5477a9 3120 rtx_insn *label = insn, *jump = next;
29f3fd5b
SB
3121
3122 if (dump_file)
3123 fprintf (dump_file, "Dead jumptable %i removed\n",
3124 INSN_UID (insn));
3125
3126 next = NEXT_INSN (next);
3127 delete_insn (jump);
3128 delete_insn (label);
3129 }
6fb5fa3c
DB
3130 }
3131 }
3132}
3133
402209ff
JH
3134\f
3135/* Tidy the CFG by deleting unreachable code and whatnot. */
3136
3137bool
d329e058 3138cleanup_cfg (int mode)
402209ff 3139{
402209ff
JH
3140 bool changed = false;
3141
aeceeb06
SB
3142 /* Set the cfglayout mode flag here. We could update all the callers
3143 but that is just inconvenient, especially given that we eventually
3144 want to have cfglayout mode as the default. */
3145 if (current_ir_type () == IR_RTL_CFGLAYOUT)
3146 mode |= CLEANUP_CFGLAYOUT;
3147
402209ff 3148 timevar_push (TV_CLEANUP_CFG);
3dec4024
JH
3149 if (delete_unreachable_blocks ())
3150 {
3151 changed = true;
3152 /* We've possibly created trivially dead code. Cleanup it right
95bd1dd7 3153 now to introduce more opportunities for try_optimize_cfg. */
6fb5fa3c 3154 if (!(mode & (CLEANUP_NO_INSN_DEL))
3dec4024 3155 && !reload_completed)
62e5bf5d 3156 delete_trivially_dead_insns (get_insns (), max_reg_num ());
3dec4024 3157 }
bf77398c
ZD
3158
3159 compact_blocks ();
3160
c1e3e2d9
SB
3161 /* To tail-merge blocks ending in the same noreturn function (e.g.
3162 a call to abort) we have to insert fake edges to exit. Do this
3163 here once. The fake edges do not interfere with any other CFG
3164 cleanups. */
3165 if (mode & CLEANUP_CROSSJUMP)
3166 add_noreturn_fake_exit_edges ();
3167
7d817ebc
DE
3168 if (!dbg_cnt (cfg_cleanup))
3169 return changed;
3170
3dec4024
JH
3171 while (try_optimize_cfg (mode))
3172 {
3173 delete_unreachable_blocks (), changed = true;
c1e3e2d9 3174 if (!(mode & CLEANUP_NO_INSN_DEL))
3dec4024 3175 {
c1e3e2d9
SB
3176 /* Try to remove some trivially dead insns when doing an expensive
3177 cleanup. But delete_trivially_dead_insns doesn't work after
3178 reload (it only handles pseudos) and run_fast_dce is too costly
3179 to run in every iteration.
3180
3181 For effective cross jumping, we really want to run a fast DCE to
3182 clean up any dead conditions, or they get in the way of performing
3183 useful tail merges.
3184
3185 Other transformations in cleanup_cfg are not so sensitive to dead
3186 code, so delete_trivially_dead_insns or even doing nothing at all
3187 is good enough. */
3188 if ((mode & CLEANUP_EXPENSIVE) && !reload_completed
3189 && !delete_trivially_dead_insns (get_insns (), max_reg_num ()))
3dec4024 3190 break;
bd2c6270 3191 if ((mode & CLEANUP_CROSSJUMP) && crossjumps_occurred)
f1f10541
RS
3192 {
3193 run_fast_dce ();
3194 mode &= ~CLEANUP_FORCE_FAST_DCE;
3195 }
3dec4024
JH
3196 }
3197 else
3198 break;
3dec4024 3199 }
402209ff 3200
c1e3e2d9
SB
3201 if (mode & CLEANUP_CROSSJUMP)
3202 remove_fake_exit_edges ();
3203
f1f10541
RS
3204 if (mode & CLEANUP_FORCE_FAST_DCE)
3205 run_fast_dce ();
3206
29f3fd5b
SB
3207 /* Don't call delete_dead_jumptables in cfglayout mode, because
3208 that function assumes that jump tables are in the insns stream.
3209 But we also don't _have_ to delete dead jumptables in cfglayout
3210 mode because we shouldn't even be looking at things that are
3211 not in a basic block. Dead jumptables are cleaned up when
3212 going out of cfglayout mode. */
3213 if (!(mode & CLEANUP_CFGLAYOUT))
6fb5fa3c
DB
3214 delete_dead_jumptables ();
3215
7d776ee2
RG
3216 /* ??? We probably do this way too often. */
3217 if (current_loops
3218 && (changed
3219 || (mode & CLEANUP_CFG_CHANGED)))
3220 {
7d776ee2
RG
3221 timevar_push (TV_REPAIR_LOOPS);
3222 /* The above doesn't preserve dominance info if available. */
3223 gcc_assert (!dom_info_available_p (CDI_DOMINATORS));
3224 calculate_dominance_info (CDI_DOMINATORS);
01cb1ef5 3225 fix_loop_structure (NULL);
7d776ee2
RG
3226 free_dominance_info (CDI_DOMINATORS);
3227 timevar_pop (TV_REPAIR_LOOPS);
3228 }
3229
402209ff
JH
3230 timevar_pop (TV_CLEANUP_CFG);
3231
402209ff
JH
3232 return changed;
3233}
ef330312 3234\f
27a4cd48
DM
3235namespace {
3236
3237const pass_data pass_data_jump =
11a687e7 3238{
27a4cd48
DM
3239 RTL_PASS, /* type */
3240 "jump", /* name */
3241 OPTGROUP_NONE, /* optinfo_flags */
27a4cd48
DM
3242 TV_JUMP, /* tv_id */
3243 0, /* properties_required */
3244 0, /* properties_provided */
3245 0, /* properties_destroyed */
3246 0, /* todo_flags_start */
3bea341f 3247 0, /* todo_flags_finish */
11a687e7 3248};
27a4cd48
DM
3249
3250class pass_jump : public rtl_opt_pass
3251{
3252public:
c3284718
RS
3253 pass_jump (gcc::context *ctxt)
3254 : rtl_opt_pass (pass_data_jump, ctxt)
27a4cd48
DM
3255 {}
3256
3257 /* opt_pass methods: */
be55bfe6 3258 virtual unsigned int execute (function *);
27a4cd48
DM
3259
3260}; // class pass_jump
3261
be55bfe6
TS
3262unsigned int
3263pass_jump::execute (function *)
3264{
3265 delete_trivially_dead_insns (get_insns (), max_reg_num ());
3266 if (dump_file)
3267 dump_flow_info (dump_file, dump_flags);
3268 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0)
3269 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3270 return 0;
3271}
3272
27a4cd48
DM
3273} // anon namespace
3274
3275rtl_opt_pass *
3276make_pass_jump (gcc::context *ctxt)
3277{
3278 return new pass_jump (ctxt);
3279}
11a687e7 3280\f
27a4cd48
DM
3281namespace {
3282
98fe146e
IL
3283const pass_data pass_data_postreload_jump =
3284{
3285 RTL_PASS, /* type */
3286 "postreload_jump", /* name */
3287 OPTGROUP_NONE, /* optinfo_flags */
3288 TV_JUMP, /* tv_id */
3289 0, /* properties_required */
3290 0, /* properties_provided */
3291 0, /* properties_destroyed */
3292 0, /* todo_flags_start */
3293 0, /* todo_flags_finish */
3294};
3295
3296class pass_postreload_jump : public rtl_opt_pass
3297{
3298public:
3299 pass_postreload_jump (gcc::context *ctxt)
3300 : rtl_opt_pass (pass_data_postreload_jump, ctxt)
3301 {}
3302
3303 /* opt_pass methods: */
3304 virtual unsigned int execute (function *);
3305
3306}; // class pass_postreload_jump
3307
3308unsigned int
3309pass_postreload_jump::execute (function *)
3310{
3311 cleanup_cfg (flag_thread_jumps ? CLEANUP_THREADING : 0);
3312 return 0;
3313}
3314
3315} // anon namespace
3316
3317rtl_opt_pass *
3318make_pass_postreload_jump (gcc::context *ctxt)
3319{
3320 return new pass_postreload_jump (ctxt);
3321}
3322
3323namespace {
3324
27a4cd48 3325const pass_data pass_data_jump2 =
ef330312 3326{
27a4cd48
DM
3327 RTL_PASS, /* type */
3328 "jump2", /* name */
3329 OPTGROUP_NONE, /* optinfo_flags */
27a4cd48
DM
3330 TV_JUMP, /* tv_id */
3331 0, /* properties_required */
3332 0, /* properties_provided */
3333 0, /* properties_destroyed */
3334 0, /* todo_flags_start */
3bea341f 3335 0, /* todo_flags_finish */
ef330312 3336};
27a4cd48
DM
3337
3338class pass_jump2 : public rtl_opt_pass
3339{
3340public:
c3284718
RS
3341 pass_jump2 (gcc::context *ctxt)
3342 : rtl_opt_pass (pass_data_jump2, ctxt)
27a4cd48
DM
3343 {}
3344
3345 /* opt_pass methods: */
be55bfe6
TS
3346 virtual unsigned int execute (function *)
3347 {
3348 cleanup_cfg (flag_crossjumping ? CLEANUP_CROSSJUMP : 0);
3349 return 0;
3350 }
27a4cd48
DM
3351
3352}; // class pass_jump2
3353
3354} // anon namespace
3355
3356rtl_opt_pass *
3357make_pass_jump2 (gcc::context *ctxt)
3358{
3359 return new pass_jump2 (ctxt);
3360}