| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Dart test program to test arithmetic operations. |
| 5 // VMOptions=--optimization-counter-threshold=10 |
| 6 |
| 7 import "package:expect/expect.dart"; |
| 8 |
| 9 main() { |
| 10 // Warmup optimizes methods. |
| 11 for (int i = 0; i < 100; i++) { |
| 12 Expect.equals(i, compareInt(i)); |
| 13 Expect.equals(i.toDouble(), compareDouble(i.toDouble())); |
| 14 Expect.equals(i, binOpInt(i, i)); |
| 15 Expect.equals(i.toDouble(), binOpDouble(i.toDouble(), i.toDouble())); |
| 16 } |
| 17 Expect.equals(3, compareInt(3)); |
| 18 Expect.equals(-2, compareInt(-2)); |
| 19 Expect.equals(0, compareInt(-1)); |
| 20 |
| 21 Expect.equals(3, binOpInt(3, 3)); |
| 22 Expect.equals(0, binOpInt(-2, -2)); |
| 23 |
| 24 Expect.equals(3.0, binOpDouble(3.0, 3.0)); |
| 25 Expect.equals(0.0, binOpDouble(-2.0, -2.0)); |
| 26 |
| 27 Expect.equals(3.0, compareDouble(3.0)); |
| 28 Expect.equals(-2.0, compareDouble(-2.0)); |
| 29 Expect.equals(0.0, compareDouble(-1.0)); |
| 30 |
| 31 testOSR(); |
| 32 } |
| 33 |
| 34 int compareInt(int i) { |
| 35 if (i < 0) { |
| 36 // Not visited in before optimization. |
| 37 // Guess cid of comparison below. |
| 38 if (i == -1) return 0; |
| 39 } |
| 40 return i; |
| 41 } |
| 42 |
| 43 double compareDouble(double i) { |
| 44 if (i < 0.0) { |
| 45 // Not visited in before optimization. |
| 46 // Guess cid of comparison below. |
| 47 if (i == -1.0) return 0.0; |
| 48 } |
| 49 return i; |
| 50 } |
| 51 |
| 52 int binOpInt(int i, int x) { |
| 53 if (i < 0) { |
| 54 // Not visited in before optimization. |
| 55 // Guess cid of binary operation below. |
| 56 return x + 2; |
| 57 } |
| 58 return i; |
| 59 } |
| 60 |
| 61 double binOpDouble(double i, double x) { |
| 62 if (i < 0.0) { |
| 63 // Not visited in before optimization. |
| 64 // Guess cid of binary operation below. |
| 65 return x + 2.0; |
| 66 } |
| 67 return i; |
| 68 } |
| 69 |
| 70 testOSR() { |
| 71 // Foul up IC data in integer's unary minus. |
| 72 var y = -0x80000000; |
| 73 Expect.equals(1475739525896764129300, testLoop(10, 0x80000000000000000)); |
| 74 // Second time no deoptimization can occur, since runtime feedback has been co
llected. |
| 75 Expect.equals(1475739525896764129300, testLoop(10, 0x80000000000000000)); |
| 76 } |
| 77 |
| 78 testLoop(N, x) { |
| 79 for (int i = 0; i < N; ++i) { |
| 80 // Will trigger OSR. Operation in loop below will use guessed cids. |
| 81 } |
| 82 int sum = 0; |
| 83 for (int i = 0; i < N; ++i) { |
| 84 // Guess 'x' is Smi, but is actually Bigint: deoptimize. |
| 85 sum += x + 2; |
| 86 } |
| 87 return sum; |
| 88 } |
| OLD | NEW |