[Mlir-commits] [mlir] [mlir] Fix StridedMemRefRankOf to check isStrided() (PR #201415)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Jun 4 06:14:02 PDT 2026


https://github.com/ConvolutedDog updated https://github.com/llvm/llvm-project/pull/201415

>From 633778c6dfe97625b8f426b3a3f991cf0c0209ff Mon Sep 17 00:00:00 2001
From: ConvolutedDog <yangjianchao16 at nudt.edu.cn>
Date: Thu, 4 Jun 2026 01:13:55 +0800
Subject: [PATCH 1/2] [mlir] Fix StridedMemRefRankOf to check isStrided()

StridedMemRefRankOf was equivalent to MemRefRankOf: it only applied HasAnyRankOfPred and never HasStridesPred, so non-strided memref layouts (e.g. multi-result affine maps) incorrectly passed ODS verification on ops using this constraint (e.g. sparse_tensor.push_back).
---
 mlir/include/mlir/IR/CommonTypeConstraints.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/IR/CommonTypeConstraints.td b/mlir/include/mlir/IR/CommonTypeConstraints.td
index d8615a4730c32..54d0918ce8d32 100644
--- a/mlir/include/mlir/IR/CommonTypeConstraints.td
+++ b/mlir/include/mlir/IR/CommonTypeConstraints.td
@@ -930,7 +930,7 @@ class AnyStridedMemRefOfRank<int rank> :
        AnyStridedMemRef.summary # " of rank " # rank>;
 
 class StridedMemRefRankOf<list<Type> allowedTypes, list<int> ranks> :
-    ConfinedType<MemRefOf<allowedTypes>, [HasAnyRankOfPred<ranks>],
+    ConfinedType<MemRefOf<allowedTypes>, [HasAnyRankOfPred<ranks>, HasStridesPred],
          !interleave(!foreach(rank, ranks, rank # "D"), "/") # " " #
          MemRefOf<allowedTypes>.summary>;
 

>From c311c6ec58a7836f2da9bdd7654d1fd439fd13cc Mon Sep 17 00:00:00 2001
From: ConvolutedDog <yangjianchao16 at nudt.edu.cn>
Date: Thu, 4 Jun 2026 01:18:24 +0800
Subject: [PATCH 2/2] Add invalid ir of non-strided push_back

The inBuffer of push_back uses StridedMemRefRankOf, which requires a strided memref layout (HasStridesPred). A non-strided layout must be rejected.
---
 mlir/test/Dialect/SparseTensor/invalid.mlir | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mlir/test/Dialect/SparseTensor/invalid.mlir b/mlir/test/Dialect/SparseTensor/invalid.mlir
index d14229b011f11..338c7269f336e 100644
--- a/mlir/test/Dialect/SparseTensor/invalid.mlir
+++ b/mlir/test/Dialect/SparseTensor/invalid.mlir
@@ -307,6 +307,14 @@ func.func @sparse_push_back_n(%arg0: index, %arg1: memref<?xf32>, %arg2: f32) ->
 
 // -----
 
+func.func @sparse_push_back_non_strided(%arg0: index, %arg1: memref<?xf64, affine_map<(d0) -> (d0 mod 2)>>, %arg2: f64) {
+  // expected-error at +1 {{'sparse_tensor.push_back' op operand #1 must be 1D memref of any type values, but got 'memref<?xf64, affine_map<(d0) -> (d0 mod 2)>>'}}
+  %0:2 = sparse_tensor.push_back %arg0, %arg1, %arg2 : index, memref<?xf64, affine_map<(d0) -> (d0 mod 2)>>, f64
+  return
+}
+
+// -----
+
 func.func @sparse_unannotated_expansion(%arg0: tensor<128xf64>) {
   // expected-error at +1 {{'sparse_tensor.expand' op operand #0 must be sparse tensor of any non-token type values, but got 'tensor<128xf64>'}}
   %values, %filled, %added, %count = sparse_tensor.expand %arg0



More information about the Mlir-commits mailing list