Skip to content

Commit abe6b9e

Browse files
authored
JIT: generalize ParseArrayAddress a bit more (#112527)
Now that we are stack allocating arrays, the array reference may be either TYP_BYREF or TYP_I_IMPL, so try and recognize those cases when possible. In particular for OSR methods the array allocation may "disappear" once we redirect flow to the OSR entry, so relying on VN is insufficient. Fixes #112429 (benchmark regression where we're measuring OSR code)
1 parent 3aaffd0 commit abe6b9e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/coreclr/jit/gentree.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19887,14 +19887,38 @@ void GenTreeArrAddr::ParseArrayAddress(Compiler* comp, GenTree** pArr, ValueNum*
1988719887
ValueNum vn = comp->GetValueNumStore()->VNLiberalNormalValue(tree->gtVNPair);
1988819888
VNFuncApp vnf;
1988919889

19890+
bool treeIsArrayRef = false;
19891+
1989019892
if (tree->TypeIs(TYP_REF) || comp->GetValueNumStore()->IsVNNewArr(vn, &vnf))
1989119893
{
1989219894
// This must be the array pointer.
1989319895
assert(*pArr == nullptr);
1989419896
*pArr = tree;
1989519897
assert(inputMul == 1); // Can't multiply the array pointer by anything.
19898+
treeIsArrayRef = true;
1989619899
}
19897-
else
19900+
else if (tree->OperIs(GT_LCL_VAR) && tree->TypeIs(TYP_BYREF, TYP_I_IMPL))
19901+
{
19902+
// This is sort of like gtGetClassHandle, but that requires TYP_REF
19903+
//
19904+
CORINFO_CLASS_HANDLE hnd = comp->lvaGetDesc(tree->AsLclVar())->lvClassHnd;
19905+
19906+
if (hnd != NO_CLASS_HANDLE)
19907+
{
19908+
DWORD attribs = comp->info.compCompHnd->getClassAttribs(hnd);
19909+
treeIsArrayRef = (attribs & CORINFO_FLG_ARRAY) != 0;
19910+
19911+
if (treeIsArrayRef)
19912+
{
19913+
// This must be the array pointer.
19914+
assert(*pArr == nullptr);
19915+
*pArr = tree;
19916+
assert(inputMul == 1); // Can't multiply the array pointer by anything.
19917+
}
19918+
}
19919+
}
19920+
19921+
if (!treeIsArrayRef)
1989819922
{
1989919923
switch (tree->OperGet())
1990019924
{

0 commit comments

Comments
 (0)