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

Unified Diff: test/unittests/compiler/simplified-operator-reducer-unittest.cc

Issue 800833003: [turbofan] Correctify JSToBoolean lowering. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Improve simplified lowering. Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/unittests/compiler/node-test-utils.cc ('k') | test/unittests/compiler/simplified-operator-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/compiler/simplified-operator-reducer-unittest.cc
diff --git a/test/unittests/compiler/simplified-operator-reducer-unittest.cc b/test/unittests/compiler/simplified-operator-reducer-unittest.cc
index 18f5e640540a71fd17da8b3e86a0411d5cc5dd4c..e5f46c0d538fd3dd77d5564db0039d6a5d85aec1 100644
--- a/test/unittests/compiler/simplified-operator-reducer-unittest.cc
+++ b/test/unittests/compiler/simplified-operator-reducer-unittest.cc
@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "src/compiler/access-builder.h"
#include "src/compiler/js-graph.h"
+#include "src/compiler/node-properties-inl.h"
#include "src/compiler/simplified-operator.h"
#include "src/compiler/simplified-operator-reducer.h"
#include "src/conversions.h"
@@ -18,10 +20,10 @@ namespace v8 {
namespace internal {
namespace compiler {
-class SimplifiedOperatorReducerTest : public GraphTest {
+class SimplifiedOperatorReducerTest : public TypedGraphTest {
public:
explicit SimplifiedOperatorReducerTest(int num_parameters = 1)
- : GraphTest(num_parameters), simplified_(zone()) {}
+ : TypedGraphTest(num_parameters), simplified_(zone()) {}
~SimplifiedOperatorReducerTest() OVERRIDE {}
protected:
@@ -139,6 +141,7 @@ std::ostream& operator<<(std::ostream& os, const UnaryOperator& unop) {
static const UnaryOperator kUnaryOperators[] = {
+ {&SimplifiedOperatorBuilder::AnyToBoolean, "AnyToBoolean"},
{&SimplifiedOperatorBuilder::BooleanNot, "BooleanNot"},
{&SimplifiedOperatorBuilder::ChangeBitToBool, "ChangeBitToBool"},
{&SimplifiedOperatorBuilder::ChangeBoolToBit, "ChangeBoolToBit"},
@@ -160,8 +163,8 @@ typedef SimplifiedOperatorReducerTestWithParam<UnaryOperator>
TEST_P(SimplifiedUnaryOperatorTest, Parameter) {
const UnaryOperator& unop = GetParam();
- Reduction reduction = Reduce(
- graph()->NewNode((simplified()->*unop.constructor)(), Parameter(0)));
+ Reduction reduction = Reduce(graph()->NewNode(
+ (simplified()->*unop.constructor)(), Parameter(Type::Any())));
EXPECT_FALSE(reduction.Changed());
}
@@ -172,6 +175,39 @@ INSTANTIATE_TEST_CASE_P(SimplifiedOperatorReducerTest,
// -----------------------------------------------------------------------------
+// AnyToBoolean
+
+
+TEST_F(SimplifiedOperatorReducerTest, AnyToBooleanWithBoolean) {
+ Node* p = Parameter(Type::Boolean());
+ Reduction r = Reduce(graph()->NewNode(simplified()->AnyToBoolean(), p));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_EQ(p, r.replacement());
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, AnyToBooleanWithOrderedNumber) {
+ Node* p = Parameter(Type::OrderedNumber());
+ Reduction r = Reduce(graph()->NewNode(simplified()->AnyToBoolean(), p));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsBooleanNot(IsNumberEqual(p, IsNumberConstant(0))));
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, AnyToBooleanWithString) {
+ Node* p = Parameter(Type::String());
+ Reduction r = Reduce(graph()->NewNode(simplified()->AnyToBoolean(), p));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsBooleanNot(
+ IsNumberEqual(IsLoadField(AccessBuilder::ForStringLength(), p,
+ graph()->start(), graph()->start()),
+ IsNumberConstant(0))));
+}
+
+
+// -----------------------------------------------------------------------------
// BooleanNot
« no previous file with comments | « test/unittests/compiler/node-test-utils.cc ('k') | test/unittests/compiler/simplified-operator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698