[llvm] r294029 - [SLP] Make sortMemAccesses explicitly return an error. NFC.

Michael Kuperstein via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 3 11:32:50 PST 2017


Author: mkuper
Date: Fri Feb  3 13:32:50 2017
New Revision: 294029

URL: http://llvm.org/viewvc/llvm-project?rev=294029&view=rev
Log:
[SLP] Make sortMemAccesses explicitly return an error. NFC.

Modified:
    llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h
    llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp
    llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp

Modified: llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h?rev=294029&r1=294028&r2=294029&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h Fri Feb  3 13:32:50 2017
@@ -692,13 +692,12 @@ int64_t getPtrStride(PredicatedScalarEvo
 
 /// \brief Try to sort an array of loads / stores.
 ///
-/// If all pointers refer to the same object, and the differences between all
-/// pointer operands are known to be constant, the array is sorted by offset,
-/// and returned in \p Sorted.
-/// 
-/// If those conditions do not hold, the output array is an arbitrary
-/// permutation of the input.
-void sortMemAccesses(ArrayRef<Value *> VL, const DataLayout &DL,
+/// An array of loads / stores can only be sorted if all pointer operands
+/// refer to the same object, and the differences between these pointers 
+/// are known to be constant. If that is the case, this returns true, and the
+/// sorted array is returned in \p Sorted. Otherwise, this returns false, and
+/// \p Sorted is invalid.
+bool sortMemAccesses(ArrayRef<Value *> VL, const DataLayout &DL,
                      ScalarEvolution &SE, SmallVectorImpl<Value *> &Sorted);
 
 /// \brief Returns true if the memory operations \p A and \p B are consecutive.

Modified: llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp?rev=294029&r1=294028&r2=294029&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp Fri Feb  3 13:32:50 2017
@@ -1058,9 +1058,9 @@ static unsigned getAddressSpaceOperand(V
   return -1;
 }
 
-void llvm::sortMemAccesses(ArrayRef<Value *> VL, const DataLayout &DL,
-                         ScalarEvolution &SE,
-                         SmallVectorImpl<Value *> &Sorted) {
+bool llvm::sortMemAccesses(ArrayRef<Value *> VL, const DataLayout &DL,
+                           ScalarEvolution &SE,
+                           SmallVectorImpl<Value *> &Sorted) {
   SmallVector<std::pair<int64_t, Value *>, 4> OffValPairs;
   OffValPairs.reserve(VL.size());
   Sorted.reserve(VL.size());
@@ -1077,10 +1077,8 @@ void llvm::sortMemAccesses(ArrayRef<Valu
     // If a pointer refers to a different underlying object, bail - the
     // pointers are by definition incomparable.
     Value *CurrObj = GetUnderlyingObject(Ptr, DL);
-    if (CurrObj != Obj0) {
-      Sorted.append(VL.begin(), VL.end());
-      return;
-    }
+    if (CurrObj != Obj0)
+      return false;
 
     const SCEVConstant *Diff =
         dyn_cast<SCEVConstant>(SE.getMinusSCEV(SE.getSCEV(Ptr), Scev0));
@@ -1088,10 +1086,8 @@ void llvm::sortMemAccesses(ArrayRef<Valu
     // The pointers may not have a constant offset from each other, or SCEV
     // may just not be smart enough to figure out they do. Regardless,
     // there's nothing we can do.
-    if (!Diff) {
-      Sorted.append(VL.begin(), VL.end());
-      return;
-    }
+    if (!Diff)
+      return false;
 
     OffValPairs.emplace_back(Diff->getAPInt().getSExtValue(), Val);
   }
@@ -1102,8 +1098,10 @@ void llvm::sortMemAccesses(ArrayRef<Valu
               return Left.first < Right.first;
             });
 
-  for (auto& it : OffValPairs)
+  for (auto &it : OffValPairs)
     Sorted.push_back(it.second);
+
+  return true;
 }
 
 /// Returns true if the memory operations \p A and \p B are consecutive.

Modified: llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=294029&r1=294028&r2=294029&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp Fri Feb  3 13:32:50 2017
@@ -467,7 +467,9 @@ private:
                         ScalarEvolution &SE) const {
       assert(VL.size() == Scalars.size() && "Invalid size");
       SmallVector<Value *, 8> List;
-      sortMemAccesses(VL, DL, SE, List);
+      if (!sortMemAccesses(VL, DL, SE, List))
+        return false;
+
       return std::equal(List.begin(), List.end(), Scalars.begin());
     }
 
@@ -1223,18 +1225,19 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val
 
       if (VL.size() > 2 && !ReverseConsecutive) {
         bool ShuffledLoads = true;
-        SmallVector<Value *, 8> List;
-        sortMemAccesses(VL, *DL, *SE, List);
-        auto NewVL = makeArrayRef(List.begin(), List.end());
-        for (unsigned i = 0, e = NewVL.size() - 1; i < e; ++i) {
-          if (!isConsecutiveAccess(NewVL[i], NewVL[i + 1], *DL, *SE)) {
-            ShuffledLoads = false;
-            break;
+        SmallVector<Value *, 8> Sorted;
+        if (sortMemAccesses(VL, *DL, *SE, Sorted)) {
+          auto NewVL = makeArrayRef(Sorted.begin(), Sorted.end());
+          for (unsigned i = 0, e = NewVL.size() - 1; i < e; ++i) {
+            if (!isConsecutiveAccess(NewVL[i], NewVL[i + 1], *DL, *SE)) {
+              ShuffledLoads = false;
+              break;
+            }
+          }
+          if (ShuffledLoads) {
+            newTreeEntry(NewVL, true, true);
+            return;
           }
-        }
-        if (ShuffledLoads) {
-          newTreeEntry(NewVL, true, true);
-          return;
         }
       }
 




More information about the llvm-commits mailing list