[Mlir-commits] [mlir] [mlir][bufferization] Add loop-iter-arg-destination-folding pass (PR #213207)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jul 31 07:36:27 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 -- mlir/lib/Dialect/Bufferization/Transforms/LoopIterArgDestinationFolding.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/mlir/lib/Dialect/Bufferization/Transforms/LoopIterArgDestinationFolding.cpp b/mlir/lib/Dialect/Bufferization/Transforms/LoopIterArgDestinationFolding.cpp
index c64a60c21..87d487ac0 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/LoopIterArgDestinationFolding.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/LoopIterArgDestinationFolding.cpp
@@ -30,7 +30,8 @@
// reuse:
//
// %w = vector.transfer_write %new, %acc[...] // destination = iter_arg
-// scf.yield %w // yield == iter_arg (in place)
+// scf.yield %w // yield == iter_arg (in
+// place)
//
// This folds the iter_arg to loop-invariant reuse; bufferization then keeps it
// in place with no per-iteration copy.
@@ -66,8 +67,7 @@ using namespace mlir::scf;
/// such a write. A whole-tensor write has all-zero constant indices, an
/// identity permutation, and all dims in-bounds, so it fully defines the tensor
/// and its destination's prior contents are dead.
-static vector::TransferWriteOp
-getFoldableYieldWrite(Value value, ForOp loop) {
+static vector::TransferWriteOp getFoldableYieldWrite(Value value, ForOp loop) {
auto write = value.getDefiningOp<vector::TransferWriteOp>();
if (!write)
return nullptr;
@@ -88,9 +88,8 @@ getFoldableYieldWrite(Value value, ForOp loop) {
return nullptr;
if (llvm::any_of(write.getInBoundsValues(), [](bool b) { return !b; }))
return nullptr;
- if (!llvm::all_of(write.getIndices(), [](Value idx) {
- return matchPattern(idx, m_Zero());
- }))
+ if (!llvm::all_of(write.getIndices(),
+ [](Value idx) { return matchPattern(idx, m_Zero()); }))
return nullptr;
return write;
}
@@ -98,16 +97,16 @@ getFoldableYieldWrite(Value value, ForOp loop) {
/// The yielded value's write only produces the loop-carried result, so it may
/// be moved down to just before the terminator. Doing so places it after every
/// other operation in the (single-block) body, in particular after every read
-/// of the iter_arg, which is what makes the in-place fold sound: the reads still
-/// observe the incoming value and only the final store defines what the next
-/// iteration reads. Moving down is legal because the write's result feeds solely
-/// the yield (checked by the caller) and its operands dominate the terminator
-/// (they are defined earlier in the same block).
+/// of the iter_arg, which is what makes the in-place fold sound: the reads
+/// still observe the incoming value and only the final store defines what the
+/// next iteration reads. Moving down is legal because the write's result feeds
+/// solely the yield (checked by the caller) and its operands dominate the
+/// terminator (they are defined earlier in the same block).
///
/// Returns false only if the write cannot be scheduled after all reads, i.e. a
/// read of the iter_arg transitively *depends on* the write's result. That
-/// cannot happen here (the result is yield-only), but the check is kept explicit
-/// for safety against future callers.
+/// cannot happen here (the result is yield-only), but the check is kept
+/// explicit for safety against future callers.
static bool canScheduleWriteLast(ForOp loop, unsigned idx,
vector::TransferWriteOp write) {
// The write's result must not be consumed by anything other than the yield,
``````````
</details>
https://github.com/llvm/llvm-project/pull/213207
More information about the Mlir-commits
mailing list