[Experiment] Fold NativeAOT relocatable constants with small offsets#131107
Draft
EgorBo wants to merge 1 commit into
Draft
[Experiment] Fold NativeAOT relocatable constants with small offsets#131107EgorBo wants to merge 1 commit into
EgorBo wants to merge 1 commit into
Conversation
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the x64 JIT NativeAOT pipeline to fold OBJ_HDL + small_const address computations into a single relocatable constant with an explicit “addend”, enabling codegen to avoid emitting a separate add reg, imm in common patterns (e.g., string literal span construction).
Changes:
- Teach
Lowering::LowerAddto foldGTF_ICON_OBJ_HDL + int32 offsetinto a newGTF_ICON_RELOC_ADDRconstant (AMD64 + NativeAOT only), carrying the addend separately. - Introduce
GTF_ICON_RELOC_ADDRand addGenTreeIntConaccessors to store/retrieve the relocation addend. - Extend the xarch emitter/codegen so
lea reg, [reloc]can record a relocation with an extra addend (via a newemitIns_R_AIparameter andemitOutputAMhandling).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/jit/lower.cpp | Adds the NativeAOT AMD64 folding path from OBJ_HDL + small offset into a relocatable constant with addend. |
| src/coreclr/jit/handlekinds.h | Adds the new handle kind GTF_ICON_RELOC_ADDR. |
| src/coreclr/jit/gentree.h | Documents and implements addend storage/access (GetRelocOffset/SetRelocOffset) on GenTreeIntCon. |
| src/coreclr/jit/gentree.cpp | Prevents address containment for GTF_ICON_RELOC_ADDR to avoid losing the addend. |
| src/coreclr/jit/emitxarch.h | Extends emitIns_R_AI signature with an optional relocation addend parameter. |
| src/coreclr/jit/emitxarch.cpp | Stores the addend in the instruction descriptor and applies it to RIP-rel relocation emission (emitOutputAM). |
| src/coreclr/jit/emitinl.h | Adds emitGetInsAmdRelocOffset helper to retrieve the stored addend. |
| src/coreclr/jit/emit.h | Declares emitGetInsAmdRelocOffset on the emitter. |
| src/coreclr/jit/codegenxarch.cpp | Emits lea with relocation addend for GTF_ICON_RELOC_ADDR (NativeAOT AMD64), with fallback to lea/mov + add. |
EgorBo
marked this pull request as draft
July 21, 2026 00:00
On x64 NativeAOT, ADD(frozen_object_handle, small_offset) was emitted as `lea reg, [reloc]` followed by `add reg, offset`. Fold it into a single `lea reg, [reloc + offset]` by carrying the offset as a relocation addend via a new GTF_ICON_RELOC_ADDR handle kind, so the relocation still targets the exact base handle while the addend is applied by the emitter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 61836295-249d-497a-8fec-f45402076cf7
EgorBo
force-pushed
the
egorbo/nativeaot-reloc-addend
branch
from
July 21, 2026 08:45
2187852 to
4dc31c5
Compare
This was referenced Jul 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Just an AI experiment for relocatable constants + small offsets in NativeAOT.