# HG changeset patch # User Roland Schatz # Date 1413815165 -7200 # Node ID 689092d5cf4474994c62e8f1f583b9e2afd09486 # Parent 3c7e73362d6aedb31891530b18c5318e5bbdaf4e Store explicit input bit width in IntegerConvertNode. diff -r 3c7e73362d6a -r 689092d5cf44 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/ArithmeticOpTable.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/ArithmeticOpTable.java Mon Oct 20 12:12:52 2014 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/ArithmeticOpTable.java Mon Oct 20 16:26:05 2014 +0200 @@ -455,6 +455,6 @@ public abstract Constant foldConstant(int inputBits, int resultBits, Constant value); - public abstract Stamp foldStamp(int resultBits, Stamp stamp); + public abstract Stamp foldStamp(int inputBits, int resultBits, Stamp stamp); } } diff -r 3c7e73362d6a -r 689092d5cf44 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/IntegerStamp.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/IntegerStamp.java Mon Oct 20 12:12:52 2014 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/IntegerStamp.java Mon Oct 20 16:26:05 2014 +0200 @@ -661,9 +661,9 @@ } @Override - public Stamp foldStamp(int resultBits, Stamp input) { + public Stamp foldStamp(int inputBits, int resultBits, Stamp input) { IntegerStamp stamp = (IntegerStamp) input; - int inputBits = stamp.getBits(); + assert inputBits == stamp.getBits(); assert inputBits <= resultBits; long downMask = CodeUtil.zeroExtend(stamp.downMask(), inputBits); @@ -690,9 +690,9 @@ } @Override - public Stamp foldStamp(int resultBits, Stamp input) { + public Stamp foldStamp(int inputBits, int resultBits, Stamp input) { IntegerStamp stamp = (IntegerStamp) input; - int inputBits = stamp.getBits(); + assert inputBits == stamp.getBits(); assert inputBits <= resultBits; long defaultMask = CodeUtil.mask(resultBits); @@ -711,9 +711,9 @@ } @Override - public Stamp foldStamp(int resultBits, Stamp input) { + public Stamp foldStamp(int inputBits, int resultBits, Stamp input) { IntegerStamp stamp = (IntegerStamp) input; - int inputBits = stamp.getBits(); + assert inputBits == stamp.getBits(); assert resultBits <= inputBits; if (resultBits == inputBits) { return stamp; diff -r 3c7e73362d6a -r 689092d5cf44 graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/IntegerStampTest.java --- a/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/IntegerStampTest.java Mon Oct 20 12:12:52 2014 +0200 +++ b/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/IntegerStampTest.java Mon Oct 20 16:26:05 2014 +0200 @@ -129,10 +129,10 @@ assertEquals(new IntegerStamp(64, -10000, 1000, 0, 0xffffffffffffffffL), StampFactory.forInteger(Kind.Long, -10000, 1000)); } - private static Stamp narrowingKindConversion(Stamp stamp, Kind kind) { - Stamp narrow = IntegerStamp.OPS.getNarrow().foldStamp(kind.getBitCount(), stamp); + private static Stamp narrowingKindConversion(IntegerStamp stamp, Kind kind) { + Stamp narrow = IntegerStamp.OPS.getNarrow().foldStamp(stamp.getBits(), kind.getBitCount(), stamp); IntegerConvertOp implicitExtend = kind.isUnsigned() ? IntegerStamp.OPS.getZeroExtend() : IntegerStamp.OPS.getSignExtend(); - return implicitExtend.foldStamp(32, narrow); + return implicitExtend.foldStamp(kind.getBitCount(), 32, narrow); } @Test @@ -273,7 +273,7 @@ private static void testSignExtendShort(long lower, long upper) { Stamp shortStamp = StampFactory.forInteger(16, lower, upper); - Stamp intStamp = IntegerStamp.OPS.getSignExtend().foldStamp(32, shortStamp); + Stamp intStamp = IntegerStamp.OPS.getSignExtend().foldStamp(16, 32, shortStamp); assertEquals(StampFactory.forInteger(32, lower, upper), intStamp); } @@ -289,7 +289,7 @@ private static void testZeroExtendShort(long lower, long upper, long newLower, long newUpper) { Stamp shortStamp = StampFactory.forInteger(16, lower, upper); - Stamp intStamp = IntegerStamp.OPS.getZeroExtend().foldStamp(32, shortStamp); + Stamp intStamp = IntegerStamp.OPS.getZeroExtend().foldStamp(16, 32, shortStamp); assertEquals(StampFactory.forInteger(32, newLower, newUpper), intStamp); } diff -r 3c7e73362d6a -r 689092d5cf44 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerConvertNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerConvertNode.java Mon Oct 20 12:12:52 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerConvertNode.java Mon Oct 20 16:26:05 2014 +0200 @@ -41,27 +41,26 @@ protected final Function> getOp; protected final Function> getReverseOp; + protected final int inputBits; protected final int resultBits; - protected IntegerConvertNode(Function> getOp, Function> getReverseOp, int resultBits, ValueNode input) { - super(getOp.apply(ArithmeticOpTable.forStamp(input.stamp())).foldStamp(resultBits, input.stamp()), input); + protected IntegerConvertNode(Function> getOp, Function> getReverseOp, int inputBits, int resultBits, + ValueNode input) { + super(getOp.apply(ArithmeticOpTable.forStamp(input.stamp())).foldStamp(inputBits, resultBits, input.stamp()), input); this.getOp = getOp; this.getReverseOp = getReverseOp; + this.inputBits = inputBits; this.resultBits = resultBits; } + public int getInputBits() { + return inputBits; + } + public int getResultBits() { return resultBits; } - public int getInputBits() { - if (getValue().stamp() instanceof IntegerStamp) { - return ((IntegerStamp) getValue().stamp()).getBits(); - } else { - return 0; - } - } - protected final IntegerConvertOp getOp(ValueNode forValue) { return getOp.apply(ArithmeticOpTable.forStamp(forValue.stamp())); } @@ -79,20 +78,18 @@ @Override public boolean inferStamp() { - return updateStamp(getOp(getValue()).foldStamp(resultBits, getValue().stamp())); + return updateStamp(getOp(getValue()).foldStamp(inputBits, resultBits, getValue().stamp())); } @Override public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { - if (value.stamp() instanceof IntegerStamp) { - int inputBits = ((IntegerStamp) value.stamp()).getBits(); - if (inputBits == resultBits) { - return value; - } else if (value.isConstant()) { - return ConstantNode.forPrimitive(stamp(), convert(forValue.asConstant())); - } + if (inputBits == resultBits) { + return value; + } else if (value.isConstant()) { + return ConstantNode.forPrimitive(stamp(), convert(forValue.asConstant())); + } else { + return this; } - return this; } public static ValueNode convert(ValueNode input, Stamp stamp) { @@ -120,7 +117,7 @@ if (toStamp.getBits() == fromStamp.getBits()) { result = input; } else if (toStamp.getBits() < fromStamp.getBits()) { - result = NarrowNode.create(input, toStamp.getBits()); + result = NarrowNode.create(input, fromStamp.getBits(), toStamp.getBits()); } else if (zeroExtend) { // toStamp.getBits() > fromStamp.getBits() result = ZeroExtendNode.create(input, toStamp.getBits()); diff -r 3c7e73362d6a -r 689092d5cf44 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NarrowNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NarrowNode.java Mon Oct 20 12:12:52 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NarrowNode.java Mon Oct 20 16:26:05 2014 +0200 @@ -38,11 +38,17 @@ public class NarrowNode extends IntegerConvertNode { public static NarrowNode create(ValueNode input, int resultBits) { - return new NarrowNode(input, resultBits); + int inputBits = PrimitiveStamp.getBits(input.stamp()); + assert 0 < resultBits && resultBits <= inputBits; + return create(input, inputBits, resultBits); } - protected NarrowNode(ValueNode input, int resultBits) { - super(ArithmeticOpTable::getNarrow, ArithmeticOpTable::getSignExtend, resultBits, input); + public static NarrowNode create(ValueNode input, int inputBits, int resultBits) { + return new NarrowNode(input, inputBits, resultBits); + } + + protected NarrowNode(ValueNode input, int inputBits, int resultBits) { + super(ArithmeticOpTable::getNarrow, ArithmeticOpTable::getSignExtend, inputBits, resultBits, input); } @Override @@ -61,7 +67,7 @@ // zzzzzzzz yyyyxxxx -(narrow)-> yyyyxxxx -(narrow)-> xxxx // ==> zzzzzzzz yyyyxxxx -(narrow)-> xxxx NarrowNode other = (NarrowNode) forValue; - return NarrowNode.create(other.getValue(), getResultBits()); + return NarrowNode.create(other.getValue(), other.getInputBits(), getResultBits()); } else if (forValue instanceof IntegerConvertNode) { // SignExtendNode or ZeroExtendNode IntegerConvertNode other = (IntegerConvertNode) forValue; @@ -72,16 +78,16 @@ } else if (getResultBits() < other.getInputBits()) { // yyyyxxxx -(extend)-> zzzzzzzz yyyyxxxx -(narrow)-> xxxx // ==> yyyyxxxx -(narrow)-> xxxx - return NarrowNode.create(other.getValue(), getResultBits()); + return NarrowNode.create(other.getValue(), other.getInputBits(), getResultBits()); } else { if (other instanceof SignExtendNode) { // sxxx -(sign-extend)-> ssssssss sssssxxx -(narrow)-> sssssxxx // ==> sxxx -(sign-extend)-> sssssxxx - return SignExtendNode.create(other.getValue(), getResultBits()); + return SignExtendNode.create(other.getValue(), other.getInputBits(), getResultBits()); } else if (other instanceof ZeroExtendNode) { // xxxx -(zero-extend)-> 00000000 00000xxx -(narrow)-> 0000xxxx // ==> xxxx -(zero-extend)-> 0000xxxx - return ZeroExtendNode.create(other.getValue(), getResultBits()); + return ZeroExtendNode.create(other.getValue(), other.getInputBits(), getResultBits()); } } } diff -r 3c7e73362d6a -r 689092d5cf44 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/SignExtendNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/SignExtendNode.java Mon Oct 20 12:12:52 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/SignExtendNode.java Mon Oct 20 16:26:05 2014 +0200 @@ -38,11 +38,17 @@ public class SignExtendNode extends IntegerConvertNode { public static SignExtendNode create(ValueNode input, int resultBits) { - return new SignExtendNode(input, resultBits); + int inputBits = PrimitiveStamp.getBits(input.stamp()); + assert 0 < inputBits && inputBits <= resultBits; + return create(input, inputBits, resultBits); } - protected SignExtendNode(ValueNode input, int resultBits) { - super(ArithmeticOpTable::getSignExtend, ArithmeticOpTable::getNarrow, resultBits, input); + public static SignExtendNode create(ValueNode input, int inputBits, int resultBits) { + return new SignExtendNode(input, inputBits, resultBits); + } + + protected SignExtendNode(ValueNode input, int inputBits, int resultBits) { + super(ArithmeticOpTable::getSignExtend, ArithmeticOpTable::getNarrow, inputBits, resultBits, input); } @Override @@ -61,13 +67,13 @@ // sxxx -(sign-extend)-> ssss sxxx -(sign-extend)-> ssssssss sssssxxx // ==> sxxx -(sign-extend)-> ssssssss sssssxxx SignExtendNode other = (SignExtendNode) forValue; - return SignExtendNode.create(other.getValue(), getResultBits()); + return SignExtendNode.create(other.getValue(), other.getInputBits(), getResultBits()); } else if (forValue instanceof ZeroExtendNode) { ZeroExtendNode other = (ZeroExtendNode) forValue; if (other.getResultBits() > other.getInputBits()) { // sxxx -(zero-extend)-> 0000 sxxx -(sign-extend)-> 00000000 0000sxxx // ==> sxxx -(zero-extend)-> 00000000 0000sxxx - return ZeroExtendNode.create(other.getValue(), getResultBits()); + return ZeroExtendNode.create(other.getValue(), other.getInputBits(), getResultBits()); } } @@ -76,7 +82,7 @@ if ((inputStamp.upMask() & (1L << (getInputBits() - 1))) == 0L) { // 0xxx -(sign-extend)-> 0000 0xxx // ==> 0xxx -(zero-extend)-> 0000 0xxx - return ZeroExtendNode.create(forValue, getResultBits()); + return ZeroExtendNode.create(forValue, getInputBits(), getResultBits()); } } diff -r 3c7e73362d6a -r 689092d5cf44 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ZeroExtendNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ZeroExtendNode.java Mon Oct 20 12:12:52 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ZeroExtendNode.java Mon Oct 20 16:26:05 2014 +0200 @@ -40,11 +40,17 @@ public class ZeroExtendNode extends IntegerConvertNode { public static ZeroExtendNode create(ValueNode input, int resultBits) { - return new ZeroExtendNode(input, resultBits); + int inputBits = PrimitiveStamp.getBits(input.stamp()); + assert 0 < inputBits && inputBits <= resultBits; + return create(input, inputBits, resultBits); } - protected ZeroExtendNode(ValueNode input, int resultBits) { - super(ArithmeticOpTable::getZeroExtend, ArithmeticOpTable::getNarrow, resultBits, input); + public static ZeroExtendNode create(ValueNode input, int inputBits, int resultBits) { + return new ZeroExtendNode(input, inputBits, resultBits); + } + + protected ZeroExtendNode(ValueNode input, int inputBits, int resultBits) { + super(ArithmeticOpTable::getZeroExtend, ArithmeticOpTable::getNarrow, inputBits, resultBits, input); } @Override @@ -76,7 +82,7 @@ // xxxx -(zero-extend)-> 0000 xxxx -(zero-extend)-> 00000000 0000xxxx // ==> xxxx -(zero-extend)-> 00000000 0000xxxx ZeroExtendNode other = (ZeroExtendNode) forValue; - return ZeroExtendNode.create(other.getValue(), getResultBits()); + return ZeroExtendNode.create(other.getValue(), other.getInputBits(), getResultBits()); } if (forValue instanceof NarrowNode) { NarrowNode narrow = (NarrowNode) forValue; diff -r 3c7e73362d6a -r 689092d5cf44 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/IndexedLocationNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/IndexedLocationNode.java Mon Oct 20 12:12:52 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/IndexedLocationNode.java Mon Oct 20 16:26:05 2014 +0200 @@ -108,7 +108,7 @@ assert indexScaling > 0 && CodeUtil.isPowerOf2(indexScaling); int scale = CodeUtil.log2(indexScaling); return (IntegerStamp) IntegerStamp.OPS.getAdd().foldStamp(StampFactory.forInteger(64, displacement, displacement), - IntegerStamp.OPS.getSignExtend().foldStamp(64, StampTool.leftShift(index.stamp(), StampFactory.forInteger(64, scale, scale)))); + IntegerStamp.OPS.getSignExtend().foldStamp(32, 64, StampTool.leftShift(index.stamp(), StampFactory.forInteger(64, scale, scale)))); } @Override diff -r 3c7e73362d6a -r 689092d5cf44 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/DefaultJavaLoweringProvider.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/DefaultJavaLoweringProvider.java Mon Oct 20 12:12:52 2014 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/DefaultJavaLoweringProvider.java Mon Oct 20 16:26:05 2014 +0200 @@ -534,10 +534,10 @@ switch (kind) { case Boolean: case Byte: - return IntegerStamp.OPS.getNarrow().foldStamp(8, stamp); + return IntegerStamp.OPS.getNarrow().foldStamp(32, 8, stamp); case Char: case Short: - return IntegerStamp.OPS.getNarrow().foldStamp(16, stamp); + return IntegerStamp.OPS.getNarrow().foldStamp(32, 16, stamp); } return stamp; }