| 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/compiler/access-builder.h" | 5 #include "src/compiler/access-builder.h" |
| 6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
| 7 #include "src/compiler/js-operator.h" | 7 #include "src/compiler/js-operator.h" |
| 8 #include "src/compiler/js-typed-lowering.h" | 8 #include "src/compiler/js-typed-lowering.h" |
| 9 #include "src/compiler/machine-operator.h" | 9 #include "src/compiler/machine-operator.h" |
| 10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 TEST_F(JSTypedLoweringTest, JSUnaryNotWithNonZeroPlainNumber) { | 177 TEST_F(JSTypedLoweringTest, JSUnaryNotWithNonZeroPlainNumber) { |
| 178 Node* input = Parameter(Type::Range(1.0, 42.0, zone()), 0); | 178 Node* input = Parameter(Type::Range(1.0, 42.0, zone()), 0); |
| 179 Node* context = Parameter(Type::Any(), 1); | 179 Node* context = Parameter(Type::Any(), 1); |
| 180 Reduction r = | 180 Reduction r = |
| 181 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); | 181 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); |
| 182 ASSERT_TRUE(r.Changed()); | 182 ASSERT_TRUE(r.Changed()); |
| 183 EXPECT_THAT(r.replacement(), IsFalseConstant()); | 183 EXPECT_THAT(r.replacement(), IsFalseConstant()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 | 186 |
| 187 TEST_F(JSTypedLoweringTest, JSUnaryNotWithString) { |
| 188 Node* input = Parameter(Type::String(), 0); |
| 189 Node* context = Parameter(Type::Any(), 1); |
| 190 Reduction r = |
| 191 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); |
| 192 ASSERT_TRUE(r.Changed()); |
| 193 EXPECT_THAT(r.replacement(), |
| 194 IsNumberEqual(IsLoadField(AccessBuilder::ForStringLength(), input, |
| 195 graph()->start(), graph()->start()), |
| 196 IsNumberConstant(0.0))); |
| 197 } |
| 198 |
| 199 |
| 187 TEST_F(JSTypedLoweringTest, JSUnaryNotWithAny) { | 200 TEST_F(JSTypedLoweringTest, JSUnaryNotWithAny) { |
| 188 Node* input = Parameter(Type::Any(), 0); | 201 Node* input = Parameter(Type::Any(), 0); |
| 189 Node* context = Parameter(Type::Any(), 1); | 202 Node* context = Parameter(Type::Any(), 1); |
| 190 Reduction r = | 203 Reduction r = |
| 191 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); | 204 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); |
| 192 ASSERT_TRUE(r.Changed()); | 205 ASSERT_FALSE(r.Changed()); |
| 193 EXPECT_THAT(r.replacement(), IsBooleanNot(IsAnyToBoolean(input))); | |
| 194 } | 206 } |
| 195 | 207 |
| 196 | 208 |
| 197 // ----------------------------------------------------------------------------- | 209 // ----------------------------------------------------------------------------- |
| 198 // Constant propagation | 210 // Constant propagation |
| 199 | 211 |
| 200 | 212 |
| 201 TEST_F(JSTypedLoweringTest, ParameterWithMinusZero) { | 213 TEST_F(JSTypedLoweringTest, ParameterWithMinusZero) { |
| 202 { | 214 { |
| 203 Reduction r = Reduce( | 215 Reduction r = Reduce( |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 TEST_F(JSTypedLoweringTest, JSToBooleanWithNonZeroPlainNumber) { | 365 TEST_F(JSTypedLoweringTest, JSToBooleanWithNonZeroPlainNumber) { |
| 354 Node* input = Parameter(Type::Range(1, V8_INFINITY, zone()), 0); | 366 Node* input = Parameter(Type::Range(1, V8_INFINITY, zone()), 0); |
| 355 Node* context = Parameter(Type::Any(), 1); | 367 Node* context = Parameter(Type::Any(), 1); |
| 356 Reduction r = | 368 Reduction r = |
| 357 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context)); | 369 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context)); |
| 358 ASSERT_TRUE(r.Changed()); | 370 ASSERT_TRUE(r.Changed()); |
| 359 EXPECT_THAT(r.replacement(), IsTrueConstant()); | 371 EXPECT_THAT(r.replacement(), IsTrueConstant()); |
| 360 } | 372 } |
| 361 | 373 |
| 362 | 374 |
| 375 TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumber) { |
| 376 Node* input = Parameter(Type::OrderedNumber(), 0); |
| 377 Node* context = Parameter(Type::Any(), 1); |
| 378 Reduction r = |
| 379 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context)); |
| 380 ASSERT_TRUE(r.Changed()); |
| 381 EXPECT_THAT(r.replacement(), |
| 382 IsBooleanNot(IsNumberEqual(input, IsNumberConstant(0.0)))); |
| 383 } |
| 384 |
| 385 |
| 386 TEST_F(JSTypedLoweringTest, JSToBooleanWithString) { |
| 387 Node* input = Parameter(Type::String(), 0); |
| 388 Node* context = Parameter(Type::Any(), 1); |
| 389 Reduction r = |
| 390 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context)); |
| 391 ASSERT_TRUE(r.Changed()); |
| 392 EXPECT_THAT( |
| 393 r.replacement(), |
| 394 IsNumberLessThan(IsNumberConstant(0.0), |
| 395 IsLoadField(AccessBuilder::ForStringLength(), input, |
| 396 graph()->start(), graph()->start()))); |
| 397 } |
| 398 |
| 399 |
| 363 TEST_F(JSTypedLoweringTest, JSToBooleanWithAny) { | 400 TEST_F(JSTypedLoweringTest, JSToBooleanWithAny) { |
| 364 Node* input = Parameter(Type::Any(), 0); | 401 Node* input = Parameter(Type::Any(), 0); |
| 365 Node* context = Parameter(Type::Any(), 1); | 402 Node* context = Parameter(Type::Any(), 1); |
| 366 Reduction r = | 403 Reduction r = |
| 367 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context)); | 404 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context)); |
| 368 ASSERT_TRUE(r.Changed()); | 405 ASSERT_FALSE(r.Changed()); |
| 369 EXPECT_THAT(r.replacement(), IsAnyToBoolean(input)); | |
| 370 } | 406 } |
| 371 | 407 |
| 372 | 408 |
| 373 // ----------------------------------------------------------------------------- | 409 // ----------------------------------------------------------------------------- |
| 374 // JSToNumber | 410 // JSToNumber |
| 375 | 411 |
| 376 | 412 |
| 377 TEST_F(JSTypedLoweringTest, JSToNumberWithPlainPrimitive) { | 413 TEST_F(JSTypedLoweringTest, JSToNumberWithPlainPrimitive) { |
| 378 Node* const input = Parameter(Type::PlainPrimitive(), 0); | 414 Node* const input = Parameter(Type::PlainPrimitive(), 0); |
| 379 Node* const context = Parameter(Type::Any(), 1); | 415 Node* const context = Parameter(Type::Any(), 1); |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 IsStoreElement( | 847 IsStoreElement( |
| 812 access, IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 848 access, IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
| 813 key, value, effect, control)); | 849 key, value, effect, control)); |
| 814 } | 850 } |
| 815 } | 851 } |
| 816 } | 852 } |
| 817 | 853 |
| 818 } // namespace compiler | 854 } // namespace compiler |
| 819 } // namespace internal | 855 } // namespace internal |
| 820 } // namespace v8 | 856 } // namespace v8 |
| OLD | NEW |