JIT: don't narrow relocatable handle constants in optNarrowTree#129519
Merged
Conversation
optNarrowTree could narrow a GT_CNS_INT handle to TYP_INT whenever its value happened to fit in 32 bits. For a relocatable handle (e.g. a function-address handle that is the operand of the fat-pointer check NE(AND(fptr, 2), 0)), this made ARM64 codegen materialize the address with a 32-bit adrp+add (0x11000000) while still recording a 64-bit PAGEOFFSET_12A relocation, tripping the (addInstr & 0xFFC00000) == 0x91000000 assert in the NativeAOT relocation writer. The bug was latent and only became observable on checked/debug NativeAOT once handle values stopped carrying a high tag bit (so they fit in int32). Guard the GT_CNS_INT narrowing on !ImmedValNeedsReloc so handle constants keep their pointer width. Fixes dotnet#129504 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the CoreCLR JIT narrowing logic to avoid narrowing relocatable handle constants during optNarrowTree, preventing the backend from selecting 32-bit instruction forms for values that must be materialized as pointer-sized addresses (notably relevant for ARM64 NativeAOT relocations).
Changes:
- Add an early-exit in
Compiler::optNarrowTreeforGT_CNS_INTwhenImmedValNeedsReloc(this)is true, disallowing narrowing of relocatable icon-handle constants.
Member
Author
|
PTAL @dotnet/jit-contrib yet another transformation on a relocable CNS_INT handle |
jakobbotsch
approved these changes
Jun 17, 2026
Member
Author
|
/ba-g timeouts |
This was referenced Jun 17, 2026
Open
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.
Fixes #129504.
Note
This PR (code and description) was generated with the assistance of GitHub Copilot.