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

Commit 0803236

Browse files
AndyAyersMSRussKeldorph
authored andcommitted
Don't map P-DEP SIMD12 local vars to SIMD16 on x64
P-DEP local vars are logically independent locals, but physically embeded in some structure with fixed layout. So they cannot be made larger. We already had safeguards for ths in place for x86 so extend these to kick in for x64 too. Also update Lowering's checker to account for the fact that some SIMD12s can persist in x64. Fixes #12950.
1 parent d99bf2d commit 0803236

File tree

5 files changed

+90
-12
lines changed

5 files changed

+90
-12
lines changed

src/jit/compiler.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,12 +2744,11 @@ class Compiler
27442744

27452745
#if defined(_TARGET_64BIT_)
27462746
assert(varDsc->lvSize() == 16);
2747-
return true;
2748-
#else // !defined(_TARGET_64BIT_)
2747+
#endif // defined(_TARGET_64BIT_)
27492748

2750-
// For 32-bit architectures, we make local variable SIMD12 types 16 bytes instead of just 12. lvSize()
2749+
// We make local variable SIMD12 types 16 bytes instead of just 12. lvSize()
27512750
// already does this calculation. However, we also need to prevent mapping types if the var is a
2752-
// depenendently promoted struct field, which must remain its exact size within its parent struct.
2751+
// dependently promoted struct field, which must remain its exact size within its parent struct.
27532752
// However, we don't know this until late, so we may have already pretended the field is bigger
27542753
// before that.
27552754
if ((varDsc->lvSize() == 16) && !lvaIsFieldOfDependentlyPromotedStruct(varDsc))
@@ -2760,8 +2759,6 @@ class Compiler
27602759
{
27612760
return false;
27622761
}
2763-
2764-
#endif // !defined(_TARGET_64BIT_)
27652762
}
27662763
#endif // defined(FEATURE_SIMD)
27672764

src/jit/lower.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4656,9 +4656,10 @@ void Lowering::CheckCall(GenTreeCall* call)
46564656
// after lowering.
46574657
//
46584658
// Arguments:
4659+
// compiler - the compiler context.
46594660
// node - the node to check.
46604661
//
4661-
void Lowering::CheckNode(GenTree* node)
4662+
void Lowering::CheckNode(Compiler* compiler, GenTree* node)
46624663
{
46634664
switch (node->OperGet())
46644665
{
@@ -4668,13 +4669,19 @@ void Lowering::CheckNode(GenTree* node)
46684669

46694670
#ifdef FEATURE_SIMD
46704671
case GT_SIMD:
4672+
assert(node->TypeGet() != TYP_SIMD12);
4673+
break;
46714674
#ifdef _TARGET_64BIT_
46724675
case GT_LCL_VAR:
46734676
case GT_STORE_LCL_VAR:
4677+
{
4678+
unsigned lclNum = node->AsLclVarCommon()->GetLclNum();
4679+
LclVarDsc* lclVar = &compiler->lvaTable[lclNum];
4680+
assert(node->TypeGet() != TYP_SIMD12 || compiler->lvaIsFieldOfDependentlyPromotedStruct(lclVar));
4681+
}
4682+
break;
46744683
#endif // _TARGET_64BIT_
4675-
assert(node->TypeGet() != TYP_SIMD12);
4676-
break;
4677-
#endif
4684+
#endif // SIMD
46784685

46794686
default:
46804687
break;
@@ -4696,7 +4703,7 @@ bool Lowering::CheckBlock(Compiler* compiler, BasicBlock* block)
46964703
LIR::Range& blockRange = LIR::AsRange(block);
46974704
for (GenTree* node : blockRange)
46984705
{
4699-
CheckNode(node);
4706+
CheckNode(compiler, node);
47004707
}
47014708

47024709
assert(blockRange.CheckLIR(compiler));

src/jit/lower.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Lowering : public Phase
5151
#ifdef DEBUG
5252
static void CheckCallArg(GenTree* arg);
5353
static void CheckCall(GenTreeCall* call);
54-
static void CheckNode(GenTree* node);
54+
static void CheckNode(Compiler* compiler, GenTree* node);
5555
static bool CheckBlock(Compiler* compiler, BasicBlock* block);
5656
#endif // DEBUG
5757

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
using System;
6+
using System.Numerics;
7+
8+
class Program
9+
{
10+
struct BoundingBoxTest
11+
{
12+
public Vector3 Min;
13+
public Vector3 Max;
14+
15+
public override int GetHashCode()
16+
{
17+
return Min.GetHashCode() + Max.GetHashCode();
18+
}
19+
}
20+
21+
public static void Test()
22+
{
23+
var box = new BoundingBoxTest();
24+
box.Min = Vector3.Min(box.Min, box.Min);
25+
var hmm = box.GetHashCode();
26+
}
27+
28+
static int Main(string[] args)
29+
{
30+
var someMemory = new int[1];
31+
var someMoreMemory = new int[1];
32+
Test();
33+
someMoreMemory[someMemory[0]] = 100;
34+
return someMoreMemory[0];
35+
}
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
14+
</PropertyGroup>
15+
<!-- Default configurations to help VS understand the configurations -->
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
19+
</PropertyGroup>
20+
<ItemGroup>
21+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
22+
<Visible>False</Visible>
23+
</CodeAnalysisDependentAssemblyPaths>
24+
</ItemGroup>
25+
<PropertyGroup>
26+
<DebugType></DebugType>
27+
<Optimize>True</Optimize>
28+
</PropertyGroup>
29+
<ItemGroup>
30+
<Compile Include="$(MSBuildProjectName).cs" />
31+
</ItemGroup>
32+
<ItemGroup>
33+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
34+
</ItemGroup>
35+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
36+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
37+
</PropertyGroup>
38+
</Project>

0 commit comments

Comments
 (0)