OSDN Git Service

BCE: Narrow instead of unconditionnaly overwrite the range.
authorNicolas Geoffray <ngeoffray@google.com>
Wed, 24 Jun 2015 09:38:27 +0000 (10:38 +0100)
committerNicolas Geoffray <ngeoffray@google.com>
Wed, 24 Jun 2015 14:07:50 +0000 (15:07 +0100)
bug:21862741
Change-Id: Ic1c2d6fa64255623f87af33a297c459cc9080d3c

compiler/optimizing/bounds_check_elimination.cc
test/513-array-deopt/src/Main.java

index 900dabe..92c7e28 100644 (file)
@@ -1180,9 +1180,7 @@ class BCEVisitor : public HGraphVisitor {
       }
     }
     ValueRange* narrowed_range = existing_range->Narrow(range);
-    if (narrowed_range != nullptr) {
-      GetValueRangeMap(successor)->Overwrite(instruction->GetId(), narrowed_range);
-    }
+    GetValueRangeMap(successor)->Overwrite(instruction->GetId(), narrowed_range);
   }
 
   // Special case that we may simultaneously narrow two MonotonicValueRange's to
@@ -1730,6 +1728,10 @@ class BCEVisitor : public HGraphVisitor {
         ValueBound upper = ValueBound(new_array, -right_const);
         ValueRange* range = new (GetGraph()->GetArena())
             ValueRange(GetGraph()->GetArena(), lower, upper);
+        ValueRange* existing_range = LookupValueRange(left, new_array->GetBlock());
+        if (existing_range != nullptr) {
+          range = existing_range->Narrow(range);
+        }
         GetValueRangeMap(new_array->GetBlock())->Overwrite(left->GetId(), range);
       }
     }
index a0ae4c3..5ee4d55 100644 (file)
@@ -19,19 +19,36 @@ public class Main {
     a[0] = 0;
     a[1] = 0;
     a[2] = 0;
-    // Up to this point, we record that the lower bound is 2.
+    // Up to this point, we record that the lower bound (inclusive) is 3.
     // The next instruction will record that the lower bound is 5.
     // The deoptimization code used to assume the lower bound has
-    // to be check it will add for the deoptimization (here, it
-    // would be 2).
+    // to be the one it will add for the deoptimization check (here, it
+    // would be 3).
     return new int[a.length - 5];
   }
 
+  public static int[] foo(int[] a) {
+    a[0] = 0;
+    a[1] = 0;
+    a[2] = 0;
+    // Up to this point, we record that the lower bound (inclusive) is 3.
+    // The next instruction will record that the lower bound is 1.
+    // The deoptimization code used to assume the lower bound has
+    // to be the one it will add for the deoptimization check (here, it
+    // would be 3).
+    return new int[a.length - 1];
+  }
+
   public static void main(String[] args) {
     int[] a = new int[5];
-    a = bar(a);
-    if (a.length != 0) {
-      throw new Error("Expected 0, got " + a.length);
+    int[] result = bar(a);
+    if (result.length != 0) {
+      throw new Error("Expected 0, got " + result.length);
+    }
+
+    result = foo(a);
+    if (result.length != 4) {
+      throw new Error("Expected 5, got " + result.length);
     }
   }
 }