Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: block throw helper merges for first block of a try #34039

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/coreclr/src/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25869,6 +25869,14 @@ void Compiler::fgTailMergeThrows()
// and there is less jumbled flow to sort out later.
for (BasicBlock* block = fgLastBB; block != nullptr; block = block->bbPrev)
{
// Workaround: don't consider try entry blocks as candidates
// for merging; if the canonical throw is later in the same try,
// we'll create invalid flow.
if ((block->bbFlags & BBF_TRY_BEG) != 0)
{
continue;
}

// For throw helpers the block should have exactly one statement....
// (this isn't guaranteed, but seems likely)
Statement* stmt = block->firstStmt();
Expand Down
36 changes: 36 additions & 0 deletions src/coreclr/tests/src/JIT/opt/ThrowHelper/ThrowHelperAtTryEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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;

// Test case where throw helper is in the try entry block.
//
// Throw helper merging is run lexically backwards,
// so the optimization may introduce a jump into the middle of the try.

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

public static int Main()
{
int x = 0;
bool p = true;
try
{
ThrowHelper();
x = -1;
if (p) ThrowHelper();
}
catch (Exception)
{
x = 100;
}

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>None</DebugType>
<Optimize>True</Optimize>
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
</PropertyGroup>
<ItemGroup>
<Compile Include="ThrowHelperAtTryEntry.cs" />
</ItemGroup>
</Project>