Skip to content
Merged
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
41 changes: 32 additions & 9 deletions src/coreclr/jit/rangecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,14 +1017,27 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
ValueNum addOpVN;
int addOpCns;
if (comp->vnStore->IsVNBinFuncWithConst(curAssertion.GetOp1().GetVN(), VNF_ADD, &addOpVN, &addOpCns) &&
(addOpVN == normalLclVN) && (addOpCns >= 0))
(addOpVN == normalLclVN))
{
cmpOper = GT_LT;
limit = Limit(Limit::keBinOpArray, preferredBoundVN, -addOpCns);
isUnsigned = false;
// The comparison being unsigned may also hint that the lower bound is -CNS1, but it's
// unlikely to be useful, so we ignore it for now. The whole thing will work only if some other
// assertion proves that the normalLclVN's lower bound is non-negative.
if (addOpCns >= 0)
{
cmpOper = GT_LT;
limit = Limit(Limit::keBinOpArray, preferredBoundVN, -addOpCns);
isUnsigned = false;
}
else if (addOpCns > INT32_MIN)
{
// (normalLclVN + negConst) u< bound, with bound non-negative.
// Since the comparison is unsigned, (normalLclVN + negConst) must not have wrapped,
// which means normalLclVN >= -negConst.
cmpOper = GT_GE;
limit = Limit(Limit::keConstant, -addOpCns);
isUnsigned = false;
}
Comment thread
EgorBo marked this conversation as resolved.
Comment thread
EgorBo marked this conversation as resolved.
else
{
continue;
}
}
else
{
Expand Down Expand Up @@ -2013,8 +2026,18 @@ Range RangeCheck::ComputeRange(BasicBlock* block, GenTree* expr, bool monIncreas
}
else if (expr->OperIs(GT_ARR_LENGTH))
{
// Better than keUnknown
range = Range(Limit(Limit::keConstant, 0), Limit(Limit::keConstant, CORINFO_Array_MaxLength));
ValueNum arrLenVN = m_compiler->optConservativeNormalVN(expr);
if ((arrLenVN != ValueNumStore::NoVN) && (arrLenVN == m_preferredBound))
{
// If the ARR_LENGTH VN matches the bounds check's length VN, represent it symbolically
// so the PHI merge can combine it with other symbolic ranges referencing the same bound.
Comment thread
EgorBo marked this conversation as resolved.
range = Range(Limit(Limit::keConstant, 0), Limit(Limit::keBinOpArray, arrLenVN, 0));
}
else
{
// Better than keUnknown
range = Range(Limit(Limit::keConstant, 0), Limit(Limit::keConstant, CORINFO_Array_MaxLength));
}
}
else
{
Expand Down
Loading