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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 Int32Constant(x)); | 835 Int32Constant(x)); |
836 Reduction r = Reduce(node); | 836 Reduction r = Reduce(node); |
837 ASSERT_TRUE(r.Changed()); | 837 ASSERT_TRUE(r.Changed()); |
838 int32_t m = bit_cast<int32_t>(~((1U << x) - 1U)); | 838 int32_t m = bit_cast<int32_t>(~((1U << x) - 1U)); |
839 EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant(m))); | 839 EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant(m))); |
840 } | 840 } |
841 } | 841 } |
842 | 842 |
843 | 843 |
844 // ----------------------------------------------------------------------------- | 844 // ----------------------------------------------------------------------------- |
| 845 // Int32Sub |
| 846 |
| 847 |
| 848 TEST_F(MachineOperatorReducerTest, Int32SubWithConstant) { |
| 849 Node* const p0 = Parameter(0); |
| 850 TRACED_FOREACH(int32_t, k, kInt32Values) { |
| 851 Reduction const r = |
| 852 Reduce(graph()->NewNode(machine()->Int32Sub(), p0, Int32Constant(k))); |
| 853 ASSERT_TRUE(r.Changed()); |
| 854 if (k == 0) { |
| 855 EXPECT_EQ(p0, r.replacement()); |
| 856 } else { |
| 857 EXPECT_THAT(r.replacement(), IsInt32Add(p0, IsInt32Constant(-k))); |
| 858 } |
| 859 } |
| 860 } |
| 861 |
| 862 |
| 863 // ----------------------------------------------------------------------------- |
845 // Int32Div | 864 // Int32Div |
846 | 865 |
847 | 866 |
848 TEST_F(MachineOperatorReducerTest, Int32DivWithConstant) { | 867 TEST_F(MachineOperatorReducerTest, Int32DivWithConstant) { |
849 Node* const p0 = Parameter(0); | 868 Node* const p0 = Parameter(0); |
850 { | 869 { |
851 Reduction const r = Reduce(graph()->NewNode( | 870 Reduction const r = Reduce(graph()->NewNode( |
852 machine()->Int32Div(), p0, Int32Constant(0), graph()->start())); | 871 machine()->Int32Div(), p0, Int32Constant(0), graph()->start())); |
853 ASSERT_TRUE(r.Changed()); | 872 ASSERT_TRUE(r.Changed()); |
854 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); | 873 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 Reduction r = Reduce(node); | 1393 Reduction r = Reduce(node); |
1375 ASSERT_TRUE(r.Changed()); | 1394 ASSERT_TRUE(r.Changed()); |
1376 EXPECT_THAT(r.replacement(), | 1395 EXPECT_THAT(r.replacement(), |
1377 IsStore(rep, base, index, value, effect, control)); | 1396 IsStore(rep, base, index, value, effect, control)); |
1378 } | 1397 } |
1379 } | 1398 } |
1380 | 1399 |
1381 } // namespace compiler | 1400 } // namespace compiler |
1382 } // namespace internal | 1401 } // namespace internal |
1383 } // namespace v8 | 1402 } // namespace v8 |
OLD | NEW |