-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JIT: Fix downwards loop transformation with multiply executed exiting…
… blocks (#103723) The transformation to turn loops into downwards counted loops was missing a check for whether the block containing the exit test was potentially executed multiple times.
- Loading branch information
1 parent
a9af6c0
commit 5891160
Showing
5 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/tests/JIT/opt/Loops/DownwardsLoopMultiplyExecutedExitingBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using Xunit; | ||
|
||
public class DownwardsLoopMultiplyExecutedExiting | ||
{ | ||
[Fact] | ||
public static int ExitFromNestedLoop() | ||
{ | ||
int n = Get10(); | ||
int i = 0; | ||
int result = 0; | ||
if (n < 0) | ||
return -1; | ||
|
||
do | ||
{ | ||
int j = 0; | ||
do | ||
{ | ||
if (i >= n) | ||
return result; | ||
|
||
j++; | ||
result++; | ||
} while (j < 10); | ||
|
||
i++; | ||
} while (true); | ||
} | ||
|
||
[Fact] | ||
public static int ExitFromNestedIrreducibleLoop() | ||
{ | ||
int n = Get10(); | ||
int i = 0; | ||
int result = -1; | ||
if (n < 0) | ||
return -1; | ||
|
||
do | ||
{ | ||
int j = 0; | ||
if (AlwaysFalse()) | ||
goto InsideLoop; | ||
|
||
LoopHeader: | ||
j++; | ||
result++; | ||
|
||
InsideLoop:; | ||
if (i >= n) | ||
return result; | ||
|
||
if (j < 10) | ||
goto LoopHeader; | ||
|
||
i++; | ||
} while (true); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static bool AlwaysFalse() => false; | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static int Get10() => 10; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/tests/JIT/opt/Loops/DownwardsLoopMultiplyExecutedExitingBlock.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<DebugType>PdbOnly</DebugType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |