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-staging] JIT: Track sideness of arrOp in GetCheckedBoundArithInfo #100968

Merged
Merged
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions src/coreclr/jit/optcse.cpp
Original file line number Diff line number Diff line change
@@ -3066,8 +3066,11 @@ class CSE_Heuristic

assert(vnStore->IsVNCompareCheckedBoundArith(oldCmpVN));
vnStore->GetCompareCheckedBoundArithInfo(oldCmpVN, &info);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the other uses of this function? Do they need to be changed too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jakobbotsch I've inspected all uses and didn't find places where we might make wrong decisions due to order of operands (the only use of arrOp is this CSE where we compose a new VN and in rangecheck)

newCmpArgVN = vnStore->VNForFunc(vnStore->TypeOfVN(info.arrOp), (VNFunc)info.arrOper,
info.arrOp, theConservativeVN);
ValueNum arrOp1 = info.arrOpLHS ? info.arrOp : theConservativeVN;
ValueNum arrOp2 = info.arrOpLHS ? theConservativeVN : info.arrOp;

newCmpArgVN =
vnStore->VNForFunc(vnStore->TypeOfVN(info.arrOp), (VNFunc)info.arrOper, arrOp1, arrOp2);
}
ValueNum newCmpVN = vnStore->VNForFunc(vnStore->TypeOfVN(oldCmpVN), (VNFunc)info.cmpOper,
info.cmpOp, newCmpArgVN);
14 changes: 8 additions & 6 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
@@ -6576,15 +6576,17 @@ void ValueNumStore::GetCheckedBoundArithInfo(ValueNum vn, CompareCheckedBoundAri
bool isOp1CheckedBound = IsVNCheckedBound(funcArith.m_args[1]);
if (isOp1CheckedBound)
{
info->arrOper = funcArith.m_func;
info->arrOp = funcArith.m_args[0];
info->vnBound = funcArith.m_args[1];
info->arrOper = funcArith.m_func;
info->arrOp = funcArith.m_args[0];
info->vnBound = funcArith.m_args[1];
info->arrOpLHS = true;
}
else
{
info->arrOper = funcArith.m_func;
info->arrOp = funcArith.m_args[1];
info->vnBound = funcArith.m_args[0];
info->arrOper = funcArith.m_func;
info->arrOp = funcArith.m_args[1];
info->vnBound = funcArith.m_args[0];
info->arrOpLHS = false;
}
}

3 changes: 2 additions & 1 deletion src/coreclr/jit/valuenum.h
Original file line number Diff line number Diff line change
@@ -920,9 +920,10 @@ class ValueNumStore
ValueNum vnBound;
unsigned arrOper;
ValueNum arrOp;
bool arrOpLHS; // arrOp is on the left side of cmpOp expression
unsigned cmpOper;
ValueNum cmpOp;
CompareCheckedBoundArithInfo() : vnBound(NoVN), arrOper(GT_NONE), arrOp(NoVN), cmpOper(GT_NONE), cmpOp(NoVN)
CompareCheckedBoundArithInfo() : vnBound(NoVN), arrOper(GT_NONE), arrOp(NoVN), arrOpLHS(false), cmpOper(GT_NONE), cmpOp(NoVN)
{
}
#ifdef DEBUG
23 changes: 23 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_100809/Runtime_100809.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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 Xunit;

public static class Runtime_100809
{
[Fact]
public static int TestEntryPoint()
{
return AlwaysFalse(96) ? -1 : 100;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool AlwaysFalse(int x)
{
var result = new byte[x];
int count = result.Length - 2;
return (x < 0 || result.Length - count < 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>