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

Code before:
    {
        LIR::Use use;
        if (BlockRange().TryGetUse(cmp, &use))
        {
            if (cmp->OperIs(GT_EQ))
            {
                GenTree* reversed = comp->gtReverseCond(op1);
                assert(reversed == op1);
            }

            // Relops and SETCC can be either TYP_INT or TYP_LONG typed, so we
            // may need to retype it.
            op1->gtType = cmp->TypeGet();

            GenTree* next = cmp->gtNext;
            use.ReplaceWith(op1);
            BlockRange().Remove(cmp->gtGetOp2());
            BlockRange().Remove(cmp);
            return next;
        }
    }

    // Optimize EQ/NE/GT/GE/LT/LE(op_that_sets_zf, 0) into op_that_sets_zf with GTF_SET_FLAGS + SETCC.
    LIR::Use use;
    if (((cmp->OperIs(GT_EQ, GT_NE) && op2->IsIntegralConst(0) && op1->SupportsSettingZeroFlag()) ||
         (cmp->OperIs(GT_GT, GT_GE, GT_LT, GT_LE) && op2->IsIntegralConst(0) && op1->OperIs(GT_AND, GT_AND_NOT) && op1->SupportsSettingFlagsAsCompareToZero())) &&
        BlockRange().TryGetUse(cmp, &use) && IsProfitableToSetZeroFlag(op1))
    {
        op1->gtFlags |= GTF_SET_FLAGS;
        op1->SetUnusedValue();

        GenTree* next = cmp->gtNext;
        BlockRange().Remove(cmp);
        BlockRange().Remove(op2);

        GenCondition cmpCondition = GenCondition::FromRelop(cmp);
        GenTreeCC*   setcc        = comp->gtNewCC(GT_SETCC, cmp->TypeGet(), cmpCondition);
        BlockRange().InsertAfter(op1, setcc);

        use.ReplaceWith(setcc);
        return next;
    }

    return cmp;
}

//------------------------------------------------------------------------
// Lowering::LowerCompare: Lowers a compare node.
//
// Arguments:
//    cmp - the compare node

Review comment (suggestion):
```suggestion
         (cmp->OperIs(GT_GT, GT_GE, GT_LT, GT_LE) && op2->IsIntegralConst(0) && op1->SupportsSettingFlagsAsCompareToZero())) &&
```

Code after:
    {
        LIR::Use use;
        if (BlockRange().TryGetUse(cmp, &use))
        {
            if (cmp->OperIs(GT_EQ))
            {
                GenTree* reversed = comp->gtReverseCond(op1);
                assert(reversed == op1);
            }

            // Relops and SETCC can be either TYP_INT or TYP_LONG typed, so we
            // may need to retype it.
            op1->gtType = cmp->TypeGet();

            GenTree* next = cmp->gtNext;
            use.ReplaceWith(op1);
            BlockRange().Remove(cmp->gtGetOp2());
            BlockRange().Remove(cmp);
            return next;
        }
    }

    // Optimize EQ/NE/GT/GE/LT/LE(op_that_sets_zf, 0) into op_that_sets_zf with GTF_SET_FLAGS + SETCC.
    LIR::Use use;
    if (((cmp->OperIs(GT_EQ, GT_NE) && op2->IsIntegralConst(0) && op1->SupportsSettingZeroFlag()) ||
         (cmp->OperIs(GT_GT, GT_GE, GT_LT, GT_LE) && op2->IsIntegralConst(0) &&
          op1->SupportsSettingFlagsAsCompareToZero())) &&
        BlockRange().TryGetUse(cmp, &use) && IsProfitableToSetZeroFlag(op1))
    {
        op1->gtFlags |= GTF_SET_FLAGS;
        op1->SetUnusedValue();

        GenTree* next = cmp->gtNext;
        BlockRange().Remove(cmp);
        BlockRange().Remove(op2);

        GenCondition cmpCondition = GenCondition::FromRelop(cmp);
        GenTreeCC*   setcc        = comp->gtNewCC(GT_SETCC, cmp->TypeGet(), cmpCondition);
        BlockRange().InsertAfter(op1, setcc);

        use.ReplaceWith(setcc);
        return next;
    }

    return cmp;
}

//------------------------------------------------------------------------
// Lowering::LowerCompare: Lowers a compare node.
//
// Arguments: