[PATCH] SLPVectorizer: limit the number of alias checks to reduce the runtime.

Erik Eckstein eeckstein at apple.com
Thu Jan 15 07:47:35 PST 2015


Hi aschwaighofer,

Beside caching the alias results, this is another step to reduce the SLPVectorizer's runtime.
In case of blocks with many memory-accessing instructions, alias checking can take lot of time (because calculating the memory dependencies has quadratic complexity).
I chose a limit which resulted in no changes when running the benchmarks.

http://reviews.llvm.org/D6999

Files:
  lib/Transforms/Vectorize/SLPVectorizer.cpp

Index: lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -2755,10 +2755,24 @@
           AliasAnalysis::Location SrcLoc = getLocation(SrcInst, SLP->AA);
           bool SrcMayWrite = BundleMember->Inst->mayWriteToMemory();
 
+          // Limit the number of alias checks, becaus SLP->isAliased() is the
+          // expensive part in the following loop. The limit is chosen so that
+          // it has no negative effect on the llvm benchmarks.
+          int AliasCheckLimit = 10;
+          int numAliased = 0;
+
           while (DepDest) {
             assert(isInSchedulingRegion(DepDest));
             if (SrcMayWrite || DepDest->Inst->mayWriteToMemory()) {
-              if (SLP->isAliased(SrcLoc, SrcInst, DepDest->Inst)) {
+
+              if (numAliased >= AliasCheckLimit
+                  || SLP->isAliased(SrcLoc, SrcInst, DepDest->Inst)) {
+
+                // We increment the counter only if the locations are aliased
+                // (instead of counting all alias checks). This gives a better
+                // balance between reduced runtime accurate dependencies.
+                numAliased++;
+
                 DepDest->MemoryDependencies.push_back(BundleMember);
                 BundleMember->Dependencies++;
                 ScheduleData *DestBundle = DepDest->FirstInBundle;

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6999.18229.patch
Type: text/x-patch
Size: 1472 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150115/8eb2b9f0/attachment.bin>


More information about the llvm-commits mailing list