Fix for RETURNTRAP xarch codegen. (#16292)
authorEugene Rozenfeld <erozen@microsoft.com>
Fri, 9 Feb 2018 23:45:37 +0000 (15:45 -0800)
committerGitHub <noreply@github.com>
Fri, 9 Feb 2018 23:45:37 +0000 (15:45 -0800)
This fixes a bug that caused an assert in GetSingleTempReg.
In this case we had an an interop call (resulting in RETURNTRAP in its epilog)
when there are live 256 bit values at the callsite.
The bug was that codegen for RETURNTRAP node requested a single temp register
and asserted that there was only one. In this case the set of temp registers
includes floating-point registers that may be needed for saving/restoring the upper
part of 256-bit registers. The fix was for codegen to request a single temp int register.
GetSingleTempReg will assert that there was only one int register in this case.

src/jit/codegenxarch.cpp
tests/src/JIT/Regression/JitBlue/DevDiv_546018/DevDiv_546018.cs [new file with mode: 0644]
tests/src/JIT/Regression/JitBlue/DevDiv_546018/DevDiv_546018.csproj [new file with mode: 0644]

index 456cfb9..f2a7c34 100644 (file)
@@ -1616,7 +1616,7 @@ void CodeGen::genCodeForReturnTrap(GenTreeOp* tree)
     inst_JMP(jmpEqual, skipLabel);
 
     // emit the call to the EE-helper that stops for GC (or other reasons)
-    regNumber tmpReg = tree->GetSingleTempReg();
+    regNumber tmpReg = tree->GetSingleTempReg(RBM_ALLINT);
     assert(genIsValidIntReg(tmpReg));
 
     genEmitHelperCall(CORINFO_HELP_STOP_FOR_GC, 0, EA_UNKNOWN, tmpReg);
diff --git a/tests/src/JIT/Regression/JitBlue/DevDiv_546018/DevDiv_546018.cs b/tests/src/JIT/Regression/JitBlue/DevDiv_546018/DevDiv_546018.cs
new file mode 100644 (file)
index 0000000..95a87e8
--- /dev/null
@@ -0,0 +1,49 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+// This tests an interop call (resulting in RETURNTRAP in its epilog)
+// when there are live 256 bit values at the callsite.
+// The bug was that codegen for RETURNTRAP node requested a single temp register
+// and asserted that there was only one. In this case the set of temp registers
+// includes floating-point registers that may be needed for saving/restoring the upper
+// part of 256-bit registers. The fix was for codegen to request a single temp int register
+// and assert that there was only one.
+
+using System;
+using System.Numerics;
+using System.Runtime.CompilerServices;
+
+class Test
+{
+    static Random random;
+
+    public static int Main ()
+    {
+        random = new Random ();
+        VectorSingle_op_Division_VectorSingle_VectorSingle (5);
+        return 100;
+    }
+
+    [MethodImpl (MethodImplOptions.NoInlining)]
+    public static void VectorSingle_op_Division_VectorSingle_VectorSingle (long iterations)
+    {
+        Vector<float> dividend = CreateRandomVector ();
+        Vector<float> divisor = CreateRandomVector ();
+
+        Vector<float> result = dividend / divisor;
+        GC.Collect ();
+        for (long iteration = 0L; iteration < iterations; iteration++) {
+            result = dividend / divisor;
+        }
+        GC.KeepAlive (new object [1] { result });
+    }
+
+    [MethodImpl (MethodImplOptions.NoInlining)]
+    static Vector<float> CreateRandomVector ()
+    {
+        return new Vector<float> ((float)(random.NextDouble () + 1.0));
+    }
+}
+
diff --git a/tests/src/JIT/Regression/JitBlue/DevDiv_546018/DevDiv_546018.csproj b/tests/src/JIT/Regression/JitBlue/DevDiv_546018/DevDiv_546018.csproj
new file mode 100644 (file)
index 0000000..6d58ab0
--- /dev/null
@@ -0,0 +1,37 @@
+<?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>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <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>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <DebugType></DebugType>
+    <Optimize>True</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="$(MSBuildProjectName).cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>