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

Commit 37168ae

Browse files
authored
Fix issue #11574. (#11579)
This bug was yet another case of a transformation being performed during remorphing that preserved a tree's value number without preserving its associated semantics. This fix disables the problematic transformations in morph.
1 parent 272b650 commit 37168ae

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

src/jit/morph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13665,7 +13665,7 @@ GenTree* Compiler::fgMorphSmpOpOptional(GenTreeOp* tree)
1366513665
GenTree* op2 = tree->gtOp2;
1366613666
var_types typ = tree->TypeGet();
1366713667

13668-
if (GenTree::OperIsCommutative(oper))
13668+
if (fgGlobalMorph && GenTree::OperIsCommutative(oper))
1366913669
{
1367013670
/* Swap the operands so that the more expensive one is 'op1' */
1367113671

@@ -13703,7 +13703,7 @@ GenTree* Compiler::fgMorphSmpOpOptional(GenTreeOp* tree)
1370313703
/* Change "((x+icon)+y)" to "((x+y)+icon)"
1370413704
Don't reorder floating-point operations */
1370513705

13706-
if ((oper == GT_ADD) && !tree->gtOverflow() && (op1->gtOper == GT_ADD) && !op1->gtOverflow() &&
13706+
if (fgGlobalMorph && (oper == GT_ADD) && !tree->gtOverflow() && (op1->gtOper == GT_ADD) && !op1->gtOverflow() &&
1370713707
varTypeIsIntegralOrI(typ))
1370813708
{
1370913709
GenTreePtr ad2 = op1->gtOp.gtOp2;
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.Runtime.CompilerServices;
6+
7+
class Program
8+
{
9+
static byte[] s_arr2;
10+
static byte[] s_arr3;
11+
12+
static void Init()
13+
{
14+
s_arr2 = new byte[] { 0x11, 0x12, 0x13 };
15+
s_arr3 = new byte[] { 0x21, 0x22, 0x33 };
16+
}
17+
18+
[MethodImpl(MethodImplOptions.NoInlining)]
19+
static int Check(int actual, int added, int expected, int rv)
20+
{
21+
return (actual == expected) ? rv : 0;
22+
}
23+
24+
static int Main(string[] args)
25+
{
26+
Init();
27+
28+
byte[] arr1 = new byte[] { 2 };
29+
byte[] arr2 = s_arr2;
30+
byte[] arr3 = s_arr3;
31+
32+
int rv = 100;
33+
int len = arr1.Length + arr2.Length + arr3.Length;
34+
int cur = 0;
35+
rv = Check(cur, 0, 0, rv);
36+
cur += arr1.Length;
37+
rv = Check(cur, arr1.Length, 1, rv);
38+
cur += arr2.Length;
39+
rv = Check(cur, arr2.Length, 4, rv);
40+
cur += arr3.Length;
41+
rv = Check(cur, arr3.Length, 7, rv);
42+
return Check(cur, 0, len, rv);
43+
}
44+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
11+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
12+
</PropertyGroup>
13+
<!-- Default configurations to help VS understand the configurations -->
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
16+
<ItemGroup>
17+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
18+
<Visible>False</Visible>
19+
</CodeAnalysisDependentAssemblyPaths>
20+
</ItemGroup>
21+
<PropertyGroup>
22+
<DebugType>None</DebugType>
23+
<Optimize>True</Optimize>
24+
</PropertyGroup>
25+
<ItemGroup>
26+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
27+
</ItemGroup>
28+
<ItemGroup>
29+
<Compile Include="GitHub_11574.cs" />
30+
</ItemGroup>
31+
<!-- <PropertyGroup>
32+
<ProjectJson>$(JitPackagesConfigFileDirectory)threading+thread\project.json</ProjectJson>
33+
<ProjectLockJson>$(JitPackagesConfigFileDirectory)threading+thread\project.lock.json</ProjectLockJson>
34+
</PropertyGroup>-->
35+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
36+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
37+
</Project>

0 commit comments

Comments
 (0)