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

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

Issue 1407413014: [turbofan] Pseudo-inline instanceof (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/compiler/test-js-typed-lowering.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/compiler/js-typed-lowering-unittest.cc
diff --git a/test/unittests/compiler/js-typed-lowering-unittest.cc b/test/unittests/compiler/js-typed-lowering-unittest.cc
index 7ef1e81d47da427a1e3e3c025aa0975525e438a1..37dc1f3eb54864bd506a5a6a277f522363712b8f 100644
--- a/test/unittests/compiler/js-typed-lowering-unittest.cc
+++ b/test/unittests/compiler/js-typed-lowering-unittest.cc
@@ -74,7 +74,8 @@ const LanguageMode kLanguageModes[] = {SLOPPY, STRICT, STRONG};
class JSTypedLoweringTest : public TypedGraphTest {
public:
- JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {}
+ JSTypedLoweringTest()
+ : TypedGraphTest(3), javascript_(zone()), deps_(isolate(), zone()) {}
~JSTypedLoweringTest() override {}
protected:
@@ -85,7 +86,9 @@ class JSTypedLoweringTest : public TypedGraphTest {
&machine);
// TODO(titzer): mock the GraphReducer here for better unit testing.
GraphReducer graph_reducer(zone(), graph());
- JSTypedLowering reducer(&graph_reducer, &jsgraph, zone());
+ JSTypedLowering reducer(&graph_reducer, &deps_,
+ JSTypedLowering::kDeoptimizationEnabled, &jsgraph,
+ zone());
return reducer.Reduce(node);
}
@@ -116,6 +119,7 @@ class JSTypedLoweringTest : public TypedGraphTest {
private:
JSOperatorBuilder javascript_;
+ CompilationDependencies deps_;
};
@@ -1168,6 +1172,70 @@ TEST_F(JSTypedLoweringTest, JSCreateWithContext) {
_));
}
+
+// -----------------------------------------------------------------------------
+// JSInstanceOf
+// Test that instanceOf is reduced if and only if the right-hand side is a
+// function constant. Functional correctness is ensured elsewhere.
+
+
+TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithoutSmiCheck) {
+ Node* const context = Parameter(Type::Any());
+ Node* const frame_state = EmptyFrameState();
+ Node* const effect = graph()->start();
+ Node* const control = graph()->start();
+
+ // Reduce if left-hand side is known to be an object.
+ Node* instanceOf =
+ graph()->NewNode(javascript()->InstanceOf(), Parameter(Type::Object(), 0),
+ HeapConstant(isolate()->object_function()), context,
+ frame_state, effect, control);
+ Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context,
+ frame_state, effect, control);
+ Reduction r = Reduce(instanceOf);
+ ASSERT_TRUE(r.Changed());
+ ASSERT_EQ(r.replacement(), dummy->InputAt(0));
+ ASSERT_NE(instanceOf, dummy->InputAt(0));
+}
+
+
+TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithSmiCheck) {
+ Node* const context = Parameter(Type::Any());
+ Node* const frame_state = EmptyFrameState();
+ Node* const effect = graph()->start();
+ Node* const control = graph()->start();
+
+ // Reduce if left-hand side could be a Smi.
+ Node* instanceOf =
+ graph()->NewNode(javascript()->InstanceOf(), Parameter(Type::Any(), 0),
+ HeapConstant(isolate()->object_function()), context,
+ frame_state, effect, control);
+ Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context,
+ frame_state, effect, control);
+ Reduction r = Reduce(instanceOf);
+ ASSERT_TRUE(r.Changed());
+ ASSERT_EQ(r.replacement(), dummy->InputAt(0));
+ ASSERT_NE(instanceOf, dummy->InputAt(0));
+}
+
+
+TEST_F(JSTypedLoweringTest, JSInstanceOfNoSpecialization) {
+ Node* const context = Parameter(Type::Any());
+ Node* const frame_state = EmptyFrameState();
+ Node* const effect = graph()->start();
+ Node* const control = graph()->start();
+
+ // Do not reduce if right-hand side is not a function constant.
+ Node* instanceOf = graph()->NewNode(
+ javascript()->InstanceOf(), Parameter(Type::Any(), 0),
+ Parameter(Type::Any()), context, frame_state, effect, control);
+ Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context,
+ frame_state, effect, control);
+ Reduction r = Reduce(instanceOf);
+ ASSERT_FALSE(r.Changed());
+ ASSERT_EQ(instanceOf, dummy->InputAt(0));
+}
+
} // namespace compiler
} // namespace internal
} // namespace v8
« no previous file with comments | « test/cctest/compiler/test-js-typed-lowering.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698