brintos

brintos / llvm-project-archived public Read only

0
0
Text · 16.6 KiB · c4bb22f Raw
608 lines · plain
1// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics2 3// -----4 5func.func @affine_apply_operand_non_index(%arg0 : i32) {6  // Custom parser automatically assigns all arguments the `index` so we must7  // use the generic syntax here to exercise the verifier.8  // expected-error@+1 {{op operand #0 must be variadic of index, but got 'i32'}}9  %0 = "affine.apply"(%arg0) {map = affine_map<(d0) -> (d0)>} : (i32) -> (index)10  return11}12 13// -----14 15func.func @affine_apply_resul_non_index(%arg0 : index) {16  // Custom parser automatically assigns `index` as the result type so we must17  // 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  return21}22 23// -----24func.func @affine_load_invalid_dim(%M : memref<10xi32>) {25  "unknown"() ({26  ^bb0(%arg: index):27    affine.load %M[%arg] : memref<10xi32>28    // expected-error@-1 {{op operand cannot be used as a dimension id}}29    cf.br ^bb130  ^bb1:31    cf.br ^bb132  }) : () -> ()33  return34}35 36// -----37 38#map0 = affine_map<(d0)[s0] -> (d0 + s0)>39 40func.func @affine_for_lower_bound_invalid_sym() {41  affine.for %i0 = 0 to 7 {42    // expected-error@+1 {{operand cannot be used as a symbol}}43    affine.for %n0 = #map0(%i0)[%i0] to 7 {44    }45  }46  return47}48 49// -----50 51#map0 = affine_map<(d0)[s0] -> (d0 + s0)>52 53func.func @affine_for_upper_bound_invalid_sym() {54  affine.for %i0 = 0 to 7 {55    // expected-error@+1 {{operand cannot be used as a symbol}}56    affine.for %n0 = 0 to #map0(%i0)[%i0] {57    }58  }59  return60}61 62// -----63 64#set0 = affine_set<(i)[N] : (i >= 0, N - i >= 0)>65 66func.func @affine_if_invalid_sym() {67  affine.for %i0 = 0 to 7 {68    // expected-error@+1 {{operand cannot be used as a symbol}}69    affine.if #set0(%i0)[%i0] {}70  }71  return72}73 74// -----75 76#set0 = affine_set<(i)[N] : (i >= 0, N - i >= 0)>77 78func.func @affine_if_invalid_dimop_dim(%arg0: index, %arg1: index, %arg2: index, %arg3: index) {79  affine.for %n0 = 0 to 7 {80    %0 = memref.alloc(%arg0, %arg1, %arg2, %arg3) : memref<?x?x?x?xf32>81    %c0 = arith.constant 0 : index82    %dim = memref.dim %0, %c0 : memref<?x?x?x?xf32>83 84    // expected-error@+1 {{operand cannot be used as a symbol}}85    affine.if #set0(%dim)[%n0] {}86  }87  return88}89 90// -----91 92func.func @affine_store_missing_l_square(%C: memref<4096x4096xf32>) {93  %9 = arith.constant 0.0 : f3294  // expected-error@+1 {{expected '['}}95  affine.store %9, %C : memref<4096x4096xf32>96  return97}98 99// -----100 101func.func @affine_store_wrong_value_type(%C: memref<f32>) {102  %c0 = arith.constant 0 : i32103  // expected-error@+1 {{value to store must have the same type as memref element type}}104  "affine.store"(%c0, %C) <{map = affine_map<(i) -> (i)>}> : (i32, memref<f32>) -> ()105  return106}107 108// -----109 110func.func @affine_min(%arg0 : index, %arg1 : index, %arg2 : index) {111  // expected-error@+1 {{operand count and affine map dimension and symbol count must match}}112  %0 = affine.min affine_map<(d0) -> (d0)> (%arg0, %arg1)113 114  return115}116 117// -----118 119func.func @affine_min(%arg0 : index, %arg1 : index, %arg2 : index) {120  // expected-error@+1 {{operand count and affine map dimension and symbol count must match}}121  %0 = affine.min affine_map<()[s0] -> (s0)> (%arg0, %arg1)122 123  return124}125 126// -----127 128func.func @affine_min(%arg0 : index, %arg1 : index, %arg2 : index) {129  // expected-error@+1 {{operand count and affine map dimension and symbol count must match}}130  %0 = affine.min affine_map<(d0) -> (d0)> ()131 132  return133}134 135// -----136 137func.func @affine_min() {138  // expected-error@+1 {{'affine.min' op affine map expect at least one result}}139  %0 = affine.min affine_map<() -> ()> ()140  return141}142 143// -----144 145func.func @affine_min(%arg0 : index) {146  // expected-error@+1 {{'affine.min' op affine map expect at least one result}}147  %0 = affine.min affine_map<(d0) -> ()> (%arg0)148  return149}150 151// -----152 153func.func @affine_max(%arg0 : index, %arg1 : index, %arg2 : index) {154  // expected-error@+1 {{operand count and affine map dimension and symbol count must match}}155  %0 = affine.max affine_map<(d0) -> (d0)> (%arg0, %arg1)156 157  return158}159 160// -----161 162func.func @affine_max(%arg0 : index, %arg1 : index, %arg2 : index) {163  // expected-error@+1 {{operand count and affine map dimension and symbol count must match}}164  %0 = affine.max affine_map<()[s0] -> (s0)> (%arg0, %arg1)165 166  return167}168 169// -----170 171func.func @affine_max(%arg0 : index, %arg1 : index, %arg2 : index) {172  // expected-error@+1 {{operand count and affine map dimension and symbol count must match}}173  %0 = affine.max affine_map<(d0) -> (d0)> ()174 175  return176}177 178// -----179 180func.func @affine_max() {181  // expected-error@+1 {{'affine.max' op affine map expect at least one result}}182  %0 = affine.max affine_map<() -> ()> ()183  return184}185 186// -----187 188func.func @affine_max(%arg0 : index) {189  // expected-error@+1 {{'affine.max' op affine map expect at least one result}}190  %0 = affine.max affine_map<(d0) -> ()> (%arg0)191  return192}193 194// -----195 196func.func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) {197  // expected-error@+1 {{the number of region arguments (1) and the number of map groups for lower (2) and upper bound (2), and the number of steps (2) must all match}}198  affine.parallel (%i) = (0, 0) to (100, 100) step (10, 10) {199  }200}201 202// -----203 204func.func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) {205  // expected-error@+1 {{the number of region arguments (2) and the number of map groups for lower (1) and upper bound (2), and the number of steps (2) must all match}}206  affine.parallel (%i, %j) = (0) to (100, 100) step (10, 10) {207  }208}209 210// -----211 212func.func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) {213  // expected-error@+1 {{the number of region arguments (2) and the number of map groups for lower (2) and upper bound (1), and the number of steps (2) must all match}}214  affine.parallel (%i, %j) = (0, 0) to (100) step (10, 10) {215  }216}217 218// -----219 220func.func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) {221  // expected-error@+1 {{the number of region arguments (2) and the number of map groups for lower (2) and upper bound (2), and the number of steps (1) must all match}}222  affine.parallel (%i, %j) = (0, 0) to (100, 100) step (10) {223  }224}225 226// -----227 228func.func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) {229  affine.for %x = 0 to 7 {230    %y = arith.addi %x, %x : index231    // expected-error@+1 {{operand cannot be used as a dimension id}}232    affine.parallel (%i, %j) = (0, 0) to (%y, 100) step (10, 10) {233    }234  }235  return236}237 238// -----239 240func.func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) {241  affine.for %x = 0 to 7 {242    %y = arith.addi %x, %x : index243    // expected-error@+1 {{operand cannot be used as a symbol}}244    affine.parallel (%i, %j) = (0, 0) to (symbol(%y), 100) step (10, 10) {245    }246  }247  return248}249 250// -----251 252func.func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) {253  %0 = memref.alloc() : memref<100x100xf32>254  //  expected-error@+1 {{reduction must be specified for each output}}255  %1 = affine.parallel (%i, %j) = (0, 0) to (100, 100) step (10, 10) -> (f32) {256    %2 = affine.load %0[%i, %j] : memref<100x100xf32>257    affine.yield %2 : f32258  }259  return260}261 262// -----263 264func.func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) {265  %0 = memref.alloc() : memref<100x100xf32>266  //  expected-error@+1 {{invalid reduction value: "bad"}}267  %1 = affine.parallel (%i, %j) = (0, 0) to (100, 100) step (10, 10) reduce ("bad") -> (f32) {268    %2 = affine.load %0[%i, %j] : memref<100x100xf32>269    affine.yield %2 : f32270  }271  return272}273 274// -----275 276func.func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) {277  %0 = memref.alloc() : memref<100x100xi32>278  %1 = affine.parallel (%i, %j) = (0, 0) to (100, 100) step (10, 10) reduce ("minimumf") -> (f32) {279    %2 = affine.load %0[%i, %j] : memref<100x100xi32>280    //  expected-error@+1 {{types mismatch between yield op and its parent}}281    affine.yield %2 : i32282  }283  return284}285 286// -----287 288func.func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) {289  %0 = memref.alloc() : memref<100x100xi32>290  //  expected-error@+1 {{result type cannot match reduction attribute}}291  %1 = affine.parallel (%i, %j) = (0, 0) to (100, 100) step (10, 10) reduce ("minimumf") -> (i32) {292    %2 = affine.load %0[%i, %j] : memref<100x100xi32>293    affine.yield %2 : i32294  }295  return296}297 298// -----299 300func.func @no_upper_bound_affine_parallel() {301  // expected-error@+1 {{expected lower bound map to have at least one result}}302  affine.parallel (%arg2) = (max()) to (1) {303  }304  return305}306 307// -----308 309func.func @no_upper_bound_affine_parallel() {310  // expected-error@+1 {{expected upper bound map to have at least one result}}311  affine.parallel (%arg3) = (0) to (min()) {312  }313  return314}315 316// -----317 318func.func @vector_load_invalid_vector_type() {319  %0 = memref.alloc() : memref<100xf32>320  affine.for %i0 = 0 to 16 step 8 {321    // expected-error@+1 {{requires memref and vector types of the same elemental type}}322    %1 = affine.vector_load %0[%i0] : memref<100xf32>, vector<8xf64>323  }324  return325}326 327// -----328 329func.func @vector_store_invalid_vector_type() {330  %0 = memref.alloc() : memref<100xf32>331  %1 = arith.constant dense<7.0> : vector<8xf64>332  affine.for %i0 = 0 to 16 step 8 {333    // expected-error@+1 {{requires memref and vector types of the same elemental type}}334    affine.vector_store %1, %0[%i0] : memref<100xf32>, vector<8xf64>335  }336  return337}338 339// -----340 341func.func @vector_load_vector_memref() {342  %0 = memref.alloc() : memref<100xvector<8xf32>>343  affine.for %i0 = 0 to 4 {344    // expected-error@+1 {{requires memref and vector types of the same elemental type}}345    %1 = affine.vector_load %0[%i0] : memref<100xvector<8xf32>>, vector<8xf32>346  }347  return348}349 350// -----351 352func.func @vector_store_vector_memref() {353  %0 = memref.alloc() : memref<100xvector<8xf32>>354  %1 = arith.constant dense<7.0> : vector<8xf32>355  affine.for %i0 = 0 to 4 {356    // expected-error@+1 {{requires memref and vector types of the same elemental type}}357    affine.vector_store %1, %0[%i0] : memref<100xvector<8xf32>>, vector<8xf32>358  }359  return360}361 362// -----363 364func.func @affine_if_with_then_region_args(%N: index) {365  %c = arith.constant 200 : index366  %i = arith.constant 20: index367  // expected-error@+1 {{affine.if' op region #0 should have no arguments}}368  affine.if affine_set<(i)[N] : (i - 2 >= 0, 4 - i >= 0)>(%i)[%c]  {369    ^bb0(%arg:i32):370      %w = affine.apply affine_map<(d0,d1)[s0] -> (d0+d1+s0)> (%i, %i) [%N]371  }372  return373}374 375// -----376 377func.func @affine_if_with_else_region_args(%N: index) {378  %c = arith.constant 200 : index379  %i = arith.constant 20: index380  // expected-error@+1 {{affine.if' op region #1 should have no arguments}}381  affine.if affine_set<(i)[N] : (i - 2 >= 0, 4 - i >= 0)>(%i)[%c]  {382      %w = affine.apply affine_map<(d0,d1)[s0] -> (d0+d1+s0)> (%i, %i) [%N]383  } else {384    ^bb0(%arg:i32):385      %w = affine.apply affine_map<(d0,d1)[s0] -> (d0-d1+s0)> (%i, %i) [%N]386  }387  return388}389 390// -----391 392func.func @affine_for_iter_args_mismatch(%buffer: memref<1024xf32>) -> f32 {393  %sum_0 = arith.constant 0.0 : f32394  // expected-error@+1 {{mismatch between the number of loop-carried values and results}}395  %res = affine.for %i = 0 to 10 step 2 iter_args(%sum_iter = %sum_0) -> (f32, f32) {396    %t = affine.load %buffer[%i] : memref<1024xf32>397    affine.yield %t : f32398  }399  return %res : f32400}401 402 403// -----404 405func.func @result_number() {406  // expected-error@+1 {{result number not allowed}}407  affine.for %n0#0 = 0 to 7 {408  }409  return410}411 412// -----413 414func.func @malformed_for_percent() {415  affine.for i = 1 to 10 { // expected-error {{expected SSA operand}}416 417// -----418 419func.func @malformed_for_equal() {420  affine.for %i 1 to 10 { // expected-error {{expected '='}}421 422// -----423 424func.func @malformed_for_to() {425  affine.for %i = 1 too 10 { // expected-error {{expected 'to' between bounds}}426  }427}428 429// -----430 431func.func @incomplete_for() {432  affine.for %i = 1 to 10 step 2433}        // expected-error @-1 {{expected '{' to begin a region}}434 435// -----436 437#map0 = affine_map<(d0) -> (d0 floordiv 4)>438 439func.func @reference_to_iv_in_bound() {440  // expected-error@+2 {{region entry argument '%i0' is already in use}}441  // expected-note@+1 {{previously referenced here}}442  affine.for %i0 = #map0(%i0) to 10 {443  }444}445 446// -----447 448func.func @nonconstant_step(%1 : i32) {449  affine.for %2 = 1 to 5 step %1 { // expected-error {{expected attribute value}}450 451// -----452 453func.func @for_negative_stride() {454  affine.for %i = 1 to 10 step -1455}        // expected-error@-1 {{expected step to be representable as a positive signed integer}}456 457// -----458 459func.func @invalid_if_conditional2() {460  affine.for %i = 1 to 10 {461    affine.if affine_set<(i)[N] : (i >= )>  // expected-error {{expected affine expression}}462  }463}464 465// -----466 467func.func @invalid_if_conditional3() {468  affine.for %i = 1 to 10 {469    affine.if affine_set<(i)[N] : (i == )>  // expected-error {{expected affine expression}}470  }471}472 473// -----474 475func.func @invalid_if_conditional6() {476  affine.for %i = 1 to 10 {477    affine.if affine_set<(i) : (i)> // expected-error {{expected '== affine-expr' or '>= affine-expr' at end of affine constraint}}478  }479}480 481// -----482// TODO: support affine.if (1)?483func.func @invalid_if_conditional7() {484  affine.for %i = 1 to 10 {485    affine.if affine_set<(i) : (1)> // expected-error {{expected '== affine-expr' or '>= affine-expr' at end of affine constraint}}486  }487}488 489// -----490 491func.func @missing_for_max(%arg0: index, %arg1: index, %arg2: memref<100xf32>) {492  // expected-error @+1 {{lower loop bound affine map with multiple results requires 'max' prefix}}493  affine.for %i0 = affine_map<()[s]->(0,s-1)>()[%arg0] to %arg1 {494  }495  return496}497 498// -----499 500func.func @missing_for_min(%arg0: index, %arg1: index, %arg2: memref<100xf32>) {501  // expected-error @+1 {{upper loop bound affine map with multiple results requires 'min' prefix}}502  affine.for %i0 = %arg0 to affine_map<()[s]->(100,s+1)>()[%arg1] {503  }504  return505}506 507// -----508 509func.func @delinearize(%idx: index, %basis0: index, %basis1 :index) {510  // expected-error@+1 {{'affine.delinearize_index' op should return an index for each basis element and up to one extra index}}511  %1 = affine.delinearize_index %idx into (%basis0, %basis1) : index512  return513}514 515// -----516 517func.func @delinearize(%idx: index) {518  // expected-error@+1 {{'affine.delinearize_index' op no basis element may be statically non-positive}}519  %1:2 = affine.delinearize_index %idx into (2, -2) : index, index520  return521}522 523// -----524 525func.func @linearize(%idx: index, %basis0: index, %basis1 :index) -> index {526  // expected-error@+1 {{'affine.linearize_index' op should be passed a basis element for each index except possibly the first}}527  %0 = affine.linearize_index [%idx] by (%basis0, %basis1) : index528  return %0 : index529}530 531// -----532 533func.func @dynamic_dimension_index() {534  "unknown.region"() ({535    %idx = "unknown.test"() : () -> (index)536    %memref = "unknown.test"() : () -> memref<?x?xf32>537    %dim = memref.dim %memref, %idx : memref<?x?xf32>538    // expected-error@below {{op operand cannot be used as a dimension id}}539    affine.load %memref[%dim, %dim] : memref<?x?xf32>540    "unknown.terminator"() : () -> ()541  }) : () -> ()542  return543}544 545// -----546 547func.func @dynamic_linearized_index() {548  "unknown.region"() ({549    %idx = "unknown.test"() : () -> (index)550    %memref = "unknown.test"() : () -> memref<?xf32>551    %pos = affine.linearize_index [%idx, %idx] by (8) : index552    // expected-error@below {{op operand cannot be used as a dimension id}}553    affine.load %memref[%pos] : memref<?xf32>554    "unknown.terminator"() : () -> ()555  }) : () -> ()556  return557}558 559// -----560 561func.func @dynamic_delinearized_index() {562  "unknown.region"() ({563    %idx = "unknown.test"() : () -> (index)564    %memref = "unknown.test"() : () -> memref<?x?xf32>565    %pos0, %pos1 = affine.delinearize_index %idx into (8) : index, index566    // expected-error@below {{op operand cannot be used as a dimension id}}567    affine.load %memref[%pos0, %pos1] : memref<?x?xf32>568    "unknown.terminator"() : () -> ()569  }) : () -> ()570  return571}572 573// -----574 575#map = affine_map<() -> ()>576#map1 = affine_map<() -> (1)>577func.func @no_lower_bound() {578  // expected-error@+1 {{'affine.for' op expected lower bound map to have at least one result}}579  affine.for %i = max #map() to min #map1() {580  }581  return582}583 584// -----585 586#map = affine_map<() -> ()>587#map1 = affine_map<() -> (1)>588func.func @no_upper_bound() {589  // expected-error@+1 {{'affine.for' op expected upper bound map to have at least one result}}590  affine.for %i = max #map1() to min #map() {591  }592  return593}594 595// -----596 597func.func @invalid_symbol() {598  affine.for %arg1 = 0 to 1 {599    affine.for %arg2 = 0 to 26 {600      affine.for %arg3 = 0 to 23 {601        affine.apply affine_map<()[s0, s1] -> (s0 * 23 + s1)>()[%arg1, %arg3]602        // expected-error@above {{dimensional operand cannot be used as a symbol}}603      }604    }605  }606  return607}608