forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JIT: block some struct promotion for OSR
This undoes part of dotnet#65903. OSR methods can't rely solely on their own analysis for struct promotion as they only see parts of methods.
- Loading branch information
1 parent
d8f8527
commit b32e80a
Showing
3 changed files
with
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// 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.Runtime.InteropServices; | ||
|
||
interface IFoo | ||
{ | ||
public Span<object> AsSpan(); | ||
} | ||
|
||
public struct ObjectSequence1 : IFoo | ||
{ | ||
public object Value1; | ||
|
||
public Span<object> AsSpan() | ||
{ | ||
return MemoryMarshal.CreateSpan(ref Value1, 1); | ||
} | ||
} | ||
|
||
public struct ObjectSequenceMany : IFoo | ||
{ | ||
public object[] _values; | ||
|
||
public Span<object> AsSpan() | ||
{ | ||
return _values.AsSpan(); | ||
} | ||
|
||
public ObjectSequenceMany(object[] x) | ||
{ | ||
_values = x; | ||
} | ||
} | ||
|
||
public class InvalidPromotion | ||
{ | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static bool G<T>(int n) where T : IFoo | ||
{ | ||
// OSR cannot safely promote values | ||
T values = default; | ||
|
||
if (values is ObjectSequenceMany) | ||
{ | ||
values = (T)(object)new ObjectSequenceMany(new object[5]); | ||
} | ||
|
||
Span<object> indexedValues = values.AsSpan(); | ||
|
||
// For a patchpoint here. | ||
for (int i = 0; i < n; i++) | ||
{ | ||
indexedValues[i] = "foo"; | ||
} | ||
|
||
if (values is ObjectSequence1) | ||
{ | ||
return (indexedValues[0] == ((ObjectSequence1)(object)values).Value1); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static int Main() | ||
{ | ||
return G<ObjectSequence1>(1) ? 100 : -1; | ||
} | ||
} | ||
|
||
|
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,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<DebugType /> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<CLRTestBatchPreCommands><![CDATA[ | ||
$(CLRTestBatchPreCommands) | ||
set COMPlus_TieredCompilation=1 | ||
set COMPlus_TC_QuickJitForLoops=1 | ||
set COMPlus_TC_OnStackReplacement=1 | ||
set COMPlus_OSR_HitLimit=1 | ||
set COMPlus_TC_OnStackReplacement=1 | ||
set COMPlus_TC_OnStackReplacement_InitialCounter=1 | ||
]]></CLRTestBatchPreCommands> | ||
<BashCLRTestPreCommands><![CDATA[ | ||
$(BashCLRTestPreCommands) | ||
export COMPlus_TieredCompilation=1 | ||
export COMPlus_TC_QuickJitForLoops=1 | ||
export COMPlus_TC_OnStackReplacement=1 | ||
export COMPlus_OSR_HitLimit=1 | ||
export COMPlus_TC_OnStackReplacement=1 | ||
export COMPlus_TC_OnStackReplacement_InitialCounter=1 | ||
]]></BashCLRTestPreCommands> | ||
</PropertyGroup> | ||
</Project> |