31
31
import jdk .graal .compiler .core .common .calc .CanonicalCondition ;
32
32
import jdk .graal .compiler .debug .Assertions ;
33
33
import jdk .graal .compiler .graph .Node ;
34
- import jdk .graal .compiler .nodes .ConditionAnchorNode ;
35
34
import jdk .graal .compiler .nodes .ConstantNode ;
36
- import jdk .graal .compiler .nodes .FixedGuardNode ;
37
35
import jdk .graal .compiler .nodes .IfNode ;
38
36
import jdk .graal .compiler .nodes .LogicConstantNode ;
39
37
import jdk .graal .compiler .nodes .LogicNode ;
40
38
import jdk .graal .compiler .nodes .NodeView ;
41
39
import jdk .graal .compiler .nodes .PhiNode ;
42
- import jdk .graal .compiler .nodes .ShortCircuitOrNode ;
43
40
import jdk .graal .compiler .nodes .StructuredGraph ;
44
41
import jdk .graal .compiler .nodes .ValueNode ;
45
42
import jdk .graal .compiler .nodes .calc .CompareNode ;
@@ -110,7 +107,12 @@ public void lower(FloatingNode instanceOf, LoweringTool tool) {
110
107
*/
111
108
protected InstanceOfUsageReplacer createReplacer (FloatingNode instanceOf , Instantiation instantiation , Node usage , final StructuredGraph graph ) {
112
109
InstanceOfUsageReplacer replacer ;
113
- 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 {
114
116
ValueNode trueValue = ConstantNode .forInt (1 , graph );
115
117
ValueNode falseValue = ConstantNode .forInt (0 , graph );
116
118
if (instantiation .isInitialized () && (trueValue != instantiation .trueValue || falseValue != instantiation .falseValue )) {
@@ -122,28 +124,10 @@ protected InstanceOfUsageReplacer createReplacer(FloatingNode instanceOf, Instan
122
124
falseValue = instantiation .falseValue ;
123
125
}
124
126
replacer = new NonMaterializationUsageReplacer (instantiation , trueValue , falseValue , instanceOf , usage );
125
- } else {
126
- assert usage instanceof ConditionalNode : "unexpected usage of " + instanceOf + ": " + usage ;
127
- ConditionalNode c = (ConditionalNode ) usage ;
128
- replacer = new MaterializationUsageReplacer (instantiation , c .trueValue (), c .falseValue (), instanceOf , c );
129
127
}
130
128
return replacer ;
131
129
}
132
130
133
- /**
134
- * Determines if an {@code instanceof} usage can be materialized.
135
- */
136
- protected boolean canMaterialize (Node usage ) {
137
- if (usage instanceof ConditionalNode ) {
138
- ConditionalNode cn = (ConditionalNode ) usage ;
139
- return cn .trueValue ().isConstant () && cn .falseValue ().isConstant ();
140
- }
141
- if (usage instanceof IfNode || usage instanceof FixedGuardNode || usage instanceof ShortCircuitOrNode || usage instanceof ConditionAnchorNode ) {
142
- return false ;
143
- }
144
- return true ;
145
- }
146
-
147
131
/**
148
132
* The result of instantiating an instanceof snippet. This enables a snippet instantiation to be
149
133
* re-used which reduces compile time and produces better code.
0 commit comments