diff --git a/src/jit/flowgraph.cpp b/src/jit/flowgraph.cpp index 7790363f94b3..d6afead366b5 100644 --- a/src/jit/flowgraph.cpp +++ b/src/jit/flowgraph.cpp @@ -22625,13 +22625,10 @@ GenTreePtr Compiler::fgInlinePrependStatements(InlineInfo* inlineInfo) impAssignTempGen(tmpNum, argNode, structHnd, (unsigned)CHECK_SPILL_NONE, &afterStmt, callILOffset, block); - // If we know the argument's value can't be - // changed within the method body, try and improve - // the type of the temp. - if (argIsSingleDef && (argType == TYP_REF)) - { - lvaUpdateClass(tmpNum, argNode); - } + // We used to refine the temp type here based on + // the actual arg, but we now do this up front, when + // creating the temp, over in impInlineFetchArg. + CLANG_FORMAT_COMMENT_ANCHOR; #ifdef DEBUG if (verbose) diff --git a/src/jit/importer.cpp b/src/jit/importer.cpp index 46ca8ff16b31..b824e6b71e82 100644 --- a/src/jit/importer.cpp +++ b/src/jit/importer.cpp @@ -18165,11 +18165,22 @@ GenTreePtr Compiler::impInlineFetchArg(unsigned lclNum, InlArgInfo* inlArgInfo, lvaTable[tmpNum].lvType = lclTyp; - // Copy over class handle for ref types. Note this may be - // further improved if it is a shared type and we know the exact context. + // For ref types, determine the type of the temp. if (lclTyp == TYP_REF) { - lvaSetClass(tmpNum, lclInfo.lclVerTypeInfo.GetClassHandleForObjRef()); + if (!argCanBeModified) + { + // If the arg can't be modified in the method + // body, use the type of the value, if + // known. Otherwise, use the declared type. + lvaSetClass(tmpNum, argInfo.argNode, lclInfo.lclVerTypeInfo.GetClassHandleForObjRef()); + } + else + { + // Arg might be modified, use the delcared type of + // the argument. + lvaSetClass(tmpNum, lclInfo.lclVerTypeInfo.GetClassHandleForObjRef()); + } } assert(lvaTable[tmpNum].lvAddrExposed == 0);