[Mlir-commits] [mlir] [mlir][vector] Fix vector.gather lowering for strided memrefs. (PR #184706)

Andrzej WarzyƄski llvmlistbot at llvm.org
Fri Mar 13 04:08:41 PDT 2026


================
@@ -163,6 +164,12 @@ struct RemoveStrideFromGatherSource : OpRewritePattern<vector::GatherOp> {
 /// Turns 1-d `vector.gather` into a scalarized sequence of `vector.loads` or
 /// `tensor.extract`s. To avoid out-of-bounds memory accesses, these
 /// loads/extracts are made conditional using `scf.if` ops.
+///
+/// For multi-dimensional memrefs (rank > 1), the gather index is combined
+/// with the base offsets via linearize-then-delinearize to produce correct
+/// N-D load indices:
+///   flatIdx = linearize(baseOffsets, memrefShape) + gatherIndex
+///   loadIndices = delinearize(flatIdx, memrefShape)
----------------
banach-space wrote:

For alignment with https://mlir.llvm.org/docs/Dialects/Vector/#vectorgather-vectorgatherop, could we use `offsets` and `indices`? 

```suggestion
///   idx = indices[i]
///   flatIdx = linearize(offsets, memrefShape) + idx 
///   loadIndices = delinearize(flatIdx, memrefShape)
```

https://github.com/llvm/llvm-project/pull/184706


More information about the Mlir-commits mailing list