Skip to content

[release/8.0] JIT: Fixed containment of STOREIND of HW intrinsics ConvertTo*/Extract* #92513

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

Merged
merged 10 commits into from
Sep 27, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6504,7 +6504,7 @@ void Lowering::ContainCheckStoreIndir(GenTreeStoreInd* node)
case NI_AVX2_ConvertToUInt32:
{
// These intrinsics are "ins reg/mem, xmm"
isContainable = varTypeIsIntegral(simdBaseType);
isContainable = varTypeIsIntegral(simdBaseType) && (genTypeSize(src) == genTypeSize(node));
break;
}

Expand Down Expand Up @@ -6568,7 +6568,8 @@ void Lowering::ContainCheckStoreIndir(GenTreeStoreInd* node)
size_t numArgs = hwintrinsic->GetOperandCount();
GenTree* lastOp = hwintrinsic->Op(numArgs);

isContainable = HWIntrinsicInfo::isImmOp(intrinsicId, lastOp) && lastOp->IsCnsIntOrI();
isContainable = HWIntrinsicInfo::isImmOp(intrinsicId, lastOp) && lastOp->IsCnsIntOrI() &&
(genTypeSize(simdBaseType) == genTypeSize(node));

if (isContainable && (intrinsicId == NI_SSE2_Extract))
{
Expand Down
29 changes: 29 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_92349/Runtime_92349.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.Intrinsics.X86;
using System.Runtime.Intrinsics;
using System.Runtime.CompilerServices;
using System.Threading;
using Xunit;

public static class Runtime_92349
{
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
unsafe static void Test(byte* pValue)
{
*pValue = (byte)Sse2.ConvertToInt32(Vector128.Create(-10, 0, 0, 0));
}

[Fact]
public unsafe static void EntryPoint()
{
if (Sse2.IsSupported)
{
ulong value = 0;
Test((byte*)Unsafe.AsPointer(ref value));
Assert.True(value == 246);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
63 changes: 63 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_92590/Runtime_92590.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using Xunit;

public class Runtime_92590
{
[Fact]
public static void TestEntryPoint()
{
Span<byte> bytes = stackalloc byte[4];
bytes.Fill(0xff);
TestByteByte(ref bytes[0], 0, Vector256.Create((byte)1));

Assert.True(bytes.SequenceEqual(stackalloc byte[] { 0x2, 0xff, 0xff, 0xff }));

bytes.Fill(0xff);
TestByteInt(ref bytes[0], 0, Vector256.Create(1));

Assert.True(bytes.SequenceEqual(stackalloc byte[] { 0x2, 0xff, 0xff, 0xff }));

int i = int.MaxValue;
TestIntByte(ref i, 0, Vector256.Create((byte)1));

Assert.Equal(2, i);

i = int.MaxValue;
TestIntInt(ref i, 0, Vector256.Create(1));

Assert.Equal(2, i);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void TestByteByte(ref byte b, int x, Vector256<byte> vin)
{
Vector256<byte> v = vin + vin;
Unsafe.Add(ref b, x) = v[3];
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void TestByteInt(ref byte b, int x, Vector256<int> vin)
{
Vector256<int> v = vin + vin;
Unsafe.Add(ref b, x) = (byte)v[3];
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void TestIntByte(ref int b, int x, Vector256<byte> vin)
{
Vector256<byte> v = vin + vin;
Unsafe.Add(ref b, x) = v[3];
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void TestIntInt(ref int b, int x, Vector256<int> vin)
{
Vector256<int> v = vin + vin;
Unsafe.Add(ref b, x) = v[3];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>