[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopSimplify.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Apr 1 13:07:01 PST 2004


Changes in directory llvm/lib/Transforms/Scalar:

LoopSimplify.cpp updated: 1.37 -> 1.38

---
Log message:

Fix PR306: http://llvm.cs.uiuc.edu/PR306 : Loop simplify incorrectly updates dominator information
Testcase: LoopSimplify/2004-04-01-IncorrectDomUpdate.ll


---
Diffs of the changes:  (+22 -9)

Index: llvm/lib/Transforms/Scalar/LoopSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.37 llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.38
--- llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.37	Tue Mar 16 00:00:15 2004
+++ llvm/lib/Transforms/Scalar/LoopSimplify.cpp	Thu Apr  1 13:06:07 2004
@@ -530,9 +530,19 @@
   BasicBlock *NewBBSucc = *succ_begin(NewBB);
   DominatorSet &DS = getAnalysis<DominatorSet>();
 
+  // Update dominator information...  The blocks that dominate NewBB are the
+  // intersection of the dominators of predecessors, plus the block itself.
+  //
+  DominatorSet::DomSetType NewBBDomSet = DS.getDominators(PredBlocks[0]);
+  for (unsigned i = 1, e = PredBlocks.size(); i != e; ++i)
+    set_intersect(NewBBDomSet, DS.getDominators(PredBlocks[i]));
+  NewBBDomSet.insert(NewBB);  // All blocks dominate themselves...
+  DS.addBasicBlock(NewBB, NewBBDomSet);
+
   // The newly inserted basic block will dominate existing basic blocks iff the
   // PredBlocks dominate all of the non-pred blocks.  If all predblocks dominate
   // the non-pred blocks, then they all must be the same block!
+  //
   bool NewBBDominatesNewBBSucc = true;
   {
     BasicBlock *OnePred = PredBlocks[0];
@@ -551,15 +561,18 @@
         }
   }
 
-  // Update dominator information...  The blocks that dominate NewBB are the
-  // intersection of the dominators of predecessors, plus the block itself.
-  // The newly created basic block does not dominate anything except itself.
-  //
-  DominatorSet::DomSetType NewBBDomSet = DS.getDominators(PredBlocks[0]);
-  for (unsigned i = 1, e = PredBlocks.size(); i != e; ++i)
-    set_intersect(NewBBDomSet, DS.getDominators(PredBlocks[i]));
-  NewBBDomSet.insert(NewBB);  // All blocks dominate themselves...
-  DS.addBasicBlock(NewBB, NewBBDomSet);
+  // The other scenario where the new block can dominate its successors are when
+  // all predecessors of NewBBSucc that are not NewBB are dominated by NewBBSucc
+  // already.
+  if (!NewBBDominatesNewBBSucc) {
+    NewBBDominatesNewBBSucc = true;
+    for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
+         PI != E; ++PI)
+      if (*PI != NewBB && !DS.dominates(NewBBSucc, *PI)) {
+        NewBBDominatesNewBBSucc = false;
+        break;
+      }
+  }
 
   // If NewBB dominates some blocks, then it will dominate all blocks that
   // NewBBSucc does.





More information about the llvm-commits mailing list