[flang-commits] [flang] [flang][mlir][fir] Unroll inner loops in presence of user vectorizati… (PR #210820)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Wed Jul 22 04:08:18 PDT 2026


================
@@ -0,0 +1,187 @@
+//===- VectorAlwaysUnroll.cpp ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+/// \file
+/// This pass tags inner loops when their outer loop has a user provided
+/// vectorization attribute:(`!dir$ vector always`, `!dir$ vector length`,
+/// and `!dir$ simd`).
+///
+/// For each such loop, this pass attaches an `llvm.loop.unroll.full` annotation
+/// to every `fir.do_loop` nested within it. Fully unrolling those inner loops
+/// later (in LLVM's LoopFullUnrollPass), which allows outer-loop vectorization
+/// of the annotated loop.
+///
+/// Full unrolling of nested loops is multiplicative in code size and compile
+/// time, so tagging is guarded by a cost heuristic:
+///   * only loops with compile-time-constant trip counts are considered
+///     (LoopFullUnrollPass cannot unroll otherwise);
+///   * and the estimated unrolled op count (trip product times per-iteration
+///     op count) stays within `max-unroll-ops`.
----------------
tblah wrote:

Okay just add the documentation please

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


More information about the flang-commits mailing list