Skip to content

Commit

Permalink
JIT: tail merge returns with multiple statements (#109670)
Browse files Browse the repository at this point in the history
Remove the restriction that a mergeable return have one statement.

But don't split tail calls away from a same-block return.
  • Loading branch information
AndyAyersMS authored Nov 11, 2024
1 parent a7c6ff7 commit 1ddfa14
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6501,10 +6501,21 @@ PhaseStatus Compiler::fgHeadTailMerge(bool early)
{
iterateTailMerge(block);

// TODO: consider removing hasSingleStmt(), it should find more opportunities
// (with size and TP regressions)
if (block->KindIs(BBJ_RETURN) && block->hasSingleStmt() && (block != genReturnBB))
if (block->KindIs(BBJ_RETURN) && !block->isEmpty() && (block != genReturnBB))
{
// Avoid spitting a return away from a possible tail call
//
if (!block->hasSingleStmt())
{
Statement* const lastStmt = block->lastStmt();
Statement* const prevStmt = lastStmt->GetPrevStmt();
GenTree* const prevTree = prevStmt->GetRootNode();
if (prevTree->IsCall() && prevTree->AsCall()->CanTailCall())
{
continue;
}
}

retBlocks.Push(block);
}
}
Expand Down

0 comments on commit 1ddfa14

Please sign in to comment.