Only try to clean up the current block if we changed that block already.
authorOwen Anderson <resistor@mac.com>
Tue, 31 Aug 2010 18:55:52 +0000 (18:55 +0000)
committerOwen Anderson <resistor@mac.com>
Tue, 31 Aug 2010 18:55:52 +0000 (18:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112625 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

index a62eb20a88e41bea595ef566f95c1d44de47efd1..c673b0b3326854fae1bc81edd0dd319b3c990138 100644 (file)
@@ -100,19 +100,25 @@ bool CorrelatedValuePropagation::processPHI(PHINode *P) {
 bool CorrelatedValuePropagation::runOnFunction(Function &F) {
   LVI = &getAnalysis<LazyValueInfo>();
   
-  bool Changed = false;
+  bool FnChanged = false;
   
   for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) {
+    bool BBChanged = false;
     for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE; ) {
       Instruction *II = BI++;
       if (SelectInst *SI = dyn_cast<SelectInst>(II))
-        Changed |= processSelect(SI);
+        BBChanged |= processSelect(SI);
       else if (PHINode *P = dyn_cast<PHINode>(II))
-        Changed |= processPHI(P);
+        BBChanged |= processPHI(P);
     }
     
-    SimplifyInstructionsInBlock(FI);
+    // Propagating correlated values might leave cruft around.
+    // Try to clean it up before we continue.
+    if (BBChanged)
+      SimplifyInstructionsInBlock(FI);
+    
+    FnChanged |= BBChanged;
   }
   
-  return Changed;
+  return FnChanged;
 }