1// RUN: mlir-opt %s \
2// RUN:     -one-shot-bufferize="allow-unknown-ops create-deallocs=0" \
3// RUN:     -split-input-file | \
4// RUN: FileCheck %s --check-prefix=CHECK-NODEALLOC
5
6// RUN: mlir-opt %s \
7// RUN:     -one-shot-bufferize="allow-unknown-ops create-deallocs=0" \
8// RUN:     -buffer-deallocation | \
9// RUN: FileCheck %s --check-prefix=CHECK-BUFFERDEALLOC
10
11// CHECK-NODEALLOC-LABEL: func @out_of_place_bufferization
12// CHECK-BUFFERDEALLOC-LABEL: func @out_of_place_bufferization
13func.func @out_of_place_bufferization(%t1 : tensor<?xf32>) -> (f32, f32) {
14  //     CHECK-NODEALLOC: memref.alloc
15  //     CHECK-NODEALLOC: memref.copy
16  // CHECK-NODEALLOC-NOT: memref.dealloc
17
18  //     CHECK-BUFFERDEALLOC: %[[alloc:.*]] = memref.alloc
19  //     CHECK-BUFFERDEALLOC: memref.copy
20  //     CHECK-BUFFERDEALLOC: memref.dealloc %[[alloc]]
21
22  %cst = arith.constant 0.0 : f32
23  %idx = arith.constant 5 : index
24
25  // This bufferizes out-of-place. An allocation + copy will be inserted.
26  %0 = tensor.insert %cst into %t1[%idx] : tensor<?xf32>
27
28  %1 = tensor.extract %t1[%idx] : tensor<?xf32>
29  %2 = tensor.extract %0[%idx] : tensor<?xf32>
30  return %1, %2 : f32, f32
31}
32