diff options
author | Eugene Rozenfeld <erozen@microsoft.com> | 2019-04-26 15:22:53 -0700 |
---|---|---|
committer | Eugene Rozenfeld <erozen@microsoft.com> | 2019-04-26 15:22:53 -0700 |
commit | e6ee8a2c075ac906f4d86d831cac124f2f22a504 (patch) | |
tree | 899ee79bd48ba4baa9289a5168d31bd8dd699e58 | |
parent | e9691546d308fde4e56cc821f8c9bfda7e9a8b91 (diff) | |
download | coreclr-e6ee8a2c075ac906f4d86d831cac124f2f22a504.tar.gz coreclr-e6ee8a2c075ac906f4d86d831cac124f2f22a504.tar.bz2 coreclr-e6ee8a2c075ac906f4d86d831cac124f2f22a504.zip |
Fix for a jit liveness bug.
`fgRemoveDeadStore` has special logic for removing dead assignments
whose rhs was of type `TYP_STRUCT`:
https://github.com/dotnet/coreclr/blob/311b5e2fe413c6c74a2a3680ab54d8a978651472/src/jit/liveness.cpp#L2264-L2274
That logic was applied to "normal"
assignments (i.e., direct children of `GT_STMT`) but not to "internal"
assignments (e.g., children of `GT_COMMA`).
The test case has an internal assignment and, because this logic wasn't
applied, we ended up with a standalone `GT_IND` of type `TYP_STRUCT`
that the register allocator can't handle.
This change apples the missing logic to "internal" assignments.
Fixes #24253.
-rw-r--r-- | src/jit/liveness.cpp | 13 | ||||
-rw-r--r-- | tests/src/JIT/Regression/JitBlue/GitHub_24253/GitHub_24253.cs | 57 | ||||
-rw-r--r-- | tests/src/JIT/Regression/JitBlue/GitHub_24253/GitHub_24253.csproj | 33 |
3 files changed, 103 insertions, 0 deletions
diff --git a/src/jit/liveness.cpp b/src/jit/liveness.cpp index e06df340a3..9e6eeda75e 100644 --- a/src/jit/liveness.cpp +++ b/src/jit/liveness.cpp @@ -2359,6 +2359,19 @@ bool Compiler::fgRemoveDeadStore(GenTree** pTree, printf("\n"); } #endif // DEBUG + + if (rhsNode->TypeGet() == TYP_STRUCT) + { + // This is a block assignment. An indirection of the rhs is not considered to + // happen until the assignment, so we will extract the side effects from only + // the address. + if (rhsNode->OperIsIndir()) + { + assert(rhsNode->OperGet() != GT_NULLCHECK); + rhsNode = rhsNode->AsIndir()->Addr(); + } + } + gtExtractSideEffList(rhsNode, &sideEffList); if (!sideEffList) diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_24253/GitHub_24253.cs b/tests/src/JIT/Regression/JitBlue/GitHub_24253/GitHub_24253.cs new file mode 100644 index 0000000000..65110fe401 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_24253/GitHub_24253.cs @@ -0,0 +1,57 @@ +// 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. + +using System; +using System.Runtime.CompilerServices; + +// Test removal of a dead struct assignment when the assignment is "internal" +// i.e., is not a direct child of a statement node. +// In this example, the statement is STMT(COMMA(CALL HELPER.CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE, ASG)). + +namespace GitHub_24253 +{ + struct TestStruct + { + public static readonly TestStruct ZeroStruct = new TestStruct(0); + + [MethodImpl(MethodImplOptions.NoInlining)] + public TestStruct(int i) + { + this.i = i; + this.j = 5; + this.k = 5; + this.l = 5; + } + + int i; + int j; + short k; + short l; + } + + class Program + { + static int Main(string[] args) + { + GetStruct(1); + return 100; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static TestStruct GetStruct(int i) + { + // This is the dead assignment that is causing the bug assert. + TestStruct result = TestStruct.ZeroStruct; + try + { + result = new TestStruct(i); + } + catch + { + throw new ArgumentException(); + } + return result; + } + } +} diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_24253/GitHub_24253.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_24253/GitHub_24253.csproj new file mode 100644 index 0000000000..95052d9884 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_24253/GitHub_24253.csproj @@ -0,0 +1,33 @@ +<?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> + </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="$(MSBuildProjectName).cs" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> +</Project> |