Skip to content

Intrinsify string.FastAllocateString#127659

Draft
EgorBo wants to merge 5 commits intodotnet:mainfrom
EgorBo:intrinsify-fast-alloc-string
Draft

Intrinsify string.FastAllocateString#127659
EgorBo wants to merge 5 commits intodotnet:mainfrom
EgorBo:intrinsify-fast-alloc-string

Conversation

@EgorBo
Copy link
Copy Markdown
Member

@EgorBo EgorBo commented May 1, 2026

Another experiment (for better #127655)

Mark String.FastAllocateString with [Intrinsic] and teach RyuJIT to:

  • Track the result as known non-null via VNF_StrFastAllocate (knownNonNull=true)
  • Fold ARR_LENGTH(VNF_StrFastAllocate(len)) -> len
  • Emit a global assertion 'string.Length(result) == lenArg' in optAssertionGen

Example:

int Foo()
{
    string a = "aaa";
    string b = "bbb";
    string c = a + b;
    return c[3]; // this PR removes this bound check
}

Copilot AI review requested due to automatic review settings May 1, 2026 19:30
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 1, 2026
@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented May 1, 2026

@MihuBot

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@EgorBo EgorBo force-pushed the intrinsify-fast-alloc-string branch from fa0f780 to f354afd Compare May 1, 2026 20:23
Copilot AI review requested due to automatic review settings May 1, 2026 20:27
@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented May 1, 2026

@MihuBot

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/jit/valuenum.cpp Outdated
Comment thread src/coreclr/jit/valuenumfuncs.h Outdated
Comment thread src/coreclr/jit/importercalls.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 1, 2026 20:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/jit/valuenum.cpp Outdated
@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented May 1, 2026

@MihuBot

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/coreclr/jit/valuenum.cpp:2576

  • This change introduces new JIT intrinsic/VN behavior that affects bounds-check elimination (e.g. folding ARR_LENGTH(StrFastAllocate(...))). Please add a JIT regression test that verifies the expected optimization (for example, the concat+index pattern from the PR description, with a disasm check or other stable assertion) so we can catch future regressions.
            // Case 4: ARR_LENGTH(new T[(long)size]) -> size
            //         ARR_LENGTH(String.FastAllocateString(pMT, (long)size)) -> size
            VNFuncApp newArrFuncApp;
            if (GetVNFunc(arg0VN, &newArrFuncApp) &&
                ((newArrFuncApp.m_func == VNF_JitNewArr) || (newArrFuncApp.m_func == VNF_StrFastAllocate)))
            {
                ValueNum actualSizeVN = VNIgnoreIntToLongCast(newArrFuncApp.m_args[1]);
                if (TypeOfVN(actualSizeVN) == TYP_INT)
                {
                    *resultVN = actualSizeVN;
                }

Comment thread src/coreclr/jit/valuenum.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants