diff graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampTool.java @ 14863:ea712c41c5a2

merge unsigned compare guards with constant indexes or limits
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Thu, 27 Mar 2014 22:17:54 -0700
parents 740367295912
children 5e4ae8709830 9c1e53adc159
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampTool.java	Thu Mar 27 16:38:39 2014 -0700
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampTool.java	Thu Mar 27 22:17:54 2014 -0700
@@ -462,4 +462,41 @@
         }
         return v;
     }
+
+    /**
+     * Compute the stamp resulting from the unsigned comparison being true.
+     * 
+     * @return null if it's can't be true or it nothing useful can be encoded.
+     */
+    public static Stamp unsignedCompare(Stamp stamp, Stamp stamp2) {
+        IntegerStamp x = (IntegerStamp) stamp;
+        IntegerStamp y = (IntegerStamp) stamp2;
+        if (x == x.unrestricted() && y == y.unrestricted()) {
+            // Don't know anything.
+            return null;
+        }
+        // c <| n, where c is a constant and n is known to be positive.
+        if (x.lowerBound() == x.upperBound()) {
+            if (y.isPositive()) {
+                if (x.lowerBound() == (1 << x.getBits()) - 1) {
+                    // Constant is MAX_VALUE which must fail.
+                    return null;
+                }
+                if (x.lowerBound() <= y.lowerBound()) {
+                    // Test will fail. Return illegalStamp instead?
+                    return null;
+                }
+                // If the test succeeds then this proves that n is at greater than c so the bounds
+                // are [c+1..-n.upperBound)].
+                return StampFactory.forInteger(x.getBits(), false, x.lowerBound() + 1, y.upperBound());
+            }
+            return null;
+        }
+        // n <| c, where c is a strictly positive constant
+        if (y.lowerBound() == y.upperBound() && y.isStrictlyPositive()) {
+            // The test proves that n is positive and less than c, [0..c-1]
+            return StampFactory.forInteger(y.getBits(), false, 0, y.lowerBound() - 1);
+        }
+        return null;
+    }
 }