Skip to content

[Wasm RyuJIT] Address block store issues from #125756#125770

Open
kg wants to merge 10 commits intodotnet:mainfrom
kg:wasm-blockstore-4
Open

[Wasm RyuJIT] Address block store issues from #125756#125770
kg wants to merge 10 commits intodotnet:mainfrom
kg:wasm-blockstore-4

Conversation

@kg
Copy link
Member

@kg kg commented Mar 19, 2026

Fixes some of the issues from #125756 , at least based on my isolated repros.

cc @AndyAyersMS still figuring this out, don't completely understand it.

@kg kg added the arch-wasm WebAssembly architecture label Mar 19, 2026
Copilot AI review requested due to automatic review settings March 19, 2026 11:58
@kg kg added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 19, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets WebAssembly RyuJIT block-store lowering/codegen issues that are triggering asserts during crossgen/debug builds (per #125756), by adjusting how GT_STORE_BLK operands are represented/contained for memory.copy/memory.fill.

Changes:

  • Update WASM LowerBlockStore to treat GT_IND sources as contained, and attempt to convert local sources to addresses for the memory.copy opcode path.
  • Add debug assertions in WASM codegen to validate containment expectations for native bulk-memory op emission (memory.copy / memory.fill).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/coreclr/jit/lowerwasm.cpp Changes block-store source handling/containment and attempts to convert local sources into address form for memory.copy.
src/coreclr/jit/codegenwasm.cpp Adds debug assertions around contained operands for the native bulk-memory opcode path.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me overall.

Copilot AI review requested due to automatic review settings March 20, 2026 14:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets WASM RyuJIT block-store correctness by adjusting lowering/RA hints and consolidating codegen paths for different GT_STORE_BLK lowering kinds, aiming to address debug/assert failures reported in #125756.

Changes:

  • Move SetMultiplyUsed marking in LowerBlockStore so it applies consistently across block-store kinds.
  • Route BlkOpKindNativeOpcode block stores through genCodeForCpObj to share logic with the CpObjUnroll path.
  • Refactor genCodeForCpObj operand handling to support both cpobj and native memory.copy/memory.fill.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/coreclr/jit/lowerwasm.cpp Moves multiply-used marking to apply across cpobj and native-op block stores.
src/coreclr/jit/codegenwasm.cpp Unifies NativeOpcode handling with CpObjUnroll and refactors operand decoding/emission.

@kg kg marked this pull request as ready for review March 20, 2026 15:54
@kg kg force-pushed the wasm-blockstore-4 branch from b5704e6 to ae3f194 Compare March 20, 2026 15:56
Copilot AI review requested due to automatic review settings March 24, 2026 06:27
@kg kg force-pushed the wasm-blockstore-4 branch from ae3f194 to a7e928f Compare March 24, 2026 06:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

kg added 3 commits March 24, 2026 12:00
Checkpoint

Update comment & run jit-format

Update comments

Refactoring

Formatting

jit-format

Add missing genUpdateLife
Copilot AI review requested due to automatic review settings March 24, 2026 19:06
@kg kg force-pushed the wasm-blockstore-4 branch from 0138cc0 to b875c9b Compare March 24, 2026 19:06
@kg
Copy link
Member Author

kg commented Mar 24, 2026

Rewrote most of the codegen changes from scratch so I'm resolving all the old comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

@kg
Copy link
Member Author

kg commented Mar 24, 2026

Null checks are missing because they unbalance the stack:

node:internal/modules/run_main:107
    triggerUncaughtException(
    ^

[CompileError: WebAssembly.compile(): Compiling function #7 failed: not enough arguments on the stack for memory.fill (need 3, got 2) @+1809]

Node.js v25.2.1

Not sure what's going on there.

Copilot AI review requested due to automatic review settings March 24, 2026 21:14
@kg
Copy link
Member Author

kg commented Mar 24, 2026

I still need to do the optimization in lowering that singleaccretion suggested, but I think this is done otherwise now after the rewrite...

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment on lines +2865 to 2869
regNumber destReg = genConsumeReg(dest);
regNumber srcReg = genConsumeReg(src);
unsigned destOffset = 0;
unsigned srcOffset = 0;

Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genCodeForStoreBlk now calls genConsumeReg(dest) / genConsumeReg(src) up front. For contained operands (e.g., src is often a contained GT_IND for copyblk), this bypasses genConsumeRegs recursion and fails to consume the actual address operand (and doesn't follow the required execution-order consumption pattern used elsewhere, e.g. genCodeForStoreInd). This can leave operand liveness/GC tracking inconsistent and can break the Wasm evaluation stack invariants for block ops.

Consider switching back to genConsumeOperands(blkOp) (or explicitly genConsumeAddress(dest) + genConsumeRegs(src) with the same contained-node handling as genConsumeRegs), and only call genConsumeReg on the specific non-contained nodes you truly consume (e.g., the unwrapped GT_IND address node).

Suggested change
regNumber destReg = genConsumeReg(dest);
regNumber srcReg = genConsumeReg(src);
unsigned destOffset = 0;
unsigned srcOffset = 0;
// Consume the destination address and source operands in proper evaluation order.
genConsumeAddress(dest);
genConsumeRegs(src);
regNumber destReg = dest->isContained() ? REG_NA : dest->GetRegNum();
regNumber srcReg = src->isContained() ? REG_NA : src->GetRegNum();
unsigned destOffset = 0;
unsigned srcOffset = 0;

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genConsumeOperands isn't usable here (it breaks) nor is genConsumeAddress (it breaks)

Copilot AI review requested due to automatic review settings March 25, 2026 06:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@kg
Copy link
Member Author

kg commented Mar 25, 2026

The proposed lowering optimization breaks codegen somehow, I'm not sure why. Will poke at it more later.

@kg kg marked this pull request as ready for review March 25, 2026 16:08
@kg kg requested review from AndyAyersMS and Copilot March 25, 2026 16:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants