Skip to content

Recognize static field intrinsics before Wasm static helpers - #135801

Merged
davidwrighton merged 1 commit into
dotnet:mainfrom
davidwrighton:split/r2r-static-intrinsics
Oct 19, 2026
Merged

davidwrighton merged 1 commit into
dotnet:mainfrom
davidwrighton:split/r2r-static-intrinsics

Conversation

@davidwrighton

Copy link
Copy Markdown
Member

Description

Extract the independent static-field intrinsic fix from #135553 onto main.

Recognize existing static-field intrinsics before selecting Wasm static-base helpers. Reads of IntPtr.Zero, UIntPtr.Zero, and BitConverter.IsLittleEndian can use constants, while String.Empty can use a string handle. Address-taking, writes, and ordinary static-field accesses retain their existing handling, including main's target-aware thread-static check.

Add a regression theory covering optimized/unoptimized and regular/composite compilation, with fixtures for both intrinsic reads and address-taking.

Source commit: 717befe76a5. This PR does not include two-phase compilation, direct calls, or the prolog/frame-identity changes.

Historical size and codegen measurements

These matched before/after measurements were collected on the original development branch, not on this newly extracted/rebased PR. The comparisons used identical input assemblies, profiles, compiler options, references, and JIT binaries. Brotli used quality 11 and window 22.

Wasm image Raw before Raw after Raw savings Brotli before Brotli after Brotli savings
Retail CoreLib 19,728,299 19,697,600 30,699 3,685,809 3,677,815 7,994
CoreLib + CallPerformance composite 13,481,936 13,454,067 27,869 2,941,278 2,935,335 5,943

Emitted method-body nodes shrank by 30,932 bytes in retail and 27,637 bytes in composite, with their counts unchanged. In the isolated intrinsic-read fixture, zero and endianness reads shrank from 47 to 17 Wasm body bytes and eliminated the static-base helper call; the empty-string read shrank from 47 to 24 bytes. Address-taking bodies were unchanged.

These are historical size/codegen results, not throughput benchmarks or a guarantee of equivalent savings on current main.

Validation

  • git diff --check upstream/main...split/r2r-static-intrinsics — passed.
  • Reviewed the extracted three-file diff for isolation and preservation of main's IsThreadStaticForTarget(field) handling.
  • Builds, runtime tests, and new benchmarks for this extracted branch — not run, at the user's explicit request.

This remains a draft; build and runtime validation on the independent branch are outstanding.

Note

This PR was prepared with GitHub Copilot.

Restore intrinsic reads of IntPtr.Zero, UIntPtr.Zero, String.Empty, and BitConverter.IsLittleEndian on the ReadyToRun Wasm path while retaining address-taking and ordinary static access behavior. Add regression coverage for optimized and unoptimized regular and composite compilations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

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

@davidwrighton
davidwrighton marked this pull request as ready for review October 14, 2026 21:44
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/crossgen-contrib
See info in area-owners.md if you want to be subscribed.

@davidwrighton
davidwrighton merged commit 438485f into dotnet:main Oct 19, 2026
102 of 104 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants