-
Notifications
You must be signed in to change notification settings - Fork 5.1k
JIT: Graph-based loop inversion #116017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JIT: Graph-based loop inversion #116017
Conversation
Rewrite loop inversion to be graph based and to use the new loop representation.
… from old inversion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request implements graph-based loop inversion in the JIT, aiming to improve IR transformation behavior and diagnostics.
- In fgopt.cpp, the logic now returns true to indicate IR modifications in edge cases, and error handling for stmt cloning has been shifted to an assertion.
- In fgdiagnostic.cpp, a more descriptive debug message is added for loop exits with non-loop predecessors.
- In compiler.h, the API is updated to use a more specific function (optTryInvertWhileLoop) with a refined parameter type.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/coreclr/jit/fgopt.cpp | Updated control flow for IR modification detection and error handling |
src/coreclr/jit/fgdiagnostic.cpp | Enhanced loop diagnostic messaging |
src/coreclr/jit/compiler.h | Updated API for loop inversion with adjusted parameter type |
Comments suppressed due to low confidence (2)
src/coreclr/jit/fgopt.cpp:2713
- Changing the response for non-RelOp conditions from returning false to returning true alters the behavior of IR modifications. Verify that this change is intentional and that downstream code correctly handles the modified IR state.
if (!condTree->OperIsCompare())
src/coreclr/jit/compiler.h:7123
- The API change from 'optInvertWhileLoop(BasicBlock* block)' to 'optTryInvertWhileLoop(FlowGraphNaturalLoop* loop)' requires ensuring that all call sites and semantic expectations are updated accordingly.
bool optTryInvertWhileLoop(FlowGraphNaturalLoop* loop);
Here's aspnet:
A size limit of 100 seems like a good starting point. That should help trim out the runaway cloning for a few large loops in |
Diffs are now a net size reduction. Unsurprisingly, we have lots of size increases from finding new inversion candidates, as well as size decreases from bailing on large loops previously inverted by the lexical implementation. Whether we are doing more or less inversion overall depends on the collection. For example:
@AndyAyersMS @jakobbotsch do these diffs seem like too much of a swing in the opposite direction? |
I think the TP cost is ok here. For CQ I don't know what experiments to try other than running a lot of benchmarks, and for that the lab data will be a better guide. P6 snap looks like 6/13 so we have time to get data back and change our minds. So let's try this and see. |
@AndyAyersMS I think that's a reasonable plan, though we'll want #115850 merged in around the same time to see improvements in the list enumeration scenarios we're targeting. That change will incur a similarly large number of diffs; are you ok trying these back-to-back before the next snap? |
Maybe not immeidately back to back -- a day apart? |
Sure, sounds reasonable. |
Succeeds #113709 (GitHub won't let me reopen it). Part of #107749 and #108901. Fixes #50204.