forked from OSchip/llvm-project
[mlir] : Fix ViewOp shape folder for identity affine maps
Summary: Fix the ViewOpShapeFolder in case of no affine mapping associated with a Memref construct identity mapping. Reviewers: nicolasvasilache Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72735
This commit is contained in:
parent
ab9aefee9f
commit
ab03564706
|
@ -2433,9 +2433,12 @@ struct ViewOpShapeFolder : public OpRewritePattern<ViewOp> {
|
|||
|
||||
// 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;
|
||||
|
|
|
@ -692,6 +692,7 @@ func @cast_values(%arg0: tensor<*xi32>, %arg1: memref<?xi32>) -> (tensor<2xi32>,
|
|||
// 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 @@ func @view(%arg0 : index) {
|
|||
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>
|
||||
|
|
Loading…
Reference in New Issue