From f2dc8d29c26e70e9830e5df7550b17158379badd Mon Sep 17 00:00:00 2001 From: Adam Perlin Date: Wed, 8 Jul 2026 16:06:36 -0700 Subject: [PATCH 1/2] More precise range assertions for GT_CNS_INT --- src/coreclr/jit/assertionprop.cpp | 43 ++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index 1a4eb8af5af569..8770f93811e2d2 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -290,13 +290,48 @@ static Range GetRange(Compiler* comp, GenTree* tree, BasicBlock* block, ASSERT_V int64_t constValue = node->AsIntConCommon()->IntegralValue(); - if (FitsIn(constValue)) + if (constValue <= UINT16_MAX) { - rangeType = TYP_INT; + 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; + } + } } - else if (FitsIn(constValue)) + else { - rangeType = TYP_UINT; + if (constValue <= UINT32_MAX) + { + if (constValue <= INT32_MAX) + { + rangeType = TYP_INT; + } + else + { + rangeType = TYP_UINT; + } + } + else + { + rangeType = TYP_LONG; + } } if (constValue >= 0) From 35231854dfc455e24d56d43e3386d9e8841c0894 Mon Sep 17 00:00:00 2001 From: Adam Perlin Date: Thu, 9 Jul 2026 09:21:58 -0700 Subject: [PATCH 2/2] Fix mis-ordering of non-negative check for constant --- src/coreclr/jit/assertionprop.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index 8770f93811e2d2..ca5de4f0f1945d 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -289,7 +289,13 @@ static Range GetRange(Compiler* comp, GenTree* tree, BasicBlock* block, ASSERT_V } int64_t constValue = node->AsIntConCommon()->IntegralValue(); + if (constValue < 0) + { + // We don't try and reason about lower bounds here to simplify the logic. + break; + } + // For a non-negative constant, try and find a tighter upper bound if (constValue <= UINT16_MAX) { if (constValue <= UINT8_MAX) @@ -334,11 +340,7 @@ static Range GetRange(Compiler* comp, GenTree* tree, BasicBlock* block, ASSERT_V } } - if (constValue >= 0) - { - return {SymbolicIntegerValue::Zero, UpperBoundForType(rangeType)}; - } - break; + return {SymbolicIntegerValue::Zero, UpperBoundForType(rangeType)}; } case GT_QMARK: