Skip to content

Conversation

@jakobbotsch
Copy link
Member

When hoisting we were cloning the full tree but only copying memory dependence of the root node. Ensure we copy it for the full tree.

Fix #115109

When hoisting we were cloning the full tree but only copying memory
dependence of the root node. Ensure we copy it for the full tree.
@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 28, 2025
@dotnet-policy-service
Copy link
Contributor

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

@jakobbotsch jakobbotsch marked this pull request as ready for review May 28, 2025 14:29
Copilot AI review requested due to automatic review settings May 28, 2025 14:29
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

No diffs.

@jakobbotsch jakobbotsch requested a review from AndyAyersMS May 28, 2025 14:30
Copy link
Contributor

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 issue #115109 by ensuring loop memory dependencies are copied recursively when hoisting expression trees. It also streamlines statement insertion and adds a regression test to validate the fix.

  • Simplify hoisted statement insertion in optPerformHoistExpr using fgInsertStmtAtEnd
  • Enhance optCopyLoopMemoryDependence to recurse through all tree operands
  • Add a JIT regression test project and C# test (Runtime_115109) to cover the full-tree dependence copy

Reviewed Changes

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

File Description
src/tests/JIT/Regression/JitBlue/Runtime_115109/Runtime_115109.csproj New test project (missing framework target)
src/tests/JIT/Regression/JitBlue/Runtime_115109/Runtime_115109.cs Generated fuzz test to verify memory-dependence cloning
src/coreclr/jit/optimizer.cpp Refactored hoist insertion and recursive memory-dependence copy

@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

The project file is missing a <TargetFramework> entry, so it may fail to build. Please add something like <TargetFramework>net7.0</TargetFramework> under the PropertyGroup.

Suggested change
<Optimize>True</Optimize>
<Optimize>True</Optimize>
<TargetFramework>net7.0</TargetFramework>

Copilot uses AI. Check for mistakes.
public static int TestEntryPoint()
{
s_10 = [Vector128.CreateScalar(0).AsVector()];
bool vr5 = 0 <= M10();
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

[nitpick] The variable vr5 is assigned but never used; consider removing it or using the result directly in the return or an assertion to make its purpose clear.

Suggested change
bool vr5 = 0 <= M10();
Assert.True(0 <= M10(), "Expected M10() to return a value greater than or equal to 0.");

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point, but I don't think it's worth rerunning CI.

Comment on lines +4286 to +4287
// This requires 'toTree' to be in its own statement
//
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

[nitpick] The remark about 'toTree' needing to be in its own statement is unclear. It would help to clarify the precondition (e.g., both trees must be part of the same statement sequence) or remove if not needed.

Suggested change
// This requires 'toTree' to be in its own statement
//
// 'toTree' must be part of a separate statement sequence to ensure proper
// traversal and mapping in the loop memory dependence analysis.

Copilot uses AI. Check for mistakes.
Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

LGTM.

Alternative idea: make this be an optional action for gtCloneExpr, since it has old and new nodes in hand ... (and do likewise for optRecordSsaUses).

@jakobbotsch
Copy link
Member Author

Alternative idea: make this be an optional action for gtCloneExpr, since it has old and new nodes in hand ... (and do likewise for optRecordSsaUses).

It means everyone gets to pay for it. I removed optional actions from gtCloneExpr in #97411 because I didn't think that tradeoff is good. Perhaps if we templatized gtCloneExpr in some way.

@jakobbotsch jakobbotsch merged commit 9703a2e into dotnet:main May 28, 2025
113 of 116 checks passed
@jakobbotsch jakobbotsch deleted the fix-115109 branch May 28, 2025 14:51
@github-actions github-actions bot locked and limited conversation to collaborators Jun 28, 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.

JIT: Wrong result with do-while loops

2 participants