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

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

Issue 792463003: [turbofan] Turn JSToBoolean and JSUnaryNot into pure operators. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
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 61943b1762ce5a5b05282f19cfedbeffbf0db6ae..2c03d885c6b6c50657e7f09eaa9aa15692ad4a5f 100644
--- a/test/unittests/compiler/js-typed-lowering-unittest.cc
+++ b/test/unittests/compiler/js-typed-lowering-unittest.cc
@@ -78,14 +78,79 @@ class JSTypedLoweringTest : public TypedGraphTest {
// JSToBoolean
+TEST_F(JSTypedLoweringTest, JSToBooleanWithBoolean) {
+ Node* input = Parameter(Type::Boolean());
+ Node* context = UndefinedConstant();
+
+ Reduction r =
+ Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_EQ(input, r.replacement());
+}
+
+
+TEST_F(JSTypedLoweringTest, JSToBooleanWithUndefined) {
+ Node* input = Parameter(Type::Undefined());
+ Node* context = UndefinedConstant();
+
+ Reduction r =
+ Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsFalseConstant());
+}
+
+
+TEST_F(JSTypedLoweringTest, JSToBooleanWithNull) {
+ Node* input = Parameter(Type::Null());
+ Node* context = UndefinedConstant();
+
+ Reduction r =
+ Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsFalseConstant());
+}
+
+
+TEST_F(JSTypedLoweringTest, JSToBooleanWithDetectableReceiver) {
+ Node* input = Parameter(Type::DetectableReceiver());
+ Node* context = UndefinedConstant();
+
+ Reduction r =
+ Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsTrueConstant());
+}
+
+
+TEST_F(JSTypedLoweringTest, JSToBooleanWithUndetectable) {
+ Node* input = Parameter(Type::Undetectable());
+ Node* context = UndefinedConstant();
+
+ Reduction r =
+ Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsFalseConstant());
+}
+
+
+TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumber) {
+ Node* input = Parameter(Type::OrderedNumber());
+ Node* context = UndefinedConstant();
+
+ Reduction r =
+ Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsBooleanNot(IsNumberEqual(input, IsNumberConstant(0))));
+}
+
+
TEST_F(JSTypedLoweringTest, JSToBooleanWithString) {
Node* input = Parameter(Type::String());
Node* context = UndefinedConstant();
- Node* effect = graph()->start();
- Node* control = graph()->start();
- Reduction r = Reduce(graph()->NewNode(javascript()->ToBoolean(), input,
- context, effect, control));
+ Reduction r =
+ Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(),
IsBooleanNot(IsNumberEqual(
@@ -95,17 +160,16 @@ TEST_F(JSTypedLoweringTest, JSToBooleanWithString) {
}
-TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumberAndBoolean) {
+TEST_F(JSTypedLoweringTest, JSToBooleanWithPhi) {
Node* p0 = Parameter(Type::OrderedNumber(), 0);
Node* p1 = Parameter(Type::Boolean(), 1);
Node* context = UndefinedConstant();
- Node* effect = graph()->start();
Node* control = graph()->start();
Reduction r = Reduce(graph()->NewNode(
javascript()->ToBoolean(),
graph()->NewNode(common()->Phi(kMachAnyTagged, 2), p0, p1, control),
- context, effect, control));
+ context));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(
r.replacement(),
@@ -114,6 +178,24 @@ TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumberAndBoolean) {
}
+TEST_F(JSTypedLoweringTest, JSToBooleanWithSelect) {
+ Node* p0 = Parameter(Type::Boolean(), 0);
+ Node* p1 = Parameter(Type::DetectableReceiver(), 1);
+ Node* p2 = Parameter(Type::OrderedNumber(), 2);
+ Node* context = UndefinedConstant();
+
+ Reduction r = Reduce(graph()->NewNode(
+ javascript()->ToBoolean(),
+ graph()->NewNode(common()->Select(kMachAnyTagged, BranchHint::kTrue), p0,
+ p1, p2),
+ context));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsSelect(kMachAnyTagged, p0, IsTrueConstant(),
+ IsBooleanNot(IsNumberEqual(p2, IsNumberConstant(0)))));
+}
+
+
// -----------------------------------------------------------------------------
// JSStrictEqual
« src/compiler/js-typed-lowering.h ('K') | « test/unittests/compiler/js-operator-unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698