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

Unified Diff: test/cctest/compiler/test-run-machops.cc

Issue 931623002: [turbofan] Optimize certain chains of Branch into a Switch. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addrssed comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/flag-definitions.h ('k') | test/mjsunit/asm/switch.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/compiler/test-run-machops.cc
diff --git a/test/cctest/compiler/test-run-machops.cc b/test/cctest/compiler/test-run-machops.cc
index 1511a01033a69b33f4063efb8de589f33703c50d..5a55ce6e23b88f74144587fbdd921f1bef14a8f4 100644
--- a/test/cctest/compiler/test-run-machops.cc
+++ b/test/cctest/compiler/test-run-machops.cc
@@ -452,13 +452,17 @@ TEST(RunSwitch1) {
int constant = 11223344;
- MLabel block0, block1, end;
- MLabel* cases[] = {&block0, &block1};
- m.Switch(m.IntPtrConstant(0), cases, arraysize(cases));
+ MLabel block0, block1, def, end;
+ MLabel* case_labels[] = {&block0, &block1};
+ int32_t case_values[] = {0, 1};
+ m.Switch(m.Int32Constant(0), &def, case_values, case_labels,
+ arraysize(case_labels));
m.Bind(&block0);
m.Goto(&end);
m.Bind(&block1);
m.Goto(&end);
+ m.Bind(&def);
+ m.Goto(&end);
m.Bind(&end);
m.Return(m.Int32Constant(constant));
@@ -469,29 +473,84 @@ TEST(RunSwitch1) {
TEST(RunSwitch2) {
RawMachineAssemblerTester<int32_t> m(kMachInt32);
- const size_t kNumCases = 255;
- int32_t values[kNumCases];
+ MLabel blocka, blockb, blockc;
+ MLabel* case_labels[] = {&blocka, &blockb};
+ int32_t case_values[] = {std::numeric_limits<int32_t>::min(),
+ std::numeric_limits<int32_t>::max()};
+ m.Switch(m.Parameter(0), &blockc, case_values, case_labels,
+ arraysize(case_labels));
+ m.Bind(&blocka);
+ m.Return(m.Int32Constant(-1));
+ m.Bind(&blockb);
+ m.Return(m.Int32Constant(1));
+ m.Bind(&blockc);
+ m.Return(m.Int32Constant(0));
+
+ CHECK_EQ(1, m.Call(std::numeric_limits<int32_t>::max()));
+ CHECK_EQ(-1, m.Call(std::numeric_limits<int32_t>::min()));
+ for (int i = -100; i < 100; i += 25) {
+ CHECK_EQ(0, m.Call(i));
+ }
+}
+
+
+TEST(RunSwitch3) {
+ RawMachineAssemblerTester<int32_t> m(kMachInt32);
+
+ MLabel blocka, blockb, blockc;
+ MLabel* case_labels[] = {&blocka, &blockb};
+ int32_t case_values[] = {std::numeric_limits<int32_t>::min() + 0,
+ std::numeric_limits<int32_t>::min() + 1};
+ m.Switch(m.Parameter(0), &blockc, case_values, case_labels,
+ arraysize(case_labels));
+ m.Bind(&blocka);
+ m.Return(m.Int32Constant(0));
+ m.Bind(&blockb);
+ m.Return(m.Int32Constant(1));
+ m.Bind(&blockc);
+ m.Return(m.Int32Constant(2));
+
+ CHECK_EQ(0, m.Call(std::numeric_limits<int32_t>::min() + 0));
+ CHECK_EQ(1, m.Call(std::numeric_limits<int32_t>::min() + 1));
+ for (int i = -100; i < 100; i += 25) {
+ CHECK_EQ(2, m.Call(i));
+ }
+}
+
+
+TEST(RunSwitch4) {
+ RawMachineAssemblerTester<int32_t> m(kMachInt32);
+
+ const size_t kNumCases = 512;
+ const size_t kNumValues = kNumCases + 1;
+ int32_t values[kNumValues];
m.main_isolate()->random_number_generator()->NextBytes(values,
sizeof(values));
- MLabel end;
- MLabel* cases[kNumCases];
- Node* results[kNumCases];
+ MLabel end, def;
+ int32_t case_values[kNumCases];
+ MLabel* case_labels[kNumCases];
+ Node* results[kNumValues];
for (size_t i = 0; i < kNumCases; ++i) {
- cases[i] = new (m.main_zone()->New(sizeof(MLabel))) MLabel;
+ case_values[i] = static_cast<int32_t>(i);
+ case_labels[i] = new (m.main_zone()->New(sizeof(MLabel))) MLabel;
}
- m.Switch(m.ConvertInt32ToIntPtr(m.Parameter(0)), cases, arraysize(cases));
+ m.Switch(m.Parameter(0), &def, case_values, case_labels,
+ arraysize(case_labels));
for (size_t i = 0; i < kNumCases; ++i) {
- m.Bind(cases[i]);
+ m.Bind(case_labels[i]);
results[i] = m.Int32Constant(values[i]);
m.Goto(&end);
}
+ m.Bind(&def);
+ results[kNumCases] = m.Int32Constant(values[kNumCases]);
+ m.Goto(&end);
m.Bind(&end);
const int num_results = static_cast<int>(arraysize(results));
Node* phi =
m.NewNode(m.common()->Phi(kMachInt32, num_results), num_results, results);
m.Return(phi);
- for (size_t i = 0; i < kNumCases; ++i) {
+ for (size_t i = 0; i < kNumValues; ++i) {
CHECK_EQ(values[i], m.Call(static_cast<int>(i)));
}
}
« no previous file with comments | « src/flag-definitions.h ('k') | test/mjsunit/asm/switch.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698