changeset 22944:d6f0245476e2

Compute correct masks when restricting the bounds of IntegerStamps
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 03 Nov 2015 22:33:13 -0800
parents 86bee10c31b0
children 249fe54d146a
files graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/IntegerStamp.java graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/StampFactory.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerBelowNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerLessThanNode.java
diffstat 4 files changed, 30 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/IntegerStamp.java	Tue Nov 03 18:45:14 2015 -0800
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/IntegerStamp.java	Tue Nov 03 22:33:13 2015 -0800
@@ -276,7 +276,10 @@
         IntegerStamp other = (IntegerStamp) otherStamp;
         long newDownMask = downMask | other.downMask;
         long newLowerBound = Math.max(lowerBound, other.lowerBound) | newDownMask;
-        return createStamp(other, Math.min(upperBound, other.upperBound), newLowerBound, newDownMask, upMask & other.upMask);
+        long newUpperBound = Math.min(upperBound, other.upperBound);
+        long newUpMask = upMask & other.upMask;
+        IntegerStamp limit = StampFactory.forInteger(getBits(), newLowerBound, newUpperBound);
+        return createStamp(other, newUpperBound, newLowerBound, limit.downMask() | newDownMask, limit.upMask() & newUpMask);
     }
 
     @Override
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/StampFactory.java	Tue Nov 03 18:45:14 2015 -0800
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/StampFactory.java	Tue Nov 03 22:33:13 2015 -0800
@@ -140,6 +140,22 @@
         return forInteger(kind.getBitCount(), lowerBound, upperBound);
     }
 
+    /**
+     * Create a new stamp use {@code newLowerBound} and {@code newUpperBound} computing the
+     * appropriate {@link IntegerStamp#upMask} and {@link IntegerStamp#downMask} and incorporating
+     * any mask information from {@code maskStamp}.
+     *
+     * @param bits
+     * @param newLowerBound
+     * @param newUpperBound
+     * @param maskStamp
+     * @return a new stamp with the appropriate bounds and masks
+     */
+    public static IntegerStamp forIntegerWithMask(int bits, long newLowerBound, long newUpperBound, IntegerStamp maskStamp) {
+        IntegerStamp limit = StampFactory.forInteger(bits, newLowerBound, newUpperBound);
+        return new IntegerStamp(bits, newLowerBound, newUpperBound, limit.downMask() | maskStamp.downMask(), limit.upMask() & maskStamp.upMask());
+    }
+
     public static IntegerStamp forInteger(int bits) {
         return new IntegerStamp(bits, CodeUtil.minValue(bits), CodeUtil.maxValue(bits), 0, CodeUtil.mask(bits));
     }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerBelowNode.java	Tue Nov 03 18:45:14 2015 -0800
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerBelowNode.java	Tue Nov 03 22:33:13 2015 -0800
@@ -29,6 +29,7 @@
 import com.oracle.graal.compiler.common.calc.Condition;
 import com.oracle.graal.compiler.common.type.IntegerStamp;
 import com.oracle.graal.compiler.common.type.Stamp;
+import com.oracle.graal.compiler.common.type.StampFactory;
 import com.oracle.graal.graph.NodeClass;
 import com.oracle.graal.graph.spi.CanonicalizerTool;
 import com.oracle.graal.nodeinfo.NodeInfo;
@@ -116,7 +117,7 @@
                         long xLowerBound = xStamp.lowerBound();
                         long yLowerBound = yStamp.lowerBound();
                         if (yLowerBound > xLowerBound) {
-                            return new IntegerStamp(bits, yLowerBound, xStamp.upperBound(), xStamp.downMask(), xStamp.upMask());
+                            return StampFactory.forIntegerWithMask(bits, yLowerBound, xStamp.upperBound(), xStamp);
                         }
                     }
                 } else {
@@ -126,7 +127,7 @@
                         long xUpperBound = xStamp.upperBound();
                         long yUpperBound = yStamp.upperBound();
                         if (yUpperBound <= xUpperBound || !xStamp.isPositive()) {
-                            return new IntegerStamp(bits, Math.max(0, xStamp.lowerBound()), Math.min(xUpperBound, yUpperBound - 1), xStamp.downMask(), xStamp.upMask());
+                            return StampFactory.forIntegerWithMask(bits, Math.max(0, xStamp.lowerBound()), Math.min(xUpperBound, yUpperBound - 1), xStamp);
                         }
                     }
                 }
@@ -151,7 +152,7 @@
                         long xUpperBound = xStamp.upperBound();
                         long yUpperBound = yStamp.upperBound();
                         if (xUpperBound < yUpperBound || !yStamp.isPositive()) {
-                            return new IntegerStamp(bits, Math.max(0, yStamp.lowerBound()), Math.min(xUpperBound, yUpperBound), yStamp.downMask(), yStamp.upMask());
+                            return StampFactory.forIntegerWithMask(bits, Math.max(0, yStamp.lowerBound()), Math.min(xUpperBound, yUpperBound), yStamp);
                         }
                     }
                 } else {
@@ -163,7 +164,7 @@
                             return null;
                         } else if (xLowerBound >= yLowerBound) {
                             assert xLowerBound != CodeUtil.maxValue(bits);
-                            return new IntegerStamp(bits, xLowerBound + 1, yStamp.upperBound(), yStamp.downMask(), yStamp.upMask());
+                            return StampFactory.forIntegerWithMask(bits, xLowerBound + 1, yStamp.upperBound(), yStamp);
                         }
                     }
                 }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerLessThanNode.java	Tue Nov 03 18:45:14 2015 -0800
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerLessThanNode.java	Tue Nov 03 22:33:13 2015 -0800
@@ -34,6 +34,7 @@
 import com.oracle.graal.compiler.common.type.FloatStamp;
 import com.oracle.graal.compiler.common.type.IntegerStamp;
 import com.oracle.graal.compiler.common.type.Stamp;
+import com.oracle.graal.compiler.common.type.StampFactory;
 import com.oracle.graal.graph.NodeClass;
 import com.oracle.graal.graph.spi.CanonicalizerTool;
 import com.oracle.graal.nodeinfo.NodeInfo;
@@ -140,7 +141,7 @@
                     long xLowerBound = xStamp.lowerBound();
                     long yLowerBound = yStamp.lowerBound();
                     if (yLowerBound > xLowerBound) {
-                        return new IntegerStamp(bits, yLowerBound, xStamp.upperBound(), xStamp.downMask(), xStamp.upMask());
+                        return StampFactory.forIntegerWithMask(bits, yLowerBound, xStamp.upperBound(), xStamp);
                     }
                 } else {
                     // x < y
@@ -150,7 +151,7 @@
                         return null;
                     } else if (yUpperBound <= xUpperBound) {
                         assert yUpperBound != CodeUtil.minValue(bits);
-                        return new IntegerStamp(bits, xStamp.lowerBound(), yUpperBound - 1, xStamp.downMask(), xStamp.upMask());
+                        return StampFactory.forIntegerWithMask(bits, xStamp.lowerBound(), yUpperBound - 1, xStamp);
                     }
                 }
             }
@@ -173,7 +174,7 @@
                     long xUpperBound = xStamp.upperBound();
                     long yUpperBound = yStamp.upperBound();
                     if (xUpperBound < yUpperBound) {
-                        return new IntegerStamp(bits, yStamp.lowerBound(), xUpperBound, yStamp.downMask(), yStamp.upMask());
+                        return StampFactory.forIntegerWithMask(bits, yStamp.lowerBound(), xUpperBound, yStamp);
                     }
                 } else {
                     // y > x
@@ -183,7 +184,7 @@
                         return null;
                     } else if (xLowerBound >= yLowerBound) {
                         assert xLowerBound != CodeUtil.maxValue(bits);
-                        return new IntegerStamp(bits, xLowerBound + 1, yStamp.upperBound(), yStamp.downMask(), yStamp.upMask());
+                        return StampFactory.forIntegerWithMask(bits, xLowerBound + 1, yStamp.upperBound(), yStamp);
                     }
                 }
             }