Skip to content

JIT: stop tracking TYP_I_IMPL locals in escape analysis #114130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

AndyAyersMS
Copy link
Member

Abstractly a non-GC local can't cause escape. On 32 bit platforms tracking connections to TYP_I_IMPL leads to confusion once we start struct field tracking, as we logically "overlay" GC and non-GC fields.

Contributes to #104936

Abstractly a non-GC local can't cause escape. On 32 bit platforms tracking connections
to `TYP_I_IMPL` leads to confusion once we start struct field tracking, as we logically
"overlay" GC and non-GC fields.

Contributes to dotnet#104936
@Copilot Copilot AI review requested due to automatic review settings April 1, 2025 23:09
Copy link
Contributor

@Copilot 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 wasn't able to review any files in this pull request.

Files not reviewed (1)
  • src/coreclr/jit/objectalloc.cpp: Language not supported

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 1, 2025
Copy link
Contributor

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

@AndyAyersMS
Copy link
Member Author

@jakobbotsch PTAL
cc @dontet/jitcontrib

Looks like just one diff on win/x64 (x86 may have more, still running).

@AndyAyersMS
Copy link
Member Author

We're walking up to some unexpected opcode ... just a guess but we likely need GT_SUB handling on the retyping pass as well.

Comment on lines +1586 to +1592
// If we're not tracking stores to this local, the value
// does not escape.
if (!IsTrackedLocal(dstLclNum))
{
canLclVarEscapeViaParentStack = false;
break;
}
Copy link
Member

Choose a reason for hiding this comment

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

Is that true? What if the object is pinned and a TYP_I_IMPL pointer to it is passed somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Pinning only lasts for the current stack frame, and the object being pinned must already exist, so the pinning lifetime will be shorter than the allocating stack frame lifetime.

I suppose the object (or part of the object) could be exposed cross-thread this way, so even though it could be stack allocated it would not be thread private.

Comment on lines 1821 to 1826
if (parent->TypeGet() != newType)
{
parent->ChangeType(newType);
++parentIndex;
keepChecking = true;
}
Copy link
Member

@jakobbotsch jakobbotsch Apr 2, 2025

Choose a reason for hiding this comment

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

Is it correct to keep retyping ancestors if the existing GT_SUB was not a pointer-result (e.g. byref - byref => TYP_I_IMPL)? I get it for the &byref - int case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah we should stop propagation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually this already happens, the only possibilities here are

parent    new
-----     ----
int       int
byref     byref
byref     int

so we only propagate in the byref->int case.

I will add some comments/asserts to make this clearer.

@AndyAyersMS AndyAyersMS merged commit 7c05ef1 into dotnet:main Apr 3, 2025
109 of 111 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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