Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #21857 from AndyAyersMS/RangeCheckSmallTypes
Browse files Browse the repository at this point in the history
JIT: infer ranges from small int type operations
  • Loading branch information
AndyAyersMS authored Jan 9, 2019
2 parents 5a0144e + eef4174 commit eaf9823
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/jit/rangecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,14 @@ bool RangeCheck::ComputeDoesOverflow(BasicBlock* block, GenTree* expr)
{
overflows = false;
}
else if (expr->OperGet() == GT_IND)
{
overflows = false;
}
else if (expr->OperGet() == GT_COMMA)
{
overflows = ComputeDoesOverflow(block, expr->gtEffectiveVal());
}
// Check if the var def has rhs involving arithmetic that overflows.
else if (expr->IsLocal())
{
Expand Down Expand Up @@ -1135,6 +1143,29 @@ Range RangeCheck::ComputeRange(BasicBlock* block, GenTree* expr, bool monotonic
JITDUMP("%s\n", range.ToString(m_pCompiler->getAllocatorDebugOnly()));
}
}
else if (varTypeIsSmallInt(expr->TypeGet()))
{
switch (expr->TypeGet())
{
case TYP_UBYTE:
range = Range(Limit(Limit::keConstant, 0), Limit(Limit::keConstant, 255));
break;
case TYP_BYTE:
range = Range(Limit(Limit::keConstant, -127), Limit(Limit::keConstant, 128));
break;
case TYP_USHORT:
range = Range(Limit(Limit::keConstant, 0), Limit(Limit::keConstant, 65535));
break;
case TYP_SHORT:
range = Range(Limit(Limit::keConstant, -32768), Limit(Limit::keConstant, 32767));
break;
default:
range = Range(Limit(Limit::keUnknown));
break;
}

JITDUMP("%s\n", range.ToString(m_pCompiler->getAllocatorDebugOnly()));
}
else
{
// The expression is not recognized, so the result is unknown.
Expand Down

0 comments on commit eaf9823

Please sign in to comment.