recommit 96626, evidence that it broke things appears
authorDale Johannesen <dalej@apple.com>
Fri, 19 Feb 2010 07:14:22 +0000 (07:14 +0000)
committerDale Johannesen <dalej@apple.com>
Fri, 19 Feb 2010 07:14:22 +0000 (07:14 +0000)
to be spurious

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

include/llvm/Analysis/ScalarEvolution.h
lib/Analysis/ScalarEvolution.cpp
lib/Transforms/Scalar/IndVarSimplify.cpp

index 383ee88ad28d1fcd98efdad7fbce42371219b602..af5d10e6b7849d7711ece22b6699fb12075acb57 100644 (file)
@@ -586,6 +586,11 @@ namespace llvm {
     /// compute a trip count, or if the loop is deleted.
     void forgetLoop(const Loop *L);
 
+    /// forgetValue - This method should be called by the client when it has
+    /// changed a value in a way that may effect its value, or which may
+    /// disconnect it from a def-use chain linking it to a loop.
+    void forgetValue(Value *V);
+
     /// GetMinTrailingZeros - Determine the minimum number of zero bits that S
     /// is guaranteed to end in (at every loop iteration).  It is, at the same
     /// time, the minimum number of times S is divisible by 2.  For example,
index 82200cd028168f987ab51cedd35f79476264eb50..c2284a8ab9bd22a2ee429a6cf8d2f0241e44e759 100644 (file)
@@ -3485,6 +3485,35 @@ void ScalarEvolution::forgetLoop(const Loop *L) {
   }
 }
 
+/// forgetValue - This method should be called by the client when it has
+/// changed a value in a way that may effect its value, or which may
+/// disconnect it from a def-use chain linking it to a loop.
+void ScalarEvolution::forgetValue(Value *V) {
+  Instruction *I = dyn_cast<Instruction>(V);
+  if (!I) return;
+
+  // Drop information about expressions based on loop-header PHIs.
+  SmallVector<Instruction *, 16> Worklist;
+  Worklist.push_back(I);
+
+  SmallPtrSet<Instruction *, 8> Visited;
+  while (!Worklist.empty()) {
+    I = Worklist.pop_back_val();
+    if (!Visited.insert(I)) continue;
+
+    std::map<SCEVCallbackVH, const SCEV *>::iterator It =
+      Scalars.find(static_cast<Value *>(I));
+    if (It != Scalars.end()) {
+      ValuesAtScopes.erase(It->second);
+      Scalars.erase(It);
+      if (PHINode *PN = dyn_cast<PHINode>(I))
+        ConstantEvolutionLoopExitValue.erase(PN);
+    }
+
+    PushDefUseChildren(I, Worklist);
+  }
+}
+
 /// ComputeBackedgeTakenCount - Compute the number of times the backedge
 /// of the specified loop will execute.
 ScalarEvolution::BackedgeTakenInfo
index e699261b277406dd45844390afbb7a67d563b5d1..60492b028369e2cf325dc60e3f4186f83d145320 100644 (file)
@@ -246,6 +246,13 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L,
       if (!PN->getType()->isIntegerTy() && !PN->getType()->isPointerTy())
         continue;
 
+      // It's necessary to tell ScalarEvolution about this explicitly so that
+      // it can walk the def-use list and forget all SCEVs, as it may not be
+      // watching the PHI itself. Once the new exit value is in place, there
+      // may not be a def-use connection between the loop and every instruction
+      // which got a SCEVAddRecExpr for that loop.
+      SE->forgetValue(PN);
+
       // Iterate over all of the values in all the PHI nodes.
       for (unsigned i = 0; i != NumPreds; ++i) {
         // If the value being merged in is not integer or is not defined