diff --git a/src/coreclr/jit/lsra.cpp b/src/coreclr/jit/lsra.cpp index b86b707121906..82ba8480047e5 100644 --- a/src/coreclr/jit/lsra.cpp +++ b/src/coreclr/jit/lsra.cpp @@ -8155,8 +8155,6 @@ void LinearScan::handleOutgoingCriticalEdges(BasicBlock* block) if (lastNode->OperIs(GT_JTRUE, GT_JCMP, GT_JTEST)) { GenTree* op = lastNode->gtGetOp1(); - -Consume_Op2: consumedRegs |= genRegMask(op->GetRegNum()); if (op->OperIs(GT_COPY)) @@ -8170,16 +8168,22 @@ void LinearScan::handleOutgoingCriticalEdges(BasicBlock* block) terminatorNodeLclVarDsc = &compiler->lvaTable[lcl->GetLclNum()]; } - if (!lastNode->gtGetOp2()->isContainedIntOrIImmed() && (op != lastNode->gtGetOp2())) + if (lastNode->OperIs(GT_JCMP, GT_JTEST) && !lastNode->gtGetOp2()->isContained()) { op = lastNode->gtGetOp2(); - goto Consume_Op2; - } + consumedRegs |= genRegMask(op->GetRegNum()); -#if !defined(TARGET_LOONGARCH64) && !defined(TARGET_RISCV64) - // For LoongArch64/RISC-V, the second operand of a JCMP can be in a register too. - assert(!lastNode->OperIs(GT_JCMP, GT_JTEST) || lastNode->gtGetOp2()->isContained()); -#endif + if (op->OperIs(GT_COPY)) + { + GenTree* srcOp = op->gtGetOp1(); + consumedRegs |= genRegMask(srcOp->GetRegNum()); + } + else if (op->IsLocal()) + { + GenTreeLclVarCommon* lcl = op->AsLclVarCommon(); + terminatorNodeLclVarDsc = &compiler->lvaTable[lcl->GetLclNum()]; + } + } } }