Fix movw on x86/x86_64 to accept any 16bits immediate.

Change-Id: I282eece0cd497431f207cec61852b4585ed3655c
diff --git a/compiler/utils/x86/assembler_x86.cc b/compiler/utils/x86/assembler_x86.cc
index a2cbd8b..4c7c4e9 100644
--- a/compiler/utils/x86/assembler_x86.cc
+++ b/compiler/utils/x86/assembler_x86.cc
@@ -248,7 +248,7 @@
   EmitOperandSizeOverride();
   EmitUint8(0xC7);
   EmitOperand(0, dst);
-  CHECK(imm.is_int16());
+  CHECK(imm.is_uint16() || imm.is_int16());
   EmitUint8(imm.value() & 0xFF);
   EmitUint8(imm.value() >> 8);
 }
diff --git a/compiler/utils/x86_64/assembler_x86_64.cc b/compiler/utils/x86_64/assembler_x86_64.cc
index ade7a13..17339ae 100644
--- a/compiler/utils/x86_64/assembler_x86_64.cc
+++ b/compiler/utils/x86_64/assembler_x86_64.cc
@@ -298,7 +298,7 @@
   EmitOptionalRex32(dst);
   EmitUint8(0xC7);
   EmitOperand(Register::RAX, dst);
-  CHECK(imm.is_int16());
+  CHECK(imm.is_uint16() || imm.is_int16());
   EmitUint8(imm.value() & 0xFF);
   EmitUint8(imm.value() >> 8);
 }
diff --git a/test/407-arrays/src/Main.java b/test/407-arrays/src/Main.java
index b5e95b0..d5c5604 100644
--- a/test/407-arrays/src/Main.java
+++ b/test/407-arrays/src/Main.java
@@ -70,6 +70,15 @@
     chars[index] = 'd';
     assertEquals('d', chars[index]);
 
+    chars[0] = 65535;
+    assertEquals(65535, chars[0]);
+    // Do an update between the two max value updates, to avoid
+    // optimizing the second away.
+    chars[index] = 0;
+    assertEquals(0, chars[index]);
+    chars[index] = 65535;
+    assertEquals(65535, chars[index]);
+
     shorts[0] = -42;
     assertEquals(-42, shorts[0]);
     shorts[index] = -84;
@@ -86,7 +95,13 @@
     Object o2 = new Object();
     objects[index] = o2;
     assertEquals(o2, objects[index]);
+    // Longs are initially not supported in the linear scan register allocator
+    // on 32bits. So we call out a long helper to ensure this method gets
+    // optimized.
+    $opt$testLongWrites(longs, index);
+  }
 
+  public static void $opt$testLongWrites(long[] longs, int index) {
     long l = -21876876876876876L;
     longs[0] = l;
     assertEquals(l, longs[0]);