Call ScalarEvolution's deleteValueFromRecords before deleting an
authorDan Gohman <gohman@apple.com>
Wed, 1 Oct 2008 02:02:03 +0000 (02:02 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 1 Oct 2008 02:02:03 +0000 (02:02 +0000)
instruction, not after. This fixes some uses of free'd memory.

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

lib/Transforms/Scalar/LoopStrengthReduce.cpp

index 07438e30c718788dd7cb2062a131f5adedaa441b..30e86447f25baf304f430cc8850b43227e6e9faf 100644 (file)
@@ -1803,15 +1803,15 @@ ICmpInst *LoopStrengthReduce::OptimizeSMax(Loop *L, ICmpInst *Cond,
                  Cond->getOperand(0), NewRHS, "scmp", Cond);
 
   // Delete the max calculation instructions.
+  SE->deleteValueFromRecords(Cond);
   Cond->replaceAllUsesWith(NewCond);
   Cond->eraseFromParent();
-  SE->deleteValueFromRecords(Cond);
   Instruction *Cmp = cast<Instruction>(Sel->getOperand(0));
-  Sel->eraseFromParent();
   SE->deleteValueFromRecords(Sel);
+  Sel->eraseFromParent();
   if (Cmp->use_empty()) {
-    Cmp->eraseFromParent();
     SE->deleteValueFromRecords(Cmp);
+    Cmp->eraseFromParent();
   }
   CondUse->User = NewCond;
   return NewCond;