Skip to content

JIT: escape analysis for object fields #115388

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

Closed

Conversation

AndyAyersMS
Copy link
Member

Add connection graph nodes and retyping for object fields. All GC fields of objects are tracked as one virtual field.

Also add support for GT_LCL_FLD and GT_STORE_LCL_FLD for local structs.

Contributes to #104936 and #108913

Add connection graph nodes and retyping for object fields. All GC fields
of objects are tracked as one virtual field.

Also add support for GT_LCL_FLD and GT_STORE_LCL_FLD for local structs.

Contributes to dotnet#104936 and dotnet#108913
@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 8, 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

Formatting errors seem like they may be from #115348 ?

@kendall1997
Copy link
Contributor

Created #115416 to try fix the issue.

…tack,

so we can properly escape its fields.

In particular finalizable objects can never be considered as non-escaping,
so any assignment to their fields escapes.
need to possibly retype the on-stack array layout. So we have to track
the array allocation locals and their stack counterparts and make
the appropriate layout update during rewriting.
@AndyAyersMS
Copy link
Member Author

Looked at one of the arm32 failures. In this case we have code like:

        var fullInput = new[]
        {
            new { utf8Bytes = new byte[] { 0x40 }, output = "@" },
            new { utf8Bytes = new byte[] { 0xC3, 0x85 }, output = "[00C5]" },
        };

and we can prove the arrays and objects don't escape. However we fail to notice the string assignment because we lack the equivalent of GTF_VAR_CONNECTED handling for field stores. That is

STMT00027 ( INL01 @ 0x00D[E-] ... ??? ) <- INLRT @ ???
               [000099] hA-XG------                         *  STOREIND  ref   
               [000098] ---X-------                         +--*  FIELD_ADDR byref  <>f__AnonymousType0`2[System.__Canon,System.__Canon]:<output>i__Field
               [000096] -----------                         |  \--*  LCL_VAR   ref    V07 tmp3         
               [000097] -----------                         \--*  CNS_STR   ref   <string constant>

does not create a connection graph edge V07.f <- unknown. So we retype the objects too aggressively.

Also I think we're being too pessimistic handling the Vxx <- Vyy.f case; currently we model this as

   Vxx <- Vyy.f
   Vxx.f <-> unknown (escapes)

this second rule since there is no immediate way to evaluate Vyy.f.f.

But it seems like we should defer the second rule here, and after building the connection graph we should connect Vxx.f to the things Vyy.f can refer to.

For example

   X a = new X();
   a.f = new Y();
   a.f.f = new Z();
   Y y = a.f;
   ...

Here we know what y.f points to. But I also think it's ok to be conservative here for now, so will leave this as a future enhancement.

@AndyAyersMS
Copy link
Member Author

Going to defer this until after .NET 10.

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