Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unique VNs for ADDRs #64230

Merged
merged 2 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8755,38 +8755,42 @@ void Compiler::fgValueNumberTree(GenTree* tree)
// Usually the ADDR and IND just cancel out...
// except when this GT_ADDR has a valid zero-offset field sequence
//

ValueNumPair addrVNP = ValueNumPair();
FieldSeqNode* zeroOffsetFieldSeq = nullptr;
if (GetZeroOffsetFieldMap()->Lookup(tree, &zeroOffsetFieldSeq) &&
(zeroOffsetFieldSeq != FieldSeqStore::NotAField()))
{
ValueNum addrExtended = vnStore->ExtendPtrVN(arg->AsOp()->gtOp1, zeroOffsetFieldSeq);
ValueNum addrExtended = vnStore->ExtendPtrVN(arg->AsIndir()->Addr(), zeroOffsetFieldSeq);
if (addrExtended != ValueNumStore::NoVN)
{
tree->gtVNPair.SetBoth(addrExtended); // We don't care about lib/cons differences for addresses.
// We don't care about lib/cons differences for addresses.
addrVNP.SetBoth(addrExtended);
}
else
{
// ExtendPtrVN returned a failure result
// So give this address a new unique value
tree->gtVNPair.SetBoth(vnStore->VNForExpr(compCurBB, TYP_BYREF));
// ExtendPtrVN returned a failure result - give this address a new unique value.
addrVNP.SetBoth(vnStore->VNForExpr(compCurBB, TYP_BYREF));
}
}
else
{
// They just cancel, so fetch the ValueNumber from the op1 of the GT_IND node.
//
GenTree* addr = arg->AsIndir()->Addr();
tree->gtVNPair = addr->gtVNPair;
GenTree* addr = arg->AsIndir()->Addr();
addrVNP = addr->gtVNPair;

// For the CSE phase mark the address as GTF_DONT_CSE
// because it will end up with the same value number as tree (the GT_ADDR).
addr->gtFlags |= GTF_DONT_CSE;
}

tree->gtVNPair = vnStore->VNPWithExc(addrVNP, vnStore->VNPExceptionSet(arg->gtVNPair));
}
else
{
// May be more cases to do here! But we'll punt for now.
tree->gtVNPair.SetBoth(vnStore->VNForExpr(compCurBB, TYP_BYREF));
tree->gtVNPair = vnStore->VNPUniqueWithExc(TYP_BYREF, vnStore->VNPExceptionSet(arg->gtVNPair));
}
}
else if ((oper == GT_IND) || GenTree::OperIsBlk(oper))
Expand Down
33 changes: 33 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_64208/Runtime_64208.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

public class Runtime_64208
{
public static int Main(string[] args)
{
if (Method0() != null)
{
return 101;
}

return 100;
}

public struct S1
{
public string string_0;
}

static S1 s_s1_32 = new S1();

public static S1 LeafMethod15() => s_s1_32;

public static string Method0()
{
return LeafMethod15().string_0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set DOTNET_JitAggressiveInlining=1
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export DOTNET_JitAggressiveInlining=1
]]></BashCLRTestPreCommands>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>