Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "test/cctest/cctest.h" | 5 #include "test/cctest/cctest.h" |
| 6 | 6 |
| 7 #include "src/base/utils/random-number-generator.h" | 7 #include "src/base/utils/random-number-generator.h" |
| 8 #include "src/compiler/graph-inl.h" | 8 #include "src/compiler/graph-inl.h" |
| 9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
| 10 #include "src/compiler/machine-operator-reducer.h" | 10 #include "src/compiler/machine-operator-reducer.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 CHECK_EQ(op_expect->opcode(), r.replacement()->op()->opcode()); | 157 CHECK_EQ(op_expect->opcode(), r.replacement()->op()->opcode()); |
| 158 CHECK_EQ(left_expect, r.replacement()->InputAt(0)); | 158 CHECK_EQ(left_expect, r.replacement()->InputAt(0)); |
| 159 CHECK_EQ(right_expect, ValueOf<T>(r.replacement()->InputAt(1)->op())); | 159 CHECK_EQ(right_expect, ValueOf<T>(r.replacement()->InputAt(1)->op())); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // Check that if the given constant appears on the left, the reducer will | 162 // Check that if the given constant appears on the left, the reducer will |
| 163 // swap it to be on the right. | 163 // swap it to be on the right. |
| 164 template <typename T> | 164 template <typename T> |
| 165 void CheckPutConstantOnRight(volatile T constant) { | 165 void CheckPutConstantOnRight(volatile T constant) { |
| 166 // TODO(titzer): CHECK(binop->HasProperty(Operator::kCommutative)); | 166 // TODO(titzer): CHECK(binop->HasProperty(Operator::kCommutative)); |
| 167 Double tmp(static_cast<double>(constant)); | |
| 168 if (tmp.IsSpecial() && !tmp.IsInfinite()) { | |
|
titzer
2014/09/25 09:08:41
I would prefer to have this check in the callers.
vincent.belliard
2014/09/25 09:51:18
Done.
| |
| 169 // Don't check NaNs as they are reduced more. | |
| 170 return; | |
| 171 } | |
| 167 Node* p = Parameter(); | 172 Node* p = Parameter(); |
| 168 Node* k = Constant<T>(constant); | 173 Node* k = Constant<T>(constant); |
| 169 { | 174 { |
| 170 Node* n = graph.NewNode(binop, k, p); | 175 Node* n = graph.NewNode(binop, k, p); |
| 171 MachineOperatorReducer reducer(&jsgraph); | 176 MachineOperatorReducer reducer(&jsgraph); |
| 172 Reduction reduction = reducer.Reduce(n); | 177 Reduction reduction = reducer.Reduce(n); |
| 173 CHECK(!reduction.Changed() || reduction.replacement() == n); | 178 CHECK(!reduction.Changed() || reduction.replacement() == n); |
| 174 CHECK_EQ(p, n->InputAt(0)); | 179 CHECK_EQ(p, n->InputAt(0)); |
| 175 CHECK_EQ(k, n->InputAt(1)); | 180 CHECK_EQ(k, n->InputAt(1)); |
| 176 } | 181 } |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 680 | 685 |
| 681 static void CheckNans(ReducerTester* R) { | 686 static void CheckNans(ReducerTester* R) { |
| 682 Node* x = R->Parameter(); | 687 Node* x = R->Parameter(); |
| 683 std::vector<double> nans = ValueHelper::nan_vector(); | 688 std::vector<double> nans = ValueHelper::nan_vector(); |
| 684 for (std::vector<double>::const_iterator pl = nans.begin(); pl != nans.end(); | 689 for (std::vector<double>::const_iterator pl = nans.begin(); pl != nans.end(); |
| 685 ++pl) { | 690 ++pl) { |
| 686 for (std::vector<double>::const_iterator pr = nans.begin(); | 691 for (std::vector<double>::const_iterator pr = nans.begin(); |
| 687 pr != nans.end(); ++pr) { | 692 pr != nans.end(); ++pr) { |
| 688 Node* nan1 = R->Constant<double>(*pl); | 693 Node* nan1 = R->Constant<double>(*pl); |
| 689 Node* nan2 = R->Constant<double>(*pr); | 694 Node* nan2 = R->Constant<double>(*pr); |
| 690 R->CheckBinop(nan1, x, nan1); // x % NaN => NaN | 695 R->CheckBinop(nan1, x, nan1); // x op NaN => NaN |
| 691 R->CheckBinop(nan1, nan1, x); // NaN % x => NaN | 696 R->CheckBinop(nan1, nan1, x); // NaN op x => NaN |
| 692 R->CheckBinop(nan1, nan2, nan1); // NaN % NaN => NaN | 697 R->CheckBinop(nan1, nan2, nan1); // NaN op NaN => NaN |
| 693 } | 698 } |
| 694 } | 699 } |
| 695 } | 700 } |
| 696 | 701 |
| 697 | 702 |
| 698 TEST(ReduceFloat64Add) { | 703 TEST(ReduceFloat64Add) { |
| 699 ReducerTester R; | 704 ReducerTester R; |
| 700 R.binop = R.machine.Float64Add(); | 705 R.binop = R.machine.Float64Add(); |
| 701 | 706 |
| 702 FOR_FLOAT64_INPUTS(pl) { | 707 FOR_FLOAT64_INPUTS(pl) { |
| 703 FOR_FLOAT64_INPUTS(pr) { | 708 FOR_FLOAT64_INPUTS(pr) { |
| 704 double x = *pl, y = *pr; | 709 double x = *pl, y = *pr; |
| 705 R.CheckFoldBinop<double>(x + y, x, y); | 710 R.CheckFoldBinop<double>(x + y, x, y); |
| 706 } | 711 } |
| 707 } | 712 } |
| 708 | 713 |
| 709 FOR_FLOAT64_INPUTS(i) { R.CheckPutConstantOnRight(*i); } | 714 FOR_FLOAT64_INPUTS(i) { R.CheckPutConstantOnRight(*i); } |
| 710 // TODO(titzer): CheckNans(&R); | 715 |
| 716 CheckNans(&R); | |
| 711 } | 717 } |
| 712 | 718 |
| 713 | 719 |
| 714 TEST(ReduceFloat64Sub) { | 720 TEST(ReduceFloat64Sub) { |
| 715 ReducerTester R; | 721 ReducerTester R; |
| 716 R.binop = R.machine.Float64Sub(); | 722 R.binop = R.machine.Float64Sub(); |
| 717 | 723 |
| 718 FOR_FLOAT64_INPUTS(pl) { | 724 FOR_FLOAT64_INPUTS(pl) { |
| 719 FOR_FLOAT64_INPUTS(pr) { | 725 FOR_FLOAT64_INPUTS(pr) { |
| 720 double x = *pl, y = *pr; | 726 double x = *pl, y = *pr; |
| 721 R.CheckFoldBinop<double>(x - y, x, y); | 727 R.CheckFoldBinop<double>(x - y, x, y); |
| 722 } | 728 } |
| 723 } | 729 } |
| 724 // TODO(titzer): CheckNans(&R); | 730 |
| 731 Node* zero = R.Constant<double>(0.0); | |
| 732 Node* x = R.Parameter(); | |
| 733 | |
| 734 R.CheckBinop(x, x, zero); // x - 0.0 => x | |
| 735 | |
| 736 CheckNans(&R); | |
| 725 } | 737 } |
| 726 | 738 |
| 727 | 739 |
| 728 TEST(ReduceFloat64Mul) { | 740 TEST(ReduceFloat64Mul) { |
| 729 ReducerTester R; | 741 ReducerTester R; |
| 730 R.binop = R.machine.Float64Mul(); | 742 R.binop = R.machine.Float64Mul(); |
| 731 | 743 |
| 732 FOR_FLOAT64_INPUTS(pl) { | 744 FOR_FLOAT64_INPUTS(pl) { |
| 733 FOR_FLOAT64_INPUTS(pr) { | 745 FOR_FLOAT64_INPUTS(pr) { |
| 734 double x = *pl, y = *pr; | 746 double x = *pl, y = *pr; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 ReducerTester R; | 788 ReducerTester R; |
| 777 R.binop = R.machine.Float64Mod(); | 789 R.binop = R.machine.Float64Mod(); |
| 778 | 790 |
| 779 FOR_FLOAT64_INPUTS(pl) { | 791 FOR_FLOAT64_INPUTS(pl) { |
| 780 FOR_FLOAT64_INPUTS(pr) { | 792 FOR_FLOAT64_INPUTS(pr) { |
| 781 double x = *pl, y = *pr; | 793 double x = *pl, y = *pr; |
| 782 R.CheckFoldBinop<double>(modulo(x, y), x, y); | 794 R.CheckFoldBinop<double>(modulo(x, y), x, y); |
| 783 } | 795 } |
| 784 } | 796 } |
| 785 | 797 |
| 798 Node* x = R.Parameter(); | |
| 799 Node* zero = R.Constant<double>(0.0); | |
| 800 | |
| 801 R.CheckFoldBinop<double>(v8::base::OS::nan_value(), x, zero); | |
| 802 | |
| 786 CheckNans(&R); | 803 CheckNans(&R); |
| 787 } | 804 } |
| 788 | 805 |
| 789 | 806 |
| 790 // TODO(titzer): test MachineOperatorReducer for Word64And | 807 // TODO(titzer): test MachineOperatorReducer for Word64And |
| 791 // TODO(titzer): test MachineOperatorReducer for Word64Or | 808 // TODO(titzer): test MachineOperatorReducer for Word64Or |
| 792 // TODO(titzer): test MachineOperatorReducer for Word64Xor | 809 // TODO(titzer): test MachineOperatorReducer for Word64Xor |
| 793 // TODO(titzer): test MachineOperatorReducer for Word64Shl | 810 // TODO(titzer): test MachineOperatorReducer for Word64Shl |
| 794 // TODO(titzer): test MachineOperatorReducer for Word64Shr | 811 // TODO(titzer): test MachineOperatorReducer for Word64Shr |
| 795 // TODO(titzer): test MachineOperatorReducer for Word64Sar | 812 // TODO(titzer): test MachineOperatorReducer for Word64Sar |
| 796 // TODO(titzer): test MachineOperatorReducer for Word64Equal | 813 // TODO(titzer): test MachineOperatorReducer for Word64Equal |
| 797 // TODO(titzer): test MachineOperatorReducer for Word64Not | 814 // TODO(titzer): test MachineOperatorReducer for Word64Not |
| 798 // TODO(titzer): test MachineOperatorReducer for Int64Add | 815 // TODO(titzer): test MachineOperatorReducer for Int64Add |
| 799 // TODO(titzer): test MachineOperatorReducer for Int64Sub | 816 // TODO(titzer): test MachineOperatorReducer for Int64Sub |
| 800 // TODO(titzer): test MachineOperatorReducer for Int64Mul | 817 // TODO(titzer): test MachineOperatorReducer for Int64Mul |
| 801 // TODO(titzer): test MachineOperatorReducer for Int64UMul | 818 // TODO(titzer): test MachineOperatorReducer for Int64UMul |
| 802 // TODO(titzer): test MachineOperatorReducer for Int64Div | 819 // TODO(titzer): test MachineOperatorReducer for Int64Div |
| 803 // TODO(titzer): test MachineOperatorReducer for Int64UDiv | 820 // TODO(titzer): test MachineOperatorReducer for Int64UDiv |
| 804 // TODO(titzer): test MachineOperatorReducer for Int64Mod | 821 // TODO(titzer): test MachineOperatorReducer for Int64Mod |
| 805 // TODO(titzer): test MachineOperatorReducer for Int64UMod | 822 // TODO(titzer): test MachineOperatorReducer for Int64UMod |
| 806 // TODO(titzer): test MachineOperatorReducer for Int64Neg | 823 // TODO(titzer): test MachineOperatorReducer for Int64Neg |
| 807 // TODO(titzer): test MachineOperatorReducer for ChangeInt32ToFloat64 | 824 // TODO(titzer): test MachineOperatorReducer for ChangeInt32ToFloat64 |
| 808 // TODO(titzer): test MachineOperatorReducer for ChangeFloat64ToInt32 | 825 // TODO(titzer): test MachineOperatorReducer for ChangeFloat64ToInt32 |
| 809 // TODO(titzer): test MachineOperatorReducer for Float64Compare | 826 // TODO(titzer): test MachineOperatorReducer for Float64Compare |
| OLD | NEW |