[PATCH] D76349: [mlir] vector.type_cast: disallow memrefs with layout in verifier

Alex Zinenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 18 03:14:02 PDT 2020


ftynse created this revision.
ftynse added a reviewer: nicolasvasilache.
Herald added subscribers: llvm-commits, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, antiagainst, shauheen, burmako, jpienaar, rriddle, mehdi_amini.
Herald added a reviewer: aartbik.
Herald added a project: LLVM.

These are not supported by any of the code using `type_cast`. In the general
case, such casting would require memrefs to handle a non-contiguous vector
representation or misaligned vectors (e.g., if the offset of the source memref
is not divisible by vector size, since offset in the target memref is expressed
in the number of elements).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76349

Files:
  mlir/lib/Dialect/VectorOps/VectorOps.cpp
  mlir/test/Dialect/VectorOps/invalid.mlir


Index: mlir/test/Dialect/VectorOps/invalid.mlir
===================================================================
--- mlir/test/Dialect/VectorOps/invalid.mlir
+++ mlir/test/Dialect/VectorOps/invalid.mlir
@@ -1046,3 +1046,10 @@
   // expected-error at +1 {{'vector.reduction' op unsupported reduction rank: 2}}
   %0 = vector.reduction "add", %arg0 : vector<4x16xf32> into f32
 }
+
+// -----
+
+func @type_cast_layout(%arg0: memref<4x3xf32, affine_map<(d0, d1)[s0, s1, s2] -> (d0 * s0 + d1 * s1 + s2)>>) {
+  // expected-error at +1 {{expects operand to be a memref with no layout}}
+  %0 = vector.type_cast %arg0: memref<4x3xf32, affine_map<(d0, d1)[s0, s1, s2] -> (d0 * s0 + d1 * s1 + s2)>> to memref<vector<4x3xf32>>
+}
Index: mlir/lib/Dialect/VectorOps/VectorOps.cpp
===================================================================
--- mlir/lib/Dialect/VectorOps/VectorOps.cpp
+++ mlir/lib/Dialect/VectorOps/VectorOps.cpp
@@ -1483,6 +1483,10 @@
 }
 
 static LogicalResult verify(TypeCastOp op) {
+  MemRefType canonicalType = canonicalizeStridedLayout(op.getMemRefType());
+  if (!canonicalType.getAffineMaps().empty())
+    return op.emitOpError("expects operand to be a memref with no layout");
+
   auto resultType = inferVectorTypeCastResultType(op.getMemRefType());
   if (op.getResultMemRefType() != resultType)
     return op.emitOpError("expects result type to be: ") << resultType;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76349.251026.patch
Type: text/x-patch
Size: 1393 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200318/44c3abe6/attachment-0001.bin>


More information about the llvm-commits mailing list