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

Side by Side 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 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/access-builder.h"
5 #include "src/compiler/js-graph.h" 6 #include "src/compiler/js-graph.h"
7 #include "src/compiler/node-properties-inl.h"
6 #include "src/compiler/simplified-operator.h" 8 #include "src/compiler/simplified-operator.h"
7 #include "src/compiler/simplified-operator-reducer.h" 9 #include "src/compiler/simplified-operator-reducer.h"
8 #include "src/conversions.h" 10 #include "src/conversions.h"
9 #include "src/types.h" 11 #include "src/types.h"
10 #include "test/unittests/compiler/graph-unittest.h" 12 #include "test/unittests/compiler/graph-unittest.h"
11 #include "test/unittests/compiler/node-test-utils.h" 13 #include "test/unittests/compiler/node-test-utils.h"
12 #include "testing/gmock-support.h" 14 #include "testing/gmock-support.h"
13 15
14 using testing::BitEq; 16 using testing::BitEq;
15 17
16 18
17 namespace v8 { 19 namespace v8 {
18 namespace internal { 20 namespace internal {
19 namespace compiler { 21 namespace compiler {
20 22
21 class SimplifiedOperatorReducerTest : public GraphTest { 23 class SimplifiedOperatorReducerTest : public TypedGraphTest {
22 public: 24 public:
23 explicit SimplifiedOperatorReducerTest(int num_parameters = 1) 25 explicit SimplifiedOperatorReducerTest(int num_parameters = 1)
24 : GraphTest(num_parameters), simplified_(zone()) {} 26 : TypedGraphTest(num_parameters), simplified_(zone()) {}
25 ~SimplifiedOperatorReducerTest() OVERRIDE {} 27 ~SimplifiedOperatorReducerTest() OVERRIDE {}
26 28
27 protected: 29 protected:
28 Reduction Reduce(Node* node) { 30 Reduction Reduce(Node* node) {
29 MachineOperatorBuilder machine(zone()); 31 MachineOperatorBuilder machine(zone());
30 JSOperatorBuilder javascript(zone()); 32 JSOperatorBuilder javascript(zone());
31 JSGraph jsgraph(graph(), common(), &javascript, &machine); 33 JSGraph jsgraph(graph(), common(), &javascript, &machine);
32 SimplifiedOperatorReducer reducer(&jsgraph); 34 SimplifiedOperatorReducer reducer(&jsgraph);
33 return reducer.Reduce(node); 35 return reducer.Reduce(node);
34 } 36 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 const char* constructor_name; 134 const char* constructor_name;
133 }; 135 };
134 136
135 137
136 std::ostream& operator<<(std::ostream& os, const UnaryOperator& unop) { 138 std::ostream& operator<<(std::ostream& os, const UnaryOperator& unop) {
137 return os << unop.constructor_name; 139 return os << unop.constructor_name;
138 } 140 }
139 141
140 142
141 static const UnaryOperator kUnaryOperators[] = { 143 static const UnaryOperator kUnaryOperators[] = {
144 {&SimplifiedOperatorBuilder::AnyToBoolean, "AnyToBoolean"},
142 {&SimplifiedOperatorBuilder::BooleanNot, "BooleanNot"}, 145 {&SimplifiedOperatorBuilder::BooleanNot, "BooleanNot"},
143 {&SimplifiedOperatorBuilder::ChangeBitToBool, "ChangeBitToBool"}, 146 {&SimplifiedOperatorBuilder::ChangeBitToBool, "ChangeBitToBool"},
144 {&SimplifiedOperatorBuilder::ChangeBoolToBit, "ChangeBoolToBit"}, 147 {&SimplifiedOperatorBuilder::ChangeBoolToBit, "ChangeBoolToBit"},
145 {&SimplifiedOperatorBuilder::ChangeFloat64ToTagged, 148 {&SimplifiedOperatorBuilder::ChangeFloat64ToTagged,
146 "ChangeFloat64ToTagged"}, 149 "ChangeFloat64ToTagged"},
147 {&SimplifiedOperatorBuilder::ChangeInt32ToTagged, "ChangeInt32ToTagged"}, 150 {&SimplifiedOperatorBuilder::ChangeInt32ToTagged, "ChangeInt32ToTagged"},
148 {&SimplifiedOperatorBuilder::ChangeTaggedToFloat64, 151 {&SimplifiedOperatorBuilder::ChangeTaggedToFloat64,
149 "ChangeTaggedToFloat64"}, 152 "ChangeTaggedToFloat64"},
150 {&SimplifiedOperatorBuilder::ChangeTaggedToInt32, "ChangeTaggedToInt32"}, 153 {&SimplifiedOperatorBuilder::ChangeTaggedToInt32, "ChangeTaggedToInt32"},
151 {&SimplifiedOperatorBuilder::ChangeTaggedToUint32, "ChangeTaggedToUint32"}, 154 {&SimplifiedOperatorBuilder::ChangeTaggedToUint32, "ChangeTaggedToUint32"},
152 {&SimplifiedOperatorBuilder::ChangeUint32ToTagged, "ChangeUint32ToTagged"}}; 155 {&SimplifiedOperatorBuilder::ChangeUint32ToTagged, "ChangeUint32ToTagged"}};
153 156
154 } // namespace 157 } // namespace
155 158
156 159
157 typedef SimplifiedOperatorReducerTestWithParam<UnaryOperator> 160 typedef SimplifiedOperatorReducerTestWithParam<UnaryOperator>
158 SimplifiedUnaryOperatorTest; 161 SimplifiedUnaryOperatorTest;
159 162
160 163
161 TEST_P(SimplifiedUnaryOperatorTest, Parameter) { 164 TEST_P(SimplifiedUnaryOperatorTest, Parameter) {
162 const UnaryOperator& unop = GetParam(); 165 const UnaryOperator& unop = GetParam();
163 Reduction reduction = Reduce( 166 Reduction reduction = Reduce(graph()->NewNode(
164 graph()->NewNode((simplified()->*unop.constructor)(), Parameter(0))); 167 (simplified()->*unop.constructor)(), Parameter(Type::Any())));
165 EXPECT_FALSE(reduction.Changed()); 168 EXPECT_FALSE(reduction.Changed());
166 } 169 }
167 170
168 171
169 INSTANTIATE_TEST_CASE_P(SimplifiedOperatorReducerTest, 172 INSTANTIATE_TEST_CASE_P(SimplifiedOperatorReducerTest,
170 SimplifiedUnaryOperatorTest, 173 SimplifiedUnaryOperatorTest,
171 ::testing::ValuesIn(kUnaryOperators)); 174 ::testing::ValuesIn(kUnaryOperators));
172 175
173 176
174 // ----------------------------------------------------------------------------- 177 // -----------------------------------------------------------------------------
178 // AnyToBoolean
179
180
181 TEST_F(SimplifiedOperatorReducerTest, AnyToBooleanWithBoolean) {
182 Node* p = Parameter(Type::Boolean());
183 Reduction r = Reduce(graph()->NewNode(simplified()->AnyToBoolean(), p));
184 ASSERT_TRUE(r.Changed());
185 EXPECT_EQ(p, r.replacement());
186 }
187
188
189 TEST_F(SimplifiedOperatorReducerTest, AnyToBooleanWithOrderedNumber) {
190 Node* p = Parameter(Type::OrderedNumber());
191 Reduction r = Reduce(graph()->NewNode(simplified()->AnyToBoolean(), p));
192 ASSERT_TRUE(r.Changed());
193 EXPECT_THAT(r.replacement(),
194 IsBooleanNot(IsNumberEqual(p, IsNumberConstant(0))));
195 }
196
197
198 TEST_F(SimplifiedOperatorReducerTest, AnyToBooleanWithString) {
199 Node* p = Parameter(Type::String());
200 Reduction r = Reduce(graph()->NewNode(simplified()->AnyToBoolean(), p));
201 ASSERT_TRUE(r.Changed());
202 EXPECT_THAT(r.replacement(),
203 IsBooleanNot(
204 IsNumberEqual(IsLoadField(AccessBuilder::ForStringLength(), p,
205 graph()->start(), graph()->start()),
206 IsNumberConstant(0))));
207 }
208
209
210 // -----------------------------------------------------------------------------
175 // BooleanNot 211 // BooleanNot
176 212
177 213
178 TEST_F(SimplifiedOperatorReducerTest, BooleanNotWithBooleanNot) { 214 TEST_F(SimplifiedOperatorReducerTest, BooleanNotWithBooleanNot) {
179 Node* param0 = Parameter(0); 215 Node* param0 = Parameter(0);
180 Reduction reduction = Reduce( 216 Reduction reduction = Reduce(
181 graph()->NewNode(simplified()->BooleanNot(), 217 graph()->NewNode(simplified()->BooleanNot(),
182 graph()->NewNode(simplified()->BooleanNot(), param0))); 218 graph()->NewNode(simplified()->BooleanNot(), param0)));
183 ASSERT_TRUE(reduction.Changed()); 219 ASSERT_TRUE(reduction.Changed());
184 EXPECT_EQ(param0, reduction.replacement()); 220 EXPECT_EQ(param0, reduction.replacement());
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 Reduce(graph()->NewNode(simplified()->ChangeUint32ToTagged(), 511 Reduce(graph()->NewNode(simplified()->ChangeUint32ToTagged(),
476 Int32Constant(bit_cast<int32_t>(n)))); 512 Int32Constant(bit_cast<int32_t>(n))));
477 ASSERT_TRUE(reduction.Changed()); 513 ASSERT_TRUE(reduction.Changed());
478 EXPECT_THAT(reduction.replacement(), IsNumberConstant(BitEq(FastUI2D(n)))); 514 EXPECT_THAT(reduction.replacement(), IsNumberConstant(BitEq(FastUI2D(n))));
479 } 515 }
480 } 516 }
481 517
482 } // namespace compiler 518 } // namespace compiler
483 } // namespace internal 519 } // namespace internal
484 } // namespace v8 520 } // namespace v8
OLDNEW
« 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