Skip to content

Commit

Permalink
Make gtHasRef pay attention to LCL_FLD nodes (#62568)
Browse files Browse the repository at this point in the history
* Add a test

* Make "gtHasRef" pay attention to LCL_FLD nodes

Fixes the interference checks in the forward substitution of relops optimization.
  • Loading branch information
SingleAccretion committed Dec 9, 2021
1 parent cc5a650 commit 666e9c7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,11 +1642,11 @@ bool GenTree::Compare(GenTree* op1, GenTree* op2, bool swapOK)
// lclNum - the local's number, *or* the handle for the field
//
// Return Value:
// Whether "tree" has any LCL_VAR nodes that refer to the local,
// LHS or RHS, or FIELD nodes with the specified handle.
// Whether "tree" has any LCL_VAR/LCL_FLD nodes that refer to the
// local, LHS or RHS, or FIELD nodes with the specified handle.
//
// Notes:
// Does not pay attention to local address nodes or LCL_FLD nodes.
// Does not pay attention to local address nodes.
//
/* static */ bool Compiler::gtHasRef(GenTree* tree, ssize_t lclNum)
{
Expand All @@ -1657,7 +1657,7 @@ bool GenTree::Compare(GenTree* op1, GenTree* op2, bool swapOK)

if (tree->OperIsLeaf())
{
if (tree->OperIs(GT_LCL_VAR) && (tree->AsLclVarCommon()->GetLclNum() == (unsigned)lclNum))
if (tree->OperIs(GT_LCL_VAR, GT_LCL_FLD) && (tree->AsLclVarCommon()->GetLclNum() == (unsigned)lclNum))
{
return true;
}
Expand Down
31 changes: 31 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_62524/Runtime_62524.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;

public class Runtime_62524
{
public static int Main()
{
return Problem(new() { Value = 1 }) == 1 ? 100 : 101;
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static int Problem(StructWithIndex a)
{
bool k = a.Value == 1;
a = default;
if (k)
{
return 1;
}

return a.Index;
}
}

public struct StructWithIndex
{
public int Index;
public int Value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set DOTNET_JitNoStructPromotion=1
set DOTNET_JitNoCSE=1
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export DOTNET_JitNoStructPromotion=1
export DOTNET_JitNoCSE=1
]]></BashCLRTestPreCommands>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit 666e9c7

Please sign in to comment.