Skip to content

Commit 80f3b6a

Browse files
tatwaichongJerry-Ge
authored andcommitted
[TOSA] Change the start and size of slice to tosa shape type
Update to use getConstShapeValue to collect shape information along the graph. Change-Id: Ic6fc2341e3bcfbec06a1d08986e26dd08573bd9c
1 parent 18e9d3d commit 80f3b6a

File tree

14 files changed

+220
-79
lines changed

14 files changed

+220
-79
lines changed

mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,8 +1664,8 @@ def Tosa_SliceOp : Tosa_InferShapedTypeOp<"slice"> {
16641664

16651665
let arguments = (ins
16661666
Tosa_Tensor:$input1,
1667-
DenseI64ArrayAttr:$start,
1668-
DenseI64ArrayAttr:$size
1667+
Tosa_Shape:$start,
1668+
Tosa_Shape:$size
16691669
);
16701670

16711671
let results = (outs

mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,28 @@ class SliceConverter : public OpConversionPattern<tosa::SliceOp> {
268268
ShapedType resultType = cast<ShapedType>(sliceOp.getType());
269269
if (llvm::isa<UnrankedTensorType>(resultType))
270270
return failure();
271+
272+
ElementsAttr StartElems;
273+
ElementsAttr SizeElems;
274+
275+
if (!matchPattern(sliceOp.getStart(), m_Constant(&StartElems)))
276+
return rewriter.notifyMatchFailure(
277+
sliceOp, "start of slice must be a static ranked shape");
278+
279+
if (!matchPattern(sliceOp.getSize(), m_Constant(&SizeElems)))
280+
return rewriter.notifyMatchFailure(
281+
sliceOp, "size of slice must be a static ranked shape");
282+
283+
llvm::SmallVector<int64_t> SliceStarts =
284+
llvm::to_vector(StartElems.getValues<int64_t>());
285+
llvm::SmallVector<int64_t> SliceSizes =
286+
llvm::to_vector(SizeElems.getValues<int64_t>());
287+
271288
SmallVector<int64_t> strides, sizes;
272-
ArrayRef<int64_t> starts = sliceOp.getStart();
273289
strides.resize(cast<ShapedType>(sliceOp.getType()).getRank(), 1);
274290

275291
SmallVector<Value> dynSizes;
276-
for (const auto &i : llvm::enumerate(sliceOp.getSize())) {
292+
for (const auto &i : llvm::enumerate(SliceSizes)) {
277293
int64_t size = i.value();
278294
size_t index = i.index();
279295
sizes.push_back(size == -1 ? ShapedType::kDynamic : size);
@@ -282,17 +298,27 @@ class SliceConverter : public OpConversionPattern<tosa::SliceOp> {
282298

283299
auto dim = rewriter.create<tensor::DimOp>(loc, input, index);
284300
auto offset = rewriter.create<arith::ConstantOp>(
285-
loc, rewriter.getIndexAttr(starts[index]));
301+
loc, rewriter.getIndexAttr(SliceStarts[index]));
286302
dynSizes.push_back(rewriter.create<arith::SubIOp>(loc, dim, offset));
287303
}
288304

289305
auto newSliceOp = rewriter.create<tensor::ExtractSliceOp>(
290306
sliceOp.getLoc(), sliceOp.getType(), input, ValueRange({}), dynSizes,
291-
ValueRange({}), rewriter.getDenseI64ArrayAttr(starts),
307+
ValueRange({}), rewriter.getDenseI64ArrayAttr(SliceStarts),
292308
rewriter.getDenseI64ArrayAttr(sizes),
293309
rewriter.getDenseI64ArrayAttr(strides));
294310

295311
rewriter.replaceOp(sliceOp, newSliceOp.getResult());
312+
313+
auto removeIfRedundant = [&](Operation *op) {
314+
if (op->getResults().size() == 1 && op->getResult(0).hasOneUse())
315+
rewriter.eraseOp(op);
316+
};
317+
318+
// Remove const_shape ops when it no longer has use point.
319+
removeIfRedundant(sliceOp.getStart().getDefiningOp());
320+
removeIfRedundant(sliceOp.getSize().getDefiningOp());
321+
296322
return success();
297323
}
298324
};

mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,21 @@ struct ConcatSliceOptimization : public OpRewritePattern<tosa::SliceOp> {
393393
sliceOp, "slice input must be a static ranked tensor");
394394
int32_t axis = concatOp.getAxis();
395395

396-
llvm::SmallVector<int64_t> sliceStart(sliceOp.getStart());
397-
llvm::ArrayRef<int64_t> sliceSize = sliceOp.getSize();
396+
DenseElementsAttr StartElems;
397+
DenseElementsAttr SizeElems;
398+
399+
if (!matchPattern(sliceOp.getStart(), m_Constant(&StartElems)))
400+
return rewriter.notifyMatchFailure(
401+
sliceOp, "start of slice must be a static ranked shape");
402+
403+
if (!matchPattern(sliceOp.getSize(), m_Constant(&SizeElems)))
404+
return rewriter.notifyMatchFailure(
405+
sliceOp, "size of slice must be a static ranked shape");
406+
407+
llvm::SmallVector<int64_t> SliceStarts =
408+
llvm::to_vector(StartElems.getValues<int64_t>());
409+
llvm::SmallVector<int64_t> SliceSizes =
410+
llvm::to_vector(SizeElems.getValues<int64_t>());
398411

399412
// Validate slice on the concatenated axis. Slicing along this
400413
// axis should span only one of the inputs to the concatenate
@@ -406,17 +419,20 @@ struct ConcatSliceOptimization : public OpRewritePattern<tosa::SliceOp> {
406419
return rewriter.notifyMatchFailure(
407420
sliceOp, "concat input must be a static ranked tensor");
408421

409-
if (sliceStart[axis] >= 0 &&
410-
(sliceStart[axis] + sliceSize[axis]) <= inputType.getDimSize(axis)) {
411-
replaceWithSlice = rewriter
412-
.create<tosa::SliceOp>(
413-
sliceOp.getLoc(), sliceOp.getType(), input,
414-
rewriter.getDenseI64ArrayAttr(sliceStart),
415-
rewriter.getDenseI64ArrayAttr(sliceSize))
416-
.getResult();
422+
if (SliceStarts[axis] >= 0 && (SliceStarts[axis] + SliceSizes[axis]) <=
423+
inputType.getDimSize(axis)) {
424+
auto start_op =
425+
getTosaConstShape(rewriter, sliceOp.getLoc(), SliceStarts);
426+
auto size_op =
427+
getTosaConstShape(rewriter, sliceOp.getLoc(), SliceSizes);
428+
replaceWithSlice =
429+
rewriter
430+
.create<tosa::SliceOp>(sliceOp.getLoc(), sliceOp.getType(),
431+
input, start_op, size_op)
432+
.getResult();
417433
break;
418434
}
419-
sliceStart[axis] -= inputType.getDimSize(axis);
435+
SliceStarts[axis] -= inputType.getDimSize(axis);
420436
}
421437

422438
if (!replaceWithSlice)
@@ -963,7 +979,12 @@ OpFoldResult SliceOp::fold(FoldAdaptor adaptor) {
963979

964980
if (inputTy.hasStaticShape() && outputTy.hasStaticShape() &&
965981
outputTy.getNumElements() == 1) {
966-
llvm::SmallVector<uint64_t> indices(getStart());
982+
DenseElementsAttr StartElems;
983+
if (!matchPattern(getStart(), m_Constant(&StartElems)))
984+
return {};
985+
986+
llvm::SmallVector<uint64_t> indices =
987+
llvm::to_vector(StartElems.getValues<uint64_t>());
967988
auto value = operand.getValues<Attribute>()[indices];
968989
return SplatElementsAttr::get(outputTy, value);
969990
}

mlir/lib/Dialect/Tosa/IR/TosaOps.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,18 @@ LogicalResult tosa::SliceOp::inferReturnTypeComponents(
891891
MLIRContext *context, ::std::optional<Location> location,
892892
SliceOp::Adaptor adaptor,
893893
SmallVectorImpl<ShapedTypeComponents> &inferredReturnShapes) {
894-
auto start = adaptor.getStart();
895-
auto size = adaptor.getSize();
894+
895+
Type inputType = getElementTypeOrSelf(adaptor.getInput1().getType());
896+
SmallVector<int64_t> start;
897+
SmallVector<int64_t> size;
898+
899+
if (!tosa::getConstShapeValue(adaptor.getStart().getDefiningOp(), start) ||
900+
!tosa::getConstShapeValue(adaptor.getSize().getDefiningOp(), size)) {
901+
auto rank = cast<tosa::shapeType>(adaptor.getSize().getType()).getRank();
902+
SmallVector<int64_t> fallback(rank, ShapedType::kDynamic);
903+
inferredReturnShapes.push_back(ShapedTypeComponents(fallback, inputType));
904+
return success();
905+
}
896906

897907
// if size[i] is -1, all remaining elements in dimension i are included
898908
// in the slice, similar to TF.
@@ -933,11 +943,15 @@ LogicalResult tosa::SliceOp::verify() {
933943
if (!inputType)
934944
return success();
935945

936-
if (static_cast<size_t>(inputType.getRank()) != getStart().size())
946+
auto StartShapeRank =
947+
llvm::cast<tosa::shapeType>(getStart().getType()).getRank();
948+
if (inputType.getRank() != StartShapeRank)
937949
return emitOpError(
938950
"length of start attribute is not equal rank of input shape");
939951

940-
if (static_cast<size_t>(inputType.getRank()) != getSize().size())
952+
auto SizeShapeRank =
953+
llvm::cast<tosa::shapeType>(getSize().getType()).getRank();
954+
if (inputType.getRank() != SizeShapeRank)
941955
return emitOpError(
942956
"length of size attribute is not equal rank of input shape");
943957

mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeTransposeConv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ class TransposeConvStridedConverter
302302

303303
auto slice = CreateOpAndInferShape<tosa::SliceOp>(
304304
rewriter, loc, UnrankedTensorType::get(resultETy), conv2d,
305-
rewriter.getDenseI64ArrayAttr(sliceBegin),
306-
rewriter.getDenseI64ArrayAttr(sliceSize))
305+
getTosaConstShape(rewriter, loc, sliceBegin),
306+
getTosaConstShape(rewriter, loc, sliceSize))
307307
.getResult();
308308

309309
llvm::SmallVector<int64_t, 8> resultPadding = {0, 0, 0, 0, 0, 0, 0, 0};

mlir/test/Conversion/TosaToTensor/tosa-to-tensor-invalid.mlir

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
// CHECK-LABEL: @slice_resultType_unranked
44
func.func @slice_resultType_unranked(%arg0: tensor<?xf32>) -> (tensor<*xf32>) {
5+
%0 = tosa.const_shape {value = dense<2> : tensor<1xindex>} : () -> !tosa.shape<1>
6+
%1 = tosa.const_shape {value = dense<0> : tensor<1xindex>} : () -> !tosa.shape<1>
57
// expected-error@+1 {{failed to legalize operation 'tosa.slice'}}
6-
%0 = "tosa.slice"(%arg0) {start = array<i64: 2>, size = array<i64: 0>} : (tensor<?xf32>) -> (tensor<*xf32>)
7-
return %0 : tensor<*xf32>
8+
%2 = tosa.slice %arg0, %0, %1 : (tensor<?xf32>, !tosa.shape<1>, !tosa.shape<1>) -> tensor<*xf32>
9+
return %2 : tensor<*xf32>
810
}

mlir/test/Conversion/TosaToTensor/tosa-to-tensor.mlir

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,9 @@ func.func @test_reshape_samerank_unsigned(%arg0: tensor<3x2xui8>) -> tensor<2x3x
437437
// CHECK-LABEL: func @slice
438438
func.func @slice(%arg0: tensor<6xf32>) ->() {
439439
// CHECK: [[SLICE:%.+]] = tensor.extract_slice %arg0[2] [1] [1]
440-
%0 = "tosa.slice"(%arg0) {start = array<i64: 2>, size = array<i64: 1>} : (tensor<6xf32>) -> (tensor<1xf32>)
440+
%0 = tosa.const_shape {value = dense<2> : tensor<1xindex>} : () -> !tosa.shape<1>
441+
%1 = tosa.const_shape {value = dense<1> : tensor<1xindex>} : () -> !tosa.shape<1>
442+
%2 = tosa.slice %arg0, %0, %1 : (tensor<6xf32>, !tosa.shape<1>, !tosa.shape<1>) -> tensor<1xf32>
441443
return
442444
}
443445

@@ -450,8 +452,10 @@ func.func @slice_dyn(%arg0: tensor<?xf32>) -> (tensor<?xf32>) {
450452
// CHECK: %[[C2:.+]] = arith.constant 2 : index
451453
// CHECK: %[[SUB:.+]] = arith.subi %[[DIM]], %[[C2]]
452454
// CHECK: tensor.extract_slice %arg0[2] [%[[SUB]]] [1]
453-
%0 = "tosa.slice"(%arg0) {start = array<i64: 2>, size = array<i64: -1>} : (tensor<?xf32>) -> (tensor<?xf32>)
454-
return %0 : tensor<?xf32>
455+
%0 = tosa.const_shape {value = dense<2> : tensor<1xindex>} : () -> !tosa.shape<1>
456+
%1 = tosa.const_shape {value = dense<-1> : tensor<1xindex>} : () -> !tosa.shape<1>
457+
%2 = tosa.slice %arg0, %0, %1 : (tensor<?xf32>, !tosa.shape<1>, !tosa.shape<1>) -> tensor<?xf32>
458+
return %2 : tensor<?xf32>
455459
}
456460

457461
// -----

mlir/test/Dialect/Tosa/canonicalize.mlir

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -572,18 +572,22 @@ func.func @transpose_canonicalize_strip_quant() -> (tensor<2x1x3x!quant.uniform<
572572

573573
// CHECK-LABEL: @slice_fold
574574
func.func @slice_fold(%arg0: tensor<3x4xf32>) -> tensor<3x4xf32> {
575+
%0 = tosa.const_shape {value = dense<[0, 0]> : tensor<2xindex>} : () -> !tosa.shape<2>
576+
%1 = tosa.const_shape {value = dense<[3, 4]> : tensor<2xindex>} : () -> !tosa.shape<2>
575577
// CHECK: return %arg0
576-
%0 = tosa.slice %arg0 { size = array<i64: 3, 4>, start = array<i64: 0, 0>}: (tensor<3x4xf32>) -> tensor<3x4xf32>
577-
return %0 : tensor<3x4xf32>
578+
%3 = tosa.slice %arg0, %0, %1 : (tensor<3x4xf32>, !tosa.shape<2>, !tosa.shape<2>) -> tensor<3x4xf32>
579+
return %3 : tensor<3x4xf32>
578580
}
579581

580582
// -----
581583

582584
// CHECK-LABEL: @slice_nofold
583585
func.func @slice_nofold(%arg0: tensor<?x4xf32>) -> tensor<?x4xf32> {
586+
%0 = tosa.const_shape {value = dense<[0, 0]> : tensor<2xindex>} : () -> !tosa.shape<2>
587+
%1 = tosa.const_shape {value = dense<[3, 4]> : tensor<2xindex>} : () -> !tosa.shape<2>
584588
// CHECK: tosa.slice
585-
%0 = tosa.slice %arg0 { size = array<i64: 3, 4>, start = array<i64: 0, 0>}: (tensor<?x4xf32>) -> tensor<?x4xf32>
586-
return %0 : tensor<?x4xf32>
589+
%3 = tosa.slice %arg0, %0, %1 : (tensor<?x4xf32>, !tosa.shape<2>, !tosa.shape<2>) -> tensor<?x4xf32>
590+
return %3 : tensor<?x4xf32>
587591
}
588592

589593
// -----
@@ -663,9 +667,12 @@ func.func @fold_resize_bilinear(%arg0 : tensor<1x15x13x1xi8>) -> tensor<1x15x13x
663667
// CHECK: return %[[VAL_0]], %[[VAL_1]] : tensor<1x12x12x1xf32>, tensor<1x12x12x1xf32>
664668
func.func @canonicalize_concat_slice_final_axis(%arg0 : tensor<1x12x12x1xf32>, %arg1 : tensor<1x12x12x1xf32>) -> (tensor<1x12x12x1xf32>, tensor<1x12x12x1xf32>) {
665669
%0 = tosa.concat %arg0, %arg1 {axis = 3 : i32} : (tensor<1x12x12x1xf32>, tensor<1x12x12x1xf32>) -> tensor<1x12x12x2xf32>
666-
%1 = tosa.slice %0 {size = array<i64: 1, 12, 12, 1>, start = array<i64: 0, 0, 0, 0>} : (tensor<1x12x12x2xf32>) -> tensor<1x12x12x1xf32>
667-
%2 = tosa.slice %0 {size = array<i64: 1, 12, 12, 1>, start = array<i64: 0, 0, 0, 1>} : (tensor<1x12x12x2xf32>) -> tensor<1x12x12x1xf32>
668-
return %1, %2 : tensor<1x12x12x1xf32>, tensor<1x12x12x1xf32>
670+
%1 = tosa.const_shape {value = dense<[0, 0, 0, 0]> : tensor<4xindex>} : () -> !tosa.shape<4>
671+
%2 = tosa.const_shape {value = dense<[0, 0, 0, 1]> : tensor<4xindex>} : () -> !tosa.shape<4>
672+
%3 = tosa.const_shape {value = dense<[1, 12, 12, 1]> : tensor<4xindex>} : () -> !tosa.shape<4>
673+
%4 = tosa.slice %0, %1, %3 : (tensor<1x12x12x2xf32>, !tosa.shape<4>, !tosa.shape<4>) -> tensor<1x12x12x1xf32>
674+
%5 = tosa.slice %0, %2, %3 : (tensor<1x12x12x2xf32>, !tosa.shape<4>, !tosa.shape<4>) -> tensor<1x12x12x1xf32>
675+
return %4, %5 : tensor<1x12x12x1xf32>, tensor<1x12x12x1xf32>
669676
}
670677

671678
// -----
@@ -675,38 +682,56 @@ func.func @canonicalize_concat_slice_final_axis(%arg0 : tensor<1x12x12x1xf32>, %
675682
// CHECK: return %[[VAL_0]], %[[VAL_1]] : tensor<1x12x12xf32>, tensor<1x12x12xf32>
676683
func.func @canonicalize_concat_slice_middle_axis(%arg0 : tensor<1x12x12xf32>, %arg1 : tensor<1x12x12xf32>) -> (tensor<1x12x12xf32>, tensor<1x12x12xf32>) {
677684
%0 = tosa.concat %arg0, %arg1 {axis = 1 : i32} : (tensor<1x12x12xf32>, tensor<1x12x12xf32>) -> tensor<1x24x12xf32>
678-
%1 = tosa.slice %0 {size = array<i64: 1, 12, 12>, start = array<i64: 0, 0, 0>} : (tensor<1x24x12xf32>) -> tensor<1x12x12xf32>
679-
%2 = tosa.slice %0 {size = array<i64: 1, 12, 12>, start = array<i64: 0, 12, 0>} : (tensor<1x24x12xf32>) -> tensor<1x12x12xf32>
680-
return %1, %2 : tensor<1x12x12xf32>, tensor<1x12x12xf32>
685+
%1 = tosa.const_shape {value = dense<[0, 0, 0]> : tensor<3xindex>} : () -> !tosa.shape<3>
686+
%2 = tosa.const_shape {value = dense<[0, 12, 0]> : tensor<3xindex>} : () -> !tosa.shape<3>
687+
%3 = tosa.const_shape {value = dense<[1, 12, 12]> : tensor<3xindex>} : () -> !tosa.shape<3>
688+
%4 = tosa.slice %0, %1, %3 : (tensor<1x24x12xf32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x12x12xf32>
689+
%5 = tosa.slice %0, %2, %3 : (tensor<1x24x12xf32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x12x12xf32>
690+
return %4, %5 : tensor<1x12x12xf32>, tensor<1x12x12xf32>
681691
}
682692

683693
// -----
684694

685695
// CHECK-LABEL: @canonicalize_cross_concat_inputs
686696
// CHECK-SAME: %[[VAL_0:.*]]: tensor<1x12x12xf32>, %[[VAL_1:.*]]: tensor<1x12x12xf32>
687-
// CHECK: %[[VAL_2:.*]] = tosa.concat %[[VAL_0]], %[[VAL_1]] {axis = 2 : i32} : (tensor<1x12x12xf32>, tensor<1x12x12xf32>) -> tensor<1x12x24xf32>
688-
// CHECK: %[[VAL_3:.*]] = tosa.slice %[[VAL_2]] {size = array<i64: 1, 12, 15>, start = array<i64: 0, 0, 0>} : (tensor<1x12x24xf32>) -> tensor<1x12x15xf32>
689-
// CHECK: %[[VAL_4:.*]] = tosa.slice %[[VAL_2]] {size = array<i64: 1, 12, 20>, start = array<i64: 0, 0, 4>} : (tensor<1x12x24xf32>) -> tensor<1x12x20xf32>
690-
// CHECK: return %[[VAL_3]], %[[VAL_4]] : tensor<1x12x15xf32>, tensor<1x12x20xf32>
697+
// CHECK-DAG: %[[VAL_2:.*]] = tosa.const_shape {value = dense<[1, 12, 20]> : tensor<3xindex>}
698+
// CHECK-DAG: %[[VAL_3:.*]] = tosa.const_shape {value = dense<[1, 12, 15]> : tensor<3xindex>}
699+
// CHECK-DAG: %[[VAL_4:.*]] = tosa.const_shape {value = dense<[0, 0, 4]> : tensor<3xindex>}
700+
// CHECK-DAG: %[[VAL_5:.*]] = tosa.const_shape {value = dense<0> : tensor<3xindex>}
701+
// CHECK: %[[VAL_6:.*]] = tosa.concat %[[VAL_0]], %[[VAL_1]] {axis = 2 : i32} : (tensor<1x12x12xf32>, tensor<1x12x12xf32>) -> tensor<1x12x24xf32>
702+
// CHECK: %[[VAL_7:.*]] = tosa.slice %[[VAL_6]], %[[VAL_5]], %[[VAL_3]]
703+
// CHECK: %[[VAL_8:.*]] = tosa.slice %[[VAL_6]], %[[VAL_4]], %[[VAL_2]]
704+
// CHECK: return %[[VAL_7]], %[[VAL_8]] : tensor<1x12x15xf32>, tensor<1x12x20xf32>
691705
func.func @canonicalize_cross_concat_inputs(%arg0 : tensor<1x12x12xf32>, %arg1 : tensor<1x12x12xf32>) -> (tensor<1x12x15xf32>, tensor<1x12x20xf32>) {
692706
%0 = tosa.concat %arg0, %arg1 {axis = 2 : i32} : (tensor<1x12x12xf32>, tensor<1x12x12xf32>) -> tensor<1x12x24xf32>
693-
%1 = tosa.slice %0 {size = array<i64: 1, 12, 15>, start = array<i64: 0, 0, 0>} : (tensor<1x12x24xf32>) -> tensor<1x12x15xf32>
694-
%2 = tosa.slice %0 {size = array<i64: 1, 12, 20>, start = array<i64: 0, 0, 4>} : (tensor<1x12x24xf32>) -> tensor<1x12x20xf32>
695-
return %1, %2 : tensor<1x12x15xf32>, tensor<1x12x20xf32>
707+
%1 = tosa.const_shape {value = dense<[0, 0, 0]> : tensor<3xindex>} : () -> !tosa.shape<3>
708+
%2 = tosa.const_shape {value = dense<[0, 0, 4]> : tensor<3xindex>} : () -> !tosa.shape<3>
709+
%3 = tosa.const_shape {value = dense<[1, 12, 15]> : tensor<3xindex>} : () -> !tosa.shape<3>
710+
%4 = tosa.const_shape {value = dense<[1, 12, 20]> : tensor<3xindex>} : () -> !tosa.shape<3>
711+
%5 = tosa.slice %0, %1, %3 : (tensor<1x12x24xf32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x12x15xf32>
712+
%6 = tosa.slice %0, %2, %4 : (tensor<1x12x24xf32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x12x20xf32>
713+
return %5, %6 : tensor<1x12x15xf32>, tensor<1x12x20xf32>
696714
}
697715

698716
// -----
699717

700718
// CHECK-LABEL: @canonicalize_concat_slice_on_non_concat_axis
701719
// CHECK-SAME: %[[VAL_0:.*]]: tensor<1x12x12xf32>, %[[VAL_1:.*]]: tensor<1x12x12xf32>
702-
// CHECK: %[[VAL_2:.*]] = tosa.slice %[[VAL_0]] {size = array<i64: 1, 6, 12>, start = array<i64: 0, 0, 0>} : (tensor<1x12x12xf32>) -> tensor<1x6x12xf32>
703-
// CHECK: %[[VAL_3:.*]] = tosa.slice %[[VAL_1]] {size = array<i64: 1, 3, 12>, start = array<i64: 1, 3, 0>} : (tensor<1x12x12xf32>) -> tensor<1x3x12xf32>
704-
// CHECK: return %[[VAL_2]], %[[VAL_3]] : tensor<1x6x12xf32>, tensor<1x3x12xf32>
720+
// CHECK-DAG: %[[VAL_2:.*]] = tosa.const_shape {value = dense<[1, 3, 0]> : tensor<3xindex>}
721+
// CHECK-DAG: %[[VAL_3:.*]] = tosa.const_shape {value = dense<[1, 3, 12]> : tensor<3xindex>}
722+
// CHECK-DAG: %[[VAL_4:.*]] = tosa.const_shape {value = dense<0> : tensor<3xindex>}
723+
// CHECK-DAG: %[[VAL_5:.*]] = tosa.const_shape {value = dense<[1, 6, 12]> : tensor<3xindex>}
724+
// CHECK: %[[VAL_6:.*]] = tosa.slice %[[VAL_0]], %[[VAL_4]], %[[VAL_5]]
725+
// CHECK: %[[VAL_7:.*]] = tosa.slice %[[VAL_1]], %[[VAL_2]], %[[VAL_3]]
726+
// CHECK: return %[[VAL_6]], %[[VAL_7]] : tensor<1x6x12xf32>, tensor<1x3x12xf32>
705727
func.func @canonicalize_concat_slice_on_non_concat_axis(%arg0 : tensor<1x12x12xf32>, %arg1 : tensor<1x12x12xf32>) -> (tensor<1x6x12xf32>, tensor<1x3x12xf32>) {
706728
%0 = tosa.concat %arg0, %arg1 {axis = 2 : i32} : (tensor<1x12x12xf32>, tensor<1x12x12xf32>) -> tensor<1x12x24xf32>
707-
%1 = tosa.slice %0 {size = array<i64: 1, 6, 12>, start = array<i64: 0, 0, 0>} : (tensor<1x12x24xf32>) -> tensor<1x6x12xf32>
708-
%2 = tosa.slice %0 {size = array<i64: 1, 3, 12>, start = array<i64: 1, 3, 12>} : (tensor<1x12x24xf32>) -> tensor<1x3x12xf32>
709-
return %1, %2 : tensor<1x6x12xf32>, tensor<1x3x12xf32>
729+
%1 = tosa.const_shape {value = dense<[0, 0, 0]> : tensor<3xindex>} : () -> !tosa.shape<3>
730+
%2 = tosa.const_shape {value = dense<[1, 6, 12]> : tensor<3xindex>} : () -> !tosa.shape<3>
731+
%3 = tosa.const_shape {value = dense<[1, 3, 12]> : tensor<3xindex>} : () -> !tosa.shape<3>
732+
%4 = tosa.slice %0, %1, %2 : (tensor<1x12x24xf32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x6x12xf32>
733+
%5 = tosa.slice %0, %3, %3 : (tensor<1x12x24xf32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x3x12xf32>
734+
return %4, %5 : tensor<1x6x12xf32>, tensor<1x3x12xf32>
710735
}
711736

712737
// -----

0 commit comments

Comments
 (0)