-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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] Fix - Do not remove CAST
nodes on store if the LCL_VAR
is address exposed
#85734
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
004b61a
Do not remove CAST nodes on assignment if the LCL_VAR is a parameter.
TIHan 56570b7
Added NormalizeOnLoad rules from SingleAccretion. Added description o…
TIHan e68875b
Remove morph optimization for NormalizeOnLoad in fgMorphLocalVar. Upd…
TIHan 861bebf
Merging
TIHan 8de354e
Merge remote-tracking branch 'upstream/main' into 85382-fix-2
TIHan b111627
Do not OptimizeCastOnStore for params and struct fields
TIHan d6417d5
Update src/coreclr/jit/morph.cpp
TIHan 0b728de
Formatting
TIHan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10115,8 +10115,20 @@ GenTree* Compiler::fgOptimizeCastOnStore(GenTree* store) | |
if (!src->OperIs(GT_CAST)) | ||
return store; | ||
|
||
if (store->OperIs(GT_STORE_LCL_VAR) && !lvaGetDesc(store->AsLclVarCommon())->lvNormalizeOnLoad()) | ||
return store; | ||
if (store->OperIs(GT_STORE_LCL_VAR)) | ||
{ | ||
LclVarDsc* varDsc = lvaGetDesc(store->AsLclVarCommon()->GetLclNum()); | ||
|
||
// We can make this transformation only under the assumption that NOL locals are always normalized before they | ||
// are used, | ||
// however this is not always the case: the JIT will utilize subrange assertions for NOL locals to make | ||
// normalization | ||
// assumptions -- see fgMorphLeafLocal. Thus we can only do this for cases where we know for sure that | ||
// subsequent uses | ||
// will normalize, which we can only guarantee when the local is address exposed. | ||
Comment on lines
+10122
to
+10128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The formatting here is a bit strange, maybe reformat the comment locally? |
||
if (!varDsc->lvNormalizeOnLoad() || !varDsc->IsAddressExposed()) | ||
return store; | ||
} | ||
|
||
if (src->gtOverflow()) | ||
return store; | ||
|
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
98 changes: 98 additions & 0 deletions
98
src/tests/JIT/Regression/JitBlue/Runtime_85382/Runtime_85382.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,98 @@ | ||
// 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.Collections; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using Xunit; | ||
|
||
public class Test | ||
{ | ||
// This is trying to verify that we properly zero-extend on all platforms. | ||
public class Program | ||
{ | ||
public static long s_15; | ||
public static sbyte s_17; | ||
public static ushort s_21 = 36659; | ||
public static int Test() | ||
{ | ||
s_15 = ~1; | ||
return M40(0); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public static void Consume(ushort x) { } | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public static int M40(ushort arg0) | ||
{ | ||
for (int var0 = 0; var0 < 2; var0++) | ||
{ | ||
arg0 = 65535; | ||
arg0 &= (ushort)(s_15++ >> s_17); | ||
arg0 %= s_21; | ||
} | ||
|
||
Consume(arg0); | ||
|
||
if (arg0 != 28876) | ||
{ | ||
return 0; | ||
} | ||
return 100; | ||
} | ||
} | ||
|
||
public class Program2 | ||
{ | ||
public static long s_15; | ||
public static sbyte s_17; | ||
public static ushort s_21 = 36659; | ||
public static int Test() | ||
{ | ||
s_15 = ~1; | ||
return M40(); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public static void Consume(ushort x) { } | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public static int M40() | ||
{ | ||
S s = default; | ||
for (int var0 = 0; var0 < 2; var0++) | ||
{ | ||
s.U = 65535; | ||
s.U &= (ushort)(s_15++ >> s_17); | ||
s.U %= s_21; | ||
} | ||
|
||
Consume(s.U); | ||
|
||
if (s.U != 28876) | ||
{ | ||
return 0; | ||
} | ||
return 100; | ||
} | ||
|
||
public struct S { public ushort U; } | ||
} | ||
|
||
[Fact] | ||
public static int TestEntryPoint() { | ||
if (Test.Program.Test() != 100) | ||
{ | ||
return 0; | ||
} | ||
|
||
if (Test.Program2.Test() != 100) | ||
{ | ||
return 0; | ||
} | ||
|
||
return 100; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/tests/JIT/Regression/JitBlue/Runtime_85382/Runtime_85382.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,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<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.
Same here, this comment is formatted strangely, missing some spaces and it should be "address-exposed", not "address - exposed".