Fix bug in register allocator.

When an input can be a constant, there is no need to
do a move.

Fix 003-omnibus-opcodes failure.

Change-Id: Ic40f99d3ae889505c1d2be8665f8521c2ebb5feb
diff --git a/compiler/optimizing/register_allocator.cc b/compiler/optimizing/register_allocator.cc
index 54888ba..b451ef4 100644
--- a/compiler/optimizing/register_allocator.cc
+++ b/compiler/optimizing/register_allocator.cc
@@ -738,9 +738,14 @@
   return instruction->GetLifetimePosition() == kInputMoveLifetimePosition;
 }
 
+static bool IsValidDestination(Location destination) {
+  return destination.IsRegister() || destination.IsStackSlot() || destination.IsDoubleStackSlot();
+}
+
 void RegisterAllocator::AddInputMoveFor(HInstruction* instruction,
                                         Location source,
                                         Location destination) const {
+  DCHECK(IsValidDestination(destination));
   if (source.Equals(destination)) return;
 
   DCHECK(instruction->AsPhi() == nullptr);
@@ -763,6 +768,7 @@
 void RegisterAllocator::InsertParallelMoveAt(size_t position,
                                              Location source,
                                              Location destination) const {
+  DCHECK(IsValidDestination(destination));
   if (source.Equals(destination)) return;
 
   HInstruction* at = liveness_.GetInstructionFromPosition(position / 2);
@@ -806,6 +812,7 @@
 void RegisterAllocator::InsertParallelMoveAtExitOf(HBasicBlock* block,
                                                    Location source,
                                                    Location destination) const {
+  DCHECK(IsValidDestination(destination));
   if (source.Equals(destination)) return;
 
   DCHECK_EQ(block->GetSuccessors().Size(), 1u);
@@ -828,6 +835,7 @@
 void RegisterAllocator::InsertParallelMoveAtEntryOf(HBasicBlock* block,
                                                     Location source,
                                                     Location destination) const {
+  DCHECK(IsValidDestination(destination));
   if (source.Equals(destination)) return;
 
   HInstruction* first = block->GetFirstInstruction();
@@ -845,6 +853,7 @@
 void RegisterAllocator::InsertMoveAfter(HInstruction* instruction,
                                         Location source,
                                         Location destination) const {
+  DCHECK(IsValidDestination(destination));
   if (source.Equals(destination)) return;
 
   if (instruction->AsPhi() != nullptr) {
@@ -892,7 +901,7 @@
         Location expected_location = locations->InAt(use->GetInputIndex());
         if (expected_location.IsUnallocated()) {
           locations->SetInAt(use->GetInputIndex(), source);
-        } else {
+        } else if (!expected_location.IsConstant()) {
           AddInputMoveFor(use->GetUser(), source, expected_location);
         }
       }