| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 | 108 |
| 109 // ----------------------------------------------------------------------------- | 109 // ----------------------------------------------------------------------------- |
| 110 // JSUnaryNot | 110 // JSUnaryNot |
| 111 | 111 |
| 112 | 112 |
| 113 TEST_F(JSTypedLoweringTest, JSUnaryNotWithBoolean) { | 113 TEST_F(JSTypedLoweringTest, JSUnaryNotWithBoolean) { |
| 114 Node* input = Parameter(Type::Boolean(), 0); | 114 Node* input = Parameter(Type::Boolean(), 0); |
| 115 Node* context = Parameter(Type::Any(), 1); | 115 Node* context = Parameter(Type::Any(), 1); |
| 116 Reduction r = | 116 Reduction r = |
| 117 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); | 117 Reduce(graph()->NewNode(javascript()->UnaryNot(LanguageMode::SLOPPY), |
| 118 input, context)); |
| 118 ASSERT_TRUE(r.Changed()); | 119 ASSERT_TRUE(r.Changed()); |
| 119 EXPECT_THAT(r.replacement(), IsBooleanNot(input)); | 120 EXPECT_THAT(r.replacement(), IsBooleanNot(input)); |
| 120 } | 121 } |
| 121 | 122 |
| 122 | 123 |
| 123 TEST_F(JSTypedLoweringTest, JSUnaryNotWithOrderedNumber) { | 124 TEST_F(JSTypedLoweringTest, JSUnaryNotWithOrderedNumber) { |
| 124 Node* input = Parameter(Type::OrderedNumber(), 0); | 125 Node* input = Parameter(Type::OrderedNumber(), 0); |
| 125 Node* context = Parameter(Type::Any(), 1); | 126 Node* context = Parameter(Type::Any(), 1); |
| 126 Reduction r = | 127 Reduction r = |
| 127 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); | 128 Reduce(graph()->NewNode(javascript()->UnaryNot(LanguageMode::SLOPPY), |
| 129 input, context)); |
| 128 ASSERT_TRUE(r.Changed()); | 130 ASSERT_TRUE(r.Changed()); |
| 129 EXPECT_THAT(r.replacement(), IsNumberEqual(input, IsNumberConstant(0))); | 131 EXPECT_THAT(r.replacement(), IsNumberEqual(input, IsNumberConstant(0))); |
| 130 } | 132 } |
| 131 | 133 |
| 132 | 134 |
| 133 TEST_F(JSTypedLoweringTest, JSUnaryNotWithFalsish) { | 135 TEST_F(JSTypedLoweringTest, JSUnaryNotWithFalsish) { |
| 134 Node* input = Parameter( | 136 Node* input = Parameter( |
| 135 Type::Union( | 137 Type::Union( |
| 136 Type::MinusZero(), | 138 Type::MinusZero(), |
| 137 Type::Union( | 139 Type::Union( |
| 138 Type::NaN(), | 140 Type::NaN(), |
| 139 Type::Union( | 141 Type::Union( |
| 140 Type::Null(), | 142 Type::Null(), |
| 141 Type::Union( | 143 Type::Union( |
| 142 Type::Undefined(), | 144 Type::Undefined(), |
| 143 Type::Union( | 145 Type::Union( |
| 144 Type::Undetectable(), | 146 Type::Undetectable(), |
| 145 Type::Union( | 147 Type::Union( |
| 146 Type::Constant(factory()->false_value(), zone()), | 148 Type::Constant(factory()->false_value(), zone()), |
| 147 Type::Range(0.0, 0.0, zone()), zone()), | 149 Type::Range(0.0, 0.0, zone()), zone()), |
| 148 zone()), | 150 zone()), |
| 149 zone()), | 151 zone()), |
| 150 zone()), | 152 zone()), |
| 151 zone()), | 153 zone()), |
| 152 zone()), | 154 zone()), |
| 153 0); | 155 0); |
| 154 Node* context = Parameter(Type::Any(), 1); | 156 Node* context = Parameter(Type::Any(), 1); |
| 155 Reduction r = | 157 Reduction r = |
| 156 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); | 158 Reduce(graph()->NewNode(javascript()->UnaryNot(LanguageMode::SLOPPY), |
| 159 input, context)); |
| 157 ASSERT_TRUE(r.Changed()); | 160 ASSERT_TRUE(r.Changed()); |
| 158 EXPECT_THAT(r.replacement(), IsTrueConstant()); | 161 EXPECT_THAT(r.replacement(), IsTrueConstant()); |
| 159 } | 162 } |
| 160 | 163 |
| 161 | 164 |
| 162 TEST_F(JSTypedLoweringTest, JSUnaryNotWithTruish) { | 165 TEST_F(JSTypedLoweringTest, JSUnaryNotWithTruish) { |
| 163 Node* input = Parameter( | 166 Node* input = Parameter( |
| 164 Type::Union( | 167 Type::Union( |
| 165 Type::Constant(factory()->true_value(), zone()), | 168 Type::Constant(factory()->true_value(), zone()), |
| 166 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone()), | 169 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone()), |
| 167 zone()), | 170 zone()), |
| 168 0); | 171 0); |
| 169 Node* context = Parameter(Type::Any(), 1); | 172 Node* context = Parameter(Type::Any(), 1); |
| 170 Reduction r = | 173 Reduction r = |
| 171 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); | 174 Reduce(graph()->NewNode(javascript()->UnaryNot(LanguageMode::SLOPPY), |
| 175 input, context)); |
| 172 ASSERT_TRUE(r.Changed()); | 176 ASSERT_TRUE(r.Changed()); |
| 173 EXPECT_THAT(r.replacement(), IsFalseConstant()); | 177 EXPECT_THAT(r.replacement(), IsFalseConstant()); |
| 174 } | 178 } |
| 175 | 179 |
| 176 | 180 |
| 177 TEST_F(JSTypedLoweringTest, JSUnaryNotWithNonZeroPlainNumber) { | 181 TEST_F(JSTypedLoweringTest, JSUnaryNotWithNonZeroPlainNumber) { |
| 178 Node* input = Parameter(Type::Range(1.0, 42.0, zone()), 0); | 182 Node* input = Parameter(Type::Range(1.0, 42.0, zone()), 0); |
| 179 Node* context = Parameter(Type::Any(), 1); | 183 Node* context = Parameter(Type::Any(), 1); |
| 180 Reduction r = | 184 Reduction r = |
| 181 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); | 185 Reduce(graph()->NewNode(javascript()->UnaryNot(LanguageMode::SLOPPY), |
| 186 input, context)); |
| 182 ASSERT_TRUE(r.Changed()); | 187 ASSERT_TRUE(r.Changed()); |
| 183 EXPECT_THAT(r.replacement(), IsFalseConstant()); | 188 EXPECT_THAT(r.replacement(), IsFalseConstant()); |
| 184 } | 189 } |
| 185 | 190 |
| 186 | 191 |
| 187 TEST_F(JSTypedLoweringTest, JSUnaryNotWithString) { | 192 TEST_F(JSTypedLoweringTest, JSUnaryNotWithString) { |
| 188 Node* input = Parameter(Type::String(), 0); | 193 Node* input = Parameter(Type::String(), 0); |
| 189 Node* context = Parameter(Type::Any(), 1); | 194 Node* context = Parameter(Type::Any(), 1); |
| 190 Reduction r = | 195 Reduction r = |
| 191 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); | 196 Reduce(graph()->NewNode(javascript()->UnaryNot(LanguageMode::SLOPPY), |
| 197 input, context)); |
| 192 ASSERT_TRUE(r.Changed()); | 198 ASSERT_TRUE(r.Changed()); |
| 193 EXPECT_THAT( | 199 EXPECT_THAT( |
| 194 r.replacement(), | 200 r.replacement(), |
| 195 IsNumberEqual(IsLoadField(AccessBuilder::ForStringLength(zone()), input, | 201 IsNumberEqual(IsLoadField(AccessBuilder::ForStringLength(zone()), input, |
| 196 graph()->start(), graph()->start()), | 202 graph()->start(), graph()->start()), |
| 197 IsNumberConstant(0.0))); | 203 IsNumberConstant(0.0))); |
| 198 } | 204 } |
| 199 | 205 |
| 200 | 206 |
| 201 TEST_F(JSTypedLoweringTest, JSUnaryNotWithAny) { | 207 TEST_F(JSTypedLoweringTest, JSUnaryNotWithAny) { |
| 202 Node* input = Parameter(Type::Any(), 0); | 208 Node* input = Parameter(Type::Any(), 0); |
| 203 Node* context = Parameter(Type::Any(), 1); | 209 Node* context = Parameter(Type::Any(), 1); |
| 204 Reduction r = | 210 Reduction r = |
| 205 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); | 211 Reduce(graph()->NewNode(javascript()->UnaryNot(LanguageMode::SLOPPY), |
| 212 input, context)); |
| 206 ASSERT_FALSE(r.Changed()); | 213 ASSERT_FALSE(r.Changed()); |
| 207 } | 214 } |
| 208 | 215 |
| 209 | 216 |
| 210 // ----------------------------------------------------------------------------- | 217 // ----------------------------------------------------------------------------- |
| 211 // Constant propagation | 218 // Constant propagation |
| 212 | 219 |
| 213 | 220 |
| 214 TEST_F(JSTypedLoweringTest, ParameterWithMinusZero) { | 221 TEST_F(JSTypedLoweringTest, ParameterWithMinusZero) { |
| 215 { | 222 { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 // JSShiftLeft | 455 // JSShiftLeft |
| 449 | 456 |
| 450 | 457 |
| 451 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndConstant) { | 458 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndConstant) { |
| 452 Node* const lhs = Parameter(Type::Signed32()); | 459 Node* const lhs = Parameter(Type::Signed32()); |
| 453 Node* const context = UndefinedConstant(); | 460 Node* const context = UndefinedConstant(); |
| 454 Node* const effect = graph()->start(); | 461 Node* const effect = graph()->start(); |
| 455 Node* const control = graph()->start(); | 462 Node* const control = graph()->start(); |
| 456 TRACED_FORRANGE(double, rhs, 0, 31) { | 463 TRACED_FORRANGE(double, rhs, 0, 31) { |
| 457 Reduction r = | 464 Reduction r = |
| 458 Reduce(graph()->NewNode(javascript()->ShiftLeft(), lhs, | 465 Reduce(graph()->NewNode(javascript()->ShiftLeft(LanguageMode::SLOPPY), |
| 459 NumberConstant(rhs), context, effect, control)); | 466 lhs, NumberConstant(rhs), context, effect, |
| 467 control)); |
| 460 ASSERT_TRUE(r.Changed()); | 468 ASSERT_TRUE(r.Changed()); |
| 461 EXPECT_THAT(r.replacement(), | 469 EXPECT_THAT(r.replacement(), |
| 462 IsWord32Shl(lhs, IsNumberConstant(BitEq(rhs)))); | 470 IsWord32Shl(lhs, IsNumberConstant(BitEq(rhs)))); |
| 463 } | 471 } |
| 464 } | 472 } |
| 465 | 473 |
| 466 | 474 |
| 467 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndUnsigned32) { | 475 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndUnsigned32) { |
| 468 Node* const lhs = Parameter(Type::Signed32()); | 476 Node* const lhs = Parameter(Type::Signed32()); |
| 469 Node* const rhs = Parameter(Type::Unsigned32()); | 477 Node* const rhs = Parameter(Type::Unsigned32()); |
| 470 Node* const context = UndefinedConstant(); | 478 Node* const context = UndefinedConstant(); |
| 471 Node* const effect = graph()->start(); | 479 Node* const effect = graph()->start(); |
| 472 Node* const control = graph()->start(); | 480 Node* const control = graph()->start(); |
| 473 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftLeft(), lhs, rhs, | 481 Reduction r = Reduce(graph()->NewNode(javascript()-> |
| 474 context, effect, control)); | 482 ShiftLeft(LanguageMode::SLOPPY), |
| 483 lhs, rhs, context, effect, control)); |
| 475 ASSERT_TRUE(r.Changed()); | 484 ASSERT_TRUE(r.Changed()); |
| 476 EXPECT_THAT(r.replacement(), | 485 EXPECT_THAT(r.replacement(), |
| 477 IsWord32Shl(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); | 486 IsWord32Shl(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); |
| 478 } | 487 } |
| 479 | 488 |
| 480 | 489 |
| 481 // ----------------------------------------------------------------------------- | 490 // ----------------------------------------------------------------------------- |
| 482 // JSShiftRight | 491 // JSShiftRight |
| 483 | 492 |
| 484 | 493 |
| 485 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndConstant) { | 494 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndConstant) { |
| 486 Node* const lhs = Parameter(Type::Signed32()); | 495 Node* const lhs = Parameter(Type::Signed32()); |
| 487 Node* const context = UndefinedConstant(); | 496 Node* const context = UndefinedConstant(); |
| 488 Node* const effect = graph()->start(); | 497 Node* const effect = graph()->start(); |
| 489 Node* const control = graph()->start(); | 498 Node* const control = graph()->start(); |
| 490 TRACED_FORRANGE(double, rhs, 0, 31) { | 499 TRACED_FORRANGE(double, rhs, 0, 31) { |
| 491 Reduction r = | 500 Reduction r = |
| 492 Reduce(graph()->NewNode(javascript()->ShiftRight(), lhs, | 501 Reduce(graph()->NewNode(javascript()-> |
| 502 ShiftRight(LanguageMode::SLOPPY), lhs, |
| 493 NumberConstant(rhs), context, effect, control)); | 503 NumberConstant(rhs), context, effect, control)); |
| 494 ASSERT_TRUE(r.Changed()); | 504 ASSERT_TRUE(r.Changed()); |
| 495 EXPECT_THAT(r.replacement(), | 505 EXPECT_THAT(r.replacement(), |
| 496 IsWord32Sar(lhs, IsNumberConstant(BitEq(rhs)))); | 506 IsWord32Sar(lhs, IsNumberConstant(BitEq(rhs)))); |
| 497 } | 507 } |
| 498 } | 508 } |
| 499 | 509 |
| 500 | 510 |
| 501 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndUnsigned32) { | 511 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndUnsigned32) { |
| 502 Node* const lhs = Parameter(Type::Signed32()); | 512 Node* const lhs = Parameter(Type::Signed32()); |
| 503 Node* const rhs = Parameter(Type::Unsigned32()); | 513 Node* const rhs = Parameter(Type::Unsigned32()); |
| 504 Node* const context = UndefinedConstant(); | 514 Node* const context = UndefinedConstant(); |
| 505 Node* const effect = graph()->start(); | 515 Node* const effect = graph()->start(); |
| 506 Node* const control = graph()->start(); | 516 Node* const control = graph()->start(); |
| 507 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRight(), lhs, rhs, | 517 Reduction r = Reduce(graph()->NewNode(javascript()-> |
| 508 context, effect, control)); | 518 ShiftRight(LanguageMode::SLOPPY), |
| 519 lhs, rhs, context, effect, control)); |
| 509 ASSERT_TRUE(r.Changed()); | 520 ASSERT_TRUE(r.Changed()); |
| 510 EXPECT_THAT(r.replacement(), | 521 EXPECT_THAT(r.replacement(), |
| 511 IsWord32Sar(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); | 522 IsWord32Sar(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); |
| 512 } | 523 } |
| 513 | 524 |
| 514 | 525 |
| 515 // ----------------------------------------------------------------------------- | 526 // ----------------------------------------------------------------------------- |
| 516 // JSShiftRightLogical | 527 // JSShiftRightLogical |
| 517 | 528 |
| 518 | 529 |
| 519 TEST_F(JSTypedLoweringTest, JSShiftRightLogicalWithUnsigned32AndConstant) { | 530 TEST_F(JSTypedLoweringTest, |
| 531 JSShiftRightLogicalWithUnsigned32AndConstant) { |
| 520 Node* const lhs = Parameter(Type::Unsigned32()); | 532 Node* const lhs = Parameter(Type::Unsigned32()); |
| 521 Node* const context = UndefinedConstant(); | 533 Node* const context = UndefinedConstant(); |
| 522 Node* const effect = graph()->start(); | 534 Node* const effect = graph()->start(); |
| 523 Node* const control = graph()->start(); | 535 Node* const control = graph()->start(); |
| 524 TRACED_FORRANGE(double, rhs, 0, 31) { | 536 TRACED_FORRANGE(double, rhs, 0, 31) { |
| 525 Reduction r = | 537 Reduction r = |
| 526 Reduce(graph()->NewNode(javascript()->ShiftRightLogical(), lhs, | 538 Reduce(graph()->NewNode(javascript()-> |
| 527 NumberConstant(rhs), context, effect, control)); | 539 ShiftRightLogical(LanguageMode::SLOPPY), |
| 540 lhs, NumberConstant(rhs), context, effect, |
| 541 control)); |
| 528 ASSERT_TRUE(r.Changed()); | 542 ASSERT_TRUE(r.Changed()); |
| 529 EXPECT_THAT(r.replacement(), | 543 EXPECT_THAT(r.replacement(), |
| 530 IsWord32Shr(lhs, IsNumberConstant(BitEq(rhs)))); | 544 IsWord32Shr(lhs, IsNumberConstant(BitEq(rhs)))); |
| 531 } | 545 } |
| 532 } | 546 } |
| 533 | 547 |
| 534 | 548 |
| 535 TEST_F(JSTypedLoweringTest, JSShiftRightLogicalWithUnsigned32AndUnsigned32) { | 549 TEST_F(JSTypedLoweringTest, |
| 550 JSShiftRightLogicalWithUnsigned32AndUnsigned32) { |
| 536 Node* const lhs = Parameter(Type::Unsigned32()); | 551 Node* const lhs = Parameter(Type::Unsigned32()); |
| 537 Node* const rhs = Parameter(Type::Unsigned32()); | 552 Node* const rhs = Parameter(Type::Unsigned32()); |
| 538 Node* const context = UndefinedConstant(); | 553 Node* const context = UndefinedConstant(); |
| 539 Node* const effect = graph()->start(); | 554 Node* const effect = graph()->start(); |
| 540 Node* const control = graph()->start(); | 555 Node* const control = graph()->start(); |
| 541 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRightLogical(), lhs, | 556 Reduction r = Reduce(graph()->NewNode(javascript()-> |
| 542 rhs, context, effect, control)); | 557 ShiftRightLogical(LanguageMode::SLOPPY), |
| 558 lhs, rhs, context, effect, control)); |
| 543 ASSERT_TRUE(r.Changed()); | 559 ASSERT_TRUE(r.Changed()); |
| 544 EXPECT_THAT(r.replacement(), | 560 EXPECT_THAT(r.replacement(), |
| 545 IsWord32Shr(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); | 561 IsWord32Shr(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); |
| 546 } | 562 } |
| 547 | 563 |
| 548 | 564 |
| 549 // ----------------------------------------------------------------------------- | 565 // ----------------------------------------------------------------------------- |
| 550 // JSLoadContext | 566 // JSLoadContext |
| 551 | 567 |
| 552 | 568 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 context, EmptyFrameState(), effect, control)); | 883 context, EmptyFrameState(), effect, control)); |
| 868 | 884 |
| 869 ASSERT_TRUE(r.Changed()); | 885 ASSERT_TRUE(r.Changed()); |
| 870 EXPECT_THAT(r.replacement(), matches[i]); | 886 EXPECT_THAT(r.replacement(), matches[i]); |
| 871 } | 887 } |
| 872 } | 888 } |
| 873 | 889 |
| 874 } // namespace compiler | 890 } // namespace compiler |
| 875 } // namespace internal | 891 } // namespace internal |
| 876 } // namespace v8 | 892 } // namespace v8 |
| OLD | NEW |