Bug 1646975 - Transpile ToString instructions. r=jandem
authorTom Schuster <evilpies@gmail.com>
Tue, 23 Jun 2020 10:14:07 +0000
changeset 536900 cc336f1c478f32579fdfdc7ede98e58338911973
parent 536899 c8be339dbdd9d5a779499554a003bf133d4bf154
child 536901 01748f8073f08ce246379df00889d6bda86b7c01
push id37533
push userdluca@mozilla.com
push dateTue, 23 Jun 2020 21:38:40 +0000
treeherdermozilla-central@d48aa0f0aa0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1646975
milestone79.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 1646975 - Transpile ToString instructions. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D80359
js/src/jit-test/tests/warp/booleantostring.js
js/src/jit/CacheIROps.yaml
js/src/jit/WarpCacheIRTranspiler.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/warp/booleantostring.js
@@ -0,0 +1,9 @@
+var a = [true, false];
+for (var i = 0; i < 1e4; i++) {
+	var str = "x: " + a[i & 1];
+	if (i & 1) {
+		assertEq(str, "x: false");
+	} else {
+		assertEq(str, "x: true");
+	}
+}
--- a/js/src/jit/CacheIROps.yaml
+++ b/js/src/jit/CacheIROps.yaml
@@ -1041,33 +1041,33 @@
   args:
     obj: ObjId
     id: Int32Id
     rhs: ValId
     strict: BoolImm
 
 - name: CallInt32ToString
   shared: true
-  transpile: false
+  transpile: true
   cost_estimate: 4
   args:
     input: Int32Id
     result: StringId
 
 - name: CallNumberToString
   shared: true
-  transpile: false
+  transpile: true
   cost_estimate: 4
   args:
     input: NumberId
     result: StringId
 
 - name: BooleanToString
   shared: true
-  transpile: false
+  transpile: true
   cost_estimate: 2
   args:
     input: Int32Id
     result: StringId
 
 - name: CallScriptedFunction
   shared: false
   transpile: true
--- a/js/src/jit/WarpCacheIRTranspiler.cpp
+++ b/js/src/jit/WarpCacheIRTranspiler.cpp
@@ -103,16 +103,18 @@ class MOZ_RAII WarpCacheIRTranspiler : p
     return static_cast<int32_t>(readStubWord(offset));
   }
   uint32_t uint32StubField(uint32_t offset) {
     return static_cast<uint32_t>(readStubWord(offset));
   }
 
   MOZ_MUST_USE bool emitGuardTo(ValOperandId inputId, MIRType type);
 
+  MOZ_MUST_USE bool emitToString(OperandId inputId, StringOperandId resultId);
+
   template <typename T>
   MOZ_MUST_USE bool emitDoubleBinaryArithResult(NumberOperandId lhsId,
                                                 NumberOperandId rhsId);
 
   template <typename T>
   MOZ_MUST_USE bool emitInt32BinaryArithResult(Int32OperandId lhsId,
                                                Int32OperandId rhsId);
 
@@ -481,16 +483,52 @@ bool WarpCacheIRTranspiler::emitGuardToI
                                                       Int32OperandId resultId) {
   MDefinition* input = getOperand(valId);
   auto* ins = MTruncateToInt32::New(alloc(), input);
   add(ins);
 
   return defineOperand(resultId, ins);
 }
 
+bool WarpCacheIRTranspiler::emitToString(OperandId inputId,
+                                         StringOperandId resultId) {
+  MDefinition* input = getOperand(inputId);
+  auto* ins =
+      MToString::New(alloc(), input, MToString::SideEffectHandling::Bailout);
+  add(ins);
+
+  return defineOperand(resultId, ins);
+}
+
+bool WarpCacheIRTranspiler::emitCallInt32ToString(Int32OperandId inputId,
+                                                  StringOperandId resultId) {
+  return emitToString(inputId, resultId);
+}
+
+bool WarpCacheIRTranspiler::emitCallNumberToString(NumberOperandId inputId,
+                                                   StringOperandId resultId) {
+  return emitToString(inputId, resultId);
+}
+
+bool WarpCacheIRTranspiler::emitBooleanToString(Int32OperandId inputId,
+                                                StringOperandId resultId) {
+  MDefinition* input = getOperand(inputId);
+
+  // Remove the MToIntegerInt32 instruction added by emitGuardToBoolean.
+  // TODO: Bug 1647602 add a BooleanOperandId.
+  MDefinition* boolean = input->toToIntegerInt32()->input();
+  MOZ_ASSERT(boolean->type() == MIRType::Boolean);
+
+  auto* ins =
+      MToString::New(alloc(), boolean, MToString::SideEffectHandling::Bailout);
+  add(ins);
+
+  return defineOperand(resultId, ins);
+}
+
 bool WarpCacheIRTranspiler::emitLoadInt32Result(Int32OperandId valId) {
   MDefinition* val = getOperand(valId);
   MOZ_ASSERT(val->type() == MIRType::Int32);
   pushResult(val);
   return true;
 }
 
 bool WarpCacheIRTranspiler::emitLoadDoubleResult(NumberOperandId valId) {