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

Side by Side Diff: test/unittests/compiler/js-builtin-reducer-unittest.cc

Issue 2064953004: [turbofan] Unify the PlainPrimitive as Number treatment. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « src/types.h ('k') | test/unittests/compiler/node-test-utils.h » ('j') | 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/compiler/js-builtin-reducer.h" 5 #include "src/compiler/js-builtin-reducer.h"
6 #include "src/compiler/js-graph.h" 6 #include "src/compiler/js-graph.h"
7 #include "src/compiler/node-properties.h" 7 #include "src/compiler/node-properties.h"
8 #include "src/compiler/simplified-operator.h" 8 #include "src/compiler/simplified-operator.h"
9 #include "src/compiler/typer.h" 9 #include "src/compiler/typer.h"
10 #include "src/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 Type* const kNumberTypes[] = { 80 Type* const kNumberTypes[] = {
81 Type::UnsignedSmall(), Type::Negative32(), Type::Unsigned31(), 81 Type::UnsignedSmall(), Type::Negative32(), Type::Unsigned31(),
82 Type::SignedSmall(), Type::Signed32(), Type::Unsigned32(), 82 Type::SignedSmall(), Type::Signed32(), Type::Unsigned32(),
83 Type::Integral32(), Type::MinusZero(), Type::NaN(), 83 Type::Integral32(), Type::MinusZero(), Type::NaN(),
84 Type::OrderedNumber(), Type::PlainNumber(), Type::Number()}; 84 Type::OrderedNumber(), Type::PlainNumber(), Type::Number()};
85 85
86 } // namespace 86 } // namespace
87 87
88 88
89 // ----------------------------------------------------------------------------- 89 // -----------------------------------------------------------------------------
90 // Math.atan
91
92 TEST_F(JSBuiltinReducerTest, MathAtanWithNumber) {
93 Node* function = MathFunction("atan");
94
95 Node* effect = graph()->start();
96 Node* control = graph()->start();
97 Node* context = UndefinedConstant();
98 Node* frame_state = graph()->start();
99 TRACED_FOREACH(Type*, t0, kNumberTypes) {
100 Node* p0 = Parameter(t0, 0);
101 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
102 UndefinedConstant(), p0, context, frame_state,
103 effect, control);
104 Reduction r = Reduce(call);
105
106 ASSERT_TRUE(r.Changed());
107 EXPECT_THAT(r.replacement(), IsNumberAtan(p0));
108 }
109 }
110
111 TEST_F(JSBuiltinReducerTest, MathAtanWithPlainPrimitive) {
112 Node* function = MathFunction("atan");
113
114 Node* effect = graph()->start();
115 Node* control = graph()->start();
116 Node* context = UndefinedConstant();
117 Node* frame_state = graph()->start();
118 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
119 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
120 UndefinedConstant(), p0, context, frame_state,
121 effect, control);
122 Reduction r = Reduce(call);
123
124 ASSERT_TRUE(r.Changed());
125 EXPECT_THAT(r.replacement(), IsNumberAtan(IsPlainPrimitiveToNumber(p0)));
126 }
127
128 // -----------------------------------------------------------------------------
129 // Math.atan2
130
131 TEST_F(JSBuiltinReducerTest, MathAtan2WithNumber) {
132 Node* function = MathFunction("atan2");
133
134 Node* effect = graph()->start();
135 Node* control = graph()->start();
136 Node* context = UndefinedConstant();
137 Node* frame_state = graph()->start();
138 TRACED_FOREACH(Type*, t0, kNumberTypes) {
139 Node* p0 = Parameter(t0, 0);
140 TRACED_FOREACH(Type*, t1, kNumberTypes) {
141 Node* p1 = Parameter(t1, 0);
142 Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
143 UndefinedConstant(), p0, p1, context,
144 frame_state, effect, control);
145 Reduction r = Reduce(call);
146
147 ASSERT_TRUE(r.Changed());
148 EXPECT_THAT(r.replacement(), IsNumberAtan2(p0, p1));
149 }
150 }
151 }
152
153 TEST_F(JSBuiltinReducerTest, MathAtan2WithPlainPrimitive) {
154 Node* function = MathFunction("atan2");
155
156 Node* effect = graph()->start();
157 Node* control = graph()->start();
158 Node* context = UndefinedConstant();
159 Node* frame_state = graph()->start();
160 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
161 Node* p1 = Parameter(Type::PlainPrimitive(), 0);
162 Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
163 UndefinedConstant(), p0, p1, context,
164 frame_state, effect, control);
165 Reduction r = Reduce(call);
166
167 ASSERT_TRUE(r.Changed());
168 EXPECT_THAT(r.replacement(), IsNumberAtan2(IsPlainPrimitiveToNumber(p0),
169 IsPlainPrimitiveToNumber(p1)));
170 }
171
172 // -----------------------------------------------------------------------------
173 // Math.ceil
174
175 TEST_F(JSBuiltinReducerTest, MathCeilWithNumber) {
176 Node* function = MathFunction("ceil");
177
178 Node* effect = graph()->start();
179 Node* control = graph()->start();
180 Node* context = UndefinedConstant();
181 Node* frame_state = graph()->start();
182 TRACED_FOREACH(Type*, t0, kNumberTypes) {
183 Node* p0 = Parameter(t0, 0);
184 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
185 UndefinedConstant(), p0, context, frame_state,
186 effect, control);
187 Reduction r = Reduce(call);
188
189 ASSERT_TRUE(r.Changed());
190 EXPECT_THAT(r.replacement(), IsNumberCeil(p0));
191 }
192 }
193
194 TEST_F(JSBuiltinReducerTest, MathCeilWithPlainPrimitive) {
195 Node* function = MathFunction("ceil");
196
197 Node* effect = graph()->start();
198 Node* control = graph()->start();
199 Node* context = UndefinedConstant();
200 Node* frame_state = graph()->start();
201 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
202 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
203 UndefinedConstant(), p0, context, frame_state,
204 effect, control);
205 Reduction r = Reduce(call);
206
207 ASSERT_TRUE(r.Changed());
208 EXPECT_THAT(r.replacement(), IsNumberCeil(IsPlainPrimitiveToNumber(p0)));
209 }
210
211 // -----------------------------------------------------------------------------
212 // Math.clz32
213
214 TEST_F(JSBuiltinReducerTest, MathClz32WithUnsigned32) {
215 Node* function = MathFunction("clz32");
216
217 Node* effect = graph()->start();
218 Node* control = graph()->start();
219 Node* context = UndefinedConstant();
220 Node* frame_state = graph()->start();
221 Node* p0 = Parameter(Type::Unsigned32(), 0);
222 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
223 UndefinedConstant(), p0, context, frame_state,
224 effect, control);
225 Reduction r = Reduce(call);
226
227 ASSERT_TRUE(r.Changed());
228 EXPECT_THAT(r.replacement(), IsNumberClz32(p0));
229 }
230
231 TEST_F(JSBuiltinReducerTest, MathClz32WithNumber) {
232 Node* function = MathFunction("clz32");
233
234 Node* effect = graph()->start();
235 Node* control = graph()->start();
236 Node* context = UndefinedConstant();
237 Node* frame_state = graph()->start();
238 Node* p0 = Parameter(Type::Number(), 0);
239 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
240 UndefinedConstant(), p0, context, frame_state,
241 effect, control);
242 Reduction r = Reduce(call);
243
244 ASSERT_TRUE(r.Changed());
245 EXPECT_THAT(r.replacement(), IsNumberClz32(IsNumberToUint32(p0)));
246 }
247
248 TEST_F(JSBuiltinReducerTest, MathClz32WithPlainPrimitive) {
249 Node* function = MathFunction("clz32");
250
251 Node* effect = graph()->start();
252 Node* control = graph()->start();
253 Node* context = UndefinedConstant();
254 Node* frame_state = graph()->start();
255 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
256 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
257 UndefinedConstant(), p0, context, frame_state,
258 effect, control);
259 Reduction r = Reduce(call);
260
261 ASSERT_TRUE(r.Changed());
262 EXPECT_THAT(r.replacement(),
263 IsNumberClz32(IsNumberToUint32(IsPlainPrimitiveToNumber(p0))));
264 }
265
266 // -----------------------------------------------------------------------------
267 // Math.floor
268
269 TEST_F(JSBuiltinReducerTest, MathFloorWithNumber) {
270 Node* function = MathFunction("floor");
271
272 Node* effect = graph()->start();
273 Node* control = graph()->start();
274 Node* context = UndefinedConstant();
275 Node* frame_state = graph()->start();
276 TRACED_FOREACH(Type*, t0, kNumberTypes) {
277 Node* p0 = Parameter(t0, 0);
278 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
279 UndefinedConstant(), p0, context, frame_state,
280 effect, control);
281 Reduction r = Reduce(call);
282
283 ASSERT_TRUE(r.Changed());
284 EXPECT_THAT(r.replacement(), IsNumberFloor(p0));
285 }
286 }
287
288 TEST_F(JSBuiltinReducerTest, MathFloorWithPlainPrimitive) {
289 Node* function = MathFunction("floor");
290
291 Node* effect = graph()->start();
292 Node* control = graph()->start();
293 Node* context = UndefinedConstant();
294 Node* frame_state = graph()->start();
295 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
296 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
297 UndefinedConstant(), p0, context, frame_state,
298 effect, control);
299 Reduction r = Reduce(call);
300
301 ASSERT_TRUE(r.Changed());
302 EXPECT_THAT(r.replacement(), IsNumberFloor(IsPlainPrimitiveToNumber(p0)));
303 }
304
305 // -----------------------------------------------------------------------------
306 // Math.fround
307
308 TEST_F(JSBuiltinReducerTest, MathFroundWithNumber) {
309 Node* function = MathFunction("fround");
310
311 Node* effect = graph()->start();
312 Node* control = graph()->start();
313 Node* context = UndefinedConstant();
314 Node* frame_state = graph()->start();
315 TRACED_FOREACH(Type*, t0, kNumberTypes) {
316 Node* p0 = Parameter(t0, 0);
317 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
318 UndefinedConstant(), p0, context, frame_state,
319 effect, control);
320 Reduction r = Reduce(call);
321
322 ASSERT_TRUE(r.Changed());
323 EXPECT_THAT(r.replacement(), IsNumberFround(p0));
324 }
325 }
326
327 TEST_F(JSBuiltinReducerTest, MathFroundWithPlainPrimitive) {
328 Node* function = MathFunction("fround");
329
330 Node* effect = graph()->start();
331 Node* control = graph()->start();
332 Node* context = UndefinedConstant();
333 Node* frame_state = graph()->start();
334 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
335 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
336 UndefinedConstant(), p0, context, frame_state,
337 effect, control);
338 Reduction r = Reduce(call);
339
340 ASSERT_TRUE(r.Changed());
341 EXPECT_THAT(r.replacement(), IsNumberFround(IsPlainPrimitiveToNumber(p0)));
342 }
343
344 // -----------------------------------------------------------------------------
345 // Math.imul
346
347 TEST_F(JSBuiltinReducerTest, MathImulWithUnsigned32) {
348 Node* function = MathFunction("imul");
349
350 Node* effect = graph()->start();
351 Node* control = graph()->start();
352 Node* context = UndefinedConstant();
353 Node* frame_state = graph()->start();
354 Node* p0 = Parameter(Type::Unsigned32(), 0);
355 Node* p1 = Parameter(Type::Unsigned32(), 1);
356 Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
357 UndefinedConstant(), p0, p1, context,
358 frame_state, effect, control);
359 Reduction r = Reduce(call);
360
361 ASSERT_TRUE(r.Changed());
362 EXPECT_THAT(r.replacement(), IsNumberImul(p0, p1));
363 }
364
365 TEST_F(JSBuiltinReducerTest, MathImulWithNumber) {
366 Node* function = MathFunction("imul");
367
368 Node* effect = graph()->start();
369 Node* control = graph()->start();
370 Node* context = UndefinedConstant();
371 Node* frame_state = graph()->start();
372 Node* p0 = Parameter(Type::Number(), 0);
373 Node* p1 = Parameter(Type::Number(), 1);
374 Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
375 UndefinedConstant(), p0, p1, context,
376 frame_state, effect, control);
377 Reduction r = Reduce(call);
378
379 ASSERT_TRUE(r.Changed());
380 EXPECT_THAT(r.replacement(),
381 IsNumberImul(IsNumberToUint32(p0), IsNumberToUint32(p1)));
382 }
383
384 TEST_F(JSBuiltinReducerTest, MathImulWithPlainPrimitive) {
385 Node* function = MathFunction("imul");
386
387 Node* effect = graph()->start();
388 Node* control = graph()->start();
389 Node* context = UndefinedConstant();
390 Node* frame_state = graph()->start();
391 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
392 Node* p1 = Parameter(Type::PlainPrimitive(), 1);
393 Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
394 UndefinedConstant(), p0, p1, context,
395 frame_state, effect, control);
396 Reduction r = Reduce(call);
397
398 ASSERT_TRUE(r.Changed());
399 EXPECT_THAT(r.replacement(),
400 IsNumberImul(IsNumberToUint32(IsPlainPrimitiveToNumber(p0)),
401 IsNumberToUint32(IsPlainPrimitiveToNumber(p1))));
402 }
403
404 // -----------------------------------------------------------------------------
405 // Math.log
406
407 TEST_F(JSBuiltinReducerTest, MathLogWithNumber) {
408 Node* function = MathFunction("log");
409
410 Node* effect = graph()->start();
411 Node* control = graph()->start();
412 Node* context = UndefinedConstant();
413 Node* frame_state = graph()->start();
414 TRACED_FOREACH(Type*, t0, kNumberTypes) {
415 Node* p0 = Parameter(t0, 0);
416 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
417 UndefinedConstant(), p0, context, frame_state,
418 effect, control);
419 Reduction r = Reduce(call);
420
421 ASSERT_TRUE(r.Changed());
422 EXPECT_THAT(r.replacement(), IsNumberLog(p0));
423 }
424 }
425
426 TEST_F(JSBuiltinReducerTest, MathLogWithPlainPrimitive) {
427 Node* function = MathFunction("log");
428
429 Node* effect = graph()->start();
430 Node* control = graph()->start();
431 Node* context = UndefinedConstant();
432 Node* frame_state = graph()->start();
433 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
434 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
435 UndefinedConstant(), p0, context, frame_state,
436 effect, control);
437 Reduction r = Reduce(call);
438
439 ASSERT_TRUE(r.Changed());
440 EXPECT_THAT(r.replacement(), IsNumberLog(IsPlainPrimitiveToNumber(p0)));
441 }
442
443 // -----------------------------------------------------------------------------
444 // Math.log1p
445
446 TEST_F(JSBuiltinReducerTest, MathLog1pWithNumber) {
447 Node* function = MathFunction("log1p");
448
449 Node* effect = graph()->start();
450 Node* control = graph()->start();
451 Node* context = UndefinedConstant();
452 Node* frame_state = graph()->start();
453 TRACED_FOREACH(Type*, t0, kNumberTypes) {
454 Node* p0 = Parameter(t0, 0);
455 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
456 UndefinedConstant(), p0, context, frame_state,
457 effect, control);
458 Reduction r = Reduce(call);
459
460 ASSERT_TRUE(r.Changed());
461 EXPECT_THAT(r.replacement(), IsNumberLog1p(p0));
462 }
463 }
464
465 TEST_F(JSBuiltinReducerTest, MathLog1pWithPlainPrimitive) {
466 Node* function = MathFunction("log1p");
467
468 Node* effect = graph()->start();
469 Node* control = graph()->start();
470 Node* context = UndefinedConstant();
471 Node* frame_state = graph()->start();
472 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
473 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
474 UndefinedConstant(), p0, context, frame_state,
475 effect, control);
476 Reduction r = Reduce(call);
477
478 ASSERT_TRUE(r.Changed());
479 EXPECT_THAT(r.replacement(), IsNumberLog1p(IsPlainPrimitiveToNumber(p0)));
480 }
481
482 // -----------------------------------------------------------------------------
90 // Math.max 483 // Math.max
91 484
92 485 TEST_F(JSBuiltinReducerTest, MathMaxWithNoArguments) {
93 TEST_F(JSBuiltinReducerTest, MathMax0) {
94 Node* function = MathFunction("max"); 486 Node* function = MathFunction("max");
95 487
96 Node* effect = graph()->start(); 488 Node* effect = graph()->start();
97 Node* control = graph()->start(); 489 Node* control = graph()->start();
98 Node* context = UndefinedConstant(); 490 Node* context = UndefinedConstant();
99 Node* frame_state = graph()->start(); 491 Node* frame_state = graph()->start();
100 Node* call = graph()->NewNode(javascript()->CallFunction(2), function, 492 Node* call = graph()->NewNode(javascript()->CallFunction(2), function,
101 UndefinedConstant(), context, frame_state, 493 UndefinedConstant(), context, frame_state,
102 effect, control); 494 effect, control);
103 Reduction r = Reduce(call); 495 Reduction r = Reduce(call);
104 496
105 ASSERT_TRUE(r.Changed()); 497 ASSERT_TRUE(r.Changed());
106 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY)); 498 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY));
107 } 499 }
108 500
109 501 TEST_F(JSBuiltinReducerTest, MathMaxWithNumber) {
110 TEST_F(JSBuiltinReducerTest, MathMax1) {
111 Node* function = MathFunction("max"); 502 Node* function = MathFunction("max");
112 503
113 Node* effect = graph()->start(); 504 Node* effect = graph()->start();
114 Node* control = graph()->start(); 505 Node* control = graph()->start();
115 Node* context = UndefinedConstant(); 506 Node* context = UndefinedConstant();
116 Node* frame_state = graph()->start(); 507 Node* frame_state = graph()->start();
117 TRACED_FOREACH(Type*, t0, kNumberTypes) { 508 TRACED_FOREACH(Type*, t0, kNumberTypes) {
118 Node* p0 = Parameter(t0, 0); 509 Node* p0 = Parameter(t0, 0);
119 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, 510 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
120 UndefinedConstant(), p0, context, frame_state, 511 UndefinedConstant(), p0, context, frame_state,
121 effect, control); 512 effect, control);
122 Reduction r = Reduce(call); 513 Reduction r = Reduce(call);
123 514
124 ASSERT_TRUE(r.Changed()); 515 ASSERT_TRUE(r.Changed());
125 EXPECT_THAT(r.replacement(), p0); 516 EXPECT_THAT(r.replacement(), p0);
126 } 517 }
127 } 518 }
128 519
129 520 TEST_F(JSBuiltinReducerTest, MathMaxWithPlainPrimitive) {
130 TEST_F(JSBuiltinReducerTest, MathMax2) {
131 Node* function = MathFunction("max"); 521 Node* function = MathFunction("max");
132 522
133 Node* effect = graph()->start(); 523 Node* effect = graph()->start();
524 Node* control = graph()->start();
525 Node* context = UndefinedConstant();
526 Node* frame_state = graph()->start();
527 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
528 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
529 UndefinedConstant(), p0, context, frame_state,
530 effect, control);
531 Reduction r = Reduce(call);
532
533 ASSERT_TRUE(r.Changed());
534 EXPECT_THAT(r.replacement(), IsPlainPrimitiveToNumber(p0));
535 }
536
537 TEST_F(JSBuiltinReducerTest, MathMaxWithIntegral32) {
538 Node* function = MathFunction("max");
539
540 Node* effect = graph()->start();
134 Node* control = graph()->start(); 541 Node* control = graph()->start();
135 Node* context = UndefinedConstant(); 542 Node* context = UndefinedConstant();
136 Node* frame_state = graph()->start(); 543 Node* frame_state = graph()->start();
137 TRACED_FOREACH(Type*, t0, kIntegral32Types) { 544 TRACED_FOREACH(Type*, t0, kIntegral32Types) {
138 TRACED_FOREACH(Type*, t1, kIntegral32Types) { 545 TRACED_FOREACH(Type*, t1, kIntegral32Types) {
139 Node* p0 = Parameter(t0, 0); 546 Node* p0 = Parameter(t0, 0);
140 Node* p1 = Parameter(t1, 1); 547 Node* p1 = Parameter(t1, 1);
141 Node* call = graph()->NewNode(javascript()->CallFunction(4), function, 548 Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
142 UndefinedConstant(), p0, p1, context, 549 UndefinedConstant(), p0, p1, context,
143 frame_state, effect, control); 550 frame_state, effect, control);
144 Reduction r = Reduce(call); 551 Reduction r = Reduce(call);
145 552
146 ASSERT_TRUE(r.Changed()); 553 ASSERT_TRUE(r.Changed());
147 EXPECT_THAT(r.replacement(), IsSelect(MachineRepresentation::kNone, 554 EXPECT_THAT(r.replacement(), IsSelect(MachineRepresentation::kNone,
148 IsNumberLessThan(p1, p0), p0, p1)); 555 IsNumberLessThan(p1, p0), p0, p1));
149 } 556 }
150 } 557 }
151 } 558 }
152 559
560 // -----------------------------------------------------------------------------
561 // Math.min
153 562
154 // ----------------------------------------------------------------------------- 563 TEST_F(JSBuiltinReducerTest, MathMinWithNoArguments) {
155 // Math.imul 564 Node* function = MathFunction("min");
156 565
566 Node* effect = graph()->start();
567 Node* control = graph()->start();
568 Node* context = UndefinedConstant();
569 Node* frame_state = graph()->start();
570 Node* call = graph()->NewNode(javascript()->CallFunction(2), function,
571 UndefinedConstant(), context, frame_state,
572 effect, control);
573 Reduction r = Reduce(call);
157 574
158 TEST_F(JSBuiltinReducerTest, MathImul) { 575 ASSERT_TRUE(r.Changed());
159 Node* function = MathFunction("imul"); 576 EXPECT_THAT(r.replacement(), IsNumberConstant(V8_INFINITY));
577 }
578
579 TEST_F(JSBuiltinReducerTest, MathMinWithNumber) {
580 Node* function = MathFunction("min");
160 581
161 Node* effect = graph()->start(); 582 Node* effect = graph()->start();
162 Node* control = graph()->start(); 583 Node* control = graph()->start();
163 Node* context = UndefinedConstant(); 584 Node* context = UndefinedConstant();
164 Node* frame_state = graph()->start(); 585 Node* frame_state = graph()->start();
165 TRACED_FOREACH(Type*, t0, kNumberTypes) { 586 TRACED_FOREACH(Type*, t0, kNumberTypes) {
166 TRACED_FOREACH(Type*, t1, kNumberTypes) { 587 Node* p0 = Parameter(t0, 0);
588 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
589 UndefinedConstant(), p0, context, frame_state,
590 effect, control);
591 Reduction r = Reduce(call);
592
593 ASSERT_TRUE(r.Changed());
594 EXPECT_THAT(r.replacement(), p0);
595 }
596 }
597
598 TEST_F(JSBuiltinReducerTest, MathMinWithPlainPrimitive) {
599 Node* function = MathFunction("min");
600
601 Node* effect = graph()->start();
602 Node* control = graph()->start();
603 Node* context = UndefinedConstant();
604 Node* frame_state = graph()->start();
605 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
606 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
607 UndefinedConstant(), p0, context, frame_state,
608 effect, control);
609 Reduction r = Reduce(call);
610
611 ASSERT_TRUE(r.Changed());
612 EXPECT_THAT(r.replacement(), IsPlainPrimitiveToNumber(p0));
613 }
614
615 TEST_F(JSBuiltinReducerTest, MathMinWithIntegral32) {
616 Node* function = MathFunction("min");
617
618 Node* effect = graph()->start();
619 Node* control = graph()->start();
620 Node* context = UndefinedConstant();
621 Node* frame_state = graph()->start();
622 TRACED_FOREACH(Type*, t0, kIntegral32Types) {
623 TRACED_FOREACH(Type*, t1, kIntegral32Types) {
167 Node* p0 = Parameter(t0, 0); 624 Node* p0 = Parameter(t0, 0);
168 Node* p1 = Parameter(t1, 1); 625 Node* p1 = Parameter(t1, 1);
169 Node* call = graph()->NewNode(javascript()->CallFunction(4), function, 626 Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
170 UndefinedConstant(), p0, p1, context, 627 UndefinedConstant(), p0, p1, context,
171 frame_state, effect, control); 628 frame_state, effect, control);
172 Reduction r = Reduce(call); 629 Reduction r = Reduce(call);
173 630
174 ASSERT_TRUE(r.Changed()); 631 ASSERT_TRUE(r.Changed());
175 EXPECT_THAT(r.replacement(), 632 EXPECT_THAT(r.replacement(), IsSelect(MachineRepresentation::kNone,
176 IsNumberImul(IsNumberToUint32(p0), IsNumberToUint32(p1))); 633 IsNumberLessThan(p1, p0), p1, p0));
177 } 634 }
178 } 635 }
179 } 636 }
180 637
638 // -----------------------------------------------------------------------------
639 // Math.round
181 640
182 // ----------------------------------------------------------------------------- 641 TEST_F(JSBuiltinReducerTest, MathRoundWithNumber) {
183 // Math.fround 642 Node* function = MathFunction("round");
184
185
186 TEST_F(JSBuiltinReducerTest, MathFround) {
187 Node* function = MathFunction("fround");
188 643
189 Node* effect = graph()->start(); 644 Node* effect = graph()->start();
190 Node* control = graph()->start(); 645 Node* control = graph()->start();
191 Node* context = UndefinedConstant(); 646 Node* context = UndefinedConstant();
192 Node* frame_state = graph()->start(); 647 Node* frame_state = graph()->start();
193 TRACED_FOREACH(Type*, t0, kNumberTypes) { 648 TRACED_FOREACH(Type*, t0, kNumberTypes) {
194 Node* p0 = Parameter(t0, 0); 649 Node* p0 = Parameter(t0, 0);
195 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, 650 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
196 UndefinedConstant(), p0, context, frame_state, 651 UndefinedConstant(), p0, context, frame_state,
197 effect, control); 652 effect, control);
198 Reduction r = Reduce(call); 653 Reduction r = Reduce(call);
199 654
200 ASSERT_TRUE(r.Changed()); 655 ASSERT_TRUE(r.Changed());
201 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); 656 EXPECT_THAT(r.replacement(), IsNumberRound(p0));
202 } 657 }
203 } 658 }
204 659
205 // ----------------------------------------------------------------------------- 660 TEST_F(JSBuiltinReducerTest, MathRoundWithPlainPrimitive) {
206 // Math.atan 661 Node* function = MathFunction("round");
207
208 TEST_F(JSBuiltinReducerTest, MathAtan) {
209 Node* function = MathFunction("atan");
210 662
211 Node* effect = graph()->start(); 663 Node* effect = graph()->start();
212 Node* control = graph()->start(); 664 Node* control = graph()->start();
665 Node* context = UndefinedConstant();
666 Node* frame_state = graph()->start();
667 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
668 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
669 UndefinedConstant(), p0, context, frame_state,
670 effect, control);
671 Reduction r = Reduce(call);
672
673 ASSERT_TRUE(r.Changed());
674 EXPECT_THAT(r.replacement(), IsNumberRound(IsPlainPrimitiveToNumber(p0)));
675 }
676
677 // -----------------------------------------------------------------------------
678 // Math.sqrt
679
680 TEST_F(JSBuiltinReducerTest, MathSqrtWithNumber) {
681 Node* function = MathFunction("sqrt");
682
683 Node* effect = graph()->start();
684 Node* control = graph()->start();
213 Node* context = UndefinedConstant(); 685 Node* context = UndefinedConstant();
214 Node* frame_state = graph()->start(); 686 Node* frame_state = graph()->start();
215 TRACED_FOREACH(Type*, t0, kNumberTypes) { 687 TRACED_FOREACH(Type*, t0, kNumberTypes) {
216 Node* p0 = Parameter(t0, 0); 688 Node* p0 = Parameter(t0, 0);
217 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, 689 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
218 UndefinedConstant(), p0, context, frame_state, 690 UndefinedConstant(), p0, context, frame_state,
219 effect, control); 691 effect, control);
220 Reduction r = Reduce(call); 692 Reduction r = Reduce(call);
221 693
222 ASSERT_TRUE(r.Changed()); 694 ASSERT_TRUE(r.Changed());
223 EXPECT_THAT(r.replacement(), IsNumberAtan(p0)); 695 EXPECT_THAT(r.replacement(), IsNumberSqrt(p0));
224 } 696 }
225 } 697 }
226 698
227 // ----------------------------------------------------------------------------- 699 TEST_F(JSBuiltinReducerTest, MathSqrtWithPlainPrimitive) {
228 // Math.atan2 700 Node* function = MathFunction("sqrt");
229
230 TEST_F(JSBuiltinReducerTest, MathAtan2) {
231 Node* function = MathFunction("atan2");
232 701
233 Node* effect = graph()->start(); 702 Node* effect = graph()->start();
234 Node* control = graph()->start(); 703 Node* control = graph()->start();
235 Node* context = UndefinedConstant(); 704 Node* context = UndefinedConstant();
236 Node* frame_state = graph()->start(); 705 Node* frame_state = graph()->start();
237 TRACED_FOREACH(Type*, t0, kNumberTypes) { 706 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
238 Node* p0 = Parameter(t0, 0); 707 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
239 TRACED_FOREACH(Type*, t1, kNumberTypes) { 708 UndefinedConstant(), p0, context, frame_state,
240 Node* p1 = Parameter(t1, 0); 709 effect, control);
241 Node* call = graph()->NewNode(javascript()->CallFunction(4), function, 710 Reduction r = Reduce(call);
242 UndefinedConstant(), p0, p1, context,
243 frame_state, effect, control);
244 Reduction r = Reduce(call);
245 711
246 ASSERT_TRUE(r.Changed()); 712 ASSERT_TRUE(r.Changed());
247 EXPECT_THAT(r.replacement(), IsNumberAtan2(p0, p1)); 713 EXPECT_THAT(r.replacement(), IsNumberSqrt(IsPlainPrimitiveToNumber(p0)));
248 }
249 }
250 } 714 }
251 715
252 // ----------------------------------------------------------------------------- 716 // -----------------------------------------------------------------------------
253 // Math.log 717 // Math.trunc
254 718
255 TEST_F(JSBuiltinReducerTest, MathLog) { 719 TEST_F(JSBuiltinReducerTest, MathTruncWithNumber) {
256 Node* function = MathFunction("log"); 720 Node* function = MathFunction("trunc");
257 721
258 Node* effect = graph()->start(); 722 Node* effect = graph()->start();
259 Node* control = graph()->start(); 723 Node* control = graph()->start();
260 Node* context = UndefinedConstant(); 724 Node* context = UndefinedConstant();
261 Node* frame_state = graph()->start(); 725 Node* frame_state = graph()->start();
262 TRACED_FOREACH(Type*, t0, kNumberTypes) { 726 TRACED_FOREACH(Type*, t0, kNumberTypes) {
263 Node* p0 = Parameter(t0, 0); 727 Node* p0 = Parameter(t0, 0);
264 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, 728 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
265 UndefinedConstant(), p0, context, frame_state, 729 UndefinedConstant(), p0, context, frame_state,
266 effect, control); 730 effect, control);
267 Reduction r = Reduce(call); 731 Reduction r = Reduce(call);
268 732
269 ASSERT_TRUE(r.Changed()); 733 ASSERT_TRUE(r.Changed());
270 EXPECT_THAT(r.replacement(), IsNumberLog(p0)); 734 EXPECT_THAT(r.replacement(), IsNumberTrunc(p0));
271 } 735 }
272 } 736 }
273 737
274 // ----------------------------------------------------------------------------- 738 TEST_F(JSBuiltinReducerTest, MathTruncWithPlainPrimitive) {
275 // Math.log1p 739 Node* function = MathFunction("trunc");
276
277 TEST_F(JSBuiltinReducerTest, MathLog1p) {
278 Node* function = MathFunction("log1p");
279 740
280 Node* effect = graph()->start(); 741 Node* effect = graph()->start();
281 Node* control = graph()->start(); 742 Node* control = graph()->start();
282 Node* context = UndefinedConstant(); 743 Node* context = UndefinedConstant();
283 Node* frame_state = graph()->start(); 744 Node* frame_state = graph()->start();
284 TRACED_FOREACH(Type*, t0, kNumberTypes) { 745 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
285 Node* p0 = Parameter(t0, 0); 746 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
286 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, 747 UndefinedConstant(), p0, context, frame_state,
287 UndefinedConstant(), p0, context, frame_state, 748 effect, control);
288 effect, control); 749 Reduction r = Reduce(call);
289 Reduction r = Reduce(call);
290 750
291 ASSERT_TRUE(r.Changed()); 751 ASSERT_TRUE(r.Changed());
292 EXPECT_THAT(r.replacement(), IsNumberLog1p(p0)); 752 EXPECT_THAT(r.replacement(), IsNumberTrunc(IsPlainPrimitiveToNumber(p0)));
293 }
294 } 753 }
295 754
296 // ----------------------------------------------------------------------------- 755 // -----------------------------------------------------------------------------
297 // String.fromCharCode 756 // String.fromCharCode
298 757
299 TEST_F(JSBuiltinReducerTest, StringFromCharCode) { 758 TEST_F(JSBuiltinReducerTest, StringFromCharCodeWithNumber) {
300 Node* function = StringFunction("fromCharCode"); 759 Node* function = StringFunction("fromCharCode");
301 760
302 Node* effect = graph()->start(); 761 Node* effect = graph()->start();
303 Node* control = graph()->start(); 762 Node* control = graph()->start();
304 Node* context = UndefinedConstant(); 763 Node* context = UndefinedConstant();
305 Node* frame_state = graph()->start(); 764 Node* frame_state = graph()->start();
306 TRACED_FOREACH(Type*, t0, kNumberTypes) { 765 TRACED_FOREACH(Type*, t0, kNumberTypes) {
307 Node* p0 = Parameter(t0, 0); 766 Node* p0 = Parameter(t0, 0);
308 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, 767 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
309 UndefinedConstant(), p0, context, frame_state, 768 UndefinedConstant(), p0, context, frame_state,
310 effect, control); 769 effect, control);
311 Reduction r = Reduce(call); 770 Reduction r = Reduce(call);
312 771
313 ASSERT_TRUE(r.Changed()); 772 ASSERT_TRUE(r.Changed());
314 EXPECT_THAT(r.replacement(), IsStringFromCharCode(p0)); 773 EXPECT_THAT(r.replacement(), IsStringFromCharCode(p0));
315 } 774 }
316 } 775 }
317 776
777 TEST_F(JSBuiltinReducerTest, StringFromCharCodeWithPlainPrimitive) {
778 Node* function = StringFunction("fromCharCode");
779
780 Node* effect = graph()->start();
781 Node* control = graph()->start();
782 Node* context = UndefinedConstant();
783 Node* frame_state = graph()->start();
784 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
785 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
786 UndefinedConstant(), p0, context, frame_state,
787 effect, control);
788 Reduction r = Reduce(call);
789
790 ASSERT_TRUE(r.Changed());
791 EXPECT_THAT(r.replacement(),
792 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0)));
793 }
794
318 } // namespace compiler 795 } // namespace compiler
319 } // namespace internal 796 } // namespace internal
320 } // namespace v8 797 } // namespace v8
OLDNEW
« no previous file with comments | « src/types.h ('k') | test/unittests/compiler/node-test-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698