-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JIT: Evaluate GDV call args early (#75634)
The normal evaluation order for a callvirt is the following: 1. The 'this' arg is evaluated 2. The arguments are evaluated 3. 'this' is null-checked 4. The call is performed Step 1 and 2 happen as part of the IL instructions that load the arguments, while step 3 and 4 happen as part of the callvirt IL instruction. For GDV the guards needs to dereference 'this'. We were doing this too early, causing step 3 to happen before step 2. The fix is to spill all side-effecting arguments for GDVs to temps. Fix #75607
- Loading branch information
1 parent
e8fa4a7
commit 10fc8ae
Showing
3 changed files
with
134 additions
and
15 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
63 changes: 63 additions & 0 deletions
63
src/tests/JIT/Regression/JitBlue/Runtime_75607/Runtime_75607.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,63 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
|
||
public class Program | ||
{ | ||
private static int s_result; | ||
public static int Main() | ||
{ | ||
C c = new(); | ||
for (int i = 0; i < 100; i++) | ||
{ | ||
Foo(c); | ||
Thread.Sleep(15); | ||
} | ||
|
||
s_result = -1; | ||
try | ||
{ | ||
Foo(null); | ||
Console.WriteLine("FAIL: No exception thrown"); | ||
return -2; | ||
} | ||
catch (NullReferenceException) | ||
{ | ||
if (s_result == 100) | ||
{ | ||
Console.WriteLine("PASS"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("FAIL: Result is {0}", s_result); | ||
} | ||
|
||
return s_result; | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static void Foo(Base b) | ||
{ | ||
b.Test(SideEffect(10)); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static long SideEffect(long i) | ||
{ | ||
s_result = 100; | ||
return i; | ||
} | ||
} | ||
|
||
public interface Base | ||
{ | ||
void Test(long arg); | ||
} | ||
|
||
public class C : Base | ||
{ | ||
public void Test(long arg) | ||
{ | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/tests/JIT/Regression/JitBlue/Runtime_75607/Runtime_75607.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,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DebugType>None</DebugType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<CLRTestBatchPreCommands><![CDATA[ | ||
$(CLRTestBatchPreCommands) | ||
set COMPlus_TieredPGO=1 | ||
set COMPlus_TC_QuickJitForLoops=1 | ||
]]></CLRTestBatchPreCommands> | ||
<BashCLRTestPreCommands><![CDATA[ | ||
$(BashCLRTestPreCommands) | ||
export COMPlus_TieredPGO=1 | ||
export COMPlus_TC_QuickJitForLoops=1 | ||
]]></BashCLRTestPreCommands> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |