Clear defnums and post-order nums in fgResetForSsa
authorJoseph Tremoulet <jotrem@microsoft.com>
Thu, 3 Nov 2016 15:50:05 +0000 (11:50 -0400)
committerJoseph Tremoulet <jotrem@microsoft.com>
Fri, 4 Nov 2016 18:57:09 +0000 (14:57 -0400)
SSA construction will overwrite these annotations, but only for reachable
code.  Clear the annotations in all code in `fgResetForSsa` so that
downstream analysis won't stumble over stale/invalid SSA annotations
in unreachable code.

src/jit/ssabuilder.cpp

index 13486bc..f0ee461 100644 (file)
@@ -118,6 +118,32 @@ void Compiler::fgResetForSsa()
                 blk->bbTreeList->gtPrev = last;
             }
         }
+
+        // Clear post-order numbers and SSA numbers; SSA construction will overwrite these,
+        // but only for reachable code, so clear them to avoid analysis getting confused
+        // by stale annotations in unreachable code.
+        blk->bbPostOrderNum = 0;
+        for (GenTreeStmt* stmt = blk->firstStmt(); stmt != nullptr; stmt = stmt->getNextStmt())
+        {
+            for (GenTreePtr tree = stmt->gtStmt.gtStmtList; tree != nullptr; tree = tree->gtNext)
+            {
+                if (tree->IsLocal())
+                {
+                    tree->gtLclVarCommon.SetSsaNum(SsaConfig::RESERVED_SSA_NUM);
+                    continue;
+                }
+
+                Compiler::IndirectAssignmentAnnotation* pIndirAssign = nullptr;
+                if ((tree->OperGet() != GT_ASG) || !GetIndirAssignMap()->Lookup(tree, &pIndirAssign) ||
+                    (pIndirAssign == nullptr))
+                {
+                    continue;
+                }
+
+                pIndirAssign->m_defSsaNum = SsaConfig::RESERVED_SSA_NUM;
+                pIndirAssign->m_useSsaNum = SsaConfig::RESERVED_SSA_NUM;
+            }
+        }
     }
 }