Skip to content
Open
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
22 changes: 13 additions & 9 deletions src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5298,11 +5298,6 @@ PhaseStatus Compiler::fgHeadTailMerge(bool early)

fgUnlinkStmt(predBlock, stmt);

if (predBlock->isEmpty())
{
tryRemoveAndFixFlow(predBlock, commSucc);
}

// Add one of the matching stmts to block, and
// update its flags.
//
Expand All @@ -5312,6 +5307,11 @@ PhaseStatus Compiler::fgHeadTailMerge(bool early)
commSucc->CopyFlags(predBlock, BBF_COPY_PROPAGATE);
}

if (predBlock->isEmpty())
{
tryRemoveAndFixFlow(predBlock, commSucc);
}

madeChanges = true;
}

Expand Down Expand Up @@ -5363,20 +5363,24 @@ PhaseStatus Compiler::fgHeadTailMerge(bool early)

// From most to least preferable.
//
if (isNoSplit && isFallThrough)
if (predBlock == commSucc)
{
return 0;
}
if (isNoSplit)
if (isNoSplit && isFallThrough)
{
return 1;
}
if (isFallThrough)
if (isNoSplit)
{
return 2;
}
if (isFallThrough)
{
return 3;
}

return 3;
return 4;
};

unsigned const rank = getRank();
Expand Down
61 changes: 61 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_133131/Runtime_133131.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Runtime_133131;

using System.Runtime.CompilerServices;
using Xunit;

public class Runtime_133131
{
private static int s_v;

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
private static void TailMergePickSelfLoopAsVictim(int x)
{
if (x == 1)
{
goto P;
}
if (x == 2)
{
s_v = 77;
goto L;
}
return;
P:
s_v = 1;
goto L;
L:
s_v = 1;
goto L;
}

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
private static void TailMergeDontRemoveSelfLoop(int x)
{
if (x >= 0)
{
goto P;
}
return;
L:
s_v = 1;
goto L;
P:
s_v = 1;
goto L;
}

[Fact]
public static void TestEntryPoint()
{
s_v = 0;
TailMergePickSelfLoopAsVictim(-1);
Assert.Equal(0, s_v);

s_v = 0;
TailMergeDontRemoveSelfLoop(-1);
Assert.Equal(0, s_v);
}
}
1 change: 1 addition & 0 deletions src/tests/JIT/Regression/Regression_ro_2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<Compile Include="JitBlue\Runtime_131137\Runtime_131137.cs" />
<Compile Include="JitBlue\Runtime_131226\Runtime_131226.cs" />
<Compile Include="JitBlue\Runtime_131459\Runtime_131459.cs" />
<Compile Include="JitBlue\Runtime_133131\Runtime_133131.cs" />
<Compile Include="JitBlue\Runtime_10337\Runtime_10337.cs" />
<Compile Include="JitBlue\Runtime_125160\Runtime_125160.cs" />
<Compile Include="JitBlue\GitHub_131472\GitHub_131472.cs" />
Expand Down
Loading