JIT: fold wasm R2R address constants into load memarg offsets#131353
Conversation
Contain a relocatable address constant under a load and emit the relocation in the memarg offset instead of a separate i32.const/i32.add. Saves 814,971 bytes (3.60%) of the System.Private.CoreLib wasm code section. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 6 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Pull request overview
This PR updates the WASM JIT lowering + codegen/emitter pipeline so that certain relocatable address constants (icon handles) can be contained under GT_IND loads and then emitted as a relocation in the wasm load’s memarg offset, avoiding the separate i32.const <reloc>; i32.add sequence.
Changes:
- Teach
Lowering::ContainCheckIndir(WASM) to contain eligible relocatable icon-handle address constants forGT_INDloads (excluding SIMD12 and multiply-used cases). - Add emitter helpers to (a) emit the module base (
imageBase) and (b) emit a memarg whose offset is a relocatable address constant. - Update
genCodeForIndirto recognize the contained icon-handle address case and emitimageBase+load(memarg offset=<reloc>).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/jit/lowerwasm.cpp | Adds containment for relocatable icon-handle addresses under eligible GT_IND loads so codegen can fold them into memarg offsets. |
| src/coreclr/jit/emitwasm.h | Declares new emitter helpers (emitImageBase, emitIns_MemargAddress) used by WASM codegen. |
| src/coreclr/jit/emitwasm.cpp | Implements emitImageBase / emitIns_MemargAddress and switches IF_MEMARG emission to use relocation-aware constant output when needed. |
| src/coreclr/jit/codegenwasm.cpp | Uses the new contained-address pattern in genCodeForIndir to emit imageBase plus a memarg relocation for loads. |
|
@adamperlin PTAL Handles folding offsets into global loads (where we know overflow is not possible). SizeSystem.Private.CoreLib, crossgen2
271,657 sites folded, each saves 3 bytes. Example
;; before ;; after
0026 local.get 0 0026 local.get 0
0028 global.get 1 ;; $imageBase 0028 global.get 1 ;; $imageBase
002e i32.const 7385676 ;; reloc 002e i32.load align=0 offset=7385676 ;; reloc
0034 i32.add
0035 i32.load align=0 offset=0
0038 global.get 1 0035 global.get 1
003e i32.const 7292488 ;; reloc 003b i32.load align=0 offset=7292488 ;; reloc
0044 i32.add
0045 i32.load align=0 offset=0
0048 local.set 3 0042 local.set 3 |
Contain a relocatable address constant under a load and emit the relocation in the memarg offset instead of a separate i32.const/i32.add. Saves 814,971 bytes (3.60%) of the System.Private.CoreLib wasm code section.