@@ -1862,14 +1862,18 @@ bool Compiler::impSpillStackEntry(unsigned level,
18621862    /* Assign the spilled entry to the temp */
18631863    impAssignTempGen(tnum, tree, verCurrentState.esStack[level].seTypeInfo.GetClassHandle(), level);
18641864
1865-     // If temp is newly introduced and a ref type, grab what type info we can.
1866-     if (isNewTemp && (lvaTable[tnum].lvType == TYP_REF))
1865+     if (isNewTemp)
18671866    {
18681867        assert(lvaTable[tnum].lvSingleDef == 0);
18691868        lvaTable[tnum].lvSingleDef = 1;
18701869        JITDUMP("Marked V%02u as a single def temp\n", tnum);
1871-         CORINFO_CLASS_HANDLE stkHnd = verCurrentState.esStack[level].seTypeInfo.GetClassHandle();
1872-         lvaSetClass(tnum, tree, stkHnd);
1870+ 
1871+         // If temp is newly introduced and a ref type, grab what type info we can.
1872+         if (lvaTable[tnum].lvType == TYP_REF)
1873+         {
1874+             CORINFO_CLASS_HANDLE stkHnd = verCurrentState.esStack[level].seTypeInfo.GetClassHandle();
1875+             lvaSetClass(tnum, tree, stkHnd);
1876+         }
18731877
18741878        // If we're assigning a GT_RET_EXPR, note the temp over on the call,
18751879        // so the inliner can use it in case it needs a return spill temp.
@@ -8373,12 +8377,12 @@ void Compiler::impImportBlockCode(BasicBlock* block)
83738377                        impAssignTempGen(tmpNum, op1, tiRetVal.GetClassHandle(), CHECK_SPILL_ALL);
83748378                        var_types type = genActualType(lvaTable[tmpNum].TypeGet());
83758379
8380+                         assert(lvaTable[tmpNum].lvSingleDef == 0);
8381+                         lvaTable[tmpNum].lvSingleDef = 1;
8382+                         JITDUMP("Marked V%02u as a single def local\n", tmpNum);
83768383                        // Propagate type info to the temp from the stack and the original tree
83778384                        if (type == TYP_REF)
83788385                        {
8379-                             assert(lvaTable[tmpNum].lvSingleDef == 0);
8380-                             lvaTable[tmpNum].lvSingleDef = 1;
8381-                             JITDUMP("Marked V%02u as a single def local\n", tmpNum);
83828386                            lvaSetClass(tmpNum, tree, tiRetVal.GetClassHandle());
83838387                        }
83848388
@@ -13582,19 +13586,19 @@ unsigned Compiler::impInlineFetchLocal(unsigned lclNum DEBUGARG(const char* reas
1358213586        lvaTable[tmpNum].lvHasILStoreOp         = inlineeLocal.lclHasStlocOp;
1358313587        lvaTable[tmpNum].lvHasMultipleILStoreOp = inlineeLocal.lclHasMultipleStlocOp;
1358413588
13589+         assert(lvaTable[tmpNum].lvSingleDef == 0);
13590+ 
13591+         lvaTable[tmpNum].lvSingleDef = !inlineeLocal.lclHasMultipleStlocOp && !inlineeLocal.lclHasLdlocaOp;
13592+         if (lvaTable[tmpNum].lvSingleDef)
13593+         {
13594+             JITDUMP("Marked V%02u as a single def temp\n", tmpNum);
13595+         }
13596+ 
1358513597        // Copy over class handle for ref types. Note this may be a
1358613598        // shared type -- someday perhaps we can get the exact
1358713599        // signature and pass in a more precise type.
1358813600        if (lclTyp == TYP_REF)
1358913601        {
13590-             assert(lvaTable[tmpNum].lvSingleDef == 0);
13591- 
13592-             lvaTable[tmpNum].lvSingleDef = !inlineeLocal.lclHasMultipleStlocOp && !inlineeLocal.lclHasLdlocaOp;
13593-             if (lvaTable[tmpNum].lvSingleDef)
13594-             {
13595-                 JITDUMP("Marked V%02u as a single def temp\n", tmpNum);
13596-             }
13597- 
1359813602            lvaSetClass(tmpNum, inlineeLocal.lclVerTypeInfo.GetClassHandleForObjRef());
1359913603        }
1360013604
@@ -13779,20 +13783,21 @@ GenTree* Compiler::impInlineFetchArg(unsigned lclNum, InlArgInfo* inlArgInfo, In
1377913783
1378013784            lvaTable[tmpNum].lvType = lclTyp;
1378113785
13782-             // For ref types, determine the type of the temp.
13783-             if (lclTyp == TYP_REF)
13786+             // If arg can't be modified, mark it as single def.
13787+             // For ref types, determine the class of the arg temp.
13788+             if (!argCanBeModified)
1378413789            {
13785-                 if (!argCanBeModified)
13790+                 assert(lvaTable[tmpNum].lvSingleDef == 0);
13791+                 lvaTable[tmpNum].lvSingleDef = 1;
13792+                 JITDUMP("Marked V%02u as a single def temp\n", tmpNum);
13793+                 if (lclTyp == TYP_REF)
1378613794                {
13787-                     // If the arg can't be modified in the method
13788-                     // body, use the type of the value, if
13789-                     // known. Otherwise, use the declared type.
13790-                     assert(lvaTable[tmpNum].lvSingleDef == 0);
13791-                     lvaTable[tmpNum].lvSingleDef = 1;
13792-                     JITDUMP("Marked V%02u as a single def temp\n", tmpNum);
1379313795                    lvaSetClass(tmpNum, argNode, lclInfo.lclVerTypeInfo.GetClassHandleForObjRef());
1379413796                }
13795-                 else
13797+             }
13798+             else
13799+             {
13800+                 if (lclTyp == TYP_REF)
1379613801                {
1379713802                    // Arg might be modified, use the declared type of
1379813803                    // the argument.
0 commit comments