Skip to content
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

[release/8.0] JIT: Extract all side effects of the index in optRemoveRangeCheck #92210

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8875,9 +8875,15 @@ GenTree* Compiler::optRemoveRangeCheck(GenTreeBoundsChk* check, GenTree* comma,
}
#endif

// Extract side effects
// TODO-Bug: We really should be extracting all side effects from the
// length and index here, but the length typically involves a GT_ARR_LENGTH
// that we would preserve. Usually, as part of proving that the range check
// passes, we have also proven that the ARR_LENGTH is non-faulting. We need
// a good way to communicate to this function that it is ok to ignore side
// effects of the ARR_LENGTH.
GenTree* sideEffList = nullptr;
gtExtractSideEffList(check, &sideEffList, GTF_ASG);
gtExtractSideEffList(check->GetArrayLength(), &sideEffList, GTF_ASG);
gtExtractSideEffList(check->GetIndex(), &sideEffList);

if (sideEffList != nullptr)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.aa
// The .NET Foundation licenses this file to you under the MIT license.

// Generated by Fuzzlyn v1.6 on 2023-09-03 15:59:01
// Run on X64 Windows
Expand Down
46 changes: 46 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_91862/Runtime_91862.cs
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)
{
}
}
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>