[Mlir-commits] [mlir] [mlir][sparse] Lower affine before SCF to CF in sparsifier (PR #219860)

Kohei Yamaguchi llvmlistbot at llvm.org
Sun Aug 30 16:47:00 PDT 2026


https://github.com/sott0n created https://github.com/llvm/llvm-project/pull/219860

Fix the lowering order in the sparsifier pipeline by running `convert-scf-to-cf` after `lower-affine`.

Previously, `convert-scf-to-cf` ran while Affine control-flow operations could still be present. For example, lowering an `scf.if` nested inside an `affine.for` introduces multiple blocks into the loop body, violating `affine.for`'s single-block region requirement and causing verification to fail.

Running `lower-affine` first converts Affine control flow to SCF. The subsequent `convert-scf-to-cf` pass can then lower both the existing SCF operations and those introduced by Affine lowering to CFG-based control flow.

`expand-strided-metadata` remains before `lower-affine`, since it can introduce Affine operations.

Fixes #217895.

>From 0394a1728de34a4567b7d1b846769f7cb0b349b4 Mon Sep 17 00:00:00 2001
From: Kohei Yamaguchi <fix7211 at gmail.com>
Date: Mon, 31 Aug 2026 08:41:20 +0900
Subject: [PATCH] [mlir][sparse] Lower affine before SCF to CF in sparsifier

---
 .../Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp b/mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp
index d85966ec88f98..9e33544efbcce 100644
--- a/mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp
@@ -67,9 +67,9 @@ void mlir::sparse_tensor::buildSparsifier(OpPassManager &pm,
   pm.addNestedPass<func::FuncOp>(createConvertLinalgToLoopsPass());
   pm.addNestedPass<func::FuncOp>(createConvertVectorToSCFPass());
   pm.addNestedPass<func::FuncOp>(memref::createExpandReallocPass());
-  pm.addNestedPass<func::FuncOp>(createSCFToControlFlowPass());
   pm.addPass(memref::createExpandStridedMetadataPass());
   pm.addPass(createLowerAffinePass());
+  pm.addNestedPass<func::FuncOp>(createSCFToControlFlowPass());
   pm.addPass(
       createConvertVectorToLLVMPass(options.convertVectorToLLVMOptions()));
   pm.addNestedPass<func::FuncOp>(createConvertComplexToStandardPass());



More information about the Mlir-commits mailing list