8b57bdba59
This is a reland of 13141c8a65
... with a fix for an UB issue of passing null pointers to memcpy()
when size is zero.
TBR=leszeks@chromium.org
Original change's description:
> [zone-compr] Introduce ZoneTypeTraits and ZoneCompression
>
> Also move zone compression flags to src/common/globals.h.
>
> Bug: v8:9923
> Change-Id: Id0a77720e735e2669a1e5eef48e1b4866ad99480
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2324255
> Reviewed-by: Leszek Swirski <leszeks@chromium.org>
> Commit-Queue: Igor Sheludko <ishell@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#69160}
Bug: v8:9923
Change-Id: I2245b81516c39ccea262c282c659ef601af57abf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2332165
Commit-Queue: Igor Sheludko (OOO Aug 3-17) <ishell@chromium.org>
Reviewed-by: Igor Sheludko (OOO Aug 3-17) <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69166}
137 lines
4.3 KiB
C++
137 lines
4.3 KiB
C++
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "src/compiler/value-numbering-reducer.h"
|
|
|
|
#include <limits>
|
|
|
|
#include "src/compiler/graph.h"
|
|
#include "src/compiler/node.h"
|
|
#include "src/compiler/operator.h"
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
namespace compiler {
|
|
namespace value_numbering_reducer_unittest {
|
|
|
|
struct TestOperator : public Operator {
|
|
TestOperator(Operator::Opcode opcode, Operator::Properties properties,
|
|
size_t value_in, size_t value_out)
|
|
: Operator(opcode, properties, "TestOp", value_in, 0, 0, value_out, 0,
|
|
0) {}
|
|
};
|
|
|
|
|
|
static const TestOperator kOp0(0, Operator::kIdempotent, 0, 1);
|
|
static const TestOperator kOp1(1, Operator::kIdempotent, 1, 1);
|
|
|
|
|
|
class ValueNumberingReducerTest : public TestWithZone {
|
|
public:
|
|
ValueNumberingReducerTest()
|
|
: TestWithZone(kCompressGraphZone),
|
|
graph_(zone()),
|
|
reducer_(zone(), graph()->zone()) {}
|
|
|
|
protected:
|
|
Reduction Reduce(Node* node) { return reducer_.Reduce(node); }
|
|
|
|
Graph* graph() { return &graph_; }
|
|
|
|
private:
|
|
Graph graph_;
|
|
ValueNumberingReducer reducer_;
|
|
};
|
|
|
|
|
|
TEST_F(ValueNumberingReducerTest, AllInputsAreChecked) {
|
|
Node* na = graph()->NewNode(&kOp0);
|
|
Node* nb = graph()->NewNode(&kOp0);
|
|
Node* n1 = graph()->NewNode(&kOp1, na);
|
|
Node* n2 = graph()->NewNode(&kOp1, nb);
|
|
EXPECT_FALSE(Reduce(n1).Changed());
|
|
EXPECT_FALSE(Reduce(n2).Changed());
|
|
}
|
|
|
|
|
|
TEST_F(ValueNumberingReducerTest, DeadNodesAreNeverReturned) {
|
|
Node* n0 = graph()->NewNode(&kOp0);
|
|
Node* n1 = graph()->NewNode(&kOp1, n0);
|
|
EXPECT_FALSE(Reduce(n1).Changed());
|
|
n1->Kill();
|
|
EXPECT_FALSE(Reduce(graph()->NewNode(&kOp1, n0)).Changed());
|
|
}
|
|
|
|
|
|
TEST_F(ValueNumberingReducerTest, OnlyEliminatableNodesAreReduced) {
|
|
TestOperator op(0, Operator::kNoProperties, 0, 1);
|
|
Node* n0 = graph()->NewNode(&op);
|
|
Node* n1 = graph()->NewNode(&op);
|
|
EXPECT_FALSE(Reduce(n0).Changed());
|
|
EXPECT_FALSE(Reduce(n1).Changed());
|
|
}
|
|
|
|
|
|
TEST_F(ValueNumberingReducerTest, OperatorEqualityNotIdentity) {
|
|
static const size_t kMaxInputCount = 16;
|
|
Node* inputs[kMaxInputCount];
|
|
for (size_t i = 0; i < arraysize(inputs); ++i) {
|
|
Operator::Opcode opcode = static_cast<Operator::Opcode>(kMaxInputCount + i);
|
|
inputs[i] = graph()->NewNode(
|
|
zone()->New<TestOperator>(opcode, Operator::kIdempotent, 0, 1));
|
|
}
|
|
TRACED_FORRANGE(size_t, input_count, 0, arraysize(inputs)) {
|
|
const TestOperator op1(static_cast<Operator::Opcode>(input_count),
|
|
Operator::kIdempotent, input_count, 1);
|
|
Node* n1 = graph()->NewNode(&op1, static_cast<int>(input_count), inputs);
|
|
Reduction r1 = Reduce(n1);
|
|
EXPECT_FALSE(r1.Changed());
|
|
|
|
const TestOperator op2(static_cast<Operator::Opcode>(input_count),
|
|
Operator::kIdempotent, input_count, 1);
|
|
Node* n2 = graph()->NewNode(&op2, static_cast<int>(input_count), inputs);
|
|
Reduction r2 = Reduce(n2);
|
|
EXPECT_TRUE(r2.Changed());
|
|
EXPECT_EQ(n1, r2.replacement());
|
|
}
|
|
}
|
|
|
|
|
|
TEST_F(ValueNumberingReducerTest, SubsequentReductionsYieldTheSameNode) {
|
|
static const size_t kMaxInputCount = 16;
|
|
Node* inputs[kMaxInputCount];
|
|
for (size_t i = 0; i < arraysize(inputs); ++i) {
|
|
Operator::Opcode opcode = static_cast<Operator::Opcode>(2 + i);
|
|
inputs[i] = graph()->NewNode(
|
|
zone()->New<TestOperator>(opcode, Operator::kIdempotent, 0, 1));
|
|
}
|
|
TRACED_FORRANGE(size_t, input_count, 0, arraysize(inputs)) {
|
|
const TestOperator op1(1, Operator::kIdempotent, input_count, 1);
|
|
Node* n = graph()->NewNode(&op1, static_cast<int>(input_count), inputs);
|
|
Reduction r = Reduce(n);
|
|
EXPECT_FALSE(r.Changed());
|
|
|
|
r = Reduce(graph()->NewNode(&op1, static_cast<int>(input_count), inputs));
|
|
ASSERT_TRUE(r.Changed());
|
|
EXPECT_EQ(n, r.replacement());
|
|
|
|
r = Reduce(graph()->NewNode(&op1, static_cast<int>(input_count), inputs));
|
|
ASSERT_TRUE(r.Changed());
|
|
EXPECT_EQ(n, r.replacement());
|
|
}
|
|
}
|
|
|
|
|
|
TEST_F(ValueNumberingReducerTest, WontReplaceNodeWithItself) {
|
|
Node* n = graph()->NewNode(&kOp0);
|
|
EXPECT_FALSE(Reduce(n).Changed());
|
|
EXPECT_FALSE(Reduce(n).Changed());
|
|
}
|
|
|
|
} // namespace value_numbering_reducer_unittest
|
|
} // namespace compiler
|
|
} // namespace internal
|
|
} // namespace v8
|