[Wasm RyuJit] More crossgen assert fixes#125102
[Wasm RyuJit] More crossgen assert fixes#125102AndyAyersMS wants to merge 9 commits intodotnet:mainfrom
Conversation
AndyAyersMS
commented
Mar 3, 2026
- use gtOverflowEx instead of gtOverflow
- not all block stores need null checks
- more cases where we don't have putarg stacks
- add lowering was bypassing Wasm overflow checking
* use gtOverflowEx instead of gtOverflow * not all block stores need null checks * more cases where we don't have putarg stacks * add lowering was bypassing Wasm overflow checking
|
We might be able to be even more fine-grained with the null checks. Also not 100% sure yet what to do with all the operand reordering for calls, but this at least tolerates the way Wasm does things. |
There was a problem hiding this comment.
Pull request overview
This PR fixes several assert failures in the WASM RyuJIT cross-compilation codepath ("crossgen assert fixes"):
Changes:
- Replace incorrect
gtOverflow()calls withgtOverflowEx()in WASM-specific lowering and codegen, sincegtOverflow()assertsOperMayOverflow()and these sites can be reached with non-overflow-capable operators (AND, OR, XOR). - Fix overflow checking for
GT_ADDon WASM:LowerAddwas not callingLowerBinaryArithmetic, so theSetMultiplyUsed()calls needed to set up overflow-checking registers were skipped for overflow ADDs. - Guard null checks in
genCodeForCpObjbehind adoNullChecksflag (GTF_EXCEPT && OperMayThrow) since not all block-copy operations need null checks. - Fix asserts in
MovePutArgUpToCall/MovePutArgNodesUpToCallthat assumed nodes must beGT_PUTARG_*orGT_FIELD_LIST, which is not true on WASM whereHAS_FIXED_REGISTER_SET = 0.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/coreclr/jit/lowerwasm.cpp |
Use gtOverflowEx() instead of gtOverflow() in LowerBinaryArithmetic for correctness when called with non-overflow-capable operators (AND/OR/XOR) |
src/coreclr/jit/lower.cpp |
Fix MovePutArgUpToCall/MovePutArgNodesUpToCall asserts for WASM (no PutArg nodes); add new else branch for plain arg nodes; call LowerBinaryArithmetic from LowerAdd on WASM to fix missing overflow setup for ADD |
src/coreclr/jit/codegenwasm.cpp |
Use gtOverflowEx() instead of gtOverflow() in genCodeForBinary; gate null checks in genCodeForCpObj behind doNullChecks for correctness when copies are known safe |
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
1 similar comment
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
SingleAccretion
left a comment
There was a problem hiding this comment.
LGTM modulo comments.
src/coreclr/jit/codegenwasm.cpp
Outdated
| } | ||
| else // A normal store, not a WriteBarrier store | ||
| { | ||
| if ((tree->gtFlags & GTF_IND_NONFAULTING) == 0) |
There was a problem hiding this comment.
FWIW, I think it would be better for now at least to consider null checking a wholly Jit side responsibility. Pushing it into the write barrier is not 'simple' (at the very least it forces us to figure out how to put the SP argument into the right place here).
There was a problem hiding this comment.
Yeah, I agree.
I still need to revise the code in Lower that bypasses Wasm lowering for stores with write barriers.
There was a problem hiding this comment.
I am tempted to add GT_IND nullchecks here, though that may be a big enough project that it should be its own PR.
There was a problem hiding this comment.
Updated to null check for any storeind that needs it. Going to defer indirect loads.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: SingleAccretion <62474226+SingleAccretion@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/coreclr/jit/lower.cpp:8056
- In
LowerAdd, theLowerBinaryArithmetic(node)call (line 8049) already invokesContainCheckBinaryinternally (seelowerwasm.cppline 174). The code then falls through to callContainCheckBinary(node)again at line 8055 for WASM. Since WASM'sContainCheckBinaryis an empty no-op, this is functionally harmless but is a redundant double call. Returning early from the WASM block (or not callingContainCheckBinaryagain for WASM) would be cleaner.
#if defined(TARGET_WASM)
if (node->OperIs(GT_ADD))
{
LowerBinaryArithmetic(node);
}
#endif
if (node->OperIs(GT_ADD))
{
ContainCheckBinary(node);
}
|
@dotnet/jit-contrib PTAL |