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@iith.ac.in>

Reviewers: grosser

Subscribers: pollydev, llvm-commits

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

llvm-svn: 243515
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 67f5b8b..0f08fd2 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -512,11 +512,21 @@
                             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()) {