Improve fgGetStaticFieldSeqAndAddress and fgValueNumberConstLoad#128638
Closed
EgorBo wants to merge 2 commits into
Closed
Improve fgGetStaticFieldSeqAndAddress and fgValueNumberConstLoad#128638EgorBo wants to merge 2 commits into
EgorBo wants to merge 2 commits into
Conversation
Member
Author
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates JIT value-numbering helpers in valuenum.cpp to better recognize static-field address patterns (including cases where constant offsets are hidden in VNs) and to widen constant-load folding opportunities during value numbering.
Changes:
- Refactors
fgGetStaticFieldSeqAndAddressinto an instance method and enhances it to use conservative-normal VNs plusValueNumStore::PeelOffsetsto recover additional constant offsets. - Updates constant-load VN folding (
fgValueNumberConstLoad) to preserve exception sets when applying folded VNs and to attempt folding from additional address forms (including icon handles). - Adjusts some static-field content reads to pass
ignoreMovableObjects=falseand updates call sites to the newfgGetStaticFieldSeqAndAddresssignature.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/coreclr/jit/valuenum.cpp | Enhances static-field address detection via conservative VNs + VN offset peeling; widens const-load VN folding and preserves exception sets when applying folded VNs. |
| src/coreclr/jit/compiler.h | Changes fgGetStaticFieldSeqAndAddress declaration to instance method and adds a new VN-based folding method declaration. |
| } | ||
| *ppValue = new (alloc) uint8_t[(size_t)size]; | ||
| return info.compCompHnd->getStaticFieldContent(fld, *ppValue, size, (int)byteOffset); | ||
| return info.compCompHnd->getStaticFieldContent(fld, *ppValue, size, (int)byteOffset, false); |
Comment on lines
12849
to
12854
| // Pass ignoreMovableObjects=false so we can fold ref-typed static readonly fields | ||
| // even when the referenced object lives on the regular (movable) heap. The JIT-side | ||
| // handle returned by the runtime keeps the object alive for the lifetime of the | ||
| // compiled code. | ||
| if (info.compCompHnd->getStaticFieldContent(fieldHandle, buffer, size, (int)byteOffset, false)) | ||
| { |
| PhaseStatus fgVNBasedIntrinsicExpansion(); | ||
| bool fgVNBasedIntrinsicExpansionForCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call); | ||
| bool fgVNBasedIntrinsicExpansionForCall_ReadUtf8(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call); | ||
| bool fgVNBasedFoldSequenceEqualCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call); |
The Copilot PR review caught two issues that I have confirmed by adding a local regression test (movable static readonly object reference): 1. Passing ignoreMovableObjects=false to getStaticFieldContent for a ref-typed static field returns a tagged JIT-side OBJECTHANDLE rather than the field's actual reference value. The JIT then folded that value as a plain immediate, but for non-frozen (movable) objects the GC moves the underlying object so the immediate becomes stale. Reverting both call sites to the default (ignoreMovableObjects=true) restores the safe behavior: folding only succeeds when the object is in a frozen segment. 2. Drops the orphan fgVNBasedFoldSequenceEqualCall declaration from compiler.h; no implementation/callers exist for it. Local validation: * Hand-crafted test with a static readonly object Obj = new object() and Bench.Test(o) => o == Obj returned false even when called with Bench.Obj before the fix; passes after. * SPMI replay clean on benchmarks.run, coreclr_tests, libraries.crossgen2, libraries.pmi (no asserts). * SPMI asmdiffs: no asm diffs on any of those four collections, confirming the remaining VN refactor is functionally equivalent to main. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2ef3f0c to
3ef81f2
Compare
Member
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.
No description provided.