OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <limits> |
| 6 |
| 7 #include "src/compiler/graph.h" |
| 8 #include "src/compiler/value-numbering-reducer.h" |
| 9 #include "src/test/test-utils.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 namespace compiler { |
| 14 |
| 15 namespace { |
| 16 |
| 17 const SimpleOperator kOp0(0, Operator::kNoProperties, 0, 1, "op0"); |
| 18 |
| 19 } // namespace |
| 20 |
| 21 |
| 22 class ValueNumberingReducerTest : public TestWithZone { |
| 23 public: |
| 24 ValueNumberingReducerTest() : graph_(zone()), reducer_(zone()) {} |
| 25 |
| 26 protected: |
| 27 Reduction Reduce(Node* node) { return reducer_.Reduce(node); } |
| 28 |
| 29 Graph* graph() { return &graph_; } |
| 30 |
| 31 private: |
| 32 Graph graph_; |
| 33 ValueNumberingReducer reducer_; |
| 34 }; |
| 35 |
| 36 |
| 37 TEST_F(ValueNumberingReducerTest, AllInputsAreChecked) { |
| 38 Node* na = graph()->NewNode(&kOp0); |
| 39 Node* nb = graph()->NewNode(&kOp0); |
| 40 Node* n1 = graph()->NewNode(&kOp0, na); |
| 41 Node* n2 = graph()->NewNode(&kOp0, nb); |
| 42 EXPECT_FALSE(Reduce(n1).Changed()); |
| 43 EXPECT_FALSE(Reduce(n2).Changed()); |
| 44 } |
| 45 |
| 46 |
| 47 TEST_F(ValueNumberingReducerTest, KilledNodesAreNeverReturned) { |
| 48 Node* n1 = graph()->NewNode(&kOp0); |
| 49 EXPECT_FALSE(Reduce(n1).Changed()); |
| 50 n1->Kill(); |
| 51 EXPECT_FALSE(Reduce(graph()->NewNode(&kOp0)).Changed()); |
| 52 } |
| 53 |
| 54 |
| 55 TEST_F(ValueNumberingReducerTest, OperatorEqualityNotIdentity) { |
| 56 static const size_t kMaxInputCount = 16; |
| 57 Node* inputs[kMaxInputCount]; |
| 58 for (size_t i = 0; i < arraysize(inputs); ++i) { |
| 59 Operator::Opcode opcode = static_cast<Operator::Opcode>( |
| 60 std::numeric_limits<Operator::Opcode>::max() - i); |
| 61 inputs[i] = graph()->NewNode(new (zone()) SimpleOperator( |
| 62 opcode, Operator::kNoProperties, 0, 1, "Operator")); |
| 63 } |
| 64 TRACED_FORRANGE(size_t, input_count, 0, arraysize(inputs)) { |
| 65 const SimpleOperator op1(static_cast<Operator::Opcode>(input_count), |
| 66 Operator::kNoProperties, input_count, 1, "op"); |
| 67 Node* n1 = graph()->NewNode(&op1, input_count, inputs); |
| 68 Reduction r1 = Reduce(n1); |
| 69 EXPECT_FALSE(r1.Changed()); |
| 70 |
| 71 const SimpleOperator op2(static_cast<Operator::Opcode>(input_count), |
| 72 Operator::kNoProperties, input_count, 1, "op"); |
| 73 Node* n2 = graph()->NewNode(&op2, input_count, inputs); |
| 74 Reduction r2 = Reduce(n2); |
| 75 EXPECT_TRUE(r2.Changed()); |
| 76 EXPECT_EQ(n1, r2.replacement()); |
| 77 } |
| 78 } |
| 79 |
| 80 |
| 81 TEST_F(ValueNumberingReducerTest, SubsequentReductionsYieldTheSameNode) { |
| 82 static const size_t kMaxInputCount = 16; |
| 83 Node* inputs[kMaxInputCount]; |
| 84 for (size_t i = 0; i < arraysize(inputs); ++i) { |
| 85 Operator::Opcode opcode = static_cast<Operator::Opcode>( |
| 86 std::numeric_limits<Operator::Opcode>::max() - i); |
| 87 inputs[i] = graph()->NewNode(new (zone()) SimpleOperator( |
| 88 opcode, Operator::kNoProperties, 0, 1, "Operator")); |
| 89 } |
| 90 TRACED_FORRANGE(size_t, input_count, 0, arraysize(inputs)) { |
| 91 const SimpleOperator op1(1, Operator::kNoProperties, input_count, 1, "op1"); |
| 92 Node* n = graph()->NewNode(&op1, input_count, inputs); |
| 93 Reduction r = Reduce(n); |
| 94 EXPECT_FALSE(r.Changed()); |
| 95 |
| 96 r = Reduce(graph()->NewNode(&op1, input_count, inputs)); |
| 97 ASSERT_TRUE(r.Changed()); |
| 98 EXPECT_EQ(n, r.replacement()); |
| 99 |
| 100 r = Reduce(graph()->NewNode(&op1, input_count, inputs)); |
| 101 ASSERT_TRUE(r.Changed()); |
| 102 EXPECT_EQ(n, r.replacement()); |
| 103 } |
| 104 } |
| 105 |
| 106 } // namespace compiler |
| 107 } // namespace internal |
| 108 } // namespace v8 |
OLD | NEW |