@@ -2606,33 +2606,47 @@ GenTree* Lowering::LowerCompare(GenTree* cmp)
26062606 {
26072607 GenTree* op1 = cmp->gtGetOp1 ();
26082608 GenTree* op2 = cmp->gtGetOp2 ();
2609- LIR::Use cmpUse;
26102609
2611- if (op1->OperIs (GT_AND, GT_OR, GT_XOR, GT_ADD, GT_SUB, GT_NEG) && op2-> IsIntegralConst ( 0 ) &&
2612- (op1->gtNext == op2) && (op2->gtNext == cmp) && BlockRange (). TryGetUse (cmp, &cmpUse) )
2610+ if (op2-> IsIntegralConst ( 0 ) && op1->OperIs (GT_AND, GT_OR, GT_XOR, GT_ADD, GT_SUB, GT_NEG) &&
2611+ (op1->gtNext == op2) && (op2->gtNext == cmp))
26132612 {
2614- genTreeOps condition = cmp->OperGet ();
2615- GenTree* next = cmp->gtNext ;
2616- GenTreeCC* cc;
2613+ op1->gtFlags |= GTF_SET_FLAGS;
2614+ op1->SetUnusedValue ();
26172615
2618- if (cmpUse.User ()->OperIs (GT_JTRUE))
2616+ BlockRange ().Remove (op2);
2617+
2618+ GenTree* next = cmp->gtNext ;
2619+ GenTree* cc;
2620+ genTreeOps ccOp;
2621+ LIR::Use cmpUse;
2622+
2623+ // Fast check for the common case - relop used by a JTRUE that immediately follows it.
2624+ if ((next != nullptr ) && next->OperIs (GT_JTRUE) && (next->gtGetOp1 () == cmp))
26192625 {
2620- cmpUse.User ()->ChangeOper (GT_JCC);
2621- cc = cmpUse.User ()->AsCC ();
2626+ cc = next;
2627+ ccOp = GT_JCC;
2628+ next = nullptr ;
26222629 BlockRange ().Remove (cmp);
26232630 }
2624- else
2631+ else if ( BlockRange (). TryGetUse (cmp, &cmpUse) && cmpUse. User ()-> OperIs (GT_JTRUE))
26252632 {
2626- cmp->ChangeOper (GT_SETCC);
2627- cc = cmp->AsCC ();
2633+ cc = cmpUse.User ();
2634+ ccOp = GT_JCC;
2635+ next = nullptr ;
2636+ BlockRange ().Remove (cmp);
2637+ }
2638+ else // The relop is not used by a JTRUE or it is not used at all.
2639+ {
2640+ // Transform the relop node it into a SETCC. If it's not used we could remove
2641+ // it completely but that means doing more work to handle a rare case.
2642+ cc = cmp;
2643+ ccOp = GT_SETCC;
26282644 }
26292645
2630- cc->gtCondition = condition;
2631- cc->gtFlags |= GTF_USE_FLAGS;
2632- op1->gtFlags |= GTF_SET_FLAGS;
2633- op1->SetUnusedValue ();
2634-
2635- BlockRange ().Remove (op2);
2646+ genTreeOps condition = cmp->OperGet ();
2647+ cc->ChangeOper (ccOp);
2648+ cc->AsCC ()->gtCondition = condition;
2649+ cc->gtFlags |= GTF_USE_FLAGS | (cmp->gtFlags & GTF_UNSIGNED);
26362650
26372651 return next;
26382652 }
0 commit comments