Skip to content

Commit 044caf6

Browse files
authored
JIT: A small CQ improvement for Equals/StartsWith unrolling (#76439)
1 parent ca6fb31 commit 044caf6

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/coreclr/jit/assertionprop.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ bool IntegralRange::Contains(int64_t value) const
175175
}
176176
break;
177177

178+
case GT_CNS_INT:
179+
if (node->IsIntegralConst(0) || node->IsIntegralConst(1))
180+
{
181+
return {SymbolicIntegerValue::Zero, SymbolicIntegerValue::One};
182+
}
183+
break;
184+
185+
case GT_QMARK:
186+
return Union(ForNode(node->AsQmark()->ThenNode(), compiler),
187+
ForNode(node->AsQmark()->ElseNode(), compiler));
188+
178189
case GT_CAST:
179190
return ForCastOutput(node->AsCast());
180191

@@ -430,6 +441,12 @@ bool IntegralRange::Contains(int64_t value) const
430441
return {lowerBound, upperBound};
431442
}
432443

444+
/* static */ IntegralRange IntegralRange::Union(IntegralRange range1, IntegralRange range2)
445+
{
446+
return IntegralRange(min(range1.GetLowerBound(), range2.GetLowerBound()),
447+
max(range1.GetUpperBound(), range2.GetUpperBound()));
448+
}
449+
433450
#ifdef DEBUG
434451
/* static */ void IntegralRange::Print(IntegralRange range)
435452
{

src/coreclr/jit/compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,7 @@ class IntegralRange
12681268
static IntegralRange ForNode(GenTree* node, Compiler* compiler);
12691269
static IntegralRange ForCastInput(GenTreeCast* cast);
12701270
static IntegralRange ForCastOutput(GenTreeCast* cast);
1271+
static IntegralRange Union(IntegralRange range1, IntegralRange range2);
12711272

12721273
#ifdef DEBUG
12731274
static void Print(IntegralRange range);

src/coreclr/jit/gentree.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5707,6 +5707,16 @@ struct GenTreeQmark : public GenTreeOp
57075707
assert((colon != nullptr) && colon->OperIs(GT_COLON));
57085708
}
57095709

5710+
GenTree* ThenNode()
5711+
{
5712+
return gtOp2->AsColon()->ThenNode();
5713+
}
5714+
5715+
GenTree* ElseNode()
5716+
{
5717+
return gtOp2->AsColon()->ElseNode();
5718+
}
5719+
57105720
#if DEBUGGABLE_GENTREE
57115721
GenTreeQmark() : GenTreeOp()
57125722
{

0 commit comments

Comments
 (0)