Index: lib/Transforms/Utils/MemorySSA.cpp =================================================================== --- lib/Transforms/Utils/MemorySSA.cpp +++ lib/Transforms/Utils/MemorySSA.cpp @@ -1322,7 +1322,9 @@ // Pop everything that doesn't dominate the current block off the stack, // increment the PopEpoch to account for this. - while (!VersionStack.empty()) { + while (true) { + assert(!VersionStack.empty() && + "Version stack should have liveOnEntry sentinel dominating everything"); BasicBlock *BackBlock = VersionStack.back()->getBlock(); if (DT->dominates(BackBlock, BB)) break; @@ -1330,6 +1332,7 @@ VersionStack.pop_back(); ++PopEpoch; } + for (MemoryAccess &MA : *Accesses) { auto *MU = dyn_cast(&MA); if (!MU) { @@ -1450,20 +1453,13 @@ /// Optimize uses to point to their actual clobbering definitions. void MemorySSA::OptimizeUses::optimizeUses() { - - // We perform a non-recursive top-down dominator tree walk - struct StackInfo { - const DomTreeNode *Node; - DomTreeNode::const_iterator Iter; - }; - SmallVector VersionStack; - SmallVector DomTreeWorklist; DenseMap LocStackInfo; VersionStack.push_back(MSSA->getLiveOnEntryDef()); unsigned long StackEpoch = 1; unsigned long PopEpoch = 1; + // We perform a non-recursive top-down dominator tree walk. for (const auto *DomNode : depth_first(DT->getRootNode())) optimizeUsesInBlock(DomNode->getBlock(), StackEpoch, PopEpoch, VersionStack, LocStackInfo);