[llvm] [AArch64] Cap upper-bound unrolling of loops with uncomputable trip counts (PR #205102)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 6 03:38:23 PDT 2026
================
@@ -6042,6 +6042,19 @@ void AArch64TTIImpl::getUnrollingPreferences(
UP.UpperBound = true;
+ // A loop can have a small maximum trip count while SCEV still cannot
+ // form an exact backedge count - typically a data-dependent exit, e.g.
+ // shifting a value until it reaches zero. Unrolling such a loop trades one
+ // well-predicted backedge for a chain of rarely-taken exit branches, so hold
----------------
david-arm wrote:
Surely this is only true for some loops (presumably including the one you care about), but in the general case it may not be. In your `varint_len` example below what if v=1? If we unroll such a loop then every early exit would be taken, so it would be a chain of always-taken exit branches instead? i.e.
if ((1 >> 7) == 0) break;
if ((1 >> 14) == 0) break;
etc.
This comment suggests we are making assumptions about the input data and using that as the motivation for the change.
https://github.com/llvm/llvm-project/pull/205102
More information about the llvm-commits
mailing list