OLD | NEW |
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 "test/unittests/compiler/graph-unittest.h" | 10 #include "test/unittests/compiler/graph-unittest.h" |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 graph()->NewNode(machine()->TruncateInt64ToInt32(), Int64Constant(x))); | 475 graph()->NewNode(machine()->TruncateInt64ToInt32(), Int64Constant(x))); |
476 ASSERT_TRUE(reduction.Changed()); | 476 ASSERT_TRUE(reduction.Changed()); |
477 EXPECT_THAT(reduction.replacement(), | 477 EXPECT_THAT(reduction.replacement(), |
478 IsInt32Constant(bit_cast<int32_t>( | 478 IsInt32Constant(bit_cast<int32_t>( |
479 static_cast<uint32_t>(bit_cast<uint64_t>(x))))); | 479 static_cast<uint32_t>(bit_cast<uint64_t>(x))))); |
480 } | 480 } |
481 } | 481 } |
482 | 482 |
483 | 483 |
484 // ----------------------------------------------------------------------------- | 484 // ----------------------------------------------------------------------------- |
| 485 // Word32And |
| 486 |
| 487 |
| 488 TEST_F(MachineOperatorReducerTest, Word32AndWithWord32AndWithConstant) { |
| 489 Node* const p0 = Parameter(0); |
| 490 |
| 491 TRACED_FOREACH(int32_t, k, kInt32Values) { |
| 492 TRACED_FOREACH(int32_t, l, kInt32Values) { |
| 493 if (k == 0 || k == -1 || l == 0 || l == -1) continue; |
| 494 |
| 495 // (x & K) & L => x & (K & L) |
| 496 Reduction const r1 = Reduce(graph()->NewNode( |
| 497 machine()->Word32And(), |
| 498 graph()->NewNode(machine()->Word32And(), p0, Int32Constant(k)), |
| 499 Int32Constant(l))); |
| 500 ASSERT_TRUE(r1.Changed()); |
| 501 EXPECT_THAT(r1.replacement(), IsWord32And(p0, IsInt32Constant(k & l))); |
| 502 |
| 503 // (K & x) & L => x & (K & L) |
| 504 Reduction const r2 = Reduce(graph()->NewNode( |
| 505 machine()->Word32And(), |
| 506 graph()->NewNode(machine()->Word32And(), Int32Constant(k), p0), |
| 507 Int32Constant(l))); |
| 508 ASSERT_TRUE(r2.Changed()); |
| 509 EXPECT_THAT(r2.replacement(), IsWord32And(p0, IsInt32Constant(k & l))); |
| 510 } |
| 511 } |
| 512 } |
| 513 |
| 514 |
| 515 // ----------------------------------------------------------------------------- |
485 // Word32Xor | 516 // Word32Xor |
486 | 517 |
487 | 518 |
488 TEST_F(MachineOperatorReducerTest, Word32XorWithWord32XorAndMinusOne) { | 519 TEST_F(MachineOperatorReducerTest, Word32XorWithWord32XorAndMinusOne) { |
489 Node* const p0 = Parameter(0); | 520 Node* const p0 = Parameter(0); |
490 | 521 |
491 // (x ^ -1) ^ -1 => x | 522 // (x ^ -1) ^ -1 => x |
492 Reduction r1 = Reduce(graph()->NewNode( | 523 Reduction r1 = Reduce(graph()->NewNode( |
493 machine()->Word32Xor(), | 524 machine()->Word32Xor(), |
494 graph()->NewNode(machine()->Word32Xor(), p0, Int32Constant(-1)), | 525 graph()->NewNode(machine()->Word32Xor(), p0, Int32Constant(-1)), |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 Reduction r = Reduce(node); | 1140 Reduction r = Reduce(node); |
1110 ASSERT_TRUE(r.Changed()); | 1141 ASSERT_TRUE(r.Changed()); |
1111 EXPECT_THAT(r.replacement(), | 1142 EXPECT_THAT(r.replacement(), |
1112 IsStore(rep, base, index, value, effect, control)); | 1143 IsStore(rep, base, index, value, effect, control)); |
1113 } | 1144 } |
1114 } | 1145 } |
1115 | 1146 |
1116 } // namespace compiler | 1147 } // namespace compiler |
1117 } // namespace internal | 1148 } // namespace internal |
1118 } // namespace v8 | 1149 } // namespace v8 |
OLD | NEW |