Commit 1314d2b8 authored by Patrick Thier's avatar Patrick Thier Committed by Commit Bot

[interpreter] Use LdaSmi when possible.

When we know a value passed to BytecodeArrayBuilder::LoadLiteral(double)
can be encoded as a Smi, we create LdaSmi instead of LdaConstant.

Driven by a forgotten Smi::FromInt() in BytecodeGenerator, also fixed in
this CL.

Bug: v8:11278
Change-Id: I4a1ad48e2c9aff8391113812e34dae838a1a38d3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2595437Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Patrick Thier <pthier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71827}
parent cce533ba
......@@ -615,8 +615,14 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLiteral(Smi smi) {
}
BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLiteral(double value) {
size_t entry = GetConstantPoolEntry(value);
OutputLdaConstant(entry);
// If we can encode the value as a Smi, we should.
int smi;
if (DoubleToSmiInteger(value, &smi)) {
LoadLiteral(Smi::FromInt(smi));
} else {
size_t entry = GetConstantPoolEntry(value);
OutputLdaConstant(entry);
}
return *this;
}
......
......@@ -3012,7 +3012,9 @@ void BytecodeGenerator::BuildCreateArrayLiteral(
if (current != end) {
// If there are remaining elements, prepare the index register
// to store the next element, which comes from the first spread.
builder()->LoadLiteral(array_index).StoreAccumulatorInRegister(index);
builder()
->LoadLiteral(Smi::FromInt(array_index))
.StoreAccumulatorInRegister(index);
}
} else {
// In other cases, we prepare an empty array to be filled in below.
......
......@@ -144,21 +144,21 @@ bytecodes: [
B(Star), R(0),
/* 52 S> */ B(CreateArrayLiteral), U8(1), U8(1), U8(37),
B(Star), R(2),
B(LdaConstant), U8(2),
B(LdaSmi), I8(1),
/* 67 S> */ B(Star), R(1),
/* 67 E> */ B(GetIterator), R(0), U8(2), U8(4),
B(JumpIfJSReceiver), U8(7),
B(CallRuntime), U16(Runtime::kThrowSymbolIteratorInvalid), R(0), U8(0),
B(Star), R(4),
B(LdaNamedProperty), R(4), U8(3), U8(6),
B(LdaNamedProperty), R(4), U8(2), U8(6),
B(Star), R(3),
B(CallProperty0), R(3), R(4), U8(15),
B(Star), R(5),
B(JumpIfJSReceiver), U8(7),
B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), R(5), U8(1),
B(LdaNamedProperty), R(5), U8(4), U8(17),
B(LdaNamedProperty), R(5), U8(3), U8(17),
B(JumpIfToBooleanTrue), U8(19),
B(LdaNamedProperty), R(5), U8(5), U8(8),
B(LdaNamedProperty), R(5), U8(4), U8(8),
B(StaInArrayLiteral), R(2), R(1), U8(13),
B(Ldar), R(1),
B(Inc), U8(12),
......@@ -170,7 +170,6 @@ bytecodes: [
constant pool: [
ARRAY_BOILERPLATE_DESCRIPTION_TYPE,
ARRAY_BOILERPLATE_DESCRIPTION_TYPE,
Smi [1],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["next"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["done"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["value"],
......
......@@ -73,24 +73,24 @@ bytecodes: [
B(Star), R(1),
B(CreateArrayLiteral), U8(2), U8(4), U8(37),
B(Star), R(4),
B(LdaConstant), U8(3),
B(LdaSmi), I8(1),
B(Star), R(3),
/* 49 S> */ B(CreateArrayLiteral), U8(4), U8(5), U8(37),
/* 49 S> */ B(CreateArrayLiteral), U8(3), U8(5), U8(37),
B(Star), R(7),
/* 49 E> */ B(GetIterator), R(7), U8(6), U8(8),
B(Mov), R(0), R(2),
B(JumpIfJSReceiver), U8(7),
B(CallRuntime), U16(Runtime::kThrowSymbolIteratorInvalid), R(0), U8(0),
B(Star), R(6),
B(LdaNamedProperty), R(6), U8(5), U8(10),
B(LdaNamedProperty), R(6), U8(4), U8(10),
B(Star), R(5),
B(CallProperty0), R(5), R(6), U8(19),
B(Star), R(7),
B(JumpIfJSReceiver), U8(7),
B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), R(7), U8(1),
B(LdaNamedProperty), R(7), U8(6), U8(21),
B(LdaNamedProperty), R(7), U8(5), U8(21),
B(JumpIfToBooleanTrue), U8(19),
B(LdaNamedProperty), R(7), U8(7), U8(12),
B(LdaNamedProperty), R(7), U8(6), U8(12),
B(StaInArrayLiteral), R(4), R(3), U8(17),
B(Ldar), R(3),
B(Inc), U8(16),
......@@ -107,7 +107,6 @@ constant pool: [
ONE_BYTE_INTERNALIZED_STRING_TYPE ["Math"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["max"],
ARRAY_BOILERPLATE_DESCRIPTION_TYPE,
Smi [1],
ARRAY_BOILERPLATE_DESCRIPTION_TYPE,
ONE_BYTE_INTERNALIZED_STRING_TYPE ["next"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["done"],
......
......@@ -107,24 +107,24 @@ bytecodes: [
B(Mov), R(4), R(0),
/* 89 S> */ B(CreateArrayLiteral), U8(3), U8(0), U8(37),
B(Star), R(3),
B(LdaConstant), U8(4),
B(LdaSmi), I8(1),
B(Star), R(2),
/* 101 S> */ B(CreateArrayLiteral), U8(5), U8(1), U8(37),
/* 101 S> */ B(CreateArrayLiteral), U8(4), U8(1), U8(37),
B(Star), R(6),
/* 101 E> */ B(GetIterator), R(6), U8(2), U8(4),
B(Mov), R(4), R(1),
B(JumpIfJSReceiver), U8(7),
B(CallRuntime), U16(Runtime::kThrowSymbolIteratorInvalid), R(0), U8(0),
B(Star), R(5),
B(LdaNamedProperty), R(5), U8(6), U8(6),
B(LdaNamedProperty), R(5), U8(5), U8(6),
B(Star), R(4),
B(CallProperty0), R(4), R(5), U8(15),
B(Star), R(6),
B(JumpIfJSReceiver), U8(7),
B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), R(6), U8(1),
B(LdaNamedProperty), R(6), U8(7), U8(17),
B(LdaNamedProperty), R(6), U8(6), U8(17),
B(JumpIfToBooleanTrue), U8(19),
B(LdaNamedProperty), R(6), U8(8), U8(8),
B(LdaNamedProperty), R(6), U8(7), U8(8),
B(StaInArrayLiteral), R(3), R(2), U8(13),
B(Ldar), R(2),
B(Inc), U8(12),
......@@ -142,7 +142,6 @@ constant pool: [
FIXED_ARRAY_TYPE,
SHARED_FUNCTION_INFO_TYPE,
ARRAY_BOILERPLATE_DESCRIPTION_TYPE,
Smi [1],
ARRAY_BOILERPLATE_DESCRIPTION_TYPE,
ONE_BYTE_INTERNALIZED_STRING_TYPE ["next"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["done"],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment