Skip to content
Draft
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
12 changes: 12 additions & 0 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,18 @@ void Compiler::optAssertionGen(GenTree* tree)
{
assertionInfo = optCreateAssertion(tree->GetIndirOrArrMetaDataAddr(), nullptr, /*equals*/ false);
}
else if (tree->OperIs(GT_IND) && tree->TypeIs(TYP_INT) &&
IntegralRange::ForNode(tree, this).IsNonNegative())
{
// Create "IND >= 0" assertion for int indirections that are known to be non-negative.
// Mainly, this is for unpromoted Span.Length indirections.
ValueNum vn = optConservativeNormalVN(tree);
if (vn != ValueNumStore::NoVN)
{
assertionInfo = optAddAssertion(
AssertionDsc::CreateConstantBound(this, VNF_GE, vn, vnStore->VNZeroForType(TYP_INT)));
}
}
break;

case GT_INTRINSIC:
Expand Down
18 changes: 6 additions & 12 deletions src/coreclr/jit/rangecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,11 @@ Range RangeCheck::ComputeRange(BasicBlock* block, GenTree* expr, bool monIncreas
range = Limit(Limit::keUnknown);
}
}
// If this value IS the caller-provided preferred bound, represent it as [bound, bound]
else if ((m_preferredBound != ValueNumStore::NoVN) && (vn == m_preferredBound))
{
range = Range(Limit(Limit::keBinOpArray, m_preferredBound, 0));
}
// If local, find the definition from the def map and evaluate the range for rhs.
else if (expr->IsLocal())
{
Expand Down Expand Up @@ -2340,18 +2345,7 @@ Range RangeCheck::ComputeRange(BasicBlock* block, GenTree* expr, bool monIncreas
}
else if (expr->OperIs(GT_ARR_LENGTH))
{
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.
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));
}
range = Range(Limit(Limit::keConstant, 0), Limit(Limit::keConstant, CORINFO_Array_MaxLength));
}
else
{
Expand Down
Loading