@@ -1012,13 +1012,15 @@ class PathFrequency {
1012
1012
GrowableArray<float > _freqs; // cache frequencies
1013
1013
PhaseIdealLoop* _phase;
1014
1014
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;
1022
1024
}
1023
1025
1024
1026
public:
@@ -1028,7 +1030,6 @@ class PathFrequency {
1028
1030
1029
1031
float to (Node* n) {
1030
1032
// 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
1032
1033
IdealLoopTree* loop = _phase->get_loop (_dom);
1033
1034
Node* c = n;
1034
1035
for (;;) {
@@ -1055,14 +1056,12 @@ class PathFrequency {
1055
1056
inner_head = inner_loop->_head ->as_Loop ();
1056
1057
inner_head->verify_strip_mined (1 );
1057
1058
}
1058
- set_rounding (FE_UPWARD); // make sure rounding doesn't push frequency above 1
1059
1059
float loop_exit_cnt = 0 .0f ;
1060
1060
for (uint i = 0 ; i < inner_loop->_body .size (); i++) {
1061
1061
Node *n = inner_loop->_body [i];
1062
1062
float c = inner_loop->compute_profile_trip_cnt_helper (n);
1063
1063
loop_exit_cnt += c;
1064
1064
}
1065
- set_rounding (FE_TOWARDZERO);
1066
1065
float cnt = -1 ;
1067
1066
if (n->in (0 )->is_If ()) {
1068
1067
IfNode* iff = n->in (0 )->as_If ();
@@ -1082,9 +1081,9 @@ class PathFrequency {
1082
1081
cnt = p * jmp->_fcnt ;
1083
1082
}
1084
1083
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);
1086
1085
f = f * this_exit_f;
1087
- check_frequency (f);
1086
+ f = check_and_truncate_frequency (f);
1088
1087
} else {
1089
1088
float p = -1 ;
1090
1089
if (n->in (0 )->is_If ()) {
@@ -1097,15 +1096,15 @@ class PathFrequency {
1097
1096
p = n->in (0 )->as_Jump ()->_probs [n->as_JumpProj ()->_con ];
1098
1097
}
1099
1098
f = f * p;
1100
- check_frequency (f);
1099
+ f = check_and_truncate_frequency (f);
1101
1100
}
1102
1101
_freqs.at_put_grow (n->_idx , (float )f, -1 );
1103
1102
_stack.pop ();
1104
1103
} else {
1105
1104
float prev_f = _freqs_stack.pop ();
1106
1105
float new_f = f;
1107
1106
f = new_f + prev_f;
1108
- check_frequency (f);
1107
+ f = check_and_truncate_frequency (f);
1109
1108
uint i = _stack.index ();
1110
1109
if (i < n->req ()) {
1111
1110
c = n->in (i);
@@ -1118,9 +1117,7 @@ class PathFrequency {
1118
1117
}
1119
1118
}
1120
1119
if (_stack.size () == 0 ) {
1121
- set_rounding (FE_TONEAREST);
1122
- check_frequency (f);
1123
- return f;
1120
+ return check_and_truncate_frequency (f);
1124
1121
}
1125
1122
} else if (c->is_Loop ()) {
1126
1123
ShouldNotReachHere ();
0 commit comments