Skip to content

Commit

Permalink
RefTypeZeroInit doesn't need treeNode (#56333)
Browse files Browse the repository at this point in the history
* RefTypeZeroInit doesn't need treeNode

* Add a test case
  • Loading branch information
kunalspathak authored Jul 28, 2021
1 parent c62ece8 commit 6d35185
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 25 deletions.
29 changes: 4 additions & 25 deletions src/coreclr/jit/lsrabuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1858,25 +1858,6 @@ void LinearScan::buildPhysRegRecords()
}
}

//------------------------------------------------------------------------
// getNonEmptyBlock: Return the first non-empty block starting with 'block'
//
// Arguments:
// block - the BasicBlock from which we start looking
//
// Return Value:
// The first non-empty BasicBlock we find.
//
BasicBlock* getNonEmptyBlock(BasicBlock* block)
{
while (block != nullptr && block->GetFirstLIRNode() == nullptr)
{
block = block->GetUniqueSucc();
}
assert(block != nullptr && block->GetFirstLIRNode() != nullptr);
return block;
}

//------------------------------------------------------------------------
// insertZeroInitRefPositions: Handle lclVars that are live-in to the first block
//
Expand Down Expand Up @@ -1927,9 +1908,8 @@ void LinearScan::insertZeroInitRefPositions()
}

JITDUMP(" creating ZeroInit\n");
GenTree* firstNode = getNonEmptyBlock(compiler->fgFirstBB)->firstNode();
RefPosition* pos =
newRefPosition(interval, MinLocation, RefTypeZeroInit, firstNode, allRegs(interval->registerType));
RefPosition* pos = newRefPosition(interval, MinLocation, RefTypeZeroInit, nullptr /* theTreeNode */,
allRegs(interval->registerType));
pos->setRegOptional(true);
}
else
Expand Down Expand Up @@ -1957,9 +1937,8 @@ void LinearScan::insertZeroInitRefPositions()
if (interval->recentRefPosition == nullptr)
{
JITDUMP(" creating ZeroInit\n");
GenTree* firstNode = getNonEmptyBlock(compiler->fgFirstBB)->firstNode();
RefPosition* pos = newRefPosition(interval, MinLocation, RefTypeZeroInit, firstNode,
allRegs(interval->registerType));
RefPosition* pos = newRefPosition(interval, MinLocation, RefTypeZeroInit,
nullptr /* theTreeNode */, allRegs(interval->registerType));
pos->setRegOptional(true);
varDsc->lvMustInit = true;
}
Expand Down
55 changes: 55 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_54100/Runtime_54100.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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_54100
{
// The test ends up containing an empty try block and we do not find a
// non-empty block from which a treeNode can be extracted to use it for
// creating zero-init refPositions.

static ushort[][] s_23 = new ushort[][]{new ushort[]{0}};
static short s_32;
static short s_33;
static int s_45;
public static int Main()
{
ushort[] vr4 = s_23[0];
return (int)M45();
}

[MethodImpl(MethodImplOptions.NoInlining)]
static ushort M45()
{
short var0;
try
{
var0 = s_32;
}
finally
{
var0 = s_33;
int var1 = s_45;
ulong vr8 = default(ulong);
var0 = (short)((sbyte)vr8 - var0);
try
{
M46();
}
finally
{
M46();
}

System.Console.WriteLine(var1);
}

return 100;
}

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

0 comments on commit 6d35185

Please sign in to comment.