[PATCH] D23473: [LSV] Use a set rather than an ArraySlice at the end of getVectorizablePrefix. NFC

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 12 16:02:11 PDT 2016


jlebar created this revision.
jlebar added a reviewer: asbirlea.
jlebar added subscribers: arsenm, llvm-commits.
Herald added a subscriber: mzolotukhin.

This avoids a small O(n^2) loop.

https://reviews.llvm.org/D23473

Files:
  llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp

Index: llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
@@ -517,12 +517,11 @@
   // ChainInstrs[0, ChainInstrIdx).  This is the largest vectorizable prefix of
   // Chain.  (Recall that Chain is in address order, but ChainInstrs is in BB
   // order.)
-  auto VectorizableChainInstrs =
-      makeArrayRef(ChainInstrs.data(), ChainInstrIdx);
-  unsigned ChainIdx, ChainLen;
-  for (ChainIdx = 0, ChainLen = Chain.size(); ChainIdx < ChainLen; ++ChainIdx) {
-    Instruction *I = Chain[ChainIdx];
-    if (!is_contained(VectorizableChainInstrs, I))
+  SmallPtrSet<Instruction *, 16> VectorizableChainInstrs(
+      ChainInstrs.begin(), ChainInstrs.begin() + ChainInstrIdx);
+  unsigned ChainIdx = 0;
+  for (unsigned ChainLen = Chain.size(); ChainIdx < ChainLen; ++ChainIdx) {
+    if (!VectorizableChainInstrs.count(Chain[ChainIdx]))
       break;
   }
   return Chain.slice(0, ChainIdx);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23473.67932.patch
Type: text/x-patch
Size: 1077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160812/8c761e48/attachment.bin>


More information about the llvm-commits mailing list