Bug 1516738 - Specialize x86 code generation for byte register. r=jseward, a=RyanVM
authorLars T Hansen <lhansen@mozilla.com>
Wed, 02 Jan 2019 09:45:55 +0100
changeset 506528 8da001054d078428a9a356caa00ce93957075aa3
parent 506527 2641666a95ba71d2fad2fcfd48bd13f8f6f0adef
child 506529 b40748b139c2fc7f87de2ef0ddd9845ca3221211
push id10448
push userryanvm@gmail.com
push dateFri, 04 Jan 2019 19:56:55 +0000
treeherdermozilla-beta@8da001054d07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjseward, RyanVM
bugs1516738
milestone65.0
Bug 1516738 - Specialize x86 code generation for byte register. r=jseward, a=RyanVM
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
@@ -7128,16 +7128,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);