[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


================
@@ -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++) {}
----------------
david-arm wrote:

A part of me wonders if this is so common we could also just recognise this as a loop idiom and have a new intrinsic for it? That would stop the unrolling and enable targets to generate the best possible code.

https://github.com/llvm/llvm-project/pull/205102


More information about the llvm-commits mailing list