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

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

Issue 951903003: [turbofan] Strength reduction for inline comparisons. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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/opcodes.h ('k') | test/unittests/compiler/opcodes-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/base/bits.h" 5 #include "src/base/bits.h"
6 #include "src/base/division-by-constant.h" 6 #include "src/base/division-by-constant.h"
7 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/machine-operator-reducer.h" 8 #include "src/compiler/machine-operator-reducer.h"
9 #include "src/compiler/typer.h" 9 #include "src/compiler/typer.h"
10 #include "test/unittests/compiler/graph-unittest.h" 10 #include "test/unittests/compiler/graph-unittest.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 const uint32_t kUint32Values[] = { 226 const uint32_t kUint32Values[] = {
227 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf, 227 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf,
228 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344, 228 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344,
229 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c, 229 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c,
230 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00, 230 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00,
231 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000, 231 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000,
232 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff, 232 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff,
233 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff, 233 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff,
234 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff}; 234 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff};
235 235
236
237 struct ComparisonBinaryOperator {
238 const Operator* (MachineOperatorBuilder::*constructor)();
239 const char* constructor_name;
240 };
241
242
243 std::ostream& operator<<(std::ostream& os,
244 ComparisonBinaryOperator const& cbop) {
245 return os << cbop.constructor_name;
246 }
247
248
249 const ComparisonBinaryOperator kComparisonBinaryOperators[] = {
250 #define OPCODE(Opcode) \
251 { &MachineOperatorBuilder::Opcode, #Opcode } \
252 ,
253 MACHINE_COMPARE_BINOP_LIST(OPCODE)
254 #undef OPCODE
255 };
256
236 } // namespace 257 } // namespace
237 258
238 259
239 // ----------------------------------------------------------------------------- 260 // -----------------------------------------------------------------------------
240 // Unary operators 261 // Unary operators
241 262
242 263
243 namespace { 264 namespace {
244 265
245 struct UnaryOperator { 266 struct UnaryOperator {
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 Int32Constant(-1 << l))); 646 Int32Constant(-1 << l)));
626 ASSERT_TRUE(r2.Changed()); 647 ASSERT_TRUE(r2.Changed());
627 EXPECT_THAT(r2.replacement(), 648 EXPECT_THAT(r2.replacement(),
628 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), 649 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)),
629 IsInt32Mul(p1, IsInt32Constant(k << l)))); 650 IsInt32Mul(p1, IsInt32Constant(k << l))));
630 } 651 }
631 } 652 }
632 } 653 }
633 654
634 655
656 TEST_F(MachineOperatorReducerTest, Word32AndWithComparisonAndConstantOne) {
657 Node* const p0 = Parameter(0);
658 Node* const p1 = Parameter(1);
659 TRACED_FOREACH(ComparisonBinaryOperator, cbop, kComparisonBinaryOperators) {
660 Node* cmp = graph()->NewNode((machine()->*cbop.constructor)(), p0, p1);
661
662 // cmp & 1 => cmp
663 Reduction const r1 =
664 Reduce(graph()->NewNode(machine()->Word32And(), cmp, Int32Constant(1)));
665 ASSERT_TRUE(r1.Changed());
666 EXPECT_EQ(cmp, r1.replacement());
667
668 // 1 & cmp => cmp
669 Reduction const r2 =
670 Reduce(graph()->NewNode(machine()->Word32And(), Int32Constant(1), cmp));
671 ASSERT_TRUE(r2.Changed());
672 EXPECT_EQ(cmp, r2.replacement());
673 }
674 }
675
676
635 // ----------------------------------------------------------------------------- 677 // -----------------------------------------------------------------------------
636 // Word32Xor 678 // Word32Xor
637 679
638 680
639 TEST_F(MachineOperatorReducerTest, Word32XorWithWord32XorAndMinusOne) { 681 TEST_F(MachineOperatorReducerTest, Word32XorWithWord32XorAndMinusOne) {
640 Node* const p0 = Parameter(0); 682 Node* const p0 = Parameter(0);
641 683
642 // (x ^ -1) ^ -1 => x 684 // (x ^ -1) ^ -1 => x
643 Reduction r1 = Reduce(graph()->NewNode( 685 Reduction r1 = Reduce(graph()->NewNode(
644 machine()->Word32Xor(), 686 machine()->Word32Xor(),
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 IsInt32Constant(base::bits::RotateRight32(x, y))); 808 IsInt32Constant(base::bits::RotateRight32(x, y)));
767 } 809 }
768 } 810 }
769 } 811 }
770 812
771 813
772 // ----------------------------------------------------------------------------- 814 // -----------------------------------------------------------------------------
773 // Word32Sar 815 // Word32Sar
774 816
775 817
818 TEST_F(MachineOperatorReducerTest, Word32SarWithWord32ShlAndComparison) {
819 Node* const p0 = Parameter(0);
820 Node* const p1 = Parameter(1);
821
822 TRACED_FOREACH(ComparisonBinaryOperator, cbop, kComparisonBinaryOperators) {
823 Node* cmp = graph()->NewNode((machine()->*cbop.constructor)(), p0, p1);
824
825 // cmp << 31 >> 31 => 0 - cmp
826 Reduction const r = Reduce(graph()->NewNode(
827 machine()->Word32Sar(),
828 graph()->NewNode(machine()->Word32Shl(), cmp, Int32Constant(31)),
829 Int32Constant(31)));
830 ASSERT_TRUE(r.Changed());
831 EXPECT_THAT(r.replacement(), IsInt32Sub(IsInt32Constant(0), cmp));
832 }
833 }
834
835
776 TEST_F(MachineOperatorReducerTest, Word32SarWithWord32ShlAndLoad) { 836 TEST_F(MachineOperatorReducerTest, Word32SarWithWord32ShlAndLoad) {
777 Node* const p0 = Parameter(0); 837 Node* const p0 = Parameter(0);
778 Node* const p1 = Parameter(1); 838 Node* const p1 = Parameter(1);
779 { 839 {
780 Node* const l = graph()->NewNode(machine()->Load(kMachInt8), p0, p1, 840 Node* const l = graph()->NewNode(machine()->Load(kMachInt8), p0, p1,
781 graph()->start(), graph()->start()); 841 graph()->start(), graph()->start());
782 Reduction const r = Reduce(graph()->NewNode( 842 Reduction const r = Reduce(graph()->NewNode(
783 machine()->Word32Sar(), 843 machine()->Word32Sar(),
784 graph()->NewNode(machine()->Word32Shl(), l, Int32Constant(24)), 844 graph()->NewNode(machine()->Word32Shl(), l, Int32Constant(24)),
785 Int32Constant(24))); 845 Int32Constant(24)));
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 TEST_F(MachineOperatorReducerTest, Uint32ModWithParameters) { 1243 TEST_F(MachineOperatorReducerTest, Uint32ModWithParameters) {
1184 Node* const p0 = Parameter(0); 1244 Node* const p0 = Parameter(0);
1185 Reduction const r = Reduce( 1245 Reduction const r = Reduce(
1186 graph()->NewNode(machine()->Uint32Mod(), p0, p0, graph()->start())); 1246 graph()->NewNode(machine()->Uint32Mod(), p0, p0, graph()->start()));
1187 ASSERT_TRUE(r.Changed()); 1247 ASSERT_TRUE(r.Changed());
1188 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 1248 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
1189 } 1249 }
1190 1250
1191 1251
1192 // ----------------------------------------------------------------------------- 1252 // -----------------------------------------------------------------------------
1253 // Int32Add
1254
1255
1256 TEST_F(MachineOperatorReducerTest, Int32AddWithInt32SubWithConstantZero) {
1257 Node* const p0 = Parameter(0);
1258 Node* const p1 = Parameter(1);
1259
1260 Reduction const r1 = Reduce(graph()->NewNode(
1261 machine()->Int32Add(),
1262 graph()->NewNode(machine()->Int32Sub(), Int32Constant(0), p0), p1));
1263 ASSERT_TRUE(r1.Changed());
1264 EXPECT_THAT(r1.replacement(), IsInt32Sub(p1, p0));
1265
1266 Reduction const r2 = Reduce(graph()->NewNode(
1267 machine()->Int32Add(), p0,
1268 graph()->NewNode(machine()->Int32Sub(), Int32Constant(0), p1)));
1269 ASSERT_TRUE(r2.Changed());
1270 EXPECT_THAT(r2.replacement(), IsInt32Sub(p0, p1));
1271 }
1272
1273
1274 // -----------------------------------------------------------------------------
1193 // Int32AddWithOverflow 1275 // Int32AddWithOverflow
1194 1276
1195 1277
1196 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithZero) { 1278 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithZero) {
1197 Node* p0 = Parameter(0); 1279 Node* p0 = Parameter(0);
1198 { 1280 {
1199 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), 1281 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(),
1200 Int32Constant(0), p0); 1282 Int32Constant(0), p0);
1201 1283
1202 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add)); 1284 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add));
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 Reduction r = Reduce(node); 1499 Reduction r = Reduce(node);
1418 ASSERT_TRUE(r.Changed()); 1500 ASSERT_TRUE(r.Changed());
1419 EXPECT_THAT(r.replacement(), 1501 EXPECT_THAT(r.replacement(),
1420 IsStore(rep, base, index, value, effect, control)); 1502 IsStore(rep, base, index, value, effect, control));
1421 } 1503 }
1422 } 1504 }
1423 1505
1424 } // namespace compiler 1506 } // namespace compiler
1425 } // namespace internal 1507 } // namespace internal
1426 } // namespace v8 1508 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/opcodes.h ('k') | test/unittests/compiler/opcodes-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698