Skip to content

Commit ade0edf

Browse files
committed
8292285: C2: remove unreachable block after NeverBranch-to-Goto conversion
Backport-of: a25e1dc53cecc5dd917ac0f76fd86ef1f074adba
1 parent 6262937 commit ade0edf

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/hotspot/share/opto/block.cpp

+24-6
Original file line numberDiff line numberDiff line change
@@ -590,19 +590,37 @@ void PhaseCFG::convert_NeverBranch_to_Goto(Block *b) {
590590
b->_num_succs = 1;
591591
// remap successor's predecessors if necessary
592592
uint j;
593-
for( j = 1; j < succ->num_preds(); j++)
594-
if( succ->pred(j)->in(0) == bp )
593+
for (j = 1; j < succ->num_preds(); j++) {
594+
if (succ->pred(j)->in(0) == bp) {
595595
succ->head()->set_req(j, gto);
596+
}
597+
}
596598
// Kill alternate exit path
597-
Block *dead = b->_succs[1-idx];
598-
for( j = 1; j < dead->num_preds(); j++)
599-
if( dead->pred(j)->in(0) == bp )
599+
Block* dead = b->_succs[1 - idx];
600+
for (j = 1; j < dead->num_preds(); j++) {
601+
if (dead->pred(j)->in(0) == bp) {
600602
break;
603+
}
604+
}
601605
// Scan through block, yanking dead path from
602606
// all regions and phis.
603607
dead->head()->del_req(j);
604-
for( int k = 1; dead->get_node(k)->is_Phi(); k++ )
608+
for (int k = 1; dead->get_node(k)->is_Phi(); k++) {
605609
dead->get_node(k)->del_req(j);
610+
}
611+
// If the fake exit block becomes unreachable, remove it from the block list.
612+
if (dead->num_preds() == 1) {
613+
for (uint i = 0; i < number_of_blocks(); i++) {
614+
Block* block = get_block(i);
615+
if (block == dead) {
616+
_blocks.remove(i);
617+
} else if (block->_pre_order > dead->_pre_order) {
618+
// Enforce contiguous pre-order indices (assumed by PhaseBlockLayout).
619+
block->_pre_order--;
620+
}
621+
}
622+
_number_of_blocks--;
623+
}
606624
}
607625

608626
// Helper function to move block bx to the slot following b_index. Return

0 commit comments

Comments
 (0)