blob: 60477f9d8e9c52fc600db1db84744832ec6aae50 [file] [log] [blame]
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// Note that $opt$reg$ is a marker for the optimizing compiler to ensure
18// it does use its register allocator.
19
20public class Main {
21 public static void main(String[] args) {
22
23 expectEquals(4, $opt$reg$TestLostCopy());
24 expectEquals(-10, $opt$reg$TestTwoLive());
25 expectEquals(-20, $opt$reg$TestThreeLive());
26 expectEquals(5, $opt$reg$TestFourLive());
27 expectEquals(10, $opt$reg$TestMultipleLive());
28 expectEquals(1, $opt$reg$TestWithBreakAndContinue());
29 expectEquals(-15, $opt$reg$testSpillInIf(5, 6, 7));
30 expectEquals(-567, $opt$reg$TestAgressiveLive(1, 2, 3, 4, 5, 6, 7));
31 }
32
33 public static int $opt$reg$TestLostCopy() {
34 int a = 0;
35 int b = 0;
36 do {
37 b = a;
38 a++;
39 } while (a != 5);
40 return b;
41 }
42
43 public static int $opt$reg$TestTwoLive() {
44 int a = 0;
45 int b = 0;
46 do {
47 a++;
48 b += 3;
49 } while (a != 5);
50 return a - b;
51 }
52
53 public static int $opt$reg$TestThreeLive() {
54 int a = 0;
55 int b = 0;
56 int c = 0;
57 do {
58 a++;
59 b += 3;
60 c += 2;
61 } while (a != 5);
62 return a - b - c;
63 }
64
65 public static int $opt$reg$TestFourLive() {
66 int a = 0;
67 int b = 0;
68 int c = 0;
69 int d = 0;
70 do {
71 a++;
72 b += 3;
73 c += 2;
74 d++;
75 } while (a != 5);
76 return d;
77 }
78
79 public static int $opt$reg$TestMultipleLive() {
80 int a = 0;
81 int b = 0;
82 int c = 0;
83 int d = 0;
84 int e = 0;
85 int f = 0;
86 int g = 0;
87 do {
88 a++;
89 b++;
90 c++;
91 d++;
92 e += 3;
93 f += 2;
94 g += 2;
95 } while (a != 5);
96 return f;
97 }
98
99 public static int $opt$reg$TestWithBreakAndContinue() {
100 int a = 0;
101 int b = 0;
102 do {
103 a++;
104 if (a == 2) {
105 continue;
106 }
107 b++;
108 if (a == 5) {
109 break;
110 }
111 } while (true);
112 return a - b;
113 }
114
115 public static int $opt$reg$testSpillInIf(int a, int b, int c) {
116 int d = 0;
117 int e = 0;
118 if (a == 5) {
119 b++;
120 c++;
121 d += 2;
122 e += 3;
123 }
124
125 return a - b - c - d - e;
126 }
127
128 public static int $opt$reg$TestAgressiveLive(int a, int b, int c, int d, int e, int f, int g) {
129 int h = a - b;
130 int i = c - d;
131 int j = e - f;
132 int k = 42 + g - a;
133 do {
134 b++;
135 while (k != 1) {
136 --k;
137 ++i;
138 if (i == 9) {
139 ++i;
140 }
141 j += 5;
142 }
143 k = 9;
144 h++;
145 } while (h != 5);
146 return a - b - c - d - e - f - g - h - i - j - k;
147 }
148
149 public static void expectEquals(int expected, int value) {
150 if (expected != value) {
151 throw new Error("Expected: " + expected + ", got: " + value);
152 }
153 }
154}