// RUN: mlir-opt -split-input-file -test-tensor-transform-patterns=test-reassociative-reshape-folding %s | FileCheck %s // CHECK-LABEL: func @expand_shape_of_rank_reducing_extract( // CHECK-SAME: %[[t:.*]]: tensor // CHECK-DAG: %[[extract1:.*]] = tensor.extract_slice %{{.*}}[0, 0, 0, 0] [%{{.*}}, 1, 1, 5] [1, 1, 1, 1] : tensor to tensor // CHECK-DAG: %[[extract2:.*]] = tensor.extract_slice %{{.*}}[0, 0, 0, 0] [%{{.*}}, 1, 1, 5] [1, 1, 1, 1] : tensor to tensor // CHECK: return %[[extract1]], %[[extract2]] func.func @expand_shape_of_rank_reducing_extract( %t: tensor, %idx: index) -> (tensor, tensor) { %0 = tensor.extract_slice %t[0, 0, 0, 0][%idx, 1, 1, 5][1, 1, 1, 1] : tensor to tensor %1 = tensor.expand_shape %0 [[0], [1, 2], [3]] : tensor into tensor %2 = tensor.expand_shape %0 [[0, 1], [2], [3]] : tensor into tensor return %1, %2 : tensor, tensor } // ----- // CHECK-LABEL: func @rank_reducing_insert_of_collapse_shape( // CHECK-SAME: %[[t:.*]]: tensor // CHECK: %[[insert:.*]] = tensor.insert_slice %[[t]] into %{{.*}}[0, 0, 0, 0] [%{{.*}}, 1, 1, 5] [1, 1, 1, 1] : tensor into tensor // CHECK: return %[[insert]] func.func @rank_reducing_insert_of_collapse_shape( %t: tensor, %d: tensor, %sz: index) -> tensor { %0 = tensor.collapse_shape %t [[0, 1], [2], [3]] : tensor into tensor %1 = tensor.insert_slice %0 into %d[0, 0, 0, 0][%sz, 1, 1, 5][1, 1, 1, 1] : tensor into tensor return %1 : tensor } // ----- // CHECK-LABEL: func @rank_reducing_parallel_insert_of_collapse_shape( // CHECK-SAME: %[[t:.*]]: tensor // CHECK: tensor.parallel_insert_slice %[[t]] into %{{.*}}[0, 0, 0, 0] [%{{.*}}, 1, 1, 5] [1, 1, 1, 1] : tensor into tensor func.func @rank_reducing_parallel_insert_of_collapse_shape( %t: tensor, %d: tensor, %sz: index, %thr: index) -> tensor { %0 = tensor.collapse_shape %t [[0, 1], [2], [3]] : tensor into tensor %1 = scf.forall (%iv) in (%thr) shared_outs(%o = %d) -> (tensor) { scf.forall.in_parallel { tensor.parallel_insert_slice %0 into %o[0, 0, 0, 0][%sz, 1, 1, 5][1, 1, 1, 1] : tensor into tensor } } return %1 : tensor }