2 * branch-opts.c: Branch optimizations support
5 * Patrik Torstensson (Patrik.Torstesson at gmail.com)
7 * (C) 2005 Ximian, Inc. http://www.ximian.com
15 * Returns true if @bb is a basic block which falls through the next block.
16 * TODO verify if it helps to check if the bb last ins is a branch to its successor.
19 mono_bb_is_fall_through (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
21 return bb
->next_bb
&& bb
->next_bb
->region
== bb
->region
&& /*fall throught between regions is not really interesting or useful*/
22 (bb
->last_ins
== NULL
|| !MONO_IS_BRANCH_OP (bb
->last_ins
)); /*and the last op can't be a branch too*/
26 * Used by the arch code to replace the exception handling
27 * with a direct branch. This is safe to do if the
28 * exception object isn't used, no rethrow statement and
29 * no filter statement (verify).
33 mono_branch_optimize_exception_target (MonoCompile
*cfg
, MonoBasicBlock
*bb
, const char * exname
)
35 MonoMethod
*method
= cfg
->method
;
36 MonoMethodHeader
*header
= mono_method_get_header (method
);
37 MonoExceptionClause
*clause
;
41 if (!(cfg
->opt
& MONO_OPT_EXCEPTION
))
44 if (bb
->region
== -1 || !MONO_BBLOCK_IS_IN_REGION (bb
, MONO_REGION_TRY
))
47 exclass
= mono_class_from_name (mono_get_corlib (), "System", exname
);
48 /* search for the handler */
49 for (i
= 0; i
< header
->num_clauses
; ++i
) {
50 clause
= &header
->clauses
[i
];
51 if (MONO_OFFSET_IN_CLAUSE (clause
, bb
->real_offset
)) {
52 if (clause
->flags
== MONO_EXCEPTION_CLAUSE_NONE
&& clause
->data
.catch_class
&& mono_class_is_assignable_from (clause
->data
.catch_class
, exclass
)) {
55 /* get the basic block for the handler and
56 * check if the exception object is used.
57 * Flag is set during method_to_ir due to
58 * pop-op is optmized away in codegen (burg).
60 tbb
= cfg
->cil_offset_to_bb
[clause
->handler_offset
];
61 if (tbb
&& tbb
->flags
& BB_EXCEPTION_DEAD_OBJ
&& !(tbb
->flags
& BB_EXCEPTION_UNSAFE
)) {
62 MonoBasicBlock
*targetbb
= tbb
;
63 gboolean unsafe
= FALSE
;
65 /* Check if this catch clause is ok to optimize by
66 * looking for the BB_EXCEPTION_UNSAFE in every BB that
67 * belongs to the same region.
69 * UNSAFE flag is set during method_to_ir (OP_RETHROW)
71 while (!unsafe
&& tbb
->next_bb
&& tbb
->region
== tbb
->next_bb
->region
) {
72 if (tbb
->next_bb
->flags
& BB_EXCEPTION_UNSAFE
) {
82 /* Create dummy inst to allow easier integration in
83 * arch dependent code (opcode ignored)
85 MONO_INST_NEW (cfg
, jump
, OP_BR
);
87 /* Allocate memory for our branch target */
88 jump
->inst_i1
= mono_mempool_alloc0 (cfg
->mempool
, sizeof (MonoInst
));
89 jump
->inst_true_bb
= targetbb
;
91 if (cfg
->verbose_level
> 2)
92 g_print ("found exception to optimize - returning branch to BB%d (%s) (instead of throw) for method %s:%s\n", targetbb
->block_num
, clause
->data
.catch_class
->name
, cfg
->method
->klass
->name
, cfg
->method
->name
);
100 /* Branching to an outer clause could skip inner clauses */
109 static const int int_cmov_opcodes
[] = {
122 static const int long_cmov_opcodes
[] = {
136 br_to_br_un (int opcode
)
152 g_assert_not_reached ();
160 * Replace INS with its decomposition which is stored in a series of bblocks starting
161 * at FIRST_BB and ending at LAST_BB. On enter, PREV points to the predecessor of INS.
162 * On return, it will be set to the last ins of the decomposition.
165 mono_replace_ins (MonoCompile
*cfg
, MonoBasicBlock
*bb
, MonoInst
*ins
, MonoInst
**prev
, MonoBasicBlock
*first_bb
, MonoBasicBlock
*last_bb
)
167 MonoInst
*next
= ins
->next
;
169 if (next
&& next
->opcode
== OP_NOP
) {
170 /* Avoid NOPs following branches */
171 ins
->next
= next
->next
;
175 if (first_bb
== last_bb
) {
177 * Only one replacement bb, merge the code into
181 /* Delete links between the first_bb and its successors */
182 while (first_bb
->out_count
)
183 mono_unlink_bblock (cfg
, first_bb
, first_bb
->out_bb
[0]);
187 (*prev
)->next
= first_bb
->code
;
188 first_bb
->code
->prev
= (*prev
);
190 bb
->code
= first_bb
->code
;
194 last_bb
->last_ins
->next
= next
;
196 next
->prev
= last_bb
->last_ins
;
198 bb
->last_ins
= last_bb
->last_ins
;
199 *prev
= last_bb
->last_ins
;
200 bb
->has_array_access
|= first_bb
->has_array_access
;
203 MonoBasicBlock
**tmp_bblocks
, *tmp
;
209 for (tmp
= first_bb
; tmp
; tmp
= tmp
->next_bb
)
210 tmp
->region
= bb
->region
;
212 /* Split the original bb */
214 ins
->next
->prev
= NULL
;
218 /* Merge the second part of the original bb into the last bb */
219 if (last_bb
->last_ins
) {
220 last_bb
->last_ins
->next
= next
;
222 next
->prev
= last_bb
->last_ins
;
224 last_bb
->code
= next
;
226 last_bb
->has_array_access
|= bb
->has_array_access
;
229 for (last
= next
; last
->next
!= NULL
; last
= last
->next
)
231 last_bb
->last_ins
= last
;
234 for (i
= 0; i
< bb
->out_count
; ++i
)
235 mono_link_bblock (cfg
, last_bb
, bb
->out_bb
[i
]);
237 /* Merge the first (dummy) bb to the original bb */
239 (*prev
)->next
= first_bb
->code
;
240 first_bb
->code
->prev
= (*prev
);
242 bb
->code
= first_bb
->code
;
244 bb
->last_ins
= first_bb
->last_ins
;
245 bb
->has_array_access
|= first_bb
->has_array_access
;
247 /* Delete the links between the original bb and its successors */
248 tmp_bblocks
= bb
->out_bb
;
249 count
= bb
->out_count
;
250 for (i
= 0; i
< count
; ++i
)
251 mono_unlink_bblock (cfg
, bb
, tmp_bblocks
[i
]);
253 /* Add links between the original bb and the first_bb's successors */
254 for (i
= 0; i
< first_bb
->out_count
; ++i
) {
255 MonoBasicBlock
*out_bb
= first_bb
->out_bb
[i
];
257 mono_link_bblock (cfg
, bb
, out_bb
);
259 /* Delete links between the first_bb and its successors */
260 for (i
= 0; i
< bb
->out_count
; ++i
) {
261 MonoBasicBlock
*out_bb
= bb
->out_bb
[i
];
263 mono_unlink_bblock (cfg
, first_bb
, out_bb
);
265 last_bb
->next_bb
= bb
->next_bb
;
266 bb
->next_bb
= first_bb
->next_bb
;
273 mono_if_conversion (MonoCompile
*cfg
)
275 #ifdef MONO_ARCH_HAVE_CMOV_OPS
277 gboolean changed
= FALSE
;
279 if (!(cfg
->opt
& MONO_OPT_CMOV
))
282 // FIXME: Make this work with extended bblocks
285 * This pass requires somewhat optimized IR code so it should be run after
286 * local cprop/deadce. Also, it should be run before dominator computation, since
287 * it changes control flow.
289 for (bb
= cfg
->bb_entry
; bb
; bb
= bb
->next_bb
) {
290 MonoBasicBlock
*bb1
, *bb2
;
293 /* Look for the IR code generated from cond ? a : b
304 if (!(bb
->out_count
== 2 && !bb
->extended
))
307 bb1
= bb
->out_bb
[0];
308 bb2
= bb
->out_bb
[1];
310 if (bb1
->in_count
== 1 && bb2
->in_count
== 1 && bb1
->out_count
== 1 && bb2
->out_count
== 1 && bb1
->out_bb
[0] == bb2
->out_bb
[0]) {
311 MonoInst
*compare
, *branch
, *ins1
, *ins2
, *cmov
, *move
, *tmp
;
312 MonoBasicBlock
*true_bb
, *false_bb
;
313 gboolean simple
, ret
;
317 if (bb
->last_ins
&& (bb
->last_ins
->opcode
== OP_BR_REG
|| bb
->last_ins
->opcode
== OP_BR
))
320 /* Find the compare instruction */
321 if (!bb
->last_ins
|| !bb
->last_ins
->prev
)
323 branch
= bb
->last_ins
;
324 compare
= branch
->prev
;
326 if (!MONO_IS_COND_BRANCH_OP (branch
))
327 /* This can happen if a cond branch is optimized away */
330 true_bb
= branch
->inst_true_bb
;
331 false_bb
= branch
->inst_false_bb
;
334 * Check that bb1 and bb2 are 'simple' and both assign to the same
337 /* FIXME: Get rid of the nops earlier */
338 ins1
= true_bb
->code
;
339 while (ins1
&& ins1
->opcode
== OP_NOP
)
341 ins2
= false_bb
->code
;
342 while (ins2
&& ins2
->opcode
== OP_NOP
)
344 if (!(ins1
&& ins2
&& ins1
->dreg
== ins2
->dreg
&& ins1
->dreg
!= -1))
348 for (tmp
= ins1
->next
; tmp
; tmp
= tmp
->next
)
349 if (!((tmp
->opcode
== OP_NOP
) || (tmp
->opcode
== OP_BR
)))
352 for (tmp
= ins2
->next
; tmp
; tmp
= tmp
->next
)
353 if (!((tmp
->opcode
== OP_NOP
) || (tmp
->opcode
== OP_BR
)))
359 /* We move ins1/ins2 before the compare so they should have no side effect */
360 if (!(MONO_INS_HAS_NO_SIDE_EFFECT (ins1
) && MONO_INS_HAS_NO_SIDE_EFFECT (ins2
)))
363 /* Moving ins1/ins2 could change the comparison */
365 if (!((compare
->sreg1
!= ins1
->dreg
) && (compare
->sreg2
!= ins1
->dreg
)))
369 comp_type
= mono_opcode_to_type (branch
->opcode
, compare
->opcode
);
370 if (!((comp_type
== CMP_TYPE_I
) || (comp_type
== CMP_TYPE_L
)))
374 /* ins->type might not be set */
375 if (INS_INFO (ins1
->opcode
) [MONO_INST_DEST
] != 'i')
378 if (cfg
->verbose_level
> 2) {
379 printf ("\tBranch -> CMove optimization in BB%d on\n", bb
->block_num
);
380 printf ("\t\t"); mono_print_ins (compare
);
381 printf ("\t\t"); mono_print_ins (compare
->next
);
382 printf ("\t\t"); mono_print_ins (ins1
);
383 printf ("\t\t"); mono_print_ins (ins2
);
390 /* Assignments to the return register must remain at the end of bbs */
392 ret
= ins1
->dreg
== cfg
->ret
->dreg
;
396 tmp_reg
= mono_alloc_dreg (cfg
, STACK_I4
);
399 /* Rewrite ins1 to emit to tmp_reg */
400 ins1
->dreg
= tmp_reg
;
403 dreg
= mono_alloc_dreg (cfg
, STACK_I4
);
407 /* Remove ins1/ins2 from bb1/bb2 */
408 MONO_REMOVE_INS (true_bb
, ins1
);
409 MONO_REMOVE_INS (false_bb
, ins2
);
411 /* Move ins1 and ins2 before the comparison */
412 /* ins1 comes first to avoid ins1 overwriting an argument of ins2 */
413 mono_bblock_insert_before_ins (bb
, compare
, ins2
);
414 mono_bblock_insert_before_ins (bb
, ins2
, ins1
);
416 /* Add cmov instruction */
417 MONO_INST_NEW (cfg
, cmov
, OP_NOP
);
420 cmov
->sreg2
= tmp_reg
;
421 switch (mono_opcode_to_type (branch
->opcode
, compare
->opcode
)) {
423 cmov
->opcode
= int_cmov_opcodes
[mono_opcode_to_cond (branch
->opcode
)];
426 cmov
->opcode
= long_cmov_opcodes
[mono_opcode_to_cond (branch
->opcode
)];
429 g_assert_not_reached ();
431 mono_bblock_insert_after_ins (bb
, compare
, cmov
);
434 /* Add an extra move */
435 MONO_INST_NEW (cfg
, move
, OP_MOVE
);
436 move
->dreg
= cfg
->ret
->dreg
;
438 mono_bblock_insert_after_ins (bb
, cmov
, move
);
441 /* Rewrite the branch */
442 branch
->opcode
= OP_BR
;
443 branch
->inst_target_bb
= true_bb
->out_bb
[0];
444 mono_link_bblock (cfg
, bb
, branch
->inst_target_bb
);
446 /* Reorder bblocks */
447 mono_unlink_bblock (cfg
, bb
, true_bb
);
448 mono_unlink_bblock (cfg
, bb
, false_bb
);
449 mono_unlink_bblock (cfg
, true_bb
, true_bb
->out_bb
[0]);
450 mono_unlink_bblock (cfg
, false_bb
, false_bb
->out_bb
[0]);
451 mono_remove_bblock (cfg
, true_bb
);
452 mono_remove_bblock (cfg
, false_bb
);
454 /* Merge bb and its successor if possible */
455 if ((bb
->out_bb
[0]->in_count
== 1) && (bb
->out_bb
[0] != cfg
->bb_exit
) &&
456 (bb
->region
== bb
->out_bb
[0]->region
)) {
457 mono_merge_basic_blocks (cfg
, bb
, bb
->out_bb
[0]);
462 /* Look for the IR code generated from if (cond) <var> <- <a>
471 if ((bb2
->in_count
== 1 && bb2
->out_count
== 1 && bb2
->out_bb
[0] == bb1
) ||
472 (bb1
->in_count
== 1 && bb1
->out_count
== 1 && bb1
->out_bb
[0] == bb2
)) {
473 MonoInst
*compare
, *branch
, *ins1
, *cmov
, *tmp
;
478 MonoBasicBlock
*next_bb
, *code_bb
;
480 /* code_bb is the bblock containing code, next_bb is the successor bblock */
481 if (bb2
->in_count
== 1 && bb2
->out_count
== 1 && bb2
->out_bb
[0] == bb1
) {
489 ins1
= code_bb
->code
;
494 /* Check that code_bb is simple */
496 for (tmp
= ins1
->next
; tmp
; tmp
= tmp
->next
)
497 if (!((tmp
->opcode
== OP_NOP
) || (tmp
->opcode
== OP_BR
)))
503 /* We move ins1 before the compare so it should have no side effect */
504 if (!MONO_INS_HAS_NO_SIDE_EFFECT (ins1
))
507 if (bb
->last_ins
&& bb
->last_ins
->opcode
== OP_BR_REG
)
510 /* Find the compare instruction */
512 if (!bb
->last_ins
|| !bb
->last_ins
->prev
)
514 branch
= bb
->last_ins
;
515 compare
= branch
->prev
;
517 if (!MONO_IS_COND_BRANCH_OP (branch
))
518 /* This can happen if a cond branch is optimized away */
522 comp_type
= mono_opcode_to_type (branch
->opcode
, compare
->opcode
);
523 if (!((comp_type
== CMP_TYPE_I
) || (comp_type
== CMP_TYPE_L
)))
527 /* ins->type might not be set */
528 if (INS_INFO (ins1
->opcode
) [MONO_INST_DEST
] != 'i')
532 if (cfg
->ret
&& ins1
->dreg
== cfg
->ret
->dreg
)
535 if (cfg
->verbose_level
> 2) {
536 printf ("\tBranch -> CMove optimization (2) in BB%d on\n", bb
->block_num
);
537 printf ("\t\t"); mono_print_ins (compare
);
538 printf ("\t\t"); mono_print_ins (compare
->next
);
539 printf ("\t\t"); mono_print_ins (ins1
);
546 tmp_reg
= mono_alloc_dreg (cfg
, STACK_I4
);
549 /* Rewrite ins1 to emit to tmp_reg */
550 ins1
->dreg
= tmp_reg
;
552 /* Remove ins1 from code_bb */
553 MONO_REMOVE_INS (code_bb
, ins1
);
555 /* Move ins1 before the comparison */
556 mono_bblock_insert_before_ins (bb
, compare
, ins1
);
558 /* Add cmov instruction */
559 MONO_INST_NEW (cfg
, cmov
, OP_NOP
);
562 cmov
->sreg2
= tmp_reg
;
563 cond
= mono_opcode_to_cond (branch
->opcode
);
564 if (branch
->inst_false_bb
== code_bb
)
565 cond
= mono_negate_cond (cond
);
566 switch (mono_opcode_to_type (branch
->opcode
, compare
->opcode
)) {
568 cmov
->opcode
= int_cmov_opcodes
[cond
];
571 cmov
->opcode
= long_cmov_opcodes
[cond
];
574 g_assert_not_reached ();
576 mono_bblock_insert_after_ins (bb
, compare
, cmov
);
578 /* Rewrite the branch */
579 branch
->opcode
= OP_BR
;
580 branch
->inst_target_bb
= next_bb
;
581 mono_link_bblock (cfg
, bb
, branch
->inst_target_bb
);
583 /* Nullify the branch at the end of code_bb */
585 branch
= code_bb
->code
;
586 MONO_DELETE_INS (code_bb
, branch
);
589 /* Reorder bblocks */
590 mono_unlink_bblock (cfg
, bb
, code_bb
);
591 mono_unlink_bblock (cfg
, code_bb
, next_bb
);
593 /* Merge bb and its successor if possible */
594 if ((bb
->out_bb
[0]->in_count
== 1) && (bb
->out_bb
[0] != cfg
->bb_exit
) &&
595 (bb
->region
== bb
->out_bb
[0]->region
)) {
596 mono_merge_basic_blocks (cfg
, bb
, bb
->out_bb
[0]);
599 * bbn might have fallen through to the next bb without a branch,
600 * have to add one now (#474718).
601 * FIXME: Maybe need to do this more generally in
602 * merge_basic_blocks () ?
604 if (!(bb
->last_ins
&& MONO_IS_BRANCH_OP (bb
->last_ins
)) && bb
->out_count
) {
605 MONO_INST_NEW (cfg
, ins1
, OP_BR
);
606 ins1
->inst_target_bb
= bb
->out_bb
[0];
607 MONO_ADD_INS (bb
, ins1
);
615 * Optimize checks like: if (v < 0 || v > limit) by changing then to unsigned
616 * compares. This isn't really if conversion, but it easier to do here than in
617 * optimize_branches () since the IR is already optimized.
619 for (bb
= cfg
->bb_entry
; bb
; bb
= bb
->next_bb
) {
620 MonoBasicBlock
*bb1
, *bb2
, *true_bb
, *false_bb
, *next_bb
;
621 MonoInst
*branch1
, *branch2
, *compare1
, *ins
;
623 /* Look for the IR code generated from if (<var> < 0 || v > <limit>)
624 * after branch opts which is:
629 * icompare_imm R [<limit>]
632 if (!(bb
->out_count
== 2 && !bb
->extended
))
635 bb1
= bb
->out_bb
[0];
636 bb2
= bb
->out_bb
[1];
638 // FIXME: Add more cases
640 /* Check structure */
641 if (!(bb1
->in_count
== 2 && bb1
->in_bb
[0] == bb
&& bb1
->in_bb
[1] == bb2
&& bb2
->in_count
== 1 && bb2
->out_count
== 2))
646 /* Check first branch */
647 branch1
= bb
->last_ins
;
648 if (!(branch1
&& ((branch1
->opcode
== OP_IBLT
) || (branch1
->opcode
== OP_LBLT
)) && (branch1
->inst_false_bb
== next_bb
)))
651 true_bb
= branch1
->inst_true_bb
;
653 /* Check second branch */
654 branch2
= next_bb
->last_ins
;
658 /* mcs sometimes generates inverted branches */
659 if (((branch2
->opcode
== OP_IBGT
) || (branch2
->opcode
== OP_LBGT
)) && branch2
->inst_true_bb
== branch1
->inst_true_bb
)
660 false_bb
= branch2
->inst_false_bb
;
661 else if (((branch2
->opcode
== OP_IBLE
) || (branch2
->opcode
== OP_LBLE
)) && branch2
->inst_false_bb
== branch1
->inst_true_bb
)
662 false_bb
= branch2
->inst_true_bb
;
666 /* Check first compare */
667 compare1
= bb
->last_ins
->prev
;
668 if (!(compare1
&& ((compare1
->opcode
== OP_ICOMPARE_IMM
) || (compare1
->opcode
== OP_LCOMPARE_IMM
)) && compare1
->inst_imm
== 0))
671 /* Check second bblock */
675 if (((ins
->opcode
== OP_ICOMPARE_IMM
) || (ins
->opcode
== OP_LCOMPARE_IMM
)) && ins
->sreg1
== compare1
->sreg1
&& ins
->next
== branch2
) {
676 /* The second arg must be positive */
677 if (ins
->inst_imm
< 0)
679 } else if (((ins
->opcode
== OP_LDLEN
) || (ins
->opcode
== OP_STRLEN
)) && ins
->dreg
!= compare1
->sreg1
&& ins
->next
&& ins
->next
->opcode
== OP_ICOMPARE
&& ins
->next
->sreg1
== compare1
->sreg1
&& ins
->next
->sreg2
== ins
->dreg
&& ins
->next
->next
== branch2
) {
680 /* Another common case: if (index < 0 || index > arr.Length) */
685 if (cfg
->verbose_level
> 2) {
686 printf ("\tSigned->unsigned compare optimization in BB%d on\n", bb
->block_num
);
687 printf ("\t\t"); mono_print_ins (compare1
);
688 printf ("\t\t"); mono_print_ins (compare1
->next
);
689 printf ("\t\t"); mono_print_ins (ins
);
692 /* Rewrite the first compare+branch */
693 MONO_DELETE_INS (bb
, compare1
);
694 branch1
->opcode
= OP_BR
;
695 mono_unlink_bblock (cfg
, bb
, branch1
->inst_true_bb
);
696 mono_unlink_bblock (cfg
, bb
, branch1
->inst_false_bb
);
697 branch1
->inst_target_bb
= next_bb
;
698 mono_link_bblock (cfg
, bb
, next_bb
);
700 /* Rewrite the second branch */
701 branch2
->opcode
= br_to_br_un (branch2
->opcode
);
703 mono_merge_basic_blocks (cfg
, bb
, next_bb
);
707 for (bb
= cfg
->bb_entry
; bb
; bb
= bb
->next_bb
) {
708 MonoBasicBlock
*bb1
, *bb2
;
709 MonoInst
*prev
, *compare
, *branch
, *ins1
, *ins2
, *cmov
, *move
, *tmp
;
710 gboolean simple
, ret
;
714 /* Look for the IR code generated from if (cond) <var> <- <a>
715 * after branch opts which is:
722 if (!(bb
->out_count
== 1 && bb
->extended
&& bb
->code
&& bb
->code
->next
&& bb
->code
->next
->next
))
725 mono_print_bb (bb
, "");
727 /* Find the compare instruction */
731 while (compare
->next
->next
&& compare
->next
->next
!= bb
->last_ins
) {
733 compare
= compare
->next
;
735 branch
= compare
->next
;
736 if (!MONO_IS_COND_BRANCH_OP (branch
))
742 if (cfg
->opt
& MONO_OPT_BRANCH
)
743 mono_optimize_branches (cfg
);
744 /* Merging bblocks could make some variables local */
745 mono_handle_global_vregs (cfg
);
746 if (cfg
->opt
& (MONO_OPT_CONSPROP
| MONO_OPT_COPYPROP
))
747 mono_local_cprop (cfg
);
748 mono_local_deadce (cfg
);
754 mono_nullify_basic_block (MonoBasicBlock
*bb
)
761 bb
->code
= bb
->last_ins
= NULL
;
766 replace_out_block (MonoBasicBlock
*bb
, MonoBasicBlock
*orig
, MonoBasicBlock
*repl
)
770 for (i
= 0; i
< bb
->out_count
; i
++) {
771 MonoBasicBlock
*ob
= bb
->out_bb
[i
];
774 if (bb
->out_count
> 1) {
775 bb
->out_bb
[i
] = bb
->out_bb
[bb
->out_count
- 1];
779 bb
->out_bb
[i
] = repl
;
786 replace_in_block (MonoBasicBlock
*bb
, MonoBasicBlock
*orig
, MonoBasicBlock
*repl
)
790 for (i
= 0; i
< bb
->in_count
; i
++) {
791 MonoBasicBlock
*ib
= bb
->in_bb
[i
];
794 if (bb
->in_count
> 1) {
795 bb
->in_bb
[i
] = bb
->in_bb
[bb
->in_count
- 1];
799 bb
->in_bb
[i
] = repl
;
806 replace_out_block_in_code (MonoBasicBlock
*bb
, MonoBasicBlock
*orig
, MonoBasicBlock
*repl
) {
809 for (ins
= bb
->code
; ins
!= NULL
; ins
= ins
->next
) {
810 switch (ins
->opcode
) {
812 if (ins
->inst_target_bb
== orig
)
813 ins
->inst_target_bb
= repl
;
815 case OP_CALL_HANDLER
:
816 if (ins
->inst_target_bb
== orig
)
817 ins
->inst_target_bb
= repl
;
821 int n
= GPOINTER_TO_INT (ins
->klass
);
822 for (i
= 0; i
< n
; i
++ ) {
823 if (ins
->inst_many_bb
[i
] == orig
)
824 ins
->inst_many_bb
[i
] = repl
;
829 if (MONO_IS_COND_BRANCH_OP (ins
)) {
830 if (ins
->inst_true_bb
== orig
)
831 ins
->inst_true_bb
= repl
;
832 if (ins
->inst_false_bb
== orig
)
833 ins
->inst_false_bb
= repl
;
834 } else if (MONO_IS_JUMP_TABLE (ins
)) {
836 MonoJumpInfoBBTable
*table
= MONO_JUMP_TABLE_FROM_INS (ins
);
837 for (i
= 0; i
< table
->table_size
; i
++ ) {
838 if (table
->table
[i
] == orig
)
839 table
->table
[i
] = repl
;
849 * Check if a bb is useless (is just made of NOPs and ends with an
850 * unconditional branch, or nothing).
851 * If it is so, unlink it from the CFG and nullify it, and return TRUE.
852 * Otherwise, return FALSE;
855 remove_block_if_useless (MonoCompile
*cfg
, MonoBasicBlock
*bb
, MonoBasicBlock
*previous_bb
) {
856 MonoBasicBlock
*target_bb
= NULL
;
859 /* Do not touch handlers */
860 if (bb
->region
!= -1) {
861 bb
->not_useless
= TRUE
;
865 MONO_BB_FOR_EACH_INS (bb
, inst
) {
866 switch (inst
->opcode
) {
870 target_bb
= inst
->inst_target_bb
;
873 bb
->not_useless
= TRUE
;
878 if (target_bb
== NULL
) {
879 if ((bb
->out_count
== 1) && (bb
->out_bb
[0] == bb
->next_bb
)) {
880 target_bb
= bb
->next_bb
;
882 /* Do not touch empty BBs that do not "fall through" to their next BB (like the exit BB) */
887 /* Do not touch BBs following a switch (they are the "default" branch) */
888 if ((previous_bb
->last_ins
!= NULL
) && (previous_bb
->last_ins
->opcode
== OP_SWITCH
)) {
892 /* Do not touch BBs following the entry BB and jumping to something that is not */
893 /* thiry "next" bb (the entry BB cannot contain the branch) */
894 if ((previous_bb
== cfg
->bb_entry
) && (bb
->next_bb
!= target_bb
)) {
899 * Do not touch BBs following a try block as the code in
900 * mini_method_compile needs them to compute the length of the try block.
902 if (MONO_BBLOCK_IS_IN_REGION (previous_bb
, MONO_REGION_TRY
))
905 /* Check that there is a target BB, and that bb is not an empty loop (Bug 75061) */
906 if ((target_bb
!= NULL
) && (target_bb
!= bb
)) {
909 if (cfg
->verbose_level
> 1) {
910 printf ("remove_block_if_useless, removed BB%d\n", bb
->block_num
);
913 /* unlink_bblock () modifies the bb->in_bb array so can't use a for loop here */
914 while (bb
->in_count
) {
915 MonoBasicBlock
*in_bb
= bb
->in_bb
[0];
916 mono_unlink_bblock (cfg
, in_bb
, bb
);
917 mono_link_bblock (cfg
, in_bb
, target_bb
);
918 replace_out_block_in_code (in_bb
, bb
, target_bb
);
921 mono_unlink_bblock (cfg
, bb
, target_bb
);
922 if (previous_bb
!= cfg
->bb_entry
&& mono_bb_is_fall_through (cfg
, previous_bb
)) {
923 for (i
= 0; i
< previous_bb
->out_count
; i
++) {
924 if (previous_bb
->out_bb
[i
] == target_bb
) {
926 MONO_INST_NEW (cfg
, jump
, OP_BR
);
927 MONO_ADD_INS (previous_bb
, jump
);
928 jump
->cil_code
= previous_bb
->cil_code
;
929 jump
->inst_target_bb
= target_bb
;
935 previous_bb
->next_bb
= bb
->next_bb
;
936 mono_nullify_basic_block (bb
);
945 mono_merge_basic_blocks (MonoCompile
*cfg
, MonoBasicBlock
*bb
, MonoBasicBlock
*bbn
)
948 MonoBasicBlock
*prev_bb
;
951 bb
->has_array_access
|= bbn
->has_array_access
;
952 bb
->extended
|= bbn
->extended
;
954 mono_unlink_bblock (cfg
, bb
, bbn
);
955 for (i
= 0; i
< bbn
->out_count
; ++i
)
956 mono_link_bblock (cfg
, bb
, bbn
->out_bb
[i
]);
957 while (bbn
->out_count
)
958 mono_unlink_bblock (cfg
, bbn
, bbn
->out_bb
[0]);
960 /* Handle the branch at the end of the bb */
961 for (inst
= bb
->code
; inst
!= NULL
; inst
= inst
->next
) {
962 if (inst
->opcode
== OP_CALL_HANDLER
) {
963 g_assert (inst
->inst_target_bb
== bbn
);
966 if (MONO_IS_JUMP_TABLE (inst
)) {
968 MonoJumpInfoBBTable
*table
= MONO_JUMP_TABLE_FROM_INS (inst
);
969 for (i
= 0; i
< table
->table_size
; i
++ ) {
970 /* Might be already NULL from a previous merge */
971 if (table
->table
[i
])
972 g_assert (table
->table
[i
] == bbn
);
973 table
->table
[i
] = NULL
;
975 /* Can't nullify this as later instructions depend on it */
978 if (bb
->last_ins
&& MONO_IS_COND_BRANCH_OP (bb
->last_ins
)) {
979 g_assert (bb
->last_ins
->inst_false_bb
== bbn
);
980 bb
->last_ins
->inst_false_bb
= NULL
;
982 } else if (bb
->last_ins
&& MONO_IS_BRANCH_OP (bb
->last_ins
)) {
983 NULLIFY_INS (bb
->last_ins
);
988 bb
->last_ins
->next
= bbn
->code
;
989 bbn
->code
->prev
= bb
->last_ins
;
990 bb
->last_ins
= bbn
->last_ins
;
993 bb
->code
= bbn
->code
;
994 bb
->last_ins
= bbn
->last_ins
;
997 for (prev_bb
= cfg
->bb_entry
; prev_bb
&& prev_bb
->next_bb
!= bbn
; prev_bb
= prev_bb
->next_bb
)
1000 prev_bb
->next_bb
= bbn
->next_bb
;
1002 /* bbn might not be in the bb list yet */
1003 if (bb
->next_bb
== bbn
)
1004 bb
->next_bb
= bbn
->next_bb
;
1006 mono_nullify_basic_block (bbn
);
1010 move_basic_block_to_end (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
1012 MonoBasicBlock
*bbn
, *next
;
1016 /* Find the previous */
1017 for (bbn
= cfg
->bb_entry
; bbn
->next_bb
&& bbn
->next_bb
!= bb
; bbn
= bbn
->next_bb
)
1020 bbn
->next_bb
= bb
->next_bb
;
1024 for (bbn
= cfg
->bb_entry
; bbn
->next_bb
; bbn
= bbn
->next_bb
)
1030 if (next
&& (!bb
->last_ins
|| ((bb
->last_ins
->opcode
!= OP_NOT_REACHED
) && (bb
->last_ins
->opcode
!= OP_BR
) && (bb
->last_ins
->opcode
!= OP_BR_REG
) && (!MONO_IS_COND_BRANCH_OP (bb
->last_ins
))))) {
1033 MONO_INST_NEW (cfg
, ins
, OP_BR
);
1034 MONO_ADD_INS (bb
, ins
);
1035 mono_link_bblock (cfg
, bb
, next
);
1036 ins
->inst_target_bb
= next
;
1041 * mono_remove_block:
1043 * Remove BB from the control flow graph
1046 mono_remove_bblock (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
1048 MonoBasicBlock
*tmp_bb
;
1050 for (tmp_bb
= cfg
->bb_entry
; tmp_bb
&& tmp_bb
->next_bb
!= bb
; tmp_bb
= tmp_bb
->next_bb
)
1054 tmp_bb
->next_bb
= bb
->next_bb
;
1058 mono_remove_critical_edges (MonoCompile
*cfg
)
1061 MonoBasicBlock
*previous_bb
;
1063 if (cfg
->verbose_level
> 3) {
1064 for (bb
= cfg
->bb_entry
; bb
; bb
= bb
->next_bb
) {
1066 printf ("remove_critical_edges, BEFORE BB%d (in:", bb
->block_num
);
1067 for (i
= 0; i
< bb
->in_count
; i
++) {
1068 printf (" %d", bb
->in_bb
[i
]->block_num
);
1071 for (i
= 0; i
< bb
->out_count
; i
++) {
1072 printf (" %d", bb
->out_bb
[i
]->block_num
);
1075 if (bb
->last_ins
!= NULL
) {
1077 mono_print_ins (bb
->last_ins
);
1083 for (previous_bb
= cfg
->bb_entry
, bb
= previous_bb
->next_bb
; bb
!= NULL
; previous_bb
= previous_bb
->next_bb
, bb
= bb
->next_bb
) {
1084 if (bb
->in_count
> 1) {
1086 for (in_bb_index
= 0; in_bb_index
< bb
->in_count
; in_bb_index
++) {
1087 MonoBasicBlock
*in_bb
= bb
->in_bb
[in_bb_index
];
1089 * Have to remove non-critical edges whose source ends with a BR_REG
1090 * ins too, since inserting a computation before the BR_REG could
1091 * overwrite the sreg1 of the ins.
1093 if ((in_bb
->out_count
> 1) || (in_bb
->out_count
== 1 && in_bb
->last_ins
&& in_bb
->last_ins
->opcode
== OP_BR_REG
)) {
1094 MonoBasicBlock
*new_bb
= mono_mempool_alloc0 ((cfg
)->mempool
, sizeof (MonoBasicBlock
));
1095 new_bb
->block_num
= cfg
->num_bblocks
++;
1096 // new_bb->real_offset = bb->real_offset;
1097 new_bb
->region
= bb
->region
;
1099 /* Do not alter the CFG while altering the BB list */
1100 if (mono_bb_is_fall_through (cfg
, previous_bb
)) {
1101 if (previous_bb
!= cfg
->bb_entry
) {
1103 /* Make sure previous_bb really falls through bb */
1104 for (i
= 0; i
< previous_bb
->out_count
; i
++) {
1105 if (previous_bb
->out_bb
[i
] == bb
) {
1107 MONO_INST_NEW (cfg
, jump
, OP_BR
);
1108 MONO_ADD_INS (previous_bb
, jump
);
1109 jump
->cil_code
= previous_bb
->cil_code
;
1110 jump
->inst_target_bb
= bb
;
1115 /* We cannot add any inst to the entry BB, so we must */
1116 /* put a new BB in the middle to hold the OP_BR */
1118 MonoBasicBlock
*new_bb_after_entry
= mono_mempool_alloc0 ((cfg
)->mempool
, sizeof (MonoBasicBlock
));
1119 new_bb_after_entry
->block_num
= cfg
->num_bblocks
++;
1120 // new_bb_after_entry->real_offset = bb->real_offset;
1121 new_bb_after_entry
->region
= bb
->region
;
1123 MONO_INST_NEW (cfg
, jump
, OP_BR
);
1124 MONO_ADD_INS (new_bb_after_entry
, jump
);
1125 jump
->cil_code
= bb
->cil_code
;
1126 jump
->inst_target_bb
= bb
;
1128 mono_unlink_bblock (cfg
, previous_bb
, bb
);
1129 mono_link_bblock (cfg
, new_bb_after_entry
, bb
);
1130 mono_link_bblock (cfg
, previous_bb
, new_bb_after_entry
);
1132 previous_bb
->next_bb
= new_bb_after_entry
;
1133 previous_bb
= new_bb_after_entry
;
1135 if (cfg
->verbose_level
> 2) {
1136 printf ("remove_critical_edges, added helper BB%d jumping to BB%d\n", new_bb_after_entry
->block_num
, bb
->block_num
);
1141 /* Insert new_bb in the BB list */
1142 previous_bb
->next_bb
= new_bb
;
1143 new_bb
->next_bb
= bb
;
1144 previous_bb
= new_bb
;
1146 /* Setup in_bb and out_bb */
1147 new_bb
->in_bb
= mono_mempool_alloc ((cfg
)->mempool
, sizeof (MonoBasicBlock
*));
1148 new_bb
->in_bb
[0] = in_bb
;
1149 new_bb
->in_count
= 1;
1150 new_bb
->out_bb
= mono_mempool_alloc ((cfg
)->mempool
, sizeof (MonoBasicBlock
*));
1151 new_bb
->out_bb
[0] = bb
;
1152 new_bb
->out_count
= 1;
1154 /* Relink in_bb and bb to (from) new_bb */
1155 replace_out_block (in_bb
, bb
, new_bb
);
1156 replace_out_block_in_code (in_bb
, bb
, new_bb
);
1157 replace_in_block (bb
, in_bb
, new_bb
);
1159 if (cfg
->verbose_level
> 2) {
1160 printf ("remove_critical_edges, removed critical edge from BB%d to BB%d (added BB%d)\n", in_bb
->block_num
, bb
->block_num
, new_bb
->block_num
);
1167 if (cfg
->verbose_level
> 3) {
1168 for (bb
= cfg
->bb_entry
; bb
; bb
= bb
->next_bb
) {
1170 printf ("remove_critical_edges, AFTER BB%d (in:", bb
->block_num
);
1171 for (i
= 0; i
< bb
->in_count
; i
++) {
1172 printf (" %d", bb
->in_bb
[i
]->block_num
);
1175 for (i
= 0; i
< bb
->out_count
; i
++) {
1176 printf (" %d", bb
->out_bb
[i
]->block_num
);
1179 if (bb
->last_ins
!= NULL
) {
1181 mono_print_ins (bb
->last_ins
);
1189 * Optimizes the branches on the Control Flow Graph
1193 mono_optimize_branches (MonoCompile
*cfg
)
1195 int i
, changed
= FALSE
;
1196 MonoBasicBlock
*bb
, *bbn
;
1197 guint32 niterations
;
1200 * Some crazy loops could cause the code below to go into an infinite
1201 * loop, see bug #53003 for an example. To prevent this, we put an upper
1202 * bound on the number of iterations.
1204 if (cfg
->num_bblocks
> 1000)
1205 niterations
= cfg
->num_bblocks
* 2;
1210 MonoBasicBlock
*previous_bb
;
1214 /* we skip the entry block (exit is handled specially instead ) */
1215 for (previous_bb
= cfg
->bb_entry
, bb
= cfg
->bb_entry
->next_bb
; bb
; previous_bb
= bb
, bb
= bb
->next_bb
) {
1216 /* dont touch code inside exception clauses */
1217 if (bb
->region
!= -1)
1220 if (!bb
->not_useless
&& remove_block_if_useless (cfg
, bb
, previous_bb
)) {
1225 if ((bbn
= bb
->next_bb
) && bbn
->in_count
== 0 && bbn
!= cfg
->bb_exit
&& bb
->region
== bbn
->region
) {
1226 if (cfg
->verbose_level
> 2)
1227 g_print ("nullify block triggered %d\n", bbn
->block_num
);
1229 bb
->next_bb
= bbn
->next_bb
;
1231 for (i
= 0; i
< bbn
->out_count
; i
++)
1232 replace_in_block (bbn
->out_bb
[i
], bbn
, NULL
);
1234 mono_nullify_basic_block (bbn
);
1238 if (bb
->out_count
== 1) {
1239 bbn
= bb
->out_bb
[0];
1241 /* conditional branches where true and false targets are the same can be also replaced with OP_BR */
1242 if (bb
->last_ins
&& (bb
->last_ins
->opcode
!= OP_BR
) && MONO_IS_COND_BRANCH_OP (bb
->last_ins
)) {
1243 bb
->last_ins
->opcode
= OP_BR
;
1244 bb
->last_ins
->inst_target_bb
= bb
->last_ins
->inst_true_bb
;
1246 if (cfg
->verbose_level
> 2)
1247 g_print ("cond branch removal triggered in %d %d\n", bb
->block_num
, bb
->out_count
);
1250 if (bb
->region
== bbn
->region
&& bb
->next_bb
== bbn
) {
1251 /* the block are in sequence anyway ... */
1253 /* branches to the following block can be removed */
1254 if (bb
->last_ins
&& bb
->last_ins
->opcode
== OP_BR
) {
1255 bb
->last_ins
->opcode
= OP_NOP
;
1257 if (cfg
->verbose_level
> 2)
1258 g_print ("br removal triggered %d -> %d\n", bb
->block_num
, bbn
->block_num
);
1261 if (bbn
->in_count
== 1 && !bb
->extended
) {
1262 if (bbn
!= cfg
->bb_exit
) {
1263 if (cfg
->verbose_level
> 2)
1264 g_print ("block merge triggered %d -> %d\n", bb
->block_num
, bbn
->block_num
);
1265 mono_merge_basic_blocks (cfg
, bb
, bbn
);
1270 //mono_print_bb_code (bb);
1275 if ((bbn
= bb
->next_bb
) && bbn
->in_count
== 0 && bbn
!= cfg
->bb_exit
&& bb
->region
== bbn
->region
) {
1276 if (cfg
->verbose_level
> 2) {
1277 g_print ("nullify block triggered %d\n", bbn
->block_num
);
1279 bb
->next_bb
= bbn
->next_bb
;
1281 for (i
= 0; i
< bbn
->out_count
; i
++)
1282 replace_in_block (bbn
->out_bb
[i
], bbn
, NULL
);
1284 mono_nullify_basic_block (bbn
);
1289 if (bb
->out_count
== 1) {
1290 bbn
= bb
->out_bb
[0];
1292 if (bb
->last_ins
&& bb
->last_ins
->opcode
== OP_BR
) {
1293 bbn
= bb
->last_ins
->inst_target_bb
;
1294 if (bb
->region
== bbn
->region
&& bbn
->code
&& bbn
->code
->opcode
== OP_BR
&&
1295 bbn
->code
->inst_target_bb
!= bbn
&&
1296 bbn
->code
->inst_target_bb
->region
== bb
->region
) {
1298 if (cfg
->verbose_level
> 2)
1299 g_print ("branch to branch triggered %d -> %d -> %d\n", bb
->block_num
, bbn
->block_num
, bbn
->code
->inst_target_bb
->block_num
);
1301 replace_in_block (bbn
, bb
, NULL
);
1302 replace_out_block (bb
, bbn
, bbn
->code
->inst_target_bb
);
1303 mono_link_bblock (cfg
, bb
, bbn
->code
->inst_target_bb
);
1304 bb
->last_ins
->inst_target_bb
= bbn
->code
->inst_target_bb
;
1309 } else if (bb
->out_count
== 2) {
1310 if (bb
->last_ins
&& MONO_IS_COND_BRANCH_NOFP (bb
->last_ins
)) {
1312 MonoBasicBlock
*taken_branch_target
= NULL
, *untaken_branch_target
= NULL
;
1314 if (bb
->last_ins
->flags
& MONO_INST_CFOLD_TAKEN
)
1315 branch_result
= BRANCH_TAKEN
;
1316 else if (bb
->last_ins
->flags
& MONO_INST_CFOLD_NOT_TAKEN
)
1317 branch_result
= BRANCH_NOT_TAKEN
;
1319 branch_result
= BRANCH_UNDEF
;
1321 if (branch_result
== BRANCH_TAKEN
) {
1322 taken_branch_target
= bb
->last_ins
->inst_true_bb
;
1323 untaken_branch_target
= bb
->last_ins
->inst_false_bb
;
1324 } else if (branch_result
== BRANCH_NOT_TAKEN
) {
1325 taken_branch_target
= bb
->last_ins
->inst_false_bb
;
1326 untaken_branch_target
= bb
->last_ins
->inst_true_bb
;
1328 if (taken_branch_target
) {
1329 /* if mono_eval_cond_branch () is ever taken to handle
1330 * non-constant values to compare, issue a pop here.
1332 bb
->last_ins
->opcode
= OP_BR
;
1333 bb
->last_ins
->inst_target_bb
= taken_branch_target
;
1335 mono_unlink_bblock (cfg
, bb
, untaken_branch_target
);
1339 bbn
= bb
->last_ins
->inst_true_bb
;
1340 if (bb
->region
== bbn
->region
&& bbn
->code
&& bbn
->code
->opcode
== OP_BR
&&
1341 bbn
->code
->inst_target_bb
->region
== bb
->region
) {
1342 if (cfg
->verbose_level
> 2)
1343 g_print ("cbranch1 to branch triggered %d -> (%d) %d (0x%02x)\n",
1344 bb
->block_num
, bbn
->block_num
, bbn
->code
->inst_target_bb
->block_num
,
1348 * Unlink, then relink bblocks to avoid various
1349 * tricky situations when the two targets of the branch
1350 * are equal, or will become equal after the change.
1352 mono_unlink_bblock (cfg
, bb
, bb
->last_ins
->inst_true_bb
);
1353 mono_unlink_bblock (cfg
, bb
, bb
->last_ins
->inst_false_bb
);
1355 bb
->last_ins
->inst_true_bb
= bbn
->code
->inst_target_bb
;
1357 mono_link_bblock (cfg
, bb
, bb
->last_ins
->inst_true_bb
);
1358 mono_link_bblock (cfg
, bb
, bb
->last_ins
->inst_false_bb
);
1364 bbn
= bb
->last_ins
->inst_false_bb
;
1365 if (bbn
&& bb
->region
== bbn
->region
&& bbn
->code
&& bbn
->code
->opcode
== OP_BR
&&
1366 bbn
->code
->inst_target_bb
->region
== bb
->region
) {
1367 if (cfg
->verbose_level
> 2)
1368 g_print ("cbranch2 to branch triggered %d -> (%d) %d (0x%02x)\n",
1369 bb
->block_num
, bbn
->block_num
, bbn
->code
->inst_target_bb
->block_num
,
1372 mono_unlink_bblock (cfg
, bb
, bb
->last_ins
->inst_true_bb
);
1373 mono_unlink_bblock (cfg
, bb
, bb
->last_ins
->inst_false_bb
);
1375 bb
->last_ins
->inst_false_bb
= bbn
->code
->inst_target_bb
;
1377 mono_link_bblock (cfg
, bb
, bb
->last_ins
->inst_true_bb
);
1378 mono_link_bblock (cfg
, bb
, bb
->last_ins
->inst_false_bb
);
1384 bbn
= bb
->last_ins
->inst_false_bb
;
1386 * If bb is an extended bb, it could contain an inside branch to bbn.
1387 * FIXME: Enable the optimization if that is not true.
1388 * If bblocks_linked () is true, then merging bb and bbn
1389 * would require addition of an extra branch at the end of bbn
1390 * slowing down loops.
1392 if (bbn
&& bb
->region
== bbn
->region
&& bbn
->in_count
== 1 && cfg
->enable_extended_bblocks
&& bbn
!= cfg
->bb_exit
&& !bb
->extended
&& !bbn
->out_of_line
&& !mono_bblocks_linked (bbn
, bb
)) {
1393 g_assert (bbn
->in_bb
[0] == bb
);
1394 if (cfg
->verbose_level
> 2)
1395 g_print ("merge false branch target triggered BB%d -> BB%d\n", bb
->block_num
, bbn
->block_num
);
1396 mono_merge_basic_blocks (cfg
, bb
, bbn
);
1402 if (bb
->last_ins
&& MONO_IS_COND_BRANCH_NOFP (bb
->last_ins
)) {
1403 if (bb
->last_ins
->inst_false_bb
&& bb
->last_ins
->inst_false_bb
->out_of_line
&& (bb
->region
== bb
->last_ins
->inst_false_bb
->region
)) {
1404 /* Reverse the branch */
1405 bb
->last_ins
->opcode
= mono_reverse_branch_op (bb
->last_ins
->opcode
);
1406 bbn
= bb
->last_ins
->inst_false_bb
;
1407 bb
->last_ins
->inst_false_bb
= bb
->last_ins
->inst_true_bb
;
1408 bb
->last_ins
->inst_true_bb
= bbn
;
1410 move_basic_block_to_end (cfg
, bb
->last_ins
->inst_true_bb
);
1411 if (cfg
->verbose_level
> 2)
1412 g_print ("cbranch to throw block triggered %d.\n",
1418 } while (changed
&& (niterations
> 0));
1421 #endif /* DISABLE_JIT */