changeset 15636:92a939e551c4

fix unsigned compare, expand test
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Wed, 14 May 2014 01:25:21 -0700
parents 3b6f898a2384
children 40f13c935d8b
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IfCanonicalizerTest.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java
diffstat 2 files changed, 22 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IfCanonicalizerTest.java	Wed May 14 01:24:10 2014 -0700
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IfCanonicalizerTest.java	Wed May 14 01:25:21 2014 -0700
@@ -142,6 +142,7 @@
     @Test
     public void test6() {
         testCombinedIf("test6Snippet", 3);
+        test("test6Snippet", new int[]{0});
     }
 
     public static int test6Snippet(int[] a) {
@@ -149,12 +150,13 @@
         if (i >= 0 && i < a.length) {
             return a[i];
         }
-        return 0;
+        return 1;
     }
 
     @Test
     public void test7() {
         testCombinedIf("test7Snippet", 1);
+        test("test7Snippet", -1);
     }
 
     public static int test7Snippet(int v) {
@@ -164,6 +166,19 @@
         return v - 1;
     }
 
+    @Test
+    public void test8() {
+        testCombinedIf("test8Snippet", 1);
+        test("test8Snippet", -1);
+    }
+
+    public static int test8Snippet(int v) {
+        if (v >= 0 && v <= 1024) {
+            return v + 1;
+        }
+        return v - 1;
+    }
+
     private void testCombinedIf(String snippet, int count) {
         StructuredGraph graph = parse(snippet);
         PhaseContext context = new PhaseContext(getProviders(), new Assumptions(false));
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java	Wed May 14 01:24:10 2014 -0700
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java	Wed May 14 01:25:21 2014 -0700
@@ -261,6 +261,8 @@
                 IfNode ifNode2 = (IfNode) falseSuccessor().next();
                 if (ifNode2.condition() instanceof IntegerLessThanNode) {
                     IntegerLessThanNode lessThan2 = (IntegerLessThanNode) ifNode2.condition();
+                    BeginNode falseSucc = ifNode2.falseSuccessor();
+                    BeginNode trueSucc = ifNode2.trueSuccessor();
                     IntegerBelowThanNode below = null;
                     /*
                      * Convert x >= 0 && x < positive which is represented as !(x < 0) && x <
@@ -268,8 +270,11 @@
                      */
                     if (lessThan2.x() == lessThan.x() && lessThan2.y().stamp() instanceof IntegerStamp && ((IntegerStamp) lessThan2.y().stamp()).isPositive() &&
                                     sameDestination(trueSuccessor(), ifNode2.falseSuccessor)) {
-
                         below = graph().unique(new IntegerBelowThanNode(lessThan2.x(), lessThan2.y()));
+                        // swap direction
+                        BeginNode tmp = falseSucc;
+                        falseSucc = trueSucc;
+                        trueSucc = tmp;
                     } else if (lessThan2.y() == lessThan.x() && sameDestination(trueSuccessor(), ifNode2.trueSuccessor)) {
                         /*
                          * Convert x >= 0 && x <= positive which is represented as !(x < 0) &&
@@ -284,9 +289,6 @@
                         }
                     }
                     if (below != null) {
-                        BeginNode falseSucc = ifNode2.falseSuccessor();
-                        BeginNode trueSucc = ifNode2.trueSuccessor();
-
                         ifNode2.setTrueSuccessor(null);
                         ifNode2.setFalseSuccessor(null);