diff --git a/include/llvm/Transforms/Utils/LoopVersioning.h b/include/llvm/Transforms/Utils/LoopVersioning.h index 009fba48c6a..077ae2a11bf 100644 --- a/include/llvm/Transforms/Utils/LoopVersioning.h +++ b/include/llvm/Transforms/Utils/LoopVersioning.h @@ -31,7 +31,8 @@ class LoopInfo; /// already has a preheader. class LoopVersioning { public: - LoopVersioning(const LoopAccessInfo &LAI, Loop *L, LoopInfo *LI, + LoopVersioning(SmallVector Checks, + const LoopAccessInfo &LAI, Loop *L, LoopInfo *LI, DominatorTree *DT, const SmallVector *PtrToPartition = nullptr); @@ -90,6 +91,9 @@ private: /// in NonVersionedLoop. ValueToValueMapTy VMap; + /// \brief The set of checks that we are versioning for. + SmallVector Checks; + /// \brief Analyses used. const LoopAccessInfo &LAI; LoopInfo *LI; diff --git a/lib/Transforms/Scalar/LoopDistribute.cpp b/lib/Transforms/Scalar/LoopDistribute.cpp index 96ac582525d..5ad4a454ce4 100644 --- a/lib/Transforms/Scalar/LoopDistribute.cpp +++ b/lib/Transforms/Scalar/LoopDistribute.cpp @@ -747,10 +747,12 @@ private: // If we need run-time checks to disambiguate pointers are run-time, version // the loop now. auto PtrToPartition = Partitions.computePartitionSetForPointers(LAI); - LoopVersioning LVer(LAI, L, LI, DT, &PtrToPartition); - if (LVer.needsRuntimeChecks()) { + auto Checks = + LAI.getRuntimePointerChecking()->generateChecks(&PtrToPartition); + if (!Checks.empty()) { DEBUG(dbgs() << "\nPointers:\n"); - DEBUG(LAI.getRuntimePointerChecking()->print(dbgs(), 0, &PtrToPartition)); + DEBUG(LAI.getRuntimePointerChecking()->printChecks(dbgs(), Checks)); + LoopVersioning LVer(std::move(Checks), LAI, L, LI, DT); LVer.versionLoop(this); LVer.addPHINodes(DefsUsedOutside); } diff --git a/lib/Transforms/Utils/LoopVersioning.cpp b/lib/Transforms/Utils/LoopVersioning.cpp index 832079d2cf6..b2182bd6409 100644 --- a/lib/Transforms/Utils/LoopVersioning.cpp +++ b/lib/Transforms/Utils/LoopVersioning.cpp @@ -22,11 +22,12 @@ using namespace llvm; -LoopVersioning::LoopVersioning(const LoopAccessInfo &LAI, Loop *L, LoopInfo *LI, - DominatorTree *DT, - const SmallVector *PtrToPartition) +LoopVersioning::LoopVersioning( + SmallVector Checks, + const LoopAccessInfo &LAI, Loop *L, LoopInfo *LI, DominatorTree *DT, + const SmallVector *PtrToPartition) : VersionedLoop(L), NonVersionedLoop(nullptr), - PtrToPartition(PtrToPartition), LAI(LAI), LI(LI), DT(DT) { + PtrToPartition(PtrToPartition), Checks(Checks), LAI(LAI), LI(LI), DT(DT) { assert(L->getExitBlock() && "No single exit block"); assert(L->getLoopPreheader() && "No preheader"); } @@ -41,7 +42,7 @@ void LoopVersioning::versionLoop(Pass *P) { // Add the memcheck in the original preheader (this is empty initially). BasicBlock *MemCheckBB = VersionedLoop->getLoopPreheader(); std::tie(FirstCheckInst, MemRuntimeCheck) = - LAI.addRuntimeCheck(MemCheckBB->getTerminator(), PtrToPartition); + LAI.addRuntimeCheck(MemCheckBB->getTerminator(), Checks); assert(MemRuntimeCheck && "called even though needsAnyChecking = false"); // Rename the block to make the IR more readable.