Skip to content

Commit 861600f

Browse files
[mlir][SparseTensor] Fix invalid IR in ForallRewriter pattern (#74547)
The `ForallRewriter` pattern used to generate invalid IR: ``` mlir/test/Dialect/SparseTensor/GPU/gpu_combi.mlir:0:0: error: 'scf.for' op expects region #0 to have 0 or 1 blocks mlir/test/Dialect/SparseTensor/GPU/gpu_combi.mlir:0:0: note: see current operation: "scf.for"(%8, %2, %9) ({ ^bb0(%arg5: index): // ... "scf.yield"() : () -> () ^bb1(%10: index): // no predecessors "scf.yield"() : () -> () }) : (index, index, index) -> () ``` This commit fixes tests such as `mlir/test/Dialect/SparseTensor/GPU/gpu_combi.mlir` when verifying the IR after each pattern application (#74270).
1 parent 851f85f commit 861600f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mlir/lib/Dialect/SparseTensor/Transforms/SparseGPUCodegen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ static void genGPUCode(PatternRewriter &rewriter, gpu::GPUFuncOp gpuFunc,
309309
// }
310310
Value upper = irMap.lookup(forallOp.getUpperBound()[0]);
311311
scf::ForOp forOp = rewriter.create<scf::ForOp>(loc, row, upper, inc);
312+
// The scf.for builder creates an empty block. scf.for does not allow multiple
313+
// blocks in its region, so delete the block before `cloneRegionBefore` adds
314+
// an additional block.
315+
rewriter.eraseBlock(forOp.getBody());
312316
rewriter.cloneRegionBefore(forallOp.getRegion(), forOp.getRegion(),
313317
forOp.getRegion().begin(), irMap);
314318

0 commit comments

Comments
 (0)