Skip to content

Use user-arg accessors when expanding runtime lookups#130949

Open
tannergooding wants to merge 2 commits into
dotnet:mainfrom
tannergooding:wasm-expand-rtlookups-user-args
Open

Use user-arg accessors when expanding runtime lookups#130949
tannergooding wants to merge 2 commits into
dotnet:mainfrom
tannergooding:wasm-expand-rtlookups-user-args

Conversation

@tannergooding

Copy link
Copy Markdown
Member

fgExpandRuntimeLookupsForCall indexed the runtime-lookup helper call's arguments with the raw CountArgs/GetArgByIndex accessors, assuming exactly its two user args (genericCtx, signatureCns).

On wasm, AddFinalArgsAndDetermineABIInfo prepends a non-user WasmShadowStackPointer arg to the front of every managed call during global morph, which runs before fgExpandRuntimeLookups. That leading arg shifts the raw indices, so:

  • assert(call->gtArgs.CountArgs() == 2) fires (there are three args), and
  • with asserts off, GetArgByIndex(0)/GetArgByIndex(1) read the shadow-stack pointer and the context instead of the context and the signature.

Switch to CountUserArgs/GetUserArgByIndex, which skip non-user args (r2r cell, wasm sp) the same way the rest of the JIT already reads helper-call args. This is behavior-identical on targets that don't prepend such args, and fixes shared-generic runtime lookups on wasm.

This shows up across shared-generic ([System.__Canon]) methods; it accounts for ~10k of the assert-failing methods in a wasm SuperPMI altjit replay over the libraries/coreclr test collections.

Note

This PR was authored with GitHub Copilot.

fgExpandRuntimeLookupsForCall indexed the helper call's arguments with the raw CountArgs/GetArgByIndex accessors, assuming the runtime-lookup helper has exactly its two user args (genericCtx, signatureCns). On wasm, AddFinalArgsAndDetermineABIInfo prepends a non-user WasmShadowStackPointer arg to every managed call during global morph, which runs before the runtime-lookup expansion phase. That leading arg shifted the raw indices, tripping assert(CountArgs() == 2) and, with asserts off, reading the context and signature from the wrong nodes.

Switch to CountUserArgs/GetUserArgByIndex, which skip non-user args (r2r cell, wasm sp) the same way the rest of the JIT already reads helper-call args. This is identical on targets that don't prepend such args.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 17, 2026 04:14
@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 17, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 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.

@tannergooding

tannergooding commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

CC. @dotnet/jit-contrib, @adamperlin, @lewing this fixes around 10k helperexpansion asserts from SPMI, is product code impacting

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 fgExpandRuntimeLookupsForCall to read runtime-lookup helper-call arguments via the “user arg” APIs (CountUserArgs / GetUserArgByIndex) instead of raw indices, so non-user arguments prepended during morphing (e.g., on TARGET_WASM) don’t shift the expected (genericCtx, signatureCns) positions.

Changes:

  • Switch runtime-lookup helper-call arity assertion from CountArgs() to CountUserArgs().
  • Switch argument reads from GetArgByIndex(0/1) to GetUserArgByIndex(0/1) when extracting genericCtx and signatureCns.
Show a summary per file
File Description
src/coreclr/jit/helperexpansion.cpp Uses user-arg accessors for runtime lookup helper-call argument indexing to avoid non-user arg prepends shifting indices (notably on wasm).

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread src/coreclr/jit/helperexpansion.cpp
Both fgExpandThreadLocalAccessForCall and fgExpandStackArrayAllocation
indexed the IL args by raw position, which the wasm shadow-stack arg
prepended during morph shifts. Switch them to the user-arg accessors used
elsewhere in the file so they skip the non-user leading arg.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 17, 2026 04:40

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.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new

@tannergooding

Copy link
Copy Markdown
Member Author

CC. @dotnet/wasm-contrib

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