dart-sdk/tests/language_2/guess_cid_test.dart
Alexander Markov a211134136 [Tests] Update _2 tests for Dart 2.0 fixed-size integers
Also, --limit-ints-to-64-bits is enabled when running tests in _2 test
suites.

This is the re-landing of 92ebd8aefa with
fixes:

* Revert changes in pkg/dev_compiler/test/browser/language_tests.js
  and tests/language/language_dart2js.status as they describe
  'language' test suite, not 'language_2'

* Correct tests/standalone_2/io/fuzz_support.dart as file_fuzz test was
  timing out on Windows and failing on android/arm.

Closes https://github.com/dart-lang/sdk/issues/31396

Change-Id: If9ca77fca300ddc605f17a7be39d1707e9724e25
Reviewed-on: https://dart-review.googlesource.com/21700
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2017-11-17 20:28:06 +00:00

91 lines
2.4 KiB
Dart

// 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.
// Dart test program to test cid guessing optimizations.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
import "package:expect/expect.dart";
main() {
// Warmup optimizes methods.
for (int i = 0; i < 100; i++) {
Expect.equals(i, compareInt(i));
Expect.equals(i.toDouble(), compareDouble(i.toDouble()));
Expect.equals(i, binOpInt(i, i));
Expect.equals(i.toDouble(), binOpDouble(i.toDouble(), i.toDouble()));
}
Expect.equals(3, compareInt(3));
Expect.equals(-2, compareInt(-2));
Expect.equals(0, compareInt(-1));
Expect.equals(3, binOpInt(3, 3));
Expect.equals(0, binOpInt(-2, -2));
Expect.equals(3.0, binOpDouble(3.0, 3.0));
Expect.equals(0.0, binOpDouble(-2.0, -2.0));
Expect.equals(3.0, compareDouble(3.0));
Expect.equals(-2.0, compareDouble(-2.0));
Expect.equals(0.0, compareDouble(-1.0));
testOSR();
}
int compareInt(int i) {
if (i < 0) {
// Not visited in before optimization.
// Guess cid of comparison below.
if (i == -1) return 0;
}
return i;
}
double compareDouble(double i) {
if (i < 0.0) {
// Not visited in before optimization.
// Guess cid of comparison below.
if (i == -1.0) return 0.0;
}
return i;
}
int binOpInt(int i, int x) {
if (i < 0) {
// Not visited in before optimization.
// Guess cid of binary operation below.
return x + 2;
}
return i;
}
double binOpDouble(double i, double x) {
if (i < 0.0) {
// Not visited in before optimization.
// Guess cid of binary operation below.
return x + 2.0;
}
return i;
}
testOSR() {
// Foul up IC data in integer's unary minus.
var y = -0x80000000;
Expect.equals(
(0x7fffffffffffffff + 2) * 10, testLoop(10, 0x7fffffffffffffff));
// Second time no deoptimization can occur, since runtime feedback has been collected.
Expect.equals(
(0x7fffffffffffffff + 2) * 10, testLoop(10, 0x7fffffffffffffff));
}
testLoop(N, x) {
for (int i = 0; i < N; ++i) {
// Will trigger OSR. Operation in loop below will use guessed cids.
}
int sum = 0;
for (int i = 0; i < N; ++i) {
// Guess 'x' is Smi, but is actually Mint: deoptimize.
sum += x + 2;
}
return sum;
}