From f7ccb60e71e87f2bf79f4c2eac26fa63202aaabd Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Fri, 22 Nov 2024 10:35:44 +0100 Subject: [PATCH] JIT: Use any reaching def for unreachable uses Fix #109971 --- src/coreclr/jit/ssabuilder.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/coreclr/jit/ssabuilder.cpp b/src/coreclr/jit/ssabuilder.cpp index 8f4561ecfc8660..3697ebc0bdf8fc 100644 --- a/src/coreclr/jit/ssabuilder.cpp +++ b/src/coreclr/jit/ssabuilder.cpp @@ -1737,13 +1737,11 @@ bool IncrementalSsaBuilder::FinalizeDefs() for (int i = 0; i < m_defs.Height(); i++) { UseDefLocation& def = m_defs.BottomRef(i); - if (!m_comp->m_dfsTree->Contains(def.Block)) + if (m_comp->m_dfsTree->Contains(def.Block)) { - continue; + BitVecOps::AddElemD(&m_poTraits, m_defBlocks, def.Block->bbPostorderNum); } - BitVecOps::AddElemD(&m_poTraits, m_defBlocks, def.Block->bbPostorderNum); - unsigned ssaNum = dsc->lvPerSsaData.AllocSsaNum(m_comp->getAllocator(CMK_SSA), def.Block, def.Tree); def.Tree->SetSsaNum(ssaNum); LclSsaVarDsc* ssaDsc = dsc->GetPerSsaData(ssaNum); @@ -1788,11 +1786,14 @@ bool IncrementalSsaBuilder::InsertUse(const UseDefLocation& use) { if (!m_comp->m_dfsTree->Contains(use.Block)) { - JITDUMP(" Use is in unreachable block " FMT_BB "\n", use.Block->bbNum); - return false; + reachingDef = m_defs.Bottom(0); + JITDUMP(" Use is in unreachable block " FMT_BB ", using first def [%06u] in " FMT_BB "\n", + use.Block->bbNum, Compiler::dspTreeID(reachingDef.Tree), reachingDef.Block->bbNum); + } + else + { + reachingDef = FindOrCreateReachingDef(use); } - - reachingDef = FindOrCreateReachingDef(use); } JITDUMP(" Reaching def is [%06u] d:%d\n", Compiler::dspTreeID(reachingDef.Tree), reachingDef.Tree->GetSsaNum());