Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 34f2864

Browse files
committed
8273139: C2: assert(f <= 1 && f >= 0) failed: Incorrect frequency
Backport-of: 68b40ec28658a2dd829c77281b0025e16095c170
1 parent 313932a commit 34f2864

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
@@ -1024,13 +1024,15 @@ class PathFrequency {
10241024
GrowableArray<float> _freqs; // cache frequencies
10251025
PhaseIdealLoop* _phase;
10261026

1027-
void set_rounding(int mode) {
1028-
// fesetround is broken on windows
1029-
NOT_WINDOWS(fesetround(mode);)
1030-
}
1031-
1032-
void check_frequency(float f) {
1033-
NOT_WINDOWS(assert(f <= 1 && f >= 0, "Incorrect frequency");)
1027+
float check_and_truncate_frequency(float f) {
1028+
assert(f >= 0, "Incorrect frequency");
1029+
// We do not perform an exact (f <= 1) check
1030+
// this would be error prone with rounding of floats.
1031+
// Performing a check like (f <= 1+eps) would be of benefit,
1032+
// however, it is not evident how to determine such an eps,
1033+
// given that an arbitrary number of add/mul operations
1034+
// are performed on these frequencies.
1035+
return (f > 1) ? 1 : f;
10341036
}
10351037

10361038
public:
@@ -1040,7 +1042,6 @@ class PathFrequency {
10401042

10411043
float to(Node* n) {
10421044
// post order walk on the CFG graph from n to _dom
1043-
set_rounding(FE_TOWARDZERO); // make sure rounding doesn't push frequency above 1
10441045
IdealLoopTree* loop = _phase->get_loop(_dom);
10451046
Node* c = n;
10461047
for (;;) {
@@ -1067,14 +1068,12 @@ class PathFrequency {
10671068
inner_head = inner_loop->_head->as_Loop();
10681069
inner_head->verify_strip_mined(1);
10691070
}
1070-
set_rounding(FE_UPWARD); // make sure rounding doesn't push frequency above 1
10711071
float loop_exit_cnt = 0.0f;
10721072
for (uint i = 0; i < inner_loop->_body.size(); i++) {
10731073
Node *n = inner_loop->_body[i];
10741074
float c = inner_loop->compute_profile_trip_cnt_helper(n);
10751075
loop_exit_cnt += c;
10761076
}
1077-
set_rounding(FE_TOWARDZERO);
10781077
float cnt = -1;
10791078
if (n->in(0)->is_If()) {
10801079
IfNode* iff = n->in(0)->as_If();
@@ -1094,9 +1093,9 @@ class PathFrequency {
10941093
cnt = p * jmp->_fcnt;
10951094
}
10961095
float this_exit_f = cnt > 0 ? cnt / loop_exit_cnt : 0;
1097-
check_frequency(this_exit_f);
1096+
this_exit_f = check_and_truncate_frequency(this_exit_f);
10981097
f = f * this_exit_f;
1099-
check_frequency(f);
1098+
f = check_and_truncate_frequency(f);
11001099
} else {
11011100
float p = -1;
11021101
if (n->in(0)->is_If()) {
@@ -1109,15 +1108,15 @@ class PathFrequency {
11091108
p = n->in(0)->as_Jump()->_probs[n->as_JumpProj()->_con];
11101109
}
11111110
f = f * p;
1112-
check_frequency(f);
1111+
f = check_and_truncate_frequency(f);
11131112
}
11141113
_freqs.at_put_grow(n->_idx, (float)f, -1);
11151114
_stack.pop();
11161115
} else {
11171116
float prev_f = _freqs_stack.pop();
11181117
float new_f = f;
11191118
f = new_f + prev_f;
1120-
check_frequency(f);
1119+
f = check_and_truncate_frequency(f);
11211120
uint i = _stack.index();
11221121
if (i < n->req()) {
11231122
c = n->in(i);
@@ -1130,9 +1129,7 @@ class PathFrequency {
11301129
}
11311130
}
11321131
if (_stack.size() == 0) {
1133-
set_rounding(FE_TONEAREST);
1134-
check_frequency(f);
1135-
return f;
1132+
return check_and_truncate_frequency(f);
11361133
}
11371134
} else if (c->is_Loop()) {
11381135
ShouldNotReachHere();

0 commit comments

Comments
 (0)