Skip to content

Commit 728df8c

Browse files
authored
Disable checked bounds for assertprop (#113638)
1 parent a45130e commit 728df8c

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/coreclr/jit/rangecheck.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -637,22 +637,27 @@ void RangeCheck::MergeEdgeAssertions(GenTreeLclVarCommon* lcl, ASSERT_VALARG_TP
637637
//
638638
bool RangeCheck::TryGetRangeFromAssertions(Compiler* comp, ValueNum num, ASSERT_VALARG_TP assertions, Range* pRange)
639639
{
640-
MergeEdgeAssertions(comp, num, num, assertions, pRange);
640+
MergeEdgeAssertions(comp, num, ValueNumStore::NoVN, assertions, pRange, false);
641641
return !pRange->LowerLimit().IsUnknown() || !pRange->UpperLimit().IsUnknown();
642642
}
643643

644644
//------------------------------------------------------------------------
645645
// MergeEdgeAssertions: Merge assertions on the edge flowing into the block about a variable
646646
//
647647
// Arguments:
648-
// comp - the compiler instance
649-
// normalLclVN - the value number to look for assertions for
650-
// preferredBoundVN - when this VN is set, it will be given preference over constant limits
651-
// assertions - the assertions to use
652-
// pRange - the range to tighten with assertions
648+
// comp - the compiler instance
649+
// normalLclVN - the value number to look for assertions for
650+
// preferredBoundVN - when this VN is set, it will be given preference over constant limits
651+
// assertions - the assertions to use
652+
// pRange - the range to tighten with assertions
653+
// canUseCheckedBounds - true if we can use checked bounds assertions (cache)
653654
//
654-
void RangeCheck::MergeEdgeAssertions(
655-
Compiler* comp, ValueNum normalLclVN, ValueNum preferredBoundVN, ASSERT_VALARG_TP assertions, Range* pRange)
655+
void RangeCheck::MergeEdgeAssertions(Compiler* comp,
656+
ValueNum normalLclVN,
657+
ValueNum preferredBoundVN,
658+
ASSERT_VALARG_TP assertions,
659+
Range* pRange,
660+
bool canUseCheckedBounds)
656661
{
657662
Range assertedRange = Range(Limit(Limit::keUnknown));
658663
if (BitVecOps::IsEmpty(comp->apTraits, assertions))
@@ -680,7 +685,7 @@ void RangeCheck::MergeEdgeAssertions(
680685
bool isUnsigned = false;
681686

682687
// Current assertion is of the form (i < len - cns) != 0
683-
if (curAssertion->IsCheckedBoundArithBound())
688+
if (canUseCheckedBounds && curAssertion->IsCheckedBoundArithBound())
684689
{
685690
ValueNumStore::CompareCheckedBoundArithInfo info;
686691

@@ -709,7 +714,7 @@ void RangeCheck::MergeEdgeAssertions(
709714
cmpOper = (genTreeOps)info.cmpOper;
710715
}
711716
// Current assertion is of the form (i < len) != 0
712-
else if (curAssertion->IsCheckedBoundBound())
717+
else if (canUseCheckedBounds && curAssertion->IsCheckedBoundBound())
713718
{
714719
ValueNumStore::CompareCheckedBoundArithInfo info;
715720

@@ -767,7 +772,7 @@ void RangeCheck::MergeEdgeAssertions(
767772
int cnstLimit = (int)curAssertion->op2.u1.iconVal;
768773
assert(cnstLimit == comp->vnStore->CoercedConstantValue<int>(curAssertion->op2.vn));
769774

770-
if ((cnstLimit == 0) && (curAssertion->assertionKind == Compiler::OAK_NOT_EQUAL) &&
775+
if ((cnstLimit == 0) && (curAssertion->assertionKind == Compiler::OAK_NOT_EQUAL) && canUseCheckedBounds &&
771776
comp->vnStore->IsVNCheckedBound(curAssertion->op1.vn))
772777
{
773778
// we have arr.Len != 0, so the length must be atleast one

src/coreclr/jit/rangecheck.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,12 @@ class RangeCheck
728728
void MergeEdgeAssertions(GenTreeLclVarCommon* lcl, ASSERT_VALARG_TP assertions, Range* pRange);
729729

730730
// Inspect the assertions about the current ValueNum to refine pRange
731-
static void MergeEdgeAssertions(
732-
Compiler* comp, ValueNum num, ValueNum preferredBoundVN, ASSERT_VALARG_TP assertions, Range* pRange);
731+
static void MergeEdgeAssertions(Compiler* comp,
732+
ValueNum num,
733+
ValueNum preferredBoundVN,
734+
ASSERT_VALARG_TP assertions,
735+
Range* pRange,
736+
bool canUseCheckedBounds = true);
733737

734738
// The maximum possible value of the given "limit". If such a value could not be determined
735739
// return "false". For example: CORINFO_Array_MaxLength for array length.

0 commit comments

Comments
 (0)