From bc9009a20a7b1ffbf86c8a9f880efd068024e59a Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Tue, 27 May 2014 22:42:09 +0000 Subject: [PATCH] pass element size to delinearization Instead of relying on the delinearization to infer the size of an element, compute the element size from the base address type. This is a much more precise way of computing the element size than before, as we would have mixed together the size of an element with the strides of the innermost dimension. llvm-svn: 209695 --- polly/include/polly/ScopDetection.h | 2 ++ polly/lib/Analysis/ScopDetection.cpp | 5 ++++- polly/lib/Analysis/TempScopInfo.cpp | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/polly/include/polly/ScopDetection.h b/polly/include/polly/ScopDetection.h index d9a2615..e4f8f2b 100644 --- a/polly/include/polly/ScopDetection.h +++ b/polly/include/polly/ScopDetection.h @@ -77,6 +77,7 @@ typedef std::set ParamSetType; typedef std::vector AFs; typedef std::map BaseToAFs; +typedef std::map BaseToElSize; extern bool PollyTrackFailures; extern bool PollyDelinearize; @@ -106,6 +107,7 @@ class ScopDetection : public FunctionPass { // Map a base pointer to all access functions accessing it. BaseToAFs NonAffineAccesses, AffineAccesses; + BaseToElSize ElementSize; DetectionContext(Region &R, AliasAnalysis &AA, bool Verify) : CurRegion(R), AST(AA), Verifying(Verify), Log(&R) {} diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp index c45524c..84508a2 100644 --- a/polly/lib/Analysis/ScopDetection.cpp +++ b/polly/lib/Analysis/ScopDetection.cpp @@ -363,7 +363,7 @@ bool ScopDetection::hasAffineMemoryAccesses(DetectionContext &Context) const { // Second step: find array shape. SmallVector Sizes; - SE->findArrayDimensions(Terms, Sizes); + SE->findArrayDimensions(Terms, Sizes, Context.ElementSize[BasePointer]); // Third step: compute the access functions for each subscript. for (const SCEVAddRecExpr *AF : Context.NonAffineAccesses[BasePointer]) { @@ -422,6 +422,9 @@ bool ScopDetection::isValidMemoryAccess(Instruction &Inst, return invalid(Context, /*Assert=*/true, AccessFunction); + const SCEV *ElementSize = SE->getElementSize(&Inst); + Context.ElementSize[BasePointer] = ElementSize; + // Collect all non affine memory accesses, and check whether they are linear // at the end of scop detection. That way we can delinearize all the memory // accesses to the same array in a unique step. diff --git a/polly/lib/Analysis/TempScopInfo.cpp b/polly/lib/Analysis/TempScopInfo.cpp index 042f1cb..f007e3a3 100644 --- a/polly/lib/Analysis/TempScopInfo.cpp +++ b/polly/lib/Analysis/TempScopInfo.cpp @@ -171,7 +171,9 @@ IRAccess TempScopInfo::buildIRAccess(Instruction *Inst, Loop *L, Region *R) { const SCEVAddRecExpr *AF = dyn_cast(AccessFunction); if (!IsAffine && PollyDelinearize && AF) { - const SCEV *Remainder = AF->delinearize(*SE, Subscripts, Sizes); + const SCEV *ElementSize = SE->getElementSize(Inst); + const SCEV *Remainder = + AF->delinearize(*SE, Subscripts, Sizes, ElementSize); int NSubs = Subscripts.size(); if (NSubs > 0) { -- 2.7.4