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

Side by Side Diff: test/cctest/compiler/test-phi-reducer.cc

Issue 426233002: Land the Fan (disabled) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback, rebase and "git cl format" 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/cctest/compiler/test-operator.cc ('k') | test/cctest/compiler/test-pipeline.cc » ('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/v8.h"
6 #include "test/cctest/cctest.h"
7
8 #include "src/compiler/common-operator.h"
9 #include "src/compiler/graph-inl.h"
10 #include "src/compiler/phi-reducer.h"
11
12 using namespace v8::internal;
13 using namespace v8::internal::compiler;
14
15 class PhiReducerTester : HandleAndZoneScope {
16 public:
17 PhiReducerTester()
18 : isolate(main_isolate()),
19 common(main_zone()),
20 graph(main_zone()),
21 self(graph.NewNode(common.Start())),
22 dead(graph.NewNode(common.Dead())) {}
23
24 Isolate* isolate;
25 CommonOperatorBuilder common;
26 Graph graph;
27 Node* self;
28 Node* dead;
29
30 void CheckReduce(Node* expect, Node* phi) {
31 PhiReducer reducer;
32 Reduction reduction = reducer.Reduce(phi);
33 if (expect == phi) {
34 CHECK(!reduction.Changed());
35 } else {
36 CHECK(reduction.Changed());
37 CHECK_EQ(expect, reduction.replacement());
38 }
39 }
40
41 Node* Int32Constant(int32_t val) {
42 return graph.NewNode(common.Int32Constant(val));
43 }
44
45 Node* Float64Constant(double val) {
46 return graph.NewNode(common.Float64Constant(val));
47 }
48
49 Node* Parameter(int32_t index = 0) {
50 return graph.NewNode(common.Parameter(index));
51 }
52
53 Node* Phi(Node* a) {
54 return SetSelfReferences(graph.NewNode(common.Phi(1), a));
55 }
56
57 Node* Phi(Node* a, Node* b) {
58 return SetSelfReferences(graph.NewNode(common.Phi(2), a, b));
59 }
60
61 Node* Phi(Node* a, Node* b, Node* c) {
62 return SetSelfReferences(graph.NewNode(common.Phi(3), a, b, c));
63 }
64
65 Node* Phi(Node* a, Node* b, Node* c, Node* d) {
66 return SetSelfReferences(graph.NewNode(common.Phi(4), a, b, c, d));
67 }
68
69 Node* PhiWithControl(Node* a, Node* control) {
70 return SetSelfReferences(graph.NewNode(common.Phi(1), a, control));
71 }
72
73 Node* PhiWithControl(Node* a, Node* b, Node* control) {
74 return SetSelfReferences(graph.NewNode(common.Phi(2), a, b, control));
75 }
76
77 Node* SetSelfReferences(Node* node) {
78 Node::Inputs inputs = node->inputs();
79 for (Node::Inputs::iterator iter(inputs.begin()); iter != inputs.end();
80 ++iter) {
81 Node* input = *iter;
82 if (input == self) node->ReplaceInput(iter.index(), node);
83 }
84 return node;
85 }
86 };
87
88
89 TEST(PhiReduce1) {
90 PhiReducerTester R;
91 Node* zero = R.Int32Constant(0);
92 Node* one = R.Int32Constant(1);
93 Node* oneish = R.Float64Constant(1.1);
94 Node* param = R.Parameter();
95
96 Node* singles[] = {zero, one, oneish, param};
97 for (size_t i = 0; i < ARRAY_SIZE(singles); i++) {
98 R.CheckReduce(singles[i], R.Phi(singles[i]));
99 }
100 }
101
102
103 TEST(PhiReduce2) {
104 PhiReducerTester R;
105 Node* zero = R.Int32Constant(0);
106 Node* one = R.Int32Constant(1);
107 Node* oneish = R.Float64Constant(1.1);
108 Node* param = R.Parameter();
109
110 Node* singles[] = {zero, one, oneish, param};
111 for (size_t i = 0; i < ARRAY_SIZE(singles); i++) {
112 Node* a = singles[i];
113 R.CheckReduce(a, R.Phi(a, a));
114 }
115
116 for (size_t i = 0; i < ARRAY_SIZE(singles); i++) {
117 Node* a = singles[i];
118 R.CheckReduce(a, R.Phi(R.self, a));
119 R.CheckReduce(a, R.Phi(a, R.self));
120 }
121
122 for (size_t i = 1; i < ARRAY_SIZE(singles); i++) {
123 Node* a = singles[i], *b = singles[0];
124 Node* phi1 = R.Phi(b, a);
125 R.CheckReduce(phi1, phi1);
126
127 Node* phi2 = R.Phi(a, b);
128 R.CheckReduce(phi2, phi2);
129 }
130 }
131
132
133 TEST(PhiReduce3) {
134 PhiReducerTester R;
135 Node* zero = R.Int32Constant(0);
136 Node* one = R.Int32Constant(1);
137 Node* oneish = R.Float64Constant(1.1);
138 Node* param = R.Parameter();
139
140 Node* singles[] = {zero, one, oneish, param};
141 for (size_t i = 0; i < ARRAY_SIZE(singles); i++) {
142 Node* a = singles[i];
143 R.CheckReduce(a, R.Phi(a, a, a));
144 }
145
146 for (size_t i = 0; i < ARRAY_SIZE(singles); i++) {
147 Node* a = singles[i];
148 R.CheckReduce(a, R.Phi(R.self, a, a));
149 R.CheckReduce(a, R.Phi(a, R.self, a));
150 R.CheckReduce(a, R.Phi(a, a, R.self));
151 }
152
153 for (size_t i = 1; i < ARRAY_SIZE(singles); i++) {
154 Node* a = singles[i], *b = singles[0];
155 Node* phi1 = R.Phi(b, a, a);
156 R.CheckReduce(phi1, phi1);
157
158 Node* phi2 = R.Phi(a, b, a);
159 R.CheckReduce(phi2, phi2);
160
161 Node* phi3 = R.Phi(a, a, b);
162 R.CheckReduce(phi3, phi3);
163 }
164 }
165
166
167 TEST(PhiReduce4) {
168 PhiReducerTester R;
169 Node* zero = R.Int32Constant(0);
170 Node* one = R.Int32Constant(1);
171 Node* oneish = R.Float64Constant(1.1);
172 Node* param = R.Parameter();
173
174 Node* singles[] = {zero, one, oneish, param};
175 for (size_t i = 0; i < ARRAY_SIZE(singles); i++) {
176 Node* a = singles[i];
177 R.CheckReduce(a, R.Phi(a, a, a, a));
178 }
179
180 for (size_t i = 0; i < ARRAY_SIZE(singles); i++) {
181 Node* a = singles[i];
182 R.CheckReduce(a, R.Phi(R.self, a, a, a));
183 R.CheckReduce(a, R.Phi(a, R.self, a, a));
184 R.CheckReduce(a, R.Phi(a, a, R.self, a));
185 R.CheckReduce(a, R.Phi(a, a, a, R.self));
186
187 R.CheckReduce(a, R.Phi(R.self, R.self, a, a));
188 R.CheckReduce(a, R.Phi(a, R.self, R.self, a));
189 R.CheckReduce(a, R.Phi(a, a, R.self, R.self));
190 R.CheckReduce(a, R.Phi(R.self, a, a, R.self));
191 }
192
193 for (size_t i = 1; i < ARRAY_SIZE(singles); i++) {
194 Node* a = singles[i], *b = singles[0];
195 Node* phi1 = R.Phi(b, a, a, a);
196 R.CheckReduce(phi1, phi1);
197
198 Node* phi2 = R.Phi(a, b, a, a);
199 R.CheckReduce(phi2, phi2);
200
201 Node* phi3 = R.Phi(a, a, b, a);
202 R.CheckReduce(phi3, phi3);
203
204 Node* phi4 = R.Phi(a, a, a, b);
205 R.CheckReduce(phi4, phi4);
206 }
207 }
208
209
210 TEST(PhiReduceShouldIgnoreControlNodes) {
211 PhiReducerTester R;
212 Node* zero = R.Int32Constant(0);
213 Node* one = R.Int32Constant(1);
214 Node* oneish = R.Float64Constant(1.1);
215 Node* param = R.Parameter();
216
217 Node* singles[] = {zero, one, oneish, param};
218 for (size_t i = 0; i < ARRAY_SIZE(singles); ++i) {
219 R.CheckReduce(singles[i], R.PhiWithControl(singles[i], R.dead));
220 R.CheckReduce(singles[i], R.PhiWithControl(R.self, singles[i], R.dead));
221 R.CheckReduce(singles[i], R.PhiWithControl(singles[i], R.self, R.dead));
222 }
223 }
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-operator.cc ('k') | test/cctest/compiler/test-pipeline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698