optimizing: NullCheck elimination

How it works:
- run a type analysis to propagate null information on instructions
- during the last instruction simplifier remove null checks for which
the input is known to be not null

The current type analysis is actually a nullability analysis but it will
be reused in follow up CLs to propagate type information: so it keeps
the more convenient name.

Change-Id: I54bb1d32ab24604b4d677d1ecdaf8d60a5ff5ce9
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc
index 63bc4ae..17c8f33 100644
--- a/compiler/optimizing/instruction_simplifier.cc
+++ b/compiler/optimizing/instruction_simplifier.cc
@@ -27,6 +27,7 @@
   void VisitEqual(HEqual* equal) OVERRIDE;
   void VisitArraySet(HArraySet* equal) OVERRIDE;
   void VisitTypeConversion(HTypeConversion* instruction) OVERRIDE;
+  void VisitNullCheck(HNullCheck* instruction) OVERRIDE;
 };
 
 void InstructionSimplifier::Run() {
@@ -34,6 +35,14 @@
   visitor.VisitInsertionOrder();
 }
 
+void InstructionSimplifierVisitor::VisitNullCheck(HNullCheck* null_check) {
+  HInstruction* obj = null_check->InputAt(0);
+  if (!obj->CanBeNull()) {
+    null_check->ReplaceWith(obj);
+    null_check->GetBlock()->RemoveInstruction(null_check);
+  }
+}
+
 void InstructionSimplifierVisitor::VisitSuspendCheck(HSuspendCheck* check) {
   HBasicBlock* block = check->GetBlock();
   // Currently always keep the suspend check at entry.