bce: handle a pattern for circular buffer

Change-Id: Ie54bdd7c044af58deea0d0addaaa8186cabf3532
diff --git a/compiler/optimizing/bounds_check_elimination.cc b/compiler/optimizing/bounds_check_elimination.cc
index 811a3bd..deaeb8e 100644
--- a/compiler/optimizing/bounds_check_elimination.cc
+++ b/compiler/optimizing/bounds_check_elimination.cc
@@ -823,6 +823,21 @@
     FindAndHandlePartialArrayLength(ushr);
   }
 
+  void VisitAnd(HAnd* instruction) {
+    if (instruction->GetRight()->IsIntConstant()) {
+      int32_t constant = instruction->GetRight()->AsIntConstant()->GetValue();
+      if (constant > 0) {
+        // constant serves as a mask so any number masked with it
+        // gets a [0, constant] value range.
+        ValueRange* range = new (GetGraph()->GetArena()) ValueRange(
+            GetGraph()->GetArena(),
+            ValueBound(nullptr, 0),
+            ValueBound(nullptr, constant));
+        GetValueRangeMap(instruction->GetBlock())->Overwrite(instruction->GetId(), range);
+      }
+    }
+  }
+
   void VisitNewArray(HNewArray* new_array) {
     HInstruction* len = new_array->InputAt(0);
     if (!len->IsIntConstant()) {