Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 0605549

Browse files
committed
Fix change to fgMorphBlockOperand
My recent fix broke the `DYN_BLK` case. In addition to checking that types match, we *still* need to check that the sizes match. This was caught by desktop testing. The test cases are somewhat complex, so I created a smaller repro.
1 parent 55bb222 commit 0605549

File tree

4 files changed

+176
-2
lines changed

4 files changed

+176
-2
lines changed

src/jit/morph.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10208,10 +10208,14 @@ GenTree* Compiler::fgMorphBlockOperand(GenTree* tree, var_types asgType, unsigne
1020810208
if (lclNode != nullptr)
1020910209
{
1021010210
LclVarDsc* varDsc = &(lvaTable[lclNode->gtLclNum]);
10211-
if (varTypeIsStruct(varDsc) && (varDsc->lvType == asgType))
10211+
if (varTypeIsStruct(varDsc) && (varDsc->lvExactSize == blockWidth) && (varDsc->lvType == asgType))
1021210212
{
1021310213
#ifndef LEGACY_BACKEND
10214-
effectiveVal = lclNode;
10214+
if (effectiveVal != lclNode)
10215+
{
10216+
JITDUMP("Replacing block node [%06d] with lclVar V%02u\n", dspTreeID(tree), lclNode->gtLclNum);
10217+
effectiveVal = lclNode;
10218+
}
1021510219
needsIndirection = false;
1021610220
#endif // !LEGACY_BACKEND
1021710221
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
// See the LICENSE file in the project root for more information.
4+
5+
// Test for a bug involving an initblk with a non-constant size,
6+
// for which the DYN_BLK(ADDR(lcl)) can't be optimized away.
7+
8+
.assembly extern legacy library mscorlib {}
9+
.assembly extern System.Console
10+
{
11+
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )
12+
.ver 4:0:0:0
13+
}
14+
15+
.assembly dynblk {}
16+
17+
.class public sequential ansi sealed beforefieldinit S8
18+
extends [mscorlib]System.ValueType
19+
{
20+
.field public uint64 val
21+
} // end of class S8
22+
23+
.class private auto ansi beforefieldinit Program
24+
extends [mscorlib]System.Object
25+
{
26+
.method public hidebysig static int32 GetSize3() cil managed noinlining
27+
{
28+
ldc.i4 3
29+
ret
30+
} // end of method Program::Init
31+
32+
.method public hidebysig static int32 GetSize5() cil managed noinlining
33+
{
34+
ldc.i4 5
35+
ret
36+
} // end of method Program::Init
37+
38+
.method private hidebysig static int32
39+
Main() cil managed
40+
{
41+
.entrypoint
42+
.locals init (valuetype S8 S, int32 retVal, int32 size)
43+
ldloca.s S
44+
ldc.i4 0
45+
ldc.i4 8
46+
initblk
47+
48+
call int32 Program::GetSize5()
49+
stloc.s size
50+
51+
ldloca.s S
52+
ldc.i4 0x55
53+
ldloc.s size
54+
initblk
55+
56+
call int32 Program::GetSize3()
57+
stloc.s size
58+
59+
ldloca.s S
60+
ldc.i4 0x33
61+
ldloc.s size
62+
initblk
63+
64+
ldloca.s S
65+
ldfld uint64 S8::val
66+
ldc.i8 0x5555333333
67+
ceq
68+
brtrue.s L1
69+
70+
ldstr "Fail"
71+
call void [mscorlib]System.Console::WriteLine(string)
72+
nop
73+
ldc.i4.m1
74+
stloc.s retVal
75+
br.s L2
76+
77+
L1: ldstr "Pass"
78+
call void [mscorlib]System.Console::WriteLine(string)
79+
nop
80+
ldc.i4.s 100
81+
stloc.s retVal
82+
83+
L2: ldloc.s retVal
84+
ret
85+
} // end of method Program::Main
86+
87+
.method public hidebysig specialname rtspecialname
88+
instance void .ctor() cil managed
89+
{
90+
// Code size 8 (0x8)
91+
.maxstack 8
92+
ldarg.0
93+
call instance void [mscorlib]System.Object::.ctor()
94+
nop
95+
ret
96+
} // end of method Program::.ctor
97+
98+
} // end of class Program
99+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
10+
<OutputType>Exe</OutputType>
11+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
12+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
13+
</PropertyGroup>
14+
<!-- Default configurations to help VS understand the configurations -->
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
18+
</PropertyGroup>
19+
<ItemGroup>
20+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
21+
<Visible>False</Visible>
22+
</CodeAnalysisDependentAssemblyPaths>
23+
</ItemGroup>
24+
<PropertyGroup>
25+
<DebugType>Full</DebugType>
26+
</PropertyGroup>
27+
<ItemGroup>
28+
<Compile Include="dynblk.il" />
29+
</ItemGroup>
30+
<ItemGroup>
31+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
32+
</ItemGroup>
33+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
34+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
35+
</PropertyGroup>
36+
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
10+
<OutputType>Exe</OutputType>
11+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
12+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
13+
</PropertyGroup>
14+
<!-- Default configurations to help VS understand the configurations -->
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup>
17+
<PropertyGroup>
18+
<DebugType>PdbOnly</DebugType>
19+
<Optimize>False</Optimize>
20+
</PropertyGroup>
21+
<ItemGroup>
22+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
23+
<Visible>False</Visible>
24+
</CodeAnalysisDependentAssemblyPaths>
25+
</ItemGroup>
26+
<PropertyGroup></PropertyGroup>
27+
<ItemGroup>
28+
<Compile Include="dynblk.il" />
29+
</ItemGroup>
30+
<ItemGroup>
31+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
32+
</ItemGroup>
33+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
34+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
35+
</Project>

0 commit comments

Comments
 (0)