Bug 1665946 - Part 2: Handle Strings in CacheIR binary bit-ops. r=jandem

`string|0` is sometimes used as a "fast" way to convert strings to integers.
Ion handles this case, but Warp doesn't yet.

Depends on D90712

Differential Revision: https://phabricator.services.mozilla.com/D90713
This commit is contained in:
André Bargull 2020-09-21 06:59:27 +00:00
Родитель ea03b8e9d5
Коммит 085e1e7b96
2 изменённых файлов: 46 добавлений и 5 удалений

Просмотреть файл

@ -16,6 +16,36 @@ function test(zero, one) {
assertEq(10 ** one, 10);
assertEq(one ** 4, 1);
assertEq(10 & zero, 0);
assertEq(zero & 10, 0);
assertEq(10 & one, 0);
assertEq(one & 10, 0);
assertEq(10 | zero, 10);
assertEq(zero | 10, 10);
assertEq(10 | one, 11);
assertEq(one | 10, 11);
assertEq(10 ^ zero, 10);
assertEq(zero ^ 10, 10);
assertEq(10 ^ one, 11);
assertEq(one ^ 10, 11);
assertEq(10 << zero, 10);
assertEq(zero << 10, 0);
assertEq(10 << one, 20);
assertEq(one << 10, 1024);
assertEq(10 >> zero, 10);
assertEq(zero >> 10, 0);
assertEq(10 >> one, 5);
assertEq(one >> 10, 0);
assertEq(10 >>> zero, 10);
assertEq(zero >>> 10, 0);
assertEq(10 >>> one, 5);
assertEq(one >>> 10, 0);
}
for (var i = 0; i < 10; i++) {

Просмотреть файл

@ -10797,7 +10797,8 @@ AttachDecision BinaryArithIRGenerator::tryAttachStub() {
// Arithmetic operations with Int32 operands
TRY_ATTACH(tryAttachInt32());
// Bitwise operations with Int32/Double/Boolean/Null/Undefined operands.
// Bitwise operations with Int32/Double/Boolean/Null/Undefined/String
// operands.
TRY_ATTACH(tryAttachBitwise());
// Arithmetic operations with Double operands. This needs to come after
@ -10833,9 +10834,13 @@ AttachDecision BinaryArithIRGenerator::tryAttachBitwise() {
return AttachDecision::NoAction;
}
auto canConvert = [](const Value& val) {
return val.isNumber() || val.isBoolean() || val.isNullOrUndefined() ||
val.isString();
};
// Check guard conditions
if (!(lhs_.isNumber() || lhs_.isBoolean() || lhs_.isNullOrUndefined()) ||
!(rhs_.isNumber() || rhs_.isBoolean() || rhs_.isNullOrUndefined())) {
if (!canConvert(lhs_) || !canConvert(rhs_)) {
return AttachDecision::NoAction;
}
@ -10857,8 +10862,14 @@ AttachDecision BinaryArithIRGenerator::tryAttachBitwise() {
writer.guardIsNullOrUndefined(id);
return writer.loadInt32Constant(0);
}
MOZ_ASSERT(val.isDouble());
NumberOperandId numId = writer.guardIsNumber(id);
NumberOperandId numId;
if (val.isString()) {
StringOperandId strId = writer.guardToString(id);
numId = writer.guardStringToNumber(strId);
} else {
MOZ_ASSERT(val.isDouble());
numId = writer.guardIsNumber(id);
}
return writer.truncateDoubleToUInt32(numId);
};