[Mlir-commits] [mlir] [mlir] Check if the stride tensor is empty. (PR #76428)

Balaji V. Iyer. llvmlistbot at llvm.org
Wed Dec 27 15:40:15 PST 2023


https://github.com/bviyer updated https://github.com/llvm/llvm-project/pull/76428

>From dd5d9f8fdf36e26b16b48297a8810068f81a2583 Mon Sep 17 00:00:00 2001
From: "Balaji V. Iyer." <43187390+bviyer at users.noreply.github.com>
Date: Wed, 27 Dec 2023 06:34:28 +0000
Subject: [PATCH 1/2] [mlir] Check if the stride tensor is empty.

Added a check to see if the stride tensor is empty. If so then
return false for isContiguousSlice function.

Possible fix for #74463
---
 mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp b/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp
index 2ad992af989c96..c1c0f5483a6af5 100644
--- a/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp
+++ b/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp
@@ -271,7 +271,7 @@ bool vector::isContiguousSlice(MemRefType memrefType, VectorType vectorType) {
     return false;
 
   // Cond 1: A contiguous memref will always have a unit trailing stride.
-  if (strides.back() != 1)
+  if (strides.empty() || strides.back() != 1)
     return false;
 
   // Cond 2: Strides of a contiguous memref have to match the flattened dims.

>From 125d9197a7f2f53a09bc1515e81baef5e68075a2 Mon Sep 17 00:00:00 2001
From: "Balaji V. Iyer" <bviyer at gmail.com>
Date: Wed, 27 Dec 2023 17:39:54 -0600
Subject: [PATCH 2/2] Added a test case

---
 .../test/Dialect/Vector/vector-transfer-flatten.mlir | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/mlir/test/Dialect/Vector/vector-transfer-flatten.mlir b/mlir/test/Dialect/Vector/vector-transfer-flatten.mlir
index 3708d741141be0..67adea90d7be95 100644
--- a/mlir/test/Dialect/Vector/vector-transfer-flatten.mlir
+++ b/mlir/test/Dialect/Vector/vector-transfer-flatten.mlir
@@ -356,3 +356,15 @@ func.func @fold_unit_dims_entirely(%arg0 : vector<8xi32>,
 // CHECK:           %[[VAL_3:.*]] = arith.muli %[[VAL_0]], %[[VAL_1]] : vector<8xi32>
 // CHECK:           %[[VAL_4:.*]] = arith.addi %[[VAL_3]], %[[VAL_2]] : vector<8xi32>
 // CHECK:           return %[[VAL_4]] : vector<8xi32>
+
+// -----
+
+// This test is to make sure there is no crash for empty stride.
+func.func @stride_empty_crash(%1: memref<i16>) -> vector<32x256xi16> {
+  %c0_i16 = arith.constant 0 : i16
+  %3 = vector.transfer_read %1[], %c0_i16 {permutation_map = affine_map<() -> (0, 0)>} : memref<i16>, vector<32x256xi16>
+  return %3 : vector<32x256xi16>
+
+  // CHECK-LABEL: func.func @stride_empty_crash
+  // CHECK: %c0_i16 = arith.constant 0 : i16
+}



More information about the Mlir-commits mailing list