Skip to content

[Wasm RyuJIT] Use offset reloc for call indirection-cell loads#127654

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/switch-const-reloc-to-offset-reloc
Draft

[Wasm RyuJIT] Use offset reloc for call indirection-cell loads#127654
Copilot wants to merge 2 commits intomainfrom
copilot/switch-const-reloc-to-offset-reloc

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 1, 2026

Wasm RyuJIT call codegen dereferences the indirection cell with i32.const <reloc> ; i32.add ; i32.load 0, using a WASM_MEMORY_ADDR_REL_SLEB const reloc. The two scaffolding instructions (i32.const_address, i32.add) can be folded into the load itself by emitting the relocation as the load's offset immediate (WASM_MEMORY_ADDR_REL_LEB), shrinking every helper/indirect call site.

Before:

global.get $__r2r_start
i32.const  <WASM_MEMORY_ADDR_REL_SLEB>
i32.add
i32.load   0
i32.load   0      ; only on EC_INDIR_R
call_indirect

After:

global.get $__r2r_start
i32.load   offset=<WASM_MEMORY_ADDR_REL_LEB>
i32.load   0      ; only on EC_INDIR_R
call_indirect

Changes

  • emitwasm.cppIF_MEMARG encoding: route the offset immediate through emitOutputConstant(..., UNSIGNED, WASM_MEMORY_ADDR_REL_LEB) so a idIsCnsReloc() instruction emits a padded-ULEB128 reloc in the offset slot; non-reloc cases keep the plain ULEB128 path. Size calculation already accounted for this.
  • emitwasm.{h,cpp} — new helper emitter::emitLoadAtAddressConstant(instruction ins, void* address): emits global.get $__r2r_start + <ins> offset=<reloc> for any IF_MEMARG load/store, asserting the format.
  • codegenwasm.cppgenEmitHelperCall: replace both emitAddressConstant(addr) + emitIns_I(INS_I_load, EA_PTRSIZE, 0) pairs (managed-helper PEP push and EC_INDIR_R indirection-cell deref) with emitLoadAtAddressConstant(INS_I_load, addr). The trailing PEP-deref load on EC_INDIR_R is unchanged.

emitAddressConstant is retained for genCodeForConstant, which takes an address rather than dereferencing it.

Copilot AI requested review from Copilot and removed request for Copilot May 1, 2026 17:00
…s in Wasm RyuJIT calls

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/b83ac7fa-44cd-4275-b00e-efcd272eb66d

Co-authored-by: adamperlin <10533886+adamperlin@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 1, 2026 17:13
Copilot AI changed the title [WIP] Optimize call codegen by switching to offset reloc [Wasm RyuJIT] Use offset reloc for call indirection-cell loads May 1, 2026
Copilot AI requested a review from adamperlin May 1, 2026 17:14
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 1, 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.

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

Labels

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.

[Wasm RyuJIT] Switch from Const Reloc -> Offset Reloc for Call Codegen

2 participants