Test control flow instruction with optimizing compiler.

Add support for basic instructions to implement these tests.

Change-Id: I3870bf9301599043b3511522bb49dc6364c9b4c0
diff --git a/compiler/optimizing/builder.cc b/compiler/optimizing/builder.cc
index f89583d..beccf01 100644
--- a/compiler/optimizing/builder.cc
+++ b/compiler/optimizing/builder.cc
@@ -44,15 +44,14 @@
   graph_->SetNumberOfInVRegs(number_of_parameters);
   const char* shorty = dex_compilation_unit_->GetShorty();
   int locals_index = locals_.Size() - number_of_parameters;
-  HBasicBlock* first_block = entry_block_->GetSuccessors()->Get(0);
   int parameter_index = 0;
 
   if (!dex_compilation_unit_->IsStatic()) {
     // Add the implicit 'this' argument, not expressed in the signature.
     HParameterValue* parameter = new (arena_) HParameterValue(parameter_index++);
-    first_block->AddInstruction(parameter);
+    entry_block_->AddInstruction(parameter);
     HLocal* local = GetLocalAt(locals_index++);
-    first_block->AddInstruction(new (arena_) HStoreLocal(local, parameter));
+    entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter));
     number_of_parameters--;
   }
 
@@ -68,11 +67,11 @@
       default: {
         // integer and reference parameters.
         HParameterValue* parameter = new (arena_) HParameterValue(parameter_index++);
-        first_block->AddInstruction(parameter);
+        entry_block_->AddInstruction(parameter);
         HLocal* local = GetLocalAt(locals_index++);
         // Store the parameter value in the local that the dex code will use
         // to reference that parameter.
-        first_block->AddInstruction(new (arena_) HStoreLocal(local, parameter));
+        entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter));
         break;
       }
     }
@@ -87,6 +86,24 @@
   return true;
 }
 
+template<typename T>
+void HGraphBuilder::If_22t(const Instruction& instruction, int32_t dex_offset, bool is_not) {
+  HInstruction* first = LoadLocal(instruction.VRegA());
+  HInstruction* second = LoadLocal(instruction.VRegB());
+  current_block_->AddInstruction(new (arena_) T(first, second));
+  if (is_not) {
+    current_block_->AddInstruction(new (arena_) HNot(current_block_->GetLastInstruction()));
+  }
+  current_block_->AddInstruction(new (arena_) HIf(current_block_->GetLastInstruction()));
+  HBasicBlock* target = FindBlockStartingAt(instruction.GetTargetOffset() + dex_offset);
+  DCHECK(target != nullptr);
+  current_block_->AddSuccessor(target);
+  target = FindBlockStartingAt(dex_offset + instruction.SizeInCodeUnits());
+  DCHECK(target != nullptr);
+  current_block_->AddSuccessor(target);
+  current_block_ = nullptr;
+}
+
 HGraph* HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) {
   if (!CanHandleCodeItem(code_item)) {
     return nullptr;
@@ -238,6 +255,19 @@
       break;
     }
 
+    case Instruction::CONST_16: {
+      int32_t register_index = instruction.VRegA();
+      HIntConstant* constant = GetConstant(instruction.VRegB_21s());
+      UpdateLocal(register_index, constant);
+      break;
+    }
+
+    case Instruction::MOVE: {
+      HInstruction* value = LoadLocal(instruction.VRegB());
+      UpdateLocal(instruction.VRegA(), value);
+      break;
+    }
+
     case Instruction::RETURN_VOID: {
       current_block_->AddInstruction(new (arena_) HReturnVoid());
       current_block_->AddSuccessor(exit_block_);
@@ -246,17 +276,12 @@
     }
 
     case Instruction::IF_EQ: {
-      HInstruction* first = LoadLocal(instruction.VRegA());
-      HInstruction* second = LoadLocal(instruction.VRegB());
-      current_block_->AddInstruction(new (arena_) HEqual(first, second));
-      current_block_->AddInstruction(new (arena_) HIf(current_block_->GetLastInstruction()));
-      HBasicBlock* target = FindBlockStartingAt(instruction.GetTargetOffset() + dex_offset);
-      DCHECK(target != nullptr);
-      current_block_->AddSuccessor(target);
-      target = FindBlockStartingAt(dex_offset + instruction.SizeInCodeUnits());
-      DCHECK(target != nullptr);
-      current_block_->AddSuccessor(target);
-      current_block_ = nullptr;
+      If_22t<HEqual>(instruction, dex_offset, false);
+      break;
+    }
+
+    case Instruction::IF_NE: {
+      If_22t<HEqual>(instruction, dex_offset, true);
       break;
     }