diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 5c2884cb29659e..d001c984a13f01 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -1659,6 +1659,7 @@ ValueNumStore::Chunk::Chunk(CompAllocator alloc, ValueNum* pNextBaseVN, var_type , m_baseVN(*pNextBaseVN) , m_typ(typ) , m_attribs(attribs) + , m_funcAppElemSize(0) { // Allocate "m_defs" here, according to the typ/attribs pair. switch (attribs) @@ -1747,20 +1748,25 @@ ValueNumStore::Chunk::Chunk(CompAllocator alloc, ValueNum* pNextBaseVN, var_type break; case CEA_Func0: - m_defs = new (alloc) VNFunc[ChunkSize]; + m_defs = new (alloc) VNFunc[ChunkSize]; + m_funcAppElemSize = sizeof(VNDefFuncAppFlexible) + sizeof(ValueNum) * 0; break; case CEA_Func1: - m_defs = alloc.allocate((sizeof(VNDefFuncAppFlexible) + sizeof(ValueNum) * 1) * ChunkSize); + m_funcAppElemSize = sizeof(VNDefFuncAppFlexible) + sizeof(ValueNum) * 1; + m_defs = alloc.allocate(m_funcAppElemSize * ChunkSize); break; case CEA_Func2: - m_defs = alloc.allocate((sizeof(VNDefFuncAppFlexible) + sizeof(ValueNum) * 2) * ChunkSize); + m_funcAppElemSize = sizeof(VNDefFuncAppFlexible) + sizeof(ValueNum) * 2; + m_defs = alloc.allocate(m_funcAppElemSize * ChunkSize); break; case CEA_Func3: - m_defs = alloc.allocate((sizeof(VNDefFuncAppFlexible) + sizeof(ValueNum) * 3) * ChunkSize); + m_funcAppElemSize = sizeof(VNDefFuncAppFlexible) + sizeof(ValueNum) * 3; + m_defs = alloc.allocate(m_funcAppElemSize * ChunkSize); break; case CEA_Func4: - m_defs = alloc.allocate((sizeof(VNDefFuncAppFlexible) + sizeof(ValueNum) * 4) * ChunkSize); + m_funcAppElemSize = sizeof(VNDefFuncAppFlexible) + sizeof(ValueNum) * 4; + m_defs = alloc.allocate(m_funcAppElemSize * ChunkSize); break; default: unreached(); diff --git a/src/coreclr/jit/valuenum.h b/src/coreclr/jit/valuenum.h index 8c75e17935a485..f6f0acd6ccdaf5 100644 --- a/src/coreclr/jit/valuenum.h +++ b/src/coreclr/jit/valuenum.h @@ -1540,6 +1540,10 @@ class ValueNumStore var_types m_typ; ChunkExtraAttribs m_attribs; + // Precomputed element size for func-app chunks (sizeof(VNFunc) + sizeof(ValueNum) * arity). + // Zero for non-func chunks. + unsigned m_funcAppElemSize; + // Initialize a chunk, starting at "*baseVN", for the given "typ", and "attribs", using "alloc" for allocations. // (Increments "*baseVN" by ChunkSize.) Chunk(CompAllocator alloc, ValueNum* baseVN, var_types typ, ChunkExtraAttribs attribs); @@ -1556,9 +1560,8 @@ class ValueNumStore { assert((m_attribs >= CEA_Func0) && (m_attribs <= CEA_Func4)); assert(numArgs == (unsigned)(m_attribs - CEA_Func0)); - static_assert(sizeof(VNDefFuncAppFlexible) == sizeof(VNFunc)); - return reinterpret_cast( - (char*)m_defs + offsetWithinChunk * (sizeof(VNDefFuncAppFlexible) + sizeof(ValueNum) * numArgs)); + assert(m_funcAppElemSize == sizeof(VNDefFuncAppFlexible) + sizeof(ValueNum) * numArgs); + return reinterpret_cast((char*)m_defs + offsetWithinChunk * m_funcAppElemSize); } template