Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8289996: Fix array range check hoisting for some scaled loop iv
Co-authored-by: John R Rose <jrose@openjdk.org> Reviewed-by: roland, kvn, thartmann
- Loading branch information
Pengfei Li
and
John R Rose
committed
Jul 26, 2022
1 parent
da9cc5c
commit 8939095
Showing
4 changed files
with
191 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
test/hotspot/jtreg/compiler/rangechecks/TestRangeCheckHoistingScaledIV.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
test/micro/org/openjdk/bench/vm/compiler/RangeCheckHoisting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.openjdk.bench.vm.compiler; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
|
||
@State(Scope.Benchmark) | ||
public class RangeCheckHoisting { | ||
|
||
private static final int SIZE = 65536; | ||
|
||
@Param("6789") private int count; | ||
|
||
private static int[] a = new int[SIZE]; | ||
private static int[] b = new int[SIZE]; | ||
|
||
@Benchmark | ||
public void ivScaled3() { | ||
for (int i = 0; i < count; i++) { | ||
b[3 * i] = a[3 * i]; | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void ivScaled7() { | ||
for (int i = 0; i < count; i++) { | ||
b[7 * i] = a[7 * i]; | ||
} | ||
} | ||
} |
8939095
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues