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: Fall back to a canonical SIMD handle in gtGetStructHandleForSimdOrHW #80240

Merged
merged 5 commits into from Jan 9, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/coreclr/jit/compiler.h
Expand Up @@ -8372,6 +8372,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// Get the handle for a SIMD type.
CORINFO_CLASS_HANDLE gtGetStructHandleForSIMD(var_types simdType, CorInfoType simdBaseJitType)
{
assert(varTypeIsSIMD(simdType));

if (m_simdHandleCache == nullptr)
{
// This may happen if the JIT generates SIMD node on its own, without importing them.
Expand Down Expand Up @@ -8438,6 +8440,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
CorInfoType simdBaseJitType,
bool isSimdAsHWIntrinsic = false)
{
assert(varTypeIsSIMD(simdType));
tannergooding marked this conversation as resolved.
Show resolved Hide resolved

CORINFO_CLASS_HANDLE clsHnd = NO_CLASS_HANDLE;

if (isSimdAsHWIntrinsic)
Expand All @@ -8449,6 +8453,14 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
clsHnd = gtGetStructHandleForHWSIMD(simdType, simdBaseJitType);
}

// Currently there are cases where isSimdAsHWIntrinsic is passed
// incorrectly. Fall back to the canonical SIMD handle in that case.
// TODO-cleanup: We can probably just always use the canonical handle.
if (clsHnd == NO_CLASS_HANDLE)
{
clsHnd = gtGetCanonicalStructHandleForSIMD(simdType);
tannergooding marked this conversation as resolved.
Show resolved Hide resolved
}

return clsHnd;
}
#endif // FEATURE_HW_INTRINSICS
Expand Down
8 changes: 6 additions & 2 deletions src/coreclr/jit/gentree.cpp
Expand Up @@ -17622,8 +17622,12 @@ CORINFO_CLASS_HANDLE Compiler::gtGetStructHandleIfPresent(GenTree* tree)
#endif // FEATURE_SIMD
#ifdef FEATURE_HW_INTRINSICS
case GT_HWINTRINSIC:
structHnd = gtGetStructHandleForSimdOrHW(tree->TypeGet(), tree->AsHWIntrinsic()->GetSimdBaseJitType(),
tree->AsHWIntrinsic()->IsSimdAsHWIntrinsic());
if (varTypeIsSIMD(tree))
{
structHnd =
gtGetStructHandleForSimdOrHW(tree->TypeGet(), tree->AsHWIntrinsic()->GetSimdBaseJitType(),
tree->AsHWIntrinsic()->IsSimdAsHWIntrinsic());
}
break;
#endif
default:
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/hwintrinsic.cpp
Expand Up @@ -88,6 +88,8 @@ CorInfoType Compiler::getBaseJitTypeFromArgIfNeeded(NamedIntrinsic intrins

CORINFO_CLASS_HANDLE Compiler::gtGetStructHandleForHWSIMD(var_types simdType, CorInfoType simdBaseJitType)
{
assert(varTypeIsSIMD(simdType));

if (m_simdHandleCache == nullptr)
{
return NO_CLASS_HANDLE;
Expand Down
21 changes: 21 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_80239/Runtime_80239.cs
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Numerics;
using System.Runtime.CompilerServices;

class Runtime_80239
{
static int Main(string[] args)
{
Unsafe.SkipInit(out Vector3 test);
test.X = 500.0f;
Consume(test);
return 100;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Consume(Vector3 test)
{
}
}
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>