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;