Skip to content

[JIT] [wasm]: Compare TYP_REF references directly with null using i32.eqz - #134666

Merged
adamperlin merged 4 commits into
dotnet:mainfrom
adamperlin:adamperlin/wasm-shrink-nullcheck-seq
Sep 29, 2026
Merged

adamperlin merged 4 commits into
dotnet:mainfrom
adamperlin:adamperlin/wasm-shrink-nullcheck-seq

Conversation

@adamperlin

@adamperlin adamperlin commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #134463; For Object References (TYP_REF) with no added offset we can perform a null check by comparing directly with zero and use i32.eqz for that purpose. We must keep the longer ordered comparison of i32.const 1023; i32.le_u for null-checks on byref/int typed references and any address with an offset/index.

SuperPMI Metrics (System.Private.CoreLib)

Code size: −70,101 bytes (−0.75%)
PerfScore in Diffs: −2.00%
10,079 size improvements, 0 regressions
10,022 PerfScore improvements, 0 regressions

Copilot AI lite review requested due to automatic review settings September 25, 2026 18:17
@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 Sep 25, 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.

Copilot review overview

🟡 Changes recommended

A critical null-check correctness issue remains for TYP_REF address-mode expressions.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Updates WebAssembly JIT null checks to use i32.eqz for direct object references while preserving offset-aware checks for byrefs and integers.

Changes:

  • Propagates operand types through null-check emission.
  • Updates Wasm null-check callers and declarations.
  • Retains ordered comparisons for non-reference addresses.

Review findings include a critical correctness issue for TYP_REF address-mode expressions and a request for code-size/performance evidence.

File Description
src/​coreclr/​jit/​hwintrinsiccodegenwasm.cpp Supplies address types for intrinsic null checks.
src/​coreclr/​jit/​codegenwasm.cpp Implements typed null-check emission and updates callers.
src/​coreclr/​jit/​codegen.h Updates the null-check helper declaration.

Comment thread src/coreclr/jit/codegenwasm.cpp Resolved
@davidwrighton

Copy link
Copy Markdown
Member

LGTM, but I'm not an expert in the JIT codebase enough to signoff on this.

@davidwrighton

Copy link
Copy Markdown
Member

Also, I'm a bit surprised we can't do it in some cases where the read has an offset. If we can prove the use of the address+offset load is something like i32.load offset=X, we probably could also use the eqz form of this.

@adamperlin
adamperlin requested a review from EgorBo September 28, 2026 21:51
@adamperlin

Copy link
Copy Markdown
Contributor Author

@EgorBo can you take a look at this one?

@adamperlin

Copy link
Copy Markdown
Contributor Author

Also, I'm a bit surprised we can't do it in some cases where the read has an offset. If we can prove the use of the address+offset load is something like i32.load offset=X, we probably could also use the eqz form of this.

This should actually work today with this change. In a case like base; i32.load offset=X, we should be passing in the tree which represents the base as the node whose result is getting null-checked.

Comment thread src/coreclr/jit/codegenwasm.cpp Resolved
@adamperlin
adamperlin enabled auto-merge (squash) September 29, 2026 20:33
@adamperlin
adamperlin merged commit 505f58f into dotnet:main Sep 29, 2026
139 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 30, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

[wasm] Null checks could use i32.eqz instead of i32.const 1023

4 participants