[llvm] [AArch64] Cap upper-bound unrolling of loops with uncomputable trip counts (PR #205102)
Igor Kirillov via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 6 06:01:08 PDT 2026
================
@@ -0,0 +1,217 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -passes=loop-unroll -mtriple=aarch64 < %s | FileCheck %s --check-prefixes=DEFAULT
+; RUN: opt -S -passes=loop-unroll -mtriple=aarch64 -unroll-max-upperbound=8 < %s | FileCheck %s --check-prefixes=WIDE
+
+; AArch64 caps upper-bound unrolling at a max trip count of 5 for loops whose
+; exact trip count is not computable (data-dependent exits). A typical case is
+; a varint-length helper:
+;
+; int varint_len(uint32_t serial_type) {
+; uint64_t v = serial_type;
+; int i;
+; for (i = 1; (v >>= 7) != 0; i++) {}
----------------
igogo-x86 wrote:
For this particular shape, no new intrinsic is needed - we already have `llvm.ctlz` and can rewrite this as:
```
len = (BW + K - 1 - ctlz(v | 1)) / K
```
or in sqlite3 case:
```
(38 - clz32(serial_type | 1)) / 7
```
However, it was slower because it results in several instructions (it's much faster on random data though)
https://github.com/llvm/llvm-project/pull/205102
More information about the llvm-commits
mailing list