Skip to content

JIT: update layout of BLK nodes during escape analysis #115845

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 1 commit into from
May 22, 2025

Conversation

AndyAyersMS
Copy link
Member

If we retype a struct local we also need to retype any BLK operations on those locals.

Fixes #115832.

If we retype a struct local we also need to retype any BLK operations
on those locals.

Fixes dotnet#115832.
@Copilot Copilot AI review requested due to automatic review settings May 21, 2025 17:04
@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 21, 2025
@AndyAyersMS
Copy link
Member Author

AndyAyersMS commented May 21, 2025

@dotnet/jit-contrib PTAL

No diffs but a lot of missed contexts.

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 fixes a JIT assertion by propagating updated struct layouts to BLK nodes during escape analysis retyping.

  • Extended UpdateAncestorTypes to accept a new ClassLayout* newLayout parameter.
  • Added SetLayout calls for GT_STORE_BLK and GT_BLK nodes when retypeFields is true.
  • Introduced a new repro test (Runtime_115832) to catch the original assertion.

Reviewed Changes

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

Show a summary per file
File Description
src/tests/JIT/opt/ObjectStackAllocation/*.csproj Added optimized test project for repro case
src/tests/JIT/opt/ObjectStackAllocation/Runtime_115832.cs New fuzz-generated test reproducing the JIT assert
src/coreclr/jit/objectalloc.h Updated UpdateAncestorTypes signature to include newLayout
src/coreclr/jit/objectalloc.cpp Implemented layout propagation to BLK nodes
src/coreclr/jit/gentree.h Added GenTreeBlk::SetLayout to allow runtime layout updates
Comments suppressed due to low confidence (2)

src/coreclr/jit/objectalloc.cpp:2196

  • Consider adding a unit test that exercises the GT_STORE_BLK retype path to ensure SetLayout is correctly applied and prevent future regressions.
if (retypeFields && parent->OperIs(GT_STORE_BLK))

src/coreclr/jit/objectalloc.cpp:2189

  • The removal of the addr->OperIs(GT_FIELD_ADDR) check broadens the STOREIND retyping logic beyond struct field stores, which conflicts with the existing comment. Consider restoring that guard or updating the comment to reflect the intended behavior.
if (parent->OperIs(GT_STOREIND) && varTypeIsGC(parent->TypeGet()))

@@ -2007,6 +2007,7 @@ void ObjectAllocator::AnalyzeParentStack(ArrayStack<GenTree*>* parentStack, unsi
// tree - Possibly-stack-pointing tree
// parentStack - Parent stack of the possibly-stack-pointing tree
// newType - New type of the possibly-stack-pointing tree
// newLayout - Layout for a retyped local struct
Copy link
Preview

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

You added a description for newLayout in the implementation comments; please update the corresponding declaration comment in objectalloc.h so the header and implementation stay in sync.

Copilot uses AI. Check for mistakes.

@AndyAyersMS
Copy link
Member Author

@dotnet/jit-contrib ping

@AndyAyersMS AndyAyersMS merged commit 1c653e9 into dotnet:main May 22, 2025
115 checks passed
SimaTian pushed a commit that referenced this pull request May 27, 2025
If we retype a struct local we also need to retype any BLK operations
on those locals.

Fixes #115832.
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.

JIT: Assertion failed 'm_blockLayout->CanAssignFrom(m_src->GetLayout(m_comp))' during 'Morph - Global'
2 participants