Do not eliminate array allocation if it may throw NegativeArraySizeException

Bug: 70023972
Test: run-test on host. 530-checker-lse.
Change-Id: I00e2d69f82b3dda21559ffcba827e0a52d900ff1
diff --git a/compiler/optimizing/load_store_elimination.cc b/compiler/optimizing/load_store_elimination.cc
index 8b4eae1..237ecd3 100644
--- a/compiler/optimizing/load_store_elimination.cc
+++ b/compiler/optimizing/load_store_elimination.cc
@@ -882,6 +882,7 @@
     }
     if (ref_info->IsSingletonAndRemovable() && !new_instance->NeedsChecks()) {
       DCHECK(!new_instance->IsFinalizable());
+      // new_instance can potentially be eliminated.
       singleton_new_instances_.push_back(new_instance);
     }
     ScopedArenaVector<HInstruction*>& heap_values =
@@ -904,7 +905,13 @@
       return;
     }
     if (ref_info->IsSingletonAndRemovable()) {
-      singleton_new_instances_.push_back(new_array);
+      if (new_array->GetLength()->IsIntConstant() &&
+          new_array->GetLength()->AsIntConstant()->GetValue() >= 0) {
+        // new_array can potentially be eliminated.
+        singleton_new_instances_.push_back(new_array);
+      } else {
+        // new_array may throw NegativeArraySizeException. Keep it.
+      }
     }
     ScopedArenaVector<HInstruction*>& heap_values =
         heap_values_for_[new_array->GetBlock()->GetBlockId()];