Optimizing compiler: ensure loop header dominates loop's blocks.

Change-Id: I6b2f1fdaac9f91dc5d9901cc2ad4c83745e90e70
diff --git a/compiler/optimizing/graph_checker.cc b/compiler/optimizing/graph_checker.cc
index b05090b..e36b1cd 100644
--- a/compiler/optimizing/graph_checker.cc
+++ b/compiler/optimizing/graph_checker.cc
@@ -20,6 +20,8 @@
 #include <map>
 #include <sstream>
 
+#include "base/bit_vector-inl.h"
+
 namespace art {
 
 void GraphChecker::VisitBasicBlock(HBasicBlock* block) {
@@ -212,6 +214,19 @@
             << num_back_edges << " back edge(s).";
       errors_.Insert(error.str());
   }
+
+  // Ensure all blocks in the loop are dominated by the loop header.
+  const ArenaBitVector& loop_blocks =
+    loop_header->GetLoopInformation()->GetBlocks();
+  for (uint32_t i : loop_blocks.Indexes()) {
+    HBasicBlock* loop_block = GetGraph()->GetBlocks().Get(i);
+    if (!loop_header->Dominates(loop_block)) {
+      std::stringstream error;
+      error << "Loop block " << loop_block->GetBlockId()
+            << " not dominated by loop header " << id;
+      errors_.Insert(error.str());
+    }
+  }
 }
 
 void SSAChecker::VisitInstruction(HInstruction* instruction) {