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

JIT: Mark replacements as dirty after setting GTF_VAR_DEATH #88669

Merged
merged 2 commits into from
Jul 13, 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
8 changes: 8 additions & 0 deletions src/coreclr/jit/promotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2404,6 +2404,14 @@ void ReplaceVisitor::ReplaceLocal(GenTree** use, GenTree* user)
{
lcl->gtFlags |= GTF_VAR_DEATH;
CheckForwardSubForLastUse(lclNum);

// Relying on the values in the struct local after this struct use
// would effectively introduce another use of the struct, so
// indicate that no replacements are up to date.
for (Replacement& rep : replacements)
{
SetNeedsWriteBack(rep);
}
}
return;
}
Expand Down
63 changes: 63 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_88616/Runtime_88616.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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 System.Runtime.CompilerServices;
using Xunit;

public class Runtime_88616
{
[Fact]
public static int TestEntryPoint()
{
S foo;
foo.A = 10;
foo.B = 20;
foo.C = 30;
foo.D = 40;
foo.E = 50;
foo.A += foo.A += foo.A += foo.A += foo.A;
foo.B += foo.B += foo.B += foo.B += foo.B;
foo.C += foo.C += foo.C += foo.C += foo.C;
foo.D += foo.D += foo.D += foo.D += foo.D;
foo.E += foo.E += foo.E += foo.E += foo.E;
// 'foo' is a last use here (it is fully promoted so all of its state
// is stored in separate field locals), so physical promotions marks
// this occurence as GTF_VAR_DEATH.
Mutate(foo);
// However, we cannot use the fact that we wrote the fields back into
// the struct local above to skip those same write backs here; if we
// skip those write backs then we effectively introduce new uses of the
// struct local.
return Check(foo);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Mutate(S s)
{
s.A = -42;
Consume(ref s);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Consume(ref S s)
{
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static int Check(S s)
{
if (s.A != 50)
{
Console.WriteLine("FAIL: s.A == {0}", s.A);
return -1;
}

return 100;
}

private struct S
{
public long A, B, C, D, E;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
<DebugType>None</DebugType>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>