Skip to content

Commit

Permalink
JIT: Relax cost improvement assert in 3-opt layout (#109835)
Browse files Browse the repository at this point in the history
Follow-up to #109741. Fixes #109831. Fixes #109905. Fixes #109903.

Tolerate some floating-point imprecision when comparing the cost of a new layout produced by 3-opt to the previous layout's cost. The JitStress failures I looked all stressed JitOptRepeat, which can produce absurdly large loop block weights by rerunning optSetBlockWeights. Manually inspecting the layout decisions made for these methods shows 3-opt making reasonable transformations, but the assertion newLayoutCost < currLayoutCost fails due to imprecision from summing large block weights. Having a backup check that the layout costs are within some epsilon seems like a reasonable fix.
  • Loading branch information
amanasifkhalid authored Nov 18, 2024
1 parent f3cdf14 commit f87428b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5375,9 +5375,10 @@ bool Compiler::ThreeOptLayout::RunThreeOptPass(BasicBlock* startBlock, BasicBloc
}

#ifdef DEBUG
// Ensure the swap improved the overall layout
// Ensure the swap improved the overall layout. Tolerate some imprecision.
const weight_t newLayoutCost = GetLayoutCost(startPos, endPos);
assert(newLayoutCost < currLayoutCost);
assert((newLayoutCost < currLayoutCost) ||
Compiler::fgProfileWeightsEqual(newLayoutCost, currLayoutCost, 0.001));
currLayoutCost = newLayoutCost;
#endif // DEBUG
}
Expand Down

0 comments on commit f87428b

Please sign in to comment.