mirror of
https://github.com/VSadov/Satori.git
synced 2025-06-11 02:13:38 +09:00
Fix constant folding for shift SIMD operators (#105752)
This commit is contained in:
parent
7f2b222f92
commit
87b1d84ba1
5 changed files with 89 additions and 7 deletions
|
@ -30912,10 +30912,7 @@ GenTree* Compiler::gtFoldExprHWIntrinsic(GenTreeHWIntrinsic* tree)
|
|||
{
|
||||
if (otherNode->TypeIs(TYP_SIMD16))
|
||||
{
|
||||
if ((ni != NI_AVX2_ShiftLeftLogicalVariable) && (ni != NI_AVX2_ShiftRightArithmeticVariable) &&
|
||||
(ni != NI_AVX512F_VL_ShiftRightArithmeticVariable) &&
|
||||
(ni != NI_AVX10v1_ShiftRightArithmeticVariable) &&
|
||||
(ni != NI_AVX2_ShiftRightLogicalVariable))
|
||||
if (!HWIntrinsicInfo::IsVariableShift(ni))
|
||||
{
|
||||
// The xarch shift instructions support taking the shift amount as
|
||||
// a simd16, in which case they take the shift amount from the lower
|
||||
|
|
|
@ -882,6 +882,32 @@ struct HWIntrinsicInfo
|
|||
}
|
||||
}
|
||||
|
||||
static bool IsVariableShift(NamedIntrinsic id)
|
||||
{
|
||||
#ifdef TARGET_XARCH
|
||||
switch (id)
|
||||
{
|
||||
case NI_AVX2_ShiftRightArithmeticVariable:
|
||||
case NI_AVX512F_ShiftRightArithmeticVariable:
|
||||
case NI_AVX512F_VL_ShiftRightArithmeticVariable:
|
||||
case NI_AVX512BW_ShiftRightArithmeticVariable:
|
||||
case NI_AVX512BW_VL_ShiftRightArithmeticVariable:
|
||||
case NI_AVX10v1_ShiftRightArithmeticVariable:
|
||||
case NI_AVX2_ShiftRightLogicalVariable:
|
||||
case NI_AVX512F_ShiftRightLogicalVariable:
|
||||
case NI_AVX512BW_ShiftRightLogicalVariable:
|
||||
case NI_AVX512BW_VL_ShiftRightLogicalVariable:
|
||||
case NI_AVX10v1_ShiftRightLogicalVariable:
|
||||
case NI_AVX2_ShiftLeftLogicalVariable:
|
||||
case NI_AVX512BW_VL_ShiftLeftLogicalVariable:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
#endif // TARGET_XARCH
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool HasImmediateOperand(NamedIntrinsic id)
|
||||
{
|
||||
#if defined(TARGET_ARM64)
|
||||
|
|
|
@ -8235,9 +8235,7 @@ ValueNum ValueNumStore::EvalHWIntrinsicFunBinary(GenTreeHWIntrinsic* tree,
|
|||
{
|
||||
if (TypeOfVN(arg1VN) == TYP_SIMD16)
|
||||
{
|
||||
if ((ni != NI_AVX2_ShiftLeftLogicalVariable) && (ni != NI_AVX2_ShiftRightArithmeticVariable) &&
|
||||
(ni != NI_AVX512F_VL_ShiftRightArithmeticVariable) &&
|
||||
(ni != NI_AVX10v1_ShiftRightArithmeticVariable) && (ni != NI_AVX2_ShiftRightLogicalVariable))
|
||||
if (!HWIntrinsicInfo::IsVariableShift(ni))
|
||||
{
|
||||
// The xarch shift instructions support taking the shift amount as
|
||||
// a simd16, in which case they take the shift amount from the lower
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
// Run on Arm64 Linux
|
||||
// Seed: 10489942769529190437-vectort,vector64,vector128,armadvsimd,armadvsimdarm64,armaes,armarmbase,armarmbasearm64,armcrc32,armcrc32arm64,armdp,armrdm,armrdmarm64,armsha1,armsha256
|
||||
// Reduced from 58.9 KiB to 0.4 KiB in 00:00:28
|
||||
// Debug: Outputs [9223372036854775808, 9223372036854775808]
|
||||
// Release: Outputs [0, 0]
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
using Xunit;
|
||||
|
||||
public class Runtime_105742
|
||||
{
|
||||
[Fact]
|
||||
public static void TestEntyPoint()
|
||||
{
|
||||
if (!Avx512BW.VL.IsSupported)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ShiftLeft().ToString() != "<2, 1, 1, 1, 1, 1, 1, 1>")
|
||||
{
|
||||
throw new Exception("ShiftLeft");
|
||||
}
|
||||
if (ShiftRight().ToString() != "<0, 32767, -1, -1, -1, -1, -1, -1>")
|
||||
{
|
||||
throw new Exception("ShiftRight");
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static Vector128<short> ShiftLeft()
|
||||
{
|
||||
var vr4 = Vector128.Create<short>(1);
|
||||
var vr5 = (ushort)1;
|
||||
var vr6 = Vector128.CreateScalar(vr5);
|
||||
var vr7 = Avx512BW.VL.ShiftLeftLogicalVariable(vr4, vr6);
|
||||
return vr7;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static Vector128<short> ShiftRight()
|
||||
{
|
||||
var vr2 = Vector128.Create<short>(-1);
|
||||
var vr3 = Vector128.Create(65534, 1, 0, 0, 0, 0, 0, 0);
|
||||
return Avx512BW.VL.ShiftRightLogicalVariable(vr2, vr3);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Optimize>True</Optimize>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildProjectName).cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue