Fixed checks for Avx/Avx2.InsertVector128 to check the type of the second arg
authorBrian Sullivan <briansul@microsoft.com>
Wed, 11 Apr 2018 23:15:57 +0000 (16:15 -0700)
committerBrian Sullivan <briansul@microsoft.com>
Wed, 11 Apr 2018 23:15:57 +0000 (16:15 -0700)
Added test case JIT\HardwareIntrinsics\X86\Regression\GitHub_17435

src/jit/gentree.cpp
tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_17435/GitHub_17435.cs [new file with mode: 0644]
tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_17435/GitHub_17435.csproj [new file with mode: 0644]

index 3846b2ea7e3b9d39b62912bc50405af6ac3129fc..d3234036e33cfe332962732d43cdce9de978376c 100644 (file)
@@ -18252,7 +18252,7 @@ bool GenTreeHWIntrinsic::OperIsMemoryLoad()
             GenTreeArgList* argList = gtOp.gtOp1->AsArgList();
 
             if ((gtHWIntrinsicId == NI_AVX_InsertVector128 || gtHWIntrinsicId == NI_AVX2_InsertVector128) &&
-                (argList->Current()->TypeGet() == TYP_I_IMPL)) // Is the type of the first arg TYP_I_IMPL?
+                (argList->Rest()->Current()->TypeGet() == TYP_I_IMPL)) // Is the type of the second arg TYP_I_IMPL?
             {
                 // This is Avx/Avx2.InsertVector128
                 return true;
@@ -18319,7 +18319,7 @@ bool GenTreeHWIntrinsic::OperIsMemoryLoadOrStore()
             GenTreeArgList* argList = gtOp.gtOp1->AsArgList();
 
             if ((gtHWIntrinsicId == NI_AVX_InsertVector128 || gtHWIntrinsicId == NI_AVX2_InsertVector128) &&
-                (argList->Current()->TypeGet() == TYP_I_IMPL)) // Is the type of the first arg TYP_I_IMPL?
+                (argList->Rest()->Current()->TypeGet() == TYP_I_IMPL)) // Is the type of the second arg TYP_I_IMPL?
             {
                 // This is Avx/Avx2.InsertVector128
                 return true;
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_17435/GitHub_17435.cs b/tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_17435/GitHub_17435.cs
new file mode 100644 (file)
index 0000000..bed639c
--- /dev/null
@@ -0,0 +1,62 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.Intrinsics.X86;
+using System.Runtime.Intrinsics;
+
+namespace GitHub_17435
+{
+    class Program
+    {
+        const int Pass = 100;
+        const int Fail = 0;
+
+        static unsafe int Main(string[] args)
+        {
+
+            if (Sse2.IsSupported)
+            {
+                (uint a, uint b) = Program.Repro();
+                if ((a !=3) || (b != 6))
+                {
+                    Console.WriteLine($"FAILED {a}, {b}");
+                    return Fail;
+                }
+                else
+                {
+                    Console.WriteLine("Passed");
+                    return Pass;
+                }
+            }
+            else
+            {
+                Console.WriteLine("SSE2 not supported");
+                return Pass;
+            }
+        }
+
+        [MethodImpl(MethodImplOptions.NoInlining)]
+        public unsafe static (uint, uint) Repro()
+        {
+            uint* a = stackalloc uint[4];
+            a[0] = 1;
+            a[1] = 1;
+            a[2] = 1;
+            a[3] = 1;
+            
+            // Here we force populate the registers
+            var b = a[0];
+            var h = a[3];
+            var c = a[1];
+            
+            // We operate the values in xmm0
+            Vector128<uint> v = Sse2.LoadVector128(a);
+            v = Sse2.Add(v, v);
+            // We send to the memory the modified values
+            Sse2.Store(a, v);
+            
+            // We return both sums (from registers and from memory)
+            return (b + h + c, a[0]+a[1]+a[3]);
+        }
+    }
+}
diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_17435/GitHub_17435.csproj b/tests/src/JIT/HardwareIntrinsics/X86/Regression/GitHub_17435/GitHub_17435.csproj
new file mode 100644 (file)
index 0000000..70fdafb
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <DebugType>None</DebugType>
+    <Optimize>True</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="GitHub_17435.cs" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
+</Project>