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

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

Issue 470633006: [turbofan] Add support for change/truncate to MachineOperatorReducer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « test/compiler-unittests/graph-unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/compiler/machine-operator-reducer.h" 6 #include "src/compiler/machine-operator-reducer.h"
7 #include "test/compiler-unittests/graph-unittest.h" 7 #include "test/compiler-unittests/graph-unittest.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 11 matching lines...) Expand all
22 return reducer.Reduce(node); 22 return reducer.Reduce(node);
23 } 23 }
24 24
25 MachineOperatorBuilder* machine() { return &machine_; } 25 MachineOperatorBuilder* machine() { return &machine_; }
26 26
27 private: 27 private:
28 MachineOperatorBuilder machine_; 28 MachineOperatorBuilder machine_;
29 }; 29 };
30 30
31 31
32 template <typename T>
33 class MachineOperatorReducerTestWithParam
34 : public MachineOperatorReducerTest,
35 public ::testing::WithParamInterface<T> {
36 public:
37 explicit MachineOperatorReducerTestWithParam(int num_parameters = 2)
38 : MachineOperatorReducerTest(num_parameters) {}
39 virtual ~MachineOperatorReducerTestWithParam() {}
40 };
41
42
32 namespace { 43 namespace {
33 44
34 static const uint32_t kConstants[] = { 45 static const double kFloat64Values[] = {
46 -V8_INFINITY, -4.23878e+275, -5.82632e+265, -6.60355e+220, -6.26172e+212,
47 -2.56222e+211, -4.82408e+201, -1.84106e+157, -1.63662e+127, -1.55772e+100,
48 -1.67813e+72, -2.3382e+55, -3.179e+30, -1.441e+09, -1.0647e+09,
49 -7.99361e+08, -5.77375e+08, -2.20984e+08, -32757, -13171,
50 -9970, -3984, -107, -105, -92,
51 -77, -61, -0.000208163, -1.86685e-06, -1.17296e-10,
52 -9.26358e-11, -5.08004e-60, -1.74753e-65, -1.06561e-71, -5.67879e-79,
53 -5.78459e-130, -2.90989e-171, -7.15489e-243, -3.76242e-252, -1.05639e-263,
54 -4.40497e-267, -2.19666e-273, -4.9998e-276, -5.59821e-278, -2.03855e-282,
55 -5.99335e-283, -7.17554e-284, -3.11744e-309, -0.0, 0.0,
56 2.22507e-308, 1.30127e-270, 7.62898e-260, 4.00313e-249, 3.16829e-233,
57 1.85244e-228, 2.03544e-129, 1.35126e-110, 1.01182e-106, 5.26333e-94,
58 1.35292e-90, 2.85394e-83, 1.78323e-77, 5.4967e-57, 1.03207e-25,
59 4.57401e-25, 1.58738e-05, 2, 125, 2310,
60 9636, 14802, 17168, 28945, 29305,
61 4.81336e+07, 1.41207e+08, 4.65962e+08, 1.40499e+09, 2.12648e+09,
62 8.80006e+30, 1.4446e+45, 1.12164e+54, 2.48188e+89, 6.71121e+102,
63 3.074e+112, 4.9699e+152, 5.58383e+166, 4.30654e+172, 7.08824e+185,
64 9.6586e+214, 2.028e+223, 6.63277e+243, 1.56192e+261, 1.23202e+269,
65 5.72883e+289, 8.5798e+290, 1.40256e+294, 1.79769e+308, V8_INFINITY};
66
67
68 static const int32_t kInt32Values[] = {
69 -2147483647 - 1, -1914954528, -1698749618, -1578693386, -1577976073,
70 -1573998034, -1529085059, -1499540537, -1299205097, -1090814845,
71 -938186388, -806828902, -750927650, -520676892, -513661538,
72 -453036354, -433622833, -282638793, -28375, -27788,
73 -22770, -18806, -14173, -11956, -11200,
74 -10212, -8160, -3751, -2758, -1522,
75 -121, -120, -118, -117, -106,
76 -84, -80, -74, -59, -52,
77 -48, -39, -35, -17, -11,
78 -10, -9, -7, -5, 0,
79 9, 12, 17, 23, 29,
80 31, 33, 35, 40, 47,
81 55, 56, 62, 64, 67,
82 68, 69, 74, 79, 84,
83 89, 90, 97, 104, 118,
84 124, 126, 127, 7278, 17787,
85 24136, 24202, 25570, 26680, 30242,
86 32399, 420886487, 642166225, 821912648, 822577803,
87 851385718, 1212241078, 1411419304, 1589626102, 1596437184,
88 1876245816, 1954730266, 2008792749, 2045320228, 2147483647};
89
90
91 static const int64_t kInt64Values[] = {
92 V8_INT64_C(-9223372036854775807) - 1, V8_INT64_C(-8974392461363618006),
93 V8_INT64_C(-8874367046689588135), V8_INT64_C(-8269197512118230839),
94 V8_INT64_C(-8146091527100606733), V8_INT64_C(-7550917981466150848),
95 V8_INT64_C(-7216590251577894337), V8_INT64_C(-6464086891160048440),
96 V8_INT64_C(-6365616494908257190), V8_INT64_C(-6305630541365849726),
97 V8_INT64_C(-5982222642272245453), V8_INT64_C(-5510103099058504169),
98 V8_INT64_C(-5496838675802432701), V8_INT64_C(-4047626578868642657),
99 V8_INT64_C(-4033755046900164544), V8_INT64_C(-3554299241457877041),
100 V8_INT64_C(-2482258764588614470), V8_INT64_C(-1688515425526875335),
101 V8_INT64_C(-924784137176548532), V8_INT64_C(-725316567157391307),
102 V8_INT64_C(-439022654781092241), V8_INT64_C(-105545757668917080),
103 V8_INT64_C(-2088319373), V8_INT64_C(-2073699916),
104 V8_INT64_C(-1844949911), V8_INT64_C(-1831090548),
105 V8_INT64_C(-1756711933), V8_INT64_C(-1559409497),
106 V8_INT64_C(-1281179700), V8_INT64_C(-1211513985),
107 V8_INT64_C(-1182371520), V8_INT64_C(-785934753),
108 V8_INT64_C(-767480697), V8_INT64_C(-705745662),
109 V8_INT64_C(-514362436), V8_INT64_C(-459916580),
110 V8_INT64_C(-312328082), V8_INT64_C(-302949707),
111 V8_INT64_C(-285499304), V8_INT64_C(-125701262),
112 V8_INT64_C(-95139843), V8_INT64_C(-32768),
113 V8_INT64_C(-27542), V8_INT64_C(-23600),
114 V8_INT64_C(-18582), V8_INT64_C(-17770),
115 V8_INT64_C(-9086), V8_INT64_C(-9010),
116 V8_INT64_C(-8244), V8_INT64_C(-2890),
117 V8_INT64_C(-103), V8_INT64_C(-34),
118 V8_INT64_C(-27), V8_INT64_C(-25),
119 V8_INT64_C(-9), V8_INT64_C(-7),
120 V8_INT64_C(0), V8_INT64_C(2),
121 V8_INT64_C(38), V8_INT64_C(58),
122 V8_INT64_C(65), V8_INT64_C(93),
123 V8_INT64_C(111), V8_INT64_C(1003),
124 V8_INT64_C(1267), V8_INT64_C(12797),
125 V8_INT64_C(23122), V8_INT64_C(28200),
126 V8_INT64_C(30888), V8_INT64_C(42648848),
127 V8_INT64_C(116836693), V8_INT64_C(263003643),
128 V8_INT64_C(571039860), V8_INT64_C(1079398689),
129 V8_INT64_C(1145196402), V8_INT64_C(1184846321),
130 V8_INT64_C(1758281648), V8_INT64_C(1859991374),
131 V8_INT64_C(1960251588), V8_INT64_C(2042443199),
132 V8_INT64_C(296220586027987448), V8_INT64_C(1015494173071134726),
133 V8_INT64_C(1151237951914455318), V8_INT64_C(1331941174616854174),
134 V8_INT64_C(2022020418667972654), V8_INT64_C(2450251424374977035),
135 V8_INT64_C(3668393562685561486), V8_INT64_C(4858229301215502171),
136 V8_INT64_C(4919426235170669383), V8_INT64_C(5034286595330341762),
137 V8_INT64_C(5055797915536941182), V8_INT64_C(6072389716149252074),
138 V8_INT64_C(6185309910199801210), V8_INT64_C(6297328311011094138),
139 V8_INT64_C(6932372858072165827), V8_INT64_C(8483640924987737210),
140 V8_INT64_C(8663764179455849203), V8_INT64_C(8877197042645298254),
141 V8_INT64_C(8901543506779157333), V8_INT64_C(9223372036854775807)};
142
143
144 static const uint32_t kUint32Values[] = {
35 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf, 145 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf,
36 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344, 146 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344,
37 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c, 147 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c,
38 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00, 148 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00,
39 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000, 149 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000,
40 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff, 150 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff,
41 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff, 151 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff,
42 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff}; 152 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff};
43 153
44 } // namespace 154 } // namespace
45 155
46 156
157 // -----------------------------------------------------------------------------
158 // Unary operators
159
160
161 namespace {
162
163 struct UnaryOperator {
164 Operator* (MachineOperatorBuilder::*constructor)();
165 const char* constructor_name;
166 };
167
168
169 std::ostream& operator<<(std::ostream& os, const UnaryOperator& unop) {
170 return os << unop.constructor_name;
171 }
172
173
174 static const UnaryOperator kUnaryOperators[] = {
175 {&MachineOperatorBuilder::ChangeInt32ToFloat64, "ChangeInt32ToFloat64"},
176 {&MachineOperatorBuilder::ChangeUint32ToFloat64, "ChangeUint32ToFloat64"},
177 {&MachineOperatorBuilder::ChangeFloat64ToInt32, "ChangeFloat64ToInt32"},
178 {&MachineOperatorBuilder::ChangeFloat64ToUint32, "ChangeFloat64ToUint32"},
179 {&MachineOperatorBuilder::ChangeInt32ToInt64, "ChangeInt32ToInt64"},
180 {&MachineOperatorBuilder::ChangeUint32ToUint64, "ChangeUint32ToUint64"},
181 {&MachineOperatorBuilder::TruncateFloat64ToInt32, "TruncateFloat64ToInt32"},
182 {&MachineOperatorBuilder::TruncateInt64ToInt32, "TruncateInt64ToInt32"}};
183
184 } // namespace
185
186
187 typedef MachineOperatorReducerTestWithParam<UnaryOperator>
188 MachineUnaryOperatorReducerTest;
189
190
191 TEST_P(MachineUnaryOperatorReducerTest, Parameter) {
192 const UnaryOperator unop = GetParam();
193 Reduction reduction =
194 Reduce(graph()->NewNode((machine()->*unop.constructor)(), Parameter(0)));
195 EXPECT_FALSE(reduction.Changed());
196 }
197
198
199 INSTANTIATE_TEST_CASE_P(MachineOperatorReducerTest,
200 MachineUnaryOperatorReducerTest,
201 ::testing::ValuesIn(kUnaryOperators));
202
203
204 // -----------------------------------------------------------------------------
205 // ChangeFloat64ToInt32
206
207
208 TEST_F(MachineOperatorReducerTest,
209 ChangeFloat64ToInt32WithChangeInt32ToFloat64) {
210 Node* value = Parameter(0);
211 Reduction reduction = Reduce(graph()->NewNode(
212 machine()->ChangeFloat64ToInt32(),
213 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value)));
214 ASSERT_TRUE(reduction.Changed());
215 EXPECT_EQ(value, reduction.replacement());
216 }
217
218
219 TEST_F(MachineOperatorReducerTest, ChangeFloat64ToInt32WithConstant) {
220 TRACED_FOREACH(int32_t, x, kInt32Values) {
221 Reduction reduction = Reduce(graph()->NewNode(
222 machine()->ChangeFloat64ToInt32(), Float64Constant(FastI2D(x))));
223 ASSERT_TRUE(reduction.Changed());
224 EXPECT_THAT(reduction.replacement(), IsInt32Constant(x));
225 }
226 }
227
228
229 // -----------------------------------------------------------------------------
230 // ChangeFloat64ToUint32
231
232
233 TEST_F(MachineOperatorReducerTest,
234 ChangeFloat64ToUint32WithChangeUint32ToFloat64) {
235 Node* value = Parameter(0);
236 Reduction reduction = Reduce(graph()->NewNode(
237 machine()->ChangeFloat64ToUint32(),
238 graph()->NewNode(machine()->ChangeUint32ToFloat64(), value)));
239 ASSERT_TRUE(reduction.Changed());
240 EXPECT_EQ(value, reduction.replacement());
241 }
242
243
244 TEST_F(MachineOperatorReducerTest, ChangeFloat64ToUint32WithConstant) {
245 TRACED_FOREACH(uint32_t, x, kUint32Values) {
246 Reduction reduction = Reduce(graph()->NewNode(
247 machine()->ChangeFloat64ToUint32(), Float64Constant(FastUI2D(x))));
248 ASSERT_TRUE(reduction.Changed());
249 EXPECT_THAT(reduction.replacement(), IsInt32Constant(BitCast<int32_t>(x)));
250 }
251 }
252
253
254 // -----------------------------------------------------------------------------
255 // ChangeInt32ToFloat64
256
257
258 TEST_F(MachineOperatorReducerTest, ChangeInt32ToFloat64WithConstant) {
259 TRACED_FOREACH(int32_t, x, kInt32Values) {
260 Reduction reduction = Reduce(
261 graph()->NewNode(machine()->ChangeInt32ToFloat64(), Int32Constant(x)));
262 ASSERT_TRUE(reduction.Changed());
263 EXPECT_THAT(reduction.replacement(), IsFloat64Constant(FastI2D(x)));
264 }
265 }
266
267
268 // -----------------------------------------------------------------------------
269 // ChangeInt32ToInt64
270
271
272 TEST_F(MachineOperatorReducerTest, ChangeInt32ToInt64WithConstant) {
273 TRACED_FOREACH(int32_t, x, kInt32Values) {
274 Reduction reduction = Reduce(
275 graph()->NewNode(machine()->ChangeInt32ToInt64(), Int32Constant(x)));
276 ASSERT_TRUE(reduction.Changed());
277 EXPECT_THAT(reduction.replacement(), IsInt64Constant(x));
278 }
279 }
280
281
282 // -----------------------------------------------------------------------------
283 // ChangeUint32ToFloat64
284
285
286 TEST_F(MachineOperatorReducerTest, ChangeUint32ToFloat64WithConstant) {
287 TRACED_FOREACH(uint32_t, x, kUint32Values) {
288 Reduction reduction =
289 Reduce(graph()->NewNode(machine()->ChangeUint32ToFloat64(),
290 Int32Constant(BitCast<int32_t>(x))));
291 ASSERT_TRUE(reduction.Changed());
292 EXPECT_THAT(reduction.replacement(), IsFloat64Constant(FastUI2D(x)));
293 }
294 }
295
296
297 // -----------------------------------------------------------------------------
298 // ChangeUint32ToUint64
299
300
301 TEST_F(MachineOperatorReducerTest, ChangeUint32ToUint64WithConstant) {
302 TRACED_FOREACH(uint32_t, x, kUint32Values) {
303 Reduction reduction = Reduce(graph()->NewNode(
304 machine()->ChangeUint32ToUint64(), Int32Constant(BitCast<int32_t>(x))));
305 ASSERT_TRUE(reduction.Changed());
306 EXPECT_THAT(reduction.replacement(),
307 IsInt64Constant(BitCast<int64_t>(static_cast<uint64_t>(x))));
308 }
309 }
310
311
312 // -----------------------------------------------------------------------------
313 // TruncateFloat64ToInt32
314
315
316 TEST_F(MachineOperatorReducerTest,
317 TruncateFloat64ToInt32WithChangeInt32ToFloat64) {
318 Node* value = Parameter(0);
319 Reduction reduction = Reduce(graph()->NewNode(
320 machine()->TruncateFloat64ToInt32(),
321 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value)));
322 ASSERT_TRUE(reduction.Changed());
323 EXPECT_EQ(value, reduction.replacement());
324 }
325
326
327 TEST_F(MachineOperatorReducerTest, TruncateFloat64ToInt32WithConstant) {
328 TRACED_FOREACH(double, x, kFloat64Values) {
329 Reduction reduction = Reduce(graph()->NewNode(
330 machine()->TruncateFloat64ToInt32(), Float64Constant(x)));
331 ASSERT_TRUE(reduction.Changed());
332 EXPECT_THAT(reduction.replacement(), IsInt32Constant(DoubleToInt32(x)));
333 }
334 }
335
336
337 // -----------------------------------------------------------------------------
338 // TruncateInt64ToInt32
339
340
341 TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithChangeInt32ToInt64) {
342 Node* value = Parameter(0);
343 Reduction reduction = Reduce(graph()->NewNode(
344 machine()->TruncateInt64ToInt32(),
345 graph()->NewNode(machine()->ChangeInt32ToInt64(), value)));
346 ASSERT_TRUE(reduction.Changed());
347 EXPECT_EQ(value, reduction.replacement());
348 }
349
350
351 TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithConstant) {
352 TRACED_FOREACH(int64_t, x, kInt64Values) {
353 Reduction reduction = Reduce(
354 graph()->NewNode(machine()->TruncateInt64ToInt32(), Int64Constant(x)));
355 ASSERT_TRUE(reduction.Changed());
356 EXPECT_THAT(reduction.replacement(),
357 IsInt32Constant(BitCast<int32_t>(
358 static_cast<uint32_t>(BitCast<uint64_t>(x)))));
359 }
360 }
361
362
363 // -----------------------------------------------------------------------------
364 // Word32Ror
365
366
47 TEST_F(MachineOperatorReducerTest, ReduceToWord32RorWithParameters) { 367 TEST_F(MachineOperatorReducerTest, ReduceToWord32RorWithParameters) {
48 Node* value = Parameter(0); 368 Node* value = Parameter(0);
49 Node* shift = Parameter(1); 369 Node* shift = Parameter(1);
50 Node* shl = graph()->NewNode(machine()->Word32Shl(), value, shift); 370 Node* shl = graph()->NewNode(machine()->Word32Shl(), value, shift);
51 Node* shr = graph()->NewNode( 371 Node* shr = graph()->NewNode(
52 machine()->Word32Shr(), value, 372 machine()->Word32Shr(), value,
53 graph()->NewNode(machine()->Int32Sub(), Int32Constant(32), shift)); 373 graph()->NewNode(machine()->Int32Sub(), Int32Constant(32), shift));
54 374
55 // (x << y) | (x >> (32 - y)) => x ror y 375 // (x << y) | (x >> (32 - y)) => x ror y
56 Node* node1 = graph()->NewNode(machine()->Word32Or(), shl, shr); 376 Node* node1 = graph()->NewNode(machine()->Word32Or(), shl, shr);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 Node* value = Parameter(0); 419 Node* value = Parameter(0);
100 Node* node = 420 Node* node =
101 graph()->NewNode(machine()->Word32Ror(), value, Int32Constant(0)); 421 graph()->NewNode(machine()->Word32Ror(), value, Int32Constant(0));
102 Reduction reduction = Reduce(node); 422 Reduction reduction = Reduce(node);
103 EXPECT_TRUE(reduction.Changed()); 423 EXPECT_TRUE(reduction.Changed());
104 EXPECT_EQ(reduction.replacement(), value); 424 EXPECT_EQ(reduction.replacement(), value);
105 } 425 }
106 426
107 427
108 TEST_F(MachineOperatorReducerTest, Word32RorWithConstants) { 428 TEST_F(MachineOperatorReducerTest, Word32RorWithConstants) {
109 TRACED_FOREACH(int32_t, x, kConstants) { 429 TRACED_FOREACH(int32_t, x, kUint32Values) {
110 TRACED_FORRANGE(int32_t, y, 0, 31) { 430 TRACED_FORRANGE(int32_t, y, 0, 31) {
111 Node* node = graph()->NewNode(machine()->Word32Ror(), Int32Constant(x), 431 Node* node = graph()->NewNode(machine()->Word32Ror(), Int32Constant(x),
112 Int32Constant(y)); 432 Int32Constant(y));
113 Reduction reduction = Reduce(node); 433 Reduction reduction = Reduce(node);
114 EXPECT_TRUE(reduction.Changed()); 434 EXPECT_TRUE(reduction.Changed());
115 EXPECT_THAT(reduction.replacement(), 435 EXPECT_THAT(reduction.replacement(),
116 IsInt32Constant(base::bits::RotateRight32(x, y))); 436 IsInt32Constant(base::bits::RotateRight32(x, y)));
117 } 437 }
118 } 438 }
119 } 439 }
120 440
121 } // namespace compiler 441 } // namespace compiler
122 } // namespace internal 442 } // namespace internal
123 } // namespace v8 443 } // namespace v8
OLDNEW
« no previous file with comments | « test/compiler-unittests/graph-unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698