[polly] r208616 - correct the delinearization failing case
Sebastian Pop
spop at codeaurora.org
Mon May 12 12:02:02 PDT 2014
Author: spop
Date: Mon May 12 14:02:02 2014
New Revision: 208616
URL: http://llvm.org/viewvc/llvm-project?rev=208616&view=rev
Log:
correct the delinearization failing case
collect terms from affine and non affine memory accesses
Added:
polly/trunk/test/ScopDetect/multidim_two_accesses_different_delinearization.ll
Modified:
polly/trunk/include/polly/ScopDetection.h
polly/trunk/lib/Analysis/ScopDetection.cpp
Modified: polly/trunk/include/polly/ScopDetection.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopDetection.h?rev=208616&r1=208615&r2=208616&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopDetection.h (original)
+++ polly/trunk/include/polly/ScopDetection.h Mon May 12 14:02:02 2014
@@ -102,7 +102,7 @@ class ScopDetection : public FunctionPas
bool Verifying; // If we are in the verification phase?
// Map a base pointer to all access functions accessing it.
- BaseToAFs NonAffineAccesses;
+ BaseToAFs NonAffineAccesses, AffineAccesses;
DetectionContext(Region &R, AliasAnalysis &AA, bool Verify)
: CurRegion(R), AST(AA), Verifying(Verify) {}
@@ -120,10 +120,10 @@ class ScopDetection : public FunctionPas
FunctionSet InvalidFunctions;
mutable std::string LastFailure;
- // Delinearize all non affine memory accesses and return true when there
- // exists a non affine memory access that cannot be delinearized. Return
- // false when all array accesses are affine after delinearization.
- bool hasNonAffineMemoryAccesses(DetectionContext &Context) const;
+ // Delinearize all non affine memory accesses and return false when there
+ // exists a non affine memory access that cannot be delinearized. Return true
+ // when all array accesses are affine after delinearization.
+ bool hasAffineMemoryAccesses(DetectionContext &Context) const;
// Try to expand the region R. If R can be expanded return the expanded
// region, NULL otherwise.
Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=208616&r1=208615&r2=208616&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Mon May 12 14:02:02 2014
@@ -338,7 +338,7 @@ bool ScopDetection::isInvariant(const Va
}
bool
-ScopDetection::hasNonAffineMemoryAccesses(DetectionContext &Context) const {
+ScopDetection::hasAffineMemoryAccesses(DetectionContext &Context) const {
for (auto P : Context.NonAffineAccesses) {
const SCEVUnknown *BasePointer = P.first;
Value *BaseValue = BasePointer->getValue();
@@ -348,14 +348,23 @@ ScopDetection::hasNonAffineMemoryAccesse
for (const SCEVAddRecExpr *AF : Context.NonAffineAccesses[BasePointer])
AF->collectParametricTerms(*SE, Terms);
+ // Also collect terms from the affine memory accesses.
+ for (const SCEVAddRecExpr *AF : Context.AffineAccesses[BasePointer])
+ AF->collectParametricTerms(*SE, Terms);
+
// Second step: find array shape.
SmallVector<const SCEV *, 4> Sizes;
SE->findArrayDimensions(Terms, Sizes);
// Third step: compute the access functions for each subscript.
for (const SCEVAddRecExpr *AF : Context.NonAffineAccesses[BasePointer]) {
+ if (Sizes.empty())
+ return invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, AF);
+
SmallVector<const SCEV *, 4> Subscripts;
- AF->computeAccessFunctions(*SE, Subscripts, Sizes);
+ if (!AF->computeAccessFunctions(*SE, Subscripts, Sizes) ||
+ Sizes.empty() || Subscripts.empty())
+ return invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, AF);
// Check that the delinearized subscripts are affine.
for (const SCEV *S : Subscripts)
@@ -363,7 +372,7 @@ ScopDetection::hasNonAffineMemoryAccesse
return invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, AF);
}
}
- return false;
+ return true;
}
bool ScopDetection::isValidMemoryAccess(Instruction &Inst,
@@ -410,6 +419,11 @@ bool ScopDetection::isValidMemoryAccess(
if (Context.NonAffineAccesses[BasePointer].size() == 0)
Context.NonAffineAccesses[BasePointer] = AFs();
Context.NonAffineAccesses[BasePointer].push_back(AF);
+ } else if (const SCEVAddRecExpr *AF =
+ dyn_cast<SCEVAddRecExpr>(AccessFunction)) {
+ if (Context.AffineAccesses[BasePointer].size() == 0)
+ Context.AffineAccesses[BasePointer] = AFs();
+ Context.AffineAccesses[BasePointer].push_back(AF);
}
// FIXME: Alias Analysis thinks IntToPtrInst aliases with alloca instructions
@@ -634,7 +648,7 @@ bool ScopDetection::allBlocksValid(Detec
if (!isValidInstruction(*I, Context))
return false;
- if (hasNonAffineMemoryAccesses(Context))
+ if (!hasAffineMemoryAccesses(Context))
return false;
return true;
Added: polly/trunk/test/ScopDetect/multidim_two_accesses_different_delinearization.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopDetect/multidim_two_accesses_different_delinearization.ll?rev=208616&view=auto
==============================================================================
--- polly/trunk/test/ScopDetect/multidim_two_accesses_different_delinearization.ll (added)
+++ polly/trunk/test/ScopDetect/multidim_two_accesses_different_delinearization.ll Mon May 12 14:02:02 2014
@@ -0,0 +1,45 @@
+; RUN: opt %loadPolly -polly-detect -analyze -polly-delinearize < %s | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Derived from the following code:
+;
+; void foo(long n, long m, double *A) {
+; for (long i = 0; i < n; i++)
+; for (long j = 0; j < m; j++)
+; *(A + i * n + j) = 1.0;
+; *(A + j * m + i) = 2.0;
+; }
+
+; CHECK-NOT: Valid Region for Scop
+
+define void @foo(i64 %n, i64 %m, double* %A) {
+entry:
+ br label %for.i
+
+for.i:
+ %i = phi i64 [ 0, %entry ], [ %i.inc, %for.i.inc ]
+ br label %for.j
+
+for.j:
+ %j = phi i64 [ 0, %for.i ], [ %j.inc, %for.j ]
+ %tmp = mul nsw i64 %i, %m
+ %vlaarrayidx.sum = add i64 %j, %tmp
+ %arrayidx = getelementptr inbounds double* %A, i64 %vlaarrayidx.sum
+ store double 1.0, double* %arrayidx
+ %tmp1 = mul nsw i64 %j, %n
+ %vlaarrayidx.sum1 = add i64 %i, %tmp1
+ %arrayidx1 = getelementptr inbounds double* %A, i64 %vlaarrayidx.sum1
+ store double 1.0, double* %arrayidx1
+ %j.inc = add nsw i64 %j, 1
+ %j.exitcond = icmp eq i64 %j.inc, %m
+ br i1 %j.exitcond, label %for.i.inc, label %for.j
+
+for.i.inc:
+ %i.inc = add nsw i64 %i, 1
+ %i.exitcond = icmp eq i64 %i.inc, %n
+ br i1 %i.exitcond, label %end, label %for.i
+
+end:
+ ret void
+}
More information about the llvm-commits
mailing list