-
Notifications
You must be signed in to change notification settings - Fork 5k
[release/8.0-staging] JIT: Fix loop recognition bug in .NET 8 #114457
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
[release/8.0-staging] JIT: Fix loop recognition bug in .NET 8 #114457
Conversation
A loop preheader can't be a callfinally pair tail. Fixes dotnet#108811.
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 reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
Files not reviewed (1)
- src/tests/JIT/Regression/JitBlue/Runtime_108811/Runtime_108811.csproj: Language not supported
} | ||
} | ||
// Found the accurate length of decrypted data | ||
while (decryptedData[decryptedByteCount - 1] == 0 && decryptedByteCount > 0) |
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 while-loop condition checks the array element before confirming that decryptedByteCount is greater than 0, which could lead to an out-of-range access. Consider swapping the operands to 'while (decryptedByteCount > 0 && decryptedData[decryptedByteCount - 1] == 0)'.
while (decryptedData[decryptedByteCount - 1] == 0 && decryptedByteCount > 0) | |
while (decryptedByteCount > 0 && decryptedData[decryptedByteCount - 1] == 0) |
Copilot uses AI. Check for mistakes.
@BruceForstall PTAL fyi @jeffschwMSFT |
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.
lgtm. we will take for consideration in 8.0.x
@carlossanlop, please merge this PR. |
Hi @JulieLeeMSFT ! PR owners can merge their own PRs in the staging branches whenever they're ready. No need to wait for me to merge them. All team members have merge permission here. |
@JulieLeeMSFT I think I see why you're asking for me to merge. The PR's "Squash & merge" button is blocked by Build Analysis: This leg always fails in release branches by design, because we need PR owners to look at the failures and confirm nothing is caused by their change. If it looks good and existing failures are all unrelated, you can add the |
I see a new failure but it does not seem related to this PR. Let me create a known build issue for it, give me a few mins:
|
/ba-g
Failure is the issue Carlos spotted (a test case added for this bug, evidently not wasm compatible?) |
Edit: I saw your edit 😄 |
No you were right -- the issue is the test I just added for this bug doesn't seem to be wasm-friendly. The test case is not in any other branch yet (this bug doesn't happen in main or with .net 9 so this was not a backport). I don't know the right exclusion syntax just yet... |
Think it's just adding to issues.target. Is there time to push a fix for this? Or should I merge and PR that separately? |
Code complete is on Monday April 14th so there is time. If you run into problems with issues.targets you can alternatively use |
runtime (Build browser-wasm linux Release AllSubsets_Mono_RuntimeTests monointerpreter) is dead but CI doesn't realize it. |
yeah, Build Analysis agrees. this is good to go. |
8690dbe
into
dotnet:release/8.0-staging
A loop preheader can't be a callfinally pair tail.
Fixes #108811.
Customer Impact
Silent bad code generation. Programs may return incorrect results after running for a while. Failure happens once key methods are tiered up.
At a source level this requires a
try/finally
(say from ausing
) with a loop with invariant expression immediately thereafter, for instance:In the JIT IR, the
using
is commonly followed with code to invoke the finally, and this finally invocation code sequence has special restrictions that are not always being honored.In particular the optimizer may attempt to hoist the invariant computation out of the loop and inadvertently place the computation in a "callfinally pair tail" block that is supposed to remain empty. And doing hosting this way leads to improper code generation for the hoisted value.
Similar constructs can arise from other source patterns or via inlining.
Regression
From the linked bug, the customer indicates the program ran properly on .NET 6.
Testing
Verified the customer test case is now fixed. Issue was flagged by a checked build of the jit, so we know it is uncommon.
We currently do not have SPMI artifacts for .NET 8 but can try and recreate them to verify that there are no unexpected changes.
This part of the JIT was substantially revised in .NET 9, which does not have this bug.
Risk
Low, this inhibits recognition of certain problematic loops and ensuing loop optimizations.