1 // RUN: mlir-opt %s -test-affine-reify-value-bounds -verify-diagnostics \
2 // RUN: -split-input-file | FileCheck %s
4 func.func @unknown_op() -> index {
5 %0 = "test.foo"() : () -> (tensor<?x?xf32>)
6 // expected-error @below{{could not reify bound}}
7 %1 = "test.reify_bound"(%0) {dim = 0} : (tensor<?x?xf32>) -> (index)
13 // CHECK-LABEL: func @cast(
14 // CHECK: %[[c10:.*]] = arith.constant 10 : index
15 // CHECK: return %[[c10]]
16 func.func @cast(%t: tensor<10xf32>) -> index {
17 %0 = tensor.cast %t : tensor<10xf32> to tensor<?xf32>
18 %1 = "test.reify_bound"(%0) {dim = 0} : (tensor<?xf32>) -> (index)
24 func.func @cast_unranked(%t: tensor<*xf32>) -> index {
25 %0 = tensor.cast %t : tensor<*xf32> to tensor<?xf32>
26 // expected-error @below{{could not reify bound}}
27 %1 = "test.reify_bound"(%0) {dim = 0} : (tensor<?xf32>) -> (index)
33 // CHECK-LABEL: func @dim(
34 // CHECK-SAME: %[[t:.*]]: tensor<?xf32>
35 // CHECK: %[[dim:.*]] = tensor.dim %[[t]]
36 // CHECK: %[[dim:.*]] = tensor.dim %[[t]]
37 // CHECK: return %[[dim]]
38 func.func @dim(%t: tensor<?xf32>) -> index {
39 %c0 = arith.constant 0 : index
40 %0 = tensor.dim %t, %c0 : tensor<?xf32>
41 %1 = "test.reify_bound"(%0) : (index) -> (index)
47 // CHECK-LABEL: func @empty(
48 // CHECK-SAME: %[[sz:.*]]: index
49 // CHECK: %[[c6:.*]] = arith.constant 6 : index
50 // CHECK: return %[[c6]], %[[sz]]
51 func.func @empty(%sz: index) -> (index, index) {
52 %0 = tensor.empty(%sz) : tensor<6x?xf32>
53 %1 = "test.reify_bound"(%0) {dim = 0} : (tensor<6x?xf32>) -> (index)
54 %2 = "test.reify_bound"(%0) {dim = 1} : (tensor<6x?xf32>) -> (index)
55 return %1, %2 : index, index
60 // CHECK-LABEL: func @extract_slice_dynamic(
61 // CHECK-SAME: %[[t:.*]]: tensor<?xf32>, %[[sz:.*]]: index
62 // CHECK: return %[[sz]]
63 func.func @extract_slice_dynamic(%t: tensor<?xf32>, %sz: index) -> index {
64 %0 = tensor.extract_slice %t[2][%sz][1] : tensor<?xf32> to tensor<?xf32>
65 %1 = "test.reify_bound"(%0) {dim = 0} : (tensor<?xf32>) -> (index)
71 // CHECK-LABEL: func @extract_slice_static(
72 // CHECK-SAME: %[[t:.*]]: tensor<?xf32>
73 // CHECK: %[[c5:.*]] = arith.constant 5 : index
74 // CHECK: return %[[c5]]
75 func.func @extract_slice_static(%t: tensor<?xf32>) -> index {
76 %0 = tensor.extract_slice %t[2][5][1] : tensor<?xf32> to tensor<5xf32>
77 %1 = "test.reify_bound"(%0) {dim = 0} : (tensor<5xf32>) -> (index)
83 func.func @extract_slice_dynamic_constant(%t: tensor<?xf32>, %sz: index) -> index {
84 %0 = tensor.extract_slice %t[2][%sz][1] : tensor<?xf32> to tensor<?xf32>
85 // expected-error @below{{could not reify bound}}
86 %1 = "test.reify_bound"(%0) {dim = 0, constant} : (tensor<?xf32>) -> (index)
92 // CHECK-LABEL: func @extract_slice_static_constant(
93 // CHECK-SAME: %[[t:.*]]: tensor<?xf32>
94 // CHECK: %[[c5:.*]] = arith.constant 5 : index
95 // CHECK: return %[[c5]]
96 func.func @extract_slice_static_constant(%t: tensor<?xf32>) -> index {
97 %0 = tensor.extract_slice %t[2][5][1] : tensor<?xf32> to tensor<5xf32>
98 %1 = "test.reify_bound"(%0) {dim = 0, constant} : (tensor<5xf32>) -> (index)
104 // CHECK-LABEL: func @extract_slice_rank_reduce(
105 // CHECK-SAME: %[[t:.*]]: tensor<?x?xf32>, %[[sz:.*]]: index
106 // CHECK: return %[[sz]]
107 func.func @extract_slice_rank_reduce(%t: tensor<?x?xf32>, %sz: index) -> index {
108 %0 = tensor.extract_slice %t[0, 2][1, %sz][1, 1] : tensor<?x?xf32> to tensor<?xf32>
109 %1 = "test.reify_bound"(%0) {dim = 0} : (tensor<?xf32>) -> (index)
115 // CHECK-LABEL: func @insert(
116 // CHECK-SAME: %[[t:.*]]: tensor<?xf32>
117 // CHECK: %[[c0:.*]] = arith.constant 0 : index
118 // CHECK: %[[dim:.*]] = tensor.dim %[[t]], %[[c0]]
119 // CHECK: return %[[dim]]
120 func.func @insert(%t: tensor<?xf32>, %f: f32, %pos: index) -> index {
121 %0 = tensor.insert %f into %t[%pos] : tensor<?xf32>
122 %1 = "test.reify_bound"(%0) {dim = 0} : (tensor<?xf32>) -> (index)
128 // CHECK: #[[$map:.*]] = affine_map<()[s0, s1] -> (s0 + s1 * 2)>
129 // CHECK: #[[$map1:.*]] = affine_map<()[s0] -> (s0 + 12)>
130 // CHECK-LABEL: func @pad(
131 // CHECK-SAME: %[[t:.*]]: tensor<?x7xf32>, %[[a:.*]]: index, %[[b:.*]]: index
132 // CHECK: %[[c0:.*]] = arith.constant 0 : index
133 // CHECK: %[[dim0:.*]] = tensor.dim %[[t]], %[[c0]]
134 // CHECK: %[[bound0:.*]] = affine.apply #[[$map]]()[%[[dim0]], %[[a]]]
135 // CHECK: %[[bound1:.*]] = affine.apply #[[$map1]]()[%[[b]]]
136 // CHECK: return %[[bound0]], %[[bound1]]
137 func.func @pad(%t: tensor<?x7xf32>, %a: index, %b: index) -> (index, index) {
138 %pad = arith.constant 0.0 : f32
139 %0 = tensor.pad %t low[%a, 5] high[%a, %b] {
140 ^bb0(%arg1: index, %arg2: index):
141 tensor.yield %pad : f32
142 } : tensor<?x7xf32> to tensor<?x?xf32>
143 %1 = "test.reify_bound"(%0) {dim = 0} : (tensor<?x?xf32>) -> (index)
144 %2 = "test.reify_bound"(%0) {dim = 1} : (tensor<?x?xf32>) -> (index)
145 return %1, %2 : index, index
150 // CHECK-LABEL: func @rank(
151 // CHECK-SAME: %[[t:.*]]: tensor<5xf32>
152 // CHECK: %[[c1:.*]] = arith.constant 1 : index
153 // CHECK: return %[[c1]]
154 func.func @rank(%t: tensor<5xf32>) -> index {
155 %0 = tensor.rank %t : tensor<5xf32>
156 %1 = "test.reify_bound"(%0) : (index) -> (index)
162 func.func @dynamic_dims_are_equal(%t: tensor<?xf32>) {
163 %c0 = arith.constant 0 : index
164 %dim0 = tensor.dim %t, %c0 : tensor<?xf32>
165 %dim1 = tensor.dim %t, %c0 : tensor<?xf32>
166 // expected-remark @below {{true}}
167 "test.compare"(%dim0, %dim1) : (index, index) -> ()
173 func.func @dynamic_dims_are_different(%t: tensor<?xf32>) {
174 %c0 = arith.constant 0 : index
175 %c1 = arith.constant 1 : index
176 %dim0 = tensor.dim %t, %c0 : tensor<?xf32>
177 %val = arith.addi %dim0, %c1 : index
178 // expected-remark @below {{false}}
179 "test.compare"(%dim0, %val) : (index, index) -> ()
185 func.func @dynamic_dims_are_maybe_equal_1(%t: tensor<?xf32>) {
186 %c0 = arith.constant 0 : index
187 %c5 = arith.constant 5 : index
188 %dim0 = tensor.dim %t, %c0 : tensor<?xf32>
189 // expected-error @below {{unknown}}
190 "test.compare"(%dim0, %c5) : (index, index) -> ()
196 func.func @dynamic_dims_are_maybe_equal_2(%t: tensor<?x?xf32>) {
197 %c0 = arith.constant 0 : index
198 %c1 = arith.constant 1 : index
199 %dim0 = tensor.dim %t, %c0 : tensor<?x?xf32>
200 %dim1 = tensor.dim %t, %c1 : tensor<?x?xf32>
201 // expected-error @below {{unknown}}
202 "test.compare"(%dim0, %dim1) : (index, index) -> ()