Uh oh!
There was an error while loading. Please reload this page.
JIT: invert oversize loops with their own bounds checks - #129722
Conversation
Relax optTryInvertWhileLoop's heuristic for loops with bounds checks in their own blocks (not just in nested loop blocks). Remove "too big to clone" and "1.25x liberal" limits. Bail out when bounds checks live only in nested loops. Nested loops can be inverted and cloned on their own merits. Partially mitigates some cases in issue dotnet#116486.
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Pull request overview
This PR updates the JIT’s loop inversion heuristic in optTryInvertWhileLoop to be more permissive for larger loops when bounds checks suggest loop cloning could be profitable, and to avoid using prior “too big / 1.25x” size caps.
Changes:
- Reworks inversion size gating to track bounds checks separately for the current loop vs. nested loops.
- Removes the “too big to clone” and “1.25x liberal” rejection logic, deferring more size decisions to later duplication/cloning budgets.
- Adds a specific bailout for the “bounds checks only exist in nested loops” case.
Uh oh!
There was an error while loading. Please reload this page.
AndyAyersMS
commented
Jun 23, 2026
Still messing with inversion heuristics. Probably needs more tweaking. |
AndyAyersMS
commented
Jun 23, 2026
@jakobbotsch PTAL Allow a bit more inversion, partially decouple from cloning. |
AndyAyersMS
commented
Jun 23, 2026
@EgorBot -intel -arm --filter "Benchstone.BenchF.Romber" |
Uh oh!
There was an error while loading. Please reload this page.
AndyAyersMS
commented
Jun 23, 2026
More code size than I was expecting... I wish there was some way to estimate where we are net-net versus .NET 10, since we also have had a number of large reductions. Tempted to say we should take this as-is. I can also keep looking for indicators that inversion is not going to be beneficial. |
BoyBaykiller
commented
Jun 23, 2026
I wonder if with this we invert the loop in #121533 (comment) again. |
AndyAyersMS
commented
Jun 23, 2026
Note Generated with AI assistance. @BoyBaykiller yes — confirmed. With this PR your JIT dump side-by-side with current main (8216cbe) vs this PR: The |
Uh oh!
There was an error while loading. Please reload this page.
AndyAyersMS
commented
Jun 24, 2026
AndyAyersMS
commented
Jun 24, 2026
@EgorBot -intel -arm --filter "Benchstone.BenchF.Romber" |
AndyAyersMS
commented
Jun 24, 2026
I can never get egorbot syntax right the first time. |
AndyAyersMS
commented
Jun 24, 2026
@EgorBot -intel -arm --filter Benchstone.BenchF.Romber.Test |
Relax `optTryInvertWhileLoop`'s heuristic for loops with bounds checks in their own blocks (not just in nested loop blocks). Remove "too big to clone" and "1.25x liberal" limits. Bail out when **any** nested loop has its own bounds checks: those nested loops will be inverted and cloned on their own merits, and inverting (then cloning) this larger outer loop on top of that just duplicates the entire nested body and disrupts downstream LICM/CSE on sibling code (e.g. `Benchstone.BenchF.InvMt`). Partially mitigates some cases in issue #116486.
Relax
optTryInvertWhileLoop's heuristic for loops with bounds checks in their own blocks (not just in nested loop blocks). Remove "too big to clone" and "1.25x liberal" limits.Bail out when any nested loop has its own bounds checks: those nested loops will be inverted and cloned on their own merits, and inverting (then cloning) this larger outer loop on top of that just duplicates the entire nested body and disrupts downstream LICM/CSE on sibling code (e.g.
Benchstone.BenchF.InvMt).Partially mitigates some cases in issue #116486.