# HG changeset patch # User Roland Schatz # Date 1407845630 -7200 # Node ID c914e5837b4bf7adcc222eacf0aab0d22b16ff74 # Parent 9f5e33cf8d52b4ea76fa084e08902fb3a908f728 More canonicalizations in FloatAdd/SubNode. diff -r 9f5e33cf8d52 -r c914e5837b4b graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/FloatAddNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/FloatAddNode.java Tue Aug 12 14:04:01 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/FloatAddNode.java Tue Aug 12 14:13:50 2014 +0200 @@ -76,6 +76,16 @@ throw GraalGraphInternalError.shouldNotReachHere(); } } + /* + * JVM spec, Chapter 6, dsub/fsub bytecode: For double subtraction, it is always the case + * that a-b produces the same result as a+(-b). + */ + if (forX instanceof NegateNode) { + return new FloatSubNode(forY, ((NegateNode) forX).getValue(), isStrictFP()); + } + if (forY instanceof NegateNode) { + return new FloatSubNode(forX, ((NegateNode) forY).getValue(), isStrictFP()); + } return this; } diff -r 9f5e33cf8d52 -r c914e5837b4b graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/FloatSubNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/FloatSubNode.java Tue Aug 12 14:04:01 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/FloatSubNode.java Tue Aug 12 14:13:50 2014 +0200 @@ -56,6 +56,24 @@ if (forX.isConstant() && forY.isConstant()) { return ConstantNode.forPrimitive(evalConst(forX.asConstant(), forY.asConstant())); } + // Constant -0.0 is an additive identity, so (-0.0) - x == (-0.0) + (-x) == -x. + if (forX.isConstant()) { + Constant x = forX.asConstant(); + switch (x.getKind()) { + case Float: + if (Float.compare(x.asFloat(), -0.0f) == 0) { + return new NegateNode(forY); + } + break; + case Double: + if (Double.compare(x.asDouble(), -0.0) == 0) { + return new NegateNode(forY); + } + break; + default: + throw GraalGraphInternalError.shouldNotReachHere(); + } + } // Constant -0.0 can't be eliminated since it can affect the sign of the result. // Constant 0.0 is a subtractive identity. if (forY.isConstant()) { @@ -77,6 +95,13 @@ throw GraalGraphInternalError.shouldNotReachHere(); } } + /* + * JVM spec, Chapter 6, dsub/fsub bytecode: For double subtraction, it is always the case + * that a-b produces the same result as a+(-b). + */ + if (forY instanceof NegateNode) { + return new FloatAddNode(forX, ((NegateNode) forY).getValue(), isStrictFP()); + } return this; }