8292285: C2: remove unreachable block after NeverBranch-to-Goto conversion

Reviewed-by: thartmann, chagedorn, kvn
This commit is contained in:
Roberto Castañeda Lozano 2022-08-17 06:25:25 +00:00
parent 1ef4e48488
commit a25e1dc53c

View File

@ -590,19 +590,37 @@ void PhaseCFG::convert_NeverBranch_to_Goto(Block *b) {
b->_num_succs = 1;
// remap successor's predecessors if necessary
uint j;
for( j = 1; j < succ->num_preds(); j++)
if( succ->pred(j)->in(0) == bp )
for (j = 1; j < succ->num_preds(); j++) {
if (succ->pred(j)->in(0) == bp) {
succ->head()->set_req(j, gto);
}
}
// Kill alternate exit path
Block *dead = b->_succs[1-idx];
for( j = 1; j < dead->num_preds(); j++)
if( dead->pred(j)->in(0) == bp )
Block* dead = b->_succs[1 - idx];
for (j = 1; j < dead->num_preds(); j++) {
if (dead->pred(j)->in(0) == bp) {
break;
}
}
// Scan through block, yanking dead path from
// all regions and phis.
dead->head()->del_req(j);
for( int k = 1; dead->get_node(k)->is_Phi(); k++ )
for (int k = 1; dead->get_node(k)->is_Phi(); k++) {
dead->get_node(k)->del_req(j);
}
// If the fake exit block becomes unreachable, remove it from the block list.
if (dead->num_preds() == 1) {
for (uint i = 0; i < number_of_blocks(); i++) {
Block* block = get_block(i);
if (block == dead) {
_blocks.remove(i);
} else if (block->_pre_order > dead->_pre_order) {
// Enforce contiguous pre-order indices (assumed by PhaseBlockLayout).
block->_pre_order--;
}
}
_number_of_blocks--;
}
}
// Helper function to move block bx to the slot following b_index. Return