diff --git a/src/coreclr/jit/fgprofile.cpp b/src/coreclr/jit/fgprofile.cpp index 31d7c208ebaf01..d5667a2b1c90c2 100644 --- a/src/coreclr/jit/fgprofile.cpp +++ b/src/coreclr/jit/fgprofile.cpp @@ -3000,6 +3000,8 @@ bool flowList::setEdgeWeightMaxChecked(BasicBlock::weight_t newWeight, void flowList::setEdgeWeights(BasicBlock::weight_t theMinWeight, BasicBlock::weight_t theMaxWeight, BasicBlock* bDst) { assert(theMinWeight <= theMaxWeight); + assert(theMinWeight >= 0.0f); + assert(theMaxWeight >= 0.0f); JITDUMP("Setting edge weights for " FMT_BB " -> " FMT_BB " to [" FMT_WT " .. " FMT_WT "]\n", getBlock()->bbNum, bDst->bbNum, theMinWeight, theMaxWeight); diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index 26e2e15f375718..3a5cfaa7f5b5bf 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -4467,7 +4467,7 @@ bool Compiler::optInvertWhileLoop(BasicBlock* block) // Note "next" is the loop top block, not bTest's bbNext, // we'll call this latter block "after". // - BasicBlock::weight_t const testToNextLikelihood = weightNext / weightTest; + BasicBlock::weight_t const testToNextLikelihood = min(1.0f, weightNext / weightTest); BasicBlock::weight_t const testToAfterLikelihood = 1.0f - testToNextLikelihood; // Adjust edges out of bTest (which now has weight weightNext)