[Mlir-commits] [mlir] [mlir][vector] Add alignment attribute to vector operations. (PR #152507)

Andrzej Warzyński llvmlistbot at llvm.org
Fri Aug 15 02:23:02 PDT 2025


================
@@ -1919,7 +1922,6 @@ def Vector_MaskedLoadOp :
     load operation. It must be a positive power of 2. The operation must access
     memory at an address aligned to this boundary. Violations may lead to
     architecture-specific faults or performance penalties.
-    A value of 0 indicates no specific alignment requirement.
----------------
banach-space wrote:

Thanks for the detailed explanation! Looks like things have become a bit complex recently 😅 

> I think having the documentation indicate that a value of zero indicates no specific alignment requirements is still correct as the Operation's alignment field is still an integer (when present) and it being zero would still signifies no specific alignment requirements.

I've just realised that we no longer support `{ alignment = 0 }`. Take this example:
```mlir
func.func @load_with_alignment(%memref : memref<200x100xf32>, %i : index, %j : index) -> vector<8xf32> {
  %0 = vector.load %memref[%i, %j] { alignment = 0 } : memref<200x100xf32>, vector<8xf32>
  return %0 : vector<8xf32>
}
```

Now:
```bash
$ bin/mlir-opt temp.mlir
temp.mlir:2:36: error: custom op 'vector.load' 'vector.load' op attribute 'alignment' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive and whose value is a power of two > 0
  %0 = vector.load %memref[%i, %j] { alignment = 0 } : memref<200x100xf32>, vector<8xf32>
                                   ^
```

So, zero-alignment is no longer valid :) This makes sense to me - otherwise `0` was some magic value with some magic meaning. 

To me, all of this calls for a few updates:
* **Docs**, i.e. this is no longer correct: "A value of 0 indicates no specific alignment requirement." 
* **Tests** (in invalid.mlir, lets check `alignemt = 0`).
* **Predicates** - can we update [this](https://github.com/llvm/llvm-project/blob/1945753700dc9e1ba526cc2078296518b7c93e8c/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td#L1724-L1725) with some alignment-specific predicate? ([VectorOfNonZeroRankOf](https://github.com/llvm/llvm-project/blob/1945753700dc9e1ba526cc2078296518b7c93e8c/mlir/include/mlir/IR/CommonTypeConstraints.td#L436-L438) is a nice example of a self-descriptive constraint).

WDYT?

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


More information about the Mlir-commits mailing list