Runtime error check elimination

  Hoist runtime checks in the loop nest if they guard an "error" like event.
  Such events are recognized as blocks with an unreachable terminator or a call
  to the ubsan function that deals with out of bound accesses. Other "error"
  events can be added easily.

  We will ignore these blocks when we detect/model/optmize and code generate SCoPs
  but we will make sure that they would not have been executed using the assumption
  framework.

llvm-svn: 247310
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 45a69cf..3aa116b 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -896,14 +896,17 @@
       return false;
   }
 
-  for (BasicBlock *BB : CurRegion.blocks())
+  for (BasicBlock *BB : CurRegion.blocks()) {
+    // Do not check exception blocks as we will never include them in the SCoP.
+    if (isErrorBlock(*BB))
+      continue;
+
     if (!isValidCFG(*BB, Context) && !KeepGoing)
       return false;
-
-  for (BasicBlock *BB : CurRegion.blocks())
     for (BasicBlock::iterator I = BB->begin(), E = --BB->end(); I != E; ++I)
       if (!isValidInstruction(*I, Context) && !KeepGoing)
         return false;
+  }
 
   if (!hasAffineMemoryAccesses(Context))
     return false;