Skip to content

Commit 776e1cf

Browse files
committed
8353041: NeverBranchNode causes incorrect block frequency calculation
Reviewed-by: thartmann, rcastanedalo
1 parent cc546e7 commit 776e1cf

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/hotspot/share/opto/domgraph.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,21 @@ uint Block_Stack::most_frequent_successor( Block *b ) {
233233
case Op_Jump:
234234
case Op_Root:
235235
case Op_Goto:
236-
case Op_NeverBranch:
237236
freq_idx = 0; // fall thru
238237
break;
238+
case Op_NeverBranch: {
239+
Node* succ = n->as_NeverBranch()->proj_out(0)->unique_ctrl_out();
240+
int succ_idx = 0; // normal case
241+
if (succ == b->_succs[1]->head()) {
242+
// Edges swapped, rare case. May happen due to an unusual matcher
243+
// traversal order for peeled infinite loops.
244+
succ_idx = 1;
245+
} else {
246+
assert(succ == b->_succs[0]->head(), "succ not found");
247+
}
248+
freq_idx = succ_idx;
249+
break;
250+
}
239251
case Op_TailCall:
240252
case Op_TailJump:
241253
case Op_ForwardException:

src/hotspot/share/opto/gcm.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2160,8 +2160,13 @@ float Block::succ_prob(uint i) {
21602160
// Pass frequency straight thru to target
21612161
return 1.0f;
21622162

2163-
case Op_NeverBranch:
2163+
case Op_NeverBranch: {
2164+
Node* succ = n->as_NeverBranch()->proj_out(0)->unique_ctrl_out();
2165+
if (_succs[i]->head() == succ) {
2166+
return 1.0f;
2167+
}
21642168
return 0.0f;
2169+
}
21652170

21662171
case Op_TailCall:
21672172
case Op_TailJump:

0 commit comments

Comments
 (0)