RefTypeZeroInit doesn't need treeNode (#56333)
authorKunal Pathak <Kunal.Pathak@microsoft.com>
Wed, 28 Jul 2021 22:47:00 +0000 (15:47 -0700)
committerGitHub <noreply@github.com>
Wed, 28 Jul 2021 22:47:00 +0000 (15:47 -0700)
* RefTypeZeroInit doesn't need treeNode

* Add a test case

src/coreclr/jit/lsrabuild.cpp
src/tests/JIT/Regression/JitBlue/Runtime_54100/Runtime_54100.cs [new file with mode: 0644]
src/tests/JIT/Regression/JitBlue/Runtime_54100/Runtime_54100.csproj [new file with mode: 0644]

index 5e95c81d2302f5c04762ad35d9a333d8933d1a75..d18e49f3894cac03d42c105c7ce08a040551096c 100644 (file)
@@ -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 (file)
index 0000000..8f8f25d
--- /dev/null
@@ -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 (file)
index 0000000..e8e73ed
--- /dev/null
@@ -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>
\ No newline at end of file