Repository navigation
[Wasm R2R] Fix two crossgen2 NYIs: FloatTraits::NaN and bitcast of same-size types - #129095
Merged
Merged
Conversation
…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]>
Contributor
There was a problem hiding this comment.
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::NaNforTARGET_WASMusing a canonical NaN payload. - Update
CodeGen::genCodeForBitCaston WASM to avoid emitting instructions for certain same-size bitcasts, and replace the previousunreached()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. |
- 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]>
Member
Author
|
@adamperlin maybe look at this one too? |
Member
Author
|
@adamperlin can you take a look? |
adamperlin
reviewed
Jun 9, 2026
Contributor
Yes. Just had one comment about |
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.
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.
adamperlin
approved these changes
Jun 9, 2026
Member
Author
|
/ba-g unrelated failure without console log |
This was referenced Jun 10, 2026
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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]