hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/NormalizeCompareNode.java
changeset 46459 7d4e637d3f21
parent 46393 d497d892ab11
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/NormalizeCompareNode.java	Fri May 12 13:14:25 2017 -0700
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/NormalizeCompareNode.java	Fri May 12 13:56:13 2017 -0700
@@ -25,9 +25,9 @@
 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_2;
 
 import org.graalvm.compiler.core.common.calc.Condition;
-import org.graalvm.compiler.core.common.type.FloatStamp;
 import org.graalvm.compiler.core.common.type.Stamp;
 import org.graalvm.compiler.core.common.type.StampFactory;
+import org.graalvm.compiler.graph.IterableNodeType;
 import org.graalvm.compiler.graph.NodeClass;
 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
 import org.graalvm.compiler.nodeinfo.NodeCycles;
@@ -36,8 +36,6 @@
 import org.graalvm.compiler.nodes.LogicConstantNode;
 import org.graalvm.compiler.nodes.LogicNode;
 import org.graalvm.compiler.nodes.ValueNode;
-import org.graalvm.compiler.nodes.spi.Lowerable;
-import org.graalvm.compiler.nodes.spi.LoweringTool;
 
 import jdk.vm.ci.meta.ConstantReflectionProvider;
 import jdk.vm.ci.meta.JavaKind;
@@ -48,39 +46,50 @@
  * true.
  */
 @NodeInfo(cycles = NodeCycles.CYCLES_2, size = SIZE_2)
-public final class NormalizeCompareNode extends BinaryNode implements Lowerable {
+public final class NormalizeCompareNode extends BinaryNode implements IterableNodeType {
 
     public static final NodeClass<NormalizeCompareNode> TYPE = NodeClass.create(NormalizeCompareNode.class);
     protected final boolean isUnorderedLess;
 
-    public NormalizeCompareNode(ValueNode x, ValueNode y, boolean isUnorderedLess) {
-        super(TYPE, StampFactory.forKind(JavaKind.Int), x, y);
+    public NormalizeCompareNode(ValueNode x, ValueNode y, JavaKind kind, boolean isUnorderedLess) {
+        super(TYPE, StampFactory.forInteger(kind, -1, 1), x, y);
         this.isUnorderedLess = isUnorderedLess;
     }
 
-    public static ValueNode create(ValueNode x, ValueNode y, boolean isUnorderedLess, ConstantReflectionProvider constantReflection) {
-        LogicNode result = CompareNode.tryConstantFold(Condition.EQ, x, y, constantReflection, false);
+    public static ValueNode create(ValueNode x, ValueNode y, boolean isUnorderedLess, JavaKind kind, ConstantReflectionProvider constantReflection) {
+        ValueNode result = tryConstantFold(x, y, isUnorderedLess, kind, constantReflection);
+        if (result != null) {
+            return result;
+        }
+
+        return new NormalizeCompareNode(x, y, kind, isUnorderedLess);
+    }
+
+    protected static ValueNode tryConstantFold(ValueNode x, ValueNode y, boolean isUnorderedLess, JavaKind kind, ConstantReflectionProvider constantReflection) {
+        LogicNode result = CompareNode.tryConstantFold(Condition.EQ, x, y, null, false);
         if (result instanceof LogicConstantNode) {
             LogicConstantNode logicConstantNode = (LogicConstantNode) result;
             LogicNode resultLT = CompareNode.tryConstantFold(Condition.LT, x, y, constantReflection, isUnorderedLess);
             if (resultLT instanceof LogicConstantNode) {
                 LogicConstantNode logicConstantNodeLT = (LogicConstantNode) resultLT;
                 if (logicConstantNodeLT.getValue()) {
-                    return ConstantNode.forInt(-1);
+                    return ConstantNode.forIntegerKind(kind, -1);
                 } else if (logicConstantNode.getValue()) {
-                    return ConstantNode.forInt(0);
+                    return ConstantNode.forIntegerKind(kind, 0);
                 } else {
-                    return ConstantNode.forInt(1);
+                    return ConstantNode.forIntegerKind(kind, 1);
                 }
             }
         }
-
-        return new NormalizeCompareNode(x, y, isUnorderedLess);
+        return null;
     }
 
     @Override
     public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
-        // nothing to do
+        ValueNode result = tryConstantFold(x, y, isUnorderedLess, stamp().getStackKind(), tool.getConstantReflection());
+        if (result != null) {
+            return result;
+        }
         return this;
     }
 
@@ -90,24 +99,11 @@
     }
 
     @Override
-    public void lower(LoweringTool tool) {
-        LogicNode equalComp;
-        LogicNode lessComp;
-        if (getX().stamp() instanceof FloatStamp) {
-            equalComp = graph().addOrUniqueWithInputs(FloatEqualsNode.create(getX(), getY()));
-            lessComp = graph().addOrUniqueWithInputs(FloatLessThanNode.create(getX(), getY(), isUnorderedLess));
-        } else {
-            equalComp = graph().addOrUniqueWithInputs(IntegerEqualsNode.create(getX(), getY()));
-            lessComp = graph().addOrUniqueWithInputs(IntegerLessThanNode.create(getX(), getY()));
-        }
-
-        ConditionalNode equalValue = graph().unique(new ConditionalNode(equalComp, ConstantNode.forInt(0, graph()), ConstantNode.forInt(1, graph())));
-        ConditionalNode value = graph().unique(new ConditionalNode(lessComp, ConstantNode.forInt(-1, graph()), equalValue));
-        replaceAtUsagesAndDelete(value);
-    }
-
-    @Override
     public Stamp foldStamp(Stamp stampX, Stamp stampY) {
         return stamp();
     }
+
+    public boolean isUnorderedLess() {
+        return isUnorderedLess;
+    }
 }