diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 2d0d108a3349c..6d7f8c7bc6fdc 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -5509,8 +5509,16 @@ GenTree* Compiler::fgMorphArrayIndex(GenTree* tree) fgSetRngChkTarget(indexAddr); } - // Change `tree` into an indirection and return. - tree->ChangeOper(GT_IND); + if (!tree->TypeIs(TYP_STRUCT)) + { + tree->ChangeOper(GT_IND); + } + else + { + DEBUG_DESTROY_NODE(tree); + tree = gtNewObjNode(elemStructType, indexAddr); + INDEBUG(tree->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED); + } GenTreeIndir* const indir = tree->AsIndir(); indir->Addr() = indexAddr; bool canCSE = indir->CanCSE(); @@ -5520,9 +5528,7 @@ GenTree* Compiler::fgMorphArrayIndex(GenTree* tree) indir->SetDoNotCSE(); } -#ifdef DEBUG - indexAddr->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED; -#endif // DEBUG + INDEBUG(indexAddr->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED); return indir; }