Skip to content

JIT: Precompute func-app element stride in VN chunks#126920

Merged
EgorBo merged 2 commits intodotnet:mainfrom
EgorBo:egorbo/vn-precompute-funcapp-stride
Apr 15, 2026
Merged

JIT: Precompute func-app element stride in VN chunks#126920
EgorBo merged 2 commits intodotnet:mainfrom
EgorBo:egorbo/vn-precompute-funcapp-stride

Conversation

@EgorBo
Copy link
Copy Markdown
Member

@EgorBo EgorBo commented Apr 14, 2026

Precompute and cache the element size for func-app VN chunks in Chunk::m_funcAppElemSize, initialized once in the constructor. PointerToFuncApp now multiplies by the cached stride instead of recomputing sizeof(VNFunc) + sizeof(ValueNum) * arity on every call.

This is a minor TP improvement — PointerToFuncApp is called from GetVNFunc (one of the hottest VN helpers, ~80 call sites) and from all VN creation paths.

Note

This PR was authored with help from GitHub Copilot.

Precompute and cache the element size for func-app chunks
(sizeof(VNFunc) + sizeof(ValueNum) * arity) in Chunk::m_funcAppElemSize,
initialized once in the constructor. PointerToFuncApp now uses a single
multiply by the cached stride instead of recomputing the expression on
every call. This reduces work on a hot path (GetVNFunc and all VN
creation sites that call PointerToFuncApp).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 14, 2026 23:23
@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 Apr 14, 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.

Copy link
Copy Markdown
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 optimizes Value Number (VN) func-app chunk access in the JIT by precomputing and caching the per-element stride in each ValueNumStore::Chunk, so hot helpers (notably GetVNFuncPointerToFuncApp) avoid recomputing the stride on every access.

Changes:

  • Added Chunk::m_funcAppElemSize to cache the func-app element stride (0 for non-func chunks).
  • Initialized m_funcAppElemSize once in the Chunk constructor for CEA_Func{0..4} and used it for allocation sizing (Func1..4) and indexing.
  • Updated PointerToFuncApp to use the cached stride for address computation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/coreclr/jit/valuenum.h Adds cached func-app element stride to Chunk and uses it in PointerToFuncApp.
src/coreclr/jit/valuenum.cpp Initializes cached stride in Chunk constructor and uses it for func-app allocations (Func1..4).

@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented Apr 15, 2026

Diffs. No memory size overhead on x64 (Chunk struct remains 24 bytes), very minor impact on Chunk size on 32bit.

@EgorBo EgorBo merged commit 1a77225 into dotnet:main Apr 15, 2026
134 of 139 checks passed
@EgorBo EgorBo deleted the egorbo/vn-precompute-funcapp-stride branch April 15, 2026 12:07
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