-
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.
[release/6.0] JIT: Avoid removing multi-use boxes (#73014)
* JIT: Avoid removing multi-use boxes There was an assumption that the local operand to a GT_BOX node is single-use which was being violated when GDV clones these as arguments. We now allow multi-uses of these locals by setting a flag when cloning and then handle it in gtTryRemoveBoxUpstreamEffects. There is also GTF_VAR_CLONED that would be set on the local itself, but given that transformations can affect the operand local node arbitrarily I went with another of these type of flags on GT_BOX instead. Fix #72775 * Add a test * Test nit Co-authored-by: Jakob Botsch Nielsen <jakob.botsch.nielsen@gmail.com>
- Loading branch information
1 parent
b01798f
commit 708d716
Showing
5 changed files
with
99 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
53 changes: 53 additions & 0 deletions
53
src/tests/JIT/Regression/JitBlue/Runtime_72775/Runtime_72775.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,53 @@ | ||
// 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 System.Threading; | ||
|
||
public class Runtime_72775 | ||
{ | ||
public static int Main() | ||
{ | ||
for (int i = 0; i < 100; i++) | ||
{ | ||
Call(new Impl1()); | ||
if (i > 30 && i < 40) | ||
Thread.Sleep(10); | ||
} | ||
|
||
// With GDV, JIT would optimize Call by fully removing the box since Impl1.Foo does not use it. | ||
// This would cause null to be passed to Impl2.Foo. | ||
return Call(new Impl2()); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static int Call(I i) => i.Foo(5); | ||
} | ||
|
||
public interface I | ||
{ | ||
int Foo(object o); | ||
} | ||
|
||
class Impl1 : I | ||
{ | ||
public int Foo(object o) => 0; | ||
} | ||
|
||
class Impl2 : I | ||
{ | ||
public int Foo(object o) | ||
{ | ||
if (o is not int i || i != 5) | ||
{ | ||
Console.WriteLine("FAIL: Got {0}", o?.ToString() ?? "(null)"); | ||
return -1; | ||
} | ||
else | ||
{ | ||
Console.WriteLine("PASS: Got 5"); | ||
return 100; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/tests/JIT/Regression/JitBlue/Runtime_72775/Runtime_72775.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,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<CLRTestBatchPreCommands><![CDATA[ | ||
$(CLRTestBatchPreCommands) | ||
set COMPlus_TieredCompilation=1 | ||
set COMPlus_TieredPGO=1 | ||
]]></CLRTestBatchPreCommands> | ||
<BashCLRTestPreCommands><![CDATA[ | ||
$(BashCLRTestPreCommands) | ||
export COMPlus_TieredCompilation=1 | ||
export COMPlus_TieredPGO=1 | ||
]]></BashCLRTestPreCommands> | ||
</PropertyGroup> | ||
</Project> |