Skip to content

Commit df7fba1

Browse files
Fei GaoDamonFool
authored andcommitted
8284981: Support the vectorization of some counting-down loops in SLP
Reviewed-by: roland, kvn
1 parent e54f26a commit df7fba1

File tree

3 files changed

+81
-5
lines changed

3 files changed

+81
-5
lines changed

src/hotspot/share/opto/superword.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,7 +3997,7 @@ bool SWPointer::scaled_iv_plus_offset(Node* n) {
39973997
NOT_PRODUCT(_tracer.scaled_iv_plus_offset_5(n);)
39983998
return true;
39993999
}
4000-
} else if (opc == Op_SubI) {
4000+
} else if (opc == Op_SubI || opc == Op_SubL) {
40014001
if (offset_plus_k(n->in(2), true) && scaled_iv_plus_offset(n->in(1))) {
40024002
NOT_PRODUCT(_tracer.scaled_iv_plus_offset_6(n);)
40034003
return true;
@@ -4316,15 +4316,15 @@ void SWPointer::Tracer::scaled_iv_plus_offset_5(Node* n) {
43164316

43174317
void SWPointer::Tracer::scaled_iv_plus_offset_6(Node* n) {
43184318
if(_slp->is_trace_alignment()) {
4319-
print_depth(); tty->print_cr(" %d SWPointer::scaled_iv_plus_offset: Op_SubI PASSED", n->_idx);
4319+
print_depth(); tty->print_cr(" %d SWPointer::scaled_iv_plus_offset: Op_%s PASSED", n->_idx, n->Name());
43204320
print_depth(); tty->print(" \\ %d SWPointer::scaled_iv_plus_offset: in(1) is scaled_iv: ", n->in(1)->_idx); n->in(1)->dump();
43214321
print_depth(); tty->print(" \\ %d SWPointer::scaled_iv_plus_offset: in(2) is offset_plus_k: ", n->in(2)->_idx); n->in(2)->dump();
43224322
}
43234323
}
43244324

43254325
void SWPointer::Tracer::scaled_iv_plus_offset_7(Node* n) {
43264326
if(_slp->is_trace_alignment()) {
4327-
print_depth(); tty->print_cr(" %d SWPointer::scaled_iv_plus_offset: Op_SubI PASSED", n->_idx);
4327+
print_depth(); tty->print_cr(" %d SWPointer::scaled_iv_plus_offset: Op_%s PASSED", n->_idx, n->Name());
43284328
print_depth(); tty->print(" \\ %d SWPointer::scaled_iv_plus_offset: in(2) is scaled_iv: ", n->in(2)->_idx); n->in(2)->dump();
43294329
print_depth(); tty->print(" \\ %d SWPointer::scaled_iv_plus_offset: in(1) is offset_plus_k: ", n->in(1)->_idx); n->in(1)->dump();
43304330
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2022, Arm Limited. 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+
24+
package compiler.c2.irTests;
25+
26+
import compiler.lib.ir_framework.*;
27+
28+
/*
29+
* @test
30+
* @bug 8284981
31+
* @summary Auto-vectorization enhancement for special counting down loops
32+
* @requires os.arch=="amd64" | os.arch=="x86_64" | os.arch=="aarch64"
33+
* @library /test/lib /
34+
* @run driver compiler.c2.irTests.TestAutoVecCountingDownLoop
35+
*/
36+
37+
public class TestAutoVecCountingDownLoop {
38+
final private static int ARRLEN = 3000;
39+
40+
private static int[] a = new int[ARRLEN];
41+
private static int[] b = new int[ARRLEN];
42+
43+
public static void main(String[] args) {
44+
TestFramework.run();
45+
}
46+
47+
48+
@Test
49+
@IR(counts = {IRNode.LOAD_VECTOR, " >0 "})
50+
@IR(counts = {IRNode.STORE_VECTOR, " >0 "})
51+
private static void testCountingDown(int[] a, int[] b) {
52+
for (int i = 2000; i > 0; i--) {
53+
b[ARRLEN - i] = a[ARRLEN - i];
54+
}
55+
}
56+
57+
@Run(test = "testCountingDown")
58+
private void testCountingDown_runner() {
59+
testCountingDown(a, b);
60+
}
61+
}

test/hotspot/jtreg/compiler/codegen/TestIntVect.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -102,6 +102,7 @@ static int test() {
102102
test_andImm(a1, a2, a3);
103103
test_orImm(a1, a2);
104104
test_xorImm(a1, a2);
105+
test_cp_countingdown(a1, a2);
105106
}
106107
// Initialize
107108
for (int i=0; i<ARRLEN; i++) {
@@ -552,6 +553,10 @@ static int test() {
552553
for (int i=0; i<ARRLEN; i++) {
553554
errn += verify("test_xorImm: a2", i, a2[i], golden);
554555
}
556+
test_cp_countingdown(a1, a2);
557+
for (int i = 500; i > 0; i--) {
558+
errn += verify("test_cp_countingdown: a2", ARRLEN - i, a2[ARRLEN - i], a1[ARRLEN - i]);
559+
}
555560

556561
}
557562

@@ -837,6 +842,12 @@ static int test() {
837842
}
838843
end = System.currentTimeMillis();
839844
System.out.println("test_xorImm: " + (end - start));
845+
start = System.currentTimeMillis();
846+
for (int i = 0; i < ITERS; i++) {
847+
test_cp_countingdown(a1, a2);
848+
}
849+
end = System.currentTimeMillis();
850+
System.out.println("test_cp_countingdown: " + (end - start));
840851

841852
return errn;
842853
}
@@ -1095,7 +1106,11 @@ static void test_xorImm(int[] a, int[] b) {
10951106
b[i] = a[i] ^ 2032;
10961107
}
10971108
}
1098-
1109+
static void test_cp_countingdown(int[] a, int[] b) {
1110+
for (int i = 500; i > 0; i--) {
1111+
b[ARRLEN - i] = a[ARRLEN - i];
1112+
}
1113+
}
10991114

11001115
static int verify(String text, int i, int elem, int val) {
11011116
if (elem != val) {

0 commit comments

Comments
 (0)