Change gtFindLink to return parent as well.
authorSergey Andreenko <seandree@microsoft.com>
Thu, 25 Apr 2019 23:05:51 +0000 (16:05 -0700)
committerSergey Andreenko <seandree@microsoft.com>
Thu, 25 Apr 2019 23:45:03 +0000 (16:45 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/332bd2ec8a6bad66e1fb9b2dc3cf37e9e4d77727

src/coreclr/src/jit/assertionprop.cpp
src/coreclr/src/jit/compiler.h
src/coreclr/src/jit/gentree.cpp
src/coreclr/src/jit/optcse.cpp

index cd1b90f..3d5e0ed 100644 (file)
@@ -3901,7 +3901,8 @@ GenTree* Compiler::optAssertionProp_Update(GenTree* newTree, GenTree* tree, GenT
         // locate our parent node and update it so that it points to newTree.
         if (newTree != tree)
         {
-            GenTree** link = gtFindLink(stmt, tree);
+            FindLinkData linkData = gtFindLink(stmt, tree);
+            GenTree**    link     = linkData.result;
             noway_assert(link != nullptr);
 
             // Replace the old operand with the newTree
index b091c92..fed7003 100644 (file)
@@ -2994,7 +2994,14 @@ public:
     static fgWalkPreFn gtMarkColonCond;
     static fgWalkPreFn gtClearColonCond;
 
-    GenTree** gtFindLink(GenTreeStmt* stmt, GenTree* node);
+    struct FindLinkData
+    {
+        GenTree*  nodeToFind;
+        GenTree** result;
+        GenTree*  parent;
+    };
+
+    FindLinkData gtFindLink(GenTreeStmt* stmt, GenTree* node);
     bool gtHasCatchArg(GenTree* tree);
 
     typedef ArrayStack<GenTree*> GenTreeStack;
index 5be0160..f5a7982 100644 (file)
@@ -7948,6 +7948,9 @@ GenTree* Compiler::gtGetThisArg(GenTreeCall* call)
             fgArgTabEntry* thisArgTabEntry = gtArgEntryByArgNum(call, argNum);
             GenTree*       result          = thisArgTabEntry->node;
 
+            // Assert if we used DEBUG_DESTROY_NODE.
+            assert(result->gtOper != GT_COUNT);
+
 #if !FEATURE_FIXED_OUT_ARGS && defined(DEBUG)
             // Check that call->fgArgInfo used in gtArgEntryByArgNum was not
             // left outdated by assertion propogation updates.
@@ -7972,6 +7975,7 @@ GenTree* Compiler::gtGetThisArg(GenTreeCall* call)
                 index++;
             }
 #endif // !FEATURE_FIXED_OUT_ARGS && defined(DEBUG)
+
             return result;
         }
     }
@@ -15162,42 +15166,37 @@ Compiler::fgWalkResult Compiler::gtClearColonCond(GenTree** pTree, fgWalkData* d
     return WALK_CONTINUE;
 }
 
-struct FindLinkData
-{
-    GenTree*  nodeToFind;
-    GenTree** result;
-};
-
 /*****************************************************************************
  *
  *  Callback used by the tree walker to implement fgFindLink()
  */
 static Compiler::fgWalkResult gtFindLinkCB(GenTree** pTree, Compiler::fgWalkData* cbData)
 {
-    FindLinkData* data = (FindLinkData*)cbData->pCallbackData;
+    Compiler::FindLinkData* data = (Compiler::FindLinkData*)cbData->pCallbackData;
     if (*pTree == data->nodeToFind)
     {
         data->result = pTree;
+        data->parent = cbData->parent;
         return Compiler::WALK_ABORT;
     }
 
     return Compiler::WALK_CONTINUE;
 }
 
-GenTree** Compiler::gtFindLink(GenTreeStmt* stmt, GenTree* node)
+Compiler::FindLinkData Compiler::gtFindLink(GenTreeStmt* stmt, GenTree* node)
 {
-    FindLinkData data = {node, nullptr};
+    FindLinkData data = {node, nullptr, nullptr};
 
     fgWalkResult result = fgWalkTreePre(&stmt->gtStmtExpr, gtFindLinkCB, &data);
 
     if (result == WALK_ABORT)
     {
         assert(data.nodeToFind == *data.result);
-        return data.result;
+        return data;
     }
     else
     {
-        return nullptr;
+        return {node, nullptr, nullptr};
     }
 }
 
index 3178932..d813fdd 100644 (file)
@@ -2364,7 +2364,8 @@ public:
             // Walk the statement 'stmt' and find the pointer
             // in the tree is pointing to 'exp'
             //
-            GenTree** link = m_pCompiler->gtFindLink(stmt, exp);
+            Compiler::FindLinkData linkData = m_pCompiler->gtFindLink(stmt, exp);
+            GenTree**              link     = linkData.result;
 
 #ifdef DEBUG
             if (link == nullptr)