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

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

Issue 683793003: [turbofan] fold constants in compares (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 6 years, 2 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') | no next file » | 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 fff6f96709d072ecf055c927800d2532a73280c3..33c5489a6f5f9a62bfe32981b9100f0ff4aa71c2 100644
--- a/test/unittests/compiler/machine-operator-reducer-unittest.cc
+++ b/test/unittests/compiler/machine-operator-reducer-unittest.cc
@@ -232,6 +232,12 @@ const uint32_t kUint32Values[] = {
0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff,
0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff};
+
+int32_t RandomInt32(base::RandomNumberGenerator* rng) {
+ int index = rng->NextInt(static_cast<int>(arraysize(kInt32Values)));
+ return kInt32Values[index];
+}
+
} // namespace
@@ -1144,6 +1150,43 @@ TEST_F(MachineOperatorReducerTest, StoreRepWord16WithWord32And) {
}
}
+
+TEST_F(MachineOperatorReducerTest, ConstantFoldCompare32) {
+ base::RandomNumberGenerator rng;
+ TRACED_FOREACH(int32_t, c_0, kInt32Values) {
+ const int32_t c_1 = RandomInt32(&rng);
+ const int32_t c_2 = RandomInt32(&rng);
+ {
+ Node* const k_0 = Int32Constant(c_0);
+ Node* const k_1 = Int32Constant(c_1);
+ Node* const k_2 = Int32Constant(c_2);
+ Node* const p0 = Parameter(0);
+ Node* const add_0 = graph()->NewNode(machine()->Int32Add(), p0, k_0);
+ Node* const add_1 = graph()->NewNode(machine()->Int32Add(), add_0, k_1);
+ Node* const node =
+ graph()->NewNode(machine()->Int32LessThan(), add_1, k_2);
+ Reduction r = Reduce(node);
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsInt32LessThan(p0, IsInt32Constant(c_2 - c_1 - c_0)));
+ }
+ {
+ Node* const k_0 = Int32Constant(c_0);
+ Node* const k_1 = Int32Constant(c_1);
+ Node* const k_2 = Int32Constant(c_2);
+ Node* const p0 = Parameter(0);
+ Node* const add_0 = graph()->NewNode(machine()->Int32Add(), p0, k_0);
+ Node* const add_1 = graph()->NewNode(machine()->Int32Add(), add_0, k_1);
+ Node* const node =
+ graph()->NewNode(machine()->Int32LessThan(), k_2, add_1);
+ Reduction r = Reduce(node);
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsInt32LessThan(IsInt32Constant(c_2 - c_1 - c_0), p0));
+ }
+ }
+}
+
} // namespace compiler
} // namespace internal
} // namespace v8
« no previous file with comments | « src/compiler/machine-operator-reducer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698