Skip to content

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

Open
AndyAyersMS wants to merge 2 commits into
dotnet:mainfrom
AndyAyersMS:wasm-jit-nyi-fixes
Open

[Wasm R2R] Fix two crossgen2 NYIs: FloatTraits::NaN and bitcast of same-size types#129095
AndyAyersMS wants to merge 2 commits into
dotnet:mainfrom
AndyAyersMS:wasm-jit-nyi-fixes

Conversation

@AndyAyersMS
Copy link
Copy Markdown
Member

@AndyAyersMS AndyAyersMS commented Jun 7, 2026

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 223556219+Copilot@users.noreply.github.com

…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 <223556219+Copilot@users.noreply.github.com>
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
@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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 Outdated
Comment thread src/coreclr/jit/codegenwasm.cpp Outdated
- 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 <223556219+Copilot@users.noreply.github.com>
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