diff --git a/src/coreclr/jit/promotion.h b/src/coreclr/jit/promotion.h index e24a606f2e3ffa..0efde03da59256 100644 --- a/src/coreclr/jit/promotion.h +++ b/src/coreclr/jit/promotion.h @@ -208,13 +208,13 @@ class Promotion // Class to represent liveness information for a struct local's fields and remainder. class StructDeaths { - BitVec m_deaths; - unsigned m_numFields = 0; + BitVec m_deaths; + AggregateInfo* m_aggregate = nullptr; friend class PromotionLiveness; private: - StructDeaths(BitVec deaths, unsigned numFields) : m_deaths(deaths), m_numFields(numFields) + StructDeaths(BitVec deaths, AggregateInfo* agg) : m_deaths(deaths), m_aggregate(agg) { } diff --git a/src/coreclr/jit/promotionliveness.cpp b/src/coreclr/jit/promotionliveness.cpp index daddd1dba2873c..9791bd08a0d90b 100644 --- a/src/coreclr/jit/promotionliveness.cpp +++ b/src/coreclr/jit/promotionliveness.cpp @@ -808,7 +808,7 @@ StructDeaths PromotionLiveness::GetDeathsForStructLocal(GenTreeLclVarCommon* lcl unsigned lclNum = lcl->GetLclNum(); AggregateInfo* aggInfo = m_aggregates.Lookup(lclNum); - return StructDeaths(aggDeaths, (unsigned)aggInfo->Replacements.size()); + return StructDeaths(aggDeaths, aggInfo); } //------------------------------------------------------------------------ @@ -820,7 +820,13 @@ StructDeaths PromotionLiveness::GetDeathsForStructLocal(GenTreeLclVarCommon* lcl // bool StructDeaths::IsRemainderDying() const { - BitVecTraits traits(1 + m_numFields, nullptr); + if (m_aggregate->UnpromotedMax <= m_aggregate->UnpromotedMin) + { + // No remainder. + return true; + } + + BitVecTraits traits(1 + (unsigned)m_aggregate->Replacements.size(), nullptr); return BitVecOps::IsMember(&traits, m_deaths, 0); } @@ -833,7 +839,9 @@ bool StructDeaths::IsRemainderDying() const // bool StructDeaths::IsReplacementDying(unsigned index) const { - BitVecTraits traits(1 + m_numFields, nullptr); + assert(index < m_aggregate->Replacements.size()); + + BitVecTraits traits(1 + (unsigned)m_aggregate->Replacements.size(), nullptr); return BitVecOps::IsMember(&traits, m_deaths, 1 + index); }