[llvm] r237574 - [LoopAccesses] If shouldRetryWithRuntimeCheck, reset InterestingDependences

Adam Nemet anemet at apple.com
Mon May 18 08:37:03 PDT 2015


Author: anemet
Date: Mon May 18 10:37:03 2015
New Revision: 237574

URL: http://llvm.org/viewvc/llvm-project?rev=237574&view=rev
Log:
[LoopAccesses] If shouldRetryWithRuntimeCheck, reset InterestingDependences

When dependence analysis encounters a non-constant distance between
memory accesses it aborts the analysis and falls back to run-time checks
only.  In this case we weren't resetting the array of dependences.

Added:
    llvm/trunk/test/Analysis/LoopAccessAnalysis/resort-to-memchecks-only.ll
Modified:
    llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h
    llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp

Modified: llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h?rev=237574&r1=237573&r2=237574&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h Mon May 18 10:37:03 2015
@@ -225,6 +225,8 @@ public:
     return RecordInterestingDependences ? &InterestingDependences : nullptr;
   }
 
+  void clearInterestingDependences() { InterestingDependences.clear(); }
+
   /// \brief The vector of memory access instructions.  The indices are used as
   /// instruction identifiers in the Dependence class.
   const SmallVectorImpl<Instruction *> &getMemoryInstructions() const {

Modified: llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp?rev=237574&r1=237573&r2=237574&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp Mon May 18 10:37:03 2015
@@ -235,7 +235,12 @@ public:
   bool isRTCheckNeeded() { return IsRTCheckNeeded; }
 
   bool isDependencyCheckNeeded() { return !CheckDeps.empty(); }
-  void resetDepChecks() { CheckDeps.clear(); }
+
+  /// We decided that no dependence analysis would be used.  Reset the state.
+  void resetDepChecks(MemoryDepChecker &DepChecker) {
+    CheckDeps.clear();
+    DepChecker.clearInterestingDependences();
+  }
 
   MemAccessInfoSet &getDependenciesToCheck() { return CheckDeps; }
 
@@ -1161,7 +1166,7 @@ void LoopAccessInfo::analyzeLoop(const V
       NeedRTCheck = true;
 
       // Clear the dependency checks. We assume they are not needed.
-      Accesses.resetDepChecks();
+      Accesses.resetDepChecks(DepChecker);
 
       PtrRtCheck.reset();
       PtrRtCheck.Need = true;

Added: llvm/trunk/test/Analysis/LoopAccessAnalysis/resort-to-memchecks-only.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/LoopAccessAnalysis/resort-to-memchecks-only.ll?rev=237574&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/LoopAccessAnalysis/resort-to-memchecks-only.ll (added)
+++ llvm/trunk/test/Analysis/LoopAccessAnalysis/resort-to-memchecks-only.ll Mon May 18 10:37:03 2015
@@ -0,0 +1,57 @@
+; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
+
+; We give up analyzing the dependences in this loop due to non-constant
+; distance between A[i+offset] and A[i] and add memchecks to prove
+; independence.  Make sure that no interesting dependences are reported in
+; this case.
+;
+;   for (i = 0; i < n; i++)
+;    A[i + offset] = A[i] * B[i] * C[i];
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.10.0"
+
+; CHECK: Memory dependences are safe with run-time checks
+; CHECK-NEXT: Interesting Dependences:
+; CHECK-NEXT: Run-time memory checks:
+; CHECK-NEXT: 0:
+; CHECK-NEXT:   %arrayidxA2 = getelementptr inbounds i16, i16* %a, i64 %idx
+; CHECK-NEXT:   %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %indvar
+
+ at B = common global i16* null, align 8
+ at A = common global i16* null, align 8
+ at C = common global i16* null, align 8
+
+define void @f(i64 %offset) {
+entry:
+  %a = load i16*, i16** @A, align 8
+  %b = load i16*, i16** @B, align 8
+  %c = load i16*, i16** @C, align 8
+  br label %for.body
+
+for.body:                                         ; preds = %for.body, %entry
+  %indvar = phi i64 [ 0, %entry ], [ %add, %for.body ]
+
+  %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %indvar
+  %loadA = load i16, i16* %arrayidxA, align 2
+
+  %arrayidxB = getelementptr inbounds i16, i16* %b, i64 %indvar
+  %loadB = load i16, i16* %arrayidxB, align 2
+
+  %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %indvar
+  %loadC = load i16, i16* %arrayidxC, align 2
+
+  %mul = mul i16 %loadB, %loadA
+  %mul1 = mul i16 %mul, %loadC
+
+  %idx = add i64 %indvar, %offset
+  %arrayidxA2 = getelementptr inbounds i16, i16* %a, i64 %idx
+  store i16 %mul1, i16* %arrayidxA2, align 2
+
+  %add = add nuw nsw i64 %indvar, 1
+  %exitcond = icmp eq i64 %add, 20
+  br i1 %exitcond, label %for.end, label %for.body
+
+for.end:                                          ; preds = %for.body
+  ret void
+}





More information about the llvm-commits mailing list