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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/flag-definitions.h ('k') | test/mjsunit/asm/switch.js » ('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 <cmath> 5 #include <cmath>
6 #include <functional> 6 #include <functional>
7 #include <limits> 7 #include <limits>
8 8
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 445
446 CHECK_EQ(10, m.Call()); 446 CHECK_EQ(10, m.Call());
447 } 447 }
448 448
449 449
450 TEST(RunSwitch1) { 450 TEST(RunSwitch1) {
451 RawMachineAssemblerTester<int32_t> m; 451 RawMachineAssemblerTester<int32_t> m;
452 452
453 int constant = 11223344; 453 int constant = 11223344;
454 454
455 MLabel block0, block1, end; 455 MLabel block0, block1, def, end;
456 MLabel* cases[] = {&block0, &block1}; 456 MLabel* case_labels[] = {&block0, &block1};
457 m.Switch(m.IntPtrConstant(0), cases, arraysize(cases)); 457 int32_t case_values[] = {0, 1};
458 m.Switch(m.Int32Constant(0), &def, case_values, case_labels,
459 arraysize(case_labels));
458 m.Bind(&block0); 460 m.Bind(&block0);
459 m.Goto(&end); 461 m.Goto(&end);
460 m.Bind(&block1); 462 m.Bind(&block1);
461 m.Goto(&end); 463 m.Goto(&end);
464 m.Bind(&def);
465 m.Goto(&end);
462 m.Bind(&end); 466 m.Bind(&end);
463 m.Return(m.Int32Constant(constant)); 467 m.Return(m.Int32Constant(constant));
464 468
465 CHECK_EQ(constant, m.Call()); 469 CHECK_EQ(constant, m.Call());
466 } 470 }
467 471
468 472
469 TEST(RunSwitch2) { 473 TEST(RunSwitch2) {
470 RawMachineAssemblerTester<int32_t> m(kMachInt32); 474 RawMachineAssemblerTester<int32_t> m(kMachInt32);
471 475
472 const size_t kNumCases = 255; 476 MLabel blocka, blockb, blockc;
473 int32_t values[kNumCases]; 477 MLabel* case_labels[] = {&blocka, &blockb};
478 int32_t case_values[] = {std::numeric_limits<int32_t>::min(),
479 std::numeric_limits<int32_t>::max()};
480 m.Switch(m.Parameter(0), &blockc, case_values, case_labels,
481 arraysize(case_labels));
482 m.Bind(&blocka);
483 m.Return(m.Int32Constant(-1));
484 m.Bind(&blockb);
485 m.Return(m.Int32Constant(1));
486 m.Bind(&blockc);
487 m.Return(m.Int32Constant(0));
488
489 CHECK_EQ(1, m.Call(std::numeric_limits<int32_t>::max()));
490 CHECK_EQ(-1, m.Call(std::numeric_limits<int32_t>::min()));
491 for (int i = -100; i < 100; i += 25) {
492 CHECK_EQ(0, m.Call(i));
493 }
494 }
495
496
497 TEST(RunSwitch3) {
498 RawMachineAssemblerTester<int32_t> m(kMachInt32);
499
500 MLabel blocka, blockb, blockc;
501 MLabel* case_labels[] = {&blocka, &blockb};
502 int32_t case_values[] = {std::numeric_limits<int32_t>::min() + 0,
503 std::numeric_limits<int32_t>::min() + 1};
504 m.Switch(m.Parameter(0), &blockc, case_values, case_labels,
505 arraysize(case_labels));
506 m.Bind(&blocka);
507 m.Return(m.Int32Constant(0));
508 m.Bind(&blockb);
509 m.Return(m.Int32Constant(1));
510 m.Bind(&blockc);
511 m.Return(m.Int32Constant(2));
512
513 CHECK_EQ(0, m.Call(std::numeric_limits<int32_t>::min() + 0));
514 CHECK_EQ(1, m.Call(std::numeric_limits<int32_t>::min() + 1));
515 for (int i = -100; i < 100; i += 25) {
516 CHECK_EQ(2, m.Call(i));
517 }
518 }
519
520
521 TEST(RunSwitch4) {
522 RawMachineAssemblerTester<int32_t> m(kMachInt32);
523
524 const size_t kNumCases = 512;
525 const size_t kNumValues = kNumCases + 1;
526 int32_t values[kNumValues];
474 m.main_isolate()->random_number_generator()->NextBytes(values, 527 m.main_isolate()->random_number_generator()->NextBytes(values,
475 sizeof(values)); 528 sizeof(values));
476 MLabel end; 529 MLabel end, def;
477 MLabel* cases[kNumCases]; 530 int32_t case_values[kNumCases];
478 Node* results[kNumCases]; 531 MLabel* case_labels[kNumCases];
532 Node* results[kNumValues];
479 for (size_t i = 0; i < kNumCases; ++i) { 533 for (size_t i = 0; i < kNumCases; ++i) {
480 cases[i] = new (m.main_zone()->New(sizeof(MLabel))) MLabel; 534 case_values[i] = static_cast<int32_t>(i);
535 case_labels[i] = new (m.main_zone()->New(sizeof(MLabel))) MLabel;
481 } 536 }
482 m.Switch(m.ConvertInt32ToIntPtr(m.Parameter(0)), cases, arraysize(cases)); 537 m.Switch(m.Parameter(0), &def, case_values, case_labels,
538 arraysize(case_labels));
483 for (size_t i = 0; i < kNumCases; ++i) { 539 for (size_t i = 0; i < kNumCases; ++i) {
484 m.Bind(cases[i]); 540 m.Bind(case_labels[i]);
485 results[i] = m.Int32Constant(values[i]); 541 results[i] = m.Int32Constant(values[i]);
486 m.Goto(&end); 542 m.Goto(&end);
487 } 543 }
544 m.Bind(&def);
545 results[kNumCases] = m.Int32Constant(values[kNumCases]);
546 m.Goto(&end);
488 m.Bind(&end); 547 m.Bind(&end);
489 const int num_results = static_cast<int>(arraysize(results)); 548 const int num_results = static_cast<int>(arraysize(results));
490 Node* phi = 549 Node* phi =
491 m.NewNode(m.common()->Phi(kMachInt32, num_results), num_results, results); 550 m.NewNode(m.common()->Phi(kMachInt32, num_results), num_results, results);
492 m.Return(phi); 551 m.Return(phi);
493 552
494 for (size_t i = 0; i < kNumCases; ++i) { 553 for (size_t i = 0; i < kNumValues; ++i) {
495 CHECK_EQ(values[i], m.Call(static_cast<int>(i))); 554 CHECK_EQ(values[i], m.Call(static_cast<int>(i)));
496 } 555 }
497 } 556 }
498 557
499 558
500 TEST(RunLoadInt32) { 559 TEST(RunLoadInt32) {
501 RawMachineAssemblerTester<int32_t> m; 560 RawMachineAssemblerTester<int32_t> m;
502 561
503 int32_t p1 = 0; // loads directly from this location. 562 int32_t p1 = 0; // loads directly from this location.
504 m.Return(m.LoadFromPointer(&p1, kMachInt32)); 563 m.Return(m.LoadFromPointer(&p1, kMachInt32));
(...skipping 4223 matching lines...) Expand 10 before | Expand all | Expand 10 after
4728 m.Float64RoundTiesAway(m.LoadFromPointer(&input, kMachFloat64))); 4787 m.Float64RoundTiesAway(m.LoadFromPointer(&input, kMachFloat64)));
4729 m.Return(m.Int32Constant(0)); 4788 m.Return(m.Int32Constant(0));
4730 for (size_t i = 0; i < arraysize(kValues); ++i) { 4789 for (size_t i = 0; i < arraysize(kValues); ++i) {
4731 input = kValues[i]; 4790 input = kValues[i];
4732 CHECK_EQ(0, m.Call()); 4791 CHECK_EQ(0, m.Call());
4733 double expected = round(kValues[i]); 4792 double expected = round(kValues[i]);
4734 CHECK_EQ(expected, result); 4793 CHECK_EQ(expected, result);
4735 } 4794 }
4736 } 4795 }
4737 #endif // V8_TURBOFAN_TARGET 4796 #endif // V8_TURBOFAN_TARGET
OLDNEW
« 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