[Wasm R2R] Fix two crossgen2 NYIs: FloatTraits::NaN and bitcast of same-size types#129095
Open
AndyAyersMS wants to merge 2 commits into
Open
[Wasm R2R] Fix two crossgen2 NYIs: FloatTraits::NaN and bitcast of same-size types#129095AndyAyersMS wants to merge 2 commits into
AndyAyersMS wants to merge 2 commits into
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 <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
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 <223556219+Copilot@users.noreply.github.com>
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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 223556219+Copilot@users.noreply.github.com