Index: lib/Analysis/LoopInfo.cpp =================================================================== --- lib/Analysis/LoopInfo.cpp +++ lib/Analysis/LoopInfo.cpp @@ -376,7 +376,7 @@ /// Find the new parent loop for all blocks within the "unloop" whose last /// backedges has just been removed. class UnloopUpdater { - Loop *Unloop; + Loop &Unloop; LoopInfo *LI; LoopBlocksDFS DFS; @@ -393,7 +393,7 @@ public: UnloopUpdater(Loop *UL, LoopInfo *LInfo) : - Unloop(UL), LI(LInfo), DFS(UL), FoundIB(false) {} + Unloop(*UL), LI(LInfo), DFS(UL), FoundIB(false) {} void updateBlockParents(); @@ -409,7 +409,7 @@ /// Update the parent loop for all blocks that are directly contained within the /// original "unloop". void UnloopUpdater::updateBlockParents() { - if (Unloop->getNumBlocks()) { + if (Unloop.getNumBlocks()) { // Perform a post order CFG traversal of all blocks within this loop, // propagating the nearest loop from sucessors to predecessors. LoopBlocksTraversal Traversal(DFS, LI); @@ -421,14 +421,14 @@ if (NL != L) { // For reducible loops, NL is now an ancestor of Unloop. - assert((NL != Unloop && (!NL || NL->contains(Unloop))) && + assert((NL != &Unloop && (!NL || NL->contains(&Unloop))) && "uninitialized successor"); LI->changeLoopFor(*POI, NL); } else { // Or the current block is part of a subloop, in which case its parent // is unchanged. - assert((FoundIB || Unloop->contains(L)) && "uninitialized successor"); + assert((FoundIB || Unloop.contains(L)) && "uninitialized successor"); } } } @@ -436,7 +436,7 @@ // the DFS result cached by Traversal. bool Changed = FoundIB; for (unsigned NIters = 0; Changed; ++NIters) { - assert(NIters < Unloop->getNumBlocks() && "runaway iterative algorithm"); + assert(NIters < Unloop.getNumBlocks() && "runaway iterative algorithm"); // Iterate over the postorder list of blocks, propagating the nearest loop // from successors to predecessors as before. @@ -447,7 +447,7 @@ Loop *L = LI->getLoopFor(*POI); Loop *NL = getNearestLoop(*POI, L); if (NL != L) { - assert(NL != Unloop && (!NL || NL->contains(Unloop)) && + assert(NL != &Unloop && (!NL || NL->contains(&Unloop)) && "uninitialized successor"); LI->changeLoopFor(*POI, NL); Changed = true; @@ -460,17 +460,17 @@ void UnloopUpdater::removeBlocksFromAncestors() { // Remove all unloop's blocks (including those in nested subloops) from // ancestors below the new parent loop. - for (Loop::block_iterator BI = Unloop->block_begin(), - BE = Unloop->block_end(); BI != BE; ++BI) { + for (Loop::block_iterator BI = Unloop.block_begin(), + BE = Unloop.block_end(); BI != BE; ++BI) { Loop *OuterParent = LI->getLoopFor(*BI); - if (Unloop->contains(OuterParent)) { - while (OuterParent->getParentLoop() != Unloop) + if (Unloop.contains(OuterParent)) { + while (OuterParent->getParentLoop() != &Unloop) OuterParent = OuterParent->getParentLoop(); OuterParent = SubloopParents[OuterParent]; } // Remove blocks from former Ancestors except Unloop itself which will be // deleted. - for (Loop *OldParent = Unloop->getParentLoop(); OldParent != OuterParent; + for (Loop *OldParent = Unloop.getParentLoop(); OldParent != OuterParent; OldParent = OldParent->getParentLoop()) { assert(OldParent && "new loop is not an ancestor of the original"); OldParent->removeBlockFromLoop(*BI); @@ -480,9 +480,9 @@ /// Update the parent loop for all subloops directly nested within unloop. void UnloopUpdater::updateSubloopParents() { - while (!Unloop->empty()) { - Loop *Subloop = *std::prev(Unloop->end()); - Unloop->removeChildLoop(std::prev(Unloop->end())); + while (!Unloop.empty()) { + Loop *Subloop = *std::prev(Unloop.end()); + Unloop.removeChildLoop(std::prev(Unloop.end())); assert(SubloopParents.count(Subloop) && "DFS failed to visit subloop"); if (Loop *Parent = SubloopParents[Subloop]) @@ -504,16 +504,16 @@ Loop *NearLoop = BBLoop; Loop *Subloop = nullptr; - if (NearLoop != Unloop && Unloop->contains(NearLoop)) { + if (NearLoop != &Unloop && Unloop.contains(NearLoop)) { Subloop = NearLoop; // Find the subloop ancestor that is directly contained within Unloop. - while (Subloop->getParentLoop() != Unloop) { + while (Subloop->getParentLoop() != &Unloop) { Subloop = Subloop->getParentLoop(); assert(Subloop && "subloop is not an ancestor of the original loop"); } // Get the current nearest parent of the Subloop exits, initially Unloop. NearLoop = - SubloopParents.insert(std::make_pair(Subloop, Unloop)).first->second; + SubloopParents.insert(std::make_pair(Subloop, &Unloop)).first->second; } succ_iterator I = succ_begin(BB), E = succ_end(BB); @@ -526,33 +526,33 @@ continue; // self loops are uninteresting Loop *L = LI->getLoopFor(*I); - if (L == Unloop) { + if (L == &Unloop) { // This successor has not been processed. This path must lead to an // irreducible backedge. assert((FoundIB || !DFS.hasPostorder(*I)) && "should have seen IB"); FoundIB = true; } - if (L != Unloop && Unloop->contains(L)) { + if (L != &Unloop && Unloop.contains(L)) { // Successor is in a subloop. if (Subloop) continue; // Branching within subloops. Ignore it. // BB branches from the original into a subloop header. - assert(L->getParentLoop() == Unloop && "cannot skip into nested loops"); + assert(L->getParentLoop() == &Unloop && "cannot skip into nested loops"); // Get the current nearest parent of the Subloop's exits. L = SubloopParents[L]; // L could be Unloop if the only exit was an irreducible backedge. } - if (L == Unloop) { + if (L == &Unloop) { continue; } // Handle critical edges from Unloop into a sibling loop. - if (L && !L->contains(Unloop)) { + if (L && !L->contains(&Unloop)) { L = L->getParentLoop(); } // Remember the nearest parent loop among successors or subloop exits. - if (NearLoop == Unloop || !NearLoop || NearLoop->contains(L)) + if (NearLoop == &Unloop || !NearLoop || NearLoop->contains(L)) NearLoop = L; } if (Subloop) { Index: lib/Analysis/ScalarEvolution.cpp =================================================================== --- lib/Analysis/ScalarEvolution.cpp +++ lib/Analysis/ScalarEvolution.cpp @@ -5567,6 +5567,8 @@ if (NumExits == 1) return; + assert(ENT && "ExitNotTakenExtras is NULL while having more than one exit"); + auto &Exits = ExitNotTaken.ExtraInfo->Exits; // Handle the rare case of multiple computable exits.