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 "src/compiler/common-operator.h"
6 #include "src/compiler/graph.h"
7 #include "src/compiler/machine-operator.h"
8 #include "src/compiler/node.h"
9 #include "src/compiler/node-matchers.h"
10 #include "src/compiler/opcodes.h"
12 #include "test/unittests/compiler/graph-unittest.h"
13 #include "test/unittests/test-utils.h"
19 class NodeMatcherTest : public GraphTest {
21 NodeMatcherTest() : machine_(zone()) {}
22 ~NodeMatcherTest() override {}
24 MachineOperatorBuilder* machine() { return &machine_; }
27 MachineOperatorBuilder machine_;
32 template <class Matcher>
33 void CheckBaseWithIndexAndDisplacement(Matcher* matcher, Node* index, int scale,
34 Node* base, Node* displacement) {
35 EXPECT_TRUE(matcher->matches());
36 EXPECT_EQ(index, matcher->index());
37 EXPECT_EQ(scale, matcher->scale());
38 EXPECT_EQ(base, matcher->base());
39 EXPECT_EQ(displacement, matcher->displacement());
44 TEST_F(NodeMatcherTest, ScaledWithOffset32Matcher) {
45 graph()->SetStart(graph()->NewNode(common()->Start(0)));
47 const Operator* d0_op = common()->Int32Constant(0);
48 Node* d0 = graph()->NewNode(d0_op);
50 const Operator* d1_op = common()->Int32Constant(1);
51 Node* d1 = graph()->NewNode(d1_op);
53 const Operator* d2_op = common()->Int32Constant(2);
54 Node* d2 = graph()->NewNode(d2_op);
56 const Operator* d3_op = common()->Int32Constant(3);
57 Node* d3 = graph()->NewNode(d3_op);
59 const Operator* d4_op = common()->Int32Constant(4);
60 Node* d4 = graph()->NewNode(d4_op);
62 const Operator* d5_op = common()->Int32Constant(5);
63 Node* d5 = graph()->NewNode(d5_op);
65 const Operator* d7_op = common()->Int32Constant(7);
66 Node* d7 = graph()->NewNode(d7_op);
68 const Operator* d8_op = common()->Int32Constant(8);
69 Node* d8 = graph()->NewNode(d8_op);
71 const Operator* d9_op = common()->Int32Constant(9);
72 Node* d9 = graph()->NewNode(d9_op);
74 const Operator* d15_op = common()->Int32Constant(15);
75 Node* d15 = graph()->NewNode(d15_op);
78 const Operator* b0_op = common()->Parameter(0);
79 Node* b0 = graph()->NewNode(b0_op, graph()->start());
81 const Operator* b1_op = common()->Parameter(1);
82 Node* b1 = graph()->NewNode(b1_op, graph()->start());
85 const Operator* p1_op = common()->Parameter(3);
86 Node* p1 = graph()->NewNode(p1_op, graph()->start());
89 const Operator* a_op = machine()->Int32Add();
92 const Operator* m_op = machine()->Int32Mul();
93 Node* m1 = graph()->NewNode(m_op, p1, d1);
94 Node* m2 = graph()->NewNode(m_op, p1, d2);
95 Node* m3 = graph()->NewNode(m_op, p1, d3);
96 Node* m4 = graph()->NewNode(m_op, p1, d4);
97 Node* m5 = graph()->NewNode(m_op, p1, d5);
98 Node* m7 = graph()->NewNode(m_op, p1, d7);
99 Node* m8 = graph()->NewNode(m_op, p1, d8);
100 Node* m9 = graph()->NewNode(m_op, p1, d9);
110 const Operator* s_op = machine()->Word32Shl();
111 Node* s0 = graph()->NewNode(s_op, p1, d0);
112 Node* s1 = graph()->NewNode(s_op, p1, d1);
113 Node* s2 = graph()->NewNode(s_op, p1, d2);
114 Node* s3 = graph()->NewNode(s_op, p1, d3);
115 Node* s4 = graph()->NewNode(s_op, p1, d4);
124 // Only relevant test dases is Checking for non-match.
125 BaseWithIndexAndDisplacement32Matcher match0(d15);
126 EXPECT_FALSE(match0.matches());
130 // (B0 + B1) -> [B0, 0, B1, NULL]
131 BaseWithIndexAndDisplacement32Matcher match1(graph()->NewNode(a_op, b0, b1));
132 CheckBaseWithIndexAndDisplacement(&match1, b1, 0, b0, NULL);
134 // (B0 + D15) -> [NULL, 0, B0, D15]
135 BaseWithIndexAndDisplacement32Matcher match2(graph()->NewNode(a_op, b0, d15));
136 CheckBaseWithIndexAndDisplacement(&match2, NULL, 0, b0, d15);
138 // (D15 + B0) -> [NULL, 0, B0, D15]
139 BaseWithIndexAndDisplacement32Matcher match3(graph()->NewNode(a_op, d15, b0));
140 CheckBaseWithIndexAndDisplacement(&match3, NULL, 0, b0, d15);
142 // (B0 + M1) -> [p1, 0, B0, NULL]
143 BaseWithIndexAndDisplacement32Matcher match4(graph()->NewNode(a_op, b0, m1));
144 CheckBaseWithIndexAndDisplacement(&match4, p1, 0, b0, NULL);
146 // (M1 + B0) -> [p1, 0, B0, NULL]
147 m1 = graph()->NewNode(m_op, p1, d1);
148 BaseWithIndexAndDisplacement32Matcher match5(graph()->NewNode(a_op, m1, b0));
149 CheckBaseWithIndexAndDisplacement(&match5, p1, 0, b0, NULL);
151 // (D15 + M1) -> [P1, 0, NULL, D15]
152 m1 = graph()->NewNode(m_op, p1, d1);
153 BaseWithIndexAndDisplacement32Matcher match6(graph()->NewNode(a_op, d15, m1));
154 CheckBaseWithIndexAndDisplacement(&match6, p1, 0, NULL, d15);
156 // (M1 + D15) -> [P1, 0, NULL, D15]
157 m1 = graph()->NewNode(m_op, p1, d1);
158 BaseWithIndexAndDisplacement32Matcher match7(graph()->NewNode(a_op, m1, d15));
159 CheckBaseWithIndexAndDisplacement(&match7, p1, 0, NULL, d15);
161 // (B0 + S0) -> [p1, 0, B0, NULL]
162 BaseWithIndexAndDisplacement32Matcher match8(graph()->NewNode(a_op, b0, s0));
163 CheckBaseWithIndexAndDisplacement(&match8, p1, 0, b0, NULL);
165 // (S0 + B0) -> [p1, 0, B0, NULL]
166 s0 = graph()->NewNode(s_op, p1, d0);
167 BaseWithIndexAndDisplacement32Matcher match9(graph()->NewNode(a_op, s0, b0));
168 CheckBaseWithIndexAndDisplacement(&match9, p1, 0, b0, NULL);
170 // (D15 + S0) -> [P1, 0, NULL, D15]
171 s0 = graph()->NewNode(s_op, p1, d0);
172 BaseWithIndexAndDisplacement32Matcher match10(
173 graph()->NewNode(a_op, d15, s0));
174 CheckBaseWithIndexAndDisplacement(&match10, p1, 0, NULL, d15);
176 // (S0 + D15) -> [P1, 0, NULL, D15]
177 s0 = graph()->NewNode(s_op, p1, d0);
178 BaseWithIndexAndDisplacement32Matcher match11(
179 graph()->NewNode(a_op, s0, d15));
180 CheckBaseWithIndexAndDisplacement(&match11, p1, 0, NULL, d15);
182 // (B0 + M2) -> [p1, 1, B0, NULL]
183 BaseWithIndexAndDisplacement32Matcher match12(graph()->NewNode(a_op, b0, m2));
184 CheckBaseWithIndexAndDisplacement(&match12, p1, 1, b0, NULL);
186 // (M2 + B0) -> [p1, 1, B0, NULL]
187 m2 = graph()->NewNode(m_op, p1, d2);
188 BaseWithIndexAndDisplacement32Matcher match13(graph()->NewNode(a_op, m2, b0));
189 CheckBaseWithIndexAndDisplacement(&match13, p1, 1, b0, NULL);
191 // (D15 + M2) -> [P1, 1, NULL, D15]
192 m2 = graph()->NewNode(m_op, p1, d2);
193 BaseWithIndexAndDisplacement32Matcher match14(
194 graph()->NewNode(a_op, d15, m2));
195 CheckBaseWithIndexAndDisplacement(&match14, p1, 1, NULL, d15);
197 // (M2 + D15) -> [P1, 1, NULL, D15]
198 m2 = graph()->NewNode(m_op, p1, d2);
199 BaseWithIndexAndDisplacement32Matcher match15(
200 graph()->NewNode(a_op, m2, d15));
201 CheckBaseWithIndexAndDisplacement(&match15, p1, 1, NULL, d15);
203 // (B0 + S1) -> [p1, 1, B0, NULL]
204 BaseWithIndexAndDisplacement32Matcher match16(graph()->NewNode(a_op, b0, s1));
205 CheckBaseWithIndexAndDisplacement(&match16, p1, 1, b0, NULL);
207 // (S1 + B0) -> [p1, 1, B0, NULL]
208 s1 = graph()->NewNode(s_op, p1, d1);
209 BaseWithIndexAndDisplacement32Matcher match17(graph()->NewNode(a_op, s1, b0));
210 CheckBaseWithIndexAndDisplacement(&match17, p1, 1, b0, NULL);
212 // (D15 + S1) -> [P1, 1, NULL, D15]
213 s1 = graph()->NewNode(s_op, p1, d1);
214 BaseWithIndexAndDisplacement32Matcher match18(
215 graph()->NewNode(a_op, d15, s1));
216 CheckBaseWithIndexAndDisplacement(&match18, p1, 1, NULL, d15);
218 // (S1 + D15) -> [P1, 1, NULL, D15]
219 s1 = graph()->NewNode(s_op, p1, d1);
220 BaseWithIndexAndDisplacement32Matcher match19(
221 graph()->NewNode(a_op, s1, d15));
222 CheckBaseWithIndexAndDisplacement(&match19, p1, 1, NULL, d15);
224 // (B0 + M4) -> [p1, 2, B0, NULL]
225 BaseWithIndexAndDisplacement32Matcher match20(graph()->NewNode(a_op, b0, m4));
226 CheckBaseWithIndexAndDisplacement(&match20, p1, 2, b0, NULL);
228 // (M4 + B0) -> [p1, 2, B0, NULL]
229 m4 = graph()->NewNode(m_op, p1, d4);
230 BaseWithIndexAndDisplacement32Matcher match21(graph()->NewNode(a_op, m4, b0));
231 CheckBaseWithIndexAndDisplacement(&match21, p1, 2, b0, NULL);
233 // (D15 + M4) -> [p1, 2, NULL, D15]
234 m4 = graph()->NewNode(m_op, p1, d4);
235 BaseWithIndexAndDisplacement32Matcher match22(
236 graph()->NewNode(a_op, d15, m4));
237 CheckBaseWithIndexAndDisplacement(&match22, p1, 2, NULL, d15);
239 // (M4 + D15) -> [p1, 2, NULL, D15]
240 m4 = graph()->NewNode(m_op, p1, d4);
241 BaseWithIndexAndDisplacement32Matcher match23(
242 graph()->NewNode(a_op, m4, d15));
243 CheckBaseWithIndexAndDisplacement(&match23, p1, 2, NULL, d15);
245 // (B0 + S2) -> [p1, 2, B0, NULL]
246 BaseWithIndexAndDisplacement32Matcher match24(graph()->NewNode(a_op, b0, s2));
247 CheckBaseWithIndexAndDisplacement(&match24, p1, 2, b0, NULL);
249 // (S2 + B0) -> [p1, 2, B0, NULL]
250 s2 = graph()->NewNode(s_op, p1, d2);
251 BaseWithIndexAndDisplacement32Matcher match25(graph()->NewNode(a_op, s2, b0));
252 CheckBaseWithIndexAndDisplacement(&match25, p1, 2, b0, NULL);
254 // (D15 + S2) -> [p1, 2, NULL, D15]
255 s2 = graph()->NewNode(s_op, p1, d2);
256 BaseWithIndexAndDisplacement32Matcher match26(
257 graph()->NewNode(a_op, d15, s2));
258 CheckBaseWithIndexAndDisplacement(&match26, p1, 2, NULL, d15);
260 // (S2 + D15) -> [p1, 2, NULL, D15]
261 s2 = graph()->NewNode(s_op, p1, d2);
262 BaseWithIndexAndDisplacement32Matcher match27(
263 graph()->NewNode(a_op, s2, d15));
264 CheckBaseWithIndexAndDisplacement(&match27, p1, 2, NULL, d15);
266 // (B0 + M8) -> [p1, 2, B0, NULL]
267 BaseWithIndexAndDisplacement32Matcher match28(graph()->NewNode(a_op, b0, m8));
268 CheckBaseWithIndexAndDisplacement(&match28, p1, 3, b0, NULL);
270 // (M8 + B0) -> [p1, 2, B0, NULL]
271 m8 = graph()->NewNode(m_op, p1, d8);
272 BaseWithIndexAndDisplacement32Matcher match29(graph()->NewNode(a_op, m8, b0));
273 CheckBaseWithIndexAndDisplacement(&match29, p1, 3, b0, NULL);
275 // (D15 + M8) -> [p1, 2, NULL, D15]
276 m8 = graph()->NewNode(m_op, p1, d8);
277 BaseWithIndexAndDisplacement32Matcher match30(
278 graph()->NewNode(a_op, d15, m8));
279 CheckBaseWithIndexAndDisplacement(&match30, p1, 3, NULL, d15);
281 // (M8 + D15) -> [p1, 2, NULL, D15]
282 m8 = graph()->NewNode(m_op, p1, d8);
283 BaseWithIndexAndDisplacement32Matcher match31(
284 graph()->NewNode(a_op, m8, d15));
285 CheckBaseWithIndexAndDisplacement(&match31, p1, 3, NULL, d15);
287 // (B0 + S3) -> [p1, 2, B0, NULL]
288 BaseWithIndexAndDisplacement32Matcher match32(graph()->NewNode(a_op, b0, s3));
289 CheckBaseWithIndexAndDisplacement(&match32, p1, 3, b0, NULL);
291 // (S3 + B0) -> [p1, 2, B0, NULL]
292 s3 = graph()->NewNode(s_op, p1, d3);
293 BaseWithIndexAndDisplacement32Matcher match33(graph()->NewNode(a_op, s3, b0));
294 CheckBaseWithIndexAndDisplacement(&match33, p1, 3, b0, NULL);
296 // (D15 + S3) -> [p1, 2, NULL, D15]
297 s3 = graph()->NewNode(s_op, p1, d3);
298 BaseWithIndexAndDisplacement32Matcher match34(
299 graph()->NewNode(a_op, d15, s3));
300 CheckBaseWithIndexAndDisplacement(&match34, p1, 3, NULL, d15);
302 // (S3 + D15) -> [p1, 2, NULL, D15]
303 s3 = graph()->NewNode(s_op, p1, d3);
304 BaseWithIndexAndDisplacement32Matcher match35(
305 graph()->NewNode(a_op, s3, d15));
306 CheckBaseWithIndexAndDisplacement(&match35, p1, 3, NULL, d15);
308 // 2 INPUT - NEGATIVE CASES
310 // (M3 + B1) -> [B0, 0, M3, NULL]
311 BaseWithIndexAndDisplacement32Matcher match36(graph()->NewNode(a_op, b1, m3));
312 CheckBaseWithIndexAndDisplacement(&match36, m3, 0, b1, NULL);
314 // (S4 + B1) -> [B0, 0, S4, NULL]
315 BaseWithIndexAndDisplacement32Matcher match37(graph()->NewNode(a_op, b1, s4));
316 CheckBaseWithIndexAndDisplacement(&match37, s4, 0, b1, NULL);
320 // (D15 + S3) + B0 -> [p1, 2, b0, d15]
321 s3 = graph()->NewNode(s_op, p1, d3);
322 BaseWithIndexAndDisplacement32Matcher match38(
323 graph()->NewNode(a_op, graph()->NewNode(a_op, d15, s3), b0));
324 CheckBaseWithIndexAndDisplacement(&match38, p1, 3, b0, d15);
326 // (B0 + D15) + S3 -> [p1, 2, b0, d15]
327 s3 = graph()->NewNode(s_op, p1, d3);
328 BaseWithIndexAndDisplacement32Matcher match39(
329 graph()->NewNode(a_op, graph()->NewNode(a_op, b0, d15), s3));
330 CheckBaseWithIndexAndDisplacement(&match39, p1, 3, b0, d15);
332 // (S3 + B0) + D15 -> [p1, 2, b0, d15]
333 s3 = graph()->NewNode(s_op, p1, d3);
334 BaseWithIndexAndDisplacement32Matcher match40(
335 graph()->NewNode(a_op, graph()->NewNode(a_op, s3, b0), d15));
336 CheckBaseWithIndexAndDisplacement(&match40, p1, 3, b0, d15);
338 // D15 + (S3 + B0) -> [p1, 2, b0, d15]
339 s3 = graph()->NewNode(s_op, p1, d3);
340 BaseWithIndexAndDisplacement32Matcher match41(
341 graph()->NewNode(a_op, d15, graph()->NewNode(a_op, s3, b0)));
342 CheckBaseWithIndexAndDisplacement(&match41, p1, 3, b0, d15);
344 // B0 + (D15 + S3) -> [p1, 2, b0, d15]
345 s3 = graph()->NewNode(s_op, p1, d3);
346 BaseWithIndexAndDisplacement32Matcher match42(
347 graph()->NewNode(a_op, b0, graph()->NewNode(a_op, d15, s3)));
348 CheckBaseWithIndexAndDisplacement(&match42, p1, 3, b0, d15);
350 // S3 + (B0 + D15) -> [p1, 2, b0, d15]
351 s3 = graph()->NewNode(s_op, p1, d3);
352 BaseWithIndexAndDisplacement32Matcher match43(
353 graph()->NewNode(a_op, s3, graph()->NewNode(a_op, b0, d15)));
354 CheckBaseWithIndexAndDisplacement(&match43, p1, 3, b0, d15);
356 // Check that scales that require using the base address work dorrectly.
360 TEST_F(NodeMatcherTest, ScaledWithOffset64Matcher) {
361 graph()->SetStart(graph()->NewNode(common()->Start(0)));
363 const Operator* d0_op = common()->Int64Constant(0);
364 Node* d0 = graph()->NewNode(d0_op);
366 const Operator* d1_op = common()->Int64Constant(1);
367 Node* d1 = graph()->NewNode(d1_op);
369 const Operator* d2_op = common()->Int64Constant(2);
370 Node* d2 = graph()->NewNode(d2_op);
372 const Operator* d3_op = common()->Int64Constant(3);
373 Node* d3 = graph()->NewNode(d3_op);
375 const Operator* d4_op = common()->Int64Constant(4);
376 Node* d4 = graph()->NewNode(d4_op);
378 const Operator* d5_op = common()->Int64Constant(5);
379 Node* d5 = graph()->NewNode(d5_op);
381 const Operator* d7_op = common()->Int64Constant(7);
382 Node* d7 = graph()->NewNode(d7_op);
384 const Operator* d8_op = common()->Int64Constant(8);
385 Node* d8 = graph()->NewNode(d8_op);
387 const Operator* d9_op = common()->Int64Constant(9);
388 Node* d9 = graph()->NewNode(d9_op);
390 const Operator* d15_op = common()->Int64Constant(15);
391 Node* d15 = graph()->NewNode(d15_op);
393 const Operator* d15_32_op = common()->Int32Constant(15);
394 Node* d15_32 = graph()->NewNode(d15_32_op);
397 const Operator* b0_op = common()->Parameter(0);
398 Node* b0 = graph()->NewNode(b0_op, graph()->start());
400 const Operator* b1_op = common()->Parameter(1);
401 Node* b1 = graph()->NewNode(b1_op, graph()->start());
404 const Operator* p1_op = common()->Parameter(3);
405 Node* p1 = graph()->NewNode(p1_op, graph()->start());
408 const Operator* a_op = machine()->Int64Add();
411 const Operator* m_op = machine()->Int64Mul();
412 Node* m1 = graph()->NewNode(m_op, p1, d1);
413 Node* m2 = graph()->NewNode(m_op, p1, d2);
414 Node* m3 = graph()->NewNode(m_op, p1, d3);
415 Node* m4 = graph()->NewNode(m_op, p1, d4);
416 Node* m5 = graph()->NewNode(m_op, p1, d5);
417 Node* m7 = graph()->NewNode(m_op, p1, d7);
418 Node* m8 = graph()->NewNode(m_op, p1, d8);
419 Node* m9 = graph()->NewNode(m_op, p1, d9);
429 const Operator* s_op = machine()->Word64Shl();
430 Node* s0 = graph()->NewNode(s_op, p1, d0);
431 Node* s1 = graph()->NewNode(s_op, p1, d1);
432 Node* s2 = graph()->NewNode(s_op, p1, d2);
433 Node* s3 = graph()->NewNode(s_op, p1, d3);
434 Node* s4 = graph()->NewNode(s_op, p1, d4);
443 // Only relevant test dases is Checking for non-match.
444 BaseWithIndexAndDisplacement64Matcher match0(d15);
445 EXPECT_FALSE(match0.matches());
449 // (B0 + B1) -> [B0, 0, B1, NULL]
450 BaseWithIndexAndDisplacement64Matcher match1(graph()->NewNode(a_op, b0, b1));
451 CheckBaseWithIndexAndDisplacement(&match1, b1, 0, b0, NULL);
453 // (B0 + D15) -> [NULL, 0, B0, D15]
454 BaseWithIndexAndDisplacement64Matcher match2(graph()->NewNode(a_op, b0, d15));
455 CheckBaseWithIndexAndDisplacement(&match2, NULL, 0, b0, d15);
457 BaseWithIndexAndDisplacement64Matcher match2_32(
458 graph()->NewNode(a_op, b0, d15_32));
459 CheckBaseWithIndexAndDisplacement(&match2_32, NULL, 0, b0, d15_32);
461 // (D15 + B0) -> [NULL, 0, B0, D15]
462 BaseWithIndexAndDisplacement64Matcher match3(graph()->NewNode(a_op, d15, b0));
463 CheckBaseWithIndexAndDisplacement(&match3, NULL, 0, b0, d15);
465 // (B0 + M1) -> [p1, 0, B0, NULL]
466 BaseWithIndexAndDisplacement64Matcher match4(graph()->NewNode(a_op, b0, m1));
467 CheckBaseWithIndexAndDisplacement(&match4, p1, 0, b0, NULL);
469 // (M1 + B0) -> [p1, 0, B0, NULL]
470 m1 = graph()->NewNode(m_op, p1, d1);
471 BaseWithIndexAndDisplacement64Matcher match5(graph()->NewNode(a_op, m1, b0));
472 CheckBaseWithIndexAndDisplacement(&match5, p1, 0, b0, NULL);
474 // (D15 + M1) -> [P1, 0, NULL, D15]
475 m1 = graph()->NewNode(m_op, p1, d1);
476 BaseWithIndexAndDisplacement64Matcher match6(graph()->NewNode(a_op, d15, m1));
477 CheckBaseWithIndexAndDisplacement(&match6, p1, 0, NULL, d15);
479 // (M1 + D15) -> [P1, 0, NULL, D15]
480 m1 = graph()->NewNode(m_op, p1, d1);
481 BaseWithIndexAndDisplacement64Matcher match7(graph()->NewNode(a_op, m1, d15));
482 CheckBaseWithIndexAndDisplacement(&match7, p1, 0, NULL, d15);
484 // (B0 + S0) -> [p1, 0, B0, NULL]
485 BaseWithIndexAndDisplacement64Matcher match8(graph()->NewNode(a_op, b0, s0));
486 CheckBaseWithIndexAndDisplacement(&match8, p1, 0, b0, NULL);
488 // (S0 + B0) -> [p1, 0, B0, NULL]
489 s0 = graph()->NewNode(s_op, p1, d0);
490 BaseWithIndexAndDisplacement64Matcher match9(graph()->NewNode(a_op, s0, b0));
491 CheckBaseWithIndexAndDisplacement(&match9, p1, 0, b0, NULL);
493 // (D15 + S0) -> [P1, 0, NULL, D15]
494 s0 = graph()->NewNode(s_op, p1, d0);
495 BaseWithIndexAndDisplacement64Matcher match10(
496 graph()->NewNode(a_op, d15, s0));
497 CheckBaseWithIndexAndDisplacement(&match10, p1, 0, NULL, d15);
499 // (S0 + D15) -> [P1, 0, NULL, D15]
500 s0 = graph()->NewNode(s_op, p1, d0);
501 BaseWithIndexAndDisplacement64Matcher match11(
502 graph()->NewNode(a_op, s0, d15));
503 CheckBaseWithIndexAndDisplacement(&match11, p1, 0, NULL, d15);
505 // (B0 + M2) -> [p1, 1, B0, NULL]
506 BaseWithIndexAndDisplacement64Matcher match12(graph()->NewNode(a_op, b0, m2));
507 CheckBaseWithIndexAndDisplacement(&match12, p1, 1, b0, NULL);
509 // (M2 + B0) -> [p1, 1, B0, NULL]
510 m2 = graph()->NewNode(m_op, p1, d2);
511 BaseWithIndexAndDisplacement64Matcher match13(graph()->NewNode(a_op, m2, b0));
512 CheckBaseWithIndexAndDisplacement(&match13, p1, 1, b0, NULL);
514 // (D15 + M2) -> [P1, 1, NULL, D15]
515 m2 = graph()->NewNode(m_op, p1, d2);
516 BaseWithIndexAndDisplacement64Matcher match14(
517 graph()->NewNode(a_op, d15, m2));
518 CheckBaseWithIndexAndDisplacement(&match14, p1, 1, NULL, d15);
520 // (M2 + D15) -> [P1, 1, NULL, D15]
521 m2 = graph()->NewNode(m_op, p1, d2);
522 BaseWithIndexAndDisplacement64Matcher match15(
523 graph()->NewNode(a_op, m2, d15));
524 CheckBaseWithIndexAndDisplacement(&match15, p1, 1, NULL, d15);
526 // (B0 + S1) -> [p1, 1, B0, NULL]
527 BaseWithIndexAndDisplacement64Matcher match16(graph()->NewNode(a_op, b0, s1));
528 CheckBaseWithIndexAndDisplacement(&match16, p1, 1, b0, NULL);
530 // (S1 + B0) -> [p1, 1, B0, NULL]
531 s1 = graph()->NewNode(s_op, p1, d1);
532 BaseWithIndexAndDisplacement64Matcher match17(graph()->NewNode(a_op, s1, b0));
533 CheckBaseWithIndexAndDisplacement(&match17, p1, 1, b0, NULL);
535 // (D15 + S1) -> [P1, 1, NULL, D15]
536 s1 = graph()->NewNode(s_op, p1, d1);
537 BaseWithIndexAndDisplacement64Matcher match18(
538 graph()->NewNode(a_op, d15, s1));
539 CheckBaseWithIndexAndDisplacement(&match18, p1, 1, NULL, d15);
541 // (S1 + D15) -> [P1, 1, NULL, D15]
542 s1 = graph()->NewNode(s_op, p1, d1);
543 BaseWithIndexAndDisplacement64Matcher match19(
544 graph()->NewNode(a_op, s1, d15));
545 CheckBaseWithIndexAndDisplacement(&match19, p1, 1, NULL, d15);
547 // (B0 + M4) -> [p1, 2, B0, NULL]
548 BaseWithIndexAndDisplacement64Matcher match20(graph()->NewNode(a_op, b0, m4));
549 CheckBaseWithIndexAndDisplacement(&match20, p1, 2, b0, NULL);
551 // (M4 + B0) -> [p1, 2, B0, NULL]
552 m4 = graph()->NewNode(m_op, p1, d4);
553 BaseWithIndexAndDisplacement64Matcher match21(graph()->NewNode(a_op, m4, b0));
554 CheckBaseWithIndexAndDisplacement(&match21, p1, 2, b0, NULL);
556 // (D15 + M4) -> [p1, 2, NULL, D15]
557 m4 = graph()->NewNode(m_op, p1, d4);
558 BaseWithIndexAndDisplacement64Matcher match22(
559 graph()->NewNode(a_op, d15, m4));
560 CheckBaseWithIndexAndDisplacement(&match22, p1, 2, NULL, d15);
562 // (M4 + D15) -> [p1, 2, NULL, D15]
563 m4 = graph()->NewNode(m_op, p1, d4);
564 BaseWithIndexAndDisplacement64Matcher match23(
565 graph()->NewNode(a_op, m4, d15));
566 CheckBaseWithIndexAndDisplacement(&match23, p1, 2, NULL, d15);
568 // (B0 + S2) -> [p1, 2, B0, NULL]
569 BaseWithIndexAndDisplacement64Matcher match24(graph()->NewNode(a_op, b0, s2));
570 CheckBaseWithIndexAndDisplacement(&match24, p1, 2, b0, NULL);
572 // (S2 + B0) -> [p1, 2, B0, NULL]
573 s2 = graph()->NewNode(s_op, p1, d2);
574 BaseWithIndexAndDisplacement64Matcher match25(graph()->NewNode(a_op, s2, b0));
575 CheckBaseWithIndexAndDisplacement(&match25, p1, 2, b0, NULL);
577 // (D15 + S2) -> [p1, 2, NULL, D15]
578 s2 = graph()->NewNode(s_op, p1, d2);
579 BaseWithIndexAndDisplacement64Matcher match26(
580 graph()->NewNode(a_op, d15, s2));
581 CheckBaseWithIndexAndDisplacement(&match26, p1, 2, NULL, d15);
583 // (S2 + D15) -> [p1, 2, NULL, D15]
584 s2 = graph()->NewNode(s_op, p1, d2);
585 BaseWithIndexAndDisplacement64Matcher match27(
586 graph()->NewNode(a_op, s2, d15));
587 CheckBaseWithIndexAndDisplacement(&match27, p1, 2, NULL, d15);
589 // (B0 + M8) -> [p1, 2, B0, NULL]
590 BaseWithIndexAndDisplacement64Matcher match28(graph()->NewNode(a_op, b0, m8));
591 CheckBaseWithIndexAndDisplacement(&match28, p1, 3, b0, NULL);
593 // (M8 + B0) -> [p1, 2, B0, NULL]
594 m8 = graph()->NewNode(m_op, p1, d8);
595 BaseWithIndexAndDisplacement64Matcher match29(graph()->NewNode(a_op, m8, b0));
596 CheckBaseWithIndexAndDisplacement(&match29, p1, 3, b0, NULL);
598 // (D15 + M8) -> [p1, 2, NULL, D15]
599 m8 = graph()->NewNode(m_op, p1, d8);
600 BaseWithIndexAndDisplacement64Matcher match30(
601 graph()->NewNode(a_op, d15, m8));
602 CheckBaseWithIndexAndDisplacement(&match30, p1, 3, NULL, d15);
604 // (M8 + D15) -> [p1, 2, NULL, D15]
605 m8 = graph()->NewNode(m_op, p1, d8);
606 BaseWithIndexAndDisplacement64Matcher match31(
607 graph()->NewNode(a_op, m8, d15));
608 CheckBaseWithIndexAndDisplacement(&match31, p1, 3, NULL, d15);
610 // (B0 + S3) -> [p1, 2, B0, NULL]
611 BaseWithIndexAndDisplacement64Matcher match64(graph()->NewNode(a_op, b0, s3));
612 CheckBaseWithIndexAndDisplacement(&match64, p1, 3, b0, NULL);
614 // (S3 + B0) -> [p1, 2, B0, NULL]
615 s3 = graph()->NewNode(s_op, p1, d3);
616 BaseWithIndexAndDisplacement64Matcher match33(graph()->NewNode(a_op, s3, b0));
617 CheckBaseWithIndexAndDisplacement(&match33, p1, 3, b0, NULL);
619 // (D15 + S3) -> [p1, 2, NULL, D15]
620 s3 = graph()->NewNode(s_op, p1, d3);
621 BaseWithIndexAndDisplacement64Matcher match34(
622 graph()->NewNode(a_op, d15, s3));
623 CheckBaseWithIndexAndDisplacement(&match34, p1, 3, NULL, d15);
625 // (S3 + D15) -> [p1, 2, NULL, D15]
626 s3 = graph()->NewNode(s_op, p1, d3);
627 BaseWithIndexAndDisplacement64Matcher match35(
628 graph()->NewNode(a_op, s3, d15));
629 CheckBaseWithIndexAndDisplacement(&match35, p1, 3, NULL, d15);
631 // 2 INPUT - NEGATIVE CASES
633 // (M3 + B1) -> [B0, 0, M3, NULL]
634 BaseWithIndexAndDisplacement64Matcher match36(graph()->NewNode(a_op, b1, m3));
635 CheckBaseWithIndexAndDisplacement(&match36, m3, 0, b1, NULL);
637 // (S4 + B1) -> [B0, 0, S4, NULL]
638 BaseWithIndexAndDisplacement64Matcher match37(graph()->NewNode(a_op, b1, s4));
639 CheckBaseWithIndexAndDisplacement(&match37, s4, 0, b1, NULL);
643 // (D15 + S3) + B0 -> [p1, 2, b0, d15]
644 s3 = graph()->NewNode(s_op, p1, d3);
645 BaseWithIndexAndDisplacement64Matcher match38(
646 graph()->NewNode(a_op, graph()->NewNode(a_op, d15, s3), b0));
647 CheckBaseWithIndexAndDisplacement(&match38, p1, 3, b0, d15);
649 // (B0 + D15) + S3 -> [p1, 2, b0, d15]
650 s3 = graph()->NewNode(s_op, p1, d3);
651 BaseWithIndexAndDisplacement64Matcher match39(
652 graph()->NewNode(a_op, graph()->NewNode(a_op, b0, d15), s3));
653 CheckBaseWithIndexAndDisplacement(&match39, p1, 3, b0, d15);
655 // (S3 + B0) + D15 -> [p1, 2, b0, d15]
656 s3 = graph()->NewNode(s_op, p1, d3);
657 BaseWithIndexAndDisplacement64Matcher match40(
658 graph()->NewNode(a_op, graph()->NewNode(a_op, s3, b0), d15));
659 CheckBaseWithIndexAndDisplacement(&match40, p1, 3, b0, d15);
661 // D15 + (S3 + B0) -> [p1, 2, b0, d15]
662 s3 = graph()->NewNode(s_op, p1, d3);
663 BaseWithIndexAndDisplacement64Matcher match41(
664 graph()->NewNode(a_op, d15, graph()->NewNode(a_op, s3, b0)));
665 CheckBaseWithIndexAndDisplacement(&match41, p1, 3, b0, d15);
667 // B0 + (D15 + S3) -> [p1, 2, b0, d15]
668 s3 = graph()->NewNode(s_op, p1, d3);
669 BaseWithIndexAndDisplacement64Matcher match42(
670 graph()->NewNode(a_op, b0, graph()->NewNode(a_op, d15, s3)));
671 CheckBaseWithIndexAndDisplacement(&match42, p1, 3, b0, d15);
673 // S3 + (B0 + D15) -> [p1, 2, b0, d15]
674 s3 = graph()->NewNode(s_op, p1, d3);
675 BaseWithIndexAndDisplacement64Matcher match43(
676 graph()->NewNode(a_op, s3, graph()->NewNode(a_op, b0, d15)));
677 CheckBaseWithIndexAndDisplacement(&match43, p1, 3, b0, d15);
679 // 2 INPUT with non-power of 2 scale
681 // (M3 + D15) -> [p1, 1, p1, D15]
682 m3 = graph()->NewNode(m_op, p1, d3);
683 BaseWithIndexAndDisplacement64Matcher match44(
684 graph()->NewNode(a_op, m3, d15));
685 CheckBaseWithIndexAndDisplacement(&match44, p1, 1, p1, d15);
687 // (M5 + D15) -> [p1, 2, p1, D15]
688 m5 = graph()->NewNode(m_op, p1, d5);
689 BaseWithIndexAndDisplacement64Matcher match45(
690 graph()->NewNode(a_op, m5, d15));
691 CheckBaseWithIndexAndDisplacement(&match45, p1, 2, p1, d15);
693 // (M9 + D15) -> [p1, 3, p1, D15]
694 m9 = graph()->NewNode(m_op, p1, d9);
695 BaseWithIndexAndDisplacement64Matcher match46(
696 graph()->NewNode(a_op, m9, d15));
697 CheckBaseWithIndexAndDisplacement(&match46, p1, 3, p1, d15);
699 // 3 INPUT negative cases: non-power of 2 scale but with a base
701 // ((M3 + B0) + D15) -> [m3, 0, b0, D15]
702 m3 = graph()->NewNode(m_op, p1, d3);
703 Node* temp = graph()->NewNode(a_op, m3, b0);
704 BaseWithIndexAndDisplacement64Matcher match47(
705 graph()->NewNode(a_op, temp, d15));
706 CheckBaseWithIndexAndDisplacement(&match47, m3, 0, b0, d15);
708 // (M3 + (B0 + D15)) -> [m3, 0, b0, D15]
709 m3 = graph()->NewNode(m_op, p1, d3);
710 temp = graph()->NewNode(a_op, d15, b0);
711 BaseWithIndexAndDisplacement64Matcher match48(
712 graph()->NewNode(a_op, m3, temp));
713 CheckBaseWithIndexAndDisplacement(&match48, m3, 0, b0, d15);
715 // ((B0 + M3) + D15) -> [m3, 0, b0, D15]
716 m3 = graph()->NewNode(m_op, p1, d3);
717 temp = graph()->NewNode(a_op, b0, m3);
718 BaseWithIndexAndDisplacement64Matcher match49(
719 graph()->NewNode(a_op, temp, d15));
720 CheckBaseWithIndexAndDisplacement(&match49, m3, 0, b0, d15);
722 // (M3 + (D15 + B0)) -> [m3, 0, b0, D15]
723 m3 = graph()->NewNode(m_op, p1, d3);
724 temp = graph()->NewNode(a_op, b0, d15);
725 BaseWithIndexAndDisplacement64Matcher match50(
726 graph()->NewNode(a_op, m3, temp));
727 CheckBaseWithIndexAndDisplacement(&match50, m3, 0, b0, d15);
731 TEST_F(NodeMatcherTest, BranchMatcher_match) {
732 Node* zero = graph()->NewNode(common()->Int32Constant(0));
735 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
736 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
737 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
738 BranchMatcher matcher(branch);
739 EXPECT_TRUE(matcher.Matched());
740 EXPECT_EQ(branch, matcher.Branch());
741 EXPECT_EQ(if_true, matcher.IfTrue());
742 EXPECT_EQ(if_false, matcher.IfFalse());
746 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
747 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
748 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
749 BranchMatcher matcher(branch);
750 EXPECT_TRUE(matcher.Matched());
751 EXPECT_EQ(branch, matcher.Branch());
752 EXPECT_EQ(if_true, matcher.IfTrue());
753 EXPECT_EQ(if_false, matcher.IfFalse());
757 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
758 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
759 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
760 Node* other = graph()->NewNode(common()->IfValue(33), branch);
761 BranchMatcher matcher(branch);
762 EXPECT_TRUE(matcher.Matched());
763 EXPECT_EQ(branch, matcher.Branch());
764 EXPECT_EQ(if_true, matcher.IfTrue());
765 EXPECT_EQ(if_false, matcher.IfFalse());
771 TEST_F(NodeMatcherTest, BranchMatcher_fail) {
772 Node* zero = graph()->NewNode(common()->Int32Constant(0));
775 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
776 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
777 BranchMatcher matcher(branch);
778 EXPECT_FALSE(matcher.Matched());
783 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
784 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
785 BranchMatcher matcher(branch);
786 EXPECT_FALSE(matcher.Matched());
791 BranchMatcher matcher(zero);
792 EXPECT_FALSE(matcher.Matched());
796 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
797 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
798 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
799 EXPECT_TRUE(BranchMatcher(branch).Matched());
800 EXPECT_FALSE(BranchMatcher(if_true).Matched());
801 EXPECT_FALSE(BranchMatcher(if_false).Matched());
805 Node* sw = graph()->NewNode(common()->Switch(5), zero, graph()->start());
806 Node* if_true = graph()->NewNode(common()->IfTrue(), sw);
807 Node* if_false = graph()->NewNode(common()->IfFalse(), sw);
808 EXPECT_FALSE(BranchMatcher(sw).Matched());
809 EXPECT_FALSE(BranchMatcher(if_true).Matched());
810 EXPECT_FALSE(BranchMatcher(if_false).Matched());
814 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
815 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
816 Node* if_value = graph()->NewNode(common()->IfValue(2), branch);
817 BranchMatcher matcher(branch);
818 EXPECT_FALSE(matcher.Matched());
819 EXPECT_FALSE(BranchMatcher(if_true).Matched());
820 EXPECT_FALSE(BranchMatcher(if_value).Matched());
825 TEST_F(NodeMatcherTest, DiamondMatcher_match) {
826 Node* zero = graph()->NewNode(common()->Int32Constant(0));
829 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
830 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
831 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
832 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
833 DiamondMatcher matcher(merge);
834 EXPECT_TRUE(matcher.Matched());
835 EXPECT_EQ(branch, matcher.Branch());
836 EXPECT_EQ(if_true, matcher.IfTrue());
837 EXPECT_EQ(if_false, matcher.IfFalse());
838 EXPECT_EQ(merge, matcher.Merge());
842 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
843 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
844 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
845 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
846 DiamondMatcher matcher(merge);
847 EXPECT_TRUE(matcher.Matched());
848 EXPECT_EQ(branch, matcher.Branch());
849 EXPECT_EQ(if_true, matcher.IfTrue());
850 EXPECT_EQ(if_false, matcher.IfFalse());
851 EXPECT_EQ(merge, matcher.Merge());
855 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
856 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
857 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
858 Node* merge = graph()->NewNode(common()->Merge(2), if_false, if_true);
859 DiamondMatcher matcher(merge);
860 EXPECT_TRUE(matcher.Matched());
861 EXPECT_EQ(branch, matcher.Branch());
862 EXPECT_EQ(if_true, matcher.IfTrue());
863 EXPECT_EQ(if_false, matcher.IfFalse());
864 EXPECT_EQ(merge, matcher.Merge());
869 TEST_F(NodeMatcherTest, DiamondMatcher_fail) {
870 Node* zero = graph()->NewNode(common()->Int32Constant(0));
873 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
874 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
875 Node* if_value = graph()->NewNode(common()->IfValue(1), branch);
876 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_value);
877 DiamondMatcher matcher(merge);
878 EXPECT_FALSE(matcher.Matched());
882 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
883 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
884 Node* if_value = graph()->NewNode(common()->IfValue(1), branch);
885 Node* merge = graph()->NewNode(common()->Merge(2), if_false, if_value);
886 DiamondMatcher matcher(merge);
887 EXPECT_FALSE(matcher.Matched());
891 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
892 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
893 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
894 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
895 DiamondMatcher matcher(merge);
896 EXPECT_TRUE(matcher.Matched());
897 EXPECT_EQ(branch, matcher.Branch());
898 EXPECT_EQ(if_true, matcher.IfTrue());
899 EXPECT_EQ(if_false, matcher.IfFalse());
900 EXPECT_EQ(merge, matcher.Merge());
902 EXPECT_FALSE(DiamondMatcher(branch).Matched()); // Must be the merge.
903 EXPECT_FALSE(DiamondMatcher(if_true).Matched());
904 EXPECT_FALSE(DiamondMatcher(if_false).Matched());
908 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
909 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
910 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
911 Node* merge = graph()->NewNode(common()->Merge(3), if_true, if_false,
913 DiamondMatcher matcher(merge);
914 EXPECT_FALSE(matcher.Matched()); // Too many inputs to merge.
918 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
919 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
920 Node* if_false = graph()->start();
921 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
922 DiamondMatcher matcher(merge);
923 EXPECT_FALSE(matcher.Matched());
927 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
928 Node* if_true = graph()->start();
929 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
930 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
931 DiamondMatcher matcher(merge);
932 EXPECT_FALSE(matcher.Matched());
937 graph()->NewNode(common()->Branch(), zero, graph()->start());
939 graph()->NewNode(common()->Branch(), zero, graph()->start());
940 Node* if_true = graph()->NewNode(common()->IfTrue(), branch1);
941 Node* if_false = graph()->NewNode(common()->IfFalse(), branch2);
942 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
943 DiamondMatcher matcher(merge);
944 EXPECT_FALSE(matcher.Matched());
949 } // namespace compiler
950 } // namespace internal