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

Unified Diff: tests/language/if_conversion_vm_test.dart

Issue 14057004: Convert diamond shaped control flow into a single conditional instruction. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address Florian's 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 side-by-side diff with in-line comments
Download patch
Index: tests/language/if_conversion_vm_test.dart
diff --git a/tests/language/if_conversion_vm_test.dart b/tests/language/if_conversion_vm_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..22e6203291f96ac6251f204399738b29cf7f2be9
--- /dev/null
+++ b/tests/language/if_conversion_vm_test.dart
@@ -0,0 +1,92 @@
+// Copyright (c) 2013, 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.
+
+// Test if-convertion pass in the optimizing compiler.
+
+import "package:expect/expect.dart";
+
+f1(i) => (i == 0) ? 0 : 1;
+f2(i) => (i == 0) ? 2 : 3;
+f3(i) => (i == null) ? 0 : 1;
+f4(i) => (i == null) ? 2 : 3;
+
+f5(i) => (i != 0) ? 0 : 1;
+f6(i) => (i != 0) ? 2 : 3;
+f7(i) => (i != null) ? 0 : 1;
+f8(i) => (i != null) ? 2 : 3;
+
+f9(i) => identical(i, 0) ? 0 : 1;
+f10(i) => identical(i, 0) ? 2 : 3;
+f11(i) => identical(i, null) ? 0 : 1;
+f12(i) => identical(i, null) ? 2 : 3;
+
+f13(i) => !identical(i, 0) ? 0 : 1;
+f14(i) => !identical(i, 0) ? 2 : 3;
+f15(i) => !identical(i, null) ? 0 : 1;
+f16(i) => !identical(i, null) ? 2 : 3;
+
+const POWER_OF_2 = 0x1000000000;
+
+bigPower(i) => (i == 11) ? 0 : POWER_OF_2;
+
+main() {
+ for (var i = 0; i < 10000; i++) {
+ f1(i);
+ f2(i);
+ f3(i);
+ f4(i);
+ f5(i);
+ f6(i);
+ f7(i);
+ f8(i);
+ f9(i);
+ f10(i);
+ f11(i);
+ f12(i);
+ f13(i);
+ f14(i);
+ f15(i);
+ f16(i);
+ bigPower(i);
+ }
+
+ Expect.equals(0, f1(0));
+ Expect.equals(1, f1(44));
+ Expect.equals(2, f2(0));
+ Expect.equals(3, f2(44));
+ Expect.equals(0, f3(null));
+ Expect.equals(1, f3(44));
+ Expect.equals(2, f4(null));
+ Expect.equals(3, f4(44));
+
+ Expect.equals(1, f5(0));
+ Expect.equals(0, f5(44));
+ Expect.equals(3, f6(0));
+ Expect.equals(2, f6(44));
+ Expect.equals(1, f7(null));
+ Expect.equals(0, f7(44));
+ Expect.equals(3, f8(null));
+ Expect.equals(2, f8(44));
+
+ Expect.equals(0, f9(0));
+ Expect.equals(1, f9(44));
+ Expect.equals(2, f10(0));
+ Expect.equals(3, f10(44));
+ Expect.equals(0, f11(null));
+ Expect.equals(1, f11(44));
+ Expect.equals(2, f12(null));
+ Expect.equals(3, f12(44));
+
+ Expect.equals(1, f13(0));
+ Expect.equals(0, f13(44));
+ Expect.equals(3, f14(0));
+ Expect.equals(2, f14(44));
+ Expect.equals(1, f15(null));
+ Expect.equals(0, f15(44));
+ Expect.equals(3, f16(null));
+ Expect.equals(2, f16(44));
+
+ Expect.equals(0, bigPower(11));
+ Expect.equals(POWER_OF_2, bigPower(12));
+}
« runtime/vm/flow_graph_optimizer.cc ('K') | « runtime/vm/intermediate_language_x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698