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

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

Issue 998283002: [turbofan] Introduce optional Float64Min and Float64Max machine operators. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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 | « test/cctest/test-disasm-x64.cc ('k') | test/unittests/compiler/machine-operator-unittest.cc » ('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/common-operator.h" 5 #include "src/compiler/common-operator.h"
6 #include "src/compiler/common-operator-reducer.h" 6 #include "src/compiler/common-operator-reducer.h"
7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/js-operator.h"
9 #include "src/compiler/machine-operator.h"
7 #include "src/compiler/machine-type.h" 10 #include "src/compiler/machine-type.h"
8 #include "src/compiler/operator.h" 11 #include "src/compiler/operator.h"
9 #include "test/unittests/compiler/graph-unittest.h" 12 #include "test/unittests/compiler/graph-unittest.h"
13 #include "test/unittests/compiler/node-test-utils.h"
10 14
11 namespace v8 { 15 namespace v8 {
12 namespace internal { 16 namespace internal {
13 namespace compiler { 17 namespace compiler {
14 18
15 class CommonOperatorReducerTest : public GraphTest { 19 class CommonOperatorReducerTest : public GraphTest {
16 public: 20 public:
17 explicit CommonOperatorReducerTest(int num_parameters = 1) 21 explicit CommonOperatorReducerTest(int num_parameters = 1)
18 : GraphTest(num_parameters) {} 22 : GraphTest(num_parameters), machine_(zone()) {}
19 ~CommonOperatorReducerTest() OVERRIDE {} 23 ~CommonOperatorReducerTest() OVERRIDE {}
20 24
21 protected: 25 protected:
22 Reduction Reduce(Node* node) { 26 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags =
23 CommonOperatorReducer reducer; 27 MachineOperatorBuilder::kNoFlags) {
28 JSOperatorBuilder javascript(zone());
29 MachineOperatorBuilder machine(zone(), kMachPtr, flags);
30 JSGraph jsgraph(isolate(), graph(), common(), &javascript, &machine);
31 CommonOperatorReducer reducer(&jsgraph);
24 return reducer.Reduce(node); 32 return reducer.Reduce(node);
25 } 33 }
34
35 MachineOperatorBuilder* machine() { return &machine_; }
36
37 private:
38 MachineOperatorBuilder machine_;
26 }; 39 };
27 40
28 41
29 namespace { 42 namespace {
30 43
31 const BranchHint kBranchHints[] = {BranchHint::kNone, BranchHint::kFalse, 44 const BranchHint kBranchHints[] = {BranchHint::kNone, BranchHint::kFalse,
32 BranchHint::kTrue}; 45 BranchHint::kTrue};
33 46
34 47
35 const MachineType kMachineTypes[] = { 48 const MachineType kMachineTypes[] = {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 84
72 85
73 TEST_F(CommonOperatorReducerTest, RedundantPhi) { 86 TEST_F(CommonOperatorReducerTest, RedundantPhi) {
74 const int kMaxInputs = 64; 87 const int kMaxInputs = 64;
75 Node* inputs[kMaxInputs]; 88 Node* inputs[kMaxInputs];
76 Node* const input = graph()->NewNode(&kOp0); 89 Node* const input = graph()->NewNode(&kOp0);
77 TRACED_FORRANGE(int, input_count, 2, kMaxInputs - 1) { 90 TRACED_FORRANGE(int, input_count, 2, kMaxInputs - 1) {
78 int const value_input_count = input_count - 1; 91 int const value_input_count = input_count - 1;
79 TRACED_FOREACH(MachineType, type, kMachineTypes) { 92 TRACED_FOREACH(MachineType, type, kMachineTypes) {
80 for (int i = 0; i < value_input_count; ++i) { 93 for (int i = 0; i < value_input_count; ++i) {
94 inputs[i] = graph()->start();
95 }
96 Node* merge = graph()->NewNode(common()->Merge(value_input_count),
97 value_input_count, inputs);
98 for (int i = 0; i < value_input_count; ++i) {
81 inputs[i] = input; 99 inputs[i] = input;
82 } 100 }
83 inputs[value_input_count] = graph()->start(); 101 inputs[value_input_count] = merge;
84 Reduction r = Reduce(graph()->NewNode( 102 Reduction r = Reduce(graph()->NewNode(
85 common()->Phi(type, value_input_count), input_count, inputs)); 103 common()->Phi(type, value_input_count), input_count, inputs));
86 ASSERT_TRUE(r.Changed()); 104 ASSERT_TRUE(r.Changed());
87 EXPECT_EQ(input, r.replacement()); 105 EXPECT_EQ(input, r.replacement());
88 } 106 }
89 } 107 }
90 } 108 }
91 109
92 110
111 TEST_F(CommonOperatorReducerTest, PhiToFloat64MaxOrFloat64Min) {
112 Node* p0 = Parameter(0);
113 Node* p1 = Parameter(1);
114 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1);
115 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start());
116 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
117 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
118 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
119 Reduction r1 =
120 Reduce(graph()->NewNode(common()->Phi(kMachFloat64, 2), p1, p0, merge),
121 MachineOperatorBuilder::kFloat64Max);
122 ASSERT_TRUE(r1.Changed());
123 EXPECT_THAT(r1.replacement(), IsFloat64Max(p1, p0));
124 Reduction r2 =
125 Reduce(graph()->NewNode(common()->Phi(kMachFloat64, 2), p0, p1, merge),
126 MachineOperatorBuilder::kFloat64Min);
127 ASSERT_TRUE(r2.Changed());
128 EXPECT_THAT(r2.replacement(), IsFloat64Min(p0, p1));
129 }
130
131
93 // ----------------------------------------------------------------------------- 132 // -----------------------------------------------------------------------------
94 // Select 133 // Select
95 134
96 135
97 TEST_F(CommonOperatorReducerTest, RedundantSelect) { 136 TEST_F(CommonOperatorReducerTest, RedundantSelect) {
98 Node* const input = graph()->NewNode(&kOp0); 137 Node* const input = graph()->NewNode(&kOp0);
99 TRACED_FOREACH(BranchHint, hint, kBranchHints) { 138 TRACED_FOREACH(BranchHint, hint, kBranchHints) {
100 TRACED_FOREACH(MachineType, type, kMachineTypes) { 139 TRACED_FOREACH(MachineType, type, kMachineTypes) {
101 Reduction r = Reduce( 140 Reduction r = Reduce(
102 graph()->NewNode(common()->Select(type, hint), input, input, input)); 141 graph()->NewNode(common()->Select(type, hint), input, input, input));
103 ASSERT_TRUE(r.Changed()); 142 ASSERT_TRUE(r.Changed());
104 EXPECT_EQ(input, r.replacement()); 143 EXPECT_EQ(input, r.replacement());
105 } 144 }
106 } 145 }
107 } 146 }
108 147
148
149 TEST_F(CommonOperatorReducerTest, SelectToFloat64MaxOrFloat64Min) {
150 Node* p0 = Parameter(0);
151 Node* p1 = Parameter(1);
152 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1);
153 Reduction r1 =
154 Reduce(graph()->NewNode(common()->Select(kMachFloat64), check, p1, p0),
155 MachineOperatorBuilder::kFloat64Max);
156 ASSERT_TRUE(r1.Changed());
157 EXPECT_THAT(r1.replacement(), IsFloat64Max(p1, p0));
158 Reduction r2 =
159 Reduce(graph()->NewNode(common()->Select(kMachFloat64), check, p0, p1),
160 MachineOperatorBuilder::kFloat64Min);
161 ASSERT_TRUE(r2.Changed());
162 EXPECT_THAT(r2.replacement(), IsFloat64Min(p0, p1));
163 }
164
109 } // namespace compiler 165 } // namespace compiler
110 } // namespace internal 166 } // namespace internal
111 } // namespace v8 167 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/test-disasm-x64.cc ('k') | test/unittests/compiler/machine-operator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698