[MLIR] `scf.parallel` loop fusion misses opportunity when equivalent index expressions are commuted
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
MLIR misses a valid `scf.parallel` loop fusion opportunity when the producer and consumer use equivalent but syntactically different index expressions.
In the example below, the first loop stores to `%arg0[%arg2 + 1]`, and the second loop loads from `%arg0[1 + %arg2]`. These indices are semantically identical because integer addition is commutative, so the two loops could be fused safely. However, the fusion pass does not recognize this equivalence.
### Input Program
**input.mlir**
```llvm
module {
func.func @commuted_index(%arg0: memref<32xf32>, %arg1: memref<32xf32>) {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c16 = arith.constant 16 : index
%cst = arith.constant 3.000000e+00 : f32
scf.parallel (%arg2) = (%c0) to (%c16) step (%c1) {
%0 = arith.addi %arg2, %c1 : index
memref.store %cst, %arg0[%0] : memref<32xf32>
scf.reduce
}
scf.parallel (%arg2) = (%c0) to (%c16) step (%c1) {
%0 = arith.addi %c1, %arg2 : index
%1 = memref.load %arg0[%0] : memref<32xf32>
memref.store %1, %arg1[%0] : memref<32xf32>
scf.reduce
}
return
}
}
```
### Command
```bash
mlir-opt input.mlir --scf-parallel-loop-fusion
```
Version: 157af9cb0e9cad7df0e8e1d44c78f08ffa7c48e7
Contributor guide
Research direction
Start by running the provided input.mlir with mlir-opt --scf-parallel-loop-fusion and inspect the scf.parallel loop fusion pass. Use the reproduced commuted index expressions as the focused case; done means the two loops are recognized as a valid fusion opportunity without changing the intended behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100