Skip to content

Commit 915efc5

Browse files
author
Jatin Bhateja
committed
8385833: C2 Vector API: assert(false) failed: infinite loop in PhaseIterGVN::transform_old
Reviewed-by: epeter, mhaessig, vlivanov
1 parent 524779c commit 915efc5

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

src/hotspot/share/opto/vectornode.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,14 @@ Node* VectorNode::reassociate_vector_operation(PhaseGVN* phase) {
13441344
return nullptr;
13451345
}
13461346

1347+
// Reassociation is beneficial if transformed node with replicate inputs can
1348+
// subsequently be collapsed by push_through_replicate into Replicate(ScalarOp(..)).
1349+
// That folding needs a scalar opcode for this operation/element type.
1350+
// Safety check to ensure we skip useless/redundant reassociations.
1351+
if (scalar_opcode(Opcode(), vect_type()->element_basic_type()) == 0) {
1352+
return nullptr;
1353+
}
1354+
13471355
Node* in1 = in(1);
13481356
Node* in2 = in(2);
13491357
if (in2->Opcode() == Op_Replicate && in1->Opcode() == Opcode()) {

test/hotspot/jtreg/compiler/vectorapi/TestVectorReassociations.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
/*
2525
* @test
26-
* @bug 8358521
26+
* @bug 8358521 8385833
27+
* @key randomness
2728
* @summary Test reassociation of broadcasted inputs across vector operations
2829
* @modules jdk.incubator.vector
2930
* @library /test/lib /
@@ -32,7 +33,10 @@
3233

3334
package compiler.vectorapi;
3435

36+
import compiler.lib.generators.Generator;
37+
import compiler.lib.generators.Generators;
3538
import compiler.lib.ir_framework.*;
39+
import compiler.lib.verify.*;
3640
import jdk.incubator.vector.*;
3741
import java.util.stream.IntStream;
3842

@@ -602,4 +606,56 @@ static void test_byte_mul_reassociation_pattern4() {
602606
ByteVector.broadcast(BSP, bb))
603607
.intoArray(byteOut, 0);
604608
}
609+
610+
private static final Generators RD = Generators.G;
611+
612+
static int uA, uB, uC;
613+
614+
static {
615+
Generator<Integer> ig = RD.ints();
616+
uA = ig.next(); uB = ig.next(); uC = ig.next();
617+
}
618+
619+
static int[] umaxIntOut = new int[ISP.length()];
620+
static int[] uminIntOut = new int[ISP.length()];
621+
622+
// UMAX(UMAX(bcast(uA), bcast(uB)), bcast(uC)).
623+
@Test
624+
@IR(counts = { IRNode.UMAX_VI, " >0 " },
625+
applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
626+
@Warmup(value = 10000)
627+
static void test_int_umax_all_broadcast() {
628+
IntVector.broadcast(ISP, uA)
629+
.lanewise(VectorOperators.UMAX, uB)
630+
.lanewise(VectorOperators.UMAX, uC)
631+
.intoArray(umaxIntOut, 0);
632+
}
633+
634+
@Check(test = "test_int_umax_all_broadcast")
635+
static void check_int_umax_all_broadcast() {
636+
int e = VectorMath.maxUnsigned(VectorMath.maxUnsigned(uA, uB), uC);
637+
for (int v : umaxIntOut) {
638+
Verify.checkEQ(v, e);
639+
}
640+
}
641+
642+
// UMIN(UMIN(bcast(uA), bcast(uB)), bcast(uC)).
643+
@Test
644+
@IR(counts = { IRNode.UMIN_VI, " >0 " },
645+
applyIfCPUFeatureOr = {"avx", "true", "rvv", "true"})
646+
@Warmup(value = 10000)
647+
static void test_int_umin_all_broadcast() {
648+
IntVector.broadcast(ISP, uA)
649+
.lanewise(VectorOperators.UMIN, uB)
650+
.lanewise(VectorOperators.UMIN, uC)
651+
.intoArray(uminIntOut, 0);
652+
}
653+
654+
@Check(test = "test_int_umin_all_broadcast")
655+
static void check_int_umin_all_broadcast() {
656+
int e = VectorMath.minUnsigned(VectorMath.minUnsigned(uA, uB), uC);
657+
for (int v : uminIntOut) {
658+
Verify.checkEQ(v, e);
659+
}
660+
}
605661
}

0 commit comments

Comments
 (0)