From 5de69e867b5d62b4c2648bafef1e788cfb8ada54 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Thu, 24 Apr 2025 09:56:01 -0700 Subject: [PATCH] JIT: revised fix for fp division issue in profile synthesis The previous fix #113396 could still leave us trying to evaluate 0.0/0.0, which causes an invalid FP operation exception. Make sure the divisor is non-zero. --- src/coreclr/jit/fgprofilesynthesis.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/coreclr/jit/fgprofilesynthesis.cpp b/src/coreclr/jit/fgprofilesynthesis.cpp index b045ef8a23e666..178b067fb46cfc 100644 --- a/src/coreclr/jit/fgprofilesynthesis.cpp +++ b/src/coreclr/jit/fgprofilesynthesis.cpp @@ -1389,14 +1389,9 @@ void ProfileSynthesis::GaussSeidelSolver() // Note we are using a "point" bound here ("infinity norm") rather than say // computing the L2-norm of the entire residual vector. // - weight_t const smallFractionOfChange = 1e-9 * change; - weight_t relDivisor = oldWeight; - if (relDivisor < smallFractionOfChange) - { - relDivisor = smallFractionOfChange; - } - - weight_t const blockRelResidual = change / relDivisor; + // Avoid dividing by zero if oldWeight is very small. + // + weight_t const blockRelResidual = change / max(oldWeight, 1e-12); if ((relResidualBlock == nullptr) || (blockRelResidual > relResidual)) {