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

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

Issue 2139733003: [turbofan] Strength reduction for Int32MulWithOverflow. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2101123005
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/machine-operator-reducer.cc ('k') | test/unittests/compiler/node-test-utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/compiler/machine-operator-reducer-unittest.cc
diff --git a/test/unittests/compiler/machine-operator-reducer-unittest.cc b/test/unittests/compiler/machine-operator-reducer-unittest.cc
index facc4991dbe34485b3e25d89f82921feba8b7ed9..7de6c7d2f24a6beffe37f5a5ffa4ac9f4af6bfc9 100644
--- a/test/unittests/compiler/machine-operator-reducer-unittest.cc
+++ b/test/unittests/compiler/machine-operator-reducer-unittest.cc
@@ -1380,8 +1380,133 @@ TEST_F(MachineOperatorReducerTest, Int32SubWithOverflowWithConstant) {
// -----------------------------------------------------------------------------
-// Uint32LessThan
+// Int32MulWithOverflow
+
+TEST_F(MachineOperatorReducerTest, Int32MulWithOverflowWithZero) {
+ Node* control = graph()->start();
+ Node* p0 = Parameter(0);
+ {
+ Node* mul = graph()->NewNode(machine()->Int32MulWithOverflow(),
+ Int32Constant(0), p0, control);
+
+ Reduction r =
+ Reduce(graph()->NewNode(common()->Projection(1), mul, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32Constant(0));
+
+ r = Reduce(graph()->NewNode(common()->Projection(0), mul, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32Constant(0));
+ }
+ {
+ Node* mul = graph()->NewNode(machine()->Int32MulWithOverflow(), p0,
+ Int32Constant(0), control);
+
+ Reduction r =
+ Reduce(graph()->NewNode(common()->Projection(1), mul, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32Constant(0));
+
+ r = Reduce(graph()->NewNode(common()->Projection(0), mul, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32Constant(0));
+ }
+}
+
+TEST_F(MachineOperatorReducerTest, Int32MulWithOverflowWithOne) {
+ Node* control = graph()->start();
+ Node* p0 = Parameter(0);
+ {
+ Node* mul = graph()->NewNode(machine()->Int32MulWithOverflow(),
+ Int32Constant(1), p0, control);
+ Reduction r =
+ Reduce(graph()->NewNode(common()->Projection(1), mul, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32Constant(0));
+
+ r = Reduce(graph()->NewNode(common()->Projection(0), mul, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_EQ(p0, r.replacement());
+ }
+ {
+ Node* mul = graph()->NewNode(machine()->Int32MulWithOverflow(), p0,
+ Int32Constant(1), control);
+
+ Reduction r =
+ Reduce(graph()->NewNode(common()->Projection(1), mul, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32Constant(0));
+
+ r = Reduce(graph()->NewNode(common()->Projection(0), mul, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_EQ(p0, r.replacement());
+ }
+}
+
+TEST_F(MachineOperatorReducerTest, Int32MulWithOverflowWithMinusOne) {
+ Node* control = graph()->start();
+ Node* p0 = Parameter(0);
+
+ {
+ Reduction r = Reduce(graph()->NewNode(machine()->Int32MulWithOverflow(),
+ Int32Constant(-1), p0, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsInt32SubWithOverflow(IsInt32Constant(0), p0));
+ }
+
+ {
+ Reduction r = Reduce(graph()->NewNode(machine()->Int32MulWithOverflow(), p0,
+ Int32Constant(-1), control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsInt32SubWithOverflow(IsInt32Constant(0), p0));
+ }
+}
+
+TEST_F(MachineOperatorReducerTest, Int32MulWithOverflowWithTwo) {
+ Node* control = graph()->start();
+ Node* p0 = Parameter(0);
+
+ {
+ Reduction r = Reduce(graph()->NewNode(machine()->Int32MulWithOverflow(),
+ Int32Constant(2), p0, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32AddWithOverflow(p0, p0));
+ }
+
+ {
+ Reduction r = Reduce(graph()->NewNode(machine()->Int32MulWithOverflow(), p0,
+ Int32Constant(2), control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32AddWithOverflow(p0, p0));
+ }
+}
+
+TEST_F(MachineOperatorReducerTest, Int32MulWithOverflowWithConstant) {
+ Node* control = graph()->start();
+ TRACED_FOREACH(int32_t, x, kInt32Values) {
+ TRACED_FOREACH(int32_t, y, kInt32Values) {
+ int32_t z;
+ Node* mul = graph()->NewNode(machine()->Int32MulWithOverflow(),
+ Int32Constant(x), Int32Constant(y), control);
+
+ Reduction r =
+ Reduce(graph()->NewNode(common()->Projection(1), mul, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsInt32Constant(base::bits::SignedMulOverflow32(x, y, &z)));
+
+ r = Reduce(graph()->NewNode(common()->Projection(0), mul, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32Constant(z));
+ }
+ }
+}
+
+// -----------------------------------------------------------------------------
+// Uint32LessThan
TEST_F(MachineOperatorReducerTest, Uint32LessThanWithWord32Sar) {
Node* const p0 = Parameter(0);
« no previous file with comments | « src/compiler/machine-operator-reducer.cc ('k') | test/unittests/compiler/node-test-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698