Skip to content

[Wasm R2R] Fix two crossgen2 NYIs: FloatTraits::NaN and bitcast of same-size types - #129095

Merged
AndyAyersMS merged 4 commits into
dotnet:mainfrom
AndyAyersMS:wasm-jit-nyi-fixes
Jun 9, 2026
Merged

AndyAyersMS merged 4 commits into
dotnet:mainfrom
AndyAyersMS:wasm-jit-nyi-fixes

Conversation

@AndyAyersMS

@AndyAyersMS AndyAyersMS commented Jun 7, 2026 •

Copy link
Copy Markdown
Member

Implement FloatTraits::NaN and DoubleTraits::NaN for WASM using the WebAssembly canonical NaN.

In genCodeForBitCast same sized bit casts are nops.

Co-authored-by: Copilot [email protected]

…me-i32-size types

Two NYI assertions were firing during wasm crossgen2 of test code:

1. valuenum.cpp:52 NYI_WASM('FloatTraits::NaN') - hit when VN constant-folds
   a NaN-producing FP expression (e.g. r4NaNrem.cs). Implement FloatTraits::NaN
   and DoubleTraits::NaN for WASM using the WebAssembly canonical NaN
   (positive sign, exponent all ones, payload MSB = 1) which matches the bit
   pattern produced by V8, SpiderMonkey, and Wasmtime, and aligns with the
   ARM convention.

2. codegenwasm.cpp:1891 unreached() in genCodeForBitCast - hit when shared-generic
   codegen produces a BITCAST between INT and REF/BYREF (e.g. Comparer_get_Default
   Bitcast<__Canon>(long)). On wasm32 these are all i32 on the wasm value stack,
   so the bitcast is a true no-op. PackTypes normalizes TYP_REF/TYP_BYREF to
   TYP_I_IMPL, so a single case for PackTypes(TYP_INT, TYP_INT) (wasm32) and
   PackTypes(TYP_LONG, TYP_LONG) (wasm64) covers all valid combinations.
   Remaining unsupported combinations now go through NYI_WASM so that R2R can
   fall back gracefully when JitWasmNyiToR2RUnsupported=1.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 7, 2026 14:28
@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 Jun 7, 2026

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 CoreCLR JIT WASM support to reduce crossgen2/ReadyToRun “NYI” failures by (1) defining target-appropriate NaN bit patterns for constant folding and (2) treating same-size WASM integer/pointer bitcasts as no-ops where no reinterpret instruction is required.

Changes:

  • Implement FloatTraits::NaN / DoubleTraits::NaN for TARGET_WASM using a canonical NaN payload.
  • Update CodeGen::genCodeForBitCast on WASM to avoid emitting instructions for certain same-size bitcasts, and replace the previous unreached() default with a WASM NYI.

Reviewed changes

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

File Description
src/coreclr/jit/valuenum.cpp Adds WASM NaN bit patterns for floating-point constant folding.
src/coreclr/jit/codegenwasm.cpp Makes some same-size bitcasts into no-ops and improves unsupported-combination handling.

Comment thread src/coreclr/jit/valuenum.cpp Resolved
Comment thread src/coreclr/jit/codegenwasm.cpp Resolved
- Extend FpAdd/FpSub/FpMul/FpDiv NaN-substitution to TARGET_WASM so
  constant folding of (+inf)+(-inf), 0*inf, 0/0, inf/inf etc. produces
  the WASM canonical NaN bit pattern instead of the host's (e.g. x64's
  0xFFC00000), keeping crossgen2 output consistent with runtime.

- Tighten the in-method comments on the WASM bit-pattern selection and
  on the same-size BITCAST no-op case in genCodeForBitCast.

Co-authored-by: Copilot <[email protected]>
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@adamperlin maybe look at this one too?

@AndyAyersMS
AndyAyersMS requested a review from adamperlin June 8, 2026 23:55
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@adamperlin can you take a look?

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

Copy link
Copy Markdown
Contributor

@adamperlin can you take a look?

Yes. Just had one comment about NYI versus unreached() in that bitcast switch.

Per PR review feedback: the default case in the bitcast type switch should be unreached(), since BITCAST should only be morphed in for supported same-size type pairings.
Copilot AI review requested due to automatic review settings June 9, 2026 18:14

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

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

Comment thread src/coreclr/jit/valuenum.cpp Resolved
Comment thread src/coreclr/jit/valuenum.cpp Resolved
Comment thread src/coreclr/jit/valuenum.cpp Resolved
Comment thread src/coreclr/jit/valuenum.cpp Resolved
Comment thread src/coreclr/jit/valuenum.cpp Resolved
Comment thread src/coreclr/jit/valuenum.cpp Resolved
Per PR review feedback: the NaN-canonicalization paths in FloatTraits::NaN, DoubleTraits::NaN, FpAdd, FpSub, FpMul, and FpDiv now also cover TARGET_LOONGARCH64, TARGET_RISCV64, and TARGET_WASM. Update the doc comments to match the preprocessor guards.
@AndyAyersMS

Copy link
Copy Markdown
Member Author

/ba-g unrelated failure without console log

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 17, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
…me-size types (#129095)

Implement FloatTraits::NaN and DoubleTraits::NaN for WASM using the
WebAssembly canonical NaN.

In genCodeForBitCast same sized bit casts are nops.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture 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.

4 participants