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 "src/code-factory.h" | 5 #include "src/code-factory.h" |
6 #include "src/compiler/access-builder.h" | 6 #include "src/compiler/access-builder.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
9 #include "src/compiler/js-typed-lowering.h" | 9 #include "src/compiler/js-typed-lowering.h" |
10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 JSOperatorBuilder* javascript() { return &javascript_; } | 118 JSOperatorBuilder* javascript() { return &javascript_; } |
119 | 119 |
120 private: | 120 private: |
121 JSOperatorBuilder javascript_; | 121 JSOperatorBuilder javascript_; |
122 CompilationDependencies deps_; | 122 CompilationDependencies deps_; |
123 }; | 123 }; |
124 | 124 |
125 | 125 |
126 // ----------------------------------------------------------------------------- | 126 // ----------------------------------------------------------------------------- |
127 // JSUnaryNot | |
128 | |
129 | |
130 TEST_F(JSTypedLoweringTest, JSUnaryNotWithBoolean) { | |
131 Node* input = Parameter(Type::Boolean(), 0); | |
132 Node* context = Parameter(Type::Any(), 1); | |
133 Reduction r = Reduce(graph()->NewNode(javascript()->UnaryNot(), input, | |
134 context, graph()->start())); | |
135 ASSERT_TRUE(r.Changed()); | |
136 EXPECT_THAT(r.replacement(), IsBooleanNot(input)); | |
137 } | |
138 | |
139 | |
140 TEST_F(JSTypedLoweringTest, JSUnaryNotWithOrderedNumber) { | |
141 Node* input = Parameter(Type::OrderedNumber(), 0); | |
142 Node* context = Parameter(Type::Any(), 1); | |
143 Reduction r = Reduce(graph()->NewNode(javascript()->UnaryNot(), input, | |
144 context, graph()->start())); | |
145 ASSERT_TRUE(r.Changed()); | |
146 EXPECT_THAT(r.replacement(), IsNumberEqual(input, IsNumberConstant(0))); | |
147 } | |
148 | |
149 | |
150 TEST_F(JSTypedLoweringTest, JSUnaryNotWithFalsish) { | |
151 Node* input = Parameter( | |
152 Type::Union( | |
153 Type::MinusZero(), | |
154 Type::Union( | |
155 Type::NaN(), | |
156 Type::Union( | |
157 Type::Null(), | |
158 Type::Union( | |
159 Type::Undefined(), | |
160 Type::Union( | |
161 Type::Undetectable(), | |
162 Type::Union( | |
163 Type::Constant(factory()->false_value(), zone()), | |
164 Type::Range(0.0, 0.0, zone()), zone()), | |
165 zone()), | |
166 zone()), | |
167 zone()), | |
168 zone()), | |
169 zone()), | |
170 0); | |
171 Node* context = Parameter(Type::Any(), 1); | |
172 Reduction r = Reduce(graph()->NewNode(javascript()->UnaryNot(), input, | |
173 context, graph()->start())); | |
174 ASSERT_TRUE(r.Changed()); | |
175 EXPECT_THAT(r.replacement(), IsTrueConstant()); | |
176 } | |
177 | |
178 | |
179 TEST_F(JSTypedLoweringTest, JSUnaryNotWithTruish) { | |
180 Node* input = Parameter( | |
181 Type::Union( | |
182 Type::Constant(factory()->true_value(), zone()), | |
183 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone()), | |
184 zone()), | |
185 0); | |
186 Node* context = Parameter(Type::Any(), 1); | |
187 Reduction r = Reduce(graph()->NewNode(javascript()->UnaryNot(), input, | |
188 context, graph()->start())); | |
189 ASSERT_TRUE(r.Changed()); | |
190 EXPECT_THAT(r.replacement(), IsFalseConstant()); | |
191 } | |
192 | |
193 | |
194 TEST_F(JSTypedLoweringTest, JSUnaryNotWithNonZeroPlainNumber) { | |
195 Node* input = Parameter(Type::Range(1.0, 42.0, zone()), 0); | |
196 Node* context = Parameter(Type::Any(), 1); | |
197 Reduction r = Reduce(graph()->NewNode(javascript()->UnaryNot(), input, | |
198 context, graph()->start())); | |
199 ASSERT_TRUE(r.Changed()); | |
200 EXPECT_THAT(r.replacement(), IsFalseConstant()); | |
201 } | |
202 | |
203 | |
204 TEST_F(JSTypedLoweringTest, JSUnaryNotWithString) { | |
205 Node* input = Parameter(Type::String(), 0); | |
206 Node* context = Parameter(Type::Any(), 1); | |
207 Reduction r = Reduce(graph()->NewNode(javascript()->UnaryNot(), input, | |
208 context, graph()->start())); | |
209 ASSERT_TRUE(r.Changed()); | |
210 EXPECT_THAT(r.replacement(), | |
211 IsNumberEqual(IsLoadField(AccessBuilder::ForStringLength(), input, | |
212 graph()->start(), graph()->start()), | |
213 IsNumberConstant(0.0))); | |
214 } | |
215 | |
216 | |
217 TEST_F(JSTypedLoweringTest, JSUnaryNotWithAny) { | |
218 Node* input = Parameter(Type::Any(), 0); | |
219 Node* context = Parameter(Type::Any(), 1); | |
220 Reduction r = Reduce(graph()->NewNode(javascript()->UnaryNot(), input, | |
221 context, graph()->start())); | |
222 ASSERT_FALSE(r.Changed()); | |
223 } | |
224 | |
225 | |
226 // ----------------------------------------------------------------------------- | |
227 // Constant propagation | 127 // Constant propagation |
228 | 128 |
229 | 129 |
230 TEST_F(JSTypedLoweringTest, ParameterWithMinusZero) { | 130 TEST_F(JSTypedLoweringTest, ParameterWithMinusZero) { |
231 { | 131 { |
232 Reduction r = Reduce( | 132 Reduction r = Reduce( |
233 Parameter(Type::Constant(factory()->minus_zero_value(), zone()))); | 133 Parameter(Type::Constant(factory()->minus_zero_value(), zone()))); |
234 ASSERT_TRUE(r.Changed()); | 134 ASSERT_TRUE(r.Changed()); |
235 EXPECT_THAT(r.replacement(), IsNumberConstant(-0.0)); | 135 EXPECT_THAT(r.replacement(), IsNumberConstant(-0.0)); |
236 } | 136 } |
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, | 1191 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, |
1292 frame_state, effect, control); | 1192 frame_state, effect, control); |
1293 Reduction r = Reduce(instanceOf); | 1193 Reduction r = Reduce(instanceOf); |
1294 ASSERT_FALSE(r.Changed()); | 1194 ASSERT_FALSE(r.Changed()); |
1295 ASSERT_EQ(instanceOf, dummy->InputAt(0)); | 1195 ASSERT_EQ(instanceOf, dummy->InputAt(0)); |
1296 } | 1196 } |
1297 | 1197 |
1298 } // namespace compiler | 1198 } // namespace compiler |
1299 } // namespace internal | 1199 } // namespace internal |
1300 } // namespace v8 | 1200 } // namespace v8 |
OLD | NEW |