diff --git a/src/coreclr/jit/block.cpp b/src/coreclr/jit/block.cpp index 7bc07a54775..6eea265871c 100644 --- a/src/coreclr/jit/block.cpp +++ b/src/coreclr/jit/block.cpp @@ -80,6 +80,7 @@ void FlowEdge::setLikelihood(weight_t likelihood) assert(likelihood >= 0.0); assert(likelihood <= 1.0); +#ifdef DEBUG if (m_likelihoodSet) { 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) } m_likelihoodSet = true; - m_likelihood = likelihood; +#endif // DEBUG + + m_likelihood = likelihood; } //------------------------------------------------------------------------ diff --git a/src/coreclr/jit/block.h b/src/coreclr/jit/block.h index 52081e9bb77..dfaace466a6 100644 --- a/src/coreclr/jit/block.h +++ b/src/coreclr/jit/block.h @@ -594,7 +594,7 @@ private: unsigned m_dupCount; // True if likelihood has been set - bool m_likelihoodSet; + INDEBUG(bool m_likelihoodSet); public: FlowEdge(BasicBlock* sourceBlock, BasicBlock* destBlock, FlowEdge* rest) @@ -605,7 +605,9 @@ public: , m_edgeWeightMax(0) , m_likelihood(0) , m_dupCount(0) +#ifdef DEBUG , m_likelihoodSet(false) +#endif // DEBUG { } @@ -668,6 +670,7 @@ public: weight_t getLikelihood() const { + assert(m_likelihoodSet); return m_likelihood; } @@ -676,14 +679,16 @@ public: void clearLikelihood() { - m_likelihood = 0.0; - m_likelihoodSet = false; + m_likelihood = 0.0; + INDEBUG(m_likelihoodSet = false); } +#ifdef DEBUG bool hasLikelihood() const { return m_likelihoodSet; } +#endif // DEBUG weight_t getLikelyWeight() const; diff --git a/src/coreclr/jit/fgbasic.cpp b/src/coreclr/jit/fgbasic.cpp index bfbf5dc95ff..5b4fcd33f8e 100644 --- a/src/coreclr/jit/fgbasic.cpp +++ b/src/coreclr/jit/fgbasic.cpp @@ -730,10 +730,7 @@ void Compiler::fgReplaceJumpTarget(BasicBlock* block, BasicBlock* oldTarget, Bas assert(newEdge->getSourceBlock() == block); assert(newEdge->getDestinationBlock() == newTarget); - if (newEdge->hasLikelihood() && oldEdge->hasLikelihood()) - { - newEdge->addLikelihood(oldEdge->getLikelihood()); - } + newEdge->addLikelihood(oldEdge->getLikelihood()); } assert(changed); diff --git a/src/coreclr/jit/fgflow.cpp b/src/coreclr/jit/fgflow.cpp index f9a17212186..f4f650f6b5d 100644 --- a/src/coreclr/jit/fgflow.cpp +++ b/src/coreclr/jit/fgflow.cpp @@ -185,9 +185,9 @@ FlowEdge* Compiler::fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, FlowE { block->bbLastPred = flow; } - else if ((oldEdge != nullptr) && oldEdge->hasLikelihood()) + else if (oldEdge != nullptr) { - // Copy likelihood from old edge, if any. + // Copy likelihood from old edge. // flow->setLikelihood(oldEdge->getLikelihood()); } diff --git a/src/coreclr/jit/fgopt.cpp b/src/coreclr/jit/fgopt.cpp index 4c6bf73b94f..0f20dccd2fe 100644 --- a/src/coreclr/jit/fgopt.cpp +++ b/src/coreclr/jit/fgopt.cpp @@ -1837,23 +1837,21 @@ bool Compiler::fgOptimizeSwitchBranches(BasicBlock* block) // Update edge likelihoods // Note old edge may still be "in use" so we decrease its likelihood. // - if (oldEdge->hasLikelihood()) + + // We want to move this much likelihood from old->new + // + const weight_t likelihoodFraction = oldEdge->getLikelihood() / (oldEdge->getDupCount() + 1); + + if (newEdge->getDupCount() == 1) { - // We want to move this much likelihood from old->new - // - const weight_t likelihoodFraction = oldEdge->getLikelihood() / (oldEdge->getDupCount() + 1); - - if (newEdge->getDupCount() == 1) - { - newEdge->setLikelihood(likelihoodFraction); - } - else - { - newEdge->addLikelihood(likelihoodFraction); - } - - oldEdge->addLikelihood(-likelihoodFraction); + newEdge->setLikelihood(likelihoodFraction); } + else + { + newEdge->addLikelihood(likelihoodFraction); + } + + oldEdge->addLikelihood(-likelihoodFraction); // we optimized a Switch label - goto REPEAT_SWITCH to follow this new jump modified = true; diff --git a/src/coreclr/jit/indirectcalltransformer.cpp b/src/coreclr/jit/indirectcalltransformer.cpp index 87120014abb..0839f9fc2a0 100644 --- a/src/coreclr/jit/indirectcalltransformer.cpp +++ b/src/coreclr/jit/indirectcalltransformer.cpp @@ -603,8 +603,7 @@ private: assert(prevCheckBlock->KindIs(BBJ_ALWAYS)); assert(prevCheckBlock->JumpsToNext()); FlowEdge* const prevCheckThenEdge = prevCheckBlock->GetTargetEdge(); - assert(prevCheckThenEdge->hasLikelihood()); - weight_t checkLikelihood = max(0.0, 1.0 - prevCheckThenEdge->getLikelihood()); + weight_t checkLikelihood = max(0.0, 1.0 - prevCheckThenEdge->getLikelihood()); JITDUMP("Level %u Check block " FMT_BB " success likelihood " FMT_WT "\n", checkIdx, checkBlock->bbNum, checkLikelihood); @@ -1086,9 +1085,8 @@ private: // just use that to figure out the "else" likelihood. // assert(checkBlock->KindIs(BBJ_ALWAYS)); - FlowEdge* const checkThenEdge = checkBlock->GetTargetEdge(); - assert(checkThenEdge->hasLikelihood()); - weight_t elseLikelihood = max(0.0, 1.0 - checkThenEdge->getLikelihood()); + FlowEdge* const checkThenEdge = checkBlock->GetTargetEdge(); + weight_t elseLikelihood = max(0.0, 1.0 - checkThenEdge->getLikelihood()); // CheckBlock flows into elseBlock unless we deal with the case // where we know the last check is always true (in case of "exact" GDV)