Skip to content

[Wasm RyuJIT] Partially implement genStructReturn#126326

Open
kg wants to merge 3 commits intodotnet:mainfrom
kg:wasm-structreturn
Open

[Wasm RyuJIT] Partially implement genStructReturn#126326
kg wants to merge 3 commits intodotnet:mainfrom
kg:wasm-structreturn

Conversation

@kg
Copy link
Copy Markdown
Member

@kg kg commented Mar 30, 2026

Addresses a top assert from #125756
Scenarios other than fieldlist are not implemented because I don't have a repro for them yet.

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

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

Copy link
Copy Markdown
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

Adds an initial WebAssembly-specific implementation of CodeGen::genStructReturn to start handling struct returns in the Wasm RyuJIT backend, as part of addressing top asserts seen during wasm crossgen.

Changes:

  • Implement partial genStructReturn handling for GT_RETURN where the return value is a FIELD_LIST.
  • Consume field list uses to keep liveness consistent, then attempt to return.

const unsigned regCount = retTypeDesc.GetReturnRegCount();

assert(regCount <= MAX_RET_REG_COUNT);

Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

actualOp1, retTypeDesc, and regCount are not used outside of assert. In non-DEBUG builds assert compiles out, leaving these locals unused (and potentially failing the build under warnings-as-errors). Either remove them for now or use (void) casts / use regCount in the logic (e.g., compare against the FIELD_LIST use count).

Suggested change
(void)actualOp1;
(void)retTypeDesc;
(void)regCount;

Copilot uses AI. Check for mistakes.
@kg
Copy link
Copy Markdown
Member Author

kg commented Mar 30, 2026

Can confirm that this fixes:

--singlemethodtypename "System.RuntimeTypeHandle" --singlemethodname "FromIntPtr" --singlemethodindex 1
--singlemethodtypename "System.RuntimeTypeHandle" --singlemethodname "GetModuleHandle" --singlemethodindex 1
--singlemethodtypename "System.BitConverter" --singlemethodname "ToBFloat16" --singlemethodindex 1
--singlemethodtypename "System.DateOnly" --singlemethodname "get_MinValue" --singlemethodindex 1

Copilot AI review requested due to automatic review settings March 30, 2026 20:49
@kg kg changed the title [Wasm RyuJIT] Implement genStructReturn [Wasm RyuJIT] Partially implement genStructReturn Mar 30, 2026
@kg kg marked this pull request as ready for review March 30, 2026 20:50
Copy link
Copy Markdown
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 1 out of 1 changed files in this pull request and generated no new comments.

// The field list's individual fields should have preceded us in LIR and code to push them onto the stack
// should already have been generated. We should also only have one field (see MAX_RET_REG_COUNT assert,
// above.) As a result, all we need to do is generate a return opcode.
GetEmitter()->emitIns(INS_return);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should not be emitting the return here, it will be part of the epilog.

I think this method can simply be: foreach (field in fieldList) genConsumeReg(field).

Since we don't have multi-regs, I think the NYI below can be removed and we can assert it is always a field list.

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.

3 participants