Mercurial > hg > truffle
changeset 5381:88cd108e0164
canonicalize more integer operations: (a+1)+2 to a+3 and (a*2)*2 to a*4
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Wed, 09 May 2012 10:42:03 +0200 |
parents | 8b5ef24da264 |
children | d6057d00e450 |
files | graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerAddNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerMulNode.java |
diffstat | 2 files changed, 28 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerAddNode.java Fri May 04 16:54:27 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerAddNode.java Wed May 09 10:42:03 2012 +0200 @@ -60,6 +60,20 @@ return x(); } } + // canonicalize expressions like "(a + 1) + 2" + if (x() instanceof IntegerAddNode) { + IntegerAddNode other = (IntegerAddNode) x(); + if (other.y().isConstant()) { + ConstantNode sum; + if (kind() == CiKind.Int) { + sum = ConstantNode.forInt(y().asConstant().asInt() + other.y().asConstant().asInt(), graph()); + } else { + assert kind() == CiKind.Long; + sum = ConstantNode.forLong(y().asConstant().asLong() + other.y().asConstant().asLong(), graph()); + } + return graph().unique(new IntegerAddNode(kind(), other.x(), sum)); + } + } } return this; }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerMulNode.java Fri May 04 16:54:27 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerMulNode.java Wed May 09 10:42:03 2012 +0200 @@ -57,6 +57,20 @@ if (c > 0 && CiUtil.isPowerOf2(c)) { return graph().unique(new LeftShiftNode(kind(), x(), ConstantNode.forInt(CiUtil.log2(c), graph()))); } + // canonicalize expressions like "(a * 1) * 2" + if (x() instanceof IntegerMulNode) { + IntegerMulNode other = (IntegerMulNode) x(); + if (other.y().isConstant()) { + ConstantNode sum; + if (kind() == CiKind.Int) { + sum = ConstantNode.forInt(y().asConstant().asInt() * other.y().asConstant().asInt(), graph()); + } else { + assert kind() == CiKind.Long; + sum = ConstantNode.forLong(y().asConstant().asLong() * other.y().asConstant().asLong(), graph()); + } + return graph().unique(new IntegerMulNode(kind(), other.x(), sum)); + } + } } return this; }