Skip to content
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

Do not nop-out SSA definitions in block morphing #92786

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3504,6 +3504,11 @@ struct GenTreeLclVarCommon : public GenTreeUnOp
return m_ssaNum.IsComposite();
}

bool HasSsaIdentity() const
{
return !m_ssaNum.IsInvalid();
}

#if DEBUGGABLE_GENTREE
GenTreeLclVarCommon() : GenTreeUnOp()
{
Expand Down
7 changes: 4 additions & 3 deletions src/coreclr/jit/morphblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,9 +750,10 @@ void MorphCopyBlockHelper::MorphStructCases()
}
}

// Check to see if we are doing a copy to/from the same local block.
// If so, morph it to a nop.
if ((m_dstVarDsc != nullptr) && (m_srcVarDsc == m_dstVarDsc) && (m_dstLclOffset == m_srcLclOffset))
// Check to see if we are doing a copy to/from the same local block. If so, morph it to a nop.
// Don't do this for SSA definitions as we have no way to update downstream uses.
if ((m_dstVarDsc != nullptr) && (m_srcVarDsc == m_dstVarDsc) && (m_dstLclOffset == m_srcLclOffset) &&
!m_store->AsLclVarCommon()->HasSsaIdentity())
{
JITDUMP("Self-copy; replaced with a NOP.\n");
m_transformationDecision = BlockTransformation::Nop;
Expand Down
69 changes: 69 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_91839/Runtime_91839.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Xunit;

public class Runtime_91839
{
public static I0[] s_1;
public static I2 s_5;

[Fact]
public static void TestEntryPoint()
{
S1 vr2 = new S1(new S0(0));
if (vr2.F5)
{
s_5 = s_5;
}

S1 vr3 = vr2;
vr3.F4 = vr3.F4;
for (int vr4 = 0; vr4 < 1; vr4++)
{
var vr5 = vr3.F4;
M2(vr5);
}

Assert.True(vr3.F4.F2 == 0);
}

private static void M2(S0 arg0)
{
s_1 = new I0[] { new C0() };
}

public interface I0
{
}

public interface I2
{
}

public struct S0
{
public ulong F0;
public long F2;
public short F3;
public S0(long f2) : this()
{
F2 = f2;
}
}

public class C0 : I0
{
}

public struct S1
{
public S0 F4;
public bool F5;
public S1(S0 f4) : this()
{
F4 = f4;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>

<!-- Needed for CLRTestEnvironmentVariable -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
<CLRTestEnvironmentVariable Include="DOTNET_JitStressModeNames" Value="STRESS_NO_OLD_PROMOTION" />
</ItemGroup>
</Project>