diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index aca2574ce6ec8..2176ac1d9c312 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -175,6 +175,17 @@ bool IntegralRange::Contains(int64_t value) const } break; + case GT_CNS_INT: + if (node->IsIntegralConst(0) || node->IsIntegralConst(1)) + { + return {SymbolicIntegerValue::Zero, SymbolicIntegerValue::One}; + } + break; + + case GT_QMARK: + return Union(ForNode(node->AsQmark()->ThenNode(), compiler), + ForNode(node->AsQmark()->ElseNode(), compiler)); + case GT_CAST: return ForCastOutput(node->AsCast()); @@ -430,6 +441,12 @@ bool IntegralRange::Contains(int64_t value) const return {lowerBound, upperBound}; } +/* static */ IntegralRange IntegralRange::Union(IntegralRange range1, IntegralRange range2) +{ + return IntegralRange(min(range1.GetLowerBound(), range2.GetLowerBound()), + max(range1.GetUpperBound(), range2.GetUpperBound())); +} + #ifdef DEBUG /* static */ void IntegralRange::Print(IntegralRange range) { diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 6850cd9d2b170..51b8764a0da35 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -1268,6 +1268,7 @@ class IntegralRange static IntegralRange ForNode(GenTree* node, Compiler* compiler); static IntegralRange ForCastInput(GenTreeCast* cast); static IntegralRange ForCastOutput(GenTreeCast* cast); + static IntegralRange Union(IntegralRange range1, IntegralRange range2); #ifdef DEBUG static void Print(IntegralRange range); diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 25f40845dd4cc..0b0c2a3545645 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -5707,6 +5707,16 @@ struct GenTreeQmark : public GenTreeOp assert((colon != nullptr) && colon->OperIs(GT_COLON)); } + GenTree* ThenNode() + { + return gtOp2->AsColon()->ThenNode(); + } + + GenTree* ElseNode() + { + return gtOp2->AsColon()->ElseNode(); + } + #if DEBUGGABLE_GENTREE GenTreeQmark() : GenTreeOp() {