[llvm] r231817 - [LAA-memchecks 2/3] Move number of memcheck threshold checking to LV

Adam Nemet anemet at apple.com
Tue Mar 10 11:54:23 PDT 2015


Author: anemet
Date: Tue Mar 10 13:54:23 2015
New Revision: 231817

URL: http://llvm.org/viewvc/llvm-project?rev=231817&view=rev
Log:
[LAA-memchecks 2/3] Move number of memcheck threshold checking to LV

Now the analysis won't "fail" if the memchecks exceed the threshold.  It
is the transform pass' responsibility to perform the check.

This allows the transform pass to further analyze/eliminate the
memchecks.  E.g. in Loop distribution we only need to check pointers
that end up in different partitions.

Note that there is a slight change of functionality here.  The logic in
analyzeLoop is that if dependence checking fails due to non-constant
distance between the pointers, another attempt is made to prove safety
of the dependences purely using run-time checks.

Before this patch we could fail the loop due to exceeding the memcheck
threshold after the first step, now we only check the threshold in the
client after the full analysis.  There is no measurable compile-time
effect but I wanted to record this here.

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

Modified: llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h?rev=231817&r1=231816&r2=231817&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h Tue Mar 10 13:54:23 2015
@@ -362,6 +362,10 @@ public:
     return &PtrRtCheck;
   }
 
+  /// \brief Number of memchecks required to prove independence of otherwise
+  /// may-alias pointers.
+  unsigned getNumRuntimePointerChecks() const { return NumComparisons; }
+
   /// Return true if the block BB needs to be predicated in order for the loop
   /// to be vectorized.
   static bool blockNeedsPredication(BasicBlock *BB, Loop *TheLoop,
@@ -416,6 +420,10 @@ private:
   /// loop-independent and loop-carried dependences between memory accesses.
   MemoryDepChecker DepChecker;
 
+  /// \brief Number of memchecks required to prove independence of otherwise
+  /// may-alias pointers
+  unsigned NumComparisons;
+
   Loop *TheLoop;
   ScalarEvolution *SE;
   const DataLayout &DL;

Modified: llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp?rev=231817&r1=231816&r2=231817&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp Tue Mar 10 13:54:23 2015
@@ -1072,7 +1072,6 @@ void LoopAccessInfo::analyzeLoop(const V
 
   // Find pointers with computable bounds. We are going to use this information
   // to place a runtime bound check.
-  unsigned NumComparisons = 0;
   bool CanDoRT = false;
   if (NeedRTCheck)
     CanDoRT = Accesses.canCheckPtrAtRT(PtrRtCheck, NumComparisons, SE, TheLoop,
@@ -1098,17 +1097,6 @@ void LoopAccessInfo::analyzeLoop(const V
     return;
   }
 
-  if (NumComparisons > RuntimeMemoryCheckThreshold) {
-    emitAnalysis(LoopAccessReport()
-                 << NumComparisons << " exceeds limit of "
-                 << RuntimeMemoryCheckThreshold
-                 << " dependent memory operations checked at runtime");
-    DEBUG(dbgs() << "LAA: Too many memory checks needed.\n");
-    PtrRtCheck.reset();
-    CanVecMem = false;
-    return;
-  }
-
   PtrRtCheck.Need = NeedRTCheck;
 
   CanVecMem = true;
@@ -1140,18 +1128,6 @@ void LoopAccessInfo::analyzeLoop(const V
         return;
       }
 
-      // Check that we did not collect too many pointers.
-      if (NumComparisons > RuntimeMemoryCheckThreshold) {
-        emitAnalysis(LoopAccessReport()
-                     << NumComparisons << " exceeds limit of "
-                     << RuntimeMemoryCheckThreshold
-                     << " dependent memory operations checked at runtime");
-        DEBUG(dbgs() << "LAA: Can't vectorize with memory checks\n");
-        PtrRtCheck.reset();
-        CanVecMem = false;
-        return;
-      }
-
       CanVecMem = true;
     }
   }
@@ -1283,9 +1259,9 @@ LoopAccessInfo::LoopAccessInfo(Loop *L,
                                const TargetLibraryInfo *TLI, AliasAnalysis *AA,
                                DominatorTree *DT,
                                const ValueToValueMap &Strides)
-    : DepChecker(SE, L), TheLoop(L), SE(SE), DL(DL), TLI(TLI), AA(AA),
-      DT(DT), NumLoads(0), NumStores(0), MaxSafeDepDistBytes(-1U),
-      CanVecMem(false) {
+    : DepChecker(SE, L), NumComparisons(0), TheLoop(L), SE(SE), DL(DL),
+      TLI(TLI), AA(AA), DT(DT), NumLoads(0), NumStores(0),
+      MaxSafeDepDistBytes(-1U), CanVecMem(false) {
   if (canAnalyzeLoop())
     analyzeLoop(Strides);
 }

Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=231817&r1=231816&r2=231817&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Tue Mar 10 13:54:23 2015
@@ -3874,7 +3874,19 @@ bool LoopVectorizationLegality::canVecto
   auto &OptionalReport = LAI->getReport();
   if (OptionalReport)
     emitAnalysis(VectorizationReport(*OptionalReport));
-  return LAI->canVectorizeMemory();
+  if (!LAI->canVectorizeMemory())
+    return false;
+
+  if (LAI->getNumRuntimePointerChecks() >
+      VectorizerParams::RuntimeMemoryCheckThreshold) {
+    emitAnalysis(VectorizationReport()
+                 << LAI->getNumRuntimePointerChecks() << " exceeds limit of "
+                 << VectorizerParams::RuntimeMemoryCheckThreshold
+                 << " dependent memory operations checked at runtime");
+    DEBUG(dbgs() << "LV: Too many memory checks needed.\n");
+    return false;
+  }
+  return true;
 }
 
 static bool hasMultipleUsesOf(Instruction *I,





More information about the llvm-commits mailing list