Skip to content

JIT: allow stack allocation of R2R arrays allocated with explicit-type helpers - #136038

Open
lewing wants to merge 1 commit into
dotnet:mainfrom
lewing:lewing/wasm-r2r-stackalloc-arrays
Open

lewing wants to merge 1 commit into
dotnet:mainfrom
lewing:lewing/wasm-r2r-stackalloc-arrays

Conversation

@lewing

@lewing lewing commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Object stack allocation skips every R2R array allocation because CORINFO_HELP_READYTORUN_NEWARR_1 carries no type argument. On WebAssembly, crossgen2 allocates arrays with the explicit-type helpers (CORINFO_HELP_NEWARR_1_DIRECT(type, length)) as JIT-compiled code does, so those can take the normal path. This removes the blanket R2R bail-out (and the now-unused m_isR2R); READYTORUN_NEWARR_1 stays excluded, so native R2R codegen is unchanged.

On wasm composite R2R, a non-escaping new int[4] ×1e7 goes from 194 ms to 27 ms, and the 9 array cases in ObjectStackAllocationTests now pass. This is the explicit-type subset of #116651, without its dependency on #116808.

SuperPMI: diffs

Missing SuperPMI contexts and test exclusions

A few R2R contexts replay with missing data (43 of 286,981 on linux-x64 libraries.crossgen2): shared-generic (__Canon) array allocations now query the array layout before being rejected. Crossgen of 9 framework assemblies with matched base/diff JITs produced zero stack-allocated arrays either way.

No test exclusion can be lifted: ObjectStackAllocationTests is still CrossGenTest=false because native R2R uses READYTORUN_NEWARR_1 (#109314), browser CoreCLR runtime tests run on the interpreter (#131321), and out-of-process tests don't run on WASI.

Note

This PR description was drafted with GitHub Copilot.

…e helpers

Object stack allocation skipped all array allocations in ReadyToRun code
because CORINFO_HELP_READYTORUN_NEWARR_1 has no type argument for the
stack allocation expansion. ReadyToRun code that allocates through the
explicit-type newarr helpers (for example on WebAssembly, where crossgen2
does not use the compact ReadyToRun helpers) passes the type handle as an
argument, so it can use the same path as JIT-compiled code.

Only classify the explicit-type newarr helpers as array candidates and
drop the blanket ReadyToRun bail-out.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8c63b295-3bbc-4eae-ac3b-012e284ba542
@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 Oct 18, 2026
@lewing
lewing requested a review from AndyAyersMS October 18, 2026 22:28
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 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.

@lewing

lewing commented Oct 19, 2026

Copy link
Copy Markdown
Member Author

The JIT_ro failure in the browser-wasm R2R lane (TypeIntrinsics_ro, pMT->Validate() assert) is the known issue #135966, not this change. I've broadened that issue's match pattern to cover the _ro variant.

Checked locally under the Helix environment for this lane (checked browser-wasm runtime, node 23, the Helix payload):

  • main without this change fails TypeIntrinsics_ro at the same rate as with it (4/15 vs 5/15), with the same assert. Whether _r or _ro fails depends on the run, which is why main currently shows JIT_r failing and this PR JIT_ro.
  • With JIT: treat throwing trees as GC safe points #135970 applied, both tests pass on both bases (48/48).
  • This change doesn't alter the compiled TypeIntrinsics_r/_ro images.

Note

This comment was drafted with GitHub Copilot.

@EgorBo

EgorBo commented Oct 21, 2026

Copy link
Copy Markdown
Member

If you don't mind, let's wait for @AndyAyersMS on this one, perhaps there was a reason R2R was not supported here.

@lewing

lewing commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

If you don't mind, let's wait for @AndyAyersMS on this one, perhaps there was a reason R2R was not supported here.

Sounds good, nothing here is blocking and Andy's full fix is a superset.

This branch has not been deployed

No deployments
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