33 import org.graalvm.compiler.core.common.type.StampFactory;
34 import org.graalvm.compiler.debug.GraalError;
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.NodeView;
44 import org.graalvm.compiler.nodes.ValueNode;
45 import org.graalvm.compiler.options.OptionValues;
46
47 import jdk.vm.ci.code.CodeUtil;
48 import jdk.vm.ci.meta.Constant;
49 import jdk.vm.ci.meta.ConstantReflectionProvider;
50 import jdk.vm.ci.meta.JavaKind;
51 import jdk.vm.ci.meta.MetaAccessProvider;
52 import jdk.vm.ci.meta.PrimitiveConstant;
53
54 @NodeInfo(shortName = "<")
55 public final class IntegerLessThanNode extends IntegerLowerThanNode {
56 public static final NodeClass<IntegerLessThanNode> TYPE = NodeClass.create(IntegerLessThanNode.class);
57 private static final LessThanOp OP = new LessThanOp();
58
59 public IntegerLessThanNode(ValueNode x, ValueNode y) {
60 super(TYPE, x, y, OP);
61 assert !x.getStackKind().isNumericFloat() && x.getStackKind() != JavaKind.Object;
62 assert !y.getStackKind().isNumericFloat() && y.getStackKind() != JavaKind.Object;
63 }
64
65 public static LogicNode create(ValueNode x, ValueNode y, NodeView view) {
66 return OP.create(x, y, view);
67 }
68
69 public static LogicNode create(ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess, OptionValues options, Integer smallestCompareWidth,
70 ValueNode x, ValueNode y, NodeView view) {
71 LogicNode value = OP.canonical(constantReflection, metaAccess, options, smallestCompareWidth, OP.getCondition(), false, x, y, view);
72 if (value != null) {
208 return logic;
209 }
210 }
211 } else if (forX instanceof AddNode) {
212
213 // (x + xConstant) < forY => x < (forY - xConstant)
214 AddNode addNode = (AddNode) forX;
215 if (addNode.getY().isJavaConstant()) {
216 IntegerStamp xStamp = (IntegerStamp) addNode.getX().stamp(view);
217 if (!IntegerStamp.addCanOverflow(xStamp, (IntegerStamp) addNode.getY().stamp(view))) {
218 long minValue = CodeUtil.minValue(xStamp.getBits());
219 long maxValue = CodeUtil.maxValue(xStamp.getBits());
220 long yConstant = forY.asJavaConstant().asLong();
221 long xConstant = addNode.getY().asJavaConstant().asLong();
222 if (!subtractMayUnderflow(yConstant, xConstant, minValue) && !subtractMayOverflow(yConstant, xConstant, maxValue)) {
223 long newConstant = yConstant - xConstant;
224 return IntegerLessThanNode.create(addNode.getX(), ConstantNode.forIntegerStamp(xStamp, newConstant), view);
225 }
226 }
227 }
228
229 }
230 }
231
232 if (forX.stamp(view) instanceof IntegerStamp) {
233 assert forY.stamp(view) instanceof IntegerStamp;
234 int bits = ((IntegerStamp) forX.stamp(view)).getBits();
235 assert ((IntegerStamp) forY.stamp(view)).getBits() == bits;
236 LogicNode logic = canonicalizeRangeFlip(forX, forY, bits, true, view);
237 if (logic != null) {
238 return logic;
239 }
240 }
241 return null;
242 }
243
244 @Override
245 protected CanonicalCondition getCondition() {
246 return LT;
247 }
248
278
279 @Override
280 protected long cast(long a, int bits) {
281 return CodeUtil.signExtend(a, bits);
282 }
283
284 @Override
285 protected long minValue(int bits) {
286 return NumUtil.minValue(bits);
287 }
288
289 @Override
290 protected long maxValue(int bits) {
291 return NumUtil.maxValue(bits);
292 }
293
294 @Override
295 protected IntegerStamp forInteger(int bits, long min, long max) {
296 return StampFactory.forInteger(bits, cast(min, bits), cast(max, bits));
297 }
298 }
299 }
|
33 import org.graalvm.compiler.core.common.type.StampFactory;
34 import org.graalvm.compiler.debug.GraalError;
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.NodeView;
44 import org.graalvm.compiler.nodes.ValueNode;
45 import org.graalvm.compiler.options.OptionValues;
46
47 import jdk.vm.ci.code.CodeUtil;
48 import jdk.vm.ci.meta.Constant;
49 import jdk.vm.ci.meta.ConstantReflectionProvider;
50 import jdk.vm.ci.meta.JavaKind;
51 import jdk.vm.ci.meta.MetaAccessProvider;
52 import jdk.vm.ci.meta.PrimitiveConstant;
53 import jdk.vm.ci.meta.TriState;
54
55 @NodeInfo(shortName = "<")
56 public final class IntegerLessThanNode extends IntegerLowerThanNode {
57 public static final NodeClass<IntegerLessThanNode> TYPE = NodeClass.create(IntegerLessThanNode.class);
58 private static final LessThanOp OP = new LessThanOp();
59
60 public IntegerLessThanNode(ValueNode x, ValueNode y) {
61 super(TYPE, x, y, OP);
62 assert !x.getStackKind().isNumericFloat() && x.getStackKind() != JavaKind.Object;
63 assert !y.getStackKind().isNumericFloat() && y.getStackKind() != JavaKind.Object;
64 }
65
66 public static LogicNode create(ValueNode x, ValueNode y, NodeView view) {
67 return OP.create(x, y, view);
68 }
69
70 public static LogicNode create(ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess, OptionValues options, Integer smallestCompareWidth,
71 ValueNode x, ValueNode y, NodeView view) {
72 LogicNode value = OP.canonical(constantReflection, metaAccess, options, smallestCompareWidth, OP.getCondition(), false, x, y, view);
73 if (value != null) {
209 return logic;
210 }
211 }
212 } else if (forX instanceof AddNode) {
213
214 // (x + xConstant) < forY => x < (forY - xConstant)
215 AddNode addNode = (AddNode) forX;
216 if (addNode.getY().isJavaConstant()) {
217 IntegerStamp xStamp = (IntegerStamp) addNode.getX().stamp(view);
218 if (!IntegerStamp.addCanOverflow(xStamp, (IntegerStamp) addNode.getY().stamp(view))) {
219 long minValue = CodeUtil.minValue(xStamp.getBits());
220 long maxValue = CodeUtil.maxValue(xStamp.getBits());
221 long yConstant = forY.asJavaConstant().asLong();
222 long xConstant = addNode.getY().asJavaConstant().asLong();
223 if (!subtractMayUnderflow(yConstant, xConstant, minValue) && !subtractMayOverflow(yConstant, xConstant, maxValue)) {
224 long newConstant = yConstant - xConstant;
225 return IntegerLessThanNode.create(addNode.getX(), ConstantNode.forIntegerStamp(xStamp, newConstant), view);
226 }
227 }
228 }
229 }
230 }
231
232 if (forX.stamp(view) instanceof IntegerStamp) {
233 assert forY.stamp(view) instanceof IntegerStamp;
234 int bits = ((IntegerStamp) forX.stamp(view)).getBits();
235 assert ((IntegerStamp) forY.stamp(view)).getBits() == bits;
236 LogicNode logic = canonicalizeRangeFlip(forX, forY, bits, true, view);
237 if (logic != null) {
238 return logic;
239 }
240 }
241 return null;
242 }
243
244 @Override
245 protected CanonicalCondition getCondition() {
246 return LT;
247 }
248
278
279 @Override
280 protected long cast(long a, int bits) {
281 return CodeUtil.signExtend(a, bits);
282 }
283
284 @Override
285 protected long minValue(int bits) {
286 return NumUtil.minValue(bits);
287 }
288
289 @Override
290 protected long maxValue(int bits) {
291 return NumUtil.maxValue(bits);
292 }
293
294 @Override
295 protected IntegerStamp forInteger(int bits, long min, long max) {
296 return StampFactory.forInteger(bits, cast(min, bits), cast(max, bits));
297 }
298 }
299
300 @Override
301 public TriState implies(boolean thisNegated, LogicNode other) {
302 if (!thisNegated) {
303 if (other instanceof IntegerLessThanNode) {
304 ValueNode otherX = ((IntegerLessThanNode) other).getX();
305 ValueNode otherY = ((IntegerLessThanNode) other).getY();
306 // x < y => !y < x
307 if (getX() == otherY && getY() == otherX) {
308 return TriState.FALSE;
309 }
310 }
311
312 // x < y => !x == y
313 // x < y => !y == x
314 if (other instanceof IntegerEqualsNode) {
315 ValueNode otherX = ((IntegerEqualsNode) other).getX();
316 ValueNode otherY = ((IntegerEqualsNode) other).getY();
317 if ((getX() == otherX && getY() == otherY) || (getX() == otherY && getY() == otherX)) {
318 return TriState.FALSE;
319 }
320 }
321 }
322 return super.implies(thisNegated, other);
323 }
324 }
|