JIT: fix three wasm R2R codegen bugs - #131841
Open
AndyAyersMS wants to merge 1 commit into
Open
Conversation
Found by ReadyToRun-compiling and running the src/tests/JIT test tree on wasm. - fgUpdateFlowGraph: don't reverse a wasm try/catch header's GT_WASM_JEXCEPT. Its edge polarity is load-bearing for try_table codegen (false = try entry, true = catch-resumption dispatcher). - valuenum PeelOffsets: read ref/byref constant offsets as host size_t. They are stored as size_t; reading them as target_ssize_t is a wrong-sized read on wasm. - Vector Get/WithElement import: fall back to the throwing software implementation for an out-of-range constant lane index on wasm; a non-constant index still uses the jump-table lowering. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 89caa9c8-5b0f-4fcc-a8c4-726ac8535110
Member
Author
|
@adamperlin PTAL fyi @dotnet/wasm-contrib These are crossgen2 failures -- there are also 3 runtime failures I'm still investigating. |
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts CoreCLR JIT behavior to fix several WebAssembly ReadyToRun (R2R) codegen issues encountered when compiling/running the JIT test suite on wasm.
Changes:
- Fixes
ValueNumStore::PeelOffsetsconstant offset peeling to correctly read ref/byref VN constants using host-sized storage on wasm. - Adds wasm-specific importer fallback for
Vector.GetElement/Vector.WithElementwhen a constant lane index is out of range (so software path can throw). - Prevents
fgUpdateFlowGraphfrom reversing wasm try/catch headerGT_WASM_JEXCEPT, preserving edge polarity needed for try_table codegen.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/coreclr/jit/valuenum.cpp | Updates VN offset peeling to handle ref/byref constant storage sizing correctly on wasm. |
| src/coreclr/jit/hwintrinsic.cpp | Adds wasm-only handling to avoid generating invalid extract/replace lane encodings for out-of-range constant indices. |
| src/coreclr/jit/fgopt.cpp | Disables a jump-reversal optimization for wasm try/catch headers to preserve GT_WASM_JEXCEPT semantics for codegen. |
Suppressed comments (1)
src/coreclr/jit/valuenum.cpp:16414
- Same issue as the previous branch: BYREF constants still use ConstantValue<target_ssize_t> (wrong-sized read on wasm), and REF coercion should use size_t (the only supported coercion for TYP_REF).
*offset += varTypeIsGC(TypeOfVN(app.GetArg(1)))
? (target_ssize_t)CoercedConstantValue<ssize_t>(app.GetArg(1))
: ConstantValue<target_ssize_t>(app.GetArg(1));
Comment on lines
+16403
to
+16407
| // Ref/byref constants are stored as host size_t, so read them as such and truncate. | ||
| // | ||
| *offset += varTypeIsGC(TypeOfVN(app.GetArg(0))) | ||
| ? (target_ssize_t)CoercedConstantValue<ssize_t>(app.GetArg(0)) | ||
| : ConstantValue<target_ssize_t>(app.GetArg(0)); |
Contributor
There was a problem hiding this comment.
varTypeIsGC should return true for TYP_BYREF as well, right? I'm not sure about this comment.
adamperlin
approved these changes
Aug 5, 2026
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.
Found by ReadyToRun-compiling and running the src/tests/JIT test tree on wasm.