Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
JIT: port fix to defer removing statements during opt CSE to release/…
Browse files Browse the repository at this point in the history
…2.0.0 (#15360)

Port of #15323.
Related issue #15319.
  • Loading branch information
AndyAyersMS authored and Petermarcu committed Jan 3, 2018
1 parent 216aa4a commit 872b9d9
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/jit/morph.cpp
Expand Up @@ -15667,7 +15667,13 @@ bool Compiler::fgMorphBlockStmt(BasicBlock* block, GenTreeStmt* stmt DEBUGARG(co
}

// Can the entire tree be removed?
bool removedStmt = fgCheckRemoveStmt(block, stmt);
bool removedStmt = false;

// Defer removing statements during CSE so we don't inadvertently remove any CSE defs.
if (!optValnumCSE_phase)
{
removedStmt = fgCheckRemoveStmt(block, stmt);
}

// Or this is the last statement of a conditional branch that was just folded?
if (!removedStmt && (stmt->getNextStmt() == nullptr) && !fgRemoveRestOfBlock)
Expand Down
44 changes: 44 additions & 0 deletions tests/src/JIT/Regression/JitBlue/GitHub_15319/GitHub_15319.cs
@@ -0,0 +1,44 @@
// 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.Linq;

// Bug where interacting CSEs of N - Old.Length and Old.Length
// were not handled properly in optCSE

class P
{
private static int Main(string[] args)
{
var ar = new double[]
{
100
};

FillTo1(ref ar, 5);
Console.WriteLine(string.Join(",", ar.Select(a => a.ToString()).ToArray()));
return (int)ar[4];
}

public static void FillTo1(ref double[] dd, int N)
{
if (dd.Length >= N)
return;

double[] Old = dd;
double d = double.NaN;
if (Old.Length > 0)
d = Old[0];

dd = new double[N];

for (int i = 0; i < Old.Length; i++)
{
dd[N - Old.Length + i] = Old[i];
}
for (int i = 0; i < N - Old.Length; i++)
dd[i] = d;
}
}
38 changes: 38 additions & 0 deletions tests/src/JIT/Regression/JitBlue/GitHub_15319/GitHub_15319.csproj
@@ -0,0 +1,38 @@
<?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>
<AppDesignerFolder>Properties</AppDesignerFolder>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
</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="GitHub_15319.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>

0 comments on commit 872b9d9

Please sign in to comment.