JIT: Expand simple stfld addresses early and spill data nodes to retain evaluation order#125141
Merged
jakobbotsch merged 7 commits intodotnet:mainfrom Mar 9, 2026
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates CoreCLR JIT import/morph logic to preserve IL evaluation order for stfld when the field address involves a large offset (which may require an explicit null check), and adds a regression test to cover the scenario.
Changes:
- Add a new JIT regression test (
Runtime_125124) validating that RHS evaluation is not reordered past a null check for large-offsetstfld. - Teach the importer to expand “simple” instance field store addresses early (when the offset is not “big”), avoiding the need for an explicit null check in those cases.
- Add
impCanReorderWithNullCheckhelper and adjustString.get_Lengthintrinsic import by removing a redundantGTF_EXCEPTannotation.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tests/JIT/Regression/Regression_ro_1.csproj | Adds the new regression test source file to the test project. |
| src/tests/JIT/Regression/JitBlue/Runtime_125124/Runtime_125124.cs | New regression test covering stfld RHS vs null-check ordering for large offsets. |
| src/coreclr/jit/lclmorph.cpp | Updates local address recognition to account for GT_LCL_ADDR offsets during struct field promotion/address morphing. |
| src/coreclr/jit/importercalls.cpp | Removes redundant manual GTF_EXCEPT marking for String.get_Length (array-length node already annotates exceptions). |
| src/coreclr/jit/importer.cpp | Adds reorderability helper and implements early expansion of small-offset stfld addresses with updated spilling logic. |
| src/coreclr/jit/compiler.h | Declares the new impCanReorderWithNullCheck helper. |
This was referenced Mar 3, 2026
Member
Author
|
/azp run runtime-coreclr superpmi-diffs |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Author
jakobbotsch
commented
Mar 9, 2026
EgorBo
reviewed
Mar 9, 2026
EgorBo
approved these changes
Mar 9, 2026
This was referenced Mar 9, 2026
Open
Member
Author
|
/ba-g Build analysis stuck in progress |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Our
stfldimportation would createSTORE(FIELD_ADDR(obj), data). However, that results in an evaluation order ofobj -> nullcheck(obj) -> data -> store
when the order needs to be
obj -> data -> nullcheck(obj) -> store
Morph would usually hide the problem because it folds the
FIELD_ADDRinto the store itself, and relies on the implicit nullcheck of the store. This PR is not addressing the fact that morph makes this incorrect transformation. I opened #125343 for that.To fix the problem this PR does two things:
Fix #125124