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/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/machine-operator-reducer.h" | 8 #include "src/compiler/machine-operator-reducer.h" |
8 #include "src/compiler/typer.h" | 9 #include "src/compiler/typer.h" |
9 #include "test/unittests/compiler/graph-unittest.h" | 10 #include "test/unittests/compiler/graph-unittest.h" |
10 #include "testing/gmock-support.h" | 11 #include "testing/gmock-support.h" |
11 | 12 |
12 using testing::AllOf; | 13 using testing::AllOf; |
13 using testing::Capture; | 14 using testing::Capture; |
14 using testing::CaptureEq; | 15 using testing::CaptureEq; |
15 | 16 |
16 namespace v8 { | 17 namespace v8 { |
17 namespace internal { | 18 namespace internal { |
18 namespace compiler { | 19 namespace compiler { |
19 | 20 |
20 class MachineOperatorReducerTest : public GraphTest { | 21 class MachineOperatorReducerTest : public GraphTest { |
21 public: | 22 public: |
22 explicit MachineOperatorReducerTest(int num_parameters = 2) | 23 explicit MachineOperatorReducerTest(int num_parameters = 2) |
23 : GraphTest(num_parameters) {} | 24 : GraphTest(num_parameters) {} |
24 | 25 |
25 protected: | 26 protected: |
26 Reduction Reduce(Node* node) { | 27 Reduction Reduce(Node* node) { |
27 Typer typer(zone()); | 28 Typer typer(zone()); |
28 JSOperatorBuilder javascript(zone()); | 29 JSOperatorBuilder javascript(zone()); |
29 JSGraph jsgraph(graph(), common(), &javascript, &typer, &machine_); | 30 JSGraph jsgraph(graph(), common(), &javascript, &typer, &machine_); |
30 MachineOperatorReducer reducer(&jsgraph); | 31 MachineOperatorReducer reducer(&jsgraph); |
31 return reducer.Reduce(node); | 32 return reducer.Reduce(node); |
32 } | 33 } |
33 | 34 |
| 35 Matcher<Node*> IsTruncatingDiv(const Matcher<Node*>& dividend_matcher, |
| 36 const int32_t divisor) { |
| 37 base::MagicNumbersForDivision<uint32_t> const mag = |
| 38 base::SignedDivisionByConstant(bit_cast<uint32_t>(divisor)); |
| 39 int32_t const multiplier = bit_cast<int32_t>(mag.multiplier); |
| 40 int32_t const shift = bit_cast<int32_t>(mag.shift); |
| 41 Matcher<Node*> quotient_matcher = |
| 42 IsInt32MulHigh(dividend_matcher, IsInt32Constant(multiplier)); |
| 43 if (divisor > 0 && multiplier < 0) { |
| 44 quotient_matcher = IsInt32Add(quotient_matcher, dividend_matcher); |
| 45 } else if (divisor < 0 && multiplier > 0) { |
| 46 quotient_matcher = IsInt32Sub(quotient_matcher, dividend_matcher); |
| 47 } |
| 48 if (shift) { |
| 49 quotient_matcher = IsWord32Sar(quotient_matcher, IsInt32Constant(shift)); |
| 50 } |
| 51 return IsInt32Add(quotient_matcher, |
| 52 IsWord32Shr(dividend_matcher, IsInt32Constant(31))); |
| 53 } |
| 54 |
34 MachineOperatorBuilder* machine() { return &machine_; } | 55 MachineOperatorBuilder* machine() { return &machine_; } |
35 | 56 |
36 private: | 57 private: |
37 MachineOperatorBuilder machine_; | 58 MachineOperatorBuilder machine_; |
38 }; | 59 }; |
39 | 60 |
40 | 61 |
41 template <typename T> | 62 template <typename T> |
42 class MachineOperatorReducerTestWithParam | 63 class MachineOperatorReducerTestWithParam |
43 : public MachineOperatorReducerTest, | 64 : public MachineOperatorReducerTest, |
44 public ::testing::WithParamInterface<T> { | 65 public ::testing::WithParamInterface<T> { |
45 public: | 66 public: |
46 explicit MachineOperatorReducerTestWithParam(int num_parameters = 2) | 67 explicit MachineOperatorReducerTestWithParam(int num_parameters = 2) |
47 : MachineOperatorReducerTest(num_parameters) {} | 68 : MachineOperatorReducerTest(num_parameters) {} |
48 virtual ~MachineOperatorReducerTestWithParam() {} | 69 virtual ~MachineOperatorReducerTestWithParam() {} |
49 }; | 70 }; |
50 | 71 |
51 | 72 |
52 namespace { | 73 namespace { |
53 | 74 |
54 static const float kFloat32Values[] = { | 75 const float kFloat32Values[] = { |
55 -std::numeric_limits<float>::infinity(), -2.70497e+38f, -1.4698e+37f, | 76 -std::numeric_limits<float>::infinity(), -2.70497e+38f, -1.4698e+37f, |
56 -1.22813e+35f, -1.20555e+35f, -1.34584e+34f, | 77 -1.22813e+35f, -1.20555e+35f, -1.34584e+34f, |
57 -1.0079e+32f, -6.49364e+26f, -3.06077e+25f, | 78 -1.0079e+32f, -6.49364e+26f, -3.06077e+25f, |
58 -1.46821e+25f, -1.17658e+23f, -1.9617e+22f, | 79 -1.46821e+25f, -1.17658e+23f, -1.9617e+22f, |
59 -2.7357e+20f, -1.48708e+13f, -1.89633e+12f, | 80 -2.7357e+20f, -1.48708e+13f, -1.89633e+12f, |
60 -4.66622e+11f, -2.22581e+11f, -1.45381e+10f, | 81 -4.66622e+11f, -2.22581e+11f, -1.45381e+10f, |
61 -1.3956e+09f, -1.32951e+09f, -1.30721e+09f, | 82 -1.3956e+09f, -1.32951e+09f, -1.30721e+09f, |
62 -1.19756e+09f, -9.26822e+08f, -6.35647e+08f, | 83 -1.19756e+09f, -9.26822e+08f, -6.35647e+08f, |
63 -4.00037e+08f, -1.81227e+08f, -5.09256e+07f, | 84 -4.00037e+08f, -1.81227e+08f, -5.09256e+07f, |
64 -964300.0f, -192446.0f, -28455.0f, | 85 -964300.0f, -192446.0f, -28455.0f, |
(...skipping 16 matching lines...) Expand all Loading... |
81 19878.0f, 20309.0f, 797056.0f, | 102 19878.0f, 20309.0f, 797056.0f, |
82 1.77219e+09f, 1.51116e+11f, 4.18193e+13f, | 103 1.77219e+09f, 1.51116e+11f, 4.18193e+13f, |
83 3.59167e+16f, 3.38211e+19f, 2.67488e+20f, | 104 3.59167e+16f, 3.38211e+19f, 2.67488e+20f, |
84 1.78831e+21f, 9.20914e+21f, 8.35654e+23f, | 105 1.78831e+21f, 9.20914e+21f, 8.35654e+23f, |
85 1.4495e+24f, 5.94015e+25f, 4.43608e+30f, | 106 1.4495e+24f, 5.94015e+25f, 4.43608e+30f, |
86 2.44502e+33f, 2.61152e+33f, 1.38178e+37f, | 107 2.44502e+33f, 2.61152e+33f, 1.38178e+37f, |
87 1.71306e+37f, 3.31899e+38f, 3.40282e+38f, | 108 1.71306e+37f, 3.31899e+38f, 3.40282e+38f, |
88 std::numeric_limits<float>::infinity()}; | 109 std::numeric_limits<float>::infinity()}; |
89 | 110 |
90 | 111 |
91 static const double kFloat64Values[] = { | 112 const double kFloat64Values[] = { |
92 -V8_INFINITY, -4.23878e+275, -5.82632e+265, -6.60355e+220, -6.26172e+212, | 113 -V8_INFINITY, -4.23878e+275, -5.82632e+265, -6.60355e+220, -6.26172e+212, |
93 -2.56222e+211, -4.82408e+201, -1.84106e+157, -1.63662e+127, -1.55772e+100, | 114 -2.56222e+211, -4.82408e+201, -1.84106e+157, -1.63662e+127, -1.55772e+100, |
94 -1.67813e+72, -2.3382e+55, -3.179e+30, -1.441e+09, -1.0647e+09, | 115 -1.67813e+72, -2.3382e+55, -3.179e+30, -1.441e+09, -1.0647e+09, |
95 -7.99361e+08, -5.77375e+08, -2.20984e+08, -32757, -13171, | 116 -7.99361e+08, -5.77375e+08, -2.20984e+08, -32757, -13171, |
96 -9970, -3984, -107, -105, -92, | 117 -9970, -3984, -107, -105, -92, |
97 -77, -61, -0.000208163, -1.86685e-06, -1.17296e-10, | 118 -77, -61, -0.000208163, -1.86685e-06, -1.17296e-10, |
98 -9.26358e-11, -5.08004e-60, -1.74753e-65, -1.06561e-71, -5.67879e-79, | 119 -9.26358e-11, -5.08004e-60, -1.74753e-65, -1.06561e-71, -5.67879e-79, |
99 -5.78459e-130, -2.90989e-171, -7.15489e-243, -3.76242e-252, -1.05639e-263, | 120 -5.78459e-130, -2.90989e-171, -7.15489e-243, -3.76242e-252, -1.05639e-263, |
100 -4.40497e-267, -2.19666e-273, -4.9998e-276, -5.59821e-278, -2.03855e-282, | 121 -4.40497e-267, -2.19666e-273, -4.9998e-276, -5.59821e-278, -2.03855e-282, |
101 -5.99335e-283, -7.17554e-284, -3.11744e-309, -0.0, 0.0, | 122 -5.99335e-283, -7.17554e-284, -3.11744e-309, -0.0, 0.0, |
102 2.22507e-308, 1.30127e-270, 7.62898e-260, 4.00313e-249, 3.16829e-233, | 123 2.22507e-308, 1.30127e-270, 7.62898e-260, 4.00313e-249, 3.16829e-233, |
103 1.85244e-228, 2.03544e-129, 1.35126e-110, 1.01182e-106, 5.26333e-94, | 124 1.85244e-228, 2.03544e-129, 1.35126e-110, 1.01182e-106, 5.26333e-94, |
104 1.35292e-90, 2.85394e-83, 1.78323e-77, 5.4967e-57, 1.03207e-25, | 125 1.35292e-90, 2.85394e-83, 1.78323e-77, 5.4967e-57, 1.03207e-25, |
105 4.57401e-25, 1.58738e-05, 2, 125, 2310, | 126 4.57401e-25, 1.58738e-05, 2, 125, 2310, |
106 9636, 14802, 17168, 28945, 29305, | 127 9636, 14802, 17168, 28945, 29305, |
107 4.81336e+07, 1.41207e+08, 4.65962e+08, 1.40499e+09, 2.12648e+09, | 128 4.81336e+07, 1.41207e+08, 4.65962e+08, 1.40499e+09, 2.12648e+09, |
108 8.80006e+30, 1.4446e+45, 1.12164e+54, 2.48188e+89, 6.71121e+102, | 129 8.80006e+30, 1.4446e+45, 1.12164e+54, 2.48188e+89, 6.71121e+102, |
109 3.074e+112, 4.9699e+152, 5.58383e+166, 4.30654e+172, 7.08824e+185, | 130 3.074e+112, 4.9699e+152, 5.58383e+166, 4.30654e+172, 7.08824e+185, |
110 9.6586e+214, 2.028e+223, 6.63277e+243, 1.56192e+261, 1.23202e+269, | 131 9.6586e+214, 2.028e+223, 6.63277e+243, 1.56192e+261, 1.23202e+269, |
111 5.72883e+289, 8.5798e+290, 1.40256e+294, 1.79769e+308, V8_INFINITY}; | 132 5.72883e+289, 8.5798e+290, 1.40256e+294, 1.79769e+308, V8_INFINITY}; |
112 | 133 |
113 | 134 |
114 static const int32_t kInt32Values[] = { | 135 const int32_t kInt32Values[] = { |
115 -2147483647 - 1, -1914954528, -1698749618, -1578693386, -1577976073, | 136 std::numeric_limits<int32_t>::min(), -1914954528, -1698749618, |
116 -1573998034, -1529085059, -1499540537, -1299205097, -1090814845, | 137 -1578693386, -1577976073, -1573998034, |
117 -938186388, -806828902, -750927650, -520676892, -513661538, | 138 -1529085059, -1499540537, -1299205097, |
118 -453036354, -433622833, -282638793, -28375, -27788, | 139 -1090814845, -938186388, -806828902, |
119 -22770, -18806, -14173, -11956, -11200, | 140 -750927650, -520676892, -513661538, |
120 -10212, -8160, -3751, -2758, -1522, | 141 -453036354, -433622833, -282638793, |
121 -121, -120, -118, -117, -106, | 142 -28375, -27788, -22770, |
122 -84, -80, -74, -59, -52, | 143 -18806, -14173, -11956, |
123 -48, -39, -35, -17, -11, | 144 -11200, -10212, -8160, |
124 -10, -9, -7, -5, 0, | 145 -3751, -2758, -1522, |
125 9, 12, 17, 23, 29, | 146 -121, -120, -118, |
126 31, 33, 35, 40, 47, | 147 -117, -106, -84, |
127 55, 56, 62, 64, 67, | 148 -80, -74, -59, |
128 68, 69, 74, 79, 84, | 149 -52, -48, -39, |
129 89, 90, 97, 104, 118, | 150 -35, -17, -11, |
130 124, 126, 127, 7278, 17787, | 151 -10, -9, -7, |
131 24136, 24202, 25570, 26680, 30242, | 152 -5, 0, 9, |
132 32399, 420886487, 642166225, 821912648, 822577803, | 153 12, 17, 23, |
133 851385718, 1212241078, 1411419304, 1589626102, 1596437184, | 154 29, 31, 33, |
134 1876245816, 1954730266, 2008792749, 2045320228, 2147483647}; | 155 35, 40, 47, |
| 156 55, 56, 62, |
| 157 64, 67, 68, |
| 158 69, 74, 79, |
| 159 84, 89, 90, |
| 160 97, 104, 118, |
| 161 124, 126, 127, |
| 162 7278, 17787, 24136, |
| 163 24202, 25570, 26680, |
| 164 30242, 32399, 420886487, |
| 165 642166225, 821912648, 822577803, |
| 166 851385718, 1212241078, 1411419304, |
| 167 1589626102, 1596437184, 1876245816, |
| 168 1954730266, 2008792749, 2045320228, |
| 169 std::numeric_limits<int32_t>::max()}; |
135 | 170 |
136 | 171 |
137 static const int64_t kInt64Values[] = { | 172 const int64_t kInt64Values[] = { |
138 V8_INT64_C(-9223372036854775807) - 1, V8_INT64_C(-8974392461363618006), | 173 std::numeric_limits<int64_t>::min(), V8_INT64_C(-8974392461363618006), |
139 V8_INT64_C(-8874367046689588135), V8_INT64_C(-8269197512118230839), | 174 V8_INT64_C(-8874367046689588135), V8_INT64_C(-8269197512118230839), |
140 V8_INT64_C(-8146091527100606733), V8_INT64_C(-7550917981466150848), | 175 V8_INT64_C(-8146091527100606733), V8_INT64_C(-7550917981466150848), |
141 V8_INT64_C(-7216590251577894337), V8_INT64_C(-6464086891160048440), | 176 V8_INT64_C(-7216590251577894337), V8_INT64_C(-6464086891160048440), |
142 V8_INT64_C(-6365616494908257190), V8_INT64_C(-6305630541365849726), | 177 V8_INT64_C(-6365616494908257190), V8_INT64_C(-6305630541365849726), |
143 V8_INT64_C(-5982222642272245453), V8_INT64_C(-5510103099058504169), | 178 V8_INT64_C(-5982222642272245453), V8_INT64_C(-5510103099058504169), |
144 V8_INT64_C(-5496838675802432701), V8_INT64_C(-4047626578868642657), | 179 V8_INT64_C(-5496838675802432701), V8_INT64_C(-4047626578868642657), |
145 V8_INT64_C(-4033755046900164544), V8_INT64_C(-3554299241457877041), | 180 V8_INT64_C(-4033755046900164544), V8_INT64_C(-3554299241457877041), |
146 V8_INT64_C(-2482258764588614470), V8_INT64_C(-1688515425526875335), | 181 V8_INT64_C(-2482258764588614470), V8_INT64_C(-1688515425526875335), |
147 V8_INT64_C(-924784137176548532), V8_INT64_C(-725316567157391307), | 182 V8_INT64_C(-924784137176548532), V8_INT64_C(-725316567157391307), |
148 V8_INT64_C(-439022654781092241), V8_INT64_C(-105545757668917080), | 183 V8_INT64_C(-439022654781092241), V8_INT64_C(-105545757668917080), |
149 V8_INT64_C(-2088319373), V8_INT64_C(-2073699916), | 184 V8_INT64_C(-2088319373), V8_INT64_C(-2073699916), |
150 V8_INT64_C(-1844949911), V8_INT64_C(-1831090548), | 185 V8_INT64_C(-1844949911), V8_INT64_C(-1831090548), |
151 V8_INT64_C(-1756711933), V8_INT64_C(-1559409497), | 186 V8_INT64_C(-1756711933), V8_INT64_C(-1559409497), |
152 V8_INT64_C(-1281179700), V8_INT64_C(-1211513985), | 187 V8_INT64_C(-1281179700), V8_INT64_C(-1211513985), |
153 V8_INT64_C(-1182371520), V8_INT64_C(-785934753), | 188 V8_INT64_C(-1182371520), V8_INT64_C(-785934753), |
154 V8_INT64_C(-767480697), V8_INT64_C(-705745662), | 189 V8_INT64_C(-767480697), V8_INT64_C(-705745662), |
155 V8_INT64_C(-514362436), V8_INT64_C(-459916580), | 190 V8_INT64_C(-514362436), V8_INT64_C(-459916580), |
156 V8_INT64_C(-312328082), V8_INT64_C(-302949707), | 191 V8_INT64_C(-312328082), V8_INT64_C(-302949707), |
157 V8_INT64_C(-285499304), V8_INT64_C(-125701262), | 192 V8_INT64_C(-285499304), V8_INT64_C(-125701262), |
158 V8_INT64_C(-95139843), V8_INT64_C(-32768), | 193 V8_INT64_C(-95139843), V8_INT64_C(-32768), |
159 V8_INT64_C(-27542), V8_INT64_C(-23600), | 194 V8_INT64_C(-27542), V8_INT64_C(-23600), |
160 V8_INT64_C(-18582), V8_INT64_C(-17770), | 195 V8_INT64_C(-18582), V8_INT64_C(-17770), |
161 V8_INT64_C(-9086), V8_INT64_C(-9010), | 196 V8_INT64_C(-9086), V8_INT64_C(-9010), |
162 V8_INT64_C(-8244), V8_INT64_C(-2890), | 197 V8_INT64_C(-8244), V8_INT64_C(-2890), |
163 V8_INT64_C(-103), V8_INT64_C(-34), | 198 V8_INT64_C(-103), V8_INT64_C(-34), |
164 V8_INT64_C(-27), V8_INT64_C(-25), | 199 V8_INT64_C(-27), V8_INT64_C(-25), |
165 V8_INT64_C(-9), V8_INT64_C(-7), | 200 V8_INT64_C(-9), V8_INT64_C(-7), |
166 V8_INT64_C(0), V8_INT64_C(2), | 201 V8_INT64_C(0), V8_INT64_C(2), |
167 V8_INT64_C(38), V8_INT64_C(58), | 202 V8_INT64_C(38), V8_INT64_C(58), |
168 V8_INT64_C(65), V8_INT64_C(93), | 203 V8_INT64_C(65), V8_INT64_C(93), |
169 V8_INT64_C(111), V8_INT64_C(1003), | 204 V8_INT64_C(111), V8_INT64_C(1003), |
170 V8_INT64_C(1267), V8_INT64_C(12797), | 205 V8_INT64_C(1267), V8_INT64_C(12797), |
171 V8_INT64_C(23122), V8_INT64_C(28200), | 206 V8_INT64_C(23122), V8_INT64_C(28200), |
172 V8_INT64_C(30888), V8_INT64_C(42648848), | 207 V8_INT64_C(30888), V8_INT64_C(42648848), |
173 V8_INT64_C(116836693), V8_INT64_C(263003643), | 208 V8_INT64_C(116836693), V8_INT64_C(263003643), |
174 V8_INT64_C(571039860), V8_INT64_C(1079398689), | 209 V8_INT64_C(571039860), V8_INT64_C(1079398689), |
175 V8_INT64_C(1145196402), V8_INT64_C(1184846321), | 210 V8_INT64_C(1145196402), V8_INT64_C(1184846321), |
176 V8_INT64_C(1758281648), V8_INT64_C(1859991374), | 211 V8_INT64_C(1758281648), V8_INT64_C(1859991374), |
177 V8_INT64_C(1960251588), V8_INT64_C(2042443199), | 212 V8_INT64_C(1960251588), V8_INT64_C(2042443199), |
178 V8_INT64_C(296220586027987448), V8_INT64_C(1015494173071134726), | 213 V8_INT64_C(296220586027987448), V8_INT64_C(1015494173071134726), |
179 V8_INT64_C(1151237951914455318), V8_INT64_C(1331941174616854174), | 214 V8_INT64_C(1151237951914455318), V8_INT64_C(1331941174616854174), |
180 V8_INT64_C(2022020418667972654), V8_INT64_C(2450251424374977035), | 215 V8_INT64_C(2022020418667972654), V8_INT64_C(2450251424374977035), |
181 V8_INT64_C(3668393562685561486), V8_INT64_C(4858229301215502171), | 216 V8_INT64_C(3668393562685561486), V8_INT64_C(4858229301215502171), |
182 V8_INT64_C(4919426235170669383), V8_INT64_C(5034286595330341762), | 217 V8_INT64_C(4919426235170669383), V8_INT64_C(5034286595330341762), |
183 V8_INT64_C(5055797915536941182), V8_INT64_C(6072389716149252074), | 218 V8_INT64_C(5055797915536941182), V8_INT64_C(6072389716149252074), |
184 V8_INT64_C(6185309910199801210), V8_INT64_C(6297328311011094138), | 219 V8_INT64_C(6185309910199801210), V8_INT64_C(6297328311011094138), |
185 V8_INT64_C(6932372858072165827), V8_INT64_C(8483640924987737210), | 220 V8_INT64_C(6932372858072165827), V8_INT64_C(8483640924987737210), |
186 V8_INT64_C(8663764179455849203), V8_INT64_C(8877197042645298254), | 221 V8_INT64_C(8663764179455849203), V8_INT64_C(8877197042645298254), |
187 V8_INT64_C(8901543506779157333), V8_INT64_C(9223372036854775807)}; | 222 V8_INT64_C(8901543506779157333), std::numeric_limits<int64_t>::max()}; |
188 | 223 |
189 | 224 |
190 static const uint32_t kUint32Values[] = { | 225 const uint32_t kUint32Values[] = { |
191 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf, | 226 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf, |
192 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344, | 227 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344, |
193 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c, | 228 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c, |
194 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00, | 229 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00, |
195 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000, | 230 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000, |
196 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff, | 231 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff, |
197 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff, | 232 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff, |
198 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff}; | 233 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff}; |
199 | 234 |
200 } // namespace | 235 } // namespace |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 Int32Constant(x)); | 597 Int32Constant(x)); |
563 Reduction r = Reduce(node); | 598 Reduction r = Reduce(node); |
564 ASSERT_TRUE(r.Changed()); | 599 ASSERT_TRUE(r.Changed()); |
565 int32_t m = bit_cast<int32_t>(~((1U << x) - 1U)); | 600 int32_t m = bit_cast<int32_t>(~((1U << x) - 1U)); |
566 EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant(m))); | 601 EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant(m))); |
567 } | 602 } |
568 } | 603 } |
569 | 604 |
570 | 605 |
571 // ----------------------------------------------------------------------------- | 606 // ----------------------------------------------------------------------------- |
| 607 // Int32Div |
| 608 |
| 609 |
| 610 TEST_F(MachineOperatorReducerTest, Int32DivWithConstant) { |
| 611 Node* const p0 = Parameter(0); |
| 612 { |
| 613 Reduction const r = |
| 614 Reduce(graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(0))); |
| 615 ASSERT_TRUE(r.Changed()); |
| 616 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); |
| 617 } |
| 618 { |
| 619 Reduction const r = |
| 620 Reduce(graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(1))); |
| 621 ASSERT_TRUE(r.Changed()); |
| 622 EXPECT_EQ(r.replacement(), p0); |
| 623 } |
| 624 { |
| 625 Reduction const r = |
| 626 Reduce(graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(-1))); |
| 627 ASSERT_TRUE(r.Changed()); |
| 628 EXPECT_THAT(r.replacement(), IsInt32Sub(IsInt32Constant(0), p0)); |
| 629 } |
| 630 { |
| 631 Reduction const r = |
| 632 Reduce(graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(2))); |
| 633 ASSERT_TRUE(r.Changed()); |
| 634 EXPECT_THAT( |
| 635 r.replacement(), |
| 636 IsWord32Sar(IsInt32Add(IsWord32Shr(p0, IsInt32Constant(31)), p0), |
| 637 IsInt32Constant(1))); |
| 638 } |
| 639 { |
| 640 Reduction const r = |
| 641 Reduce(graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(-2))); |
| 642 ASSERT_TRUE(r.Changed()); |
| 643 EXPECT_THAT( |
| 644 r.replacement(), |
| 645 IsInt32Sub( |
| 646 IsInt32Constant(0), |
| 647 IsWord32Sar(IsInt32Add(IsWord32Shr(p0, IsInt32Constant(31)), p0), |
| 648 IsInt32Constant(1)))); |
| 649 } |
| 650 TRACED_FORRANGE(int32_t, shift, 2, 30) { |
| 651 Reduction const r = Reduce( |
| 652 graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(1 << shift))); |
| 653 ASSERT_TRUE(r.Changed()); |
| 654 EXPECT_THAT( |
| 655 r.replacement(), |
| 656 IsWord32Sar(IsInt32Add(IsWord32Shr(IsWord32Sar(p0, IsInt32Constant(31)), |
| 657 IsInt32Constant(32 - shift)), |
| 658 p0), |
| 659 IsInt32Constant(shift))); |
| 660 } |
| 661 TRACED_FORRANGE(int32_t, shift, 2, 31) { |
| 662 Reduction const r = Reduce(graph()->NewNode( |
| 663 machine()->Int32Div(), p0, |
| 664 Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift))); |
| 665 ASSERT_TRUE(r.Changed()); |
| 666 EXPECT_THAT( |
| 667 r.replacement(), |
| 668 IsInt32Sub( |
| 669 IsInt32Constant(0), |
| 670 IsWord32Sar( |
| 671 IsInt32Add(IsWord32Shr(IsWord32Sar(p0, IsInt32Constant(31)), |
| 672 IsInt32Constant(32 - shift)), |
| 673 p0), |
| 674 IsInt32Constant(shift)))); |
| 675 } |
| 676 TRACED_FOREACH(int32_t, divisor, kInt32Values) { |
| 677 if (divisor < 0) { |
| 678 if (base::bits::IsPowerOfTwo32(-divisor)) continue; |
| 679 Reduction const r = Reduce( |
| 680 graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(divisor))); |
| 681 ASSERT_TRUE(r.Changed()); |
| 682 EXPECT_THAT(r.replacement(), IsInt32Sub(IsInt32Constant(0), |
| 683 IsTruncatingDiv(p0, -divisor))); |
| 684 } else if (divisor > 0) { |
| 685 if (base::bits::IsPowerOfTwo32(divisor)) continue; |
| 686 Reduction const r = Reduce( |
| 687 graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(divisor))); |
| 688 ASSERT_TRUE(r.Changed()); |
| 689 EXPECT_THAT(r.replacement(), IsTruncatingDiv(p0, divisor)); |
| 690 } |
| 691 } |
| 692 } |
| 693 |
| 694 |
| 695 // ----------------------------------------------------------------------------- |
572 // Int32Mod | 696 // Int32Mod |
573 | 697 |
574 | 698 |
575 TEST_F(MachineOperatorReducerTest, Int32ModWithPowerOfTwo) { | 699 TEST_F(MachineOperatorReducerTest, Int32ModWithConstant) { |
576 Node* p0 = Parameter(0); | 700 Node* const p0 = Parameter(0); |
577 TRACED_FORRANGE(int32_t, x, 1, 30) { | 701 static const int32_t kOnes[] = {-1, 1}; |
578 int32_t const divisor = 1 << x; | 702 TRACED_FOREACH(int32_t, one, kOnes) { |
579 Node* node = | 703 Reduction const r = |
580 graph()->NewNode(machine()->Int32Mod(), p0, Int32Constant(divisor)); | 704 Reduce(graph()->NewNode(machine()->Int32Mod(), p0, Int32Constant(one))); |
581 Reduction r = Reduce(node); | 705 ASSERT_TRUE(r.Changed()); |
| 706 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); |
| 707 } |
| 708 TRACED_FORRANGE(int32_t, shift, 1, 30) { |
| 709 Reduction const r = Reduce( |
| 710 graph()->NewNode(machine()->Int32Mod(), p0, Int32Constant(1 << shift))); |
582 ASSERT_TRUE(r.Changed()); | 711 ASSERT_TRUE(r.Changed()); |
583 | 712 |
584 Capture<Node*> branch; | 713 Capture<Node*> branch; |
585 Node* phi = r.replacement(); | 714 Node* const phi = r.replacement(); |
586 int32_t const mask = divisor - 1; | 715 int32_t const mask = (1 << shift) - 1; |
587 EXPECT_THAT( | 716 EXPECT_THAT( |
588 phi, IsPhi(kMachInt32, | 717 phi, IsPhi(kMachInt32, |
589 IsInt32Sub(IsInt32Constant(0), | 718 IsInt32Sub(IsInt32Constant(0), |
590 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), | 719 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), |
591 IsInt32Constant(mask))), | 720 IsInt32Constant(mask))), |
592 IsWord32And(p0, IsInt32Constant(mask)), | 721 IsWord32And(p0, IsInt32Constant(mask)), |
593 IsMerge(IsIfTrue(CaptureEq(&branch)), | 722 IsMerge(IsIfTrue(CaptureEq(&branch)), |
594 IsIfFalse(AllOf( | 723 IsIfFalse(AllOf( |
595 CaptureEq(&branch), | 724 CaptureEq(&branch), |
596 IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)), | 725 IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)), |
597 graph()->start())))))); | 726 graph()->start())))))); |
598 } | 727 } |
| 728 TRACED_FORRANGE(int32_t, shift, 1, 31) { |
| 729 Reduction const r = Reduce(graph()->NewNode( |
| 730 machine()->Int32Mod(), p0, |
| 731 Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift))); |
| 732 ASSERT_TRUE(r.Changed()); |
| 733 |
| 734 Capture<Node*> branch; |
| 735 Node* const phi = r.replacement(); |
| 736 int32_t const mask = bit_cast<int32_t, uint32_t>((1U << shift) - 1); |
| 737 EXPECT_THAT( |
| 738 phi, IsPhi(kMachInt32, |
| 739 IsInt32Sub(IsInt32Constant(0), |
| 740 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), |
| 741 IsInt32Constant(mask))), |
| 742 IsWord32And(p0, IsInt32Constant(mask)), |
| 743 IsMerge(IsIfTrue(CaptureEq(&branch)), |
| 744 IsIfFalse(AllOf( |
| 745 CaptureEq(&branch), |
| 746 IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)), |
| 747 graph()->start())))))); |
| 748 } |
| 749 TRACED_FOREACH(int32_t, divisor, kInt32Values) { |
| 750 if (divisor == 0 || base::bits::IsPowerOfTwo32(Abs(divisor))) continue; |
| 751 Reduction const r = Reduce( |
| 752 graph()->NewNode(machine()->Int32Mod(), p0, Int32Constant(divisor))); |
| 753 ASSERT_TRUE(r.Changed()); |
| 754 EXPECT_THAT(r.replacement(), |
| 755 IsInt32Sub(p0, IsInt32Mul(IsTruncatingDiv(p0, Abs(divisor)), |
| 756 IsInt32Constant(Abs(divisor))))); |
| 757 } |
599 } | 758 } |
600 | 759 |
601 | 760 |
602 // ----------------------------------------------------------------------------- | 761 // ----------------------------------------------------------------------------- |
603 // Int32AddWithOverflow | 762 // Int32AddWithOverflow |
604 | 763 |
605 | 764 |
606 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithZero) { | 765 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithZero) { |
607 Node* p0 = Parameter(0); | 766 Node* p0 = Parameter(0); |
608 { | 767 { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 Reduction r = Reduce(node); | 916 Reduction r = Reduce(node); |
758 ASSERT_TRUE(r.Changed()); | 917 ASSERT_TRUE(r.Changed()); |
759 EXPECT_THAT(r.replacement(), | 918 EXPECT_THAT(r.replacement(), |
760 IsStore(rep, base, index, value, effect, control)); | 919 IsStore(rep, base, index, value, effect, control)); |
761 } | 920 } |
762 } | 921 } |
763 | 922 |
764 } // namespace compiler | 923 } // namespace compiler |
765 } // namespace internal | 924 } // namespace internal |
766 } // namespace v8 | 925 } // namespace v8 |
OLD | NEW |