llvm-project
llvm-project copied to clipboard
[MLIR] Missed Optimization: Disjoint stores prevent hoisting an invariant `affine.load`
The load from A[0] can move before the loop because all loop stores access A[1..16]. However, the interference check treats any write to the same memref as a conflict without distinguishing the accessed addresses.
Inpu Program
input.mlir
func.func @addresses(%A: memref<17xi32>, %v: i32) {
affine.store %v, %A[0] : memref<17xi32>
affine.for %i = 0 to 16 {
%x = affine.load %A[0] : memref<17xi32>
affine.store %x, %A[%i + 1] : memref<17xi32>
}
return
}
Command
mlir-opt input.mlir -affine-loop-invariant-code-motion
Version: 6f54fe6b6fb22f8a335fd19b94049fc769dfea25
@llvm/issue-subscribers-mlir
Author: CC_Fans (dev-816)
The load from `A[0]` can move before the loop because all loop stores access `A[1..16]`. However, the interference check treats any write to the same memref as a conflict without distinguishing the accessed addresses.
Inpu Program
input.mlir
func.func @<!-- -->addresses(%A: memref<17xi32>, %v: i32) {
affine.store %v, %A[0] : memref<17xi32>
affine.for %i = 0 to 16 {
%x = affine.load %A[0] : memref<17xi32>
affine.store %x, %A[%i + 1] : memref<17xi32>
}
return
}
Command
mlir-opt input.mlir -affine-loop-invariant-code-motion
Version: 6f54fe6b6fb22f8a335fd19b94049fc769dfea25
I'm cleaning up my implementation and will open a PR soon.
I've opened a PR. Reviews and feedback are welcome.