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

Side by Side Diff: runtime/vm/flow_graph_range_analysis_test.cc

Issue 477193002: Reland r39293. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/flow_graph_range_analysis.h" 5 #include "vm/flow_graph_range_analysis.h"
6 #include "vm/unit_test.h" 6 #include "vm/unit_test.h"
7 7
8 namespace dart { 8 namespace dart {
9 9
10 10
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 Range* range_a = new Range(RangeBoundary::FromConstant(-1), 254 Range* range_a = new Range(RangeBoundary::FromConstant(-1),
255 RangeBoundary::PositiveInfinity()); 255 RangeBoundary::PositiveInfinity());
256 range_a->Clamp(RangeBoundary::kRangeBoundaryInt64); 256 range_a->Clamp(RangeBoundary::kRangeBoundaryInt64);
257 EXPECT(range_a->min().ConstantValue() == -1); 257 EXPECT(range_a->min().ConstantValue() == -1);
258 EXPECT(range_a->max().ConstantValue() == RangeBoundary::kMax); 258 EXPECT(range_a->max().ConstantValue() == RangeBoundary::kMax);
259 Range* range_b = new Range(RangeBoundary::NegativeInfinity(), 259 Range* range_b = new Range(RangeBoundary::NegativeInfinity(),
260 RangeBoundary::FromConstant(1)); 260 RangeBoundary::FromConstant(1));
261 range_b->Clamp(RangeBoundary::kRangeBoundaryInt64); 261 range_b->Clamp(RangeBoundary::kRangeBoundaryInt64);
262 EXPECT(range_b->min().ConstantValue() == RangeBoundary::kMin); 262 EXPECT(range_b->min().ConstantValue() == RangeBoundary::kMin);
263 EXPECT(range_b->max().ConstantValue() == 1); 263 EXPECT(range_b->max().ConstantValue() == 1);
264 Range* result = Range::BinaryOp(Token::kADD, 264
265 range_a, 265 {
266 range_b, 266 Range result;
267 NULL); 267 Range::BinaryOp(Token::kADD,
268 ASSERT(result != NULL); 268 range_a,
269 EXPECT(result->min().IsNegativeInfinity()); 269 range_b,
270 EXPECT(result->max().IsPositiveInfinity()); 270 NULL,
271 &result);
272 ASSERT(!Range::IsUnknown(&result));
273 EXPECT(result.min().IsNegativeInfinity());
274 EXPECT(result.max().IsPositiveInfinity());
275 }
271 276
272 // Test that [5, 10] + [0, 5] = [5, 15]. 277 // Test that [5, 10] + [0, 5] = [5, 15].
273 Range* range_c = new Range(RangeBoundary::FromConstant(5), 278 Range* range_c = new Range(RangeBoundary::FromConstant(5),
274 RangeBoundary::FromConstant(10)); 279 RangeBoundary::FromConstant(10));
275 Range* range_d = new Range(RangeBoundary::FromConstant(0), 280 Range* range_d = new Range(RangeBoundary::FromConstant(0),
276 RangeBoundary::FromConstant(5)); 281 RangeBoundary::FromConstant(5));
277 result = Range::BinaryOp(Token::kADD,
278 range_c,
279 range_d,
280 NULL);
281 ASSERT(result != NULL);
282 EXPECT(result->min().ConstantValue() == 5);
283 EXPECT(result->max().ConstantValue() == 15);
284 282
283 {
284 Range result;
285 Range::BinaryOp(Token::kADD,
286 range_c,
287 range_d,
288 NULL,
289 &result);
290 ASSERT(!Range::IsUnknown(&result));
291 EXPECT(result.min().ConstantValue() == 5);
292 EXPECT(result.max().ConstantValue() == 15);
293 }
285 294
286 // Test that [0xff, 0xfff] & [0xf, 0xf] = [0x0, 0xf]. 295 // Test that [0xff, 0xfff] & [0xf, 0xf] = [0x0, 0xf].
287 Range* range_e = new Range(RangeBoundary::FromConstant(0xff), 296 Range* range_e = new Range(RangeBoundary::FromConstant(0xff),
288 RangeBoundary::FromConstant(0xfff)); 297 RangeBoundary::FromConstant(0xfff));
289 Range* range_f = new Range(RangeBoundary::FromConstant(0xf), 298 Range* range_f = new Range(RangeBoundary::FromConstant(0xf),
290 RangeBoundary::FromConstant(0xf)); 299 RangeBoundary::FromConstant(0xf));
291 result = Range::BinaryOp(Token::kBIT_AND, 300 {
292 range_e, 301 Range result;
293 range_f, 302 Range::BinaryOp(Token::kBIT_AND,
294 NULL); 303 range_e,
295 ASSERT(result != NULL); 304 range_f,
296 EXPECT(result->min().ConstantValue() == 0x0); 305 NULL,
297 EXPECT(result->max().ConstantValue() == 0xf); 306 &result);
307 ASSERT(!Range::IsUnknown(&result));
308 EXPECT(result.min().ConstantValue() == 0x0);
309 EXPECT(result.max().ConstantValue() == 0xf);
310 }
298 } 311 }
299 312
300 313
301 TEST_CASE(RangeAdd) { 314 TEST_CASE(RangeAdd) {
302 #define TEST_RANGE_ADD(l_min, l_max, r_min, r_max, result_min, result_max) \ 315 #define TEST_RANGE_ADD(l_min, l_max, r_min, r_max, result_min, result_max) \
303 { \ 316 { \
304 RangeBoundary min, max; \ 317 RangeBoundary min, max; \
305 Range* left_range = new Range( \ 318 Range* left_range = new Range( \
306 RangeBoundary::FromConstant(l_min), \ 319 RangeBoundary::FromConstant(l_min), \
307 RangeBoundary::FromConstant(l_max)); \ 320 RangeBoundary::FromConstant(l_max)); \
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 static_cast<int64_t>(20), 531 static_cast<int64_t>(20),
519 static_cast<int64_t>(-20), 532 static_cast<int64_t>(-20),
520 static_cast<int64_t>(20), 533 static_cast<int64_t>(20),
521 RangeBoundary(), 534 RangeBoundary(),
522 RangeBoundary()); 535 RangeBoundary());
523 536
524 #undef TEST_RANGE_AND 537 #undef TEST_RANGE_AND
525 } 538 }
526 539
527 540
528 TEST_CASE(RangeMinMax) { 541 TEST_CASE(RangeIntersectionMinMax) {
542 // Test IntersectionMin and IntersectionMax methods which for constants are
543 // simply defined as Max/Min respectively.
544
529 // Constants. 545 // Constants.
530 // MIN(0, 1) == 0 546 // MIN(0, 1) == 0
531 EXPECT(RangeBoundary::Min( 547 EXPECT(RangeBoundary::IntersectionMax(
532 RangeBoundary::FromConstant(0), 548 RangeBoundary::FromConstant(0),
533 RangeBoundary::FromConstant(1), 549 RangeBoundary::FromConstant(1)).ConstantValue() == 0);
534 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == 0);
535 // MIN(0, -1) == -1 550 // MIN(0, -1) == -1
536 EXPECT(RangeBoundary::Min( 551 EXPECT(RangeBoundary::IntersectionMax(
537 RangeBoundary::FromConstant(0), 552 RangeBoundary::FromConstant(0),
538 RangeBoundary::FromConstant(-1), 553 RangeBoundary::FromConstant(-1)).ConstantValue() == -1);
539 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == -1);
540 554
541 // MIN(1, 0) == 0 555 // MIN(1, 0) == 0
542 EXPECT(RangeBoundary::Min( 556 EXPECT(RangeBoundary::IntersectionMax(
543 RangeBoundary::FromConstant(1), 557 RangeBoundary::FromConstant(1),
544 RangeBoundary::FromConstant(0), 558 RangeBoundary::FromConstant(0)).ConstantValue() == 0);
545 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == 0);
546 // MIN(-1, 0) == -1 559 // MIN(-1, 0) == -1
547 EXPECT(RangeBoundary::Min( 560 EXPECT(RangeBoundary::IntersectionMax(
548 RangeBoundary::FromConstant(-1), 561 RangeBoundary::FromConstant(-1),
549 RangeBoundary::FromConstant(0), 562 RangeBoundary::FromConstant(0)).ConstantValue() == -1);
550 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == -1);
551 563
552 // MAX(0, 1) == 1 564 // MAX(0, 1) == 1
553 EXPECT(RangeBoundary::Max( 565 EXPECT(RangeBoundary::IntersectionMin(
554 RangeBoundary::FromConstant(0), 566 RangeBoundary::FromConstant(0),
555 RangeBoundary::FromConstant(1), 567 RangeBoundary::FromConstant(1)).ConstantValue() == 1);
556 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == 1);
557 568
558 // MAX(0, -1) == 0 569 // MAX(0, -1) == 0
559 EXPECT(RangeBoundary::Max( 570 EXPECT(RangeBoundary::IntersectionMin(
560 RangeBoundary::FromConstant(0), 571 RangeBoundary::FromConstant(0),
561 RangeBoundary::FromConstant(-1), 572 RangeBoundary::FromConstant(-1)).ConstantValue() == 0);
562 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == 0);
563 573
564 // MAX(1, 0) == 1 574 // MAX(1, 0) == 1
565 EXPECT(RangeBoundary::Max( 575 EXPECT(RangeBoundary::IntersectionMin(
566 RangeBoundary::FromConstant(1), 576 RangeBoundary::FromConstant(1),
567 RangeBoundary::FromConstant(0), 577 RangeBoundary::FromConstant(0)).ConstantValue() == 1);
568 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == 1);
569 // MAX(-1, 0) == 0 578 // MAX(-1, 0) == 0
570 EXPECT(RangeBoundary::Max( 579 EXPECT(RangeBoundary::IntersectionMin(
571 RangeBoundary::FromConstant(-1), 580 RangeBoundary::FromConstant(-1),
572 RangeBoundary::FromConstant(0), 581 RangeBoundary::FromConstant(0)).ConstantValue() == 0);
573 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == 0);
574 582
575 RangeBoundary n_infinity = RangeBoundary::NegativeInfinity(); 583 RangeBoundary n_infinity = RangeBoundary::NegativeInfinity();
576 RangeBoundary p_infinity = RangeBoundary::PositiveInfinity(); 584 RangeBoundary p_infinity = RangeBoundary::PositiveInfinity();
577 585
578 // Constants vs. infinity. 586 // Constants vs. infinity.
579 EXPECT(RangeBoundary::Max( 587 EXPECT(RangeBoundary::IntersectionMin(
580 n_infinity, 588 n_infinity,
589 RangeBoundary::FromConstant(-1)).ConstantValue() == -1);
590
591 EXPECT(RangeBoundary::IntersectionMin(
581 RangeBoundary::FromConstant(-1), 592 RangeBoundary::FromConstant(-1),
582 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == -1); 593 n_infinity).ConstantValue() == -1);
583 594
584 EXPECT(RangeBoundary::Max( 595 EXPECT(RangeBoundary::IntersectionMin(
596 RangeBoundary::FromConstant(1),
597 n_infinity).ConstantValue() == 1);
598
599 EXPECT(RangeBoundary::IntersectionMin(
600 n_infinity,
601 RangeBoundary::FromConstant(1)).ConstantValue() == 1);
602
603 EXPECT(RangeBoundary::IntersectionMax(
604 p_infinity,
605 RangeBoundary::FromConstant(-1)).ConstantValue() == -1);
606
607 EXPECT(RangeBoundary::IntersectionMax(
585 RangeBoundary::FromConstant(-1), 608 RangeBoundary::FromConstant(-1),
586 n_infinity, 609 p_infinity).ConstantValue() == -1);
587 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == -1);
588 610
589 EXPECT(RangeBoundary::Max( 611 EXPECT(RangeBoundary::IntersectionMax(
590 RangeBoundary::FromConstant(1), 612 RangeBoundary::FromConstant(1),
591 n_infinity, 613 p_infinity).ConstantValue() == 1);
592 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == 1);
593 614
594 EXPECT(RangeBoundary::Max( 615 EXPECT(RangeBoundary::IntersectionMax(
595 n_infinity,
596 RangeBoundary::FromConstant(1),
597 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == 1);
598
599 EXPECT(RangeBoundary::Min(
600 p_infinity, 616 p_infinity,
601 RangeBoundary::FromConstant(-1), 617 RangeBoundary::FromConstant(1)).ConstantValue() == 1);
602 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == -1);
603
604 EXPECT(RangeBoundary::Min(
605 RangeBoundary::FromConstant(-1),
606 p_infinity,
607 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == -1);
608
609 EXPECT(RangeBoundary::Min(
610 RangeBoundary::FromConstant(1),
611 p_infinity,
612 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == 1);
613
614 EXPECT(RangeBoundary::Min(
615 p_infinity,
616 RangeBoundary::FromConstant(1),
617 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == 1);
618
619 // 64-bit values.
620 EXPECT(RangeBoundary::Min(
621 RangeBoundary(static_cast<int64_t>(kMinInt64)),
622 RangeBoundary(static_cast<int64_t>(kMinInt32)),
623 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == kMinInt64);
624
625 EXPECT(RangeBoundary::Max(
626 RangeBoundary(static_cast<int64_t>(kMinInt64)),
627 RangeBoundary(static_cast<int64_t>(kMinInt32)),
628 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == kMinInt32);
629
630 EXPECT(RangeBoundary::Min(
631 RangeBoundary(static_cast<int64_t>(kMaxInt64)),
632 RangeBoundary(static_cast<int64_t>(kMaxInt32)),
633 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == kMaxInt32);
634
635 EXPECT(RangeBoundary::Max(
636 RangeBoundary(static_cast<int64_t>(kMaxInt64)),
637 RangeBoundary(static_cast<int64_t>(kMaxInt32)),
638 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == kMaxInt64);
639 } 618 }
640 619
641 620
621 TEST_CASE(RangeJoinMinMax) {
622 // Test IntersectionMin and IntersectionMax methods which for constants are
623 // simply defined as Min/Max respectively.
624
625 // Constants.
626 EXPECT(RangeBoundary::JoinMax(
627 RangeBoundary::FromConstant(0),
628 RangeBoundary::FromConstant(1)).ConstantValue() == 1);
629 EXPECT(RangeBoundary::JoinMax(
630 RangeBoundary::FromConstant(0),
631 RangeBoundary::FromConstant(-1)).ConstantValue() == 0);
632 EXPECT(RangeBoundary::JoinMax(
633 RangeBoundary::FromConstant(1),
634 RangeBoundary::FromConstant(0)).ConstantValue() == 1);
635 EXPECT(RangeBoundary::JoinMax(
636 RangeBoundary::FromConstant(-1),
637 RangeBoundary::FromConstant(0)).ConstantValue() == 0);
638 EXPECT(RangeBoundary::JoinMin(
639 RangeBoundary::FromConstant(0),
640 RangeBoundary::FromConstant(1)).ConstantValue() == 0);
641 EXPECT(RangeBoundary::JoinMin(
642 RangeBoundary::FromConstant(0),
643 RangeBoundary::FromConstant(-1)).ConstantValue() == -1);
644 EXPECT(RangeBoundary::JoinMin(
645 RangeBoundary::FromConstant(1),
646 RangeBoundary::FromConstant(0)).ConstantValue() == 0);
647 EXPECT(RangeBoundary::JoinMin(
648 RangeBoundary::FromConstant(-1),
649 RangeBoundary::FromConstant(0)).ConstantValue() == -1);
650
651 RangeBoundary n_infinity = RangeBoundary::NegativeInfinity();
652 RangeBoundary p_infinity = RangeBoundary::PositiveInfinity();
653
654 // Constants vs. infinity.
655 EXPECT(RangeBoundary::JoinMin(
656 n_infinity,
657 RangeBoundary::FromConstant(-1)).IsSmiMinimumOrBelow());
658
659 EXPECT(RangeBoundary::JoinMin(
660 RangeBoundary::FromConstant(-1),
661 n_infinity).IsSmiMinimumOrBelow());
662
663 EXPECT(RangeBoundary::JoinMin(
664 RangeBoundary::FromConstant(1),
665 n_infinity).IsSmiMinimumOrBelow());
666
667 EXPECT(RangeBoundary::JoinMin(
668 n_infinity,
669 RangeBoundary::FromConstant(1)).IsSmiMinimumOrBelow());
670
671 EXPECT(RangeBoundary::JoinMax(
672 p_infinity,
673 RangeBoundary::FromConstant(-1)).IsSmiMaximumOrAbove());
674
675 EXPECT(RangeBoundary::JoinMax(
676 RangeBoundary::FromConstant(-1),
677 p_infinity).IsSmiMaximumOrAbove());
678
679 EXPECT(RangeBoundary::JoinMax(
680 RangeBoundary::FromConstant(1),
681 p_infinity).IsSmiMaximumOrAbove());
682
683 EXPECT(RangeBoundary::JoinMax(
684 p_infinity,
685 RangeBoundary::FromConstant(1)).IsSmiMaximumOrAbove());
686 }
687
642 } // namespace dart 688 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698