Repository: dotnet/runtime
File: src/coreclr/jit/assertionprop.cpp (C++)

Code before:
    // Note we only need check the op1 vector; copies get indexed on both op1
    // and op2, so searching the first will find any existing match.
    //
    if (optLocalAssertionProp)
    {
        assert(newAssertion.GetOp1().KindIs(O1K_LCLVAR));

        unsigned        lclNum = newAssertion.GetOp1().GetLclNum();
        BitVecOps::Iter iter(apTraits, GetAssertionDep(lclNum));
        unsigned        bvIndex = 0;
        while (iter.NextElem(&bvIndex))
        {
            AssertionIndex const index        = GetAssertionIndex(bvIndex);
            const AssertionDsc&  curAssertion = optGetAssertion(index);

            if (curAssertion.Equals(newAssertion, /* vnBased */ false))
            {
                return index;
            }
        }
    }
    else
    {
        bool mayHaveDuplicates =
            optAssertionHasAssertionsForVN(newAssertion.GetOp1().GetVN(), /* addIfNotFound */ canAddNewAssertions);
        // We need to register op2.vn too, even if know for sure there are no duplicates
        if (newAssertion.GetOp2().KindIs(O2K_CHECKED_BOUND_ADD_CNS))
        {
            mayHaveDuplicates |= optAssertionHasAssertionsForVN(newAssertion.GetOp2().GetCheckedBound(),
                                                                /* addIfNotFound */ canAddNewAssertions);
        }

        if (mayHaveDuplicates)
        {
            // For global prop we search the entire table.
            //
            // Check if exists already, so we can skip adding new one. Search backwards.
            for (AssertionIndex index = optAssertionCount; index >= 1; index--)
            {
                const AssertionDsc& curAssertion = optGetAssertion(index);
                if (curAssertion.Equals(newAssertion, /* vnBased */ true))
                {
                    return index;
                }
            }
        }
    }

    // Check if we are within max count.
    if (!canAddNewAssertions)
    {

Review comment (refactor):
Comment has a minor grammar issue: "even if know for sure" should be "even if we know for sure" for clarity.
```suggestion
        // We need to register op2.vn too, even if we know for sure there are no duplicates
```

Code after:
/*****************************************************************************
 *
 *  Given an assertion add it to the assertion table
 *
 *  If it is already in the assertion table return the assertionIndex that
 *  we use to refer to this element.
 *  Otherwise add it to the assertion table and return the assertionIndex that
 *  we use to refer to this element.
 *  If we need to add to the table and the table is full return the value zero
 */
AssertionIndex Compiler::optAddAssertion(const AssertionDsc& newAssertion)
{
    bool canAddNewAssertions = optAssertionCount < optMaxAssertionCount;

    // See if we already have this assertion in the table.
    //
    // For local assertion prop we can speed things up by checking the dep vector.
    // Note we only need check the op1 vector; copies get indexed on both op1
    // and op2, so searching the first will find any existing match.
    //
    if (optLocalAssertionProp)
    {
        assert(newAssertion.GetOp1().KindIs(O1K_LCLVAR));

        unsigned        lclNum = newAssertion.GetOp1().GetLclNum();
        BitVecOps::Iter iter(apTraits, GetAssertionDep(lclNum));
        unsigned        bvIndex = 0;
        while (iter.NextElem(&bvIndex))
        {
            AssertionIndex const index        = GetAssertionIndex(bvIndex);
            const AssertionDsc&  curAssertion = optGetAssertion(index);

            if (curAssertion.Equals(newAssertion, /* vnBased */ false))
            {
                return index;
            }
        }
    }
    else
    {
        bool mayHaveDuplicates =
            optAssertionHasAssertionsForVN(newAssertion.GetOp1().GetVN(), /* addIfNotFound */ canAddNewAssertions);
        // We need to register op2.vn too, even if we know for sure there are no duplicates
        if (newAssertion.GetOp2().KindIs(O2K_CHECKED_BOUND_ADD_CNS))
        {
            mayHaveDuplicates |= optAssertionHasAssertionsForVN(newAssertion.GetOp2().GetCheckedBound(),
                                                                /* addIfNotFound */ canAddNewAssertions);
        }

        if (mayHaveDuplicates)
        {