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

Commit 872b9d9

Browse files
AndyAyersMSPetermarcu
authored andcommitted
JIT: port fix to defer removing statements during opt CSE to release/2.0.0 (#15360)
Port of #15323. Related issue #15319.
1 parent 216aa4a commit 872b9d9

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

src/jit/morph.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15667,7 +15667,13 @@ bool Compiler::fgMorphBlockStmt(BasicBlock* block, GenTreeStmt* stmt DEBUGARG(co
1566715667
}
1566815668

1566915669
// Can the entire tree be removed?
15670-
bool removedStmt = fgCheckRemoveStmt(block, stmt);
15670+
bool removedStmt = false;
15671+
15672+
// Defer removing statements during CSE so we don't inadvertently remove any CSE defs.
15673+
if (!optValnumCSE_phase)
15674+
{
15675+
removedStmt = fgCheckRemoveStmt(block, stmt);
15676+
}
1567115677

1567215678
// Or this is the last statement of a conditional branch that was just folded?
1567315679
if (!removedStmt && (stmt->getNextStmt() == nullptr) && !fgRemoveRestOfBlock)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Linq;
7+
8+
// Bug where interacting CSEs of N - Old.Length and Old.Length
9+
// were not handled properly in optCSE
10+
11+
class P
12+
{
13+
private static int Main(string[] args)
14+
{
15+
var ar = new double[]
16+
{
17+
100
18+
};
19+
20+
FillTo1(ref ar, 5);
21+
Console.WriteLine(string.Join(",", ar.Select(a => a.ToString()).ToArray()));
22+
return (int)ar[4];
23+
}
24+
25+
public static void FillTo1(ref double[] dd, int N)
26+
{
27+
if (dd.Length >= N)
28+
return;
29+
30+
double[] Old = dd;
31+
double d = double.NaN;
32+
if (Old.Length > 0)
33+
d = Old[0];
34+
35+
dd = new double[N];
36+
37+
for (int i = 0; i < Old.Length; i++)
38+
{
39+
dd[N - Old.Length + i] = Old[i];
40+
}
41+
for (int i = 0; i < N - Old.Length; i++)
42+
dd[i] = d;
43+
}
44+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
10+
<OutputType>Exe</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
15+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
16+
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<!-- Default configurations to help VS understand the configurations -->
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup>
21+
<ItemGroup>
22+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
23+
<Visible>False</Visible>
24+
</CodeAnalysisDependentAssemblyPaths>
25+
</ItemGroup>
26+
<PropertyGroup>
27+
<DebugType></DebugType>
28+
<Optimize>True</Optimize>
29+
</PropertyGroup>
30+
<ItemGroup>
31+
<Compile Include="GitHub_15319.cs" />
32+
</ItemGroup>
33+
<ItemGroup>
34+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
35+
</ItemGroup>
36+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
37+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
38+
</Project>

0 commit comments

Comments
 (0)