New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JIT: Fold string fields in structs stored in static readonly fields #80431
Merged
Merged
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
13344be
Fold string fields in structs located in static readonly fields
EgorBo b7c0918
Add more checks
EgorBo 5cacf2c
Add comments
EgorBo 2269fde
handle null
EgorBo 7f41259
Merge branch 'main' of github.com:dotnet/runtime into vn-static-reado…
EgorBo 0cc917d
fix assert
EgorBo 9995feb
Fix getReadonlyStaticFieldValue for structs with gc fields
EgorBo ecd0b29
Merge branch 'main' of github.com:dotnet/runtime into vn-static-reado…
EgorBo 53a8e73
Update jitinterface.cpp
EgorBo 53716c8
Address feedback
EgorBo feced0f
Add tests
EgorBo c0b6956
the test needs tiering
EgorBo b03f848
Merge branch 'main' of github.com:dotnet/runtime into vn-static-reado…
EgorBo 278c35b
Update src/coreclr/vm/jitinterface.cpp
EgorBo d134808
Merge branch 'vn-static-readonly-struct-string' of github.com:EgorBo/…
EgorBo f8b8aab
Address feedback
EgorBo 523b6b9
Merge branch 'main' of github.com:dotnet/runtime into vn-static-reado…
EgorBo 7786e8e
Address feedback
EgorBo a23700a
Merge branch 'main' of github.com:dotnet/runtime into vn-static-reado…
EgorBo 552c488
clean up
EgorBo 3a63145
Update src/coreclr/vm/jitinterface.cpp
EgorBo 6dc936f
hoist the check
EgorBo fe4543a
Address feedback
EgorBo File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
71 changes: 71 additions & 0 deletions
71
src/tests/JIT/opt/ValueNumbering/StaticReadonlyStructWithGC.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,71 @@ | ||
// 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; | ||
|
||
class StaticReadonlyStructWithGC | ||
{ | ||
static int Main() | ||
{ | ||
// Pre-initialize host type | ||
RuntimeHelpers.RunClassConstructor(typeof(StaticReadonlyStructWithGC).TypeHandle); | ||
|
||
if (!Test1()) throw new Exception("Test1 failed"); | ||
if (!Test2()) throw new Exception("Test2 failed"); | ||
if (!Test3()) throw new Exception("Test3 failed"); | ||
if (!Test4()) throw new Exception("Test4 failed"); | ||
if (!Test5()) throw new Exception("Test5 failed"); | ||
if (!Test6()) throw new Exception("Test6 failed"); | ||
if (!Test7()) throw new Exception("Test7 failed"); | ||
if (!Test8()) throw new Exception("Test8 failed"); | ||
if (!Test9()) throw new Exception("Test9 failed"); | ||
return 100; | ||
} | ||
|
||
static readonly MyStruct MyStructFld = new() | ||
{ | ||
A = "A", | ||
B = 111111.ToString(), // non-literal | ||
C = new MyStruct2 { A = "AA" }, | ||
D = typeof(int), | ||
E = () => 42, | ||
F = new MyStruct3 { A = typeof(double), B = typeof(string) }, | ||
G = new int[0], | ||
H = null | ||
}; | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test1() => MyStructFld.A == "A"; | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test2() => MyStructFld.B == "111111"; | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test3() => MyStructFld.C.A == "AA"; | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test4() => MyStructFld.D == typeof(int); | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test5() => MyStructFld.E() == 42; | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test6() => MyStructFld.F.A == typeof(double); | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test7() => MyStructFld.F.B == typeof(string); | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test8() => MyStructFld.G.Length == 0; | ||
[MethodImpl(MethodImplOptions.NoInlining)] static bool Test9() => MyStructFld.H == null; | ||
|
||
struct MyStruct | ||
{ | ||
public string A; | ||
public string B; | ||
public MyStruct2 C; | ||
public Type D; | ||
public Func<int> E; | ||
public MyStruct3 F; | ||
public int[] G; | ||
public object H; | ||
} | ||
|
||
struct MyStruct2 | ||
{ | ||
public string A; | ||
} | ||
|
||
struct MyStruct3 | ||
{ | ||
public Type A; | ||
public Type B; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/tests/JIT/opt/ValueNumbering/StaticReadonlyStructWithGC.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> | ||
<OutputType>Exe</OutputType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be
TYP_BYREF
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any point in checking the type of the address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, removed 🙂