[polly] r243515 - Do not detect scops that are delinearized to arrays with "undef" size

Tobias Grosser tobias at grosser.es
Wed Jul 29 06:52:05 PDT 2015


Author: grosser
Date: Wed Jul 29 08:52:05 2015
New Revision: 243515

URL: http://llvm.org/viewvc/llvm-project?rev=243515&view=rev
Log:
Do not detect scops that are delinearized to arrays with "undef" size

Such codes are not interesting to optimize and most likely never appear in the
normal compilation flow. However, they show up during test case reduction with
bugpoint and trigger -- without this change -- an assert in
polly::MemoryAccess::foldAccess(). It is better to detect them in
ScopDetection itself and just bail out.

Contributed-by:  Utpal Bora  <cs14mtech11017 at iith.ac.in>

Reviewers: grosser

Subscribers: pollydev, llvm-commits

Differential Revision: http://reviews.llvm.org/D11425

Added:
    polly/trunk/test/ScopDetect/restrict-undef-size-scopdetect.ll
Modified:
    polly/trunk/lib/Analysis/ScopDetection.cpp

Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=243515&r1=243514&r2=243515&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Wed Jul 29 08:52:05 2015
@@ -512,11 +512,21 @@ bool ScopDetection::hasAffineMemoryAcces
                             Context.ElementSize[BasePointer]);
 
     if (!AllowNonAffine)
-      for (const SCEV *DelinearizedSize : Shape->DelinearizedSizes)
+      for (const SCEV *DelinearizedSize : Shape->DelinearizedSizes) {
+        if (auto *Unknown = dyn_cast<SCEVUnknown>(DelinearizedSize)) {
+          auto *value = dyn_cast<Value>(Unknown->getValue());
+          if (isa<UndefValue>(value)) {
+            invalid<ReportDifferentArrayElementSize>(
+                Context, /*Assert=*/true,
+                Context.Accesses[BasePointer].front().first, BaseValue);
+            return false;
+          }
+        }
         if (hasScalarDepsInsideRegion(DelinearizedSize, &CurRegion))
           invalid<ReportNonAffineAccess>(
               Context, /*Assert=*/true, DelinearizedSize,
               Context.Accesses[BasePointer].front().first, BaseValue);
+      }
 
     // No array shape derived.
     if (Shape->DelinearizedSizes.empty()) {

Added: polly/trunk/test/ScopDetect/restrict-undef-size-scopdetect.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopDetect/restrict-undef-size-scopdetect.ll?rev=243515&view=auto
==============================================================================
--- polly/trunk/test/ScopDetect/restrict-undef-size-scopdetect.ll (added)
+++ polly/trunk/test/ScopDetect/restrict-undef-size-scopdetect.ll Wed Jul 29 08:52:05 2015
@@ -0,0 +1,33 @@
+; RUN: opt %loadPolly -polly-detect -analyze  < %s | FileCheck %s
+; CHECK-NOT: Valid Region for Scop:
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+%struct.bar = type { i32, [4 x i32] }
+
+define void @f(%struct.bar* %arg) {
+bb:
+  %tmp = alloca [4 x i32], align 16
+  br label %bb1
+
+bb1:                                              ; preds = %bb8, %bb
+  %tmp2 = phi i64 [ 0, %bb ], [ %tmp9, %bb8 ]
+  br i1 false, label %bb3, label %bb6
+
+bb3:                                              ; preds = %bb1
+  %tmp4 = getelementptr inbounds [4 x i32], [4 x i32]* %tmp, i64 0, i64 0
+  %tmp5 = load i32, i32* %tmp4
+  br label %bb8
+
+bb6:                                              ; preds = %bb1
+  %tmp7 = getelementptr inbounds %struct.bar, %struct.bar* %arg, i64 0, i32 1, i64 undef
+  store i32 42, i32* %tmp7
+  br label %bb8
+
+bb8:                                              ; preds = %bb6, %bb3
+  %tmp9 = add nuw nsw i64 %tmp2, 1
+  br i1 false, label %bb1, label %bb10
+
+bb10:                                             ; preds = %bb8
+  ret void
+}





More information about the llvm-commits mailing list