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

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

Issue 2511223003: [turbofan] Properly optimize instanceof (even in the presence of @@hasInstance). (Closed)
Patch Set: Created 4 years, 1 month 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/compiler/js-typed-lowering.h" 5 #include "src/compiler/js-typed-lowering.h"
6 #include "src/code-factory.h" 6 #include "src/code-factory.h"
7 #include "src/compilation-dependencies.h" 7 #include "src/compilation-dependencies.h"
8 #include "src/compiler/access-builder.h" 8 #include "src/compiler/access-builder.h"
9 #include "src/compiler/js-graph.h" 9 #include "src/compiler/js-graph.h"
10 #include "src/compiler/js-operator.h" 10 #include "src/compiler/js-operator.h"
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 Node* control = graph()->start(); 853 Node* control = graph()->start();
854 Reduction r = Reduce(graph()->NewNode(javascript()->Subtract(hint), lhs, rhs, 854 Reduction r = Reduce(graph()->NewNode(javascript()->Subtract(hint), lhs, rhs,
855 context, frame_state, effect, control)); 855 context, frame_state, effect, control));
856 ASSERT_TRUE(r.Changed()); 856 ASSERT_TRUE(r.Changed());
857 EXPECT_THAT(r.replacement(), 857 EXPECT_THAT(r.replacement(),
858 IsSpeculativeNumberSubtract(NumberOperationHint::kSignedSmall, 858 IsSpeculativeNumberSubtract(NumberOperationHint::kSignedSmall,
859 lhs, rhs, effect, control)); 859 lhs, rhs, effect, control));
860 } 860 }
861 861
862 // ----------------------------------------------------------------------------- 862 // -----------------------------------------------------------------------------
863 // JSInstanceOf
864 // Test that instanceOf is reduced if and only if the right-hand side is a
865 // function constant. Functional correctness is ensured elsewhere.
866
867 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecialization) {
868 Node* const context = Parameter(Type::Any());
869 Node* const frame_state = EmptyFrameState();
870 Node* const effect = graph()->start();
871 Node* const control = graph()->start();
872
873 Node* instanceOf =
874 graph()->NewNode(javascript()->InstanceOf(), Parameter(Type::Any(), 0),
875 HeapConstant(isolate()->object_function()), context,
876 frame_state, effect, control);
877 Reduction r = Reduce(instanceOf);
878 ASSERT_TRUE(r.Changed());
879 }
880
881
882 TEST_F(JSTypedLoweringTest, JSInstanceOfNoSpecialization) {
883 Node* const context = Parameter(Type::Any());
884 Node* const frame_state = EmptyFrameState();
885 Node* const effect = graph()->start();
886 Node* const control = graph()->start();
887
888 // Do not reduce if right-hand side is not a function constant.
889 Node* instanceOf = graph()->NewNode(
890 javascript()->InstanceOf(), Parameter(Type::Any(), 0),
891 Parameter(Type::Any()), context, frame_state, effect, control);
892 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context,
893 frame_state, effect, control);
894 Reduction r = Reduce(instanceOf);
895 ASSERT_FALSE(r.Changed());
896 ASSERT_EQ(instanceOf, dummy->InputAt(0));
897 }
898
899 // -----------------------------------------------------------------------------
900 // JSBitwiseAnd 863 // JSBitwiseAnd
901 864
902 TEST_F(JSTypedLoweringTest, JSBitwiseAndWithSignedSmallHint) { 865 TEST_F(JSTypedLoweringTest, JSBitwiseAndWithSignedSmallHint) {
903 BinaryOperationHint const hint = BinaryOperationHint::kSignedSmall; 866 BinaryOperationHint const hint = BinaryOperationHint::kSignedSmall;
904 Node* lhs = Parameter(Type::Number(), 2); 867 Node* lhs = Parameter(Type::Number(), 2);
905 Node* rhs = Parameter(Type::Number(), 3); 868 Node* rhs = Parameter(Type::Number(), 3);
906 Node* effect = graph()->start(); 869 Node* effect = graph()->start();
907 Node* control = graph()->start(); 870 Node* control = graph()->start();
908 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseAnd(hint), lhs, 871 Reduction r = Reduce(graph()->NewNode(javascript()->BitwiseAnd(hint), lhs,
909 rhs, UndefinedConstant(), 872 rhs, UndefinedConstant(),
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 EmptyFrameState(), effect, control)); 999 EmptyFrameState(), effect, control));
1037 ASSERT_TRUE(r.Changed()); 1000 ASSERT_TRUE(r.Changed());
1038 EXPECT_THAT(r.replacement(), IsSpeculativeNumberBitwiseXor( 1001 EXPECT_THAT(r.replacement(), IsSpeculativeNumberBitwiseXor(
1039 NumberOperationHint::kNumberOrOddball, lhs, 1002 NumberOperationHint::kNumberOrOddball, lhs,
1040 rhs, effect, control)); 1003 rhs, effect, control));
1041 } 1004 }
1042 1005
1043 } // namespace compiler 1006 } // namespace compiler
1044 } // namespace internal 1007 } // namespace internal
1045 } // namespace v8 1008 } // namespace v8
OLDNEW
« src/compiler/js-native-context-specialization.cc ('K') | « test/mjsunit/compiler/instanceof.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698