-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
TestRangeCheckHoistingScaledIV.java
104 lines (89 loc) · 4.05 KB
/
TestRangeCheckHoistingScaledIV.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright (c) 2022, Arm Limited. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8289996
* @summary Test range check hoisting for some scaled iv at array index
* @library /test/lib /
* @requires vm.debug & vm.compiler2.enabled
* @modules jdk.incubator.vector
* @compile --enable-preview -source ${jdk.version} TestRangeCheckHoistingScaledIV.java
* @run main/othervm --enable-preview compiler.rangechecks.TestRangeCheckHoistingScaledIV
*/
package compiler.rangechecks;
import java.lang.foreign.MemorySegment;
import java.nio.ByteOrder;
import jdk.incubator.vector.ByteVector;
import jdk.incubator.vector.VectorSpecies;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
public class TestRangeCheckHoistingScaledIV {
// Inner class for test loops
class Launcher {
private static final int SIZE = 16000;
private static final VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_64;
private static final ByteOrder ORDER = ByteOrder.nativeOrder();
private static byte[] ta = new byte[SIZE];
private static byte[] tb = new byte[SIZE];
private static MemorySegment sa = MemorySegment.ofArray(ta);
private static MemorySegment sb = MemorySegment.ofArray(tb);
private static int count = 789;
// Normal array accesses with int range checks
public static void scaledIntIV() {
for (int i = 0; i < count; i += 2) {
tb[7 * i] = ta[3 * i];
}
}
// Memory segment accesses with long range checks
public static void scaledLongIV() {
for (long l = 0; l < count; l += 64) {
ByteVector v = ByteVector.fromMemorySegment(SPECIES, sa, l * 6, ORDER);
v.intoMemorySegment(sb, l * 15, ORDER);
}
}
public static void main(String[] args) {
for (int i = 0; i < 20000; i++) {
scaledIntIV();
scaledLongIV();
}
}
}
public static void main(String[] args) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"--enable-preview", "--add-modules", "jdk.incubator.vector",
"-Xbatch", "-XX:+TraceLoopPredicate", Launcher.class.getName());
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
analyzer.shouldHaveExitValue(0);
analyzer.outputTo(System.out);
// Check if int range checks are hoisted
analyzer.stdoutShouldContain("rc_predicate init * 3 <u range");
analyzer.stdoutShouldContain("rc_predicate (limit - 2) * 3 <u range");
analyzer.stdoutShouldContain("rc_predicate init * 7 <u range");
analyzer.stdoutShouldContain("rc_predicate (limit - 2) * 7 <u range");
// Check if long range checks are hoisted
analyzer.stdoutShouldContain("rc_predicate init * 6 <u range");
analyzer.stdoutShouldContain("rc_predicate (limit - 64) * 6 <u range");
analyzer.stdoutShouldContain("rc_predicate init * 15 <u range");
analyzer.stdoutShouldContain("rc_predicate (limit - 64) * 15 <u range");
}
}