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

Side by Side Diff: tests/language/range_analysis_test.dart

Issue 13469013: Use range analysis to improve constant propagation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: addressed comments Created 7 years, 8 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
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // Dart test program for constructors and initializers. 4 // Dart test program for constructors and initializers.
5 5
6 // Check that range analysis does not enter infinite loop trying to propagate 6 // Check that range analysis does not enter infinite loop trying to propagate
7 // ranges through dependant phis. 7 // ranges through dependant phis.
8 bar() { 8 bar() {
9 var sum = 0; 9 var sum = 0;
10 for (var i = 0; i < 10; i++) { 10 for (var i = 0; i < 10; i++) {
11 for (var j = i - 1; j >= 0; j--) { 11 for (var j = i - 1; j >= 0; j--) {
12 for (var k = j; k < i; k++) { 12 for (var k = j; k < i; k++) {
13 sum += (i + j + k); 13 sum += (i + j + k);
14 } 14 }
15 } 15 }
16 } 16 }
17 return sum; 17 return sum;
18 } 18 }
19 19
20 test1() { 20 test1() {
21 for (var i = 0; i < 1000; i++) bar(); 21 for (var i = 0; i < 1000; i++) bar();
22 } 22 }
23 23
24 // Check that range analysis does not erroneously remove overflow check. 24 // Check that range analysis does not erroneously remove overflow check.
25 test2() { 25 test2() {
26 var width = 1073741823; 26 var width = 1073741823;
27 print(foo(width - 5000, width - 1)); 27 Expect.equals(width - 1, foo(width - 5000, width - 1));
28 print(foo(width - 5000, width)); 28 Expect.equals(width, foo(width - 5000, width));
29 } 29 }
30 30
31 foo(n, w) { 31 foo(n, w) {
32 var x = 0; 32 var x = 0;
33 for (var i = n; i <= w; i++) { 33 for (var i = n; i <= w; i++) {
34 Expect.isTrue(i > 0); 34 Expect.isTrue(i > 0);
35 x = i; 35 x = i;
36 } 36 }
37 return x; 37 return x;
38 } 38 }
39 39
40
41 // Test detection of unsatisfiable constraints.
42 f(a, b) {
43 if (a < b) {
44 if (a > b) {
45 throw "unreachable";
46 }
47 return 2;
48 }
49 return 3;
50 }
51
52 f1(a, b) {
53 if (a < b) {
54 if (a > b - 1) {
55 throw "unreachable";
56 }
57 return 2;
58 }
59 return 3;
60 }
61
62 f2(a, b) {
63 if (a < b) {
64 if (a > b - 2) {
65 return 2;
66 }
67 throw "unreachable";
68 }
69 return 3;
70 }
71
72 g() {
73 var i;
74 for (i = 0; i < 10; i++) {
75 if (i < 0) throw "unreachable";
76 }
77 return i;
78 }
79
80 h(n) {
81 var i;
82 for (i = 0; i < n; i++) {
83 if (i < 0) throw "unreachable";
84 var j = i - 1;
85 if (j >= n - 1) throw "unreachable";
86 }
87 return i;
88 }
89
90
91 test3() {
92 test_fun(fun) {
93 Expect.equals(2, fun(0, 1));
94 Expect.equals(3, fun(0, 0));
95 for (var i = 0; i < 2000; i++) fun(0, 1);
96 Expect.equals(2, fun(0, 1));
97 Expect.equals(3, fun(0, 0));
98 }
99
100 test_fun(f);
101 test_fun(f1);
102 test_fun(f2);
103
104 Expect.equals(10, g());
105 for (var i = 0; i < 2000; i++) g();
106 Expect.equals(10, g());
107
108
109 Expect.equals(10, h(10));
110 for (var i = 0; i < 2000; i++) h(10);
111 Expect.equals(10, h(10));
112 }
113
114
40 main() { 115 main() {
41 test1(); 116 test1();
42 test2(); 117 test2();
43 } 118 test3();
119 }
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698