Skip to content

Commit 21bfbd5

Browse files
JIT: Remove hasLikelihood checks; make FlowEdge::m_likelihoodSet debug-only (#99925)
Part of #93020. Now that edge likelihoods are expected to be set throughout all phases, when transferring the likelihood of an existing edge to a new edge, we should assume the former edge's likelihood should already be set. By removing all non-debug conditional logic that uses hasLikelihood, we can make m_likelihoodSet available only in Debug builds again.
1 parent 682d1c7 commit 21bfbd5

File tree

6 files changed

+30
-29
lines changed

6 files changed

+30
-29
lines changed

src/coreclr/jit/block.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void FlowEdge::setLikelihood(weight_t likelihood)
8080
assert(likelihood >= 0.0);
8181
assert(likelihood <= 1.0);
8282

83+
#ifdef DEBUG
8384
if (m_likelihoodSet)
8485
{
8586
JITDUMP("setting likelihood of " FMT_BB " -> " FMT_BB " from " FMT_WT " to " FMT_WT "\n", m_sourceBlock->bbNum,
@@ -92,7 +93,9 @@ void FlowEdge::setLikelihood(weight_t likelihood)
9293
}
9394

9495
m_likelihoodSet = true;
95-
m_likelihood = likelihood;
96+
#endif // DEBUG
97+
98+
m_likelihood = likelihood;
9699
}
97100

98101
//------------------------------------------------------------------------

src/coreclr/jit/block.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ struct FlowEdge
594594
unsigned m_dupCount;
595595

596596
// True if likelihood has been set
597-
bool m_likelihoodSet;
597+
INDEBUG(bool m_likelihoodSet);
598598

599599
public:
600600
FlowEdge(BasicBlock* sourceBlock, BasicBlock* destBlock, FlowEdge* rest)
@@ -605,7 +605,9 @@ struct FlowEdge
605605
, m_edgeWeightMax(0)
606606
, m_likelihood(0)
607607
, m_dupCount(0)
608+
#ifdef DEBUG
608609
, m_likelihoodSet(false)
610+
#endif // DEBUG
609611
{
610612
}
611613

@@ -668,6 +670,7 @@ struct FlowEdge
668670

669671
weight_t getLikelihood() const
670672
{
673+
assert(m_likelihoodSet);
671674
return m_likelihood;
672675
}
673676

@@ -676,14 +679,16 @@ struct FlowEdge
676679

677680
void clearLikelihood()
678681
{
679-
m_likelihood = 0.0;
680-
m_likelihoodSet = false;
682+
m_likelihood = 0.0;
683+
INDEBUG(m_likelihoodSet = false);
681684
}
682685

686+
#ifdef DEBUG
683687
bool hasLikelihood() const
684688
{
685689
return m_likelihoodSet;
686690
}
691+
#endif // DEBUG
687692

688693
weight_t getLikelyWeight() const;
689694

src/coreclr/jit/fgbasic.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,10 +730,7 @@ void Compiler::fgReplaceJumpTarget(BasicBlock* block, BasicBlock* oldTarget, Bas
730730
assert(newEdge->getSourceBlock() == block);
731731
assert(newEdge->getDestinationBlock() == newTarget);
732732

733-
if (newEdge->hasLikelihood() && oldEdge->hasLikelihood())
734-
{
735-
newEdge->addLikelihood(oldEdge->getLikelihood());
736-
}
733+
newEdge->addLikelihood(oldEdge->getLikelihood());
737734
}
738735

739736
assert(changed);

src/coreclr/jit/fgflow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ FlowEdge* Compiler::fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, FlowE
185185
{
186186
block->bbLastPred = flow;
187187
}
188-
else if ((oldEdge != nullptr) && oldEdge->hasLikelihood())
188+
else if (oldEdge != nullptr)
189189
{
190-
// Copy likelihood from old edge, if any.
190+
// Copy likelihood from old edge.
191191
//
192192
flow->setLikelihood(oldEdge->getLikelihood());
193193
}

src/coreclr/jit/fgopt.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,24 +1837,22 @@ bool Compiler::fgOptimizeSwitchBranches(BasicBlock* block)
18371837
// Update edge likelihoods
18381838
// Note old edge may still be "in use" so we decrease its likelihood.
18391839
//
1840-
if (oldEdge->hasLikelihood())
1841-
{
1842-
// We want to move this much likelihood from old->new
1843-
//
1844-
const weight_t likelihoodFraction = oldEdge->getLikelihood() / (oldEdge->getDupCount() + 1);
18451840

1846-
if (newEdge->getDupCount() == 1)
1847-
{
1848-
newEdge->setLikelihood(likelihoodFraction);
1849-
}
1850-
else
1851-
{
1852-
newEdge->addLikelihood(likelihoodFraction);
1853-
}
1841+
// We want to move this much likelihood from old->new
1842+
//
1843+
const weight_t likelihoodFraction = oldEdge->getLikelihood() / (oldEdge->getDupCount() + 1);
18541844

1855-
oldEdge->addLikelihood(-likelihoodFraction);
1845+
if (newEdge->getDupCount() == 1)
1846+
{
1847+
newEdge->setLikelihood(likelihoodFraction);
1848+
}
1849+
else
1850+
{
1851+
newEdge->addLikelihood(likelihoodFraction);
18561852
}
18571853

1854+
oldEdge->addLikelihood(-likelihoodFraction);
1855+
18581856
// we optimized a Switch label - goto REPEAT_SWITCH to follow this new jump
18591857
modified = true;
18601858

src/coreclr/jit/indirectcalltransformer.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,7 @@ class IndirectCallTransformer
603603
assert(prevCheckBlock->KindIs(BBJ_ALWAYS));
604604
assert(prevCheckBlock->JumpsToNext());
605605
FlowEdge* const prevCheckThenEdge = prevCheckBlock->GetTargetEdge();
606-
assert(prevCheckThenEdge->hasLikelihood());
607-
weight_t checkLikelihood = max(0.0, 1.0 - prevCheckThenEdge->getLikelihood());
606+
weight_t checkLikelihood = max(0.0, 1.0 - prevCheckThenEdge->getLikelihood());
608607

609608
JITDUMP("Level %u Check block " FMT_BB " success likelihood " FMT_WT "\n", checkIdx, checkBlock->bbNum,
610609
checkLikelihood);
@@ -1086,9 +1085,8 @@ class IndirectCallTransformer
10861085
// just use that to figure out the "else" likelihood.
10871086
//
10881087
assert(checkBlock->KindIs(BBJ_ALWAYS));
1089-
FlowEdge* const checkThenEdge = checkBlock->GetTargetEdge();
1090-
assert(checkThenEdge->hasLikelihood());
1091-
weight_t elseLikelihood = max(0.0, 1.0 - checkThenEdge->getLikelihood());
1088+
FlowEdge* const checkThenEdge = checkBlock->GetTargetEdge();
1089+
weight_t elseLikelihood = max(0.0, 1.0 - checkThenEdge->getLikelihood());
10921090

10931091
// CheckBlock flows into elseBlock unless we deal with the case
10941092
// where we know the last check is always true (in case of "exact" GDV)

0 commit comments

Comments
 (0)