[Mlir-commits] [mlir] [mlir][memref] Keep alignment and invariant in memref-emulate-wide-int (PR #221320)

Hung-Kuan Tseng llvmlistbot at llvm.org
Fri Sep 4 11:52:07 PDT 2026


https://github.com/Tim096 created https://github.com/llvm/llvm-project/pull/221320

`ConvertMemRefLoad` and `ConvertMemRefStore` forward `nontemporal` to the
rebuilt op but not `alignment`, nor `invariant` on the load; both
attributes were added after the pass:

```mlir
%v = memref.load %m[%c0] alignment(16) nontemporal(true) invariant(true) : memref<4xi64, 1>
// -memref-emulate-wide-int today
%v = memref.load %m[%c0] nontemporal(true) : memref<4xvector<2xi32>, 1>
```

The emulated memref has the same byte layout as the original (`iN` becomes
`vector<2xiN/2>`), so the same index names the same address and the
attributes still describe the access. This forwards all of them through
the attribute builder, next to the existing `nontemporal`.

Tests: one load/store case with all attributes, mirroring the existing
`@alloc_load_store_i64_nontemporal`.


>From 7b2fa9a7332776ed6e2a8b1d73bbc441d3440ef8 Mon Sep 17 00:00:00 2001
From: Hung-Kuan Tseng <tseng.tim096 at gmail.com>
Date: Sat, 5 Sep 2026 02:51:53 +0800
Subject: [PATCH] [mlir][memref] Keep alignment and invariant in
 memref-emulate-wide-int

`ConvertMemRefLoad` and `ConvertMemRefStore` forward `nontemporal` to
the rebuilt op but not `alignment`, nor `invariant` on the load; both
attributes were added after the pass:

  %v = memref.load %m[%c0] alignment(16) nontemporal(true) invariant(true) : memref<4xi64, 1>
  // -memref-emulate-wide-int today
  %v = memref.load %m[%c0] nontemporal(true) : memref<4xvector<2xi32>, 1>

The emulated memref has the same byte layout, so the same index names
the same address. Forward all the attributes.
---
 .../MemRef/Transforms/EmulateWideInt.cpp        |  4 ++--
 mlir/test/Dialect/MemRef/emulate-wide-int.mlir  | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp b/mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp
index 6f815ae46904c..fb5f36e9a4920 100644
--- a/mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp
+++ b/mlir/lib/Dialect/MemRef/Transforms/EmulateWideInt.cpp
@@ -68,7 +68,7 @@ struct ConvertMemRefLoad final : OpConversionPattern<memref::LoadOp> {
 
     rewriter.replaceOpWithNewOp<memref::LoadOp>(
         op, newResTy, adaptor.getMemref(), adaptor.getIndices(),
-        op.getNontemporal());
+        op.getNontemporalAttr(), op.getAlignmentAttr(), op.getInvariantAttr());
     return success();
   }
 };
@@ -91,7 +91,7 @@ struct ConvertMemRefStore final : OpConversionPattern<memref::StoreOp> {
 
     rewriter.replaceOpWithNewOp<memref::StoreOp>(
         op, adaptor.getValue(), adaptor.getMemref(), adaptor.getIndices(),
-        op.getNontemporal());
+        op.getNontemporalAttr(), op.getAlignmentAttr());
     return success();
   }
 };
diff --git a/mlir/test/Dialect/MemRef/emulate-wide-int.mlir b/mlir/test/Dialect/MemRef/emulate-wide-int.mlir
index cad9ae334fb63..175058e58878e 100644
--- a/mlir/test/Dialect/MemRef/emulate-wide-int.mlir
+++ b/mlir/test/Dialect/MemRef/emulate-wide-int.mlir
@@ -69,6 +69,23 @@ func.func @alloc_load_store_i64_nontemporal() {
 
 // -----
 
+// CHECK-LABEL: func @alloc_load_store_i64_attrs
+// CHECK:         [[C1:%.+]] = arith.constant dense<[1, 0]> : vector<2xi32>
+// CHECK-NEXT:    [[M:%.+]]  = memref.alloc() : memref<4xvector<2xi32>, 1>
+// CHECK-NEXT:    [[V:%.+]]  = memref.load [[M]][{{%.+}}] alignment(16) nontemporal(true) invariant(true) : memref<4xvector<2xi32>, 1>
+// CHECK-NEXT:    memref.store [[C1]], [[M]][{{%.+}}] alignment(16) nontemporal(true) : memref<4xvector<2xi32>, 1>
+// CHECK-NEXT:    return
+func.func @alloc_load_store_i64_attrs() {
+    %c0 = arith.constant 0 : index
+    %c1 = arith.constant 1 : i64
+    %m = memref.alloc() : memref<4xi64, 1>
+    %v = memref.load %m[%c0] alignment(16) nontemporal(true) invariant(true) : memref<4xi64, 1>
+    memref.store %c1, %m[%c0] alignment(16) nontemporal(true) : memref<4xi64, 1>
+    return
+}
+
+// -----
+
 // Make sure we do not crash on unsupported types.
 func.func @alloc_i128() {
   // expected-error at +1 {{failed to legalize operation 'memref.alloc' that was explicitly marked illegal}}



More information about the Mlir-commits mailing list