OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // VMOptions=--optimization_counter_threshold=10 | 4 // VMOptions=--optimization_counter_threshold=10 |
5 | 5 |
6 // Test branch optimization for TestSmiInstr | 6 // Test branch optimization for TestSmiInstr |
7 | 7 |
8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
9 | 9 |
10 test(bool b) { | 10 test1(a, bool b) { |
11 var a = 0; | |
12 if (b) { | 11 if (b) { |
13 a++; | 12 a++; |
14 } else { | 13 } else { |
15 a += 2; | 14 a += 2; |
16 } | 15 } |
17 if (a & 1 == 0) { | 16 if (a & 1 == 0) { |
18 return "even"; | 17 return "even"; |
19 } | 18 } |
20 return "odd"; | 19 return "odd"; |
21 } | 20 } |
22 | 21 |
23 main() { | 22 test2(a, bool b) { |
24 Expect.equals("odd", test(true)); | 23 if (b) { |
25 Expect.equals("even", test(false)); | 24 a++; |
26 for (var i=0; i<20; i++) test(false); | 25 } else { |
27 Expect.equals("odd", test(true)); | 26 a += 2; |
28 Expect.equals("even", test(false)); | 27 } |
| 28 if (a & 1 == 1) { |
| 29 return "odd"; |
| 30 } |
| 31 return "even"; |
29 } | 32 } |
30 | 33 |
| 34 test3(a, bool b) { |
| 35 return test1(0, b); |
| 36 } |
| 37 |
| 38 test4(a, bool b) { |
| 39 return test2(0, b); |
| 40 } |
| 41 |
| 42 run(test) { |
| 43 Expect.equals("odd", test(0, true)); |
| 44 Expect.equals("even", test(0, false)); |
| 45 for (var i=0; i<20; i++) test(0, false); |
| 46 Expect.equals("odd", test(0, true)); |
| 47 Expect.equals("even", test(0, false)); |
| 48 } |
| 49 |
| 50 main() { |
| 51 run(test1); |
| 52 run(test2); |
| 53 run(test3); |
| 54 run(test4); |
| 55 } |
| 56 |
OLD | NEW |