Skip to content

Commit 60544f9

Browse files
author
Xiaohong Gong
committed
8309894: compiler/vectorapi/VectorLogicalOpIdentityTest.java fails on SVE system with UseSVE=0
Reviewed-by: epeter, chagedorn
1 parent 0916e6a commit 60544f9

File tree

4 files changed

+54
-24
lines changed

4 files changed

+54
-24
lines changed

test/hotspot/jtreg/compiler/lib/ir_framework/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ One might also want to restrict the application of certain `@IR` rules depending
9494
- `applyIfOr`: Only apply a rule if **at least one** flag has the specified value/range of values.
9595

9696
#### Disable/Enable IR Rules based on available CPU Features
97-
Sometimes, an `@IR` rule should only be applied if a certain CPU feature is present. This can be done with
98-
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).
97+
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).
98+
99+
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).
99100

100101
#### Implicitly Skipping IR Verification
101102
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:

test/hotspot/jtreg/compiler/lib/ir_framework/test/IREncodingPrinter.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ private boolean shouldApplyIrRule(IR irAnno, String m, int ruleIndex, int ruleMa
132132
checkIRAnnotations(irAnno);
133133
if (isIRNodeUnsupported(irAnno)) {
134134
return false;
135+
} else if (irAnno.applyIfCPUFeature().length != 0 && !hasAllRequiredCPUFeature(irAnno.applyIfCPUFeature())) {
136+
printDisableReason(m, "Feature constraint not met (applyIfCPUFeature)", irAnno.applyIfCPUFeature(), ruleIndex, ruleMax);
137+
return false;
138+
} else if (irAnno.applyIfCPUFeatureAnd().length != 0 && !hasAllRequiredCPUFeature(irAnno.applyIfCPUFeatureAnd())) {
139+
printDisableReason(m, "Not all feature constraints are met (applyIfCPUFeatureAnd)", irAnno.applyIfCPUFeatureAnd(), ruleIndex, ruleMax);
140+
return false;
141+
} else if (irAnno.applyIfCPUFeatureOr().length != 0 && !hasAnyRequiredCPUFeature(irAnno.applyIfCPUFeatureOr())) {
142+
printDisableReason(m, "None of the feature constraints met (applyIfCPUFeatureOr)", irAnno.applyIfCPUFeatureOr(), ruleIndex, ruleMax);
143+
return false;
135144
} else if (irAnno.applyIf().length != 0 && !hasAllRequiredFlags(irAnno.applyIf(), "applyIf")) {
136145
printDisableReason(m, "Flag constraint not met (applyIf)", irAnno.applyIf(), ruleIndex, ruleMax);
137146
return false;
@@ -144,15 +153,6 @@ private boolean shouldApplyIrRule(IR irAnno, String m, int ruleIndex, int ruleMa
144153
} else if (irAnno.applyIfOr().length != 0 && hasNoRequiredFlags(irAnno.applyIfOr(), "applyIfOr")) {
145154
printDisableReason(m, "None of the flag constraints met (applyIfOr)", irAnno.applyIfOr(), ruleIndex, ruleMax);
146155
return false;
147-
} else if (irAnno.applyIfCPUFeature().length != 0 && !hasAllRequiredCPUFeature(irAnno.applyIfCPUFeature())) {
148-
printDisableReason(m, "Feature constraint not met (applyIfCPUFeature)", irAnno.applyIfCPUFeature(), ruleIndex, ruleMax);
149-
return false;
150-
} else if (irAnno.applyIfCPUFeatureAnd().length != 0 && !hasAllRequiredCPUFeature(irAnno.applyIfCPUFeatureAnd())) {
151-
printDisableReason(m, "Not all feature constraints are met (applyIfCPUFeatureAnd)", irAnno.applyIfCPUFeatureAnd(), ruleIndex, ruleMax);
152-
return false;
153-
} else if (irAnno.applyIfCPUFeatureOr().length != 0 && !hasAnyRequiredCPUFeature(irAnno.applyIfCPUFeatureOr())) {
154-
printDisableReason(m, "None of the feature constraints met (applyIfCPUFeatureOr)", irAnno.applyIfCPUFeatureOr(), ruleIndex, ruleMax);
155-
return false;
156156
} else {
157157
// All preconditions satisfied: apply rule.
158158
return true;

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Arm Limited. All rights reserved.
2+
* Copyright (c) 2022, 2023, Arm Limited. All rights reserved.
33
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -164,7 +164,7 @@ public static void testMaskedAndMinusOne1() {
164164
@Test
165165
@Warmup(10000)
166166
@IR(counts = {IRNode.LOAD_VECTOR, ">=1"})
167-
@IR(failOn = IRNode.AND_V, applyIfCPUFeatureAnd = {"asimd", "true", "sve", "false"})
167+
@IR(failOn = IRNode.AND_V, applyIfCPUFeature = {"asimd", "true"}, applyIf = {"UseSVE", "0"})
168168
public static void testMaskedAndMinusOne2() {
169169
VectorMask<Byte> mask = VectorMask.fromArray(B_SPECIES, m, 0);
170170
ByteVector av = ByteVector.fromArray(B_SPECIES, ba, 0);
@@ -185,7 +185,7 @@ public static void testMaskedAndMinusOne2() {
185185
@Test
186186
@Warmup(10000)
187187
@IR(counts = {IRNode.STORE_VECTOR, ">=1"})
188-
@IR(failOn = IRNode.AND_V, applyIfCPUFeatureAnd = {"asimd", "true", "sve", "false"})
188+
@IR(failOn = IRNode.AND_V, applyIfCPUFeature = {"asimd", "true"}, applyIf = {"UseSVE", "0"})
189189
public static void testMaskedAndZero1() {
190190
VectorMask<Short> mask = VectorMask.fromArray(S_SPECIES, m, 0);
191191
ShortVector av = ShortVector.fromArray(S_SPECIES, sa, 0);
@@ -302,7 +302,8 @@ public static void testAndSameValue4() {
302302
// Transform AndV(AndV(a, b, m), b, m) ==> AndV(a, b, m)
303303
@Test
304304
@Warmup(10000)
305-
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeatureOr = {"sve", "true", "avx512", "true"})
305+
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeature = {"sve", "true"}, applyIf = {"UseSVE", "> 0"})
306+
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeature = {"avx512", "true"})
306307
public static void testAndMaskSameValue1() {
307308
VectorMask<Integer> mask = VectorMask.fromArray(I_SPECIES, m, 0);
308309
IntVector av = IntVector.fromArray(I_SPECIES, ia, 0);
@@ -323,7 +324,8 @@ public static void testAndMaskSameValue1() {
323324
// Transform AndV(AndV(a, b, m), a, m) ==> AndV(a, b, m)
324325
@Test
325326
@Warmup(10000)
326-
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeatureOr = {"sve", "true", "avx512", "true"})
327+
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeature = {"sve", "true"}, applyIf = {"UseSVE", "> 0"})
328+
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeature = {"avx512", "true"})
327329
public static void testAndMaskSameValue2() {
328330
VectorMask<Long> mask = VectorMask.fromArray(L_SPECIES, m, 0);
329331
LongVector av = LongVector.fromArray(L_SPECIES, la, 0);
@@ -344,7 +346,8 @@ public static void testAndMaskSameValue2() {
344346
// Transform AndV(a, AndV(a, b, m), m) ==> AndV(a, b, m)
345347
@Test
346348
@Warmup(10000)
347-
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeatureOr = {"sve", "true", "avx512", "true"})
349+
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeature = {"sve", "true"}, applyIf = {"UseSVE", "> 0"})
350+
@IR(counts = {IRNode.AND_V, "1"}, applyIfCPUFeature = {"avx512", "true"})
348351
public static void testAndMaskSameValue3() {
349352
VectorMask<Integer> mask = VectorMask.fromArray(I_SPECIES, m, 0);
350353
IntVector av = IntVector.fromArray(I_SPECIES, ia, 0);
@@ -409,7 +412,7 @@ public static void testOrSame() {
409412
@Test
410413
@Warmup(10000)
411414
@IR(counts = {IRNode.STORE_VECTOR, ">=1"})
412-
@IR(failOn = IRNode.OR_V, applyIfCPUFeatureAnd = {"asimd", "true", "sve", "false"})
415+
@IR(failOn = IRNode.OR_V, applyIfCPUFeature = {"asimd", "true"}, applyIf = {"UseSVE", "0"})
413416
public static void testMaskedOrMinusOne1() {
414417
VectorMask<Byte> mask = VectorMask.fromArray(B_SPECIES, m, 0);
415418
ByteVector av = ByteVector.fromArray(B_SPECIES, ba, 0);
@@ -468,7 +471,7 @@ public static void testMaskedOrZero1() {
468471
@Test
469472
@Warmup(10000)
470473
@IR(counts = {IRNode.LOAD_VECTOR, ">=1"})
471-
@IR(failOn = IRNode.OR_V, applyIfCPUFeatureAnd = {"asimd", "true", "sve", "false"})
474+
@IR(failOn = IRNode.OR_V, applyIfCPUFeature = {"asimd", "true"}, applyIf = {"UseSVE", "0"})
472475
public static void testMaskedOrZero2() {
473476
VectorMask<Byte> mask = VectorMask.fromArray(B_SPECIES, m, 0);
474477
ByteVector av = ByteVector.fromArray(B_SPECIES, ba, 0);
@@ -566,7 +569,8 @@ public static void testOrSameValue4() {
566569
// Transform OrV(OrV(a, b, m), b, m) ==> OrV(a, b, m)
567570
@Test
568571
@Warmup(10000)
569-
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeatureOr = {"sve", "true", "avx512", "true"})
572+
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeature = {"sve", "true"}, applyIf = {"UseSVE", "> 0"})
573+
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeature = {"avx512", "true"})
570574
public static void testOrMaskSameValue1() {
571575
VectorMask<Integer> mask = VectorMask.fromArray(I_SPECIES, m, 0);
572576
IntVector av = IntVector.fromArray(I_SPECIES, ia, 0);
@@ -587,7 +591,8 @@ public static void testOrMaskSameValue1() {
587591
// Transform OrV(OrV(a, b, m), a, m) ==> OrV(a, b, m)
588592
@Test
589593
@Warmup(10000)
590-
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeatureOr = {"sve", "true", "avx512", "true"})
594+
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeature = {"sve", "true"}, applyIf = {"UseSVE", "> 0"})
595+
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeature = {"avx512", "true"})
591596
public static void testOrMaskSameValue2() {
592597
VectorMask<Long> mask = VectorMask.fromArray(L_SPECIES, m, 0);
593598
LongVector av = LongVector.fromArray(L_SPECIES, la, 0);
@@ -608,7 +613,8 @@ public static void testOrMaskSameValue2() {
608613
// Transform OrV(a, OrV(a, b, m), m) ==> OrV(a, b, m)
609614
@Test
610615
@Warmup(10000)
611-
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeatureOr = {"sve", "true", "avx512", "true"})
616+
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeature = {"sve", "true"}, applyIf = {"UseSVE", "> 0"})
617+
@IR(counts = {IRNode.OR_V, "1"}, applyIfCPUFeature = {"avx512", "true"})
612618
public static void testOrMaskSameValue3() {
613619
VectorMask<Integer> mask = VectorMask.fromArray(I_SPECIES, m, 0);
614620
IntVector av = IntVector.fromArray(I_SPECIES, ia, 0);
@@ -647,7 +653,7 @@ public static void testXorSame() {
647653
@Test
648654
@Warmup(10000)
649655
@IR(counts = {IRNode.STORE_VECTOR, ">=1"})
650-
@IR(failOn = IRNode.XOR_V, applyIfCPUFeatureAnd = {"asimd", "true", "sve", "false"})
656+
@IR(failOn = IRNode.XOR_V, applyIfCPUFeature = {"asimd", "true"}, applyIf = {"UseSVE", "0"})
651657
public static void testMaskedXorSame() {
652658
VectorMask<Short> mask = VectorMask.fromArray(S_SPECIES, m, 0);
653659
ShortVector av = ShortVector.fromArray(S_SPECIES, sa, 0);

test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestPreconditions.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@ public static void testApplyIfCPUFeatureOnly() {}
5656
@IR(applyIfCPUFeatureAnd = {"asimd", "true", "sse", "true"},
5757
applyIf = {"LoopMaxUnroll", "= 8"},
5858
counts = {IRNode.LOOP, ">= 1000"})
59-
public static void testApplyBoth() {}
59+
public static void testApplyBoth1() {}
6060

61+
// The IR check should not be applied on aarch64, because the "applyIfAnd"
62+
// condition returns false as the VM is run with LoopMaxUnroll=8.
63+
// Note that precondition `applyIfCPUFeature` will be evaluated first with
64+
// early return. Hence the IR check should not be applied on non-aarch64
65+
// systems, and no exception is thrown because we are not checking the value
66+
// of the unsupported "UseSVE" flag on non-aarch64 systems.
67+
@Test
68+
@IR(applyIfCPUFeature = {"asimd", "true"},
69+
applyIfAnd = {"UseSVE", "= 0", "LoopMaxUnroll", "= 0"},
70+
counts = {IRNode.LOOP, ">= 1000"})
71+
public static void testApplyBoth2() {}
72+
73+
// The IR check should not be applied on x86, because the "applyIfAnd"
74+
// condition returns false as the VM is run with LoopMaxUnroll=8.
75+
// Note that precondition `applyIfCPUFeature` will be evaluated first with
76+
// early return. Hence the IR check should not be applied on non-avx systems,
77+
// and no exception is thrown because we are not checking the value of the
78+
// unsupported "UseAVX" flag on non-avx systems.
79+
@Test
80+
@IR(applyIfCPUFeature = {"avx", "true"},
81+
applyIfAnd = {"UseAVX", "= 2", "LoopMaxUnroll", "= 0"},
82+
counts = {IRNode.LOOP, ">= 1000"})
83+
public static void testApplyBoth3() {}
6184
}

0 commit comments

Comments
 (0)