ScopDetect: Use getPointerBase to get the base pointer

Previously we allowed in access functions only a single SCEVUnknown, which later
became the base address. We now use getPointerBase() to derive the base address
and all remaining unknowns are handled as parameters. This allows us to handle
cases like A[b+c];

llvm-svn: 144278
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 25811f0..17f43ce 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -56,6 +56,7 @@
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/RegionIterator.h"
 #include "llvm/Analysis/ScalarEvolution.h"
+#include "llvm/Analysis/ScalarEvolutionExpressions.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Assembly/Writer.h"
 
@@ -213,10 +214,26 @@
                                         DetectionContext &Context) const {
   Value *Ptr = getPointerOperand(Inst), *BasePtr;
   const SCEV *AccessFunction = SE->getSCEV(Ptr);
+  const SCEVUnknown *BasePointer;
+  const Value *BaseValue;
 
-  if (!isAffineExpr(&Context.CurRegion, AccessFunction, *SE, &BasePtr))
+  BasePointer = dyn_cast<SCEVUnknown>(SE->getPointerBase(AccessFunction));
+
+  if (!BasePointer)
+    INVALID(AffFunc, "No base pointer");
+
+  BaseValue = BasePointer->getValue();
+
+  if (isa<UndefValue>(BaseValue))
+    INVALID(AffFunc, "Undefined base pointer");
+
+  AccessFunction = SE->getMinusSCEV(AccessFunction, BasePointer);
+
+  if (!isAffineExpr(&Context.CurRegion, AccessFunction, *SE))
     INVALID(AffFunc, "Bad memory address " << *AccessFunction);
 
+  BasePtr = BasePointer->getValue();
+
   // FIXME: Alias Analysis thinks IntToPtrInst aliases with alloca instructions
   // created by IndependentBlocks Pass.
   if (isa<IntToPtrInst>(BasePtr))