Skip to content

Commit

Permalink
JIT: Track sideness of arrOp in GetCheckedBoundArithInfo (#100848)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored Apr 10, 2024
1 parent b8803cb commit 674ba3f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/coreclr/jit/optcse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4813,8 +4813,12 @@ void CSE_HeuristicCommon::PerformCSE(CSE_Candidate* successfulCandidate)

assert(vnStore->IsVNCompareCheckedBoundArith(oldCmpVN));
vnStore->GetCompareCheckedBoundArithInfo(oldCmpVN, &info);
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);
Expand Down
14 changes: 8 additions & 6 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6669,15 +6669,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;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/valuenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -932,12 +932,14 @@ 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)
, arrOpLHS(false)
, cmpOper(GT_NONE)
, cmpOp(NoVN)
{
Expand Down
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>

0 comments on commit 674ba3f

Please sign in to comment.