[flang-commits] [flang] [flang][mlir][fir] Unroll inner loops in presence of user vectorizati… (PR #210820)
via flang-commits
flang-commits at lists.llvm.org
Mon Jul 20 14:47:52 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- flang/lib/Optimizer/Transforms/VectorAlwaysUnroll.cpp flang/lib/Optimizer/Dialect/FIROps.cpp flang/lib/Optimizer/Passes/Pipelines.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index dd656efed..cd42e5127 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -4080,8 +4080,7 @@ llvm::SmallVector<mlir::Region *> fir::DoLoopOp::getLoopRegions() {
std::optional<llvm::APInt> fir::DoLoopOp::getStaticTripCount() {
auto getConstant = [](mlir::Value v) -> std::optional<std::int64_t> {
- while (auto cvt =
- mlir::dyn_cast_or_null<fir::ConvertOp>(v.getDefiningOp()))
+ while (auto cvt = mlir::dyn_cast_or_null<fir::ConvertOp>(v.getDefiningOp()))
v = cvt.getValue();
return fir::getIntIfConstant(v);
};
diff --git a/flang/lib/Optimizer/Transforms/VectorAlwaysUnroll.cpp b/flang/lib/Optimizer/Transforms/VectorAlwaysUnroll.cpp
index 3e70722e6..4ddf3cf21 100644
--- a/flang/lib/Optimizer/Transforms/VectorAlwaysUnroll.cpp
+++ b/flang/lib/Optimizer/Transforms/VectorAlwaysUnroll.cpp
@@ -8,13 +8,13 @@
//===----------------------------------------------------------------------===//
/// \file
-/// This pass tags inner loops when their outer loop has a user provided
-/// vectorization attribute:(`!dir$ vector always`, `!dir$ vector length`,
+/// 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
+/// 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
@@ -80,7 +80,8 @@ public:
void runOnOperation() override;
private:
- /// Tag qualifying nested inner loops with `llvm.loop.unroll.full` annotations.
+ /// Tag qualifying nested inner loops with `llvm.loop.unroll.full`
+ /// annotations.
void tagNest(fir::DoLoopOp outerLoop,
mlir::LLVM::LoopAnnotationAttr unrollAnnotation);
};
@@ -107,7 +108,6 @@ void VectorAlwaysUnrollPass::runOnOperation() {
/*mustProgress=*/{}, /*isVectorized=*/{}, /*startLoc=*/{},
/*endLoc=*/{}, /*parallelAccesses=*/{});
-
func.walk([&](fir::DoLoopOp outerLoop) {
// Only act on loops that request vectorization. Lowering encodes
// `!dir$ vector always`, `!dir$ vector length`, and `!dir$ simd` as a
@@ -131,8 +131,7 @@ void VectorAlwaysUnrollPass::runOnOperation() {
}
void VectorAlwaysUnrollPass::tagNest(
- fir::DoLoopOp outerLoop,
- mlir::LLVM::LoopAnnotationAttr unrollAnnotation) {
+ fir::DoLoopOp outerLoop, mlir::LLVM::LoopAnnotationAttr unrollAnnotation) {
std::uint64_t estimatedOps = 0;
for (mlir::Operation &op : outerLoop.getBody()->without_terminator()) {
auto nested = mlir::dyn_cast<fir::DoLoopOp>(&op);
@@ -162,13 +161,12 @@ void VectorAlwaysUnrollPass::tagNest(
return;
LLVM_DEBUG(llvm::dbgs() << " tagging loop at " << innerLoop.getLoc()
<< " with unroll.full\n");
- mlir::LLVM::LoopAnnotationAttr existing =
- innerLoop.getLoopAnnotationAttr();
+ mlir::LLVM::LoopAnnotationAttr existing = innerLoop.getLoopAnnotationAttr();
if (!existing) {
innerLoop.setLoopAnnotationAttr(unrollAnnotation);
return;
}
-
+
if (existing.getUnroll()) {
LLVM_DEBUG(llvm::dbgs()
<< " keep: loop already has an unroll annotation\n");
@@ -176,16 +174,14 @@ void VectorAlwaysUnrollPass::tagNest(
}
// Append the unroll.full annotation to the existing loop_annotation
mlir::MLIRContext *ctx = innerLoop.getContext();
- mlir::LLVM::LoopAnnotationAttr merged =
- mlir::LLVM::LoopAnnotationAttr::get(
- ctx, existing.getDisableNonforced(), existing.getVectorize(),
- existing.getInterleave(), /*unroll=*/unrollAnnotation.getUnroll(),
- existing.getUnrollAndJam(), existing.getLicm(),
- existing.getDistribute(), existing.getPipeline(),
- existing.getPeeled(), existing.getUnswitch(),
- existing.getMustProgress(), existing.getIsVectorized(),
- existing.getStartLoc(), existing.getEndLoc(),
- existing.getParallelAccesses());
+ mlir::LLVM::LoopAnnotationAttr merged = mlir::LLVM::LoopAnnotationAttr::get(
+ ctx, existing.getDisableNonforced(), existing.getVectorize(),
+ existing.getInterleave(), /*unroll=*/unrollAnnotation.getUnroll(),
+ existing.getUnrollAndJam(), existing.getLicm(),
+ existing.getDistribute(), existing.getPipeline(), existing.getPeeled(),
+ existing.getUnswitch(), existing.getMustProgress(),
+ existing.getIsVectorized(), existing.getStartLoc(),
+ existing.getEndLoc(), existing.getParallelAccesses());
innerLoop.setLoopAnnotationAttr(merged);
});
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/210820
More information about the flang-commits
mailing list