Skip to content

Commit c8613e5

Browse files
JIT: avoid fp divide by zero in profile synthesis (#113418)
This can trip up users that have enabled floating point exceptions. While we don't generally support changing the exception modes we also can easily avoid dividing by zero here. Addresses #113369 Co-authored-by: Andy Ayers <andya@microsoft.com>
1 parent f488c54 commit c8613e5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/coreclr/jit/fgprofilesynthesis.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,12 +1408,19 @@ void ProfileSynthesis::GaussSeidelSolver()
14081408
countVector[block->bbNum] = newWeight;
14091409

14101410
// Remember max absolute and relative change
1411-
// (note rel residual will be infinite at times, that's ok)
1411+
// (note rel residual will be as large as 1e9 at times, that's ok)
14121412
//
14131413
// Note we are using a "point" bound here ("infinity norm") rather than say
14141414
// computing the L2-norm of the entire residual vector.
14151415
//
1416-
weight_t const blockRelResidual = change / oldWeight;
1416+
weight_t const smallFractionOfChange = 1e-9 * change;
1417+
weight_t relDivisor = oldWeight;
1418+
if (relDivisor < smallFractionOfChange)
1419+
{
1420+
relDivisor = smallFractionOfChange;
1421+
}
1422+
1423+
weight_t const blockRelResidual = change / relDivisor;
14171424

14181425
if ((relResidualBlock == nullptr) || (blockRelResidual > relResidual))
14191426
{

0 commit comments

Comments
 (0)