Commit e1f23233 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[bigint,interpreter] Add more tests for type feedback.

R=jkummerow@chromium.org

Bug: v8:6791
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I2b04e4d5c2f8dd8c7e57662c81778a3a77376cb5
Reviewed-on: https://chromium-review.googlesource.com/819271
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50034}
parent 4f4654a0
......@@ -387,6 +387,48 @@ TEST(InterpreterBinaryOpsHeapNumber) {
}
}
TEST(InterpreterBinaryOpsBigInt) {
// This test only checks that the recorded type feedback is kBigInt.
AstBigInt inputs[] = {AstBigInt("1"), AstBigInt("-42"), AstBigInt("0xFFFF")};
for (size_t l = 0; l < arraysize(inputs); l++) {
for (size_t r = 0; r < arraysize(inputs); r++) {
for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) {
// Skip over unsigned right shift.
if (kArithmeticOperators[o] == Token::Value::SHR) continue;
HandleAndZoneScope handles;
Isolate* isolate = handles.main_isolate();
Zone* zone = handles.main_zone();
FeedbackVectorSpec feedback_spec(zone);
BytecodeArrayBuilder builder(zone, 1, 1, &feedback_spec);
FeedbackSlot slot = feedback_spec.AddBinaryOpICSlot();
Handle<i::FeedbackMetadata> metadata =
NewFeedbackMetadata(isolate, &feedback_spec);
Register reg(0);
auto lhs = inputs[l];
auto rhs = inputs[r];
builder.LoadLiteral(lhs)
.StoreAccumulatorInRegister(reg)
.LoadLiteral(rhs)
.BinaryOperation(kArithmeticOperators[o], reg, GetIndex(slot))
.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array, metadata);
auto callable = tester.GetCallable<>();
Handle<Object> return_value = callable().ToHandleChecked();
CHECK(return_value->IsBigInt());
Object* feedback = callable.vector()->Get(slot);
CHECK(feedback->IsSmi());
CHECK_EQ(BinaryOperationFeedback::kBigInt,
static_cast<Smi*>(feedback)->value());
}
}
}
}
namespace {
struct LiteralForTest {
......@@ -827,6 +869,8 @@ TEST(InterpreterUnaryOpFeedback) {
Handle<Smi> smi_max = Handle<Smi>(Smi::FromInt(Smi::kMaxValue), isolate);
Handle<Smi> smi_min = Handle<Smi>(Smi::FromInt(Smi::kMinValue), isolate);
Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(2.1);
Handle<BigInt> bigint =
BigInt::FromNumber(isolate, smi_max).ToHandleChecked();
Handle<String> str = isolate->factory()->NewStringFromAsciiChecked("42");
struct TestCase {
......@@ -834,19 +878,23 @@ TEST(InterpreterUnaryOpFeedback) {
Handle<Smi> smi_feedback_value;
Handle<Smi> smi_to_number_feedback_value;
Handle<HeapNumber> number_feedback_value;
Handle<BigInt> bigint_feedback_value;
Handle<Object> any_feedback_value;
};
TestCase const kTestCases[] = {
{Token::Value::INC, smi_one, smi_max, number, str},
{Token::Value::DEC, smi_one, smi_min, number, str}};
// Testing ADD and BIT_NOT would require generalizing the test setup.
{Token::Value::SUB, smi_one, smi_min, number, bigint, str},
{Token::Value::INC, smi_one, smi_max, number, bigint, str},
{Token::Value::DEC, smi_one, smi_min, number, bigint, str}};
for (TestCase const& test_case : kTestCases) {
i::FeedbackVectorSpec feedback_spec(zone);
BytecodeArrayBuilder builder(zone, 4, 0, &feedback_spec);
BytecodeArrayBuilder builder(zone, 5, 0, &feedback_spec);
i::FeedbackSlot slot0 = feedback_spec.AddBinaryOpICSlot();
i::FeedbackSlot slot1 = feedback_spec.AddBinaryOpICSlot();
i::FeedbackSlot slot2 = feedback_spec.AddBinaryOpICSlot();
i::FeedbackSlot slot3 = feedback_spec.AddBinaryOpICSlot();
i::FeedbackSlot slot4 = feedback_spec.AddBinaryOpICSlot();
Handle<i::FeedbackMetadata> metadata =
i::NewFeedbackMetadata(isolate, &feedback_spec);
......@@ -859,18 +907,21 @@ TEST(InterpreterUnaryOpFeedback) {
.UnaryOperation(test_case.op, GetIndex(slot2))
.LoadAccumulatorWithRegister(builder.Parameter(2))
.UnaryOperation(test_case.op, GetIndex(slot3))
.LoadAccumulatorWithRegister(builder.Parameter(3))
.UnaryOperation(test_case.op, GetIndex(slot4))
.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
InterpreterTester tester(isolate, bytecode_array, metadata);
typedef Handle<Object> H;
auto callable = tester.GetCallable<H, H, H, H>();
auto callable = tester.GetCallable<H, H, H, H, H>();
Handle<Object> return_val =
callable(test_case.smi_feedback_value,
test_case.smi_to_number_feedback_value,
test_case.number_feedback_value, test_case.any_feedback_value)
test_case.number_feedback_value,
test_case.bigint_feedback_value, test_case.any_feedback_value)
.ToHandleChecked();
USE(return_val);
Object* feedback0 = callable.vector()->Get(slot0);
......@@ -890,8 +941,13 @@ TEST(InterpreterUnaryOpFeedback) {
Object* feedback3 = callable.vector()->Get(slot3);
CHECK(feedback3->IsSmi());
CHECK_EQ(BinaryOperationFeedback::kAny,
CHECK_EQ(BinaryOperationFeedback::kBigInt,
static_cast<Smi*>(feedback3)->value());
Object* feedback4 = callable.vector()->Get(slot4);
CHECK(feedback4->IsSmi());
CHECK_EQ(BinaryOperationFeedback::kAny,
static_cast<Smi*>(feedback4)->value());
}
}
......
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