Repository navigation
JIT: Do not fold a relocatable constant into a block store address mode on Arm, LoongArch64 and RISC-V - #137128
Closed
SHAZAM-Analytics wants to merge 1 commit into
Closed
SHAZAM-Analytics wants to merge 1 commit into
SHAZAM-Analytics wants to merge 1 commit into
Conversation
ContainBlockStoreAddress on arm/arm64, loongarch64 and riscv64 turned ADD(base, CNS_INT) into a contained LEA whenever the constant fit the offset range, without checking whether the constant needs a relocation. A frozen object handle under NativeAOT became a plain offset that codegen materialized with movz/movk and no relocation, so the copy faulted. Leave the ADD uncontained when the constant needs a relocation, matching what TryCreateAddrMode does on xarch. Fixes #136687
|
Azure Pipelines: Successfully started running 5 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. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
Author
|
This fix is needed in servicing too: shipped .NET 10 and 11 NativeAOT apps hit it on arm64 today. Once it merges, could an area owner backport it to release/10.0 and release/11.0? I opened backport PRs earlier by mistake and they were rightly closed. |
Member
|
@SHAZAM-Analytics Did you happen to close this by accident? |
Contributor
Author
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 #136687
Problem
Lowering::ContainBlockStoreAddressfor arm/arm64 (and its loongarch64 and riscv64 copies) turnsADD(base, CNS_INT)into a containedLEA(base, offset)whenever the constant fits the offset range. It does not check whether the constant needs a relocation. When the constant is a handle, such as a frozen object's address under NativeAOT, the handle becomes a plain address-mode offset. Codegen then materializes it withmovz/movkand no relocation, so at run time the value is ILC's placeholder rather than an address and the block copy faults.The xarch version builds its address mode through
TryCreateAddrMode, which only folds constants for whichImmedValCanBeFoldedis true, so x86 and x64 are not affected.Minimal case: a loop over a preinitialized
static readonlyarray of structs that copies each element to a local (an unrolled block copy):SumElementscompiled for win-arm64 by the 10.0.14 ILCompiler:With this change:
Fix
ContainBlockStoreAddressreturns early when the offset constantImmedValNeedsReloc, so theADDstays uncontained and the constant is emitted through the normal relocatable path. The same check is added in the loongarch64 and riscv64 implementations, which have the same shape.Testing
Adds
TestFrozenStructArrayElementCopyto the NativeAOTPreinitializationsmoke test, which runs on the osx-arm64, linux-arm64 and windows-arm64 NativeAOT legs. It asserts the class is preinitialized and checks a checksum over every field of every element. Without the fix it faults at the first element copy on arm64; on x64 it passes either way.I confirmed the codegen difference above by cross-compiling the test (in the release/10.0 copy of
Preinitialization.cs) for win-arm64 with the 10.0.14 ILCompiler, once with its shipped arm64 JIT and once with the release/10.0 JIT rebuilt with this change. I have not run it on main's JIT, whose JIT-EE interface does not match a shipped ILCompiler.