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

Unified Diff: tests/standalone/array_bounds_check_generalization_test.dart

Issue 619903002: Generalize bounds checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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
« runtime/vm/intermediate_language_ia32.cc ('K') | « runtime/vm/stack_frame.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/array_bounds_check_generalization_test.dart
diff --git a/tests/standalone/array_bounds_check_generalization_test.dart b/tests/standalone/array_bounds_check_generalization_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2f173d4fbd0348347c808149f416da0336199354
--- /dev/null
+++ b/tests/standalone/array_bounds_check_generalization_test.dart
@@ -0,0 +1,75 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// VMOptions=--optimization_counter_threshold=10 --no-use-osr
+
+import "package:expect/expect.dart";
+
+test1(a, start, step, N) {
+ var e;
+ for (var i = 0; i < N; i++) {
Florian Schneider 2014/10/07 11:40:48 Can you add a test with a nested loop as well? e.g
Vyacheslav Egorov (Google) 2014/10/07 18:57:27 Done
+ e = a[start + i * step];
+ }
+ return e;
+}
+
+test2(a, b) {
+ var e;
+ for (var i = 0, j = 0, k = 0; i < a.length; i++, j++, k++) {
+ e = b[k] = a[j];
+ }
+ return e;
+}
+
+test3(a, b) {
+ var e;
+ for (var i = 0, j = 1, k = 0; i < a.length - 1; i++, j++, k++) {
+ e = b[k] = a[j - 1];
+ }
+ return e;
+}
+
+test4(a, b) {
+ var e;
+ if (a.length < 2) {
+ return;
+ }
+
+ for (var i = 0, j = 1, k = 0; i < a.length - 1; i++, j++, k++) {
+ e = b[k] = a[j - 1];
+ }
+ return e;
+}
+
+test5(a, b, k0) {
+ var e;
+ if (a.length < 2) {
+ return;
+ }
+
+ if (k0 > 1) {
+ return;
+ }
+
+ for (var i = 0, j = 1, k = 0; i < a.length - 1; i++, j++, k++) {
+ e = b[k - k0] = a[j - 1];
+ }
+ return e;
+}
+
+main() {
+ var a = const [0, 1, 2, 3, 4, 5, 6, 7];
+ var b = new List(a.length);
+ for (var i = 0; i < 10000; i++) {
+ Expect.equals(a.last, test1(a, 0, 1, a.length));
+ Expect.equals(a.last, test2(a, b));
+ Expect.equals(a[a.length - 2], test3(a, b));
+ Expect.equals(a[a.length - 2], test4(a, b));
+ Expect.equals(a[a.length - 2], test5(a, b, 0));
+ }
+
+ test1(a, 0, 2, a.length ~/ 2);
+ Expect.throws(() => test1(a, 1, 1, a.length));
+ Expect.throws(() => test2(a, new List(a.length - 1)));
+}
« runtime/vm/intermediate_language_ia32.cc ('K') | « runtime/vm/stack_frame.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698