8353041: NeverBranchNode causes incorrect block frequency calculation

Reviewed-by: thartmann, rcastanedalo
This commit is contained in:
Dean Long 2025-04-09 20:06:49 +00:00
parent cc546e7a28
commit 776e1cf1df
2 changed files with 19 additions and 2 deletions

View File

@ -233,9 +233,21 @@ uint Block_Stack::most_frequent_successor( Block *b ) {
case Op_Jump:
case Op_Root:
case Op_Goto:
case Op_NeverBranch:
freq_idx = 0; // fall thru
break;
case Op_NeverBranch: {
Node* succ = n->as_NeverBranch()->proj_out(0)->unique_ctrl_out();
int succ_idx = 0; // normal case
if (succ == b->_succs[1]->head()) {
// Edges swapped, rare case. May happen due to an unusual matcher
// traversal order for peeled infinite loops.
succ_idx = 1;
} else {
assert(succ == b->_succs[0]->head(), "succ not found");
}
freq_idx = succ_idx;
break;
}
case Op_TailCall:
case Op_TailJump:
case Op_ForwardException:

View File

@ -2160,8 +2160,13 @@ float Block::succ_prob(uint i) {
// Pass frequency straight thru to target
return 1.0f;
case Op_NeverBranch:
case Op_NeverBranch: {
Node* succ = n->as_NeverBranch()->proj_out(0)->unique_ctrl_out();
if (_succs[i]->head() == succ) {
return 1.0f;
}
return 0.0f;
}
case Op_TailCall:
case Op_TailJump: