Skip to content

JIT: allocate and initialize the LSRA VarToRegMaps in one shot - #131400

Draft
EgorBo wants to merge 2 commits into
dotnet:mainfrom
EgorBo:jit-lsra-varregmaps
Draft

JIT: allocate and initialize the LSRA VarToRegMaps in one shot#131400
EgorBo wants to merge 2 commits into
dotnet:mainfrom
EgorBo:jit-lsra-varregmaps

Conversation

@EgorBo

@EgorBo EgorBo commented Jul 26, 2026

Copy link
Copy Markdown
Member

initVarRegMaps made two arena allocations per basic block and filled them one byte at a time, so it cost O(blocks * tracked locals) scalar stores plus 2 * blocks allocator calls.

All of the in/out maps are now allocated as a single block and filled with one memset. They are only ever reached through inVarToRegMaps/outVarToRegMaps, which are not modified after this point, so the maps can live contiguously. Keeping a block's in and out map adjacent also helps locality during resolution.

initVarRegMaps made two arena allocations per basic block and filled them a
byte at a time, so the cost was O(blocks * tracked locals) of scalar stores
plus 2 * blocks allocator calls. Allocate all of the in/out maps as a single
block and fill it with one memset instead; the maps are only ever reached
through inVarToRegMaps/outVarToRegMaps, which are not modified afterwards.

No diffs. Throughput (SPMI, instructions retired):
  libraries.pmi      -0.51%
  aspnet2.run        -0.68%
  benchmarks.run_pgo -0.63%
  realworld.run      -0.61%
  coreclr_tests.run  -0.29%

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6d486224-7977-4f41-8410-21bf27321cee
Copilot AI review requested due to automatic review settings July 26, 2026 22:33
@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 26, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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 optimizes LSRA variable-to-register boundary maps initialization by allocating all per-block in/out VarToRegMaps in one contiguous arena allocation and initializing them in bulk, reducing allocator churn and per-element scalar initialization overhead.

Changes:

  • Allocate all block in/out var-to-reg maps as one contiguous regNumberSmall[] buffer.
  • Initialize the full buffer in one pass (using memset when regNumberSmall is 1 byte).
  • Point inVarToRegMaps[i] / outVarToRegMaps[i] at the appropriate slices of the contiguous buffer.

Comment thread src/coreclr/jit/lsra.cpp Outdated
@EgorBo
EgorBo marked this pull request as draft July 26, 2026 22:52
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6d486224-7977-4f41-8410-21bf27321cee
Copilot AI review requested due to automatic review settings July 26, 2026 23:03

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

Comment thread src/coreclr/jit/lsra.cpp
Comment on lines +2010 to 2019
if (sizeof(regNumberSmall) == 1)
{
memset(maps, REG_STK, entryCount * sizeof(regNumberSmall));
}
else
{
for (size_t j = 0; j < entryCount; j++)
{
inVarToRegMap[j] = REG_STK;
outVarToRegMap[j] = REG_STK;
maps[j] = REG_STK;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be just the loop everywhere, it should be optimized to memset.

TP gains may actually be a bit misleading, I am not sure if we count instructions executed inside memset.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TP gains may actually be a bit misleading, I am not sure if we count instructions executed inside memset.

Disregard this, I double checked and we do statically link so clrjit does have its own memset copy. So it should be getting counted properly.

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.

3 participants