diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index ea02025450b39a..23147d1d101f74 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -19887,14 +19887,38 @@ void GenTreeArrAddr::ParseArrayAddress(Compiler* comp, GenTree** pArr, ValueNum* ValueNum vn = comp->GetValueNumStore()->VNLiberalNormalValue(tree->gtVNPair); VNFuncApp vnf; + bool treeIsArrayRef = false; + if (tree->TypeIs(TYP_REF) || comp->GetValueNumStore()->IsVNNewArr(vn, &vnf)) { // This must be the array pointer. assert(*pArr == nullptr); *pArr = tree; assert(inputMul == 1); // Can't multiply the array pointer by anything. + treeIsArrayRef = true; } - else + else if (tree->OperIs(GT_LCL_VAR) && tree->TypeIs(TYP_BYREF, TYP_I_IMPL)) + { + // This is sort of like gtGetClassHandle, but that requires TYP_REF + // + CORINFO_CLASS_HANDLE hnd = comp->lvaGetDesc(tree->AsLclVar())->lvClassHnd; + + if (hnd != NO_CLASS_HANDLE) + { + DWORD attribs = comp->info.compCompHnd->getClassAttribs(hnd); + treeIsArrayRef = (attribs & CORINFO_FLG_ARRAY) != 0; + + if (treeIsArrayRef) + { + // This must be the array pointer. + assert(*pArr == nullptr); + *pArr = tree; + assert(inputMul == 1); // Can't multiply the array pointer by anything. + } + } + } + + if (!treeIsArrayRef) { switch (tree->OperGet()) {