blob: 1ff5475e45b59bb8c7687af4e4d5bdcae8a39b68 [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
Roland Levillainc2abe2f2015-08-03 15:20:02 +010017// Note that $opt$reg$ is a marker for the optimizing compiler to test
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010018// 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));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +010030 expectEquals(-567, $opt$reg$TestAgressiveLive1(1, 2, 3, 4, 5, 6, 7));
31 expectEquals(-77, $opt$reg$TestAgressiveLive2(1, 2, 3, 4, 5, 6, 7));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010032 }
33
34 public static int $opt$reg$TestLostCopy() {
35 int a = 0;
36 int b = 0;
37 do {
38 b = a;
39 a++;
40 } while (a != 5);
41 return b;
42 }
43
44 public static int $opt$reg$TestTwoLive() {
45 int a = 0;
46 int b = 0;
47 do {
48 a++;
49 b += 3;
50 } while (a != 5);
51 return a - b;
52 }
53
54 public static int $opt$reg$TestThreeLive() {
55 int a = 0;
56 int b = 0;
57 int c = 0;
58 do {
59 a++;
60 b += 3;
61 c += 2;
62 } while (a != 5);
63 return a - b - c;
64 }
65
66 public static int $opt$reg$TestFourLive() {
67 int a = 0;
68 int b = 0;
69 int c = 0;
70 int d = 0;
71 do {
72 a++;
73 b += 3;
74 c += 2;
75 d++;
76 } while (a != 5);
77 return d;
78 }
79
80 public static int $opt$reg$TestMultipleLive() {
81 int a = 0;
82 int b = 0;
83 int c = 0;
84 int d = 0;
85 int e = 0;
86 int f = 0;
87 int g = 0;
88 do {
89 a++;
90 b++;
91 c++;
92 d++;
93 e += 3;
94 f += 2;
95 g += 2;
96 } while (a != 5);
97 return f;
98 }
99
100 public static int $opt$reg$TestWithBreakAndContinue() {
101 int a = 0;
102 int b = 0;
103 do {
104 a++;
105 if (a == 2) {
106 continue;
107 }
108 b++;
109 if (a == 5) {
110 break;
111 }
112 } while (true);
113 return a - b;
114 }
115
116 public static int $opt$reg$testSpillInIf(int a, int b, int c) {
117 int d = 0;
118 int e = 0;
119 if (a == 5) {
120 b++;
121 c++;
122 d += 2;
123 e += 3;
124 }
125
126 return a - b - c - d - e;
127 }
128
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100129 public static int $opt$reg$TestAgressiveLive1(int a, int b, int c, int d, int e, int f, int g) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100130 int h = a - b;
131 int i = c - d;
132 int j = e - f;
133 int k = 42 + g - a;
134 do {
135 b++;
136 while (k != 1) {
137 --k;
138 ++i;
139 if (i == 9) {
140 ++i;
141 }
142 j += 5;
143 }
144 k = 9;
145 h++;
146 } while (h != 5);
147 return a - b - c - d - e - f - g - h - i - j - k;
148 }
149
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100150 public static int $opt$reg$TestAgressiveLive2(int a, int b, int c, int d, int e, int f, int g) {
151 int h = a - b;
152 int i = c - d;
153 int j = e - f;
154 int k = 42 + g - a;
155 do {
156 h++;
157 } while (h != 5);
158 return a - b - c - d - e - f - g - h - i - j - k;
159 }
160
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100161 public static void expectEquals(int expected, int value) {
162 if (expected != value) {
163 throw new Error("Expected: " + expected + ", got: " + value);
164 }
165 }
166}