< prev index next >
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/IntegerLessThanNode.java
Print this page
rev 52509 : [mq]: graal
*** 1,7 ****
/*
! * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 45,55 ****
import org.graalvm.compiler.options.OptionValues;
import jdk.vm.ci.code.CodeUtil;
import jdk.vm.ci.meta.Constant;
import jdk.vm.ci.meta.ConstantReflectionProvider;
- import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.PrimitiveConstant;
@NodeInfo(shortName = "<")
--- 45,54 ----
*** 173,183 ****
if (forX.stamp(view) instanceof IntegerStamp && forY.stamp(view) instanceof IntegerStamp) {
if (IntegerStamp.sameSign((IntegerStamp) forX.stamp(view), (IntegerStamp) forY.stamp(view))) {
return new IntegerBelowNode(forX, forY);
}
}
! if (forY.isConstant() && forX instanceof SubNode) {
SubNode sub = (SubNode) forX;
ValueNode xx = null;
ValueNode yy = null;
boolean negate = false;
if (forY.asConstant().isDefaultForKind()) {
--- 172,186 ----
if (forX.stamp(view) instanceof IntegerStamp && forY.stamp(view) instanceof IntegerStamp) {
if (IntegerStamp.sameSign((IntegerStamp) forX.stamp(view), (IntegerStamp) forY.stamp(view))) {
return new IntegerBelowNode(forX, forY);
}
}
!
! // Attempt to optimize the case where we can fold a constant from the left side (either
! // from an add or sub) into the constant on the right side.
! if (forY.isConstant()) {
! if (forX instanceof SubNode) {
SubNode sub = (SubNode) forX;
ValueNode xx = null;
ValueNode yy = null;
boolean negate = false;
if (forY.asConstant().isDefaultForKind()) {
*** 203,261 ****
logic = LogicNegationNode.create(logic);
}
return logic;
}
}
}
if (forX.stamp(view) instanceof IntegerStamp) {
assert forY.stamp(view) instanceof IntegerStamp;
int bits = ((IntegerStamp) forX.stamp(view)).getBits();
assert ((IntegerStamp) forY.stamp(view)).getBits() == bits;
! long min = OP.minValue(bits);
! long xResidue = 0;
! ValueNode left = null;
! JavaConstant leftCst = null;
! if (forX instanceof AddNode) {
! AddNode xAdd = (AddNode) forX;
! if (xAdd.getY().isJavaConstant()) {
! long xCst = xAdd.getY().asJavaConstant().asLong();
! xResidue = xCst - min;
! left = xAdd.getX();
! }
! } else if (forX.isJavaConstant()) {
! leftCst = forX.asJavaConstant();
! }
! if (left != null || leftCst != null) {
! long yResidue = 0;
! ValueNode right = null;
! JavaConstant rightCst = null;
! if (forY instanceof AddNode) {
! AddNode yAdd = (AddNode) forY;
! if (yAdd.getY().isJavaConstant()) {
! long yCst = yAdd.getY().asJavaConstant().asLong();
! yResidue = yCst - min;
! right = yAdd.getX();
! }
! } else if (forY.isJavaConstant()) {
! rightCst = forY.asJavaConstant();
! }
! if (right != null || rightCst != null) {
! if ((xResidue == 0 && left != null) || (yResidue == 0 && right != null)) {
! if (left == null) {
! left = ConstantNode.forIntegerBits(bits, leftCst.asLong() - min);
! } else if (xResidue != 0) {
! left = AddNode.create(left, ConstantNode.forIntegerBits(bits, xResidue), view);
! }
! if (right == null) {
! right = ConstantNode.forIntegerBits(bits, rightCst.asLong() - min);
! } else if (yResidue != 0) {
! right = AddNode.create(right, ConstantNode.forIntegerBits(bits, yResidue), view);
! }
! return new IntegerBelowNode(left, right);
! }
! }
}
}
return null;
}
--- 206,243 ----
logic = LogicNegationNode.create(logic);
}
return logic;
}
}
+ } else if (forX instanceof AddNode) {
+
+ // (x + xConstant) < forY => x < (forY - xConstant)
+ AddNode addNode = (AddNode) forX;
+ if (addNode.getY().isJavaConstant()) {
+ IntegerStamp xStamp = (IntegerStamp) addNode.getX().stamp(view);
+ if (!IntegerStamp.addCanOverflow(xStamp, (IntegerStamp) addNode.getY().stamp(view))) {
+ long minValue = CodeUtil.minValue(xStamp.getBits());
+ long maxValue = CodeUtil.maxValue(xStamp.getBits());
+ long yConstant = forY.asJavaConstant().asLong();
+ long xConstant = addNode.getY().asJavaConstant().asLong();
+ if (!subtractMayUnderflow(yConstant, xConstant, minValue) && !subtractMayOverflow(yConstant, xConstant, maxValue)) {
+ long newConstant = yConstant - xConstant;
+ return IntegerLessThanNode.create(addNode.getX(), ConstantNode.forIntegerStamp(xStamp, newConstant), view);
+ }
+ }
+ }
+
+ }
}
if (forX.stamp(view) instanceof IntegerStamp) {
assert forY.stamp(view) instanceof IntegerStamp;
int bits = ((IntegerStamp) forX.stamp(view)).getBits();
assert ((IntegerStamp) forY.stamp(view)).getBits() == bits;
! LogicNode logic = canonicalizeRangeFlip(forX, forY, bits, true, view);
! if (logic != null) {
! return logic;
}
}
return null;
}
< prev index next >