-
Notifications
You must be signed in to change notification settings - Fork 5.1k
JIT: Don't transform infinite loops in fgOptimizeBranchToEmptyUnconditional
#116822
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: Don't transform infinite loops in fgOptimizeBranchToEmptyUnconditional
#116822
Conversation
/azp run runtime-jit-experimental |
Azure Pipelines successfully started running 1 pipeline(s). |
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
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 PR prevents the JIT from folding an unconditional jump into a target that immediately jumps back, avoiding an unintended infinite loop.
Key changes:
- Introduce a new
bDestTarget
local and disable optimization when it would create a loop. - Update the removed-block check to use the
bDestTarget
variable. - Retain existing try-region and removal logic.
Comments suppressed due to low confidence (1)
src/coreclr/jit/fgopt.cpp:1307
- Consider adding a unit test that covers the case where an empty block jumps back to its predecessor, verifying that
fgOptimizeBranchToEmptyUnconditional
does not perform the redirection and avoids an infinite loop.
if (bDestTarget->GetUniqueSucc() == bDest)
// entering an infinite loop. | ||
// |
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.
[nitpick] This standalone //
line is empty—consider removing it or merging the adjacent comment blocks to improve readability.
// entering an infinite loop. | |
// | |
// entering an infinite loop, which would cause issues. |
Copilot uses AI. Check for mistakes.
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.
The rest of this method follows this convention -- perhaps we ought to unify the comment style at some point.
@dotnet/jit-contrib PTAL. No diffs. |
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.
I believe this has broken this way before though I can't find any relevant issue.
Any way you can think of to avoid this sort of problem more definitively?
The caller has a check for
For the infinite loop to trigger, |
Now that I'm thinking about it, I don't see why we need |
If that doesn't pan out we can take this fix and work on a more major revamping next release. |
@AndyAyersMS the diffs are on the order of tens of thousands of bytes, in both directions. From a quick look, I can see that the different order of transformations during flow opts sometimes leaves branches swapped, churning downstream phases. These look like good opportunities to investigate, but I think we ought to take the easy fix for now. |
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.
Sounds good.
/ba-g Build Analysis not picking up HostActivation.Tests known failure |
Fixes #116701 (comment).