JIT: fold char loads from movable static readonly strings#130197
Closed
EgorBo wants to merge 1 commit into
Closed
Conversation
Rely on GetImmutableDataFromAddress/getObjectContent instead of the getStringChar special path, and resolve movable 'static readonly' string fields (ignoreMovableObjects=false) so their immutable char content can be folded. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
@MihuBot -nuget |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates RyuJIT value numbering constant-folding so that char loads from immutable string content can be folded even when the string comes from a movable static readonly reference field, by resolving the field’s runtime value at JIT time and reading immutable object content via getObjectContent.
Changes:
- Extend
Compiler::GetObjectHandleAndOffsetto recognize addresses based onstatic readonlyref field loads (via VN patterns) and resolve the field’s object value usinggetStaticFieldContent(..., ignoreMovableObjects: false)when the target object is immutable (excluding arrays). - Remove the
getStringChar-based special-casing infgValueNumberConstLoadso folding relies on the generalgetObjectContentpath.
Comment on lines
+12880
to
12885
| // Use the liberal VN: the content we are about to read is immutable, so a constant fold is | ||
| // correct even when the liberal and conservative VNs differ (e.g. a load from a movable | ||
| // 'static readonly' reference field has an opaque conservative VN). | ||
| ValueNum treeVN = tree->gtVNPair.GetLiberal(); | ||
| if (treeVN == ValueNumStore::NoVN) | ||
| { |
This was referenced Jul 4, 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.
Fold char loads from movable
static readonlystrings (e.g.Str = 111111.ToString(); ... str[2]).Removes the
getStringCharspecial path infgValueNumberConstLoadin favor of thegetObjectContentpath, and teachesGetObjectHandleAndOffsetto resolve movablestatic readonlystring fields (viagetStaticFieldContent(ignoreMovableObjects: false)) so their immutable char content can be folded. The movable handle is only used to read content at compile time, never materialized. Arrays are excluded (mutable contents).