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

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

Issue 555833002: [turbofan] Add support for overflow add/sub to the MachineOperatorReducer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address nit. Created 6 years, 3 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/cctest/compiler/test-run-machops.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/machine-operator-reducer-unittest.cc
diff --git a/src/compiler/machine-operator-reducer-unittest.cc b/src/compiler/machine-operator-reducer-unittest.cc
index 4267161954a03ab494102e893577cfa747a60c2e..a756fe3486a5d757b09eadfdc956bfaf5b5739d9 100644
--- a/src/compiler/machine-operator-reducer-unittest.cc
+++ b/src/compiler/machine-operator-reducer-unittest.cc
@@ -442,6 +442,98 @@ TEST_F(MachineOperatorReducerTest, Word32RorWithConstants) {
}
}
+
+// -----------------------------------------------------------------------------
+// Int32AddWithOverflow
+
+
+TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithZero) {
+ Node* p0 = Parameter(0);
+ {
+ Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(),
+ Int32Constant(0), p0);
+
+ Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32Constant(0));
+
+ r = Reduce(graph()->NewNode(common()->Projection(0), add));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_EQ(p0, r.replacement());
+ }
+ {
+ Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), p0,
+ Int32Constant(0));
+
+ Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32Constant(0));
+
+ r = Reduce(graph()->NewNode(common()->Projection(0), add));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_EQ(p0, r.replacement());
+ }
+}
+
+
+TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithConstant) {
+ TRACED_FOREACH(int32_t, x, kInt32Values) {
+ TRACED_FOREACH(int32_t, y, kInt32Values) {
+ int32_t z;
+ Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(),
+ Int32Constant(x), Int32Constant(y));
+
+ Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsInt32Constant(base::bits::SignedAddOverflow32(x, y, &z)));
+
+ r = Reduce(graph()->NewNode(common()->Projection(0), add));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32Constant(z));
+ }
+ }
+}
+
+
+// -----------------------------------------------------------------------------
+// Int32SubWithOverflow
+
+
+TEST_F(MachineOperatorReducerTest, Int32SubWithOverflowWithZero) {
+ Node* p0 = Parameter(0);
+ Node* add =
+ graph()->NewNode(machine()->Int32SubWithOverflow(), p0, Int32Constant(0));
+
+ Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32Constant(0));
+
+ r = Reduce(graph()->NewNode(common()->Projection(0), add));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_EQ(p0, r.replacement());
+}
+
+
+TEST_F(MachineOperatorReducerTest, Int32SubWithOverflowWithConstant) {
+ TRACED_FOREACH(int32_t, x, kInt32Values) {
+ TRACED_FOREACH(int32_t, y, kInt32Values) {
+ int32_t z;
+ Node* add = graph()->NewNode(machine()->Int32SubWithOverflow(),
+ Int32Constant(x), Int32Constant(y));
+
+ Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsInt32Constant(base::bits::SignedSubOverflow32(x, y, &z)));
+
+ r = Reduce(graph()->NewNode(common()->Projection(0), add));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsInt32Constant(z));
+ }
+ }
+}
+
} // namespace compiler
} // namespace internal
} // namespace v8
« no previous file with comments | « src/compiler/machine-operator-reducer.cc ('k') | test/cctest/compiler/test-run-machops.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698