Skip to content

JIT: fix retyping of BLK ops when parent local is retyped #116027

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 29, 2025

Conversation

AndyAyersMS
Copy link
Member

Properly handle cases where we have updated the layout of a struct local (because its fields may now refer to stack allocated objects) and then store or load from just part of that local.

Fixes #115979.

Properly handle cases where we have updated the layout of a struct local (because
its fields may now refer to stack allocated objects) and then store or load from
just part of that local.

Fixes dotnet#115979.
@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 17:26
@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 27, 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 fixes the retyping of BLK operations when a parent local’s layout changes, addressing issues related to partial updates of struct locals.

  • Updated the object allocation logic in the JIT to correctly handle retyping for both store and load operations.
  • Added a regression test in the ObjectStackAllocation test suite to capture the fixed behavior.

Reviewed Changes

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

File Description
src/tests/JIT/opt/ObjectStackAllocation/Runtime_115979.csproj Added a new test project for the regression test.
src/tests/JIT/opt/ObjectStackAllocation/Runtime_115979.cs Added a test case to validate the fixed retyping behavior.
src/coreclr/jit/objectalloc.cpp Updated retyping logic for BLK ops in both store and load cases.

// If we are storing a struct, we may need to change the layout
//
if (retypeFields && parent->OperIs(GT_STORE_BLK))
else if (retypeFields && parent->OperIs(GT_STORE_BLK))
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

Consider adding a more detailed comment above this branch to clarify the specific conditions for adjusting the block layout during BLK store operations, especially for the case when only a portion of the local is updated.

Copilot uses AI. Check for mistakes.

@@ -2219,19 +2239,54 @@ void ObjectAllocator::UpdateAncestorTypes(
{
// If we are loading from a GC struct field, we may need to retype the load
//
if (retypeFields && (varTypeIsGC(parent->TypeGet())))
if (retypeFields)
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

It might be helpful to document the purpose of the 'didRetype' flag and the rationale for resetting 'retypeFields' to false in this load operation branch, to improve future maintainability and 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

No diffs.

@AndyAyersMS
Copy link
Member Author

Failures seem unrelated, but are not flagged by build analysis. Going to look at some other recent PRs.

@AndyAyersMS
Copy link
Member Author

@jakobbotsch ping

@AndyAyersMS AndyAyersMS merged commit 236643c into dotnet:main May 29, 2025
112 of 116 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.

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