89 return true; 90 } 91 } 92 93 @Override 94 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { 95 ValueNode ret = super.canonical(tool, forValue); 96 if (ret != this) { 97 return ret; 98 } 99 100 if (forValue instanceof ZeroExtendNode) { 101 // xxxx -(zero-extend)-> 0000 xxxx -(zero-extend)-> 00000000 0000xxxx 102 // ==> xxxx -(zero-extend)-> 00000000 0000xxxx 103 ZeroExtendNode other = (ZeroExtendNode) forValue; 104 return new ZeroExtendNode(other.getValue(), other.getInputBits(), getResultBits()); 105 } 106 if (forValue instanceof NarrowNode) { 107 NarrowNode narrow = (NarrowNode) forValue; 108 Stamp inputStamp = narrow.getValue().stamp(); 109 if (inputStamp instanceof IntegerStamp && inputStamp.isCompatible(stamp())) { 110 IntegerStamp istamp = (IntegerStamp) inputStamp; 111 long mask = CodeUtil.mask(PrimitiveStamp.getBits(narrow.stamp())); 112 if (((istamp.upMask() | istamp.downMask()) & ~mask) == 0) { 113 // The original value is in the range of the masked zero extended result so 114 // simply return the original input. 115 return narrow.getValue(); 116 } 117 } 118 } 119 120 return this; 121 } 122 123 @Override 124 public void generate(NodeLIRBuilderTool nodeValueMap, ArithmeticLIRGeneratorTool gen) { 125 nodeValueMap.setResult(this, gen.emitZeroExtend(nodeValueMap.operand(getValue()), getInputBits(), getResultBits())); 126 } 127 } | 89 return true; 90 } 91 } 92 93 @Override 94 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { 95 ValueNode ret = super.canonical(tool, forValue); 96 if (ret != this) { 97 return ret; 98 } 99 100 if (forValue instanceof ZeroExtendNode) { 101 // xxxx -(zero-extend)-> 0000 xxxx -(zero-extend)-> 00000000 0000xxxx 102 // ==> xxxx -(zero-extend)-> 00000000 0000xxxx 103 ZeroExtendNode other = (ZeroExtendNode) forValue; 104 return new ZeroExtendNode(other.getValue(), other.getInputBits(), getResultBits()); 105 } 106 if (forValue instanceof NarrowNode) { 107 NarrowNode narrow = (NarrowNode) forValue; 108 Stamp inputStamp = narrow.getValue().stamp(); 109 if (inputStamp instanceof IntegerStamp) { 110 IntegerStamp istamp = (IntegerStamp) inputStamp; 111 long mask = CodeUtil.mask(PrimitiveStamp.getBits(narrow.stamp())); 112 113 if ((istamp.upMask() & ~mask) == 0) { 114 // The original value cannot change because of the narrow and zero extend. 115 116 if (istamp.getBits() < resultBits) { 117 // Need to keep the zero extend, skip the narrow. 118 return create(narrow.getValue(), resultBits); 119 } else if (istamp.getBits() > resultBits) { 120 // Need to keep the narrow, skip the zero extend. 121 return NarrowNode.create(narrow.getValue(), resultBits); 122 } else { 123 assert istamp.getBits() == resultBits; 124 // Just return the original value. 125 return narrow.getValue(); 126 } 127 } 128 } 129 } 130 131 return this; 132 } 133 134 @Override 135 public void generate(NodeLIRBuilderTool nodeValueMap, ArithmeticLIRGeneratorTool gen) { 136 nodeValueMap.setResult(this, gen.emitZeroExtend(nodeValueMap.operand(getValue()), getInputBits(), getResultBits())); 137 } 138 139 @Override 140 public boolean mayNullCheckSkipConversion() { 141 return true; 142 } 143 } |