[Mlir-commits] [mlir] [mlir][vector][memref] Add `alignment` attribute to memory access ops (PR #144344)

Andrzej WarzyƄski llvmlistbot at llvm.org
Thu Jul 17 01:46:10 PDT 2025


================
@@ -962,6 +962,24 @@ func.func @test_store_zero_results2(%x: i32, %p: memref<i32>) {
 
 // -----
 
+func.func @negative_load_alignment(%memref: memref<4xi32>) {
+  %c0 = arith.constant 0 : index
+  // expected-error @below {{'memref.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}}
+  %val = memref.load %memref[%c0] { alignment = -1 } : memref<4xi32>
+  return
+}
+
+// -----
+
+func.func @non_power_of_2_store_alignment(%memref: memref<4xi32>, %val: i32) {
+  %c0 = arith.constant 0 : index
+  // expected-error @below {{'memref.store' 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}}
+  memref.store %val, %memref[%c0] { alignment = 3 } : memref<4xi32>
+  return
+}
----------------
banach-space wrote:

[nit] Please use consistent naming
```suggestion
func.func @non_power_of_2_load_alignment(%memref: memref<4xi32>) {
  %c0 = arith.constant 0 : index
  // expected-error @below {{'memref.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}}
  %val = memref.load %memref[%c0] { alignment = -1 } : memref<4xi32>
  return
}

// -----

func.func @non_power_of_2_store_alignment(%memref: memref<4xi32>, %val: i32) {
  %c0 = arith.constant 0 : index
  // expected-error @below {{'memref.store' 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}}
  memref.store %val, %memref[%c0] { alignment = 3 } : memref<4xi32>
  return
}
```

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


More information about the Mlir-commits mailing list