Skip to content

Commit c7c961a

Browse files
Ensure that NI_SSE2_Extract and NI_SSE41_Extract are simdSize=16 (#115580)
1 parent 3aa00d7 commit c7c961a

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

src/coreclr/jit/lowerxarch.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7875,7 +7875,8 @@ void Lowering::ContainCheckStoreIndir(GenTreeStoreInd* node)
78757875
// However, we want to prefer containing the store over allowing the
78767876
// input to be regOptional, so track and clear containment if required.
78777877

7878-
clearContainedNode = hwintrinsic->Op(1);
7878+
GenTree* op1 = hwintrinsic->Op(1);
7879+
clearContainedNode = op1;
78797880
isContainable = !clearContainedNode->isContained();
78807881

78817882
if (isContainable && varTypeIsIntegral(simdBaseType))
@@ -7887,13 +7888,29 @@ void Lowering::ContainCheckStoreIndir(GenTreeStoreInd* node)
78877888
if (isContainable && varTypeIsSmall(simdBaseType))
78887889
{
78897890
CorInfoType baseJitType = varTypeIsByte(node) ? CORINFO_TYPE_UBYTE : CORINFO_TYPE_USHORT;
7890-
intrinsicId = varTypeIsByte(node) ? NI_SSE41_Extract : NI_SSE2_Extract;
7891+
7892+
if (intrinsicId == NI_Vector512_ToScalar)
7893+
{
7894+
op1 = comp->gtNewSimdHWIntrinsicNode(TYP_SIMD16, op1, NI_Vector512_GetLower128,
7895+
baseJitType, 64);
7896+
BlockRange().InsertBefore(hwintrinsic, op1);
7897+
LowerNode(op1);
7898+
}
7899+
else if (intrinsicId == NI_Vector256_ToScalar)
7900+
{
7901+
op1 = comp->gtNewSimdGetLowerNode(TYP_SIMD16, op1, baseJitType, 32);
7902+
BlockRange().InsertBefore(hwintrinsic, op1);
7903+
LowerNode(op1);
7904+
}
7905+
7906+
intrinsicId = varTypeIsByte(node) ? NI_SSE41_Extract : NI_SSE2_Extract;
78917907

78927908
GenTree* zero = comp->gtNewZeroConNode(TYP_INT);
78937909
BlockRange().InsertBefore(hwintrinsic, zero);
78947910

78957911
hwintrinsic->SetSimdBaseJitType(baseJitType);
7896-
hwintrinsic->ResetHWIntrinsicId(intrinsicId, hwintrinsic->Op(1), zero);
7912+
hwintrinsic->SetSimdSize(16);
7913+
hwintrinsic->ResetHWIntrinsicId(intrinsicId, op1, zero);
78977914
zero->SetContained();
78987915
}
78997916
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
using Xunit;
7+
8+
public class Runtime_115493
9+
{
10+
[Fact]
11+
public static void Problem()
12+
{
13+
int checksum = 44444;
14+
int exitCode = 100;
15+
16+
[MethodImpl(MethodImplOptions.NoInlining)]
17+
int ProcessValue(object val)
18+
{
19+
return val switch
20+
{
21+
int i => i,
22+
short s => s,
23+
_ => 0
24+
};
25+
}
26+
27+
var a = new Vector<short>(25);
28+
a = Vector.SquareRoot(a);
29+
checksum = unchecked(checksum + ProcessValue(a[0]));
30+
if (a[0] != 5)
31+
{
32+
exitCode = 0;
33+
}
34+
35+
Assert.Equal(44449, checksum);
36+
Assert.Equal(100, exitCode);
37+
}
38+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Include="$(MSBuildProjectName).cs" />
7+
</ItemGroup>
8+
</Project>

0 commit comments

Comments
 (0)