LLVM API Documentation

LoopUnroll.cpp
Go to the documentation of this file.
00001 //===-- UnrollLoop.cpp - Loop unrolling utilities -------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements some loop unrolling utilities. It does not define any
00011 // actual pass or policy, but provides a single function to perform loop
00012 // unrolling.
00013 //
00014 // The process of unrolling can produce extraneous basic blocks linked with
00015 // unconditional branches.  This will be corrected in the future.
00016 //
00017 //===----------------------------------------------------------------------===//
00018 
00019 #include "llvm/Transforms/Utils/UnrollLoop.h"
00020 #include "llvm/ADT/SmallPtrSet.h"
00021 #include "llvm/ADT/Statistic.h"
00022 #include "llvm/Analysis/AssumptionCache.h"
00023 #include "llvm/Analysis/InstructionSimplify.h"
00024 #include "llvm/Analysis/LoopIterator.h"
00025 #include "llvm/Analysis/LoopPass.h"
00026 #include "llvm/Analysis/ScalarEvolution.h"
00027 #include "llvm/IR/BasicBlock.h"
00028 #include "llvm/IR/DataLayout.h"
00029 #include "llvm/IR/Dominators.h"
00030 #include "llvm/IR/DiagnosticInfo.h"
00031 #include "llvm/IR/LLVMContext.h"
00032 #include "llvm/Support/Debug.h"
00033 #include "llvm/Support/raw_ostream.h"
00034 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
00035 #include "llvm/Transforms/Utils/Cloning.h"
00036 #include "llvm/Transforms/Utils/Local.h"
00037 #include "llvm/Transforms/Utils/LoopUtils.h"
00038 #include "llvm/Transforms/Utils/SimplifyIndVar.h"
00039 using namespace llvm;
00040 
00041 #define DEBUG_TYPE "loop-unroll"
00042 
00043 // TODO: Should these be here or in LoopUnroll?
00044 STATISTIC(NumCompletelyUnrolled, "Number of loops completely unrolled");
00045 STATISTIC(NumUnrolled, "Number of loops unrolled (completely or otherwise)");
00046 
00047 /// RemapInstruction - Convert the instruction operands from referencing the
00048 /// current values into those specified by VMap.
00049 static inline void RemapInstruction(Instruction *I,
00050                                     ValueToValueMapTy &VMap) {
00051   for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
00052     Value *Op = I->getOperand(op);
00053     ValueToValueMapTy::iterator It = VMap.find(Op);
00054     if (It != VMap.end())
00055       I->setOperand(op, It->second);
00056   }
00057 
00058   if (PHINode *PN = dyn_cast<PHINode>(I)) {
00059     for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
00060       ValueToValueMapTy::iterator It = VMap.find(PN->getIncomingBlock(i));
00061       if (It != VMap.end())
00062         PN->setIncomingBlock(i, cast<BasicBlock>(It->second));
00063     }
00064   }
00065 }
00066 
00067 /// FoldBlockIntoPredecessor - Folds a basic block into its predecessor if it
00068 /// only has one predecessor, and that predecessor only has one successor.
00069 /// The LoopInfo Analysis that is passed will be kept consistent.  If folding is
00070 /// successful references to the containing loop must be removed from
00071 /// ScalarEvolution by calling ScalarEvolution::forgetLoop because SE may have
00072 /// references to the eliminated BB.  The argument ForgottenLoops contains a set
00073 /// of loops that have already been forgotten to prevent redundant, expensive
00074 /// calls to ScalarEvolution::forgetLoop.  Returns the new combined block.
00075 static BasicBlock *
00076 FoldBlockIntoPredecessor(BasicBlock *BB, LoopInfo* LI, LPPassManager *LPM,
00077                          SmallPtrSetImpl<Loop *> &ForgottenLoops) {
00078   // Merge basic blocks into their predecessor if there is only one distinct
00079   // pred, and if there is only one distinct successor of the predecessor, and
00080   // if there are no PHI nodes.
00081   BasicBlock *OnlyPred = BB->getSinglePredecessor();
00082   if (!OnlyPred) return nullptr;
00083 
00084   if (OnlyPred->getTerminator()->getNumSuccessors() != 1)
00085     return nullptr;
00086 
00087   DEBUG(dbgs() << "Merging: " << *BB << "into: " << *OnlyPred);
00088 
00089   // Resolve any PHI nodes at the start of the block.  They are all
00090   // guaranteed to have exactly one entry if they exist, unless there are
00091   // multiple duplicate (but guaranteed to be equal) entries for the
00092   // incoming edges.  This occurs when there are multiple edges from
00093   // OnlyPred to OnlySucc.
00094   FoldSingleEntryPHINodes(BB);
00095 
00096   // Delete the unconditional branch from the predecessor...
00097   OnlyPred->getInstList().pop_back();
00098 
00099   // Make all PHI nodes that referred to BB now refer to Pred as their
00100   // source...
00101   BB->replaceAllUsesWith(OnlyPred);
00102 
00103   // Move all definitions in the successor to the predecessor...
00104   OnlyPred->getInstList().splice(OnlyPred->end(), BB->getInstList());
00105 
00106   // OldName will be valid until erased.
00107   StringRef OldName = BB->getName();
00108 
00109   // Erase basic block from the function...
00110 
00111   // ScalarEvolution holds references to loop exit blocks.
00112   if (LPM) {
00113     if (ScalarEvolution *SE = LPM->getAnalysisIfAvailable<ScalarEvolution>()) {
00114       if (Loop *L = LI->getLoopFor(BB)) {
00115         if (ForgottenLoops.insert(L).second)
00116           SE->forgetLoop(L);
00117       }
00118     }
00119   }
00120   LI->removeBlock(BB);
00121 
00122   // Inherit predecessor's name if it exists...
00123   if (!OldName.empty() && !OnlyPred->hasName())
00124     OnlyPred->setName(OldName);
00125 
00126   BB->eraseFromParent();
00127 
00128   return OnlyPred;
00129 }
00130 
00131 /// Unroll the given loop by Count. The loop must be in LCSSA form. Returns true
00132 /// if unrolling was successful, or false if the loop was unmodified. Unrolling
00133 /// can only fail when the loop's latch block is not terminated by a conditional
00134 /// branch instruction. However, if the trip count (and multiple) are not known,
00135 /// loop unrolling will mostly produce more code that is no faster.
00136 ///
00137 /// TripCount is generally defined as the number of times the loop header
00138 /// executes. UnrollLoop relaxes the definition to permit early exits: here
00139 /// TripCount is the iteration on which control exits LatchBlock if no early
00140 /// exits were taken. Note that UnrollLoop assumes that the loop counter test
00141 /// terminates LatchBlock in order to remove unnecesssary instances of the
00142 /// test. In other words, control may exit the loop prior to TripCount
00143 /// iterations via an early branch, but control may not exit the loop from the
00144 /// LatchBlock's terminator prior to TripCount iterations.
00145 ///
00146 /// Similarly, TripMultiple divides the number of times that the LatchBlock may
00147 /// execute without exiting the loop.
00148 ///
00149 /// The LoopInfo Analysis that is passed will be kept consistent.
00150 ///
00151 /// If a LoopPassManager is passed in, and the loop is fully removed, it will be
00152 /// removed from the LoopPassManager as well. LPM can also be NULL.
00153 ///
00154 /// This utility preserves LoopInfo. If DominatorTree or ScalarEvolution are
00155 /// available from the Pass it must also preserve those analyses.
00156 bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount,
00157                       bool AllowRuntime, unsigned TripMultiple, LoopInfo *LI,
00158                       Pass *PP, LPPassManager *LPM, AssumptionCache *AC) {
00159   BasicBlock *Preheader = L->getLoopPreheader();
00160   if (!Preheader) {
00161     DEBUG(dbgs() << "  Can't unroll; loop preheader-insertion failed.\n");
00162     return false;
00163   }
00164 
00165   BasicBlock *LatchBlock = L->getLoopLatch();
00166   if (!LatchBlock) {
00167     DEBUG(dbgs() << "  Can't unroll; loop exit-block-insertion failed.\n");
00168     return false;
00169   }
00170 
00171   // Loops with indirectbr cannot be cloned.
00172   if (!L->isSafeToClone()) {
00173     DEBUG(dbgs() << "  Can't unroll; Loop body cannot be cloned.\n");
00174     return false;
00175   }
00176 
00177   BasicBlock *Header = L->getHeader();
00178   BranchInst *BI = dyn_cast<BranchInst>(LatchBlock->getTerminator());
00179 
00180   if (!BI || BI->isUnconditional()) {
00181     // The loop-rotate pass can be helpful to avoid this in many cases.
00182     DEBUG(dbgs() <<
00183              "  Can't unroll; loop not terminated by a conditional branch.\n");
00184     return false;
00185   }
00186 
00187   if (Header->hasAddressTaken()) {
00188     // The loop-rotate pass can be helpful to avoid this in many cases.
00189     DEBUG(dbgs() <<
00190           "  Won't unroll loop: address of header block is taken.\n");
00191     return false;
00192   }
00193 
00194   if (TripCount != 0)
00195     DEBUG(dbgs() << "  Trip Count = " << TripCount << "\n");
00196   if (TripMultiple != 1)
00197     DEBUG(dbgs() << "  Trip Multiple = " << TripMultiple << "\n");
00198 
00199   // Effectively "DCE" unrolled iterations that are beyond the tripcount
00200   // and will never be executed.
00201   if (TripCount != 0 && Count > TripCount)
00202     Count = TripCount;
00203 
00204   // Don't enter the unroll code if there is nothing to do. This way we don't
00205   // need to support "partial unrolling by 1".
00206   if (TripCount == 0 && Count < 2)
00207     return false;
00208 
00209   assert(Count > 0);
00210   assert(TripMultiple > 0);
00211   assert(TripCount == 0 || TripCount % TripMultiple == 0);
00212 
00213   // Are we eliminating the loop control altogether?
00214   bool CompletelyUnroll = Count == TripCount;
00215 
00216   // We assume a run-time trip count if the compiler cannot
00217   // figure out the loop trip count and the unroll-runtime
00218   // flag is specified.
00219   bool RuntimeTripCount = (TripCount == 0 && Count > 0 && AllowRuntime);
00220 
00221   if (RuntimeTripCount && !UnrollRuntimeLoopProlog(L, Count, LI, LPM))
00222     return false;
00223 
00224   // Notify ScalarEvolution that the loop will be substantially changed,
00225   // if not outright eliminated.
00226   ScalarEvolution *SE =
00227       PP ? PP->getAnalysisIfAvailable<ScalarEvolution>() : nullptr;
00228   if (SE)
00229     SE->forgetLoop(L);
00230 
00231   // If we know the trip count, we know the multiple...
00232   unsigned BreakoutTrip = 0;
00233   if (TripCount != 0) {
00234     BreakoutTrip = TripCount % Count;
00235     TripMultiple = 0;
00236   } else {
00237     // Figure out what multiple to use.
00238     BreakoutTrip = TripMultiple =
00239       (unsigned)GreatestCommonDivisor64(Count, TripMultiple);
00240   }
00241 
00242   // Report the unrolling decision.
00243   DebugLoc LoopLoc = L->getStartLoc();
00244   Function *F = Header->getParent();
00245   LLVMContext &Ctx = F->getContext();
00246 
00247   if (CompletelyUnroll) {
00248     DEBUG(dbgs() << "COMPLETELY UNROLLING loop %" << Header->getName()
00249           << " with trip count " << TripCount << "!\n");
00250     emitOptimizationRemark(Ctx, DEBUG_TYPE, *F, LoopLoc,
00251                            Twine("completely unrolled loop with ") +
00252                                Twine(TripCount) + " iterations");
00253   } else {
00254     auto EmitDiag = [&](const Twine &T) {
00255       emitOptimizationRemark(Ctx, DEBUG_TYPE, *F, LoopLoc,
00256                              "unrolled loop by a factor of " + Twine(Count) +
00257                                  T);
00258     };
00259 
00260     DEBUG(dbgs() << "UNROLLING loop %" << Header->getName()
00261           << " by " << Count);
00262     if (TripMultiple == 0 || BreakoutTrip != TripMultiple) {
00263       DEBUG(dbgs() << " with a breakout at trip " << BreakoutTrip);
00264       EmitDiag(" with a breakout at trip " + Twine(BreakoutTrip));
00265     } else if (TripMultiple != 1) {
00266       DEBUG(dbgs() << " with " << TripMultiple << " trips per branch");
00267       EmitDiag(" with " + Twine(TripMultiple) + " trips per branch");
00268     } else if (RuntimeTripCount) {
00269       DEBUG(dbgs() << " with run-time trip count");
00270       EmitDiag(" with run-time trip count");
00271     }
00272     DEBUG(dbgs() << "!\n");
00273   }
00274 
00275   bool ContinueOnTrue = L->contains(BI->getSuccessor(0));
00276   BasicBlock *LoopExit = BI->getSuccessor(ContinueOnTrue);
00277 
00278   // For the first iteration of the loop, we should use the precloned values for
00279   // PHI nodes.  Insert associations now.
00280   ValueToValueMapTy LastValueMap;
00281   std::vector<PHINode*> OrigPHINode;
00282   for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {
00283     OrigPHINode.push_back(cast<PHINode>(I));
00284   }
00285 
00286   std::vector<BasicBlock*> Headers;
00287   std::vector<BasicBlock*> Latches;
00288   Headers.push_back(Header);
00289   Latches.push_back(LatchBlock);
00290 
00291   // The current on-the-fly SSA update requires blocks to be processed in
00292   // reverse postorder so that LastValueMap contains the correct value at each
00293   // exit.
00294   LoopBlocksDFS DFS(L);
00295   DFS.perform(LI);
00296 
00297   // Stash the DFS iterators before adding blocks to the loop.
00298   LoopBlocksDFS::RPOIterator BlockBegin = DFS.beginRPO();
00299   LoopBlocksDFS::RPOIterator BlockEnd = DFS.endRPO();
00300 
00301   for (unsigned It = 1; It != Count; ++It) {
00302     std::vector<BasicBlock*> NewBlocks;
00303     SmallDenseMap<const Loop *, Loop *, 4> NewLoops;
00304     NewLoops[L] = L;
00305 
00306     for (LoopBlocksDFS::RPOIterator BB = BlockBegin; BB != BlockEnd; ++BB) {
00307       ValueToValueMapTy VMap;
00308       BasicBlock *New = CloneBasicBlock(*BB, VMap, "." + Twine(It));
00309       Header->getParent()->getBasicBlockList().push_back(New);
00310 
00311       // Tell LI about New.
00312       if (*BB == Header) {
00313         assert(LI->getLoopFor(*BB) == L && "Header should not be in a sub-loop");
00314         L->addBasicBlockToLoop(New, *LI);
00315       } else {
00316         // Figure out which loop New is in.
00317         const Loop *OldLoop = LI->getLoopFor(*BB);
00318         assert(OldLoop && "Should (at least) be in the loop being unrolled!");
00319 
00320         Loop *&NewLoop = NewLoops[OldLoop];
00321         if (!NewLoop) {
00322           // Found a new sub-loop.
00323           assert(*BB == OldLoop->getHeader() &&
00324                  "Header should be first in RPO");
00325 
00326           Loop *NewLoopParent = NewLoops.lookup(OldLoop->getParentLoop());
00327           assert(NewLoopParent &&
00328                  "Expected parent loop before sub-loop in RPO");
00329           NewLoop = new Loop;
00330           NewLoopParent->addChildLoop(NewLoop);
00331 
00332           // Forget the old loop, since its inputs may have changed.
00333           if (SE)
00334             SE->forgetLoop(OldLoop);
00335         }
00336         NewLoop->addBasicBlockToLoop(New, *LI);
00337       }
00338 
00339       if (*BB == Header)
00340         // Loop over all of the PHI nodes in the block, changing them to use
00341         // the incoming values from the previous block.
00342         for (unsigned i = 0, e = OrigPHINode.size(); i != e; ++i) {
00343           PHINode *NewPHI = cast<PHINode>(VMap[OrigPHINode[i]]);
00344           Value *InVal = NewPHI->getIncomingValueForBlock(LatchBlock);
00345           if (Instruction *InValI = dyn_cast<Instruction>(InVal))
00346             if (It > 1 && L->contains(InValI))
00347               InVal = LastValueMap[InValI];
00348           VMap[OrigPHINode[i]] = InVal;
00349           New->getInstList().erase(NewPHI);
00350         }
00351 
00352       // Update our running map of newest clones
00353       LastValueMap[*BB] = New;
00354       for (ValueToValueMapTy::iterator VI = VMap.begin(), VE = VMap.end();
00355            VI != VE; ++VI)
00356         LastValueMap[VI->first] = VI->second;
00357 
00358       // Add phi entries for newly created values to all exit blocks.
00359       for (succ_iterator SI = succ_begin(*BB), SE = succ_end(*BB);
00360            SI != SE; ++SI) {
00361         if (L->contains(*SI))
00362           continue;
00363         for (BasicBlock::iterator BBI = (*SI)->begin();
00364              PHINode *phi = dyn_cast<PHINode>(BBI); ++BBI) {
00365           Value *Incoming = phi->getIncomingValueForBlock(*BB);
00366           ValueToValueMapTy::iterator It = LastValueMap.find(Incoming);
00367           if (It != LastValueMap.end())
00368             Incoming = It->second;
00369           phi->addIncoming(Incoming, New);
00370         }
00371       }
00372       // Keep track of new headers and latches as we create them, so that
00373       // we can insert the proper branches later.
00374       if (*BB == Header)
00375         Headers.push_back(New);
00376       if (*BB == LatchBlock)
00377         Latches.push_back(New);
00378 
00379       NewBlocks.push_back(New);
00380     }
00381 
00382     // Remap all instructions in the most recent iteration
00383     for (unsigned i = 0; i < NewBlocks.size(); ++i)
00384       for (BasicBlock::iterator I = NewBlocks[i]->begin(),
00385            E = NewBlocks[i]->end(); I != E; ++I)
00386         ::RemapInstruction(I, LastValueMap);
00387   }
00388 
00389   // Loop over the PHI nodes in the original block, setting incoming values.
00390   for (unsigned i = 0, e = OrigPHINode.size(); i != e; ++i) {
00391     PHINode *PN = OrigPHINode[i];
00392     if (CompletelyUnroll) {
00393       PN->replaceAllUsesWith(PN->getIncomingValueForBlock(Preheader));
00394       Header->getInstList().erase(PN);
00395     }
00396     else if (Count > 1) {
00397       Value *InVal = PN->removeIncomingValue(LatchBlock, false);
00398       // If this value was defined in the loop, take the value defined by the
00399       // last iteration of the loop.
00400       if (Instruction *InValI = dyn_cast<Instruction>(InVal)) {
00401         if (L->contains(InValI))
00402           InVal = LastValueMap[InVal];
00403       }
00404       assert(Latches.back() == LastValueMap[LatchBlock] && "bad last latch");
00405       PN->addIncoming(InVal, Latches.back());
00406     }
00407   }
00408 
00409   // Now that all the basic blocks for the unrolled iterations are in place,
00410   // set up the branches to connect them.
00411   for (unsigned i = 0, e = Latches.size(); i != e; ++i) {
00412     // The original branch was replicated in each unrolled iteration.
00413     BranchInst *Term = cast<BranchInst>(Latches[i]->getTerminator());
00414 
00415     // The branch destination.
00416     unsigned j = (i + 1) % e;
00417     BasicBlock *Dest = Headers[j];
00418     bool NeedConditional = true;
00419 
00420     if (RuntimeTripCount && j != 0) {
00421       NeedConditional = false;
00422     }
00423 
00424     // For a complete unroll, make the last iteration end with a branch
00425     // to the exit block.
00426     if (CompletelyUnroll && j == 0) {
00427       Dest = LoopExit;
00428       NeedConditional = false;
00429     }
00430 
00431     // If we know the trip count or a multiple of it, we can safely use an
00432     // unconditional branch for some iterations.
00433     if (j != BreakoutTrip && (TripMultiple == 0 || j % TripMultiple != 0)) {
00434       NeedConditional = false;
00435     }
00436 
00437     if (NeedConditional) {
00438       // Update the conditional branch's successor for the following
00439       // iteration.
00440       Term->setSuccessor(!ContinueOnTrue, Dest);
00441     } else {
00442       // Remove phi operands at this loop exit
00443       if (Dest != LoopExit) {
00444         BasicBlock *BB = Latches[i];
00445         for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB);
00446              SI != SE; ++SI) {
00447           if (*SI == Headers[i])
00448             continue;
00449           for (BasicBlock::iterator BBI = (*SI)->begin();
00450                PHINode *Phi = dyn_cast<PHINode>(BBI); ++BBI) {
00451             Phi->removeIncomingValue(BB, false);
00452           }
00453         }
00454       }
00455       // Replace the conditional branch with an unconditional one.
00456       BranchInst::Create(Dest, Term);
00457       Term->eraseFromParent();
00458     }
00459   }
00460 
00461   // Merge adjacent basic blocks, if possible.
00462   SmallPtrSet<Loop *, 4> ForgottenLoops;
00463   for (unsigned i = 0, e = Latches.size(); i != e; ++i) {
00464     BranchInst *Term = cast<BranchInst>(Latches[i]->getTerminator());
00465     if (Term->isUnconditional()) {
00466       BasicBlock *Dest = Term->getSuccessor(0);
00467       if (BasicBlock *Fold = FoldBlockIntoPredecessor(Dest, LI, LPM,
00468                                                       ForgottenLoops))
00469         std::replace(Latches.begin(), Latches.end(), Dest, Fold);
00470     }
00471   }
00472 
00473   // FIXME: We could register any cloned assumptions instead of clearing the
00474   // whole function's cache.
00475   AC->clear();
00476 
00477   DominatorTree *DT = nullptr;
00478   if (PP) {
00479     // FIXME: Reconstruct dom info, because it is not preserved properly.
00480     // Incrementally updating domtree after loop unrolling would be easy.
00481     if (DominatorTreeWrapperPass *DTWP =
00482             PP->getAnalysisIfAvailable<DominatorTreeWrapperPass>()) {
00483       DT = &DTWP->getDomTree();
00484       DT->recalculate(*L->getHeader()->getParent());
00485     }
00486 
00487     // Simplify any new induction variables in the partially unrolled loop.
00488     if (SE && !CompletelyUnroll) {
00489       SmallVector<WeakVH, 16> DeadInsts;
00490       simplifyLoopIVs(L, SE, LPM, DeadInsts);
00491 
00492       // Aggressively clean up dead instructions that simplifyLoopIVs already
00493       // identified. Any remaining should be cleaned up below.
00494       while (!DeadInsts.empty())
00495         if (Instruction *Inst =
00496             dyn_cast_or_null<Instruction>(&*DeadInsts.pop_back_val()))
00497           RecursivelyDeleteTriviallyDeadInstructions(Inst);
00498     }
00499   }
00500   // At this point, the code is well formed.  We now do a quick sweep over the
00501   // inserted code, doing constant propagation and dead code elimination as we
00502   // go.
00503   const std::vector<BasicBlock*> &NewLoopBlocks = L->getBlocks();
00504   for (std::vector<BasicBlock*>::const_iterator BB = NewLoopBlocks.begin(),
00505        BBE = NewLoopBlocks.end(); BB != BBE; ++BB)
00506     for (BasicBlock::iterator I = (*BB)->begin(), E = (*BB)->end(); I != E; ) {
00507       Instruction *Inst = I++;
00508 
00509       if (isInstructionTriviallyDead(Inst))
00510         (*BB)->getInstList().erase(Inst);
00511       else if (Value *V = SimplifyInstruction(Inst))
00512         if (LI->replacementPreservesLCSSAForm(Inst, V)) {
00513           Inst->replaceAllUsesWith(V);
00514           (*BB)->getInstList().erase(Inst);
00515         }
00516     }
00517 
00518   NumCompletelyUnrolled += CompletelyUnroll;
00519   ++NumUnrolled;
00520 
00521   Loop *OuterL = L->getParentLoop();
00522   // Remove the loop from the LoopPassManager if it's completely removed.
00523   if (CompletelyUnroll && LPM != nullptr)
00524     LPM->deleteLoopFromQueue(L);
00525 
00526   // If we have a pass and a DominatorTree we should re-simplify impacted loops
00527   // to ensure subsequent analyses can rely on this form. We want to simplify
00528   // at least one layer outside of the loop that was unrolled so that any
00529   // changes to the parent loop exposed by the unrolling are considered.
00530   if (PP && DT) {
00531     if (!OuterL && !CompletelyUnroll)
00532       OuterL = L;
00533     if (OuterL) {
00534       DataLayoutPass *DLP = PP->getAnalysisIfAvailable<DataLayoutPass>();
00535       const DataLayout *DL = DLP ? &DLP->getDataLayout() : nullptr;
00536       simplifyLoop(OuterL, DT, LI, PP, /*AliasAnalysis*/ nullptr, SE, DL, AC);
00537 
00538       // LCSSA must be performed on the outermost affected loop. The unrolled
00539       // loop's last loop latch is guaranteed to be in the outermost loop after
00540       // deleteLoopFromQueue updates LoopInfo.
00541       Loop *LatchLoop = LI->getLoopFor(Latches.back());
00542       if (!OuterL->contains(LatchLoop))
00543         while (OuterL->getParentLoop() != LatchLoop)
00544           OuterL = OuterL->getParentLoop();
00545 
00546       formLCSSARecursively(*OuterL, *DT, LI, SE);
00547     }
00548   }
00549 
00550   return true;
00551 }