Skip to content

Commit f4eb681

Browse files
author
MaheshRavishankar
committed
[mlir][Linalg] Drop unit-trip loops of reductions only if other reduction loops exists.
Recent change enable dropping unit-trip loops of "reduction" iterator type as well. This is fine as long as there is one other "reduction" iterator in the operation. Without this the initialized value (value of `out`) is not read which leads to a correctness issue. Also fix a bug in the `fill` -> `tensor_reshape` folding. The `out` operand of the `fill` needs to be reshaped to get the `out` operand of the generated `fill` operation. Differential Revision: https://reviews.llvm.org/D100145
1 parent 097d77d commit f4eb681

6 files changed

Lines changed: 196 additions & 40 deletions

File tree

‎mlir/include/mlir/Dialect/Linalg/Passes.td‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def LinalgFoldUnitExtentDims : FunctionPass<"linalg-fold-unit-extent-dims"> {
3131
"Only folds the one-trip loops from Linalg ops on tensors "
3232
"(for testing purposes only)">
3333
];
34-
let dependentDialects = ["linalg::LinalgDialect"];
34+
let dependentDialects = [
35+
"linalg::LinalgDialect", "AffineDialect", "memref::MemRefDialect"
36+
];
3537
}
3638

3739
def LinalgFusionOfTensorOps : Pass<"linalg-fusion-for-tensor-ops"> {
@@ -43,15 +45,17 @@ def LinalgFusionOfTensorOps : Pass<"linalg-fusion-for-tensor-ops"> {
4345
"Allow fusing linalg.tensor_reshape ops that performs unit "
4446
"dimension collapsing">
4547
];
46-
let dependentDialects = ["linalg::LinalgDialect", "AffineDialect"];
48+
let dependentDialects = [
49+
"AffineDialect", "linalg::LinalgDialect", "memref::MemRefDialect"
50+
];
4751
}
4852

4953
def LinalgFoldReshapeOpsByLinearization :
5054
Pass<"linalg-fold-reshape-ops-by-linearization"> {
5155
let summary = "Fold TensorReshapeOps with generic/indexed generic ops by "
5256
"linearization";
5357
let constructor = "mlir::createFoldReshapeOpsByLinearizationPass()";
54-
let dependentDialects = ["AffineDialect"];
58+
let dependentDialects = ["AffineDialect", "memref::MemRefDialect"];
5559
}
5660

5761
def LinalgLowerToAffineLoops : FunctionPass<"convert-linalg-to-affine-loops"> {
@@ -64,7 +68,8 @@ def LinalgLowerToAffineLoops : FunctionPass<"convert-linalg-to-affine-loops"> {
6468
"interchange vector",
6569
"llvm::cl::ZeroOrMore, llvm::cl::MiscFlags::CommaSeparated">
6670
];
67-
let dependentDialects = ["linalg::LinalgDialect", "AffineDialect"];
71+
let dependentDialects = [
72+
"AffineDialect", "linalg::LinalgDialect", "memref::MemRefDialect"];
6873
}
6974

7075
def LinalgLowerToLoops : FunctionPass<"convert-linalg-to-loops"> {

‎mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,9 +1681,10 @@ struct FoldFillWithTensorReshape : OpRewritePattern<TensorReshapeOp> {
16811681
if (!oldFill)
16821682
return failure();
16831683

1684-
auto newInit = rewriter.create<InitTensorOp>(
1685-
oldFill.getLoc(), reshapeOp.getResultType().getShape(),
1686-
reshapeOp.getResultType().getElementType());
1684+
Location loc = oldFill.getLoc();
1685+
auto newInit = rewriter.create<TensorReshapeOp>(
1686+
loc, reshapeOp.getResultType(), oldFill.output(),
1687+
reshapeOp.reassociation());
16871688
rewriter.replaceOpWithNewOp<FillOp>(reshapeOp, newInit, oldFill.value());
16881689

16891690
return success();
@@ -1694,7 +1695,8 @@ struct FoldFillWithTensorReshape : OpRewritePattern<TensorReshapeOp> {
16941695
void TensorReshapeOp::getCanonicalizationPatterns(RewritePatternSet &results,
16951696
MLIRContext *context) {
16961697
results.add<CollapseReshapeOps<TensorReshapeOp>, FoldFillWithTensorReshape,
1697-
FoldReshapeWithConstant>(context);
1698+
FoldInitTensorWithTensorReshapeOp, FoldReshapeWithConstant>(
1699+
context);
16981700
}
16991701

17001702
LogicalResult TensorReshapeOp::reifyReturnTypeShapesPerResultDim(

‎mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,43 @@ struct FoldUnitDimLoops : public OpRewritePattern<GenericOpTy> {
190190
SmallVector<int64_t, 4> dims;
191191
for (ShapedType shapedType : op.getShapedOperandTypes())
192192
dims.append(shapedType.getShape().begin(), shapedType.getShape().end());
193+
194+
// Find all the reduction iterators. Those need some special consideration
195+
// (see below).
196+
auto getLoopDimsOfType =
197+
[&](StringRef iteratorTypeName) -> SmallVector<unsigned, 4> {
198+
SmallVector<AffineExpr> dimExprs;
199+
getDimsOfType(op, iteratorTypeName, dimExprs);
200+
return llvm::to_vector<4>(llvm::map_range(dimExprs, [](AffineExpr expr) {
201+
return expr.cast<AffineDimExpr>().getPosition();
202+
}));
203+
};
204+
auto reductionDims = getLoopDimsOfType(getReductionIteratorTypeName());
205+
193206
DenseSet<unsigned> unitDims;
207+
SmallVector<unsigned, 4> unitDimsReductionLoops;
194208
ArrayAttr iteratorTypes = op.iterator_types();
195209
for (auto expr : enumerate(invertedMap.getResults())) {
196210
if (AffineDimExpr dimExpr = expr.value().dyn_cast<AffineDimExpr>())
197-
if (dims[dimExpr.getPosition()] == 1 &&
198-
iteratorTypes[expr.index()].dyn_cast<StringAttr>().getValue() ==
199-
getParallelIteratorTypeName())
200-
unitDims.insert(expr.index());
211+
if (dims[dimExpr.getPosition()] == 1) {
212+
if (isParallelIterator(iteratorTypes[expr.index()]))
213+
unitDims.insert(expr.index());
214+
else if (isReductionIterator(iteratorTypes[expr.index()]))
215+
unitDimsReductionLoops.push_back(expr.index());
216+
}
201217
}
218+
219+
// Reduction loops can be dropped if there is at least one other reduction
220+
// loop that is not dropped. This accounts for the initial value read in the
221+
// reduction loop.
222+
if (!unitDimsReductionLoops.empty() && reductionDims.size() > 1) {
223+
if (unitDimsReductionLoops.size() == reductionDims.size())
224+
unitDims.insert(reductionDims.begin(), std::prev(reductionDims.end()));
225+
else
226+
unitDims.insert(unitDimsReductionLoops.begin(),
227+
unitDimsReductionLoops.end());
228+
}
229+
202230
if (unitDims.empty())
203231
return failure();
204232

@@ -293,7 +321,6 @@ struct ReplaceUnitExtentTensors : public OpRewritePattern<GenericOpTy> {
293321
using OpRewritePattern<GenericOpTy>::OpRewritePattern;
294322
LogicalResult matchAndRewrite(GenericOpTy op,
295323
PatternRewriter &rewriter) const override {
296-
// TODO: support reductions.
297324
if (!op.hasTensorSemantics())
298325
return failure();
299326

@@ -565,7 +592,6 @@ void mlir::linalg::populateFoldUnitExtentDimsPatterns(
565592
ReplaceUnitExtentTensors<IndexedGenericOp>>(context);
566593
TensorReshapeOp::getCanonicalizationPatterns(patterns, context);
567594
patterns.add<FoldReshapeOpWithUnitExtent>(context);
568-
populateFoldUnitDimsReshapeOpsByLinearizationPatterns(patterns);
569595
}
570596

571597
namespace {

‎mlir/test/Dialect/Linalg/canonicalize.mlir‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,23 @@ func @fold_fill_reshape() -> tensor<6x4xf32> {
827827

828828
// -----
829829

830+
// CHECK: func @fold_fill_reshape_dynamic
831+
// CHECK-SAME: %[[ARG0:.+]]: tensor<?x?x?x?x?xf32>
832+
func @fold_fill_reshape_dynamic(%arg0 : tensor<?x?x?x?x?xf32>) -> tensor<?x?xf32> {
833+
%zero = constant 0.0 : f32
834+
// CHECK: %[[RESHAPE:.+]] = linalg.tensor_reshape %[[ARG0]]
835+
%0 = linalg.fill(%arg0, %zero) : tensor<?x?x?x?x?xf32>, f32 -> tensor<?x?x?x?x?xf32>
836+
// CHECK: %[[RESULT:.+]] = linalg.fill(%[[RESHAPE]], %{{.+}})
837+
%1 = linalg.tensor_reshape %0
838+
[affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2)>,
839+
affine_map<(d0, d1, d2, d3, d4) -> (d3, d4)>]
840+
: tensor<?x?x?x?x?xf32> into tensor<?x?xf32>
841+
// CHECK: return %[[RESULT]]
842+
return %1 : tensor<?x?xf32>
843+
}
844+
845+
// -----
846+
830847
#map0 = affine_map<(d0) -> (24, -d0 + 192)>
831848
#map1 = affine_map<(d0, d1)[s0] -> (d0 * 192 + s0 + d1)>
832849
#map2 = affine_map<(d0) -> (16, -d0 + 192)>

‎mlir/test/Dialect/Linalg/drop-unit-extent-dims.mlir‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,113 @@ func @no_fold_subtensor(
456456
// CHECK: %[[RESULT_RESHAPE:.+]] = linalg.tensor_reshape %[[SUBTENSOR]]
457457
// CHECK-SAME: [#[[MAP0]], #[[MAP1]], #[[MAP2]], #[[MAP3]], #[[MAP4]], #[[MAP5]]]
458458
// CHECK: return %[[RESULT_RESHAPE]]
459+
460+
// -----
461+
462+
func @unit_dim_for_reduction(%arg0: tensor<1x?x1x?xf32>) -> tensor<1x?xf32> {
463+
%cst = constant 1.000000e+00 : f32
464+
%c3 = constant 3 : index
465+
%0 = memref.dim %arg0, %c3 : tensor<1x?x1x?xf32>
466+
%1 = linalg.init_tensor [1, %0] : tensor<1x?xf32>
467+
%2 = linalg.fill(%1, %cst) : tensor<1x?xf32>, f32 -> tensor<1x?xf32>
468+
%3 = linalg.generic {
469+
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>,
470+
affine_map<(d0, d1, d2, d3) -> (d0, d1)>],
471+
iterator_types = ["parallel", "parallel", "reduction", "reduction"]}
472+
ins(%arg0 : tensor<1x?x1x?xf32>)
473+
outs(%2 : tensor<1x?xf32>) {
474+
^bb0(%arg1: f32, %arg2: f32): // no predecessors
475+
%4 = addf %arg1, %arg2 : f32
476+
linalg.yield %4 : f32
477+
} -> tensor<1x?xf32>
478+
return %3 : tensor<1x?xf32>
479+
}
480+
// CHECK-DAG: #[[MAP0:.+]] = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2)>
481+
// CHECK-DAG: #[[MAP1:.+]] = affine_map<(d0, d1, d2, d3) -> (d3)>
482+
// CHECK-DAG: #[[MAP2:.+]] = affine_map<(d0, d1) -> (d0, d1)>
483+
// CHECK-DAG: #[[MAP3:.+]] = affine_map<(d0, d1) -> (d0)>
484+
// CHECK: func @unit_dim_for_reduction
485+
// CHECK-SAME: %[[ARG0:.+]]: tensor<1x?x1x?xf32>
486+
// CHECK-DAG: %[[RESHAPE:.+]] = linalg.tensor_reshape %[[ARG0]] [#[[MAP0]], #[[MAP1]]]
487+
// CHECK: %[[INIT:.+]] = linalg.init_tensor [%{{.+}}] : tensor<?xf32>
488+
// CHECK: %[[FILL:.+]] = linalg.fill(%[[INIT]], %{{.+}})
489+
// CHECK: %[[RESULT:.+]] = linalg.generic
490+
// CHECK-SAME: indexing_maps = [#[[MAP2]], #[[MAP3]]]
491+
// CHECK-SAME: iterator_types = ["parallel", "reduction"]
492+
// CHECK-SAME: ins(%[[RESHAPE]] : tensor<?x?xf32>)
493+
// CHECK-SAME: outs(%[[FILL]] : tensor<?xf32>)
494+
// CHECK: %[[RESULT_RESHAPE:.+]] = linalg.tensor_reshape %[[RESULT]] [#[[MAP2]]]
495+
// CHECK: return %[[RESULT_RESHAPE]]
496+
497+
// -----
498+
499+
func @unit_dim_for_reduction_keep_one(%arg0: tensor<1x?x1x1xf32>) -> tensor<1x1xf32> {
500+
%cst = constant 1.000000e+00 : f32
501+
%c3 = constant 3 : index
502+
%1 = linalg.init_tensor [1, 1] : tensor<1x1xf32>
503+
%2 = linalg.fill(%1, %cst) : tensor<1x1xf32>, f32 -> tensor<1x1xf32>
504+
%3 = linalg.generic {
505+
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>,
506+
affine_map<(d0, d1, d2, d3) -> (d0, d1)>],
507+
iterator_types = ["parallel", "parallel", "reduction", "reduction"]}
508+
ins(%arg0 : tensor<1x?x1x1xf32>)
509+
outs(%2 : tensor<1x1xf32>) {
510+
^bb0(%arg1: f32, %arg2: f32): // no predecessors
511+
%4 = addf %arg1, %arg2 : f32
512+
linalg.yield %4 : f32
513+
} -> tensor<1x1xf32>
514+
return %3 : tensor<1x1xf32>
515+
}
516+
// CHECK-DAG: #[[MAP0:.+]] = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2)>
517+
// CHECK-DAG: #[[MAP1:.+]] = affine_map<(d0, d1, d2, d3) -> (d3)>
518+
// CHECK-DAG: #[[MAP2:.+]] = affine_map<(d0, d1) -> (d0, d1)>
519+
// CHECK-DAG: #[[MAP3:.+]] = affine_map<(d0, d1) -> (d0)>
520+
// CHECK: func @unit_dim_for_reduction_keep_one
521+
// CHECK-SAME: %[[ARG0:.+]]: tensor<1x?x1x1xf32>
522+
// CHECK-DAG: %[[RESHAPE:.+]] = linalg.tensor_reshape %[[ARG0]] [#[[MAP0]], #[[MAP1]]]
523+
// CHECK: %[[INIT:.+]] = linalg.init_tensor [1] : tensor<1xf32>
524+
// CHECK: %[[FILL:.+]] = linalg.fill(%[[INIT]], %{{.+}})
525+
// CHECK: %[[RESULT:.+]] = linalg.generic
526+
// CHECK-SAME: indexing_maps = [#[[MAP2]], #[[MAP3]]]
527+
// CHECK-SAME: iterator_types = ["parallel", "reduction"]
528+
// CHECK-SAME: ins(%[[RESHAPE]] : tensor<?x1xf32>)
529+
// CHECK-SAME: outs(%[[FILL]] : tensor<1xf32>)
530+
// CHECK: %[[RESULT_RESHAPE:.+]] = linalg.tensor_reshape %[[RESULT]] [#[[MAP2]]]
531+
// CHECK: return %[[RESULT_RESHAPE]]
532+
533+
// -----
534+
535+
func @unit_dim_for_reduction_inner(%arg0: tensor<?x1x?x1xf32>) -> tensor<?x1xf32> {
536+
%cst = constant 1.000000e+00 : f32
537+
%c2 = constant 2 : index
538+
%0 = memref.dim %arg0, %c2 : tensor<?x1x?x1xf32>
539+
%1 = linalg.init_tensor [%0, 1] : tensor<?x1xf32>
540+
%2 = linalg.fill(%1, %cst) : tensor<?x1xf32>, f32 -> tensor<?x1xf32>
541+
%3 = linalg.generic {
542+
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>,
543+
affine_map<(d0, d1, d2, d3) -> (d0, d1)>],
544+
iterator_types = ["parallel", "parallel", "reduction", "reduction"]}
545+
ins(%arg0 : tensor<?x1x?x1xf32>)
546+
outs(%2 : tensor<?x1xf32>) {
547+
^bb0(%arg1: f32, %arg2: f32): // no predecessors
548+
%4 = addf %arg1, %arg2 : f32
549+
linalg.yield %4 : f32
550+
} -> tensor<?x1xf32>
551+
return %3 : tensor<?x1xf32>
552+
}
553+
// CHECK-DAG: #[[MAP0:.+]] = affine_map<(d0, d1, d2, d3) -> (d0, d1)>
554+
// CHECK-DAG: #[[MAP1:.+]] = affine_map<(d0, d1, d2, d3) -> (d2, d3)>
555+
// CHECK-DAG: #[[MAP2:.+]] = affine_map<(d0, d1) -> (d0, d1)>
556+
// CHECK-DAG: #[[MAP3:.+]] = affine_map<(d0, d1) -> (d0)>
557+
// CHECK: func @unit_dim_for_reduction_inner
558+
// CHECK-SAME: %[[ARG0:.+]]: tensor<?x1x?x1xf32>
559+
// CHECK-DAG: %[[RESHAPE:.+]] = linalg.tensor_reshape %[[ARG0]] [#[[MAP0]], #[[MAP1]]]
560+
// CHECK: %[[INIT:.+]] = linalg.init_tensor [%{{.+}}] : tensor<?xf32>
561+
// CHECK: %[[FILL:.+]] = linalg.fill(%[[INIT]], %{{.+}})
562+
// CHECK: %[[RESULT:.+]] = linalg.generic
563+
// CHECK-SAME: indexing_maps = [#[[MAP2]], #[[MAP3]]]
564+
// CHECK-SAME: iterator_types = ["parallel", "reduction"]
565+
// CHECK-SAME: ins(%[[RESHAPE]] : tensor<?x?xf32>)
566+
// CHECK-SAME: outs(%[[FILL]] : tensor<?xf32>)
567+
// CHECK: %[[RESULT_RESHAPE:.+]] = linalg.tensor_reshape %[[RESULT]] [#[[MAP2]]]
568+
// CHECK: return %[[RESULT_RESHAPE]]

‎mlir/test/Dialect/Linalg/reshape_fusion.mlir‎

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,16 @@ func @generic_op_reshape_consumer_static(%arg0: tensor<264x4xf32>)
174174
// CHECK-DAG: #[[MAP2:.+]] = affine_map<(d0, d1, d2) -> (d0, d1, d2)>
175175
// CHECK: func @generic_op_reshape_consumer_static
176176
// CHECK-SAME: %[[ARG0:[a-zA-Z0-9_]+]]: tensor<264x4xf32>
177-
// CHECK: %[[T0:.+]] = linalg.init_tensor [264, 4]
178-
// CHECK: %[[T1:.+]] = linalg.tensor_reshape %[[ARG0]]
177+
// CHECK: %[[T0:.+]] = linalg.tensor_reshape %[[ARG0]]
179178
// CHECK-SAME: [#[[MAP0]], #[[MAP1]]]
180179
// CHECK-SAME: tensor<264x4xf32> into tensor<8x33x4xf32>
181-
// CHECK: %[[T2:.+]] = linalg.tensor_reshape %[[T0]]
182-
// CHECK-SAME: [#[[MAP0]], #[[MAP1]]]
183-
// CHECK: %[[T3:.+]] = linalg.generic
180+
// CHECK: %[[T1:.+]] = linalg.init_tensor [8, 33, 4]
181+
// CHECK: %[[T2:.+]] = linalg.generic
184182
// CHECK-SAME: indexing_maps = [#[[MAP2]], #[[MAP2]]]
185183
// CHECK-SAME: ["parallel", "parallel", "parallel"]
186-
// CHECK-SAME: ins(%[[T1]] : tensor<8x33x4xf32>)
187-
// CHECK-SAME: outs(%[[T2]] : tensor<8x33x4xf32>)
188-
// CHECK: return %[[T3]] : tensor<8x33x4xf32>
184+
// CHECK-SAME: ins(%[[T0]] : tensor<8x33x4xf32>)
185+
// CHECK-SAME: outs(%[[T1]] : tensor<8x33x4xf32>)
186+
// CHECK: return %[[T2]] : tensor<8x33x4xf32>
189187

190188
// -----
191189

@@ -317,36 +315,31 @@ func @reshape_as_consumer_permutation
317315
// CHECK-DAG: #[[MAP2:.+]] = affine_map<(d0, d1, d2, d3, d4, d5) -> (d5)>
318316
// CHECK-DAG: #[[MAP3:.+]] = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2)>
319317
// CHECK-DAG: #[[MAP4:.+]] = affine_map<(d0, d1, d2, d3) -> (d3)>
320-
// CHECK-DAG: #[[MAP5:.+]] = affine_map<(d0, d1, d2, d3, d4, d5) -> (d0, d1)>
321-
// CHECK-DAG: #[[MAP6:.+]] = affine_map<(d0, d1, d2, d3, d4, d5) -> (d2)>
322-
// CHECK-DAG: #[[MAP7:.+]] = affine_map<(d0, d1, d2, d3, d4, d5) -> (d3, d4, d5)>
323-
// CHECK-DAG: #[[MAP8:.+]] = affine_map<(d0, d1, d2, d3, d4, d5) -> (d2, d3, d4, d0, d1, d5)>
324-
// CHECK-DAG: #[[MAP9:.+]] = affine_map<(d0, d1, d2, d3, d4, d5) -> (d2, d3, d4, d5)>
325-
// CHECK-DAG: #[[MAP10:.+]] = affine_map<(d0, d1, d2, d3, d4, d5) -> (d0, d1, d5, d2, d3, d4)>
326-
// CHECK-DAG: #[[MAP11:.+]] = affine_map<(d0, d1) -> (d0 + d1 * 3)>
327-
// CHECK-DAG: #[[MAP12:.+]] = affine_map<(d0, d1, d2) -> (d0 + d1 * 7 + d2 * 42)>
318+
// CHECK-DAG: #[[MAP5:.+]] = affine_map<(d0, d1, d2, d3, d4, d5) -> (d2, d3, d4, d0, d1, d5)>
319+
// CHECK-DAG: #[[MAP6:.+]] = affine_map<(d0, d1, d2, d3, d4, d5) -> (d2, d3, d4, d5)>
320+
// CHECK-DAG: #[[MAP7:.+]] = affine_map<(d0, d1, d2, d3, d4, d5) -> (d0, d1, d5, d2, d3, d4)>
321+
// CHECK-DAG: #[[MAP8:.+]] = affine_map<(d0, d1) -> (d0 + d1 * 3)>
322+
// CHECK-DAG: #[[MAP9:.+]] = affine_map<(d0, d1, d2) -> (d0 + d1 * 7 + d2 * 42)>
328323
// CHECK: func @reshape_as_consumer_permutation
329324
// CHECK-SAME: %[[ARG0:.+]]: tensor<210x6x4xi32>
330325
// CHECK-SAME: %[[ARG1:.+]]: tensor<210x4xi32>
331-
// CHECK-DAG: %[[T0:.+]] = linalg.init_tensor [6, 4, 210]
332326
// CHECK-DAG: %[[T1:.+]] = linalg.tensor_reshape %[[ARG0]]
333327
// CHECK-SAME: [#[[MAP0]], #[[MAP1]], #[[MAP2]]]
334328
// CHECK-DAG: %[[T2:.+]] = linalg.tensor_reshape %[[ARG1]]
335329
// CHECK-SAME: [#[[MAP3]], #[[MAP4]]]
336-
// CHECK: %[[T3:.+]] = linalg.tensor_reshape %[[T0]]
337-
// CHECK-SAME: [#[[MAP5]], #[[MAP6]], #[[MAP7]]]
330+
// CHECK-DAG: %[[T0:.+]] = linalg.init_tensor [2, 3, 4, 5, 6, 7]
338331
// CHECK: %[[T4:.+]] = linalg.indexed_generic
339-
// CHECK-SAME: indexing_maps = [#[[MAP8]], #[[MAP9]], #[[MAP10]]]
332+
// CHECK-SAME: indexing_maps = [#[[MAP5]], #[[MAP6]], #[[MAP7]]]
340333
// CHECK-SAME: ins(%[[T1]], %[[T2]] : tensor<5x6x7x2x3x4xi32>, tensor<5x6x7x4xi32>)
341-
// CHECK-SAME: outs(%[[T3]] : tensor<2x3x4x5x6x7xi32>)
334+
// CHECK-SAME: outs(%[[T0]] : tensor<2x3x4x5x6x7xi32>)
342335
// CHECK: ^{{.+}}(
343336
// CHECK-SAME: %[[ARG2:[a-zA-Z0-9]+]]: index, %[[ARG3:[a-zA-Z0-9]+]]: index,
344337
// CHECK-SAME: %[[ARG4:[a-zA-Z0-9]+]]: index, %[[ARG5:[a-zA-Z0-9]+]]: index,
345338
// CHECK-SAME: %[[ARG6:[a-zA-Z0-9]+]]: index, %[[ARG7:[a-zA-Z0-9]+]]: index,
346339
// CHECK-SAME: %[[ARG8:[a-zA-Z0-9]+]]: i32, %[[ARG9:[a-zA-Z0-9]+]]: i32,
347340
// CHECK-SAME: %[[ARG10:[a-zA-Z0-9]+]]: i32)
348-
// CHECK-DAG: %[[T5:.+]] = affine.apply #[[MAP11]](%[[ARG3]], %[[ARG2]])
349-
// CHECK-DAG: %[[T6:.+]] = affine.apply #[[MAP12]](%[[ARG6]], %[[ARG5]], %[[ARG4]])
341+
// CHECK-DAG: %[[T5:.+]] = affine.apply #[[MAP8]](%[[ARG3]], %[[ARG2]])
342+
// CHECK-DAG: %[[T6:.+]] = affine.apply #[[MAP9]](%[[ARG6]], %[[ARG5]], %[[ARG4]])
350343
// CHECK-DAG: %[[T7:.+]] = addi %[[ARG8]], %[[ARG9]]
351344
// CHECK: %[[T8:.+]] = index_cast %[[T5]]
352345
// CHECK: %[[T9:.+]] = addi %[[T7]], %[[T8]]
@@ -535,8 +528,11 @@ func @unit_dim_reshape_expansion_full
535528
// CHECK-SAME: ins(%{{.+}}, %{{.+}} : tensor<?x2x4xf32>, tensor<?x2x4xf32>)
536529

537530
// FOLDUNITDIM: func @unit_dim_reshape_expansion_full
538-
// FOLDUNITDIM: linalg.init_tensor
539-
// FOLDUNITDIM-COUNT-2: linalg.tensor_reshape
531+
// FOLDUNITDIM-SAME: %[[ARG0:.+]]: tensor<1x?x1x2x1x4xf32>
532+
// FOLDUNITDIM-SAME: %[[ARG1:.+]]: tensor<?x2x4xf32>
533+
// FOLDUNITDIM-DAG: %[[RESHAPE:.+]] = linalg.tensor_reshape %[[ARG1]]
534+
// FOLDUNITDIM-DAG: %[[INIT:.+]] = linalg.init_tensor [1, %{{.+}}, 1, 2, 1, 4]
540535
// FOLDUNITDIM: linalg.generic
541-
// FOLDUNITDIM-SAME: ins(%{{.+}}, %{{.+}} : tensor<1x?x1x2x1x4xf32>, tensor<1x?x1x2x1x4xf32>)
536+
// FOLDUNITDIM-SAME: ins(%[[ARG0]], %[[RESHAPE]] : tensor<1x?x1x2x1x4xf32>, tensor<1x?x1x2x1x4xf32>)
537+
// FOLDUNITDIM-SAME: outs(%[[INIT]] : tensor<1x?x1x2x1x4xf32>)
542538

0 commit comments

Comments
 (0)