Skip to content

Commit 6561e7c

Browse files
authored
JIT: fix count reconstruction problem (#100385)
In large methods with lots of irreducible loops we may find reconstructed counts reaching very large values. Since profile counts in practice won't ever be much larger than say 10^12, detect when reconstructed counts exceed this value, and stop the algorithm. We may eventually decide to rerun in "hard blend" mode where we intentionally limit the edge likelihood ranges. But this should do for now. Closes #100350.
1 parent f51d705 commit 6561e7c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/coreclr/jit/fgprofilesynthesis.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,12 @@ void ProfileSynthesis::GaussSeidelSolver()
12891289
residual = change;
12901290
residualBlock = block;
12911291
}
1292+
1293+
if (newWeight >= maxCount)
1294+
{
1295+
JITDUMP("count overflow in " FMT_BB ": " FMT_WT "\n", block->bbNum, newWeight);
1296+
m_overflow = true;
1297+
}
12921298
}
12931299

12941300
// If there were no improper headers, we will have converged in one pass.
@@ -1312,6 +1318,11 @@ void ProfileSynthesis::GaussSeidelSolver()
13121318
break;
13131319
}
13141320

1321+
if (m_overflow)
1322+
{
1323+
break;
1324+
}
1325+
13151326
// If we have been iterating for a bit, estimate the dominant GS
13161327
// eigenvalue. (we might want to start with Jacobi iterations
13171328
// to get the Jacobi eigenvalue instead).

src/coreclr/jit/fgprofilesynthesis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ProfileSynthesis
5151
static constexpr weight_t ilNextLikelihood = 0.52;
5252
static constexpr weight_t loopBackLikelihood = 0.9;
5353
static constexpr weight_t loopExitLikelihood = 0.9;
54+
static constexpr weight_t maxCount = 1e12;
5455

5556
void Run(ProfileSynthesisOption option);
5657

@@ -84,6 +85,7 @@ class ProfileSynthesis
8485
unsigned m_improperLoopHeaders = 0;
8586
unsigned m_cappedCyclicProbabilities = 0;
8687
bool m_approximate = false;
88+
bool m_overflow = false;
8789
};
8890

8991
#endif // !_FGPROFILESYNTHESIS_H_

0 commit comments

Comments
 (0)