8309894: compiler/vectorapi/VectorLogicalOpIdentityTest.java fails on SVE system with UseSVE=0

Reviewed-by: epeter, chagedorn
This commit is contained in:
Xiaohong Gong 2023-07-04 01:35:03 +00:00
parent 0916e6a603
commit 60544f9088
4 changed files with 54 additions and 24 deletions
test/hotspot/jtreg
compiler
testlibrary_tests/ir_framework/tests

@ -94,8 +94,9 @@ One might also want to restrict the application of certain `@IR` rules depending
- `applyIfOr`: Only apply a rule if **at least one** flag has the specified value/range of values.
#### Disable/Enable IR Rules based on available CPU Features
Sometimes, an `@IR` rule should only be applied if a certain CPU feature is present. This can be done with
the attributes `applyIfCPUFeatureXXX` in [@IR](./IR.java) which follow the same logic as the `applyIfXXX` methods for flags in the previous section. If a `@Test` annotated method has multiple preconditions (for example `applyIf` and `applyIfCPUFeature`), they are evaluated as a logical conjunction. An example with `applyIfCPUFeatureXXX` can be found in [TestCPUFeatureCheck](../../../testlibrary_tests/ir_framework/tests/TestCPUFeatureCheck.java) (internal framework test).
Sometimes, an `@IR` rule should only be applied if a certain CPU feature is present. This can be done with the attributes `applyIfCPUFeatureXXX` in [@IR](./IR.java) which follow the same logic as the `applyIfXXX` methods for flags in the previous section. An example with `applyIfCPUFeatureXXX` can be found in [TestCPUFeatureCheck](../../../testlibrary_tests/ir_framework/tests/TestCPUFeatureCheck.java) (internal framework test).
If a `@Test` annotated method has multiple preconditions (for example `applyIf` and `applyIfCPUFeature`), they are evaluated as a logical conjunction. It's worth noting that flags in `applyIf` are checked only if the CPU features in `applyIfCPUFeature` are matched when they are both specified. This avoids the VM flag being evaluated on hardware that does not support it. An example with both `applyIfCPUFeatureXXX` and `applyIfXXX` can be found in [TestPreconditions](../../../testlibrary_tests/ir_framework/tests/TestPreconditions.java) (internal framework test).
#### Implicitly Skipping IR Verification
An IR verification cannot always be performed. Certain VM flags explicitly disable IR verification, change the IR shape in unexpected ways letting IR rules fail or even make IR verification impossible:

@ -132,6 +132,15 @@ public class IREncodingPrinter {
checkIRAnnotations(irAnno);
if (isIRNodeUnsupported(irAnno)) {
return false;
} else if (irAnno.applyIfCPUFeature().length != 0 && !hasAllRequiredCPUFeature(irAnno.applyIfCPUFeature())) {
printDisableReason(m, "Feature constraint not met (applyIfCPUFeature)", irAnno.applyIfCPUFeature(), ruleIndex, ruleMax);
return false;
} else if (irAnno.applyIfCPUFeatureAnd().length != 0 && !hasAllRequiredCPUFeature(irAnno.applyIfCPUFeatureAnd())) {
printDisableReason(m, "Not all feature constraints are met (applyIfCPUFeatureAnd)", irAnno.applyIfCPUFeatureAnd(), ruleIndex, ruleMax);
return false;
} else if (irAnno.applyIfCPUFeatureOr().length != 0 && !hasAnyRequiredCPUFeature(irAnno.applyIfCPUFeatureOr())) {
printDisableReason(m, "None of the feature constraints met (applyIfCPUFeatureOr)", irAnno.applyIfCPUFeatureOr(), ruleIndex, ruleMax);
return false;
} else if (irAnno.applyIf().length != 0 && !hasAllRequiredFlags(irAnno.applyIf(), "applyIf")) {
printDisableReason(m, "Flag constraint not met (applyIf)", irAnno.applyIf(), ruleIndex, ruleMax);
return false;
@ -144,15 +153,6 @@ public class IREncodingPrinter {
} else if (irAnno.applyIfOr().length != 0 && hasNoRequiredFlags(irAnno.applyIfOr(), "applyIfOr")) {
printDisableReason(m, "None of the flag constraints met (applyIfOr)", irAnno.applyIfOr(), ruleIndex, ruleMax);
return false;
} else if (irAnno.applyIfCPUFeature().length != 0 && !hasAllRequiredCPUFeature(irAnno.applyIfCPUFeature())) {
printDisableReason(m, "Feature constraint not met (applyIfCPUFeature)", irAnno.applyIfCPUFeature(), ruleIndex, ruleMax);
return false;
} else if (irAnno.applyIfCPUFeatureAnd().length != 0 && !hasAllRequiredCPUFeature(irAnno.applyIfCPUFeatureAnd())) {
printDisableReason(m, "Not all feature constraints are met (applyIfCPUFeatureAnd)", irAnno.applyIfCPUFeatureAnd(), ruleIndex, ruleMax);
return false;
} else if (irAnno.applyIfCPUFeatureOr().length != 0 && !hasAnyRequiredCPUFeature(irAnno.applyIfCPUFeatureOr())) {
printDisableReason(m, "None of the feature constraints met (applyIfCPUFeatureOr)", irAnno.applyIfCPUFeatureOr(), ruleIndex, ruleMax);
return false;
} else {
// All preconditions satisfied: apply rule.
return true;

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Arm Limited. All rights reserved.
* Copyright (c) 2022, 2023, Arm Limited. All rights reserved.
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -164,7 +164,7 @@ public class VectorLogicalOpIdentityTest {
@Test
@Warmup(10000)
@IR(counts = {IRNode.LOAD_VECTOR, ">=1"})
@IR(failOn = IRNode.AND_V, applyIfCPUFeatureAnd = {"asimd", "true", "sve", "false"})
@IR(failOn = IRNode.AND_V, applyIfCPUFeature = {"asimd", "true"}, applyIf = {"UseSVE", "0"})
public static void testMaskedAndMinusOne2() {
VectorMask<Byte> mask = VectorMask.fromArray(B_SPECIES, m, 0);
ByteVector av = ByteVector.fromArray(B_SPECIES, ba, 0);
@ -185,7 +185,7 @@ public class VectorLogicalOpIdentityTest {
@Test
@Warmup(10000)
@IR(counts = {IRNode.STORE_VECTOR, ">=1"})
@IR(failOn = IRNode.AND_V, applyIfCPUFeatureAnd = {"asimd", "true", "sve", "false"})
@IR(failOn = IRNode.AND_V, applyIfCPUFeature = {"asimd", "true"}, applyIf = {"UseSVE", "0"})
public static void testMaskedAndZero1() {
VectorMask<Short> mask = VectorMask.fromArray(S_SPECIES, m, 0);
ShortVector av = ShortVector.fromArray(S_SPECIES, sa, 0);
@ -302,7 +302,8 @@ public class VectorLogicalOpIdentityTest {
// Transform AndV(AndV(a, b, m), b, m) ==> AndV(a, b, m)
@Test
@Warmup(10000)
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeatureOr = {"sve", "true", "avx512", "true"})
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeature = {"sve", "true"}, applyIf = {"UseSVE", "> 0"})
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeature = {"avx512", "true"})
public static void testAndMaskSameValue1() {
VectorMask<Integer> mask = VectorMask.fromArray(I_SPECIES, m, 0);
IntVector av = IntVector.fromArray(I_SPECIES, ia, 0);
@ -323,7 +324,8 @@ public class VectorLogicalOpIdentityTest {
// Transform AndV(AndV(a, b, m), a, m) ==> AndV(a, b, m)
@Test
@Warmup(10000)
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeatureOr = {"sve", "true", "avx512", "true"})
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeature = {"sve", "true"}, applyIf = {"UseSVE", "> 0"})
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeature = {"avx512", "true"})
public static void testAndMaskSameValue2() {
VectorMask<Long> mask = VectorMask.fromArray(L_SPECIES, m, 0);
LongVector av = LongVector.fromArray(L_SPECIES, la, 0);
@ -344,7 +346,8 @@ public class VectorLogicalOpIdentityTest {
// Transform AndV(a, AndV(a, b, m), m) ==> AndV(a, b, m)
@Test
@Warmup(10000)
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeatureOr = {"sve", "true", "avx512", "true"})
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeature = {"sve", "true"}, applyIf = {"UseSVE", "> 0"})
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeature = {"avx512", "true"})
public static void testAndMaskSameValue3() {
VectorMask<Integer> mask = VectorMask.fromArray(I_SPECIES, m, 0);
IntVector av = IntVector.fromArray(I_SPECIES, ia, 0);
@ -409,7 +412,7 @@ public class VectorLogicalOpIdentityTest {
@Test
@Warmup(10000)
@IR(counts = {IRNode.STORE_VECTOR, ">=1"})
@IR(failOn = IRNode.OR_V, applyIfCPUFeatureAnd = {"asimd", "true", "sve", "false"})
@IR(failOn = IRNode.OR_V, applyIfCPUFeature = {"asimd", "true"}, applyIf = {"UseSVE", "0"})
public static void testMaskedOrMinusOne1() {
VectorMask<Byte> mask = VectorMask.fromArray(B_SPECIES, m, 0);
ByteVector av = ByteVector.fromArray(B_SPECIES, ba, 0);
@ -468,7 +471,7 @@ public class VectorLogicalOpIdentityTest {
@Test
@Warmup(10000)
@IR(counts = {IRNode.LOAD_VECTOR, ">=1"})
@IR(failOn = IRNode.OR_V, applyIfCPUFeatureAnd = {"asimd", "true", "sve", "false"})
@IR(failOn = IRNode.OR_V, applyIfCPUFeature = {"asimd", "true"}, applyIf = {"UseSVE", "0"})
public static void testMaskedOrZero2() {
VectorMask<Byte> mask = VectorMask.fromArray(B_SPECIES, m, 0);
ByteVector av = ByteVector.fromArray(B_SPECIES, ba, 0);
@ -566,7 +569,8 @@ public class VectorLogicalOpIdentityTest {
// Transform OrV(OrV(a, b, m), b, m) ==> OrV(a, b, m)
@Test
@Warmup(10000)
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeatureOr = {"sve", "true", "avx512", "true"})
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeature = {"sve", "true"}, applyIf = {"UseSVE", "> 0"})
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeature = {"avx512", "true"})
public static void testOrMaskSameValue1() {
VectorMask<Integer> mask = VectorMask.fromArray(I_SPECIES, m, 0);
IntVector av = IntVector.fromArray(I_SPECIES, ia, 0);
@ -587,7 +591,8 @@ public class VectorLogicalOpIdentityTest {
// Transform OrV(OrV(a, b, m), a, m) ==> OrV(a, b, m)
@Test
@Warmup(10000)
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeatureOr = {"sve", "true", "avx512", "true"})
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeature = {"sve", "true"}, applyIf = {"UseSVE", "> 0"})
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeature = {"avx512", "true"})
public static void testOrMaskSameValue2() {
VectorMask<Long> mask = VectorMask.fromArray(L_SPECIES, m, 0);
LongVector av = LongVector.fromArray(L_SPECIES, la, 0);
@ -608,7 +613,8 @@ public class VectorLogicalOpIdentityTest {
// Transform OrV(a, OrV(a, b, m), m) ==> OrV(a, b, m)
@Test
@Warmup(10000)
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeatureOr = {"sve", "true", "avx512", "true"})
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeature = {"sve", "true"}, applyIf = {"UseSVE", "> 0"})
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeature = {"avx512", "true"})
public static void testOrMaskSameValue3() {
VectorMask<Integer> mask = VectorMask.fromArray(I_SPECIES, m, 0);
IntVector av = IntVector.fromArray(I_SPECIES, ia, 0);
@ -647,7 +653,7 @@ public class VectorLogicalOpIdentityTest {
@Test
@Warmup(10000)
@IR(counts = {IRNode.STORE_VECTOR, ">=1"})
@IR(failOn = IRNode.XOR_V, applyIfCPUFeatureAnd = {"asimd", "true", "sve", "false"})
@IR(failOn = IRNode.XOR_V, applyIfCPUFeature = {"asimd", "true"}, applyIf = {"UseSVE", "0"})
public static void testMaskedXorSame() {
VectorMask<Short> mask = VectorMask.fromArray(S_SPECIES, m, 0);
ShortVector av = ShortVector.fromArray(S_SPECIES, sa, 0);

@ -56,6 +56,29 @@ public class TestPreconditions {
@IR(applyIfCPUFeatureAnd = {"asimd", "true", "sse", "true"},
applyIf = {"LoopMaxUnroll", "= 8"},
counts = {IRNode.LOOP, ">= 1000"})
public static void testApplyBoth() {}
public static void testApplyBoth1() {}
// The IR check should not be applied on aarch64, because the "applyIfAnd"
// condition returns false as the VM is run with LoopMaxUnroll=8.
// Note that precondition `applyIfCPUFeature` will be evaluated first with
// early return. Hence the IR check should not be applied on non-aarch64
// systems, and no exception is thrown because we are not checking the value
// of the unsupported "UseSVE" flag on non-aarch64 systems.
@Test
@IR(applyIfCPUFeature = {"asimd", "true"},
applyIfAnd = {"UseSVE", "= 0", "LoopMaxUnroll", "= 0"},
counts = {IRNode.LOOP, ">= 1000"})
public static void testApplyBoth2() {}
// The IR check should not be applied on x86, because the "applyIfAnd"
// condition returns false as the VM is run with LoopMaxUnroll=8.
// Note that precondition `applyIfCPUFeature` will be evaluated first with
// early return. Hence the IR check should not be applied on non-avx systems,
// and no exception is thrown because we are not checking the value of the
// unsupported "UseAVX" flag on non-avx systems.
@Test
@IR(applyIfCPUFeature = {"avx", "true"},
applyIfAnd = {"UseAVX", "= 2", "LoopMaxUnroll", "= 0"},
counts = {IRNode.LOOP, ">= 1000"})
public static void testApplyBoth3() {}
}