This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New fix for #26417 - Don't allow the hoisting of GT_CLS_VARs that were assigned a constant value. #26952
Merged
Merged
New fix for #26417 - Don't allow the hoisting of GT_CLS_VARs that were assigned a constant value. #26952
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
47 changes: 47 additions & 0 deletions
47
tests/src/JIT/Regression/JitBlue/GitHub_26417/GitHub_26417.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,47 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
class GitHub_26417 | ||
{ | ||
static int _a; | ||
|
||
[MethodImplAttribute(MethodImplOptions.NoInlining)] | ||
static void MyWriteLine(int v) | ||
{ | ||
Console.WriteLine(v); | ||
if (v == 0) | ||
{ | ||
throw new Exception(); | ||
} | ||
} | ||
|
||
[MethodImplAttribute(MethodImplOptions.NoInlining)] | ||
static void Test() | ||
{ | ||
_a = 1; | ||
|
||
while (_a == 1) | ||
{ | ||
MyWriteLine(_a); | ||
_a = 0; | ||
} | ||
} | ||
|
||
static int Main() | ||
{ | ||
int result = 100; | ||
try { | ||
Test(); | ||
} | ||
catch (Exception) | ||
{ | ||
Console.WriteLine("FAILED"); | ||
result = -1; | ||
} | ||
return result; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/src/JIT/Regression/JitBlue/GitHub_26417/GitHub_26417.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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DebugType>None</DebugType> | ||
<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.
I think the right check here is
if (!treeIsHoistable)
. If the tree is invariant and can throw but we don't hoist it, we need to setm_beforeSideEffect
tofalse
.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.
Unfortunately we have trees that switch back and forth from having treeIsHoistable as true to false and back to true.
Only the switch to treeIsInvariant is permanent.
One such tree that is important to be able to hoist is an invariant array read inside a loop:
Because ARR_BOUNDS_CHECK is a void, (it doesn't produce a value) it isn't a CSE candidate,
and anything that isn't a CSE candidate has treeIsHoistable set to false.
It's parent node is a GT_COMMA which produces a ushort value and can be hoistable.
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.
We may still have a hole here if we encounter a tree that's invariant and can throw an exception but we never hoist it (directly or as part of a parent). I tried to construct an example but ran into another bug where we do an incorrect exception reordering even without a loop: https://github.com/dotnet/coreclr/issues/27027.
I'm ok with this fix as it makes us "more correct" than before but we'll need to revisit this code.