scop detection: run isValidCFG as early as possible

to discard regions with invalid CFG before going through the contents of the
basic blocks

llvm-svn: 183797
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 343ac83..335418f 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -390,9 +390,6 @@
 
 bool ScopDetection::isValidBasicBlock(BasicBlock &BB,
                                       DetectionContext &Context) const {
-  if (!isValidCFG(BB, Context))
-    return false;
-
   // Check all instructions, except the terminator instruction.
   for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I)
     if (!isValidInstruction(*I, Context))
@@ -542,6 +539,11 @@
 
   for (Region::block_iterator I = R.block_begin(), E = R.block_end(); I != E;
        ++I)
+    if (!isValidCFG(**I, Context))
+      return false;
+
+  for (Region::block_iterator I = R.block_begin(), E = R.block_end(); I != E;
+       ++I)
     if (!isValidBasicBlock(**I, Context))
       return false;