Skip to content

Commit 0170d78

Browse files
authored
JIT: Use any reaching def for unreachable uses in incremental SSA builder (#110077)
There really is no correct reaching definition in this case, so any reaching definition will do here. This matches what happens normally in the JIT when various phases optimize control flow after SSA has been built without removing the now-unreachable blocks. Also give unreachable stores an SSA number. Fix #109971
1 parent d86f770 commit 0170d78

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

src/coreclr/jit/optcse.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5114,10 +5114,7 @@ void CSE_HeuristicCommon::ReplaceCSENode(Statement* stmt, GenTree* exp, GenTree*
51145114
//
51155115
void CSE_HeuristicCommon::InsertUseIntoSsa(IncrementalSsaBuilder& ssaBuilder, const UseDefLocation& useDefLoc)
51165116
{
5117-
if (!ssaBuilder.InsertUse(useDefLoc))
5118-
{
5119-
return;
5120-
}
5117+
ssaBuilder.InsertUse(useDefLoc);
51215118

51225119
GenTreeLclVar* lcl = useDefLoc.Tree;
51235120
assert(lcl->HasSsaName());

src/coreclr/jit/ssabuilder.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,13 +1737,11 @@ bool IncrementalSsaBuilder::FinalizeDefs()
17371737
for (int i = 0; i < m_defs.Height(); i++)
17381738
{
17391739
UseDefLocation& def = m_defs.BottomRef(i);
1740-
if (!m_comp->m_dfsTree->Contains(def.Block))
1740+
if (m_comp->m_dfsTree->Contains(def.Block))
17411741
{
1742-
continue;
1742+
BitVecOps::AddElemD(&m_poTraits, m_defBlocks, def.Block->bbPostorderNum);
17431743
}
17441744

1745-
BitVecOps::AddElemD(&m_poTraits, m_defBlocks, def.Block->bbPostorderNum);
1746-
17471745
unsigned ssaNum = dsc->lvPerSsaData.AllocSsaNum(m_comp->getAllocator(CMK_SSA), def.Block, def.Tree);
17481746
def.Tree->SetSsaNum(ssaNum);
17491747
LclSsaVarDsc* ssaDsc = dsc->GetPerSsaData(ssaNum);
@@ -1763,17 +1761,13 @@ bool IncrementalSsaBuilder::FinalizeDefs()
17631761
// Parameters:
17641762
// use - Location of the use
17651763
//
1766-
// Returns:
1767-
// True if the use was in a reachable block and thus has a reaching def;
1768-
// otherwise false.
1769-
//
17701764
// Remarks:
17711765
// All uses are required to never read an uninitialized value of the local.
17721766
// That is, this function requires that all paths through the function go
17731767
// through one of the defs in "defs" before any use in "uses" for uses that
17741768
// are statically reachable.
17751769
//
1776-
bool IncrementalSsaBuilder::InsertUse(const UseDefLocation& use)
1770+
void IncrementalSsaBuilder::InsertUse(const UseDefLocation& use)
17771771
{
17781772
assert(m_finalizedDefs);
17791773

@@ -1788,11 +1782,14 @@ bool IncrementalSsaBuilder::InsertUse(const UseDefLocation& use)
17881782
{
17891783
if (!m_comp->m_dfsTree->Contains(use.Block))
17901784
{
1791-
JITDUMP(" Use is in unreachable block " FMT_BB "\n", use.Block->bbNum);
1792-
return false;
1785+
reachingDef = m_defs.Bottom(0);
1786+
JITDUMP(" Use is in unreachable block " FMT_BB ", using first def [%06u] in " FMT_BB "\n",
1787+
use.Block->bbNum, Compiler::dspTreeID(reachingDef.Tree), reachingDef.Block->bbNum);
1788+
}
1789+
else
1790+
{
1791+
reachingDef = FindOrCreateReachingDef(use);
17931792
}
1794-
1795-
reachingDef = FindOrCreateReachingDef(use);
17961793
}
17971794

17981795
JITDUMP(" Reaching def is [%06u] d:%d\n", Compiler::dspTreeID(reachingDef.Tree), reachingDef.Tree->GetSsaNum());
@@ -1802,5 +1799,4 @@ bool IncrementalSsaBuilder::InsertUse(const UseDefLocation& use)
18021799

18031800
LclVarDsc* dsc = m_comp->lvaGetDesc(m_lclNum);
18041801
dsc->GetPerSsaData(reachingDef.Tree->GetSsaNum())->AddUse(use.Block);
1805-
return true;
18061802
}

src/coreclr/jit/ssabuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,5 @@ class IncrementalSsaBuilder
151151

152152
void InsertDef(const UseDefLocation& def);
153153
bool FinalizeDefs();
154-
bool InsertUse(const UseDefLocation& use);
154+
void InsertUse(const UseDefLocation& use);
155155
};

0 commit comments

Comments
 (0)