Bug 1516738 - specialize x86 code generation for byte register. r=jseward
authorLars T Hansen <lhansen@mozilla.com>
Wed, 02 Jan 2019 09:45:55 +0100
changeset 509533 00ff999d70b351e37c404ee4e1cab6f8cf9cfe43
parent 509532 f391e2edd0f904993cf7e04f6b063ff6def6625c
child 509534 33c57870ca18692ea8bf646d3f341263893142c7
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjseward
bugs1516738
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1516738 - specialize x86 code generation for byte register. r=jseward
js/src/jit-test/tests/wasm/regress/baseline-extend8.js
js/src/wasm/WasmBaselineCompile.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/regress/baseline-extend8.js
@@ -0,0 +1,34 @@
+// This attempts to test that we can do an 8-bit sign extend no matter what the
+// source register.  This test is arguably somewhat tied to the baseline
+// compiler's register allocator, but is still appropriate for most simple
+// register allocators.  It works by filling an increasing number of registers
+// with values so as eventually to force the source operand for extend8_s into a
+// register that does not have a byte personality.
+
+for ( let i=0; i < 8; i++) {
+    let txt =
+        `(module
+           (func (export "f") (param i32) (result i32)
+           ${adds(i)}
+           (set_local 0 (i32.extend8_s (i32.add (get_local 0) (i32.const 1))))
+           ${drops(i)}
+           (get_local 0)))`;
+    let ins = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(txt)));
+    assertEq(ins.exports.f(254), -1);
+}
+
+function adds(n) {
+    let s = ""
+    for ( let i=0; i < n; i++ )
+        s += "(i32.add (get_local 0) (i32.const 1))\n";
+    return s;
+}
+
+function drops(n) {
+    let s = "";
+    for ( let i=0; i < n; i++ )
+        s += "drop\n";
+    return s;
+}
+
+
--- a/js/src/wasm/WasmBaselineCompile.cpp
+++ b/js/src/wasm/WasmBaselineCompile.cpp
@@ -7765,16 +7765,25 @@ void BaseCompiler::emitWrapI64ToI32() {
   RegI32 rd = fromI64(rs);
   masm.move64To32(rs, rd);
   freeI64Except(rs, rd);
   pushI32(rd);
 }
 
 void BaseCompiler::emitExtendI32_8() {
   RegI32 r = popI32();
+#ifdef JS_CODEGEN_X86
+  if (!ra.isSingleByteI32(r)) {
+    ScratchI8 scratch(*this);
+    moveI32(r, scratch);
+    masm.move8SignExtend(scratch, r);
+    pushI32(r);
+    return;
+  }
+#endif
   masm.move8SignExtend(r, r);
   pushI32(r);
 }
 
 void BaseCompiler::emitExtendI32_16() {
   RegI32 r = popI32();
   masm.move16SignExtend(r, r);
   pushI32(r);