1// RUN: mlir-opt %s -linalg-bufferize \
2// RUN: -arith-bufferize -tensor-bufferize -func-bufferize \
3// RUN: -finalizing-bufferize -buffer-deallocation \
4// RUN: -convert-linalg-to-loops -convert-scf-to-cf -convert-linalg-to-llvm --convert-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | \
5// RUN: mlir-cpu-runner -e main -entry-point-result=void \
6// RUN:   -shared-libs=%mlir_integration_test_dir/libmlir_c_runner_utils%shlibext,%mlir_integration_test_dir/libmlir_runner_utils%shlibext \
7// RUN: | FileCheck %s
8
9func.func @main() {
10  %const = arith.constant dense<10.0> : tensor<2xf32>
11  %insert_val = arith.constant dense<20.0> : tensor<1xf32>
12
13  // Both of these insert_slice ops insert into the same original tensor
14  // value `%const`. This can easily cause bugs if at the memref level
15  // we attempt to write in-place into the memref that %const has been
16  // converted into.
17  %inserted_at_position_0 = tensor.insert_slice %insert_val into %const[0][1][1] : tensor<1xf32> into tensor<2xf32>
18  %inserted_at_position_1 = tensor.insert_slice %insert_val into %const[1][1][1] : tensor<1xf32> into tensor<2xf32>
19
20  %unranked_at_position_0 = tensor.cast %inserted_at_position_0 : tensor<2xf32> to tensor<*xf32>
21  call @printMemrefF32(%unranked_at_position_0) : (tensor<*xf32>) -> ()
22
23  //      CHECK: Unranked Memref base@ = {{0x[-9a-f]*}}
24  // CHECK-SAME: rank = 1 offset = 0 sizes = [2] strides = [1] data =
25  // CHECK-NEXT: [20, 10]
26
27  %unranked_at_position_1 = tensor.cast %inserted_at_position_1 : tensor<2xf32> to tensor<*xf32>
28  call @printMemrefF32(%unranked_at_position_1) : (tensor<*xf32>) -> ()
29
30  //      CHECK: Unranked Memref base@ = {{0x[-9a-f]*}}
31  // CHECK-SAME: rank = 1 offset = 0 sizes = [2] strides = [1] data =
32  // CHECK-NEXT: [10, 20]
33
34  return
35}
36
37func.func private @printMemrefF32(%ptr : tensor<*xf32>)
38