[PATCH] D72735: [mlir] : Fix ViewOp shape folder for identity affine maps
Ahmed S. Taei via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 14 13:28:36 PST 2020
asaadaldien created this revision.
asaadaldien added a reviewer: nicolasvasilache.
Herald added subscribers: llvm-commits, liufengdb, lucyrfox, mgester, arpith-jacob, antiagainst, shauheen, burmako, jpienaar, rriddle, mehdi_amini.
Herald added a project: LLVM.
Fix the ViewOpShapeFolder in case of no affine mapping associated with a Memref construct identity mapping.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D72735
Files:
mlir/lib/Dialect/StandardOps/Ops.cpp
mlir/test/Transforms/canonicalize.mlir
Index: mlir/test/Transforms/canonicalize.mlir
===================================================================
--- mlir/test/Transforms/canonicalize.mlir
+++ mlir/test/Transforms/canonicalize.mlir
@@ -692,6 +692,7 @@
// CHECK-DAG: #[[VIEW_MAP2:map[0-9]+]] = affine_map<(d0, d1)[s0] -> (d0 * s0 + d1 + 15)>
// CHECK-DAG: #[[VIEW_MAP3:map[0-9]+]] = affine_map<(d0, d1, d2)[s0] -> (d0 * s0 + d1 * 7 + d2)>
// CHECK-DAG: #[[VIEW_MAP4:map[0-9]+]] = affine_map<(d0, d1) -> (d0 * 4 + d1 + 15)>
+// CHECK-DAG: #[[VIEW_MAP5:map[0-9]+]] = affine_map<(d0, d1) -> (d0 * 7 + d1)>
// CHECK-LABEL: func @view
func @view(%arg0 : index) {
@@ -736,7 +737,7 @@
load %5[%c0, %c0] : memref<?x4xf32, #TEST_VIEW_MAP2>
// Test: folding static alloc and memref_cast into a view.
- // CHECK: std.view %[[ALLOC_MEM]][][%c15, %c7] : memref<2048xi8> to memref<?x?xf32>
+ // CHECK: std.view %[[ALLOC_MEM]][][] : memref<2048xi8> to memref<15x7xf32, #[[VIEW_MAP5]]>
%6 = memref_cast %0 : memref<2048xi8> to memref<?xi8>
%7 = view %6[%c15][%c7] : memref<?xi8> to memref<?x?xf32>
load %7[%c0, %c0] : memref<?x?xf32>
Index: mlir/lib/Dialect/StandardOps/Ops.cpp
===================================================================
--- mlir/lib/Dialect/StandardOps/Ops.cpp
+++ mlir/lib/Dialect/StandardOps/Ops.cpp
@@ -2433,9 +2433,12 @@
// Get result memref type.
auto memrefType = viewOp.getType();
- if (memrefType.getAffineMaps().size() != 1)
+ if (memrefType.getAffineMaps().size() > 1)
return matchFailure();
- auto map = memrefType.getAffineMaps()[0];
+ auto map = memrefType.getAffineMaps().empty()
+ ? AffineMap::getMultiDimIdentityMap(memrefType.getRank(),
+ rewriter.getContext())
+ : memrefType.getAffineMaps()[0];
// Get offset from old memref view type 'memRefType'.
int64_t oldOffset;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72735.238088.patch
Type: text/x-patch
Size: 1923 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200114/c7b566e2/attachment.bin>
More information about the llvm-commits
mailing list