|
| 1 | +// RUN: mlir-opt -split-input-file -test-tensor-transform-patterns=test-fold-consecutive-insert-extract-slice -canonicalize -mlir-print-local-scope %s | FileCheck %s |
| 2 | + |
| 3 | +func.func @extract_slice_same_rank( |
| 4 | + %src: tensor<?x?x?x?xf32>, %offset0: index, %offset1: index, %size0: index, %size1: index) -> tensor<8x16x32x?xf32> { |
| 5 | + %0 = tensor.extract_slice %src[0, 1, 2, %offset0] [128, 128, 128, %size0] [1, 1, 1, 1] : tensor<?x?x?x?xf32> to tensor<128x128x128x?xf32> |
| 6 | + %1 = tensor.extract_slice %0[7, 8, 9, %offset1] [8, 16, 32, %size1] [1, 1, 1, 1] : tensor<128x128x128x?xf32> to tensor<8x16x32x?xf32> |
| 7 | + return %1: tensor<8x16x32x?xf32> |
| 8 | +} |
| 9 | + |
| 10 | +// CHECK-LABEL: func.func @extract_slice_same_rank |
| 11 | +// CHECK-SAME: (%[[SOURCE:.+]]: tensor<?x?x?x?xf32>, %[[OFFSET0:.+]]: index, %[[OFFSET1:.+]]: index, %{{.+}}: index, %[[SIZE1:.+]]: index) |
| 12 | +// CHECK: %[[OFFSET:.+]] = affine.apply affine_map<()[s0, s1] -> (s0 + s1)>()[%[[OFFSET0]], %[[OFFSET1]]] |
| 13 | +// CHECK: %[[EXTRACT:.+]] = tensor.extract_slice %[[SOURCE]][7, 9, 11, %[[OFFSET]]] [8, 16, 32, %[[SIZE1]]] [1, 1, 1, 1] |
| 14 | +// CHECK: return %[[EXTRACT]] : tensor<8x16x32x?xf32> |
| 15 | + |
| 16 | +func.func @extract_slice_rank_reducing_consumer( |
| 17 | + %src: tensor<?x?x?x?xf32>, %offset0: index, %offset1: index, %size0: index, %size1: index) -> tensor<16x?xf32> { |
| 18 | + %0 = tensor.extract_slice %src[0, 1, 2, %offset0] [128, 128, 128, %size0] [1, 1, 1, 1] : tensor<?x?x?x?xf32> to tensor<128x128x128x?xf32> |
| 19 | + %1 = tensor.extract_slice %0[7, 8, 9, %offset1] [1, 16, 1, %size1] [1, 1, 1, 1] : tensor<128x128x128x?xf32> to tensor<16x?xf32> |
| 20 | + return %1: tensor<16x?xf32> |
| 21 | +} |
| 22 | + |
| 23 | +// CHECK-LABEL: func.func @extract_slice_rank_reducing_consumer |
| 24 | +// CHECK: tensor.extract_slice %{{.+}}[7, 9, 11, %{{.+}}] [1, 16, 1, %{{.+}}] [1, 1, 1, 1] : tensor<?x?x?x?xf32> to tensor<16x?xf32> |
| 25 | + |
| 26 | +func.func @extract_slice_rank_reducing_producer( |
| 27 | + %src: tensor<?x?x?x?xf32>, %offset0: index, %offset1: index, %size0: index, %size1: index) -> tensor<8x?xf32> { |
| 28 | + %0 = tensor.extract_slice %src[0, 1, 2, %offset0] [1, 128, 1, %size0] [1, 1, 1, 1] : tensor<?x?x?x?xf32> to tensor<128x?xf32> |
| 29 | + %1 = tensor.extract_slice %0[7, %offset1] [8, %size1] [1, 1] : tensor<128x?xf32> to tensor<8x?xf32> |
| 30 | + return %1: tensor<8x?xf32> |
| 31 | +} |
| 32 | + |
| 33 | +// CHECK-LABEL: func.func @extract_slice_rank_reducing_producer |
| 34 | +// CHECK-COUNT-2: tensor.extract_slice |
| 35 | + |
| 36 | +// ----- |
| 37 | + |
| 38 | +func.func @insert_slice_rank_reducing( |
| 39 | + %dst: tensor<128x128x128x128xf32>, %mid: tensor<1x16x1xf32>, %src: tensor<16xf32>, %offset: index) -> tensor<128x128x128x128xf32> { |
| 40 | + %0 = tensor.insert_slice %src into %mid[0, 0, 0] [1, 16, 1] [1, 1, 1] : tensor<16xf32> into tensor<1x16x1xf32> |
| 41 | + %1 = tensor.insert_slice %0 into %dst[6, 7, 8, %offset] [1, 1, 16, 1] [1, 1, 1, 1] : tensor<1x16x1xf32> into tensor<128x128x128x128xf32> |
| 42 | + return %1: tensor<128x128x128x128xf32> |
| 43 | +} |
| 44 | + |
| 45 | +// CHECK-LABEL: func.func @insert_slice_rank_reducing |
| 46 | +// CHECK-SAME: (%[[DST:.+]]: tensor<128x128x128x128xf32>, %{{.+}}: tensor<1x16x1xf32>, %[[SRC:.+]]: tensor<16xf32>, %[[IDX:.+]]: index) |
| 47 | +// CHECK: %[[INSERT:.+]] = tensor.insert_slice %[[SRC]] into %[[DST]][6, 7, 8, %[[IDX]]] [1, 1, 16, 1] [1, 1, 1, 1] |
| 48 | +// CHECK: return %[[INSERT]] |
| 49 | + |
| 50 | +func.func @insert_slice_rank_reducing_dynamic_shape( |
| 51 | + %dst: tensor<128x128x128x128xf32>, %mid: tensor<1x?x1xf32>, %src: tensor<?xf32>, %offset: index, %size: index) -> tensor<128x128x128x128xf32> { |
| 52 | + %0 = tensor.insert_slice %src into %mid[0, 0, 0] [1, %size, 1] [1, 1, 1] : tensor<?xf32> into tensor<1x?x1xf32> |
| 53 | + %1 = tensor.insert_slice %0 into %dst[6, 7, 8, %offset] [1, 1, %size, 1] [1, 1, 1, 1] : tensor<1x?x1xf32> into tensor<128x128x128x128xf32> |
| 54 | + return %1: tensor<128x128x128x128xf32> |
| 55 | +} |
| 56 | + |
| 57 | +// CHECK-LABEL: func.func @insert_slice_rank_reducing_dynamic_shape |
| 58 | +// CHECK-COUNT-2: tensor.insert_slice |
0 commit comments