[mlir] Move memref-tests from standard to memref folder.

Split memref-test from standard test and move them to the folder MemRef.

Differential Revision: https://reviews.llvm.org/D100950
This commit is contained in:
Thomas Schmeyer 2021-04-16 17:33:06 +02:00
parent 8000e1f578
commit 28b6726c4d
7 changed files with 343 additions and 341 deletions

View File

@ -0,0 +1,64 @@
// RUN: mlir-opt %s -canonicalize --split-input-file | FileCheck %s
// Test case: Basic folding of memref.tensor_load(memref.buffer_cast(t)) -> t
// CHECK-LABEL: func @tensor_load_of_buffer_cast(
// CHECK-SAME: %[[TENSOR:.*]]: tensor<?xf32>) -> tensor<?xf32> {
// CHECK: return %[[TENSOR]]
func @tensor_load_of_buffer_cast(%arg0: tensor<?xf32>) -> tensor<?xf32> {
%0 = memref.buffer_cast %arg0 : memref<?xf32>
%1 = memref.tensor_load %0 : memref<?xf32>
return %1 : tensor<?xf32>
}
// -----
// Test case: Basic folding of memref.buffer_cast(memref.tensor_load(m)) -> m
// CHECK-LABEL: func @buffer_cast_of_tensor_load(
// CHECK-SAME: %[[MEMREF:.*]]: memref<?xf32>) -> memref<?xf32> {
// CHECK: return %[[MEMREF]]
func @buffer_cast_of_tensor_load(%arg0: memref<?xf32>) -> memref<?xf32> {
%0 = memref.tensor_load %arg0 : memref<?xf32>
%1 = memref.buffer_cast %0 : memref<?xf32>
return %1 : memref<?xf32>
}
// -----
// Test case: If the memrefs are not the same type, don't fold them.
// Test case: If the memrefs are not cast-compatible (e.g. different address space),
// don't canonicalize them either.
// CHECK-LABEL: func @no_fold_buffer_cast_of_tensor_load(
// CHECK-SAME: %[[MEMREF_ADDRSPACE2:.*]]: memref<?xf32, 2>)
// CHECK-SAME: -> memref<?xf32, 7> {
// CHECK: %[[TENSOR:.*]] = memref.tensor_load
// CHECK_SAME: %[[MEMREF_ADDRSPACE2]] : memref<?xf32, 2>
// CHECK: %[[MEMREF_ADDRSPACE7:.*]] = memref.buffer_cast
// CHECK_SAME: %[[TENSOR]] : memref<?xf32, 7>
// CHECK: return %[[MEMREF_ADDRSPACE7]]
func @no_fold_buffer_cast_of_tensor_load(%arg0: memref<?xf32, 2>) -> memref<?xf32, 7> {
%0 = memref.tensor_load %arg0 : memref<?xf32, 2>
%1 = memref.buffer_cast %0 : memref<?xf32, 7>
return %1 : memref<?xf32, 7>
}
// -----
// CHECK-DAG: #[[$OFF_3:[a-z0-9]+]] = affine_map<(d0) -> (d0 + 3)>
// CHECK-DAG: #[[$OFF_UNK:[a-z0-9]+]] = affine_map<(d0)[s0] -> (d0 + s0)>
// Test case: If the memrefs are cast-compatible, canonicalize.
// CHECK-LABEL: func @canonicalize_buffer_cast_of_tensor_load(
// CHECK-SAME: %[[M:.*]]: memref<?xf32, #[[$OFF_3]]>)
// CHEKC-SAME: -> memref<?xf32, #[[$OFF_UNK]]> {
// CHECK-NOT: memref.tensor_load
// CHECK-NOT: memref.buffer_cast
// CHECK: %[[R:.*]] = memref.cast %[[M]]
// CHECK-SAME: memref<?xf32, #[[$OFF_3]]> to memref<?xf32, #[[$OFF_UNK]]>
// CHECK: return %[[R]]
func @canonicalize_buffer_cast_of_tensor_load(%arg0: memref<?xf32, offset: 3, strides: [1]>)
-> memref<?xf32, offset: ?, strides: [1]>
{
%0 = memref.tensor_load %arg0 : memref<?xf32, offset: 3, strides: [1]>
%1 = memref.buffer_cast %0 : memref<?xf32, offset: ?, strides: [1]>
return %1 : memref<?xf32, offset: ?, strides: [1]>
}

View File

@ -0,0 +1,217 @@
// RUN: mlir-opt -split-input-file %s -verify-diagnostics
func @transpose_not_permutation(%v : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>) {
// expected-error @+1 {{expected a permutation map}}
memref.transpose %v (i, j) -> (i, i) : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>> to memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>
}
// -----
func @transpose_bad_rank(%v : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>) {
// expected-error @+1 {{expected a permutation map of same rank as the input}}
memref.transpose %v (i) -> (i) : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>> to memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>
}
// -----
func @transpose_wrong_type(%v : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>) {
// expected-error @+1 {{output type 'memref<?x?xf32, affine_map<(d0, d1)[s0, s1] -> (d0 * s1 + s0 + d1)>>' does not match transposed input type 'memref<?x?xf32, affine_map<(d0, d1)[s0, s1] -> (d0 * s1 + s0 + d1)>>'}}
memref.transpose %v (i, j) -> (j, i) : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>> to memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>
}
// -----
func @memref_reinterpret_cast_too_many_offsets(%in: memref<?xf32>) {
// expected-error @+1 {{expected <= 1 offset values}}
%out = memref.reinterpret_cast %in to
offset: [0, 0], sizes: [10, 10], strides: [10, 1]
: memref<?xf32> to memref<10x10xf32, offset: 0, strides: [10, 1]>
return
}
// -----
func @memref_reinterpret_cast_incompatible_element_types(%in: memref<*xf32>) {
// expected-error @+1 {{different element types specified}}
%out = memref.reinterpret_cast %in to
offset: [0], sizes: [10], strides: [1]
: memref<*xf32> to memref<10xi32, offset: 0, strides: [1]>
return
}
// -----
func @memref_reinterpret_cast_incompatible_memory_space(%in: memref<*xf32>) {
// expected-error @+1 {{different memory spaces specified}}
%out = memref.reinterpret_cast %in to
offset: [0], sizes: [10], strides: [1]
: memref<*xf32> to memref<10xi32, offset: 0, strides: [1], 2>
return
}
// -----
func @memref_reinterpret_cast_offset_mismatch(%in: memref<?xf32>) {
// expected-error @+1 {{expected result type with offset = 2 instead of 1}}
%out = memref.reinterpret_cast %in to
offset: [1], sizes: [10], strides: [1]
: memref<?xf32> to memref<10xf32, offset: 2, strides: [1]>
return
}
// -----
func @memref_reinterpret_cast_size_mismatch(%in: memref<*xf32>) {
// expected-error @+1 {{expected result type with size = 10 instead of 1 in dim = 0}}
%out = memref.reinterpret_cast %in to
offset: [0], sizes: [10], strides: [1]
: memref<*xf32> to memref<1xf32, offset: 0, strides: [1]>
return
}
// -----
func @memref_reinterpret_cast_offset_mismatch(%in: memref<?xf32>) {
// expected-error @+1 {{expected result type with stride = 2 instead of 1 in dim = 0}}
%out = memref.reinterpret_cast %in to
offset: [2], sizes: [10], strides: [2]
: memref<?xf32> to memref<10xf32, offset: 2, strides: [1]>
return
}
// -----
func @memref_reinterpret_cast_offset_mismatch(%in: memref<?xf32>) {
%c0 = constant 0 : index
%c10 = constant 10 : index
// expected-error @+1 {{expected result type with size = 10 instead of -1 in dim = 0}}
%out = memref.reinterpret_cast %in to
offset: [%c0], sizes: [10, %c10], strides: [%c10, 1]
: memref<?xf32> to memref<?x?xf32, offset: ?, strides: [?, 1]>
return
}
// -----
func @memref_reshape_element_type_mismatch(
%buf: memref<*xf32>, %shape: memref<1xi32>) {
// expected-error @+1 {{element types of source and destination memref types should be the same}}
memref.reshape %buf(%shape) : (memref<*xf32>, memref<1xi32>) -> memref<?xi32>
}
// -----
func @memref_reshape_dst_ranked_shape_unranked(
%buf: memref<*xf32>, %shape: memref<?xi32>) {
// expected-error @+1 {{cannot use shape operand with dynamic length to reshape to statically-ranked memref type}}
memref.reshape %buf(%shape) : (memref<*xf32>, memref<?xi32>) -> memref<?xf32>
}
// -----
func @memref_reshape_dst_shape_rank_mismatch(
%buf: memref<*xf32>, %shape: memref<1xi32>) {
// expected-error @+1 {{length of shape operand differs from the result's memref rank}}
memref.reshape %buf(%shape)
: (memref<*xf32>, memref<1xi32>) -> memref<?x?xf32>
}
// -----
func @memref_reshape_src_affine_map_is_not_identity(
%buf: memref<4x4xf32, offset: 0, strides: [3, 2]>,
%shape: memref<1xi32>) {
// expected-error @+1 {{source memref type should have identity affine map}}
memref.reshape %buf(%shape)
: (memref<4x4xf32, offset: 0, strides: [3, 2]>, memref<1xi32>)
-> memref<8xf32>
}
// -----
func @memref_reshape_result_affine_map_is_not_identity(
%buf: memref<4x4xf32>, %shape: memref<1xi32>) {
// expected-error @+1 {{result memref type should have identity affine map}}
memref.reshape %buf(%shape)
: (memref<4x4xf32>, memref<1xi32>) -> memref<8xf32, offset: 0, strides: [2]>
}
// -----
// expected-error @+1 {{type should be static shaped memref}}
memref.global @foo : i32
// -----
// expected-error @+1 {{type should be static shaped memref}}
memref.global @foo : i32 = 5
// -----
// expected-error @+1 {{type should be static shaped memref}}
memref.global @foo : memref<*xf32>
// -----
// expected-error @+1 {{type should be static shaped memref}}
memref.global @foo : memref<?x?xf32>
// -----
// expected-error @+1 {{initial value should be a unit or elements attribute}}
memref.global @foo : memref<2x2xf32> = "foo"
// -----
// expected-error @+1 {{inferred shape of elements literal ([2]) does not match type ([2, 2])}}
memref.global @foo : memref<2x2xf32> = dense<[0.0, 1.0]>
// -----
// expected-error @+1 {{expected valid '@'-identifier for symbol name}}
memref.global "private" "public" @foo : memref<2x2xf32> = "foo"
// -----
// expected-error @+1 {{expected valid '@'-identifier for symbol name}}
memref.global constant external @foo : memref<2x2xf32> = "foo"
// -----
// constant qualifier must be after visibility.
// expected-error @+1 {{expected valid '@'-identifier for symbol name}}
memref.global constant "private" @foo : memref<2x2xf32> = "foo"
// -----
// expected-error @+1 {{op visibility expected to be one of ["public", "private", "nested"], but got "priate"}}
memref.global "priate" constant @memref5 : memref<2xf32> = uninitialized
// -----
func @nonexistent_global_memref() {
// expected-error @+1 {{'gv' does not reference a valid global memref}}
%0 = memref.get_global @gv : memref<3xf32>
return
}
// -----
func @foo()
func @nonexistent_global_memref() {
// expected-error @+1 {{'foo' does not reference a valid global memref}}
%0 = memref.get_global @foo : memref<3xf32>
return
}
// -----
memref.global @gv : memref<3xi32>
func @mismatched_types() {
// expected-error @+1 {{result type 'memref<3xf32>' does not match type 'memref<3xi32>' of the global memref @gv}}
%0 = memref.get_global @gv : memref<3xf32>
return
}

View File

@ -0,0 +1,62 @@
// RUN: mlir-opt %s | mlir-opt | FileCheck %s
// RUN: mlir-opt %s --mlir-print-op-generic | mlir-opt | FileCheck %s
// CHECK-LABEL: test_buffer_cast
func @test_buffer_cast(%arg0: tensor<?xi64>, %arg1: tensor<*xi64>) -> (memref<?xi64, affine_map<(d0) -> (d0 + 7)>>, memref<*xi64, 1>) {
%0 = memref.buffer_cast %arg0 : memref<?xi64, affine_map<(d0) -> (d0 + 7)>>
%1 = memref.buffer_cast %arg1 : memref<*xi64, 1>
return %0, %1 : memref<?xi64, affine_map<(d0) -> (d0 + 7)>>, memref<*xi64, 1>
}
// CHECK-LABEL: func @memref_reinterpret_cast
func @memref_reinterpret_cast(%in: memref<?xf32>)
-> memref<10x?xf32, offset: ?, strides: [?, 1]> {
%c0 = constant 0 : index
%c10 = constant 10 : index
%out = memref.reinterpret_cast %in to
offset: [%c0], sizes: [10, %c10], strides: [%c10, 1]
: memref<?xf32> to memref<10x?xf32, offset: ?, strides: [?, 1]>
return %out : memref<10x?xf32, offset: ?, strides: [?, 1]>
}
// CHECK-LABEL: func @memref_reshape(
func @memref_reshape(%unranked: memref<*xf32>, %shape1: memref<1xi32>,
%shape2: memref<2xi32>, %shape3: memref<?xi32>) -> memref<*xf32> {
%dyn_vec = memref.reshape %unranked(%shape1)
: (memref<*xf32>, memref<1xi32>) -> memref<?xf32>
%dyn_mat = memref.reshape %dyn_vec(%shape2)
: (memref<?xf32>, memref<2xi32>) -> memref<?x?xf32>
%new_unranked = memref.reshape %dyn_mat(%shape3)
: (memref<?x?xf32>, memref<?xi32>) -> memref<*xf32>
return %new_unranked : memref<*xf32>
}
// CHECK-LABEL: memref.global @memref0 : memref<2xf32>
memref.global @memref0 : memref<2xf32>
// CHECK-LABEL: memref.global constant @memref1 : memref<2xf32> = dense<[0.000000e+00, 1.000000e+00]>
memref.global constant @memref1 : memref<2xf32> = dense<[0.0, 1.0]>
// CHECK-LABEL: memref.global @memref2 : memref<2xf32> = uninitialized
memref.global @memref2 : memref<2xf32> = uninitialized
// CHECK-LABEL: memref.global "private" @memref3 : memref<2xf32> = uninitialized
memref.global "private" @memref3 : memref<2xf32> = uninitialized
// CHECK-LABEL: memref.global "private" constant @memref4 : memref<2xf32> = uninitialized
memref.global "private" constant @memref4 : memref<2xf32> = uninitialized
// CHECK-LABEL: func @write_global_memref
func @write_global_memref() {
%0 = memref.get_global @memref0 : memref<2xf32>
%1 = constant dense<[1.0, 2.0]> : tensor<2xf32>
memref.tensor_store %1, %0 : memref<2xf32>
return
}
// CHECK-LABEL: func @read_global_memref
func @read_global_memref() {
%0 = memref.get_global @memref0 : memref<2xf32>
%1 = memref.tensor_load %0 : memref<2xf32>
return
}

View File

@ -443,4 +443,3 @@ func @assert(%arg : i1) {
assert %arg, "Computer says no"
return
}

View File

@ -1,67 +1,5 @@
// RUN: mlir-opt %s -canonicalize --split-input-file | FileCheck %s
// -----
// Test case: Basic folding of memref.tensor_load(memref.buffer_cast(t)) -> t
// CHECK-LABEL: func @tensor_load_of_buffer_cast(
// CHECK-SAME: %[[TENSOR:.*]]: tensor<?xf32>) -> tensor<?xf32> {
// CHECK: return %[[TENSOR]]
func @tensor_load_of_buffer_cast(%arg0: tensor<?xf32>) -> tensor<?xf32> {
%0 = memref.buffer_cast %arg0 : memref<?xf32>
%1 = memref.tensor_load %0 : memref<?xf32>
return %1 : tensor<?xf32>
}
// -----
// Test case: Basic folding of memref.buffer_cast(memref.tensor_load(m)) -> m
// CHECK-LABEL: func @buffer_cast_of_tensor_load(
// CHECK-SAME: %[[MEMREF:.*]]: memref<?xf32>) -> memref<?xf32> {
// CHECK: return %[[MEMREF]]
func @buffer_cast_of_tensor_load(%arg0: memref<?xf32>) -> memref<?xf32> {
%0 = memref.tensor_load %arg0 : memref<?xf32>
%1 = memref.buffer_cast %0 : memref<?xf32>
return %1 : memref<?xf32>
}
// -----
// Test case: If the memrefs are not the same type, don't fold them.
// Test case: If the memrefs are not cast-compatible (e.g. different address space),
// don't canonicalize them either.
// CHECK-LABEL: func @no_fold_buffer_cast_of_tensor_load(
// CHECK-SAME: %[[MEMREF_ADDRSPACE2:.*]]: memref<?xf32, 2>) -> memref<?xf32, 7> {
// CHECK: %[[TENSOR:.*]] = memref.tensor_load %[[MEMREF_ADDRSPACE2]] : memref<?xf32, 2>
// CHECK: %[[MEMREF_ADDRSPACE7:.*]] = memref.buffer_cast %[[TENSOR]] : memref<?xf32, 7>
// CHECK: return %[[MEMREF_ADDRSPACE7]]
func @no_fold_buffer_cast_of_tensor_load(%arg0: memref<?xf32, 2>) -> memref<?xf32, 7> {
%0 = memref.tensor_load %arg0 : memref<?xf32, 2>
%1 = memref.buffer_cast %0 : memref<?xf32, 7>
return %1 : memref<?xf32, 7>
}
// -----
// CHECK-DAG: #[[$OFF_3:[a-z0-9]+]] = affine_map<(d0) -> (d0 + 3)>
// CHECK-DAG: #[[$OFF_UNK:[a-z0-9]+]] = affine_map<(d0)[s0] -> (d0 + s0)>
// Test case: If the memrefs are cast-compatible, canonicalize.
// CHECK-LABEL: func @canonicalize_buffer_cast_of_tensor_load(
// CHECK-SAME: %[[M:.*]]: memref<?xf32, #[[$OFF_3]]>) -> memref<?xf32, #[[$OFF_UNK]]> {
// CHECK-NOT: memref.tensor_load
// CHECK-NOT: memref.buffer_cast
// CHECK: %[[R:.*]] = memref.cast %[[M]] : memref<?xf32, #[[$OFF_3]]> to memref<?xf32, #[[$OFF_UNK]]>
// CHECK: return %[[R]]
func @canonicalize_buffer_cast_of_tensor_load(%arg0: memref<?xf32, offset: 3, strides: [1]>)
-> memref<?xf32, offset: ?, strides: [1]>
{
%0 = memref.tensor_load %arg0 : memref<?xf32, offset: 3, strides: [1]>
%1 = memref.buffer_cast %0 : memref<?xf32, offset: ?, strides: [1]>
return %1 : memref<?xf32, offset: ?, strides: [1]>
}
// -----
// Test case: Basic folding of memref.dim(memref.tensor_load(m)) -> memref.dim(m).
// CHECK-LABEL: func @dim_of_tensor_load(
// CHECK-SAME: %[[MEMREF:[0-9a-z]*]]: memref<?xf32>

View File

@ -16,224 +16,6 @@ func @test_index_cast_tensor_error(%arg0 : tensor<index>) -> i64 {
// -----
func @transpose_not_permutation(%v : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>) {
// expected-error @+1 {{expected a permutation map}}
memref.transpose %v (i, j) -> (i, i) : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>> to memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>
}
// -----
func @transpose_bad_rank(%v : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>) {
// expected-error @+1 {{expected a permutation map of same rank as the input}}
memref.transpose %v (i) -> (i) : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>> to memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>
}
// -----
func @transpose_wrong_type(%v : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>) {
// expected-error @+1 {{output type 'memref<?x?xf32, affine_map<(d0, d1)[s0, s1] -> (d0 * s1 + s0 + d1)>>' does not match transposed input type 'memref<?x?xf32, affine_map<(d0, d1)[s0, s1] -> (d0 * s1 + s0 + d1)>>'}}
memref.transpose %v (i, j) -> (j, i) : memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>> to memref<?x?xf32, affine_map<(i, j)[off, M]->(off + M * i + j)>>
}
// -----
func @memref_reinterpret_cast_too_many_offsets(%in: memref<?xf32>) {
// expected-error @+1 {{expected <= 1 offset values}}
%out = memref.reinterpret_cast %in to
offset: [0, 0], sizes: [10, 10], strides: [10, 1]
: memref<?xf32> to memref<10x10xf32, offset: 0, strides: [10, 1]>
return
}
// -----
func @memref_reinterpret_cast_incompatible_element_types(%in: memref<*xf32>) {
// expected-error @+1 {{different element types specified}}
%out = memref.reinterpret_cast %in to
offset: [0], sizes: [10], strides: [1]
: memref<*xf32> to memref<10xi32, offset: 0, strides: [1]>
return
}
// -----
func @memref_reinterpret_cast_incompatible_memory_space(%in: memref<*xf32>) {
// expected-error @+1 {{different memory spaces specified}}
%out = memref.reinterpret_cast %in to
offset: [0], sizes: [10], strides: [1]
: memref<*xf32> to memref<10xi32, offset: 0, strides: [1], 2>
return
}
// -----
func @memref_reinterpret_cast_offset_mismatch(%in: memref<?xf32>) {
// expected-error @+1 {{expected result type with offset = 2 instead of 1}}
%out = memref.reinterpret_cast %in to
offset: [1], sizes: [10], strides: [1]
: memref<?xf32> to memref<10xf32, offset: 2, strides: [1]>
return
}
// -----
func @memref_reinterpret_cast_size_mismatch(%in: memref<*xf32>) {
// expected-error @+1 {{expected result type with size = 10 instead of 1 in dim = 0}}
%out = memref.reinterpret_cast %in to
offset: [0], sizes: [10], strides: [1]
: memref<*xf32> to memref<1xf32, offset: 0, strides: [1]>
return
}
// -----
func @memref_reinterpret_cast_offset_mismatch(%in: memref<?xf32>) {
// expected-error @+1 {{expected result type with stride = 2 instead of 1 in dim = 0}}
%out = memref.reinterpret_cast %in to
offset: [2], sizes: [10], strides: [2]
: memref<?xf32> to memref<10xf32, offset: 2, strides: [1]>
return
}
// -----
func @memref_reinterpret_cast_offset_mismatch(%in: memref<?xf32>) {
%c0 = constant 0 : index
%c10 = constant 10 : index
// expected-error @+1 {{expected result type with size = 10 instead of -1 in dim = 0}}
%out = memref.reinterpret_cast %in to
offset: [%c0], sizes: [10, %c10], strides: [%c10, 1]
: memref<?xf32> to memref<?x?xf32, offset: ?, strides: [?, 1]>
return
}
// -----
func @memref_reshape_element_type_mismatch(
%buf: memref<*xf32>, %shape: memref<1xi32>) {
// expected-error @+1 {{element types of source and destination memref types should be the same}}
memref.reshape %buf(%shape) : (memref<*xf32>, memref<1xi32>) -> memref<?xi32>
}
// -----
func @memref_reshape_dst_ranked_shape_unranked(
%buf: memref<*xf32>, %shape: memref<?xi32>) {
// expected-error @+1 {{cannot use shape operand with dynamic length to reshape to statically-ranked memref type}}
memref.reshape %buf(%shape) : (memref<*xf32>, memref<?xi32>) -> memref<?xf32>
}
// -----
func @memref_reshape_dst_shape_rank_mismatch(
%buf: memref<*xf32>, %shape: memref<1xi32>) {
// expected-error @+1 {{length of shape operand differs from the result's memref rank}}
memref.reshape %buf(%shape)
: (memref<*xf32>, memref<1xi32>) -> memref<?x?xf32>
}
// -----
func @memref_reshape_src_affine_map_is_not_identity(
%buf: memref<4x4xf32, offset: 0, strides: [3, 2]>,
%shape: memref<1xi32>) {
// expected-error @+1 {{source memref type should have identity affine map}}
memref.reshape %buf(%shape)
: (memref<4x4xf32, offset: 0, strides: [3, 2]>, memref<1xi32>)
-> memref<8xf32>
}
// -----
func @memref_reshape_result_affine_map_is_not_identity(
%buf: memref<4x4xf32>, %shape: memref<1xi32>) {
// expected-error @+1 {{result memref type should have identity affine map}}
memref.reshape %buf(%shape)
: (memref<4x4xf32>, memref<1xi32>) -> memref<8xf32, offset: 0, strides: [2]>
}
// -----
// expected-error @+1 {{type should be static shaped memref}}
memref.global @foo : i32
// -----
// expected-error @+1 {{type should be static shaped memref}}
memref.global @foo : i32 = 5
// -----
// expected-error @+1 {{type should be static shaped memref}}
memref.global @foo : memref<*xf32>
// -----
// expected-error @+1 {{type should be static shaped memref}}
memref.global @foo : memref<?x?xf32>
// -----
// expected-error @+1 {{initial value should be a unit or elements attribute}}
memref.global @foo : memref<2x2xf32> = "foo"
// -----
// expected-error @+1 {{inferred shape of elements literal ([2]) does not match type ([2, 2])}}
memref.global @foo : memref<2x2xf32> = dense<[0.0, 1.0]>
// -----
// expected-error @+1 {{expected valid '@'-identifier for symbol name}}
memref.global "private" "public" @foo : memref<2x2xf32> = "foo"
// -----
// expected-error @+1 {{expected valid '@'-identifier for symbol name}}
memref.global constant external @foo : memref<2x2xf32> = "foo"
// -----
// constant qualifier must be after visibility.
// expected-error @+1 {{expected valid '@'-identifier for symbol name}}
memref.global constant "private" @foo : memref<2x2xf32> = "foo"
// -----
// expected-error @+1 {{op visibility expected to be one of ["public", "private", "nested"], but got "priate"}}
memref.global "priate" constant @memref5 : memref<2xf32> = uninitialized
// -----
func @nonexistent_global_memref() {
// expected-error @+1 {{'gv' does not reference a valid global memref}}
%0 = memref.get_global @gv : memref<3xf32>
return
}
// -----
func @foo()
func @nonexistent_global_memref() {
// expected-error @+1 {{'foo' does not reference a valid global memref}}
%0 = memref.get_global @foo : memref<3xf32>
return
}
// -----
memref.global @gv : memref<3xi32>
func @mismatched_types() {
// expected-error @+1 {{result type 'memref<3xf32>' does not match type 'memref<3xi32>' of the global memref @gv}}
%0 = memref.get_global @gv : memref<3xf32>
return
}
// -----
func @non_signless_constant() {
// expected-error @+1 {{requires integer result types to be signless}}
%0 = constant 0 : ui32

View File

@ -19,13 +19,6 @@ func @test_index_cast_tensor_reverse(%arg0 : tensor<i64>) -> tensor<index> {
return %0 : tensor<index>
}
// CHECK-LABEL: test_buffer_cast
func @test_buffer_cast(%arg0: tensor<?xi64>, %arg1: tensor<*xi64>) -> (memref<?xi64, affine_map<(d0) -> (d0 + 7)>>, memref<*xi64, 1>) {
%0 = memref.buffer_cast %arg0 : memref<?xi64, affine_map<(d0) -> (d0 + 7)>>
%1 = memref.buffer_cast %arg1 : memref<*xi64, 1>
return %0, %1 : memref<?xi64, affine_map<(d0) -> (d0 + 7)>>, memref<*xi64, 1>
}
// CHECK-LABEL: @assert
func @assert(%arg : i1) {
assert %arg, "Some message in case this assertion fails."
@ -44,59 +37,6 @@ func @atan2(%arg0 : f32, %arg1 : f32) -> f32 {
return %result : f32
}
// CHECK-LABEL: func @memref_reinterpret_cast
func @memref_reinterpret_cast(%in: memref<?xf32>)
-> memref<10x?xf32, offset: ?, strides: [?, 1]> {
%c0 = constant 0 : index
%c10 = constant 10 : index
%out = memref.reinterpret_cast %in to
offset: [%c0], sizes: [10, %c10], strides: [%c10, 1]
: memref<?xf32> to memref<10x?xf32, offset: ?, strides: [?, 1]>
return %out : memref<10x?xf32, offset: ?, strides: [?, 1]>
}
// CHECK-LABEL: func @memref_reshape(
func @memref_reshape(%unranked: memref<*xf32>, %shape1: memref<1xi32>,
%shape2: memref<2xi32>, %shape3: memref<?xi32>) -> memref<*xf32> {
%dyn_vec = memref.reshape %unranked(%shape1)
: (memref<*xf32>, memref<1xi32>) -> memref<?xf32>
%dyn_mat = memref.reshape %dyn_vec(%shape2)
: (memref<?xf32>, memref<2xi32>) -> memref<?x?xf32>
%new_unranked = memref.reshape %dyn_mat(%shape3)
: (memref<?x?xf32>, memref<?xi32>) -> memref<*xf32>
return %new_unranked : memref<*xf32>
}
// CHECK-LABEL: memref.global @memref0 : memref<2xf32>
memref.global @memref0 : memref<2xf32>
// CHECK-LABEL: memref.global constant @memref1 : memref<2xf32> = dense<[0.000000e+00, 1.000000e+00]>
memref.global constant @memref1 : memref<2xf32> = dense<[0.0, 1.0]>
// CHECK-LABEL: memref.global @memref2 : memref<2xf32> = uninitialized
memref.global @memref2 : memref<2xf32> = uninitialized
// CHECK-LABEL: memref.global "private" @memref3 : memref<2xf32> = uninitialized
memref.global "private" @memref3 : memref<2xf32> = uninitialized
// CHECK-LABEL: memref.global "private" constant @memref4 : memref<2xf32> = uninitialized
memref.global "private" constant @memref4 : memref<2xf32> = uninitialized
// CHECK-LABEL: func @write_global_memref
func @write_global_memref() {
%0 = memref.get_global @memref0 : memref<2xf32>
%1 = constant dense<[1.0, 2.0]> : tensor<2xf32>
memref.tensor_store %1, %0 : memref<2xf32>
return
}
// CHECK-LABEL: func @read_global_memref
func @read_global_memref() {
%0 = memref.get_global @memref0 : memref<2xf32>
%1 = memref.tensor_load %0 : memref<2xf32>
return
}
// CHECK-LABEL: func @switch(
func @switch(%flag : i32, %caseOperand : i32) {
switch %flag : i32, [