[Mlir-commits] [mlir] [mlir][vector] Sink vector.extract/splat into load/store ops (PR #134389)
Jakub Kuderski
llvmlistbot at llvm.org
Fri Apr 11 08:27:34 PDT 2025
================
@@ -161,6 +161,20 @@ void populateVectorTransferCollapseInnerMostContiguousDimsPatterns(
void populateSinkVectorOpsPatterns(RewritePatternSet &patterns,
PatternBenefit benefit = 1);
+/// Patterns that remove redundant Vector Ops by merging them with load/store
+/// ops
+/// ```
+/// vector.load %arg0[%arg1] : memref<?xf32>, vector<4xf32>
+/// vector.extract %0[1] : f32 from vector<4xf32>
+/// ```
+/// Gets converted to:
+/// ```
+/// %c1 = arith.constant 1 : index
+/// %0 = arith.addi %arg1, %c1 overflow<nsw> : index
+/// %1 = memref.load %arg0[%0] : memref<?xf32>
----------------
kuhar wrote:
> This pattern is constrained to using/extracting only one element so we wouldn't be dropping access pattern information for that case, right? Do you have something else in mind?
Say one of your memory is dword-sized but your memory accesses take byte offsets:
```mlir
%x = vector.load ... : vector<4xi8>
%y = vector.extract %x [2]: i8
```
The original load is efficient because you are accessing a full dword. However, if you turn it into `memref.load ... : i8`, you may no longer know, once the index calculation simplifies with something else, that to get an aligned dword load you you need to also load the preceding bytes vs. only the bytes following this i8 (unaligned).
> Could you help me understand this? We should be able to remove any load operation that is dead, regardless of whether it's in-bounds or OOB, right? What makes this case different?
For example, the buffer instruction on amdgpu allow you to get a default value for any OOB accesses. Looking into the example above, it could be that only the last byte is OOB, but this alone makes the whole `vector<4xi8>` have the default value. If you no longer load that last byte, the access would be in-bounds and you would observe a different value.
https://github.com/llvm/llvm-project/pull/134389
More information about the Mlir-commits
mailing list