Skip to content

Commit ec5d6be

Browse files
committed
refactor InstanceofSnippetsTemplates#canMaterialize
1 parent aa81037 commit ec5d6be

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/InstanceOfSnippetsTemplates.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,12 @@
3131
import jdk.graal.compiler.core.common.calc.CanonicalCondition;
3232
import jdk.graal.compiler.debug.Assertions;
3333
import jdk.graal.compiler.graph.Node;
34-
import jdk.graal.compiler.nodes.ConditionAnchorNode;
3534
import jdk.graal.compiler.nodes.ConstantNode;
36-
import jdk.graal.compiler.nodes.FixedGuardNode;
3735
import jdk.graal.compiler.nodes.IfNode;
3836
import jdk.graal.compiler.nodes.LogicConstantNode;
39-
import jdk.graal.compiler.nodes.LogicNegationNode;
4037
import jdk.graal.compiler.nodes.LogicNode;
4138
import jdk.graal.compiler.nodes.NodeView;
4239
import jdk.graal.compiler.nodes.PhiNode;
43-
import jdk.graal.compiler.nodes.ShortCircuitOrNode;
4440
import jdk.graal.compiler.nodes.StructuredGraph;
4541
import jdk.graal.compiler.nodes.ValueNode;
4642
import jdk.graal.compiler.nodes.calc.CompareNode;
@@ -111,7 +107,12 @@ public void lower(FloatingNode instanceOf, LoweringTool tool) {
111107
*/
112108
protected InstanceOfUsageReplacer createReplacer(FloatingNode instanceOf, Instantiation instantiation, Node usage, final StructuredGraph graph) {
113109
InstanceOfUsageReplacer replacer;
114-
if (!canMaterialize(usage)) {
110+
111+
final boolean mustMaterializeAsConditional = usage instanceof ConditionalNode cn && cn.trueValue().isConstant() && cn.falseValue().isConstant();
112+
if (mustMaterializeAsConditional) {
113+
ConditionalNode c = (ConditionalNode) usage;
114+
replacer = new MaterializationUsageReplacer(instantiation, c.trueValue(), c.falseValue(), instanceOf, c);
115+
} else {
115116
ValueNode trueValue = ConstantNode.forInt(1, graph);
116117
ValueNode falseValue = ConstantNode.forInt(0, graph);
117118
if (instantiation.isInitialized() && (trueValue != instantiation.trueValue || falseValue != instantiation.falseValue)) {
@@ -123,28 +124,10 @@ protected InstanceOfUsageReplacer createReplacer(FloatingNode instanceOf, Instan
123124
falseValue = instantiation.falseValue;
124125
}
125126
replacer = new NonMaterializationUsageReplacer(instantiation, trueValue, falseValue, instanceOf, usage);
126-
} else {
127-
assert usage instanceof ConditionalNode : "unexpected usage of " + instanceOf + ": " + usage;
128-
ConditionalNode c = (ConditionalNode) usage;
129-
replacer = new MaterializationUsageReplacer(instantiation, c.trueValue(), c.falseValue(), instanceOf, c);
130127
}
131128
return replacer;
132129
}
133130

134-
/**
135-
* Determines if an {@code instanceof} usage can be materialized.
136-
*/
137-
protected boolean canMaterialize(Node usage) {
138-
if (usage instanceof ConditionalNode) {
139-
ConditionalNode cn = (ConditionalNode) usage;
140-
return cn.trueValue().isConstant() && cn.falseValue().isConstant();
141-
}
142-
if (usage instanceof IfNode || usage instanceof FixedGuardNode || usage instanceof ShortCircuitOrNode || usage instanceof ConditionAnchorNode || usage instanceof LogicNegationNode) {
143-
return false;
144-
}
145-
return true;
146-
}
147-
148131
/**
149132
* The result of instantiating an instanceof snippet. This enables a snippet instantiation to be
150133
* re-used which reduces compile time and produces better code.

0 commit comments

Comments
 (0)