Skip to content

Commit d596037

Browse files
committed
JIT: fix liveness in throw helper blocks
PR dotnet#123781 changed things so that throw helper blocks are now created just after lower. Because of this they no longer get the special liveness update for unreachable blocks. Add this update in explicitly when the blocks are created. Fixes dotnet#123929
1 parent d78c24c commit d596037

3 files changed

Lines changed: 34 additions & 16 deletions

File tree

src/coreclr/jit/compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6792,6 +6792,7 @@ class Compiler
67926792
AddCodeDsc* fgGetExcptnTarget(SpecialCodeKind kind, BasicBlock* fromBlock, bool createIfNeeded = false);
67936793
bool fgUseThrowHelperBlocks();
67946794
void fgCreateThrowHelperBlockCode(AddCodeDsc* add);
6795+
void fgSetThrowHelpBlockLiveness(BasicBlock* block);
67956796
void fgSequenceLocals(Statement* stmt);
67966797

67976798
private:

src/coreclr/jit/flowgraph.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3492,6 +3492,10 @@ void Compiler::fgCreateThrowHelperBlock(AddCodeDsc* add)
34923492
//
34933493
add->acdDstBlk = newBlk;
34943494

3495+
// Set up liveness
3496+
//
3497+
fgSetThrowHelpBlockLiveness(newBlk);
3498+
34953499
#ifdef DEBUG
34963500
if (verbose)
34973501
{

src/coreclr/jit/liveness.cpp

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,22 +1472,7 @@ void Liveness<TLiveness>::DoLiveVarAnalysis()
14721472
continue;
14731473
}
14741474

1475-
VarSetOps::ClearD(m_compiler, block->bbLiveOut);
1476-
if (keepAliveThis)
1477-
{
1478-
unsigned thisVarIndex = m_compiler->lvaGetDesc(m_compiler->info.compThisArg)->lvVarIndex;
1479-
VarSetOps::AddElemD(m_compiler, block->bbLiveOut, thisVarIndex);
1480-
}
1481-
1482-
if (block->HasPotentialEHSuccs(m_compiler))
1483-
{
1484-
block->VisitEHSuccs(m_compiler, [=](BasicBlock* succ) {
1485-
VarSetOps::UnionD(m_compiler, block->bbLiveOut, succ->bbLiveIn);
1486-
return BasicBlockVisit::Continue;
1487-
});
1488-
}
1489-
1490-
VarSetOps::Assign(m_compiler, block->bbLiveIn, block->bbLiveOut);
1475+
m_compiler->fgSetThrowHelpBlockLiveness(block);
14911476
}
14921477
}
14931478

@@ -1615,6 +1600,34 @@ void Compiler::fgAddHandlerLiveVars(BasicBlock* block, VARSET_TP& ehHandlerLiveV
16151600
});
16161601
}
16171602

1603+
//------------------------------------------------------------------------
1604+
// fgSetThrowHelpBlockLiveness: set liveness for throw helper block
1605+
//
1606+
// Arguments:
1607+
// block -- potential throw helper block
1608+
//
1609+
void Compiler::fgSetThrowHelpBlockLiveness(BasicBlock* block)
1610+
{
1611+
VarSetOps::ClearD(this, block->bbLiveOut);
1612+
1613+
const bool keepAliveThis = lvaKeepAliveAndReportThis() && lvaTable[info.compThisArg].lvTracked;
1614+
if (keepAliveThis)
1615+
{
1616+
unsigned thisVarIndex = lvaGetDesc(info.compThisArg)->lvVarIndex;
1617+
VarSetOps::AddElemD(this, block->bbLiveOut, thisVarIndex);
1618+
}
1619+
1620+
if (block->HasPotentialEHSuccs(this))
1621+
{
1622+
block->VisitEHSuccs(this, [=](BasicBlock* succ) {
1623+
VarSetOps::UnionD(this, block->bbLiveOut, succ->bbLiveIn);
1624+
return BasicBlockVisit::Continue;
1625+
});
1626+
}
1627+
1628+
VarSetOps::Assign(this, block->bbLiveIn, block->bbLiveOut);
1629+
}
1630+
16181631
#ifdef DEBUG
16191632

16201633
void Compiler::fgDispBBLiveness()

0 commit comments

Comments
 (0)