Skip to content

Commit ff1383c

Browse files
authored
JIT: avoid fp divide by zero in profile synthesis (#113396)
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
1 parent f50e71c commit ff1383c

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
@@ -1411,12 +1411,19 @@ void ProfileSynthesis::GaussSeidelSolver()
14111411
countVector[block->bbNum] = newWeight;
14121412

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

14211428
if ((relResidualBlock == nullptr) || (blockRelResidual > relResidual))
14221429
{

0 commit comments

Comments
 (0)