Skip to content

JIT: Coalesce adjacent constant-address stores#130107

Merged
EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:egorbo/coalesce-const-addr-stores
Jul 7, 2026
Merged

JIT: Coalesce adjacent constant-address stores#130107
EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:egorbo/coalesce-const-addr-stores

Conversation

@EgorBo

@EgorBo EgorBo commented Jul 2, 2026

Copy link
Copy Markdown
Member

Extend LowerStoreCoalescing to recognize STOREIND nodes whose address is an absolute (non-relocatable) constant, e.g. writes to adjacent fields of a non-GC static struct:

private struct S2 { public int A, B; }

private static S2 s_static2;

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
private static void Test()
{
    s_static2.A = 1;
    s_static2.B = 2;
}

Codegen for Test on win-x64:

-       mov      rax, 0x1E049543570      ; data for Program:s_static2
-       mov      dword ptr [rax], 1
-       mov      rax, 0x1E049543574
-       mov      dword ptr [rax], 2
+       mov      rax, 0x200000001
+       mov      rcx, 0x1F549543570
+       mov      qword ptr [rcx], rax

Diffs

Basically, I represent it as baseAddr being null and offset being the full absolute address, the rest of the code is the same, just had to bump the type of offset from int to ssize_t

Extend LowerStoreCoalescing to recognize STOREIND nodes whose address is an absolute (non-relocatable) constant, such as writes to adjacent fields of a non-GC static struct. The constant address is treated as the offset from a common null base so adjacent stores can be merged into a single wider store.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 2, 2026 02:24
@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 Jul 2, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@EgorBo

EgorBo commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

@MihuBot -nuget

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 extends JIT lowering-time store coalescing so that adjacent STOREIND nodes whose address is a non-relocatable absolute constant can be recognized as targeting the same “base” and then merged into a single wider store, while updating offset-related arithmetic/alignment checks to support that new address form.

Changes:

  • Teach GetLoadStoreCoalescingData to treat non-relocatable constant addresses as (base=null, offset=<absolute address>) so adjacent constant-address stores can be matched/coalesced.
  • Widen LoadStoreCoalescingData::offset to ssize_t and adjust related offset math, alignment, and atomicity checks to account for baseAddr == nullptr.
  • Update the store-coalescing rewrite path to correctly update either GT_LEA offsets or constant-address GT_CNS_INT values after coalescing.

Reviewed changes

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

File Description
src/coreclr/jit/lower.h Widen store-coalescing offset storage to ssize_t.
src/coreclr/jit/lower.cpp Add constant-address handling for coalescing + adjust atomicity/alignment and rewrite logic accordingly.

Comment thread src/coreclr/jit/lower.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 2, 2026 02:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/jit/lower.cpp
Comment thread src/coreclr/jit/lower.cpp
Comment thread src/coreclr/jit/lower.cpp
@EgorBo

EgorBo commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

PTAL @AndyAyersMS as someone who recently touched this area, cc @dotnet/jit-contrib

@EgorBo EgorBo requested a review from AndyAyersMS July 6, 2026 20:37
@EgorBo EgorBo enabled auto-merge (squash) July 7, 2026 22:02
@EgorBo EgorBo merged commit f121231 into dotnet:main Jul 7, 2026
139 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 8, 2026
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.

4 participants