[llvm] r278581 - [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 17:04:12 PDT 2016


Author: jlebar
Date: Fri Aug 12 19:04:12 2016
New Revision: 278581

URL: http://llvm.org/viewvc/llvm-project?rev=278581&view=rev
Log:
[LSV] Use a set rather than an ArraySlice at the end of getVectorizablePrefix. NFC

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

Reviewers: asbirlea

Subscribers: mzolotukhin, llvm-commits, arsenm

Differential Revision: https://reviews.llvm.org/D23473

Modified:
    llvm/trunk/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp

Modified: llvm/trunk/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp?rev=278581&r1=278580&r2=278581&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp Fri Aug 12 19:04:12 2016
@@ -516,12 +516,11 @@ Vectorizer::getVectorizablePrefix(ArrayR
   // 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 *, 8> 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);




More information about the llvm-commits mailing list