[MLIR] Missed Optimization: Sparse vectorization rejects loop-invariant block arguments
isInvariantValue requires a defining operation, so it does not recognize function arguments as loop-invariant values. Consequently, the supported contiguous access pattern a[base + i] is rejected when base is a function argument. The same omission affects invariant shift amounts passed as function arguments.
Code Example
input.mlir
func.func @invariant_base(%a: memref<?xi32>, %base: index) {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c64 = arith.constant 64 : index
%two = arith.constant 2 : i32
scf.for %i = %c0 to %c64 step %c1 {
%p = arith.addi %base, %i : index
%x = memref.load %a[%p] : memref<?xi32>
%y = arith.muli %x, %two : i32
memref.store %y, %a[%p] : memref<?xi32>
} {"Emitted from" = "linalg.generic"}
return
}
Command
mlir-opt input.mlir --sparse-vectorization='vl=4'
Version: 6f54fe6b6fb22f8a335fd19b94049fc769dfea25
@llvm/issue-subscribers-mlir
Author: CC_Fans (dev-816)
Code Example
input.mlir
func.func @<!-- -->invariant_base(%a: memref<?xi32>, %base: index) {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c64 = arith.constant 64 : index
%two = arith.constant 2 : i32
scf.for %i = %c0 to %c64 step %c1 {
%p = arith.addi %base, %i : index
%x = memref.load %a[%p] : memref<?xi32>
%y = arith.muli %x, %two : i32
memref.store %y, %a[%p] : memref<?xi32>
} {"Emitted from" = "linalg.generic"}
return
}
Command
mlir-opt input.mlir --sparse-vectorization='vl=4'
Version: 6f54fe6b6fb22f8a335fd19b94049fc769dfea25
hey, can this issue be assigned? I was interested
@Vara715 I don't have permission to assign issues. If you are interested, please submit a PR to fix this bug and @ relevant developers.