minor tidying of comments.
[oota-llvm.git] / lib / Transforms / Scalar / LoopUnswitch.cpp
index 767ea1d30eea832ea50827e7d18e3d9e674a0f62..955622e0256c2274efb090c3a29dc113b950680a 100644 (file)
@@ -569,7 +569,6 @@ void LoopUnswitch::EmitPreheaderBranchOnCondition(Value *LIC, Constant *Val,
 
   // Insert the new branch.
   BranchInst::Create(TrueDest, FalseDest, BranchVal, InsertPt);
-
 }
 
 
@@ -607,6 +606,27 @@ void LoopUnswitch::UnswitchTrivialCondition(Loop *L, Value *Cond,
   // insert the new conditional branch.
   EmitPreheaderBranchOnCondition(Cond, Val, NewExit, NewPH, 
                                  OrigPH->getTerminator());
+  if (DT) {
+    DT->changeImmediateDominator(NewExit, OrigPH);
+    DT->changeImmediateDominator(NewPH, OrigPH);
+  }
+   
+  if (DF) {
+    // NewExit is now part of NewPH and Loop Header's dominance
+    // frontier.
+    DominanceFrontier::iterator  DFI = DF->find(NewPH);
+    if (DFI != DF->end())
+      DF->addToFrontier(DFI, NewExit);
+    DFI = DF->find(L->getHeader());
+    DF->addToFrontier(DFI, NewExit);
+
+    // ExitBlock does not have successors then NewExit is part of
+    // its dominance frontier.
+    if (succ_begin(ExitBlock) == succ_end(ExitBlock)) {
+      DFI = DF->find(ExitBlock);
+      DF->addToFrontier(DFI, NewExit);
+    }
+  }
   LPM->deleteSimpleAnalysisValue(OrigPH->getTerminator(), L);
   OrigPH->getTerminator()->eraseFromParent();