[Mlir-commits] [mlir] [MLIR][SCF] Support permutation-based parallel loop fusion (PR #203207)
Ivan Butygin
llvmlistbot at llvm.org
Tue Jun 16 04:27:28 PDT 2026
https://github.com/Hardcode84 commented:
another crash
```
// The first pair only fuses after the second loop is interchanged. The fusion
// driver must update the loop chain entry to the newly fused loop before trying
// the next pair, otherwise it can revisit the erased pre-interchange loop.
func.func @fuse_chain_after_interchanged_reduction(
%a: memref<2x3xf32>, %out: memref<2x3xf32>) -> (f32, f32) {
%tmp = memref.alloc() : memref<2x3xf32>
%mid = memref.alloc() : memref<2x3xf32>
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c2 = arith.constant 2 : index
%c3 = arith.constant 3 : index
%init1 = arith.constant 1.0 : f32
%init2 = arith.constant 2.0 : f32
%r1 = scf.parallel (%i, %j) = (%c0, %c0) to (%c2, %c3)
step (%c1, %c1) init(%init1) -> f32 {
%x = memref.load %a[%i, %j] : memref<2x3xf32>
memref.store %x, %tmp[%i, %j] : memref<2x3xf32>
scf.reduce(%x : f32) {
^bb0(%lhs: f32, %rhs: f32):
%sum = arith.addf %lhs, %rhs : f32
scf.reduce.return %sum : f32
}
}
%r2 = scf.parallel (%j2, %i2) = (%c0, %c0) to (%c3, %c2)
step (%c1, %c1) init(%init2) -> f32 {
%x = memref.load %tmp[%i2, %j2] : memref<2x3xf32>
memref.store %x, %mid[%i2, %j2] : memref<2x3xf32>
scf.reduce(%x : f32) {
^bb0(%lhs: f32, %rhs: f32):
%prod = arith.mulf %lhs, %rhs : f32
scf.reduce.return %prod : f32
}
}
scf.parallel (%i3, %j3) = (%c0, %c0) to (%c2, %c3)
step (%c1, %c1) {
%y = memref.load %mid[%i3, %j3] : memref<2x3xf32>
memref.store %y, %out[%i3, %j3] : memref<2x3xf32>
scf.reduce
}
memref.dealloc %tmp : memref<2x3xf32>
memref.dealloc %mid : memref<2x3xf32>
return %r1, %r2 : f32, f32
}
```
https://github.com/llvm/llvm-project/pull/203207
More information about the Mlir-commits
mailing list