@@ -1024,13 +1024,15 @@ class PathFrequency {
1024
1024
GrowableArray<float > _freqs; // cache frequencies
1025
1025
PhaseIdealLoop* _phase;
1026
1026
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;
1034
1036
}
1035
1037
1036
1038
public:
@@ -1040,7 +1042,6 @@ class PathFrequency {
1040
1042
1041
1043
float to (Node* n) {
1042
1044
// 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
1044
1045
IdealLoopTree* loop = _phase->get_loop (_dom);
1045
1046
Node* c = n;
1046
1047
for (;;) {
@@ -1067,14 +1068,12 @@ class PathFrequency {
1067
1068
inner_head = inner_loop->_head ->as_Loop ();
1068
1069
inner_head->verify_strip_mined (1 );
1069
1070
}
1070
- set_rounding (FE_UPWARD); // make sure rounding doesn't push frequency above 1
1071
1071
float loop_exit_cnt = 0 .0f ;
1072
1072
for (uint i = 0 ; i < inner_loop->_body .size (); i++) {
1073
1073
Node *n = inner_loop->_body [i];
1074
1074
float c = inner_loop->compute_profile_trip_cnt_helper (n);
1075
1075
loop_exit_cnt += c;
1076
1076
}
1077
- set_rounding (FE_TOWARDZERO);
1078
1077
float cnt = -1 ;
1079
1078
if (n->in (0 )->is_If ()) {
1080
1079
IfNode* iff = n->in (0 )->as_If ();
@@ -1094,9 +1093,9 @@ class PathFrequency {
1094
1093
cnt = p * jmp->_fcnt ;
1095
1094
}
1096
1095
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);
1098
1097
f = f * this_exit_f;
1099
- check_frequency (f);
1098
+ f = check_and_truncate_frequency (f);
1100
1099
} else {
1101
1100
float p = -1 ;
1102
1101
if (n->in (0 )->is_If ()) {
@@ -1109,15 +1108,15 @@ class PathFrequency {
1109
1108
p = n->in (0 )->as_Jump ()->_probs [n->as_JumpProj ()->_con ];
1110
1109
}
1111
1110
f = f * p;
1112
- check_frequency (f);
1111
+ f = check_and_truncate_frequency (f);
1113
1112
}
1114
1113
_freqs.at_put_grow (n->_idx , (float )f, -1 );
1115
1114
_stack.pop ();
1116
1115
} else {
1117
1116
float prev_f = _freqs_stack.pop ();
1118
1117
float new_f = f;
1119
1118
f = new_f + prev_f;
1120
- check_frequency (f);
1119
+ f = check_and_truncate_frequency (f);
1121
1120
uint i = _stack.index ();
1122
1121
if (i < n->req ()) {
1123
1122
c = n->in (i);
@@ -1130,9 +1129,7 @@ class PathFrequency {
1130
1129
}
1131
1130
}
1132
1131
if (_stack.size () == 0 ) {
1133
- set_rounding (FE_TONEAREST);
1134
- check_frequency (f);
1135
- return f;
1132
+ return check_and_truncate_frequency (f);
1136
1133
}
1137
1134
} else if (c->is_Loop ()) {
1138
1135
ShouldNotReachHere ();
0 commit comments