[MLIR] `scf-parallel-loop-fusion` misses adjacent loops with identical constant bounds
scf-parallel-loop-fusion misses a fusion opportunity when two adjacent scf.parallel loops have the same constant bounds and step, but those constants are defined by different arith.constant ops.
The loops below both iterate from 0 to 16 with step 1, so their iteration spaces are equivalent and they should be fusible. However, the pass appears to compare loop bounds by SSA value identity instead of comparing equivalent constant values.
Input Program
input.mlir
module {
func.func @constant_bounds(%arg0: memref<16xf32>, %arg1: memref<16xf32>) {
%c0 = arith.constant 0 : index
%c16 = arith.constant 16 : index
%c1 = arith.constant 1 : index
%cst = arith.constant 1.000000e+00 : f32
scf.parallel (%arg2) = (%c0) to (%c16) step (%c1) {
memref.store %cst, %arg0[%arg2] : memref<16xf32>
scf.reduce
}
%c0_0 = arith.constant 0 : index
%c16_1 = arith.constant 16 : index
%c1_2 = arith.constant 1 : index
scf.parallel (%arg2) = (%c0_0) to (%c16_1) step (%c1_2) {
%0 = memref.load %arg0[%arg2] : memref<16xf32>
memref.store %0, %arg1[%arg2] : memref<16xf32>
scf.reduce
}
return
}
}
Command
mlir-opt input.mlir --scf-parallel-loop-fusion
Version: 157af9cb0e9cad7df0e8e1d44c78f08ffa7c48e7
@llvm/issue-subscribers-mlir
Author: CC_Fans (dev-816)
The loops below both iterate from 0 to 16 with step 1, so their iteration spaces are equivalent and they should be fusible. However, the pass appears to compare loop bounds by SSA value identity instead of comparing equivalent constant values.
Input Program
input.mlir
module {
func.func @<!-- -->constant_bounds(%arg0: memref<16xf32>, %arg1: memref<16xf32>) {
%c0 = arith.constant 0 : index
%c16 = arith.constant 16 : index
%c1 = arith.constant 1 : index
%cst = arith.constant 1.000000e+00 : f32
scf.parallel (%arg2) = (%c0) to (%c16) step (%c1) {
memref.store %cst, %arg0[%arg2] : memref<16xf32>
scf.reduce
}
%c0_0 = arith.constant 0 : index
%c16_1 = arith.constant 16 : index
%c1_2 = arith.constant 1 : index
scf.parallel (%arg2) = (%c0_0) to (%c16_1) step (%c1_2) {
%0 = memref.load %arg0[%arg2] : memref<16xf32>
memref.store %0, %arg1[%arg2] : memref<16xf32>
scf.reduce
}
return
}
}
Command
mlir-opt input.mlir --scf-parallel-loop-fusion
Version: 157af9cb0e9cad7df0e8e1d44c78f08ffa7c48e7