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

Side by Side Diff: test/unittests/compiler/node-matchers-unittest.cc

Issue 2137323003: [turbofan] Support subtraction displacements in BaseWithIndexAndDisplacementMatcher (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Review feedback Created 4 years, 5 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 | « src/compiler/x64/instruction-selector-x64.cc ('k') | no next file » | 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/graph.h" 6 #include "src/compiler/graph.h"
7 #include "src/compiler/machine-operator.h" 7 #include "src/compiler/machine-operator.h"
8 #include "src/compiler/node.h" 8 #include "src/compiler/node.h"
9 #include "src/compiler/node-matchers.h" 9 #include "src/compiler/node-matchers.h"
10 #include "src/compiler/opcodes.h" 10 #include "src/compiler/opcodes.h"
(...skipping 12 matching lines...) Expand all
23 23
24 MachineOperatorBuilder* machine() { return &machine_; } 24 MachineOperatorBuilder* machine() { return &machine_; }
25 25
26 private: 26 private:
27 MachineOperatorBuilder machine_; 27 MachineOperatorBuilder machine_;
28 }; 28 };
29 29
30 namespace { 30 namespace {
31 31
32 template <class Matcher> 32 template <class Matcher>
33 void CheckBaseWithIndexAndDisplacement(Matcher* matcher, Node* index, int scale, 33 void CheckBaseWithIndexAndDisplacement(
34 Node* base, Node* displacement) { 34 Matcher* matcher, Node* index, int scale, Node* base, Node* displacement,
35 DisplacementMode displacement_mode = kPositiveDisplacement) {
35 EXPECT_TRUE(matcher->matches()); 36 EXPECT_TRUE(matcher->matches());
36 EXPECT_EQ(index, matcher->index()); 37 EXPECT_EQ(index, matcher->index());
37 EXPECT_EQ(scale, matcher->scale()); 38 EXPECT_EQ(scale, matcher->scale());
38 EXPECT_EQ(base, matcher->base()); 39 EXPECT_EQ(base, matcher->base());
39 EXPECT_EQ(displacement, matcher->displacement()); 40 EXPECT_EQ(displacement, matcher->displacement());
41 EXPECT_EQ(displacement_mode, matcher->displacement_mode());
40 } 42 }
41 43
42 } // namespace 44 } // namespace
43 45
44 46
45 TEST_F(NodeMatcherTest, ScaledWithOffset32Matcher) { 47 TEST_F(NodeMatcherTest, ScaledWithOffset32Matcher) {
46 graph()->SetStart(graph()->NewNode(common()->Start(0))); 48 graph()->SetStart(graph()->NewNode(common()->Start(0)));
47 49
48 const Operator* d0_op = common()->Int32Constant(0); 50 const Operator* d0_op = common()->Int32Constant(0);
49 Node* d0 = graph()->NewNode(d0_op); 51 Node* d0 = graph()->NewNode(d0_op);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 Node* b1 = graph()->NewNode(b1_op, graph()->start()); 85 Node* b1 = graph()->NewNode(b1_op, graph()->start());
84 USE(b0); 86 USE(b0);
85 87
86 const Operator* p1_op = common()->Parameter(3); 88 const Operator* p1_op = common()->Parameter(3);
87 Node* p1 = graph()->NewNode(p1_op, graph()->start()); 89 Node* p1 = graph()->NewNode(p1_op, graph()->start());
88 USE(p1); 90 USE(p1);
89 91
90 const Operator* a_op = machine()->Int32Add(); 92 const Operator* a_op = machine()->Int32Add();
91 USE(a_op); 93 USE(a_op);
92 94
95 const Operator* sub_op = machine()->Int32Sub();
96 USE(sub_op);
97
93 const Operator* m_op = machine()->Int32Mul(); 98 const Operator* m_op = machine()->Int32Mul();
94 Node* m1 = graph()->NewNode(m_op, p1, d1); 99 Node* m1 = graph()->NewNode(m_op, p1, d1);
95 Node* m2 = graph()->NewNode(m_op, p1, d2); 100 Node* m2 = graph()->NewNode(m_op, p1, d2);
96 Node* m3 = graph()->NewNode(m_op, p1, d3); 101 Node* m3 = graph()->NewNode(m_op, p1, d3);
97 Node* m4 = graph()->NewNode(m_op, p1, d4); 102 Node* m4 = graph()->NewNode(m_op, p1, d4);
98 Node* m5 = graph()->NewNode(m_op, p1, d5); 103 Node* m5 = graph()->NewNode(m_op, p1, d5);
99 Node* m7 = graph()->NewNode(m_op, p1, d7); 104 Node* m7 = graph()->NewNode(m_op, p1, d7);
100 Node* m8 = graph()->NewNode(m_op, p1, d8); 105 Node* m8 = graph()->NewNode(m_op, p1, d8);
101 Node* m9 = graph()->NewNode(m_op, p1, d9); 106 Node* m9 = graph()->NewNode(m_op, p1, d9);
102 USE(m1); 107 USE(m1);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 BaseWithIndexAndDisplacement32Matcher match42( 352 BaseWithIndexAndDisplacement32Matcher match42(
348 graph()->NewNode(a_op, b0, graph()->NewNode(a_op, d15, s3))); 353 graph()->NewNode(a_op, b0, graph()->NewNode(a_op, d15, s3)));
349 CheckBaseWithIndexAndDisplacement(&match42, p1, 3, b0, d15); 354 CheckBaseWithIndexAndDisplacement(&match42, p1, 3, b0, d15);
350 355
351 // S3 + (B0 + D15) -> [p1, 2, b0, d15] 356 // S3 + (B0 + D15) -> [p1, 2, b0, d15]
352 s3 = graph()->NewNode(s_op, p1, d3); 357 s3 = graph()->NewNode(s_op, p1, d3);
353 BaseWithIndexAndDisplacement32Matcher match43( 358 BaseWithIndexAndDisplacement32Matcher match43(
354 graph()->NewNode(a_op, s3, graph()->NewNode(a_op, b0, d15))); 359 graph()->NewNode(a_op, s3, graph()->NewNode(a_op, b0, d15)));
355 CheckBaseWithIndexAndDisplacement(&match43, p1, 3, b0, d15); 360 CheckBaseWithIndexAndDisplacement(&match43, p1, 3, b0, d15);
356 361
357 // Check that scales that require using the base address work dorrectly. 362 // S3 + (B0 - D15) -> [p1, 2, b0, d15, true]
363 s3 = graph()->NewNode(s_op, p1, d3);
364 BaseWithIndexAndDisplacement32Matcher match44(
365 graph()->NewNode(a_op, s3, graph()->NewNode(sub_op, b0, d15)));
366 CheckBaseWithIndexAndDisplacement(&match44, p1, 3, b0, d15,
367 kNegativeDisplacement);
368
369 // B0 + (B1 - D15) -> [p1, 2, b0, d15, true]
370 BaseWithIndexAndDisplacement32Matcher match45(
371 graph()->NewNode(a_op, b0, graph()->NewNode(sub_op, b1, d15)));
372 CheckBaseWithIndexAndDisplacement(&match45, b1, 0, b0, d15,
373 kNegativeDisplacement);
374
375 // (B0 - D15) + S3 -> [p1, 2, b0, d15, true]
376 s3 = graph()->NewNode(s_op, p1, d3);
377 BaseWithIndexAndDisplacement32Matcher match46(
378 graph()->NewNode(a_op, graph()->NewNode(sub_op, b0, d15), s3));
379 CheckBaseWithIndexAndDisplacement(&match46, p1, 3, b0, d15,
380 kNegativeDisplacement);
358 } 381 }
359 382
360 383
361 TEST_F(NodeMatcherTest, ScaledWithOffset64Matcher) { 384 TEST_F(NodeMatcherTest, ScaledWithOffset64Matcher) {
362 graph()->SetStart(graph()->NewNode(common()->Start(0))); 385 graph()->SetStart(graph()->NewNode(common()->Start(0)));
363 386
364 const Operator* d0_op = common()->Int64Constant(0); 387 const Operator* d0_op = common()->Int64Constant(0);
365 Node* d0 = graph()->NewNode(d0_op); 388 Node* d0 = graph()->NewNode(d0_op);
366 USE(d0); 389 USE(d0);
367 const Operator* d1_op = common()->Int64Constant(1); 390 const Operator* d1_op = common()->Int64Constant(1);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 Node* b1 = graph()->NewNode(b1_op, graph()->start()); 425 Node* b1 = graph()->NewNode(b1_op, graph()->start());
403 USE(b0); 426 USE(b0);
404 427
405 const Operator* p1_op = common()->Parameter(3); 428 const Operator* p1_op = common()->Parameter(3);
406 Node* p1 = graph()->NewNode(p1_op, graph()->start()); 429 Node* p1 = graph()->NewNode(p1_op, graph()->start());
407 USE(p1); 430 USE(p1);
408 431
409 const Operator* a_op = machine()->Int64Add(); 432 const Operator* a_op = machine()->Int64Add();
410 USE(a_op); 433 USE(a_op);
411 434
435 const Operator* sub_op = machine()->Int64Sub();
436 USE(sub_op);
437
412 const Operator* m_op = machine()->Int64Mul(); 438 const Operator* m_op = machine()->Int64Mul();
413 Node* m1 = graph()->NewNode(m_op, p1, d1); 439 Node* m1 = graph()->NewNode(m_op, p1, d1);
414 Node* m2 = graph()->NewNode(m_op, p1, d2); 440 Node* m2 = graph()->NewNode(m_op, p1, d2);
415 Node* m3 = graph()->NewNode(m_op, p1, d3); 441 Node* m3 = graph()->NewNode(m_op, p1, d3);
416 Node* m4 = graph()->NewNode(m_op, p1, d4); 442 Node* m4 = graph()->NewNode(m_op, p1, d4);
417 Node* m5 = graph()->NewNode(m_op, p1, d5); 443 Node* m5 = graph()->NewNode(m_op, p1, d5);
418 Node* m7 = graph()->NewNode(m_op, p1, d7); 444 Node* m7 = graph()->NewNode(m_op, p1, d7);
419 Node* m8 = graph()->NewNode(m_op, p1, d8); 445 Node* m8 = graph()->NewNode(m_op, p1, d8);
420 Node* m9 = graph()->NewNode(m_op, p1, d9); 446 Node* m9 = graph()->NewNode(m_op, p1, d9);
421 USE(m1); 447 USE(m1);
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 BaseWithIndexAndDisplacement64Matcher match49( 745 BaseWithIndexAndDisplacement64Matcher match49(
720 graph()->NewNode(a_op, temp, d15)); 746 graph()->NewNode(a_op, temp, d15));
721 CheckBaseWithIndexAndDisplacement(&match49, m3, 0, b0, d15); 747 CheckBaseWithIndexAndDisplacement(&match49, m3, 0, b0, d15);
722 748
723 // (M3 + (D15 + B0)) -> [m3, 0, b0, D15] 749 // (M3 + (D15 + B0)) -> [m3, 0, b0, D15]
724 m3 = graph()->NewNode(m_op, p1, d3); 750 m3 = graph()->NewNode(m_op, p1, d3);
725 temp = graph()->NewNode(a_op, b0, d15); 751 temp = graph()->NewNode(a_op, b0, d15);
726 BaseWithIndexAndDisplacement64Matcher match50( 752 BaseWithIndexAndDisplacement64Matcher match50(
727 graph()->NewNode(a_op, m3, temp)); 753 graph()->NewNode(a_op, m3, temp));
728 CheckBaseWithIndexAndDisplacement(&match50, m3, 0, b0, d15); 754 CheckBaseWithIndexAndDisplacement(&match50, m3, 0, b0, d15);
755
756 // S3 + (B0 - D15) -> [p1, 2, b0, d15, true]
757 s3 = graph()->NewNode(s_op, p1, d3);
758 BaseWithIndexAndDisplacement64Matcher match51(
759 graph()->NewNode(a_op, s3, graph()->NewNode(sub_op, b0, d15)));
760 CheckBaseWithIndexAndDisplacement(&match51, p1, 3, b0, d15,
761 kNegativeDisplacement);
762
763 // B0 + (B1 - D15) -> [p1, 2, b0, d15, true]
764 BaseWithIndexAndDisplacement64Matcher match52(
765 graph()->NewNode(a_op, b0, graph()->NewNode(sub_op, b1, d15)));
766 CheckBaseWithIndexAndDisplacement(&match52, b1, 0, b0, d15,
767 kNegativeDisplacement);
768
769 // (B0 - D15) + S3 -> [p1, 2, b0, d15, true]
770 s3 = graph()->NewNode(s_op, p1, d3);
771 BaseWithIndexAndDisplacement64Matcher match53(
772 graph()->NewNode(a_op, graph()->NewNode(sub_op, b0, d15), s3));
773 CheckBaseWithIndexAndDisplacement(&match53, p1, 3, b0, d15,
774 kNegativeDisplacement);
729 } 775 }
730 776
731
732 TEST_F(NodeMatcherTest, BranchMatcher_match) { 777 TEST_F(NodeMatcherTest, BranchMatcher_match) {
733 Node* zero = graph()->NewNode(common()->Int32Constant(0)); 778 Node* zero = graph()->NewNode(common()->Int32Constant(0));
734 779
735 { 780 {
736 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); 781 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
737 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); 782 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
738 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); 783 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
739 BranchMatcher matcher(branch); 784 BranchMatcher matcher(branch);
740 EXPECT_TRUE(matcher.Matched()); 785 EXPECT_TRUE(matcher.Matched());
741 EXPECT_EQ(branch, matcher.Branch()); 786 EXPECT_EQ(branch, matcher.Branch());
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); 988 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
944 DiamondMatcher matcher(merge); 989 DiamondMatcher matcher(merge);
945 EXPECT_FALSE(matcher.Matched()); 990 EXPECT_FALSE(matcher.Matched());
946 } 991 }
947 } 992 }
948 993
949 994
950 } // namespace compiler 995 } // namespace compiler
951 } // namespace internal 996 } // namespace internal
952 } // namespace v8 997 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/x64/instruction-selector-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698