Mercurial > hg > truffle
diff graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NormalizeCompareNode.java @ 19379:b720a1e02fa0
Add graph building time canonicalization for NormalizeCompareNode.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 15 Feb 2015 14:33:16 +0100 |
parents | 7227f5671c87 |
children | 7e2c87dae93e |
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NormalizeCompareNode.java Sun Feb 15 14:28:01 2015 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NormalizeCompareNode.java Sun Feb 15 14:33:16 2015 +0100 @@ -23,6 +23,7 @@ package com.oracle.graal.nodes.calc; import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.common.calc.*; import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.graph.spi.*; import com.oracle.graal.nodeinfo.*; @@ -44,6 +45,26 @@ 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); + 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); + } else if (logicConstantNode.getValue()) { + return ConstantNode.forInt(0); + } else { + return ConstantNode.forInt(1); + } + } + } + + return new NormalizeCompareNode(x, y, isUnorderedLess); + } + @Override public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) { // nothing to do @@ -56,10 +77,10 @@ LogicNode lessComp; if (getX().stamp() instanceof FloatStamp) { equalComp = graph().unique(FloatEqualsNode.create(getX(), getY(), tool.getConstantReflection())); - lessComp = graph().unique(new FloatLessThanNode(getX(), getY(), isUnorderedLess)); + lessComp = graph().unique(FloatLessThanNode.create(getX(), getY(), isUnorderedLess, tool.getConstantReflection())); } else { - equalComp = graph().unique(new IntegerEqualsNode(getX(), getY())); - lessComp = graph().unique(new IntegerLessThanNode(getX(), getY())); + equalComp = graph().unique(IntegerEqualsNode.create(getX(), getY(), tool.getConstantReflection())); + lessComp = graph().unique(IntegerLessThanNode.create(getX(), getY(), tool.getConstantReflection())); } ConditionalNode equalValue = graph().unique(new ConditionalNode(equalComp, ConstantNode.forInt(0, graph()), ConstantNode.forInt(1, graph())));