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
- import jdk .graal .compiler .nodes .LogicNegationNode ;
40
37
import jdk .graal .compiler .nodes .LogicNode ;
41
38
import jdk .graal .compiler .nodes .NodeView ;
42
39
import jdk .graal .compiler .nodes .PhiNode ;
43
- import jdk .graal .compiler .nodes .ShortCircuitOrNode ;
44
40
import jdk .graal .compiler .nodes .StructuredGraph ;
45
41
import jdk .graal .compiler .nodes .ValueNode ;
46
42
import jdk .graal .compiler .nodes .calc .CompareNode ;
@@ -111,7 +107,12 @@ public void lower(FloatingNode instanceOf, LoweringTool tool) {
111
107
*/
112
108
protected InstanceOfUsageReplacer createReplacer (FloatingNode instanceOf , Instantiation instantiation , Node usage , final StructuredGraph graph ) {
113
109
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 {
115
116
ValueNode trueValue = ConstantNode .forInt (1 , graph );
116
117
ValueNode falseValue = ConstantNode .forInt (0 , graph );
117
118
if (instantiation .isInitialized () && (trueValue != instantiation .trueValue || falseValue != instantiation .falseValue )) {
@@ -123,28 +124,10 @@ protected InstanceOfUsageReplacer createReplacer(FloatingNode instanceOf, Instan
123
124
falseValue = instantiation .falseValue ;
124
125
}
125
126
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 );
130
127
}
131
128
return replacer ;
132
129
}
133
130
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
-
148
131
/**
149
132
* The result of instantiating an instanceof snippet. This enables a snippet instantiation to be
150
133
* re-used which reduces compile time and produces better code.
0 commit comments