summaryrefslogtreecommitdiff
path: root/packaging/0020-JIT-port-fix-to-defer-removing-statements-during-opt.patch
blob: db0d267dc29820e6f5cc10e83ba20f7b29ae3ea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
From 240ffdf43611fda5d22672f56be5760803d1a011 Mon Sep 17 00:00:00 2001
From: Andy Ayers <andya@microsoft.com>
Date: Mon, 4 Dec 2017 11:22:26 -0800
Subject: [PATCH 20/47] JIT: port fix to defer removing statements during opt
 CSE to release/2.0.0

Port of #15323.
Related issue #15319.
---
 src/jit/morph.cpp                                  |  8 +++-
 .../JitBlue/GitHub_15319/GitHub_15319.cs           | 44 ++++++++++++++++++++++
 .../JitBlue/GitHub_15319/GitHub_15319.csproj       | 38 +++++++++++++++++++
 3 files changed, 89 insertions(+), 1 deletion(-)
 create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_15319/GitHub_15319.cs
 create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_15319/GitHub_15319.csproj

diff --git a/src/jit/morph.cpp b/src/jit/morph.cpp
index 79b3fef..993ce53 100644
--- a/src/jit/morph.cpp
+++ b/src/jit/morph.cpp
@@ -15695,7 +15695,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)
diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_15319/GitHub_15319.cs b/tests/src/JIT/Regression/JitBlue/GitHub_15319/GitHub_15319.cs
new file mode 100644
index 0000000..af7419f
--- /dev/null
+++ b/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;
+    }
+}
diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_15319/GitHub_15319.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_15319/GitHub_15319.csproj
new file mode 100644
index 0000000..c3a87c1
--- /dev/null
+++ b/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>
-- 
2.7.4