From 7f750ab9f79703564796ed4967acfe2700dc9cd2 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 8 Apr 2021 16:26:14 +0300 Subject: [PATCH] Address feedback --- src/coreclr/jit/morph.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 8fbce8a586e79..fe95a6b61275c 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -7733,7 +7733,31 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call) // if (nextBlock->bbJumpKind != BBJ_RETURN) { - BasicBlock* const nextNextBlock = nextBlock->GetUniqueSucc(); + BasicBlock* nextNextBlock = nextBlock->GetUniqueSucc(); + + // Check if we have a sequence of GT_ASG blocks where the same variable is assigned to temps over + // and over (can happen after multiple GDVs of potential tall calls). + // TODO-CQ: Don't introduce new temps when we replace GT_RET_EXPR which is already assigned to a + // local. + if (nextNextBlock->bbJumpKind != BBJ_RETURN) + { + assert(nextBlock->firstStmt() == nextBlock->lastStmt()); + GenTree* asgNode = nextBlock->firstStmt()->GetRootNode(); + assert(asgNode->OperIs(GT_ASG)); + + unsigned lcl = asgNode->gtGetOp1()->AsLclVarCommon()->GetLclNum(); + + while (nextNextBlock->bbJumpKind != BBJ_RETURN) + { + assert(nextNextBlock->firstStmt() == nextNextBlock->lastStmt()); + asgNode = nextNextBlock->firstStmt()->GetRootNode(); + assert(asgNode->OperIs(GT_ASG)); + assert(lcl == asgNode->gtGetOp2()->AsLclVarCommon()->GetLclNum()); + lcl = asgNode->gtGetOp1()->AsLclVarCommon()->GetLclNum(); + nextNextBlock = nextNextBlock->GetUniqueSucc(); + } + } + assert(nextNextBlock->bbJumpKind == BBJ_RETURN); if (nextNextBlock->hasProfileWeight())