x86_64: Fix wide argument increment

This patch fixes to always increment the index for a wide argument,
and fixes the index upper bound.
Otherwise, the mapping may be incorrect.

Change-Id: I0116d8fd0a0a5c1270a23129c73a9e3651132977
Signed-off-by: Chao-ying Fu <chao-ying.fu@intel.com>
Signed-off-by: Serguei Katkov <serguei.i.katkov@intel.com>
diff --git a/compiler/dex/quick/x86/target_x86.cc b/compiler/dex/quick/x86/target_x86.cc
index 078dd5a..45e5d8a 100644
--- a/compiler/dex/quick/x86/target_x86.cc
+++ b/compiler/dex/quick/x86/target_x86.cc
@@ -2150,7 +2150,8 @@
   if (in_to_reg_storage_mapping.IsThereStackMapped()) {
     RegStorage regSingle = TargetReg(kArg2);
     RegStorage regWide = RegStorage::Solo64(TargetReg(kArg3).GetReg());
-    for (int i = start_index; i <= last_mapped_in + regs_left_to_pass_via_stack; i++) {
+    for (int i = start_index;
+         i < last_mapped_in + size_of_the_last_mapped + regs_left_to_pass_via_stack; i++) {
       RegLocation rl_arg = info->args[i];
       rl_arg = UpdateRawLoc(rl_arg);
       RegStorage reg = in_to_reg_storage_mapping.Get(i);
@@ -2166,7 +2167,6 @@
               LoadValueDirectWideFixed(rl_arg, regWide);
               StoreBaseDisp(TargetReg(kSp), out_offset, regWide, k64);
             }
-            i++;
           } else {
             if (rl_arg.location == kLocPhysReg) {
               StoreBaseDisp(TargetReg(kSp), out_offset, rl_arg.reg, k32);
@@ -2179,6 +2179,9 @@
         call_state = next_call_insn(cu_, info, call_state, target_method,
                                     vtable_idx, direct_code, direct_method, type);
       }
+      if (rl_arg.wide) {
+        i++;
+      }
     }
   }
 
@@ -2190,13 +2193,15 @@
     if (reg.Valid()) {
       if (rl_arg.wide) {
         LoadValueDirectWideFixed(rl_arg, reg);
-        i++;
       } else {
         LoadValueDirectFixed(rl_arg, reg);
       }
       call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
                                direct_code, direct_method, type);
     }
+    if (rl_arg.wide) {
+      i++;
+    }
   }
 
   call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,