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.
5 #include "test/cctest/cctest.h"
7 #include "src/base/utils/random-number-generator.h"
8 #include "src/codegen.h"
9 #include "src/compiler/graph-inl.h"
10 #include "src/compiler/js-graph.h"
11 #include "src/compiler/machine-operator-reducer.h"
12 #include "src/compiler/operator-properties.h"
13 #include "src/compiler/operator-properties-inl.h"
14 #include "src/compiler/typer.h"
15 #include "test/cctest/compiler/value-helper.h"
17 using namespace v8::internal;
18 using namespace v8::internal::compiler;
21 const Operator* NewConstantOperator(CommonOperatorBuilder* common,
25 const Operator* NewConstantOperator<int32_t>(CommonOperatorBuilder* common,
26 volatile int32_t value) {
27 return common->Int32Constant(value);
31 const Operator* NewConstantOperator<double>(CommonOperatorBuilder* common,
32 volatile double value) {
33 return common->Float64Constant(value);
38 T ValueOfOperator(const Operator* op);
41 int32_t ValueOfOperator<int32_t>(const Operator* op) {
42 CHECK_EQ(IrOpcode::kInt32Constant, op->opcode());
43 return OpParameter<int32_t>(op);
47 double ValueOfOperator<double>(const Operator* op) {
48 CHECK_EQ(IrOpcode::kFloat64Constant, op->opcode());
49 return OpParameter<double>(op);
53 class ReducerTester : public HandleAndZoneScope {
55 explicit ReducerTester(int num_parameters = 0)
56 : isolate(main_isolate()),
61 javascript(main_zone()),
62 typer(&graph, MaybeHandle<Context>()),
63 jsgraph(&graph, &common, &javascript, &machine),
64 maxuint32(Constant<int32_t>(kMaxUInt32)) {
65 Node* s = graph.NewNode(common.Start(num_parameters));
70 const Operator* binop;
72 MachineOperatorBuilder machine;
73 CommonOperatorBuilder common;
75 JSOperatorBuilder javascript;
81 Node* Constant(volatile T value) {
82 return graph.NewNode(NewConstantOperator<T>(&common, value));
86 const T ValueOf(const Operator* op) {
87 return ValueOfOperator<T>(op);
90 // Check that the reduction of this binop applied to constants {a} and {b}
91 // yields the {expect} value.
93 void CheckFoldBinop(volatile T expect, volatile T a, volatile T b) {
94 CheckFoldBinop<T>(expect, Constant<T>(a), Constant<T>(b));
97 // Check that the reduction of this binop applied to {a} and {b} yields
98 // the {expect} value.
100 void CheckFoldBinop(volatile T expect, Node* a, Node* b) {
101 CHECK_NE(NULL, binop);
102 Node* n = CreateBinopNode(a, b);
103 MachineOperatorReducer reducer(&jsgraph);
104 Reduction reduction = reducer.Reduce(n);
105 CHECK(reduction.Changed());
106 CHECK_NE(n, reduction.replacement());
107 CHECK_EQ(expect, ValueOf<T>(reduction.replacement()->op()));
110 // Check that the reduction of this binop applied to {a} and {b} yields
111 // the {expect} node.
112 void CheckBinop(Node* expect, Node* a, Node* b) {
113 CHECK_NE(NULL, binop);
114 Node* n = CreateBinopNode(a, b);
115 MachineOperatorReducer reducer(&jsgraph);
116 Reduction reduction = reducer.Reduce(n);
117 CHECK(reduction.Changed());
118 CHECK_EQ(expect, reduction.replacement());
121 // Check that the reduction of this binop applied to {left} and {right} yields
122 // this binop applied to {left_expect} and {right_expect}.
123 void CheckFoldBinop(Node* left_expect, Node* right_expect, Node* left,
125 CHECK_NE(NULL, binop);
126 Node* n = CreateBinopNode(left, right);
127 MachineOperatorReducer reducer(&jsgraph);
128 Reduction reduction = reducer.Reduce(n);
129 CHECK(reduction.Changed());
130 CHECK_EQ(binop, reduction.replacement()->op());
131 CHECK_EQ(left_expect, reduction.replacement()->InputAt(0));
132 CHECK_EQ(right_expect, reduction.replacement()->InputAt(1));
135 // Check that the reduction of this binop applied to {left} and {right} yields
136 // the {op_expect} applied to {left_expect} and {right_expect}.
137 template <typename T>
138 void CheckFoldBinop(volatile T left_expect, const Operator* op_expect,
139 Node* right_expect, Node* left, Node* right) {
140 CHECK_NE(NULL, binop);
141 Node* n = CreateBinopNode(left, right);
142 MachineOperatorReducer reducer(&jsgraph);
143 Reduction r = reducer.Reduce(n);
145 CHECK_EQ(op_expect->opcode(), r.replacement()->op()->opcode());
146 CHECK_EQ(left_expect, ValueOf<T>(r.replacement()->InputAt(0)->op()));
147 CHECK_EQ(right_expect, r.replacement()->InputAt(1));
150 // Check that the reduction of this binop applied to {left} and {right} yields
151 // the {op_expect} applied to {left_expect} and {right_expect}.
152 template <typename T>
153 void CheckFoldBinop(Node* left_expect, const Operator* op_expect,
154 volatile T right_expect, Node* left, Node* right) {
155 CHECK_NE(NULL, binop);
156 Node* n = CreateBinopNode(left, right);
157 MachineOperatorReducer reducer(&jsgraph);
158 Reduction r = reducer.Reduce(n);
160 CHECK_EQ(op_expect->opcode(), r.replacement()->op()->opcode());
161 CHECK_EQ(OperatorProperties::GetTotalInputCount(op_expect),
162 r.replacement()->InputCount());
163 CHECK_EQ(left_expect, r.replacement()->InputAt(0));
164 CHECK_EQ(right_expect, ValueOf<T>(r.replacement()->InputAt(1)->op()));
167 // Check that if the given constant appears on the left, the reducer will
168 // swap it to be on the right.
169 template <typename T>
170 void CheckPutConstantOnRight(volatile T constant) {
171 // TODO(titzer): CHECK(binop->HasProperty(Operator::kCommutative));
172 Node* p = Parameter();
173 Node* k = Constant<T>(constant);
175 Node* n = CreateBinopNode(k, p);
176 MachineOperatorReducer reducer(&jsgraph);
177 Reduction reduction = reducer.Reduce(n);
178 CHECK(!reduction.Changed() || reduction.replacement() == n);
179 CHECK_EQ(p, n->InputAt(0));
180 CHECK_EQ(k, n->InputAt(1));
183 Node* n = CreateBinopNode(p, k);
184 MachineOperatorReducer reducer(&jsgraph);
185 Reduction reduction = reducer.Reduce(n);
186 CHECK(!reduction.Changed());
187 CHECK_EQ(p, n->InputAt(0));
188 CHECK_EQ(k, n->InputAt(1));
192 // Check that if the given constant appears on the left, the reducer will
193 // *NOT* swap it to be on the right.
194 template <typename T>
195 void CheckDontPutConstantOnRight(volatile T constant) {
196 CHECK(!binop->HasProperty(Operator::kCommutative));
197 Node* p = Parameter();
198 Node* k = Constant<T>(constant);
199 Node* n = CreateBinopNode(k, p);
200 MachineOperatorReducer reducer(&jsgraph);
201 Reduction reduction = reducer.Reduce(n);
202 CHECK(!reduction.Changed());
203 CHECK_EQ(k, n->InputAt(0));
204 CHECK_EQ(p, n->InputAt(1));
207 Node* Parameter(int32_t index = 0) {
208 return graph.NewNode(common.Parameter(index), graph.start());
212 Node* CreateBinopNode(Node* left, Node* right) {
213 if (binop->ControlInputCount() > 0) {
214 return graph.NewNode(binop, left, right, graph.start());
216 return graph.NewNode(binop, left, right);
222 TEST(ReduceWord32And) {
224 R.binop = R.machine.Word32And();
226 FOR_INT32_INPUTS(pl) {
227 FOR_INT32_INPUTS(pr) {
228 int32_t x = *pl, y = *pr;
229 R.CheckFoldBinop<int32_t>(x & y, x, y);
233 R.CheckPutConstantOnRight(33);
234 R.CheckPutConstantOnRight(44000);
236 Node* x = R.Parameter();
237 Node* zero = R.Constant<int32_t>(0);
238 Node* minus_1 = R.Constant<int32_t>(-1);
240 R.CheckBinop(zero, x, zero); // x & 0 => 0
241 R.CheckBinop(zero, zero, x); // 0 & x => 0
242 R.CheckBinop(x, x, minus_1); // x & -1 => 0
243 R.CheckBinop(x, minus_1, x); // -1 & x => 0
244 R.CheckBinop(x, x, x); // x & x => x
248 TEST(ReduceWord32Or) {
250 R.binop = R.machine.Word32Or();
252 FOR_INT32_INPUTS(pl) {
253 FOR_INT32_INPUTS(pr) {
254 int32_t x = *pl, y = *pr;
255 R.CheckFoldBinop<int32_t>(x | y, x, y);
259 R.CheckPutConstantOnRight(36);
260 R.CheckPutConstantOnRight(44001);
262 Node* x = R.Parameter();
263 Node* zero = R.Constant<int32_t>(0);
264 Node* minus_1 = R.Constant<int32_t>(-1);
266 R.CheckBinop(x, x, zero); // x & 0 => x
267 R.CheckBinop(x, zero, x); // 0 & x => x
268 R.CheckBinop(minus_1, x, minus_1); // x & -1 => -1
269 R.CheckBinop(minus_1, minus_1, x); // -1 & x => -1
270 R.CheckBinop(x, x, x); // x & x => x
274 TEST(ReduceWord32Xor) {
276 R.binop = R.machine.Word32Xor();
278 FOR_INT32_INPUTS(pl) {
279 FOR_INT32_INPUTS(pr) {
280 int32_t x = *pl, y = *pr;
281 R.CheckFoldBinop<int32_t>(x ^ y, x, y);
285 R.CheckPutConstantOnRight(39);
286 R.CheckPutConstantOnRight(4403);
288 Node* x = R.Parameter();
289 Node* zero = R.Constant<int32_t>(0);
291 R.CheckBinop(x, x, zero); // x ^ 0 => x
292 R.CheckBinop(x, zero, x); // 0 ^ x => x
293 R.CheckFoldBinop<int32_t>(0, x, x); // x ^ x => 0
297 TEST(ReduceWord32Shl) {
299 R.binop = R.machine.Word32Shl();
301 // TODO(titzer): out of range shifts
302 FOR_INT32_INPUTS(i) {
303 for (int y = 0; y < 32; y++) {
305 R.CheckFoldBinop<int32_t>(x << y, x, y);
309 R.CheckDontPutConstantOnRight(44);
311 Node* x = R.Parameter();
312 Node* zero = R.Constant<int32_t>(0);
314 R.CheckBinop(x, x, zero); // x << 0 => x
318 TEST(ReduceWord32Shr) {
320 R.binop = R.machine.Word32Shr();
322 // TODO(titzer): test out of range shifts
323 FOR_UINT32_INPUTS(i) {
324 for (uint32_t y = 0; y < 32; y++) {
326 R.CheckFoldBinop<int32_t>(x >> y, x, y);
330 R.CheckDontPutConstantOnRight(44);
332 Node* x = R.Parameter();
333 Node* zero = R.Constant<int32_t>(0);
335 R.CheckBinop(x, x, zero); // x >>> 0 => x
339 TEST(ReduceWord32Sar) {
341 R.binop = R.machine.Word32Sar();
343 // TODO(titzer): test out of range shifts
344 FOR_INT32_INPUTS(i) {
345 for (int32_t y = 0; y < 32; y++) {
347 R.CheckFoldBinop<int32_t>(x >> y, x, y);
351 R.CheckDontPutConstantOnRight(44);
353 Node* x = R.Parameter();
354 Node* zero = R.Constant<int32_t>(0);
356 R.CheckBinop(x, x, zero); // x >> 0 => x
360 TEST(ReduceWord32Equal) {
362 R.binop = R.machine.Word32Equal();
364 FOR_INT32_INPUTS(pl) {
365 FOR_INT32_INPUTS(pr) {
366 int32_t x = *pl, y = *pr;
367 R.CheckFoldBinop<int32_t>(x == y ? 1 : 0, x, y);
371 R.CheckPutConstantOnRight(48);
372 R.CheckPutConstantOnRight(-48);
374 Node* x = R.Parameter(0);
375 Node* y = R.Parameter(1);
376 Node* zero = R.Constant<int32_t>(0);
377 Node* sub = R.graph.NewNode(R.machine.Int32Sub(), x, y);
379 R.CheckFoldBinop<int32_t>(1, x, x); // x == x => 1
380 R.CheckFoldBinop(x, y, sub, zero); // x - y == 0 => x == y
381 R.CheckFoldBinop(x, y, zero, sub); // 0 == x - y => x == y
385 TEST(ReduceInt32Add) {
387 R.binop = R.machine.Int32Add();
389 FOR_INT32_INPUTS(pl) {
390 FOR_INT32_INPUTS(pr) {
391 int32_t x = *pl, y = *pr;
392 R.CheckFoldBinop<int32_t>(x + y, x, y); // TODO(titzer): signed overflow
396 R.CheckPutConstantOnRight(41);
397 R.CheckPutConstantOnRight(4407);
399 Node* x = R.Parameter();
400 Node* zero = R.Constant<int32_t>(0);
402 R.CheckBinop(x, x, zero); // x + 0 => x
403 R.CheckBinop(x, zero, x); // 0 + x => x
407 TEST(ReduceInt32Sub) {
409 R.binop = R.machine.Int32Sub();
411 FOR_INT32_INPUTS(pl) {
412 FOR_INT32_INPUTS(pr) {
413 int32_t x = *pl, y = *pr;
414 R.CheckFoldBinop<int32_t>(x - y, x, y);
418 R.CheckDontPutConstantOnRight(412);
420 Node* x = R.Parameter();
421 Node* zero = R.Constant<int32_t>(0);
423 R.CheckBinop(x, x, zero); // x - 0 => x
427 TEST(ReduceInt32Mul) {
429 R.binop = R.machine.Int32Mul();
431 FOR_INT32_INPUTS(pl) {
432 FOR_INT32_INPUTS(pr) {
433 int32_t x = *pl, y = *pr;
434 R.CheckFoldBinop<int32_t>(x * y, x, y); // TODO(titzer): signed overflow
438 R.CheckPutConstantOnRight(4111);
439 R.CheckPutConstantOnRight(-4407);
441 Node* x = R.Parameter();
442 Node* zero = R.Constant<int32_t>(0);
443 Node* one = R.Constant<int32_t>(1);
444 Node* minus_one = R.Constant<int32_t>(-1);
446 R.CheckBinop(zero, x, zero); // x * 0 => 0
447 R.CheckBinop(zero, zero, x); // 0 * x => 0
448 R.CheckBinop(x, x, one); // x * 1 => x
449 R.CheckBinop(x, one, x); // 1 * x => x
450 R.CheckFoldBinop<int32_t>(0, R.machine.Int32Sub(), x, minus_one,
451 x); // -1 * x => 0 - x
452 R.CheckFoldBinop<int32_t>(0, R.machine.Int32Sub(), x, x,
453 minus_one); // x * -1 => 0 - x
455 for (int32_t n = 1; n < 31; ++n) {
456 Node* multiplier = R.Constant<int32_t>(1 << n);
457 R.CheckFoldBinop<int32_t>(x, R.machine.Word32Shl(), n, x,
458 multiplier); // x * 2^n => x << n
459 R.CheckFoldBinop<int32_t>(x, R.machine.Word32Shl(), n, multiplier,
460 x); // 2^n * x => x << n
465 TEST(ReduceInt32Div) {
467 R.binop = R.machine.Int32Div();
469 FOR_INT32_INPUTS(pl) {
470 FOR_INT32_INPUTS(pr) {
471 int32_t x = *pl, y = *pr;
472 if (y == 0) continue; // TODO(titzer): test / 0
473 int32_t r = y == -1 ? -x : x / y; // INT_MIN / -1 may explode in C
474 R.CheckFoldBinop<int32_t>(r, x, y);
478 R.CheckDontPutConstantOnRight(41111);
479 R.CheckDontPutConstantOnRight(-44071);
481 Node* x = R.Parameter();
482 Node* one = R.Constant<int32_t>(1);
483 Node* minus_one = R.Constant<int32_t>(-1);
485 R.CheckBinop(x, x, one); // x / 1 => x
486 // TODO(titzer): // 0 / x => 0 if x != 0
487 // TODO(titzer): // x / 2^n => x >> n and round
488 R.CheckFoldBinop<int32_t>(0, R.machine.Int32Sub(), x, x,
489 minus_one); // x / -1 => 0 - x
493 TEST(ReduceUint32Div) {
495 R.binop = R.machine.Uint32Div();
497 FOR_UINT32_INPUTS(pl) {
498 FOR_UINT32_INPUTS(pr) {
499 uint32_t x = *pl, y = *pr;
500 if (y == 0) continue; // TODO(titzer): test / 0
501 R.CheckFoldBinop<int32_t>(x / y, x, y);
505 R.CheckDontPutConstantOnRight(41311);
506 R.CheckDontPutConstantOnRight(-44371);
508 Node* x = R.Parameter();
509 Node* one = R.Constant<int32_t>(1);
511 R.CheckBinop(x, x, one); // x / 1 => x
512 // TODO(titzer): // 0 / x => 0 if x != 0
514 for (uint32_t n = 1; n < 32; ++n) {
515 Node* divisor = R.Constant<int32_t>(1u << n);
516 R.CheckFoldBinop<int32_t>(x, R.machine.Word32Shr(), n, x,
517 divisor); // x / 2^n => x >> n
522 TEST(ReduceInt32Mod) {
524 R.binop = R.machine.Int32Mod();
526 FOR_INT32_INPUTS(pl) {
527 FOR_INT32_INPUTS(pr) {
528 int32_t x = *pl, y = *pr;
529 if (y == 0) continue; // TODO(titzer): test % 0
530 int32_t r = y == -1 ? 0 : x % y; // INT_MIN % -1 may explode in C
531 R.CheckFoldBinop<int32_t>(r, x, y);
535 R.CheckDontPutConstantOnRight(413);
536 R.CheckDontPutConstantOnRight(-4401);
538 Node* x = R.Parameter();
539 Node* one = R.Constant<int32_t>(1);
541 R.CheckFoldBinop<int32_t>(0, x, one); // x % 1 => 0
542 // TODO(titzer): // x % 2^n => x & 2^n-1 and round
546 TEST(ReduceUint32Mod) {
548 R.binop = R.machine.Uint32Mod();
550 FOR_INT32_INPUTS(pl) {
551 FOR_INT32_INPUTS(pr) {
552 uint32_t x = *pl, y = *pr;
553 if (y == 0) continue; // TODO(titzer): test x % 0
554 R.CheckFoldBinop<int32_t>(x % y, x, y);
558 R.CheckDontPutConstantOnRight(417);
559 R.CheckDontPutConstantOnRight(-4371);
561 Node* x = R.Parameter();
562 Node* one = R.Constant<int32_t>(1);
564 R.CheckFoldBinop<int32_t>(0, x, one); // x % 1 => 0
566 for (uint32_t n = 1; n < 32; ++n) {
567 Node* divisor = R.Constant<int32_t>(1u << n);
568 R.CheckFoldBinop<int32_t>(x, R.machine.Word32And(), (1u << n) - 1, x,
569 divisor); // x % 2^n => x & 2^n-1
574 TEST(ReduceInt32LessThan) {
576 R.binop = R.machine.Int32LessThan();
578 FOR_INT32_INPUTS(pl) {
579 FOR_INT32_INPUTS(pr) {
580 int32_t x = *pl, y = *pr;
581 R.CheckFoldBinop<int32_t>(x < y ? 1 : 0, x, y);
585 R.CheckDontPutConstantOnRight(41399);
586 R.CheckDontPutConstantOnRight(-440197);
588 Node* x = R.Parameter(0);
589 Node* y = R.Parameter(1);
590 Node* zero = R.Constant<int32_t>(0);
591 Node* sub = R.graph.NewNode(R.machine.Int32Sub(), x, y);
593 R.CheckFoldBinop<int32_t>(0, x, x); // x < x => 0
594 R.CheckFoldBinop(x, y, sub, zero); // x - y < 0 => x < y
595 R.CheckFoldBinop(y, x, zero, sub); // 0 < x - y => y < x
599 TEST(ReduceInt32LessThanOrEqual) {
601 R.binop = R.machine.Int32LessThanOrEqual();
603 FOR_INT32_INPUTS(pl) {
604 FOR_INT32_INPUTS(pr) {
605 int32_t x = *pl, y = *pr;
606 R.CheckFoldBinop<int32_t>(x <= y ? 1 : 0, x, y);
610 FOR_INT32_INPUTS(i) { R.CheckDontPutConstantOnRight<int32_t>(*i); }
612 Node* x = R.Parameter(0);
613 Node* y = R.Parameter(1);
614 Node* zero = R.Constant<int32_t>(0);
615 Node* sub = R.graph.NewNode(R.machine.Int32Sub(), x, y);
617 R.CheckFoldBinop<int32_t>(1, x, x); // x <= x => 1
618 R.CheckFoldBinop(x, y, sub, zero); // x - y <= 0 => x <= y
619 R.CheckFoldBinop(y, x, zero, sub); // 0 <= x - y => y <= x
623 TEST(ReduceUint32LessThan) {
625 R.binop = R.machine.Uint32LessThan();
627 FOR_UINT32_INPUTS(pl) {
628 FOR_UINT32_INPUTS(pr) {
629 uint32_t x = *pl, y = *pr;
630 R.CheckFoldBinop<int32_t>(x < y ? 1 : 0, x, y);
634 R.CheckDontPutConstantOnRight(41399);
635 R.CheckDontPutConstantOnRight(-440197);
637 Node* x = R.Parameter();
638 Node* max = R.maxuint32;
639 Node* zero = R.Constant<int32_t>(0);
641 R.CheckFoldBinop<int32_t>(0, max, x); // M < x => 0
642 R.CheckFoldBinop<int32_t>(0, x, zero); // x < 0 => 0
643 R.CheckFoldBinop<int32_t>(0, x, x); // x < x => 0
647 TEST(ReduceUint32LessThanOrEqual) {
649 R.binop = R.machine.Uint32LessThanOrEqual();
651 FOR_UINT32_INPUTS(pl) {
652 FOR_UINT32_INPUTS(pr) {
653 uint32_t x = *pl, y = *pr;
654 R.CheckFoldBinop<int32_t>(x <= y ? 1 : 0, x, y);
658 R.CheckDontPutConstantOnRight(41399);
659 R.CheckDontPutConstantOnRight(-440197);
661 Node* x = R.Parameter();
662 Node* max = R.maxuint32;
663 Node* zero = R.Constant<int32_t>(0);
665 R.CheckFoldBinop<int32_t>(1, x, max); // x <= M => 1
666 R.CheckFoldBinop<int32_t>(1, zero, x); // 0 <= x => 1
667 R.CheckFoldBinop<int32_t>(1, x, x); // x <= x => 1
671 TEST(ReduceLoadStore) {
674 Node* base = R.Constant<int32_t>(11);
675 Node* index = R.Constant<int32_t>(4);
676 Node* load = R.graph.NewNode(R.machine.Load(kMachInt32), base, index);
679 MachineOperatorReducer reducer(&R.jsgraph);
680 Reduction reduction = reducer.Reduce(load);
681 CHECK(!reduction.Changed()); // loads should not be reduced.
685 Node* store = R.graph.NewNode(
686 R.machine.Store(StoreRepresentation(kMachInt32, kNoWriteBarrier)), base,
688 MachineOperatorReducer reducer(&R.jsgraph);
689 Reduction reduction = reducer.Reduce(store);
690 CHECK(!reduction.Changed()); // stores should not be reduced.
695 static void CheckNans(ReducerTester* R) {
696 Node* x = R->Parameter();
697 std::vector<double> nans = ValueHelper::nan_vector();
698 for (std::vector<double>::const_iterator pl = nans.begin(); pl != nans.end();
700 for (std::vector<double>::const_iterator pr = nans.begin();
701 pr != nans.end(); ++pr) {
702 Node* nan1 = R->Constant<double>(*pl);
703 Node* nan2 = R->Constant<double>(*pr);
704 R->CheckBinop(nan1, x, nan1); // x op NaN => NaN
705 R->CheckBinop(nan1, nan1, x); // NaN op x => NaN
706 R->CheckBinop(nan1, nan2, nan1); // NaN op NaN => NaN
712 TEST(ReduceFloat64Add) {
714 R.binop = R.machine.Float64Add();
716 FOR_FLOAT64_INPUTS(pl) {
717 FOR_FLOAT64_INPUTS(pr) {
718 double x = *pl, y = *pr;
719 R.CheckFoldBinop<double>(x + y, x, y);
723 FOR_FLOAT64_INPUTS(i) {
725 if (!tmp.IsSpecial() || tmp.IsInfinite()) {
726 // Don't check NaNs as they are reduced more.
727 R.CheckPutConstantOnRight(*i);
735 TEST(ReduceFloat64Sub) {
737 R.binop = R.machine.Float64Sub();
739 FOR_FLOAT64_INPUTS(pl) {
740 FOR_FLOAT64_INPUTS(pr) {
741 double x = *pl, y = *pr;
742 R.CheckFoldBinop<double>(x - y, x, y);
746 Node* zero = R.Constant<double>(0.0);
747 Node* x = R.Parameter();
749 R.CheckBinop(x, x, zero); // x - 0.0 => x
755 TEST(ReduceFloat64Mul) {
757 R.binop = R.machine.Float64Mul();
759 FOR_FLOAT64_INPUTS(pl) {
760 FOR_FLOAT64_INPUTS(pr) {
761 double x = *pl, y = *pr;
762 R.CheckFoldBinop<double>(x * y, x, y);
766 double inf = V8_INFINITY;
767 R.CheckPutConstantOnRight(-inf);
768 R.CheckPutConstantOnRight(-0.1);
769 R.CheckPutConstantOnRight(0.1);
770 R.CheckPutConstantOnRight(inf);
772 Node* x = R.Parameter();
773 Node* one = R.Constant<double>(1.0);
775 R.CheckBinop(x, x, one); // x * 1.0 => x
776 R.CheckBinop(x, one, x); // 1.0 * x => x
782 TEST(ReduceFloat64Div) {
784 R.binop = R.machine.Float64Div();
786 FOR_FLOAT64_INPUTS(pl) {
787 FOR_FLOAT64_INPUTS(pr) {
788 double x = *pl, y = *pr;
789 R.CheckFoldBinop<double>(x / y, x, y);
793 Node* x = R.Parameter();
794 Node* one = R.Constant<double>(1.0);
796 R.CheckBinop(x, x, one); // x / 1.0 => x
802 TEST(ReduceFloat64Mod) {
804 R.binop = R.machine.Float64Mod();
806 FOR_FLOAT64_INPUTS(pl) {
807 FOR_FLOAT64_INPUTS(pr) {
808 double x = *pl, y = *pr;
809 R.CheckFoldBinop<double>(modulo(x, y), x, y);
813 Node* x = R.Parameter();
814 Node* zero = R.Constant<double>(0.0);
816 R.CheckFoldBinop<double>(v8::base::OS::nan_value(), x, zero);
822 // TODO(titzer): test MachineOperatorReducer for Word64And
823 // TODO(titzer): test MachineOperatorReducer for Word64Or
824 // TODO(titzer): test MachineOperatorReducer for Word64Xor
825 // TODO(titzer): test MachineOperatorReducer for Word64Shl
826 // TODO(titzer): test MachineOperatorReducer for Word64Shr
827 // TODO(titzer): test MachineOperatorReducer for Word64Sar
828 // TODO(titzer): test MachineOperatorReducer for Word64Equal
829 // TODO(titzer): test MachineOperatorReducer for Word64Not
830 // TODO(titzer): test MachineOperatorReducer for Int64Add
831 // TODO(titzer): test MachineOperatorReducer for Int64Sub
832 // TODO(titzer): test MachineOperatorReducer for Int64Mul
833 // TODO(titzer): test MachineOperatorReducer for Int64UMul
834 // TODO(titzer): test MachineOperatorReducer for Int64Div
835 // TODO(titzer): test MachineOperatorReducer for Uint64Div
836 // TODO(titzer): test MachineOperatorReducer for Int64Mod
837 // TODO(titzer): test MachineOperatorReducer for Uint64Mod
838 // TODO(titzer): test MachineOperatorReducer for Int64Neg
839 // TODO(titzer): test MachineOperatorReducer for ChangeInt32ToFloat64
840 // TODO(titzer): test MachineOperatorReducer for ChangeFloat64ToInt32
841 // TODO(titzer): test MachineOperatorReducer for Float64Compare