[Wasm/Ryujit] Fix if stack depth; fix pep call ordering#128242
Conversation
Account for additional control flow stack depth added during codegen when using `if/end`. Fix argument eval ordering for PEP calls so the PEP is pushed as the last arg, and then pushed and indirected to get the function index.
There was a problem hiding this comment.
Pull request overview
This PR updates the Wasm RyuJIT backend to better handle Wasm control-flow depth for generated if/end blocks and to adjust Portable Entry Point indirect-call lowering so the PEP argument is evaluated before the final call target load.
Changes:
- Adds Wasm
if/endemission helpers that track extra control-flow depth for branch depth calculation. - Replaces several direct
if/endemissions with the new helpers. - Reorders PEP call target lowering so the indirect call target is pushed immediately before the call.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/coreclr/jit/lowerwasm.cpp |
Reorders PEP control-expression load placement before the call. |
src/coreclr/jit/codegenwasm.cpp |
Tracks extra Wasm control-flow depth and routes generated if/end through helpers. |
src/coreclr/jit/codegen.h |
Adds Wasm codegen state and helper declarations. |
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
|
FYI @dotnet/jit-contrib For a PEP call we were emitting the control target before the pep instead of after. For late-introduced control flow we were not accounting for the extra depth. @davidwrighton this should fix the two issues you were seeing. Seems like we should be able to use a wasm local for the pep / target instead of storing it on the shadow stack, but will tackle that later. Eg the sequence is now and it could be simply |
Account for additional control flow stack depth added during codegen when using
if/end.Fix argument eval ordering for PEP calls so the PEP is pushed as the last arg, and then pushed and indirected to get the function index.