[SLP] Fixed non-deterministic behavior in Loop Vectorizer.

Differential Revision: https://reviews.llvm.org/D30638

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297257 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Amjad Aboud 2017-03-08 05:09:10 +00:00
parent 2aec349a25
commit 8cd8473e96
2 changed files with 13 additions and 11 deletions

View File

@ -93,7 +93,7 @@ struct VectorizerParams {
class MemoryDepChecker { class MemoryDepChecker {
public: public:
typedef PointerIntPair<Value *, 1, bool> MemAccessInfo; typedef PointerIntPair<Value *, 1, bool> MemAccessInfo;
typedef SmallPtrSet<MemAccessInfo, 8> MemAccessInfoSet; typedef SmallVector<MemAccessInfo, 8> MemAccessInfoList;
/// \brief Set of potential dependent memory accesses. /// \brief Set of potential dependent memory accesses.
typedef EquivalenceClasses<MemAccessInfo> DepCandidates; typedef EquivalenceClasses<MemAccessInfo> DepCandidates;
@ -188,7 +188,7 @@ public:
/// \brief Check whether the dependencies between the accesses are safe. /// \brief Check whether the dependencies between the accesses are safe.
/// ///
/// Only checks sets with elements in \p CheckDeps. /// Only checks sets with elements in \p CheckDeps.
bool areDepsSafe(DepCandidates &AccessSets, MemAccessInfoSet &CheckDeps, bool areDepsSafe(DepCandidates &AccessSets, MemAccessInfoList &CheckDeps,
const ValueToValueMap &Strides); const ValueToValueMap &Strides);
/// \brief No memory dependence was encountered that would inhibit /// \brief No memory dependence was encountered that would inhibit

View File

@ -498,7 +498,7 @@ class AccessAnalysis {
public: public:
/// \brief Read or write access location. /// \brief Read or write access location.
typedef PointerIntPair<Value *, 1, bool> MemAccessInfo; typedef PointerIntPair<Value *, 1, bool> MemAccessInfo;
typedef SmallPtrSet<MemAccessInfo, 8> MemAccessInfoSet; typedef SmallVector<MemAccessInfo, 8> MemAccessInfoList;
AccessAnalysis(const DataLayout &Dl, AliasAnalysis *AA, LoopInfo *LI, AccessAnalysis(const DataLayout &Dl, AliasAnalysis *AA, LoopInfo *LI,
MemoryDepChecker::DepCandidates &DA, MemoryDepChecker::DepCandidates &DA,
@ -550,7 +550,7 @@ public:
DepChecker.clearDependences(); DepChecker.clearDependences();
} }
MemAccessInfoSet &getDependenciesToCheck() { return CheckDeps; } MemAccessInfoList &getDependenciesToCheck() { return CheckDeps; }
private: private:
typedef SetVector<MemAccessInfo> PtrAccessSet; typedef SetVector<MemAccessInfo> PtrAccessSet;
@ -564,8 +564,8 @@ private:
const DataLayout &DL; const DataLayout &DL;
/// Set of accesses that need a further dependence check. /// List of accesses that need a further dependence check.
MemAccessInfoSet CheckDeps; MemAccessInfoList CheckDeps;
/// Set of pointers that are read only. /// Set of pointers that are read only.
SmallPtrSet<Value*, 16> ReadOnlyPtr; SmallPtrSet<Value*, 16> ReadOnlyPtr;
@ -822,7 +822,7 @@ void AccessAnalysis::processMemAccesses() {
// there is no other write to the ptr - this is an optimization to // there is no other write to the ptr - this is an optimization to
// catch "a[i] = a[i] + " without having to do a dependence check). // catch "a[i] = a[i] + " without having to do a dependence check).
if ((IsWrite || IsReadOnlyPtr) && SetHasWrite) { if ((IsWrite || IsReadOnlyPtr) && SetHasWrite) {
CheckDeps.insert(Access); CheckDeps.push_back(Access);
IsRTCheckAnalysisNeeded = true; IsRTCheckAnalysisNeeded = true;
} }
@ -1530,12 +1530,14 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
} }
bool MemoryDepChecker::areDepsSafe(DepCandidates &AccessSets, bool MemoryDepChecker::areDepsSafe(DepCandidates &AccessSets,
MemAccessInfoSet &CheckDeps, MemAccessInfoList &CheckDeps,
const ValueToValueMap &Strides) { const ValueToValueMap &Strides) {
MaxSafeDepDistBytes = -1; MaxSafeDepDistBytes = -1;
while (!CheckDeps.empty()) { SmallPtrSet<MemAccessInfo, 8> Visited;
MemAccessInfo CurAccess = *CheckDeps.begin(); for (MemAccessInfo CurAccess : CheckDeps) {
if (Visited.count(CurAccess))
continue;
// Get the relevant memory access set. // Get the relevant memory access set.
EquivalenceClasses<MemAccessInfo>::iterator I = EquivalenceClasses<MemAccessInfo>::iterator I =
@ -1549,7 +1551,7 @@ bool MemoryDepChecker::areDepsSafe(DepCandidates &AccessSets,
// Check every access pair. // Check every access pair.
while (AI != AE) { while (AI != AE) {
CheckDeps.erase(*AI); Visited.insert(*AI);
EquivalenceClasses<MemAccessInfo>::member_iterator OI = std::next(AI); EquivalenceClasses<MemAccessInfo>::member_iterator OI = std::next(AI);
while (OI != AE) { while (OI != AE) {
// Check every accessing instruction pair in program order. // Check every accessing instruction pair in program order.