Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f5bc205
tmp
EgorBo Dec 2, 2021
2757d64
Merge branch 'main' of https://github.com/dotnet/runtime into span-bo…
EgorBo Dec 14, 2021
1556eb8
Handle bound checks for ((uint)index cmp CNS) pattern
EgorBo Dec 15, 2021
be074e4
Fix typo
EgorBo Dec 15, 2021
1b14746
Fix build error
EgorBo Dec 15, 2021
31ab6d5
Fix 32bit platforms
EgorBo Dec 16, 2021
1b06196
Fix 32bit again
EgorBo Dec 16, 2021
81b5232
Update morph.cpp
EgorBo Dec 16, 2021
b13b852
Update morph.cpp
EgorBo Dec 16, 2021
fc5ceb2
Clean up
EgorBo Dec 17, 2021
1e14f8e
Clean up
EgorBo Dec 17, 2021
53a6405
Move to fgOptimizeRelationalComparisonWithCasts
EgorBo Dec 17, 2021
747339c
fix 32bit again
EgorBo Dec 17, 2021
f4b1ffa
fix SetUnsigned
EgorBo Dec 17, 2021
58f4f68
Clean up
EgorBo Dec 18, 2021
b9e68b0
Update morph.cpp
EgorBo Dec 18, 2021
929e53b
Merge branch 'main' of https://github.com/dotnet/runtime into bound-c…
EgorBo Dec 19, 2021
f4e82ce
test
EgorBo Dec 19, 2021
abc7d54
Introduce O1K_CONSTANT_LOOP_BND_UN
EgorBo Dec 19, 2021
3bf8534
Merge branch 'main' of https://github.com/dotnet/runtime into bound-c…
EgorBo Dec 19, 2021
aecf6a4
Update assertionprop.cpp
EgorBo Dec 20, 2021
96376f6
Merge branch 'bound-checks-constant-len' of https://github.com/EgorBo…
EgorBo Jan 15, 2022
1c9f406
Merge branch 'main' of https://github.com/dotnet/runtime into bound-c…
EgorBo Jan 27, 2022
ff58212
resolve conflicts
EgorBo Jan 27, 2022
61b1fa1
fix newline
EgorBo Jan 27, 2022
8ba164d
Merge branch 'main' of https://github.com/dotnet/runtime into bound-c…
EgorBo Jan 27, 2022
e4fff61
Merge branch 'main' of https://github.com/dotnet/runtime into bound-c…
EgorBo Feb 15, 2022
f2aa51a
Merge branch 'main' of https://github.com/dotnet/runtime into bound-c…
EgorBo Feb 18, 2022
58cec64
Address feedback
EgorBo Feb 18, 2022
10d9a0d
Apply suggestions from code review
EgorBo Feb 24, 2022
20505fd
Merge branch 'main' of https://github.com/dotnet/runtime into bound-c…
EgorBo Feb 24, 2022
a643eb6
Apply suggestions
EgorBo Feb 24, 2022
ffadcd7
use bashtoconst
EgorBo Feb 24, 2022
d2518c2
use bashtoconst
EgorBo Feb 25, 2022
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
Prev Previous commit
Next Next commit
test
  • Loading branch information
EgorBo committed Dec 19, 2021
commit f4e82cee81ae8851353a17baeb34d1a87e850630
6 changes: 4 additions & 2 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,8 @@ AssertionInfo Compiler::optCreateJTrueBoundsAssertion(GenTree* tree)
bool hasTestAgainstZero =
(relop->gtOper == GT_EQ || relop->gtOper == GT_NE) && (op2VN == vnStore->VNZeroForType(op2->TypeGet()));

bool isUnsignedRelop = false;

ValueNumStore::UnsignedCompareCheckedBoundInfo unsignedCompareBnd;
// Cases where op1 holds the upper bound arithmetic and op2 is 0.
// Loop condition like: "i < bnd +/-k == 0"
Expand Down Expand Up @@ -2293,7 +2295,7 @@ AssertionInfo Compiler::optCreateJTrueBoundsAssertion(GenTree* tree)
// Cases where op1 holds the condition bound check and op2 is 0.
// Loop condition like: "i < 100 == 0"
// Assertion: "i < 100 == false"
else if (hasTestAgainstZero && vnStore->IsVNConstantBound(op1VN))
else if (hasTestAgainstZero && vnStore->IsVNConstantBound(op1VN, &isUnsignedRelop) && !isUnsignedRelop)
{
AssertionDsc dsc;
dsc.assertionKind = relop->gtOper == GT_EQ ? OAK_EQUAL : OAK_NOT_EQUAL;
Expand All @@ -2310,7 +2312,7 @@ AssertionInfo Compiler::optCreateJTrueBoundsAssertion(GenTree* tree)
// Cases where op1 holds the lhs of the condition op2 holds rhs.
// Loop condition like "i < 100"
// Assertion: "i < 100 != 0"
else if (vnStore->IsVNConstantBound(relopVN))
else if (vnStore->IsVNConstantBound(relopVN, &isUnsignedRelop))
{
AssertionDsc dsc;
dsc.assertionKind = OAK_NOT_EQUAL;
Expand Down
56 changes: 28 additions & 28 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4771,14 +4771,17 @@ bool ValueNumStore::IsVNRelop(ValueNum vn)
}
}

bool ValueNumStore::IsVNConstantBound(ValueNum vn)
bool ValueNumStore::IsVNConstantBound(ValueNum vn, bool* viaUnsigned)
{
assert(viaUnsigned);

VNFuncApp funcApp;
if ((vn != NoVN) && GetVNFunc(vn, &funcApp))
{
if ((funcApp.m_func == (VNFunc)GT_LE) || (funcApp.m_func == (VNFunc)GT_GE) ||
(funcApp.m_func == (VNFunc)GT_LT) || (funcApp.m_func == (VNFunc)GT_GT))
{
*viaUnsigned = false;
const bool op1IsConst = IsVNInt32Constant(funcApp.m_args[0]);
const bool op2IsConst = IsVNInt32Constant(funcApp.m_args[1]);
return op1IsConst != op2IsConst;
Expand All @@ -4790,12 +4793,14 @@ bool ValueNumStore::IsVNConstantBound(ValueNum vn)
{
// (uint)index < CNS
// (uint)index >= CNS
*viaUnsigned = true;
return (funcApp.m_func == VNF_LT_UN) || (funcApp.m_func == VNF_GE_UN);
}
else if (op1IsPositiveConst && !op2IsPositiveConst)
{
// CNS > (uint)index
// CNS <= (uint)index
*viaUnsigned = true;
return (funcApp.m_func == VNF_GT_UN) || (funcApp.m_func == VNF_LE_UN);
}
}
Expand All @@ -4804,42 +4809,36 @@ bool ValueNumStore::IsVNConstantBound(ValueNum vn)

void ValueNumStore::GetConstantBoundInfo(ValueNum vn, ConstantBoundInfo* info)
{
assert(IsVNConstantBound(vn));
bool viaUnsigned = false;
assert(IsVNConstantBound(vn, &viaUnsigned));
assert(info);

VNFuncApp funcAttr;
GetVNFunc(vn, &funcAttr);

bool isOp1Const = IsVNInt32Constant(funcAttr.m_args[1]);

bool isUnsigned = true;
genTreeOps op;
if (funcAttr.m_func == VNF_GT_UN)
switch (funcAttr.m_func)
{
op = GT_GT;
info->isUnsigned = true;
}
else if (funcAttr.m_func == VNF_GE_UN)
{
op = GT_GE;
info->isUnsigned = true;
}
else if (funcAttr.m_func == VNF_LT_UN)
{
op = GT_LT;
info->isUnsigned = true;
}
else if (funcAttr.m_func == VNF_LE_UN)
{
op = GT_LE;
info->isUnsigned = true;
}
else
{
op = (genTreeOps)funcAttr.m_func;
info->isUnsigned = false;
case VNF_GT_UN:
op = GT_GT;
break;
case VNF_GE_UN:
op = GT_GE;
break;
case VNF_LT_UN:
op = GT_LT;
break;
case VNF_LE_UN:
op = GT_LE;
break;
default:
op = (genTreeOps)funcAttr.m_func;
isUnsigned = false;
break;
}

if (isOp1Const)
if (IsVNInt32Constant(funcAttr.m_args[1]))
{
info->cmpOper = op;
info->cmpOpVN = funcAttr.m_args[0];
Expand All @@ -4851,6 +4850,7 @@ void ValueNumStore::GetConstantBoundInfo(ValueNum vn, ConstantBoundInfo* info)
info->cmpOpVN = funcAttr.m_args[1];
info->constVal = GetConstantInt32(funcAttr.m_args[0]);
}
info->isUnsigned = isUnsigned;
}

//------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/valuenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ class ValueNumStore
ValueNum GetArrForLenVn(ValueNum vn);

// Return true with any Relop except for == and != and one operand has to be a 32-bit integer constant.
bool IsVNConstantBound(ValueNum vn);
bool IsVNConstantBound(ValueNum vn, bool* viaUnsigned);

// If "vn" is constant bound, then populate the "info" fields for constVal, cmpOp, cmpOper.
void GetConstantBoundInfo(ValueNum vn, ConstantBoundInfo* info);
Expand Down