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

Unified 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, 9 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 | « runtime/vm/intermediate_language.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/range_analysis_test.dart
===================================================================
--- tests/language/range_analysis_test.dart (revision 20842)
+++ tests/language/range_analysis_test.dart (working copy)
@@ -24,8 +24,8 @@
// Check that range analysis does not erroneously remove overflow check.
test2() {
var width = 1073741823;
- print(foo(width - 5000, width - 1));
- print(foo(width - 5000, width));
+ Expect.equals(width - 1, foo(width - 5000, width - 1));
+ Expect.equals(width, foo(width - 5000, width));
}
foo(n, w) {
@@ -37,7 +37,83 @@
return x;
}
+
+// Test detection of unsatisfiable constraints.
+f(a, b) {
+ if (a < b) {
+ if (a > b) {
+ throw "unreachable";
+ }
+ return 2;
+ }
+ return 3;
+}
+
+f1(a, b) {
+ if (a < b) {
+ if (a > b - 1) {
+ throw "unreachable";
+ }
+ return 2;
+ }
+ return 3;
+}
+
+f2(a, b) {
+ if (a < b) {
+ if (a > b - 2) {
+ return 2;
+ }
+ throw "unreachable";
+ }
+ return 3;
+}
+
+g() {
+ var i;
+ for (i = 0; i < 10; i++) {
+ if (i < 0) throw "unreachable";
+ }
+ return i;
+}
+
+h(n) {
+ var i;
+ for (i = 0; i < n; i++) {
+ if (i < 0) throw "unreachable";
+ var j = i - 1;
+ if (j >= n - 1) throw "unreachable";
+ }
+ return i;
+}
+
+
+test3() {
+ test_fun(fun) {
+ Expect.equals(2, fun(0, 1));
+ Expect.equals(3, fun(0, 0));
+ for (var i = 0; i < 2000; i++) fun(0, 1);
+ Expect.equals(2, fun(0, 1));
+ Expect.equals(3, fun(0, 0));
+ }
+
+ test_fun(f);
+ test_fun(f1);
+ test_fun(f2);
+
+ Expect.equals(10, g());
+ for (var i = 0; i < 2000; i++) g();
+ Expect.equals(10, g());
+
+
+ Expect.equals(10, h(10));
+ for (var i = 0; i < 2000; i++) h(10);
+ Expect.equals(10, h(10));
+}
+
+
main() {
test1();
test2();
-}
+ test3();
+}
« 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