Skip to content

Commit 3752108

Browse files
Have ComputeRange call into GetRangeFromAssertions for non dependent/symbolic cases (#128922)
This is a smaller change from #128906 that doesn't involve more complex handling around `TYP_LONG`
1 parent 5e11a0f commit 3752108

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

src/coreclr/jit/rangecheck.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ void RangeCheck::MergeEdgeAssertionsWorker(Compiler* comp
12011201
ValueNumStore::SmallValueNumSet* visited)
12021202
{
12031203
Range assertedRange = Range(Limit(Limit::keUnknown));
1204-
if (BitVecOps::IsEmpty(comp->apTraits, assertions))
1204+
if (BitVecOps::MayBeUninit(assertions) || BitVecOps::IsEmpty(comp->apTraits, assertions))
12051205
{
12061206
return;
12071207
}
@@ -2287,9 +2287,19 @@ Range RangeCheck::ComputeRange(BasicBlock* block, GenTree* expr, bool monIncreas
22872287
// If VN is constant return range as constant.
22882288
else if (m_compiler->vnStore->IsVNConstant(vn))
22892289
{
2290-
range = (m_compiler->vnStore->TypeOfVN(vn) == TYP_INT)
2291-
? Range(Limit(Limit::keConstant, m_compiler->vnStore->ConstantValue<int>(vn)))
2292-
: Limit(Limit::keUnknown);
2290+
// We want to handle constants first since it can avoid other more expensive work
2291+
2292+
int cns;
2293+
if (m_compiler->vnStore->IsVNIntegralConstant(vn, &cns))
2294+
{
2295+
range = Range(Limit(Limit::keConstant, cns));
2296+
}
2297+
else
2298+
{
2299+
// TODO: We could return `0, keUnknown` if the constant is known positive
2300+
// but this would require more handling in other places to take advantage of.
2301+
range = Limit(Limit::keUnknown);
2302+
}
22932303
}
22942304
// If local, find the definition from the def map and evaluate the range for rhs.
22952305
else if (expr->IsLocal())
@@ -2331,20 +2341,10 @@ Range RangeCheck::ComputeRange(BasicBlock* block, GenTree* expr, bool monIncreas
23312341
JITDUMP("%s\n", range.ToString(m_compiler));
23322342
}
23332343
}
2334-
else if (varTypeIsSmall(expr))
2335-
{
2336-
range = GetRangeFromType(expr->TypeGet());
2337-
JITDUMP("%s\n", range.ToString(m_compiler));
2338-
}
23392344
else if (expr->OperIs(GT_COMMA))
23402345
{
23412346
range = GetRangeWorker(block, expr->gtEffectiveVal(), monIncreasing DEBUGARG(indent + 1));
23422347
}
2343-
else if (expr->OperIs(GT_CAST))
2344-
{
2345-
// TODO: consider computing range for CastOp and intersect it with this.
2346-
range = GetRangeFromType(expr->AsCast()->CastToType());
2347-
}
23482348
else if (expr->OperIs(GT_ARR_LENGTH))
23492349
{
23502350
ValueNum arrLenVN = m_compiler->optConservativeNormalVN(expr);
@@ -2360,6 +2360,11 @@ Range RangeCheck::ComputeRange(BasicBlock* block, GenTree* expr, bool monIncreas
23602360
range = Range(Limit(Limit::keConstant, 0), Limit(Limit::keConstant, CORINFO_Array_MaxLength));
23612361
}
23622362
}
2363+
else if (genActualType(expr) == TYP_INT)
2364+
{
2365+
// Use GetRangeFromAssertions for everything else since they won't produce dependent or symbolic ranges
2366+
range = GetRangeFromAssertions(m_compiler, vn, block->bbAssertionIn);
2367+
}
23632368
else
23642369
{
23652370
// The expression is not recognized, so the result is unknown.

0 commit comments

Comments
 (0)