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: block copy/zero assertion gen for structs with exposed promoted … #75375

Merged
merged 1 commit into from
Sep 10, 2022
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
JIT: block copy/zero assertion gen for structs with exposed promoted …
…fields

If a struct has an exposed field, we can't safely reason about is value in
local assertion prop.

Closes #75249.
  • Loading branch information
AndyAyersMS committed Sep 9, 2022
commit cce3383cee5ce13327302cdb16764408a5f2e4ff
39 changes: 36 additions & 3 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,15 +1473,32 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,
//
else if (op1->gtOper == GT_LCL_VAR)
{
unsigned lclNum = op1->AsLclVarCommon()->GetLclNum();
LclVarDsc* lclVar = lvaGetDesc(lclNum);
unsigned const lclNum = op1->AsLclVarCommon()->GetLclNum();
LclVarDsc* const lclVar = lvaGetDesc(lclNum);

// If the local variable has its address exposed then bail
// If the local variable has its address exposed then bail
//
if (lclVar->IsAddressExposed())
{
goto DONE_ASSERTION; // Don't make an assertion
}

// If the local is a promoted struct and has an exposed field then bail.
//
if (lclVar->lvPromoted)
{
for (unsigned childLclNum = lclVar->lvFieldLclStart;
childLclNum < lclVar->lvFieldLclStart + lclVar->lvFieldCnt; ++childLclNum)
{
LclVarDsc* const childVar = lvaGetDesc(childLclNum);

if (childVar->IsAddressExposed())
{
goto DONE_ASSERTION;
}
}
}

if (helperCallArgs)
{
//
Expand Down Expand Up @@ -1701,6 +1718,22 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,
goto DONE_ASSERTION; // Don't make an assertion
}

// If the local is a promoted struct and has an exposed field then bail.
//
if (lclVar2->lvPromoted)
{
for (unsigned childLclNum = lclVar2->lvFieldLclStart;
childLclNum < lclVar2->lvFieldLclStart + lclVar2->lvFieldCnt; ++childLclNum)
{
LclVarDsc* const childVar = lvaGetDesc(childLclNum);

if (childVar->IsAddressExposed())
{
goto DONE_ASSERTION;
}
}
}

assertion.op2.kind = O2K_LCLVAR_COPY;
assertion.op2.vn = optConservativeNormalVN(op2);
assertion.op2.lcl.lclNum = lclNum2;
Expand Down
59 changes: 59 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_75249/Runtime_75249.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Generated by Fuzzlyn v1.5 on 2022-09-04 15:54:25
// Run on X86 Windows
// Seed: 14105179845188319926
// Reduced from 33.3 KiB to 0.8 KiB in 00:01:22
// Debug: Outputs 0
// Release: Outputs 1

public struct S1
{
public uint F0;
public S2 M18(ref int arg0, ulong arg1)
{
S1 var6;
try
{
}
finally
{
var6.F0 = Runtime_75249.s_13;
this = var6;
}

return new S2(0);
}
}

public struct S2
{
public S1 F0;
public short F1;
public S2(short f1): this()
{
F1 = f1;
}
}

public class Runtime_75249
{
public static byte s_4;
public static int s_10;
public static uint s_13 = 1;
public static int s_19;
public static int Main()
{
S2 vr1 = new S2(-1);
byte r = M17(vr1, M17(vr1.F0.M18(ref s_19, 0), s_4));
return r == 0 ? 100 : -1;
}

public static byte M17(S2 arg0, int arg4)
{
uint r = arg0.F0.F0;
System.Console.WriteLine(r);
return (byte) r;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>