Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: test/unittests/compiler/js-typed-lowering-unittest.cc

Issue 2220573002: [turbofan] Add NumberOperationHint for speculative number operations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Update comment. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/simplified-operator.cc ('k') | test/unittests/compiler/node-test-utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 graph()->NewNode(javascript()->StrictEqual(CompareOperationHints::Any()), 409 graph()->NewNode(javascript()->StrictEqual(CompareOperationHints::Any()),
410 lhs, rhs, context)); 410 lhs, rhs, context));
411 ASSERT_TRUE(r.Changed()); 411 ASSERT_TRUE(r.Changed());
412 EXPECT_THAT(r.replacement(), IsReferenceEqual(Type::Unique(), lhs, rhs)); 412 EXPECT_THAT(r.replacement(), IsReferenceEqual(Type::Unique(), lhs, rhs));
413 } 413 }
414 414
415 415
416 // ----------------------------------------------------------------------------- 416 // -----------------------------------------------------------------------------
417 // JSShiftLeft 417 // JSShiftLeft
418 418
419
420 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndConstant) { 419 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndConstant) {
421 BinaryOperationHints const hints = BinaryOperationHints::Any(); 420 BinaryOperationHints const hints = BinaryOperationHints::Any();
422 Node* const lhs = Parameter(Type::Signed32()); 421 Node* const lhs = Parameter(Type::Signed32());
423 Node* const context = UndefinedConstant(); 422 Node* const context = UndefinedConstant();
424 Node* const effect = graph()->start(); 423 Node* const effect = graph()->start();
425 Node* const control = graph()->start(); 424 Node* const control = graph()->start();
426 TRACED_FORRANGE(double, rhs, 0, 31) { 425 TRACED_FORRANGE(double, rhs, 0, 31) {
427 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftLeft(hints), lhs, 426 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftLeft(hints), lhs,
428 NumberConstant(rhs), context, 427 NumberConstant(rhs), context,
429 EmptyFrameState(), effect, control)); 428 EmptyFrameState(), effect, control));
430 ASSERT_TRUE(r.Changed()); 429 ASSERT_TRUE(r.Changed());
431 EXPECT_THAT(r.replacement(), 430 EXPECT_THAT(r.replacement(),
432 IsNumberShiftLeft(lhs, IsNumberConstant(BitEq(rhs)))); 431 IsNumberShiftLeft(lhs, IsNumberConstant(BitEq(rhs))));
433 } 432 }
434 } 433 }
435 434
436
437 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndUnsigned32) { 435 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndUnsigned32) {
438 BinaryOperationHints const hints = BinaryOperationHints::Any(); 436 BinaryOperationHints const hints = BinaryOperationHints::Any();
439 Node* const lhs = Parameter(Type::Signed32()); 437 Node* const lhs = Parameter(Type::Signed32());
440 Node* const rhs = Parameter(Type::Unsigned32()); 438 Node* const rhs = Parameter(Type::Unsigned32());
441 Node* const context = UndefinedConstant(); 439 Node* const context = UndefinedConstant();
442 Node* const effect = graph()->start(); 440 Node* const effect = graph()->start();
443 Node* const control = graph()->start(); 441 Node* const control = graph()->start();
444 Reduction r = 442 Reduction r =
445 Reduce(graph()->NewNode(javascript()->ShiftLeft(hints), lhs, rhs, context, 443 Reduce(graph()->NewNode(javascript()->ShiftLeft(hints), lhs, rhs, context,
446 EmptyFrameState(), effect, control)); 444 EmptyFrameState(), effect, control));
447 ASSERT_TRUE(r.Changed()); 445 ASSERT_TRUE(r.Changed());
448 EXPECT_THAT(r.replacement(), IsNumberShiftLeft(lhs, rhs)); 446 EXPECT_THAT(r.replacement(), IsNumberShiftLeft(lhs, rhs));
449 } 447 }
450 448
451 TEST_F(JSTypedLoweringTest, JSShiftLeftWithTypeFeedback) { 449 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSignedSmallHint) {
452 BinaryOperationHints::Hint const feedback_types[] = { 450 BinaryOperationHints const hints(BinaryOperationHints::kSignedSmall,
453 BinaryOperationHints::kSignedSmall, 451 BinaryOperationHints::kSignedSmall,
454 BinaryOperationHints::kNumberOrOddball}; 452 BinaryOperationHints::kSignedSmall);
455 for (BinaryOperationHints::Hint feedback : feedback_types) { 453 Node* lhs = Parameter(Type::Number(), 2);
456 BinaryOperationHints const hints(feedback, feedback, feedback); 454 Node* rhs = Parameter(Type::Number(), 3);
457 Node* lhs = Parameter(Type::Number(), 2); 455 Node* effect = graph()->start();
458 Node* rhs = Parameter(Type::Number(), 3); 456 Node* control = graph()->start();
459 Node* effect = graph()->start(); 457 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftLeft(hints), lhs,
460 Node* control = graph()->start(); 458 rhs, UndefinedConstant(),
461 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftLeft(hints), lhs, 459 EmptyFrameState(), effect, control));
462 rhs, UndefinedConstant(), 460 ASSERT_TRUE(r.Changed());
463 EmptyFrameState(), effect, control)); 461 EXPECT_THAT(r.replacement(),
464 ASSERT_TRUE(r.Changed()); 462 IsSpeculativeNumberShiftLeft(NumberOperationHint::kSignedSmall,
465 EXPECT_THAT(r.replacement(), IsSpeculativeNumberShiftLeft( 463 lhs, rhs, effect, control));
466 feedback, lhs, rhs, effect, control)); 464 }
467 } 465
466 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32Hint) {
467 BinaryOperationHints const hints(BinaryOperationHints::kSigned32,
468 BinaryOperationHints::kSigned32,
469 BinaryOperationHints::kSigned32);
470 Node* lhs = Parameter(Type::Number(), 2);
471 Node* rhs = Parameter(Type::Number(), 3);
472 Node* effect = graph()->start();
473 Node* control = graph()->start();
474 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftLeft(hints), lhs,
475 rhs, UndefinedConstant(),
476 EmptyFrameState(), effect, control));
477 ASSERT_TRUE(r.Changed());
478 EXPECT_THAT(r.replacement(),
479 IsSpeculativeNumberShiftLeft(NumberOperationHint::kSigned32, lhs,
480 rhs, effect, control));
481 }
482
483 TEST_F(JSTypedLoweringTest, JSShiftLeftWithNumberOrOddballHint) {
484 BinaryOperationHints const hints(BinaryOperationHints::kNumberOrOddball,
485 BinaryOperationHints::kNumberOrOddball,
486 BinaryOperationHints::kNumberOrOddball);
487 Node* lhs = Parameter(Type::Number(), 2);
488 Node* rhs = Parameter(Type::Number(), 3);
489 Node* effect = graph()->start();
490 Node* control = graph()->start();
491 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftLeft(hints), lhs,
492 rhs, UndefinedConstant(),
493 EmptyFrameState(), effect, control));
494 ASSERT_TRUE(r.Changed());
495 EXPECT_THAT(r.replacement(), IsSpeculativeNumberShiftLeft(
496 NumberOperationHint::kNumberOrOddball, lhs,
497 rhs, effect, control));
468 } 498 }
469 499
470 // ----------------------------------------------------------------------------- 500 // -----------------------------------------------------------------------------
471 // JSShiftRight 501 // JSShiftRight
472 502
473 503
474 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndConstant) { 504 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndConstant) {
475 BinaryOperationHints const hints = BinaryOperationHints::Any(); 505 BinaryOperationHints const hints = BinaryOperationHints::Any();
476 Node* const lhs = Parameter(Type::Signed32()); 506 Node* const lhs = Parameter(Type::Signed32());
477 Node* const context = UndefinedConstant(); 507 Node* const context = UndefinedConstant();
(...skipping 17 matching lines...) Expand all
495 Node* const context = UndefinedConstant(); 525 Node* const context = UndefinedConstant();
496 Node* const effect = graph()->start(); 526 Node* const effect = graph()->start();
497 Node* const control = graph()->start(); 527 Node* const control = graph()->start();
498 Reduction r = 528 Reduction r =
499 Reduce(graph()->NewNode(javascript()->ShiftRight(hints), lhs, rhs, 529 Reduce(graph()->NewNode(javascript()->ShiftRight(hints), lhs, rhs,
500 context, EmptyFrameState(), effect, control)); 530 context, EmptyFrameState(), effect, control));
501 ASSERT_TRUE(r.Changed()); 531 ASSERT_TRUE(r.Changed());
502 EXPECT_THAT(r.replacement(), IsNumberShiftRight(lhs, rhs)); 532 EXPECT_THAT(r.replacement(), IsNumberShiftRight(lhs, rhs));
503 } 533 }
504 534
505 TEST_F(JSTypedLoweringTest, JSShiftRightWithTypeFeedback) { 535 TEST_F(JSTypedLoweringTest, JSShiftRightWithSignedSmallHint) {
506 BinaryOperationHints::Hint const feedback_types[] = { 536 BinaryOperationHints const hints(BinaryOperationHints::kSignedSmall,
507 BinaryOperationHints::kSignedSmall, 537 BinaryOperationHints::kSignedSmall,
508 BinaryOperationHints::kNumberOrOddball}; 538 BinaryOperationHints::kSignedSmall);
509 for (BinaryOperationHints::Hint feedback : feedback_types) { 539 Node* lhs = Parameter(Type::Number(), 2);
510 BinaryOperationHints const hints(feedback, feedback, feedback); 540 Node* rhs = Parameter(Type::Number(), 3);
511 Node* lhs = Parameter(Type::Number(), 2); 541 Node* effect = graph()->start();
512 Node* rhs = Parameter(Type::Number(), 3); 542 Node* control = graph()->start();
513 Node* effect = graph()->start(); 543 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRight(hints), lhs,
514 Node* control = graph()->start(); 544 rhs, UndefinedConstant(),
515 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRight(hints), lhs, 545 EmptyFrameState(), effect, control));
516 rhs, UndefinedConstant(), 546 ASSERT_TRUE(r.Changed());
517 EmptyFrameState(), effect, control)); 547 EXPECT_THAT(r.replacement(),
518 ASSERT_TRUE(r.Changed()); 548 IsSpeculativeNumberShiftRight(NumberOperationHint::kSignedSmall,
519 EXPECT_THAT(r.replacement(), IsSpeculativeNumberShiftRight( 549 lhs, rhs, effect, control));
520 feedback, lhs, rhs, effect, control)); 550 }
521 } 551
552 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32Hint) {
553 BinaryOperationHints const hints(BinaryOperationHints::kSigned32,
554 BinaryOperationHints::kSigned32,
555 BinaryOperationHints::kSigned32);
556 Node* lhs = Parameter(Type::Number(), 2);
557 Node* rhs = Parameter(Type::Number(), 3);
558 Node* effect = graph()->start();
559 Node* control = graph()->start();
560 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRight(hints), lhs,
561 rhs, UndefinedConstant(),
562 EmptyFrameState(), effect, control));
563 ASSERT_TRUE(r.Changed());
564 EXPECT_THAT(r.replacement(),
565 IsSpeculativeNumberShiftRight(NumberOperationHint::kSigned32, lhs,
566 rhs, effect, control));
567 }
568
569 TEST_F(JSTypedLoweringTest, JSShiftRightWithNumberOrOddballHint) {
570 BinaryOperationHints const hints(BinaryOperationHints::kNumberOrOddball,
571 BinaryOperationHints::kNumberOrOddball,
572 BinaryOperationHints::kNumberOrOddball);
573 Node* lhs = Parameter(Type::Number(), 2);
574 Node* rhs = Parameter(Type::Number(), 3);
575 Node* effect = graph()->start();
576 Node* control = graph()->start();
577 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRight(hints), lhs,
578 rhs, UndefinedConstant(),
579 EmptyFrameState(), effect, control));
580 ASSERT_TRUE(r.Changed());
581 EXPECT_THAT(r.replacement(), IsSpeculativeNumberShiftRight(
582 NumberOperationHint::kNumberOrOddball, lhs,
583 rhs, effect, control));
522 } 584 }
523 585
524 // ----------------------------------------------------------------------------- 586 // -----------------------------------------------------------------------------
525 // JSShiftRightLogical 587 // JSShiftRightLogical
526 588
527 589
528 TEST_F(JSTypedLoweringTest, 590 TEST_F(JSTypedLoweringTest,
529 JSShiftRightLogicalWithUnsigned32AndConstant) { 591 JSShiftRightLogicalWithUnsigned32AndConstant) {
530 BinaryOperationHints const hints = BinaryOperationHints::Any(); 592 BinaryOperationHints const hints = BinaryOperationHints::Any();
531 Node* const lhs = Parameter(Type::Unsigned32()); 593 Node* const lhs = Parameter(Type::Unsigned32());
(...skipping 18 matching lines...) Expand all
550 Node* const context = UndefinedConstant(); 612 Node* const context = UndefinedConstant();
551 Node* const effect = graph()->start(); 613 Node* const effect = graph()->start();
552 Node* const control = graph()->start(); 614 Node* const control = graph()->start();
553 Reduction r = 615 Reduction r =
554 Reduce(graph()->NewNode(javascript()->ShiftRightLogical(hints), lhs, rhs, 616 Reduce(graph()->NewNode(javascript()->ShiftRightLogical(hints), lhs, rhs,
555 context, EmptyFrameState(), effect, control)); 617 context, EmptyFrameState(), effect, control));
556 ASSERT_TRUE(r.Changed()); 618 ASSERT_TRUE(r.Changed());
557 EXPECT_THAT(r.replacement(), IsNumberShiftRightLogical(lhs, rhs)); 619 EXPECT_THAT(r.replacement(), IsNumberShiftRightLogical(lhs, rhs));
558 } 620 }
559 621
560 TEST_F(JSTypedLoweringTest, JSShiftRightLogicalWithTypeFeedback) { 622 TEST_F(JSTypedLoweringTest, JSShiftRightLogicalWithSignedSmallHint) {
561 BinaryOperationHints::Hint const feedback_types[] = { 623 BinaryOperationHints const hints(BinaryOperationHints::kSignedSmall,
562 BinaryOperationHints::kSignedSmall, 624 BinaryOperationHints::kSignedSmall,
563 BinaryOperationHints::kNumberOrOddball}; 625 BinaryOperationHints::kSignedSmall);
564 for (BinaryOperationHints::Hint feedback : feedback_types) { 626 Node* lhs = Parameter(Type::Number(), 2);
565 BinaryOperationHints const hints(feedback, feedback, feedback); 627 Node* rhs = Parameter(Type::Number(), 3);
566 Node* lhs = Parameter(Type::Number(), 2); 628 Node* effect = graph()->start();
567 Node* rhs = Parameter(Type::Number(), 3); 629 Node* control = graph()->start();
568 Node* effect = graph()->start(); 630 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRightLogical(hints),
569 Node* control = graph()->start(); 631 lhs, rhs, UndefinedConstant(),
570 Reduction r = Reduce(graph()->NewNode( 632 EmptyFrameState(), effect, control));
571 javascript()->ShiftRightLogical(hints), lhs, rhs, UndefinedConstant(), 633 ASSERT_TRUE(r.Changed());
572 EmptyFrameState(), effect, control)); 634 EXPECT_THAT(r.replacement(), IsSpeculativeNumberShiftRightLogical(
573 ASSERT_TRUE(r.Changed()); 635 NumberOperationHint::kSignedSmall, lhs, rhs,
574 EXPECT_THAT(r.replacement(), IsSpeculativeNumberShiftRightLogical( 636 effect, control));
575 feedback, lhs, rhs, effect, control)); 637 }
576 } 638
639 TEST_F(JSTypedLoweringTest, JSShiftRightLogicalWithSigned32Hint) {
640 BinaryOperationHints const hints(BinaryOperationHints::kSigned32,
641 BinaryOperationHints::kSigned32,
642 BinaryOperationHints::kSigned32);
643 Node* lhs = Parameter(Type::Number(), 2);
644 Node* rhs = Parameter(Type::Number(), 3);
645 Node* effect = graph()->start();
646 Node* control = graph()->start();
647 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRightLogical(hints),
648 lhs, rhs, UndefinedConstant(),
649 EmptyFrameState(), effect, control));
650 ASSERT_TRUE(r.Changed());
651 EXPECT_THAT(r.replacement(),
652 IsSpeculativeNumberShiftRightLogical(
653 NumberOperationHint::kSigned32, lhs, rhs, effect, control));
654 }
655
656 TEST_F(JSTypedLoweringTest, JSShiftRightLogicalWithNumberOrOddballHint) {
657 BinaryOperationHints const hints(BinaryOperationHints::kNumberOrOddball,
658 BinaryOperationHints::kNumberOrOddball,
659 BinaryOperationHints::kNumberOrOddball);
660 Node* lhs = Parameter(Type::Number(), 2);
661 Node* rhs = Parameter(Type::Number(), 3);
662 Node* effect = graph()->start();
663 Node* control = graph()->start();
664 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRightLogical(hints),
665 lhs, rhs, UndefinedConstant(),
666 EmptyFrameState(), effect, control));
667 ASSERT_TRUE(r.Changed());
668 EXPECT_THAT(r.replacement(), IsSpeculativeNumberShiftRightLogical(
669 NumberOperationHint::kNumberOrOddball, lhs,
670 rhs, effect, control));
577 } 671 }
578 672
579 // ----------------------------------------------------------------------------- 673 // -----------------------------------------------------------------------------
580 // JSLoadContext 674 // JSLoadContext
581 675
582 676
583 TEST_F(JSTypedLoweringTest, JSLoadContext) { 677 TEST_F(JSTypedLoweringTest, JSLoadContext) {
584 Node* const context = Parameter(Type::Any()); 678 Node* const context = Parameter(Type::Any());
585 Node* const effect = graph()->start(); 679 Node* const effect = graph()->start();
586 static bool kBooleans[] = {false, true}; 680 static bool kBooleans[] = {false, true};
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 Node* lhs = Parameter(Type::Number(), 0); 1006 Node* lhs = Parameter(Type::Number(), 0);
913 Node* rhs = Parameter(Type::Number(), 1); 1007 Node* rhs = Parameter(Type::Number(), 1);
914 Node* context = Parameter(Type::Any(), 2); 1008 Node* context = Parameter(Type::Any(), 2);
915 Node* frame_state = EmptyFrameState(); 1009 Node* frame_state = EmptyFrameState();
916 Node* effect = graph()->start(); 1010 Node* effect = graph()->start();
917 Node* control = graph()->start(); 1011 Node* control = graph()->start();
918 Reduction r = Reduce(graph()->NewNode(javascript()->Add(hints), lhs, rhs, 1012 Reduction r = Reduce(graph()->NewNode(javascript()->Add(hints), lhs, rhs,
919 context, frame_state, effect, control)); 1013 context, frame_state, effect, control));
920 ASSERT_TRUE(r.Changed()); 1014 ASSERT_TRUE(r.Changed());
921 EXPECT_THAT(r.replacement(), 1015 EXPECT_THAT(r.replacement(),
922 IsSpeculativeNumberAdd(BinaryOperationHints::kSignedSmall, lhs, 1016 IsSpeculativeNumberAdd(NumberOperationHint::kSignedSmall, lhs,
923 rhs, effect, control)); 1017 rhs, effect, control));
924 } 1018 }
925 1019
926 // ----------------------------------------------------------------------------- 1020 // -----------------------------------------------------------------------------
927 // JSSubtract 1021 // JSSubtract
928 1022
929 TEST_F(JSTypedLoweringTest, JSSubtractSmis) { 1023 TEST_F(JSTypedLoweringTest, JSSubtractSmis) {
930 BinaryOperationHints const hints(BinaryOperationHints::kSignedSmall, 1024 BinaryOperationHints const hints(BinaryOperationHints::kSignedSmall,
931 BinaryOperationHints::kSignedSmall, 1025 BinaryOperationHints::kSignedSmall,
932 BinaryOperationHints::kSignedSmall); 1026 BinaryOperationHints::kSignedSmall);
933 Node* lhs = Parameter(Type::Number(), 0); 1027 Node* lhs = Parameter(Type::Number(), 0);
934 Node* rhs = Parameter(Type::Number(), 1); 1028 Node* rhs = Parameter(Type::Number(), 1);
935 Node* context = Parameter(Type::Any(), 2); 1029 Node* context = Parameter(Type::Any(), 2);
936 Node* frame_state = EmptyFrameState(); 1030 Node* frame_state = EmptyFrameState();
937 Node* effect = graph()->start(); 1031 Node* effect = graph()->start();
938 Node* control = graph()->start(); 1032 Node* control = graph()->start();
939 Reduction r = Reduce(graph()->NewNode(javascript()->Subtract(hints), lhs, rhs, 1033 Reduction r = Reduce(graph()->NewNode(javascript()->Subtract(hints), lhs, rhs,
940 context, frame_state, effect, control)); 1034 context, frame_state, effect, control));
941 ASSERT_TRUE(r.Changed()); 1035 ASSERT_TRUE(r.Changed());
942 EXPECT_THAT(r.replacement(), 1036 EXPECT_THAT(r.replacement(),
943 IsSpeculativeNumberSubtract(BinaryOperationHints::kSignedSmall, 1037 IsSpeculativeNumberSubtract(NumberOperationHint::kSignedSmall,
944 lhs, rhs, effect, control)); 1038 lhs, rhs, effect, control));
945 } 1039 }
946 1040
947 // ----------------------------------------------------------------------------- 1041 // -----------------------------------------------------------------------------
948 // JSInstanceOf 1042 // JSInstanceOf
949 // Test that instanceOf is reduced if and only if the right-hand side is a 1043 // Test that instanceOf is reduced if and only if the right-hand side is a
950 // function constant. Functional correctness is ensured elsewhere. 1044 // function constant. Functional correctness is ensured elsewhere.
951 1045
952 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithoutSmiCheck) { 1046 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithoutSmiCheck) {
953 Node* const context = Parameter(Type::Any()); 1047 Node* const context = Parameter(Type::Any());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, 1096 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context,
1003 frame_state, effect, control); 1097 frame_state, effect, control);
1004 Reduction r = Reduce(instanceOf); 1098 Reduction r = Reduce(instanceOf);
1005 ASSERT_FALSE(r.Changed()); 1099 ASSERT_FALSE(r.Changed());
1006 ASSERT_EQ(instanceOf, dummy->InputAt(0)); 1100 ASSERT_EQ(instanceOf, dummy->InputAt(0));
1007 } 1101 }
1008 1102
1009 // ----------------------------------------------------------------------------- 1103 // -----------------------------------------------------------------------------
1010 // JSBitwiseAnd 1104 // JSBitwiseAnd
1011 1105
1012 TEST_F(JSTypedLoweringTest, JSBitwiseAndWithTypeFeedback) { 1106 TEST_F(JSTypedLoweringTest, JSBitwiseAndWithSignedSmallHint) {
1013 BinaryOperationHints::Hint const feedback_types[] = { 1107 BinaryOperationHints const hints(BinaryOperationHints::kSignedSmall,
1014 BinaryOperationHints::kSignedSmall, 1108 BinaryOperationHints::kSignedSmall,
1015 BinaryOperationHints::kNumberOrOddball}; 1109 BinaryOperationHints::kSignedSmall);
1016 for (BinaryOperationHints::Hint feedback : feedback_types) { 1110 Node* lhs = Parameter(Type::Number(), 2);
1017 BinaryOperationHints const hints(feedback, feedback, feedback); 1111 Node* rhs = Parameter(Type::Number(), 3);
1018 Node* lhs = Parameter(Type::Number(), 2); 1112 Node* effect = graph()->start();
1019 Node* rhs = Parameter(Type::Number(), 3); 1113 Node* control = graph()->start();
1020 Node* effect = graph()->start(); 1114 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseAnd(hints), lhs,
1021 Node* control = graph()->start(); 1115 rhs, UndefinedConstant(),
1022 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseAnd(hints), lhs, 1116 EmptyFrameState(), effect, control));
1023 rhs, UndefinedConstant(), 1117 ASSERT_TRUE(r.Changed());
1024 EmptyFrameState(), effect, control)); 1118 EXPECT_THAT(r.replacement(),
1025 ASSERT_TRUE(r.Changed()); 1119 IsSpeculativeNumberBitwiseAnd(NumberOperationHint::kSignedSmall,
1026 EXPECT_THAT(r.replacement(), IsSpeculativeNumberBitwiseAnd( 1120 lhs, rhs, effect, control));
1027 feedback, lhs, rhs, effect, control)); 1121 }
1028 } 1122
1123 TEST_F(JSTypedLoweringTest, JSBitwiseAndWithSigned32Hint) {
1124 BinaryOperationHints const hints(BinaryOperationHints::kSigned32,
1125 BinaryOperationHints::kSigned32,
1126 BinaryOperationHints::kSigned32);
1127 Node* lhs = Parameter(Type::Number(), 2);
1128 Node* rhs = Parameter(Type::Number(), 3);
1129 Node* effect = graph()->start();
1130 Node* control = graph()->start();
1131 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseAnd(hints), lhs,
1132 rhs, UndefinedConstant(),
1133 EmptyFrameState(), effect, control));
1134 ASSERT_TRUE(r.Changed());
1135 EXPECT_THAT(r.replacement(),
1136 IsSpeculativeNumberBitwiseAnd(NumberOperationHint::kSigned32, lhs,
1137 rhs, effect, control));
1138 }
1139
1140 TEST_F(JSTypedLoweringTest, JSBitwiseAndWithNumberOrOddballHint) {
1141 BinaryOperationHints const hints(BinaryOperationHints::kNumberOrOddball,
1142 BinaryOperationHints::kNumberOrOddball,
1143 BinaryOperationHints::kNumberOrOddball);
1144 Node* lhs = Parameter(Type::Number(), 2);
1145 Node* rhs = Parameter(Type::Number(), 3);
1146 Node* effect = graph()->start();
1147 Node* control = graph()->start();
1148 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseAnd(hints), lhs,
1149 rhs, UndefinedConstant(),
1150 EmptyFrameState(), effect, control));
1151 ASSERT_TRUE(r.Changed());
1152 EXPECT_THAT(r.replacement(), IsSpeculativeNumberBitwiseAnd(
1153 NumberOperationHint::kNumberOrOddball, lhs,
1154 rhs, effect, control));
1029 } 1155 }
1030 1156
1031 // ----------------------------------------------------------------------------- 1157 // -----------------------------------------------------------------------------
1032 // JSBitwiseOr 1158 // JSBitwiseOr
1033 1159
1034 TEST_F(JSTypedLoweringTest, JSBitwiseOrWithTypeFeedback) { 1160 TEST_F(JSTypedLoweringTest, JSBitwiseOrWithSignedSmallHint) {
1035 BinaryOperationHints::Hint const feedback_types[] = { 1161 BinaryOperationHints const hints(BinaryOperationHints::kSignedSmall,
1036 BinaryOperationHints::kSignedSmall, 1162 BinaryOperationHints::kSignedSmall,
1037 BinaryOperationHints::kNumberOrOddball}; 1163 BinaryOperationHints::kSignedSmall);
1038 for (BinaryOperationHints::Hint feedback : feedback_types) { 1164 Node* lhs = Parameter(Type::Number(), 2);
1039 BinaryOperationHints const hints(feedback, feedback, feedback); 1165 Node* rhs = Parameter(Type::Number(), 3);
1040 Node* lhs = Parameter(Type::Number(), 2); 1166 Node* effect = graph()->start();
1041 Node* rhs = Parameter(Type::Number(), 3); 1167 Node* control = graph()->start();
1042 Node* effect = graph()->start(); 1168 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseOr(hints), lhs,
1043 Node* control = graph()->start(); 1169 rhs, UndefinedConstant(),
1044 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseOr(hints), lhs, 1170 EmptyFrameState(), effect, control));
1045 rhs, UndefinedConstant(), 1171 ASSERT_TRUE(r.Changed());
1046 EmptyFrameState(), effect, control)); 1172 EXPECT_THAT(r.replacement(),
1047 ASSERT_TRUE(r.Changed()); 1173 IsSpeculativeNumberBitwiseOr(NumberOperationHint::kSignedSmall,
1048 EXPECT_THAT(r.replacement(), IsSpeculativeNumberBitwiseOr( 1174 lhs, rhs, effect, control));
1049 feedback, lhs, rhs, effect, control)); 1175 }
1050 } 1176
1177 TEST_F(JSTypedLoweringTest, JSBitwiseOrWithSigned32Hint) {
1178 BinaryOperationHints const hints(BinaryOperationHints::kSigned32,
1179 BinaryOperationHints::kSigned32,
1180 BinaryOperationHints::kSigned32);
1181 Node* lhs = Parameter(Type::Number(), 2);
1182 Node* rhs = Parameter(Type::Number(), 3);
1183 Node* effect = graph()->start();
1184 Node* control = graph()->start();
1185 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseOr(hints), lhs,
1186 rhs, UndefinedConstant(),
1187 EmptyFrameState(), effect, control));
1188 ASSERT_TRUE(r.Changed());
1189 EXPECT_THAT(r.replacement(),
1190 IsSpeculativeNumberBitwiseOr(NumberOperationHint::kSigned32, lhs,
1191 rhs, effect, control));
1192 }
1193
1194 TEST_F(JSTypedLoweringTest, JSBitwiseOrWithNumberOrOddballHint) {
1195 BinaryOperationHints const hints(BinaryOperationHints::kNumberOrOddball,
1196 BinaryOperationHints::kNumberOrOddball,
1197 BinaryOperationHints::kNumberOrOddball);
1198 Node* lhs = Parameter(Type::Number(), 2);
1199 Node* rhs = Parameter(Type::Number(), 3);
1200 Node* effect = graph()->start();
1201 Node* control = graph()->start();
1202 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseOr(hints), lhs,
1203 rhs, UndefinedConstant(),
1204 EmptyFrameState(), effect, control));
1205 ASSERT_TRUE(r.Changed());
1206 EXPECT_THAT(r.replacement(), IsSpeculativeNumberBitwiseOr(
1207 NumberOperationHint::kNumberOrOddball, lhs,
1208 rhs, effect, control));
1051 } 1209 }
1052 1210
1053 // ----------------------------------------------------------------------------- 1211 // -----------------------------------------------------------------------------
1054 // JSBitwiseXor 1212 // JSBitwiseXor
1055 1213
1056 TEST_F(JSTypedLoweringTest, JSBitwiseXorWithTypeFeedback) { 1214 TEST_F(JSTypedLoweringTest, JSBitwiseXorWithSignedSmallHint) {
1057 BinaryOperationHints::Hint const feedback_types[] = { 1215 BinaryOperationHints const hints(BinaryOperationHints::kSignedSmall,
1058 BinaryOperationHints::kSignedSmall, 1216 BinaryOperationHints::kSignedSmall,
1059 BinaryOperationHints::kNumberOrOddball}; 1217 BinaryOperationHints::kSignedSmall);
1060 for (BinaryOperationHints::Hint feedback : feedback_types) { 1218 Node* lhs = Parameter(Type::Number(), 2);
1061 BinaryOperationHints const hints(feedback, feedback, feedback); 1219 Node* rhs = Parameter(Type::Number(), 3);
1062 Node* lhs = Parameter(Type::Number(), 2); 1220 Node* effect = graph()->start();
1063 Node* rhs = Parameter(Type::Number(), 3); 1221 Node* control = graph()->start();
1064 Node* effect = graph()->start(); 1222 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseXor(hints), lhs,
1065 Node* control = graph()->start(); 1223 rhs, UndefinedConstant(),
1066 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseXor(hints), lhs, 1224 EmptyFrameState(), effect, control));
1067 rhs, UndefinedConstant(), 1225 ASSERT_TRUE(r.Changed());
1068 EmptyFrameState(), effect, control)); 1226 EXPECT_THAT(r.replacement(),
1069 ASSERT_TRUE(r.Changed()); 1227 IsSpeculativeNumberBitwiseXor(NumberOperationHint::kSignedSmall,
1070 EXPECT_THAT(r.replacement(), IsSpeculativeNumberBitwiseXor( 1228 lhs, rhs, effect, control));
1071 feedback, lhs, rhs, effect, control)); 1229 }
1072 } 1230
1231 TEST_F(JSTypedLoweringTest, JSBitwiseXorWithSigned32Hint) {
1232 BinaryOperationHints const hints(BinaryOperationHints::kSigned32,
1233 BinaryOperationHints::kSigned32,
1234 BinaryOperationHints::kSigned32);
1235 Node* lhs = Parameter(Type::Number(), 2);
1236 Node* rhs = Parameter(Type::Number(), 3);
1237 Node* effect = graph()->start();
1238 Node* control = graph()->start();
1239 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseXor(hints), lhs,
1240 rhs, UndefinedConstant(),
1241 EmptyFrameState(), effect, control));
1242 ASSERT_TRUE(r.Changed());
1243 EXPECT_THAT(r.replacement(),
1244 IsSpeculativeNumberBitwiseXor(NumberOperationHint::kSigned32, lhs,
1245 rhs, effect, control));
1246 }
1247
1248 TEST_F(JSTypedLoweringTest, JSBitwiseXorWithNumberOrOddballHint) {
1249 BinaryOperationHints const hints(BinaryOperationHints::kNumberOrOddball,
1250 BinaryOperationHints::kNumberOrOddball,
1251 BinaryOperationHints::kNumberOrOddball);
1252 Node* lhs = Parameter(Type::Number(), 2);
1253 Node* rhs = Parameter(Type::Number(), 3);
1254 Node* effect = graph()->start();
1255 Node* control = graph()->start();
1256 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseXor(hints), lhs,
1257 rhs, UndefinedConstant(),
1258 EmptyFrameState(), effect, control));
1259 ASSERT_TRUE(r.Changed());
1260 EXPECT_THAT(r.replacement(), IsSpeculativeNumberBitwiseXor(
1261 NumberOperationHint::kNumberOrOddball, lhs,
1262 rhs, effect, control));
1073 } 1263 }
1074 1264
1075 } // namespace compiler 1265 } // namespace compiler
1076 } // namespace internal 1266 } // namespace internal
1077 } // namespace v8 1267 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/simplified-operator.cc ('k') | test/unittests/compiler/node-test-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698