Mercurial > hg > graal-compiler
changeset 23014:60dd55e84d87
Tune sign and zero extend canonicalizations to take usage counts of the convert operation and its value into account.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Wed, 18 Nov 2015 04:00:32 +0100 |
parents | 79266e707964 |
children | dc609421fcdb |
files | graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NarrowNode.java |
diffstat | 2 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java Tue Nov 17 16:32:15 2015 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java Wed Nov 18 04:00:32 2015 +0100 @@ -132,6 +132,12 @@ ConvertNode convertX = (ConvertNode) forX; ConvertNode convertY = (ConvertNode) forY; if (convertX.preservesOrder(condition()) && convertY.preservesOrder(condition()) && convertX.getValue().stamp().isCompatible(convertY.getValue().stamp())) { + boolean multiUsage = (convertX.asNode().getUsageCount() > 1 || convertY.asNode().getUsageCount() > 1); + if ((forX instanceof ZeroExtendNode || forX instanceof SignExtendNode) && multiUsage) { + // Do not perform for zero or sign extend if there are multiple usages of the + // value. + return this; + } return duplicateModified(convertX.getValue(), convertY.getValue()); } } @@ -154,6 +160,12 @@ return optimizeNormalizeCmp(constant, (NormalizeCompareNode) nonConstant, mirrored); } else if (nonConstant instanceof ConvertNode) { ConvertNode convert = (ConvertNode) nonConstant; + boolean multiUsage = (convert.asNode().getUsageCount() > 1 && convert.getValue().getUsageCount() == 1); + if ((convert instanceof ZeroExtendNode || convert instanceof SignExtendNode) && multiUsage) { + // Do not perform for zero or sign extend if it could introduce + // new live values. + return this; + } ConstantNode newConstant = canonicalConvertConstant(tool, convert, constant); if (newConstant != null) { if (mirrored) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NarrowNode.java Tue Nov 17 16:32:15 2015 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NarrowNode.java Wed Nov 18 04:00:32 2015 +0100 @@ -85,6 +85,12 @@ } else if (forValue instanceof IntegerConvertNode) { // SignExtendNode or ZeroExtendNode IntegerConvertNode<?, ?> other = (IntegerConvertNode<?, ?>) forValue; + if (other.getValue().getUsageCount() == 1 && other.getUsageCount() > 1) { + // Do not perform if this will introduce a new live value. + // If the original value's usage count is > 1, there is already another user. + // If the convert's usage count is <=1, it will be dead code eliminated. + return this; + } if (getResultBits() == other.getInputBits()) { // xxxx -(extend)-> yyyy xxxx -(narrow)-> xxxx // ==> no-op