diff --git a/include/llvm/Analysis/LoopAccessAnalysis.h b/include/llvm/Analysis/LoopAccessAnalysis.h index 476e4b6686b..0361d78b88f 100644 --- a/include/llvm/Analysis/LoopAccessAnalysis.h +++ b/include/llvm/Analysis/LoopAccessAnalysis.h @@ -405,6 +405,14 @@ public: /// Holds a partitioning of pointers into "check groups". SmallVector CheckingGroups; + /// \brief Check if pointers are in the same partition + /// + /// \p PtrToPartition contains the partition number for pointers (-1 if the + /// pointer belongs to multiple partitions). + static bool + 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. diff --git a/lib/Analysis/LoopAccessAnalysis.cpp b/lib/Analysis/LoopAccessAnalysis.cpp index becbae4c5b5..d7880cc2dfa 100644 --- a/lib/Analysis/LoopAccessAnalysis.cpp +++ b/lib/Analysis/LoopAccessAnalysis.cpp @@ -280,6 +280,13 @@ void RuntimePointerChecking::groupChecks( } } +bool RuntimePointerChecking::arePointersInSamePartition( + const SmallVectorImpl &PtrToPartition, unsigned PtrIdx1, + unsigned PtrIdx2) { + return (PtrToPartition[PtrIdx1] != -1 && + PtrToPartition[PtrIdx1] == PtrToPartition[PtrIdx2]); +} + bool RuntimePointerChecking::needsChecking( unsigned I, unsigned J, const SmallVectorImpl *PtrPartition) const { const PointerInfo &PointerI = Pointers[I]; @@ -298,10 +305,7 @@ bool RuntimePointerChecking::needsChecking( return false; // If PtrPartition is set omit checks between pointers of the same partition. - // Partition number -1 means that the pointer is used in multiple partitions. - // In this case we can't omit the check. - if (PtrPartition && (*PtrPartition)[I] != -1 && - (*PtrPartition)[I] == (*PtrPartition)[J]) + if (PtrPartition && arePointersInSamePartition(*PtrPartition, I, J)) return false; return true;