Bug 1492995 - Adding CacheIR support for String + Boolean. r=mgaudet

Differential Revision: https://phabricator.services.mozilla.com/D27376

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Adam Holm 2019-04-23 20:46:14 +00:00
parent a989ba39e4
commit 6ef12c56b1
6 changed files with 74 additions and 0 deletions

View File

@ -50,6 +50,11 @@ var funAdd6 = (a, b) => { return a + b; }
warmup(funAdd6, [["x", 10, "x10"], [10, "bba", "10bba"], ["x", 1.2, "x1.2"],
[1.2, "bba", "1.2bba"]]);
// Add: String Boolean
var funAddStrBool = (a, b) => { return a + b; }
warmup(funAddStrBool, [[true, "true", "truetrue"], [false, "true", "falsetrue"],
["a string", true, "a stringtrue"]]);
// Sub Int32
var funSub1 = (a, b) => { return a - b; }
warmup(funSub1, [[7, 0, 7], [7, 8, -1], [4294967295, 2, 4294967293], [0,0,0]]);

View File

@ -284,6 +284,7 @@ static MIRType ParseCacheIRStub(ICStub* stub) {
case CacheOp::CallStringConcatResult:
case CacheOp::CallStringObjectConcatResult:
case CacheOp::CallInt32ToString:
case CacheOp::BooleanToString:
case CacheOp::CallNumberToString:
return MIRType::String;
case CacheOp::DoubleAddResult:

View File

@ -6403,6 +6403,11 @@ bool BinaryArithIRGenerator::tryAttachStub() {
return true;
}
// String + Boolean
if (tryAttachStringBooleanConcat()) {
return true;
}
trackAttached(IRGenerator::NotAttached);
return false;
}
@ -6621,6 +6626,39 @@ bool BinaryArithIRGenerator::tryAttachStringNumberConcat() {
return true;
}
bool BinaryArithIRGenerator::tryAttachStringBooleanConcat() {
// Only Addition
if (op_ != JSOP_ADD) {
return false;
}
if ((!lhs_.isString() || !rhs_.isBoolean()) &&
(!lhs_.isBoolean() || !rhs_.isString())) {
return false;
}
ValOperandId lhsId(writer.setInputOperandId(0));
ValOperandId rhsId(writer.setInputOperandId(1));
auto guardToString = [&](ValOperandId id, HandleValue v) {
if (v.isString()) {
return writer.guardIsString(id);
}
MOZ_ASSERT(v.isBoolean());
writer.guardIsBoolean(id);
return writer.callBooleanToString(id);
};
StringOperandId lhsStrId = guardToString(lhsId, lhs_);
StringOperandId rhsStrId = guardToString(rhsId, rhs_);
writer.callStringConcatResult(lhsStrId, rhsStrId);
writer.returnFromIC();
trackAttached("BinaryArith.StringBooleanConcat");
return true;
}
bool BinaryArithIRGenerator::tryAttachStringConcat() {
// Only Addition
if (op_ != JSOP_ADD) {

View File

@ -294,6 +294,7 @@ extern const uint32_t ArgLengths[];
_(CallAddOrUpdateSparseElementHelper, Id, Id, Id, Byte) \
_(CallInt32ToString, Id, Id) \
_(CallNumberToString, Id, Id) \
_(BooleanToString, Id, Id) \
_(CallScriptedFunction, Id, Id, Byte) \
_(CallNativeFunction, Id, Id, Byte, IF_SIMULATOR(Field, Byte)) \
_(CallClassHook, Id, Id, Byte, Field) \
@ -1297,6 +1298,12 @@ class MOZ_RAII CacheIRWriter : public JS::CustomAutoRooter {
writeOperandId(res);
return res;
}
StringOperandId callBooleanToString(ValOperandId id) {
StringOperandId res(nextOperandId_++);
writeOpWithOperandId(CacheOp::BooleanToString, id);
writeOperandId(res);
return res;
}
void callScriptedFunction(ObjOperandId calleeId, Int32OperandId argc,
CallFlags flags) {
writeOpWithOperandId(CacheOp::CallScriptedFunction, calleeId);
@ -2440,6 +2447,7 @@ class MOZ_RAII BinaryArithIRGenerator : public IRGenerator {
bool tryAttachStringConcat();
bool tryAttachStringObjectConcat();
bool tryAttachStringNumberConcat();
bool tryAttachStringBooleanConcat();
public:
BinaryArithIRGenerator(JSContext* cx, HandleScript, jsbytecode* pc,

View File

@ -4284,6 +4284,27 @@ bool CacheIRCompiler::emitCallNumberToString() {
return true;
}
bool CacheIRCompiler::emitBooleanToString() {
JitSpew(JitSpew_Codegen, __FUNCTION__);
Register boolean = allocator.useRegister(masm, reader.objOperandId());
Register result = allocator.defineRegister(masm, reader.stringOperandId());
const JSAtomState& names = cx_->names();
Label true_, done;
masm.branchTest32(Assembler::NonZero, boolean, boolean, &true_);
// False case
masm.movePtr(ImmGCPtr(names.false_), result);
masm.jump(&done);
// True case
masm.bind(&true_);
masm.movePtr(ImmGCPtr(names.true_), result);
masm.bind(&done);
return true;
}
void js::jit::LoadTypedThingData(MacroAssembler& masm, TypedThingLayout layout,
Register obj, Register result) {
switch (layout) {

View File

@ -126,6 +126,7 @@ namespace jit {
_(CallObjectHasSparseElementResult) \
_(CallInt32ToString) \
_(CallNumberToString) \
_(BooleanToString) \
_(CallIsSuspendedGeneratorResult) \
_(MetaTwoByte) \
_(WrapResult)