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

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

Issue 1487973002: [turbofan] Add binary operation hints for javascript operators. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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
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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 ASSERT_TRUE(r.Changed()); 515 ASSERT_TRUE(r.Changed());
516 EXPECT_THAT(r.replacement(), IsReferenceEqual(Type::Unique(), lhs, rhs)); 516 EXPECT_THAT(r.replacement(), IsReferenceEqual(Type::Unique(), lhs, rhs));
517 } 517 }
518 518
519 519
520 // ----------------------------------------------------------------------------- 520 // -----------------------------------------------------------------------------
521 // JSShiftLeft 521 // JSShiftLeft
522 522
523 523
524 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndConstant) { 524 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndConstant) {
525 BinaryOperationHints const hints = BinaryOperationHints::Any();
525 Node* const lhs = Parameter(Type::Signed32()); 526 Node* const lhs = Parameter(Type::Signed32());
526 Node* const context = UndefinedConstant(); 527 Node* const context = UndefinedConstant();
527 Node* const effect = graph()->start(); 528 Node* const effect = graph()->start();
528 Node* const control = graph()->start(); 529 Node* const control = graph()->start();
529 TRACED_FORRANGE(double, rhs, 0, 31) { 530 TRACED_FORRANGE(double, rhs, 0, 31) {
530 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { 531 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) {
531 Reduction r = Reduce(graph()->NewNode( 532 Reduction r = Reduce(
532 javascript()->ShiftLeft(language_mode), lhs, NumberConstant(rhs), 533 graph()->NewNode(javascript()->ShiftLeft(language_mode, hints), lhs,
533 context, EmptyFrameState(), EmptyFrameState(), effect, control)); 534 NumberConstant(rhs), context, EmptyFrameState(),
535 EmptyFrameState(), effect, control));
534 ASSERT_TRUE(r.Changed()); 536 ASSERT_TRUE(r.Changed());
535 EXPECT_THAT(r.replacement(), 537 EXPECT_THAT(r.replacement(),
536 IsNumberShiftLeft(lhs, IsNumberConstant(BitEq(rhs)))); 538 IsNumberShiftLeft(lhs, IsNumberConstant(BitEq(rhs))));
537 } 539 }
538 } 540 }
539 } 541 }
540 542
541 543
542 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndUnsigned32) { 544 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndUnsigned32) {
545 BinaryOperationHints const hints = BinaryOperationHints::Any();
543 Node* const lhs = Parameter(Type::Signed32()); 546 Node* const lhs = Parameter(Type::Signed32());
544 Node* const rhs = Parameter(Type::Unsigned32()); 547 Node* const rhs = Parameter(Type::Unsigned32());
545 Node* const context = UndefinedConstant(); 548 Node* const context = UndefinedConstant();
546 Node* const effect = graph()->start(); 549 Node* const effect = graph()->start();
547 Node* const control = graph()->start(); 550 Node* const control = graph()->start();
548 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { 551 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) {
549 Reduction r = Reduce(graph()->NewNode( 552 Reduction r = Reduce(graph()->NewNode(
550 javascript()->ShiftLeft(language_mode), lhs, rhs, context, 553 javascript()->ShiftLeft(language_mode, hints), lhs, rhs, context,
551 EmptyFrameState(), EmptyFrameState(), effect, control)); 554 EmptyFrameState(), EmptyFrameState(), effect, control));
552 ASSERT_TRUE(r.Changed()); 555 ASSERT_TRUE(r.Changed());
553 EXPECT_THAT(r.replacement(), IsNumberShiftLeft(lhs, rhs)); 556 EXPECT_THAT(r.replacement(), IsNumberShiftLeft(lhs, rhs));
554 } 557 }
555 } 558 }
556 559
557 560
558 // ----------------------------------------------------------------------------- 561 // -----------------------------------------------------------------------------
559 // JSShiftRight 562 // JSShiftRight
560 563
561 564
562 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndConstant) { 565 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndConstant) {
566 BinaryOperationHints const hints = BinaryOperationHints::Any();
563 Node* const lhs = Parameter(Type::Signed32()); 567 Node* const lhs = Parameter(Type::Signed32());
564 Node* const context = UndefinedConstant(); 568 Node* const context = UndefinedConstant();
565 Node* const effect = graph()->start(); 569 Node* const effect = graph()->start();
566 Node* const control = graph()->start(); 570 Node* const control = graph()->start();
567 TRACED_FORRANGE(double, rhs, 0, 31) { 571 TRACED_FORRANGE(double, rhs, 0, 31) {
568 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { 572 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) {
569 Reduction r = Reduce(graph()->NewNode( 573 Reduction r = Reduce(
570 javascript()->ShiftRight(language_mode), lhs, NumberConstant(rhs), 574 graph()->NewNode(javascript()->ShiftRight(language_mode, hints), lhs,
571 context, EmptyFrameState(), EmptyFrameState(), effect, control)); 575 NumberConstant(rhs), context, EmptyFrameState(),
576 EmptyFrameState(), effect, control));
572 ASSERT_TRUE(r.Changed()); 577 ASSERT_TRUE(r.Changed());
573 EXPECT_THAT(r.replacement(), 578 EXPECT_THAT(r.replacement(),
574 IsNumberShiftRight(lhs, IsNumberConstant(BitEq(rhs)))); 579 IsNumberShiftRight(lhs, IsNumberConstant(BitEq(rhs))));
575 } 580 }
576 } 581 }
577 } 582 }
578 583
579 584
580 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndUnsigned32) { 585 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndUnsigned32) {
586 BinaryOperationHints const hints = BinaryOperationHints::Any();
581 Node* const lhs = Parameter(Type::Signed32()); 587 Node* const lhs = Parameter(Type::Signed32());
582 Node* const rhs = Parameter(Type::Unsigned32()); 588 Node* const rhs = Parameter(Type::Unsigned32());
583 Node* const context = UndefinedConstant(); 589 Node* const context = UndefinedConstant();
584 Node* const effect = graph()->start(); 590 Node* const effect = graph()->start();
585 Node* const control = graph()->start(); 591 Node* const control = graph()->start();
586 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { 592 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) {
587 Reduction r = Reduce(graph()->NewNode( 593 Reduction r = Reduce(graph()->NewNode(
588 javascript()->ShiftRight(language_mode), lhs, rhs, context, 594 javascript()->ShiftRight(language_mode, hints), lhs, rhs, context,
589 EmptyFrameState(), EmptyFrameState(), effect, control)); 595 EmptyFrameState(), EmptyFrameState(), effect, control));
590 ASSERT_TRUE(r.Changed()); 596 ASSERT_TRUE(r.Changed());
591 EXPECT_THAT(r.replacement(), IsNumberShiftRight(lhs, rhs)); 597 EXPECT_THAT(r.replacement(), IsNumberShiftRight(lhs, rhs));
592 } 598 }
593 } 599 }
594 600
595 601
596 // ----------------------------------------------------------------------------- 602 // -----------------------------------------------------------------------------
597 // JSShiftRightLogical 603 // JSShiftRightLogical
598 604
599 605
600 TEST_F(JSTypedLoweringTest, 606 TEST_F(JSTypedLoweringTest,
601 JSShiftRightLogicalWithUnsigned32AndConstant) { 607 JSShiftRightLogicalWithUnsigned32AndConstant) {
608 BinaryOperationHints const hints = BinaryOperationHints::Any();
602 Node* const lhs = Parameter(Type::Unsigned32()); 609 Node* const lhs = Parameter(Type::Unsigned32());
603 Node* const context = UndefinedConstant(); 610 Node* const context = UndefinedConstant();
604 Node* const effect = graph()->start(); 611 Node* const effect = graph()->start();
605 Node* const control = graph()->start(); 612 Node* const control = graph()->start();
606 TRACED_FORRANGE(double, rhs, 0, 31) { 613 TRACED_FORRANGE(double, rhs, 0, 31) {
607 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { 614 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) {
608 Reduction r = Reduce( 615 Reduction r = Reduce(graph()->NewNode(
609 graph()->NewNode(javascript()->ShiftRightLogical(language_mode), lhs, 616 javascript()->ShiftRightLogical(language_mode, hints), lhs,
610 NumberConstant(rhs), context, EmptyFrameState(), 617 NumberConstant(rhs), context, EmptyFrameState(), EmptyFrameState(),
611 EmptyFrameState(), effect, control)); 618 effect, control));
612 ASSERT_TRUE(r.Changed()); 619 ASSERT_TRUE(r.Changed());
613 EXPECT_THAT(r.replacement(), 620 EXPECT_THAT(r.replacement(),
614 IsNumberShiftRightLogical(lhs, IsNumberConstant(BitEq(rhs)))); 621 IsNumberShiftRightLogical(lhs, IsNumberConstant(BitEq(rhs))));
615 } 622 }
616 } 623 }
617 } 624 }
618 625
619 626
620 TEST_F(JSTypedLoweringTest, 627 TEST_F(JSTypedLoweringTest, JSShiftRightLogicalWithUnsigned32AndUnsigned32) {
621 JSShiftRightLogicalWithUnsigned32AndUnsigned32) { 628 BinaryOperationHints const hints = BinaryOperationHints::Any();
622 Node* const lhs = Parameter(Type::Unsigned32()); 629 Node* const lhs = Parameter(Type::Unsigned32());
623 Node* const rhs = Parameter(Type::Unsigned32()); 630 Node* const rhs = Parameter(Type::Unsigned32());
624 Node* const context = UndefinedConstant(); 631 Node* const context = UndefinedConstant();
625 Node* const effect = graph()->start(); 632 Node* const effect = graph()->start();
626 Node* const control = graph()->start(); 633 Node* const control = graph()->start();
627 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { 634 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) {
628 Reduction r = Reduce(graph()->NewNode( 635 Reduction r = Reduce(graph()->NewNode(
629 javascript()->ShiftRightLogical(language_mode), lhs, rhs, context, 636 javascript()->ShiftRightLogical(language_mode, hints), lhs, rhs,
630 EmptyFrameState(), EmptyFrameState(), effect, control)); 637 context, EmptyFrameState(), EmptyFrameState(), effect, control));
631 ASSERT_TRUE(r.Changed()); 638 ASSERT_TRUE(r.Changed());
632 EXPECT_THAT(r.replacement(), IsNumberShiftRightLogical(lhs, rhs)); 639 EXPECT_THAT(r.replacement(), IsNumberShiftRightLogical(lhs, rhs));
633 } 640 }
634 } 641 }
635 642
636 643
637 // ----------------------------------------------------------------------------- 644 // -----------------------------------------------------------------------------
638 // JSLoadContext 645 // JSLoadContext
639 646
640 647
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 EXPECT_THAT(r.replacement(), IsHeapConstant(function_prototype)); 978 EXPECT_THAT(r.replacement(), IsHeapConstant(function_prototype));
972 } 979 }
973 } 980 }
974 981
975 982
976 // ----------------------------------------------------------------------------- 983 // -----------------------------------------------------------------------------
977 // JSAdd 984 // JSAdd
978 985
979 986
980 TEST_F(JSTypedLoweringTest, JSAddWithString) { 987 TEST_F(JSTypedLoweringTest, JSAddWithString) {
988 BinaryOperationHints const hints = BinaryOperationHints::Any();
981 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { 989 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) {
982 Node* lhs = Parameter(Type::String(), 0); 990 Node* lhs = Parameter(Type::String(), 0);
983 Node* rhs = Parameter(Type::String(), 1); 991 Node* rhs = Parameter(Type::String(), 1);
984 Node* context = Parameter(Type::Any(), 2); 992 Node* context = Parameter(Type::Any(), 2);
985 Node* frame_state0 = EmptyFrameState(); 993 Node* frame_state0 = EmptyFrameState();
986 Node* frame_state1 = EmptyFrameState(); 994 Node* frame_state1 = EmptyFrameState();
987 Node* effect = graph()->start(); 995 Node* effect = graph()->start();
988 Node* control = graph()->start(); 996 Node* control = graph()->start();
989 Reduction r = Reduce(graph()->NewNode(javascript()->Add(language_mode), lhs, 997 Reduction r = Reduce(
990 rhs, context, frame_state0, 998 graph()->NewNode(javascript()->Add(language_mode, hints), lhs, rhs,
991 frame_state1, effect, control)); 999 context, frame_state0, frame_state1, effect, control));
992 ASSERT_TRUE(r.Changed()); 1000 ASSERT_TRUE(r.Changed());
993 EXPECT_THAT(r.replacement(), 1001 EXPECT_THAT(r.replacement(),
994 IsCall(_, IsHeapConstant(CodeFactory::StringAdd( 1002 IsCall(_, IsHeapConstant(CodeFactory::StringAdd(
995 isolate(), STRING_ADD_CHECK_NONE, 1003 isolate(), STRING_ADD_CHECK_NONE,
996 NOT_TENURED).code()), 1004 NOT_TENURED).code()),
997 lhs, rhs, context, frame_state0, effect, control)); 1005 lhs, rhs, context, frame_state0, effect, control));
998 } 1006 }
999 } 1007 }
1000 1008
1001 1009
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, 1291 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context,
1284 frame_state, effect, control); 1292 frame_state, effect, control);
1285 Reduction r = Reduce(instanceOf); 1293 Reduction r = Reduce(instanceOf);
1286 ASSERT_FALSE(r.Changed()); 1294 ASSERT_FALSE(r.Changed());
1287 ASSERT_EQ(instanceOf, dummy->InputAt(0)); 1295 ASSERT_EQ(instanceOf, dummy->InputAt(0));
1288 } 1296 }
1289 1297
1290 } // namespace compiler 1298 } // namespace compiler
1291 } // namespace internal 1299 } // namespace internal
1292 } // namespace v8 1300 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698