[llvm] r186420 - SLPVectorizer: Reduce the compile time of the consecutive store lookup.

Andrew Trick atrick at apple.com
Tue Jul 16 10:59:37 PDT 2013


On Jul 16, 2013, at 9:27 AM, Nadav Rotem <nrotem at apple.com> wrote:

> Hi Hal, 
> 
> Yes, we can do better.  Andy suggested that we calculate the offsets of the stores from the base pointer and sort them according to this offset. Like you said, that will bring us down to NlogN. 

Also you’ll want to compare gep offsets directly (via accumulateConstantOffset) instead of creating very expensive SCEV expressions. Then
if isConsecutiveAccess was the only use of SCEV, you can remove the dependence entirely. SCEV is mostly useful in loop passes.

-Andy


> On Jul 16, 2013, at 9:13 AM, Hal Finkel <hfinkel at anl.gov> wrote:
> 
>> ----- Original Message -----
>>> Author: nadav
>>> Date: Tue Jul 16 10:25:17 2013
>>> New Revision: 186420
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=186420&view=rev
>>> Log:
>>> SLPVectorizer: Reduce the compile time of the consecutive store
>>> lookup.
>>> 
>>> Process groups of stores in chunks of 16.
>> 
>> This is, in practice, what the BB vectorizer does (uses a cutoff on what is otherwise a quadratic search), and while I think that some cutoff is definitely necessary, I've never liked the solution. Is there any way that we could sort them first? That way the sorting would be NlogN and we could handle larger groups?
>> 
>> Thanks again,
>> Hal
>> 
>>> 
>>> 
>>> Modified:
>>>    llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp
>>> 
>>> Modified: llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=186420&r1=186419&r2=186420&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp (original)
>>> +++ llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp Tue Jul 16
>>> 10:25:17 2013
>>> @@ -1645,7 +1645,7 @@ bool SLPVectorizer::vectorizeStoreChain(
>>> }
>>> 
>>> bool SLPVectorizer::vectorizeStores(ArrayRef<StoreInst *> Stores,
>>> -                                      int costThreshold, BoUpSLP &R)
>>> {
>>> +                                    int costThreshold, BoUpSLP &R) {
>>>   SetVector<Value *> Heads, Tails;
>>>   SmallDenseMap<Value *, Value *> ConsecutiveChain;
>>> 
>>> @@ -1656,9 +1656,11 @@ bool SLPVectorizer::vectorizeStores(Arra
>>> 
>>>   // Do a quadratic search on all of the given stores and find
>>>   // all of the pairs of stores that follow each other.
>>> -  for (unsigned i = 0, e = Stores.size(); i < e; ++i)
>>> +  for (unsigned i = 0, e = Stores.size(); i < e; ++i) {
>>> +    if (Heads.count(Stores[i]))
>>> +      continue;
>>>     for (unsigned j = 0; j < e; ++j) {
>>> -      if (i == j)
>>> +      if (i == j || Tails.count(Stores[j]))
>>>         continue;
>>> 
>>>       if (R.isConsecutiveAccess(Stores[i], Stores[j])) {
>>> @@ -1667,6 +1669,7 @@ bool SLPVectorizer::vectorizeStores(Arra
>>>         ConsecutiveChain[Stores[i]] = Stores[j];
>>>       }
>>>     }
>>> +  }
>>> 
>>>   // For stores that start but don't end a link in the chain:
>>>   for (SetVector<Value *>::iterator it = Heads.begin(), e =
>>>   Heads.end();
>>> @@ -1879,9 +1882,14 @@ bool SLPVectorizer::vectorizeStoreChains
>>>       continue;
>>> 
>>>     DEBUG(dbgs() << "SLP: Analyzing a store chain of length "
>>> -                 << it->second.size() << ".\n");
>>> +          << it->second.size() << ".\n");
>>> 
>>> -    Changed |= vectorizeStores(it->second, -SLPCostThreshold, R);
>>> +    // Process the stores in chunks of 16.
>>> +    for (unsigned CI = 0, CE = it->second.size(); CI < CE; CI+=16) {
>>> +      unsigned Len = std::min<unsigned>(CE - CI, 16);
>>> +      ArrayRef<StoreInst *> Chunk(&it->second[CI], Len);
>>> +      Changed |= vectorizeStores(Chunk, -SLPCostThreshold, R);
>>> +    }
>>>   }
>>>   return Changed;
>>> }
>>> 
>>> 
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>> 
>> 
>> -- 
>> Hal Finkel
>> Assistant Computational Scientist
>> Leadership Computing Facility
>> Argonne National Laboratory
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130716/1d239477/attachment.html>


More information about the llvm-commits mailing list