Skip to content

Commit cb1343d

Browse files
authored
JIT: block copy/zero assertion gen for structs with exposed promoted fields (#75375)
If a struct has an exposed field, we can't safely reason about is value in local assertion prop. Closes #75249.
1 parent aaf0bde commit cb1343d

File tree

3 files changed

+104
-3
lines changed

3 files changed

+104
-3
lines changed

src/coreclr/jit/assertionprop.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,15 +1473,32 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,
14731473
//
14741474
else if (op1->gtOper == GT_LCL_VAR)
14751475
{
1476-
unsigned lclNum = op1->AsLclVarCommon()->GetLclNum();
1477-
LclVarDsc* lclVar = lvaGetDesc(lclNum);
1476+
unsigned const lclNum = op1->AsLclVarCommon()->GetLclNum();
1477+
LclVarDsc* const lclVar = lvaGetDesc(lclNum);
14781478

1479-
// If the local variable has its address exposed then bail
1479+
// If the local variable has its address exposed then bail
1480+
//
14801481
if (lclVar->IsAddressExposed())
14811482
{
14821483
goto DONE_ASSERTION; // Don't make an assertion
14831484
}
14841485

1486+
// If the local is a promoted struct and has an exposed field then bail.
1487+
//
1488+
if (lclVar->lvPromoted)
1489+
{
1490+
for (unsigned childLclNum = lclVar->lvFieldLclStart;
1491+
childLclNum < lclVar->lvFieldLclStart + lclVar->lvFieldCnt; ++childLclNum)
1492+
{
1493+
LclVarDsc* const childVar = lvaGetDesc(childLclNum);
1494+
1495+
if (childVar->IsAddressExposed())
1496+
{
1497+
goto DONE_ASSERTION;
1498+
}
1499+
}
1500+
}
1501+
14851502
if (helperCallArgs)
14861503
{
14871504
//
@@ -1701,6 +1718,22 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,
17011718
goto DONE_ASSERTION; // Don't make an assertion
17021719
}
17031720

1721+
// If the local is a promoted struct and has an exposed field then bail.
1722+
//
1723+
if (lclVar2->lvPromoted)
1724+
{
1725+
for (unsigned childLclNum = lclVar2->lvFieldLclStart;
1726+
childLclNum < lclVar2->lvFieldLclStart + lclVar2->lvFieldCnt; ++childLclNum)
1727+
{
1728+
LclVarDsc* const childVar = lvaGetDesc(childLclNum);
1729+
1730+
if (childVar->IsAddressExposed())
1731+
{
1732+
goto DONE_ASSERTION;
1733+
}
1734+
}
1735+
}
1736+
17041737
assertion.op2.kind = O2K_LCLVAR_COPY;
17051738
assertion.op2.vn = optConservativeNormalVN(op2);
17061739
assertion.op2.lcl.lclNum = lclNum2;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
// Generated by Fuzzlyn v1.5 on 2022-09-04 15:54:25
5+
// Run on X86 Windows
6+
// Seed: 14105179845188319926
7+
// Reduced from 33.3 KiB to 0.8 KiB in 00:01:22
8+
// Debug: Outputs 0
9+
// Release: Outputs 1
10+
11+
public struct S1
12+
{
13+
public uint F0;
14+
public S2 M18(ref int arg0, ulong arg1)
15+
{
16+
S1 var6;
17+
try
18+
{
19+
}
20+
finally
21+
{
22+
var6.F0 = Runtime_75249.s_13;
23+
this = var6;
24+
}
25+
26+
return new S2(0);
27+
}
28+
}
29+
30+
public struct S2
31+
{
32+
public S1 F0;
33+
public short F1;
34+
public S2(short f1): this()
35+
{
36+
F1 = f1;
37+
}
38+
}
39+
40+
public class Runtime_75249
41+
{
42+
public static byte s_4;
43+
public static int s_10;
44+
public static uint s_13 = 1;
45+
public static int s_19;
46+
public static int Main()
47+
{
48+
S2 vr1 = new S2(-1);
49+
byte r = M17(vr1, M17(vr1.F0.M18(ref s_19, 0), s_4));
50+
return r == 0 ? 100 : -1;
51+
}
52+
53+
public static byte M17(S2 arg0, int arg4)
54+
{
55+
uint r = arg0.F0.F0;
56+
System.Console.WriteLine(r);
57+
return (byte) r;
58+
}
59+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<Optimize>True</Optimize>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<Compile Include="$(MSBuildProjectName).cs" />
8+
</ItemGroup>
9+
</Project>

0 commit comments

Comments
 (0)