Skip to content

Commit

Permalink
Fix ADDR(IND(tree))=>tree transformation in morph.
Browse files Browse the repository at this point in the history
ADDR(IND(tree)) => tree transformation was losing zero field
sequence annotation that was causing incorrect value numbering
and asserts in the CSE optimization.

Fixes dotnet/coreclr#27107.


Commit migrated from dotnet/coreclr@f929feb
  • Loading branch information
erozenfeld committed Oct 9, 2019
1 parent e6c64c6 commit cf678ad
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/coreclr/src/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13188,6 +13188,14 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)
// Perform the transform ADDR(IND(...)) == (...).
GenTree* addr = op1->gtOp.gtOp1;

// If tree has a zero field sequence annotation, update the annotation
// on addr node.
FieldSeqNode* zeroFieldSeq = nullptr;
if (GetZeroOffsetFieldMap()->Lookup(tree, &zeroFieldSeq))
{
fgAddFieldSeqForZeroOffset(addr, zeroFieldSeq);
}

noway_assert(varTypeIsGC(addr->gtType) || addr->gtType == TYP_I_IMPL);

DEBUG_DESTROY_NODE(op1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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;

struct S
{
public Program p;
public int i;
}

struct T
{
public S s;
}

class Program
{
public T t;
public T t1;

[MethodImpl(MethodImplOptions.NoInlining)]
int Test()
{
// The bug was that a field sequence annotation was lost
// when morph was transforming ADDR(IND(tree)) into tree
// when processing this.t.s.p.
if (this.t.s.p == this.t1.s.p)
{
return 0;
}
this.t1.s = this.t.s;
int result = Helper(this.t.s);
return result;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static int Helper(S s)
{
return s.i;
}

static int Main()
{
Program p = new Program();
p.t.s.i = 100;
p.t.s.p = p;

return p.Test();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit cf678ad

Please sign in to comment.