[llvm-commits] [llvm] r104225 - /llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Dan Gohman gohman at apple.com
Thu May 20 08:17:54 PDT 2010


Author: djg
Date: Thu May 20 10:17:54 2010
New Revision: 104225

URL: http://llvm.org/viewvc/llvm-project?rev=104225&view=rev
Log:
Move the code for deleting BaseRegs and LSRUses into helper functions,
and fix a bug that valgrind noticed where the code would std::swap an
element with itself.

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=104225&r1=104224&r2=104225&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Thu May 20 10:17:54 2010
@@ -207,6 +207,8 @@
   unsigned getNumRegs() const;
   const Type *getType() const;
 
+  void DeleteBaseReg(const SCEV *&S);
+
   bool referencesReg(const SCEV *S) const;
   bool hasRegsUsedByUsesOtherThan(size_t LUIdx,
                                   const RegUseTracker &RegUses) const;
@@ -310,6 +312,13 @@
          0;
 }
 
+/// DeleteBaseReg - Delete the given base reg from the BaseRegs list.
+void Formula::DeleteBaseReg(const SCEV *&S) {
+  if (&S != &BaseRegs.back())
+    std::swap(S, BaseRegs.back());
+  BaseRegs.pop_back();
+}
+
 /// referencesReg - Test if this formula references the given register.
 bool Formula::referencesReg(const SCEV *S) const {
   return S == ScaledReg ||
@@ -1013,7 +1022,8 @@
 
 /// DeleteFormula - Remove the given formula from this use's list.
 void LSRUse::DeleteFormula(Formula &F) {
-  std::swap(F, Formulae.back());
+  if (&F != &Formulae.back())
+    std::swap(F, Formulae.back());
   Formulae.pop_back();
   assert(!Formulae.empty() && "LSRUse has no formulae left!");
 }
@@ -1279,6 +1289,8 @@
                                     LSRUse::KindType Kind,
                                     const Type *AccessTy);
 
+  void DeleteUse(LSRUse &LU);
+
   LSRUse *FindUseWithSimilarFormula(const Formula &F, const LSRUse &OrigLU);
 
 public:
@@ -1851,6 +1863,13 @@
   return std::make_pair(LUIdx, Offset);
 }
 
+/// DeleteUse - Delete the given use from the Uses list.
+void LSRInstance::DeleteUse(LSRUse &LU) {
+  if (&LU != &Uses.back())
+    std::swap(LU, Uses.back());
+  Uses.pop_back();
+}
+
 /// FindUseWithFormula - Look for a use distinct from OrigLU which is has
 /// a formula that has the same registers as the given formula.
 LSRUse *
@@ -2423,8 +2442,7 @@
           // TODO: This could be optimized to avoid all the copying.
           Formula F = Base;
           F.ScaledReg = Quotient;
-          std::swap(F.BaseRegs[i], F.BaseRegs.back());
-          F.BaseRegs.pop_back();
+          F.DeleteBaseReg(F.BaseRegs[i]);
           (void)InsertFormula(LU, LUIdx, F);
         }
       }
@@ -2895,8 +2913,7 @@
               }
 
               // Delete the old use.
-              std::swap(LU, Uses.back());
-              Uses.pop_back();
+              DeleteUse(LU);
               --LUIdx;
               --NumUses;
               break;





More information about the llvm-commits mailing list