diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -712,11 +712,12 @@ // We assign a consecutive id to access from different alias sets. // Accesses between different groups doesn't need to be checked. - unsigned ASId = 1; + unsigned ASId = 0; for (auto &AS : AST) { int NumReadPtrChecks = 0; int NumWritePtrChecks = 0; bool CanDoAliasSetRT = true; + ++ASId; // We assign consecutive id to access from different dependence sets. // Accesses within the same set don't need a runtime check. @@ -752,9 +753,25 @@ // for which we couldn't find the bounds but we don't actually need to emit // any checks so it does not matter. bool NeedsAliasSetRTCheck = false; - if (!(IsDepCheckNeeded && CanDoAliasSetRT && RunningDepId == 2)) + if (!(IsDepCheckNeeded && CanDoAliasSetRT && RunningDepId == 2)) { NeedsAliasSetRTCheck = (NumWritePtrChecks >= 2 || (NumReadPtrChecks >= 1 && NumWritePtrChecks >= 1)); + // For alias sets without at least 2 writes or 1 write and 1 read, there + // is no need to generate RT checks and CanDoAliasSetRT for this alias set + // does not impact whether runtime checks can be generated. + if (!NeedsAliasSetRTCheck) { + assert(AS.size() <= 1 || + all_of(AS, + [this](auto AC) { + MemAccessInfo AccessWrite(AC.getValue(), true); + return DepCands.findValue(AccessWrite) == + DepCands.end(); + }) && + "Can only skip updating CanDoRT below, if all entries in AS " + "are reads or there is at most 1 entry"); + continue; + } + } // We need to perform run-time alias checks, but some pointers had bounds // that couldn't be checked. @@ -774,7 +791,6 @@ CanDoRT &= CanDoAliasSetRT; NeedRTCheck |= NeedsAliasSetRTCheck; - ++ASId; } // If the pointers that we would use for the bounds comparison have different