| 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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 Int32Constant(divisor), graph()->start())); | 869 Int32Constant(divisor), graph()->start())); |
| 870 ASSERT_TRUE(r.Changed()); | 870 ASSERT_TRUE(r.Changed()); |
| 871 EXPECT_THAT(r.replacement(), | 871 EXPECT_THAT(r.replacement(), |
| 872 IsInt32Constant(base::bits::SignedMod32(dividend, divisor))); | 872 IsInt32Constant(base::bits::SignedMod32(dividend, divisor))); |
| 873 } | 873 } |
| 874 } | 874 } |
| 875 TRACED_FORRANGE(int32_t, shift, 1, 30) { | 875 TRACED_FORRANGE(int32_t, shift, 1, 30) { |
| 876 Reduction const r = | 876 Reduction const r = |
| 877 Reduce(graph()->NewNode(machine()->Int32Mod(), p0, | 877 Reduce(graph()->NewNode(machine()->Int32Mod(), p0, |
| 878 Int32Constant(1 << shift), graph()->start())); | 878 Int32Constant(1 << shift), graph()->start())); |
| 879 int32_t const mask = (1 << shift) - 1; |
| 879 ASSERT_TRUE(r.Changed()); | 880 ASSERT_TRUE(r.Changed()); |
| 880 | |
| 881 Capture<Node*> branch; | |
| 882 Node* const phi = r.replacement(); | |
| 883 int32_t const mask = (1 << shift) - 1; | |
| 884 EXPECT_THAT( | 881 EXPECT_THAT( |
| 885 phi, IsPhi(kMachInt32, | 882 r.replacement(), |
| 886 IsInt32Sub(IsInt32Constant(0), | 883 IsSelect(kMachInt32, IsInt32LessThan(p0, IsInt32Constant(0)), |
| 887 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), | 884 IsInt32Sub(IsInt32Constant(0), |
| 888 IsInt32Constant(mask))), | 885 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), |
| 889 IsWord32And(p0, IsInt32Constant(mask)), | 886 IsInt32Constant(mask))), |
| 890 IsMerge(IsIfTrue(CaptureEq(&branch)), | 887 IsWord32And(p0, IsInt32Constant(mask)))); |
| 891 IsIfFalse(AllOf( | |
| 892 CaptureEq(&branch), | |
| 893 IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)), | |
| 894 graph()->start())))))); | |
| 895 } | 888 } |
| 896 TRACED_FORRANGE(int32_t, shift, 1, 31) { | 889 TRACED_FORRANGE(int32_t, shift, 1, 31) { |
| 897 Reduction const r = Reduce(graph()->NewNode( | 890 Reduction const r = Reduce(graph()->NewNode( |
| 898 machine()->Int32Mod(), p0, | 891 machine()->Int32Mod(), p0, |
| 899 Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift), | 892 Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift), |
| 900 graph()->start())); | 893 graph()->start())); |
| 894 int32_t const mask = bit_cast<int32_t, uint32_t>((1U << shift) - 1); |
| 901 ASSERT_TRUE(r.Changed()); | 895 ASSERT_TRUE(r.Changed()); |
| 902 | |
| 903 Capture<Node*> branch; | |
| 904 Node* const phi = r.replacement(); | |
| 905 int32_t const mask = bit_cast<int32_t, uint32_t>((1U << shift) - 1); | |
| 906 EXPECT_THAT( | 896 EXPECT_THAT( |
| 907 phi, IsPhi(kMachInt32, | 897 r.replacement(), |
| 908 IsInt32Sub(IsInt32Constant(0), | 898 IsSelect(kMachInt32, IsInt32LessThan(p0, IsInt32Constant(0)), |
| 909 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), | 899 IsInt32Sub(IsInt32Constant(0), |
| 910 IsInt32Constant(mask))), | 900 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), |
| 911 IsWord32And(p0, IsInt32Constant(mask)), | 901 IsInt32Constant(mask))), |
| 912 IsMerge(IsIfTrue(CaptureEq(&branch)), | 902 IsWord32And(p0, IsInt32Constant(mask)))); |
| 913 IsIfFalse(AllOf( | |
| 914 CaptureEq(&branch), | |
| 915 IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)), | |
| 916 graph()->start())))))); | |
| 917 } | 903 } |
| 918 TRACED_FOREACH(int32_t, divisor, kInt32Values) { | 904 TRACED_FOREACH(int32_t, divisor, kInt32Values) { |
| 919 if (divisor == 0 || base::bits::IsPowerOfTwo32(Abs(divisor))) continue; | 905 if (divisor == 0 || base::bits::IsPowerOfTwo32(Abs(divisor))) continue; |
| 920 Reduction const r = Reduce(graph()->NewNode( | 906 Reduction const r = Reduce(graph()->NewNode( |
| 921 machine()->Int32Mod(), p0, Int32Constant(divisor), graph()->start())); | 907 machine()->Int32Mod(), p0, Int32Constant(divisor), graph()->start())); |
| 922 ASSERT_TRUE(r.Changed()); | 908 ASSERT_TRUE(r.Changed()); |
| 923 EXPECT_THAT(r.replacement(), | 909 EXPECT_THAT(r.replacement(), |
| 924 IsInt32Sub(p0, IsInt32Mul(IsTruncatingDiv(p0, Abs(divisor)), | 910 IsInt32Sub(p0, IsInt32Mul(IsTruncatingDiv(p0, Abs(divisor)), |
| 925 IsInt32Constant(Abs(divisor))))); | 911 IsInt32Constant(Abs(divisor))))); |
| 926 } | 912 } |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 Reduction r = Reduce(node); | 1183 Reduction r = Reduce(node); |
| 1198 ASSERT_TRUE(r.Changed()); | 1184 ASSERT_TRUE(r.Changed()); |
| 1199 EXPECT_THAT(r.replacement(), | 1185 EXPECT_THAT(r.replacement(), |
| 1200 IsStore(rep, base, index, value, effect, control)); | 1186 IsStore(rep, base, index, value, effect, control)); |
| 1201 } | 1187 } |
| 1202 } | 1188 } |
| 1203 | 1189 |
| 1204 } // namespace compiler | 1190 } // namespace compiler |
| 1205 } // namespace internal | 1191 } // namespace internal |
| 1206 } // namespace v8 | 1192 } // namespace v8 |
| OLD | NEW |