[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Evan Cheng evan.cheng at apple.com
Fri Mar 17 16:45:01 PST 2006



Changes in directory llvm/lib/Transforms/Scalar:

LoopStrengthReduce.cpp updated: 1.78 -> 1.79
---
Log message:

Sort StrideOrder so we can process the smallest strides first. This allows
for more IV reuses.


---
Diffs of the changes:  (+27 -0)

 LoopStrengthReduce.cpp |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+)


Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.78 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.79
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.78	Fri Mar 17 13:52:23 2006
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp	Fri Mar 17 18:44:49 2006
@@ -1199,6 +1199,30 @@
   CondUse->isUseOfPostIncrementedValue = true;
 }
 
+namespace {
+  // Constant strides come first which in turns are sorted by their absolute
+  // values. If absolute values are the same, then positive strides comes first.
+  // e.g.
+  // 4, -1, X, 1, 2 ==> 1, -1, 2, 4, X
+  struct StrideCompare {
+    bool operator()(const SCEVHandle &LHS, const SCEVHandle &RHS) {
+      SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS);
+      SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS);
+      if (LHSC && RHSC) {
+        int64_t  LV = LHSC->getValue()->getSExtValue();
+        int64_t  RV = RHSC->getValue()->getSExtValue();
+        uint64_t ALV = (LV < 0) ? -LV : LV;
+        uint64_t ARV = (RV < 0) ? -RV : RV;
+        if (ALV == ARV)
+          return LV > RV;
+        else
+          return ALV < ARV;
+      } else
+        return (LHSC && !RHSC);
+    }
+  };
+}
+
 void LoopStrengthReduce::runOnLoop(Loop *L) {
   // First step, transform all loops nesting inside of this loop.
   for (LoopInfo::iterator I = L->begin(), E = L->end(); I != E; ++I)
@@ -1241,6 +1265,9 @@
   // IVsByStride keeps IVs for one particular loop.
   IVsByStride.clear();
 
+  // Sort the StrideOrder so we process larger strides first.
+  std::stable_sort(StrideOrder.begin(), StrideOrder.end(), StrideCompare());
+
   // Note: this processes each stride/type pair individually.  All users passed
   // into StrengthReduceStridedIVUsers have the same type AND stride.  Also,
   // node that we iterate over IVUsesByStride indirectly by using StrideOrder.






More information about the llvm-commits mailing list