diff options
author | 2024-05-24 16:36:52 +0100 | |
---|---|---|
committer | 2024-06-21 15:27:19 +0000 | |
commit | 08b60ea29684c526f7bfb4ec30f6b0bf2186422d (patch) | |
tree | 8e8281eb3c03cf0d7fb1801567a126b9c7e34b12 /compiler/optimizing/induction_var_range.cc | |
parent | 50a7c38d0ec0c8e2817e782ef7f52e6f670ccb33 (diff) |
Eliminate never taken loops
If a loop is never taken we can safely eliminate it.
Known limitation: Due to how the loop trip calculation works,
if the calculation would overflow we would get "unknown" number
of trips. This could happen even for loops with 0 real iterations
like `(int i = Integer.MAX_VALUE; i < Integer.MIN_VALUE; i++)`.
Bug: 336236538
Fixes: 336236538
Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b
Test: m test-art-host-gtest-art_compiler_tests64
Change-Id: I26cae89a593e3375f9f1990a47f3c8973a76364c
Diffstat (limited to 'compiler/optimizing/induction_var_range.cc')
-rw-r--r-- | compiler/optimizing/induction_var_range.cc | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/optimizing/induction_var_range.cc b/compiler/optimizing/induction_var_range.cc index 8568062933..72719f89bf 100644 --- a/compiler/optimizing/induction_var_range.cc +++ b/compiler/optimizing/induction_var_range.cc @@ -384,6 +384,11 @@ bool InductionVarRange::HasKnownTripCount(const HLoopInformation* loop, /*out*/ int64_t* trip_count) const { bool is_constant = false; CheckForFiniteAndConstantProps(loop, &is_constant, trip_count); + // Set negative trip counts as 0, since it means that no trips would happen. Note that if the + // `is_constant` value is false, `trip_count` would be disregareded. + if (*trip_count < 0) { + *trip_count = 0; + } return is_constant; } |