Skip to content

JIT: revisions to struct field escape analysis #116124

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
merged 2 commits into from
Jun 1, 2025

Conversation

AndyAyersMS
Copy link
Member

Peel off some changes from the more general field-wise escape analysis:

  • make sure we have modelled all relevant stores. Change local store tracking to use the new model.
  • keep track of which temps will represent stack allocated arrays and do suitable retyping
  • reject "known escaping" allocations earlier (eg finalizable objects)
  • handle local fields (rare but can exist in importer IR)
  • add the field test cases; all of these stack allocate for now

This generally is able to classify more locals as non-GC.

Peel off some changes from the more general field-wise escape analysis:
* make sure we have modelled all relevant stores. Change local store tracking to use the new model.
* keep track of which temps will represent stack allocated arrays and do suitable retyping
* reject "known escaping" allocations earlier (eg finalizable objects)
* handle local fields (rare but can exist in importer IR)
* add the field test cases; all of these stack allocate for now

This generally is able to classify more locals as non-GC.
@Copilot Copilot AI review requested due to automatic review settings May 30, 2025 01:18
@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 30, 2025
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.

Pull Request Overview

This PR refines the JIT’s struct field escape analysis to better model field stores, improve local variable retyping, and distinguish between stack allocations for objects and arrays.

  • Introduces a new StoreInfo struct and updates NodeToIndexMap to use it.
  • Splits the heap-local-to-stack mapping into separate object and array maps.
  • Revises allocation classification with the introduction of a new OAT_NEWOBJ_HEAP type and adjusts connection graph modeling.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

File Description
src/tests/JIT/opt/ObjectStackAllocation/Fields.csproj Adds project configuration for better isolation and optimization.
src/coreclr/jit/objectalloc.h Adds StoreInfo struct and updates mapping types for escape analysis.
src/coreclr/jit/objectalloc.cpp Revises allocation logic, retyping, and connection graph edge handling.
src/coreclr/jit/gentree.h Removes the GTF_VAR_CONNECTED flag in accordance with the new model.
Comments suppressed due to low confidence (1)

src/coreclr/jit/gentree.h:452

  • Ensure that the removal of GTF_VAR_CONNECTED is consistent across the codebase so that modules expecting this flag are updated accordingly.
GTF_VAR_CONNECTED     = 0x00100000, // GT_STORE_LCL_VAR -- this store was modelled in the connection graph during escape analysis

assert(clsHnd != NO_CLASS_HANDLE);
const bool isValueClass = comp->info.compCompHnd->isValueClass(clsHnd);
bool const canBeOnStack = isValueClass || comp->info.compCompHnd->canAllocateOnStack(clsHnd);
allocType = canBeOnStack ? OAT_NEWOBJ : OAT_NEWOBJ_HEAP;
Copy link
Preview

Copilot AI May 30, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding documentation that explains the distinction between OAT_NEWOBJ and OAT_NEWOBJ_HEAP to clarify when each allocation type is chosen.

Copilot uses AI. Check for mistakes.

@@ -2004,9 +2180,10 @@ void ObjectAllocator::AnalyzeParentStack(ArrayStack<GenTree*>* parentStack, unsi
}
}

if (canLclVarEscapeViaParentStack)
if (canLclVarEscapeViaParentStack && !CanIndexEscape(lclIndex))
Copy link
Preview

Copilot AI May 30, 2025

Choose a reason for hiding this comment

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

[nitpick] Add a comment to clarify the rationale for including the '!CanIndexEscape(lclIndex)' check, which would help maintain code clarity.

Copilot uses AI. Check for mistakes.

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 @dotnet/jit-contrib

SPMI will show many missing contexts here due to missing isValueClass results. Local bespoke SPMI of asp.net had no diffs.

@jakobbotsch
Copy link
Member

/azp run Fuzzlyn

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@AndyAyersMS
Copy link
Member Author

Looks like fuzzlyn sees more can assign from failures.

@AndyAyersMS
Copy link
Member Author

/azp run Fuzzlyn

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@AndyAyersMS
Copy link
Member Author

/ba-g unrelated test failure without a log

@AndyAyersMS AndyAyersMS merged commit 3be9089 into dotnet:main Jun 1, 2025
119 of 123 checks passed
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