Skip to content

Commit 5fe837a

Browse files
committedOct 3, 2022
8294236: [IR Framework] CPU preconditions are overriden by regular preconditions
Reviewed-by: chagedorn, pli, kvn
1 parent 8e9cfeb commit 5fe837a

File tree

3 files changed

+91
-65
lines changed

3 files changed

+91
-65
lines changed
 

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ An IR verification cannot always be performed. For example, a JTreg test could b
6464

6565
In general, the framework will only perform IR verification if the used VM flags allow a C2 compilation and if non-critical additional JTreg VM and Javaoptions are provided (see whiteflag list in [TestFramework](./TestFramework.java)). The user test code, however, can specify any flags which still allow an IR verification to be performed if a C2 compilation is done (expected flags by user defined `@IR` annotations).
6666

67-
An `@IR` annotation allows additional preconditions/restrictions on the currently present VM flags to enable or disable rules when certain flags are present or have a specific value (see `applyIfXX` properties of an `@IR` annotation).
67+
An `@IR` annotation allows additional preconditions/restrictions on the currently present VM flags to enable or disable rules when certain flags are present or have a specific value (see `applyIfXX` properties of an `@IR` annotation). If a `@Test` annotated method has multiple preconditions (for example `applyIf` and `applyIfCPUFeature`), they are evaluated as a logical conjunction.
6868

6969
More information about IR matching can be found in the Javadocs of [IR](./IR.java). Concrete examples on how to specify IR constraint/rules can be found in [IRExample](../../../testlibrary_tests/ir_framework/examples/IRExample.java) and [TestIRMatching](../../../testlibrary_tests/ir_framework/tests/TestIRMatching.java) (an internal framework test).
7070

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

+29-64
Original file line numberDiff line numberDiff line change
@@ -95,75 +95,40 @@ public void emitRuleEncoding(Method m, boolean skipped) {
9595
}
9696
}
9797

98+
private void printDisableReason(String method, String reason) {
99+
TestFrameworkSocket.write("Disabling IR matching for " + method + ": " + reason + ".",
100+
"[IREncodingPrinter]", true);
101+
}
102+
98103
private boolean shouldApplyIrRule(IR irAnno, String m) {
99104
checkIRAnnotations(irAnno);
100105
if (isDefaultRegexUnsupported(irAnno)) {
101106
return false;
107+
} else if (irAnno.applyIf().length != 0 && !hasAllRequiredFlags(irAnno.applyIf(), "applyIf")) {
108+
printDisableReason(m, "Flag constraint not met");
109+
return false;
110+
} else if (irAnno.applyIfNot().length != 0 && !hasNoRequiredFlags(irAnno.applyIfNot(), "applyIfNot")) {
111+
printDisableReason(m, "Flag constraint not met");
112+
return false;
113+
} else if (irAnno.applyIfAnd().length != 0 && !hasAllRequiredFlags(irAnno.applyIfAnd(), "applyIfAnd")) {
114+
printDisableReason(m, "All flag constraints not met");
115+
return false;
116+
} else if (irAnno.applyIfOr().length != 0 && hasNoRequiredFlags(irAnno.applyIfOr(), "applyIfOr")) {
117+
printDisableReason(m, "None of the flag constraints met");
118+
return false;
119+
} else if (irAnno.applyIfCPUFeature().length != 0 && !hasAllRequiredCPUFeature(irAnno.applyIfCPUFeature())) {
120+
printDisableReason(m, "Feature constraint not met");
121+
return false;
122+
} else if (irAnno.applyIfCPUFeatureAnd().length != 0 && !hasAllRequiredCPUFeature(irAnno.applyIfCPUFeatureAnd())) {
123+
printDisableReason(m, "All feature constraints not met");
124+
return false;
125+
} else if (irAnno.applyIfCPUFeatureOr().length != 0 && !hasAnyRequiredCPUFeature(irAnno.applyIfCPUFeatureOr())) {
126+
printDisableReason(m, "None of the feature constraints met");
127+
return false;
128+
} else {
129+
// All preconditions satisfied: apply rule.
130+
return true;
102131
}
103-
if (irAnno.applyIf().length != 0) {
104-
boolean check = hasAllRequiredFlags(irAnno.applyIf(), "applyIf");
105-
if (!check) {
106-
TestFrameworkSocket.write("Disabling IR matching for " + m + ": Flag constraint not met.",
107-
"[IREncodingPrinter]", true);
108-
}
109-
return check;
110-
}
111-
112-
if (irAnno.applyIfNot().length != 0) {
113-
boolean check = hasNoRequiredFlags(irAnno.applyIfNot(), "applyIfNot");
114-
if (!check) {
115-
TestFrameworkSocket.write("Disabling IR matching for " + m + ": Flag constraint not met.",
116-
"[IREncodingPrinter]", true);
117-
}
118-
return check;
119-
}
120-
121-
if (irAnno.applyIfAnd().length != 0) {
122-
boolean check = hasAllRequiredFlags(irAnno.applyIfAnd(), "applyIfAnd");
123-
if (!check) {
124-
TestFrameworkSocket.write("Disabling IR matching for " + m + ": All flag constraints not met.",
125-
"[IREncodingPrinter]", true);
126-
}
127-
return check;
128-
}
129-
130-
if (irAnno.applyIfOr().length != 0) {
131-
boolean check = hasNoRequiredFlags(irAnno.applyIfOr(), "applyIfOr");
132-
if (check) {
133-
TestFrameworkSocket.write("Disabling IR matching for " + m + ": None of the flag constraint met.",
134-
"[IREncodingPrinter]", true);
135-
}
136-
return !check;
137-
}
138-
139-
if (irAnno.applyIfCPUFeature().length != 0) {
140-
boolean check = hasAllRequiredCPUFeature(irAnno.applyIfCPUFeature());
141-
if (!check) {
142-
TestFrameworkSocket.write("Disabling IR matching for " + m + ": Feature constraint not met.",
143-
"[IREncodingPrinter]", true);
144-
}
145-
return check;
146-
}
147-
148-
if (irAnno.applyIfCPUFeatureAnd().length != 0) {
149-
boolean check = hasAllRequiredCPUFeature(irAnno.applyIfCPUFeatureAnd());
150-
if (!check) {
151-
TestFrameworkSocket.write("Disabling IR matching for " + m + ": All feature constraints not met.",
152-
"[IREncodingPrinter]", true);
153-
}
154-
return check;
155-
}
156-
157-
if (irAnno.applyIfCPUFeatureOr().length != 0) {
158-
boolean check = hasAnyRequiredCPUFeature(irAnno.applyIfCPUFeatureOr());
159-
if (!check) {
160-
TestFrameworkSocket.write("Disabling IR matching for " + m + ": None of the feature constraint met.",
161-
"[IREncodingPrinter]", true);
162-
}
163-
return check;
164-
}
165-
// No conditions, always apply.
166-
return true;
167132
}
168133

169134
private void checkIRAnnotations(IR irAnno) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2022, 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 8294236
26+
* @summary Tests different sources and combinations of preconditions.
27+
* @library /test/lib /
28+
* @requires vm.compiler2.enabled
29+
* @run driver ir_framework.tests.TestPreconditions
30+
*/
31+
32+
package ir_framework.tests;
33+
34+
import compiler.lib.ir_framework.*;
35+
36+
public class TestPreconditions {
37+
38+
public static void main(String[] args) {
39+
TestFramework.runWithFlags("-XX:LoopMaxUnroll=8");
40+
}
41+
42+
// The IR check should not be applied, since the VM is run with LoopMaxUnroll=8.
43+
@Test
44+
@IR(applyIf = {"LoopMaxUnroll", "= 0"},
45+
counts = {IRNode.LOOP, ">= 1000"})
46+
public static void testApplyIfOnly() {}
47+
48+
// The IR check should not be applied, since the CPU feature does not exist.
49+
@Test
50+
@IR(applyIfCPUFeature = {"this-feature-does-not-exist-at-all", "true"},
51+
counts = {IRNode.LOOP, ">= 1000"})
52+
public static void testApplyIfCPUFeatureOnly() {}
53+
54+
// The IR check should not be applied, since the CPU feature does not exist.
55+
@Test
56+
@IR(applyIfCPUFeature = {"this-feature-does-not-exist-at-all", "true"},
57+
applyIf = {"LoopMaxUnroll", "= 8"},
58+
counts = {IRNode.LOOP, ">= 1000"})
59+
public static void testApplyBoth() {}
60+
61+
}

0 commit comments

Comments
 (0)
Please sign in to comment.