Fix bug in dynamic BCE. With regression test.
Rationale:
We implicitly assumed anything on a fixed offset to a suitable
candidate could be picked for codegen. Although this is usually
true, the scanner found an exception (on types). So, it is best
to make the test explicit. Note: some type implications are TBD.
Bug:32193474
Test: test-art-host and offending APKs
Change-Id: I664a2caa97a7f231509f8832b940dd72da11a372
diff --git a/compiler/optimizing/bounds_check_elimination.cc b/compiler/optimizing/bounds_check_elimination.cc
index 994d394..529fc9e 100644
--- a/compiler/optimizing/bounds_check_elimination.cc
+++ b/compiler/optimizing/bounds_check_elimination.cc
@@ -1361,6 +1361,11 @@
ValueBound other_value = ValueBound::AsValueBound(other_index);
int32_t other_c = other_value.GetConstant();
if (array_length == other_array_length && base == other_value.GetInstruction()) {
+ // Ensure every candidate could be picked for code generation.
+ bool b1 = false, b2 = false;
+ if (!induction_range_.CanGenerateRange(other_bounds_check, other_index, &b1, &b2)) {
+ continue;
+ }
// Does the current basic block dominate all back edges? If not,
// add this candidate later only if it falls into the range.
if (!loop->DominatesAllBackEdges(user->GetBlock())) {