Skip to content

Commit edbdce5

Browse files
authored
JIT: Fall back to a canonical SIMD handle in gtGetStructHandleForSimdOrHW (#80240)
1 parent b2babe4 commit edbdce5

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

src/coreclr/jit/compiler.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8397,6 +8397,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
83978397
// Get the handle for a SIMD type.
83988398
CORINFO_CLASS_HANDLE gtGetStructHandleForSIMD(var_types simdType, CorInfoType simdBaseJitType)
83998399
{
8400+
assert(varTypeIsSIMD(simdType));
8401+
84008402
if (m_simdHandleCache == nullptr)
84018403
{
84028404
// This may happen if the JIT generates SIMD node on its own, without importing them.
@@ -8463,6 +8465,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
84638465
CorInfoType simdBaseJitType,
84648466
bool isSimdAsHWIntrinsic = false)
84658467
{
8468+
assert(varTypeIsSIMD(simdType));
8469+
84668470
CORINFO_CLASS_HANDLE clsHnd = NO_CLASS_HANDLE;
84678471

84688472
if (isSimdAsHWIntrinsic)
@@ -8474,6 +8478,14 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
84748478
clsHnd = gtGetStructHandleForHWSIMD(simdType, simdBaseJitType);
84758479
}
84768480

8481+
// Currently there are cases where isSimdAsHWIntrinsic is passed
8482+
// incorrectly. Fall back to the canonical SIMD handle in that case.
8483+
// TODO-cleanup: We can probably just always use the canonical handle.
8484+
if (clsHnd == NO_CLASS_HANDLE)
8485+
{
8486+
clsHnd = gtGetCanonicalStructHandleForSIMD(simdType);
8487+
}
8488+
84778489
return clsHnd;
84788490
}
84798491
#endif // FEATURE_HW_INTRINSICS

src/coreclr/jit/gentree.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17598,8 +17598,12 @@ CORINFO_CLASS_HANDLE Compiler::gtGetStructHandleIfPresent(GenTree* tree)
1759817598
#endif // FEATURE_SIMD
1759917599
#ifdef FEATURE_HW_INTRINSICS
1760017600
case GT_HWINTRINSIC:
17601-
structHnd = gtGetStructHandleForSimdOrHW(tree->TypeGet(), tree->AsHWIntrinsic()->GetSimdBaseJitType(),
17602-
tree->AsHWIntrinsic()->IsSimdAsHWIntrinsic());
17601+
if (varTypeIsSIMD(tree))
17602+
{
17603+
structHnd =
17604+
gtGetStructHandleForSimdOrHW(tree->TypeGet(), tree->AsHWIntrinsic()->GetSimdBaseJitType(),
17605+
tree->AsHWIntrinsic()->IsSimdAsHWIntrinsic());
17606+
}
1760317607
break;
1760417608
#endif
1760517609
default:

src/coreclr/jit/hwintrinsic.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ CorInfoType Compiler::getBaseJitTypeFromArgIfNeeded(NamedIntrinsic intrins
8888

8989
CORINFO_CLASS_HANDLE Compiler::gtGetStructHandleForHWSIMD(var_types simdType, CorInfoType simdBaseJitType)
9090
{
91+
assert(varTypeIsSIMD(simdType));
92+
9193
if (m_simdHandleCache == nullptr)
9294
{
9395
return NO_CLASS_HANDLE;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
using System.Numerics;
5+
using System.Runtime.CompilerServices;
6+
7+
class Runtime_80239
8+
{
9+
static int Main(string[] args)
10+
{
11+
Unsafe.SkipInit(out Vector3 test);
12+
test.X = 500.0f;
13+
Consume(test);
14+
return 100;
15+
}
16+
17+
[MethodImpl(MethodImplOptions.NoInlining)]
18+
private static void Consume(Vector3 test)
19+
{
20+
}
21+
}
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)