Skip to content

Commit

Permalink
JIT: Ensure tail merging does not add preds to scratch block (#84353)
Browse files Browse the repository at this point in the history
Fix issue seen in #83388 where tail merging ended up adding new
predecessors to the scratch block, making adding more "initialization
IR" impossible for downstream phases.
  • Loading branch information
jakobbotsch committed Apr 5, 2023
1 parent da7fbb7 commit 30f7511
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6886,8 +6886,8 @@ PhaseStatus Compiler::fgTailMerge()
JITDUMP("A set of %d preds of " FMT_BB " end with the same tree\n", matchedPredInfo.Height(), block->bbNum);
JITDUMPEXEC(gtDispStmt(matchedPredInfo.TopRef(0).m_stmt));

BasicBlock* crossJumpVictim = matchedPredInfo.TopRef(0).m_block;
Statement* crossJumpStmt = matchedPredInfo.TopRef(0).m_stmt;
BasicBlock* crossJumpVictim = nullptr;
Statement* crossJumpStmt = nullptr;
bool haveNoSplitVictim = false;
bool haveFallThroughVictim = false;

Expand All @@ -6897,14 +6897,26 @@ PhaseStatus Compiler::fgTailMerge()
Statement* const stmt = info.m_stmt;
BasicBlock* const predBlock = info.m_block;

// Never pick the scratch block as the victim as that would
// cause us to add a predecessor to it, which is invalid.
if (fgBBisScratch(predBlock))
{
continue;
}

bool const isNoSplit = stmt == predBlock->firstStmt();
bool const isFallThrough = (predBlock->bbJumpKind == BBJ_NONE);

// Is this block possibly better than what we have?
//
bool useBlock = false;

if (isNoSplit && isFallThrough)
if (crossJumpVictim == nullptr)
{
// Pick an initial candidate.
useBlock = true;
}
else if (isNoSplit && isFallThrough)
{
// This is the ideal choice.
//
Expand Down

0 comments on commit 30f7511

Please sign in to comment.