comparison graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NarrowNode.java @ 18124:689092d5cf44

Store explicit input bit width in IntegerConvertNode.
author Roland Schatz <roland.schatz@oracle.com>
date Mon, 20 Oct 2014 16:26:05 +0200
parents 45b45f902bed
children 47263ffe47bd
comparison
equal deleted inserted replaced
18123:3c7e73362d6a 18124:689092d5cf44
36 */ 36 */
37 @NodeInfo 37 @NodeInfo
38 public class NarrowNode extends IntegerConvertNode<Narrow, SignExtend> { 38 public class NarrowNode extends IntegerConvertNode<Narrow, SignExtend> {
39 39
40 public static NarrowNode create(ValueNode input, int resultBits) { 40 public static NarrowNode create(ValueNode input, int resultBits) {
41 return new NarrowNode(input, resultBits); 41 int inputBits = PrimitiveStamp.getBits(input.stamp());
42 assert 0 < resultBits && resultBits <= inputBits;
43 return create(input, inputBits, resultBits);
42 } 44 }
43 45
44 protected NarrowNode(ValueNode input, int resultBits) { 46 public static NarrowNode create(ValueNode input, int inputBits, int resultBits) {
45 super(ArithmeticOpTable::getNarrow, ArithmeticOpTable::getSignExtend, resultBits, input); 47 return new NarrowNode(input, inputBits, resultBits);
48 }
49
50 protected NarrowNode(ValueNode input, int inputBits, int resultBits) {
51 super(ArithmeticOpTable::getNarrow, ArithmeticOpTable::getSignExtend, inputBits, resultBits, input);
46 } 52 }
47 53
48 @Override 54 @Override
49 public boolean isLossless() { 55 public boolean isLossless() {
50 return false; 56 return false;
59 65
60 if (forValue instanceof NarrowNode) { 66 if (forValue instanceof NarrowNode) {
61 // zzzzzzzz yyyyxxxx -(narrow)-> yyyyxxxx -(narrow)-> xxxx 67 // zzzzzzzz yyyyxxxx -(narrow)-> yyyyxxxx -(narrow)-> xxxx
62 // ==> zzzzzzzz yyyyxxxx -(narrow)-> xxxx 68 // ==> zzzzzzzz yyyyxxxx -(narrow)-> xxxx
63 NarrowNode other = (NarrowNode) forValue; 69 NarrowNode other = (NarrowNode) forValue;
64 return NarrowNode.create(other.getValue(), getResultBits()); 70 return NarrowNode.create(other.getValue(), other.getInputBits(), getResultBits());
65 } else if (forValue instanceof IntegerConvertNode) { 71 } else if (forValue instanceof IntegerConvertNode) {
66 // SignExtendNode or ZeroExtendNode 72 // SignExtendNode or ZeroExtendNode
67 IntegerConvertNode<?, ?> other = (IntegerConvertNode<?, ?>) forValue; 73 IntegerConvertNode<?, ?> other = (IntegerConvertNode<?, ?>) forValue;
68 if (getResultBits() == other.getInputBits()) { 74 if (getResultBits() == other.getInputBits()) {
69 // xxxx -(extend)-> yyyy xxxx -(narrow)-> xxxx 75 // xxxx -(extend)-> yyyy xxxx -(narrow)-> xxxx
70 // ==> no-op 76 // ==> no-op
71 return other.getValue(); 77 return other.getValue();
72 } else if (getResultBits() < other.getInputBits()) { 78 } else if (getResultBits() < other.getInputBits()) {
73 // yyyyxxxx -(extend)-> zzzzzzzz yyyyxxxx -(narrow)-> xxxx 79 // yyyyxxxx -(extend)-> zzzzzzzz yyyyxxxx -(narrow)-> xxxx
74 // ==> yyyyxxxx -(narrow)-> xxxx 80 // ==> yyyyxxxx -(narrow)-> xxxx
75 return NarrowNode.create(other.getValue(), getResultBits()); 81 return NarrowNode.create(other.getValue(), other.getInputBits(), getResultBits());
76 } else { 82 } else {
77 if (other instanceof SignExtendNode) { 83 if (other instanceof SignExtendNode) {
78 // sxxx -(sign-extend)-> ssssssss sssssxxx -(narrow)-> sssssxxx 84 // sxxx -(sign-extend)-> ssssssss sssssxxx -(narrow)-> sssssxxx
79 // ==> sxxx -(sign-extend)-> sssssxxx 85 // ==> sxxx -(sign-extend)-> sssssxxx
80 return SignExtendNode.create(other.getValue(), getResultBits()); 86 return SignExtendNode.create(other.getValue(), other.getInputBits(), getResultBits());
81 } else if (other instanceof ZeroExtendNode) { 87 } else if (other instanceof ZeroExtendNode) {
82 // xxxx -(zero-extend)-> 00000000 00000xxx -(narrow)-> 0000xxxx 88 // xxxx -(zero-extend)-> 00000000 00000xxx -(narrow)-> 0000xxxx
83 // ==> xxxx -(zero-extend)-> 0000xxxx 89 // ==> xxxx -(zero-extend)-> 0000xxxx
84 return ZeroExtendNode.create(other.getValue(), getResultBits()); 90 return ZeroExtendNode.create(other.getValue(), other.getInputBits(), getResultBits());
85 } 91 }
86 } 92 }
87 } 93 }
88 return this; 94 return this;
89 } 95 }