diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index 1a4eb8af5af569..ca5de4f0f1945d 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -289,21 +289,58 @@ static Range GetRange(Compiler* comp, GenTree* tree, BasicBlock* block, ASSERT_V } int64_t constValue = node->AsIntConCommon()->IntegralValue(); - - if (FitsIn(constValue)) + if (constValue < 0) { - rangeType = TYP_INT; + // We don't try and reason about lower bounds here to simplify the logic. + break; } - else if (FitsIn(constValue)) + + // For a non-negative constant, try and find a tighter upper bound + if (constValue <= UINT16_MAX) { - rangeType = TYP_UINT; + if (constValue <= UINT8_MAX) + { + if (constValue <= INT8_MAX) + { + rangeType = TYP_BYTE; + } + else + { + rangeType = TYP_UBYTE; + } + } + else + { + if (constValue <= INT16_MAX) + { + rangeType = TYP_SHORT; + } + else + { + rangeType = TYP_USHORT; + } + } } - - if (constValue >= 0) + else { - return {SymbolicIntegerValue::Zero, UpperBoundForType(rangeType)}; + if (constValue <= UINT32_MAX) + { + if (constValue <= INT32_MAX) + { + rangeType = TYP_INT; + } + else + { + rangeType = TYP_UINT; + } + } + else + { + rangeType = TYP_LONG; + } } - break; + + return {SymbolicIntegerValue::Zero, UpperBoundForType(rangeType)}; } case GT_QMARK: