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

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

Issue 479793004: [turbofan] Initial import of SimplifiedOperatorReducer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments 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/machine-operator-reducer-unittest.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/compiler/js-graph.h"
6 #include "src/compiler/simplified-operator.h"
7 #include "src/compiler/simplified-operator-reducer.h"
8 #include "src/compiler/typer.h"
9 #include "src/conversions.h"
10 #include "test/compiler-unittests/graph-unittest.h"
11
12 namespace v8 {
13 namespace internal {
14 namespace compiler {
15
16 class SimplifiedOperatorReducerTest : public GraphTest {
17 public:
18 explicit SimplifiedOperatorReducerTest(int num_parameters = 1)
19 : GraphTest(num_parameters), simplified_(zone()) {}
20 virtual ~SimplifiedOperatorReducerTest() {}
21
22 protected:
23 Reduction Reduce(Node* node) {
24 Typer typer(zone());
25 MachineOperatorBuilder machine(zone());
26 JSGraph jsgraph(graph(), common(), &typer);
27 SimplifiedOperatorReducer reducer(&jsgraph, &machine);
28 return reducer.Reduce(node);
29 }
30
31 SimplifiedOperatorBuilder* simplified() { return &simplified_; }
32
33 private:
34 SimplifiedOperatorBuilder simplified_;
35 };
36
37
38 template <typename T>
39 class SimplifiedOperatorReducerTestWithParam
40 : public SimplifiedOperatorReducerTest,
41 public ::testing::WithParamInterface<T> {
42 public:
43 explicit SimplifiedOperatorReducerTestWithParam(int num_parameters = 1)
44 : SimplifiedOperatorReducerTest(num_parameters) {}
45 virtual ~SimplifiedOperatorReducerTestWithParam() {}
46 };
47
48
49 namespace {
50
51 static const double kFloat64Values[] = {
52 -V8_INFINITY, -6.52696e+290, -1.05768e+290, -5.34203e+268, -1.01997e+268,
53 -8.22758e+266, -1.58402e+261, -5.15246e+241, -5.92107e+226, -1.21477e+226,
54 -1.67913e+188, -1.6257e+184, -2.60043e+170, -2.52941e+168, -3.06033e+116,
55 -4.56201e+52, -3.56788e+50, -9.9066e+38, -3.07261e+31, -2.1271e+09,
56 -1.91489e+09, -1.73053e+09, -9.30675e+08, -26030, -20453,
57 -15790, -11699, -111, -97, -78,
58 -63, -58, -1.53858e-06, -2.98914e-12, -1.14741e-39,
59 -8.20347e-57, -1.48932e-59, -3.17692e-66, -8.93103e-81, -3.91337e-83,
60 -6.0489e-92, -8.83291e-113, -4.28266e-117, -1.92058e-178, -2.0567e-192,
61 -1.68167e-194, -1.51841e-214, -3.98738e-234, -7.31851e-242, -2.21875e-253,
62 -1.11612e-293, -0.0, 0.0, 2.22507e-308, 1.06526e-307,
63 4.16643e-227, 6.76624e-223, 2.0432e-197, 3.16254e-184, 1.37315e-173,
64 2.88603e-172, 1.54155e-99, 4.42923e-81, 1.40539e-73, 5.4462e-73,
65 1.24064e-58, 3.11167e-58, 2.75826e-39, 0.143815, 58,
66 67, 601, 7941, 11644, 13697,
67 25680, 29882, 1.32165e+08, 1.62439e+08, 4.16837e+08,
68 9.59097e+08, 1.32491e+09, 1.8728e+09, 1.0672e+17, 2.69606e+46,
69 1.98285e+79, 1.0098e+82, 7.93064e+88, 3.67444e+121, 9.36506e+123,
70 7.27954e+162, 3.05316e+168, 1.16171e+175, 1.64771e+189, 1.1622e+202,
71 2.00748e+239, 2.51778e+244, 3.90282e+306, 1.79769e+308, V8_INFINITY};
72
73
74 static const int32_t kInt32Values[] = {
75 -2147483647 - 1, -2104508227, -2103151830, -1435284490, -1378926425,
76 -1318814539, -1289388009, -1287537572, -1279026536, -1241605942,
77 -1226046939, -941837148, -779818051, -413830641, -245798087,
78 -184657557, -127145950, -105483328, -32325, -26653,
79 -23858, -23834, -22363, -19858, -19044,
80 -18744, -15528, -5309, -3372, -2093,
81 -104, -98, -97, -93, -84,
82 -80, -78, -76, -72, -58,
83 -57, -56, -55, -45, -40,
84 -34, -32, -25, -24, -5,
85 -2, 0, 3, 10, 24,
86 34, 42, 46, 47, 48,
87 52, 56, 64, 65, 71,
88 76, 79, 81, 82, 97,
89 102, 103, 104, 106, 107,
90 109, 116, 122, 3653, 4485,
91 12405, 16504, 26262, 28704, 29755,
92 30554, 16476817, 605431957, 832401070, 873617242,
93 914205764, 1062628108, 1087581664, 1488498068, 1534668023,
94 1661587028, 1696896187, 1866841746, 2032089723, 2147483647};
95
96
97 static const uint32_t kUint32Values[] = {
98 0x0, 0x5, 0x8, 0xc, 0xd, 0x26,
99 0x28, 0x29, 0x30, 0x34, 0x3e, 0x42,
100 0x50, 0x5b, 0x63, 0x71, 0x77, 0x7c,
101 0x83, 0x88, 0x96, 0x9c, 0xa3, 0xfa,
102 0x7a7, 0x165d, 0x234d, 0x3acb, 0x43a5, 0x4573,
103 0x5b4f, 0x5f14, 0x6996, 0x6c6e, 0x7289, 0x7b9a,
104 0x7bc9, 0x86bb, 0xa839, 0xaa41, 0xb03b, 0xc942,
105 0xce68, 0xcf4c, 0xd3ad, 0xdea3, 0xe90c, 0xed86,
106 0xfba5, 0x172dcc6, 0x114d8fc1, 0x182d6c9d, 0x1b1e3fad, 0x1db033bf,
107 0x1e1de755, 0x1f625c80, 0x28f6cf00, 0x2acb6a94, 0x2c20240e, 0x2f0fe54e,
108 0x31863a7c, 0x33325474, 0x3532fae3, 0x3bab82ea, 0x4c4b83a2, 0x4cd93d1e,
109 0x4f7331d4, 0x5491b09b, 0x57cc6ff9, 0x60d3b4dc, 0x653f5904, 0x690ae256,
110 0x69fe3276, 0x6bebf0ba, 0x6e2c69a3, 0x73b84ff7, 0x7b3a1924, 0x7ed032d9,
111 0x84dd734b, 0x8552ea53, 0x8680754f, 0x8e9660eb, 0x94fe2b9c, 0x972d30cf,
112 0x9b98c482, 0xb158667e, 0xb432932c, 0xb5b70989, 0xb669971a, 0xb7c359d1,
113 0xbeb15c0d, 0xc171c53d, 0xc743dd38, 0xc8e2af50, 0xc98e2df0, 0xd9d1cdf9,
114 0xdcc91049, 0xe46f396d, 0xee991950, 0xef64e521, 0xf7aeefc9, 0xffffffff};
115
116
117 MATCHER(IsNaN, std::string(negation ? "isn't" : "is") + " NaN") {
118 return std::isnan(arg);
119 }
120
121 } // namespace
122
123
124 // -----------------------------------------------------------------------------
125 // Unary operators
126
127
128 namespace {
129
130 struct UnaryOperator {
131 Operator* (SimplifiedOperatorBuilder::*constructor)() const;
132 const char* constructor_name;
133 };
134
135
136 std::ostream& operator<<(std::ostream& os, const UnaryOperator& unop) {
137 return os << unop.constructor_name;
138 }
139
140
141 static const UnaryOperator kUnaryOperators[] = {
142 {&SimplifiedOperatorBuilder::BooleanNot, "BooleanNot"},
143 {&SimplifiedOperatorBuilder::ChangeBitToBool, "ChangeBitToBool"},
144 {&SimplifiedOperatorBuilder::ChangeBoolToBit, "ChangeBoolToBit"},
145 {&SimplifiedOperatorBuilder::ChangeFloat64ToTagged,
146 "ChangeFloat64ToTagged"},
147 {&SimplifiedOperatorBuilder::ChangeInt32ToTagged, "ChangeInt32ToTagged"},
148 {&SimplifiedOperatorBuilder::ChangeTaggedToFloat64,
149 "ChangeTaggedToFloat64"},
150 {&SimplifiedOperatorBuilder::ChangeTaggedToInt32, "ChangeTaggedToInt32"},
151 {&SimplifiedOperatorBuilder::ChangeTaggedToUint32, "ChangeTaggedToUint32"},
152 {&SimplifiedOperatorBuilder::ChangeUint32ToTagged, "ChangeUint32ToTagged"}};
153
154 } // namespace
155
156
157 typedef SimplifiedOperatorReducerTestWithParam<UnaryOperator>
158 SimplifiedUnaryOperatorTest;
159
160
161 TEST_P(SimplifiedUnaryOperatorTest, Parameter) {
162 const UnaryOperator& unop = GetParam();
163 Reduction reduction = Reduce(
164 graph()->NewNode((simplified()->*unop.constructor)(), Parameter(0)));
165 EXPECT_FALSE(reduction.Changed());
166 }
167
168
169 INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest, SimplifiedUnaryOperatorTest,
170 ::testing::ValuesIn(kUnaryOperators));
171
172
173 // -----------------------------------------------------------------------------
174 // BooleanNot
175
176
177 TEST_F(SimplifiedOperatorReducerTest, BooleanNotWithBooleanNot) {
178 Node* param0 = Parameter(0);
179 Reduction reduction = Reduce(
180 graph()->NewNode(simplified()->BooleanNot(),
181 graph()->NewNode(simplified()->BooleanNot(), param0)));
182 ASSERT_TRUE(reduction.Changed());
183 EXPECT_EQ(param0, reduction.replacement());
184 }
185
186
187 TEST_F(SimplifiedOperatorReducerTest, BooleanNotWithFalseConstant) {
188 Reduction reduction0 =
189 Reduce(graph()->NewNode(simplified()->BooleanNot(), FalseConstant()));
190 ASSERT_TRUE(reduction0.Changed());
191 EXPECT_THAT(reduction0.replacement(), IsTrueConstant());
192 }
193
194
195 TEST_F(SimplifiedOperatorReducerTest, BooleanNotWithTrueConstant) {
196 Reduction reduction1 =
197 Reduce(graph()->NewNode(simplified()->BooleanNot(), TrueConstant()));
198 ASSERT_TRUE(reduction1.Changed());
199 EXPECT_THAT(reduction1.replacement(), IsFalseConstant());
200 }
201
202
203 // -----------------------------------------------------------------------------
204 // ChangeBoolToBit
205
206
207 TEST_F(SimplifiedOperatorReducerTest, ChangeBitToBoolWithChangeBoolToBit) {
208 Node* param0 = Parameter(0);
209 Reduction reduction = Reduce(graph()->NewNode(
210 simplified()->ChangeBitToBool(),
211 graph()->NewNode(simplified()->ChangeBoolToBit(), param0)));
212 ASSERT_TRUE(reduction.Changed());
213 EXPECT_EQ(param0, reduction.replacement());
214 }
215
216
217 TEST_F(SimplifiedOperatorReducerTest, ChangeBitToBoolWithZeroConstant) {
218 Reduction reduction = Reduce(
219 graph()->NewNode(simplified()->ChangeBitToBool(), Int32Constant(0)));
220 ASSERT_TRUE(reduction.Changed());
221 EXPECT_THAT(reduction.replacement(), IsFalseConstant());
222 }
223
224
225 TEST_F(SimplifiedOperatorReducerTest, ChangeBitToBoolWithOneConstant) {
226 Reduction reduction = Reduce(
227 graph()->NewNode(simplified()->ChangeBitToBool(), Int32Constant(1)));
228 ASSERT_TRUE(reduction.Changed());
229 EXPECT_THAT(reduction.replacement(), IsTrueConstant());
230 }
231
232
233 // -----------------------------------------------------------------------------
234 // ChangeBoolToBit
235
236
237 TEST_F(SimplifiedOperatorReducerTest, ChangeBoolToBitWithFalseConstant) {
238 Reduction reduction = Reduce(
239 graph()->NewNode(simplified()->ChangeBoolToBit(), FalseConstant()));
240 ASSERT_TRUE(reduction.Changed());
241 EXPECT_THAT(reduction.replacement(), IsInt32Constant(0));
242 }
243
244
245 TEST_F(SimplifiedOperatorReducerTest, ChangeBoolToBitWithTrueConstant) {
246 Reduction reduction =
247 Reduce(graph()->NewNode(simplified()->ChangeBoolToBit(), TrueConstant()));
248 ASSERT_TRUE(reduction.Changed());
249 EXPECT_THAT(reduction.replacement(), IsInt32Constant(1));
250 }
251
252
253 TEST_F(SimplifiedOperatorReducerTest, ChangeBoolToBitWithChangeBitToBool) {
254 Node* param0 = Parameter(0);
255 Reduction reduction = Reduce(graph()->NewNode(
256 simplified()->ChangeBoolToBit(),
257 graph()->NewNode(simplified()->ChangeBitToBool(), param0)));
258 ASSERT_TRUE(reduction.Changed());
259 EXPECT_EQ(param0, reduction.replacement());
260 }
261
262
263 // -----------------------------------------------------------------------------
264 // ChangeFloat64ToTagged
265
266
267 TEST_F(SimplifiedOperatorReducerTest, ChangeFloat64ToTaggedWithConstant) {
268 TRACED_FOREACH(double, n, kFloat64Values) {
269 Reduction reduction = Reduce(graph()->NewNode(
270 simplified()->ChangeFloat64ToTagged(), Float64Constant(n)));
271 ASSERT_TRUE(reduction.Changed());
272 EXPECT_THAT(reduction.replacement(), IsNumberConstant(n));
273 }
274 }
275
276
277 // -----------------------------------------------------------------------------
278 // ChangeInt32ToTagged
279
280
281 TEST_F(SimplifiedOperatorReducerTest, ChangeInt32ToTaggedWithConstant) {
282 TRACED_FOREACH(int32_t, n, kInt32Values) {
283 Reduction reduction = Reduce(graph()->NewNode(
284 simplified()->ChangeInt32ToTagged(), Int32Constant(n)));
285 ASSERT_TRUE(reduction.Changed());
286 EXPECT_THAT(reduction.replacement(), IsNumberConstant(FastI2D(n)));
287 }
288 }
289
290
291 // -----------------------------------------------------------------------------
292 // ChangeTaggedToFloat64
293
294
295 TEST_F(SimplifiedOperatorReducerTest,
296 ChangeTaggedToFloat64WithChangeFloat64ToTagged) {
297 Node* param0 = Parameter(0);
298 Reduction reduction = Reduce(graph()->NewNode(
299 simplified()->ChangeTaggedToFloat64(),
300 graph()->NewNode(simplified()->ChangeFloat64ToTagged(), param0)));
301 ASSERT_TRUE(reduction.Changed());
302 EXPECT_EQ(param0, reduction.replacement());
303 }
304
305
306 TEST_F(SimplifiedOperatorReducerTest,
307 ChangeTaggedToFloat64WithChangeInt32ToTagged) {
308 Node* param0 = Parameter(0);
309 Reduction reduction = Reduce(graph()->NewNode(
310 simplified()->ChangeTaggedToFloat64(),
311 graph()->NewNode(simplified()->ChangeInt32ToTagged(), param0)));
312 ASSERT_TRUE(reduction.Changed());
313 EXPECT_THAT(reduction.replacement(), IsChangeInt32ToFloat64(param0));
314 }
315
316
317 TEST_F(SimplifiedOperatorReducerTest,
318 ChangeTaggedToFloat64WithChangeUint32ToTagged) {
319 Node* param0 = Parameter(0);
320 Reduction reduction = Reduce(graph()->NewNode(
321 simplified()->ChangeTaggedToFloat64(),
322 graph()->NewNode(simplified()->ChangeUint32ToTagged(), param0)));
323 ASSERT_TRUE(reduction.Changed());
324 EXPECT_THAT(reduction.replacement(), IsChangeUint32ToFloat64(param0));
325 }
326
327
328 TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToFloat64WithConstant) {
329 TRACED_FOREACH(double, n, kFloat64Values) {
330 Reduction reduction = Reduce(graph()->NewNode(
331 simplified()->ChangeTaggedToFloat64(), NumberConstant(n)));
332 ASSERT_TRUE(reduction.Changed());
333 EXPECT_THAT(reduction.replacement(), IsFloat64Constant(n));
334 }
335 }
336
337
338 TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToFloat64WithNaNConstant1) {
339 Reduction reduction =
340 Reduce(graph()->NewNode(simplified()->ChangeTaggedToFloat64(),
341 NumberConstant(-base::OS::nan_value())));
342 ASSERT_TRUE(reduction.Changed());
343 EXPECT_THAT(reduction.replacement(), IsFloat64Constant(IsNaN()));
344 }
345
346
347 TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToFloat64WithNaNConstant2) {
348 Reduction reduction =
349 Reduce(graph()->NewNode(simplified()->ChangeTaggedToFloat64(),
350 NumberConstant(base::OS::nan_value())));
351 ASSERT_TRUE(reduction.Changed());
352 EXPECT_THAT(reduction.replacement(), IsFloat64Constant(IsNaN()));
353 }
354
355
356 // -----------------------------------------------------------------------------
357 // ChangeTaggedToInt32
358
359
360 TEST_F(SimplifiedOperatorReducerTest,
361 ChangeTaggedToInt32WithChangeFloat64ToTagged) {
362 Node* param0 = Parameter(0);
363 Reduction reduction = Reduce(graph()->NewNode(
364 simplified()->ChangeTaggedToInt32(),
365 graph()->NewNode(simplified()->ChangeFloat64ToTagged(), param0)));
366 ASSERT_TRUE(reduction.Changed());
367 EXPECT_THAT(reduction.replacement(), IsTruncateFloat64ToInt32(param0));
368 }
369
370
371 TEST_F(SimplifiedOperatorReducerTest,
372 ChangeTaggedToInt32WithChangeInt32ToTagged) {
373 Node* param0 = Parameter(0);
374 Reduction reduction = Reduce(graph()->NewNode(
375 simplified()->ChangeTaggedToInt32(),
376 graph()->NewNode(simplified()->ChangeInt32ToTagged(), param0)));
377 ASSERT_TRUE(reduction.Changed());
378 EXPECT_EQ(param0, reduction.replacement());
379 }
380
381
382 TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToInt32WithConstant) {
383 TRACED_FOREACH(double, n, kFloat64Values) {
384 Reduction reduction = Reduce(graph()->NewNode(
385 simplified()->ChangeTaggedToInt32(), NumberConstant(n)));
386 ASSERT_TRUE(reduction.Changed());
387 EXPECT_THAT(reduction.replacement(), IsInt32Constant(DoubleToInt32(n)));
388 }
389 }
390
391
392 TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToInt32WithNaNConstant1) {
393 Reduction reduction =
394 Reduce(graph()->NewNode(simplified()->ChangeTaggedToInt32(),
395 NumberConstant(-base::OS::nan_value())));
396 ASSERT_TRUE(reduction.Changed());
397 EXPECT_THAT(reduction.replacement(), IsInt32Constant(0));
398 }
399
400
401 TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToInt32WithNaNConstant2) {
402 Reduction reduction =
403 Reduce(graph()->NewNode(simplified()->ChangeTaggedToInt32(),
404 NumberConstant(base::OS::nan_value())));
405 ASSERT_TRUE(reduction.Changed());
406 EXPECT_THAT(reduction.replacement(), IsInt32Constant(0));
407 }
408
409
410 // -----------------------------------------------------------------------------
411 // ChangeTaggedToUint32
412
413
414 TEST_F(SimplifiedOperatorReducerTest,
415 ChangeTaggedToUint32WithChangeFloat64ToTagged) {
416 Node* param0 = Parameter(0);
417 Reduction reduction = Reduce(graph()->NewNode(
418 simplified()->ChangeTaggedToUint32(),
419 graph()->NewNode(simplified()->ChangeFloat64ToTagged(), param0)));
420 ASSERT_TRUE(reduction.Changed());
421 EXPECT_THAT(reduction.replacement(), IsTruncateFloat64ToInt32(param0));
422 }
423
424
425 TEST_F(SimplifiedOperatorReducerTest,
426 ChangeTaggedToUint32WithChangeUint32ToTagged) {
427 Node* param0 = Parameter(0);
428 Reduction reduction = Reduce(graph()->NewNode(
429 simplified()->ChangeTaggedToUint32(),
430 graph()->NewNode(simplified()->ChangeUint32ToTagged(), param0)));
431 ASSERT_TRUE(reduction.Changed());
432 EXPECT_EQ(param0, reduction.replacement());
433 }
434
435
436 TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToUint32WithConstant) {
437 TRACED_FOREACH(double, n, kFloat64Values) {
438 Reduction reduction = Reduce(graph()->NewNode(
439 simplified()->ChangeTaggedToUint32(), NumberConstant(n)));
440 ASSERT_TRUE(reduction.Changed());
441 EXPECT_THAT(reduction.replacement(),
442 IsInt32Constant(BitCast<int32_t>(DoubleToUint32(n))));
443 }
444 }
445
446
447 TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToUint32WithNaNConstant1) {
448 Reduction reduction =
449 Reduce(graph()->NewNode(simplified()->ChangeTaggedToUint32(),
450 NumberConstant(-base::OS::nan_value())));
451 ASSERT_TRUE(reduction.Changed());
452 EXPECT_THAT(reduction.replacement(), IsInt32Constant(0));
453 }
454
455
456 TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToUint32WithNaNConstant2) {
457 Reduction reduction =
458 Reduce(graph()->NewNode(simplified()->ChangeTaggedToUint32(),
459 NumberConstant(base::OS::nan_value())));
460 ASSERT_TRUE(reduction.Changed());
461 EXPECT_THAT(reduction.replacement(), IsInt32Constant(0));
462 }
463
464
465 // -----------------------------------------------------------------------------
466 // ChangeUint32ToTagged
467
468
469 TEST_F(SimplifiedOperatorReducerTest, ChangeUint32ToTagged) {
470 TRACED_FOREACH(uint32_t, n, kUint32Values) {
471 Reduction reduction =
472 Reduce(graph()->NewNode(simplified()->ChangeUint32ToTagged(),
473 Int32Constant(BitCast<int32_t>(n))));
474 ASSERT_TRUE(reduction.Changed());
475 EXPECT_THAT(reduction.replacement(), IsNumberConstant(FastUI2D(n)));
476 }
477 }
478
479 } // namespace compiler
480 } // namespace internal
481 } // namespace v8
OLDNEW
« no previous file with comments | « test/compiler-unittests/machine-operator-reducer-unittest.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698