# HG changeset patch # User Christian Wirth # Date 1405588896 -7200 # Node ID eb3209d37c506a14cee27c319931249483936a9a # Parent 45fff0246a4389ca3523d1ef8d4016f1ca5a2355 extract methods in exact arithmetic nodes diff -r 45fff0246a43 -r eb3209d37c50 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/arithmetic/IntegerAddExactNode.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/arithmetic/IntegerAddExactNode.java Thu Jul 17 11:13:31 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/arithmetic/IntegerAddExactNode.java Thu Jul 17 11:21:36 2014 +0200 @@ -54,19 +54,7 @@ return new IntegerAddExactNode(forY, forX); } if (forX.isConstant()) { - Constant xConst = forX.asConstant(); - Constant yConst = forY.asConstant(); - assert xConst.getKind() == yConst.getKind(); - try { - if (xConst.getKind() == Kind.Int) { - return ConstantNode.forInt(ExactMath.addExact(xConst.asInt(), yConst.asInt())); - } else { - assert xConst.getKind() == Kind.Long; - return ConstantNode.forLong(ExactMath.addExact(xConst.asLong(), yConst.asLong())); - } - } catch (ArithmeticException ex) { - // The operation will result in an overflow exception, so do not canonicalize. - } + return canonicalXconstant(forX, forY); } else if (forY.isConstant()) { long c = forY.asConstant().asLong(); if (c == 0) { @@ -76,6 +64,23 @@ return this; } + private ValueNode canonicalXconstant(ValueNode forX, ValueNode forY) { + Constant xConst = forX.asConstant(); + Constant yConst = forY.asConstant(); + assert xConst.getKind() == yConst.getKind(); + try { + if (xConst.getKind() == Kind.Int) { + return ConstantNode.forInt(ExactMath.addExact(xConst.asInt(), yConst.asInt())); + } else { + assert xConst.getKind() == Kind.Long; + return ConstantNode.forLong(ExactMath.addExact(xConst.asLong(), yConst.asLong())); + } + } catch (ArithmeticException ex) { + // The operation will result in an overflow exception, so do not canonicalize. + } + return this; + } + @Override public IntegerExactArithmeticSplitNode createSplit(BeginNode next, BeginNode deopt) { return graph().add(new IntegerAddExactSplitNode(stamp(), getX(), getY(), next, deopt)); diff -r 45fff0246a43 -r eb3209d37c50 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/arithmetic/IntegerMulExactNode.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/arithmetic/IntegerMulExactNode.java Thu Jul 17 11:13:31 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/arithmetic/IntegerMulExactNode.java Thu Jul 17 11:21:36 2014 +0200 @@ -47,19 +47,7 @@ return new IntegerMulExactNode(forY, forX); } if (forX.isConstant()) { - Constant xConst = forX.asConstant(); - Constant yConst = forY.asConstant(); - assert xConst.getKind() == yConst.getKind(); - try { - if (xConst.getKind() == Kind.Int) { - return ConstantNode.forInt(ExactMath.multiplyExact(xConst.asInt(), yConst.asInt())); - } else { - assert xConst.getKind() == Kind.Long; - return ConstantNode.forLong(ExactMath.multiplyExact(xConst.asLong(), yConst.asLong())); - } - } catch (ArithmeticException ex) { - // The operation will result in an overflow exception, so do not canonicalize. - } + return canonicalXconstant(forX, forY); } else if (forY.isConstant()) { long c = forY.asConstant().asLong(); if (c == 1) { @@ -72,6 +60,23 @@ return this; } + private ValueNode canonicalXconstant(ValueNode forX, ValueNode forY) { + Constant xConst = forX.asConstant(); + Constant yConst = forY.asConstant(); + assert xConst.getKind() == yConst.getKind(); + try { + if (xConst.getKind() == Kind.Int) { + return ConstantNode.forInt(ExactMath.multiplyExact(xConst.asInt(), yConst.asInt())); + } else { + assert xConst.getKind() == Kind.Long; + return ConstantNode.forLong(ExactMath.multiplyExact(xConst.asLong(), yConst.asLong())); + } + } catch (ArithmeticException ex) { + // The operation will result in an overflow exception, so do not canonicalize. + } + return this; + } + @Override public IntegerExactArithmeticSplitNode createSplit(BeginNode next, BeginNode deopt) { return graph().add(new IntegerMulExactSplitNode(stamp(), getX(), getY(), next, deopt)); diff -r 45fff0246a43 -r eb3209d37c50 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/arithmetic/IntegerSubExactNode.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/arithmetic/IntegerSubExactNode.java Thu Jul 17 11:13:31 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/arithmetic/IntegerSubExactNode.java Thu Jul 17 11:21:36 2014 +0200 @@ -55,19 +55,7 @@ return ConstantNode.forIntegerStamp(stamp(), 0); } if (forX.isConstant() && forY.isConstant()) { - Constant xConst = forX.asConstant(); - Constant yConst = forY.asConstant(); - assert xConst.getKind() == yConst.getKind(); - try { - if (xConst.getKind() == Kind.Int) { - return ConstantNode.forInt(ExactMath.subtractExact(xConst.asInt(), yConst.asInt())); - } else { - assert xConst.getKind() == Kind.Long; - return ConstantNode.forLong(ExactMath.subtractExact(xConst.asLong(), yConst.asLong())); - } - } catch (ArithmeticException ex) { - // The operation will result in an overflow exception, so do not canonicalize. - } + return canonicalXYconstant(forX, forY); } else if (forY.isConstant()) { long c = forY.asConstant().asLong(); if (c == 0) { @@ -77,6 +65,23 @@ return this; } + private ValueNode canonicalXYconstant(ValueNode forX, ValueNode forY) { + Constant xConst = forX.asConstant(); + Constant yConst = forY.asConstant(); + assert xConst.getKind() == yConst.getKind(); + try { + if (xConst.getKind() == Kind.Int) { + return ConstantNode.forInt(ExactMath.subtractExact(xConst.asInt(), yConst.asInt())); + } else { + assert xConst.getKind() == Kind.Long; + return ConstantNode.forLong(ExactMath.subtractExact(xConst.asLong(), yConst.asLong())); + } + } catch (ArithmeticException ex) { + // The operation will result in an overflow exception, so do not canonicalize. + } + return this; + } + @Override public IntegerExactArithmeticSplitNode createSplit(BeginNode next, BeginNode deopt) { return graph().add(new IntegerSubExactSplitNode(stamp(), getX(), getY(), next, deopt));