Skip to content

Commit 22a9a86

Browse files
committed
8309268: C2: "assert(in_bb(n)) failed: must be" after JDK-8306302
Reviewed-by: rcastanedalo, kvn, thartmann
1 parent b6c9232 commit 22a9a86

File tree

3 files changed

+135
-3
lines changed

3 files changed

+135
-3
lines changed

src/hotspot/share/opto/superword.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3712,8 +3712,12 @@ void SuperWord::compute_vector_element_type() {
37123712
assert(nn->is_Cmp(), "always have Cmp above Bool");
37133713
}
37143714
if (nn->is_Cmp() && nn->in(0) == nullptr) {
3715-
nn = nn->in(1);
3716-
set_velt_type(n, velt_type(nn));
3715+
assert(in_bb(nn->in(1)) || in_bb(nn->in(2)), "one of the inputs must be in the loop too");
3716+
if (in_bb(nn->in(1))) {
3717+
set_velt_type(n, velt_type(nn->in(1)));
3718+
} else {
3719+
set_velt_type(n, velt_type(nn->in(2)));
3720+
}
37173721
}
37183722
}
37193723
#ifndef PRODUCT

test/hotspot/jtreg/compiler/c2/irTests/TestVectorConditionalMove.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2022, Arm Limited. All rights reserved.
3+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
56
* This code is free software; you can redistribute it and/or modify it
@@ -590,6 +591,32 @@ private static void testCMoveDGTforD(double[] a, double[] b, double[] c, double[
590591
}
591592
}
592593

594+
// Use some constants in the comparison
595+
@Test
596+
@IR(counts = {IRNode.LOAD_VECTOR, ">0", IRNode.VECTOR_MASK_CMP, ">0", IRNode.VECTOR_BLEND, ">0", IRNode.STORE_VECTOR, ">0"},
597+
applyIfCPUFeatureOr = {"avx", "true", "asimd", "true"})
598+
private static void testCMoveFGTforFCmpCon1(float a, float[] b, float[] c, float[] d, float[] r, float[] r2) {
599+
for (int i = 0; i < b.length; i++) {
600+
float cc = c[i];
601+
float dd = d[i];
602+
r2[i] = cc + dd;
603+
r[i] = (a > b[i]) ? cc : dd;
604+
}
605+
}
606+
607+
@Test
608+
@IR(counts = {IRNode.LOAD_VECTOR, ">0", IRNode.VECTOR_MASK_CMP, ">0", IRNode.VECTOR_BLEND, ">0", IRNode.STORE_VECTOR, ">0"},
609+
applyIfCPUFeatureOr = {"avx", "true", "asimd", "true"})
610+
private static void testCMoveFGTforFCmpCon2(float[] a, float b, float[] c, float[] d, float[] r, float[] r2) {
611+
for (int i = 0; i < a.length; i++) {
612+
float cc = c[i];
613+
float dd = d[i];
614+
r2[i] = cc + dd;
615+
r[i] = (a[i] > b) ? cc : dd;
616+
}
617+
}
618+
619+
// A case that is currently not supported and is not expected to vectorize
593620
@Test
594621
@IR(failOn = {IRNode.VECTOR_MASK_CMP, IRNode.VECTOR_BLEND})
595622
private static void testCMoveVDUnsupported() {
@@ -723,7 +750,9 @@ private void testCMove_runner() {
723750
"testCMoveDGTforI",
724751
"testCMoveDGTforL",
725752
"testCMoveDGTforF",
726-
"testCMoveDGTforD"})
753+
"testCMoveDGTforD",
754+
"testCMoveFGTforFCmpCon1",
755+
"testCMoveFGTforFCmpCon2"})
727756
private void testCMove_runner_two() {
728757
int[] aI = new int[SIZE];
729758
int[] bI = new int[SIZE];
@@ -842,6 +871,17 @@ private void testCMove_runner_two() {
842871
for (int i = 0; i < SIZE; i++) {
843872
Asserts.assertEquals(rD[i], cmoveDGTforD(aD[i], bD[i], cD[i], dD[i]));
844873
}
874+
875+
// Use some constants/invariants in the comparison
876+
testCMoveFGTforFCmpCon1(aF[0], bF, cF, dF, rF, rF);
877+
for (int i = 0; i < SIZE; i++) {
878+
Asserts.assertEquals(rF[i], cmoveFGTforF(aF[0], bF[i], cF[i], dF[i]));
879+
}
880+
881+
testCMoveFGTforFCmpCon2(aF, bF[0], cF, dF, rF, rF);
882+
for (int i = 0; i < SIZE; i++) {
883+
Asserts.assertEquals(rF[i], cmoveFGTforF(aF[i], bF[0], cF[i], dF[i]));
884+
}
845885
}
846886

847887
private static void init(int[] a) {
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 2023, 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+
24+
/**
25+
* @test
26+
* @bug 8309268
27+
* @summary Test loop invariant input to Cmp.
28+
*
29+
* @run main/othervm -Xcomp -XX:-TieredCompilation
30+
* -XX:CompileCommand=compileonly,compiler.loopopts.superword.TestCmpInvar::test*
31+
* compiler.loopopts.superword.TestCmpInvar
32+
*/
33+
package compiler.loopopts.superword;
34+
35+
public class TestCmpInvar {
36+
static int N = 400;
37+
static long myInvar;
38+
39+
static void test1(int limit, float fcon) {
40+
boolean a[] = new boolean[1000];
41+
for (int i = 0; i < limit; i++) {
42+
a[i] = fcon > i;
43+
}
44+
}
45+
46+
static void test2(int limit, float fcon) {
47+
boolean a[] = new boolean[1000];
48+
for (int i = 0; i < limit; i++) {
49+
a[i] = i > fcon;
50+
}
51+
}
52+
53+
static int test3() {
54+
int[] a = new int[N];
55+
int acc = 0;
56+
for (int i = 1; i < 63; i++) {
57+
acc += Math.min(myInvar, a[i]--);
58+
}
59+
return acc;
60+
}
61+
62+
static int test4() {
63+
int[] a = new int[N];
64+
int acc = 0;
65+
for (int i = 1; i < 63; i++) {
66+
acc += Math.min(a[i]--, myInvar);
67+
}
68+
return acc;
69+
}
70+
71+
public static void main(String[] strArr) {
72+
for (int i = 0; i < 10_100; i++) {
73+
test1(500, 80.1f);
74+
}
75+
76+
for (int i = 0; i < 10_100; i++) {
77+
test2(500, 80.1f);
78+
}
79+
80+
for (int i = 0; i < 10_000; i++) {
81+
test3();
82+
}
83+
84+
for (int i = 0; i < 10_000; i++) {
85+
test4();
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)