From dfd88da8cffd29b58c1039147ed35a2b3191632c Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Tue, 23 Jun 2020 10:14:07 +0000 Subject: [PATCH] Bug 1646975 - Transpile ToString instructions. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D80359 --- js/src/jit-test/tests/warp/booleantostring.js | 9 +++++ js/src/jit/CacheIROps.yaml | 6 +-- js/src/jit/WarpCacheIRTranspiler.cpp | 38 +++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 js/src/jit-test/tests/warp/booleantostring.js diff --git a/js/src/jit-test/tests/warp/booleantostring.js b/js/src/jit-test/tests/warp/booleantostring.js new file mode 100644 index 000000000000..39ff0b1b6d0e --- /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"); + } +} diff --git a/js/src/jit/CacheIROps.yaml b/js/src/jit/CacheIROps.yaml index 1db651dec92c..59aec63ef404 100644 --- a/js/src/jit/CacheIROps.yaml +++ b/js/src/jit/CacheIROps.yaml @@ -1046,7 +1046,7 @@ - name: CallInt32ToString shared: true - transpile: false + transpile: true cost_estimate: 4 args: input: Int32Id @@ -1054,7 +1054,7 @@ - name: CallNumberToString shared: true - transpile: false + transpile: true cost_estimate: 4 args: input: NumberId @@ -1062,7 +1062,7 @@ - name: BooleanToString shared: true - transpile: false + transpile: true cost_estimate: 2 args: input: Int32Id diff --git a/js/src/jit/WarpCacheIRTranspiler.cpp b/js/src/jit/WarpCacheIRTranspiler.cpp index 7ca97e9adfee..117d2937ad45 100644 --- a/js/src/jit/WarpCacheIRTranspiler.cpp +++ b/js/src/jit/WarpCacheIRTranspiler.cpp @@ -108,6 +108,8 @@ class MOZ_RAII WarpCacheIRTranspiler : public WarpBuilderShared { MOZ_MUST_USE bool emitGuardTo(ValOperandId inputId, MIRType type); + MOZ_MUST_USE bool emitToString(OperandId inputId, StringOperandId resultId); + template MOZ_MUST_USE bool emitDoubleBinaryArithResult(NumberOperandId lhsId, NumberOperandId rhsId); @@ -486,6 +488,42 @@ bool WarpCacheIRTranspiler::emitGuardToInt32ModUint32(ValOperandId valId, 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);