-
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: Extract all side effects of the index in optRemoveRangeCheck (#9…
…2210) optRemoveRangeCheck extracts only GTF_ASG from the bounds check. If the BOUNDS_CHECK is complex, that results in silently dropping side effects on the floor (see the example case). The ideal fix is that we should always extract all side effects from the index and length operands, however this has large regressions because the length typically has an ARR_LENGTH that we then extract. This PR instead has a surgical fix for the problem case that can be backported to .NET 8. It extracts all side effects from the index, but keeps extracting only GTF_ASG from the length to get around the issue mentioned above. Fix #91862 Co-authored-by: Jakob Botsch Nielsen <jakob.botsch.nielsen@gmail.com>
- Loading branch information
1 parent
6c9a743
commit db172b4
Showing
4 changed files
with
63 additions
and
3 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
2 changes: 1 addition & 1 deletion
2
src/tests/JIT/Regression/JitBlue/Runtime_91576/Runtime_91576.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
46 changes: 46 additions & 0 deletions
46
src/tests/JIT/Regression/JitBlue/Runtime_91862/Runtime_91862.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,46 @@ | ||
// 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.Intrinsics; | ||
using Xunit; | ||
|
||
public class Runtime_91862 | ||
{ | ||
[Fact] | ||
public static int TestEntryPoint() | ||
{ | ||
return Foo(default); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static int Foo(Vector128<float> v) | ||
{ | ||
int result = 101; | ||
// This tree results in a BOUNDS_CHECK for Bar(...) & 3 | ||
float x = Vector128.GetElement(v, Bar(ref result) & 3); | ||
|
||
if (result != 100) | ||
{ | ||
Console.WriteLine("FAIL"); | ||
} | ||
|
||
// After inlining x is DCE'd, which will extract side effects of its assignment above. | ||
// That results IR amenable to forward sub, and we end up with a BOUNDS_CHECK | ||
// with a complex index expression that we can still prove is within bounds. | ||
Baz(x); | ||
return result; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static int Bar(ref int result) | ||
{ | ||
result = 100; | ||
return 0; | ||
} | ||
|
||
private static void Baz(float x) | ||
{ | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/tests/JIT/Regression/JitBlue/Runtime_91862/Runtime_91862.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> |