43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package org.graalvm.compiler.core.test;
|
|
24 |
|
46371
|
25 |
import org.graalvm.compiler.api.directives.GraalDirectives;
|
43972
|
26 |
import org.junit.Ignore;
|
|
27 |
import org.junit.Test;
|
|
28 |
|
|
29 |
/**
|
46459
|
30 |
* Collection of tests for {@link org.graalvm.compiler.phases.common.ConditionalEliminationPhase}
|
|
31 |
* including those that triggered bugs in this phase.
|
43972
|
32 |
*/
|
|
33 |
public class ConditionalEliminationTest11 extends ConditionalEliminationTestBase {
|
|
34 |
@SuppressWarnings("all")
|
|
35 |
public static int referenceSnippet(int a) {
|
|
36 |
if ((a & 15) != 15) {
|
46344
|
37 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
38 |
}
|
|
39 |
return 0;
|
|
40 |
}
|
|
41 |
|
|
42 |
@Test
|
|
43 |
public void test1() {
|
|
44 |
testConditionalElimination("test1Snippet", "referenceSnippet");
|
|
45 |
}
|
|
46 |
|
|
47 |
@SuppressWarnings("all")
|
|
48 |
public static int test1Snippet(int a) {
|
|
49 |
if ((a & 8) != 8) {
|
46344
|
50 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
51 |
}
|
|
52 |
if ((a & 15) != 15) {
|
46344
|
53 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
54 |
}
|
|
55 |
return 0;
|
|
56 |
}
|
|
57 |
|
|
58 |
@SuppressWarnings("all")
|
|
59 |
public static int test2Snippet(int a) {
|
|
60 |
if ((a & 8) == 0) {
|
46344
|
61 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
62 |
}
|
|
63 |
if ((a & 15) != 15) {
|
46344
|
64 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
65 |
}
|
|
66 |
return 0;
|
|
67 |
}
|
|
68 |
|
|
69 |
@Test
|
|
70 |
public void test2() {
|
|
71 |
testConditionalElimination("test2Snippet", "referenceSnippet");
|
|
72 |
}
|
|
73 |
|
|
74 |
@SuppressWarnings("all")
|
|
75 |
public static int test3Snippet(int a) {
|
|
76 |
if ((a & 15) != 15) {
|
46344
|
77 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
78 |
}
|
|
79 |
if ((a & 8) != 8) {
|
46344
|
80 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
81 |
}
|
|
82 |
return 0;
|
|
83 |
}
|
|
84 |
|
|
85 |
@Test
|
|
86 |
public void test3() {
|
|
87 |
// Test forward elimination of bitwise tests
|
|
88 |
testConditionalElimination("test3Snippet", "referenceSnippet");
|
|
89 |
}
|
|
90 |
|
|
91 |
@SuppressWarnings("all")
|
|
92 |
public static int test4Snippet(int a) {
|
|
93 |
if ((a & 15) != 15) {
|
46344
|
94 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
95 |
}
|
|
96 |
if ((a & 8) == 0) {
|
46344
|
97 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
98 |
}
|
|
99 |
return 0;
|
|
100 |
}
|
|
101 |
|
|
102 |
@Test
|
|
103 |
public void test4() {
|
|
104 |
// Test forward elimination of bitwise tests
|
|
105 |
testConditionalElimination("test4Snippet", "referenceSnippet");
|
|
106 |
}
|
|
107 |
|
|
108 |
public static int test5Snippet(int a) {
|
|
109 |
if ((a & 5) == 5) {
|
46344
|
110 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
111 |
}
|
|
112 |
if ((a & 7) != 0) {
|
|
113 |
return 0;
|
|
114 |
}
|
|
115 |
return 1;
|
|
116 |
}
|
|
117 |
|
|
118 |
@Test
|
|
119 |
public void test5() {
|
|
120 |
// Shouldn't be possible to optimize this
|
|
121 |
testConditionalElimination("test5Snippet", "test5Snippet");
|
|
122 |
}
|
|
123 |
|
|
124 |
public static int test6Snippet(int a) {
|
|
125 |
if ((a & 8) != 0) {
|
48861
|
126 |
GraalDirectives.deoptimize();
|
43972
|
127 |
}
|
|
128 |
if ((a & 15) != 15) {
|
48861
|
129 |
GraalDirectives.deoptimize();
|
43972
|
130 |
}
|
|
131 |
return 0;
|
|
132 |
}
|
|
133 |
|
|
134 |
public static int reference6Snippet(int a) {
|
|
135 |
if ((a & 8) != 0) {
|
48861
|
136 |
GraalDirectives.deoptimize();
|
43972
|
137 |
}
|
48861
|
138 |
GraalDirectives.deoptimize();
|
43972
|
139 |
return 0;
|
|
140 |
}
|
|
141 |
|
|
142 |
@Test
|
|
143 |
public void test6() {
|
|
144 |
testConditionalElimination("test6Snippet", "reference6Snippet");
|
|
145 |
}
|
|
146 |
|
|
147 |
public static int test7Snippet(int a) {
|
|
148 |
if ((a & 15) == 15) {
|
46344
|
149 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
150 |
}
|
|
151 |
if ((a & 8) == 8) {
|
46344
|
152 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
153 |
}
|
|
154 |
return a;
|
|
155 |
}
|
|
156 |
|
|
157 |
public static int reference7Snippet(int a) {
|
|
158 |
if ((a & 8) == 8) {
|
46344
|
159 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
160 |
}
|
|
161 |
return a;
|
|
162 |
}
|
|
163 |
|
|
164 |
@Test
|
|
165 |
public void test7() {
|
|
166 |
testConditionalElimination("test7Snippet", "reference7Snippet");
|
|
167 |
}
|
|
168 |
|
|
169 |
public static int test8Snippet(int a) {
|
|
170 |
if ((a & 16) == 16) {
|
46344
|
171 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
172 |
}
|
|
173 |
if ((a & 8) != 8) {
|
46344
|
174 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
175 |
}
|
|
176 |
if ((a & 44) != 44) {
|
46344
|
177 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
178 |
}
|
|
179 |
return a;
|
|
180 |
}
|
|
181 |
|
|
182 |
public static int reference8Snippet(int a) {
|
|
183 |
if ((a & 60) != 44) {
|
46344
|
184 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
185 |
}
|
|
186 |
return a;
|
|
187 |
}
|
|
188 |
|
|
189 |
@Ignore("requires merging of bit tests")
|
|
190 |
@Test
|
|
191 |
public void test8() {
|
|
192 |
testConditionalElimination("test8Snippet", "reference8Snippet");
|
|
193 |
}
|
|
194 |
|
|
195 |
public static int test9Snippet(int a) {
|
|
196 |
if ((a & 16) == 16) {
|
46344
|
197 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
198 |
}
|
|
199 |
if ((a & 8) != 8) {
|
46344
|
200 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
201 |
}
|
|
202 |
if ((a & 44) != 44) {
|
46344
|
203 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
204 |
}
|
|
205 |
if (a != 44) {
|
46344
|
206 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
207 |
}
|
|
208 |
return a;
|
|
209 |
}
|
|
210 |
|
|
211 |
public static int reference9Snippet(int a) {
|
|
212 |
if (a != 44) {
|
46344
|
213 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
214 |
}
|
|
215 |
return a;
|
|
216 |
}
|
|
217 |
|
|
218 |
@Test
|
|
219 |
public void test9() {
|
|
220 |
testConditionalElimination("test9Snippet", "reference9Snippet");
|
|
221 |
}
|
|
222 |
|
|
223 |
static class ByteHolder {
|
|
224 |
public byte b;
|
|
225 |
|
|
226 |
byte byteValue() {
|
|
227 |
return b;
|
|
228 |
}
|
|
229 |
}
|
|
230 |
|
|
231 |
public static int test10Snippet(ByteHolder b) {
|
|
232 |
int v = b.byteValue();
|
|
233 |
long a = v & 0xffffffff;
|
|
234 |
if (v != 44) {
|
46344
|
235 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
236 |
}
|
|
237 |
if ((a & 16) == 16) {
|
46344
|
238 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
239 |
}
|
|
240 |
if ((a & 8) != 8) {
|
46344
|
241 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
242 |
}
|
|
243 |
if ((a & 44) != 44) {
|
46344
|
244 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
245 |
}
|
|
246 |
|
|
247 |
return v;
|
|
248 |
}
|
|
249 |
|
|
250 |
public static int reference10Snippet(ByteHolder b) {
|
|
251 |
byte v = b.byteValue();
|
|
252 |
if (v != 44) {
|
46344
|
253 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
254 |
}
|
|
255 |
return v;
|
|
256 |
}
|
|
257 |
|
|
258 |
@Test
|
46344
|
259 |
@Ignore
|
43972
|
260 |
public void test10() {
|
|
261 |
testConditionalElimination("test10Snippet", "reference10Snippet");
|
|
262 |
}
|
|
263 |
|
|
264 |
public static int test11Snippet(ByteHolder b) {
|
|
265 |
int v = b.byteValue();
|
|
266 |
long a = v & 0xffffffff;
|
|
267 |
|
|
268 |
if ((a & 16) == 16) {
|
46344
|
269 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
270 |
}
|
|
271 |
if ((a & 8) != 8) {
|
46344
|
272 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
273 |
}
|
|
274 |
if ((a & 44) != 44) {
|
46344
|
275 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
276 |
}
|
|
277 |
if (v != 44) {
|
46344
|
278 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
279 |
}
|
|
280 |
return v;
|
|
281 |
}
|
|
282 |
|
|
283 |
public static int reference11Snippet(ByteHolder b) {
|
|
284 |
byte v = b.byteValue();
|
|
285 |
if (v != 44) {
|
46344
|
286 |
GraalDirectives.deoptimizeAndInvalidate();
|
43972
|
287 |
}
|
|
288 |
return v;
|
|
289 |
}
|
|
290 |
|
|
291 |
@Test
|
46344
|
292 |
@Ignore
|
43972
|
293 |
public void test11() {
|
|
294 |
testConditionalElimination("test11Snippet", "reference11Snippet");
|
|
295 |
}
|
|
296 |
|
|
297 |
}
|