Skip to content

Commit

Permalink
Additional cost checks
Browse files Browse the repository at this point in the history
  • Loading branch information
amanasifkhalid committed Nov 15, 2024
1 parent 4c4d0c9 commit 4ac1036
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4950,12 +4950,16 @@ weight_t Compiler::ThreeOptLayout::GetCost(BasicBlock* block, BasicBlock* next)

const weight_t maxCost = block->bbWeight;
const FlowEdge* fallthroughEdge = compiler->fgGetPredForBlock(next, block);
assert(maxCost >= BB_ZERO_WEIGHT);

if (fallthroughEdge != nullptr)
{
// The edge's weight should never exceed its source block's weight,
// but handle negative results from rounding errors in getLikelyWeight(), just in case
return max(0.0, maxCost - fallthroughEdge->getLikelyWeight());
const weight_t edgeWeight = fallthroughEdge->getLikelyWeight();
assert(edgeWeight >= BB_ZERO_WEIGHT);
assert(edgeWeight <= maxCost);
return maxCost - edgeWeight;
}

return maxCost;
Expand Down

0 comments on commit 4ac1036

Please sign in to comment.