From 52aafdb50accbf74aee04280a9133ff73499fa43 Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Thu, 30 Jul 2015 03:29:16 +0000 Subject: [PATCH] [LDist] Filter the checks locally rather than in LAA, NFC Before, we were passing the pointer partitions to LAA. Now, we get all the checks from LAA and filter out the checks within partitions in LoopDistribution. This effectively concludes the steps to move filtering memchecks from LAA into its clients. There is still some cleanup left to remove the unused interfaces in LAA that still take PtrPartition. (Moving this functionality to LoopDistribution also requires needsChecking on pointers to be made public.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243613 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/LoopAccessAnalysis.h | 4 +- lib/Transforms/Scalar/LoopDistribute.cpp | 45 +++++++++++++++++++++- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/include/llvm/Analysis/LoopAccessAnalysis.h b/include/llvm/Analysis/LoopAccessAnalysis.h index 716e18f7bb1..7971bbbbd19 100644 --- a/include/llvm/Analysis/LoopAccessAnalysis.h +++ b/include/llvm/Analysis/LoopAccessAnalysis.h @@ -435,7 +435,6 @@ public: arePointersInSamePartition(const SmallVectorImpl &PtrToPartition, unsigned PtrIdx1, unsigned PtrIdx2); -private: /// \brief Decide whether we need to issue a run-time check for pointer at /// index \p I and \p J to prove their independence. /// @@ -443,8 +442,9 @@ private: /// pointers (-1 if the pointer belongs to multiple partitions). In this /// case omit checks between pointers belonging to the same partition. bool needsChecking(unsigned I, unsigned J, - const SmallVectorImpl *PtrPartition) const; + const SmallVectorImpl *PtrPartition = nullptr) const; +private: /// Holds a pointer to the ScalarEvolution analysis. ScalarEvolution *SE; }; diff --git a/lib/Transforms/Scalar/LoopDistribute.cpp b/lib/Transforms/Scalar/LoopDistribute.cpp index 5ad4a454ce4..b2a3e28c3f0 100644 --- a/lib/Transforms/Scalar/LoopDistribute.cpp +++ b/lib/Transforms/Scalar/LoopDistribute.cpp @@ -627,6 +627,45 @@ public: static char ID; private: + /// \brief Filter out checks between pointers from the same partition. + /// + /// \p PtrToPartition contains the partition number for pointers. Partition + /// number -1 means that the pointer is used in multiple partitions. In this + /// case we can't safely omit the check. + SmallVector + includeOnlyCrossPartitionChecks( + const SmallVectorImpl &AllChecks, + const SmallVectorImpl &PtrToPartition, + const RuntimePointerChecking *RtPtrChecking) { + SmallVector Checks; + + std::copy_if(AllChecks.begin(), AllChecks.end(), std::back_inserter(Checks), + [&](const RuntimePointerChecking::PointerCheck &Check) { + for (unsigned PtrIdx1 : Check.first->Members) + for (unsigned PtrIdx2 : Check.second->Members) + // Only include this check if there is a pair of pointers + // that require checking and the pointers fall into + // separate partitions. + // + // (Note that we already know at this point that the two + // pointer groups need checking but it doesn't follow + // that each pair of pointers within the two groups need + // checking as well. + // + // In other words we don't want to include a check just + // because there is a pair of pointers between the two + // pointer groups that require checks and a different + // pair whose pointers fall into different partitions.) + if (RtPtrChecking->needsChecking(PtrIdx1, PtrIdx2) && + !RuntimePointerChecking::arePointersInSamePartition( + PtrToPartition, PtrIdx1, PtrIdx2)) + return true; + return false; + }); + + return Checks; + } + /// \brief Try to distribute an inner-most loop. bool processLoop(Loop *L) { assert(L->empty() && "Only process inner loops."); @@ -747,8 +786,10 @@ private: // If we need run-time checks to disambiguate pointers are run-time, version // the loop now. auto PtrToPartition = Partitions.computePartitionSetForPointers(LAI); - auto Checks = - LAI.getRuntimePointerChecking()->generateChecks(&PtrToPartition); + const auto *RtPtrChecking = LAI.getRuntimePointerChecking(); + auto AllChecks = RtPtrChecking->generateChecks(); + auto Checks = includeOnlyCrossPartitionChecks(AllChecks, PtrToPartition, + RtPtrChecking); if (!Checks.empty()) { DEBUG(dbgs() << "\nPointers:\n"); DEBUG(LAI.getRuntimePointerChecking()->printChecks(dbgs(), Checks)); -- 2.34.1