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

Side by Side Diff: test/unittests/compiler/machine-operator-reducer-unittest.cc

Issue 1919513002: [turbofan] Introduce TruncateTaggedToWord32 simplified operator. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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/base/bits.h" 5 #include "src/base/bits.h"
6 #include "src/base/division-by-constant.h" 6 #include "src/base/division-by-constant.h"
7 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/machine-operator-reducer.h" 8 #include "src/compiler/machine-operator-reducer.h"
9 #include "src/compiler/typer.h" 9 #include "src/compiler/typer.h"
10 #include "src/conversions-inl.h" 10 #include "src/conversions-inl.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf, 229 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf,
230 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344, 230 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344,
231 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c, 231 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c,
232 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00, 232 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00,
233 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000, 233 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000,
234 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff, 234 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff,
235 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff, 235 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff,
236 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff}; 236 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff};
237 237
238 238
239 const TruncationMode kTruncationModes[] = {TruncationMode::kJavaScript,
240 TruncationMode::kRoundToZero};
241
242
243 struct ComparisonBinaryOperator { 239 struct ComparisonBinaryOperator {
244 const Operator* (MachineOperatorBuilder::*constructor)(); 240 const Operator* (MachineOperatorBuilder::*constructor)();
245 const char* constructor_name; 241 const char* constructor_name;
246 }; 242 };
247 243
248 244
249 std::ostream& operator<<(std::ostream& os, 245 std::ostream& operator<<(std::ostream& os,
250 ComparisonBinaryOperator const& cbop) { 246 ComparisonBinaryOperator const& cbop) {
251 return os << cbop.constructor_name; 247 return os << cbop.constructor_name;
252 } 248 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 Reduction reduction = Reduce(graph()->NewNode( 402 Reduction reduction = Reduce(graph()->NewNode(
407 machine()->TruncateFloat64ToFloat32(), Float64Constant(x))); 403 machine()->TruncateFloat64ToFloat32(), Float64Constant(x)));
408 ASSERT_TRUE(reduction.Changed()); 404 ASSERT_TRUE(reduction.Changed());
409 EXPECT_THAT(reduction.replacement(), 405 EXPECT_THAT(reduction.replacement(),
410 IsFloat32Constant(BitEq(DoubleToFloat32(x)))); 406 IsFloat32Constant(BitEq(DoubleToFloat32(x))));
411 } 407 }
412 } 408 }
413 409
414 410
415 // ----------------------------------------------------------------------------- 411 // -----------------------------------------------------------------------------
416 // TruncateFloat64ToInt32 412 // TruncateFloat64ToWord32
417
418 413
419 TEST_F(MachineOperatorReducerTest, 414 TEST_F(MachineOperatorReducerTest,
420 TruncateFloat64ToInt32WithChangeInt32ToFloat64) { 415 TruncateFloat64ToWord32WithChangeInt32ToFloat64) {
421 TRACED_FOREACH(TruncationMode, mode, kTruncationModes) { 416 Node* value = Parameter(0);
422 Node* value = Parameter(0); 417 Reduction reduction = Reduce(graph()->NewNode(
423 Reduction reduction = Reduce(graph()->NewNode( 418 machine()->TruncateFloat64ToWord32(),
424 machine()->TruncateFloat64ToInt32(mode), 419 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value)));
425 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value))); 420 ASSERT_TRUE(reduction.Changed());
426 ASSERT_TRUE(reduction.Changed()); 421 EXPECT_EQ(value, reduction.replacement());
427 EXPECT_EQ(value, reduction.replacement());
428 }
429 } 422 }
430 423
431 424 TEST_F(MachineOperatorReducerTest, TruncateFloat64ToWord32WithConstant) {
432 TEST_F(MachineOperatorReducerTest, TruncateFloat64ToInt32WithConstant) {
433 TRACED_FOREACH(double, x, kFloat64Values) { 425 TRACED_FOREACH(double, x, kFloat64Values) {
434 Reduction reduction = Reduce(graph()->NewNode( 426 Reduction reduction = Reduce(graph()->NewNode(
435 machine()->TruncateFloat64ToInt32(TruncationMode::kJavaScript), 427 machine()->TruncateFloat64ToWord32(), Float64Constant(x)));
436 Float64Constant(x)));
437 ASSERT_TRUE(reduction.Changed()); 428 ASSERT_TRUE(reduction.Changed());
438 EXPECT_THAT(reduction.replacement(), IsInt32Constant(DoubleToInt32(x))); 429 EXPECT_THAT(reduction.replacement(), IsInt32Constant(DoubleToInt32(x)));
439 } 430 }
440 } 431 }
441 432
442 433
443 TEST_F(MachineOperatorReducerTest, TruncateFloat64ToInt32WithPhi) {
444 Node* const p0 = Parameter(0);
445 Node* const p1 = Parameter(1);
446 Node* const merge = graph()->start();
447 TRACED_FOREACH(TruncationMode, mode, kTruncationModes) {
448 Reduction reduction = Reduce(graph()->NewNode(
449 machine()->TruncateFloat64ToInt32(mode),
450 graph()->NewNode(common()->Phi(MachineRepresentation::kFloat64, 2), p0,
451 p1, merge)));
452 ASSERT_TRUE(reduction.Changed());
453 EXPECT_THAT(
454 reduction.replacement(),
455 IsPhi(MachineRepresentation::kWord32, IsTruncateFloat64ToInt32(p0),
456 IsTruncateFloat64ToInt32(p1), merge));
457 }
458 }
459
460
461 // ----------------------------------------------------------------------------- 434 // -----------------------------------------------------------------------------
462 // TruncateInt64ToInt32 435 // TruncateInt64ToInt32
463 436
464 437
465 TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithChangeInt32ToInt64) { 438 TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithChangeInt32ToInt64) {
466 Node* value = Parameter(0); 439 Node* value = Parameter(0);
467 Reduction reduction = Reduce(graph()->NewNode( 440 Reduction reduction = Reduce(graph()->NewNode(
468 machine()->TruncateInt64ToInt32(), 441 machine()->TruncateInt64ToInt32(),
469 graph()->NewNode(machine()->ChangeInt32ToInt64(), value))); 442 graph()->NewNode(machine()->ChangeInt32ToInt64(), value)));
470 ASSERT_TRUE(reduction.Changed()); 443 ASSERT_TRUE(reduction.Changed());
471 EXPECT_EQ(value, reduction.replacement()); 444 EXPECT_EQ(value, reduction.replacement());
472 } 445 }
473 446
474 447
475 TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithConstant) { 448 TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithConstant) {
476 TRACED_FOREACH(int64_t, x, kInt64Values) { 449 TRACED_FOREACH(int64_t, x, kInt64Values) {
477 Reduction reduction = Reduce( 450 Reduction reduction = Reduce(
478 graph()->NewNode(machine()->TruncateInt64ToInt32(), Int64Constant(x))); 451 graph()->NewNode(machine()->TruncateInt64ToInt32(), Int64Constant(x)));
479 ASSERT_TRUE(reduction.Changed()); 452 ASSERT_TRUE(reduction.Changed());
480 EXPECT_THAT(reduction.replacement(), 453 EXPECT_THAT(reduction.replacement(),
481 IsInt32Constant(bit_cast<int32_t>( 454 IsInt32Constant(bit_cast<int32_t>(
482 static_cast<uint32_t>(bit_cast<uint64_t>(x))))); 455 static_cast<uint32_t>(bit_cast<uint64_t>(x)))));
483 } 456 }
484 } 457 }
485 458
486 459
487 // ----------------------------------------------------------------------------- 460 // -----------------------------------------------------------------------------
461 // RoundFloat64ToInt32
462
463 TEST_F(MachineOperatorReducerTest,
464 RoundFloat64ToInt32WithChangeInt32ToFloat64) {
465 Node* value = Parameter(0);
466 Reduction reduction = Reduce(graph()->NewNode(
467 machine()->RoundFloat64ToInt32(),
468 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value)));
469 ASSERT_TRUE(reduction.Changed());
470 EXPECT_EQ(value, reduction.replacement());
471 }
472
473 TEST_F(MachineOperatorReducerTest, RoundFloat64ToInt32WithConstant) {
474 TRACED_FOREACH(double, x, kFloat64Values) {
475 Reduction reduction = Reduce(
476 graph()->NewNode(machine()->RoundFloat64ToInt32(), Float64Constant(x)));
477 ASSERT_TRUE(reduction.Changed());
478 EXPECT_THAT(reduction.replacement(),
479 IsInt32Constant(static_cast<int32_t>(x)));
480 }
481 }
482
483 // -----------------------------------------------------------------------------
488 // Word32And 484 // Word32And
489 485
490
491 TEST_F(MachineOperatorReducerTest, Word32AndWithWord32ShlWithConstant) { 486 TEST_F(MachineOperatorReducerTest, Word32AndWithWord32ShlWithConstant) {
492 Node* const p0 = Parameter(0); 487 Node* const p0 = Parameter(0);
493 488
494 TRACED_FORRANGE(int32_t, l, 1, 31) { 489 TRACED_FORRANGE(int32_t, l, 1, 31) {
495 TRACED_FORRANGE(int32_t, k, 1, l) { 490 TRACED_FORRANGE(int32_t, k, 1, l) {
496 // (x << L) & (-1 << K) => x << L 491 // (x << L) & (-1 << K) => x << L
497 Reduction const r1 = Reduce(graph()->NewNode( 492 Reduction const r1 = Reduce(graph()->NewNode(
498 machine()->Word32And(), 493 machine()->Word32And(),
499 graph()->NewNode(machine()->Word32Shl(), p0, Int32Constant(l)), 494 graph()->NewNode(machine()->Word32Shl(), p0, Int32Constant(l)),
500 Int32Constant(-1 << k))); 495 Int32Constant(-1 << k)));
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 Reduction r = Reduce(node); 1643 Reduction r = Reduce(node);
1649 ASSERT_TRUE(r.Changed()); 1644 ASSERT_TRUE(r.Changed());
1650 EXPECT_THAT(r.replacement(), 1645 EXPECT_THAT(r.replacement(),
1651 IsStore(rep, base, index, value, effect, control)); 1646 IsStore(rep, base, index, value, effect, control));
1652 } 1647 }
1653 } 1648 }
1654 1649
1655 } // namespace compiler 1650 } // namespace compiler
1656 } // namespace internal 1651 } // namespace internal
1657 } // namespace v8 1652 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698