35 import org.graalvm.compiler.graph.Node;
36 import org.graalvm.compiler.graph.NodeClass;
37 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
38 import org.graalvm.compiler.nodeinfo.NodeInfo;
39 import org.graalvm.compiler.nodes.ConstantNode;
40 import org.graalvm.compiler.nodes.LogicConstantNode;
41 import org.graalvm.compiler.nodes.LogicNegationNode;
42 import org.graalvm.compiler.nodes.LogicNode;
43 import org.graalvm.compiler.nodes.ValueNode;
44
45 import jdk.vm.ci.code.CodeUtil;
46 import jdk.vm.ci.meta.Constant;
47 import jdk.vm.ci.meta.JavaConstant;
48 import jdk.vm.ci.meta.JavaKind;
49 import jdk.vm.ci.meta.PrimitiveConstant;
50 import org.graalvm.compiler.options.OptionValues;
51
52 @NodeInfo(shortName = "<")
53 public final class IntegerLessThanNode extends IntegerLowerThanNode {
54 public static final NodeClass<IntegerLessThanNode> TYPE = NodeClass.create(IntegerLessThanNode.class);
55 public static final LessThanOp OP = new LessThanOp();
56
57 public IntegerLessThanNode(ValueNode x, ValueNode y) {
58 super(TYPE, x, y, OP);
59 assert !x.getStackKind().isNumericFloat() && x.getStackKind() != JavaKind.Object;
60 assert !y.getStackKind().isNumericFloat() && y.getStackKind() != JavaKind.Object;
61 }
62
63 public static LogicNode create(ValueNode x, ValueNode y) {
64 return OP.create(x, y);
65 }
66
67 public static LogicNode create(ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess, OptionValues options, Integer smallestCompareWidth,
68 ValueNode x, ValueNode y) {
69 LogicNode value = OP.canonical(constantReflection, metaAccess, options, smallestCompareWidth, OP.getCondition(), false, x, y);
70 if (value != null) {
71 return value;
72 }
73 return create(x, y);
74 }
75
186 yy = sub.getX();
187 negate = true;
188 }
189 if (xx != null) {
190 assert yy != null;
191 IntegerStamp xStamp = (IntegerStamp) sub.getX().stamp();
192 IntegerStamp yStamp = (IntegerStamp) sub.getY().stamp();
193 long minValue = CodeUtil.minValue(xStamp.getBits());
194 long maxValue = CodeUtil.maxValue(xStamp.getBits());
195
196 if (!subtractMayUnderflow(xStamp.lowerBound(), yStamp.upperBound(), minValue) && !subtractMayOverflow(xStamp.upperBound(), yStamp.lowerBound(), maxValue)) {
197 LogicNode logic = new IntegerLessThanNode(xx, yy);
198 if (negate) {
199 logic = LogicNegationNode.create(logic);
200 }
201 return logic;
202 }
203 }
204 }
205
206 int bits = ((IntegerStamp) forX.stamp()).getBits();
207 assert ((IntegerStamp) forY.stamp()).getBits() == bits;
208 long min = OP.minValue(bits);
209 long xResidue = 0;
210 ValueNode left = null;
211 JavaConstant leftCst = null;
212 if (forX instanceof AddNode) {
213 AddNode xAdd = (AddNode) forX;
214 if (xAdd.getY().isJavaConstant()) {
215 long xCst = xAdd.getY().asJavaConstant().asLong();
216 xResidue = xCst - min;
217 left = xAdd.getX();
218 }
219 } else if (forX.isJavaConstant()) {
220 leftCst = forX.asJavaConstant();
221 }
222 if (left != null || leftCst != null) {
223 long yResidue = 0;
224 ValueNode right = null;
225 JavaConstant rightCst = null;
229 long yCst = yAdd.getY().asJavaConstant().asLong();
230 yResidue = yCst - min;
231 right = yAdd.getX();
232 }
233 } else if (forY.isJavaConstant()) {
234 rightCst = forY.asJavaConstant();
235 }
236 if (right != null || rightCst != null) {
237 if ((xResidue == 0 && left != null) || (yResidue == 0 && right != null)) {
238 if (left == null) {
239 left = ConstantNode.forIntegerBits(bits, leftCst.asLong() - min);
240 } else if (xResidue != 0) {
241 left = AddNode.create(left, ConstantNode.forIntegerBits(bits, xResidue));
242 }
243 if (right == null) {
244 right = ConstantNode.forIntegerBits(bits, rightCst.asLong() - min);
245 } else if (yResidue != 0) {
246 right = AddNode.create(right, ConstantNode.forIntegerBits(bits, yResidue));
247 }
248 return new IntegerBelowNode(left, right);
249 }
250 }
251 }
252 return null;
253 }
254
255 @Override
256 protected Condition getCondition() {
257 return LT;
258 }
259
260 @Override
261 protected IntegerLowerThanNode createNode(ValueNode x, ValueNode y) {
262 return new IntegerLessThanNode(x, y);
263 }
264
265 @Override
266 protected long upperBound(IntegerStamp stamp) {
267 return stamp.upperBound();
268 }
|
35 import org.graalvm.compiler.graph.Node;
36 import org.graalvm.compiler.graph.NodeClass;
37 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
38 import org.graalvm.compiler.nodeinfo.NodeInfo;
39 import org.graalvm.compiler.nodes.ConstantNode;
40 import org.graalvm.compiler.nodes.LogicConstantNode;
41 import org.graalvm.compiler.nodes.LogicNegationNode;
42 import org.graalvm.compiler.nodes.LogicNode;
43 import org.graalvm.compiler.nodes.ValueNode;
44
45 import jdk.vm.ci.code.CodeUtil;
46 import jdk.vm.ci.meta.Constant;
47 import jdk.vm.ci.meta.JavaConstant;
48 import jdk.vm.ci.meta.JavaKind;
49 import jdk.vm.ci.meta.PrimitiveConstant;
50 import org.graalvm.compiler.options.OptionValues;
51
52 @NodeInfo(shortName = "<")
53 public final class IntegerLessThanNode extends IntegerLowerThanNode {
54 public static final NodeClass<IntegerLessThanNode> TYPE = NodeClass.create(IntegerLessThanNode.class);
55 private static final LessThanOp OP = new LessThanOp();
56
57 public IntegerLessThanNode(ValueNode x, ValueNode y) {
58 super(TYPE, x, y, OP);
59 assert !x.getStackKind().isNumericFloat() && x.getStackKind() != JavaKind.Object;
60 assert !y.getStackKind().isNumericFloat() && y.getStackKind() != JavaKind.Object;
61 }
62
63 public static LogicNode create(ValueNode x, ValueNode y) {
64 return OP.create(x, y);
65 }
66
67 public static LogicNode create(ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess, OptionValues options, Integer smallestCompareWidth,
68 ValueNode x, ValueNode y) {
69 LogicNode value = OP.canonical(constantReflection, metaAccess, options, smallestCompareWidth, OP.getCondition(), false, x, y);
70 if (value != null) {
71 return value;
72 }
73 return create(x, y);
74 }
75
186 yy = sub.getX();
187 negate = true;
188 }
189 if (xx != null) {
190 assert yy != null;
191 IntegerStamp xStamp = (IntegerStamp) sub.getX().stamp();
192 IntegerStamp yStamp = (IntegerStamp) sub.getY().stamp();
193 long minValue = CodeUtil.minValue(xStamp.getBits());
194 long maxValue = CodeUtil.maxValue(xStamp.getBits());
195
196 if (!subtractMayUnderflow(xStamp.lowerBound(), yStamp.upperBound(), minValue) && !subtractMayOverflow(xStamp.upperBound(), yStamp.lowerBound(), maxValue)) {
197 LogicNode logic = new IntegerLessThanNode(xx, yy);
198 if (negate) {
199 logic = LogicNegationNode.create(logic);
200 }
201 return logic;
202 }
203 }
204 }
205
206 if (forX.stamp() instanceof IntegerStamp) {
207 assert forY.stamp() instanceof IntegerStamp;
208 int bits = ((IntegerStamp) forX.stamp()).getBits();
209 assert ((IntegerStamp) forY.stamp()).getBits() == bits;
210 long min = OP.minValue(bits);
211 long xResidue = 0;
212 ValueNode left = null;
213 JavaConstant leftCst = null;
214 if (forX instanceof AddNode) {
215 AddNode xAdd = (AddNode) forX;
216 if (xAdd.getY().isJavaConstant()) {
217 long xCst = xAdd.getY().asJavaConstant().asLong();
218 xResidue = xCst - min;
219 left = xAdd.getX();
220 }
221 } else if (forX.isJavaConstant()) {
222 leftCst = forX.asJavaConstant();
223 }
224 if (left != null || leftCst != null) {
225 long yResidue = 0;
226 ValueNode right = null;
227 JavaConstant rightCst = null;
231 long yCst = yAdd.getY().asJavaConstant().asLong();
232 yResidue = yCst - min;
233 right = yAdd.getX();
234 }
235 } else if (forY.isJavaConstant()) {
236 rightCst = forY.asJavaConstant();
237 }
238 if (right != null || rightCst != null) {
239 if ((xResidue == 0 && left != null) || (yResidue == 0 && right != null)) {
240 if (left == null) {
241 left = ConstantNode.forIntegerBits(bits, leftCst.asLong() - min);
242 } else if (xResidue != 0) {
243 left = AddNode.create(left, ConstantNode.forIntegerBits(bits, xResidue));
244 }
245 if (right == null) {
246 right = ConstantNode.forIntegerBits(bits, rightCst.asLong() - min);
247 } else if (yResidue != 0) {
248 right = AddNode.create(right, ConstantNode.forIntegerBits(bits, yResidue));
249 }
250 return new IntegerBelowNode(left, right);
251 }
252 }
253 }
254 }
255 return null;
256 }
257
258 @Override
259 protected Condition getCondition() {
260 return LT;
261 }
262
263 @Override
264 protected IntegerLowerThanNode createNode(ValueNode x, ValueNode y) {
265 return new IntegerLessThanNode(x, y);
266 }
267
268 @Override
269 protected long upperBound(IntegerStamp stamp) {
270 return stamp.upperBound();
271 }
|