1// RUN: mlir-opt %s -eliminate-empty-tensors -empty-tensor-to-alloc-tensor -one-shot-bufferize="bufferize-function-boundaries test-analysis-only" -split-input-file | FileCheck %s 2 3// CHECK-LABEL: func @buffer_forwarding_conflict 4func.func @buffer_forwarding_conflict(%arg0: tensor<?xf32> {bufferization.writable = true}, %arg1: index) -> (tensor<?xf32>, tensor<?xf32>) { 5 %cst = arith.constant 0.000000e+00 : f32 6 // CHECK: tensor.extract_slice 7 // CHECK-SAME: {__inplace_operands_attr__ = ["false", "none"] 8 // Instead of allocating, share buffer with some inplace bufferization? 9 %0 = tensor.empty(%arg1) : tensor<?xf32> 10 11 // CHECK: linalg.fill 12 // CHECK-SAME: {__inplace_operands_attr__ = ["none", "true"] 13 %1 = linalg.fill ins(%cst : f32) outs(%0 : tensor<?xf32>) -> tensor<?xf32> 14 15 // CHECK: tensor.insert_slice 16 // CHECK-SAME: {__inplace_operands_attr__ = ["true", "false", "none"] 17 %2 = tensor.insert_slice %1 into %arg0[0] [%arg1] [1] : tensor<?xf32> into tensor<?xf32> 18 19 // CHECK: tensor.insert_slice 20 // CHECK-SAME: {__inplace_operands_attr__ = ["true", "true", "none"] 21 %3 = tensor.insert_slice %1 into %arg0[42] [%arg1] [1] : tensor<?xf32> into tensor<?xf32> 22 23 // CHECK: return 24 // CHECK-SAME: __equivalent_func_args__ = [-1, 0] 25 return %2, %3 : tensor<?xf32>, tensor<?xf32> 26} 27 28// ----- 29 30// CHECK-LABEL: func @buffer_forwarding_no_conflict 31func.func @buffer_forwarding_no_conflict(%arg0: tensor<?xf32> {bufferization.writable = true}, %arg1: index) -> (tensor<?xf32>, tensor<?xf32>) { 32 %cst = arith.constant 0.000000e+00 : f32 33 // CHECK: tensor.extract_slice 34 // CHECK-SAME: {__inplace_operands_attr__ = ["true", "none"] 35 // Instead of allocating, share buffer with some inplace bufferization? 36 %0 = tensor.empty(%arg1) : tensor<?xf32> 37 38 // CHECK: linalg.fill 39 // CHECK-SAME: {__inplace_operands_attr__ = ["none", "true"] 40 %1 = linalg.fill ins(%cst : f32) outs(%0 : tensor<?xf32>) -> tensor<?xf32> 41 42 // CHECK: tensor.insert_slice 43 // CHECK-SAME: {__inplace_operands_attr__ = ["true", "true", "none"] 44 %2 = tensor.insert_slice %1 into %arg0[42] [%arg1] [1] : tensor<?xf32> into tensor<?xf32> 45 46 // CHECK: return 47 // CHECK-SAME: __equivalent_func_args__ = [0, 0] 48 return %2, %2 : tensor<?xf32>, tensor<?xf32> 49} 50 51// ----- 52 53// CHECK-LABEL: func @buffer_forwarding_conflict_with_different_element_type 54func.func @buffer_forwarding_conflict_with_different_element_type(%arg0: tensor<?xf32> {bufferization.writable = true}, %arg1: index) -> (tensor<?xf32>, tensor<?xf32>) { 55 // CHECK: tensor.extract_slice 56 // CHECK-SAME: {__inplace_operands_attr__ = ["true", "none"] 57 %cst = arith.constant 0.000000e+00 : f32 58 // CHECK: bufferization.alloc_tensor(%arg1) 59 %0 = tensor.empty(%arg1) : tensor<?xf32> 60 61 // CHECK: bufferization.alloc_tensor(%arg1) 62 %1 = tensor.empty(%arg1) : tensor<?xbf16> 63 64 // CHECK: linalg.copy 65 // CHECK-SAME: {__inplace_operands_attr__ = ["true", "true"] 66 %2 = linalg.copy ins(%0 : tensor<?xf32>) outs(%1 : tensor<?xbf16>) -> tensor<?xbf16> 67 68 // CHECK: linalg.copy 69 // CHECK-SAME: {__inplace_operands_attr__ = ["true", "true"] 70 %3 = linalg.copy ins(%2 : tensor<?xbf16>) outs(%0 : tensor<?xf32>) -> tensor<?xf32> 71 72 // CHECK: tensor.insert_slice 73 // CHECK-SAME: {__inplace_operands_attr__ = ["true", "true", "none"] 74 %4 = tensor.insert_slice %3 into %arg0[42] [%arg1] [1] : tensor<?xf32> into tensor<?xf32> 75 76 // CHECK: return 77 // CHECK-SAME: __equivalent_func_args__ = [0, 0] 78 return %4, %4 : tensor<?xf32>, tensor<?xf32> 79} 80