43972
|
1 |
/*
|
58299
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.core.test;
|
|
26 |
|
|
27 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED;
|
|
28 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED;
|
|
29 |
|
|
30 |
import org.graalvm.compiler.api.directives.GraalDirectives;
|
|
31 |
import org.graalvm.compiler.graph.NodeClass;
|
|
32 |
import org.graalvm.compiler.loop.InductionVariable;
|
|
33 |
import org.graalvm.compiler.loop.LoopsData;
|
|
34 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
49451
|
35 |
import org.graalvm.compiler.nodes.ConstantNode;
|
48861
|
36 |
import org.graalvm.compiler.nodes.NodeView;
|
43972
|
37 |
import org.graalvm.compiler.nodes.StructuredGraph;
|
|
38 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
39 |
import org.graalvm.compiler.nodes.calc.FloatingNode;
|
|
40 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
|
|
41 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
|
46459
|
42 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
43972
|
43 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration;
|
|
44 |
import org.graalvm.compiler.nodes.spi.LIRLowerable;
|
|
45 |
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
|
52910
|
46 |
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
|
47 |
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
48861
|
48 |
import org.junit.Test;
|
43972
|
49 |
|
|
50 |
import jdk.vm.ci.meta.JavaKind;
|
|
51 |
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
52 |
|
|
53 |
public class CountedLoopTest extends GraalCompilerTest {
|
|
54 |
|
|
55 |
@FunctionalInterface
|
|
56 |
private interface IVProperty {
|
|
57 |
ValueNode get(InductionVariable iv);
|
|
58 |
}
|
|
59 |
|
49451
|
60 |
@FunctionalInterface
|
|
61 |
private interface StaticIVProperty {
|
|
62 |
long get(InductionVariable iv);
|
|
63 |
}
|
|
64 |
|
|
65 |
@FunctionalInterface
|
|
66 |
private interface IVPredicate {
|
|
67 |
boolean test(InductionVariable iv);
|
|
68 |
}
|
|
69 |
|
43972
|
70 |
/**
|
|
71 |
* Get a property of an induction variable.
|
|
72 |
*/
|
58299
|
73 |
@SuppressWarnings("unused")
|
|
74 |
private static int get(IVProperty property, StaticIVProperty staticProperty, IVPredicate constantCheck, int iv) {
|
49451
|
75 |
return iv;
|
|
76 |
}
|
|
77 |
|
58299
|
78 |
@SuppressWarnings("unused")
|
|
79 |
private static int get(IVProperty property, int iv) {
|
49451
|
80 |
return iv;
|
|
81 |
}
|
|
82 |
|
58299
|
83 |
@SuppressWarnings("unused")
|
|
84 |
private static long get(IVProperty property, StaticIVProperty staticProperty, IVPredicate constantCheck,
|
49451
|
85 |
long iv) {
|
|
86 |
return iv;
|
|
87 |
}
|
|
88 |
|
58299
|
89 |
@SuppressWarnings("unused")
|
|
90 |
private static long get(IVProperty property, long iv) {
|
43972
|
91 |
return iv;
|
|
92 |
}
|
|
93 |
|
|
94 |
private static class Result {
|
49451
|
95 |
public long extremum;
|
|
96 |
public long exitValue;
|
43972
|
97 |
|
|
98 |
@Override
|
|
99 |
public int hashCode() {
|
|
100 |
final int prime = 31;
|
|
101 |
int result = 1;
|
49451
|
102 |
result = prime * result + Long.hashCode(exitValue);
|
|
103 |
result = prime * result + Long.hashCode(extremum);
|
43972
|
104 |
return result;
|
|
105 |
}
|
|
106 |
|
|
107 |
@Override
|
|
108 |
public boolean equals(Object obj) {
|
|
109 |
if (!(obj instanceof Result)) {
|
|
110 |
return false;
|
|
111 |
}
|
|
112 |
Result other = (Result) obj;
|
|
113 |
return extremum == other.extremum && exitValue == other.exitValue;
|
|
114 |
}
|
|
115 |
|
|
116 |
@Override
|
|
117 |
public String toString() {
|
|
118 |
return String.format("extremum = %d, exitValue = %d", extremum, exitValue);
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
public static Result incrementSnippet(int start, int limit, int step) {
|
|
123 |
int i;
|
|
124 |
int inc = ((step - 1) & 0xFFFF) + 1; // make sure this value is always strictly positive
|
|
125 |
Result ret = new Result();
|
|
126 |
for (i = start; i < limit; i += inc) {
|
|
127 |
GraalDirectives.controlFlowAnchor();
|
49451
|
128 |
ret.extremum = get(InductionVariable::extremumNode, InductionVariable::constantExtremum, InductionVariable::isConstantExtremum, i);
|
43972
|
129 |
}
|
|
130 |
ret.exitValue = get(InductionVariable::exitValueNode, i);
|
|
131 |
return ret;
|
|
132 |
}
|
|
133 |
|
|
134 |
@Test
|
|
135 |
public void increment1() {
|
49451
|
136 |
testCounted("incrementSnippet", 0, 256, 1);
|
43972
|
137 |
}
|
|
138 |
|
|
139 |
@Test
|
|
140 |
public void increment2() {
|
49451
|
141 |
testCounted("incrementSnippet", 0, 256, 2);
|
43972
|
142 |
}
|
|
143 |
|
|
144 |
@Test
|
|
145 |
public void increment3() {
|
49451
|
146 |
testCounted("incrementSnippet", 0, 256, 3);
|
43972
|
147 |
}
|
|
148 |
|
48861
|
149 |
@Test
|
|
150 |
public void increment4() {
|
49451
|
151 |
testCounted("incrementSnippet", -10, 1, Integer.MAX_VALUE);
|
48861
|
152 |
}
|
|
153 |
|
|
154 |
@Test
|
|
155 |
public void increment5() {
|
58299
|
156 |
testRemovableCounted("incrementSnippet", 256, 256, 1);
|
48861
|
157 |
}
|
|
158 |
|
|
159 |
@Test
|
|
160 |
public void increment6() {
|
58299
|
161 |
testRemovableCounted("incrementSnippet", 257, 256, 1);
|
49451
|
162 |
}
|
|
163 |
|
|
164 |
@Test
|
|
165 |
public void increment7() {
|
|
166 |
testCounted("incrementSnippet", -10, Integer.MAX_VALUE, 1);
|
|
167 |
}
|
|
168 |
|
|
169 |
@Test
|
|
170 |
public void increment8() {
|
|
171 |
testCounted("incrementSnippet", -10, Integer.MAX_VALUE - 1, 2);
|
48861
|
172 |
}
|
|
173 |
|
43972
|
174 |
public static Result incrementEqSnippet(int start, int limit, int step) {
|
|
175 |
int i;
|
|
176 |
int inc = ((step - 1) & 0xFFFF) + 1; // make sure this value is always strictly positive
|
|
177 |
Result ret = new Result();
|
|
178 |
for (i = start; i <= limit; i += inc) {
|
|
179 |
GraalDirectives.controlFlowAnchor();
|
49451
|
180 |
ret.extremum = get(InductionVariable::extremumNode, InductionVariable::constantExtremum, InductionVariable::isConstantExtremum, i);
|
43972
|
181 |
}
|
|
182 |
ret.exitValue = get(InductionVariable::exitValueNode, i);
|
|
183 |
return ret;
|
|
184 |
}
|
|
185 |
|
|
186 |
@Test
|
|
187 |
public void incrementEq1() {
|
49451
|
188 |
testCounted("incrementEqSnippet", 0, 256, 1);
|
43972
|
189 |
}
|
|
190 |
|
|
191 |
@Test
|
|
192 |
public void incrementEq2() {
|
49451
|
193 |
testCounted("incrementEqSnippet", 0, 256, 2);
|
43972
|
194 |
}
|
|
195 |
|
|
196 |
@Test
|
|
197 |
public void incrementEq3() {
|
49451
|
198 |
testCounted("incrementEqSnippet", 0, 256, 3);
|
43972
|
199 |
}
|
|
200 |
|
48861
|
201 |
@Test
|
|
202 |
public void incrementEq4() {
|
49451
|
203 |
testCounted("incrementEqSnippet", -10, 0, Integer.MAX_VALUE);
|
48861
|
204 |
}
|
|
205 |
|
|
206 |
@Test
|
|
207 |
public void incrementEq5() {
|
49451
|
208 |
testCounted("incrementEqSnippet", 256, 256, 1);
|
48861
|
209 |
}
|
|
210 |
|
|
211 |
@Test
|
|
212 |
public void incrementEq6() {
|
58299
|
213 |
testRemovableCounted("incrementEqSnippet", 257, 256, 1);
|
49451
|
214 |
}
|
|
215 |
|
|
216 |
@Test
|
|
217 |
public void incrementEq7() {
|
|
218 |
testCounted("incrementEqSnippet", -10, Integer.MAX_VALUE - 1, 1);
|
|
219 |
}
|
|
220 |
|
|
221 |
@Test
|
|
222 |
public void incrementEq8() {
|
|
223 |
testCounted("incrementEqSnippet", -10, Integer.MAX_VALUE - 2, 2);
|
48861
|
224 |
}
|
|
225 |
|
58299
|
226 |
@Test
|
|
227 |
public void incrementEq9() {
|
|
228 |
testCounted("incrementEqSnippet", 0, 0, 1);
|
|
229 |
}
|
|
230 |
|
|
231 |
@Test
|
|
232 |
public void incrementEq10() {
|
|
233 |
testCounted("incrementEqSnippet", 0, 0, 3);
|
|
234 |
}
|
|
235 |
|
43972
|
236 |
public static Result decrementSnippet(int start, int limit, int step) {
|
|
237 |
int i;
|
|
238 |
int dec = ((step - 1) & 0xFFFF) + 1; // make sure this value is always strictly positive
|
|
239 |
Result ret = new Result();
|
|
240 |
for (i = start; i > limit; i -= dec) {
|
|
241 |
GraalDirectives.controlFlowAnchor();
|
49451
|
242 |
ret.extremum = get(InductionVariable::extremumNode, InductionVariable::constantExtremum, InductionVariable::isConstantExtremum, i);
|
43972
|
243 |
}
|
|
244 |
ret.exitValue = get(InductionVariable::exitValueNode, i);
|
|
245 |
return ret;
|
|
246 |
}
|
|
247 |
|
|
248 |
@Test
|
|
249 |
public void decrement1() {
|
49451
|
250 |
testCounted("decrementSnippet", 256, 0, 1);
|
43972
|
251 |
}
|
|
252 |
|
|
253 |
@Test
|
|
254 |
public void decrement2() {
|
49451
|
255 |
testCounted("decrementSnippet", 256, 0, 2);
|
43972
|
256 |
}
|
|
257 |
|
|
258 |
@Test
|
|
259 |
public void decrement3() {
|
49451
|
260 |
testCounted("decrementSnippet", 256, 0, 3);
|
|
261 |
}
|
|
262 |
|
|
263 |
@Test
|
|
264 |
public void decrement4() {
|
|
265 |
testCounted("decrementSnippet", Integer.MAX_VALUE, -10, 1);
|
|
266 |
}
|
|
267 |
|
|
268 |
@Test
|
|
269 |
public void decrement5() {
|
|
270 |
testCounted("decrementSnippet", Integer.MAX_VALUE, -10, 2);
|
43972
|
271 |
}
|
|
272 |
|
|
273 |
public static Result decrementEqSnippet(int start, int limit, int step) {
|
|
274 |
int i;
|
|
275 |
int dec = ((step - 1) & 0xFFFF) + 1; // make sure this value is always strictly positive
|
|
276 |
Result ret = new Result();
|
|
277 |
for (i = start; i >= limit; i -= dec) {
|
|
278 |
GraalDirectives.controlFlowAnchor();
|
49451
|
279 |
ret.extremum = get(InductionVariable::extremumNode, InductionVariable::constantExtremum, InductionVariable::isConstantExtremum, i);
|
43972
|
280 |
}
|
|
281 |
ret.exitValue = get(InductionVariable::exitValueNode, i);
|
|
282 |
return ret;
|
|
283 |
}
|
|
284 |
|
|
285 |
@Test
|
|
286 |
public void decrementEq1() {
|
49451
|
287 |
testCounted("decrementEqSnippet", 256, 0, 1);
|
43972
|
288 |
}
|
|
289 |
|
|
290 |
@Test
|
|
291 |
public void decrementEq2() {
|
49451
|
292 |
testCounted("decrementEqSnippet", 256, 0, 2);
|
43972
|
293 |
}
|
|
294 |
|
|
295 |
@Test
|
|
296 |
public void decrementEq3() {
|
49451
|
297 |
testCounted("decrementEqSnippet", 256, 0, 3);
|
43972
|
298 |
}
|
|
299 |
|
48861
|
300 |
@Test
|
|
301 |
public void decrementEq4() {
|
58299
|
302 |
testRemovableCounted("decrementEqSnippet", -10, 0, Integer.MAX_VALUE);
|
49451
|
303 |
}
|
|
304 |
|
|
305 |
@Test
|
|
306 |
public void decrementEq5() {
|
|
307 |
testCounted("decrementEqSnippet", Integer.MAX_VALUE, -10, 1);
|
|
308 |
}
|
|
309 |
|
|
310 |
@Test
|
|
311 |
public void decrementEq6() {
|
|
312 |
testCounted("decrementEqSnippet", Integer.MAX_VALUE, -10, 2);
|
48861
|
313 |
}
|
|
314 |
|
58299
|
315 |
@Test
|
|
316 |
public void decrementEq7() {
|
|
317 |
testCounted("decrementEqSnippet", 10, 10, 1);
|
|
318 |
}
|
|
319 |
|
|
320 |
@Test
|
|
321 |
public void decrementEq8() {
|
|
322 |
testCounted("decrementEqSnippet", 10, 10, 3);
|
|
323 |
}
|
|
324 |
|
43972
|
325 |
public static Result twoVariablesSnippet() {
|
|
326 |
Result ret = new Result();
|
|
327 |
int j = 0;
|
|
328 |
for (int i = 0; i < 1024; i++) {
|
|
329 |
j += 5;
|
|
330 |
GraalDirectives.controlFlowAnchor();
|
49451
|
331 |
ret.extremum = get(InductionVariable::extremumNode, InductionVariable::constantExtremum, InductionVariable::isConstantExtremum, j);
|
43972
|
332 |
}
|
|
333 |
ret.exitValue = get(InductionVariable::exitValueNode, j);
|
|
334 |
return ret;
|
|
335 |
}
|
|
336 |
|
|
337 |
@Test
|
|
338 |
public void testTwoVariables() {
|
49451
|
339 |
testCounted("twoVariablesSnippet");
|
|
340 |
}
|
|
341 |
|
|
342 |
public static Result incrementNeqSnippet(int limit) {
|
|
343 |
int i;
|
|
344 |
int posLimit = ((limit - 1) & 0xFFFF) + 1; // make sure limit is always strictly positive
|
|
345 |
Result ret = new Result();
|
|
346 |
for (i = 0; i != posLimit; i++) {
|
|
347 |
GraalDirectives.controlFlowAnchor();
|
|
348 |
ret.extremum = get(InductionVariable::extremumNode, InductionVariable::constantExtremum, InductionVariable::isConstantExtremum, i);
|
|
349 |
}
|
|
350 |
ret.exitValue = get(InductionVariable::exitValueNode, i);
|
|
351 |
return ret;
|
|
352 |
}
|
|
353 |
|
|
354 |
@Test
|
|
355 |
public void decrementNeq() {
|
|
356 |
testCounted("decrementNeqSnippet", 256);
|
|
357 |
}
|
|
358 |
|
|
359 |
public static Result decrementNeqSnippet(int limit) {
|
|
360 |
int i;
|
|
361 |
int posLimit = ((limit - 1) & 0xFFFF) + 1; // make sure limit is always strictly positive
|
|
362 |
Result ret = new Result();
|
|
363 |
for (i = posLimit; i != 0; i--) {
|
|
364 |
GraalDirectives.controlFlowAnchor();
|
|
365 |
ret.extremum = get(InductionVariable::extremumNode, InductionVariable::constantExtremum, InductionVariable::isConstantExtremum, i);
|
|
366 |
}
|
|
367 |
ret.exitValue = get(InductionVariable::exitValueNode, i);
|
|
368 |
return ret;
|
|
369 |
}
|
|
370 |
|
|
371 |
@Test
|
|
372 |
public void incrementNeq() {
|
|
373 |
testCounted("incrementNeqSnippet", 256);
|
|
374 |
}
|
|
375 |
|
|
376 |
public static Result incrementLongSnippet(long start, long limit, long step) {
|
|
377 |
long i;
|
|
378 |
long inc = ((step - 1) & 0xFFFF) + 1; // make sure this value is always strictly positive
|
|
379 |
Result ret = new Result();
|
|
380 |
for (i = start; i < limit; i += inc) {
|
|
381 |
GraalDirectives.controlFlowAnchor();
|
|
382 |
ret.extremum = get(InductionVariable::extremumNode, InductionVariable::constantExtremum, InductionVariable::isConstantExtremum, i);
|
|
383 |
}
|
|
384 |
ret.exitValue = get(InductionVariable::exitValueNode, i);
|
|
385 |
return ret;
|
|
386 |
}
|
|
387 |
|
|
388 |
@Test
|
|
389 |
public void incrementLong1() {
|
|
390 |
testCounted("incrementLongSnippet", 0L, 256L, 1L);
|
|
391 |
}
|
|
392 |
|
|
393 |
@Test
|
|
394 |
public void incrementLong2() {
|
|
395 |
testCounted("incrementLongSnippet", 0L, 256L, 2L);
|
|
396 |
}
|
|
397 |
|
|
398 |
@Test
|
|
399 |
public void incrementLong3() {
|
|
400 |
testCounted("incrementLongSnippet", 0L, 256L, 3L);
|
|
401 |
}
|
|
402 |
|
|
403 |
@Test
|
|
404 |
public void incrementLong4() {
|
|
405 |
testCounted("incrementLongSnippet", -10L, 1L, Long.MAX_VALUE);
|
|
406 |
}
|
|
407 |
|
|
408 |
@Test
|
|
409 |
public void incrementLong5() {
|
58299
|
410 |
testRemovableCounted("incrementLongSnippet", 256L, 256L, 1L);
|
49451
|
411 |
}
|
|
412 |
|
|
413 |
@Test
|
|
414 |
public void incrementLong6() {
|
58299
|
415 |
testRemovableCounted("incrementLongSnippet", 257L, 256L, 1L);
|
|
416 |
}
|
|
417 |
|
|
418 |
public static Result incrementUnsignedSnippet(int start, int limit, int step) {
|
|
419 |
int i;
|
|
420 |
int inc = ((step - 1) & 0xFFFF) + 1; // make sure this value is always strictly positive
|
|
421 |
Result ret = new Result();
|
|
422 |
for (i = start; Integer.compareUnsigned(i, limit) < 0; i += inc) {
|
|
423 |
GraalDirectives.controlFlowAnchor();
|
|
424 |
ret.extremum = get(InductionVariable::extremumNode, InductionVariable::constantExtremum, InductionVariable::isConstantExtremum, i);
|
|
425 |
}
|
|
426 |
ret.exitValue = get(InductionVariable::exitValueNode, i);
|
|
427 |
return ret;
|
|
428 |
}
|
|
429 |
|
|
430 |
@Test
|
|
431 |
public void incrementUnsigned1() {
|
|
432 |
testCounted("incrementUnsignedSnippet", 0, 256, 1);
|
|
433 |
}
|
|
434 |
|
|
435 |
@Test
|
|
436 |
public void incrementUnsigned2() {
|
|
437 |
testCounted("incrementUnsignedSnippet", 0, 256, 2);
|
|
438 |
}
|
|
439 |
|
|
440 |
@Test
|
|
441 |
public void incrementUnsigned3() {
|
|
442 |
testCounted("incrementUnsignedSnippet", 0, 256, 3);
|
|
443 |
}
|
|
444 |
|
|
445 |
@Test
|
|
446 |
public void incrementUnsigned4() {
|
|
447 |
testCounted("incrementUnsignedSnippet", 1, Integer.MAX_VALUE + 10, Integer.MAX_VALUE);
|
|
448 |
}
|
|
449 |
|
|
450 |
@Test
|
|
451 |
public void incrementUnsigned5() {
|
|
452 |
testRemovableCounted("incrementUnsignedSnippet", 256, 256, 1);
|
|
453 |
}
|
|
454 |
|
|
455 |
@Test
|
|
456 |
public void incrementUnsigned6() {
|
|
457 |
testRemovableCounted("incrementUnsignedSnippet", 257, 256, 1);
|
|
458 |
}
|
|
459 |
|
|
460 |
@Test
|
|
461 |
public void incrementUnsigned7() {
|
|
462 |
testCounted("incrementUnsignedSnippet", 0, Integer.MAX_VALUE + 10, 1);
|
|
463 |
}
|
|
464 |
|
|
465 |
@Test
|
|
466 |
public void incrementUnsigned8a() {
|
|
467 |
testCounted("incrementUnsignedSnippet", 0, Integer.MAX_VALUE + 11, 2);
|
|
468 |
}
|
|
469 |
|
|
470 |
@Test
|
|
471 |
public void incrementUnsigned8b() {
|
|
472 |
testCounted("incrementUnsignedSnippet", 0, Integer.MAX_VALUE + 10, 2);
|
|
473 |
}
|
|
474 |
|
|
475 |
@Test
|
|
476 |
public void incrementUnsigned9() {
|
|
477 |
testCounted("incrementUnsignedSnippet", Integer.MAX_VALUE - 1, Integer.MAX_VALUE + 10, 1);
|
|
478 |
}
|
|
479 |
|
|
480 |
@Test
|
|
481 |
public void incrementUnsigned10() {
|
|
482 |
testCounted("incrementUnsignedSnippet", Integer.MAX_VALUE - 1, Integer.MAX_VALUE + 10, 2);
|
|
483 |
}
|
|
484 |
|
|
485 |
public static Result decrementUnsignedSnippet(int start, int limit, int step) {
|
|
486 |
int dec = ((step - 1) & 0xFFFF) + 1; // make sure this value is always strictly positive
|
|
487 |
Result ret = new Result();
|
|
488 |
int i;
|
|
489 |
for (i = start; Integer.compareUnsigned(i, limit) > 0; i -= dec) {
|
|
490 |
GraalDirectives.controlFlowAnchor();
|
|
491 |
ret.extremum = get(InductionVariable::extremumNode, InductionVariable::constantExtremum, InductionVariable::isConstantExtremum, i);
|
|
492 |
}
|
|
493 |
ret.exitValue = get(InductionVariable::exitValueNode, i);
|
|
494 |
return ret;
|
|
495 |
}
|
|
496 |
|
|
497 |
@Test
|
|
498 |
public void decrementUnsigned1() {
|
|
499 |
testCounted("decrementUnsignedSnippet", 256, 0, 1);
|
|
500 |
}
|
|
501 |
|
|
502 |
@Test
|
|
503 |
public void decrementUnsigned2() {
|
|
504 |
testCounted("decrementUnsignedSnippet", 256, 0, 2);
|
|
505 |
}
|
|
506 |
|
|
507 |
@Test
|
|
508 |
public void decrementUnsigned3() {
|
|
509 |
testCounted("decrementUnsignedSnippet", 256, 2, 3);
|
|
510 |
}
|
|
511 |
|
|
512 |
@Test
|
|
513 |
public void decrementUnsigned5() {
|
|
514 |
testRemovableCounted("decrementUnsignedSnippet", 256, 256, 1);
|
|
515 |
}
|
|
516 |
|
|
517 |
@Test
|
|
518 |
public void decrementUnsigned6() {
|
|
519 |
testRemovableCounted("decrementUnsignedSnippet", 256, 257, 1);
|
|
520 |
}
|
|
521 |
|
|
522 |
@Test
|
|
523 |
public void decrementUnsigned7() {
|
|
524 |
testCounted("decrementUnsignedSnippet", Integer.MAX_VALUE + 10, 0, 1);
|
|
525 |
}
|
|
526 |
|
|
527 |
@Test
|
|
528 |
public void decrementUnsigned8() {
|
|
529 |
testCounted("decrementUnsignedSnippet", Integer.MAX_VALUE + 11, 0, 2);
|
|
530 |
}
|
|
531 |
|
|
532 |
@Test
|
|
533 |
public void decrementUnsigned9() {
|
|
534 |
testCounted("decrementUnsignedSnippet", Integer.MAX_VALUE + 10, Integer.MAX_VALUE - 1, 1);
|
|
535 |
}
|
|
536 |
|
|
537 |
@Test
|
|
538 |
public void decrementUnsigned10() {
|
|
539 |
testCounted("decrementUnsignedSnippet", Integer.MAX_VALUE + 10, Integer.MAX_VALUE - 1, 2);
|
43972
|
540 |
}
|
|
541 |
|
|
542 |
@NodeInfo(cycles = CYCLES_IGNORED, size = SIZE_IGNORED)
|
|
543 |
private static class IVPropertyNode extends FloatingNode implements LIRLowerable {
|
|
544 |
public static final NodeClass<IVPropertyNode> TYPE = NodeClass.create(IVPropertyNode.class);
|
|
545 |
|
|
546 |
private final IVProperty property;
|
49451
|
547 |
private final StaticIVProperty staticProperty;
|
|
548 |
private final IVPredicate staticCheck;
|
58299
|
549 |
private final boolean loopCanBeRemoved;
|
43972
|
550 |
@Input private ValueNode iv;
|
|
551 |
|
58299
|
552 |
protected IVPropertyNode(IVProperty property, StaticIVProperty staticProperty, IVPredicate staticCheck, ValueNode iv, boolean loopCanBeRemoved) {
|
48190
|
553 |
super(TYPE, iv.stamp(NodeView.DEFAULT).unrestricted());
|
43972
|
554 |
this.property = property;
|
49451
|
555 |
this.staticProperty = staticProperty;
|
|
556 |
this.staticCheck = staticCheck;
|
43972
|
557 |
this.iv = iv;
|
58299
|
558 |
this.loopCanBeRemoved = loopCanBeRemoved;
|
43972
|
559 |
}
|
|
560 |
|
|
561 |
public void rewrite(LoopsData loops) {
|
|
562 |
InductionVariable inductionVariable = loops.getInductionVariable(iv);
|
49451
|
563 |
ValueNode node = null;
|
58299
|
564 |
if (inductionVariable == null) {
|
|
565 |
assert loopCanBeRemoved;
|
|
566 |
assert loops.loops().isEmpty();
|
|
567 |
node = iv;
|
|
568 |
} else {
|
|
569 |
assertTrue(inductionVariable.getLoop().isCounted(), "must be counted");
|
|
570 |
if (staticCheck != null) {
|
|
571 |
assert staticProperty != null;
|
|
572 |
if (staticCheck.test(inductionVariable)) {
|
|
573 |
node = ConstantNode.forLong(staticProperty.get(inductionVariable), graph());
|
|
574 |
}
|
49451
|
575 |
}
|
58299
|
576 |
if (node == null) {
|
|
577 |
node = property.get(inductionVariable);
|
|
578 |
}
|
49451
|
579 |
}
|
43972
|
580 |
replaceAtUsagesAndDelete(node);
|
|
581 |
}
|
|
582 |
|
|
583 |
@Override
|
|
584 |
public void generate(NodeLIRBuilderTool gen) {
|
|
585 |
gen.setResult(this, gen.operand(iv));
|
|
586 |
}
|
|
587 |
}
|
|
588 |
|
|
589 |
@Override
|
46459
|
590 |
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
|
|
591 |
Registration r = new Registration(invocationPlugins, CountedLoopTest.class);
|
49451
|
592 |
registerPlugins(r, JavaKind.Int);
|
|
593 |
registerPlugins(r, JavaKind.Long);
|
|
594 |
super.registerInvocationPlugins(invocationPlugins);
|
|
595 |
}
|
|
596 |
|
|
597 |
private void registerPlugins(Registration r, JavaKind ivKind) {
|
|
598 |
r.register2("get", IVProperty.class, ivKind.toJavaClass(), new InvocationPlugin() {
|
43972
|
599 |
@Override
|
|
600 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) {
|
|
601 |
IVProperty property = null;
|
|
602 |
if (arg1.isConstant()) {
|
|
603 |
property = getSnippetReflection().asObject(IVProperty.class, arg1.asJavaConstant());
|
|
604 |
}
|
|
605 |
if (property != null) {
|
58299
|
606 |
b.addPush(ivKind, new IVPropertyNode(property, null, null, arg2, loopCanBeRemoved));
|
43972
|
607 |
return true;
|
|
608 |
} else {
|
|
609 |
return false;
|
|
610 |
}
|
|
611 |
}
|
|
612 |
});
|
49451
|
613 |
r.register4("get", IVProperty.class, StaticIVProperty.class, IVPredicate.class, ivKind.toJavaClass(), new InvocationPlugin() {
|
|
614 |
@Override
|
|
615 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2, ValueNode arg3, ValueNode arg4) {
|
|
616 |
IVProperty property = null;
|
|
617 |
StaticIVProperty staticProperty = null;
|
|
618 |
IVPredicate staticCheck = null;
|
|
619 |
if (arg1.isConstant()) {
|
|
620 |
property = getSnippetReflection().asObject(IVProperty.class, arg1.asJavaConstant());
|
|
621 |
}
|
|
622 |
if (arg2.isConstant()) {
|
|
623 |
staticProperty = getSnippetReflection().asObject(StaticIVProperty.class, arg2.asJavaConstant());
|
|
624 |
}
|
|
625 |
if (arg3.isConstant()) {
|
|
626 |
staticCheck = getSnippetReflection().asObject(IVPredicate.class, arg3.asJavaConstant());
|
|
627 |
}
|
|
628 |
if (property != null && staticProperty != null && staticCheck != null) {
|
58299
|
629 |
b.addPush(ivKind, new IVPropertyNode(property, staticProperty, staticCheck, arg4, loopCanBeRemoved));
|
49451
|
630 |
return true;
|
|
631 |
} else {
|
|
632 |
return false;
|
|
633 |
}
|
|
634 |
}
|
|
635 |
});
|
43972
|
636 |
}
|
|
637 |
|
|
638 |
@Override
|
55509
|
639 |
protected void checkHighTierGraph(StructuredGraph graph) {
|
43972
|
640 |
LoopsData loops = new LoopsData(graph);
|
|
641 |
loops.detectedCountedLoops();
|
|
642 |
for (IVPropertyNode node : graph.getNodes().filter(IVPropertyNode.class)) {
|
|
643 |
node.rewrite(loops);
|
|
644 |
}
|
|
645 |
assert graph.getNodes().filter(IVPropertyNode.class).isEmpty();
|
|
646 |
}
|
|
647 |
|
52910
|
648 |
@Override
|
|
649 |
protected HighTierContext getDefaultHighTierContext() {
|
|
650 |
// Don't convert unreached paths into Guard
|
|
651 |
return new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.NONE);
|
|
652 |
}
|
|
653 |
|
49451
|
654 |
private Object[] argsToBind;
|
58299
|
655 |
private boolean loopCanBeRemoved;
|
43972
|
656 |
|
49451
|
657 |
@Override
|
|
658 |
protected Object[] getArgumentToBind() {
|
|
659 |
return argsToBind;
|
43972
|
660 |
}
|
|
661 |
|
49451
|
662 |
public void testCounted(String snippetName, Object... args) {
|
58299
|
663 |
this.loopCanBeRemoved = false;
|
49451
|
664 |
test(snippetName, args);
|
58299
|
665 |
this.argsToBind = args;
|
49451
|
666 |
test(snippetName, args);
|
58299
|
667 |
this.argsToBind = null;
|
|
668 |
}
|
|
669 |
|
|
670 |
public void testCounted(String snippetName, Object start, Object limit, Object step) {
|
|
671 |
testCounted(false, snippetName, start, limit, step);
|
|
672 |
}
|
|
673 |
|
|
674 |
public void testRemovableCounted(String snippetName, Object start, Object limit, Object step) {
|
|
675 |
testCounted(true, snippetName, start, limit, step);
|
|
676 |
}
|
|
677 |
|
|
678 |
public void testCounted(boolean removable, String snippetName, Object start, Object limit, Object step) {
|
|
679 |
this.loopCanBeRemoved = removable;
|
|
680 |
Object[] args = {start, limit, step};
|
|
681 |
test(snippetName, args);
|
|
682 |
this.argsToBind = args;
|
|
683 |
test(snippetName, args);
|
|
684 |
this.argsToBind = new Object[]{NO_BIND, NO_BIND, step};
|
|
685 |
test(snippetName, args);
|
|
686 |
this.argsToBind = new Object[]{start, NO_BIND, step};
|
|
687 |
test(snippetName, args);
|
|
688 |
this.argsToBind = null;
|
|
689 |
this.loopCanBeRemoved = false;
|
43972
|
690 |
}
|
|
691 |
}
|