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

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

Issue 1494973002: [turbofan] Introduce ToBooleanHints on ToBoolean operators. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « test/unittests/compiler/js-operator-unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/code-factory.h" 5 #include "src/code-factory.h"
6 #include "src/compiler/access-builder.h" 6 #include "src/compiler/access-builder.h"
7 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/js-operator.h" 8 #include "src/compiler/js-operator.h"
9 #include "src/compiler/js-typed-lowering.h" 9 #include "src/compiler/js-typed-lowering.h"
10 #include "src/compiler/machine-operator.h" 10 #include "src/compiler/machine-operator.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 217 }
218 218
219 219
220 // ----------------------------------------------------------------------------- 220 // -----------------------------------------------------------------------------
221 // JSToBoolean 221 // JSToBoolean
222 222
223 223
224 TEST_F(JSTypedLoweringTest, JSToBooleanWithBoolean) { 224 TEST_F(JSTypedLoweringTest, JSToBooleanWithBoolean) {
225 Node* input = Parameter(Type::Boolean(), 0); 225 Node* input = Parameter(Type::Boolean(), 0);
226 Node* context = Parameter(Type::Any(), 1); 226 Node* context = Parameter(Type::Any(), 1);
227 Reduction r = Reduce(graph()->NewNode(javascript()->ToBoolean(), input, 227 Reduction r =
228 context, graph()->start())); 228 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny),
229 input, context, graph()->start()));
229 ASSERT_TRUE(r.Changed()); 230 ASSERT_TRUE(r.Changed());
230 EXPECT_EQ(input, r.replacement()); 231 EXPECT_EQ(input, r.replacement());
231 } 232 }
232 233
233 234
234 TEST_F(JSTypedLoweringTest, JSToBooleanWithFalsish) { 235 TEST_F(JSTypedLoweringTest, JSToBooleanWithFalsish) {
235 Node* input = Parameter( 236 Node* input = Parameter(
236 Type::Union( 237 Type::Union(
237 Type::MinusZero(), 238 Type::MinusZero(),
238 Type::Union( 239 Type::Union(
239 Type::NaN(), 240 Type::NaN(),
240 Type::Union( 241 Type::Union(
241 Type::Null(), 242 Type::Null(),
242 Type::Union( 243 Type::Union(
243 Type::Undefined(), 244 Type::Undefined(),
244 Type::Union( 245 Type::Union(
245 Type::Undetectable(), 246 Type::Undetectable(),
246 Type::Union( 247 Type::Union(
247 Type::Constant(factory()->false_value(), zone()), 248 Type::Constant(factory()->false_value(), zone()),
248 Type::Range(0.0, 0.0, zone()), zone()), 249 Type::Range(0.0, 0.0, zone()), zone()),
249 zone()), 250 zone()),
250 zone()), 251 zone()),
251 zone()), 252 zone()),
252 zone()), 253 zone()),
253 zone()), 254 zone()),
254 0); 255 0);
255 Node* context = Parameter(Type::Any(), 1); 256 Node* context = Parameter(Type::Any(), 1);
256 Reduction r = Reduce(graph()->NewNode(javascript()->ToBoolean(), input, 257 Reduction r =
257 context, graph()->start())); 258 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny),
259 input, context, graph()->start()));
258 ASSERT_TRUE(r.Changed()); 260 ASSERT_TRUE(r.Changed());
259 EXPECT_THAT(r.replacement(), IsFalseConstant()); 261 EXPECT_THAT(r.replacement(), IsFalseConstant());
260 } 262 }
261 263
262 264
263 TEST_F(JSTypedLoweringTest, JSToBooleanWithTruish) { 265 TEST_F(JSTypedLoweringTest, JSToBooleanWithTruish) {
264 Node* input = Parameter( 266 Node* input = Parameter(
265 Type::Union( 267 Type::Union(
266 Type::Constant(factory()->true_value(), zone()), 268 Type::Constant(factory()->true_value(), zone()),
267 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone()), 269 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone()),
268 zone()), 270 zone()),
269 0); 271 0);
270 Node* context = Parameter(Type::Any(), 1); 272 Node* context = Parameter(Type::Any(), 1);
271 Reduction r = Reduce(graph()->NewNode(javascript()->ToBoolean(), input, 273 Reduction r =
272 context, graph()->start())); 274 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny),
275 input, context, graph()->start()));
273 ASSERT_TRUE(r.Changed()); 276 ASSERT_TRUE(r.Changed());
274 EXPECT_THAT(r.replacement(), IsTrueConstant()); 277 EXPECT_THAT(r.replacement(), IsTrueConstant());
275 } 278 }
276 279
277 280
278 TEST_F(JSTypedLoweringTest, JSToBooleanWithNonZeroPlainNumber) { 281 TEST_F(JSTypedLoweringTest, JSToBooleanWithNonZeroPlainNumber) {
279 Node* input = Parameter(Type::Range(1, V8_INFINITY, zone()), 0); 282 Node* input = Parameter(Type::Range(1, V8_INFINITY, zone()), 0);
280 Node* context = Parameter(Type::Any(), 1); 283 Node* context = Parameter(Type::Any(), 1);
281 Reduction r = Reduce(graph()->NewNode(javascript()->ToBoolean(), input, 284 Reduction r =
282 context, graph()->start())); 285 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny),
286 input, context, graph()->start()));
283 ASSERT_TRUE(r.Changed()); 287 ASSERT_TRUE(r.Changed());
284 EXPECT_THAT(r.replacement(), IsTrueConstant()); 288 EXPECT_THAT(r.replacement(), IsTrueConstant());
285 } 289 }
286 290
287 291
288 TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumber) { 292 TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumber) {
289 Node* input = Parameter(Type::OrderedNumber(), 0); 293 Node* input = Parameter(Type::OrderedNumber(), 0);
290 Node* context = Parameter(Type::Any(), 1); 294 Node* context = Parameter(Type::Any(), 1);
291 Reduction r = Reduce(graph()->NewNode(javascript()->ToBoolean(), input, 295 Reduction r =
292 context, graph()->start())); 296 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny),
297 input, context, graph()->start()));
293 ASSERT_TRUE(r.Changed()); 298 ASSERT_TRUE(r.Changed());
294 EXPECT_THAT(r.replacement(), 299 EXPECT_THAT(r.replacement(),
295 IsBooleanNot(IsNumberEqual(input, IsNumberConstant(0.0)))); 300 IsBooleanNot(IsNumberEqual(input, IsNumberConstant(0.0))));
296 } 301 }
297 302
298 303
299 TEST_F(JSTypedLoweringTest, JSToBooleanWithString) { 304 TEST_F(JSTypedLoweringTest, JSToBooleanWithString) {
300 Node* input = Parameter(Type::String(), 0); 305 Node* input = Parameter(Type::String(), 0);
301 Node* context = Parameter(Type::Any(), 1); 306 Node* context = Parameter(Type::Any(), 1);
302 Reduction r = Reduce(graph()->NewNode(javascript()->ToBoolean(), input, 307 Reduction r =
303 context, graph()->start())); 308 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny),
309 input, context, graph()->start()));
304 ASSERT_TRUE(r.Changed()); 310 ASSERT_TRUE(r.Changed());
305 EXPECT_THAT( 311 EXPECT_THAT(
306 r.replacement(), 312 r.replacement(),
307 IsNumberLessThan(IsNumberConstant(0.0), 313 IsNumberLessThan(IsNumberConstant(0.0),
308 IsLoadField(AccessBuilder::ForStringLength(), input, 314 IsLoadField(AccessBuilder::ForStringLength(), input,
309 graph()->start(), graph()->start()))); 315 graph()->start(), graph()->start())));
310 } 316 }
311 317
312 318
313 TEST_F(JSTypedLoweringTest, JSToBooleanWithAny) { 319 TEST_F(JSTypedLoweringTest, JSToBooleanWithAny) {
314 Node* input = Parameter(Type::Any(), 0); 320 Node* input = Parameter(Type::Any(), 0);
315 Node* context = Parameter(Type::Any(), 1); 321 Node* context = Parameter(Type::Any(), 1);
316 Reduction r = Reduce(graph()->NewNode(javascript()->ToBoolean(), input, 322 Reduction r =
317 context, graph()->start())); 323 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny),
324 input, context, graph()->start()));
318 ASSERT_FALSE(r.Changed()); 325 ASSERT_FALSE(r.Changed());
319 } 326 }
320 327
321 328
322 // ----------------------------------------------------------------------------- 329 // -----------------------------------------------------------------------------
323 // JSToNumber 330 // JSToNumber
324 331
325 332
326 TEST_F(JSTypedLoweringTest, JSToNumberWithPlainPrimitive) { 333 TEST_F(JSTypedLoweringTest, JSToNumberWithPlainPrimitive) {
327 Node* const input = Parameter(Type::PlainPrimitive(), 0); 334 Node* const input = Parameter(Type::PlainPrimitive(), 0);
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, 1198 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context,
1192 frame_state, effect, control); 1199 frame_state, effect, control);
1193 Reduction r = Reduce(instanceOf); 1200 Reduction r = Reduce(instanceOf);
1194 ASSERT_FALSE(r.Changed()); 1201 ASSERT_FALSE(r.Changed());
1195 ASSERT_EQ(instanceOf, dummy->InputAt(0)); 1202 ASSERT_EQ(instanceOf, dummy->InputAt(0));
1196 } 1203 }
1197 1204
1198 } // namespace compiler 1205 } // namespace compiler
1199 } // namespace internal 1206 } // namespace internal
1200 } // namespace v8 1207 } // namespace v8
OLDNEW
« no previous file with comments | « 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