Skip to content

Commit

Permalink
Use BoundsCheckNoThrow assertion in optAssertionProp_RangeProperties (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored May 11, 2024
1 parent b997776 commit bdfbed6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3930,6 +3930,18 @@ void Compiler::optAssertionProp_RangeProperties(ASSERT_VALARG_TP assertions,
{
AssertionDsc* curAssertion = optGetAssertion(GetAssertionIndex(index));

// if treeVN has a bound-check assertion where it's an index, then
// it means it's not negative, example:
//
// array[idx] = 42; // creates 'BoundsCheckNoThrow' assertion
// return idx % 8; // idx is known to be never negative here, hence, MOD->UMOD
//
if (curAssertion->IsBoundsCheckNoThrow() && (curAssertion->op1.bnd.vnIdx == treeVN))
{
*isKnownNonNegative = true;
continue;
}

// First, analyze possible X ==/!= CNS assertions.
if (curAssertion->IsConstantInt32Assertion() && (curAssertion->op1.vn == treeVN))
{
Expand Down

0 comments on commit bdfbed6

Please sign in to comment.