Fix BuildInvoke

The invoke should be added to the graph before
PotentiallySimplifyFakeString.

Change-Id: I2afc1d16e6dae60957e7d1386fd028e4f3a5b27a
diff --git a/compiler/optimizing/builder.cc b/compiler/optimizing/builder.cc
index d214976..1483403 100644
--- a/compiler/optimizing/builder.cc
+++ b/compiler/optimizing/builder.cc
@@ -885,20 +885,13 @@
                                            table_index);
   }
 
-  if (!SetupArgumentsForInvoke(invoke,
-                               number_of_vreg_arguments,
-                               args,
-                               register_index,
-                               is_range,
-                               descriptor,
-                               clinit_check)) {
-    return false;
-  }
-
-  current_block_->AddInstruction(invoke);
-  latest_result_ = invoke;
-
-  return true;
+  return SetupArgumentsAndAddInvoke(invoke,
+                                    number_of_vreg_arguments,
+                                    args,
+                                    register_index,
+                                    is_range,
+                                    descriptor,
+                                    clinit_check));
 }
 
 HClinitCheck* HGraphBuilder::ProcessClinitCheckForInvoke(
@@ -1047,13 +1040,13 @@
     method_load_kind, code_ptr_location, method_load_data, direct_code_ptr };
 }
 
-bool HGraphBuilder::SetupArgumentsForInvoke(HInvoke* invoke,
-                                            uint32_t number_of_vreg_arguments,
-                                            uint32_t* args,
-                                            uint32_t register_index,
-                                            bool is_range,
-                                            const char* descriptor,
-                                            HClinitCheck* clinit_check) {
+bool HGraphBuilder::SetupArgumentsAndAddInvoke(HInvoke* invoke,
+                                               uint32_t number_of_vreg_arguments,
+                                               uint32_t* args,
+                                               uint32_t register_index,
+                                               bool is_range,
+                                               const char* descriptor,
+                                               HClinitCheck* clinit_check) {
   size_t start_index = 0;
   size_t argument_index = 0;
   uint32_t descriptor_index = 1;  // Skip the return type.
@@ -1131,8 +1124,14 @@
     uint32_t orig_this_reg = is_range ? register_index : args[0];
     HInstruction* fake_string = LoadLocal(orig_this_reg, Primitive::kPrimNot);
     invoke->SetArgumentAt(argument_index, fake_string);
+    current_block_->AddInstruction(invoke);
     PotentiallySimplifyFakeString(orig_this_reg, invoke->GetDexPc(), invoke);
+  } else {
+    current_block_->AddInstruction(invoke);
   }
+
+  latest_result_ = invoke;
+
   return true;
 }
 
diff --git a/compiler/optimizing/builder.h b/compiler/optimizing/builder.h
index c179ea2..19dd944 100644
--- a/compiler/optimizing/builder.h
+++ b/compiler/optimizing/builder.h
@@ -272,13 +272,13 @@
                                                           uintptr_t direct_method,
                                                           uintptr_t direct_code);
 
-  bool SetupArgumentsForInvoke(HInvoke* invoke,
-                               uint32_t number_of_vreg_arguments,
-                               uint32_t* args,
-                               uint32_t register_index,
-                               bool is_range,
-                               const char* descriptor,
-                               HClinitCheck* clinit_check);
+  bool SetupArgumentsAndAddInvoke(HInvoke* invoke,
+                                  uint32_t number_of_vreg_arguments,
+                                  uint32_t* args,
+                                  uint32_t register_index,
+                                  bool is_range,
+                                  const char* descriptor,
+                                  HClinitCheck* clinit_check);
 
   HClinitCheck* ProcessClinitCheckForInvoke(
       uint32_t dex_pc,