xref: /llvm-project/mlir/test/Integration/Dialect/Linalg/CPU/test-subtensor-insert-multiple-uses.mlir (revision eb206e9ea84eff0a0596fed2de8316d924f946d1)
1debdbedaSKunwar Grover// RUN: mlir-opt %s \
2debdbedaSKunwar Grover// RUN: -one-shot-bufferize="bufferize-function-boundaries" \
399c05b26SMatthias Springer// RUN: -buffer-deallocation-pipeline -convert-bufferization-to-memref \
41a4dd8d3SMartin Erhart// RUN: -convert-linalg-to-loops -convert-scf-to-cf -expand-strided-metadata  \
51a4dd8d3SMartin Erhart// RUN: -lower-affine -convert-arith-to-llvm --finalize-memref-to-llvm \
61a4dd8d3SMartin Erhart// RUN: -convert-func-to-llvm -reconcile-unrealized-casts | \
7*eb206e9eSAndrea Faulds// RUN: mlir-runner -e main -entry-point-result=void \
89048ea28SMarkus Böck// RUN:   -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils \
999b0032cSMehdi Amini// RUN: | FileCheck %s
1099b0032cSMehdi Amini
1187db8e44SRiver Riddlefunc.func @main() {
12a54f4eaeSMogball  %const = arith.constant dense<10.0> : tensor<2xf32>
13a54f4eaeSMogball  %insert_val = arith.constant dense<20.0> : tensor<1xf32>
1499b0032cSMehdi Amini
15060208b4SMatthias Springer  // Both of these insert_slice ops insert into the same original tensor
1699b0032cSMehdi Amini  // value `%const`. This can easily cause bugs if at the memref level
1799b0032cSMehdi Amini  // we attempt to write in-place into the memref that %const has been
1899b0032cSMehdi Amini  // converted into.
19060208b4SMatthias Springer  %inserted_at_position_0 = tensor.insert_slice %insert_val into %const[0][1][1] : tensor<1xf32> into tensor<2xf32>
20060208b4SMatthias Springer  %inserted_at_position_1 = tensor.insert_slice %insert_val into %const[1][1][1] : tensor<1xf32> into tensor<2xf32>
2199b0032cSMehdi Amini
2299b0032cSMehdi Amini  %unranked_at_position_0 = tensor.cast %inserted_at_position_0 : tensor<2xf32> to tensor<*xf32>
23d4555698SStella Stamenova  call @printMemrefF32(%unranked_at_position_0) : (tensor<*xf32>) -> ()
2499b0032cSMehdi Amini
2599b0032cSMehdi Amini  //      CHECK: Unranked Memref base@ = {{0x[-9a-f]*}}
2699b0032cSMehdi Amini  // CHECK-SAME: rank = 1 offset = 0 sizes = [2] strides = [1] data =
2799b0032cSMehdi Amini  // CHECK-NEXT: [20, 10]
2899b0032cSMehdi Amini
2999b0032cSMehdi Amini  %unranked_at_position_1 = tensor.cast %inserted_at_position_1 : tensor<2xf32> to tensor<*xf32>
30d4555698SStella Stamenova  call @printMemrefF32(%unranked_at_position_1) : (tensor<*xf32>) -> ()
3199b0032cSMehdi Amini
3299b0032cSMehdi Amini  //      CHECK: Unranked Memref base@ = {{0x[-9a-f]*}}
3399b0032cSMehdi Amini  // CHECK-SAME: rank = 1 offset = 0 sizes = [2] strides = [1] data =
3499b0032cSMehdi Amini  // CHECK-NEXT: [10, 20]
3599b0032cSMehdi Amini
3699b0032cSMehdi Amini  return
3799b0032cSMehdi Amini}
3899b0032cSMehdi Amini
39d4555698SStella Stamenovafunc.func private @printMemrefF32(%ptr : tensor<*xf32>)
40