clean code that counts promoted implict byref argument occurrences. (dotnet/coreclr...
authorSergey Andreenko <seandree@microsoft.com>
Mon, 24 Sep 2018 23:03:36 +0000 (16:03 -0700)
committerGitHub <noreply@github.com>
Mon, 24 Sep 2018 23:03:36 +0000 (16:03 -0700)
* clean code that counts promoted implict byref argument occurrences.

Move 3 copies of that code into one in `PreOrderVisit`. Run this check after we have made morph for fields and structs.

Commit migrated from https://github.com/dotnet/coreclr/commit/bcb2a56138685748c5a8c1d8c973ff1a51c81883

src/coreclr/src/jit/morph.cpp

index c2ee5d3..58c25fe 100644 (file)
@@ -17148,20 +17148,6 @@ void Compiler::fgMorphStructField(GenTree* tree, GenTree* parent)
                 unsigned fieldLclIndex = lvaGetFieldLocal(varDsc, fldOffset);
                 noway_assert(fieldLclIndex != BAD_VAR_NUM);
 
-                if (lvaIsImplicitByRefLocal(lclNum))
-                {
-                    // Keep track of the number of appearances of each promoted implicit
-                    // byref (here during struct promotion, which happens during address-exposed
-                    // analysis); fgMakeOutgoingStructArgCopy checks the ref counts for implicit
-                    // byref params when deciding if it's legal to elide certain copies of them.
-                    // This should probably be moved LocalAddressVisitor, which does this already
-                    // for GT_LCL_VAR nodes it encounters.
-                    JITDUMP(
-                        "Incrementing ref count from %d to %d for V%02d in fgMorphStructField for promoted struct\n",
-                        varDsc->lvRefCnt(RCS_EARLY), varDsc->lvRefCnt(RCS_EARLY) + 1, lclNum);
-                    varDsc->incLvRefCnt(1, RCS_EARLY);
-                }
-
                 tree->SetOper(GT_LCL_VAR);
                 tree->gtLclVarCommon.SetLclNum(fieldLclIndex);
                 tree->gtType = lvaTable[fieldLclIndex].TypeGet();
@@ -17236,19 +17222,6 @@ void Compiler::fgMorphStructField(GenTree* tree, GenTree* parent)
 
             if (tree->TypeGet() == obj->TypeGet())
             {
-                if (lvaIsImplicitByRefLocal(lclNum))
-                {
-                    // Keep track of the number of appearances of each promoted implicit
-                    // byref (here during struct promotion, which happens during address-exposed
-                    // analysis); fgMakeOutgoingStructArgCopy checks the ref counts for implicit
-                    // byref params when deciding if it's legal to elide certain copies of them.
-                    // This should probably be moved LocalAddressVisitor, which does this already
-                    // for GT_LCL_VAR nodes it encounters.
-                    JITDUMP("Incrementing ref count from %d to %d for V%02d in fgMorphStructField for normed struct\n",
-                            varDsc->lvRefCnt(RCS_EARLY), varDsc->lvRefCnt(RCS_EARLY) + 1, lclNum);
-                    varDsc->incLvRefCnt(1, RCS_EARLY);
-                }
-
                 tree->ChangeOper(GT_LCL_VAR);
                 tree->gtLclVarCommon.SetLclNum(lclNum);
                 tree->gtFlags &= GTF_NODE_MASK;
@@ -18153,7 +18126,12 @@ public:
         {
             MorphStructField(node, user);
         }
-        else if (node->OperIs(GT_LCL_VAR, GT_LCL_FLD))
+        else if (node->OperIs(GT_LCL_FLD))
+        {
+            MorphLocalField(node, user);
+        }
+
+        if (node->OperIsLocal())
         {
             unsigned lclNum = node->AsLclVarCommon()->GetLclNum();
 
@@ -18168,11 +18146,6 @@ public:
                         varDsc->lvRefCnt(RCS_EARLY), varDsc->lvRefCnt(RCS_EARLY) + 1, lclNum);
                 varDsc->incLvRefCnt(1, RCS_EARLY);
             }
-
-            if (node->OperIs(GT_LCL_FLD))
-            {
-                MorphLocalField(node, user);
-            }
         }
 
         PushValue(node);