Skip to content

JIT: Coalesce stores from struct copies#130535

Draft
EgorBo wants to merge 1 commit into
dotnet:mainfrom
EgorBo:egor/jit-struct-store-coalescing
Draft

JIT: Coalesce stores from struct copies#130535
EgorBo wants to merge 1 commit into
dotnet:mainfrom
EgorBo:egor/jit-struct-store-coalescing

Conversation

@EgorBo

@EgorBo EgorBo commented Jul 10, 2026

Copy link
Copy Markdown
Member

Allows existing store coalescing to merge non-GC field stores produced by struct copies.

Int128 _fld;

void Foo1(out Int128 x) => x = new Int128(2L, 1L);

void Foo2() => _fld = 123456789;
 Foo1:
- mov      qword ptr [rdx], 1
- mov      qword ptr [rdx+0x08], 2
+ vmovups  xmm0, xmmword ptr [reloc @RWD00]
+ vmovups  xmmword ptr [rdx], xmm0

 Foo2:
- mov      qword ptr [rcx+0x08], 0x75BCD15
- xor      eax, eax
- mov      qword ptr [rcx+0x10], rax
+ vmovss   xmm0, dword ptr [reloc @RWD00]
+ vmovups  xmmword ptr [rcx+0x08], xmm0

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f267b92e-719f-4b0d-b19f-eab8f97611f5
Copilot AI review requested due to automatic review settings July 10, 2026 23:16
@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 10, 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.

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 updates JIT copy-block morphing so that when a struct copy is expanded into multiple field stores, the non-GC field STOREIND nodes are marked with GTF_IND_ALLOW_NON_ATOMIC. This enables existing lowering-time store coalescing to legally merge adjacent non-volatile stores (e.g., two 8-byte stores into one 16-byte SIMD store) without being blocked by atomicity constraints.

Changes:

  • In MorphCopyBlockHelper::CopyFieldByField, mark per-field indirect stores as GTF_IND_ALLOW_NON_ATOMIC when they originate from a copyBlk and the field type is not GC (!varTypeIsGC(srcType)).
  • This allows Lowering’s store coalescing (LowerStoreCoalescing / LowerCheckCoalescedStoreAtomicity) to treat these adjacent stores as eligible for wider, potentially unaligned, non-atomic combined stores.

@EgorBo

EgorBo commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

@MihuBot -nuget

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