1// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics 2 3// ----- 4 5func @affine_apply_operand_non_index(%arg0 : i32) { 6 // Custom parser automatically assigns all arguments the `index` so we must 7 // use the generic syntax here to exercise the verifier. 8 // expected-error@+1 {{op operand #0 must be index, but got 'i32'}} 9 %0 = "affine.apply"(%arg0) {map = affine_map<(d0) -> (d0)>} : (i32) -> (index) 10 return 11} 12 13// ----- 14 15func @affine_apply_resul_non_index(%arg0 : index) { 16 // Custom parser automatically assigns `index` as the result type so we must 17 // use the generic syntax here to exercise the verifier. 18 // expected-error@+1 {{op result #0 must be index, but got 'i32'}} 19 %0 = "affine.apply"(%arg0) {map = affine_map<(d0) -> (d0)>} : (index) -> (i32) 20 return 21} 22 23// ----- 24 25#map = affine_map<(d0)[s0] -> (d0 + s0)> 26 27func @affine_for_lower_bound_invalid_dim(%arg : index) { 28 affine.for %n0 = 0 to 7 { 29 %dim = addi %arg, %arg : index 30 31 // expected-error@+1 {{operand cannot be used as a dimension id}} 32 affine.for %n1 = 0 to #map(%dim)[%arg] { 33 } 34 } 35 return 36} 37 38// ----- 39 40#map = affine_map<(d0)[s0] -> (d0 + s0)> 41 42func @affine_for_upper_bound_invalid_dim(%arg : index) { 43 affine.for %n0 = 0 to 7 { 44 %dim = addi %arg, %arg : index 45 46 // expected-error@+1 {{operand cannot be used as a dimension id}} 47 affine.for %n1 = #map(%dim)[%arg] to 7 { 48 } 49 } 50 return 51} 52 53// ----- 54func @affine_load_invalid_dim(%M : memref<10xi32>) { 55 "unknown"() ({ 56 ^bb0(%arg: index): 57 affine.load %M[%arg] : memref<10xi32> 58 // expected-error@-1 {{index must be a dimension or symbol identifier}} 59 br ^bb1 60 ^bb1: 61 br ^bb1 62 }) : () -> () 63 return 64} 65 66// ----- 67 68#map0 = affine_map<(d0)[s0] -> (d0 + s0)> 69 70func @affine_for_lower_bound_invalid_sym() { 71 affine.for %i0 = 0 to 7 { 72 // expected-error@+1 {{operand cannot be used as a symbol}} 73 affine.for %n0 = #map0(%i0)[%i0] to 7 { 74 } 75 } 76 return 77} 78 79// ----- 80 81#map0 = affine_map<(d0)[s0] -> (d0 + s0)> 82 83func @affine_for_upper_bound_invalid_sym() { 84 affine.for %i0 = 0 to 7 { 85 // expected-error@+1 {{operand cannot be used as a symbol}} 86 affine.for %n0 = 0 to #map0(%i0)[%i0] { 87 } 88 } 89 return 90} 91 92// ----- 93 94#set0 = affine_set<(i)[N] : (i >= 0, N - i >= 0)> 95 96func @affine_if_invalid_dim(%arg : index) { 97 affine.for %n0 = 0 to 7 { 98 %dim = addi %arg, %arg : index 99 100 // expected-error@+1 {{operand cannot be used as a dimension id}} 101 affine.if #set0(%dim)[%n0] {} 102 } 103 return 104} 105 106// ----- 107 108#set0 = affine_set<(i)[N] : (i >= 0, N - i >= 0)> 109 110func @affine_if_invalid_sym() { 111 affine.for %i0 = 0 to 7 { 112 // expected-error@+1 {{operand cannot be used as a symbol}} 113 affine.if #set0(%i0)[%i0] {} 114 } 115 return 116} 117 118// ----- 119 120#set0 = affine_set<(i)[N] : (i >= 0, N - i >= 0)> 121 122func @affine_if_invalid_dimop_dim(%arg0: index, %arg1: index, %arg2: index, %arg3: index) { 123 affine.for %n0 = 0 to 7 { 124 %0 = alloc(%arg0, %arg1, %arg2, %arg3) : memref<?x?x?x?xf32> 125 %c0 = constant 0 : index 126 %dim = dim %0, %c0 : memref<?x?x?x?xf32> 127 128 // expected-error@+1 {{operand cannot be used as a symbol}} 129 affine.if #set0(%dim)[%n0] {} 130 } 131 return 132} 133 134// ----- 135 136func @affine_store_missing_l_square(%C: memref<4096x4096xf32>) { 137 %9 = constant 0.0 : f32 138 // expected-error@+1 {{expected '['}} 139 affine.store %9, %C : memref<4096x4096xf32> 140 return 141} 142 143// ----- 144 145func @affine_min(%arg0 : index, %arg1 : index, %arg2 : index) { 146 // expected-error@+1 {{operand count and affine map dimension and symbol count must match}} 147 %0 = affine.min affine_map<(d0) -> (d0)> (%arg0, %arg1) 148 149 return 150} 151 152// ----- 153 154func @affine_min(%arg0 : index, %arg1 : index, %arg2 : index) { 155 // expected-error@+1 {{operand count and affine map dimension and symbol count must match}} 156 %0 = affine.min affine_map<()[s0] -> (s0)> (%arg0, %arg1) 157 158 return 159} 160 161// ----- 162 163func @affine_min(%arg0 : index, %arg1 : index, %arg2 : index) { 164 // expected-error@+1 {{operand count and affine map dimension and symbol count must match}} 165 %0 = affine.min affine_map<(d0) -> (d0)> () 166 167 return 168} 169 170// ----- 171 172func @affine_max(%arg0 : index, %arg1 : index, %arg2 : index) { 173 // expected-error@+1 {{operand count and affine map dimension and symbol count must match}} 174 %0 = affine.max affine_map<(d0) -> (d0)> (%arg0, %arg1) 175 176 return 177} 178 179// ----- 180 181func @affine_max(%arg0 : index, %arg1 : index, %arg2 : index) { 182 // expected-error@+1 {{operand count and affine map dimension and symbol count must match}} 183 %0 = affine.max affine_map<()[s0] -> (s0)> (%arg0, %arg1) 184 185 return 186} 187 188// ----- 189 190func @affine_max(%arg0 : index, %arg1 : index, %arg2 : index) { 191 // expected-error@+1 {{operand count and affine map dimension and symbol count must match}} 192 %0 = affine.max affine_map<(d0) -> (d0)> () 193 194 return 195} 196 197// ----- 198 199func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) { 200 // expected-error@+1 {{region argument count and num results of upper bounds, lower bounds, and steps must all match}} 201 affine.parallel (%i) = (0, 0) to (100, 100) step (10, 10) { 202 } 203} 204 205// ----- 206 207func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) { 208 // expected-error@+1 {{region argument count and num results of upper bounds, lower bounds, and steps must all match}} 209 affine.parallel (%i, %j) = (0) to (100, 100) step (10, 10) { 210 } 211} 212 213// ----- 214 215func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) { 216 // expected-error@+1 {{region argument count and num results of upper bounds, lower bounds, and steps must all match}} 217 affine.parallel (%i, %j) = (0, 0) to (100) step (10, 10) { 218 } 219} 220 221// ----- 222 223func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) { 224 // expected-error@+1 {{region argument count and num results of upper bounds, lower bounds, and steps must all match}} 225 affine.parallel (%i, %j) = (0, 0) to (100, 100) step (10) { 226 } 227} 228 229// ----- 230 231func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) { 232 affine.for %x = 0 to 7 { 233 %y = addi %x, %x : index 234 // expected-error@+1 {{operand cannot be used as a dimension id}} 235 affine.parallel (%i, %j) = (0, 0) to (%y, 100) step (10, 10) { 236 } 237 } 238 return 239} 240 241// ----- 242 243func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) { 244 affine.for %x = 0 to 7 { 245 %y = addi %x, %x : index 246 // expected-error@+1 {{operand cannot be used as a symbol}} 247 affine.parallel (%i, %j) = (0, 0) to (symbol(%y), 100) step (10, 10) { 248 } 249 } 250 return 251} 252 253// ----- 254 255func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) { 256 %0 = alloc() : memref<100x100xf32> 257 // expected-error@+1 {{reduction must be specified for each output}} 258 %1 = affine.parallel (%i, %j) = (0, 0) to (100, 100) step (10, 10) -> (f32) { 259 %2 = affine.load %0[%i, %j] : memref<100x100xf32> 260 affine.yield %2 : f32 261 } 262 return 263} 264 265// ----- 266 267func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) { 268 %0 = alloc() : memref<100x100xf32> 269 // expected-error@+1 {{invalid reduction value: "bad"}} 270 %1 = affine.parallel (%i, %j) = (0, 0) to (100, 100) step (10, 10) reduce ("bad") -> (f32) { 271 %2 = affine.load %0[%i, %j] : memref<100x100xf32> 272 affine.yield %2 : f32 273 } 274 return 275} 276 277// ----- 278 279func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) { 280 %0 = alloc() : memref<100x100xi32> 281 %1 = affine.parallel (%i, %j) = (0, 0) to (100, 100) step (10, 10) reduce ("minf") -> (f32) { 282 %2 = affine.load %0[%i, %j] : memref<100x100xi32> 283 // expected-error@+1 {{types mismatch between yield op and its parent}} 284 affine.yield %2 : i32 285 } 286 return 287} 288 289// ----- 290 291func @vector_load_invalid_vector_type() { 292 %0 = alloc() : memref<100xf32> 293 affine.for %i0 = 0 to 16 step 8 { 294 // expected-error@+1 {{requires memref and vector types of the same elemental type}} 295 %1 = affine.vector_load %0[%i0] : memref<100xf32>, vector<8xf64> 296 } 297 return 298} 299 300// ----- 301 302func @vector_store_invalid_vector_type() { 303 %0 = alloc() : memref<100xf32> 304 %1 = constant dense<7.0> : vector<8xf64> 305 affine.for %i0 = 0 to 16 step 8 { 306 // expected-error@+1 {{requires memref and vector types of the same elemental type}} 307 affine.vector_store %1, %0[%i0] : memref<100xf32>, vector<8xf64> 308 } 309 return 310} 311 312// ----- 313 314func @vector_load_vector_memref() { 315 %0 = alloc() : memref<100xvector<8xf32>> 316 affine.for %i0 = 0 to 4 { 317 // expected-error@+1 {{requires memref and vector types of the same elemental type}} 318 %1 = affine.vector_load %0[%i0] : memref<100xvector<8xf32>>, vector<8xf32> 319 } 320 return 321} 322 323// ----- 324 325func @vector_store_vector_memref() { 326 %0 = alloc() : memref<100xvector<8xf32>> 327 %1 = constant dense<7.0> : vector<8xf32> 328 affine.for %i0 = 0 to 4 { 329 // expected-error@+1 {{requires memref and vector types of the same elemental type}} 330 affine.vector_store %1, %0[%i0] : memref<100xvector<8xf32>>, vector<8xf32> 331 } 332 return 333} 334 335// ----- 336 337func @affine_if_with_then_region_args(%N: index) { 338 %c = constant 200 : index 339 %i = constant 20: index 340 // expected-error@+1 {{affine.if' op region #0 should have no arguments}} 341 affine.if affine_set<(i)[N] : (i - 2 >= 0, 4 - i >= 0)>(%i)[%c] { 342 ^bb0(%arg:i32): 343 %w = affine.apply affine_map<(d0,d1)[s0] -> (d0+d1+s0)> (%i, %i) [%N] 344 } 345 return 346} 347 348// ----- 349 350func @affine_if_with_else_region_args(%N: index) { 351 %c = constant 200 : index 352 %i = constant 20: index 353 // expected-error@+1 {{affine.if' op region #1 should have no arguments}} 354 affine.if affine_set<(i)[N] : (i - 2 >= 0, 4 - i >= 0)>(%i)[%c] { 355 %w = affine.apply affine_map<(d0,d1)[s0] -> (d0+d1+s0)> (%i, %i) [%N] 356 } else { 357 ^bb0(%arg:i32): 358 %w = affine.apply affine_map<(d0,d1)[s0] -> (d0-d1+s0)> (%i, %i) [%N] 359 } 360 return 361} 362 363// ----- 364 365func @affine_for_iter_args_mismatch(%buffer: memref<1024xf32>) -> f32 { 366 %sum_0 = constant 0.0 : f32 367 // expected-error@+1 {{mismatch between the number of loop-carried values and results}} 368 %res = affine.for %i = 0 to 10 step 2 iter_args(%sum_iter = %sum_0) -> (f32, f32) { 369 %t = affine.load %buffer[%i] : memref<1024xf32> 370 affine.yield %t : f32 371 } 372 return %res : f32 373} 374