Skip to content

JIT: Expand simple stfld addresses early and spill data nodes to retain evaluation order#125141

Merged
jakobbotsch merged 7 commits intodotnet:mainfrom
jakobbotsch:expand-stfld-early
Mar 9, 2026
Merged

JIT: Expand simple stfld addresses early and spill data nodes to retain evaluation order#125141
jakobbotsch merged 7 commits intodotnet:mainfrom
jakobbotsch:expand-stfld-early

Conversation

@jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Mar 3, 2026

Our stfld importation would create STORE(FIELD_ADDR(obj), data). However, that results in an evaluation order of
obj -> 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_ADDR into 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:

  1. Introduce early expansion of simple field addresses, in some of the cases where we know the implicit nullcheck of the store will be enough;
  2. Spill the data node when we couldn't do the above if the data node cannot be reordered with the null check.

Fix #125124

Copilot AI review requested due to automatic review settings March 3, 2026 18:05
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 3, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a 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 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-offset stfld.
  • 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 impCanReorderWithNullCheck helper and adjust String.get_Length intrinsic import by removing a redundant GTF_EXCEPT annotation.

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.

Copilot AI review requested due to automatic review settings March 4, 2026 11:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

@jakobbotsch
Copy link
Member Author

/azp run runtime-coreclr superpmi-diffs

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI review requested due to automatic review settings March 9, 2026 14:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

@jakobbotsch jakobbotsch marked this pull request as ready for review March 9, 2026 18:03
@jakobbotsch jakobbotsch changed the title JIT: Expand simple stfld addresses early JIT: Expand simple stfld addresses early and spill data nodes to retain evaluation order Mar 9, 2026
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @EgorBo

Diffs. Overall improvements. Some small regressions in a few places, but that's probably something we can live with given this is a bug fix.

@jakobbotsch
Copy link
Member Author

/ba-g Build analysis stuck in progress

@jakobbotsch jakobbotsch merged commit e3b528c into dotnet:main Mar 9, 2026
141 of 143 checks passed
@jakobbotsch jakobbotsch deleted the expand-stfld-early branch March 9, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: Reordering of data and null check for stores

3 participants