Skip to content

Commit

Permalink
fix the regs conflicts within the addResolution for LoongArch64 and…
Browse files Browse the repository at this point in the history
… RISC-V. (#86294)

* Fix the regs conflicts within the `addResolution` for LoongArch64/RISC-V.

* amend the code for CR.

* add terminatorNodeLclVarDsc2 for the second op2.
  • Loading branch information
shushanhf authored May 17, 2023
1 parent 27d0009 commit 2b11093
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/coreclr/jit/lsra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8118,7 +8118,8 @@ void LinearScan::handleOutgoingCriticalEdges(BasicBlock* block)
}
}

LclVarDsc* terminatorNodeLclVarDsc = nullptr;
LclVarDsc* terminatorNodeLclVarDsc = nullptr;
LclVarDsc* terminatorNodeLclVarDsc2 = nullptr;
// Next, if this blocks ends with a switch table, or for Arm64, ends with JCMP/JTEST instruction,
// make sure to not copy into the registers that are consumed at the end of this block.
//
Expand Down Expand Up @@ -8178,18 +8179,28 @@ void LinearScan::handleOutgoingCriticalEdges(BasicBlock* block)
GenTree* srcOp = op->gtGetOp1();
consumedRegs |= genRegMask(srcOp->GetRegNum());
}

if (op->IsLocal())
else if (op->IsLocal())
{
GenTreeLclVarCommon* lcl = op->AsLclVarCommon();
terminatorNodeLclVarDsc = &compiler->lvaTable[lcl->GetLclNum()];
}

#if !defined(TARGET_LOONGARCH64) && !defined(TARGET_RISCV64)
// TODO-LOONGARCH64: Take into account that on LA64, the second
// operand of a JCMP can be in a register too.
assert(!lastNode->OperIs(GT_JCMP, GT_JTEST) || lastNode->gtGetOp2()->isContained());
#endif
if (lastNode->OperIs(GT_JCMP, GT_JTEST) && !lastNode->gtGetOp2()->isContained())
{
op = lastNode->gtGetOp2();
consumedRegs |= genRegMask(op->GetRegNum());

if (op->OperIs(GT_COPY))
{
GenTree* srcOp = op->gtGetOp1();
consumedRegs |= genRegMask(srcOp->GetRegNum());
}
else if (op->IsLocal())
{
GenTreeLclVarCommon* lcl = op->AsLclVarCommon();
terminatorNodeLclVarDsc2 = &compiler->lvaTable[lcl->GetLclNum()];
}
}
}
}

Expand Down Expand Up @@ -8273,6 +8284,11 @@ void LinearScan::handleOutgoingCriticalEdges(BasicBlock* block)
{
sameToReg = REG_NA;
}
else if ((terminatorNodeLclVarDsc2 != nullptr) &&
(terminatorNodeLclVarDsc2->lvVarIndex == outResolutionSetVarIndex))
{
sameToReg = REG_NA;
}
#endif // defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)

// If the var is live only at those blocks connected by a split edge and not live-in at some of the
Expand Down

0 comments on commit 2b11093

Please sign in to comment.