Skip to content

Commit 7b65a39

Browse files
committed
8273139: C2: assert(f <= 1 && f >= 0) failed: Incorrect frequency
Backport-of: 68b40ec28658a2dd829c77281b0025e16095c170
1 parent 3521504 commit 7b65a39

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/hotspot/share/opto/loopPredicate.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,13 +1012,15 @@ class PathFrequency {
10121012
GrowableArray<float> _freqs; // cache frequencies
10131013
PhaseIdealLoop* _phase;
10141014

1015-
void set_rounding(int mode) {
1016-
// fesetround is broken on windows
1017-
NOT_WINDOWS(fesetround(mode);)
1018-
}
1019-
1020-
void check_frequency(float f) {
1021-
NOT_WINDOWS(assert(f <= 1 && f >= 0, "Incorrect frequency");)
1015+
float check_and_truncate_frequency(float f) {
1016+
assert(f >= 0, "Incorrect frequency");
1017+
// We do not perform an exact (f <= 1) check
1018+
// this would be error prone with rounding of floats.
1019+
// Performing a check like (f <= 1+eps) would be of benefit,
1020+
// however, it is not evident how to determine such an eps,
1021+
// given that an arbitrary number of add/mul operations
1022+
// are performed on these frequencies.
1023+
return (f > 1) ? 1 : f;
10221024
}
10231025

10241026
public:
@@ -1028,7 +1030,6 @@ class PathFrequency {
10281030

10291031
float to(Node* n) {
10301032
// post order walk on the CFG graph from n to _dom
1031-
set_rounding(FE_TOWARDZERO); // make sure rounding doesn't push frequency above 1
10321033
IdealLoopTree* loop = _phase->get_loop(_dom);
10331034
Node* c = n;
10341035
for (;;) {
@@ -1055,14 +1056,12 @@ class PathFrequency {
10551056
inner_head = inner_loop->_head->as_Loop();
10561057
inner_head->verify_strip_mined(1);
10571058
}
1058-
set_rounding(FE_UPWARD); // make sure rounding doesn't push frequency above 1
10591059
float loop_exit_cnt = 0.0f;
10601060
for (uint i = 0; i < inner_loop->_body.size(); i++) {
10611061
Node *n = inner_loop->_body[i];
10621062
float c = inner_loop->compute_profile_trip_cnt_helper(n);
10631063
loop_exit_cnt += c;
10641064
}
1065-
set_rounding(FE_TOWARDZERO);
10661065
float cnt = -1;
10671066
if (n->in(0)->is_If()) {
10681067
IfNode* iff = n->in(0)->as_If();
@@ -1082,9 +1081,9 @@ class PathFrequency {
10821081
cnt = p * jmp->_fcnt;
10831082
}
10841083
float this_exit_f = cnt > 0 ? cnt / loop_exit_cnt : 0;
1085-
check_frequency(this_exit_f);
1084+
this_exit_f = check_and_truncate_frequency(this_exit_f);
10861085
f = f * this_exit_f;
1087-
check_frequency(f);
1086+
f = check_and_truncate_frequency(f);
10881087
} else {
10891088
float p = -1;
10901089
if (n->in(0)->is_If()) {
@@ -1097,15 +1096,15 @@ class PathFrequency {
10971096
p = n->in(0)->as_Jump()->_probs[n->as_JumpProj()->_con];
10981097
}
10991098
f = f * p;
1100-
check_frequency(f);
1099+
f = check_and_truncate_frequency(f);
11011100
}
11021101
_freqs.at_put_grow(n->_idx, (float)f, -1);
11031102
_stack.pop();
11041103
} else {
11051104
float prev_f = _freqs_stack.pop();
11061105
float new_f = f;
11071106
f = new_f + prev_f;
1108-
check_frequency(f);
1107+
f = check_and_truncate_frequency(f);
11091108
uint i = _stack.index();
11101109
if (i < n->req()) {
11111110
c = n->in(i);
@@ -1118,9 +1117,7 @@ class PathFrequency {
11181117
}
11191118
}
11201119
if (_stack.size() == 0) {
1121-
set_rounding(FE_TONEAREST);
1122-
check_frequency(f);
1123-
return f;
1120+
return check_and_truncate_frequency(f);
11241121
}
11251122
} else if (c->is_Loop()) {
11261123
ShouldNotReachHere();

0 commit comments

Comments
 (0)