Skip to content

Commit f401263

Browse files
Do not nop-out SSA definitions in block morphing (#92786)
SSA definitions cannot be deleted.
1 parent 38fd485 commit f401263

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

src/coreclr/jit/gentree.h

+5
Original file line numberDiff line numberDiff line change
@@ -3516,6 +3516,11 @@ struct GenTreeLclVarCommon : public GenTreeUnOp
35163516
return m_ssaNum.IsComposite();
35173517
}
35183518

3519+
bool HasSsaIdentity() const
3520+
{
3521+
return !m_ssaNum.IsInvalid();
3522+
}
3523+
35193524
#if DEBUGGABLE_GENTREE
35203525
GenTreeLclVarCommon() : GenTreeUnOp()
35213526
{

src/coreclr/jit/morphblock.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,10 @@ void MorphCopyBlockHelper::MorphStructCases()
750750
}
751751
}
752752

753-
// Check to see if we are doing a copy to/from the same local block.
754-
// If so, morph it to a nop.
755-
if ((m_dstVarDsc != nullptr) && (m_srcVarDsc == m_dstVarDsc) && (m_dstLclOffset == m_srcLclOffset))
753+
// Check to see if we are doing a copy to/from the same local block. If so, morph it to a nop.
754+
// Don't do this for SSA definitions as we have no way to update downstream uses.
755+
if ((m_dstVarDsc != nullptr) && (m_srcVarDsc == m_dstVarDsc) && (m_dstLclOffset == m_srcLclOffset) &&
756+
!m_store->AsLclVarCommon()->HasSsaIdentity())
756757
{
757758
JITDUMP("Self-copy; replaced with a NOP.\n");
758759
m_transformationDecision = BlockTransformation::Nop;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using Xunit;
6+
7+
public class Runtime_91839
8+
{
9+
public static I0[] s_1;
10+
public static I2 s_5;
11+
12+
[Fact]
13+
public static void TestEntryPoint()
14+
{
15+
S1 vr2 = new S1(new S0(0));
16+
if (vr2.F5)
17+
{
18+
s_5 = s_5;
19+
}
20+
21+
S1 vr3 = vr2;
22+
vr3.F4 = vr3.F4;
23+
for (int vr4 = 0; vr4 < 1; vr4++)
24+
{
25+
var vr5 = vr3.F4;
26+
M2(vr5);
27+
}
28+
29+
Assert.True(vr3.F4.F2 == 0);
30+
}
31+
32+
private static void M2(S0 arg0)
33+
{
34+
s_1 = new I0[] { new C0() };
35+
}
36+
37+
public interface I0
38+
{
39+
}
40+
41+
public interface I2
42+
{
43+
}
44+
45+
public struct S0
46+
{
47+
public ulong F0;
48+
public long F2;
49+
public short F3;
50+
public S0(long f2) : this()
51+
{
52+
F2 = f2;
53+
}
54+
}
55+
56+
public class C0 : I0
57+
{
58+
}
59+
60+
public struct S1
61+
{
62+
public S0 F4;
63+
public bool F5;
64+
public S1(S0 f4) : this()
65+
{
66+
F4 = f4;
67+
}
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
5+
<!-- Needed for CLRTestEnvironmentVariable -->
6+
<RequiresProcessIsolation>true</RequiresProcessIsolation>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Compile Include="$(MSBuildProjectName).cs" />
10+
<CLRTestEnvironmentVariable Include="DOTNET_JitStressModeNames" Value="STRESS_NO_OLD_PROMOTION" />
11+
</ItemGroup>
12+
</Project>

0 commit comments

Comments
 (0)