OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits> | 5 #include <limits> |
6 | 6 |
7 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
8 #include "src/compiler/node.h" | 8 #include "src/compiler/node.h" |
9 #include "src/compiler/operator.h" | 9 #include "src/compiler/operator.h" |
10 #include "src/compiler/value-numbering-reducer.h" | 10 #include "src/compiler/value-numbering-reducer.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 Node* n1 = graph()->NewNode(&op); | 66 Node* n1 = graph()->NewNode(&op); |
67 EXPECT_FALSE(Reduce(n0).Changed()); | 67 EXPECT_FALSE(Reduce(n0).Changed()); |
68 EXPECT_FALSE(Reduce(n1).Changed()); | 68 EXPECT_FALSE(Reduce(n1).Changed()); |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 TEST_F(ValueNumberingReducerTest, OperatorEqualityNotIdentity) { | 72 TEST_F(ValueNumberingReducerTest, OperatorEqualityNotIdentity) { |
73 static const size_t kMaxInputCount = 16; | 73 static const size_t kMaxInputCount = 16; |
74 Node* inputs[kMaxInputCount]; | 74 Node* inputs[kMaxInputCount]; |
75 for (size_t i = 0; i < arraysize(inputs); ++i) { | 75 for (size_t i = 0; i < arraysize(inputs); ++i) { |
76 Operator::Opcode opcode = static_cast<Operator::Opcode>( | 76 Operator::Opcode opcode = static_cast<Operator::Opcode>(kMaxInputCount + i); |
77 std::numeric_limits<Operator::Opcode>::max() - i); | |
78 inputs[i] = graph()->NewNode( | 77 inputs[i] = graph()->NewNode( |
79 new (zone()) TestOperator(opcode, Operator::kIdempotent, 0, 1)); | 78 new (zone()) TestOperator(opcode, Operator::kIdempotent, 0, 1)); |
80 } | 79 } |
81 TRACED_FORRANGE(size_t, input_count, 0, arraysize(inputs)) { | 80 TRACED_FORRANGE(size_t, input_count, 0, arraysize(inputs)) { |
82 const TestOperator op1(static_cast<Operator::Opcode>(input_count), | 81 const TestOperator op1(static_cast<Operator::Opcode>(input_count), |
83 Operator::kIdempotent, input_count, 1); | 82 Operator::kIdempotent, input_count, 1); |
84 Node* n1 = graph()->NewNode(&op1, static_cast<int>(input_count), inputs); | 83 Node* n1 = graph()->NewNode(&op1, static_cast<int>(input_count), inputs); |
85 Reduction r1 = Reduce(n1); | 84 Reduction r1 = Reduce(n1); |
86 EXPECT_FALSE(r1.Changed()); | 85 EXPECT_FALSE(r1.Changed()); |
87 | 86 |
88 const TestOperator op2(static_cast<Operator::Opcode>(input_count), | 87 const TestOperator op2(static_cast<Operator::Opcode>(input_count), |
89 Operator::kIdempotent, input_count, 1); | 88 Operator::kIdempotent, input_count, 1); |
90 Node* n2 = graph()->NewNode(&op2, static_cast<int>(input_count), inputs); | 89 Node* n2 = graph()->NewNode(&op2, static_cast<int>(input_count), inputs); |
91 Reduction r2 = Reduce(n2); | 90 Reduction r2 = Reduce(n2); |
92 EXPECT_TRUE(r2.Changed()); | 91 EXPECT_TRUE(r2.Changed()); |
93 EXPECT_EQ(n1, r2.replacement()); | 92 EXPECT_EQ(n1, r2.replacement()); |
94 } | 93 } |
95 } | 94 } |
96 | 95 |
97 | 96 |
98 TEST_F(ValueNumberingReducerTest, SubsequentReductionsYieldTheSameNode) { | 97 TEST_F(ValueNumberingReducerTest, SubsequentReductionsYieldTheSameNode) { |
99 static const size_t kMaxInputCount = 16; | 98 static const size_t kMaxInputCount = 16; |
100 Node* inputs[kMaxInputCount]; | 99 Node* inputs[kMaxInputCount]; |
101 for (size_t i = 0; i < arraysize(inputs); ++i) { | 100 for (size_t i = 0; i < arraysize(inputs); ++i) { |
102 Operator::Opcode opcode = static_cast<Operator::Opcode>( | 101 Operator::Opcode opcode = static_cast<Operator::Opcode>(2 + i); |
103 std::numeric_limits<Operator::Opcode>::max() - i); | |
104 inputs[i] = graph()->NewNode( | 102 inputs[i] = graph()->NewNode( |
105 new (zone()) TestOperator(opcode, Operator::kIdempotent, 0, 1)); | 103 new (zone()) TestOperator(opcode, Operator::kIdempotent, 0, 1)); |
106 } | 104 } |
107 TRACED_FORRANGE(size_t, input_count, 0, arraysize(inputs)) { | 105 TRACED_FORRANGE(size_t, input_count, 0, arraysize(inputs)) { |
108 const TestOperator op1(1, Operator::kIdempotent, input_count, 1); | 106 const TestOperator op1(1, Operator::kIdempotent, input_count, 1); |
109 Node* n = graph()->NewNode(&op1, static_cast<int>(input_count), inputs); | 107 Node* n = graph()->NewNode(&op1, static_cast<int>(input_count), inputs); |
110 Reduction r = Reduce(n); | 108 Reduction r = Reduce(n); |
111 EXPECT_FALSE(r.Changed()); | 109 EXPECT_FALSE(r.Changed()); |
112 | 110 |
113 r = Reduce(graph()->NewNode(&op1, static_cast<int>(input_count), inputs)); | 111 r = Reduce(graph()->NewNode(&op1, static_cast<int>(input_count), inputs)); |
114 ASSERT_TRUE(r.Changed()); | 112 ASSERT_TRUE(r.Changed()); |
115 EXPECT_EQ(n, r.replacement()); | 113 EXPECT_EQ(n, r.replacement()); |
116 | 114 |
117 r = Reduce(graph()->NewNode(&op1, static_cast<int>(input_count), inputs)); | 115 r = Reduce(graph()->NewNode(&op1, static_cast<int>(input_count), inputs)); |
118 ASSERT_TRUE(r.Changed()); | 116 ASSERT_TRUE(r.Changed()); |
119 EXPECT_EQ(n, r.replacement()); | 117 EXPECT_EQ(n, r.replacement()); |
120 } | 118 } |
121 } | 119 } |
122 | 120 |
123 | 121 |
124 TEST_F(ValueNumberingReducerTest, WontReplaceNodeWithItself) { | 122 TEST_F(ValueNumberingReducerTest, WontReplaceNodeWithItself) { |
125 Node* n = graph()->NewNode(&kOp0); | 123 Node* n = graph()->NewNode(&kOp0); |
126 EXPECT_FALSE(Reduce(n).Changed()); | 124 EXPECT_FALSE(Reduce(n).Changed()); |
127 EXPECT_FALSE(Reduce(n).Changed()); | 125 EXPECT_FALSE(Reduce(n).Changed()); |
128 } | 126 } |
129 | 127 |
130 } // namespace compiler | 128 } // namespace compiler |
131 } // namespace internal | 129 } // namespace internal |
132 } // namespace v8 | 130 } // namespace v8 |
OLD | NEW |