From 6d3518520ae041fb4c6c1c54d5abf0975a38a450 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 28 Jul 2021 15:47:00 -0700 Subject: [PATCH] RefTypeZeroInit doesn't need treeNode (#56333) * RefTypeZeroInit doesn't need treeNode * Add a test case --- src/coreclr/jit/lsrabuild.cpp | 29 ++-------- .../JitBlue/Runtime_54100/Runtime_54100.cs | 55 +++++++++++++++++++ .../Runtime_54100/Runtime_54100.csproj | 10 ++++ 3 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_54100/Runtime_54100.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_54100/Runtime_54100.csproj diff --git a/src/coreclr/jit/lsrabuild.cpp b/src/coreclr/jit/lsrabuild.cpp index 5e95c81d230..d18e49f3894 100644 --- a/src/coreclr/jit/lsrabuild.cpp +++ b/src/coreclr/jit/lsrabuild.cpp @@ -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 // @@ -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 @@ -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; } diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_54100/Runtime_54100.cs b/src/tests/JIT/Regression/JitBlue/Runtime_54100/Runtime_54100.cs new file mode 100644 index 00000000000..8f8f25d2b36 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_54100/Runtime_54100.cs @@ -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); + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_54100/Runtime_54100.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_54100/Runtime_54100.csproj new file mode 100644 index 00000000000..e8e73ed9d1a --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_54100/Runtime_54100.csproj @@ -0,0 +1,10 @@ + + + Exe + True + None + + + + + \ No newline at end of file -- 2.34.1