[PATCH] D34768: Remove creation of vector to store loop indices

Aditya Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 28 11:08:45 PDT 2017


hiraditya created this revision.
Herald added a subscriber: mzolotukhin.

Passes make check. No performance/functionality change.


https://reviews.llvm.org/D34768

Files:
  lib/Transforms/Scalar/LoopIdiomRecognize.cpp


Index: lib/Transforms/Scalar/LoopIdiomRecognize.cpp
===================================================================
--- lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -554,8 +554,7 @@
 
   // Do a quadratic search on all of the given stores and find
   // all of the pairs of stores that follow each other.
-  SmallVector<unsigned, 16> IndexQueue;
-  for (unsigned i = 0, e = SL.size(); i < e; ++i) {
+  for (int i = 0, e = SL.size(); i < e; ++i) {
     assert(SL[i]->isSimple() && "Expected only non-volatile stores.");
 
     Value *FirstStoredVal = SL[i]->getValueOperand();
@@ -582,19 +581,29 @@
     assert((FirstSplatValue || FirstPatternValue) &&
            "Expected either splat value or pattern value.");
 
-    IndexQueue.clear();
     // If a store has multiple consecutive store candidates, search Stores
-    // array according to the sequence: from i+1 to e, then from i-1 to 0.
+    // array according to the sequence: from [i+1, e), then from [i-1, 0].
     // This is because usually pairing with immediate succeeding or preceding
     // candidate create the best chance to find memset opportunity.
-    unsigned j = 0;
-    for (j = i + 1; j < e; ++j)
-      IndexQueue.push_back(j);
-    for (j = i; j > 0; --j)
-      IndexQueue.push_back(j - 1);
+    // k varies from [i+1,e), [i-1,0]
+    int delta = 1;
+    int it = 0;
+    int k = i+1;
+    if (k == e) { // [i+1, e) cannot be done.
+      k = i-1;
+      delta = -1;
+    }
 
-    for (auto &k : IndexQueue) {
+    for ( ; k >= 0; k = it) {
       assert(SL[k]->isSimple() && "Expected only non-volatile stores.");
+      it = k;
+      if (it+1 == e) {
+        it = i;
+        delta = -1;
+      }
+
+      it += delta;
+
       Value *SecondStorePtr = SL[k]->getPointerOperand();
       const SCEVAddRecExpr *SecondStoreEv =
           cast<SCEVAddRecExpr>(SE->getSCEV(SecondStorePtr));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34768.104454.patch
Type: text/x-patch
Size: 1924 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170628/c49f98b4/attachment.bin>


More information about the llvm-commits mailing list