There's no need to iterate block merging and PRE. In fact, iterating the latter
authorOwen Anderson <resistor@mac.com>
Wed, 16 Jul 2008 17:52:31 +0000 (17:52 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 16 Jul 2008 17:52:31 +0000 (17:52 +0000)
could cause problems for memdep when it breaks critical edges.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53691 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/GVN.cpp

index 7bbfbadf017d63cfe65dad40a89619859965e7c3..986d755bad0f9a04ddcffdc1aeb3229b5deb2cf4 100644 (file)
@@ -727,7 +727,6 @@ namespace {
       
       AU.addPreserved<DominatorTree>();
       AU.addPreserved<AliasAnalysis>();
-      AU.addPreserved<MemoryDependenceAnalysis>();
     }
   
     // Helper fuctions
@@ -1121,11 +1120,22 @@ bool GVN::runOnFunction(Function& F) {
   bool changed = false;
   bool shouldContinue = true;
   
+  // Merge unconditional branches, allowing PRE to catch more
+  // optimization opportunities.
+  for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ) {
+    BasicBlock* BB = FI;
+    ++FI;
+    changed |= mergeBlockIntoPredecessor(BB);
+  }
+  
   while (shouldContinue) {
     shouldContinue = iterateOnFunction(F);
     changed |= shouldContinue;
   }
   
+  if (EnablePRE)
+    changed |= performPRE(F);
+  
   return changed;
 }
 
@@ -1382,15 +1392,6 @@ bool GVN::iterateOnFunction(Function &F) {
   VN.clear();
   phiMap.clear();
   
-  // Merge unconditional branches, allowing PRE to catch more
-  // optimization opportunities.
-  bool mergedBlocks = false;
-  for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ) {
-    BasicBlock* BB = FI;
-    ++FI;
-    mergedBlocks |= mergeBlockIntoPredecessor(BB);
-  }
-  
   for (DenseMap<BasicBlock*, ValueNumberScope*>::iterator
        I = localAvail.begin(), E = localAvail.end(); I != E; ++I)
     delete I->second;
@@ -1404,8 +1405,5 @@ bool GVN::iterateOnFunction(Function &F) {
        DE = df_end(DT.getRootNode()); DI != DE; ++DI)
     changed |= processBlock(*DI);
   
-  if (EnablePRE)
-    changed |= performPRE(F);
-  
-  return changed || mergedBlocks;
+  return changed;
 }