[Mlir-commits] [mlir] [mlir][sparse] Fix mixed sparse-dense iterator lowering (PR #219753)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Aug 29 20:22:24 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/SparseTensor/Transforms/SparseIterationToScf.cpp mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.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/SparseTensor/Transforms/SparseIterationToScf.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseIterationToScf.cpp
index bc03b7f0d..adfb06402 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseIterationToScf.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseIterationToScf.cpp
@@ -230,8 +230,7 @@ public:
                   ConversionPatternRewriter &rewriter) const override {
     I64BitSet crdUsedLvls = op.getCrdUsedLvls();
     if (crdUsedLvls.count() > 1 ||
-        (!crdUsedLvls.empty() &&
-         !crdUsedLvls[op.getSpaceDim() - 1]))
+        (!crdUsedLvls.empty() && !crdUsedLvls[op.getSpaceDim() - 1]))
       return rewriter.notifyMatchFailure(
           op, "coordinates other than the final level are not implemented");
 
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
index 364ce9ee1..9b307b31d 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
@@ -1135,15 +1135,16 @@ static bool startLoopSeq(CodegenEnv &env, OpBuilder &builder, ExprId exp,
   const LatPointId l0 = env.set(lts)[0];
 
   SmallVector<TensorLevel> tidLvls;
-  getAllTidLvlsInLatPoints(
-      env, l0, curr, [&](TensorLevel tl, AffineExpr, bool) {
-    // TODO: remove this! The same tensor level might be added for multiple
-    // times due to the special handling for all-dense "sparse" output tensor
-    // (see L1038).
-    if (llvm::is_contained(tidLvls, tl))
-      return;
-    tidLvls.emplace_back(tl);
-  });
+  getAllTidLvlsInLatPoints(env, l0, curr,
+                           [&](TensorLevel tl, AffineExpr, bool) {
+                             // TODO: remove this! The same tensor level might
+                             // be added for multiple times due to the special
+                             // handling for all-dense "sparse" output tensor
+                             // (see L1038).
+                             if (llvm::is_contained(tidLvls, tl))
+                               return;
+                             tidLvls.emplace_back(tl);
+                           });
 
   env.emitter().enterNewLoopSeq(builder, env.op().getLoc(), tidLvls);
 
@@ -1199,17 +1200,16 @@ static bool translateBitsToTidLvlPairs(
     SmallVectorImpl<TensorLevel> &tidLvls,
     SmallVectorImpl<TensorLevel> &condTidLvls,
     SmallVectorImpl<std::pair<TensorLevel, AffineExpr>> &affineTidLvls) {
-  return getAllTidLvlsInLatPoints(env, li, curr,
-                                  [&](TensorLevel tl, AffineExpr exp,
-                                      bool isLoopCond) {
-                                    if (exp)
-                                      affineTidLvls.emplace_back(tl, exp);
-                                    else {
-                                      tidLvls.emplace_back(tl);
-                                      if (isLoopCond)
-                                        condTidLvls.emplace_back(tl);
-                                    }
-                                  });
+  return getAllTidLvlsInLatPoints(
+      env, li, curr, [&](TensorLevel tl, AffineExpr exp, bool isLoopCond) {
+        if (exp)
+          affineTidLvls.emplace_back(tl, exp);
+        else {
+          tidLvls.emplace_back(tl);
+          if (isLoopCond)
+            condTidLvls.emplace_back(tl);
+        }
+      });
 }
 
 /// Starts a single loop in current sequence.
@@ -1226,13 +1226,13 @@ static std::pair<Operation *, bool> startLoop(CodegenEnv &env,
   // The set of dense tensors with non-trivial affine expression that just
   // becomes invariant and the address are generated at the current level.
   SmallVector<std::pair<TensorLevel, AffineExpr>> affineTidLvls;
-  bool isSingleCond = translateBitsToTidLvlPairs(
-      env, li, curr, tidLvls, condTidLvls, affineTidLvls);
+  bool isSingleCond = translateBitsToTidLvlPairs(env, li, curr, tidLvls,
+                                                 condTidLvls, affineTidLvls);
 
   // Emit the for/while-loop control.
-  ArrayRef<TensorLevel> loopTidLvls =
-      env.generatingSparseIterator() ? ArrayRef(condTidLvls)
-                                     : ArrayRef(tidLvls);
+  ArrayRef<TensorLevel> loopTidLvls = env.generatingSparseIterator()
+                                          ? ArrayRef(condTidLvls)
+                                          : ArrayRef(tidLvls);
   Operation *loop =
       genLoop(env, builder, curr, numCases, needsUniv, loopTidLvls);
   Location loc = env.op().getLoc();

``````````

</details>


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


More information about the Mlir-commits mailing list