3131import jdk .graal .compiler .core .common .calc .CanonicalCondition ;
3232import jdk .graal .compiler .debug .Assertions ;
3333import jdk .graal .compiler .graph .Node ;
34- import jdk .graal .compiler .nodes .ConditionAnchorNode ;
3534import jdk .graal .compiler .nodes .ConstantNode ;
36- import jdk .graal .compiler .nodes .FixedGuardNode ;
3735import jdk .graal .compiler .nodes .IfNode ;
3836import jdk .graal .compiler .nodes .LogicConstantNode ;
3937import jdk .graal .compiler .nodes .LogicNode ;
4038import jdk .graal .compiler .nodes .NodeView ;
4139import jdk .graal .compiler .nodes .PhiNode ;
42- import jdk .graal .compiler .nodes .ShortCircuitOrNode ;
4340import jdk .graal .compiler .nodes .StructuredGraph ;
4441import jdk .graal .compiler .nodes .ValueNode ;
4542import jdk .graal .compiler .nodes .calc .CompareNode ;
@@ -110,7 +107,12 @@ public void lower(FloatingNode instanceOf, LoweringTool tool) {
110107 */
111108 protected InstanceOfUsageReplacer createReplacer (FloatingNode instanceOf , Instantiation instantiation , Node usage , final StructuredGraph graph ) {
112109 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 {
114116 ValueNode trueValue = ConstantNode .forInt (1 , graph );
115117 ValueNode falseValue = ConstantNode .forInt (0 , graph );
116118 if (instantiation .isInitialized () && (trueValue != instantiation .trueValue || falseValue != instantiation .falseValue )) {
@@ -122,28 +124,10 @@ protected InstanceOfUsageReplacer createReplacer(FloatingNode instanceOf, Instan
122124 falseValue = instantiation .falseValue ;
123125 }
124126 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 );
129127 }
130128 return replacer ;
131129 }
132130
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-
147131 /**
148132 * The result of instantiating an instanceof snippet. This enables a snippet instantiation to be
149133 * re-used which reduces compile time and produces better code.
0 commit comments