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

Commit 1d61034

Browse files
CarolEidtKoundinya Veluri
authored andcommitted
Use 16 bytes to spill SIMD12 (#19237)
Port of #19237 to 2.2 On 64-bit systems, SIMD12 locals are naturally rounded to 16 bytes, but the spill temp logic was not doing the same. Fix #19197
1 parent d90c382 commit 1d61034

File tree

4 files changed

+103
-4
lines changed

4 files changed

+103
-4
lines changed

src/jit/compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ class LclVarDsc
708708
// For 32-bit architectures, we make local variable SIMD12 types 16 bytes instead of just 12. We can't do
709709
// this for arguments, which must be passed according the defined ABI. We don't want to do this for
710710
// dependently promoted struct fields, but we don't know that here. See lvaMapSimd12ToSimd16().
711+
// (Note that for 64-bits, we are already rounding up to 16.)
711712
if ((lvType == TYP_SIMD12) && !lvIsParam)
712713
{
713714
assert(lvExactSize == 12);

src/jit/regset.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,10 +3274,11 @@ var_types Compiler::tmpNormalizeType(var_types type)
32743274

32753275
type = genActualType(type);
32763276

3277-
#if defined(FEATURE_SIMD) && !defined(_TARGET_64BIT_)
3278-
// For SIMD on 32-bit platforms, we always spill SIMD12 to a 16-byte SIMD16 temp.
3279-
// This is because we don't have a single instruction to store 12 bytes. We also
3280-
// allocate non-argument locals as 16 bytes; see lvSize().
3277+
#if defined(FEATURE_SIMD)
3278+
// We always spill SIMD12 to a 16-byte SIMD16 temp.
3279+
// This is because we don't have a single instruction to store 12 bytes, so we want
3280+
// to ensure that we always have the full 16 bytes for loading & storing the value.
3281+
// We also allocate non-argument locals as 16 bytes; see lvSize().
32813282
if (type == TYP_SIMD12)
32823283
{
32833284
type = TYP_SIMD16;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
// This test was extracted from the corefx System.Numerics.Vectors tests,
6+
// and was failing with minOpts because a SIMD12 was being spilled using
7+
// a 16-byte load, but only a 12-byte location had been allocated.
8+
9+
using System;
10+
using System.Numerics;
11+
12+
public class GitHub_19171
13+
{
14+
static int returnVal = 100;
15+
16+
static public void Vector3EqualsTest()
17+
{
18+
Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
19+
Vector3 b = new Vector3(1.0f, 2.0f, 3.0f);
20+
21+
// case 1: compare between same values
22+
object obj = b;
23+
24+
bool expected = true;
25+
bool actual = a.Equals(obj);
26+
Equal(expected, actual);
27+
28+
// case 2: compare between different values
29+
b.X = 10.0f;
30+
obj = b;
31+
expected = false;
32+
actual = a.Equals(obj);
33+
Equal(expected, actual);
34+
35+
// case 3: compare between different types.
36+
obj = new Quaternion();
37+
expected = false;
38+
actual = a.Equals(obj);
39+
Equal(expected, actual);
40+
41+
// case 3: compare against null.
42+
obj = null;
43+
expected = false;
44+
actual = a.Equals(obj);
45+
Equal(expected, actual);
46+
}
47+
48+
static void Equal(bool a, bool b)
49+
{
50+
Console.WriteLine(a == b ? "ok" : "bad");
51+
if (a != b)
52+
{
53+
returnVal = -1;
54+
}
55+
}
56+
57+
public static int Main()
58+
{
59+
Vector3EqualsTest();
60+
return returnVal;
61+
}
62+
}
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>{ADEEA3D1-B67B-456E-8F2B-6DCCACC2D34C}</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+
<CLRTestPriority>1</CLRTestPriority>
14+
</PropertyGroup>
15+
<!-- Default configurations to help VS understand the configurations -->
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup>
18+
<ItemGroup>
19+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
20+
<Visible>False</Visible>
21+
</CodeAnalysisDependentAssemblyPaths>
22+
</ItemGroup>
23+
<PropertyGroup>
24+
<DebugType>Full</DebugType>
25+
<Optimize>True</Optimize>
26+
</PropertyGroup>
27+
<ItemGroup>
28+
<Compile Include="$(MSBuildProjectName).cs" />
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)