diff options
author | 2018-01-22 12:59:43 -0800 | |
---|---|---|
committer | 2018-01-22 12:59:43 -0800 | |
commit | a95a5cc888e61e3a2ae7abecc00be770c6297267 (patch) | |
tree | 13a4e0a5210234bbea801347a9c8bd20cdc19219 /compiler/optimizing/bounds_check_elimination.cc | |
parent | 0d413f64984775f0e719d186bccfbd388a745d17 (diff) |
Improve bound analysis on constant range.
Rationale:
A low hanging fruit basedon the first CL
that addressed b/70688025 (when the method
is inlined, BCE did not kick in due to
missing the now constant range).
Bug: b/70688025
Test: test-art-host test-art-target
Change-Id: Ic317d5a0920e654b5158694a1dfa1ea359e0a839
Diffstat (limited to 'compiler/optimizing/bounds_check_elimination.cc')
-rw-r--r-- | compiler/optimizing/bounds_check_elimination.cc | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/compiler/optimizing/bounds_check_elimination.cc b/compiler/optimizing/bounds_check_elimination.cc index 147df1e3e8..d893cc88c4 100644 --- a/compiler/optimizing/bounds_check_elimination.cc +++ b/compiler/optimizing/bounds_check_elimination.cc @@ -836,9 +836,23 @@ class BCEVisitor : public HGraphVisitor { ValueRange array_range(&allocator_, lower, upper); // Try index range obtained by dominator-based analysis. ValueRange* index_range = LookupValueRange(index, block); - if (index_range != nullptr && index_range->FitsIn(&array_range)) { - ReplaceInstruction(bounds_check, index); - return; + if (index_range != nullptr) { + if (index_range->FitsIn(&array_range)) { + ReplaceInstruction(bounds_check, index); + return; + } else if (index_range->IsConstantValueRange()) { + // If the non-constant index turns out to have a constant range, + // make one more attempt to get a constant in the array range. + ValueRange* existing_range = LookupValueRange(array_length, block); + if (existing_range != nullptr && + existing_range->IsConstantValueRange()) { + ValueRange constant_array_range(&allocator_, lower, existing_range->GetLower()); + if (index_range->FitsIn(&constant_array_range)) { + ReplaceInstruction(bounds_check, index); + return; + } + } + } } // Try index range obtained by induction variable analysis. // Disables dynamic bce if OOB is certain. |