Skip to content

JIT: Expand simple stfld addresses early#125141

Draft
jakobbotsch wants to merge 6 commits intodotnet:mainfrom
jakobbotsch:expand-stfld-early
Draft

JIT: Expand simple stfld addresses early#125141
jakobbotsch wants to merge 6 commits intodotnet:mainfrom
jakobbotsch:expand-stfld-early

Conversation

@jakobbotsch
Copy link
Member

Alternative to #125126

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.


[Fact]
public static void TestEntryPoint()
{
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

The test relies on the initial value of the static flag s_barCalled. To make the test self-contained (and resilient to potential re-runs within the same process), consider explicitly resetting s_barCalled to false at the start of TestEntryPoint before executing the scenario.

Suggested change
{
{
s_barCalled = false;

Copilot uses AI. Check for mistakes.
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.

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.

2 participants