Skip to content

Commit

Permalink
JIT: fix no return call accounting
Browse files Browse the repository at this point in the history
The jit tracks the number of no return calls to determine if it should run
throw helper merging and to decide if no return calls should tail called.

The accounting is currently done when the calls are initially imported,
so if code is duplicated (by say finally cloning the count may end up being
an under-estimate. While not a correctness issue, it is better for the count
to be accurate (or an over-estimate).

So, update the count when cloning a no-return call.

Closes dotnet#36584.
  • Loading branch information
AndyAyersMS committed May 19, 2020
1 parent 9740aa5 commit eb15919
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/coreclr/src/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7861,6 +7861,15 @@ GenTreeCall* Compiler::gtCloneExprCallHelper(GenTreeCall* tree, unsigned addFlag

copy->CopyOtherRegFlags(tree);

// We keep track of the number of no return calls, so if we've cloned
// one of these, update the tracking.
//
if (tree->IsNoReturn())
{
assert(copy->IsNoReturn());
setMethodHasNoReturnCalls();
}

return copy;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

// Finally cloning creates new throw merge candidates that
// need to be properly counted.

class Runtime_36584
{
static int x;

static void ThrowHelper()
{
throw new Exception();
}

public static int Main()
{
x = 100;

if (x != 100)
{
ThrowHelper();
}

if (x != 100)
{
ThrowHelper();
}

if (x != 100)
{
try
{
x++;
}
// This finally will be cloned
finally
{
if (x != 100)
{
ThrowHelper();
}

if (x != 100)
{
ThrowHelper();
}
}
}

return x;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<DebugType />
<Optimize>True</Optimize>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit eb15919

Please sign in to comment.