Bug 1538692 - Part 2: Support relational string comparison in CacheIR. r=mgaudet

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
André Bargull 2019-03-26 14:49:35 +00:00
parent 0e674b927f
commit 3d274f3ace
4 changed files with 93 additions and 11 deletions

View File

@ -224,3 +224,60 @@ warmup(String_Number_SEQ1, [["1.4",2, false], ["1",1, false], [3,"4", false],
var String_Number_SNEQ1 = (a, b) => { return a !== b; }
warmup(String_Number_SNEQ1, [["1.4",2, true], ["1",1, true], [3,"4", true],
[-1024, "-1023", true], [1.2, "1.2", true]]);
// String + String
var String_String_GT1 = (a, b) => a > b;
warmup(String_String_GT1, [["", "", false], ["a", "a", false], ["aa", "aa", false],
["a", "", true], ["", "a", false],
["a", "b", false], ["b", "a", true],
["a", "ab", false], ["ab", "a", true],
]);
var String_String_GE1 = (a, b) => a >= b;
warmup(String_String_GE1, [["", "", true], ["a", "a", true], ["aa", "aa", true],
["a", "", true], ["", "a", false],
["a", "b", false], ["b", "a", true],
["a", "ab", false], ["ab", "a", true],
]);
var String_String_LT1 = (a, b) => a < b;
warmup(String_String_LT1, [["", "", false], ["a", "a", false], ["aa", "aa", false],
["a", "", false], ["", "a", true],
["a", "b", true], ["b", "a", false],
["a", "ab", true], ["ab", "a", false],
]);
var String_String_LE1 = (a, b) => a <= b;
warmup(String_String_LE1, [["", "", true], ["a", "a", true], ["aa", "aa", true],
["a", "", false], ["", "a", true],
["a", "b", true], ["b", "a", false],
["a", "ab", true], ["ab", "a", false],
]);
var String_String_EQ1 = (a, b) => a == b;
warmup(String_String_EQ1, [["", "", true], ["a", "a", true], ["aa", "aa", true],
["a", "", false], ["", "a", false],
["a", "b", false], ["b", "a", false],
["a", "ab", false], ["ab", "a", false],
]);
var String_String_SEQ1 = (a, b) => a === b;
warmup(String_String_SEQ1, [["", "", true], ["a", "a", true], ["aa", "aa", true],
["a", "", false], ["", "a", false],
["a", "b", false], ["b", "a", false],
["a", "ab", false], ["ab", "a", false],
]);
var String_String_NE1 = (a, b) => a != b;
warmup(String_String_NE1, [["", "", false], ["a", "a", false], ["aa", "aa", false],
["a", "", true], ["", "a", true],
["a", "b", true], ["b", "a", true],
["a", "ab", true], ["ab", "a", true],
]);
var String_String_SNE1 = (a, b) => a !== b;
warmup(String_String_SNE1, [["", "", false], ["a", "a", false], ["aa", "aa", false],
["a", "", true], ["", "a", true],
["a", "b", true], ["b", "a", true],
["a", "ab", true], ["ab", "a", true],
]);

View File

@ -923,14 +923,27 @@ bool BaselineCacheIRCompiler::emitCompareStringResult() {
AutoStubFrame stubFrame(*this);
stubFrame.enter(masm, scratch);
// Push the operands in reverse order for JSOP_LE and JSOP_GT:
// - |left <= right| is implemented as |right >= left|.
// - |left > right| is implemented as |right < left|.
if (op == JSOP_LE || op == JSOP_GT) {
masm.Push(left);
masm.Push(right);
} else {
masm.Push(right);
masm.Push(left);
}
using Fn = bool (*)(JSContext*, HandleString, HandleString, bool*);
if (op == JSOP_EQ || op == JSOP_STRICTEQ) {
callVM<Fn, jit::StringsEqual<true>>(masm);
} else {
} else if (op == JSOP_NE || op == JSOP_STRICTNE) {
callVM<Fn, jit::StringsEqual<false>>(masm);
} else if (op == JSOP_LT || op == JSOP_GT) {
callVM<Fn, jit::StringsCompare<true>>(masm);
} else {
MOZ_ASSERT(op == JSOP_LE || op == JSOP_GE);
callVM<Fn, jit::StringsCompare<false>>(masm);
}
stubFrame.leave(masm);

View File

@ -5465,8 +5465,6 @@ CompareIRGenerator::CompareIRGenerator(JSContext* cx, HandleScript script,
bool CompareIRGenerator::tryAttachString(ValOperandId lhsId,
ValOperandId rhsId) {
MOZ_ASSERT(IsEqualityOp(op_));
if (!lhsVal_.isString() || !rhsVal_.isString()) {
return false;
}
@ -5761,9 +5759,6 @@ bool CompareIRGenerator::tryAttachStub() {
// - {Bool} x {Double}.
// - {Object} x {String, Symbol, Bool, Number}.
if (IsEqualityOp(op_)) {
if (tryAttachString(lhsId, rhsId)) {
return true;
}
if (tryAttachObject(lhsId, rhsId)) {
return true;
}
@ -5810,6 +5805,9 @@ bool CompareIRGenerator::tryAttachStub() {
if (tryAttachNumber(lhsId, rhsId)) {
return true;
}
if (tryAttachString(lhsId, rhsId)) {
return true;
}
if (tryAttachStringNumber(lhsId, rhsId)) {
return true;

View File

@ -1322,14 +1322,28 @@ bool IonCacheIRCompiler::emitCompareStringResult() {
masm.bind(&slow);
prepareVMCall(masm, save);
// Push the operands in reverse order for JSOP_LE and JSOP_GT:
// - |left <= right| is implemented as |right >= left|.
// - |left > right| is implemented as |right < left|.
if (op == JSOP_LE || op == JSOP_GT) {
masm.Push(left);
masm.Push(right);
} else {
masm.Push(right);
masm.Push(left);
}
using Fn = bool (*)(JSContext*, HandleString, HandleString, bool*);
if (op == JSOP_EQ || op == JSOP_STRICTEQ) {
callVM<Fn, jit::StringsEqual<true>>(masm);
} else {
} else if (op == JSOP_NE || op == JSOP_STRICTNE) {
callVM<Fn, jit::StringsEqual<false>>(masm);
} else if (op == JSOP_LT || op == JSOP_GT) {
callVM<Fn, jit::StringsCompare<true>>(masm);
} else {
MOZ_ASSERT(op == JSOP_LE || op == JSOP_GE);
callVM<Fn, jit::StringsCompare<false>>(masm);
}
masm.storeCallBoolResult(output.typedReg().gpr());